ipheth.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. /*
  2. * ipheth.c - Apple iPhone USB Ethernet driver
  3. *
  4. * Copyright (c) 2009 Diego Giagio <diego@giagio.com>
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of GIAGIO.COM nor the names of its contributors
  16. * may be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * Alternatively, provided that this notice is retained in full, this
  20. * software may be distributed under the terms of the GNU General
  21. * Public License ("GPL") version 2, in which case the provisions of the
  22. * GPL apply INSTEAD OF those given above.
  23. *
  24. * The provided data structures and external interfaces from this code
  25. * are not restricted to be used by modules with a GPL compatible license.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  30. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  31. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  32. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  33. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  34. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  35. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  36. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  37. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  38. * DAMAGE.
  39. *
  40. *
  41. * Attention: iPhone device must be paired, otherwise it won't respond to our
  42. * driver. For more info: http://giagio.com/wiki/moin.cgi/iPhoneEthernetDriver
  43. *
  44. */
  45. #include <linux/kernel.h>
  46. #include <linux/errno.h>
  47. #include <linux/slab.h>
  48. #include <linux/module.h>
  49. #include <linux/netdevice.h>
  50. #include <linux/etherdevice.h>
  51. #include <linux/ethtool.h>
  52. #include <linux/usb.h>
  53. #include <linux/workqueue.h>
  54. #define USB_VENDOR_APPLE 0x05ac
  55. #define USB_PRODUCT_IPHONE 0x1290
  56. #define USB_PRODUCT_IPHONE_3G 0x1292
  57. #define USB_PRODUCT_IPHONE_3GS 0x1294
  58. #define USB_PRODUCT_IPHONE_4 0x1297
  59. #define USB_PRODUCT_IPAD 0x129a
  60. #define USB_PRODUCT_IPAD_2 0x12a2
  61. #define USB_PRODUCT_IPAD_3 0x12a6
  62. #define USB_PRODUCT_IPAD_MINI 0x12ab
  63. #define USB_PRODUCT_IPHONE_4_VZW 0x129c
  64. #define USB_PRODUCT_IPHONE_4S 0x12a0
  65. #define USB_PRODUCT_IPHONE_5 0x12a8
  66. #define IPHETH_USBINTF_CLASS 255
  67. #define IPHETH_USBINTF_SUBCLASS 253
  68. #define IPHETH_USBINTF_PROTO 1
  69. #define IPHETH_BUF_SIZE 1516
  70. #define IPHETH_IP_ALIGN 2 /* padding at front of URB */
  71. #define IPHETH_TX_TIMEOUT (5 * HZ)
  72. #define IPHETH_INTFNUM 2
  73. #define IPHETH_ALT_INTFNUM 1
  74. #define IPHETH_CTRL_ENDP 0x00
  75. #define IPHETH_CTRL_BUF_SIZE 0x40
  76. #define IPHETH_CTRL_TIMEOUT (5 * HZ)
  77. #define IPHETH_CMD_GET_MACADDR 0x00
  78. #define IPHETH_CMD_CARRIER_CHECK 0x45
  79. #define IPHETH_CARRIER_CHECK_TIMEOUT round_jiffies_relative(1 * HZ)
  80. #define IPHETH_CARRIER_ON 0x04
  81. static struct usb_device_id ipheth_table[] = {
  82. { USB_DEVICE_AND_INTERFACE_INFO(
  83. USB_VENDOR_APPLE, USB_PRODUCT_IPHONE,
  84. IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
  85. IPHETH_USBINTF_PROTO) },
  86. { USB_DEVICE_AND_INTERFACE_INFO(
  87. USB_VENDOR_APPLE, USB_PRODUCT_IPHONE_3G,
  88. IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
  89. IPHETH_USBINTF_PROTO) },
  90. { USB_DEVICE_AND_INTERFACE_INFO(
  91. USB_VENDOR_APPLE, USB_PRODUCT_IPHONE_3GS,
  92. IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
  93. IPHETH_USBINTF_PROTO) },
  94. { USB_DEVICE_AND_INTERFACE_INFO(
  95. USB_VENDOR_APPLE, USB_PRODUCT_IPHONE_4,
  96. IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
  97. IPHETH_USBINTF_PROTO) },
  98. { USB_DEVICE_AND_INTERFACE_INFO(
  99. USB_VENDOR_APPLE, USB_PRODUCT_IPAD,
  100. IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
  101. IPHETH_USBINTF_PROTO) },
  102. { USB_DEVICE_AND_INTERFACE_INFO(
  103. USB_VENDOR_APPLE, USB_PRODUCT_IPAD_2,
  104. IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
  105. IPHETH_USBINTF_PROTO) },
  106. { USB_DEVICE_AND_INTERFACE_INFO(
  107. USB_VENDOR_APPLE, USB_PRODUCT_IPAD_3,
  108. IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
  109. IPHETH_USBINTF_PROTO) },
  110. { USB_DEVICE_AND_INTERFACE_INFO(
  111. USB_VENDOR_APPLE, USB_PRODUCT_IPAD_MINI,
  112. IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
  113. IPHETH_USBINTF_PROTO) },
  114. { USB_DEVICE_AND_INTERFACE_INFO(
  115. USB_VENDOR_APPLE, USB_PRODUCT_IPHONE_4_VZW,
  116. IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
  117. IPHETH_USBINTF_PROTO) },
  118. { USB_DEVICE_AND_INTERFACE_INFO(
  119. USB_VENDOR_APPLE, USB_PRODUCT_IPHONE_4S,
  120. IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
  121. IPHETH_USBINTF_PROTO) },
  122. { USB_DEVICE_AND_INTERFACE_INFO(
  123. USB_VENDOR_APPLE, USB_PRODUCT_IPHONE_5,
  124. IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
  125. IPHETH_USBINTF_PROTO) },
  126. { }
  127. };
  128. MODULE_DEVICE_TABLE(usb, ipheth_table);
  129. struct ipheth_device {
  130. struct usb_device *udev;
  131. struct usb_interface *intf;
  132. struct net_device *net;
  133. struct urb *tx_urb;
  134. struct urb *rx_urb;
  135. unsigned char *tx_buf;
  136. unsigned char *rx_buf;
  137. unsigned char *ctrl_buf;
  138. u8 bulk_in;
  139. u8 bulk_out;
  140. struct delayed_work carrier_work;
  141. };
  142. static int ipheth_rx_submit(struct ipheth_device *dev, gfp_t mem_flags);
  143. static int ipheth_alloc_urbs(struct ipheth_device *iphone)
  144. {
  145. struct urb *tx_urb = NULL;
  146. struct urb *rx_urb = NULL;
  147. u8 *tx_buf = NULL;
  148. u8 *rx_buf = NULL;
  149. tx_urb = usb_alloc_urb(0, GFP_KERNEL);
  150. if (tx_urb == NULL)
  151. goto error_nomem;
  152. rx_urb = usb_alloc_urb(0, GFP_KERNEL);
  153. if (rx_urb == NULL)
  154. goto free_tx_urb;
  155. tx_buf = usb_alloc_coherent(iphone->udev, IPHETH_BUF_SIZE,
  156. GFP_KERNEL, &tx_urb->transfer_dma);
  157. if (tx_buf == NULL)
  158. goto free_rx_urb;
  159. rx_buf = usb_alloc_coherent(iphone->udev, IPHETH_BUF_SIZE,
  160. GFP_KERNEL, &rx_urb->transfer_dma);
  161. if (rx_buf == NULL)
  162. goto free_tx_buf;
  163. iphone->tx_urb = tx_urb;
  164. iphone->rx_urb = rx_urb;
  165. iphone->tx_buf = tx_buf;
  166. iphone->rx_buf = rx_buf;
  167. return 0;
  168. free_tx_buf:
  169. usb_free_coherent(iphone->udev, IPHETH_BUF_SIZE, tx_buf,
  170. tx_urb->transfer_dma);
  171. free_rx_urb:
  172. usb_free_urb(rx_urb);
  173. free_tx_urb:
  174. usb_free_urb(tx_urb);
  175. error_nomem:
  176. return -ENOMEM;
  177. }
  178. static void ipheth_free_urbs(struct ipheth_device *iphone)
  179. {
  180. usb_free_coherent(iphone->udev, IPHETH_BUF_SIZE, iphone->rx_buf,
  181. iphone->rx_urb->transfer_dma);
  182. usb_free_coherent(iphone->udev, IPHETH_BUF_SIZE, iphone->tx_buf,
  183. iphone->tx_urb->transfer_dma);
  184. usb_free_urb(iphone->rx_urb);
  185. usb_free_urb(iphone->tx_urb);
  186. }
  187. static void ipheth_kill_urbs(struct ipheth_device *dev)
  188. {
  189. usb_kill_urb(dev->tx_urb);
  190. usb_kill_urb(dev->rx_urb);
  191. }
  192. static void ipheth_rcvbulk_callback(struct urb *urb)
  193. {
  194. struct ipheth_device *dev;
  195. struct sk_buff *skb;
  196. int status;
  197. char *buf;
  198. int len;
  199. dev = urb->context;
  200. if (dev == NULL)
  201. return;
  202. status = urb->status;
  203. switch (status) {
  204. case -ENOENT:
  205. case -ECONNRESET:
  206. case -ESHUTDOWN:
  207. case -EPROTO:
  208. return;
  209. case 0:
  210. break;
  211. default:
  212. dev_err(&dev->intf->dev, "%s: urb status: %d\n",
  213. __func__, status);
  214. return;
  215. }
  216. if (urb->actual_length <= IPHETH_IP_ALIGN) {
  217. dev->net->stats.rx_length_errors++;
  218. return;
  219. }
  220. len = urb->actual_length - IPHETH_IP_ALIGN;
  221. buf = urb->transfer_buffer + IPHETH_IP_ALIGN;
  222. skb = dev_alloc_skb(len);
  223. if (!skb) {
  224. dev_err(&dev->intf->dev, "%s: dev_alloc_skb: -ENOMEM\n",
  225. __func__);
  226. dev->net->stats.rx_dropped++;
  227. return;
  228. }
  229. memcpy(skb_put(skb, len), buf, len);
  230. skb->dev = dev->net;
  231. skb->protocol = eth_type_trans(skb, dev->net);
  232. dev->net->stats.rx_packets++;
  233. dev->net->stats.rx_bytes += len;
  234. netif_rx(skb);
  235. ipheth_rx_submit(dev, GFP_ATOMIC);
  236. }
  237. static void ipheth_sndbulk_callback(struct urb *urb)
  238. {
  239. struct ipheth_device *dev;
  240. int status = urb->status;
  241. dev = urb->context;
  242. if (dev == NULL)
  243. return;
  244. if (status != 0 &&
  245. status != -ENOENT &&
  246. status != -ECONNRESET &&
  247. status != -ESHUTDOWN)
  248. dev_err(&dev->intf->dev, "%s: urb status: %d\n",
  249. __func__, status);
  250. netif_wake_queue(dev->net);
  251. }
  252. static int ipheth_carrier_set(struct ipheth_device *dev)
  253. {
  254. struct usb_device *udev = dev->udev;
  255. int retval;
  256. retval = usb_control_msg(udev,
  257. usb_rcvctrlpipe(udev, IPHETH_CTRL_ENDP),
  258. IPHETH_CMD_CARRIER_CHECK, /* request */
  259. 0xc0, /* request type */
  260. 0x00, /* value */
  261. 0x02, /* index */
  262. dev->ctrl_buf, IPHETH_CTRL_BUF_SIZE,
  263. IPHETH_CTRL_TIMEOUT);
  264. if (retval < 0) {
  265. dev_err(&dev->intf->dev, "%s: usb_control_msg: %d\n",
  266. __func__, retval);
  267. return retval;
  268. }
  269. if (dev->ctrl_buf[0] == IPHETH_CARRIER_ON)
  270. netif_carrier_on(dev->net);
  271. else
  272. netif_carrier_off(dev->net);
  273. return 0;
  274. }
  275. static void ipheth_carrier_check_work(struct work_struct *work)
  276. {
  277. struct ipheth_device *dev = container_of(work, struct ipheth_device,
  278. carrier_work.work);
  279. ipheth_carrier_set(dev);
  280. schedule_delayed_work(&dev->carrier_work, IPHETH_CARRIER_CHECK_TIMEOUT);
  281. }
  282. static int ipheth_get_macaddr(struct ipheth_device *dev)
  283. {
  284. struct usb_device *udev = dev->udev;
  285. struct net_device *net = dev->net;
  286. int retval;
  287. retval = usb_control_msg(udev,
  288. usb_rcvctrlpipe(udev, IPHETH_CTRL_ENDP),
  289. IPHETH_CMD_GET_MACADDR, /* request */
  290. 0xc0, /* request type */
  291. 0x00, /* value */
  292. 0x02, /* index */
  293. dev->ctrl_buf,
  294. IPHETH_CTRL_BUF_SIZE,
  295. IPHETH_CTRL_TIMEOUT);
  296. if (retval < 0) {
  297. dev_err(&dev->intf->dev, "%s: usb_control_msg: %d\n",
  298. __func__, retval);
  299. } else if (retval < ETH_ALEN) {
  300. dev_err(&dev->intf->dev,
  301. "%s: usb_control_msg: short packet: %d bytes\n",
  302. __func__, retval);
  303. retval = -EINVAL;
  304. } else {
  305. memcpy(net->dev_addr, dev->ctrl_buf, ETH_ALEN);
  306. retval = 0;
  307. }
  308. return retval;
  309. }
  310. static int ipheth_rx_submit(struct ipheth_device *dev, gfp_t mem_flags)
  311. {
  312. struct usb_device *udev = dev->udev;
  313. int retval;
  314. usb_fill_bulk_urb(dev->rx_urb, udev,
  315. usb_rcvbulkpipe(udev, dev->bulk_in),
  316. dev->rx_buf, IPHETH_BUF_SIZE,
  317. ipheth_rcvbulk_callback,
  318. dev);
  319. dev->rx_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  320. retval = usb_submit_urb(dev->rx_urb, mem_flags);
  321. if (retval)
  322. dev_err(&dev->intf->dev, "%s: usb_submit_urb: %d\n",
  323. __func__, retval);
  324. return retval;
  325. }
  326. static int ipheth_open(struct net_device *net)
  327. {
  328. struct ipheth_device *dev = netdev_priv(net);
  329. struct usb_device *udev = dev->udev;
  330. int retval = 0;
  331. usb_set_interface(udev, IPHETH_INTFNUM, IPHETH_ALT_INTFNUM);
  332. retval = ipheth_carrier_set(dev);
  333. if (retval)
  334. return retval;
  335. retval = ipheth_rx_submit(dev, GFP_KERNEL);
  336. if (retval)
  337. return retval;
  338. schedule_delayed_work(&dev->carrier_work, IPHETH_CARRIER_CHECK_TIMEOUT);
  339. netif_start_queue(net);
  340. return retval;
  341. }
  342. static int ipheth_close(struct net_device *net)
  343. {
  344. struct ipheth_device *dev = netdev_priv(net);
  345. cancel_delayed_work_sync(&dev->carrier_work);
  346. netif_stop_queue(net);
  347. return 0;
  348. }
  349. static int ipheth_tx(struct sk_buff *skb, struct net_device *net)
  350. {
  351. struct ipheth_device *dev = netdev_priv(net);
  352. struct usb_device *udev = dev->udev;
  353. int retval;
  354. /* Paranoid */
  355. if (skb->len > IPHETH_BUF_SIZE) {
  356. WARN(1, "%s: skb too large: %d bytes\n", __func__, skb->len);
  357. dev->net->stats.tx_dropped++;
  358. dev_kfree_skb_any(skb);
  359. return NETDEV_TX_OK;
  360. }
  361. memcpy(dev->tx_buf, skb->data, skb->len);
  362. if (skb->len < IPHETH_BUF_SIZE)
  363. memset(dev->tx_buf + skb->len, 0, IPHETH_BUF_SIZE - skb->len);
  364. usb_fill_bulk_urb(dev->tx_urb, udev,
  365. usb_sndbulkpipe(udev, dev->bulk_out),
  366. dev->tx_buf, IPHETH_BUF_SIZE,
  367. ipheth_sndbulk_callback,
  368. dev);
  369. dev->tx_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  370. retval = usb_submit_urb(dev->tx_urb, GFP_ATOMIC);
  371. if (retval) {
  372. dev_err(&dev->intf->dev, "%s: usb_submit_urb: %d\n",
  373. __func__, retval);
  374. dev->net->stats.tx_errors++;
  375. dev_kfree_skb_any(skb);
  376. } else {
  377. dev->net->stats.tx_packets++;
  378. dev->net->stats.tx_bytes += skb->len;
  379. dev_consume_skb_any(skb);
  380. netif_stop_queue(net);
  381. }
  382. return NETDEV_TX_OK;
  383. }
  384. static void ipheth_tx_timeout(struct net_device *net)
  385. {
  386. struct ipheth_device *dev = netdev_priv(net);
  387. dev_err(&dev->intf->dev, "%s: TX timeout\n", __func__);
  388. dev->net->stats.tx_errors++;
  389. usb_unlink_urb(dev->tx_urb);
  390. }
  391. static u32 ipheth_ethtool_op_get_link(struct net_device *net)
  392. {
  393. struct ipheth_device *dev = netdev_priv(net);
  394. return netif_carrier_ok(dev->net);
  395. }
  396. static const struct ethtool_ops ops = {
  397. .get_link = ipheth_ethtool_op_get_link
  398. };
  399. static const struct net_device_ops ipheth_netdev_ops = {
  400. .ndo_open = ipheth_open,
  401. .ndo_stop = ipheth_close,
  402. .ndo_start_xmit = ipheth_tx,
  403. .ndo_tx_timeout = ipheth_tx_timeout,
  404. };
  405. static int ipheth_probe(struct usb_interface *intf,
  406. const struct usb_device_id *id)
  407. {
  408. struct usb_device *udev = interface_to_usbdev(intf);
  409. struct usb_host_interface *hintf;
  410. struct usb_endpoint_descriptor *endp;
  411. struct ipheth_device *dev;
  412. struct net_device *netdev;
  413. int i;
  414. int retval;
  415. netdev = alloc_etherdev(sizeof(struct ipheth_device));
  416. if (!netdev)
  417. return -ENOMEM;
  418. netdev->netdev_ops = &ipheth_netdev_ops;
  419. netdev->watchdog_timeo = IPHETH_TX_TIMEOUT;
  420. strcpy(netdev->name, "eth%d");
  421. dev = netdev_priv(netdev);
  422. dev->udev = udev;
  423. dev->net = netdev;
  424. dev->intf = intf;
  425. /* Set up endpoints */
  426. hintf = usb_altnum_to_altsetting(intf, IPHETH_ALT_INTFNUM);
  427. if (hintf == NULL) {
  428. retval = -ENODEV;
  429. dev_err(&intf->dev, "Unable to find alternate settings interface\n");
  430. goto err_endpoints;
  431. }
  432. for (i = 0; i < hintf->desc.bNumEndpoints; i++) {
  433. endp = &hintf->endpoint[i].desc;
  434. if (usb_endpoint_is_bulk_in(endp))
  435. dev->bulk_in = endp->bEndpointAddress;
  436. else if (usb_endpoint_is_bulk_out(endp))
  437. dev->bulk_out = endp->bEndpointAddress;
  438. }
  439. if (!(dev->bulk_in && dev->bulk_out)) {
  440. retval = -ENODEV;
  441. dev_err(&intf->dev, "Unable to find endpoints\n");
  442. goto err_endpoints;
  443. }
  444. dev->ctrl_buf = kmalloc(IPHETH_CTRL_BUF_SIZE, GFP_KERNEL);
  445. if (dev->ctrl_buf == NULL) {
  446. retval = -ENOMEM;
  447. goto err_alloc_ctrl_buf;
  448. }
  449. retval = ipheth_get_macaddr(dev);
  450. if (retval)
  451. goto err_get_macaddr;
  452. INIT_DELAYED_WORK(&dev->carrier_work, ipheth_carrier_check_work);
  453. retval = ipheth_alloc_urbs(dev);
  454. if (retval) {
  455. dev_err(&intf->dev, "error allocating urbs: %d\n", retval);
  456. goto err_alloc_urbs;
  457. }
  458. usb_set_intfdata(intf, dev);
  459. SET_NETDEV_DEV(netdev, &intf->dev);
  460. netdev->ethtool_ops = &ops;
  461. retval = register_netdev(netdev);
  462. if (retval) {
  463. dev_err(&intf->dev, "error registering netdev: %d\n", retval);
  464. retval = -EIO;
  465. goto err_register_netdev;
  466. }
  467. dev_info(&intf->dev, "Apple iPhone USB Ethernet device attached\n");
  468. return 0;
  469. err_register_netdev:
  470. ipheth_free_urbs(dev);
  471. err_alloc_urbs:
  472. err_get_macaddr:
  473. err_alloc_ctrl_buf:
  474. kfree(dev->ctrl_buf);
  475. err_endpoints:
  476. free_netdev(netdev);
  477. return retval;
  478. }
  479. static void ipheth_disconnect(struct usb_interface *intf)
  480. {
  481. struct ipheth_device *dev;
  482. dev = usb_get_intfdata(intf);
  483. if (dev != NULL) {
  484. unregister_netdev(dev->net);
  485. ipheth_kill_urbs(dev);
  486. ipheth_free_urbs(dev);
  487. kfree(dev->ctrl_buf);
  488. free_netdev(dev->net);
  489. }
  490. usb_set_intfdata(intf, NULL);
  491. dev_info(&intf->dev, "Apple iPhone USB Ethernet now disconnected\n");
  492. }
  493. static struct usb_driver ipheth_driver = {
  494. .name = "ipheth",
  495. .probe = ipheth_probe,
  496. .disconnect = ipheth_disconnect,
  497. .id_table = ipheth_table,
  498. .disable_hub_initiated_lpm = 1,
  499. };
  500. module_usb_driver(ipheth_driver);
  501. MODULE_AUTHOR("Diego Giagio <diego@giagio.com>");
  502. MODULE_DESCRIPTION("Apple iPhone USB Ethernet driver");
  503. MODULE_LICENSE("Dual BSD/GPL");