45 #include <linux/ethtool.h>
47 #include <linux/mii.h>
48 #include <linux/module.h>
49 #include <linux/netdevice.h>
50 #include <linux/slab.h>
55 #define MCS7830_RD_BMREQ (USB_DIR_IN | USB_TYPE_VENDOR | \
57 #define MCS7830_WR_BMREQ (USB_DIR_OUT | USB_TYPE_VENDOR | \
59 #define MCS7830_RD_BREQ 0x0E
60 #define MCS7830_WR_BREQ 0x0D
62 #define MCS7830_CTRL_TIMEOUT 1000
63 #define MCS7830_MAX_MCAST 64
65 #define MCS7830_VENDOR_ID 0x9710
66 #define MCS7832_PRODUCT_ID 0x7832
67 #define MCS7830_PRODUCT_ID 0x7830
68 #define MCS7730_PRODUCT_ID 0x7730
70 #define SITECOM_VENDOR_ID 0x0DF6
71 #define LN_030_PRODUCT_ID 0x0021
73 #define MCS7830_MII_ADVERTISE (ADVERTISE_PAUSE_CAP | ADVERTISE_100FULL | \
74 ADVERTISE_100HALF | ADVERTISE_10FULL | \
75 ADVERTISE_10HALF | ADVERTISE_CSMA)
123 static const char driver_name[] =
"MOSCHIP usb-ethernet driver";
127 struct usb_device *xdev = dev->
udev;
138 memcpy(data, buffer, size);
146 struct usb_device *xdev = dev->
udev;
161 static void mcs7830_async_cmd_callback(
struct urb *
urb)
174 static void mcs7830_set_reg_async(
struct usbnet *dev,
u16 index,
u16 size,
void *data)
183 "Error allocating URB in write_cmd_async!\n");
190 "Failed to allocate memory for control request\n");
199 usb_fill_control_urb(urb, dev->
udev,
200 usb_sndctrlpipe(dev->
udev, 0),
201 (
void *)req, data, size,
202 mcs7830_async_cmd_callback, req);
207 "Error submitting the control message: ret=%d\n", ret);
216 static int mcs7830_hif_get_mac_address(
struct usbnet *dev,
unsigned char *
addr)
224 static int mcs7830_hif_set_mac_address(
struct usbnet *dev,
unsigned char *addr)
233 static int mcs7830_set_mac_address(
struct net_device *netdev,
void *
p)
236 struct usbnet *dev = netdev_priv(netdev);
239 if (netif_running(netdev))
242 if (!is_valid_ether_addr(addr->
sa_data))
245 ret = mcs7830_hif_set_mac_address(dev, addr->
sa_data);
256 static int mcs7830_read_phy(
struct usbnet *dev,
u8 index)
274 for (i = 0; i < 10; i++) {
289 dev_dbg(&dev->
udev->dev,
"read PHY reg %02x: %04x (%d tries)\n",
296 static int mcs7830_write_phy(
struct usbnet *dev,
u8 index,
u16 val)
321 for (i = 0; i < 10; i++) {
332 dev_dbg(&dev->
udev->dev,
"write PHY reg %02x: %04x (%d tries)\n",
343 static int mcs7830_set_autoneg(
struct usbnet *dev,
int ptrUserPhyMode)
351 ret = mcs7830_write_phy(dev,
MII_BMCR, 0x0000);
357 ret = mcs7830_write_phy(dev,
MII_BMCR,
366 static int mcs7830_get_rev(
struct usbnet *dev)
379 static void mcs7830_rev_C_fixup(
struct usbnet *dev)
384 for (retry = 0; retry < 2; retry++) {
385 if (mcs7830_get_rev(dev) == 2) {
388 1, &pause_threshold);
397 struct usbnet *dev = netdev_priv(netdev);
398 return mcs7830_read_phy(dev, location);
404 struct usbnet *dev = netdev_priv(netdev);
405 mcs7830_write_phy(dev, location, val);
410 struct usbnet *dev = netdev_priv(net);
419 static void mcs7830_hif_update_multicast_hash(
struct usbnet *dev)
427 static void mcs7830_hif_update_config(
struct usbnet *dev)
435 static void mcs7830_data_set_multicast(
struct net_device *net)
437 struct usbnet *dev = netdev_priv(net);
465 data->
multi_filter[crc_bits >> 3] |= 1 << (crc_bits & 7);
470 static int mcs7830_apply_base_config(
struct usbnet *dev)
475 ret = mcs7830_hif_set_mac_address(dev, dev->
net->dev_addr);
482 ret = mcs7830_set_autoneg(dev, 0);
488 mcs7830_hif_update_multicast_hash(dev);
489 mcs7830_hif_update_config(dev);
491 mcs7830_rev_C_fixup(dev);
498 static void mcs7830_set_multicast(
struct net_device *net)
500 struct usbnet *dev = netdev_priv(net);
502 mcs7830_data_set_multicast(net);
504 mcs7830_hif_update_multicast_hash(dev);
505 mcs7830_hif_update_config(dev);
508 static int mcs7830_get_regs_len(
struct net_device *net)
510 struct usbnet *dev = netdev_priv(net);
512 switch (mcs7830_get_rev(dev)) {
529 struct usbnet *dev = netdev_priv(net);
531 regs->
version = mcs7830_get_rev(dev);
532 mcs7830_get_reg(dev, 0, regs->
len, data);
535 static const struct ethtool_ops mcs7830_ethtool_ops = {
536 .get_drvinfo = mcs7830_get_drvinfo,
537 .get_regs_len = mcs7830_get_regs_len,
538 .get_regs = mcs7830_get_regs,
556 .ndo_do_ioctl = mcs7830_ioctl,
557 .ndo_set_rx_mode = mcs7830_set_multicast,
558 .ndo_set_mac_address = mcs7830_set_mac_address,
569 for (retry = 0; retry < 5 &&
ret; retry++)
570 ret = mcs7830_hif_get_mac_address(dev, net->
dev_addr);
576 mcs7830_data_set_multicast(net);
578 ret = mcs7830_apply_base_config(dev);
588 dev->
mii.mdio_read = mcs7830_mdio_read;
589 dev->
mii.mdio_write = mcs7830_mdio_write;
591 dev->
mii.phy_id_mask = 0x3f;
592 dev->
mii.reg_num_mask = 0x1f;
606 dev_err(&dev->
udev->dev,
"unexpected empty rx frame\n");
614 dev_dbg(&dev->
udev->dev,
"rx fixup status %x\n", status);
618 dev->
net->stats.rx_errors++;
623 dev->
net->stats.rx_length_errors++;
625 dev->
net->stats.rx_frame_errors++;
627 dev->
net->stats.rx_crc_errors++;
633 static void mcs7830_status(
struct usbnet *dev,
struct urb *urb)
635 u8 *
buf = urb->transfer_buffer;
636 bool link, link_changed;
639 if (urb->actual_length < 16)
642 link = !(buf[1] & 0x20);
643 link_changed = netif_carrier_ok(dev->
net) !=
link;
664 .description =
"MOSCHIP 7830/7832/7730 usb-NET adapter",
665 .bind = mcs7830_bind,
666 .rx_fixup = mcs7830_rx_fixup,
668 .status = mcs7830_status,
674 .description =
"Sitecom LN-30 usb-NET adapter",
675 .bind = mcs7830_bind,
676 .rx_fixup = mcs7830_rx_fixup,
678 .status = mcs7830_status,
686 .driver_info = (
unsigned long) &moschip_info,
690 .driver_info = (
unsigned long) &moschip_info,
694 .driver_info = (
unsigned long) &moschip_info,
698 .driver_info = (
unsigned long) &sitecom_info,
709 struct usbnet *dev = usb_get_intfdata(intf);
711 mcs7830_apply_base_config(dev);
718 static struct usb_driver mcs7830_driver = {
720 .id_table = products,
725 .reset_resume = mcs7830_reset_resume,
726 .disable_hub_initiated_lpm = 1,