diff options
| -rw-r--r-- | drivers/net/usb/Kconfig | 8 | ||||
| -rw-r--r-- | drivers/net/usb/Makefile | 1 | ||||
| -rw-r--r-- | drivers/net/usb/cx82310_eth.c | 354 |
3 files changed, 363 insertions, 0 deletions
diff --git a/drivers/net/usb/Kconfig b/drivers/net/usb/Kconfig index d7b7018a1de1..52ffabe6db0e 100644 --- a/drivers/net/usb/Kconfig +++ b/drivers/net/usb/Kconfig | |||
| @@ -358,6 +358,14 @@ config USB_NET_ZAURUS | |||
| 358 | really need this non-conformant variant of CDC Ethernet (or in | 358 | really need this non-conformant variant of CDC Ethernet (or in |
| 359 | some cases CDC MDLM) protocol, not "g_ether". | 359 | some cases CDC MDLM) protocol, not "g_ether". |
| 360 | 360 | ||
| 361 | config USB_NET_CX82310_ETH | ||
| 362 | tristate "Conexant CX82310 USB ethernet port" | ||
| 363 | depends on USB_USBNET | ||
| 364 | help | ||
| 365 | Choose this option if you're using a Conexant CX82310-based ADSL | ||
| 366 | router with USB ethernet port. This driver is for routers only, | ||
| 367 | it will not work with ADSL modems (use cxacru driver instead). | ||
| 368 | |||
| 361 | config USB_HSO | 369 | config USB_HSO |
| 362 | tristate "Option USB High Speed Mobile Devices" | 370 | tristate "Option USB High Speed Mobile Devices" |
| 363 | depends on USB && RFKILL | 371 | depends on USB && RFKILL |
diff --git a/drivers/net/usb/Makefile b/drivers/net/usb/Makefile index b13a279663ba..a19b0259ae16 100644 --- a/drivers/net/usb/Makefile +++ b/drivers/net/usb/Makefile | |||
| @@ -25,4 +25,5 @@ obj-$(CONFIG_USB_NET_INT51X1) += int51x1.o | |||
| 25 | obj-$(CONFIG_USB_CDC_PHONET) += cdc-phonet.o | 25 | obj-$(CONFIG_USB_CDC_PHONET) += cdc-phonet.o |
| 26 | obj-$(CONFIG_USB_IPHETH) += ipheth.o | 26 | obj-$(CONFIG_USB_IPHETH) += ipheth.o |
| 27 | obj-$(CONFIG_USB_SIERRA_NET) += sierra_net.o | 27 | obj-$(CONFIG_USB_SIERRA_NET) += sierra_net.o |
| 28 | obj-$(CONFIG_USB_NET_CX82310_ETH) += cx82310_eth.o | ||
| 28 | 29 | ||
diff --git a/drivers/net/usb/cx82310_eth.c b/drivers/net/usb/cx82310_eth.c new file mode 100644 index 000000000000..6fbe03276b27 --- /dev/null +++ b/drivers/net/usb/cx82310_eth.c | |||
| @@ -0,0 +1,354 @@ | |||
| 1 | /* | ||
| 2 | * Driver for USB ethernet port of Conexant CX82310-based ADSL routers | ||
| 3 | * Copyright (C) 2010 by Ondrej Zary | ||
| 4 | * some parts inspired by the cxacru driver | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation; either version 2 of the License, or | ||
| 9 | * (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This program is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | * GNU General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License | ||
| 17 | * along with this program; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include <linux/module.h> | ||
| 22 | #include <linux/init.h> | ||
| 23 | #include <linux/netdevice.h> | ||
| 24 | #include <linux/etherdevice.h> | ||
| 25 | #include <linux/ethtool.h> | ||
| 26 | #include <linux/workqueue.h> | ||
| 27 | #include <linux/mii.h> | ||
| 28 | #include <linux/usb.h> | ||
| 29 | #include <linux/usb/usbnet.h> | ||
| 30 | |||
| 31 | enum cx82310_cmd { | ||
| 32 | CMD_START = 0x84, /* no effect? */ | ||
| 33 | CMD_STOP = 0x85, /* no effect? */ | ||
| 34 | CMD_GET_STATUS = 0x90, /* returns nothing? */ | ||
| 35 | CMD_GET_MAC_ADDR = 0x91, /* read MAC address */ | ||
| 36 | CMD_GET_LINK_STATUS = 0x92, /* not useful, link is always up */ | ||
| 37 | CMD_ETHERNET_MODE = 0x99, /* unknown, needed during init */ | ||
| 38 | }; | ||
| 39 | |||
| 40 | enum cx82310_status { | ||
| 41 | STATUS_UNDEFINED, | ||
| 42 | STATUS_SUCCESS, | ||
| 43 | STATUS_ERROR, | ||
| 44 | STATUS_UNSUPPORTED, | ||
| 45 | STATUS_UNIMPLEMENTED, | ||
| 46 | STATUS_PARAMETER_ERROR, | ||
| 47 | STATUS_DBG_LOOPBACK, | ||
| 48 | }; | ||
| 49 | |||
| 50 | #define CMD_PACKET_SIZE 64 | ||
| 51 | /* first command after power on can take around 8 seconds */ | ||
| 52 | #define CMD_TIMEOUT 15000 | ||
| 53 | #define CMD_REPLY_RETRY 5 | ||
| 54 | |||
| 55 | #define CX82310_MTU 1514 | ||
| 56 | #define CMD_EP 0x01 | ||
| 57 | |||
| 58 | /* | ||
| 59 | * execute control command | ||
| 60 | * - optionally send some data (command parameters) | ||
| 61 | * - optionally wait for the reply | ||
| 62 | * - optionally read some data from the reply | ||
| 63 | */ | ||
| 64 | static int cx82310_cmd(struct usbnet *dev, enum cx82310_cmd cmd, bool reply, | ||
| 65 | u8 *wdata, int wlen, u8 *rdata, int rlen) | ||
| 66 | { | ||
| 67 | int actual_len, retries, ret; | ||
| 68 | struct usb_device *udev = dev->udev; | ||
| 69 | u8 *buf = kzalloc(CMD_PACKET_SIZE, GFP_KERNEL); | ||
| 70 | |||
| 71 | if (!buf) | ||
| 72 | return -ENOMEM; | ||
| 73 | |||
| 74 | /* create command packet */ | ||
| 75 | buf[0] = cmd; | ||
| 76 | if (wdata) | ||
| 77 | memcpy(buf + 4, wdata, min_t(int, wlen, CMD_PACKET_SIZE - 4)); | ||
| 78 | |||
| 79 | /* send command packet */ | ||
| 80 | ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, CMD_EP), buf, | ||
| 81 | CMD_PACKET_SIZE, &actual_len, CMD_TIMEOUT); | ||
| 82 | if (ret < 0) { | ||
| 83 | dev_err(&dev->udev->dev, "send command %#x: error %d\n", | ||
| 84 | cmd, ret); | ||
| 85 | goto end; | ||
| 86 | } | ||
| 87 | |||
| 88 | if (reply) { | ||
| 89 | /* wait for reply, retry if it's empty */ | ||
| 90 | for (retries = 0; retries < CMD_REPLY_RETRY; retries++) { | ||
| 91 | ret = usb_bulk_msg(udev, usb_rcvbulkpipe(udev, CMD_EP), | ||
| 92 | buf, CMD_PACKET_SIZE, &actual_len, | ||
| 93 | CMD_TIMEOUT); | ||
| 94 | if (ret < 0) { | ||
| 95 | dev_err(&dev->udev->dev, | ||
| 96 | "reply receive error %d\n", ret); | ||
| 97 | goto end; | ||
| 98 | } | ||
| 99 | if (actual_len > 0) | ||
| 100 | break; | ||
| 101 | } | ||
| 102 | if (actual_len == 0) { | ||
| 103 | dev_err(&dev->udev->dev, "no reply to command %#x\n", | ||
| 104 | cmd); | ||
| 105 | ret = -EIO; | ||
| 106 | goto end; | ||
| 107 | } | ||
| 108 | if (buf[0] != cmd) { | ||
| 109 | dev_err(&dev->udev->dev, | ||
| 110 | "got reply to command %#x, expected: %#x\n", | ||
| 111 | buf[0], cmd); | ||
| 112 | ret = -EIO; | ||
| 113 | goto end; | ||
| 114 | } | ||
| 115 | if (buf[1] != STATUS_SUCCESS) { | ||
| 116 | dev_err(&dev->udev->dev, "command %#x failed: %#x\n", | ||
| 117 | cmd, buf[1]); | ||
| 118 | ret = -EIO; | ||
| 119 | goto end; | ||
| 120 | } | ||
| 121 | if (rdata) | ||
| 122 | memcpy(rdata, buf + 4, | ||
| 123 | min_t(int, rlen, CMD_PACKET_SIZE - 4)); | ||
| 124 | } | ||
| 125 | end: | ||
| 126 | kfree(buf); | ||
| 127 | return ret; | ||
| 128 | } | ||
| 129 | |||
| 130 | #define partial_len data[0] /* length of partial packet data */ | ||
| 131 | #define partial_rem data[1] /* remaining (missing) data length */ | ||
| 132 | #define partial_data data[2] /* partial packet data */ | ||
| 133 | |||
| 134 | static int cx82310_bind(struct usbnet *dev, struct usb_interface *intf) | ||
| 135 | { | ||
| 136 | int ret; | ||
| 137 | char buf[15]; | ||
| 138 | struct usb_device *udev = dev->udev; | ||
| 139 | |||
| 140 | /* avoid ADSL modems - continue only if iProduct is "USB NET CARD" */ | ||
| 141 | if (udev->descriptor.iProduct && | ||
| 142 | usb_string(udev, udev->descriptor.iProduct, buf, sizeof(buf)) && | ||
| 143 | strcmp(buf, "USB NET CARD")) { | ||
| 144 | dev_err(&udev->dev, | ||
| 145 | "probably an ADSL modem, use cxacru driver instead\n"); | ||
| 146 | return -ENODEV; | ||
| 147 | } | ||
| 148 | |||
| 149 | ret = usbnet_get_endpoints(dev, intf); | ||
| 150 | if (ret) | ||
| 151 | return ret; | ||
| 152 | |||
| 153 | /* | ||
| 154 | * this must not include ethernet header as the device can send partial | ||
| 155 | * packets with no header (URB is at least 2 bytes long, so 2 is OK) | ||
| 156 | */ | ||
| 157 | dev->net->hard_header_len = 2; | ||
| 158 | /* we can send at most 1514 bytes of data (+ 2-byte header) per URB */ | ||
| 159 | dev->hard_mtu = CX82310_MTU + dev->net->hard_header_len; | ||
| 160 | /* we can receive URBs up to 4KB from the device */ | ||
| 161 | dev->rx_urb_size = 4096; | ||
| 162 | |||
| 163 | dev->partial_data = (unsigned long) kmalloc(dev->hard_mtu, GFP_KERNEL); | ||
| 164 | if (!dev->partial_data) | ||
| 165 | return -ENOMEM; | ||
| 166 | |||
