Skip to content

Commit 2b3a9af

Browse files
committed
Merge branch 'netvsc-small-cleanups'
Stephen Hemminger says: ==================== netvsc: small cleanups These are all small optimizations found during development of later features. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents e073782 + 592b4fe commit 2b3a9af

File tree

3 files changed

+29
-76
lines changed

3 files changed

+29
-76
lines changed

drivers/net/hyperv/hyperv_net.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,7 @@ struct netvsc_device {
763763

764764
refcount_t sc_offered;
765765

766-
/* Holds rndis device info */
767-
void *extension;
766+
struct rndis_device *extension;
768767

769768
int ring_size;
770769

drivers/net/hyperv/netvsc.c

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,6 @@ static void free_netvsc_device_rcu(struct netvsc_device *nvdev)
9797
call_rcu(&nvdev->rcu, free_netvsc_device);
9898
}
9999

100-
static struct netvsc_device *get_outbound_net_device(struct hv_device *device)
101-
{
102-
struct netvsc_device *net_device = hv_device_to_netvsc_device(device);
103-
104-
if (net_device && net_device->destroy)
105-
net_device = NULL;
106-
107-
return net_device;
108-
}
109-
110100
static void netvsc_destroy_buf(struct hv_device *device)
111101
{
112102
struct nvsp_message *revoke_packet;
@@ -243,18 +233,15 @@ static void netvsc_destroy_buf(struct hv_device *device)
243233
kfree(net_device->send_section_map);
244234
}
245235

