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>
60 /* for SIOGCM/SIOSCM stuff */
61 #include <linux/if_cablemodem.h>
64 int sb1000_debug
= SB1000_DEBUG
;
69 static const int SB1000_IO_EXTENT
= 8;
70 /* SB1000 Maximum Receive Unit */
71 static const int SB1000_MRU
= 1500; /* octects */
74 struct sb1000_private
{
75 struct sk_buff
*rx_skb
[NPIDS
];
77 unsigned int rx_bytes
;
78 unsigned int rx_frames
;
80 short rx_error_dpc_count
;
81 unsigned char rx_session_id
[NPIDS
];
82 unsigned char rx_frame_id
[NPIDS
];
83 unsigned char rx_pkt_type
[NPIDS
];
84 struct net_device_stats stats
;
87 /* prototypes for Linux interface */
88 extern int sb1000_probe(struct net_device
*dev
);
89 static int sb1000_open(struct net_device
*dev
);
90 static int sb1000_dev_ioctl (struct net_device
*dev
, struct ifreq
*ifr
, int cmd
);
91 static int sb1000_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
92 static void sb1000_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
);
93 static struct enet_statistics
*sb1000_stats(struct net_device
*dev
);
94 static int sb1000_close(struct net_device
*dev
);
96 /* Plug-n-Play routine */
97 static inline unsigned char read_resource_data(void);
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
);
142 /* Plug-n-Play constants */
143 static const int READ_DATA_PORT
= 0x203; /* This port number may change!!! */
144 static const int ADDRESS_PORT
= 0x279;
145 static const int WRITE_DATA_PORT
= 0xa79;
147 /* Plug-n-Play read resource mechanism */
148 static inline unsigned char
149 read_resource_data(void) {
151 outb(0x05, ADDRESS_PORT
); /* Select PnP status register. */
152 while (!(inb(READ_DATA_PORT
) & 0x1)) ;
153 /* read resource data */
154 outb(0x04, ADDRESS_PORT
); /* Select PnP resource data register. */
155 return inb(READ_DATA_PORT
);
158 /* probe for SB1000 using Plug-n-Play mechanism */
160 sb1000_probe(struct net_device
*dev
)
163 unsigned short ioaddr
[2], irq
;
165 unsigned int serial_number
;
167 const unsigned char initiation_key
[] = { 0x00, 0x00, 0x6a, 0xb5, 0xda,
168 0xed, 0xf6, 0xfb, 0x7d, 0xbe, 0xdf, 0x6f, 0x37, 0x1b, 0x0d,
169 0x86, 0xc3, 0x61, 0xb0, 0x58, 0x2c, 0x16, 0x8b, 0x45, 0xa2,
170 0xd1, 0xe8, 0x74, 0x3a, 0x9d, 0xce, 0xe7, 0x73, 0x39 };
171 const unsigned char sb1000_vendor_ID
[] = {
172 0x1d, 0x23, 0x10, 0x00 }; /* "GIC1000" */
174 /* Reset the ISA PnP mechanism */
175 outb(0x02, ADDRESS_PORT
); /* Select PnP config control register. */
176 outb(0x02, WRITE_DATA_PORT
); /* Return to WaitForKey state. */
178 /* send initiation key */
179 for (i
= 0; i
< sizeof(initiation_key
) / sizeof(initiation_key
[0]); i
++) {
180 outb(initiation_key
[i
], ADDRESS_PORT
);
183 /* set card CSN into configuration mode */
184 for (csn
= 1; csn
<= 255; csn
++) {
185 outb(0x03, ADDRESS_PORT
); /* Select PnP wake[CSN] register. */
186 outb(csn
, WRITE_DATA_PORT
); /* Wake[CSN] */
188 for (i
= 0; i
< 4; i
++) {
189 if (read_resource_data() != sb1000_vendor_ID
[i
]) break;
194 /* SB1000 not found */
196 /* return to WaitForKey state */
197 outb(0x02, ADDRESS_PORT
); /* Select PnP config control register. */
198 outb(0x02, WRITE_DATA_PORT
);/* Return to WaitForKey state. */
202 /* found: get serial number and skip checksum */
204 for (i
= 0; i
< 4; i
++) {
205 serial_number
|= read_resource_data() << (8 * i
);
207 read_resource_data();
209 /* get I/O port base address */
210 outb(0x60, ADDRESS_PORT
); /* Select PnP I/O port base address 0. */
211 ioaddr
[0] = inb(READ_DATA_PORT
) << 8;
212 outb(0x61, ADDRESS_PORT
);
213 ioaddr
[0] |= inb(READ_DATA_PORT
);
214 outb(0x62, ADDRESS_PORT
); /* Select PnP I/O port base address 1. */
215 ioaddr
[1] = inb(READ_DATA_PORT
) << 8;
216 outb(0x63, ADDRESS_PORT
);
217 ioaddr
[1] |= inb(READ_DATA_PORT
);
220 outb(0x70, ADDRESS_PORT
); /* Select PnP IRQ level select 0. */
221 irq
= inb(READ_DATA_PORT
);
223 /* return to WaitForKey state */
224 outb(0x02, ADDRESS_PORT
); /* Select PnP config control register. */
225 outb(0x02, WRITE_DATA_PORT
); /* Return to WaitForKey state. */
227 /* check I/O base and IRQ */
228 if (dev
->base_addr
!= 0 && dev
->base_addr
!= ioaddr
[0]) {
231 if (dev
->rmem_end
!= 0 && dev
->rmem_end
!= ioaddr
[1]) {
234 if (dev
->irq
!= 0 && dev
->irq
!= irq
) {
238 dev
->base_addr
= ioaddr
[0];
239 /* rmem_end holds the second I/O address - fv */
240 dev
->rmem_end
= ioaddr
[1];
243 if (sb1000_debug
> 0)
244 printk(KERN_NOTICE
"%s: sb1000 at (%#3.3lx,%#3.3lx), csn %d, "
245 "S/N %#8.8x, IRQ %d.\n", dev
->name
, dev
->base_addr
,
246 dev
->rmem_end
, csn
, serial_number
, dev
->irq
);
248 dev
= init_etherdev(dev
, 0);
250 /* Make up a SB1000-specific-data structure. */
251 dev
->priv
= kmalloc(sizeof(struct sb1000_private
), GFP_KERNEL
);
252 if (dev
->priv
== NULL
)
254 memset(dev
->priv
, 0, sizeof(struct sb1000_private
));
256 if (sb1000_debug
> 0)
257 printk(KERN_NOTICE
"%s", version
);
259 /* The SB1000-specific entries in the device structure. */
260 dev
->open
= sb1000_open
;
261 dev
->do_ioctl
= sb1000_dev_ioctl
;
262 dev
->hard_start_xmit
= sb1000_start_xmit
;
263 dev
->stop
= sb1000_close
;
264 dev
->get_stats
= sb1000_stats
;
266 /* Fill in the generic fields of the device structure. */
267 dev
->change_mtu
= NULL
;
268 dev
->hard_header
= NULL
;
269 dev
->rebuild_header
= NULL
;
270 dev
->set_mac_address
= NULL
;
271 dev
->header_cache_update
= NULL
;
273 dev
->type
= ARPHRD_ETHER
;
274 dev
->hard_header_len
= 0;
276 dev
->addr_len
= ETH_ALEN
;
277 /* hardware address is 0:0:serial_number */
278 dev
->dev_addr
[0] = 0;
279 dev
->dev_addr
[1] = 0;
280 dev
->dev_addr
[2] = serial_number
>> 24 & 0xff;
281 dev
->dev_addr
[3] = serial_number
>> 16 & 0xff;
282 dev
->dev_addr
[4] = serial_number
>> 8 & 0xff;
283 dev
->dev_addr
[5] = serial_number
>> 0 & 0xff;
284 dev
->tx_queue_len
= 0;
286 /* New-style flags. */
287 dev
->flags
= IFF_POINTOPOINT
|IFF_NOARP
;
293 * SB1000 hardware routines to be used during open/configuration phases
295 const int TimeOutJiffies
= (int)(8.75 * HZ
);
297 static inline void nicedelay(unsigned long usecs
)
299 current
->state
= TASK_INTERRUPTIBLE
;
300 schedule_timeout(HZ
);
304 /* Card Wait For Busy Clear (cannot be used during an interrupt) */
306 card_wait_for_busy_clear(const int ioaddr
[], const char* name
)
309 unsigned long timeout
;
311 a
= inb(ioaddr
[0] + 7);
312 timeout
= jiffies
+ TimeOutJiffies
;
313 while (a
& 0x80 || a
& 0x40) {
315 current
->state
= TASK_INTERRUPTIBLE
;
317 a
= inb(ioaddr
[0] + 7);
318 if (jiffies
>= timeout
) {
319 printk(KERN_WARNING
"%s: card_wait_for_busy_clear timeout\n",
328 /* Card Wait For Ready (cannot be used during an interrupt) */
330 card_wait_for_ready(const int ioaddr
[], const char* name
, unsigned char in
[])
333 unsigned long timeout
;
335 a
= inb(ioaddr
[1] + 6);
336 timeout
= jiffies
+ TimeOutJiffies
;
337 while (a
& 0x80 || !(a
& 0x40)) {
339 current
->state
= TASK_INTERRUPTIBLE
;
341 a
= inb(ioaddr
[1] + 6);
342 if (jiffies
>= timeout
) {
343 printk(KERN_WARNING
"%s: card_wait_for_ready timeout\n",
349 in
[1] = inb(ioaddr
[0] + 1);
350 in
[2] = inb(ioaddr
[0] + 2);
351 in
[3] = inb(ioaddr
[0] + 3);
352 in
[4] = inb(ioaddr
[0] + 4);
353 in
[0] = inb(ioaddr
[0] + 5);
354 in
[6] = inb(ioaddr
[0] + 6);
355 in
[5] = inb(ioaddr
[1] + 6);
359 /* Card Send Command (cannot be used during an interrupt) */
361 card_send_command(const int ioaddr
[], const char* name
,
362 const unsigned char out
[], unsigned char in
[])
366 if ((status
= card_wait_for_busy_clear(ioaddr
, name
)))
368 outb(0xa0, ioaddr
[0] + 6);
369 outb(out
[2], ioaddr
[0] + 1);
370 outb(out
[3], ioaddr
[0] + 2);
371 outb(out
[4], ioaddr
[0] + 3);
372 outb(out
[5], ioaddr
[0] + 4);
373 outb(out
[1], ioaddr
[0] + 5);
374 outb(0xa0, ioaddr
[0] + 6);
375 outb(out
[0], ioaddr
[0] + 7);
376 if (out
[0] != 0x20 && out
[0] != 0x30) {
377 if ((status
= card_wait_for_ready(ioaddr
, name
, in
)))
380 if (sb1000_debug
> 3)
381 printk(KERN_DEBUG
"%s: card_send_command "
382 "out: %02x%02x%02x%02x%02x%02x "
383 "in: %02x%02x%02x%02x%02x%02x%02x\n", name
,
384 out
[0], out
[1], out
[2], out
[3], out
[4], out
[5],
385 in
[0], in
[1], in
[2], in
[3], in
[4], in
[5], in
[6]);
387 if (sb1000_debug
> 3)
388 printk(KERN_DEBUG
"%s: card_send_command "
389 "out: %02x%02x%02x%02x%02x%02x\n", name
,
390 out
[0], out
[1], out
[2], out
[3], out
[4], out
[5]);
393 if (out
[1] == 0x1b) {
394 x
= (out
[2] == 0x02);
396 if (out
[0] >= 0x80 && in
[0] != (out
[1] | 0x80))
404 * SB1000 hardware routines to be used during frame rx interrupt
406 const int Sb1000TimeOutJiffies
= 7 * HZ
;
408 /* Card Wait For Ready (to be used during frame rx) */
410 sb1000_wait_for_ready(const int ioaddr
[], const char* name
)
412 unsigned long timeout
;
414 timeout
= jiffies
+ Sb1000TimeOutJiffies
;
415 while (inb(ioaddr
[1] + 6) & 0x80) {
416 if (jiffies
>= timeout
) {
417 printk(KERN_WARNING
"%s: sb1000_wait_for_ready timeout\n",
422 timeout
= jiffies
+ Sb1000TimeOutJiffies
;
423 while (!(inb(ioaddr
[1] + 6) & 0x40)) {
424 if (jiffies
>= timeout
) {
425 printk(KERN_WARNING
"%s: sb1000_wait_for_ready timeout\n",
434 /* Card Wait For Ready Clear (to be used during frame rx) */
436 sb1000_wait_for_ready_clear(const int ioaddr
[], const char* name
)
438 unsigned long timeout
;
440 timeout
= jiffies
+ Sb1000TimeOutJiffies
;
441 while (inb(ioaddr
[1] + 6) & 0x80) {
442 if (jiffies
>= timeout
) {
443 printk(KERN_WARNING
"%s: sb1000_wait_for_ready_clear timeout\n",
448 timeout
= jiffies
+ Sb1000TimeOutJiffies
;
449 while (inb(ioaddr
[1] + 6) & 0x40) {
450 if (jiffies
>= timeout
) {
451 printk(KERN_WARNING
"%s: sb1000_wait_for_ready_clear timeout\n",
459 /* Card Send Command (to be used during frame rx) */
461 sb1000_send_command(const int ioaddr
[], const char* name
,
462 const unsigned char out
[])
464 outb(out
[2], ioaddr
[0] + 1);
465 outb(out
[3], ioaddr
[0] + 2);
466 outb(out
[4], ioaddr
[0] + 3);
467 outb(out
[5], ioaddr
[0] + 4);
468 outb(out
[1], ioaddr
[0] + 5);
469 outb(out
[0], ioaddr
[0] + 7);
470 if (sb1000_debug
> 3)
471 printk(KERN_DEBUG
"%s: sb1000_send_command out: %02x%02x%02x%02x"
472 "%02x%02x\n", name
, out
[0], out
[1], out
[2], out
[3], out
[4], out
[5]);
476 /* Card Read Status (to be used during frame rx) */
478 sb1000_read_status(const int ioaddr
[], unsigned char in
[])
480 in
[1] = inb(ioaddr
[0] + 1);
481 in
[2] = inb(ioaddr
[0] + 2);
482 in
[3] = inb(ioaddr
[0] + 3);
483 in
[4] = inb(ioaddr
[0] + 4);
484 in
[0] = inb(ioaddr
[0] + 5);
488 /* Issue Read Command (to be used during frame rx) */
490 sb1000_issue_read_command(const int ioaddr
[], const char* name
)
492 const unsigned char Command0
[6] = {0x20, 0x00, 0x00, 0x01, 0x00, 0x00};
494 sb1000_wait_for_ready_clear(ioaddr
, name
);
495 outb(0xa0, ioaddr
[0] + 6);
496 sb1000_send_command(ioaddr
, name
, Command0
);
502 * SB1000 commands for open/configuration
504 /* reset SB1000 card */
506 sb1000_reset(const int ioaddr
[], const char* name
)
510 const unsigned char Command0
[6] = {0x80, 0x16, 0x00, 0x00, 0x00, 0x00};
512 port
= ioaddr
[1] + 6;
526 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
533 /* check SB1000 firmware CRC */
535 sb1000_check_CRC(const int ioaddr
[], const char* name
)
539 const unsigned char Command0
[6] = {0x80, 0x1f, 0x00, 0x00, 0x00, 0x00};
542 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
544 if (st
[1] != st
[3] || st
[2] != st
[4])
546 crc
= st
[1] << 8 | st
[2];
551 sb1000_start_get_set_command(const int ioaddr
[], const char* name
)
554 const unsigned char Command0
[6] = {0x80, 0x1b, 0x00, 0x00, 0x00, 0x00};
556 return card_send_command(ioaddr
, name
, Command0
, st
);
560 sb1000_end_get_set_command(const int ioaddr
[], const char* name
)
564 const unsigned char Command0
[6] = {0x80, 0x1b, 0x02, 0x00, 0x00, 0x00};
565 const unsigned char Command1
[6] = {0x20, 0x00, 0x00, 0x00, 0x00, 0x00};
567 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
569 return card_send_command(ioaddr
, name
, Command1
, st
);
573 sb1000_activate(const int ioaddr
[], const char* name
)
577 const unsigned char Command0
[6] = {0x80, 0x11, 0x00, 0x00, 0x00, 0x00};
578 const unsigned char Command1
[6] = {0x80, 0x16, 0x00, 0x00, 0x00, 0x00};
581 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
583 if ((status
= card_send_command(ioaddr
, name
, Command1
, st
)))
586 if ((status
= sb1000_start_get_set_command(ioaddr
, name
)))
591 return sb1000_start_get_set_command(ioaddr
, name
);
594 /* get SB1000 firmware version */
596 sb1000_get_firmware_version(const int ioaddr
[], const char* name
,
597 unsigned char version
[], int do_end
)
601 const unsigned char Command0
[6] = {0x80, 0x23, 0x00, 0x00, 0x00, 0x00};
603 if ((status
= sb1000_start_get_set_command(ioaddr
, name
)))
605 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
612 return sb1000_end_get_set_command(ioaddr
, name
);
617 /* get SB1000 frequency */
619 sb1000_get_frequency(const int ioaddr
[], const char* name
, int* frequency
)
623 const unsigned char Command0
[6] = {0x80, 0x44, 0x00, 0x00, 0x00, 0x00};
626 if ((status
= sb1000_start_get_set_command(ioaddr
, name
)))
628 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
630 *frequency
= ((st
[1] << 8 | st
[2]) << 8 | st
[3]) << 8 | st
[4];
631 return sb1000_end_get_set_command(ioaddr
, name
);
634 /* set SB1000 frequency */
636 sb1000_set_frequency(const int ioaddr
[], const char* name
, int frequency
)
640 unsigned char Command0
[6] = {0x80, 0x29, 0x00, 0x00, 0x00, 0x00};
642 const int FrequencyLowerLimit
= 57000;
643 const int FrequencyUpperLimit
= 804000;
645 if (frequency
< FrequencyLowerLimit
|| frequency
> FrequencyUpperLimit
) {
646 printk(KERN_ERR
"%s: frequency chosen (%d kHz) is not in the range "
647 "[%d,%d] kHz\n", name
, frequency
, FrequencyLowerLimit
,
648 FrequencyUpperLimit
);
652 if ((status
= sb1000_start_get_set_command(ioaddr
, name
)))
654 Command0
[5] = frequency
& 0xff;
656 Command0
[4] = frequency
& 0xff;
658 Command0
[3] = frequency
& 0xff;
660 Command0
[2] = frequency
& 0xff;
661 return card_send_command(ioaddr
, name
, Command0
, st
);
664 /* get SB1000 PIDs */
666 sb1000_get_PIDs(const int ioaddr
[], const char* name
, short PID
[])
670 const unsigned char Command0
[6] = {0x80, 0x40, 0x00, 0x00, 0x00, 0x00};
671 const unsigned char Command1
[6] = {0x80, 0x41, 0x00, 0x00, 0x00, 0x00};
672 const unsigned char Command2
[6] = {0x80, 0x42, 0x00, 0x00, 0x00, 0x00};
673 const unsigned char Command3
[6] = {0x80, 0x43, 0x00, 0x00, 0x00, 0x00};
676 if ((status
= sb1000_start_get_set_command(ioaddr
, name
)))
679 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
681 PID
[0] = st
[1] << 8 | st
[2];
683 if ((status
= card_send_command(ioaddr
, name
, Command1
, st
)))
685 PID
[1] = st
[1] << 8 | st
[2];
687 if ((status
= card_send_command(ioaddr
, name
, Command2
, st
)))
689 PID
[2] = st
[1] << 8 | st
[2];
691 if ((status
= card_send_command(ioaddr
, name
, Command3
, st
)))
693 PID
[3] = st
[1] << 8 | st
[2];
695 return sb1000_end_get_set_command(ioaddr
, name
);
698 /* set SB1000 PIDs */
700 sb1000_set_PIDs(const int ioaddr
[], const char* name
, const short PID
[])
705 unsigned char Command0
[6] = {0x80, 0x31, 0x00, 0x00, 0x00, 0x00};
706 unsigned char Command1
[6] = {0x80, 0x32, 0x00, 0x00, 0x00, 0x00};
707 unsigned char Command2
[6] = {0x80, 0x33, 0x00, 0x00, 0x00, 0x00};
708 unsigned char Command3
[6] = {0x80, 0x34, 0x00, 0x00, 0x00, 0x00};
709 const unsigned char Command4
[6] = {0x80, 0x2e, 0x00, 0x00, 0x00, 0x00};
712 if ((status
= sb1000_start_get_set_command(ioaddr
, name
)))
716 Command0
[3] = p
& 0xff;
718 Command0
[2] = p
& 0xff;
719 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
723 Command1
[3] = p
& 0xff;
725 Command1
[2] = p
& 0xff;
726 if ((status
= card_send_command(ioaddr
, name
, Command1
, st
)))
730 Command2
[3] = p
& 0xff;
732 Command2
[2] = p
& 0xff;
733 if ((status
= card_send_command(ioaddr
, name
, Command2
, st
)))
737 Command3
[3] = p
& 0xff;
739 Command3
[2] = p
& 0xff;
740 if ((status
= card_send_command(ioaddr
, name
, Command3
, st
)))
743 if ((status
= card_send_command(ioaddr
, name
, Command4
, st
)))
745 return sb1000_end_get_set_command(ioaddr
, name
);
750 sb1000_print_status_buffer(const char* name
, unsigned char st
[],
751 unsigned char buffer
[], int size
)
755 printk(KERN_DEBUG
"%s: status: %02x %02x\n", name
, st
[0], st
[1]);
756 if (buffer
[24] == 0x08 && buffer
[25] == 0x00 && buffer
[26] == 0x45) {
757 printk(KERN_DEBUG
"%s: length: %d protocol: %d from: %d.%d.%d.%d:%d "
758 "to %d.%d.%d.%d:%d\n", name
, buffer
[28] << 8 | buffer
[29],
759 buffer
[35], buffer
[38], buffer
[39], buffer
[40], buffer
[41],
760 buffer
[46] << 8 | buffer
[47],
761 buffer
[42], buffer
[43], buffer
[44], buffer
[45],
762 buffer
[48] << 8 | buffer
[49]);
764 for (i
= 0, k
= 0; i
< (size
+ 7) / 8; i
++) {
765 printk(KERN_DEBUG
"%s: %s", name
, i
? " " : "buffer:");
766 for (j
= 0; j
< 8 && k
< size
; j
++, k
++)
767 printk(" %02x", buffer
[k
]);
775 * SB1000 commands for frame rx interrupt
777 /* receive a single frame and assemble datagram
778 * (this is the heart of the interrupt routine)
781 sb1000_rx(struct net_device
*dev
)
784 #define FRAMESIZE 184
785 unsigned char st
[2], buffer
[FRAMESIZE
], session_id
, frame_id
;
788 unsigned int skbsize
;
790 struct sb1000_private
*lp
= (struct sb1000_private
*)dev
->priv
;
791 struct enet_statistics
*stats
= &lp
->stats
;
793 /* SB1000 frame constants */
794 const int FrameSize
= FRAMESIZE
;
795 const int NewDatagramHeaderSkip
= 8;
796 const int NewDatagramHeaderSize
= NewDatagramHeaderSkip
+ 18;
797 const int NewDatagramDataSize
= FrameSize
- NewDatagramHeaderSize
;
798 const int ContDatagramHeaderSkip
= 7;
799 const int ContDatagramHeaderSize
= ContDatagramHeaderSkip
+ 1;
800 const int ContDatagramDataSize
= FrameSize
- ContDatagramHeaderSize
;
801 const int TrailerSize
= 4;
803 ioaddr
= dev
->base_addr
;
805 insw(ioaddr
, (unsigned short*) st
, 1);
807 printk("cm0: received: %02x %02x\n", st
[0], st
[1]);
808 #endif /* XXXDEBUG */
811 /* decide if it is a good or bad frame */
812 for (ns
= 0; ns
< NPIDS
; ns
++) {
813 session_id
= lp
->rx_session_id
[ns
];
814 frame_id
= lp
->rx_frame_id
[ns
];
815 if (st
[0] == session_id
) {
816 if (st
[1] == frame_id
|| (!frame_id
&& (st
[1] & 0xf0) == 0x30)) {
818 } else if ((st
[1] & 0xf0) == 0x30 && (st
[0] & 0x40)) {
823 } else if (st
[0] == (session_id
| 0x40)) {
824 if ((st
[1] & 0xf0) == 0x30) {
834 stats
->rx_frame_errors
++;
835 skb
= lp
->rx_skb
[ns
];
836 if (sb1000_debug
> 1)
837 printk(KERN_WARNING
"%s: missing frame(s): got %02x %02x "
838 "expecting %02x %02x\n", dev
->name
, st
[0], st
[1],
839 skb
? session_id
: session_id
| 0x40, frame_id
);
846 lp
->rx_frame_id
[ns
] = 0x30 | ((st
[1] + 1) & 0x0f);
849 /* get data length */
850 insw(ioaddr
, buffer
, NewDatagramHeaderSize
/ 2);
852 printk("cm0: IP identification: %02x%02x fragment offset: %02x%02x\n", buffer
[30], buffer
[31], buffer
[32], buffer
[33]);
853 #endif /* XXXDEBUG */
854 if (buffer
[0] != NewDatagramHeaderSkip
) {
855 if (sb1000_debug
> 1)
856 printk(KERN_WARNING
"%s: new datagram header skip error: "
857 "got %02x expecting %02x\n", dev
->name
, buffer
[0],
858 NewDatagramHeaderSkip
);
859 stats
->rx_length_errors
++;
860 insw(ioaddr
, buffer
, NewDatagramDataSize
/ 2);
863 dlen
= ((buffer
[NewDatagramHeaderSkip
+ 3] & 0x0f) << 8 |
864 buffer
[NewDatagramHeaderSkip
+ 4]) - 17;
865 if (dlen
> SB1000_MRU
) {
866 if (sb1000_debug
> 1)
867 printk(KERN_WARNING
"%s: datagram length (%d) greater "
868 "than MRU (%d)\n", dev
->name
, dlen
, SB1000_MRU
);
869 stats
->rx_length_errors
++;
870 insw(ioaddr
, buffer
, NewDatagramDataSize
/ 2);
873 lp
->rx_dlen
[ns
] = dlen
;
874 /* compute size to allocate for datagram */
875 skbsize
= dlen
+ FrameSize
;
876 if ((skb
= alloc_skb(skbsize
, GFP_ATOMIC
)) == NULL
) {
877 if (sb1000_debug
> 1)
878 printk(KERN_WARNING
"%s: can't allocate %d bytes long "
879 "skbuff\n", dev
->name
, skbsize
);
881 insw(ioaddr
, buffer
, NewDatagramDataSize
/ 2);
885 skb
->mac
.raw
= skb
->data
;
886 skb
->protocol
= (unsigned short) buffer
[NewDatagramHeaderSkip
+ 16];
887 insw(ioaddr
, skb_put(skb
, NewDatagramDataSize
),
888 NewDatagramDataSize
/ 2);
889 lp
->rx_skb
[ns
] = skb
;
891 /* continuation of previous datagram */
892 insw(ioaddr
, buffer
, ContDatagramHeaderSize
/ 2);
893 if (buffer
[0] != ContDatagramHeaderSkip
) {
894 if (sb1000_debug
> 1)
895 printk(KERN_WARNING
"%s: cont datagram header skip error: "
896 "got %02x expecting %02x\n", dev
->name
, buffer
[0],
897 ContDatagramHeaderSkip
);
898 stats
->rx_length_errors
++;
899 insw(ioaddr
, buffer
, ContDatagramDataSize
/ 2);
902 skb
= lp
->rx_skb
[ns
];
903 insw(ioaddr
, skb_put(skb
, ContDatagramDataSize
),
904 ContDatagramDataSize
/ 2);
905 dlen
= lp
->rx_dlen
[ns
];
907 if (skb
->len
< dlen
+ TrailerSize
) {
908 lp
->rx_session_id
[ns
] &= ~0x40;
912 /* datagram completed: send to upper level */
915 stats
->rx_bytes
+=dlen
;
917 lp
->rx_bytes
+= dlen
;
919 lp
->rx_session_id
[ns
] |= 0x40;
923 insw(ioaddr
, buffer
, FrameSize
/ 2);
924 if (sb1000_debug
> 1)
925 printk(KERN_WARNING
"%s: frame error: got %02x %02x\n",
926 dev
->name
, st
[0], st
[1]);
927 stats
->rx_frame_errors
++;
929 if (sb1000_debug
> 2)
930 sb1000_print_status_buffer(dev
->name
, st
, buffer
, FrameSize
);
934 if ((skb
= lp
->rx_skb
[ns
])) {
938 lp
->rx_session_id
[ns
] |= 0x40;
944 sb1000_error_dpc(struct net_device
*dev
)
949 struct sb1000_private
*lp
= (struct sb1000_private
*)dev
->priv
;
950 const unsigned char Command0
[6] = {0x80, 0x26, 0x00, 0x00, 0x00, 0x00};
951 const int ErrorDpcCounterInitialize
= 200;
953 ioaddr
[0] = dev
->base_addr
;
954 /* rmem_end holds the second I/O address - fv */
955 ioaddr
[1] = dev
->rmem_end
;
958 sb1000_wait_for_ready_clear(ioaddr
, name
);
959 sb1000_send_command(ioaddr
, name
, Command0
);
960 sb1000_wait_for_ready(ioaddr
, name
);
961 sb1000_read_status(ioaddr
, st
);
963 lp
->rx_error_dpc_count
= ErrorDpcCounterInitialize
;
969 * Linux interface functions
972 sb1000_open(struct net_device
*dev
)
975 int ioaddr
[2], status
;
976 struct sb1000_private
*lp
= (struct sb1000_private
*)dev
->priv
;
977 const unsigned short FirmwareVersion
[] = {0x01, 0x01};
979 ioaddr
[0] = dev
->base_addr
;
980 /* rmem_end holds the second I/O address - fv */
981 ioaddr
[1] = dev
->rmem_end
;
983 request_region(ioaddr
[0], SB1000_IO_EXTENT
, "sb1000");
984 request_region(ioaddr
[1], SB1000_IO_EXTENT
, "sb1000");
986 /* initialize sb1000 */
987 if ((status
= sb1000_reset(ioaddr
, name
)))
990 if ((status
= sb1000_check_CRC(ioaddr
, name
)))
993 /* initialize private data before board can catch interrupts */
994 lp
->rx_skb
[0] = NULL
;
995 lp
->rx_skb
[1] = NULL
;
996 lp
->rx_skb
[2] = NULL
;
997 lp
->rx_skb
[3] = NULL
;
1004 lp
->rx_error_count
= 0;
1005 lp
->rx_error_dpc_count
= 0;
1006 lp
->rx_session_id
[0] = 0x50;
1007 lp
->rx_session_id
[0] = 0x48;
1008 lp
->rx_session_id
[0] = 0x44;
1009 lp
->rx_session_id
[0] = 0x42;
1010 lp
->rx_frame_id
[0] = 0;
1011 lp
->rx_frame_id
[1] = 0;
1012 lp
->rx_frame_id
[2] = 0;
1013 lp
->rx_frame_id
[3] = 0;
1014 if (request_irq(dev
->irq
, &sb1000_interrupt
, 0, "sb1000", dev
)) {
1018 if (sb1000_debug
> 2)
1019 printk(KERN_DEBUG
"%s: Opening, IRQ %d\n", name
, dev
->irq
);
1021 /* Activate board and check firmware version */
1023 if ((status
= sb1000_activate(ioaddr
, name
)))
1026 if ((status
= sb1000_get_firmware_version(ioaddr
, name
, version
, 0)))
1028 if (version
[0] != FirmwareVersion
[0] || version
[1] != FirmwareVersion
[1])
1029 printk(KERN_WARNING
"%s: found firmware version %x.%02x "
1030 "(should be %x.%02x)\n", name
, version
[0], version
[1],
1031 FirmwareVersion
[0], FirmwareVersion
[1]);
1038 return 0; /* Always succeed */
1041 static int sb1000_dev_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
1044 unsigned char version
[2];
1046 int ioaddr
[2], status
, frequency
;
1047 unsigned int stats
[5];
1048 struct sb1000_private
*lp
= (struct sb1000_private
*)dev
->priv
;
1050 if (!(dev
&& dev
->flags
& IFF_UP
))
1053 ioaddr
[0] = dev
->base_addr
;
1054 /* rmem_end holds the second I/O address - fv */
1055 ioaddr
[1] = dev
->rmem_end
;
1059 case SIOCGCMSTATS
: /* get statistics */
1060 stats
[0] = lp
->rx_bytes
;
1061 stats
[1] = lp
->rx_frames
;
1062 stats
[2] = lp
->stats
.rx_packets
;
1063 stats
[3] = lp
->stats
.rx_errors
;
1064 stats
[4] = lp
->stats
.rx_dropped
;
1065 if(copy_to_user(ifr
->ifr_data
, stats
, sizeof(stats
)))
1070 case SIOCGCMFIRMWARE
: /* get firmware version */
1071 if ((status
= sb1000_get_firmware_version(ioaddr
, name
, version
, 1)))
1073 if(copy_to_user(ifr
->ifr_data
, version
, sizeof(version
)))
1077 case SIOCGCMFREQUENCY
: /* get frequency */
1078 if ((status
= sb1000_get_frequency(ioaddr
, name
, &frequency
)))
1080 if(put_user(frequency
, (int*) ifr
->ifr_data
))
1084 case SIOCSCMFREQUENCY
: /* set frequency */
1087 if(get_user(frequency
, (int*) ifr
->ifr_data
))
1089 if ((status
= sb1000_set_frequency(ioaddr
, name
, frequency
)))
1093 case SIOCGCMPIDS
: /* get PIDs */
1094 if ((status
= sb1000_get_PIDs(ioaddr
, name
, PID
)))
1096 if(copy_to_user(ifr
->ifr_data
, PID
, sizeof(PID
)))
1100 case SIOCSCMPIDS
: /* set PIDs */
1103 if(copy_from_user(PID
, ifr
->ifr_data
, sizeof(PID
)))
1105 if ((status
= sb1000_set_PIDs(ioaddr
, name
, PID
)))
1107 /* set session_id, frame_id and pkt_type too */
1108 lp
->rx_session_id
[0] = 0x50 | (PID
[0] & 0x0f);
1109 lp
->rx_session_id
[1] = 0x48;
1110 lp
->rx_session_id
[2] = 0x44;
1111 lp
->rx_session_id
[3] = 0x42;
1112 lp
->rx_frame_id
[0] = 0;
1113 lp
->rx_frame_id
[1] = 0;
1114 lp
->rx_frame_id
[2] = 0;
1115 lp
->rx_frame_id
[3] = 0;
1125 /* transmit function: do nothing since SB1000 can't send anything out */
1127 sb1000_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1129 printk(KERN_WARNING
"%s: trying to transmit!!!\n", dev
->name
);
1130 /* sb1000 can't xmit datagrams */
1135 /* SB1000 interrupt handler. */
1136 static void sb1000_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
1141 struct net_device
*dev
= (struct net_device
*) dev_id
;
1142 struct sb1000_private
*lp
= (struct sb1000_private
*)dev
->priv
;
1144 const unsigned char Command0
[6] = {0x80, 0x2c, 0x00, 0x00, 0x00, 0x00};
1145 const unsigned char Command1
[6] = {0x80, 0x2e, 0x00, 0x00, 0x00, 0x00};
1146 const int MaxRxErrorCount
= 6;
1149 printk(KERN_ERR
"sb1000_interrupt(): irq %d for unknown device.\n",
1154 printk(KERN_ERR
"%s: Re-entering the interrupt handler.\n",
1158 ioaddr
[0] = dev
->base_addr
;
1159 /* rmem_end holds the second I/O address - fv */
1160 ioaddr
[1] = dev
->rmem_end
;
1163 /* is it a good interrupt? */
1164 st
= inb(ioaddr
[1] + 6);
1165 if (!(st
& 0x08 && st
& 0x20)) {
1170 if (sb1000_debug
> 3)
1171 printk(KERN_DEBUG
"%s: entering interrupt\n", dev
->name
);
1173 st
= inb(ioaddr
[0] + 7);
1175 lp
->rx_error_count
++;
1177 udelay(SB1000_DELAY
);
1178 #endif /* SB1000_DELAY */
1179 sb1000_issue_read_command(ioaddr
, name
);
1181 sb1000_error_dpc(dev
);
1182 sb1000_issue_read_command(ioaddr
, name
);
1184 if (lp
->rx_error_dpc_count
&& !(--lp
->rx_error_dpc_count
)) {
1185 sb1000_wait_for_ready_clear(ioaddr
, name
);
1186 sb1000_send_command(ioaddr
, name
, Command0
);
1187 sb1000_wait_for_ready(ioaddr
, name
);
1188 sb1000_issue_read_command(ioaddr
, name
);
1190 if (lp
->rx_error_count
>= MaxRxErrorCount
) {
1191 sb1000_wait_for_ready_clear(ioaddr
, name
);
1192 sb1000_send_command(ioaddr
, name
, Command1
);
1193 sb1000_wait_for_ready(ioaddr
, name
);
1194 sb1000_issue_read_command(ioaddr
, name
);
1195 lp
->rx_error_count
= 0;
1202 static struct net_device_stats
*sb1000_stats(struct net_device
*dev
)
1204 struct sb1000_private
*lp
= (struct sb1000_private
*)dev
->priv
;
1208 static int sb1000_close(struct net_device
*dev
)
1212 struct sb1000_private
*lp
= (struct sb1000_private
*)dev
->priv
;
1214 if (sb1000_debug
> 2)
1215 printk(KERN_DEBUG
"%s: Shutting down sb1000.\n", dev
->name
);
1220 ioaddr
[0] = dev
->base_addr
;
1221 /* rmem_end holds the second I/O address - fv */
1222 ioaddr
[1] = dev
->rmem_end
;
1224 free_irq(dev
->irq
, dev
);
1225 /* If we don't do this, we can't re-insmod it later. */
1226 release_region(ioaddr
[1], SB1000_IO_EXTENT
);
1227 release_region(ioaddr
[0], SB1000_IO_EXTENT
);
1229 /* free rx_skb's if needed */
1230 for (i
=0; i
<4; i
++) {
1231 if (lp
->rx_skb
[i
]) {
1232 dev_kfree_skb(lp
->rx_skb
[i
]);
1240 MODULE_AUTHOR("Franco Venturi <fventuri@mediaone.net>");
1241 MODULE_DESCRIPTION("General Instruments SB1000 driver");
1242 MODULE_PARM(io
, "1-2i");
1243 MODULE_PARM(irq
, "i");
1245 static char devname
[8] = {0, };
1246 static struct net_device dev_sb1000
= {
1250 0, 0, 0, NULL
, sb1000_probe
};
1252 static int io
[2] = {0, 0};
1259 for (i
= 0; i
< 100; i
++) {
1260 sprintf(devname
, "cm%d", i
);
1261 if (dev_get(devname
) == 0) break;
1264 printk(KERN_ERR
"sb1000: can't register any device cm<n>\n");
1267 dev_sb1000
.base_addr
= io
[0];
1268 /* rmem_end holds the second I/O address - fv */
1269 dev_sb1000
.rmem_end
= io
[1];
1270 dev_sb1000
.irq
= irq
;
1271 if (register_netdev(&dev_sb1000
) != 0) {
1272 printk(KERN_ERR
"sb1000: failed to register device (io: %03x,%03x "
1273 "irq: %d)\n", io
[0], io
[1], irq
);
1279 void cleanup_module(void)
1281 unregister_netdev(&dev_sb1000
);
1282 kfree_s(dev_sb1000
.priv
, sizeof(struct sb1000_private
));
1283 dev_sb1000
.priv
= NULL
;
1289 * compile-command: "gcc -D__KERNEL__ -DMODULE -Wall -Wstrict-prototypes -O -m486 -c sb1000.c"
1290 * version-control: t