35 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
37 #include <linux/module.h>
38 #include <linux/kernel.h>
39 #include <linux/types.h>
40 #include <linux/fcntl.h>
42 #include <linux/ptrace.h>
45 #include <linux/slab.h>
46 #include <linux/string.h>
48 #include <linux/errno.h>
50 #include <linux/netdevice.h>
52 #include <linux/if_arp.h>
53 #include <linux/if_frad.h>
54 #include <linux/sdla.h>
55 #include <linux/bitops.h>
59 #include <asm/uaccess.h>
63 static unsigned int valid_port[] = { 0x250, 0x270, 0x280, 0x300, 0x350, 0x360, 0x380, 0x390};
65 static unsigned int valid_mem[] = {
66 0xA0000, 0xA2000, 0xA4000, 0xA6000, 0xA8000, 0xAA000, 0xAC000, 0xAE000,
67 0xB0000, 0xB2000, 0xB4000, 0xB6000, 0xB8000, 0xBA000, 0xBC000, 0xBE000,
68 0xC0000, 0xC2000, 0xC4000, 0xC6000, 0xC8000, 0xCA000, 0xCC000, 0xCE000,
69 0xD0000, 0xD2000, 0xD4000, 0xD6000, 0xD8000, 0xDA000, 0xDC000, 0xDE000,
70 0xE0000, 0xE2000, 0xE4000, 0xE6000, 0xE8000, 0xEA000, 0xEC000, 0xEE000};
80 #define SDLA_WINDOW(dev,addr) outb((((addr) >> 13) & 0x1F), (dev)->base_addr + SDLA_REG_Z80_WINDOW)
93 base = (
const void *) (dev->
mem_start + offset);
108 __sdla_read(dev, addr, buf, len);
109 spin_unlock_irqrestore(&sdla_lock, flags);
113 const void *
buf,
short len)
124 base = (
void *) (dev->
mem_start + offset);
127 memcpy(base, temp, bytes);
135 static void sdla_write(
struct net_device *dev,
int addr,
136 const void *buf,
short len)
141 __sdla_write(dev, addr, buf, len);
142 spin_unlock_irqrestore(&sdla_lock, flags);
146 static void sdla_clear(
struct net_device *dev)
166 spin_unlock_irqrestore(&sdla_lock, flags);
170 static char sdla_byte(
struct net_device *dev,
int addr)
180 spin_unlock_irqrestore(&sdla_lock, flags);
187 struct frad_local *flp;
189 flp = netdev_priv(dev);
212 static void sdla_start(
struct net_device *dev)
214 struct frad_local *flp;
216 flp = netdev_priv(dev);
250 static int sdla_z80_poll(
struct net_device *dev,
int z80_addr,
int jiffs,
char resp1,
char resp2)
262 while (
time_before(jiffies, done) && (resp != resp1) && (!resp2 || (resp != resp2)))
275 #define Z80_READY '1'
276 #define LOADER_READY '2'
277 #define Z80_SCC_OK '3'
278 #define Z80_SCC_BAD '4'
290 sdla_write(dev, 0, &data, 1);
296 sdla_read(dev, 0, &data, 1);
309 else if (jiffs < 220)
311 else if (jiffs < 258)
313 else if (jiffs < 357)
315 else if (jiffs < 467)
354 netdev_info(dev,
"Modem DCD unexpectedly low!\n");
356 netdev_info(dev,
"Modem CTS unexpectedly low!\n");
361 netdev_info(dev,
"Channel became inoperative!\n");
366 netdev_info(dev,
"Channel became operative!\n");
371 netdev_info(dev,
"Status change reported by Access Node\n");
373 for(pstatus = data, i=0;i < len;i++,pstatus++)
386 netdev_info(dev,
"DLCI %i: %s\n",
387 pstatus->
dlci, state);
393 netdev_info(dev,
"Received unknown DLCIs:");
394 len /=
sizeof(
short);
395 for(pdlci = data,i=0;i < len;i++,pdlci++)
401 netdev_err(dev,
"Command timed out!\n");
405 netdev_info(dev,
"Bc/CIR overflow, acceptable size is %i\n",
410 netdev_info(dev,
"Buffer size over specified max of %i\n",
422 netdev_dbg(dev,
"Cmd 0x%02X generated return code 0x%02X\n",
433 struct frad_local *flp;
435 unsigned long pflags;
437 int ret, waiting, len;
440 flp = netdev_priv(dev);
459 spin_unlock_irqrestore(&sdla_lock, pflags);
470 spin_unlock_irqrestore(&sdla_lock, pflags);
481 if (outbuf && outlen)
483 *outlen = *outlen >= len ? len : *
outlen;
493 spin_unlock_irqrestore(&sdla_lock, pflags);
499 sdla_errors(dev, cmd, dlci, ret, len, &
status);
510 static int sdla_reconfig(
struct net_device *dev);
514 struct frad_local *flp;
517 flp = netdev_priv(slave);
519 for(i=0;i<CONFIG_DLCI_MAX;i++)
520 if (flp->master[i] == master)
523 if (i == CONFIG_DLCI_MAX)
526 flp->dlci[
i] =
abs(flp->dlci[i]);
536 struct frad_local *flp;
539 flp = netdev_priv(slave);
541 for(i=0;i<CONFIG_DLCI_MAX;i++)
542 if (flp->master[i] == master)
545 if (i == CONFIG_DLCI_MAX)
548 flp->dlci[
i] = -
abs(flp->dlci[i]);
558 struct frad_local *flp;
564 flp = netdev_priv(slave);
566 for(i=0;i<CONFIG_DLCI_MAX;i++)
570 if (
abs(flp->dlci[i]) == *(
short *)(master->
dev_addr))
574 if (i == CONFIG_DLCI_MAX)
578 flp->master[
i] = master;
579 flp->dlci[
i] = -*(
short *)(master->
dev_addr);
582 if (netif_running(slave)) {
584 sdla_reconfig(slave);
594 struct frad_local *flp;
597 flp = netdev_priv(slave);
599 for(i=0;i<CONFIG_DLCI_MAX;i++)
600 if (flp->master[i] == master)
603 if (i == CONFIG_DLCI_MAX)
606 flp->master[
i] =
NULL;
610 if (netif_running(slave)) {
612 sdla_reconfig(slave);
622 struct frad_local *flp;
623 struct dlci_local *dlp;
627 flp = netdev_priv(slave);
629 for(i=0;i<CONFIG_DLCI_MAX;i++)
630 if (flp->master[i] == master)
633 if (i == CONFIG_DLCI_MAX)
636 dlp = netdev_priv(master);
640 if (netif_running(slave)) {
643 NULL, 0, &dlp->config, &len);
662 struct frad_local *flp;
668 flp = netdev_priv(dev);
672 netif_stop_queue(dev);
686 netdev_warn(dev,
"Non DLCI device, type %i, tried to send on FRAD module\n",
692 netdev_warn(dev,
"unknown firmware type 0x%04X\n",
718 spin_unlock_irqrestore(&sdla_lock, flags);
726 dev->
stats.tx_packets++;
732 dev->
stats.tx_dropped++;
736 dev->
stats.tx_errors++;
740 netif_wake_queue(dev);
741 for(i=0;i<CONFIG_DLCI_MAX;i++)
743 if(flp->master[i]!=
NULL)
744 netif_wake_queue(flp->master[i]);
751 static void sdla_receive(
struct net_device *dev)
754 struct frad_local *flp;
755 struct dlci_local *dlp;
766 flp = netdev_priv(dev);
768 received = addr = buf_top = buf_base = 0;
811 for (i=0;i<CONFIG_DLCI_MAX;i++)
812 if (flp->dlci[i] == dlci)
815 if (i == CONFIG_DLCI_MAX)
817 netdev_notice(dev,
"Received packet from invalid DLCI %i, ignoring\n",
819 dev->
stats.rx_errors++;
827 skb = dev_alloc_skb(len +
sizeof(
struct frhdr));
830 netdev_notice(dev,
"Memory squeeze, dropping packet\n");
831 dev->
stats.rx_dropped++;
835 skb_reserve(skb,
sizeof(
struct frhdr));
854 split = addr + len > buf_top + 1 ? len - (buf_top - addr + 1) : 0;
857 __sdla_read(dev, addr,
skb_put(skb, len2), len2);
859 __sdla_read(dev, buf_base,
skb_put(skb, split), split);
864 flp->buffer = (flp->buffer + 1) % pbufi->
rse_num;
871 dev->
stats.rx_packets++;
872 dlp = netdev_priv(master);
873 (*dlp->receive)(skb, master);
876 spin_unlock_irqrestore(&sdla_lock, flags);
882 struct frad_local *flp;
887 flp = netdev_priv(dev);
889 if (!flp->initialized)
891 netdev_warn(dev,
"irq %d for uninitialized device\n", dev->
irq);
911 netdev_warn(dev,
"invalid irq flag 0x%02X\n", byte);
930 static void sdla_poll(
unsigned long device)
933 struct frad_local *flp;
936 flp = netdev_priv(dev);
941 flp->timer.expires = 1;
947 struct frad_local *flp;
950 short dlcis[CONFIG_DLCI_MAX];
952 flp = netdev_priv(dev);
955 for(i=0;i<CONFIG_DLCI_MAX;i++)
957 dlcis[len++] =
abs(flp->dlci[i]);
962 for(i=0;i<CONFIG_DLCI_MAX;i++)
963 if (flp->dlci[i] > 0)
994 netif_stop_queue(dev);
1001 short dlci[CONFIG_DLCI_MAX];
1006 struct frad_local *flp;
1007 struct dlci_local *dlp;
1013 flp = netdev_priv(dev);
1015 if (!flp->initialized)
1018 if (!flp->configured)
1023 for(i=0;i<CONFIG_DLCI_MAX;i++)
1025 data.
dlci[len++] =
abs(flp->dlci[i]);
1040 memset(&intr, 0,
sizeof(intr));
1044 flp->timer.expires = 1;
1081 for(i=0;i<CONFIG_DLCI_MAX;i++)
1082 if (flp->dlci[i] > 0)
1087 for(i=0;i<CONFIG_DLCI_MAX;i++)
1090 dlp = netdev_priv(flp->master[i]);
1091 if (dlp->configured)
1095 netif_start_queue(dev);
1102 struct frad_local *flp;
1107 if (dev->
type == 0xFFFF)
1110 flp = netdev_priv(dev);
1114 if (netif_running(dev))
1126 if ((data.
config.kbaud < 0) ||
1142 if ((data.
config.N391 < 1) || (data.
config.N391 > 255))
1157 if (dev->
mtu != flp->config.mtu)
1160 dev->
mtu = flp->config.mtu;
1161 for(i=0;i<CONFIG_DLCI_MAX;i++)
1163 flp->master[
i]->mtu = flp->config.mtu;
1166 flp->config.mtu +=
sizeof(
struct frhdr);
1169 if (!flp->configured)
1172 flp->configured = 1;
1177 if (netif_running(dev))
1179 size =
sizeof(
data);
1184 if (flp->configured)
1198 static
int sdla_xfer(struct net_device *dev, struct sdla_mem __user *info, int read)
1223 return PTR_ERR(temp);
1230 static int sdla_reconfig(
struct net_device *dev)
1232 struct frad_local *flp;
1236 flp = netdev_priv(dev);
1239 for(i=0;i<CONFIG_DLCI_MAX;i++)
1241 data.
dlci[len++] = flp->dlci[
i];
1254 static int sdla_ioctl(
struct net_device *dev,
struct ifreq *ifr,
int cmd)
1256 struct frad_local *flp;
1261 flp = netdev_priv(dev);
1263 if (!flp->initialized)
1270 return sdla_config(dev, ifr->ifr_data, cmd ==
FRAD_GET_CONF);
1273 ifr->ifr_flags = flp->type;
1277 return sdla_cpuspeed(dev, ifr);
1286 if (flp->configured)
1289 switch (ifr->ifr_flags)
1292 dev->
type = ifr->ifr_flags;
1307 return sdla_xfer(dev, ifr->ifr_data, cmd ==
SDLA_READMEM);
1323 static int sdla_change_mtu(
struct net_device *dev,
int new_mtu)
1325 struct frad_local *flp;
1327 flp = netdev_priv(dev);
1329 if (netif_running(dev))
1338 struct frad_local *flp;
1344 flp = netdev_priv(dev);
1346 if (flp->initialized)
1368 if (
inb(base + i) != 0xFF)
1371 if (i == SDLA_IO_EXTENTS) {
1384 if (
inb(base + i) != byte)
1387 if (i == SDLA_IO_EXTENTS) {
1422 netdev_notice(dev,
"Unknown card type\n");
1586 flp->initialized = 1;
1597 .ndo_open = sdla_open,
1598 .ndo_stop = sdla_close,
1599 .ndo_do_ioctl = sdla_ioctl,
1600 .ndo_set_config = sdla_set_config,
1601 .ndo_start_xmit = sdla_transmit,
1602 .ndo_change_mtu = sdla_change_mtu,
1605 static void setup_sdla(
struct net_device *dev)
1607 struct frad_local *flp = netdev_priv(dev);
1618 flp->activate = sdla_activate;
1619 flp->deactivate = sdla_deactivate;
1620 flp->assoc = sdla_assoc;
1621 flp->deassoc = sdla_deassoc;
1625 flp->timer.expires = 1;
1626 flp->timer.data = (
unsigned long) dev;
1627 flp->timer.function = sdla_poll;
1632 static int __init init_sdla(
void)
1638 sdla =
alloc_netdev(
sizeof(
struct frad_local),
"sdla0", setup_sdla);
1649 static void __exit exit_sdla(
void)
1651 struct frad_local *flp = netdev_priv(sdla);
1654 if (flp->initialized) {