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/ioport.h>
42 #include <linux/wait.h>
43 #include <linux/slab.h>
45 #include <asm/system.h>
47 #include <asm/atomic.h>
48 #include <asm/uaccess.h>
49 #include <asm/string.h>
50 #include <asm/byteorder.h>
54 #define maintainer_string "Giuliano Procida at Madge Networks <gprocida@madge.com>"
55 #define description_string "Madge ATM Horizon [Ultra] driver"
56 #define version_string "1.2.1"
58 static inline void __init
show_version (void) {
59 printk ("%s version %s\n", description_string
, version_string
);
66 Driver and documentation by:
68 Chris Aston Madge Networks
69 Giuliano Procida Madge Networks
70 Simon Benham Madge Networks
71 Simon Johnson Madge Networks
72 Various Others Madge Networks
74 Some inspiration taken from other drivers by:
77 Kari Mettinen University of Helsinki
78 Werner Almesberger EPFL LRC
82 I Hardware, detection, initialisation and shutdown.
86 This driver should handle all variants of the PCI Madge ATM adapters
87 with the Horizon chipset. These are all PCI cards supporting PIO, BM
88 DMA and a form of MMIO (registers only, not internal RAM).
90 The driver is only known to work with SONET and UTP Horizon Ultra
91 cards at 155Mb/s. However, code is in place to deal with both the
92 original Horizon and 25Mb/s operation.
94 There are two revisions of the Horizon ASIC: the original and the
95 Ultra. Details of hardware bugs are in section III.
97 The ASIC version can be distinguished by chip markings but is NOT
98 indicated by the PCI revision (all adapters seem to have PCI rev 1).
102 Horizon => Collage 25 PCI Adapter (UTP and STP)
103 Horizon Ultra => Collage 155 PCI Client (UTP or SONET)
104 Ambassador x => Collage 155 PCI Server (completely different)
106 Horizon (25Mb/s) is fitted with UTP and STP connectors. It seems to
107 have a Madge B154 plus glue logic serializer. I have also found a
108 really ancient version of this with slightly different glue. It
109 comes with the revision 0 (140-025-01) ASIC.
111 Horizon Ultra (155Mb/s) is fitted with either a Pulse Medialink
112 output (UTP) or an HP HFBR 5205 output (SONET). It has either
113 Madge's SAMBA framer or a SUNI-lite device (early versions). It
114 comes with the revision 1 (140-027-01) ASIC.
118 All Horizon-based cards present with the same PCI Vendor and Device
119 IDs. The standard Linux 2.2 PCI API is used to locate any cards and
120 to enable bus-mastering (with appropriate latency).
122 ATM_LAYER_STATUS in the control register distinguishes between the
123 two possible physical layers (25 and 155). It is not clear whether
124 the 155 cards can also operate at 25Mbps. We rely on the fact that a
125 card operates at 155 if and only if it has the newer Horizon Ultra
128 For 155 cards the two possible framers are probed for and then set
133 The card is reset and then put into a known state. The physical
134 layer is configured for normal operation at the appropriate speed;
135 in the case of the 155 cards, the framer is initialised with
136 line-based timing; the internal RAM is zeroed and the allocation of
137 buffers for RX and TX is made; the Burnt In Address is read and
138 copied to the ATM ESI; various policy settings for RX (VPI bits,
139 unknown VCs, oam cells) are made. Ideally all policy items should be
140 configurable at module load (if not actually on-demand), however,
141 only the vpi vs vci bit allocation can be specified at insmod.
145 This is in response to module_cleaup. No VCs are in use and the card
146 should be idle; it is reset.
148 II Driver software (as it should be)
150 0. Traffic Parameters
152 The traffic classes (not an enumeration) are currently: ATM_NONE (no
153 traffic), ATM_UBR, ATM_CBR, ATM_VBR and ATM_ABR, ATM_ANYCLASS
154 (compatible with everything). Together with (perhaps only some of)
155 the following items they make up the traffic specification.
158 unsigned char traffic_class; traffic class (ATM_UBR, ...)
159 int max_pcr; maximum PCR in cells per second
160 int pcr; desired PCR in cells per second
161 int min_pcr; minimum PCR in cells per second
162 int max_cdv; maximum CDV in microseconds
163 int max_sdu; maximum SDU in bytes
166 Note that these denote bandwidth available not bandwidth used; the
167 possibilities according to ATMF are:
169 Real Time (cdv and max CDT given)
171 CBR(pcr) pcr bandwidth always available
172 rtVBR(pcr,scr,mbs) scr bandwidth always available, upto pcr at mbs too
176 nrtVBR(pcr,scr,mbs) scr bandwidth always available, upto pcr at mbs too
178 ABR(mcr,pcr) mcr bandwidth always available, upto pcr (depending) too
180 mbs is max burst size (bucket)
181 pcr and scr have associated cdvt values
182 mcr is like scr but has no cdtv
183 cdtv may differ at each hop
185 Some of the above items are qos items (as opposed to traffic
186 parameters). We have nothing to do with qos. All except ABR can have
187 their traffic parameters converted to GCRA parameters. The GCRA may
188 be implemented as a (real-number) leaky bucket. The GCRA can be used
189 in complicated ways by switches and in simpler ways by end-stations.
190 It can be used both to filter incoming cells and shape out-going
193 ATM Linux actually supports:
195 ATM_NONE() (no traffic in this direction)
196 ATM_UBR(max_frame_size)
197 ATM_CBR(max/min_pcr, max_cdv, max_frame_size)
199 0 or ATM_MAX_PCR are used to indicate maximum available PCR
201 A traffic specification consists of the AAL type and separate
202 traffic specifications for either direction. In ATM Linux it is:
205 struct atm_trafprm txtp;
206 struct atm_trafprm rxtp;
212 ATM_NO_AAL AAL not specified
213 ATM_AAL0 "raw" ATM cells
216 ATM_AAL34 AAL3/4 (data)
218 ATM_SAAL signaling AAL
220 The Horizon has support for AAL frame types: 0, 3/4 and 5. However,
221 it does not implement AAL 3/4 SAR and it has a different notion of
222 "raw cell" to ATM Linux's (48 bytes vs. 52 bytes) so neither are
223 supported by this driver.
225 The Horizon has limited support for ABR (including UBR), VBR and
226 CBR. Each TX channel has a bucket (containing up to 31 cell units)
227 and two timers (PCR and SCR) associated with it that can be used to
228 govern cell emissions and host notification (in the case of ABR this
229 is presumably so that RM cells may be emitted at appropriate times).
230 The timers may either be disabled or may be set to any of 240 values
231 (determined by the clock crystal, a fixed (?) per-device divider, a
232 configurable divider and a configurable timer preload value).
234 At the moment only UBR and CBR are supported by the driver. VBR will
235 be supported as soon as ATM for Linux supports it. ABR support is
236 very unlikely as RM cell handling is completely up to the driver.
238 1. TX (TX channel setup and TX transfer)
240 The TX half of the driver owns the TX Horizon registers. The TX
241 component in the IRQ handler is the BM completion handler. This can
242 only be entered when tx_busy is true (enforced by hardware). The
243 other TX component can only be entered when tx_busy is false
244 (enforced by driver). So TX is single-threaded.
246 Apart from a minor optimisation to not re-select the last channel,
247 the TX send component works as follows:
249 Atomic test and set tx_busy until we succeed; we should implement
250 some sort of timeout so that tx_busy will never be stuck at true.
252 If no TX channel is set up for this VC we wait for an idle one (if
253 necessary) and set it up.
255 At this point we have a TX channel ready for use. We wait for enough
256 buffers to become available then start a TX transmit (set the TX
257 descriptor, schedule transfer, exit).
259 The IRQ component handles TX completion (stats, free buffer, tx_busy
260 unset, exit). We also re-schedule further transfers for the same
263 TX setup in more detail:
265 TX open is a nop, the relevant information is held in the hrz_vcc
266 (vcc->dev_data) structure and is "cached" on the card.
268 TX close gets the TX lock and clears the channel from the "cache".
270 2. RX (Data Available and RX transfer)
272 The RX half of the driver owns the RX registers. There are two RX
273 components in the IRQ handler: the data available handler deals with
274 fresh data that has arrived on the card, the BM completion handler
275 is very similar to the TX completion handler. The data available
276 handler grabs the rx_lock and it is only released once the data has
277 been discarded or completely transferred to the host. The BM
278 completion handler only runs when the lock is held; the data
279 available handler is locked out over the same period.
281 Data available on the card triggers an interrupt. If the data is not
282 suitable for our existing RX channels or we cannot allocate a buffer
283 it is flushed. Otherwise an RX receive is scheduled. Multiple RX
284 transfers may be scheduled for the same frame.
286 RX setup in more detail:
293 0. Byte vs Word addressing of adapter RAM.
295 A design feature; see the .h file (especially the memory map).
297 1. Bus Master Data Transfers (original Horizon only, fixed in Ultra)
299 The host must not start a transmit direction transfer at a
300 non-four-byte boundary in host memory. Instead the host should
301 perform a byte, or a two byte, or one byte followed by two byte
302 transfer in order to start the rest of the transfer on a four byte
305 Simultaneous transmit and receive direction bus master transfers are
308 The simplest solution to these two is to always do PIO (never DMA)
309 in the TX direction on the original Horizon. More complicated
310 solutions are likely to hurt my brain.
312 2. Loss of buffer on close VC
314 When a VC is being closed, the buffer associated with it is not
315 returned to the pool. The host must store the reference to this
316 buffer and when opening a new VC then give it to that new VC.
318 The host intervention currently consists of stacking such a buffer
319 pointer at VC close and checking the stack at VC open.
321 3. Failure to close a VC
323 If a VC is currently receiving a frame then closing the VC may fail
324 and the frame continues to be received.
326 The solution is to make sure any received frames are flushed when
327 ready. This is currently done just before the solution to 2.
329 4. PCI bus (original Horizon only, fixed in Ultra)
331 Reading from the data port prior to initialisation will hang the PCI
332 bus. Just don't do that then! We don't.
336 . Timer code may be broken.
338 . Allow users to specify buffer allocation split for TX and RX.
340 . Deal once and for all with buggy VC close.
342 . Handle interrupted and/or non-blocking operations.
344 . Change some macros to functions and move from .h to .c.
346 . Try to limit the number of TX frames each VC may have queued, in
347 order to reduce the chances of TX buffer exhaustion.
349 . Implement VBR (bucket and timers not understood) and ABR (need to
350 do RM cells manually); also no Linux support for either.
352 . Implement QoS changes on open VCs (involves extracting parts of VC open
353 and close into separate functions and using them to make changes).
357 /********** globals **********/
359 static void do_housekeeping (unsigned long arg
);
361 static unsigned short debug
= 0;
362 static unsigned short vpi_bits
= 0;
363 static int max_tx_size
= 9000;
364 static int max_rx_size
= 9000;
365 static unsigned char pci_lat
= 0;
367 /********** access functions **********/
369 /* Read / Write Horizon registers */
370 static inline void wr_regl (const hrz_dev
* dev
, unsigned char reg
, u32 data
) {
371 outl (cpu_to_le32 (data
), dev
->iobase
+ reg
);
374 static inline u32
rd_regl (const hrz_dev
* dev
, unsigned char reg
) {
375 return le32_to_cpu (inl (dev
->iobase
+ reg
));
378 static inline void wr_regw (const hrz_dev
* dev
, unsigned char reg
, u16 data
) {
379 outw (cpu_to_le16 (data
), dev
->iobase
+ reg
);
382 static inline u16
rd_regw (const hrz_dev
* dev
, unsigned char reg
) {
383 return le16_to_cpu (inw (dev
->iobase
+ reg
));
386 static inline void wrs_regb (const hrz_dev
* dev
, unsigned char reg
, void * addr
, u32 len
) {
387 outsb (dev
->iobase
+ reg
, addr
, len
);
390 static inline void rds_regb (const hrz_dev
* dev
, unsigned char reg
, void * addr
, u32 len
) {
391 insb (dev
->iobase
+ reg
, addr
, len
);
394 /* Read / Write to a given address in Horizon buffer memory.
395 Interrupts must be disabled between the address register and data
396 port accesses as these must form an atomic operation. */
397 static inline void wr_mem (const hrz_dev
* dev
, HDW
* addr
, u32 data
) {
398 // wr_regl (dev, MEM_WR_ADDR_REG_OFF, (u32) addr);
399 wr_regl (dev
, MEM_WR_ADDR_REG_OFF
, (addr
- (HDW
*) 0) * sizeof(HDW
));
400 wr_regl (dev
, MEMORY_PORT_OFF
, data
);
403 static inline u32
rd_mem (const hrz_dev
* dev
, HDW
* addr
) {
404 // wr_regl (dev, MEM_RD_ADDR_REG_OFF, (u32) addr);
405 wr_regl (dev
, MEM_RD_ADDR_REG_OFF
, (addr
- (HDW
*) 0) * sizeof(HDW
));
406 return rd_regl (dev
, MEMORY_PORT_OFF
);
409 static inline void wr_framer (const hrz_dev
* dev
, u32 addr
, u32 data
) {
410 wr_regl (dev
, MEM_WR_ADDR_REG_OFF
, (u32
) addr
| 0x80000000);
411 wr_regl (dev
, MEMORY_PORT_OFF
, data
);
414 static inline u32
rd_framer (const hrz_dev
* dev
, u32 addr
) {
415 wr_regl (dev
, MEM_RD_ADDR_REG_OFF
, (u32
) addr
| 0x80000000);
416 return rd_regl (dev
, MEMORY_PORT_OFF
);
419 /********** specialised access functions **********/
423 static inline void FLUSH_RX_CHANNEL (hrz_dev
* dev
, u16 channel
) {
424 wr_regw (dev
, RX_CHANNEL_PORT_OFF
, FLUSH_CHANNEL
| channel
);
428 static void WAIT_FLUSH_RX_COMPLETE (hrz_dev
* dev
) {
429 while (rd_regw (dev
, RX_CHANNEL_PORT_OFF
) & FLUSH_CHANNEL
)
434 static inline void SELECT_RX_CHANNEL (hrz_dev
* dev
, u16 channel
) {
435 wr_regw (dev
, RX_CHANNEL_PORT_OFF
, channel
);
439 static void WAIT_UPDATE_COMPLETE (hrz_dev
* dev
) {
440 while (rd_regw (dev
, RX_CHANNEL_PORT_OFF
) & RX_CHANNEL_UPDATE_IN_PROGRESS
)
447 static inline void SELECT_TX_CHANNEL (hrz_dev
* dev
, u16 tx_channel
) {
448 wr_regl (dev
, TX_CHANNEL_PORT_OFF
, tx_channel
);
452 /* Update or query one configuration parameter of a particular channel. */
454 static inline void update_tx_channel_config (hrz_dev
* dev
, short chan
, u8 mode
, u16 value
) {
455 wr_regw (dev
, TX_CHANNEL_CONFIG_COMMAND_OFF
,
456 chan
* TX_CHANNEL_CONFIG_MULT
| mode
);
457 wr_regw (dev
, TX_CHANNEL_CONFIG_DATA_OFF
, value
);
461 static inline u16
query_tx_channel_config (hrz_dev
* dev
, short chan
, u8 mode
) {
462 wr_regw (dev
, TX_CHANNEL_CONFIG_COMMAND_OFF
,
463 chan
* TX_CHANNEL_CONFIG_MULT
| mode
);
464 return rd_regw (dev
, TX_CHANNEL_CONFIG_DATA_OFF
);
467 /********** dump functions **********/
469 static inline void dump_skb (char * prefix
, unsigned int vc
, struct sk_buff
* skb
) {
472 unsigned char * data
= skb
->data
;
473 PRINTDB (DBG_DATA
, "%s(%u) ", prefix
, vc
);
474 for (i
=0; i
<skb
->len
&& i
< 256;i
++)
475 PRINTDM (DBG_DATA
, "%02x ", data
[i
]);
476 PRINTDE (DBG_DATA
,"");
485 static inline void dump_regs (hrz_dev
* dev
) {
487 PRINTD (DBG_REGS
, "CONTROL 0: %#x", rd_regl (dev
, CONTROL_0_REG
));
488 PRINTD (DBG_REGS
, "RX CONFIG: %#x", rd_regw (dev
, RX_CONFIG_OFF
));
489 PRINTD (DBG_REGS
, "TX CONFIG: %#x", rd_regw (dev
, TX_CONFIG_OFF
));
490 PRINTD (DBG_REGS
, "TX STATUS: %#x", rd_regw (dev
, TX_STATUS_OFF
));
491 PRINTD (DBG_REGS
, "IRQ ENBLE: %#x", rd_regl (dev
, INT_ENABLE_REG_OFF
));
492 PRINTD (DBG_REGS
, "IRQ SORCE: %#x", rd_regl (dev
, INT_SOURCE_REG_OFF
));
499 static inline void dump_framer (hrz_dev
* dev
) {
502 PRINTDB (DBG_REGS
, "framer registers:");
503 for (i
= 0; i
< 0x10; ++i
)
504 PRINTDM (DBG_REGS
, " %02x", rd_framer (dev
, i
));
505 PRINTDE (DBG_REGS
,"");
512 /********** VPI/VCI <-> (RX) channel conversions **********/
514 /* RX channels are 10 bit integers, these fns are quite paranoid */
516 static inline int channel_to_vpivci (const u16 channel
, short * vpi
, int * vci
) {
517 unsigned short vci_bits
= 10 - vpi_bits
;
518 if ((channel
& RX_CHANNEL_MASK
) == channel
) {
519 *vci
= channel
& ((~0)<<vci_bits
);
520 *vpi
= channel
>> vci_bits
;
521 return channel
? 0 : -EINVAL
;
526 static inline int vpivci_to_channel (u16
* channel
, const short vpi
, const int vci
) {
527 unsigned short vci_bits
= 10 - vpi_bits
;
528 if (0 <= vpi
&& vpi
< 1<<vpi_bits
&& 0 <= vci
&& vci
< 1<<vci_bits
) {
529 *channel
= vpi
<<vci_bits
| vci
;
530 return *channel
? 0 : -EINVAL
;
535 /********** decode RX queue entries **********/
537 static inline u16
rx_q_entry_to_length (u32 x
) {
538 return x
& RX_Q_ENTRY_LENGTH_MASK
;
541 static inline u16
rx_q_entry_to_rx_channel (u32 x
) {
542 return (x
>>RX_Q_ENTRY_CHANNEL_SHIFT
) & RX_CHANNEL_MASK
;
545 /* Cell Transmit Rate Values
547 * the cell transmit rate (cells per sec) can be set to a variety of
548 * different values by specifying two parameters: a timer preload from
549 * 1 to 16 (stored as 0 to 15) and a clock divider (2 to the power of
550 * an exponent from 0 to 14; the special value 15 disables the timer).
552 * cellrate = baserate / (preload * 2^divider)
554 * The maximum cell rate that can be specified is therefore just the
555 * base rate. Halving the preload is equivalent to adding 1 to the
556 * divider and so values 1 to 8 of the preload are redundant except
557 * in the case of a maximal divider (14).
559 * Given a desired cell rate, an algorithm to determine the preload
562 * a) x = baserate / cellrate, want p * 2^d = x (as far as possible)
563 * b) if x > 16 * 2^14 then set p = 16, d = 14 (min rate), done
564 * if x <= 16 then set p = x, d = 0 (high rates), done
565 * c) now have 16 < x <= 2^18, or 1 < x/16 <= 2^14 and we want to
566 * know n such that 2^(n-1) < x/16 <= 2^n, so slide a bit until
567 * we find the range (n will be between 1 and 14), set d = n
568 * d) Also have 8 < x/2^n <= 16, so set p nearest x/2^n
570 * The algorithm used below is a minor variant of the above.
572 * The base rate is derived from the oscillator frequency (Hz) using a
575 * baserate = freq / 32 in the case of some Unknown Card
576 * baserate = freq / 8 in the case of the Horizon 25
577 * baserate = freq / 8 in the case of the Horizon Ultra 155
579 * The Horizon cards have oscillators and base rates as follows:
581 * Card Oscillator Base Rate
582 * Unknown Card 33 MHz 1.03125 MHz (33 MHz = PCI freq)
583 * Horizon 25 32 MHz 4 MHz
584 * Horizon Ultra 155 40 MHz 5 MHz
586 * The following defines give the base rates in Hz. These were
587 * previously a factor of 100 larger, no doubt someone was using
591 #define BR_UKN 1031250l
592 #define BR_HRZ 4000000l
593 #define BR_ULT 5000000l
599 // p ranges from 1 to a power of 2
602 static int make_rate (const hrz_dev
* dev
, u32 c
, rounding r
,
603 u16
* bits
, unsigned int * actual
)
605 // note: rounding the rate down means rounding 'p' up
606 const unsigned long br
= test_bit(ultra
, &dev
->flags
) ? BR_ULT
: BR_HRZ
;
611 // br_exp and br_man are used to avoid overflowing (c*maxp*2^d) in
612 // the tests below. We could think harder about exact possibilities
615 unsigned long br_man
= br
;
616 unsigned int br_exp
= 0;
618 PRINTD (DBG_QOS
|DBG_FLOW
, "make_rate b=%lu, c=%u, %s", br
, c
,
619 r
== round_up
? "up" : r
== round_down
? "down" : "nearest");
623 PRINTD (DBG_QOS
|DBG_ERR
, "zero rate is not allowed!");
627 while (br_exp
< CR_MAXPEXP
+ CR_MIND
&& (br_man
% 2 == 0)) {
628 br_man
= br_man
>> 1;
631 // (br >>br_exp) <<br_exp == br and
632 // br_exp <= CR_MAXPEXP+CR_MIND
634 if (br_man
<= (c
<< (CR_MAXPEXP
+CR_MIND
-br_exp
))) {
635 // Equivalent to: B <= (c << (MAXPEXP+MIND))
636 // take care of rounding
639 pre
= DIV_ROUND_UP(br
, c
<<div
);
640 // but p must be non-zero
645 pre
= DIV_ROUND_CLOSEST(br
, c
<<div
);
646 // but p must be non-zero
650 default: /* round_up */
652 // but p must be non-zero
656 PRINTD (DBG_QOS
, "A: p=%u, d=%u", pre
, div
);
660 // at this point we have
661 // d == MIND and (c << (MAXPEXP+MIND)) < B
662 while (div
< CR_MAXD
) {
664 if (br_man
<= (c
<< (CR_MAXPEXP
+div
-br_exp
))) {
665 // Equivalent to: B <= (c << (MAXPEXP+d))
666 // c << (MAXPEXP+d-1) < B <= c << (MAXPEXP+d)
667 // 1 << (MAXPEXP-1) < B/2^d/c <= 1 << MAXPEXP
668 // MAXP/2 < B/c2^d <= MAXP
669 // take care of rounding
672 pre
= DIV_ROUND_UP(br
, c
<<div
);
675 pre
= DIV_ROUND_CLOSEST(br
, c
<<div
);
677 default: /* round_up */
680 PRINTD (DBG_QOS
, "B: p=%u, d=%u", pre
, div
);
684 // at this point we have
685 // d == MAXD and (c << (MAXPEXP+MAXD)) < B
686 // but we cannot go any higher
687 // take care of rounding
690 pre
= 1 << CR_MAXPEXP
;
691 PRINTD (DBG_QOS
, "C: p=%u, d=%u", pre
, div
);
694 if (div
> CR_MAXD
|| (!pre
) || pre
> 1<<CR_MAXPEXP
) {
695 PRINTD (DBG_QOS
, "set_cr internal failure: d=%u p=%u",
700 *bits
= (div
<<CLOCK_SELECT_SHIFT
) | (pre
-1);
702 *actual
= DIV_ROUND_UP(br
, pre
<<div
);
703 PRINTD (DBG_QOS
, "actual rate: %u", *actual
);
709 static int make_rate_with_tolerance (const hrz_dev
* dev
, u32 c
, rounding r
, unsigned int tol
,
710 u16
* bit_pattern
, unsigned int * actual
) {
711 unsigned int my_actual
;
713 PRINTD (DBG_QOS
|DBG_FLOW
, "make_rate_with_tolerance c=%u, %s, tol=%u",
714 c
, (r
== round_up
) ? "up" : (r
== round_down
) ? "down" : "nearest", tol
);
717 // actual rate is not returned
720 if (make_rate (dev
, c
, round_nearest
, bit_pattern
, actual
))
721 // should never happen as round_nearest always succeeds
724 if (c
- tol
<= *actual
&& *actual
<= c
+ tol
)
728 // intolerant, try rounding instead
729 return make_rate (dev
, c
, r
, bit_pattern
, actual
);
732 /********** Listen on a VC **********/
734 static int hrz_open_rx (hrz_dev
* dev
, u16 channel
) {
735 // is there any guarantee that we don't get two simulataneous
736 // identical calls of this function from different processes? yes
739 u32 channel_type
; // u16?
741 u16 buf_ptr
= RX_CHANNEL_IDLE
;
743 rx_ch_desc
* rx_desc
= &memmap
->rx_descs
[channel
];
745 PRINTD (DBG_FLOW
, "hrz_open_rx %x", channel
);
747 spin_lock_irqsave (&dev
->mem_lock
, flags
);
748 channel_type
= rd_mem (dev
, &rx_desc
->wr_buf_type
) & BUFFER_PTR_MASK
;
749 spin_unlock_irqrestore (&dev
->mem_lock
, flags
);
751 // very serious error, should never occur
752 if (channel_type
!= RX_CHANNEL_DISABLED
) {
753 PRINTD (DBG_ERR
|DBG_VCC
, "RX channel for VC already open");
754 return -EBUSY
; // clean up?
757 // Give back spare buffer
758 if (dev
->noof_spare_buffers
) {
759 buf_ptr
= dev
->spare_buffers
[--dev
->noof_spare_buffers
];
760 PRINTD (DBG_VCC
, "using a spare buffer: %u", buf_ptr
);
761 // should never occur
762 if (buf_ptr
== RX_CHANNEL_DISABLED
|| buf_ptr
== RX_CHANNEL_IDLE
) {
763 // but easy to recover from
764 PRINTD (DBG_ERR
|DBG_VCC
, "bad spare buffer pointer, using IDLE");
765 buf_ptr
= RX_CHANNEL_IDLE
;
768 PRINTD (DBG_VCC
, "using IDLE buffer pointer");
771 // Channel is currently disabled so change its status to idle
773 // do we really need to save the flags again?
774 spin_lock_irqsave (&dev
->mem_lock
, flags
);
776 wr_mem (dev
, &rx_desc
->wr_buf_type
,
777 buf_ptr
| CHANNEL_TYPE_AAL5
| FIRST_CELL_OF_AAL5_FRAME
);
778 if (buf_ptr
!= RX_CHANNEL_IDLE
)
779 wr_mem (dev
, &rx_desc
->rd_buf_type
, buf_ptr
);
781 spin_unlock_irqrestore (&dev
->mem_lock
, flags
);
783 // rxer->rate = make_rate (qos->peak_cells);
785 PRINTD (DBG_FLOW
, "hrz_open_rx ok");
791 /********** change vc rate for a given vc **********/
793 static void hrz_change_vc_qos (ATM_RXER
* rxer
, MAAL_QOS
* qos
) {
794 rxer
->rate
= make_rate (qos
->peak_cells
);
798 /********** free an skb (as per ATM device driver documentation) **********/
800 static void hrz_kfree_skb (struct sk_buff
* skb
) {
801 if (ATM_SKB(skb
)->vcc
->pop
) {
802 ATM_SKB(skb
)->vcc
->pop (ATM_SKB(skb
)->vcc
, skb
);
804 dev_kfree_skb_any (skb
);
808 /********** cancel listen on a VC **********/
810 static void hrz_close_rx (hrz_dev
* dev
, u16 vc
) {
817 rx_ch_desc
* rx_desc
= &memmap
->rx_descs
[vc
];
821 spin_lock_irqsave (&dev
->mem_lock
, flags
);
822 value
= rd_mem (dev
, &rx_desc
->wr_buf_type
) & BUFFER_PTR_MASK
;
823 spin_unlock_irqrestore (&dev
->mem_lock
, flags
);
825 if (value
== RX_CHANNEL_DISABLED
) {
826 // I suppose this could happen once we deal with _NONE traffic properly
827 PRINTD (DBG_VCC
, "closing VC: RX channel %u already disabled", vc
);
830 if (value
== RX_CHANNEL_IDLE
)
833 spin_lock_irqsave (&dev
->mem_lock
, flags
);
836 wr_mem (dev
, &rx_desc
->wr_buf_type
, RX_CHANNEL_DISABLED
);
838 if ((rd_mem (dev
, &rx_desc
->wr_buf_type
) & BUFFER_PTR_MASK
) == RX_CHANNEL_DISABLED
)
845 spin_unlock_irqrestore (&dev
->mem_lock
, flags
);
849 WAIT_FLUSH_RX_COMPLETE(dev
);
851 // XXX Is this all really necessary? We can rely on the rx_data_av
852 // handler to discard frames that remain queued for delivery. If the
853 // worry is that immediately reopening the channel (perhaps by a
854 // different process) may cause some data to be mis-delivered then
855 // there may still be a simpler solution (such as busy-waiting on
856 // rx_busy once the channel is disabled or before a new one is
857 // opened - does this leave any holes?). Arguably setting up and
858 // tearing down the TX and RX halves of each virtual circuit could
859 // most safely be done within ?x_busy protected regions.
861 // OK, current changes are that Simon's marker is disabled and we DO
862 // look for NULL rxer elsewhere. The code here seems flush frames
863 // and then remember the last dead cell belonging to the channel
864 // just disabled - the cell gets relinked at the next vc_open.
865 // However, when all VCs are closed or only a few opened there are a
866 // handful of buffers that are unusable.
868 // Does anyone feel like documenting spare_buffers properly?
869 // Does anyone feel like fixing this in a nicer way?
871 // Flush any data which is left in the channel
873 // Change the rx channel port to something different to the RX
874 // channel we are trying to close to force Horizon to flush the rx
875 // channel read and write pointers.
877 u16 other
= vc
^(RX_CHANS
/2);
879 SELECT_RX_CHANNEL (dev
, other
);
880 WAIT_UPDATE_COMPLETE (dev
);
882 r1
= rd_mem (dev
, &rx_desc
->rd_buf_type
);
884 // Select this RX channel. Flush doesn't seem to work unless we
885 // select an RX channel before hand
887 SELECT_RX_CHANNEL (dev
, vc
);
888 WAIT_UPDATE_COMPLETE (dev
);
890 // Attempt to flush a frame on this RX channel
892 FLUSH_RX_CHANNEL (dev
, vc
);
893 WAIT_FLUSH_RX_COMPLETE (dev
);
895 // Force Horizon to flush rx channel read and write pointers as before
897 SELECT_RX_CHANNEL (dev
, other
);
898 WAIT_UPDATE_COMPLETE (dev
);
900 r2
= rd_mem (dev
, &rx_desc
->rd_buf_type
);
902 PRINTD (DBG_VCC
|DBG_RX
, "r1 = %u, r2 = %u", r1
, r2
);
905 dev
->spare_buffers
[dev
->noof_spare_buffers
++] = (u16
)r1
;
912 rx_q_entry
* wr_ptr
= &memmap
->rx_q_entries
[rd_regw (dev
, RX_QUEUE_WR_PTR_OFF
)];
913 rx_q_entry
* rd_ptr
= dev
->rx_q_entry
;
915 PRINTD (DBG_VCC
|DBG_RX
, "rd_ptr = %u, wr_ptr = %u", rd_ptr
, wr_ptr
);
917 while (rd_ptr
!= wr_ptr
) {
918 u32 x
= rd_mem (dev
, (HDW
*) rd_ptr
);
920 if (vc
== rx_q_entry_to_rx_channel (x
)) {
921 x
|= SIMONS_DODGEY_MARKER
;
923 PRINTD (DBG_RX
|DBG_VCC
|DBG_WARN
, "marking a frame as dodgey");
925 wr_mem (dev
, (HDW
*) rd_ptr
, x
);
928 if (rd_ptr
== dev
->rx_q_wrap
)
929 rd_ptr
= dev
->rx_q_reset
;
936 spin_unlock_irqrestore (&dev
->mem_lock
, flags
);
941 /********** schedule RX transfers **********/
943 // Note on tail recursion: a GCC developer said that it is not likely
944 // to be fixed soon, so do not define TAILRECUSRIONWORKS unless you
945 // are sure it does as you may otherwise overflow the kernel stack.
947 // giving this fn a return value would help GCC, alledgedly
949 static void rx_schedule (hrz_dev
* dev
, int irq
) {
950 unsigned int rx_bytes
;
953 #ifndef TAILRECURSIONWORKS
955 while (pio_instead
) {
957 // bytes waiting for RX transfer
958 rx_bytes
= dev
->rx_bytes
;
962 while (rd_regl (dev
, MASTER_RX_COUNT_REG_OFF
)) {
963 PRINTD (DBG_RX
|DBG_WARN
, "RX error: other PCI Bus Master RX still in progress!");
964 if (++spin_count
> 10) {
965 PRINTD (DBG_RX
|DBG_ERR
, "spun out waiting PCI Bus Master RX completion");
966 wr_regl (dev
, MASTER_RX_COUNT_REG_OFF
, 0);
967 clear_bit (rx_busy
, &dev
->flags
);
968 hrz_kfree_skb (dev
->rx_skb
);
974 // this code follows the TX code but (at the moment) there is only
975 // one region - the skb itself. I don't know if this will change,
976 // but it doesn't hurt to have the code here, disabled.
979 // start next transfer within same region
980 if (rx_bytes
<= MAX_PIO_COUNT
) {
981 PRINTD (DBG_RX
|DBG_BUS
, "(pio)");
984 if (rx_bytes
<= MAX_TRANSFER_COUNT
) {
985 PRINTD (DBG_RX
|DBG_BUS
, "(simple or last multi)");
988 PRINTD (DBG_RX
|DBG_BUS
, "(continuing multi)");
989 dev
->rx_bytes
= rx_bytes
- MAX_TRANSFER_COUNT
;
990 rx_bytes
= MAX_TRANSFER_COUNT
;
993 // rx_bytes == 0 -- we're between regions
994 // regions remaining to transfer
996 unsigned int rx_regions
= dev
->rx_regions
;
998 unsigned int rx_regions
= 0;
1003 // start a new region
1004 dev
->rx_addr
= dev
->rx_iovec
->iov_base
;
1005 rx_bytes
= dev
->rx_iovec
->iov_len
;
1007 dev
->rx_regions
= rx_regions
- 1;
1009 if (rx_bytes
<= MAX_PIO_COUNT
) {
1010 PRINTD (DBG_RX
|DBG_BUS
, "(pio)");
1013 if (rx_bytes
<= MAX_TRANSFER_COUNT
) {
1014 PRINTD (DBG_RX
|DBG_BUS
, "(full region)");
1017 PRINTD (DBG_RX
|DBG_BUS
, "(start multi region)");
1018 dev
->rx_bytes
= rx_bytes
- MAX_TRANSFER_COUNT
;
1019 rx_bytes
= MAX_TRANSFER_COUNT
;
1024 // that's all folks - end of frame
1025 struct sk_buff
* skb
= dev
->rx_skb
;
1026 // dev->rx_iovec = 0;
1028 FLUSH_RX_CHANNEL (dev
, dev
->rx_channel
);
1030 dump_skb ("<<<", dev
->rx_channel
, skb
);
1032 PRINTD (DBG_RX
|DBG_SKB
, "push %p %u", skb
->data
, skb
->len
);
1035 struct atm_vcc
* vcc
= ATM_SKB(skb
)->vcc
;
1037 atomic_inc(&vcc
->stats
->rx
);
1038 __net_timestamp(skb
);
1039 // end of our responsability
1040 vcc
->push (vcc
, skb
);
1045 // note: writing RX_COUNT clears any interrupt condition
1049 wr_regl (dev
, MASTER_RX_COUNT_REG_OFF
, 0);
1050 rds_regb (dev
, DATA_PORT_OFF
, dev
->rx_addr
, rx_bytes
);
1052 wr_regl (dev
, MASTER_RX_ADDR_REG_OFF
, virt_to_bus (dev
->rx_addr
));
1053 wr_regl (dev
, MASTER_RX_COUNT_REG_OFF
, rx_bytes
);
1055 dev
->rx_addr
+= rx_bytes
;
1058 wr_regl (dev
, MASTER_RX_COUNT_REG_OFF
, 0);
1059 // allow another RX thread to start
1061 clear_bit (rx_busy
, &dev
->flags
);
1062 PRINTD (DBG_RX
, "cleared rx_busy for dev %p", dev
);
1065 #ifdef TAILRECURSIONWORKS
1066 // and we all bless optimised tail calls
1068 return rx_schedule (dev
, 0);
1078 /********** handle RX bus master complete events **********/
1080 static void rx_bus_master_complete_handler (hrz_dev
* dev
) {
1081 if (test_bit (rx_busy
, &dev
->flags
)) {
1082 rx_schedule (dev
, 1);
1084 PRINTD (DBG_RX
|DBG_ERR
, "unexpected RX bus master completion");
1085 // clear interrupt condition on adapter
1086 wr_regl (dev
, MASTER_RX_COUNT_REG_OFF
, 0);
1091 /********** (queue to) become the next TX thread **********/
1093 static int tx_hold (hrz_dev
* dev
) {
1094 PRINTD (DBG_TX
, "sleeping at tx lock %p %lu", dev
, dev
->flags
);
1095 wait_event_interruptible(dev
->tx_queue
, (!test_and_set_bit(tx_busy
, &dev
->flags
)));
1096 PRINTD (DBG_TX
, "woken at tx lock %p %lu", dev
, dev
->flags
);
1097 if (signal_pending (current
))
1099 PRINTD (DBG_TX
, "set tx_busy for dev %p", dev
);
1103 /********** allow another TX thread to start **********/
1105 static inline void tx_release (hrz_dev
* dev
) {
1106 clear_bit (tx_busy
, &dev
->flags
);
1107 PRINTD (DBG_TX
, "cleared tx_busy for dev %p", dev
);
1108 wake_up_interruptible (&dev
->tx_queue
);
1111 /********** schedule TX transfers **********/
1113 static void tx_schedule (hrz_dev
* const dev
, int irq
) {
1114 unsigned int tx_bytes
;
1116 int append_desc
= 0;
1118 int pio_instead
= 0;
1119 #ifndef TAILRECURSIONWORKS
1121 while (pio_instead
) {
1123 // bytes in current region waiting for TX transfer
1124 tx_bytes
= dev
->tx_bytes
;
1128 while (rd_regl (dev
, MASTER_TX_COUNT_REG_OFF
)) {
1129 PRINTD (DBG_TX
|DBG_WARN
, "TX error: other PCI Bus Master TX still in progress!");
1130 if (++spin_count
> 10) {
1131 PRINTD (DBG_TX
|DBG_ERR
, "spun out waiting PCI Bus Master TX completion");
1132 wr_regl (dev
, MASTER_TX_COUNT_REG_OFF
, 0);
1134 hrz_kfree_skb (dev
->tx_skb
);
1141 // start next transfer within same region
1142 if (!test_bit (ultra
, &dev
->flags
) || tx_bytes
<= MAX_PIO_COUNT
) {
1143 PRINTD (DBG_TX
|DBG_BUS
, "(pio)");
1146 if (tx_bytes
<= MAX_TRANSFER_COUNT
) {
1147 PRINTD (DBG_TX
|DBG_BUS
, "(simple or last multi)");
1148 if (!dev
->tx_iovec
) {
1149 // end of last region
1154 PRINTD (DBG_TX
|DBG_BUS
, "(continuing multi)");
1155 dev
->tx_bytes
= tx_bytes
- MAX_TRANSFER_COUNT
;
1156 tx_bytes
= MAX_TRANSFER_COUNT
;
1159 // tx_bytes == 0 -- we're between regions
1160 // regions remaining to transfer
1161 unsigned int tx_regions
= dev
->tx_regions
;
1164 // start a new region
1165 dev
->tx_addr
= dev
->tx_iovec
->iov_base
;
1166 tx_bytes
= dev
->tx_iovec
->iov_len
;
1168 dev
->tx_regions
= tx_regions
- 1;
1170 if (!test_bit (ultra
, &dev
->flags
) || tx_bytes
<= MAX_PIO_COUNT
) {
1171 PRINTD (DBG_TX
|DBG_BUS
, "(pio)");
1174 if (tx_bytes
<= MAX_TRANSFER_COUNT
) {
1175 PRINTD (DBG_TX
|DBG_BUS
, "(full region)");
1178 PRINTD (DBG_TX
|DBG_BUS
, "(start multi region)");
1179 dev
->tx_bytes
= tx_bytes
- MAX_TRANSFER_COUNT
;
1180 tx_bytes
= MAX_TRANSFER_COUNT
;
1184 // that's all folks - end of frame
1185 struct sk_buff
* skb
= dev
->tx_skb
;
1186 dev
->tx_iovec
= NULL
;
1189 atomic_inc(&ATM_SKB(skb
)->vcc
->stats
->tx
);
1192 hrz_kfree_skb (skb
);
1196 // note: writing TX_COUNT clears any interrupt condition
1200 wr_regl (dev
, MASTER_TX_COUNT_REG_OFF
, 0);
1201 wrs_regb (dev
, DATA_PORT_OFF
, dev
->tx_addr
, tx_bytes
);
1203 wr_regl (dev
, TX_DESCRIPTOR_PORT_OFF
, cpu_to_be32 (dev
->tx_skb
->len
));
1205 wr_regl (dev
, MASTER_TX_ADDR_REG_OFF
, virt_to_bus (dev
->tx_addr
));
1207 wr_regl (dev
, TX_DESCRIPTOR_REG_OFF
, cpu_to_be32 (dev
->tx_skb
->len
));
1208 wr_regl (dev
, MASTER_TX_COUNT_REG_OFF
,
1210 ? tx_bytes
| MASTER_TX_AUTO_APPEND_DESC
1213 dev
->tx_addr
+= tx_bytes
;
1216 wr_regl (dev
, MASTER_TX_COUNT_REG_OFF
, 0);
1221 #ifdef TAILRECURSIONWORKS
1222 // and we all bless optimised tail calls
1224 return tx_schedule (dev
, 0);
1234 /********** handle TX bus master complete events **********/
1236 static void tx_bus_master_complete_handler (hrz_dev
* dev
) {
1237 if (test_bit (tx_busy
, &dev
->flags
)) {
1238 tx_schedule (dev
, 1);
1240 PRINTD (DBG_TX
|DBG_ERR
, "unexpected TX bus master completion");
1241 // clear interrupt condition on adapter
1242 wr_regl (dev
, MASTER_TX_COUNT_REG_OFF
, 0);
1247 /********** move RX Q pointer to next item in circular buffer **********/
1249 // called only from IRQ sub-handler
1250 static u32
rx_queue_entry_next (hrz_dev
* dev
) {
1252 spin_lock (&dev
->mem_lock
);
1253 rx_queue_entry
= rd_mem (dev
, &dev
->rx_q_entry
->entry
);
1254 if (dev
->rx_q_entry
== dev
->rx_q_wrap
)
1255 dev
->rx_q_entry
= dev
->rx_q_reset
;
1258 wr_regw (dev
, RX_QUEUE_RD_PTR_OFF
, dev
->rx_q_entry
- dev
->rx_q_reset
);
1259 spin_unlock (&dev
->mem_lock
);
1260 return rx_queue_entry
;
1263 /********** handle RX disabled by device **********/
1265 static inline void rx_disabled_handler (hrz_dev
* dev
) {
1266 wr_regw (dev
, RX_CONFIG_OFF
, rd_regw (dev
, RX_CONFIG_OFF
) | RX_ENABLE
);
1268 PRINTK (KERN_WARNING
, "RX was disabled!");
1271 /********** handle RX data received by device **********/
1273 // called from IRQ handler
1274 static void rx_data_av_handler (hrz_dev
* dev
) {
1276 u32 rx_queue_entry_flags
;
1280 PRINTD (DBG_FLOW
, "hrz_data_av_handler");
1282 // try to grab rx lock (not possible during RX bus mastering)
1283 if (test_and_set_bit (rx_busy
, &dev
->flags
)) {
1284 PRINTD (DBG_RX
, "locked out of rx lock");
1287 PRINTD (DBG_RX
, "set rx_busy for dev %p", dev
);
1288 // lock is cleared if we fail now, o/w after bus master completion
1290 YELLOW_LED_OFF(dev
);
1292 rx_queue_entry
= rx_queue_entry_next (dev
);
1294 rx_len
= rx_q_entry_to_length (rx_queue_entry
);
1295 rx_channel
= rx_q_entry_to_rx_channel (rx_queue_entry
);
1297 WAIT_FLUSH_RX_COMPLETE (dev
);
1299 SELECT_RX_CHANNEL (dev
, rx_channel
);
1301 PRINTD (DBG_RX
, "rx_queue_entry is: %#x", rx_queue_entry
);
1302 rx_queue_entry_flags
= rx_queue_entry
& (RX_CRC_32_OK
|RX_COMPLETE_FRAME
|SIMONS_DODGEY_MARKER
);
1305 // (at least) bus-mastering breaks if we try to handle a
1306 // zero-length frame, besides AAL5 does not support them
1307 PRINTK (KERN_ERR
, "zero-length frame!");
1308 rx_queue_entry_flags
&= ~RX_COMPLETE_FRAME
;
1311 if (rx_queue_entry_flags
& SIMONS_DODGEY_MARKER
) {
1312 PRINTD (DBG_RX
|DBG_ERR
, "Simon's marker detected!");
1314 if (rx_queue_entry_flags
== (RX_CRC_32_OK
| RX_COMPLETE_FRAME
)) {
1315 struct atm_vcc
* atm_vcc
;
1317 PRINTD (DBG_RX
, "got a frame on rx_channel %x len %u", rx_channel
, rx_len
);
1319 atm_vcc
= dev
->rxer
[rx_channel
];
1320 // if no vcc is assigned to this channel, we should drop the frame
1321 // (is this what SIMONS etc. was trying to achieve?)
1325 if (atm_vcc
->qos
.rxtp
.traffic_class
!= ATM_NONE
) {
1327 if (rx_len
<= atm_vcc
->qos
.rxtp
.max_sdu
) {
1329 struct sk_buff
* skb
= atm_alloc_charge (atm_vcc
, rx_len
, GFP_ATOMIC
);
1331 // remember this so we can push it later
1333 // remember this so we can flush it later
1334 dev
->rx_channel
= rx_channel
;
1336 // prepare socket buffer
1337 skb_put (skb
, rx_len
);
1338 ATM_SKB(skb
)->vcc
= atm_vcc
;
1341 // dev->rx_regions = 0;
1342 // dev->rx_iovec = 0;
1343 dev
->rx_bytes
= rx_len
;
1344 dev
->rx_addr
= skb
->data
;
1345 PRINTD (DBG_RX
, "RX start simple transfer (addr %p, len %d)",
1349 rx_schedule (dev
, 0);
1353 PRINTD (DBG_SKB
|DBG_WARN
, "failed to get skb");
1357 PRINTK (KERN_INFO
, "frame received on TX-only VC %x", rx_channel
);
1358 // do we count this?
1362 PRINTK (KERN_WARNING
, "dropped over-size frame");
1363 // do we count this?
1367 PRINTD (DBG_WARN
|DBG_VCC
|DBG_RX
, "no VCC for this frame (VC closed)");
1368 // do we count this?
1372 // Wait update complete ? SPONG
1378 FLUSH_RX_CHANNEL (dev
,rx_channel
);
1379 clear_bit (rx_busy
, &dev
->flags
);
1384 /********** interrupt handler **********/
1386 static irqreturn_t
interrupt_handler(int irq
, void *dev_id
)
1388 hrz_dev
*dev
= dev_id
;
1390 unsigned int irq_ok
;
1392 PRINTD (DBG_FLOW
, "interrupt_handler: %p", dev_id
);
1394 // definitely for us
1396 while ((int_source
= rd_regl (dev
, INT_SOURCE_REG_OFF
)
1397 & INTERESTING_INTERRUPTS
)) {
1398 // In the interests of fairness, the handlers below are
1399 // called in sequence and without immediate return to the head of
1400 // the while loop. This is only of issue for slow hosts (or when
1401 // debugging messages are on). Really slow hosts may find a fast
1402 // sender keeps them permanently in the IRQ handler. :(
1404 // (only an issue for slow hosts) RX completion goes before
1405 // rx_data_av as the former implies rx_busy and so the latter
1406 // would just abort. If it reschedules another transfer
1407 // (continuing the same frame) then it will not clear rx_busy.
1409 // (only an issue for slow hosts) TX completion goes before RX
1410 // data available as it is a much shorter routine - there is the
1411 // chance that any further transfers it schedules will be complete
1412 // by the time of the return to the head of the while loop
1414 if (int_source
& RX_BUS_MASTER_COMPLETE
) {
1416 PRINTD (DBG_IRQ
|DBG_BUS
|DBG_RX
, "rx_bus_master_complete asserted");
1417 rx_bus_master_complete_handler (dev
);
1419 if (int_source
& TX_BUS_MASTER_COMPLETE
) {
1421 PRINTD (DBG_IRQ
|DBG_BUS
|DBG_TX
, "tx_bus_master_complete asserted");
1422 tx_bus_master_complete_handler (dev
);
1424 if (int_source
& RX_DATA_AV
) {
1426 PRINTD (DBG_IRQ
|DBG_RX
, "rx_data_av asserted");
1427 rx_data_av_handler (dev
);
1431 PRINTD (DBG_IRQ
, "work done: %u", irq_ok
);
1433 PRINTD (DBG_IRQ
|DBG_WARN
, "spurious interrupt source: %#x", int_source
);
1436 PRINTD (DBG_IRQ
|DBG_FLOW
, "interrupt_handler done: %p", dev_id
);
1442 /********** housekeeping **********/
1444 static void do_housekeeping (unsigned long arg
) {
1445 // just stats at the moment
1446 hrz_dev
* dev
= (hrz_dev
*) arg
;
1448 // collect device-specific (not driver/atm-linux) stats here
1449 dev
->tx_cell_count
+= rd_regw (dev
, TX_CELL_COUNT_OFF
);
1450 dev
->rx_cell_count
+= rd_regw (dev
, RX_CELL_COUNT_OFF
);
1451 dev
->hec_error_count
+= rd_regw (dev
, HEC_ERROR_COUNT_OFF
);
1452 dev
->unassigned_cell_count
+= rd_regw (dev
, UNASSIGNED_CELL_COUNT_OFF
);
1454 mod_timer (&dev
->housekeeping
, jiffies
+ HZ
/10);
1459 /********** find an idle channel for TX and set it up **********/
1461 // called with tx_busy set
1462 static short setup_idle_tx_channel (hrz_dev
* dev
, hrz_vcc
* vcc
) {
1463 unsigned short idle_channels
;
1464 short tx_channel
= -1;
1465 unsigned int spin_count
;
1466 PRINTD (DBG_FLOW
|DBG_TX
, "setup_idle_tx_channel %p", dev
);
1468 // better would be to fail immediately, the caller can then decide whether
1469 // to wait or drop (depending on whether this is UBR etc.)
1471 while (!(idle_channels
= rd_regw (dev
, TX_STATUS_OFF
) & IDLE_CHANNELS_MASK
)) {
1472 PRINTD (DBG_TX
|DBG_WARN
, "waiting for idle TX channel");
1474 if (++spin_count
> 100) {
1475 PRINTD (DBG_TX
|DBG_ERR
, "spun out waiting for idle TX channel");
1480 // got an idle channel
1482 // tx_idle ensures we look for idle channels in RR order
1483 int chan
= dev
->tx_idle
;
1486 while (keep_going
) {
1487 if (idle_channels
& (1<<chan
)) {
1492 if (chan
== TX_CHANS
)
1496 dev
->tx_idle
= chan
;
1499 // set up the channel we found
1501 // Initialise the cell header in the transmit channel descriptor
1502 // a.k.a. prepare the channel and remember that we have done so.
1504 tx_ch_desc
* tx_desc
= &memmap
->tx_descs
[tx_channel
];
1507 u16 channel
= vcc
->channel
;
1509 unsigned long flags
;
1510 spin_lock_irqsave (&dev
->mem_lock
, flags
);
1512 // Update the transmit channel record.
1513 dev
->tx_channel_record
[tx_channel
] = channel
;
1516 update_tx_channel_config (dev
, tx_channel
, RATE_TYPE_ACCESS
,
1519 // Update the PCR counter preload value etc.
1520 update_tx_channel_config (dev
, tx_channel
, PCR_TIMER_ACCESS
,
1524 if (vcc
->tx_xbr_bits
== VBR_RATE_TYPE
) {
1526 update_tx_channel_config (dev
, tx_channel
, SCR_TIMER_ACCESS
,
1530 update_tx_channel_config (dev
, tx_channel
, BUCKET_CAPACITY_ACCESS
,
1531 vcc
->tx_bucket_bits
);
1534 update_tx_channel_config (dev
, tx_channel
, BUCKET_FULLNESS_ACCESS
,
1535 vcc
->tx_bucket_bits
);
1539 // Initialise the read and write buffer pointers
1540 rd_ptr
= rd_mem (dev
, &tx_desc
->rd_buf_type
) & BUFFER_PTR_MASK
;
1541 wr_ptr
= rd_mem (dev
, &tx_desc
->wr_buf_type
) & BUFFER_PTR_MASK
;
1543 // idle TX channels should have identical pointers
1544 if (rd_ptr
!= wr_ptr
) {
1545 PRINTD (DBG_TX
|DBG_ERR
, "TX buffer pointers are broken!");
1546 // spin_unlock... return -E...
1547 // I wonder if gcc would get rid of one of the pointer aliases
1549 PRINTD (DBG_TX
, "TX buffer pointers are: rd %x, wr %x.",
1554 PRINTD (DBG_QOS
|DBG_TX
, "tx_channel: aal0");
1555 rd_ptr
|= CHANNEL_TYPE_RAW_CELLS
;
1556 wr_ptr
|= CHANNEL_TYPE_RAW_CELLS
;
1559 PRINTD (DBG_QOS
|DBG_TX
, "tx_channel: aal34");
1560 rd_ptr
|= CHANNEL_TYPE_AAL3_4
;
1561 wr_ptr
|= CHANNEL_TYPE_AAL3_4
;
1564 rd_ptr
|= CHANNEL_TYPE_AAL5
;
1565 wr_ptr
|= CHANNEL_TYPE_AAL5
;
1566 // Initialise the CRC
1567 wr_mem (dev
, &tx_desc
->partial_crc
, INITIAL_CRC
);
1571 wr_mem (dev
, &tx_desc
->rd_buf_type
, rd_ptr
);
1572 wr_mem (dev
, &tx_desc
->wr_buf_type
, wr_ptr
);
1574 // Write the Cell Header
1575 // Payload Type, CLP and GFC would go here if non-zero
1576 wr_mem (dev
, &tx_desc
->cell_header
, channel
);
1578 spin_unlock_irqrestore (&dev
->mem_lock
, flags
);
1584 /********** send a frame **********/
1586 static int hrz_send (struct atm_vcc
* atm_vcc
, struct sk_buff
* skb
) {
1587 unsigned int spin_count
;
1589 hrz_dev
* dev
= HRZ_DEV(atm_vcc
->dev
);
1590 hrz_vcc
* vcc
= HRZ_VCC(atm_vcc
);
1591 u16 channel
= vcc
->channel
;
1593 u32 buffers_required
;
1595 /* signed for error return */
1598 PRINTD (DBG_FLOW
|DBG_TX
, "hrz_send vc %x data %p len %u",
1599 channel
, skb
->data
, skb
->len
);
1601 dump_skb (">>>", channel
, skb
);
1603 if (atm_vcc
->qos
.txtp
.traffic_class
== ATM_NONE
) {
1604 PRINTK (KERN_ERR
, "attempt to send on RX-only VC %x", channel
);
1605 hrz_kfree_skb (skb
);
1609 // don't understand this
1610 ATM_SKB(skb
)->vcc
= atm_vcc
;
1612 if (skb
->len
> atm_vcc
->qos
.txtp
.max_sdu
) {
1613 PRINTK (KERN_ERR
, "sk_buff length greater than agreed max_sdu, dropping...");
1614 hrz_kfree_skb (skb
);
1619 PRINTD (DBG_ERR
|DBG_TX
, "attempt to transmit on zero (rx_)channel");
1620 hrz_kfree_skb (skb
);
1626 // where would be a better place for this? housekeeping?
1628 pci_read_config_word (dev
->pci_dev
, PCI_STATUS
, &status
);
1629 if (status
& PCI_STATUS_REC_MASTER_ABORT
) {
1630 PRINTD (DBG_BUS
|DBG_ERR
, "Clearing PCI Master Abort (and cleaning up)");
1631 status
&= ~PCI_STATUS_REC_MASTER_ABORT
;
1632 pci_write_config_word (dev
->pci_dev
, PCI_STATUS
, status
);
1633 if (test_bit (tx_busy
, &dev
->flags
)) {
1634 hrz_kfree_skb (dev
->tx_skb
);
1641 #ifdef DEBUG_HORIZON
1643 if (channel
== 1023) {
1645 unsigned short d
= 0;
1646 char * s
= skb
->data
;
1648 for (i
= 0; i
< 4; ++i
) {
1649 d
= (d
<<4) | ((*s
<= '9') ? (*s
- '0') : (*s
- 'a' + 10));
1652 PRINTK (KERN_INFO
, "debug bitmap is now %hx", debug
= d
);
1657 // wait until TX is free and grab lock
1658 if (tx_hold (dev
)) {
1659 hrz_kfree_skb (skb
);
1660 return -ERESTARTSYS
;
1663 // Wait for enough space to be available in transmit buffer memory.
1665 // should be number of cells needed + 2 (according to hardware docs)
1666 // = ((framelen+8)+47) / 48 + 2
1667 // = (framelen+7) / 48 + 3, hmm... faster to put addition inside XXX
1668 buffers_required
= (skb
->len
+(ATM_AAL5_TRAILER
-1)) / ATM_CELL_PAYLOAD
+ 3;
1670 // replace with timer and sleep, add dev->tx_buffers_queue (max 1 entry)
1672 while ((free_buffers
= rd_regw (dev
, TX_FREE_BUFFER_COUNT_OFF
)) < buffers_required
) {
1673 PRINTD (DBG_TX
, "waiting for free TX buffers, got %d of %d",
1674 free_buffers
, buffers_required
);
1675 // what is the appropriate delay? implement a timeout? (depending on line speed?)
1677 // what happens if we kill (current_pid, SIGKILL) ?
1679 if (++spin_count
> 1000) {
1680 PRINTD (DBG_TX
|DBG_ERR
, "spun out waiting for tx buffers, got %d of %d",
1681 free_buffers
, buffers_required
);
1683 hrz_kfree_skb (skb
);
1684 return -ERESTARTSYS
;
1688 // Select a channel to transmit the frame on.
1689 if (channel
== dev
->last_vc
) {
1690 PRINTD (DBG_TX
, "last vc hack: hit");
1691 tx_channel
= dev
->tx_last
;
1693 PRINTD (DBG_TX
, "last vc hack: miss");
1694 // Are we currently transmitting this VC on one of the channels?
1695 for (tx_channel
= 0; tx_channel
< TX_CHANS
; ++tx_channel
)
1696 if (dev
->tx_channel_record
[tx_channel
] == channel
) {
1697 PRINTD (DBG_TX
, "vc already on channel: hit");
1700 if (tx_channel
== TX_CHANS
) {
1701 PRINTD (DBG_TX
, "vc already on channel: miss");
1702 // Find and set up an idle channel.
1703 tx_channel
= setup_idle_tx_channel (dev
, vcc
);
1704 if (tx_channel
< 0) {
1705 PRINTD (DBG_TX
|DBG_ERR
, "failed to get channel");
1711 PRINTD (DBG_TX
, "got channel");
1712 SELECT_TX_CHANNEL(dev
, tx_channel
);
1714 dev
->last_vc
= channel
;
1715 dev
->tx_last
= tx_channel
;
1718 PRINTD (DBG_TX
, "using channel %u", tx_channel
);
1720 YELLOW_LED_OFF(dev
);
1722 // TX start transfer
1725 unsigned int tx_len
= skb
->len
;
1726 unsigned int tx_iovcnt
= skb_shinfo(skb
)->nr_frags
;
1727 // remember this so we can free it later
1731 // scatter gather transfer
1732 dev
->tx_regions
= tx_iovcnt
;
1733 dev
->tx_iovec
= NULL
; /* @@@ needs rewritten */
1735 PRINTD (DBG_TX
|DBG_BUS
, "TX start scatter-gather transfer (iovec %p, len %d)",
1738 hrz_kfree_skb (skb
);
1742 dev
->tx_regions
= 0;
1743 dev
->tx_iovec
= NULL
;
1744 dev
->tx_bytes
= tx_len
;
1745 dev
->tx_addr
= skb
->data
;
1746 PRINTD (DBG_TX
|DBG_BUS
, "TX start simple transfer (addr %p, len %d)",
1750 // and do the business
1751 tx_schedule (dev
, 0);
1758 /********** reset a card **********/
1760 static void hrz_reset (const hrz_dev
* dev
) {
1761 u32 control_0_reg
= rd_regl (dev
, CONTROL_0_REG
);
1763 // why not set RESET_HORIZON to one and wait for the card to
1764 // reassert that bit as zero? Like so:
1765 control_0_reg
= control_0_reg
& RESET_HORIZON
;
1766 wr_regl (dev
, CONTROL_0_REG
, control_0_reg
);
1767 while (control_0_reg
& RESET_HORIZON
)
1768 control_0_reg
= rd_regl (dev
, CONTROL_0_REG
);
1770 // old reset code retained:
1771 wr_regl (dev
, CONTROL_0_REG
, control_0_reg
|
1772 RESET_ATM
| RESET_RX
| RESET_TX
| RESET_HOST
);
1773 // just guessing here
1776 wr_regl (dev
, CONTROL_0_REG
, control_0_reg
);
1779 /********** read the burnt in address **********/
1781 static void WRITE_IT_WAIT (const hrz_dev
*dev
, u32 ctrl
)
1783 wr_regl (dev
, CONTROL_0_REG
, ctrl
);
1787 static void CLOCK_IT (const hrz_dev
*dev
, u32 ctrl
)
1789 // DI must be valid around rising SK edge
1790 WRITE_IT_WAIT(dev
, ctrl
& ~SEEPROM_SK
);
1791 WRITE_IT_WAIT(dev
, ctrl
| SEEPROM_SK
);
1794 static u16 __devinit
read_bia (const hrz_dev
* dev
, u16 addr
)
1796 u32 ctrl
= rd_regl (dev
, CONTROL_0_REG
);
1798 const unsigned int addr_bits
= 6;
1799 const unsigned int data_bits
= 16;
1805 ctrl
&= ~(SEEPROM_CS
| SEEPROM_SK
| SEEPROM_DI
);
1806 WRITE_IT_WAIT(dev
, ctrl
);
1808 // wake Serial EEPROM and send 110 (READ) command
1809 ctrl
|= (SEEPROM_CS
| SEEPROM_DI
);
1810 CLOCK_IT(dev
, ctrl
);
1813 CLOCK_IT(dev
, ctrl
);
1815 ctrl
&= ~SEEPROM_DI
;
1816 CLOCK_IT(dev
, ctrl
);
1818 for (i
=0; i
<addr_bits
; i
++) {
1819 if (addr
& (1 << (addr_bits
-1)))
1822 ctrl
&= ~SEEPROM_DI
;
1824 CLOCK_IT(dev
, ctrl
);
1829 // we could check that we have DO = 0 here
1830 ctrl
&= ~SEEPROM_DI
;
1833 for (i
=0;i
<data_bits
;i
++) {
1836 CLOCK_IT(dev
, ctrl
);
1838 if (rd_regl (dev
, CONTROL_0_REG
) & SEEPROM_DO
)
1839 res
|= (1 << (data_bits
-1));
1842 ctrl
&= ~(SEEPROM_SK
| SEEPROM_CS
);
1843 WRITE_IT_WAIT(dev
, ctrl
);
1848 /********** initialise a card **********/
1850 static int __devinit
hrz_init (hrz_dev
* dev
) {
1864 ctrl
= rd_regl (dev
, CONTROL_0_REG
);
1865 PRINTD (DBG_INFO
, "ctrl0reg is %#x", ctrl
);
1866 onefivefive
= ctrl
& ATM_LAYER_STATUS
;
1869 printk (DEV_LABEL
": Horizon Ultra (at 155.52 MBps)");
1871 printk (DEV_LABEL
": Horizon (at 25 MBps)");
1874 // Reset the card to get everything in a known state
1879 // Clear all the buffer memory
1881 printk (" clearing memory");
1883 for (mem
= (HDW
*) memmap
; mem
< (HDW
*) (memmap
+ 1); ++mem
)
1884 wr_mem (dev
, mem
, 0);
1886 printk (" tx channels");
1888 // All transmit eight channels are set up as AAL5 ABR channels with
1889 // a 16us cell spacing. Why?
1891 // Channel 0 gets the free buffer at 100h, channel 1 gets the free
1892 // buffer at 110h etc.
1894 for (chan
= 0; chan
< TX_CHANS
; ++chan
) {
1895 tx_ch_desc
* tx_desc
= &memmap
->tx_descs
[chan
];
1896 cell_buf
* buf
= &memmap
->inittxbufs
[chan
];
1898 // initialise the read and write buffer pointers
1899 wr_mem (dev
, &tx_desc
->rd_buf_type
, BUF_PTR(buf
));
1900 wr_mem (dev
, &tx_desc
->wr_buf_type
, BUF_PTR(buf
));
1902 // set the status of the initial buffers to empty
1903 wr_mem (dev
, &buf
->next
, BUFF_STATUS_EMPTY
);
1906 // Use space bufn3 at the moment for tx buffers
1908 printk (" tx buffers");
1910 tx_desc
= memmap
->bufn3
;
1912 wr_mem (dev
, &memmap
->txfreebufstart
.next
, BUF_PTR(tx_desc
) | BUFF_STATUS_EMPTY
);
1914 for (buff_count
= 0; buff_count
< BUFN3_SIZE
-1; buff_count
++) {
1915 wr_mem (dev
, &tx_desc
->next
, BUF_PTR(tx_desc
+1) | BUFF_STATUS_EMPTY
);
1919 wr_mem (dev
, &tx_desc
->next
, BUF_PTR(&memmap
->txfreebufend
) | BUFF_STATUS_EMPTY
);
1921 // Initialise the transmit free buffer count
1922 wr_regw (dev
, TX_FREE_BUFFER_COUNT_OFF
, BUFN3_SIZE
);
1924 printk (" rx channels");
1926 // Initialise all of the receive channels to be AAL5 disabled with
1927 // an interrupt threshold of 0
1929 for (chan
= 0; chan
< RX_CHANS
; ++chan
) {
1930 rx_ch_desc
* rx_desc
= &memmap
->rx_descs
[chan
];
1932 wr_mem (dev
, &rx_desc
->wr_buf_type
, CHANNEL_TYPE_AAL5
| RX_CHANNEL_DISABLED
);
1935 printk (" rx buffers");
1937 // Use space bufn4 at the moment for rx buffers
1939 rx_desc
= memmap
->bufn4
;
1941 wr_mem (dev
, &memmap
->rxfreebufstart
.next
, BUF_PTR(rx_desc
) | BUFF_STATUS_EMPTY
);
1943 for (buff_count
= 0; buff_count
< BUFN4_SIZE
-1; buff_count
++) {
1944 wr_mem (dev
, &rx_desc
->next
, BUF_PTR(rx_desc
+1) | BUFF_STATUS_EMPTY
);
1949 wr_mem (dev
, &rx_desc
->next
, BUF_PTR(&memmap
->rxfreebufend
) | BUFF_STATUS_EMPTY
);
1951 // Initialise the receive free buffer count
1952 wr_regw (dev
, RX_FREE_BUFFER_COUNT_OFF
, BUFN4_SIZE
);
1954 // Initialize Horizons registers
1957 wr_regw (dev
, TX_CONFIG_OFF
,
1958 ABR_ROUND_ROBIN
| TX_NORMAL_OPERATION
| DRVR_DRVRBAR_ENABLE
);
1960 // RX config. Use 10-x VC bits, x VP bits, non user cells in channel 0.
1961 wr_regw (dev
, RX_CONFIG_OFF
,
1962 DISCARD_UNUSED_VPI_VCI_BITS_SET
| NON_USER_CELLS_IN_ONE_CHANNEL
| vpi_bits
);
1965 wr_regw (dev
, RX_LINE_CONFIG_OFF
,
1966 LOCK_DETECT_ENABLE
| FREQUENCY_DETECT_ENABLE
| GXTALOUT_SELECT_DIV4
);
1968 // Set the max AAL5 cell count to be just enough to contain the
1969 // largest AAL5 frame that the user wants to receive
1970 wr_regw (dev
, MAX_AAL5_CELL_COUNT_OFF
,
1971 DIV_ROUND_UP(max_rx_size
+ ATM_AAL5_TRAILER
, ATM_CELL_PAYLOAD
));
1974 wr_regw (dev
, RX_CONFIG_OFF
, rd_regw (dev
, RX_CONFIG_OFF
) | RX_ENABLE
);
1976 printk (" control");
1978 // Drive the OE of the LEDs then turn the green LED on
1979 ctrl
|= GREEN_LED_OE
| YELLOW_LED_OE
| GREEN_LED
| YELLOW_LED
;
1980 wr_regl (dev
, CONTROL_0_REG
, ctrl
);
1982 // Test for a 155-capable card
1985 // Select 155 mode... make this a choice (or: how do we detect
1986 // external line speed and switch?)
1987 ctrl
|= ATM_LAYER_SELECT
;
1988 wr_regl (dev
, CONTROL_0_REG
, ctrl
);
1990 // test SUNI-lite vs SAMBA
1992 // Register 0x00 in the SUNI will have some of bits 3-7 set, and
1993 // they will always be zero for the SAMBA. Ha! Bloody hardware
1994 // engineers. It'll never work.
1996 if (rd_framer (dev
, 0) & 0x00f0) {
2000 // Reset, just in case
2001 wr_framer (dev
, 0x00, 0x0080);
2002 wr_framer (dev
, 0x00, 0x0000);
2004 // Configure transmit FIFO
2005 wr_framer (dev
, 0x63, rd_framer (dev
, 0x63) | 0x0002);
2007 // Set line timed mode
2008 wr_framer (dev
, 0x05, rd_framer (dev
, 0x05) | 0x0001);
2013 // Reset, just in case
2014 wr_framer (dev
, 0, rd_framer (dev
, 0) | 0x0001);
2015 wr_framer (dev
, 0, rd_framer (dev
, 0) &~ 0x0001);
2017 // Turn off diagnostic loopback and enable line-timed mode
2018 wr_framer (dev
, 0, 0x0002);
2020 // Turn on transmit outputs
2021 wr_framer (dev
, 2, 0x0B80);
2025 ctrl
&= ~ATM_LAYER_SELECT
;
2041 u8
* esi
= dev
->atm_dev
->esi
;
2043 // in the card I have, EEPROM
2044 // addresses 0, 1, 2 contain 0
2045 // addresess 5, 6 etc. contain ffff
2046 // NB: Madge prefix is 00 00 f6 (which is 00 00 6f in Ethernet bit order)
2047 // the read_bia routine gets the BIA in Ethernet bit order
2049 for (i
=0; i
< ESI_LEN
; ++i
) {
2051 b
= read_bia (dev
, i
/2 + 2);
2055 printk ("%02x", esi
[i
]);
2059 // Enable RX_Q and ?X_COMPLETE interrupts only
2060 wr_regl (dev
, INT_ENABLE_REG_OFF
, INTERESTING_INTERRUPTS
);
2068 /********** check max_sdu **********/
2070 static int check_max_sdu (hrz_aal aal
, struct atm_trafprm
* tp
, unsigned int max_frame_size
) {
2071 PRINTD (DBG_FLOW
|DBG_QOS
, "check_max_sdu");
2075 if (!(tp
->max_sdu
)) {
2076 PRINTD (DBG_QOS
, "defaulting max_sdu");
2077 tp
->max_sdu
= ATM_AAL0_SDU
;
2078 } else if (tp
->max_sdu
!= ATM_AAL0_SDU
) {
2079 PRINTD (DBG_QOS
|DBG_ERR
, "rejecting max_sdu");
2084 if (tp
->max_sdu
== 0 || tp
->max_sdu
> ATM_MAX_AAL34_PDU
) {
2085 PRINTD (DBG_QOS
, "%sing max_sdu", tp
->max_sdu
? "capp" : "default");
2086 tp
->max_sdu
= ATM_MAX_AAL34_PDU
;
2090 if (tp
->max_sdu
== 0 || tp
->max_sdu
> max_frame_size
) {
2091 PRINTD (DBG_QOS
, "%sing max_sdu", tp
->max_sdu
? "capp" : "default");
2092 tp
->max_sdu
= max_frame_size
;
2099 /********** check pcr **********/
2101 // something like this should be part of ATM Linux
2102 static int atm_pcr_check (struct atm_trafprm
* tp
, unsigned int pcr
) {
2103 // we are assuming non-UBR, and non-special values of pcr
2104 if (tp
->min_pcr
== ATM_MAX_PCR
)
2105 PRINTD (DBG_QOS
, "luser gave min_pcr = ATM_MAX_PCR");
2106 else if (tp
->min_pcr
< 0)
2107 PRINTD (DBG_QOS
, "luser gave negative min_pcr");
2108 else if (tp
->min_pcr
&& tp
->min_pcr
> pcr
)
2109 PRINTD (DBG_QOS
, "pcr less than min_pcr");
2111 // !! max_pcr = UNSPEC (0) is equivalent to max_pcr = MAX (-1)
2112 // easier to #define ATM_MAX_PCR 0 and have all rates unsigned?
2113 // [this would get rid of next two conditionals]
2114 if ((0) && tp
->max_pcr
== ATM_MAX_PCR
)
2115 PRINTD (DBG_QOS
, "luser gave max_pcr = ATM_MAX_PCR");
2116 else if ((tp
->max_pcr
!= ATM_MAX_PCR
) && tp
->max_pcr
< 0)
2117 PRINTD (DBG_QOS
, "luser gave negative max_pcr");
2118 else if (tp
->max_pcr
&& tp
->max_pcr
!= ATM_MAX_PCR
&& tp
->max_pcr
< pcr
)
2119 PRINTD (DBG_QOS
, "pcr greater than max_pcr");
2121 // each limit unspecified or not violated
2122 PRINTD (DBG_QOS
, "xBR(pcr) OK");
2125 PRINTD (DBG_QOS
, "pcr=%u, tp: min_pcr=%d, pcr=%d, max_pcr=%d",
2126 pcr
, tp
->min_pcr
, tp
->pcr
, tp
->max_pcr
);
2130 /********** open VC **********/
2132 static int hrz_open (struct atm_vcc
*atm_vcc
)
2137 struct atm_qos
* qos
;
2138 struct atm_trafprm
* txtp
;
2139 struct atm_trafprm
* rxtp
;
2141 hrz_dev
* dev
= HRZ_DEV(atm_vcc
->dev
);
2143 hrz_vcc
* vccp
; // allocated late
2144 short vpi
= atm_vcc
->vpi
;
2145 int vci
= atm_vcc
->vci
;
2146 PRINTD (DBG_FLOW
|DBG_VCC
, "hrz_open %x %x", vpi
, vci
);
2148 #ifdef ATM_VPI_UNSPEC
2149 // UNSPEC is deprecated, remove this code eventually
2150 if (vpi
== ATM_VPI_UNSPEC
|| vci
== ATM_VCI_UNSPEC
) {
2151 PRINTK (KERN_WARNING
, "rejecting open with unspecified VPI/VCI (deprecated)");
2156 error
= vpivci_to_channel (&channel
, vpi
, vci
);
2158 PRINTD (DBG_WARN
|DBG_VCC
, "VPI/VCI out of range: %hd/%d", vpi
, vci
);
2162 vcc
.channel
= channel
;
2163 // max speed for the moment
2166 qos
= &atm_vcc
->qos
;
2168 // check AAL and remember it
2171 // we would if it were 48 bytes and not 52!
2172 PRINTD (DBG_QOS
|DBG_VCC
, "AAL0");
2176 // we would if I knew how do the SAR!
2177 PRINTD (DBG_QOS
|DBG_VCC
, "AAL3/4");
2181 PRINTD (DBG_QOS
|DBG_VCC
, "AAL5");
2185 PRINTD (DBG_QOS
|DBG_VCC
, "Bad AAL!");
2190 // TX traffic parameters
2192 // there are two, interrelated problems here: 1. the reservation of
2193 // PCR is not a binary choice, we are given bounds and/or a
2194 // desirable value; 2. the device is only capable of certain values,
2195 // most of which are not integers. It is almost certainly acceptable
2196 // to be off by a maximum of 1 to 10 cps.
2198 // Pragmatic choice: always store an integral PCR as that which has
2199 // been allocated, even if we allocate a little (or a lot) less,
2200 // after rounding. The actual allocation depends on what we can
2201 // manage with our rate selection algorithm. The rate selection
2202 // algorithm is given an integral PCR and a tolerance and told
2203 // whether it should round the value up or down if the tolerance is
2204 // exceeded; it returns: a) the actual rate selected (rounded up to
2205 // the nearest integer), b) a bit pattern to feed to the timer
2206 // register, and c) a failure value if no applicable rate exists.
2208 // Part of the job is done by atm_pcr_goal which gives us a PCR
2209 // specification which says: EITHER grab the maximum available PCR
2210 // (and perhaps a lower bound which we musn't pass), OR grab this
2211 // amount, rounding down if you have to (and perhaps a lower bound
2212 // which we musn't pass) OR grab this amount, rounding up if you
2213 // have to (and perhaps an upper bound which we musn't pass). If any
2214 // bounds ARE passed we fail. Note that rounding is only rounding to
2215 // match device limitations, we do not round down to satisfy
2216 // bandwidth availability even if this would not violate any given
2219 // Note: telephony = 64kb/s = 48 byte cell payload @ 500/3 cells/s
2220 // (say) so this is not even a binary fixpoint cell rate (but this
2221 // device can do it). To avoid this sort of hassle we use a
2222 // tolerance parameter (currently fixed at 10 cps).
2224 PRINTD (DBG_QOS
, "TX:");
2228 // set up defaults for no traffic
2230 // who knows what would actually happen if you try and send on this?
2231 vcc
.tx_xbr_bits
= IDLE_RATE_TYPE
;
2232 vcc
.tx_pcr_bits
= CLOCK_DISABLE
;
2234 vcc
.tx_scr_bits
= CLOCK_DISABLE
;
2235 vcc
.tx_bucket_bits
= 0;
2238 if (txtp
->traffic_class
!= ATM_NONE
) {
2239 error
= check_max_sdu (vcc
.aal
, txtp
, max_tx_size
);
2241 PRINTD (DBG_QOS
, "TX max_sdu check failed");
2245 switch (txtp
->traffic_class
) {
2247 // we take "the PCR" as a rate-cap
2250 make_rate (dev
, 1<<30, round_nearest
, &vcc
.tx_pcr_bits
, NULL
);
2251 vcc
.tx_xbr_bits
= ABR_RATE_TYPE
;
2256 // reserve min, allow up to max
2257 vcc
.tx_rate
= 0; // ?
2258 make_rate (dev
, 1<<30, round_nearest
, &vcc
.tx_pcr_bits
, 0);
2259 vcc
.tx_xbr_bits
= ABR_RATE_TYPE
;
2264 int pcr
= atm_pcr_goal (txtp
);
2267 // down vs. up, remaining bandwidth vs. unlimited bandwidth!!
2268 // should really have: once someone gets unlimited bandwidth
2269 // that no more non-UBR channels can be opened until the
2270 // unlimited one closes?? For the moment, round_down means
2271 // greedy people actually get something and not nothing
2273 // slight race (no locking) here so we may get -EAGAIN
2274 // later; the greedy bastards would deserve it :)
2275 PRINTD (DBG_QOS
, "snatching all remaining TX bandwidth");
2276 pcr
= dev
->tx_avail
;
2277 } else if (pcr
< 0) {
2283 error
= make_rate_with_tolerance (dev
, pcr
, r
, 10,
2284 &vcc
.tx_pcr_bits
, &vcc
.tx_rate
);
2286 PRINTD (DBG_QOS
, "could not make rate from TX PCR");
2289 // not really clear what further checking is needed
2290 error
= atm_pcr_check (txtp
, vcc
.tx_rate
);
2292 PRINTD (DBG_QOS
, "TX PCR failed consistency check");
2295 vcc
.tx_xbr_bits
= CBR_RATE_TYPE
;
2300 int pcr
= atm_pcr_goal (txtp
);
2301 // int scr = atm_scr_goal (txtp);
2302 int scr
= pcr
/2; // just for fun
2303 unsigned int mbs
= 60; // just for fun
2306 unsigned int bucket
;
2310 } else if (pcr
< 0) {
2316 error
= make_rate_with_tolerance (dev
, pcr
, pr
, 10,
2317 &vcc
.tx_pcr_bits
, 0);
2319 // see comments for PCR with CBR above
2321 // slight race (no locking) here so we may get -EAGAIN
2322 // later; the greedy bastards would deserve it :)
2323 PRINTD (DBG_QOS
, "snatching all remaining TX bandwidth");
2324 scr
= dev
->tx_avail
;
2325 } else if (scr
< 0) {
2331 error
= make_rate_with_tolerance (dev
, scr
, sr
, 10,
2332 &vcc
.tx_scr_bits
, &vcc
.tx_rate
);
2334 PRINTD (DBG_QOS
, "could not make rate from TX SCR");
2337 // not really clear what further checking is needed
2338 // error = atm_scr_check (txtp, vcc.tx_rate);
2340 PRINTD (DBG_QOS
, "TX SCR failed consistency check");
2343 // bucket calculations (from a piece of paper...) cell bucket
2344 // capacity must be largest integer smaller than m(p-s)/p + 1
2345 // where m = max burst size, p = pcr, s = scr
2346 bucket
= mbs
*(pcr
-scr
)/pcr
;
2347 if (bucket
*pcr
!= mbs
*(pcr
-scr
))
2349 if (bucket
> BUCKET_MAX_SIZE
) {
2350 PRINTD (DBG_QOS
, "shrinking bucket from %u to %u",
2351 bucket
, BUCKET_MAX_SIZE
);
2352 bucket
= BUCKET_MAX_SIZE
;
2354 vcc
.tx_xbr_bits
= VBR_RATE_TYPE
;
2355 vcc
.tx_bucket_bits
= bucket
;
2360 PRINTD (DBG_QOS
, "unsupported TX traffic class");
2367 // RX traffic parameters
2369 PRINTD (DBG_QOS
, "RX:");
2373 // set up defaults for no traffic
2376 if (rxtp
->traffic_class
!= ATM_NONE
) {
2377 error
= check_max_sdu (vcc
.aal
, rxtp
, max_rx_size
);
2379 PRINTD (DBG_QOS
, "RX max_sdu check failed");
2382 switch (rxtp
->traffic_class
) {
2390 vcc
.rx_rate
= 0; // ?
2395 int pcr
= atm_pcr_goal (rxtp
);
2397 // slight race (no locking) here so we may get -EAGAIN
2398 // later; the greedy bastards would deserve it :)
2399 PRINTD (DBG_QOS
, "snatching all remaining RX bandwidth");
2400 pcr
= dev
->rx_avail
;
2401 } else if (pcr
< 0) {
2405 // not really clear what further checking is needed
2406 error
= atm_pcr_check (rxtp
, vcc
.rx_rate
);
2408 PRINTD (DBG_QOS
, "RX PCR failed consistency check");
2415 // int scr = atm_scr_goal (rxtp);
2416 int scr
= 1<<16; // just for fun
2418 // slight race (no locking) here so we may get -EAGAIN
2419 // later; the greedy bastards would deserve it :)
2420 PRINTD (DBG_QOS
, "snatching all remaining RX bandwidth");
2421 scr
= dev
->rx_avail
;
2422 } else if (scr
< 0) {
2426 // not really clear what further checking is needed
2427 // error = atm_scr_check (rxtp, vcc.rx_rate);
2429 PRINTD (DBG_QOS
, "RX SCR failed consistency check");
2436 PRINTD (DBG_QOS
, "unsupported RX traffic class");
2444 // late abort useful for diagnostics
2445 if (vcc
.aal
!= aal5
) {
2446 PRINTD (DBG_QOS
, "AAL not supported");
2450 // get space for our vcc stuff and copy parameters into it
2451 vccp
= kmalloc (sizeof(hrz_vcc
), GFP_KERNEL
);
2453 PRINTK (KERN_ERR
, "out of memory!");
2458 // clear error and grab cell rate resource lock
2460 spin_lock (&dev
->rate_lock
);
2462 if (vcc
.tx_rate
> dev
->tx_avail
) {
2463 PRINTD (DBG_QOS
, "not enough TX PCR left");
2467 if (vcc
.rx_rate
> dev
->rx_avail
) {
2468 PRINTD (DBG_QOS
, "not enough RX PCR left");
2473 // really consume cell rates
2474 dev
->tx_avail
-= vcc
.tx_rate
;
2475 dev
->rx_avail
-= vcc
.rx_rate
;
2476 PRINTD (DBG_QOS
|DBG_VCC
, "reserving %u TX PCR and %u RX PCR",
2477 vcc
.tx_rate
, vcc
.rx_rate
);
2480 // release lock and exit on error
2481 spin_unlock (&dev
->rate_lock
);
2483 PRINTD (DBG_QOS
|DBG_VCC
, "insufficient cell rate resources");
2488 // this is "immediately before allocating the connection identifier
2489 // in hardware" - so long as the next call does not fail :)
2490 set_bit(ATM_VF_ADDR
,&atm_vcc
->flags
);
2492 // any errors here are very serious and should never occur
2494 if (rxtp
->traffic_class
!= ATM_NONE
) {
2495 if (dev
->rxer
[channel
]) {
2496 PRINTD (DBG_ERR
|DBG_VCC
, "VC already open for RX");
2500 error
= hrz_open_rx (dev
, channel
);
2505 // this link allows RX frames through
2506 dev
->rxer
[channel
] = atm_vcc
;
2509 // success, set elements of atm_vcc
2510 atm_vcc
->dev_data
= (void *) vccp
;
2512 // indicate readiness
2513 set_bit(ATM_VF_READY
,&atm_vcc
->flags
);
2518 /********** close VC **********/
2520 static void hrz_close (struct atm_vcc
* atm_vcc
) {
2521 hrz_dev
* dev
= HRZ_DEV(atm_vcc
->dev
);
2522 hrz_vcc
* vcc
= HRZ_VCC(atm_vcc
);
2523 u16 channel
= vcc
->channel
;
2524 PRINTD (DBG_VCC
|DBG_FLOW
, "hrz_close");
2526 // indicate unreadiness
2527 clear_bit(ATM_VF_READY
,&atm_vcc
->flags
);
2529 if (atm_vcc
->qos
.txtp
.traffic_class
!= ATM_NONE
) {
2532 // let any TX on this channel that has started complete
2533 // no restart, just keep trying
2534 while (tx_hold (dev
))
2536 // remove record of any tx_channel having been setup for this channel
2537 for (i
= 0; i
< TX_CHANS
; ++i
)
2538 if (dev
->tx_channel_record
[i
] == channel
) {
2539 dev
->tx_channel_record
[i
] = -1;
2542 if (dev
->last_vc
== channel
)
2547 if (atm_vcc
->qos
.rxtp
.traffic_class
!= ATM_NONE
) {
2548 // disable RXing - it tries quite hard
2549 hrz_close_rx (dev
, channel
);
2550 // forget the vcc - no more skbs will be pushed
2551 if (atm_vcc
!= dev
->rxer
[channel
])
2552 PRINTK (KERN_ERR
, "%s atm_vcc=%p rxer[channel]=%p",
2553 "arghhh! we're going to die!",
2554 atm_vcc
, dev
->rxer
[channel
]);
2555 dev
->rxer
[channel
] = NULL
;
2558 // atomically release our rate reservation
2559 spin_lock (&dev
->rate_lock
);
2560 PRINTD (DBG_QOS
|DBG_VCC
, "releasing %u TX PCR and %u RX PCR",
2561 vcc
->tx_rate
, vcc
->rx_rate
);
2562 dev
->tx_avail
+= vcc
->tx_rate
;
2563 dev
->rx_avail
+= vcc
->rx_rate
;
2564 spin_unlock (&dev
->rate_lock
);
2566 // free our structure
2568 // say the VPI/VCI is free again
2569 clear_bit(ATM_VF_ADDR
,&atm_vcc
->flags
);
2573 static int hrz_getsockopt (struct atm_vcc
* atm_vcc
, int level
, int optname
,
2574 void *optval
, int optlen
) {
2575 hrz_dev
* dev
= HRZ_DEV(atm_vcc
->dev
);
2576 PRINTD (DBG_FLOW
|DBG_VCC
, "hrz_getsockopt");
2585 return -ENOPROTOOPT
;
2593 static int hrz_setsockopt (struct atm_vcc
* atm_vcc
, int level
, int optname
,
2594 void *optval
, unsigned int optlen
) {
2595 hrz_dev
* dev
= HRZ_DEV(atm_vcc
->dev
);
2596 PRINTD (DBG_FLOW
|DBG_VCC
, "hrz_setsockopt");
2605 return -ENOPROTOOPT
;
2615 static int hrz_ioctl (struct atm_dev
* atm_dev
, unsigned int cmd
, void *arg
) {
2616 hrz_dev
* dev
= HRZ_DEV(atm_dev
);
2617 PRINTD (DBG_FLOW
, "hrz_ioctl");
2621 unsigned char hrz_phy_get (struct atm_dev
* atm_dev
, unsigned long addr
) {
2622 hrz_dev
* dev
= HRZ_DEV(atm_dev
);
2623 PRINTD (DBG_FLOW
, "hrz_phy_get");
2627 static void hrz_phy_put (struct atm_dev
* atm_dev
, unsigned char value
,
2628 unsigned long addr
) {
2629 hrz_dev
* dev
= HRZ_DEV(atm_dev
);
2630 PRINTD (DBG_FLOW
, "hrz_phy_put");
2633 static int hrz_change_qos (struct atm_vcc
* atm_vcc
, struct atm_qos
*qos
, int flgs
) {
2634 hrz_dev
* dev
= HRZ_DEV(vcc
->dev
);
2635 PRINTD (DBG_FLOW
, "hrz_change_qos");
2640 /********** proc file contents **********/
2642 static int hrz_proc_read (struct atm_dev
* atm_dev
, loff_t
* pos
, char * page
) {
2643 hrz_dev
* dev
= HRZ_DEV(atm_dev
);
2645 PRINTD (DBG_FLOW
, "hrz_proc_read");
2647 /* more diagnostics here? */
2651 unsigned int count
= sprintf (page
, "vbr buckets:");
2653 for (i
= 0; i
< TX_CHANS
; ++i
)
2654 count
+= sprintf (page
, " %u/%u",
2655 query_tx_channel_config (dev
, i
, BUCKET_FULLNESS_ACCESS
),
2656 query_tx_channel_config (dev
, i
, BUCKET_CAPACITY_ACCESS
));
2657 count
+= sprintf (page
+count
, ".\n");
2663 return sprintf (page
,
2664 "cells: TX %lu, RX %lu, HEC errors %lu, unassigned %lu.\n",
2665 dev
->tx_cell_count
, dev
->rx_cell_count
,
2666 dev
->hec_error_count
, dev
->unassigned_cell_count
);
2669 return sprintf (page
,
2670 "free cell buffers: TX %hu, RX %hu+%hu.\n",
2671 rd_regw (dev
, TX_FREE_BUFFER_COUNT_OFF
),
2672 rd_regw (dev
, RX_FREE_BUFFER_COUNT_OFF
),
2673 dev
->noof_spare_buffers
);
2676 return sprintf (page
,
2677 "cps remaining: TX %u, RX %u\n",
2678 dev
->tx_avail
, dev
->rx_avail
);
2683 static const struct atmdev_ops hrz_ops
= {
2687 .proc_read
= hrz_proc_read
,
2688 .owner
= THIS_MODULE
,
2691 static int __devinit
hrz_probe(struct pci_dev
*pci_dev
, const struct pci_device_id
*pci_ent
)
2696 // adapter slot free, read resources from PCI configuration space
2697 u32 iobase
= pci_resource_start (pci_dev
, 0);
2698 u32
* membase
= bus_to_virt (pci_resource_start (pci_dev
, 1));
2702 PRINTD (DBG_FLOW
, "hrz_probe");
2704 if (pci_enable_device(pci_dev
))
2707 /* XXX DEV_LABEL is a guess */
2708 if (!request_region(iobase
, HRZ_IO_EXTENT
, DEV_LABEL
)) {
2713 dev
= kzalloc(sizeof(hrz_dev
), GFP_KERNEL
);
2715 // perhaps we should be nice: deregister all adapters and abort?
2716 PRINTD(DBG_ERR
, "out of memory");
2721 pci_set_drvdata(pci_dev
, dev
);
2723 // grab IRQ and install handler - move this someplace more sensible
2725 if (request_irq(irq
,
2727 IRQF_SHARED
, /* irqflags guess */
2728 DEV_LABEL
, /* name guess */
2730 PRINTD(DBG_WARN
, "request IRQ failed!");
2735 PRINTD(DBG_INFO
, "found Madge ATM adapter (hrz) at: IO %x, IRQ %u, MEM %p",
2736 iobase
, irq
, membase
);
2738 dev
->atm_dev
= atm_dev_register(DEV_LABEL
, &hrz_ops
, -1, NULL
);
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
);