Skip to content

Commit 3a4487b

Browse files
committed
Merge branch 'netvsc-minor-fixes-and-improvements'
Stephen Hemminger says: ==================== netvsc: minor fixes and improvements These are non-critical bug fixes, related to functionality now in net-next. 1. delaying the automatic bring up of VF device to allow udev to change name. 2. performance improvement 3. handle MAC address change with VF; mostly propogate the error that VF gives. 4. minor cleanups 5. allow setting send/receive buffer size with ethtool. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents d18c2a1 + cad5c19 commit 3a4487b

File tree

3 files changed

+227
-95
lines changed

3 files changed

+227
-95
lines changed

drivers/net/hyperv/hyperv_net.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ struct netvsc_device_info {
148148
unsigned char mac_adr[ETH_ALEN];
149149
int ring_size;
150150
u32 num_chn;
151+
u32 send_sections;
152+
u32 recv_sections;
151153
};
152154

153155
enum rndis_device_state {
@@ -634,12 +636,12 @@ struct nvsp_message {
634636
#define NETVSC_SEND_BUFFER_SIZE (1024 * 1024 * 15) /* 15MB */
635637
#define NETVSC_INVALID_INDEX -1
636638

639+
#define NETVSC_SEND_SECTION_SIZE 6144
640+
#define NETVSC_RECV_SECTION_SIZE 1728
637641

638642
#define NETVSC_RECEIVE_BUFFER_ID 0xcafe
639643
#define NETVSC_SEND_BUFFER_ID 0
640644

641-
#define NETVSC_PACKET_SIZE 4096
642-
643645
#define VRSS_SEND_TAB_SIZE 16 /* must be power of 2 */
644646
#define VRSS_CHANNEL_MAX 64
645647
#define VRSS_CHANNEL_DEFAULT 8
@@ -678,6 +680,8 @@ struct netvsc_ethtool_stats {
678680
unsigned long tx_no_space;
679681
unsigned long tx_too_big;
680682
unsigned long tx_busy;
683+
unsigned long tx_send_full;
684+
unsigned long rx_comp_busy;
681685
};
682686

683687
struct netvsc_vf_pcpu_stats {
@@ -723,7 +727,7 @@ struct net_device_context {
723727
/* State to manage the associated VF interface. */
724728
struct net_device __rcu *vf_netdev;
725729
struct netvsc_vf_pcpu_stats __percpu *vf_stats;
726-
struct work_struct vf_takeover;
730+
struct delayed_work vf_takeover;
727731

728732
/* 1: allocated, serial number is valid. 0: not allocated */
729733
u32 vf_alloc;
@@ -754,14 +758,13 @@ struct netvsc_device {
754758

755759
/* Receive buffer allocated by us but manages by NetVSP */
756760
void *recv_buf;
757-
u32 recv_buf_size;
758761
u32 recv_buf_gpadl_handle;
759762
u32 recv_section_cnt;
763+
u32 recv_section_size;
760764
u32 recv_completion_cnt;
761765

762766
/* Send buffer allocated by us */
763767
void *send_buf;
764-
u32 send_buf_size;
765768
u32 send_buf_gpadl_handle;
766769
u32 send_section_cnt;
767770
u32 send_section_size;

drivers/net/hyperv/netvsc.c

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ static struct netvsc_device *alloc_net_device(void)
7575
atomic_set(&net_device->open_cnt, 0);
7676
net_device->max_pkt = RNDIS_MAX_PKT_DEFAULT;
7777
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+
7882
init_completion(&net_device->channel_init_wait);
7983
init_waitqueue_head(&net_device->subchan_open);
8084

@@ -143,6 +147,7 @@ static void netvsc_destroy_buf(struct hv_device *device)
143147
"revoke receive buffer to netvsp\n");
144148
return;
145149
}
150+
net_device->recv_section_cnt = 0;
146151
}
147152

148153
/* Teardown the gpadl on the vsp end */
@@ -173,7 +178,7 @@ static void netvsc_destroy_buf(struct hv_device *device)
173178
* NVSP_MSG1_TYPE_SEND_SEND_BUF msg) therefore, we need
174179
* to send a revoke msg here
175180
*/
176-
if (net_device->send_section_size) {
181+
if (net_device->send_section_cnt) {
177182
/* Send the revoke receive buffer */
178183
revoke_packet = &net_device->revoke_packet;
179184
memset(revoke_packet, 0, sizeof(struct nvsp_message));
@@ -205,6 +210,7 @@ static void netvsc_destroy_buf(struct hv_device *device)
205210
"revoke send buffer to netvsp\n");
206211
return;
207212
}
213+
net_device->send_section_cnt = 0;
208214
}
209215
/* Teardown the gpadl on the vsp end */
210216
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)
244250
}
245251

246252
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)
248255
{
249-
int ret = 0;
250-
struct nvsp_message *init_packet;
251256
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;
253260
size_t map_words;
254-
int node;
255-
256-
ndev = hv_get_drvdata(device);
261+
int ret = 0;
257262

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);
262266

