2 Madge Horizon ATM Adapter driver.
3 Copyright (C) 1995-1999 Madge Networks Ltd.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 The GNU GPL is contained in /usr/doc/copyright/GPL on a Debian
20 system and in the file COPYING in the Linux kernel source.
24 IMPORTANT NOTE: Madge Networks no longer makes the adapters
25 supported by this driver and makes no commitment to maintain it.
28 #include <linux/module.h>
29 #include <linux/kernel.h>
31 #include <linux/pci.h>
32 #include <linux/errno.h>
33 #include <linux/atm.h>
34 #include <linux/atmdev.h>
35 #include <linux/sonet.h>
36 #include <linux/skbuff.h>
37 #include <linux/time.h>
38 #include <linux/delay.h>
39 #include <linux/uio.h>
40 #include <linux/init.h>
41 #include <linux/interrupt.h>
42 #include <linux/ioport.h>
43 #include <linux/wait.h>
44 #include <linux/slab.h>
46 #include <asm/system.h>
48 #include <linux/atomic.h>
49 #include <asm/uaccess.h>
50 #include <asm/string.h>
51 #include <asm/byteorder.h>
55 #define maintainer_string "Giuliano Procida at Madge Networks <gprocida@madge.com>"
56 #define description_string "Madge ATM Horizon [Ultra] driver"
57 #define version_string "1.2.1"
59 static inline void __init
show_version (void) {
60 printk ("%s version %s\n", description_string
, version_string
);
67 Driver and documentation by:
69 Chris Aston Madge Networks
70 Giuliano Procida Madge Networks
71 Simon Benham Madge Networks
72 Simon Johnson Madge Networks
73 Various Others Madge Networks
75 Some inspiration taken from other drivers by:
78 Kari Mettinen University of Helsinki
79 Werner Almesberger EPFL LRC
83 I Hardware, detection, initialisation and shutdown.
87 This driver should handle all variants of the PCI Madge ATM adapters
88 with the Horizon chipset. These are all PCI cards supporting PIO, BM
89 DMA and a form of MMIO (registers only, not internal RAM).
91 The driver is only known to work with SONET and UTP Horizon Ultra
92 cards at 155Mb/s. However, code is in place to deal with both the
93 original Horizon and 25Mb/s operation.
95 There are two revisions of the Horizon ASIC: the original and the
96 Ultra. Details of hardware bugs are in section III.
98 The ASIC version can be distinguished by chip markings but is NOT
99 indicated by the PCI revision (all adapters seem to have PCI rev 1).
103 Horizon => Collage 25 PCI Adapter (UTP and STP)
104 Horizon Ultra => Collage 155 PCI Client (UTP or SONET)
105 Ambassador x => Collage 155 PCI Server (completely different)
107 Horizon (25Mb/s) is fitted with UTP and STP connectors. It seems to
108 have a Madge B154 plus glue logic serializer. I have also found a
109 really ancient version of this with slightly different glue. It
110 comes with the revision 0 (140-025-01) ASIC.
112 Horizon Ultra (155Mb/s) is fitted with either a Pulse Medialink
113 output (UTP) or an HP HFBR 5205 output (SONET). It has either
114 Madge's SAMBA framer or a SUNI-lite device (early versions). It
115 comes with the revision 1 (140-027-01) ASIC.
119 All Horizon-based cards present with the same PCI Vendor and Device
120 IDs. The standard Linux 2.2 PCI API is used to locate any cards and
121 to enable bus-mastering (with appropriate latency).
123 ATM_LAYER_STATUS in the control register distinguishes between the
124 two possible physical layers (25 and 155). It is not clear whether
125 the 155 cards can also operate at 25Mbps. We rely on the fact that a
126 card operates at 155 if and only if it has the newer Horizon Ultra
129 For 155 cards the two possible framers are probed for and then set
134 The card is reset and then put into a known state. The physical
135 layer is configured for normal operation at the appropriate speed;
136 in the case of the 155 cards, the framer is initialised with
137 line-based timing; the internal RAM is zeroed and the allocation of
138 buffers for RX and TX is made; the Burnt In Address is read and
139 copied to the ATM ESI; various policy settings for RX (VPI bits,
140 unknown VCs, oam cells) are made. Ideally all policy items should be
141 configurable at module load (if not actually on-demand), however,
142 only the vpi vs vci bit allocation can be specified at insmod.
146 This is in response to module_cleaup. No VCs are in use and the card
147 should be idle; it is reset.
149 II Driver software (as it should be)
151 0. Traffic Parameters
153 The traffic classes (not an enumeration) are currently: ATM_NONE (no
154 traffic), ATM_UBR, ATM_CBR, ATM_VBR and ATM_ABR, ATM_ANYCLASS
155 (compatible with everything). Together with (perhaps only some of)
156 the following items they make up the traffic specification.
159 unsigned char traffic_class; traffic class (ATM_UBR, ...)
160 int max_pcr; maximum PCR in cells per second
161 int pcr; desired PCR in cells per second
162 int min_pcr; minimum PCR in cells per second
163 int max_cdv; maximum CDV in microseconds
164 int max_sdu; maximum SDU in bytes
167 Note that these denote bandwidth available not bandwidth used; the
168 possibilities according to ATMF are:
170 Real Time (cdv and max CDT given)
172 CBR(pcr) pcr bandwidth always available
173 rtVBR(pcr,scr,mbs) scr bandwidth always available, up to pcr at mbs too
177 nrtVBR(pcr,scr,mbs) scr bandwidth always available, up to pcr at mbs too
179 ABR(mcr,pcr) mcr bandwidth always available, up to pcr (depending) too
181 mbs is max burst size (bucket)
182 pcr and scr have associated cdvt values
183 mcr is like scr but has no cdtv
184 cdtv may differ at each hop
186 Some of the above items are qos items (as opposed to traffic
187 parameters). We have nothing to do with qos. All except ABR can have
188 their traffic parameters converted to GCRA parameters. The GCRA may
189 be implemented as a (real-number) leaky bucket. The GCRA can be used
190 in complicated ways by switches and in simpler ways by end-stations.
191 It can be used both to filter incoming cells and shape out-going
194 ATM Linux actually supports:
196 ATM_NONE() (no traffic in this direction)
197 ATM_UBR(max_frame_size)
198 ATM_CBR(max/min_pcr, max_cdv, max_frame_size)
200 0 or ATM_MAX_PCR are used to indicate maximum available PCR
202 A traffic specification consists of the AAL type and separate
203 traffic specifications for either direction. In ATM Linux it is:
206 struct atm_trafprm txtp;
207 struct atm_trafprm rxtp;
213 ATM_NO_AAL AAL not specified
214 ATM_AAL0 "raw" ATM cells
217 ATM_AAL34 AAL3/4 (data)
219 ATM_SAAL signaling AAL
221 The Horizon has support for AAL frame types: 0, 3/4 and 5. However,
222 it does not implement AAL 3/4 SAR and it has a different notion of
223 "raw cell" to ATM Linux's (48 bytes vs. 52 bytes) so neither are
224 supported by this driver.
226 The Horizon has limited support for ABR (including UBR), VBR and
227 CBR. Each TX channel has a bucket (containing up to 31 cell units)
228 and two timers (PCR and SCR) associated with it that can be used to
229 govern cell emissions and host notification (in the case of ABR this
230 is presumably so that RM cells may be emitted at appropriate times).
231 The timers may either be disabled or may be set to any of 240 values
232 (determined by the clock crystal, a fixed (?) per-device divider, a
233 configurable divider and a configurable timer preload value).
235 At the moment only UBR and CBR are supported by the driver. VBR will
236 be supported as soon as ATM for Linux supports it. ABR support is
237 very unlikely as RM cell handling is completely up to the driver.
239 1. TX (TX channel setup and TX transfer)
241 The TX half of the driver owns the TX Horizon registers. The TX
242 component in the IRQ handler is the BM completion handler. This can
243 only be entered when tx_busy is true (enforced by hardware). The
244 other TX component can only be entered when tx_busy is false
245 (enforced by driver). So TX is single-threaded.
247 Apart from a minor optimisation to not re-select the last channel,
248 the TX send component works as follows:
250 Atomic test and set tx_busy until we succeed; we should implement
251 some sort of timeout so that tx_busy will never be stuck at true.
253 If no TX channel is set up for this VC we wait for an idle one (if
254 necessary) and set it up.
256 At this point we have a TX channel ready for use. We wait for enough
257 buffers to become available then start a TX transmit (set the TX
258 descriptor, schedule transfer, exit).
260 The IRQ component handles TX completion (stats, free buffer, tx_busy
261 unset, exit). We also re-schedule further transfers for the same
264 TX setup in more detail:
266 TX open is a nop, the relevant information is held in the hrz_vcc
267 (vcc->dev_data) structure and is "cached" on the card.
269 TX close gets the TX lock and clears the channel from the "cache".
271 2. RX (Data Available and RX transfer)
273 The RX half of the driver owns the RX registers. There are two RX
274 components in the IRQ handler: the data available handler deals with
275 fresh data that has arrived on the card, the BM completion handler
276 is very similar to the TX completion handler. The data available
277 handler grabs the rx_lock and it is only released once the data has
278 been discarded or completely transferred to the host. The BM
279 completion handler only runs when the lock is held; the data
280 available handler is locked out over the same period.
282 Data available on the card triggers an interrupt. If the data is not
283 suitable for our existing RX channels or we cannot allocate a buffer
284 it is flushed. Otherwise an RX receive is scheduled. Multiple RX
285 transfers may be scheduled for the same frame.
287 RX setup in more detail:
294 0. Byte vs Word addressing of adapter RAM.
296 A design feature; see the .h file (especially the memory map).
298 1. Bus Master Data Transfers (original Horizon only, fixed in Ultra)
300 The host must not start a transmit direction transfer at a
301 non-four-byte boundary in host memory. Instead the host should
302 perform a byte, or a two byte, or one byte followed by two byte
303 transfer in order to start the rest of the transfer on a four byte
306 Simultaneous transmit and receive direction bus master transfers are
309 The simplest solution to these two is to always do PIO (never DMA)
310 in the TX direction on the original Horizon. More complicated
311 solutions are likely to hurt my brain.
313 2. Loss of buffer on close VC
315 When a VC is being closed, the buffer associated with it is not
316 returned to the pool. The host must store the reference to this
317 buffer and when opening a new VC then give it to that new VC.
319 The host intervention currently consists of stacking such a buffer
320 pointer at VC close and checking the stack at VC open.
322 3. Failure to close a VC
324 If a VC is currently receiving a frame then closing the VC may fail
325 and the frame continues to be received.
327 The solution is to make sure any received frames are flushed when
328 ready. This is currently done just before the solution to 2.
330 4. PCI bus (original Horizon only, fixed in Ultra)
332 Reading from the data port prior to initialisation will hang the PCI
333 bus. Just don't do that then! We don't.
337 . Timer code may be broken.
339 . Allow users to specify buffer allocation split for TX and RX.
341 . Deal once and for all with buggy VC close.
343 . Handle interrupted and/or non-blocking operations.
345 . Change some macros to functions and move from .h to .c.
347 . Try to limit the number of TX frames each VC may have queued, in
348 order to reduce the chances of TX buffer exhaustion.
350 . Implement VBR (bucket and timers not understood) and ABR (need to
351 do RM cells manually); also no Linux support for either.
353 . Implement QoS changes on open VCs (involves extracting parts of VC open
354 and close into separate functions and using them to make changes).
358 /********** globals **********/
360 static void do_housekeeping (unsigned long arg
);
362 static unsigned short debug
= 0;
363 static unsigned short vpi_bits
= 0;
364 static int max_tx_size
= 9000;
365 static int max_rx_size
= 9000;
366 static unsigned char pci_lat
= 0;
368 /********** access functions **********/
370 /* Read / Write Horizon registers */
371 static inline void wr_regl (const hrz_dev
* dev
, unsigned char reg
, u32 data
) {
372 outl (cpu_to_le32 (data
), dev
->iobase
+ reg
);
375 static inline u32
rd_regl (const hrz_dev
* dev
, unsigned char reg
) {
376 return le32_to_cpu (inl (dev
->iobase
+ reg
));
379 static inline void wr_regw (const hrz_dev
* dev
, unsigned char reg
, u16 data
) {
380 outw (cpu_to_le16 (data
), dev
->iobase
+ reg
);
383 static inline u16
rd_regw (const hrz_dev
* dev
, unsigned char reg
) {
384 return le16_to_cpu (inw (dev
->iobase
+ reg
));
387 static inline void wrs_regb (const hrz_dev
* dev
, unsigned char reg
, void * addr
, u32 len
) {
388 outsb (dev
->iobase
+ reg
, addr
, len
);
391 static inline void rds_regb (const hrz_dev
* dev
, unsigned char reg
, void * addr
, u32 len
) {
392 insb (dev
->iobase
+ reg
, addr
, len
);
395 /* Read / Write to a given address in Horizon buffer memory.
396 Interrupts must be disabled between the address register and data
397 port accesses as these must form an atomic operation. */
398 static inline void wr_mem (const hrz_dev
* dev
, HDW
* addr
, u32 data
) {
399 // wr_regl (dev, MEM_WR_ADDR_REG_OFF, (u32) addr);
400 wr_regl (dev
, MEM_WR_ADDR_REG_OFF
, (addr
- (HDW
*) 0) * sizeof(HDW
));
401 wr_regl (dev
, MEMORY_PORT_OFF
, data
);
404 static inline u32
rd_mem (const hrz_dev
* dev
, HDW
* addr
) {
405 // wr_regl (dev, MEM_RD_ADDR_REG_OFF, (u32) addr);
406 wr_regl (dev
, MEM_RD_ADDR_REG_OFF
, (addr
- (HDW
*) 0) * sizeof(HDW
));
407 return rd_regl (dev
, MEMORY_PORT_OFF
);
410 static inline void wr_framer (const hrz_dev
* dev
, u32 addr
, u32 data
) {
411 wr_regl (dev
, MEM_WR_ADDR_REG_OFF
, (u32
) addr
| 0x80000000);
412 wr_regl (dev
, MEMORY_PORT_OFF
, data
);
415 static inline u32
rd_framer (const hrz_dev
* dev
, u32 addr
) {
416 wr_regl (dev
, MEM_RD_ADDR_REG_OFF
, (u32
) addr
| 0x80000000);
417 return rd_regl (dev
, MEMORY_PORT_OFF
);
420 /********** specialised access functions **********/
424 static inline void FLUSH_RX_CHANNEL (hrz_dev
* dev
, u16 channel
) {
425 wr_regw (dev
, RX_CHANNEL_PORT_OFF
, FLUSH_CHANNEL
| channel
);
429 static void WAIT_FLUSH_RX_COMPLETE (hrz_dev
* dev
) {
430 while (rd_regw (dev
, RX_CHANNEL_PORT_OFF
) & FLUSH_CHANNEL
)
435 static inline void SELECT_RX_CHANNEL (hrz_dev
* dev
, u16 channel
) {
436 wr_regw (dev
, RX_CHANNEL_PORT_OFF
, channel
);
440 static void WAIT_UPDATE_COMPLETE (hrz_dev
* dev
) {
441 while (rd_regw (dev
, RX_CHANNEL_PORT_OFF
) & RX_CHANNEL_UPDATE_IN_PROGRESS
)
448 static inline void SELECT_TX_CHANNEL (hrz_dev
* dev
, u16 tx_channel
) {
449 wr_regl (dev
, TX_CHANNEL_PORT_OFF
, tx_channel
);
453 /* Update or query one configuration parameter of a particular channel. */
455 static inline void update_tx_channel_config (hrz_dev
* dev
, short chan
, u8 mode
, u16 value
) {
456 wr_regw (dev
, TX_CHANNEL_CONFIG_COMMAND_OFF
,
457 chan
* TX_CHANNEL_CONFIG_MULT
| mode
);
458 wr_regw (dev
, TX_CHANNEL_CONFIG_DATA_OFF
, value
);
462 static inline u16
query_tx_channel_config (hrz_dev
* dev
, short chan
, u8 mode
) {
463 wr_regw (dev
, TX_CHANNEL_CONFIG_COMMAND_OFF
,
464 chan
* TX_CHANNEL_CONFIG_MULT
| mode
);
465 return rd_regw (dev
, TX_CHANNEL_CONFIG_DATA_OFF
);
468 /********** dump functions **********/
470 static inline void dump_skb (char * prefix
, unsigned int vc
, struct sk_buff
* skb
) {
473 unsigned char * data
= skb
->data
;
474 PRINTDB (DBG_DATA
, "%s(%u) ", prefix
, vc
);
475 for (i
=0; i
<skb
->len
&& i
< 256;i
++)
476 PRINTDM (DBG_DATA
, "%02x ", data
[i
]);
477 PRINTDE (DBG_DATA
,"");
486 static inline void dump_regs (hrz_dev
* dev
) {
488 PRINTD (DBG_REGS
, "CONTROL 0: %#x", rd_regl (dev
, CONTROL_0_REG
));
489 PRINTD (DBG_REGS
, "RX CONFIG: %#x", rd_regw (dev
, RX_CONFIG_OFF
));
490 PRINTD (DBG_REGS
, "TX CONFIG: %#x", rd_regw (dev
, TX_CONFIG_OFF
));
491 PRINTD (DBG_REGS
, "TX STATUS: %#x", rd_regw (dev
, TX_STATUS_OFF
));
492 PRINTD (DBG_REGS
, "IRQ ENBLE: %#x", rd_regl (dev
, INT_ENABLE_REG_OFF
));
493 PRINTD (DBG_REGS
, "IRQ SORCE: %#x", rd_regl (dev
, INT_SOURCE_REG_OFF
));
500 static inline void dump_framer (hrz_dev
* dev
) {
503 PRINTDB (DBG_REGS
, "framer registers:");
504 for (i
= 0; i
< 0x10; ++i
)
505 PRINTDM (DBG_REGS
, " %02x", rd_framer (dev
, i
));
506 PRINTDE (DBG_REGS
,"");
513 /********** VPI/VCI <-> (RX) channel conversions **********/
515 /* RX channels are 10 bit integers, these fns are quite paranoid */
517 static inline int channel_to_vpivci (const u16 channel
, short * vpi
, int * vci
) {
518 unsigned short vci_bits
= 10 - vpi_bits
;
519 if ((channel
& RX_CHANNEL_MASK
) == channel
) {
520 *vci
= channel
& ((~0)<<vci_bits
);
521 *vpi
= channel
>> vci_bits
;
522 return channel
? 0 : -EINVAL
;
527 static inline int vpivci_to_channel (u16
* channel
, const short vpi
, const int vci
) {
528 unsigned short vci_bits
= 10 - vpi_bits
;
529 if (0 <= vpi
&& vpi
< 1<<vpi_bits
&& 0 <= vci
&& vci
< 1<<vci_bits
) {
530 *channel
= vpi
<<vci_bits
| vci
;
531 return *channel
? 0 : -EINVAL
;
536 /********** decode RX queue entries **********/
538 static inline u16
rx_q_entry_to_length (u32 x
) {
539 return x
& RX_Q_ENTRY_LENGTH_MASK
;
542 static inline u16
rx_q_entry_to_rx_channel (u32 x
) {
543 return (x
>>RX_Q_ENTRY_CHANNEL_SHIFT
) & RX_CHANNEL_MASK
;
546 /* Cell Transmit Rate Values
548 * the cell transmit rate (cells per sec) can be set to a variety of
549 * different values by specifying two parameters: a timer preload from
550 * 1 to 16 (stored as 0 to 15) and a clock divider (2 to the power of
551 * an exponent from 0 to 14; the special value 15 disables the timer).
553 * cellrate = baserate / (preload * 2^divider)
555 * The maximum cell rate that can be specified is therefore just the
556 * base rate. Halving the preload is equivalent to adding 1 to the
557 * divider and so values 1 to 8 of the preload are redundant except
558 * in the case of a maximal divider (14).
560 * Given a desired cell rate, an algorithm to determine the preload
563 * a) x = baserate / cellrate, want p * 2^d = x (as far as possible)
564 * b) if x > 16 * 2^14 then set p = 16, d = 14 (min rate), done
565 * if x <= 16 then set p = x, d = 0 (high rates), done
566 * c) now have 16 < x <= 2^18, or 1 < x/16 <= 2^14 and we want to
567 * know n such that 2^(n-1) < x/16 <= 2^n, so slide a bit until
568 * we find the range (n will be between 1 and 14), set d = n
569 * d) Also have 8 < x/2^n <= 16, so set p nearest x/2^n
571 * The algorithm used below is a minor variant of the above.
573 * The base rate is derived from the oscillator frequency (Hz) using a
576 * baserate = freq / 32 in the case of some Unknown Card
577 * baserate = freq / 8 in the case of the Horizon 25
578 * baserate = freq / 8 in the case of the Horizon Ultra 155
580 * The Horizon cards have oscillators and base rates as follows:
582 * Card Oscillator Base Rate
583 * Unknown Card 33 MHz 1.03125 MHz (33 MHz = PCI freq)
584 * Horizon 25 32 MHz 4 MHz
585 * Horizon Ultra 155 40 MHz 5 MHz
587 * The following defines give the base rates in Hz. These were
588 * previously a factor of 100 larger, no doubt someone was using
592 #define BR_UKN 1031250l
593 #define BR_HRZ 4000000l
594 #define BR_ULT 5000000l
600 // p ranges from 1 to a power of 2
603 static int make_rate (const hrz_dev
* dev
, u32 c
, rounding r
,
604 u16
* bits
, unsigned int * actual
)
606 // note: rounding the rate down means rounding 'p' up
607 const unsigned long br
= test_bit(ultra
, &dev
->flags
) ? BR_ULT
: BR_HRZ
;
612 // br_exp and br_man are used to avoid overflowing (c*maxp*2^d) in
613 // the tests below. We could think harder about exact possibilities
616 unsigned long br_man
= br
;
617 unsigned int br_exp
= 0;
619 PRINTD (DBG_QOS
|DBG_FLOW
, "make_rate b=%lu, c=%u, %s", br
, c
,
620 r
== round_up
? "up" : r
== round_down
? "down" : "nearest");
624 PRINTD (DBG_QOS
|DBG_ERR
, "zero rate is not allowed!");
628 while (br_exp
< CR_MAXPEXP
+ CR_MIND
&& (br_man
% 2 == 0)) {
629 br_man
= br_man
>> 1;
632 // (br >>br_exp) <<br_exp == br and
633 // br_exp <= CR_MAXPEXP+CR_MIND
635 if (br_man
<= (c
<< (CR_MAXPEXP
+CR_MIND
-br_exp
))) {
636 // Equivalent to: B <= (c << (MAXPEXP+MIND))
637 // take care of rounding
640 pre
= DIV_ROUND_UP(br
, c
<<div
);
641 // but p must be non-zero
646 pre
= DIV_ROUND_CLOSEST(br
, c
<<div
);
647 // but p must be non-zero
651 default: /* round_up */
653 // but p must be non-zero
657 PRINTD (DBG_QOS
, "A: p=%u, d=%u", pre
, div
);
661 // at this point we have
662 // d == MIND and (c << (MAXPEXP+MIND)) < B
663 while (div
< CR_MAXD
) {
665 if (br_man
<= (c
<< (CR_MAXPEXP
+div
-br_exp
))) {
666 // Equivalent to: B <= (c << (MAXPEXP+d))
667 // c << (MAXPEXP+d-1) < B <= c << (MAXPEXP+d)
668 // 1 << (MAXPEXP-1) < B/2^d/c <= 1 << MAXPEXP
669 // MAXP/2 < B/c2^d <= MAXP
670 // take care of rounding
673 pre
= DIV_ROUND_UP(br
, c
<<div
);
676 pre
= DIV_ROUND_CLOSEST(br
, c
<<div
);
678 default: /* round_up */
681 PRINTD (DBG_QOS
, "B: p=%u, d=%u", pre
, div
);
685 // at this point we have
686 // d == MAXD and (c << (MAXPEXP+MAXD)) < B
687 // but we cannot go any higher
688 // take care of rounding
691 pre
= 1 << CR_MAXPEXP
;
692 PRINTD (DBG_QOS
, "C: p=%u, d=%u", pre
, div
);
695 if (div
> CR_MAXD
|| (!pre
) || pre
> 1<<CR_MAXPEXP
) {
696 PRINTD (DBG_QOS
, "set_cr internal failure: d=%u p=%u",
701 *bits
= (div
<<CLOCK_SELECT_SHIFT
) | (pre
-1);
703 *actual
= DIV_ROUND_UP(br
, pre
<<div
);
704 PRINTD (DBG_QOS
, "actual rate: %u", *actual
);
710 static int make_rate_with_tolerance (const hrz_dev
* dev
, u32 c
, rounding r
, unsigned int tol
,
711 u16
* bit_pattern
, unsigned int * actual
) {
712 unsigned int my_actual
;
714 PRINTD (DBG_QOS
|DBG_FLOW
, "make_rate_with_tolerance c=%u, %s, tol=%u",
715 c
, (r
== round_up
) ? "up" : (r
== round_down
) ? "down" : "nearest", tol
);
718 // actual rate is not returned
721 if (make_rate (dev
, c
, round_nearest
, bit_pattern
, actual
))
722 // should never happen as round_nearest always succeeds
725 if (c
- tol
<= *actual
&& *actual
<= c
+ tol
)
729 // intolerant, try rounding instead
730 return make_rate (dev
, c
, r
, bit_pattern
, actual
);
733 /********** Listen on a VC **********/
735 static int hrz_open_rx (hrz_dev
* dev
, u16 channel
) {
736 // is there any guarantee that we don't get two simulataneous
737 // identical calls of this function from different processes? yes
740 u32 channel_type
; // u16?
742 u16 buf_ptr
= RX_CHANNEL_IDLE
;
744 rx_ch_desc
* rx_desc
= &memmap
->rx_descs
[channel
];
746 PRINTD (DBG_FLOW
, "hrz_open_rx %x", channel
);
748 spin_lock_irqsave (&dev
->mem_lock
, flags
);
749 channel_type
= rd_mem (dev
, &rx_desc
->wr_buf_type
) & BUFFER_PTR_MASK
;
750 spin_unlock_irqrestore (&dev
->mem_lock
, flags
);
752 // very serious error, should never occur
753 if (channel_type
!= RX_CHANNEL_DISABLED
) {
754 PRINTD (DBG_ERR
|DBG_VCC
, "RX channel for VC already open");
755 return -EBUSY
; // clean up?
758 // Give back spare buffer
759 if (dev
->noof_spare_buffers
) {
760 buf_ptr
= dev
->spare_buffers
[--dev
->noof_spare_buffers
];
761 PRINTD (DBG_VCC
, "using a spare buffer: %u", buf_ptr
);
762 // should never occur
763 if (buf_ptr
== RX_CHANNEL_DISABLED
|| buf_ptr
== RX_CHANNEL_IDLE
) {
764 // but easy to recover from
765 PRINTD (DBG_ERR
|DBG_VCC
, "bad spare buffer pointer, using IDLE");
766 buf_ptr
= RX_CHANNEL_IDLE
;
769 PRINTD (DBG_VCC
, "using IDLE buffer pointer");
772 // Channel is currently disabled so change its status to idle
774 // do we really need to save the flags again?
775 spin_lock_irqsave (&dev
->mem_lock
, flags
);
777 wr_mem (dev
, &rx_desc
->wr_buf_type
,
778 buf_ptr
| CHANNEL_TYPE_AAL5
| FIRST_CELL_OF_AAL5_FRAME
);
779 if (buf_ptr
!= RX_CHANNEL_IDLE
)
780 wr_mem (dev
, &rx_desc
->rd_buf_type
, buf_ptr
);
782 spin_unlock_irqrestore (&dev
->mem_lock
, flags
);
784 // rxer->rate = make_rate (qos->peak_cells);
786 PRINTD (DBG_FLOW
, "hrz_open_rx ok");
792 /********** change vc rate for a given vc **********/
794 static void hrz_change_vc_qos (ATM_RXER
* rxer
, MAAL_QOS
* qos
) {
795 rxer
->rate
= make_rate (qos
->peak_cells
);
799 /********** free an skb (as per ATM device driver documentation) **********/
801 static void hrz_kfree_skb (struct sk_buff
* skb
) {
802 if (ATM_SKB(skb
)->vcc
->pop
) {
803 ATM_SKB(skb
)->vcc
->pop (ATM_SKB(skb
)->vcc
, skb
);
805 dev_kfree_skb_any (skb
);
809 /********** cancel listen on a VC **********/
811 static void hrz_close_rx (hrz_dev
* dev
, u16 vc
) {
818 rx_ch_desc
* rx_desc
= &memmap
->rx_descs
[vc
];
822 spin_lock_irqsave (&dev
->mem_lock
, flags
);
823 value
= rd_mem (dev
, &rx_desc
->wr_buf_type
) & BUFFER_PTR_MASK
;
824 spin_unlock_irqrestore (&dev
->mem_lock
, flags
);
826 if (value
== RX_CHANNEL_DISABLED
) {
827 // I suppose this could happen once we deal with _NONE traffic properly
828 PRINTD (DBG_VCC
, "closing VC: RX channel %u already disabled", vc
);
831 if (value
== RX_CHANNEL_IDLE
)
834 spin_lock_irqsave (&dev
->mem_lock
, flags
);
837 wr_mem (dev
, &rx_desc
->wr_buf_type
, RX_CHANNEL_DISABLED
);
839 if ((rd_mem (dev
, &rx_desc
->wr_buf_type
) & BUFFER_PTR_MASK
) == RX_CHANNEL_DISABLED
)
846 spin_unlock_irqrestore (&dev
->mem_lock
, flags
);
850 WAIT_FLUSH_RX_COMPLETE(dev
);
852 // XXX Is this all really necessary? We can rely on the rx_data_av
853 // handler to discard frames that remain queued for delivery. If the
854 // worry is that immediately reopening the channel (perhaps by a
855 // different process) may cause some data to be mis-delivered then
856 // there may still be a simpler solution (such as busy-waiting on
857 // rx_busy once the channel is disabled or before a new one is
858 // opened - does this leave any holes?). Arguably setting up and
859 // tearing down the TX and RX halves of each virtual circuit could
860 // most safely be done within ?x_busy protected regions.
862 // OK, current changes are that Simon's marker is disabled and we DO
863 // look for NULL rxer elsewhere. The code here seems flush frames
864 // and then remember the last dead cell belonging to the channel
865 // just disabled - the cell gets relinked at the next vc_open.
866 // However, when all VCs are closed or only a few opened there are a
867 // handful of buffers that are unusable.
869 // Does anyone feel like documenting spare_buffers properly?
870 // Does anyone feel like fixing this in a nicer way?
872 // Flush any data which is left in the channel
874 // Change the rx channel port to something different to the RX
875 // channel we are trying to close to force Horizon to flush the rx
876 // channel read and write pointers.
878 u16 other
= vc
^(RX_CHANS
/2);
880 SELECT_RX_CHANNEL (dev
, other
);
881 WAIT_UPDATE_COMPLETE (dev
);
883 r1
= rd_mem (dev
, &rx_desc
->rd_buf_type
);
885 // Select this RX channel. Flush doesn't seem to work unless we
886 // select an RX channel before hand
888 SELECT_RX_CHANNEL (dev
, vc
);
889 WAIT_UPDATE_COMPLETE (dev
);
891 // Attempt to flush a frame on this RX channel
893 FLUSH_RX_CHANNEL (dev
, vc
);
894 WAIT_FLUSH_RX_COMPLETE (dev
);
896 // Force Horizon to flush rx channel read and write pointers as before
898 SELECT_RX_CHANNEL (dev
, other
);
899 WAIT_UPDATE_COMPLETE (dev
);
901 r2
= rd_mem (dev
, &rx_desc
->rd_buf_type
);
903 PRINTD (DBG_VCC
|DBG_RX
, "r1 = %u, r2 = %u", r1
, r2
);
906 dev
->spare_buffers
[dev
->noof_spare_buffers
++] = (u16
)r1
;
913 rx_q_entry
* wr_ptr
= &memmap
->rx_q_entries
[rd_regw (dev
, RX_QUEUE_WR_PTR_OFF
)];
914 rx_q_entry
* rd_ptr
= dev
->rx_q_entry
;
916 PRINTD (DBG_VCC
|DBG_RX
, "rd_ptr = %u, wr_ptr = %u", rd_ptr
, wr_ptr
);
918 while (rd_ptr
!= wr_ptr
) {
919 u32 x
= rd_mem (dev
, (HDW
*) rd_ptr
);
921 if (vc
== rx_q_entry_to_rx_channel (x
)) {
922 x
|= SIMONS_DODGEY_MARKER
;
924 PRINTD (DBG_RX
|DBG_VCC
|DBG_WARN
, "marking a frame as dodgey");
926 wr_mem (dev
, (HDW
*) rd_ptr
, x
);
929 if (rd_ptr
== dev
->rx_q_wrap
)
930 rd_ptr
= dev
->rx_q_reset
;
937 spin_unlock_irqrestore (&dev
->mem_lock
, flags
);
942 /********** schedule RX transfers **********/
944 // Note on tail recursion: a GCC developer said that it is not likely
945 // to be fixed soon, so do not define TAILRECUSRIONWORKS unless you
946 // are sure it does as you may otherwise overflow the kernel stack.
948 // giving this fn a return value would help GCC, allegedly
950 static void rx_schedule (hrz_dev
* dev
, int irq
) {
951 unsigned int rx_bytes
;
954 #ifndef TAILRECURSIONWORKS
956 while (pio_instead
) {
958 // bytes waiting for RX transfer
959 rx_bytes
= dev
->rx_bytes
;
963 while (rd_regl (dev
, MASTER_RX_COUNT_REG_OFF
)) {
964 PRINTD (DBG_RX
|DBG_WARN
, "RX error: other PCI Bus Master RX still in progress!");
965 if (++spin_count
> 10) {
966 PRINTD (DBG_RX
|DBG_ERR
, "spun out waiting PCI Bus Master RX completion");
967 wr_regl (dev
, MASTER_RX_COUNT_REG_OFF
, 0);
968 clear_bit (rx_busy
, &dev
->flags
);
969 hrz_kfree_skb (dev
->rx_skb
);
975 // this code follows the TX code but (at the moment) there is only
976 // one region - the skb itself. I don't know if this will change,
977 // but it doesn't hurt to have the code here, disabled.
980 // start next transfer within same region
981 if (rx_bytes
<= MAX_PIO_COUNT
) {
982 PRINTD (DBG_RX
|DBG_BUS
, "(pio)");
985 if (rx_bytes
<= MAX_TRANSFER_COUNT
) {
986 PRINTD (DBG_RX
|DBG_BUS
, "(simple or last multi)");
989 PRINTD (DBG_RX
|DBG_BUS
, "(continuing multi)");
990 dev
->rx_bytes
= rx_bytes
- MAX_TRANSFER_COUNT
;
991 rx_bytes
= MAX_TRANSFER_COUNT
;
994 // rx_bytes == 0 -- we're between regions
995 // regions remaining to transfer
997 unsigned int rx_regions
= dev
->rx_regions
;
999 unsigned int rx_regions
= 0;
1004 // start a new region
1005 dev
->rx_addr
= dev
->rx_iovec
->iov_base
;
1006 rx_bytes
= dev
->rx_iovec
->iov_len
;
1008 dev
->rx_regions
= rx_regions
- 1;
1010 if (rx_bytes
<= MAX_PIO_COUNT
) {
1011 PRINTD (DBG_RX
|DBG_BUS
, "(pio)");
1014 if (rx_bytes
<= MAX_TRANSFER_COUNT
) {
1015 PRINTD (DBG_RX
|DBG_BUS
, "(full region)");
1018 PRINTD (DBG_RX
|DBG_BUS
, "(start multi region)");
1019 dev
->rx_bytes
= rx_bytes
- MAX_TRANSFER_COUNT
;
1020 rx_bytes
= MAX_TRANSFER_COUNT
;
1025 // that's all folks - end of frame
1026 struct sk_buff
* skb
= dev
->rx_skb
;
1027 // dev->rx_iovec = 0;
1029 FLUSH_RX_CHANNEL (dev
, dev
->rx_channel
);
1031 dump_skb ("<<<", dev
->rx_channel
, skb
);
1033 PRINTD (DBG_RX
|DBG_SKB
, "push %p %u", skb
->data
, skb
->len
);
1036 struct atm_vcc
* vcc
= ATM_SKB(skb
)->vcc
;
1038 atomic_inc(&vcc
->stats
->rx
);
1039 __net_timestamp(skb
);
1040 // end of our responsibility
1041 vcc
->push (vcc
, skb
);
1046 // note: writing RX_COUNT clears any interrupt condition
1050 wr_regl (dev
, MASTER_RX_COUNT_REG_OFF
, 0);
1051 rds_regb (dev
, DATA_PORT_OFF
, dev
->rx_addr
, rx_bytes
);
1053 wr_regl (dev
, MASTER_RX_ADDR_REG_OFF
, virt_to_bus (dev
->rx_addr
));
1054 wr_regl (dev
, MASTER_RX_COUNT_REG_OFF
, rx_bytes
);
1056 dev
->rx_addr
+= rx_bytes
;
1059 wr_regl (dev
, MASTER_RX_COUNT_REG_OFF
, 0);
1060 // allow another RX thread to start
1062 clear_bit (rx_busy
, &dev
->flags
);
1063 PRINTD (DBG_RX
, "cleared rx_busy for dev %p", dev
);
1066 #ifdef TAILRECURSIONWORKS
1067 // and we all bless optimised tail calls
1069 return rx_schedule (dev
, 0);
1079 /********** handle RX bus master complete events **********/
1081 static void rx_bus_master_complete_handler (hrz_dev
* dev
) {
1082 if (test_bit (rx_busy
, &dev
->flags
)) {
1083 rx_schedule (dev
, 1);
1085 PRINTD (DBG_RX
|DBG_ERR
, "unexpected RX bus master completion");
1086 // clear interrupt condition on adapter
1087 wr_regl (dev
, MASTER_RX_COUNT_REG_OFF
, 0);
1092 /********** (queue to) become the next TX thread **********/
1094 static int tx_hold (hrz_dev
* dev
) {
1095 PRINTD (DBG_TX
, "sleeping at tx lock %p %lu", dev
, dev
->flags
);
1096 wait_event_interruptible(dev
->tx_queue
, (!test_and_set_bit(tx_busy
, &dev
->flags
)));
1097 PRINTD (DBG_TX
, "woken at tx lock %p %lu", dev
, dev
->flags
);
1098 if (signal_pending (current
))
1100 PRINTD (DBG_TX
, "set tx_busy for dev %p", dev
);
1104 /********** allow another TX thread to start **********/
1106 static inline void tx_release (hrz_dev
* dev
) {
1107 clear_bit (tx_busy
, &dev
->flags
);
1108 PRINTD (DBG_TX
, "cleared tx_busy for dev %p", dev
);
1109 wake_up_interruptible (&dev
->tx_queue
);
1112 /********** schedule TX transfers **********/
1114 static void tx_schedule (hrz_dev
* const dev
, int irq
) {
1115 unsigned int tx_bytes
;
1117 int append_desc
= 0;
1119 int pio_instead
= 0;
1120 #ifndef TAILRECURSIONWORKS
1122 while (pio_instead
) {
1124 // bytes in current region waiting for TX transfer
1125 tx_bytes
= dev
->tx_bytes
;
1129 while (rd_regl (dev
, MASTER_TX_COUNT_REG_OFF
)) {
1130 PRINTD (DBG_TX
|DBG_WARN
, "TX error: other PCI Bus Master TX still in progress!");
1131 if (++spin_count
> 10) {
1132 PRINTD (DBG_TX
|DBG_ERR
, "spun out waiting PCI Bus Master TX completion");
1133 wr_regl (dev
, MASTER_TX_COUNT_REG_OFF
, 0);
1135 hrz_kfree_skb (dev
->tx_skb
);
1142 // start next transfer within same region
1143 if (!test_bit (ultra
, &dev
->flags
) || tx_bytes
<= MAX_PIO_COUNT
) {
1144 PRINTD (DBG_TX
|DBG_BUS
, "(pio)");
1147 if (tx_bytes
<= MAX_TRANSFER_COUNT
) {
1148 PRINTD (DBG_TX
|DBG_BUS
, "(simple or last multi)");
1149 if (!dev
->tx_iovec
) {
1150 // end of last region
1155 PRINTD (DBG_TX
|DBG_BUS
, "(continuing multi)");
1156 dev
->tx_bytes
= tx_bytes
- MAX_TRANSFER_COUNT
;
1157 tx_bytes
= MAX_TRANSFER_COUNT
;
1160 // tx_bytes == 0 -- we're between regions
1161 // regions remaining to transfer
1162 unsigned int tx_regions
= dev
->tx_regions
;
1165 // start a new region
1166 dev
->tx_addr
= dev
->tx_iovec
->iov_base
;
1167 tx_bytes
= dev
->tx_iovec
->iov_len
;
1169 dev
->tx_regions
= tx_regions
- 1;
1171 if (!test_bit (ultra
, &dev
->flags
) || tx_bytes
<= MAX_PIO_COUNT
) {
1172 PRINTD (DBG_TX
|DBG_BUS
, "(pio)");
1175 if (tx_bytes
<= MAX_TRANSFER_COUNT
) {
1176 PRINTD (DBG_TX
|DBG_BUS
, "(full region)");
1179 PRINTD (DBG_TX
|DBG_BUS
, "(start multi region)");
1180 dev
->tx_bytes
= tx_bytes
- MAX_TRANSFER_COUNT
;
1181 tx_bytes
= MAX_TRANSFER_COUNT
;
1185 // that's all folks - end of frame
1186 struct sk_buff
* skb
= dev
->tx_skb
;
1187 dev
->tx_iovec
= NULL
;
1190 atomic_inc(&ATM_SKB(skb
)->vcc
->stats
->tx
);
1193 hrz_kfree_skb (skb
);
1197 // note: writing TX_COUNT clears any interrupt condition
1201 wr_regl (dev
, MASTER_TX_COUNT_REG_OFF
, 0);
1202 wrs_regb (dev
, DATA_PORT_OFF
, dev
->tx_addr
, tx_bytes
);
1204 wr_regl (dev
, TX_DESCRIPTOR_PORT_OFF
, cpu_to_be32 (dev
->tx_skb
->len
));
1206 wr_regl (dev
, MASTER_TX_ADDR_REG_OFF
, virt_to_bus (dev
->tx_addr
));
1208 wr_regl (dev
, TX_DESCRIPTOR_REG_OFF
, cpu_to_be32 (dev
->tx_skb
->len
));
1209 wr_regl (dev
, MASTER_TX_COUNT_REG_OFF
,
1211 ? tx_bytes
| MASTER_TX_AUTO_APPEND_DESC
1214 dev
->tx_addr
+= tx_bytes
;
1217 wr_regl (dev
, MASTER_TX_COUNT_REG_OFF
, 0);
1222 #ifdef TAILRECURSIONWORKS
1223 // and we all bless optimised tail calls
1225 return tx_schedule (dev
, 0);
1235 /********** handle TX bus master complete events **********/
1237 static void tx_bus_master_complete_handler (hrz_dev
* dev
) {
1238 if (test_bit (tx_busy
, &dev
->flags
)) {
1239 tx_schedule (dev
, 1);
1241 PRINTD (DBG_TX
|DBG_ERR
, "unexpected TX bus master completion");
1242 // clear interrupt condition on adapter
1243 wr_regl (dev
, MASTER_TX_COUNT_REG_OFF
, 0);
1248 /********** move RX Q pointer to next item in circular buffer **********/
1250 // called only from IRQ sub-handler
1251 static u32
rx_queue_entry_next (hrz_dev
* dev
) {
1253 spin_lock (&dev
->mem_lock
);
1254 rx_queue_entry
= rd_mem (dev
, &dev
->rx_q_entry
->entry
);
1255 if (dev
->rx_q_entry
== dev
->rx_q_wrap
)
1256 dev
->rx_q_entry
= dev
->rx_q_reset
;
1259 wr_regw (dev
, RX_QUEUE_RD_PTR_OFF
, dev
->rx_q_entry
- dev
->rx_q_reset
);
1260 spin_unlock (&dev
->mem_lock
);
1261 return rx_queue_entry
;
1264 /********** handle RX disabled by device **********/
1266 static inline void rx_disabled_handler (hrz_dev
* dev
) {
1267 wr_regw (dev
, RX_CONFIG_OFF
, rd_regw (dev
, RX_CONFIG_OFF
) | RX_ENABLE
);
1269 PRINTK (KERN_WARNING
, "RX was disabled!");
1272 /********** handle RX data received by device **********/
1274 // called from IRQ handler
1275 static void rx_data_av_handler (hrz_dev
* dev
) {
1277 u32 rx_queue_entry_flags
;
1281 PRINTD (DBG_FLOW
, "hrz_data_av_handler");
1283 // try to grab rx lock (not possible during RX bus mastering)
1284 if (test_and_set_bit (rx_busy
, &dev
->flags
)) {
1285 PRINTD (DBG_RX
, "locked out of rx lock");
1288 PRINTD (DBG_RX
, "set rx_busy for dev %p", dev
);
1289 // lock is cleared if we fail now, o/w after bus master completion
1291 YELLOW_LED_OFF(dev
);
1293 rx_queue_entry
= rx_queue_entry_next (dev
);
1295 rx_len
= rx_q_entry_to_length (rx_queue_entry
);
1296 rx_channel
= rx_q_entry_to_rx_channel (rx_queue_entry
);
1298 WAIT_FLUSH_RX_COMPLETE (dev
);
1300 SELECT_RX_CHANNEL (dev
, rx_channel
);
1302 PRINTD (DBG_RX
, "rx_queue_entry is: %#x", rx_queue_entry
);
1303 rx_queue_entry_flags
= rx_queue_entry
& (RX_CRC_32_OK
|RX_COMPLETE_FRAME
|SIMONS_DODGEY_MARKER
);
1306 // (at least) bus-mastering breaks if we try to handle a
1307 // zero-length frame, besides AAL5 does not support them
1308 PRINTK (KERN_ERR
, "zero-length frame!");
1309 rx_queue_entry_flags
&= ~RX_COMPLETE_FRAME
;
1312 if (rx_queue_entry_flags
& SIMONS_DODGEY_MARKER
) {
1313 PRINTD (DBG_RX
|DBG_ERR
, "Simon's marker detected!");
1315 if (rx_queue_entry_flags
== (RX_CRC_32_OK
| RX_COMPLETE_FRAME
)) {
1316 struct atm_vcc
* atm_vcc
;
1318 PRINTD (DBG_RX
, "got a frame on rx_channel %x len %u", rx_channel
, rx_len
);
1320 atm_vcc
= dev
->rxer
[rx_channel
];
1321 // if no vcc is assigned to this channel, we should drop the frame
1322 // (is this what SIMONS etc. was trying to achieve?)
1326 if (atm_vcc
->qos
.rxtp
.traffic_class
!= ATM_NONE
) {
1328 if (rx_len
<= atm_vcc
->qos
.rxtp
.max_sdu
) {
1330 struct sk_buff
* skb
= atm_alloc_charge (atm_vcc
, rx_len
, GFP_ATOMIC
);
1332 // remember this so we can push it later
1334 // remember this so we can flush it later
1335 dev
->rx_channel
= rx_channel
;
1337 // prepare socket buffer
1338 skb_put (skb
, rx_len
);
1339 ATM_SKB(skb
)->vcc
= atm_vcc
;
1342 // dev->rx_regions = 0;
1343 // dev->rx_iovec = 0;
1344 dev
->rx_bytes
= rx_len
;
1345 dev
->rx_addr
= skb
->data
;
1346 PRINTD (DBG_RX
, "RX start simple transfer (addr %p, len %d)",
1350 rx_schedule (dev
, 0);
1354 PRINTD (DBG_SKB
|DBG_WARN
, "failed to get skb");
1358 PRINTK (KERN_INFO
, "frame received on TX-only VC %x", rx_channel
);
1359 // do we count this?
1363 PRINTK (KERN_WARNING
, "dropped over-size frame");
1364 // do we count this?
1368 PRINTD (DBG_WARN
|DBG_VCC
|DBG_RX
, "no VCC for this frame (VC closed)");
1369 // do we count this?
1373 // Wait update complete ? SPONG
1379 FLUSH_RX_CHANNEL (dev
,rx_channel
);
1380 clear_bit (rx_busy
, &dev
->flags
);
1385 /********** interrupt handler **********/
1387 static irqreturn_t
interrupt_handler(int irq
, void *dev_id
)
1389 hrz_dev
*dev
= dev_id
;
1391 unsigned int irq_ok
;
1393 PRINTD (DBG_FLOW
, "interrupt_handler: %p", dev_id
);
1395 // definitely for us
1397 while ((int_source
= rd_regl (dev
, INT_SOURCE_REG_OFF
)
1398 & INTERESTING_INTERRUPTS
)) {
1399 // In the interests of fairness, the handlers below are
1400 // called in sequence and without immediate return to the head of
1401 // the while loop. This is only of issue for slow hosts (or when
1402 // debugging messages are on). Really slow hosts may find a fast
1403 // sender keeps them permanently in the IRQ handler. :(
1405 // (only an issue for slow hosts) RX completion goes before
1406 // rx_data_av as the former implies rx_busy and so the latter
1407 // would just abort. If it reschedules another transfer
1408 // (continuing the same frame) then it will not clear rx_busy.
1410 // (only an issue for slow hosts) TX completion goes before RX
1411 // data available as it is a much shorter routine - there is the
1412 // chance that any further transfers it schedules will be complete
1413 // by the time of the return to the head of the while loop
1415 if (int_source
& RX_BUS_MASTER_COMPLETE
) {
1417 PRINTD (DBG_IRQ
|DBG_BUS
|DBG_RX
, "rx_bus_master_complete asserted");
1418 rx_bus_master_complete_handler (dev
);
1420 if (int_source
& TX_BUS_MASTER_COMPLETE
) {
1422 PRINTD (DBG_IRQ
|DBG_BUS
|DBG_TX
, "tx_bus_master_complete asserted");
1423 tx_bus_master_complete_handler (dev
);
1425 if (int_source
& RX_DATA_AV
) {
1427 PRINTD (DBG_IRQ
|DBG_RX
, "rx_data_av asserted");
1428 rx_data_av_handler (dev
);
1432 PRINTD (DBG_IRQ
, "work done: %u", irq_ok
);
1434 PRINTD (DBG_IRQ
|DBG_WARN
, "spurious interrupt source: %#x", int_source
);
1437 PRINTD (DBG_IRQ
|DBG_FLOW
, "interrupt_handler done: %p", dev_id
);
1443 /********** housekeeping **********/
1445 static void do_housekeeping (unsigned long arg
) {
1446 // just stats at the moment
1447 hrz_dev
* dev
= (hrz_dev
*) arg
;
1449 // collect device-specific (not driver/atm-linux) stats here
1450 dev
->tx_cell_count
+= rd_regw (dev
, TX_CELL_COUNT_OFF
);
1451 dev
->rx_cell_count
+= rd_regw (dev
, RX_CELL_COUNT_OFF
);
1452 dev
->hec_error_count
+= rd_regw (dev
, HEC_ERROR_COUNT_OFF
);
1453 dev
->unassigned_cell_count
+= rd_regw (dev
, UNASSIGNED_CELL_COUNT_OFF
);
1455 mod_timer (&dev
->housekeeping
, jiffies
+ HZ
/10);
1460 /********** find an idle channel for TX and set it up **********/
1462 // called with tx_busy set
1463 static short setup_idle_tx_channel (hrz_dev
* dev
, hrz_vcc
* vcc
) {
1464 unsigned short idle_channels
;
1465 short tx_channel
= -1;
1466 unsigned int spin_count
;
1467 PRINTD (DBG_FLOW
|DBG_TX
, "setup_idle_tx_channel %p", dev
);
1469 // better would be to fail immediately, the caller can then decide whether
1470 // to wait or drop (depending on whether this is UBR etc.)
1472 while (!(idle_channels
= rd_regw (dev
, TX_STATUS_OFF
) & IDLE_CHANNELS_MASK
)) {
1473 PRINTD (DBG_TX
|DBG_WARN
, "waiting for idle TX channel");
1475 if (++spin_count
> 100) {
1476 PRINTD (DBG_TX
|DBG_ERR
, "spun out waiting for idle TX channel");
1481 // got an idle channel
1483 // tx_idle ensures we look for idle channels in RR order
1484 int chan
= dev
->tx_idle
;
1487 while (keep_going
) {
1488 if (idle_channels
& (1<<chan
)) {
1493 if (chan
== TX_CHANS
)
1497 dev
->tx_idle
= chan
;
1500 // set up the channel we found
1502 // Initialise the cell header in the transmit channel descriptor
1503 // a.k.a. prepare the channel and remember that we have done so.
1505 tx_ch_desc
* tx_desc
= &memmap
->tx_descs
[tx_channel
];
1508 u16 channel
= vcc
->channel
;
1510 unsigned long flags
;
1511 spin_lock_irqsave (&dev
->mem_lock
, flags
);
1513 // Update the transmit channel record.
1514 dev
->tx_channel_record
[tx_channel
] = channel
;
1517 update_tx_channel_config (dev
, tx_channel
, RATE_TYPE_ACCESS
,
1520 // Update the PCR counter preload value etc.
1521 update_tx_channel_config (dev
, tx_channel
, PCR_TIMER_ACCESS
,
1525 if (vcc
->tx_xbr_bits
== VBR_RATE_TYPE
) {
1527 update_tx_channel_config (dev
, tx_channel
, SCR_TIMER_ACCESS
,
1531 update_tx_channel_config (dev
, tx_channel
, BUCKET_CAPACITY_ACCESS
,
1532 vcc
->tx_bucket_bits
);
1535 update_tx_channel_config (dev
, tx_channel
, BUCKET_FULLNESS_ACCESS
,
1536 vcc
->tx_bucket_bits
);
1540 // Initialise the read and write buffer pointers
1541 rd_ptr
= rd_mem (dev
, &tx_desc
->rd_buf_type
) & BUFFER_PTR_MASK
;
1542 wr_ptr
= rd_mem (dev
, &tx_desc
->wr_buf_type
) & BUFFER_PTR_MASK
;
1544 // idle TX channels should have identical pointers
1545 if (rd_ptr
!= wr_ptr
) {
1546 PRINTD (DBG_TX
|DBG_ERR
, "TX buffer pointers are broken!");
1547 // spin_unlock... return -E...
1548 // I wonder if gcc would get rid of one of the pointer aliases
1550 PRINTD (DBG_TX
, "TX buffer pointers are: rd %x, wr %x.",
1555 PRINTD (DBG_QOS
|DBG_TX
, "tx_channel: aal0");
1556 rd_ptr
|= CHANNEL_TYPE_RAW_CELLS
;
1557 wr_ptr
|= CHANNEL_TYPE_RAW_CELLS
;
1560 PRINTD (DBG_QOS
|DBG_TX
, "tx_channel: aal34");
1561 rd_ptr
|= CHANNEL_TYPE_AAL3_4
;
1562 wr_ptr
|= CHANNEL_TYPE_AAL3_4
;
1565 rd_ptr
|= CHANNEL_TYPE_AAL5
;
1566 wr_ptr
|= CHANNEL_TYPE_AAL5
;
1567 // Initialise the CRC
1568 wr_mem (dev
, &tx_desc
->partial_crc
, INITIAL_CRC
);
1572 wr_mem (dev
, &tx_desc
->rd_buf_type
, rd_ptr
);
1573 wr_mem (dev
, &tx_desc
->wr_buf_type
, wr_ptr
);
1575 // Write the Cell Header
1576 // Payload Type, CLP and GFC would go here if non-zero
1577 wr_mem (dev
, &tx_desc
->cell_header
, channel
);
1579 spin_unlock_irqrestore (&dev
->mem_lock
, flags
);
1585 /********** send a frame **********/
1587 static int hrz_send (struct atm_vcc
* atm_vcc
, struct sk_buff
* skb
) {
1588 unsigned int spin_count
;
1590 hrz_dev
* dev
= HRZ_DEV(atm_vcc
->dev
);
1591 hrz_vcc
* vcc
= HRZ_VCC(atm_vcc
);
1592 u16 channel
= vcc
->channel
;
1594 u32 buffers_required
;
1596 /* signed for error return */
1599 PRINTD (DBG_FLOW
|DBG_TX
, "hrz_send vc %x data %p len %u",
1600 channel
, skb
->data
, skb
->len
);
1602 dump_skb (">>>", channel
, skb
);
1604 if (atm_vcc
->qos
.txtp
.traffic_class
== ATM_NONE
) {
1605 PRINTK (KERN_ERR
, "attempt to send on RX-only VC %x", channel
);
1606 hrz_kfree_skb (skb
);
1610 // don't understand this
1611 ATM_SKB(skb
)->vcc
= atm_vcc
;
1613 if (skb
->len
> atm_vcc
->qos
.txtp
.max_sdu
) {
1614 PRINTK (KERN_ERR
, "sk_buff length greater than agreed max_sdu, dropping...");
1615 hrz_kfree_skb (skb
);
1620 PRINTD (DBG_ERR
|DBG_TX
, "attempt to transmit on zero (rx_)channel");
1621 hrz_kfree_skb (skb
);
1627 // where would be a better place for this? housekeeping?
1629 pci_read_config_word (dev
->pci_dev
, PCI_STATUS
, &status
);
1630 if (status
& PCI_STATUS_REC_MASTER_ABORT
) {
1631 PRINTD (DBG_BUS
|DBG_ERR
, "Clearing PCI Master Abort (and cleaning up)");
1632 status
&= ~PCI_STATUS_REC_MASTER_ABORT
;
1633 pci_write_config_word (dev
->pci_dev
, PCI_STATUS
, status
);
1634 if (test_bit (tx_busy
, &dev
->flags
)) {
1635 hrz_kfree_skb (dev
->tx_skb
);
1642 #ifdef DEBUG_HORIZON
1644 if (channel
== 1023) {
1646 unsigned short d
= 0;
1647 char * s
= skb
->data
;
1649 for (i
= 0; i
< 4; ++i
)
1650 d
= (d
<< 4) | hex_to_bin(*s
++);
1651 PRINTK (KERN_INFO
, "debug bitmap is now %hx", debug
= d
);
1656 // wait until TX is free and grab lock
1657 if (tx_hold (dev
)) {
1658 hrz_kfree_skb (skb
);
1659 return -ERESTARTSYS
;
1662 // Wait for enough space to be available in transmit buffer memory.
1664 // should be number of cells needed + 2 (according to hardware docs)
1665 // = ((framelen+8)+47) / 48 + 2
1666 // = (framelen+7) / 48 + 3, hmm... faster to put addition inside XXX
1667 buffers_required
= (skb
->len
+(ATM_AAL5_TRAILER
-1)) / ATM_CELL_PAYLOAD
+ 3;
1669 // replace with timer and sleep, add dev->tx_buffers_queue (max 1 entry)
1671 while ((free_buffers
= rd_regw (dev
, TX_FREE_BUFFER_COUNT_OFF
)) < buffers_required
) {
1672 PRINTD (DBG_TX
, "waiting for free TX buffers, got %d of %d",
1673 free_buffers
, buffers_required
);
1674 // what is the appropriate delay? implement a timeout? (depending on line speed?)
1676 // what happens if we kill (current_pid, SIGKILL) ?
1678 if (++spin_count
> 1000) {
1679 PRINTD (DBG_TX
|DBG_ERR
, "spun out waiting for tx buffers, got %d of %d",
1680 free_buffers
, buffers_required
);
1682 hrz_kfree_skb (skb
);
1683 return -ERESTARTSYS
;
1687 // Select a channel to transmit the frame on.
1688 if (channel
== dev
->last_vc
) {
1689 PRINTD (DBG_TX
, "last vc hack: hit");
1690 tx_channel
= dev
->tx_last
;
1692 PRINTD (DBG_TX
, "last vc hack: miss");
1693 // Are we currently transmitting this VC on one of the channels?
1694 for (tx_channel
= 0; tx_channel
< TX_CHANS
; ++tx_channel
)
1695 if (dev
->tx_channel_record
[tx_channel
] == channel
) {
1696 PRINTD (DBG_TX
, "vc already on channel: hit");
1699 if (tx_channel
== TX_CHANS
) {
1700 PRINTD (DBG_TX
, "vc already on channel: miss");
1701 // Find and set up an idle channel.
1702 tx_channel
= setup_idle_tx_channel (dev
, vcc
);
1703 if (tx_channel
< 0) {
1704 PRINTD (DBG_TX
|DBG_ERR
, "failed to get channel");
1710 PRINTD (DBG_TX
, "got channel");
1711 SELECT_TX_CHANNEL(dev
, tx_channel
);
1713 dev
->last_vc
= channel
;
1714 dev
->tx_last
= tx_channel
;
1717 PRINTD (DBG_TX
, "using channel %u", tx_channel
);
1719 YELLOW_LED_OFF(dev
);
1721 // TX start transfer
1724 unsigned int tx_len
= skb
->len
;
1725 unsigned int tx_iovcnt
= skb_shinfo(skb
)->nr_frags
;
1726 // remember this so we can free it later
1730 // scatter gather transfer
1731 dev
->tx_regions
= tx_iovcnt
;
1732 dev
->tx_iovec
= NULL
; /* @@@ needs rewritten */
1734 PRINTD (DBG_TX
|DBG_BUS
, "TX start scatter-gather transfer (iovec %p, len %d)",
1737 hrz_kfree_skb (skb
);
1741 dev
->tx_regions
= 0;
1742 dev
->tx_iovec
= NULL
;
1743 dev
->tx_bytes
= tx_len
;
1744 dev
->tx_addr
= skb
->data
;
1745 PRINTD (DBG_TX
|DBG_BUS
, "TX start simple transfer (addr %p, len %d)",
1749 // and do the business
1750 tx_schedule (dev
, 0);
1757 /********** reset a card **********/
1759 static void hrz_reset (const hrz_dev
* dev
) {
1760 u32 control_0_reg
= rd_regl (dev
, CONTROL_0_REG
);
1762 // why not set RESET_HORIZON to one and wait for the card to
1763 // reassert that bit as zero? Like so:
1764 control_0_reg
= control_0_reg
& RESET_HORIZON
;
1765 wr_regl (dev
, CONTROL_0_REG
, control_0_reg
);
1766 while (control_0_reg
& RESET_HORIZON
)
1767 control_0_reg
= rd_regl (dev
, CONTROL_0_REG
);
1769 // old reset code retained:
1770 wr_regl (dev
, CONTROL_0_REG
, control_0_reg
|
1771 RESET_ATM
| RESET_RX
| RESET_TX
| RESET_HOST
);
1772 // just guessing here
1775 wr_regl (dev
, CONTROL_0_REG
, control_0_reg
);
1778 /********** read the burnt in address **********/
1780 static void WRITE_IT_WAIT (const hrz_dev
*dev
, u32 ctrl
)
1782 wr_regl (dev
, CONTROL_0_REG
, ctrl
);
1786 static void CLOCK_IT (const hrz_dev
*dev
, u32 ctrl
)
1788 // DI must be valid around rising SK edge
1789 WRITE_IT_WAIT(dev
, ctrl
& ~SEEPROM_SK
);
1790 WRITE_IT_WAIT(dev
, ctrl
| SEEPROM_SK
);
1793 static u16 __devinit
read_bia (const hrz_dev
* dev
, u16 addr
)
1795 u32 ctrl
= rd_regl (dev
, CONTROL_0_REG
);
1797 const unsigned int addr_bits
= 6;
1798 const unsigned int data_bits
= 16;
1804 ctrl
&= ~(SEEPROM_CS
| SEEPROM_SK
| SEEPROM_DI
);
1805 WRITE_IT_WAIT(dev
, ctrl
);
1807 // wake Serial EEPROM and send 110 (READ) command
1808 ctrl
|= (SEEPROM_CS
| SEEPROM_DI
);
1809 CLOCK_IT(dev
, ctrl
);
1812 CLOCK_IT(dev
, ctrl
);
1814 ctrl
&= ~SEEPROM_DI
;
1815 CLOCK_IT(dev
, ctrl
);
1817 for (i
=0; i
<addr_bits
; i
++) {
1818 if (addr
& (1 << (addr_bits
-1)))
1821 ctrl
&= ~SEEPROM_DI
;
1823 CLOCK_IT(dev
, ctrl
);
1828 // we could check that we have DO = 0 here
1829 ctrl
&= ~SEEPROM_DI
;
1832 for (i
=0;i
<data_bits
;i
++) {
1835 CLOCK_IT(dev
, ctrl
);
1837 if (rd_regl (dev
, CONTROL_0_REG
) & SEEPROM_DO
)
1838 res
|= (1 << (data_bits
-1));
1841 ctrl
&= ~(SEEPROM_SK
| SEEPROM_CS
);
1842 WRITE_IT_WAIT(dev
, ctrl
);
1847 /********** initialise a card **********/
1849 static int __devinit
hrz_init (hrz_dev
* dev
) {
1863 ctrl
= rd_regl (dev
, CONTROL_0_REG
);
1864 PRINTD (DBG_INFO
, "ctrl0reg is %#x", ctrl
);
1865 onefivefive
= ctrl
& ATM_LAYER_STATUS
;
1868 printk (DEV_LABEL
": Horizon Ultra (at 155.52 MBps)");
1870 printk (DEV_LABEL
": Horizon (at 25 MBps)");
1873 // Reset the card to get everything in a known state
1878 // Clear all the buffer memory
1880 printk (" clearing memory");
1882 for (mem
= (HDW
*) memmap
; mem
< (HDW
*) (memmap
+ 1); ++mem
)
1883 wr_mem (dev
, mem
, 0);
1885 printk (" tx channels");
1887 // All transmit eight channels are set up as AAL5 ABR channels with
1888 // a 16us cell spacing. Why?
1890 // Channel 0 gets the free buffer at 100h, channel 1 gets the free
1891 // buffer at 110h etc.
1893 for (chan
= 0; chan
< TX_CHANS
; ++chan
) {
1894 tx_ch_desc
* tx_desc
= &memmap
->tx_descs
[chan
];
1895 cell_buf
* buf
= &memmap
->inittxbufs
[chan
];
1897 // initialise the read and write buffer pointers
1898 wr_mem (dev
, &tx_desc
->rd_buf_type
, BUF_PTR(buf
));
1899 wr_mem (dev
, &tx_desc
->wr_buf_type
, BUF_PTR(buf
));
1901 // set the status of the initial buffers to empty
1902 wr_mem (dev
, &buf
->next
, BUFF_STATUS_EMPTY
);
1905 // Use space bufn3 at the moment for tx buffers
1907 printk (" tx buffers");
1909 tx_desc
= memmap
->bufn3
;
1911 wr_mem (dev
, &memmap
->txfreebufstart
.next
, BUF_PTR(tx_desc
) | BUFF_STATUS_EMPTY
);
1913 for (buff_count
= 0; buff_count
< BUFN3_SIZE
-1; buff_count
++) {
1914 wr_mem (dev
, &tx_desc
->next
, BUF_PTR(tx_desc
+1) | BUFF_STATUS_EMPTY
);
1918 wr_mem (dev
, &tx_desc
->next
, BUF_PTR(&memmap
->txfreebufend
) | BUFF_STATUS_EMPTY
);
1920 // Initialise the transmit free buffer count
1921 wr_regw (dev
, TX_FREE_BUFFER_COUNT_OFF
, BUFN3_SIZE
);
1923 printk (" rx channels");
1925 // Initialise all of the receive channels to be AAL5 disabled with
1926 // an interrupt threshold of 0
1928 for (chan
= 0; chan
< RX_CHANS
; ++chan
) {
1929 rx_ch_desc
* rx_desc
= &memmap
->rx_descs
[chan
];
1931 wr_mem (dev
, &rx_desc
->wr_buf_type
, CHANNEL_TYPE_AAL5
| RX_CHANNEL_DISABLED
);
1934 printk (" rx buffers");
1936 // Use space bufn4 at the moment for rx buffers
1938 rx_desc
= memmap
->bufn4
;
1940 wr_mem (dev
, &memmap
->rxfreebufstart
.next
, BUF_PTR(rx_desc
) | BUFF_STATUS_EMPTY
);
1942 for (buff_count
= 0; buff_count
< BUFN4_SIZE
-1; buff_count
++) {
1943 wr_mem (dev
, &rx_desc
->next
, BUF_PTR(rx_desc
+1) | BUFF_STATUS_EMPTY
);
1948 wr_mem (dev
, &rx_desc
->next
, BUF_PTR(&memmap
->rxfreebufend
) | BUFF_STATUS_EMPTY
);
1950 // Initialise the receive free buffer count
1951 wr_regw (dev
, RX_FREE_BUFFER_COUNT_OFF
, BUFN4_SIZE
);
1953 // Initialize Horizons registers
1956 wr_regw (dev
, TX_CONFIG_OFF
,
1957 ABR_ROUND_ROBIN
| TX_NORMAL_OPERATION
| DRVR_DRVRBAR_ENABLE
);
1959 // RX config. Use 10-x VC bits, x VP bits, non user cells in channel 0.
1960 wr_regw (dev
, RX_CONFIG_OFF
,
1961 DISCARD_UNUSED_VPI_VCI_BITS_SET
| NON_USER_CELLS_IN_ONE_CHANNEL
| vpi_bits
);
1964 wr_regw (dev
, RX_LINE_CONFIG_OFF
,
1965 LOCK_DETECT_ENABLE
| FREQUENCY_DETECT_ENABLE
| GXTALOUT_SELECT_DIV4
);
1967 // Set the max AAL5 cell count to be just enough to contain the
1968 // largest AAL5 frame that the user wants to receive
1969 wr_regw (dev
, MAX_AAL5_CELL_COUNT_OFF
,
1970 DIV_ROUND_UP(max_rx_size
+ ATM_AAL5_TRAILER
, ATM_CELL_PAYLOAD
));
1973 wr_regw (dev
, RX_CONFIG_OFF
, rd_regw (dev
, RX_CONFIG_OFF
) | RX_ENABLE
);
1975 printk (" control");
1977 // Drive the OE of the LEDs then turn the green LED on
1978 ctrl
|= GREEN_LED_OE
| YELLOW_LED_OE
| GREEN_LED
| YELLOW_LED
;
1979 wr_regl (dev
, CONTROL_0_REG
, ctrl
);
1981 // Test for a 155-capable card
1984 // Select 155 mode... make this a choice (or: how do we detect
1985 // external line speed and switch?)
1986 ctrl
|= ATM_LAYER_SELECT
;
1987 wr_regl (dev
, CONTROL_0_REG
, ctrl
);
1989 // test SUNI-lite vs SAMBA
1991 // Register 0x00 in the SUNI will have some of bits 3-7 set, and
1992 // they will always be zero for the SAMBA. Ha! Bloody hardware
1993 // engineers. It'll never work.
1995 if (rd_framer (dev
, 0) & 0x00f0) {
1999 // Reset, just in case
2000 wr_framer (dev
, 0x00, 0x0080);
2001 wr_framer (dev
, 0x00, 0x0000);
2003 // Configure transmit FIFO
2004 wr_framer (dev
, 0x63, rd_framer (dev
, 0x63) | 0x0002);
2006 // Set line timed mode
2007 wr_framer (dev
, 0x05, rd_framer (dev
, 0x05) | 0x0001);
2012 // Reset, just in case
2013 wr_framer (dev
, 0, rd_framer (dev
, 0) | 0x0001);
2014 wr_framer (dev
, 0, rd_framer (dev
, 0) &~ 0x0001);
2016 // Turn off diagnostic loopback and enable line-timed mode
2017 wr_framer (dev
, 0, 0x0002);
2019 // Turn on transmit outputs
2020 wr_framer (dev
, 2, 0x0B80);
2024 ctrl
&= ~ATM_LAYER_SELECT
;
2040 u8
* esi
= dev
->atm_dev
->esi
;
2042 // in the card I have, EEPROM
2043 // addresses 0, 1, 2 contain 0
2044 // addresess 5, 6 etc. contain ffff
2045 // NB: Madge prefix is 00 00 f6 (which is 00 00 6f in Ethernet bit order)
2046 // the read_bia routine gets the BIA in Ethernet bit order
2048 for (i
=0; i
< ESI_LEN
; ++i
) {
2050 b
= read_bia (dev
, i
/2 + 2);
2054 printk ("%02x", esi
[i
]);
2058 // Enable RX_Q and ?X_COMPLETE interrupts only
2059 wr_regl (dev
, INT_ENABLE_REG_OFF
, INTERESTING_INTERRUPTS
);
2067 /********** check max_sdu **********/
2069 static int check_max_sdu (hrz_aal aal
, struct atm_trafprm
* tp
, unsigned int max_frame_size
) {
2070 PRINTD (DBG_FLOW
|DBG_QOS
, "check_max_sdu");
2074 if (!(tp
->max_sdu
)) {
2075 PRINTD (DBG_QOS
, "defaulting max_sdu");
2076 tp
->max_sdu
= ATM_AAL0_SDU
;
2077 } else if (tp
->max_sdu
!= ATM_AAL0_SDU
) {
2078 PRINTD (DBG_QOS
|DBG_ERR
, "rejecting max_sdu");
2083 if (tp
->max_sdu
== 0 || tp
->max_sdu
> ATM_MAX_AAL34_PDU
) {
2084 PRINTD (DBG_QOS
, "%sing max_sdu", tp
->max_sdu
? "capp" : "default");
2085 tp
->max_sdu
= ATM_MAX_AAL34_PDU
;
2089 if (tp
->max_sdu
== 0 || tp
->max_sdu
> max_frame_size
) {
2090 PRINTD (DBG_QOS
, "%sing max_sdu", tp
->max_sdu
? "capp" : "default");
2091 tp
->max_sdu
= max_frame_size
;
2098 /********** check pcr **********/
2100 // something like this should be part of ATM Linux
2101 static int atm_pcr_check (struct atm_trafprm
* tp
, unsigned int pcr
) {
2102 // we are assuming non-UBR, and non-special values of pcr
2103 if (tp
->min_pcr
== ATM_MAX_PCR
)
2104 PRINTD (DBG_QOS
, "luser gave min_pcr = ATM_MAX_PCR");
2105 else if (tp
->min_pcr
< 0)
2106 PRINTD (DBG_QOS
, "luser gave negative min_pcr");
2107 else if (tp
->min_pcr
&& tp
->min_pcr
> pcr
)
2108 PRINTD (DBG_QOS
, "pcr less than min_pcr");
2110 // !! max_pcr = UNSPEC (0) is equivalent to max_pcr = MAX (-1)
2111 // easier to #define ATM_MAX_PCR 0 and have all rates unsigned?
2112 // [this would get rid of next two conditionals]
2113 if ((0) && tp
->max_pcr
== ATM_MAX_PCR
)
2114 PRINTD (DBG_QOS
, "luser gave max_pcr = ATM_MAX_PCR");
2115 else if ((tp
->max_pcr
!= ATM_MAX_PCR
) && tp
->max_pcr
< 0)
2116 PRINTD (DBG_QOS
, "luser gave negative max_pcr");
2117 else if (tp
->max_pcr
&& tp
->max_pcr
!= ATM_MAX_PCR
&& tp
->max_pcr
< pcr
)
2118 PRINTD (DBG_QOS
, "pcr greater than max_pcr");
2120 // each limit unspecified or not violated
2121 PRINTD (DBG_QOS
, "xBR(pcr) OK");
2124 PRINTD (DBG_QOS
, "pcr=%u, tp: min_pcr=%d, pcr=%d, max_pcr=%d",
2125 pcr
, tp
->min_pcr
, tp
->pcr
, tp
->max_pcr
);
2129 /********** open VC **********/
2131 static int hrz_open (struct atm_vcc
*atm_vcc
)
2136 struct atm_qos
* qos
;
2137 struct atm_trafprm
* txtp
;
2138 struct atm_trafprm
* rxtp
;
2140 hrz_dev
* dev
= HRZ_DEV(atm_vcc
->dev
);
2142 hrz_vcc
* vccp
; // allocated late
2143 short vpi
= atm_vcc
->vpi
;
2144 int vci
= atm_vcc
->vci
;
2145 PRINTD (DBG_FLOW
|DBG_VCC
, "hrz_open %x %x", vpi
, vci
);
2147 #ifdef ATM_VPI_UNSPEC
2148 // UNSPEC is deprecated, remove this code eventually
2149 if (vpi
== ATM_VPI_UNSPEC
|| vci
== ATM_VCI_UNSPEC
) {
2150 PRINTK (KERN_WARNING
, "rejecting open with unspecified VPI/VCI (deprecated)");
2155 error
= vpivci_to_channel (&channel
, vpi
, vci
);
2157 PRINTD (DBG_WARN
|DBG_VCC
, "VPI/VCI out of range: %hd/%d", vpi
, vci
);
2161 vcc
.channel
= channel
;
2162 // max speed for the moment
2165 qos
= &atm_vcc
->qos
;
2167 // check AAL and remember it
2170 // we would if it were 48 bytes and not 52!
2171 PRINTD (DBG_QOS
|DBG_VCC
, "AAL0");
2175 // we would if I knew how do the SAR!
2176 PRINTD (DBG_QOS
|DBG_VCC
, "AAL3/4");
2180 PRINTD (DBG_QOS
|DBG_VCC
, "AAL5");
2184 PRINTD (DBG_QOS
|DBG_VCC
, "Bad AAL!");
2189 // TX traffic parameters
2191 // there are two, interrelated problems here: 1. the reservation of
2192 // PCR is not a binary choice, we are given bounds and/or a
2193 // desirable value; 2. the device is only capable of certain values,
2194 // most of which are not integers. It is almost certainly acceptable
2195 // to be off by a maximum of 1 to 10 cps.
2197 // Pragmatic choice: always store an integral PCR as that which has
2198 // been allocated, even if we allocate a little (or a lot) less,
2199 // after rounding. The actual allocation depends on what we can
2200 // manage with our rate selection algorithm. The rate selection
2201 // algorithm is given an integral PCR and a tolerance and told
2202 // whether it should round the value up or down if the tolerance is
2203 // exceeded; it returns: a) the actual rate selected (rounded up to
2204 // the nearest integer), b) a bit pattern to feed to the timer
2205 // register, and c) a failure value if no applicable rate exists.
2207 // Part of the job is done by atm_pcr_goal which gives us a PCR
2208 // specification which says: EITHER grab the maximum available PCR
2209 // (and perhaps a lower bound which we musn't pass), OR grab this
2210 // amount, rounding down if you have to (and perhaps a lower bound
2211 // which we musn't pass) OR grab this amount, rounding up if you
2212 // have to (and perhaps an upper bound which we musn't pass). If any
2213 // bounds ARE passed we fail. Note that rounding is only rounding to
2214 // match device limitations, we do not round down to satisfy
2215 // bandwidth availability even if this would not violate any given
2218 // Note: telephony = 64kb/s = 48 byte cell payload @ 500/3 cells/s
2219 // (say) so this is not even a binary fixpoint cell rate (but this
2220 // device can do it). To avoid this sort of hassle we use a
2221 // tolerance parameter (currently fixed at 10 cps).
2223 PRINTD (DBG_QOS
, "TX:");
2227 // set up defaults for no traffic
2229 // who knows what would actually happen if you try and send on this?
2230 vcc
.tx_xbr_bits
= IDLE_RATE_TYPE
;
2231 vcc
.tx_pcr_bits
= CLOCK_DISABLE
;
2233 vcc
.tx_scr_bits
= CLOCK_DISABLE
;
2234 vcc
.tx_bucket_bits
= 0;
2237 if (txtp
->traffic_class
!= ATM_NONE
) {
2238 error
= check_max_sdu (vcc
.aal
, txtp
, max_tx_size
);
2240 PRINTD (DBG_QOS
, "TX max_sdu check failed");
2244 switch (txtp
->traffic_class
) {
2246 // we take "the PCR" as a rate-cap
2249 make_rate (dev
, 1<<30, round_nearest
, &vcc
.tx_pcr_bits
, NULL
);
2250 vcc
.tx_xbr_bits
= ABR_RATE_TYPE
;
2255 // reserve min, allow up to max
2256 vcc
.tx_rate
= 0; // ?
2257 make_rate (dev
, 1<<30, round_nearest
, &vcc
.tx_pcr_bits
, 0);
2258 vcc
.tx_xbr_bits
= ABR_RATE_TYPE
;
2263 int pcr
= atm_pcr_goal (txtp
);
2266 // down vs. up, remaining bandwidth vs. unlimited bandwidth!!
2267 // should really have: once someone gets unlimited bandwidth
2268 // that no more non-UBR channels can be opened until the
2269 // unlimited one closes?? For the moment, round_down means
2270 // greedy people actually get something and not nothing
2272 // slight race (no locking) here so we may get -EAGAIN
2273 // later; the greedy bastards would deserve it :)
2274 PRINTD (DBG_QOS
, "snatching all remaining TX bandwidth");
2275 pcr
= dev
->tx_avail
;
2276 } else if (pcr
< 0) {
2282 error
= make_rate_with_tolerance (dev
, pcr
, r
, 10,
2283 &vcc
.tx_pcr_bits
, &vcc
.tx_rate
);
2285 PRINTD (DBG_QOS
, "could not make rate from TX PCR");
2288 // not really clear what further checking is needed
2289 error
= atm_pcr_check (txtp
, vcc
.tx_rate
);
2291 PRINTD (DBG_QOS
, "TX PCR failed consistency check");
2294 vcc
.tx_xbr_bits
= CBR_RATE_TYPE
;
2299 int pcr
= atm_pcr_goal (txtp
);
2300 // int scr = atm_scr_goal (txtp);
2301 int scr
= pcr
/2; // just for fun
2302 unsigned int mbs
= 60; // just for fun
2305 unsigned int bucket
;
2309 } else if (pcr
< 0) {
2315 error
= make_rate_with_tolerance (dev
, pcr
, pr
, 10,
2316 &vcc
.tx_pcr_bits
, 0);
2318 // see comments for PCR with CBR above
2320 // slight race (no locking) here so we may get -EAGAIN
2321 // later; the greedy bastards would deserve it :)
2322 PRINTD (DBG_QOS
, "snatching all remaining TX bandwidth");
2323 scr
= dev
->tx_avail
;
2324 } else if (scr
< 0) {
2330 error
= make_rate_with_tolerance (dev
, scr
, sr
, 10,
2331 &vcc
.tx_scr_bits
, &vcc
.tx_rate
);
2333 PRINTD (DBG_QOS
, "could not make rate from TX SCR");
2336 // not really clear what further checking is needed
2337 // error = atm_scr_check (txtp, vcc.tx_rate);
2339 PRINTD (DBG_QOS
, "TX SCR failed consistency check");
2342 // bucket calculations (from a piece of paper...) cell bucket
2343 // capacity must be largest integer smaller than m(p-s)/p + 1
2344 // where m = max burst size, p = pcr, s = scr
2345 bucket
= mbs
*(pcr
-scr
)/pcr
;
2346 if (bucket
*pcr
!= mbs
*(pcr
-scr
))
2348 if (bucket
> BUCKET_MAX_SIZE
) {
2349 PRINTD (DBG_QOS
, "shrinking bucket from %u to %u",
2350 bucket
, BUCKET_MAX_SIZE
);
2351 bucket
= BUCKET_MAX_SIZE
;
2353 vcc
.tx_xbr_bits
= VBR_RATE_TYPE
;
2354 vcc
.tx_bucket_bits
= bucket
;
2359 PRINTD (DBG_QOS
, "unsupported TX traffic class");
2366 // RX traffic parameters
2368 PRINTD (DBG_QOS
, "RX:");
2372 // set up defaults for no traffic
2375 if (rxtp
->traffic_class
!= ATM_NONE
) {
2376 error
= check_max_sdu (vcc
.aal
, rxtp
, max_rx_size
);
2378 PRINTD (DBG_QOS
, "RX max_sdu check failed");
2381 switch (rxtp
->traffic_class
) {
2389 vcc
.rx_rate
= 0; // ?
2394 int pcr
= atm_pcr_goal (rxtp
);
2396 // slight race (no locking) here so we may get -EAGAIN
2397 // later; the greedy bastards would deserve it :)
2398 PRINTD (DBG_QOS
, "snatching all remaining RX bandwidth");
2399 pcr
= dev
->rx_avail
;
2400 } else if (pcr
< 0) {
2404 // not really clear what further checking is needed
2405 error
= atm_pcr_check (rxtp
, vcc
.rx_rate
);
2407 PRINTD (DBG_QOS
, "RX PCR failed consistency check");
2414 // int scr = atm_scr_goal (rxtp);
2415 int scr
= 1<<16; // just for fun
2417 // slight race (no locking) here so we may get -EAGAIN
2418 // later; the greedy bastards would deserve it :)
2419 PRINTD (DBG_QOS
, "snatching all remaining RX bandwidth");
2420 scr
= dev
->rx_avail
;
2421 } else if (scr
< 0) {
2425 // not really clear what further checking is needed
2426 // error = atm_scr_check (rxtp, vcc.rx_rate);
2428 PRINTD (DBG_QOS
, "RX SCR failed consistency check");
2435 PRINTD (DBG_QOS
, "unsupported RX traffic class");
2443 // late abort useful for diagnostics
2444 if (vcc
.aal
!= aal5
) {
2445 PRINTD (DBG_QOS
, "AAL not supported");
2449 // get space for our vcc stuff and copy parameters into it
2450 vccp
= kmalloc (sizeof(hrz_vcc
), GFP_KERNEL
);
2452 PRINTK (KERN_ERR
, "out of memory!");
2457 // clear error and grab cell rate resource lock
2459 spin_lock (&dev
->rate_lock
);
2461 if (vcc
.tx_rate
> dev
->tx_avail
) {
2462 PRINTD (DBG_QOS
, "not enough TX PCR left");
2466 if (vcc
.rx_rate
> dev
->rx_avail
) {
2467 PRINTD (DBG_QOS
, "not enough RX PCR left");
2472 // really consume cell rates
2473 dev
->tx_avail
-= vcc
.tx_rate
;
2474 dev
->rx_avail
-= vcc
.rx_rate
;
2475 PRINTD (DBG_QOS
|DBG_VCC
, "reserving %u TX PCR and %u RX PCR",
2476 vcc
.tx_rate
, vcc
.rx_rate
);
2479 // release lock and exit on error
2480 spin_unlock (&dev
->rate_lock
);
2482 PRINTD (DBG_QOS
|DBG_VCC
, "insufficient cell rate resources");
2487 // this is "immediately before allocating the connection identifier
2488 // in hardware" - so long as the next call does not fail :)
2489 set_bit(ATM_VF_ADDR
,&atm_vcc
->flags
);
2491 // any errors here are very serious and should never occur
2493 if (rxtp
->traffic_class
!= ATM_NONE
) {
2494 if (dev
->rxer
[channel
]) {
2495 PRINTD (DBG_ERR
|DBG_VCC
, "VC already open for RX");
2499 error
= hrz_open_rx (dev
, channel
);
2504 // this link allows RX frames through
2505 dev
->rxer
[channel
] = atm_vcc
;
2508 // success, set elements of atm_vcc
2509 atm_vcc
->dev_data
= (void *) vccp
;
2511 // indicate readiness
2512 set_bit(ATM_VF_READY
,&atm_vcc
->flags
);
2517 /********** close VC **********/
2519 static void hrz_close (struct atm_vcc
* atm_vcc
) {
2520 hrz_dev
* dev
= HRZ_DEV(atm_vcc
->dev
);
2521 hrz_vcc
* vcc
= HRZ_VCC(atm_vcc
);
2522 u16 channel
= vcc
->channel
;
2523 PRINTD (DBG_VCC
|DBG_FLOW
, "hrz_close");
2525 // indicate unreadiness
2526 clear_bit(ATM_VF_READY
,&atm_vcc
->flags
);
2528 if (atm_vcc
->qos
.txtp
.traffic_class
!= ATM_NONE
) {
2531 // let any TX on this channel that has started complete
2532 // no restart, just keep trying
2533 while (tx_hold (dev
))
2535 // remove record of any tx_channel having been setup for this channel
2536 for (i
= 0; i
< TX_CHANS
; ++i
)
2537 if (dev
->tx_channel_record
[i
] == channel
) {
2538 dev
->tx_channel_record
[i
] = -1;
2541 if (dev
->last_vc
== channel
)
2546 if (atm_vcc
->qos
.rxtp
.traffic_class
!= ATM_NONE
) {
2547 // disable RXing - it tries quite hard
2548 hrz_close_rx (dev
, channel
);
2549 // forget the vcc - no more skbs will be pushed
2550 if (atm_vcc
!= dev
->rxer
[channel
])
2551 PRINTK (KERN_ERR
, "%s atm_vcc=%p rxer[channel]=%p",
2552 "arghhh! we're going to die!",
2553 atm_vcc
, dev
->rxer
[channel
]);
2554 dev
->rxer
[channel
] = NULL
;
2557 // atomically release our rate reservation
2558 spin_lock (&dev
->rate_lock
);
2559 PRINTD (DBG_QOS
|DBG_VCC
, "releasing %u TX PCR and %u RX PCR",
2560 vcc
->tx_rate
, vcc
->rx_rate
);
2561 dev
->tx_avail
+= vcc
->tx_rate
;
2562 dev
->rx_avail
+= vcc
->rx_rate
;
2563 spin_unlock (&dev
->rate_lock
);
2565 // free our structure
2567 // say the VPI/VCI is free again
2568 clear_bit(ATM_VF_ADDR
,&atm_vcc
->flags
);
2572 static int hrz_getsockopt (struct atm_vcc
* atm_vcc
, int level
, int optname
,
2573 void *optval
, int optlen
) {
2574 hrz_dev
* dev
= HRZ_DEV(atm_vcc
->dev
);
2575 PRINTD (DBG_FLOW
|DBG_VCC
, "hrz_getsockopt");
2584 return -ENOPROTOOPT
;
2592 static int hrz_setsockopt (struct atm_vcc
* atm_vcc
, int level
, int optname
,
2593 void *optval
, unsigned int optlen
) {
2594 hrz_dev
* dev
= HRZ_DEV(atm_vcc
->dev
);
2595 PRINTD (DBG_FLOW
|DBG_VCC
, "hrz_setsockopt");
2604 return -ENOPROTOOPT
;
2614 static int hrz_ioctl (struct atm_dev
* atm_dev
, unsigned int cmd
, void *arg
) {
2615 hrz_dev
* dev
= HRZ_DEV(atm_dev
);
2616 PRINTD (DBG_FLOW
, "hrz_ioctl");
2620 unsigned char hrz_phy_get (struct atm_dev
* atm_dev
, unsigned long addr
) {
2621 hrz_dev
* dev
= HRZ_DEV(atm_dev
);
2622 PRINTD (DBG_FLOW
, "hrz_phy_get");
2626 static void hrz_phy_put (struct atm_dev
* atm_dev
, unsigned char value
,
2627 unsigned long addr
) {
2628 hrz_dev
* dev
= HRZ_DEV(atm_dev
);
2629 PRINTD (DBG_FLOW
, "hrz_phy_put");
2632 static int hrz_change_qos (struct atm_vcc
* atm_vcc
, struct atm_qos
*qos
, int flgs
) {
2633 hrz_dev
* dev
= HRZ_DEV(vcc
->dev
);
2634 PRINTD (DBG_FLOW
, "hrz_change_qos");
2639 /********** proc file contents **********/
2641 static int hrz_proc_read (struct atm_dev
* atm_dev
, loff_t
* pos
, char * page
) {
2642 hrz_dev
* dev
= HRZ_DEV(atm_dev
);
2644 PRINTD (DBG_FLOW
, "hrz_proc_read");
2646 /* more diagnostics here? */
2650 unsigned int count
= sprintf (page
, "vbr buckets:");
2652 for (i
= 0; i
< TX_CHANS
; ++i
)
2653 count
+= sprintf (page
, " %u/%u",
2654 query_tx_channel_config (dev
, i
, BUCKET_FULLNESS_ACCESS
),
2655 query_tx_channel_config (dev
, i
, BUCKET_CAPACITY_ACCESS
));
2656 count
+= sprintf (page
+count
, ".\n");
2662 return sprintf (page
,
2663 "cells: TX %lu, RX %lu, HEC errors %lu, unassigned %lu.\n",
2664 dev
->tx_cell_count
, dev
->rx_cell_count
,
2665 dev
->hec_error_count
, dev
->unassigned_cell_count
);
2668 return sprintf (page
,
2669 "free cell buffers: TX %hu, RX %hu+%hu.\n",
2670 rd_regw (dev
, TX_FREE_BUFFER_COUNT_OFF
),
2671 rd_regw (dev
, RX_FREE_BUFFER_COUNT_OFF
),
2672 dev
->noof_spare_buffers
);
2675 return sprintf (page
,
2676 "cps remaining: TX %u, RX %u\n",
2677 dev
->tx_avail
, dev
->rx_avail
);
2682 static const struct atmdev_ops hrz_ops
= {
2686 .proc_read
= hrz_proc_read
,
2687 .owner
= THIS_MODULE
,
2690 static int __devinit
hrz_probe(struct pci_dev
*pci_dev
, const struct pci_device_id
*pci_ent
)
2695 // adapter slot free, read resources from PCI configuration space
2696 u32 iobase
= pci_resource_start (pci_dev
, 0);
2697 u32
* membase
= bus_to_virt (pci_resource_start (pci_dev
, 1));
2701 PRINTD (DBG_FLOW
, "hrz_probe");
2703 if (pci_enable_device(pci_dev
))
2706 /* XXX DEV_LABEL is a guess */
2707 if (!request_region(iobase
, HRZ_IO_EXTENT
, DEV_LABEL
)) {
2712 dev
= kzalloc(sizeof(hrz_dev
), GFP_KERNEL
);
2714 // perhaps we should be nice: deregister all adapters and abort?
2715 PRINTD(DBG_ERR
, "out of memory");
2720 pci_set_drvdata(pci_dev
, dev
);
2722 // grab IRQ and install handler - move this someplace more sensible
2724 if (request_irq(irq
,
2726 IRQF_SHARED
, /* irqflags guess */
2727 DEV_LABEL
, /* name guess */
2729 PRINTD(DBG_WARN
, "request IRQ failed!");
2734 PRINTD(DBG_INFO
, "found Madge ATM adapter (hrz) at: IO %x, IRQ %u, MEM %p",
2735 iobase
, irq
, membase
);
2737 dev
->atm_dev
= atm_dev_register(DEV_LABEL
, &pci_dev
->dev
, &hrz_ops
, -1,
2739 if (!(dev
->atm_dev
)) {
2740 PRINTD(DBG_ERR
, "failed to register Madge ATM adapter");
2745 PRINTD(DBG_INFO
, "registered Madge ATM adapter (no. %d) (%p) at %p",
2746 dev
->atm_dev
->number
, dev
, dev
->atm_dev
);
2747 dev
->atm_dev
->dev_data
= (void *) dev
;
2748 dev
->pci_dev
= pci_dev
;
2750 // enable bus master accesses
2751 pci_set_master(pci_dev
);
2753 // frobnicate latency (upwards, usually)
2754 pci_read_config_byte(pci_dev
, PCI_LATENCY_TIMER
, &lat
);
2756 PRINTD(DBG_INFO
, "%s PCI latency timer from %hu to %hu",
2757 "changing", lat
, pci_lat
);
2758 pci_write_config_byte(pci_dev
, PCI_LATENCY_TIMER
, pci_lat
);
2759 } else if (lat
< MIN_PCI_LATENCY
) {
2760 PRINTK(KERN_INFO
, "%s PCI latency timer from %hu to %hu",
2761 "increasing", lat
, MIN_PCI_LATENCY
);
2762 pci_write_config_byte(pci_dev
, PCI_LATENCY_TIMER
, MIN_PCI_LATENCY
);
2765 dev
->iobase
= iobase
;
2767 dev
->membase
= membase
;
2769 dev
->rx_q_entry
= dev
->rx_q_reset
= &memmap
->rx_q_entries
[0];
2770 dev
->rx_q_wrap
= &memmap
->rx_q_entries
[RX_CHANS
-1];
2772 // these next three are performance hacks
2777 dev
->tx_regions
= 0;
2780 dev
->tx_iovec
= NULL
;
2782 dev
->tx_cell_count
= 0;
2783 dev
->rx_cell_count
= 0;
2784 dev
->hec_error_count
= 0;
2785 dev
->unassigned_cell_count
= 0;
2787 dev
->noof_spare_buffers
= 0;
2791 for (i
= 0; i
< TX_CHANS
; ++i
)
2792 dev
->tx_channel_record
[i
] = -1;
2797 // Allocate cell rates and remember ASIC version
2798 // Fibre: ATM_OC3_PCR = 1555200000/8/270*260/53 - 29/53
2799 // Copper: (WRONG) we want 6 into the above, close to 25Mb/s
2800 // Copper: (plagarise!) 25600000/8/270*260/53 - n/53
2802 if (hrz_init(dev
)) {
2803 // to be really pedantic, this should be ATM_OC3c_PCR
2804 dev
->tx_avail
= ATM_OC3_PCR
;
2805 dev
->rx_avail
= ATM_OC3_PCR
;
2806 set_bit(ultra
, &dev
->flags
); // NOT "|= ultra" !
2808 dev
->tx_avail
= ((25600000/8)*26)/(27*53);
2809 dev
->rx_avail
= ((25600000/8)*26)/(27*53);
2810 PRINTD(DBG_WARN
, "Buggy ASIC: no TX bus-mastering.");
2813 // rate changes spinlock
2814 spin_lock_init(&dev
->rate_lock
);
2816 // on-board memory access spinlock; we want atomic reads and
2817 // writes to adapter memory (handles IRQ and SMP)
2818 spin_lock_init(&dev
->mem_lock
);
2820 init_waitqueue_head(&dev
->tx_queue
);
2822 // vpi in 0..4, vci in 6..10
2823 dev
->atm_dev
->ci_range
.vpi_bits
= vpi_bits
;
2824 dev
->atm_dev
->ci_range
.vci_bits
= 10-vpi_bits
;
2826 init_timer(&dev
->housekeeping
);
2827 dev
->housekeeping
.function
= do_housekeeping
;
2828 dev
->housekeeping
.data
= (unsigned long) dev
;
2829 mod_timer(&dev
->housekeeping
, jiffies
);
2835 free_irq(dev
->irq
, dev
);
2839 release_region(iobase
, HRZ_IO_EXTENT
);
2841 pci_disable_device(pci_dev
);
2845 static void __devexit
hrz_remove_one(struct pci_dev
*pci_dev
)
2849 dev
= pci_get_drvdata(pci_dev
);
2851 PRINTD(DBG_INFO
, "closing %p (atm_dev = %p)", dev
, dev
->atm_dev
);
2852 del_timer_sync(&dev
->housekeeping
);
2854 atm_dev_deregister(dev
->atm_dev
);
2855 free_irq(dev
->irq
, dev
);
2856 release_region(dev
->iobase
, HRZ_IO_EXTENT
);
2859 pci_disable_device(pci_dev
);
2862 static void __init
hrz_check_args (void) {
2863 #ifdef DEBUG_HORIZON
2864 PRINTK (KERN_NOTICE
, "debug bitmap is %hx", debug
&= DBG_MASK
);
2867 PRINTK (KERN_NOTICE
, "no debug support in this image");
2870 if (vpi_bits
> HRZ_MAX_VPI
)
2871 PRINTK (KERN_ERR
, "vpi_bits has been limited to %hu",
2872 vpi_bits
= HRZ_MAX_VPI
);
2874 if (max_tx_size
< 0 || max_tx_size
> TX_AAL5_LIMIT
)
2875 PRINTK (KERN_NOTICE
, "max_tx_size has been limited to %hu",
2876 max_tx_size
= TX_AAL5_LIMIT
);
2878 if (max_rx_size
< 0 || max_rx_size
> RX_AAL5_LIMIT
)
2879 PRINTK (KERN_NOTICE
, "max_rx_size has been limited to %hu",
2880 max_rx_size
= RX_AAL5_LIMIT
);
2885 MODULE_AUTHOR(maintainer_string
);
2886 MODULE_DESCRIPTION(description_string
);
2887 MODULE_LICENSE("GPL");
2888 module_param(debug
, ushort
, 0644);
2889 module_param(vpi_bits
, ushort
, 0);
2890 module_param(max_tx_size
, int, 0);
2891 module_param(max_rx_size
, int, 0);
2892 module_param(pci_lat
, byte
, 0);
2893 MODULE_PARM_DESC(debug
, "debug bitmap, see .h file");
2894 MODULE_PARM_DESC(vpi_bits
, "number of bits (0..4) to allocate to VPIs");
2895 MODULE_PARM_DESC(max_tx_size
, "maximum size of TX AAL5 frames");
2896 MODULE_PARM_DESC(max_rx_size
, "maximum size of RX AAL5 frames");
2897 MODULE_PARM_DESC(pci_lat
, "PCI latency in bus cycles");
2899 static struct pci_device_id hrz_pci_tbl
[] = {
2900 { PCI_VENDOR_ID_MADGE
, PCI_DEVICE_ID_MADGE_HORIZON
, PCI_ANY_ID
, PCI_ANY_ID
,
2905 MODULE_DEVICE_TABLE(pci
, hrz_pci_tbl
);
2907 static struct pci_driver hrz_driver
= {
2910 .remove
= __devexit_p(hrz_remove_one
),
2911 .id_table
= hrz_pci_tbl
,
2914 /********** module entry **********/
2916 static int __init
hrz_module_init (void) {
2917 // sanity check - cast is needed since printk does not support %Zu
2918 if (sizeof(struct MEMMAP
) != 128*1024/4) {
2919 PRINTK (KERN_ERR
, "Fix struct MEMMAP (is %lu fakewords).",
2920 (unsigned long) sizeof(struct MEMMAP
));
2930 return pci_register_driver(&hrz_driver
);
2933 /********** module exit **********/
2935 static void __exit
hrz_module_exit (void) {
2936 PRINTD (DBG_FLOW
, "cleanup_module");
2938 pci_unregister_driver(&hrz_driver
);
2941 module_init(hrz_module_init
);
2942 module_exit(hrz_module_exit
);