asix_devices.c 36 KB

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