267+
net_device->recv_buf = vzalloc(buf_size);
263268
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);
266272
ret = -ENOMEM;
267273
goto cleanup;
268274
}
@@ -273,7 +279,7 @@ static int netvsc_init_buf(struct hv_device *device,
273279
* than the channel to establish the gpadl handle.
274280
*/
275281
ret = vmbus_establish_gpadl(device->channel, net_device->recv_buf,
276-
net_device->recv_buf_size,
282+
buf_size,
277283
&net_device->recv_buf_gpadl_handle);
278284
if (ret != 0) {
279285
netdev_err(ndev,
@@ -319,33 +325,31 @@ static int netvsc_init_buf(struct hv_device *device,
319325
resp->num_sections, resp->sections[0].sub_alloc_size,
320326
resp->sections[0].num_sub_allocs);
321327

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) {
330330
ret = -EINVAL;
331331
goto cleanup;
332332
}
333333

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+
334337
/* Setup receive completion ring */
335338
net_device->recv_completion_cnt
336-
= round_up(resp->sections[0].num_sub_allocs + 1,
339+
= round_up(net_device->recv_section_cnt + 1,
337340
PAGE_SIZE / sizeof(u64));
338341
ret = netvsc_alloc_recv_comp_ring(net_device, 0);
339342
if (ret)
340343
goto cleanup;
341344

342345
/* 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);
346350
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);
349353
ret = -ENOMEM;
350354
goto cleanup;
351355
}
@@ -355,7 +359,7 @@ static int netvsc_init_buf(struct hv_device *device,
355359
* than the channel to establish the gpadl handle.
356360
*/
357361
ret = vmbus_establish_gpadl(device->channel, net_device->send_buf,
358-
net_device->send_buf_size,
362+
buf_size,
359363
&net_device->send_buf_gpadl_handle);
360364
if (ret != 0) {
361365
netdev_err(ndev,
@@ -400,10 +404,8 @@ static int netvsc_init_buf(struct hv_device *device,
400404
net_device->send_section_size = init_packet->msg.
401405
v1_msg.send_send_buf_complete.section_size;
402406

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;
407409

408410
netdev_dbg(ndev, "Send section size: %d, Section count:%d\n",
409411
net_device->send_section_size, net_device->send_section_cnt);
@@ -481,7 +483,8 @@ static int negotiate_nvsp_ver(struct hv_device *device,
481483
}
482484

483485
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)
485488
{
486489
const u32 ver_list[] = {
487490
NVSP_PROTOCOL_VERSION_1, NVSP_PROTOCOL_VERSION_2,
@@ -531,14 +534,8 @@ static int netvsc_connect_vsp(struct hv_device *device,
531534
if (ret != 0)
532535
goto cleanup;
533536

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;
540537

541-
ret = netvsc_init_buf(device, net_device);
538+
ret = netvsc_init_buf(device, net_device, device_info);
542539

543540
cleanup:
544541
return ret;
@@ -886,7 +883,9 @@ int netvsc_send(struct net_device_context *ndev_ctx,
886883
} else if (pktlen + net_device->pkt_align <
887884
net_device->send_section_size) {
888885
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 {
890889
move_pkt_msd(&msd_send, &msd_skb, msdp);
891890
msd_len = 0;
892891
}
@@ -952,9 +951,10 @@ int netvsc_send(struct net_device_context *ndev_ctx,
952951
}
953952

954953
/* 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)
956957
{
957-
struct netvsc_device *nvdev = nvchan->net_device;
958958
struct multi_recv_comp *mrc = &nvchan->mrc;
959959
struct recv_comp_msg {
960960
struct nvsp_message_header hdr;
@@ -972,8 +972,12 @@ static int send_recv_completions(struct netvsc_channel *nvchan)
972972
msg.status = rcd->status;
973973
ret = vmbus_sendpacket(nvchan->channel, &msg, sizeof(msg),
974974
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;
976979
return ret;
980+
}
977981

978982
if (++mrc->first == nvdev->recv_completion_cnt)
979983
mrc->first = 0;
@@ -1014,7 +1018,7 @@ static void enq_receive_complete(struct net_device *ndev,
10141018
recv_comp_slot_avail(nvdev, mrc, &filled, &avail);
10151019

10161020
if (unlikely(filled > NAPI_POLL_WEIGHT)) {
1017-
send_recv_completions(nvchan);
1021+
send_recv_completions(ndev, nvdev, nvchan);
10181022
recv_comp_slot_avail(nvdev, mrc, &filled, &avail);
10191023
}
10201024

@@ -1191,17 +1195,13 @@ int netvsc_poll(struct napi_struct *napi, int budget)
11911195
nvchan->desc = hv_pkt_iter_next(channel, nvchan->desc);
11921196
}
11931197

1194-
/* if ring is empty, signal host */
1195-
if (!nvchan->desc)
1196-
hv_pkt_iter_close(channel);
1197-
11981198
/* If send of pending receive completions suceeded
11991199
* and did not exhaust NAPI budget this time
12001200
* and not doing busy poll
12011201
* then re-enable host interrupts
12021202
* and reschedule if ring is not empty.
12031203
*/
1204-
if (send_recv_completions(nvchan) == 0 &&
1204+
if (send_recv_completions(ndev, net_device, nvchan) == 0 &&
12051205
work_done < budget &&
12061206
napi_complete_done(napi, work_done) &&
12071207
hv_end_read(&channel->inbound)) {
@@ -1300,7 +1300,7 @@ struct netvsc_device *netvsc_device_add(struct hv_device *device,
13001300
rcu_assign_pointer(net_device_ctx->nvdev, net_device);
13011301

13021302
/* Connect with the NetVsp */
1303-
ret = netvsc_connect_vsp(device, net_device);
1303+
ret = netvsc_connect_vsp(device, net_device, device_info);
13041304
if (ret != 0) {
13051305
netdev_err(ndev,
13061306
"unable to connect to NetVSP - %d\n", ret);

0 commit comments

Comments
 (0)