2 * SDLA An implementation of a driver for the Sangoma S502/S508 series
3 * multi-protocol PC interface card. Initial offering is with
4 * the DLCI driver, providing Frame Relay support for linux.
6 * Global definitions for the Frame relay interface.
8 * Version: @(#)sdla.c 0.30 12 Sep 1996
10 * Credits: Sangoma Technologies, for the use of 2 cards for an extended
12 * David Mandelstam <dm@sangoma.com> for getting me started on
13 * this project, and incentive to complete it.
14 * Gene Kozen <74604.152@compuserve.com> for providing me with
15 * important information about the cards.
17 * Author: Mike McLagan <mike.mclagan@linux.org>
20 * 0.15 Mike McLagan Improved error handling, packet dropping
21 * 0.20 Mike McLagan New transmit/receive flags for config
22 * If in FR mode, don't accept packets from
24 * 0.25 Mike McLagan Fixed problem with rejecting packets
25 * from non DLCI devices.
26 * 0.30 Mike McLagan Fixed kernel panic when used with modified
29 * This program is free software; you can redistribute it and/or
30 * modify it under the terms of the GNU General Public License
31 * as published by the Free Software Foundation; either version
32 * 2 of the License, or (at your option) any later version.
35 #include <linux/config.h> /* for CONFIG_DLCI_MAX */
36 #include <linux/module.h>
37 #include <linux/kernel.h>
38 #include <linux/types.h>
39 #include <linux/fcntl.h>
40 #include <linux/interrupt.h>
41 #include <linux/ptrace.h>
42 #include <linux/ioport.h>
44 #include <linux/slab.h>
45 #include <linux/string.h>
46 #include <linux/timer.h>
47 #include <linux/errno.h>
48 #include <linux/init.h>
49 #include <linux/netdevice.h>
50 #include <linux/skbuff.h>
51 #include <linux/if_arp.h>
52 #include <linux/if_frad.h>
53 #include <linux/sdla.h>
54 #include <linux/bitops.h>
56 #include <asm/system.h>
59 #include <asm/uaccess.h>
61 static const char* version = "SDLA driver v0.30, 12 Sep 1996, mike.mclagan@linux.org";
63 static unsigned int valid_port[] __initdata = { 0x250, 0x270, 0x280, 0x300, 0x350, 0x360, 0x380, 0x390};
65 static unsigned int valid_mem[] __initdata = {
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};
72 static DEFINE_SPINLOCK(sdla_lock);
74 /*********************************************************
76 * these are the core routines that access the card itself
78 *********************************************************/
80 #define SDLA_WINDOW(dev,addr) outb((((addr) >> 13) & 0x1F), (dev)->base_addr + SDLA_REG_Z80_WINDOW)
82 static void __sdla_read(struct net_device *dev, int addr, void *buf, short len)
91 offset = addr & SDLA_ADDR_MASK;
92 bytes = offset + len > SDLA_WINDOW_SIZE ? SDLA_WINDOW_SIZE - offset : len;
93 base = (const void *) (dev->mem_start + offset);
95 SDLA_WINDOW(dev, addr);
96 memcpy(temp, base, bytes);
104 static void sdla_read(struct net_device *dev, int addr, void *buf, short len)
107 spin_lock_irqsave(&sdla_lock, flags);
108 __sdla_read(dev, addr, buf, len);
109 spin_unlock_irqrestore(&sdla_lock, flags);
112 static void __sdla_write(struct net_device *dev, int addr,
113 const void *buf, short len)
122 offset = addr & SDLA_ADDR_MASK;
123 bytes = offset + len > SDLA_WINDOW_SIZE ? SDLA_WINDOW_SIZE - offset : len;
124 base = (void *) (dev->mem_start + offset);
126 SDLA_WINDOW(dev, addr);
127 memcpy(base, temp, bytes);
135 static void sdla_write(struct net_device *dev, int addr,
136 const void *buf, short len)
140 spin_lock_irqsave(&sdla_lock, flags);
141 __sdla_write(dev, addr, buf, len);
142 spin_unlock_irqrestore(&sdla_lock, flags);
146 static void sdla_clear(struct net_device *dev)
150 int len, addr, bytes;
154 bytes = SDLA_WINDOW_SIZE;
155 base = (void *) dev->mem_start;
157 spin_lock_irqsave(&sdla_lock, flags);
160 SDLA_WINDOW(dev, addr);
161 memset(base, 0, bytes);
166 spin_unlock_irqrestore(&sdla_lock, flags);
170 static char sdla_byte(struct net_device *dev, int addr)
175 temp = (void *) (dev->mem_start + (addr & SDLA_ADDR_MASK));
177 spin_lock_irqsave(&sdla_lock, flags);
178 SDLA_WINDOW(dev, addr);
180 spin_unlock_irqrestore(&sdla_lock, flags);
185 void sdla_stop(struct net_device *dev)
187 struct frad_local *flp;
193 outb(SDLA_S502A_HALT, dev->base_addr + SDLA_REG_CONTROL);
194 flp->state = SDLA_HALT;
197 outb(SDLA_HALT, dev->base_addr + SDLA_REG_Z80_CONTROL);
198 outb(SDLA_S502E_ENABLE, dev->base_addr + SDLA_REG_CONTROL);
199 flp->state = SDLA_S502E_ENABLE;
202 flp->state &= ~SDLA_CPUEN;
203 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
206 flp->state &= ~SDLA_CPUEN;
207 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
212 void sdla_start(struct net_device *dev)
214 struct frad_local *flp;
220 outb(SDLA_S502A_NMI, dev->base_addr + SDLA_REG_CONTROL);
221 outb(SDLA_S502A_START, dev->base_addr + SDLA_REG_CONTROL);
222 flp->state = SDLA_S502A_START;
225 outb(SDLA_S502E_CPUEN, dev->base_addr + SDLA_REG_Z80_CONTROL);
226 outb(0x00, dev->base_addr + SDLA_REG_CONTROL);
230 flp->state |= SDLA_CPUEN;
231 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
234 flp->state |= SDLA_CPUEN;
235 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
240 /****************************************************
242 * this is used for the S502A/E cards to determine
243 * the speed of the onboard CPU. Calibration is
244 * necessary for the Frame Relay code uploaded
245 * later. Incorrect results cause timing problems
246 * with link checks & status messages
248 ***************************************************/
250 int sdla_z80_poll(struct net_device *dev, int z80_addr, int jiffs, char resp1, char resp2)
252 unsigned long start, done, now;
255 start = now = jiffies;
256 done = jiffies + jiffs;
258 temp = (void *)dev->mem_start;
259 temp += z80_addr & SDLA_ADDR_MASK;
262 while (time_before(jiffies, done) && (resp != resp1) && (!resp2 || (resp != resp2)))
266 SDLA_WINDOW(dev, z80_addr);
271 return(time_before(jiffies, done) ? jiffies - start : -1);
274 /* constants for Z80 CPU speed */
275 #define Z80_READY '1' /* Z80 is ready to begin */
276 #define LOADER_READY '2' /* driver is ready to begin */
277 #define Z80_SCC_OK '3' /* SCC is on board */
278 #define Z80_SCC_BAD '4' /* SCC was not found */
280 static int sdla_cpuspeed(struct net_device *dev, struct ifreq *ifr)
286 if (sdla_z80_poll(dev, 0, 3*HZ, Z80_READY, 0) < 0)
290 sdla_write(dev, 0, &data, 1);
292 if ((jiffs = sdla_z80_poll(dev, 0, 8*HZ, Z80_SCC_OK, Z80_SCC_BAD)) < 0)
296 sdla_read(dev, 0, &data, 1);
298 if (data == Z80_SCC_BAD)
300 printk("%s: SCC bad\n", dev->name);
304 if (data != Z80_SCC_OK)
308 ifr->ifr_mtu = SDLA_CPU_16M;
309 else if (jiffs < 220)
310 ifr->ifr_mtu = SDLA_CPU_10M;
311 else if (jiffs < 258)
312 ifr->ifr_mtu = SDLA_CPU_8M;
313 else if (jiffs < 357)
314 ifr->ifr_mtu = SDLA_CPU_7M;
315 else if (jiffs < 467)
316 ifr->ifr_mtu = SDLA_CPU_5M;
318 ifr->ifr_mtu = SDLA_CPU_3M;
323 /************************************************
325 * Direct interaction with the Frame Relay code
328 ************************************************/
332 short dlci __attribute__((packed));
333 char flags __attribute__((packed));
339 struct _dlci_stat dlcis[SDLA_MAX_DLCI];
342 static void sdla_errors(struct net_device *dev, int cmd, int dlci, int ret, int len, void *data)
344 struct _dlci_stat *pstatus;
347 char *state, line[30];
353 if (*state & SDLA_MODEM_DCD_LOW)
354 printk(KERN_INFO "%s: Modem DCD unexpectedly low!\n", dev->name);
355 if (*state & SDLA_MODEM_CTS_LOW)
356 printk(KERN_INFO "%s: Modem CTS unexpectedly low!\n", dev->name);
357 /* I should probably do something about this! */
360 case SDLA_RET_CHANNEL_OFF:
361 printk(KERN_INFO "%s: Channel became inoperative!\n", dev->name);
365 case SDLA_RET_CHANNEL_ON:
366 printk(KERN_INFO "%s: Channel became operative!\n", dev->name);
370 case SDLA_RET_DLCI_STATUS:
371 printk(KERN_INFO "%s: Status change reported by Access Node.\n", dev->name);
372 len /= sizeof(struct _dlci_stat);
373 for(pstatus = data, i=0;i < len;i++,pstatus++)
375 if (pstatus->flags & SDLA_DLCI_NEW)
377 else if (pstatus->flags & SDLA_DLCI_DELETED)
379 else if (pstatus->flags & SDLA_DLCI_ACTIVE)
383 sprintf(line, "unknown status: %02X", pstatus->flags);
386 printk(KERN_INFO "%s: DLCI %i: %s.\n", dev->name, pstatus->dlci, state);
391 case SDLA_RET_DLCI_UNKNOWN:
392 printk(KERN_INFO "%s: Received unknown DLCIs:", dev->name);
393 len /= sizeof(short);
394 for(pdlci = data,i=0;i < len;i++,pdlci++)
395 printk(" %i", *pdlci);
399 case SDLA_RET_TIMEOUT:
400 printk(KERN_ERR "%s: Command timed out!\n", dev->name);
403 case SDLA_RET_BUF_OVERSIZE:
404 printk(KERN_INFO "%s: Bc/CIR overflow, acceptable size is %i\n", dev->name, len);
407 case SDLA_RET_BUF_TOO_BIG:
408 printk(KERN_INFO "%s: Buffer size over specified max of %i\n", dev->name, len);
411 case SDLA_RET_CHANNEL_INACTIVE:
412 case SDLA_RET_DLCI_INACTIVE:
413 case SDLA_RET_CIR_OVERFLOW:
414 case SDLA_RET_NO_BUFS:
415 if (cmd == SDLA_INFORMATION_WRITE)
419 printk(KERN_DEBUG "%s: Cmd 0x%2.2X generated return code 0x%2.2X\n", dev->name, cmd, ret);
420 /* Further processing could be done here */
425 static int sdla_cmd(struct net_device *dev, int cmd, short dlci, short flags,
426 void *inbuf, short inlen, void *outbuf, short *outlen)
428 static struct _frad_stat status;
429 struct frad_local *flp;
430 struct sdla_cmd *cmd_buf;
431 unsigned long pflags;
433 int ret, waiting, len;
437 window = flp->type == SDLA_S508 ? SDLA_508_CMD_BUF : SDLA_502_CMD_BUF;
438 cmd_buf = (struct sdla_cmd *)(dev->mem_start + (window & SDLA_ADDR_MASK));
441 jiffs = jiffies + HZ; /* 1 second is plenty */
443 spin_lock_irqsave(&sdla_lock, pflags);
444 SDLA_WINDOW(dev, window);
446 cmd_buf->dlci = dlci;
447 cmd_buf->flags = flags;
450 memcpy(cmd_buf->data, inbuf, inlen);
452 cmd_buf->length = inlen;
454 cmd_buf->opp_flag = 1;
455 spin_unlock_irqrestore(&sdla_lock, pflags);
459 while (waiting && time_before_eq(jiffies, jiffs))
463 spin_lock_irqsave(&sdla_lock, pflags);
464 SDLA_WINDOW(dev, window);
465 waiting = ((volatile int)(cmd_buf->opp_flag));
466 spin_unlock_irqrestore(&sdla_lock, pflags);
473 spin_lock_irqsave(&sdla_lock, pflags);
474 SDLA_WINDOW(dev, window);
475 ret = cmd_buf->retval;
476 len = cmd_buf->length;
477 if (outbuf && outlen)
479 *outlen = *outlen >= len ? len : *outlen;
482 memcpy(outbuf, cmd_buf->data, *outlen);
485 /* This is a local copy that's used for error handling */
487 memcpy(&status, cmd_buf->data, len > sizeof(status) ? sizeof(status) : len);
489 spin_unlock_irqrestore(&sdla_lock, pflags);
492 ret = SDLA_RET_TIMEOUT;
494 if (ret != SDLA_RET_OK)
495 sdla_errors(dev, cmd, dlci, ret, len, &status);
500 /***********************************************
502 * these functions are called by the DLCI driver
504 ***********************************************/
506 static int sdla_reconfig(struct net_device *dev);
508 int sdla_activate(struct net_device *slave, struct net_device *master)
510 struct frad_local *flp;
515 for(i=0;i<CONFIG_DLCI_MAX;i++)
516 if (flp->master[i] == master)
519 if (i == CONFIG_DLCI_MAX)
522 flp->dlci[i] = abs(flp->dlci[i]);
524 if (netif_running(slave) && (flp->config.station == FRAD_STATION_NODE))
525 sdla_cmd(slave, SDLA_ACTIVATE_DLCI, 0, 0, &flp->dlci[i], sizeof(short), NULL, NULL);
530 int sdla_deactivate(struct net_device *slave, struct net_device *master)
532 struct frad_local *flp;
537 for(i=0;i<CONFIG_DLCI_MAX;i++)
538 if (flp->master[i] == master)
541 if (i == CONFIG_DLCI_MAX)
544 flp->dlci[i] = -abs(flp->dlci[i]);
546 if (netif_running(slave) && (flp->config.station == FRAD_STATION_NODE))
547 sdla_cmd(slave, SDLA_DEACTIVATE_DLCI, 0, 0, &flp->dlci[i], sizeof(short), NULL, NULL);
552 int sdla_assoc(struct net_device *slave, struct net_device *master)
554 struct frad_local *flp;
557 if (master->type != ARPHRD_DLCI)
562 for(i=0;i<CONFIG_DLCI_MAX;i++)
566 if (abs(flp->dlci[i]) == *(short *)(master->dev_addr))
570 if (i == CONFIG_DLCI_MAX)
571 return(-EMLINK); /* #### Alan: Comments on this ?? */
574 flp->master[i] = master;
575 flp->dlci[i] = -*(short *)(master->dev_addr);
576 master->mtu = slave->mtu;
578 if (netif_running(slave)) {
579 if (flp->config.station == FRAD_STATION_CPE)
580 sdla_reconfig(slave);
582 sdla_cmd(slave, SDLA_ADD_DLCI, 0, 0, master->dev_addr, sizeof(short), NULL, NULL);
588 int sdla_deassoc(struct net_device *slave, struct net_device *master)
590 struct frad_local *flp;
595 for(i=0;i<CONFIG_DLCI_MAX;i++)
596 if (flp->master[i] == master)
599 if (i == CONFIG_DLCI_MAX)
602 flp->master[i] = NULL;
606 if (netif_running(slave)) {
607 if (flp->config.station == FRAD_STATION_CPE)
608 sdla_reconfig(slave);
610 sdla_cmd(slave, SDLA_DELETE_DLCI, 0, 0, master->dev_addr, sizeof(short), NULL, NULL);
616 int sdla_dlci_conf(struct net_device *slave, struct net_device *master, int get)
618 struct frad_local *flp;
619 struct dlci_local *dlp;
625 for(i=0;i<CONFIG_DLCI_MAX;i++)
626 if (flp->master[i] == master)
629 if (i == CONFIG_DLCI_MAX)
635 len = sizeof(struct dlci_conf);
636 if (netif_running(slave)) {
638 ret = sdla_cmd(slave, SDLA_READ_DLCI_CONFIGURATION, abs(flp->dlci[i]), 0,
639 NULL, 0, &dlp->config, &len);
641 ret = sdla_cmd(slave, SDLA_SET_DLCI_CONFIGURATION, abs(flp->dlci[i]), 0,
642 &dlp->config, sizeof(struct dlci_conf) - 4 * sizeof(short), NULL, NULL);
645 return(ret == SDLA_RET_OK ? 0 : -EIO);
648 /**************************
650 * now for the Linux driver
652 **************************/
654 /* NOTE: the DLCI driver deals with freeing the SKB!! */
655 static int sdla_transmit(struct sk_buff *skb, struct net_device *dev)
657 struct frad_local *flp;
658 int ret, addr, accept, i;
661 struct buf_entry *pbuf;
667 netif_stop_queue(dev);
670 * stupid GateD insists on setting up the multicast router thru us
671 * and we're ill equipped to handle a non Frame Relay packet at this
679 if (skb->dev->type != ARPHRD_DLCI)
681 printk(KERN_WARNING "%s: Non DLCI device, type %i, tried to send on FRAD module.\n", dev->name, skb->dev->type);
686 printk(KERN_WARNING "%s: unknown firmware type 0x%4.4X\n", dev->name, dev->type);
692 /* this is frame specific, but till there's a PPP module, it's the default */
697 ret = sdla_cmd(dev, SDLA_INFORMATION_WRITE, *(short *)(skb->dev->dev_addr), 0, skb->data, skb->len, NULL, NULL);
701 ret = sdla_cmd(dev, SDLA_INFORMATION_WRITE, *(short *)(skb->dev->dev_addr), 0, NULL, skb->len, &addr, &size);
702 if (ret == SDLA_RET_OK)
705 spin_lock_irqsave(&sdla_lock, flags);
706 SDLA_WINDOW(dev, addr);
707 pbuf = (void *)(((int) dev->mem_start) + (addr & SDLA_ADDR_MASK));
708 __sdla_write(dev, pbuf->buf_addr, skb->data, skb->len);
709 SDLA_WINDOW(dev, addr);
711 spin_unlock_irqrestore(&sdla_lock, flags);
718 flp->stats.tx_packets++;
722 case SDLA_RET_CIR_OVERFLOW:
723 case SDLA_RET_BUF_OVERSIZE:
724 case SDLA_RET_NO_BUFS:
725 flp->stats.tx_dropped++;
730 flp->stats.tx_errors++;
735 netif_wake_queue(dev);
736 for(i=0;i<CONFIG_DLCI_MAX;i++)
738 if(flp->master[i]!=NULL)
739 netif_wake_queue(flp->master[i]);
744 static void sdla_receive(struct net_device *dev)
746 struct net_device *master;
747 struct frad_local *flp;
748 struct dlci_local *dlp;
751 struct sdla_cmd *cmd;
752 struct buf_info *pbufi;
753 struct buf_entry *pbuf;
756 int i=0, received, success, addr, buf_base, buf_top;
757 short dlci, len, len2, split;
761 received = addr = buf_top = buf_base = 0;
769 spin_lock_irqsave(&sdla_lock, flags);
775 cmd = (void *) (dev->mem_start + (SDLA_502_RCV_BUF & SDLA_ADDR_MASK));
776 SDLA_WINDOW(dev, SDLA_502_RCV_BUF);
777 success = cmd->opp_flag;
786 pbufi = (void *) (dev->mem_start + (SDLA_508_RXBUF_INFO & SDLA_ADDR_MASK));
787 SDLA_WINDOW(dev, SDLA_508_RXBUF_INFO);
788 pbuf = (void *) (dev->mem_start + ((pbufi->rse_base + flp->buffer * sizeof(struct buf_entry)) & SDLA_ADDR_MASK));
789 success = pbuf->opp_flag;
793 buf_top = pbufi->buf_top;
794 buf_base = pbufi->buf_base;
797 addr = pbuf->buf_addr;
801 /* common code, find the DLCI and get the SKB */
804 for (i=0;i<CONFIG_DLCI_MAX;i++)
805 if (flp->dlci[i] == dlci)
808 if (i == CONFIG_DLCI_MAX)
810 printk(KERN_NOTICE "%s: Received packet from invalid DLCI %i, ignoring.", dev->name, dlci);
811 flp->stats.rx_errors++;
818 master = flp->master[i];
819 skb = dev_alloc_skb(len + sizeof(struct frhdr));
822 printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n", dev->name);
823 flp->stats.rx_dropped++;
827 skb_reserve(skb, sizeof(struct frhdr));
830 /* pick up the data */
836 __sdla_read(dev, SDLA_502_RCV_BUF + SDLA_502_DATA_OFS, skb_put(skb,len), len);
838 SDLA_WINDOW(dev, SDLA_502_RCV_BUF);
845 /* is this buffer split off the end of the internal ring buffer */
846 split = addr + len > buf_top + 1 ? len - (buf_top - addr + 1) : 0;
849 __sdla_read(dev, addr, skb_put(skb, len2), len2);
851 __sdla_read(dev, buf_base, skb_put(skb, split), split);
854 /* increment the buffer we're looking at */
855 SDLA_WINDOW(dev, SDLA_508_RXBUF_INFO);
856 flp->buffer = (flp->buffer + 1) % pbufi->rse_num;
863 flp->stats.rx_packets++;
865 (*dlp->receive)(skb, master);
868 spin_unlock_irqrestore(&sdla_lock, flags);
871 static irqreturn_t sdla_isr(int irq, void *dev_id, struct pt_regs * regs)
873 struct net_device *dev;
874 struct frad_local *flp;
881 printk(KERN_WARNING "sdla_isr(): irq %d for unknown device.\n", irq);
887 if (!flp->initialized)
889 printk(KERN_WARNING "%s: irq %d for uninitialized device.\n", dev->name, irq);
893 byte = sdla_byte(dev, flp->type == SDLA_S508 ? SDLA_508_IRQ_INTERFACE : SDLA_502_IRQ_INTERFACE);
900 /* the command will get an error return, which is processed above */
901 case SDLA_INTR_MODEM:
902 case SDLA_INTR_STATUS:
903 sdla_cmd(dev, SDLA_READ_DLC_STATUS, 0, 0, NULL, 0, NULL, NULL);
907 case SDLA_INTR_COMPLETE:
908 case SDLA_INTR_TIMER:
909 printk(KERN_WARNING "%s: invalid irq flag 0x%02X.\n", dev->name, byte);
913 /* the S502E requires a manual acknowledgement of the interrupt */
914 if (flp->type == SDLA_S502E)
916 flp->state &= ~SDLA_S502E_INTACK;
917 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
918 flp->state |= SDLA_S502E_INTACK;
919 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
922 /* this clears the byte, informing the Z80 we're done */
924 sdla_write(dev, flp->type == SDLA_S508 ? SDLA_508_IRQ_INTERFACE : SDLA_502_IRQ_INTERFACE, &byte, sizeof(byte));
928 static void sdla_poll(unsigned long device)
930 struct net_device *dev;
931 struct frad_local *flp;
933 dev = (struct net_device *) device;
936 if (sdla_byte(dev, SDLA_502_RCV_BUF))
939 flp->timer.expires = 1;
940 add_timer(&flp->timer);
943 static int sdla_close(struct net_device *dev)
945 struct frad_local *flp;
946 struct intr_info intr;
948 short dlcis[CONFIG_DLCI_MAX];
953 for(i=0;i<CONFIG_DLCI_MAX;i++)
955 dlcis[len++] = abs(flp->dlci[i]);
958 if (flp->config.station == FRAD_STATION_NODE)
960 for(i=0;i<CONFIG_DLCI_MAX;i++)
961 if (flp->dlci[i] > 0)
962 sdla_cmd(dev, SDLA_DEACTIVATE_DLCI, 0, 0, dlcis, len, NULL, NULL);
963 sdla_cmd(dev, SDLA_DELETE_DLCI, 0, 0, &flp->dlci[i], sizeof(flp->dlci[i]), NULL, NULL);
966 memset(&intr, 0, sizeof(intr));
967 /* let's start up the reception */
971 del_timer(&flp->timer);
975 sdla_cmd(dev, SDLA_SET_IRQ_TRIGGER, 0, 0, &intr, sizeof(char) + sizeof(short), NULL, NULL);
976 flp->state &= ~SDLA_S502E_INTACK;
977 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
984 sdla_cmd(dev, SDLA_SET_IRQ_TRIGGER, 0, 0, &intr, sizeof(struct intr_info), NULL, NULL);
985 flp->state &= ~SDLA_S508_INTEN;
986 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
990 sdla_cmd(dev, SDLA_DISABLE_COMMUNICATIONS, 0, 0, NULL, 0, NULL, NULL);
992 netif_stop_queue(dev);
998 struct frad_conf config;
999 short dlci[CONFIG_DLCI_MAX];
1002 static int sdla_open(struct net_device *dev)
1004 struct frad_local *flp;
1005 struct dlci_local *dlp;
1006 struct conf_data data;
1007 struct intr_info intr;
1013 if (!flp->initialized)
1016 if (!flp->configured)
1019 /* time to send in the configuration */
1021 for(i=0;i<CONFIG_DLCI_MAX;i++)
1023 data.dlci[len++] = abs(flp->dlci[i]);
1026 memcpy(&data.config, &flp->config, sizeof(struct frad_conf));
1027 len += sizeof(struct frad_conf);
1029 sdla_cmd(dev, SDLA_DISABLE_COMMUNICATIONS, 0, 0, NULL, 0, NULL, NULL);
1030 sdla_cmd(dev, SDLA_SET_DLCI_CONFIGURATION, 0, 0, &data, len, NULL, NULL);
1032 if (flp->type == SDLA_S508)
1035 sdla_cmd(dev, SDLA_ENABLE_COMMUNICATIONS, 0, 0, NULL, 0, NULL, NULL);
1037 /* let's start up the reception */
1038 memset(&intr, 0, sizeof(intr));
1042 flp->timer.expires = 1;
1043 add_timer(&flp->timer);
1047 flp->state |= SDLA_S502E_ENABLE;
1048 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
1049 flp->state |= SDLA_S502E_INTACK;
1050 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
1052 sdla_write(dev, SDLA_502_IRQ_INTERFACE, &byte, sizeof(byte));
1053 intr.flags = SDLA_INTR_RX | SDLA_INTR_STATUS | SDLA_INTR_MODEM;
1054 sdla_cmd(dev, SDLA_SET_IRQ_TRIGGER, 0, 0, &intr, sizeof(char) + sizeof(short), NULL, NULL);
1061 flp->state |= SDLA_S508_INTEN;
1062 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
1064 sdla_write(dev, SDLA_508_IRQ_INTERFACE, &byte, sizeof(byte));
1065 intr.flags = SDLA_INTR_RX | SDLA_INTR_STATUS | SDLA_INTR_MODEM;
1066 intr.irq = dev->irq;
1067 sdla_cmd(dev, SDLA_SET_IRQ_TRIGGER, 0, 0, &intr, sizeof(struct intr_info), NULL, NULL);
1071 if (flp->config.station == FRAD_STATION_CPE)
1073 byte = SDLA_ICS_STATUS_ENQ;
1074 sdla_cmd(dev, SDLA_ISSUE_IN_CHANNEL_SIGNAL, 0, 0, &byte, sizeof(byte), NULL, NULL);
1078 sdla_cmd(dev, SDLA_ADD_DLCI, 0, 0, data.dlci, len - sizeof(struct frad_conf), NULL, NULL);
1079 for(i=0;i<CONFIG_DLCI_MAX;i++)
1080 if (flp->dlci[i] > 0)
1081 sdla_cmd(dev, SDLA_ACTIVATE_DLCI, 0, 0, &flp->dlci[i], 2*sizeof(flp->dlci[i]), NULL, NULL);
1084 /* configure any specific DLCI settings */
1085 for(i=0;i<CONFIG_DLCI_MAX;i++)
1088 dlp = flp->master[i]->priv;
1089 if (dlp->configured)
1090 sdla_cmd(dev, SDLA_SET_DLCI_CONFIGURATION, abs(flp->dlci[i]), 0, &dlp->config, sizeof(struct dlci_conf), NULL, NULL);
1093 netif_start_queue(dev);
1098 static int sdla_config(struct net_device *dev, struct frad_conf __user *conf, int get)
1100 struct frad_local *flp;
1101 struct conf_data data;
1105 if (dev->type == 0xFFFF)
1112 if (netif_running(dev))
1115 if(copy_from_user(&data.config, conf, sizeof(struct frad_conf)))
1118 if (data.config.station & ~FRAD_STATION_NODE)
1121 if (data.config.flags & ~FRAD_VALID_FLAGS)
1124 if ((data.config.kbaud < 0) ||
1125 ((data.config.kbaud > 128) && (flp->type != SDLA_S508)))
1128 if (data.config.clocking & ~(FRAD_CLOCK_INT | SDLA_S508_PORT_RS232))
1131 if ((data.config.mtu < 0) || (data.config.mtu > SDLA_MAX_MTU))
1134 if ((data.config.T391 < 5) || (data.config.T391 > 30))
1137 if ((data.config.T392 < 5) || (data.config.T392 > 30))
1140 if ((data.config.N391 < 1) || (data.config.N391 > 255))
1143 if ((data.config.N392 < 1) || (data.config.N392 > 10))
1146 if ((data.config.N393 < 1) || (data.config.N393 > 10))
1149 memcpy(&flp->config, &data.config, sizeof(struct frad_conf));
1150 flp->config.flags |= SDLA_DIRECT_RECV;
1152 if (flp->type == SDLA_S508)
1153 flp->config.flags |= SDLA_TX70_RX30;
1155 if (dev->mtu != flp->config.mtu)
1157 /* this is required to change the MTU */
1158 dev->mtu = flp->config.mtu;
1159 for(i=0;i<CONFIG_DLCI_MAX;i++)
1161 flp->master[i]->mtu = flp->config.mtu;
1164 flp->config.mtu += sizeof(struct frhdr);
1166 /* off to the races! */
1167 if (!flp->configured)
1170 flp->configured = 1;
1174 /* no sense reading if the CPU isn't started */
1175 if (netif_running(dev))
1177 size = sizeof(data);
1178 if (sdla_cmd(dev, SDLA_READ_DLCI_CONFIGURATION, 0, 0, NULL, 0, &data, &size) != SDLA_RET_OK)
1182 if (flp->configured)
1183 memcpy(&data.config, &flp->config, sizeof(struct frad_conf));
1185 memset(&data.config, 0, sizeof(struct frad_conf));
1187 memcpy(&flp->config, &data.config, sizeof(struct frad_conf));
1188 data.config.flags &= FRAD_VALID_FLAGS;
1189 data.config.mtu -= data.config.mtu > sizeof(struct frhdr) ? sizeof(struct frhdr) : data.config.mtu;
1190 return copy_to_user(conf, &data.config, sizeof(struct frad_conf))?-EFAULT:0;
1196 static int sdla_xfer(struct net_device *dev, struct sdla_mem __user *info, int read)
1198 struct sdla_mem mem;
1201 if(copy_from_user(&mem, info, sizeof(mem)))
1206 temp = kmalloc(mem.len, GFP_KERNEL);
1209 memset(temp, 0, mem.len);
1210 sdla_read(dev, mem.addr, temp, mem.len);
1211 if(copy_to_user(mem.data, temp, mem.len))
1220 temp = kmalloc(mem.len, GFP_KERNEL);
1223 if(copy_from_user(temp, mem.data, mem.len))
1228 sdla_write(dev, mem.addr, temp, mem.len);
1234 static int sdla_reconfig(struct net_device *dev)
1236 struct frad_local *flp;
1237 struct conf_data data;
1243 for(i=0;i<CONFIG_DLCI_MAX;i++)
1245 data.dlci[len++] = flp->dlci[i];
1248 memcpy(&data, &flp->config, sizeof(struct frad_conf));
1249 len += sizeof(struct frad_conf);
1251 sdla_cmd(dev, SDLA_DISABLE_COMMUNICATIONS, 0, 0, NULL, 0, NULL, NULL);
1252 sdla_cmd(dev, SDLA_SET_DLCI_CONFIGURATION, 0, 0, &data, len, NULL, NULL);
1253 sdla_cmd(dev, SDLA_ENABLE_COMMUNICATIONS, 0, 0, NULL, 0, NULL, NULL);
1258 static int sdla_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1260 struct frad_local *flp;
1262 if(!capable(CAP_NET_ADMIN))
1267 if (!flp->initialized)
1274 return(sdla_config(dev, ifr->ifr_data, cmd == FRAD_GET_CONF));
1277 ifr->ifr_flags = flp->type;
1281 return(sdla_cpuspeed(dev, ifr));
1283 /* ==========================================================
1284 NOTE: This is rather a useless action right now, as the
1285 current driver does not support protocols other than
1286 FR. However, Sangoma has modules for a number of
1287 other protocols in the works.
1288 ============================================================*/
1290 if (flp->configured)
1293 switch (ifr->ifr_flags)
1296 dev->type = ifr->ifr_flags;
1299 return(-ENOPROTOOPT);
1309 if(!capable(CAP_SYS_RAWIO))
1311 return(sdla_xfer(dev, ifr->ifr_data, cmd == SDLA_READMEM));
1322 return(-EOPNOTSUPP);
1327 int sdla_change_mtu(struct net_device *dev, int new_mtu)
1329 struct frad_local *flp;
1333 if (netif_running(dev))
1336 /* for now, you can't change the MTU! */
1337 return(-EOPNOTSUPP);
1340 int sdla_set_config(struct net_device *dev, struct ifmap *map)
1342 struct frad_local *flp;
1350 if (flp->initialized)
1353 for(i=0;i < sizeof(valid_port) / sizeof (int) ; i++)
1354 if (valid_port[i] == map->base_addr)
1357 if (i == sizeof(valid_port) / sizeof(int))
1360 if (!request_region(map->base_addr, SDLA_IO_EXTENTS, dev->name)){
1361 printk(KERN_WARNING "SDLA: io-port 0x%04lx in use \n", dev->base_addr);
1364 base = map->base_addr;
1366 /* test for card types, S502A, S502E, S507, S508 */
1367 /* these tests shut down the card completely, so clear the state */
1368 flp->type = SDLA_UNKNOWN;
1371 for(i=1;i<SDLA_IO_EXTENTS;i++)
1372 if (inb(base + i) != 0xFF)
1375 if (i == SDLA_IO_EXTENTS) {
1376 outb(SDLA_HALT, base + SDLA_REG_Z80_CONTROL);
1377 if ((inb(base + SDLA_S502_STS) & 0x0F) == 0x08) {
1378 outb(SDLA_S502E_INTACK, base + SDLA_REG_CONTROL);
1379 if ((inb(base + SDLA_S502_STS) & 0x0F) == 0x0C) {
1380 outb(SDLA_HALT, base + SDLA_REG_CONTROL);
1381 flp->type = SDLA_S502E;
1387 for(byte=inb(base),i=0;i<SDLA_IO_EXTENTS;i++)
1388 if (inb(base + i) != byte)
1391 if (i == SDLA_IO_EXTENTS) {
1392 outb(SDLA_HALT, base + SDLA_REG_CONTROL);
1393 if ((inb(base + SDLA_S502_STS) & 0x7E) == 0x30) {
1394 outb(SDLA_S507_ENABLE, base + SDLA_REG_CONTROL);
1395 if ((inb(base + SDLA_S502_STS) & 0x7E) == 0x32) {
1396 outb(SDLA_HALT, base + SDLA_REG_CONTROL);
1397 flp->type = SDLA_S507;
1403 outb(SDLA_HALT, base + SDLA_REG_CONTROL);
1404 if ((inb(base + SDLA_S508_STS) & 0x3F) == 0x00) {
1405 outb(SDLA_S508_INTEN, base + SDLA_REG_CONTROL);
1406 if ((inb(base + SDLA_S508_STS) & 0x3F) == 0x10) {
1407 outb(SDLA_HALT, base + SDLA_REG_CONTROL);
1408 flp->type = SDLA_S508;
1413 outb(SDLA_S502A_HALT, base + SDLA_REG_CONTROL);
1414 if (inb(base + SDLA_S502_STS) == 0x40) {
1415 outb(SDLA_S502A_START, base + SDLA_REG_CONTROL);
1416 if (inb(base + SDLA_S502_STS) == 0x40) {
1417 outb(SDLA_S502A_INTEN, base + SDLA_REG_CONTROL);
1418 if (inb(base + SDLA_S502_STS) == 0x44) {
1419 outb(SDLA_S502A_START, base + SDLA_REG_CONTROL);
1420 flp->type = SDLA_S502A;
1426 printk(KERN_NOTICE "%s: Unknown card type\n", dev->name);
1436 if (flp->type != SDLA_S508 && flp->type != SDLA_S507)
1442 if (flp->type != SDLA_S502E)
1451 if (flp->type != SDLA_S508 && flp->type != SDLA_S507)
1457 if (flp->type == SDLA_S502A)
1466 if (request_irq(dev->irq, &sdla_isr, 0, dev->name, dev))
1469 if (flp->type == SDLA_S507) {
1472 flp->state = SDLA_S507_IRQ3;
1475 flp->state = SDLA_S507_IRQ4;
1478 flp->state = SDLA_S507_IRQ5;
1481 flp->state = SDLA_S507_IRQ7;
1484 flp->state = SDLA_S507_IRQ10;
1487 flp->state = SDLA_S507_IRQ11;
1490 flp->state = SDLA_S507_IRQ12;
1493 flp->state = SDLA_S507_IRQ15;
1498 for(i=0;i < sizeof(valid_mem) / sizeof (int) ; i++)
1499 if (valid_mem[i] == map->mem_start)
1503 if (i == sizeof(valid_mem) / sizeof(int))
1506 if (flp->type == SDLA_S502A && (map->mem_start & 0xF000) >> 12 == 0x0E)
1509 if (flp->type != SDLA_S507 && map->mem_start >> 16 == 0x0B)
1512 if (flp->type == SDLA_S507 && map->mem_start >> 16 == 0x0D)
1515 byte = flp->type != SDLA_S508 ? SDLA_8K_WINDOW : 0;
1516 byte |= (map->mem_start & 0xF000) >> (12 + (flp->type == SDLA_S508 ? 1 : 0));
1520 switch (map->mem_start >> 16) {
1522 byte |= SDLA_S502_SEG_A;
1525 byte |= SDLA_S502_SEG_C;
1528 byte |= SDLA_S502_SEG_D;
1531 byte |= SDLA_S502_SEG_E;
1536 switch (map->mem_start >> 16) {
1538 byte |= SDLA_S507_SEG_A;
1541 byte |= SDLA_S507_SEG_B;
1544 byte |= SDLA_S507_SEG_C;
1547 byte |= SDLA_S507_SEG_E;
1552 switch (map->mem_start >> 16) {
1554 byte |= SDLA_S508_SEG_A;
1557 byte |= SDLA_S508_SEG_C;
1560 byte |= SDLA_S508_SEG_D;
1563 byte |= SDLA_S508_SEG_E;
1569 /* set the memory bits, and enable access */
1570 outb(byte, base + SDLA_REG_PC_WINDOW);
1575 flp->state = SDLA_S502E_ENABLE;
1578 flp->state |= SDLA_MEMEN;
1581 flp->state = SDLA_MEMEN;
1584 outb(flp->state, base + SDLA_REG_CONTROL);
1586 dev->irq = map->irq;
1587 dev->base_addr = base;
1588 dev->mem_start = map->mem_start;
1589 dev->mem_end = dev->mem_start + 0x2000;
1590 flp->initialized = 1;
1594 free_irq(map->irq, dev);
1596 release_region(base, SDLA_IO_EXTENTS);
1600 static struct net_device_stats *sdla_stats(struct net_device *dev)
1602 struct frad_local *flp;
1605 return(&flp->stats);
1608 static void setup_sdla(struct net_device *dev)
1610 struct frad_local *flp = dev->priv;
1612 netdev_boot_setup_check(dev);
1614 SET_MODULE_OWNER(dev);
1617 dev->hard_header_len = 0;
1619 dev->mtu = SDLA_MAX_MTU;
1621 dev->open = sdla_open;
1622 dev->stop = sdla_close;
1623 dev->do_ioctl = sdla_ioctl;
1624 dev->set_config = sdla_set_config;
1625 dev->get_stats = sdla_stats;
1626 dev->hard_start_xmit = sdla_transmit;
1627 dev->change_mtu = sdla_change_mtu;
1629 flp->activate = sdla_activate;
1630 flp->deactivate = sdla_deactivate;
1631 flp->assoc = sdla_assoc;
1632 flp->deassoc = sdla_deassoc;
1633 flp->dlci_conf = sdla_dlci_conf;
1635 init_timer(&flp->timer);
1636 flp->timer.expires = 1;
1637 flp->timer.data = (unsigned long) dev;
1638 flp->timer.function = sdla_poll;
1641 static struct net_device *sdla;
1643 static int __init init_sdla(void)
1647 printk("%s.\n", version);
1649 sdla = alloc_netdev(sizeof(struct frad_local), "sdla0", setup_sdla);
1653 err = register_netdev(sdla);
1660 static void __exit exit_sdla(void)
1662 struct frad_local *flp = sdla->priv;
1664 unregister_netdev(sdla);
1665 if (flp->initialized) {
1666 free_irq(sdla->irq, sdla);
1667 release_region(sdla->base_addr, SDLA_IO_EXTENTS);
1669 del_timer_sync(&flp->timer);
1673 MODULE_LICENSE("GPL");
1675 module_init(init_sdla);
1676 module_exit(exit_sdla);