asix.c 43 KB

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