mcs7830.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. /*
  2. * MOSCHIP MCS7830 based (7730/7830/7832) USB 2.0 Ethernet Devices
  3. *
  4. * based on usbnet.c, asix.c and the vendor provided mcs7830 driver
  5. *
  6. * Copyright (C) 2010 Andreas Mohr <andi@lisas.de>
  7. * Copyright (C) 2006 Arnd Bergmann <arnd@arndb.de>
  8. * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com>
  9. * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net>
  10. * Copyright (c) 2002-2003 TiVo Inc.
  11. *
  12. * Definitions gathered from MOSCHIP, Data Sheet_7830DA.pdf (thanks!).
  13. *
  14. * 2010-12-19: add 7832 USB PID ("functionality same as MCS7830"),
  15. * per active notification by manufacturer
  16. *
  17. * TODO:
  18. * - support HIF_REG_CONFIG_SLEEPMODE/HIF_REG_CONFIG_TXENABLE (via autopm?)
  19. * - implement ethtool_ops get_pauseparam/set_pauseparam
  20. * via HIF_REG_PAUSE_THRESHOLD (>= revision C only!)
  21. * - implement get_eeprom/[set_eeprom]
  22. * - switch PHY on/off on ifup/ifdown (perhaps in usbnet.c, via MII)
  23. * - mcs7830_get_regs() handling is weird: for rev 2 we return 32 regs,
  24. * can access only ~ 24, remaining user buffer is uninitialized garbage
  25. * - anything else?
  26. *
  27. *
  28. * This program is free software; you can redistribute it and/or modify
  29. * it under the terms of the GNU General Public License as published by
  30. * the Free Software Foundation; either version 2 of the License, or
  31. * (at your option) any later version.
  32. *
  33. * This program is distributed in the hope that it will be useful,
  34. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  35. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  36. * GNU General Public License for more details.
  37. *
  38. * You should have received a copy of the GNU General Public License
  39. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  40. */
  41. #include <linux/crc32.h>
  42. #include <linux/etherdevice.h>
  43. #include <linux/ethtool.h>
  44. #include <linux/mii.h>
  45. #include <linux/module.h>
  46. #include <linux/netdevice.h>
  47. #include <linux/slab.h>
  48. #include <linux/usb.h>
  49. #include <linux/usb/usbnet.h>
  50. /* requests */
  51. #define MCS7830_RD_BMREQ (USB_DIR_IN | USB_TYPE_VENDOR | \
  52. USB_RECIP_DEVICE)
  53. #define MCS7830_WR_BMREQ (USB_DIR_OUT | USB_TYPE_VENDOR | \
  54. USB_RECIP_DEVICE)
  55. #define MCS7830_RD_BREQ 0x0E
  56. #define MCS7830_WR_BREQ 0x0D
  57. #define MCS7830_CTRL_TIMEOUT 1000
  58. #define MCS7830_MAX_MCAST 64
  59. #define MCS7830_VENDOR_ID 0x9710
  60. #define MCS7832_PRODUCT_ID 0x7832
  61. #define MCS7830_PRODUCT_ID 0x7830
  62. #define MCS7730_PRODUCT_ID 0x7730
  63. #define SITECOM_VENDOR_ID 0x0DF6
  64. #define LN_030_PRODUCT_ID 0x0021
  65. #define MCS7830_MII_ADVERTISE (ADVERTISE_PAUSE_CAP | ADVERTISE_100FULL | \
  66. ADVERTISE_100HALF | ADVERTISE_10FULL | \
  67. ADVERTISE_10HALF | ADVERTISE_CSMA)
  68. /* HIF_REG_XX corresponding index value */
  69. enum {
  70. HIF_REG_MULTICAST_HASH = 0x00,
  71. HIF_REG_PACKET_GAP1 = 0x08,
  72. HIF_REG_PACKET_GAP2 = 0x09,
  73. HIF_REG_PHY_DATA = 0x0a,
  74. HIF_REG_PHY_CMD1 = 0x0c,
  75. HIF_REG_PHY_CMD1_READ = 0x40,
  76. HIF_REG_PHY_CMD1_WRITE = 0x20,
  77. HIF_REG_PHY_CMD1_PHYADDR = 0x01,
  78. HIF_REG_PHY_CMD2 = 0x0d,
  79. HIF_REG_PHY_CMD2_PEND_FLAG_BIT = 0x80,
  80. HIF_REG_PHY_CMD2_READY_FLAG_BIT = 0x40,
  81. HIF_REG_CONFIG = 0x0e,
  82. /* hmm, spec sez: "R/W", "Except bit 3" (likely TXENABLE). */
  83. HIF_REG_CONFIG_CFG = 0x80,
  84. HIF_REG_CONFIG_SPEED100 = 0x40,
  85. HIF_REG_CONFIG_FULLDUPLEX_ENABLE = 0x20,
  86. HIF_REG_CONFIG_RXENABLE = 0x10,
  87. HIF_REG_CONFIG_TXENABLE = 0x08,
  88. HIF_REG_CONFIG_SLEEPMODE = 0x04,
  89. HIF_REG_CONFIG_ALLMULTICAST = 0x02,
  90. HIF_REG_CONFIG_PROMISCUOUS = 0x01,
  91. HIF_REG_ETHERNET_ADDR = 0x0f,
  92. HIF_REG_FRAME_DROP_COUNTER = 0x15, /* 0..ff; reset: 0 */
  93. HIF_REG_PAUSE_THRESHOLD = 0x16,
  94. HIF_REG_PAUSE_THRESHOLD_DEFAULT = 0,
  95. };
  96. /* Trailing status byte in Ethernet Rx frame */
  97. enum {
  98. MCS7830_RX_SHORT_FRAME = 0x01, /* < 64 bytes */
  99. MCS7830_RX_LENGTH_ERROR = 0x02, /* framelen != Ethernet length field */
  100. MCS7830_RX_ALIGNMENT_ERROR = 0x04, /* non-even number of nibbles */
  101. MCS7830_RX_CRC_ERROR = 0x08,
  102. MCS7830_RX_LARGE_FRAME = 0x10, /* > 1518 bytes */
  103. MCS7830_RX_FRAME_CORRECT = 0x20, /* frame is correct */
  104. /* [7:6] reserved */
  105. };
  106. struct mcs7830_data {
  107. u8 multi_filter[8];
  108. u8 config;
  109. };
  110. static const char driver_name[] = "MOSCHIP usb-ethernet driver";
  111. static int mcs7830_get_reg(struct usbnet *dev, u16 index, u16 size, void *data)
  112. {
  113. return usbnet_read_cmd(dev, MCS7830_RD_BREQ, MCS7830_RD_BMREQ,
  114. 0x0000, index, data, size);
  115. }
  116. static int mcs7830_set_reg(struct usbnet *dev, u16 index, u16 size, const void *data)
  117. {
  118. return usbnet_write_cmd(dev, MCS7830_WR_BREQ, MCS7830_WR_BMREQ,
  119. 0x0000, index, data, size);
  120. }
  121. static void mcs7830_set_reg_async(struct usbnet *dev, u16 index, u16 size, void *data)
  122. {
  123. usbnet_write_cmd_async(dev, MCS7830_WR_BREQ, MCS7830_WR_BMREQ,
  124. 0x0000, index, data, size);
  125. }
  126. static int mcs7830_hif_get_mac_address(struct usbnet *dev, unsigned char *addr)
  127. {
  128. int ret = mcs7830_get_reg(dev, HIF_REG_ETHERNET_ADDR, ETH_ALEN, addr);
  129. if (ret < 0)
  130. return ret;
  131. return 0;
  132. }
  133. static int mcs7830_hif_set_mac_address(struct usbnet *dev, unsigned char *addr)
  134. {
  135. int ret = mcs7830_set_reg(dev, HIF_REG_ETHERNET_ADDR, ETH_ALEN, addr);
  136. if (ret < 0)
  137. return ret;
  138. return 0;
  139. }
  140. static int mcs7830_set_mac_address(struct net_device *netdev, void *p)
  141. {
  142. int ret;
  143. struct usbnet *dev = netdev_priv(netdev);
  144. struct sockaddr *addr = p;
  145. if (netif_running(netdev))
  146. return -EBUSY;
  147. if (!is_valid_ether_addr(addr->sa_data))
  148. return -EADDRNOTAVAIL;
  149. ret = mcs7830_hif_set_mac_address(dev, addr->sa_data);
  150. if (ret < 0)
  151. return ret;
  152. /* it worked --> adopt it on netdev side */
  153. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  154. return 0;
  155. }
  156. static int mcs7830_read_phy(struct usbnet *dev, u8 index)
  157. {
  158. int ret;
  159. int i;
  160. __le16 val;
  161. u8 cmd[2] = {
  162. HIF_REG_PHY_CMD1_READ | HIF_REG_PHY_CMD1_PHYADDR,
  163. HIF_REG_PHY_CMD2_PEND_FLAG_BIT | index,
  164. };
  165. mutex_lock(&dev->phy_mutex);
  166. /* write the MII command */
  167. ret = mcs7830_set_reg(dev, HIF_REG_PHY_CMD1, 2, cmd);
  168. if (ret < 0)
  169. goto out;
  170. /* wait for the data to become valid, should be within < 1ms */
  171. for (i = 0; i < 10; i++) {
  172. ret = mcs7830_get_reg(dev, HIF_REG_PHY_CMD1, 2, cmd);
  173. if ((ret < 0) || (cmd[1] & HIF_REG_PHY_CMD2_READY_FLAG_BIT))
  174. break;
  175. ret = -EIO;
  176. msleep(1);
  177. }
  178. if (ret < 0)
  179. goto out;
  180. /* read actual register contents */
  181. ret = mcs7830_get_reg(dev, HIF_REG_PHY_DATA, 2, &val);
  182. if (ret < 0)
  183. goto out;
  184. ret = le16_to_cpu(val);
  185. dev_dbg(&dev->udev->dev, "read PHY reg %02x: %04x (%d tries)\n",
  186. index, val, i);
  187. out:
  188. mutex_unlock(&dev->phy_mutex);
  189. return ret;
  190. }
  191. static int mcs7830_write_phy(struct usbnet *dev, u8 index, u16 val)
  192. {
  193. int ret;
  194. int i;
  195. __le16 le_val;
  196. u8 cmd[2] = {
  197. HIF_REG_PHY_CMD1_WRITE | HIF_REG_PHY_CMD1_PHYADDR,
  198. HIF_REG_PHY_CMD2_PEND_FLAG_BIT | (index & 0x1F),
  199. };
  200. mutex_lock(&dev->phy_mutex);
  201. /* write the new register contents */
  202. le_val = cpu_to_le16(val);
  203. ret = mcs7830_set_reg(dev, HIF_REG_PHY_DATA, 2, &le_val);
  204. if (ret < 0)
  205. goto out;
  206. /* write the MII command */
  207. ret = mcs7830_set_reg(dev, HIF_REG_PHY_CMD1, 2, cmd);
  208. if (ret < 0)
  209. goto out;
  210. /* wait for the command to be accepted by the PHY */
  211. for (i = 0; i < 10; i++) {
  212. ret = mcs7830_get_reg(dev, HIF_REG_PHY_CMD1, 2, cmd);
  213. if ((ret < 0) || (cmd[1] & HIF_REG_PHY_CMD2_READY_FLAG_BIT))
  214. break;
  215. ret = -EIO;
  216. msleep(1);
  217. }
  218. if (ret < 0)
  219. goto out;
  220. ret = 0;
  221. dev_dbg(&dev->udev->dev, "write PHY reg %02x: %04x (%d tries)\n",
  222. index, val, i);
  223. out:
  224. mutex_unlock(&dev->phy_mutex);
  225. return ret;
  226. }
  227. /*
  228. * This algorithm comes from the original mcs7830 version 1.4 driver,
  229. * not sure if it is needed.
  230. */
  231. static int mcs7830_set_autoneg(struct usbnet *dev, int ptrUserPhyMode)
  232. {
  233. int ret;
  234. /* Enable all media types */
  235. ret = mcs7830_write_phy(dev, MII_ADVERTISE, MCS7830_MII_ADVERTISE);
  236. /* First reset BMCR */
  237. if (!ret)
  238. ret = mcs7830_write_phy(dev, MII_BMCR, 0x0000);
  239. /* Enable Auto Neg */
  240. if (!ret)
  241. ret = mcs7830_write_phy(dev, MII_BMCR, BMCR_ANENABLE);
  242. /* Restart Auto Neg (Keep the Enable Auto Neg Bit Set) */
  243. if (!ret)
  244. ret = mcs7830_write_phy(dev, MII_BMCR,
  245. BMCR_ANENABLE | BMCR_ANRESTART );
  246. return ret;
  247. }
  248. /*
  249. * if we can read register 22, the chip revision is C or higher
  250. */
  251. static int mcs7830_get_rev(struct usbnet *dev)
  252. {
  253. u8 dummy[2];
  254. int ret;
  255. ret = mcs7830_get_reg(dev, HIF_REG_FRAME_DROP_COUNTER, 2, dummy);
  256. if (ret > 0)
  257. return 2; /* Rev C or later */
  258. return 1; /* earlier revision */
  259. }
  260. /*
  261. * On rev. C we need to set the pause threshold
  262. */
  263. static void mcs7830_rev_C_fixup(struct usbnet *dev)
  264. {
  265. u8 pause_threshold = HIF_REG_PAUSE_THRESHOLD_DEFAULT;
  266. int retry;
  267. for (retry = 0; retry < 2; retry++) {
  268. if (mcs7830_get_rev(dev) == 2) {
  269. dev_info(&dev->udev->dev, "applying rev.C fixup\n");
  270. mcs7830_set_reg(dev, HIF_REG_PAUSE_THRESHOLD,
  271. 1, &pause_threshold);
  272. }
  273. msleep(1);
  274. }
  275. }
  276. static int mcs7830_mdio_read(struct net_device *netdev, int phy_id,
  277. int location)
  278. {
  279. struct usbnet *dev = netdev_priv(netdev);
  280. return mcs7830_read_phy(dev, location);
  281. }
  282. static void mcs7830_mdio_write(struct net_device *netdev, int phy_id,
  283. int location, int val)
  284. {
  285. struct usbnet *dev = netdev_priv(netdev);
  286. mcs7830_write_phy(dev, location, val);
  287. }
  288. static int mcs7830_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
  289. {
  290. struct usbnet *dev = netdev_priv(net);
  291. return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
  292. }
  293. static inline struct mcs7830_data *mcs7830_get_data(struct usbnet *dev)
  294. {
  295. return (struct mcs7830_data *)&dev->data;
  296. }
  297. static void mcs7830_hif_update_multicast_hash(struct usbnet *dev)
  298. {
  299. struct mcs7830_data *data = mcs7830_get_data(dev);
  300. mcs7830_set_reg_async(dev, HIF_REG_MULTICAST_HASH,
  301. sizeof data->multi_filter,
  302. data->multi_filter);
  303. }
  304. static void mcs7830_hif_update_config(struct usbnet *dev)
  305. {
  306. /* implementation specific to data->config
  307. (argument needs to be heap-based anyway - USB DMA!) */
  308. struct mcs7830_data *data = mcs7830_get_data(dev);
  309. mcs7830_set_reg_async(dev, HIF_REG_CONFIG, 1, &data->config);
  310. }
  311. static void mcs7830_data_set_multicast(struct net_device *net)
  312. {
  313. struct usbnet *dev = netdev_priv(net);
  314. struct mcs7830_data *data = mcs7830_get_data(dev);
  315. memset(data->multi_filter, 0, sizeof data->multi_filter);
  316. data->config = HIF_REG_CONFIG_TXENABLE;
  317. /* this should not be needed, but it doesn't work otherwise */
  318. data->config |= HIF_REG_CONFIG_ALLMULTICAST;
  319. if (net->flags & IFF_PROMISC) {
  320. data->config |= HIF_REG_CONFIG_PROMISCUOUS;
  321. } else if (net->flags & IFF_ALLMULTI ||
  322. netdev_mc_count(net) > MCS7830_MAX_MCAST) {
  323. data->config |= HIF_REG_CONFIG_ALLMULTICAST;
  324. } else if (netdev_mc_empty(net)) {
  325. /* just broadcast and directed */
  326. } else {
  327. /* We use the 20 byte dev->data
  328. * for our 8 byte filter buffer
  329. * to avoid allocating memory that
  330. * is tricky to free later */
  331. struct netdev_hw_addr *ha;
  332. u32 crc_bits;
  333. /* Build the multicast hash filter. */
  334. netdev_for_each_mc_addr(ha, net) {
  335. crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26;
  336. data->multi_filter[crc_bits >> 3] |= 1 << (crc_bits & 7);
  337. }
  338. }
  339. }
  340. static int mcs7830_apply_base_config(struct usbnet *dev)
  341. {
  342. int ret;
  343. /* re-configure known MAC (suspend case etc.) */
  344. ret = mcs7830_hif_set_mac_address(dev, dev->net->dev_addr);
  345. if (ret) {
  346. dev_info(&dev->udev->dev, "Cannot set MAC address\n");
  347. goto out;
  348. }
  349. /* Set up PHY */
  350. ret = mcs7830_set_autoneg(dev, 0);
  351. if (ret) {
  352. dev_info(&dev->udev->dev, "Cannot set autoneg\n");
  353. goto out;
  354. }
  355. mcs7830_hif_update_multicast_hash(dev);
  356. mcs7830_hif_update_config(dev);
  357. mcs7830_rev_C_fixup(dev);
  358. ret = 0;
  359. out:
  360. return ret;
  361. }
  362. /* credits go to asix_set_multicast */
  363. static void mcs7830_set_multicast(struct net_device *net)
  364. {
  365. struct usbnet *dev = netdev_priv(net);
  366. mcs7830_data_set_multicast(net);
  367. mcs7830_hif_update_multicast_hash(dev);
  368. mcs7830_hif_update_config(dev);
  369. }
  370. static int mcs7830_get_regs_len(struct net_device *net)
  371. {
  372. struct usbnet *dev = netdev_priv(net);
  373. switch (mcs7830_get_rev(dev)) {
  374. case 1:
  375. return 21;
  376. case 2:
  377. return 32;
  378. }
  379. return 0;
  380. }
  381. static void mcs7830_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *drvinfo)
  382. {
  383. usbnet_get_drvinfo(net, drvinfo);
  384. }
  385. static void mcs7830_get_regs(struct net_device *net, struct ethtool_regs *regs, void *data)
  386. {
  387. struct usbnet *dev = netdev_priv(net);
  388. regs->version = mcs7830_get_rev(dev);
  389. mcs7830_get_reg(dev, 0, regs->len, data);
  390. }
  391. static const struct ethtool_ops mcs7830_ethtool_ops = {
  392. .get_drvinfo = mcs7830_get_drvinfo,
  393. .get_regs_len = mcs7830_get_regs_len,
  394. .get_regs = mcs7830_get_regs,
  395. /* common usbnet calls */
  396. .get_link = usbnet_get_link,
  397. .get_msglevel = usbnet_get_msglevel,
  398. .set_msglevel = usbnet_set_msglevel,
  399. .get_settings = usbnet_get_settings,
  400. .set_settings = usbnet_set_settings,
  401. .nway_reset = usbnet_nway_reset,
  402. };
  403. static const struct net_device_ops mcs7830_netdev_ops = {
  404. .ndo_open = usbnet_open,
  405. .ndo_stop = usbnet_stop,
  406. .ndo_start_xmit = usbnet_start_xmit,
  407. .ndo_tx_timeout = usbnet_tx_timeout,
  408. .ndo_change_mtu = usbnet_change_mtu,
  409. .ndo_validate_addr = eth_validate_addr,
  410. .ndo_do_ioctl = mcs7830_ioctl,
  411. .ndo_set_rx_mode = mcs7830_set_multicast,
  412. .ndo_set_mac_address = mcs7830_set_mac_address,
  413. };
  414. static int mcs7830_bind(struct usbnet *dev, struct usb_interface *udev)
  415. {
  416. struct net_device *net = dev->net;
  417. int ret;
  418. int retry;
  419. /* Initial startup: Gather MAC address setting from EEPROM */
  420. ret = -EINVAL;
  421. for (retry = 0; retry < 5 && ret; retry++)
  422. ret = mcs7830_hif_get_mac_address(dev, net->dev_addr);
  423. if (ret) {
  424. dev_warn(&dev->udev->dev, "Cannot read MAC address\n");
  425. goto out;
  426. }
  427. mcs7830_data_set_multicast(net);
  428. ret = mcs7830_apply_base_config(dev);
  429. if (ret)
  430. goto out;
  431. net->ethtool_ops = &mcs7830_ethtool_ops;
  432. net->netdev_ops = &mcs7830_netdev_ops;
  433. /* reserve space for the status byte on rx */
  434. dev->rx_urb_size = ETH_FRAME_LEN + 1;
  435. dev->mii.mdio_read = mcs7830_mdio_read;
  436. dev->mii.mdio_write = mcs7830_mdio_write;
  437. dev->mii.dev = net;
  438. dev->mii.phy_id_mask = 0x3f;
  439. dev->mii.reg_num_mask = 0x1f;
  440. dev->mii.phy_id = *((u8 *) net->dev_addr + 1);
  441. ret = usbnet_get_endpoints(dev, udev);
  442. out:
  443. return ret;
  444. }
  445. /* The chip always appends a status byte that we need to strip */
  446. static int mcs7830_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
  447. {
  448. u8 status;
  449. /* This check is no longer done by usbnet */
  450. if (skb->len < dev->net->hard_header_len) {
  451. dev_err(&dev->udev->dev, "unexpected tiny rx frame\n");
  452. return 0;
  453. }
  454. skb_trim(skb, skb->len - 1);
  455. status = skb->data[skb->len];
  456. if (status != MCS7830_RX_FRAME_CORRECT) {
  457. dev_dbg(&dev->udev->dev, "rx fixup status %x\n", status);
  458. /* hmm, perhaps usbnet.c already sees a globally visible
  459. frame error and increments rx_errors on its own already? */
  460. dev->net->stats.rx_errors++;
  461. if (status & (MCS7830_RX_SHORT_FRAME
  462. |MCS7830_RX_LENGTH_ERROR
  463. |MCS7830_RX_LARGE_FRAME))
  464. dev->net->stats.rx_length_errors++;
  465. if (status & MCS7830_RX_ALIGNMENT_ERROR)
  466. dev->net->stats.rx_frame_errors++;
  467. if (status & MCS7830_RX_CRC_ERROR)
  468. dev->net->stats.rx_crc_errors++;
  469. }
  470. return skb->len > 0;
  471. }
  472. static void mcs7830_status(struct usbnet *dev, struct urb *urb)
  473. {
  474. u8 *buf = urb->transfer_buffer;
  475. bool link, link_changed;
  476. if (urb->actual_length < 16)
  477. return;
  478. link = !(buf[1] == 0x20);
  479. link_changed = netif_carrier_ok(dev->net) != link;
  480. if (link_changed) {
  481. usbnet_link_change(dev, link, 0);
  482. netdev_dbg(dev->net, "Link Status is: %d\n", link);
  483. }
  484. }
  485. static const struct driver_info moschip_info = {
  486. .description = "MOSCHIP 7830/7832/7730 usb-NET adapter",
  487. .bind = mcs7830_bind,
  488. .rx_fixup = mcs7830_rx_fixup,
  489. .flags = FLAG_ETHER | FLAG_LINK_INTR,
  490. .status = mcs7830_status,
  491. .in = 1,
  492. .out = 2,
  493. };
  494. static const struct driver_info sitecom_info = {
  495. .description = "Sitecom LN-30 usb-NET adapter",
  496. .bind = mcs7830_bind,
  497. .rx_fixup = mcs7830_rx_fixup,
  498. .flags = FLAG_ETHER | FLAG_LINK_INTR,
  499. .status = mcs7830_status,
  500. .in = 1,
  501. .out = 2,
  502. };
  503. static const struct usb_device_id products[] = {
  504. {
  505. USB_DEVICE(MCS7830_VENDOR_ID, MCS7832_PRODUCT_ID),
  506. .driver_info = (unsigned long) &moschip_info,
  507. },
  508. {
  509. USB_DEVICE(MCS7830_VENDOR_ID, MCS7830_PRODUCT_ID),
  510. .driver_info = (unsigned long) &moschip_info,
  511. },
  512. {
  513. USB_DEVICE(MCS7830_VENDOR_ID, MCS7730_PRODUCT_ID),
  514. .driver_info = (unsigned long) &moschip_info,
  515. },
  516. {
  517. USB_DEVICE(SITECOM_VENDOR_ID, LN_030_PRODUCT_ID),
  518. .driver_info = (unsigned long) &sitecom_info,
  519. },
  520. {},
  521. };
  522. MODULE_DEVICE_TABLE(usb, products);
  523. static int mcs7830_reset_resume (struct usb_interface *intf)
  524. {
  525. /* YES, this function is successful enough that ethtool -d
  526. does show same output pre-/post-suspend */
  527. struct usbnet *dev = usb_get_intfdata(intf);
  528. mcs7830_apply_base_config(dev);
  529. usbnet_resume(intf);
  530. return 0;
  531. }
  532. static struct usb_driver mcs7830_driver = {
  533. .name = driver_name,
  534. .id_table = products,
  535. .probe = usbnet_probe,
  536. .disconnect = usbnet_disconnect,
  537. .suspend = usbnet_suspend,
  538. .resume = usbnet_resume,
  539. .reset_resume = mcs7830_reset_resume,
  540. .disable_hub_initiated_lpm = 1,
  541. };
  542. module_usb_driver(mcs7830_driver);
  543. MODULE_DESCRIPTION("USB to network adapter MCS7830)");
  544. MODULE_LICENSE("GPL");