@@ -75,6 +75,10 @@ static struct netvsc_device *alloc_net_device(void)
75
75
atomic_set (& net_device -> open_cnt , 0 );
76
76
net_device -> max_pkt = RNDIS_MAX_PKT_DEFAULT ;
77
77
net_device -> pkt_align = RNDIS_PKT_ALIGN_DEFAULT ;
78
+
79
+ net_device -> recv_section_size = NETVSC_RECV_SECTION_SIZE ;
80
+ net_device -> send_section_size = NETVSC_SEND_SECTION_SIZE ;
81
+
78
82
init_completion (& net_device -> channel_init_wait );
79
83
init_waitqueue_head (& net_device -> subchan_open );
80
84
@@ -143,6 +147,7 @@ static void netvsc_destroy_buf(struct hv_device *device)
143
147
"revoke receive buffer to netvsp\n" );
144
148
return ;
145
149
}
150
+ net_device -> recv_section_cnt = 0 ;
146
151
}
147
152
148
153
/* Teardown the gpadl on the vsp end */
@@ -173,7 +178,7 @@ static void netvsc_destroy_buf(struct hv_device *device)
173
178
* NVSP_MSG1_TYPE_SEND_SEND_BUF msg) therefore, we need
174
179
* to send a revoke msg here
175
180
*/
176
- if (net_device -> send_section_size ) {
181
+ if (net_device -> send_section_cnt ) {
177
182
/* Send the revoke receive buffer */
178
183
revoke_packet = & net_device -> revoke_packet ;
179
184
memset (revoke_packet , 0 , sizeof (struct nvsp_message ));
@@ -205,6 +210,7 @@ static void netvsc_destroy_buf(struct hv_device *device)
205
210
"revoke send buffer to netvsp\n" );
206
211
return ;
207
212
}
213
+ net_device -> send_section_cnt = 0 ;
208
214
}
209
215
/* Teardown the gpadl on the vsp end */
210
216
if (net_device -> send_buf_gpadl_handle ) {
@@ -244,25 +250,25 @@ int netvsc_alloc_recv_comp_ring(struct netvsc_device *net_device, u32 q_idx)
244
250
}
245
251
246
252
static int netvsc_init_buf (struct hv_device * device ,
247
- struct netvsc_device * net_device )
253
+ struct netvsc_device * net_device ,
254
+ const struct netvsc_device_info * device_info )
248
255
{
249
- int ret = 0 ;
250
- struct nvsp_message * init_packet ;
251
256
struct nvsp_1_message_send_receive_buffer_complete * resp ;
252
- struct net_device * ndev ;
257
+ struct net_device * ndev = hv_get_drvdata (device );
258
+ struct nvsp_message * init_packet ;
259
+ unsigned int buf_size ;
253
260
size_t map_words ;
254
- int node ;
255
-
256
- ndev = hv_get_drvdata (device );
261
+ int ret = 0 ;
257
262
258
- node = cpu_to_node (device -> channel -> target_cpu );
259
- net_device -> recv_buf = vzalloc_node (net_device -> recv_buf_size , node );
260
- if (!net_device -> recv_buf )
261
- net_device -> recv_buf = vzalloc (net_device -> recv_buf_size );
263
+ /* Get receive buffer area. */
264
+ buf_size = device_info -> recv_sections * net_device -> recv_section_size ;
265
+ buf_size = roundup (buf_size , PAGE_SIZE );
262
266
267
+ net_device -> recv_buf = vzalloc (buf_size );
263
268
if (!net_device -> recv_buf ) {
264
- netdev_err (ndev , "unable to allocate receive "
265
- "buffer of size %d\n" , net_device -> recv_buf_size );
269
+ netdev_err (ndev ,
270
+ "unable to allocate receive buffer of size %u\n" ,
271
+ buf_size );
266
272
ret = - ENOMEM ;
267
273
goto cleanup ;
268
274
}
@@ -273,7 +279,7 @@ static int netvsc_init_buf(struct hv_device *device,
273
279
* than the channel to establish the gpadl handle.
274
280
*/
275
281
ret = vmbus_establish_gpadl (device -> channel , net_device -> recv_buf ,
276
- net_device -> recv_buf_size ,
282
+ buf_size ,
277
283
& net_device -> recv_buf_gpadl_handle );
278
284
if (ret != 0 ) {
279
285
netdev_err (ndev ,
@@ -319,33 +325,31 @@ static int netvsc_init_buf(struct hv_device *device,
319
325
resp -> num_sections , resp -> sections [0 ].sub_alloc_size ,
320
326
resp -> sections [0 ].num_sub_allocs );
321
327
322
- net_device -> recv_section_cnt = resp -> num_sections ;
323
-
324
- /*
325
- * For 1st release, there should only be 1 section that represents the
326
- * entire receive buffer
327
- */
328
- if (net_device -> recv_section_cnt != 1 ||
329
- resp -> sections [0 ].offset != 0 ) {
328
+ /* There should only be one section for the entire receive buffer */
329
+ if (resp -> num_sections != 1 || resp -> sections [0 ].offset != 0 ) {
330
330
ret = - EINVAL ;
331
331
goto cleanup ;
332
332
}
333
333
334
+ net_device -> recv_section_size = resp -> sections [0 ].sub_alloc_size ;
335
+ net_device -> recv_section_cnt = resp -> sections [0 ].num_sub_allocs ;
336
+
334
337
/* Setup receive completion ring */
335
338
net_device -> recv_completion_cnt
336
- = round_up (resp -> sections [ 0 ]. num_sub_allocs + 1 ,
339
+ = round_up (net_device -> recv_section_cnt + 1 ,
337
340
PAGE_SIZE / sizeof (u64 ));
338
341
ret = netvsc_alloc_recv_comp_ring (net_device , 0 );
339
342
if (ret )
340
343
goto cleanup ;
341
344
342
345
/* Now setup the send buffer. */
343
- net_device -> send_buf = vzalloc_node (net_device -> send_buf_size , node );
344
- if (!net_device -> send_buf )
345
- net_device -> send_buf = vzalloc (net_device -> send_buf_size );
346
+ buf_size = device_info -> send_sections * net_device -> send_section_size ;
347
+ buf_size = round_up (buf_size , PAGE_SIZE );
348
+
349
+ net_device -> send_buf = vzalloc (buf_size );
346
350
if (!net_device -> send_buf ) {
347
- netdev_err (ndev , "unable to allocate send "
348
- "buffer of size %d\n" , net_device -> send_buf_size );
351
+ netdev_err (ndev , "unable to allocate send buffer of size %u\n" ,
352
+ buf_size );
349
353
ret = - ENOMEM ;
350
354
goto cleanup ;
351
355
}
@@ -355,7 +359,7 @@ static int netvsc_init_buf(struct hv_device *device,
355
359
* than the channel to establish the gpadl handle.
356
360
*/
357
361
ret = vmbus_establish_gpadl (device -> channel , net_device -> send_buf ,
358
- net_device -> send_buf_size ,
362
+ buf_size ,
359
363
& net_device -> send_buf_gpadl_handle );
360
364
if (ret != 0 ) {
361
365
netdev_err (ndev ,
@@ -400,10 +404,8 @@ static int netvsc_init_buf(struct hv_device *device,
400
404
net_device -> send_section_size = init_packet -> msg .
401
405
v1_msg .send_send_buf_complete .section_size ;
402
406
403
- /* Section count is simply the size divided by the section size.
404
- */
405
- net_device -> send_section_cnt =
406
- net_device -> send_buf_size / net_device -> send_section_size ;
407
+ /* Section count is simply the size divided by the section size. */
408
+ net_device -> send_section_cnt = buf_size / net_device -> send_section_size ;
407
409
408
410
netdev_dbg (ndev , "Send section size: %d, Section count:%d\n" ,
409
411
net_device -> send_section_size , net_device -> send_section_cnt );
@@ -481,7 +483,8 @@ static int negotiate_nvsp_ver(struct hv_device *device,
481
483
}
482
484
483
485
static int netvsc_connect_vsp (struct hv_device * device ,
484
- struct netvsc_device * net_device )
486
+ struct netvsc_device * net_device ,
487
+ const struct netvsc_device_info * device_info )
485
488
{
486
489
const u32 ver_list [] = {
487
490
NVSP_PROTOCOL_VERSION_1 , NVSP_PROTOCOL_VERSION_2 ,
@@ -531,14 +534,8 @@ static int netvsc_connect_vsp(struct hv_device *device,
531
534
if (ret != 0 )
532
535
goto cleanup ;
533
536
534
- /* Post the big receive buffer to NetVSP */
535
- if (net_device -> nvsp_version <= NVSP_PROTOCOL_VERSION_2 )
536
- net_device -> recv_buf_size = NETVSC_RECEIVE_BUFFER_SIZE_LEGACY ;
537
- else
538
- net_device -> recv_buf_size = NETVSC_RECEIVE_BUFFER_SIZE ;
539
- net_device -> send_buf_size = NETVSC_SEND_BUFFER_SIZE ;
540
537
541
- ret = netvsc_init_buf (device , net_device );
538
+ ret = netvsc_init_buf (device , net_device , device_info );
542
539
543
540
cleanup :
544
541
return ret ;
@@ -886,7 +883,9 @@ int netvsc_send(struct net_device_context *ndev_ctx,
886
883
} else if (pktlen + net_device -> pkt_align <
887
884
net_device -> send_section_size ) {
888
885
section_index = netvsc_get_next_send_section (net_device );
889
- if (section_index != NETVSC_INVALID_INDEX ) {
886
+ if (unlikely (section_index == NETVSC_INVALID_INDEX )) {
887
+ ++ ndev_ctx -> eth_stats .tx_send_full ;
888
+ } else {
890
889
move_pkt_msd (& msd_send , & msd_skb , msdp );
891
890
msd_len = 0 ;
892
891
}
@@ -952,9 +951,10 @@ int netvsc_send(struct net_device_context *ndev_ctx,
952
951
}
953
952
954
953
/* Send pending recv completions */
955
- static int send_recv_completions (struct netvsc_channel * nvchan )
954
+ static int send_recv_completions (struct net_device * ndev ,
955
+ struct netvsc_device * nvdev ,
956
+ struct netvsc_channel * nvchan )
956
957
{
957
- struct netvsc_device * nvdev = nvchan -> net_device ;
958
958
struct multi_recv_comp * mrc = & nvchan -> mrc ;
959
959
struct recv_comp_msg {
960
960
struct nvsp_message_header hdr ;
@@ -972,8 +972,12 @@ static int send_recv_completions(struct netvsc_channel *nvchan)
972
972
msg .status = rcd -> status ;
973
973
ret = vmbus_sendpacket (nvchan -> channel , & msg , sizeof (msg ),
974
974
rcd -> tid , VM_PKT_COMP , 0 );
975
- if (unlikely (ret ))
975
+ if (unlikely (ret )) {
976
+ struct net_device_context * ndev_ctx = netdev_priv (ndev );
977
+
978
+ ++ ndev_ctx -> eth_stats .rx_comp_busy ;
976
979
return ret ;
980
+ }
977
981
978
982
if (++ mrc -> first == nvdev -> recv_completion_cnt )
979
983
mrc -> first = 0 ;
@@ -1014,7 +1018,7 @@ static void enq_receive_complete(struct net_device *ndev,
1014
1018
recv_comp_slot_avail (nvdev , mrc , & filled , & avail );
1015
1019
1016
1020
if (unlikely (filled > NAPI_POLL_WEIGHT )) {
1017
- send_recv_completions (nvchan );
1021
+ send_recv_completions (ndev , nvdev , nvchan );
1018
1022
recv_comp_slot_avail (nvdev , mrc , & filled , & avail );
1019
1023
}
1020
1024
@@ -1191,17 +1195,13 @@ int netvsc_poll(struct napi_struct *napi, int budget)
1191
1195
nvchan -> desc = hv_pkt_iter_next (channel , nvchan -> desc );
1192
1196
}
1193
1197
1194
- /* if ring is empty, signal host */
1195
- if (!nvchan -> desc )
1196
- hv_pkt_iter_close (channel );
1197
-
1198
1198
/* If send of pending receive completions suceeded
1199
1199
* and did not exhaust NAPI budget this time
1200
1200
* and not doing busy poll
1201
1201
* then re-enable host interrupts
1202
1202
* and reschedule if ring is not empty.
1203
1203
*/
1204
- if (send_recv_completions (nvchan ) == 0 &&
1204
+ if (send_recv_completions (ndev , net_device , nvchan ) == 0 &&
1205
1205
work_done < budget &&
1206
1206
napi_complete_done (napi , work_done ) &&
1207
1207
hv_end_read (& channel -> inbound )) {
@@ -1300,7 +1300,7 @@ struct netvsc_device *netvsc_device_add(struct hv_device *device,
1300
1300
rcu_assign_pointer (net_device_ctx -> nvdev , net_device );
1301
1301
1302
1302
/* Connect with the NetVsp */
1303
- ret = netvsc_connect_vsp (device , net_device );
1303
+ ret = netvsc_connect_vsp (device , net_device , device_info );
1304
1304
if (ret != 0 ) {
1305
1305
netdev_err (ndev ,
1306
1306
"unable to connect to NetVSP - %d\n" , ret );
0 commit comments