2 /* drivers/atm/firestream.c - FireStream 155 (MB86697) and
3 * FireStream 50 (MB86695) device driver
6 /* Written & (C) 2000 by R.E.Wolff@BitWizard.nl
7 * Copied snippets from zatm.c by Werner Almesberger, EPFL LRC/ICA
8 * and ambassador.c Copyright (C) 1995-1999 Madge Networks Ltd
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 The GNU GPL is contained in /usr/doc/copyright/GPL on a Debian
27 system and in the file COPYING in the Linux kernel source.
31 #include <linux/module.h>
32 #include <linux/sched.h>
33 #include <linux/kernel.h>
35 #include <linux/pci.h>
36 #include <linux/poison.h>
37 #include <linux/errno.h>
38 #include <linux/atm.h>
39 #include <linux/atmdev.h>
40 #include <linux/sonet.h>
41 #include <linux/skbuff.h>
42 #include <linux/netdevice.h>
43 #include <linux/delay.h>
44 #include <linux/ioport.h> /* for request_region */
45 #include <linux/uio.h>
46 #include <linux/init.h>
47 #include <linux/interrupt.h>
48 #include <linux/capability.h>
49 #include <linux/bitops.h>
50 #include <linux/slab.h>
51 #include <asm/byteorder.h>
52 #include <asm/system.h>
53 #include <asm/string.h>
55 #include <linux/atomic.h>
56 #include <asm/uaccess.h>
57 #include <linux/wait.h>
59 #include "firestream.h"
61 static int loopback
= 0;
64 /* According to measurements (but they look suspicious to me!) done in
65 * '97, 37% of the packets are one cell in size. So it pays to have
66 * buffers allocated at that size. A large jump in percentage of
67 * packets occurs at packets around 536 bytes in length. So it also
68 * pays to have those pre-allocated. Unfortunately, we can't fully
69 * take advantage of this as the majority of the packets is likely to
70 * be TCP/IP (As where obviously the measurement comes from) There the
71 * link would be opened with say a 1500 byte MTU, and we can't handle
72 * smaller buffers more efficiently than the larger ones. -- REW
75 /* Due to the way Linux memory management works, specifying "576" as
76 * an allocation size here isn't going to help. They are allocated
77 * from 1024-byte regions anyway. With the size of the sk_buffs (quite
78 * large), it doesn't pay to allocate the smallest size (64) -- REW */
80 /* This is all guesswork. Hard numbers to back this up or disprove this,
81 * are appreciated. -- REW */
83 /* The last entry should be about 64k. However, the "buffer size" is
84 * passed to the chip in a 16 bit field. I don't know how "65536"
85 * would be interpreted. -- REW */
87 #define NP FS_NR_FREE_POOLS
88 static int rx_buf_sizes
[NP
] = {128, 256, 512, 1024, 2048, 4096, 16384, 65520};
89 /* log2: 7 8 9 10 11 12 14 16 */
92 static int rx_pool_sizes
[NP
] = {1024, 1024, 512, 256, 128, 64, 32, 32};
95 static int rx_pool_sizes
[NP
] = {128, 128, 128, 64, 64, 64, 32, 32};
97 /* log2: 10 10 9 8 7 6 5 5 */
98 /* sumlog2: 17 18 18 18 18 18 19 21 */
99 /* mem allocated: 128k 256k 256k 256k 256k 256k 512k 2M */
100 /* tot mem: almost 4M */
102 /* NP is shorter, so that it fits on a single line. */
106 /* Small hardware gotcha:
108 The FS50 CAM (VP/VC match registers) always take the lowest channel
109 number that matches. This is not a problem.
111 However, they also ignore whether the channel is enabled or
112 not. This means that if you allocate channel 0 to 1.2 and then
113 channel 1 to 0.0, then disabeling channel 0 and writing 0 to the
114 match channel for channel 0 will "steal" the traffic from channel
115 1, even if you correctly disable channel 0.
119 - When disabling channels, write an invalid VP/VC value to the
120 match register. (We use 0xffffffff, which in the worst case
121 matches VP/VC = <maxVP>/<maxVC>, but I expect it not to match
122 anything as some "when not in use, program to 0" bits are now
125 - Don't initialize the match registers to 0, as 0.0 is a valid
130 /* Optimization hints and tips.
132 The FireStream chips are very capable of reducing the amount of
133 "interrupt-traffic" for the CPU. This driver requests an interrupt on EVERY
134 action. You could try to minimize this a bit.
136 Besides that, the userspace->kernel copy and the PCI bus are the
137 performance limiting issues for this driver.
139 You could queue up a bunch of outgoing packets without telling the
140 FireStream. I'm not sure that's going to win you much though. The
141 Linux layer won't tell us in advance when it's not going to give us
142 any more packets in a while. So this is tricky to implement right without
143 introducing extra delays.
151 /* The strings that define what the RX queue entry is all about. */
152 /* Fujitsu: Please tell me which ones can have a pointer to a
153 freepool descriptor! */
154 static char *res_strings
[] = {
155 "RX OK: streaming not EOP",
156 "RX OK: streaming EOP",
157 "RX OK: Single buffer packet",
158 "RX OK: packet mode",
159 "RX OK: F4 OAM (end to end)",
160 "RX OK: F4 OAM (Segment)",
161 "RX OK: F5 OAM (end to end)",
162 "RX OK: F5 OAM (Segment)",
164 "RX OK: TRANSP cell",
165 "RX OK: TRANSPC cell",
172 "reassemby abort: AAL5 abort",
174 "packet ageing timeout",
175 "channel ageing timeout",
176 "calculated length error",
177 "programmed length limit error",
179 "oam transp or transpc crc10 error",
186 "reassembly abort: no buffers",
187 "receive buffer overflow",
189 "receive buffer full",
190 "low priority discard - no receive descriptor",
191 "low priority discard - missing end of packet",
217 static char *irq_bitname
[] = {
249 #define PHY_CLEARALL -2
251 struct reginit_item
{
256 static struct reginit_item PHY_NTC_INIT
[] __devinitdata
= {
257 { PHY_CLEARALL
, 0x40 },
263 { 0x39, 0x0006 }, /* changed here to make loopback */
267 { PHY_EOF
, 0}, /* -1 signals end of list */
271 /* Safetyfeature: If the card interrupts more than this number of times
272 in a jiffy (1/100th of a second) then we just disable the interrupt and
273 print a message. This prevents the system from hanging.
275 150000 packets per second is close to the limit a PC is going to have
276 anyway. We therefore have to disable this for production. -- REW */
277 #undef IRQ_RATE_LIMIT // 100
279 /* Interrupts work now. Unlike serial cards, ATM cards don't work all
280 that great without interrupts. -- REW */
281 #undef FS_POLL_FREQ // 100
284 This driver can spew a whole lot of debugging output at you. If you
285 need maximum performance, you should disable the DEBUG define. To
286 aid in debugging in the field, I'm leaving the compile-time debug
287 features enabled, and disable them "runtime". That allows me to
288 instruct people with problems to enable debugging without requiring
289 them to recompile... -- REW
294 #define fs_dprintk(f, str...) if (fs_debug & f) printk (str)
296 #define fs_dprintk(f, str...) /* nothing */
300 static int fs_keystream
= 0;
303 /* I didn't forget to set this to zero before shipping. Hit me with a stick
304 if you get this with the debug default not set to zero again. -- REW */
305 static int fs_debug
= 0;
312 module_param(fs_debug
, int, 0644);
314 module_param(loopback
, int, 0);
315 module_param(num
, int, 0);
316 module_param(fs_keystream
, int, 0);
317 /* XXX Add rx_buf_sizes, and rx_pool_sizes As per request Amar. -- REW */
321 #define FS_DEBUG_FLOW 0x00000001
322 #define FS_DEBUG_OPEN 0x00000002
323 #define FS_DEBUG_QUEUE 0x00000004
324 #define FS_DEBUG_IRQ 0x00000008
325 #define FS_DEBUG_INIT 0x00000010
326 #define FS_DEBUG_SEND 0x00000020
327 #define FS_DEBUG_PHY 0x00000040
328 #define FS_DEBUG_CLEANUP 0x00000080
329 #define FS_DEBUG_QOS 0x00000100
330 #define FS_DEBUG_TXQ 0x00000200
331 #define FS_DEBUG_ALLOC 0x00000400
332 #define FS_DEBUG_TXMEM 0x00000800
333 #define FS_DEBUG_QSIZE 0x00001000
336 #define func_enter() fs_dprintk(FS_DEBUG_FLOW, "fs: enter %s\n", __func__)
337 #define func_exit() fs_dprintk(FS_DEBUG_FLOW, "fs: exit %s\n", __func__)
340 static struct fs_dev
*fs_boards
= NULL
;
344 static void my_hd (void *addr
, int len
)
347 unsigned char *ptr
= addr
;
351 for (j
=0;j
< ((len
< 16)?len
:16);j
++) {
352 printk ("%02x %s", ptr
[j
], (j
==7)?" ":"");
355 printk (" %s", (j
==7)?" ":"");
357 for (j
=0;j
< ((len
< 16)?len
:16);j
++) {
359 printk ("%c", (ch
< 0x20)?'.':((ch
> 0x7f)?'.':ch
));
367 static void my_hd (void *addr
, int len
){}
370 /********** free an skb (as per ATM device driver documentation) **********/
372 /* Hmm. If this is ATM specific, why isn't there an ATM routine for this?
373 * I copied it over from the ambassador driver. -- REW */
375 static inline void fs_kfree_skb (struct sk_buff
* skb
)
377 if (ATM_SKB(skb
)->vcc
->pop
)
378 ATM_SKB(skb
)->vcc
->pop (ATM_SKB(skb
)->vcc
, skb
);
380 dev_kfree_skb_any (skb
);
386 /* It seems the ATM forum recommends this horribly complicated 16bit
387 * floating point format. Turns out the Ambassador uses the exact same
388 * encoding. I just copied it over. If Mitch agrees, I'll move it over
389 * to the atm_misc file or something like that. (and remove it from
390 * here and the ambassador driver) -- REW
393 /* The good thing about this format is that it is monotonic. So,
394 a conversion routine need not be very complicated. To be able to
395 round "nearest" we need to take along a few extra bits. Lets
396 put these after 16 bits, so that we can just return the top 16
397 bits of the 32bit number as the result:
399 int mr (unsigned int rate, int r)
402 static int round[4]={0, 0, 0xffff, 0x8000};
404 while (rate & 0xfc000000) {
408 while (! (rate & 0xfe000000)) {
413 // Now the mantissa is in positions bit 16-25. Excepf for the "hidden 1" that's in bit 26.
415 // Next add in the exponent
417 // And perform the rounding:
418 return (rate + round[r]) >> 16;
421 14 lines-of-code. Compare that with the 120 that the Ambassador
422 guys needed. (would be 8 lines shorter if I'd try to really reduce
425 int mr (unsigned int rate, int r)
428 static int round[4]={0, 0, 0xffff, 0x8000};
430 for (; rate & 0xfc000000 ;rate >>= 1, e++);
431 for (;!(rate & 0xfe000000);rate <<= 1, e--);
432 return ((rate & ~0x02000000) | (e << (16+9)) + round[r]) >> 16;
435 Exercise for the reader: Remove one more line-of-code, without
436 cheating. (Just joining two lines is cheating). (I know it's
437 possible, don't think you've beat me if you found it... If you
438 manage to lose two lines or more, keep me updated! ;-)
445 #define ROUND_NEAREST 3
446 /********** make rate (not quite as much fun as Horizon) **********/
448 static int make_rate(unsigned int rate
, int r
,
449 u16
*bits
, unsigned int *actual
)
451 unsigned char exp
= -1; /* hush gcc */
452 unsigned int man
= -1; /* hush gcc */
454 fs_dprintk (FS_DEBUG_QOS
, "make_rate %u", rate
);
456 /* rates in cells per second, ITU format (nasty 16-bit floating-point)
457 given 5-bit e and 9-bit m:
458 rate = EITHER (1+m/2^9)*2^e OR 0
459 bits = EITHER 1<<14 | e<<9 | m OR 0
460 (bit 15 is "reserved", bit 14 "non-zero")
461 smallest rate is 0 (special representation)
462 largest rate is (1+511/512)*2^31 = 4290772992 (< 2^32-1)
463 smallest non-zero rate is (1+0/512)*2^0 = 1 (> 0)
465 find position of top bit, this gives e
466 remove top bit and shift (rounding if feeling clever) by 9-e
468 /* Ambassador ucode bug: please don't set bit 14! so 0 rate not
469 representable. // This should move into the ambassador driver
470 when properly merged. -- REW */
472 if (rate
> 0xffc00000U
) {
473 /* larger than largest representable rate */
483 /* representable rate */
488 /* invariant: rate = man*2^(exp-31) */
489 while (!(man
& (1<<31))) {
494 /* man has top bit set
495 rate = (2^31+(man-2^31))*2^(exp-31)
496 rate = (1+(man-2^31)/2^31)*2^exp
499 man
&= 0xffffffffU
; /* a nop on 32-bit systems */
500 /* rate = (1+man/2^32)*2^exp
502 exp is in the range 0 to 31, man is in the range 0 to 2^32-1
503 time to lose significance... we want m in the range 0 to 2^9-1
504 rounding presents a minor problem... we first decide which way
505 we are rounding (based on given rounding direction and possibly
506 the bits of the mantissa that are to be discarded).
516 /* check all bits that we are discarding */
517 if (man
& (~0U>>9)) {
518 man
= (man
>>(32-9)) + 1;
520 /* no need to check for round up outside of range */
529 case ROUND_NEAREST
: {
530 /* check msb that we are discarding */
531 if (man
& (1<<(32-9-1))) {
532 man
= (man
>>(32-9)) + 1;
534 /* no need to check for round up outside of range */
546 /* zero rate - not representable */
548 if (r
== ROUND_DOWN
) {
556 fs_dprintk (FS_DEBUG_QOS
, "rate: man=%u, exp=%hu", man
, exp
);
559 *bits
= /* (1<<14) | */ (exp
<<9) | man
;
563 ? (1 << exp
) + (man
<< (exp
-9))
564 : (1 << exp
) + ((man
+ (1<<(9-exp
-1))) >> (9-exp
));
572 /* FireStream access routines */
573 /* For DEEP-DOWN debugging these can be rigged to intercept accesses to
574 certain registers or to just log all accesses. */
576 static inline void write_fs (struct fs_dev
*dev
, int offset
, u32 val
)
578 writel (val
, dev
->base
+ offset
);
582 static inline u32
read_fs (struct fs_dev
*dev
, int offset
)
584 return readl (dev
->base
+ offset
);
589 static inline struct FS_QENTRY
*get_qentry (struct fs_dev
*dev
, struct queue
*q
)
591 return bus_to_virt (read_fs (dev
, Q_WP(q
->offset
)) & Q_ADDR_MASK
);
595 static void submit_qentry (struct fs_dev
*dev
, struct queue
*q
, struct FS_QENTRY
*qe
)
598 struct FS_QENTRY
*cqe
;
600 /* XXX Sanity check: the write pointer can be checked to be
601 still the same as the value passed as qe... -- REW */
603 while ((wp
= read_fs (dev
, Q_WP (q
->offset
))) & Q_FULL
) {
604 fs_dprintk (FS_DEBUG_TXQ
, "Found queue at %x full. Waiting.\n",
610 cqe
= bus_to_virt (wp
);
612 fs_dprintk (FS_DEBUG_TXQ
, "q mismatch! %p %p\n", qe
, cqe
);
615 write_fs (dev
, Q_WP(q
->offset
), Q_INCWRAP
);
622 rp
= read_fs (dev
, Q_RP(q
->offset
));
623 wp
= read_fs (dev
, Q_WP(q
->offset
));
624 fs_dprintk (FS_DEBUG_TXQ
, "q at %d: %x-%x: %x entries.\n",
625 q
->offset
, rp
, wp
, wp
-rp
);
631 static struct FS_QENTRY pq
[60];
634 static struct FS_BPENTRY dq
[60];
639 static void submit_queue (struct fs_dev
*dev
, struct queue
*q
,
640 u32 cmd
, u32 p1
, u32 p2
, u32 p3
)
642 struct FS_QENTRY
*qe
;
644 qe
= get_qentry (dev
, q
);
649 submit_qentry (dev
, q
, qe
);
657 if (qp
>= 60) qp
= 0;
661 /* Test the "other" way one day... -- REW */
663 #define submit_command submit_queue
666 static void submit_command (struct fs_dev
*dev
, struct queue
*q
,
667 u32 cmd
, u32 p1
, u32 p2
, u32 p3
)
669 write_fs (dev
, CMDR0
, cmd
);
670 write_fs (dev
, CMDR1
, p1
);
671 write_fs (dev
, CMDR2
, p2
);
672 write_fs (dev
, CMDR3
, p3
);
678 static void process_return_queue (struct fs_dev
*dev
, struct queue
*q
)
681 struct FS_QENTRY
*qe
;
684 while (!((rq
= read_fs (dev
, Q_RP(q
->offset
))) & Q_EMPTY
)) {
685 fs_dprintk (FS_DEBUG_QUEUE
, "reaping return queue entry at %lx\n", rq
);
686 qe
= bus_to_virt (rq
);
688 fs_dprintk (FS_DEBUG_QUEUE
, "queue entry: %08x %08x %08x %08x. (%d)\n",
689 qe
->cmd
, qe
->p0
, qe
->p1
, qe
->p2
, STATUS_CODE (qe
));
691 switch (STATUS_CODE (qe
)) {
693 tc
= bus_to_virt (qe
->p0
);
694 fs_dprintk (FS_DEBUG_ALLOC
, "Free tc: %p\n", tc
);
699 write_fs (dev
, Q_RP(q
->offset
), Q_INCWRAP
);
704 static void process_txdone_queue (struct fs_dev
*dev
, struct queue
*q
)
708 struct FS_QENTRY
*qe
;
710 struct FS_BPENTRY
*td
;
712 while (!((rq
= read_fs (dev
, Q_RP(q
->offset
))) & Q_EMPTY
)) {
713 fs_dprintk (FS_DEBUG_QUEUE
, "reaping txdone entry at %lx\n", rq
);
714 qe
= bus_to_virt (rq
);
716 fs_dprintk (FS_DEBUG_QUEUE
, "queue entry: %08x %08x %08x %08x: %d\n",
717 qe
->cmd
, qe
->p0
, qe
->p1
, qe
->p2
, STATUS_CODE (qe
));
719 if (STATUS_CODE (qe
) != 2)
720 fs_dprintk (FS_DEBUG_TXMEM
, "queue entry: %08x %08x %08x %08x: %d\n",
721 qe
->cmd
, qe
->p0
, qe
->p1
, qe
->p2
, STATUS_CODE (qe
));
724 switch (STATUS_CODE (qe
)) {
725 case 0x01: /* This is for AAL0 where we put the chip in streaming mode */
728 /* Process a real txdone entry. */
731 printk (KERN_WARNING
"td not aligned: %ld\n", tmp
);
733 td
= bus_to_virt (tmp
);
735 fs_dprintk (FS_DEBUG_QUEUE
, "Pool entry: %08x %08x %08x %08x %p.\n",
736 td
->flags
, td
->next
, td
->bsa
, td
->aal_bufsize
, td
->skb
);
739 if (skb
== FS_VCC (ATM_SKB(skb
)->vcc
)->last_skb
) {
740 wake_up_interruptible (& FS_VCC (ATM_SKB(skb
)->vcc
)->close_wait
);
741 FS_VCC (ATM_SKB(skb
)->vcc
)->last_skb
= NULL
;
749 fs_dprintk (FS_DEBUG_QSIZE
, "[%d]", td
->dev
->ntxpckts
);
753 atomic_inc(&ATM_SKB(skb
)->vcc
->stats
->tx
);
755 fs_dprintk (FS_DEBUG_TXMEM
, "i");
756 fs_dprintk (FS_DEBUG_ALLOC
, "Free t-skb: %p\n", skb
);
759 fs_dprintk (FS_DEBUG_ALLOC
, "Free trans-d: %p\n", td
);
760 memset (td
, ATM_POISON_FREE
, sizeof(struct FS_BPENTRY
));
764 /* Here we get the tx purge inhibit command ... */
765 /* Action, I believe, is "don't do anything". -- REW */
769 write_fs (dev
, Q_RP(q
->offset
), Q_INCWRAP
);
774 static void process_incoming (struct fs_dev
*dev
, struct queue
*q
)
777 struct FS_QENTRY
*qe
;
778 struct FS_BPENTRY
*pe
;
781 struct atm_vcc
*atm_vcc
;
783 while (!((rq
= read_fs (dev
, Q_RP(q
->offset
))) & Q_EMPTY
)) {
784 fs_dprintk (FS_DEBUG_QUEUE
, "reaping incoming queue entry at %lx\n", rq
);
785 qe
= bus_to_virt (rq
);
787 fs_dprintk (FS_DEBUG_QUEUE
, "queue entry: %08x %08x %08x %08x. ",
788 qe
->cmd
, qe
->p0
, qe
->p1
, qe
->p2
);
790 fs_dprintk (FS_DEBUG_QUEUE
, "-> %x: %s\n",
792 res_strings
[STATUS_CODE(qe
)]);
794 pe
= bus_to_virt (qe
->p0
);
795 fs_dprintk (FS_DEBUG_QUEUE
, "Pool entry: %08x %08x %08x %08x %p %p.\n",
796 pe
->flags
, pe
->next
, pe
->bsa
, pe
->aal_bufsize
,
799 channo
= qe
->cmd
& 0xffff;
801 if (channo
< dev
->nchannels
)
802 atm_vcc
= dev
->atm_vccs
[channo
];
806 /* Single buffer packet */
807 switch (STATUS_CODE (qe
)) {
809 /* Fall through for streaming mode */
810 case 0x2:/* Packet received OK.... */
815 fs_dprintk (FS_DEBUG_QUEUE
, "Got skb: %p\n", skb
);
816 if (FS_DEBUG_QUEUE
& fs_debug
) my_hd (bus_to_virt (pe
->bsa
), 0x20);
818 skb_put (skb
, qe
->p1
& 0xffff);
819 ATM_SKB(skb
)->vcc
= atm_vcc
;
820 atomic_inc(&atm_vcc
->stats
->rx
);
821 __net_timestamp(skb
);
822 fs_dprintk (FS_DEBUG_ALLOC
, "Free rec-skb: %p (pushed)\n", skb
);
823 atm_vcc
->push (atm_vcc
, skb
);
824 fs_dprintk (FS_DEBUG_ALLOC
, "Free rec-d: %p\n", pe
);
827 printk (KERN_ERR
"Got a receive on a non-open channel %d.\n", channo
);
830 case 0x17:/* AAL 5 CRC32 error. IFF the length field is nonzero, a buffer
831 has been consumed and needs to be processed. -- REW */
832 if (qe
->p1
& 0xffff) {
833 pe
= bus_to_virt (qe
->p0
);
835 fs_dprintk (FS_DEBUG_ALLOC
, "Free rec-skb: %p\n", pe
->skb
);
836 dev_kfree_skb_any (pe
->skb
);
837 fs_dprintk (FS_DEBUG_ALLOC
, "Free rec-d: %p\n", pe
);
841 atomic_inc(&atm_vcc
->stats
->rx_drop
);
843 case 0x1f: /* Reassembly abort: no buffers. */
844 /* Silently increment error counter. */
846 atomic_inc(&atm_vcc
->stats
->rx_drop
);
848 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
849 printk (KERN_WARNING
"Don't know what to do with RX status %x: %s.\n",
850 STATUS_CODE(qe
), res_strings
[STATUS_CODE (qe
)]);
852 write_fs (dev
, Q_RP(q
->offset
), Q_INCWRAP
);
858 #define DO_DIRECTION(tp) ((tp)->traffic_class != ATM_NONE)
860 static int fs_open(struct atm_vcc
*atm_vcc
)
864 struct fs_transmit_config
*tc
;
865 struct atm_trafprm
* txtp
;
866 struct atm_trafprm
* rxtp
;
867 /* struct fs_receive_config *rc;*/
868 /* struct FS_QENTRY *qe; */
873 short vpi
= atm_vcc
->vpi
;
874 int vci
= atm_vcc
->vci
;
878 dev
= FS_DEV(atm_vcc
->dev
);
879 fs_dprintk (FS_DEBUG_OPEN
, "fs: open on dev: %p, vcc at %p\n",
882 if (vci
!= ATM_VPI_UNSPEC
&& vpi
!= ATM_VCI_UNSPEC
)
883 set_bit(ATM_VF_ADDR
, &atm_vcc
->flags
);
885 if ((atm_vcc
->qos
.aal
!= ATM_AAL5
) &&
886 (atm_vcc
->qos
.aal
!= ATM_AAL2
))
887 return -EINVAL
; /* XXX AAL0 */
889 fs_dprintk (FS_DEBUG_OPEN
, "fs: (itf %d): open %d.%d\n",
890 atm_vcc
->dev
->number
, atm_vcc
->vpi
, atm_vcc
->vci
);
892 /* XXX handle qos parameters (rate limiting) ? */
894 vcc
= kmalloc(sizeof(struct fs_vcc
), GFP_KERNEL
);
895 fs_dprintk (FS_DEBUG_ALLOC
, "Alloc VCC: %p(%Zd)\n", vcc
, sizeof(struct fs_vcc
));
897 clear_bit(ATM_VF_ADDR
, &atm_vcc
->flags
);
901 atm_vcc
->dev_data
= vcc
;
902 vcc
->last_skb
= NULL
;
904 init_waitqueue_head (&vcc
->close_wait
);
906 txtp
= &atm_vcc
->qos
.txtp
;
907 rxtp
= &atm_vcc
->qos
.rxtp
;
909 if (!test_bit(ATM_VF_PARTIAL
, &atm_vcc
->flags
)) {
911 /* Increment the channel numer: take a free one next time. */
912 for (to
=33;to
;to
--, dev
->channo
++) {
913 /* We only have 32 channels */
914 if (dev
->channo
>= 32)
916 /* If we need to do RX, AND the RX is inuse, try the next */
917 if (DO_DIRECTION(rxtp
) && dev
->atm_vccs
[dev
->channo
])
919 /* If we need to do TX, AND the TX is inuse, try the next */
920 if (DO_DIRECTION(txtp
) && test_bit (dev
->channo
, dev
->tx_inuse
))
922 /* Ok, both are free! (or not needed) */
926 printk ("No more free channels for FS50..\n");
929 vcc
->channo
= dev
->channo
;
930 dev
->channo
&= dev
->channel_mask
;
933 vcc
->channo
= (vpi
<< FS155_VCI_BITS
) | (vci
);
934 if (((DO_DIRECTION(rxtp
) && dev
->atm_vccs
[vcc
->channo
])) ||
935 ( DO_DIRECTION(txtp
) && test_bit (vcc
->channo
, dev
->tx_inuse
))) {
936 printk ("Channel is in use for FS155.\n");
940 fs_dprintk (FS_DEBUG_OPEN
, "OK. Allocated channel %x(%d).\n",
941 vcc
->channo
, vcc
->channo
);
944 if (DO_DIRECTION (txtp
)) {
945 tc
= kmalloc (sizeof (struct fs_transmit_config
), GFP_KERNEL
);
946 fs_dprintk (FS_DEBUG_ALLOC
, "Alloc tc: %p(%Zd)\n",
947 tc
, sizeof (struct fs_transmit_config
));
949 fs_dprintk (FS_DEBUG_OPEN
, "fs: can't alloc transmit_config.\n");
953 /* Allocate the "open" entry from the high priority txq. This makes
954 it most likely that the chip will notice it. It also prevents us
955 from having to wait for completion. On the other hand, we may
956 need to wait for completion anyway, to see if it completed
959 switch (atm_vcc
->qos
.aal
) {
963 | TC_FLAGS_TRANSPARENT_PAYLOAD
966 | TC_FLAGS_TYPE_UBR
/* XXX Change to VBR -- PVDL */
972 | TC_FLAGS_PACKET
/* ??? */
977 printk ("Unknown aal: %d\n", atm_vcc
->qos
.aal
);
980 /* Docs are vague about this atm_hdr field. By the way, the FS
981 * chip makes odd errors if lower bits are set.... -- REW */
982 tc
->atm_hdr
= (vpi
<< 20) | (vci
<< 4);
985 int pcr
= atm_pcr_goal (txtp
);
987 fs_dprintk (FS_DEBUG_OPEN
, "pcr = %d.\n", pcr
);
989 /* XXX Hmm. officially we're only allowed to do this if rounding
990 is round_down -- REW */
992 if (pcr
> 51840000/53/8) pcr
= 51840000/53/8;
994 if (pcr
> 155520000/53/8) pcr
= 155520000/53/8;
998 tmc0
= IS_FS50(dev
)?0x61BE:0x64c9; /* Just copied over the bits from Fujitsu -- REW */
1007 error
= make_rate (pcr
, r
, &tmc0
, NULL
);
1013 fs_dprintk (FS_DEBUG_OPEN
, "pcr = %d.\n", pcr
);
1016 tc
->TMC
[0] = tmc0
| 0x4000;
1017 tc
->TMC
[1] = 0; /* Unused */
1018 tc
->TMC
[2] = 0; /* Unused */
1019 tc
->TMC
[3] = 0; /* Unused */
1021 tc
->spec
= 0; /* UTOPIA address, UDF, HEC: Unused -> 0 */
1022 tc
->rtag
[0] = 0; /* What should I do with routing tags???
1023 -- Not used -- AS -- Thanks -- REW*/
1027 if (fs_debug
& FS_DEBUG_OPEN
) {
1028 fs_dprintk (FS_DEBUG_OPEN
, "TX config record:\n");
1029 my_hd (tc
, sizeof (*tc
));
1032 /* We now use the "submit_command" function to submit commands to
1033 the firestream. There is a define up near the definition of
1034 that routine that switches this routine between immediate write
1035 to the immediate command registers and queuing the commands in
1036 the HPTXQ for execution. This last technique might be more
1037 efficient if we know we're going to submit a whole lot of
1038 commands in one go, but this driver is not setup to be able to
1039 use such a construct. So it probably doen't matter much right
1042 /* The command is IMMediate and INQueue. The parameters are out-of-line.. */
1043 submit_command (dev
, &dev
->hp_txq
,
1044 QE_CMD_CONFIG_TX
| QE_CMD_IMM_INQ
| vcc
->channo
,
1045 virt_to_bus (tc
), 0, 0);
1047 submit_command (dev
, &dev
->hp_txq
,
1048 QE_CMD_TX_EN
| QE_CMD_IMM_INQ
| vcc
->channo
,
1050 set_bit (vcc
->channo
, dev
->tx_inuse
);
1053 if (DO_DIRECTION (rxtp
)) {
1054 dev
->atm_vccs
[vcc
->channo
] = atm_vcc
;
1056 for (bfp
= 0;bfp
< FS_NR_FREE_POOLS
; bfp
++)
1057 if (atm_vcc
->qos
.rxtp
.max_sdu
<= dev
->rx_fp
[bfp
].bufsize
) break;
1058 if (bfp
>= FS_NR_FREE_POOLS
) {
1059 fs_dprintk (FS_DEBUG_OPEN
, "No free pool fits sdu: %d.\n",
1060 atm_vcc
->qos
.rxtp
.max_sdu
);
1061 /* XXX Cleanup? -- Would just calling fs_close work??? -- REW */
1063 /* XXX clear tx inuse. Close TX part? */
1064 dev
->atm_vccs
[vcc
->channo
] = NULL
;
1069 switch (atm_vcc
->qos
.aal
) {
1072 submit_command (dev
, &dev
->hp_txq
,
1073 QE_CMD_CONFIG_RX
| QE_CMD_IMM_INQ
| vcc
->channo
,
1075 RC_FLAGS_BFPS_BFP
* bfp
|
1076 RC_FLAGS_RXBM_PSB
, 0, 0);
1079 submit_command (dev
, &dev
->hp_txq
,
1080 QE_CMD_CONFIG_RX
| QE_CMD_IMM_INQ
| vcc
->channo
,
1082 RC_FLAGS_BFPS_BFP
* bfp
|
1083 RC_FLAGS_RXBM_PSB
, 0, 0);
1086 if (IS_FS50 (dev
)) {
1087 submit_command (dev
, &dev
->hp_txq
,
1088 QE_CMD_REG_WR
| QE_CMD_IMM_INQ
,
1090 (vpi
<< 16) | vci
, 0 ); /* XXX -- Use defines. */
1092 submit_command (dev
, &dev
->hp_txq
,
1093 QE_CMD_RX_EN
| QE_CMD_IMM_INQ
| vcc
->channo
,
1097 /* Indicate we're done! */
1098 set_bit(ATM_VF_READY
, &atm_vcc
->flags
);
1105 static void fs_close(struct atm_vcc
*atm_vcc
)
1107 struct fs_dev
*dev
= FS_DEV (atm_vcc
->dev
);
1108 struct fs_vcc
*vcc
= FS_VCC (atm_vcc
);
1109 struct atm_trafprm
* txtp
;
1110 struct atm_trafprm
* rxtp
;
1114 clear_bit(ATM_VF_READY
, &atm_vcc
->flags
);
1116 fs_dprintk (FS_DEBUG_QSIZE
, "--==**[%d]**==--", dev
->ntxpckts
);
1117 if (vcc
->last_skb
) {
1118 fs_dprintk (FS_DEBUG_QUEUE
, "Waiting for skb %p to be sent.\n",
1120 /* We're going to wait for the last packet to get sent on this VC. It would
1121 be impolite not to send them don't you think?
1123 We don't know which packets didn't get sent. So if we get interrupted in
1124 this sleep_on, we'll lose any reference to these packets. Memory leak!
1125 On the other hand, it's awfully convenient that we can abort a "close" that
1126 is taking too long. Maybe just use non-interruptible sleep on? -- REW */
1127 interruptible_sleep_on (& vcc
->close_wait
);
1130 txtp
= &atm_vcc
->qos
.txtp
;
1131 rxtp
= &atm_vcc
->qos
.rxtp
;
1134 /* See App note XXX (Unpublished as of now) for the reason for the
1135 removal of the "CMD_IMM_INQ" part of the TX_PURGE_INH... -- REW */
1137 if (DO_DIRECTION (txtp
)) {
1138 submit_command (dev
, &dev
->hp_txq
,
1139 QE_CMD_TX_PURGE_INH
| /*QE_CMD_IMM_INQ|*/ vcc
->channo
, 0,0,0);
1140 clear_bit (vcc
->channo
, dev
->tx_inuse
);
1143 if (DO_DIRECTION (rxtp
)) {
1144 submit_command (dev
, &dev
->hp_txq
,
1145 QE_CMD_RX_PURGE_INH
| QE_CMD_IMM_INQ
| vcc
->channo
, 0,0,0);
1146 dev
->atm_vccs
[vcc
->channo
] = NULL
;
1148 /* This means that this is configured as a receive channel */
1149 if (IS_FS50 (dev
)) {
1150 /* Disable the receive filter. Is 0/0 indeed an invalid receive
1151 channel? -- REW. Yes it is. -- Hang. Ok. I'll use -1
1152 (0xfff...) -- REW */
1153 submit_command (dev
, &dev
->hp_txq
,
1154 QE_CMD_REG_WR
| QE_CMD_IMM_INQ
,
1155 0x80 + vcc
->channo
, -1, 0 );
1159 fs_dprintk (FS_DEBUG_ALLOC
, "Free vcc: %p\n", vcc
);
1166 static int fs_send (struct atm_vcc
*atm_vcc
, struct sk_buff
*skb
)
1168 struct fs_dev
*dev
= FS_DEV (atm_vcc
->dev
);
1169 struct fs_vcc
*vcc
= FS_VCC (atm_vcc
);
1170 struct FS_BPENTRY
*td
;
1174 fs_dprintk (FS_DEBUG_TXMEM
, "I");
1175 fs_dprintk (FS_DEBUG_SEND
, "Send: atm_vcc %p skb %p vcc %p dev %p\n",
1176 atm_vcc
, skb
, vcc
, dev
);
1178 fs_dprintk (FS_DEBUG_ALLOC
, "Alloc t-skb: %p (atm_send)\n", skb
);
1180 ATM_SKB(skb
)->vcc
= atm_vcc
;
1182 vcc
->last_skb
= skb
;
1184 td
= kmalloc (sizeof (struct FS_BPENTRY
), GFP_ATOMIC
);
1185 fs_dprintk (FS_DEBUG_ALLOC
, "Alloc transd: %p(%Zd)\n", td
, sizeof (struct FS_BPENTRY
));
1187 /* Oops out of mem */
1191 fs_dprintk (FS_DEBUG_SEND
, "first word in buffer: %x\n",
1192 *(int *) skb
->data
);
1194 td
->flags
= TD_EPI
| TD_DATA
| skb
->len
;
1196 td
->bsa
= virt_to_bus (skb
->data
);
1203 dq
[qd
].flags
= td
->flags
;
1204 dq
[qd
].next
= td
->next
;
1205 dq
[qd
].bsa
= td
->bsa
;
1206 dq
[qd
].skb
= td
->skb
;
1207 dq
[qd
].dev
= td
->dev
;
1209 if (qd
>= 60) qd
= 0;
1212 submit_queue (dev
, &dev
->hp_txq
,
1213 QE_TRANSMIT_DE
| vcc
->channo
,
1214 virt_to_bus (td
), 0,
1217 fs_dprintk (FS_DEBUG_QUEUE
, "in send: txq %d txrq %d\n",
1218 read_fs (dev
, Q_EA (dev
->hp_txq
.offset
)) -
1219 read_fs (dev
, Q_SA (dev
->hp_txq
.offset
)),
1220 read_fs (dev
, Q_EA (dev
->tx_relq
.offset
)) -
1221 read_fs (dev
, Q_SA (dev
->tx_relq
.offset
)));
1228 /* Some function placeholders for functions we don't yet support. */
1231 static int fs_ioctl(struct atm_dev
*dev
,unsigned int cmd
,void __user
*arg
)
1235 return -ENOIOCTLCMD
;
1239 static int fs_getsockopt(struct atm_vcc
*vcc
,int level
,int optname
,
1240 void __user
*optval
,int optlen
)
1248 static int fs_setsockopt(struct atm_vcc
*vcc
,int level
,int optname
,
1249 void __user
*optval
,unsigned int optlen
)
1257 static void fs_phy_put(struct atm_dev
*dev
,unsigned char value
,
1265 static unsigned char fs_phy_get(struct atm_dev
*dev
,unsigned long addr
)
1273 static int fs_change_qos(struct atm_vcc
*vcc
,struct atm_qos
*qos
,int flags
)
1283 static const struct atmdev_ops ops
= {
1287 .owner
= THIS_MODULE
,
1288 /* ioctl: fs_ioctl, */
1289 /* getsockopt: fs_getsockopt, */
1290 /* setsockopt: fs_setsockopt, */
1291 /* change_qos: fs_change_qos, */
1293 /* For now implement these internally here... */
1294 /* phy_put: fs_phy_put, */
1295 /* phy_get: fs_phy_get, */
1299 static void __devinit
undocumented_pci_fix (struct pci_dev
*pdev
)
1303 /* The Windows driver says: */
1304 /* Switch off FireStream Retry Limit Threshold
1307 /* The register at 0x28 is documented as "reserved", no further
1310 pci_read_config_dword (pdev
, 0x28, &tint
);
1313 pci_write_config_dword (pdev
, 0x28, tint
);
1319 /**************************************************************************
1321 **************************************************************************/
1323 static void __devinit
write_phy (struct fs_dev
*dev
, int regnum
, int val
)
1325 submit_command (dev
, &dev
->hp_txq
, QE_CMD_PRP_WR
| QE_CMD_IMM_INQ
,
1329 static int __devinit
init_phy (struct fs_dev
*dev
, struct reginit_item
*reginit
)
1334 while (reginit
->reg
!= PHY_EOF
) {
1335 if (reginit
->reg
== PHY_CLEARALL
) {
1336 /* "PHY_CLEARALL means clear all registers. Numregisters is in "val". */
1337 for (i
=0;i
<reginit
->val
;i
++) {
1338 write_phy (dev
, i
, 0);
1341 write_phy (dev
, reginit
->reg
, reginit
->val
);
1349 static void reset_chip (struct fs_dev
*dev
)
1353 write_fs (dev
, SARMODE0
, SARMODE0_SRTS0
);
1355 /* Undocumented delay */
1358 /* The "internal registers are documented to all reset to zero, but
1359 comments & code in the Windows driver indicates that the pools are
1361 for (i
=0;i
< FS_NR_FREE_POOLS
;i
++) {
1362 write_fs (dev
, FP_CNF (RXB_FP(i
)), 0);
1363 write_fs (dev
, FP_SA (RXB_FP(i
)), 0);
1364 write_fs (dev
, FP_EA (RXB_FP(i
)), 0);
1365 write_fs (dev
, FP_CNT (RXB_FP(i
)), 0);
1366 write_fs (dev
, FP_CTU (RXB_FP(i
)), 0);
1369 /* The same goes for the match channel registers, although those are
1370 NOT documented that way in the Windows driver. -- REW */
1371 /* The Windows driver DOES write 0 to these registers somewhere in
1372 the init sequence. However, a small hardware-feature, will
1373 prevent reception of data on VPI/VCI = 0/0 (Unless the channel
1374 allocated happens to have no disabled channels that have a lower
1377 /* Clear the match channel registers. */
1378 if (IS_FS50 (dev
)) {
1379 for (i
=0;i
<FS50_NR_CHANNELS
;i
++) {
1380 write_fs (dev
, 0x200 + i
* 4, -1);
1385 static void __devinit
*aligned_kmalloc (int size
, gfp_t flags
, int alignment
)
1389 if (alignment
<= 0x10) {
1390 t
= kmalloc (size
, flags
);
1391 if ((unsigned long)t
& (alignment
-1)) {
1392 printk ("Kmalloc doesn't align things correctly! %p\n", t
);
1394 return aligned_kmalloc (size
, flags
, alignment
* 4);
1398 printk (KERN_ERR
"Request for > 0x10 alignment not yet implemented (hard!)\n");
1402 static int __devinit
init_q (struct fs_dev
*dev
,
1403 struct queue
*txq
, int queue
, int nentries
, int is_rq
)
1405 int sz
= nentries
* sizeof (struct FS_QENTRY
);
1406 struct FS_QENTRY
*p
;
1410 fs_dprintk (FS_DEBUG_INIT
, "Inititing queue at %x: %d entries:\n",
1413 p
= aligned_kmalloc (sz
, GFP_KERNEL
, 0x10);
1414 fs_dprintk (FS_DEBUG_ALLOC
, "Alloc queue: %p(%d)\n", p
, sz
);
1418 write_fs (dev
, Q_SA(queue
), virt_to_bus(p
));
1419 write_fs (dev
, Q_EA(queue
), virt_to_bus(p
+nentries
-1));
1420 write_fs (dev
, Q_WP(queue
), virt_to_bus(p
));
1421 write_fs (dev
, Q_RP(queue
), virt_to_bus(p
));
1423 /* Configuration for the receive queue: 0: interrupt immediately,
1424 no pre-warning to empty queues: We do our best to keep the
1425 queue filled anyway. */
1426 write_fs (dev
, Q_CNF(queue
), 0 );
1431 txq
->offset
= queue
;
1438 static int __devinit
init_fp (struct fs_dev
*dev
,
1439 struct freepool
*fp
, int queue
, int bufsize
, int nr_buffers
)
1443 fs_dprintk (FS_DEBUG_INIT
, "Inititing free pool at %x:\n", queue
);
1445 write_fs (dev
, FP_CNF(queue
), (bufsize
* RBFP_RBS
) | RBFP_RBSVAL
| RBFP_CME
);
1446 write_fs (dev
, FP_SA(queue
), 0);
1447 write_fs (dev
, FP_EA(queue
), 0);
1448 write_fs (dev
, FP_CTU(queue
), 0);
1449 write_fs (dev
, FP_CNT(queue
), 0);
1452 fp
->bufsize
= bufsize
;
1453 fp
->nr_buffers
= nr_buffers
;
1460 static inline int nr_buffers_in_freepool (struct fs_dev
*dev
, struct freepool
*fp
)
1463 /* This seems to be unreliable.... */
1464 return read_fs (dev
, FP_CNT (fp
->offset
));
1471 /* Check if this gets going again if a pool ever runs out. -- Yes, it
1472 does. I've seen "receive abort: no buffers" and things started
1473 working again after that... -- REW */
1475 static void top_off_fp (struct fs_dev
*dev
, struct freepool
*fp
,
1478 struct FS_BPENTRY
*qe
, *ne
;
1479 struct sk_buff
*skb
;
1483 fs_dprintk (FS_DEBUG_QUEUE
, "Topping off queue at %x (%d-%d/%d)\n",
1484 fp
->offset
, read_fs (dev
, FP_CNT (fp
->offset
)), fp
->n
,
1486 while (nr_buffers_in_freepool(dev
, fp
) < fp
->nr_buffers
) {
1488 skb
= alloc_skb (fp
->bufsize
, gfp_flags
);
1489 fs_dprintk (FS_DEBUG_ALLOC
, "Alloc rec-skb: %p(%d)\n", skb
, fp
->bufsize
);
1491 ne
= kmalloc (sizeof (struct FS_BPENTRY
), gfp_flags
);
1492 fs_dprintk (FS_DEBUG_ALLOC
, "Alloc rec-d: %p(%Zd)\n", ne
, sizeof (struct FS_BPENTRY
));
1494 fs_dprintk (FS_DEBUG_ALLOC
, "Free rec-skb: %p\n", skb
);
1495 dev_kfree_skb_any (skb
);
1499 fs_dprintk (FS_DEBUG_QUEUE
, "Adding skb %p desc %p -> %p(%p) ",
1500 skb
, ne
, skb
->data
, skb
->head
);
1502 ne
->flags
= FP_FLAGS_EPI
| fp
->bufsize
;
1503 ne
->next
= virt_to_bus (NULL
);
1504 ne
->bsa
= virt_to_bus (skb
->data
);
1505 ne
->aal_bufsize
= fp
->bufsize
;
1510 * FIXME: following code encodes and decodes
1511 * machine pointers (could be 64-bit) into a
1515 qe_tmp
= read_fs (dev
, FP_EA(fp
->offset
));
1516 fs_dprintk (FS_DEBUG_QUEUE
, "link at %x\n", qe_tmp
);
1518 qe
= bus_to_virt ((long) qe_tmp
);
1519 qe
->next
= virt_to_bus(ne
);
1520 qe
->flags
&= ~FP_FLAGS_EPI
;
1522 write_fs (dev
, FP_SA(fp
->offset
), virt_to_bus(ne
));
1524 write_fs (dev
, FP_EA(fp
->offset
), virt_to_bus (ne
));
1525 fp
->n
++; /* XXX Atomic_inc? */
1526 write_fs (dev
, FP_CTU(fp
->offset
), 1);
1529 fs_dprintk (FS_DEBUG_QUEUE
, "Added %d entries. \n", n
);
1532 static void __devexit
free_queue (struct fs_dev
*dev
, struct queue
*txq
)
1536 write_fs (dev
, Q_SA(txq
->offset
), 0);
1537 write_fs (dev
, Q_EA(txq
->offset
), 0);
1538 write_fs (dev
, Q_RP(txq
->offset
), 0);
1539 write_fs (dev
, Q_WP(txq
->offset
), 0);
1540 /* Configuration ? */
1542 fs_dprintk (FS_DEBUG_ALLOC
, "Free queue: %p\n", txq
->sa
);
1548 static void __devexit
free_freepool (struct fs_dev
*dev
, struct freepool
*fp
)
1552 write_fs (dev
, FP_CNF(fp
->offset
), 0);
1553 write_fs (dev
, FP_SA (fp
->offset
), 0);
1554 write_fs (dev
, FP_EA (fp
->offset
), 0);
1555 write_fs (dev
, FP_CNT(fp
->offset
), 0);
1556 write_fs (dev
, FP_CTU(fp
->offset
), 0);
1563 static irqreturn_t
fs_irq (int irq
, void *dev_id
)
1567 struct fs_dev
*dev
= dev_id
;
1569 status
= read_fs (dev
, ISR
);
1575 #ifdef IRQ_RATE_LIMIT
1576 /* Aaargh! I'm ashamed. This costs more lines-of-code than the actual
1577 interrupt routine!. (Well, used to when I wrote that comment) -- REW */
1582 if (lastjif
== jiffies
) {
1583 if (++nintr
> IRQ_RATE_LIMIT
) {
1584 free_irq (dev
->irq
, dev_id
);
1585 printk (KERN_ERR
"fs: Too many interrupts. Turning off interrupt %d.\n",
1594 fs_dprintk (FS_DEBUG_QUEUE
, "in intr: txq %d txrq %d\n",
1595 read_fs (dev
, Q_EA (dev
->hp_txq
.offset
)) -
1596 read_fs (dev
, Q_SA (dev
->hp_txq
.offset
)),
1597 read_fs (dev
, Q_EA (dev
->tx_relq
.offset
)) -
1598 read_fs (dev
, Q_SA (dev
->tx_relq
.offset
)));
1600 /* print the bits in the ISR register. */
1601 if (fs_debug
& FS_DEBUG_IRQ
) {
1602 /* The FS_DEBUG things are unnecessary here. But this way it is
1603 clear for grep that these are debug prints. */
1604 fs_dprintk (FS_DEBUG_IRQ
, "IRQ status:");
1606 if (status
& (1 << i
))
1607 fs_dprintk (FS_DEBUG_IRQ
, " %s", irq_bitname
[i
]);
1608 fs_dprintk (FS_DEBUG_IRQ
, "\n");
1611 if (status
& ISR_RBRQ0_W
) {
1612 fs_dprintk (FS_DEBUG_IRQ
, "Iiiin-coming (0)!!!!\n");
1613 process_incoming (dev
, &dev
->rx_rq
[0]);
1614 /* items mentioned on RBRQ0 are from FP 0 or 1. */
1615 top_off_fp (dev
, &dev
->rx_fp
[0], GFP_ATOMIC
);
1616 top_off_fp (dev
, &dev
->rx_fp
[1], GFP_ATOMIC
);
1619 if (status
& ISR_RBRQ1_W
) {
1620 fs_dprintk (FS_DEBUG_IRQ
, "Iiiin-coming (1)!!!!\n");
1621 process_incoming (dev
, &dev
->rx_rq
[1]);
1622 top_off_fp (dev
, &dev
->rx_fp
[2], GFP_ATOMIC
);
1623 top_off_fp (dev
, &dev
->rx_fp
[3], GFP_ATOMIC
);
1626 if (status
& ISR_RBRQ2_W
) {
1627 fs_dprintk (FS_DEBUG_IRQ
, "Iiiin-coming (2)!!!!\n");
1628 process_incoming (dev
, &dev
->rx_rq
[2]);
1629 top_off_fp (dev
, &dev
->rx_fp
[4], GFP_ATOMIC
);
1630 top_off_fp (dev
, &dev
->rx_fp
[5], GFP_ATOMIC
);
1633 if (status
& ISR_RBRQ3_W
) {
1634 fs_dprintk (FS_DEBUG_IRQ
, "Iiiin-coming (3)!!!!\n");
1635 process_incoming (dev
, &dev
->rx_rq
[3]);
1636 top_off_fp (dev
, &dev
->rx_fp
[6], GFP_ATOMIC
);
1637 top_off_fp (dev
, &dev
->rx_fp
[7], GFP_ATOMIC
);
1640 if (status
& ISR_CSQ_W
) {
1641 fs_dprintk (FS_DEBUG_IRQ
, "Command executed ok!\n");
1642 process_return_queue (dev
, &dev
->st_q
);
1645 if (status
& ISR_TBRQ_W
) {
1646 fs_dprintk (FS_DEBUG_IRQ
, "Data tramsitted!\n");
1647 process_txdone_queue (dev
, &dev
->tx_relq
);
1656 static void fs_poll (unsigned long data
)
1658 struct fs_dev
*dev
= (struct fs_dev
*) data
;
1661 dev
->timer
.expires
= jiffies
+ FS_POLL_FREQ
;
1662 add_timer (&dev
->timer
);
1666 static int __devinit
fs_init (struct fs_dev
*dev
)
1668 struct pci_dev
*pci_dev
;
1673 pci_dev
= dev
->pci_dev
;
1675 printk (KERN_INFO
"found a FireStream %d card, base %16llx, irq%d.\n",
1676 IS_FS50(dev
)?50:155,
1677 (unsigned long long)pci_resource_start(pci_dev
, 0),
1680 if (fs_debug
& FS_DEBUG_INIT
)
1681 my_hd ((unsigned char *) dev
, sizeof (*dev
));
1683 undocumented_pci_fix (pci_dev
);
1685 dev
->hw_base
= pci_resource_start(pci_dev
, 0);
1687 dev
->base
= ioremap(dev
->hw_base
, 0x1000);
1691 write_fs (dev
, SARMODE0
, 0
1692 | (0 * SARMODE0_SHADEN
) /* We don't use shadow registers. */
1693 | (1 * SARMODE0_INTMODE_READCLEAR
)
1694 | (1 * SARMODE0_CWRE
)
1695 | (IS_FS50(dev
) ? SARMODE0_PRPWT_FS50_5
:
1696 SARMODE0_PRPWT_FS155_3
)
1697 | (1 * SARMODE0_CALSUP_1
)
1698 | (IS_FS50(dev
) ? (0
1700 | SARMODE0_ABRVCS_32
1701 | SARMODE0_TXVCS_32
):
1704 | SARMODE0_ABRVCS_1k
1705 | SARMODE0_TXVCS_1k
)));
1707 /* 10ms * 100 is 1 second. That should be enough, as AN3:9 says it takes
1711 isr
= read_fs (dev
, ISR
);
1713 /* This bit is documented as "RESERVED" */
1714 if (isr
& ISR_INIT_ERR
) {
1715 printk (KERN_ERR
"Error initializing the FS... \n");
1718 if (isr
& ISR_INIT
) {
1719 fs_dprintk (FS_DEBUG_INIT
, "Ha! Initialized OK!\n");
1723 /* Try again after 10ms. */
1728 printk (KERN_ERR
"timeout initializing the FS... \n");
1732 /* XXX fix for fs155 */
1733 dev
->channel_mask
= 0x1f;
1737 write_fs (dev
, SARMODE1
, 0
1738 | (fs_keystream
* SARMODE1_DEFHEC
) /* XXX PHY */
1739 | ((loopback
== 1) * SARMODE1_TSTLP
) /* XXX Loopback mode enable... */
1740 | (1 * SARMODE1_DCRM
)
1741 | (1 * SARMODE1_DCOAM
)
1742 | (0 * SARMODE1_OAMCRC
)
1743 | (0 * SARMODE1_DUMPE
)
1744 | (0 * SARMODE1_GPLEN
)
1745 | (0 * SARMODE1_GNAM
)
1746 | (0 * SARMODE1_GVAS
)
1747 | (0 * SARMODE1_GPAS
)
1748 | (1 * SARMODE1_GPRI
)
1749 | (0 * SARMODE1_PMS
)
1750 | (0 * SARMODE1_GFCR
)
1751 | (1 * SARMODE1_HECM2
)
1752 | (1 * SARMODE1_HECM1
)
1753 | (1 * SARMODE1_HECM0
)
1754 | (1 << 12) /* That's what hang's driver does. Program to 0 */
1755 | (0 * 0xff) /* XXX FS155 */);
1758 /* Cal prescale etc */
1761 write_fs (dev
, TMCONF
, 0x0000000f);
1762 write_fs (dev
, CALPRESCALE
, 0x01010101 * num
);
1763 write_fs (dev
, 0x80, 0x000F00E4);
1766 write_fs (dev
, CELLOSCONF
, 0
1767 | ( 0 * CELLOSCONF_CEN
)
1769 | (0x80 * CELLOSCONF_COBS
)
1770 | (num
* CELLOSCONF_COPK
) /* Changed from 0xff to 0x5a */
1771 | (num
* CELLOSCONF_COST
));/* after a hint from Hang.
1772 * performance jumped 50->70... */
1774 /* Magic value by Hang */
1775 write_fs (dev
, CELLOSCONF_COST
, 0x0B809191);
1777 if (IS_FS50 (dev
)) {
1778 write_fs (dev
, RAS0
, RAS0_DCD_XHLT
);
1779 dev
->atm_dev
->ci_range
.vpi_bits
= 12;
1780 dev
->atm_dev
->ci_range
.vci_bits
= 16;
1781 dev
->nchannels
= FS50_NR_CHANNELS
;
1783 write_fs (dev
, RAS0
, RAS0_DCD_XHLT
1784 | (((1 << FS155_VPI_BITS
) - 1) * RAS0_VPSEL
)
1785 | (((1 << FS155_VCI_BITS
) - 1) * RAS0_VCSEL
));
1786 /* We can chose the split arbitrarily. We might be able to
1787 support more. Whatever. This should do for now. */
1788 dev
->atm_dev
->ci_range
.vpi_bits
= FS155_VPI_BITS
;
1789 dev
->atm_dev
->ci_range
.vci_bits
= FS155_VCI_BITS
;
1791 /* Address bits we can't use should be compared to 0. */
1792 write_fs (dev
, RAC
, 0);
1794 /* Manual (AN9, page 6) says ASF1=0 means compare Utopia address
1795 * too. I can't find ASF1 anywhere. Anyway, we AND with just the
1796 * other bits, then compare with 0, which is exactly what we
1798 write_fs (dev
, RAM
, (1 << (28 - FS155_VPI_BITS
- FS155_VCI_BITS
)) - 1);
1799 dev
->nchannels
= FS155_NR_CHANNELS
;
1801 dev
->atm_vccs
= kcalloc (dev
->nchannels
, sizeof (struct atm_vcc
*),
1803 fs_dprintk (FS_DEBUG_ALLOC
, "Alloc atmvccs: %p(%Zd)\n",
1804 dev
->atm_vccs
, dev
->nchannels
* sizeof (struct atm_vcc
*));
1806 if (!dev
->atm_vccs
) {
1807 printk (KERN_WARNING
"Couldn't allocate memory for VCC buffers. Woops!\n");
1808 /* XXX Clean up..... */
1812 dev
->tx_inuse
= kzalloc (dev
->nchannels
/ 8 /* bits/byte */ , GFP_KERNEL
);
1813 fs_dprintk (FS_DEBUG_ALLOC
, "Alloc tx_inuse: %p(%d)\n",
1814 dev
->atm_vccs
, dev
->nchannels
/ 8);
1816 if (!dev
->tx_inuse
) {
1817 printk (KERN_WARNING
"Couldn't allocate memory for tx_inuse bits!\n");
1818 /* XXX Clean up..... */
1821 /* -- RAS1 : FS155 and 50 differ. Default (0) should be OK for both */
1822 /* -- RAS2 : FS50 only: Default is OK. */
1824 /* DMAMODE, default should be OK. -- REW */
1825 write_fs (dev
, DMAMR
, DMAMR_TX_MODE_FULL
);
1827 init_q (dev
, &dev
->hp_txq
, TX_PQ(TXQ_HP
), TXQ_NENTRIES
, 0);
1828 init_q (dev
, &dev
->lp_txq
, TX_PQ(TXQ_LP
), TXQ_NENTRIES
, 0);
1829 init_q (dev
, &dev
->tx_relq
, TXB_RQ
, TXQ_NENTRIES
, 1);
1830 init_q (dev
, &dev
->st_q
, ST_Q
, TXQ_NENTRIES
, 1);
1832 for (i
=0;i
< FS_NR_FREE_POOLS
;i
++) {
1833 init_fp (dev
, &dev
->rx_fp
[i
], RXB_FP(i
),
1834 rx_buf_sizes
[i
], rx_pool_sizes
[i
]);
1835 top_off_fp (dev
, &dev
->rx_fp
[i
], GFP_KERNEL
);
1839 for (i
=0;i
< FS_NR_RX_QUEUES
;i
++)
1840 init_q (dev
, &dev
->rx_rq
[i
], RXB_RQ(i
), RXRQ_NENTRIES
, 1);
1842 dev
->irq
= pci_dev
->irq
;
1843 if (request_irq (dev
->irq
, fs_irq
, IRQF_SHARED
, "firestream", dev
)) {
1844 printk (KERN_WARNING
"couldn't get irq %d for firestream.\n", pci_dev
->irq
);
1845 /* XXX undo all previous stuff... */
1848 fs_dprintk (FS_DEBUG_INIT
, "Grabbed irq %d for dev at %p.\n", dev
->irq
, dev
);
1850 /* We want to be notified of most things. Just the statistics count
1851 overflows are not interesting */
1852 write_fs (dev
, IMR
, 0
1860 write_fs (dev
, SARMODE0
, 0
1861 | (0 * SARMODE0_SHADEN
) /* We don't use shadow registers. */
1862 | (1 * SARMODE0_GINT
)
1863 | (1 * SARMODE0_INTMODE_READCLEAR
)
1864 | (0 * SARMODE0_CWRE
)
1865 | (IS_FS50(dev
)?SARMODE0_PRPWT_FS50_5
:
1866 SARMODE0_PRPWT_FS155_3
)
1867 | (1 * SARMODE0_CALSUP_1
)
1870 | SARMODE0_ABRVCS_32
1871 | SARMODE0_TXVCS_32
):
1874 | SARMODE0_ABRVCS_1k
1875 | SARMODE0_TXVCS_1k
))
1876 | (1 * SARMODE0_RUN
));
1878 init_phy (dev
, PHY_NTC_INIT
);
1880 if (loopback
== 2) {
1881 write_phy (dev
, 0x39, 0x000e);
1885 init_timer (&dev
->timer
);
1886 dev
->timer
.data
= (unsigned long) dev
;
1887 dev
->timer
.function
= fs_poll
;
1888 dev
->timer
.expires
= jiffies
+ FS_POLL_FREQ
;
1889 add_timer (&dev
->timer
);
1892 dev
->atm_dev
->dev_data
= dev
;
1901 static int __devinit
firestream_init_one (struct pci_dev
*pci_dev
,
1902 const struct pci_device_id
*ent
)
1904 struct atm_dev
*atm_dev
;
1905 struct fs_dev
*fs_dev
;
1907 if (pci_enable_device(pci_dev
))
1910 fs_dev
= kzalloc (sizeof (struct fs_dev
), GFP_KERNEL
);
1911 fs_dprintk (FS_DEBUG_ALLOC
, "Alloc fs-dev: %p(%Zd)\n",
1912 fs_dev
, sizeof (struct fs_dev
));
1915 atm_dev
= atm_dev_register("fs", &pci_dev
->dev
, &ops
, -1, NULL
);
1917 goto err_out_free_fs_dev
;
1919 fs_dev
->pci_dev
= pci_dev
;
1920 fs_dev
->atm_dev
= atm_dev
;
1921 fs_dev
->flags
= ent
->driver_data
;
1923 if (fs_init(fs_dev
))
1924 goto err_out_free_atm_dev
;
1926 fs_dev
->next
= fs_boards
;
1930 err_out_free_atm_dev
:
1931 atm_dev_deregister(atm_dev
);
1932 err_out_free_fs_dev
:
1938 static void __devexit
firestream_remove_one (struct pci_dev
*pdev
)
1941 struct fs_dev
*dev
, *nxtdev
;
1943 struct FS_BPENTRY
*fp
, *nxt
;
1948 printk ("hptxq:\n");
1949 for (i
=0;i
<60;i
++) {
1950 printk ("%d: %08x %08x %08x %08x \n",
1951 i
, pq
[qp
].cmd
, pq
[qp
].p0
, pq
[qp
].p1
, pq
[qp
].p2
);
1953 if (qp
>= 60) qp
= 0;
1956 printk ("descriptors:\n");
1957 for (i
=0;i
<60;i
++) {
1958 printk ("%d: %p: %08x %08x %p %p\n",
1959 i
, da
[qd
], dq
[qd
].flags
, dq
[qd
].bsa
, dq
[qd
].skb
, dq
[qd
].dev
);
1961 if (qd
>= 60) qd
= 0;
1965 for (dev
= fs_boards
;dev
!= NULL
;dev
=nxtdev
) {
1966 fs_dprintk (FS_DEBUG_CLEANUP
, "Releasing resources for dev at %p.\n", dev
);
1968 /* XXX Hit all the tx channels too! */
1970 for (i
=0;i
< dev
->nchannels
;i
++) {
1971 if (dev
->atm_vccs
[i
]) {
1972 vcc
= FS_VCC (dev
->atm_vccs
[i
]);
1973 submit_command (dev
, &dev
->hp_txq
,
1974 QE_CMD_TX_PURGE_INH
| QE_CMD_IMM_INQ
| vcc
->channo
, 0,0,0);
1975 submit_command (dev
, &dev
->hp_txq
,
1976 QE_CMD_RX_PURGE_INH
| QE_CMD_IMM_INQ
| vcc
->channo
, 0,0,0);
1981 /* XXX Wait a while for the chip to release all buffers. */
1983 for (i
=0;i
< FS_NR_FREE_POOLS
;i
++) {
1984 for (fp
=bus_to_virt (read_fs (dev
, FP_SA(dev
->rx_fp
[i
].offset
)));
1985 !(fp
->flags
& FP_FLAGS_EPI
);fp
= nxt
) {
1986 fs_dprintk (FS_DEBUG_ALLOC
, "Free rec-skb: %p\n", fp
->skb
);
1987 dev_kfree_skb_any (fp
->skb
);
1988 nxt
= bus_to_virt (fp
->next
);
1989 fs_dprintk (FS_DEBUG_ALLOC
, "Free rec-d: %p\n", fp
);
1992 fs_dprintk (FS_DEBUG_ALLOC
, "Free rec-skb: %p\n", fp
->skb
);
1993 dev_kfree_skb_any (fp
->skb
);
1994 fs_dprintk (FS_DEBUG_ALLOC
, "Free rec-d: %p\n", fp
);
1998 /* Hang the chip in "reset", prevent it clobbering memory that is
2002 fs_dprintk (FS_DEBUG_CLEANUP
, "Freeing irq%d.\n", dev
->irq
);
2003 free_irq (dev
->irq
, dev
);
2004 del_timer (&dev
->timer
);
2006 atm_dev_deregister(dev
->atm_dev
);
2007 free_queue (dev
, &dev
->hp_txq
);
2008 free_queue (dev
, &dev
->lp_txq
);
2009 free_queue (dev
, &dev
->tx_relq
);
2010 free_queue (dev
, &dev
->st_q
);
2012 fs_dprintk (FS_DEBUG_ALLOC
, "Free atmvccs: %p\n", dev
->atm_vccs
);
2013 kfree (dev
->atm_vccs
);
2015 for (i
=0;i
< FS_NR_FREE_POOLS
;i
++)
2016 free_freepool (dev
, &dev
->rx_fp
[i
]);
2018 for (i
=0;i
< FS_NR_RX_QUEUES
;i
++)
2019 free_queue (dev
, &dev
->rx_rq
[i
]);
2022 fs_dprintk (FS_DEBUG_ALLOC
, "Free fs-dev: %p\n", dev
);
2030 static struct pci_device_id firestream_pci_tbl
[] = {
2031 { PCI_VDEVICE(FUJITSU_ME
, PCI_DEVICE_ID_FUJITSU_FS50
), FS_IS50
},
2032 { PCI_VDEVICE(FUJITSU_ME
, PCI_DEVICE_ID_FUJITSU_FS155
), FS_IS155
},
2036 MODULE_DEVICE_TABLE(pci
, firestream_pci_tbl
);
2038 static struct pci_driver firestream_driver
= {
2039 .name
= "firestream",
2040 .id_table
= firestream_pci_tbl
,
2041 .probe
= firestream_init_one
,
2042 .remove
= __devexit_p(firestream_remove_one
),
2045 static int __init
firestream_init_module (void)
2050 error
= pci_register_driver(&firestream_driver
);
2055 static void __exit
firestream_cleanup_module(void)
2057 pci_unregister_driver(&firestream_driver
);
2060 module_init(firestream_init_module
);
2061 module_exit(firestream_cleanup_module
);
2063 MODULE_LICENSE("GPL");