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/sched.h>
40 #include <linux/string.h>
41 #include <linux/interrupt.h>
42 #include <linux/errno.h>
43 #include <linux/if_cablemodem.h> /* for SIOGCM/SIOSCM stuff */
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>
54 #include <linux/gfp.h>
57 #include <asm/processor.h>
58 #include <asm/uaccess.h>
61 static int sb1000_debug
= SB1000_DEBUG
;
63 static const int sb1000_debug
= 1;
66 static const int SB1000_IO_EXTENT
= 8;
67 /* SB1000 Maximum Receive Unit */
68 static const int SB1000_MRU
= 1500; /* octects */
71 struct sb1000_private
{
72 struct sk_buff
*rx_skb
[NPIDS
];
74 unsigned int rx_frames
;
76 short rx_error_dpc_count
;
77 unsigned char rx_session_id
[NPIDS
];
78 unsigned char rx_frame_id
[NPIDS
];
79 unsigned char rx_pkt_type
[NPIDS
];
82 /* prototypes for Linux interface */
83 extern int sb1000_probe(struct net_device
*dev
);
84 static int sb1000_open(struct net_device
*dev
);
85 static int sb1000_dev_ioctl (struct net_device
*dev
, struct ifreq
*ifr
, int cmd
);
86 static netdev_tx_t
sb1000_start_xmit(struct sk_buff
*skb
,
87 struct net_device
*dev
);
88 static irqreturn_t
sb1000_interrupt(int irq
, void *dev_id
);
89 static int sb1000_close(struct net_device
*dev
);
92 /* SB1000 hardware routines to be used during open/configuration phases */
93 static int card_wait_for_busy_clear(const int ioaddr
[],
95 static int card_wait_for_ready(const int ioaddr
[], const char* name
,
97 static int card_send_command(const int ioaddr
[], const char* name
,
98 const unsigned char out
[], unsigned char in
[]);
100 /* SB1000 hardware routines to be used during frame rx interrupt */
101 static int sb1000_wait_for_ready(const int ioaddr
[], const char* name
);
102 static int sb1000_wait_for_ready_clear(const int ioaddr
[],
104 static void sb1000_send_command(const int ioaddr
[], const char* name
,
105 const unsigned char out
[]);
106 static void sb1000_read_status(const int ioaddr
[], unsigned char in
[]);
107 static void sb1000_issue_read_command(const int ioaddr
[],
110 /* SB1000 commands for open/configuration */
111 static int sb1000_reset(const int ioaddr
[], const char* name
);
112 static int sb1000_check_CRC(const int ioaddr
[], const char* name
);
113 static inline int sb1000_start_get_set_command(const int ioaddr
[],
115 static int sb1000_end_get_set_command(const int ioaddr
[],
117 static int sb1000_activate(const int ioaddr
[], const char* name
);
118 static int sb1000_get_firmware_version(const int ioaddr
[],
119 const char* name
, unsigned char version
[], int do_end
);
120 static int sb1000_get_frequency(const int ioaddr
[], const char* name
,
122 static int sb1000_set_frequency(const int ioaddr
[], const char* name
,
124 static int sb1000_get_PIDs(const int ioaddr
[], const char* name
,
126 static int sb1000_set_PIDs(const int ioaddr
[], const char* name
,
129 /* SB1000 commands for frame rx interrupt */
130 static int sb1000_rx(struct net_device
*dev
);
131 static void sb1000_error_dpc(struct net_device
*dev
);
133 static const struct pnp_device_id sb1000_pnp_ids
[] = {
137 MODULE_DEVICE_TABLE(pnp
, sb1000_pnp_ids
);
139 static const struct net_device_ops sb1000_netdev_ops
= {
140 .ndo_open
= sb1000_open
,
141 .ndo_start_xmit
= sb1000_start_xmit
,
142 .ndo_do_ioctl
= sb1000_dev_ioctl
,
143 .ndo_stop
= sb1000_close
,
144 .ndo_change_mtu
= eth_change_mtu
,
145 .ndo_set_mac_address
= eth_mac_addr
,
146 .ndo_validate_addr
= eth_validate_addr
,
150 sb1000_probe_one(struct pnp_dev
*pdev
, const struct pnp_device_id
*id
)
152 struct net_device
*dev
;
153 unsigned short ioaddr
[2], irq
;
154 unsigned int serial_number
;
157 if (pnp_device_attach(pdev
) < 0)
159 if (pnp_activate_dev(pdev
) < 0)
162 if (!pnp_port_valid(pdev
, 0) || !pnp_port_valid(pdev
, 1))
164 if (!pnp_irq_valid(pdev
, 0))
167 serial_number
= pdev
->card
->serial
;
169 ioaddr
[0] = pnp_port_start(pdev
, 0);
170 ioaddr
[1] = pnp_port_start(pdev
, 0);
172 irq
= pnp_irq(pdev
, 0);
174 if (!request_region(ioaddr
[0], 16, "sb1000"))
176 if (!request_region(ioaddr
[1], 16, "sb1000"))
177 goto out_release_region0
;
179 dev
= alloc_etherdev(sizeof(struct sb1000_private
));
182 goto out_release_regions
;
186 dev
->base_addr
= ioaddr
[0];
187 /* mem_start holds the second I/O address */
188 dev
->mem_start
= ioaddr
[1];
191 if (sb1000_debug
> 0)
192 printk(KERN_NOTICE
"%s: sb1000 at (%#3.3lx,%#3.3lx), "
193 "S/N %#8.8x, IRQ %d.\n", dev
->name
, dev
->base_addr
,
194 dev
->mem_start
, serial_number
, dev
->irq
);
197 * The SB1000 is an rx-only cable modem device. The uplink is a modem
198 * and we do not want to arp on it.
200 dev
->flags
= IFF_POINTOPOINT
|IFF_NOARP
;
202 SET_NETDEV_DEV(dev
, &pdev
->dev
);
204 if (sb1000_debug
> 0)
205 printk(KERN_NOTICE
"%s", version
);
207 dev
->netdev_ops
= &sb1000_netdev_ops
;
209 /* hardware address is 0:0:serial_number */
210 dev
->dev_addr
[2] = serial_number
>> 24 & 0xff;
211 dev
->dev_addr
[3] = serial_number
>> 16 & 0xff;
212 dev
->dev_addr
[4] = serial_number
>> 8 & 0xff;
213 dev
->dev_addr
[5] = serial_number
>> 0 & 0xff;
215 pnp_set_drvdata(pdev
, dev
);
217 error
= register_netdev(dev
);
219 goto out_free_netdev
;
225 release_region(ioaddr
[1], 16);
227 release_region(ioaddr
[0], 16);
229 pnp_disable_dev(pdev
);
231 pnp_device_detach(pdev
);
236 sb1000_remove_one(struct pnp_dev
*pdev
)
238 struct net_device
*dev
= pnp_get_drvdata(pdev
);
240 unregister_netdev(dev
);
241 release_region(dev
->base_addr
, 16);
242 release_region(dev
->mem_start
, 16);
246 static struct pnp_driver sb1000_driver
= {
248 .id_table
= sb1000_pnp_ids
,
249 .probe
= sb1000_probe_one
,
250 .remove
= sb1000_remove_one
,
255 * SB1000 hardware routines to be used during open/configuration phases
258 static const int TimeOutJiffies
= (875 * HZ
) / 100;
260 /* Card Wait For Busy Clear (cannot be used during an interrupt) */
262 card_wait_for_busy_clear(const int ioaddr
[], const char* name
)
265 unsigned long timeout
;
267 a
= inb(ioaddr
[0] + 7);
268 timeout
= jiffies
+ TimeOutJiffies
;
269 while (a
& 0x80 || a
& 0x40) {
273 a
= inb(ioaddr
[0] + 7);
274 if (time_after_eq(jiffies
, timeout
)) {
275 printk(KERN_WARNING
"%s: card_wait_for_busy_clear timeout\n",
284 /* Card Wait For Ready (cannot be used during an interrupt) */
286 card_wait_for_ready(const int ioaddr
[], const char* name
, unsigned char in
[])
289 unsigned long timeout
;
291 a
= inb(ioaddr
[1] + 6);
292 timeout
= jiffies
+ TimeOutJiffies
;
293 while (a
& 0x80 || !(a
& 0x40)) {
297 a
= inb(ioaddr
[1] + 6);
298 if (time_after_eq(jiffies
, timeout
)) {
299 printk(KERN_WARNING
"%s: card_wait_for_ready timeout\n",
305 in
[1] = inb(ioaddr
[0] + 1);
306 in
[2] = inb(ioaddr
[0] + 2);
307 in
[3] = inb(ioaddr
[0] + 3);
308 in
[4] = inb(ioaddr
[0] + 4);
309 in
[0] = inb(ioaddr
[0] + 5);
310 in
[6] = inb(ioaddr
[0] + 6);
311 in
[5] = inb(ioaddr
[1] + 6);
315 /* Card Send Command (cannot be used during an interrupt) */
317 card_send_command(const int ioaddr
[], const char* name
,
318 const unsigned char out
[], unsigned char in
[])
322 if ((status
= card_wait_for_busy_clear(ioaddr
, name
)))
324 outb(0xa0, ioaddr
[0] + 6);
325 outb(out
[2], ioaddr
[0] + 1);
326 outb(out
[3], ioaddr
[0] + 2);
327 outb(out
[4], ioaddr
[0] + 3);
328 outb(out
[5], ioaddr
[0] + 4);
329 outb(out
[1], ioaddr
[0] + 5);
330 outb(0xa0, ioaddr
[0] + 6);
331 outb(out
[0], ioaddr
[0] + 7);
332 if (out
[0] != 0x20 && out
[0] != 0x30) {
333 if ((status
= card_wait_for_ready(ioaddr
, name
, in
)))
336 if (sb1000_debug
> 3)
337 printk(KERN_DEBUG
"%s: card_send_command "
338 "out: %02x%02x%02x%02x%02x%02x "
339 "in: %02x%02x%02x%02x%02x%02x%02x\n", name
,
340 out
[0], out
[1], out
[2], out
[3], out
[4], out
[5],
341 in
[0], in
[1], in
[2], in
[3], in
[4], in
[5], in
[6]);
343 if (sb1000_debug
> 3)
344 printk(KERN_DEBUG
"%s: card_send_command "
345 "out: %02x%02x%02x%02x%02x%02x\n", name
,
346 out
[0], out
[1], out
[2], out
[3], out
[4], out
[5]);
349 if (out
[1] == 0x1b) {
350 x
= (out
[2] == 0x02);
352 if (out
[0] >= 0x80 && in
[0] != (out
[1] | 0x80))
360 * SB1000 hardware routines to be used during frame rx interrupt
362 static const int Sb1000TimeOutJiffies
= 7 * HZ
;
364 /* Card Wait For Ready (to be used during frame rx) */
366 sb1000_wait_for_ready(const int ioaddr
[], const char* name
)
368 unsigned long timeout
;
370 timeout
= jiffies
+ Sb1000TimeOutJiffies
;
371 while (inb(ioaddr
[1] + 6) & 0x80) {
372 if (time_after_eq(jiffies
, timeout
)) {
373 printk(KERN_WARNING
"%s: sb1000_wait_for_ready timeout\n",
378 timeout
= jiffies
+ Sb1000TimeOutJiffies
;
379 while (!(inb(ioaddr
[1] + 6) & 0x40)) {
380 if (time_after_eq(jiffies
, timeout
)) {
381 printk(KERN_WARNING
"%s: sb1000_wait_for_ready timeout\n",
390 /* Card Wait For Ready Clear (to be used during frame rx) */
392 sb1000_wait_for_ready_clear(const int ioaddr
[], const char* name
)
394 unsigned long timeout
;
396 timeout
= jiffies
+ Sb1000TimeOutJiffies
;
397 while (inb(ioaddr
[1] + 6) & 0x80) {
398 if (time_after_eq(jiffies
, timeout
)) {
399 printk(KERN_WARNING
"%s: sb1000_wait_for_ready_clear timeout\n",
404 timeout
= jiffies
+ Sb1000TimeOutJiffies
;
405 while (inb(ioaddr
[1] + 6) & 0x40) {
406 if (time_after_eq(jiffies
, timeout
)) {
407 printk(KERN_WARNING
"%s: sb1000_wait_for_ready_clear timeout\n",
415 /* Card Send Command (to be used during frame rx) */
417 sb1000_send_command(const int ioaddr
[], const char* name
,
418 const unsigned char out
[])
420 outb(out
[2], ioaddr
[0] + 1);
421 outb(out
[3], ioaddr
[0] + 2);
422 outb(out
[4], ioaddr
[0] + 3);
423 outb(out
[5], ioaddr
[0] + 4);
424 outb(out
[1], ioaddr
[0] + 5);
425 outb(out
[0], ioaddr
[0] + 7);
426 if (sb1000_debug
> 3)
427 printk(KERN_DEBUG
"%s: sb1000_send_command out: %02x%02x%02x%02x"
428 "%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);
442 /* Issue Read Command (to be used during frame rx) */
444 sb1000_issue_read_command(const int ioaddr
[], const char* name
)
446 static const unsigned char Command0
[6] = {0x20, 0x00, 0x00, 0x01, 0x00, 0x00};
448 sb1000_wait_for_ready_clear(ioaddr
, name
);
449 outb(0xa0, ioaddr
[0] + 6);
450 sb1000_send_command(ioaddr
, name
, Command0
);
455 * SB1000 commands for open/configuration
457 /* reset SB1000 card */
459 sb1000_reset(const int ioaddr
[], const char* name
)
461 static const unsigned char Command0
[6] = {0x80, 0x16, 0x00, 0x00, 0x00, 0x00};
466 port
= ioaddr
[1] + 6;
480 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
487 /* check SB1000 firmware CRC */
489 sb1000_check_CRC(const int ioaddr
[], const char* name
)
491 static const unsigned char Command0
[6] = {0x80, 0x1f, 0x00, 0x00, 0x00, 0x00};
497 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
499 if (st
[1] != st
[3] || st
[2] != st
[4])
501 crc
= st
[1] << 8 | st
[2];
506 sb1000_start_get_set_command(const int ioaddr
[], const char* name
)
508 static const unsigned char Command0
[6] = {0x80, 0x1b, 0x00, 0x00, 0x00, 0x00};
512 return card_send_command(ioaddr
, name
, Command0
, st
);
516 sb1000_end_get_set_command(const int ioaddr
[], const char* name
)
518 static const unsigned char Command0
[6] = {0x80, 0x1b, 0x02, 0x00, 0x00, 0x00};
519 static const unsigned char Command1
[6] = {0x20, 0x00, 0x00, 0x00, 0x00, 0x00};
524 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
526 return card_send_command(ioaddr
, name
, Command1
, st
);
530 sb1000_activate(const int ioaddr
[], const char* name
)
532 static const unsigned char Command0
[6] = {0x80, 0x11, 0x00, 0x00, 0x00, 0x00};
533 static const unsigned char Command1
[6] = {0x80, 0x16, 0x00, 0x00, 0x00, 0x00};
539 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
541 if ((status
= card_send_command(ioaddr
, name
, Command1
, st
)))
544 if ((status
= sb1000_start_get_set_command(ioaddr
, name
)))
549 return sb1000_start_get_set_command(ioaddr
, name
);
552 /* get SB1000 firmware version */
554 sb1000_get_firmware_version(const int ioaddr
[], const char* name
,
555 unsigned char version
[], int do_end
)
557 static const unsigned char Command0
[6] = {0x80, 0x23, 0x00, 0x00, 0x00, 0x00};
562 if ((status
= sb1000_start_get_set_command(ioaddr
, name
)))
564 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
571 return sb1000_end_get_set_command(ioaddr
, name
);
576 /* get SB1000 frequency */
578 sb1000_get_frequency(const int ioaddr
[], const char* name
, int* frequency
)
580 static const unsigned char Command0
[6] = {0x80, 0x44, 0x00, 0x00, 0x00, 0x00};
586 if ((status
= sb1000_start_get_set_command(ioaddr
, name
)))
588 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
590 *frequency
= ((st
[1] << 8 | st
[2]) << 8 | st
[3]) << 8 | st
[4];
591 return sb1000_end_get_set_command(ioaddr
, name
);
594 /* set SB1000 frequency */
596 sb1000_set_frequency(const int ioaddr
[], const char* name
, int frequency
)
600 unsigned char Command0
[6] = {0x80, 0x29, 0x00, 0x00, 0x00, 0x00};
602 const int FrequencyLowerLimit
= 57000;
603 const int FrequencyUpperLimit
= 804000;
605 if (frequency
< FrequencyLowerLimit
|| frequency
> FrequencyUpperLimit
) {
606 printk(KERN_ERR
"%s: frequency chosen (%d kHz) is not in the range "
607 "[%d,%d] kHz\n", name
, frequency
, FrequencyLowerLimit
,
608 FrequencyUpperLimit
);
612 if ((status
= sb1000_start_get_set_command(ioaddr
, name
)))
614 Command0
[5] = frequency
& 0xff;
616 Command0
[4] = frequency
& 0xff;
618 Command0
[3] = frequency
& 0xff;
620 Command0
[2] = frequency
& 0xff;
621 return card_send_command(ioaddr
, name
, Command0
, st
);
624 /* get SB1000 PIDs */
626 sb1000_get_PIDs(const int ioaddr
[], const char* name
, short PID
[])
628 static const unsigned char Command0
[6] = {0x80, 0x40, 0x00, 0x00, 0x00, 0x00};
629 static const unsigned char Command1
[6] = {0x80, 0x41, 0x00, 0x00, 0x00, 0x00};
630 static const unsigned char Command2
[6] = {0x80, 0x42, 0x00, 0x00, 0x00, 0x00};
631 static const unsigned char Command3
[6] = {0x80, 0x43, 0x00, 0x00, 0x00, 0x00};
637 if ((status
= sb1000_start_get_set_command(ioaddr
, name
)))
640 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
642 PID
[0] = st
[1] << 8 | st
[2];
644 if ((status
= card_send_command(ioaddr
, name
, Command1
, st
)))
646 PID
[1] = st
[1] << 8 | st
[2];
648 if ((status
= card_send_command(ioaddr
, name
, Command2
, st
)))
650 PID
[2] = st
[1] << 8 | st
[2];
652 if ((status
= card_send_command(ioaddr
, name
, Command3
, st
)))
654 PID
[3] = st
[1] << 8 | st
[2];
656 return sb1000_end_get_set_command(ioaddr
, name
);
659 /* set SB1000 PIDs */
661 sb1000_set_PIDs(const int ioaddr
[], const char* name
, const short PID
[])
663 static const unsigned char Command4
[6] = {0x80, 0x2e, 0x00, 0x00, 0x00, 0x00};
668 unsigned char Command0
[6] = {0x80, 0x31, 0x00, 0x00, 0x00, 0x00};
669 unsigned char Command1
[6] = {0x80, 0x32, 0x00, 0x00, 0x00, 0x00};
670 unsigned char Command2
[6] = {0x80, 0x33, 0x00, 0x00, 0x00, 0x00};
671 unsigned char Command3
[6] = {0x80, 0x34, 0x00, 0x00, 0x00, 0x00};
674 if ((status
= sb1000_start_get_set_command(ioaddr
, name
)))
678 Command0
[3] = p
& 0xff;
680 Command0
[2] = p
& 0xff;
681 if ((status
= card_send_command(ioaddr
, name
, Command0
, st
)))
685 Command1
[3] = p
& 0xff;
687 Command1
[2] = p
& 0xff;
688 if ((status
= card_send_command(ioaddr
, name
, Command1
, st
)))
692 Command2
[3] = p
& 0xff;
694 Command2
[2] = p
& 0xff;
695 if ((status
= card_send_command(ioaddr
, name
, Command2
, st
)))
699 Command3
[3] = p
& 0xff;
701 Command3
[2] = p
& 0xff;
702 if ((status
= card_send_command(ioaddr
, name
, Command3
, st
)))
705 if ((status
= card_send_command(ioaddr
, name
, Command4
, st
)))
707 return sb1000_end_get_set_command(ioaddr
, name
);
712 sb1000_print_status_buffer(const char* name
, unsigned char st
[],
713 unsigned char buffer
[], int size
)
717 printk(KERN_DEBUG
"%s: status: %02x %02x\n", name
, st
[0], st
[1]);
718 if (buffer
[24] == 0x08 && buffer
[25] == 0x00 && buffer
[26] == 0x45) {
719 printk(KERN_DEBUG
"%s: length: %d protocol: %d from: %d.%d.%d.%d:%d "
720 "to %d.%d.%d.%d:%d\n", name
, buffer
[28] << 8 | buffer
[29],
721 buffer
[35], buffer
[38], buffer
[39], buffer
[40], buffer
[41],
722 buffer
[46] << 8 | buffer
[47],
723 buffer
[42], buffer
[43], buffer
[44], buffer
[45],
724 buffer
[48] << 8 | buffer
[49]);
726 for (i
= 0, k
= 0; i
< (size
+ 7) / 8; i
++) {
727 printk(KERN_DEBUG
"%s: %s", name
, i
? " " : "buffer:");
728 for (j
= 0; j
< 8 && k
< size
; j
++, k
++)
729 printk(" %02x", buffer
[k
]);
736 * SB1000 commands for frame rx interrupt
738 /* receive a single frame and assemble datagram
739 * (this is the heart of the interrupt routine)
742 sb1000_rx(struct net_device
*dev
)
745 #define FRAMESIZE 184
746 unsigned char st
[2], buffer
[FRAMESIZE
], session_id
, frame_id
;
749 unsigned int skbsize
;
751 struct sb1000_private
*lp
= netdev_priv(dev
);
752 struct net_device_stats
*stats
= &dev
->stats
;
754 /* SB1000 frame constants */
755 const int FrameSize
= FRAMESIZE
;
756 const int NewDatagramHeaderSkip
= 8;
757 const int NewDatagramHeaderSize
= NewDatagramHeaderSkip
+ 18;
758 const int NewDatagramDataSize
= FrameSize
- NewDatagramHeaderSize
;
759 const int ContDatagramHeaderSkip
= 7;
760 const int ContDatagramHeaderSize
= ContDatagramHeaderSkip
+ 1;
761 const int ContDatagramDataSize
= FrameSize
- ContDatagramHeaderSize
;
762 const int TrailerSize
= 4;
764 ioaddr
= dev
->base_addr
;
766 insw(ioaddr
, (unsigned short*) st
, 1);
768 printk("cm0: received: %02x %02x\n", st
[0], st
[1]);
769 #endif /* XXXDEBUG */
772 /* decide if it is a good or bad frame */
773 for (ns
= 0; ns
< NPIDS
; ns
++) {
774 session_id
= lp
->rx_session_id
[ns
];
775 frame_id
= lp
->rx_frame_id
[ns
];
776 if (st
[0] == session_id
) {
777 if (st
[1] == frame_id
|| (!frame_id
&& (st
[1] & 0xf0) == 0x30)) {
779 } else if ((st
[1] & 0xf0) == 0x30 && (st
[0] & 0x40)) {
784 } else if (st
[0] == (session_id
| 0x40)) {
785 if ((st
[1] & 0xf0) == 0x30) {
795 stats
->rx_frame_errors
++;
796 skb
= lp
->rx_skb
[ns
];
797 if (sb1000_debug
> 1)
798 printk(KERN_WARNING
"%s: missing frame(s): got %02x %02x "
799 "expecting %02x %02x\n", dev
->name
, st
[0], st
[1],
800 skb
? session_id
: session_id
| 0x40, frame_id
);
807 lp
->rx_frame_id
[ns
] = 0x30 | ((st
[1] + 1) & 0x0f);
810 /* get data length */
811 insw(ioaddr
, buffer
, NewDatagramHeaderSize
/ 2);
813 printk("cm0: IP identification: %02x%02x fragment offset: %02x%02x\n", buffer
[30], buffer
[31], buffer
[32], buffer
[33]);
814 #endif /* XXXDEBUG */
815 if (buffer
[0] != NewDatagramHeaderSkip
) {
816 if (sb1000_debug
> 1)
817 printk(KERN_WARNING
"%s: new datagram header skip error: "
818 "got %02x expecting %02x\n", dev
->name
, buffer
[0],
819 NewDatagramHeaderSkip
);
820 stats
->rx_length_errors
++;
821 insw(ioaddr
, buffer
, NewDatagramDataSize
/ 2);
824 dlen
= ((buffer
[NewDatagramHeaderSkip
+ 3] & 0x0f) << 8 |
825 buffer
[NewDatagramHeaderSkip
+ 4]) - 17;
826 if (dlen
> SB1000_MRU
) {
827 if (sb1000_debug
> 1)
828 printk(KERN_WARNING
"%s: datagram length (%d) greater "
829 "than MRU (%d)\n", dev
->name
, dlen
, SB1000_MRU
);
830 stats
->rx_length_errors
++;
831 insw(ioaddr
, buffer
, NewDatagramDataSize
/ 2);
834 lp
->rx_dlen
[ns
] = dlen
;
835 /* compute size to allocate for datagram */
836 skbsize
= dlen
+ FrameSize
;
837 if ((skb
= alloc_skb(skbsize
, GFP_ATOMIC
)) == NULL
) {
838 if (sb1000_debug
> 1)
839 printk(KERN_WARNING
"%s: can't allocate %d bytes long "
840 "skbuff\n", dev
->name
, skbsize
);
842 insw(ioaddr
, buffer
, NewDatagramDataSize
/ 2);
846 skb_reset_mac_header(skb
);
847 skb
->protocol
= (unsigned short) buffer
[NewDatagramHeaderSkip
+ 16];
848 insw(ioaddr
, skb_put(skb
, NewDatagramDataSize
),
849 NewDatagramDataSize
/ 2);
850 lp
->rx_skb
[ns
] = skb
;
852 /* continuation of previous datagram */
853 insw(ioaddr
, buffer
, ContDatagramHeaderSize
/ 2);
854 if (buffer
[0] != ContDatagramHeaderSkip
) {
855 if (sb1000_debug
> 1)
856 printk(KERN_WARNING
"%s: cont datagram header skip error: "
857 "got %02x expecting %02x\n", dev
->name
, buffer
[0],
858 ContDatagramHeaderSkip
);
859 stats
->rx_length_errors
++;
860 insw(ioaddr
, buffer
, ContDatagramDataSize
/ 2);
863 skb
= lp
->rx_skb
[ns
];
864 insw(ioaddr
, skb_put(skb
, ContDatagramDataSize
),
865 ContDatagramDataSize
/ 2);
866 dlen
= lp
->rx_dlen
[ns
];
868 if (skb
->len
< dlen
+ TrailerSize
) {
869 lp
->rx_session_id
[ns
] &= ~0x40;
873 /* datagram completed: send to upper level */
876 stats
->rx_bytes
+=dlen
;
878 lp
->rx_skb
[ns
] = NULL
;
879 lp
->rx_session_id
[ns
] |= 0x40;
883 insw(ioaddr
, buffer
, FrameSize
/ 2);
884 if (sb1000_debug
> 1)
885 printk(KERN_WARNING
"%s: frame error: got %02x %02x\n",
886 dev
->name
, st
[0], st
[1]);
887 stats
->rx_frame_errors
++;
889 if (sb1000_debug
> 2)
890 sb1000_print_status_buffer(dev
->name
, st
, buffer
, FrameSize
);
894 if ((skb
= lp
->rx_skb
[ns
])) {
896 lp
->rx_skb
[ns
] = NULL
;
898 lp
->rx_session_id
[ns
] |= 0x40;
904 sb1000_error_dpc(struct net_device
*dev
)
906 static const unsigned char Command0
[6] = {0x80, 0x26, 0x00, 0x00, 0x00, 0x00};
911 struct sb1000_private
*lp
= netdev_priv(dev
);
912 const int ErrorDpcCounterInitialize
= 200;
914 ioaddr
[0] = dev
->base_addr
;
915 /* mem_start holds the second I/O address */
916 ioaddr
[1] = dev
->mem_start
;
919 sb1000_wait_for_ready_clear(ioaddr
, name
);
920 sb1000_send_command(ioaddr
, name
, Command0
);
921 sb1000_wait_for_ready(ioaddr
, name
);
922 sb1000_read_status(ioaddr
, st
);
924 lp
->rx_error_dpc_count
= ErrorDpcCounterInitialize
;
929 * Linux interface functions
932 sb1000_open(struct net_device
*dev
)
935 int ioaddr
[2], status
;
936 struct sb1000_private
*lp
= netdev_priv(dev
);
937 const unsigned short FirmwareVersion
[] = {0x01, 0x01};
939 ioaddr
[0] = dev
->base_addr
;
940 /* mem_start holds the second I/O address */
941 ioaddr
[1] = dev
->mem_start
;
944 /* initialize sb1000 */
945 if ((status
= sb1000_reset(ioaddr
, name
)))
948 if ((status
= sb1000_check_CRC(ioaddr
, name
)))
951 /* initialize private data before board can catch interrupts */
952 lp
->rx_skb
[0] = NULL
;
953 lp
->rx_skb
[1] = NULL
;
954 lp
->rx_skb
[2] = NULL
;
955 lp
->rx_skb
[3] = NULL
;
961 lp
->rx_error_count
= 0;
962 lp
->rx_error_dpc_count
= 0;
963 lp
->rx_session_id
[0] = 0x50;
964 lp
->rx_session_id
[0] = 0x48;
965 lp
->rx_session_id
[0] = 0x44;
966 lp
->rx_session_id
[0] = 0x42;
967 lp
->rx_frame_id
[0] = 0;
968 lp
->rx_frame_id
[1] = 0;
969 lp
->rx_frame_id
[2] = 0;
970 lp
->rx_frame_id
[3] = 0;
971 if (request_irq(dev
->irq
, sb1000_interrupt
, 0, "sb1000", dev
)) {
975 if (sb1000_debug
> 2)
976 printk(KERN_DEBUG
"%s: Opening, IRQ %d\n", name
, dev
->irq
);
978 /* Activate board and check firmware version */
980 if ((status
= sb1000_activate(ioaddr
, name
)))
983 if ((status
= sb1000_get_firmware_version(ioaddr
, name
, version
, 0)))
985 if (version
[0] != FirmwareVersion
[0] || version
[1] != FirmwareVersion
[1])
986 printk(KERN_WARNING
"%s: found firmware version %x.%02x "
987 "(should be %x.%02x)\n", name
, version
[0], version
[1],
988 FirmwareVersion
[0], FirmwareVersion
[1]);
991 netif_start_queue(dev
);
992 return 0; /* Always succeed */
995 static int sb1000_dev_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
998 unsigned char version
[2];
1000 int ioaddr
[2], status
, frequency
;
1001 unsigned int stats
[5];
1002 struct sb1000_private
*lp
= netdev_priv(dev
);
1004 if (!(dev
&& dev
->flags
& IFF_UP
))
1007 ioaddr
[0] = dev
->base_addr
;
1008 /* mem_start holds the second I/O address */
1009 ioaddr
[1] = dev
->mem_start
;
1013 case SIOCGCMSTATS
: /* get statistics */
1014 stats
[0] = dev
->stats
.rx_bytes
;
1015 stats
[1] = lp
->rx_frames
;
1016 stats
[2] = dev
->stats
.rx_packets
;
1017 stats
[3] = dev
->stats
.rx_errors
;
1018 stats
[4] = dev
->stats
.rx_dropped
;
1019 if(copy_to_user(ifr
->ifr_data
, stats
, sizeof(stats
)))
1024 case SIOCGCMFIRMWARE
: /* get firmware version */
1025 if ((status
= sb1000_get_firmware_version(ioaddr
, name
, version
, 1)))
1027 if(copy_to_user(ifr
->ifr_data
, version
, sizeof(version
)))
1031 case SIOCGCMFREQUENCY
: /* get frequency */
1032 if ((status
= sb1000_get_frequency(ioaddr
, name
, &frequency
)))
1034 if(put_user(frequency
, (int __user
*) ifr
->ifr_data
))
1038 case SIOCSCMFREQUENCY
: /* set frequency */
1039 if (!capable(CAP_NET_ADMIN
))
1041 if(get_user(frequency
, (int __user
*) ifr
->ifr_data
))
1043 if ((status
= sb1000_set_frequency(ioaddr
, name
, frequency
)))
1047 case SIOCGCMPIDS
: /* get PIDs */
1048 if ((status
= sb1000_get_PIDs(ioaddr
, name
, PID
)))
1050 if(copy_to_user(ifr
->ifr_data
, PID
, sizeof(PID
)))
1054 case SIOCSCMPIDS
: /* set PIDs */
1055 if (!capable(CAP_NET_ADMIN
))
1057 if(copy_from_user(PID
, ifr
->ifr_data
, sizeof(PID
)))
1059 if ((status
= sb1000_set_PIDs(ioaddr
, name
, PID
)))
1061 /* set session_id, frame_id and pkt_type too */
1062 lp
->rx_session_id
[0] = 0x50 | (PID
[0] & 0x0f);
1063 lp
->rx_session_id
[1] = 0x48;
1064 lp
->rx_session_id
[2] = 0x44;
1065 lp
->rx_session_id
[3] = 0x42;
1066 lp
->rx_frame_id
[0] = 0;
1067 lp
->rx_frame_id
[1] = 0;
1068 lp
->rx_frame_id
[2] = 0;
1069 lp
->rx_frame_id
[3] = 0;
1079 /* transmit function: do nothing since SB1000 can't send anything out */
1081 sb1000_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1083 printk(KERN_WARNING
"%s: trying to transmit!!!\n", dev
->name
);
1084 /* sb1000 can't xmit datagrams */
1086 return NETDEV_TX_OK
;
1089 /* SB1000 interrupt handler. */
1090 static irqreturn_t
sb1000_interrupt(int irq
, void *dev_id
)
1092 static const unsigned char Command0
[6] = {0x80, 0x2c, 0x00, 0x00, 0x00, 0x00};
1093 static const unsigned char Command1
[6] = {0x80, 0x2e, 0x00, 0x00, 0x00, 0x00};
1098 struct net_device
*dev
= dev_id
;
1099 struct sb1000_private
*lp
= netdev_priv(dev
);
1101 const int MaxRxErrorCount
= 6;
1103 ioaddr
[0] = dev
->base_addr
;
1104 /* mem_start holds the second I/O address */
1105 ioaddr
[1] = dev
->mem_start
;
1108 /* is it a good interrupt? */
1109 st
= inb(ioaddr
[1] + 6);
1110 if (!(st
& 0x08 && st
& 0x20)) {
1114 if (sb1000_debug
> 3)
1115 printk(KERN_DEBUG
"%s: entering interrupt\n", dev
->name
);
1117 st
= inb(ioaddr
[0] + 7);
1119 lp
->rx_error_count
++;
1121 udelay(SB1000_DELAY
);
1122 #endif /* SB1000_DELAY */
1123 sb1000_issue_read_command(ioaddr
, name
);
1125 sb1000_error_dpc(dev
);
1126 sb1000_issue_read_command(ioaddr
, name
);
1128 if (lp
->rx_error_dpc_count
&& !(--lp
->rx_error_dpc_count
)) {
1129 sb1000_wait_for_ready_clear(ioaddr
, name
);
1130 sb1000_send_command(ioaddr
, name
, Command0
);
1131 sb1000_wait_for_ready(ioaddr
, name
);
1132 sb1000_issue_read_command(ioaddr
, name
);
1134 if (lp
->rx_error_count
>= MaxRxErrorCount
) {
1135 sb1000_wait_for_ready_clear(ioaddr
, name
);
1136 sb1000_send_command(ioaddr
, name
, Command1
);
1137 sb1000_wait_for_ready(ioaddr
, name
);
1138 sb1000_issue_read_command(ioaddr
, name
);
1139 lp
->rx_error_count
= 0;
1145 static int sb1000_close(struct net_device
*dev
)
1149 struct sb1000_private
*lp
= netdev_priv(dev
);
1151 if (sb1000_debug
> 2)
1152 printk(KERN_DEBUG
"%s: Shutting down sb1000.\n", dev
->name
);
1154 netif_stop_queue(dev
);
1156 ioaddr
[0] = dev
->base_addr
;
1157 /* mem_start holds the second I/O address */
1158 ioaddr
[1] = dev
->mem_start
;
1160 free_irq(dev
->irq
, dev
);
1161 /* If we don't do this, we can't re-insmod it later. */
1162 release_region(ioaddr
[1], SB1000_IO_EXTENT
);
1163 release_region(ioaddr
[0], SB1000_IO_EXTENT
);
1165 /* free rx_skb's if needed */
1166 for (i
=0; i
<4; i
++) {
1167 if (lp
->rx_skb
[i
]) {
1168 dev_kfree_skb(lp
->rx_skb
[i
]);
1174 MODULE_AUTHOR("Franco Venturi <fventuri@mediaone.net>");
1175 MODULE_DESCRIPTION("General Instruments SB1000 driver");
1176 MODULE_LICENSE("GPL");
1181 return pnp_register_driver(&sb1000_driver
);
1187 pnp_unregister_driver(&sb1000_driver
);
1190 module_init(sb1000_init
);
1191 module_exit(sb1000_exit
);