Lines Matching refs:dev
111 struct eth_dev *dev = netdev_priv(net); in eth_get_drvinfo() local
115 strscpy(p->fw_version, dev->gadget->name, sizeof(p->fw_version)); in eth_get_drvinfo()
116 strscpy(p->bus_info, dev_name(&dev->gadget->dev), sizeof(p->bus_info)); in eth_get_drvinfo()
130 static void defer_kevent(struct eth_dev *dev, int flag) in defer_kevent() argument
132 if (test_and_set_bit(flag, &dev->todo)) in defer_kevent()
134 if (!schedule_work(&dev->work)) in defer_kevent()
135 ERROR(dev, "kevent %d may have been dropped\n", flag); in defer_kevent()
137 DBG(dev, "kevent %d scheduled\n", flag); in defer_kevent()
143 rx_submit(struct eth_dev *dev, struct usb_request *req, gfp_t gfp_flags) in rx_submit() argument
145 struct usb_gadget *g = dev->gadget; in rx_submit()
152 spin_lock_irqsave(&dev->lock, flags); in rx_submit()
153 if (dev->port_usb) in rx_submit()
154 out = dev->port_usb->out_ep; in rx_submit()
160 spin_unlock_irqrestore(&dev->lock, flags); in rx_submit()
176 size += sizeof(struct ethhdr) + dev->net->mtu + RX_EXTRA; in rx_submit()
177 size += dev->port_usb->header_len; in rx_submit()
184 if (dev->port_usb->is_fixed) in rx_submit()
185 size = max_t(size_t, size, dev->port_usb->fixed_out_len); in rx_submit()
186 spin_unlock_irqrestore(&dev->lock, flags); in rx_submit()
188 skb = __netdev_alloc_skb(dev->net, size + NET_IP_ALIGN, gfp_flags); in rx_submit()
190 DBG(dev, "no rx skb\n"); in rx_submit()
198 if (likely(!dev->no_skb_reserve)) in rx_submit()
209 defer_kevent(dev, WORK_RX_MEMORY); in rx_submit()
211 DBG(dev, "rx submit --> %d\n", retval); in rx_submit()
214 spin_lock_irqsave(&dev->req_lock, flags); in rx_submit()
215 list_add(&req->list, &dev->rx_reqs); in rx_submit()
216 spin_unlock_irqrestore(&dev->req_lock, flags); in rx_submit()
224 struct eth_dev *dev = ep->driver_data; in rx_complete() local
233 if (dev->unwrap) { in rx_complete()
236 spin_lock_irqsave(&dev->lock, flags); in rx_complete()
237 if (dev->port_usb) { in rx_complete()
238 status = dev->unwrap(dev->port_usb, in rx_complete()
240 &dev->rx_frames); in rx_complete()
245 spin_unlock_irqrestore(&dev->lock, flags); in rx_complete()
247 skb_queue_tail(&dev->rx_frames, skb); in rx_complete()
251 skb2 = skb_dequeue(&dev->rx_frames); in rx_complete()
256 dev->net->stats.rx_errors++; in rx_complete()
257 dev->net->stats.rx_length_errors++; in rx_complete()
258 DBG(dev, "rx length %d\n", skb2->len); in rx_complete()
262 skb2->protocol = eth_type_trans(skb2, dev->net); in rx_complete()
263 dev->net->stats.rx_packets++; in rx_complete()
264 dev->net->stats.rx_bytes += skb2->len; in rx_complete()
271 skb2 = skb_dequeue(&dev->rx_frames); in rx_complete()
278 VDBG(dev, "rx shutdown, code %d\n", status); in rx_complete()
283 DBG(dev, "rx %s reset\n", ep->name); in rx_complete()
284 defer_kevent(dev, WORK_RX_MEMORY); in rx_complete()
291 dev->net->stats.rx_over_errors++; in rx_complete()
295 dev->net->stats.rx_errors++; in rx_complete()
296 DBG(dev, "rx status %d\n", status); in rx_complete()
302 if (!netif_running(dev->net)) { in rx_complete()
304 spin_lock(&dev->req_lock); in rx_complete()
305 list_add(&req->list, &dev->rx_reqs); in rx_complete()
306 spin_unlock(&dev->req_lock); in rx_complete()
310 rx_submit(dev, req, GFP_ATOMIC); in rx_complete()
352 static int alloc_requests(struct eth_dev *dev, struct gether *link, unsigned n) in alloc_requests() argument
356 spin_lock(&dev->req_lock); in alloc_requests()
357 status = prealloc(&dev->tx_reqs, link->in_ep, n); in alloc_requests()
360 status = prealloc(&dev->rx_reqs, link->out_ep, n); in alloc_requests()
365 DBG(dev, "can't alloc requests\n"); in alloc_requests()
367 spin_unlock(&dev->req_lock); in alloc_requests()
371 static void rx_fill(struct eth_dev *dev, gfp_t gfp_flags) in rx_fill() argument
377 spin_lock_irqsave(&dev->req_lock, flags); in rx_fill()
378 while (!list_empty(&dev->rx_reqs)) { in rx_fill()
379 req = list_first_entry(&dev->rx_reqs, struct usb_request, list); in rx_fill()
381 spin_unlock_irqrestore(&dev->req_lock, flags); in rx_fill()
383 if (rx_submit(dev, req, gfp_flags) < 0) { in rx_fill()
384 defer_kevent(dev, WORK_RX_MEMORY); in rx_fill()
388 spin_lock_irqsave(&dev->req_lock, flags); in rx_fill()
390 spin_unlock_irqrestore(&dev->req_lock, flags); in rx_fill()
395 struct eth_dev *dev = container_of(work, struct eth_dev, work); in eth_work() local
397 if (test_and_clear_bit(WORK_RX_MEMORY, &dev->todo)) { in eth_work()
398 if (netif_running(dev->net)) in eth_work()
399 rx_fill(dev, GFP_KERNEL); in eth_work()
402 if (dev->todo) in eth_work()
403 DBG(dev, "work done, flags = 0x%lx\n", dev->todo); in eth_work()
409 struct eth_dev *dev = ep->driver_data; in tx_complete() local
413 dev->net->stats.tx_errors++; in tx_complete()
414 VDBG(dev, "tx err %d\n", req->status); in tx_complete()
421 dev->net->stats.tx_bytes += skb->len; in tx_complete()
424 dev->net->stats.tx_packets++; in tx_complete()
426 spin_lock(&dev->req_lock); in tx_complete()
427 list_add(&req->list, &dev->tx_reqs); in tx_complete()
428 spin_unlock(&dev->req_lock); in tx_complete()
430 atomic_dec(&dev->tx_qlen); in tx_complete()
431 if (netif_carrier_ok(dev->net)) in tx_complete()
432 netif_wake_queue(dev->net); in tx_complete()
457 struct eth_dev *dev = netdev_priv(net); in eth_start_xmit() local
465 spin_lock_irqsave(&dev->lock, flags); in eth_start_xmit()
466 if (dev->port_usb) { in eth_start_xmit()
467 in = dev->port_usb->in_ep; in eth_start_xmit()
468 cdc_filter = dev->port_usb->cdc_filter; in eth_start_xmit()
474 if (dev->port_usb && dev->port_usb->is_suspend) { in eth_start_xmit()
475 DBG(dev, "Port suspended. Triggering wakeup\n"); in eth_start_xmit()
477 spin_unlock_irqrestore(&dev->lock, flags); in eth_start_xmit()
478 ether_wakeup_host(dev->port_usb); in eth_start_xmit()
482 spin_unlock_irqrestore(&dev->lock, flags); in eth_start_xmit()
512 spin_lock_irqsave(&dev->req_lock, flags); in eth_start_xmit()
518 if (list_empty(&dev->tx_reqs)) { in eth_start_xmit()
519 spin_unlock_irqrestore(&dev->req_lock, flags); in eth_start_xmit()
523 req = list_first_entry(&dev->tx_reqs, struct usb_request, list); in eth_start_xmit()
527 if (list_empty(&dev->tx_reqs)) in eth_start_xmit()
529 spin_unlock_irqrestore(&dev->req_lock, flags); in eth_start_xmit()
535 if (dev->wrap) { in eth_start_xmit()
538 spin_lock_irqsave(&dev->lock, flags); in eth_start_xmit()
539 if (dev->port_usb) in eth_start_xmit()
540 skb = dev->wrap(dev->port_usb, skb); in eth_start_xmit()
541 spin_unlock_irqrestore(&dev->lock, flags); in eth_start_xmit()
546 if (dev->port_usb && in eth_start_xmit()
547 dev->port_usb->supports_multi_frame) in eth_start_xmit()
559 if (dev->port_usb && in eth_start_xmit()
560 dev->port_usb->is_fixed && in eth_start_xmit()
561 length == dev->port_usb->fixed_in_len && in eth_start_xmit()
571 if (req->zero && !dev->zlp && (length % in->maxpacket) == 0) in eth_start_xmit()
579 DBG(dev, "tx queue err %d\n", retval); in eth_start_xmit()
583 atomic_inc(&dev->tx_qlen); in eth_start_xmit()
589 dev->net->stats.tx_dropped++; in eth_start_xmit()
591 spin_lock_irqsave(&dev->req_lock, flags); in eth_start_xmit()
592 if (list_empty(&dev->tx_reqs)) in eth_start_xmit()
594 list_add(&req->list, &dev->tx_reqs); in eth_start_xmit()
595 spin_unlock_irqrestore(&dev->req_lock, flags); in eth_start_xmit()
602 static void eth_start(struct eth_dev *dev, gfp_t gfp_flags) in eth_start() argument
604 DBG(dev, "%s\n", __func__); in eth_start()
607 rx_fill(dev, gfp_flags); in eth_start()
610 atomic_set(&dev->tx_qlen, 0); in eth_start()
611 netif_wake_queue(dev->net); in eth_start()
616 struct eth_dev *dev = netdev_priv(net); in eth_open() local
619 DBG(dev, "%s\n", __func__); in eth_open()
620 if (netif_carrier_ok(dev->net)) in eth_open()
621 eth_start(dev, GFP_KERNEL); in eth_open()
623 spin_lock_irq(&dev->lock); in eth_open()
624 link = dev->port_usb; in eth_open()
627 spin_unlock_irq(&dev->lock); in eth_open()
634 struct eth_dev *dev = netdev_priv(net); in eth_stop() local
637 VDBG(dev, "%s\n", __func__); in eth_stop()
640 DBG(dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld\n", in eth_stop()
641 dev->net->stats.rx_packets, dev->net->stats.tx_packets, in eth_stop()
642 dev->net->stats.rx_errors, dev->net->stats.tx_errors in eth_stop()
646 spin_lock_irqsave(&dev->lock, flags); in eth_stop()
647 if (dev->port_usb) { in eth_stop()
648 struct gether *link = dev->port_usb; in eth_stop()
669 DBG(dev, "host still using in/out endpoints\n"); in eth_stop()
676 spin_unlock_irqrestore(&dev->lock, flags); in eth_stop()
743 struct eth_dev *dev; in gether_setup_name() local
748 net = alloc_etherdev(sizeof *dev); in gether_setup_name()
752 dev = netdev_priv(net); in gether_setup_name()
753 spin_lock_init(&dev->lock); in gether_setup_name()
754 spin_lock_init(&dev->req_lock); in gether_setup_name()
755 INIT_WORK(&dev->work, eth_work); in gether_setup_name()
756 INIT_LIST_HEAD(&dev->tx_reqs); in gether_setup_name()
757 INIT_LIST_HEAD(&dev->rx_reqs); in gether_setup_name()
759 skb_queue_head_init(&dev->rx_frames); in gether_setup_name()
762 dev->net = net; in gether_setup_name()
763 dev->qmult = qmult; in gether_setup_name()
768 dev_warn(&g->dev, in gether_setup_name()
774 if (get_ether_addr(host_addr, dev->host_mac)) in gether_setup_name()
775 dev_warn(&g->dev, in gether_setup_name()
779 memcpy(ethaddr, dev->host_mac, ETH_ALEN); in gether_setup_name()
789 dev->gadget = g; in gether_setup_name()
790 SET_NETDEV_DEV(net, &g->dev); in gether_setup_name()
795 dev_dbg(&g->dev, "register_netdev failed, %d\n", status); in gether_setup_name()
797 dev = ERR_PTR(status); in gether_setup_name()
799 INFO(dev, "MAC %pM\n", net->dev_addr); in gether_setup_name()
800 INFO(dev, "HOST MAC %pM\n", dev->host_mac); in gether_setup_name()
810 return dev; in gether_setup_name()
817 struct eth_dev *dev; in gether_setup_name_default() local
819 net = alloc_etherdev(sizeof(*dev)); in gether_setup_name_default()
823 dev = netdev_priv(net); in gether_setup_name_default()
824 spin_lock_init(&dev->lock); in gether_setup_name_default()
825 spin_lock_init(&dev->req_lock); in gether_setup_name_default()
826 INIT_WORK(&dev->work, eth_work); in gether_setup_name_default()
827 INIT_LIST_HEAD(&dev->tx_reqs); in gether_setup_name_default()
828 INIT_LIST_HEAD(&dev->rx_reqs); in gether_setup_name_default()
830 skb_queue_head_init(&dev->rx_frames); in gether_setup_name_default()
833 dev->net = net; in gether_setup_name_default()
834 dev->qmult = QMULT_DEFAULT; in gether_setup_name_default()
837 eth_random_addr(dev->dev_mac); in gether_setup_name_default()
842 eth_random_addr(dev->host_mac); in gether_setup_name_default()
859 struct eth_dev *dev; in gether_register_netdev() local
863 if (!net->dev.parent) in gether_register_netdev()
865 dev = netdev_priv(net); in gether_register_netdev()
866 g = dev->gadget; in gether_register_netdev()
868 eth_hw_addr_set(net, dev->dev_mac); in gether_register_netdev()
872 dev_dbg(&g->dev, "register_netdev failed, %d\n", status); in gether_register_netdev()
875 INFO(dev, "HOST MAC %pM\n", dev->host_mac); in gether_register_netdev()
876 INFO(dev, "MAC %pM\n", dev->dev_mac); in gether_register_netdev()
891 struct eth_dev *dev; in gether_set_gadget() local
893 dev = netdev_priv(net); in gether_set_gadget()
894 dev->gadget = g; in gether_set_gadget()
895 SET_NETDEV_DEV(net, &g->dev); in gether_set_gadget()
901 struct eth_dev *dev; in gether_set_dev_addr() local
904 dev = netdev_priv(net); in gether_set_dev_addr()
907 memcpy(dev->dev_mac, new_addr, ETH_ALEN); in gether_set_dev_addr()
915 struct eth_dev *dev; in gether_get_dev_addr() local
918 dev = netdev_priv(net); in gether_get_dev_addr()
919 ret = get_ether_addr_str(dev->dev_mac, dev_addr, len); in gether_get_dev_addr()
931 struct eth_dev *dev; in gether_set_host_addr() local
934 dev = netdev_priv(net); in gether_set_host_addr()
937 memcpy(dev->host_mac, new_addr, ETH_ALEN); in gether_set_host_addr()
944 struct eth_dev *dev; in gether_get_host_addr() local
947 dev = netdev_priv(net); in gether_get_host_addr()
948 ret = get_ether_addr_str(dev->host_mac, host_addr, len); in gether_get_host_addr()
960 struct eth_dev *dev; in gether_get_host_addr_cdc() local
965 dev = netdev_priv(net); in gether_get_host_addr_cdc()
966 snprintf(host_addr, len, "%pm", dev->host_mac); in gether_get_host_addr_cdc()
976 struct eth_dev *dev; in gether_get_host_addr_u8() local
978 dev = netdev_priv(net); in gether_get_host_addr_u8()
979 memcpy(host_mac, dev->host_mac, ETH_ALEN); in gether_get_host_addr_u8()
985 struct eth_dev *dev; in gether_set_qmult() local
987 dev = netdev_priv(net); in gether_set_qmult()
988 dev->qmult = qmult; in gether_set_qmult()
994 struct eth_dev *dev; in gether_get_qmult() local
996 dev = netdev_priv(net); in gether_get_qmult()
997 return dev->qmult; in gether_get_qmult()
1003 struct eth_dev *dev = netdev_priv(net); in gether_get_ifname() local
1008 dev->ifname_set ? net->name : netdev_name(net)); in gether_get_ifname()
1016 struct eth_dev *dev = netdev_priv(net); in gether_set_ifname() local
1036 dev->ifname_set = true; in gether_set_ifname()
1044 struct eth_dev *dev = link->ioport; in gether_suspend() local
1047 if (!dev) in gether_suspend()
1050 if (atomic_read(&dev->tx_qlen)) { in gether_suspend()
1055 ether_wakeup_host(dev->port_usb); in gether_suspend()
1058 spin_lock_irqsave(&dev->lock, flags); in gether_suspend()
1060 spin_unlock_irqrestore(&dev->lock, flags); in gether_suspend()
1066 struct eth_dev *dev = link->ioport; in gether_resume() local
1069 if (!dev) in gether_resume()
1072 if (netif_queue_stopped(dev->net)) in gether_resume()
1073 netif_start_queue(dev->net); in gether_resume()
1075 spin_lock_irqsave(&dev->lock, flags); in gether_resume()
1077 spin_unlock_irqrestore(&dev->lock, flags); in gether_resume()
1087 void gether_cleanup(struct eth_dev *dev) in gether_cleanup() argument
1089 if (!dev) in gether_cleanup()
1092 unregister_netdev(dev->net); in gether_cleanup()
1093 flush_work(&dev->work); in gether_cleanup()
1094 free_netdev(dev->net); in gether_cleanup()
1116 struct eth_dev *dev = link->ioport; in gether_connect() local
1119 if (!dev) in gether_connect()
1122 link->in_ep->driver_data = dev; in gether_connect()
1125 DBG(dev, "enable %s --> %d\n", in gether_connect()
1130 link->out_ep->driver_data = dev; in gether_connect()
1133 DBG(dev, "enable %s --> %d\n", in gether_connect()
1139 result = alloc_requests(dev, link, qlen(dev->gadget, in gether_connect()
1140 dev->qmult)); in gether_connect()
1143 dev->zlp = link->is_zlp_ok; in gether_connect()
1144 dev->no_skb_reserve = gadget_avoids_skb_reserve(dev->gadget); in gether_connect()
1145 DBG(dev, "qlen %d\n", qlen(dev->gadget, dev->qmult)); in gether_connect()
1147 dev->header_len = link->header_len; in gether_connect()
1148 dev->unwrap = link->unwrap; in gether_connect()
1149 dev->wrap = link->wrap; in gether_connect()
1151 spin_lock(&dev->lock); in gether_connect()
1152 dev->port_usb = link; in gether_connect()
1153 if (netif_running(dev->net)) { in gether_connect()
1160 spin_unlock(&dev->lock); in gether_connect()
1162 netif_carrier_on(dev->net); in gether_connect()
1163 if (netif_running(dev->net)) in gether_connect()
1164 eth_start(dev, GFP_ATOMIC); in gether_connect()
1176 return dev->net; in gether_connect()
1194 struct eth_dev *dev = link->ioport; in gether_disconnect() local
1197 WARN_ON(!dev); in gether_disconnect()
1198 if (!dev) in gether_disconnect()
1201 DBG(dev, "%s\n", __func__); in gether_disconnect()
1203 netif_stop_queue(dev->net); in gether_disconnect()
1204 netif_carrier_off(dev->net); in gether_disconnect()
1211 spin_lock(&dev->req_lock); in gether_disconnect()
1212 while (!list_empty(&dev->tx_reqs)) { in gether_disconnect()
1213 req = list_first_entry(&dev->tx_reqs, struct usb_request, list); in gether_disconnect()
1216 spin_unlock(&dev->req_lock); in gether_disconnect()
1218 spin_lock(&dev->req_lock); in gether_disconnect()
1220 spin_unlock(&dev->req_lock); in gether_disconnect()
1224 spin_lock(&dev->req_lock); in gether_disconnect()
1225 while (!list_empty(&dev->rx_reqs)) { in gether_disconnect()
1226 req = list_first_entry(&dev->rx_reqs, struct usb_request, list); in gether_disconnect()
1229 spin_unlock(&dev->req_lock); in gether_disconnect()
1231 spin_lock(&dev->req_lock); in gether_disconnect()
1233 spin_unlock(&dev->req_lock); in gether_disconnect()
1237 dev->header_len = 0; in gether_disconnect()
1238 dev->unwrap = NULL; in gether_disconnect()
1239 dev->wrap = NULL; in gether_disconnect()
1241 spin_lock(&dev->lock); in gether_disconnect()
1242 dev->port_usb = NULL; in gether_disconnect()
1244 spin_unlock(&dev->lock); in gether_disconnect()