23 #include <linux/module.h>
25 #include <linux/netdevice.h>
27 #include <linux/ethtool.h>
29 #include <linux/mii.h>
32 #include <linux/slab.h>
34 #include <asm/unaligned.h>
43 #define frame_errors data[1]
69 #define PAD_BYTE ((unsigned char)0xAC)
76 #define FRAMED_SIZE(mtu) (sizeof (struct nc_header) \
77 + sizeof (struct ethhdr) \
80 + sizeof (struct nc_trailer))
82 #define MIN_FRAMED FRAMED_SIZE(0)
85 #define NC_MAX_PACKET 32767
94 #define NC_READ_TTL_MS ((u8)255) // ms
99 #define REG_USBCTL ((u8)0x04)
100 #define REG_TTL ((u8)0x10)
101 #define REG_STATUS ((u8)0x11)
106 #define REQUEST_REGISTER ((u8)0x10)
107 #define REQUEST_EEPROM ((u8)0x11)
113 usb_rcvctrlpipe(dev->
udev, 0),
117 retval_ptr,
sizeof *retval_ptr,
118 USB_CTRL_GET_TIMEOUT);
137 usb_sndctrlpipe(dev->
udev, 0),
142 USB_CTRL_SET_TIMEOUT);
146 nc_register_write(
struct usbnet *dev,
u8 regnum,
u16 value)
153 static void nc_dump_registers(
struct usbnet *dev)
162 for (reg = 0; reg < 0x20; reg++) {
166 if (reg >= 0x08 && reg <= 0xf)
168 if (reg >= 0x12 && reg <= 0x1e)
171 retval = nc_register_read(dev, reg, vp);
189 #define USBCTL_WRITABLE_MASK 0x1f0f
191 #define USBCTL_ENABLE_LANG (1 << 12)
192 #define USBCTL_ENABLE_MFGR (1 << 11)
193 #define USBCTL_ENABLE_PROD (1 << 10)
194 #define USBCTL_ENABLE_SERIAL (1 << 9)
195 #define USBCTL_ENABLE_DEFAULTS (1 << 8)
197 #define USBCTL_FLUSH_OTHER (1 << 3)
198 #define USBCTL_FLUSH_THIS (1 << 2)
199 #define USBCTL_DISCONN_OTHER (1 << 1)
200 #define USBCTL_DISCONN_THIS (1 << 0)
205 "net1080 %s-%s usbctl 0x%x:%s%s%s%s%s; this%s%s; other%s%s; r/o 0x%x\n",
206 dev->
udev->bus->bus_name, dev->
udev->devpath,
229 #define STATUS_PORT_A (1 << 15)
231 #define STATUS_CONN_OTHER (1 << 14)
232 #define STATUS_SUSPEND_OTHER (1 << 13)
233 #define STATUS_MAILBOX_OTHER (1 << 12)
234 #define STATUS_PACKETS_OTHER(n) (((n) >> 8) & 0x03)
236 #define STATUS_CONN_THIS (1 << 6)
237 #define STATUS_SUSPEND_THIS (1 << 5)
238 #define STATUS_MAILBOX_THIS (1 << 4)
239 #define STATUS_PACKETS_THIS(n) (((n) >> 0) & 0x03)
241 #define STATUS_UNSPEC_MASK 0x0c8c
242 #define STATUS_NOISE_MASK ((u16)~(0x0303|STATUS_UNSPEC_MASK))
248 "net1080 %s-%s status 0x%x: this (%c) PKT=%d%s%s%s; other PKT=%d%s%s%s; unspec 0x%x\n",
249 dev->
udev->bus->bus_name, dev->
udev->devpath,
275 #define TTL_THIS(ttl) (0x00ff & ttl)
276 #define TTL_OTHER(ttl) (0x00ff & (ttl >> 8))
277 #define MK_TTL(this,other) ((u16)(((other)<<8)|(0x00ff&(this))))
279 static inline void nc_dump_ttl(
struct usbnet *dev,
u16 ttl)
281 netif_dbg(dev,
link, dev->
net,
"net1080 %s-%s ttl 0x%x this = %d, other = %d\n",
282 dev->
udev->bus->bus_name, dev->
udev->devpath,
288 static int net1080_reset(
struct usbnet *dev)
299 if ((retval = nc_register_read(dev,
REG_STATUS, vp)) < 0) {
301 dev->
udev->bus->bus_name, dev->
udev->devpath, retval);
305 nc_dump_status(dev, status);
307 if ((retval = nc_register_read(dev,
REG_USBCTL, vp)) < 0) {
312 nc_dump_usbctl(dev, usbctl);
317 if ((retval = nc_register_read(dev,
REG_TTL, vp)) < 0) {
324 nc_register_write(dev,
REG_TTL,
338 static int net1080_check_connect(
struct usbnet *dev)
346 retval = nc_register_read(dev,
REG_STATUS, vp);
350 netdev_dbg(dev->
net,
"net1080_check_conn read - %d\n", retval);
358 static void nc_flush_complete(
struct urb *
urb)
364 static void nc_ensure_sync(
struct usbnet *dev)
367 if (dev->frame_errors > 5) {
395 usb_fill_control_urb(urb, dev->
udev,
396 usb_sndctrlpipe(dev->
udev, 0),
397 (
unsigned char *) req,
399 nc_flush_complete, req);
408 "flush net1080; too many framing errors\n");
409 dev->frame_errors = 0;
419 if (!(skb->
len & 0x01)) {
420 netdev_dbg(dev->
net,
"rx framesize %d range %d..%d mtu %d\n",
423 dev->
net->stats.rx_frame_errors++;
432 dev->
net->stats.rx_frame_errors++;
437 dev->
net->stats.rx_frame_errors++;
450 (skb->
data + skb->
len -
sizeof *trailer);
453 if ((packet_len & 0x01) == 0) {
455 dev->
net->stats.rx_frame_errors++;
461 if (skb->
len != packet_len) {
462 dev->
net->stats.rx_frame_errors++;
464 skb->
len, packet_len);
469 dev->
net->stats.rx_fifo_errors++;
470 netdev_dbg(dev->
net,
"(2+ dropped) rx packet_id mismatch 0x%x 0x%x\n",
479 dev->frame_errors = 0;
492 if (!((len + padlen +
sizeof (
struct nc_header)) & 0x01))
494 if (!skb_cloned(skb)) {
495 int headroom = skb_headroom(skb);
496 int tailroom = skb_tailroom(skb);
498 if (padlen <= tailroom &&
503 if ((
sizeof (
struct nc_header) + padlen) <
504 (headroom + tailroom)) {
509 skb_set_tail_pointer(skb, len);
532 if (!((skb->
len +
sizeof *trailer) & 0x01))
557 .description =
"NetChip TurboCONNECT",
559 .bind = net1080_bind,
560 .reset = net1080_reset,
561 .check_connect = net1080_check_connect,
562 .rx_fixup = net1080_rx_fixup,
563 .tx_fixup = net1080_tx_fixup,
568 USB_DEVICE(0x0525, 0x1080),
569 .driver_info = (
unsigned long) &net1080_info,
571 USB_DEVICE(0x06D0, 0x0622),
572 .driver_info = (
unsigned long) &net1080_info,
578 static struct usb_driver net1080_driver = {
580 .id_table = products,
585 .disable_hub_initiated_lpm = 1,