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 #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>
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/system.h>
60 #include <asm/uaccess.h>
62 static const char* version
= "SDLA driver v0.30, 12 Sep 1996, mike.mclagan@linux.org";
64 static unsigned int valid_port
[] = { 0x250, 0x270, 0x280, 0x300, 0x350, 0x360, 0x380, 0x390};
66 static unsigned int valid_mem
[] = {
67 0xA0000, 0xA2000, 0xA4000, 0xA6000, 0xA8000, 0xAA000, 0xAC000, 0xAE000,
68 0xB0000, 0xB2000, 0xB4000, 0xB6000, 0xB8000, 0xBA000, 0xBC000, 0xBE000,
69 0xC0000, 0xC2000, 0xC4000, 0xC6000, 0xC8000, 0xCA000, 0xCC000, 0xCE000,
70 0xD0000, 0xD2000, 0xD4000, 0xD6000, 0xD8000, 0xDA000, 0xDC000, 0xDE000,
71 0xE0000, 0xE2000, 0xE4000, 0xE6000, 0xE8000, 0xEA000, 0xEC000, 0xEE000};
73 static DEFINE_SPINLOCK(sdla_lock
);
75 /*********************************************************
77 * these are the core routines that access the card itself
79 *********************************************************/
81 #define SDLA_WINDOW(dev,addr) outb((((addr) >> 13) & 0x1F), (dev)->base_addr + SDLA_REG_Z80_WINDOW)
83 static void __sdla_read(struct net_device
*dev
, int addr
, void *buf
, short len
)
92 offset
= addr
& SDLA_ADDR_MASK
;
93 bytes
= offset
+ len
> SDLA_WINDOW_SIZE
? SDLA_WINDOW_SIZE
- offset
: len
;
94 base
= (const void *) (dev
->mem_start
+ offset
);
96 SDLA_WINDOW(dev
, addr
);
97 memcpy(temp
, base
, bytes
);
105 static void sdla_read(struct net_device
*dev
, int addr
, void *buf
, short len
)
108 spin_lock_irqsave(&sdla_lock
, flags
);
109 __sdla_read(dev
, addr
, buf
, len
);
110 spin_unlock_irqrestore(&sdla_lock
, flags
);
113 static void __sdla_write(struct net_device
*dev
, int addr
,
114 const void *buf
, short len
)
123 offset
= addr
& SDLA_ADDR_MASK
;
124 bytes
= offset
+ len
> SDLA_WINDOW_SIZE
? SDLA_WINDOW_SIZE
- offset
: len
;
125 base
= (void *) (dev
->mem_start
+ offset
);
127 SDLA_WINDOW(dev
, addr
);
128 memcpy(base
, temp
, bytes
);
136 static void sdla_write(struct net_device
*dev
, int addr
,
137 const void *buf
, short len
)
141 spin_lock_irqsave(&sdla_lock
, flags
);
142 __sdla_write(dev
, addr
, buf
, len
);
143 spin_unlock_irqrestore(&sdla_lock
, flags
);
147 static void sdla_clear(struct net_device
*dev
)
151 int len
, addr
, bytes
;
155 bytes
= SDLA_WINDOW_SIZE
;
156 base
= (void *) dev
->mem_start
;
158 spin_lock_irqsave(&sdla_lock
, flags
);
161 SDLA_WINDOW(dev
, addr
);
162 memset(base
, 0, bytes
);
167 spin_unlock_irqrestore(&sdla_lock
, flags
);
171 static char sdla_byte(struct net_device
*dev
, int addr
)
176 temp
= (void *) (dev
->mem_start
+ (addr
& SDLA_ADDR_MASK
));
178 spin_lock_irqsave(&sdla_lock
, flags
);
179 SDLA_WINDOW(dev
, addr
);
181 spin_unlock_irqrestore(&sdla_lock
, flags
);
186 static void sdla_stop(struct net_device
*dev
)
188 struct frad_local
*flp
;
190 flp
= netdev_priv(dev
);
194 outb(SDLA_S502A_HALT
, dev
->base_addr
+ SDLA_REG_CONTROL
);
195 flp
->state
= SDLA_HALT
;
198 outb(SDLA_HALT
, dev
->base_addr
+ SDLA_REG_Z80_CONTROL
);
199 outb(SDLA_S502E_ENABLE
, dev
->base_addr
+ SDLA_REG_CONTROL
);
200 flp
->state
= SDLA_S502E_ENABLE
;
203 flp
->state
&= ~SDLA_CPUEN
;
204 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
207 flp
->state
&= ~SDLA_CPUEN
;
208 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
213 static void sdla_start(struct net_device
*dev
)
215 struct frad_local
*flp
;
217 flp
= netdev_priv(dev
);
221 outb(SDLA_S502A_NMI
, dev
->base_addr
+ SDLA_REG_CONTROL
);
222 outb(SDLA_S502A_START
, dev
->base_addr
+ SDLA_REG_CONTROL
);
223 flp
->state
= SDLA_S502A_START
;
226 outb(SDLA_S502E_CPUEN
, dev
->base_addr
+ SDLA_REG_Z80_CONTROL
);
227 outb(0x00, dev
->base_addr
+ SDLA_REG_CONTROL
);
231 flp
->state
|= SDLA_CPUEN
;
232 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
235 flp
->state
|= SDLA_CPUEN
;
236 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
241 /****************************************************
243 * this is used for the S502A/E cards to determine
244 * the speed of the onboard CPU. Calibration is
245 * necessary for the Frame Relay code uploaded
246 * later. Incorrect results cause timing problems
247 * with link checks & status messages
249 ***************************************************/
251 static int sdla_z80_poll(struct net_device
*dev
, int z80_addr
, int jiffs
, char resp1
, char resp2
)
253 unsigned long start
, done
, now
;
256 start
= now
= jiffies
;
257 done
= jiffies
+ jiffs
;
259 temp
= (void *)dev
->mem_start
;
260 temp
+= z80_addr
& SDLA_ADDR_MASK
;
263 while (time_before(jiffies
, done
) && (resp
!= resp1
) && (!resp2
|| (resp
!= resp2
)))
267 SDLA_WINDOW(dev
, z80_addr
);
272 return time_before(jiffies
, done
) ? jiffies
- start
: -1;
275 /* constants for Z80 CPU speed */
276 #define Z80_READY '1' /* Z80 is ready to begin */
277 #define LOADER_READY '2' /* driver is ready to begin */
278 #define Z80_SCC_OK '3' /* SCC is on board */
279 #define Z80_SCC_BAD '4' /* SCC was not found */
281 static int sdla_cpuspeed(struct net_device
*dev
, struct ifreq
*ifr
)
287 if (sdla_z80_poll(dev
, 0, 3*HZ
, Z80_READY
, 0) < 0)
291 sdla_write(dev
, 0, &data
, 1);
293 if ((jiffs
= sdla_z80_poll(dev
, 0, 8*HZ
, Z80_SCC_OK
, Z80_SCC_BAD
)) < 0)
297 sdla_read(dev
, 0, &data
, 1);
299 if (data
== Z80_SCC_BAD
)
301 printk("%s: SCC bad\n", dev
->name
);
305 if (data
!= Z80_SCC_OK
)
309 ifr
->ifr_mtu
= SDLA_CPU_16M
;
310 else if (jiffs
< 220)
311 ifr
->ifr_mtu
= SDLA_CPU_10M
;
312 else if (jiffs
< 258)
313 ifr
->ifr_mtu
= SDLA_CPU_8M
;
314 else if (jiffs
< 357)
315 ifr
->ifr_mtu
= SDLA_CPU_7M
;
316 else if (jiffs
< 467)
317 ifr
->ifr_mtu
= SDLA_CPU_5M
;
319 ifr
->ifr_mtu
= SDLA_CPU_3M
;
324 /************************************************
326 * Direct interaction with the Frame Relay code
329 ************************************************/
340 struct _dlci_stat dlcis
[SDLA_MAX_DLCI
];
343 static void sdla_errors(struct net_device
*dev
, int cmd
, int dlci
, int ret
, int len
, void *data
)
345 struct _dlci_stat
*pstatus
;
348 char *state
, line
[30];
354 if (*state
& SDLA_MODEM_DCD_LOW
)
355 netdev_info(dev
, "Modem DCD unexpectedly low!\n");
356 if (*state
& SDLA_MODEM_CTS_LOW
)
357 netdev_info(dev
, "Modem CTS unexpectedly low!\n");
358 /* I should probably do something about this! */
361 case SDLA_RET_CHANNEL_OFF
:
362 netdev_info(dev
, "Channel became inoperative!\n");
366 case SDLA_RET_CHANNEL_ON
:
367 netdev_info(dev
, "Channel became operative!\n");
371 case SDLA_RET_DLCI_STATUS
:
372 netdev_info(dev
, "Status change reported by Access Node\n");
373 len
/= sizeof(struct _dlci_stat
);
374 for(pstatus
= data
, i
=0;i
< len
;i
++,pstatus
++)
376 if (pstatus
->flags
& SDLA_DLCI_NEW
)
378 else if (pstatus
->flags
& SDLA_DLCI_DELETED
)
380 else if (pstatus
->flags
& SDLA_DLCI_ACTIVE
)
384 sprintf(line
, "unknown status: %02X", pstatus
->flags
);
387 netdev_info(dev
, "DLCI %i: %s\n",
388 pstatus
->dlci
, state
);
393 case SDLA_RET_DLCI_UNKNOWN
:
394 netdev_info(dev
, "Received unknown DLCIs:");
395 len
/= sizeof(short);
396 for(pdlci
= data
,i
=0;i
< len
;i
++,pdlci
++)
397 pr_cont(" %i", *pdlci
);
401 case SDLA_RET_TIMEOUT
:
402 netdev_err(dev
, "Command timed out!\n");
405 case SDLA_RET_BUF_OVERSIZE
:
406 netdev_info(dev
, "Bc/CIR overflow, acceptable size is %i\n",
410 case SDLA_RET_BUF_TOO_BIG
:
411 netdev_info(dev
, "Buffer size over specified max of %i\n",
415 case SDLA_RET_CHANNEL_INACTIVE
:
416 case SDLA_RET_DLCI_INACTIVE
:
417 case SDLA_RET_CIR_OVERFLOW
:
418 case SDLA_RET_NO_BUFS
:
419 if (cmd
== SDLA_INFORMATION_WRITE
)
423 netdev_dbg(dev
, "Cmd 0x%02X generated return code 0x%02X\n",
425 /* Further processing could be done here */
430 static int sdla_cmd(struct net_device
*dev
, int cmd
, short dlci
, short flags
,
431 void *inbuf
, short inlen
, void *outbuf
, short *outlen
)
433 static struct _frad_stat status
;
434 struct frad_local
*flp
;
435 struct sdla_cmd
*cmd_buf
;
436 unsigned long pflags
;
438 int ret
, waiting
, len
;
441 flp
= netdev_priv(dev
);
442 window
= flp
->type
== SDLA_S508
? SDLA_508_CMD_BUF
: SDLA_502_CMD_BUF
;
443 cmd_buf
= (struct sdla_cmd
*)(dev
->mem_start
+ (window
& SDLA_ADDR_MASK
));
446 jiffs
= jiffies
+ HZ
; /* 1 second is plenty */
448 spin_lock_irqsave(&sdla_lock
, pflags
);
449 SDLA_WINDOW(dev
, window
);
451 cmd_buf
->dlci
= dlci
;
452 cmd_buf
->flags
= flags
;
455 memcpy(cmd_buf
->data
, inbuf
, inlen
);
457 cmd_buf
->length
= inlen
;
459 cmd_buf
->opp_flag
= 1;
460 spin_unlock_irqrestore(&sdla_lock
, pflags
);
464 while (waiting
&& time_before_eq(jiffies
, jiffs
))
468 spin_lock_irqsave(&sdla_lock
, pflags
);
469 SDLA_WINDOW(dev
, window
);
470 waiting
= ((volatile int)(cmd_buf
->opp_flag
));
471 spin_unlock_irqrestore(&sdla_lock
, pflags
);
478 spin_lock_irqsave(&sdla_lock
, pflags
);
479 SDLA_WINDOW(dev
, window
);
480 ret
= cmd_buf
->retval
;
481 len
= cmd_buf
->length
;
482 if (outbuf
&& outlen
)
484 *outlen
= *outlen
>= len
? len
: *outlen
;
487 memcpy(outbuf
, cmd_buf
->data
, *outlen
);
490 /* This is a local copy that's used for error handling */
492 memcpy(&status
, cmd_buf
->data
, len
> sizeof(status
) ? sizeof(status
) : len
);
494 spin_unlock_irqrestore(&sdla_lock
, pflags
);
497 ret
= SDLA_RET_TIMEOUT
;
499 if (ret
!= SDLA_RET_OK
)
500 sdla_errors(dev
, cmd
, dlci
, ret
, len
, &status
);
505 /***********************************************
507 * these functions are called by the DLCI driver
509 ***********************************************/
511 static int sdla_reconfig(struct net_device
*dev
);
513 static int sdla_activate(struct net_device
*slave
, struct net_device
*master
)
515 struct frad_local
*flp
;
518 flp
= netdev_priv(slave
);
520 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
521 if (flp
->master
[i
] == master
)
524 if (i
== CONFIG_DLCI_MAX
)
527 flp
->dlci
[i
] = abs(flp
->dlci
[i
]);
529 if (netif_running(slave
) && (flp
->config
.station
== FRAD_STATION_NODE
))
530 sdla_cmd(slave
, SDLA_ACTIVATE_DLCI
, 0, 0, &flp
->dlci
[i
], sizeof(short), NULL
, NULL
);
535 static int sdla_deactivate(struct net_device
*slave
, struct net_device
*master
)
537 struct frad_local
*flp
;
540 flp
= netdev_priv(slave
);
542 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
543 if (flp
->master
[i
] == master
)
546 if (i
== CONFIG_DLCI_MAX
)
549 flp
->dlci
[i
] = -abs(flp
->dlci
[i
]);
551 if (netif_running(slave
) && (flp
->config
.station
== FRAD_STATION_NODE
))
552 sdla_cmd(slave
, SDLA_DEACTIVATE_DLCI
, 0, 0, &flp
->dlci
[i
], sizeof(short), NULL
, NULL
);
557 static int sdla_assoc(struct net_device
*slave
, struct net_device
*master
)
559 struct frad_local
*flp
;
562 if (master
->type
!= ARPHRD_DLCI
)
565 flp
= netdev_priv(slave
);
567 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
571 if (abs(flp
->dlci
[i
]) == *(short *)(master
->dev_addr
))
575 if (i
== CONFIG_DLCI_MAX
)
576 return -EMLINK
; /* #### Alan: Comments on this ?? */
579 flp
->master
[i
] = master
;
580 flp
->dlci
[i
] = -*(short *)(master
->dev_addr
);
581 master
->mtu
= slave
->mtu
;
583 if (netif_running(slave
)) {
584 if (flp
->config
.station
== FRAD_STATION_CPE
)
585 sdla_reconfig(slave
);
587 sdla_cmd(slave
, SDLA_ADD_DLCI
, 0, 0, master
->dev_addr
, sizeof(short), NULL
, NULL
);
593 static int sdla_deassoc(struct net_device
*slave
, struct net_device
*master
)
595 struct frad_local
*flp
;
598 flp
= netdev_priv(slave
);
600 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
601 if (flp
->master
[i
] == master
)
604 if (i
== CONFIG_DLCI_MAX
)
607 flp
->master
[i
] = NULL
;
611 if (netif_running(slave
)) {
612 if (flp
->config
.station
== FRAD_STATION_CPE
)
613 sdla_reconfig(slave
);
615 sdla_cmd(slave
, SDLA_DELETE_DLCI
, 0, 0, master
->dev_addr
, sizeof(short), NULL
, NULL
);
621 static int sdla_dlci_conf(struct net_device
*slave
, struct net_device
*master
, int get
)
623 struct frad_local
*flp
;
624 struct dlci_local
*dlp
;
628 flp
= netdev_priv(slave
);
630 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
631 if (flp
->master
[i
] == master
)
634 if (i
== CONFIG_DLCI_MAX
)
637 dlp
= netdev_priv(master
);
640 len
= sizeof(struct dlci_conf
);
641 if (netif_running(slave
)) {
643 ret
= sdla_cmd(slave
, SDLA_READ_DLCI_CONFIGURATION
, abs(flp
->dlci
[i
]), 0,
644 NULL
, 0, &dlp
->config
, &len
);
646 ret
= sdla_cmd(slave
, SDLA_SET_DLCI_CONFIGURATION
, abs(flp
->dlci
[i
]), 0,
647 &dlp
->config
, sizeof(struct dlci_conf
) - 4 * sizeof(short), NULL
, NULL
);
650 return ret
== SDLA_RET_OK
? 0 : -EIO
;
653 /**************************
655 * now for the Linux driver
657 **************************/
659 /* NOTE: the DLCI driver deals with freeing the SKB!! */
660 static netdev_tx_t
sdla_transmit(struct sk_buff
*skb
,
661 struct net_device
*dev
)
663 struct frad_local
*flp
;
664 int ret
, addr
, accept
, i
;
667 struct buf_entry
*pbuf
;
669 flp
= netdev_priv(dev
);
673 netif_stop_queue(dev
);
676 * stupid GateD insists on setting up the multicast router thru us
677 * and we're ill equipped to handle a non Frame Relay packet at this
685 if (skb
->dev
->type
!= ARPHRD_DLCI
)
687 netdev_warn(dev
, "Non DLCI device, type %i, tried to send on FRAD module\n",
693 netdev_warn(dev
, "unknown firmware type 0x%04X\n",
700 /* this is frame specific, but till there's a PPP module, it's the default */
705 ret
= sdla_cmd(dev
, SDLA_INFORMATION_WRITE
, *(short *)(skb
->dev
->dev_addr
), 0, skb
->data
, skb
->len
, NULL
, NULL
);
709 ret
= sdla_cmd(dev
, SDLA_INFORMATION_WRITE
, *(short *)(skb
->dev
->dev_addr
), 0, NULL
, skb
->len
, &addr
, &size
);
710 if (ret
== SDLA_RET_OK
)
713 spin_lock_irqsave(&sdla_lock
, flags
);
714 SDLA_WINDOW(dev
, addr
);
715 pbuf
= (void *)(((int) dev
->mem_start
) + (addr
& SDLA_ADDR_MASK
));
716 __sdla_write(dev
, pbuf
->buf_addr
, skb
->data
, skb
->len
);
717 SDLA_WINDOW(dev
, addr
);
719 spin_unlock_irqrestore(&sdla_lock
, flags
);
727 dev
->stats
.tx_packets
++;
730 case SDLA_RET_CIR_OVERFLOW
:
731 case SDLA_RET_BUF_OVERSIZE
:
732 case SDLA_RET_NO_BUFS
:
733 dev
->stats
.tx_dropped
++;
737 dev
->stats
.tx_errors
++;
741 netif_wake_queue(dev
);
742 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
744 if(flp
->master
[i
]!=NULL
)
745 netif_wake_queue(flp
->master
[i
]);
752 static void sdla_receive(struct net_device
*dev
)
754 struct net_device
*master
;
755 struct frad_local
*flp
;
756 struct dlci_local
*dlp
;
759 struct sdla_cmd
*cmd
;
760 struct buf_info
*pbufi
;
761 struct buf_entry
*pbuf
;
764 int i
=0, received
, success
, addr
, buf_base
, buf_top
;
765 short dlci
, len
, len2
, split
;
767 flp
= netdev_priv(dev
);
769 received
= addr
= buf_top
= buf_base
= 0;
777 spin_lock_irqsave(&sdla_lock
, flags
);
783 cmd
= (void *) (dev
->mem_start
+ (SDLA_502_RCV_BUF
& SDLA_ADDR_MASK
));
784 SDLA_WINDOW(dev
, SDLA_502_RCV_BUF
);
785 success
= cmd
->opp_flag
;
794 pbufi
= (void *) (dev
->mem_start
+ (SDLA_508_RXBUF_INFO
& SDLA_ADDR_MASK
));
795 SDLA_WINDOW(dev
, SDLA_508_RXBUF_INFO
);
796 pbuf
= (void *) (dev
->mem_start
+ ((pbufi
->rse_base
+ flp
->buffer
* sizeof(struct buf_entry
)) & SDLA_ADDR_MASK
));
797 success
= pbuf
->opp_flag
;
801 buf_top
= pbufi
->buf_top
;
802 buf_base
= pbufi
->buf_base
;
805 addr
= pbuf
->buf_addr
;
809 /* common code, find the DLCI and get the SKB */
812 for (i
=0;i
<CONFIG_DLCI_MAX
;i
++)
813 if (flp
->dlci
[i
] == dlci
)
816 if (i
== CONFIG_DLCI_MAX
)
818 netdev_notice(dev
, "Received packet from invalid DLCI %i, ignoring\n",
820 dev
->stats
.rx_errors
++;
827 master
= flp
->master
[i
];
828 skb
= dev_alloc_skb(len
+ sizeof(struct frhdr
));
831 netdev_notice(dev
, "Memory squeeze, dropping packet\n");
832 dev
->stats
.rx_dropped
++;
836 skb_reserve(skb
, sizeof(struct frhdr
));
839 /* pick up the data */
845 __sdla_read(dev
, SDLA_502_RCV_BUF
+ SDLA_502_DATA_OFS
, skb_put(skb
,len
), len
);
847 SDLA_WINDOW(dev
, SDLA_502_RCV_BUF
);
854 /* is this buffer split off the end of the internal ring buffer */
855 split
= addr
+ len
> buf_top
+ 1 ? len
- (buf_top
- addr
+ 1) : 0;
858 __sdla_read(dev
, addr
, skb_put(skb
, len2
), len2
);
860 __sdla_read(dev
, buf_base
, skb_put(skb
, split
), split
);
863 /* increment the buffer we're looking at */
864 SDLA_WINDOW(dev
, SDLA_508_RXBUF_INFO
);
865 flp
->buffer
= (flp
->buffer
+ 1) % pbufi
->rse_num
;
872 dev
->stats
.rx_packets
++;
873 dlp
= netdev_priv(master
);
874 (*dlp
->receive
)(skb
, master
);
877 spin_unlock_irqrestore(&sdla_lock
, flags
);
880 static irqreturn_t
sdla_isr(int dummy
, void *dev_id
)
882 struct net_device
*dev
;
883 struct frad_local
*flp
;
888 flp
= netdev_priv(dev
);
890 if (!flp
->initialized
)
892 netdev_warn(dev
, "irq %d for uninitialized device\n", dev
->irq
);
896 byte
= sdla_byte(dev
, flp
->type
== SDLA_S508
? SDLA_508_IRQ_INTERFACE
: SDLA_502_IRQ_INTERFACE
);
903 /* the command will get an error return, which is processed above */
904 case SDLA_INTR_MODEM
:
905 case SDLA_INTR_STATUS
:
906 sdla_cmd(dev
, SDLA_READ_DLC_STATUS
, 0, 0, NULL
, 0, NULL
, NULL
);
910 case SDLA_INTR_COMPLETE
:
911 case SDLA_INTR_TIMER
:
912 netdev_warn(dev
, "invalid irq flag 0x%02X\n", byte
);
916 /* the S502E requires a manual acknowledgement of the interrupt */
917 if (flp
->type
== SDLA_S502E
)
919 flp
->state
&= ~SDLA_S502E_INTACK
;
920 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
921 flp
->state
|= SDLA_S502E_INTACK
;
922 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
925 /* this clears the byte, informing the Z80 we're done */
927 sdla_write(dev
, flp
->type
== SDLA_S508
? SDLA_508_IRQ_INTERFACE
: SDLA_502_IRQ_INTERFACE
, &byte
, sizeof(byte
));
931 static void sdla_poll(unsigned long device
)
933 struct net_device
*dev
;
934 struct frad_local
*flp
;
936 dev
= (struct net_device
*) device
;
937 flp
= netdev_priv(dev
);
939 if (sdla_byte(dev
, SDLA_502_RCV_BUF
))
942 flp
->timer
.expires
= 1;
943 add_timer(&flp
->timer
);
946 static int sdla_close(struct net_device
*dev
)
948 struct frad_local
*flp
;
949 struct intr_info intr
;
951 short dlcis
[CONFIG_DLCI_MAX
];
953 flp
= netdev_priv(dev
);
956 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
958 dlcis
[len
++] = abs(flp
->dlci
[i
]);
961 if (flp
->config
.station
== FRAD_STATION_NODE
)
963 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
964 if (flp
->dlci
[i
] > 0)
965 sdla_cmd(dev
, SDLA_DEACTIVATE_DLCI
, 0, 0, dlcis
, len
, NULL
, NULL
);
966 sdla_cmd(dev
, SDLA_DELETE_DLCI
, 0, 0, &flp
->dlci
[i
], sizeof(flp
->dlci
[i
]), NULL
, NULL
);
969 memset(&intr
, 0, sizeof(intr
));
970 /* let's start up the reception */
974 del_timer(&flp
->timer
);
978 sdla_cmd(dev
, SDLA_SET_IRQ_TRIGGER
, 0, 0, &intr
, sizeof(char) + sizeof(short), NULL
, NULL
);
979 flp
->state
&= ~SDLA_S502E_INTACK
;
980 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
987 sdla_cmd(dev
, SDLA_SET_IRQ_TRIGGER
, 0, 0, &intr
, sizeof(struct intr_info
), NULL
, NULL
);
988 flp
->state
&= ~SDLA_S508_INTEN
;
989 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
993 sdla_cmd(dev
, SDLA_DISABLE_COMMUNICATIONS
, 0, 0, NULL
, 0, NULL
, NULL
);
995 netif_stop_queue(dev
);
1001 struct frad_conf config
;
1002 short dlci
[CONFIG_DLCI_MAX
];
1005 static int sdla_open(struct net_device
*dev
)
1007 struct frad_local
*flp
;
1008 struct dlci_local
*dlp
;
1009 struct conf_data data
;
1010 struct intr_info intr
;
1014 flp
= netdev_priv(dev
);
1016 if (!flp
->initialized
)
1019 if (!flp
->configured
)
1022 /* time to send in the configuration */
1024 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
1026 data
.dlci
[len
++] = abs(flp
->dlci
[i
]);
1029 memcpy(&data
.config
, &flp
->config
, sizeof(struct frad_conf
));
1030 len
+= sizeof(struct frad_conf
);
1032 sdla_cmd(dev
, SDLA_DISABLE_COMMUNICATIONS
, 0, 0, NULL
, 0, NULL
, NULL
);
1033 sdla_cmd(dev
, SDLA_SET_DLCI_CONFIGURATION
, 0, 0, &data
, len
, NULL
, NULL
);
1035 if (flp
->type
== SDLA_S508
)
1038 sdla_cmd(dev
, SDLA_ENABLE_COMMUNICATIONS
, 0, 0, NULL
, 0, NULL
, NULL
);
1040 /* let's start up the reception */
1041 memset(&intr
, 0, sizeof(intr
));
1045 flp
->timer
.expires
= 1;
1046 add_timer(&flp
->timer
);
1050 flp
->state
|= SDLA_S502E_ENABLE
;
1051 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
1052 flp
->state
|= SDLA_S502E_INTACK
;
1053 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
1055 sdla_write(dev
, SDLA_502_IRQ_INTERFACE
, &byte
, sizeof(byte
));
1056 intr
.flags
= SDLA_INTR_RX
| SDLA_INTR_STATUS
| SDLA_INTR_MODEM
;
1057 sdla_cmd(dev
, SDLA_SET_IRQ_TRIGGER
, 0, 0, &intr
, sizeof(char) + sizeof(short), NULL
, NULL
);
1064 flp
->state
|= SDLA_S508_INTEN
;
1065 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
1067 sdla_write(dev
, SDLA_508_IRQ_INTERFACE
, &byte
, sizeof(byte
));
1068 intr
.flags
= SDLA_INTR_RX
| SDLA_INTR_STATUS
| SDLA_INTR_MODEM
;
1069 intr
.irq
= dev
->irq
;
1070 sdla_cmd(dev
, SDLA_SET_IRQ_TRIGGER
, 0, 0, &intr
, sizeof(struct intr_info
), NULL
, NULL
);
1074 if (flp
->config
.station
== FRAD_STATION_CPE
)
1076 byte
= SDLA_ICS_STATUS_ENQ
;
1077 sdla_cmd(dev
, SDLA_ISSUE_IN_CHANNEL_SIGNAL
, 0, 0, &byte
, sizeof(byte
), NULL
, NULL
);
1081 sdla_cmd(dev
, SDLA_ADD_DLCI
, 0, 0, data
.dlci
, len
- sizeof(struct frad_conf
), NULL
, NULL
);
1082 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
1083 if (flp
->dlci
[i
] > 0)
1084 sdla_cmd(dev
, SDLA_ACTIVATE_DLCI
, 0, 0, &flp
->dlci
[i
], 2*sizeof(flp
->dlci
[i
]), NULL
, NULL
);
1087 /* configure any specific DLCI settings */
1088 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
1091 dlp
= netdev_priv(flp
->master
[i
]);
1092 if (dlp
->configured
)
1093 sdla_cmd(dev
, SDLA_SET_DLCI_CONFIGURATION
, abs(flp
->dlci
[i
]), 0, &dlp
->config
, sizeof(struct dlci_conf
), NULL
, NULL
);
1096 netif_start_queue(dev
);
1101 static int sdla_config(struct net_device
*dev
, struct frad_conf __user
*conf
, int get
)
1103 struct frad_local
*flp
;
1104 struct conf_data data
;
1108 if (dev
->type
== 0xFFFF)
1111 flp
= netdev_priv(dev
);
1115 if (netif_running(dev
))
1118 if(copy_from_user(&data
.config
, conf
, sizeof(struct frad_conf
)))
1121 if (data
.config
.station
& ~FRAD_STATION_NODE
)
1124 if (data
.config
.flags
& ~FRAD_VALID_FLAGS
)
1127 if ((data
.config
.kbaud
< 0) ||
1128 ((data
.config
.kbaud
> 128) && (flp
->type
!= SDLA_S508
)))
1131 if (data
.config
.clocking
& ~(FRAD_CLOCK_INT
| SDLA_S508_PORT_RS232
))
1134 if ((data
.config
.mtu
< 0) || (data
.config
.mtu
> SDLA_MAX_MTU
))
1137 if ((data
.config
.T391
< 5) || (data
.config
.T391
> 30))
1140 if ((data
.config
.T392
< 5) || (data
.config
.T392
> 30))
1143 if ((data
.config
.N391
< 1) || (data
.config
.N391
> 255))
1146 if ((data
.config
.N392
< 1) || (data
.config
.N392
> 10))
1149 if ((data
.config
.N393
< 1) || (data
.config
.N393
> 10))
1152 memcpy(&flp
->config
, &data
.config
, sizeof(struct frad_conf
));
1153 flp
->config
.flags
|= SDLA_DIRECT_RECV
;
1155 if (flp
->type
== SDLA_S508
)
1156 flp
->config
.flags
|= SDLA_TX70_RX30
;
1158 if (dev
->mtu
!= flp
->config
.mtu
)
1160 /* this is required to change the MTU */
1161 dev
->mtu
= flp
->config
.mtu
;
1162 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
1164 flp
->master
[i
]->mtu
= flp
->config
.mtu
;
1167 flp
->config
.mtu
+= sizeof(struct frhdr
);
1169 /* off to the races! */
1170 if (!flp
->configured
)
1173 flp
->configured
= 1;
1177 /* no sense reading if the CPU isn't started */
1178 if (netif_running(dev
))
1180 size
= sizeof(data
);
1181 if (sdla_cmd(dev
, SDLA_READ_DLCI_CONFIGURATION
, 0, 0, NULL
, 0, &data
, &size
) != SDLA_RET_OK
)
1185 if (flp
->configured
)
1186 memcpy(&data
.config
, &flp
->config
, sizeof(struct frad_conf
));
1188 memset(&data
.config
, 0, sizeof(struct frad_conf
));
1190 memcpy(&flp
->config
, &data
.config
, sizeof(struct frad_conf
));
1191 data
.config
.flags
&= FRAD_VALID_FLAGS
;
1192 data
.config
.mtu
-= data
.config
.mtu
> sizeof(struct frhdr
) ? sizeof(struct frhdr
) : data
.config
.mtu
;
1193 return copy_to_user(conf
, &data
.config
, sizeof(struct frad_conf
))?-EFAULT
:0;
1199 static int sdla_xfer(struct net_device
*dev
, struct sdla_mem __user
*info
, int read
)
1201 struct sdla_mem mem
;
1204 if(copy_from_user(&mem
, info
, sizeof(mem
)))
1209 temp
= kzalloc(mem
.len
, GFP_KERNEL
);
1212 sdla_read(dev
, mem
.addr
, temp
, mem
.len
);
1213 if(copy_to_user(mem
.data
, temp
, mem
.len
))
1222 temp
= memdup_user(mem
.data
, mem
.len
);
1224 return PTR_ERR(temp
);
1225 sdla_write(dev
, mem
.addr
, temp
, mem
.len
);
1231 static int sdla_reconfig(struct net_device
*dev
)
1233 struct frad_local
*flp
;
1234 struct conf_data data
;
1237 flp
= netdev_priv(dev
);
1240 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
1242 data
.dlci
[len
++] = flp
->dlci
[i
];
1245 memcpy(&data
, &flp
->config
, sizeof(struct frad_conf
));
1246 len
+= sizeof(struct frad_conf
);
1248 sdla_cmd(dev
, SDLA_DISABLE_COMMUNICATIONS
, 0, 0, NULL
, 0, NULL
, NULL
);
1249 sdla_cmd(dev
, SDLA_SET_DLCI_CONFIGURATION
, 0, 0, &data
, len
, NULL
, NULL
);
1250 sdla_cmd(dev
, SDLA_ENABLE_COMMUNICATIONS
, 0, 0, NULL
, 0, NULL
, NULL
);
1255 static int sdla_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
1257 struct frad_local
*flp
;
1259 if(!capable(CAP_NET_ADMIN
))
1262 flp
= netdev_priv(dev
);
1264 if (!flp
->initialized
)
1271 return sdla_config(dev
, ifr
->ifr_data
, cmd
== FRAD_GET_CONF
);
1274 ifr
->ifr_flags
= flp
->type
;
1278 return sdla_cpuspeed(dev
, ifr
);
1280 /* ==========================================================
1281 NOTE: This is rather a useless action right now, as the
1282 current driver does not support protocols other than
1283 FR. However, Sangoma has modules for a number of
1284 other protocols in the works.
1285 ============================================================*/
1287 if (flp
->configured
)
1290 switch (ifr
->ifr_flags
)
1293 dev
->type
= ifr
->ifr_flags
;
1296 return -ENOPROTOOPT
;
1306 if(!capable(CAP_SYS_RAWIO
))
1308 return sdla_xfer(dev
, ifr
->ifr_data
, cmd
== SDLA_READMEM
);
1324 static int sdla_change_mtu(struct net_device
*dev
, int new_mtu
)
1326 struct frad_local
*flp
;
1328 flp
= netdev_priv(dev
);
1330 if (netif_running(dev
))
1333 /* for now, you can't change the MTU! */
1337 static int sdla_set_config(struct net_device
*dev
, struct ifmap
*map
)
1339 struct frad_local
*flp
;
1345 flp
= netdev_priv(dev
);
1347 if (flp
->initialized
)
1350 for(i
=0; i
< ARRAY_SIZE(valid_port
); i
++)
1351 if (valid_port
[i
] == map
->base_addr
)
1354 if (i
== ARRAY_SIZE(valid_port
))
1357 if (!request_region(map
->base_addr
, SDLA_IO_EXTENTS
, dev
->name
)){
1358 pr_warn("io-port 0x%04lx in use\n", dev
->base_addr
);
1361 base
= map
->base_addr
;
1363 /* test for card types, S502A, S502E, S507, S508 */
1364 /* these tests shut down the card completely, so clear the state */
1365 flp
->type
= SDLA_UNKNOWN
;
1368 for(i
=1;i
<SDLA_IO_EXTENTS
;i
++)
1369 if (inb(base
+ i
) != 0xFF)
1372 if (i
== SDLA_IO_EXTENTS
) {
1373 outb(SDLA_HALT
, base
+ SDLA_REG_Z80_CONTROL
);
1374 if ((inb(base
+ SDLA_S502_STS
) & 0x0F) == 0x08) {
1375 outb(SDLA_S502E_INTACK
, base
+ SDLA_REG_CONTROL
);
1376 if ((inb(base
+ SDLA_S502_STS
) & 0x0F) == 0x0C) {
1377 outb(SDLA_HALT
, base
+ SDLA_REG_CONTROL
);
1378 flp
->type
= SDLA_S502E
;
1384 for(byte
=inb(base
),i
=0;i
<SDLA_IO_EXTENTS
;i
++)
1385 if (inb(base
+ i
) != byte
)
1388 if (i
== SDLA_IO_EXTENTS
) {
1389 outb(SDLA_HALT
, base
+ SDLA_REG_CONTROL
);
1390 if ((inb(base
+ SDLA_S502_STS
) & 0x7E) == 0x30) {
1391 outb(SDLA_S507_ENABLE
, base
+ SDLA_REG_CONTROL
);
1392 if ((inb(base
+ SDLA_S502_STS
) & 0x7E) == 0x32) {
1393 outb(SDLA_HALT
, base
+ SDLA_REG_CONTROL
);
1394 flp
->type
= SDLA_S507
;
1400 outb(SDLA_HALT
, base
+ SDLA_REG_CONTROL
);
1401 if ((inb(base
+ SDLA_S508_STS
) & 0x3F) == 0x00) {
1402 outb(SDLA_S508_INTEN
, base
+ SDLA_REG_CONTROL
);
1403 if ((inb(base
+ SDLA_S508_STS
) & 0x3F) == 0x10) {
1404 outb(SDLA_HALT
, base
+ SDLA_REG_CONTROL
);
1405 flp
->type
= SDLA_S508
;
1410 outb(SDLA_S502A_HALT
, base
+ SDLA_REG_CONTROL
);
1411 if (inb(base
+ SDLA_S502_STS
) == 0x40) {
1412 outb(SDLA_S502A_START
, base
+ SDLA_REG_CONTROL
);
1413 if (inb(base
+ SDLA_S502_STS
) == 0x40) {
1414 outb(SDLA_S502A_INTEN
, base
+ SDLA_REG_CONTROL
);
1415 if (inb(base
+ SDLA_S502_STS
) == 0x44) {
1416 outb(SDLA_S502A_START
, base
+ SDLA_REG_CONTROL
);
1417 flp
->type
= SDLA_S502A
;
1423 netdev_notice(dev
, "Unknown card type\n");
1433 if (flp
->type
!= SDLA_S508
&& flp
->type
!= SDLA_S507
)
1439 if (flp
->type
!= SDLA_S502E
)
1448 if (flp
->type
!= SDLA_S508
&& flp
->type
!= SDLA_S507
)
1454 if (flp
->type
== SDLA_S502A
)
1463 if (request_irq(dev
->irq
, sdla_isr
, 0, dev
->name
, dev
))
1466 if (flp
->type
== SDLA_S507
) {
1469 flp
->state
= SDLA_S507_IRQ3
;
1472 flp
->state
= SDLA_S507_IRQ4
;
1475 flp
->state
= SDLA_S507_IRQ5
;
1478 flp
->state
= SDLA_S507_IRQ7
;
1481 flp
->state
= SDLA_S507_IRQ10
;
1484 flp
->state
= SDLA_S507_IRQ11
;
1487 flp
->state
= SDLA_S507_IRQ12
;
1490 flp
->state
= SDLA_S507_IRQ15
;
1495 for(i
=0; i
< ARRAY_SIZE(valid_mem
); i
++)
1496 if (valid_mem
[i
] == map
->mem_start
)
1500 if (i
== ARRAY_SIZE(valid_mem
))
1503 if (flp
->type
== SDLA_S502A
&& (map
->mem_start
& 0xF000) >> 12 == 0x0E)
1506 if (flp
->type
!= SDLA_S507
&& map
->mem_start
>> 16 == 0x0B)
1509 if (flp
->type
== SDLA_S507
&& map
->mem_start
>> 16 == 0x0D)
1512 byte
= flp
->type
!= SDLA_S508
? SDLA_8K_WINDOW
: 0;
1513 byte
|= (map
->mem_start
& 0xF000) >> (12 + (flp
->type
== SDLA_S508
? 1 : 0));
1517 switch (map
->mem_start
>> 16) {
1519 byte
|= SDLA_S502_SEG_A
;
1522 byte
|= SDLA_S502_SEG_C
;
1525 byte
|= SDLA_S502_SEG_D
;
1528 byte
|= SDLA_S502_SEG_E
;
1533 switch (map
->mem_start
>> 16) {
1535 byte
|= SDLA_S507_SEG_A
;
1538 byte
|= SDLA_S507_SEG_B
;
1541 byte
|= SDLA_S507_SEG_C
;
1544 byte
|= SDLA_S507_SEG_E
;
1549 switch (map
->mem_start
>> 16) {
1551 byte
|= SDLA_S508_SEG_A
;
1554 byte
|= SDLA_S508_SEG_C
;
1557 byte
|= SDLA_S508_SEG_D
;
1560 byte
|= SDLA_S508_SEG_E
;
1566 /* set the memory bits, and enable access */
1567 outb(byte
, base
+ SDLA_REG_PC_WINDOW
);
1572 flp
->state
= SDLA_S502E_ENABLE
;
1575 flp
->state
|= SDLA_MEMEN
;
1578 flp
->state
= SDLA_MEMEN
;
1581 outb(flp
->state
, base
+ SDLA_REG_CONTROL
);
1583 dev
->irq
= map
->irq
;
1584 dev
->base_addr
= base
;
1585 dev
->mem_start
= map
->mem_start
;
1586 dev
->mem_end
= dev
->mem_start
+ 0x2000;
1587 flp
->initialized
= 1;
1591 free_irq(map
->irq
, dev
);
1593 release_region(base
, SDLA_IO_EXTENTS
);
1597 static const struct net_device_ops sdla_netdev_ops
= {
1598 .ndo_open
= sdla_open
,
1599 .ndo_stop
= sdla_close
,
1600 .ndo_do_ioctl
= sdla_ioctl
,
1601 .ndo_set_config
= sdla_set_config
,
1602 .ndo_start_xmit
= sdla_transmit
,
1603 .ndo_change_mtu
= sdla_change_mtu
,
1606 static void setup_sdla(struct net_device
*dev
)
1608 struct frad_local
*flp
= netdev_priv(dev
);
1610 netdev_boot_setup_check(dev
);
1612 dev
->netdev_ops
= &sdla_netdev_ops
;
1615 dev
->hard_header_len
= 0;
1617 dev
->mtu
= SDLA_MAX_MTU
;
1619 flp
->activate
= sdla_activate
;
1620 flp
->deactivate
= sdla_deactivate
;
1621 flp
->assoc
= sdla_assoc
;
1622 flp
->deassoc
= sdla_deassoc
;
1623 flp
->dlci_conf
= sdla_dlci_conf
;
1625 init_timer(&flp
->timer
);
1626 flp
->timer
.expires
= 1;
1627 flp
->timer
.data
= (unsigned long) dev
;
1628 flp
->timer
.function
= sdla_poll
;
1631 static struct net_device
*sdla
;
1633 static int __init
init_sdla(void)
1637 printk("%s.\n", version
);
1639 sdla
= alloc_netdev(sizeof(struct frad_local
), "sdla0", setup_sdla
);
1643 err
= register_netdev(sdla
);
1650 static void __exit
exit_sdla(void)
1652 struct frad_local
*flp
= netdev_priv(sdla
);
1654 unregister_netdev(sdla
);
1655 if (flp
->initialized
) {
1656 free_irq(sdla
->irq
, sdla
);
1657 release_region(sdla
->base_addr
, SDLA_IO_EXTENTS
);
1659 del_timer_sync(&flp
->timer
);
1663 MODULE_LICENSE("GPL");
1665 module_init(init_sdla
);
1666 module_exit(exit_sdla
);