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, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 * Should you need to contact me, the author, you can do so either by
31 * e-mail - mail your message to <vojtech@suse.cz>, or by paper mail:
32 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
35 #include <linux/init.h>
36 #include <linux/module.h>
37 #include <linux/kernel.h>
38 #include <linux/string.h>
39 #include <linux/slab.h>
40 #include <linux/netdevice.h>
41 #include <linux/etherdevice.h>
42 #include <linux/skbuff.h>
43 #include <linux/spinlock.h>
44 #include <linux/ethtool.h>
45 #include <linux/crc32.h>
46 #include <linux/bitops.h>
47 #include <asm/uaccess.h>
51 #include <linux/usb.h>
54 * Version information.
57 #define DRIVER_VERSION "v2.8"
58 #define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@suse.cz>"
59 #define DRIVER_DESC "CATC EL1210A NetMate USB Ethernet driver"
60 #define SHORT_DRIVER_DESC "EL1210A NetMate USB Ethernet"
62 MODULE_AUTHOR(DRIVER_AUTHOR
);
63 MODULE_DESCRIPTION(DRIVER_DESC
);
64 MODULE_LICENSE("GPL");
66 static const char driver_name
[] = "catc";
72 #define STATS_UPDATE (HZ) /* Time between stats updates */
73 #define TX_TIMEOUT (5*HZ) /* Max time the queue can be stopped */
74 #define PKT_SZ 1536 /* Max Ethernet packet size */
75 #define RX_MAX_BURST 15 /* Max packets per rx buffer (> 0, < 16) */
76 #define TX_MAX_BURST 15 /* Max full sized packets per tx buffer (> 0) */
77 #define CTRL_QUEUE 16 /* Max control requests in flight (power of two) */
78 #define RX_PKT_SZ 1600 /* Max size of receive packet for F5U011 */
84 enum control_requests
{
89 SetRxMode
= 0xf5, /* F5U011 only */
101 enum register_offsets
{
127 OpWin95bugfix
= 0x40,
131 enum rx_filter_bits
{
137 AltRxPromisc
= 0x20, /* F5U011 uses different bit */
158 #define CTRL_RUNNING 0
163 struct net_device
*netdev
;
164 struct usb_device
*usbdev
;
168 unsigned int tx_ptr
, tx_idx
;
169 unsigned int ctrl_head
, ctrl_tail
;
170 spinlock_t tx_lock
, ctrl_lock
;
172 u8 tx_buf
[2][TX_MAX_BURST
* (PKT_SZ
+ 2)];
173 u8 rx_buf
[RX_MAX_BURST
* (PKT_SZ
+ 2)];
176 struct usb_ctrlrequest ctrl_dr
;
178 struct timer_list timer
;
181 unsigned long last_stats
;
192 void (*callback
)(struct catc
*catc
, struct ctrl_queue
*q
);
193 } ctrl_queue
[CTRL_QUEUE
];
195 struct urb
*tx_urb
, *rx_urb
, *irq_urb
, *ctrl_urb
;
197 u8 is_f5u011
; /* Set if device is an F5U011 */
198 u8 rxmode
[2]; /* Used for F5U011 */
199 atomic_t recq_sz
; /* Used for F5U011 - counter of waiting rx packets */
206 #define catc_get_mac(catc, mac) catc_ctrl_msg(catc, USB_DIR_IN, GetMac, 0, 0, mac, 6)
207 #define catc_reset(catc) catc_ctrl_msg(catc, USB_DIR_OUT, Reset, 0, 0, NULL, 0)
208 #define catc_set_reg(catc, reg, val) catc_ctrl_msg(catc, USB_DIR_OUT, SetReg, val, reg, NULL, 0)
209 #define catc_get_reg(catc, reg, buf) catc_ctrl_msg(catc, USB_DIR_IN, GetReg, 0, reg, buf, 1)
210 #define catc_write_mem(catc, addr, buf, size) catc_ctrl_msg(catc, USB_DIR_OUT, WriteMem, 0, addr, buf, size)
211 #define catc_read_mem(catc, addr, buf, size) catc_ctrl_msg(catc, USB_DIR_IN, ReadMem, 0, addr, buf, size)
213 #define f5u011_rxmode(catc, rxmode) catc_ctrl_msg(catc, USB_DIR_OUT, SetRxMode, 0, 1, rxmode, 2)
214 #define f5u011_rxmode_async(catc, rxmode) catc_ctrl_async(catc, USB_DIR_OUT, SetRxMode, 0, 1, &rxmode, 2, NULL)
215 #define f5u011_mchash_async(catc, hash) catc_ctrl_async(catc, USB_DIR_OUT, SetRxMode, 0, 2, &hash, 8, NULL)
217 #define catc_set_reg_async(catc, reg, val) catc_ctrl_async(catc, USB_DIR_OUT, SetReg, val, reg, NULL, 0, NULL)
218 #define catc_get_reg_async(catc, reg, cb) catc_ctrl_async(catc, USB_DIR_IN, GetReg, 0, reg, NULL, 1, cb)
219 #define catc_write_mem_async(catc, addr, buf, size) catc_ctrl_async(catc, USB_DIR_OUT, WriteMem, 0, addr, buf, size, NULL)
225 static void catc_rx_done(struct urb
*urb
)
227 struct catc
*catc
= urb
->context
;
228 u8
*pkt_start
= urb
->transfer_buffer
;
230 int pkt_len
, pkt_offset
= 0;
231 int status
= urb
->status
;
233 if (!catc
->is_f5u011
) {
234 clear_bit(RX_RUNNING
, &catc
->flags
);
239 dbg("rx_done, status %d, length %d", status
, urb
->actual_length
);
244 if(!catc
->is_f5u011
) {
245 pkt_len
= le16_to_cpup((__le16
*)pkt_start
);
246 if (pkt_len
> urb
->actual_length
) {
247 catc
->netdev
->stats
.rx_length_errors
++;
248 catc
->netdev
->stats
.rx_errors
++;
252 pkt_len
= urb
->actual_length
;
255 if (!(skb
= dev_alloc_skb(pkt_len
)))
258 skb_copy_to_linear_data(skb
, pkt_start
+ pkt_offset
, pkt_len
);
259 skb_put(skb
, pkt_len
);
261 skb
->protocol
= eth_type_trans(skb
, catc
->netdev
);
264 catc
->netdev
->stats
.rx_packets
++;
265 catc
->netdev
->stats
.rx_bytes
+= pkt_len
;
267 /* F5U011 only does one packet per RX */
270 pkt_start
+= (((pkt_len
+ 1) >> 6) + 1) << 6;
272 } while (pkt_start
- (u8
*) urb
->transfer_buffer
< urb
->actual_length
);
274 if (catc
->is_f5u011
) {
275 if (atomic_read(&catc
->recq_sz
)) {
277 atomic_dec(&catc
->recq_sz
);
278 dbg("getting extra packet");
279 urb
->dev
= catc
->usbdev
;
280 if ((state
= usb_submit_urb(urb
, GFP_ATOMIC
)) < 0) {
281 dbg("submit(rx_urb) status %d", 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 dbg("irq_done, status %d, data %02x %02x.", status
, data
[0], data
[1]);
324 if (linksts
== LinkGood
) {
325 netif_carrier_on(catc
->netdev
);
329 if (linksts
== LinkBad
) {
330 netif_carrier_off(catc
->netdev
);
335 if (test_and_set_bit(RX_RUNNING
, &catc
->flags
)) {
337 atomic_inc(&catc
->recq_sz
);
339 catc
->rx_urb
->dev
= catc
->usbdev
;
340 if ((res
= usb_submit_urb(catc
->rx_urb
, GFP_ATOMIC
)) < 0) {
341 err("submit(rx_urb) status %d", res
);
346 res
= usb_submit_urb (urb
, GFP_ATOMIC
);
348 err ("can't resubmit intr, %s-%s, status %d",
349 catc
->usbdev
->bus
->bus_name
,
350 catc
->usbdev
->devpath
, res
);
357 static int catc_tx_run(struct catc
*catc
)
362 catc
->tx_ptr
= (catc
->tx_ptr
+ 63) & ~63;
364 catc
->tx_urb
->transfer_buffer_length
= catc
->tx_ptr
;
365 catc
->tx_urb
->transfer_buffer
= catc
->tx_buf
[catc
->tx_idx
];
366 catc
->tx_urb
->dev
= catc
->usbdev
;
368 if ((status
= usb_submit_urb(catc
->tx_urb
, GFP_ATOMIC
)) < 0)
369 err("submit(tx_urb), status %d", status
);
371 catc
->tx_idx
= !catc
->tx_idx
;
374 catc
->netdev
->trans_start
= jiffies
;
378 static void catc_tx_done(struct urb
*urb
)
380 struct catc
*catc
= urb
->context
;
382 int r
, status
= urb
->status
;
384 if (status
== -ECONNRESET
) {
387 catc
->netdev
->trans_start
= jiffies
;
388 catc
->netdev
->stats
.tx_errors
++;
389 clear_bit(TX_RUNNING
, &catc
->flags
);
390 netif_wake_queue(catc
->netdev
);
395 dbg("tx_done, status %d, length %d", status
, urb
->actual_length
);
399 spin_lock_irqsave(&catc
->tx_lock
, flags
);
402 r
= catc_tx_run(catc
);
404 clear_bit(TX_RUNNING
, &catc
->flags
);
406 clear_bit(TX_RUNNING
, &catc
->flags
);
409 netif_wake_queue(catc
->netdev
);
411 spin_unlock_irqrestore(&catc
->tx_lock
, flags
);
414 static netdev_tx_t
catc_start_xmit(struct sk_buff
*skb
,
415 struct net_device
*netdev
)
417 struct catc
*catc
= netdev_priv(netdev
);
422 spin_lock_irqsave(&catc
->tx_lock
, flags
);
424 catc
->tx_ptr
= (((catc
->tx_ptr
- 1) >> 6) + 1) << 6;
425 tx_buf
= catc
->tx_buf
[catc
->tx_idx
] + catc
->tx_ptr
;
427 *(__be16
*)tx_buf
= cpu_to_be16(skb
->len
);
429 *(__le16
*)tx_buf
= cpu_to_le16(skb
->len
);
430 skb_copy_from_linear_data(skb
, tx_buf
+ 2, skb
->len
);
431 catc
->tx_ptr
+= skb
->len
+ 2;
433 if (!test_and_set_bit(TX_RUNNING
, &catc
->flags
)) {
434 r
= catc_tx_run(catc
);
436 clear_bit(TX_RUNNING
, &catc
->flags
);
439 if ((catc
->is_f5u011
&& catc
->tx_ptr
) ||
440 (catc
->tx_ptr
>= ((TX_MAX_BURST
- 1) * (PKT_SZ
+ 2))))
441 netif_stop_queue(netdev
);
443 spin_unlock_irqrestore(&catc
->tx_lock
, flags
);
446 catc
->netdev
->stats
.tx_bytes
+= skb
->len
;
447 catc
->netdev
->stats
.tx_packets
++;
455 static void catc_tx_timeout(struct net_device
*netdev
)
457 struct catc
*catc
= netdev_priv(netdev
);
459 dev_warn(&netdev
->dev
, "Transmit timed out.\n");
460 usb_unlink_urb(catc
->tx_urb
);
467 static int catc_ctrl_msg(struct catc
*catc
, u8 dir
, u8 request
, u16 value
, u16 index
, void *buf
, int len
)
469 int retval
= usb_control_msg(catc
->usbdev
,
470 dir
? usb_rcvctrlpipe(catc
->usbdev
, 0) : usb_sndctrlpipe(catc
->usbdev
, 0),
471 request
, 0x40 | dir
, value
, index
, buf
, len
, 1000);
472 return retval
< 0 ? retval
: 0;
475 static void catc_ctrl_run(struct catc
*catc
)
477 struct ctrl_queue
*q
= catc
->ctrl_queue
+ catc
->ctrl_tail
;
478 struct usb_device
*usbdev
= catc
->usbdev
;
479 struct urb
*urb
= catc
->ctrl_urb
;
480 struct usb_ctrlrequest
*dr
= &catc
->ctrl_dr
;
483 dr
->bRequest
= q
->request
;
484 dr
->bRequestType
= 0x40 | q
->dir
;
485 dr
->wValue
= cpu_to_le16(q
->value
);
486 dr
->wIndex
= cpu_to_le16(q
->index
);
487 dr
->wLength
= cpu_to_le16(q
->len
);
489 urb
->pipe
= q
->dir
? usb_rcvctrlpipe(usbdev
, 0) : usb_sndctrlpipe(usbdev
, 0);
490 urb
->transfer_buffer_length
= q
->len
;
491 urb
->transfer_buffer
= catc
->ctrl_buf
;
492 urb
->setup_packet
= (void *) dr
;
495 if (!q
->dir
&& q
->buf
&& q
->len
)
496 memcpy(catc
->ctrl_buf
, q
->buf
, q
->len
);
498 if ((status
= usb_submit_urb(catc
->ctrl_urb
, GFP_KERNEL
)))
499 err("submit(ctrl_urb) status %d", status
);
502 static void catc_ctrl_done(struct urb
*urb
)
504 struct catc
*catc
= urb
->context
;
505 struct ctrl_queue
*q
;
507 int status
= urb
->status
;
510 dbg("ctrl_done, status %d, len %d.", status
, urb
->actual_length
);
512 spin_lock_irqsave(&catc
->ctrl_lock
, flags
);
514 q
= catc
->ctrl_queue
+ catc
->ctrl_tail
;
517 if (q
->buf
&& q
->len
)
518 memcpy(q
->buf
, catc
->ctrl_buf
, q
->len
);
520 q
->buf
= catc
->ctrl_buf
;
524 q
->callback(catc
, q
);
526 catc
->ctrl_tail
= (catc
->ctrl_tail
+ 1) & (CTRL_QUEUE
- 1);
528 if (catc
->ctrl_head
!= catc
->ctrl_tail
)
531 clear_bit(CTRL_RUNNING
, &catc
->flags
);
533 spin_unlock_irqrestore(&catc
->ctrl_lock
, flags
);
536 static int catc_ctrl_async(struct catc
*catc
, u8 dir
, u8 request
, u16 value
,
537 u16 index
, void *buf
, int len
, void (*callback
)(struct catc
*catc
, struct ctrl_queue
*q
))
539 struct ctrl_queue
*q
;
543 spin_lock_irqsave(&catc
->ctrl_lock
, flags
);
545 q
= catc
->ctrl_queue
+ catc
->ctrl_head
;
548 q
->request
= request
;
553 q
->callback
= callback
;
555 catc
->ctrl_head
= (catc
->ctrl_head
+ 1) & (CTRL_QUEUE
- 1);
557 if (catc
->ctrl_head
== catc
->ctrl_tail
) {
558 err("ctrl queue full");
559 catc
->ctrl_tail
= (catc
->ctrl_tail
+ 1) & (CTRL_QUEUE
- 1);
563 if (!test_and_set_bit(CTRL_RUNNING
, &catc
->flags
))
566 spin_unlock_irqrestore(&catc
->ctrl_lock
, flags
);
575 static void catc_stats_done(struct catc
*catc
, struct ctrl_queue
*q
)
577 int index
= q
->index
- EthStats
;
580 catc
->stats_buf
[index
] = *((char *)q
->buf
);
585 data
= ((u16
)catc
->stats_buf
[index
] << 8) | catc
->stats_buf
[index
+ 1];
586 last
= catc
->stats_vals
[index
>> 1];
591 catc
->netdev
->stats
.collisions
+= data
- last
;
594 catc
->netdev
->stats
.tx_aborted_errors
+= data
- last
;
595 catc
->netdev
->stats
.tx_errors
+= data
- last
;
598 catc
->netdev
->stats
.rx_frame_errors
+= data
- last
;
599 catc
->netdev
->stats
.rx_errors
+= data
- last
;
603 catc
->stats_vals
[index
>> 1] = data
;
606 static void catc_stats_timer(unsigned long data
)
608 struct catc
*catc
= (void *) data
;
611 for (i
= 0; i
< 8; i
++)
612 catc_get_reg_async(catc
, EthStats
+ 7 - i
, catc_stats_done
);
614 mod_timer(&catc
->timer
, jiffies
+ STATS_UPDATE
);
618 * Receive modes. Broadcast, Multicast, Promisc.
621 static void catc_multicast(unsigned char *addr
, u8
*multicast
)
625 crc
= ether_crc_le(6, addr
);
626 multicast
[(crc
>> 3) & 0x3f] |= 1 << (crc
& 7);
629 static void catc_set_multicast_list(struct net_device
*netdev
)
631 struct catc
*catc
= netdev_priv(netdev
);
632 struct dev_mc_list
*mc
;
634 u8 rx
= RxEnable
| RxPolarity
| RxMultiCast
;
637 memset(broadcast
, 0xff, 6);
638 memset(catc
->multicast
, 0, 64);
640 catc_multicast(broadcast
, catc
->multicast
);
641 catc_multicast(netdev
->dev_addr
, catc
->multicast
);
643 if (netdev
->flags
& IFF_PROMISC
) {
644 memset(catc
->multicast
, 0xff, 64);
645 rx
|= (!catc
->is_f5u011
) ? RxPromisc
: AltRxPromisc
;
648 if (netdev
->flags
& IFF_ALLMULTI
) {
649 memset(catc
->multicast
, 0xff, 64);
651 for (i
= 0, mc
= netdev
->mc_list
; mc
&& i
< netdev
->mc_count
; i
++, mc
= mc
->next
) {
652 u32 crc
= ether_crc_le(6, mc
->dmi_addr
);
653 if (!catc
->is_f5u011
) {
654 catc
->multicast
[(crc
>> 3) & 0x3f] |= 1 << (crc
& 7);
656 catc
->multicast
[7-(crc
>> 29)] |= 1 << ((crc
>> 26) & 7);
660 if (!catc
->is_f5u011
) {
661 catc_set_reg_async(catc
, RxUnit
, rx
);
662 catc_write_mem_async(catc
, 0xfa80, catc
->multicast
, 64);
664 f5u011_mchash_async(catc
, catc
->multicast
);
665 if (catc
->rxmode
[0] != rx
) {
666 catc
->rxmode
[0] = rx
;
667 dbg("Setting RX mode to %2.2X %2.2X", catc
->rxmode
[0], catc
->rxmode
[1]);
668 f5u011_rxmode_async(catc
, catc
->rxmode
);
673 static void catc_get_drvinfo(struct net_device
*dev
,
674 struct ethtool_drvinfo
*info
)
676 struct catc
*catc
= netdev_priv(dev
);
677 strncpy(info
->driver
, driver_name
, ETHTOOL_BUSINFO_LEN
);
678 strncpy(info
->version
, DRIVER_VERSION
, ETHTOOL_BUSINFO_LEN
);
679 usb_make_path (catc
->usbdev
, info
->bus_info
, sizeof info
->bus_info
);
682 static int catc_get_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
684 struct catc
*catc
= netdev_priv(dev
);
685 if (!catc
->is_f5u011
)
688 cmd
->supported
= SUPPORTED_10baseT_Half
| SUPPORTED_TP
;
689 cmd
->advertising
= ADVERTISED_10baseT_Half
| ADVERTISED_TP
;
690 cmd
->speed
= SPEED_10
;
691 cmd
->duplex
= DUPLEX_HALF
;
693 cmd
->phy_address
= 0;
694 cmd
->transceiver
= XCVR_INTERNAL
;
695 cmd
->autoneg
= AUTONEG_DISABLE
;
701 static const struct ethtool_ops ops
= {
702 .get_drvinfo
= catc_get_drvinfo
,
703 .get_settings
= catc_get_settings
,
704 .get_link
= ethtool_op_get_link
711 static int catc_open(struct net_device
*netdev
)
713 struct catc
*catc
= netdev_priv(netdev
);
716 catc
->irq_urb
->dev
= catc
->usbdev
;
717 if ((status
= usb_submit_urb(catc
->irq_urb
, GFP_KERNEL
)) < 0) {
718 err("submit(irq_urb) status %d", status
);
722 netif_start_queue(netdev
);
724 if (!catc
->is_f5u011
)
725 mod_timer(&catc
->timer
, jiffies
+ STATS_UPDATE
);
730 static int catc_stop(struct net_device
*netdev
)
732 struct catc
*catc
= netdev_priv(netdev
);
734 netif_stop_queue(netdev
);
736 if (!catc
->is_f5u011
)
737 del_timer_sync(&catc
->timer
);
739 usb_kill_urb(catc
->rx_urb
);
740 usb_kill_urb(catc
->tx_urb
);
741 usb_kill_urb(catc
->irq_urb
);
742 usb_kill_urb(catc
->ctrl_urb
);
747 static const struct net_device_ops catc_netdev_ops
= {
748 .ndo_open
= catc_open
,
749 .ndo_stop
= catc_stop
,
750 .ndo_start_xmit
= catc_start_xmit
,
752 .ndo_tx_timeout
= catc_tx_timeout
,
753 .ndo_set_multicast_list
= catc_set_multicast_list
,
754 .ndo_change_mtu
= eth_change_mtu
,
755 .ndo_set_mac_address
= eth_mac_addr
,
756 .ndo_validate_addr
= eth_validate_addr
,
760 * USB probe, disconnect.
763 static int catc_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
765 struct usb_device
*usbdev
= interface_to_usbdev(intf
);
766 struct net_device
*netdev
;
771 if (usb_set_interface(usbdev
,
772 intf
->altsetting
->desc
.bInterfaceNumber
, 1)) {
773 err("Can't set altsetting 1.");
777 netdev
= alloc_etherdev(sizeof(struct catc
));
781 catc
= netdev_priv(netdev
);
783 netdev
->netdev_ops
= &catc_netdev_ops
;
784 netdev
->watchdog_timeo
= TX_TIMEOUT
;
785 SET_ETHTOOL_OPS(netdev
, &ops
);
787 catc
->usbdev
= usbdev
;
788 catc
->netdev
= netdev
;
790 spin_lock_init(&catc
->tx_lock
);
791 spin_lock_init(&catc
->ctrl_lock
);
793 init_timer(&catc
->timer
);
794 catc
->timer
.data
= (long) catc
;
795 catc
->timer
.function
= catc_stats_timer
;
797 catc
->ctrl_urb
= usb_alloc_urb(0, GFP_KERNEL
);
798 catc
->tx_urb
= usb_alloc_urb(0, GFP_KERNEL
);
799 catc
->rx_urb
= usb_alloc_urb(0, GFP_KERNEL
);
800 catc
->irq_urb
= usb_alloc_urb(0, GFP_KERNEL
);
801 if ((!catc
->ctrl_urb
) || (!catc
->tx_urb
) ||
802 (!catc
->rx_urb
) || (!catc
->irq_urb
)) {
803 err("No free urbs available.");
804 usb_free_urb(catc
->ctrl_urb
);
805 usb_free_urb(catc
->tx_urb
);
806 usb_free_urb(catc
->rx_urb
);
807 usb_free_urb(catc
->irq_urb
);
812 /* The F5U011 has the same vendor/product as the netmate but a device version of 0x130 */
813 if (le16_to_cpu(usbdev
->descriptor
.idVendor
) == 0x0423 &&
814 le16_to_cpu(usbdev
->descriptor
.idProduct
) == 0xa &&
815 le16_to_cpu(catc
->usbdev
->descriptor
.bcdDevice
) == 0x0130) {
816 dbg("Testing for f5u011");
818 atomic_set(&catc
->recq_sz
, 0);
821 pktsz
= RX_MAX_BURST
* (PKT_SZ
+ 2);
824 usb_fill_control_urb(catc
->ctrl_urb
, usbdev
, usb_sndctrlpipe(usbdev
, 0),
825 NULL
, NULL
, 0, catc_ctrl_done
, catc
);
827 usb_fill_bulk_urb(catc
->tx_urb
, usbdev
, usb_sndbulkpipe(usbdev
, 1),
828 NULL
, 0, catc_tx_done
, catc
);
830 usb_fill_bulk_urb(catc
->rx_urb
, usbdev
, usb_rcvbulkpipe(usbdev
, 1),
831 catc
->rx_buf
, pktsz
, catc_rx_done
, catc
);
833 usb_fill_int_urb(catc
->irq_urb
, usbdev
, usb_rcvintpipe(usbdev
, 2),
834 catc
->irq_buf
, 2, catc_irq_done
, catc
, 1);
836 if (!catc
->is_f5u011
) {
837 dbg("Checking memory size\n");
840 catc_write_mem(catc
, 0x7a80, &i
, 4);
842 catc_write_mem(catc
, 0xfa80, &i
, 4);
843 catc_read_mem(catc
, 0x7a80, &i
, 4);
847 catc_set_reg(catc
, TxBufCount
, 8);
848 catc_set_reg(catc
, RxBufCount
, 32);
853 "Couldn't detect memory size, assuming 32k\n");
855 catc_set_reg(catc
, TxBufCount
, 4);
856 catc_set_reg(catc
, RxBufCount
, 16);
861 dbg("Getting MAC from SEEROM.");
863 catc_get_mac(catc
, netdev
->dev_addr
);
865 dbg("Setting MAC into registers.");
867 for (i
= 0; i
< 6; i
++)
868 catc_set_reg(catc
, StationAddr0
- i
, netdev
->dev_addr
[i
]);
870 dbg("Filling the multicast list.");
872 memset(broadcast
, 0xff, 6);
873 catc_multicast(broadcast
, catc
->multicast
);
874 catc_multicast(netdev
->dev_addr
, catc
->multicast
);
875 catc_write_mem(catc
, 0xfa80, catc
->multicast
, 64);
877 dbg("Clearing error counters.");
879 for (i
= 0; i
< 8; i
++)
880 catc_set_reg(catc
, EthStats
+ i
, 0);
881 catc
->last_stats
= jiffies
;
885 catc_set_reg(catc
, MaxBurst
, RX_MAX_BURST
);
886 catc_set_reg(catc
, OpModes
, OpTxMerge
| OpRxMerge
| OpLenInclude
| Op3MemWaits
);
887 catc_set_reg(catc
, LEDCtrl
, LEDLink
);
888 catc_set_reg(catc
, RxUnit
, RxEnable
| RxPolarity
| RxMultiCast
);
890 dbg("Performing reset\n");
892 catc_get_mac(catc
, netdev
->dev_addr
);
894 dbg("Setting RX Mode");
895 catc
->rxmode
[0] = RxEnable
| RxPolarity
| RxMultiCast
;
897 f5u011_rxmode(catc
, catc
->rxmode
);
900 printk(KERN_INFO
"%s: %s USB Ethernet at usb-%s-%s, ",
901 netdev
->name
, (catc
->is_f5u011
) ? "Belkin F5U011" : "CATC EL1210A NetMate",
902 usbdev
->bus
->bus_name
, usbdev
->devpath
);
903 for (i
= 0; i
< 5; i
++) printk("%2.2x:", netdev
->dev_addr
[i
]);
904 printk("%2.2x.\n", netdev
->dev_addr
[i
]);
905 usb_set_intfdata(intf
, catc
);
907 SET_NETDEV_DEV(netdev
, &intf
->dev
);
908 if (register_netdev(netdev
) != 0) {
909 usb_set_intfdata(intf
, NULL
);
910 usb_free_urb(catc
->ctrl_urb
);
911 usb_free_urb(catc
->tx_urb
);
912 usb_free_urb(catc
->rx_urb
);
913 usb_free_urb(catc
->irq_urb
);
920 static void catc_disconnect(struct usb_interface
*intf
)
922 struct catc
*catc
= usb_get_intfdata(intf
);
924 usb_set_intfdata(intf
, NULL
);
926 unregister_netdev(catc
->netdev
);
927 usb_free_urb(catc
->ctrl_urb
);
928 usb_free_urb(catc
->tx_urb
);
929 usb_free_urb(catc
->rx_urb
);
930 usb_free_urb(catc
->irq_urb
);
931 free_netdev(catc
->netdev
);
936 * Module functions and tables.
939 static struct usb_device_id catc_id_table
[] = {
940 { USB_DEVICE(0x0423, 0xa) }, /* CATC Netmate, Belkin F5U011 */
941 { USB_DEVICE(0x0423, 0xc) }, /* CATC Netmate II, Belkin F5U111 */
942 { USB_DEVICE(0x08d1, 0x1) }, /* smartBridges smartNIC */
946 MODULE_DEVICE_TABLE(usb
, catc_id_table
);
948 static struct usb_driver catc_driver
= {
951 .disconnect
= catc_disconnect
,
952 .id_table
= catc_id_table
,
955 static int __init
catc_init(void)
957 int result
= usb_register(&catc_driver
);
959 printk(KERN_INFO KBUILD_MODNAME
": " DRIVER_VERSION
":"
964 static void __exit
catc_exit(void)
966 usb_deregister(&catc_driver
);
969 module_init(catc_init
);
970 module_exit(catc_exit
);