asix_devices.c 36 KB

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