1 #define RCS_ID "$Id: scc.c,v 1.75 1998/11/04 15:15:01 jreuter Exp jreuter $"
6 * Please use z8530drv-utils-3.0 with this version.
9 * You can find a subset of the documentation in
10 * Documentation/networking/device_drivers/hamradio/z8530drv.rst.
14 ********************************************************************
15 * SCC.C - Linux driver for Z8530 based HDLC cards for AX.25 *
16 ********************************************************************
19 ********************************************************************
21 Copyright (c) 1993, 2000 Joerg Reuter DL1BKE
23 portions (c) 1993 Guido ten Dolle PE1NNZ
25 ********************************************************************
27 The driver and the programs in the archive are UNDER CONSTRUCTION.
28 The code is likely to fail, and so your kernel could --- even
31 This driver is intended for Amateur Radio use. If you are running it
32 for commercial purposes, please drop me a note. I am nosy...
36 ! You m u s t recognize the appropriate legislations of your country !
37 ! before you connect a radio to the SCC board and start to transmit or !
38 ! receive. The GPL allows you to use the d r i v e r, NOT the RADIO! !
40 For non-Amateur-Radio use please note that you might need a special
41 allowance/licence from the designer of the SCC Board and/or the
44 This program is free software; you can redistribute it and/or modify
45 it under the terms of the (modified) GNU General Public License
46 delivered with the Linux kernel source.
48 This program is distributed in the hope that it will be useful,
49 but WITHOUT ANY WARRANTY; without even the implied warranty of
50 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51 GNU General Public License for more details.
53 You should find a copy of the GNU General Public License in
54 /usr/src/linux/COPYING;
56 ********************************************************************
59 Incomplete history of z8530drv:
60 -------------------------------
62 1994-09-13 started to write the driver, rescued most of my own
63 code (and Hans Alblas' memory buffer pool concept) from
64 an earlier project "sccdrv" which was initiated by
65 Guido ten Dolle. Not much of the old driver survived,
66 though. The first version I put my hands on was sccdrv1.3
67 from August 1993. The memory buffer pool concept
68 appeared in an unauthorized sccdrv version (1.5) from
71 1995-01-31 changed copyright notice to GPL without limitations.
77 1996-10-05 New semester, new driver...
79 * KISS TNC emulator removed (TTY driver)
80 * Source moved to drivers/net/
81 * Includes Z8530 defines from drivers/net/z8530.h
82 * Uses sk_buffer memory management
83 * Reduced overhead of /proc/net/z8530drv output
84 * Streamlined quite a lot things
85 * Invents brand new bugs... ;-)
87 The move to version number 3.0 reflects theses changes.
88 You can use 'kissbridge' if you need a KISS TNC emulator.
90 1996-12-13 Fixed for Linux networking changes. (G4KLX)
91 1997-01-08 Fixed the remaining problems.
92 1997-04-02 Hopefully fixed the problems with the new *_timer()
93 routines, added calibration code.
94 1997-10-12 Made SCC_DELAY a CONFIG option, added CONFIG_SCC_TRXECHO
95 1998-01-29 Small fix to avoid lock-up on initialization
96 1998-09-29 Fixed the "grouping" bugs, tx_inhibit works again,
97 using dev->tx_queue_len now instead of MAXQUEUE now.
98 1998-10-21 Postponed the spinlock changes, would need a lot of
99 testing I currently don't have the time to. Softdcd doesn't
101 1998-11-04 Softdcd does not work correctly in DPLL mode, in fact it
102 never did. The DPLL locks on noise, the SYNC unit sees
103 flags that aren't... Restarting the DPLL does not help
104 either, it resynchronizes too slow and the first received
106 2000-02-13 Fixed for new network driver interface changes, still
107 does TX timeouts itself since it uses its own queue
110 Thanks to all who contributed to this driver with ideas and bug
113 NB -- if you find errors, change something, please let me know
114 first before you distribute it... And please don't touch
115 the version number. Just replace my callsign in
116 "v3.0.dl1bke" with your own. Just to avoid confusion...
118 If you want to add your modification to the linux distribution
119 please (!) contact me first.
121 New versions of the driver will be announced on the linux-hams
122 mailing list on vger.kernel.org. To subscribe send an e-mail
123 to majordomo@vger.kernel.org with the following line in
124 the body of the mail:
128 The content of the "Subject" field will be ignored.
131 Joerg Reuter ampr-net: dl1bke@db0pra.ampr.org
132 AX-25 : DL1BKE @ DB0ABH.#BAY.DEU.EU
133 Internet: jreuter@yaina.de
134 www : http://yaina.de/jreuter
137 /* ----------------------------------------------------------------------- */
139 #undef SCC_LDELAY /* slow it even a bit more down */
140 #undef SCC_DONT_CHECK /* don't look if the SCCs you specified are available */
142 #define SCC_MAXCHIPS 4 /* number of max. supported chips */
143 #define SCC_BUFSIZE 384 /* must not exceed 4096 */
146 #define SCC_DEFAULT_CLOCK 4915200
147 /* default pclock if nothing is specified */
149 /* ----------------------------------------------------------------------- */
151 #include <linux/compat.h>
152 #include <linux/module.h>
153 #include <linux/errno.h>
154 #include <linux/signal.h>
155 #include <linux/timer.h>
156 #include <linux/interrupt.h>
157 #include <linux/ioport.h>
158 #include <linux/string.h>
159 #include <linux/in.h>
160 #include <linux/fcntl.h>
161 #include <linux/ptrace.h>
162 #include <linux/delay.h>
163 #include <linux/skbuff.h>
164 #include <linux/netdevice.h>
165 #include <linux/rtnetlink.h>
166 #include <linux/if_ether.h>
167 #include <linux/if_arp.h>
168 #include <linux/socket.h>
169 #include <linux/init.h>
170 #include <linux/scc.h>
171 #include <linux/ctype.h>
172 #include <linux/kernel.h>
173 #include <linux/proc_fs.h>
174 #include <linux/seq_file.h>
175 #include <linux/bitops.h>
177 #include <net/net_namespace.h>
178 #include <net/ax25.h>
182 #include <linux/uaccess.h>
186 static const char banner
[] __initconst
= KERN_INFO \
187 "AX.25: Z8530 SCC driver version "VERSION
".dl1bke\n";
189 static void t_dwait(struct timer_list
*t
);
190 static void t_txdelay(struct timer_list
*t
);
191 static void t_tail(struct timer_list
*t
);
192 static void t_busy(struct timer_list
*);
193 static void t_maxkeyup(struct timer_list
*);
194 static void t_idle(struct timer_list
*t
);
195 static void scc_tx_done(struct scc_channel
*);
196 static void scc_start_tx_timer(struct scc_channel
*,
197 void (*)(struct timer_list
*), unsigned long);
198 static void scc_start_maxkeyup(struct scc_channel
*);
199 static void scc_start_defer(struct scc_channel
*);
201 static void z8530_init(void);
203 static void init_channel(struct scc_channel
*scc
);
204 static void scc_key_trx (struct scc_channel
*scc
, char tx
);
205 static void scc_init_timer(struct scc_channel
*scc
);
207 static int scc_net_alloc(const char *name
, struct scc_channel
*scc
);
208 static void scc_net_setup(struct net_device
*dev
);
209 static int scc_net_open(struct net_device
*dev
);
210 static int scc_net_close(struct net_device
*dev
);
211 static void scc_net_rx(struct scc_channel
*scc
, struct sk_buff
*skb
);
212 static netdev_tx_t
scc_net_tx(struct sk_buff
*skb
,
213 struct net_device
*dev
);
214 static int scc_net_siocdevprivate(struct net_device
*dev
, struct ifreq
*ifr
,
215 void __user
*data
, int cmd
);
216 static int scc_net_set_mac_address(struct net_device
*dev
, void *addr
);
217 static struct net_device_stats
* scc_net_get_stats(struct net_device
*dev
);
219 static unsigned char SCC_DriverName
[] = "scc";
221 static struct irqflags
{ unsigned char used
: 1; } Ivec
[NR_IRQS
];
223 static struct scc_channel SCC_Info
[2 * SCC_MAXCHIPS
]; /* information per channel */
225 static struct scc_ctrl
{
229 } SCC_ctrl
[SCC_MAXCHIPS
+1];
231 static unsigned char Driver_Initialized
;
233 static io_port Vector_Latch
;
236 /* ******************************************************************** */
237 /* * Port Access Functions * */
238 /* ******************************************************************** */
240 /* These provide interrupt save 2-step access to the Z8530 registers */
242 static DEFINE_SPINLOCK(iolock
); /* Guards paired accesses */
244 static inline unsigned char InReg(io_port port
, unsigned char reg
)
249 spin_lock_irqsave(&iolock
, flags
);
259 spin_unlock_irqrestore(&iolock
, flags
);
263 static inline void OutReg(io_port port
, unsigned char reg
, unsigned char val
)
267 spin_lock_irqsave(&iolock
, flags
);
269 Outb(port
, reg
); udelay(SCC_LDELAY
);
270 Outb(port
, val
); udelay(SCC_LDELAY
);
275 spin_unlock_irqrestore(&iolock
, flags
);
278 static inline void wr(struct scc_channel
*scc
, unsigned char reg
,
281 OutReg(scc
->ctrl
, reg
, (scc
->wreg
[reg
] = val
));
284 static inline void or(struct scc_channel
*scc
, unsigned char reg
, unsigned char val
)
286 OutReg(scc
->ctrl
, reg
, (scc
->wreg
[reg
] |= val
));
289 static inline void cl(struct scc_channel
*scc
, unsigned char reg
, unsigned char val
)
291 OutReg(scc
->ctrl
, reg
, (scc
->wreg
[reg
] &= ~val
));
294 /* ******************************************************************** */
295 /* * Some useful macros * */
296 /* ******************************************************************** */
298 static inline void scc_discard_buffers(struct scc_channel
*scc
)
302 spin_lock_irqsave(&scc
->lock
, flags
);
303 if (scc
->tx_buff
!= NULL
)
305 dev_kfree_skb_irq(scc
->tx_buff
);
309 while (!skb_queue_empty(&scc
->tx_queue
))
310 dev_kfree_skb_irq(skb_dequeue(&scc
->tx_queue
));
312 spin_unlock_irqrestore(&scc
->lock
, flags
);
317 /* ******************************************************************** */
318 /* * Interrupt Service Routines * */
319 /* ******************************************************************** */
322 /* ----> subroutines for the interrupt handlers <---- */
324 static inline void scc_notify(struct scc_channel
*scc
, int event
)
329 if (scc
->kiss
.fulldup
!= KISS_DUPLEX_OPTIMA
)
332 skb
= dev_alloc_skb(2);
335 bp
= skb_put(skb
, 2);
336 *bp
++ = PARAM_HWEVENT
;
338 scc_net_rx(scc
, skb
);
343 static inline void flush_rx_FIFO(struct scc_channel
*scc
)
350 if(scc
->rx_buff
!= NULL
) /* did we receive something? */
352 scc
->stat
.rxerrs
++; /* then count it as an error */
353 dev_kfree_skb_irq(scc
->rx_buff
);
358 static void start_hunt(struct scc_channel
*scc
)
360 if ((scc
->modem
.clocksrc
!= CLK_EXTERNAL
))
361 OutReg(scc
->ctrl
,R14
,SEARCH
|scc
->wreg
[R14
]); /* DPLL: enter search mode */
362 or(scc
,R3
,ENT_HM
|RxENABLE
); /* enable the receiver, hunt mode */
365 /* ----> four different interrupt handlers for Tx, Rx, changing of */
366 /* DCD/CTS and Rx/Tx errors */
368 /* Transmitter interrupt handler */
369 static inline void scc_txint(struct scc_channel
*scc
)
376 /* send first octet */
380 skb
= skb_dequeue(&scc
->tx_queue
);
382 netif_wake_queue(scc
->dev
);
387 Outb(scc
->ctrl
, RES_Tx_P
);
391 if (skb
->len
== 0) /* Paranoia... */
393 dev_kfree_skb_irq(skb
);
396 Outb(scc
->ctrl
, RES_Tx_P
);
400 scc
->stat
.tx_state
= TXS_ACTIVE
;
402 OutReg(scc
->ctrl
, R0
, RES_Tx_CRC
);
403 /* reset CRC generator */
404 or(scc
,R10
,ABUNDER
); /* re-install underrun protection */
405 Outb(scc
->data
,*skb
->data
); /* send byte */
408 if (!scc
->enhanced
) /* reset EOM latch */
409 Outb(scc
->ctrl
,RES_EOM_L
);
413 /* End Of Frame... */
417 Outb(scc
->ctrl
, RES_Tx_P
); /* reset pending int */
418 cl(scc
, R10
, ABUNDER
); /* send CRC */
419 dev_kfree_skb_irq(skb
);
421 scc
->stat
.tx_state
= TXS_NEWFRAME
; /* next frame... */
427 Outb(scc
->data
,*skb
->data
);
432 /* External/Status interrupt handler */
433 static inline void scc_exint(struct scc_channel
*scc
)
435 unsigned char status
,changes
,chg_and_stat
;
439 status
= InReg(scc
->ctrl
,R0
);
440 changes
= status
^ scc
->status
;
441 chg_and_stat
= changes
& status
;
443 /* ABORT: generated whenever DCD drops while receiving */
445 if (chg_and_stat
& BRK_ABRT
) /* Received an ABORT */
448 /* HUNT: software DCD; on = waiting for SYNC, off = receiving frame */
450 if ((changes
& SYNC_HUNT
) && scc
->kiss
.softdcd
)
452 if (status
& SYNC_HUNT
)
456 if ((scc
->modem
.clocksrc
!= CLK_EXTERNAL
))
457 OutReg(scc
->ctrl
,R14
,SEARCH
|scc
->wreg
[R14
]); /* DPLL: enter search mode */
462 scc_notify(scc
, scc
->dcd
? HWEV_DCD_OFF
:HWEV_DCD_ON
);
465 /* DCD: on = start to receive packet, off = ABORT condition */
466 /* (a successfully received packet generates a special condition int) */
468 if((changes
& DCD
) && !scc
->kiss
.softdcd
) /* DCD input changed state */
470 if(status
& DCD
) /* DCD is now ON */
474 } else { /* DCD is now OFF */
475 cl(scc
,R3
,ENT_HM
|RxENABLE
); /* disable the receiver */
480 scc_notify(scc
, scc
->dcd
? HWEV_DCD_ON
:HWEV_DCD_OFF
);
484 /* CTS: use external TxDelay (what's that good for?!)
485 * Anyway: If we _could_ use it (BayCom USCC uses CTS for
486 * own purposes) we _should_ use the "autoenable" feature
487 * of the Z8530 and not this interrupt...
490 if (chg_and_stat
& CTS
) /* CTS is now ON */
492 if (scc
->kiss
.txdelay
== 0) /* zero TXDELAY = wait for CTS */
493 scc_start_tx_timer(scc
, t_txdelay
, 0);
497 if (scc
->stat
.tx_state
== TXS_ACTIVE
&& (status
& TxEOM
))
499 scc
->stat
.tx_under
++; /* oops, an underrun! count 'em */
500 Outb(scc
->ctrl
, RES_EXT_INT
); /* reset ext/status interrupts */
502 if (scc
->tx_buff
!= NULL
)
504 dev_kfree_skb_irq(scc
->tx_buff
);
509 scc_start_tx_timer(scc
, t_txdelay
, 0); /* restart transmission */
512 scc
->status
= status
;
513 Outb(scc
->ctrl
,RES_EXT_INT
);
517 /* Receiver interrupt handler */
518 static inline void scc_rxint(struct scc_channel
*scc
)
524 if((scc
->wreg
[5] & RTS
) && scc
->kiss
.fulldup
== KISS_DUPLEX_HALF
)
526 Inb(scc
->data
); /* discard char */
527 or(scc
,R3
,ENT_HM
); /* enter hunt mode for next flag */
535 skb
= dev_alloc_skb(scc
->stat
.bufsize
);
538 scc
->dev_stat
.rx_dropped
++;
546 skb_put_u8(skb
, 0); /* KISS data */
549 if (skb
->len
>= scc
->stat
.bufsize
)
552 printk(KERN_DEBUG
"z8530drv: oops, scc_rxint() received huge frame...\n");
554 dev_kfree_skb_irq(skb
);
561 skb_put_u8(skb
, Inb(scc
->data
));
565 /* Receive Special Condition interrupt handler */
566 static inline void scc_spint(struct scc_channel
*scc
)
568 unsigned char status
;
573 status
= InReg(scc
->ctrl
,R1
); /* read receiver status */
575 Inb(scc
->data
); /* throw away Rx byte */
578 if(status
& Rx_OVR
) /* receiver overrun */
580 scc
->stat
.rx_over
++; /* count them */
581 or(scc
,R3
,ENT_HM
); /* enter hunt mode for next flag */
584 dev_kfree_skb_irq(skb
);
585 scc
->rx_buff
= skb
= NULL
;
588 if(status
& END_FR
&& skb
!= NULL
) /* end of frame */
590 /* CRC okay, frame ends on 8 bit boundary and received something ? */
592 if (!(status
& CRC_ERR
) && (status
& 0xe) == RES8
&& skb
->len
> 0)
594 /* ignore last received byte (first of the CRC bytes) */
595 skb_trim(skb
, skb
->len
-1);
596 scc_net_rx(scc
, skb
);
598 scc
->stat
.rxframes
++;
599 } else { /* a bad frame */
600 dev_kfree_skb_irq(skb
);
606 Outb(scc
->ctrl
,ERR_RES
);
610 /* ----> interrupt service routine for the Z8530 <---- */
612 static void scc_isr_dispatch(struct scc_channel
*scc
, int vector
)
614 spin_lock(&scc
->lock
);
615 switch (vector
& VECTOR_MASK
)
617 case TXINT
: scc_txint(scc
); break;
618 case EXINT
: scc_exint(scc
); break;
619 case RXINT
: scc_rxint(scc
); break;
620 case SPINT
: scc_spint(scc
); break;
622 spin_unlock(&scc
->lock
);
625 /* If the card has a latch for the interrupt vector (like the PA0HZP card)
626 use it to get the number of the chip that generated the int.
627 If not: poll all defined chips.
630 #define SCC_IRQTIMEOUT 30000
632 static irqreturn_t
scc_isr(int irq
, void *dev_id
)
634 int chip_irq
= (long) dev_id
;
635 unsigned char vector
;
636 struct scc_channel
*scc
;
637 struct scc_ctrl
*ctrl
;
642 for(k
=0; k
< SCC_IRQTIMEOUT
; k
++)
644 Outb(Vector_Latch
, 0); /* Generate INTACK */
646 /* Read the vector */
647 if((vector
=Inb(Vector_Latch
)) >= 16 * Nchips
) break;
648 if (vector
& 0x01) break;
650 scc
=&SCC_Info
[vector
>> 3 ^ 0x01];
651 if (!scc
->dev
) break;
653 scc_isr_dispatch(scc
, vector
);
655 OutReg(scc
->ctrl
,R0
,RES_H_IUS
); /* Reset Highest IUS */
658 if (k
== SCC_IRQTIMEOUT
)
659 printk(KERN_WARNING
"z8530drv: endless loop in scc_isr()?\n");
664 /* Find the SCC generating the interrupt by polling all attached SCCs
665 * reading RR3A (the interrupt pending register)
671 if (ctrl
->irq
!= chip_irq
)
678 for (k
= 0; InReg(ctrl
->chan_A
,R3
) && k
< SCC_IRQTIMEOUT
; k
++)
680 vector
=InReg(ctrl
->chan_B
,R2
); /* Read the vector */
681 if (vector
& 0x01) break;
683 scc
= &SCC_Info
[vector
>> 3 ^ 0x01];
684 if (!scc
->dev
) break;
686 scc_isr_dispatch(scc
, vector
);
689 if (k
== SCC_IRQTIMEOUT
)
691 printk(KERN_WARNING
"z8530drv: endless loop in scc_isr()?!\n");
695 /* This looks weird and it is. At least the BayCom USCC doesn't
696 * use the Interrupt Daisy Chain, thus we'll have to start
697 * all over again to be sure not to miss an interrupt from
698 * (any of) the other chip(s)...
699 * Honestly, the situation *is* braindamaged...
704 OutReg(scc
->ctrl
,R0
,RES_H_IUS
);
714 /* ******************************************************************** */
716 /* ******************************************************************** */
719 /* ----> set SCC channel speed <---- */
721 static inline void set_brg(struct scc_channel
*scc
, unsigned int tc
)
723 cl(scc
,R14
,BRENABL
); /* disable baudrate generator */
724 wr(scc
,R12
,tc
& 255); /* brg rate LOW */
725 wr(scc
,R13
,tc
>> 8); /* brg rate HIGH */
726 or(scc
,R14
,BRENABL
); /* enable baudrate generator */
729 static inline void set_speed(struct scc_channel
*scc
)
732 spin_lock_irqsave(&scc
->lock
, flags
);
734 if (scc
->modem
.speed
> 0) /* paranoia... */
735 set_brg(scc
, (unsigned) (scc
->clock
/ (scc
->modem
.speed
* 64)) - 2);
737 spin_unlock_irqrestore(&scc
->lock
, flags
);
741 /* ----> initialize a SCC channel <---- */
743 static inline void init_brg(struct scc_channel
*scc
)
745 wr(scc
, R14
, BRSRC
); /* BRG source = PCLK */
746 OutReg(scc
->ctrl
, R14
, SSBR
|scc
->wreg
[R14
]); /* DPLL source = BRG */
747 OutReg(scc
->ctrl
, R14
, SNRZI
|scc
->wreg
[R14
]); /* DPLL NRZI mode */
751 * Initialization according to the Z8530 manual (SGS-Thomson's version):
753 * 1. Modes and constants
755 * WR9 11000000 chip reset
756 * WR4 XXXXXXXX Tx/Rx control, async or sync mode
757 * WR1 0XX00X00 select W/REQ (optional)
758 * WR2 XXXXXXXX program interrupt vector
759 * WR3 XXXXXXX0 select Rx control
760 * WR5 XXXX0XXX select Tx control
761 * WR6 XXXXXXXX sync character
762 * WR7 XXXXXXXX sync character
763 * WR9 000X0XXX select interrupt control
764 * WR10 XXXXXXXX miscellaneous control (optional)
765 * WR11 XXXXXXXX clock control
766 * WR12 XXXXXXXX time constant lower byte (optional)
767 * WR13 XXXXXXXX time constant upper byte (optional)
768 * WR14 XXXXXXX0 miscellaneous control
769 * WR14 XXXSSSSS commands (optional)
773 * WR14 000SSSS1 baud rate enable
774 * WR3 SSSSSSS1 Rx enable
775 * WR5 SSSS1SSS Tx enable
776 * WR0 10000000 reset Tx CRG (optional)
777 * WR1 XSS00S00 DMA enable (optional)
779 * 3. Interrupt status
781 * WR15 XXXXXXXX enable external/status
782 * WR0 00010000 reset external status
783 * WR0 00010000 reset external status twice
784 * WR1 SSSXXSXX enable Rx, Tx and Ext/status
785 * WR9 000SXSSS enable master interrupt enable
787 * 1 = set to one, 0 = reset to zero
788 * X = user defined, S = same as previous init
791 * Note that the implementation differs in some points from above scheme.
795 static void init_channel(struct scc_channel
*scc
)
797 del_timer(&scc
->tx_t
);
798 del_timer(&scc
->tx_wdog
);
800 disable_irq(scc
->irq
);
802 wr(scc
,R4
,X1CLK
|SDLC
); /* *1 clock, SDLC mode */
803 wr(scc
,R1
,0); /* no W/REQ operation */
804 wr(scc
,R3
,Rx8
|RxCRC_ENAB
); /* RX 8 bits/char, CRC, disabled */
805 wr(scc
,R5
,Tx8
|DTR
|TxCRC_ENAB
); /* TX 8 bits/char, disabled, DTR */
806 wr(scc
,R6
,0); /* SDLC address zero (not used) */
807 wr(scc
,R7
,FLAG
); /* SDLC flag value */
808 wr(scc
,R9
,VIS
); /* vector includes status */
809 wr(scc
,R10
,(scc
->modem
.nrz
? NRZ
: NRZI
)|CRCPS
|ABUNDER
); /* abort on underrun, preset CRC generator, NRZ(I) */
813 /* set clock sources:
815 CLK_DPLL: normal halfduplex operation
819 TRxC mode DPLL output
821 CLK_EXTERNAL: external clocking (G3RUH or DF9IC modem)
825 TxClk = pin RTxC TxClk = pin TRxC
826 RxClk = pin TRxC RxClk = pin RTxC
834 pin TRxC = DPLL pin TRxC = BRG
835 (RxClk * 1) (RxClk * 32)
839 switch(scc
->modem
.clocksrc
)
842 wr(scc
, R11
, RCDPLL
|TCDPLL
|TRxCOI
|TRxCDP
);
847 wr(scc
, R11
, ((scc
->brand
& BAYCOM
)? TRxCDP
: TRxCBR
) | RCDPLL
|TCRTxCP
|TRxCOI
);
852 wr(scc
, R11
, (scc
->brand
& BAYCOM
)? RCTRxCP
|TCRTxCP
: RCRTxCP
|TCTRxCP
);
853 OutReg(scc
->ctrl
, R14
, DISDPLL
);
858 set_speed(scc
); /* set baudrate */
862 or(scc
,R15
,SHDLCE
|FIFOE
); /* enable FIFO, SDLC/HDLC Enhancements (From now R7 is R7') */
866 if(scc
->kiss
.softdcd
|| (InReg(scc
->ctrl
,R0
) & DCD
))
872 /* enable ABORT, DCD & SYNC/HUNT interrupts */
874 wr(scc
,R15
, BRKIE
|TxUIE
|(scc
->kiss
.softdcd
? SYNCIE
:DCDIE
));
876 Outb(scc
->ctrl
,RES_EXT_INT
); /* reset ext/status interrupts */
877 Outb(scc
->ctrl
,RES_EXT_INT
); /* must be done twice */
879 or(scc
,R1
,INT_ALL_Rx
|TxINT_ENAB
|EXT_INT_ENAB
); /* enable interrupts */
881 scc
->status
= InReg(scc
->ctrl
,R0
); /* read initial status */
883 or(scc
,R9
,MIE
); /* master interrupt enable */
887 enable_irq(scc
->irq
);
893 /* ******************************************************************** */
894 /* * SCC timer functions * */
895 /* ******************************************************************** */
898 /* ----> scc_key_trx sets the time constant for the baudrate
899 generator and keys the transmitter <---- */
901 static void scc_key_trx(struct scc_channel
*scc
, char tx
)
903 unsigned int time_const
;
905 if (scc
->brand
& PRIMUS
)
906 Outb(scc
->ctrl
+ 4, scc
->option
| (tx
? 0x80 : 0));
908 if (scc
->modem
.speed
< 300)
909 scc
->modem
.speed
= 1200;
911 time_const
= (unsigned) (scc
->clock
/ (scc
->modem
.speed
* (tx
? 2:64))) - 2;
913 disable_irq(scc
->irq
);
917 or(scc
, R1
, TxINT_ENAB
); /* t_maxkeyup may have reset these */
921 if (scc
->modem
.clocksrc
== CLK_DPLL
)
922 { /* force simplex operation */
925 #ifdef CONFIG_SCC_TRXECHO
926 cl(scc
, R3
, RxENABLE
|ENT_HM
); /* switch off receiver */
927 cl(scc
, R15
, DCDIE
|SYNCIE
); /* No DCD changes, please */
929 set_brg(scc
, time_const
); /* reprogram baudrate generator */
931 /* DPLL -> Rx clk, BRG -> Tx CLK, TRxC mode output, TRxC = BRG */
932 wr(scc
, R11
, RCDPLL
|TCBR
|TRxCOI
|TRxCBR
);
934 /* By popular demand: tx_inhibit */
935 if (scc
->kiss
.tx_inhibit
)
938 scc
->wreg
[R5
] |= RTS
;
940 or(scc
,R5
,RTS
|TxENAB
); /* set the RTS line and enable TX */
943 cl(scc
,R5
,RTS
|TxENAB
);
945 set_brg(scc
, time_const
); /* reprogram baudrate generator */
947 /* DPLL -> Rx clk, DPLL -> Tx CLK, TRxC mode output, TRxC = DPLL */
948 wr(scc
, R11
, RCDPLL
|TCDPLL
|TRxCOI
|TRxCDP
);
950 #ifndef CONFIG_SCC_TRXECHO
951 if (scc
->kiss
.softdcd
)
954 or(scc
,R15
, scc
->kiss
.softdcd
? SYNCIE
:DCDIE
);
961 #ifdef CONFIG_SCC_TRXECHO
962 if (scc
->kiss
.fulldup
== KISS_DUPLEX_HALF
)
964 cl(scc
, R3
, RxENABLE
);
965 cl(scc
, R15
, DCDIE
|SYNCIE
);
969 if (scc
->kiss
.tx_inhibit
)
972 scc
->wreg
[R5
] |= RTS
;
974 or(scc
,R5
,RTS
|TxENAB
); /* enable tx */
977 cl(scc
,R5
,RTS
|TxENAB
); /* disable tx */
979 if ((scc
->kiss
.fulldup
== KISS_DUPLEX_HALF
) &&
980 #ifndef CONFIG_SCC_TRXECHO
986 or(scc
, R15
, scc
->kiss
.softdcd
? SYNCIE
:DCDIE
);
992 enable_irq(scc
->irq
);
996 /* ----> SCC timer interrupt handler and friends. <---- */
998 static void __scc_start_tx_timer(struct scc_channel
*scc
,
999 void (*handler
)(struct timer_list
*t
),
1002 del_timer(&scc
->tx_t
);
1006 handler(&scc
->tx_t
);
1008 if (when
!= TIMER_OFF
)
1010 scc
->tx_t
.function
= handler
;
1011 scc
->tx_t
.expires
= jiffies
+ (when
*HZ
)/100;
1012 add_timer(&scc
->tx_t
);
1016 static void scc_start_tx_timer(struct scc_channel
*scc
,
1017 void (*handler
)(struct timer_list
*t
),
1020 unsigned long flags
;
1022 spin_lock_irqsave(&scc
->lock
, flags
);
1023 __scc_start_tx_timer(scc
, handler
, when
);
1024 spin_unlock_irqrestore(&scc
->lock
, flags
);
1027 static void scc_start_defer(struct scc_channel
*scc
)
1029 unsigned long flags
;
1031 spin_lock_irqsave(&scc
->lock
, flags
);
1032 del_timer(&scc
->tx_wdog
);
1034 if (scc
->kiss
.maxdefer
!= 0 && scc
->kiss
.maxdefer
!= TIMER_OFF
)
1036 scc
->tx_wdog
.function
= t_busy
;
1037 scc
->tx_wdog
.expires
= jiffies
+ HZ
*scc
->kiss
.maxdefer
;
1038 add_timer(&scc
->tx_wdog
);
1040 spin_unlock_irqrestore(&scc
->lock
, flags
);
1043 static void scc_start_maxkeyup(struct scc_channel
*scc
)
1045 unsigned long flags
;
1047 spin_lock_irqsave(&scc
->lock
, flags
);
1048 del_timer(&scc
->tx_wdog
);
1050 if (scc
->kiss
.maxkeyup
!= 0 && scc
->kiss
.maxkeyup
!= TIMER_OFF
)
1052 scc
->tx_wdog
.function
= t_maxkeyup
;
1053 scc
->tx_wdog
.expires
= jiffies
+ HZ
*scc
->kiss
.maxkeyup
;
1054 add_timer(&scc
->tx_wdog
);
1056 spin_unlock_irqrestore(&scc
->lock
, flags
);
1060 * This is called from scc_txint() when there are no more frames to send.
1061 * Not exactly a timer function, but it is a close friend of the family...
1064 static void scc_tx_done(struct scc_channel
*scc
)
1067 * trx remains keyed in fulldup mode 2 until t_idle expires.
1070 switch (scc
->kiss
.fulldup
)
1072 case KISS_DUPLEX_LINK
:
1073 scc
->stat
.tx_state
= TXS_IDLE2
;
1074 if (scc
->kiss
.idletime
!= TIMER_OFF
)
1075 scc_start_tx_timer(scc
, t_idle
,
1076 scc
->kiss
.idletime
*100);
1078 case KISS_DUPLEX_OPTIMA
:
1079 scc_notify(scc
, HWEV_ALL_SENT
);
1082 scc
->stat
.tx_state
= TXS_BUSY
;
1083 scc_start_tx_timer(scc
, t_tail
, scc
->kiss
.tailtime
);
1086 netif_wake_queue(scc
->dev
);
1090 static unsigned char Rand
= 17;
1092 static inline int is_grouped(struct scc_channel
*scc
)
1095 struct scc_channel
*scc2
;
1096 unsigned char grp1
, grp2
;
1098 grp1
= scc
->kiss
.group
;
1100 for (k
= 0; k
< (Nchips
* 2); k
++)
1102 scc2
= &SCC_Info
[k
];
1103 grp2
= scc2
->kiss
.group
;
1105 if (scc2
== scc
|| !(scc2
->dev
&& grp2
))
1108 if ((grp1
& 0x3f) == (grp2
& 0x3f))
1110 if ( (grp1
& TXGROUP
) && (scc2
->wreg
[R5
] & RTS
) )
1113 if ( (grp1
& RXGROUP
) && scc2
->dcd
)
1120 /* DWAIT and SLOTTIME expired
1122 * fulldup == 0: DCD is active or Rand > P-persistence: start t_busy timer
1123 * else key trx and start txdelay
1124 * fulldup == 1: key trx and start txdelay
1125 * fulldup == 2: mintime expired, reset status or key trx and start txdelay
1128 static void t_dwait(struct timer_list
*t
)
1130 struct scc_channel
*scc
= from_timer(scc
, t
, tx_t
);
1132 if (scc
->stat
.tx_state
== TXS_WAIT
) /* maxkeyup or idle timeout */
1134 if (skb_queue_empty(&scc
->tx_queue
)) { /* nothing to send */
1135 scc
->stat
.tx_state
= TXS_IDLE
;
1136 netif_wake_queue(scc
->dev
); /* t_maxkeyup locked it. */
1140 scc
->stat
.tx_state
= TXS_BUSY
;
1143 if (scc
->kiss
.fulldup
== KISS_DUPLEX_HALF
)
1145 Rand
= Rand
* 17 + 31;
1147 if (scc
->dcd
|| (scc
->kiss
.persist
) < Rand
|| (scc
->kiss
.group
&& is_grouped(scc
)) )
1149 scc_start_defer(scc
);
1150 scc_start_tx_timer(scc
, t_dwait
, scc
->kiss
.slottime
);
1155 if ( !(scc
->wreg
[R5
] & RTS
) )
1157 scc_key_trx(scc
, TX_ON
);
1158 scc_start_tx_timer(scc
, t_txdelay
, scc
->kiss
.txdelay
);
1160 scc_start_tx_timer(scc
, t_txdelay
, 0);
1167 * kick transmission by a fake scc_txint(scc), start 'maxkeyup' watchdog.
1170 static void t_txdelay(struct timer_list
*t
)
1172 struct scc_channel
*scc
= from_timer(scc
, t
, tx_t
);
1174 scc_start_maxkeyup(scc
);
1176 if (scc
->tx_buff
== NULL
)
1178 disable_irq(scc
->irq
);
1180 enable_irq(scc
->irq
);
1187 * switch off transmitter. If we were stopped by Maxkeyup restart
1188 * transmission after 'mintime' seconds
1191 static void t_tail(struct timer_list
*t
)
1193 struct scc_channel
*scc
= from_timer(scc
, t
, tx_t
);
1194 unsigned long flags
;
1196 spin_lock_irqsave(&scc
->lock
, flags
);
1197 del_timer(&scc
->tx_wdog
);
1198 scc_key_trx(scc
, TX_OFF
);
1199 spin_unlock_irqrestore(&scc
->lock
, flags
);
1201 if (scc
->stat
.tx_state
== TXS_TIMEOUT
) /* we had a timeout? */
1203 scc
->stat
.tx_state
= TXS_WAIT
;
1204 scc_start_tx_timer(scc
, t_dwait
, scc
->kiss
.mintime
*100);
1208 scc
->stat
.tx_state
= TXS_IDLE
;
1209 netif_wake_queue(scc
->dev
);
1215 * throw away send buffers if DCD remains active too long.
1218 static void t_busy(struct timer_list
*t
)
1220 struct scc_channel
*scc
= from_timer(scc
, t
, tx_wdog
);
1222 del_timer(&scc
->tx_t
);
1223 netif_stop_queue(scc
->dev
); /* don't pile on the wabbit! */
1225 scc_discard_buffers(scc
);
1227 scc
->stat
.tx_state
= TXS_IDLE
;
1229 netif_wake_queue(scc
->dev
);
1234 * this is our watchdog.
1237 static void t_maxkeyup(struct timer_list
*t
)
1239 struct scc_channel
*scc
= from_timer(scc
, t
, tx_wdog
);
1240 unsigned long flags
;
1242 spin_lock_irqsave(&scc
->lock
, flags
);
1244 * let things settle down before we start to
1248 netif_stop_queue(scc
->dev
);
1249 scc_discard_buffers(scc
);
1251 del_timer(&scc
->tx_t
);
1253 cl(scc
, R1
, TxINT_ENAB
); /* force an ABORT, but don't */
1254 cl(scc
, R15
, TxUIE
); /* count it. */
1255 OutReg(scc
->ctrl
, R0
, RES_Tx_P
);
1257 spin_unlock_irqrestore(&scc
->lock
, flags
);
1260 scc
->stat
.tx_state
= TXS_TIMEOUT
;
1261 scc_start_tx_timer(scc
, t_tail
, scc
->kiss
.tailtime
);
1266 * in fulldup mode 2 it keys down the transmitter after 'idle' seconds
1267 * of inactivity. We will not restart transmission before 'mintime'
1271 static void t_idle(struct timer_list
*t
)
1273 struct scc_channel
*scc
= from_timer(scc
, t
, tx_t
);
1275 del_timer(&scc
->tx_wdog
);
1277 scc_key_trx(scc
, TX_OFF
);
1278 if(scc
->kiss
.mintime
)
1279 scc_start_tx_timer(scc
, t_dwait
, scc
->kiss
.mintime
*100);
1280 scc
->stat
.tx_state
= TXS_WAIT
;
1283 static void scc_init_timer(struct scc_channel
*scc
)
1285 unsigned long flags
;
1287 spin_lock_irqsave(&scc
->lock
, flags
);
1288 scc
->stat
.tx_state
= TXS_IDLE
;
1289 spin_unlock_irqrestore(&scc
->lock
, flags
);
1293 /* ******************************************************************** */
1294 /* * Set/get L1 parameters * */
1295 /* ******************************************************************** */
1299 * this will set the "hardware" parameters through KISS commands or ioctl()
1302 #define CAST(x) (unsigned long)(x)
1304 static unsigned int scc_set_param(struct scc_channel
*scc
, unsigned int cmd
, unsigned int arg
)
1308 case PARAM_TXDELAY
: scc
->kiss
.txdelay
=arg
; break;
1309 case PARAM_PERSIST
: scc
->kiss
.persist
=arg
; break;
1310 case PARAM_SLOTTIME
: scc
->kiss
.slottime
=arg
; break;
1311 case PARAM_TXTAIL
: scc
->kiss
.tailtime
=arg
; break;
1312 case PARAM_FULLDUP
: scc
->kiss
.fulldup
=arg
; break;
1313 case PARAM_DTR
: break; /* does someone need this? */
1314 case PARAM_GROUP
: scc
->kiss
.group
=arg
; break;
1315 case PARAM_IDLE
: scc
->kiss
.idletime
=arg
; break;
1316 case PARAM_MIN
: scc
->kiss
.mintime
=arg
; break;
1317 case PARAM_MAXKEY
: scc
->kiss
.maxkeyup
=arg
; break;
1318 case PARAM_WAIT
: scc
->kiss
.waittime
=arg
; break;
1319 case PARAM_MAXDEFER
: scc
->kiss
.maxdefer
=arg
; break;
1320 case PARAM_TX
: scc
->kiss
.tx_inhibit
=arg
; break;
1323 scc
->kiss
.softdcd
=arg
;
1326 or(scc
, R15
, SYNCIE
);
1327 cl(scc
, R15
, DCDIE
);
1330 or(scc
, R15
, DCDIE
);
1331 cl(scc
, R15
, SYNCIE
);
1337 scc
->modem
.speed
=arg
*100;
1339 scc
->modem
.speed
=arg
;
1341 if (scc
->stat
.tx_state
== 0) /* only switch baudrate on rx... ;-) */
1346 if ( !(scc
->wreg
[R5
] & RTS
) )
1348 if (arg
!= TX_OFF
) {
1349 scc_key_trx(scc
, TX_ON
);
1350 scc_start_tx_timer(scc
, t_txdelay
, scc
->kiss
.txdelay
);
1355 scc
->stat
.tx_state
= TXS_BUSY
;
1356 scc_start_tx_timer(scc
, t_tail
, scc
->kiss
.tailtime
);
1362 scc_notify(scc
, scc
->dcd
? HWEV_DCD_ON
:HWEV_DCD_OFF
);
1365 default: return -EINVAL
;
1373 static unsigned long scc_get_param(struct scc_channel
*scc
, unsigned int cmd
)
1377 case PARAM_TXDELAY
: return CAST(scc
->kiss
.txdelay
);
1378 case PARAM_PERSIST
: return CAST(scc
->kiss
.persist
);
1379 case PARAM_SLOTTIME
: return CAST(scc
->kiss
.slottime
);
1380 case PARAM_TXTAIL
: return CAST(scc
->kiss
.tailtime
);
1381 case PARAM_FULLDUP
: return CAST(scc
->kiss
.fulldup
);
1382 case PARAM_SOFTDCD
: return CAST(scc
->kiss
.softdcd
);
1383 case PARAM_DTR
: return CAST((scc
->wreg
[R5
] & DTR
)? 1:0);
1384 case PARAM_RTS
: return CAST((scc
->wreg
[R5
] & RTS
)? 1:0);
1385 case PARAM_SPEED
: return CAST(scc
->modem
.speed
);
1386 case PARAM_GROUP
: return CAST(scc
->kiss
.group
);
1387 case PARAM_IDLE
: return CAST(scc
->kiss
.idletime
);
1388 case PARAM_MIN
: return CAST(scc
->kiss
.mintime
);
1389 case PARAM_MAXKEY
: return CAST(scc
->kiss
.maxkeyup
);
1390 case PARAM_WAIT
: return CAST(scc
->kiss
.waittime
);
1391 case PARAM_MAXDEFER
: return CAST(scc
->kiss
.maxdefer
);
1392 case PARAM_TX
: return CAST(scc
->kiss
.tx_inhibit
);
1393 default: return NO_SUCH_PARAM
;
1400 /* ******************************************************************* */
1401 /* * Send calibration pattern * */
1402 /* ******************************************************************* */
1404 static void scc_stop_calibrate(struct timer_list
*t
)
1406 struct scc_channel
*scc
= from_timer(scc
, t
, tx_wdog
);
1407 unsigned long flags
;
1409 spin_lock_irqsave(&scc
->lock
, flags
);
1410 del_timer(&scc
->tx_wdog
);
1411 scc_key_trx(scc
, TX_OFF
);
1414 Outb(scc
->ctrl
,RES_EXT_INT
); /* reset ext/status interrupts */
1415 Outb(scc
->ctrl
,RES_EXT_INT
);
1417 netif_wake_queue(scc
->dev
);
1418 spin_unlock_irqrestore(&scc
->lock
, flags
);
1423 scc_start_calibrate(struct scc_channel
*scc
, int duration
, unsigned char pattern
)
1425 unsigned long flags
;
1427 spin_lock_irqsave(&scc
->lock
, flags
);
1428 netif_stop_queue(scc
->dev
);
1429 scc_discard_buffers(scc
);
1431 del_timer(&scc
->tx_wdog
);
1433 scc
->tx_wdog
.function
= scc_stop_calibrate
;
1434 scc
->tx_wdog
.expires
= jiffies
+ HZ
*duration
;
1435 add_timer(&scc
->tx_wdog
);
1437 /* This doesn't seem to work. Why not? */
1439 wr(scc
, R7
, pattern
);
1442 * Don't know if this works.
1443 * Damn, where is my Z8530 programming manual...?
1446 Outb(scc
->ctrl
,RES_EXT_INT
); /* reset ext/status interrupts */
1447 Outb(scc
->ctrl
,RES_EXT_INT
);
1449 scc_key_trx(scc
, TX_ON
);
1450 spin_unlock_irqrestore(&scc
->lock
, flags
);
1453 /* ******************************************************************* */
1454 /* * Init channel structures, special HW, etc... * */
1455 /* ******************************************************************* */
1458 * Reset the Z8530s and setup special hardware
1461 static void z8530_init(void)
1463 const unsigned int nr_irqs
= irq_get_nr_irqs();
1464 struct scc_channel
*scc
;
1466 unsigned long flags
;
1470 printk(KERN_INFO
"Init Z8530 driver: %u channels, IRQ", Nchips
*2);
1473 for (k
= 0; k
< nr_irqs
; k
++)
1476 printk("%s%d", flag
, k
);
1482 /* reset and pre-init all chips in the system */
1483 for (chip
= 0; chip
< Nchips
; chip
++)
1485 scc
=&SCC_Info
[2*chip
];
1486 if (!scc
->ctrl
) continue;
1488 /* Special SCC cards */
1490 if(scc
->brand
& EAGLE
) /* this is an EAGLE card */
1491 Outb(scc
->special
,0x08); /* enable interrupt on the board */
1493 if(scc
->brand
& (PC100
| PRIMUS
)) /* this is a PC100/PRIMUS card */
1494 Outb(scc
->special
,scc
->option
); /* set the MODEM mode (0x22) */
1497 /* Reset and pre-init Z8530 */
1499 spin_lock_irqsave(&scc
->lock
, flags
);
1502 OutReg(scc
->ctrl
,R9
,FHWRES
); /* force hardware reset */
1503 udelay(100); /* give it 'a bit' more time than required */
1504 wr(scc
, R2
, chip
*16); /* interrupt vector */
1505 wr(scc
, R9
, VIS
); /* vector includes status */
1506 spin_unlock_irqrestore(&scc
->lock
, flags
);
1510 Driver_Initialized
= 1;
1514 * Allocate device structure, err, instance, and register driver
1517 static int scc_net_alloc(const char *name
, struct scc_channel
*scc
)
1520 struct net_device
*dev
;
1522 dev
= alloc_netdev(0, name
, NET_NAME_UNKNOWN
, scc_net_setup
);
1528 spin_lock_init(&scc
->lock
);
1529 timer_setup(&scc
->tx_t
, NULL
, 0);
1530 timer_setup(&scc
->tx_wdog
, NULL
, 0);
1532 err
= register_netdevice(dev
);
1534 printk(KERN_ERR
"%s: can't register network device (%d)\n",
1546 /* ******************************************************************** */
1547 /* * Network driver methods * */
1548 /* ******************************************************************** */
1550 static const struct net_device_ops scc_netdev_ops
= {
1551 .ndo_open
= scc_net_open
,
1552 .ndo_stop
= scc_net_close
,
1553 .ndo_start_xmit
= scc_net_tx
,
1554 .ndo_set_mac_address
= scc_net_set_mac_address
,
1555 .ndo_get_stats
= scc_net_get_stats
,
1556 .ndo_siocdevprivate
= scc_net_siocdevprivate
,
1559 /* ----> Initialize device <----- */
1561 static void scc_net_setup(struct net_device
*dev
)
1563 dev
->tx_queue_len
= 16; /* should be enough... */
1565 dev
->netdev_ops
= &scc_netdev_ops
;
1566 dev
->header_ops
= &ax25_header_ops
;
1570 dev
->type
= ARPHRD_AX25
;
1571 dev
->hard_header_len
= AX25_MAX_HEADER_LEN
+ AX25_BPQ_HEADER_LEN
;
1572 dev
->mtu
= AX25_DEF_PACLEN
;
1573 dev
->addr_len
= AX25_ADDR_LEN
;
1575 memcpy(dev
->broadcast
, &ax25_bcast
, AX25_ADDR_LEN
);
1576 dev_addr_set(dev
, (u8
*)&ax25_defaddr
);
1579 /* ----> open network device <---- */
1581 static int scc_net_open(struct net_device
*dev
)
1583 struct scc_channel
*scc
= (struct scc_channel
*) dev
->ml_priv
;
1588 scc
->tx_buff
= NULL
;
1589 skb_queue_head_init(&scc
->tx_queue
);
1593 netif_start_queue(dev
);
1597 /* ----> close network device <---- */
1599 static int scc_net_close(struct net_device
*dev
)
1601 struct scc_channel
*scc
= (struct scc_channel
*) dev
->ml_priv
;
1602 unsigned long flags
;
1604 netif_stop_queue(dev
);
1606 spin_lock_irqsave(&scc
->lock
, flags
);
1607 Outb(scc
->ctrl
,0); /* Make sure pointer is written */
1608 wr(scc
,R1
,0); /* disable interrupts */
1610 spin_unlock_irqrestore(&scc
->lock
, flags
);
1612 del_timer_sync(&scc
->tx_t
);
1613 del_timer_sync(&scc
->tx_wdog
);
1615 scc_discard_buffers(scc
);
1620 /* ----> receive frame, called from scc_rxint() <---- */
1622 static void scc_net_rx(struct scc_channel
*scc
, struct sk_buff
*skb
)
1624 if (skb
->len
== 0) {
1625 dev_kfree_skb_irq(skb
);
1629 scc
->dev_stat
.rx_packets
++;
1630 scc
->dev_stat
.rx_bytes
+= skb
->len
;
1632 skb
->protocol
= ax25_type_trans(skb
, scc
->dev
);
1637 /* ----> transmit frame <---- */
1639 static netdev_tx_t
scc_net_tx(struct sk_buff
*skb
, struct net_device
*dev
)
1641 struct scc_channel
*scc
= (struct scc_channel
*) dev
->ml_priv
;
1642 unsigned long flags
;
1645 if (skb
->protocol
== htons(ETH_P_IP
))
1646 return ax25_ip_xmit(skb
);
1648 if (skb
->len
> scc
->stat
.bufsize
|| skb
->len
< 2) {
1649 scc
->dev_stat
.tx_dropped
++; /* bogus frame */
1651 return NETDEV_TX_OK
;
1654 scc
->dev_stat
.tx_packets
++;
1655 scc
->dev_stat
.tx_bytes
+= skb
->len
;
1656 scc
->stat
.txframes
++;
1658 kisscmd
= *skb
->data
& 0x1f;
1662 scc_set_param(scc
, kisscmd
, *skb
->data
);
1664 return NETDEV_TX_OK
;
1667 spin_lock_irqsave(&scc
->lock
, flags
);
1669 if (skb_queue_len(&scc
->tx_queue
) > scc
->dev
->tx_queue_len
) {
1670 struct sk_buff
*skb_del
;
1671 skb_del
= skb_dequeue(&scc
->tx_queue
);
1672 dev_kfree_skb_irq(skb_del
);
1674 skb_queue_tail(&scc
->tx_queue
, skb
);
1675 netif_trans_update(dev
);
1679 * Start transmission if the trx state is idle or
1680 * t_idle hasn't expired yet. Use dwait/persistence/slottime
1681 * algorithm for normal halfduplex operation.
1684 if(scc
->stat
.tx_state
== TXS_IDLE
|| scc
->stat
.tx_state
== TXS_IDLE2
) {
1685 scc
->stat
.tx_state
= TXS_BUSY
;
1686 if (scc
->kiss
.fulldup
== KISS_DUPLEX_HALF
)
1687 __scc_start_tx_timer(scc
, t_dwait
, scc
->kiss
.waittime
);
1689 __scc_start_tx_timer(scc
, t_dwait
, 0);
1691 spin_unlock_irqrestore(&scc
->lock
, flags
);
1692 return NETDEV_TX_OK
;
1695 /* ----> ioctl functions <---- */
1698 * SIOCSCCCFG - configure driver arg: (struct scc_hw_config *) arg
1699 * SIOCSCCINI - initialize driver arg: ---
1700 * SIOCSCCCHANINI - initialize channel arg: (struct scc_modem *) arg
1701 * SIOCSCCSMEM - set memory arg: (struct scc_mem_config *) arg
1702 * SIOCSCCGKISS - get level 1 parameter arg: (struct scc_kiss_cmd *) arg
1703 * SIOCSCCSKISS - set level 1 parameter arg: (struct scc_kiss_cmd *) arg
1704 * SIOCSCCGSTAT - get driver status arg: (struct scc_stat *) arg
1705 * SIOCSCCCAL - send calib. pattern arg: (struct scc_calibrate *) arg
1708 static int scc_net_siocdevprivate(struct net_device
*dev
,
1709 struct ifreq
*ifr
, void __user
*arg
, int cmd
)
1711 struct scc_kiss_cmd kiss_cmd
;
1712 struct scc_mem_config memcfg
;
1713 struct scc_hw_config hwcfg
;
1714 struct scc_calibrate cal
;
1715 struct scc_channel
*scc
= (struct scc_channel
*) dev
->ml_priv
;
1717 unsigned char device_name
[IFNAMSIZ
];
1719 if (!Driver_Initialized
)
1721 if (cmd
== SIOCSCCCFG
)
1725 if (!capable(CAP_SYS_RAWIO
)) return -EPERM
;
1726 if (in_compat_syscall())
1729 if (!arg
) return -EFAULT
;
1731 if (Nchips
>= SCC_MAXCHIPS
)
1734 if (copy_from_user(&hwcfg
, arg
, sizeof(hwcfg
)))
1737 if (hwcfg
.irq
== 2) hwcfg
.irq
= 9;
1739 if (hwcfg
.irq
< 0 || hwcfg
.irq
>= irq_get_nr_irqs())
1742 if (!Ivec
[hwcfg
.irq
].used
&& hwcfg
.irq
)
1744 if (request_irq(hwcfg
.irq
, scc_isr
,
1746 (void *)(long) hwcfg
.irq
))
1747 printk(KERN_WARNING
"z8530drv: warning, cannot get IRQ %d\n", hwcfg
.irq
);
1749 Ivec
[hwcfg
.irq
].used
= 1;
1752 if (hwcfg
.vector_latch
&& !Vector_Latch
) {
1753 if (!request_region(hwcfg
.vector_latch
, 1, "scc vector latch"))
1754 printk(KERN_WARNING
"z8530drv: warning, cannot reserve vector latch port 0x%lx\n, disabled.", hwcfg
.vector_latch
);
1756 Vector_Latch
= hwcfg
.vector_latch
;
1759 if (hwcfg
.clock
== 0)
1760 hwcfg
.clock
= SCC_DEFAULT_CLOCK
;
1762 #ifndef SCC_DONT_CHECK
1764 if(request_region(hwcfg
.ctrl_a
, 1, "scc-probe"))
1766 disable_irq(hwcfg
.irq
);
1767 Outb(hwcfg
.ctrl_a
, 0);
1768 OutReg(hwcfg
.ctrl_a
, R9
, FHWRES
);
1770 OutReg(hwcfg
.ctrl_a
,R13
,0x55); /* is this chip really there? */
1773 if (InReg(hwcfg
.ctrl_a
,R13
) != 0x55)
1775 enable_irq(hwcfg
.irq
);
1776 release_region(hwcfg
.ctrl_a
, 1);
1784 SCC_Info
[2*Nchips
].ctrl
= hwcfg
.ctrl_a
;
1785 SCC_Info
[2*Nchips
].data
= hwcfg
.data_a
;
1786 SCC_Info
[2*Nchips
].irq
= hwcfg
.irq
;
1787 SCC_Info
[2*Nchips
+1].ctrl
= hwcfg
.ctrl_b
;
1788 SCC_Info
[2*Nchips
+1].data
= hwcfg
.data_b
;
1789 SCC_Info
[2*Nchips
+1].irq
= hwcfg
.irq
;
1791 SCC_ctrl
[Nchips
].chan_A
= hwcfg
.ctrl_a
;
1792 SCC_ctrl
[Nchips
].chan_B
= hwcfg
.ctrl_b
;
1793 SCC_ctrl
[Nchips
].irq
= hwcfg
.irq
;
1797 for (chan
= 0; chan
< 2; chan
++)
1799 sprintf(device_name
, "%s%i", SCC_DriverName
, 2*Nchips
+chan
);
1801 SCC_Info
[2*Nchips
+chan
].special
= hwcfg
.special
;
1802 SCC_Info
[2*Nchips
+chan
].clock
= hwcfg
.clock
;
1803 SCC_Info
[2*Nchips
+chan
].brand
= hwcfg
.brand
;
1804 SCC_Info
[2*Nchips
+chan
].option
= hwcfg
.option
;
1805 SCC_Info
[2*Nchips
+chan
].enhanced
= hwcfg
.escc
;
1807 #ifdef SCC_DONT_CHECK
1808 printk(KERN_INFO
"%s: data port = 0x%3.3x control port = 0x%3.3x\n",
1810 SCC_Info
[2*Nchips
+chan
].data
,
1811 SCC_Info
[2*Nchips
+chan
].ctrl
);
1814 printk(KERN_INFO
"%s: data port = 0x%3.3lx control port = 0x%3.3lx -- %s\n",
1816 chan
? hwcfg
.data_b
: hwcfg
.data_a
,
1817 chan
? hwcfg
.ctrl_b
: hwcfg
.ctrl_a
,
1818 found
? "found" : "missing");
1823 request_region(SCC_Info
[2*Nchips
+chan
].ctrl
, 1, "scc ctrl");
1824 request_region(SCC_Info
[2*Nchips
+chan
].data
, 1, "scc data");
1825 if (Nchips
+chan
!= 0 &&
1826 scc_net_alloc(device_name
,
1827 &SCC_Info
[2*Nchips
+chan
]))
1832 if (found
) Nchips
++;
1837 if (cmd
== SIOCSCCINI
)
1839 if (!capable(CAP_SYS_RAWIO
))
1849 return -EINVAL
; /* confuse the user */
1854 if (cmd
== SIOCSCCCHANINI
)
1856 if (!capable(CAP_NET_ADMIN
)) return -EPERM
;
1857 if (!arg
) return -EINVAL
;
1859 scc
->stat
.bufsize
= SCC_BUFSIZE
;
1861 if (copy_from_user(&scc
->modem
, arg
, sizeof(struct scc_modem
)))
1864 /* default KISS Params */
1866 if (scc
->modem
.speed
< 4800)
1868 scc
->kiss
.txdelay
= 36; /* 360 ms */
1869 scc
->kiss
.persist
= 42; /* 25% persistence */ /* was 25 */
1870 scc
->kiss
.slottime
= 16; /* 160 ms */
1871 scc
->kiss
.tailtime
= 4; /* minimal reasonable value */
1872 scc
->kiss
.fulldup
= 0; /* CSMA */
1873 scc
->kiss
.waittime
= 50; /* 500 ms */
1874 scc
->kiss
.maxkeyup
= 10; /* 10 s */
1875 scc
->kiss
.mintime
= 3; /* 3 s */
1876 scc
->kiss
.idletime
= 30; /* 30 s */
1877 scc
->kiss
.maxdefer
= 120; /* 2 min */
1878 scc
->kiss
.softdcd
= 0; /* hardware dcd */
1880 scc
->kiss
.txdelay
= 10; /* 100 ms */
1881 scc
->kiss
.persist
= 64; /* 25% persistence */ /* was 25 */
1882 scc
->kiss
.slottime
= 8; /* 160 ms */
1883 scc
->kiss
.tailtime
= 1; /* minimal reasonable value */
1884 scc
->kiss
.fulldup
= 0; /* CSMA */
1885 scc
->kiss
.waittime
= 50; /* 500 ms */
1886 scc
->kiss
.maxkeyup
= 7; /* 7 s */
1887 scc
->kiss
.mintime
= 3; /* 3 s */
1888 scc
->kiss
.idletime
= 30; /* 30 s */
1889 scc
->kiss
.maxdefer
= 120; /* 2 min */
1890 scc
->kiss
.softdcd
= 0; /* hardware dcd */
1893 scc
->tx_buff
= NULL
;
1894 skb_queue_head_init(&scc
->tx_queue
);
1905 case SIOCSCCRESERVED
:
1906 return -ENOIOCTLCMD
;
1909 if (!capable(CAP_SYS_RAWIO
)) return -EPERM
;
1910 if (!arg
|| copy_from_user(&memcfg
, arg
, sizeof(memcfg
)))
1912 scc
->stat
.bufsize
= memcfg
.bufsize
;
1916 if (!arg
|| copy_to_user(arg
, &scc
->stat
, sizeof(scc
->stat
)))
1921 if (!arg
|| copy_from_user(&kiss_cmd
, arg
, sizeof(kiss_cmd
)))
1923 kiss_cmd
.param
= scc_get_param(scc
, kiss_cmd
.command
);
1924 if (copy_to_user(arg
, &kiss_cmd
, sizeof(kiss_cmd
)))
1929 if (!capable(CAP_NET_ADMIN
)) return -EPERM
;
1930 if (!arg
|| copy_from_user(&kiss_cmd
, arg
, sizeof(kiss_cmd
)))
1932 return scc_set_param(scc
, kiss_cmd
.command
, kiss_cmd
.param
);
1935 if (!capable(CAP_SYS_RAWIO
)) return -EPERM
;
1936 if (!arg
|| copy_from_user(&cal
, arg
, sizeof(cal
)) || cal
.time
== 0)
1939 scc_start_calibrate(scc
, cal
.time
, cal
.pattern
);
1943 return -ENOIOCTLCMD
;
1950 /* ----> set interface callsign <---- */
1952 static int scc_net_set_mac_address(struct net_device
*dev
, void *addr
)
1954 struct sockaddr
*sa
= (struct sockaddr
*) addr
;
1955 dev_addr_set(dev
, sa
->sa_data
);
1959 /* ----> get statistics <---- */
1961 static struct net_device_stats
*scc_net_get_stats(struct net_device
*dev
)
1963 struct scc_channel
*scc
= (struct scc_channel
*) dev
->ml_priv
;
1965 scc
->dev_stat
.rx_errors
= scc
->stat
.rxerrs
+ scc
->stat
.rx_over
;
1966 scc
->dev_stat
.tx_errors
= scc
->stat
.txerrs
+ scc
->stat
.tx_under
;
1967 scc
->dev_stat
.rx_fifo_errors
= scc
->stat
.rx_over
;
1968 scc
->dev_stat
.tx_fifo_errors
= scc
->stat
.tx_under
;
1970 return &scc
->dev_stat
;
1973 /* ******************************************************************** */
1974 /* * dump statistics to /proc/net/z8530drv * */
1975 /* ******************************************************************** */
1977 #ifdef CONFIG_PROC_FS
1979 static inline struct scc_channel
*scc_net_seq_idx(loff_t pos
)
1983 for (k
= 0; k
< Nchips
*2; ++k
) {
1984 if (!SCC_Info
[k
].init
)
1987 return &SCC_Info
[k
];
1992 static void *scc_net_seq_start(struct seq_file
*seq
, loff_t
*pos
)
1994 return *pos
? scc_net_seq_idx(*pos
- 1) : SEQ_START_TOKEN
;
1998 static void *scc_net_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
2001 struct scc_channel
*scc
= v
;
2004 for (k
= (v
== SEQ_START_TOKEN
) ? 0 : (scc
- SCC_Info
)+1;
2005 k
< Nchips
*2; ++k
) {
2006 if (SCC_Info
[k
].init
)
2007 return &SCC_Info
[k
];
2012 static void scc_net_seq_stop(struct seq_file
*seq
, void *v
)
2016 static int scc_net_seq_show(struct seq_file
*seq
, void *v
)
2018 if (v
== SEQ_START_TOKEN
) {
2019 seq_puts(seq
, "z8530drv-"VERSION
"\n");
2020 } else if (!Driver_Initialized
) {
2021 seq_puts(seq
, "not initialized\n");
2022 } else if (!Nchips
) {
2023 seq_puts(seq
, "chips missing\n");
2025 const struct scc_channel
*scc
= v
;
2026 const struct scc_stat
*stat
= &scc
->stat
;
2027 const struct scc_kiss
*kiss
= &scc
->kiss
;
2030 /* dev data ctrl irq clock brand enh vector special option
2031 * baud nrz clocksrc softdcd bufsize
2032 * rxints txints exints spints
2033 * rcvd rxerrs over / xmit txerrs under / nospace bufsize
2034 * txd pers slot tail ful wait min maxk idl defr txof grp
2035 * W ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
2036 * R ## ## XX ## ## ## ## ## XX ## ## ## ## ## ## ##
2039 seq_printf(seq
, "%s\t%3.3lx %3.3lx %d %lu %2.2x %d %3.3lx %3.3lx %d\n",
2041 scc
->data
, scc
->ctrl
, scc
->irq
, scc
->clock
, scc
->brand
,
2042 scc
->enhanced
, Vector_Latch
, scc
->special
,
2044 seq_printf(seq
, "\t%lu %d %d %d %d\n",
2045 scc
->modem
.speed
, scc
->modem
.nrz
,
2046 scc
->modem
.clocksrc
, kiss
->softdcd
,
2048 seq_printf(seq
, "\t%lu %lu %lu %lu\n",
2049 stat
->rxints
, stat
->txints
, stat
->exints
, stat
->spints
);
2050 seq_printf(seq
, "\t%lu %lu %d / %lu %lu %d / %d %d\n",
2051 stat
->rxframes
, stat
->rxerrs
, stat
->rx_over
,
2052 stat
->txframes
, stat
->txerrs
, stat
->tx_under
,
2053 stat
->nospace
, stat
->tx_state
);
2055 #define K(x) kiss->x
2056 seq_printf(seq
, "\t%d %d %d %d %d %d %d %d %d %d %d %d\n",
2057 K(txdelay
), K(persist
), K(slottime
), K(tailtime
),
2058 K(fulldup
), K(waittime
), K(mintime
), K(maxkeyup
),
2059 K(idletime
), K(maxdefer
), K(tx_inhibit
), K(group
));
2065 seq_printf(seq
, "\tW ");
2066 for (reg
= 0; reg
< 16; reg
++)
2067 seq_printf(seq
, "%2.2x ", scc
->wreg
[reg
]);
2068 seq_printf(seq
, "\n");
2070 seq_printf(seq
, "\tR %2.2x %2.2x XX ", InReg(scc
->ctrl
,R0
), InReg(scc
->ctrl
,R1
));
2071 for (reg
= 3; reg
< 8; reg
++)
2072 seq_printf(seq
, "%2.2x ", InReg(scc
->ctrl
, reg
));
2073 seq_printf(seq
, "XX ");
2074 for (reg
= 9; reg
< 16; reg
++)
2075 seq_printf(seq
, "%2.2x ", InReg(scc
->ctrl
, reg
));
2076 seq_printf(seq
, "\n");
2079 seq_putc(seq
, '\n');
2085 static const struct seq_operations scc_net_seq_ops
= {
2086 .start
= scc_net_seq_start
,
2087 .next
= scc_net_seq_next
,
2088 .stop
= scc_net_seq_stop
,
2089 .show
= scc_net_seq_show
,
2091 #endif /* CONFIG_PROC_FS */
2094 /* ******************************************************************** */
2095 /* * Init SCC driver * */
2096 /* ******************************************************************** */
2098 static int __init
scc_init_driver (void)
2100 char devname
[IFNAMSIZ
];
2104 sprintf(devname
,"%s0", SCC_DriverName
);
2107 if (scc_net_alloc(devname
, SCC_Info
)) {
2109 printk(KERN_ERR
"z8530drv: cannot initialize module\n");
2114 proc_create_seq("z8530drv", 0, init_net
.proc_net
, &scc_net_seq_ops
);
2119 static void __exit
scc_cleanup_driver(void)
2121 const unsigned int nr_irqs
= irq_get_nr_irqs();
2124 struct scc_channel
*scc
;
2125 struct net_device
*dev
;
2127 if (Nchips
== 0 && (dev
= SCC_Info
[0].dev
))
2129 unregister_netdev(dev
);
2133 /* Guard against chip prattle */
2134 local_irq_disable();
2136 for (k
= 0; k
< Nchips
; k
++)
2137 if ( (ctrl
= SCC_ctrl
[k
].chan_A
) )
2140 OutReg(ctrl
,R9
,FHWRES
); /* force hardware reset */
2144 /* To unload the port must be closed so no real IRQ pending */
2145 for (k
= 0; k
< nr_irqs
; k
++)
2146 if (Ivec
[k
].used
) free_irq(k
, NULL
);
2151 for (k
= 0; k
< Nchips
*2; k
++)
2156 release_region(scc
->ctrl
, 1);
2157 release_region(scc
->data
, 1);
2161 unregister_netdev(scc
->dev
);
2162 free_netdev(scc
->dev
);
2168 release_region(Vector_Latch
, 1);
2170 remove_proc_entry("z8530drv", init_net
.proc_net
);
2173 MODULE_AUTHOR("Joerg Reuter <jreuter@yaina.de>");
2174 MODULE_DESCRIPTION("AX.25 Device Driver for Z8530 based HDLC cards");
2175 MODULE_LICENSE("GPL");
2176 module_init(scc_init_driver
);
2177 module_exit(scc_cleanup_driver
);