asix_devices.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396
  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. if (priv->presvd_phy_bmcr & BMCR_ANENABLE)
  519. priv->presvd_phy_bmcr |= BMCR_ANRESTART;
  520. asix_mdio_write_nopm(dev->net, dev->mii.phy_id, MII_BMCR,
  521. priv->presvd_phy_bmcr);
  522. priv->presvd_phy_advertise = 0;
  523. priv->presvd_phy_bmcr = 0;
  524. }
  525. }
  526. static void ax88772_resume(struct usbnet *dev)
  527. {
  528. int i;
  529. for (i = 0; i < 3; i++)
  530. if (!ax88772_hw_reset(dev, 1))
  531. break;
  532. ax88772_restore_phy(dev);
  533. }
  534. static void ax88772a_resume(struct usbnet *dev)
  535. {
  536. int i;
  537. for (i = 0; i < 3; i++) {
  538. if (!ax88772a_hw_reset(dev, 1))
  539. break;
  540. }
  541. ax88772_restore_phy(dev);
  542. }
  543. static int asix_resume(struct usb_interface *intf)
  544. {
  545. struct usbnet *dev = usb_get_intfdata(intf);
  546. struct asix_common_private *priv = dev->driver_priv;
  547. if (priv && priv->resume)
  548. priv->resume(dev);
  549. return usbnet_resume(intf);
  550. }
  551. static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
  552. {
  553. int ret, i;
  554. u8 buf[ETH_ALEN], chipcode = 0;
  555. u32 phyid;
  556. struct asix_common_private *priv;
  557. usbnet_get_endpoints(dev, intf);
  558. /* Maybe the boot loader passed the MAC address via device tree */
  559. if (!eth_platform_get_mac_address(&dev->udev->dev, buf)) {
  560. netif_dbg(dev, ifup, dev->net,
  561. "MAC address read from device tree");
  562. } else {
  563. /* Try getting the MAC address from EEPROM */
  564. if (dev->driver_info->data & FLAG_EEPROM_MAC) {
  565. for (i = 0; i < (ETH_ALEN >> 1); i++) {
  566. ret = asix_read_cmd(dev, AX_CMD_READ_EEPROM,
  567. 0x04 + i, 0, 2, buf + i * 2,
  568. 0);
  569. if (ret < 0)
  570. break;
  571. }
  572. } else {
  573. ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID,
  574. 0, 0, ETH_ALEN, buf, 0);
  575. }
  576. if (ret < 0) {
  577. netdev_dbg(dev->net, "Failed to read MAC address: %d\n",
  578. ret);
  579. return ret;
  580. }
  581. }
  582. asix_set_netdev_dev_addr(dev, buf);
  583. /* Initialize MII structure */
  584. dev->mii.dev = dev->net;
  585. dev->mii.mdio_read = asix_mdio_read;
  586. dev->mii.mdio_write = asix_mdio_write;
  587. dev->mii.phy_id_mask = 0x1f;
  588. dev->mii.reg_num_mask = 0x1f;
  589. dev->mii.phy_id = asix_get_phy_addr(dev);
  590. dev->net->netdev_ops = &ax88772_netdev_ops;
  591. dev->net->ethtool_ops = &ax88772_ethtool_ops;
  592. dev->net->needed_headroom = 4; /* cf asix_tx_fixup() */
  593. dev->net->needed_tailroom = 4; /* cf asix_tx_fixup() */
  594. asix_read_cmd(dev, AX_CMD_STATMNGSTS_REG, 0, 0, 1, &chipcode, 0);
  595. chipcode &= AX_CHIPCODE_MASK;
  596. (chipcode == AX_AX88772_CHIPCODE) ? ax88772_hw_reset(dev, 0) :
  597. ax88772a_hw_reset(dev, 0);
  598. /* Read PHYID register *AFTER* the PHY was reset properly */
  599. phyid = asix_get_phyid(dev);
  600. netdev_dbg(dev->net, "PHYID=0x%08x\n", phyid);
  601. /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
  602. if (dev->driver_info->flags & FLAG_FRAMING_AX) {
  603. /* hard_mtu is still the default - the device does not support
  604. jumbo eth frames */
  605. dev->rx_urb_size = 2048;
  606. }
  607. dev->driver_priv = kzalloc(sizeof(struct asix_common_private), GFP_KERNEL);
  608. if (!dev->driver_priv)
  609. return -ENOMEM;
  610. priv = dev->driver_priv;
  611. priv->presvd_phy_bmcr = 0;
  612. priv->presvd_phy_advertise = 0;
  613. if (chipcode == AX_AX88772_CHIPCODE) {
  614. priv->resume = ax88772_resume;
  615. priv->suspend = ax88772_suspend;
  616. } else {
  617. priv->resume = ax88772a_resume;
  618. priv->suspend = ax88772_suspend;
  619. }
  620. return 0;
  621. }
  622. static void ax88772_unbind(struct usbnet *dev, struct usb_interface *intf)
  623. {
  624. asix_rx_fixup_common_free(dev->driver_priv);
  625. kfree(dev->driver_priv);
  626. }
  627. static const struct ethtool_ops ax88178_ethtool_ops = {
  628. .get_drvinfo = asix_get_drvinfo,
  629. .get_link = asix_get_link,
  630. .get_msglevel = usbnet_get_msglevel,
  631. .set_msglevel = usbnet_set_msglevel,
  632. .get_wol = asix_get_wol,
  633. .set_wol = asix_set_wol,
  634. .get_eeprom_len = asix_get_eeprom_len,
  635. .get_eeprom = asix_get_eeprom,
  636. .set_eeprom = asix_set_eeprom,
  637. .nway_reset = usbnet_nway_reset,
  638. .get_link_ksettings = usbnet_get_link_ksettings,
  639. .set_link_ksettings = usbnet_set_link_ksettings,
  640. };
  641. static int marvell_phy_init(struct usbnet *dev)
  642. {
  643. struct asix_data *data = (struct asix_data *)&dev->data;
  644. u16 reg;
  645. netdev_dbg(dev->net, "marvell_phy_init()\n");
  646. reg = asix_mdio_read(dev->net, dev->mii.phy_id, MII_MARVELL_STATUS);
  647. netdev_dbg(dev->net, "MII_MARVELL_STATUS = 0x%04x\n", reg);
  648. asix_mdio_write(dev->net, dev->mii.phy_id, MII_MARVELL_CTRL,
  649. MARVELL_CTRL_RXDELAY | MARVELL_CTRL_TXDELAY);
  650. if (data->ledmode) {
  651. reg = asix_mdio_read(dev->net, dev->mii.phy_id,
  652. MII_MARVELL_LED_CTRL);
  653. netdev_dbg(dev->net, "MII_MARVELL_LED_CTRL (1) = 0x%04x\n", reg);
  654. reg &= 0xf8ff;
  655. reg |= (1 + 0x0100);
  656. asix_mdio_write(dev->net, dev->mii.phy_id,
  657. MII_MARVELL_LED_CTRL, reg);
  658. reg = asix_mdio_read(dev->net, dev->mii.phy_id,
  659. MII_MARVELL_LED_CTRL);
  660. netdev_dbg(dev->net, "MII_MARVELL_LED_CTRL (2) = 0x%04x\n", reg);
  661. reg &= 0xfc0f;
  662. }
  663. return 0;
  664. }
  665. static int rtl8211cl_phy_init(struct usbnet *dev)
  666. {
  667. struct asix_data *data = (struct asix_data *)&dev->data;
  668. netdev_dbg(dev->net, "rtl8211cl_phy_init()\n");
  669. asix_mdio_write (dev->net, dev->mii.phy_id, 0x1f, 0x0005);
  670. asix_mdio_write (dev->net, dev->mii.phy_id, 0x0c, 0);
  671. asix_mdio_write (dev->net, dev->mii.phy_id, 0x01,
  672. asix_mdio_read (dev->net, dev->mii.phy_id, 0x01) | 0x0080);
  673. asix_mdio_write (dev->net, dev->mii.phy_id, 0x1f, 0);
  674. if (data->ledmode == 12) {
  675. asix_mdio_write (dev->net, dev->mii.phy_id, 0x1f, 0x0002);
  676. asix_mdio_write (dev->net, dev->mii.phy_id, 0x1a, 0x00cb);
  677. asix_mdio_write (dev->net, dev->mii.phy_id, 0x1f, 0);
  678. }
  679. return 0;
  680. }
  681. static int marvell_led_status(struct usbnet *dev, u16 speed)
  682. {
  683. u16 reg = asix_mdio_read(dev->net, dev->mii.phy_id, MARVELL_LED_MANUAL);
  684. netdev_dbg(dev->net, "marvell_led_status() read 0x%04x\n", reg);
  685. /* Clear out the center LED bits - 0x03F0 */
  686. reg &= 0xfc0f;
  687. switch (speed) {
  688. case SPEED_1000:
  689. reg |= 0x03e0;
  690. break;
  691. case SPEED_100:
  692. reg |= 0x03b0;
  693. break;
  694. default:
  695. reg |= 0x02f0;
  696. }
  697. netdev_dbg(dev->net, "marvell_led_status() writing 0x%04x\n", reg);
  698. asix_mdio_write(dev->net, dev->mii.phy_id, MARVELL_LED_MANUAL, reg);
  699. return 0;
  700. }
  701. static int ax88178_reset(struct usbnet *dev)
  702. {
  703. struct asix_data *data = (struct asix_data *)&dev->data;
  704. int ret;
  705. __le16 eeprom;
  706. u8 status;
  707. int gpio0 = 0;
  708. u32 phyid;
  709. asix_read_cmd(dev, AX_CMD_READ_GPIOS, 0, 0, 1, &status, 0);
  710. netdev_dbg(dev->net, "GPIO Status: 0x%04x\n", status);
  711. asix_write_cmd(dev, AX_CMD_WRITE_ENABLE, 0, 0, 0, NULL, 0);
  712. asix_read_cmd(dev, AX_CMD_READ_EEPROM, 0x0017, 0, 2, &eeprom, 0);
  713. asix_write_cmd(dev, AX_CMD_WRITE_DISABLE, 0, 0, 0, NULL, 0);
  714. netdev_dbg(dev->net, "EEPROM index 0x17 is 0x%04x\n", eeprom);
  715. if (eeprom == cpu_to_le16(0xffff)) {
  716. data->phymode = PHY_MODE_MARVELL;
  717. data->ledmode = 0;
  718. gpio0 = 1;
  719. } else {
  720. data->phymode = le16_to_cpu(eeprom) & 0x7F;
  721. data->ledmode = le16_to_cpu(eeprom) >> 8;
  722. gpio0 = (le16_to_cpu(eeprom) & 0x80) ? 0 : 1;
  723. }
  724. netdev_dbg(dev->net, "GPIO0: %d, PhyMode: %d\n", gpio0, data->phymode);
  725. /* Power up external GigaPHY through AX88178 GPIO pin */
  726. asix_write_gpio(dev, AX_GPIO_RSE | AX_GPIO_GPO_1 |
  727. AX_GPIO_GPO1EN, 40, 0);
  728. if ((le16_to_cpu(eeprom) >> 8) != 1) {
  729. asix_write_gpio(dev, 0x003c, 30, 0);
  730. asix_write_gpio(dev, 0x001c, 300, 0);
  731. asix_write_gpio(dev, 0x003c, 30, 0);
  732. } else {
  733. netdev_dbg(dev->net, "gpio phymode == 1 path\n");
  734. asix_write_gpio(dev, AX_GPIO_GPO1EN, 30, 0);
  735. asix_write_gpio(dev, AX_GPIO_GPO1EN | AX_GPIO_GPO_1, 30, 0);
  736. }
  737. /* Read PHYID register *AFTER* powering up PHY */
  738. phyid = asix_get_phyid(dev);
  739. netdev_dbg(dev->net, "PHYID=0x%08x\n", phyid);
  740. /* Set AX88178 to enable MII/GMII/RGMII interface for external PHY */
  741. asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT, 0, 0, 0, NULL, 0);
  742. asix_sw_reset(dev, 0, 0);
  743. msleep(150);
  744. asix_sw_reset(dev, AX_SWRESET_PRL | AX_SWRESET_IPPD, 0);
  745. msleep(150);
  746. asix_write_rx_ctl(dev, 0, 0);
  747. if (data->phymode == PHY_MODE_MARVELL) {
  748. marvell_phy_init(dev);
  749. msleep(60);
  750. } else if (data->phymode == PHY_MODE_RTL8211CL)
  751. rtl8211cl_phy_init(dev);
  752. asix_phy_reset(dev, BMCR_RESET | BMCR_ANENABLE);
  753. asix_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
  754. ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  755. asix_mdio_write(dev->net, dev->mii.phy_id, MII_CTRL1000,
  756. ADVERTISE_1000FULL);
  757. asix_write_medium_mode(dev, AX88178_MEDIUM_DEFAULT, 0);
  758. mii_nway_restart(&dev->mii);
  759. /* Rewrite MAC address */
  760. memcpy(data->mac_addr, dev->net->dev_addr, ETH_ALEN);
  761. ret = asix_write_cmd(dev, AX_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
  762. data->mac_addr, 0);
  763. if (ret < 0)
  764. return ret;
  765. ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL, 0);
  766. if (ret < 0)
  767. return ret;
  768. return 0;
  769. }
  770. static int ax88178_link_reset(struct usbnet *dev)
  771. {
  772. u16 mode;
  773. struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
  774. struct asix_data *data = (struct asix_data *)&dev->data;
  775. u32 speed;
  776. netdev_dbg(dev->net, "ax88178_link_reset()\n");
  777. mii_check_media(&dev->mii, 1, 1);
  778. mii_ethtool_gset(&dev->mii, &ecmd);
  779. mode = AX88178_MEDIUM_DEFAULT;
  780. speed = ethtool_cmd_speed(&ecmd);
  781. if (speed == SPEED_1000)
  782. mode |= AX_MEDIUM_GM;
  783. else if (speed == SPEED_100)
  784. mode |= AX_MEDIUM_PS;
  785. else
  786. mode &= ~(AX_MEDIUM_PS | AX_MEDIUM_GM);
  787. mode |= AX_MEDIUM_ENCK;
  788. if (ecmd.duplex == DUPLEX_FULL)
  789. mode |= AX_MEDIUM_FD;
  790. else
  791. mode &= ~AX_MEDIUM_FD;
  792. netdev_dbg(dev->net, "ax88178_link_reset() speed: %u duplex: %d setting mode to 0x%04x\n",
  793. speed, ecmd.duplex, mode);
  794. asix_write_medium_mode(dev, mode, 0);
  795. if (data->phymode == PHY_MODE_MARVELL && data->ledmode)
  796. marvell_led_status(dev, speed);
  797. return 0;
  798. }
  799. static void ax88178_set_mfb(struct usbnet *dev)
  800. {
  801. u16 mfb = AX_RX_CTL_MFB_16384;
  802. u16 rxctl;
  803. u16 medium;
  804. int old_rx_urb_size = dev->rx_urb_size;
  805. if (dev->hard_mtu < 2048) {
  806. dev->rx_urb_size = 2048;
  807. mfb = AX_RX_CTL_MFB_2048;
  808. } else if (dev->hard_mtu < 4096) {
  809. dev->rx_urb_size = 4096;
  810. mfb = AX_RX_CTL_MFB_4096;
  811. } else if (dev->hard_mtu < 8192) {
  812. dev->rx_urb_size = 8192;
  813. mfb = AX_RX_CTL_MFB_8192;
  814. } else if (dev->hard_mtu < 16384) {
  815. dev->rx_urb_size = 16384;
  816. mfb = AX_RX_CTL_MFB_16384;
  817. }
  818. rxctl = asix_read_rx_ctl(dev, 0);
  819. asix_write_rx_ctl(dev, (rxctl & ~AX_RX_CTL_MFB_16384) | mfb, 0);
  820. medium = asix_read_medium_status(dev, 0);
  821. if (dev->net->mtu > 1500)
  822. medium |= AX_MEDIUM_JFE;
  823. else
  824. medium &= ~AX_MEDIUM_JFE;
  825. asix_write_medium_mode(dev, medium, 0);
  826. if (dev->rx_urb_size > old_rx_urb_size)
  827. usbnet_unlink_rx_urbs(dev);
  828. }
  829. static int ax88178_change_mtu(struct net_device *net, int new_mtu)
  830. {
  831. struct usbnet *dev = netdev_priv(net);
  832. int ll_mtu = new_mtu + net->hard_header_len + 4;
  833. netdev_dbg(dev->net, "ax88178_change_mtu() new_mtu=%d\n", new_mtu);
  834. if ((ll_mtu % dev->maxpacket) == 0)
  835. return -EDOM;
  836. net->mtu = new_mtu;
  837. dev->hard_mtu = net->mtu + net->hard_header_len;
  838. ax88178_set_mfb(dev);
  839. /* max qlen depend on hard_mtu and rx_urb_size */
  840. usbnet_update_max_qlen(dev);
  841. return 0;
  842. }
  843. static const struct net_device_ops ax88178_netdev_ops = {
  844. .ndo_open = usbnet_open,
  845. .ndo_stop = usbnet_stop,
  846. .ndo_start_xmit = usbnet_start_xmit,
  847. .ndo_tx_timeout = usbnet_tx_timeout,
  848. .ndo_get_stats64 = usbnet_get_stats64,
  849. .ndo_set_mac_address = asix_set_mac_address,
  850. .ndo_validate_addr = eth_validate_addr,
  851. .ndo_set_rx_mode = asix_set_multicast,
  852. .ndo_do_ioctl = asix_ioctl,
  853. .ndo_change_mtu = ax88178_change_mtu,
  854. };
  855. static int ax88178_bind(struct usbnet *dev, struct usb_interface *intf)
  856. {
  857. int ret;
  858. u8 buf[ETH_ALEN];
  859. usbnet_get_endpoints(dev,intf);
  860. /* Get the MAC address */
  861. ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf, 0);
  862. if (ret < 0) {
  863. netdev_dbg(dev->net, "Failed to read MAC address: %d\n", ret);
  864. return ret;
  865. }
  866. asix_set_netdev_dev_addr(dev, buf);
  867. /* Initialize MII structure */
  868. dev->mii.dev = dev->net;
  869. dev->mii.mdio_read = asix_mdio_read;
  870. dev->mii.mdio_write = asix_mdio_write;
  871. dev->mii.phy_id_mask = 0x1f;
  872. dev->mii.reg_num_mask = 0xff;
  873. dev->mii.supports_gmii = 1;
  874. dev->mii.phy_id = asix_get_phy_addr(dev);
  875. dev->net->netdev_ops = &ax88178_netdev_ops;
  876. dev->net->ethtool_ops = &ax88178_ethtool_ops;
  877. dev->net->max_mtu = 16384 - (dev->net->hard_header_len + 4);
  878. /* Blink LEDS so users know driver saw dongle */
  879. asix_sw_reset(dev, 0, 0);
  880. msleep(150);
  881. asix_sw_reset(dev, AX_SWRESET_PRL | AX_SWRESET_IPPD, 0);
  882. msleep(150);
  883. /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
  884. if (dev->driver_info->flags & FLAG_FRAMING_AX) {
  885. /* hard_mtu is still the default - the device does not support
  886. jumbo eth frames */
  887. dev->rx_urb_size = 2048;
  888. }
  889. dev->driver_priv = kzalloc(sizeof(struct asix_common_private), GFP_KERNEL);
  890. if (!dev->driver_priv)
  891. return -ENOMEM;
  892. return 0;
  893. }
  894. static const struct driver_info ax8817x_info = {
  895. .description = "ASIX AX8817x USB 2.0 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 = 0x00130103,
  902. };
  903. static const struct driver_info dlink_dub_e100_info = {
  904. .description = "DLink DUB-E100 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 = 0x009f9d9f,
  911. };
  912. static const struct driver_info netgear_fa120_info = {
  913. .description = "Netgear FA-120 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 = 0x00130103,
  920. };
  921. static const struct driver_info hawking_uf200_info = {
  922. .description = "Hawking UF200 USB Ethernet",
  923. .bind = ax88172_bind,
  924. .status = asix_status,
  925. .link_reset = ax88172_link_reset,
  926. .reset = ax88172_link_reset,
  927. .flags = FLAG_ETHER | FLAG_LINK_INTR,
  928. .data = 0x001f1d1f,
  929. };
  930. static const struct driver_info ax88772_info = {
  931. .description = "ASIX AX88772 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 | FLAG_MULTI_PACKET,
  938. .rx_fixup = asix_rx_fixup_common,
  939. .tx_fixup = asix_tx_fixup,
  940. };
  941. static const struct driver_info ax88772b_info = {
  942. .description = "ASIX AX88772B USB 2.0 Ethernet",
  943. .bind = ax88772_bind,
  944. .unbind = ax88772_unbind,
  945. .status = asix_status,
  946. .link_reset = ax88772_link_reset,
  947. .reset = ax88772_reset,
  948. .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR |
  949. FLAG_MULTI_PACKET,
  950. .rx_fixup = asix_rx_fixup_common,
  951. .tx_fixup = asix_tx_fixup,
  952. .data = FLAG_EEPROM_MAC,
  953. };
  954. static const struct driver_info ax88178_info = {
  955. .description = "ASIX AX88178 USB 2.0 Ethernet",
  956. .bind = ax88178_bind,
  957. .unbind = ax88772_unbind,
  958. .status = asix_status,
  959. .link_reset = ax88178_link_reset,
  960. .reset = ax88178_reset,
  961. .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR |
  962. FLAG_MULTI_PACKET,
  963. .rx_fixup = asix_rx_fixup_common,
  964. .tx_fixup = asix_tx_fixup,
  965. };
  966. /*
  967. * USBLINK 20F9 "USB 2.0 LAN" USB ethernet adapter, typically found in
  968. * no-name packaging.
  969. * USB device strings are:
  970. * 1: Manufacturer: USBLINK
  971. * 2: Product: HG20F9 USB2.0
  972. * 3: Serial: 000003
  973. * Appears to be compatible with Asix 88772B.
  974. */
  975. static const struct driver_info hg20f9_info = {
  976. .description = "HG20F9 USB 2.0 Ethernet",
  977. .bind = ax88772_bind,
  978. .unbind = ax88772_unbind,
  979. .status = asix_status,
  980. .link_reset = ax88772_link_reset,
  981. .reset = ax88772_reset,
  982. .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR |
  983. FLAG_MULTI_PACKET,
  984. .rx_fixup = asix_rx_fixup_common,
  985. .tx_fixup = asix_tx_fixup,
  986. .data = FLAG_EEPROM_MAC,
  987. };
  988. static const struct usb_device_id products [] = {
  989. {
  990. // Linksys USB200M
  991. USB_DEVICE (0x077b, 0x2226),
  992. .driver_info = (unsigned long) &ax8817x_info,
  993. }, {
  994. // Netgear FA120
  995. USB_DEVICE (0x0846, 0x1040),
  996. .driver_info = (unsigned long) &netgear_fa120_info,
  997. }, {
  998. // DLink DUB-E100
  999. USB_DEVICE (0x2001, 0x1a00),
  1000. .driver_info = (unsigned long) &dlink_dub_e100_info,
  1001. }, {
  1002. // Intellinet, ST Lab USB Ethernet
  1003. USB_DEVICE (0x0b95, 0x1720),
  1004. .driver_info = (unsigned long) &ax8817x_info,
  1005. }, {
  1006. // Hawking UF200, TrendNet TU2-ET100
  1007. USB_DEVICE (0x07b8, 0x420a),
  1008. .driver_info = (unsigned long) &hawking_uf200_info,
  1009. }, {
  1010. // Billionton Systems, USB2AR
  1011. USB_DEVICE (0x08dd, 0x90ff),
  1012. .driver_info = (unsigned long) &ax8817x_info,
  1013. }, {
  1014. // Billionton Systems, GUSB2AM-1G-B
  1015. USB_DEVICE(0x08dd, 0x0114),
  1016. .driver_info = (unsigned long) &ax88178_info,
  1017. }, {
  1018. // ATEN UC210T
  1019. USB_DEVICE (0x0557, 0x2009),
  1020. .driver_info = (unsigned long) &ax8817x_info,
  1021. }, {
  1022. // Buffalo LUA-U2-KTX
  1023. USB_DEVICE (0x0411, 0x003d),
  1024. .driver_info = (unsigned long) &ax8817x_info,
  1025. }, {
  1026. // Buffalo LUA-U2-GT 10/100/1000
  1027. USB_DEVICE (0x0411, 0x006e),
  1028. .driver_info = (unsigned long) &ax88178_info,
  1029. }, {
  1030. // Sitecom LN-029 "USB 2.0 10/100 Ethernet adapter"
  1031. USB_DEVICE (0x6189, 0x182d),
  1032. .driver_info = (unsigned long) &ax8817x_info,
  1033. }, {
  1034. // Sitecom LN-031 "USB 2.0 10/100/1000 Ethernet adapter"
  1035. USB_DEVICE (0x0df6, 0x0056),
  1036. .driver_info = (unsigned long) &ax88178_info,
  1037. }, {
  1038. // Sitecom LN-028 "USB 2.0 10/100/1000 Ethernet adapter"
  1039. USB_DEVICE (0x0df6, 0x061c),
  1040. .driver_info = (unsigned long) &ax88178_info,
  1041. }, {
  1042. // corega FEther USB2-TX
  1043. USB_DEVICE (0x07aa, 0x0017),
  1044. .driver_info = (unsigned long) &ax8817x_info,
  1045. }, {
  1046. // Surecom EP-1427X-2
  1047. USB_DEVICE (0x1189, 0x0893),
  1048. .driver_info = (unsigned long) &ax8817x_info,
  1049. }, {
  1050. // goodway corp usb gwusb2e
  1051. USB_DEVICE (0x1631, 0x6200),
  1052. .driver_info = (unsigned long) &ax8817x_info,
  1053. }, {
  1054. // JVC MP-PRX1 Port Replicator
  1055. USB_DEVICE (0x04f1, 0x3008),
  1056. .driver_info = (unsigned long) &ax8817x_info,
  1057. }, {
  1058. // Lenovo U2L100P 10/100
  1059. USB_DEVICE (0x17ef, 0x7203),
  1060. .driver_info = (unsigned long)&ax88772b_info,
  1061. }, {
  1062. // ASIX AX88772B 10/100
  1063. USB_DEVICE (0x0b95, 0x772b),
  1064. .driver_info = (unsigned long) &ax88772b_info,
  1065. }, {
  1066. // ASIX AX88772 10/100
  1067. USB_DEVICE (0x0b95, 0x7720),
  1068. .driver_info = (unsigned long) &ax88772_info,
  1069. }, {
  1070. // ASIX AX88178 10/100/1000
  1071. USB_DEVICE (0x0b95, 0x1780),
  1072. .driver_info = (unsigned long) &ax88178_info,
  1073. }, {
  1074. // Logitec LAN-GTJ/U2A
  1075. USB_DEVICE (0x0789, 0x0160),
  1076. .driver_info = (unsigned long) &ax88178_info,
  1077. }, {
  1078. // Linksys USB200M Rev 2
  1079. USB_DEVICE (0x13b1, 0x0018),
  1080. .driver_info = (unsigned long) &ax88772_info,
  1081. }, {
  1082. // 0Q0 cable ethernet
  1083. USB_DEVICE (0x1557, 0x7720),
  1084. .driver_info = (unsigned long) &ax88772_info,
  1085. }, {
  1086. // DLink DUB-E100 H/W Ver B1
  1087. USB_DEVICE (0x07d1, 0x3c05),
  1088. .driver_info = (unsigned long) &ax88772_info,
  1089. }, {
  1090. // DLink DUB-E100 H/W Ver B1 Alternate
  1091. USB_DEVICE (0x2001, 0x3c05),
  1092. .driver_info = (unsigned long) &ax88772_info,
  1093. }, {
  1094. // DLink DUB-E100 H/W Ver C1
  1095. USB_DEVICE (0x2001, 0x1a02),
  1096. .driver_info = (unsigned long) &ax88772_info,
  1097. }, {
  1098. // Linksys USB1000
  1099. USB_DEVICE (0x1737, 0x0039),
  1100. .driver_info = (unsigned long) &ax88178_info,
  1101. }, {
  1102. // IO-DATA ETG-US2
  1103. USB_DEVICE (0x04bb, 0x0930),
  1104. .driver_info = (unsigned long) &ax88178_info,
  1105. }, {
  1106. // Belkin F5D5055
  1107. USB_DEVICE(0x050d, 0x5055),
  1108. .driver_info = (unsigned long) &ax88178_info,
  1109. }, {
  1110. // Apple USB Ethernet Adapter
  1111. USB_DEVICE(0x05ac, 0x1402),
  1112. .driver_info = (unsigned long) &ax88772_info,
  1113. }, {
  1114. // Cables-to-Go USB Ethernet Adapter
  1115. USB_DEVICE(0x0b95, 0x772a),
  1116. .driver_info = (unsigned long) &ax88772_info,
  1117. }, {
  1118. // ABOCOM for pci
  1119. USB_DEVICE(0x14ea, 0xab11),
  1120. .driver_info = (unsigned long) &ax88178_info,
  1121. }, {
  1122. // ASIX 88772a
  1123. USB_DEVICE(0x0db0, 0xa877),
  1124. .driver_info = (unsigned long) &ax88772_info,
  1125. }, {
  1126. // Asus USB Ethernet Adapter
  1127. USB_DEVICE (0x0b95, 0x7e2b),
  1128. .driver_info = (unsigned long)&ax88772b_info,
  1129. }, {
  1130. /* ASIX 88172a demo board */
  1131. USB_DEVICE(0x0b95, 0x172a),
  1132. .driver_info = (unsigned long) &ax88172a_info,
  1133. }, {
  1134. /*
  1135. * USBLINK HG20F9 "USB 2.0 LAN"
  1136. * Appears to have gazumped Linksys's manufacturer ID but
  1137. * doesn't (yet) conflict with any known Linksys product.
  1138. */
  1139. USB_DEVICE(0x066b, 0x20f9),
  1140. .driver_info = (unsigned long) &hg20f9_info,
  1141. },
  1142. { }, // END
  1143. };
  1144. MODULE_DEVICE_TABLE(usb, products);
  1145. static struct usb_driver asix_driver = {
  1146. .name = DRIVER_NAME,
  1147. .id_table = products,
  1148. .probe = usbnet_probe,
  1149. .suspend = asix_suspend,
  1150. .resume = asix_resume,
  1151. .reset_resume = asix_resume,
  1152. .disconnect = usbnet_disconnect,
  1153. .supports_autosuspend = 1,
  1154. .disable_hub_initiated_lpm = 1,
  1155. };
  1156. module_usb_driver(asix_driver);
  1157. MODULE_AUTHOR("David Hollis");
  1158. MODULE_VERSION(DRIVER_VERSION);
  1159. MODULE_DESCRIPTION("ASIX AX8817X based USB 2.0 Ethernet Devices");
  1160. MODULE_LICENSE("GPL");