Lines Matching full:scc
1 #define RCS_ID "$Id: scc.c,v 1.75 1998/11/04 15:15:01 jreuter Exp jreuter $"
15 * SCC.C - Linux driver for Z8530 based HDLC cards for AX.25 *
37 ! before you connect a radio to the SCC board and start to transmit or !
41 allowance/licence from the designer of the SCC Board and/or the
169 #include <linux/scc.h>
186 "AX.25: Z8530 SCC driver version "VERSION".dl1bke\n";
202 static void init_channel(struct scc_channel *scc);
203 static void scc_key_trx (struct scc_channel *scc, char tx);
204 static void scc_init_timer(struct scc_channel *scc);
206 static int scc_net_alloc(const char *name, struct scc_channel *scc);
210 static void scc_net_rx(struct scc_channel *scc, struct sk_buff *skb);
217 static unsigned char SCC_DriverName[] = "scc";
276 static inline void wr(struct scc_channel *scc, unsigned char reg, in wr() argument
279 OutReg(scc->ctrl, reg, (scc->wreg[reg] = val)); in wr()
282 static inline void or(struct scc_channel *scc, unsigned char reg, unsigned char val) in or() argument
284 OutReg(scc->ctrl, reg, (scc->wreg[reg] |= val)); in or()
287 static inline void cl(struct scc_channel *scc, unsigned char reg, unsigned char val) in cl() argument
289 OutReg(scc->ctrl, reg, (scc->wreg[reg] &= ~val)); in cl()
296 static inline void scc_discard_buffers(struct scc_channel *scc) in scc_discard_buffers() argument
300 spin_lock_irqsave(&scc->lock, flags); in scc_discard_buffers()
301 if (scc->tx_buff != NULL) in scc_discard_buffers()
303 dev_kfree_skb_irq(scc->tx_buff); in scc_discard_buffers()
304 scc->tx_buff = NULL; in scc_discard_buffers()
307 while (!skb_queue_empty(&scc->tx_queue)) in scc_discard_buffers()
308 dev_kfree_skb_irq(skb_dequeue(&scc->tx_queue)); in scc_discard_buffers()
310 spin_unlock_irqrestore(&scc->lock, flags); in scc_discard_buffers()
322 static inline void scc_notify(struct scc_channel *scc, int event) in scc_notify() argument
327 if (scc->kiss.fulldup != KISS_DUPLEX_OPTIMA) in scc_notify()
336 scc_net_rx(scc, skb); in scc_notify()
338 scc->stat.nospace++; in scc_notify()
341 static inline void flush_rx_FIFO(struct scc_channel *scc) in flush_rx_FIFO() argument
346 Inb(scc->data); in flush_rx_FIFO()
348 if(scc->rx_buff != NULL) /* did we receive something? */ in flush_rx_FIFO()
350 scc->stat.rxerrs++; /* then count it as an error */ in flush_rx_FIFO()
351 dev_kfree_skb_irq(scc->rx_buff); in flush_rx_FIFO()
352 scc->rx_buff = NULL; in flush_rx_FIFO()
356 static void start_hunt(struct scc_channel *scc) in start_hunt() argument
358 if ((scc->modem.clocksrc != CLK_EXTERNAL)) in start_hunt()
359 OutReg(scc->ctrl,R14,SEARCH|scc->wreg[R14]); /* DPLL: enter search mode */ in start_hunt()
360 or(scc,R3,ENT_HM|RxENABLE); /* enable the receiver, hunt mode */ in start_hunt()
367 static inline void scc_txint(struct scc_channel *scc) in scc_txint() argument
371 scc->stat.txints++; in scc_txint()
372 skb = scc->tx_buff; in scc_txint()
378 skb = skb_dequeue(&scc->tx_queue); in scc_txint()
379 scc->tx_buff = skb; in scc_txint()
380 netif_wake_queue(scc->dev); in scc_txint()
384 scc_tx_done(scc); in scc_txint()
385 Outb(scc->ctrl, RES_Tx_P); in scc_txint()
392 scc->tx_buff = NULL; in scc_txint()
393 scc_tx_done(scc); in scc_txint()
394 Outb(scc->ctrl, RES_Tx_P); in scc_txint()
398 scc->stat.tx_state = TXS_ACTIVE; in scc_txint()
400 OutReg(scc->ctrl, R0, RES_Tx_CRC); in scc_txint()
402 or(scc,R10,ABUNDER); /* re-install underrun protection */ in scc_txint()
403 Outb(scc->data,*skb->data); /* send byte */ in scc_txint()
406 if (!scc->enhanced) /* reset EOM latch */ in scc_txint()
407 Outb(scc->ctrl,RES_EOM_L); in scc_txint()
415 Outb(scc->ctrl, RES_Tx_P); /* reset pending int */ in scc_txint()
416 cl(scc, R10, ABUNDER); /* send CRC */ in scc_txint()
418 scc->tx_buff = NULL; in scc_txint()
419 scc->stat.tx_state = TXS_NEWFRAME; /* next frame... */ in scc_txint()
425 Outb(scc->data,*skb->data); in scc_txint()
431 static inline void scc_exint(struct scc_channel *scc) in scc_exint() argument
435 scc->stat.exints++; in scc_exint()
437 status = InReg(scc->ctrl,R0); in scc_exint()
438 changes = status ^ scc->status; in scc_exint()
444 flush_rx_FIFO(scc); in scc_exint()
448 if ((changes & SYNC_HUNT) && scc->kiss.softdcd) in scc_exint()
452 scc->dcd = 0; in scc_exint()
453 flush_rx_FIFO(scc); in scc_exint()
454 if ((scc->modem.clocksrc != CLK_EXTERNAL)) in scc_exint()
455 OutReg(scc->ctrl,R14,SEARCH|scc->wreg[R14]); /* DPLL: enter search mode */ in scc_exint()
457 scc->dcd = 1; in scc_exint()
460 scc_notify(scc, scc->dcd? HWEV_DCD_OFF:HWEV_DCD_ON); in scc_exint()
466 if((changes & DCD) && !scc->kiss.softdcd) /* DCD input changed state */ in scc_exint()
470 start_hunt(scc); in scc_exint()
471 scc->dcd = 1; in scc_exint()
473 cl(scc,R3,ENT_HM|RxENABLE); /* disable the receiver */ in scc_exint()
474 flush_rx_FIFO(scc); in scc_exint()
475 scc->dcd = 0; in scc_exint()
478 scc_notify(scc, scc->dcd? HWEV_DCD_ON:HWEV_DCD_OFF); in scc_exint()
490 if (scc->kiss.txdelay == 0) /* zero TXDELAY = wait for CTS */ in scc_exint()
491 scc_start_tx_timer(scc, t_txdelay, 0); in scc_exint()
495 if (scc->stat.tx_state == TXS_ACTIVE && (status & TxEOM)) in scc_exint()
497 scc->stat.tx_under++; /* oops, an underrun! count 'em */ in scc_exint()
498 Outb(scc->ctrl, RES_EXT_INT); /* reset ext/status interrupts */ in scc_exint()
500 if (scc->tx_buff != NULL) in scc_exint()
502 dev_kfree_skb_irq(scc->tx_buff); in scc_exint()
503 scc->tx_buff = NULL; in scc_exint()
506 or(scc,R10,ABUNDER); in scc_exint()
507 scc_start_tx_timer(scc, t_txdelay, 0); /* restart transmission */ in scc_exint()
510 scc->status = status; in scc_exint()
511 Outb(scc->ctrl,RES_EXT_INT); in scc_exint()
516 static inline void scc_rxint(struct scc_channel *scc) in scc_rxint() argument
520 scc->stat.rxints++; in scc_rxint()
522 if((scc->wreg[5] & RTS) && scc->kiss.fulldup == KISS_DUPLEX_HALF) in scc_rxint()
524 Inb(scc->data); /* discard char */ in scc_rxint()
525 or(scc,R3,ENT_HM); /* enter hunt mode for next flag */ in scc_rxint()
529 skb = scc->rx_buff; in scc_rxint()
533 skb = dev_alloc_skb(scc->stat.bufsize); in scc_rxint()
536 scc->dev_stat.rx_dropped++; in scc_rxint()
537 scc->stat.nospace++; in scc_rxint()
538 Inb(scc->data); in scc_rxint()
539 or(scc, R3, ENT_HM); in scc_rxint()
543 scc->rx_buff = skb; in scc_rxint()
547 if (skb->len >= scc->stat.bufsize) in scc_rxint()
553 scc->rx_buff = NULL; in scc_rxint()
554 Inb(scc->data); in scc_rxint()
555 or(scc, R3, ENT_HM); in scc_rxint()
559 skb_put_u8(skb, Inb(scc->data)); in scc_rxint()
564 static inline void scc_spint(struct scc_channel *scc) in scc_spint() argument
569 scc->stat.spints++; in scc_spint()
571 status = InReg(scc->ctrl,R1); /* read receiver status */ in scc_spint()
573 Inb(scc->data); /* throw away Rx byte */ in scc_spint()
574 skb = scc->rx_buff; in scc_spint()
578 scc->stat.rx_over++; /* count them */ in scc_spint()
579 or(scc,R3,ENT_HM); /* enter hunt mode for next flag */ in scc_spint()
583 scc->rx_buff = skb = NULL; in scc_spint()
594 scc_net_rx(scc, skb); in scc_spint()
595 scc->rx_buff = NULL; in scc_spint()
596 scc->stat.rxframes++; in scc_spint()
599 scc->rx_buff = NULL; in scc_spint()
600 scc->stat.rxerrs++; in scc_spint()
604 Outb(scc->ctrl,ERR_RES); in scc_spint()
610 static void scc_isr_dispatch(struct scc_channel *scc, int vector) in scc_isr_dispatch() argument
612 spin_lock(&scc->lock); in scc_isr_dispatch()
615 case TXINT: scc_txint(scc); break; in scc_isr_dispatch()
616 case EXINT: scc_exint(scc); break; in scc_isr_dispatch()
617 case RXINT: scc_rxint(scc); break; in scc_isr_dispatch()
618 case SPINT: scc_spint(scc); break; in scc_isr_dispatch()
620 spin_unlock(&scc->lock); in scc_isr_dispatch()
634 struct scc_channel *scc; in scc_isr() local
648 scc=&SCC_Info[vector >> 3 ^ 0x01]; in scc_isr()
649 if (!scc->dev) break; in scc_isr()
651 scc_isr_dispatch(scc, vector); in scc_isr()
653 OutReg(scc->ctrl,R0,RES_H_IUS); /* Reset Highest IUS */ in scc_isr()
662 /* Find the SCC generating the interrupt by polling all attached SCCs in scc_isr()
675 scc = NULL; in scc_isr()
681 scc = &SCC_Info[vector >> 3 ^ 0x01]; in scc_isr()
682 if (!scc->dev) break; in scc_isr()
684 scc_isr_dispatch(scc, vector); in scc_isr()
700 if (scc != NULL) in scc_isr()
702 OutReg(scc->ctrl,R0,RES_H_IUS); in scc_isr()
717 /* ----> set SCC channel speed <---- */
719 static inline void set_brg(struct scc_channel *scc, unsigned int tc) in set_brg() argument
721 cl(scc,R14,BRENABL); /* disable baudrate generator */ in set_brg()
722 wr(scc,R12,tc & 255); /* brg rate LOW */ in set_brg()
723 wr(scc,R13,tc >> 8); /* brg rate HIGH */ in set_brg()
724 or(scc,R14,BRENABL); /* enable baudrate generator */ in set_brg()
727 static inline void set_speed(struct scc_channel *scc) in set_speed() argument
730 spin_lock_irqsave(&scc->lock, flags); in set_speed()
732 if (scc->modem.speed > 0) /* paranoia... */ in set_speed()
733 set_brg(scc, (unsigned) (scc->clock / (scc->modem.speed * 64)) - 2); in set_speed()
735 spin_unlock_irqrestore(&scc->lock, flags); in set_speed()
739 /* ----> initialize a SCC channel <---- */
741 static inline void init_brg(struct scc_channel *scc) in init_brg() argument
743 wr(scc, R14, BRSRC); /* BRG source = PCLK */ in init_brg()
744 OutReg(scc->ctrl, R14, SSBR|scc->wreg[R14]); /* DPLL source = BRG */ in init_brg()
745 OutReg(scc->ctrl, R14, SNRZI|scc->wreg[R14]); /* DPLL NRZI mode */ in init_brg()
793 static void init_channel(struct scc_channel *scc) in init_channel() argument
795 del_timer(&scc->tx_t); in init_channel()
796 del_timer(&scc->tx_wdog); in init_channel()
798 disable_irq(scc->irq); in init_channel()
800 wr(scc,R4,X1CLK|SDLC); /* *1 clock, SDLC mode */ in init_channel()
801 wr(scc,R1,0); /* no W/REQ operation */ in init_channel()
802 wr(scc,R3,Rx8|RxCRC_ENAB); /* RX 8 bits/char, CRC, disabled */ in init_channel()
803 wr(scc,R5,Tx8|DTR|TxCRC_ENAB); /* TX 8 bits/char, disabled, DTR */ in init_channel()
804 wr(scc,R6,0); /* SDLC address zero (not used) */ in init_channel()
805 wr(scc,R7,FLAG); /* SDLC flag value */ in init_channel()
806 wr(scc,R9,VIS); /* vector includes status */ in init_channel()
807 …wr(scc,R10,(scc->modem.nrz? NRZ : NRZI)|CRCPS|ABUNDER); /* abort on underrun, preset CRC generator… in init_channel()
808 wr(scc,R14, 0); in init_channel()
837 switch(scc->modem.clocksrc) in init_channel()
840 wr(scc, R11, RCDPLL|TCDPLL|TRxCOI|TRxCDP); in init_channel()
841 init_brg(scc); in init_channel()
845 wr(scc, R11, ((scc->brand & BAYCOM)? TRxCDP : TRxCBR) | RCDPLL|TCRTxCP|TRxCOI); in init_channel()
846 init_brg(scc); in init_channel()
850 wr(scc, R11, (scc->brand & BAYCOM)? RCTRxCP|TCRTxCP : RCRTxCP|TCTRxCP); in init_channel()
851 OutReg(scc->ctrl, R14, DISDPLL); in init_channel()
856 set_speed(scc); /* set baudrate */ in init_channel()
858 if(scc->enhanced) in init_channel()
860 or(scc,R15,SHDLCE|FIFOE); /* enable FIFO, SDLC/HDLC Enhancements (From now R7 is R7') */ in init_channel()
861 wr(scc,R7,AUTOEOM); in init_channel()
864 if(scc->kiss.softdcd || (InReg(scc->ctrl,R0) & DCD)) in init_channel()
867 start_hunt(scc); in init_channel()
872 wr(scc,R15, BRKIE|TxUIE|(scc->kiss.softdcd? SYNCIE:DCDIE)); in init_channel()
874 Outb(scc->ctrl,RES_EXT_INT); /* reset ext/status interrupts */ in init_channel()
875 Outb(scc->ctrl,RES_EXT_INT); /* must be done twice */ in init_channel()
877 or(scc,R1,INT_ALL_Rx|TxINT_ENAB|EXT_INT_ENAB); /* enable interrupts */ in init_channel()
879 scc->status = InReg(scc->ctrl,R0); /* read initial status */ in init_channel()
881 or(scc,R9,MIE); /* master interrupt enable */ in init_channel()
883 scc_init_timer(scc); in init_channel()
885 enable_irq(scc->irq); in init_channel()
892 /* * SCC timer functions * */
899 static void scc_key_trx(struct scc_channel *scc, char tx) in scc_key_trx() argument
903 if (scc->brand & PRIMUS) in scc_key_trx()
904 Outb(scc->ctrl + 4, scc->option | (tx? 0x80 : 0)); in scc_key_trx()
906 if (scc->modem.speed < 300) in scc_key_trx()
907 scc->modem.speed = 1200; in scc_key_trx()
909 time_const = (unsigned) (scc->clock / (scc->modem.speed * (tx? 2:64))) - 2; in scc_key_trx()
911 disable_irq(scc->irq); in scc_key_trx()
915 or(scc, R1, TxINT_ENAB); /* t_maxkeyup may have reset these */ in scc_key_trx()
916 or(scc, R15, TxUIE); in scc_key_trx()
919 if (scc->modem.clocksrc == CLK_DPLL) in scc_key_trx()
924 cl(scc, R3, RxENABLE|ENT_HM); /* switch off receiver */ in scc_key_trx()
925 cl(scc, R15, DCDIE|SYNCIE); /* No DCD changes, please */ in scc_key_trx()
927 set_brg(scc, time_const); /* reprogram baudrate generator */ in scc_key_trx()
930 wr(scc, R11, RCDPLL|TCBR|TRxCOI|TRxCBR); in scc_key_trx()
933 if (scc->kiss.tx_inhibit) in scc_key_trx()
935 or(scc,R5, TxENAB); in scc_key_trx()
936 scc->wreg[R5] |= RTS; in scc_key_trx()
938 or(scc,R5,RTS|TxENAB); /* set the RTS line and enable TX */ in scc_key_trx()
941 cl(scc,R5,RTS|TxENAB); in scc_key_trx()
943 set_brg(scc, time_const); /* reprogram baudrate generator */ in scc_key_trx()
946 wr(scc, R11, RCDPLL|TCDPLL|TRxCOI|TRxCDP); in scc_key_trx()
949 if (scc->kiss.softdcd) in scc_key_trx()
952 or(scc,R15, scc->kiss.softdcd? SYNCIE:DCDIE); in scc_key_trx()
953 start_hunt(scc); in scc_key_trx()
960 if (scc->kiss.fulldup == KISS_DUPLEX_HALF) in scc_key_trx()
962 cl(scc, R3, RxENABLE); in scc_key_trx()
963 cl(scc, R15, DCDIE|SYNCIE); in scc_key_trx()
967 if (scc->kiss.tx_inhibit) in scc_key_trx()
969 or(scc,R5, TxENAB); in scc_key_trx()
970 scc->wreg[R5] |= RTS; in scc_key_trx()
972 or(scc,R5,RTS|TxENAB); /* enable tx */ in scc_key_trx()
975 cl(scc,R5,RTS|TxENAB); /* disable tx */ in scc_key_trx()
977 if ((scc->kiss.fulldup == KISS_DUPLEX_HALF) && in scc_key_trx()
979 scc->kiss.softdcd) in scc_key_trx()
984 or(scc, R15, scc->kiss.softdcd? SYNCIE:DCDIE); in scc_key_trx()
985 start_hunt(scc); in scc_key_trx()
990 enable_irq(scc->irq); in scc_key_trx()
994 /* ----> SCC timer interrupt handler and friends. <---- */
996 static void __scc_start_tx_timer(struct scc_channel *scc, in __scc_start_tx_timer() argument
1000 del_timer(&scc->tx_t); in __scc_start_tx_timer()
1004 handler(&scc->tx_t); in __scc_start_tx_timer()
1008 scc->tx_t.function = handler; in __scc_start_tx_timer()
1009 scc->tx_t.expires = jiffies + (when*HZ)/100; in __scc_start_tx_timer()
1010 add_timer(&scc->tx_t); in __scc_start_tx_timer()
1014 static void scc_start_tx_timer(struct scc_channel *scc, in scc_start_tx_timer() argument
1020 spin_lock_irqsave(&scc->lock, flags); in scc_start_tx_timer()
1021 __scc_start_tx_timer(scc, handler, when); in scc_start_tx_timer()
1022 spin_unlock_irqrestore(&scc->lock, flags); in scc_start_tx_timer()
1025 static void scc_start_defer(struct scc_channel *scc) in scc_start_defer() argument
1029 spin_lock_irqsave(&scc->lock, flags); in scc_start_defer()
1030 del_timer(&scc->tx_wdog); in scc_start_defer()
1032 if (scc->kiss.maxdefer != 0 && scc->kiss.maxdefer != TIMER_OFF) in scc_start_defer()
1034 scc->tx_wdog.function = t_busy; in scc_start_defer()
1035 scc->tx_wdog.expires = jiffies + HZ*scc->kiss.maxdefer; in scc_start_defer()
1036 add_timer(&scc->tx_wdog); in scc_start_defer()
1038 spin_unlock_irqrestore(&scc->lock, flags); in scc_start_defer()
1041 static void scc_start_maxkeyup(struct scc_channel *scc) in scc_start_maxkeyup() argument
1045 spin_lock_irqsave(&scc->lock, flags); in scc_start_maxkeyup()
1046 del_timer(&scc->tx_wdog); in scc_start_maxkeyup()
1048 if (scc->kiss.maxkeyup != 0 && scc->kiss.maxkeyup != TIMER_OFF) in scc_start_maxkeyup()
1050 scc->tx_wdog.function = t_maxkeyup; in scc_start_maxkeyup()
1051 scc->tx_wdog.expires = jiffies + HZ*scc->kiss.maxkeyup; in scc_start_maxkeyup()
1052 add_timer(&scc->tx_wdog); in scc_start_maxkeyup()
1054 spin_unlock_irqrestore(&scc->lock, flags); in scc_start_maxkeyup()
1062 static void scc_tx_done(struct scc_channel *scc) in scc_tx_done() argument
1068 switch (scc->kiss.fulldup) in scc_tx_done()
1071 scc->stat.tx_state = TXS_IDLE2; in scc_tx_done()
1072 if (scc->kiss.idletime != TIMER_OFF) in scc_tx_done()
1073 scc_start_tx_timer(scc, t_idle, in scc_tx_done()
1074 scc->kiss.idletime*100); in scc_tx_done()
1077 scc_notify(scc, HWEV_ALL_SENT); in scc_tx_done()
1080 scc->stat.tx_state = TXS_BUSY; in scc_tx_done()
1081 scc_start_tx_timer(scc, t_tail, scc->kiss.tailtime); in scc_tx_done()
1084 netif_wake_queue(scc->dev); in scc_tx_done()
1090 static inline int is_grouped(struct scc_channel *scc) in is_grouped() argument
1096 grp1 = scc->kiss.group; in is_grouped()
1103 if (scc2 == scc || !(scc2->dev && grp2)) in is_grouped()
1128 struct scc_channel *scc = from_timer(scc, t, tx_t); in t_dwait() local
1130 if (scc->stat.tx_state == TXS_WAIT) /* maxkeyup or idle timeout */ in t_dwait()
1132 if (skb_queue_empty(&scc->tx_queue)) { /* nothing to send */ in t_dwait()
1133 scc->stat.tx_state = TXS_IDLE; in t_dwait()
1134 netif_wake_queue(scc->dev); /* t_maxkeyup locked it. */ in t_dwait()
1138 scc->stat.tx_state = TXS_BUSY; in t_dwait()
1141 if (scc->kiss.fulldup == KISS_DUPLEX_HALF) in t_dwait()
1145 if (scc->dcd || (scc->kiss.persist) < Rand || (scc->kiss.group && is_grouped(scc)) ) in t_dwait()
1147 scc_start_defer(scc); in t_dwait()
1148 scc_start_tx_timer(scc, t_dwait, scc->kiss.slottime); in t_dwait()
1153 if ( !(scc->wreg[R5] & RTS) ) in t_dwait()
1155 scc_key_trx(scc, TX_ON); in t_dwait()
1156 scc_start_tx_timer(scc, t_txdelay, scc->kiss.txdelay); in t_dwait()
1158 scc_start_tx_timer(scc, t_txdelay, 0); in t_dwait()
1165 * kick transmission by a fake scc_txint(scc), start 'maxkeyup' watchdog.
1170 struct scc_channel *scc = from_timer(scc, t, tx_t); in t_txdelay() local
1172 scc_start_maxkeyup(scc); in t_txdelay()
1174 if (scc->tx_buff == NULL) in t_txdelay()
1176 disable_irq(scc->irq); in t_txdelay()
1177 scc_txint(scc); in t_txdelay()
1178 enable_irq(scc->irq); in t_txdelay()
1191 struct scc_channel *scc = from_timer(scc, t, tx_t); in t_tail() local
1194 spin_lock_irqsave(&scc->lock, flags); in t_tail()
1195 del_timer(&scc->tx_wdog); in t_tail()
1196 scc_key_trx(scc, TX_OFF); in t_tail()
1197 spin_unlock_irqrestore(&scc->lock, flags); in t_tail()
1199 if (scc->stat.tx_state == TXS_TIMEOUT) /* we had a timeout? */ in t_tail()
1201 scc->stat.tx_state = TXS_WAIT; in t_tail()
1202 scc_start_tx_timer(scc, t_dwait, scc->kiss.mintime*100); in t_tail()
1206 scc->stat.tx_state = TXS_IDLE; in t_tail()
1207 netif_wake_queue(scc->dev); in t_tail()
1218 struct scc_channel *scc = from_timer(scc, t, tx_wdog); in t_busy() local
1220 del_timer(&scc->tx_t); in t_busy()
1221 netif_stop_queue(scc->dev); /* don't pile on the wabbit! */ in t_busy()
1223 scc_discard_buffers(scc); in t_busy()
1224 scc->stat.txerrs++; in t_busy()
1225 scc->stat.tx_state = TXS_IDLE; in t_busy()
1227 netif_wake_queue(scc->dev); in t_busy()
1237 struct scc_channel *scc = from_timer(scc, t, tx_wdog); in t_maxkeyup() local
1240 spin_lock_irqsave(&scc->lock, flags); in t_maxkeyup()
1246 netif_stop_queue(scc->dev); in t_maxkeyup()
1247 scc_discard_buffers(scc); in t_maxkeyup()
1249 del_timer(&scc->tx_t); in t_maxkeyup()
1251 cl(scc, R1, TxINT_ENAB); /* force an ABORT, but don't */ in t_maxkeyup()
1252 cl(scc, R15, TxUIE); /* count it. */ in t_maxkeyup()
1253 OutReg(scc->ctrl, R0, RES_Tx_P); in t_maxkeyup()
1255 spin_unlock_irqrestore(&scc->lock, flags); in t_maxkeyup()
1257 scc->stat.txerrs++; in t_maxkeyup()
1258 scc->stat.tx_state = TXS_TIMEOUT; in t_maxkeyup()
1259 scc_start_tx_timer(scc, t_tail, scc->kiss.tailtime); in t_maxkeyup()
1271 struct scc_channel *scc = from_timer(scc, t, tx_t); in t_idle() local
1273 del_timer(&scc->tx_wdog); in t_idle()
1275 scc_key_trx(scc, TX_OFF); in t_idle()
1276 if(scc->kiss.mintime) in t_idle()
1277 scc_start_tx_timer(scc, t_dwait, scc->kiss.mintime*100); in t_idle()
1278 scc->stat.tx_state = TXS_WAIT; in t_idle()
1281 static void scc_init_timer(struct scc_channel *scc) in scc_init_timer() argument
1285 spin_lock_irqsave(&scc->lock, flags); in scc_init_timer()
1286 scc->stat.tx_state = TXS_IDLE; in scc_init_timer()
1287 spin_unlock_irqrestore(&scc->lock, flags); in scc_init_timer()
1302 static unsigned int scc_set_param(struct scc_channel *scc, unsigned int cmd, unsigned int arg) in scc_set_param() argument
1306 case PARAM_TXDELAY: scc->kiss.txdelay=arg; break; in scc_set_param()
1307 case PARAM_PERSIST: scc->kiss.persist=arg; break; in scc_set_param()
1308 case PARAM_SLOTTIME: scc->kiss.slottime=arg; break; in scc_set_param()
1309 case PARAM_TXTAIL: scc->kiss.tailtime=arg; break; in scc_set_param()
1310 case PARAM_FULLDUP: scc->kiss.fulldup=arg; break; in scc_set_param()
1312 case PARAM_GROUP: scc->kiss.group=arg; break; in scc_set_param()
1313 case PARAM_IDLE: scc->kiss.idletime=arg; break; in scc_set_param()
1314 case PARAM_MIN: scc->kiss.mintime=arg; break; in scc_set_param()
1315 case PARAM_MAXKEY: scc->kiss.maxkeyup=arg; break; in scc_set_param()
1316 case PARAM_WAIT: scc->kiss.waittime=arg; break; in scc_set_param()
1317 case PARAM_MAXDEFER: scc->kiss.maxdefer=arg; break; in scc_set_param()
1318 case PARAM_TX: scc->kiss.tx_inhibit=arg; break; in scc_set_param()
1321 scc->kiss.softdcd=arg; in scc_set_param()
1324 or(scc, R15, SYNCIE); in scc_set_param()
1325 cl(scc, R15, DCDIE); in scc_set_param()
1326 start_hunt(scc); in scc_set_param()
1328 or(scc, R15, DCDIE); in scc_set_param()
1329 cl(scc, R15, SYNCIE); in scc_set_param()
1335 scc->modem.speed=arg*100; in scc_set_param()
1337 scc->modem.speed=arg; in scc_set_param()
1339 if (scc->stat.tx_state == 0) /* only switch baudrate on rx... ;-) */ in scc_set_param()
1340 set_speed(scc); in scc_set_param()
1344 if ( !(scc->wreg[R5] & RTS) ) in scc_set_param()
1347 scc_key_trx(scc, TX_ON); in scc_set_param()
1348 scc_start_tx_timer(scc, t_txdelay, scc->kiss.txdelay); in scc_set_param()
1353 scc->stat.tx_state = TXS_BUSY; in scc_set_param()
1354 scc_start_tx_timer(scc, t_tail, scc->kiss.tailtime); in scc_set_param()
1360 scc_notify(scc, scc->dcd? HWEV_DCD_ON:HWEV_DCD_OFF); in scc_set_param()
1371 static unsigned long scc_get_param(struct scc_channel *scc, unsigned int cmd) in scc_get_param() argument
1375 case PARAM_TXDELAY: return CAST(scc->kiss.txdelay); in scc_get_param()
1376 case PARAM_PERSIST: return CAST(scc->kiss.persist); in scc_get_param()
1377 case PARAM_SLOTTIME: return CAST(scc->kiss.slottime); in scc_get_param()
1378 case PARAM_TXTAIL: return CAST(scc->kiss.tailtime); in scc_get_param()
1379 case PARAM_FULLDUP: return CAST(scc->kiss.fulldup); in scc_get_param()
1380 case PARAM_SOFTDCD: return CAST(scc->kiss.softdcd); in scc_get_param()
1381 case PARAM_DTR: return CAST((scc->wreg[R5] & DTR)? 1:0); in scc_get_param()
1382 case PARAM_RTS: return CAST((scc->wreg[R5] & RTS)? 1:0); in scc_get_param()
1383 case PARAM_SPEED: return CAST(scc->modem.speed); in scc_get_param()
1384 case PARAM_GROUP: return CAST(scc->kiss.group); in scc_get_param()
1385 case PARAM_IDLE: return CAST(scc->kiss.idletime); in scc_get_param()
1386 case PARAM_MIN: return CAST(scc->kiss.mintime); in scc_get_param()
1387 case PARAM_MAXKEY: return CAST(scc->kiss.maxkeyup); in scc_get_param()
1388 case PARAM_WAIT: return CAST(scc->kiss.waittime); in scc_get_param()
1389 case PARAM_MAXDEFER: return CAST(scc->kiss.maxdefer); in scc_get_param()
1390 case PARAM_TX: return CAST(scc->kiss.tx_inhibit); in scc_get_param()
1404 struct scc_channel *scc = from_timer(scc, t, tx_wdog); in scc_stop_calibrate() local
1407 spin_lock_irqsave(&scc->lock, flags); in scc_stop_calibrate()
1408 del_timer(&scc->tx_wdog); in scc_stop_calibrate()
1409 scc_key_trx(scc, TX_OFF); in scc_stop_calibrate()
1410 wr(scc, R6, 0); in scc_stop_calibrate()
1411 wr(scc, R7, FLAG); in scc_stop_calibrate()
1412 Outb(scc->ctrl,RES_EXT_INT); /* reset ext/status interrupts */ in scc_stop_calibrate()
1413 Outb(scc->ctrl,RES_EXT_INT); in scc_stop_calibrate()
1415 netif_wake_queue(scc->dev); in scc_stop_calibrate()
1416 spin_unlock_irqrestore(&scc->lock, flags); in scc_stop_calibrate()
1421 scc_start_calibrate(struct scc_channel *scc, int duration, unsigned char pattern) in scc_start_calibrate() argument
1425 spin_lock_irqsave(&scc->lock, flags); in scc_start_calibrate()
1426 netif_stop_queue(scc->dev); in scc_start_calibrate()
1427 scc_discard_buffers(scc); in scc_start_calibrate()
1429 del_timer(&scc->tx_wdog); in scc_start_calibrate()
1431 scc->tx_wdog.function = scc_stop_calibrate; in scc_start_calibrate()
1432 scc->tx_wdog.expires = jiffies + HZ*duration; in scc_start_calibrate()
1433 add_timer(&scc->tx_wdog); in scc_start_calibrate()
1436 wr(scc, R6, 0); in scc_start_calibrate()
1437 wr(scc, R7, pattern); in scc_start_calibrate()
1444 Outb(scc->ctrl,RES_EXT_INT); /* reset ext/status interrupts */ in scc_start_calibrate()
1445 Outb(scc->ctrl,RES_EXT_INT); in scc_start_calibrate()
1447 scc_key_trx(scc, TX_ON); in scc_start_calibrate()
1448 spin_unlock_irqrestore(&scc->lock, flags); in scc_start_calibrate()
1461 struct scc_channel *scc; in z8530_init() local
1482 scc=&SCC_Info[2*chip]; in z8530_init()
1483 if (!scc->ctrl) continue; in z8530_init()
1485 /* Special SCC cards */ in z8530_init()
1487 if(scc->brand & EAGLE) /* this is an EAGLE card */ in z8530_init()
1488 Outb(scc->special,0x08); /* enable interrupt on the board */ in z8530_init()
1490 if(scc->brand & (PC100 | PRIMUS)) /* this is a PC100/PRIMUS card */ in z8530_init()
1491 Outb(scc->special,scc->option); /* set the MODEM mode (0x22) */ in z8530_init()
1496 spin_lock_irqsave(&scc->lock, flags); in z8530_init()
1498 Outb(scc->ctrl, 0); in z8530_init()
1499 OutReg(scc->ctrl,R9,FHWRES); /* force hardware reset */ in z8530_init()
1501 wr(scc, R2, chip*16); /* interrupt vector */ in z8530_init()
1502 wr(scc, R9, VIS); /* vector includes status */ in z8530_init()
1503 spin_unlock_irqrestore(&scc->lock, flags); in z8530_init()
1514 static int scc_net_alloc(const char *name, struct scc_channel *scc) in scc_net_alloc() argument
1523 dev->ml_priv = scc; in scc_net_alloc()
1524 scc->dev = dev; in scc_net_alloc()
1525 spin_lock_init(&scc->lock); in scc_net_alloc()
1526 timer_setup(&scc->tx_t, NULL, 0); in scc_net_alloc()
1527 timer_setup(&scc->tx_wdog, NULL, 0); in scc_net_alloc()
1534 scc->dev = NULL; in scc_net_alloc()
1581 struct scc_channel *scc = (struct scc_channel *) dev->ml_priv; in scc_net_open() local
1583 if (!scc->init) in scc_net_open()
1586 scc->tx_buff = NULL; in scc_net_open()
1587 skb_queue_head_init(&scc->tx_queue); in scc_net_open()
1589 init_channel(scc); in scc_net_open()
1599 struct scc_channel *scc = (struct scc_channel *) dev->ml_priv; in scc_net_close() local
1604 spin_lock_irqsave(&scc->lock, flags); in scc_net_close()
1605 Outb(scc->ctrl,0); /* Make sure pointer is written */ in scc_net_close()
1606 wr(scc,R1,0); /* disable interrupts */ in scc_net_close()
1607 wr(scc,R3,0); in scc_net_close()
1608 spin_unlock_irqrestore(&scc->lock, flags); in scc_net_close()
1610 del_timer_sync(&scc->tx_t); in scc_net_close()
1611 del_timer_sync(&scc->tx_wdog); in scc_net_close()
1613 scc_discard_buffers(scc); in scc_net_close()
1620 static void scc_net_rx(struct scc_channel *scc, struct sk_buff *skb) in scc_net_rx() argument
1627 scc->dev_stat.rx_packets++; in scc_net_rx()
1628 scc->dev_stat.rx_bytes += skb->len; in scc_net_rx()
1630 skb->protocol = ax25_type_trans(skb, scc->dev); in scc_net_rx()
1639 struct scc_channel *scc = (struct scc_channel *) dev->ml_priv; in scc_net_tx() local
1646 if (skb->len > scc->stat.bufsize || skb->len < 2) { in scc_net_tx()
1647 scc->dev_stat.tx_dropped++; /* bogus frame */ in scc_net_tx()
1652 scc->dev_stat.tx_packets++; in scc_net_tx()
1653 scc->dev_stat.tx_bytes += skb->len; in scc_net_tx()
1654 scc->stat.txframes++; in scc_net_tx()
1660 scc_set_param(scc, kisscmd, *skb->data); in scc_net_tx()
1665 spin_lock_irqsave(&scc->lock, flags); in scc_net_tx()
1667 if (skb_queue_len(&scc->tx_queue) > scc->dev->tx_queue_len) { in scc_net_tx()
1669 skb_del = skb_dequeue(&scc->tx_queue); in scc_net_tx()
1672 skb_queue_tail(&scc->tx_queue, skb); in scc_net_tx()
1682 if(scc->stat.tx_state == TXS_IDLE || scc->stat.tx_state == TXS_IDLE2) { in scc_net_tx()
1683 scc->stat.tx_state = TXS_BUSY; in scc_net_tx()
1684 if (scc->kiss.fulldup == KISS_DUPLEX_HALF) in scc_net_tx()
1685 __scc_start_tx_timer(scc, t_dwait, scc->kiss.waittime); in scc_net_tx()
1687 __scc_start_tx_timer(scc, t_dwait, 0); in scc_net_tx()
1689 spin_unlock_irqrestore(&scc->lock, flags); in scc_net_tx()
1712 struct scc_channel *scc = (struct scc_channel *) dev->ml_priv; in scc_net_ioctl() local
1741 0, "AX.25 SCC", in scc_net_ioctl()
1749 if (!request_region(hwcfg.vector_latch, 1, "scc vector latch")) in scc_net_ioctl()
1760 if(request_region(hwcfg.ctrl_a, 1, "scc-probe")) in scc_net_ioctl()
1819 request_region(SCC_Info[2*Nchips+chan].ctrl, 1, "scc ctrl"); in scc_net_ioctl()
1820 request_region(SCC_Info[2*Nchips+chan].data, 1, "scc data"); in scc_net_ioctl()
1848 if (!scc->init) in scc_net_ioctl()
1855 scc->stat.bufsize = SCC_BUFSIZE; in scc_net_ioctl()
1857 if (copy_from_user(&scc->modem, arg, sizeof(struct scc_modem))) in scc_net_ioctl()
1862 if (scc->modem.speed < 4800) in scc_net_ioctl()
1864 scc->kiss.txdelay = 36; /* 360 ms */ in scc_net_ioctl()
1865 scc->kiss.persist = 42; /* 25% persistence */ /* was 25 */ in scc_net_ioctl()
1866 scc->kiss.slottime = 16; /* 160 ms */ in scc_net_ioctl()
1867 scc->kiss.tailtime = 4; /* minimal reasonable value */ in scc_net_ioctl()
1868 scc->kiss.fulldup = 0; /* CSMA */ in scc_net_ioctl()
1869 scc->kiss.waittime = 50; /* 500 ms */ in scc_net_ioctl()
1870 scc->kiss.maxkeyup = 10; /* 10 s */ in scc_net_ioctl()
1871 scc->kiss.mintime = 3; /* 3 s */ in scc_net_ioctl()
1872 scc->kiss.idletime = 30; /* 30 s */ in scc_net_ioctl()
1873 scc->kiss.maxdefer = 120; /* 2 min */ in scc_net_ioctl()
1874 scc->kiss.softdcd = 0; /* hardware dcd */ in scc_net_ioctl()
1876 scc->kiss.txdelay = 10; /* 100 ms */ in scc_net_ioctl()
1877 scc->kiss.persist = 64; /* 25% persistence */ /* was 25 */ in scc_net_ioctl()
1878 scc->kiss.slottime = 8; /* 160 ms */ in scc_net_ioctl()
1879 scc->kiss.tailtime = 1; /* minimal reasonable value */ in scc_net_ioctl()
1880 scc->kiss.fulldup = 0; /* CSMA */ in scc_net_ioctl()
1881 scc->kiss.waittime = 50; /* 500 ms */ in scc_net_ioctl()
1882 scc->kiss.maxkeyup = 7; /* 7 s */ in scc_net_ioctl()
1883 scc->kiss.mintime = 3; /* 3 s */ in scc_net_ioctl()
1884 scc->kiss.idletime = 30; /* 30 s */ in scc_net_ioctl()
1885 scc->kiss.maxdefer = 120; /* 2 min */ in scc_net_ioctl()
1886 scc->kiss.softdcd = 0; /* hardware dcd */ in scc_net_ioctl()
1889 scc->tx_buff = NULL; in scc_net_ioctl()
1890 skb_queue_head_init(&scc->tx_queue); in scc_net_ioctl()
1891 scc->init = 1; in scc_net_ioctl()
1908 scc->stat.bufsize = memcfg.bufsize; in scc_net_ioctl()
1912 if (!arg || copy_to_user(arg, &scc->stat, sizeof(scc->stat))) in scc_net_ioctl()
1919 kiss_cmd.param = scc_get_param(scc, kiss_cmd.command); in scc_net_ioctl()
1928 return scc_set_param(scc, kiss_cmd.command, kiss_cmd.param); in scc_net_ioctl()
1935 scc_start_calibrate(scc, cal.time, cal.pattern); in scc_net_ioctl()
1959 struct scc_channel *scc = (struct scc_channel *) dev->ml_priv; in scc_net_get_stats() local
1961 scc->dev_stat.rx_errors = scc->stat.rxerrs + scc->stat.rx_over; in scc_net_get_stats()
1962 scc->dev_stat.tx_errors = scc->stat.txerrs + scc->stat.tx_under; in scc_net_get_stats()
1963 scc->dev_stat.rx_fifo_errors = scc->stat.rx_over; in scc_net_get_stats()
1964 scc->dev_stat.tx_fifo_errors = scc->stat.tx_under; in scc_net_get_stats()
1966 return &scc->dev_stat; in scc_net_get_stats()
1997 struct scc_channel *scc = v; in scc_net_seq_next() local
2000 for (k = (v == SEQ_START_TOKEN) ? 0 : (scc - SCC_Info)+1; in scc_net_seq_next()
2021 const struct scc_channel *scc = v; in scc_net_seq_show() local
2022 const struct scc_stat *stat = &scc->stat; in scc_net_seq_show()
2023 const struct scc_kiss *kiss = &scc->kiss; in scc_net_seq_show()
2036 scc->dev->name, in scc_net_seq_show()
2037 scc->data, scc->ctrl, scc->irq, scc->clock, scc->brand, in scc_net_seq_show()
2038 scc->enhanced, Vector_Latch, scc->special, in scc_net_seq_show()
2039 scc->option); in scc_net_seq_show()
2041 scc->modem.speed, scc->modem.nrz, in scc_net_seq_show()
2042 scc->modem.clocksrc, kiss->softdcd, in scc_net_seq_show()
2063 seq_printf(seq, "%2.2x ", scc->wreg[reg]); in scc_net_seq_show()
2066 seq_printf(seq, "\tR %2.2x %2.2x XX ", InReg(scc->ctrl,R0), InReg(scc->ctrl,R1)); in scc_net_seq_show()
2068 seq_printf(seq, "%2.2x ", InReg(scc->ctrl, reg)); in scc_net_seq_show()
2071 seq_printf(seq, "%2.2x ", InReg(scc->ctrl, reg)); in scc_net_seq_show()
2091 /* * Init SCC driver * */
2119 struct scc_channel *scc; in scc_cleanup_driver() local
2148 scc = &SCC_Info[k]; in scc_cleanup_driver()
2149 if (scc->ctrl) in scc_cleanup_driver()
2151 release_region(scc->ctrl, 1); in scc_cleanup_driver()
2152 release_region(scc->data, 1); in scc_cleanup_driver()
2154 if (scc->dev) in scc_cleanup_driver()
2156 unregister_netdev(scc->dev); in scc_cleanup_driver()
2157 free_netdev(scc->dev); in scc_cleanup_driver()
2170 MODULE_SUPPORTED_DEVICE("Z8530 based SCC cards for Amateur Radio");