1 /* sb1000.c: A General Instruments SB1000 driver for linux. */
3 Written 1998 by Franco Venturi.
5 Copyright 1998 by Franco Venturi.
6 Copyright 1994,1995 by Donald Becker.
7 Copyright 1993 United States Government as represented by the
8 Director, National Security Agency.
10 This driver is for the General Instruments SB1000 (internal SURFboard)
12 The author may be reached as fventuri@mediaone.net
14 This program is free software; you can redistribute it
15 and/or modify it under the terms of the GNU General
16 Public License as published by the Free Software
17 Foundation; either version 2 of the License, or (at
18 your option) any later version.
22 981115 Steven Hirsch <shirsch@adelphia.net>
24 Linus changed the timer interface. Should work on all recent
27 980608 Steven Hirsch <shirsch@adelphia.net>
29 Small changes to make it work with 2.1.x kernels. Hopefully,
30 nothing major will change before official release of Linux 2.2.
32 Merged with 2.2 - Alan Cox
35 static char version
[] = "sb1000.c:v1.1.2 6/01/98 (fventuri@mediaone.net)\n";
37 #include <linux/module.h>
38 #include <linux/kernel.h>
39 #include <linux/string.h>
40 #include <linux/interrupt.h>
41 #include <linux/errno.h>
42 #include <linux/if_cablemodem.h> /* for SIOGCM/SIOSCM stuff */
44 #include <linux/slab.h>
45 #include <linux/ioport.h>
46 #include <linux/netdevice.h>
47 #include <linux/if_arp.h>
48 #include <linux/skbuff.h>
49 #include <linux/delay.h> /* for udelay() */
50 #include <linux/etherdevice.h>
51 #include <linux/pnp.h>
52 #include <linux/init.h>
53 #include <linux/bitops.h>
56 #include <asm/processor.h>
57 #include <asm/uaccess.h>
60 static int sb1000_debug
= SB1000_DEBUG
;
62 static const int sb1000_debug
= 1;
65 static const int SB1000_IO_EXTENT
= 8;
66 /* SB1000 Maximum Receive Unit */
67 static const int SB1000_MRU
= 1500; /* octects */
70 struct sb1000_private
{
71 struct sk_buff
*rx_skb
[NPIDS
];
73 unsigned int rx_frames
;
75 short rx_error_dpc_count
;
76 unsigned char rx_session_id
[NPIDS
];
77 unsigned char rx_frame_id
[NPIDS
];
78 unsigned char rx_pkt_type
[NPIDS
];
81 /* prototypes for Linux interface */
82 extern int sb1000_probe(struct net_device
*dev
);
83 static int sb1000_open(struct net_device
*dev
);
84 static int sb1000_dev_ioctl (struct net_device
*dev
, struct ifreq
*ifr
, int cmd
);
85 static netdev_tx_t
sb1000_start_xmit(struct sk_buff
*skb
,
86 struct net_device
*dev
);
87 static irqreturn_t
sb1000_interrupt(int irq
, void *dev_id
);
88 static int sb1000_close(struct net_device
*dev
);
91 /* SB1000 hardware routines to be used during open/configuration phases */
92 static int card_wait_for_busy_clear(const int ioaddr
[],
94 static int card_wait_for_ready(const int ioaddr
[], const char* name
,
96 static int card_send_command(const int ioaddr
[], const char* name
,
97 const unsigned char out
[], unsigned char in
[]);
99 /* SB1000 hardware routines to be used during frame rx interrupt */
100 static int sb1000_wait_for_ready(const int ioaddr
[], const char* name
);
101 static int sb1000_wait_for_ready_clear(const int ioaddr
[],
103 static void sb1000_send_command(const int ioaddr
[], const char* name
,
104 const unsigned char out
[]);
105 static void sb1000_read_status(const int ioaddr
[], unsigned char in
[]);
106 static void sb1000_issue_read_command(const int ioaddr
[],
109 /* SB1000 commands for open/configuration */
110 static int sb1000_reset(const int ioaddr
[], const char* name
);
111 static int sb1000_check_CRC(const int ioaddr
[], const char* name
);
112 static inline int sb1000_start_get_set_command(const int ioaddr
[],
114 static int sb1000_end_get_set_command(const int ioaddr
[],
116 static int sb1000_activate(const int ioaddr
[], const char* name
);
117 static int sb1000_get_firmware_version(const int ioaddr
[],
118 const char* name
, unsigned char version
[], int do_end
);
119 static int sb1000_get_frequency(const int ioaddr
[], const char* name
,
121 static int sb1000_set_frequency(const int ioaddr
[], const char* name
,
123 static int sb1000_get_PIDs(const int ioaddr
[], const char* name
,
125 static int sb1000_set_PIDs(const int ioaddr
[], const char* name
,
128 /* SB1000 commands for frame rx interrupt */
129 static int sb1000_rx(struct net_device
*dev
);
130 static void sb1000_error_dpc(struct net_device
*dev
);
132 static const struct pnp_device_id sb1000_pnp_ids
[] = {
136 MODULE_DEVICE_TABLE(pnp
, sb1000_pnp_ids
);
138 static const struct net_device_ops sb1000_netdev_ops
= {
139 .ndo_open
= sb1000_open
,
140 .ndo_start_xmit
= sb1000_start_xmit
,
141 .ndo_do_ioctl
= sb1000_dev_ioctl
,
142 .ndo_stop
= sb1000_close
,
143 .ndo_change_mtu
= eth_change_mtu
,
144 .ndo_set_mac_address
= eth_mac_addr
,
145 .ndo_validate_addr
= eth_validate_addr
,
149 sb1000_probe_one(struct pnp_dev
*pdev
, const struct pnp_device_id
*id
)
151 struct net_device
*dev
;
152 unsigned short ioaddr
[2], irq
;
153 unsigned int serial_number
;
156 if (pnp_device_attach(pdev
) < 0)
158 if (pnp_activate_dev(pdev
) < 0)
161 if (!pnp_port_valid(pdev
, 0) || !pnp_port_valid(pdev
, 1))
163 if (!pnp_irq_valid(pdev
, 0))
166 serial_number
= pdev
->card
->serial
;
168 ioaddr
[0] = pnp_port_start(pdev
, 0);
169 ioaddr
[1] = pnp_port_start(pdev
, 0);
171 irq
= pnp_irq(pdev
, 0);
173 if (!request_region(ioaddr
[0], 16, "sb1000"))
175 if (!request_region(ioaddr
[1], 16, "sb1000"))
176 goto out_release_region0
;
178 dev
= alloc_etherdev(sizeof(struct sb1000_private
));
181 goto out_release_regions
;
185 dev
->base_addr
= ioaddr
[0];
186 /* mem_start holds the second I/O address */
187 dev
->mem_start
= ioaddr
[1];
190 if (sb1000_debug
> 0)
191 printk(KERN_NOTICE
"%s: sb1000 at (%#3.3lx,%#3.3lx), "
192 "S/N %#8.8x, IRQ %d.\n", dev
->name
, dev
->base_addr
,
193 dev
->mem_start
, serial_number
, dev
->irq
);
196 * The SB1000 is an rx-only cable modem device. The uplink is a modem
197 * and we do not want to arp on it.
199 dev
->flags
= IFF_POINTOPOINT
|IFF_NOARP
;
201 SET_NETDEV_DEV(dev
, &pdev
->dev
);
203 if (sb1000_debug
> 0)
204 printk(KERN_NOTICE
"%s", version
);
206 dev
->netdev_ops
= &sb1000_netdev_ops
;
208 /* hardware address is 0:0:serial_number */
209 dev
->dev_addr
[2] = serial_number
>> 24 & 0xff;
210 dev
->dev_addr
[3] = serial_number
>> 16 & 0xff;
211 dev
->dev_addr
[4] = serial_number
>> 8 & 0xff;
212 dev
->dev_addr
[5] = serial_number
>> 0 & 0xff;
214 pnp_set_drvdata(pdev
, dev
);
216 error
= register_netdev(dev
);
218 goto out_free_netdev
;
224 release_region(ioaddr
[1], 16);
226 release_region(ioaddr
[0], 16);
228 pnp_disable_dev(pdev
);
230 pnp_device_detach(pdev
);
235 sb1000_remove_one(struct pnp_dev
*pdev
)
237 struct net_device
*dev
= pnp_get_drvdata(pdev
);
239 unregister_netdev(dev
);
240 release_region(dev
->base_addr
, 16);
241 release_region(dev
->mem_start
, 16);
245 static struct pnp_driver sb1000_driver
= {
247 .id_table
= sb1000_pnp_ids
,
248 .probe
= sb1000_probe_one
,
249 .remove
= sb1000_remove_one
,
254 * SB1000 hardware routines to be used during open/configuration phases
257 static const int TimeOutJiffies
= (875 * HZ
) / 100;
259 /* Card Wait For Busy Clear (cannot be used during an interrupt) */
261 card_wait_for_busy_clear(const int ioaddr
[], const char* name
)
264 unsigned long timeout
;
266 a
= inb(ioaddr
[0] + 7);
267 timeout
= jiffies
+ TimeOutJiffies
;
268 while (a
& 0x80 || a
& 0x40) {
272 a
= inb(ioaddr
[0] + 7);
273 if (time_after_eq(jiffies
, timeout
)) {
274 printk(KERN_WARNING
"%s: card_wait_for_busy_clear timeout\n",
283 /* Card Wait For Ready (cannot be used during an interrupt) */
285 card_wait_for_ready(const int ioaddr
[], const char* name
, unsigned char in
[])
288 unsigned long timeout
;
290 a
= inb(ioaddr
[1] + 6);
291 timeout
= jiffies
+ TimeOutJiffies
;
292 while (a
& 0x80 || !(a
& 0x40)) {
296 a
= inb(ioaddr
[1] + 6);
297 if (time_after_eq(jiffies
, timeout
)) {
298 printk(KERN_WARNING
"%s: card_wait_for_ready timeout\n",
304 in
[1] = inb(ioaddr
[0] + 1);
305 in
[2] = inb(ioaddr
[0] + 2);
306 in
[3] = inb(ioaddr
[0] + 3);
307 in
[4] = inb(ioaddr
[0] + 4);
308 in
[0] = inb(ioaddr
[0] + 5);
309 in
[6] = inb(ioaddr
[0] + 6);
310 in
[5] = inb(ioaddr
[1] + 6);
314 /* Card Send Command (cannot be used during an interrupt) */
316 card_send_command(const int ioaddr
[], const char* name
,
317 const unsigned char out
[], unsigned char in
[])
321 if ((status
= card_wait_for_busy_clear(ioaddr
, name
)))
323 outb(0xa0, ioaddr
[0] + 6);
324 outb(out
[2], ioaddr
[0] + 1);
325 outb(out
[3], ioaddr
[0] + 2);
326 outb(out
[4], ioaddr
[0] + 3);
327 outb(out
[5], ioaddr
[0] + 4);
328 outb(out
[1], ioaddr
[0] + 5);
329 outb(0xa0, ioaddr
[0] + 6);
330 outb(out
[0], ioaddr
[0] + 7);
331 if (out
[0] != 0x20 && out
[0] != 0x30) {
332 if ((status
= card_wait_for_ready(ioaddr
, name
, in
)))
335 if (sb1000_debug
> 3)
336 printk(KERN_DEBUG
"%s: card_send_command "
337 "out: %02x%02x%02x%02x%02x%02x "
338 "in: %02x%02x%02x%02x%02x%02x%02x\n", name
,
339 out
[0], out
[1], out
[2], out
[3], out
[4], out
[5],
340 in
[0], in
[1], in
[2], in
[3], in
[4], in
[5], in
[6]);
342 if (sb1000_debug
> 3)
343 printk(KERN_DEBUG
"%s: card_send_command "
344 "out: %02x%02x%02x%02x%02x%02x\n", name
,
345 out
[0], out
[1], out
[2], out
[3], out
[4], out
[5]);
348 if (out
[1] == 0x1b) {
349 x
= (out
[2] == 0x02);
351 if (out
[0] >= 0x80 && in
[0] != (out
[1] | 0x80))
359 * SB1000 hardware routines to be used during frame rx interrupt
361 static const int Sb1000TimeOutJiffies
= 7 * HZ
;
363 /* Card Wait For Ready (to be used during frame rx) */
365 sb1000_wait_for_ready(const int ioaddr
[], const char* name
)
367 unsigned long timeout
;
369 timeout
= jiffies
+ Sb1000TimeOutJiffies
;
370 while (inb(ioaddr
[1] + 6) & 0x80) {
371 if (time_after_eq(jiffies
, timeout
)) {
372 printk(KERN_WARNING
"%s: sb1000_wait_for_ready timeout\n",
377 timeout
= jiffies
+ Sb1000TimeOutJiffies
;
378 while (!(inb(ioaddr
[1] + 6) & 0x40)) {
379 if (time_after_eq(jiffies
, timeout
)) {
380 printk(KERN_WARNING
"%s: sb1000_wait_for_ready timeout\n",
389 /* Card Wait For Ready Clear (to be used during frame rx) */
391 sb1000_wait_for_ready_clear(const int ioaddr
[], const char* name
)
393 unsigned long timeout
;
395 timeout
= jiffies
+ Sb1000TimeOutJiffies
;
396 while (inb(ioaddr
[1] + 6) & 0x80) {
397 if (time_after_eq(jiffies
, timeout
)) {
398 printk(KERN_WARNING
"%s: sb1000_wait_for_ready_clear timeout\n",
403 timeout
= jiffies
+ Sb1000TimeOutJiffies
;
404 while (inb(ioaddr
[1] + 6) & 0x40) {
405 if (time_after_eq(jiffies
, timeout
)) {
406 printk(KERN_WARNING
"%s: sb1000_wait_for_ready_clear timeout\n",
414 /* Card Send Command (to be used during frame rx) */
416 sb1000_send_command(const int ioaddr
[], const char* name
,
417 const unsigned char out
[])
419 outb(out
[2], ioaddr
[0] + 1);
420 outb(out
[3], ioaddr
[0] + 2);
421 outb(out
[4], ioaddr
[0] + 3);
422 outb(out
[5], ioaddr
[0] + 4);
423 outb(out
[1], ioaddr
[0] + 5);
424 outb(out
[0], ioaddr
[0] + 7);
425 if (sb1000_debug
> 3)
426 printk(KERN_DEBUG
"%s: sb1000_send_command out: %02x%02x%02x%02x"
427 "%02x%02x\n", name
, out
[0], out
[1], out
[2], out
[3], out
[4], out
[5]);
431 /* Card Read Status (to be used during frame rx) */
433 sb1000_read_status(const int ioaddr
[], unsigned char in
[])
435 in
[1] = inb(ioaddr
[0] + 1);
436 in
[2] = inb(ioaddr
[0] + 2);
437 in
[3] = inb(ioaddr
[0] + 3);
438 in
[4] = inb(ioaddr
[0] + 4);
439 in
[0] = inb(ioaddr
[0] + 5);
443 /* Issue Read Command (to be used during frame rx) */
445 sb1000_issue_read_command(const int ioaddr
[], const char* name
)
447 static const unsigned char Command0
[6] = {0x20, 0x00, 0x00, 0x01, 0x00, 0x00};
449 sb1000_wait_for_ready_clear(ioaddr
, name
);
450 outb(0xa0, ioaddr
[0] + 6);
451 sb1000_send_command(ioaddr
, name
, Command0
);
457 * SB1000 commands for open/configuration
459 /* reset SB1000 card */
461 sb1000_reset(const int ioaddr
[], const char* name
)
463 static const unsigned char Command0
[6] = {0x80, 0x16, 0x00, 0x00, 0x00, 0x00};
468 port
= ioaddr
[1] + 6;
482 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
489 /* check SB1000 firmware CRC */
491 sb1000_check_CRC(const int ioaddr
[], const char* name
)
493 static const unsigned char Command0
[6] = {0x80, 0x1f, 0x00, 0x00, 0x00, 0x00};
499 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
501 if (st
[1] != st
[3] || st
[2] != st
[4])
503 crc
= st
[1] << 8 | st
[2];
508 sb1000_start_get_set_command(const int ioaddr
[], const char* name
)
510 static const unsigned char Command0
[6] = {0x80, 0x1b, 0x00, 0x00, 0x00, 0x00};
514 return card_send_command(ioaddr
, name
, Command0
, st
);
518 sb1000_end_get_set_command(const int ioaddr
[], const char* name
)
520 static const unsigned char Command0
[6] = {0x80, 0x1b, 0x02, 0x00, 0x00, 0x00};
521 static const unsigned char Command1
[6] = {0x20, 0x00, 0x00, 0x00, 0x00, 0x00};
526 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
528 return card_send_command(ioaddr
, name
, Command1
, st
);
532 sb1000_activate(const int ioaddr
[], const char* name
)
534 static const unsigned char Command0
[6] = {0x80, 0x11, 0x00, 0x00, 0x00, 0x00};
535 static const unsigned char Command1
[6] = {0x80, 0x16, 0x00, 0x00, 0x00, 0x00};
541 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
543 if ((status
= card_send_command(ioaddr
, name
, Command1
, st
)))
546 if ((status
= sb1000_start_get_set_command(ioaddr
, name
)))
551 return sb1000_start_get_set_command(ioaddr
, name
);
554 /* get SB1000 firmware version */
556 sb1000_get_firmware_version(const int ioaddr
[], const char* name
,
557 unsigned char version
[], int do_end
)
559 static const unsigned char Command0
[6] = {0x80, 0x23, 0x00, 0x00, 0x00, 0x00};
564 if ((status
= sb1000_start_get_set_command(ioaddr
, name
)))
566 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
573 return sb1000_end_get_set_command(ioaddr
, name
);
578 /* get SB1000 frequency */
580 sb1000_get_frequency(const int ioaddr
[], const char* name
, int* frequency
)
582 static const unsigned char Command0
[6] = {0x80, 0x44, 0x00, 0x00, 0x00, 0x00};
588 if ((status
= sb1000_start_get_set_command(ioaddr
, name
)))
590 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
592 *frequency
= ((st
[1] << 8 | st
[2]) << 8 | st
[3]) << 8 | st
[4];
593 return sb1000_end_get_set_command(ioaddr
, name
);
596 /* set SB1000 frequency */
598 sb1000_set_frequency(const int ioaddr
[], const char* name
, int frequency
)
602 unsigned char Command0
[6] = {0x80, 0x29, 0x00, 0x00, 0x00, 0x00};
604 const int FrequencyLowerLimit
= 57000;
605 const int FrequencyUpperLimit
= 804000;
607 if (frequency
< FrequencyLowerLimit
|| frequency
> FrequencyUpperLimit
) {
608 printk(KERN_ERR
"%s: frequency chosen (%d kHz) is not in the range "
609 "[%d,%d] kHz\n", name
, frequency
, FrequencyLowerLimit
,
610 FrequencyUpperLimit
);
614 if ((status
= sb1000_start_get_set_command(ioaddr
, name
)))
616 Command0
[5] = frequency
& 0xff;
618 Command0
[4] = frequency
& 0xff;
620 Command0
[3] = frequency
& 0xff;
622 Command0
[2] = frequency
& 0xff;
623 return card_send_command(ioaddr
, name
, Command0
, st
);
626 /* get SB1000 PIDs */
628 sb1000_get_PIDs(const int ioaddr
[], const char* name
, short PID
[])
630 static const unsigned char Command0
[6] = {0x80, 0x40, 0x00, 0x00, 0x00, 0x00};
631 static const unsigned char Command1
[6] = {0x80, 0x41, 0x00, 0x00, 0x00, 0x00};
632 static const unsigned char Command2
[6] = {0x80, 0x42, 0x00, 0x00, 0x00, 0x00};
633 static const unsigned char Command3
[6] = {0x80, 0x43, 0x00, 0x00, 0x00, 0x00};
639 if ((status
= sb1000_start_get_set_command(ioaddr
, name
)))
642 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
644 PID
[0] = st
[1] << 8 | st
[2];
646 if ((status
= card_send_command(ioaddr
, name
, Command1
, st
)))
648 PID
[1] = st
[1] << 8 | st
[2];
650 if ((status
= card_send_command(ioaddr
, name
, Command2
, st
)))
652 PID
[2] = st
[1] << 8 | st
[2];
654 if ((status
= card_send_command(ioaddr
, name
, Command3
, st
)))
656 PID
[3] = st
[1] << 8 | st
[2];
658 return sb1000_end_get_set_command(ioaddr
, name
);
661 /* set SB1000 PIDs */
663 sb1000_set_PIDs(const int ioaddr
[], const char* name
, const short PID
[])
665 static const unsigned char Command4
[6] = {0x80, 0x2e, 0x00, 0x00, 0x00, 0x00};
670 unsigned char Command0
[6] = {0x80, 0x31, 0x00, 0x00, 0x00, 0x00};
671 unsigned char Command1
[6] = {0x80, 0x32, 0x00, 0x00, 0x00, 0x00};
672 unsigned char Command2
[6] = {0x80, 0x33, 0x00, 0x00, 0x00, 0x00};
673 unsigned char Command3
[6] = {0x80, 0x34, 0x00, 0x00, 0x00, 0x00};
676 if ((status
= sb1000_start_get_set_command(ioaddr
, name
)))
680 Command0
[3] = p
& 0xff;
682 Command0
[2] = p
& 0xff;
683 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
687 Command1
[3] = p
& 0xff;
689 Command1
[2] = p
& 0xff;
690 if ((status
= card_send_command(ioaddr
, name
, Command1
, st
)))
694 Command2
[3] = p
& 0xff;
696 Command2
[2] = p
& 0xff;
697 if ((status
= card_send_command(ioaddr
, name
, Command2
, st
)))
701 Command3
[3] = p
& 0xff;
703 Command3
[2] = p
& 0xff;
704 if ((status
= card_send_command(ioaddr
, name
, Command3
, st
)))
707 if ((status
= card_send_command(ioaddr
, name
, Command4
, st
)))
709 return sb1000_end_get_set_command(ioaddr
, name
);
714 sb1000_print_status_buffer(const char* name
, unsigned char st
[],
715 unsigned char buffer
[], int size
)
719 printk(KERN_DEBUG
"%s: status: %02x %02x\n", name
, st
[0], st
[1]);
720 if (buffer
[24] == 0x08 && buffer
[25] == 0x00 && buffer
[26] == 0x45) {
721 printk(KERN_DEBUG
"%s: length: %d protocol: %d from: %d.%d.%d.%d:%d "
722 "to %d.%d.%d.%d:%d\n", name
, buffer
[28] << 8 | buffer
[29],
723 buffer
[35], buffer
[38], buffer
[39], buffer
[40], buffer
[41],
724 buffer
[46] << 8 | buffer
[47],
725 buffer
[42], buffer
[43], buffer
[44], buffer
[45],
726 buffer
[48] << 8 | buffer
[49]);
728 for (i
= 0, k
= 0; i
< (size
+ 7) / 8; i
++) {
729 printk(KERN_DEBUG
"%s: %s", name
, i
? " " : "buffer:");
730 for (j
= 0; j
< 8 && k
< size
; j
++, k
++)
731 printk(" %02x", buffer
[k
]);
739 * SB1000 commands for frame rx interrupt
741 /* receive a single frame and assemble datagram
742 * (this is the heart of the interrupt routine)
745 sb1000_rx(struct net_device
*dev
)
748 #define FRAMESIZE 184
749 unsigned char st
[2], buffer
[FRAMESIZE
], session_id
, frame_id
;
752 unsigned int skbsize
;
754 struct sb1000_private
*lp
= netdev_priv(dev
);
755 struct net_device_stats
*stats
= &dev
->stats
;
757 /* SB1000 frame constants */
758 const int FrameSize
= FRAMESIZE
;
759 const int NewDatagramHeaderSkip
= 8;
760 const int NewDatagramHeaderSize
= NewDatagramHeaderSkip
+ 18;
761 const int NewDatagramDataSize
= FrameSize
- NewDatagramHeaderSize
;
762 const int ContDatagramHeaderSkip
= 7;
763 const int ContDatagramHeaderSize
= ContDatagramHeaderSkip
+ 1;
764 const int ContDatagramDataSize
= FrameSize
- ContDatagramHeaderSize
;
765 const int TrailerSize
= 4;
767 ioaddr
= dev
->base_addr
;
769 insw(ioaddr
, (unsigned short*) st
, 1);
771 printk("cm0: received: %02x %02x\n", st
[0], st
[1]);
772 #endif /* XXXDEBUG */
775 /* decide if it is a good or bad frame */
776 for (ns
= 0; ns
< NPIDS
; ns
++) {
777 session_id
= lp
->rx_session_id
[ns
];
778 frame_id
= lp
->rx_frame_id
[ns
];
779 if (st
[0] == session_id
) {
780 if (st
[1] == frame_id
|| (!frame_id
&& (st
[1] & 0xf0) == 0x30)) {
782 } else if ((st
[1] & 0xf0) == 0x30 && (st
[0] & 0x40)) {
787 } else if (st
[0] == (session_id
| 0x40)) {
788 if ((st
[1] & 0xf0) == 0x30) {
798 stats
->rx_frame_errors
++;
799 skb
= lp
->rx_skb
[ns
];
800 if (sb1000_debug
> 1)
801 printk(KERN_WARNING
"%s: missing frame(s): got %02x %02x "
802 "expecting %02x %02x\n", dev
->name
, st
[0], st
[1],
803 skb
? session_id
: session_id
| 0x40, frame_id
);
810 lp
->rx_frame_id
[ns
] = 0x30 | ((st
[1] + 1) & 0x0f);
813 /* get data length */
814 insw(ioaddr
, buffer
, NewDatagramHeaderSize
/ 2);
816 printk("cm0: IP identification: %02x%02x fragment offset: %02x%02x\n", buffer
[30], buffer
[31], buffer
[32], buffer
[33]);
817 #endif /* XXXDEBUG */
818 if (buffer
[0] != NewDatagramHeaderSkip
) {
819 if (sb1000_debug
> 1)
820 printk(KERN_WARNING
"%s: new datagram header skip error: "
821 "got %02x expecting %02x\n", dev
->name
, buffer
[0],
822 NewDatagramHeaderSkip
);
823 stats
->rx_length_errors
++;
824 insw(ioaddr
, buffer
, NewDatagramDataSize
/ 2);
827 dlen
= ((buffer
[NewDatagramHeaderSkip
+ 3] & 0x0f) << 8 |
828 buffer
[NewDatagramHeaderSkip
+ 4]) - 17;
829 if (dlen
> SB1000_MRU
) {
830 if (sb1000_debug
> 1)
831 printk(KERN_WARNING
"%s: datagram length (%d) greater "
832 "than MRU (%d)\n", dev
->name
, dlen
, SB1000_MRU
);
833 stats
->rx_length_errors
++;
834 insw(ioaddr
, buffer
, NewDatagramDataSize
/ 2);
837 lp
->rx_dlen
[ns
] = dlen
;
838 /* compute size to allocate for datagram */
839 skbsize
= dlen
+ FrameSize
;
840 if ((skb
= alloc_skb(skbsize
, GFP_ATOMIC
)) == NULL
) {
841 if (sb1000_debug
> 1)
842 printk(KERN_WARNING
"%s: can't allocate %d bytes long "
843 "skbuff\n", dev
->name
, skbsize
);
845 insw(ioaddr
, buffer
, NewDatagramDataSize
/ 2);
849 skb_reset_mac_header(skb
);
850 skb
->protocol
= (unsigned short) buffer
[NewDatagramHeaderSkip
+ 16];
851 insw(ioaddr
, skb_put(skb
, NewDatagramDataSize
),
852 NewDatagramDataSize
/ 2);
853 lp
->rx_skb
[ns
] = skb
;
855 /* continuation of previous datagram */
856 insw(ioaddr
, buffer
, ContDatagramHeaderSize
/ 2);
857 if (buffer
[0] != ContDatagramHeaderSkip
) {
858 if (sb1000_debug
> 1)
859 printk(KERN_WARNING
"%s: cont datagram header skip error: "
860 "got %02x expecting %02x\n", dev
->name
, buffer
[0],
861 ContDatagramHeaderSkip
);
862 stats
->rx_length_errors
++;
863 insw(ioaddr
, buffer
, ContDatagramDataSize
/ 2);
866 skb
= lp
->rx_skb
[ns
];
867 insw(ioaddr
, skb_put(skb
, ContDatagramDataSize
),
868 ContDatagramDataSize
/ 2);
869 dlen
= lp
->rx_dlen
[ns
];
871 if (skb
->len
< dlen
+ TrailerSize
) {
872 lp
->rx_session_id
[ns
] &= ~0x40;
876 /* datagram completed: send to upper level */
879 stats
->rx_bytes
+=dlen
;
881 lp
->rx_skb
[ns
] = NULL
;
882 lp
->rx_session_id
[ns
] |= 0x40;
886 insw(ioaddr
, buffer
, FrameSize
/ 2);
887 if (sb1000_debug
> 1)
888 printk(KERN_WARNING
"%s: frame error: got %02x %02x\n",
889 dev
->name
, st
[0], st
[1]);
890 stats
->rx_frame_errors
++;
892 if (sb1000_debug
> 2)
893 sb1000_print_status_buffer(dev
->name
, st
, buffer
, FrameSize
);
897 if ((skb
= lp
->rx_skb
[ns
])) {
899 lp
->rx_skb
[ns
] = NULL
;
901 lp
->rx_session_id
[ns
] |= 0x40;
907 sb1000_error_dpc(struct net_device
*dev
)
909 static const unsigned char Command0
[6] = {0x80, 0x26, 0x00, 0x00, 0x00, 0x00};
914 struct sb1000_private
*lp
= netdev_priv(dev
);
915 const int ErrorDpcCounterInitialize
= 200;
917 ioaddr
[0] = dev
->base_addr
;
918 /* mem_start holds the second I/O address */
919 ioaddr
[1] = dev
->mem_start
;
922 sb1000_wait_for_ready_clear(ioaddr
, name
);
923 sb1000_send_command(ioaddr
, name
, Command0
);
924 sb1000_wait_for_ready(ioaddr
, name
);
925 sb1000_read_status(ioaddr
, st
);
927 lp
->rx_error_dpc_count
= ErrorDpcCounterInitialize
;
933 * Linux interface functions
936 sb1000_open(struct net_device
*dev
)
939 int ioaddr
[2], status
;
940 struct sb1000_private
*lp
= netdev_priv(dev
);
941 const unsigned short FirmwareVersion
[] = {0x01, 0x01};
943 ioaddr
[0] = dev
->base_addr
;
944 /* mem_start holds the second I/O address */
945 ioaddr
[1] = dev
->mem_start
;
948 /* initialize sb1000 */
949 if ((status
= sb1000_reset(ioaddr
, name
)))
952 if ((status
= sb1000_check_CRC(ioaddr
, name
)))
955 /* initialize private data before board can catch interrupts */
956 lp
->rx_skb
[0] = NULL
;
957 lp
->rx_skb
[1] = NULL
;
958 lp
->rx_skb
[2] = NULL
;
959 lp
->rx_skb
[3] = NULL
;
965 lp
->rx_error_count
= 0;
966 lp
->rx_error_dpc_count
= 0;
967 lp
->rx_session_id
[0] = 0x50;
968 lp
->rx_session_id
[0] = 0x48;
969 lp
->rx_session_id
[0] = 0x44;
970 lp
->rx_session_id
[0] = 0x42;
971 lp
->rx_frame_id
[0] = 0;
972 lp
->rx_frame_id
[1] = 0;
973 lp
->rx_frame_id
[2] = 0;
974 lp
->rx_frame_id
[3] = 0;
975 if (request_irq(dev
->irq
, &sb1000_interrupt
, 0, "sb1000", dev
)) {
979 if (sb1000_debug
> 2)
980 printk(KERN_DEBUG
"%s: Opening, IRQ %d\n", name
, dev
->irq
);
982 /* Activate board and check firmware version */
984 if ((status
= sb1000_activate(ioaddr
, name
)))
987 if ((status
= sb1000_get_firmware_version(ioaddr
, name
, version
, 0)))
989 if (version
[0] != FirmwareVersion
[0] || version
[1] != FirmwareVersion
[1])
990 printk(KERN_WARNING
"%s: found firmware version %x.%02x "
991 "(should be %x.%02x)\n", name
, version
[0], version
[1],
992 FirmwareVersion
[0], FirmwareVersion
[1]);
995 netif_start_queue(dev
);
996 return 0; /* Always succeed */
999 static int sb1000_dev_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
1002 unsigned char version
[2];
1004 int ioaddr
[2], status
, frequency
;
1005 unsigned int stats
[5];
1006 struct sb1000_private
*lp
= netdev_priv(dev
);
1008 if (!(dev
&& dev
->flags
& IFF_UP
))
1011 ioaddr
[0] = dev
->base_addr
;
1012 /* mem_start holds the second I/O address */
1013 ioaddr
[1] = dev
->mem_start
;
1017 case SIOCGCMSTATS
: /* get statistics */
1018 stats
[0] = dev
->stats
.rx_bytes
;
1019 stats
[1] = lp
->rx_frames
;
1020 stats
[2] = dev
->stats
.rx_packets
;
1021 stats
[3] = dev
->stats
.rx_errors
;
1022 stats
[4] = dev
->stats
.rx_dropped
;
1023 if(copy_to_user(ifr
->ifr_data
, stats
, sizeof(stats
)))
1028 case SIOCGCMFIRMWARE
: /* get firmware version */
1029 if ((status
= sb1000_get_firmware_version(ioaddr
, name
, version
, 1)))
1031 if(copy_to_user(ifr
->ifr_data
, version
, sizeof(version
)))
1035 case SIOCGCMFREQUENCY
: /* get frequency */
1036 if ((status
= sb1000_get_frequency(ioaddr
, name
, &frequency
)))
1038 if(put_user(frequency
, (int __user
*) ifr
->ifr_data
))
1042 case SIOCSCMFREQUENCY
: /* set frequency */
1043 if (!capable(CAP_NET_ADMIN
))
1045 if(get_user(frequency
, (int __user
*) ifr
->ifr_data
))
1047 if ((status
= sb1000_set_frequency(ioaddr
, name
, frequency
)))
1051 case SIOCGCMPIDS
: /* get PIDs */
1052 if ((status
= sb1000_get_PIDs(ioaddr
, name
, PID
)))
1054 if(copy_to_user(ifr
->ifr_data
, PID
, sizeof(PID
)))
1058 case SIOCSCMPIDS
: /* set PIDs */
1059 if (!capable(CAP_NET_ADMIN
))
1061 if(copy_from_user(PID
, ifr
->ifr_data
, sizeof(PID
)))
1063 if ((status
= sb1000_set_PIDs(ioaddr
, name
, PID
)))
1065 /* set session_id, frame_id and pkt_type too */
1066 lp
->rx_session_id
[0] = 0x50 | (PID
[0] & 0x0f);
1067 lp
->rx_session_id
[1] = 0x48;
1068 lp
->rx_session_id
[2] = 0x44;
1069 lp
->rx_session_id
[3] = 0x42;
1070 lp
->rx_frame_id
[0] = 0;
1071 lp
->rx_frame_id
[1] = 0;
1072 lp
->rx_frame_id
[2] = 0;
1073 lp
->rx_frame_id
[3] = 0;
1083 /* transmit function: do nothing since SB1000 can't send anything out */
1085 sb1000_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1087 printk(KERN_WARNING
"%s: trying to transmit!!!\n", dev
->name
);
1088 /* sb1000 can't xmit datagrams */
1090 return NETDEV_TX_OK
;
1093 /* SB1000 interrupt handler. */
1094 static irqreturn_t
sb1000_interrupt(int irq
, void *dev_id
)
1096 static const unsigned char Command0
[6] = {0x80, 0x2c, 0x00, 0x00, 0x00, 0x00};
1097 static const unsigned char Command1
[6] = {0x80, 0x2e, 0x00, 0x00, 0x00, 0x00};
1102 struct net_device
*dev
= dev_id
;
1103 struct sb1000_private
*lp
= netdev_priv(dev
);
1105 const int MaxRxErrorCount
= 6;
1107 ioaddr
[0] = dev
->base_addr
;
1108 /* mem_start holds the second I/O address */
1109 ioaddr
[1] = dev
->mem_start
;
1112 /* is it a good interrupt? */
1113 st
= inb(ioaddr
[1] + 6);
1114 if (!(st
& 0x08 && st
& 0x20)) {
1118 if (sb1000_debug
> 3)
1119 printk(KERN_DEBUG
"%s: entering interrupt\n", dev
->name
);
1121 st
= inb(ioaddr
[0] + 7);
1123 lp
->rx_error_count
++;
1125 udelay(SB1000_DELAY
);
1126 #endif /* SB1000_DELAY */
1127 sb1000_issue_read_command(ioaddr
, name
);
1129 sb1000_error_dpc(dev
);
1130 sb1000_issue_read_command(ioaddr
, name
);
1132 if (lp
->rx_error_dpc_count
&& !(--lp
->rx_error_dpc_count
)) {
1133 sb1000_wait_for_ready_clear(ioaddr
, name
);
1134 sb1000_send_command(ioaddr
, name
, Command0
);
1135 sb1000_wait_for_ready(ioaddr
, name
);
1136 sb1000_issue_read_command(ioaddr
, name
);
1138 if (lp
->rx_error_count
>= MaxRxErrorCount
) {
1139 sb1000_wait_for_ready_clear(ioaddr
, name
);
1140 sb1000_send_command(ioaddr
, name
, Command1
);
1141 sb1000_wait_for_ready(ioaddr
, name
);
1142 sb1000_issue_read_command(ioaddr
, name
);
1143 lp
->rx_error_count
= 0;
1149 static int sb1000_close(struct net_device
*dev
)
1153 struct sb1000_private
*lp
= netdev_priv(dev
);
1155 if (sb1000_debug
> 2)
1156 printk(KERN_DEBUG
"%s: Shutting down sb1000.\n", dev
->name
);
1158 netif_stop_queue(dev
);
1160 ioaddr
[0] = dev
->base_addr
;
1161 /* mem_start holds the second I/O address */
1162 ioaddr
[1] = dev
->mem_start
;
1164 free_irq(dev
->irq
, dev
);
1165 /* If we don't do this, we can't re-insmod it later. */
1166 release_region(ioaddr
[1], SB1000_IO_EXTENT
);
1167 release_region(ioaddr
[0], SB1000_IO_EXTENT
);
1169 /* free rx_skb's if needed */
1170 for (i
=0; i
<4; i
++) {
1171 if (lp
->rx_skb
[i
]) {
1172 dev_kfree_skb(lp
->rx_skb
[i
]);
1178 MODULE_AUTHOR("Franco Venturi <fventuri@mediaone.net>");
1179 MODULE_DESCRIPTION("General Instruments SB1000 driver");
1180 MODULE_LICENSE("GPL");
1185 return pnp_register_driver(&sb1000_driver
);
1191 pnp_unregister_driver(&sb1000_driver
);
1194 module_init(sb1000_init
);
1195 module_exit(sb1000_exit
);