Lines Matching refs:net

238 static int tbnet_login_response(struct tbnet *net, u64 route, u8 sequence,  in tbnet_login_response()  argument
242 struct tb_xdomain *xd = net->xd; in tbnet_login_response()
248 memcpy(reply.receiver_mac, net->dev->dev_addr, ETH_ALEN); in tbnet_login_response()
255 static int tbnet_login_request(struct tbnet *net, u8 sequence) in tbnet_login_request() argument
259 struct tb_xdomain *xd = net->xd; in tbnet_login_request()
264 atomic_inc_return(&net->command_id)); in tbnet_login_request()
267 request.transmit_path = net->local_transmit_path; in tbnet_login_request()
275 static int tbnet_logout_response(struct tbnet *net, u64 route, u8 sequence, in tbnet_logout_response() argument
279 struct tb_xdomain *xd = net->xd; in tbnet_logout_response()
284 atomic_inc_return(&net->command_id)); in tbnet_logout_response()
289 static int tbnet_logout_request(struct tbnet *net) in tbnet_logout_request() argument
293 struct tb_xdomain *xd = net->xd; in tbnet_logout_request()
298 atomic_inc_return(&net->command_id)); in tbnet_logout_request()
306 static void start_login(struct tbnet *net) in start_login() argument
308 mutex_lock(&net->connection_lock); in start_login()
309 net->login_sent = false; in start_login()
310 net->login_received = false; in start_login()
311 mutex_unlock(&net->connection_lock); in start_login()
313 queue_delayed_work(system_long_wq, &net->login_work, in start_login()
317 static void stop_login(struct tbnet *net) in stop_login() argument
319 cancel_delayed_work_sync(&net->login_work); in stop_login()
320 cancel_work_sync(&net->connected_work); in stop_login()
364 static void tbnet_tear_down(struct tbnet *net, bool send_logout) in tbnet_tear_down() argument
366 netif_carrier_off(net->dev); in tbnet_tear_down()
367 netif_stop_queue(net->dev); in tbnet_tear_down()
369 stop_login(net); in tbnet_tear_down()
371 mutex_lock(&net->connection_lock); in tbnet_tear_down()
373 if (net->login_sent && net->login_received) { in tbnet_tear_down()
377 ret = tbnet_logout_request(net); in tbnet_tear_down()
382 tb_ring_stop(net->rx_ring.ring); in tbnet_tear_down()
383 tb_ring_stop(net->tx_ring.ring); in tbnet_tear_down()
384 tbnet_free_buffers(&net->rx_ring); in tbnet_tear_down()
385 tbnet_free_buffers(&net->tx_ring); in tbnet_tear_down()
387 ret = tb_xdomain_disable_paths(net->xd, in tbnet_tear_down()
388 net->local_transmit_path, in tbnet_tear_down()
389 net->rx_ring.ring->hop, in tbnet_tear_down()
390 net->remote_transmit_path, in tbnet_tear_down()
391 net->tx_ring.ring->hop); in tbnet_tear_down()
393 netdev_warn(net->dev, "failed to disable DMA paths\n"); in tbnet_tear_down()
395 tb_xdomain_release_in_hopid(net->xd, net->remote_transmit_path); in tbnet_tear_down()
396 net->remote_transmit_path = 0; in tbnet_tear_down()
399 net->login_retries = 0; in tbnet_tear_down()
400 net->login_sent = false; in tbnet_tear_down()
401 net->login_received = false; in tbnet_tear_down()
403 mutex_unlock(&net->connection_lock); in tbnet_tear_down()
409 struct tbnet *net = data; in tbnet_handle_packet() local
418 if (!uuid_equal(&pkg->hdr.initiator_uuid, net->xd->remote_uuid)) in tbnet_handle_packet()
420 if (!uuid_equal(&pkg->hdr.target_uuid, net->xd->local_uuid)) in tbnet_handle_packet()
425 if (route != net->xd->route) in tbnet_handle_packet()
434 if (!netif_running(net->dev)) in tbnet_handle_packet()
437 ret = tbnet_login_response(net, route, sequence, in tbnet_handle_packet()
440 mutex_lock(&net->connection_lock); in tbnet_handle_packet()
441 net->login_received = true; in tbnet_handle_packet()
442 net->remote_transmit_path = pkg->transmit_path; in tbnet_handle_packet()
448 if (net->login_retries >= TBNET_LOGIN_RETRIES || in tbnet_handle_packet()
449 !net->login_sent) { in tbnet_handle_packet()
450 net->login_retries = 0; in tbnet_handle_packet()
452 &net->login_work, 0); in tbnet_handle_packet()
454 mutex_unlock(&net->connection_lock); in tbnet_handle_packet()
456 queue_work(system_long_wq, &net->connected_work); in tbnet_handle_packet()
461 ret = tbnet_logout_response(net, route, sequence, command_id); in tbnet_handle_packet()
463 queue_work(system_long_wq, &net->disconnect_work); in tbnet_handle_packet()
471 netdev_warn(net->dev, "failed to send ThunderboltIP response\n"); in tbnet_handle_packet()
481 static int tbnet_alloc_rx_buffers(struct tbnet *net, unsigned int nbuffers) in tbnet_alloc_rx_buffers() argument
483 struct tbnet_ring *ring = &net->rx_ring; in tbnet_alloc_rx_buffers()
513 tf->dev = net->dev; in tbnet_alloc_rx_buffers()
527 static struct tbnet_frame *tbnet_get_tx_buffer(struct tbnet *net) in tbnet_get_tx_buffer() argument
529 struct tbnet_ring *ring = &net->tx_ring; in tbnet_get_tx_buffer()
552 struct tbnet *net = netdev_priv(tf->dev); in tbnet_tx_callback() local
555 net->tx_ring.prod++; in tbnet_tx_callback()
557 if (tbnet_available_buffers(&net->tx_ring) >= TBNET_RING_SIZE / 2) in tbnet_tx_callback()
558 netif_wake_queue(net->dev); in tbnet_tx_callback()
561 static int tbnet_alloc_tx_buffers(struct tbnet *net) in tbnet_alloc_tx_buffers() argument
563 struct tbnet_ring *ring = &net->tx_ring; in tbnet_alloc_tx_buffers()
586 tf->dev = net->dev; in tbnet_alloc_tx_buffers()
601 struct tbnet *net = container_of(work, typeof(*net), connected_work); in tbnet_connected_work() local
605 if (netif_carrier_ok(net->dev)) in tbnet_connected_work()
608 mutex_lock(&net->connection_lock); in tbnet_connected_work()
609 connected = net->login_sent && net->login_received; in tbnet_connected_work()
610 mutex_unlock(&net->connection_lock); in tbnet_connected_work()
615 ret = tb_xdomain_alloc_in_hopid(net->xd, net->remote_transmit_path); in tbnet_connected_work()
616 if (ret != net->remote_transmit_path) { in tbnet_connected_work()
617 netdev_err(net->dev, "failed to allocate Rx HopID\n"); in tbnet_connected_work()
628 tb_ring_start(net->tx_ring.ring); in tbnet_connected_work()
629 tb_ring_start(net->rx_ring.ring); in tbnet_connected_work()
631 ret = tbnet_alloc_rx_buffers(net, TBNET_RING_SIZE); in tbnet_connected_work()
635 ret = tbnet_alloc_tx_buffers(net); in tbnet_connected_work()
639 ret = tb_xdomain_enable_paths(net->xd, net->local_transmit_path, in tbnet_connected_work()
640 net->rx_ring.ring->hop, in tbnet_connected_work()
641 net->remote_transmit_path, in tbnet_connected_work()
642 net->tx_ring.ring->hop); in tbnet_connected_work()
644 netdev_err(net->dev, "failed to enable DMA paths\n"); in tbnet_connected_work()
648 netif_carrier_on(net->dev); in tbnet_connected_work()
649 netif_start_queue(net->dev); in tbnet_connected_work()
653 tbnet_free_buffers(&net->tx_ring); in tbnet_connected_work()
655 tbnet_free_buffers(&net->rx_ring); in tbnet_connected_work()
657 tb_ring_stop(net->rx_ring.ring); in tbnet_connected_work()
658 tb_ring_stop(net->tx_ring.ring); in tbnet_connected_work()
659 tb_xdomain_release_in_hopid(net->xd, net->remote_transmit_path); in tbnet_connected_work()
664 struct tbnet *net = container_of(work, typeof(*net), login_work.work); in tbnet_login_work() local
668 if (netif_carrier_ok(net->dev)) in tbnet_login_work()
671 ret = tbnet_login_request(net, net->login_retries % 4); in tbnet_login_work()
673 if (net->login_retries++ < TBNET_LOGIN_RETRIES) { in tbnet_login_work()
674 queue_delayed_work(system_long_wq, &net->login_work, in tbnet_login_work()
677 netdev_info(net->dev, "ThunderboltIP login timed out\n"); in tbnet_login_work()
680 net->login_retries = 0; in tbnet_login_work()
682 mutex_lock(&net->connection_lock); in tbnet_login_work()
683 net->login_sent = true; in tbnet_login_work()
684 mutex_unlock(&net->connection_lock); in tbnet_login_work()
686 queue_work(system_long_wq, &net->connected_work); in tbnet_login_work()
692 struct tbnet *net = container_of(work, typeof(*net), disconnect_work); in tbnet_disconnect_work() local
694 tbnet_tear_down(net, false); in tbnet_disconnect_work()
697 static bool tbnet_check_frame(struct tbnet *net, const struct tbnet_frame *tf, in tbnet_check_frame() argument
704 net->stats.rx_crc_errors++; in tbnet_check_frame()
707 net->stats.rx_over_errors++; in tbnet_check_frame()
714 net->stats.rx_length_errors++; in tbnet_check_frame()
724 net->stats.rx_length_errors++; in tbnet_check_frame()
731 if (net->skb && net->rx_hdr.frame_count) { in tbnet_check_frame()
733 if (frame_count != net->rx_hdr.frame_count) { in tbnet_check_frame()
734 net->stats.rx_length_errors++; in tbnet_check_frame()
741 if (frame_index != net->rx_hdr.frame_index + 1 || in tbnet_check_frame()
742 frame_id != net->rx_hdr.frame_id) { in tbnet_check_frame()
743 net->stats.rx_missed_errors++; in tbnet_check_frame()
747 if (net->skb->len + frame_size > TBNET_MAX_MTU) { in tbnet_check_frame()
748 net->stats.rx_length_errors++; in tbnet_check_frame()
757 net->stats.rx_length_errors++; in tbnet_check_frame()
761 net->stats.rx_missed_errors++; in tbnet_check_frame()
770 struct tbnet *net = container_of(napi, struct tbnet, napi); in tbnet_poll() local
771 unsigned int cleaned_count = tbnet_available_buffers(&net->rx_ring); in tbnet_poll()
772 struct device *dma_dev = tb_ring_dma_device(net->rx_ring.ring); in tbnet_poll()
790 tbnet_alloc_rx_buffers(net, cleaned_count); in tbnet_poll()
794 frame = tb_ring_poll(net->rx_ring.ring); in tbnet_poll()
805 net->rx_ring.cons++; in tbnet_poll()
809 if (!tbnet_check_frame(net, tf, hdr)) { in tbnet_poll()
811 dev_kfree_skb_any(net->skb); in tbnet_poll()
812 net->skb = NULL; in tbnet_poll()
818 skb = net->skb; in tbnet_poll()
824 net->stats.rx_errors++; in tbnet_poll()
831 net->skb = skb; in tbnet_poll()
838 net->rx_hdr.frame_size = frame_size; in tbnet_poll()
839 net->rx_hdr.frame_count = le32_to_cpu(hdr->frame_count); in tbnet_poll()
840 net->rx_hdr.frame_index = le16_to_cpu(hdr->frame_index); in tbnet_poll()
841 net->rx_hdr.frame_id = le16_to_cpu(hdr->frame_id); in tbnet_poll()
842 last = net->rx_hdr.frame_index == net->rx_hdr.frame_count - 1; in tbnet_poll()
845 net->stats.rx_bytes += frame_size; in tbnet_poll()
848 skb->protocol = eth_type_trans(skb, net->dev); in tbnet_poll()
849 napi_gro_receive(&net->napi, skb); in tbnet_poll()
850 net->skb = NULL; in tbnet_poll()
854 net->stats.rx_packets += rx_packets; in tbnet_poll()
857 tbnet_alloc_rx_buffers(net, cleaned_count); in tbnet_poll()
864 tb_ring_poll_complete(net->rx_ring.ring); in tbnet_poll()
871 struct tbnet *net = data; in tbnet_start_poll() local
873 napi_schedule(&net->napi); in tbnet_start_poll()
878 struct tbnet *net = netdev_priv(dev); in tbnet_open() local
879 struct tb_xdomain *xd = net->xd; in tbnet_open()
893 net->tx_ring.ring = ring; in tbnet_open()
898 tb_ring_free(net->tx_ring.ring); in tbnet_open()
899 net->tx_ring.ring = NULL; in tbnet_open()
902 net->local_transmit_path = hopid; in tbnet_open()
909 if (tbnet_e2e && net->svc->prtcstns & TBNET_E2E) in tbnet_open()
913 net->tx_ring.ring->hop, sof_mask, in tbnet_open()
914 eof_mask, tbnet_start_poll, net); in tbnet_open()
918 tb_ring_free(net->tx_ring.ring); in tbnet_open()
919 net->tx_ring.ring = NULL; in tbnet_open()
922 net->rx_ring.ring = ring; in tbnet_open()
924 napi_enable(&net->napi); in tbnet_open()
925 start_login(net); in tbnet_open()
932 struct tbnet *net = netdev_priv(dev); in tbnet_stop() local
934 napi_disable(&net->napi); in tbnet_stop()
936 cancel_work_sync(&net->disconnect_work); in tbnet_stop()
937 tbnet_tear_down(net, true); in tbnet_stop()
939 tb_ring_free(net->rx_ring.ring); in tbnet_stop()
940 net->rx_ring.ring = NULL; in tbnet_stop()
942 tb_xdomain_release_out_hopid(net->xd, net->local_transmit_path); in tbnet_stop()
943 tb_ring_free(net->tx_ring.ring); in tbnet_stop()
944 net->tx_ring.ring = NULL; in tbnet_stop()
949 static bool tbnet_xmit_csum_and_map(struct tbnet *net, struct sk_buff *skb, in tbnet_xmit_csum_and_map() argument
953 struct device *dma_dev = tb_ring_dma_device(net->tx_ring.ring); in tbnet_xmit_csum_and_map()
1061 struct tbnet *net = netdev_priv(dev); in tbnet_start_xmit() local
1063 u16 frame_id = atomic_read(&net->frame_id); in tbnet_start_xmit()
1075 if (tbnet_available_buffers(&net->tx_ring) < nframes) { in tbnet_start_xmit()
1076 netif_stop_queue(net->dev); in tbnet_start_xmit()
1080 frames[frame_index] = tbnet_get_tx_buffer(net); in tbnet_start_xmit()
1130 frames[frame_index] = tbnet_get_tx_buffer(net); in tbnet_start_xmit()
1168 if (!tbnet_xmit_csum_and_map(net, skb, frames, frame_index + 1)) in tbnet_start_xmit()
1172 tb_ring_tx(net->tx_ring.ring, &frames[i]->frame); in tbnet_start_xmit()
1174 if (net->svc->prtcstns & TBNET_MATCH_FRAGS_ID) in tbnet_start_xmit()
1175 atomic_inc(&net->frame_id); in tbnet_start_xmit()
1177 net->stats.tx_packets++; in tbnet_start_xmit()
1178 net->stats.tx_bytes += skb->len; in tbnet_start_xmit()
1186 net->tx_ring.cons -= frame_index; in tbnet_start_xmit()
1189 net->stats.tx_errors++; in tbnet_start_xmit()
1197 struct tbnet *net = netdev_priv(dev); in tbnet_get_stats64() local
1199 stats->tx_packets = net->stats.tx_packets; in tbnet_get_stats64()
1200 stats->rx_packets = net->stats.rx_packets; in tbnet_get_stats64()
1201 stats->tx_bytes = net->stats.tx_bytes; in tbnet_get_stats64()
1202 stats->rx_bytes = net->stats.rx_bytes; in tbnet_get_stats64()
1203 stats->rx_errors = net->stats.rx_errors + net->stats.rx_length_errors + in tbnet_get_stats64()
1204 net->stats.rx_over_errors + net->stats.rx_crc_errors + in tbnet_get_stats64()
1205 net->stats.rx_missed_errors; in tbnet_get_stats64()
1206 stats->tx_errors = net->stats.tx_errors; in tbnet_get_stats64()
1207 stats->rx_length_errors = net->stats.rx_length_errors; in tbnet_get_stats64()
1208 stats->rx_over_errors = net->stats.rx_over_errors; in tbnet_get_stats64()
1209 stats->rx_crc_errors = net->stats.rx_crc_errors; in tbnet_get_stats64()
1210 stats->rx_missed_errors = net->stats.rx_missed_errors; in tbnet_get_stats64()
1222 const struct tbnet *net = netdev_priv(dev); in tbnet_generate_mac() local
1223 const struct tb_xdomain *xd = net->xd; in tbnet_generate_mac()
1243 struct tbnet *net; in tbnet_probe() local
1246 dev = alloc_etherdev(sizeof(*net)); in tbnet_probe()
1252 net = netdev_priv(dev); in tbnet_probe()
1253 INIT_DELAYED_WORK(&net->login_work, tbnet_login_work); in tbnet_probe()
1254 INIT_WORK(&net->connected_work, tbnet_connected_work); in tbnet_probe()
1255 INIT_WORK(&net->disconnect_work, tbnet_disconnect_work); in tbnet_probe()
1256 mutex_init(&net->connection_lock); in tbnet_probe()
1257 atomic_set(&net->command_id, 0); in tbnet_probe()
1258 atomic_set(&net->frame_id, 0); in tbnet_probe()
1259 net->svc = svc; in tbnet_probe()
1260 net->dev = dev; in tbnet_probe()
1261 net->xd = xd; in tbnet_probe()
1286 netif_napi_add(dev, &net->napi, tbnet_poll); in tbnet_probe()
1292 net->handler.uuid = &tbnet_svc_uuid; in tbnet_probe()
1293 net->handler.callback = tbnet_handle_packet; in tbnet_probe()
1294 net->handler.data = net; in tbnet_probe()
1295 tb_register_protocol_handler(&net->handler); in tbnet_probe()
1297 tb_service_set_drvdata(svc, net); in tbnet_probe()
1301 tb_unregister_protocol_handler(&net->handler); in tbnet_probe()
1311 struct tbnet *net = tb_service_get_drvdata(svc); in tbnet_remove() local
1313 unregister_netdev(net->dev); in tbnet_remove()
1314 tb_unregister_protocol_handler(&net->handler); in tbnet_remove()
1315 free_netdev(net->dev); in tbnet_remove()
1326 struct tbnet *net = tb_service_get_drvdata(svc); in tbnet_suspend() local
1328 stop_login(net); in tbnet_suspend()
1329 if (netif_running(net->dev)) { in tbnet_suspend()
1330 netif_device_detach(net->dev); in tbnet_suspend()
1331 tbnet_tear_down(net, true); in tbnet_suspend()
1334 tb_unregister_protocol_handler(&net->handler); in tbnet_suspend()
1341 struct tbnet *net = tb_service_get_drvdata(svc); in tbnet_resume() local
1343 tb_register_protocol_handler(&net->handler); in tbnet_resume()
1345 netif_carrier_off(net->dev); in tbnet_resume()
1346 if (netif_running(net->dev)) { in tbnet_resume()
1347 netif_device_attach(net->dev); in tbnet_resume()
1348 start_login(net); in tbnet_resume()