Skip to content

Commit 1771afd

Browse files
ardbiesheuveldavem330
authored andcommitted
net: cpsw: avoid alignment faults by taking NET_IP_ALIGN into account
Both versions of the CPSW driver declare a CPSW_HEADROOM_NA macro that takes NET_IP_ALIGN into account, but fail to use it appropriately when storing incoming packets in memory. This results in the IPv4 source and destination addresses to appear misaligned in memory, which causes aligment faults that need to be fixed up in software. So let's switch from CPSW_HEADROOM to CPSW_HEADROOM_NA where needed. This gets rid of any alignment faults on the RX path on a Beaglebone White. Fixes: 9ed4050 ("net: ethernet: ti: cpsw: add XDP support") Cc: Grygorii Strashko <[email protected]> Cc: Ilias Apalodimas <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent dded089 commit 1771afd

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

drivers/net/ethernet/ti/cpsw.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ static void cpsw_rx_handler(void *token, int len, int status)
349349
struct cpsw_common *cpsw = ndev_to_cpsw(xmeta->ndev);
350350
int pkt_size = cpsw->rx_packet_max;
351351
int ret = 0, port, ch = xmeta->ch;
352-
int headroom = CPSW_HEADROOM;
352+
int headroom = CPSW_HEADROOM_NA;
353353
struct net_device *ndev = xmeta->ndev;
354354
struct cpsw_priv *priv;
355355
struct page_pool *pool;
@@ -392,7 +392,7 @@ static void cpsw_rx_handler(void *token, int len, int status)
392392
}
393393

394394
if (priv->xdp_prog) {
395-
int headroom = CPSW_HEADROOM, size = len;
395+
int size = len;
396396

397397
xdp_init_buff(&xdp, PAGE_SIZE, &priv->xdp_rxq[ch]);
398398
if (status & CPDMA_RX_VLAN_ENCAP) {
@@ -442,7 +442,7 @@ static void cpsw_rx_handler(void *token, int len, int status)
442442
xmeta->ndev = ndev;
443443
xmeta->ch = ch;
444444

445-
dma = page_pool_get_dma_addr(new_page) + CPSW_HEADROOM;
445+
dma = page_pool_get_dma_addr(new_page) + CPSW_HEADROOM_NA;
446446
ret = cpdma_chan_submit_mapped(cpsw->rxv[ch].ch, new_page, dma,
447447
pkt_size, 0);
448448
if (ret < 0) {

drivers/net/ethernet/ti/cpsw_new.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ static void cpsw_rx_handler(void *token, int len, int status)
283283
{
284284
struct page *new_page, *page = token;
285285
void *pa = page_address(page);
286-
int headroom = CPSW_HEADROOM;
286+
int headroom = CPSW_HEADROOM_NA;
287287
struct cpsw_meta_xdp *xmeta;
288288
struct cpsw_common *cpsw;
289289
struct net_device *ndev;
@@ -336,7 +336,7 @@ static void cpsw_rx_handler(void *token, int len, int status)
336336
}
337337

338338
if (priv->xdp_prog) {
339-
int headroom = CPSW_HEADROOM, size = len;
339+
int size = len;
340340

341341
xdp_init_buff(&xdp, PAGE_SIZE, &priv->xdp_rxq[ch]);
342342
if (status & CPDMA_RX_VLAN_ENCAP) {
@@ -386,7 +386,7 @@ static void cpsw_rx_handler(void *token, int len, int status)
386386
xmeta->ndev = ndev;
387387
xmeta->ch = ch;
388388

389-
dma = page_pool_get_dma_addr(new_page) + CPSW_HEADROOM;
389+
dma = page_pool_get_dma_addr(new_page) + CPSW_HEADROOM_NA;
390390
ret = cpdma_chan_submit_mapped(cpsw->rxv[ch].ch, new_page, dma,
391391
pkt_size, 0);
392392
if (ret < 0) {

drivers/net/ethernet/ti/cpsw_priv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ int cpsw_fill_rx_channels(struct cpsw_priv *priv)
11221122
xmeta->ndev = priv->ndev;
11231123
xmeta->ch = ch;
11241124

1125-
dma = page_pool_get_dma_addr(page) + CPSW_HEADROOM;
1125+
dma = page_pool_get_dma_addr(page) + CPSW_HEADROOM_NA;
11261126
ret = cpdma_chan_idle_submit_mapped(cpsw->rxv[ch].ch,
11271127
page, dma,
11281128
cpsw->rx_packet_max,

0 commit comments

Comments
 (0)