asix_devices.c 36 KB

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