asix_devices.c 36 KB

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