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>
39 #include <linux/version.h>
40 #include <linux/kernel.h>
41 #include <linux/sched.h>
42 #include <linux/string.h>
43 #include <linux/interrupt.h>
44 #include <linux/ptrace.h>
45 #include <linux/errno.h>
47 #include <linux/malloc.h>
48 #include <linux/ioport.h>
49 #include <linux/netdevice.h>
50 #include <linux/if_arp.h>
51 #include <linux/skbuff.h>
52 #include <linux/delay.h> /* for udelay() */
53 #include <asm/processor.h>
55 #include <asm/bitops.h>
57 #include <asm/uaccess.h>
58 #include <linux/etherdevice.h>
59 #include <linux/isapnp.h>
61 /* for SIOGCM/SIOSCM stuff */
63 #include <linux/if_cablemodem.h>
66 int sb1000_debug
= SB1000_DEBUG
;
71 static const int SB1000_IO_EXTENT
= 8;
72 /* SB1000 Maximum Receive Unit */
73 static const int SB1000_MRU
= 1500; /* octects */
76 struct sb1000_private
{
77 struct sk_buff
*rx_skb
[NPIDS
];
79 unsigned int rx_bytes
;
80 unsigned int rx_frames
;
82 short rx_error_dpc_count
;
83 unsigned char rx_session_id
[NPIDS
];
84 unsigned char rx_frame_id
[NPIDS
];
85 unsigned char rx_pkt_type
[NPIDS
];
86 struct net_device_stats stats
;
89 /* prototypes for Linux interface */
90 extern int sb1000_probe(struct net_device
*dev
);
91 static int sb1000_open(struct net_device
*dev
);
92 static int sb1000_dev_ioctl (struct net_device
*dev
, struct ifreq
*ifr
, int cmd
);
93 static int sb1000_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
94 static void sb1000_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
);
95 static struct net_device_stats
*sb1000_stats(struct net_device
*dev
);
96 static int sb1000_close(struct net_device
*dev
);
99 /* SB1000 hardware routines to be used during open/configuration phases */
100 static inline void nicedelay(unsigned long usecs
);
101 static inline int card_wait_for_busy_clear(const int ioaddr
[],
103 static inline int card_wait_for_ready(const int ioaddr
[], const char* name
,
105 static inline int card_send_command(const int ioaddr
[], const char* name
,
106 const unsigned char out
[], unsigned char in
[]);
108 /* SB1000 hardware routines to be used during frame rx interrupt */
109 static inline int sb1000_wait_for_ready(const int ioaddr
[], const char* name
);
110 static inline int sb1000_wait_for_ready_clear(const int ioaddr
[],
112 static inline void sb1000_send_command(const int ioaddr
[], const char* name
,
113 const unsigned char out
[]);
114 static inline void sb1000_read_status(const int ioaddr
[], unsigned char in
[]);
115 static inline void sb1000_issue_read_command(const int ioaddr
[],
118 /* SB1000 commands for open/configuration */
119 static inline int sb1000_reset(const int ioaddr
[], const char* name
);
120 static inline int sb1000_check_CRC(const int ioaddr
[], const char* name
);
121 static inline int sb1000_start_get_set_command(const int ioaddr
[],
123 static inline int sb1000_end_get_set_command(const int ioaddr
[],
125 static inline int sb1000_activate(const int ioaddr
[], const char* name
);
126 static inline int sb1000_get_firmware_version(const int ioaddr
[],
127 const char* name
, unsigned char version
[], int do_end
);
128 static inline int sb1000_get_frequency(const int ioaddr
[], const char* name
,
130 static inline int sb1000_set_frequency(const int ioaddr
[], const char* name
,
132 static inline int sb1000_get_PIDs(const int ioaddr
[], const char* name
,
134 static inline int sb1000_set_PIDs(const int ioaddr
[], const char* name
,
137 /* SB1000 commands for frame rx interrupt */
138 static inline int sb1000_rx(struct net_device
*dev
);
139 static inline void sb1000_error_dpc(struct net_device
*dev
);
141 /* probe for SB1000 using Plug-n-Play mechanism */
143 sb1000_probe(struct net_device
*dev
)
146 unsigned short ioaddr
[2], irq
;
147 struct pci_dev
*idev
=NULL
;
148 unsigned int serial_number
;
156 idev
=isapnp_find_dev(NULL
, ISAPNP_VENDOR('G','I','C'),
157 ISAPNP_FUNCTION(0x1000), idev
);
171 idev
->activate(idev
);
177 if(!idev
->resource
[0].start
|| check_region(idev
->resource
[0].start
, 16))
179 if(!idev
->resource
[1].start
|| check_region(idev
->resource
[1].start
, 16))
182 serial_number
= idev
->bus
->serial
;
184 ioaddr
[0]=idev
->resource
[0].start
;
185 ioaddr
[1]=idev
->resource
[1].start
;
189 /* check I/O base and IRQ */
190 if (dev
->base_addr
!= 0 && dev
->base_addr
!= ioaddr
[0])
192 if (dev
->rmem_end
!= 0 && dev
->rmem_end
!= ioaddr
[1])
194 if (dev
->irq
!= 0 && dev
->irq
!= irq
)
202 dev
->base_addr
= ioaddr
[0];
203 /* rmem_end holds the second I/O address - fv */
204 dev
->rmem_end
= ioaddr
[1];
207 if (sb1000_debug
> 0)
208 printk(KERN_NOTICE
"%s: sb1000 at (%#3.3lx,%#3.3lx), "
209 "S/N %#8.8x, IRQ %d.\n", dev
->name
, dev
->base_addr
,
210 dev
->rmem_end
, serial_number
, dev
->irq
);
212 dev
= init_etherdev(dev
, 0);
215 SET_MODULE_OWNER(dev
);
217 /* Make up a SB1000-specific-data structure. */
218 dev
->priv
= kmalloc(sizeof(struct sb1000_private
), GFP_KERNEL
);
219 if (dev
->priv
== NULL
)
221 memset(dev
->priv
, 0, sizeof(struct sb1000_private
));
223 if (sb1000_debug
> 0)
224 printk(KERN_NOTICE
"%s", version
);
226 /* The SB1000-specific entries in the device structure. */
227 dev
->open
= sb1000_open
;
228 dev
->do_ioctl
= sb1000_dev_ioctl
;
229 dev
->hard_start_xmit
= sb1000_start_xmit
;
230 dev
->stop
= sb1000_close
;
231 dev
->get_stats
= sb1000_stats
;
233 /* Fill in the generic fields of the device structure. */
234 dev
->change_mtu
= NULL
;
235 dev
->hard_header
= NULL
;
236 dev
->rebuild_header
= NULL
;
237 dev
->set_mac_address
= NULL
;
238 dev
->header_cache_update
= NULL
;
240 dev
->type
= ARPHRD_ETHER
;
241 dev
->hard_header_len
= 0;
243 dev
->addr_len
= ETH_ALEN
;
244 /* hardware address is 0:0:serial_number */
245 dev
->dev_addr
[0] = 0;
246 dev
->dev_addr
[1] = 0;
247 dev
->dev_addr
[2] = serial_number
>> 24 & 0xff;
248 dev
->dev_addr
[3] = serial_number
>> 16 & 0xff;
249 dev
->dev_addr
[4] = serial_number
>> 8 & 0xff;
250 dev
->dev_addr
[5] = serial_number
>> 0 & 0xff;
251 dev
->tx_queue_len
= 0;
253 /* New-style flags. */
254 dev
->flags
= IFF_POINTOPOINT
|IFF_NOARP
;
258 request_region(ioaddr
[0], 16, dev
->name
);
259 request_region(ioaddr
[1], 16, dev
->name
);
267 * SB1000 hardware routines to be used during open/configuration phases
270 const int TimeOutJiffies
= (int)(8.75 * HZ
);
272 static inline void nicedelay(unsigned long usecs
)
274 current
->state
= TASK_INTERRUPTIBLE
;
275 schedule_timeout(HZ
);
279 /* Card Wait For Busy Clear (cannot be used during an interrupt) */
281 card_wait_for_busy_clear(const int ioaddr
[], const char* name
)
284 unsigned long timeout
;
286 a
= inb(ioaddr
[0] + 7);
287 timeout
= jiffies
+ TimeOutJiffies
;
288 while (a
& 0x80 || a
& 0x40) {
290 current
->state
= TASK_INTERRUPTIBLE
;
292 a
= inb(ioaddr
[0] + 7);
293 if (jiffies
>= timeout
) {
294 printk(KERN_WARNING
"%s: card_wait_for_busy_clear timeout\n",
303 /* Card Wait For Ready (cannot be used during an interrupt) */
305 card_wait_for_ready(const int ioaddr
[], const char* name
, unsigned char in
[])
308 unsigned long timeout
;
310 a
= inb(ioaddr
[1] + 6);
311 timeout
= jiffies
+ TimeOutJiffies
;
312 while (a
& 0x80 || !(a
& 0x40)) {
314 current
->state
= TASK_INTERRUPTIBLE
;
316 a
= inb(ioaddr
[1] + 6);
317 if (jiffies
>= timeout
) {
318 printk(KERN_WARNING
"%s: card_wait_for_ready timeout\n",
324 in
[1] = inb(ioaddr
[0] + 1);
325 in
[2] = inb(ioaddr
[0] + 2);
326 in
[3] = inb(ioaddr
[0] + 3);
327 in
[4] = inb(ioaddr
[0] + 4);
328 in
[0] = inb(ioaddr
[0] + 5);
329 in
[6] = inb(ioaddr
[0] + 6);
330 in
[5] = inb(ioaddr
[1] + 6);
334 /* Card Send Command (cannot be used during an interrupt) */
336 card_send_command(const int ioaddr
[], const char* name
,
337 const unsigned char out
[], unsigned char in
[])
341 if ((status
= card_wait_for_busy_clear(ioaddr
, name
)))
343 outb(0xa0, ioaddr
[0] + 6);
344 outb(out
[2], ioaddr
[0] + 1);
345 outb(out
[3], ioaddr
[0] + 2);
346 outb(out
[4], ioaddr
[0] + 3);
347 outb(out
[5], ioaddr
[0] + 4);
348 outb(out
[1], ioaddr
[0] + 5);
349 outb(0xa0, ioaddr
[0] + 6);
350 outb(out
[0], ioaddr
[0] + 7);
351 if (out
[0] != 0x20 && out
[0] != 0x30) {
352 if ((status
= card_wait_for_ready(ioaddr
, name
, in
)))
355 if (sb1000_debug
> 3)
356 printk(KERN_DEBUG
"%s: card_send_command "
357 "out: %02x%02x%02x%02x%02x%02x "
358 "in: %02x%02x%02x%02x%02x%02x%02x\n", name
,
359 out
[0], out
[1], out
[2], out
[3], out
[4], out
[5],
360 in
[0], in
[1], in
[2], in
[3], in
[4], in
[5], in
[6]);
362 if (sb1000_debug
> 3)
363 printk(KERN_DEBUG
"%s: card_send_command "
364 "out: %02x%02x%02x%02x%02x%02x\n", name
,
365 out
[0], out
[1], out
[2], out
[3], out
[4], out
[5]);
368 if (out
[1] == 0x1b) {
369 x
= (out
[2] == 0x02);
371 if (out
[0] >= 0x80 && in
[0] != (out
[1] | 0x80))
379 * SB1000 hardware routines to be used during frame rx interrupt
381 const int Sb1000TimeOutJiffies
= 7 * HZ
;
383 /* Card Wait For Ready (to be used during frame rx) */
385 sb1000_wait_for_ready(const int ioaddr
[], const char* name
)
387 unsigned long timeout
;
389 timeout
= jiffies
+ Sb1000TimeOutJiffies
;
390 while (inb(ioaddr
[1] + 6) & 0x80) {
391 if (jiffies
>= timeout
) {
392 printk(KERN_WARNING
"%s: sb1000_wait_for_ready timeout\n",
397 timeout
= jiffies
+ Sb1000TimeOutJiffies
;
398 while (!(inb(ioaddr
[1] + 6) & 0x40)) {
399 if (jiffies
>= timeout
) {
400 printk(KERN_WARNING
"%s: sb1000_wait_for_ready timeout\n",
409 /* Card Wait For Ready Clear (to be used during frame rx) */
411 sb1000_wait_for_ready_clear(const int ioaddr
[], const char* name
)
413 unsigned long timeout
;
415 timeout
= jiffies
+ Sb1000TimeOutJiffies
;
416 while (inb(ioaddr
[1] + 6) & 0x80) {
417 if (jiffies
>= timeout
) {
418 printk(KERN_WARNING
"%s: sb1000_wait_for_ready_clear timeout\n",
423 timeout
= jiffies
+ Sb1000TimeOutJiffies
;
424 while (inb(ioaddr
[1] + 6) & 0x40) {
425 if (jiffies
>= timeout
) {
426 printk(KERN_WARNING
"%s: sb1000_wait_for_ready_clear timeout\n",
434 /* Card Send Command (to be used during frame rx) */
436 sb1000_send_command(const int ioaddr
[], const char* name
,
437 const unsigned char out
[])
439 outb(out
[2], ioaddr
[0] + 1);
440 outb(out
[3], ioaddr
[0] + 2);
441 outb(out
[4], ioaddr
[0] + 3);
442 outb(out
[5], ioaddr
[0] + 4);
443 outb(out
[1], ioaddr
[0] + 5);
444 outb(out
[0], ioaddr
[0] + 7);
445 if (sb1000_debug
> 3)
446 printk(KERN_DEBUG
"%s: sb1000_send_command out: %02x%02x%02x%02x"
447 "%02x%02x\n", name
, out
[0], out
[1], out
[2], out
[3], out
[4], out
[5]);
451 /* Card Read Status (to be used during frame rx) */
453 sb1000_read_status(const int ioaddr
[], unsigned char in
[])
455 in
[1] = inb(ioaddr
[0] + 1);
456 in
[2] = inb(ioaddr
[0] + 2);
457 in
[3] = inb(ioaddr
[0] + 3);
458 in
[4] = inb(ioaddr
[0] + 4);
459 in
[0] = inb(ioaddr
[0] + 5);
463 /* Issue Read Command (to be used during frame rx) */
465 sb1000_issue_read_command(const int ioaddr
[], const char* name
)
467 const unsigned char Command0
[6] = {0x20, 0x00, 0x00, 0x01, 0x00, 0x00};
469 sb1000_wait_for_ready_clear(ioaddr
, name
);
470 outb(0xa0, ioaddr
[0] + 6);
471 sb1000_send_command(ioaddr
, name
, Command0
);
477 * SB1000 commands for open/configuration
479 /* reset SB1000 card */
481 sb1000_reset(const int ioaddr
[], const char* name
)
485 const unsigned char Command0
[6] = {0x80, 0x16, 0x00, 0x00, 0x00, 0x00};
487 port
= ioaddr
[1] + 6;
501 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
508 /* check SB1000 firmware CRC */
510 sb1000_check_CRC(const int ioaddr
[], const char* name
)
514 const unsigned char Command0
[6] = {0x80, 0x1f, 0x00, 0x00, 0x00, 0x00};
517 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
519 if (st
[1] != st
[3] || st
[2] != st
[4])
521 crc
= st
[1] << 8 | st
[2];
526 sb1000_start_get_set_command(const int ioaddr
[], const char* name
)
529 const unsigned char Command0
[6] = {0x80, 0x1b, 0x00, 0x00, 0x00, 0x00};
531 return card_send_command(ioaddr
, name
, Command0
, st
);
535 sb1000_end_get_set_command(const int ioaddr
[], const char* name
)
539 const unsigned char Command0
[6] = {0x80, 0x1b, 0x02, 0x00, 0x00, 0x00};
540 const unsigned char Command1
[6] = {0x20, 0x00, 0x00, 0x00, 0x00, 0x00};
542 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
544 return card_send_command(ioaddr
, name
, Command1
, st
);
548 sb1000_activate(const int ioaddr
[], const char* name
)
552 const unsigned char Command0
[6] = {0x80, 0x11, 0x00, 0x00, 0x00, 0x00};
553 const unsigned char Command1
[6] = {0x80, 0x16, 0x00, 0x00, 0x00, 0x00};
556 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
558 if ((status
= card_send_command(ioaddr
, name
, Command1
, st
)))
561 if ((status
= sb1000_start_get_set_command(ioaddr
, name
)))
566 return sb1000_start_get_set_command(ioaddr
, name
);
569 /* get SB1000 firmware version */
571 sb1000_get_firmware_version(const int ioaddr
[], const char* name
,
572 unsigned char version
[], int do_end
)
576 const unsigned char Command0
[6] = {0x80, 0x23, 0x00, 0x00, 0x00, 0x00};
578 if ((status
= sb1000_start_get_set_command(ioaddr
, name
)))
580 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
587 return sb1000_end_get_set_command(ioaddr
, name
);
592 /* get SB1000 frequency */
594 sb1000_get_frequency(const int ioaddr
[], const char* name
, int* frequency
)
598 const unsigned char Command0
[6] = {0x80, 0x44, 0x00, 0x00, 0x00, 0x00};
601 if ((status
= sb1000_start_get_set_command(ioaddr
, name
)))
603 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
605 *frequency
= ((st
[1] << 8 | st
[2]) << 8 | st
[3]) << 8 | st
[4];
606 return sb1000_end_get_set_command(ioaddr
, name
);
609 /* set SB1000 frequency */
611 sb1000_set_frequency(const int ioaddr
[], const char* name
, int frequency
)
615 unsigned char Command0
[6] = {0x80, 0x29, 0x00, 0x00, 0x00, 0x00};
617 const int FrequencyLowerLimit
= 57000;
618 const int FrequencyUpperLimit
= 804000;
620 if (frequency
< FrequencyLowerLimit
|| frequency
> FrequencyUpperLimit
) {
621 printk(KERN_ERR
"%s: frequency chosen (%d kHz) is not in the range "
622 "[%d,%d] kHz\n", name
, frequency
, FrequencyLowerLimit
,
623 FrequencyUpperLimit
);
627 if ((status
= sb1000_start_get_set_command(ioaddr
, name
)))
629 Command0
[5] = frequency
& 0xff;
631 Command0
[4] = frequency
& 0xff;
633 Command0
[3] = frequency
& 0xff;
635 Command0
[2] = frequency
& 0xff;
636 return card_send_command(ioaddr
, name
, Command0
, st
);
639 /* get SB1000 PIDs */
641 sb1000_get_PIDs(const int ioaddr
[], const char* name
, short PID
[])
645 const unsigned char Command0
[6] = {0x80, 0x40, 0x00, 0x00, 0x00, 0x00};
646 const unsigned char Command1
[6] = {0x80, 0x41, 0x00, 0x00, 0x00, 0x00};
647 const unsigned char Command2
[6] = {0x80, 0x42, 0x00, 0x00, 0x00, 0x00};
648 const unsigned char Command3
[6] = {0x80, 0x43, 0x00, 0x00, 0x00, 0x00};
651 if ((status
= sb1000_start_get_set_command(ioaddr
, name
)))
654 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
656 PID
[0] = st
[1] << 8 | st
[2];
658 if ((status
= card_send_command(ioaddr
, name
, Command1
, st
)))
660 PID
[1] = st
[1] << 8 | st
[2];
662 if ((status
= card_send_command(ioaddr
, name
, Command2
, st
)))
664 PID
[2] = st
[1] << 8 | st
[2];
666 if ((status
= card_send_command(ioaddr
, name
, Command3
, st
)))
668 PID
[3] = st
[1] << 8 | st
[2];
670 return sb1000_end_get_set_command(ioaddr
, name
);
673 /* set SB1000 PIDs */
675 sb1000_set_PIDs(const int ioaddr
[], const char* name
, const short PID
[])
680 unsigned char Command0
[6] = {0x80, 0x31, 0x00, 0x00, 0x00, 0x00};
681 unsigned char Command1
[6] = {0x80, 0x32, 0x00, 0x00, 0x00, 0x00};
682 unsigned char Command2
[6] = {0x80, 0x33, 0x00, 0x00, 0x00, 0x00};
683 unsigned char Command3
[6] = {0x80, 0x34, 0x00, 0x00, 0x00, 0x00};
684 const unsigned char Command4
[6] = {0x80, 0x2e, 0x00, 0x00, 0x00, 0x00};
687 if ((status
= sb1000_start_get_set_command(ioaddr
, name
)))
691 Command0
[3] = p
& 0xff;
693 Command0
[2] = p
& 0xff;
694 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
698 Command1
[3] = p
& 0xff;
700 Command1
[2] = p
& 0xff;
701 if ((status
= card_send_command(ioaddr
, name
, Command1
, st
)))
705 Command2
[3] = p
& 0xff;
707 Command2
[2] = p
& 0xff;
708 if ((status
= card_send_command(ioaddr
, name
, Command2
, st
)))
712 Command3
[3] = p
& 0xff;
714 Command3
[2] = p
& 0xff;
715 if ((status
= card_send_command(ioaddr
, name
, Command3
, st
)))
718 if ((status
= card_send_command(ioaddr
, name
, Command4
, st
)))
720 return sb1000_end_get_set_command(ioaddr
, name
);
725 sb1000_print_status_buffer(const char* name
, unsigned char st
[],
726 unsigned char buffer
[], int size
)
730 printk(KERN_DEBUG
"%s: status: %02x %02x\n", name
, st
[0], st
[1]);
731 if (buffer
[24] == 0x08 && buffer
[25] == 0x00 && buffer
[26] == 0x45) {
732 printk(KERN_DEBUG
"%s: length: %d protocol: %d from: %d.%d.%d.%d:%d "
733 "to %d.%d.%d.%d:%d\n", name
, buffer
[28] << 8 | buffer
[29],
734 buffer
[35], buffer
[38], buffer
[39], buffer
[40], buffer
[41],
735 buffer
[46] << 8 | buffer
[47],
736 buffer
[42], buffer
[43], buffer
[44], buffer
[45],
737 buffer
[48] << 8 | buffer
[49]);
739 for (i
= 0, k
= 0; i
< (size
+ 7) / 8; i
++) {
740 printk(KERN_DEBUG
"%s: %s", name
, i
? " " : "buffer:");
741 for (j
= 0; j
< 8 && k
< size
; j
++, k
++)
742 printk(" %02x", buffer
[k
]);
750 * SB1000 commands for frame rx interrupt
752 /* receive a single frame and assemble datagram
753 * (this is the heart of the interrupt routine)
756 sb1000_rx(struct net_device
*dev
)
759 #define FRAMESIZE 184
760 unsigned char st
[2], buffer
[FRAMESIZE
], session_id
, frame_id
;
763 unsigned int skbsize
;
765 struct sb1000_private
*lp
= (struct sb1000_private
*)dev
->priv
;
766 struct net_device_stats
*stats
= &lp
->stats
;
768 /* SB1000 frame constants */
769 const int FrameSize
= FRAMESIZE
;
770 const int NewDatagramHeaderSkip
= 8;
771 const int NewDatagramHeaderSize
= NewDatagramHeaderSkip
+ 18;
772 const int NewDatagramDataSize
= FrameSize
- NewDatagramHeaderSize
;
773 const int ContDatagramHeaderSkip
= 7;
774 const int ContDatagramHeaderSize
= ContDatagramHeaderSkip
+ 1;
775 const int ContDatagramDataSize
= FrameSize
- ContDatagramHeaderSize
;
776 const int TrailerSize
= 4;
778 ioaddr
= dev
->base_addr
;
780 insw(ioaddr
, (unsigned short*) st
, 1);
782 printk("cm0: received: %02x %02x\n", st
[0], st
[1]);
783 #endif /* XXXDEBUG */
786 /* decide if it is a good or bad frame */
787 for (ns
= 0; ns
< NPIDS
; ns
++) {
788 session_id
= lp
->rx_session_id
[ns
];
789 frame_id
= lp
->rx_frame_id
[ns
];
790 if (st
[0] == session_id
) {
791 if (st
[1] == frame_id
|| (!frame_id
&& (st
[1] & 0xf0) == 0x30)) {
793 } else if ((st
[1] & 0xf0) == 0x30 && (st
[0] & 0x40)) {
798 } else if (st
[0] == (session_id
| 0x40)) {
799 if ((st
[1] & 0xf0) == 0x30) {
809 stats
->rx_frame_errors
++;
810 skb
= lp
->rx_skb
[ns
];
811 if (sb1000_debug
> 1)
812 printk(KERN_WARNING
"%s: missing frame(s): got %02x %02x "
813 "expecting %02x %02x\n", dev
->name
, st
[0], st
[1],
814 skb
? session_id
: session_id
| 0x40, frame_id
);
821 lp
->rx_frame_id
[ns
] = 0x30 | ((st
[1] + 1) & 0x0f);
824 /* get data length */
825 insw(ioaddr
, buffer
, NewDatagramHeaderSize
/ 2);
827 printk("cm0: IP identification: %02x%02x fragment offset: %02x%02x\n", buffer
[30], buffer
[31], buffer
[32], buffer
[33]);
828 #endif /* XXXDEBUG */
829 if (buffer
[0] != NewDatagramHeaderSkip
) {
830 if (sb1000_debug
> 1)
831 printk(KERN_WARNING
"%s: new datagram header skip error: "
832 "got %02x expecting %02x\n", dev
->name
, buffer
[0],
833 NewDatagramHeaderSkip
);
834 stats
->rx_length_errors
++;
835 insw(ioaddr
, buffer
, NewDatagramDataSize
/ 2);
838 dlen
= ((buffer
[NewDatagramHeaderSkip
+ 3] & 0x0f) << 8 |
839 buffer
[NewDatagramHeaderSkip
+ 4]) - 17;
840 if (dlen
> SB1000_MRU
) {
841 if (sb1000_debug
> 1)
842 printk(KERN_WARNING
"%s: datagram length (%d) greater "
843 "than MRU (%d)\n", dev
->name
, dlen
, SB1000_MRU
);
844 stats
->rx_length_errors
++;
845 insw(ioaddr
, buffer
, NewDatagramDataSize
/ 2);
848 lp
->rx_dlen
[ns
] = dlen
;
849 /* compute size to allocate for datagram */
850 skbsize
= dlen
+ FrameSize
;
851 if ((skb
= alloc_skb(skbsize
, GFP_ATOMIC
)) == NULL
) {
852 if (sb1000_debug
> 1)
853 printk(KERN_WARNING
"%s: can't allocate %d bytes long "
854 "skbuff\n", dev
->name
, skbsize
);
856 insw(ioaddr
, buffer
, NewDatagramDataSize
/ 2);
860 skb
->mac
.raw
= skb
->data
;
861 skb
->protocol
= (unsigned short) buffer
[NewDatagramHeaderSkip
+ 16];
862 insw(ioaddr
, skb_put(skb
, NewDatagramDataSize
),
863 NewDatagramDataSize
/ 2);
864 lp
->rx_skb
[ns
] = skb
;
866 /* continuation of previous datagram */
867 insw(ioaddr
, buffer
, ContDatagramHeaderSize
/ 2);
868 if (buffer
[0] != ContDatagramHeaderSkip
) {
869 if (sb1000_debug
> 1)
870 printk(KERN_WARNING
"%s: cont datagram header skip error: "
871 "got %02x expecting %02x\n", dev
->name
, buffer
[0],
872 ContDatagramHeaderSkip
);
873 stats
->rx_length_errors
++;
874 insw(ioaddr
, buffer
, ContDatagramDataSize
/ 2);
877 skb
= lp
->rx_skb
[ns
];
878 insw(ioaddr
, skb_put(skb
, ContDatagramDataSize
),
879 ContDatagramDataSize
/ 2);
880 dlen
= lp
->rx_dlen
[ns
];
882 if (skb
->len
< dlen
+ TrailerSize
) {
883 lp
->rx_session_id
[ns
] &= ~0x40;
887 /* datagram completed: send to upper level */
890 stats
->rx_bytes
+=dlen
;
892 lp
->rx_bytes
+= dlen
;
894 lp
->rx_session_id
[ns
] |= 0x40;
898 insw(ioaddr
, buffer
, FrameSize
/ 2);
899 if (sb1000_debug
> 1)
900 printk(KERN_WARNING
"%s: frame error: got %02x %02x\n",
901 dev
->name
, st
[0], st
[1]);
902 stats
->rx_frame_errors
++;
904 if (sb1000_debug
> 2)
905 sb1000_print_status_buffer(dev
->name
, st
, buffer
, FrameSize
);
909 if ((skb
= lp
->rx_skb
[ns
])) {
913 lp
->rx_session_id
[ns
] |= 0x40;
919 sb1000_error_dpc(struct net_device
*dev
)
924 struct sb1000_private
*lp
= (struct sb1000_private
*)dev
->priv
;
925 const unsigned char Command0
[6] = {0x80, 0x26, 0x00, 0x00, 0x00, 0x00};
926 const int ErrorDpcCounterInitialize
= 200;
928 ioaddr
[0] = dev
->base_addr
;
929 /* rmem_end holds the second I/O address - fv */
930 ioaddr
[1] = dev
->rmem_end
;
933 sb1000_wait_for_ready_clear(ioaddr
, name
);
934 sb1000_send_command(ioaddr
, name
, Command0
);
935 sb1000_wait_for_ready(ioaddr
, name
);
936 sb1000_read_status(ioaddr
, st
);
938 lp
->rx_error_dpc_count
= ErrorDpcCounterInitialize
;
944 * Linux interface functions
947 sb1000_open(struct net_device
*dev
)
950 int ioaddr
[2], status
;
951 struct sb1000_private
*lp
= (struct sb1000_private
*)dev
->priv
;
952 const unsigned short FirmwareVersion
[] = {0x01, 0x01};
954 ioaddr
[0] = dev
->base_addr
;
955 /* rmem_end holds the second I/O address - fv */
956 ioaddr
[1] = dev
->rmem_end
;
958 request_region(ioaddr
[0], SB1000_IO_EXTENT
, "sb1000");
959 request_region(ioaddr
[1], SB1000_IO_EXTENT
, "sb1000");
961 /* initialize sb1000 */
962 if ((status
= sb1000_reset(ioaddr
, name
)))
965 if ((status
= sb1000_check_CRC(ioaddr
, name
)))
968 /* initialize private data before board can catch interrupts */
969 lp
->rx_skb
[0] = NULL
;
970 lp
->rx_skb
[1] = NULL
;
971 lp
->rx_skb
[2] = NULL
;
972 lp
->rx_skb
[3] = NULL
;
979 lp
->rx_error_count
= 0;
980 lp
->rx_error_dpc_count
= 0;
981 lp
->rx_session_id
[0] = 0x50;
982 lp
->rx_session_id
[0] = 0x48;
983 lp
->rx_session_id
[0] = 0x44;
984 lp
->rx_session_id
[0] = 0x42;
985 lp
->rx_frame_id
[0] = 0;
986 lp
->rx_frame_id
[1] = 0;
987 lp
->rx_frame_id
[2] = 0;
988 lp
->rx_frame_id
[3] = 0;
989 if (request_irq(dev
->irq
, &sb1000_interrupt
, 0, "sb1000", dev
)) {
993 if (sb1000_debug
> 2)
994 printk(KERN_DEBUG
"%s: Opening, IRQ %d\n", name
, dev
->irq
);
996 /* Activate board and check firmware version */
998 if ((status
= sb1000_activate(ioaddr
, name
)))
1001 if ((status
= sb1000_get_firmware_version(ioaddr
, name
, version
, 0)))
1003 if (version
[0] != FirmwareVersion
[0] || version
[1] != FirmwareVersion
[1])
1004 printk(KERN_WARNING
"%s: found firmware version %x.%02x "
1005 "(should be %x.%02x)\n", name
, version
[0], version
[1],
1006 FirmwareVersion
[0], FirmwareVersion
[1]);
1009 netif_start_queue(dev
);
1010 return 0; /* Always succeed */
1013 static int sb1000_dev_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
1016 unsigned char version
[2];
1018 int ioaddr
[2], status
, frequency
;
1019 unsigned int stats
[5];
1020 struct sb1000_private
*lp
= (struct sb1000_private
*)dev
->priv
;
1022 if (!(dev
&& dev
->flags
& IFF_UP
))
1025 ioaddr
[0] = dev
->base_addr
;
1026 /* rmem_end holds the second I/O address - fv */
1027 ioaddr
[1] = dev
->rmem_end
;
1031 case SIOCGCMSTATS
: /* get statistics */
1032 stats
[0] = lp
->rx_bytes
;
1033 stats
[1] = lp
->rx_frames
;
1034 stats
[2] = lp
->stats
.rx_packets
;
1035 stats
[3] = lp
->stats
.rx_errors
;
1036 stats
[4] = lp
->stats
.rx_dropped
;
1037 if(copy_to_user(ifr
->ifr_data
, stats
, sizeof(stats
)))
1042 case SIOCGCMFIRMWARE
: /* get firmware version */
1043 if ((status
= sb1000_get_firmware_version(ioaddr
, name
, version
, 1)))
1045 if(copy_to_user(ifr
->ifr_data
, version
, sizeof(version
)))
1049 case SIOCGCMFREQUENCY
: /* get frequency */
1050 if ((status
= sb1000_get_frequency(ioaddr
, name
, &frequency
)))
1052 if(put_user(frequency
, (int*) ifr
->ifr_data
))
1056 case SIOCSCMFREQUENCY
: /* set frequency */
1057 if (!capable(CAP_NET_ADMIN
))
1059 if(get_user(frequency
, (int*) ifr
->ifr_data
))
1061 if ((status
= sb1000_set_frequency(ioaddr
, name
, frequency
)))
1065 case SIOCGCMPIDS
: /* get PIDs */
1066 if ((status
= sb1000_get_PIDs(ioaddr
, name
, PID
)))
1068 if(copy_to_user(ifr
->ifr_data
, PID
, sizeof(PID
)))
1072 case SIOCSCMPIDS
: /* set PIDs */
1073 if (!capable(CAP_NET_ADMIN
))
1075 if(copy_from_user(PID
, ifr
->ifr_data
, sizeof(PID
)))
1077 if ((status
= sb1000_set_PIDs(ioaddr
, name
, PID
)))
1079 /* set session_id, frame_id and pkt_type too */
1080 lp
->rx_session_id
[0] = 0x50 | (PID
[0] & 0x0f);
1081 lp
->rx_session_id
[1] = 0x48;
1082 lp
->rx_session_id
[2] = 0x44;
1083 lp
->rx_session_id
[3] = 0x42;
1084 lp
->rx_frame_id
[0] = 0;
1085 lp
->rx_frame_id
[1] = 0;
1086 lp
->rx_frame_id
[2] = 0;
1087 lp
->rx_frame_id
[3] = 0;
1097 /* transmit function: do nothing since SB1000 can't send anything out */
1099 sb1000_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1101 printk(KERN_WARNING
"%s: trying to transmit!!!\n", dev
->name
);
1102 /* sb1000 can't xmit datagrams */
1107 /* SB1000 interrupt handler. */
1108 static void sb1000_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
1113 struct net_device
*dev
= (struct net_device
*) dev_id
;
1114 struct sb1000_private
*lp
= (struct sb1000_private
*)dev
->priv
;
1116 const unsigned char Command0
[6] = {0x80, 0x2c, 0x00, 0x00, 0x00, 0x00};
1117 const unsigned char Command1
[6] = {0x80, 0x2e, 0x00, 0x00, 0x00, 0x00};
1118 const int MaxRxErrorCount
= 6;
1121 printk(KERN_ERR
"sb1000_interrupt(): irq %d for unknown device.\n",
1126 ioaddr
[0] = dev
->base_addr
;
1127 /* rmem_end holds the second I/O address - fv */
1128 ioaddr
[1] = dev
->rmem_end
;
1131 /* is it a good interrupt? */
1132 st
= inb(ioaddr
[1] + 6);
1133 if (!(st
& 0x08 && st
& 0x20)) {
1137 if (sb1000_debug
> 3)
1138 printk(KERN_DEBUG
"%s: entering interrupt\n", dev
->name
);
1140 st
= inb(ioaddr
[0] + 7);
1142 lp
->rx_error_count
++;
1144 udelay(SB1000_DELAY
);
1145 #endif /* SB1000_DELAY */
1146 sb1000_issue_read_command(ioaddr
, name
);
1148 sb1000_error_dpc(dev
);
1149 sb1000_issue_read_command(ioaddr
, name
);
1151 if (lp
->rx_error_dpc_count
&& !(--lp
->rx_error_dpc_count
)) {
1152 sb1000_wait_for_ready_clear(ioaddr
, name
);
1153 sb1000_send_command(ioaddr
, name
, Command0
);
1154 sb1000_wait_for_ready(ioaddr
, name
);
1155 sb1000_issue_read_command(ioaddr
, name
);
1157 if (lp
->rx_error_count
>= MaxRxErrorCount
) {
1158 sb1000_wait_for_ready_clear(ioaddr
, name
);
1159 sb1000_send_command(ioaddr
, name
, Command1
);
1160 sb1000_wait_for_ready(ioaddr
, name
);
1161 sb1000_issue_read_command(ioaddr
, name
);
1162 lp
->rx_error_count
= 0;
1168 static struct net_device_stats
*sb1000_stats(struct net_device
*dev
)
1170 struct sb1000_private
*lp
= (struct sb1000_private
*)dev
->priv
;
1174 static int sb1000_close(struct net_device
*dev
)
1178 struct sb1000_private
*lp
= (struct sb1000_private
*)dev
->priv
;
1180 if (sb1000_debug
> 2)
1181 printk(KERN_DEBUG
"%s: Shutting down sb1000.\n", dev
->name
);
1183 netif_stop_queue(dev
);
1185 ioaddr
[0] = dev
->base_addr
;
1186 /* rmem_end holds the second I/O address - fv */
1187 ioaddr
[1] = dev
->rmem_end
;
1189 free_irq(dev
->irq
, dev
);
1190 /* If we don't do this, we can't re-insmod it later. */
1191 release_region(ioaddr
[1], SB1000_IO_EXTENT
);
1192 release_region(ioaddr
[0], SB1000_IO_EXTENT
);
1194 /* free rx_skb's if needed */
1195 for (i
=0; i
<4; i
++) {
1196 if (lp
->rx_skb
[i
]) {
1197 dev_kfree_skb(lp
->rx_skb
[i
]);
1204 MODULE_AUTHOR("Franco Venturi <fventuri@mediaone.net>");
1205 MODULE_DESCRIPTION("General Instruments SB1000 driver");
1206 MODULE_PARM(io
, "1-2i");
1207 MODULE_PARM(irq
, "i");
1209 static struct net_device dev_sb1000
;
1217 for (i
= 0; i
< 100; i
++) {
1218 sprintf(dev_sb1000
.name
, "cm%d", i
);
1219 if (dev_get(dev_sb1000
.name
) == 0) break;
1222 printk(KERN_ERR
"sb1000: can't register any device cm<n>\n");
1225 dev_sb1000
.init
= sb1000_probe
;
1226 dev_sb1000
.base_addr
= io
[0];
1227 /* rmem_end holds the second I/O address - fv */
1228 dev_sb1000
.rmem_end
= io
[1];
1229 dev_sb1000
.irq
= irq
;
1230 if (register_netdev(&dev_sb1000
) != 0) {
1231 printk(KERN_ERR
"sb1000: failed to register device (io: %03x,%03x "
1232 "irq: %d)\n", io
[0], io
[1], irq
);
1238 void cleanup_module(void)
1240 unregister_netdev(&dev_sb1000
);
1241 release_region(dev_sb1000
.base_addr
, 16);
1242 release_region(dev_sb1000
.rmem_end
, 16);
1243 kfree(dev_sb1000
.priv
);
1244 dev_sb1000
.priv
= NULL
;
1250 * compile-command: "gcc -D__KERNEL__ -DMODULE -Wall -Wstrict-prototypes -O -m486 -c sb1000.c"
1251 * version-control: t