23 #include <linux/kernel.h>
25 #include <linux/module.h>
29 #include <linux/netdevice.h>
30 #include <linux/if_arp.h>
31 #include <linux/if_phonet.h>
32 #include <linux/phonet.h>
34 #define PN_MEDIA_USB 0x1B
36 static const unsigned rxq_size = 17;
42 struct usb_device *
usb;
55 static void tx_complete(
struct urb *
req);
56 static void rx_complete(
struct urb *
req);
76 req->transfer_flags = URB_ZERO_PACKET;
86 netif_stop_queue(dev);
87 spin_unlock_irqrestore(&pnd->
tx_lock, flags);
92 dev->
stats.tx_dropped++;
96 static void tx_complete(
struct urb *req)
98 struct sk_buff *skb = req->context;
100 struct usbpn_dev *pnd = netdev_priv(dev);
111 dev->
stats.tx_aborted_errors++;
113 dev->
stats.tx_errors++;
114 dev_dbg(&dev->
dev,
"TX error (%d)\n", status);
116 dev->
stats.tx_packets++;
120 netif_wake_queue(dev);
139 req->transfer_flags = 0;
142 dev_dbg(&dev->
dev,
"RX submit error (%d)\n", err);
148 static void rx_complete(
struct urb *req)
151 struct usbpn_dev *pnd = netdev_priv(dev);
155 int status = req->status;
162 skb = pnd->
rx_skb = netdev_alloc_skb(dev, 12);
167 page, 1, req->actual_length,
173 page, 0, req->actual_length,
181 spin_unlock_irqrestore(&pnd->
rx_lock, flags);
184 skb_reset_mac_header(skb);
187 dev->
stats.rx_packets++;
201 dev->
stats.rx_over_errors++;
206 dev->
stats.rx_crc_errors++;
210 dev->
stats.rx_errors++;
218 static int usbpn_close(
struct net_device *dev);
222 struct usbpn_dev *pnd = netdev_priv(dev);
225 unsigned num = pnd->
data_intf->cur_altsetting->desc.bInterfaceNumber;
231 for (i = 0; i < rxq_size; i++) {
242 netif_wake_queue(dev);
246 static int usbpn_close(
struct net_device *dev)
248 struct usbpn_dev *pnd = netdev_priv(dev);
250 unsigned num = pnd->
data_intf->cur_altsetting->desc.bInterfaceNumber;
252 netif_stop_queue(dev);
254 for (i = 0; i < rxq_size; i++) {
273 req->ifr_phonet_autoconf.device =
PN_DEV_PC;
279 static int usbpn_set_mtu(
struct net_device *dev,
int new_mtu)
289 .ndo_open = usbpn_open,
290 .ndo_stop = usbpn_close,
291 .ndo_start_xmit = usbpn_xmit,
292 .ndo_do_ioctl = usbpn_ioctl,
293 .ndo_change_mtu = usbpn_set_mtu,
296 static void usbpn_setup(
struct net_device *dev)
322 .bInterfaceSubClass = 0xFE,
329 static struct usb_driver usbpn_driver;
333 static const char ifname[] =
"usbpn%d";
335 const struct usb_host_interface *data_desc;
337 struct usb_device *usbdev = interface_to_usbdev(intf);
344 data = intf->altsetting->extra;
345 len = intf->altsetting->extralen;
356 if (union_header || dlen < 5)
370 if (!union_header || !phonet)
374 if (data_intf ==
NULL)
377 if (data_intf->num_altsetting != 2)
379 if (data_intf->altsetting[0].desc.bNumEndpoints == 0 &&
380 data_intf->altsetting[1].desc.bNumEndpoints == 2)
381 data_desc = data_intf->altsetting + 1;
383 if (data_intf->altsetting[0].desc.bNumEndpoints == 2 &&
384 data_intf->altsetting[1].desc.bNumEndpoints == 0)
385 data_desc = data_intf->altsetting;
390 ifname, usbpn_setup);
394 pnd = netdev_priv(dev);
404 if (usb_pipein(data_desc->endpoint[0].desc.bEndpointAddress)) {
405 pnd->
rx_pipe = usb_rcvbulkpipe(usbdev,
406 data_desc->endpoint[0].desc.bEndpointAddress);
407 pnd->
tx_pipe = usb_sndbulkpipe(usbdev,
408 data_desc->endpoint[1].desc.bEndpointAddress);
410 pnd->
rx_pipe = usb_rcvbulkpipe(usbdev,
411 data_desc->endpoint[1].desc.bEndpointAddress);
412 pnd->
tx_pipe = usb_sndbulkpipe(usbdev,
413 data_desc->endpoint[0].desc.bEndpointAddress);
424 usb_set_intfdata(intf, pnd);
432 dev_dbg(&dev->
dev,
"USB CDC Phonet device found\n");
436 usb_set_intfdata(intf,
NULL);
443 struct usbpn_dev *pnd = usb_get_intfdata(intf);
454 static struct usb_driver usbpn_driver = {
455 .name =
"cdc_phonet",
457 .disconnect = usbpn_disconnect,
458 .id_table = usbpn_ids,
459 .disable_hub_initiated_lpm = 1,