37 #include <linux/module.h>
38 #include <linux/kernel.h>
39 #include <linux/sched.h>
40 #include <linux/string.h>
42 #include <linux/errno.h>
46 #include <linux/netdevice.h>
47 #include <linux/if_arp.h>
53 #include <linux/bitops.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;
68 static const int SB1000_MRU = 1500;
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[]);
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[],
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,
140 .ndo_open = sb1000_open,
141 .ndo_start_xmit = sb1000_start_xmit,
142 .ndo_do_ioctl = sb1000_dev_ioctl,
143 .ndo_stop = sb1000_close,
153 unsigned short ioaddr[2],
irq;
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);
177 goto out_release_region0;
182 goto out_release_regions;
191 if (sb1000_debug > 0)
204 if (sb1000_debug > 0)
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);
219 goto out_free_netdev;
236 sb1000_remove_one(
struct pnp_dev *pdev)
238 struct net_device *dev = pnp_get_drvdata(pdev);
248 .id_table = sb1000_pnp_ids,
249 .probe = sb1000_probe_one,
250 .remove = sb1000_remove_one,
258 static const int TimeOutJiffies = (875 *
HZ) / 100;
262 card_wait_for_busy_clear(
const int ioaddr[],
const char*
name)
267 a =
inb(ioaddr[0] + 7);
268 timeout =
jiffies + TimeOutJiffies;
269 while (a & 0x80 || a & 0x40) {
273 a =
inb(ioaddr[0] + 7);
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);
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);
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)
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)
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))
362 static const int Sb1000TimeOutJiffies = 7 *
HZ;
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) {
378 timeout =
jiffies + Sb1000TimeOutJiffies;
379 while (!(
inb(ioaddr[1] + 6) & 0x40)) {
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) {
404 timeout =
jiffies + Sb1000TimeOutJiffies;
405 while (
inb(ioaddr[1] + 6) & 0x40) {
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)
428 "%02x%02x\n", name, out[0], out[1], out[2], out[3], out[4], out[5]);
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);
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);
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)))
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);
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);
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);
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);
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);
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[],
718 if (buffer[24] == 0x08 && buffer[25] == 0x00 && buffer[26] == 0x45) {
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++) {
728 for (j = 0; j < 8 && k <
size; j++, k++)
729 printk(
" %02x", buffer[k]);
745 #define FRAMESIZE 184
746 unsigned char st[2], buffer[
FRAMESIZE], session_id, frame_id;
749 unsigned int skbsize;
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;
766 insw(ioaddr, (
unsigned short*) st, 1);
768 printk(
"cm0: received: %02x %02x\n", st[0], st[1]);
773 for (ns = 0; ns <
NPIDS; 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) {
797 if (sb1000_debug > 1)
799 "expecting %02x %02x\n", dev->
name, st[0], st[1],
800 skb ? session_id : session_id | 0x40, frame_id);
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]);
815 if (buffer[0] != NewDatagramHeaderSkip) {
816 if (sb1000_debug > 1)
818 "got %02x expecting %02x\n", dev->
name, buffer[0],
819 NewDatagramHeaderSkip);
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)
829 "than MRU (%d)\n", dev->
name, dlen, SB1000_MRU);
831 insw(ioaddr, buffer, NewDatagramDataSize / 2);
836 skbsize = dlen + FrameSize;
838 if (sb1000_debug > 1)
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];
849 NewDatagramDataSize / 2);
853 insw(ioaddr, buffer, ContDatagramHeaderSize / 2);
854 if (buffer[0] != ContDatagramHeaderSkip) {
855 if (sb1000_debug > 1)
857 "got %02x expecting %02x\n", dev->
name, buffer[0],
858 ContDatagramHeaderSkip);
860 insw(ioaddr, buffer, ContDatagramDataSize / 2);
865 ContDatagramDataSize / 2);
868 if (skb->
len < dlen + TrailerSize) {
883 insw(ioaddr, buffer, FrameSize / 2);
884 if (sb1000_debug > 1)
886 dev->
name, st[0], st[1]);
889 if (sb1000_debug > 2)
890 sb1000_print_status_buffer(dev->
name, st, buffer, FrameSize);
894 if ((skb = lp->
rx_skb[ns])) {
906 static const unsigned char Command0[6] = {0x80, 0x26, 0x00, 0x00, 0x00, 0x00};
912 const int ErrorDpcCounterInitialize = 200;
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);
937 const unsigned short FirmwareVersion[] = {0x01, 0x01};
945 if ((status = sb1000_reset(ioaddr, name)))
948 if ((status = sb1000_check_CRC(ioaddr, name)))
975 if (sb1000_debug > 2)
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])
987 "(should be %x.%02x)\n", name, version[0], version[1],
988 FirmwareVersion[0], FirmwareVersion[1]);
991 netif_start_queue(dev);
998 unsigned char version[2];
1001 unsigned int stats[5];
1014 stats[0] = dev->
stats.rx_bytes;
1016 stats[2] = dev->
stats.rx_packets;
1017 stats[3] = dev->
stats.rx_errors;
1018 stats[4] = dev->
stats.rx_dropped;
1025 if ((status = sb1000_get_firmware_version(ioaddr, name, version, 1)))
1027 if(
copy_to_user(ifr->ifr_data, version,
sizeof(version)))
1032 if ((status = sb1000_get_frequency(ioaddr, name, &frequency)))
1034 if(
put_user(frequency, (
int __user *) ifr->ifr_data))
1041 if(
get_user(frequency, (
int __user *) ifr->ifr_data))
1043 if ((status = sb1000_set_frequency(ioaddr, name, frequency)))
1048 if ((status = sb1000_get_PIDs(ioaddr, name, PID)))
1059 if ((status = sb1000_set_PIDs(ioaddr, name, PID)))
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};
1101 const int MaxRxErrorCount = 6;
1109 st =
inb(ioaddr[1] + 6);
1110 if (!(st & 0x08 && st & 0x20)) {
1114 if (sb1000_debug > 3)
1117 st =
inb(ioaddr[0] + 7);
1123 sb1000_issue_read_command(ioaddr, name);
1125 sb1000_error_dpc(dev);
1126 sb1000_issue_read_command(ioaddr, name);
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);
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);
1145 static int sb1000_close(
struct net_device *dev)
1151 if (sb1000_debug > 2)
1154 netif_stop_queue(dev);
1166 for (i=0; i<4; i++) {
1168 dev_kfree_skb(lp->
rx_skb[i]);