Commit 1771afd4 authored by Ard Biesheuvel's avatar Ard Biesheuvel Committed by David S. Miller

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: 9ed4050c ("net: ethernet: ti: cpsw: add XDP support")
Cc: Grygorii Strashko <grygorii.strashko@ti.com>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent dded0892
...@@ -349,7 +349,7 @@ static void cpsw_rx_handler(void *token, int len, int status) ...@@ -349,7 +349,7 @@ static void cpsw_rx_handler(void *token, int len, int status)
struct cpsw_common *cpsw = ndev_to_cpsw(xmeta->ndev); struct cpsw_common *cpsw = ndev_to_cpsw(xmeta->ndev);
int pkt_size = cpsw->rx_packet_max; int pkt_size = cpsw->rx_packet_max;
int ret = 0, port, ch = xmeta->ch; int ret = 0, port, ch = xmeta->ch;
int headroom = CPSW_HEADROOM; int headroom = CPSW_HEADROOM_NA;
struct net_device *ndev = xmeta->ndev; struct net_device *ndev = xmeta->ndev;
struct cpsw_priv *priv; struct cpsw_priv *priv;
struct page_pool *pool; struct page_pool *pool;
...@@ -392,7 +392,7 @@ static void cpsw_rx_handler(void *token, int len, int status) ...@@ -392,7 +392,7 @@ static void cpsw_rx_handler(void *token, int len, int status)
} }
if (priv->xdp_prog) { if (priv->xdp_prog) {
int headroom = CPSW_HEADROOM, size = len; int size = len;
xdp_init_buff(&xdp, PAGE_SIZE, &priv->xdp_rxq[ch]); xdp_init_buff(&xdp, PAGE_SIZE, &priv->xdp_rxq[ch]);
if (status & CPDMA_RX_VLAN_ENCAP) { if (status & CPDMA_RX_VLAN_ENCAP) {
...@@ -442,7 +442,7 @@ static void cpsw_rx_handler(void *token, int len, int status) ...@@ -442,7 +442,7 @@ static void cpsw_rx_handler(void *token, int len, int status)
xmeta->ndev = ndev; xmeta->ndev = ndev;
xmeta->ch = ch; xmeta->ch = ch;
dma = page_pool_get_dma_addr(new_page) + CPSW_HEADROOM; dma = page_pool_get_dma_addr(new_page) + CPSW_HEADROOM_NA;
ret = cpdma_chan_submit_mapped(cpsw->rxv[ch].ch, new_page, dma, ret = cpdma_chan_submit_mapped(cpsw->rxv[ch].ch, new_page, dma,
pkt_size, 0); pkt_size, 0);
if (ret < 0) { if (ret < 0) {
......
...@@ -283,7 +283,7 @@ static void cpsw_rx_handler(void *token, int len, int status) ...@@ -283,7 +283,7 @@ static void cpsw_rx_handler(void *token, int len, int status)
{ {
struct page *new_page, *page = token; struct page *new_page, *page = token;
void *pa = page_address(page); void *pa = page_address(page);
int headroom = CPSW_HEADROOM; int headroom = CPSW_HEADROOM_NA;
struct cpsw_meta_xdp *xmeta; struct cpsw_meta_xdp *xmeta;
struct cpsw_common *cpsw; struct cpsw_common *cpsw;
struct net_device *ndev; struct net_device *ndev;
...@@ -336,7 +336,7 @@ static void cpsw_rx_handler(void *token, int len, int status) ...@@ -336,7 +336,7 @@ static void cpsw_rx_handler(void *token, int len, int status)
} }
if (priv->xdp_prog) { if (priv->xdp_prog) {
int headroom = CPSW_HEADROOM, size = len; int size = len;
xdp_init_buff(&xdp, PAGE_SIZE, &priv->xdp_rxq[ch]); xdp_init_buff(&xdp, PAGE_SIZE, &priv->xdp_rxq[ch]);
if (status & CPDMA_RX_VLAN_ENCAP) { if (status & CPDMA_RX_VLAN_ENCAP) {
...@@ -386,7 +386,7 @@ static void cpsw_rx_handler(void *token, int len, int status) ...@@ -386,7 +386,7 @@ static void cpsw_rx_handler(void *token, int len, int status)
xmeta->ndev = ndev; xmeta->ndev = ndev;
xmeta->ch = ch; xmeta->ch = ch;
dma = page_pool_get_dma_addr(new_page) + CPSW_HEADROOM; dma = page_pool_get_dma_addr(new_page) + CPSW_HEADROOM_NA;
ret = cpdma_chan_submit_mapped(cpsw->rxv[ch].ch, new_page, dma, ret = cpdma_chan_submit_mapped(cpsw->rxv[ch].ch, new_page, dma,
pkt_size, 0); pkt_size, 0);
if (ret < 0) { if (ret < 0) {
......
...@@ -1122,7 +1122,7 @@ int cpsw_fill_rx_channels(struct cpsw_priv *priv) ...@@ -1122,7 +1122,7 @@ int cpsw_fill_rx_channels(struct cpsw_priv *priv)
xmeta->ndev = priv->ndev; xmeta->ndev = priv->ndev;
xmeta->ch = ch; xmeta->ch = ch;
dma = page_pool_get_dma_addr(page) + CPSW_HEADROOM; dma = page_pool_get_dma_addr(page) + CPSW_HEADROOM_NA;
ret = cpdma_chan_idle_submit_mapped(cpsw->rxv[ch].ch, ret = cpdma_chan_idle_submit_mapped(cpsw->rxv[ch].ch,
page, dma, page, dma,
cpsw->rx_packet_max, cpsw->rx_packet_max,
......
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