asix.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660
  1. /*
  2. * ASIX AX8817X based USB 2.0 Ethernet Devices
  3. * Copyright (C) 2003-2006 David Hollis <dhollis@davehollis.com>
  4. * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net>
  5. * Copyright (C) 2006 James Painter <jamie.painter@iname.com>
  6. * Copyright (c) 2002-2003 TiVo Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. // #define DEBUG // error path messages, extra info
  23. // #define VERBOSE // more; success messages
  24. #include <linux/module.h>
  25. #include <linux/kmod.h>
  26. #include <linux/init.h>
  27. #include <linux/netdevice.h>
  28. #include <linux/etherdevice.h>
  29. #include <linux/ethtool.h>
  30. #include <linux/workqueue.h>
  31. #include <linux/mii.h>
  32. #include <linux/usb.h>
  33. #include <linux/crc32.h>
  34. #include <linux/usb/usbnet.h>
  35. #include <linux/slab.h>
  36. #include <linux/if_vlan.h>
  37. #define DRIVER_VERSION "22-Dec-2011"
  38. #define DRIVER_NAME "asix"
  39. /* ASIX AX8817X based USB 2.0 Ethernet Devices */
  40. #define AX_CMD_SET_SW_MII 0x06
  41. #define AX_CMD_READ_MII_REG 0x07
  42. #define AX_CMD_WRITE_MII_REG 0x08
  43. #define AX_CMD_SET_HW_MII 0x0a
  44. #define AX_CMD_READ_EEPROM 0x0b
  45. #define AX_CMD_WRITE_EEPROM 0x0c
  46. #define AX_CMD_WRITE_ENABLE 0x0d
  47. #define AX_CMD_WRITE_DISABLE 0x0e
  48. #define AX_CMD_READ_RX_CTL 0x0f
  49. #define AX_CMD_WRITE_RX_CTL 0x10
  50. #define AX_CMD_READ_IPG012 0x11
  51. #define AX_CMD_WRITE_IPG0 0x12
  52. #define AX_CMD_WRITE_IPG1 0x13
  53. #define AX_CMD_READ_NODE_ID 0x13
  54. #define AX_CMD_WRITE_NODE_ID 0x14
  55. #define AX_CMD_WRITE_IPG2 0x14
  56. #define AX_CMD_WRITE_MULTI_FILTER 0x16
  57. #define AX88172_CMD_READ_NODE_ID 0x17
  58. #define AX_CMD_READ_PHY_ID 0x19
  59. #define AX_CMD_READ_MEDIUM_STATUS 0x1a
  60. #define AX_CMD_WRITE_MEDIUM_MODE 0x1b
  61. #define AX_CMD_READ_MONITOR_MODE 0x1c
  62. #define AX_CMD_WRITE_MONITOR_MODE 0x1d
  63. #define AX_CMD_READ_GPIOS 0x1e
  64. #define AX_CMD_WRITE_GPIOS 0x1f
  65. #define AX_CMD_SW_RESET 0x20
  66. #define AX_CMD_SW_PHY_STATUS 0x21
  67. #define AX_CMD_SW_PHY_SELECT 0x22
  68. #define AX_MONITOR_MODE 0x01
  69. #define AX_MONITOR_LINK 0x02
  70. #define AX_MONITOR_MAGIC 0x04
  71. #define AX_MONITOR_HSFS 0x10
  72. /* AX88172 Medium Status Register values */
  73. #define AX88172_MEDIUM_FD 0x02
  74. #define AX88172_MEDIUM_TX 0x04
  75. #define AX88172_MEDIUM_FC 0x10
  76. #define AX88172_MEDIUM_DEFAULT \
  77. ( AX88172_MEDIUM_FD | AX88172_MEDIUM_TX | AX88172_MEDIUM_FC )
  78. #define AX_MCAST_FILTER_SIZE 8
  79. #define AX_MAX_MCAST 64
  80. #define AX_SWRESET_CLEAR 0x00
  81. #define AX_SWRESET_RR 0x01
  82. #define AX_SWRESET_RT 0x02
  83. #define AX_SWRESET_PRTE 0x04
  84. #define AX_SWRESET_PRL 0x08
  85. #define AX_SWRESET_BZ 0x10
  86. #define AX_SWRESET_IPRL 0x20
  87. #define AX_SWRESET_IPPD 0x40
  88. #define AX88772_IPG0_DEFAULT 0x15
  89. #define AX88772_IPG1_DEFAULT 0x0c
  90. #define AX88772_IPG2_DEFAULT 0x12
  91. /* AX88772 & AX88178 Medium Mode Register */
  92. #define AX_MEDIUM_PF 0x0080
  93. #define AX_MEDIUM_JFE 0x0040
  94. #define AX_MEDIUM_TFC 0x0020
  95. #define AX_MEDIUM_RFC 0x0010
  96. #define AX_MEDIUM_ENCK 0x0008
  97. #define AX_MEDIUM_AC 0x0004
  98. #define AX_MEDIUM_FD 0x0002
  99. #define AX_MEDIUM_GM 0x0001
  100. #define AX_MEDIUM_SM 0x1000
  101. #define AX_MEDIUM_SBP 0x0800
  102. #define AX_MEDIUM_PS 0x0200
  103. #define AX_MEDIUM_RE 0x0100
  104. #define AX88178_MEDIUM_DEFAULT \
  105. (AX_MEDIUM_PS | AX_MEDIUM_FD | AX_MEDIUM_AC | \
  106. AX_MEDIUM_RFC | AX_MEDIUM_TFC | AX_MEDIUM_JFE | \
  107. AX_MEDIUM_RE)
  108. #define AX88772_MEDIUM_DEFAULT \
  109. (AX_MEDIUM_FD | AX_MEDIUM_RFC | \
  110. AX_MEDIUM_TFC | AX_MEDIUM_PS | \
  111. AX_MEDIUM_AC | AX_MEDIUM_RE)
  112. /* AX88772 & AX88178 RX_CTL values */
  113. #define AX_RX_CTL_SO 0x0080
  114. #define AX_RX_CTL_AP 0x0020
  115. #define AX_RX_CTL_AM 0x0010
  116. #define AX_RX_CTL_AB 0x0008
  117. #define AX_RX_CTL_SEP 0x0004
  118. #define AX_RX_CTL_AMALL 0x0002
  119. #define AX_RX_CTL_PRO 0x0001
  120. #define AX_RX_CTL_MFB_2048 0x0000
  121. #define AX_RX_CTL_MFB_4096 0x0100
  122. #define AX_RX_CTL_MFB_8192 0x0200
  123. #define AX_RX_CTL_MFB_16384 0x0300
  124. #define AX_DEFAULT_RX_CTL (AX_RX_CTL_SO | AX_RX_CTL_AB)
  125. /* GPIO 0 .. 2 toggles */
  126. #define AX_GPIO_GPO0EN 0x01 /* GPIO0 Output enable */
  127. #define AX_GPIO_GPO_0 0x02 /* GPIO0 Output value */
  128. #define AX_GPIO_GPO1EN 0x04 /* GPIO1 Output enable */
  129. #define AX_GPIO_GPO_1 0x08 /* GPIO1 Output value */
  130. #define AX_GPIO_GPO2EN 0x10 /* GPIO2 Output enable */
  131. #define AX_GPIO_GPO_2 0x20 /* GPIO2 Output value */
  132. #define AX_GPIO_RESERVED 0x40 /* Reserved */
  133. #define AX_GPIO_RSE 0x80 /* Reload serial EEPROM */
  134. #define AX_EEPROM_MAGIC 0xdeadbeef
  135. #define AX88172_EEPROM_LEN 0x40
  136. #define AX88772_EEPROM_LEN 0xff
  137. #define PHY_MODE_MARVELL 0x0000
  138. #define MII_MARVELL_LED_CTRL 0x0018
  139. #define MII_MARVELL_STATUS 0x001b
  140. #define MII_MARVELL_CTRL 0x0014
  141. #define MARVELL_LED_MANUAL 0x0019
  142. #define MARVELL_STATUS_HWCFG 0x0004
  143. #define MARVELL_CTRL_TXDELAY 0x0002
  144. #define MARVELL_CTRL_RXDELAY 0x0080
  145. #define PHY_MODE_RTL8211CL 0x000C
  146. /* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */
  147. struct asix_data {
  148. u8 multi_filter[AX_MCAST_FILTER_SIZE];
  149. u8 mac_addr[ETH_ALEN];
  150. u8 phymode;
  151. u8 ledmode;
  152. u8 eeprom_len;
  153. };
  154. struct ax88172_int_data {
  155. __le16 res1;
  156. u8 link;
  157. __le16 res2;
  158. u8 status;
  159. __le16 res3;
  160. } __packed;
  161. static int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
  162. u16 size, void *data)
  163. {
  164. void *buf;
  165. int err = -ENOMEM;
  166. netdev_dbg(dev->net, "asix_read_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d\n",
  167. cmd, value, index, size);
  168. buf = kmalloc(size, GFP_KERNEL);
  169. if (!buf)
  170. goto out;
  171. err = usb_control_msg(
  172. dev->udev,
  173. usb_rcvctrlpipe(dev->udev, 0),
  174. cmd,
  175. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  176. value,
  177. index,
  178. buf,
  179. size,
  180. USB_CTRL_GET_TIMEOUT);
  181. if (err == size)
  182. memcpy(data, buf, size);
  183. else if (err >= 0)
  184. err = -EINVAL;
  185. kfree(buf);
  186. out:
  187. return err;
  188. }
  189. static int asix_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
  190. u16 size, void *data)
  191. {
  192. void *buf = NULL;
  193. int err = -ENOMEM;
  194. netdev_dbg(dev->net, "asix_write_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d\n",
  195. cmd, value, index, size);
  196. if (data) {
  197. buf = kmemdup(data, size, GFP_KERNEL);
  198. if (!buf)
  199. goto out;
  200. }
  201. err = usb_control_msg(
  202. dev->udev,
  203. usb_sndctrlpipe(dev->udev, 0),
  204. cmd,
  205. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  206. value,
  207. index,
  208. buf,
  209. size,
  210. USB_CTRL_SET_TIMEOUT);
  211. kfree(buf);
  212. out:
  213. return err;
  214. }
  215. static void asix_async_cmd_callback(struct urb *urb)
  216. {
  217. struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context;
  218. int status = urb->status;
  219. if (status < 0)
  220. printk(KERN_DEBUG "asix_async_cmd_callback() failed with %d",
  221. status);
  222. kfree(req);
  223. usb_free_urb(urb);
  224. }
  225. static void
  226. asix_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
  227. u16 size, void *data)
  228. {
  229. struct usb_ctrlrequest *req;
  230. int status;
  231. struct urb *urb;
  232. netdev_dbg(dev->net, "asix_write_cmd_async() cmd=0x%02x value=0x%04x index=0x%04x size=%d\n",
  233. cmd, value, index, size);
  234. urb = usb_alloc_urb(0, GFP_ATOMIC);
  235. if (!urb) {
  236. netdev_err(dev->net, "Error allocating URB in write_cmd_async!\n");
  237. return;
  238. }
  239. req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC);
  240. if (!req) {
  241. netdev_err(dev->net, "Failed to allocate memory for control request\n");
  242. usb_free_urb(urb);
  243. return;
  244. }
  245. req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
  246. req->bRequest = cmd;
  247. req->wValue = cpu_to_le16(value);
  248. req->wIndex = cpu_to_le16(index);
  249. req->wLength = cpu_to_le16(size);
  250. usb_fill_control_urb(urb, dev->udev,
  251. usb_sndctrlpipe(dev->udev, 0),
  252. (void *)req, data, size,
  253. asix_async_cmd_callback, req);
  254. status = usb_submit_urb(urb, GFP_ATOMIC);
  255. if (status < 0) {
  256. netdev_err(dev->net, "Error submitting the control message: status=%d\n",
  257. status);
  258. kfree(req);
  259. usb_free_urb(urb);
  260. }
  261. }
  262. static int asix_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
  263. {
  264. int offset = 0;
  265. while (offset + sizeof(u32) < skb->len) {
  266. struct sk_buff *ax_skb;
  267. u16 size;
  268. u32 header = get_unaligned_le32(skb->data + offset);
  269. offset += sizeof(u32);
  270. /* get the packet length */
  271. size = (u16) (header & 0x7ff);
  272. if (size != ((~header >> 16) & 0x07ff)) {
  273. netdev_err(dev->net, "asix_rx_fixup() Bad Header Length\n");
  274. return 0;
  275. }
  276. if ((size > dev->net->mtu + ETH_HLEN + VLAN_HLEN) ||
  277. (size + offset > skb->len)) {
  278. netdev_err(dev->net, "asix_rx_fixup() Bad RX Length %d\n",
  279. size);
  280. return 0;
  281. }
  282. ax_skb = netdev_alloc_skb_ip_align(dev->net, size);
  283. if (!ax_skb)
  284. return 0;
  285. skb_put(ax_skb, size);
  286. memcpy(ax_skb->data, skb->data + offset, size);
  287. usbnet_skb_return(dev, ax_skb);
  288. offset += (size + 1) & 0xfffe;
  289. }
  290. if (skb->len != offset) {
  291. netdev_err(dev->net, "asix_rx_fixup() Bad SKB Length %d\n",
  292. skb->len);
  293. return 0;
  294. }
  295. return 1;
  296. }
  297. static struct sk_buff *asix_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
  298. gfp_t flags)
  299. {
  300. int padlen;
  301. int headroom = skb_headroom(skb);
  302. int tailroom = skb_tailroom(skb);
  303. u32 packet_len;
  304. u32 padbytes = 0xffff0000;
  305. padlen = ((skb->len + 4) & (dev->maxpacket - 1)) ? 0 : 4;
  306. if ((!skb_cloned(skb)) &&
  307. ((headroom + tailroom) >= (4 + padlen))) {
  308. if ((headroom < 4) || (tailroom < padlen)) {
  309. skb->data = memmove(skb->head + 4, skb->data, skb->len);
  310. skb_set_tail_pointer(skb, skb->len);
  311. }
  312. } else {
  313. struct sk_buff *skb2;
  314. skb2 = skb_copy_expand(skb, 4, padlen, flags);
  315. dev_kfree_skb_any(skb);
  316. skb = skb2;
  317. if (!skb)
  318. return NULL;
  319. }
  320. skb_push(skb, 4);
  321. packet_len = (((skb->len - 4) ^ 0x0000ffff) << 16) + (skb->len - 4);
  322. cpu_to_le32s(&packet_len);
  323. skb_copy_to_linear_data(skb, &packet_len, sizeof(packet_len));
  324. if (padlen) {
  325. cpu_to_le32s(&padbytes);
  326. memcpy(skb_tail_pointer(skb), &padbytes, sizeof(padbytes));
  327. skb_put(skb, sizeof(padbytes));
  328. }
  329. return skb;
  330. }
  331. static void asix_status(struct usbnet *dev, struct urb *urb)
  332. {
  333. struct ax88172_int_data *event;
  334. int link;
  335. if (urb->actual_length < 8)
  336. return;
  337. event = urb->transfer_buffer;
  338. link = event->link & 0x01;
  339. if (netif_carrier_ok(dev->net) != link) {
  340. if (link) {
  341. netif_carrier_on(dev->net);
  342. usbnet_defer_kevent (dev, EVENT_LINK_RESET );
  343. } else
  344. netif_carrier_off(dev->net);
  345. netdev_dbg(dev->net, "Link Status is: %d\n", link);
  346. }
  347. }
  348. static inline int asix_set_sw_mii(struct usbnet *dev)
  349. {
  350. int ret;
  351. ret = asix_write_cmd(dev, AX_CMD_SET_SW_MII, 0x0000, 0, 0, NULL);
  352. if (ret < 0)
  353. netdev_err(dev->net, "Failed to enable software MII access\n");
  354. return ret;
  355. }
  356. static inline int asix_set_hw_mii(struct usbnet *dev)
  357. {
  358. int ret;
  359. ret = asix_write_cmd(dev, AX_CMD_SET_HW_MII, 0x0000, 0, 0, NULL);
  360. if (ret < 0)
  361. netdev_err(dev->net, "Failed to enable hardware MII access\n");
  362. return ret;
  363. }
  364. static inline int asix_get_phy_addr(struct usbnet *dev)
  365. {
  366. u8 buf[2];
  367. int ret = asix_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf);
  368. netdev_dbg(dev->net, "asix_get_phy_addr()\n");
  369. if (ret < 0) {
  370. netdev_err(dev->net, "Error reading PHYID register: %02x\n", ret);
  371. goto out;
  372. }
  373. netdev_dbg(dev->net, "asix_get_phy_addr() returning 0x%04x\n",
  374. *((__le16 *)buf));
  375. ret = buf[1];
  376. out:
  377. return ret;
  378. }
  379. static int asix_sw_reset(struct usbnet *dev, u8 flags)
  380. {
  381. int ret;
  382. ret = asix_write_cmd(dev, AX_CMD_SW_RESET, flags, 0, 0, NULL);
  383. if (ret < 0)
  384. netdev_err(dev->net, "Failed to send software reset: %02x\n", ret);
  385. return ret;
  386. }
  387. static u16 asix_read_rx_ctl(struct usbnet *dev)
  388. {
  389. __le16 v;
  390. int ret = asix_read_cmd(dev, AX_CMD_READ_RX_CTL, 0, 0, 2, &v);
  391. if (ret < 0) {
  392. netdev_err(dev->net, "Error reading RX_CTL register: %02x\n", ret);
  393. goto out;
  394. }
  395. ret = le16_to_cpu(v);
  396. out:
  397. return ret;
  398. }
  399. static int asix_write_rx_ctl(struct usbnet *dev, u16 mode)
  400. {
  401. int ret;
  402. netdev_dbg(dev->net, "asix_write_rx_ctl() - mode = 0x%04x\n", mode);
  403. ret = asix_write_cmd(dev, AX_CMD_WRITE_RX_CTL, mode, 0, 0, NULL);
  404. if (ret < 0)
  405. netdev_err(dev->net, "Failed to write RX_CTL mode to 0x%04x: %02x\n",
  406. mode, ret);
  407. return ret;
  408. }
  409. static u16 asix_read_medium_status(struct usbnet *dev)
  410. {
  411. __le16 v;
  412. int ret = asix_read_cmd(dev, AX_CMD_READ_MEDIUM_STATUS, 0, 0, 2, &v);
  413. if (ret < 0) {
  414. netdev_err(dev->net, "Error reading Medium Status register: %02x\n",
  415. ret);
  416. return ret; /* TODO: callers not checking for error ret */
  417. }
  418. return le16_to_cpu(v);
  419. }
  420. static int asix_write_medium_mode(struct usbnet *dev, u16 mode)
  421. {
  422. int ret;
  423. netdev_dbg(dev->net, "asix_write_medium_mode() - mode = 0x%04x\n", mode);
  424. ret = asix_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
  425. if (ret < 0)
  426. netdev_err(dev->net, "Failed to write Medium Mode mode to 0x%04x: %02x\n",
  427. mode, ret);
  428. return ret;
  429. }
  430. static int asix_write_gpio(struct usbnet *dev, u16 value, int sleep)
  431. {
  432. int ret;
  433. netdev_dbg(dev->net, "asix_write_gpio() - value = 0x%04x\n", value);
  434. ret = asix_write_cmd(dev, AX_CMD_WRITE_GPIOS, value, 0, 0, NULL);
  435. if (ret < 0)
  436. netdev_err(dev->net, "Failed to write GPIO value 0x%04x: %02x\n",
  437. value, ret);
  438. if (sleep)
  439. msleep(sleep);
  440. return ret;
  441. }
  442. /*
  443. * AX88772 & AX88178 have a 16-bit RX_CTL value
  444. */
  445. static void asix_set_multicast(struct net_device *net)
  446. {
  447. struct usbnet *dev = netdev_priv(net);
  448. struct asix_data *data = (struct asix_data *)&dev->data;
  449. u16 rx_ctl = AX_DEFAULT_RX_CTL;
  450. if (net->flags & IFF_PROMISC) {
  451. rx_ctl |= AX_RX_CTL_PRO;
  452. } else if (net->flags & IFF_ALLMULTI ||
  453. netdev_mc_count(net) > AX_MAX_MCAST) {
  454. rx_ctl |= AX_RX_CTL_AMALL;
  455. } else if (netdev_mc_empty(net)) {
  456. /* just broadcast and directed */
  457. } else {
  458. /* We use the 20 byte dev->data
  459. * for our 8 byte filter buffer
  460. * to avoid allocating memory that
  461. * is tricky to free later */
  462. struct netdev_hw_addr *ha;
  463. u32 crc_bits;
  464. memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE);
  465. /* Build the multicast hash filter. */
  466. netdev_for_each_mc_addr(ha, net) {
  467. crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26;
  468. data->multi_filter[crc_bits >> 3] |=
  469. 1 << (crc_bits & 7);
  470. }
  471. asix_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
  472. AX_MCAST_FILTER_SIZE, data->multi_filter);
  473. rx_ctl |= AX_RX_CTL_AM;
  474. }
  475. asix_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
  476. }
  477. static int asix_mdio_read(struct net_device *netdev, int phy_id, int loc)
  478. {
  479. struct usbnet *dev = netdev_priv(netdev);
  480. __le16 res;
  481. mutex_lock(&dev->phy_mutex);
  482. asix_set_sw_mii(dev);
  483. asix_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id,
  484. (__u16)loc, 2, &res);
  485. asix_set_hw_mii(dev);
  486. mutex_unlock(&dev->phy_mutex);
  487. netdev_dbg(dev->net, "asix_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x\n",
  488. phy_id, loc, le16_to_cpu(res));
  489. return le16_to_cpu(res);
  490. }
  491. static void
  492. asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)
  493. {
  494. struct usbnet *dev = netdev_priv(netdev);
  495. __le16 res = cpu_to_le16(val);
  496. netdev_dbg(dev->net, "asix_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x\n",
  497. phy_id, loc, val);
  498. mutex_lock(&dev->phy_mutex);
  499. asix_set_sw_mii(dev);
  500. asix_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2, &res);
  501. asix_set_hw_mii(dev);
  502. mutex_unlock(&dev->phy_mutex);
  503. }
  504. /* Get the PHY Identifier from the PHYSID1 & PHYSID2 MII registers */
  505. static u32 asix_get_phyid(struct usbnet *dev)
  506. {
  507. int phy_reg;
  508. u32 phy_id;
  509. int i;
  510. /* Poll for the rare case the FW or phy isn't ready yet. */
  511. for (i = 0; i < 100; i++) {
  512. phy_reg = asix_mdio_read(dev->net, dev->mii.phy_id, MII_PHYSID1);
  513. if (phy_reg != 0 && phy_reg != 0xFFFF)
  514. break;
  515. mdelay(1);
  516. }
  517. if (phy_reg <= 0 || phy_reg == 0xFFFF)
  518. return 0;
  519. phy_id = (phy_reg & 0xffff) << 16;
  520. phy_reg = asix_mdio_read(dev->net, dev->mii.phy_id, MII_PHYSID2);
  521. if (phy_reg < 0)
  522. return 0;
  523. phy_id |= (phy_reg & 0xffff);
  524. return phy_id;
  525. }
  526. static void
  527. asix_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
  528. {
  529. struct usbnet *dev = netdev_priv(net);
  530. u8 opt;
  531. if (asix_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) {
  532. wolinfo->supported = 0;
  533. wolinfo->wolopts = 0;
  534. return;
  535. }
  536. wolinfo->supported = WAKE_PHY | WAKE_MAGIC;
  537. wolinfo->wolopts = 0;
  538. if (opt & AX_MONITOR_LINK)
  539. wolinfo->wolopts |= WAKE_PHY;
  540. if (opt & AX_MONITOR_MAGIC)
  541. wolinfo->wolopts |= WAKE_MAGIC;
  542. }
  543. static int
  544. asix_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
  545. {
  546. struct usbnet *dev = netdev_priv(net);
  547. u8 opt = 0;
  548. if (wolinfo->wolopts & WAKE_PHY)
  549. opt |= AX_MONITOR_LINK;
  550. if (wolinfo->wolopts & WAKE_MAGIC)
  551. opt |= AX_MONITOR_MAGIC;
  552. if (asix_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE,
  553. opt, 0, 0, NULL) < 0)
  554. return -EINVAL;
  555. return 0;
  556. }
  557. static int asix_get_eeprom_len(struct net_device *net)
  558. {
  559. struct usbnet *dev = netdev_priv(net);
  560. struct asix_data *data = (struct asix_data *)&dev->data;
  561. return data->eeprom_len;
  562. }
  563. static int asix_get_eeprom(struct net_device *net,
  564. struct ethtool_eeprom *eeprom, u8 *data)
  565. {
  566. struct usbnet *dev = netdev_priv(net);
  567. __le16 *ebuf = (__le16 *)data;
  568. int i;
  569. /* Crude hack to ensure that we don't overwrite memory
  570. * if an odd length is supplied
  571. */
  572. if (eeprom->len % 2)
  573. return -EINVAL;
  574. eeprom->magic = AX_EEPROM_MAGIC;
  575. /* ax8817x returns 2 bytes from eeprom on read */
  576. for (i=0; i < eeprom->len / 2; i++) {
  577. if (asix_read_cmd(dev, AX_CMD_READ_EEPROM,
  578. eeprom->offset + i, 0, 2, &ebuf[i]) < 0)
  579. return -EINVAL;
  580. }
  581. return 0;
  582. }
  583. static void asix_get_drvinfo (struct net_device *net,
  584. struct ethtool_drvinfo *info)
  585. {
  586. struct usbnet *dev = netdev_priv(net);
  587. struct asix_data *data = (struct asix_data *)&dev->data;
  588. /* Inherit standard device info */
  589. usbnet_get_drvinfo(net, info);
  590. strncpy (info->driver, DRIVER_NAME, sizeof info->driver);
  591. strncpy (info->version, DRIVER_VERSION, sizeof info->version);
  592. info->eedump_len = data->eeprom_len;
  593. }
  594. static u32 asix_get_link(struct net_device *net)
  595. {
  596. struct usbnet *dev = netdev_priv(net);
  597. return mii_link_ok(&dev->mii);
  598. }
  599. static int asix_ioctl (struct net_device *net, struct ifreq *rq, int cmd)
  600. {
  601. struct usbnet *dev = netdev_priv(net);
  602. return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
  603. }
  604. static int asix_set_mac_address(struct net_device *net, void *p)
  605. {
  606. struct usbnet *dev = netdev_priv(net);
  607. struct asix_data *data = (struct asix_data *)&dev->data;
  608. struct sockaddr *addr = p;
  609. if (netif_running(net))
  610. return -EBUSY;
  611. if (!is_valid_ether_addr(addr->sa_data))
  612. return -EADDRNOTAVAIL;
  613. memcpy(net->dev_addr, addr->sa_data, ETH_ALEN);
  614. /* We use the 20 byte dev->data
  615. * for our 6 byte mac buffer
  616. * to avoid allocating memory that
  617. * is tricky to free later */
  618. memcpy(data->mac_addr, addr->sa_data, ETH_ALEN);
  619. asix_write_cmd_async(dev, AX_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
  620. data->mac_addr);
  621. return 0;
  622. }
  623. /* We need to override some ethtool_ops so we require our
  624. own structure so we don't interfere with other usbnet
  625. devices that may be connected at the same time. */
  626. static const struct ethtool_ops ax88172_ethtool_ops = {
  627. .get_drvinfo = asix_get_drvinfo,
  628. .get_link = asix_get_link,
  629. .get_msglevel = usbnet_get_msglevel,
  630. .set_msglevel = usbnet_set_msglevel,
  631. .get_wol = asix_get_wol,
  632. .set_wol = asix_set_wol,
  633. .get_eeprom_len = asix_get_eeprom_len,
  634. .get_eeprom = asix_get_eeprom,
  635. .get_settings = usbnet_get_settings,
  636. .set_settings = usbnet_set_settings,
  637. .nway_reset = usbnet_nway_reset,
  638. };
  639. static void ax88172_set_multicast(struct net_device *net)
  640. {
  641. struct usbnet *dev = netdev_priv(net);
  642. struct asix_data *data = (struct asix_data *)&dev->data;
  643. u8 rx_ctl = 0x8c;
  644. if (net->flags & IFF_PROMISC) {
  645. rx_ctl |= 0x01;
  646. } else if (net->flags & IFF_ALLMULTI ||
  647. netdev_mc_count(net) > AX_MAX_MCAST) {
  648. rx_ctl |= 0x02;
  649. } else if (netdev_mc_empty(net)) {
  650. /* just broadcast and directed */
  651. } else {
  652. /* We use the 20 byte dev->data
  653. * for our 8 byte filter buffer
  654. * to avoid allocating memory that
  655. * is tricky to free later */
  656. struct netdev_hw_addr *ha;
  657. u32 crc_bits;
  658. memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE);
  659. /* Build the multicast hash filter. */
  660. netdev_for_each_mc_addr(ha, net) {
  661. crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26;
  662. data->multi_filter[crc_bits >> 3] |=
  663. 1 << (crc_bits & 7);
  664. }
  665. asix_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
  666. AX_MCAST_FILTER_SIZE, data->multi_filter);
  667. rx_ctl |= 0x10;
  668. }
  669. asix_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
  670. }
  671. static int ax88172_link_reset(struct usbnet *dev)
  672. {
  673. u8 mode;
  674. struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
  675. mii_check_media(&dev->mii, 1, 1);
  676. mii_ethtool_gset(&dev->mii, &ecmd);
  677. mode = AX88172_MEDIUM_DEFAULT;
  678. if (ecmd.duplex != DUPLEX_FULL)
  679. mode |= ~AX88172_MEDIUM_FD;
  680. netdev_dbg(dev->net, "ax88172_link_reset() speed: %u duplex: %d setting mode to 0x%04x\n",
  681. ethtool_cmd_speed(&ecmd), ecmd.duplex, mode);
  682. asix_write_medium_mode(dev, mode);
  683. return 0;
  684. }
  685. static const struct net_device_ops ax88172_netdev_ops = {
  686. .ndo_open = usbnet_open,
  687. .ndo_stop = usbnet_stop,
  688. .ndo_start_xmit = usbnet_start_xmit,
  689. .ndo_tx_timeout = usbnet_tx_timeout,
  690. .ndo_change_mtu = usbnet_change_mtu,
  691. .ndo_set_mac_address = eth_mac_addr,
  692. .ndo_validate_addr = eth_validate_addr,
  693. .ndo_do_ioctl = asix_ioctl,
  694. .ndo_set_rx_mode = ax88172_set_multicast,
  695. };
  696. static int ax88172_bind(struct usbnet *dev, struct usb_interface *intf)
  697. {
  698. int ret = 0;
  699. u8 buf[ETH_ALEN];
  700. int i;
  701. unsigned long gpio_bits = dev->driver_info->data;
  702. struct asix_data *data = (struct asix_data *)&dev->data;
  703. data->eeprom_len = AX88172_EEPROM_LEN;
  704. usbnet_get_endpoints(dev,intf);
  705. /* Toggle the GPIOs in a manufacturer/model specific way */
  706. for (i = 2; i >= 0; i--) {
  707. ret = asix_write_cmd(dev, AX_CMD_WRITE_GPIOS,
  708. (gpio_bits >> (i * 8)) & 0xff, 0, 0, NULL);
  709. if (ret < 0)
  710. goto out;
  711. msleep(5);
  712. }
  713. ret = asix_write_rx_ctl(dev, 0x80);
  714. if (ret < 0)
  715. goto out;
  716. /* Get the MAC address */
  717. ret = asix_read_cmd(dev, AX88172_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf);
  718. if (ret < 0) {
  719. dbg("read AX_CMD_READ_NODE_ID failed: %d", ret);
  720. goto out;
  721. }
  722. memcpy(dev->net->dev_addr, buf, ETH_ALEN);
  723. /* Initialize MII structure */
  724. dev->mii.dev = dev->net;
  725. dev->mii.mdio_read = asix_mdio_read;
  726. dev->mii.mdio_write = asix_mdio_write;
  727. dev->mii.phy_id_mask = 0x3f;
  728. dev->mii.reg_num_mask = 0x1f;
  729. dev->mii.phy_id = asix_get_phy_addr(dev);
  730. dev->net->netdev_ops = &ax88172_netdev_ops;
  731. dev->net->ethtool_ops = &ax88172_ethtool_ops;
  732. asix_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
  733. asix_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
  734. ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  735. mii_nway_restart(&dev->mii);
  736. return 0;
  737. out:
  738. return ret;
  739. }
  740. static const struct ethtool_ops ax88772_ethtool_ops = {
  741. .get_drvinfo = asix_get_drvinfo,
  742. .get_link = asix_get_link,
  743. .get_msglevel = usbnet_get_msglevel,
  744. .set_msglevel = usbnet_set_msglevel,
  745. .get_wol = asix_get_wol,
  746. .set_wol = asix_set_wol,
  747. .get_eeprom_len = asix_get_eeprom_len,
  748. .get_eeprom = asix_get_eeprom,
  749. .get_settings = usbnet_get_settings,
  750. .set_settings = usbnet_set_settings,
  751. .nway_reset = usbnet_nway_reset,
  752. };
  753. static int ax88772_link_reset(struct usbnet *dev)
  754. {
  755. u16 mode;
  756. struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
  757. mii_check_media(&dev->mii, 1, 1);
  758. mii_ethtool_gset(&dev->mii, &ecmd);
  759. mode = AX88772_MEDIUM_DEFAULT;
  760. if (ethtool_cmd_speed(&ecmd) != SPEED_100)
  761. mode &= ~AX_MEDIUM_PS;
  762. if (ecmd.duplex != DUPLEX_FULL)
  763. mode &= ~AX_MEDIUM_FD;
  764. netdev_dbg(dev->net, "ax88772_link_reset() speed: %u duplex: %d setting mode to 0x%04x\n",
  765. ethtool_cmd_speed(&ecmd), ecmd.duplex, mode);
  766. asix_write_medium_mode(dev, mode);
  767. return 0;
  768. }
  769. static int ax88772_reset(struct usbnet *dev)
  770. {
  771. struct asix_data *data = (struct asix_data *)&dev->data;
  772. int ret, embd_phy;
  773. u16 rx_ctl;
  774. ret = asix_write_gpio(dev,
  775. AX_GPIO_RSE | AX_GPIO_GPO_2 | AX_GPIO_GPO2EN, 5);
  776. if (ret < 0)
  777. goto out;
  778. embd_phy = ((asix_get_phy_addr(dev) & 0x1f) == 0x10 ? 1 : 0);
  779. ret = asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT, embd_phy, 0, 0, NULL);
  780. if (ret < 0) {
  781. dbg("Select PHY #1 failed: %d", ret);
  782. goto out;
  783. }
  784. ret = asix_sw_reset(dev, AX_SWRESET_IPPD | AX_SWRESET_PRL);
  785. if (ret < 0)
  786. goto out;
  787. msleep(150);
  788. ret = asix_sw_reset(dev, AX_SWRESET_CLEAR);
  789. if (ret < 0)
  790. goto out;
  791. msleep(150);
  792. if (embd_phy) {
  793. ret = asix_sw_reset(dev, AX_SWRESET_IPRL);
  794. if (ret < 0)
  795. goto out;
  796. } else {
  797. ret = asix_sw_reset(dev, AX_SWRESET_PRTE);
  798. if (ret < 0)
  799. goto out;
  800. }
  801. msleep(150);
  802. rx_ctl = asix_read_rx_ctl(dev);
  803. dbg("RX_CTL is 0x%04x after software reset", rx_ctl);
  804. ret = asix_write_rx_ctl(dev, 0x0000);
  805. if (ret < 0)
  806. goto out;
  807. rx_ctl = asix_read_rx_ctl(dev);
  808. dbg("RX_CTL is 0x%04x setting to 0x0000", rx_ctl);
  809. ret = asix_sw_reset(dev, AX_SWRESET_PRL);
  810. if (ret < 0)
  811. goto out;
  812. msleep(150);
  813. ret = asix_sw_reset(dev, AX_SWRESET_IPRL | AX_SWRESET_PRL);
  814. if (ret < 0)
  815. goto out;
  816. msleep(150);
  817. asix_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
  818. asix_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
  819. ADVERTISE_ALL | ADVERTISE_CSMA);
  820. mii_nway_restart(&dev->mii);
  821. ret = asix_write_medium_mode(dev, AX88772_MEDIUM_DEFAULT);
  822. if (ret < 0)
  823. goto out;
  824. ret = asix_write_cmd(dev, AX_CMD_WRITE_IPG0,
  825. AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT,
  826. AX88772_IPG2_DEFAULT, 0, NULL);
  827. if (ret < 0) {
  828. dbg("Write IPG,IPG1,IPG2 failed: %d", ret);
  829. goto out;
  830. }
  831. /* Rewrite MAC address */
  832. memcpy(data->mac_addr, dev->net->dev_addr, ETH_ALEN);
  833. ret = asix_write_cmd(dev, AX_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
  834. data->mac_addr);
  835. if (ret < 0)
  836. goto out;
  837. /* Set RX_CTL to default values with 2k buffer, and enable cactus */
  838. ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL);
  839. if (ret < 0)
  840. goto out;
  841. rx_ctl = asix_read_rx_ctl(dev);
  842. dbg("RX_CTL is 0x%04x after all initializations", rx_ctl);
  843. rx_ctl = asix_read_medium_status(dev);
  844. dbg("Medium Status is 0x%04x after all initializations", rx_ctl);
  845. return 0;
  846. out:
  847. return ret;
  848. }
  849. static const struct net_device_ops ax88772_netdev_ops = {
  850. .ndo_open = usbnet_open,
  851. .ndo_stop = usbnet_stop,
  852. .ndo_start_xmit = usbnet_start_xmit,
  853. .ndo_tx_timeout = usbnet_tx_timeout,
  854. .ndo_change_mtu = usbnet_change_mtu,
  855. .ndo_set_mac_address = asix_set_mac_address,
  856. .ndo_validate_addr = eth_validate_addr,
  857. .ndo_do_ioctl = asix_ioctl,
  858. .ndo_set_rx_mode = asix_set_multicast,
  859. };
  860. static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
  861. {
  862. int ret, embd_phy;
  863. struct asix_data *data = (struct asix_data *)&dev->data;
  864. u8 buf[ETH_ALEN];
  865. u32 phyid;
  866. data->eeprom_len = AX88772_EEPROM_LEN;
  867. usbnet_get_endpoints(dev,intf);
  868. /* Get the MAC address */
  869. ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf);
  870. if (ret < 0) {
  871. dbg("Failed to read MAC address: %d", ret);
  872. return ret;
  873. }
  874. memcpy(dev->net->dev_addr, buf, ETH_ALEN);
  875. /* Initialize MII structure */
  876. dev->mii.dev = dev->net;
  877. dev->mii.mdio_read = asix_mdio_read;
  878. dev->mii.mdio_write = asix_mdio_write;
  879. dev->mii.phy_id_mask = 0x1f;
  880. dev->mii.reg_num_mask = 0x1f;
  881. dev->mii.phy_id = asix_get_phy_addr(dev);
  882. dev->net->netdev_ops = &ax88772_netdev_ops;
  883. dev->net->ethtool_ops = &ax88772_ethtool_ops;
  884. embd_phy = ((dev->mii.phy_id & 0x1f) == 0x10 ? 1 : 0);
  885. /* Reset the PHY to normal operation mode */
  886. ret = asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT, embd_phy, 0, 0, NULL);
  887. if (ret < 0) {
  888. dbg("Select PHY #1 failed: %d", ret);
  889. return ret;
  890. }
  891. ret = asix_sw_reset(dev, AX_SWRESET_IPPD | AX_SWRESET_PRL);
  892. if (ret < 0)
  893. return ret;
  894. msleep(150);
  895. ret = asix_sw_reset(dev, AX_SWRESET_CLEAR);
  896. if (ret < 0)
  897. return ret;
  898. msleep(150);
  899. ret = asix_sw_reset(dev, embd_phy ? AX_SWRESET_IPRL : AX_SWRESET_PRTE);
  900. /* Read PHYID register *AFTER* the PHY was reset properly */
  901. phyid = asix_get_phyid(dev);
  902. dbg("PHYID=0x%08x", phyid);
  903. /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
  904. if (dev->driver_info->flags & FLAG_FRAMING_AX) {
  905. /* hard_mtu is still the default - the device does not support
  906. jumbo eth frames */
  907. dev->rx_urb_size = 2048;
  908. }
  909. return 0;
  910. }
  911. static const struct ethtool_ops ax88178_ethtool_ops = {
  912. .get_drvinfo = asix_get_drvinfo,
  913. .get_link = asix_get_link,
  914. .get_msglevel = usbnet_get_msglevel,
  915. .set_msglevel = usbnet_set_msglevel,
  916. .get_wol = asix_get_wol,
  917. .set_wol = asix_set_wol,
  918. .get_eeprom_len = asix_get_eeprom_len,
  919. .get_eeprom = asix_get_eeprom,
  920. .get_settings = usbnet_get_settings,
  921. .set_settings = usbnet_set_settings,
  922. .nway_reset = usbnet_nway_reset,
  923. };
  924. static int marvell_phy_init(struct usbnet *dev)
  925. {
  926. struct asix_data *data = (struct asix_data *)&dev->data;
  927. u16 reg;
  928. netdev_dbg(dev->net, "marvell_phy_init()\n");
  929. reg = asix_mdio_read(dev->net, dev->mii.phy_id, MII_MARVELL_STATUS);
  930. netdev_dbg(dev->net, "MII_MARVELL_STATUS = 0x%04x\n", reg);
  931. asix_mdio_write(dev->net, dev->mii.phy_id, MII_MARVELL_CTRL,
  932. MARVELL_CTRL_RXDELAY | MARVELL_CTRL_TXDELAY);
  933. if (data->ledmode) {
  934. reg = asix_mdio_read(dev->net, dev->mii.phy_id,
  935. MII_MARVELL_LED_CTRL);
  936. netdev_dbg(dev->net, "MII_MARVELL_LED_CTRL (1) = 0x%04x\n", reg);
  937. reg &= 0xf8ff;
  938. reg |= (1 + 0x0100);
  939. asix_mdio_write(dev->net, dev->mii.phy_id,
  940. MII_MARVELL_LED_CTRL, reg);
  941. reg = asix_mdio_read(dev->net, dev->mii.phy_id,
  942. MII_MARVELL_LED_CTRL);
  943. netdev_dbg(dev->net, "MII_MARVELL_LED_CTRL (2) = 0x%04x\n", reg);
  944. reg &= 0xfc0f;
  945. }
  946. return 0;
  947. }
  948. static int rtl8211cl_phy_init(struct usbnet *dev)
  949. {
  950. struct asix_data *data = (struct asix_data *)&dev->data;
  951. netdev_dbg(dev->net, "rtl8211cl_phy_init()\n");
  952. asix_mdio_write (dev->net, dev->mii.phy_id, 0x1f, 0x0005);
  953. asix_mdio_write (dev->net, dev->mii.phy_id, 0x0c, 0);
  954. asix_mdio_write (dev->net, dev->mii.phy_id, 0x01,
  955. asix_mdio_read (dev->net, dev->mii.phy_id, 0x01) | 0x0080);
  956. asix_mdio_write (dev->net, dev->mii.phy_id, 0x1f, 0);
  957. if (data->ledmode == 12) {
  958. asix_mdio_write (dev->net, dev->mii.phy_id, 0x1f, 0x0002);
  959. asix_mdio_write (dev->net, dev->mii.phy_id, 0x1a, 0x00cb);
  960. asix_mdio_write (dev->net, dev->mii.phy_id, 0x1f, 0);
  961. }
  962. return 0;
  963. }
  964. static int marvell_led_status(struct usbnet *dev, u16 speed)
  965. {
  966. u16 reg = asix_mdio_read(dev->net, dev->mii.phy_id, MARVELL_LED_MANUAL);
  967. netdev_dbg(dev->net, "marvell_led_status() read 0x%04x\n", reg);
  968. /* Clear out the center LED bits - 0x03F0 */
  969. reg &= 0xfc0f;
  970. switch (speed) {
  971. case SPEED_1000:
  972. reg |= 0x03e0;
  973. break;
  974. case SPEED_100:
  975. reg |= 0x03b0;
  976. break;
  977. default:
  978. reg |= 0x02f0;
  979. }
  980. netdev_dbg(dev->net, "marvell_led_status() writing 0x%04x\n", reg);
  981. asix_mdio_write(dev->net, dev->mii.phy_id, MARVELL_LED_MANUAL, reg);
  982. return 0;
  983. }
  984. static int ax88178_reset(struct usbnet *dev)
  985. {
  986. struct asix_data *data = (struct asix_data *)&dev->data;
  987. int ret;
  988. __le16 eeprom;
  989. u8 status;
  990. int gpio0 = 0;
  991. u32 phyid;
  992. asix_read_cmd(dev, AX_CMD_READ_GPIOS, 0, 0, 1, &status);
  993. dbg("GPIO Status: 0x%04x", status);
  994. asix_write_cmd(dev, AX_CMD_WRITE_ENABLE, 0, 0, 0, NULL);
  995. asix_read_cmd(dev, AX_CMD_READ_EEPROM, 0x0017, 0, 2, &eeprom);
  996. asix_write_cmd(dev, AX_CMD_WRITE_DISABLE, 0, 0, 0, NULL);
  997. dbg("EEPROM index 0x17 is 0x%04x", eeprom);
  998. if (eeprom == cpu_to_le16(0xffff)) {
  999. data->phymode = PHY_MODE_MARVELL;
  1000. data->ledmode = 0;
  1001. gpio0 = 1;
  1002. } else {
  1003. data->phymode = le16_to_cpu(eeprom) & 0x7F;
  1004. data->ledmode = le16_to_cpu(eeprom) >> 8;
  1005. gpio0 = (le16_to_cpu(eeprom) & 0x80) ? 0 : 1;
  1006. }
  1007. dbg("GPIO0: %d, PhyMode: %d", gpio0, data->phymode);
  1008. /* Power up external GigaPHY through AX88178 GPIO pin */
  1009. asix_write_gpio(dev, AX_GPIO_RSE | AX_GPIO_GPO_1 | AX_GPIO_GPO1EN, 40);
  1010. if ((le16_to_cpu(eeprom) >> 8) != 1) {
  1011. asix_write_gpio(dev, 0x003c, 30);
  1012. asix_write_gpio(dev, 0x001c, 300);
  1013. asix_write_gpio(dev, 0x003c, 30);
  1014. } else {
  1015. dbg("gpio phymode == 1 path");
  1016. asix_write_gpio(dev, AX_GPIO_GPO1EN, 30);
  1017. asix_write_gpio(dev, AX_GPIO_GPO1EN | AX_GPIO_GPO_1, 30);
  1018. }
  1019. /* Read PHYID register *AFTER* powering up PHY */
  1020. phyid = asix_get_phyid(dev);
  1021. dbg("PHYID=0x%08x", phyid);
  1022. /* Set AX88178 to enable MII/GMII/RGMII interface for external PHY */
  1023. asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT, 0, 0, 0, NULL);
  1024. asix_sw_reset(dev, 0);
  1025. msleep(150);
  1026. asix_sw_reset(dev, AX_SWRESET_PRL | AX_SWRESET_IPPD);
  1027. msleep(150);
  1028. asix_write_rx_ctl(dev, 0);
  1029. if (data->phymode == PHY_MODE_MARVELL) {
  1030. marvell_phy_init(dev);
  1031. msleep(60);
  1032. } else if (data->phymode == PHY_MODE_RTL8211CL)
  1033. rtl8211cl_phy_init(dev);
  1034. asix_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR,
  1035. BMCR_RESET | BMCR_ANENABLE);
  1036. asix_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
  1037. ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  1038. asix_mdio_write(dev->net, dev->mii.phy_id, MII_CTRL1000,
  1039. ADVERTISE_1000FULL);
  1040. mii_nway_restart(&dev->mii);
  1041. ret = asix_write_medium_mode(dev, AX88178_MEDIUM_DEFAULT);
  1042. if (ret < 0)
  1043. return ret;
  1044. /* Rewrite MAC address */
  1045. memcpy(data->mac_addr, dev->net->dev_addr, ETH_ALEN);
  1046. ret = asix_write_cmd(dev, AX_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
  1047. data->mac_addr);
  1048. if (ret < 0)
  1049. return ret;
  1050. ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL);
  1051. if (ret < 0)
  1052. return ret;
  1053. return 0;
  1054. }
  1055. static int ax88178_link_reset(struct usbnet *dev)
  1056. {
  1057. u16 mode;
  1058. struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
  1059. struct asix_data *data = (struct asix_data *)&dev->data;
  1060. u32 speed;
  1061. netdev_dbg(dev->net, "ax88178_link_reset()\n");
  1062. mii_check_media(&dev->mii, 1, 1);
  1063. mii_ethtool_gset(&dev->mii, &ecmd);
  1064. mode = AX88178_MEDIUM_DEFAULT;
  1065. speed = ethtool_cmd_speed(&ecmd);
  1066. if (speed == SPEED_1000)
  1067. mode |= AX_MEDIUM_GM;
  1068. else if (speed == SPEED_100)
  1069. mode |= AX_MEDIUM_PS;
  1070. else
  1071. mode &= ~(AX_MEDIUM_PS | AX_MEDIUM_GM);
  1072. mode |= AX_MEDIUM_ENCK;
  1073. if (ecmd.duplex == DUPLEX_FULL)
  1074. mode |= AX_MEDIUM_FD;
  1075. else
  1076. mode &= ~AX_MEDIUM_FD;
  1077. netdev_dbg(dev->net, "ax88178_link_reset() speed: %u duplex: %d setting mode to 0x%04x\n",
  1078. speed, ecmd.duplex, mode);
  1079. asix_write_medium_mode(dev, mode);
  1080. if (data->phymode == PHY_MODE_MARVELL && data->ledmode)
  1081. marvell_led_status(dev, speed);
  1082. return 0;
  1083. }
  1084. static void ax88178_set_mfb(struct usbnet *dev)
  1085. {
  1086. u16 mfb = AX_RX_CTL_MFB_16384;
  1087. u16 rxctl;
  1088. u16 medium;
  1089. int old_rx_urb_size = dev->rx_urb_size;
  1090. if (dev->hard_mtu < 2048) {
  1091. dev->rx_urb_size = 2048;
  1092. mfb = AX_RX_CTL_MFB_2048;
  1093. } else if (dev->hard_mtu < 4096) {
  1094. dev->rx_urb_size = 4096;
  1095. mfb = AX_RX_CTL_MFB_4096;
  1096. } else if (dev->hard_mtu < 8192) {
  1097. dev->rx_urb_size = 8192;
  1098. mfb = AX_RX_CTL_MFB_8192;
  1099. } else if (dev->hard_mtu < 16384) {
  1100. dev->rx_urb_size = 16384;
  1101. mfb = AX_RX_CTL_MFB_16384;
  1102. }
  1103. rxctl = asix_read_rx_ctl(dev);
  1104. asix_write_rx_ctl(dev, (rxctl & ~AX_RX_CTL_MFB_16384) | mfb);
  1105. medium = asix_read_medium_status(dev);
  1106. if (dev->net->mtu > 1500)
  1107. medium |= AX_MEDIUM_JFE;
  1108. else
  1109. medium &= ~AX_MEDIUM_JFE;
  1110. asix_write_medium_mode(dev, medium);
  1111. if (dev->rx_urb_size > old_rx_urb_size)
  1112. usbnet_unlink_rx_urbs(dev);
  1113. }
  1114. static int ax88178_change_mtu(struct net_device *net, int new_mtu)
  1115. {
  1116. struct usbnet *dev = netdev_priv(net);
  1117. int ll_mtu = new_mtu + net->hard_header_len + 4;
  1118. netdev_dbg(dev->net, "ax88178_change_mtu() new_mtu=%d\n", new_mtu);
  1119. if (new_mtu <= 0 || ll_mtu > 16384)
  1120. return -EINVAL;
  1121. if ((ll_mtu % dev->maxpacket) == 0)
  1122. return -EDOM;
  1123. net->mtu = new_mtu;
  1124. dev->hard_mtu = net->mtu + net->hard_header_len;
  1125. ax88178_set_mfb(dev);
  1126. return 0;
  1127. }
  1128. static const struct net_device_ops ax88178_netdev_ops = {
  1129. .ndo_open = usbnet_open,
  1130. .ndo_stop = usbnet_stop,
  1131. .ndo_start_xmit = usbnet_start_xmit,
  1132. .ndo_tx_timeout = usbnet_tx_timeout,
  1133. .ndo_set_mac_address = asix_set_mac_address,
  1134. .ndo_validate_addr = eth_validate_addr,
  1135. .ndo_set_rx_mode = asix_set_multicast,
  1136. .ndo_do_ioctl = asix_ioctl,
  1137. .ndo_change_mtu = ax88178_change_mtu,
  1138. };
  1139. static int ax88178_bind(struct usbnet *dev, struct usb_interface *intf)
  1140. {
  1141. int ret;
  1142. u8 buf[ETH_ALEN];
  1143. struct asix_data *data = (struct asix_data *)&dev->data;
  1144. data->eeprom_len = AX88772_EEPROM_LEN;
  1145. usbnet_get_endpoints(dev,intf);
  1146. /* Get the MAC address */
  1147. ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf);
  1148. if (ret < 0) {
  1149. dbg("Failed to read MAC address: %d", ret);
  1150. return ret;
  1151. }
  1152. memcpy(dev->net->dev_addr, buf, ETH_ALEN);
  1153. /* Initialize MII structure */
  1154. dev->mii.dev = dev->net;
  1155. dev->mii.mdio_read = asix_mdio_read;
  1156. dev->mii.mdio_write = asix_mdio_write;
  1157. dev->mii.phy_id_mask = 0x1f;
  1158. dev->mii.reg_num_mask = 0xff;
  1159. dev->mii.supports_gmii = 1;
  1160. dev->mii.phy_id = asix_get_phy_addr(dev);
  1161. dev->net->netdev_ops = &ax88178_netdev_ops;
  1162. dev->net->ethtool_ops = &ax88178_ethtool_ops;
  1163. /* Blink LEDS so users know driver saw dongle */
  1164. asix_sw_reset(dev, 0);
  1165. msleep(150);
  1166. asix_sw_reset(dev, AX_SWRESET_PRL | AX_SWRESET_IPPD);
  1167. msleep(150);
  1168. /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
  1169. if (dev->driver_info->flags & FLAG_FRAMING_AX) {
  1170. /* hard_mtu is still the default - the device does not support
  1171. jumbo eth frames */
  1172. dev->rx_urb_size = 2048;
  1173. }
  1174. return 0;
  1175. }
  1176. static const struct driver_info ax8817x_info = {
  1177. .description = "ASIX AX8817x USB 2.0 Ethernet",
  1178. .bind = ax88172_bind,
  1179. .status = asix_status,
  1180. .link_reset = ax88172_link_reset,
  1181. .reset = ax88172_link_reset,
  1182. .flags = FLAG_ETHER | FLAG_LINK_INTR,
  1183. .data = 0x00130103,
  1184. };
  1185. static const struct driver_info dlink_dub_e100_info = {
  1186. .description = "DLink DUB-E100 USB Ethernet",
  1187. .bind = ax88172_bind,
  1188. .status = asix_status,
  1189. .link_reset = ax88172_link_reset,
  1190. .reset = ax88172_link_reset,
  1191. .flags = FLAG_ETHER | FLAG_LINK_INTR,
  1192. .data = 0x009f9d9f,
  1193. };
  1194. static const struct driver_info netgear_fa120_info = {
  1195. .description = "Netgear FA-120 USB Ethernet",
  1196. .bind = ax88172_bind,
  1197. .status = asix_status,
  1198. .link_reset = ax88172_link_reset,
  1199. .reset = ax88172_link_reset,
  1200. .flags = FLAG_ETHER | FLAG_LINK_INTR,
  1201. .data = 0x00130103,
  1202. };
  1203. static const struct driver_info hawking_uf200_info = {
  1204. .description = "Hawking UF200 USB Ethernet",
  1205. .bind = ax88172_bind,
  1206. .status = asix_status,
  1207. .link_reset = ax88172_link_reset,
  1208. .reset = ax88172_link_reset,
  1209. .flags = FLAG_ETHER | FLAG_LINK_INTR,
  1210. .data = 0x001f1d1f,
  1211. };
  1212. static const struct driver_info ax88772_info = {
  1213. .description = "ASIX AX88772 USB 2.0 Ethernet",
  1214. .bind = ax88772_bind,
  1215. .status = asix_status,
  1216. .link_reset = ax88772_link_reset,
  1217. .reset = ax88772_reset,
  1218. .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR | FLAG_MULTI_PACKET,
  1219. .rx_fixup = asix_rx_fixup,
  1220. .tx_fixup = asix_tx_fixup,
  1221. };
  1222. static const struct driver_info ax88178_info = {
  1223. .description = "ASIX AX88178 USB 2.0 Ethernet",
  1224. .bind = ax88178_bind,
  1225. .status = asix_status,
  1226. .link_reset = ax88178_link_reset,
  1227. .reset = ax88178_reset,
  1228. .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR,
  1229. .rx_fixup = asix_rx_fixup,
  1230. .tx_fixup = asix_tx_fixup,
  1231. };
  1232. static const struct usb_device_id products [] = {
  1233. {
  1234. // Linksys USB200M
  1235. USB_DEVICE (0x077b, 0x2226),
  1236. .driver_info = (unsigned long) &ax8817x_info,
  1237. }, {
  1238. // Netgear FA120
  1239. USB_DEVICE (0x0846, 0x1040),
  1240. .driver_info = (unsigned long) &netgear_fa120_info,
  1241. }, {
  1242. // DLink DUB-E100
  1243. USB_DEVICE (0x2001, 0x1a00),
  1244. .driver_info = (unsigned long) &dlink_dub_e100_info,
  1245. }, {
  1246. // Intellinet, ST Lab USB Ethernet
  1247. USB_DEVICE (0x0b95, 0x1720),
  1248. .driver_info = (unsigned long) &ax8817x_info,
  1249. }, {
  1250. // Hawking UF200, TrendNet TU2-ET100
  1251. USB_DEVICE (0x07b8, 0x420a),
  1252. .driver_info = (unsigned long) &hawking_uf200_info,
  1253. }, {
  1254. // Billionton Systems, USB2AR
  1255. USB_DEVICE (0x08dd, 0x90ff),
  1256. .driver_info = (unsigned long) &ax8817x_info,
  1257. }, {
  1258. // ATEN UC210T
  1259. USB_DEVICE (0x0557, 0x2009),
  1260. .driver_info = (unsigned long) &ax8817x_info,
  1261. }, {
  1262. // Buffalo LUA-U2-KTX
  1263. USB_DEVICE (0x0411, 0x003d),
  1264. .driver_info = (unsigned long) &ax8817x_info,
  1265. }, {
  1266. // Buffalo LUA-U2-GT 10/100/1000
  1267. USB_DEVICE (0x0411, 0x006e),
  1268. .driver_info = (unsigned long) &ax88178_info,
  1269. }, {
  1270. // Sitecom LN-029 "USB 2.0 10/100 Ethernet adapter"
  1271. USB_DEVICE (0x6189, 0x182d),
  1272. .driver_info = (unsigned long) &ax8817x_info,
  1273. }, {
  1274. // Sitecom LN-031 "USB 2.0 10/100/1000 Ethernet adapter"
  1275. USB_DEVICE (0x0df6, 0x0056),
  1276. .driver_info = (unsigned long) &ax88178_info,
  1277. }, {
  1278. // corega FEther USB2-TX
  1279. USB_DEVICE (0x07aa, 0x0017),
  1280. .driver_info = (unsigned long) &ax8817x_info,
  1281. }, {
  1282. // Surecom EP-1427X-2
  1283. USB_DEVICE (0x1189, 0x0893),
  1284. .driver_info = (unsigned long) &ax8817x_info,
  1285. }, {
  1286. // goodway corp usb gwusb2e
  1287. USB_DEVICE (0x1631, 0x6200),
  1288. .driver_info = (unsigned long) &ax8817x_info,
  1289. }, {
  1290. // JVC MP-PRX1 Port Replicator
  1291. USB_DEVICE (0x04f1, 0x3008),
  1292. .driver_info = (unsigned long) &ax8817x_info,
  1293. }, {
  1294. // ASIX AX88772B 10/100
  1295. USB_DEVICE (0x0b95, 0x772b),
  1296. .driver_info = (unsigned long) &ax88772_info,
  1297. }, {
  1298. // ASIX AX88772 10/100
  1299. USB_DEVICE (0x0b95, 0x7720),
  1300. .driver_info = (unsigned long) &ax88772_info,
  1301. }, {
  1302. // ASIX AX88178 10/100/1000
  1303. USB_DEVICE (0x0b95, 0x1780),
  1304. .driver_info = (unsigned long) &ax88178_info,
  1305. }, {
  1306. // Logitec LAN-GTJ/U2A
  1307. USB_DEVICE (0x0789, 0x0160),
  1308. .driver_info = (unsigned long) &ax88178_info,
  1309. }, {
  1310. // Linksys USB200M Rev 2
  1311. USB_DEVICE (0x13b1, 0x0018),
  1312. .driver_info = (unsigned long) &ax88772_info,
  1313. }, {
  1314. // 0Q0 cable ethernet
  1315. USB_DEVICE (0x1557, 0x7720),
  1316. .driver_info = (unsigned long) &ax88772_info,
  1317. }, {
  1318. // DLink DUB-E100 H/W Ver B1
  1319. USB_DEVICE (0x07d1, 0x3c05),
  1320. .driver_info = (unsigned long) &ax88772_info,
  1321. }, {
  1322. // DLink DUB-E100 H/W Ver B1 Alternate
  1323. USB_DEVICE (0x2001, 0x3c05),
  1324. .driver_info = (unsigned long) &ax88772_info,
  1325. }, {
  1326. // Linksys USB1000
  1327. USB_DEVICE (0x1737, 0x0039),
  1328. .driver_info = (unsigned long) &ax88178_info,
  1329. }, {
  1330. // IO-DATA ETG-US2
  1331. USB_DEVICE (0x04bb, 0x0930),
  1332. .driver_info = (unsigned long) &ax88178_info,
  1333. }, {
  1334. // Belkin F5D5055
  1335. USB_DEVICE(0x050d, 0x5055),
  1336. .driver_info = (unsigned long) &ax88178_info,
  1337. }, {
  1338. // Apple USB Ethernet Adapter
  1339. USB_DEVICE(0x05ac, 0x1402),
  1340. .driver_info = (unsigned long) &ax88772_info,
  1341. }, {
  1342. // Cables-to-Go USB Ethernet Adapter
  1343. USB_DEVICE(0x0b95, 0x772a),
  1344. .driver_info = (unsigned long) &ax88772_info,
  1345. }, {
  1346. // ABOCOM for pci
  1347. USB_DEVICE(0x14ea, 0xab11),
  1348. .driver_info = (unsigned long) &ax88178_info,
  1349. }, {
  1350. // ASIX 88772a
  1351. USB_DEVICE(0x0db0, 0xa877),
  1352. .driver_info = (unsigned long) &ax88772_info,
  1353. }, {
  1354. // Asus USB Ethernet Adapter
  1355. USB_DEVICE (0x0b95, 0x7e2b),
  1356. .driver_info = (unsigned long) &ax88772_info,
  1357. },
  1358. { }, // END
  1359. };
  1360. MODULE_DEVICE_TABLE(usb, products);
  1361. static struct usb_driver asix_driver = {
  1362. .name = DRIVER_NAME,
  1363. .id_table = products,
  1364. .probe = usbnet_probe,
  1365. .suspend = usbnet_suspend,
  1366. .resume = usbnet_resume,
  1367. .disconnect = usbnet_disconnect,
  1368. .supports_autosuspend = 1,
  1369. .disable_hub_initiated_lpm = 1,
  1370. };
  1371. module_usb_driver(asix_driver);
  1372. MODULE_AUTHOR("David Hollis");
  1373. MODULE_VERSION(DRIVER_VERSION);
  1374. MODULE_DESCRIPTION("ASIX AX8817X based USB 2.0 Ethernet Devices");
  1375. MODULE_LICENSE("GPL");