Linux 4.16.11
[linux/fpc-iii.git] / drivers / net / wan / sdla.c
blob57ed259c8208d32474912a144e735cae74992fe6
1 /*
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
11 * period of time.
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>
19 * Changes:
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
23 * non DLCI devices.
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
27 * ifconfig
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 #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>
41 #include <linux/interrupt.h>
42 #include <linux/ptrace.h>
43 #include <linux/ioport.h>
44 #include <linux/in.h>
45 #include <linux/slab.h>
46 #include <linux/string.h>
47 #include <linux/timer.h>
48 #include <linux/errno.h>
49 #include <linux/init.h>
50 #include <linux/netdevice.h>
51 #include <linux/skbuff.h>
52 #include <linux/if_arp.h>
53 #include <linux/if_frad.h>
54 #include <linux/sdla.h>
55 #include <linux/bitops.h>
57 #include <asm/io.h>
58 #include <asm/dma.h>
59 #include <linux/uaccess.h>
61 static const char* version = "SDLA driver v0.30, 12 Sep 1996, mike.mclagan@linux.org";
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};
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)
84 char *temp;
85 const void *base;
86 int offset, bytes;
88 temp = buf;
89 while(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);
98 addr += bytes;
99 temp += bytes;
100 len -= bytes;
104 static void sdla_read(struct net_device *dev, int addr, void *buf, short len)
106 unsigned long flags;
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)
115 const char *temp;
116 void *base;
117 int offset, bytes;
119 temp = buf;
120 while(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);
129 addr += bytes;
130 temp += bytes;
131 len -= bytes;
135 static void sdla_write(struct net_device *dev, int addr,
136 const void *buf, short len)
138 unsigned long flags;
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)
148 unsigned long flags;
149 char *base;
150 int len, addr, bytes;
152 len = 65536;
153 addr = 0;
154 bytes = SDLA_WINDOW_SIZE;
155 base = (void *) dev->mem_start;
157 spin_lock_irqsave(&sdla_lock, flags);
158 while(len)
160 SDLA_WINDOW(dev, addr);
161 memset(base, 0, bytes);
163 addr += bytes;
164 len -= bytes;
166 spin_unlock_irqrestore(&sdla_lock, flags);
170 static char sdla_byte(struct net_device *dev, int addr)
172 unsigned long flags;
173 char byte, *temp;
175 temp = (void *) (dev->mem_start + (addr & SDLA_ADDR_MASK));
177 spin_lock_irqsave(&sdla_lock, flags);
178 SDLA_WINDOW(dev, addr);
179 byte = *temp;
180 spin_unlock_irqrestore(&sdla_lock, flags);
182 return byte;
185 static void sdla_stop(struct net_device *dev)
187 struct frad_local *flp;
189 flp = netdev_priv(dev);
190 switch(flp->type)
192 case SDLA_S502A:
193 outb(SDLA_S502A_HALT, dev->base_addr + SDLA_REG_CONTROL);
194 flp->state = SDLA_HALT;
195 break;
196 case SDLA_S502E:
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;
200 break;
201 case SDLA_S507:
202 flp->state &= ~SDLA_CPUEN;
203 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
204 break;
205 case SDLA_S508:
206 flp->state &= ~SDLA_CPUEN;
207 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
208 break;
212 static void sdla_start(struct net_device *dev)
214 struct frad_local *flp;
216 flp = netdev_priv(dev);
217 switch(flp->type)
219 case SDLA_S502A:
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;
223 break;
224 case SDLA_S502E:
225 outb(SDLA_S502E_CPUEN, dev->base_addr + SDLA_REG_Z80_CONTROL);
226 outb(0x00, dev->base_addr + SDLA_REG_CONTROL);
227 flp->state = 0;
228 break;
229 case SDLA_S507:
230 flp->state |= SDLA_CPUEN;
231 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
232 break;
233 case SDLA_S508:
234 flp->state |= SDLA_CPUEN;
235 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
236 break;
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 static int sdla_z80_poll(struct net_device *dev, int z80_addr, int jiffs, char resp1, char resp2)
252 unsigned long start, done, now;
253 char resp, *temp;
255 start = now = jiffies;
256 done = jiffies + jiffs;
258 temp = (void *)dev->mem_start;
259 temp += z80_addr & SDLA_ADDR_MASK;
261 resp = ~resp1;
262 while (time_before(jiffies, done) && (resp != resp1) && (!resp2 || (resp != resp2)))
264 if (jiffies != now)
266 SDLA_WINDOW(dev, z80_addr);
267 now = jiffies;
268 resp = *temp;
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)
282 int jiffs;
283 char data;
285 sdla_start(dev);
286 if (sdla_z80_poll(dev, 0, 3*HZ, Z80_READY, 0) < 0)
287 return -EIO;
289 data = LOADER_READY;
290 sdla_write(dev, 0, &data, 1);
292 if ((jiffs = sdla_z80_poll(dev, 0, 8*HZ, Z80_SCC_OK, Z80_SCC_BAD)) < 0)
293 return -EIO;
295 sdla_stop(dev);
296 sdla_read(dev, 0, &data, 1);
298 if (data == Z80_SCC_BAD)
300 printk("%s: SCC bad\n", dev->name);
301 return -EIO;
304 if (data != Z80_SCC_OK)
305 return -EINVAL;
307 if (jiffs < 165)
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;
317 else
318 ifr->ifr_mtu = SDLA_CPU_3M;
320 return 0;
323 /************************************************
325 * Direct interaction with the Frame Relay code
326 * starts here.
328 ************************************************/
330 struct _dlci_stat
332 short dlci;
333 char flags;
334 } __packed;
336 struct _frad_stat
338 char flags;
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;
345 short *pdlci;
346 int i;
347 char *state, line[30];
349 switch (ret)
351 case SDLA_RET_MODEM:
352 state = data;
353 if (*state & SDLA_MODEM_DCD_LOW)
354 netdev_info(dev, "Modem DCD unexpectedly low!\n");
355 if (*state & SDLA_MODEM_CTS_LOW)
356 netdev_info(dev, "Modem CTS unexpectedly low!\n");
357 /* I should probably do something about this! */
358 break;
360 case SDLA_RET_CHANNEL_OFF:
361 netdev_info(dev, "Channel became inoperative!\n");
362 /* same here */
363 break;
365 case SDLA_RET_CHANNEL_ON:
366 netdev_info(dev, "Channel became operative!\n");
367 /* same here */
368 break;
370 case SDLA_RET_DLCI_STATUS:
371 netdev_info(dev, "Status change reported by Access Node\n");
372 len /= sizeof(struct _dlci_stat);
373 for(pstatus = data, i=0;i < len;i++,pstatus++)
375 if (pstatus->flags & SDLA_DLCI_NEW)
376 state = "new";
377 else if (pstatus->flags & SDLA_DLCI_DELETED)
378 state = "deleted";
379 else if (pstatus->flags & SDLA_DLCI_ACTIVE)
380 state = "active";
381 else
383 sprintf(line, "unknown status: %02X", pstatus->flags);
384 state = line;
386 netdev_info(dev, "DLCI %i: %s\n",
387 pstatus->dlci, state);
388 /* same here */
390 break;
392 case SDLA_RET_DLCI_UNKNOWN:
393 netdev_info(dev, "Received unknown DLCIs:");
394 len /= sizeof(short);
395 for(pdlci = data,i=0;i < len;i++,pdlci++)
396 pr_cont(" %i", *pdlci);
397 pr_cont("\n");
398 break;
400 case SDLA_RET_TIMEOUT:
401 netdev_err(dev, "Command timed out!\n");
402 break;
404 case SDLA_RET_BUF_OVERSIZE:
405 netdev_info(dev, "Bc/CIR overflow, acceptable size is %i\n",
406 len);
407 break;
409 case SDLA_RET_BUF_TOO_BIG:
410 netdev_info(dev, "Buffer size over specified max of %i\n",
411 len);
412 break;
414 case SDLA_RET_CHANNEL_INACTIVE:
415 case SDLA_RET_DLCI_INACTIVE:
416 case SDLA_RET_CIR_OVERFLOW:
417 case SDLA_RET_NO_BUFS:
418 if (cmd == SDLA_INFORMATION_WRITE)
419 break;
421 default:
422 netdev_dbg(dev, "Cmd 0x%02X generated return code 0x%02X\n",
423 cmd, ret);
424 /* Further processing could be done here */
425 break;
429 static int sdla_cmd(struct net_device *dev, int cmd, short dlci, short flags,
430 void *inbuf, short inlen, void *outbuf, short *outlen)
432 static struct _frad_stat status;
433 struct frad_local *flp;
434 struct sdla_cmd *cmd_buf;
435 unsigned long pflags;
436 unsigned long jiffs;
437 int ret, waiting, len;
438 long window;
440 flp = netdev_priv(dev);
441 window = flp->type == SDLA_S508 ? SDLA_508_CMD_BUF : SDLA_502_CMD_BUF;
442 cmd_buf = (struct sdla_cmd *)(dev->mem_start + (window & SDLA_ADDR_MASK));
443 ret = 0;
444 len = 0;
445 jiffs = jiffies + HZ; /* 1 second is plenty */
447 spin_lock_irqsave(&sdla_lock, pflags);
448 SDLA_WINDOW(dev, window);
449 cmd_buf->cmd = cmd;
450 cmd_buf->dlci = dlci;
451 cmd_buf->flags = flags;
453 if (inbuf)
454 memcpy(cmd_buf->data, inbuf, inlen);
456 cmd_buf->length = inlen;
458 cmd_buf->opp_flag = 1;
459 spin_unlock_irqrestore(&sdla_lock, pflags);
461 waiting = 1;
462 len = 0;
463 while (waiting && time_before_eq(jiffies, jiffs))
465 if (waiting++ % 3)
467 spin_lock_irqsave(&sdla_lock, pflags);
468 SDLA_WINDOW(dev, window);
469 waiting = ((volatile int)(cmd_buf->opp_flag));
470 spin_unlock_irqrestore(&sdla_lock, pflags);
474 if (!waiting)
477 spin_lock_irqsave(&sdla_lock, pflags);
478 SDLA_WINDOW(dev, window);
479 ret = cmd_buf->retval;
480 len = cmd_buf->length;
481 if (outbuf && outlen)
483 *outlen = *outlen >= len ? len : *outlen;
485 if (*outlen)
486 memcpy(outbuf, cmd_buf->data, *outlen);
489 /* This is a local copy that's used for error handling */
490 if (ret)
491 memcpy(&status, cmd_buf->data, len > sizeof(status) ? sizeof(status) : len);
493 spin_unlock_irqrestore(&sdla_lock, pflags);
495 else
496 ret = SDLA_RET_TIMEOUT;
498 if (ret != SDLA_RET_OK)
499 sdla_errors(dev, cmd, dlci, ret, len, &status);
501 return ret;
504 /***********************************************
506 * these functions are called by the DLCI driver
508 ***********************************************/
510 static int sdla_reconfig(struct net_device *dev);
512 static int sdla_activate(struct net_device *slave, struct net_device *master)
514 struct frad_local *flp;
515 int i;
517 flp = netdev_priv(slave);
519 for(i=0;i<CONFIG_DLCI_MAX;i++)
520 if (flp->master[i] == master)
521 break;
523 if (i == CONFIG_DLCI_MAX)
524 return -ENODEV;
526 flp->dlci[i] = abs(flp->dlci[i]);
528 if (netif_running(slave) && (flp->config.station == FRAD_STATION_NODE))
529 sdla_cmd(slave, SDLA_ACTIVATE_DLCI, 0, 0, &flp->dlci[i], sizeof(short), NULL, NULL);
531 return 0;
534 static int sdla_deactivate(struct net_device *slave, struct net_device *master)
536 struct frad_local *flp;
537 int i;
539 flp = netdev_priv(slave);
541 for(i=0;i<CONFIG_DLCI_MAX;i++)
542 if (flp->master[i] == master)
543 break;
545 if (i == CONFIG_DLCI_MAX)
546 return -ENODEV;
548 flp->dlci[i] = -abs(flp->dlci[i]);
550 if (netif_running(slave) && (flp->config.station == FRAD_STATION_NODE))
551 sdla_cmd(slave, SDLA_DEACTIVATE_DLCI, 0, 0, &flp->dlci[i], sizeof(short), NULL, NULL);
553 return 0;
556 static int sdla_assoc(struct net_device *slave, struct net_device *master)
558 struct frad_local *flp;
559 int i;
561 if (master->type != ARPHRD_DLCI)
562 return -EINVAL;
564 flp = netdev_priv(slave);
566 for(i=0;i<CONFIG_DLCI_MAX;i++)
568 if (!flp->master[i])
569 break;
570 if (abs(flp->dlci[i]) == *(short *)(master->dev_addr))
571 return -EADDRINUSE;
574 if (i == CONFIG_DLCI_MAX)
575 return -EMLINK; /* #### Alan: Comments on this ?? */
578 flp->master[i] = master;
579 flp->dlci[i] = -*(short *)(master->dev_addr);
580 master->mtu = slave->mtu;
582 if (netif_running(slave)) {
583 if (flp->config.station == FRAD_STATION_CPE)
584 sdla_reconfig(slave);
585 else
586 sdla_cmd(slave, SDLA_ADD_DLCI, 0, 0, master->dev_addr, sizeof(short), NULL, NULL);
589 return 0;
592 static int sdla_deassoc(struct net_device *slave, struct net_device *master)
594 struct frad_local *flp;
595 int i;
597 flp = netdev_priv(slave);
599 for(i=0;i<CONFIG_DLCI_MAX;i++)
600 if (flp->master[i] == master)
601 break;
603 if (i == CONFIG_DLCI_MAX)
604 return -ENODEV;
606 flp->master[i] = NULL;
607 flp->dlci[i] = 0;
610 if (netif_running(slave)) {
611 if (flp->config.station == FRAD_STATION_CPE)
612 sdla_reconfig(slave);
613 else
614 sdla_cmd(slave, SDLA_DELETE_DLCI, 0, 0, master->dev_addr, sizeof(short), NULL, NULL);
617 return 0;
620 static int sdla_dlci_conf(struct net_device *slave, struct net_device *master, int get)
622 struct frad_local *flp;
623 struct dlci_local *dlp;
624 int i;
625 short len, ret;
627 flp = netdev_priv(slave);
629 for(i=0;i<CONFIG_DLCI_MAX;i++)
630 if (flp->master[i] == master)
631 break;
633 if (i == CONFIG_DLCI_MAX)
634 return -ENODEV;
636 dlp = netdev_priv(master);
638 ret = SDLA_RET_OK;
639 len = sizeof(struct dlci_conf);
640 if (netif_running(slave)) {
641 if (get)
642 ret = sdla_cmd(slave, SDLA_READ_DLCI_CONFIGURATION, abs(flp->dlci[i]), 0,
643 NULL, 0, &dlp->config, &len);
644 else
645 ret = sdla_cmd(slave, SDLA_SET_DLCI_CONFIGURATION, abs(flp->dlci[i]), 0,
646 &dlp->config, sizeof(struct dlci_conf) - 4 * sizeof(short), NULL, NULL);
649 return ret == SDLA_RET_OK ? 0 : -EIO;
652 /**************************
654 * now for the Linux driver
656 **************************/
658 /* NOTE: the DLCI driver deals with freeing the SKB!! */
659 static netdev_tx_t sdla_transmit(struct sk_buff *skb,
660 struct net_device *dev)
662 struct frad_local *flp;
663 int ret, addr, accept, i;
664 short size;
665 unsigned long flags;
666 struct buf_entry *pbuf;
668 flp = netdev_priv(dev);
669 ret = 0;
670 accept = 1;
672 netif_stop_queue(dev);
675 * stupid GateD insists on setting up the multicast router thru us
676 * and we're ill equipped to handle a non Frame Relay packet at this
677 * time!
680 accept = 1;
681 switch (dev->type)
683 case ARPHRD_FRAD:
684 if (skb->dev->type != ARPHRD_DLCI)
686 netdev_warn(dev, "Non DLCI device, type %i, tried to send on FRAD module\n",
687 skb->dev->type);
688 accept = 0;
690 break;
691 default:
692 netdev_warn(dev, "unknown firmware type 0x%04X\n",
693 dev->type);
694 accept = 0;
695 break;
697 if (accept)
699 /* this is frame specific, but till there's a PPP module, it's the default */
700 switch (flp->type)
702 case SDLA_S502A:
703 case SDLA_S502E:
704 ret = sdla_cmd(dev, SDLA_INFORMATION_WRITE, *(short *)(skb->dev->dev_addr), 0, skb->data, skb->len, NULL, NULL);
705 break;
706 case SDLA_S508:
707 size = sizeof(addr);
708 ret = sdla_cmd(dev, SDLA_INFORMATION_WRITE, *(short *)(skb->dev->dev_addr), 0, NULL, skb->len, &addr, &size);
709 if (ret == SDLA_RET_OK)
712 spin_lock_irqsave(&sdla_lock, flags);
713 SDLA_WINDOW(dev, addr);
714 pbuf = (void *)(((int) dev->mem_start) + (addr & SDLA_ADDR_MASK));
715 __sdla_write(dev, pbuf->buf_addr, skb->data, skb->len);
716 SDLA_WINDOW(dev, addr);
717 pbuf->opp_flag = 1;
718 spin_unlock_irqrestore(&sdla_lock, flags);
720 break;
723 switch (ret)
725 case SDLA_RET_OK:
726 dev->stats.tx_packets++;
727 break;
729 case SDLA_RET_CIR_OVERFLOW:
730 case SDLA_RET_BUF_OVERSIZE:
731 case SDLA_RET_NO_BUFS:
732 dev->stats.tx_dropped++;
733 break;
735 default:
736 dev->stats.tx_errors++;
737 break;
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]);
747 dev_kfree_skb(skb);
748 return NETDEV_TX_OK;
751 static void sdla_receive(struct net_device *dev)
753 struct net_device *master;
754 struct frad_local *flp;
755 struct dlci_local *dlp;
756 struct sk_buff *skb;
758 struct sdla_cmd *cmd;
759 struct buf_info *pbufi;
760 struct buf_entry *pbuf;
762 unsigned long flags;
763 int i=0, received, success, addr, buf_base, buf_top;
764 short dlci, len, len2, split;
766 flp = netdev_priv(dev);
767 success = 1;
768 received = addr = buf_top = buf_base = 0;
769 len = dlci = 0;
770 skb = NULL;
771 master = NULL;
772 cmd = NULL;
773 pbufi = NULL;
774 pbuf = NULL;
776 spin_lock_irqsave(&sdla_lock, flags);
778 switch (flp->type)
780 case SDLA_S502A:
781 case SDLA_S502E:
782 cmd = (void *) (dev->mem_start + (SDLA_502_RCV_BUF & SDLA_ADDR_MASK));
783 SDLA_WINDOW(dev, SDLA_502_RCV_BUF);
784 success = cmd->opp_flag;
785 if (!success)
786 break;
788 dlci = cmd->dlci;
789 len = cmd->length;
790 break;
792 case SDLA_S508:
793 pbufi = (void *) (dev->mem_start + (SDLA_508_RXBUF_INFO & SDLA_ADDR_MASK));
794 SDLA_WINDOW(dev, SDLA_508_RXBUF_INFO);
795 pbuf = (void *) (dev->mem_start + ((pbufi->rse_base + flp->buffer * sizeof(struct buf_entry)) & SDLA_ADDR_MASK));
796 success = pbuf->opp_flag;
797 if (!success)
798 break;
800 buf_top = pbufi->buf_top;
801 buf_base = pbufi->buf_base;
802 dlci = pbuf->dlci;
803 len = pbuf->length;
804 addr = pbuf->buf_addr;
805 break;
808 /* common code, find the DLCI and get the SKB */
809 if (success)
811 for (i=0;i<CONFIG_DLCI_MAX;i++)
812 if (flp->dlci[i] == dlci)
813 break;
815 if (i == CONFIG_DLCI_MAX)
817 netdev_notice(dev, "Received packet from invalid DLCI %i, ignoring\n",
818 dlci);
819 dev->stats.rx_errors++;
820 success = 0;
824 if (success)
826 master = flp->master[i];
827 skb = dev_alloc_skb(len + sizeof(struct frhdr));
828 if (skb == NULL)
830 netdev_notice(dev, "Memory squeeze, dropping packet\n");
831 dev->stats.rx_dropped++;
832 success = 0;
834 else
835 skb_reserve(skb, sizeof(struct frhdr));
838 /* pick up the data */
839 switch (flp->type)
841 case SDLA_S502A:
842 case SDLA_S502E:
843 if (success)
844 __sdla_read(dev, SDLA_502_RCV_BUF + SDLA_502_DATA_OFS, skb_put(skb,len), len);
846 SDLA_WINDOW(dev, SDLA_502_RCV_BUF);
847 cmd->opp_flag = 0;
848 break;
850 case SDLA_S508:
851 if (success)
853 /* is this buffer split off the end of the internal ring buffer */
854 split = addr + len > buf_top + 1 ? len - (buf_top - addr + 1) : 0;
855 len2 = len - split;
857 __sdla_read(dev, addr, skb_put(skb, len2), len2);
858 if (split)
859 __sdla_read(dev, buf_base, skb_put(skb, split), split);
862 /* increment the buffer we're looking at */
863 SDLA_WINDOW(dev, SDLA_508_RXBUF_INFO);
864 flp->buffer = (flp->buffer + 1) % pbufi->rse_num;
865 pbuf->opp_flag = 0;
866 break;
869 if (success)
871 dev->stats.rx_packets++;
872 dlp = netdev_priv(master);
873 (*dlp->receive)(skb, master);
876 spin_unlock_irqrestore(&sdla_lock, flags);
879 static irqreturn_t sdla_isr(int dummy, void *dev_id)
881 struct net_device *dev;
882 struct frad_local *flp;
883 char byte;
885 dev = dev_id;
887 flp = netdev_priv(dev);
889 if (!flp->initialized)
891 netdev_warn(dev, "irq %d for uninitialized device\n", dev->irq);
892 return IRQ_NONE;
895 byte = sdla_byte(dev, flp->type == SDLA_S508 ? SDLA_508_IRQ_INTERFACE : SDLA_502_IRQ_INTERFACE);
896 switch (byte)
898 case SDLA_INTR_RX:
899 sdla_receive(dev);
900 break;
902 /* the command will get an error return, which is processed above */
903 case SDLA_INTR_MODEM:
904 case SDLA_INTR_STATUS:
905 sdla_cmd(dev, SDLA_READ_DLC_STATUS, 0, 0, NULL, 0, NULL, NULL);
906 break;
908 case SDLA_INTR_TX:
909 case SDLA_INTR_COMPLETE:
910 case SDLA_INTR_TIMER:
911 netdev_warn(dev, "invalid irq flag 0x%02X\n", byte);
912 break;
915 /* the S502E requires a manual acknowledgement of the interrupt */
916 if (flp->type == SDLA_S502E)
918 flp->state &= ~SDLA_S502E_INTACK;
919 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
920 flp->state |= SDLA_S502E_INTACK;
921 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
924 /* this clears the byte, informing the Z80 we're done */
925 byte = 0;
926 sdla_write(dev, flp->type == SDLA_S508 ? SDLA_508_IRQ_INTERFACE : SDLA_502_IRQ_INTERFACE, &byte, sizeof(byte));
927 return IRQ_HANDLED;
930 static void sdla_poll(struct timer_list *t)
932 struct frad_local *flp = from_timer(flp, t, timer);
933 struct net_device *dev = flp->dev;
935 if (sdla_byte(dev, SDLA_502_RCV_BUF))
936 sdla_receive(dev);
938 flp->timer.expires = 1;
939 add_timer(&flp->timer);
942 static int sdla_close(struct net_device *dev)
944 struct frad_local *flp;
945 struct intr_info intr;
946 int len, i;
947 short dlcis[CONFIG_DLCI_MAX];
949 flp = netdev_priv(dev);
951 len = 0;
952 for(i=0;i<CONFIG_DLCI_MAX;i++)
953 if (flp->dlci[i])
954 dlcis[len++] = abs(flp->dlci[i]);
955 len *= 2;
957 if (flp->config.station == FRAD_STATION_NODE)
959 for(i=0;i<CONFIG_DLCI_MAX;i++)
960 if (flp->dlci[i] > 0)
961 sdla_cmd(dev, SDLA_DEACTIVATE_DLCI, 0, 0, dlcis, len, NULL, NULL);
962 sdla_cmd(dev, SDLA_DELETE_DLCI, 0, 0, &flp->dlci[i], sizeof(flp->dlci[i]), NULL, NULL);
965 memset(&intr, 0, sizeof(intr));
966 /* let's start up the reception */
967 switch(flp->type)
969 case SDLA_S502A:
970 del_timer(&flp->timer);
971 break;
973 case SDLA_S502E:
974 sdla_cmd(dev, SDLA_SET_IRQ_TRIGGER, 0, 0, &intr, sizeof(char) + sizeof(short), NULL, NULL);
975 flp->state &= ~SDLA_S502E_INTACK;
976 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
977 break;
979 case SDLA_S507:
980 break;
982 case SDLA_S508:
983 sdla_cmd(dev, SDLA_SET_IRQ_TRIGGER, 0, 0, &intr, sizeof(struct intr_info), NULL, NULL);
984 flp->state &= ~SDLA_S508_INTEN;
985 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
986 break;
989 sdla_cmd(dev, SDLA_DISABLE_COMMUNICATIONS, 0, 0, NULL, 0, NULL, NULL);
991 netif_stop_queue(dev);
993 return 0;
996 struct conf_data {
997 struct frad_conf config;
998 short dlci[CONFIG_DLCI_MAX];
1001 static int sdla_open(struct net_device *dev)
1003 struct frad_local *flp;
1004 struct dlci_local *dlp;
1005 struct conf_data data;
1006 struct intr_info intr;
1007 int len, i;
1008 char byte;
1010 flp = netdev_priv(dev);
1012 if (!flp->initialized)
1013 return -EPERM;
1015 if (!flp->configured)
1016 return -EPERM;
1018 /* time to send in the configuration */
1019 len = 0;
1020 for(i=0;i<CONFIG_DLCI_MAX;i++)
1021 if (flp->dlci[i])
1022 data.dlci[len++] = abs(flp->dlci[i]);
1023 len *= 2;
1025 memcpy(&data.config, &flp->config, sizeof(struct frad_conf));
1026 len += sizeof(struct frad_conf);
1028 sdla_cmd(dev, SDLA_DISABLE_COMMUNICATIONS, 0, 0, NULL, 0, NULL, NULL);
1029 sdla_cmd(dev, SDLA_SET_DLCI_CONFIGURATION, 0, 0, &data, len, NULL, NULL);
1031 if (flp->type == SDLA_S508)
1032 flp->buffer = 0;
1034 sdla_cmd(dev, SDLA_ENABLE_COMMUNICATIONS, 0, 0, NULL, 0, NULL, NULL);
1036 /* let's start up the reception */
1037 memset(&intr, 0, sizeof(intr));
1038 switch(flp->type)
1040 case SDLA_S502A:
1041 flp->timer.expires = 1;
1042 add_timer(&flp->timer);
1043 break;
1045 case SDLA_S502E:
1046 flp->state |= SDLA_S502E_ENABLE;
1047 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
1048 flp->state |= SDLA_S502E_INTACK;
1049 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
1050 byte = 0;
1051 sdla_write(dev, SDLA_502_IRQ_INTERFACE, &byte, sizeof(byte));
1052 intr.flags = SDLA_INTR_RX | SDLA_INTR_STATUS | SDLA_INTR_MODEM;
1053 sdla_cmd(dev, SDLA_SET_IRQ_TRIGGER, 0, 0, &intr, sizeof(char) + sizeof(short), NULL, NULL);
1054 break;
1056 case SDLA_S507:
1057 break;
1059 case SDLA_S508:
1060 flp->state |= SDLA_S508_INTEN;
1061 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
1062 byte = 0;
1063 sdla_write(dev, SDLA_508_IRQ_INTERFACE, &byte, sizeof(byte));
1064 intr.flags = SDLA_INTR_RX | SDLA_INTR_STATUS | SDLA_INTR_MODEM;
1065 intr.irq = dev->irq;
1066 sdla_cmd(dev, SDLA_SET_IRQ_TRIGGER, 0, 0, &intr, sizeof(struct intr_info), NULL, NULL);
1067 break;
1070 if (flp->config.station == FRAD_STATION_CPE)
1072 byte = SDLA_ICS_STATUS_ENQ;
1073 sdla_cmd(dev, SDLA_ISSUE_IN_CHANNEL_SIGNAL, 0, 0, &byte, sizeof(byte), NULL, NULL);
1075 else
1077 sdla_cmd(dev, SDLA_ADD_DLCI, 0, 0, data.dlci, len - sizeof(struct frad_conf), NULL, NULL);
1078 for(i=0;i<CONFIG_DLCI_MAX;i++)
1079 if (flp->dlci[i] > 0)
1080 sdla_cmd(dev, SDLA_ACTIVATE_DLCI, 0, 0, &flp->dlci[i], 2*sizeof(flp->dlci[i]), NULL, NULL);
1083 /* configure any specific DLCI settings */
1084 for(i=0;i<CONFIG_DLCI_MAX;i++)
1085 if (flp->dlci[i])
1087 dlp = netdev_priv(flp->master[i]);
1088 if (dlp->configured)
1089 sdla_cmd(dev, SDLA_SET_DLCI_CONFIGURATION, abs(flp->dlci[i]), 0, &dlp->config, sizeof(struct dlci_conf), NULL, NULL);
1092 netif_start_queue(dev);
1094 return 0;
1097 static int sdla_config(struct net_device *dev, struct frad_conf __user *conf, int get)
1099 struct frad_local *flp;
1100 struct conf_data data;
1101 int i;
1102 short size;
1104 if (dev->type == 0xFFFF)
1105 return -EUNATCH;
1107 flp = netdev_priv(dev);
1109 if (!get)
1111 if (netif_running(dev))
1112 return -EBUSY;
1114 if(copy_from_user(&data.config, conf, sizeof(struct frad_conf)))
1115 return -EFAULT;
1117 if (data.config.station & ~FRAD_STATION_NODE)
1118 return -EINVAL;
1120 if (data.config.flags & ~FRAD_VALID_FLAGS)
1121 return -EINVAL;
1123 if ((data.config.kbaud < 0) ||
1124 ((data.config.kbaud > 128) && (flp->type != SDLA_S508)))
1125 return -EINVAL;
1127 if (data.config.clocking & ~(FRAD_CLOCK_INT | SDLA_S508_PORT_RS232))
1128 return -EINVAL;
1130 if ((data.config.mtu < 0) || (data.config.mtu > SDLA_MAX_MTU))
1131 return -EINVAL;
1133 if ((data.config.T391 < 5) || (data.config.T391 > 30))
1134 return -EINVAL;
1136 if ((data.config.T392 < 5) || (data.config.T392 > 30))
1137 return -EINVAL;
1139 if ((data.config.N391 < 1) || (data.config.N391 > 255))
1140 return -EINVAL;
1142 if ((data.config.N392 < 1) || (data.config.N392 > 10))
1143 return -EINVAL;
1145 if ((data.config.N393 < 1) || (data.config.N393 > 10))
1146 return -EINVAL;
1148 memcpy(&flp->config, &data.config, sizeof(struct frad_conf));
1149 flp->config.flags |= SDLA_DIRECT_RECV;
1151 if (flp->type == SDLA_S508)
1152 flp->config.flags |= SDLA_TX70_RX30;
1154 if (dev->mtu != flp->config.mtu)
1156 /* this is required to change the MTU */
1157 dev->mtu = flp->config.mtu;
1158 for(i=0;i<CONFIG_DLCI_MAX;i++)
1159 if (flp->master[i])
1160 flp->master[i]->mtu = flp->config.mtu;
1163 flp->config.mtu += sizeof(struct frhdr);
1165 /* off to the races! */
1166 if (!flp->configured)
1167 sdla_start(dev);
1169 flp->configured = 1;
1171 else
1173 /* no sense reading if the CPU isn't started */
1174 if (netif_running(dev))
1176 size = sizeof(data);
1177 if (sdla_cmd(dev, SDLA_READ_DLCI_CONFIGURATION, 0, 0, NULL, 0, &data, &size) != SDLA_RET_OK)
1178 return -EIO;
1180 else
1181 if (flp->configured)
1182 memcpy(&data.config, &flp->config, sizeof(struct frad_conf));
1183 else
1184 memset(&data.config, 0, sizeof(struct frad_conf));
1186 memcpy(&flp->config, &data.config, sizeof(struct frad_conf));
1187 data.config.flags &= FRAD_VALID_FLAGS;
1188 data.config.mtu -= data.config.mtu > sizeof(struct frhdr) ? sizeof(struct frhdr) : data.config.mtu;
1189 return copy_to_user(conf, &data.config, sizeof(struct frad_conf))?-EFAULT:0;
1192 return 0;
1195 static int sdla_xfer(struct net_device *dev, struct sdla_mem __user *info, int read)
1197 struct sdla_mem mem;
1198 char *temp;
1200 if(copy_from_user(&mem, info, sizeof(mem)))
1201 return -EFAULT;
1203 if (read)
1205 temp = kzalloc(mem.len, GFP_KERNEL);
1206 if (!temp)
1207 return -ENOMEM;
1208 sdla_read(dev, mem.addr, temp, mem.len);
1209 if(copy_to_user(mem.data, temp, mem.len))
1211 kfree(temp);
1212 return -EFAULT;
1214 kfree(temp);
1216 else
1218 temp = memdup_user(mem.data, mem.len);
1219 if (IS_ERR(temp))
1220 return PTR_ERR(temp);
1221 sdla_write(dev, mem.addr, temp, mem.len);
1222 kfree(temp);
1224 return 0;
1227 static int sdla_reconfig(struct net_device *dev)
1229 struct frad_local *flp;
1230 struct conf_data data;
1231 int i, len;
1233 flp = netdev_priv(dev);
1235 len = 0;
1236 for(i=0;i<CONFIG_DLCI_MAX;i++)
1237 if (flp->dlci[i])
1238 data.dlci[len++] = flp->dlci[i];
1239 len *= 2;
1241 memcpy(&data, &flp->config, sizeof(struct frad_conf));
1242 len += sizeof(struct frad_conf);
1244 sdla_cmd(dev, SDLA_DISABLE_COMMUNICATIONS, 0, 0, NULL, 0, NULL, NULL);
1245 sdla_cmd(dev, SDLA_SET_DLCI_CONFIGURATION, 0, 0, &data, len, NULL, NULL);
1246 sdla_cmd(dev, SDLA_ENABLE_COMMUNICATIONS, 0, 0, NULL, 0, NULL, NULL);
1248 return 0;
1251 static int sdla_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1253 struct frad_local *flp;
1255 if(!capable(CAP_NET_ADMIN))
1256 return -EPERM;
1258 flp = netdev_priv(dev);
1260 if (!flp->initialized)
1261 return -EINVAL;
1263 switch (cmd)
1265 case FRAD_GET_CONF:
1266 case FRAD_SET_CONF:
1267 return sdla_config(dev, ifr->ifr_data, cmd == FRAD_GET_CONF);
1269 case SDLA_IDENTIFY:
1270 ifr->ifr_flags = flp->type;
1271 break;
1273 case SDLA_CPUSPEED:
1274 return sdla_cpuspeed(dev, ifr);
1276 /* ==========================================================
1277 NOTE: This is rather a useless action right now, as the
1278 current driver does not support protocols other than
1279 FR. However, Sangoma has modules for a number of
1280 other protocols in the works.
1281 ============================================================*/
1282 case SDLA_PROTOCOL:
1283 if (flp->configured)
1284 return -EALREADY;
1286 switch (ifr->ifr_flags)
1288 case ARPHRD_FRAD:
1289 dev->type = ifr->ifr_flags;
1290 break;
1291 default:
1292 return -ENOPROTOOPT;
1294 break;
1296 case SDLA_CLEARMEM:
1297 sdla_clear(dev);
1298 break;
1300 case SDLA_WRITEMEM:
1301 case SDLA_READMEM:
1302 if(!capable(CAP_SYS_RAWIO))
1303 return -EPERM;
1304 return sdla_xfer(dev, ifr->ifr_data, cmd == SDLA_READMEM);
1306 case SDLA_START:
1307 sdla_start(dev);
1308 break;
1310 case SDLA_STOP:
1311 sdla_stop(dev);
1312 break;
1314 default:
1315 return -EOPNOTSUPP;
1317 return 0;
1320 static int sdla_change_mtu(struct net_device *dev, int new_mtu)
1322 if (netif_running(dev))
1323 return -EBUSY;
1325 /* for now, you can't change the MTU! */
1326 return -EOPNOTSUPP;
1329 static int sdla_set_config(struct net_device *dev, struct ifmap *map)
1331 struct frad_local *flp;
1332 int i;
1333 char byte;
1334 unsigned base;
1335 int err = -EINVAL;
1337 flp = netdev_priv(dev);
1339 if (flp->initialized)
1340 return -EINVAL;
1342 for(i=0; i < ARRAY_SIZE(valid_port); i++)
1343 if (valid_port[i] == map->base_addr)
1344 break;
1346 if (i == ARRAY_SIZE(valid_port))
1347 return -EINVAL;
1349 if (!request_region(map->base_addr, SDLA_IO_EXTENTS, dev->name)){
1350 pr_warn("io-port 0x%04lx in use\n", dev->base_addr);
1351 return -EINVAL;
1353 base = map->base_addr;
1355 /* test for card types, S502A, S502E, S507, S508 */
1356 /* these tests shut down the card completely, so clear the state */
1357 flp->type = SDLA_UNKNOWN;
1358 flp->state = 0;
1360 for(i=1;i<SDLA_IO_EXTENTS;i++)
1361 if (inb(base + i) != 0xFF)
1362 break;
1364 if (i == SDLA_IO_EXTENTS) {
1365 outb(SDLA_HALT, base + SDLA_REG_Z80_CONTROL);
1366 if ((inb(base + SDLA_S502_STS) & 0x0F) == 0x08) {
1367 outb(SDLA_S502E_INTACK, base + SDLA_REG_CONTROL);
1368 if ((inb(base + SDLA_S502_STS) & 0x0F) == 0x0C) {
1369 outb(SDLA_HALT, base + SDLA_REG_CONTROL);
1370 flp->type = SDLA_S502E;
1371 goto got_type;
1376 for(byte=inb(base),i=0;i<SDLA_IO_EXTENTS;i++)
1377 if (inb(base + i) != byte)
1378 break;
1380 if (i == SDLA_IO_EXTENTS) {
1381 outb(SDLA_HALT, base + SDLA_REG_CONTROL);
1382 if ((inb(base + SDLA_S502_STS) & 0x7E) == 0x30) {
1383 outb(SDLA_S507_ENABLE, base + SDLA_REG_CONTROL);
1384 if ((inb(base + SDLA_S502_STS) & 0x7E) == 0x32) {
1385 outb(SDLA_HALT, base + SDLA_REG_CONTROL);
1386 flp->type = SDLA_S507;
1387 goto got_type;
1392 outb(SDLA_HALT, base + SDLA_REG_CONTROL);
1393 if ((inb(base + SDLA_S508_STS) & 0x3F) == 0x00) {
1394 outb(SDLA_S508_INTEN, base + SDLA_REG_CONTROL);
1395 if ((inb(base + SDLA_S508_STS) & 0x3F) == 0x10) {
1396 outb(SDLA_HALT, base + SDLA_REG_CONTROL);
1397 flp->type = SDLA_S508;
1398 goto got_type;
1402 outb(SDLA_S502A_HALT, base + SDLA_REG_CONTROL);
1403 if (inb(base + SDLA_S502_STS) == 0x40) {
1404 outb(SDLA_S502A_START, base + SDLA_REG_CONTROL);
1405 if (inb(base + SDLA_S502_STS) == 0x40) {
1406 outb(SDLA_S502A_INTEN, base + SDLA_REG_CONTROL);
1407 if (inb(base + SDLA_S502_STS) == 0x44) {
1408 outb(SDLA_S502A_START, base + SDLA_REG_CONTROL);
1409 flp->type = SDLA_S502A;
1410 goto got_type;
1415 netdev_notice(dev, "Unknown card type\n");
1416 err = -ENODEV;
1417 goto fail;
1419 got_type:
1420 switch(base) {
1421 case 0x270:
1422 case 0x280:
1423 case 0x380:
1424 case 0x390:
1425 if (flp->type != SDLA_S508 && flp->type != SDLA_S507)
1426 goto fail;
1429 switch (map->irq) {
1430 case 2:
1431 if (flp->type != SDLA_S502E)
1432 goto fail;
1433 break;
1435 case 10:
1436 case 11:
1437 case 12:
1438 case 15:
1439 case 4:
1440 if (flp->type != SDLA_S508 && flp->type != SDLA_S507)
1441 goto fail;
1442 break;
1443 case 3:
1444 case 5:
1445 case 7:
1446 if (flp->type == SDLA_S502A)
1447 goto fail;
1448 break;
1450 default:
1451 goto fail;
1454 err = -EAGAIN;
1455 if (request_irq(dev->irq, sdla_isr, 0, dev->name, dev))
1456 goto fail;
1458 if (flp->type == SDLA_S507) {
1459 switch(dev->irq) {
1460 case 3:
1461 flp->state = SDLA_S507_IRQ3;
1462 break;
1463 case 4:
1464 flp->state = SDLA_S507_IRQ4;
1465 break;
1466 case 5:
1467 flp->state = SDLA_S507_IRQ5;
1468 break;
1469 case 7:
1470 flp->state = SDLA_S507_IRQ7;
1471 break;
1472 case 10:
1473 flp->state = SDLA_S507_IRQ10;
1474 break;
1475 case 11:
1476 flp->state = SDLA_S507_IRQ11;
1477 break;
1478 case 12:
1479 flp->state = SDLA_S507_IRQ12;
1480 break;
1481 case 15:
1482 flp->state = SDLA_S507_IRQ15;
1483 break;
1487 for(i=0; i < ARRAY_SIZE(valid_mem); i++)
1488 if (valid_mem[i] == map->mem_start)
1489 break;
1491 err = -EINVAL;
1492 if (i == ARRAY_SIZE(valid_mem))
1493 goto fail2;
1495 if (flp->type == SDLA_S502A && (map->mem_start & 0xF000) >> 12 == 0x0E)
1496 goto fail2;
1498 if (flp->type != SDLA_S507 && map->mem_start >> 16 == 0x0B)
1499 goto fail2;
1501 if (flp->type == SDLA_S507 && map->mem_start >> 16 == 0x0D)
1502 goto fail2;
1504 byte = flp->type != SDLA_S508 ? SDLA_8K_WINDOW : 0;
1505 byte |= (map->mem_start & 0xF000) >> (12 + (flp->type == SDLA_S508 ? 1 : 0));
1506 switch(flp->type) {
1507 case SDLA_S502A:
1508 case SDLA_S502E:
1509 switch (map->mem_start >> 16) {
1510 case 0x0A:
1511 byte |= SDLA_S502_SEG_A;
1512 break;
1513 case 0x0C:
1514 byte |= SDLA_S502_SEG_C;
1515 break;
1516 case 0x0D:
1517 byte |= SDLA_S502_SEG_D;
1518 break;
1519 case 0x0E:
1520 byte |= SDLA_S502_SEG_E;
1521 break;
1523 break;
1524 case SDLA_S507:
1525 switch (map->mem_start >> 16) {
1526 case 0x0A:
1527 byte |= SDLA_S507_SEG_A;
1528 break;
1529 case 0x0B:
1530 byte |= SDLA_S507_SEG_B;
1531 break;
1532 case 0x0C:
1533 byte |= SDLA_S507_SEG_C;
1534 break;
1535 case 0x0E:
1536 byte |= SDLA_S507_SEG_E;
1537 break;
1539 break;
1540 case SDLA_S508:
1541 switch (map->mem_start >> 16) {
1542 case 0x0A:
1543 byte |= SDLA_S508_SEG_A;
1544 break;
1545 case 0x0C:
1546 byte |= SDLA_S508_SEG_C;
1547 break;
1548 case 0x0D:
1549 byte |= SDLA_S508_SEG_D;
1550 break;
1551 case 0x0E:
1552 byte |= SDLA_S508_SEG_E;
1553 break;
1555 break;
1558 /* set the memory bits, and enable access */
1559 outb(byte, base + SDLA_REG_PC_WINDOW);
1561 switch(flp->type)
1563 case SDLA_S502E:
1564 flp->state = SDLA_S502E_ENABLE;
1565 break;
1566 case SDLA_S507:
1567 flp->state |= SDLA_MEMEN;
1568 break;
1569 case SDLA_S508:
1570 flp->state = SDLA_MEMEN;
1571 break;
1573 outb(flp->state, base + SDLA_REG_CONTROL);
1575 dev->irq = map->irq;
1576 dev->base_addr = base;
1577 dev->mem_start = map->mem_start;
1578 dev->mem_end = dev->mem_start + 0x2000;
1579 flp->initialized = 1;
1580 return 0;
1582 fail2:
1583 free_irq(map->irq, dev);
1584 fail:
1585 release_region(base, SDLA_IO_EXTENTS);
1586 return err;
1589 static const struct net_device_ops sdla_netdev_ops = {
1590 .ndo_open = sdla_open,
1591 .ndo_stop = sdla_close,
1592 .ndo_do_ioctl = sdla_ioctl,
1593 .ndo_set_config = sdla_set_config,
1594 .ndo_start_xmit = sdla_transmit,
1595 .ndo_change_mtu = sdla_change_mtu,
1598 static void setup_sdla(struct net_device *dev)
1600 struct frad_local *flp = netdev_priv(dev);
1602 netdev_boot_setup_check(dev);
1604 dev->netdev_ops = &sdla_netdev_ops;
1605 dev->flags = 0;
1606 dev->type = 0xFFFF;
1607 dev->hard_header_len = 0;
1608 dev->addr_len = 0;
1609 dev->mtu = SDLA_MAX_MTU;
1611 flp->activate = sdla_activate;
1612 flp->deactivate = sdla_deactivate;
1613 flp->assoc = sdla_assoc;
1614 flp->deassoc = sdla_deassoc;
1615 flp->dlci_conf = sdla_dlci_conf;
1616 flp->dev = dev;
1618 timer_setup(&flp->timer, sdla_poll, 0);
1619 flp->timer.expires = 1;
1622 static struct net_device *sdla;
1624 static int __init init_sdla(void)
1626 int err;
1628 printk("%s.\n", version);
1630 sdla = alloc_netdev(sizeof(struct frad_local), "sdla0",
1631 NET_NAME_UNKNOWN, setup_sdla);
1632 if (!sdla)
1633 return -ENOMEM;
1635 err = register_netdev(sdla);
1636 if (err)
1637 free_netdev(sdla);
1639 return err;
1642 static void __exit exit_sdla(void)
1644 struct frad_local *flp = netdev_priv(sdla);
1646 unregister_netdev(sdla);
1647 if (flp->initialized) {
1648 free_irq(sdla->irq, sdla);
1649 release_region(sdla->base_addr, SDLA_IO_EXTENTS);
1651 del_timer_sync(&flp->timer);
1652 free_netdev(sdla);
1655 MODULE_LICENSE("GPL");
1657 module_init(init_sdla);
1658 module_exit(exit_sdla);