asix_devices.c 36 KB

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