Commit b05e9254 authored by Franky Lin's avatar Franky Lin Committed by John W. Linville

brcmfmac: abstract tx packet processing functions

Abstract brcmf_sdio_txpkt_prep and brcmf_sdio_txpkt_postp as a preparation
of chained tx packets for host side tx glomming.
Reviewed-by: default avatarHante Meuleman <meuleman@broadcom.com>
Reviewed-by: default avatarPieter-Paul Giesberts <pieterpg@broadcom.com>
Reviewed-by: default avatarArend van Spriel <arend@broadcom.com>
Signed-off-by: default avatarFranky Lin <frankyl@broadcom.com>
Signed-off-by: default avatarArend van Spriel <arend@broadcom.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 89c2f382
...@@ -592,6 +592,7 @@ brcmf_sdcard_send_buf(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn, ...@@ -592,6 +592,7 @@ brcmf_sdcard_send_buf(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn,
uint flags, u8 *buf, uint nbytes) uint flags, u8 *buf, uint nbytes)
{ {
struct sk_buff *mypkt; struct sk_buff *mypkt;
struct sk_buff_head pktq;
int err; int err;
mypkt = brcmu_pkt_buf_get_skb(nbytes); mypkt = brcmu_pkt_buf_get_skb(nbytes);
...@@ -602,7 +603,10 @@ brcmf_sdcard_send_buf(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn, ...@@ -602,7 +603,10 @@ brcmf_sdcard_send_buf(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn,
} }
memcpy(mypkt->data, buf, nbytes); memcpy(mypkt->data, buf, nbytes);
err = brcmf_sdcard_send_pkt(sdiodev, addr, fn, flags, mypkt); __skb_queue_head_init(&pktq);
__skb_queue_tail(&pktq, mypkt);
err = brcmf_sdcard_send_pkt(sdiodev, addr, fn, flags, &pktq);
__skb_dequeue_tail(&pktq);
brcmu_pkt_buf_free_skb(mypkt); brcmu_pkt_buf_free_skb(mypkt);
return err; return err;
...@@ -611,22 +615,18 @@ brcmf_sdcard_send_buf(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn, ...@@ -611,22 +615,18 @@ brcmf_sdcard_send_buf(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn,
int int
brcmf_sdcard_send_pkt(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn, brcmf_sdcard_send_pkt(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn,
uint flags, struct sk_buff *pkt) uint flags, struct sk_buff_head *pktq)
{ {
uint width; uint width;
int err = 0; int err = 0;
struct sk_buff_head pkt_list;
brcmf_dbg(SDIO, "fun = %d, addr = 0x%x, size = %d\n", brcmf_dbg(SDIO, "fun = %d, addr = 0x%x, size = %d\n",
fn, addr, pkt->len); fn, addr, pktq->qlen);
width = (flags & SDIO_REQ_4BYTE) ? 4 : 2; width = (flags & SDIO_REQ_4BYTE) ? 4 : 2;
brcmf_sdio_addrprep(sdiodev, width, &addr); brcmf_sdio_addrprep(sdiodev, width, &addr);
skb_queue_head_init(&pkt_list); err = brcmf_sdio_buffrw(sdiodev, fn, true, addr, pktq);
skb_queue_tail(&pkt_list, pkt);
err = brcmf_sdio_buffrw(sdiodev, fn, true, addr, &pkt_list);
skb_dequeue_tail(&pkt_list);
return err; return err;
} }
......
...@@ -510,7 +510,6 @@ struct brcmf_sdio { ...@@ -510,7 +510,6 @@ struct brcmf_sdio {
#ifdef DEBUG #ifdef DEBUG
static int qcount[NUMPRIO]; static int qcount[NUMPRIO];
static int tx_packets[NUMPRIO];
#endif /* DEBUG */ #endif /* DEBUG */
#define DEFAULT_SDIO_DRIVE_STRENGTH 6 /* in milliamps */ #define DEFAULT_SDIO_DRIVE_STRENGTH 6 /* in milliamps */
...@@ -1759,85 +1758,185 @@ brcmf_sdbrcm_wait_event_wakeup(struct brcmf_sdio *bus) ...@@ -1759,85 +1758,185 @@ brcmf_sdbrcm_wait_event_wakeup(struct brcmf_sdio *bus)
return; return;
} }
/* Writes a HW/SW header into the packet and sends it. */ /* flag marking a dummy skb added for DMA alignment requirement */
/* Assumes: (a) header space already there, (b) caller holds lock */ #define DUMMY_SKB_FLAG 0x10000
static int brcmf_sdbrcm_txpkt(struct brcmf_sdio *bus, struct sk_buff *pkt, /* bit mask of data length chopped from the previous packet */
#define DUMMY_SKB_CHOP_LEN_MASK 0xffff
/**
* brcmf_sdio_txpkt_prep - packet preparation for transmit
* @bus: brcmf_sdio structure pointer
* @pktq: packet list pointer
* @chan: virtual channel to transmit the packet
*
* Processes to be applied to the packet
* - Align data buffer pointer
* - Align data buffer length
* - Prepare header
* Return: negative value if there is error
*/
static int
brcmf_sdio_txpkt_prep(struct brcmf_sdio *bus, struct sk_buff_head *pktq,
uint chan) uint chan)
{ {
int ret; u16 head_pad, tail_pad, tail_chop, pkt_len;
u8 *frame; u16 head_align, sg_align;
u16 len, pad = 0; u32 sw_header;
u32 swheader; int ntail;
int i; struct sk_buff *pkt_next, *pkt_new;
u8 *dat_buf;
brcmf_dbg(TRACE, "Enter\n"); unsigned blksize = bus->sdiodev->func[SDIO_FUNC_2]->cur_blksize;
frame = (u8 *) (pkt->data); /* SDIO ADMA requires at least 32 bit alignment */
head_align = 4;
/* Add alignment padding, allocate new packet if needed */ sg_align = 4;
pad = ((unsigned long)frame % BRCMF_SDALIGN); if (bus->sdiodev->pdata) {
if (pad) { head_align = bus->sdiodev->pdata->sd_head_align > 4 ?
if (skb_headroom(pkt) < pad) { bus->sdiodev->pdata->sd_head_align : 4;
brcmf_dbg(INFO, "insufficient headroom %d for %d pad\n", sg_align = bus->sdiodev->pdata->sd_sgentry_align > 4 ?
skb_headroom(pkt), pad); bus->sdiodev->pdata->sd_sgentry_align : 4;
}
/* sg entry alignment should be a divisor of block size */
WARN_ON(blksize % sg_align);
pkt_next = pktq->next;
dat_buf = (u8 *)(pkt_next->data);
/* Check head padding */
head_pad = ((unsigned long)dat_buf % head_align);
if (head_pad) {
if (skb_headroom(pkt_next) < head_pad) {
bus->sdiodev->bus_if->tx_realloc++; bus->sdiodev->bus_if->tx_realloc++;
ret = skb_cow(pkt, BRCMF_SDALIGN); head_pad = 0;
if (ret) if (skb_cow(pkt_next, head_pad))
goto done; return -ENOMEM;
pad = ((unsigned long)frame % BRCMF_SDALIGN);
} }
skb_push(pkt, pad); skb_push(pkt_next, head_pad);
frame = (u8 *) (pkt->data); dat_buf = (u8 *)(pkt_next->data);
memset(frame, 0, pad + SDPCM_HDRLEN); memset(dat_buf, 0, head_pad + SDPCM_HDRLEN);
} }
/* precondition: pad < BRCMF_SDALIGN */
/* Hardware tag: 2 byte len followed by 2 byte ~len check (all LE) */ /* Check tail padding */
len = (u16) (pkt->len); pkt_new = NULL;
*(__le16 *) frame = cpu_to_le16(len); tail_chop = pkt_next->len % sg_align;
*(((__le16 *) frame) + 1) = cpu_to_le16(~len); tail_pad = sg_align - tail_chop;
tail_pad += blksize - (pkt_next->len + tail_pad) % blksize;
if (skb_tailroom(pkt_next) < tail_pad && pkt_next->len > blksize) {
pkt_new = brcmu_pkt_buf_get_skb(tail_pad + tail_chop);
if (pkt_new == NULL)
return -ENOMEM;
memcpy(pkt_new->data,
pkt_next->data + pkt_next->len - tail_chop,
tail_chop);
*(u32 *)(pkt_new->cb) = DUMMY_SKB_FLAG + tail_chop;
skb_trim(pkt_next, pkt_next->len - tail_chop);
__skb_queue_after(pktq, pkt_next, pkt_new);
} else {
ntail = pkt_next->data_len + tail_pad -
(pkt_next->end - pkt_next->tail);
if (skb_cloned(pkt_next) || ntail > 0)
if (pskb_expand_head(pkt_next, 0, ntail, GFP_ATOMIC))
return -ENOMEM;
if (skb_linearize(pkt_next))
return -ENOMEM;
dat_buf = (u8 *)(pkt_next->data);
__skb_put(pkt_next, tail_pad);
}
/* Software tag: channel, sequence number, data offset */ /* Now prep the header */
swheader = /* 4 bytes hardware header (frame tag)
((chan << SDPCM_CHANNEL_SHIFT) & SDPCM_CHANNEL_MASK) | bus->tx_seq | * Byte 0~1: Frame length
(((pad + * Byte 2~3: Checksum, bit-wise inverse of frame length
SDPCM_HDRLEN) << SDPCM_DOFFSET_SHIFT) & SDPCM_DOFFSET_MASK); */
if (pkt_new)
pkt_len = pkt_next->len + tail_chop;
else
pkt_len = pkt_next->len - tail_pad;
*(__le16 *)dat_buf = cpu_to_le16(pkt_len);
*(((__le16 *)dat_buf) + 1) = cpu_to_le16(~pkt_len);
/* 8 bytes software header
* Byte 0: Tx sequence number
* Byte 1: 4 MSB Channel number
* Byte 2: Reserved
* Byte 3: Data offset
* Byte 4~7: Reserved
*/
sw_header = bus->tx_seq;
sw_header |= ((chan << SDPCM_CHANNEL_SHIFT) & SDPCM_CHANNEL_MASK);
sw_header |= ((head_pad + SDPCM_HDRLEN) << SDPCM_DOFFSET_SHIFT) &
SDPCM_DOFFSET_MASK;
*(((__le32 *)dat_buf) + 1) = cpu_to_le32(sw_header);
*(((__le32 *)dat_buf) + 2) = 0;
if (BRCMF_BYTES_ON() &&
((BRCMF_CTL_ON() && chan == SDPCM_CONTROL_CHANNEL) ||
(BRCMF_DATA_ON() && chan != SDPCM_CONTROL_CHANNEL)))
brcmf_dbg_hex_dump(true, pkt_next, pkt_len, "Tx Frame:\n");
else if (BRCMF_HDRS_ON())
brcmf_dbg_hex_dump(true, pkt_next, head_pad + SDPCM_HDRLEN,
"Tx Header:\n");
*(((__le32 *) frame) + 1) = cpu_to_le32(swheader); return 0;
*(((__le32 *) frame) + 2) = 0; }
#ifdef DEBUG /**
tx_packets[pkt->priority]++; * brcmf_sdio_txpkt_postp - packet post processing for transmit
#endif * @bus: brcmf_sdio structure pointer
* @pktq: packet list pointer
*
* Processes to be applied to the packet
* - Remove head padding
* - Remove tail padding
*/
static void
brcmf_sdio_txpkt_postp(struct brcmf_sdio *bus, struct sk_buff_head *pktq)
{
u8 *hdr;
u32 dat_offset;
u32 dummy_flags, chop_len;
struct sk_buff *pkt_next, *tmp, *pkt_prev;
skb_queue_walk_safe(pktq, pkt_next, tmp) {
dummy_flags = *(u32 *)(pkt_next->cb);
if (dummy_flags & DUMMY_SKB_FLAG) {
chop_len = dummy_flags & DUMMY_SKB_CHOP_LEN_MASK;
if (chop_len) {
pkt_prev = pkt_next->prev;
memcpy(pkt_prev->data + pkt_prev->len,
pkt_next->data, chop_len);
skb_put(pkt_prev, chop_len);
}
__skb_unlink(pkt_next, pktq);
brcmu_pkt_buf_free_skb(pkt_next);
} else {
hdr = pkt_next->data + SDPCM_FRAMETAG_LEN;
dat_offset = le32_to_cpu(*(__le32 *)hdr);
dat_offset = (dat_offset & SDPCM_DOFFSET_MASK) >>
SDPCM_DOFFSET_SHIFT;
skb_pull(pkt_next, dat_offset);
}
}
}
brcmf_dbg_hex_dump(BRCMF_BYTES_ON() && /* Writes a HW/SW header into the packet and sends it. */
((BRCMF_CTL_ON() && chan == SDPCM_CONTROL_CHANNEL) || /* Assumes: (a) header space already there, (b) caller holds lock */
(BRCMF_DATA_ON() && chan != SDPCM_CONTROL_CHANNEL)), static int brcmf_sdbrcm_txpkt(struct brcmf_sdio *bus, struct sk_buff *pkt,
frame, len, "Tx Frame:\n"); uint chan)
brcmf_dbg_hex_dump(!(BRCMF_BYTES_ON() && {
((BRCMF_CTL_ON() && int ret;
chan == SDPCM_CONTROL_CHANNEL) || int i;
(BRCMF_DATA_ON() && struct sk_buff_head localq;
chan != SDPCM_CONTROL_CHANNEL))) &&
BRCMF_HDRS_ON(),
frame, min_t(u16, len, 16), "TxHdr:\n");
/* Raise len to next SDIO block to eliminate tail command */ brcmf_dbg(TRACE, "Enter\n");
if (bus->roundup && bus->blocksize && (len > bus->blocksize)) {
u16 pad = bus->blocksize - (len % bus->blocksize);
if ((pad <= bus->roundup) && (pad < bus->blocksize))
len += pad;
} else if (len % BRCMF_SDALIGN) {
len += BRCMF_SDALIGN - (len % BRCMF_SDALIGN);
}
/* Some controllers have trouble with odd bytes -- round to even */ __skb_queue_head_init(&localq);
if (len & (ALIGNMENT - 1)) __skb_queue_tail(&localq, pkt);
len = roundup(len, ALIGNMENT); ret = brcmf_sdio_txpkt_prep(bus, &localq, chan);
if (ret)
goto done;
sdio_claim_host(bus->sdiodev->func[1]); sdio_claim_host(bus->sdiodev->func[1]);
ret = brcmf_sdcard_send_pkt(bus->sdiodev, bus->sdiodev->sbwad, ret = brcmf_sdcard_send_pkt(bus->sdiodev, bus->sdiodev->sbwad,
SDIO_FUNC_2, F2SYNC, pkt); SDIO_FUNC_2, F2SYNC, &localq);
bus->sdcnt.f2txdata++; bus->sdcnt.f2txdata++;
if (ret < 0) { if (ret < 0) {
...@@ -1868,8 +1967,8 @@ static int brcmf_sdbrcm_txpkt(struct brcmf_sdio *bus, struct sk_buff *pkt, ...@@ -1868,8 +1967,8 @@ static int brcmf_sdbrcm_txpkt(struct brcmf_sdio *bus, struct sk_buff *pkt,
bus->tx_seq = (bus->tx_seq + 1) % SDPCM_SEQUENCE_WRAP; bus->tx_seq = (bus->tx_seq + 1) % SDPCM_SEQUENCE_WRAP;
done: done:
/* restore pkt buffer pointer before calling tx complete routine */ brcmf_sdio_txpkt_postp(bus, &localq);
skb_pull(pkt, SDPCM_HDRLEN + pad); __skb_dequeue_tail(&localq);
brcmf_txcomplete(bus->sdiodev->dev, pkt, ret == 0); brcmf_txcomplete(bus->sdiodev->dev, pkt, ret == 0);
return ret; return ret;
} }
......
...@@ -208,7 +208,7 @@ extern int brcmf_sdio_regrw_helper(struct brcmf_sdio_dev *sdiodev, u32 addr, ...@@ -208,7 +208,7 @@ extern int brcmf_sdio_regrw_helper(struct brcmf_sdio_dev *sdiodev, u32 addr,
*/ */
extern int extern int
brcmf_sdcard_send_pkt(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn, brcmf_sdcard_send_pkt(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn,
uint flags, struct sk_buff *pkt); uint flags, struct sk_buff_head *pktq);
extern int extern int
brcmf_sdcard_send_buf(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn, brcmf_sdcard_send_buf(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn,
uint flags, u8 *buf, uint nbytes); uint flags, u8 *buf, uint nbytes);
......
...@@ -94,6 +94,10 @@ void __init brcmfmac_init_pdata(void) ...@@ -94,6 +94,10 @@ void __init brcmfmac_init_pdata(void)
* Set this to true if the SDIO host controller has higher align requirement * Set this to true if the SDIO host controller has higher align requirement
* than 32 bytes for each scatterlist item. * than 32 bytes for each scatterlist item.
* *
* sd_head_align: alignment requirement for start of data buffer
*
* sd_sgentry_align: length alignment requirement for each sg entry
*
* power_on: This function is called by the brcmfmac when the module gets * power_on: This function is called by the brcmfmac when the module gets
* loaded. This can be particularly useful for low power devices. The platform * loaded. This can be particularly useful for low power devices. The platform
* spcific routine may for example decide to power up the complete device. * spcific routine may for example decide to power up the complete device.
...@@ -121,6 +125,8 @@ struct brcmfmac_sdio_platform_data { ...@@ -121,6 +125,8 @@ struct brcmfmac_sdio_platform_data {
unsigned int oob_irq_nr; unsigned int oob_irq_nr;
unsigned long oob_irq_flags; unsigned long oob_irq_flags;
bool broken_sg_support; bool broken_sg_support;
unsigned short sd_head_align;
unsigned short sd_sgentry_align;
void (*power_on)(void); void (*power_on)(void);
void (*power_off)(void); void (*power_off)(void);
void (*reset)(void); void (*reset)(void);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment