asix.c 16 KB

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