@@ -1045,61 +1045,23 @@ static bool i40e_can_reuse_rx_page(struct i40e_rx_buffer *rx_buffer)
10451045 * @size: packet length from rx_desc
10461046 *
10471047 * This function will add the data contained in rx_buffer->page to the skb.
1048- * This is done either through a direct copy if the data in the buffer is
1049- * less than the skb header size, otherwise it will just attach the page as
1050- * a frag to the skb.
1048+ * It will just attach the page as a frag to the skb.
10511049 *
1052- * The function will then update the page offset if necessary and return
1053- * true if the buffer can be reused by the adapter.
1050+ * The function will then update the page offset.
10541051 **/
10551052static void i40e_add_rx_frag (struct i40e_ring * rx_ring ,
10561053 struct i40e_rx_buffer * rx_buffer ,
10571054 struct sk_buff * skb ,
10581055 unsigned int size )
10591056{
1060- struct page * page = rx_buffer -> page ;
1061- unsigned char * va = page_address (page ) + rx_buffer -> page_offset ;
10621057#if (PAGE_SIZE < 8192 )
10631058 unsigned int truesize = I40E_RXBUFFER_2048 ;
10641059#else
1065- unsigned int truesize = ALIGN (size , L1_CACHE_BYTES );
1060+ unsigned int truesize = SKB_DATA_ALIGN (size );
10661061#endif
1067- unsigned int pull_len ;
1068-
1069- if (unlikely (skb_is_nonlinear (skb )))
1070- goto add_tail_frag ;
1071-
1072- /* will the data fit in the skb we allocated? if so, just
1073- * copy it as it is pretty small anyway
1074- */
1075- if (size <= I40E_RX_HDR_SIZE ) {
1076- memcpy (__skb_put (skb , size ), va , ALIGN (size , sizeof (long )));
1077-
1078- /* page is to be freed, increase pagecnt_bias instead of
1079- * decreasing page count.
1080- */
1081- rx_buffer -> pagecnt_bias ++ ;
1082- return ;
1083- }
1084-
1085- /* we need the header to contain the greater of either
1086- * ETH_HLEN or 60 bytes if the skb->len is less than
1087- * 60 for skb_pad.
1088- */
1089- pull_len = eth_get_headlen (va , I40E_RX_HDR_SIZE );
1090-
1091- /* align pull length to size of long to optimize
1092- * memcpy performance
1093- */
1094- memcpy (__skb_put (skb , pull_len ), va , ALIGN (pull_len , sizeof (long )));
1095-
1096- /* update all of the pointers */
1097- va += pull_len ;
1098- size -= pull_len ;
10991062
1100- add_tail_frag :
1101- skb_add_rx_frag (skb , skb_shinfo (skb )-> nr_frags , page ,
1102- (unsigned long )va & ~PAGE_MASK , size , truesize );
1063+ skb_add_rx_frag (skb , skb_shinfo (skb )-> nr_frags , rx_buffer -> page ,
1064+ rx_buffer -> page_offset , size , truesize );
11031065
11041066 /* page is being used so we must update the page offset */
11051067#if (PAGE_SIZE < 8192 )
@@ -1139,45 +1101,66 @@ static struct i40e_rx_buffer *i40e_get_rx_buffer(struct i40e_ring *rx_ring,
11391101}
11401102
11411103/**
1142- * i40evf_fetch_rx_buffer - Allocate skb and populate it
1104+ * i40e_construct_skb - Allocate skb and populate it
11431105 * @rx_ring: rx descriptor ring to transact packets on
11441106 * @rx_buffer: rx buffer to pull data from
11451107 * @size: size of buffer to add to skb
11461108 *
1147- * This function allocates an skb on the fly, and populates it with the page
1148- * data from the current receive descriptor, taking care to set up the skb
1149- * correctly, as well as handling calling the page recycle function if
1150- * necessary.
1109+ * This function allocates an skb. It then populates it with the page
1110+ * data from the current receive descriptor, taking care to set up the
1111+ * skb correctly.
11511112 */
1152- static inline
1153- struct sk_buff * i40evf_fetch_rx_buffer (struct i40e_ring * rx_ring ,
1154- struct i40e_rx_buffer * rx_buffer ,
1155- struct sk_buff * skb ,
1156- unsigned int size )
1113+ static struct sk_buff * i40e_construct_skb (struct i40e_ring * rx_ring ,
1114+ struct i40e_rx_buffer * rx_buffer ,
1115+ unsigned int size )
11571116{
1158- if (likely (!skb )) {
1159- void * page_addr = page_address (rx_buffer -> page ) +
1160- rx_buffer -> page_offset ;
1117+ void * va = page_address (rx_buffer -> page ) + rx_buffer -> page_offset ;
1118+ #if (PAGE_SIZE < 8192 )
1119+ unsigned int truesize = I40E_RXBUFFER_2048 ;
1120+ #else
1121+ unsigned int truesize = SKB_DATA_ALIGN (size );
1122+ #endif
1123+ unsigned int headlen ;
1124+ struct sk_buff * skb ;
11611125
1162- /* prefetch first cache line of first page */
1163- prefetch (page_addr );
1126+ /* prefetch first cache line of first page */
1127+ prefetch (va );
11641128#if L1_CACHE_BYTES < 128
1165- prefetch (page_addr + L1_CACHE_BYTES );
1129+ prefetch (va + L1_CACHE_BYTES );
11661130#endif
11671131
1168- /* allocate a skb to store the frags */
1169- skb = __napi_alloc_skb (& rx_ring -> q_vector -> napi ,
1170- I40E_RX_HDR_SIZE ,
1171- GFP_ATOMIC | __GFP_NOWARN );
1172- if (unlikely (!skb )) {
1173- rx_ring -> rx_stats .alloc_buff_failed ++ ;
1174- rx_buffer -> pagecnt_bias ++ ;
1175- return NULL ;
1176- }
1177- }
1132+ /* allocate a skb to store the frags */
1133+ skb = __napi_alloc_skb (& rx_ring -> q_vector -> napi ,
1134+ I40E_RX_HDR_SIZE ,
1135+ GFP_ATOMIC | __GFP_NOWARN );
1136+ if (unlikely (!skb ))
1137+ return NULL ;
1138+
1139+ /* Determine available headroom for copy */
1140+ headlen = size ;
1141+ if (headlen > I40E_RX_HDR_SIZE )
1142+ headlen = eth_get_headlen (va , I40E_RX_HDR_SIZE );
11781143
1179- /* pull page into skb */
1180- i40e_add_rx_frag (rx_ring , rx_buffer , skb , size );
1144+ /* align pull length to size of long to optimize memcpy performance */
1145+ memcpy (__skb_put (skb , headlen ), va , ALIGN (headlen , sizeof (long )));
1146+
1147+ /* update all of the pointers */
1148+ size -= headlen ;
1149+ if (size ) {
1150+ skb_add_rx_frag (skb , 0 , rx_buffer -> page ,
1151+ rx_buffer -> page_offset + headlen ,
1152+ size , truesize );
1153+
1154+ /* buffer is used by skb, update page_offset */
1155+ #if (PAGE_SIZE < 8192 )
1156+ rx_buffer -> page_offset ^= truesize ;
1157+ #else
1158+ rx_buffer -> page_offset += truesize ;
1159+ #endif
1160+ } else {
1161+ /* buffer is unused, reset bias back to rx_buffer */
1162+ rx_buffer -> pagecnt_bias ++ ;
1163+ }
11811164
11821165 return skb ;
11831166}
@@ -1297,9 +1280,18 @@ static int i40e_clean_rx_irq(struct i40e_ring *rx_ring, int budget)
12971280
12981281 rx_buffer = i40e_get_rx_buffer (rx_ring , size );
12991282
1300- skb = i40evf_fetch_rx_buffer (rx_ring , rx_buffer , skb , size );
1301- if (!skb )
1283+ /* retrieve a buffer from the ring */
1284+ if (skb )
1285+ i40e_add_rx_frag (rx_ring , rx_buffer , skb , size );
1286+ else
1287+ skb = i40e_construct_skb (rx_ring , rx_buffer , size );
1288+
1289+ /* exit if we failed to retrieve a buffer */
1290+ if (!skb ) {
1291+ rx_ring -> rx_stats .alloc_buff_failed ++ ;
1292+ rx_buffer -> pagecnt_bias ++ ;
13021293 break ;
1294+ }
13031295
13041296 i40e_put_rx_buffer (rx_ring , rx_buffer );
13051297 cleaned_count ++ ;
0 commit comments