asix_devices.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * ASIX AX8817X based USB 2.0 Ethernet Devices
  4. * Copyright (C) 2003-2006 David Hollis <dhollis@davehollis.com>
  5. * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net>
  6. * Copyright (C) 2006 James Painter <jamie.painter@iname.com>
  7. * Copyright (c) 2002-2003 TiVo Inc.
  8. */
  9. #include "asix.h"
  10. #define PHY_MODE_MARVELL 0x0000
  11. #define MII_MARVELL_LED_CTRL 0x0018
  12. #define MII_MARVELL_STATUS 0x001b
  13. #define MII_MARVELL_CTRL 0x0014
  14. #define MARVELL_LED_MANUAL 0x0019
  15. #define MARVELL_STATUS_HWCFG 0x0004
  16. #define MARVELL_CTRL_TXDELAY 0x0002
  17. #define MARVELL_CTRL_RXDELAY 0x0080
  18. #define PHY_MODE_RTL8211CL 0x000C
  19. #define AX88772A_PHY14H 0x14
  20. #define AX88772A_PHY14H_DEFAULT 0x442C
  21. #define AX88772A_PHY15H 0x15
  22. #define AX88772A_PHY15H_DEFAULT 0x03C8
  23. #define AX88772A_PHY16H 0x16
  24. #define AX88772A_PHY16H_DEFAULT 0x4044
  25. struct ax88172_int_data {
  26. __le16 res1;
  27. u8 link;
  28. __le16 res2;
  29. u8 status;
  30. __le16 res3;
  31. } __packed;
  32. static void asix_status(struct usbnet *dev, struct urb *urb)
  33. {
  34. struct ax88172_int_data *event;
  35. int link;
  36. if (urb->actual_length < 8)
  37. return;
  38. event = urb->transfer_buffer;
  39. link = event->link & 0x01;
  40. if (netif_carrier_ok(dev->net) != link) {
  41. usbnet_link_change(dev, link, 1);
  42. netdev_dbg(dev->net, "Link Status is: %d\n", link);
  43. }
  44. }
  45. static void asix_set_netdev_dev_addr(struct usbnet *dev, u8 *addr)
  46. {
  47. if (is_valid_ether_addr(addr)) {
  48. memcpy(dev->net->dev_addr, addr, ETH_ALEN);
  49. } else {
  50. netdev_info(dev->net, "invalid hw address, using random\n");
  51. eth_hw_addr_random(dev->net);
  52. }
  53. }
  54. /* Get the PHY Identifier from the PHYSID1 & PHYSID2 MII registers */
  55. static u32 asix_get_phyid(struct usbnet *dev)
  56. {
  57. int phy_reg;
  58. u32 phy_id;
  59. int i;
  60. /* Poll for the rare case the FW or phy isn't ready yet. */
  61. for (i = 0; i < 100; i++) {
  62. phy_reg = asix_mdio_read(dev->net, dev->mii.phy_id, MII_PHYSID1);
  63. if (phy_reg < 0)
  64. return 0;
  65. if (phy_reg != 0 && phy_reg != 0xFFFF)
  66. break;
  67. mdelay(1);
  68. }
  69. if (phy_reg <= 0 || phy_reg == 0xFFFF)
  70. return 0;
  71. phy_id = (phy_reg & 0xffff) << 16;
  72. phy_reg = asix_mdio_read(dev->net, dev->mii.phy_id, MII_PHYSID2);
  73. if (phy_reg < 0)
  74. return 0;
  75. phy_id |= (phy_reg & 0xffff);
  76. return phy_id;
  77. }
  78. static u32 asix_get_link(struct net_device *net)
  79. {
  80. struct usbnet *dev = netdev_priv(net);
  81. return mii_link_ok(&dev->mii);
  82. }
  83. static int asix_ioctl (struct net_device *net, struct ifreq *rq, int cmd)
  84. {
  85. struct usbnet *dev = netdev_priv(net);
  86. return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
  87. }
  88. /* We need to override some ethtool_ops so we require our
  89. own structure so we don't interfere with other usbnet
  90. devices that may be connected at the same time. */
  91. static const struct ethtool_ops ax88172_ethtool_ops = {
  92. .get_drvinfo = asix_get_drvinfo,
  93. .get_link = asix_get_link,
  94. .get_msglevel = usbnet_get_msglevel,
  95. .set_msglevel = usbnet_set_msglevel,
  96. .get_wol = asix_get_wol,
  97. .set_wol = asix_set_wol,
  98. .get_eeprom_len = asix_get_eeprom_len,
  99. .get_eeprom = asix_get_eeprom,
  100. .set_eeprom = asix_set_eeprom,
  101. .nway_reset = usbnet_nway_reset,
  102. .get_link_ksettings = usbnet_get_link_ksettings,
  103. .set_link_ksettings = usbnet_set_link_ksettings,
  104. };
  105. static void ax88172_set_multicast(struct net_device *net)
  106. {
  107. struct usbnet *dev = netdev_priv(net);
  108. struct asix_data *data = (struct asix_data *)&dev->data;
  109. u8 rx_ctl = 0x8c;
  110. if (net->flags & IFF_PROMISC) {
  111. rx_ctl |= 0x01;
  112. } else if (net->flags & IFF_ALLMULTI ||
  113. netdev_mc_count(net) > AX_MAX_MCAST) {
  114. rx_ctl |= 0x02;
  115. } else if (netdev_mc_empty(net)) {
  116. /* just broadcast and directed */
  117. } else {
  118. /* We use the 20 byte dev->data
  119. * for our 8 byte filter buffer
  120. * to avoid allocating memory that
  121. * is tricky to free later */
  122. struct netdev_hw_addr *ha;
  123. u32 crc_bits;
  124. memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE);
  125. /* Build the multicast hash filter. */
  126. netdev_for_each_mc_addr(ha, net) {
  127. crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26;
  128. data->multi_filter[crc_bits >> 3] |=
  129. 1 << (crc_bits & 7);
  130. }
  131. asix_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
  132. AX_MCAST_FILTER_SIZE, data->multi_filter);
  133. rx_ctl |= 0x10;
  134. }
  135. asix_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
  136. }
  137. static int ax88172_link_reset(struct usbnet *dev)
  138. {
  139. u8 mode;
  140. struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
  141. mii_check_media(&dev->mii, 1, 1);
  142. mii_ethtool_gset(&dev->mii, &ecmd);
  143. mode = AX88172_MEDIUM_DEFAULT;
  144. if (ecmd.duplex != DUPLEX_FULL)
  145. mode |= ~AX88172_MEDIUM_FD;
  146. netdev_dbg(dev->net, "ax88172_link_reset() speed: %u duplex: %d setting mode to 0x%04x\n",
  147. ethtool_cmd_speed(&ecmd), ecmd.duplex, mode);
  148. asix_write_medium_mode(dev, mode, 0);
  149. return 0;
  150. }
  151. static const struct net_device_ops ax88172_netdev_ops = {
  152. .ndo_open = usbnet_open,
  153. .ndo_stop = usbnet_stop,
  154. .ndo_start_xmit = usbnet_start_xmit,
  155. .ndo_tx_timeout = usbnet_tx_timeout,
  156. .ndo_change_mtu = usbnet_change_mtu,
  157. .ndo_get_stats64 = usbnet_get_stats64,
  158. .ndo_set_mac_address = eth_mac_addr,
  159. .ndo_validate_addr = eth_validate_addr,
  160. .ndo_do_ioctl = asix_ioctl,
  161. .ndo_set_rx_mode = ax88172_set_multicast,
  162. };
  163. static void asix_phy_reset(struct usbnet *dev, unsigned int reset_bits)
  164. {
  165. unsigned int timeout = 5000;
  166. asix_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, reset_bits);
  167. /* give phy_id a chance to process reset */
  168. udelay(500);
  169. /* See IEEE 802.3 "22.2.4.1.1 Reset": 500ms max */
  170. while (timeout--) {
  171. if (asix_mdio_read(dev->net, dev->mii.phy_id, MII_BMCR)
  172. & BMCR_RESET)
  173. udelay(100);
  174. else
  175. return;
  176. }
  177. netdev_err(dev->net, "BMCR_RESET timeout on phy_id %d\n",
  178. dev->mii.phy_id);
  179. }
  180. static int ax88172_bind(struct usbnet *dev, struct usb_interface *intf)
  181. {
  182. int ret = 0;
  183. u8 buf[ETH_ALEN] = {0};
  184. int i;
  185. unsigned long gpio_bits = dev->driver_info->data;
  186. usbnet_get_endpoints(dev,intf);
  187. /* Toggle the GPIOs in a manufacturer/model specific way */
  188. for (i = 2; i >= 0; i--) {
  189. ret = asix_write_cmd(dev, AX_CMD_WRITE_GPIOS,
  190. (gpio_bits >> (i * 8)) & 0xff, 0, 0, NULL, 0);
  191. if (ret < 0)
  192. goto out;
  193. msleep(5);
  194. }
  195. ret = asix_write_rx_ctl(dev, 0x80, 0);
  196. if (ret < 0)
  197. goto out;
  198. /* Get the MAC address */
  199. ret = asix_read_cmd(dev, AX88172_CMD_READ_NODE_ID,
  200. 0, 0, ETH_ALEN, buf, 0);
  201. if (ret < 0) {
  202. netdev_dbg(dev->net, "read AX_CMD_READ_NODE_ID failed: %d\n",
  203. ret);
  204. goto out;
  205. }
  206. asix_set_netdev_dev_addr(dev, buf);
  207. /* Initialize MII structure */
  208. dev->mii.dev = dev->net;
  209. dev->mii.mdio_read = asix_mdio_read;
  210. dev->mii.mdio_write = asix_mdio_write;
  211. dev->mii.phy_id_mask = 0x3f;
  212. dev->mii.reg_num_mask = 0x1f;
  213. dev->mii.phy_id = asix_get_phy_addr(dev);
  214. dev->net->netdev_ops = &ax88172_netdev_ops;
  215. dev->net->ethtool_ops = &ax88172_ethtool_ops;
  216. dev->net->needed_headroom = 4; /* cf asix_tx_fixup() */
  217. dev->net->needed_tailroom = 4; /* cf asix_tx_fixup() */
  218. asix_phy_reset(dev, BMCR_RESET);
  219. asix_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
  220. ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  221. mii_nway_restart(&dev->mii);
  222. return 0;
  223. out:
  224. return ret;
  225. }
  226. static const struct ethtool_ops ax88772_ethtool_ops = {
  227. .get_drvinfo = asix_get_drvinfo,
  228. .get_link = asix_get_link,
  229. .get_msglevel = usbnet_get_msglevel,
  230. .set_msglevel = usbnet_set_msglevel,
  231. .get_wol = asix_get_wol,
  232. .set_wol = asix_set_wol,
  233. .get_eeprom_len = asix_get_eeprom_len,
  234. .get_eeprom = asix_get_eeprom,
  235. .set_eeprom = asix_set_eeprom,
  236. .nway_reset = usbnet_nway_reset,
  237. .get_link_ksettings = usbnet_get_link_ksettings,
  238. .set_link_ksettings = usbnet_set_link_ksettings,
  239. };
  240. static int ax88772_link_reset(struct usbnet *dev)
  241. {
  242. u16 mode;
  243. struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
  244. mii_check_media(&dev->mii, 1, 1);
  245. mii_ethtool_gset(&dev->mii, &ecmd);
  246. mode = AX88772_MEDIUM_DEFAULT;
  247. if (ethtool_cmd_speed(&ecmd) != SPEED_100)
  248. mode &= ~AX_MEDIUM_PS;
  249. if (ecmd.duplex != DUPLEX_FULL)
  250. mode &= ~AX_MEDIUM_FD;
  251. netdev_dbg(dev->net, "ax88772_link_reset() speed: %u duplex: %d setting mode to 0x%04x\n",
  252. ethtool_cmd_speed(&ecmd), ecmd.duplex, mode);
  253. asix_write_medium_mode(dev, mode, 0);
  254. return 0;
  255. }
  256. static int ax88772_reset(struct usbnet *dev)
  257. {
  258. struct asix_data *data = (struct asix_data *)&dev->data;
  259. int ret;
  260. /* Rewrite MAC address */
  261. ether_addr_copy(data->mac_addr, dev->net->dev_addr);
  262. ret = asix_write_cmd(dev, AX_CMD_WRITE_NODE_ID, 0, 0,
  263. ETH_ALEN, data->mac_addr, 0);
  264. if (ret < 0)
  265. goto out;
  266. /* Set RX_CTL to default values with 2k buffer, and enable cactus */
  267. ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL, 0);
  268. if (ret < 0)
  269. goto out;
  270. ret = asix_write_medium_mode(dev, AX88772_MEDIUM_DEFAULT, 0);
  271. if (ret < 0)
  272. goto out;
  273. return 0;
  274. out:
  275. return ret;
  276. }
  277. static int ax88772_hw_reset(struct usbnet *dev, int in_pm)
  278. {
  279. struct asix_data *data = (struct asix_data *)&dev->data;
  280. int ret, embd_phy;
  281. u16 rx_ctl;
  282. ret = asix_write_gpio(dev, AX_GPIO_RSE | AX_GPIO_GPO_2 |
  283. AX_GPIO_GPO2EN, 5, in_pm);
  284. if (ret < 0)
  285. goto out;
  286. embd_phy = ((dev->mii.phy_id & 0x1f) == 0x10 ? 1 : 0);
  287. ret = asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT, embd_phy,
  288. 0, 0, NULL, in_pm);
  289. if (ret < 0) {
  290. netdev_dbg(dev->net, "Select PHY #1 failed: %d\n", ret);
  291. goto out;
  292. }
  293. if (embd_phy) {
  294. ret = asix_sw_reset(dev, AX_SWRESET_IPPD, in_pm);
  295. if (ret < 0)
  296. goto out;
  297. usleep_range(10000, 11000);
  298. ret = asix_sw_reset(dev, AX_SWRESET_CLEAR, in_pm);
  299. if (ret < 0)
  300. goto out;
  301. msleep(60);
  302. ret = asix_sw_reset(dev, AX_SWRESET_IPRL | AX_SWRESET_PRL,
  303. in_pm);
  304. if (ret < 0)
  305. goto out;
  306. } else {
  307. ret = asix_sw_reset(dev, AX_SWRESET_IPPD | AX_SWRESET_PRL,
  308. in_pm);
  309. if (ret < 0)
  310. goto out;
  311. }
  312. msleep(150);
  313. if (in_pm && (!asix_mdio_read_nopm(dev->net, dev->mii.phy_id,
  314. MII_PHYSID1))){
  315. ret = -EIO;
  316. goto out;
  317. }
  318. ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL, in_pm);
  319. if (ret < 0)
  320. goto out;
  321. ret = asix_write_medium_mode(dev, AX88772_MEDIUM_DEFAULT, in_pm);
  322. if (ret < 0)
  323. goto out;
  324. ret = asix_write_cmd(dev, AX_CMD_WRITE_IPG0,
  325. AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT,
  326. AX88772_IPG2_DEFAULT, 0, NULL, in_pm);
  327. if (ret < 0) {
  328. netdev_dbg(dev->net, "Write IPG,IPG1,IPG2 failed: %d\n", ret);
  329. goto out;
  330. }
  331. /* Rewrite MAC address */
  332. ether_addr_copy(data->mac_addr, dev->net->dev_addr);
  333. ret = asix_write_cmd(dev, AX_CMD_WRITE_NODE_ID, 0, 0,
  334. ETH_ALEN, data->mac_addr, in_pm);
  335. if (ret < 0)
  336. goto out;
  337. /* Set RX_CTL to default values with 2k buffer, and enable cactus */
  338. ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL, in_pm);
  339. if (ret < 0)
  340. goto out;
  341. rx_ctl = asix_read_rx_ctl(dev, in_pm);
  342. netdev_dbg(dev->net, "RX_CTL is 0x%04x after all initializations\n",
  343. rx_ctl);
  344. rx_ctl = asix_read_medium_status(dev, in_pm);
  345. netdev_dbg(dev->net,
  346. "Medium Status is 0x%04x after all initializations\n",
  347. rx_ctl);
  348. return 0;
  349. out:
  350. return ret;
  351. }
  352. static int ax88772a_hw_reset(struct usbnet *dev, int in_pm)
  353. {
  354. struct asix_data *data = (struct asix_data *)&dev->data;
  355. int ret, embd_phy;
  356. u16 rx_ctl, phy14h, phy15h, phy16h;
  357. u8 chipcode = 0;
  358. ret = asix_write_gpio(dev, AX_GPIO_RSE, 5, in_pm);
  359. if (ret < 0)
  360. goto out;
  361. embd_phy = ((dev->mii.phy_id & 0x1f) == 0x10 ? 1 : 0);
  362. ret = asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT, embd_phy |
  363. AX_PHYSEL_SSEN, 0, 0, NULL, in_pm);
  364. if (ret < 0) {
  365. netdev_dbg(dev->net, "Select PHY #1 failed: %d\n", ret);
  366. goto out;
  367. }
  368. usleep_range(10000, 11000);
  369. ret = asix_sw_reset(dev, AX_SWRESET_IPPD | AX_SWRESET_IPRL, in_pm);
  370. if (ret < 0)
  371. goto out;
  372. usleep_range(10000, 11000);
  373. ret = asix_sw_reset(dev, AX_SWRESET_IPRL, in_pm);
  374. if (ret < 0)
  375. goto out;
  376. msleep(160);
  377. ret = asix_sw_reset(dev, AX_SWRESET_CLEAR, in_pm);
  378. if (ret < 0)
  379. goto out;
  380. ret = asix_sw_reset(dev, AX_SWRESET_IPRL, in_pm);
  381. if (ret < 0)
  382. goto out;
  383. msleep(200);
  384. if (in_pm && (!asix_mdio_read_nopm(dev->net, dev->mii.phy_id,
  385. MII_PHYSID1))) {
  386. ret = -1;
  387. goto out;
  388. }
  389. ret = asix_read_cmd(dev, AX_CMD_STATMNGSTS_REG, 0,
  390. 0, 1, &chipcode, in_pm);
  391. if (ret < 0)
  392. goto out;
  393. if ((chipcode & AX_CHIPCODE_MASK) == AX_AX88772B_CHIPCODE) {
  394. ret = asix_write_cmd(dev, AX_QCTCTRL, 0x8000, 0x8001,
  395. 0, NULL, in_pm);
  396. if (ret < 0) {
  397. netdev_dbg(dev->net, "Write BQ setting failed: %d\n",
  398. ret);
  399. goto out;
  400. }
  401. } else if ((chipcode & AX_CHIPCODE_MASK) == AX_AX88772A_CHIPCODE) {
  402. /* Check if the PHY registers have default settings */
  403. phy14h = asix_mdio_read_nopm(dev->net, dev->mii.phy_id,
  404. AX88772A_PHY14H);
  405. phy15h = asix_mdio_read_nopm(dev->net, dev->mii.phy_id,
  406. AX88772A_PHY15H);
  407. phy16h = asix_mdio_read_nopm(dev->net, dev->mii.phy_id,
  408. AX88772A_PHY16H);
  409. netdev_dbg(dev->net,
  410. "772a_hw_reset: MR20=0x%x MR21=0x%x MR22=0x%x\n",
  411. phy14h, phy15h, phy16h);
  412. /* Restore PHY registers default setting if not */
  413. if (phy14h != AX88772A_PHY14H_DEFAULT)
  414. asix_mdio_write_nopm(dev->net, dev->mii.phy_id,
  415. AX88772A_PHY14H,
  416. AX88772A_PHY14H_DEFAULT);
  417. if (phy15h != AX88772A_PHY15H_DEFAULT)
  418. asix_mdio_write_nopm(dev->net, dev->mii.phy_id,
  419. AX88772A_PHY15H,
  420. AX88772A_PHY15H_DEFAULT);
  421. if (phy16h != AX88772A_PHY16H_DEFAULT)
  422. asix_mdio_write_nopm(dev->net, dev->mii.phy_id,
  423. AX88772A_PHY16H,
  424. AX88772A_PHY16H_DEFAULT);
  425. }
  426. ret = asix_write_cmd(dev, AX_CMD_WRITE_IPG0,
  427. AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT,
  428. AX88772_IPG2_DEFAULT, 0, NULL, in_pm);
  429. if (ret < 0) {
  430. netdev_dbg(dev->net, "Write IPG,IPG1,IPG2 failed: %d\n", ret);
  431. goto out;
  432. }
  433. /* Rewrite MAC address */
  434. memcpy(data->mac_addr, dev->net->dev_addr, ETH_ALEN);
  435. ret = asix_write_cmd(dev, AX_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
  436. data->mac_addr, in_pm);
  437. if (ret < 0)
  438. goto out;
  439. /* Set RX_CTL to default values with 2k buffer, and enable cactus */
  440. ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL, in_pm);
  441. if (ret < 0)
  442. goto out;
  443. ret = asix_write_medium_mode(dev, AX88772_MEDIUM_DEFAULT, in_pm);
  444. if (ret < 0)
  445. return ret;
  446. /* Set RX_CTL to default values with 2k buffer, and enable cactus */
  447. ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL, in_pm);
  448. if (ret < 0)
  449. goto out;
  450. rx_ctl = asix_read_rx_ctl(dev, in_pm);
  451. netdev_dbg(dev->net, "RX_CTL is 0x%04x after all initializations\n",
  452. rx_ctl);
  453. rx_ctl = asix_read_medium_status(dev, in_pm);
  454. netdev_dbg(dev->net,
  455. "Medium Status is 0x%04x after all initializations\n",
  456. rx_ctl);
  457. return 0;
  458. out:
  459. return ret;
  460. }
  461. static const struct net_device_ops ax88772_netdev_ops = {
  462. .ndo_open = usbnet_open,
  463. .ndo_stop = usbnet_stop,
  464. .ndo_start_xmit = usbnet_start_xmit,
  465. .ndo_tx_timeout = usbnet_tx_timeout,
  466. .ndo_change_mtu = usbnet_change_mtu,
  467. .ndo_get_stats64 = usbnet_get_stats64,
  468. .ndo_set_mac_address = asix_set_mac_address,
  469. .ndo_validate_addr = eth_validate_addr,
  470. .ndo_do_ioctl = asix_ioctl,
  471. .ndo_set_rx_mode = asix_set_multicast,
  472. };
  473. static void ax88772_suspend(struct usbnet *dev)
  474. {
  475. struct asix_common_private *priv = dev->driver_priv;
  476. u16 medium;
  477. /* Stop MAC operation */
  478. medium = asix_read_medium_status(dev, 1);
  479. medium &= ~AX_MEDIUM_RE;
  480. asix_write_medium_mode(dev, medium, 1);
  481. netdev_dbg(dev->net, "ax88772_suspend: medium=0x%04x\n",
  482. asix_read_medium_status(dev, 1));
  483. /* Preserve BMCR for restoring */
  484. priv->presvd_phy_bmcr =
  485. asix_mdio_read_nopm(dev->net, dev->mii.phy_id, MII_BMCR);
  486. /* Preserve ANAR for restoring */
  487. priv->presvd_phy_advertise =
  488. asix_mdio_read_nopm(dev->net, dev->mii.phy_id, MII_ADVERTISE);
  489. }
  490. static int asix_suspend(struct usb_interface *intf, pm_message_t message)
  491. {
  492. struct usbnet *dev = usb_get_intfdata(intf);
  493. struct asix_common_private *priv = dev->driver_priv;
  494. if (priv && priv->suspend)
  495. priv->suspend(dev);
  496. return usbnet_suspend(intf, message);
  497. }
  498. static void ax88772_restore_phy(struct usbnet *dev)
  499. {
  500. struct asix_common_private *priv = dev->driver_priv;
  501. if (priv->presvd_phy_advertise) {
  502. /* Restore Advertisement control reg */
  503. asix_mdio_write_nopm(dev->net, dev->mii.phy_id, MII_ADVERTISE,
  504. priv->presvd_phy_advertise);
  505. /* Restore BMCR */
  506. if (priv->presvd_phy_bmcr & BMCR_ANENABLE)
  507. priv->presvd_phy_bmcr |= BMCR_ANRESTART;
  508. asix_mdio_write_nopm(dev->net, dev->mii.phy_id, MII_BMCR,
  509. priv->presvd_phy_bmcr);
  510. priv->presvd_phy_advertise = 0;
  511. priv->presvd_phy_bmcr = 0;
  512. }
  513. }
  514. static void ax88772_resume(struct usbnet *dev)
  515. {
  516. int i;
  517. for (i = 0; i < 3; i++)
  518. if (!ax88772_hw_reset(dev, 1))
  519. break;
  520. ax88772_restore_phy(dev);
  521. }
  522. static void ax88772a_resume(struct usbnet *dev)
  523. {
  524. int i;
  525. for (i = 0; i < 3; i++) {
  526. if (!ax88772a_hw_reset(dev, 1))
  527. break;
  528. }
  529. ax88772_restore_phy(dev);
  530. }
  531. static int asix_resume(struct usb_interface *intf)
  532. {
  533. struct usbnet *dev = usb_get_intfdata(intf);
  534. struct asix_common_private *priv = dev->driver_priv;
  535. if (priv && priv->resume)
  536. priv->resume(dev);
  537. return usbnet_resume(intf);
  538. }
  539. static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
  540. {
  541. int ret, i;
  542. u8 buf[ETH_ALEN] = {0}, chipcode = 0;
  543. u32 phyid;
  544. struct asix_common_private *priv;
  545. usbnet_get_endpoints(dev, intf);
  546. /* Maybe the boot loader passed the MAC address via device tree */
  547. if (!eth_platform_get_mac_address(&dev->udev->dev, buf)) {
  548. netif_dbg(dev, ifup, dev->net,
  549. "MAC address read from device tree");
  550. } else {
  551. /* Try getting the MAC address from EEPROM */
  552. if (dev->driver_info->data & FLAG_EEPROM_MAC) {
  553. for (i = 0; i < (ETH_ALEN >> 1); i++) {
  554. ret = asix_read_cmd(dev, AX_CMD_READ_EEPROM,
  555. 0x04 + i, 0, 2, buf + i * 2,
  556. 0);
  557. if (ret < 0)
  558. break;
  559. }
  560. } else {
  561. ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID,
  562. 0, 0, ETH_ALEN, buf, 0);
  563. }
  564. if (ret < 0) {
  565. netdev_dbg(dev->net, "Failed to read MAC address: %d\n",
  566. ret);
  567. return ret;
  568. }
  569. }
  570. asix_set_netdev_dev_addr(dev, buf);
  571. /* Initialize MII structure */
  572. dev->mii.dev = dev->net;
  573. dev->mii.mdio_read = asix_mdio_read;
  574. dev->mii.mdio_write = asix_mdio_write;
  575. dev->mii.phy_id_mask = 0x1f;
  576. dev->mii.reg_num_mask = 0x1f;
  577. dev->mii.phy_id = asix_get_phy_addr(dev);
  578. dev->net->netdev_ops = &ax88772_netdev_ops;
  579. dev->net->ethtool_ops = &ax88772_ethtool_ops;
  580. dev->net->needed_headroom = 4; /* cf asix_tx_fixup() */
  581. dev->net->needed_tailroom = 4; /* cf asix_tx_fixup() */
  582. asix_read_cmd(dev, AX_CMD_STATMNGSTS_REG, 0, 0, 1, &chipcode, 0);
  583. chipcode &= AX_CHIPCODE_MASK;
  584. ret = (chipcode == AX_AX88772_CHIPCODE) ? ax88772_hw_reset(dev, 0) :
  585. ax88772a_hw_reset(dev, 0);
  586. if (ret < 0) {
  587. netdev_dbg(dev->net, "Failed to reset AX88772: %d\n", ret);
  588. return ret;
  589. }
  590. /* Read PHYID register *AFTER* the PHY was reset properly */
  591. phyid = asix_get_phyid(dev);
  592. netdev_dbg(dev->net, "PHYID=0x%08x\n", phyid);
  593. /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
  594. if (dev->driver_info->flags & FLAG_FRAMING_AX) {
  595. /* hard_mtu is still the default - the device does not support
  596. jumbo eth frames */
  597. dev->rx_urb_size = 2048;
  598. }
  599. dev->driver_priv = kzalloc(sizeof(struct asix_common_private), GFP_KERNEL);
  600. if (!dev->driver_priv)
  601. return -ENOMEM;
  602. priv = dev->driver_priv;
  603. priv->presvd_phy_bmcr = 0;
  604. priv->presvd_phy_advertise = 0;
  605. if (chipcode == AX_AX88772_CHIPCODE) {
  606. priv->resume = ax88772_resume;
  607. priv->suspend = ax88772_suspend;
  608. } else {
  609. priv->resume = ax88772a_resume;
  610. priv->suspend = ax88772_suspend;
  611. }
  612. return 0;
  613. }
  614. static void ax88772_unbind(struct usbnet *dev, struct usb_interface *intf)
  615. {
  616. asix_rx_fixup_common_free(dev->driver_priv);
  617. kfree(dev->driver_priv);
  618. }
  619. static const struct ethtool_ops ax88178_ethtool_ops = {
  620. .get_drvinfo = asix_get_drvinfo,
  621. .get_link = asix_get_link,
  622. .get_msglevel = usbnet_get_msglevel,
  623. .set_msglevel = usbnet_set_msglevel,
  624. .get_wol = asix_get_wol,
  625. .set_wol = asix_set_wol,
  626. .get_eeprom_len = asix_get_eeprom_len,
  627. .get_eeprom = asix_get_eeprom,
  628. .set_eeprom = asix_set_eeprom,
  629. .nway_reset = usbnet_nway_reset,
  630. .get_link_ksettings = usbnet_get_link_ksettings,
  631. .set_link_ksettings = usbnet_set_link_ksettings,
  632. };
  633. static int marvell_phy_init(struct usbnet *dev)
  634. {
  635. struct asix_data *data = (struct asix_data *)&dev->data;
  636. u16 reg;
  637. netdev_dbg(dev->net, "marvell_phy_init()\n");
  638. reg = asix_mdio_read(dev->net, dev->mii.phy_id, MII_MARVELL_STATUS);
  639. netdev_dbg(dev->net, "MII_MARVELL_STATUS = 0x%04x\n", reg);
  640. asix_mdio_write(dev->net, dev->mii.phy_id, MII_MARVELL_CTRL,
  641. MARVELL_CTRL_RXDELAY | MARVELL_CTRL_TXDELAY);
  642. if (data->ledmode) {
  643. reg = asix_mdio_read(dev->net, dev->mii.phy_id,
  644. MII_MARVELL_LED_CTRL);
  645. netdev_dbg(dev->net, "MII_MARVELL_LED_CTRL (1) = 0x%04x\n", reg);
  646. reg &= 0xf8ff;
  647. reg |= (1 + 0x0100);
  648. asix_mdio_write(dev->net, dev->mii.phy_id,
  649. MII_MARVELL_LED_CTRL, reg);
  650. reg = asix_mdio_read(dev->net, dev->mii.phy_id,
  651. MII_MARVELL_LED_CTRL);
  652. netdev_dbg(dev->net, "MII_MARVELL_LED_CTRL (2) = 0x%04x\n", reg);
  653. reg &= 0xfc0f;
  654. }
  655. return 0;
  656. }
  657. static int rtl8211cl_phy_init(struct usbnet *dev)
  658. {
  659. struct asix_data *data = (struct asix_data *)&dev->data;
  660. netdev_dbg(dev->net, "rtl8211cl_phy_init()\n");
  661. asix_mdio_write (dev->net, dev->mii.phy_id, 0x1f, 0x0005);
  662. asix_mdio_write (dev->net, dev->mii.phy_id, 0x0c, 0);
  663. asix_mdio_write (dev->net, dev->mii.phy_id, 0x01,
  664. asix_mdio_read (dev->net, dev->mii.phy_id, 0x01) | 0x0080);
  665. asix_mdio_write (dev->net, dev->mii.phy_id, 0x1f, 0);
  666. if (data->ledmode == 12) {
  667. asix_mdio_write (dev->net, dev->mii.phy_id, 0x1f, 0x0002);
  668. asix_mdio_write (dev->net, dev->mii.phy_id, 0x1a, 0x00cb);
  669. asix_mdio_write (dev->net, dev->mii.phy_id, 0x1f, 0);
  670. }
  671. return 0;
  672. }
  673. static int marvell_led_status(struct usbnet *dev, u16 speed)
  674. {
  675. u16 reg = asix_mdio_read(dev->net, dev->mii.phy_id, MARVELL_LED_MANUAL);
  676. netdev_dbg(dev->net, "marvell_led_status() read 0x%04x\n", reg);
  677. /* Clear out the center LED bits - 0x03F0 */
  678. reg &= 0xfc0f;
  679. switch (speed) {
  680. case SPEED_1000:
  681. reg |= 0x03e0;
  682. break;
  683. case SPEED_100:
  684. reg |= 0x03b0;
  685. break;
  686. default:
  687. reg |= 0x02f0;
  688. }
  689. netdev_dbg(dev->net, "marvell_led_status() writing 0x%04x\n", reg);
  690. asix_mdio_write(dev->net, dev->mii.phy_id, MARVELL_LED_MANUAL, reg);
  691. return 0;
  692. }
  693. static int ax88178_reset(struct usbnet *dev)
  694. {
  695. struct asix_data *data = (struct asix_data *)&dev->data;
  696. int ret;
  697. __le16 eeprom;
  698. u8 status;
  699. int gpio0 = 0;
  700. u32 phyid;
  701. asix_read_cmd(dev, AX_CMD_READ_GPIOS, 0, 0, 1, &status, 0);
  702. netdev_dbg(dev->net, "GPIO Status: 0x%04x\n", status);
  703. asix_write_cmd(dev, AX_CMD_WRITE_ENABLE, 0, 0, 0, NULL, 0);
  704. asix_read_cmd(dev, AX_CMD_READ_EEPROM, 0x0017, 0, 2, &eeprom, 0);
  705. asix_write_cmd(dev, AX_CMD_WRITE_DISABLE, 0, 0, 0, NULL, 0);
  706. netdev_dbg(dev->net, "EEPROM index 0x17 is 0x%04x\n", eeprom);
  707. if (eeprom == cpu_to_le16(0xffff)) {
  708. data->phymode = PHY_MODE_MARVELL;
  709. data->ledmode = 0;
  710. gpio0 = 1;
  711. } else {
  712. data->phymode = le16_to_cpu(eeprom) & 0x7F;
  713. data->ledmode = le16_to_cpu(eeprom) >> 8;
  714. gpio0 = (le16_to_cpu(eeprom) & 0x80) ? 0 : 1;
  715. }
  716. netdev_dbg(dev->net, "GPIO0: %d, PhyMode: %d\n", gpio0, data->phymode);
  717. /* Power up external GigaPHY through AX88178 GPIO pin */
  718. asix_write_gpio(dev, AX_GPIO_RSE | AX_GPIO_GPO_1 |
  719. AX_GPIO_GPO1EN, 40, 0);
  720. if ((le16_to_cpu(eeprom) >> 8) != 1) {
  721. asix_write_gpio(dev, 0x003c, 30, 0);
  722. asix_write_gpio(dev, 0x001c, 300, 0);
  723. asix_write_gpio(dev, 0x003c, 30, 0);
  724. } else {
  725. netdev_dbg(dev->net, "gpio phymode == 1 path\n");
  726. asix_write_gpio(dev, AX_GPIO_GPO1EN, 30, 0);
  727. asix_write_gpio(dev, AX_GPIO_GPO1EN | AX_GPIO_GPO_1, 30, 0);
  728. }
  729. /* Read PHYID register *AFTER* powering up PHY */
  730. phyid = asix_get_phyid(dev);
  731. netdev_dbg(dev->net, "PHYID=0x%08x\n", phyid);
  732. /* Set AX88178 to enable MII/GMII/RGMII interface for external PHY */
  733. asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT, 0, 0, 0, NULL, 0);
  734. asix_sw_reset(dev, 0, 0);
  735. msleep(150);
  736. asix_sw_reset(dev, AX_SWRESET_PRL | AX_SWRESET_IPPD, 0);
  737. msleep(150);
  738. asix_write_rx_ctl(dev, 0, 0);
  739. if (data->phymode == PHY_MODE_MARVELL) {
  740. marvell_phy_init(dev);
  741. msleep(60);
  742. } else if (data->phymode == PHY_MODE_RTL8211CL)
  743. rtl8211cl_phy_init(dev);
  744. asix_phy_reset(dev, BMCR_RESET | BMCR_ANENABLE);
  745. asix_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
  746. ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  747. asix_mdio_write(dev->net, dev->mii.phy_id, MII_CTRL1000,
  748. ADVERTISE_1000FULL);
  749. asix_write_medium_mode(dev, AX88178_MEDIUM_DEFAULT, 0);
  750. mii_nway_restart(&dev->mii);
  751. /* Rewrite MAC address */
  752. memcpy(data->mac_addr, dev->net->dev_addr, ETH_ALEN);
  753. ret = asix_write_cmd(dev, AX_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
  754. data->mac_addr, 0);
  755. if (ret < 0)
  756. return ret;
  757. ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL, 0);
  758. if (ret < 0)
  759. return ret;
  760. return 0;
  761. }
  762. static int ax88178_link_reset(struct usbnet *dev)
  763. {
  764. u16 mode;
  765. struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
  766. struct asix_data *data = (struct asix_data *)&dev->data;
  767. u32 speed;
  768. netdev_dbg(dev->net, "ax88178_link_reset()\n");
  769. mii_check_media(&dev->mii, 1, 1);
  770. mii_ethtool_gset(&dev->mii, &ecmd);
  771. mode = AX88178_MEDIUM_DEFAULT;
  772. speed = ethtool_cmd_speed(&ecmd);
  773. if (speed == SPEED_1000)
  774. mode |= AX_MEDIUM_GM;
  775. else if (speed == SPEED_100)
  776. mode |= AX_MEDIUM_PS;
  777. else
  778. mode &= ~(AX_MEDIUM_PS | AX_MEDIUM_GM);
  779. mode |= AX_MEDIUM_ENCK;
  780. if (ecmd.duplex == DUPLEX_FULL)
  781. mode |= AX_MEDIUM_FD;
  782. else
  783. mode &= ~AX_MEDIUM_FD;
  784. netdev_dbg(dev->net, "ax88178_link_reset() speed: %u duplex: %d setting mode to 0x%04x\n",
  785. speed, ecmd.duplex, mode);
  786. asix_write_medium_mode(dev, mode, 0);
  787. if (data->phymode == PHY_MODE_MARVELL && data->ledmode)
  788. marvell_led_status(dev, speed);
  789. return 0;
  790. }
  791. static void ax88178_set_mfb(struct usbnet *dev)
  792. {
  793. u16 mfb = AX_RX_CTL_MFB_16384;
  794. u16 rxctl;
  795. u16 medium;
  796. int old_rx_urb_size = dev->rx_urb_size;
  797. if (dev->hard_mtu < 2048) {
  798. dev->rx_urb_size = 2048;
  799. mfb = AX_RX_CTL_MFB_2048;
  800. } else if (dev->hard_mtu < 4096) {
  801. dev->rx_urb_size = 4096;
  802. mfb = AX_RX_CTL_MFB_4096;
  803. } else if (dev->hard_mtu < 8192) {
  804. dev->rx_urb_size = 8192;
  805. mfb = AX_RX_CTL_MFB_8192;
  806. } else if (dev->hard_mtu < 16384) {
  807. dev->rx_urb_size = 16384;
  808. mfb = AX_RX_CTL_MFB_16384;
  809. }
  810. rxctl = asix_read_rx_ctl(dev, 0);
  811. asix_write_rx_ctl(dev, (rxctl & ~AX_RX_CTL_MFB_16384) | mfb, 0);
  812. medium = asix_read_medium_status(dev, 0);
  813. if (dev->net->mtu > 1500)
  814. medium |= AX_MEDIUM_JFE;
  815. else
  816. medium &= ~AX_MEDIUM_JFE;
  817. asix_write_medium_mode(dev, medium, 0);
  818. if (dev->rx_urb_size > old_rx_urb_size)
  819. usbnet_unlink_rx_urbs(dev);
  820. }
  821. static int ax88178_change_mtu(struct net_device *net, int new_mtu)
  822. {
  823. struct usbnet *dev = netdev_priv(net);
  824. int ll_mtu = new_mtu + net->hard_header_len + 4;
  825. netdev_dbg(dev->net, "ax88178_change_mtu() new_mtu=%d\n", new_mtu);
  826. if ((ll_mtu % dev->maxpacket) == 0)
  827. return -EDOM;
  828. net->mtu = new_mtu;
  829. dev->hard_mtu = net->mtu + net->hard_header_len;
  830. ax88178_set_mfb(dev);
  831. /* max qlen depend on hard_mtu and rx_urb_size */
  832. usbnet_update_max_qlen(dev);
  833. return 0;
  834. }
  835. static const struct net_device_ops ax88178_netdev_ops = {
  836. .ndo_open = usbnet_open,
  837. .ndo_stop = usbnet_stop,
  838. .ndo_start_xmit = usbnet_start_xmit,
  839. .ndo_tx_timeout = usbnet_tx_timeout,
  840. .ndo_get_stats64 = usbnet_get_stats64,
  841. .ndo_set_mac_address = asix_set_mac_address,
  842. .ndo_validate_addr = eth_validate_addr,
  843. .ndo_set_rx_mode = asix_set_multicast,
  844. .ndo_do_ioctl = asix_ioctl,
  845. .ndo_change_mtu = ax88178_change_mtu,
  846. };
  847. static int ax88178_bind(struct usbnet *dev, struct usb_interface *intf)
  848. {
  849. int ret;
  850. u8 buf[ETH_ALEN] = {0};
  851. usbnet_get_endpoints(dev,intf);
  852. /* Get the MAC address */
  853. ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf, 0);
  854. if (ret < 0) {
  855. netdev_dbg(dev->net, "Failed to read MAC address: %d\n", ret);
  856. return ret;
  857. }
  858. asix_set_netdev_dev_addr(dev, buf);
  859. /* Initialize MII structure */
  860. dev->mii.dev = dev->net;
  861. dev->mii.mdio_read = asix_mdio_read;
  862. dev->mii.mdio_write = asix_mdio_write;
  863. dev->mii.phy_id_mask = 0x1f;
  864. dev->mii.reg_num_mask = 0xff;
  865. dev->mii.supports_gmii = 1;
  866. dev->mii.phy_id = asix_get_phy_addr(dev);
  867. dev->net->netdev_ops = &ax88178_netdev_ops;
  868. dev->net->ethtool_ops = &ax88178_ethtool_ops;
  869. dev->net->max_mtu = 16384 - (dev->net->hard_header_len + 4);
  870. /* Blink LEDS so users know driver saw dongle */
  871. asix_sw_reset(dev, 0, 0);
  872. msleep(150);
  873. asix_sw_reset(dev, AX_SWRESET_PRL | AX_SWRESET_IPPD, 0);
  874. msleep(150);
  875. /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
  876. if (dev->driver_info->flags & FLAG_FRAMING_AX) {
  877. /* hard_mtu is still the default - the device does not support
  878. jumbo eth frames */
  879. dev->rx_urb_size = 2048;
  880. }
  881. dev->driver_priv = kzalloc(sizeof(struct asix_common_private), GFP_KERNEL);
  882. if (!dev->driver_priv)
  883. return -ENOMEM;
  884. return 0;
  885. }
  886. static const struct driver_info ax8817x_info = {
  887. .description = "ASIX AX8817x USB 2.0 Ethernet",
  888. .bind = ax88172_bind,
  889. .status = asix_status,
  890. .link_reset = ax88172_link_reset,
  891. .reset = ax88172_link_reset,
  892. .flags = FLAG_ETHER | FLAG_LINK_INTR,
  893. .data = 0x00130103,
  894. };
  895. static const struct driver_info dlink_dub_e100_info = {
  896. .description = "DLink DUB-E100 USB Ethernet",
  897. .bind = ax88172_bind,
  898. .status = asix_status,
  899. .link_reset = ax88172_link_reset,
  900. .reset = ax88172_link_reset,
  901. .flags = FLAG_ETHER | FLAG_LINK_INTR,
  902. .data = 0x009f9d9f,
  903. };
  904. static const struct driver_info netgear_fa120_info = {
  905. .description = "Netgear FA-120 USB Ethernet",
  906. .bind = ax88172_bind,
  907. .status = asix_status,
  908. .link_reset = ax88172_link_reset,
  909. .reset = ax88172_link_reset,
  910. .flags = FLAG_ETHER | FLAG_LINK_INTR,
  911. .data = 0x00130103,
  912. };
  913. static const struct driver_info hawking_uf200_info = {
  914. .description = "Hawking UF200 USB Ethernet",
  915. .bind = ax88172_bind,
  916. .status = asix_status,
  917. .link_reset = ax88172_link_reset,
  918. .reset = ax88172_link_reset,
  919. .flags = FLAG_ETHER | FLAG_LINK_INTR,
  920. .data = 0x001f1d1f,
  921. };
  922. static const struct driver_info ax88772_info = {
  923. .description = "ASIX AX88772 USB 2.0 Ethernet",
  924. .bind = ax88772_bind,
  925. .unbind = ax88772_unbind,
  926. .status = asix_status,
  927. .link_reset = ax88772_link_reset,
  928. .reset = ax88772_reset,
  929. .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR | FLAG_MULTI_PACKET,
  930. .rx_fixup = asix_rx_fixup_common,
  931. .tx_fixup = asix_tx_fixup,
  932. };
  933. static const struct driver_info ax88772b_info = {
  934. .description = "ASIX AX88772B USB 2.0 Ethernet",
  935. .bind = ax88772_bind,
  936. .unbind = ax88772_unbind,
  937. .status = asix_status,
  938. .link_reset = ax88772_link_reset,
  939. .reset = ax88772_reset,
  940. .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR |
  941. FLAG_MULTI_PACKET,
  942. .rx_fixup = asix_rx_fixup_common,
  943. .tx_fixup = asix_tx_fixup,
  944. .data = FLAG_EEPROM_MAC,
  945. };
  946. static const struct driver_info ax88178_info = {
  947. .description = "ASIX AX88178 USB 2.0 Ethernet",
  948. .bind = ax88178_bind,
  949. .unbind = ax88772_unbind,
  950. .status = asix_status,
  951. .link_reset = ax88178_link_reset,
  952. .reset = ax88178_reset,
  953. .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR |
  954. FLAG_MULTI_PACKET,
  955. .rx_fixup = asix_rx_fixup_common,
  956. .tx_fixup = asix_tx_fixup,
  957. };
  958. /*
  959. * USBLINK 20F9 "USB 2.0 LAN" USB ethernet adapter, typically found in
  960. * no-name packaging.
  961. * USB device strings are:
  962. * 1: Manufacturer: USBLINK
  963. * 2: Product: HG20F9 USB2.0
  964. * 3: Serial: 000003
  965. * Appears to be compatible with Asix 88772B.
  966. */
  967. static const struct driver_info hg20f9_info = {
  968. .description = "HG20F9 USB 2.0 Ethernet",
  969. .bind = ax88772_bind,
  970. .unbind = ax88772_unbind,
  971. .status = asix_status,
  972. .link_reset = ax88772_link_reset,
  973. .reset = ax88772_reset,
  974. .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR |
  975. FLAG_MULTI_PACKET,
  976. .rx_fixup = asix_rx_fixup_common,
  977. .tx_fixup = asix_tx_fixup,
  978. .data = FLAG_EEPROM_MAC,
  979. };
  980. static const struct usb_device_id products [] = {
  981. {
  982. // Linksys USB200M
  983. USB_DEVICE (0x077b, 0x2226),
  984. .driver_info = (unsigned long) &ax8817x_info,
  985. }, {
  986. // Netgear FA120
  987. USB_DEVICE (0x0846, 0x1040),
  988. .driver_info = (unsigned long) &netgear_fa120_info,
  989. }, {
  990. // DLink DUB-E100
  991. USB_DEVICE (0x2001, 0x1a00),
  992. .driver_info = (unsigned long) &dlink_dub_e100_info,
  993. }, {
  994. // Intellinet, ST Lab USB Ethernet
  995. USB_DEVICE (0x0b95, 0x1720),
  996. .driver_info = (unsigned long) &ax8817x_info,
  997. }, {
  998. // Hawking UF200, TrendNet TU2-ET100
  999. USB_DEVICE (0x07b8, 0x420a),
  1000. .driver_info = (unsigned long) &hawking_uf200_info,
  1001. }, {
  1002. // Billionton Systems, USB2AR
  1003. USB_DEVICE (0x08dd, 0x90ff),
  1004. .driver_info = (unsigned long) &ax8817x_info,
  1005. }, {
  1006. // Billionton Systems, GUSB2AM-1G-B
  1007. USB_DEVICE(0x08dd, 0x0114),
  1008. .driver_info = (unsigned long) &ax88178_info,
  1009. }, {
  1010. // ATEN UC210T
  1011. USB_DEVICE (0x0557, 0x2009),
  1012. .driver_info = (unsigned long) &ax8817x_info,
  1013. }, {
  1014. // Buffalo LUA-U2-KTX
  1015. USB_DEVICE (0x0411, 0x003d),
  1016. .driver_info = (unsigned long) &ax8817x_info,
  1017. }, {
  1018. // Buffalo LUA-U2-GT 10/100/1000
  1019. USB_DEVICE (0x0411, 0x006e),
  1020. .driver_info = (unsigned long) &ax88178_info,
  1021. }, {
  1022. // Sitecom LN-029 "USB 2.0 10/100 Ethernet adapter"
  1023. USB_DEVICE (0x6189, 0x182d),
  1024. .driver_info = (unsigned long) &ax8817x_info,
  1025. }, {
  1026. // Sitecom LN-031 "USB 2.0 10/100/1000 Ethernet adapter"
  1027. USB_DEVICE (0x0df6, 0x0056),
  1028. .driver_info = (unsigned long) &ax88178_info,
  1029. }, {
  1030. // Sitecom LN-028 "USB 2.0 10/100/1000 Ethernet adapter"
  1031. USB_DEVICE (0x0df6, 0x061c),
  1032. .driver_info = (unsigned long) &ax88178_info,
  1033. }, {
  1034. // corega FEther USB2-TX
  1035. USB_DEVICE (0x07aa, 0x0017),
  1036. .driver_info = (unsigned long) &ax8817x_info,
  1037. }, {
  1038. // Surecom EP-1427X-2
  1039. USB_DEVICE (0x1189, 0x0893),
  1040. .driver_info = (unsigned long) &ax8817x_info,
  1041. }, {
  1042. // goodway corp usb gwusb2e
  1043. USB_DEVICE (0x1631, 0x6200),
  1044. .driver_info = (unsigned long) &ax8817x_info,
  1045. }, {
  1046. // JVC MP-PRX1 Port Replicator
  1047. USB_DEVICE (0x04f1, 0x3008),
  1048. .driver_info = (unsigned long) &ax8817x_info,
  1049. }, {
  1050. // Lenovo U2L100P 10/100
  1051. USB_DEVICE (0x17ef, 0x7203),
  1052. .driver_info = (unsigned long)&ax88772b_info,
  1053. }, {
  1054. // ASIX AX88772B 10/100
  1055. USB_DEVICE (0x0b95, 0x772b),
  1056. .driver_info = (unsigned long) &ax88772b_info,
  1057. }, {
  1058. // ASIX AX88772 10/100
  1059. USB_DEVICE (0x0b95, 0x7720),
  1060. .driver_info = (unsigned long) &ax88772_info,
  1061. }, {
  1062. // ASIX AX88178 10/100/1000
  1063. USB_DEVICE (0x0b95, 0x1780),
  1064. .driver_info = (unsigned long) &ax88178_info,
  1065. }, {
  1066. // Logitec LAN-GTJ/U2A
  1067. USB_DEVICE (0x0789, 0x0160),
  1068. .driver_info = (unsigned long) &ax88178_info,
  1069. }, {
  1070. // Linksys USB200M Rev 2
  1071. USB_DEVICE (0x13b1, 0x0018),
  1072. .driver_info = (unsigned long) &ax88772_info,
  1073. }, {
  1074. // 0Q0 cable ethernet
  1075. USB_DEVICE (0x1557, 0x7720),
  1076. .driver_info = (unsigned long) &ax88772_info,
  1077. }, {
  1078. // DLink DUB-E100 H/W Ver B1
  1079. USB_DEVICE (0x07d1, 0x3c05),
  1080. .driver_info = (unsigned long) &ax88772_info,
  1081. }, {
  1082. // DLink DUB-E100 H/W Ver B1 Alternate
  1083. USB_DEVICE (0x2001, 0x3c05),
  1084. .driver_info = (unsigned long) &ax88772_info,
  1085. }, {
  1086. // DLink DUB-E100 H/W Ver C1
  1087. USB_DEVICE (0x2001, 0x1a02),
  1088. .driver_info = (unsigned long) &ax88772_info,
  1089. }, {
  1090. // Linksys USB1000
  1091. USB_DEVICE (0x1737, 0x0039),
  1092. .driver_info = (unsigned long) &ax88178_info,
  1093. }, {
  1094. // IO-DATA ETG-US2
  1095. USB_DEVICE (0x04bb, 0x0930),
  1096. .driver_info = (unsigned long) &ax88178_info,
  1097. }, {
  1098. // Belkin F5D5055
  1099. USB_DEVICE(0x050d, 0x5055),
  1100. .driver_info = (unsigned long) &ax88178_info,
  1101. }, {
  1102. // Apple USB Ethernet Adapter
  1103. USB_DEVICE(0x05ac, 0x1402),
  1104. .driver_info = (unsigned long) &ax88772_info,
  1105. }, {
  1106. // Cables-to-Go USB Ethernet Adapter
  1107. USB_DEVICE(0x0b95, 0x772a),
  1108. .driver_info = (unsigned long) &ax88772_info,
  1109. }, {
  1110. // ABOCOM for pci
  1111. USB_DEVICE(0x14ea, 0xab11),
  1112. .driver_info = (unsigned long) &ax88178_info,
  1113. }, {
  1114. // ASIX 88772a
  1115. USB_DEVICE(0x0db0, 0xa877),
  1116. .driver_info = (unsigned long) &ax88772_info,
  1117. }, {
  1118. // Asus USB Ethernet Adapter
  1119. USB_DEVICE (0x0b95, 0x7e2b),
  1120. .driver_info = (unsigned long)&ax88772b_info,
  1121. }, {
  1122. /* ASIX 88172a demo board */
  1123. USB_DEVICE(0x0b95, 0x172a),
  1124. .driver_info = (unsigned long) &ax88172a_info,
  1125. }, {
  1126. /*
  1127. * USBLINK HG20F9 "USB 2.0 LAN"
  1128. * Appears to have gazumped Linksys's manufacturer ID but
  1129. * doesn't (yet) conflict with any known Linksys product.
  1130. */
  1131. USB_DEVICE(0x066b, 0x20f9),
  1132. .driver_info = (unsigned long) &hg20f9_info,
  1133. },
  1134. { }, // END
  1135. };
  1136. MODULE_DEVICE_TABLE(usb, products);
  1137. static struct usb_driver asix_driver = {
  1138. .name = DRIVER_NAME,
  1139. .id_table = products,
  1140. .probe = usbnet_probe,
  1141. .suspend = asix_suspend,
  1142. .resume = asix_resume,
  1143. .reset_resume = asix_resume,
  1144. .disconnect = usbnet_disconnect,
  1145. .supports_autosuspend = 1,
  1146. .disable_hub_initiated_lpm = 1,
  1147. };
  1148. module_usb_driver(asix_driver);
  1149. MODULE_AUTHOR("David Hollis");
  1150. MODULE_VERSION(DRIVER_VERSION);
  1151. MODULE_DESCRIPTION("ASIX AX8817X based USB 2.0 Ethernet Devices");
  1152. MODULE_LICENSE("GPL");