Linux Audio

Check our new training course

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