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>
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
)
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 static void sdla_stop(struct net_device
*dev
)
187 struct frad_local
*flp
;
189 flp
= netdev_priv(dev
);
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 static void sdla_start(struct net_device
*dev
)
214 struct frad_local
*flp
;
216 flp
= netdev_priv(dev
);
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 static 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 ************************************************/
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 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! */
360 case SDLA_RET_CHANNEL_OFF
:
361 netdev_info(dev
, "Channel became inoperative!\n");
365 case SDLA_RET_CHANNEL_ON
:
366 netdev_info(dev
, "Channel became operative!\n");
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
)
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 netdev_info(dev
, "DLCI %i: %s\n",
387 pstatus
->dlci
, state
);
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
);
400 case SDLA_RET_TIMEOUT
:
401 netdev_err(dev
, "Command timed out!\n");
404 case SDLA_RET_BUF_OVERSIZE
:
405 netdev_info(dev
, "Bc/CIR overflow, acceptable size is %i\n",
409 case SDLA_RET_BUF_TOO_BIG
:
410 netdev_info(dev
, "Buffer size over specified max of %i\n",
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
)
422 netdev_dbg(dev
, "Cmd 0x%02X generated return code 0x%02X\n",
424 /* Further processing could be done here */
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
;
437 int ret
, waiting
, len
;
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
));
445 jiffs
= jiffies
+ HZ
; /* 1 second is plenty */
447 spin_lock_irqsave(&sdla_lock
, pflags
);
448 SDLA_WINDOW(dev
, window
);
450 cmd_buf
->dlci
= dlci
;
451 cmd_buf
->flags
= flags
;
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
);
463 while (waiting
&& time_before_eq(jiffies
, jiffs
))
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
);
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
;
486 memcpy(outbuf
, cmd_buf
->data
, *outlen
);
489 /* This is a local copy that's used for error handling */
491 memcpy(&status
, cmd_buf
->data
, len
> sizeof(status
) ? sizeof(status
) : len
);
493 spin_unlock_irqrestore(&sdla_lock
, pflags
);
496 ret
= SDLA_RET_TIMEOUT
;
498 if (ret
!= SDLA_RET_OK
)
499 sdla_errors(dev
, cmd
, dlci
, ret
, len
, &status
);
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
;
517 flp
= netdev_priv(slave
);
519 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
520 if (flp
->master
[i
] == master
)
523 if (i
== CONFIG_DLCI_MAX
)
526 flp
->dlci
[i
] = abs(flp
->dlci
[i
]);
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
);
534 static int sdla_deactivate(struct net_device
*slave
, struct net_device
*master
)
536 struct frad_local
*flp
;
539 flp
= netdev_priv(slave
);
541 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
542 if (flp
->master
[i
] == master
)
545 if (i
== CONFIG_DLCI_MAX
)
548 flp
->dlci
[i
] = -abs(flp
->dlci
[i
]);
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
);
556 static int sdla_assoc(struct net_device
*slave
, struct net_device
*master
)
558 struct frad_local
*flp
;
561 if (master
->type
!= ARPHRD_DLCI
)
564 flp
= netdev_priv(slave
);
566 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
570 if (abs(flp
->dlci
[i
]) == *(short *)(master
->dev_addr
))
574 if (i
== CONFIG_DLCI_MAX
)
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
);
586 sdla_cmd(slave
, SDLA_ADD_DLCI
, 0, 0, master
->dev_addr
, sizeof(short), NULL
, NULL
);
592 static int sdla_deassoc(struct net_device
*slave
, struct net_device
*master
)
594 struct frad_local
*flp
;
597 flp
= netdev_priv(slave
);
599 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
600 if (flp
->master
[i
] == master
)
603 if (i
== CONFIG_DLCI_MAX
)
606 flp
->master
[i
] = NULL
;
610 if (netif_running(slave
)) {
611 if (flp
->config
.station
== FRAD_STATION_CPE
)
612 sdla_reconfig(slave
);
614 sdla_cmd(slave
, SDLA_DELETE_DLCI
, 0, 0, master
->dev_addr
, sizeof(short), NULL
, NULL
);
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
;
627 flp
= netdev_priv(slave
);
629 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
630 if (flp
->master
[i
] == master
)
633 if (i
== CONFIG_DLCI_MAX
)
636 dlp
= netdev_priv(master
);
639 len
= sizeof(struct dlci_conf
);
640 if (netif_running(slave
)) {
642 ret
= sdla_cmd(slave
, SDLA_READ_DLCI_CONFIGURATION
, abs(flp
->dlci
[i
]), 0,
643 NULL
, 0, &dlp
->config
, &len
);
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
;
666 struct buf_entry
*pbuf
;
668 flp
= netdev_priv(dev
);
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
684 if (skb
->dev
->type
!= ARPHRD_DLCI
)
686 netdev_warn(dev
, "Non DLCI device, type %i, tried to send on FRAD module\n",
692 netdev_warn(dev
, "unknown firmware type 0x%04X\n",
699 /* this is frame specific, but till there's a PPP module, it's the default */
704 ret
= sdla_cmd(dev
, SDLA_INFORMATION_WRITE
, *(short *)(skb
->dev
->dev_addr
), 0, skb
->data
, skb
->len
, NULL
, NULL
);
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
);
718 spin_unlock_irqrestore(&sdla_lock
, flags
);
726 dev
->stats
.tx_packets
++;
729 case SDLA_RET_CIR_OVERFLOW
:
730 case SDLA_RET_BUF_OVERSIZE
:
731 case SDLA_RET_NO_BUFS
:
732 dev
->stats
.tx_dropped
++;
736 dev
->stats
.tx_errors
++;
740 netif_wake_queue(dev
);
741 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
743 if(flp
->master
[i
]!=NULL
)
744 netif_wake_queue(flp
->master
[i
]);
751 static void sdla_receive(struct net_device
*dev
)
753 struct net_device
*master
;
754 struct frad_local
*flp
;
755 struct dlci_local
*dlp
;
758 struct sdla_cmd
*cmd
;
759 struct buf_info
*pbufi
;
760 struct buf_entry
*pbuf
;
763 int i
=0, received
, success
, addr
, buf_base
, buf_top
;
764 short dlci
, len
, len2
, split
;
766 flp
= netdev_priv(dev
);
768 received
= addr
= buf_top
= buf_base
= 0;
776 spin_lock_irqsave(&sdla_lock
, flags
);
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
;
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
;
800 buf_top
= pbufi
->buf_top
;
801 buf_base
= pbufi
->buf_base
;
804 addr
= pbuf
->buf_addr
;
808 /* common code, find the DLCI and get the SKB */
811 for (i
=0;i
<CONFIG_DLCI_MAX
;i
++)
812 if (flp
->dlci
[i
] == dlci
)
815 if (i
== CONFIG_DLCI_MAX
)
817 netdev_notice(dev
, "Received packet from invalid DLCI %i, ignoring\n",
819 dev
->stats
.rx_errors
++;
826 master
= flp
->master
[i
];
827 skb
= dev_alloc_skb(len
+ sizeof(struct frhdr
));
830 netdev_notice(dev
, "Memory squeeze, dropping packet\n");
831 dev
->stats
.rx_dropped
++;
835 skb_reserve(skb
, sizeof(struct frhdr
));
838 /* pick up the data */
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
);
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;
857 __sdla_read(dev
, addr
, skb_put(skb
, len2
), len2
);
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
;
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
;
887 flp
= netdev_priv(dev
);
889 if (!flp
->initialized
)
891 netdev_warn(dev
, "irq %d for uninitialized device\n", dev
->irq
);
895 byte
= sdla_byte(dev
, flp
->type
== SDLA_S508
? SDLA_508_IRQ_INTERFACE
: SDLA_502_IRQ_INTERFACE
);
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
);
909 case SDLA_INTR_COMPLETE
:
910 case SDLA_INTR_TIMER
:
911 netdev_warn(dev
, "invalid irq flag 0x%02X\n", byte
);
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 */
926 sdla_write(dev
, flp
->type
== SDLA_S508
? SDLA_508_IRQ_INTERFACE
: SDLA_502_IRQ_INTERFACE
, &byte
, sizeof(byte
));
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
))
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
;
947 short dlcis
[CONFIG_DLCI_MAX
];
949 flp
= netdev_priv(dev
);
952 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
954 dlcis
[len
++] = abs(flp
->dlci
[i
]);
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 */
970 del_timer(&flp
->timer
);
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
);
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
);
989 sdla_cmd(dev
, SDLA_DISABLE_COMMUNICATIONS
, 0, 0, NULL
, 0, NULL
, NULL
);
991 netif_stop_queue(dev
);
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
;
1010 flp
= netdev_priv(dev
);
1012 if (!flp
->initialized
)
1015 if (!flp
->configured
)
1018 /* time to send in the configuration */
1020 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
1022 data
.dlci
[len
++] = abs(flp
->dlci
[i
]);
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
)
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
));
1041 flp
->timer
.expires
= 1;
1042 add_timer(&flp
->timer
);
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
);
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
);
1060 flp
->state
|= SDLA_S508_INTEN
;
1061 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
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
);
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
);
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
++)
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
);
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
;
1104 if (dev
->type
== 0xFFFF)
1107 flp
= netdev_priv(dev
);
1111 if (netif_running(dev
))
1114 if(copy_from_user(&data
.config
, conf
, sizeof(struct frad_conf
)))
1117 if (data
.config
.station
& ~FRAD_STATION_NODE
)
1120 if (data
.config
.flags
& ~FRAD_VALID_FLAGS
)
1123 if ((data
.config
.kbaud
< 0) ||
1124 ((data
.config
.kbaud
> 128) && (flp
->type
!= SDLA_S508
)))
1127 if (data
.config
.clocking
& ~(FRAD_CLOCK_INT
| SDLA_S508_PORT_RS232
))
1130 if ((data
.config
.mtu
< 0) || (data
.config
.mtu
> SDLA_MAX_MTU
))
1133 if ((data
.config
.T391
< 5) || (data
.config
.T391
> 30))
1136 if ((data
.config
.T392
< 5) || (data
.config
.T392
> 30))
1139 if ((data
.config
.N391
< 1) || (data
.config
.N391
> 255))
1142 if ((data
.config
.N392
< 1) || (data
.config
.N392
> 10))
1145 if ((data
.config
.N393
< 1) || (data
.config
.N393
> 10))
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
++)
1160 flp
->master
[i
]->mtu
= flp
->config
.mtu
;
1163 flp
->config
.mtu
+= sizeof(struct frhdr
);
1165 /* off to the races! */
1166 if (!flp
->configured
)
1169 flp
->configured
= 1;
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
)
1181 if (flp
->configured
)
1182 memcpy(&data
.config
, &flp
->config
, sizeof(struct frad_conf
));
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;
1195 static int sdla_xfer(struct net_device
*dev
, struct sdla_mem __user
*info
, int read
)
1197 struct sdla_mem mem
;
1200 if(copy_from_user(&mem
, info
, sizeof(mem
)))
1205 temp
= kzalloc(mem
.len
, GFP_KERNEL
);
1208 sdla_read(dev
, mem
.addr
, temp
, mem
.len
);
1209 if(copy_to_user(mem
.data
, temp
, mem
.len
))
1218 temp
= memdup_user(mem
.data
, mem
.len
);
1220 return PTR_ERR(temp
);
1221 sdla_write(dev
, mem
.addr
, temp
, mem
.len
);
1227 static int sdla_reconfig(struct net_device
*dev
)
1229 struct frad_local
*flp
;
1230 struct conf_data data
;
1233 flp
= netdev_priv(dev
);
1236 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
1238 data
.dlci
[len
++] = flp
->dlci
[i
];
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
);
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
))
1258 flp
= netdev_priv(dev
);
1260 if (!flp
->initialized
)
1267 return sdla_config(dev
, ifr
->ifr_data
, cmd
== FRAD_GET_CONF
);
1270 ifr
->ifr_flags
= flp
->type
;
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 ============================================================*/
1283 if (flp
->configured
)
1286 switch (ifr
->ifr_flags
)
1289 dev
->type
= ifr
->ifr_flags
;
1292 return -ENOPROTOOPT
;
1302 if(!capable(CAP_SYS_RAWIO
))
1304 return sdla_xfer(dev
, ifr
->ifr_data
, cmd
== SDLA_READMEM
);
1320 static int sdla_change_mtu(struct net_device
*dev
, int new_mtu
)
1322 if (netif_running(dev
))
1325 /* for now, you can't change the MTU! */
1329 static int sdla_set_config(struct net_device
*dev
, struct ifmap
*map
)
1331 struct frad_local
*flp
;
1337 flp
= netdev_priv(dev
);
1339 if (flp
->initialized
)
1342 for(i
=0; i
< ARRAY_SIZE(valid_port
); i
++)
1343 if (valid_port
[i
] == map
->base_addr
)
1346 if (i
== ARRAY_SIZE(valid_port
))
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
);
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
;
1360 for(i
=1;i
<SDLA_IO_EXTENTS
;i
++)
1361 if (inb(base
+ i
) != 0xFF)
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
;
1376 for(byte
=inb(base
),i
=0;i
<SDLA_IO_EXTENTS
;i
++)
1377 if (inb(base
+ i
) != byte
)
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
;
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
;
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
;
1415 netdev_notice(dev
, "Unknown card type\n");
1425 if (flp
->type
!= SDLA_S508
&& flp
->type
!= SDLA_S507
)
1431 if (flp
->type
!= SDLA_S502E
)
1440 if (flp
->type
!= SDLA_S508
&& flp
->type
!= SDLA_S507
)
1446 if (flp
->type
== SDLA_S502A
)
1455 if (request_irq(dev
->irq
, sdla_isr
, 0, dev
->name
, dev
))
1458 if (flp
->type
== SDLA_S507
) {
1461 flp
->state
= SDLA_S507_IRQ3
;
1464 flp
->state
= SDLA_S507_IRQ4
;
1467 flp
->state
= SDLA_S507_IRQ5
;
1470 flp
->state
= SDLA_S507_IRQ7
;
1473 flp
->state
= SDLA_S507_IRQ10
;
1476 flp
->state
= SDLA_S507_IRQ11
;
1479 flp
->state
= SDLA_S507_IRQ12
;
1482 flp
->state
= SDLA_S507_IRQ15
;
1487 for(i
=0; i
< ARRAY_SIZE(valid_mem
); i
++)
1488 if (valid_mem
[i
] == map
->mem_start
)
1492 if (i
== ARRAY_SIZE(valid_mem
))
1495 if (flp
->type
== SDLA_S502A
&& (map
->mem_start
& 0xF000) >> 12 == 0x0E)
1498 if (flp
->type
!= SDLA_S507
&& map
->mem_start
>> 16 == 0x0B)
1501 if (flp
->type
== SDLA_S507
&& map
->mem_start
>> 16 == 0x0D)
1504 byte
= flp
->type
!= SDLA_S508
? SDLA_8K_WINDOW
: 0;
1505 byte
|= (map
->mem_start
& 0xF000) >> (12 + (flp
->type
== SDLA_S508
? 1 : 0));
1509 switch (map
->mem_start
>> 16) {
1511 byte
|= SDLA_S502_SEG_A
;
1514 byte
|= SDLA_S502_SEG_C
;
1517 byte
|= SDLA_S502_SEG_D
;
1520 byte
|= SDLA_S502_SEG_E
;
1525 switch (map
->mem_start
>> 16) {
1527 byte
|= SDLA_S507_SEG_A
;
1530 byte
|= SDLA_S507_SEG_B
;
1533 byte
|= SDLA_S507_SEG_C
;
1536 byte
|= SDLA_S507_SEG_E
;
1541 switch (map
->mem_start
>> 16) {
1543 byte
|= SDLA_S508_SEG_A
;
1546 byte
|= SDLA_S508_SEG_C
;
1549 byte
|= SDLA_S508_SEG_D
;
1552 byte
|= SDLA_S508_SEG_E
;
1558 /* set the memory bits, and enable access */
1559 outb(byte
, base
+ SDLA_REG_PC_WINDOW
);
1564 flp
->state
= SDLA_S502E_ENABLE
;
1567 flp
->state
|= SDLA_MEMEN
;
1570 flp
->state
= SDLA_MEMEN
;
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;
1583 free_irq(map
->irq
, dev
);
1585 release_region(base
, SDLA_IO_EXTENTS
);
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
;
1607 dev
->hard_header_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
;
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)
1628 printk("%s.\n", version
);
1630 sdla
= alloc_netdev(sizeof(struct frad_local
), "sdla0",
1631 NET_NAME_UNKNOWN
, setup_sdla
);
1635 err
= register_netdev(sdla
);
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
);
1655 MODULE_LICENSE("GPL");
1657 module_init(init_sdla
);
1658 module_exit(exit_sdla
);