2 * FarSync WAN driver for Linux (2.6.x kernel version)
4 * Actually sync driver for X.21, V.35 and V.24 on FarSync T-series cards
6 * Copyright (C) 2001-2004 FarSite Communications Ltd.
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
14 * Author: R.J.Dunlop <bob.dunlop@farsite.co.uk>
15 * Maintainer: Kevin Curtis <kevin.curtis@farsite.co.uk>
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/version.h>
21 #include <linux/pci.h>
22 #include <linux/ioport.h>
23 #include <linux/init.h>
25 #include <linux/hdlc.h>
27 #include <asm/uaccess.h>
34 MODULE_AUTHOR("R.J.Dunlop <bob.dunlop@farsite.co.uk>");
35 MODULE_DESCRIPTION("FarSync T-Series WAN driver. FarSite Communications Ltd.");
36 MODULE_LICENSE("GPL");
38 /* Driver configuration and global parameters
39 * ==========================================
42 /* Number of ports (per card) and cards supported
44 #define FST_MAX_PORTS 4
45 #define FST_MAX_CARDS 32
47 /* Default parameters for the link
49 #define FST_TX_QUEUE_LEN 100 /* At 8Mbps a longer queue length is
51 #define FST_TXQ_DEPTH 16 /* This one is for the buffering
52 * of frames on the way down to the card
53 * so that we can keep the card busy
54 * and maximise throughput
56 #define FST_HIGH_WATER_MARK 12 /* Point at which we flow control
58 #define FST_LOW_WATER_MARK 8 /* Point at which we remove flow
59 * control from network layer */
60 #define FST_MAX_MTU 8000 /* Huge but possible */
61 #define FST_DEF_MTU 1500 /* Common sane value */
63 #define FST_TX_TIMEOUT (2*HZ)
66 #define ARPHRD_MYTYPE ARPHRD_RAWHDLC /* Raw frames */
68 #define ARPHRD_MYTYPE ARPHRD_HDLC /* Cisco-HDLC (keepalives etc) */
72 * Modules parameters and associated varaibles
74 static int fst_txq_low
= FST_LOW_WATER_MARK
;
75 static int fst_txq_high
= FST_HIGH_WATER_MARK
;
76 static int fst_max_reads
= 7;
77 static int fst_excluded_cards
= 0;
78 static int fst_excluded_list
[FST_MAX_CARDS
];
80 module_param(fst_txq_low
, int, 0);
81 module_param(fst_txq_high
, int, 0);
82 module_param(fst_max_reads
, int, 0);
83 module_param(fst_excluded_cards
, int, 0);
84 module_param_array(fst_excluded_list
, int, NULL
, 0);
86 /* Card shared memory layout
87 * =========================
91 /* This information is derived in part from the FarSite FarSync Smc.h
92 * file. Unfortunately various name clashes and the non-portability of the
93 * bit field declarations in that file have meant that I have chosen to
94 * recreate the information here.
96 * The SMC (Shared Memory Configuration) has a version number that is
97 * incremented every time there is a significant change. This number can
98 * be used to check that we have not got out of step with the firmware
99 * contained in the .CDE files.
101 #define SMC_VERSION 24
103 #define FST_MEMSIZE 0x100000 /* Size of card memory (1Mb) */
105 #define SMC_BASE 0x00002000L /* Base offset of the shared memory window main
106 * configuration structure */
107 #define BFM_BASE 0x00010000L /* Base offset of the shared memory window DMA
110 #define LEN_TX_BUFFER 8192 /* Size of packet buffers */
111 #define LEN_RX_BUFFER 8192
113 #define LEN_SMALL_TX_BUFFER 256 /* Size of obsolete buffs used for DOS diags */
114 #define LEN_SMALL_RX_BUFFER 256
116 #define NUM_TX_BUFFER 2 /* Must be power of 2. Fixed by firmware */
117 #define NUM_RX_BUFFER 8
119 /* Interrupt retry time in milliseconds */
120 #define INT_RETRY_TIME 2
122 /* The Am186CH/CC processors support a SmartDMA mode using circular pools
123 * of buffer descriptors. The structure is almost identical to that used
124 * in the LANCE Ethernet controllers. Details available as PDF from the
125 * AMD web site: http://www.amd.com/products/epd/processors/\
126 * 2.16bitcont/3.am186cxfa/a21914/21914.pdf
128 struct txdesc
{ /* Transmit descriptor */
129 volatile u16 ladr
; /* Low order address of packet. This is a
130 * linear address in the Am186 memory space
132 volatile u8 hadr
; /* High order address. Low 4 bits only, high 4
135 volatile u8 bits
; /* Status and config */
136 volatile u16 bcnt
; /* 2s complement of packet size in low 15 bits.
137 * Transmit terminal count interrupt enable in
140 u16 unused
; /* Not used in Tx */
143 struct rxdesc
{ /* Receive descriptor */
144 volatile u16 ladr
; /* Low order address of packet */
145 volatile u8 hadr
; /* High order address */
146 volatile u8 bits
; /* Status and config */
147 volatile u16 bcnt
; /* 2s complement of buffer size in low 15 bits.
148 * Receive terminal count interrupt enable in
151 volatile u16 mcnt
; /* Message byte count (15 bits) */
154 /* Convert a length into the 15 bit 2's complement */
155 /* #define cnv_bcnt(len) (( ~(len) + 1 ) & 0x7FFF ) */
156 /* Since we need to set the high bit to enable the completion interrupt this
157 * can be made a lot simpler
159 #define cnv_bcnt(len) (-(len))
161 /* Status and config bits for the above */
162 #define DMA_OWN 0x80 /* SmartDMA owns the descriptor */
163 #define TX_STP 0x02 /* Tx: start of packet */
164 #define TX_ENP 0x01 /* Tx: end of packet */
165 #define RX_ERR 0x40 /* Rx: error (OR of next 4 bits) */
166 #define RX_FRAM 0x20 /* Rx: framing error */
167 #define RX_OFLO 0x10 /* Rx: overflow error */
168 #define RX_CRC 0x08 /* Rx: CRC error */
169 #define RX_HBUF 0x04 /* Rx: buffer error */
170 #define RX_STP 0x02 /* Rx: start of packet */
171 #define RX_ENP 0x01 /* Rx: end of packet */
173 /* Interrupts from the card are caused by various events which are presented
174 * in a circular buffer as several events may be processed on one physical int
176 #define MAX_CIRBUFF 32
179 u8 rdindex
; /* read, then increment and wrap */
180 u8 wrindex
; /* write, then increment and wrap */
181 u8 evntbuff
[MAX_CIRBUFF
];
184 /* Interrupt event codes.
185 * Where appropriate the two low order bits indicate the port number
187 #define CTLA_CHG 0x18 /* Control signal changed */
188 #define CTLB_CHG 0x19
189 #define CTLC_CHG 0x1A
190 #define CTLD_CHG 0x1B
192 #define INIT_CPLT 0x20 /* Initialisation complete */
193 #define INIT_FAIL 0x21 /* Initialisation failed */
195 #define ABTA_SENT 0x24 /* Abort sent */
196 #define ABTB_SENT 0x25
197 #define ABTC_SENT 0x26
198 #define ABTD_SENT 0x27
200 #define TXA_UNDF 0x28 /* Transmission underflow */
201 #define TXB_UNDF 0x29
202 #define TXC_UNDF 0x2A
203 #define TXD_UNDF 0x2B
208 #define TE1_ALMA 0x30
210 /* Port physical configuration. See farsync.h for field values */
212 u16 lineInterface
; /* Physical interface type */
213 u8 x25op
; /* Unused at present */
214 u8 internalClock
; /* 1 => internal clock, 0 => external */
215 u8 transparentMode
; /* 1 => on, 0 => off */
216 u8 invertClock
; /* 0 => normal, 1 => inverted */
217 u8 padBytes
[6]; /* Padding */
218 u32 lineSpeed
; /* Speed in bps */
221 /* TE1 port physical configuration */
245 u32 receiveBufferDelay
;
246 u32 framingErrorCount
;
247 u32 codeViolationCount
;
252 u8 receiveRemoteAlarm
;
253 u8 alarmIndicationSignal
;
257 /* Finally sling all the above together into the shared memory structure.
258 * Sorry it's a hodge podge of arrays, structures and unused bits, it's been
259 * evolving under NT for some time so I guess we're stuck with it.
260 * The structure starts at offset SMC_BASE.
261 * See farsync.h for some field values.
264 /* DMA descriptor rings */
265 struct rxdesc rxDescrRing
[FST_MAX_PORTS
][NUM_RX_BUFFER
];
266 struct txdesc txDescrRing
[FST_MAX_PORTS
][NUM_TX_BUFFER
];
268 /* Obsolete small buffers */
269 u8 smallRxBuffer
[FST_MAX_PORTS
][NUM_RX_BUFFER
][LEN_SMALL_RX_BUFFER
];
270 u8 smallTxBuffer
[FST_MAX_PORTS
][NUM_TX_BUFFER
][LEN_SMALL_TX_BUFFER
];
272 u8 taskStatus
; /* 0x00 => initialising, 0x01 => running,
276 u8 interruptHandshake
; /* Set to 0x01 by adapter to signal interrupt,
277 * set to 0xEE by host to acknowledge interrupt
280 u16 smcVersion
; /* Must match SMC_VERSION */
282 u32 smcFirmwareVersion
; /* 0xIIVVRRBB where II = product ID, VV = major
283 * version, RR = revision and BB = build
286 u16 txa_done
; /* Obsolete completion flags */
295 u16 mailbox
[4]; /* Diagnostics mailbox. Not used */
297 struct cirbuff interruptEvent
; /* interrupt causes */
299 u32 v24IpSts
[FST_MAX_PORTS
]; /* V.24 control input status */
300 u32 v24OpSts
[FST_MAX_PORTS
]; /* V.24 control output status */
302 struct port_cfg portConfig
[FST_MAX_PORTS
];
304 u16 clockStatus
[FST_MAX_PORTS
]; /* lsb: 0=> present, 1=> absent */
306 u16 cableStatus
; /* lsb: 0=> present, 1=> absent */
308 u16 txDescrIndex
[FST_MAX_PORTS
]; /* transmit descriptor ring index */
309 u16 rxDescrIndex
[FST_MAX_PORTS
]; /* receive descriptor ring index */
311 u16 portMailbox
[FST_MAX_PORTS
][2]; /* command, modifier */
312 u16 cardMailbox
[4]; /* Not used */
314 /* Number of times the card thinks the host has
315 * missed an interrupt by not acknowledging
316 * within 2mS (I guess NT has problems)
318 u32 interruptRetryCount
;
320 /* Driver private data used as an ID. We'll not
321 * use this as I'd rather keep such things
322 * in main memory rather than on the PCI bus
324 u32 portHandle
[FST_MAX_PORTS
];
326 /* Count of Tx underflows for stats */
327 u32 transmitBufferUnderflow
[FST_MAX_PORTS
];
329 /* Debounced V.24 control input status */
330 u32 v24DebouncedSts
[FST_MAX_PORTS
];
332 /* Adapter debounce timers. Don't touch */
333 u32 ctsTimer
[FST_MAX_PORTS
];
334 u32 ctsTimerRun
[FST_MAX_PORTS
];
335 u32 dcdTimer
[FST_MAX_PORTS
];
336 u32 dcdTimerRun
[FST_MAX_PORTS
];
338 u32 numberOfPorts
; /* Number of ports detected at startup */
342 u16 cardMode
; /* Bit-mask to enable features:
343 * Bit 0: 1 enables LED identify mode
346 u16 portScheduleOffset
;
348 struct su_config suConfig
; /* TE1 Bits */
349 struct su_status suStatus
;
351 u32 endOfSmcSignature
; /* endOfSmcSignature MUST be the last member of
352 * the structure and marks the end of shared
353 * memory. Adapter code initializes it as
358 /* endOfSmcSignature value */
359 #define END_SIG 0x12345678
361 /* Mailbox values. (portMailbox) */
362 #define NOP 0 /* No operation */
363 #define ACK 1 /* Positive acknowledgement to PC driver */
364 #define NAK 2 /* Negative acknowledgement to PC driver */
365 #define STARTPORT 3 /* Start an HDLC port */
366 #define STOPPORT 4 /* Stop an HDLC port */
367 #define ABORTTX 5 /* Abort the transmitter for a port */
368 #define SETV24O 6 /* Set V24 outputs */
370 /* PLX Chip Register Offsets */
371 #define CNTRL_9052 0x50 /* Control Register */
372 #define CNTRL_9054 0x6c /* Control Register */
374 #define INTCSR_9052 0x4c /* Interrupt control/status register */
375 #define INTCSR_9054 0x68 /* Interrupt control/status register */
377 /* 9054 DMA Registers */
379 * Note that we will be using DMA Channel 0 for copying rx data
380 * and Channel 1 for copying tx data
382 #define DMAMODE0 0x80
383 #define DMAPADR0 0x84
384 #define DMALADR0 0x88
387 #define DMAMODE1 0x94
388 #define DMAPADR1 0x98
389 #define DMALADR1 0x9c
398 #define DMAMARBR 0xac
400 #define FST_MIN_DMA_LEN 64
401 #define FST_RX_DMA_INT 0x01
402 #define FST_TX_DMA_INT 0x02
403 #define FST_CARD_INT 0x04
405 /* Larger buffers are positioned in memory at offset BFM_BASE */
407 u8 txBuffer
[FST_MAX_PORTS
][NUM_TX_BUFFER
][LEN_TX_BUFFER
];
408 u8 rxBuffer
[FST_MAX_PORTS
][NUM_RX_BUFFER
][LEN_RX_BUFFER
];
411 /* Calculate offset of a buffer object within the shared memory window */
412 #define BUF_OFFSET(X) (BFM_BASE + offsetof(struct buf_window, X))
416 /* Device driver private information
417 * =================================
419 /* Per port (line or channel) information
421 struct fst_port_info
{
422 struct net_device
*dev
; /* Device struct - must be first */
423 struct fst_card_info
*card
; /* Card we're associated with */
424 int index
; /* Port index on the card */
425 int hwif
; /* Line hardware (lineInterface copy) */
426 int run
; /* Port is running */
427 int mode
; /* Normal or FarSync raw */
428 int rxpos
; /* Next Rx buffer to use */
429 int txpos
; /* Next Tx buffer to use */
430 int txipos
; /* Next Tx buffer to check for free */
431 int start
; /* Indication of start/stop to network */
433 * A sixteen entry transmit queue
435 int txqs
; /* index to get next buffer to tx */
436 int txqe
; /* index to queue next packet */
437 struct sk_buff
*txq
[FST_TXQ_DEPTH
]; /* The queue */
441 /* Per card information
443 struct fst_card_info
{
444 char __iomem
*mem
; /* Card memory mapped to kernel space */
445 char __iomem
*ctlmem
; /* Control memory for PCI cards */
446 unsigned int phys_mem
; /* Physical memory window address */
447 unsigned int phys_ctlmem
; /* Physical control memory address */
448 unsigned int irq
; /* Interrupt request line number */
449 unsigned int nports
; /* Number of serial ports */
450 unsigned int type
; /* Type index of card */
451 unsigned int state
; /* State of card */
452 spinlock_t card_lock
; /* Lock for SMP access */
453 unsigned short pci_conf
; /* PCI card config in I/O space */
455 struct fst_port_info ports
[FST_MAX_PORTS
];
456 struct pci_dev
*device
; /* Information about the pci device */
457 int card_no
; /* Inst of the card on the system */
458 int family
; /* TxP or TxU */
459 int dmarx_in_progress
;
460 int dmatx_in_progress
;
461 unsigned long int_count
;
462 unsigned long int_time_ave
;
463 void *rx_dma_handle_host
;
464 dma_addr_t rx_dma_handle_card
;
465 void *tx_dma_handle_host
;
466 dma_addr_t tx_dma_handle_card
;
467 struct sk_buff
*dma_skb_rx
;
468 struct fst_port_info
*dma_port_rx
;
469 struct fst_port_info
*dma_port_tx
;
476 /* Convert an HDLC device pointer into a port info pointer and similar */
477 #define dev_to_port(D) (dev_to_hdlc(D)->priv)
478 #define port_to_dev(P) ((P)->dev)
482 * Shared memory window access macros
484 * We have a nice memory based structure above, which could be directly
485 * mapped on i386 but might not work on other architectures unless we use
486 * the readb,w,l and writeb,w,l macros. Unfortunately these macros take
487 * physical offsets so we have to convert. The only saving grace is that
488 * this should all collapse back to a simple indirection eventually.
490 #define WIN_OFFSET(X) ((long)&(((struct fst_shared *)SMC_BASE)->X))
492 #define FST_RDB(C,E) readb ((C)->mem + WIN_OFFSET(E))
493 #define FST_RDW(C,E) readw ((C)->mem + WIN_OFFSET(E))
494 #define FST_RDL(C,E) readl ((C)->mem + WIN_OFFSET(E))
496 #define FST_WRB(C,E,B) writeb ((B), (C)->mem + WIN_OFFSET(E))
497 #define FST_WRW(C,E,W) writew ((W), (C)->mem + WIN_OFFSET(E))
498 #define FST_WRL(C,E,L) writel ((L), (C)->mem + WIN_OFFSET(E))
505 static int fst_debug_mask
= { FST_DEBUG
};
507 /* Most common debug activity is to print something if the corresponding bit
508 * is set in the debug mask. Note: this uses a non-ANSI extension in GCC to
509 * support variable numbers of macro parameters. The inverted if prevents us
510 * eating someone else's else clause.
512 #define dbg(F,fmt,A...) if ( ! ( fst_debug_mask & (F))) \
515 printk ( KERN_DEBUG FST_NAME ": " fmt, ## A )
518 #define dbg(X...) /* NOP */
521 /* Printing short cuts
523 #define printk_err(fmt,A...) printk ( KERN_ERR FST_NAME ": " fmt, ## A )
524 #define printk_warn(fmt,A...) printk ( KERN_WARNING FST_NAME ": " fmt, ## A )
525 #define printk_info(fmt,A...) printk ( KERN_INFO FST_NAME ": " fmt, ## A )
528 * PCI ID lookup table
530 static struct pci_device_id fst_pci_dev_id
[] __devinitdata
= {
531 {PCI_VENDOR_ID_FARSITE
, PCI_DEVICE_ID_FARSITE_T2P
, PCI_ANY_ID
,
532 PCI_ANY_ID
, 0, 0, FST_TYPE_T2P
},
534 {PCI_VENDOR_ID_FARSITE
, PCI_DEVICE_ID_FARSITE_T4P
, PCI_ANY_ID
,
535 PCI_ANY_ID
, 0, 0, FST_TYPE_T4P
},
537 {PCI_VENDOR_ID_FARSITE
, PCI_DEVICE_ID_FARSITE_T1U
, PCI_ANY_ID
,
538 PCI_ANY_ID
, 0, 0, FST_TYPE_T1U
},
540 {PCI_VENDOR_ID_FARSITE
, PCI_DEVICE_ID_FARSITE_T2U
, PCI_ANY_ID
,
541 PCI_ANY_ID
, 0, 0, FST_TYPE_T2U
},
543 {PCI_VENDOR_ID_FARSITE
, PCI_DEVICE_ID_FARSITE_T4U
, PCI_ANY_ID
,
544 PCI_ANY_ID
, 0, 0, FST_TYPE_T4U
},
546 {PCI_VENDOR_ID_FARSITE
, PCI_DEVICE_ID_FARSITE_TE1
, PCI_ANY_ID
,
547 PCI_ANY_ID
, 0, 0, FST_TYPE_TE1
},
549 {PCI_VENDOR_ID_FARSITE
, PCI_DEVICE_ID_FARSITE_TE1C
, PCI_ANY_ID
,
550 PCI_ANY_ID
, 0, 0, FST_TYPE_TE1
},
554 MODULE_DEVICE_TABLE(pci
, fst_pci_dev_id
);
557 * Device Driver Work Queues
559 * So that we don't spend too much time processing events in the
560 * Interrupt Service routine, we will declare a work queue per Card
561 * and make the ISR schedule a task in the queue for later execution.
562 * In the 2.4 Kernel we used to use the immediate queue for BH's
563 * Now that they are gone, tasklets seem to be much better than work
567 static void do_bottom_half_tx(struct fst_card_info
*card
);
568 static void do_bottom_half_rx(struct fst_card_info
*card
);
569 static void fst_process_tx_work_q(unsigned long work_q
);
570 static void fst_process_int_work_q(unsigned long work_q
);
572 static DECLARE_TASKLET(fst_tx_task
, fst_process_tx_work_q
, 0);
573 static DECLARE_TASKLET(fst_int_task
, fst_process_int_work_q
, 0);
575 static struct fst_card_info
*fst_card_array
[FST_MAX_CARDS
];
576 static spinlock_t fst_work_q_lock
;
577 static u64 fst_work_txq
;
578 static u64 fst_work_intq
;
581 fst_q_work_item(u64
* queue
, int card_index
)
587 * Grab the queue exclusively
589 spin_lock_irqsave(&fst_work_q_lock
, flags
);
592 * Making an entry in the queue is simply a matter of setting
593 * a bit for the card indicating that there is work to do in the
594 * bottom half for the card. Note the limitation of 64 cards.
595 * That ought to be enough
597 mask
= 1 << card_index
;
599 spin_unlock_irqrestore(&fst_work_q_lock
, flags
);
603 fst_process_tx_work_q(unsigned long /*void **/work_q
)
610 * Grab the queue exclusively
612 dbg(DBG_TX
, "fst_process_tx_work_q\n");
613 spin_lock_irqsave(&fst_work_q_lock
, flags
);
614 work_txq
= fst_work_txq
;
616 spin_unlock_irqrestore(&fst_work_q_lock
, flags
);
619 * Call the bottom half for each card with work waiting
621 for (i
= 0; i
< FST_MAX_CARDS
; i
++) {
622 if (work_txq
& 0x01) {
623 if (fst_card_array
[i
] != NULL
) {
624 dbg(DBG_TX
, "Calling tx bh for card %d\n", i
);
625 do_bottom_half_tx(fst_card_array
[i
]);
628 work_txq
= work_txq
>> 1;
633 fst_process_int_work_q(unsigned long /*void **/work_q
)
640 * Grab the queue exclusively
642 dbg(DBG_INTR
, "fst_process_int_work_q\n");
643 spin_lock_irqsave(&fst_work_q_lock
, flags
);
644 work_intq
= fst_work_intq
;
646 spin_unlock_irqrestore(&fst_work_q_lock
, flags
);
649 * Call the bottom half for each card with work waiting
651 for (i
= 0; i
< FST_MAX_CARDS
; i
++) {
652 if (work_intq
& 0x01) {
653 if (fst_card_array
[i
] != NULL
) {
655 "Calling rx & tx bh for card %d\n", i
);
656 do_bottom_half_rx(fst_card_array
[i
]);
657 do_bottom_half_tx(fst_card_array
[i
]);
660 work_intq
= work_intq
>> 1;
664 /* Card control functions
665 * ======================
667 /* Place the processor in reset state
669 * Used to be a simple write to card control space but a glitch in the latest
670 * AMD Am186CH processor means that we now have to do it by asserting and de-
671 * asserting the PLX chip PCI Adapter Software Reset. Bit 30 in CNTRL register
672 * at offset 9052_CNTRL. Note the updates for the TXU.
675 fst_cpureset(struct fst_card_info
*card
)
677 unsigned char interrupt_line_register
;
678 unsigned long j
= jiffies
+ 1;
681 if (card
->family
== FST_FAMILY_TXU
) {
682 if (pci_read_config_byte
683 (card
->device
, PCI_INTERRUPT_LINE
, &interrupt_line_register
)) {
685 "Error in reading interrupt line register\n");
688 * Assert PLX software reset and Am186 hardware reset
689 * and then deassert the PLX software reset but 186 still in reset
691 outw(0x440f, card
->pci_conf
+ CNTRL_9054
+ 2);
692 outw(0x040f, card
->pci_conf
+ CNTRL_9054
+ 2);
694 * We are delaying here to allow the 9054 to reset itself
699 outw(0x240f, card
->pci_conf
+ CNTRL_9054
+ 2);
701 * We are delaying here to allow the 9054 to reload its eeprom
706 outw(0x040f, card
->pci_conf
+ CNTRL_9054
+ 2);
708 if (pci_write_config_byte
709 (card
->device
, PCI_INTERRUPT_LINE
, interrupt_line_register
)) {
711 "Error in writing interrupt line register\n");
715 regval
= inl(card
->pci_conf
+ CNTRL_9052
);
717 outl(regval
| 0x40000000, card
->pci_conf
+ CNTRL_9052
);
718 outl(regval
& ~0x40000000, card
->pci_conf
+ CNTRL_9052
);
722 /* Release the processor from reset
725 fst_cpurelease(struct fst_card_info
*card
)
727 if (card
->family
== FST_FAMILY_TXU
) {
729 * Force posted writes to complete
731 (void) readb(card
->mem
);
734 * Release LRESET DO = 1
735 * Then release Local Hold, DO = 1
737 outw(0x040e, card
->pci_conf
+ CNTRL_9054
+ 2);
738 outw(0x040f, card
->pci_conf
+ CNTRL_9054
+ 2);
740 (void) readb(card
->ctlmem
);
744 /* Clear the cards interrupt flag
747 fst_clear_intr(struct fst_card_info
*card
)
749 if (card
->family
== FST_FAMILY_TXU
) {
750 (void) readb(card
->ctlmem
);
752 /* Poke the appropriate PLX chip register (same as enabling interrupts)
754 outw(0x0543, card
->pci_conf
+ INTCSR_9052
);
758 /* Enable card interrupts
761 fst_enable_intr(struct fst_card_info
*card
)
763 if (card
->family
== FST_FAMILY_TXU
) {
764 outl(0x0f0c0900, card
->pci_conf
+ INTCSR_9054
);
766 outw(0x0543, card
->pci_conf
+ INTCSR_9052
);
770 /* Disable card interrupts
773 fst_disable_intr(struct fst_card_info
*card
)
775 if (card
->family
== FST_FAMILY_TXU
) {
776 outl(0x00000000, card
->pci_conf
+ INTCSR_9054
);
778 outw(0x0000, card
->pci_conf
+ INTCSR_9052
);
782 /* Process the result of trying to pass a received frame up the stack
785 fst_process_rx_status(int rx_status
, char *name
)
798 dbg(DBG_ASS
, "%s: Receive Low Congestion\n", name
);
804 dbg(DBG_ASS
, "%s: Receive Moderate Congestion\n", name
);
810 dbg(DBG_ASS
, "%s: Receive High Congestion\n", name
);
816 dbg(DBG_ASS
, "%s: Received packet dropped\n", name
);
822 /* Initilaise DMA for PLX 9054
825 fst_init_dma(struct fst_card_info
*card
)
828 * This is only required for the PLX 9054
830 if (card
->family
== FST_FAMILY_TXU
) {
831 pci_set_master(card
->device
);
832 outl(0x00020441, card
->pci_conf
+ DMAMODE0
);
833 outl(0x00020441, card
->pci_conf
+ DMAMODE1
);
834 outl(0x0, card
->pci_conf
+ DMATHR
);
838 /* Tx dma complete interrupt
841 fst_tx_dma_complete(struct fst_card_info
*card
, struct fst_port_info
*port
,
844 struct net_device
*dev
= port_to_dev(port
);
847 * Everything is now set, just tell the card to go
849 dbg(DBG_TX
, "fst_tx_dma_complete\n");
850 FST_WRB(card
, txDescrRing
[port
->index
][txpos
].bits
,
851 DMA_OWN
| TX_STP
| TX_ENP
);
852 dev
->stats
.tx_packets
++;
853 dev
->stats
.tx_bytes
+= len
;
854 dev
->trans_start
= jiffies
;
858 * Mark it for our own raw sockets interface
860 static __be16
farsync_type_trans(struct sk_buff
*skb
, struct net_device
*dev
)
863 skb_reset_mac_header(skb
);
864 skb
->pkt_type
= PACKET_HOST
;
865 return htons(ETH_P_CUST
);
868 /* Rx dma complete interrupt
871 fst_rx_dma_complete(struct fst_card_info
*card
, struct fst_port_info
*port
,
872 int len
, struct sk_buff
*skb
, int rxp
)
874 struct net_device
*dev
= port_to_dev(port
);
878 dbg(DBG_TX
, "fst_rx_dma_complete\n");
880 memcpy(skb_put(skb
, len
), card
->rx_dma_handle_host
, len
);
882 /* Reset buffer descriptor */
883 FST_WRB(card
, rxDescrRing
[pi
][rxp
].bits
, DMA_OWN
);
886 dev
->stats
.rx_packets
++;
887 dev
->stats
.rx_bytes
+= len
;
890 dbg(DBG_RX
, "Pushing the frame up the stack\n");
891 if (port
->mode
== FST_RAW
)
892 skb
->protocol
= farsync_type_trans(skb
, dev
);
894 skb
->protocol
= hdlc_type_trans(skb
, dev
);
895 rx_status
= netif_rx(skb
);
896 fst_process_rx_status(rx_status
, port_to_dev(port
)->name
);
897 if (rx_status
== NET_RX_DROP
)
898 dev
->stats
.rx_dropped
++;
899 dev
->last_rx
= jiffies
;
903 * Receive a frame through the DMA
906 fst_rx_dma(struct fst_card_info
*card
, unsigned char *skb
,
907 unsigned char *mem
, int len
)
910 * This routine will setup the DMA and start it
913 dbg(DBG_RX
, "In fst_rx_dma %p %p %d\n", skb
, mem
, len
);
914 if (card
->dmarx_in_progress
) {
915 dbg(DBG_ASS
, "In fst_rx_dma while dma in progress\n");
918 outl((unsigned long) skb
, card
->pci_conf
+ DMAPADR0
); /* Copy to here */
919 outl((unsigned long) mem
, card
->pci_conf
+ DMALADR0
); /* from here */
920 outl(len
, card
->pci_conf
+ DMASIZ0
); /* for this length */
921 outl(0x00000000c, card
->pci_conf
+ DMADPR0
); /* In this direction */
924 * We use the dmarx_in_progress flag to flag the channel as busy
926 card
->dmarx_in_progress
= 1;
927 outb(0x03, card
->pci_conf
+ DMACSR0
); /* Start the transfer */
931 * Send a frame through the DMA
934 fst_tx_dma(struct fst_card_info
*card
, unsigned char *skb
,
935 unsigned char *mem
, int len
)
938 * This routine will setup the DMA and start it.
941 dbg(DBG_TX
, "In fst_tx_dma %p %p %d\n", skb
, mem
, len
);
942 if (card
->dmatx_in_progress
) {
943 dbg(DBG_ASS
, "In fst_tx_dma while dma in progress\n");
946 outl((unsigned long) skb
, card
->pci_conf
+ DMAPADR1
); /* Copy from here */
947 outl((unsigned long) mem
, card
->pci_conf
+ DMALADR1
); /* to here */
948 outl(len
, card
->pci_conf
+ DMASIZ1
); /* for this length */
949 outl(0x000000004, card
->pci_conf
+ DMADPR1
); /* In this direction */
952 * We use the dmatx_in_progress to flag the channel as busy
954 card
->dmatx_in_progress
= 1;
955 outb(0x03, card
->pci_conf
+ DMACSR1
); /* Start the transfer */
958 /* Issue a Mailbox command for a port.
959 * Note we issue them on a fire and forget basis, not expecting to see an
960 * error and not waiting for completion.
963 fst_issue_cmd(struct fst_port_info
*port
, unsigned short cmd
)
965 struct fst_card_info
*card
;
966 unsigned short mbval
;
971 spin_lock_irqsave(&card
->card_lock
, flags
);
972 mbval
= FST_RDW(card
, portMailbox
[port
->index
][0]);
975 /* Wait for any previous command to complete */
976 while (mbval
> NAK
) {
977 spin_unlock_irqrestore(&card
->card_lock
, flags
);
978 schedule_timeout_uninterruptible(1);
979 spin_lock_irqsave(&card
->card_lock
, flags
);
981 if (++safety
> 2000) {
982 printk_err("Mailbox safety timeout\n");
986 mbval
= FST_RDW(card
, portMailbox
[port
->index
][0]);
989 dbg(DBG_CMD
, "Mailbox clear after %d jiffies\n", safety
);
992 dbg(DBG_CMD
, "issue_cmd: previous command was NAK'd\n");
995 FST_WRW(card
, portMailbox
[port
->index
][0], cmd
);
997 if (cmd
== ABORTTX
|| cmd
== STARTPORT
) {
1003 spin_unlock_irqrestore(&card
->card_lock
, flags
);
1006 /* Port output signals control
1009 fst_op_raise(struct fst_port_info
*port
, unsigned int outputs
)
1011 outputs
|= FST_RDL(port
->card
, v24OpSts
[port
->index
]);
1012 FST_WRL(port
->card
, v24OpSts
[port
->index
], outputs
);
1015 fst_issue_cmd(port
, SETV24O
);
1019 fst_op_lower(struct fst_port_info
*port
, unsigned int outputs
)
1021 outputs
= ~outputs
& FST_RDL(port
->card
, v24OpSts
[port
->index
]);
1022 FST_WRL(port
->card
, v24OpSts
[port
->index
], outputs
);
1025 fst_issue_cmd(port
, SETV24O
);
1029 * Setup port Rx buffers
1032 fst_rx_config(struct fst_port_info
*port
)
1036 unsigned int offset
;
1037 unsigned long flags
;
1038 struct fst_card_info
*card
;
1042 spin_lock_irqsave(&card
->card_lock
, flags
);
1043 for (i
= 0; i
< NUM_RX_BUFFER
; i
++) {
1044 offset
= BUF_OFFSET(rxBuffer
[pi
][i
][0]);
1046 FST_WRW(card
, rxDescrRing
[pi
][i
].ladr
, (u16
) offset
);
1047 FST_WRB(card
, rxDescrRing
[pi
][i
].hadr
, (u8
) (offset
>> 16));
1048 FST_WRW(card
, rxDescrRing
[pi
][i
].bcnt
, cnv_bcnt(LEN_RX_BUFFER
));
1049 FST_WRW(card
, rxDescrRing
[pi
][i
].mcnt
, LEN_RX_BUFFER
);
1050 FST_WRB(card
, rxDescrRing
[pi
][i
].bits
, DMA_OWN
);
1053 spin_unlock_irqrestore(&card
->card_lock
, flags
);
1057 * Setup port Tx buffers
1060 fst_tx_config(struct fst_port_info
*port
)
1064 unsigned int offset
;
1065 unsigned long flags
;
1066 struct fst_card_info
*card
;
1070 spin_lock_irqsave(&card
->card_lock
, flags
);
1071 for (i
= 0; i
< NUM_TX_BUFFER
; i
++) {
1072 offset
= BUF_OFFSET(txBuffer
[pi
][i
][0]);
1074 FST_WRW(card
, txDescrRing
[pi
][i
].ladr
, (u16
) offset
);
1075 FST_WRB(card
, txDescrRing
[pi
][i
].hadr
, (u8
) (offset
>> 16));
1076 FST_WRW(card
, txDescrRing
[pi
][i
].bcnt
, 0);
1077 FST_WRB(card
, txDescrRing
[pi
][i
].bits
, 0);
1082 spin_unlock_irqrestore(&card
->card_lock
, flags
);
1085 /* TE1 Alarm change interrupt event
1088 fst_intr_te1_alarm(struct fst_card_info
*card
, struct fst_port_info
*port
)
1094 los
= FST_RDB(card
, suStatus
.lossOfSignal
);
1095 rra
= FST_RDB(card
, suStatus
.receiveRemoteAlarm
);
1096 ais
= FST_RDB(card
, suStatus
.alarmIndicationSignal
);
1102 if (netif_carrier_ok(port_to_dev(port
))) {
1103 dbg(DBG_INTR
, "Net carrier off\n");
1104 netif_carrier_off(port_to_dev(port
));
1110 if (!netif_carrier_ok(port_to_dev(port
))) {
1111 dbg(DBG_INTR
, "Net carrier on\n");
1112 netif_carrier_on(port_to_dev(port
));
1117 dbg(DBG_INTR
, "Assert LOS Alarm\n");
1119 dbg(DBG_INTR
, "De-assert LOS Alarm\n");
1121 dbg(DBG_INTR
, "Assert RRA Alarm\n");
1123 dbg(DBG_INTR
, "De-assert RRA Alarm\n");
1126 dbg(DBG_INTR
, "Assert AIS Alarm\n");
1128 dbg(DBG_INTR
, "De-assert AIS Alarm\n");
1131 /* Control signal change interrupt event
1134 fst_intr_ctlchg(struct fst_card_info
*card
, struct fst_port_info
*port
)
1138 signals
= FST_RDL(card
, v24DebouncedSts
[port
->index
]);
1140 if (signals
& (((port
->hwif
== X21
) || (port
->hwif
== X21D
))
1141 ? IPSTS_INDICATE
: IPSTS_DCD
)) {
1142 if (!netif_carrier_ok(port_to_dev(port
))) {
1143 dbg(DBG_INTR
, "DCD active\n");
1144 netif_carrier_on(port_to_dev(port
));
1147 if (netif_carrier_ok(port_to_dev(port
))) {
1148 dbg(DBG_INTR
, "DCD lost\n");
1149 netif_carrier_off(port_to_dev(port
));
1157 fst_log_rx_error(struct fst_card_info
*card
, struct fst_port_info
*port
,
1158 unsigned char dmabits
, int rxp
, unsigned short len
)
1160 struct net_device
*dev
= port_to_dev(port
);
1163 * Increment the appropriate error counter
1165 dev
->stats
.rx_errors
++;
1166 if (dmabits
& RX_OFLO
) {
1167 dev
->stats
.rx_fifo_errors
++;
1168 dbg(DBG_ASS
, "Rx fifo error on card %d port %d buffer %d\n",
1169 card
->card_no
, port
->index
, rxp
);
1171 if (dmabits
& RX_CRC
) {
1172 dev
->stats
.rx_crc_errors
++;
1173 dbg(DBG_ASS
, "Rx crc error on card %d port %d\n",
1174 card
->card_no
, port
->index
);
1176 if (dmabits
& RX_FRAM
) {
1177 dev
->stats
.rx_frame_errors
++;
1178 dbg(DBG_ASS
, "Rx frame error on card %d port %d\n",
1179 card
->card_no
, port
->index
);
1181 if (dmabits
== (RX_STP
| RX_ENP
)) {
1182 dev
->stats
.rx_length_errors
++;
1183 dbg(DBG_ASS
, "Rx length error (%d) on card %d port %d\n",
1184 len
, card
->card_no
, port
->index
);
1188 /* Rx Error Recovery
1191 fst_recover_rx_error(struct fst_card_info
*card
, struct fst_port_info
*port
,
1192 unsigned char dmabits
, int rxp
, unsigned short len
)
1199 * Discard buffer descriptors until we see the start of the
1200 * next frame. Note that for long frames this could be in
1201 * a subsequent interrupt.
1204 while ((dmabits
& (DMA_OWN
| RX_STP
)) == 0) {
1205 FST_WRB(card
, rxDescrRing
[pi
][rxp
].bits
, DMA_OWN
);
1206 rxp
= (rxp
+1) % NUM_RX_BUFFER
;
1207 if (++i
> NUM_RX_BUFFER
) {
1208 dbg(DBG_ASS
, "intr_rx: Discarding more bufs"
1212 dmabits
= FST_RDB(card
, rxDescrRing
[pi
][rxp
].bits
);
1213 dbg(DBG_ASS
, "DMA Bits of next buffer was %x\n", dmabits
);
1215 dbg(DBG_ASS
, "There were %d subsequent buffers in error\n", i
);
1217 /* Discard the terminal buffer */
1218 if (!(dmabits
& DMA_OWN
)) {
1219 FST_WRB(card
, rxDescrRing
[pi
][rxp
].bits
, DMA_OWN
);
1220 rxp
= (rxp
+1) % NUM_RX_BUFFER
;
1227 /* Rx complete interrupt
1230 fst_intr_rx(struct fst_card_info
*card
, struct fst_port_info
*port
)
1232 unsigned char dmabits
;
1237 struct sk_buff
*skb
;
1238 struct net_device
*dev
= port_to_dev(port
);
1240 /* Check we have a buffer to process */
1243 dmabits
= FST_RDB(card
, rxDescrRing
[pi
][rxp
].bits
);
1244 if (dmabits
& DMA_OWN
) {
1245 dbg(DBG_RX
| DBG_INTR
, "intr_rx: No buffer port %d pos %d\n",
1249 if (card
->dmarx_in_progress
) {
1253 /* Get buffer length */
1254 len
= FST_RDW(card
, rxDescrRing
[pi
][rxp
].mcnt
);
1255 /* Discard the CRC */
1259 * This seems to happen on the TE1 interface sometimes
1260 * so throw the frame away and log the event.
1262 printk_err("Frame received with 0 length. Card %d Port %d\n",
1263 card
->card_no
, port
->index
);
1264 /* Return descriptor to card */
1265 FST_WRB(card
, rxDescrRing
[pi
][rxp
].bits
, DMA_OWN
);
1267 rxp
= (rxp
+1) % NUM_RX_BUFFER
;
1272 /* Check buffer length and for other errors. We insist on one packet
1273 * in one buffer. This simplifies things greatly and since we've
1274 * allocated 8K it shouldn't be a real world limitation
1276 dbg(DBG_RX
, "intr_rx: %d,%d: flags %x len %d\n", pi
, rxp
, dmabits
, len
);
1277 if (dmabits
!= (RX_STP
| RX_ENP
) || len
> LEN_RX_BUFFER
- 2) {
1278 fst_log_rx_error(card
, port
, dmabits
, rxp
, len
);
1279 fst_recover_rx_error(card
, port
, dmabits
, rxp
, len
);
1284 if ((skb
= dev_alloc_skb(len
)) == NULL
) {
1285 dbg(DBG_RX
, "intr_rx: can't allocate buffer\n");
1287 dev
->stats
.rx_dropped
++;
1289 /* Return descriptor to card */
1290 FST_WRB(card
, rxDescrRing
[pi
][rxp
].bits
, DMA_OWN
);
1292 rxp
= (rxp
+1) % NUM_RX_BUFFER
;
1298 * We know the length we need to receive, len.
1299 * It's not worth using the DMA for reads of less than
1303 if ((len
< FST_MIN_DMA_LEN
) || (card
->family
== FST_FAMILY_TXP
)) {
1304 memcpy_fromio(skb_put(skb
, len
),
1305 card
->mem
+ BUF_OFFSET(rxBuffer
[pi
][rxp
][0]),
1308 /* Reset buffer descriptor */
1309 FST_WRB(card
, rxDescrRing
[pi
][rxp
].bits
, DMA_OWN
);
1312 dev
->stats
.rx_packets
++;
1313 dev
->stats
.rx_bytes
+= len
;
1316 dbg(DBG_RX
, "Pushing frame up the stack\n");
1317 if (port
->mode
== FST_RAW
)
1318 skb
->protocol
= farsync_type_trans(skb
, dev
);
1320 skb
->protocol
= hdlc_type_trans(skb
, dev
);
1321 rx_status
= netif_rx(skb
);
1322 fst_process_rx_status(rx_status
, port_to_dev(port
)->name
);
1323 if (rx_status
== NET_RX_DROP
)
1324 dev
->stats
.rx_dropped
++;
1325 dev
->last_rx
= jiffies
;
1327 card
->dma_skb_rx
= skb
;
1328 card
->dma_port_rx
= port
;
1329 card
->dma_len_rx
= len
;
1330 card
->dma_rxpos
= rxp
;
1331 fst_rx_dma(card
, (char *) card
->rx_dma_handle_card
,
1332 (char *) BUF_OFFSET(rxBuffer
[pi
][rxp
][0]), len
);
1334 if (rxp
!= port
->rxpos
) {
1335 dbg(DBG_ASS
, "About to increment rxpos by more than 1\n");
1336 dbg(DBG_ASS
, "rxp = %d rxpos = %d\n", rxp
, port
->rxpos
);
1338 rxp
= (rxp
+1) % NUM_RX_BUFFER
;
1343 * The bottom halfs to the ISR
1348 do_bottom_half_tx(struct fst_card_info
*card
)
1350 struct fst_port_info
*port
;
1353 struct sk_buff
*skb
;
1354 unsigned long flags
;
1355 struct net_device
*dev
;
1358 * Find a free buffer for the transmit
1359 * Step through each port on this card
1362 dbg(DBG_TX
, "do_bottom_half_tx\n");
1363 for (pi
= 0, port
= card
->ports
; pi
< card
->nports
; pi
++, port
++) {
1367 dev
= port_to_dev(port
);
1368 while (!(FST_RDB(card
, txDescrRing
[pi
][port
->txpos
].bits
) &
1370 && !(card
->dmatx_in_progress
)) {
1372 * There doesn't seem to be a txdone event per-se
1373 * We seem to have to deduce it, by checking the DMA_OWN
1374 * bit on the next buffer we think we can use
1376 spin_lock_irqsave(&card
->card_lock
, flags
);
1377 if ((txq_length
= port
->txqe
- port
->txqs
) < 0) {
1379 * This is the case where one has wrapped and the
1380 * maths gives us a negative number
1382 txq_length
= txq_length
+ FST_TXQ_DEPTH
;
1384 spin_unlock_irqrestore(&card
->card_lock
, flags
);
1385 if (txq_length
> 0) {
1387 * There is something to send
1389 spin_lock_irqsave(&card
->card_lock
, flags
);
1390 skb
= port
->txq
[port
->txqs
];
1392 if (port
->txqs
== FST_TXQ_DEPTH
) {
1395 spin_unlock_irqrestore(&card
->card_lock
, flags
);
1397 * copy the data and set the required indicators on the
1400 FST_WRW(card
, txDescrRing
[pi
][port
->txpos
].bcnt
,
1401 cnv_bcnt(skb
->len
));
1402 if ((skb
->len
< FST_MIN_DMA_LEN
)
1403 || (card
->family
== FST_FAMILY_TXP
)) {
1404 /* Enqueue the packet with normal io */
1405 memcpy_toio(card
->mem
+
1406 BUF_OFFSET(txBuffer
[pi
]
1409 skb
->data
, skb
->len
);
1411 txDescrRing
[pi
][port
->txpos
].
1413 DMA_OWN
| TX_STP
| TX_ENP
);
1414 dev
->stats
.tx_packets
++;
1415 dev
->stats
.tx_bytes
+= skb
->len
;
1416 dev
->trans_start
= jiffies
;
1418 /* Or do it through dma */
1419 memcpy(card
->tx_dma_handle_host
,
1420 skb
->data
, skb
->len
);
1421 card
->dma_port_tx
= port
;
1422 card
->dma_len_tx
= skb
->len
;
1423 card
->dma_txpos
= port
->txpos
;
1428 BUF_OFFSET(txBuffer
[pi
]
1432 if (++port
->txpos
>= NUM_TX_BUFFER
)
1435 * If we have flow control on, can we now release it?
1438 if (txq_length
< fst_txq_low
) {
1439 netif_wake_queue(port_to_dev
1447 * Nothing to send so break out of the while loop
1456 do_bottom_half_rx(struct fst_card_info
*card
)
1458 struct fst_port_info
*port
;
1462 /* Check for rx completions on all ports on this card */
1463 dbg(DBG_RX
, "do_bottom_half_rx\n");
1464 for (pi
= 0, port
= card
->ports
; pi
< card
->nports
; pi
++, port
++) {
1468 while (!(FST_RDB(card
, rxDescrRing
[pi
][port
->rxpos
].bits
)
1469 & DMA_OWN
) && !(card
->dmarx_in_progress
)) {
1470 if (rx_count
> fst_max_reads
) {
1472 * Don't spend forever in receive processing
1473 * Schedule another event
1475 fst_q_work_item(&fst_work_intq
, card
->card_no
);
1476 tasklet_schedule(&fst_int_task
);
1477 break; /* Leave the loop */
1479 fst_intr_rx(card
, port
);
1486 * The interrupt service routine
1487 * Dev_id is our fst_card_info pointer
1490 fst_intr(int dummy
, void *dev_id
)
1492 struct fst_card_info
*card
= dev_id
;
1493 struct fst_port_info
*port
;
1494 int rdidx
; /* Event buffer indices */
1496 int event
; /* Actual event for processing */
1497 unsigned int dma_intcsr
= 0;
1498 unsigned int do_card_interrupt
;
1499 unsigned int int_retry_count
;
1502 * Check to see if the interrupt was for this card
1504 * Note that the call to clear the interrupt is important
1506 dbg(DBG_INTR
, "intr: %d %p\n", card
->irq
, card
);
1507 if (card
->state
!= FST_RUNNING
) {
1509 ("Interrupt received for card %d in a non running state (%d)\n",
1510 card
->card_no
, card
->state
);
1513 * It is possible to really be running, i.e. we have re-loaded
1515 * Clear and reprime the interrupt source
1517 fst_clear_intr(card
);
1521 /* Clear and reprime the interrupt source */
1522 fst_clear_intr(card
);
1525 * Is the interrupt for this card (handshake == 1)
1527 do_card_interrupt
= 0;
1528 if (FST_RDB(card
, interruptHandshake
) == 1) {
1529 do_card_interrupt
+= FST_CARD_INT
;
1530 /* Set the software acknowledge */
1531 FST_WRB(card
, interruptHandshake
, 0xEE);
1533 if (card
->family
== FST_FAMILY_TXU
) {
1535 * Is it a DMA Interrupt
1537 dma_intcsr
= inl(card
->pci_conf
+ INTCSR_9054
);
1538 if (dma_intcsr
& 0x00200000) {
1540 * DMA Channel 0 (Rx transfer complete)
1542 dbg(DBG_RX
, "DMA Rx xfer complete\n");
1543 outb(0x8, card
->pci_conf
+ DMACSR0
);
1544 fst_rx_dma_complete(card
, card
->dma_port_rx
,
1545 card
->dma_len_rx
, card
->dma_skb_rx
,
1547 card
->dmarx_in_progress
= 0;
1548 do_card_interrupt
+= FST_RX_DMA_INT
;
1550 if (dma_intcsr
& 0x00400000) {
1552 * DMA Channel 1 (Tx transfer complete)
1554 dbg(DBG_TX
, "DMA Tx xfer complete\n");
1555 outb(0x8, card
->pci_conf
+ DMACSR1
);
1556 fst_tx_dma_complete(card
, card
->dma_port_tx
,
1557 card
->dma_len_tx
, card
->dma_txpos
);
1558 card
->dmatx_in_progress
= 0;
1559 do_card_interrupt
+= FST_TX_DMA_INT
;
1564 * Have we been missing Interrupts
1566 int_retry_count
= FST_RDL(card
, interruptRetryCount
);
1567 if (int_retry_count
) {
1568 dbg(DBG_ASS
, "Card %d int_retry_count is %d\n",
1569 card
->card_no
, int_retry_count
);
1570 FST_WRL(card
, interruptRetryCount
, 0);
1573 if (!do_card_interrupt
) {
1577 /* Scehdule the bottom half of the ISR */
1578 fst_q_work_item(&fst_work_intq
, card
->card_no
);
1579 tasklet_schedule(&fst_int_task
);
1581 /* Drain the event queue */
1582 rdidx
= FST_RDB(card
, interruptEvent
.rdindex
) & 0x1f;
1583 wridx
= FST_RDB(card
, interruptEvent
.wrindex
) & 0x1f;
1584 while (rdidx
!= wridx
) {
1585 event
= FST_RDB(card
, interruptEvent
.evntbuff
[rdidx
]);
1586 port
= &card
->ports
[event
& 0x03];
1588 dbg(DBG_INTR
, "Processing Interrupt event: %x\n", event
);
1592 dbg(DBG_INTR
, "TE1 Alarm intr\n");
1594 fst_intr_te1_alarm(card
, port
);
1602 fst_intr_ctlchg(card
, port
);
1609 dbg(DBG_TX
, "Abort complete port %d\n", port
->index
);
1616 /* Difficult to see how we'd get this given that we
1617 * always load up the entire packet for DMA.
1619 dbg(DBG_TX
, "Tx underflow port %d\n", port
->index
);
1620 port_to_dev(port
)->stats
.tx_errors
++;
1621 port_to_dev(port
)->stats
.tx_fifo_errors
++;
1622 dbg(DBG_ASS
, "Tx underflow on card %d port %d\n",
1623 card
->card_no
, port
->index
);
1627 dbg(DBG_INIT
, "Card init OK intr\n");
1631 dbg(DBG_INIT
, "Card init FAILED intr\n");
1632 card
->state
= FST_IFAILED
;
1636 printk_err("intr: unknown card event %d. ignored\n",
1641 /* Bump and wrap the index */
1642 if (++rdidx
>= MAX_CIRBUFF
)
1645 FST_WRB(card
, interruptEvent
.rdindex
, rdidx
);
1649 /* Check that the shared memory configuration is one that we can handle
1650 * and that some basic parameters are correct
1653 check_started_ok(struct fst_card_info
*card
)
1657 /* Check structure version and end marker */
1658 if (FST_RDW(card
, smcVersion
) != SMC_VERSION
) {
1659 printk_err("Bad shared memory version %d expected %d\n",
1660 FST_RDW(card
, smcVersion
), SMC_VERSION
);
1661 card
->state
= FST_BADVERSION
;
1664 if (FST_RDL(card
, endOfSmcSignature
) != END_SIG
) {
1665 printk_err("Missing shared memory signature\n");
1666 card
->state
= FST_BADVERSION
;
1669 /* Firmware status flag, 0x00 = initialising, 0x01 = OK, 0xFF = fail */
1670 if ((i
= FST_RDB(card
, taskStatus
)) == 0x01) {
1671 card
->state
= FST_RUNNING
;
1672 } else if (i
== 0xFF) {
1673 printk_err("Firmware initialisation failed. Card halted\n");
1674 card
->state
= FST_HALTED
;
1676 } else if (i
!= 0x00) {
1677 printk_err("Unknown firmware status 0x%x\n", i
);
1678 card
->state
= FST_HALTED
;
1682 /* Finally check the number of ports reported by firmware against the
1683 * number we assumed at card detection. Should never happen with
1684 * existing firmware etc so we just report it for the moment.
1686 if (FST_RDL(card
, numberOfPorts
) != card
->nports
) {
1687 printk_warn("Port count mismatch on card %d."
1688 " Firmware thinks %d we say %d\n", card
->card_no
,
1689 FST_RDL(card
, numberOfPorts
), card
->nports
);
1694 set_conf_from_info(struct fst_card_info
*card
, struct fst_port_info
*port
,
1695 struct fstioc_info
*info
)
1698 unsigned char my_framing
;
1700 /* Set things according to the user set valid flags
1701 * Several of the old options have been invalidated/replaced by the
1702 * generic hdlc package.
1705 if (info
->valid
& FSTVAL_PROTO
) {
1706 if (info
->proto
== FST_RAW
)
1707 port
->mode
= FST_RAW
;
1709 port
->mode
= FST_GEN_HDLC
;
1712 if (info
->valid
& FSTVAL_CABLE
)
1715 if (info
->valid
& FSTVAL_SPEED
)
1718 if (info
->valid
& FSTVAL_PHASE
)
1719 FST_WRB(card
, portConfig
[port
->index
].invertClock
,
1721 if (info
->valid
& FSTVAL_MODE
)
1722 FST_WRW(card
, cardMode
, info
->cardMode
);
1723 if (info
->valid
& FSTVAL_TE1
) {
1724 FST_WRL(card
, suConfig
.dataRate
, info
->lineSpeed
);
1725 FST_WRB(card
, suConfig
.clocking
, info
->clockSource
);
1726 my_framing
= FRAMING_E1
;
1727 if (info
->framing
== E1
)
1728 my_framing
= FRAMING_E1
;
1729 if (info
->framing
== T1
)
1730 my_framing
= FRAMING_T1
;
1731 if (info
->framing
== J1
)
1732 my_framing
= FRAMING_J1
;
1733 FST_WRB(card
, suConfig
.framing
, my_framing
);
1734 FST_WRB(card
, suConfig
.structure
, info
->structure
);
1735 FST_WRB(card
, suConfig
.interface
, info
->interface
);
1736 FST_WRB(card
, suConfig
.coding
, info
->coding
);
1737 FST_WRB(card
, suConfig
.lineBuildOut
, info
->lineBuildOut
);
1738 FST_WRB(card
, suConfig
.equalizer
, info
->equalizer
);
1739 FST_WRB(card
, suConfig
.transparentMode
, info
->transparentMode
);
1740 FST_WRB(card
, suConfig
.loopMode
, info
->loopMode
);
1741 FST_WRB(card
, suConfig
.range
, info
->range
);
1742 FST_WRB(card
, suConfig
.txBufferMode
, info
->txBufferMode
);
1743 FST_WRB(card
, suConfig
.rxBufferMode
, info
->rxBufferMode
);
1744 FST_WRB(card
, suConfig
.startingSlot
, info
->startingSlot
);
1745 FST_WRB(card
, suConfig
.losThreshold
, info
->losThreshold
);
1747 FST_WRB(card
, suConfig
.enableIdleCode
, 1);
1749 FST_WRB(card
, suConfig
.enableIdleCode
, 0);
1750 FST_WRB(card
, suConfig
.idleCode
, info
->idleCode
);
1752 if (info
->valid
& FSTVAL_TE1
) {
1753 printk("Setting TE1 data\n");
1754 printk("Line Speed = %d\n", info
->lineSpeed
);
1755 printk("Start slot = %d\n", info
->startingSlot
);
1756 printk("Clock source = %d\n", info
->clockSource
);
1757 printk("Framing = %d\n", my_framing
);
1758 printk("Structure = %d\n", info
->structure
);
1759 printk("interface = %d\n", info
->interface
);
1760 printk("Coding = %d\n", info
->coding
);
1761 printk("Line build out = %d\n", info
->lineBuildOut
);
1762 printk("Equaliser = %d\n", info
->equalizer
);
1763 printk("Transparent mode = %d\n",
1764 info
->transparentMode
);
1765 printk("Loop mode = %d\n", info
->loopMode
);
1766 printk("Range = %d\n", info
->range
);
1767 printk("Tx Buffer mode = %d\n", info
->txBufferMode
);
1768 printk("Rx Buffer mode = %d\n", info
->rxBufferMode
);
1769 printk("LOS Threshold = %d\n", info
->losThreshold
);
1770 printk("Idle Code = %d\n", info
->idleCode
);
1775 if (info
->valid
& FSTVAL_DEBUG
) {
1776 fst_debug_mask
= info
->debug
;
1784 gather_conf_info(struct fst_card_info
*card
, struct fst_port_info
*port
,
1785 struct fstioc_info
*info
)
1789 memset(info
, 0, sizeof (struct fstioc_info
));
1792 info
->kernelVersion
= LINUX_VERSION_CODE
;
1793 info
->nports
= card
->nports
;
1794 info
->type
= card
->type
;
1795 info
->state
= card
->state
;
1796 info
->proto
= FST_GEN_HDLC
;
1799 info
->debug
= fst_debug_mask
;
1802 /* Only mark information as valid if card is running.
1803 * Copy the data anyway in case it is useful for diagnostics
1805 info
->valid
= ((card
->state
== FST_RUNNING
) ? FSTVAL_ALL
: FSTVAL_CARD
)
1811 info
->lineInterface
= FST_RDW(card
, portConfig
[i
].lineInterface
);
1812 info
->internalClock
= FST_RDB(card
, portConfig
[i
].internalClock
);
1813 info
->lineSpeed
= FST_RDL(card
, portConfig
[i
].lineSpeed
);
1814 info
->invertClock
= FST_RDB(card
, portConfig
[i
].invertClock
);
1815 info
->v24IpSts
= FST_RDL(card
, v24IpSts
[i
]);
1816 info
->v24OpSts
= FST_RDL(card
, v24OpSts
[i
]);
1817 info
->clockStatus
= FST_RDW(card
, clockStatus
[i
]);
1818 info
->cableStatus
= FST_RDW(card
, cableStatus
);
1819 info
->cardMode
= FST_RDW(card
, cardMode
);
1820 info
->smcFirmwareVersion
= FST_RDL(card
, smcFirmwareVersion
);
1823 * The T2U can report cable presence for both A or B
1824 * in bits 0 and 1 of cableStatus. See which port we are and
1827 if (card
->family
== FST_FAMILY_TXU
) {
1828 if (port
->index
== 0) {
1832 info
->cableStatus
= info
->cableStatus
& 1;
1837 info
->cableStatus
= info
->cableStatus
>> 1;
1838 info
->cableStatus
= info
->cableStatus
& 1;
1842 * Some additional bits if we are TE1
1844 if (card
->type
== FST_TYPE_TE1
) {
1845 info
->lineSpeed
= FST_RDL(card
, suConfig
.dataRate
);
1846 info
->clockSource
= FST_RDB(card
, suConfig
.clocking
);
1847 info
->framing
= FST_RDB(card
, suConfig
.framing
);
1848 info
->structure
= FST_RDB(card
, suConfig
.structure
);
1849 info
->interface
= FST_RDB(card
, suConfig
.interface
);
1850 info
->coding
= FST_RDB(card
, suConfig
.coding
);
1851 info
->lineBuildOut
= FST_RDB(card
, suConfig
.lineBuildOut
);
1852 info
->equalizer
= FST_RDB(card
, suConfig
.equalizer
);
1853 info
->loopMode
= FST_RDB(card
, suConfig
.loopMode
);
1854 info
->range
= FST_RDB(card
, suConfig
.range
);
1855 info
->txBufferMode
= FST_RDB(card
, suConfig
.txBufferMode
);
1856 info
->rxBufferMode
= FST_RDB(card
, suConfig
.rxBufferMode
);
1857 info
->startingSlot
= FST_RDB(card
, suConfig
.startingSlot
);
1858 info
->losThreshold
= FST_RDB(card
, suConfig
.losThreshold
);
1859 if (FST_RDB(card
, suConfig
.enableIdleCode
))
1860 info
->idleCode
= FST_RDB(card
, suConfig
.idleCode
);
1863 info
->receiveBufferDelay
=
1864 FST_RDL(card
, suStatus
.receiveBufferDelay
);
1865 info
->framingErrorCount
=
1866 FST_RDL(card
, suStatus
.framingErrorCount
);
1867 info
->codeViolationCount
=
1868 FST_RDL(card
, suStatus
.codeViolationCount
);
1869 info
->crcErrorCount
= FST_RDL(card
, suStatus
.crcErrorCount
);
1870 info
->lineAttenuation
= FST_RDL(card
, suStatus
.lineAttenuation
);
1871 info
->lossOfSignal
= FST_RDB(card
, suStatus
.lossOfSignal
);
1872 info
->receiveRemoteAlarm
=
1873 FST_RDB(card
, suStatus
.receiveRemoteAlarm
);
1874 info
->alarmIndicationSignal
=
1875 FST_RDB(card
, suStatus
.alarmIndicationSignal
);
1880 fst_set_iface(struct fst_card_info
*card
, struct fst_port_info
*port
,
1883 sync_serial_settings sync
;
1886 if (ifr
->ifr_settings
.size
!= sizeof (sync
)) {
1891 (&sync
, ifr
->ifr_settings
.ifs_ifsu
.sync
, sizeof (sync
))) {
1900 switch (ifr
->ifr_settings
.type
) {
1902 FST_WRW(card
, portConfig
[i
].lineInterface
, V35
);
1907 FST_WRW(card
, portConfig
[i
].lineInterface
, V24
);
1912 FST_WRW(card
, portConfig
[i
].lineInterface
, X21
);
1917 FST_WRW(card
, portConfig
[i
].lineInterface
, X21D
);
1922 FST_WRW(card
, portConfig
[i
].lineInterface
, T1
);
1927 FST_WRW(card
, portConfig
[i
].lineInterface
, E1
);
1931 case IF_IFACE_SYNC_SERIAL
:
1938 switch (sync
.clock_type
) {
1940 FST_WRB(card
, portConfig
[i
].internalClock
, EXTCLK
);
1944 FST_WRB(card
, portConfig
[i
].internalClock
, INTCLK
);
1950 FST_WRL(card
, portConfig
[i
].lineSpeed
, sync
.clock_rate
);
1955 fst_get_iface(struct fst_card_info
*card
, struct fst_port_info
*port
,
1958 sync_serial_settings sync
;
1961 /* First check what line type is set, we'll default to reporting X.21
1962 * if nothing is set as IF_IFACE_SYNC_SERIAL implies it can't be
1965 switch (port
->hwif
) {
1967 ifr
->ifr_settings
.type
= IF_IFACE_E1
;
1970 ifr
->ifr_settings
.type
= IF_IFACE_T1
;
1973 ifr
->ifr_settings
.type
= IF_IFACE_V35
;
1976 ifr
->ifr_settings
.type
= IF_IFACE_V24
;
1979 ifr
->ifr_settings
.type
= IF_IFACE_X21D
;
1983 ifr
->ifr_settings
.type
= IF_IFACE_X21
;
1986 if (ifr
->ifr_settings
.size
== 0) {
1987 return 0; /* only type requested */
1989 if (ifr
->ifr_settings
.size
< sizeof (sync
)) {
1994 sync
.clock_rate
= FST_RDL(card
, portConfig
[i
].lineSpeed
);
1995 /* Lucky card and linux use same encoding here */
1996 sync
.clock_type
= FST_RDB(card
, portConfig
[i
].internalClock
) ==
1997 INTCLK
? CLOCK_INT
: CLOCK_EXT
;
2000 if (copy_to_user(ifr
->ifr_settings
.ifs_ifsu
.sync
, &sync
, sizeof (sync
))) {
2004 ifr
->ifr_settings
.size
= sizeof (sync
);
2009 fst_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
2011 struct fst_card_info
*card
;
2012 struct fst_port_info
*port
;
2013 struct fstioc_write wrthdr
;
2014 struct fstioc_info info
;
2015 unsigned long flags
;
2018 dbg(DBG_IOCTL
, "ioctl: %x, %p\n", cmd
, ifr
->ifr_data
);
2020 port
= dev_to_port(dev
);
2023 if (!capable(CAP_NET_ADMIN
))
2029 card
->state
= FST_RESET
;
2033 fst_cpurelease(card
);
2034 card
->state
= FST_STARTING
;
2037 case FSTWRITE
: /* Code write (download) */
2039 /* First copy in the header with the length and offset of data
2042 if (ifr
->ifr_data
== NULL
) {
2045 if (copy_from_user(&wrthdr
, ifr
->ifr_data
,
2046 sizeof (struct fstioc_write
))) {
2050 /* Sanity check the parameters. We don't support partial writes
2051 * when going over the top
2053 if (wrthdr
.size
> FST_MEMSIZE
|| wrthdr
.offset
> FST_MEMSIZE
2054 || wrthdr
.size
+ wrthdr
.offset
> FST_MEMSIZE
) {
2058 /* Now copy the data to the card. */
2060 buf
= kmalloc(wrthdr
.size
, GFP_KERNEL
);
2064 if (copy_from_user(buf
,
2065 ifr
->ifr_data
+ sizeof (struct fstioc_write
),
2071 memcpy_toio(card
->mem
+ wrthdr
.offset
, buf
, wrthdr
.size
);
2074 /* Writes to the memory of a card in the reset state constitute
2077 if (card
->state
== FST_RESET
) {
2078 card
->state
= FST_DOWNLOAD
;
2084 /* If card has just been started check the shared memory config
2085 * version and marker
2087 if (card
->state
== FST_STARTING
) {
2088 check_started_ok(card
);
2090 /* If everything checked out enable card interrupts */
2091 if (card
->state
== FST_RUNNING
) {
2092 spin_lock_irqsave(&card
->card_lock
, flags
);
2093 fst_enable_intr(card
);
2094 FST_WRB(card
, interruptHandshake
, 0xEE);
2095 spin_unlock_irqrestore(&card
->card_lock
, flags
);
2099 if (ifr
->ifr_data
== NULL
) {
2103 gather_conf_info(card
, port
, &info
);
2105 if (copy_to_user(ifr
->ifr_data
, &info
, sizeof (info
))) {
2113 * Most of the settings have been moved to the generic ioctls
2114 * this just covers debug and board ident now
2117 if (card
->state
!= FST_RUNNING
) {
2119 ("Attempt to configure card %d in non-running state (%d)\n",
2120 card
->card_no
, card
->state
);
2123 if (copy_from_user(&info
, ifr
->ifr_data
, sizeof (info
))) {
2127 return set_conf_from_info(card
, port
, &info
);
2130 switch (ifr
->ifr_settings
.type
) {
2132 return fst_get_iface(card
, port
, ifr
);
2134 case IF_IFACE_SYNC_SERIAL
:
2141 return fst_set_iface(card
, port
, ifr
);
2144 port
->mode
= FST_RAW
;
2148 if (port
->mode
== FST_RAW
) {
2149 ifr
->ifr_settings
.type
= IF_PROTO_RAW
;
2152 return hdlc_ioctl(dev
, ifr
, cmd
);
2155 port
->mode
= FST_GEN_HDLC
;
2156 dbg(DBG_IOCTL
, "Passing this type to hdlc %x\n",
2157 ifr
->ifr_settings
.type
);
2158 return hdlc_ioctl(dev
, ifr
, cmd
);
2162 /* Not one of ours. Pass through to HDLC package */
2163 return hdlc_ioctl(dev
, ifr
, cmd
);
2168 fst_openport(struct fst_port_info
*port
)
2173 /* Only init things if card is actually running. This allows open to
2174 * succeed for downloads etc.
2176 if (port
->card
->state
== FST_RUNNING
) {
2178 dbg(DBG_OPEN
, "open: found port already running\n");
2180 fst_issue_cmd(port
, STOPPORT
);
2184 fst_rx_config(port
);
2185 fst_tx_config(port
);
2186 fst_op_raise(port
, OPSTS_RTS
| OPSTS_DTR
);
2188 fst_issue_cmd(port
, STARTPORT
);
2191 signals
= FST_RDL(port
->card
, v24DebouncedSts
[port
->index
]);
2192 if (signals
& (((port
->hwif
== X21
) || (port
->hwif
== X21D
))
2193 ? IPSTS_INDICATE
: IPSTS_DCD
))
2194 netif_carrier_on(port_to_dev(port
));
2196 netif_carrier_off(port_to_dev(port
));
2198 txq_length
= port
->txqe
- port
->txqs
;
2206 fst_closeport(struct fst_port_info
*port
)
2208 if (port
->card
->state
== FST_RUNNING
) {
2211 fst_op_lower(port
, OPSTS_RTS
| OPSTS_DTR
);
2213 fst_issue_cmd(port
, STOPPORT
);
2215 dbg(DBG_OPEN
, "close: port not running\n");
2221 fst_open(struct net_device
*dev
)
2224 struct fst_port_info
*port
;
2226 port
= dev_to_port(dev
);
2227 if (!try_module_get(THIS_MODULE
))
2230 if (port
->mode
!= FST_RAW
) {
2231 err
= hdlc_open(dev
);
2237 netif_wake_queue(dev
);
2242 fst_close(struct net_device
*dev
)
2244 struct fst_port_info
*port
;
2245 struct fst_card_info
*card
;
2246 unsigned char tx_dma_done
;
2247 unsigned char rx_dma_done
;
2249 port
= dev_to_port(dev
);
2252 tx_dma_done
= inb(card
->pci_conf
+ DMACSR1
);
2253 rx_dma_done
= inb(card
->pci_conf
+ DMACSR0
);
2255 "Port Close: tx_dma_in_progress = %d (%x) rx_dma_in_progress = %d (%x)\n",
2256 card
->dmatx_in_progress
, tx_dma_done
, card
->dmarx_in_progress
,
2259 netif_stop_queue(dev
);
2260 fst_closeport(dev_to_port(dev
));
2261 if (port
->mode
!= FST_RAW
) {
2264 module_put(THIS_MODULE
);
2269 fst_attach(struct net_device
*dev
, unsigned short encoding
, unsigned short parity
)
2272 * Setting currently fixed in FarSync card so we check and forget
2274 if (encoding
!= ENCODING_NRZ
|| parity
!= PARITY_CRC16_PR1_CCITT
)
2280 fst_tx_timeout(struct net_device
*dev
)
2282 struct fst_port_info
*port
;
2283 struct fst_card_info
*card
;
2285 port
= dev_to_port(dev
);
2287 dev
->stats
.tx_errors
++;
2288 dev
->stats
.tx_aborted_errors
++;
2289 dbg(DBG_ASS
, "Tx timeout card %d port %d\n",
2290 card
->card_no
, port
->index
);
2291 fst_issue_cmd(port
, ABORTTX
);
2293 dev
->trans_start
= jiffies
;
2294 netif_wake_queue(dev
);
2299 fst_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
2301 struct fst_card_info
*card
;
2302 struct fst_port_info
*port
;
2303 unsigned long flags
;
2306 port
= dev_to_port(dev
);
2308 dbg(DBG_TX
, "fst_start_xmit: length = %d\n", skb
->len
);
2310 /* Drop packet with error if we don't have carrier */
2311 if (!netif_carrier_ok(dev
)) {
2313 dev
->stats
.tx_errors
++;
2314 dev
->stats
.tx_carrier_errors
++;
2316 "Tried to transmit but no carrier on card %d port %d\n",
2317 card
->card_no
, port
->index
);
2321 /* Drop it if it's too big! MTU failure ? */
2322 if (skb
->len
> LEN_TX_BUFFER
) {
2323 dbg(DBG_ASS
, "Packet too large %d vs %d\n", skb
->len
,
2326 dev
->stats
.tx_errors
++;
2331 * We are always going to queue the packet
2332 * so that the bottom half is the only place we tx from
2333 * Check there is room in the port txq
2335 spin_lock_irqsave(&card
->card_lock
, flags
);
2336 if ((txq_length
= port
->txqe
- port
->txqs
) < 0) {
2338 * This is the case where the next free has wrapped but the
2341 txq_length
= txq_length
+ FST_TXQ_DEPTH
;
2343 spin_unlock_irqrestore(&card
->card_lock
, flags
);
2344 if (txq_length
> fst_txq_high
) {
2346 * We have got enough buffers in the pipeline. Ask the network
2347 * layer to stop sending frames down
2349 netif_stop_queue(dev
);
2350 port
->start
= 1; /* I'm using this to signal stop sent up */
2353 if (txq_length
== FST_TXQ_DEPTH
- 1) {
2355 * This shouldn't have happened but such is life
2358 dev
->stats
.tx_errors
++;
2359 dbg(DBG_ASS
, "Tx queue overflow card %d port %d\n",
2360 card
->card_no
, port
->index
);
2367 spin_lock_irqsave(&card
->card_lock
, flags
);
2368 port
->txq
[port
->txqe
] = skb
;
2370 if (port
->txqe
== FST_TXQ_DEPTH
)
2372 spin_unlock_irqrestore(&card
->card_lock
, flags
);
2374 /* Scehdule the bottom half which now does transmit processing */
2375 fst_q_work_item(&fst_work_txq
, card
->card_no
);
2376 tasklet_schedule(&fst_tx_task
);
2382 * Card setup having checked hardware resources.
2383 * Should be pretty bizarre if we get an error here (kernel memory
2384 * exhaustion is one possibility). If we do see a problem we report it
2385 * via a printk and leave the corresponding interface and all that follow
2388 static char *type_strings
[] __devinitdata
= {
2389 "no hardware", /* Should never be seen */
2398 static void __devinit
2399 fst_init_card(struct fst_card_info
*card
)
2404 /* We're working on a number of ports based on the card ID. If the
2405 * firmware detects something different later (should never happen)
2406 * we'll have to revise it in some way then.
2408 for (i
= 0; i
< card
->nports
; i
++) {
2409 err
= register_hdlc_device(card
->ports
[i
].dev
);
2412 printk_err ("Cannot register HDLC device for port %d"
2413 " (errno %d)\n", i
, -err
);
2414 for (j
= i
; j
< card
->nports
; j
++) {
2415 free_netdev(card
->ports
[j
].dev
);
2416 card
->ports
[j
].dev
= NULL
;
2423 printk_info("%s-%s: %s IRQ%d, %d ports\n",
2424 port_to_dev(&card
->ports
[0])->name
,
2425 port_to_dev(&card
->ports
[card
->nports
- 1])->name
,
2426 type_strings
[card
->type
], card
->irq
, card
->nports
);
2430 * Initialise card when detected.
2431 * Returns 0 to indicate success, or errno otherwise.
2433 static int __devinit
2434 fst_add_one(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
2436 static int firsttime_done
= 0;
2437 static int no_of_cards_added
= 0;
2438 struct fst_card_info
*card
;
2442 if (!firsttime_done
) {
2443 printk_info("FarSync WAN driver " FST_USER_VERSION
2444 " (c) 2001-2004 FarSite Communications Ltd.\n");
2446 dbg(DBG_ASS
, "The value of debug mask is %x\n", fst_debug_mask
);
2450 * We are going to be clever and allow certain cards not to be
2451 * configured. An exclude list can be provided in /etc/modules.conf
2453 if (fst_excluded_cards
!= 0) {
2455 * There are cards to exclude
2458 for (i
= 0; i
< fst_excluded_cards
; i
++) {
2459 if ((pdev
->devfn
) >> 3 == fst_excluded_list
[i
]) {
2460 printk_info("FarSync PCI device %d not assigned\n",
2461 (pdev
->devfn
) >> 3);
2467 /* Allocate driver private data */
2468 card
= kzalloc(sizeof (struct fst_card_info
), GFP_KERNEL
);
2470 printk_err("FarSync card found but insufficient memory for"
2471 " driver storage\n");
2475 /* Try to enable the device */
2476 if ((err
= pci_enable_device(pdev
)) != 0) {
2477 printk_err("Failed to enable card. Err %d\n", -err
);
2482 if ((err
= pci_request_regions(pdev
, "FarSync")) !=0) {
2483 printk_err("Failed to allocate regions. Err %d\n", -err
);
2484 pci_disable_device(pdev
);
2489 /* Get virtual addresses of memory regions */
2490 card
->pci_conf
= pci_resource_start(pdev
, 1);
2491 card
->phys_mem
= pci_resource_start(pdev
, 2);
2492 card
->phys_ctlmem
= pci_resource_start(pdev
, 3);
2493 if ((card
->mem
= ioremap(card
->phys_mem
, FST_MEMSIZE
)) == NULL
) {
2494 printk_err("Physical memory remap failed\n");
2495 pci_release_regions(pdev
);
2496 pci_disable_device(pdev
);
2500 if ((card
->ctlmem
= ioremap(card
->phys_ctlmem
, 0x10)) == NULL
) {
2501 printk_err("Control memory remap failed\n");
2502 pci_release_regions(pdev
);
2503 pci_disable_device(pdev
);
2507 dbg(DBG_PCI
, "kernel mem %p, ctlmem %p\n", card
->mem
, card
->ctlmem
);
2509 /* Register the interrupt handler */
2510 if (request_irq(pdev
->irq
, fst_intr
, IRQF_SHARED
, FST_DEV_NAME
, card
)) {
2511 printk_err("Unable to register interrupt %d\n", card
->irq
);
2512 pci_release_regions(pdev
);
2513 pci_disable_device(pdev
);
2514 iounmap(card
->ctlmem
);
2520 /* Record info we need */
2521 card
->irq
= pdev
->irq
;
2522 card
->type
= ent
->driver_data
;
2523 card
->family
= ((ent
->driver_data
== FST_TYPE_T2P
) ||
2524 (ent
->driver_data
== FST_TYPE_T4P
))
2525 ? FST_FAMILY_TXP
: FST_FAMILY_TXU
;
2526 if ((ent
->driver_data
== FST_TYPE_T1U
) ||
2527 (ent
->driver_data
== FST_TYPE_TE1
))
2530 card
->nports
= ((ent
->driver_data
== FST_TYPE_T2P
) ||
2531 (ent
->driver_data
== FST_TYPE_T2U
)) ? 2 : 4;
2533 card
->state
= FST_UNINIT
;
2534 spin_lock_init ( &card
->card_lock
);
2536 for ( i
= 0 ; i
< card
->nports
; i
++ ) {
2537 struct net_device
*dev
= alloc_hdlcdev(&card
->ports
[i
]);
2541 free_netdev(card
->ports
[i
].dev
);
2542 printk_err ("FarSync: out of memory\n");
2543 free_irq(card
->irq
, card
);
2544 pci_release_regions(pdev
);
2545 pci_disable_device(pdev
);
2546 iounmap(card
->ctlmem
);
2551 card
->ports
[i
].dev
= dev
;
2552 card
->ports
[i
].card
= card
;
2553 card
->ports
[i
].index
= i
;
2554 card
->ports
[i
].run
= 0;
2556 hdlc
= dev_to_hdlc(dev
);
2558 /* Fill in the net device info */
2559 /* Since this is a PCI setup this is purely
2560 * informational. Give them the buffer addresses
2561 * and basic card I/O.
2563 dev
->mem_start
= card
->phys_mem
2564 + BUF_OFFSET ( txBuffer
[i
][0][0]);
2565 dev
->mem_end
= card
->phys_mem
2566 + BUF_OFFSET ( txBuffer
[i
][NUM_TX_BUFFER
][0]);
2567 dev
->base_addr
= card
->pci_conf
;
2568 dev
->irq
= card
->irq
;
2570 dev
->tx_queue_len
= FST_TX_QUEUE_LEN
;
2571 dev
->open
= fst_open
;
2572 dev
->stop
= fst_close
;
2573 dev
->do_ioctl
= fst_ioctl
;
2574 dev
->watchdog_timeo
= FST_TX_TIMEOUT
;
2575 dev
->tx_timeout
= fst_tx_timeout
;
2576 hdlc
->attach
= fst_attach
;
2577 hdlc
->xmit
= fst_start_xmit
;
2580 card
->device
= pdev
;
2582 dbg(DBG_PCI
, "type %d nports %d irq %d\n", card
->type
,
2583 card
->nports
, card
->irq
);
2584 dbg(DBG_PCI
, "conf %04x mem %08x ctlmem %08x\n",
2585 card
->pci_conf
, card
->phys_mem
, card
->phys_ctlmem
);
2587 /* Reset the card's processor */
2589 card
->state
= FST_RESET
;
2591 /* Initialise DMA (if required) */
2594 /* Record driver data for later use */
2595 pci_set_drvdata(pdev
, card
);
2597 /* Remainder of card setup */
2598 fst_card_array
[no_of_cards_added
] = card
;
2599 card
->card_no
= no_of_cards_added
++; /* Record instance and bump it */
2600 fst_init_card(card
);
2601 if (card
->family
== FST_FAMILY_TXU
) {
2603 * Allocate a dma buffer for transmit and receives
2605 card
->rx_dma_handle_host
=
2606 pci_alloc_consistent(card
->device
, FST_MAX_MTU
,
2607 &card
->rx_dma_handle_card
);
2608 if (card
->rx_dma_handle_host
== NULL
) {
2609 printk_err("Could not allocate rx dma buffer\n");
2610 fst_disable_intr(card
);
2611 pci_release_regions(pdev
);
2612 pci_disable_device(pdev
);
2613 iounmap(card
->ctlmem
);
2618 card
->tx_dma_handle_host
=
2619 pci_alloc_consistent(card
->device
, FST_MAX_MTU
,
2620 &card
->tx_dma_handle_card
);
2621 if (card
->tx_dma_handle_host
== NULL
) {
2622 printk_err("Could not allocate tx dma buffer\n");
2623 fst_disable_intr(card
);
2624 pci_release_regions(pdev
);
2625 pci_disable_device(pdev
);
2626 iounmap(card
->ctlmem
);
2632 return 0; /* Success */
2636 * Cleanup and close down a card
2638 static void __devexit
2639 fst_remove_one(struct pci_dev
*pdev
)
2641 struct fst_card_info
*card
;
2644 card
= pci_get_drvdata(pdev
);
2646 for (i
= 0; i
< card
->nports
; i
++) {
2647 struct net_device
*dev
= port_to_dev(&card
->ports
[i
]);
2648 unregister_hdlc_device(dev
);
2651 fst_disable_intr(card
);
2652 free_irq(card
->irq
, card
);
2654 iounmap(card
->ctlmem
);
2656 pci_release_regions(pdev
);
2657 if (card
->family
== FST_FAMILY_TXU
) {
2661 pci_free_consistent(card
->device
, FST_MAX_MTU
,
2662 card
->rx_dma_handle_host
,
2663 card
->rx_dma_handle_card
);
2664 pci_free_consistent(card
->device
, FST_MAX_MTU
,
2665 card
->tx_dma_handle_host
,
2666 card
->tx_dma_handle_card
);
2668 fst_card_array
[card
->card_no
] = NULL
;
2671 static struct pci_driver fst_driver
= {
2673 .id_table
= fst_pci_dev_id
,
2674 .probe
= fst_add_one
,
2675 .remove
= __devexit_p(fst_remove_one
),
2685 for (i
= 0; i
< FST_MAX_CARDS
; i
++)
2686 fst_card_array
[i
] = NULL
;
2687 spin_lock_init(&fst_work_q_lock
);
2688 return pci_register_driver(&fst_driver
);
2692 fst_cleanup_module(void)
2694 printk_info("FarSync WAN driver unloading\n");
2695 pci_unregister_driver(&fst_driver
);
2698 module_init(fst_init
);
2699 module_exit(fst_cleanup_module
);