xpp: BRI: split multibyte functionality

* The zero lenth case (Magic request) was split into
  send_magic_request() function. It was not possible
  to move it into card_bri.c, because it is called
  directly from the general interface we provide for
  register read/write via sysfs/proc.

* The normal case (send_multibyte_request) was moved from
  card_global.c into card_bri.c

* This sets the stage to enable bundling of multibyte
  packets into frames (like we do for PCM).

Signed-off-by: Oron Peled <oron.peled@xorcom.com>
Acked-By: Tzafrir Cohen <tzafrir.cohen@xorcom.com>

git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/trunk@10389 a0bf4364-ded3-4de4-8d8a-66a801d63aff
This commit is contained in:
Oron Peled 2012-01-02 14:06:50 +00:00 committed by Tzafrir Cohen
parent 6706b03d9d
commit 9fd76d93c9
2 changed files with 67 additions and 41 deletions

View File

@ -514,6 +514,41 @@ static void bri_hdlc_hard_xmit(struct dahdi_chan *chan)
}
}
int send_multibyte_request(xbus_t *xbus,
unsigned unit, xportno_t portno,
bool eoftx, byte *buf, unsigned len)
{
xframe_t *xframe;
xpacket_t *pack;
reg_cmd_t *reg_cmd;
int ret;
if (!len) {
PORT_ERR(xbus, unit, portno,
"%s: zero length request. dropping.\n", __func__);
return -EINVAL;
}
if (len > MULTIBYTE_MAX_LEN) {
PORT_ERR(xbus, unit, portno,
"%s: len=%d is too long. dropping.\n", __func__, len);
return -EINVAL;
}
XFRAME_NEW_CMD(xframe, pack, xbus, GLOBAL, REGISTER_REQUEST, unit);
reg_cmd = &RPACKET_FIELD(pack, GLOBAL, REGISTER_REQUEST, reg_cmd);
reg_cmd->bytes = len;
reg_cmd->is_multibyte = 1;
reg_cmd->portnum = portno;
reg_cmd->eoframe = eoftx;
memcpy(REG_XDATA(reg_cmd), (byte *)buf, len);
if (debug & DBG_REGS)
dump_xframe(__func__, xbus, xframe, debug);
ret = send_cmd_frame(xbus, xframe);
if (ret < 0)
PORT_ERR(xbus, unit, portno,
"%s: failed sending xframe\n", __func__);
return ret;
}
static int tx_dchan(xpd_t *xpd)
{
struct BRI_priv_data *priv;

View File

@ -40,6 +40,36 @@ extern int debug;
/*---------------- GLOBAL PROC handling -----------------------------------*/
static int send_magic_request(xbus_t *xbus,
unsigned unit, xportno_t portno, bool eoftx)
{
xframe_t *xframe;
xpacket_t *pack;
reg_cmd_t *reg_cmd;
int ret;
/*
* Zero length multibyte is legal and has special meaning for the
* firmware:
* eoftx==1: Start sending us D-channel packets.
* eoftx==0: Stop sending us D-channel packets.
*/
XFRAME_NEW_CMD(xframe, pack, xbus, GLOBAL, REGISTER_REQUEST, unit);
reg_cmd = &RPACKET_FIELD(pack, GLOBAL, REGISTER_REQUEST, reg_cmd);
reg_cmd->bytes = 0;
reg_cmd->is_multibyte = 1;
reg_cmd->portnum = portno;
reg_cmd->eoframe = eoftx;
PORT_DBG(REGS, xbus, unit, portno, "Magic Packet (eoftx=%d)\n", eoftx);
if (debug & DBG_REGS)
dump_xframe(__func__, xbus, xframe, debug);
ret = send_cmd_frame(xbus, xframe);
if (ret < 0)
PORT_ERR(xbus, unit, portno,
"%s: failed sending xframe\n", __func__);
return ret;
}
static int parse_hexbyte(const char *buf)
{
char *endp;
@ -155,8 +185,8 @@ static int execute_chip_command(xpd_t *xpd, const int argc, char *argv[])
addr_mode, argc - argno);
goto out;
}
ret = send_multibyte_request(xpd->xbus, xpd->addr.unit, portno,
addr_mode == 'm', NULL, 0);
ret = send_magic_request(xpd->xbus, xpd->addr.unit, portno,
addr_mode == 'm');
goto out;
}
/* Normal (non-Magic) register commands */
@ -370,44 +400,6 @@ int xpp_register_request(xbus_t *xbus, xpd_t *xpd, xportno_t portno,
return ret;
}
int send_multibyte_request(xbus_t *xbus,
unsigned unit, xportno_t portno,
bool eoftx, byte *buf, unsigned len)
{
xframe_t *xframe;
xpacket_t *pack;
reg_cmd_t *reg_cmd;
int ret;
/*
* Zero length multibyte is legal and has special meaning for the
* firmware:
* eoftx==1: Start sending us D-channel packets.
* eoftx==0: Stop sending us D-channel packets.
*/
if(len > MULTIBYTE_MAX_LEN) {
PORT_ERR(xbus, unit, portno, "%s: len=%d is too long. dropping.\n", __FUNCTION__, len);
return -EINVAL;
}
XFRAME_NEW_CMD(xframe, pack, xbus, GLOBAL, REGISTER_REQUEST, unit);
reg_cmd = &RPACKET_FIELD(pack, GLOBAL, REGISTER_REQUEST, reg_cmd);
reg_cmd->bytes = len;
reg_cmd->is_multibyte = 1;
reg_cmd->portnum = portno;
reg_cmd->eoframe = eoftx;
if(len > 0) {
memcpy(REG_XDATA(reg_cmd), (byte *)buf, len);
} else {
PORT_DBG(REGS, xbus, unit, portno, "Magic Packet (eoftx=%d)\n", eoftx);
}
if(debug & DBG_REGS)
dump_xframe(__FUNCTION__, xbus, xframe, debug);
ret = send_cmd_frame(xbus, xframe);
if(ret < 0)
PORT_ERR(xbus, unit, portno, "%s: failed sending xframe\n", __FUNCTION__);
return ret;
}
/*
* The XPD parameter is totaly ignored by the driver and firmware as well.
*/
@ -752,4 +744,3 @@ err:
EXPORT_SYMBOL(sync_mode_name);
EXPORT_SYMBOL(run_initialize_registers);
EXPORT_SYMBOL(xpp_register_request);
EXPORT_SYMBOL(send_multibyte_request);