1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * SDLA An implementation of a driver for the Sangoma S502/S508 series
4 * multi-protocol PC interface card. Initial offering is with
5 * the DLCI driver, providing Frame Relay support for linux.
7 * Global definitions for the Frame relay interface.
9 * Version: @(#)sdla.c 0.30 12 Sep 1996
11 * Credits: Sangoma Technologies, for the use of 2 cards for an extended
13 * David Mandelstam <dm@sangoma.com> for getting me started on
14 * this project, and incentive to complete it.
15 * Gene Kozen <74604.152@compuserve.com> for providing me with
16 * important information about the cards.
18 * Author: Mike McLagan <mike.mclagan@linux.org>
21 * 0.15 Mike McLagan Improved error handling, packet dropping
22 * 0.20 Mike McLagan New transmit/receive flags for config
23 * If in FR mode, don't accept packets from
25 * 0.25 Mike McLagan Fixed problem with rejecting packets
26 * from non DLCI devices.
27 * 0.30 Mike McLagan Fixed kernel panic when used with modified
31 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
33 #include <linux/module.h>
34 #include <linux/kernel.h>
35 #include <linux/types.h>
36 #include <linux/fcntl.h>
37 #include <linux/interrupt.h>
38 #include <linux/ptrace.h>
39 #include <linux/ioport.h>
41 #include <linux/slab.h>
42 #include <linux/string.h>
43 #include <linux/timer.h>
44 #include <linux/errno.h>
45 #include <linux/init.h>
46 #include <linux/netdevice.h>
47 #include <linux/skbuff.h>
48 #include <linux/if_arp.h>
49 #include <linux/if_frad.h>
50 #include <linux/sdla.h>
51 #include <linux/bitops.h>
55 #include <linux/uaccess.h>
57 static const char* version
= "SDLA driver v0.30, 12 Sep 1996, mike.mclagan@linux.org";
59 static unsigned int valid_port
[] = { 0x250, 0x270, 0x280, 0x300, 0x350, 0x360, 0x380, 0x390};
61 static unsigned int valid_mem
[] = {
62 0xA0000, 0xA2000, 0xA4000, 0xA6000, 0xA8000, 0xAA000, 0xAC000, 0xAE000,
63 0xB0000, 0xB2000, 0xB4000, 0xB6000, 0xB8000, 0xBA000, 0xBC000, 0xBE000,
64 0xC0000, 0xC2000, 0xC4000, 0xC6000, 0xC8000, 0xCA000, 0xCC000, 0xCE000,
65 0xD0000, 0xD2000, 0xD4000, 0xD6000, 0xD8000, 0xDA000, 0xDC000, 0xDE000,
66 0xE0000, 0xE2000, 0xE4000, 0xE6000, 0xE8000, 0xEA000, 0xEC000, 0xEE000};
68 static DEFINE_SPINLOCK(sdla_lock
);
70 /*********************************************************
72 * these are the core routines that access the card itself
74 *********************************************************/
76 #define SDLA_WINDOW(dev,addr) outb((((addr) >> 13) & 0x1F), (dev)->base_addr + SDLA_REG_Z80_WINDOW)
78 static void __sdla_read(struct net_device
*dev
, int addr
, void *buf
, short len
)
87 offset
= addr
& SDLA_ADDR_MASK
;
88 bytes
= offset
+ len
> SDLA_WINDOW_SIZE
? SDLA_WINDOW_SIZE
- offset
: len
;
89 base
= (const void *) (dev
->mem_start
+ offset
);
91 SDLA_WINDOW(dev
, addr
);
92 memcpy(temp
, base
, bytes
);
100 static void sdla_read(struct net_device
*dev
, int addr
, void *buf
, short len
)
103 spin_lock_irqsave(&sdla_lock
, flags
);
104 __sdla_read(dev
, addr
, buf
, len
);
105 spin_unlock_irqrestore(&sdla_lock
, flags
);
108 static void __sdla_write(struct net_device
*dev
, int addr
,
109 const void *buf
, short len
)
118 offset
= addr
& SDLA_ADDR_MASK
;
119 bytes
= offset
+ len
> SDLA_WINDOW_SIZE
? SDLA_WINDOW_SIZE
- offset
: len
;
120 base
= (void *) (dev
->mem_start
+ offset
);
122 SDLA_WINDOW(dev
, addr
);
123 memcpy(base
, temp
, bytes
);
131 static void sdla_write(struct net_device
*dev
, int addr
,
132 const void *buf
, short len
)
136 spin_lock_irqsave(&sdla_lock
, flags
);
137 __sdla_write(dev
, addr
, buf
, len
);
138 spin_unlock_irqrestore(&sdla_lock
, flags
);
142 static void sdla_clear(struct net_device
*dev
)
146 int len
, addr
, bytes
;
150 bytes
= SDLA_WINDOW_SIZE
;
151 base
= (void *) dev
->mem_start
;
153 spin_lock_irqsave(&sdla_lock
, flags
);
156 SDLA_WINDOW(dev
, addr
);
157 memset(base
, 0, bytes
);
162 spin_unlock_irqrestore(&sdla_lock
, flags
);
166 static char sdla_byte(struct net_device
*dev
, int addr
)
171 temp
= (void *) (dev
->mem_start
+ (addr
& SDLA_ADDR_MASK
));
173 spin_lock_irqsave(&sdla_lock
, flags
);
174 SDLA_WINDOW(dev
, addr
);
176 spin_unlock_irqrestore(&sdla_lock
, flags
);
181 static void sdla_stop(struct net_device
*dev
)
183 struct frad_local
*flp
;
185 flp
= netdev_priv(dev
);
189 outb(SDLA_S502A_HALT
, dev
->base_addr
+ SDLA_REG_CONTROL
);
190 flp
->state
= SDLA_HALT
;
193 outb(SDLA_HALT
, dev
->base_addr
+ SDLA_REG_Z80_CONTROL
);
194 outb(SDLA_S502E_ENABLE
, dev
->base_addr
+ SDLA_REG_CONTROL
);
195 flp
->state
= SDLA_S502E_ENABLE
;
198 flp
->state
&= ~SDLA_CPUEN
;
199 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
202 flp
->state
&= ~SDLA_CPUEN
;
203 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
208 static void sdla_start(struct net_device
*dev
)
210 struct frad_local
*flp
;
212 flp
= netdev_priv(dev
);
216 outb(SDLA_S502A_NMI
, dev
->base_addr
+ SDLA_REG_CONTROL
);
217 outb(SDLA_S502A_START
, dev
->base_addr
+ SDLA_REG_CONTROL
);
218 flp
->state
= SDLA_S502A_START
;
221 outb(SDLA_S502E_CPUEN
, dev
->base_addr
+ SDLA_REG_Z80_CONTROL
);
222 outb(0x00, dev
->base_addr
+ SDLA_REG_CONTROL
);
226 flp
->state
|= SDLA_CPUEN
;
227 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
230 flp
->state
|= SDLA_CPUEN
;
231 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
236 /****************************************************
238 * this is used for the S502A/E cards to determine
239 * the speed of the onboard CPU. Calibration is
240 * necessary for the Frame Relay code uploaded
241 * later. Incorrect results cause timing problems
242 * with link checks & status messages
244 ***************************************************/
246 static int sdla_z80_poll(struct net_device
*dev
, int z80_addr
, int jiffs
, char resp1
, char resp2
)
248 unsigned long start
, done
, now
;
251 start
= now
= jiffies
;
252 done
= jiffies
+ jiffs
;
254 temp
= (void *)dev
->mem_start
;
255 temp
+= z80_addr
& SDLA_ADDR_MASK
;
258 while (time_before(jiffies
, done
) && (resp
!= resp1
) && (!resp2
|| (resp
!= resp2
)))
262 SDLA_WINDOW(dev
, z80_addr
);
267 return time_before(jiffies
, done
) ? jiffies
- start
: -1;
270 /* constants for Z80 CPU speed */
271 #define Z80_READY '1' /* Z80 is ready to begin */
272 #define LOADER_READY '2' /* driver is ready to begin */
273 #define Z80_SCC_OK '3' /* SCC is on board */
274 #define Z80_SCC_BAD '4' /* SCC was not found */
276 static int sdla_cpuspeed(struct net_device
*dev
, struct ifreq
*ifr
)
282 if (sdla_z80_poll(dev
, 0, 3*HZ
, Z80_READY
, 0) < 0)
286 sdla_write(dev
, 0, &data
, 1);
288 if ((jiffs
= sdla_z80_poll(dev
, 0, 8*HZ
, Z80_SCC_OK
, Z80_SCC_BAD
)) < 0)
292 sdla_read(dev
, 0, &data
, 1);
294 if (data
== Z80_SCC_BAD
)
296 printk("%s: SCC bad\n", dev
->name
);
300 if (data
!= Z80_SCC_OK
)
304 ifr
->ifr_mtu
= SDLA_CPU_16M
;
305 else if (jiffs
< 220)
306 ifr
->ifr_mtu
= SDLA_CPU_10M
;
307 else if (jiffs
< 258)
308 ifr
->ifr_mtu
= SDLA_CPU_8M
;
309 else if (jiffs
< 357)
310 ifr
->ifr_mtu
= SDLA_CPU_7M
;
311 else if (jiffs
< 467)
312 ifr
->ifr_mtu
= SDLA_CPU_5M
;
314 ifr
->ifr_mtu
= SDLA_CPU_3M
;
319 /************************************************
321 * Direct interaction with the Frame Relay code
324 ************************************************/
335 struct _dlci_stat dlcis
[SDLA_MAX_DLCI
];
338 static void sdla_errors(struct net_device
*dev
, int cmd
, int dlci
, int ret
, int len
, void *data
)
340 struct _dlci_stat
*pstatus
;
343 char *state
, line
[30];
349 if (*state
& SDLA_MODEM_DCD_LOW
)
350 netdev_info(dev
, "Modem DCD unexpectedly low!\n");
351 if (*state
& SDLA_MODEM_CTS_LOW
)
352 netdev_info(dev
, "Modem CTS unexpectedly low!\n");
353 /* I should probably do something about this! */
356 case SDLA_RET_CHANNEL_OFF
:
357 netdev_info(dev
, "Channel became inoperative!\n");
361 case SDLA_RET_CHANNEL_ON
:
362 netdev_info(dev
, "Channel became operative!\n");
366 case SDLA_RET_DLCI_STATUS
:
367 netdev_info(dev
, "Status change reported by Access Node\n");
368 len
/= sizeof(struct _dlci_stat
);
369 for(pstatus
= data
, i
=0;i
< len
;i
++,pstatus
++)
371 if (pstatus
->flags
& SDLA_DLCI_NEW
)
373 else if (pstatus
->flags
& SDLA_DLCI_DELETED
)
375 else if (pstatus
->flags
& SDLA_DLCI_ACTIVE
)
379 sprintf(line
, "unknown status: %02X", pstatus
->flags
);
382 netdev_info(dev
, "DLCI %i: %s\n",
383 pstatus
->dlci
, state
);
388 case SDLA_RET_DLCI_UNKNOWN
:
389 netdev_info(dev
, "Received unknown DLCIs:");
390 len
/= sizeof(short);
391 for(pdlci
= data
,i
=0;i
< len
;i
++,pdlci
++)
392 pr_cont(" %i", *pdlci
);
396 case SDLA_RET_TIMEOUT
:
397 netdev_err(dev
, "Command timed out!\n");
400 case SDLA_RET_BUF_OVERSIZE
:
401 netdev_info(dev
, "Bc/CIR overflow, acceptable size is %i\n",
405 case SDLA_RET_BUF_TOO_BIG
:
406 netdev_info(dev
, "Buffer size over specified max of %i\n",
410 case SDLA_RET_CHANNEL_INACTIVE
:
411 case SDLA_RET_DLCI_INACTIVE
:
412 case SDLA_RET_CIR_OVERFLOW
:
413 case SDLA_RET_NO_BUFS
:
414 if (cmd
== SDLA_INFORMATION_WRITE
)
416 /* Else, fall through */
419 netdev_dbg(dev
, "Cmd 0x%02X generated return code 0x%02X\n",
421 /* Further processing could be done here */
426 static int sdla_cmd(struct net_device
*dev
, int cmd
, short dlci
, short flags
,
427 void *inbuf
, short inlen
, void *outbuf
, short *outlen
)
429 static struct _frad_stat status
;
430 struct frad_local
*flp
;
431 struct sdla_cmd
*cmd_buf
;
432 unsigned long pflags
;
434 int ret
, waiting
, len
;
437 flp
= netdev_priv(dev
);
438 window
= flp
->type
== SDLA_S508
? SDLA_508_CMD_BUF
: SDLA_502_CMD_BUF
;
439 cmd_buf
= (struct sdla_cmd
*)(dev
->mem_start
+ (window
& SDLA_ADDR_MASK
));
442 jiffs
= jiffies
+ HZ
; /* 1 second is plenty */
444 spin_lock_irqsave(&sdla_lock
, pflags
);
445 SDLA_WINDOW(dev
, window
);
447 cmd_buf
->dlci
= dlci
;
448 cmd_buf
->flags
= flags
;
451 memcpy(cmd_buf
->data
, inbuf
, inlen
);
453 cmd_buf
->length
= inlen
;
455 cmd_buf
->opp_flag
= 1;
456 spin_unlock_irqrestore(&sdla_lock
, pflags
);
460 while (waiting
&& time_before_eq(jiffies
, jiffs
))
464 spin_lock_irqsave(&sdla_lock
, pflags
);
465 SDLA_WINDOW(dev
, window
);
466 waiting
= ((volatile int)(cmd_buf
->opp_flag
));
467 spin_unlock_irqrestore(&sdla_lock
, pflags
);
474 spin_lock_irqsave(&sdla_lock
, pflags
);
475 SDLA_WINDOW(dev
, window
);
476 ret
= cmd_buf
->retval
;
477 len
= cmd_buf
->length
;
478 if (outbuf
&& outlen
)
480 *outlen
= *outlen
>= len
? len
: *outlen
;
483 memcpy(outbuf
, cmd_buf
->data
, *outlen
);
486 /* This is a local copy that's used for error handling */
488 memcpy(&status
, cmd_buf
->data
, len
> sizeof(status
) ? sizeof(status
) : len
);
490 spin_unlock_irqrestore(&sdla_lock
, pflags
);
493 ret
= SDLA_RET_TIMEOUT
;
495 if (ret
!= SDLA_RET_OK
)
496 sdla_errors(dev
, cmd
, dlci
, ret
, len
, &status
);
501 /***********************************************
503 * these functions are called by the DLCI driver
505 ***********************************************/
507 static int sdla_reconfig(struct net_device
*dev
);
509 static int sdla_activate(struct net_device
*slave
, struct net_device
*master
)
511 struct frad_local
*flp
;
514 flp
= netdev_priv(slave
);
516 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
517 if (flp
->master
[i
] == master
)
520 if (i
== CONFIG_DLCI_MAX
)
523 flp
->dlci
[i
] = abs(flp
->dlci
[i
]);
525 if (netif_running(slave
) && (flp
->config
.station
== FRAD_STATION_NODE
))
526 sdla_cmd(slave
, SDLA_ACTIVATE_DLCI
, 0, 0, &flp
->dlci
[i
], sizeof(short), NULL
, NULL
);
531 static int sdla_deactivate(struct net_device
*slave
, struct net_device
*master
)
533 struct frad_local
*flp
;
536 flp
= netdev_priv(slave
);
538 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
539 if (flp
->master
[i
] == master
)
542 if (i
== CONFIG_DLCI_MAX
)
545 flp
->dlci
[i
] = -abs(flp
->dlci
[i
]);
547 if (netif_running(slave
) && (flp
->config
.station
== FRAD_STATION_NODE
))
548 sdla_cmd(slave
, SDLA_DEACTIVATE_DLCI
, 0, 0, &flp
->dlci
[i
], sizeof(short), NULL
, NULL
);
553 static int sdla_assoc(struct net_device
*slave
, struct net_device
*master
)
555 struct frad_local
*flp
;
558 if (master
->type
!= ARPHRD_DLCI
)
561 flp
= netdev_priv(slave
);
563 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
567 if (abs(flp
->dlci
[i
]) == *(short *)(master
->dev_addr
))
571 if (i
== CONFIG_DLCI_MAX
)
572 return -EMLINK
; /* #### Alan: Comments on this ?? */
575 flp
->master
[i
] = master
;
576 flp
->dlci
[i
] = -*(short *)(master
->dev_addr
);
577 master
->mtu
= slave
->mtu
;
579 if (netif_running(slave
)) {
580 if (flp
->config
.station
== FRAD_STATION_CPE
)
581 sdla_reconfig(slave
);
583 sdla_cmd(slave
, SDLA_ADD_DLCI
, 0, 0, master
->dev_addr
, sizeof(short), NULL
, NULL
);
589 static int sdla_deassoc(struct net_device
*slave
, struct net_device
*master
)
591 struct frad_local
*flp
;
594 flp
= netdev_priv(slave
);
596 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
597 if (flp
->master
[i
] == master
)
600 if (i
== CONFIG_DLCI_MAX
)
603 flp
->master
[i
] = NULL
;
607 if (netif_running(slave
)) {
608 if (flp
->config
.station
== FRAD_STATION_CPE
)
609 sdla_reconfig(slave
);
611 sdla_cmd(slave
, SDLA_DELETE_DLCI
, 0, 0, master
->dev_addr
, sizeof(short), NULL
, NULL
);
617 static int sdla_dlci_conf(struct net_device
*slave
, struct net_device
*master
, int get
)
619 struct frad_local
*flp
;
620 struct dlci_local
*dlp
;
624 flp
= netdev_priv(slave
);
626 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
627 if (flp
->master
[i
] == master
)
630 if (i
== CONFIG_DLCI_MAX
)
633 dlp
= netdev_priv(master
);
636 len
= sizeof(struct dlci_conf
);
637 if (netif_running(slave
)) {
639 ret
= sdla_cmd(slave
, SDLA_READ_DLCI_CONFIGURATION
, abs(flp
->dlci
[i
]), 0,
640 NULL
, 0, &dlp
->config
, &len
);
642 ret
= sdla_cmd(slave
, SDLA_SET_DLCI_CONFIGURATION
, abs(flp
->dlci
[i
]), 0,
643 &dlp
->config
, sizeof(struct dlci_conf
) - 4 * sizeof(short), NULL
, NULL
);
646 return ret
== SDLA_RET_OK
? 0 : -EIO
;
649 /**************************
651 * now for the Linux driver
653 **************************/
655 /* NOTE: the DLCI driver deals with freeing the SKB!! */
656 static netdev_tx_t
sdla_transmit(struct sk_buff
*skb
,
657 struct net_device
*dev
)
659 struct frad_local
*flp
;
660 int ret
, addr
, accept
, i
;
663 struct buf_entry
*pbuf
;
665 flp
= netdev_priv(dev
);
669 netif_stop_queue(dev
);
672 * stupid GateD insists on setting up the multicast router thru us
673 * and we're ill equipped to handle a non Frame Relay packet at this
681 if (skb
->dev
->type
!= ARPHRD_DLCI
)
683 netdev_warn(dev
, "Non DLCI device, type %i, tried to send on FRAD module\n",
689 netdev_warn(dev
, "unknown firmware type 0x%04X\n",
696 /* this is frame specific, but till there's a PPP module, it's the default */
701 ret
= sdla_cmd(dev
, SDLA_INFORMATION_WRITE
, *(short *)(skb
->dev
->dev_addr
), 0, skb
->data
, skb
->len
, NULL
, NULL
);
705 ret
= sdla_cmd(dev
, SDLA_INFORMATION_WRITE
, *(short *)(skb
->dev
->dev_addr
), 0, NULL
, skb
->len
, &addr
, &size
);
706 if (ret
== SDLA_RET_OK
)
709 spin_lock_irqsave(&sdla_lock
, flags
);
710 SDLA_WINDOW(dev
, addr
);
711 pbuf
= (void *)(dev
->mem_start
+ (addr
& SDLA_ADDR_MASK
));
712 __sdla_write(dev
, pbuf
->buf_addr
, skb
->data
, skb
->len
);
713 SDLA_WINDOW(dev
, addr
);
715 spin_unlock_irqrestore(&sdla_lock
, flags
);
723 dev
->stats
.tx_packets
++;
726 case SDLA_RET_CIR_OVERFLOW
:
727 case SDLA_RET_BUF_OVERSIZE
:
728 case SDLA_RET_NO_BUFS
:
729 dev
->stats
.tx_dropped
++;
733 dev
->stats
.tx_errors
++;
737 netif_wake_queue(dev
);
738 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
740 if(flp
->master
[i
]!=NULL
)
741 netif_wake_queue(flp
->master
[i
]);
748 static void sdla_receive(struct net_device
*dev
)
750 struct net_device
*master
;
751 struct frad_local
*flp
;
752 struct dlci_local
*dlp
;
755 struct sdla_cmd
*cmd
;
756 struct buf_info
*pbufi
;
757 struct buf_entry
*pbuf
;
760 int i
=0, received
, success
, addr
, buf_base
, buf_top
;
761 short dlci
, len
, len2
, split
;
763 flp
= netdev_priv(dev
);
765 received
= addr
= buf_top
= buf_base
= 0;
773 spin_lock_irqsave(&sdla_lock
, flags
);
779 cmd
= (void *) (dev
->mem_start
+ (SDLA_502_RCV_BUF
& SDLA_ADDR_MASK
));
780 SDLA_WINDOW(dev
, SDLA_502_RCV_BUF
);
781 success
= cmd
->opp_flag
;
790 pbufi
= (void *) (dev
->mem_start
+ (SDLA_508_RXBUF_INFO
& SDLA_ADDR_MASK
));
791 SDLA_WINDOW(dev
, SDLA_508_RXBUF_INFO
);
792 pbuf
= (void *) (dev
->mem_start
+ ((pbufi
->rse_base
+ flp
->buffer
* sizeof(struct buf_entry
)) & SDLA_ADDR_MASK
));
793 success
= pbuf
->opp_flag
;
797 buf_top
= pbufi
->buf_top
;
798 buf_base
= pbufi
->buf_base
;
801 addr
= pbuf
->buf_addr
;
805 /* common code, find the DLCI and get the SKB */
808 for (i
=0;i
<CONFIG_DLCI_MAX
;i
++)
809 if (flp
->dlci
[i
] == dlci
)
812 if (i
== CONFIG_DLCI_MAX
)
814 netdev_notice(dev
, "Received packet from invalid DLCI %i, ignoring\n",
816 dev
->stats
.rx_errors
++;
823 master
= flp
->master
[i
];
824 skb
= dev_alloc_skb(len
+ sizeof(struct frhdr
));
827 netdev_notice(dev
, "Memory squeeze, dropping packet\n");
828 dev
->stats
.rx_dropped
++;
832 skb_reserve(skb
, sizeof(struct frhdr
));
835 /* pick up the data */
841 __sdla_read(dev
, SDLA_502_RCV_BUF
+ SDLA_502_DATA_OFS
, skb_put(skb
,len
), len
);
843 SDLA_WINDOW(dev
, SDLA_502_RCV_BUF
);
850 /* is this buffer split off the end of the internal ring buffer */
851 split
= addr
+ len
> buf_top
+ 1 ? len
- (buf_top
- addr
+ 1) : 0;
854 __sdla_read(dev
, addr
, skb_put(skb
, len2
), len2
);
856 __sdla_read(dev
, buf_base
, skb_put(skb
, split
), split
);
859 /* increment the buffer we're looking at */
860 SDLA_WINDOW(dev
, SDLA_508_RXBUF_INFO
);
861 flp
->buffer
= (flp
->buffer
+ 1) % pbufi
->rse_num
;
868 dev
->stats
.rx_packets
++;
869 dlp
= netdev_priv(master
);
870 (*dlp
->receive
)(skb
, master
);
873 spin_unlock_irqrestore(&sdla_lock
, flags
);
876 static irqreturn_t
sdla_isr(int dummy
, void *dev_id
)
878 struct net_device
*dev
;
879 struct frad_local
*flp
;
884 flp
= netdev_priv(dev
);
886 if (!flp
->initialized
)
888 netdev_warn(dev
, "irq %d for uninitialized device\n", dev
->irq
);
892 byte
= sdla_byte(dev
, flp
->type
== SDLA_S508
? SDLA_508_IRQ_INTERFACE
: SDLA_502_IRQ_INTERFACE
);
899 /* the command will get an error return, which is processed above */
900 case SDLA_INTR_MODEM
:
901 case SDLA_INTR_STATUS
:
902 sdla_cmd(dev
, SDLA_READ_DLC_STATUS
, 0, 0, NULL
, 0, NULL
, NULL
);
906 case SDLA_INTR_COMPLETE
:
907 case SDLA_INTR_TIMER
:
908 netdev_warn(dev
, "invalid irq flag 0x%02X\n", byte
);
912 /* the S502E requires a manual acknowledgement of the interrupt */
913 if (flp
->type
== SDLA_S502E
)
915 flp
->state
&= ~SDLA_S502E_INTACK
;
916 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
917 flp
->state
|= SDLA_S502E_INTACK
;
918 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
921 /* this clears the byte, informing the Z80 we're done */
923 sdla_write(dev
, flp
->type
== SDLA_S508
? SDLA_508_IRQ_INTERFACE
: SDLA_502_IRQ_INTERFACE
, &byte
, sizeof(byte
));
927 static void sdla_poll(struct timer_list
*t
)
929 struct frad_local
*flp
= from_timer(flp
, t
, timer
);
930 struct net_device
*dev
= flp
->dev
;
932 if (sdla_byte(dev
, SDLA_502_RCV_BUF
))
935 flp
->timer
.expires
= 1;
936 add_timer(&flp
->timer
);
939 static int sdla_close(struct net_device
*dev
)
941 struct frad_local
*flp
;
942 struct intr_info intr
;
944 short dlcis
[CONFIG_DLCI_MAX
];
946 flp
= netdev_priv(dev
);
949 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
951 dlcis
[len
++] = abs(flp
->dlci
[i
]);
954 if (flp
->config
.station
== FRAD_STATION_NODE
)
956 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
957 if (flp
->dlci
[i
] > 0)
958 sdla_cmd(dev
, SDLA_DEACTIVATE_DLCI
, 0, 0, dlcis
, len
, NULL
, NULL
);
959 sdla_cmd(dev
, SDLA_DELETE_DLCI
, 0, 0, &flp
->dlci
[i
], sizeof(flp
->dlci
[i
]), NULL
, NULL
);
962 memset(&intr
, 0, sizeof(intr
));
963 /* let's start up the reception */
967 del_timer(&flp
->timer
);
971 sdla_cmd(dev
, SDLA_SET_IRQ_TRIGGER
, 0, 0, &intr
, sizeof(char) + sizeof(short), NULL
, NULL
);
972 flp
->state
&= ~SDLA_S502E_INTACK
;
973 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
980 sdla_cmd(dev
, SDLA_SET_IRQ_TRIGGER
, 0, 0, &intr
, sizeof(struct intr_info
), NULL
, NULL
);
981 flp
->state
&= ~SDLA_S508_INTEN
;
982 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
986 sdla_cmd(dev
, SDLA_DISABLE_COMMUNICATIONS
, 0, 0, NULL
, 0, NULL
, NULL
);
988 netif_stop_queue(dev
);
994 struct frad_conf config
;
995 short dlci
[CONFIG_DLCI_MAX
];
998 static int sdla_open(struct net_device
*dev
)
1000 struct frad_local
*flp
;
1001 struct dlci_local
*dlp
;
1002 struct conf_data data
;
1003 struct intr_info intr
;
1007 flp
= netdev_priv(dev
);
1009 if (!flp
->initialized
)
1012 if (!flp
->configured
)
1015 /* time to send in the configuration */
1017 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
1019 data
.dlci
[len
++] = abs(flp
->dlci
[i
]);
1022 memcpy(&data
.config
, &flp
->config
, sizeof(struct frad_conf
));
1023 len
+= sizeof(struct frad_conf
);
1025 sdla_cmd(dev
, SDLA_DISABLE_COMMUNICATIONS
, 0, 0, NULL
, 0, NULL
, NULL
);
1026 sdla_cmd(dev
, SDLA_SET_DLCI_CONFIGURATION
, 0, 0, &data
, len
, NULL
, NULL
);
1028 if (flp
->type
== SDLA_S508
)
1031 sdla_cmd(dev
, SDLA_ENABLE_COMMUNICATIONS
, 0, 0, NULL
, 0, NULL
, NULL
);
1033 /* let's start up the reception */
1034 memset(&intr
, 0, sizeof(intr
));
1038 flp
->timer
.expires
= 1;
1039 add_timer(&flp
->timer
);
1043 flp
->state
|= SDLA_S502E_ENABLE
;
1044 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
1045 flp
->state
|= SDLA_S502E_INTACK
;
1046 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
1048 sdla_write(dev
, SDLA_502_IRQ_INTERFACE
, &byte
, sizeof(byte
));
1049 intr
.flags
= SDLA_INTR_RX
| SDLA_INTR_STATUS
| SDLA_INTR_MODEM
;
1050 sdla_cmd(dev
, SDLA_SET_IRQ_TRIGGER
, 0, 0, &intr
, sizeof(char) + sizeof(short), NULL
, NULL
);
1057 flp
->state
|= SDLA_S508_INTEN
;
1058 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
1060 sdla_write(dev
, SDLA_508_IRQ_INTERFACE
, &byte
, sizeof(byte
));
1061 intr
.flags
= SDLA_INTR_RX
| SDLA_INTR_STATUS
| SDLA_INTR_MODEM
;
1062 intr
.irq
= dev
->irq
;
1063 sdla_cmd(dev
, SDLA_SET_IRQ_TRIGGER
, 0, 0, &intr
, sizeof(struct intr_info
), NULL
, NULL
);
1067 if (flp
->config
.station
== FRAD_STATION_CPE
)
1069 byte
= SDLA_ICS_STATUS_ENQ
;
1070 sdla_cmd(dev
, SDLA_ISSUE_IN_CHANNEL_SIGNAL
, 0, 0, &byte
, sizeof(byte
), NULL
, NULL
);
1074 sdla_cmd(dev
, SDLA_ADD_DLCI
, 0, 0, data
.dlci
, len
- sizeof(struct frad_conf
), NULL
, NULL
);
1075 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
1076 if (flp
->dlci
[i
] > 0)
1077 sdla_cmd(dev
, SDLA_ACTIVATE_DLCI
, 0, 0, &flp
->dlci
[i
], 2*sizeof(flp
->dlci
[i
]), NULL
, NULL
);
1080 /* configure any specific DLCI settings */
1081 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
1084 dlp
= netdev_priv(flp
->master
[i
]);
1085 if (dlp
->configured
)
1086 sdla_cmd(dev
, SDLA_SET_DLCI_CONFIGURATION
, abs(flp
->dlci
[i
]), 0, &dlp
->config
, sizeof(struct dlci_conf
), NULL
, NULL
);
1089 netif_start_queue(dev
);
1094 static int sdla_config(struct net_device
*dev
, struct frad_conf __user
*conf
, int get
)
1096 struct frad_local
*flp
;
1097 struct conf_data data
;
1101 if (dev
->type
== 0xFFFF)
1104 flp
= netdev_priv(dev
);
1108 if (netif_running(dev
))
1111 if(copy_from_user(&data
.config
, conf
, sizeof(struct frad_conf
)))
1114 if (data
.config
.station
& ~FRAD_STATION_NODE
)
1117 if (data
.config
.flags
& ~FRAD_VALID_FLAGS
)
1120 if ((data
.config
.kbaud
< 0) ||
1121 ((data
.config
.kbaud
> 128) && (flp
->type
!= SDLA_S508
)))
1124 if (data
.config
.clocking
& ~(FRAD_CLOCK_INT
| SDLA_S508_PORT_RS232
))
1127 if ((data
.config
.mtu
< 0) || (data
.config
.mtu
> SDLA_MAX_MTU
))
1130 if ((data
.config
.T391
< 5) || (data
.config
.T391
> 30))
1133 if ((data
.config
.T392
< 5) || (data
.config
.T392
> 30))
1136 if ((data
.config
.N391
< 1) || (data
.config
.N391
> 255))
1139 if ((data
.config
.N392
< 1) || (data
.config
.N392
> 10))
1142 if ((data
.config
.N393
< 1) || (data
.config
.N393
> 10))
1145 memcpy(&flp
->config
, &data
.config
, sizeof(struct frad_conf
));
1146 flp
->config
.flags
|= SDLA_DIRECT_RECV
;
1148 if (flp
->type
== SDLA_S508
)
1149 flp
->config
.flags
|= SDLA_TX70_RX30
;
1151 if (dev
->mtu
!= flp
->config
.mtu
)
1153 /* this is required to change the MTU */
1154 dev
->mtu
= flp
->config
.mtu
;
1155 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
1157 flp
->master
[i
]->mtu
= flp
->config
.mtu
;
1160 flp
->config
.mtu
+= sizeof(struct frhdr
);
1162 /* off to the races! */
1163 if (!flp
->configured
)
1166 flp
->configured
= 1;
1170 /* no sense reading if the CPU isn't started */
1171 if (netif_running(dev
))
1173 size
= sizeof(data
);
1174 if (sdla_cmd(dev
, SDLA_READ_DLCI_CONFIGURATION
, 0, 0, NULL
, 0, &data
, &size
) != SDLA_RET_OK
)
1178 if (flp
->configured
)
1179 memcpy(&data
.config
, &flp
->config
, sizeof(struct frad_conf
));
1181 memset(&data
.config
, 0, sizeof(struct frad_conf
));
1183 memcpy(&flp
->config
, &data
.config
, sizeof(struct frad_conf
));
1184 data
.config
.flags
&= FRAD_VALID_FLAGS
;
1185 data
.config
.mtu
-= data
.config
.mtu
> sizeof(struct frhdr
) ? sizeof(struct frhdr
) : data
.config
.mtu
;
1186 return copy_to_user(conf
, &data
.config
, sizeof(struct frad_conf
))?-EFAULT
:0;
1192 static int sdla_xfer(struct net_device
*dev
, struct sdla_mem __user
*info
, int read
)
1194 struct sdla_mem mem
;
1197 if(copy_from_user(&mem
, info
, sizeof(mem
)))
1202 temp
= kzalloc(mem
.len
, GFP_KERNEL
);
1205 sdla_read(dev
, mem
.addr
, temp
, mem
.len
);
1206 if(copy_to_user(mem
.data
, temp
, mem
.len
))
1215 temp
= memdup_user(mem
.data
, mem
.len
);
1217 return PTR_ERR(temp
);
1218 sdla_write(dev
, mem
.addr
, temp
, mem
.len
);
1224 static int sdla_reconfig(struct net_device
*dev
)
1226 struct frad_local
*flp
;
1227 struct conf_data data
;
1230 flp
= netdev_priv(dev
);
1233 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
1235 data
.dlci
[len
++] = flp
->dlci
[i
];
1238 memcpy(&data
, &flp
->config
, sizeof(struct frad_conf
));
1239 len
+= sizeof(struct frad_conf
);
1241 sdla_cmd(dev
, SDLA_DISABLE_COMMUNICATIONS
, 0, 0, NULL
, 0, NULL
, NULL
);
1242 sdla_cmd(dev
, SDLA_SET_DLCI_CONFIGURATION
, 0, 0, &data
, len
, NULL
, NULL
);
1243 sdla_cmd(dev
, SDLA_ENABLE_COMMUNICATIONS
, 0, 0, NULL
, 0, NULL
, NULL
);
1248 static int sdla_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
1250 struct frad_local
*flp
;
1252 if(!capable(CAP_NET_ADMIN
))
1255 flp
= netdev_priv(dev
);
1257 if (!flp
->initialized
)
1264 return sdla_config(dev
, ifr
->ifr_data
, cmd
== FRAD_GET_CONF
);
1267 ifr
->ifr_flags
= flp
->type
;
1271 return sdla_cpuspeed(dev
, ifr
);
1273 /* ==========================================================
1274 NOTE: This is rather a useless action right now, as the
1275 current driver does not support protocols other than
1276 FR. However, Sangoma has modules for a number of
1277 other protocols in the works.
1278 ============================================================*/
1280 if (flp
->configured
)
1283 switch (ifr
->ifr_flags
)
1286 dev
->type
= ifr
->ifr_flags
;
1289 return -ENOPROTOOPT
;
1299 if(!capable(CAP_SYS_RAWIO
))
1301 return sdla_xfer(dev
, ifr
->ifr_data
, cmd
== SDLA_READMEM
);
1317 static int sdla_change_mtu(struct net_device
*dev
, int new_mtu
)
1319 if (netif_running(dev
))
1322 /* for now, you can't change the MTU! */
1326 static int sdla_set_config(struct net_device
*dev
, struct ifmap
*map
)
1328 struct frad_local
*flp
;
1334 flp
= netdev_priv(dev
);
1336 if (flp
->initialized
)
1339 for(i
=0; i
< ARRAY_SIZE(valid_port
); i
++)
1340 if (valid_port
[i
] == map
->base_addr
)
1343 if (i
== ARRAY_SIZE(valid_port
))
1346 if (!request_region(map
->base_addr
, SDLA_IO_EXTENTS
, dev
->name
)){
1347 pr_warn("io-port 0x%04lx in use\n", dev
->base_addr
);
1350 base
= map
->base_addr
;
1352 /* test for card types, S502A, S502E, S507, S508 */
1353 /* these tests shut down the card completely, so clear the state */
1354 flp
->type
= SDLA_UNKNOWN
;
1357 for(i
=1;i
<SDLA_IO_EXTENTS
;i
++)
1358 if (inb(base
+ i
) != 0xFF)
1361 if (i
== SDLA_IO_EXTENTS
) {
1362 outb(SDLA_HALT
, base
+ SDLA_REG_Z80_CONTROL
);
1363 if ((inb(base
+ SDLA_S502_STS
) & 0x0F) == 0x08) {
1364 outb(SDLA_S502E_INTACK
, base
+ SDLA_REG_CONTROL
);
1365 if ((inb(base
+ SDLA_S502_STS
) & 0x0F) == 0x0C) {
1366 outb(SDLA_HALT
, base
+ SDLA_REG_CONTROL
);
1367 flp
->type
= SDLA_S502E
;
1373 for(byte
=inb(base
),i
=0;i
<SDLA_IO_EXTENTS
;i
++)
1374 if (inb(base
+ i
) != byte
)
1377 if (i
== SDLA_IO_EXTENTS
) {
1378 outb(SDLA_HALT
, base
+ SDLA_REG_CONTROL
);
1379 if ((inb(base
+ SDLA_S502_STS
) & 0x7E) == 0x30) {
1380 outb(SDLA_S507_ENABLE
, base
+ SDLA_REG_CONTROL
);
1381 if ((inb(base
+ SDLA_S502_STS
) & 0x7E) == 0x32) {
1382 outb(SDLA_HALT
, base
+ SDLA_REG_CONTROL
);
1383 flp
->type
= SDLA_S507
;
1389 outb(SDLA_HALT
, base
+ SDLA_REG_CONTROL
);
1390 if ((inb(base
+ SDLA_S508_STS
) & 0x3F) == 0x00) {
1391 outb(SDLA_S508_INTEN
, base
+ SDLA_REG_CONTROL
);
1392 if ((inb(base
+ SDLA_S508_STS
) & 0x3F) == 0x10) {
1393 outb(SDLA_HALT
, base
+ SDLA_REG_CONTROL
);
1394 flp
->type
= SDLA_S508
;
1399 outb(SDLA_S502A_HALT
, base
+ SDLA_REG_CONTROL
);
1400 if (inb(base
+ SDLA_S502_STS
) == 0x40) {
1401 outb(SDLA_S502A_START
, base
+ SDLA_REG_CONTROL
);
1402 if (inb(base
+ SDLA_S502_STS
) == 0x40) {
1403 outb(SDLA_S502A_INTEN
, base
+ SDLA_REG_CONTROL
);
1404 if (inb(base
+ SDLA_S502_STS
) == 0x44) {
1405 outb(SDLA_S502A_START
, base
+ SDLA_REG_CONTROL
);
1406 flp
->type
= SDLA_S502A
;
1412 netdev_notice(dev
, "Unknown card type\n");
1422 if (flp
->type
!= SDLA_S508
&& flp
->type
!= SDLA_S507
)
1428 if (flp
->type
!= SDLA_S502E
)
1437 if (flp
->type
!= SDLA_S508
&& flp
->type
!= SDLA_S507
)
1443 if (flp
->type
== SDLA_S502A
)
1452 if (request_irq(dev
->irq
, sdla_isr
, 0, dev
->name
, dev
))
1455 if (flp
->type
== SDLA_S507
) {
1458 flp
->state
= SDLA_S507_IRQ3
;
1461 flp
->state
= SDLA_S507_IRQ4
;
1464 flp
->state
= SDLA_S507_IRQ5
;
1467 flp
->state
= SDLA_S507_IRQ7
;
1470 flp
->state
= SDLA_S507_IRQ10
;
1473 flp
->state
= SDLA_S507_IRQ11
;
1476 flp
->state
= SDLA_S507_IRQ12
;
1479 flp
->state
= SDLA_S507_IRQ15
;
1484 for(i
=0; i
< ARRAY_SIZE(valid_mem
); i
++)
1485 if (valid_mem
[i
] == map
->mem_start
)
1489 if (i
== ARRAY_SIZE(valid_mem
))
1492 if (flp
->type
== SDLA_S502A
&& (map
->mem_start
& 0xF000) >> 12 == 0x0E)
1495 if (flp
->type
!= SDLA_S507
&& map
->mem_start
>> 16 == 0x0B)
1498 if (flp
->type
== SDLA_S507
&& map
->mem_start
>> 16 == 0x0D)
1501 byte
= flp
->type
!= SDLA_S508
? SDLA_8K_WINDOW
: 0;
1502 byte
|= (map
->mem_start
& 0xF000) >> (12 + (flp
->type
== SDLA_S508
? 1 : 0));
1506 switch (map
->mem_start
>> 16) {
1508 byte
|= SDLA_S502_SEG_A
;
1511 byte
|= SDLA_S502_SEG_C
;
1514 byte
|= SDLA_S502_SEG_D
;
1517 byte
|= SDLA_S502_SEG_E
;
1522 switch (map
->mem_start
>> 16) {
1524 byte
|= SDLA_S507_SEG_A
;
1527 byte
|= SDLA_S507_SEG_B
;
1530 byte
|= SDLA_S507_SEG_C
;
1533 byte
|= SDLA_S507_SEG_E
;
1538 switch (map
->mem_start
>> 16) {
1540 byte
|= SDLA_S508_SEG_A
;
1543 byte
|= SDLA_S508_SEG_C
;
1546 byte
|= SDLA_S508_SEG_D
;
1549 byte
|= SDLA_S508_SEG_E
;
1555 /* set the memory bits, and enable access */
1556 outb(byte
, base
+ SDLA_REG_PC_WINDOW
);
1561 flp
->state
= SDLA_S502E_ENABLE
;
1564 flp
->state
|= SDLA_MEMEN
;
1567 flp
->state
= SDLA_MEMEN
;
1570 outb(flp
->state
, base
+ SDLA_REG_CONTROL
);
1572 dev
->irq
= map
->irq
;
1573 dev
->base_addr
= base
;
1574 dev
->mem_start
= map
->mem_start
;
1575 dev
->mem_end
= dev
->mem_start
+ 0x2000;
1576 flp
->initialized
= 1;
1580 free_irq(map
->irq
, dev
);
1582 release_region(base
, SDLA_IO_EXTENTS
);
1586 static const struct net_device_ops sdla_netdev_ops
= {
1587 .ndo_open
= sdla_open
,
1588 .ndo_stop
= sdla_close
,
1589 .ndo_do_ioctl
= sdla_ioctl
,
1590 .ndo_set_config
= sdla_set_config
,
1591 .ndo_start_xmit
= sdla_transmit
,
1592 .ndo_change_mtu
= sdla_change_mtu
,
1595 static void setup_sdla(struct net_device
*dev
)
1597 struct frad_local
*flp
= netdev_priv(dev
);
1599 netdev_boot_setup_check(dev
);
1601 dev
->netdev_ops
= &sdla_netdev_ops
;
1604 dev
->hard_header_len
= 0;
1606 dev
->mtu
= SDLA_MAX_MTU
;
1608 flp
->activate
= sdla_activate
;
1609 flp
->deactivate
= sdla_deactivate
;
1610 flp
->assoc
= sdla_assoc
;
1611 flp
->deassoc
= sdla_deassoc
;
1612 flp
->dlci_conf
= sdla_dlci_conf
;
1615 timer_setup(&flp
->timer
, sdla_poll
, 0);
1616 flp
->timer
.expires
= 1;
1619 static struct net_device
*sdla
;
1621 static int __init
init_sdla(void)
1625 printk("%s.\n", version
);
1627 sdla
= alloc_netdev(sizeof(struct frad_local
), "sdla0",
1628 NET_NAME_UNKNOWN
, setup_sdla
);
1632 err
= register_netdev(sdla
);
1639 static void __exit
exit_sdla(void)
1641 struct frad_local
*flp
= netdev_priv(sdla
);
1643 unregister_netdev(sdla
);
1644 if (flp
->initialized
) {
1645 free_irq(sdla
->irq
, sdla
);
1646 release_region(sdla
->base_addr
, SDLA_IO_EXTENTS
);
1648 del_timer_sync(&flp
->timer
);
1652 MODULE_LICENSE("GPL");
1654 module_init(init_sdla
);
1655 module_exit(exit_sdla
);