40 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
42 #include <linux/module.h>
43 #include <linux/kernel.h>
44 #include <linux/ptrace.h>
45 #include <linux/fcntl.h>
48 #include <linux/string.h>
49 #include <linux/errno.h>
50 #include <linux/netdevice.h>
52 #include <linux/pci.h>
62 #include <asm/types.h>
63 #include <asm/byteorder.h>
65 #include <asm/uaccess.h>
106 #ifdef CONFIG_SBNI_MULTILINE
113 static int sbni_card_probe(
unsigned long );
114 static int sbni_pci_probe(
struct net_device * );
121 static void set_multicast_list(
struct net_device * );
124 static void handle_channel(
struct net_device * );
126 static void send_frame(
struct net_device * );
128 unsigned,
unsigned,
unsigned,
u32 );
130 static void sbni_watchdog(
unsigned long );
131 static void interpret_ack(
struct net_device *,
unsigned );
132 static int append_frame_to_pkt(
struct net_device *,
unsigned,
u32 );
133 static void indicate_pkt(
struct net_device * );
134 static void card_start(
struct net_device * );
136 static void drop_xmit_queue(
struct net_device * );
138 static int skip_tail(
unsigned int,
unsigned int,
u32 );
140 static void change_level(
struct net_device * );
141 static void timeout_change_level(
struct net_device * );
146 #ifdef CONFIG_SBNI_MULTILINE
156 "Granch SBNI12 driver ver 5.0.1 Jun 22 2001 Denis I.Timofeev.\n";
158 static bool skip_pci_probe
__initdata =
false;
162 static unsigned char rxl_tab[];
163 static u32 crc32tab[];
183 static unsigned int netcard_portlist[ ]
__initdata = {
184 0x210, 0x214, 0x220, 0x224, 0x230, 0x234, 0x240, 0x244, 0x250, 0x254,
185 0x260, 0x264, 0x270, 0x274, 0x280, 0x284, 0x290, 0x294, 0x2a0, 0x2a4,
186 0x2b0, 0x2b4, 0x2c0, 0x2c4, 0x2d0, 0x2d4, 0x2e0, 0x2e4, 0x2f0, 0x2f4,
189 #define NET_LOCAL_LOCK(dev) (((struct net_local *)netdev_priv(dev))->lock)
205 pr_err(
"base address 0x%lx is busy, or adapter is malfunctional!\n",
212 .ndo_open = sbni_open,
213 .ndo_stop = sbni_close,
214 .ndo_start_xmit = sbni_start_xmit,
215 .ndo_set_rx_mode = set_multicast_list,
216 .ndo_do_ioctl = sbni_ioctl,
242 err = sbni_init(dev);
262 return sbni_isa_probe( dev );
265 if(
io[ num ] != -1 )
268 else if( scandone ||
io[ 0 ] != -1 )
273 return sbni_isa_probe( dev );
276 if( !skip_pci_probe && !sbni_pci_probe( dev ) )
279 if(
io[ num ] == -1 ) {
286 for( i = 0; netcard_portlist[
i ]; ++
i ) {
287 int ioaddr = netcard_portlist[
i ];
289 sbni_probe1( dev, ioaddr, 0 ))
305 unsigned long pci_ioaddr;
312 pci_irq_line = pdev->
irq;
325 if (pci_irq_line <= 0 || pci_irq_line >=
nr_irqs)
327 "WARNING: The PCI BIOS assigned this PCI card to IRQ %d, which is unlikely to work!.\n"
328 "You should use the PCI BIOS setup to assign a valid IRQ line.\n",
337 if( sbni_probe1( dev, pci_ioaddr, pci_irq_line ) ) {
350 sbni_probe1(
struct net_device *dev,
unsigned long ioaddr,
int irq )
354 if( sbni_card_probe( ioaddr ) ) {
362 unsigned long irq_mask;
372 pr_err(
"%s: can't detect device irq!\n", dev->
name);
376 }
else if( irq == 2 )
383 nl = netdev_priv(dev);
385 pr_err(
"%s: unable to get memory!\n", dev->
name);
398 (
u32)((
long)netdev_priv(dev))) & 0x00ffffff));
411 if(
inb( ioaddr +
CSR0 ) & 0x01 )
414 pr_notice(
"%s: ioaddr %#lx, irq %d, MAC: 00:ff:01:%02x:%02x:%02x\n",
423 / (1 << nl->
csr1.rate));
428 pr_cont(
", receive level (auto)\n");
430 #ifdef CONFIG_SBNI_MULTILINE
435 sbni_cards[ num++ ] =
dev;
441 #ifdef CONFIG_SBNI_MULTILINE
448 netif_stop_queue( dev );
453 spin_lock( &nl->
lock );
456 spin_unlock( &nl->
lock );
459 prepare_to_send( skb, p );
460 spin_unlock( &nl->
lock );
461 netif_start_queue( dev );
476 netif_stop_queue( dev );
477 spin_lock( &nl->
lock );
479 prepare_to_send( skb, dev );
481 spin_unlock( &nl->
lock );
505 sbni_interrupt(
int irq,
void *
dev_id )
511 spin_lock( &nl->
lock );
518 handle_channel( dev ),
522 handle_channel( nl->
second ),
528 spin_unlock( &nl->
lock );
542 #ifdef CONFIG_SBNI_MULTILINE
544 if( nl->
state & FL_SLAVE )
566 if( !(csr0 &
TR_RDY) || (csr0 & RC_RDY) )
567 netdev_err(dev,
"internal error!\n");
579 #ifdef CONFIG_SBNI_MULTILINE
580 if( nl->
state & FL_SLAVE )
600 unsigned is_first, frame_ok = 0;
602 if( check_fhdr( ioaddr, &framelen, &frameno, &ack, &is_first, &crc ) ) {
603 frame_ok = framelen > 4
604 ? upload_data( dev, framelen, frameno, is_first, crc )
605 : skip_tail( ioaddr, framelen, crc );
607 interpret_ack( dev, ack );
621 return !frame_ok || framelen > 4;
641 #ifdef CONFIG_SBNI_MULTILINE
642 if( (nl->
state & FL_SLAVE) || nl->link )
645 drop_xmit_queue( dev );
651 send_frame_header( dev, &crc );
660 download_data( dev, &crc );
691 *crc_p = calc_crc32( *crc_p, skb->
data + nl->
outpos, len );
694 for( len = nl->
framelen - len; len--; )
696 *crc_p =
CRC32( 0, *crc_p );
701 upload_data(
struct net_device *dev,
unsigned framelen,
unsigned frameno,
702 unsigned is_first,
u32 crc )
715 frame_ok = append_frame_to_pkt( dev, framelen, crc );
721 else if( (frame_ok = skip_tail( dev->
base_addr, framelen, crc ))
725 #ifdef CONFIG_SBNI_MULTILINE
726 nl->master->stats.rx_errors++,
727 nl->master->stats.rx_missed_errors++;
729 dev->
stats.rx_errors++,
730 dev->
stats.rx_missed_errors++;
734 frame_ok = skip_tail( dev->
base_addr, framelen, crc );
736 if( is_first && !frame_ok )
742 #ifdef CONFIG_SBNI_MULTILINE
743 nl->master->stats.rx_errors++,
744 nl->master->stats.rx_crc_errors++;
746 dev->
stats.rx_errors++,
747 dev->
stats.rx_crc_errors++;
759 #ifdef CONFIG_SBNI_MULTILINE
760 nl->master->stats.tx_packets++;
761 nl->master->stats.tx_bytes += nl->
tx_buf_p->len;
763 dev->
stats.tx_packets++;
777 interpret_ack(
struct net_device *dev,
unsigned ack )
792 send_complete( dev ),
793 #ifdef CONFIG_SBNI_MULTILINE
794 netif_wake_queue( nl->master );
796 netif_wake_queue( dev );
811 append_frame_to_pkt(
struct net_device *dev,
unsigned framelen,
u32 crc )
828 nl->
inppos += framelen - 4;
850 netdev_err(dev,
"memory leak!\n");
864 #ifdef CONFIG_SBNI_MULTILINE
865 nl->master->trans_start =
jiffies;
880 #ifdef CONFIG_SBNI_MULTILINE
881 nl->master->stats.tx_errors++,
882 nl->master->stats.tx_carrier_errors++;
884 dev->
stats.tx_errors++,
885 dev->
stats.tx_carrier_errors++;
892 #ifdef CONFIG_SBNI_MULTILINE
893 netif_start_queue( nl->master );
894 nl->master->trans_start =
jiffies;
896 netif_start_queue( dev );
920 value = (
u8) len_field;
922 crc =
CRC32( value, crc );
923 value = (
u8) (len_field >> 8);
925 crc =
CRC32( value, crc );
930 crc =
CRC32( 0, crc );
941 skip_tail(
unsigned int ioaddr,
unsigned int tail_len,
u32 crc )
956 check_fhdr(
u32 ioaddr,
u32 *framelen,
u32 *frameno,
u32 *ack,
957 u32 *is_first,
u32 *crc_p )
965 value =
inb( ioaddr +
DAT );
966 *framelen = (
u32)value;
967 crc =
CRC32( value, crc );
968 value =
inb( ioaddr +
DAT );
969 *framelen |= ((
u32)value) << 8;
970 crc =
CRC32( value, crc );
979 value =
inb( ioaddr +
DAT );
980 *frameno = (
u32)value;
981 crc =
CRC32( value, crc );
999 skb_reserve( skb, 2 );
1007 struct net_local *nl = netdev_priv(dev);
1012 #ifdef CONFIG_SBNI_MULTILINE
1015 ++nl->master->stats.rx_packets;
1016 nl->master->stats.rx_bytes += nl->
inppos;
1020 ++dev->
stats.rx_packets;
1035 sbni_watchdog(
unsigned long arg )
1038 struct net_local *nl = netdev_priv(dev);
1040 unsigned long flags;
1049 if( csr0 & (RC_RDY |
BU_EMP) )
1055 timeout_change_level( dev );
1072 spin_unlock_irqrestore( &nl->
lock, flags );
1076 static unsigned char rxl_tab[] = {
1077 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x08,
1078 0x0a, 0x0c, 0x0f, 0x16, 0x18, 0x1a, 0x1c, 0x1f
1081 #define SIZE_OF_TIMEOUT_RXL_TAB 4
1082 static unsigned char timeout_rxl_tab[] = {
1083 0x03, 0x05, 0x08, 0x0b
1091 struct net_local *nl = netdev_priv(dev);
1113 struct net_local *nl = netdev_priv(dev);
1135 timeout_change_level(
struct net_device *dev )
1137 struct net_local *nl = netdev_priv(dev);
1160 struct net_local *nl = netdev_priv(dev);
1171 if( (*p)->irq == dev->
irq &&
1172 ((*p)->base_addr == dev->
base_addr + 4 ||
1173 (*p)->base_addr == dev->
base_addr - 4) &&
1176 ((
struct net_local *) (netdev_priv(*p)))
1178 netdev_notice(dev,
"using shared irq with %s\n",
1181 goto handler_attached;
1186 netdev_err(dev,
"unable to get IRQ %d\n", dev->
irq);
1192 spin_lock( &nl->
lock );
1198 netif_start_queue( dev );
1207 spin_unlock( &nl->
lock );
1215 struct net_local *nl = netdev_priv(dev);
1218 netdev_notice(dev,
"Secondary channel (%s) is active!\n",
1223 #ifdef CONFIG_SBNI_MULTILINE
1224 if( nl->
state & FL_SLAVE )
1228 emancipate( nl->link );
1231 spin_lock( &nl->
lock );
1234 drop_xmit_queue( dev );
1235 netif_stop_queue( dev );
1245 spin_unlock( &nl->
lock );
1273 #define VALID_DECODER (2 + 8 + 0x10 + 0x20 + 0x80 + 0x100 + 0x200)
1277 sbni_card_probe(
unsigned long ioaddr )
1282 if( csr0 != 0xff && csr0 != 0x00 ) {
1299 struct net_local *nl = netdev_priv(dev);
1303 #ifdef CONFIG_SBNI_MULTILINE
1305 char slave_name[ 8 ];
1323 flags.rate = nl->
csr1.rate;
1328 if (
copy_to_user( ifr->ifr_data, &flags,
sizeof flags ))
1336 spin_lock( &nl->
lock );
1338 if( flags.fixed_rxl )
1346 nl->
csr1.rate = flags.rate;
1348 spin_unlock( &nl->
lock );
1351 #ifdef CONFIG_SBNI_MULTILINE
1357 if (
copy_from_user( slave_name, ifr->ifr_data,
sizeof slave_name ))
1360 if( !slave_dev || !(slave_dev->
flags &
IFF_UP) ) {
1361 netdev_err(dev,
"trying to enslave non-active device %s\n",
1366 return enslave( dev, slave_dev );
1372 return emancipate( dev );
1384 #ifdef CONFIG_SBNI_MULTILINE
1389 struct net_local *nl = netdev_priv(dev);
1390 struct net_local *snl = netdev_priv(slave_dev);
1392 if( nl->
state & FL_SLAVE )
1395 if( snl->
state & FL_SLAVE )
1398 spin_lock( &nl->
lock );
1399 spin_lock( &snl->
lock );
1402 snl->link = nl->link;
1403 nl->link = slave_dev;
1405 snl->
state |= FL_SLAVE;
1410 netif_stop_queue( slave_dev );
1411 netif_wake_queue( dev );
1413 spin_unlock( &snl->
lock );
1414 spin_unlock( &nl->
lock );
1415 netdev_notice(dev,
"slave device (%s) attached\n", slave_dev->
name);
1423 struct net_local *snl = netdev_priv(dev);
1427 if( !(snl->
state & FL_SLAVE) )
1430 spin_lock( &nl->
lock );
1431 spin_lock( &snl->
lock );
1432 drop_xmit_queue( dev );
1437 if( t->link == dev ) {
1438 t->link = snl->link;
1446 snl->
state &= ~FL_SLAVE;
1448 netif_start_queue( dev );
1450 spin_unlock( &snl->
lock );
1451 spin_unlock( &nl->
lock );
1482 while( num < SBNI_MAX_NUM_CARDS ) {
1484 "sbni%d", sbni_devsetup);
1490 err = sbni_init(dev);
1503 return *sbni_cards ? 0 : -
ENODEV;
1524 sbni_setup(
char *p )
1531 for( n = 0, parm = 0; *p && n < 8; ) {
1533 if( !*p || *p ==
')' )
1537 else if( *p++ !=
',' )
1544 pr_err(
"Error in sbni kernel parameter!\n");
1548 __setup(
"sbni=", sbni_setup );
1557 calc_crc32(
u32 crc,
u8 *p,
u32 len )
1563 "xorl %%ebx, %%ebx\n"
1566 "movl $crc32tab, %%edi\n"
1573 "movl (%%esi), %%edx\n"
1577 "xorl (%%edi,%%ebx,4), %%eax\n"
1583 "xorl (%%edi,%%ebx,4), %%eax\n"
1589 "xorl (%%edi,%%ebx,4), %%eax\n"
1595 "xorl (%%edi,%%ebx,4), %%eax\n"
1607 "xorb (%%esi), %%bl\n"
1608 "xorl (%%edi,%%ebx,4), %%eax\n"
1615 "xorb 1(%%esi), %%bl\n"
1616 "xorl (%%edi,%%ebx,4), %%eax\n"
1623 "xorb 2(%%esi), %%bl\n"
1624 "xorl (%%edi,%%ebx,4), %%eax\n"
1627 :
"0" (_crc),
"g" (p),
"g" (len)
1628 :
"bx",
"cx",
"dx",
"si",
"di"
1637 calc_crc32(
u32 crc,
u8 *p,
u32 len )
1640 crc =
CRC32( *p++, crc );
1649 0xD202EF8D, 0xA505DF1B, 0x3C0C8EA1, 0x4B0BBE37,
1650 0xD56F2B94, 0xA2681B02, 0x3B614AB8, 0x4C667A2E,
1651 0xDCD967BF, 0xABDE5729, 0x32D70693, 0x45D03605,
1652 0xDBB4A3A6, 0xACB39330, 0x35BAC28A, 0x42BDF21C,
1653 0xCFB5FFE9, 0xB8B2CF7F, 0x21BB9EC5, 0x56BCAE53,
1654 0xC8D83BF0, 0xBFDF0B66, 0x26D65ADC, 0x51D16A4A,
1655 0xC16E77DB, 0xB669474D, 0x2F6016F7, 0x58672661,
1656 0xC603B3C2, 0xB1048354, 0x280DD2EE, 0x5F0AE278,
1657 0xE96CCF45, 0x9E6BFFD3, 0x0762AE69, 0x70659EFF,
1658 0xEE010B5C, 0x99063BCA, 0x000F6A70, 0x77085AE6,
1659 0xE7B74777, 0x90B077E1, 0x09B9265B, 0x7EBE16CD,
1660 0xE0DA836E, 0x97DDB3F8, 0x0ED4E242, 0x79D3D2D4,
1661 0xF4DBDF21, 0x83DCEFB7, 0x1AD5BE0D, 0x6DD28E9B,
1662 0xF3B61B38, 0x84B12BAE, 0x1DB87A14, 0x6ABF4A82,
1663 0xFA005713, 0x8D076785, 0x140E363F, 0x630906A9,
1664 0xFD6D930A, 0x8A6AA39C, 0x1363F226, 0x6464C2B0,
1665 0xA4DEAE1D, 0xD3D99E8B, 0x4AD0CF31, 0x3DD7FFA7,
1666 0xA3B36A04, 0xD4B45A92, 0x4DBD0B28, 0x3ABA3BBE,
1667 0xAA05262F, 0xDD0216B9, 0x440B4703, 0x330C7795,
1668 0xAD68E236, 0xDA6FD2A0, 0x4366831A, 0x3461B38C,
1669 0xB969BE79, 0xCE6E8EEF, 0x5767DF55, 0x2060EFC3,
1670 0xBE047A60, 0xC9034AF6, 0x500A1B4C, 0x270D2BDA,
1671 0xB7B2364B, 0xC0B506DD, 0x59BC5767, 0x2EBB67F1,
1672 0xB0DFF252, 0xC7D8C2C4, 0x5ED1937E, 0x29D6A3E8,
1673 0x9FB08ED5, 0xE8B7BE43, 0x71BEEFF9, 0x06B9DF6F,
1674 0x98DD4ACC, 0xEFDA7A5A, 0x76D32BE0, 0x01D41B76,
1675 0x916B06E7, 0xE66C3671, 0x7F6567CB, 0x0862575D,
1676 0x9606C2FE, 0xE101F268, 0x7808A3D2, 0x0F0F9344,
1677 0x82079EB1, 0xF500AE27, 0x6C09FF9D, 0x1B0ECF0B,
1678 0x856A5AA8, 0xF26D6A3E, 0x6B643B84, 0x1C630B12,
1679 0x8CDC1683, 0xFBDB2615, 0x62D277AF, 0x15D54739,
1680 0x8BB1D29A, 0xFCB6E20C, 0x65BFB3B6, 0x12B88320,
1681 0x3FBA6CAD, 0x48BD5C3B, 0xD1B40D81, 0xA6B33D17,
1682 0x38D7A8B4, 0x4FD09822, 0xD6D9C998, 0xA1DEF90E,
1683 0x3161E49F, 0x4666D409, 0xDF6F85B3, 0xA868B525,
1684 0x360C2086, 0x410B1010, 0xD80241AA, 0xAF05713C,
1685 0x220D7CC9, 0x550A4C5F, 0xCC031DE5, 0xBB042D73,
1686 0x2560B8D0, 0x52678846, 0xCB6ED9FC, 0xBC69E96A,
1687 0x2CD6F4FB, 0x5BD1C46D, 0xC2D895D7, 0xB5DFA541,
1688 0x2BBB30E2, 0x5CBC0074, 0xC5B551CE, 0xB2B26158,
1689 0x04D44C65, 0x73D37CF3, 0xEADA2D49, 0x9DDD1DDF,
1690 0x03B9887C, 0x74BEB8EA, 0xEDB7E950, 0x9AB0D9C6,
1691 0x0A0FC457, 0x7D08F4C1, 0xE401A57B, 0x930695ED,
1692 0x0D62004E, 0x7A6530D8, 0xE36C6162, 0x946B51F4,
1693 0x19635C01, 0x6E646C97, 0xF76D3D2D, 0x806A0DBB,
1694 0x1E0E9818, 0x6909A88E, 0xF000F934, 0x8707C9A2,
1695 0x17B8D433, 0x60BFE4A5, 0xF9B6B51F, 0x8EB18589,
1696 0x10D5102A, 0x67D220BC, 0xFEDB7106, 0x89DC4190,
1697 0x49662D3D, 0x3E611DAB, 0xA7684C11, 0xD06F7C87,
1698 0x4E0BE924, 0x390CD9B2, 0xA0058808, 0xD702B89E,
1699 0x47BDA50F, 0x30BA9599, 0xA9B3C423, 0xDEB4F4B5,
1700 0x40D06116, 0x37D75180, 0xAEDE003A, 0xD9D930AC,
1701 0x54D13D59, 0x23D60DCF, 0xBADF5C75, 0xCDD86CE3,
1702 0x53BCF940, 0x24BBC9D6, 0xBDB2986C, 0xCAB5A8FA,
1703 0x5A0AB56B, 0x2D0D85FD, 0xB404D447, 0xC303E4D1,
1704 0x5D677172, 0x2A6041E4, 0xB369105E, 0xC46E20C8,
1705 0x72080DF5, 0x050F3D63, 0x9C066CD9, 0xEB015C4F,
1706 0x7565C9EC, 0x0262F97A, 0x9B6BA8C0, 0xEC6C9856,
1707 0x7CD385C7, 0x0BD4B551, 0x92DDE4EB, 0xE5DAD47D,
1708 0x7BBE41DE, 0x0CB97148, 0x95B020F2, 0xE2B71064,
1709 0x6FBF1D91, 0x18B82D07, 0x81B17CBD, 0xF6B64C2B,
1710 0x68D2D988, 0x1FD5E91E, 0x86DCB8A4, 0xF1DB8832,
1711 0x616495A3, 0x1663A535, 0x8F6AF48F, 0xF86DC419,
1712 0x660951BA, 0x110E612C, 0x88073096, 0xFF000000