246-
static int netvsc_init_buf(struct hv_device *device)
236+
static int netvsc_init_buf(struct hv_device *device,
237+
struct netvsc_device *net_device)
247238
{
248239
int ret = 0;
249-
struct netvsc_device *net_device;
250240
struct nvsp_message *init_packet;
251241
struct net_device *ndev;
252242
size_t map_words;
253243
int node;
254244

255-
net_device = get_outbound_net_device(device);
256-
if (!net_device)
257-
return -ENODEV;
258245
ndev = hv_get_drvdata(device);
259246

260247
node = cpu_to_node(device->channel->target_cpu);
@@ -285,9 +272,7 @@ static int netvsc_init_buf(struct hv_device *device)
285272

286273
/* Notify the NetVsp of the gpadl handle */
287274
init_packet = &net_device->channel_init_pkt;
288-
289275
memset(init_packet, 0, sizeof(struct nvsp_message));
290-
291276
init_packet->hdr.msg_type = NVSP_MSG1_TYPE_SEND_RECV_BUF;
292277
init_packet->msg.v1_msg.send_recv_buf.
293278
gpadl_handle = net_device->recv_buf_gpadl_handle;
@@ -486,20 +471,15 @@ static int negotiate_nvsp_ver(struct hv_device *device,
486471
return ret;
487472
}
488473

489-
static int netvsc_connect_vsp(struct hv_device *device)
474+
static int netvsc_connect_vsp(struct hv_device *device,
475+
struct netvsc_device *net_device)
490476
{
491-
int ret;
492-
struct netvsc_device *net_device;
493-
struct nvsp_message *init_packet;
494-
int ndis_version;
495477
const u32 ver_list[] = {
496478
NVSP_PROTOCOL_VERSION_1, NVSP_PROTOCOL_VERSION_2,
497-
NVSP_PROTOCOL_VERSION_4, NVSP_PROTOCOL_VERSION_5 };
498-
int i;
499-
500-
net_device = get_outbound_net_device(device);
501-
if (!net_device)
502-
return -ENODEV;
479+
NVSP_PROTOCOL_VERSION_4, NVSP_PROTOCOL_VERSION_5
480+
};
481+
struct nvsp_message *init_packet;
482+
int ndis_version, i, ret;
503483

504484
init_packet = &net_device->channel_init_pkt;
505485

@@ -549,7 +529,7 @@ static int netvsc_connect_vsp(struct hv_device *device)
549529
net_device->recv_buf_size = NETVSC_RECEIVE_BUFFER_SIZE;
550530
net_device->send_buf_size = NETVSC_SEND_BUFFER_SIZE;
551531

552-
ret = netvsc_init_buf(device);
532+
ret = netvsc_init_buf(device, net_device);
553533

554534
cleanup:
555535
return ret;
@@ -843,7 +823,7 @@ int netvsc_send(struct hv_device *device,
843823
struct hv_page_buffer **pb,
844824
struct sk_buff *skb)
845825
{
846-
struct netvsc_device *net_device;
826+
struct netvsc_device *net_device = hv_device_to_netvsc_device(device);
847827
int ret = 0;
848828
struct netvsc_channel *nvchan;
849829
u32 pktlen = packet->total_data_buflen, msd_len = 0;
@@ -854,15 +834,15 @@ int netvsc_send(struct hv_device *device,
854834
bool try_batch;
855835
bool xmit_more = (skb != NULL) ? skb->xmit_more : false;
856836

857-
net_device = get_outbound_net_device(device);
858-
if (!net_device)
837+
/* If device is rescinded, return error and packet will get dropped. */
838+
if (unlikely(net_device->destroy))
859839
return -ENODEV;
860840

861841
/* We may race with netvsc_connect_vsp()/netvsc_init_buf() and get
862842
* here before the negotiation with the host is finished and
863843
* send_section_map may not be allocated yet.
864844
*/
865-
if (!net_device->send_section_map)
845+
if (unlikely(!net_device->send_section_map))
866846
return -EAGAIN;
867847

868848
nvchan = &net_device->chan_table[packet->q_idx];
@@ -1349,7 +1329,7 @@ int netvsc_device_add(struct hv_device *device,
13491329
rcu_assign_pointer(net_device_ctx->nvdev, net_device);
13501330

13511331
/* Connect with the NetVsp */
1352-
ret = netvsc_connect_vsp(device);
1332+
ret = netvsc_connect_vsp(device, net_device);
13531333
if (ret != 0) {
13541334
netdev_err(ndev,
13551335
"unable to connect to NetVSP - %d\n", ret);
@@ -1368,4 +1348,5 @@ int netvsc_device_add(struct hv_device *device,
13681348
free_netvsc_device(&net_device->rcu);
13691349

13701350
return ret;
1351+
13711352
}

drivers/net/hyperv/netvsc_drv.c

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ static int netvsc_close(struct net_device *net)
120120
struct net_device_context *net_device_ctx = netdev_priv(net);
121121
struct netvsc_device *nvdev = rtnl_dereference(net_device_ctx->nvdev);
122122
int ret;
123-
u32 aread, awrite, i, msec = 10, retry = 0, retry_max = 20;
123+
u32 aread, i, msec = 10, retry = 0, retry_max = 20;
124124
struct vmbus_channel *chn;
125125

126126
netif_tx_disable(net);
@@ -141,15 +141,11 @@ static int netvsc_close(struct net_device *net)
141141
if (!chn)
142142
continue;
143143

144-
hv_get_ringbuffer_availbytes(&chn->inbound, &aread,
145-
&awrite);
146-
144+
aread = hv_get_bytes_to_read(&chn->inbound);
147145
if (aread)
148146
break;
149147

150-
hv_get_ringbuffer_availbytes(&chn->outbound, &aread,
151-
&awrite);
152-
148+
aread = hv_get_bytes_to_read(&chn->outbound);
153149
if (aread)
154150
break;
155151
}
@@ -345,34 +341,14 @@ static u32 init_page_array(void *hdr, u32 len, struct sk_buff *skb,
345341
return slots_used;
346342
}
347343

348-
static int count_skb_frag_slots(struct sk_buff *skb)
349-
{
350-
int i, frags = skb_shinfo(skb)->nr_frags;
351-
int pages = 0;
352-
353-
for (i = 0; i < frags; i++) {
354-
skb_frag_t *frag = skb_shinfo(skb)->frags + i;
355-
unsigned long size = skb_frag_size(frag);
356-
unsigned long offset = frag->page_offset;
357-
358-
/* Skip unused frames from start of page */
359-
offset &= ~PAGE_MASK;
360-
pages += PFN_UP(offset + size);
361-
}
362-
return pages;
363-
}
364-
365-
static int netvsc_get_slots(struct sk_buff *skb)
344+
/* Estimate number of page buffers neede to transmit
345+
* Need at most 2 for RNDIS header plus skb body and fragments.
346+
*/
347+
static unsigned int netvsc_get_slots(const struct sk_buff *skb)
366348
{
367-
char *data = skb->data;
368-
unsigned int offset = offset_in_page(data);
369-
unsigned int len = skb_headlen(skb);
370-
int slots;
371-
int frag_slots;
372-
373-
slots = DIV_ROUND_UP(offset + len, PAGE_SIZE);
374-
frag_slots = count_skb_frag_slots(skb);
375-
return slots + frag_slots;
349+
return PFN_UP(offset_in_page(skb->data) + skb_headlen(skb))
350+
+ skb_shinfo(skb)->nr_frags
351+
+ 2;
376352
}
377353

378354
static u32 net_checksum_info(struct sk_buff *skb)
@@ -410,21 +386,18 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
410386
struct hv_page_buffer page_buf[MAX_PAGE_BUFFER_COUNT];
411387
struct hv_page_buffer *pb = page_buf;
412388

413-
/* We will atmost need two pages to describe the rndis
414-
* header. We can only transmit MAX_PAGE_BUFFER_COUNT number
389+
/* We can only transmit MAX_PAGE_BUFFER_COUNT number
415390
* of pages in a single packet. If skb is scattered around
416391
* more pages we try linearizing it.
417392
*/
418-
419-
num_data_pgs = netvsc_get_slots(skb) + 2;
420-
393+
num_data_pgs = netvsc_get_slots(skb);
421394
if (unlikely(num_data_pgs > MAX_PAGE_BUFFER_COUNT)) {
422395
++net_device_ctx->eth_stats.tx_scattered;
423396

424397
if (skb_linearize(skb))
425398
goto no_memory;
426399

427-
num_data_pgs = netvsc_get_slots(skb) + 2;
400+
num_data_pgs = netvsc_get_slots(skb);
428401
if (num_data_pgs > MAX_PAGE_BUFFER_COUNT) {
429402
++net_device_ctx->eth_stats.tx_too_big;
430403
goto drop;

0 commit comments

Comments
 (0)