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