asix.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. /*
  2. * Copyright (c) 2011 The Chromium OS Authors.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <usb.h>
  8. #include <linux/mii.h>
  9. #include "usb_ether.h"
  10. #include <malloc.h>
  11. /* ASIX AX8817X based USB 2.0 Ethernet Devices */
  12. #define AX_CMD_SET_SW_MII 0x06
  13. #define AX_CMD_READ_MII_REG 0x07
  14. #define AX_CMD_WRITE_MII_REG 0x08
  15. #define AX_CMD_SET_HW_MII 0x0a
  16. #define AX_CMD_READ_EEPROM 0x0b
  17. #define AX_CMD_READ_RX_CTL 0x0f
  18. #define AX_CMD_WRITE_RX_CTL 0x10
  19. #define AX_CMD_WRITE_IPG0 0x12
  20. #define AX_CMD_READ_NODE_ID 0x13
  21. #define AX_CMD_WRITE_NODE_ID 0x14
  22. #define AX_CMD_READ_PHY_ID 0x19
  23. #define AX_CMD_WRITE_MEDIUM_MODE 0x1b
  24. #define AX_CMD_WRITE_GPIOS 0x1f
  25. #define AX_CMD_SW_RESET 0x20
  26. #define AX_CMD_SW_PHY_SELECT 0x22
  27. #define AX_SWRESET_CLEAR 0x00
  28. #define AX_SWRESET_PRTE 0x04
  29. #define AX_SWRESET_PRL 0x08
  30. #define AX_SWRESET_IPRL 0x20
  31. #define AX_SWRESET_IPPD 0x40
  32. #define AX88772_IPG0_DEFAULT 0x15
  33. #define AX88772_IPG1_DEFAULT 0x0c
  34. #define AX88772_IPG2_DEFAULT 0x12
  35. /* AX88772 & AX88178 Medium Mode Register */
  36. #define AX_MEDIUM_PF 0x0080
  37. #define AX_MEDIUM_JFE 0x0040
  38. #define AX_MEDIUM_TFC 0x0020
  39. #define AX_MEDIUM_RFC 0x0010
  40. #define AX_MEDIUM_ENCK 0x0008
  41. #define AX_MEDIUM_AC 0x0004
  42. #define AX_MEDIUM_FD 0x0002
  43. #define AX_MEDIUM_GM 0x0001
  44. #define AX_MEDIUM_SM 0x1000
  45. #define AX_MEDIUM_SBP 0x0800
  46. #define AX_MEDIUM_PS 0x0200
  47. #define AX_MEDIUM_RE 0x0100
  48. #define AX88178_MEDIUM_DEFAULT \
  49. (AX_MEDIUM_PS | AX_MEDIUM_FD | AX_MEDIUM_AC | \
  50. AX_MEDIUM_RFC | AX_MEDIUM_TFC | AX_MEDIUM_JFE | \
  51. AX_MEDIUM_RE)
  52. #define AX88772_MEDIUM_DEFAULT \
  53. (AX_MEDIUM_FD | AX_MEDIUM_RFC | \
  54. AX_MEDIUM_TFC | AX_MEDIUM_PS | \
  55. AX_MEDIUM_AC | AX_MEDIUM_RE)
  56. /* AX88772 & AX88178 RX_CTL values */
  57. #define AX_RX_CTL_SO 0x0080
  58. #define AX_RX_CTL_AB 0x0008
  59. #define AX_DEFAULT_RX_CTL \
  60. (AX_RX_CTL_SO | AX_RX_CTL_AB)
  61. /* GPIO 2 toggles */
  62. #define AX_GPIO_GPO2EN 0x10 /* GPIO2 Output enable */
  63. #define AX_GPIO_GPO_2 0x20 /* GPIO2 Output value */
  64. #define AX_GPIO_RSE 0x80 /* Reload serial EEPROM */
  65. /* local defines */
  66. #define ASIX_BASE_NAME "asx"
  67. #define USB_CTRL_SET_TIMEOUT 5000
  68. #define USB_CTRL_GET_TIMEOUT 5000
  69. #define USB_BULK_SEND_TIMEOUT 5000
  70. #define USB_BULK_RECV_TIMEOUT 5000
  71. #define AX_RX_URB_SIZE 2048
  72. #define PHY_CONNECT_TIMEOUT 5000
  73. /* asix_flags defines */
  74. #define FLAG_NONE 0
  75. #define FLAG_TYPE_AX88172 (1U << 0)
  76. #define FLAG_TYPE_AX88772 (1U << 1)
  77. #define FLAG_TYPE_AX88772B (1U << 2)
  78. #define FLAG_EEPROM_MAC (1U << 3) /* initial mac address in eeprom */
  79. /* local vars */
  80. static int curr_eth_dev; /* index for name of next device detected */
  81. /* driver private */
  82. struct asix_private {
  83. int flags;
  84. };
  85. /*
  86. * Asix infrastructure commands
  87. */
  88. static int asix_write_cmd(struct ueth_data *dev, u8 cmd, u16 value, u16 index,
  89. u16 size, void *data)
  90. {
  91. int len;
  92. debug("asix_write_cmd() cmd=0x%02x value=0x%04x index=0x%04x "
  93. "size=%d\n", cmd, value, index, size);
  94. len = usb_control_msg(
  95. dev->pusb_dev,
  96. usb_sndctrlpipe(dev->pusb_dev, 0),
  97. cmd,
  98. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  99. value,
  100. index,
  101. data,
  102. size,
  103. USB_CTRL_SET_TIMEOUT);
  104. return len == size ? 0 : -1;
  105. }
  106. static int asix_read_cmd(struct ueth_data *dev, u8 cmd, u16 value, u16 index,
  107. u16 size, void *data)
  108. {
  109. int len;
  110. debug("asix_read_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d\n",
  111. cmd, value, index, size);
  112. len = usb_control_msg(
  113. dev->pusb_dev,
  114. usb_rcvctrlpipe(dev->pusb_dev, 0),
  115. cmd,
  116. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  117. value,
  118. index,
  119. data,
  120. size,
  121. USB_CTRL_GET_TIMEOUT);
  122. return len == size ? 0 : -1;
  123. }
  124. static inline int asix_set_sw_mii(struct ueth_data *dev)
  125. {
  126. int ret;
  127. ret = asix_write_cmd(dev, AX_CMD_SET_SW_MII, 0x0000, 0, 0, NULL);
  128. if (ret < 0)
  129. debug("Failed to enable software MII access\n");
  130. return ret;
  131. }
  132. static inline int asix_set_hw_mii(struct ueth_data *dev)
  133. {
  134. int ret;
  135. ret = asix_write_cmd(dev, AX_CMD_SET_HW_MII, 0x0000, 0, 0, NULL);
  136. if (ret < 0)
  137. debug("Failed to enable hardware MII access\n");
  138. return ret;
  139. }
  140. static int asix_mdio_read(struct ueth_data *dev, int phy_id, int loc)
  141. {
  142. ALLOC_CACHE_ALIGN_BUFFER(__le16, res, 1);
  143. asix_set_sw_mii(dev);
  144. asix_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, (__u16)loc, 2, res);
  145. asix_set_hw_mii(dev);
  146. debug("asix_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x\n",
  147. phy_id, loc, le16_to_cpu(*res));
  148. return le16_to_cpu(*res);
  149. }
  150. static void
  151. asix_mdio_write(struct ueth_data *dev, int phy_id, int loc, int val)
  152. {
  153. ALLOC_CACHE_ALIGN_BUFFER(__le16, res, 1);
  154. *res = cpu_to_le16(val);
  155. debug("asix_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x\n",
  156. phy_id, loc, val);
  157. asix_set_sw_mii(dev);
  158. asix_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2, res);
  159. asix_set_hw_mii(dev);
  160. }
  161. /*
  162. * Asix "high level" commands
  163. */
  164. static int asix_sw_reset(struct ueth_data *dev, u8 flags)
  165. {
  166. int ret;
  167. ret = asix_write_cmd(dev, AX_CMD_SW_RESET, flags, 0, 0, NULL);
  168. if (ret < 0)
  169. debug("Failed to send software reset: %02x\n", ret);
  170. else
  171. udelay(150 * 1000);
  172. return ret;
  173. }
  174. static inline int asix_get_phy_addr(struct ueth_data *dev)
  175. {
  176. ALLOC_CACHE_ALIGN_BUFFER(u8, buf, 2);
  177. int ret = asix_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf);
  178. debug("asix_get_phy_addr()\n");
  179. if (ret < 0) {
  180. debug("Error reading PHYID register: %02x\n", ret);
  181. goto out;
  182. }
  183. debug("asix_get_phy_addr() returning 0x%02x%02x\n", buf[0], buf[1]);
  184. ret = buf[1];
  185. out:
  186. return ret;
  187. }
  188. static int asix_write_medium_mode(struct ueth_data *dev, u16 mode)
  189. {
  190. int ret;
  191. debug("asix_write_medium_mode() - mode = 0x%04x\n", mode);
  192. ret = asix_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode,
  193. 0, 0, NULL);
  194. if (ret < 0) {
  195. debug("Failed to write Medium Mode mode to 0x%04x: %02x\n",
  196. mode, ret);
  197. }
  198. return ret;
  199. }
  200. static u16 asix_read_rx_ctl(struct ueth_data *dev)
  201. {
  202. ALLOC_CACHE_ALIGN_BUFFER(__le16, v, 1);
  203. int ret = asix_read_cmd(dev, AX_CMD_READ_RX_CTL, 0, 0, 2, v);
  204. if (ret < 0)
  205. debug("Error reading RX_CTL register: %02x\n", ret);
  206. else
  207. ret = le16_to_cpu(*v);
  208. return ret;
  209. }
  210. static int asix_write_rx_ctl(struct ueth_data *dev, u16 mode)
  211. {
  212. int ret;
  213. debug("asix_write_rx_ctl() - mode = 0x%04x\n", mode);
  214. ret = asix_write_cmd(dev, AX_CMD_WRITE_RX_CTL, mode, 0, 0, NULL);
  215. if (ret < 0) {
  216. debug("Failed to write RX_CTL mode to 0x%04x: %02x\n",
  217. mode, ret);
  218. }
  219. return ret;
  220. }
  221. static int asix_write_gpio(struct ueth_data *dev, u16 value, int sleep)
  222. {
  223. int ret;
  224. debug("asix_write_gpio() - value = 0x%04x\n", value);
  225. ret = asix_write_cmd(dev, AX_CMD_WRITE_GPIOS, value, 0, 0, NULL);
  226. if (ret < 0) {
  227. debug("Failed to write GPIO value 0x%04x: %02x\n",
  228. value, ret);
  229. }
  230. if (sleep)
  231. udelay(sleep * 1000);
  232. return ret;
  233. }
  234. static int asix_write_hwaddr(struct eth_device *eth)
  235. {
  236. struct ueth_data *dev = (struct ueth_data *)eth->priv;
  237. int ret;
  238. ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buf, ETH_ALEN);
  239. memcpy(buf, eth->enetaddr, ETH_ALEN);
  240. ret = asix_write_cmd(dev, AX_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN, buf);
  241. if (ret < 0)
  242. debug("Failed to set MAC address: %02x\n", ret);
  243. return ret;
  244. }
  245. /*
  246. * mii commands
  247. */
  248. /*
  249. * mii_nway_restart - restart NWay (autonegotiation) for this interface
  250. *
  251. * Returns 0 on success, negative on error.
  252. */
  253. static int mii_nway_restart(struct ueth_data *dev)
  254. {
  255. int bmcr;
  256. int r = -1;
  257. /* if autoneg is off, it's an error */
  258. bmcr = asix_mdio_read(dev, dev->phy_id, MII_BMCR);
  259. if (bmcr & BMCR_ANENABLE) {
  260. bmcr |= BMCR_ANRESTART;
  261. asix_mdio_write(dev, dev->phy_id, MII_BMCR, bmcr);
  262. r = 0;
  263. }
  264. return r;
  265. }
  266. static int asix_read_mac(struct eth_device *eth)
  267. {
  268. struct ueth_data *dev = (struct ueth_data *)eth->priv;
  269. struct asix_private *priv = (struct asix_private *)dev->dev_priv;
  270. int i;
  271. ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buf, ETH_ALEN);
  272. if (priv->flags & FLAG_EEPROM_MAC) {
  273. for (i = 0; i < (ETH_ALEN >> 1); i++) {
  274. if (asix_read_cmd(dev, AX_CMD_READ_EEPROM,
  275. 0x04 + i, 0, 2, buf) < 0) {
  276. debug("Failed to read SROM address 04h.\n");
  277. return -1;
  278. }
  279. memcpy((eth->enetaddr + i * 2), buf, 2);
  280. }
  281. } else {
  282. if (asix_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf)
  283. < 0) {
  284. debug("Failed to read MAC address.\n");
  285. return -1;
  286. }
  287. memcpy(eth->enetaddr, buf, ETH_ALEN);
  288. }
  289. return 0;
  290. }
  291. static int asix_basic_reset(struct ueth_data *dev)
  292. {
  293. int embd_phy;
  294. u16 rx_ctl;
  295. if (asix_write_gpio(dev,
  296. AX_GPIO_RSE | AX_GPIO_GPO_2 | AX_GPIO_GPO2EN, 5) < 0)
  297. return -1;
  298. /* 0x10 is the phy id of the embedded 10/100 ethernet phy */
  299. embd_phy = ((asix_get_phy_addr(dev) & 0x1f) == 0x10 ? 1 : 0);
  300. if (asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT,
  301. embd_phy, 0, 0, NULL) < 0) {
  302. debug("Select PHY #1 failed\n");
  303. return -1;
  304. }
  305. if (asix_sw_reset(dev, AX_SWRESET_IPPD | AX_SWRESET_PRL) < 0)
  306. return -1;
  307. if (asix_sw_reset(dev, AX_SWRESET_CLEAR) < 0)
  308. return -1;
  309. if (embd_phy) {
  310. if (asix_sw_reset(dev, AX_SWRESET_IPRL) < 0)
  311. return -1;
  312. } else {
  313. if (asix_sw_reset(dev, AX_SWRESET_PRTE) < 0)
  314. return -1;
  315. }
  316. rx_ctl = asix_read_rx_ctl(dev);
  317. debug("RX_CTL is 0x%04x after software reset\n", rx_ctl);
  318. if (asix_write_rx_ctl(dev, 0x0000) < 0)
  319. return -1;
  320. rx_ctl = asix_read_rx_ctl(dev);
  321. debug("RX_CTL is 0x%04x setting to 0x0000\n", rx_ctl);
  322. dev->phy_id = asix_get_phy_addr(dev);
  323. if (dev->phy_id < 0)
  324. debug("Failed to read phy id\n");
  325. asix_mdio_write(dev, dev->phy_id, MII_BMCR, BMCR_RESET);
  326. asix_mdio_write(dev, dev->phy_id, MII_ADVERTISE,
  327. ADVERTISE_ALL | ADVERTISE_CSMA);
  328. mii_nway_restart(dev);
  329. if (asix_write_medium_mode(dev, AX88772_MEDIUM_DEFAULT) < 0)
  330. return -1;
  331. if (asix_write_cmd(dev, AX_CMD_WRITE_IPG0,
  332. AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT,
  333. AX88772_IPG2_DEFAULT, 0, NULL) < 0) {
  334. debug("Write IPG,IPG1,IPG2 failed\n");
  335. return -1;
  336. }
  337. return 0;
  338. }
  339. /*
  340. * Asix callbacks
  341. */
  342. static int asix_init(struct eth_device *eth, bd_t *bd)
  343. {
  344. struct ueth_data *dev = (struct ueth_data *)eth->priv;
  345. int timeout = 0;
  346. #define TIMEOUT_RESOLUTION 50 /* ms */
  347. int link_detected;
  348. debug("** %s()\n", __func__);
  349. if (asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL) < 0)
  350. goto out_err;
  351. do {
  352. link_detected = asix_mdio_read(dev, dev->phy_id, MII_BMSR) &
  353. BMSR_LSTATUS;
  354. if (!link_detected) {
  355. if (timeout == 0)
  356. printf("Waiting for Ethernet connection... ");
  357. udelay(TIMEOUT_RESOLUTION * 1000);
  358. timeout += TIMEOUT_RESOLUTION;
  359. }
  360. } while (!link_detected && timeout < PHY_CONNECT_TIMEOUT);
  361. if (link_detected) {
  362. if (timeout != 0)
  363. printf("done.\n");
  364. } else {
  365. printf("unable to connect.\n");
  366. goto out_err;
  367. }
  368. return 0;
  369. out_err:
  370. return -1;
  371. }
  372. static int asix_send(struct eth_device *eth, void *packet, int length)
  373. {
  374. struct ueth_data *dev = (struct ueth_data *)eth->priv;
  375. int err;
  376. u32 packet_len;
  377. int actual_len;
  378. ALLOC_CACHE_ALIGN_BUFFER(unsigned char, msg,
  379. PKTSIZE + sizeof(packet_len));
  380. debug("** %s(), len %d\n", __func__, length);
  381. packet_len = (((length) ^ 0x0000ffff) << 16) + (length);
  382. cpu_to_le32s(&packet_len);
  383. memcpy(msg, &packet_len, sizeof(packet_len));
  384. memcpy(msg + sizeof(packet_len), (void *)packet, length);
  385. err = usb_bulk_msg(dev->pusb_dev,
  386. usb_sndbulkpipe(dev->pusb_dev, dev->ep_out),
  387. (void *)msg,
  388. length + sizeof(packet_len),
  389. &actual_len,
  390. USB_BULK_SEND_TIMEOUT);
  391. debug("Tx: len = %zu, actual = %u, err = %d\n",
  392. length + sizeof(packet_len), actual_len, err);
  393. return err;
  394. }
  395. static int asix_recv(struct eth_device *eth)
  396. {
  397. struct ueth_data *dev = (struct ueth_data *)eth->priv;
  398. ALLOC_CACHE_ALIGN_BUFFER(unsigned char, recv_buf, AX_RX_URB_SIZE);
  399. unsigned char *buf_ptr;
  400. int err;
  401. int actual_len;
  402. u32 packet_len;
  403. debug("** %s()\n", __func__);
  404. err = usb_bulk_msg(dev->pusb_dev,
  405. usb_rcvbulkpipe(dev->pusb_dev, dev->ep_in),
  406. (void *)recv_buf,
  407. AX_RX_URB_SIZE,
  408. &actual_len,
  409. USB_BULK_RECV_TIMEOUT);
  410. debug("Rx: len = %u, actual = %u, err = %d\n", AX_RX_URB_SIZE,
  411. actual_len, err);
  412. if (err != 0) {
  413. debug("Rx: failed to receive\n");
  414. return -1;
  415. }
  416. if (actual_len > AX_RX_URB_SIZE) {
  417. debug("Rx: received too many bytes %d\n", actual_len);
  418. return -1;
  419. }
  420. buf_ptr = recv_buf;
  421. while (actual_len > 0) {
  422. /*
  423. * 1st 4 bytes contain the length of the actual data as two
  424. * complementary 16-bit words. Extract the length of the data.
  425. */
  426. if (actual_len < sizeof(packet_len)) {
  427. debug("Rx: incomplete packet length\n");
  428. return -1;
  429. }
  430. memcpy(&packet_len, buf_ptr, sizeof(packet_len));
  431. le32_to_cpus(&packet_len);
  432. if (((~packet_len >> 16) & 0x7ff) != (packet_len & 0x7ff)) {
  433. debug("Rx: malformed packet length: %#x (%#x:%#x)\n",
  434. packet_len, (~packet_len >> 16) & 0x7ff,
  435. packet_len & 0x7ff);
  436. return -1;
  437. }
  438. packet_len = packet_len & 0x7ff;
  439. if (packet_len > actual_len - sizeof(packet_len)) {
  440. debug("Rx: too large packet: %d\n", packet_len);
  441. return -1;
  442. }
  443. /* Notify net stack */
  444. net_process_received_packet(buf_ptr + sizeof(packet_len),
  445. packet_len);
  446. /* Adjust for next iteration. Packets are padded to 16-bits */
  447. if (packet_len & 1)
  448. packet_len++;
  449. actual_len -= sizeof(packet_len) + packet_len;
  450. buf_ptr += sizeof(packet_len) + packet_len;
  451. }
  452. return err;
  453. }
  454. static void asix_halt(struct eth_device *eth)
  455. {
  456. debug("** %s()\n", __func__);
  457. }
  458. /*
  459. * Asix probing functions
  460. */
  461. void asix_eth_before_probe(void)
  462. {
  463. curr_eth_dev = 0;
  464. }
  465. struct asix_dongle {
  466. unsigned short vendor;
  467. unsigned short product;
  468. int flags;
  469. };
  470. static const struct asix_dongle asix_dongles[] = {
  471. { 0x05ac, 0x1402, FLAG_TYPE_AX88772 }, /* Apple USB Ethernet Adapter */
  472. { 0x07d1, 0x3c05, FLAG_TYPE_AX88772 }, /* D-Link DUB-E100 H/W Ver B1 */
  473. { 0x2001, 0x1a02, FLAG_TYPE_AX88772 }, /* D-Link DUB-E100 H/W Ver C1 */
  474. /* Cables-to-Go USB Ethernet Adapter */
  475. { 0x0b95, 0x772a, FLAG_TYPE_AX88772 },
  476. { 0x0b95, 0x7720, FLAG_TYPE_AX88772 }, /* Trendnet TU2-ET100 V3.0R */
  477. { 0x0b95, 0x1720, FLAG_TYPE_AX88172 }, /* SMC */
  478. { 0x0db0, 0xa877, FLAG_TYPE_AX88772 }, /* MSI - ASIX 88772a */
  479. { 0x13b1, 0x0018, FLAG_TYPE_AX88172 }, /* Linksys 200M v2.1 */
  480. { 0x1557, 0x7720, FLAG_TYPE_AX88772 }, /* 0Q0 cable ethernet */
  481. /* DLink DUB-E100 H/W Ver B1 Alternate */
  482. { 0x2001, 0x3c05, FLAG_TYPE_AX88772 },
  483. /* ASIX 88772B */
  484. { 0x0b95, 0x772b, FLAG_TYPE_AX88772B | FLAG_EEPROM_MAC },
  485. { 0x0b95, 0x7e2b, FLAG_TYPE_AX88772B },
  486. { 0x0000, 0x0000, FLAG_NONE } /* END - Do not remove */
  487. };
  488. /* Probe to see if a new device is actually an asix device */
  489. int asix_eth_probe(struct usb_device *dev, unsigned int ifnum,
  490. struct ueth_data *ss)
  491. {
  492. struct usb_interface *iface;
  493. struct usb_interface_descriptor *iface_desc;
  494. int ep_in_found = 0, ep_out_found = 0;
  495. int i;
  496. /* let's examine the device now */
  497. iface = &dev->config.if_desc[ifnum];
  498. iface_desc = &dev->config.if_desc[ifnum].desc;
  499. for (i = 0; asix_dongles[i].vendor != 0; i++) {
  500. if (dev->descriptor.idVendor == asix_dongles[i].vendor &&
  501. dev->descriptor.idProduct == asix_dongles[i].product)
  502. /* Found a supported dongle */
  503. break;
  504. }
  505. if (asix_dongles[i].vendor == 0)
  506. return 0;
  507. memset(ss, 0, sizeof(struct ueth_data));
  508. /* At this point, we know we've got a live one */
  509. debug("\n\nUSB Ethernet device detected: %#04x:%#04x\n",
  510. dev->descriptor.idVendor, dev->descriptor.idProduct);
  511. /* Initialize the ueth_data structure with some useful info */
  512. ss->ifnum = ifnum;
  513. ss->pusb_dev = dev;
  514. ss->subclass = iface_desc->bInterfaceSubClass;
  515. ss->protocol = iface_desc->bInterfaceProtocol;
  516. /* alloc driver private */
  517. ss->dev_priv = calloc(1, sizeof(struct asix_private));
  518. if (!ss->dev_priv)
  519. return 0;
  520. ((struct asix_private *)ss->dev_priv)->flags = asix_dongles[i].flags;
  521. /*
  522. * We are expecting a minimum of 3 endpoints - in, out (bulk), and
  523. * int. We will ignore any others.
  524. */
  525. for (i = 0; i < iface_desc->bNumEndpoints; i++) {
  526. /* is it an BULK endpoint? */
  527. if ((iface->ep_desc[i].bmAttributes &
  528. USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK) {
  529. u8 ep_addr = iface->ep_desc[i].bEndpointAddress;
  530. if (ep_addr & USB_DIR_IN) {
  531. if (!ep_in_found) {
  532. ss->ep_in = ep_addr &
  533. USB_ENDPOINT_NUMBER_MASK;
  534. ep_in_found = 1;
  535. }
  536. } else {
  537. if (!ep_out_found) {
  538. ss->ep_out = ep_addr &
  539. USB_ENDPOINT_NUMBER_MASK;
  540. ep_out_found = 1;
  541. }
  542. }
  543. }
  544. /* is it an interrupt endpoint? */
  545. if ((iface->ep_desc[i].bmAttributes &
  546. USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT) {
  547. ss->ep_int = iface->ep_desc[i].bEndpointAddress &
  548. USB_ENDPOINT_NUMBER_MASK;
  549. ss->irqinterval = iface->ep_desc[i].bInterval;
  550. }
  551. }
  552. debug("Endpoints In %d Out %d Int %d\n",
  553. ss->ep_in, ss->ep_out, ss->ep_int);
  554. /* Do some basic sanity checks, and bail if we find a problem */
  555. if (usb_set_interface(dev, iface_desc->bInterfaceNumber, 0) ||
  556. !ss->ep_in || !ss->ep_out || !ss->ep_int) {
  557. debug("Problems with device\n");
  558. return 0;
  559. }
  560. dev->privptr = (void *)ss;
  561. return 1;
  562. }
  563. int asix_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
  564. struct eth_device *eth)
  565. {
  566. struct asix_private *priv = (struct asix_private *)ss->dev_priv;
  567. if (!eth) {
  568. debug("%s: missing parameter.\n", __func__);
  569. return 0;
  570. }
  571. sprintf(eth->name, "%s%d", ASIX_BASE_NAME, curr_eth_dev++);
  572. eth->init = asix_init;
  573. eth->send = asix_send;
  574. eth->recv = asix_recv;
  575. eth->halt = asix_halt;
  576. if (!(priv->flags & FLAG_TYPE_AX88172))
  577. eth->write_hwaddr = asix_write_hwaddr;
  578. eth->priv = ss;
  579. if (asix_basic_reset(ss))
  580. return 0;
  581. /* Get the MAC address */
  582. if (asix_read_mac(eth))
  583. return 0;
  584. debug("MAC %pM\n", eth->enetaddr);
  585. return 1;
  586. }