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/sched.h>
23 #include <linux/ioport.h>
24 #include <linux/init.h>
26 #include <linux/hdlc.h>
28 #include <asm/uaccess.h>
35 MODULE_AUTHOR("R.J.Dunlop <bob.dunlop@farsite.co.uk>");
36 MODULE_DESCRIPTION("FarSync T-Series WAN driver. FarSite Communications Ltd.");
37 MODULE_LICENSE("GPL");
39 /* Driver configuration and global parameters
40 * ==========================================
43 /* Number of ports (per card) and cards supported
45 #define FST_MAX_PORTS 4
46 #define FST_MAX_CARDS 32
48 /* Default parameters for the link
50 #define FST_TX_QUEUE_LEN 100 /* At 8Mbps a longer queue length is
52 #define FST_TXQ_DEPTH 16 /* This one is for the buffering
53 * of frames on the way down to the card
54 * so that we can keep the card busy
55 * and maximise throughput
57 #define FST_HIGH_WATER_MARK 12 /* Point at which we flow control
59 #define FST_LOW_WATER_MARK 8 /* Point at which we remove flow
60 * control from network layer */
61 #define FST_MAX_MTU 8000 /* Huge but possible */
62 #define FST_DEF_MTU 1500 /* Common sane value */
64 #define FST_TX_TIMEOUT (2*HZ)
67 #define ARPHRD_MYTYPE ARPHRD_RAWHDLC /* Raw frames */
69 #define ARPHRD_MYTYPE ARPHRD_HDLC /* Cisco-HDLC (keepalives etc) */
73 * Modules parameters and associated variables
75 static int fst_txq_low
= FST_LOW_WATER_MARK
;
76 static int fst_txq_high
= FST_HIGH_WATER_MARK
;
77 static int fst_max_reads
= 7;
78 static int fst_excluded_cards
= 0;
79 static int fst_excluded_list
[FST_MAX_CARDS
];
81 module_param(fst_txq_low
, int, 0);
82 module_param(fst_txq_high
, int, 0);
83 module_param(fst_max_reads
, int, 0);
84 module_param(fst_excluded_cards
, int, 0);
85 module_param_array(fst_excluded_list
, int, NULL
, 0);
87 /* Card shared memory layout
88 * =========================
92 /* This information is derived in part from the FarSite FarSync Smc.h
93 * file. Unfortunately various name clashes and the non-portability of the
94 * bit field declarations in that file have meant that I have chosen to
95 * recreate the information here.
97 * The SMC (Shared Memory Configuration) has a version number that is
98 * incremented every time there is a significant change. This number can
99 * be used to check that we have not got out of step with the firmware
100 * contained in the .CDE files.
102 #define SMC_VERSION 24
104 #define FST_MEMSIZE 0x100000 /* Size of card memory (1Mb) */
106 #define SMC_BASE 0x00002000L /* Base offset of the shared memory window main
107 * configuration structure */
108 #define BFM_BASE 0x00010000L /* Base offset of the shared memory window DMA
111 #define LEN_TX_BUFFER 8192 /* Size of packet buffers */
112 #define LEN_RX_BUFFER 8192
114 #define LEN_SMALL_TX_BUFFER 256 /* Size of obsolete buffs used for DOS diags */
115 #define LEN_SMALL_RX_BUFFER 256
117 #define NUM_TX_BUFFER 2 /* Must be power of 2. Fixed by firmware */
118 #define NUM_RX_BUFFER 8
120 /* Interrupt retry time in milliseconds */
121 #define INT_RETRY_TIME 2
123 /* The Am186CH/CC processors support a SmartDMA mode using circular pools
124 * of buffer descriptors. The structure is almost identical to that used
125 * in the LANCE Ethernet controllers. Details available as PDF from the
126 * AMD web site: http://www.amd.com/products/epd/processors/\
127 * 2.16bitcont/3.am186cxfa/a21914/21914.pdf
129 struct txdesc
{ /* Transmit descriptor */
130 volatile u16 ladr
; /* Low order address of packet. This is a
131 * linear address in the Am186 memory space
133 volatile u8 hadr
; /* High order address. Low 4 bits only, high 4
136 volatile u8 bits
; /* Status and config */
137 volatile u16 bcnt
; /* 2s complement of packet size in low 15 bits.
138 * Transmit terminal count interrupt enable in
141 u16 unused
; /* Not used in Tx */
144 struct rxdesc
{ /* Receive descriptor */
145 volatile u16 ladr
; /* Low order address of packet */
146 volatile u8 hadr
; /* High order address */
147 volatile u8 bits
; /* Status and config */
148 volatile u16 bcnt
; /* 2s complement of buffer size in low 15 bits.
149 * Receive terminal count interrupt enable in
152 volatile u16 mcnt
; /* Message byte count (15 bits) */
155 /* Convert a length into the 15 bit 2's complement */
156 /* #define cnv_bcnt(len) (( ~(len) + 1 ) & 0x7FFF ) */
157 /* Since we need to set the high bit to enable the completion interrupt this
158 * can be made a lot simpler
160 #define cnv_bcnt(len) (-(len))
162 /* Status and config bits for the above */
163 #define DMA_OWN 0x80 /* SmartDMA owns the descriptor */
164 #define TX_STP 0x02 /* Tx: start of packet */
165 #define TX_ENP 0x01 /* Tx: end of packet */
166 #define RX_ERR 0x40 /* Rx: error (OR of next 4 bits) */
167 #define RX_FRAM 0x20 /* Rx: framing error */
168 #define RX_OFLO 0x10 /* Rx: overflow error */
169 #define RX_CRC 0x08 /* Rx: CRC error */
170 #define RX_HBUF 0x04 /* Rx: buffer error */
171 #define RX_STP 0x02 /* Rx: start of packet */
172 #define RX_ENP 0x01 /* Rx: end of packet */
174 /* Interrupts from the card are caused by various events which are presented
175 * in a circular buffer as several events may be processed on one physical int
177 #define MAX_CIRBUFF 32
180 u8 rdindex
; /* read, then increment and wrap */
181 u8 wrindex
; /* write, then increment and wrap */
182 u8 evntbuff
[MAX_CIRBUFF
];
185 /* Interrupt event codes.
186 * Where appropriate the two low order bits indicate the port number
188 #define CTLA_CHG 0x18 /* Control signal changed */
189 #define CTLB_CHG 0x19
190 #define CTLC_CHG 0x1A
191 #define CTLD_CHG 0x1B
193 #define INIT_CPLT 0x20 /* Initialisation complete */
194 #define INIT_FAIL 0x21 /* Initialisation failed */
196 #define ABTA_SENT 0x24 /* Abort sent */
197 #define ABTB_SENT 0x25
198 #define ABTC_SENT 0x26
199 #define ABTD_SENT 0x27
201 #define TXA_UNDF 0x28 /* Transmission underflow */
202 #define TXB_UNDF 0x29
203 #define TXC_UNDF 0x2A
204 #define TXD_UNDF 0x2B
209 #define TE1_ALMA 0x30
211 /* Port physical configuration. See farsync.h for field values */
213 u16 lineInterface
; /* Physical interface type */
214 u8 x25op
; /* Unused at present */
215 u8 internalClock
; /* 1 => internal clock, 0 => external */
216 u8 transparentMode
; /* 1 => on, 0 => off */
217 u8 invertClock
; /* 0 => normal, 1 => inverted */
218 u8 padBytes
[6]; /* Padding */
219 u32 lineSpeed
; /* Speed in bps */
222 /* TE1 port physical configuration */
246 u32 receiveBufferDelay
;
247 u32 framingErrorCount
;
248 u32 codeViolationCount
;
253 u8 receiveRemoteAlarm
;
254 u8 alarmIndicationSignal
;
258 /* Finally sling all the above together into the shared memory structure.
259 * Sorry it's a hodge podge of arrays, structures and unused bits, it's been
260 * evolving under NT for some time so I guess we're stuck with it.
261 * The structure starts at offset SMC_BASE.
262 * See farsync.h for some field values.
265 /* DMA descriptor rings */
266 struct rxdesc rxDescrRing
[FST_MAX_PORTS
][NUM_RX_BUFFER
];
267 struct txdesc txDescrRing
[FST_MAX_PORTS
][NUM_TX_BUFFER
];
269 /* Obsolete small buffers */
270 u8 smallRxBuffer
[FST_MAX_PORTS
][NUM_RX_BUFFER
][LEN_SMALL_RX_BUFFER
];
271 u8 smallTxBuffer
[FST_MAX_PORTS
][NUM_TX_BUFFER
][LEN_SMALL_TX_BUFFER
];
273 u8 taskStatus
; /* 0x00 => initialising, 0x01 => running,
277 u8 interruptHandshake
; /* Set to 0x01 by adapter to signal interrupt,
278 * set to 0xEE by host to acknowledge interrupt
281 u16 smcVersion
; /* Must match SMC_VERSION */
283 u32 smcFirmwareVersion
; /* 0xIIVVRRBB where II = product ID, VV = major
284 * version, RR = revision and BB = build
287 u16 txa_done
; /* Obsolete completion flags */
296 u16 mailbox
[4]; /* Diagnostics mailbox. Not used */
298 struct cirbuff interruptEvent
; /* interrupt causes */
300 u32 v24IpSts
[FST_MAX_PORTS
]; /* V.24 control input status */
301 u32 v24OpSts
[FST_MAX_PORTS
]; /* V.24 control output status */
303 struct port_cfg portConfig
[FST_MAX_PORTS
];
305 u16 clockStatus
[FST_MAX_PORTS
]; /* lsb: 0=> present, 1=> absent */
307 u16 cableStatus
; /* lsb: 0=> present, 1=> absent */
309 u16 txDescrIndex
[FST_MAX_PORTS
]; /* transmit descriptor ring index */
310 u16 rxDescrIndex
[FST_MAX_PORTS
]; /* receive descriptor ring index */
312 u16 portMailbox
[FST_MAX_PORTS
][2]; /* command, modifier */
313 u16 cardMailbox
[4]; /* Not used */
315 /* Number of times the card thinks the host has
316 * missed an interrupt by not acknowledging
317 * within 2mS (I guess NT has problems)
319 u32 interruptRetryCount
;
321 /* Driver private data used as an ID. We'll not
322 * use this as I'd rather keep such things
323 * in main memory rather than on the PCI bus
325 u32 portHandle
[FST_MAX_PORTS
];
327 /* Count of Tx underflows for stats */
328 u32 transmitBufferUnderflow
[FST_MAX_PORTS
];
330 /* Debounced V.24 control input status */
331 u32 v24DebouncedSts
[FST_MAX_PORTS
];
333 /* Adapter debounce timers. Don't touch */
334 u32 ctsTimer
[FST_MAX_PORTS
];
335 u32 ctsTimerRun
[FST_MAX_PORTS
];
336 u32 dcdTimer
[FST_MAX_PORTS
];
337 u32 dcdTimerRun
[FST_MAX_PORTS
];
339 u32 numberOfPorts
; /* Number of ports detected at startup */
343 u16 cardMode
; /* Bit-mask to enable features:
344 * Bit 0: 1 enables LED identify mode
347 u16 portScheduleOffset
;
349 struct su_config suConfig
; /* TE1 Bits */
350 struct su_status suStatus
;
352 u32 endOfSmcSignature
; /* endOfSmcSignature MUST be the last member of
353 * the structure and marks the end of shared
354 * memory. Adapter code initializes it as
359 /* endOfSmcSignature value */
360 #define END_SIG 0x12345678
362 /* Mailbox values. (portMailbox) */
363 #define NOP 0 /* No operation */
364 #define ACK 1 /* Positive acknowledgement to PC driver */
365 #define NAK 2 /* Negative acknowledgement to PC driver */
366 #define STARTPORT 3 /* Start an HDLC port */
367 #define STOPPORT 4 /* Stop an HDLC port */
368 #define ABORTTX 5 /* Abort the transmitter for a port */
369 #define SETV24O 6 /* Set V24 outputs */
371 /* PLX Chip Register Offsets */
372 #define CNTRL_9052 0x50 /* Control Register */
373 #define CNTRL_9054 0x6c /* Control Register */
375 #define INTCSR_9052 0x4c /* Interrupt control/status register */
376 #define INTCSR_9054 0x68 /* Interrupt control/status register */
378 /* 9054 DMA Registers */
380 * Note that we will be using DMA Channel 0 for copying rx data
381 * and Channel 1 for copying tx data
383 #define DMAMODE0 0x80
384 #define DMAPADR0 0x84
385 #define DMALADR0 0x88
388 #define DMAMODE1 0x94
389 #define DMAPADR1 0x98
390 #define DMALADR1 0x9c
399 #define DMAMARBR 0xac
401 #define FST_MIN_DMA_LEN 64
402 #define FST_RX_DMA_INT 0x01
403 #define FST_TX_DMA_INT 0x02
404 #define FST_CARD_INT 0x04
406 /* Larger buffers are positioned in memory at offset BFM_BASE */
408 u8 txBuffer
[FST_MAX_PORTS
][NUM_TX_BUFFER
][LEN_TX_BUFFER
];
409 u8 rxBuffer
[FST_MAX_PORTS
][NUM_RX_BUFFER
][LEN_RX_BUFFER
];
412 /* Calculate offset of a buffer object within the shared memory window */
413 #define BUF_OFFSET(X) (BFM_BASE + offsetof(struct buf_window, X))
417 /* Device driver private information
418 * =================================
420 /* Per port (line or channel) information
422 struct fst_port_info
{
423 struct net_device
*dev
; /* Device struct - must be first */
424 struct fst_card_info
*card
; /* Card we're associated with */
425 int index
; /* Port index on the card */
426 int hwif
; /* Line hardware (lineInterface copy) */
427 int run
; /* Port is running */
428 int mode
; /* Normal or FarSync raw */
429 int rxpos
; /* Next Rx buffer to use */
430 int txpos
; /* Next Tx buffer to use */
431 int txipos
; /* Next Tx buffer to check for free */
432 int start
; /* Indication of start/stop to network */
434 * A sixteen entry transmit queue
436 int txqs
; /* index to get next buffer to tx */
437 int txqe
; /* index to queue next packet */
438 struct sk_buff
*txq
[FST_TXQ_DEPTH
]; /* The queue */
442 /* Per card information
444 struct fst_card_info
{
445 char __iomem
*mem
; /* Card memory mapped to kernel space */
446 char __iomem
*ctlmem
; /* Control memory for PCI cards */
447 unsigned int phys_mem
; /* Physical memory window address */
448 unsigned int phys_ctlmem
; /* Physical control memory address */
449 unsigned int irq
; /* Interrupt request line number */
450 unsigned int nports
; /* Number of serial ports */
451 unsigned int type
; /* Type index of card */
452 unsigned int state
; /* State of card */
453 spinlock_t card_lock
; /* Lock for SMP access */
454 unsigned short pci_conf
; /* PCI card config in I/O space */
456 struct fst_port_info ports
[FST_MAX_PORTS
];
457 struct pci_dev
*device
; /* Information about the pci device */
458 int card_no
; /* Inst of the card on the system */
459 int family
; /* TxP or TxU */
460 int dmarx_in_progress
;
461 int dmatx_in_progress
;
462 unsigned long int_count
;
463 unsigned long int_time_ave
;
464 void *rx_dma_handle_host
;
465 dma_addr_t rx_dma_handle_card
;
466 void *tx_dma_handle_host
;
467 dma_addr_t tx_dma_handle_card
;
468 struct sk_buff
*dma_skb_rx
;
469 struct fst_port_info
*dma_port_rx
;
470 struct fst_port_info
*dma_port_tx
;
477 /* Convert an HDLC device pointer into a port info pointer and similar */
478 #define dev_to_port(D) (dev_to_hdlc(D)->priv)
479 #define port_to_dev(P) ((P)->dev)
483 * Shared memory window access macros
485 * We have a nice memory based structure above, which could be directly
486 * mapped on i386 but might not work on other architectures unless we use
487 * the readb,w,l and writeb,w,l macros. Unfortunately these macros take
488 * physical offsets so we have to convert. The only saving grace is that
489 * this should all collapse back to a simple indirection eventually.
491 #define WIN_OFFSET(X) ((long)&(((struct fst_shared *)SMC_BASE)->X))
493 #define FST_RDB(C,E) readb ((C)->mem + WIN_OFFSET(E))
494 #define FST_RDW(C,E) readw ((C)->mem + WIN_OFFSET(E))
495 #define FST_RDL(C,E) readl ((C)->mem + WIN_OFFSET(E))
497 #define FST_WRB(C,E,B) writeb ((B), (C)->mem + WIN_OFFSET(E))
498 #define FST_WRW(C,E,W) writew ((W), (C)->mem + WIN_OFFSET(E))
499 #define FST_WRL(C,E,L) writel ((L), (C)->mem + WIN_OFFSET(E))
506 static int fst_debug_mask
= { FST_DEBUG
};
508 /* Most common debug activity is to print something if the corresponding bit
509 * is set in the debug mask. Note: this uses a non-ANSI extension in GCC to
510 * support variable numbers of macro parameters. The inverted if prevents us
511 * eating someone else's else clause.
513 #define dbg(F,fmt,A...) if ( ! ( fst_debug_mask & (F))) \
516 printk ( KERN_DEBUG FST_NAME ": " fmt, ## A )
519 #define dbg(X...) /* NOP */
522 /* Printing short cuts
524 #define printk_err(fmt,A...) printk ( KERN_ERR FST_NAME ": " fmt, ## A )
525 #define printk_warn(fmt,A...) printk ( KERN_WARNING FST_NAME ": " fmt, ## A )
526 #define printk_info(fmt,A...) printk ( KERN_INFO FST_NAME ": " fmt, ## A )
529 * PCI ID lookup table
531 static struct pci_device_id fst_pci_dev_id
[] __devinitdata
= {
532 {PCI_VENDOR_ID_FARSITE
, PCI_DEVICE_ID_FARSITE_T2P
, PCI_ANY_ID
,
533 PCI_ANY_ID
, 0, 0, FST_TYPE_T2P
},
535 {PCI_VENDOR_ID_FARSITE
, PCI_DEVICE_ID_FARSITE_T4P
, PCI_ANY_ID
,
536 PCI_ANY_ID
, 0, 0, FST_TYPE_T4P
},
538 {PCI_VENDOR_ID_FARSITE
, PCI_DEVICE_ID_FARSITE_T1U
, PCI_ANY_ID
,
539 PCI_ANY_ID
, 0, 0, FST_TYPE_T1U
},
541 {PCI_VENDOR_ID_FARSITE
, PCI_DEVICE_ID_FARSITE_T2U
, PCI_ANY_ID
,
542 PCI_ANY_ID
, 0, 0, FST_TYPE_T2U
},
544 {PCI_VENDOR_ID_FARSITE
, PCI_DEVICE_ID_FARSITE_T4U
, PCI_ANY_ID
,
545 PCI_ANY_ID
, 0, 0, FST_TYPE_T4U
},
547 {PCI_VENDOR_ID_FARSITE
, PCI_DEVICE_ID_FARSITE_TE1
, PCI_ANY_ID
,
548 PCI_ANY_ID
, 0, 0, FST_TYPE_TE1
},
550 {PCI_VENDOR_ID_FARSITE
, PCI_DEVICE_ID_FARSITE_TE1C
, PCI_ANY_ID
,
551 PCI_ANY_ID
, 0, 0, FST_TYPE_TE1
},
555 MODULE_DEVICE_TABLE(pci
, fst_pci_dev_id
);
558 * Device Driver Work Queues
560 * So that we don't spend too much time processing events in the
561 * Interrupt Service routine, we will declare a work queue per Card
562 * and make the ISR schedule a task in the queue for later execution.
563 * In the 2.4 Kernel we used to use the immediate queue for BH's
564 * Now that they are gone, tasklets seem to be much better than work
568 static void do_bottom_half_tx(struct fst_card_info
*card
);
569 static void do_bottom_half_rx(struct fst_card_info
*card
);
570 static void fst_process_tx_work_q(unsigned long work_q
);
571 static void fst_process_int_work_q(unsigned long work_q
);
573 static DECLARE_TASKLET(fst_tx_task
, fst_process_tx_work_q
, 0);
574 static DECLARE_TASKLET(fst_int_task
, fst_process_int_work_q
, 0);
576 static struct fst_card_info
*fst_card_array
[FST_MAX_CARDS
];
577 static spinlock_t fst_work_q_lock
;
578 static u64 fst_work_txq
;
579 static u64 fst_work_intq
;
582 fst_q_work_item(u64
* queue
, int card_index
)
588 * Grab the queue exclusively
590 spin_lock_irqsave(&fst_work_q_lock
, flags
);
593 * Making an entry in the queue is simply a matter of setting
594 * a bit for the card indicating that there is work to do in the
595 * bottom half for the card. Note the limitation of 64 cards.
596 * That ought to be enough
598 mask
= 1 << card_index
;
600 spin_unlock_irqrestore(&fst_work_q_lock
, flags
);
604 fst_process_tx_work_q(unsigned long /*void **/work_q
)
611 * Grab the queue exclusively
613 dbg(DBG_TX
, "fst_process_tx_work_q\n");
614 spin_lock_irqsave(&fst_work_q_lock
, flags
);
615 work_txq
= fst_work_txq
;
617 spin_unlock_irqrestore(&fst_work_q_lock
, flags
);
620 * Call the bottom half for each card with work waiting
622 for (i
= 0; i
< FST_MAX_CARDS
; i
++) {
623 if (work_txq
& 0x01) {
624 if (fst_card_array
[i
] != NULL
) {
625 dbg(DBG_TX
, "Calling tx bh for card %d\n", i
);
626 do_bottom_half_tx(fst_card_array
[i
]);
629 work_txq
= work_txq
>> 1;
634 fst_process_int_work_q(unsigned long /*void **/work_q
)
641 * Grab the queue exclusively
643 dbg(DBG_INTR
, "fst_process_int_work_q\n");
644 spin_lock_irqsave(&fst_work_q_lock
, flags
);
645 work_intq
= fst_work_intq
;
647 spin_unlock_irqrestore(&fst_work_q_lock
, flags
);
650 * Call the bottom half for each card with work waiting
652 for (i
= 0; i
< FST_MAX_CARDS
; i
++) {
653 if (work_intq
& 0x01) {
654 if (fst_card_array
[i
] != NULL
) {
656 "Calling rx & tx bh for card %d\n", i
);
657 do_bottom_half_rx(fst_card_array
[i
]);
658 do_bottom_half_tx(fst_card_array
[i
]);
661 work_intq
= work_intq
>> 1;
665 /* Card control functions
666 * ======================
668 /* Place the processor in reset state
670 * Used to be a simple write to card control space but a glitch in the latest
671 * AMD Am186CH processor means that we now have to do it by asserting and de-
672 * asserting the PLX chip PCI Adapter Software Reset. Bit 30 in CNTRL register
673 * at offset 9052_CNTRL. Note the updates for the TXU.
676 fst_cpureset(struct fst_card_info
*card
)
678 unsigned char interrupt_line_register
;
679 unsigned long j
= jiffies
+ 1;
682 if (card
->family
== FST_FAMILY_TXU
) {
683 if (pci_read_config_byte
684 (card
->device
, PCI_INTERRUPT_LINE
, &interrupt_line_register
)) {
686 "Error in reading interrupt line register\n");
689 * Assert PLX software reset and Am186 hardware reset
690 * and then deassert the PLX software reset but 186 still in reset
692 outw(0x440f, card
->pci_conf
+ CNTRL_9054
+ 2);
693 outw(0x040f, card
->pci_conf
+ CNTRL_9054
+ 2);
695 * We are delaying here to allow the 9054 to reset itself
700 outw(0x240f, card
->pci_conf
+ CNTRL_9054
+ 2);
702 * We are delaying here to allow the 9054 to reload its eeprom
707 outw(0x040f, card
->pci_conf
+ CNTRL_9054
+ 2);
709 if (pci_write_config_byte
710 (card
->device
, PCI_INTERRUPT_LINE
, interrupt_line_register
)) {
712 "Error in writing interrupt line register\n");
716 regval
= inl(card
->pci_conf
+ CNTRL_9052
);
718 outl(regval
| 0x40000000, card
->pci_conf
+ CNTRL_9052
);
719 outl(regval
& ~0x40000000, card
->pci_conf
+ CNTRL_9052
);
723 /* Release the processor from reset
726 fst_cpurelease(struct fst_card_info
*card
)
728 if (card
->family
== FST_FAMILY_TXU
) {
730 * Force posted writes to complete
732 (void) readb(card
->mem
);
735 * Release LRESET DO = 1
736 * Then release Local Hold, DO = 1
738 outw(0x040e, card
->pci_conf
+ CNTRL_9054
+ 2);
739 outw(0x040f, card
->pci_conf
+ CNTRL_9054
+ 2);
741 (void) readb(card
->ctlmem
);
745 /* Clear the cards interrupt flag
748 fst_clear_intr(struct fst_card_info
*card
)
750 if (card
->family
== FST_FAMILY_TXU
) {
751 (void) readb(card
->ctlmem
);
753 /* Poke the appropriate PLX chip register (same as enabling interrupts)
755 outw(0x0543, card
->pci_conf
+ INTCSR_9052
);
759 /* Enable card interrupts
762 fst_enable_intr(struct fst_card_info
*card
)
764 if (card
->family
== FST_FAMILY_TXU
) {
765 outl(0x0f0c0900, card
->pci_conf
+ INTCSR_9054
);
767 outw(0x0543, card
->pci_conf
+ INTCSR_9052
);
771 /* Disable card interrupts
774 fst_disable_intr(struct fst_card_info
*card
)
776 if (card
->family
== FST_FAMILY_TXU
) {
777 outl(0x00000000, card
->pci_conf
+ INTCSR_9054
);
779 outw(0x0000, card
->pci_conf
+ INTCSR_9052
);
783 /* Process the result of trying to pass a received frame up the stack
786 fst_process_rx_status(int rx_status
, char *name
)
798 dbg(DBG_ASS
, "%s: Received packet dropped\n", name
);
804 /* Initilaise DMA for PLX 9054
807 fst_init_dma(struct fst_card_info
*card
)
810 * This is only required for the PLX 9054
812 if (card
->family
== FST_FAMILY_TXU
) {
813 pci_set_master(card
->device
);
814 outl(0x00020441, card
->pci_conf
+ DMAMODE0
);
815 outl(0x00020441, card
->pci_conf
+ DMAMODE1
);
816 outl(0x0, card
->pci_conf
+ DMATHR
);
820 /* Tx dma complete interrupt
823 fst_tx_dma_complete(struct fst_card_info
*card
, struct fst_port_info
*port
,
826 struct net_device
*dev
= port_to_dev(port
);
829 * Everything is now set, just tell the card to go
831 dbg(DBG_TX
, "fst_tx_dma_complete\n");
832 FST_WRB(card
, txDescrRing
[port
->index
][txpos
].bits
,
833 DMA_OWN
| TX_STP
| TX_ENP
);
834 dev
->stats
.tx_packets
++;
835 dev
->stats
.tx_bytes
+= len
;
836 dev
->trans_start
= jiffies
;
840 * Mark it for our own raw sockets interface
842 static __be16
farsync_type_trans(struct sk_buff
*skb
, struct net_device
*dev
)
845 skb_reset_mac_header(skb
);
846 skb
->pkt_type
= PACKET_HOST
;
847 return htons(ETH_P_CUST
);
850 /* Rx dma complete interrupt
853 fst_rx_dma_complete(struct fst_card_info
*card
, struct fst_port_info
*port
,
854 int len
, struct sk_buff
*skb
, int rxp
)
856 struct net_device
*dev
= port_to_dev(port
);
860 dbg(DBG_TX
, "fst_rx_dma_complete\n");
862 memcpy(skb_put(skb
, len
), card
->rx_dma_handle_host
, len
);
864 /* Reset buffer descriptor */
865 FST_WRB(card
, rxDescrRing
[pi
][rxp
].bits
, DMA_OWN
);
868 dev
->stats
.rx_packets
++;
869 dev
->stats
.rx_bytes
+= len
;
872 dbg(DBG_RX
, "Pushing the frame up the stack\n");
873 if (port
->mode
== FST_RAW
)
874 skb
->protocol
= farsync_type_trans(skb
, dev
);
876 skb
->protocol
= hdlc_type_trans(skb
, dev
);
877 rx_status
= netif_rx(skb
);
878 fst_process_rx_status(rx_status
, port_to_dev(port
)->name
);
879 if (rx_status
== NET_RX_DROP
)
880 dev
->stats
.rx_dropped
++;
884 * Receive a frame through the DMA
887 fst_rx_dma(struct fst_card_info
*card
, unsigned char *skb
,
888 unsigned char *mem
, int len
)
891 * This routine will setup the DMA and start it
894 dbg(DBG_RX
, "In fst_rx_dma %p %p %d\n", skb
, mem
, len
);
895 if (card
->dmarx_in_progress
) {
896 dbg(DBG_ASS
, "In fst_rx_dma while dma in progress\n");
899 outl((unsigned long) skb
, card
->pci_conf
+ DMAPADR0
); /* Copy to here */
900 outl((unsigned long) mem
, card
->pci_conf
+ DMALADR0
); /* from here */
901 outl(len
, card
->pci_conf
+ DMASIZ0
); /* for this length */
902 outl(0x00000000c, card
->pci_conf
+ DMADPR0
); /* In this direction */
905 * We use the dmarx_in_progress flag to flag the channel as busy
907 card
->dmarx_in_progress
= 1;
908 outb(0x03, card
->pci_conf
+ DMACSR0
); /* Start the transfer */
912 * Send a frame through the DMA
915 fst_tx_dma(struct fst_card_info
*card
, unsigned char *skb
,
916 unsigned char *mem
, int len
)
919 * This routine will setup the DMA and start it.
922 dbg(DBG_TX
, "In fst_tx_dma %p %p %d\n", skb
, mem
, len
);
923 if (card
->dmatx_in_progress
) {
924 dbg(DBG_ASS
, "In fst_tx_dma while dma in progress\n");
927 outl((unsigned long) skb
, card
->pci_conf
+ DMAPADR1
); /* Copy from here */
928 outl((unsigned long) mem
, card
->pci_conf
+ DMALADR1
); /* to here */
929 outl(len
, card
->pci_conf
+ DMASIZ1
); /* for this length */
930 outl(0x000000004, card
->pci_conf
+ DMADPR1
); /* In this direction */
933 * We use the dmatx_in_progress to flag the channel as busy
935 card
->dmatx_in_progress
= 1;
936 outb(0x03, card
->pci_conf
+ DMACSR1
); /* Start the transfer */
939 /* Issue a Mailbox command for a port.
940 * Note we issue them on a fire and forget basis, not expecting to see an
941 * error and not waiting for completion.
944 fst_issue_cmd(struct fst_port_info
*port
, unsigned short cmd
)
946 struct fst_card_info
*card
;
947 unsigned short mbval
;
952 spin_lock_irqsave(&card
->card_lock
, flags
);
953 mbval
= FST_RDW(card
, portMailbox
[port
->index
][0]);
956 /* Wait for any previous command to complete */
957 while (mbval
> NAK
) {
958 spin_unlock_irqrestore(&card
->card_lock
, flags
);
959 schedule_timeout_uninterruptible(1);
960 spin_lock_irqsave(&card
->card_lock
, flags
);
962 if (++safety
> 2000) {
963 printk_err("Mailbox safety timeout\n");
967 mbval
= FST_RDW(card
, portMailbox
[port
->index
][0]);
970 dbg(DBG_CMD
, "Mailbox clear after %d jiffies\n", safety
);
973 dbg(DBG_CMD
, "issue_cmd: previous command was NAK'd\n");
976 FST_WRW(card
, portMailbox
[port
->index
][0], cmd
);
978 if (cmd
== ABORTTX
|| cmd
== STARTPORT
) {
984 spin_unlock_irqrestore(&card
->card_lock
, flags
);
987 /* Port output signals control
990 fst_op_raise(struct fst_port_info
*port
, unsigned int outputs
)
992 outputs
|= FST_RDL(port
->card
, v24OpSts
[port
->index
]);
993 FST_WRL(port
->card
, v24OpSts
[port
->index
], outputs
);
996 fst_issue_cmd(port
, SETV24O
);
1000 fst_op_lower(struct fst_port_info
*port
, unsigned int outputs
)
1002 outputs
= ~outputs
& FST_RDL(port
->card
, v24OpSts
[port
->index
]);
1003 FST_WRL(port
->card
, v24OpSts
[port
->index
], outputs
);
1006 fst_issue_cmd(port
, SETV24O
);
1010 * Setup port Rx buffers
1013 fst_rx_config(struct fst_port_info
*port
)
1017 unsigned int offset
;
1018 unsigned long flags
;
1019 struct fst_card_info
*card
;
1023 spin_lock_irqsave(&card
->card_lock
, flags
);
1024 for (i
= 0; i
< NUM_RX_BUFFER
; i
++) {
1025 offset
= BUF_OFFSET(rxBuffer
[pi
][i
][0]);
1027 FST_WRW(card
, rxDescrRing
[pi
][i
].ladr
, (u16
) offset
);
1028 FST_WRB(card
, rxDescrRing
[pi
][i
].hadr
, (u8
) (offset
>> 16));
1029 FST_WRW(card
, rxDescrRing
[pi
][i
].bcnt
, cnv_bcnt(LEN_RX_BUFFER
));
1030 FST_WRW(card
, rxDescrRing
[pi
][i
].mcnt
, LEN_RX_BUFFER
);
1031 FST_WRB(card
, rxDescrRing
[pi
][i
].bits
, DMA_OWN
);
1034 spin_unlock_irqrestore(&card
->card_lock
, flags
);
1038 * Setup port Tx buffers
1041 fst_tx_config(struct fst_port_info
*port
)
1045 unsigned int offset
;
1046 unsigned long flags
;
1047 struct fst_card_info
*card
;
1051 spin_lock_irqsave(&card
->card_lock
, flags
);
1052 for (i
= 0; i
< NUM_TX_BUFFER
; i
++) {
1053 offset
= BUF_OFFSET(txBuffer
[pi
][i
][0]);
1055 FST_WRW(card
, txDescrRing
[pi
][i
].ladr
, (u16
) offset
);
1056 FST_WRB(card
, txDescrRing
[pi
][i
].hadr
, (u8
) (offset
>> 16));
1057 FST_WRW(card
, txDescrRing
[pi
][i
].bcnt
, 0);
1058 FST_WRB(card
, txDescrRing
[pi
][i
].bits
, 0);
1063 spin_unlock_irqrestore(&card
->card_lock
, flags
);
1066 /* TE1 Alarm change interrupt event
1069 fst_intr_te1_alarm(struct fst_card_info
*card
, struct fst_port_info
*port
)
1075 los
= FST_RDB(card
, suStatus
.lossOfSignal
);
1076 rra
= FST_RDB(card
, suStatus
.receiveRemoteAlarm
);
1077 ais
= FST_RDB(card
, suStatus
.alarmIndicationSignal
);
1083 if (netif_carrier_ok(port_to_dev(port
))) {
1084 dbg(DBG_INTR
, "Net carrier off\n");
1085 netif_carrier_off(port_to_dev(port
));
1091 if (!netif_carrier_ok(port_to_dev(port
))) {
1092 dbg(DBG_INTR
, "Net carrier on\n");
1093 netif_carrier_on(port_to_dev(port
));
1098 dbg(DBG_INTR
, "Assert LOS Alarm\n");
1100 dbg(DBG_INTR
, "De-assert LOS Alarm\n");
1102 dbg(DBG_INTR
, "Assert RRA Alarm\n");
1104 dbg(DBG_INTR
, "De-assert RRA Alarm\n");
1107 dbg(DBG_INTR
, "Assert AIS Alarm\n");
1109 dbg(DBG_INTR
, "De-assert AIS Alarm\n");
1112 /* Control signal change interrupt event
1115 fst_intr_ctlchg(struct fst_card_info
*card
, struct fst_port_info
*port
)
1119 signals
= FST_RDL(card
, v24DebouncedSts
[port
->index
]);
1121 if (signals
& (((port
->hwif
== X21
) || (port
->hwif
== X21D
))
1122 ? IPSTS_INDICATE
: IPSTS_DCD
)) {
1123 if (!netif_carrier_ok(port_to_dev(port
))) {
1124 dbg(DBG_INTR
, "DCD active\n");
1125 netif_carrier_on(port_to_dev(port
));
1128 if (netif_carrier_ok(port_to_dev(port
))) {
1129 dbg(DBG_INTR
, "DCD lost\n");
1130 netif_carrier_off(port_to_dev(port
));
1138 fst_log_rx_error(struct fst_card_info
*card
, struct fst_port_info
*port
,
1139 unsigned char dmabits
, int rxp
, unsigned short len
)
1141 struct net_device
*dev
= port_to_dev(port
);
1144 * Increment the appropriate error counter
1146 dev
->stats
.rx_errors
++;
1147 if (dmabits
& RX_OFLO
) {
1148 dev
->stats
.rx_fifo_errors
++;
1149 dbg(DBG_ASS
, "Rx fifo error on card %d port %d buffer %d\n",
1150 card
->card_no
, port
->index
, rxp
);
1152 if (dmabits
& RX_CRC
) {
1153 dev
->stats
.rx_crc_errors
++;
1154 dbg(DBG_ASS
, "Rx crc error on card %d port %d\n",
1155 card
->card_no
, port
->index
);
1157 if (dmabits
& RX_FRAM
) {
1158 dev
->stats
.rx_frame_errors
++;
1159 dbg(DBG_ASS
, "Rx frame error on card %d port %d\n",
1160 card
->card_no
, port
->index
);
1162 if (dmabits
== (RX_STP
| RX_ENP
)) {
1163 dev
->stats
.rx_length_errors
++;
1164 dbg(DBG_ASS
, "Rx length error (%d) on card %d port %d\n",
1165 len
, card
->card_no
, port
->index
);
1169 /* Rx Error Recovery
1172 fst_recover_rx_error(struct fst_card_info
*card
, struct fst_port_info
*port
,
1173 unsigned char dmabits
, int rxp
, unsigned short len
)
1180 * Discard buffer descriptors until we see the start of the
1181 * next frame. Note that for long frames this could be in
1182 * a subsequent interrupt.
1185 while ((dmabits
& (DMA_OWN
| RX_STP
)) == 0) {
1186 FST_WRB(card
, rxDescrRing
[pi
][rxp
].bits
, DMA_OWN
);
1187 rxp
= (rxp
+1) % NUM_RX_BUFFER
;
1188 if (++i
> NUM_RX_BUFFER
) {
1189 dbg(DBG_ASS
, "intr_rx: Discarding more bufs"
1193 dmabits
= FST_RDB(card
, rxDescrRing
[pi
][rxp
].bits
);
1194 dbg(DBG_ASS
, "DMA Bits of next buffer was %x\n", dmabits
);
1196 dbg(DBG_ASS
, "There were %d subsequent buffers in error\n", i
);
1198 /* Discard the terminal buffer */
1199 if (!(dmabits
& DMA_OWN
)) {
1200 FST_WRB(card
, rxDescrRing
[pi
][rxp
].bits
, DMA_OWN
);
1201 rxp
= (rxp
+1) % NUM_RX_BUFFER
;
1208 /* Rx complete interrupt
1211 fst_intr_rx(struct fst_card_info
*card
, struct fst_port_info
*port
)
1213 unsigned char dmabits
;
1218 struct sk_buff
*skb
;
1219 struct net_device
*dev
= port_to_dev(port
);
1221 /* Check we have a buffer to process */
1224 dmabits
= FST_RDB(card
, rxDescrRing
[pi
][rxp
].bits
);
1225 if (dmabits
& DMA_OWN
) {
1226 dbg(DBG_RX
| DBG_INTR
, "intr_rx: No buffer port %d pos %d\n",
1230 if (card
->dmarx_in_progress
) {
1234 /* Get buffer length */
1235 len
= FST_RDW(card
, rxDescrRing
[pi
][rxp
].mcnt
);
1236 /* Discard the CRC */
1240 * This seems to happen on the TE1 interface sometimes
1241 * so throw the frame away and log the event.
1243 printk_err("Frame received with 0 length. Card %d Port %d\n",
1244 card
->card_no
, port
->index
);
1245 /* Return descriptor to card */
1246 FST_WRB(card
, rxDescrRing
[pi
][rxp
].bits
, DMA_OWN
);
1248 rxp
= (rxp
+1) % NUM_RX_BUFFER
;
1253 /* Check buffer length and for other errors. We insist on one packet
1254 * in one buffer. This simplifies things greatly and since we've
1255 * allocated 8K it shouldn't be a real world limitation
1257 dbg(DBG_RX
, "intr_rx: %d,%d: flags %x len %d\n", pi
, rxp
, dmabits
, len
);
1258 if (dmabits
!= (RX_STP
| RX_ENP
) || len
> LEN_RX_BUFFER
- 2) {
1259 fst_log_rx_error(card
, port
, dmabits
, rxp
, len
);
1260 fst_recover_rx_error(card
, port
, dmabits
, rxp
, len
);
1265 if ((skb
= dev_alloc_skb(len
)) == NULL
) {
1266 dbg(DBG_RX
, "intr_rx: can't allocate buffer\n");
1268 dev
->stats
.rx_dropped
++;
1270 /* Return descriptor to card */
1271 FST_WRB(card
, rxDescrRing
[pi
][rxp
].bits
, DMA_OWN
);
1273 rxp
= (rxp
+1) % NUM_RX_BUFFER
;
1279 * We know the length we need to receive, len.
1280 * It's not worth using the DMA for reads of less than
1284 if ((len
< FST_MIN_DMA_LEN
) || (card
->family
== FST_FAMILY_TXP
)) {
1285 memcpy_fromio(skb_put(skb
, len
),
1286 card
->mem
+ BUF_OFFSET(rxBuffer
[pi
][rxp
][0]),
1289 /* Reset buffer descriptor */
1290 FST_WRB(card
, rxDescrRing
[pi
][rxp
].bits
, DMA_OWN
);
1293 dev
->stats
.rx_packets
++;
1294 dev
->stats
.rx_bytes
+= len
;
1297 dbg(DBG_RX
, "Pushing frame up the stack\n");
1298 if (port
->mode
== FST_RAW
)
1299 skb
->protocol
= farsync_type_trans(skb
, dev
);
1301 skb
->protocol
= hdlc_type_trans(skb
, dev
);
1302 rx_status
= netif_rx(skb
);
1303 fst_process_rx_status(rx_status
, port_to_dev(port
)->name
);
1304 if (rx_status
== NET_RX_DROP
)
1305 dev
->stats
.rx_dropped
++;
1307 card
->dma_skb_rx
= skb
;
1308 card
->dma_port_rx
= port
;
1309 card
->dma_len_rx
= len
;
1310 card
->dma_rxpos
= rxp
;
1311 fst_rx_dma(card
, (char *) card
->rx_dma_handle_card
,
1312 (char *) BUF_OFFSET(rxBuffer
[pi
][rxp
][0]), len
);
1314 if (rxp
!= port
->rxpos
) {
1315 dbg(DBG_ASS
, "About to increment rxpos by more than 1\n");
1316 dbg(DBG_ASS
, "rxp = %d rxpos = %d\n", rxp
, port
->rxpos
);
1318 rxp
= (rxp
+1) % NUM_RX_BUFFER
;
1323 * The bottom halfs to the ISR
1328 do_bottom_half_tx(struct fst_card_info
*card
)
1330 struct fst_port_info
*port
;
1333 struct sk_buff
*skb
;
1334 unsigned long flags
;
1335 struct net_device
*dev
;
1338 * Find a free buffer for the transmit
1339 * Step through each port on this card
1342 dbg(DBG_TX
, "do_bottom_half_tx\n");
1343 for (pi
= 0, port
= card
->ports
; pi
< card
->nports
; pi
++, port
++) {
1347 dev
= port_to_dev(port
);
1348 while (!(FST_RDB(card
, txDescrRing
[pi
][port
->txpos
].bits
) &
1350 && !(card
->dmatx_in_progress
)) {
1352 * There doesn't seem to be a txdone event per-se
1353 * We seem to have to deduce it, by checking the DMA_OWN
1354 * bit on the next buffer we think we can use
1356 spin_lock_irqsave(&card
->card_lock
, flags
);
1357 if ((txq_length
= port
->txqe
- port
->txqs
) < 0) {
1359 * This is the case where one has wrapped and the
1360 * maths gives us a negative number
1362 txq_length
= txq_length
+ FST_TXQ_DEPTH
;
1364 spin_unlock_irqrestore(&card
->card_lock
, flags
);
1365 if (txq_length
> 0) {
1367 * There is something to send
1369 spin_lock_irqsave(&card
->card_lock
, flags
);
1370 skb
= port
->txq
[port
->txqs
];
1372 if (port
->txqs
== FST_TXQ_DEPTH
) {
1375 spin_unlock_irqrestore(&card
->card_lock
, flags
);
1377 * copy the data and set the required indicators on the
1380 FST_WRW(card
, txDescrRing
[pi
][port
->txpos
].bcnt
,
1381 cnv_bcnt(skb
->len
));
1382 if ((skb
->len
< FST_MIN_DMA_LEN
)
1383 || (card
->family
== FST_FAMILY_TXP
)) {
1384 /* Enqueue the packet with normal io */
1385 memcpy_toio(card
->mem
+
1386 BUF_OFFSET(txBuffer
[pi
]
1389 skb
->data
, skb
->len
);
1391 txDescrRing
[pi
][port
->txpos
].
1393 DMA_OWN
| TX_STP
| TX_ENP
);
1394 dev
->stats
.tx_packets
++;
1395 dev
->stats
.tx_bytes
+= skb
->len
;
1396 dev
->trans_start
= jiffies
;
1398 /* Or do it through dma */
1399 memcpy(card
->tx_dma_handle_host
,
1400 skb
->data
, skb
->len
);
1401 card
->dma_port_tx
= port
;
1402 card
->dma_len_tx
= skb
->len
;
1403 card
->dma_txpos
= port
->txpos
;
1408 BUF_OFFSET(txBuffer
[pi
]
1412 if (++port
->txpos
>= NUM_TX_BUFFER
)
1415 * If we have flow control on, can we now release it?
1418 if (txq_length
< fst_txq_low
) {
1419 netif_wake_queue(port_to_dev
1427 * Nothing to send so break out of the while loop
1436 do_bottom_half_rx(struct fst_card_info
*card
)
1438 struct fst_port_info
*port
;
1442 /* Check for rx completions on all ports on this card */
1443 dbg(DBG_RX
, "do_bottom_half_rx\n");
1444 for (pi
= 0, port
= card
->ports
; pi
< card
->nports
; pi
++, port
++) {
1448 while (!(FST_RDB(card
, rxDescrRing
[pi
][port
->rxpos
].bits
)
1449 & DMA_OWN
) && !(card
->dmarx_in_progress
)) {
1450 if (rx_count
> fst_max_reads
) {
1452 * Don't spend forever in receive processing
1453 * Schedule another event
1455 fst_q_work_item(&fst_work_intq
, card
->card_no
);
1456 tasklet_schedule(&fst_int_task
);
1457 break; /* Leave the loop */
1459 fst_intr_rx(card
, port
);
1466 * The interrupt service routine
1467 * Dev_id is our fst_card_info pointer
1470 fst_intr(int dummy
, void *dev_id
)
1472 struct fst_card_info
*card
= dev_id
;
1473 struct fst_port_info
*port
;
1474 int rdidx
; /* Event buffer indices */
1476 int event
; /* Actual event for processing */
1477 unsigned int dma_intcsr
= 0;
1478 unsigned int do_card_interrupt
;
1479 unsigned int int_retry_count
;
1482 * Check to see if the interrupt was for this card
1484 * Note that the call to clear the interrupt is important
1486 dbg(DBG_INTR
, "intr: %d %p\n", card
->irq
, card
);
1487 if (card
->state
!= FST_RUNNING
) {
1489 ("Interrupt received for card %d in a non running state (%d)\n",
1490 card
->card_no
, card
->state
);
1493 * It is possible to really be running, i.e. we have re-loaded
1495 * Clear and reprime the interrupt source
1497 fst_clear_intr(card
);
1501 /* Clear and reprime the interrupt source */
1502 fst_clear_intr(card
);
1505 * Is the interrupt for this card (handshake == 1)
1507 do_card_interrupt
= 0;
1508 if (FST_RDB(card
, interruptHandshake
) == 1) {
1509 do_card_interrupt
+= FST_CARD_INT
;
1510 /* Set the software acknowledge */
1511 FST_WRB(card
, interruptHandshake
, 0xEE);
1513 if (card
->family
== FST_FAMILY_TXU
) {
1515 * Is it a DMA Interrupt
1517 dma_intcsr
= inl(card
->pci_conf
+ INTCSR_9054
);
1518 if (dma_intcsr
& 0x00200000) {
1520 * DMA Channel 0 (Rx transfer complete)
1522 dbg(DBG_RX
, "DMA Rx xfer complete\n");
1523 outb(0x8, card
->pci_conf
+ DMACSR0
);
1524 fst_rx_dma_complete(card
, card
->dma_port_rx
,
1525 card
->dma_len_rx
, card
->dma_skb_rx
,
1527 card
->dmarx_in_progress
= 0;
1528 do_card_interrupt
+= FST_RX_DMA_INT
;
1530 if (dma_intcsr
& 0x00400000) {
1532 * DMA Channel 1 (Tx transfer complete)
1534 dbg(DBG_TX
, "DMA Tx xfer complete\n");
1535 outb(0x8, card
->pci_conf
+ DMACSR1
);
1536 fst_tx_dma_complete(card
, card
->dma_port_tx
,
1537 card
->dma_len_tx
, card
->dma_txpos
);
1538 card
->dmatx_in_progress
= 0;
1539 do_card_interrupt
+= FST_TX_DMA_INT
;
1544 * Have we been missing Interrupts
1546 int_retry_count
= FST_RDL(card
, interruptRetryCount
);
1547 if (int_retry_count
) {
1548 dbg(DBG_ASS
, "Card %d int_retry_count is %d\n",
1549 card
->card_no
, int_retry_count
);
1550 FST_WRL(card
, interruptRetryCount
, 0);
1553 if (!do_card_interrupt
) {
1557 /* Scehdule the bottom half of the ISR */
1558 fst_q_work_item(&fst_work_intq
, card
->card_no
);
1559 tasklet_schedule(&fst_int_task
);
1561 /* Drain the event queue */
1562 rdidx
= FST_RDB(card
, interruptEvent
.rdindex
) & 0x1f;
1563 wridx
= FST_RDB(card
, interruptEvent
.wrindex
) & 0x1f;
1564 while (rdidx
!= wridx
) {
1565 event
= FST_RDB(card
, interruptEvent
.evntbuff
[rdidx
]);
1566 port
= &card
->ports
[event
& 0x03];
1568 dbg(DBG_INTR
, "Processing Interrupt event: %x\n", event
);
1572 dbg(DBG_INTR
, "TE1 Alarm intr\n");
1574 fst_intr_te1_alarm(card
, port
);
1582 fst_intr_ctlchg(card
, port
);
1589 dbg(DBG_TX
, "Abort complete port %d\n", port
->index
);
1596 /* Difficult to see how we'd get this given that we
1597 * always load up the entire packet for DMA.
1599 dbg(DBG_TX
, "Tx underflow port %d\n", port
->index
);
1600 port_to_dev(port
)->stats
.tx_errors
++;
1601 port_to_dev(port
)->stats
.tx_fifo_errors
++;
1602 dbg(DBG_ASS
, "Tx underflow on card %d port %d\n",
1603 card
->card_no
, port
->index
);
1607 dbg(DBG_INIT
, "Card init OK intr\n");
1611 dbg(DBG_INIT
, "Card init FAILED intr\n");
1612 card
->state
= FST_IFAILED
;
1616 printk_err("intr: unknown card event %d. ignored\n",
1621 /* Bump and wrap the index */
1622 if (++rdidx
>= MAX_CIRBUFF
)
1625 FST_WRB(card
, interruptEvent
.rdindex
, rdidx
);
1629 /* Check that the shared memory configuration is one that we can handle
1630 * and that some basic parameters are correct
1633 check_started_ok(struct fst_card_info
*card
)
1637 /* Check structure version and end marker */
1638 if (FST_RDW(card
, smcVersion
) != SMC_VERSION
) {
1639 printk_err("Bad shared memory version %d expected %d\n",
1640 FST_RDW(card
, smcVersion
), SMC_VERSION
);
1641 card
->state
= FST_BADVERSION
;
1644 if (FST_RDL(card
, endOfSmcSignature
) != END_SIG
) {
1645 printk_err("Missing shared memory signature\n");
1646 card
->state
= FST_BADVERSION
;
1649 /* Firmware status flag, 0x00 = initialising, 0x01 = OK, 0xFF = fail */
1650 if ((i
= FST_RDB(card
, taskStatus
)) == 0x01) {
1651 card
->state
= FST_RUNNING
;
1652 } else if (i
== 0xFF) {
1653 printk_err("Firmware initialisation failed. Card halted\n");
1654 card
->state
= FST_HALTED
;
1656 } else if (i
!= 0x00) {
1657 printk_err("Unknown firmware status 0x%x\n", i
);
1658 card
->state
= FST_HALTED
;
1662 /* Finally check the number of ports reported by firmware against the
1663 * number we assumed at card detection. Should never happen with
1664 * existing firmware etc so we just report it for the moment.
1666 if (FST_RDL(card
, numberOfPorts
) != card
->nports
) {
1667 printk_warn("Port count mismatch on card %d."
1668 " Firmware thinks %d we say %d\n", card
->card_no
,
1669 FST_RDL(card
, numberOfPorts
), card
->nports
);
1674 set_conf_from_info(struct fst_card_info
*card
, struct fst_port_info
*port
,
1675 struct fstioc_info
*info
)
1678 unsigned char my_framing
;
1680 /* Set things according to the user set valid flags
1681 * Several of the old options have been invalidated/replaced by the
1682 * generic hdlc package.
1685 if (info
->valid
& FSTVAL_PROTO
) {
1686 if (info
->proto
== FST_RAW
)
1687 port
->mode
= FST_RAW
;
1689 port
->mode
= FST_GEN_HDLC
;
1692 if (info
->valid
& FSTVAL_CABLE
)
1695 if (info
->valid
& FSTVAL_SPEED
)
1698 if (info
->valid
& FSTVAL_PHASE
)
1699 FST_WRB(card
, portConfig
[port
->index
].invertClock
,
1701 if (info
->valid
& FSTVAL_MODE
)
1702 FST_WRW(card
, cardMode
, info
->cardMode
);
1703 if (info
->valid
& FSTVAL_TE1
) {
1704 FST_WRL(card
, suConfig
.dataRate
, info
->lineSpeed
);
1705 FST_WRB(card
, suConfig
.clocking
, info
->clockSource
);
1706 my_framing
= FRAMING_E1
;
1707 if (info
->framing
== E1
)
1708 my_framing
= FRAMING_E1
;
1709 if (info
->framing
== T1
)
1710 my_framing
= FRAMING_T1
;
1711 if (info
->framing
== J1
)
1712 my_framing
= FRAMING_J1
;
1713 FST_WRB(card
, suConfig
.framing
, my_framing
);
1714 FST_WRB(card
, suConfig
.structure
, info
->structure
);
1715 FST_WRB(card
, suConfig
.interface
, info
->interface
);
1716 FST_WRB(card
, suConfig
.coding
, info
->coding
);
1717 FST_WRB(card
, suConfig
.lineBuildOut
, info
->lineBuildOut
);
1718 FST_WRB(card
, suConfig
.equalizer
, info
->equalizer
);
1719 FST_WRB(card
, suConfig
.transparentMode
, info
->transparentMode
);
1720 FST_WRB(card
, suConfig
.loopMode
, info
->loopMode
);
1721 FST_WRB(card
, suConfig
.range
, info
->range
);
1722 FST_WRB(card
, suConfig
.txBufferMode
, info
->txBufferMode
);
1723 FST_WRB(card
, suConfig
.rxBufferMode
, info
->rxBufferMode
);
1724 FST_WRB(card
, suConfig
.startingSlot
, info
->startingSlot
);
1725 FST_WRB(card
, suConfig
.losThreshold
, info
->losThreshold
);
1727 FST_WRB(card
, suConfig
.enableIdleCode
, 1);
1729 FST_WRB(card
, suConfig
.enableIdleCode
, 0);
1730 FST_WRB(card
, suConfig
.idleCode
, info
->idleCode
);
1732 if (info
->valid
& FSTVAL_TE1
) {
1733 printk("Setting TE1 data\n");
1734 printk("Line Speed = %d\n", info
->lineSpeed
);
1735 printk("Start slot = %d\n", info
->startingSlot
);
1736 printk("Clock source = %d\n", info
->clockSource
);
1737 printk("Framing = %d\n", my_framing
);
1738 printk("Structure = %d\n", info
->structure
);
1739 printk("interface = %d\n", info
->interface
);
1740 printk("Coding = %d\n", info
->coding
);
1741 printk("Line build out = %d\n", info
->lineBuildOut
);
1742 printk("Equaliser = %d\n", info
->equalizer
);
1743 printk("Transparent mode = %d\n",
1744 info
->transparentMode
);
1745 printk("Loop mode = %d\n", info
->loopMode
);
1746 printk("Range = %d\n", info
->range
);
1747 printk("Tx Buffer mode = %d\n", info
->txBufferMode
);
1748 printk("Rx Buffer mode = %d\n", info
->rxBufferMode
);
1749 printk("LOS Threshold = %d\n", info
->losThreshold
);
1750 printk("Idle Code = %d\n", info
->idleCode
);
1755 if (info
->valid
& FSTVAL_DEBUG
) {
1756 fst_debug_mask
= info
->debug
;
1764 gather_conf_info(struct fst_card_info
*card
, struct fst_port_info
*port
,
1765 struct fstioc_info
*info
)
1769 memset(info
, 0, sizeof (struct fstioc_info
));
1772 info
->kernelVersion
= LINUX_VERSION_CODE
;
1773 info
->nports
= card
->nports
;
1774 info
->type
= card
->type
;
1775 info
->state
= card
->state
;
1776 info
->proto
= FST_GEN_HDLC
;
1779 info
->debug
= fst_debug_mask
;
1782 /* Only mark information as valid if card is running.
1783 * Copy the data anyway in case it is useful for diagnostics
1785 info
->valid
= ((card
->state
== FST_RUNNING
) ? FSTVAL_ALL
: FSTVAL_CARD
)
1791 info
->lineInterface
= FST_RDW(card
, portConfig
[i
].lineInterface
);
1792 info
->internalClock
= FST_RDB(card
, portConfig
[i
].internalClock
);
1793 info
->lineSpeed
= FST_RDL(card
, portConfig
[i
].lineSpeed
);
1794 info
->invertClock
= FST_RDB(card
, portConfig
[i
].invertClock
);
1795 info
->v24IpSts
= FST_RDL(card
, v24IpSts
[i
]);
1796 info
->v24OpSts
= FST_RDL(card
, v24OpSts
[i
]);
1797 info
->clockStatus
= FST_RDW(card
, clockStatus
[i
]);
1798 info
->cableStatus
= FST_RDW(card
, cableStatus
);
1799 info
->cardMode
= FST_RDW(card
, cardMode
);
1800 info
->smcFirmwareVersion
= FST_RDL(card
, smcFirmwareVersion
);
1803 * The T2U can report cable presence for both A or B
1804 * in bits 0 and 1 of cableStatus. See which port we are and
1807 if (card
->family
== FST_FAMILY_TXU
) {
1808 if (port
->index
== 0) {
1812 info
->cableStatus
= info
->cableStatus
& 1;
1817 info
->cableStatus
= info
->cableStatus
>> 1;
1818 info
->cableStatus
= info
->cableStatus
& 1;
1822 * Some additional bits if we are TE1
1824 if (card
->type
== FST_TYPE_TE1
) {
1825 info
->lineSpeed
= FST_RDL(card
, suConfig
.dataRate
);
1826 info
->clockSource
= FST_RDB(card
, suConfig
.clocking
);
1827 info
->framing
= FST_RDB(card
, suConfig
.framing
);
1828 info
->structure
= FST_RDB(card
, suConfig
.structure
);
1829 info
->interface
= FST_RDB(card
, suConfig
.interface
);
1830 info
->coding
= FST_RDB(card
, suConfig
.coding
);
1831 info
->lineBuildOut
= FST_RDB(card
, suConfig
.lineBuildOut
);
1832 info
->equalizer
= FST_RDB(card
, suConfig
.equalizer
);
1833 info
->loopMode
= FST_RDB(card
, suConfig
.loopMode
);
1834 info
->range
= FST_RDB(card
, suConfig
.range
);
1835 info
->txBufferMode
= FST_RDB(card
, suConfig
.txBufferMode
);
1836 info
->rxBufferMode
= FST_RDB(card
, suConfig
.rxBufferMode
);
1837 info
->startingSlot
= FST_RDB(card
, suConfig
.startingSlot
);
1838 info
->losThreshold
= FST_RDB(card
, suConfig
.losThreshold
);
1839 if (FST_RDB(card
, suConfig
.enableIdleCode
))
1840 info
->idleCode
= FST_RDB(card
, suConfig
.idleCode
);
1843 info
->receiveBufferDelay
=
1844 FST_RDL(card
, suStatus
.receiveBufferDelay
);
1845 info
->framingErrorCount
=
1846 FST_RDL(card
, suStatus
.framingErrorCount
);
1847 info
->codeViolationCount
=
1848 FST_RDL(card
, suStatus
.codeViolationCount
);
1849 info
->crcErrorCount
= FST_RDL(card
, suStatus
.crcErrorCount
);
1850 info
->lineAttenuation
= FST_RDL(card
, suStatus
.lineAttenuation
);
1851 info
->lossOfSignal
= FST_RDB(card
, suStatus
.lossOfSignal
);
1852 info
->receiveRemoteAlarm
=
1853 FST_RDB(card
, suStatus
.receiveRemoteAlarm
);
1854 info
->alarmIndicationSignal
=
1855 FST_RDB(card
, suStatus
.alarmIndicationSignal
);
1860 fst_set_iface(struct fst_card_info
*card
, struct fst_port_info
*port
,
1863 sync_serial_settings sync
;
1866 if (ifr
->ifr_settings
.size
!= sizeof (sync
)) {
1871 (&sync
, ifr
->ifr_settings
.ifs_ifsu
.sync
, sizeof (sync
))) {
1880 switch (ifr
->ifr_settings
.type
) {
1882 FST_WRW(card
, portConfig
[i
].lineInterface
, V35
);
1887 FST_WRW(card
, portConfig
[i
].lineInterface
, V24
);
1892 FST_WRW(card
, portConfig
[i
].lineInterface
, X21
);
1897 FST_WRW(card
, portConfig
[i
].lineInterface
, X21D
);
1902 FST_WRW(card
, portConfig
[i
].lineInterface
, T1
);
1907 FST_WRW(card
, portConfig
[i
].lineInterface
, E1
);
1911 case IF_IFACE_SYNC_SERIAL
:
1918 switch (sync
.clock_type
) {
1920 FST_WRB(card
, portConfig
[i
].internalClock
, EXTCLK
);
1924 FST_WRB(card
, portConfig
[i
].internalClock
, INTCLK
);
1930 FST_WRL(card
, portConfig
[i
].lineSpeed
, sync
.clock_rate
);
1935 fst_get_iface(struct fst_card_info
*card
, struct fst_port_info
*port
,
1938 sync_serial_settings sync
;
1941 /* First check what line type is set, we'll default to reporting X.21
1942 * if nothing is set as IF_IFACE_SYNC_SERIAL implies it can't be
1945 switch (port
->hwif
) {
1947 ifr
->ifr_settings
.type
= IF_IFACE_E1
;
1950 ifr
->ifr_settings
.type
= IF_IFACE_T1
;
1953 ifr
->ifr_settings
.type
= IF_IFACE_V35
;
1956 ifr
->ifr_settings
.type
= IF_IFACE_V24
;
1959 ifr
->ifr_settings
.type
= IF_IFACE_X21D
;
1963 ifr
->ifr_settings
.type
= IF_IFACE_X21
;
1966 if (ifr
->ifr_settings
.size
== 0) {
1967 return 0; /* only type requested */
1969 if (ifr
->ifr_settings
.size
< sizeof (sync
)) {
1974 sync
.clock_rate
= FST_RDL(card
, portConfig
[i
].lineSpeed
);
1975 /* Lucky card and linux use same encoding here */
1976 sync
.clock_type
= FST_RDB(card
, portConfig
[i
].internalClock
) ==
1977 INTCLK
? CLOCK_INT
: CLOCK_EXT
;
1980 if (copy_to_user(ifr
->ifr_settings
.ifs_ifsu
.sync
, &sync
, sizeof (sync
))) {
1984 ifr
->ifr_settings
.size
= sizeof (sync
);
1989 fst_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
1991 struct fst_card_info
*card
;
1992 struct fst_port_info
*port
;
1993 struct fstioc_write wrthdr
;
1994 struct fstioc_info info
;
1995 unsigned long flags
;
1998 dbg(DBG_IOCTL
, "ioctl: %x, %p\n", cmd
, ifr
->ifr_data
);
2000 port
= dev_to_port(dev
);
2003 if (!capable(CAP_NET_ADMIN
))
2009 card
->state
= FST_RESET
;
2013 fst_cpurelease(card
);
2014 card
->state
= FST_STARTING
;
2017 case FSTWRITE
: /* Code write (download) */
2019 /* First copy in the header with the length and offset of data
2022 if (ifr
->ifr_data
== NULL
) {
2025 if (copy_from_user(&wrthdr
, ifr
->ifr_data
,
2026 sizeof (struct fstioc_write
))) {
2030 /* Sanity check the parameters. We don't support partial writes
2031 * when going over the top
2033 if (wrthdr
.size
> FST_MEMSIZE
|| wrthdr
.offset
> FST_MEMSIZE
2034 || wrthdr
.size
+ wrthdr
.offset
> FST_MEMSIZE
) {
2038 /* Now copy the data to the card. */
2040 buf
= kmalloc(wrthdr
.size
, GFP_KERNEL
);
2044 if (copy_from_user(buf
,
2045 ifr
->ifr_data
+ sizeof (struct fstioc_write
),
2051 memcpy_toio(card
->mem
+ wrthdr
.offset
, buf
, wrthdr
.size
);
2054 /* Writes to the memory of a card in the reset state constitute
2057 if (card
->state
== FST_RESET
) {
2058 card
->state
= FST_DOWNLOAD
;
2064 /* If card has just been started check the shared memory config
2065 * version and marker
2067 if (card
->state
== FST_STARTING
) {
2068 check_started_ok(card
);
2070 /* If everything checked out enable card interrupts */
2071 if (card
->state
== FST_RUNNING
) {
2072 spin_lock_irqsave(&card
->card_lock
, flags
);
2073 fst_enable_intr(card
);
2074 FST_WRB(card
, interruptHandshake
, 0xEE);
2075 spin_unlock_irqrestore(&card
->card_lock
, flags
);
2079 if (ifr
->ifr_data
== NULL
) {
2083 gather_conf_info(card
, port
, &info
);
2085 if (copy_to_user(ifr
->ifr_data
, &info
, sizeof (info
))) {
2093 * Most of the settings have been moved to the generic ioctls
2094 * this just covers debug and board ident now
2097 if (card
->state
!= FST_RUNNING
) {
2099 ("Attempt to configure card %d in non-running state (%d)\n",
2100 card
->card_no
, card
->state
);
2103 if (copy_from_user(&info
, ifr
->ifr_data
, sizeof (info
))) {
2107 return set_conf_from_info(card
, port
, &info
);
2110 switch (ifr
->ifr_settings
.type
) {
2112 return fst_get_iface(card
, port
, ifr
);
2114 case IF_IFACE_SYNC_SERIAL
:
2121 return fst_set_iface(card
, port
, ifr
);
2124 port
->mode
= FST_RAW
;
2128 if (port
->mode
== FST_RAW
) {
2129 ifr
->ifr_settings
.type
= IF_PROTO_RAW
;
2132 return hdlc_ioctl(dev
, ifr
, cmd
);
2135 port
->mode
= FST_GEN_HDLC
;
2136 dbg(DBG_IOCTL
, "Passing this type to hdlc %x\n",
2137 ifr
->ifr_settings
.type
);
2138 return hdlc_ioctl(dev
, ifr
, cmd
);
2142 /* Not one of ours. Pass through to HDLC package */
2143 return hdlc_ioctl(dev
, ifr
, cmd
);
2148 fst_openport(struct fst_port_info
*port
)
2153 /* Only init things if card is actually running. This allows open to
2154 * succeed for downloads etc.
2156 if (port
->card
->state
== FST_RUNNING
) {
2158 dbg(DBG_OPEN
, "open: found port already running\n");
2160 fst_issue_cmd(port
, STOPPORT
);
2164 fst_rx_config(port
);
2165 fst_tx_config(port
);
2166 fst_op_raise(port
, OPSTS_RTS
| OPSTS_DTR
);
2168 fst_issue_cmd(port
, STARTPORT
);
2171 signals
= FST_RDL(port
->card
, v24DebouncedSts
[port
->index
]);
2172 if (signals
& (((port
->hwif
== X21
) || (port
->hwif
== X21D
))
2173 ? IPSTS_INDICATE
: IPSTS_DCD
))
2174 netif_carrier_on(port_to_dev(port
));
2176 netif_carrier_off(port_to_dev(port
));
2178 txq_length
= port
->txqe
- port
->txqs
;
2186 fst_closeport(struct fst_port_info
*port
)
2188 if (port
->card
->state
== FST_RUNNING
) {
2191 fst_op_lower(port
, OPSTS_RTS
| OPSTS_DTR
);
2193 fst_issue_cmd(port
, STOPPORT
);
2195 dbg(DBG_OPEN
, "close: port not running\n");
2201 fst_open(struct net_device
*dev
)
2204 struct fst_port_info
*port
;
2206 port
= dev_to_port(dev
);
2207 if (!try_module_get(THIS_MODULE
))
2210 if (port
->mode
!= FST_RAW
) {
2211 err
= hdlc_open(dev
);
2217 netif_wake_queue(dev
);
2222 fst_close(struct net_device
*dev
)
2224 struct fst_port_info
*port
;
2225 struct fst_card_info
*card
;
2226 unsigned char tx_dma_done
;
2227 unsigned char rx_dma_done
;
2229 port
= dev_to_port(dev
);
2232 tx_dma_done
= inb(card
->pci_conf
+ DMACSR1
);
2233 rx_dma_done
= inb(card
->pci_conf
+ DMACSR0
);
2235 "Port Close: tx_dma_in_progress = %d (%x) rx_dma_in_progress = %d (%x)\n",
2236 card
->dmatx_in_progress
, tx_dma_done
, card
->dmarx_in_progress
,
2239 netif_stop_queue(dev
);
2240 fst_closeport(dev_to_port(dev
));
2241 if (port
->mode
!= FST_RAW
) {
2244 module_put(THIS_MODULE
);
2249 fst_attach(struct net_device
*dev
, unsigned short encoding
, unsigned short parity
)
2252 * Setting currently fixed in FarSync card so we check and forget
2254 if (encoding
!= ENCODING_NRZ
|| parity
!= PARITY_CRC16_PR1_CCITT
)
2260 fst_tx_timeout(struct net_device
*dev
)
2262 struct fst_port_info
*port
;
2263 struct fst_card_info
*card
;
2265 port
= dev_to_port(dev
);
2267 dev
->stats
.tx_errors
++;
2268 dev
->stats
.tx_aborted_errors
++;
2269 dbg(DBG_ASS
, "Tx timeout card %d port %d\n",
2270 card
->card_no
, port
->index
);
2271 fst_issue_cmd(port
, ABORTTX
);
2273 dev
->trans_start
= jiffies
;
2274 netif_wake_queue(dev
);
2279 fst_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
2281 struct fst_card_info
*card
;
2282 struct fst_port_info
*port
;
2283 unsigned long flags
;
2286 port
= dev_to_port(dev
);
2288 dbg(DBG_TX
, "fst_start_xmit: length = %d\n", skb
->len
);
2290 /* Drop packet with error if we don't have carrier */
2291 if (!netif_carrier_ok(dev
)) {
2293 dev
->stats
.tx_errors
++;
2294 dev
->stats
.tx_carrier_errors
++;
2296 "Tried to transmit but no carrier on card %d port %d\n",
2297 card
->card_no
, port
->index
);
2298 return NETDEV_TX_OK
;
2301 /* Drop it if it's too big! MTU failure ? */
2302 if (skb
->len
> LEN_TX_BUFFER
) {
2303 dbg(DBG_ASS
, "Packet too large %d vs %d\n", skb
->len
,
2306 dev
->stats
.tx_errors
++;
2307 return NETDEV_TX_OK
;
2311 * We are always going to queue the packet
2312 * so that the bottom half is the only place we tx from
2313 * Check there is room in the port txq
2315 spin_lock_irqsave(&card
->card_lock
, flags
);
2316 if ((txq_length
= port
->txqe
- port
->txqs
) < 0) {
2318 * This is the case where the next free has wrapped but the
2321 txq_length
= txq_length
+ FST_TXQ_DEPTH
;
2323 spin_unlock_irqrestore(&card
->card_lock
, flags
);
2324 if (txq_length
> fst_txq_high
) {
2326 * We have got enough buffers in the pipeline. Ask the network
2327 * layer to stop sending frames down
2329 netif_stop_queue(dev
);
2330 port
->start
= 1; /* I'm using this to signal stop sent up */
2333 if (txq_length
== FST_TXQ_DEPTH
- 1) {
2335 * This shouldn't have happened but such is life
2338 dev
->stats
.tx_errors
++;
2339 dbg(DBG_ASS
, "Tx queue overflow card %d port %d\n",
2340 card
->card_no
, port
->index
);
2341 return NETDEV_TX_OK
;
2347 spin_lock_irqsave(&card
->card_lock
, flags
);
2348 port
->txq
[port
->txqe
] = skb
;
2350 if (port
->txqe
== FST_TXQ_DEPTH
)
2352 spin_unlock_irqrestore(&card
->card_lock
, flags
);
2354 /* Scehdule the bottom half which now does transmit processing */
2355 fst_q_work_item(&fst_work_txq
, card
->card_no
);
2356 tasklet_schedule(&fst_tx_task
);
2358 return NETDEV_TX_OK
;
2362 * Card setup having checked hardware resources.
2363 * Should be pretty bizarre if we get an error here (kernel memory
2364 * exhaustion is one possibility). If we do see a problem we report it
2365 * via a printk and leave the corresponding interface and all that follow
2368 static char *type_strings
[] __devinitdata
= {
2369 "no hardware", /* Should never be seen */
2378 static void __devinit
2379 fst_init_card(struct fst_card_info
*card
)
2384 /* We're working on a number of ports based on the card ID. If the
2385 * firmware detects something different later (should never happen)
2386 * we'll have to revise it in some way then.
2388 for (i
= 0; i
< card
->nports
; i
++) {
2389 err
= register_hdlc_device(card
->ports
[i
].dev
);
2392 printk_err ("Cannot register HDLC device for port %d"
2393 " (errno %d)\n", i
, -err
);
2394 for (j
= i
; j
< card
->nports
; j
++) {
2395 free_netdev(card
->ports
[j
].dev
);
2396 card
->ports
[j
].dev
= NULL
;
2403 printk_info("%s-%s: %s IRQ%d, %d ports\n",
2404 port_to_dev(&card
->ports
[0])->name
,
2405 port_to_dev(&card
->ports
[card
->nports
- 1])->name
,
2406 type_strings
[card
->type
], card
->irq
, card
->nports
);
2409 static const struct net_device_ops fst_ops
= {
2410 .ndo_open
= fst_open
,
2411 .ndo_stop
= fst_close
,
2412 .ndo_change_mtu
= hdlc_change_mtu
,
2413 .ndo_start_xmit
= hdlc_start_xmit
,
2414 .ndo_do_ioctl
= fst_ioctl
,
2415 .ndo_tx_timeout
= fst_tx_timeout
,
2419 * Initialise card when detected.
2420 * Returns 0 to indicate success, or errno otherwise.
2422 static int __devinit
2423 fst_add_one(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
2425 static int firsttime_done
= 0;
2426 static int no_of_cards_added
= 0;
2427 struct fst_card_info
*card
;
2431 if (!firsttime_done
) {
2432 printk_info("FarSync WAN driver " FST_USER_VERSION
2433 " (c) 2001-2004 FarSite Communications Ltd.\n");
2435 dbg(DBG_ASS
, "The value of debug mask is %x\n", fst_debug_mask
);
2439 * We are going to be clever and allow certain cards not to be
2440 * configured. An exclude list can be provided in /etc/modules.conf
2442 if (fst_excluded_cards
!= 0) {
2444 * There are cards to exclude
2447 for (i
= 0; i
< fst_excluded_cards
; i
++) {
2448 if ((pdev
->devfn
) >> 3 == fst_excluded_list
[i
]) {
2449 printk_info("FarSync PCI device %d not assigned\n",
2450 (pdev
->devfn
) >> 3);
2456 /* Allocate driver private data */
2457 card
= kzalloc(sizeof (struct fst_card_info
), GFP_KERNEL
);
2459 printk_err("FarSync card found but insufficient memory for"
2460 " driver storage\n");
2464 /* Try to enable the device */
2465 if ((err
= pci_enable_device(pdev
)) != 0) {
2466 printk_err("Failed to enable card. Err %d\n", -err
);
2471 if ((err
= pci_request_regions(pdev
, "FarSync")) !=0) {
2472 printk_err("Failed to allocate regions. Err %d\n", -err
);
2473 pci_disable_device(pdev
);
2478 /* Get virtual addresses of memory regions */
2479 card
->pci_conf
= pci_resource_start(pdev
, 1);
2480 card
->phys_mem
= pci_resource_start(pdev
, 2);
2481 card
->phys_ctlmem
= pci_resource_start(pdev
, 3);
2482 if ((card
->mem
= ioremap(card
->phys_mem
, FST_MEMSIZE
)) == NULL
) {
2483 printk_err("Physical memory remap failed\n");
2484 pci_release_regions(pdev
);
2485 pci_disable_device(pdev
);
2489 if ((card
->ctlmem
= ioremap(card
->phys_ctlmem
, 0x10)) == NULL
) {
2490 printk_err("Control memory remap failed\n");
2491 pci_release_regions(pdev
);
2492 pci_disable_device(pdev
);
2496 dbg(DBG_PCI
, "kernel mem %p, ctlmem %p\n", card
->mem
, card
->ctlmem
);
2498 /* Register the interrupt handler */
2499 if (request_irq(pdev
->irq
, fst_intr
, IRQF_SHARED
, FST_DEV_NAME
, card
)) {
2500 printk_err("Unable to register interrupt %d\n", card
->irq
);
2501 pci_release_regions(pdev
);
2502 pci_disable_device(pdev
);
2503 iounmap(card
->ctlmem
);
2509 /* Record info we need */
2510 card
->irq
= pdev
->irq
;
2511 card
->type
= ent
->driver_data
;
2512 card
->family
= ((ent
->driver_data
== FST_TYPE_T2P
) ||
2513 (ent
->driver_data
== FST_TYPE_T4P
))
2514 ? FST_FAMILY_TXP
: FST_FAMILY_TXU
;
2515 if ((ent
->driver_data
== FST_TYPE_T1U
) ||
2516 (ent
->driver_data
== FST_TYPE_TE1
))
2519 card
->nports
= ((ent
->driver_data
== FST_TYPE_T2P
) ||
2520 (ent
->driver_data
== FST_TYPE_T2U
)) ? 2 : 4;
2522 card
->state
= FST_UNINIT
;
2523 spin_lock_init ( &card
->card_lock
);
2525 for ( i
= 0 ; i
< card
->nports
; i
++ ) {
2526 struct net_device
*dev
= alloc_hdlcdev(&card
->ports
[i
]);
2530 free_netdev(card
->ports
[i
].dev
);
2531 printk_err ("FarSync: out of memory\n");
2532 free_irq(card
->irq
, card
);
2533 pci_release_regions(pdev
);
2534 pci_disable_device(pdev
);
2535 iounmap(card
->ctlmem
);
2540 card
->ports
[i
].dev
= dev
;
2541 card
->ports
[i
].card
= card
;
2542 card
->ports
[i
].index
= i
;
2543 card
->ports
[i
].run
= 0;
2545 hdlc
= dev_to_hdlc(dev
);
2547 /* Fill in the net device info */
2548 /* Since this is a PCI setup this is purely
2549 * informational. Give them the buffer addresses
2550 * and basic card I/O.
2552 dev
->mem_start
= card
->phys_mem
2553 + BUF_OFFSET ( txBuffer
[i
][0][0]);
2554 dev
->mem_end
= card
->phys_mem
2555 + BUF_OFFSET ( txBuffer
[i
][NUM_TX_BUFFER
][0]);
2556 dev
->base_addr
= card
->pci_conf
;
2557 dev
->irq
= card
->irq
;
2559 dev
->netdev_ops
= &fst_ops
;
2560 dev
->tx_queue_len
= FST_TX_QUEUE_LEN
;
2561 dev
->watchdog_timeo
= FST_TX_TIMEOUT
;
2562 hdlc
->attach
= fst_attach
;
2563 hdlc
->xmit
= fst_start_xmit
;
2566 card
->device
= pdev
;
2568 dbg(DBG_PCI
, "type %d nports %d irq %d\n", card
->type
,
2569 card
->nports
, card
->irq
);
2570 dbg(DBG_PCI
, "conf %04x mem %08x ctlmem %08x\n",
2571 card
->pci_conf
, card
->phys_mem
, card
->phys_ctlmem
);
2573 /* Reset the card's processor */
2575 card
->state
= FST_RESET
;
2577 /* Initialise DMA (if required) */
2580 /* Record driver data for later use */
2581 pci_set_drvdata(pdev
, card
);
2583 /* Remainder of card setup */
2584 fst_card_array
[no_of_cards_added
] = card
;
2585 card
->card_no
= no_of_cards_added
++; /* Record instance and bump it */
2586 fst_init_card(card
);
2587 if (card
->family
== FST_FAMILY_TXU
) {
2589 * Allocate a dma buffer for transmit and receives
2591 card
->rx_dma_handle_host
=
2592 pci_alloc_consistent(card
->device
, FST_MAX_MTU
,
2593 &card
->rx_dma_handle_card
);
2594 if (card
->rx_dma_handle_host
== NULL
) {
2595 printk_err("Could not allocate rx dma buffer\n");
2596 fst_disable_intr(card
);
2597 pci_release_regions(pdev
);
2598 pci_disable_device(pdev
);
2599 iounmap(card
->ctlmem
);
2604 card
->tx_dma_handle_host
=
2605 pci_alloc_consistent(card
->device
, FST_MAX_MTU
,
2606 &card
->tx_dma_handle_card
);
2607 if (card
->tx_dma_handle_host
== NULL
) {
2608 printk_err("Could not allocate tx dma buffer\n");
2609 fst_disable_intr(card
);
2610 pci_release_regions(pdev
);
2611 pci_disable_device(pdev
);
2612 iounmap(card
->ctlmem
);
2618 return 0; /* Success */
2622 * Cleanup and close down a card
2624 static void __devexit
2625 fst_remove_one(struct pci_dev
*pdev
)
2627 struct fst_card_info
*card
;
2630 card
= pci_get_drvdata(pdev
);
2632 for (i
= 0; i
< card
->nports
; i
++) {
2633 struct net_device
*dev
= port_to_dev(&card
->ports
[i
]);
2634 unregister_hdlc_device(dev
);
2637 fst_disable_intr(card
);
2638 free_irq(card
->irq
, card
);
2640 iounmap(card
->ctlmem
);
2642 pci_release_regions(pdev
);
2643 if (card
->family
== FST_FAMILY_TXU
) {
2647 pci_free_consistent(card
->device
, FST_MAX_MTU
,
2648 card
->rx_dma_handle_host
,
2649 card
->rx_dma_handle_card
);
2650 pci_free_consistent(card
->device
, FST_MAX_MTU
,
2651 card
->tx_dma_handle_host
,
2652 card
->tx_dma_handle_card
);
2654 fst_card_array
[card
->card_no
] = NULL
;
2657 static struct pci_driver fst_driver
= {
2659 .id_table
= fst_pci_dev_id
,
2660 .probe
= fst_add_one
,
2661 .remove
= __devexit_p(fst_remove_one
),
2671 for (i
= 0; i
< FST_MAX_CARDS
; i
++)
2672 fst_card_array
[i
] = NULL
;
2673 spin_lock_init(&fst_work_q_lock
);
2674 return pci_register_driver(&fst_driver
);
2678 fst_cleanup_module(void)
2680 printk_info("FarSync WAN driver unloading\n");
2681 pci_unregister_driver(&fst_driver
);
2684 module_init(fst_init
);
2685 module_exit(fst_cleanup_module
);