mcs7830.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. /*
  2. * MosChips MCS7830 based 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. * TODO:
  15. * - add .reset_resume support (iface is _gone_ after resume w/ power loss)
  16. * - verify that mcs7830_get_regs() does have same output pre-/post-suspend
  17. * - support HIF_REG_CONFIG_SLEEPMODE/HIF_REG_CONFIG_TXENABLE (via autopm?)
  18. * - implement ethtool_ops get_pauseparam/set_pauseparam
  19. * via HIF_REG_PAUSE_THRESHOLD (>= revision C only!)
  20. * - implement get_eeprom/[set_eeprom]
  21. * - switch PHY on/off on ifup/ifdown (perhaps in usbnet.c, via MII)
  22. * - mcs7830_get_regs() handling is weird: for rev 2 we return 32 regs,
  23. * can access only ~ 24, remaining user buffer is uninitialized garbage
  24. * - anything else?
  25. *
  26. *
  27. * This program is free software; you can redistribute it and/or modify
  28. * it under the terms of the GNU General Public License as published by
  29. * the Free Software Foundation; either version 2 of the License, or
  30. * (at your option) any later version.
  31. *
  32. * This program is distributed in the hope that it will be useful,
  33. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  34. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  35. * GNU General Public License for more details.
  36. *
  37. * You should have received a copy of the GNU General Public License
  38. * along with this program; if not, write to the Free Software
  39. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  40. */
  41. #include <linux/crc32.h>
  42. #include <linux/etherdevice.h>
  43. #include <linux/ethtool.h>
  44. #include <linux/init.h>
  45. #include <linux/mii.h>
  46. #include <linux/module.h>
  47. #include <linux/netdevice.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 MCS7830_PRODUCT_ID 0x7830
  61. #define MCS7730_PRODUCT_ID 0x7730
  62. #define SITECOM_VENDOR_ID 0x0DF6
  63. #define LN_030_PRODUCT_ID 0x0021
  64. #define MCS7830_MII_ADVERTISE (ADVERTISE_PAUSE_CAP | ADVERTISE_100FULL | \
  65. ADVERTISE_100HALF | ADVERTISE_10FULL | \
  66. ADVERTISE_10HALF | ADVERTISE_CSMA)
  67. /* HIF_REG_XX coressponding index value */
  68. enum {
  69. HIF_REG_MULTICAST_HASH = 0x00,
  70. HIF_REG_PACKET_GAP1 = 0x08,
  71. HIF_REG_PACKET_GAP2 = 0x09,
  72. HIF_REG_PHY_DATA = 0x0a,
  73. HIF_REG_PHY_CMD1 = 0x0c,
  74. HIF_REG_PHY_CMD1_READ = 0x40,
  75. HIF_REG_PHY_CMD1_WRITE = 0x20,
  76. HIF_REG_PHY_CMD1_PHYADDR = 0x01,
  77. HIF_REG_PHY_CMD2 = 0x0d,
  78. HIF_REG_PHY_CMD2_PEND_FLAG_BIT = 0x80,
  79. HIF_REG_PHY_CMD2_READY_FLAG_BIT = 0x40,
  80. HIF_REG_CONFIG = 0x0e,
  81. HIF_REG_CONFIG_CFG = 0x80,
  82. HIF_REG_CONFIG_SPEED100 = 0x40,
  83. HIF_REG_CONFIG_FULLDUPLEX_ENABLE = 0x20,
  84. HIF_REG_CONFIG_RXENABLE = 0x10,
  85. HIF_REG_CONFIG_TXENABLE = 0x08,
  86. HIF_REG_CONFIG_SLEEPMODE = 0x04,
  87. HIF_REG_CONFIG_ALLMULTICAST = 0x02,
  88. HIF_REG_CONFIG_PROMISCIOUS = 0x01,
  89. HIF_REG_ETHERNET_ADDR = 0x0f,
  90. HIF_REG_22 = 0x15,
  91. HIF_REG_PAUSE_THRESHOLD = 0x16,
  92. HIF_REG_PAUSE_THRESHOLD_DEFAULT = 0,
  93. };
  94. /* Trailing status byte in Ethernet Rx frame */
  95. enum {
  96. MCS7830_RX_SHORT_FRAME = 0x01, /* < 64 bytes */
  97. MCS7830_RX_LENGTH_ERROR = 0x02, /* framelen != Ethernet length field */
  98. MCS7830_RX_ALIGNMENT_ERROR = 0x04, /* non-even number of nibbles */
  99. MCS7830_RX_CRC_ERROR = 0x08,
  100. MCS7830_RX_LARGE_FRAME = 0x10, /* > 1518 bytes */
  101. MCS7830_RX_FRAME_CORRECT = 0x20, /* frame is correct */
  102. /* [7:6] reserved */
  103. };
  104. struct mcs7830_data {
  105. u8 multi_filter[8];
  106. u8 config;
  107. };
  108. static const char driver_name[] = "MOSCHIP usb-ethernet driver";
  109. static int mcs7830_get_reg(struct usbnet *dev, u16 index, u16 size, void *data)
  110. {
  111. struct usb_device *xdev = dev->udev;
  112. int ret;
  113. void *buffer;
  114. buffer = kmalloc(size, GFP_NOIO);
  115. if (buffer == NULL)
  116. return -ENOMEM;
  117. ret = usb_control_msg(xdev, usb_rcvctrlpipe(xdev, 0), MCS7830_RD_BREQ,
  118. MCS7830_RD_BMREQ, 0x0000, index, buffer,
  119. size, MCS7830_CTRL_TIMEOUT);
  120. memcpy(data, buffer, size);
  121. kfree(buffer);
  122. return ret;
  123. }
  124. static int mcs7830_set_reg(struct usbnet *dev, u16 index, u16 size, void *data)
  125. {
  126. struct usb_device *xdev = dev->udev;
  127. int ret;
  128. void *buffer;
  129. buffer = kmalloc(size, GFP_NOIO);
  130. if (buffer == NULL)
  131. return -ENOMEM;
  132. memcpy(buffer, data, size);
  133. ret = usb_control_msg(xdev, usb_sndctrlpipe(xdev, 0), MCS7830_WR_BREQ,
  134. MCS7830_WR_BMREQ, 0x0000, index, buffer,
  135. size, MCS7830_CTRL_TIMEOUT);
  136. kfree(buffer);
  137. return ret;
  138. }
  139. static void mcs7830_async_cmd_callback(struct urb *urb)
  140. {
  141. struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context;
  142. int status = urb->status;
  143. if (status < 0)
  144. printk(KERN_DEBUG "%s() failed with %d\n",
  145. __func__, status);
  146. kfree(req);
  147. usb_free_urb(urb);
  148. }
  149. static void mcs7830_set_reg_async(struct usbnet *dev, u16 index, u16 size, void *data)
  150. {
  151. struct usb_ctrlrequest *req;
  152. int ret;
  153. struct urb *urb;
  154. urb = usb_alloc_urb(0, GFP_ATOMIC);
  155. if (!urb) {
  156. dev_dbg(&dev->udev->dev,
  157. "Error allocating URB in write_cmd_async!\n");
  158. return;
  159. }
  160. req = kmalloc(sizeof *req, GFP_ATOMIC);
  161. if (!req) {
  162. dev_err(&dev->udev->dev,
  163. "Failed to allocate memory for control request\n");
  164. goto out;
  165. }
  166. req->bRequestType = MCS7830_WR_BMREQ;
  167. req->bRequest = MCS7830_WR_BREQ;
  168. req->wValue = 0;
  169. req->wIndex = cpu_to_le16(index);
  170. req->wLength = cpu_to_le16(size);
  171. usb_fill_control_urb(urb, dev->udev,
  172. usb_sndctrlpipe(dev->udev, 0),
  173. (void *)req, data, size,
  174. mcs7830_async_cmd_callback, req);
  175. ret = usb_submit_urb(urb, GFP_ATOMIC);
  176. if (ret < 0) {
  177. dev_err(&dev->udev->dev,
  178. "Error submitting the control message: ret=%d\n", ret);
  179. goto out;
  180. }
  181. return;
  182. out:
  183. kfree(req);
  184. usb_free_urb(urb);
  185. }
  186. static int mcs7830_get_address(struct usbnet *dev)
  187. {
  188. int ret;
  189. ret = mcs7830_get_reg(dev, HIF_REG_ETHERNET_ADDR, ETH_ALEN,
  190. dev->net->dev_addr);
  191. if (ret < 0)
  192. return ret;
  193. return 0;
  194. }
  195. static int mcs7830_read_phy(struct usbnet *dev, u8 index)
  196. {
  197. int ret;
  198. int i;
  199. __le16 val;
  200. u8 cmd[2] = {
  201. HIF_REG_PHY_CMD1_READ | HIF_REG_PHY_CMD1_PHYADDR,
  202. HIF_REG_PHY_CMD2_PEND_FLAG_BIT | index,
  203. };
  204. mutex_lock(&dev->phy_mutex);
  205. /* write the MII command */
  206. ret = mcs7830_set_reg(dev, HIF_REG_PHY_CMD1, 2, cmd);
  207. if (ret < 0)
  208. goto out;
  209. /* wait for the data to become valid, should be within < 1ms */
  210. for (i = 0; i < 10; i++) {
  211. ret = mcs7830_get_reg(dev, HIF_REG_PHY_CMD1, 2, cmd);
  212. if ((ret < 0) || (cmd[1] & HIF_REG_PHY_CMD2_READY_FLAG_BIT))
  213. break;
  214. ret = -EIO;
  215. msleep(1);
  216. }
  217. if (ret < 0)
  218. goto out;
  219. /* read actual register contents */
  220. ret = mcs7830_get_reg(dev, HIF_REG_PHY_DATA, 2, &val);
  221. if (ret < 0)
  222. goto out;
  223. ret = le16_to_cpu(val);
  224. dev_dbg(&dev->udev->dev, "read PHY reg %02x: %04x (%d tries)\n",
  225. index, val, i);
  226. out:
  227. mutex_unlock(&dev->phy_mutex);
  228. return ret;
  229. }
  230. static int mcs7830_write_phy(struct usbnet *dev, u8 index, u16 val)
  231. {
  232. int ret;
  233. int i;
  234. __le16 le_val;
  235. u8 cmd[2] = {
  236. HIF_REG_PHY_CMD1_WRITE | HIF_REG_PHY_CMD1_PHYADDR,
  237. HIF_REG_PHY_CMD2_PEND_FLAG_BIT | (index & 0x1F),
  238. };
  239. mutex_lock(&dev->phy_mutex);
  240. /* write the new register contents */
  241. le_val = cpu_to_le16(val);
  242. ret = mcs7830_set_reg(dev, HIF_REG_PHY_DATA, 2, &le_val);
  243. if (ret < 0)
  244. goto out;
  245. /* write the MII command */
  246. ret = mcs7830_set_reg(dev, HIF_REG_PHY_CMD1, 2, cmd);
  247. if (ret < 0)
  248. goto out;
  249. /* wait for the command to be accepted by the PHY */
  250. for (i = 0; i < 10; i++) {
  251. ret = mcs7830_get_reg(dev, HIF_REG_PHY_CMD1, 2, cmd);
  252. if ((ret < 0) || (cmd[1] & HIF_REG_PHY_CMD2_READY_FLAG_BIT))
  253. break;
  254. ret = -EIO;
  255. msleep(1);
  256. }
  257. if (ret < 0)
  258. goto out;
  259. ret = 0;
  260. dev_dbg(&dev->udev->dev, "write PHY reg %02x: %04x (%d tries)\n",
  261. index, val, i);
  262. out:
  263. mutex_unlock(&dev->phy_mutex);
  264. return ret;
  265. }
  266. /*
  267. * This algorithm comes from the original mcs7830 version 1.4 driver,
  268. * not sure if it is needed.
  269. */
  270. static int mcs7830_set_autoneg(struct usbnet *dev, int ptrUserPhyMode)
  271. {
  272. int ret;
  273. /* Enable all media types */
  274. ret = mcs7830_write_phy(dev, MII_ADVERTISE, MCS7830_MII_ADVERTISE);
  275. /* First reset BMCR */
  276. if (!ret)
  277. ret = mcs7830_write_phy(dev, MII_BMCR, 0x0000);
  278. /* Enable Auto Neg */
  279. if (!ret)
  280. ret = mcs7830_write_phy(dev, MII_BMCR, BMCR_ANENABLE);
  281. /* Restart Auto Neg (Keep the Enable Auto Neg Bit Set) */
  282. if (!ret)
  283. ret = mcs7830_write_phy(dev, MII_BMCR,
  284. BMCR_ANENABLE | BMCR_ANRESTART );
  285. return ret < 0 ? : 0;
  286. }
  287. /*
  288. * if we can read register 22, the chip revision is C or higher
  289. */
  290. static int mcs7830_get_rev(struct usbnet *dev)
  291. {
  292. u8 dummy[2];
  293. int ret;
  294. ret = mcs7830_get_reg(dev, HIF_REG_22, 2, dummy);
  295. if (ret > 0)
  296. return 2; /* Rev C or later */
  297. return 1; /* earlier revision */
  298. }
  299. /*
  300. * On rev. C we need to set the pause threshold
  301. */
  302. static void mcs7830_rev_C_fixup(struct usbnet *dev)
  303. {
  304. u8 pause_threshold = HIF_REG_PAUSE_THRESHOLD_DEFAULT;
  305. int retry;
  306. for (retry = 0; retry < 2; retry++) {
  307. if (mcs7830_get_rev(dev) == 2) {
  308. dev_info(&dev->udev->dev, "applying rev.C fixup\n");
  309. mcs7830_set_reg(dev, HIF_REG_PAUSE_THRESHOLD,
  310. 1, &pause_threshold);
  311. }
  312. msleep(1);
  313. }
  314. }
  315. static int mcs7830_init_dev(struct usbnet *dev)
  316. {
  317. int ret;
  318. int retry;
  319. /* Read MAC address from EEPROM */
  320. ret = -EINVAL;
  321. for (retry = 0; retry < 5 && ret; retry++)
  322. ret = mcs7830_get_address(dev);
  323. if (ret) {
  324. dev_warn(&dev->udev->dev, "Cannot read MAC address\n");
  325. goto out;
  326. }
  327. /* Set up PHY */
  328. ret = mcs7830_set_autoneg(dev, 0);
  329. if (ret) {
  330. dev_info(&dev->udev->dev, "Cannot set autoneg\n");
  331. goto out;
  332. }
  333. mcs7830_rev_C_fixup(dev);
  334. ret = 0;
  335. out:
  336. return ret;
  337. }
  338. static int mcs7830_mdio_read(struct net_device *netdev, int phy_id,
  339. int location)
  340. {
  341. struct usbnet *dev = netdev_priv(netdev);
  342. return mcs7830_read_phy(dev, location);
  343. }
  344. static void mcs7830_mdio_write(struct net_device *netdev, int phy_id,
  345. int location, int val)
  346. {
  347. struct usbnet *dev = netdev_priv(netdev);
  348. mcs7830_write_phy(dev, location, val);
  349. }
  350. static int mcs7830_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
  351. {
  352. struct usbnet *dev = netdev_priv(net);
  353. return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
  354. }
  355. /* credits go to asix_set_multicast */
  356. static void mcs7830_set_multicast(struct net_device *net)
  357. {
  358. struct usbnet *dev = netdev_priv(net);
  359. struct mcs7830_data *data = (struct mcs7830_data *)&dev->data;
  360. data->config = HIF_REG_CONFIG_TXENABLE;
  361. /* this should not be needed, but it doesn't work otherwise */
  362. data->config |= HIF_REG_CONFIG_ALLMULTICAST;
  363. if (net->flags & IFF_PROMISC) {
  364. data->config |= HIF_REG_CONFIG_PROMISCIOUS;
  365. } else if (net->flags & IFF_ALLMULTI ||
  366. net->mc_count > MCS7830_MAX_MCAST) {
  367. data->config |= HIF_REG_CONFIG_ALLMULTICAST;
  368. } else if (net->mc_count == 0) {
  369. /* just broadcast and directed */
  370. } else {
  371. /* We use the 20 byte dev->data
  372. * for our 8 byte filter buffer
  373. * to avoid allocating memory that
  374. * is tricky to free later */
  375. struct dev_mc_list *mc_list = net->mc_list;
  376. u32 crc_bits;
  377. int i;
  378. memset(data->multi_filter, 0, sizeof data->multi_filter);
  379. /* Build the multicast hash filter. */
  380. for (i = 0; i < net->mc_count; i++) {
  381. crc_bits = ether_crc(ETH_ALEN, mc_list->dmi_addr) >> 26;
  382. data->multi_filter[crc_bits >> 3] |= 1 << (crc_bits & 7);
  383. mc_list = mc_list->next;
  384. }
  385. mcs7830_set_reg_async(dev, HIF_REG_MULTICAST_HASH,
  386. sizeof data->multi_filter,
  387. data->multi_filter);
  388. }
  389. mcs7830_set_reg_async(dev, HIF_REG_CONFIG, 1, &data->config);
  390. }
  391. static int mcs7830_get_regs_len(struct net_device *net)
  392. {
  393. struct usbnet *dev = netdev_priv(net);
  394. switch (mcs7830_get_rev(dev)) {
  395. case 1:
  396. return 21;
  397. case 2:
  398. return 32;
  399. }
  400. return 0;
  401. }
  402. static void mcs7830_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *drvinfo)
  403. {
  404. usbnet_get_drvinfo(net, drvinfo);
  405. drvinfo->regdump_len = mcs7830_get_regs_len(net);
  406. }
  407. static void mcs7830_get_regs(struct net_device *net, struct ethtool_regs *regs, void *data)
  408. {
  409. struct usbnet *dev = netdev_priv(net);
  410. regs->version = mcs7830_get_rev(dev);
  411. mcs7830_get_reg(dev, 0, regs->len, data);
  412. }
  413. static const struct ethtool_ops mcs7830_ethtool_ops = {
  414. .get_drvinfo = mcs7830_get_drvinfo,
  415. .get_regs_len = mcs7830_get_regs_len,
  416. .get_regs = mcs7830_get_regs,
  417. /* common usbnet calls */
  418. .get_link = usbnet_get_link,
  419. .get_msglevel = usbnet_get_msglevel,
  420. .set_msglevel = usbnet_set_msglevel,
  421. .get_settings = usbnet_get_settings,
  422. .set_settings = usbnet_set_settings,
  423. .nway_reset = usbnet_nway_reset,
  424. };
  425. static int mcs7830_set_mac_address(struct net_device *netdev, void *p)
  426. {
  427. int ret;
  428. struct usbnet *dev = netdev_priv(netdev);
  429. struct sockaddr *addr = p;
  430. if (netif_running(netdev))
  431. return -EBUSY;
  432. if (!is_valid_ether_addr(addr->sa_data))
  433. return -EINVAL;
  434. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  435. ret = mcs7830_set_reg(dev, HIF_REG_ETHERNET_ADDR, ETH_ALEN,
  436. netdev->dev_addr);
  437. if (ret < 0)
  438. return ret;
  439. return 0;
  440. }
  441. static const struct net_device_ops mcs7830_netdev_ops = {
  442. .ndo_open = usbnet_open,
  443. .ndo_stop = usbnet_stop,
  444. .ndo_start_xmit = usbnet_start_xmit,
  445. .ndo_tx_timeout = usbnet_tx_timeout,
  446. .ndo_change_mtu = usbnet_change_mtu,
  447. .ndo_validate_addr = eth_validate_addr,
  448. .ndo_do_ioctl = mcs7830_ioctl,
  449. .ndo_set_multicast_list = mcs7830_set_multicast,
  450. .ndo_set_mac_address = mcs7830_set_mac_address,
  451. };
  452. static int mcs7830_bind(struct usbnet *dev, struct usb_interface *udev)
  453. {
  454. struct net_device *net = dev->net;
  455. int ret;
  456. ret = mcs7830_init_dev(dev);
  457. if (ret)
  458. goto out;
  459. net->ethtool_ops = &mcs7830_ethtool_ops;
  460. net->netdev_ops = &mcs7830_netdev_ops;
  461. mcs7830_set_multicast(net);
  462. /* reserve space for the status byte on rx */
  463. dev->rx_urb_size = ETH_FRAME_LEN + 1;
  464. dev->mii.mdio_read = mcs7830_mdio_read;
  465. dev->mii.mdio_write = mcs7830_mdio_write;
  466. dev->mii.dev = net;
  467. dev->mii.phy_id_mask = 0x3f;
  468. dev->mii.reg_num_mask = 0x1f;
  469. dev->mii.phy_id = *((u8 *) net->dev_addr + 1);
  470. ret = usbnet_get_endpoints(dev, udev);
  471. out:
  472. return ret;
  473. }
  474. /* The chip always appends a status bytes that we need to strip */
  475. static int mcs7830_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
  476. {
  477. u8 status;
  478. if (skb->len == 0) {
  479. dev_err(&dev->udev->dev, "unexpected empty rx frame\n");
  480. return 0;
  481. }
  482. skb_trim(skb, skb->len - 1);
  483. status = skb->data[skb->len];
  484. if (status != MCS7830_RX_FRAME_CORRECT) {
  485. dev_dbg(&dev->udev->dev, "rx fixup status %x\n", status);
  486. /* hmm, perhaps usbnet.c already sees a globally visible
  487. frame error and increments rx_errors on its own already? */
  488. dev->net->stats.rx_errors++;
  489. if (status & (MCS7830_RX_SHORT_FRAME
  490. |MCS7830_RX_LENGTH_ERROR
  491. |MCS7830_RX_LARGE_FRAME))
  492. dev->net->stats.rx_length_errors++;
  493. if (status & MCS7830_RX_ALIGNMENT_ERROR)
  494. dev->net->stats.rx_frame_errors++;
  495. if (status & MCS7830_RX_CRC_ERROR)
  496. dev->net->stats.rx_crc_errors++;
  497. }
  498. return skb->len > 0;
  499. }
  500. static const struct driver_info moschip_info = {
  501. .description = "MOSCHIP 7830/7730 usb-NET adapter",
  502. .bind = mcs7830_bind,
  503. .rx_fixup = mcs7830_rx_fixup,
  504. .flags = FLAG_ETHER,
  505. .in = 1,
  506. .out = 2,
  507. };
  508. static const struct driver_info sitecom_info = {
  509. .description = "Sitecom LN-30 usb-NET adapter",
  510. .bind = mcs7830_bind,
  511. .rx_fixup = mcs7830_rx_fixup,
  512. .flags = FLAG_ETHER,
  513. .in = 1,
  514. .out = 2,
  515. };
  516. static const struct usb_device_id products[] = {
  517. {
  518. USB_DEVICE(MCS7830_VENDOR_ID, MCS7830_PRODUCT_ID),
  519. .driver_info = (unsigned long) &moschip_info,
  520. },
  521. {
  522. USB_DEVICE(MCS7830_VENDOR_ID, MCS7730_PRODUCT_ID),
  523. .driver_info = (unsigned long) &moschip_info,
  524. },
  525. {
  526. USB_DEVICE(SITECOM_VENDOR_ID, LN_030_PRODUCT_ID),
  527. .driver_info = (unsigned long) &sitecom_info,
  528. },
  529. {},
  530. };
  531. MODULE_DEVICE_TABLE(usb, products);
  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. };
  540. static int __init mcs7830_init(void)
  541. {
  542. return usb_register(&mcs7830_driver);
  543. }
  544. module_init(mcs7830_init);
  545. static void __exit mcs7830_exit(void)
  546. {
  547. usb_deregister(&mcs7830_driver);
  548. }
  549. module_exit(mcs7830_exit);
  550. MODULE_DESCRIPTION("USB to network adapter MCS7830)");
  551. MODULE_LICENSE("GPL");