Lines Matching refs:net_device
38 struct netvsc_device *net_device; in alloc_net_device() local
39 struct net_device *ndev = hv_get_drvdata(device); in alloc_net_device()
42 net_device = kzalloc(sizeof(struct netvsc_device), GFP_KERNEL); in alloc_net_device()
43 if (!net_device) in alloc_net_device()
46 net_device->cb_buffer = kzalloc(NETVSC_PACKET_SIZE, GFP_KERNEL); in alloc_net_device()
47 if (!net_device->cb_buffer) { in alloc_net_device()
48 kfree(net_device); in alloc_net_device()
52 init_waitqueue_head(&net_device->wait_drain); in alloc_net_device()
53 net_device->start_remove = false; in alloc_net_device()
54 net_device->destroy = false; in alloc_net_device()
55 net_device->dev = device; in alloc_net_device()
56 net_device->ndev = ndev; in alloc_net_device()
57 net_device->max_pkt = RNDIS_MAX_PKT_DEFAULT; in alloc_net_device()
58 net_device->pkt_align = RNDIS_PKT_ALIGN_DEFAULT; in alloc_net_device()
61 spin_lock_init(&net_device->msd[i].lock); in alloc_net_device()
63 hv_set_drvdata(device, net_device); in alloc_net_device()
64 return net_device; in alloc_net_device()
75 struct netvsc_device *net_device; in get_outbound_net_device() local
77 net_device = hv_get_drvdata(device); in get_outbound_net_device()
78 if (net_device && net_device->destroy) in get_outbound_net_device()
79 net_device = NULL; in get_outbound_net_device()
81 return net_device; in get_outbound_net_device()
86 struct netvsc_device *net_device; in get_inbound_net_device() local
88 net_device = hv_get_drvdata(device); in get_inbound_net_device()
90 if (!net_device) in get_inbound_net_device()
93 if (net_device->destroy && in get_inbound_net_device()
94 atomic_read(&net_device->num_outstanding_sends) == 0) in get_inbound_net_device()
95 net_device = NULL; in get_inbound_net_device()
98 return net_device; in get_inbound_net_device()
102 static int netvsc_destroy_buf(struct netvsc_device *net_device) in netvsc_destroy_buf() argument
106 struct net_device *ndev = net_device->ndev; in netvsc_destroy_buf()
114 if (net_device->recv_section_cnt) { in netvsc_destroy_buf()
116 revoke_packet = &net_device->revoke_packet; in netvsc_destroy_buf()
124 ret = vmbus_sendpacket(net_device->dev->channel, in netvsc_destroy_buf()
141 if (net_device->recv_buf_gpadl_handle) { in netvsc_destroy_buf()
142 ret = vmbus_teardown_gpadl(net_device->dev->channel, in netvsc_destroy_buf()
143 net_device->recv_buf_gpadl_handle); in netvsc_destroy_buf()
153 net_device->recv_buf_gpadl_handle = 0; in netvsc_destroy_buf()
156 if (net_device->recv_buf) { in netvsc_destroy_buf()
158 vfree(net_device->recv_buf); in netvsc_destroy_buf()
159 net_device->recv_buf = NULL; in netvsc_destroy_buf()
162 if (net_device->recv_section) { in netvsc_destroy_buf()
163 net_device->recv_section_cnt = 0; in netvsc_destroy_buf()
164 kfree(net_device->recv_section); in netvsc_destroy_buf()
165 net_device->recv_section = NULL; in netvsc_destroy_buf()
174 if (net_device->send_section_size) { in netvsc_destroy_buf()
176 revoke_packet = &net_device->revoke_packet; in netvsc_destroy_buf()
184 ret = vmbus_sendpacket(net_device->dev->channel, in netvsc_destroy_buf()
199 if (net_device->send_buf_gpadl_handle) { in netvsc_destroy_buf()
200 ret = vmbus_teardown_gpadl(net_device->dev->channel, in netvsc_destroy_buf()
201 net_device->send_buf_gpadl_handle); in netvsc_destroy_buf()
211 net_device->send_buf_gpadl_handle = 0; in netvsc_destroy_buf()
213 if (net_device->send_buf) { in netvsc_destroy_buf()
215 vfree(net_device->send_buf); in netvsc_destroy_buf()
216 net_device->send_buf = NULL; in netvsc_destroy_buf()
218 kfree(net_device->send_section_map); in netvsc_destroy_buf()
227 struct netvsc_device *net_device; in netvsc_init_buf() local
229 struct net_device *ndev; in netvsc_init_buf()
231 net_device = get_outbound_net_device(device); in netvsc_init_buf()
232 if (!net_device) in netvsc_init_buf()
234 ndev = net_device->ndev; in netvsc_init_buf()
236 net_device->recv_buf = vzalloc(net_device->recv_buf_size); in netvsc_init_buf()
237 if (!net_device->recv_buf) { in netvsc_init_buf()
239 "buffer of size %d\n", net_device->recv_buf_size); in netvsc_init_buf()
249 ret = vmbus_establish_gpadl(device->channel, net_device->recv_buf, in netvsc_init_buf()
250 net_device->recv_buf_size, in netvsc_init_buf()
251 &net_device->recv_buf_gpadl_handle); in netvsc_init_buf()
260 init_packet = &net_device->channel_init_pkt; in netvsc_init_buf()
266 gpadl_handle = net_device->recv_buf_gpadl_handle; in netvsc_init_buf()
282 t = wait_for_completion_timeout(&net_device->channel_init_wait, 5*HZ); in netvsc_init_buf()
299 net_device->recv_section_cnt = init_packet->msg. in netvsc_init_buf()
302 net_device->recv_section = kmemdup( in netvsc_init_buf()
304 net_device->recv_section_cnt * in netvsc_init_buf()
307 if (net_device->recv_section == NULL) { in netvsc_init_buf()
316 if (net_device->recv_section_cnt != 1 || in netvsc_init_buf()
317 net_device->recv_section->offset != 0) { in netvsc_init_buf()
324 net_device->send_buf = vzalloc(net_device->send_buf_size); in netvsc_init_buf()
325 if (!net_device->send_buf) { in netvsc_init_buf()
327 "buffer of size %d\n", net_device->send_buf_size); in netvsc_init_buf()
336 ret = vmbus_establish_gpadl(device->channel, net_device->send_buf, in netvsc_init_buf()
337 net_device->send_buf_size, in netvsc_init_buf()
338 &net_device->send_buf_gpadl_handle); in netvsc_init_buf()
346 init_packet = &net_device->channel_init_pkt; in netvsc_init_buf()
350 net_device->send_buf_gpadl_handle; in netvsc_init_buf()
365 t = wait_for_completion_timeout(&net_device->channel_init_wait, 5*HZ); in netvsc_init_buf()
380 net_device->send_section_size = init_packet->msg. in netvsc_init_buf()
385 net_device->send_section_cnt = in netvsc_init_buf()
386 net_device->send_buf_size/net_device->send_section_size; in netvsc_init_buf()
389 net_device->send_section_size, net_device->send_section_cnt); in netvsc_init_buf()
392 net_device->map_words = DIV_ROUND_UP(net_device->send_section_cnt, in netvsc_init_buf()
395 net_device->send_section_map = in netvsc_init_buf()
396 kzalloc(net_device->map_words * sizeof(ulong), GFP_KERNEL); in netvsc_init_buf()
397 if (net_device->send_section_map == NULL) { in netvsc_init_buf()
405 netvsc_destroy_buf(net_device); in netvsc_init_buf()
414 struct netvsc_device *net_device, in negotiate_nvsp_ver() argument
436 t = wait_for_completion_timeout(&net_device->channel_init_wait, 5*HZ); in negotiate_nvsp_ver()
451 init_packet->msg.v2_msg.send_ndis_config.mtu = net_device->ndev->mtu + in negotiate_nvsp_ver()
466 struct netvsc_device *net_device; in netvsc_connect_vsp() local
469 struct net_device *ndev; in netvsc_connect_vsp()
474 net_device = get_outbound_net_device(device); in netvsc_connect_vsp()
475 if (!net_device) in netvsc_connect_vsp()
477 ndev = net_device->ndev; in netvsc_connect_vsp()
479 init_packet = &net_device->channel_init_pkt; in netvsc_connect_vsp()
483 if (negotiate_nvsp_ver(device, net_device, init_packet, in netvsc_connect_vsp()
485 net_device->nvsp_version = ver_list[i]; in netvsc_connect_vsp()
494 pr_debug("Negotiated NVSP version:%x\n", net_device->nvsp_version); in netvsc_connect_vsp()
499 if (net_device->nvsp_version <= NVSP_PROTOCOL_VERSION_4) in netvsc_connect_vsp()
521 if (net_device->nvsp_version <= NVSP_PROTOCOL_VERSION_2) in netvsc_connect_vsp()
522 net_device->recv_buf_size = NETVSC_RECEIVE_BUFFER_SIZE_LEGACY; in netvsc_connect_vsp()
524 net_device->recv_buf_size = NETVSC_RECEIVE_BUFFER_SIZE; in netvsc_connect_vsp()
525 net_device->send_buf_size = NETVSC_SEND_BUFFER_SIZE; in netvsc_connect_vsp()
533 static void netvsc_disconnect_vsp(struct netvsc_device *net_device) in netvsc_disconnect_vsp() argument
535 netvsc_destroy_buf(net_device); in netvsc_disconnect_vsp()
543 struct netvsc_device *net_device; in netvsc_device_remove() local
546 net_device = hv_get_drvdata(device); in netvsc_device_remove()
548 netvsc_disconnect_vsp(net_device); in netvsc_device_remove()
572 vfree(net_device->sub_cb_buf); in netvsc_device_remove()
573 free_netvsc_device(net_device); in netvsc_device_remove()
595 static inline void netvsc_free_send_slot(struct netvsc_device *net_device, in netvsc_free_send_slot() argument
598 sync_change_bit(index, net_device->send_section_map); in netvsc_free_send_slot()
601 static void netvsc_send_completion(struct netvsc_device *net_device, in netvsc_send_completion() argument
607 struct net_device *ndev; in netvsc_send_completion()
610 ndev = net_device->ndev; in netvsc_send_completion()
623 memcpy(&net_device->channel_init_pkt, nvsp_packet, in netvsc_send_completion()
625 complete(&net_device->channel_init_wait); in netvsc_send_completion()
641 netvsc_free_send_slot(net_device, send_index); in netvsc_send_completion()
649 atomic_dec_return(&net_device->num_outstanding_sends); in netvsc_send_completion()
650 queue_sends = atomic_dec_return(&net_device-> in netvsc_send_completion()
653 if (net_device->destroy && num_outstanding_sends == 0) in netvsc_send_completion()
654 wake_up(&net_device->wait_drain); in netvsc_send_completion()
657 !net_device->start_remove && in netvsc_send_completion()
669 static u32 netvsc_get_next_send_section(struct netvsc_device *net_device) in netvsc_get_next_send_section() argument
672 u32 max_words = net_device->map_words; in netvsc_get_next_send_section()
673 unsigned long *map_addr = (unsigned long *)net_device->send_section_map; in netvsc_get_next_send_section()
674 u32 section_cnt = net_device->send_section_cnt; in netvsc_get_next_send_section()
694 static u32 netvsc_copy_to_send_buf(struct netvsc_device *net_device, in netvsc_copy_to_send_buf() argument
699 char *start = net_device->send_buf; in netvsc_copy_to_send_buf()
700 char *dest = start + (section_index * net_device->send_section_size) in netvsc_copy_to_send_buf()
705 u32 remain = packet->total_data_buflen % net_device->pkt_align; in netvsc_copy_to_send_buf()
712 padding = net_device->pkt_align - remain; in netvsc_copy_to_send_buf()
737 struct netvsc_device *net_device) in netvsc_send_pkt() argument
742 struct net_device *ndev = net_device->ndev; in netvsc_send_pkt()
791 atomic_inc(&net_device->num_outstanding_sends); in netvsc_send_pkt()
792 atomic_inc(&net_device->queue_sends[q_idx]); in netvsc_send_pkt()
799 if (atomic_read(&net_device-> in netvsc_send_pkt()
807 if (atomic_read(&net_device->queue_sends[q_idx]) < 1) { in netvsc_send_pkt()
823 struct netvsc_device *net_device; in netvsc_send() local
834 net_device = get_outbound_net_device(device); in netvsc_send()
835 if (!net_device) in netvsc_send()
838 out_channel = net_device->chn_table[q_idx]; in netvsc_send()
848 msdp = &net_device->msd[q_idx]; in netvsc_send()
856 net_device->max_pkt; in netvsc_send()
858 if (try_batch && msd_len + pktlen + net_device->pkt_align < in netvsc_send()
859 net_device->send_section_size) { in netvsc_send()
863 net_device->send_section_size) { in netvsc_send()
867 } else if (packet->is_data_pkt && pktlen + net_device->pkt_align < in netvsc_send()
868 net_device->send_section_size) { in netvsc_send()
869 section_index = netvsc_get_next_send_section(net_device); in netvsc_send()
879 netvsc_copy_to_send_buf(net_device, in netvsc_send()
914 m_ret = netvsc_send_pkt(msd_send, net_device); in netvsc_send()
917 netvsc_free_send_slot(net_device, in netvsc_send()
924 ret = netvsc_send_pkt(cur_send, net_device); in netvsc_send()
927 netvsc_free_send_slot(net_device, section_index); in netvsc_send()
934 struct netvsc_device *net_device, in netvsc_send_recv_completion() argument
940 struct net_device *ndev; in netvsc_send_recv_completion()
942 ndev = net_device->ndev; in netvsc_send_recv_completion()
977 static void netvsc_receive(struct netvsc_device *net_device, in netvsc_receive() argument
989 struct net_device *ndev; in netvsc_receive()
991 ndev = net_device->ndev; in netvsc_receive()
1030 netvsc_packet->data = (void *)((unsigned long)net_device-> in netvsc_receive()
1042 netvsc_send_recv_completion(device, channel, net_device, in netvsc_receive()
1051 struct net_device *ndev; in netvsc_send_table()
1085 struct netvsc_device *net_device; in netvsc_channel_cb() local
1091 struct net_device *ndev; in netvsc_channel_cb()
1098 net_device = get_inbound_net_device(device); in netvsc_channel_cb()
1099 if (!net_device) in netvsc_channel_cb()
1101 ndev = net_device->ndev; in netvsc_channel_cb()
1112 netvsc_send_completion(net_device, in netvsc_channel_cb()
1117 netvsc_receive(net_device, channel, in netvsc_channel_cb()
1172 struct netvsc_device *net_device; in netvsc_device_add() local
1173 struct net_device *ndev; in netvsc_device_add()
1175 net_device = alloc_net_device(device); in netvsc_device_add()
1176 if (!net_device) in netvsc_device_add()
1179 net_device->ring_size = ring_size; in netvsc_device_add()
1188 ndev = net_device->ndev; in netvsc_device_add()
1191 net_device->nd_ctx = netdev_priv(ndev); in netvsc_device_add()
1194 init_completion(&net_device->channel_init_wait); in netvsc_device_add()
1196 set_per_channel_state(device->channel, net_device->cb_buffer); in netvsc_device_add()
1211 net_device->chn_table[0] = device->channel; in netvsc_device_add()
1228 free_netvsc_device(net_device); in netvsc_device_add()