asix.c 18 KB

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