2 * SDLA An implementation of a driver for the Sangoma S502/S508 series
3 * multi-protocol PC interface card. Initial offering is with
4 * the DLCI driver, providing Frame Relay support for linux.
6 * Global definitions for the Frame relay interface.
8 * Version: @(#)sdla.c 0.30 12 Sep 1996
10 * Credits: Sangoma Technologies, for the use of 2 cards for an extended
12 * David Mandelstam <dm@sangoma.com> for getting me started on
13 * this project, and incentive to complete it.
14 * Gene Kozen <74604.152@compuserve.com> for providing me with
15 * important information about the cards.
17 * Author: Mike McLagan <mike.mclagan@linux.org>
20 * 0.15 Mike McLagan Improved error handling, packet dropping
21 * 0.20 Mike McLagan New transmit/receive flags for config
22 * If in FR mode, don't accept packets from
24 * 0.25 Mike McLagan Fixed problem with rejecting packets
25 * from non DLCI devices.
26 * 0.30 Mike McLagan Fixed kernel panic when used with modified
29 * This program is free software; you can redistribute it and/or
30 * modify it under the terms of the GNU General Public License
31 * as published by the Free Software Foundation; either version
32 * 2 of the License, or (at your option) any later version.
35 #include <linux/module.h>
36 #include <linux/kernel.h>
37 #include <linux/types.h>
38 #include <linux/fcntl.h>
39 #include <linux/interrupt.h>
40 #include <linux/ptrace.h>
41 #include <linux/ioport.h>
43 #include <linux/slab.h>
44 #include <linux/string.h>
45 #include <linux/timer.h>
46 #include <linux/errno.h>
47 #include <linux/init.h>
48 #include <linux/netdevice.h>
49 #include <linux/skbuff.h>
50 #include <linux/if_arp.h>
51 #include <linux/if_frad.h>
52 #include <linux/sdla.h>
53 #include <linux/bitops.h>
55 #include <asm/system.h>
58 #include <asm/uaccess.h>
60 static const char* version
= "SDLA driver v0.30, 12 Sep 1996, mike.mclagan@linux.org";
62 static unsigned int valid_port
[] = { 0x250, 0x270, 0x280, 0x300, 0x350, 0x360, 0x380, 0x390};
64 static unsigned int valid_mem
[] = {
65 0xA0000, 0xA2000, 0xA4000, 0xA6000, 0xA8000, 0xAA000, 0xAC000, 0xAE000,
66 0xB0000, 0xB2000, 0xB4000, 0xB6000, 0xB8000, 0xBA000, 0xBC000, 0xBE000,
67 0xC0000, 0xC2000, 0xC4000, 0xC6000, 0xC8000, 0xCA000, 0xCC000, 0xCE000,
68 0xD0000, 0xD2000, 0xD4000, 0xD6000, 0xD8000, 0xDA000, 0xDC000, 0xDE000,
69 0xE0000, 0xE2000, 0xE4000, 0xE6000, 0xE8000, 0xEA000, 0xEC000, 0xEE000};
71 static DEFINE_SPINLOCK(sdla_lock
);
73 /*********************************************************
75 * these are the core routines that access the card itself
77 *********************************************************/
79 #define SDLA_WINDOW(dev,addr) outb((((addr) >> 13) & 0x1F), (dev)->base_addr + SDLA_REG_Z80_WINDOW)
81 static void __sdla_read(struct net_device
*dev
, int addr
, void *buf
, short len
)
90 offset
= addr
& SDLA_ADDR_MASK
;
91 bytes
= offset
+ len
> SDLA_WINDOW_SIZE
? SDLA_WINDOW_SIZE
- offset
: len
;
92 base
= (const void *) (dev
->mem_start
+ offset
);
94 SDLA_WINDOW(dev
, addr
);
95 memcpy(temp
, base
, bytes
);
103 static void sdla_read(struct net_device
*dev
, int addr
, void *buf
, short len
)
106 spin_lock_irqsave(&sdla_lock
, flags
);
107 __sdla_read(dev
, addr
, buf
, len
);
108 spin_unlock_irqrestore(&sdla_lock
, flags
);
111 static void __sdla_write(struct net_device
*dev
, int addr
,
112 const void *buf
, short len
)
121 offset
= addr
& SDLA_ADDR_MASK
;
122 bytes
= offset
+ len
> SDLA_WINDOW_SIZE
? SDLA_WINDOW_SIZE
- offset
: len
;
123 base
= (void *) (dev
->mem_start
+ offset
);
125 SDLA_WINDOW(dev
, addr
);
126 memcpy(base
, temp
, bytes
);
134 static void sdla_write(struct net_device
*dev
, int addr
,
135 const void *buf
, short len
)
139 spin_lock_irqsave(&sdla_lock
, flags
);
140 __sdla_write(dev
, addr
, buf
, len
);
141 spin_unlock_irqrestore(&sdla_lock
, flags
);
145 static void sdla_clear(struct net_device
*dev
)
149 int len
, addr
, bytes
;
153 bytes
= SDLA_WINDOW_SIZE
;
154 base
= (void *) dev
->mem_start
;
156 spin_lock_irqsave(&sdla_lock
, flags
);
159 SDLA_WINDOW(dev
, addr
);
160 memset(base
, 0, bytes
);
165 spin_unlock_irqrestore(&sdla_lock
, flags
);
169 static char sdla_byte(struct net_device
*dev
, int addr
)
174 temp
= (void *) (dev
->mem_start
+ (addr
& SDLA_ADDR_MASK
));
176 spin_lock_irqsave(&sdla_lock
, flags
);
177 SDLA_WINDOW(dev
, addr
);
179 spin_unlock_irqrestore(&sdla_lock
, flags
);
184 static void sdla_stop(struct net_device
*dev
)
186 struct frad_local
*flp
;
192 outb(SDLA_S502A_HALT
, dev
->base_addr
+ SDLA_REG_CONTROL
);
193 flp
->state
= SDLA_HALT
;
196 outb(SDLA_HALT
, dev
->base_addr
+ SDLA_REG_Z80_CONTROL
);
197 outb(SDLA_S502E_ENABLE
, dev
->base_addr
+ SDLA_REG_CONTROL
);
198 flp
->state
= SDLA_S502E_ENABLE
;
201 flp
->state
&= ~SDLA_CPUEN
;
202 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
205 flp
->state
&= ~SDLA_CPUEN
;
206 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
211 static void sdla_start(struct net_device
*dev
)
213 struct frad_local
*flp
;
219 outb(SDLA_S502A_NMI
, dev
->base_addr
+ SDLA_REG_CONTROL
);
220 outb(SDLA_S502A_START
, dev
->base_addr
+ SDLA_REG_CONTROL
);
221 flp
->state
= SDLA_S502A_START
;
224 outb(SDLA_S502E_CPUEN
, dev
->base_addr
+ SDLA_REG_Z80_CONTROL
);
225 outb(0x00, dev
->base_addr
+ SDLA_REG_CONTROL
);
229 flp
->state
|= SDLA_CPUEN
;
230 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
233 flp
->state
|= SDLA_CPUEN
;
234 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
239 /****************************************************
241 * this is used for the S502A/E cards to determine
242 * the speed of the onboard CPU. Calibration is
243 * necessary for the Frame Relay code uploaded
244 * later. Incorrect results cause timing problems
245 * with link checks & status messages
247 ***************************************************/
249 static int sdla_z80_poll(struct net_device
*dev
, int z80_addr
, int jiffs
, char resp1
, char resp2
)
251 unsigned long start
, done
, now
;
254 start
= now
= jiffies
;
255 done
= jiffies
+ jiffs
;
257 temp
= (void *)dev
->mem_start
;
258 temp
+= z80_addr
& SDLA_ADDR_MASK
;
261 while (time_before(jiffies
, done
) && (resp
!= resp1
) && (!resp2
|| (resp
!= resp2
)))
265 SDLA_WINDOW(dev
, z80_addr
);
270 return(time_before(jiffies
, done
) ? jiffies
- start
: -1);
273 /* constants for Z80 CPU speed */
274 #define Z80_READY '1' /* Z80 is ready to begin */
275 #define LOADER_READY '2' /* driver is ready to begin */
276 #define Z80_SCC_OK '3' /* SCC is on board */
277 #define Z80_SCC_BAD '4' /* SCC was not found */
279 static int sdla_cpuspeed(struct net_device
*dev
, struct ifreq
*ifr
)
285 if (sdla_z80_poll(dev
, 0, 3*HZ
, Z80_READY
, 0) < 0)
289 sdla_write(dev
, 0, &data
, 1);
291 if ((jiffs
= sdla_z80_poll(dev
, 0, 8*HZ
, Z80_SCC_OK
, Z80_SCC_BAD
)) < 0)
295 sdla_read(dev
, 0, &data
, 1);
297 if (data
== Z80_SCC_BAD
)
299 printk("%s: SCC bad\n", dev
->name
);
303 if (data
!= Z80_SCC_OK
)
307 ifr
->ifr_mtu
= SDLA_CPU_16M
;
308 else if (jiffs
< 220)
309 ifr
->ifr_mtu
= SDLA_CPU_10M
;
310 else if (jiffs
< 258)
311 ifr
->ifr_mtu
= SDLA_CPU_8M
;
312 else if (jiffs
< 357)
313 ifr
->ifr_mtu
= SDLA_CPU_7M
;
314 else if (jiffs
< 467)
315 ifr
->ifr_mtu
= SDLA_CPU_5M
;
317 ifr
->ifr_mtu
= SDLA_CPU_3M
;
322 /************************************************
324 * Direct interaction with the Frame Relay code
327 ************************************************/
333 } __attribute__((packed
));
338 struct _dlci_stat dlcis
[SDLA_MAX_DLCI
];
341 static void sdla_errors(struct net_device
*dev
, int cmd
, int dlci
, int ret
, int len
, void *data
)
343 struct _dlci_stat
*pstatus
;
346 char *state
, line
[30];
352 if (*state
& SDLA_MODEM_DCD_LOW
)
353 printk(KERN_INFO
"%s: Modem DCD unexpectedly low!\n", dev
->name
);
354 if (*state
& SDLA_MODEM_CTS_LOW
)
355 printk(KERN_INFO
"%s: Modem CTS unexpectedly low!\n", dev
->name
);
356 /* I should probably do something about this! */
359 case SDLA_RET_CHANNEL_OFF
:
360 printk(KERN_INFO
"%s: Channel became inoperative!\n", dev
->name
);
364 case SDLA_RET_CHANNEL_ON
:
365 printk(KERN_INFO
"%s: Channel became operative!\n", dev
->name
);
369 case SDLA_RET_DLCI_STATUS
:
370 printk(KERN_INFO
"%s: Status change reported by Access Node.\n", dev
->name
);
371 len
/= sizeof(struct _dlci_stat
);
372 for(pstatus
= data
, i
=0;i
< len
;i
++,pstatus
++)
374 if (pstatus
->flags
& SDLA_DLCI_NEW
)
376 else if (pstatus
->flags
& SDLA_DLCI_DELETED
)
378 else if (pstatus
->flags
& SDLA_DLCI_ACTIVE
)
382 sprintf(line
, "unknown status: %02X", pstatus
->flags
);
385 printk(KERN_INFO
"%s: DLCI %i: %s.\n", dev
->name
, pstatus
->dlci
, state
);
390 case SDLA_RET_DLCI_UNKNOWN
:
391 printk(KERN_INFO
"%s: Received unknown DLCIs:", dev
->name
);
392 len
/= sizeof(short);
393 for(pdlci
= data
,i
=0;i
< len
;i
++,pdlci
++)
394 printk(" %i", *pdlci
);
398 case SDLA_RET_TIMEOUT
:
399 printk(KERN_ERR
"%s: Command timed out!\n", dev
->name
);
402 case SDLA_RET_BUF_OVERSIZE
:
403 printk(KERN_INFO
"%s: Bc/CIR overflow, acceptable size is %i\n", dev
->name
, len
);
406 case SDLA_RET_BUF_TOO_BIG
:
407 printk(KERN_INFO
"%s: Buffer size over specified max of %i\n", dev
->name
, len
);
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
)
418 printk(KERN_DEBUG
"%s: Cmd 0x%2.2X generated return code 0x%2.2X\n", dev
->name
, cmd
, ret
);
419 /* Further processing could be done here */
424 static int sdla_cmd(struct net_device
*dev
, int cmd
, short dlci
, short flags
,
425 void *inbuf
, short inlen
, void *outbuf
, short *outlen
)
427 static struct _frad_stat status
;
428 struct frad_local
*flp
;
429 struct sdla_cmd
*cmd_buf
;
430 unsigned long pflags
;
432 int ret
, waiting
, len
;
436 window
= flp
->type
== SDLA_S508
? SDLA_508_CMD_BUF
: SDLA_502_CMD_BUF
;
437 cmd_buf
= (struct sdla_cmd
*)(dev
->mem_start
+ (window
& SDLA_ADDR_MASK
));
440 jiffs
= jiffies
+ HZ
; /* 1 second is plenty */
442 spin_lock_irqsave(&sdla_lock
, pflags
);
443 SDLA_WINDOW(dev
, window
);
445 cmd_buf
->dlci
= dlci
;
446 cmd_buf
->flags
= flags
;
449 memcpy(cmd_buf
->data
, inbuf
, inlen
);
451 cmd_buf
->length
= inlen
;
453 cmd_buf
->opp_flag
= 1;
454 spin_unlock_irqrestore(&sdla_lock
, pflags
);
458 while (waiting
&& time_before_eq(jiffies
, jiffs
))
462 spin_lock_irqsave(&sdla_lock
, pflags
);
463 SDLA_WINDOW(dev
, window
);
464 waiting
= ((volatile int)(cmd_buf
->opp_flag
));
465 spin_unlock_irqrestore(&sdla_lock
, pflags
);
472 spin_lock_irqsave(&sdla_lock
, pflags
);
473 SDLA_WINDOW(dev
, window
);
474 ret
= cmd_buf
->retval
;
475 len
= cmd_buf
->length
;
476 if (outbuf
&& outlen
)
478 *outlen
= *outlen
>= len
? len
: *outlen
;
481 memcpy(outbuf
, cmd_buf
->data
, *outlen
);
484 /* This is a local copy that's used for error handling */
486 memcpy(&status
, cmd_buf
->data
, len
> sizeof(status
) ? sizeof(status
) : len
);
488 spin_unlock_irqrestore(&sdla_lock
, pflags
);
491 ret
= SDLA_RET_TIMEOUT
;
493 if (ret
!= SDLA_RET_OK
)
494 sdla_errors(dev
, cmd
, dlci
, ret
, len
, &status
);
499 /***********************************************
501 * these functions are called by the DLCI driver
503 ***********************************************/
505 static int sdla_reconfig(struct net_device
*dev
);
507 static int sdla_activate(struct net_device
*slave
, struct net_device
*master
)
509 struct frad_local
*flp
;
514 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
515 if (flp
->master
[i
] == master
)
518 if (i
== CONFIG_DLCI_MAX
)
521 flp
->dlci
[i
] = abs(flp
->dlci
[i
]);
523 if (netif_running(slave
) && (flp
->config
.station
== FRAD_STATION_NODE
))
524 sdla_cmd(slave
, SDLA_ACTIVATE_DLCI
, 0, 0, &flp
->dlci
[i
], sizeof(short), NULL
, NULL
);
529 static int sdla_deactivate(struct net_device
*slave
, struct net_device
*master
)
531 struct frad_local
*flp
;
536 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
537 if (flp
->master
[i
] == master
)
540 if (i
== CONFIG_DLCI_MAX
)
543 flp
->dlci
[i
] = -abs(flp
->dlci
[i
]);
545 if (netif_running(slave
) && (flp
->config
.station
== FRAD_STATION_NODE
))
546 sdla_cmd(slave
, SDLA_DEACTIVATE_DLCI
, 0, 0, &flp
->dlci
[i
], sizeof(short), NULL
, NULL
);
551 static int sdla_assoc(struct net_device
*slave
, struct net_device
*master
)
553 struct frad_local
*flp
;
556 if (master
->type
!= ARPHRD_DLCI
)
561 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
565 if (abs(flp
->dlci
[i
]) == *(short *)(master
->dev_addr
))
569 if (i
== CONFIG_DLCI_MAX
)
570 return(-EMLINK
); /* #### Alan: Comments on this ?? */
573 flp
->master
[i
] = master
;
574 flp
->dlci
[i
] = -*(short *)(master
->dev_addr
);
575 master
->mtu
= slave
->mtu
;
577 if (netif_running(slave
)) {
578 if (flp
->config
.station
== FRAD_STATION_CPE
)
579 sdla_reconfig(slave
);
581 sdla_cmd(slave
, SDLA_ADD_DLCI
, 0, 0, master
->dev_addr
, sizeof(short), NULL
, NULL
);
587 static int sdla_deassoc(struct net_device
*slave
, struct net_device
*master
)
589 struct frad_local
*flp
;
594 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
595 if (flp
->master
[i
] == master
)
598 if (i
== CONFIG_DLCI_MAX
)
601 flp
->master
[i
] = NULL
;
605 if (netif_running(slave
)) {
606 if (flp
->config
.station
== FRAD_STATION_CPE
)
607 sdla_reconfig(slave
);
609 sdla_cmd(slave
, SDLA_DELETE_DLCI
, 0, 0, master
->dev_addr
, sizeof(short), NULL
, NULL
);
615 static int sdla_dlci_conf(struct net_device
*slave
, struct net_device
*master
, int get
)
617 struct frad_local
*flp
;
618 struct dlci_local
*dlp
;
624 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
625 if (flp
->master
[i
] == master
)
628 if (i
== CONFIG_DLCI_MAX
)
634 len
= sizeof(struct dlci_conf
);
635 if (netif_running(slave
)) {
637 ret
= sdla_cmd(slave
, SDLA_READ_DLCI_CONFIGURATION
, abs(flp
->dlci
[i
]), 0,
638 NULL
, 0, &dlp
->config
, &len
);
640 ret
= sdla_cmd(slave
, SDLA_SET_DLCI_CONFIGURATION
, abs(flp
->dlci
[i
]), 0,
641 &dlp
->config
, sizeof(struct dlci_conf
) - 4 * sizeof(short), NULL
, NULL
);
644 return(ret
== SDLA_RET_OK
? 0 : -EIO
);
647 /**************************
649 * now for the Linux driver
651 **************************/
653 /* NOTE: the DLCI driver deals with freeing the SKB!! */
654 static int sdla_transmit(struct sk_buff
*skb
, struct net_device
*dev
)
656 struct frad_local
*flp
;
657 int ret
, addr
, accept
, i
;
660 struct buf_entry
*pbuf
;
666 netif_stop_queue(dev
);
669 * stupid GateD insists on setting up the multicast router thru us
670 * and we're ill equipped to handle a non Frame Relay packet at this
678 if (skb
->dev
->type
!= ARPHRD_DLCI
)
680 printk(KERN_WARNING
"%s: Non DLCI device, type %i, tried to send on FRAD module.\n", dev
->name
, skb
->dev
->type
);
685 printk(KERN_WARNING
"%s: unknown firmware type 0x%4.4X\n", dev
->name
, dev
->type
);
691 /* this is frame specific, but till there's a PPP module, it's the default */
696 ret
= sdla_cmd(dev
, SDLA_INFORMATION_WRITE
, *(short *)(skb
->dev
->dev_addr
), 0, skb
->data
, skb
->len
, NULL
, NULL
);
700 ret
= sdla_cmd(dev
, SDLA_INFORMATION_WRITE
, *(short *)(skb
->dev
->dev_addr
), 0, NULL
, skb
->len
, &addr
, &size
);
701 if (ret
== SDLA_RET_OK
)
704 spin_lock_irqsave(&sdla_lock
, flags
);
705 SDLA_WINDOW(dev
, addr
);
706 pbuf
= (void *)(((int) dev
->mem_start
) + (addr
& SDLA_ADDR_MASK
));
707 __sdla_write(dev
, pbuf
->buf_addr
, skb
->data
, skb
->len
);
708 SDLA_WINDOW(dev
, addr
);
710 spin_unlock_irqrestore(&sdla_lock
, flags
);
717 flp
->stats
.tx_packets
++;
721 case SDLA_RET_CIR_OVERFLOW
:
722 case SDLA_RET_BUF_OVERSIZE
:
723 case SDLA_RET_NO_BUFS
:
724 flp
->stats
.tx_dropped
++;
729 flp
->stats
.tx_errors
++;
734 netif_wake_queue(dev
);
735 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
737 if(flp
->master
[i
]!=NULL
)
738 netif_wake_queue(flp
->master
[i
]);
743 static void sdla_receive(struct net_device
*dev
)
745 struct net_device
*master
;
746 struct frad_local
*flp
;
747 struct dlci_local
*dlp
;
750 struct sdla_cmd
*cmd
;
751 struct buf_info
*pbufi
;
752 struct buf_entry
*pbuf
;
755 int i
=0, received
, success
, addr
, buf_base
, buf_top
;
756 short dlci
, len
, len2
, split
;
760 received
= addr
= buf_top
= buf_base
= 0;
768 spin_lock_irqsave(&sdla_lock
, flags
);
774 cmd
= (void *) (dev
->mem_start
+ (SDLA_502_RCV_BUF
& SDLA_ADDR_MASK
));
775 SDLA_WINDOW(dev
, SDLA_502_RCV_BUF
);
776 success
= cmd
->opp_flag
;
785 pbufi
= (void *) (dev
->mem_start
+ (SDLA_508_RXBUF_INFO
& SDLA_ADDR_MASK
));
786 SDLA_WINDOW(dev
, SDLA_508_RXBUF_INFO
);
787 pbuf
= (void *) (dev
->mem_start
+ ((pbufi
->rse_base
+ flp
->buffer
* sizeof(struct buf_entry
)) & SDLA_ADDR_MASK
));
788 success
= pbuf
->opp_flag
;
792 buf_top
= pbufi
->buf_top
;
793 buf_base
= pbufi
->buf_base
;
796 addr
= pbuf
->buf_addr
;
800 /* common code, find the DLCI and get the SKB */
803 for (i
=0;i
<CONFIG_DLCI_MAX
;i
++)
804 if (flp
->dlci
[i
] == dlci
)
807 if (i
== CONFIG_DLCI_MAX
)
809 printk(KERN_NOTICE
"%s: Received packet from invalid DLCI %i, ignoring.", dev
->name
, dlci
);
810 flp
->stats
.rx_errors
++;
817 master
= flp
->master
[i
];
818 skb
= dev_alloc_skb(len
+ sizeof(struct frhdr
));
821 printk(KERN_NOTICE
"%s: Memory squeeze, dropping packet.\n", dev
->name
);
822 flp
->stats
.rx_dropped
++;
826 skb_reserve(skb
, sizeof(struct frhdr
));
829 /* pick up the data */
835 __sdla_read(dev
, SDLA_502_RCV_BUF
+ SDLA_502_DATA_OFS
, skb_put(skb
,len
), len
);
837 SDLA_WINDOW(dev
, SDLA_502_RCV_BUF
);
844 /* is this buffer split off the end of the internal ring buffer */
845 split
= addr
+ len
> buf_top
+ 1 ? len
- (buf_top
- addr
+ 1) : 0;
848 __sdla_read(dev
, addr
, skb_put(skb
, len2
), len2
);
850 __sdla_read(dev
, buf_base
, skb_put(skb
, split
), split
);
853 /* increment the buffer we're looking at */
854 SDLA_WINDOW(dev
, SDLA_508_RXBUF_INFO
);
855 flp
->buffer
= (flp
->buffer
+ 1) % pbufi
->rse_num
;
862 flp
->stats
.rx_packets
++;
864 (*dlp
->receive
)(skb
, master
);
867 spin_unlock_irqrestore(&sdla_lock
, flags
);
870 static irqreturn_t
sdla_isr(int dummy
, void *dev_id
)
872 struct net_device
*dev
;
873 struct frad_local
*flp
;
878 flp
= netdev_priv(dev
);
880 if (!flp
->initialized
)
882 printk(KERN_WARNING
"%s: irq %d for uninitialized device.\n",
883 dev
->name
, dev
->irq
);
887 byte
= sdla_byte(dev
, flp
->type
== SDLA_S508
? SDLA_508_IRQ_INTERFACE
: SDLA_502_IRQ_INTERFACE
);
894 /* the command will get an error return, which is processed above */
895 case SDLA_INTR_MODEM
:
896 case SDLA_INTR_STATUS
:
897 sdla_cmd(dev
, SDLA_READ_DLC_STATUS
, 0, 0, NULL
, 0, NULL
, NULL
);
901 case SDLA_INTR_COMPLETE
:
902 case SDLA_INTR_TIMER
:
903 printk(KERN_WARNING
"%s: invalid irq flag 0x%02X.\n", dev
->name
, byte
);
907 /* the S502E requires a manual acknowledgement of the interrupt */
908 if (flp
->type
== SDLA_S502E
)
910 flp
->state
&= ~SDLA_S502E_INTACK
;
911 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
912 flp
->state
|= SDLA_S502E_INTACK
;
913 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
916 /* this clears the byte, informing the Z80 we're done */
918 sdla_write(dev
, flp
->type
== SDLA_S508
? SDLA_508_IRQ_INTERFACE
: SDLA_502_IRQ_INTERFACE
, &byte
, sizeof(byte
));
922 static void sdla_poll(unsigned long device
)
924 struct net_device
*dev
;
925 struct frad_local
*flp
;
927 dev
= (struct net_device
*) device
;
930 if (sdla_byte(dev
, SDLA_502_RCV_BUF
))
933 flp
->timer
.expires
= 1;
934 add_timer(&flp
->timer
);
937 static int sdla_close(struct net_device
*dev
)
939 struct frad_local
*flp
;
940 struct intr_info intr
;
942 short dlcis
[CONFIG_DLCI_MAX
];
947 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
949 dlcis
[len
++] = abs(flp
->dlci
[i
]);
952 if (flp
->config
.station
== FRAD_STATION_NODE
)
954 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
955 if (flp
->dlci
[i
] > 0)
956 sdla_cmd(dev
, SDLA_DEACTIVATE_DLCI
, 0, 0, dlcis
, len
, NULL
, NULL
);
957 sdla_cmd(dev
, SDLA_DELETE_DLCI
, 0, 0, &flp
->dlci
[i
], sizeof(flp
->dlci
[i
]), NULL
, NULL
);
960 memset(&intr
, 0, sizeof(intr
));
961 /* let's start up the reception */
965 del_timer(&flp
->timer
);
969 sdla_cmd(dev
, SDLA_SET_IRQ_TRIGGER
, 0, 0, &intr
, sizeof(char) + sizeof(short), NULL
, NULL
);
970 flp
->state
&= ~SDLA_S502E_INTACK
;
971 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
978 sdla_cmd(dev
, SDLA_SET_IRQ_TRIGGER
, 0, 0, &intr
, sizeof(struct intr_info
), NULL
, NULL
);
979 flp
->state
&= ~SDLA_S508_INTEN
;
980 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
984 sdla_cmd(dev
, SDLA_DISABLE_COMMUNICATIONS
, 0, 0, NULL
, 0, NULL
, NULL
);
986 netif_stop_queue(dev
);
992 struct frad_conf config
;
993 short dlci
[CONFIG_DLCI_MAX
];
996 static int sdla_open(struct net_device
*dev
)
998 struct frad_local
*flp
;
999 struct dlci_local
*dlp
;
1000 struct conf_data data
;
1001 struct intr_info intr
;
1007 if (!flp
->initialized
)
1010 if (!flp
->configured
)
1013 /* time to send in the configuration */
1015 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
1017 data
.dlci
[len
++] = abs(flp
->dlci
[i
]);
1020 memcpy(&data
.config
, &flp
->config
, sizeof(struct frad_conf
));
1021 len
+= sizeof(struct frad_conf
);
1023 sdla_cmd(dev
, SDLA_DISABLE_COMMUNICATIONS
, 0, 0, NULL
, 0, NULL
, NULL
);
1024 sdla_cmd(dev
, SDLA_SET_DLCI_CONFIGURATION
, 0, 0, &data
, len
, NULL
, NULL
);
1026 if (flp
->type
== SDLA_S508
)
1029 sdla_cmd(dev
, SDLA_ENABLE_COMMUNICATIONS
, 0, 0, NULL
, 0, NULL
, NULL
);
1031 /* let's start up the reception */
1032 memset(&intr
, 0, sizeof(intr
));
1036 flp
->timer
.expires
= 1;
1037 add_timer(&flp
->timer
);
1041 flp
->state
|= SDLA_S502E_ENABLE
;
1042 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
1043 flp
->state
|= SDLA_S502E_INTACK
;
1044 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
1046 sdla_write(dev
, SDLA_502_IRQ_INTERFACE
, &byte
, sizeof(byte
));
1047 intr
.flags
= SDLA_INTR_RX
| SDLA_INTR_STATUS
| SDLA_INTR_MODEM
;
1048 sdla_cmd(dev
, SDLA_SET_IRQ_TRIGGER
, 0, 0, &intr
, sizeof(char) + sizeof(short), NULL
, NULL
);
1055 flp
->state
|= SDLA_S508_INTEN
;
1056 outb(flp
->state
, dev
->base_addr
+ SDLA_REG_CONTROL
);
1058 sdla_write(dev
, SDLA_508_IRQ_INTERFACE
, &byte
, sizeof(byte
));
1059 intr
.flags
= SDLA_INTR_RX
| SDLA_INTR_STATUS
| SDLA_INTR_MODEM
;
1060 intr
.irq
= dev
->irq
;
1061 sdla_cmd(dev
, SDLA_SET_IRQ_TRIGGER
, 0, 0, &intr
, sizeof(struct intr_info
), NULL
, NULL
);
1065 if (flp
->config
.station
== FRAD_STATION_CPE
)
1067 byte
= SDLA_ICS_STATUS_ENQ
;
1068 sdla_cmd(dev
, SDLA_ISSUE_IN_CHANNEL_SIGNAL
, 0, 0, &byte
, sizeof(byte
), NULL
, NULL
);
1072 sdla_cmd(dev
, SDLA_ADD_DLCI
, 0, 0, data
.dlci
, len
- sizeof(struct frad_conf
), NULL
, NULL
);
1073 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
1074 if (flp
->dlci
[i
] > 0)
1075 sdla_cmd(dev
, SDLA_ACTIVATE_DLCI
, 0, 0, &flp
->dlci
[i
], 2*sizeof(flp
->dlci
[i
]), NULL
, NULL
);
1078 /* configure any specific DLCI settings */
1079 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
1082 dlp
= flp
->master
[i
]->priv
;
1083 if (dlp
->configured
)
1084 sdla_cmd(dev
, SDLA_SET_DLCI_CONFIGURATION
, abs(flp
->dlci
[i
]), 0, &dlp
->config
, sizeof(struct dlci_conf
), NULL
, NULL
);
1087 netif_start_queue(dev
);
1092 static int sdla_config(struct net_device
*dev
, struct frad_conf __user
*conf
, int get
)
1094 struct frad_local
*flp
;
1095 struct conf_data data
;
1099 if (dev
->type
== 0xFFFF)
1106 if (netif_running(dev
))
1109 if(copy_from_user(&data
.config
, conf
, sizeof(struct frad_conf
)))
1112 if (data
.config
.station
& ~FRAD_STATION_NODE
)
1115 if (data
.config
.flags
& ~FRAD_VALID_FLAGS
)
1118 if ((data
.config
.kbaud
< 0) ||
1119 ((data
.config
.kbaud
> 128) && (flp
->type
!= SDLA_S508
)))
1122 if (data
.config
.clocking
& ~(FRAD_CLOCK_INT
| SDLA_S508_PORT_RS232
))
1125 if ((data
.config
.mtu
< 0) || (data
.config
.mtu
> SDLA_MAX_MTU
))
1128 if ((data
.config
.T391
< 5) || (data
.config
.T391
> 30))
1131 if ((data
.config
.T392
< 5) || (data
.config
.T392
> 30))
1134 if ((data
.config
.N391
< 1) || (data
.config
.N391
> 255))
1137 if ((data
.config
.N392
< 1) || (data
.config
.N392
> 10))
1140 if ((data
.config
.N393
< 1) || (data
.config
.N393
> 10))
1143 memcpy(&flp
->config
, &data
.config
, sizeof(struct frad_conf
));
1144 flp
->config
.flags
|= SDLA_DIRECT_RECV
;
1146 if (flp
->type
== SDLA_S508
)
1147 flp
->config
.flags
|= SDLA_TX70_RX30
;
1149 if (dev
->mtu
!= flp
->config
.mtu
)
1151 /* this is required to change the MTU */
1152 dev
->mtu
= flp
->config
.mtu
;
1153 for(i
=0;i
<CONFIG_DLCI_MAX
;i
++)
1155 flp
->master
[i
]->mtu
= flp
->config
.mtu
;
1158 flp
->config
.mtu
+= sizeof(struct frhdr
);
1160 /* off to the races! */
1161 if (!flp
->configured
)
1164 flp
->configured
= 1;
1168 /* no sense reading if the CPU isn't started */
1169 if (netif_running(dev
))
1171 size
= sizeof(data
);
1172 if (sdla_cmd(dev
, SDLA_READ_DLCI_CONFIGURATION
, 0, 0, NULL
, 0, &data
, &size
) != SDLA_RET_OK
)
1176 if (flp
->configured
)
1177 memcpy(&data
.config
, &flp
->config
, sizeof(struct frad_conf
));
1179 memset(&data
.config
, 0, sizeof(struct frad_conf
));
1181 memcpy(&flp
->config
, &data
.config
, sizeof(struct frad_conf
));
1182 data
.config
.flags
&= FRAD_VALID_FLAGS
;
1183 data
.config
.mtu
-= data
.config
.mtu
> sizeof(struct frhdr
) ? sizeof(struct frhdr
) : data
.config
.mtu
;
1184 return copy_to_user(conf
, &data
.config
, sizeof(struct frad_conf
))?-EFAULT
:0;
1190 static int sdla_xfer(struct net_device
*dev
, struct sdla_mem __user
*info
, int read
)
1192 struct sdla_mem mem
;
1195 if(copy_from_user(&mem
, info
, sizeof(mem
)))
1200 temp
= kzalloc(mem
.len
, GFP_KERNEL
);
1203 sdla_read(dev
, mem
.addr
, temp
, mem
.len
);
1204 if(copy_to_user(mem
.data
, temp
, mem
.len
))
1213 temp
= kmalloc(mem
.len
, GFP_KERNEL
);
1216 if(copy_from_user(temp
, mem
.data
, mem
.len
))
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
;
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
))
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
));
1315 return(-EOPNOTSUPP
);
1320 static int sdla_change_mtu(struct net_device
*dev
, int new_mtu
)
1322 struct frad_local
*flp
;
1326 if (netif_running(dev
))
1329 /* for now, you can't change the MTU! */
1330 return(-EOPNOTSUPP
);
1333 static int sdla_set_config(struct net_device
*dev
, struct ifmap
*map
)
1335 struct frad_local
*flp
;
1343 if (flp
->initialized
)
1346 for(i
=0; i
< ARRAY_SIZE(valid_port
); i
++)
1347 if (valid_port
[i
] == map
->base_addr
)
1350 if (i
== ARRAY_SIZE(valid_port
))
1353 if (!request_region(map
->base_addr
, SDLA_IO_EXTENTS
, dev
->name
)){
1354 printk(KERN_WARNING
"SDLA: io-port 0x%04lx in use \n", dev
->base_addr
);
1357 base
= map
->base_addr
;
1359 /* test for card types, S502A, S502E, S507, S508 */
1360 /* these tests shut down the card completely, so clear the state */
1361 flp
->type
= SDLA_UNKNOWN
;
1364 for(i
=1;i
<SDLA_IO_EXTENTS
;i
++)
1365 if (inb(base
+ i
) != 0xFF)
1368 if (i
== SDLA_IO_EXTENTS
) {
1369 outb(SDLA_HALT
, base
+ SDLA_REG_Z80_CONTROL
);
1370 if ((inb(base
+ SDLA_S502_STS
) & 0x0F) == 0x08) {
1371 outb(SDLA_S502E_INTACK
, base
+ SDLA_REG_CONTROL
);
1372 if ((inb(base
+ SDLA_S502_STS
) & 0x0F) == 0x0C) {
1373 outb(SDLA_HALT
, base
+ SDLA_REG_CONTROL
);
1374 flp
->type
= SDLA_S502E
;
1380 for(byte
=inb(base
),i
=0;i
<SDLA_IO_EXTENTS
;i
++)
1381 if (inb(base
+ i
) != byte
)
1384 if (i
== SDLA_IO_EXTENTS
) {
1385 outb(SDLA_HALT
, base
+ SDLA_REG_CONTROL
);
1386 if ((inb(base
+ SDLA_S502_STS
) & 0x7E) == 0x30) {
1387 outb(SDLA_S507_ENABLE
, base
+ SDLA_REG_CONTROL
);
1388 if ((inb(base
+ SDLA_S502_STS
) & 0x7E) == 0x32) {
1389 outb(SDLA_HALT
, base
+ SDLA_REG_CONTROL
);
1390 flp
->type
= SDLA_S507
;
1396 outb(SDLA_HALT
, base
+ SDLA_REG_CONTROL
);
1397 if ((inb(base
+ SDLA_S508_STS
) & 0x3F) == 0x00) {
1398 outb(SDLA_S508_INTEN
, base
+ SDLA_REG_CONTROL
);
1399 if ((inb(base
+ SDLA_S508_STS
) & 0x3F) == 0x10) {
1400 outb(SDLA_HALT
, base
+ SDLA_REG_CONTROL
);
1401 flp
->type
= SDLA_S508
;
1406 outb(SDLA_S502A_HALT
, base
+ SDLA_REG_CONTROL
);
1407 if (inb(base
+ SDLA_S502_STS
) == 0x40) {
1408 outb(SDLA_S502A_START
, base
+ SDLA_REG_CONTROL
);
1409 if (inb(base
+ SDLA_S502_STS
) == 0x40) {
1410 outb(SDLA_S502A_INTEN
, base
+ SDLA_REG_CONTROL
);
1411 if (inb(base
+ SDLA_S502_STS
) == 0x44) {
1412 outb(SDLA_S502A_START
, base
+ SDLA_REG_CONTROL
);
1413 flp
->type
= SDLA_S502A
;
1419 printk(KERN_NOTICE
"%s: Unknown card type\n", dev
->name
);
1429 if (flp
->type
!= SDLA_S508
&& flp
->type
!= SDLA_S507
)
1435 if (flp
->type
!= SDLA_S502E
)
1444 if (flp
->type
!= SDLA_S508
&& flp
->type
!= SDLA_S507
)
1450 if (flp
->type
== SDLA_S502A
)
1459 if (request_irq(dev
->irq
, &sdla_isr
, 0, dev
->name
, dev
))
1462 if (flp
->type
== SDLA_S507
) {
1465 flp
->state
= SDLA_S507_IRQ3
;
1468 flp
->state
= SDLA_S507_IRQ4
;
1471 flp
->state
= SDLA_S507_IRQ5
;
1474 flp
->state
= SDLA_S507_IRQ7
;
1477 flp
->state
= SDLA_S507_IRQ10
;
1480 flp
->state
= SDLA_S507_IRQ11
;
1483 flp
->state
= SDLA_S507_IRQ12
;
1486 flp
->state
= SDLA_S507_IRQ15
;
1491 for(i
=0; i
< ARRAY_SIZE(valid_mem
); i
++)
1492 if (valid_mem
[i
] == map
->mem_start
)
1496 if (i
== ARRAY_SIZE(valid_mem
))
1499 if (flp
->type
== SDLA_S502A
&& (map
->mem_start
& 0xF000) >> 12 == 0x0E)
1502 if (flp
->type
!= SDLA_S507
&& map
->mem_start
>> 16 == 0x0B)
1505 if (flp
->type
== SDLA_S507
&& map
->mem_start
>> 16 == 0x0D)
1508 byte
= flp
->type
!= SDLA_S508
? SDLA_8K_WINDOW
: 0;
1509 byte
|= (map
->mem_start
& 0xF000) >> (12 + (flp
->type
== SDLA_S508
? 1 : 0));
1513 switch (map
->mem_start
>> 16) {
1515 byte
|= SDLA_S502_SEG_A
;
1518 byte
|= SDLA_S502_SEG_C
;
1521 byte
|= SDLA_S502_SEG_D
;
1524 byte
|= SDLA_S502_SEG_E
;
1529 switch (map
->mem_start
>> 16) {
1531 byte
|= SDLA_S507_SEG_A
;
1534 byte
|= SDLA_S507_SEG_B
;
1537 byte
|= SDLA_S507_SEG_C
;
1540 byte
|= SDLA_S507_SEG_E
;
1545 switch (map
->mem_start
>> 16) {
1547 byte
|= SDLA_S508_SEG_A
;
1550 byte
|= SDLA_S508_SEG_C
;
1553 byte
|= SDLA_S508_SEG_D
;
1556 byte
|= SDLA_S508_SEG_E
;
1562 /* set the memory bits, and enable access */
1563 outb(byte
, base
+ SDLA_REG_PC_WINDOW
);
1568 flp
->state
= SDLA_S502E_ENABLE
;
1571 flp
->state
|= SDLA_MEMEN
;
1574 flp
->state
= SDLA_MEMEN
;
1577 outb(flp
->state
, base
+ SDLA_REG_CONTROL
);
1579 dev
->irq
= map
->irq
;
1580 dev
->base_addr
= base
;
1581 dev
->mem_start
= map
->mem_start
;
1582 dev
->mem_end
= dev
->mem_start
+ 0x2000;
1583 flp
->initialized
= 1;
1587 free_irq(map
->irq
, dev
);
1589 release_region(base
, SDLA_IO_EXTENTS
);
1593 static struct net_device_stats
*sdla_stats(struct net_device
*dev
)
1595 struct frad_local
*flp
;
1598 return(&flp
->stats
);
1601 static void setup_sdla(struct net_device
*dev
)
1603 struct frad_local
*flp
= dev
->priv
;
1605 netdev_boot_setup_check(dev
);
1609 dev
->hard_header_len
= 0;
1611 dev
->mtu
= SDLA_MAX_MTU
;
1613 dev
->open
= sdla_open
;
1614 dev
->stop
= sdla_close
;
1615 dev
->do_ioctl
= sdla_ioctl
;
1616 dev
->set_config
= sdla_set_config
;
1617 dev
->get_stats
= sdla_stats
;
1618 dev
->hard_start_xmit
= sdla_transmit
;
1619 dev
->change_mtu
= sdla_change_mtu
;
1621 flp
->activate
= sdla_activate
;
1622 flp
->deactivate
= sdla_deactivate
;
1623 flp
->assoc
= sdla_assoc
;
1624 flp
->deassoc
= sdla_deassoc
;
1625 flp
->dlci_conf
= sdla_dlci_conf
;
1627 init_timer(&flp
->timer
);
1628 flp
->timer
.expires
= 1;
1629 flp
->timer
.data
= (unsigned long) dev
;
1630 flp
->timer
.function
= sdla_poll
;
1633 static struct net_device
*sdla
;
1635 static int __init
init_sdla(void)
1639 printk("%s.\n", version
);
1641 sdla
= alloc_netdev(sizeof(struct frad_local
), "sdla0", setup_sdla
);
1645 err
= register_netdev(sdla
);
1652 static void __exit
exit_sdla(void)
1654 struct frad_local
*flp
= sdla
->priv
;
1656 unregister_netdev(sdla
);
1657 if (flp
->initialized
) {
1658 free_irq(sdla
->irq
, sdla
);
1659 release_region(sdla
->base_addr
, SDLA_IO_EXTENTS
);
1661 del_timer_sync(&flp
->timer
);
1665 MODULE_LICENSE("GPL");
1667 module_init(init_sdla
);
1668 module_exit(exit_sdla
);