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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20 #include <linux/module.h>
21 #include <linux/kernel.h>
22 #include <linux/version.h>
23 #include <linux/pci.h>
24 #include <linux/sched.h>
25 #include <linux/slab.h>
26 #include <linux/ioport.h>
27 #include <linux/init.h>
29 #include <linux/hdlc.h>
31 #include <asm/uaccess.h>
38 MODULE_AUTHOR("R.J.Dunlop <bob.dunlop@farsite.co.uk>");
39 MODULE_DESCRIPTION("FarSync T-Series WAN driver. FarSite Communications Ltd.");
40 MODULE_LICENSE("GPL");
42 /* Driver configuration and global parameters
43 * ==========================================
46 /* Number of ports (per card) and cards supported
48 #define FST_MAX_PORTS 4
49 #define FST_MAX_CARDS 32
51 /* Default parameters for the link
53 #define FST_TX_QUEUE_LEN 100 /* At 8Mbps a longer queue length is
55 #define FST_TXQ_DEPTH 16 /* This one is for the buffering
56 * of frames on the way down to the card
57 * so that we can keep the card busy
58 * and maximise throughput
60 #define FST_HIGH_WATER_MARK 12 /* Point at which we flow control
62 #define FST_LOW_WATER_MARK 8 /* Point at which we remove flow
63 * control from network layer */
64 #define FST_MAX_MTU 8000 /* Huge but possible */
65 #define FST_DEF_MTU 1500 /* Common sane value */
67 #define FST_TX_TIMEOUT (2*HZ)
70 #define ARPHRD_MYTYPE ARPHRD_RAWHDLC /* Raw frames */
72 #define ARPHRD_MYTYPE ARPHRD_HDLC /* Cisco-HDLC (keepalives etc) */
76 * Modules parameters and associated variables
78 static int fst_txq_low
= FST_LOW_WATER_MARK
;
79 static int fst_txq_high
= FST_HIGH_WATER_MARK
;
80 static int fst_max_reads
= 7;
81 static int fst_excluded_cards
= 0;
82 static int fst_excluded_list
[FST_MAX_CARDS
];
84 module_param(fst_txq_low
, int, 0);
85 module_param(fst_txq_high
, int, 0);
86 module_param(fst_max_reads
, int, 0);
87 module_param(fst_excluded_cards
, int, 0);
88 module_param_array(fst_excluded_list
, int, NULL
, 0);
90 /* Card shared memory layout
91 * =========================
95 /* This information is derived in part from the FarSite FarSync Smc.h
96 * file. Unfortunately various name clashes and the non-portability of the
97 * bit field declarations in that file have meant that I have chosen to
98 * recreate the information here.
100 * The SMC (Shared Memory Configuration) has a version number that is
101 * incremented every time there is a significant change. This number can
102 * be used to check that we have not got out of step with the firmware
103 * contained in the .CDE files.
105 #define SMC_VERSION 24
107 #define FST_MEMSIZE 0x100000 /* Size of card memory (1Mb) */
109 #define SMC_BASE 0x00002000L /* Base offset of the shared memory window main
110 * configuration structure */
111 #define BFM_BASE 0x00010000L /* Base offset of the shared memory window DMA
114 #define LEN_TX_BUFFER 8192 /* Size of packet buffers */
115 #define LEN_RX_BUFFER 8192
117 #define LEN_SMALL_TX_BUFFER 256 /* Size of obsolete buffs used for DOS diags */
118 #define LEN_SMALL_RX_BUFFER 256
120 #define NUM_TX_BUFFER 2 /* Must be power of 2. Fixed by firmware */
121 #define NUM_RX_BUFFER 8
123 /* Interrupt retry time in milliseconds */
124 #define INT_RETRY_TIME 2
126 /* The Am186CH/CC processors support a SmartDMA mode using circular pools
127 * of buffer descriptors. The structure is almost identical to that used
128 * in the LANCE Ethernet controllers. Details available as PDF from the
129 * AMD web site: http://www.amd.com/products/epd/processors/\
130 * 2.16bitcont/3.am186cxfa/a21914/21914.pdf
132 struct txdesc
{ /* Transmit descriptor */
133 volatile u16 ladr
; /* Low order address of packet. This is a
134 * linear address in the Am186 memory space
136 volatile u8 hadr
; /* High order address. Low 4 bits only, high 4
139 volatile u8 bits
; /* Status and config */
140 volatile u16 bcnt
; /* 2s complement of packet size in low 15 bits.
141 * Transmit terminal count interrupt enable in
144 u16 unused
; /* Not used in Tx */
147 struct rxdesc
{ /* Receive descriptor */
148 volatile u16 ladr
; /* Low order address of packet */
149 volatile u8 hadr
; /* High order address */
150 volatile u8 bits
; /* Status and config */
151 volatile u16 bcnt
; /* 2s complement of buffer size in low 15 bits.
152 * Receive terminal count interrupt enable in
155 volatile u16 mcnt
; /* Message byte count (15 bits) */
158 /* Convert a length into the 15 bit 2's complement */
159 /* #define cnv_bcnt(len) (( ~(len) + 1 ) & 0x7FFF ) */
160 /* Since we need to set the high bit to enable the completion interrupt this
161 * can be made a lot simpler
163 #define cnv_bcnt(len) (-(len))
165 /* Status and config bits for the above */
166 #define DMA_OWN 0x80 /* SmartDMA owns the descriptor */
167 #define TX_STP 0x02 /* Tx: start of packet */
168 #define TX_ENP 0x01 /* Tx: end of packet */
169 #define RX_ERR 0x40 /* Rx: error (OR of next 4 bits) */
170 #define RX_FRAM 0x20 /* Rx: framing error */
171 #define RX_OFLO 0x10 /* Rx: overflow error */
172 #define RX_CRC 0x08 /* Rx: CRC error */
173 #define RX_HBUF 0x04 /* Rx: buffer error */
174 #define RX_STP 0x02 /* Rx: start of packet */
175 #define RX_ENP 0x01 /* Rx: end of packet */
177 /* Interrupts from the card are caused by various events which are presented
178 * in a circular buffer as several events may be processed on one physical int
180 #define MAX_CIRBUFF 32
183 u8 rdindex
; /* read, then increment and wrap */
184 u8 wrindex
; /* write, then increment and wrap */
185 u8 evntbuff
[MAX_CIRBUFF
];
188 /* Interrupt event codes.
189 * Where appropriate the two low order bits indicate the port number
191 #define CTLA_CHG 0x18 /* Control signal changed */
192 #define CTLB_CHG 0x19
193 #define CTLC_CHG 0x1A
194 #define CTLD_CHG 0x1B
196 #define INIT_CPLT 0x20 /* Initialisation complete */
197 #define INIT_FAIL 0x21 /* Initialisation failed */
199 #define ABTA_SENT 0x24 /* Abort sent */
200 #define ABTB_SENT 0x25
201 #define ABTC_SENT 0x26
202 #define ABTD_SENT 0x27
204 #define TXA_UNDF 0x28 /* Transmission underflow */
205 #define TXB_UNDF 0x29
206 #define TXC_UNDF 0x2A
207 #define TXD_UNDF 0x2B
212 #define TE1_ALMA 0x30
214 /* Port physical configuration. See farsync.h for field values */
216 u16 lineInterface
; /* Physical interface type */
217 u8 x25op
; /* Unused at present */
218 u8 internalClock
; /* 1 => internal clock, 0 => external */
219 u8 transparentMode
; /* 1 => on, 0 => off */
220 u8 invertClock
; /* 0 => normal, 1 => inverted */
221 u8 padBytes
[6]; /* Padding */
222 u32 lineSpeed
; /* Speed in bps */
225 /* TE1 port physical configuration */
249 u32 receiveBufferDelay
;
250 u32 framingErrorCount
;
251 u32 codeViolationCount
;
256 u8 receiveRemoteAlarm
;
257 u8 alarmIndicationSignal
;
261 /* Finally sling all the above together into the shared memory structure.
262 * Sorry it's a hodge podge of arrays, structures and unused bits, it's been
263 * evolving under NT for some time so I guess we're stuck with it.
264 * The structure starts at offset SMC_BASE.
265 * See farsync.h for some field values.
268 /* DMA descriptor rings */
269 struct rxdesc rxDescrRing
[FST_MAX_PORTS
][NUM_RX_BUFFER
];
270 struct txdesc txDescrRing
[FST_MAX_PORTS
][NUM_TX_BUFFER
];
272 /* Obsolete small buffers */
273 u8 smallRxBuffer
[FST_MAX_PORTS
][NUM_RX_BUFFER
][LEN_SMALL_RX_BUFFER
];
274 u8 smallTxBuffer
[FST_MAX_PORTS
][NUM_TX_BUFFER
][LEN_SMALL_TX_BUFFER
];
276 u8 taskStatus
; /* 0x00 => initialising, 0x01 => running,
280 u8 interruptHandshake
; /* Set to 0x01 by adapter to signal interrupt,
281 * set to 0xEE by host to acknowledge interrupt
284 u16 smcVersion
; /* Must match SMC_VERSION */
286 u32 smcFirmwareVersion
; /* 0xIIVVRRBB where II = product ID, VV = major
287 * version, RR = revision and BB = build
290 u16 txa_done
; /* Obsolete completion flags */
299 u16 mailbox
[4]; /* Diagnostics mailbox. Not used */
301 struct cirbuff interruptEvent
; /* interrupt causes */
303 u32 v24IpSts
[FST_MAX_PORTS
]; /* V.24 control input status */
304 u32 v24OpSts
[FST_MAX_PORTS
]; /* V.24 control output status */
306 struct port_cfg portConfig
[FST_MAX_PORTS
];
308 u16 clockStatus
[FST_MAX_PORTS
]; /* lsb: 0=> present, 1=> absent */
310 u16 cableStatus
; /* lsb: 0=> present, 1=> absent */
312 u16 txDescrIndex
[FST_MAX_PORTS
]; /* transmit descriptor ring index */
313 u16 rxDescrIndex
[FST_MAX_PORTS
]; /* receive descriptor ring index */
315 u16 portMailbox
[FST_MAX_PORTS
][2]; /* command, modifier */
316 u16 cardMailbox
[4]; /* Not used */
318 /* Number of times the card thinks the host has
319 * missed an interrupt by not acknowledging
320 * within 2mS (I guess NT has problems)
322 u32 interruptRetryCount
;
324 /* Driver private data used as an ID. We'll not
325 * use this as I'd rather keep such things
326 * in main memory rather than on the PCI bus
328 u32 portHandle
[FST_MAX_PORTS
];
330 /* Count of Tx underflows for stats */
331 u32 transmitBufferUnderflow
[FST_MAX_PORTS
];
333 /* Debounced V.24 control input status */
334 u32 v24DebouncedSts
[FST_MAX_PORTS
];
336 /* Adapter debounce timers. Don't touch */
337 u32 ctsTimer
[FST_MAX_PORTS
];
338 u32 ctsTimerRun
[FST_MAX_PORTS
];
339 u32 dcdTimer
[FST_MAX_PORTS
];
340 u32 dcdTimerRun
[FST_MAX_PORTS
];
342 u32 numberOfPorts
; /* Number of ports detected at startup */
346 u16 cardMode
; /* Bit-mask to enable features:
347 * Bit 0: 1 enables LED identify mode
350 u16 portScheduleOffset
;
352 struct su_config suConfig
; /* TE1 Bits */
353 struct su_status suStatus
;
355 u32 endOfSmcSignature
; /* endOfSmcSignature MUST be the last member of
356 * the structure and marks the end of shared
357 * memory. Adapter code initializes it as
362 /* endOfSmcSignature value */
363 #define END_SIG 0x12345678
365 /* Mailbox values. (portMailbox) */
366 #define NOP 0 /* No operation */
367 #define ACK 1 /* Positive acknowledgement to PC driver */
368 #define NAK 2 /* Negative acknowledgement to PC driver */
369 #define STARTPORT 3 /* Start an HDLC port */
370 #define STOPPORT 4 /* Stop an HDLC port */
371 #define ABORTTX 5 /* Abort the transmitter for a port */
372 #define SETV24O 6 /* Set V24 outputs */
374 /* PLX Chip Register Offsets */
375 #define CNTRL_9052 0x50 /* Control Register */
376 #define CNTRL_9054 0x6c /* Control Register */
378 #define INTCSR_9052 0x4c /* Interrupt control/status register */
379 #define INTCSR_9054 0x68 /* Interrupt control/status register */
381 /* 9054 DMA Registers */
383 * Note that we will be using DMA Channel 0 for copying rx data
384 * and Channel 1 for copying tx data
386 #define DMAMODE0 0x80
387 #define DMAPADR0 0x84
388 #define DMALADR0 0x88
391 #define DMAMODE1 0x94
392 #define DMAPADR1 0x98
393 #define DMALADR1 0x9c
402 #define DMAMARBR 0xac
404 #define FST_MIN_DMA_LEN 64
405 #define FST_RX_DMA_INT 0x01
406 #define FST_TX_DMA_INT 0x02
407 #define FST_CARD_INT 0x04
409 /* Larger buffers are positioned in memory at offset BFM_BASE */
411 u8 txBuffer
[FST_MAX_PORTS
][NUM_TX_BUFFER
][LEN_TX_BUFFER
];
412 u8 rxBuffer
[FST_MAX_PORTS
][NUM_RX_BUFFER
][LEN_RX_BUFFER
];
415 /* Calculate offset of a buffer object within the shared memory window */
416 #define BUF_OFFSET(X) (BFM_BASE + offsetof(struct buf_window, X))
420 /* Device driver private information
421 * =================================
423 /* Per port (line or channel) information
425 struct fst_port_info
{
426 struct net_device
*dev
; /* Device struct - must be first */
427 struct fst_card_info
*card
; /* Card we're associated with */
428 int index
; /* Port index on the card */
429 int hwif
; /* Line hardware (lineInterface copy) */
430 int run
; /* Port is running */
431 int mode
; /* Normal or FarSync raw */
432 int rxpos
; /* Next Rx buffer to use */
433 int txpos
; /* Next Tx buffer to use */
434 int txipos
; /* Next Tx buffer to check for free */
435 int start
; /* Indication of start/stop to network */
437 * A sixteen entry transmit queue
439 int txqs
; /* index to get next buffer to tx */
440 int txqe
; /* index to queue next packet */
441 struct sk_buff
*txq
[FST_TXQ_DEPTH
]; /* The queue */
445 /* Per card information
447 struct fst_card_info
{
448 char __iomem
*mem
; /* Card memory mapped to kernel space */
449 char __iomem
*ctlmem
; /* Control memory for PCI cards */
450 unsigned int phys_mem
; /* Physical memory window address */
451 unsigned int phys_ctlmem
; /* Physical control memory address */
452 unsigned int irq
; /* Interrupt request line number */
453 unsigned int nports
; /* Number of serial ports */
454 unsigned int type
; /* Type index of card */
455 unsigned int state
; /* State of card */
456 spinlock_t card_lock
; /* Lock for SMP access */
457 unsigned short pci_conf
; /* PCI card config in I/O space */
459 struct fst_port_info ports
[FST_MAX_PORTS
];
460 struct pci_dev
*device
; /* Information about the pci device */
461 int card_no
; /* Inst of the card on the system */
462 int family
; /* TxP or TxU */
463 int dmarx_in_progress
;
464 int dmatx_in_progress
;
465 unsigned long int_count
;
466 unsigned long int_time_ave
;
467 void *rx_dma_handle_host
;
468 dma_addr_t rx_dma_handle_card
;
469 void *tx_dma_handle_host
;
470 dma_addr_t tx_dma_handle_card
;
471 struct sk_buff
*dma_skb_rx
;
472 struct fst_port_info
*dma_port_rx
;
473 struct fst_port_info
*dma_port_tx
;
480 /* Convert an HDLC device pointer into a port info pointer and similar */
481 #define dev_to_port(D) (dev_to_hdlc(D)->priv)
482 #define port_to_dev(P) ((P)->dev)
486 * Shared memory window access macros
488 * We have a nice memory based structure above, which could be directly
489 * mapped on i386 but might not work on other architectures unless we use
490 * the readb,w,l and writeb,w,l macros. Unfortunately these macros take
491 * physical offsets so we have to convert. The only saving grace is that
492 * this should all collapse back to a simple indirection eventually.
494 #define WIN_OFFSET(X) ((long)&(((struct fst_shared *)SMC_BASE)->X))
496 #define FST_RDB(C,E) readb ((C)->mem + WIN_OFFSET(E))
497 #define FST_RDW(C,E) readw ((C)->mem + WIN_OFFSET(E))
498 #define FST_RDL(C,E) readl ((C)->mem + WIN_OFFSET(E))
500 #define FST_WRB(C,E,B) writeb ((B), (C)->mem + WIN_OFFSET(E))
501 #define FST_WRW(C,E,W) writew ((W), (C)->mem + WIN_OFFSET(E))
502 #define FST_WRL(C,E,L) writel ((L), (C)->mem + WIN_OFFSET(E))
509 static int fst_debug_mask
= { FST_DEBUG
};
511 /* Most common debug activity is to print something if the corresponding bit
512 * is set in the debug mask. Note: this uses a non-ANSI extension in GCC to
513 * support variable numbers of macro parameters. The inverted if prevents us
514 * eating someone else's else clause.
516 #define dbg(F, fmt, args...) \
518 if (fst_debug_mask & (F)) \
519 printk(KERN_DEBUG pr_fmt(fmt), ##args); \
522 #define dbg(F, fmt, args...) \
525 printk(KERN_DEBUG pr_fmt(fmt), ##args); \
530 * PCI ID lookup table
532 static DEFINE_PCI_DEVICE_TABLE(fst_pci_dev_id
) = {
533 {PCI_VENDOR_ID_FARSITE
, PCI_DEVICE_ID_FARSITE_T2P
, PCI_ANY_ID
,
534 PCI_ANY_ID
, 0, 0, FST_TYPE_T2P
},
536 {PCI_VENDOR_ID_FARSITE
, PCI_DEVICE_ID_FARSITE_T4P
, PCI_ANY_ID
,
537 PCI_ANY_ID
, 0, 0, FST_TYPE_T4P
},
539 {PCI_VENDOR_ID_FARSITE
, PCI_DEVICE_ID_FARSITE_T1U
, PCI_ANY_ID
,
540 PCI_ANY_ID
, 0, 0, FST_TYPE_T1U
},
542 {PCI_VENDOR_ID_FARSITE
, PCI_DEVICE_ID_FARSITE_T2U
, PCI_ANY_ID
,
543 PCI_ANY_ID
, 0, 0, FST_TYPE_T2U
},
545 {PCI_VENDOR_ID_FARSITE
, PCI_DEVICE_ID_FARSITE_T4U
, PCI_ANY_ID
,
546 PCI_ANY_ID
, 0, 0, FST_TYPE_T4U
},
548 {PCI_VENDOR_ID_FARSITE
, PCI_DEVICE_ID_FARSITE_TE1
, PCI_ANY_ID
,
549 PCI_ANY_ID
, 0, 0, FST_TYPE_TE1
},
551 {PCI_VENDOR_ID_FARSITE
, PCI_DEVICE_ID_FARSITE_TE1C
, PCI_ANY_ID
,
552 PCI_ANY_ID
, 0, 0, FST_TYPE_TE1
},
556 MODULE_DEVICE_TABLE(pci
, fst_pci_dev_id
);
559 * Device Driver Work Queues
561 * So that we don't spend too much time processing events in the
562 * Interrupt Service routine, we will declare a work queue per Card
563 * and make the ISR schedule a task in the queue for later execution.
564 * In the 2.4 Kernel we used to use the immediate queue for BH's
565 * Now that they are gone, tasklets seem to be much better than work
569 static void do_bottom_half_tx(struct fst_card_info
*card
);
570 static void do_bottom_half_rx(struct fst_card_info
*card
);
571 static void fst_process_tx_work_q(unsigned long work_q
);
572 static void fst_process_int_work_q(unsigned long work_q
);
574 static DECLARE_TASKLET(fst_tx_task
, fst_process_tx_work_q
, 0);
575 static DECLARE_TASKLET(fst_int_task
, fst_process_int_work_q
, 0);
577 static struct fst_card_info
*fst_card_array
[FST_MAX_CARDS
];
578 static spinlock_t fst_work_q_lock
;
579 static u64 fst_work_txq
;
580 static u64 fst_work_intq
;
583 fst_q_work_item(u64
* queue
, int card_index
)
589 * Grab the queue exclusively
591 spin_lock_irqsave(&fst_work_q_lock
, flags
);
594 * Making an entry in the queue is simply a matter of setting
595 * a bit for the card indicating that there is work to do in the
596 * bottom half for the card. Note the limitation of 64 cards.
597 * That ought to be enough
599 mask
= 1 << card_index
;
601 spin_unlock_irqrestore(&fst_work_q_lock
, flags
);
605 fst_process_tx_work_q(unsigned long /*void **/work_q
)
612 * Grab the queue exclusively
614 dbg(DBG_TX
, "fst_process_tx_work_q\n");
615 spin_lock_irqsave(&fst_work_q_lock
, flags
);
616 work_txq
= fst_work_txq
;
618 spin_unlock_irqrestore(&fst_work_q_lock
, flags
);
621 * Call the bottom half for each card with work waiting
623 for (i
= 0; i
< FST_MAX_CARDS
; i
++) {
624 if (work_txq
& 0x01) {
625 if (fst_card_array
[i
] != NULL
) {
626 dbg(DBG_TX
, "Calling tx bh for card %d\n", i
);
627 do_bottom_half_tx(fst_card_array
[i
]);
630 work_txq
= work_txq
>> 1;
635 fst_process_int_work_q(unsigned long /*void **/work_q
)
642 * Grab the queue exclusively
644 dbg(DBG_INTR
, "fst_process_int_work_q\n");
645 spin_lock_irqsave(&fst_work_q_lock
, flags
);
646 work_intq
= fst_work_intq
;
648 spin_unlock_irqrestore(&fst_work_q_lock
, flags
);
651 * Call the bottom half for each card with work waiting
653 for (i
= 0; i
< FST_MAX_CARDS
; i
++) {
654 if (work_intq
& 0x01) {
655 if (fst_card_array
[i
] != NULL
) {
657 "Calling rx & tx bh for card %d\n", i
);
658 do_bottom_half_rx(fst_card_array
[i
]);
659 do_bottom_half_tx(fst_card_array
[i
]);
662 work_intq
= work_intq
>> 1;
666 /* Card control functions
667 * ======================
669 /* Place the processor in reset state
671 * Used to be a simple write to card control space but a glitch in the latest
672 * AMD Am186CH processor means that we now have to do it by asserting and de-
673 * asserting the PLX chip PCI Adapter Software Reset. Bit 30 in CNTRL register
674 * at offset 9052_CNTRL. Note the updates for the TXU.
677 fst_cpureset(struct fst_card_info
*card
)
679 unsigned char interrupt_line_register
;
680 unsigned long j
= jiffies
+ 1;
683 if (card
->family
== FST_FAMILY_TXU
) {
684 if (pci_read_config_byte
685 (card
->device
, PCI_INTERRUPT_LINE
, &interrupt_line_register
)) {
687 "Error in reading interrupt line register\n");
690 * Assert PLX software reset and Am186 hardware reset
691 * and then deassert the PLX software reset but 186 still in reset
693 outw(0x440f, card
->pci_conf
+ CNTRL_9054
+ 2);
694 outw(0x040f, card
->pci_conf
+ CNTRL_9054
+ 2);
696 * We are delaying here to allow the 9054 to reset itself
701 outw(0x240f, card
->pci_conf
+ CNTRL_9054
+ 2);
703 * We are delaying here to allow the 9054 to reload its eeprom
708 outw(0x040f, card
->pci_conf
+ CNTRL_9054
+ 2);
710 if (pci_write_config_byte
711 (card
->device
, PCI_INTERRUPT_LINE
, interrupt_line_register
)) {
713 "Error in writing interrupt line register\n");
717 regval
= inl(card
->pci_conf
+ CNTRL_9052
);
719 outl(regval
| 0x40000000, card
->pci_conf
+ CNTRL_9052
);
720 outl(regval
& ~0x40000000, card
->pci_conf
+ CNTRL_9052
);
724 /* Release the processor from reset
727 fst_cpurelease(struct fst_card_info
*card
)
729 if (card
->family
== FST_FAMILY_TXU
) {
731 * Force posted writes to complete
733 (void) readb(card
->mem
);
736 * Release LRESET DO = 1
737 * Then release Local Hold, DO = 1
739 outw(0x040e, card
->pci_conf
+ CNTRL_9054
+ 2);
740 outw(0x040f, card
->pci_conf
+ CNTRL_9054
+ 2);
742 (void) readb(card
->ctlmem
);
746 /* Clear the cards interrupt flag
749 fst_clear_intr(struct fst_card_info
*card
)
751 if (card
->family
== FST_FAMILY_TXU
) {
752 (void) readb(card
->ctlmem
);
754 /* Poke the appropriate PLX chip register (same as enabling interrupts)
756 outw(0x0543, card
->pci_conf
+ INTCSR_9052
);
760 /* Enable card interrupts
763 fst_enable_intr(struct fst_card_info
*card
)
765 if (card
->family
== FST_FAMILY_TXU
) {
766 outl(0x0f0c0900, card
->pci_conf
+ INTCSR_9054
);
768 outw(0x0543, card
->pci_conf
+ INTCSR_9052
);
772 /* Disable card interrupts
775 fst_disable_intr(struct fst_card_info
*card
)
777 if (card
->family
== FST_FAMILY_TXU
) {
778 outl(0x00000000, card
->pci_conf
+ INTCSR_9054
);
780 outw(0x0000, card
->pci_conf
+ INTCSR_9052
);
784 /* Process the result of trying to pass a received frame up the stack
787 fst_process_rx_status(int rx_status
, char *name
)
799 dbg(DBG_ASS
, "%s: Received packet dropped\n", name
);
805 /* Initilaise DMA for PLX 9054
808 fst_init_dma(struct fst_card_info
*card
)
811 * This is only required for the PLX 9054
813 if (card
->family
== FST_FAMILY_TXU
) {
814 pci_set_master(card
->device
);
815 outl(0x00020441, card
->pci_conf
+ DMAMODE0
);
816 outl(0x00020441, card
->pci_conf
+ DMAMODE1
);
817 outl(0x0, card
->pci_conf
+ DMATHR
);
821 /* Tx dma complete interrupt
824 fst_tx_dma_complete(struct fst_card_info
*card
, struct fst_port_info
*port
,
827 struct net_device
*dev
= port_to_dev(port
);
830 * Everything is now set, just tell the card to go
832 dbg(DBG_TX
, "fst_tx_dma_complete\n");
833 FST_WRB(card
, txDescrRing
[port
->index
][txpos
].bits
,
834 DMA_OWN
| TX_STP
| TX_ENP
);
835 dev
->stats
.tx_packets
++;
836 dev
->stats
.tx_bytes
+= len
;
837 dev
->trans_start
= jiffies
;
841 * Mark it for our own raw sockets interface
843 static __be16
farsync_type_trans(struct sk_buff
*skb
, struct net_device
*dev
)
846 skb_reset_mac_header(skb
);
847 skb
->pkt_type
= PACKET_HOST
;
848 return htons(ETH_P_CUST
);
851 /* Rx dma complete interrupt
854 fst_rx_dma_complete(struct fst_card_info
*card
, struct fst_port_info
*port
,
855 int len
, struct sk_buff
*skb
, int rxp
)
857 struct net_device
*dev
= port_to_dev(port
);
861 dbg(DBG_TX
, "fst_rx_dma_complete\n");
863 memcpy(skb_put(skb
, len
), card
->rx_dma_handle_host
, len
);
865 /* Reset buffer descriptor */
866 FST_WRB(card
, rxDescrRing
[pi
][rxp
].bits
, DMA_OWN
);
869 dev
->stats
.rx_packets
++;
870 dev
->stats
.rx_bytes
+= len
;
873 dbg(DBG_RX
, "Pushing the frame up the stack\n");
874 if (port
->mode
== FST_RAW
)
875 skb
->protocol
= farsync_type_trans(skb
, dev
);
877 skb
->protocol
= hdlc_type_trans(skb
, dev
);
878 rx_status
= netif_rx(skb
);
879 fst_process_rx_status(rx_status
, port_to_dev(port
)->name
);
880 if (rx_status
== NET_RX_DROP
)
881 dev
->stats
.rx_dropped
++;
885 * Receive a frame through the DMA
888 fst_rx_dma(struct fst_card_info
*card
, dma_addr_t skb
,
889 dma_addr_t mem
, int len
)
892 * This routine will setup the DMA and start it
895 dbg(DBG_RX
, "In fst_rx_dma %lx %lx %d\n",
896 (unsigned long) skb
, (unsigned long) mem
, len
);
897 if (card
->dmarx_in_progress
) {
898 dbg(DBG_ASS
, "In fst_rx_dma while dma in progress\n");
901 outl(skb
, card
->pci_conf
+ DMAPADR0
); /* Copy to here */
902 outl(mem
, card
->pci_conf
+ DMALADR0
); /* from here */
903 outl(len
, card
->pci_conf
+ DMASIZ0
); /* for this length */
904 outl(0x00000000c, card
->pci_conf
+ DMADPR0
); /* In this direction */
907 * We use the dmarx_in_progress flag to flag the channel as busy
909 card
->dmarx_in_progress
= 1;
910 outb(0x03, card
->pci_conf
+ DMACSR0
); /* Start the transfer */
914 * Send a frame through the DMA
917 fst_tx_dma(struct fst_card_info
*card
, unsigned char *skb
,
918 unsigned char *mem
, int len
)
921 * This routine will setup the DMA and start it.
924 dbg(DBG_TX
, "In fst_tx_dma %p %p %d\n", skb
, mem
, len
);
925 if (card
->dmatx_in_progress
) {
926 dbg(DBG_ASS
, "In fst_tx_dma while dma in progress\n");
929 outl((unsigned long) skb
, card
->pci_conf
+ DMAPADR1
); /* Copy from here */
930 outl((unsigned long) mem
, card
->pci_conf
+ DMALADR1
); /* to here */
931 outl(len
, card
->pci_conf
+ DMASIZ1
); /* for this length */
932 outl(0x000000004, card
->pci_conf
+ DMADPR1
); /* In this direction */
935 * We use the dmatx_in_progress to flag the channel as busy
937 card
->dmatx_in_progress
= 1;
938 outb(0x03, card
->pci_conf
+ DMACSR1
); /* Start the transfer */
941 /* Issue a Mailbox command for a port.
942 * Note we issue them on a fire and forget basis, not expecting to see an
943 * error and not waiting for completion.
946 fst_issue_cmd(struct fst_port_info
*port
, unsigned short cmd
)
948 struct fst_card_info
*card
;
949 unsigned short mbval
;
954 spin_lock_irqsave(&card
->card_lock
, flags
);
955 mbval
= FST_RDW(card
, portMailbox
[port
->index
][0]);
958 /* Wait for any previous command to complete */
959 while (mbval
> NAK
) {
960 spin_unlock_irqrestore(&card
->card_lock
, flags
);
961 schedule_timeout_uninterruptible(1);
962 spin_lock_irqsave(&card
->card_lock
, flags
);
964 if (++safety
> 2000) {
965 pr_err("Mailbox safety timeout\n");
969 mbval
= FST_RDW(card
, portMailbox
[port
->index
][0]);
972 dbg(DBG_CMD
, "Mailbox clear after %d jiffies\n", safety
);
975 dbg(DBG_CMD
, "issue_cmd: previous command was NAK'd\n");
978 FST_WRW(card
, portMailbox
[port
->index
][0], cmd
);
980 if (cmd
== ABORTTX
|| cmd
== STARTPORT
) {
986 spin_unlock_irqrestore(&card
->card_lock
, flags
);
989 /* Port output signals control
992 fst_op_raise(struct fst_port_info
*port
, unsigned int outputs
)
994 outputs
|= FST_RDL(port
->card
, v24OpSts
[port
->index
]);
995 FST_WRL(port
->card
, v24OpSts
[port
->index
], outputs
);
998 fst_issue_cmd(port
, SETV24O
);
1002 fst_op_lower(struct fst_port_info
*port
, unsigned int outputs
)
1004 outputs
= ~outputs
& FST_RDL(port
->card
, v24OpSts
[port
->index
]);
1005 FST_WRL(port
->card
, v24OpSts
[port
->index
], outputs
);
1008 fst_issue_cmd(port
, SETV24O
);
1012 * Setup port Rx buffers
1015 fst_rx_config(struct fst_port_info
*port
)
1019 unsigned int offset
;
1020 unsigned long flags
;
1021 struct fst_card_info
*card
;
1025 spin_lock_irqsave(&card
->card_lock
, flags
);
1026 for (i
= 0; i
< NUM_RX_BUFFER
; i
++) {
1027 offset
= BUF_OFFSET(rxBuffer
[pi
][i
][0]);
1029 FST_WRW(card
, rxDescrRing
[pi
][i
].ladr
, (u16
) offset
);
1030 FST_WRB(card
, rxDescrRing
[pi
][i
].hadr
, (u8
) (offset
>> 16));
1031 FST_WRW(card
, rxDescrRing
[pi
][i
].bcnt
, cnv_bcnt(LEN_RX_BUFFER
));
1032 FST_WRW(card
, rxDescrRing
[pi
][i
].mcnt
, LEN_RX_BUFFER
);
1033 FST_WRB(card
, rxDescrRing
[pi
][i
].bits
, DMA_OWN
);
1036 spin_unlock_irqrestore(&card
->card_lock
, flags
);
1040 * Setup port Tx buffers
1043 fst_tx_config(struct fst_port_info
*port
)
1047 unsigned int offset
;
1048 unsigned long flags
;
1049 struct fst_card_info
*card
;
1053 spin_lock_irqsave(&card
->card_lock
, flags
);
1054 for (i
= 0; i
< NUM_TX_BUFFER
; i
++) {
1055 offset
= BUF_OFFSET(txBuffer
[pi
][i
][0]);
1057 FST_WRW(card
, txDescrRing
[pi
][i
].ladr
, (u16
) offset
);
1058 FST_WRB(card
, txDescrRing
[pi
][i
].hadr
, (u8
) (offset
>> 16));
1059 FST_WRW(card
, txDescrRing
[pi
][i
].bcnt
, 0);
1060 FST_WRB(card
, txDescrRing
[pi
][i
].bits
, 0);
1065 spin_unlock_irqrestore(&card
->card_lock
, flags
);
1068 /* TE1 Alarm change interrupt event
1071 fst_intr_te1_alarm(struct fst_card_info
*card
, struct fst_port_info
*port
)
1077 los
= FST_RDB(card
, suStatus
.lossOfSignal
);
1078 rra
= FST_RDB(card
, suStatus
.receiveRemoteAlarm
);
1079 ais
= FST_RDB(card
, suStatus
.alarmIndicationSignal
);
1085 if (netif_carrier_ok(port_to_dev(port
))) {
1086 dbg(DBG_INTR
, "Net carrier off\n");
1087 netif_carrier_off(port_to_dev(port
));
1093 if (!netif_carrier_ok(port_to_dev(port
))) {
1094 dbg(DBG_INTR
, "Net carrier on\n");
1095 netif_carrier_on(port_to_dev(port
));
1100 dbg(DBG_INTR
, "Assert LOS Alarm\n");
1102 dbg(DBG_INTR
, "De-assert LOS Alarm\n");
1104 dbg(DBG_INTR
, "Assert RRA Alarm\n");
1106 dbg(DBG_INTR
, "De-assert RRA Alarm\n");
1109 dbg(DBG_INTR
, "Assert AIS Alarm\n");
1111 dbg(DBG_INTR
, "De-assert AIS Alarm\n");
1114 /* Control signal change interrupt event
1117 fst_intr_ctlchg(struct fst_card_info
*card
, struct fst_port_info
*port
)
1121 signals
= FST_RDL(card
, v24DebouncedSts
[port
->index
]);
1123 if (signals
& (((port
->hwif
== X21
) || (port
->hwif
== X21D
))
1124 ? IPSTS_INDICATE
: IPSTS_DCD
)) {
1125 if (!netif_carrier_ok(port_to_dev(port
))) {
1126 dbg(DBG_INTR
, "DCD active\n");
1127 netif_carrier_on(port_to_dev(port
));
1130 if (netif_carrier_ok(port_to_dev(port
))) {
1131 dbg(DBG_INTR
, "DCD lost\n");
1132 netif_carrier_off(port_to_dev(port
));
1140 fst_log_rx_error(struct fst_card_info
*card
, struct fst_port_info
*port
,
1141 unsigned char dmabits
, int rxp
, unsigned short len
)
1143 struct net_device
*dev
= port_to_dev(port
);
1146 * Increment the appropriate error counter
1148 dev
->stats
.rx_errors
++;
1149 if (dmabits
& RX_OFLO
) {
1150 dev
->stats
.rx_fifo_errors
++;
1151 dbg(DBG_ASS
, "Rx fifo error on card %d port %d buffer %d\n",
1152 card
->card_no
, port
->index
, rxp
);
1154 if (dmabits
& RX_CRC
) {
1155 dev
->stats
.rx_crc_errors
++;
1156 dbg(DBG_ASS
, "Rx crc error on card %d port %d\n",
1157 card
->card_no
, port
->index
);
1159 if (dmabits
& RX_FRAM
) {
1160 dev
->stats
.rx_frame_errors
++;
1161 dbg(DBG_ASS
, "Rx frame error on card %d port %d\n",
1162 card
->card_no
, port
->index
);
1164 if (dmabits
== (RX_STP
| RX_ENP
)) {
1165 dev
->stats
.rx_length_errors
++;
1166 dbg(DBG_ASS
, "Rx length error (%d) on card %d port %d\n",
1167 len
, card
->card_no
, port
->index
);
1171 /* Rx Error Recovery
1174 fst_recover_rx_error(struct fst_card_info
*card
, struct fst_port_info
*port
,
1175 unsigned char dmabits
, int rxp
, unsigned short len
)
1182 * Discard buffer descriptors until we see the start of the
1183 * next frame. Note that for long frames this could be in
1184 * a subsequent interrupt.
1187 while ((dmabits
& (DMA_OWN
| RX_STP
)) == 0) {
1188 FST_WRB(card
, rxDescrRing
[pi
][rxp
].bits
, DMA_OWN
);
1189 rxp
= (rxp
+1) % NUM_RX_BUFFER
;
1190 if (++i
> NUM_RX_BUFFER
) {
1191 dbg(DBG_ASS
, "intr_rx: Discarding more bufs"
1195 dmabits
= FST_RDB(card
, rxDescrRing
[pi
][rxp
].bits
);
1196 dbg(DBG_ASS
, "DMA Bits of next buffer was %x\n", dmabits
);
1198 dbg(DBG_ASS
, "There were %d subsequent buffers in error\n", i
);
1200 /* Discard the terminal buffer */
1201 if (!(dmabits
& DMA_OWN
)) {
1202 FST_WRB(card
, rxDescrRing
[pi
][rxp
].bits
, DMA_OWN
);
1203 rxp
= (rxp
+1) % NUM_RX_BUFFER
;
1210 /* Rx complete interrupt
1213 fst_intr_rx(struct fst_card_info
*card
, struct fst_port_info
*port
)
1215 unsigned char dmabits
;
1220 struct sk_buff
*skb
;
1221 struct net_device
*dev
= port_to_dev(port
);
1223 /* Check we have a buffer to process */
1226 dmabits
= FST_RDB(card
, rxDescrRing
[pi
][rxp
].bits
);
1227 if (dmabits
& DMA_OWN
) {
1228 dbg(DBG_RX
| DBG_INTR
, "intr_rx: No buffer port %d pos %d\n",
1232 if (card
->dmarx_in_progress
) {
1236 /* Get buffer length */
1237 len
= FST_RDW(card
, rxDescrRing
[pi
][rxp
].mcnt
);
1238 /* Discard the CRC */
1242 * This seems to happen on the TE1 interface sometimes
1243 * so throw the frame away and log the event.
1245 pr_err("Frame received with 0 length. Card %d Port %d\n",
1246 card
->card_no
, port
->index
);
1247 /* Return descriptor to card */
1248 FST_WRB(card
, rxDescrRing
[pi
][rxp
].bits
, DMA_OWN
);
1250 rxp
= (rxp
+1) % NUM_RX_BUFFER
;
1255 /* Check buffer length and for other errors. We insist on one packet
1256 * in one buffer. This simplifies things greatly and since we've
1257 * allocated 8K it shouldn't be a real world limitation
1259 dbg(DBG_RX
, "intr_rx: %d,%d: flags %x len %d\n", pi
, rxp
, dmabits
, len
);
1260 if (dmabits
!= (RX_STP
| RX_ENP
) || len
> LEN_RX_BUFFER
- 2) {
1261 fst_log_rx_error(card
, port
, dmabits
, rxp
, len
);
1262 fst_recover_rx_error(card
, port
, dmabits
, rxp
, len
);
1267 if ((skb
= dev_alloc_skb(len
)) == NULL
) {
1268 dbg(DBG_RX
, "intr_rx: can't allocate buffer\n");
1270 dev
->stats
.rx_dropped
++;
1272 /* Return descriptor to card */
1273 FST_WRB(card
, rxDescrRing
[pi
][rxp
].bits
, DMA_OWN
);
1275 rxp
= (rxp
+1) % NUM_RX_BUFFER
;
1281 * We know the length we need to receive, len.
1282 * It's not worth using the DMA for reads of less than
1286 if ((len
< FST_MIN_DMA_LEN
) || (card
->family
== FST_FAMILY_TXP
)) {
1287 memcpy_fromio(skb_put(skb
, len
),
1288 card
->mem
+ BUF_OFFSET(rxBuffer
[pi
][rxp
][0]),
1291 /* Reset buffer descriptor */
1292 FST_WRB(card
, rxDescrRing
[pi
][rxp
].bits
, DMA_OWN
);
1295 dev
->stats
.rx_packets
++;
1296 dev
->stats
.rx_bytes
+= len
;
1299 dbg(DBG_RX
, "Pushing frame up the stack\n");
1300 if (port
->mode
== FST_RAW
)
1301 skb
->protocol
= farsync_type_trans(skb
, dev
);
1303 skb
->protocol
= hdlc_type_trans(skb
, dev
);
1304 rx_status
= netif_rx(skb
);
1305 fst_process_rx_status(rx_status
, port_to_dev(port
)->name
);
1306 if (rx_status
== NET_RX_DROP
)
1307 dev
->stats
.rx_dropped
++;
1309 card
->dma_skb_rx
= skb
;
1310 card
->dma_port_rx
= port
;
1311 card
->dma_len_rx
= len
;
1312 card
->dma_rxpos
= rxp
;
1313 fst_rx_dma(card
, card
->rx_dma_handle_card
,
1314 BUF_OFFSET(rxBuffer
[pi
][rxp
][0]), len
);
1316 if (rxp
!= port
->rxpos
) {
1317 dbg(DBG_ASS
, "About to increment rxpos by more than 1\n");
1318 dbg(DBG_ASS
, "rxp = %d rxpos = %d\n", rxp
, port
->rxpos
);
1320 rxp
= (rxp
+1) % NUM_RX_BUFFER
;
1325 * The bottom halfs to the ISR
1330 do_bottom_half_tx(struct fst_card_info
*card
)
1332 struct fst_port_info
*port
;
1335 struct sk_buff
*skb
;
1336 unsigned long flags
;
1337 struct net_device
*dev
;
1340 * Find a free buffer for the transmit
1341 * Step through each port on this card
1344 dbg(DBG_TX
, "do_bottom_half_tx\n");
1345 for (pi
= 0, port
= card
->ports
; pi
< card
->nports
; pi
++, port
++) {
1349 dev
= port_to_dev(port
);
1350 while (!(FST_RDB(card
, txDescrRing
[pi
][port
->txpos
].bits
) &
1352 !(card
->dmatx_in_progress
)) {
1354 * There doesn't seem to be a txdone event per-se
1355 * We seem to have to deduce it, by checking the DMA_OWN
1356 * bit on the next buffer we think we can use
1358 spin_lock_irqsave(&card
->card_lock
, flags
);
1359 if ((txq_length
= port
->txqe
- port
->txqs
) < 0) {
1361 * This is the case where one has wrapped and the
1362 * maths gives us a negative number
1364 txq_length
= txq_length
+ FST_TXQ_DEPTH
;
1366 spin_unlock_irqrestore(&card
->card_lock
, flags
);
1367 if (txq_length
> 0) {
1369 * There is something to send
1371 spin_lock_irqsave(&card
->card_lock
, flags
);
1372 skb
= port
->txq
[port
->txqs
];
1374 if (port
->txqs
== FST_TXQ_DEPTH
) {
1377 spin_unlock_irqrestore(&card
->card_lock
, flags
);
1379 * copy the data and set the required indicators on the
1382 FST_WRW(card
, txDescrRing
[pi
][port
->txpos
].bcnt
,
1383 cnv_bcnt(skb
->len
));
1384 if ((skb
->len
< FST_MIN_DMA_LEN
) ||
1385 (card
->family
== FST_FAMILY_TXP
)) {
1386 /* Enqueue the packet with normal io */
1387 memcpy_toio(card
->mem
+
1388 BUF_OFFSET(txBuffer
[pi
]
1391 skb
->data
, skb
->len
);
1393 txDescrRing
[pi
][port
->txpos
].
1395 DMA_OWN
| TX_STP
| TX_ENP
);
1396 dev
->stats
.tx_packets
++;
1397 dev
->stats
.tx_bytes
+= skb
->len
;
1398 dev
->trans_start
= jiffies
;
1400 /* Or do it through dma */
1401 memcpy(card
->tx_dma_handle_host
,
1402 skb
->data
, skb
->len
);
1403 card
->dma_port_tx
= port
;
1404 card
->dma_len_tx
= skb
->len
;
1405 card
->dma_txpos
= port
->txpos
;
1410 BUF_OFFSET(txBuffer
[pi
]
1414 if (++port
->txpos
>= NUM_TX_BUFFER
)
1417 * If we have flow control on, can we now release it?
1420 if (txq_length
< fst_txq_low
) {
1421 netif_wake_queue(port_to_dev
1429 * Nothing to send so break out of the while loop
1438 do_bottom_half_rx(struct fst_card_info
*card
)
1440 struct fst_port_info
*port
;
1444 /* Check for rx completions on all ports on this card */
1445 dbg(DBG_RX
, "do_bottom_half_rx\n");
1446 for (pi
= 0, port
= card
->ports
; pi
< card
->nports
; pi
++, port
++) {
1450 while (!(FST_RDB(card
, rxDescrRing
[pi
][port
->rxpos
].bits
)
1451 & DMA_OWN
) && !(card
->dmarx_in_progress
)) {
1452 if (rx_count
> fst_max_reads
) {
1454 * Don't spend forever in receive processing
1455 * Schedule another event
1457 fst_q_work_item(&fst_work_intq
, card
->card_no
);
1458 tasklet_schedule(&fst_int_task
);
1459 break; /* Leave the loop */
1461 fst_intr_rx(card
, port
);
1468 * The interrupt service routine
1469 * Dev_id is our fst_card_info pointer
1472 fst_intr(int dummy
, void *dev_id
)
1474 struct fst_card_info
*card
= dev_id
;
1475 struct fst_port_info
*port
;
1476 int rdidx
; /* Event buffer indices */
1478 int event
; /* Actual event for processing */
1479 unsigned int dma_intcsr
= 0;
1480 unsigned int do_card_interrupt
;
1481 unsigned int int_retry_count
;
1484 * Check to see if the interrupt was for this card
1486 * Note that the call to clear the interrupt is important
1488 dbg(DBG_INTR
, "intr: %d %p\n", card
->irq
, card
);
1489 if (card
->state
!= FST_RUNNING
) {
1490 pr_err("Interrupt received for card %d in a non running state (%d)\n",
1491 card
->card_no
, card
->state
);
1494 * It is possible to really be running, i.e. we have re-loaded
1496 * Clear and reprime the interrupt source
1498 fst_clear_intr(card
);
1502 /* Clear and reprime the interrupt source */
1503 fst_clear_intr(card
);
1506 * Is the interrupt for this card (handshake == 1)
1508 do_card_interrupt
= 0;
1509 if (FST_RDB(card
, interruptHandshake
) == 1) {
1510 do_card_interrupt
+= FST_CARD_INT
;
1511 /* Set the software acknowledge */
1512 FST_WRB(card
, interruptHandshake
, 0xEE);
1514 if (card
->family
== FST_FAMILY_TXU
) {
1516 * Is it a DMA Interrupt
1518 dma_intcsr
= inl(card
->pci_conf
+ INTCSR_9054
);
1519 if (dma_intcsr
& 0x00200000) {
1521 * DMA Channel 0 (Rx transfer complete)
1523 dbg(DBG_RX
, "DMA Rx xfer complete\n");
1524 outb(0x8, card
->pci_conf
+ DMACSR0
);
1525 fst_rx_dma_complete(card
, card
->dma_port_rx
,
1526 card
->dma_len_rx
, card
->dma_skb_rx
,
1528 card
->dmarx_in_progress
= 0;
1529 do_card_interrupt
+= FST_RX_DMA_INT
;
1531 if (dma_intcsr
& 0x00400000) {
1533 * DMA Channel 1 (Tx transfer complete)
1535 dbg(DBG_TX
, "DMA Tx xfer complete\n");
1536 outb(0x8, card
->pci_conf
+ DMACSR1
);
1537 fst_tx_dma_complete(card
, card
->dma_port_tx
,
1538 card
->dma_len_tx
, card
->dma_txpos
);
1539 card
->dmatx_in_progress
= 0;
1540 do_card_interrupt
+= FST_TX_DMA_INT
;
1545 * Have we been missing Interrupts
1547 int_retry_count
= FST_RDL(card
, interruptRetryCount
);
1548 if (int_retry_count
) {
1549 dbg(DBG_ASS
, "Card %d int_retry_count is %d\n",
1550 card
->card_no
, int_retry_count
);
1551 FST_WRL(card
, interruptRetryCount
, 0);
1554 if (!do_card_interrupt
) {
1558 /* Scehdule the bottom half of the ISR */
1559 fst_q_work_item(&fst_work_intq
, card
->card_no
);
1560 tasklet_schedule(&fst_int_task
);
1562 /* Drain the event queue */
1563 rdidx
= FST_RDB(card
, interruptEvent
.rdindex
) & 0x1f;
1564 wridx
= FST_RDB(card
, interruptEvent
.wrindex
) & 0x1f;
1565 while (rdidx
!= wridx
) {
1566 event
= FST_RDB(card
, interruptEvent
.evntbuff
[rdidx
]);
1567 port
= &card
->ports
[event
& 0x03];
1569 dbg(DBG_INTR
, "Processing Interrupt event: %x\n", event
);
1573 dbg(DBG_INTR
, "TE1 Alarm intr\n");
1575 fst_intr_te1_alarm(card
, port
);
1583 fst_intr_ctlchg(card
, port
);
1590 dbg(DBG_TX
, "Abort complete port %d\n", port
->index
);
1597 /* Difficult to see how we'd get this given that we
1598 * always load up the entire packet for DMA.
1600 dbg(DBG_TX
, "Tx underflow port %d\n", port
->index
);
1601 port_to_dev(port
)->stats
.tx_errors
++;
1602 port_to_dev(port
)->stats
.tx_fifo_errors
++;
1603 dbg(DBG_ASS
, "Tx underflow on card %d port %d\n",
1604 card
->card_no
, port
->index
);
1608 dbg(DBG_INIT
, "Card init OK intr\n");
1612 dbg(DBG_INIT
, "Card init FAILED intr\n");
1613 card
->state
= FST_IFAILED
;
1617 pr_err("intr: unknown card event %d. ignored\n", event
);
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 pr_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 pr_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 pr_err("Firmware initialisation failed. Card halted\n");
1654 card
->state
= FST_HALTED
;
1656 } else if (i
!= 0x00) {
1657 pr_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 pr_warning("Port count mismatch on card %d. "
1668 "Firmware thinks %d we say %d\n",
1670 FST_RDL(card
, numberOfPorts
), card
->nports
);
1675 set_conf_from_info(struct fst_card_info
*card
, struct fst_port_info
*port
,
1676 struct fstioc_info
*info
)
1679 unsigned char my_framing
;
1681 /* Set things according to the user set valid flags
1682 * Several of the old options have been invalidated/replaced by the
1683 * generic hdlc package.
1686 if (info
->valid
& FSTVAL_PROTO
) {
1687 if (info
->proto
== FST_RAW
)
1688 port
->mode
= FST_RAW
;
1690 port
->mode
= FST_GEN_HDLC
;
1693 if (info
->valid
& FSTVAL_CABLE
)
1696 if (info
->valid
& FSTVAL_SPEED
)
1699 if (info
->valid
& FSTVAL_PHASE
)
1700 FST_WRB(card
, portConfig
[port
->index
].invertClock
,
1702 if (info
->valid
& FSTVAL_MODE
)
1703 FST_WRW(card
, cardMode
, info
->cardMode
);
1704 if (info
->valid
& FSTVAL_TE1
) {
1705 FST_WRL(card
, suConfig
.dataRate
, info
->lineSpeed
);
1706 FST_WRB(card
, suConfig
.clocking
, info
->clockSource
);
1707 my_framing
= FRAMING_E1
;
1708 if (info
->framing
== E1
)
1709 my_framing
= FRAMING_E1
;
1710 if (info
->framing
== T1
)
1711 my_framing
= FRAMING_T1
;
1712 if (info
->framing
== J1
)
1713 my_framing
= FRAMING_J1
;
1714 FST_WRB(card
, suConfig
.framing
, my_framing
);
1715 FST_WRB(card
, suConfig
.structure
, info
->structure
);
1716 FST_WRB(card
, suConfig
.interface
, info
->interface
);
1717 FST_WRB(card
, suConfig
.coding
, info
->coding
);
1718 FST_WRB(card
, suConfig
.lineBuildOut
, info
->lineBuildOut
);
1719 FST_WRB(card
, suConfig
.equalizer
, info
->equalizer
);
1720 FST_WRB(card
, suConfig
.transparentMode
, info
->transparentMode
);
1721 FST_WRB(card
, suConfig
.loopMode
, info
->loopMode
);
1722 FST_WRB(card
, suConfig
.range
, info
->range
);
1723 FST_WRB(card
, suConfig
.txBufferMode
, info
->txBufferMode
);
1724 FST_WRB(card
, suConfig
.rxBufferMode
, info
->rxBufferMode
);
1725 FST_WRB(card
, suConfig
.startingSlot
, info
->startingSlot
);
1726 FST_WRB(card
, suConfig
.losThreshold
, info
->losThreshold
);
1728 FST_WRB(card
, suConfig
.enableIdleCode
, 1);
1730 FST_WRB(card
, suConfig
.enableIdleCode
, 0);
1731 FST_WRB(card
, suConfig
.idleCode
, info
->idleCode
);
1733 if (info
->valid
& FSTVAL_TE1
) {
1734 printk("Setting TE1 data\n");
1735 printk("Line Speed = %d\n", info
->lineSpeed
);
1736 printk("Start slot = %d\n", info
->startingSlot
);
1737 printk("Clock source = %d\n", info
->clockSource
);
1738 printk("Framing = %d\n", my_framing
);
1739 printk("Structure = %d\n", info
->structure
);
1740 printk("interface = %d\n", info
->interface
);
1741 printk("Coding = %d\n", info
->coding
);
1742 printk("Line build out = %d\n", info
->lineBuildOut
);
1743 printk("Equaliser = %d\n", info
->equalizer
);
1744 printk("Transparent mode = %d\n",
1745 info
->transparentMode
);
1746 printk("Loop mode = %d\n", info
->loopMode
);
1747 printk("Range = %d\n", info
->range
);
1748 printk("Tx Buffer mode = %d\n", info
->txBufferMode
);
1749 printk("Rx Buffer mode = %d\n", info
->rxBufferMode
);
1750 printk("LOS Threshold = %d\n", info
->losThreshold
);
1751 printk("Idle Code = %d\n", info
->idleCode
);
1756 if (info
->valid
& FSTVAL_DEBUG
) {
1757 fst_debug_mask
= info
->debug
;
1765 gather_conf_info(struct fst_card_info
*card
, struct fst_port_info
*port
,
1766 struct fstioc_info
*info
)
1770 memset(info
, 0, sizeof (struct fstioc_info
));
1773 info
->kernelVersion
= LINUX_VERSION_CODE
;
1774 info
->nports
= card
->nports
;
1775 info
->type
= card
->type
;
1776 info
->state
= card
->state
;
1777 info
->proto
= FST_GEN_HDLC
;
1780 info
->debug
= fst_debug_mask
;
1783 /* Only mark information as valid if card is running.
1784 * Copy the data anyway in case it is useful for diagnostics
1786 info
->valid
= ((card
->state
== FST_RUNNING
) ? FSTVAL_ALL
: FSTVAL_CARD
)
1792 info
->lineInterface
= FST_RDW(card
, portConfig
[i
].lineInterface
);
1793 info
->internalClock
= FST_RDB(card
, portConfig
[i
].internalClock
);
1794 info
->lineSpeed
= FST_RDL(card
, portConfig
[i
].lineSpeed
);
1795 info
->invertClock
= FST_RDB(card
, portConfig
[i
].invertClock
);
1796 info
->v24IpSts
= FST_RDL(card
, v24IpSts
[i
]);
1797 info
->v24OpSts
= FST_RDL(card
, v24OpSts
[i
]);
1798 info
->clockStatus
= FST_RDW(card
, clockStatus
[i
]);
1799 info
->cableStatus
= FST_RDW(card
, cableStatus
);
1800 info
->cardMode
= FST_RDW(card
, cardMode
);
1801 info
->smcFirmwareVersion
= FST_RDL(card
, smcFirmwareVersion
);
1804 * The T2U can report cable presence for both A or B
1805 * in bits 0 and 1 of cableStatus. See which port we are and
1808 if (card
->family
== FST_FAMILY_TXU
) {
1809 if (port
->index
== 0) {
1813 info
->cableStatus
= info
->cableStatus
& 1;
1818 info
->cableStatus
= info
->cableStatus
>> 1;
1819 info
->cableStatus
= info
->cableStatus
& 1;
1823 * Some additional bits if we are TE1
1825 if (card
->type
== FST_TYPE_TE1
) {
1826 info
->lineSpeed
= FST_RDL(card
, suConfig
.dataRate
);
1827 info
->clockSource
= FST_RDB(card
, suConfig
.clocking
);
1828 info
->framing
= FST_RDB(card
, suConfig
.framing
);
1829 info
->structure
= FST_RDB(card
, suConfig
.structure
);
1830 info
->interface
= FST_RDB(card
, suConfig
.interface
);
1831 info
->coding
= FST_RDB(card
, suConfig
.coding
);
1832 info
->lineBuildOut
= FST_RDB(card
, suConfig
.lineBuildOut
);
1833 info
->equalizer
= FST_RDB(card
, suConfig
.equalizer
);
1834 info
->loopMode
= FST_RDB(card
, suConfig
.loopMode
);
1835 info
->range
= FST_RDB(card
, suConfig
.range
);
1836 info
->txBufferMode
= FST_RDB(card
, suConfig
.txBufferMode
);
1837 info
->rxBufferMode
= FST_RDB(card
, suConfig
.rxBufferMode
);
1838 info
->startingSlot
= FST_RDB(card
, suConfig
.startingSlot
);
1839 info
->losThreshold
= FST_RDB(card
, suConfig
.losThreshold
);
1840 if (FST_RDB(card
, suConfig
.enableIdleCode
))
1841 info
->idleCode
= FST_RDB(card
, suConfig
.idleCode
);
1844 info
->receiveBufferDelay
=
1845 FST_RDL(card
, suStatus
.receiveBufferDelay
);
1846 info
->framingErrorCount
=
1847 FST_RDL(card
, suStatus
.framingErrorCount
);
1848 info
->codeViolationCount
=
1849 FST_RDL(card
, suStatus
.codeViolationCount
);
1850 info
->crcErrorCount
= FST_RDL(card
, suStatus
.crcErrorCount
);
1851 info
->lineAttenuation
= FST_RDL(card
, suStatus
.lineAttenuation
);
1852 info
->lossOfSignal
= FST_RDB(card
, suStatus
.lossOfSignal
);
1853 info
->receiveRemoteAlarm
=
1854 FST_RDB(card
, suStatus
.receiveRemoteAlarm
);
1855 info
->alarmIndicationSignal
=
1856 FST_RDB(card
, suStatus
.alarmIndicationSignal
);
1861 fst_set_iface(struct fst_card_info
*card
, struct fst_port_info
*port
,
1864 sync_serial_settings sync
;
1867 if (ifr
->ifr_settings
.size
!= sizeof (sync
)) {
1872 (&sync
, ifr
->ifr_settings
.ifs_ifsu
.sync
, sizeof (sync
))) {
1881 switch (ifr
->ifr_settings
.type
) {
1883 FST_WRW(card
, portConfig
[i
].lineInterface
, V35
);
1888 FST_WRW(card
, portConfig
[i
].lineInterface
, V24
);
1893 FST_WRW(card
, portConfig
[i
].lineInterface
, X21
);
1898 FST_WRW(card
, portConfig
[i
].lineInterface
, X21D
);
1903 FST_WRW(card
, portConfig
[i
].lineInterface
, T1
);
1908 FST_WRW(card
, portConfig
[i
].lineInterface
, E1
);
1912 case IF_IFACE_SYNC_SERIAL
:
1919 switch (sync
.clock_type
) {
1921 FST_WRB(card
, portConfig
[i
].internalClock
, EXTCLK
);
1925 FST_WRB(card
, portConfig
[i
].internalClock
, INTCLK
);
1931 FST_WRL(card
, portConfig
[i
].lineSpeed
, sync
.clock_rate
);
1936 fst_get_iface(struct fst_card_info
*card
, struct fst_port_info
*port
,
1939 sync_serial_settings sync
;
1942 /* First check what line type is set, we'll default to reporting X.21
1943 * if nothing is set as IF_IFACE_SYNC_SERIAL implies it can't be
1946 switch (port
->hwif
) {
1948 ifr
->ifr_settings
.type
= IF_IFACE_E1
;
1951 ifr
->ifr_settings
.type
= IF_IFACE_T1
;
1954 ifr
->ifr_settings
.type
= IF_IFACE_V35
;
1957 ifr
->ifr_settings
.type
= IF_IFACE_V24
;
1960 ifr
->ifr_settings
.type
= IF_IFACE_X21D
;
1964 ifr
->ifr_settings
.type
= IF_IFACE_X21
;
1967 if (ifr
->ifr_settings
.size
== 0) {
1968 return 0; /* only type requested */
1970 if (ifr
->ifr_settings
.size
< sizeof (sync
)) {
1975 sync
.clock_rate
= FST_RDL(card
, portConfig
[i
].lineSpeed
);
1976 /* Lucky card and linux use same encoding here */
1977 sync
.clock_type
= FST_RDB(card
, portConfig
[i
].internalClock
) ==
1978 INTCLK
? CLOCK_INT
: CLOCK_EXT
;
1981 if (copy_to_user(ifr
->ifr_settings
.ifs_ifsu
.sync
, &sync
, sizeof (sync
))) {
1985 ifr
->ifr_settings
.size
= sizeof (sync
);
1990 fst_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
1992 struct fst_card_info
*card
;
1993 struct fst_port_info
*port
;
1994 struct fstioc_write wrthdr
;
1995 struct fstioc_info info
;
1996 unsigned long flags
;
1999 dbg(DBG_IOCTL
, "ioctl: %x, %p\n", cmd
, ifr
->ifr_data
);
2001 port
= dev_to_port(dev
);
2004 if (!capable(CAP_NET_ADMIN
))
2010 card
->state
= FST_RESET
;
2014 fst_cpurelease(card
);
2015 card
->state
= FST_STARTING
;
2018 case FSTWRITE
: /* Code write (download) */
2020 /* First copy in the header with the length and offset of data
2023 if (ifr
->ifr_data
== NULL
) {
2026 if (copy_from_user(&wrthdr
, ifr
->ifr_data
,
2027 sizeof (struct fstioc_write
))) {
2031 /* Sanity check the parameters. We don't support partial writes
2032 * when going over the top
2034 if (wrthdr
.size
> FST_MEMSIZE
|| wrthdr
.offset
> FST_MEMSIZE
||
2035 wrthdr
.size
+ wrthdr
.offset
> FST_MEMSIZE
) {
2039 /* Now copy the data to the card. */
2041 buf
= memdup_user(ifr
->ifr_data
+ sizeof(struct fstioc_write
),
2044 return PTR_ERR(buf
);
2046 memcpy_toio(card
->mem
+ wrthdr
.offset
, buf
, wrthdr
.size
);
2049 /* Writes to the memory of a card in the reset state constitute
2052 if (card
->state
== FST_RESET
) {
2053 card
->state
= FST_DOWNLOAD
;
2059 /* If card has just been started check the shared memory config
2060 * version and marker
2062 if (card
->state
== FST_STARTING
) {
2063 check_started_ok(card
);
2065 /* If everything checked out enable card interrupts */
2066 if (card
->state
== FST_RUNNING
) {
2067 spin_lock_irqsave(&card
->card_lock
, flags
);
2068 fst_enable_intr(card
);
2069 FST_WRB(card
, interruptHandshake
, 0xEE);
2070 spin_unlock_irqrestore(&card
->card_lock
, flags
);
2074 if (ifr
->ifr_data
== NULL
) {
2078 gather_conf_info(card
, port
, &info
);
2080 if (copy_to_user(ifr
->ifr_data
, &info
, sizeof (info
))) {
2088 * Most of the settings have been moved to the generic ioctls
2089 * this just covers debug and board ident now
2092 if (card
->state
!= FST_RUNNING
) {
2093 pr_err("Attempt to configure card %d in non-running state (%d)\n",
2094 card
->card_no
, card
->state
);
2097 if (copy_from_user(&info
, ifr
->ifr_data
, sizeof (info
))) {
2101 return set_conf_from_info(card
, port
, &info
);
2104 switch (ifr
->ifr_settings
.type
) {
2106 return fst_get_iface(card
, port
, ifr
);
2108 case IF_IFACE_SYNC_SERIAL
:
2115 return fst_set_iface(card
, port
, ifr
);
2118 port
->mode
= FST_RAW
;
2122 if (port
->mode
== FST_RAW
) {
2123 ifr
->ifr_settings
.type
= IF_PROTO_RAW
;
2126 return hdlc_ioctl(dev
, ifr
, cmd
);
2129 port
->mode
= FST_GEN_HDLC
;
2130 dbg(DBG_IOCTL
, "Passing this type to hdlc %x\n",
2131 ifr
->ifr_settings
.type
);
2132 return hdlc_ioctl(dev
, ifr
, cmd
);
2136 /* Not one of ours. Pass through to HDLC package */
2137 return hdlc_ioctl(dev
, ifr
, cmd
);
2142 fst_openport(struct fst_port_info
*port
)
2147 /* Only init things if card is actually running. This allows open to
2148 * succeed for downloads etc.
2150 if (port
->card
->state
== FST_RUNNING
) {
2152 dbg(DBG_OPEN
, "open: found port already running\n");
2154 fst_issue_cmd(port
, STOPPORT
);
2158 fst_rx_config(port
);
2159 fst_tx_config(port
);
2160 fst_op_raise(port
, OPSTS_RTS
| OPSTS_DTR
);
2162 fst_issue_cmd(port
, STARTPORT
);
2165 signals
= FST_RDL(port
->card
, v24DebouncedSts
[port
->index
]);
2166 if (signals
& (((port
->hwif
== X21
) || (port
->hwif
== X21D
))
2167 ? IPSTS_INDICATE
: IPSTS_DCD
))
2168 netif_carrier_on(port_to_dev(port
));
2170 netif_carrier_off(port_to_dev(port
));
2172 txq_length
= port
->txqe
- port
->txqs
;
2180 fst_closeport(struct fst_port_info
*port
)
2182 if (port
->card
->state
== FST_RUNNING
) {
2185 fst_op_lower(port
, OPSTS_RTS
| OPSTS_DTR
);
2187 fst_issue_cmd(port
, STOPPORT
);
2189 dbg(DBG_OPEN
, "close: port not running\n");
2195 fst_open(struct net_device
*dev
)
2198 struct fst_port_info
*port
;
2200 port
= dev_to_port(dev
);
2201 if (!try_module_get(THIS_MODULE
))
2204 if (port
->mode
!= FST_RAW
) {
2205 err
= hdlc_open(dev
);
2211 netif_wake_queue(dev
);
2216 fst_close(struct net_device
*dev
)
2218 struct fst_port_info
*port
;
2219 struct fst_card_info
*card
;
2220 unsigned char tx_dma_done
;
2221 unsigned char rx_dma_done
;
2223 port
= dev_to_port(dev
);
2226 tx_dma_done
= inb(card
->pci_conf
+ DMACSR1
);
2227 rx_dma_done
= inb(card
->pci_conf
+ DMACSR0
);
2229 "Port Close: tx_dma_in_progress = %d (%x) rx_dma_in_progress = %d (%x)\n",
2230 card
->dmatx_in_progress
, tx_dma_done
, card
->dmarx_in_progress
,
2233 netif_stop_queue(dev
);
2234 fst_closeport(dev_to_port(dev
));
2235 if (port
->mode
!= FST_RAW
) {
2238 module_put(THIS_MODULE
);
2243 fst_attach(struct net_device
*dev
, unsigned short encoding
, unsigned short parity
)
2246 * Setting currently fixed in FarSync card so we check and forget
2248 if (encoding
!= ENCODING_NRZ
|| parity
!= PARITY_CRC16_PR1_CCITT
)
2254 fst_tx_timeout(struct net_device
*dev
)
2256 struct fst_port_info
*port
;
2257 struct fst_card_info
*card
;
2259 port
= dev_to_port(dev
);
2261 dev
->stats
.tx_errors
++;
2262 dev
->stats
.tx_aborted_errors
++;
2263 dbg(DBG_ASS
, "Tx timeout card %d port %d\n",
2264 card
->card_no
, port
->index
);
2265 fst_issue_cmd(port
, ABORTTX
);
2267 dev
->trans_start
= jiffies
;
2268 netif_wake_queue(dev
);
2273 fst_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
2275 struct fst_card_info
*card
;
2276 struct fst_port_info
*port
;
2277 unsigned long flags
;
2280 port
= dev_to_port(dev
);
2282 dbg(DBG_TX
, "fst_start_xmit: length = %d\n", skb
->len
);
2284 /* Drop packet with error if we don't have carrier */
2285 if (!netif_carrier_ok(dev
)) {
2287 dev
->stats
.tx_errors
++;
2288 dev
->stats
.tx_carrier_errors
++;
2290 "Tried to transmit but no carrier on card %d port %d\n",
2291 card
->card_no
, port
->index
);
2292 return NETDEV_TX_OK
;
2295 /* Drop it if it's too big! MTU failure ? */
2296 if (skb
->len
> LEN_TX_BUFFER
) {
2297 dbg(DBG_ASS
, "Packet too large %d vs %d\n", skb
->len
,
2300 dev
->stats
.tx_errors
++;
2301 return NETDEV_TX_OK
;
2305 * We are always going to queue the packet
2306 * so that the bottom half is the only place we tx from
2307 * Check there is room in the port txq
2309 spin_lock_irqsave(&card
->card_lock
, flags
);
2310 if ((txq_length
= port
->txqe
- port
->txqs
) < 0) {
2312 * This is the case where the next free has wrapped but the
2315 txq_length
= txq_length
+ FST_TXQ_DEPTH
;
2317 spin_unlock_irqrestore(&card
->card_lock
, flags
);
2318 if (txq_length
> fst_txq_high
) {
2320 * We have got enough buffers in the pipeline. Ask the network
2321 * layer to stop sending frames down
2323 netif_stop_queue(dev
);
2324 port
->start
= 1; /* I'm using this to signal stop sent up */
2327 if (txq_length
== FST_TXQ_DEPTH
- 1) {
2329 * This shouldn't have happened but such is life
2332 dev
->stats
.tx_errors
++;
2333 dbg(DBG_ASS
, "Tx queue overflow card %d port %d\n",
2334 card
->card_no
, port
->index
);
2335 return NETDEV_TX_OK
;
2341 spin_lock_irqsave(&card
->card_lock
, flags
);
2342 port
->txq
[port
->txqe
] = skb
;
2344 if (port
->txqe
== FST_TXQ_DEPTH
)
2346 spin_unlock_irqrestore(&card
->card_lock
, flags
);
2348 /* Scehdule the bottom half which now does transmit processing */
2349 fst_q_work_item(&fst_work_txq
, card
->card_no
);
2350 tasklet_schedule(&fst_tx_task
);
2352 return NETDEV_TX_OK
;
2356 * Card setup having checked hardware resources.
2357 * Should be pretty bizarre if we get an error here (kernel memory
2358 * exhaustion is one possibility). If we do see a problem we report it
2359 * via a printk and leave the corresponding interface and all that follow
2362 static char *type_strings
[] __devinitdata
= {
2363 "no hardware", /* Should never be seen */
2372 static void __devinit
2373 fst_init_card(struct fst_card_info
*card
)
2378 /* We're working on a number of ports based on the card ID. If the
2379 * firmware detects something different later (should never happen)
2380 * we'll have to revise it in some way then.
2382 for (i
= 0; i
< card
->nports
; i
++) {
2383 err
= register_hdlc_device(card
->ports
[i
].dev
);
2386 pr_err("Cannot register HDLC device for port %d (errno %d)\n",
2388 for (j
= i
; j
< card
->nports
; j
++) {
2389 free_netdev(card
->ports
[j
].dev
);
2390 card
->ports
[j
].dev
= NULL
;
2397 pr_info("%s-%s: %s IRQ%d, %d ports\n",
2398 port_to_dev(&card
->ports
[0])->name
,
2399 port_to_dev(&card
->ports
[card
->nports
- 1])->name
,
2400 type_strings
[card
->type
], card
->irq
, card
->nports
);
2403 static const struct net_device_ops fst_ops
= {
2404 .ndo_open
= fst_open
,
2405 .ndo_stop
= fst_close
,
2406 .ndo_change_mtu
= hdlc_change_mtu
,
2407 .ndo_start_xmit
= hdlc_start_xmit
,
2408 .ndo_do_ioctl
= fst_ioctl
,
2409 .ndo_tx_timeout
= fst_tx_timeout
,
2413 * Initialise card when detected.
2414 * Returns 0 to indicate success, or errno otherwise.
2416 static int __devinit
2417 fst_add_one(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
2419 static int no_of_cards_added
= 0;
2420 struct fst_card_info
*card
;
2424 printk_once(KERN_INFO
2425 pr_fmt("FarSync WAN driver " FST_USER_VERSION
2426 " (c) 2001-2004 FarSite Communications Ltd.\n"));
2428 dbg(DBG_ASS
, "The value of debug mask is %x\n", fst_debug_mask
);
2431 * We are going to be clever and allow certain cards not to be
2432 * configured. An exclude list can be provided in /etc/modules.conf
2434 if (fst_excluded_cards
!= 0) {
2436 * There are cards to exclude
2439 for (i
= 0; i
< fst_excluded_cards
; i
++) {
2440 if ((pdev
->devfn
) >> 3 == fst_excluded_list
[i
]) {
2441 pr_info("FarSync PCI device %d not assigned\n",
2442 (pdev
->devfn
) >> 3);
2448 /* Allocate driver private data */
2449 card
= kzalloc(sizeof (struct fst_card_info
), GFP_KERNEL
);
2451 pr_err("FarSync card found but insufficient memory for driver storage\n");
2455 /* Try to enable the device */
2456 if ((err
= pci_enable_device(pdev
)) != 0) {
2457 pr_err("Failed to enable card. Err %d\n", -err
);
2462 if ((err
= pci_request_regions(pdev
, "FarSync")) !=0) {
2463 pr_err("Failed to allocate regions. Err %d\n", -err
);
2464 pci_disable_device(pdev
);
2469 /* Get virtual addresses of memory regions */
2470 card
->pci_conf
= pci_resource_start(pdev
, 1);
2471 card
->phys_mem
= pci_resource_start(pdev
, 2);
2472 card
->phys_ctlmem
= pci_resource_start(pdev
, 3);
2473 if ((card
->mem
= ioremap(card
->phys_mem
, FST_MEMSIZE
)) == NULL
) {
2474 pr_err("Physical memory remap failed\n");
2475 pci_release_regions(pdev
);
2476 pci_disable_device(pdev
);
2480 if ((card
->ctlmem
= ioremap(card
->phys_ctlmem
, 0x10)) == NULL
) {
2481 pr_err("Control memory remap failed\n");
2482 pci_release_regions(pdev
);
2483 pci_disable_device(pdev
);
2487 dbg(DBG_PCI
, "kernel mem %p, ctlmem %p\n", card
->mem
, card
->ctlmem
);
2489 /* Register the interrupt handler */
2490 if (request_irq(pdev
->irq
, fst_intr
, IRQF_SHARED
, FST_DEV_NAME
, card
)) {
2491 pr_err("Unable to register interrupt %d\n", card
->irq
);
2492 pci_release_regions(pdev
);
2493 pci_disable_device(pdev
);
2494 iounmap(card
->ctlmem
);
2500 /* Record info we need */
2501 card
->irq
= pdev
->irq
;
2502 card
->type
= ent
->driver_data
;
2503 card
->family
= ((ent
->driver_data
== FST_TYPE_T2P
) ||
2504 (ent
->driver_data
== FST_TYPE_T4P
))
2505 ? FST_FAMILY_TXP
: FST_FAMILY_TXU
;
2506 if ((ent
->driver_data
== FST_TYPE_T1U
) ||
2507 (ent
->driver_data
== FST_TYPE_TE1
))
2510 card
->nports
= ((ent
->driver_data
== FST_TYPE_T2P
) ||
2511 (ent
->driver_data
== FST_TYPE_T2U
)) ? 2 : 4;
2513 card
->state
= FST_UNINIT
;
2514 spin_lock_init ( &card
->card_lock
);
2516 for ( i
= 0 ; i
< card
->nports
; i
++ ) {
2517 struct net_device
*dev
= alloc_hdlcdev(&card
->ports
[i
]);
2521 free_netdev(card
->ports
[i
].dev
);
2522 pr_err("FarSync: out of memory\n");
2523 free_irq(card
->irq
, card
);
2524 pci_release_regions(pdev
);
2525 pci_disable_device(pdev
);
2526 iounmap(card
->ctlmem
);
2531 card
->ports
[i
].dev
= dev
;
2532 card
->ports
[i
].card
= card
;
2533 card
->ports
[i
].index
= i
;
2534 card
->ports
[i
].run
= 0;
2536 hdlc
= dev_to_hdlc(dev
);
2538 /* Fill in the net device info */
2539 /* Since this is a PCI setup this is purely
2540 * informational. Give them the buffer addresses
2541 * and basic card I/O.
2543 dev
->mem_start
= card
->phys_mem
2544 + BUF_OFFSET ( txBuffer
[i
][0][0]);
2545 dev
->mem_end
= card
->phys_mem
2546 + BUF_OFFSET ( txBuffer
[i
][NUM_TX_BUFFER
][0]);
2547 dev
->base_addr
= card
->pci_conf
;
2548 dev
->irq
= card
->irq
;
2550 dev
->netdev_ops
= &fst_ops
;
2551 dev
->tx_queue_len
= FST_TX_QUEUE_LEN
;
2552 dev
->watchdog_timeo
= FST_TX_TIMEOUT
;
2553 hdlc
->attach
= fst_attach
;
2554 hdlc
->xmit
= fst_start_xmit
;
2557 card
->device
= pdev
;
2559 dbg(DBG_PCI
, "type %d nports %d irq %d\n", card
->type
,
2560 card
->nports
, card
->irq
);
2561 dbg(DBG_PCI
, "conf %04x mem %08x ctlmem %08x\n",
2562 card
->pci_conf
, card
->phys_mem
, card
->phys_ctlmem
);
2564 /* Reset the card's processor */
2566 card
->state
= FST_RESET
;
2568 /* Initialise DMA (if required) */
2571 /* Record driver data for later use */
2572 pci_set_drvdata(pdev
, card
);
2574 /* Remainder of card setup */
2575 fst_card_array
[no_of_cards_added
] = card
;
2576 card
->card_no
= no_of_cards_added
++; /* Record instance and bump it */
2577 fst_init_card(card
);
2578 if (card
->family
== FST_FAMILY_TXU
) {
2580 * Allocate a dma buffer for transmit and receives
2582 card
->rx_dma_handle_host
=
2583 pci_alloc_consistent(card
->device
, FST_MAX_MTU
,
2584 &card
->rx_dma_handle_card
);
2585 if (card
->rx_dma_handle_host
== NULL
) {
2586 pr_err("Could not allocate rx dma buffer\n");
2587 fst_disable_intr(card
);
2588 pci_release_regions(pdev
);
2589 pci_disable_device(pdev
);
2590 iounmap(card
->ctlmem
);
2595 card
->tx_dma_handle_host
=
2596 pci_alloc_consistent(card
->device
, FST_MAX_MTU
,
2597 &card
->tx_dma_handle_card
);
2598 if (card
->tx_dma_handle_host
== NULL
) {
2599 pr_err("Could not allocate tx dma buffer\n");
2600 fst_disable_intr(card
);
2601 pci_release_regions(pdev
);
2602 pci_disable_device(pdev
);
2603 iounmap(card
->ctlmem
);
2609 return 0; /* Success */
2613 * Cleanup and close down a card
2615 static void __devexit
2616 fst_remove_one(struct pci_dev
*pdev
)
2618 struct fst_card_info
*card
;
2621 card
= pci_get_drvdata(pdev
);
2623 for (i
= 0; i
< card
->nports
; i
++) {
2624 struct net_device
*dev
= port_to_dev(&card
->ports
[i
]);
2625 unregister_hdlc_device(dev
);
2628 fst_disable_intr(card
);
2629 free_irq(card
->irq
, card
);
2631 iounmap(card
->ctlmem
);
2633 pci_release_regions(pdev
);
2634 if (card
->family
== FST_FAMILY_TXU
) {
2638 pci_free_consistent(card
->device
, FST_MAX_MTU
,
2639 card
->rx_dma_handle_host
,
2640 card
->rx_dma_handle_card
);
2641 pci_free_consistent(card
->device
, FST_MAX_MTU
,
2642 card
->tx_dma_handle_host
,
2643 card
->tx_dma_handle_card
);
2645 fst_card_array
[card
->card_no
] = NULL
;
2648 static struct pci_driver fst_driver
= {
2650 .id_table
= fst_pci_dev_id
,
2651 .probe
= fst_add_one
,
2652 .remove
= __devexit_p(fst_remove_one
),
2662 for (i
= 0; i
< FST_MAX_CARDS
; i
++)
2663 fst_card_array
[i
] = NULL
;
2664 spin_lock_init(&fst_work_q_lock
);
2665 return pci_register_driver(&fst_driver
);
2669 fst_cleanup_module(void)
2671 pr_info("FarSync WAN driver unloading\n");
2672 pci_unregister_driver(&fst_driver
);
2675 module_init(fst_init
);
2676 module_exit(fst_cleanup_module
);