2 * Copyright (c) 2001 Vojtech Pavlik
4 * CATC EL1210A NetMate USB Ethernet driver
11 * Old chipset support added by Simon Evans <spse@secret.org.uk> 2002
12 * - adds support for Belkin F5U011
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, see <http://www.gnu.org/licenses/>.
29 * Should you need to contact me, the author, you can do so either by
30 * e-mail - mail your message to <vojtech@suse.cz>, or by paper mail:
31 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
34 #include <linux/module.h>
35 #include <linux/kernel.h>
36 #include <linux/string.h>
37 #include <linux/netdevice.h>
38 #include <linux/etherdevice.h>
39 #include <linux/skbuff.h>
40 #include <linux/spinlock.h>
41 #include <linux/ethtool.h>
42 #include <linux/crc32.h>
43 #include <linux/bitops.h>
44 #include <linux/gfp.h>
45 #include <linux/uaccess.h>
49 #include <linux/usb.h>
52 * Version information.
55 #define DRIVER_VERSION "v2.8"
56 #define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@suse.cz>"
57 #define DRIVER_DESC "CATC EL1210A NetMate USB Ethernet driver"
58 #define SHORT_DRIVER_DESC "EL1210A NetMate USB Ethernet"
60 MODULE_AUTHOR(DRIVER_AUTHOR
);
61 MODULE_DESCRIPTION(DRIVER_DESC
);
62 MODULE_LICENSE("GPL");
64 static const char driver_name
[] = "catc";
70 #define STATS_UPDATE (HZ) /* Time between stats updates */
71 #define TX_TIMEOUT (5*HZ) /* Max time the queue can be stopped */
72 #define PKT_SZ 1536 /* Max Ethernet packet size */
73 #define RX_MAX_BURST 15 /* Max packets per rx buffer (> 0, < 16) */
74 #define TX_MAX_BURST 15 /* Max full sized packets per tx buffer (> 0) */
75 #define CTRL_QUEUE 16 /* Max control requests in flight (power of two) */
76 #define RX_PKT_SZ 1600 /* Max size of receive packet for F5U011 */
82 enum control_requests
{
87 SetRxMode
= 0xf5, /* F5U011 only */
99 enum register_offsets
{
125 OpWin95bugfix
= 0x40,
129 enum rx_filter_bits
{
135 AltRxPromisc
= 0x20, /* F5U011 uses different bit */
156 #define CTRL_RUNNING 0
161 struct net_device
*netdev
;
162 struct usb_device
*usbdev
;
166 unsigned int tx_ptr
, tx_idx
;
167 unsigned int ctrl_head
, ctrl_tail
;
168 spinlock_t tx_lock
, ctrl_lock
;
170 u8 tx_buf
[2][TX_MAX_BURST
* (PKT_SZ
+ 2)];
171 u8 rx_buf
[RX_MAX_BURST
* (PKT_SZ
+ 2)];
174 struct usb_ctrlrequest ctrl_dr
;
176 struct timer_list timer
;
179 unsigned long last_stats
;
190 void (*callback
)(struct catc
*catc
, struct ctrl_queue
*q
);
191 } ctrl_queue
[CTRL_QUEUE
];
193 struct urb
*tx_urb
, *rx_urb
, *irq_urb
, *ctrl_urb
;
195 u8 is_f5u011
; /* Set if device is an F5U011 */
196 u8 rxmode
[2]; /* Used for F5U011 */
197 atomic_t recq_sz
; /* Used for F5U011 - counter of waiting rx packets */
204 #define catc_get_mac(catc, mac) catc_ctrl_msg(catc, USB_DIR_IN, GetMac, 0, 0, mac, 6)
205 #define catc_reset(catc) catc_ctrl_msg(catc, USB_DIR_OUT, Reset, 0, 0, NULL, 0)
206 #define catc_set_reg(catc, reg, val) catc_ctrl_msg(catc, USB_DIR_OUT, SetReg, val, reg, NULL, 0)
207 #define catc_get_reg(catc, reg, buf) catc_ctrl_msg(catc, USB_DIR_IN, GetReg, 0, reg, buf, 1)
208 #define catc_write_mem(catc, addr, buf, size) catc_ctrl_msg(catc, USB_DIR_OUT, WriteMem, 0, addr, buf, size)
209 #define catc_read_mem(catc, addr, buf, size) catc_ctrl_msg(catc, USB_DIR_IN, ReadMem, 0, addr, buf, size)
211 #define f5u011_rxmode(catc, rxmode) catc_ctrl_msg(catc, USB_DIR_OUT, SetRxMode, 0, 1, rxmode, 2)
212 #define f5u011_rxmode_async(catc, rxmode) catc_ctrl_async(catc, USB_DIR_OUT, SetRxMode, 0, 1, &rxmode, 2, NULL)
213 #define f5u011_mchash_async(catc, hash) catc_ctrl_async(catc, USB_DIR_OUT, SetRxMode, 0, 2, &hash, 8, NULL)
215 #define catc_set_reg_async(catc, reg, val) catc_ctrl_async(catc, USB_DIR_OUT, SetReg, val, reg, NULL, 0, NULL)
216 #define catc_get_reg_async(catc, reg, cb) catc_ctrl_async(catc, USB_DIR_IN, GetReg, 0, reg, NULL, 1, cb)
217 #define catc_write_mem_async(catc, addr, buf, size) catc_ctrl_async(catc, USB_DIR_OUT, WriteMem, 0, addr, buf, size, NULL)
223 static void catc_rx_done(struct urb
*urb
)
225 struct catc
*catc
= urb
->context
;
226 u8
*pkt_start
= urb
->transfer_buffer
;
228 int pkt_len
, pkt_offset
= 0;
229 int status
= urb
->status
;
231 if (!catc
->is_f5u011
) {
232 clear_bit(RX_RUNNING
, &catc
->flags
);
237 dev_dbg(&urb
->dev
->dev
, "rx_done, status %d, length %d\n",
238 status
, urb
->actual_length
);
243 if(!catc
->is_f5u011
) {
244 pkt_len
= le16_to_cpup((__le16
*)pkt_start
);
245 if (pkt_len
> urb
->actual_length
) {
246 catc
->netdev
->stats
.rx_length_errors
++;
247 catc
->netdev
->stats
.rx_errors
++;
251 pkt_len
= urb
->actual_length
;
254 if (!(skb
= dev_alloc_skb(pkt_len
)))
257 skb_copy_to_linear_data(skb
, pkt_start
+ pkt_offset
, pkt_len
);
258 skb_put(skb
, pkt_len
);
260 skb
->protocol
= eth_type_trans(skb
, catc
->netdev
);
263 catc
->netdev
->stats
.rx_packets
++;
264 catc
->netdev
->stats
.rx_bytes
+= pkt_len
;
266 /* F5U011 only does one packet per RX */
269 pkt_start
+= (((pkt_len
+ 1) >> 6) + 1) << 6;
271 } while (pkt_start
- (u8
*) urb
->transfer_buffer
< urb
->actual_length
);
273 if (catc
->is_f5u011
) {
274 if (atomic_read(&catc
->recq_sz
)) {
276 atomic_dec(&catc
->recq_sz
);
277 netdev_dbg(catc
->netdev
, "getting extra packet\n");
278 urb
->dev
= catc
->usbdev
;
279 if ((state
= usb_submit_urb(urb
, GFP_ATOMIC
)) < 0) {
280 netdev_dbg(catc
->netdev
,
281 "submit(rx_urb) status %d\n", state
);
284 clear_bit(RX_RUNNING
, &catc
->flags
);
289 static void catc_irq_done(struct urb
*urb
)
291 struct catc
*catc
= urb
->context
;
292 u8
*data
= urb
->transfer_buffer
;
293 int status
= urb
->status
;
294 unsigned int hasdata
= 0, linksts
= LinkNoChange
;
297 if (!catc
->is_f5u011
) {
298 hasdata
= data
[1] & 0x80;
301 else if (data
[1] & 0x20)
304 hasdata
= (unsigned int)(be16_to_cpup((__be16
*)data
) & 0x0fff);
307 else if (data
[0] == 0xA0)
312 case 0: /* success */
314 case -ECONNRESET
: /* unlink */
318 /* -EPIPE: should clear the halt */
320 dev_dbg(&urb
->dev
->dev
,
321 "irq_done, status %d, data %02x %02x.\n",
322 status
, data
[0], data
[1]);
326 if (linksts
== LinkGood
) {
327 netif_carrier_on(catc
->netdev
);
328 netdev_dbg(catc
->netdev
, "link ok\n");
331 if (linksts
== LinkBad
) {
332 netif_carrier_off(catc
->netdev
);
333 netdev_dbg(catc
->netdev
, "link bad\n");
337 if (test_and_set_bit(RX_RUNNING
, &catc
->flags
)) {
339 atomic_inc(&catc
->recq_sz
);
341 catc
->rx_urb
->dev
= catc
->usbdev
;
342 if ((res
= usb_submit_urb(catc
->rx_urb
, GFP_ATOMIC
)) < 0) {
343 dev_err(&catc
->usbdev
->dev
,
344 "submit(rx_urb) status %d\n", res
);
349 res
= usb_submit_urb (urb
, GFP_ATOMIC
);
351 dev_err(&catc
->usbdev
->dev
,
352 "can't resubmit intr, %s-%s, status %d\n",
353 catc
->usbdev
->bus
->bus_name
,
354 catc
->usbdev
->devpath
, res
);
361 static int catc_tx_run(struct catc
*catc
)
366 catc
->tx_ptr
= (catc
->tx_ptr
+ 63) & ~63;
368 catc
->tx_urb
->transfer_buffer_length
= catc
->tx_ptr
;
369 catc
->tx_urb
->transfer_buffer
= catc
->tx_buf
[catc
->tx_idx
];
370 catc
->tx_urb
->dev
= catc
->usbdev
;
372 if ((status
= usb_submit_urb(catc
->tx_urb
, GFP_ATOMIC
)) < 0)
373 dev_err(&catc
->usbdev
->dev
, "submit(tx_urb), status %d\n",
376 catc
->tx_idx
= !catc
->tx_idx
;
379 netif_trans_update(catc
->netdev
);
383 static void catc_tx_done(struct urb
*urb
)
385 struct catc
*catc
= urb
->context
;
387 int r
, status
= urb
->status
;
389 if (status
== -ECONNRESET
) {
390 dev_dbg(&urb
->dev
->dev
, "Tx Reset.\n");
392 netif_trans_update(catc
->netdev
);
393 catc
->netdev
->stats
.tx_errors
++;
394 clear_bit(TX_RUNNING
, &catc
->flags
);
395 netif_wake_queue(catc
->netdev
);
400 dev_dbg(&urb
->dev
->dev
, "tx_done, status %d, length %d\n",
401 status
, urb
->actual_length
);
405 spin_lock_irqsave(&catc
->tx_lock
, flags
);
408 r
= catc_tx_run(catc
);
410 clear_bit(TX_RUNNING
, &catc
->flags
);
412 clear_bit(TX_RUNNING
, &catc
->flags
);
415 netif_wake_queue(catc
->netdev
);
417 spin_unlock_irqrestore(&catc
->tx_lock
, flags
);
420 static netdev_tx_t
catc_start_xmit(struct sk_buff
*skb
,
421 struct net_device
*netdev
)
423 struct catc
*catc
= netdev_priv(netdev
);
428 spin_lock_irqsave(&catc
->tx_lock
, flags
);
430 catc
->tx_ptr
= (((catc
->tx_ptr
- 1) >> 6) + 1) << 6;
431 tx_buf
= catc
->tx_buf
[catc
->tx_idx
] + catc
->tx_ptr
;
433 *(__be16
*)tx_buf
= cpu_to_be16(skb
->len
);
435 *(__le16
*)tx_buf
= cpu_to_le16(skb
->len
);
436 skb_copy_from_linear_data(skb
, tx_buf
+ 2, skb
->len
);
437 catc
->tx_ptr
+= skb
->len
+ 2;
439 if (!test_and_set_bit(TX_RUNNING
, &catc
->flags
)) {
440 r
= catc_tx_run(catc
);
442 clear_bit(TX_RUNNING
, &catc
->flags
);
445 if ((catc
->is_f5u011
&& catc
->tx_ptr
) ||
446 (catc
->tx_ptr
>= ((TX_MAX_BURST
- 1) * (PKT_SZ
+ 2))))
447 netif_stop_queue(netdev
);
449 spin_unlock_irqrestore(&catc
->tx_lock
, flags
);
452 catc
->netdev
->stats
.tx_bytes
+= skb
->len
;
453 catc
->netdev
->stats
.tx_packets
++;
461 static void catc_tx_timeout(struct net_device
*netdev
)
463 struct catc
*catc
= netdev_priv(netdev
);
465 dev_warn(&netdev
->dev
, "Transmit timed out.\n");
466 usb_unlink_urb(catc
->tx_urb
);
473 static int catc_ctrl_msg(struct catc
*catc
, u8 dir
, u8 request
, u16 value
, u16 index
, void *buf
, int len
)
475 int retval
= usb_control_msg(catc
->usbdev
,
476 dir
? usb_rcvctrlpipe(catc
->usbdev
, 0) : usb_sndctrlpipe(catc
->usbdev
, 0),
477 request
, 0x40 | dir
, value
, index
, buf
, len
, 1000);
478 return retval
< 0 ? retval
: 0;
481 static void catc_ctrl_run(struct catc
*catc
)
483 struct ctrl_queue
*q
= catc
->ctrl_queue
+ catc
->ctrl_tail
;
484 struct usb_device
*usbdev
= catc
->usbdev
;
485 struct urb
*urb
= catc
->ctrl_urb
;
486 struct usb_ctrlrequest
*dr
= &catc
->ctrl_dr
;
489 dr
->bRequest
= q
->request
;
490 dr
->bRequestType
= 0x40 | q
->dir
;
491 dr
->wValue
= cpu_to_le16(q
->value
);
492 dr
->wIndex
= cpu_to_le16(q
->index
);
493 dr
->wLength
= cpu_to_le16(q
->len
);
495 urb
->pipe
= q
->dir
? usb_rcvctrlpipe(usbdev
, 0) : usb_sndctrlpipe(usbdev
, 0);
496 urb
->transfer_buffer_length
= q
->len
;
497 urb
->transfer_buffer
= catc
->ctrl_buf
;
498 urb
->setup_packet
= (void *) dr
;
501 if (!q
->dir
&& q
->buf
&& q
->len
)
502 memcpy(catc
->ctrl_buf
, q
->buf
, q
->len
);
504 if ((status
= usb_submit_urb(catc
->ctrl_urb
, GFP_ATOMIC
)))
505 dev_err(&catc
->usbdev
->dev
, "submit(ctrl_urb) status %d\n",
509 static void catc_ctrl_done(struct urb
*urb
)
511 struct catc
*catc
= urb
->context
;
512 struct ctrl_queue
*q
;
514 int status
= urb
->status
;
517 dev_dbg(&urb
->dev
->dev
, "ctrl_done, status %d, len %d.\n",
518 status
, urb
->actual_length
);
520 spin_lock_irqsave(&catc
->ctrl_lock
, flags
);
522 q
= catc
->ctrl_queue
+ catc
->ctrl_tail
;
525 if (q
->buf
&& q
->len
)
526 memcpy(q
->buf
, catc
->ctrl_buf
, q
->len
);
528 q
->buf
= catc
->ctrl_buf
;
532 q
->callback(catc
, q
);
534 catc
->ctrl_tail
= (catc
->ctrl_tail
+ 1) & (CTRL_QUEUE
- 1);
536 if (catc
->ctrl_head
!= catc
->ctrl_tail
)
539 clear_bit(CTRL_RUNNING
, &catc
->flags
);
541 spin_unlock_irqrestore(&catc
->ctrl_lock
, flags
);
544 static int catc_ctrl_async(struct catc
*catc
, u8 dir
, u8 request
, u16 value
,
545 u16 index
, void *buf
, int len
, void (*callback
)(struct catc
*catc
, struct ctrl_queue
*q
))
547 struct ctrl_queue
*q
;
551 spin_lock_irqsave(&catc
->ctrl_lock
, flags
);
553 q
= catc
->ctrl_queue
+ catc
->ctrl_head
;
556 q
->request
= request
;
561 q
->callback
= callback
;
563 catc
->ctrl_head
= (catc
->ctrl_head
+ 1) & (CTRL_QUEUE
- 1);
565 if (catc
->ctrl_head
== catc
->ctrl_tail
) {
566 dev_err(&catc
->usbdev
->dev
, "ctrl queue full\n");
567 catc
->ctrl_tail
= (catc
->ctrl_tail
+ 1) & (CTRL_QUEUE
- 1);
571 if (!test_and_set_bit(CTRL_RUNNING
, &catc
->flags
))
574 spin_unlock_irqrestore(&catc
->ctrl_lock
, flags
);
583 static void catc_stats_done(struct catc
*catc
, struct ctrl_queue
*q
)
585 int index
= q
->index
- EthStats
;
588 catc
->stats_buf
[index
] = *((char *)q
->buf
);
593 data
= ((u16
)catc
->stats_buf
[index
] << 8) | catc
->stats_buf
[index
+ 1];
594 last
= catc
->stats_vals
[index
>> 1];
599 catc
->netdev
->stats
.collisions
+= data
- last
;
602 catc
->netdev
->stats
.tx_aborted_errors
+= data
- last
;
603 catc
->netdev
->stats
.tx_errors
+= data
- last
;
606 catc
->netdev
->stats
.rx_frame_errors
+= data
- last
;
607 catc
->netdev
->stats
.rx_errors
+= data
- last
;
611 catc
->stats_vals
[index
>> 1] = data
;
614 static void catc_stats_timer(struct timer_list
*t
)
616 struct catc
*catc
= from_timer(catc
, t
, timer
);
619 for (i
= 0; i
< 8; i
++)
620 catc_get_reg_async(catc
, EthStats
+ 7 - i
, catc_stats_done
);
622 mod_timer(&catc
->timer
, jiffies
+ STATS_UPDATE
);
626 * Receive modes. Broadcast, Multicast, Promisc.
629 static void catc_multicast(unsigned char *addr
, u8
*multicast
)
633 crc
= ether_crc_le(6, addr
);
634 multicast
[(crc
>> 3) & 0x3f] |= 1 << (crc
& 7);
637 static void catc_set_multicast_list(struct net_device
*netdev
)
639 struct catc
*catc
= netdev_priv(netdev
);
640 struct netdev_hw_addr
*ha
;
641 u8 broadcast
[ETH_ALEN
];
642 u8 rx
= RxEnable
| RxPolarity
| RxMultiCast
;
644 eth_broadcast_addr(broadcast
);
645 memset(catc
->multicast
, 0, 64);
647 catc_multicast(broadcast
, catc
->multicast
);
648 catc_multicast(netdev
->dev_addr
, catc
->multicast
);
650 if (netdev
->flags
& IFF_PROMISC
) {
651 memset(catc
->multicast
, 0xff, 64);
652 rx
|= (!catc
->is_f5u011
) ? RxPromisc
: AltRxPromisc
;
655 if (netdev
->flags
& IFF_ALLMULTI
) {
656 memset(catc
->multicast
, 0xff, 64);
658 netdev_for_each_mc_addr(ha
, netdev
) {
659 u32 crc
= ether_crc_le(6, ha
->addr
);
660 if (!catc
->is_f5u011
) {
661 catc
->multicast
[(crc
>> 3) & 0x3f] |= 1 << (crc
& 7);
663 catc
->multicast
[7-(crc
>> 29)] |= 1 << ((crc
>> 26) & 7);
667 if (!catc
->is_f5u011
) {
668 catc_set_reg_async(catc
, RxUnit
, rx
);
669 catc_write_mem_async(catc
, 0xfa80, catc
->multicast
, 64);
671 f5u011_mchash_async(catc
, catc
->multicast
);
672 if (catc
->rxmode
[0] != rx
) {
673 catc
->rxmode
[0] = rx
;
674 netdev_dbg(catc
->netdev
,
675 "Setting RX mode to %2.2X %2.2X\n",
676 catc
->rxmode
[0], catc
->rxmode
[1]);
677 f5u011_rxmode_async(catc
, catc
->rxmode
);
682 static void catc_get_drvinfo(struct net_device
*dev
,
683 struct ethtool_drvinfo
*info
)
685 struct catc
*catc
= netdev_priv(dev
);
686 strlcpy(info
->driver
, driver_name
, sizeof(info
->driver
));
687 strlcpy(info
->version
, DRIVER_VERSION
, sizeof(info
->version
));
688 usb_make_path(catc
->usbdev
, info
->bus_info
, sizeof(info
->bus_info
));
691 static int catc_get_link_ksettings(struct net_device
*dev
,
692 struct ethtool_link_ksettings
*cmd
)
694 struct catc
*catc
= netdev_priv(dev
);
695 if (!catc
->is_f5u011
)
698 ethtool_link_ksettings_zero_link_mode(cmd
, supported
);
699 ethtool_link_ksettings_add_link_mode(cmd
, supported
, 10baseT_Half
);
700 ethtool_link_ksettings_add_link_mode(cmd
, supported
, TP
);
702 ethtool_link_ksettings_zero_link_mode(cmd
, advertising
);
703 ethtool_link_ksettings_add_link_mode(cmd
, advertising
, 10baseT_Half
);
704 ethtool_link_ksettings_add_link_mode(cmd
, advertising
, TP
);
706 cmd
->base
.speed
= SPEED_10
;
707 cmd
->base
.duplex
= DUPLEX_HALF
;
708 cmd
->base
.port
= PORT_TP
;
709 cmd
->base
.phy_address
= 0;
710 cmd
->base
.autoneg
= AUTONEG_DISABLE
;
715 static const struct ethtool_ops ops
= {
716 .get_drvinfo
= catc_get_drvinfo
,
717 .get_link
= ethtool_op_get_link
,
718 .get_link_ksettings
= catc_get_link_ksettings
,
725 static int catc_open(struct net_device
*netdev
)
727 struct catc
*catc
= netdev_priv(netdev
);
730 catc
->irq_urb
->dev
= catc
->usbdev
;
731 if ((status
= usb_submit_urb(catc
->irq_urb
, GFP_KERNEL
)) < 0) {
732 dev_err(&catc
->usbdev
->dev
, "submit(irq_urb) status %d\n",
737 netif_start_queue(netdev
);
739 if (!catc
->is_f5u011
)
740 mod_timer(&catc
->timer
, jiffies
+ STATS_UPDATE
);
745 static int catc_stop(struct net_device
*netdev
)
747 struct catc
*catc
= netdev_priv(netdev
);
749 netif_stop_queue(netdev
);
751 if (!catc
->is_f5u011
)
752 del_timer_sync(&catc
->timer
);
754 usb_kill_urb(catc
->rx_urb
);
755 usb_kill_urb(catc
->tx_urb
);
756 usb_kill_urb(catc
->irq_urb
);
757 usb_kill_urb(catc
->ctrl_urb
);
762 static const struct net_device_ops catc_netdev_ops
= {
763 .ndo_open
= catc_open
,
764 .ndo_stop
= catc_stop
,
765 .ndo_start_xmit
= catc_start_xmit
,
767 .ndo_tx_timeout
= catc_tx_timeout
,
768 .ndo_set_rx_mode
= catc_set_multicast_list
,
769 .ndo_set_mac_address
= eth_mac_addr
,
770 .ndo_validate_addr
= eth_validate_addr
,
774 * USB probe, disconnect.
777 static int catc_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
779 struct device
*dev
= &intf
->dev
;
780 struct usb_device
*usbdev
= interface_to_usbdev(intf
);
781 struct net_device
*netdev
;
783 u8 broadcast
[ETH_ALEN
];
786 if (usb_set_interface(usbdev
,
787 intf
->altsetting
->desc
.bInterfaceNumber
, 1)) {
788 dev_err(dev
, "Can't set altsetting 1.\n");
792 netdev
= alloc_etherdev(sizeof(struct catc
));
796 catc
= netdev_priv(netdev
);
798 netdev
->netdev_ops
= &catc_netdev_ops
;
799 netdev
->watchdog_timeo
= TX_TIMEOUT
;
800 netdev
->ethtool_ops
= &ops
;
802 catc
->usbdev
= usbdev
;
803 catc
->netdev
= netdev
;
805 spin_lock_init(&catc
->tx_lock
);
806 spin_lock_init(&catc
->ctrl_lock
);
808 timer_setup(&catc
->timer
, catc_stats_timer
, 0);
810 catc
->ctrl_urb
= usb_alloc_urb(0, GFP_KERNEL
);
811 catc
->tx_urb
= usb_alloc_urb(0, GFP_KERNEL
);
812 catc
->rx_urb
= usb_alloc_urb(0, GFP_KERNEL
);
813 catc
->irq_urb
= usb_alloc_urb(0, GFP_KERNEL
);
814 if ((!catc
->ctrl_urb
) || (!catc
->tx_urb
) ||
815 (!catc
->rx_urb
) || (!catc
->irq_urb
)) {
816 dev_err(&intf
->dev
, "No free urbs available.\n");
821 /* The F5U011 has the same vendor/product as the netmate but a device version of 0x130 */
822 if (le16_to_cpu(usbdev
->descriptor
.idVendor
) == 0x0423 &&
823 le16_to_cpu(usbdev
->descriptor
.idProduct
) == 0xa &&
824 le16_to_cpu(catc
->usbdev
->descriptor
.bcdDevice
) == 0x0130) {
825 dev_dbg(dev
, "Testing for f5u011\n");
827 atomic_set(&catc
->recq_sz
, 0);
830 pktsz
= RX_MAX_BURST
* (PKT_SZ
+ 2);
833 usb_fill_control_urb(catc
->ctrl_urb
, usbdev
, usb_sndctrlpipe(usbdev
, 0),
834 NULL
, NULL
, 0, catc_ctrl_done
, catc
);
836 usb_fill_bulk_urb(catc
->tx_urb
, usbdev
, usb_sndbulkpipe(usbdev
, 1),
837 NULL
, 0, catc_tx_done
, catc
);
839 usb_fill_bulk_urb(catc
->rx_urb
, usbdev
, usb_rcvbulkpipe(usbdev
, 1),
840 catc
->rx_buf
, pktsz
, catc_rx_done
, catc
);
842 usb_fill_int_urb(catc
->irq_urb
, usbdev
, usb_rcvintpipe(usbdev
, 2),
843 catc
->irq_buf
, 2, catc_irq_done
, catc
, 1);
845 if (!catc
->is_f5u011
) {
849 dev_dbg(dev
, "Checking memory size\n");
851 buf
= kmalloc(4, GFP_KERNEL
);
858 catc_write_mem(catc
, 0x7a80, buf
, 4);
860 catc_write_mem(catc
, 0xfa80, buf
, 4);
861 catc_read_mem(catc
, 0x7a80, buf
, 4);
865 catc_set_reg(catc
, TxBufCount
, 8);
866 catc_set_reg(catc
, RxBufCount
, 32);
867 dev_dbg(dev
, "64k Memory\n");
871 "Couldn't detect memory size, assuming 32k\n");
873 catc_set_reg(catc
, TxBufCount
, 4);
874 catc_set_reg(catc
, RxBufCount
, 16);
875 dev_dbg(dev
, "32k Memory\n");
881 dev_dbg(dev
, "Getting MAC from SEEROM.\n");
883 catc_get_mac(catc
, netdev
->dev_addr
);
885 dev_dbg(dev
, "Setting MAC into registers.\n");
887 for (i
= 0; i
< 6; i
++)
888 catc_set_reg(catc
, StationAddr0
- i
, netdev
->dev_addr
[i
]);
890 dev_dbg(dev
, "Filling the multicast list.\n");
892 eth_broadcast_addr(broadcast
);
893 catc_multicast(broadcast
, catc
->multicast
);
894 catc_multicast(netdev
->dev_addr
, catc
->multicast
);
895 catc_write_mem(catc
, 0xfa80, catc
->multicast
, 64);
897 dev_dbg(dev
, "Clearing error counters.\n");
899 for (i
= 0; i
< 8; i
++)
900 catc_set_reg(catc
, EthStats
+ i
, 0);
901 catc
->last_stats
= jiffies
;
903 dev_dbg(dev
, "Enabling.\n");
905 catc_set_reg(catc
, MaxBurst
, RX_MAX_BURST
);
906 catc_set_reg(catc
, OpModes
, OpTxMerge
| OpRxMerge
| OpLenInclude
| Op3MemWaits
);
907 catc_set_reg(catc
, LEDCtrl
, LEDLink
);
908 catc_set_reg(catc
, RxUnit
, RxEnable
| RxPolarity
| RxMultiCast
);
910 dev_dbg(dev
, "Performing reset\n");
912 catc_get_mac(catc
, netdev
->dev_addr
);
914 dev_dbg(dev
, "Setting RX Mode\n");
915 catc
->rxmode
[0] = RxEnable
| RxPolarity
| RxMultiCast
;
917 f5u011_rxmode(catc
, catc
->rxmode
);
919 dev_dbg(dev
, "Init done.\n");
920 printk(KERN_INFO
"%s: %s USB Ethernet at usb-%s-%s, %pM.\n",
921 netdev
->name
, (catc
->is_f5u011
) ? "Belkin F5U011" : "CATC EL1210A NetMate",
922 usbdev
->bus
->bus_name
, usbdev
->devpath
, netdev
->dev_addr
);
923 usb_set_intfdata(intf
, catc
);
925 SET_NETDEV_DEV(netdev
, &intf
->dev
);
926 ret
= register_netdev(netdev
);
928 goto fail_clear_intfdata
;
933 usb_set_intfdata(intf
, NULL
);
935 usb_free_urb(catc
->ctrl_urb
);
936 usb_free_urb(catc
->tx_urb
);
937 usb_free_urb(catc
->rx_urb
);
938 usb_free_urb(catc
->irq_urb
);
943 static void catc_disconnect(struct usb_interface
*intf
)
945 struct catc
*catc
= usb_get_intfdata(intf
);
947 usb_set_intfdata(intf
, NULL
);
949 unregister_netdev(catc
->netdev
);
950 usb_free_urb(catc
->ctrl_urb
);
951 usb_free_urb(catc
->tx_urb
);
952 usb_free_urb(catc
->rx_urb
);
953 usb_free_urb(catc
->irq_urb
);
954 free_netdev(catc
->netdev
);
959 * Module functions and tables.
962 static const struct usb_device_id catc_id_table
[] = {
963 { USB_DEVICE(0x0423, 0xa) }, /* CATC Netmate, Belkin F5U011 */
964 { USB_DEVICE(0x0423, 0xc) }, /* CATC Netmate II, Belkin F5U111 */
965 { USB_DEVICE(0x08d1, 0x1) }, /* smartBridges smartNIC */
969 MODULE_DEVICE_TABLE(usb
, catc_id_table
);
971 static struct usb_driver catc_driver
= {
974 .disconnect
= catc_disconnect
,
975 .id_table
= catc_id_table
,
976 .disable_hub_initiated_lpm
= 1,
979 module_usb_driver(catc_driver
);