Skip to content

Commit 7d9ca34

Browse files
tlendackydavem330
authored andcommitted
amd-xgbe: Rework the Rx path SKB allocation
Rework the SKB allocation so that all of the buffers of the first descriptor are handled in the SKB allocation routine. After copying the data in the header buffer (which can be just the header if split header processing succeeded for header plus data if split header processing did not succeed) into the SKB, check for remaining data in the receive buffer. If there is data remaining in the receive buffer, add that as a frag to the SKB. Once an SKB has been allocated, all other descriptors are added as frags to the SKB. Signed-off-by: Tom Lendacky <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 34bf65d commit 7d9ca34

File tree

3 files changed

+37
-33
lines changed

3 files changed

+37
-33
lines changed

drivers/net/ethernet/amd/xgbe/xgbe-desc.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,6 @@ static void xgbe_unmap_rdata(struct xgbe_prv_data *pdata,
481481

482482
if (rdata->state_saved) {
483483
rdata->state_saved = 0;
484-
rdata->state.incomplete = 0;
485-
rdata->state.context_next = 0;
486484
rdata->state.skb = NULL;
487485
rdata->state.len = 0;
488486
rdata->state.error = 0;

drivers/net/ethernet/amd/xgbe/xgbe-drv.c

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,9 +1822,10 @@ static void xgbe_rx_refresh(struct xgbe_channel *channel)
18221822
lower_32_bits(rdata->rdesc_dma));
18231823
}
18241824

1825-
static struct sk_buff *xgbe_create_skb(struct napi_struct *napi,
1825+
static struct sk_buff *xgbe_create_skb(struct xgbe_prv_data *pdata,
1826+
struct napi_struct *napi,
18261827
struct xgbe_ring_data *rdata,
1827-
unsigned int *len)
1828+
unsigned int len)
18281829
{
18291830
struct sk_buff *skb;
18301831
u8 *packet;
@@ -1834,14 +1835,31 @@ static struct sk_buff *xgbe_create_skb(struct napi_struct *napi,
18341835
if (!skb)
18351836
return NULL;
18361837

1838+
/* Start with the header buffer which may contain just the header
1839+
* or the header plus data
1840+
*/
1841+
dma_sync_single_for_cpu(pdata->dev, rdata->rx.hdr.dma,
1842+
rdata->rx.hdr.dma_len, DMA_FROM_DEVICE);
1843+
18371844
packet = page_address(rdata->rx.hdr.pa.pages) +
18381845
rdata->rx.hdr.pa.pages_offset;
1839-
copy_len = (rdata->rx.hdr_len) ? rdata->rx.hdr_len : *len;
1846+
copy_len = (rdata->rx.hdr_len) ? rdata->rx.hdr_len : len;
18401847
copy_len = min(rdata->rx.hdr.dma_len, copy_len);
18411848
skb_copy_to_linear_data(skb, packet, copy_len);
18421849
skb_put(skb, copy_len);
18431850

1844-
*len -= copy_len;
1851+
len -= copy_len;
1852+
if (len) {
1853+
/* Add the remaining data as a frag */
1854+
dma_sync_single_for_cpu(pdata->dev, rdata->rx.buf.dma,
1855+
rdata->rx.buf.dma_len, DMA_FROM_DEVICE);
1856+
1857+
skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
1858+
rdata->rx.buf.pa.pages,
1859+
rdata->rx.buf.pa.pages_offset,
1860+
len, rdata->rx.buf.dma_len);
1861+
rdata->rx.buf.pa.pages = NULL;
1862+
}
18451863

18461864
return skb;
18471865
}
@@ -1923,7 +1941,7 @@ static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
19231941
struct sk_buff *skb;
19241942
struct skb_shared_hwtstamps *hwtstamps;
19251943
unsigned int incomplete, error, context_next, context;
1926-
unsigned int len, put_len, max_len;
1944+
unsigned int len, rdesc_len, max_len;
19271945
unsigned int received = 0;
19281946
int packet_count = 0;
19291947

@@ -1933,6 +1951,9 @@ static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
19331951
if (!ring)
19341952
return 0;
19351953

1954+
incomplete = 0;
1955+
context_next = 0;
1956+
19361957
napi = (pdata->per_channel_irq) ? &channel->napi : &pdata->napi;
19371958

19381959
rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
@@ -1942,15 +1963,11 @@ static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
19421963

19431964
/* First time in loop see if we need to restore state */
19441965
if (!received && rdata->state_saved) {
1945-
incomplete = rdata->state.incomplete;
1946-
context_next = rdata->state.context_next;
19471966
skb = rdata->state.skb;
19481967
error = rdata->state.error;
19491968
len = rdata->state.len;
19501969
} else {
19511970
memset(packet, 0, sizeof(*packet));
1952-
incomplete = 0;
1953-
context_next = 0;
19541971
skb = NULL;
19551972
error = 0;
19561973
len = 0;
@@ -1991,23 +2008,16 @@ static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
19912008
}
19922009

19932010
if (!context) {
1994-
put_len = rdata->rx.len - len;
1995-
len += put_len;
1996-
1997-
if (!skb) {
1998-
dma_sync_single_for_cpu(pdata->dev,
1999-
rdata->rx.hdr.dma,
2000-
rdata->rx.hdr.dma_len,
2001-
DMA_FROM_DEVICE);
2002-
2003-
skb = xgbe_create_skb(napi, rdata, &put_len);
2004-
if (!skb) {
2011+
/* Length is cumulative, get this descriptor's length */
2012+
rdesc_len = rdata->rx.len - len;
2013+
len += rdesc_len;
2014+
2015+
if (rdesc_len && !skb) {
2016+
skb = xgbe_create_skb(pdata, napi, rdata,
2017+
rdesc_len);
2018+
if (!skb)
20052019
error = 1;
2006-
goto skip_data;
2007-
}
2008-
}
2009-
2010-
if (put_len) {
2020+
} else if (rdesc_len) {
20112021
dma_sync_single_for_cpu(pdata->dev,
20122022
rdata->rx.buf.dma,
20132023
rdata->rx.buf.dma_len,
@@ -2016,12 +2026,12 @@ static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
20162026
skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
20172027
rdata->rx.buf.pa.pages,
20182028
rdata->rx.buf.pa.pages_offset,
2019-
put_len, rdata->rx.buf.dma_len);
2029+
rdesc_len,
2030+
rdata->rx.buf.dma_len);
20202031
rdata->rx.buf.pa.pages = NULL;
20212032
}
20222033
}
20232034

2024-
skip_data:
20252035
if (incomplete || context_next)
20262036
goto read_again;
20272037

@@ -2084,8 +2094,6 @@ static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
20842094
if (received && (incomplete || context_next)) {
20852095
rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
20862096
rdata->state_saved = 1;
2087-
rdata->state.incomplete = incomplete;
2088-
rdata->state.context_next = context_next;
20892097
rdata->state.skb = skb;
20902098
rdata->state.len = len;
20912099
rdata->state.error = error;

drivers/net/ethernet/amd/xgbe/xgbe.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,6 @@ struct xgbe_ring_data {
334334
*/
335335
unsigned int state_saved;
336336
struct {
337-
unsigned int incomplete;
338-
unsigned int context_next;
339337
struct sk_buff *skb;
340338
unsigned int len;
341339
unsigned int error;

0 commit comments

Comments
 (0)