Lines Matching refs:net_device
39 struct netvsc_device *net_device; in alloc_net_device() local
40 struct net_device *ndev = hv_get_drvdata(device); in alloc_net_device()
43 net_device = kzalloc(sizeof(struct netvsc_device), GFP_KERNEL); in alloc_net_device()
44 if (!net_device) in alloc_net_device()
47 net_device->cb_buffer = kzalloc(NETVSC_PACKET_SIZE, GFP_KERNEL); in alloc_net_device()
48 if (!net_device->cb_buffer) { in alloc_net_device()
49 kfree(net_device); in alloc_net_device()
53 init_waitqueue_head(&net_device->wait_drain); in alloc_net_device()
54 net_device->start_remove = false; in alloc_net_device()
55 net_device->destroy = false; in alloc_net_device()
56 net_device->dev = device; in alloc_net_device()
57 net_device->ndev = ndev; in alloc_net_device()
58 net_device->max_pkt = RNDIS_MAX_PKT_DEFAULT; in alloc_net_device()
59 net_device->pkt_align = RNDIS_PKT_ALIGN_DEFAULT; in alloc_net_device()
62 spin_lock_init(&net_device->msd[i].lock); in alloc_net_device()
64 hv_set_drvdata(device, net_device); in alloc_net_device()
65 return net_device; in alloc_net_device()
76 struct netvsc_device *net_device; in get_outbound_net_device() local
78 net_device = hv_get_drvdata(device); in get_outbound_net_device()
79 if (net_device && net_device->destroy) in get_outbound_net_device()
80 net_device = NULL; in get_outbound_net_device()
82 return net_device; in get_outbound_net_device()
87 struct netvsc_device *net_device; in get_inbound_net_device() local
89 net_device = hv_get_drvdata(device); in get_inbound_net_device()
91 if (!net_device) in get_inbound_net_device()
94 if (net_device->destroy && in get_inbound_net_device()
95 atomic_read(&net_device->num_outstanding_sends) == 0) in get_inbound_net_device()
96 net_device = NULL; in get_inbound_net_device()
99 return net_device; in get_inbound_net_device()
103 static int netvsc_destroy_buf(struct netvsc_device *net_device) in netvsc_destroy_buf() argument
107 struct net_device *ndev = net_device->ndev; in netvsc_destroy_buf()
115 if (net_device->recv_section_cnt) { in netvsc_destroy_buf()
117 revoke_packet = &net_device->revoke_packet; in netvsc_destroy_buf()
125 ret = vmbus_sendpacket(net_device->dev->channel, in netvsc_destroy_buf()
142 if (net_device->recv_buf_gpadl_handle) { in netvsc_destroy_buf()
143 ret = vmbus_teardown_gpadl(net_device->dev->channel, in netvsc_destroy_buf()
144 net_device->recv_buf_gpadl_handle); in netvsc_destroy_buf()
154 net_device->recv_buf_gpadl_handle = 0; in netvsc_destroy_buf()
157 if (net_device->recv_buf) { in netvsc_destroy_buf()
159 vfree(net_device->recv_buf); in netvsc_destroy_buf()
160 net_device->recv_buf = NULL; in netvsc_destroy_buf()
163 if (net_device->recv_section) { in netvsc_destroy_buf()
164 net_device->recv_section_cnt = 0; in netvsc_destroy_buf()
165 kfree(net_device->recv_section); in netvsc_destroy_buf()
166 net_device->recv_section = NULL; in netvsc_destroy_buf()
175 if (net_device->send_section_size) { in netvsc_destroy_buf()
177 revoke_packet = &net_device->revoke_packet; in netvsc_destroy_buf()
185 ret = vmbus_sendpacket(net_device->dev->channel, in netvsc_destroy_buf()
200 if (net_device->send_buf_gpadl_handle) { in netvsc_destroy_buf()
201 ret = vmbus_teardown_gpadl(net_device->dev->channel, in netvsc_destroy_buf()
202 net_device->send_buf_gpadl_handle); in netvsc_destroy_buf()
212 net_device->send_buf_gpadl_handle = 0; in netvsc_destroy_buf()
214 if (net_device->send_buf) { in netvsc_destroy_buf()
216 vfree(net_device->send_buf); in netvsc_destroy_buf()
217 net_device->send_buf = NULL; in netvsc_destroy_buf()
219 kfree(net_device->send_section_map); in netvsc_destroy_buf()
228 struct netvsc_device *net_device; in netvsc_init_buf() local
230 struct net_device *ndev; in netvsc_init_buf()
233 net_device = get_outbound_net_device(device); in netvsc_init_buf()
234 if (!net_device) in netvsc_init_buf()
236 ndev = net_device->ndev; in netvsc_init_buf()
239 net_device->recv_buf = vzalloc_node(net_device->recv_buf_size, node); in netvsc_init_buf()
240 if (!net_device->recv_buf) in netvsc_init_buf()
241 net_device->recv_buf = vzalloc(net_device->recv_buf_size); in netvsc_init_buf()
243 if (!net_device->recv_buf) { in netvsc_init_buf()
245 "buffer of size %d\n", net_device->recv_buf_size); in netvsc_init_buf()
255 ret = vmbus_establish_gpadl(device->channel, net_device->recv_buf, in netvsc_init_buf()
256 net_device->recv_buf_size, in netvsc_init_buf()
257 &net_device->recv_buf_gpadl_handle); in netvsc_init_buf()
266 init_packet = &net_device->channel_init_pkt; in netvsc_init_buf()
272 gpadl_handle = net_device->recv_buf_gpadl_handle; in netvsc_init_buf()
288 t = wait_for_completion_timeout(&net_device->channel_init_wait, 5*HZ); in netvsc_init_buf()
305 net_device->recv_section_cnt = init_packet->msg. in netvsc_init_buf()
308 net_device->recv_section = kmemdup( in netvsc_init_buf()
310 net_device->recv_section_cnt * in netvsc_init_buf()
313 if (net_device->recv_section == NULL) { in netvsc_init_buf()
322 if (net_device->recv_section_cnt != 1 || in netvsc_init_buf()
323 net_device->recv_section->offset != 0) { in netvsc_init_buf()
330 net_device->send_buf = vzalloc_node(net_device->send_buf_size, node); in netvsc_init_buf()
331 if (!net_device->send_buf) in netvsc_init_buf()
332 net_device->send_buf = vzalloc(net_device->send_buf_size); in netvsc_init_buf()
333 if (!net_device->send_buf) { in netvsc_init_buf()
335 "buffer of size %d\n", net_device->send_buf_size); in netvsc_init_buf()
344 ret = vmbus_establish_gpadl(device->channel, net_device->send_buf, in netvsc_init_buf()
345 net_device->send_buf_size, in netvsc_init_buf()
346 &net_device->send_buf_gpadl_handle); in netvsc_init_buf()
354 init_packet = &net_device->channel_init_pkt; in netvsc_init_buf()
358 net_device->send_buf_gpadl_handle; in netvsc_init_buf()
373 t = wait_for_completion_timeout(&net_device->channel_init_wait, 5*HZ); in netvsc_init_buf()
388 net_device->send_section_size = init_packet->msg. in netvsc_init_buf()
393 net_device->send_section_cnt = in netvsc_init_buf()
394 net_device->send_buf_size/net_device->send_section_size; in netvsc_init_buf()
397 net_device->send_section_size, net_device->send_section_cnt); in netvsc_init_buf()
400 net_device->map_words = DIV_ROUND_UP(net_device->send_section_cnt, in netvsc_init_buf()
403 net_device->send_section_map = in netvsc_init_buf()
404 kzalloc(net_device->map_words * sizeof(ulong), GFP_KERNEL); in netvsc_init_buf()
405 if (net_device->send_section_map == NULL) { in netvsc_init_buf()
413 netvsc_destroy_buf(net_device); in netvsc_init_buf()
422 struct netvsc_device *net_device, in negotiate_nvsp_ver() argument
444 t = wait_for_completion_timeout(&net_device->channel_init_wait, 5*HZ); in negotiate_nvsp_ver()
459 init_packet->msg.v2_msg.send_ndis_config.mtu = net_device->ndev->mtu + in negotiate_nvsp_ver()
477 struct netvsc_device *net_device; in netvsc_connect_vsp() local
480 struct net_device *ndev; in netvsc_connect_vsp()
485 net_device = get_outbound_net_device(device); in netvsc_connect_vsp()
486 if (!net_device) in netvsc_connect_vsp()
488 ndev = net_device->ndev; in netvsc_connect_vsp()
490 init_packet = &net_device->channel_init_pkt; in netvsc_connect_vsp()
494 if (negotiate_nvsp_ver(device, net_device, init_packet, in netvsc_connect_vsp()
496 net_device->nvsp_version = ver_list[i]; in netvsc_connect_vsp()
505 pr_debug("Negotiated NVSP version:%x\n", net_device->nvsp_version); in netvsc_connect_vsp()
510 if (net_device->nvsp_version <= NVSP_PROTOCOL_VERSION_4) in netvsc_connect_vsp()
532 if (net_device->nvsp_version <= NVSP_PROTOCOL_VERSION_2) in netvsc_connect_vsp()
533 net_device->recv_buf_size = NETVSC_RECEIVE_BUFFER_SIZE_LEGACY; in netvsc_connect_vsp()
535 net_device->recv_buf_size = NETVSC_RECEIVE_BUFFER_SIZE; in netvsc_connect_vsp()
536 net_device->send_buf_size = NETVSC_SEND_BUFFER_SIZE; in netvsc_connect_vsp()
544 static void netvsc_disconnect_vsp(struct netvsc_device *net_device) in netvsc_disconnect_vsp() argument
546 netvsc_destroy_buf(net_device); in netvsc_disconnect_vsp()
554 struct netvsc_device *net_device; in netvsc_device_remove() local
557 net_device = hv_get_drvdata(device); in netvsc_device_remove()
559 netvsc_disconnect_vsp(net_device); in netvsc_device_remove()
583 vfree(net_device->sub_cb_buf); in netvsc_device_remove()
584 free_netvsc_device(net_device); in netvsc_device_remove()
606 static inline void netvsc_free_send_slot(struct netvsc_device *net_device, in netvsc_free_send_slot() argument
609 sync_change_bit(index, net_device->send_section_map); in netvsc_free_send_slot()
612 static void netvsc_send_completion(struct netvsc_device *net_device, in netvsc_send_completion() argument
618 struct net_device *ndev; in netvsc_send_completion()
621 ndev = net_device->ndev; in netvsc_send_completion()
634 memcpy(&net_device->channel_init_pkt, nvsp_packet, in netvsc_send_completion()
636 complete(&net_device->channel_init_wait); in netvsc_send_completion()
652 netvsc_free_send_slot(net_device, send_index); in netvsc_send_completion()
660 atomic_dec_return(&net_device->num_outstanding_sends); in netvsc_send_completion()
661 queue_sends = atomic_dec_return(&net_device-> in netvsc_send_completion()
664 if (net_device->destroy && num_outstanding_sends == 0) in netvsc_send_completion()
665 wake_up(&net_device->wait_drain); in netvsc_send_completion()
668 !net_device->start_remove && in netvsc_send_completion()
680 static u32 netvsc_get_next_send_section(struct netvsc_device *net_device) in netvsc_get_next_send_section() argument
683 u32 max_words = net_device->map_words; in netvsc_get_next_send_section()
684 unsigned long *map_addr = (unsigned long *)net_device->send_section_map; in netvsc_get_next_send_section()
685 u32 section_cnt = net_device->send_section_cnt; in netvsc_get_next_send_section()
705 static u32 netvsc_copy_to_send_buf(struct netvsc_device *net_device, in netvsc_copy_to_send_buf() argument
710 char *start = net_device->send_buf; in netvsc_copy_to_send_buf()
711 char *dest = start + (section_index * net_device->send_section_size) in netvsc_copy_to_send_buf()
716 u32 remain = packet->total_data_buflen % net_device->pkt_align; in netvsc_copy_to_send_buf()
723 padding = net_device->pkt_align - remain; in netvsc_copy_to_send_buf()
748 struct netvsc_device *net_device) in netvsc_send_pkt() argument
753 struct net_device *ndev = net_device->ndev; in netvsc_send_pkt()
815 atomic_inc(&net_device->num_outstanding_sends); in netvsc_send_pkt()
816 atomic_inc(&net_device->queue_sends[q_idx]); in netvsc_send_pkt()
821 if (atomic_read(&net_device-> in netvsc_send_pkt()
829 if (atomic_read(&net_device->queue_sends[q_idx]) < 1) { in netvsc_send_pkt()
845 struct netvsc_device *net_device; in netvsc_send() local
856 net_device = get_outbound_net_device(device); in netvsc_send()
857 if (!net_device) in netvsc_send()
860 out_channel = net_device->chn_table[q_idx]; in netvsc_send()
870 msdp = &net_device->msd[q_idx]; in netvsc_send()
878 net_device->max_pkt; in netvsc_send()
880 if (try_batch && msd_len + pktlen + net_device->pkt_align < in netvsc_send()
881 net_device->send_section_size) { in netvsc_send()
885 net_device->send_section_size) { in netvsc_send()
889 } else if (packet->is_data_pkt && pktlen + net_device->pkt_align < in netvsc_send()
890 net_device->send_section_size) { in netvsc_send()
891 section_index = netvsc_get_next_send_section(net_device); in netvsc_send()
901 netvsc_copy_to_send_buf(net_device, in netvsc_send()
936 m_ret = netvsc_send_pkt(msd_send, net_device); in netvsc_send()
939 netvsc_free_send_slot(net_device, in netvsc_send()
946 ret = netvsc_send_pkt(cur_send, net_device); in netvsc_send()
949 netvsc_free_send_slot(net_device, section_index); in netvsc_send()
956 struct netvsc_device *net_device, in netvsc_send_recv_completion() argument
962 struct net_device *ndev; in netvsc_send_recv_completion()
964 ndev = net_device->ndev; in netvsc_send_recv_completion()
999 static void netvsc_receive(struct netvsc_device *net_device, in netvsc_receive() argument
1011 struct net_device *ndev; in netvsc_receive()
1013 ndev = net_device->ndev; in netvsc_receive()
1052 netvsc_packet->data = (void *)((unsigned long)net_device-> in netvsc_receive()
1064 netvsc_send_recv_completion(device, channel, net_device, in netvsc_receive()
1073 struct net_device *ndev; in netvsc_send_table()
1122 struct netvsc_device *net_device; in netvsc_channel_cb() local
1128 struct net_device *ndev; in netvsc_channel_cb()
1136 net_device = get_inbound_net_device(device); in netvsc_channel_cb()
1137 if (!net_device) in netvsc_channel_cb()
1139 ndev = net_device->ndev; in netvsc_channel_cb()
1152 netvsc_send_completion(net_device, in netvsc_channel_cb()
1157 netvsc_receive(net_device, channel, in netvsc_channel_cb()
1163 net_device, in netvsc_channel_cb()
1214 struct netvsc_device *net_device; in netvsc_device_add() local
1215 struct net_device *ndev; in netvsc_device_add()
1217 net_device = alloc_net_device(device); in netvsc_device_add()
1218 if (!net_device) in netvsc_device_add()
1221 net_device->ring_size = ring_size; in netvsc_device_add()
1230 ndev = net_device->ndev; in netvsc_device_add()
1233 net_device->nd_ctx = netdev_priv(ndev); in netvsc_device_add()
1236 init_completion(&net_device->channel_init_wait); in netvsc_device_add()
1238 set_per_channel_state(device->channel, net_device->cb_buffer); in netvsc_device_add()
1253 net_device->chn_table[0] = device->channel; in netvsc_device_add()
1270 free_netvsc_device(net_device); in netvsc_device_add()