Skip to content

Commit e156103

Browse files
yogeshpowarlinvjw
authored andcommitted
mwifiex: 4-byte alignment in mwifiex_process_sta_txpd()
In XMIT path, the skb that we get from the kernel itself is not aligned with 4-byte boundary on some embedded platforms. Had it not been the presence of tx_pkt_offset field in txpd, 4 byte memory alignment was not possible without memmove of entire skb. And that would have increased MIPS instead of reducing. With this patch few memory cycles can be saved while fetching interface header and txpd structure because of 4 bytes memory alignment. Reported-by: Philip Rakity <prakity@marvell.com> Signed-off-by: Yogesh Ashok Powar <yogeshp@marvell.com> Tested-by: Philip Rakity <prakity@marvell.com> Signed-off-by: Bing Zhao <bzhao@marvell.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
1 parent 38869d7 commit e156103

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

‎drivers/net/wireless/mwifiex/decl.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030

3131
#define MWIFIEX_MAX_BSS_NUM (1)
3232

33-
#define MWIFIEX_MIN_DATA_HEADER_LEN 32 /* (sizeof(mwifiex_txpd)) */
33+
#define MWIFIEX_MIN_DATA_HEADER_LEN 36 /* sizeof(mwifiex_txpd)
34+
* + 4 byte alignment
35+
*/
3436

3537
#define MWIFIEX_MAX_TX_BASTREAM_SUPPORTED 2
3638
#define MWIFIEX_MAX_RX_BASTREAM_SUPPORTED 16

‎drivers/net/wireless/mwifiex/sta_tx.c‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ void *mwifiex_process_sta_txpd(struct mwifiex_private *priv,
4747
struct mwifiex_adapter *adapter = priv->adapter;
4848
struct txpd *local_tx_pd;
4949
struct mwifiex_txinfo *tx_info = MWIFIEX_SKB_TXCB(skb);
50+
u8 pad;
5051

5152
if (!skb->len) {
5253
dev_err(adapter->dev, "Tx: bad packet length: %d\n",
@@ -55,15 +56,19 @@ void *mwifiex_process_sta_txpd(struct mwifiex_private *priv,
5556
return skb->data;
5657
}
5758

58-
BUG_ON(skb_headroom(skb) < (sizeof(*local_tx_pd) + INTF_HEADER_LEN));
59-
skb_push(skb, sizeof(*local_tx_pd));
59+
/* If skb->data is not aligned; add padding */
60+
pad = (4 - (((void *)skb->data - NULL) & 0x3)) % 4;
61+
62+
BUG_ON(skb_headroom(skb) < (sizeof(*local_tx_pd) + INTF_HEADER_LEN
63+
+ pad));
64+
skb_push(skb, sizeof(*local_tx_pd) + pad);
6065

6166
local_tx_pd = (struct txpd *) skb->data;
6267
memset(local_tx_pd, 0, sizeof(struct txpd));
6368
local_tx_pd->bss_num = priv->bss_num;
6469
local_tx_pd->bss_type = priv->bss_type;
6570
local_tx_pd->tx_pkt_length = cpu_to_le16((u16) (skb->len -
66-
sizeof(struct txpd)));
71+
(sizeof(struct txpd) + pad)));
6772

6873
local_tx_pd->priority = (u8) skb->priority;
6974
local_tx_pd->pkt_delay_2ms =
@@ -88,7 +93,7 @@ void *mwifiex_process_sta_txpd(struct mwifiex_private *priv,
8893
}
8994

9095
/* Offset of actual data */
91-
local_tx_pd->tx_pkt_offset = cpu_to_le16(sizeof(struct txpd));
96+
local_tx_pd->tx_pkt_offset = cpu_to_le16(sizeof(struct txpd) + pad);
9297

9398
/* make space for INTF_HEADER_LEN */
9499
skb_push(skb, INTF_HEADER_LEN);

0 commit comments

Comments
 (0)