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
170 #include <linux/scc.h>
187 "AX.25: Z8530 SCC driver version "VERSION".dl1bke\n";
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);
211 static void scc_net_rx(struct scc_channel *scc, struct sk_buff *skb);
219 static unsigned char SCC_DriverName[] = "scc";
278 static inline void wr(struct scc_channel *scc, unsigned char reg, in wr() argument
281 OutReg(scc->ctrl, reg, (scc->wreg[reg] = val)); in wr()
284 static inline void or(struct scc_channel *scc, unsigned char reg, unsigned char val) in or() argument
286 OutReg(scc->ctrl, reg, (scc->wreg[reg] |= val)); in or()
289 static inline void cl(struct scc_channel *scc, unsigned char reg, unsigned char val) in cl() argument
291 OutReg(scc->ctrl, reg, (scc->wreg[reg] &= ~val)); in cl()
298 static inline void scc_discard_buffers(struct scc_channel *scc) in scc_discard_buffers() argument
302 spin_lock_irqsave(&scc->lock, flags); in scc_discard_buffers()
303 if (scc->tx_buff != NULL) in scc_discard_buffers()
305 dev_kfree_skb_irq(scc->tx_buff); in scc_discard_buffers()
306 scc->tx_buff = NULL; in scc_discard_buffers()
309 while (!skb_queue_empty(&scc->tx_queue)) in scc_discard_buffers()
310 dev_kfree_skb_irq(skb_dequeue(&scc->tx_queue)); in scc_discard_buffers()
312 spin_unlock_irqrestore(&scc->lock, flags); in scc_discard_buffers()
324 static inline void scc_notify(struct scc_channel *scc, int event) in scc_notify() argument
329 if (scc->kiss.fulldup != KISS_DUPLEX_OPTIMA) in scc_notify()
338 scc_net_rx(scc, skb); in scc_notify()
340 scc->stat.nospace++; in scc_notify()
343 static inline void flush_rx_FIFO(struct scc_channel *scc) in flush_rx_FIFO() argument
348 Inb(scc->data); in flush_rx_FIFO()
350 if(scc->rx_buff != NULL) /* did we receive something? */ in flush_rx_FIFO()
352 scc->stat.rxerrs++; /* then count it as an error */ in flush_rx_FIFO()
353 dev_kfree_skb_irq(scc->rx_buff); in flush_rx_FIFO()
354 scc->rx_buff = NULL; in flush_rx_FIFO()
358 static void start_hunt(struct scc_channel *scc) in start_hunt() argument
360 if ((scc->modem.clocksrc != CLK_EXTERNAL)) in start_hunt()
361 OutReg(scc->ctrl,R14,SEARCH|scc->wreg[R14]); /* DPLL: enter search mode */ in start_hunt()
362 or(scc,R3,ENT_HM|RxENABLE); /* enable the receiver, hunt mode */ in start_hunt()
369 static inline void scc_txint(struct scc_channel *scc) in scc_txint() argument
373 scc->stat.txints++; in scc_txint()
374 skb = scc->tx_buff; in scc_txint()
380 skb = skb_dequeue(&scc->tx_queue); in scc_txint()
381 scc->tx_buff = skb; in scc_txint()
382 netif_wake_queue(scc->dev); in scc_txint()
386 scc_tx_done(scc); in scc_txint()
387 Outb(scc->ctrl, RES_Tx_P); in scc_txint()
394 scc->tx_buff = NULL; in scc_txint()
395 scc_tx_done(scc); in scc_txint()
396 Outb(scc->ctrl, RES_Tx_P); in scc_txint()
400 scc->stat.tx_state = TXS_ACTIVE; in scc_txint()
402 OutReg(scc->ctrl, R0, RES_Tx_CRC); in scc_txint()
404 or(scc,R10,ABUNDER); /* re-install underrun protection */ in scc_txint()
405 Outb(scc->data,*skb->data); /* send byte */ in scc_txint()
408 if (!scc->enhanced) /* reset EOM latch */ in scc_txint()
409 Outb(scc->ctrl,RES_EOM_L); in scc_txint()
417 Outb(scc->ctrl, RES_Tx_P); /* reset pending int */ in scc_txint()
418 cl(scc, R10, ABUNDER); /* send CRC */ in scc_txint()
420 scc->tx_buff = NULL; in scc_txint()
421 scc->stat.tx_state = TXS_NEWFRAME; /* next frame... */ in scc_txint()
427 Outb(scc->data,*skb->data); in scc_txint()
433 static inline void scc_exint(struct scc_channel *scc) in scc_exint() argument
437 scc->stat.exints++; in scc_exint()
439 status = InReg(scc->ctrl,R0); in scc_exint()
440 changes = status ^ scc->status; in scc_exint()
446 flush_rx_FIFO(scc); in scc_exint()
450 if ((changes & SYNC_HUNT) && scc->kiss.softdcd) in scc_exint()
454 scc->dcd = 0; in scc_exint()
455 flush_rx_FIFO(scc); in scc_exint()
456 if ((scc->modem.clocksrc != CLK_EXTERNAL)) in scc_exint()
457 OutReg(scc->ctrl,R14,SEARCH|scc->wreg[R14]); /* DPLL: enter search mode */ in scc_exint()
459 scc->dcd = 1; in scc_exint()
462 scc_notify(scc, scc->dcd? HWEV_DCD_OFF:HWEV_DCD_ON); in scc_exint()
468 if((changes & DCD) && !scc->kiss.softdcd) /* DCD input changed state */ in scc_exint()
472 start_hunt(scc); in scc_exint()
473 scc->dcd = 1; in scc_exint()
475 cl(scc,R3,ENT_HM|RxENABLE); /* disable the receiver */ in scc_exint()
476 flush_rx_FIFO(scc); in scc_exint()
477 scc->dcd = 0; in scc_exint()
480 scc_notify(scc, scc->dcd? HWEV_DCD_ON:HWEV_DCD_OFF); in scc_exint()
492 if (scc->kiss.txdelay == 0) /* zero TXDELAY = wait for CTS */ in scc_exint()
493 scc_start_tx_timer(scc, t_txdelay, 0); in scc_exint()
497 if (scc->stat.tx_state == TXS_ACTIVE && (status & TxEOM)) in scc_exint()
499 scc->stat.tx_under++; /* oops, an underrun! count 'em */ in scc_exint()
500 Outb(scc->ctrl, RES_EXT_INT); /* reset ext/status interrupts */ in scc_exint()
502 if (scc->tx_buff != NULL) in scc_exint()
504 dev_kfree_skb_irq(scc->tx_buff); in scc_exint()
505 scc->tx_buff = NULL; in scc_exint()
508 or(scc,R10,ABUNDER); in scc_exint()
509 scc_start_tx_timer(scc, t_txdelay, 0); /* restart transmission */ in scc_exint()
512 scc->status = status; in scc_exint()
513 Outb(scc->ctrl,RES_EXT_INT); in scc_exint()
518 static inline void scc_rxint(struct scc_channel *scc) in scc_rxint() argument
522 scc->stat.rxints++; in scc_rxint()
524 if((scc->wreg[5] & RTS) && scc->kiss.fulldup == KISS_DUPLEX_HALF) in scc_rxint()
526 Inb(scc->data); /* discard char */ in scc_rxint()
527 or(scc,R3,ENT_HM); /* enter hunt mode for next flag */ in scc_rxint()
531 skb = scc->rx_buff; in scc_rxint()
535 skb = dev_alloc_skb(scc->stat.bufsize); in scc_rxint()
538 scc->dev_stat.rx_dropped++; in scc_rxint()
539 scc->stat.nospace++; in scc_rxint()
540 Inb(scc->data); in scc_rxint()
541 or(scc, R3, ENT_HM); in scc_rxint()
545 scc->rx_buff = skb; in scc_rxint()
549 if (skb->len >= scc->stat.bufsize) in scc_rxint()
555 scc->rx_buff = NULL; in scc_rxint()
556 Inb(scc->data); in scc_rxint()
557 or(scc, R3, ENT_HM); in scc_rxint()
561 skb_put_u8(skb, Inb(scc->data)); in scc_rxint()
566 static inline void scc_spint(struct scc_channel *scc) in scc_spint() argument
571 scc->stat.spints++; in scc_spint()
573 status = InReg(scc->ctrl,R1); /* read receiver status */ in scc_spint()
575 Inb(scc->data); /* throw away Rx byte */ in scc_spint()
576 skb = scc->rx_buff; in scc_spint()
580 scc->stat.rx_over++; /* count them */ in scc_spint()
581 or(scc,R3,ENT_HM); /* enter hunt mode for next flag */ in scc_spint()
585 scc->rx_buff = skb = NULL; in scc_spint()
596 scc_net_rx(scc, skb); in scc_spint()
597 scc->rx_buff = NULL; in scc_spint()
598 scc->stat.rxframes++; in scc_spint()
601 scc->rx_buff = NULL; in scc_spint()
602 scc->stat.rxerrs++; in scc_spint()
606 Outb(scc->ctrl,ERR_RES); in scc_spint()
612 static void scc_isr_dispatch(struct scc_channel *scc, int vector) in scc_isr_dispatch() argument
614 spin_lock(&scc->lock); in scc_isr_dispatch()
617 case TXINT: scc_txint(scc); break; in scc_isr_dispatch()
618 case EXINT: scc_exint(scc); break; in scc_isr_dispatch()
619 case RXINT: scc_rxint(scc); break; in scc_isr_dispatch()
620 case SPINT: scc_spint(scc); break; in scc_isr_dispatch()
622 spin_unlock(&scc->lock); in scc_isr_dispatch()
636 struct scc_channel *scc; in scc_isr() local
650 scc=&SCC_Info[vector >> 3 ^ 0x01]; in scc_isr()
651 if (!scc->dev) break; in scc_isr()
653 scc_isr_dispatch(scc, vector); in scc_isr()
655 OutReg(scc->ctrl,R0,RES_H_IUS); /* Reset Highest IUS */ in scc_isr()
664 /* Find the SCC generating the interrupt by polling all attached SCCs in scc_isr()
677 scc = NULL; in scc_isr()
683 scc = &SCC_Info[vector >> 3 ^ 0x01]; in scc_isr()
684 if (!scc->dev) break; in scc_isr()
686 scc_isr_dispatch(scc, vector); in scc_isr()
702 if (scc != NULL) in scc_isr()
704 OutReg(scc->ctrl,R0,RES_H_IUS); in scc_isr()
719 /* ----> set SCC channel speed <---- */
721 static inline void set_brg(struct scc_channel *scc, unsigned int tc) in set_brg() argument
723 cl(scc,R14,BRENABL); /* disable baudrate generator */ in set_brg()
724 wr(scc,R12,tc & 255); /* brg rate LOW */ in set_brg()
725 wr(scc,R13,tc >> 8); /* brg rate HIGH */ in set_brg()
726 or(scc,R14,BRENABL); /* enable baudrate generator */ in set_brg()
729 static inline void set_speed(struct scc_channel *scc) in set_speed() argument
732 spin_lock_irqsave(&scc->lock, flags); in set_speed()
734 if (scc->modem.speed > 0) /* paranoia... */ in set_speed()
735 set_brg(scc, (unsigned) (scc->clock / (scc->modem.speed * 64)) - 2); in set_speed()
737 spin_unlock_irqrestore(&scc->lock, flags); in set_speed()
741 /* ----> initialize a SCC channel <---- */
743 static inline void init_brg(struct scc_channel *scc) in init_brg() argument
745 wr(scc, R14, BRSRC); /* BRG source = PCLK */ in init_brg()
746 OutReg(scc->ctrl, R14, SSBR|scc->wreg[R14]); /* DPLL source = BRG */ in init_brg()
747 OutReg(scc->ctrl, R14, SNRZI|scc->wreg[R14]); /* DPLL NRZI mode */ in init_brg()
795 static void init_channel(struct scc_channel *scc) in init_channel() argument
797 del_timer(&scc->tx_t); in init_channel()
798 del_timer(&scc->tx_wdog); in init_channel()
800 disable_irq(scc->irq); in init_channel()
802 wr(scc,R4,X1CLK|SDLC); /* *1 clock, SDLC mode */ in init_channel()
803 wr(scc,R1,0); /* no W/REQ operation */ in init_channel()
804 wr(scc,R3,Rx8|RxCRC_ENAB); /* RX 8 bits/char, CRC, disabled */ in init_channel()
805 wr(scc,R5,Tx8|DTR|TxCRC_ENAB); /* TX 8 bits/char, disabled, DTR */ in init_channel()
806 wr(scc,R6,0); /* SDLC address zero (not used) */ in init_channel()
807 wr(scc,R7,FLAG); /* SDLC flag value */ in init_channel()
808 wr(scc,R9,VIS); /* vector includes status */ in init_channel()
809 …wr(scc,R10,(scc->modem.nrz? NRZ : NRZI)|CRCPS|ABUNDER); /* abort on underrun, preset CRC generator… in init_channel()
810 wr(scc,R14, 0); in init_channel()
839 switch(scc->modem.clocksrc) in init_channel()
842 wr(scc, R11, RCDPLL|TCDPLL|TRxCOI|TRxCDP); in init_channel()
843 init_brg(scc); in init_channel()
847 wr(scc, R11, ((scc->brand & BAYCOM)? TRxCDP : TRxCBR) | RCDPLL|TCRTxCP|TRxCOI); in init_channel()
848 init_brg(scc); in init_channel()
852 wr(scc, R11, (scc->brand & BAYCOM)? RCTRxCP|TCRTxCP : RCRTxCP|TCTRxCP); in init_channel()
853 OutReg(scc->ctrl, R14, DISDPLL); in init_channel()
858 set_speed(scc); /* set baudrate */ in init_channel()
860 if(scc->enhanced) in init_channel()
862 or(scc,R15,SHDLCE|FIFOE); /* enable FIFO, SDLC/HDLC Enhancements (From now R7 is R7') */ in init_channel()
863 wr(scc,R7,AUTOEOM); in init_channel()
866 if(scc->kiss.softdcd || (InReg(scc->ctrl,R0) & DCD)) in init_channel()
869 start_hunt(scc); in init_channel()
874 wr(scc,R15, BRKIE|TxUIE|(scc->kiss.softdcd? SYNCIE:DCDIE)); in init_channel()
876 Outb(scc->ctrl,RES_EXT_INT); /* reset ext/status interrupts */ in init_channel()
877 Outb(scc->ctrl,RES_EXT_INT); /* must be done twice */ in init_channel()
879 or(scc,R1,INT_ALL_Rx|TxINT_ENAB|EXT_INT_ENAB); /* enable interrupts */ in init_channel()
881 scc->status = InReg(scc->ctrl,R0); /* read initial status */ in init_channel()
883 or(scc,R9,MIE); /* master interrupt enable */ in init_channel()
885 scc_init_timer(scc); in init_channel()
887 enable_irq(scc->irq); in init_channel()
894 /* * SCC timer functions * */
901 static void scc_key_trx(struct scc_channel *scc, char tx) in scc_key_trx() argument
905 if (scc->brand & PRIMUS) in scc_key_trx()
906 Outb(scc->ctrl + 4, scc->option | (tx? 0x80 : 0)); in scc_key_trx()
908 if (scc->modem.speed < 300) in scc_key_trx()
909 scc->modem.speed = 1200; in scc_key_trx()
911 time_const = (unsigned) (scc->clock / (scc->modem.speed * (tx? 2:64))) - 2; in scc_key_trx()
913 disable_irq(scc->irq); in scc_key_trx()
917 or(scc, R1, TxINT_ENAB); /* t_maxkeyup may have reset these */ in scc_key_trx()
918 or(scc, R15, TxUIE); in scc_key_trx()
921 if (scc->modem.clocksrc == CLK_DPLL) in scc_key_trx()
926 cl(scc, R3, RxENABLE|ENT_HM); /* switch off receiver */ in scc_key_trx()
927 cl(scc, R15, DCDIE|SYNCIE); /* No DCD changes, please */ in scc_key_trx()
929 set_brg(scc, time_const); /* reprogram baudrate generator */ in scc_key_trx()
932 wr(scc, R11, RCDPLL|TCBR|TRxCOI|TRxCBR); in scc_key_trx()
935 if (scc->kiss.tx_inhibit) in scc_key_trx()
937 or(scc,R5, TxENAB); in scc_key_trx()
938 scc->wreg[R5] |= RTS; in scc_key_trx()
940 or(scc,R5,RTS|TxENAB); /* set the RTS line and enable TX */ in scc_key_trx()
943 cl(scc,R5,RTS|TxENAB); in scc_key_trx()
945 set_brg(scc, time_const); /* reprogram baudrate generator */ in scc_key_trx()
948 wr(scc, R11, RCDPLL|TCDPLL|TRxCOI|TRxCDP); in scc_key_trx()
951 if (scc->kiss.softdcd) in scc_key_trx()
954 or(scc,R15, scc->kiss.softdcd? SYNCIE:DCDIE); in scc_key_trx()
955 start_hunt(scc); in scc_key_trx()
962 if (scc->kiss.fulldup == KISS_DUPLEX_HALF) in scc_key_trx()
964 cl(scc, R3, RxENABLE); in scc_key_trx()
965 cl(scc, R15, DCDIE|SYNCIE); in scc_key_trx()
969 if (scc->kiss.tx_inhibit) in scc_key_trx()
971 or(scc,R5, TxENAB); in scc_key_trx()
972 scc->wreg[R5] |= RTS; in scc_key_trx()
974 or(scc,R5,RTS|TxENAB); /* enable tx */ in scc_key_trx()
977 cl(scc,R5,RTS|TxENAB); /* disable tx */ in scc_key_trx()
979 if ((scc->kiss.fulldup == KISS_DUPLEX_HALF) && in scc_key_trx()
981 scc->kiss.softdcd) in scc_key_trx()
986 or(scc, R15, scc->kiss.softdcd? SYNCIE:DCDIE); in scc_key_trx()
987 start_hunt(scc); in scc_key_trx()
992 enable_irq(scc->irq); in scc_key_trx()
996 /* ----> SCC timer interrupt handler and friends. <---- */
998 static void __scc_start_tx_timer(struct scc_channel *scc, in __scc_start_tx_timer() argument
1002 del_timer(&scc->tx_t); in __scc_start_tx_timer()
1006 handler(&scc->tx_t); in __scc_start_tx_timer()
1010 scc->tx_t.function = handler; in __scc_start_tx_timer()
1011 scc->tx_t.expires = jiffies + (when*HZ)/100; in __scc_start_tx_timer()
1012 add_timer(&scc->tx_t); in __scc_start_tx_timer()
1016 static void scc_start_tx_timer(struct scc_channel *scc, in scc_start_tx_timer() argument
1022 spin_lock_irqsave(&scc->lock, flags); in scc_start_tx_timer()
1023 __scc_start_tx_timer(scc, handler, when); in scc_start_tx_timer()
1024 spin_unlock_irqrestore(&scc->lock, flags); in scc_start_tx_timer()
1027 static void scc_start_defer(struct scc_channel *scc) in scc_start_defer() argument
1031 spin_lock_irqsave(&scc->lock, flags); in scc_start_defer()
1032 del_timer(&scc->tx_wdog); in scc_start_defer()
1034 if (scc->kiss.maxdefer != 0 && scc->kiss.maxdefer != TIMER_OFF) in scc_start_defer()
1036 scc->tx_wdog.function = t_busy; in scc_start_defer()
1037 scc->tx_wdog.expires = jiffies + HZ*scc->kiss.maxdefer; in scc_start_defer()
1038 add_timer(&scc->tx_wdog); in scc_start_defer()
1040 spin_unlock_irqrestore(&scc->lock, flags); in scc_start_defer()
1043 static void scc_start_maxkeyup(struct scc_channel *scc) in scc_start_maxkeyup() argument
1047 spin_lock_irqsave(&scc->lock, flags); in scc_start_maxkeyup()
1048 del_timer(&scc->tx_wdog); in scc_start_maxkeyup()
1050 if (scc->kiss.maxkeyup != 0 && scc->kiss.maxkeyup != TIMER_OFF) in scc_start_maxkeyup()
1052 scc->tx_wdog.function = t_maxkeyup; in scc_start_maxkeyup()
1053 scc->tx_wdog.expires = jiffies + HZ*scc->kiss.maxkeyup; in scc_start_maxkeyup()
1054 add_timer(&scc->tx_wdog); in scc_start_maxkeyup()
1056 spin_unlock_irqrestore(&scc->lock, flags); in scc_start_maxkeyup()
1064 static void scc_tx_done(struct scc_channel *scc) in scc_tx_done() argument
1070 switch (scc->kiss.fulldup) in scc_tx_done()
1073 scc->stat.tx_state = TXS_IDLE2; in scc_tx_done()
1074 if (scc->kiss.idletime != TIMER_OFF) in scc_tx_done()
1075 scc_start_tx_timer(scc, t_idle, in scc_tx_done()
1076 scc->kiss.idletime*100); in scc_tx_done()
1079 scc_notify(scc, HWEV_ALL_SENT); in scc_tx_done()
1082 scc->stat.tx_state = TXS_BUSY; in scc_tx_done()
1083 scc_start_tx_timer(scc, t_tail, scc->kiss.tailtime); in scc_tx_done()
1086 netif_wake_queue(scc->dev); in scc_tx_done()
1092 static inline int is_grouped(struct scc_channel *scc) in is_grouped() argument
1098 grp1 = scc->kiss.group; in is_grouped()
1105 if (scc2 == scc || !(scc2->dev && grp2)) in is_grouped()
1130 struct scc_channel *scc = from_timer(scc, t, tx_t); in t_dwait() local
1132 if (scc->stat.tx_state == TXS_WAIT) /* maxkeyup or idle timeout */ in t_dwait()
1134 if (skb_queue_empty(&scc->tx_queue)) { /* nothing to send */ in t_dwait()
1135 scc->stat.tx_state = TXS_IDLE; in t_dwait()
1136 netif_wake_queue(scc->dev); /* t_maxkeyup locked it. */ in t_dwait()
1140 scc->stat.tx_state = TXS_BUSY; in t_dwait()
1143 if (scc->kiss.fulldup == KISS_DUPLEX_HALF) in t_dwait()
1147 if (scc->dcd || (scc->kiss.persist) < Rand || (scc->kiss.group && is_grouped(scc)) ) in t_dwait()
1149 scc_start_defer(scc); in t_dwait()
1150 scc_start_tx_timer(scc, t_dwait, scc->kiss.slottime); in t_dwait()
1155 if ( !(scc->wreg[R5] & RTS) ) in t_dwait()
1157 scc_key_trx(scc, TX_ON); in t_dwait()
1158 scc_start_tx_timer(scc, t_txdelay, scc->kiss.txdelay); in t_dwait()
1160 scc_start_tx_timer(scc, t_txdelay, 0); in t_dwait()
1167 * kick transmission by a fake scc_txint(scc), start 'maxkeyup' watchdog.
1172 struct scc_channel *scc = from_timer(scc, t, tx_t); in t_txdelay() local
1174 scc_start_maxkeyup(scc); in t_txdelay()
1176 if (scc->tx_buff == NULL) in t_txdelay()
1178 disable_irq(scc->irq); in t_txdelay()
1179 scc_txint(scc); in t_txdelay()
1180 enable_irq(scc->irq); in t_txdelay()
1193 struct scc_channel *scc = from_timer(scc, t, tx_t); in t_tail() local
1196 spin_lock_irqsave(&scc->lock, flags); in t_tail()
1197 del_timer(&scc->tx_wdog); in t_tail()
1198 scc_key_trx(scc, TX_OFF); in t_tail()
1199 spin_unlock_irqrestore(&scc->lock, flags); in t_tail()
1201 if (scc->stat.tx_state == TXS_TIMEOUT) /* we had a timeout? */ in t_tail()
1203 scc->stat.tx_state = TXS_WAIT; in t_tail()
1204 scc_start_tx_timer(scc, t_dwait, scc->kiss.mintime*100); in t_tail()
1208 scc->stat.tx_state = TXS_IDLE; in t_tail()
1209 netif_wake_queue(scc->dev); in t_tail()
1220 struct scc_channel *scc = from_timer(scc, t, tx_wdog); in t_busy() local
1222 del_timer(&scc->tx_t); in t_busy()
1223 netif_stop_queue(scc->dev); /* don't pile on the wabbit! */ in t_busy()
1225 scc_discard_buffers(scc); in t_busy()
1226 scc->stat.txerrs++; in t_busy()
1227 scc->stat.tx_state = TXS_IDLE; in t_busy()
1229 netif_wake_queue(scc->dev); in t_busy()
1239 struct scc_channel *scc = from_timer(scc, t, tx_wdog); in t_maxkeyup() local
1242 spin_lock_irqsave(&scc->lock, flags); in t_maxkeyup()
1248 netif_stop_queue(scc->dev); in t_maxkeyup()
1249 scc_discard_buffers(scc); in t_maxkeyup()
1251 del_timer(&scc->tx_t); in t_maxkeyup()
1253 cl(scc, R1, TxINT_ENAB); /* force an ABORT, but don't */ in t_maxkeyup()
1254 cl(scc, R15, TxUIE); /* count it. */ in t_maxkeyup()
1255 OutReg(scc->ctrl, R0, RES_Tx_P); in t_maxkeyup()
1257 spin_unlock_irqrestore(&scc->lock, flags); in t_maxkeyup()
1259 scc->stat.txerrs++; in t_maxkeyup()
1260 scc->stat.tx_state = TXS_TIMEOUT; in t_maxkeyup()
1261 scc_start_tx_timer(scc, t_tail, scc->kiss.tailtime); in t_maxkeyup()
1273 struct scc_channel *scc = from_timer(scc, t, tx_t); in t_idle() local
1275 del_timer(&scc->tx_wdog); in t_idle()
1277 scc_key_trx(scc, TX_OFF); in t_idle()
1278 if(scc->kiss.mintime) in t_idle()
1279 scc_start_tx_timer(scc, t_dwait, scc->kiss.mintime*100); in t_idle()
1280 scc->stat.tx_state = TXS_WAIT; in t_idle()
1283 static void scc_init_timer(struct scc_channel *scc) in scc_init_timer() argument
1287 spin_lock_irqsave(&scc->lock, flags); in scc_init_timer()
1288 scc->stat.tx_state = TXS_IDLE; in scc_init_timer()
1289 spin_unlock_irqrestore(&scc->lock, flags); in scc_init_timer()
1304 static unsigned int scc_set_param(struct scc_channel *scc, unsigned int cmd, unsigned int arg) in scc_set_param() argument
1308 case PARAM_TXDELAY: scc->kiss.txdelay=arg; break; in scc_set_param()
1309 case PARAM_PERSIST: scc->kiss.persist=arg; break; in scc_set_param()
1310 case PARAM_SLOTTIME: scc->kiss.slottime=arg; break; in scc_set_param()
1311 case PARAM_TXTAIL: scc->kiss.tailtime=arg; break; in scc_set_param()
1312 case PARAM_FULLDUP: scc->kiss.fulldup=arg; break; in scc_set_param()
1314 case PARAM_GROUP: scc->kiss.group=arg; break; in scc_set_param()
1315 case PARAM_IDLE: scc->kiss.idletime=arg; break; in scc_set_param()
1316 case PARAM_MIN: scc->kiss.mintime=arg; break; in scc_set_param()
1317 case PARAM_MAXKEY: scc->kiss.maxkeyup=arg; break; in scc_set_param()
1318 case PARAM_WAIT: scc->kiss.waittime=arg; break; in scc_set_param()
1319 case PARAM_MAXDEFER: scc->kiss.maxdefer=arg; break; in scc_set_param()
1320 case PARAM_TX: scc->kiss.tx_inhibit=arg; break; in scc_set_param()
1323 scc->kiss.softdcd=arg; in scc_set_param()
1326 or(scc, R15, SYNCIE); in scc_set_param()
1327 cl(scc, R15, DCDIE); in scc_set_param()
1328 start_hunt(scc); in scc_set_param()
1330 or(scc, R15, DCDIE); in scc_set_param()
1331 cl(scc, R15, SYNCIE); in scc_set_param()
1337 scc->modem.speed=arg*100; in scc_set_param()
1339 scc->modem.speed=arg; in scc_set_param()
1341 if (scc->stat.tx_state == 0) /* only switch baudrate on rx... ;-) */ in scc_set_param()
1342 set_speed(scc); in scc_set_param()
1346 if ( !(scc->wreg[R5] & RTS) ) in scc_set_param()
1349 scc_key_trx(scc, TX_ON); in scc_set_param()
1350 scc_start_tx_timer(scc, t_txdelay, scc->kiss.txdelay); in scc_set_param()
1355 scc->stat.tx_state = TXS_BUSY; in scc_set_param()
1356 scc_start_tx_timer(scc, t_tail, scc->kiss.tailtime); in scc_set_param()
1362 scc_notify(scc, scc->dcd? HWEV_DCD_ON:HWEV_DCD_OFF); in scc_set_param()
1373 static unsigned long scc_get_param(struct scc_channel *scc, unsigned int cmd) in scc_get_param() argument
1377 case PARAM_TXDELAY: return CAST(scc->kiss.txdelay); in scc_get_param()
1378 case PARAM_PERSIST: return CAST(scc->kiss.persist); in scc_get_param()
1379 case PARAM_SLOTTIME: return CAST(scc->kiss.slottime); in scc_get_param()
1380 case PARAM_TXTAIL: return CAST(scc->kiss.tailtime); in scc_get_param()
1381 case PARAM_FULLDUP: return CAST(scc->kiss.fulldup); in scc_get_param()
1382 case PARAM_SOFTDCD: return CAST(scc->kiss.softdcd); in scc_get_param()
1383 case PARAM_DTR: return CAST((scc->wreg[R5] & DTR)? 1:0); in scc_get_param()
1384 case PARAM_RTS: return CAST((scc->wreg[R5] & RTS)? 1:0); in scc_get_param()
1385 case PARAM_SPEED: return CAST(scc->modem.speed); in scc_get_param()
1386 case PARAM_GROUP: return CAST(scc->kiss.group); in scc_get_param()
1387 case PARAM_IDLE: return CAST(scc->kiss.idletime); in scc_get_param()
1388 case PARAM_MIN: return CAST(scc->kiss.mintime); in scc_get_param()
1389 case PARAM_MAXKEY: return CAST(scc->kiss.maxkeyup); in scc_get_param()
1390 case PARAM_WAIT: return CAST(scc->kiss.waittime); in scc_get_param()
1391 case PARAM_MAXDEFER: return CAST(scc->kiss.maxdefer); in scc_get_param()
1392 case PARAM_TX: return CAST(scc->kiss.tx_inhibit); in scc_get_param()
1406 struct scc_channel *scc = from_timer(scc, t, tx_wdog); in scc_stop_calibrate() local
1409 spin_lock_irqsave(&scc->lock, flags); in scc_stop_calibrate()
1410 del_timer(&scc->tx_wdog); in scc_stop_calibrate()
1411 scc_key_trx(scc, TX_OFF); in scc_stop_calibrate()
1412 wr(scc, R6, 0); in scc_stop_calibrate()
1413 wr(scc, R7, FLAG); in scc_stop_calibrate()
1414 Outb(scc->ctrl,RES_EXT_INT); /* reset ext/status interrupts */ in scc_stop_calibrate()
1415 Outb(scc->ctrl,RES_EXT_INT); in scc_stop_calibrate()
1417 netif_wake_queue(scc->dev); in scc_stop_calibrate()
1418 spin_unlock_irqrestore(&scc->lock, flags); in scc_stop_calibrate()
1423 scc_start_calibrate(struct scc_channel *scc, int duration, unsigned char pattern) in scc_start_calibrate() argument
1427 spin_lock_irqsave(&scc->lock, flags); in scc_start_calibrate()
1428 netif_stop_queue(scc->dev); in scc_start_calibrate()
1429 scc_discard_buffers(scc); in scc_start_calibrate()
1431 del_timer(&scc->tx_wdog); in scc_start_calibrate()
1433 scc->tx_wdog.function = scc_stop_calibrate; in scc_start_calibrate()
1434 scc->tx_wdog.expires = jiffies + HZ*duration; in scc_start_calibrate()
1435 add_timer(&scc->tx_wdog); in scc_start_calibrate()
1438 wr(scc, R6, 0); in scc_start_calibrate()
1439 wr(scc, R7, pattern); in scc_start_calibrate()
1446 Outb(scc->ctrl,RES_EXT_INT); /* reset ext/status interrupts */ in scc_start_calibrate()
1447 Outb(scc->ctrl,RES_EXT_INT); in scc_start_calibrate()
1449 scc_key_trx(scc, TX_ON); in scc_start_calibrate()
1450 spin_unlock_irqrestore(&scc->lock, flags); in scc_start_calibrate()
1464 struct scc_channel *scc; in z8530_init() local
1485 scc=&SCC_Info[2*chip]; in z8530_init()
1486 if (!scc->ctrl) continue; in z8530_init()
1488 /* Special SCC cards */ in z8530_init()
1490 if(scc->brand & EAGLE) /* this is an EAGLE card */ in z8530_init()
1491 Outb(scc->special,0x08); /* enable interrupt on the board */ in z8530_init()
1493 if(scc->brand & (PC100 | PRIMUS)) /* this is a PC100/PRIMUS card */ in z8530_init()
1494 Outb(scc->special,scc->option); /* set the MODEM mode (0x22) */ in z8530_init()
1499 spin_lock_irqsave(&scc->lock, flags); in z8530_init()
1501 Outb(scc->ctrl, 0); in z8530_init()
1502 OutReg(scc->ctrl,R9,FHWRES); /* force hardware reset */ in z8530_init()
1504 wr(scc, R2, chip*16); /* interrupt vector */ in z8530_init()
1505 wr(scc, R9, VIS); /* vector includes status */ in z8530_init()
1506 spin_unlock_irqrestore(&scc->lock, flags); in z8530_init()
1517 static int scc_net_alloc(const char *name, struct scc_channel *scc) in scc_net_alloc() argument
1526 dev->ml_priv = scc; in scc_net_alloc()
1527 scc->dev = dev; in scc_net_alloc()
1528 spin_lock_init(&scc->lock); in scc_net_alloc()
1529 timer_setup(&scc->tx_t, NULL, 0); in scc_net_alloc()
1530 timer_setup(&scc->tx_wdog, NULL, 0); in scc_net_alloc()
1537 scc->dev = NULL; in scc_net_alloc()
1583 struct scc_channel *scc = (struct scc_channel *) dev->ml_priv; in scc_net_open() local
1585 if (!scc->init) in scc_net_open()
1588 scc->tx_buff = NULL; in scc_net_open()
1589 skb_queue_head_init(&scc->tx_queue); in scc_net_open()
1591 init_channel(scc); in scc_net_open()
1601 struct scc_channel *scc = (struct scc_channel *) dev->ml_priv; in scc_net_close() local
1606 spin_lock_irqsave(&scc->lock, flags); in scc_net_close()
1607 Outb(scc->ctrl,0); /* Make sure pointer is written */ in scc_net_close()
1608 wr(scc,R1,0); /* disable interrupts */ in scc_net_close()
1609 wr(scc,R3,0); in scc_net_close()
1610 spin_unlock_irqrestore(&scc->lock, flags); in scc_net_close()
1612 del_timer_sync(&scc->tx_t); in scc_net_close()
1613 del_timer_sync(&scc->tx_wdog); in scc_net_close()
1615 scc_discard_buffers(scc); in scc_net_close()
1622 static void scc_net_rx(struct scc_channel *scc, struct sk_buff *skb) in scc_net_rx() argument
1629 scc->dev_stat.rx_packets++; in scc_net_rx()
1630 scc->dev_stat.rx_bytes += skb->len; in scc_net_rx()
1632 skb->protocol = ax25_type_trans(skb, scc->dev); in scc_net_rx()
1641 struct scc_channel *scc = (struct scc_channel *) dev->ml_priv; in scc_net_tx() local
1648 if (skb->len > scc->stat.bufsize || skb->len < 2) { in scc_net_tx()
1649 scc->dev_stat.tx_dropped++; /* bogus frame */ in scc_net_tx()
1654 scc->dev_stat.tx_packets++; in scc_net_tx()
1655 scc->dev_stat.tx_bytes += skb->len; in scc_net_tx()
1656 scc->stat.txframes++; in scc_net_tx()
1662 scc_set_param(scc, kisscmd, *skb->data); in scc_net_tx()
1667 spin_lock_irqsave(&scc->lock, flags); in scc_net_tx()
1669 if (skb_queue_len(&scc->tx_queue) > scc->dev->tx_queue_len) { in scc_net_tx()
1671 skb_del = skb_dequeue(&scc->tx_queue); in scc_net_tx()
1674 skb_queue_tail(&scc->tx_queue, skb); in scc_net_tx()
1684 if(scc->stat.tx_state == TXS_IDLE || scc->stat.tx_state == TXS_IDLE2) { in scc_net_tx()
1685 scc->stat.tx_state = TXS_BUSY; in scc_net_tx()
1686 if (scc->kiss.fulldup == KISS_DUPLEX_HALF) in scc_net_tx()
1687 __scc_start_tx_timer(scc, t_dwait, scc->kiss.waittime); in scc_net_tx()
1689 __scc_start_tx_timer(scc, t_dwait, 0); in scc_net_tx()
1691 spin_unlock_irqrestore(&scc->lock, flags); in scc_net_tx()
1715 struct scc_channel *scc = (struct scc_channel *) dev->ml_priv; in scc_net_siocdevprivate() local
1745 0, "AX.25 SCC", in scc_net_siocdevprivate()
1753 if (!request_region(hwcfg.vector_latch, 1, "scc vector latch")) in scc_net_siocdevprivate()
1764 if(request_region(hwcfg.ctrl_a, 1, "scc-probe")) in scc_net_siocdevprivate()
1823 request_region(SCC_Info[2*Nchips+chan].ctrl, 1, "scc ctrl"); in scc_net_siocdevprivate()
1824 request_region(SCC_Info[2*Nchips+chan].data, 1, "scc data"); in scc_net_siocdevprivate()
1852 if (!scc->init) in scc_net_siocdevprivate()
1859 scc->stat.bufsize = SCC_BUFSIZE; in scc_net_siocdevprivate()
1861 if (copy_from_user(&scc->modem, arg, sizeof(struct scc_modem))) in scc_net_siocdevprivate()
1866 if (scc->modem.speed < 4800) in scc_net_siocdevprivate()
1868 scc->kiss.txdelay = 36; /* 360 ms */ in scc_net_siocdevprivate()
1869 scc->kiss.persist = 42; /* 25% persistence */ /* was 25 */ in scc_net_siocdevprivate()
1870 scc->kiss.slottime = 16; /* 160 ms */ in scc_net_siocdevprivate()
1871 scc->kiss.tailtime = 4; /* minimal reasonable value */ in scc_net_siocdevprivate()
1872 scc->kiss.fulldup = 0; /* CSMA */ in scc_net_siocdevprivate()
1873 scc->kiss.waittime = 50; /* 500 ms */ in scc_net_siocdevprivate()
1874 scc->kiss.maxkeyup = 10; /* 10 s */ in scc_net_siocdevprivate()
1875 scc->kiss.mintime = 3; /* 3 s */ in scc_net_siocdevprivate()
1876 scc->kiss.idletime = 30; /* 30 s */ in scc_net_siocdevprivate()
1877 scc->kiss.maxdefer = 120; /* 2 min */ in scc_net_siocdevprivate()
1878 scc->kiss.softdcd = 0; /* hardware dcd */ in scc_net_siocdevprivate()
1880 scc->kiss.txdelay = 10; /* 100 ms */ in scc_net_siocdevprivate()
1881 scc->kiss.persist = 64; /* 25% persistence */ /* was 25 */ in scc_net_siocdevprivate()
1882 scc->kiss.slottime = 8; /* 160 ms */ in scc_net_siocdevprivate()
1883 scc->kiss.tailtime = 1; /* minimal reasonable value */ in scc_net_siocdevprivate()
1884 scc->kiss.fulldup = 0; /* CSMA */ in scc_net_siocdevprivate()
1885 scc->kiss.waittime = 50; /* 500 ms */ in scc_net_siocdevprivate()
1886 scc->kiss.maxkeyup = 7; /* 7 s */ in scc_net_siocdevprivate()
1887 scc->kiss.mintime = 3; /* 3 s */ in scc_net_siocdevprivate()
1888 scc->kiss.idletime = 30; /* 30 s */ in scc_net_siocdevprivate()
1889 scc->kiss.maxdefer = 120; /* 2 min */ in scc_net_siocdevprivate()
1890 scc->kiss.softdcd = 0; /* hardware dcd */ in scc_net_siocdevprivate()
1893 scc->tx_buff = NULL; in scc_net_siocdevprivate()
1894 skb_queue_head_init(&scc->tx_queue); in scc_net_siocdevprivate()
1895 scc->init = 1; in scc_net_siocdevprivate()
1912 scc->stat.bufsize = memcfg.bufsize; in scc_net_siocdevprivate()
1916 if (!arg || copy_to_user(arg, &scc->stat, sizeof(scc->stat))) in scc_net_siocdevprivate()
1923 kiss_cmd.param = scc_get_param(scc, kiss_cmd.command); in scc_net_siocdevprivate()
1932 return scc_set_param(scc, kiss_cmd.command, kiss_cmd.param); in scc_net_siocdevprivate()
1939 scc_start_calibrate(scc, cal.time, cal.pattern); in scc_net_siocdevprivate()
1963 struct scc_channel *scc = (struct scc_channel *) dev->ml_priv; in scc_net_get_stats() local
1965 scc->dev_stat.rx_errors = scc->stat.rxerrs + scc->stat.rx_over; in scc_net_get_stats()
1966 scc->dev_stat.tx_errors = scc->stat.txerrs + scc->stat.tx_under; in scc_net_get_stats()
1967 scc->dev_stat.rx_fifo_errors = scc->stat.rx_over; in scc_net_get_stats()
1968 scc->dev_stat.tx_fifo_errors = scc->stat.tx_under; in scc_net_get_stats()
1970 return &scc->dev_stat; in scc_net_get_stats()
2001 struct scc_channel *scc = v; in scc_net_seq_next() local
2004 for (k = (v == SEQ_START_TOKEN) ? 0 : (scc - SCC_Info)+1; in scc_net_seq_next()
2025 const struct scc_channel *scc = v; in scc_net_seq_show() local
2026 const struct scc_stat *stat = &scc->stat; in scc_net_seq_show()
2027 const struct scc_kiss *kiss = &scc->kiss; in scc_net_seq_show()
2040 scc->dev->name, in scc_net_seq_show()
2041 scc->data, scc->ctrl, scc->irq, scc->clock, scc->brand, in scc_net_seq_show()
2042 scc->enhanced, Vector_Latch, scc->special, in scc_net_seq_show()
2043 scc->option); in scc_net_seq_show()
2045 scc->modem.speed, scc->modem.nrz, in scc_net_seq_show()
2046 scc->modem.clocksrc, kiss->softdcd, in scc_net_seq_show()
2067 seq_printf(seq, "%2.2x ", scc->wreg[reg]); in scc_net_seq_show()
2070 seq_printf(seq, "\tR %2.2x %2.2x XX ", InReg(scc->ctrl,R0), InReg(scc->ctrl,R1)); in scc_net_seq_show()
2072 seq_printf(seq, "%2.2x ", InReg(scc->ctrl, reg)); in scc_net_seq_show()
2075 seq_printf(seq, "%2.2x ", InReg(scc->ctrl, reg)); in scc_net_seq_show()
2095 /* * Init SCC driver * */
2124 struct scc_channel *scc; in scc_cleanup_driver() local
2153 scc = &SCC_Info[k]; in scc_cleanup_driver()
2154 if (scc->ctrl) in scc_cleanup_driver()
2156 release_region(scc->ctrl, 1); in scc_cleanup_driver()
2157 release_region(scc->data, 1); in scc_cleanup_driver()
2159 if (scc->dev) in scc_cleanup_driver()
2161 unregister_netdev(scc->dev); in scc_cleanup_driver()
2162 free_netdev(scc->dev); in scc_cleanup_driver()