@@ -1971,13 +1971,12 @@ static struct sk_buff *xgbe_create_skb(struct xgbe_prv_data *pdata,
1971
1971
{
1972
1972
struct sk_buff * skb ;
1973
1973
u8 * packet ;
1974
- unsigned int copy_len ;
1975
1974
1976
1975
skb = napi_alloc_skb (napi , rdata -> rx .hdr .dma_len );
1977
1976
if (!skb )
1978
1977
return NULL ;
1979
1978
1980
- /* Start with the header buffer which may contain just the header
1979
+ /* Pull in the header buffer which may contain just the header
1981
1980
* or the header plus data
1982
1981
*/
1983
1982
dma_sync_single_range_for_cpu (pdata -> dev , rdata -> rx .hdr .dma_base ,
@@ -1986,30 +1985,49 @@ static struct sk_buff *xgbe_create_skb(struct xgbe_prv_data *pdata,
1986
1985
1987
1986
packet = page_address (rdata -> rx .hdr .pa .pages ) +
1988
1987
rdata -> rx .hdr .pa .pages_offset ;
1989
- copy_len = (rdata -> rx .hdr_len ) ? rdata -> rx .hdr_len : len ;
1990
- copy_len = min (rdata -> rx .hdr .dma_len , copy_len );
1991
- skb_copy_to_linear_data (skb , packet , copy_len );
1992
- skb_put (skb , copy_len );
1993
-
1994
- len -= copy_len ;
1995
- if (len ) {
1996
- /* Add the remaining data as a frag */
1997
- dma_sync_single_range_for_cpu (pdata -> dev ,
1998
- rdata -> rx .buf .dma_base ,
1999
- rdata -> rx .buf .dma_off ,
2000
- rdata -> rx .buf .dma_len ,
2001
- DMA_FROM_DEVICE );
2002
-
2003
- skb_add_rx_frag (skb , skb_shinfo (skb )-> nr_frags ,
2004
- rdata -> rx .buf .pa .pages ,
2005
- rdata -> rx .buf .pa .pages_offset ,
2006
- len , rdata -> rx .buf .dma_len );
2007
- rdata -> rx .buf .pa .pages = NULL ;
2008
- }
1988
+ skb_copy_to_linear_data (skb , packet , len );
1989
+ skb_put (skb , len );
2009
1990
2010
1991
return skb ;
2011
1992
}
2012
1993
1994
+ static unsigned int xgbe_rx_buf1_len (struct xgbe_ring_data * rdata ,
1995
+ struct xgbe_packet_data * packet )
1996
+ {
1997
+ /* Always zero if not the first descriptor */
1998
+ if (!XGMAC_GET_BITS (packet -> attributes , RX_PACKET_ATTRIBUTES , FIRST ))
1999
+ return 0 ;
2000
+
2001
+ /* First descriptor with split header, return header length */
2002
+ if (rdata -> rx .hdr_len )
2003
+ return rdata -> rx .hdr_len ;
2004
+
2005
+ /* First descriptor but not the last descriptor and no split header,
2006
+ * so the full buffer was used
2007
+ */
2008
+ if (!XGMAC_GET_BITS (packet -> attributes , RX_PACKET_ATTRIBUTES , LAST ))
2009
+ return rdata -> rx .hdr .dma_len ;
2010
+
2011
+ /* First descriptor and last descriptor and no split header, so
2012
+ * calculate how much of the buffer was used
2013
+ */
2014
+ return min_t (unsigned int , rdata -> rx .hdr .dma_len , rdata -> rx .len );
2015
+ }
2016
+
2017
+ static unsigned int xgbe_rx_buf2_len (struct xgbe_ring_data * rdata ,
2018
+ struct xgbe_packet_data * packet ,
2019
+ unsigned int len )
2020
+ {
2021
+ /* Always the full buffer if not the last descriptor */
2022
+ if (!XGMAC_GET_BITS (packet -> attributes , RX_PACKET_ATTRIBUTES , LAST ))
2023
+ return rdata -> rx .buf .dma_len ;
2024
+
2025
+ /* Last descriptor so calculate how much of the buffer was used
2026
+ * for the last bit of data
2027
+ */
2028
+ return rdata -> rx .len - len ;
2029
+ }
2030
+
2013
2031
static int xgbe_tx_poll (struct xgbe_channel * channel )
2014
2032
{
2015
2033
struct xgbe_prv_data * pdata = channel -> pdata ;
@@ -2092,8 +2110,8 @@ static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
2092
2110
struct napi_struct * napi ;
2093
2111
struct sk_buff * skb ;
2094
2112
struct skb_shared_hwtstamps * hwtstamps ;
2095
- unsigned int incomplete , error , context_next , context ;
2096
- unsigned int len , rdesc_len , max_len ;
2113
+ unsigned int last , error , context_next , context ;
2114
+ unsigned int len , buf1_len , buf2_len , max_len ;
2097
2115
unsigned int received = 0 ;
2098
2116
int packet_count = 0 ;
2099
2117
@@ -2103,7 +2121,7 @@ static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
2103
2121
if (!ring )
2104
2122
return 0 ;
2105
2123
2106
- incomplete = 0 ;
2124
+ last = 0 ;
2107
2125
context_next = 0 ;
2108
2126
2109
2127
napi = (pdata -> per_channel_irq ) ? & channel -> napi : & pdata -> napi ;
@@ -2137,9 +2155,8 @@ static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
2137
2155
received ++ ;
2138
2156
ring -> cur ++ ;
2139
2157
2140
- incomplete = XGMAC_GET_BITS (packet -> attributes ,
2141
- RX_PACKET_ATTRIBUTES ,
2142
- INCOMPLETE );
2158
+ last = XGMAC_GET_BITS (packet -> attributes , RX_PACKET_ATTRIBUTES ,
2159
+ LAST );
2143
2160
context_next = XGMAC_GET_BITS (packet -> attributes ,
2144
2161
RX_PACKET_ATTRIBUTES ,
2145
2162
CONTEXT_NEXT );
@@ -2148,7 +2165,7 @@ static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
2148
2165
CONTEXT );
2149
2166
2150
2167
/* Earlier error, just drain the remaining data */
2151
- if ((incomplete || context_next ) && error )
2168
+ if ((! last || context_next ) && error )
2152
2169
goto read_again ;
2153
2170
2154
2171
if (error || packet -> errors ) {
@@ -2160,16 +2177,22 @@ static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
2160
2177
}
2161
2178
2162
2179
if (!context ) {
2163
- /* Length is cumulative, get this descriptor's length */
2164
- rdesc_len = rdata -> rx .len - len ;
2165
- len += rdesc_len ;
2180
+ /* Get the data length in the descriptor buffers */
2181
+ buf1_len = xgbe_rx_buf1_len (rdata , packet );
2182
+ len += buf1_len ;
2183
+ buf2_len = xgbe_rx_buf2_len (rdata , packet , len );
2184
+ len += buf2_len ;
2166
2185
2167
- if (rdesc_len && !skb ) {
2186
+ if (!skb ) {
2168
2187
skb = xgbe_create_skb (pdata , napi , rdata ,
2169
- rdesc_len );
2170
- if (!skb )
2188
+ buf1_len );
2189
+ if (!skb ) {
2171
2190
error = 1 ;
2172
- } else if (rdesc_len ) {
2191
+ goto skip_data ;
2192
+ }
2193
+ }
2194
+
2195
+ if (buf2_len ) {
2173
2196
dma_sync_single_range_for_cpu (pdata -> dev ,
2174
2197
rdata -> rx .buf .dma_base ,
2175
2198
rdata -> rx .buf .dma_off ,
@@ -2179,13 +2202,14 @@ static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
2179
2202
skb_add_rx_frag (skb , skb_shinfo (skb )-> nr_frags ,
2180
2203
rdata -> rx .buf .pa .pages ,
2181
2204
rdata -> rx .buf .pa .pages_offset ,
2182
- rdesc_len ,
2205
+ buf2_len ,
2183
2206
rdata -> rx .buf .dma_len );
2184
2207
rdata -> rx .buf .pa .pages = NULL ;
2185
2208
}
2186
2209
}
2187
2210
2188
- if (incomplete || context_next )
2211
+ skip_data :
2212
+ if (!last || context_next )
2189
2213
goto read_again ;
2190
2214
2191
2215
if (!skb )
@@ -2243,7 +2267,7 @@ static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
2243
2267
}
2244
2268
2245
2269
/* Check if we need to save state before leaving */
2246
- if (received && (incomplete || context_next )) {
2270
+ if (received && (! last || context_next )) {
2247
2271
rdata = XGBE_GET_DESC_DATA (ring , ring -> cur );
2248
2272
rdata -> state_saved = 1 ;
2249
2273
rdata -> state .skb = skb ;
0 commit comments