1 /*******************************************************************
3 * Copyright (c) 2000 ATecoM GmbH
5 * The author may be reached at ecd@atecom.com.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
12 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
13 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
15 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
16 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
17 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
18 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
21 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 675 Mass Ave, Cambridge, MA 02139, USA.
27 *******************************************************************/
29 #include <linux/module.h>
30 #include <linux/pci.h>
31 #include <linux/poison.h>
32 #include <linux/skbuff.h>
33 #include <linux/kernel.h>
34 #include <linux/vmalloc.h>
35 #include <linux/netdevice.h>
36 #include <linux/atmdev.h>
37 #include <linux/atm.h>
38 #include <linux/delay.h>
39 #include <linux/init.h>
40 #include <linux/interrupt.h>
41 #include <linux/bitops.h>
42 #include <linux/wait.h>
43 #include <linux/jiffies.h>
44 #include <linux/mutex.h>
45 #include <linux/slab.h>
48 #include <linux/uaccess.h>
49 #include <linux/atomic.h>
50 #include <asm/byteorder.h>
52 #ifdef CONFIG_ATM_IDT77252_USE_SUNI
54 #endif /* CONFIG_ATM_IDT77252_USE_SUNI */
58 #include "idt77252_tables.h"
60 static unsigned int vpibits
= 1;
63 #define ATM_IDT77252_SEND_IDLE 1
69 #define DEBUG_MODULE 1
70 #undef HAVE_EEPROM /* does not work, yet. */
72 #ifdef CONFIG_ATM_IDT77252_DEBUG
73 static unsigned long debug
= DBG_GENERAL
;
77 #define SAR_RX_DELAY (SAR_CFG_RXINT_NODELAY)
83 static struct scq_info
*alloc_scq(struct idt77252_dev
*, int);
84 static void free_scq(struct idt77252_dev
*, struct scq_info
*);
85 static int queue_skb(struct idt77252_dev
*, struct vc_map
*,
86 struct sk_buff
*, int oam
);
87 static void drain_scq(struct idt77252_dev
*, struct vc_map
*);
88 static unsigned long get_free_scd(struct idt77252_dev
*, struct vc_map
*);
89 static void fill_scd(struct idt77252_dev
*, struct scq_info
*, int);
94 static int push_rx_skb(struct idt77252_dev
*,
95 struct sk_buff
*, int queue
);
96 static void recycle_rx_skb(struct idt77252_dev
*, struct sk_buff
*);
97 static void flush_rx_pool(struct idt77252_dev
*, struct rx_pool
*);
98 static void recycle_rx_pool_skb(struct idt77252_dev
*,
100 static void add_rx_skb(struct idt77252_dev
*, int queue
,
101 unsigned int size
, unsigned int count
);
106 static int init_rsq(struct idt77252_dev
*);
107 static void deinit_rsq(struct idt77252_dev
*);
108 static void idt77252_rx(struct idt77252_dev
*);
113 static int init_tsq(struct idt77252_dev
*);
114 static void deinit_tsq(struct idt77252_dev
*);
115 static void idt77252_tx(struct idt77252_dev
*);
121 static void idt77252_dev_close(struct atm_dev
*dev
);
122 static int idt77252_open(struct atm_vcc
*vcc
);
123 static void idt77252_close(struct atm_vcc
*vcc
);
124 static int idt77252_send(struct atm_vcc
*vcc
, struct sk_buff
*skb
);
125 static int idt77252_send_oam(struct atm_vcc
*vcc
, void *cell
,
127 static void idt77252_phy_put(struct atm_dev
*dev
, unsigned char value
,
129 static unsigned char idt77252_phy_get(struct atm_dev
*dev
, unsigned long addr
);
130 static int idt77252_change_qos(struct atm_vcc
*vcc
, struct atm_qos
*qos
,
132 static int idt77252_proc_read(struct atm_dev
*dev
, loff_t
* pos
,
134 static void idt77252_softint(struct work_struct
*work
);
137 static const struct atmdev_ops idt77252_ops
=
139 .dev_close
= idt77252_dev_close
,
140 .open
= idt77252_open
,
141 .close
= idt77252_close
,
142 .send
= idt77252_send
,
143 .send_oam
= idt77252_send_oam
,
144 .phy_put
= idt77252_phy_put
,
145 .phy_get
= idt77252_phy_get
,
146 .change_qos
= idt77252_change_qos
,
147 .proc_read
= idt77252_proc_read
,
151 static struct idt77252_dev
*idt77252_chain
= NULL
;
152 static unsigned int idt77252_sram_write_errors
= 0;
154 /*****************************************************************************/
156 /* I/O and Utility Bus */
158 /*****************************************************************************/
161 waitfor_idle(struct idt77252_dev
*card
)
165 stat
= readl(SAR_REG_STAT
);
166 while (stat
& SAR_STAT_CMDBZ
)
167 stat
= readl(SAR_REG_STAT
);
171 read_sram(struct idt77252_dev
*card
, unsigned long addr
)
176 spin_lock_irqsave(&card
->cmd_lock
, flags
);
177 writel(SAR_CMD_READ_SRAM
| (addr
<< 2), SAR_REG_CMD
);
179 value
= readl(SAR_REG_DR0
);
180 spin_unlock_irqrestore(&card
->cmd_lock
, flags
);
185 write_sram(struct idt77252_dev
*card
, unsigned long addr
, u32 value
)
189 if ((idt77252_sram_write_errors
== 0) &&
190 (((addr
> card
->tst
[0] + card
->tst_size
- 2) &&
191 (addr
< card
->tst
[0] + card
->tst_size
)) ||
192 ((addr
> card
->tst
[1] + card
->tst_size
- 2) &&
193 (addr
< card
->tst
[1] + card
->tst_size
)))) {
194 printk("%s: ERROR: TST JMP section at %08lx written: %08x\n",
195 card
->name
, addr
, value
);
198 spin_lock_irqsave(&card
->cmd_lock
, flags
);
199 writel(value
, SAR_REG_DR0
);
200 writel(SAR_CMD_WRITE_SRAM
| (addr
<< 2), SAR_REG_CMD
);
202 spin_unlock_irqrestore(&card
->cmd_lock
, flags
);
206 read_utility(void *dev
, unsigned long ubus_addr
)
208 struct idt77252_dev
*card
= dev
;
213 printk("Error: No such device.\n");
217 spin_lock_irqsave(&card
->cmd_lock
, flags
);
218 writel(SAR_CMD_READ_UTILITY
+ ubus_addr
, SAR_REG_CMD
);
220 value
= readl(SAR_REG_DR0
);
221 spin_unlock_irqrestore(&card
->cmd_lock
, flags
);
226 write_utility(void *dev
, unsigned long ubus_addr
, u8 value
)
228 struct idt77252_dev
*card
= dev
;
232 printk("Error: No such device.\n");
236 spin_lock_irqsave(&card
->cmd_lock
, flags
);
237 writel((u32
) value
, SAR_REG_DR0
);
238 writel(SAR_CMD_WRITE_UTILITY
+ ubus_addr
, SAR_REG_CMD
);
240 spin_unlock_irqrestore(&card
->cmd_lock
, flags
);
244 static u32 rdsrtab
[] =
246 SAR_GP_EECS
| SAR_GP_EESCLK
,
248 SAR_GP_EESCLK
, /* 0 */
250 SAR_GP_EESCLK
, /* 0 */
252 SAR_GP_EESCLK
, /* 0 */
254 SAR_GP_EESCLK
, /* 0 */
256 SAR_GP_EESCLK
, /* 0 */
258 SAR_GP_EESCLK
| SAR_GP_EEDO
, /* 1 */
260 SAR_GP_EESCLK
, /* 0 */
262 SAR_GP_EESCLK
| SAR_GP_EEDO
/* 1 */
265 static u32 wrentab
[] =
267 SAR_GP_EECS
| SAR_GP_EESCLK
,
269 SAR_GP_EESCLK
, /* 0 */
271 SAR_GP_EESCLK
, /* 0 */
273 SAR_GP_EESCLK
, /* 0 */
275 SAR_GP_EESCLK
, /* 0 */
277 SAR_GP_EESCLK
| SAR_GP_EEDO
, /* 1 */
279 SAR_GP_EESCLK
| SAR_GP_EEDO
, /* 1 */
281 SAR_GP_EESCLK
, /* 0 */
283 SAR_GP_EESCLK
/* 0 */
288 SAR_GP_EECS
| SAR_GP_EESCLK
,
290 SAR_GP_EESCLK
, /* 0 */
292 SAR_GP_EESCLK
, /* 0 */
294 SAR_GP_EESCLK
, /* 0 */
296 SAR_GP_EESCLK
, /* 0 */
298 SAR_GP_EESCLK
, /* 0 */
300 SAR_GP_EESCLK
, /* 0 */
302 SAR_GP_EESCLK
| SAR_GP_EEDO
, /* 1 */
304 SAR_GP_EESCLK
| SAR_GP_EEDO
/* 1 */
309 SAR_GP_EECS
| SAR_GP_EESCLK
,
311 SAR_GP_EESCLK
, /* 0 */
313 SAR_GP_EESCLK
, /* 0 */
315 SAR_GP_EESCLK
, /* 0 */
317 SAR_GP_EESCLK
, /* 0 */
319 SAR_GP_EESCLK
, /* 0 */
321 SAR_GP_EESCLK
, /* 0 */
323 SAR_GP_EESCLK
| SAR_GP_EEDO
, /* 1 */
325 SAR_GP_EESCLK
/* 0 */
328 static u32 clktab
[] =
350 idt77252_read_gp(struct idt77252_dev
*card
)
354 gp
= readl(SAR_REG_GP
);
356 printk("RD: %s\n", gp
& SAR_GP_EEDI
? "1" : "0");
362 idt77252_write_gp(struct idt77252_dev
*card
, u32 value
)
367 printk("WR: %s %s %s\n", value
& SAR_GP_EECS
? " " : "/CS",
368 value
& SAR_GP_EESCLK
? "HIGH" : "LOW ",
369 value
& SAR_GP_EEDO
? "1" : "0");
372 spin_lock_irqsave(&card
->cmd_lock
, flags
);
374 writel(value
, SAR_REG_GP
);
375 spin_unlock_irqrestore(&card
->cmd_lock
, flags
);
379 idt77252_eeprom_read_status(struct idt77252_dev
*card
)
385 gp
= idt77252_read_gp(card
) & ~(SAR_GP_EESCLK
|SAR_GP_EECS
|SAR_GP_EEDO
);
387 for (i
= 0; i
< ARRAY_SIZE(rdsrtab
); i
++) {
388 idt77252_write_gp(card
, gp
| rdsrtab
[i
]);
391 idt77252_write_gp(card
, gp
| SAR_GP_EECS
);
395 for (i
= 0, j
= 0; i
< 8; i
++) {
398 idt77252_write_gp(card
, gp
| clktab
[j
++]);
401 byte
|= idt77252_read_gp(card
) & SAR_GP_EEDI
? 1 : 0;
403 idt77252_write_gp(card
, gp
| clktab
[j
++]);
406 idt77252_write_gp(card
, gp
| SAR_GP_EECS
);
413 idt77252_eeprom_read_byte(struct idt77252_dev
*card
, u8 offset
)
419 gp
= idt77252_read_gp(card
) & ~(SAR_GP_EESCLK
|SAR_GP_EECS
|SAR_GP_EEDO
);
421 for (i
= 0; i
< ARRAY_SIZE(rdtab
); i
++) {
422 idt77252_write_gp(card
, gp
| rdtab
[i
]);
425 idt77252_write_gp(card
, gp
| SAR_GP_EECS
);
428 for (i
= 0, j
= 0; i
< 8; i
++) {
429 idt77252_write_gp(card
, gp
| clktab
[j
++] |
430 (offset
& 1 ? SAR_GP_EEDO
: 0));
433 idt77252_write_gp(card
, gp
| clktab
[j
++] |
434 (offset
& 1 ? SAR_GP_EEDO
: 0));
439 idt77252_write_gp(card
, gp
| SAR_GP_EECS
);
443 for (i
= 0, j
= 0; i
< 8; i
++) {
446 idt77252_write_gp(card
, gp
| clktab
[j
++]);
449 byte
|= idt77252_read_gp(card
) & SAR_GP_EEDI
? 1 : 0;
451 idt77252_write_gp(card
, gp
| clktab
[j
++]);
454 idt77252_write_gp(card
, gp
| SAR_GP_EECS
);
461 idt77252_eeprom_write_byte(struct idt77252_dev
*card
, u8 offset
, u8 data
)
466 gp
= idt77252_read_gp(card
) & ~(SAR_GP_EESCLK
|SAR_GP_EECS
|SAR_GP_EEDO
);
468 for (i
= 0; i
< ARRAY_SIZE(wrentab
); i
++) {
469 idt77252_write_gp(card
, gp
| wrentab
[i
]);
472 idt77252_write_gp(card
, gp
| SAR_GP_EECS
);
475 for (i
= 0; i
< ARRAY_SIZE(wrtab
); i
++) {
476 idt77252_write_gp(card
, gp
| wrtab
[i
]);
479 idt77252_write_gp(card
, gp
| SAR_GP_EECS
);
482 for (i
= 0, j
= 0; i
< 8; i
++) {
483 idt77252_write_gp(card
, gp
| clktab
[j
++] |
484 (offset
& 1 ? SAR_GP_EEDO
: 0));
487 idt77252_write_gp(card
, gp
| clktab
[j
++] |
488 (offset
& 1 ? SAR_GP_EEDO
: 0));
493 idt77252_write_gp(card
, gp
| SAR_GP_EECS
);
496 for (i
= 0, j
= 0; i
< 8; i
++) {
497 idt77252_write_gp(card
, gp
| clktab
[j
++] |
498 (data
& 1 ? SAR_GP_EEDO
: 0));
501 idt77252_write_gp(card
, gp
| clktab
[j
++] |
502 (data
& 1 ? SAR_GP_EEDO
: 0));
507 idt77252_write_gp(card
, gp
| SAR_GP_EECS
);
512 idt77252_eeprom_init(struct idt77252_dev
*card
)
516 gp
= idt77252_read_gp(card
) & ~(SAR_GP_EESCLK
|SAR_GP_EECS
|SAR_GP_EEDO
);
518 idt77252_write_gp(card
, gp
| SAR_GP_EECS
| SAR_GP_EESCLK
);
520 idt77252_write_gp(card
, gp
| SAR_GP_EECS
);
522 idt77252_write_gp(card
, gp
| SAR_GP_EECS
| SAR_GP_EESCLK
);
524 idt77252_write_gp(card
, gp
| SAR_GP_EECS
);
527 #endif /* HAVE_EEPROM */
530 #ifdef CONFIG_ATM_IDT77252_DEBUG
532 dump_tct(struct idt77252_dev
*card
, int index
)
537 tct
= (unsigned long) (card
->tct_base
+ index
* SAR_SRAM_TCT_SIZE
);
539 printk("%s: TCT %x:", card
->name
, index
);
540 for (i
= 0; i
< 8; i
++) {
541 printk(" %08x", read_sram(card
, tct
+ i
));
547 idt77252_tx_dump(struct idt77252_dev
*card
)
553 printk("%s\n", __func__
);
554 for (i
= 0; i
< card
->tct_size
; i
++) {
568 printk("%s: Connection %d:\n", card
->name
, vc
->index
);
569 dump_tct(card
, vc
->index
);
575 /*****************************************************************************/
579 /*****************************************************************************/
582 sb_pool_add(struct idt77252_dev
*card
, struct sk_buff
*skb
, int queue
)
584 struct sb_pool
*pool
= &card
->sbpool
[queue
];
588 while (pool
->skb
[index
]) {
589 index
= (index
+ 1) & FBQ_MASK
;
590 if (index
== pool
->index
)
594 pool
->skb
[index
] = skb
;
595 IDT77252_PRV_POOL(skb
) = POOL_HANDLE(queue
, index
);
597 pool
->index
= (index
+ 1) & FBQ_MASK
;
602 sb_pool_remove(struct idt77252_dev
*card
, struct sk_buff
*skb
)
604 unsigned int queue
, index
;
607 handle
= IDT77252_PRV_POOL(skb
);
609 queue
= POOL_QUEUE(handle
);
613 index
= POOL_INDEX(handle
);
614 if (index
> FBQ_SIZE
- 1)
617 card
->sbpool
[queue
].skb
[index
] = NULL
;
620 static struct sk_buff
*
621 sb_pool_skb(struct idt77252_dev
*card
, u32 handle
)
623 unsigned int queue
, index
;
625 queue
= POOL_QUEUE(handle
);
629 index
= POOL_INDEX(handle
);
630 if (index
> FBQ_SIZE
- 1)
633 return card
->sbpool
[queue
].skb
[index
];
636 static struct scq_info
*
637 alloc_scq(struct idt77252_dev
*card
, int class)
639 struct scq_info
*scq
;
641 scq
= kzalloc(sizeof(struct scq_info
), GFP_KERNEL
);
644 scq
->base
= dma_alloc_coherent(&card
->pcidev
->dev
, SCQ_SIZE
,
645 &scq
->paddr
, GFP_KERNEL
);
646 if (scq
->base
== NULL
) {
651 scq
->next
= scq
->base
;
652 scq
->last
= scq
->base
+ (SCQ_ENTRIES
- 1);
653 atomic_set(&scq
->used
, 0);
655 spin_lock_init(&scq
->lock
);
656 spin_lock_init(&scq
->skblock
);
658 skb_queue_head_init(&scq
->transmit
);
659 skb_queue_head_init(&scq
->pending
);
661 TXPRINTK("idt77252: SCQ: base 0x%p, next 0x%p, last 0x%p, paddr %08llx\n",
662 scq
->base
, scq
->next
, scq
->last
, (unsigned long long)scq
->paddr
);
668 free_scq(struct idt77252_dev
*card
, struct scq_info
*scq
)
673 dma_free_coherent(&card
->pcidev
->dev
, SCQ_SIZE
,
674 scq
->base
, scq
->paddr
);
676 while ((skb
= skb_dequeue(&scq
->transmit
))) {
677 dma_unmap_single(&card
->pcidev
->dev
, IDT77252_PRV_PADDR(skb
),
678 skb
->len
, DMA_TO_DEVICE
);
680 vcc
= ATM_SKB(skb
)->vcc
;
687 while ((skb
= skb_dequeue(&scq
->pending
))) {
688 dma_unmap_single(&card
->pcidev
->dev
, IDT77252_PRV_PADDR(skb
),
689 skb
->len
, DMA_TO_DEVICE
);
691 vcc
= ATM_SKB(skb
)->vcc
;
703 push_on_scq(struct idt77252_dev
*card
, struct vc_map
*vc
, struct sk_buff
*skb
)
705 struct scq_info
*scq
= vc
->scq
;
710 TXPRINTK("%s: SCQ: next 0x%p\n", card
->name
, scq
->next
);
712 atomic_inc(&scq
->used
);
713 entries
= atomic_read(&scq
->used
);
714 if (entries
> (SCQ_ENTRIES
- 1)) {
715 atomic_dec(&scq
->used
);
719 skb_queue_tail(&scq
->transmit
, skb
);
721 spin_lock_irqsave(&vc
->lock
, flags
);
723 struct atm_vcc
*vcc
= vc
->tx_vcc
;
724 struct sock
*sk
= sk_atm(vcc
);
726 vc
->estimator
->cells
+= (skb
->len
+ 47) / 48;
727 if (refcount_read(&sk
->sk_wmem_alloc
) >
728 (sk
->sk_sndbuf
>> 1)) {
729 u32 cps
= vc
->estimator
->maxcps
;
731 vc
->estimator
->cps
= cps
;
732 vc
->estimator
->avcps
= cps
<< 5;
733 if (vc
->lacr
< vc
->init_er
) {
734 vc
->lacr
= vc
->init_er
;
735 writel(TCMDQ_LACR
| (vc
->lacr
<< 16) |
736 vc
->index
, SAR_REG_TCMDQ
);
740 spin_unlock_irqrestore(&vc
->lock
, flags
);
742 tbd
= &IDT77252_PRV_TBD(skb
);
744 spin_lock_irqsave(&scq
->lock
, flags
);
745 scq
->next
->word_1
= cpu_to_le32(tbd
->word_1
|
746 SAR_TBD_TSIF
| SAR_TBD_GTSI
);
747 scq
->next
->word_2
= cpu_to_le32(tbd
->word_2
);
748 scq
->next
->word_3
= cpu_to_le32(tbd
->word_3
);
749 scq
->next
->word_4
= cpu_to_le32(tbd
->word_4
);
751 if (scq
->next
== scq
->last
)
752 scq
->next
= scq
->base
;
756 write_sram(card
, scq
->scd
,
758 (u32
)((unsigned long)scq
->next
- (unsigned long)scq
->base
));
759 spin_unlock_irqrestore(&scq
->lock
, flags
);
761 scq
->trans_start
= jiffies
;
763 if (test_and_clear_bit(VCF_IDLE
, &vc
->flags
)) {
764 writel(TCMDQ_START_LACR
| (vc
->lacr
<< 16) | vc
->index
,
768 TXPRINTK("%d entries in SCQ used (push).\n", atomic_read(&scq
->used
));
770 XPRINTK("%s: SCQ (after push %2d) head = 0x%x, next = 0x%p.\n",
771 card
->name
, atomic_read(&scq
->used
),
772 read_sram(card
, scq
->scd
+ 1), scq
->next
);
777 if (time_after(jiffies
, scq
->trans_start
+ HZ
)) {
778 printk("%s: Error pushing TBD for %d.%d\n",
779 card
->name
, vc
->tx_vcc
->vpi
, vc
->tx_vcc
->vci
);
780 #ifdef CONFIG_ATM_IDT77252_DEBUG
781 idt77252_tx_dump(card
);
783 scq
->trans_start
= jiffies
;
791 drain_scq(struct idt77252_dev
*card
, struct vc_map
*vc
)
793 struct scq_info
*scq
= vc
->scq
;
797 TXPRINTK("%s: SCQ (before drain %2d) next = 0x%p.\n",
798 card
->name
, atomic_read(&scq
->used
), scq
->next
);
800 skb
= skb_dequeue(&scq
->transmit
);
802 TXPRINTK("%s: freeing skb at %p.\n", card
->name
, skb
);
804 dma_unmap_single(&card
->pcidev
->dev
, IDT77252_PRV_PADDR(skb
),
805 skb
->len
, DMA_TO_DEVICE
);
807 vcc
= ATM_SKB(skb
)->vcc
;
814 atomic_inc(&vcc
->stats
->tx
);
817 atomic_dec(&scq
->used
);
819 spin_lock(&scq
->skblock
);
820 while ((skb
= skb_dequeue(&scq
->pending
))) {
821 if (push_on_scq(card
, vc
, skb
)) {
822 skb_queue_head(&vc
->scq
->pending
, skb
);
826 spin_unlock(&scq
->skblock
);
830 queue_skb(struct idt77252_dev
*card
, struct vc_map
*vc
,
831 struct sk_buff
*skb
, int oam
)
841 printk("%s: invalid skb->len (%d)\n", card
->name
, skb
->len
);
845 TXPRINTK("%s: Sending %d bytes of data.\n",
846 card
->name
, skb
->len
);
848 tbd
= &IDT77252_PRV_TBD(skb
);
849 vcc
= ATM_SKB(skb
)->vcc
;
850 word4
= (skb
->data
[0] << 24) | (skb
->data
[1] << 16) |
851 (skb
->data
[2] << 8) | (skb
->data
[3] << 0);
853 IDT77252_PRV_PADDR(skb
) = dma_map_single(&card
->pcidev
->dev
, skb
->data
,
854 skb
->len
, DMA_TO_DEVICE
);
862 tbd
->word_1
= SAR_TBD_OAM
| ATM_CELL_PAYLOAD
| SAR_TBD_EPDU
;
863 tbd
->word_2
= IDT77252_PRV_PADDR(skb
) + 4;
864 tbd
->word_3
= 0x00000000;
867 if (test_bit(VCF_RSV
, &vc
->flags
))
873 if (test_bit(VCF_RSV
, &vc
->flags
)) {
874 printk("%s: Trying to transmit on reserved VC\n", card
->name
);
887 tbd
->word_1
= SAR_TBD_EPDU
| SAR_TBD_AAL0
|
890 tbd
->word_1
= SAR_TBD_EPDU
| SAR_TBD_AAL34
|
893 tbd
->word_2
= IDT77252_PRV_PADDR(skb
) + 4;
894 tbd
->word_3
= 0x00000000;
899 tbd
->word_1
= SAR_TBD_EPDU
| SAR_TBD_AAL5
| skb
->len
;
900 tbd
->word_2
= IDT77252_PRV_PADDR(skb
);
901 tbd
->word_3
= skb
->len
;
902 tbd
->word_4
= (vcc
->vpi
<< SAR_TBD_VPI_SHIFT
) |
903 (vcc
->vci
<< SAR_TBD_VCI_SHIFT
);
909 printk("%s: Traffic type not supported.\n", card
->name
);
910 error
= -EPROTONOSUPPORT
;
915 spin_lock_irqsave(&vc
->scq
->skblock
, flags
);
916 skb_queue_tail(&vc
->scq
->pending
, skb
);
918 while ((skb
= skb_dequeue(&vc
->scq
->pending
))) {
919 if (push_on_scq(card
, vc
, skb
)) {
920 skb_queue_head(&vc
->scq
->pending
, skb
);
924 spin_unlock_irqrestore(&vc
->scq
->skblock
, flags
);
929 dma_unmap_single(&card
->pcidev
->dev
, IDT77252_PRV_PADDR(skb
),
930 skb
->len
, DMA_TO_DEVICE
);
935 get_free_scd(struct idt77252_dev
*card
, struct vc_map
*vc
)
939 for (i
= 0; i
< card
->scd_size
; i
++) {
940 if (!card
->scd2vc
[i
]) {
941 card
->scd2vc
[i
] = vc
;
943 return card
->scd_base
+ i
* SAR_SRAM_SCD_SIZE
;
950 fill_scd(struct idt77252_dev
*card
, struct scq_info
*scq
, int class)
952 write_sram(card
, scq
->scd
, scq
->paddr
);
953 write_sram(card
, scq
->scd
+ 1, 0x00000000);
954 write_sram(card
, scq
->scd
+ 2, 0xffffffff);
955 write_sram(card
, scq
->scd
+ 3, 0x00000000);
959 clear_scd(struct idt77252_dev
*card
, struct scq_info
*scq
, int class)
964 /*****************************************************************************/
968 /*****************************************************************************/
971 init_rsq(struct idt77252_dev
*card
)
973 struct rsq_entry
*rsqe
;
975 card
->rsq
.base
= dma_alloc_coherent(&card
->pcidev
->dev
, RSQSIZE
,
976 &card
->rsq
.paddr
, GFP_KERNEL
);
977 if (card
->rsq
.base
== NULL
) {
978 printk("%s: can't allocate RSQ.\n", card
->name
);
982 card
->rsq
.last
= card
->rsq
.base
+ RSQ_NUM_ENTRIES
- 1;
983 card
->rsq
.next
= card
->rsq
.last
;
984 for (rsqe
= card
->rsq
.base
; rsqe
<= card
->rsq
.last
; rsqe
++)
987 writel((unsigned long) card
->rsq
.last
- (unsigned long) card
->rsq
.base
,
989 writel(card
->rsq
.paddr
, SAR_REG_RSQB
);
991 IPRINTK("%s: RSQ base at 0x%lx (0x%x).\n", card
->name
,
992 (unsigned long) card
->rsq
.base
,
993 readl(SAR_REG_RSQB
));
994 IPRINTK("%s: RSQ head = 0x%x, base = 0x%x, tail = 0x%x.\n",
998 readl(SAR_REG_RSQT
));
1004 deinit_rsq(struct idt77252_dev
*card
)
1006 dma_free_coherent(&card
->pcidev
->dev
, RSQSIZE
,
1007 card
->rsq
.base
, card
->rsq
.paddr
);
1011 dequeue_rx(struct idt77252_dev
*card
, struct rsq_entry
*rsqe
)
1013 struct atm_vcc
*vcc
;
1014 struct sk_buff
*skb
;
1015 struct rx_pool
*rpp
;
1017 u32 header
, vpi
, vci
;
1021 stat
= le32_to_cpu(rsqe
->word_4
);
1023 if (stat
& SAR_RSQE_IDLE
) {
1024 RXPRINTK("%s: message about inactive connection.\n",
1029 skb
= sb_pool_skb(card
, le32_to_cpu(rsqe
->word_2
));
1031 printk("%s: NULL skb in %s, rsqe: %08x %08x %08x %08x\n",
1032 card
->name
, __func__
,
1033 le32_to_cpu(rsqe
->word_1
), le32_to_cpu(rsqe
->word_2
),
1034 le32_to_cpu(rsqe
->word_3
), le32_to_cpu(rsqe
->word_4
));
1038 header
= le32_to_cpu(rsqe
->word_1
);
1039 vpi
= (header
>> 16) & 0x00ff;
1040 vci
= (header
>> 0) & 0xffff;
1042 RXPRINTK("%s: SDU for %d.%d received in buffer 0x%p (data 0x%p).\n",
1043 card
->name
, vpi
, vci
, skb
, skb
->data
);
1045 if ((vpi
>= (1 << card
->vpibits
)) || (vci
!= (vci
& card
->vcimask
))) {
1046 printk("%s: SDU received for out-of-range vc %u.%u\n",
1047 card
->name
, vpi
, vci
);
1048 recycle_rx_skb(card
, skb
);
1052 vc
= card
->vcs
[VPCI2VC(card
, vpi
, vci
)];
1053 if (!vc
|| !test_bit(VCF_RX
, &vc
->flags
)) {
1054 printk("%s: SDU received on non RX vc %u.%u\n",
1055 card
->name
, vpi
, vci
);
1056 recycle_rx_skb(card
, skb
);
1062 dma_sync_single_for_cpu(&card
->pcidev
->dev
, IDT77252_PRV_PADDR(skb
),
1063 skb_end_pointer(skb
) - skb
->data
,
1066 if ((vcc
->qos
.aal
== ATM_AAL0
) ||
1067 (vcc
->qos
.aal
== ATM_AAL34
)) {
1069 unsigned char *cell
;
1073 for (i
= (stat
& SAR_RSQE_CELLCNT
); i
; i
--) {
1074 if ((sb
= dev_alloc_skb(64)) == NULL
) {
1075 printk("%s: Can't allocate buffers for aal0.\n",
1077 atomic_add(i
, &vcc
->stats
->rx_drop
);
1080 if (!atm_charge(vcc
, sb
->truesize
)) {
1081 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
1083 atomic_add(i
- 1, &vcc
->stats
->rx_drop
);
1087 aal0
= (vpi
<< ATM_HDR_VPI_SHIFT
) |
1088 (vci
<< ATM_HDR_VCI_SHIFT
);
1089 aal0
|= (stat
& SAR_RSQE_EPDU
) ? 0x00000002 : 0;
1090 aal0
|= (stat
& SAR_RSQE_CLP
) ? 0x00000001 : 0;
1092 *((u32
*) sb
->data
) = aal0
;
1093 skb_put(sb
, sizeof(u32
));
1094 skb_put_data(sb
, cell
, ATM_CELL_PAYLOAD
);
1096 ATM_SKB(sb
)->vcc
= vcc
;
1097 __net_timestamp(sb
);
1099 atomic_inc(&vcc
->stats
->rx
);
1101 cell
+= ATM_CELL_PAYLOAD
;
1104 recycle_rx_skb(card
, skb
);
1107 if (vcc
->qos
.aal
!= ATM_AAL5
) {
1108 printk("%s: Unexpected AAL type in dequeue_rx(): %d.\n",
1109 card
->name
, vcc
->qos
.aal
);
1110 recycle_rx_skb(card
, skb
);
1113 skb
->len
= (stat
& SAR_RSQE_CELLCNT
) * ATM_CELL_PAYLOAD
;
1115 rpp
= &vc
->rcv
.rx_pool
;
1117 __skb_queue_tail(&rpp
->queue
, skb
);
1118 rpp
->len
+= skb
->len
;
1120 if (stat
& SAR_RSQE_EPDU
) {
1121 unsigned int len
, truesize
;
1122 unsigned char *l1l2
;
1124 l1l2
= (unsigned char *) ((unsigned long) skb
->data
+ skb
->len
- 6);
1126 len
= (l1l2
[0] << 8) | l1l2
[1];
1127 len
= len
? len
: 0x10000;
1129 RXPRINTK("%s: PDU has %d bytes.\n", card
->name
, len
);
1131 if ((len
+ 8 > rpp
->len
) || (len
+ (47 + 8) < rpp
->len
)) {
1132 RXPRINTK("%s: AAL5 PDU size mismatch: %d != %d. "
1134 card
->name
, len
, rpp
->len
, readl(SAR_REG_CDC
));
1135 recycle_rx_pool_skb(card
, rpp
);
1136 atomic_inc(&vcc
->stats
->rx_err
);
1139 if (stat
& SAR_RSQE_CRC
) {
1140 RXPRINTK("%s: AAL5 CRC error.\n", card
->name
);
1141 recycle_rx_pool_skb(card
, rpp
);
1142 atomic_inc(&vcc
->stats
->rx_err
);
1145 if (skb_queue_len(&rpp
->queue
) > 1) {
1148 skb
= dev_alloc_skb(rpp
->len
);
1150 RXPRINTK("%s: Can't alloc RX skb.\n",
1152 recycle_rx_pool_skb(card
, rpp
);
1153 atomic_inc(&vcc
->stats
->rx_err
);
1156 if (!atm_charge(vcc
, skb
->truesize
)) {
1157 recycle_rx_pool_skb(card
, rpp
);
1161 skb_queue_walk(&rpp
->queue
, sb
)
1162 skb_put_data(skb
, sb
->data
, sb
->len
);
1164 recycle_rx_pool_skb(card
, rpp
);
1167 ATM_SKB(skb
)->vcc
= vcc
;
1168 __net_timestamp(skb
);
1170 vcc
->push(vcc
, skb
);
1171 atomic_inc(&vcc
->stats
->rx
);
1176 flush_rx_pool(card
, rpp
);
1178 if (!atm_charge(vcc
, skb
->truesize
)) {
1179 recycle_rx_skb(card
, skb
);
1183 dma_unmap_single(&card
->pcidev
->dev
, IDT77252_PRV_PADDR(skb
),
1184 skb_end_pointer(skb
) - skb
->data
,
1186 sb_pool_remove(card
, skb
);
1189 ATM_SKB(skb
)->vcc
= vcc
;
1190 __net_timestamp(skb
);
1192 truesize
= skb
->truesize
;
1193 vcc
->push(vcc
, skb
);
1194 atomic_inc(&vcc
->stats
->rx
);
1196 if (truesize
> SAR_FB_SIZE_3
)
1197 add_rx_skb(card
, 3, SAR_FB_SIZE_3
, 1);
1198 else if (truesize
> SAR_FB_SIZE_2
)
1199 add_rx_skb(card
, 2, SAR_FB_SIZE_2
, 1);
1200 else if (truesize
> SAR_FB_SIZE_1
)
1201 add_rx_skb(card
, 1, SAR_FB_SIZE_1
, 1);
1203 add_rx_skb(card
, 0, SAR_FB_SIZE_0
, 1);
1209 idt77252_rx(struct idt77252_dev
*card
)
1211 struct rsq_entry
*rsqe
;
1213 if (card
->rsq
.next
== card
->rsq
.last
)
1214 rsqe
= card
->rsq
.base
;
1216 rsqe
= card
->rsq
.next
+ 1;
1218 if (!(le32_to_cpu(rsqe
->word_4
) & SAR_RSQE_VALID
)) {
1219 RXPRINTK("%s: no entry in RSQ.\n", card
->name
);
1224 dequeue_rx(card
, rsqe
);
1226 card
->rsq
.next
= rsqe
;
1227 if (card
->rsq
.next
== card
->rsq
.last
)
1228 rsqe
= card
->rsq
.base
;
1230 rsqe
= card
->rsq
.next
+ 1;
1231 } while (le32_to_cpu(rsqe
->word_4
) & SAR_RSQE_VALID
);
1233 writel((unsigned long) card
->rsq
.next
- (unsigned long) card
->rsq
.base
,
1238 idt77252_rx_raw(struct idt77252_dev
*card
)
1240 struct sk_buff
*queue
;
1242 struct atm_vcc
*vcc
;
1246 if (card
->raw_cell_head
== NULL
) {
1247 u32 handle
= le32_to_cpu(*(card
->raw_cell_hnd
+ 1));
1248 card
->raw_cell_head
= sb_pool_skb(card
, handle
);
1251 queue
= card
->raw_cell_head
;
1255 head
= IDT77252_PRV_PADDR(queue
) + (queue
->data
- queue
->head
- 16);
1256 tail
= readl(SAR_REG_RAWCT
);
1258 dma_sync_single_for_cpu(&card
->pcidev
->dev
, IDT77252_PRV_PADDR(queue
),
1259 skb_end_offset(queue
) - 16,
1262 while (head
!= tail
) {
1263 unsigned int vpi
, vci
;
1266 header
= le32_to_cpu(*(u32
*) &queue
->data
[0]);
1268 vpi
= (header
& ATM_HDR_VPI_MASK
) >> ATM_HDR_VPI_SHIFT
;
1269 vci
= (header
& ATM_HDR_VCI_MASK
) >> ATM_HDR_VCI_SHIFT
;
1271 #ifdef CONFIG_ATM_IDT77252_DEBUG
1272 if (debug
& DBG_RAW_CELL
) {
1275 printk("%s: raw cell %x.%02x.%04x.%x.%x\n",
1276 card
->name
, (header
>> 28) & 0x000f,
1277 (header
>> 20) & 0x00ff,
1278 (header
>> 4) & 0xffff,
1279 (header
>> 1) & 0x0007,
1280 (header
>> 0) & 0x0001);
1281 for (i
= 16; i
< 64; i
++)
1282 printk(" %02x", queue
->data
[i
]);
1287 if (vpi
>= (1<<card
->vpibits
) || vci
>= (1<<card
->vcibits
)) {
1288 RPRINTK("%s: SDU received for out-of-range vc %u.%u\n",
1289 card
->name
, vpi
, vci
);
1293 vc
= card
->vcs
[VPCI2VC(card
, vpi
, vci
)];
1294 if (!vc
|| !test_bit(VCF_RX
, &vc
->flags
)) {
1295 RPRINTK("%s: SDU received on non RX vc %u.%u\n",
1296 card
->name
, vpi
, vci
);
1302 if (vcc
->qos
.aal
!= ATM_AAL0
) {
1303 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
1304 card
->name
, vpi
, vci
);
1305 atomic_inc(&vcc
->stats
->rx_drop
);
1309 if ((sb
= dev_alloc_skb(64)) == NULL
) {
1310 printk("%s: Can't allocate buffers for AAL0.\n",
1312 atomic_inc(&vcc
->stats
->rx_err
);
1316 if (!atm_charge(vcc
, sb
->truesize
)) {
1317 RXPRINTK("%s: atm_charge() dropped AAL0 packets.\n",
1323 *((u32
*) sb
->data
) = header
;
1324 skb_put(sb
, sizeof(u32
));
1325 skb_put_data(sb
, &(queue
->data
[16]), ATM_CELL_PAYLOAD
);
1327 ATM_SKB(sb
)->vcc
= vcc
;
1328 __net_timestamp(sb
);
1330 atomic_inc(&vcc
->stats
->rx
);
1333 skb_pull(queue
, 64);
1335 head
= IDT77252_PRV_PADDR(queue
)
1336 + (queue
->data
- queue
->head
- 16);
1338 if (queue
->len
< 128) {
1339 struct sk_buff
*next
;
1342 head
= le32_to_cpu(*(u32
*) &queue
->data
[0]);
1343 handle
= le32_to_cpu(*(u32
*) &queue
->data
[4]);
1345 next
= sb_pool_skb(card
, handle
);
1346 recycle_rx_skb(card
, queue
);
1349 card
->raw_cell_head
= next
;
1350 queue
= card
->raw_cell_head
;
1351 dma_sync_single_for_cpu(&card
->pcidev
->dev
,
1352 IDT77252_PRV_PADDR(queue
),
1353 (skb_end_pointer(queue
) -
1357 card
->raw_cell_head
= NULL
;
1358 printk("%s: raw cell queue overrun\n",
1367 /*****************************************************************************/
1371 /*****************************************************************************/
1374 init_tsq(struct idt77252_dev
*card
)
1376 struct tsq_entry
*tsqe
;
1378 card
->tsq
.base
= dma_alloc_coherent(&card
->pcidev
->dev
, RSQSIZE
,
1379 &card
->tsq
.paddr
, GFP_KERNEL
);
1380 if (card
->tsq
.base
== NULL
) {
1381 printk("%s: can't allocate TSQ.\n", card
->name
);
1385 card
->tsq
.last
= card
->tsq
.base
+ TSQ_NUM_ENTRIES
- 1;
1386 card
->tsq
.next
= card
->tsq
.last
;
1387 for (tsqe
= card
->tsq
.base
; tsqe
<= card
->tsq
.last
; tsqe
++)
1388 tsqe
->word_2
= cpu_to_le32(SAR_TSQE_INVALID
);
1390 writel(card
->tsq
.paddr
, SAR_REG_TSQB
);
1391 writel((unsigned long) card
->tsq
.next
- (unsigned long) card
->tsq
.base
,
1398 deinit_tsq(struct idt77252_dev
*card
)
1400 dma_free_coherent(&card
->pcidev
->dev
, TSQSIZE
,
1401 card
->tsq
.base
, card
->tsq
.paddr
);
1405 idt77252_tx(struct idt77252_dev
*card
)
1407 struct tsq_entry
*tsqe
;
1408 unsigned int vpi
, vci
;
1412 if (card
->tsq
.next
== card
->tsq
.last
)
1413 tsqe
= card
->tsq
.base
;
1415 tsqe
= card
->tsq
.next
+ 1;
1417 TXPRINTK("idt77252_tx: tsq %p: base %p, next %p, last %p\n", tsqe
,
1418 card
->tsq
.base
, card
->tsq
.next
, card
->tsq
.last
);
1419 TXPRINTK("idt77252_tx: tsqb %08x, tsqt %08x, tsqh %08x, \n",
1420 readl(SAR_REG_TSQB
),
1421 readl(SAR_REG_TSQT
),
1422 readl(SAR_REG_TSQH
));
1424 stat
= le32_to_cpu(tsqe
->word_2
);
1426 if (stat
& SAR_TSQE_INVALID
)
1430 TXPRINTK("tsqe: 0x%p [0x%08x 0x%08x]\n", tsqe
,
1431 le32_to_cpu(tsqe
->word_1
),
1432 le32_to_cpu(tsqe
->word_2
));
1434 switch (stat
& SAR_TSQE_TYPE
) {
1435 case SAR_TSQE_TYPE_TIMER
:
1436 TXPRINTK("%s: Timer RollOver detected.\n", card
->name
);
1439 case SAR_TSQE_TYPE_IDLE
:
1441 conn
= le32_to_cpu(tsqe
->word_1
);
1443 if (SAR_TSQE_TAG(stat
) == 0x10) {
1445 printk("%s: Connection %d halted.\n",
1447 le32_to_cpu(tsqe
->word_1
) & 0x1fff);
1452 vc
= card
->vcs
[conn
& 0x1fff];
1454 printk("%s: could not find VC from conn %d\n",
1455 card
->name
, conn
& 0x1fff);
1459 printk("%s: Connection %d IDLE.\n",
1460 card
->name
, vc
->index
);
1462 set_bit(VCF_IDLE
, &vc
->flags
);
1465 case SAR_TSQE_TYPE_TSR
:
1467 conn
= le32_to_cpu(tsqe
->word_1
);
1469 vc
= card
->vcs
[conn
& 0x1fff];
1471 printk("%s: no VC at index %d\n",
1473 le32_to_cpu(tsqe
->word_1
) & 0x1fff);
1477 drain_scq(card
, vc
);
1480 case SAR_TSQE_TYPE_TBD_COMP
:
1482 conn
= le32_to_cpu(tsqe
->word_1
);
1484 vpi
= (conn
>> SAR_TBD_VPI_SHIFT
) & 0x00ff;
1485 vci
= (conn
>> SAR_TBD_VCI_SHIFT
) & 0xffff;
1487 if (vpi
>= (1 << card
->vpibits
) ||
1488 vci
>= (1 << card
->vcibits
)) {
1489 printk("%s: TBD complete: "
1490 "out of range VPI.VCI %u.%u\n",
1491 card
->name
, vpi
, vci
);
1495 vc
= card
->vcs
[VPCI2VC(card
, vpi
, vci
)];
1497 printk("%s: TBD complete: "
1498 "no VC at VPI.VCI %u.%u\n",
1499 card
->name
, vpi
, vci
);
1503 drain_scq(card
, vc
);
1507 tsqe
->word_2
= cpu_to_le32(SAR_TSQE_INVALID
);
1509 card
->tsq
.next
= tsqe
;
1510 if (card
->tsq
.next
== card
->tsq
.last
)
1511 tsqe
= card
->tsq
.base
;
1513 tsqe
= card
->tsq
.next
+ 1;
1515 TXPRINTK("tsqe: %p: base %p, next %p, last %p\n", tsqe
,
1516 card
->tsq
.base
, card
->tsq
.next
, card
->tsq
.last
);
1518 stat
= le32_to_cpu(tsqe
->word_2
);
1520 } while (!(stat
& SAR_TSQE_INVALID
));
1522 writel((unsigned long)card
->tsq
.next
- (unsigned long)card
->tsq
.base
,
1525 XPRINTK("idt77252_tx-after writel%d: TSQ head = 0x%x, tail = 0x%x, next = 0x%p.\n",
1526 card
->index
, readl(SAR_REG_TSQH
),
1527 readl(SAR_REG_TSQT
), card
->tsq
.next
);
1532 tst_timer(struct timer_list
*t
)
1534 struct idt77252_dev
*card
= from_timer(card
, t
, tst_timer
);
1535 unsigned long base
, idle
, jump
;
1536 unsigned long flags
;
1540 spin_lock_irqsave(&card
->tst_lock
, flags
);
1542 base
= card
->tst
[card
->tst_index
];
1543 idle
= card
->tst
[card
->tst_index
^ 1];
1545 if (test_bit(TST_SWITCH_WAIT
, &card
->tst_state
)) {
1546 jump
= base
+ card
->tst_size
- 2;
1548 pc
= readl(SAR_REG_NOW
) >> 2;
1549 if ((pc
^ idle
) & ~(card
->tst_size
- 1)) {
1550 mod_timer(&card
->tst_timer
, jiffies
+ 1);
1554 clear_bit(TST_SWITCH_WAIT
, &card
->tst_state
);
1556 card
->tst_index
^= 1;
1557 write_sram(card
, jump
, TSTE_OPC_JMP
| (base
<< 2));
1559 base
= card
->tst
[card
->tst_index
];
1560 idle
= card
->tst
[card
->tst_index
^ 1];
1562 for (e
= 0; e
< card
->tst_size
- 2; e
++) {
1563 if (card
->soft_tst
[e
].tste
& TSTE_PUSH_IDLE
) {
1564 write_sram(card
, idle
+ e
,
1565 card
->soft_tst
[e
].tste
& TSTE_MASK
);
1566 card
->soft_tst
[e
].tste
&= ~(TSTE_PUSH_IDLE
);
1571 if (test_and_clear_bit(TST_SWITCH_PENDING
, &card
->tst_state
)) {
1573 for (e
= 0; e
< card
->tst_size
- 2; e
++) {
1574 if (card
->soft_tst
[e
].tste
& TSTE_PUSH_ACTIVE
) {
1575 write_sram(card
, idle
+ e
,
1576 card
->soft_tst
[e
].tste
& TSTE_MASK
);
1577 card
->soft_tst
[e
].tste
&= ~(TSTE_PUSH_ACTIVE
);
1578 card
->soft_tst
[e
].tste
|= TSTE_PUSH_IDLE
;
1582 jump
= base
+ card
->tst_size
- 2;
1584 write_sram(card
, jump
, TSTE_OPC_NULL
);
1585 set_bit(TST_SWITCH_WAIT
, &card
->tst_state
);
1587 mod_timer(&card
->tst_timer
, jiffies
+ 1);
1591 spin_unlock_irqrestore(&card
->tst_lock
, flags
);
1595 __fill_tst(struct idt77252_dev
*card
, struct vc_map
*vc
,
1596 int n
, unsigned int opc
)
1598 unsigned long cl
, avail
;
1603 avail
= card
->tst_size
- 2;
1604 for (e
= 0; e
< avail
; e
++) {
1605 if (card
->soft_tst
[e
].vc
== NULL
)
1609 printk("%s: No free TST entries found\n", card
->name
);
1613 NPRINTK("%s: conn %d: first TST entry at %d.\n",
1614 card
->name
, vc
? vc
->index
: -1, e
);
1618 data
= opc
& TSTE_OPC_MASK
;
1619 if (vc
&& (opc
!= TSTE_OPC_NULL
))
1620 data
= opc
| vc
->index
;
1622 idle
= card
->tst
[card
->tst_index
^ 1];
1628 if ((cl
>= avail
) && (card
->soft_tst
[e
].vc
== NULL
)) {
1630 card
->soft_tst
[e
].vc
= vc
;
1632 card
->soft_tst
[e
].vc
= (void *)-1;
1634 card
->soft_tst
[e
].tste
= data
;
1635 if (timer_pending(&card
->tst_timer
))
1636 card
->soft_tst
[e
].tste
|= TSTE_PUSH_ACTIVE
;
1638 write_sram(card
, idle
+ e
, data
);
1639 card
->soft_tst
[e
].tste
|= TSTE_PUSH_IDLE
;
1642 cl
-= card
->tst_size
;
1655 fill_tst(struct idt77252_dev
*card
, struct vc_map
*vc
, int n
, unsigned int opc
)
1657 unsigned long flags
;
1660 spin_lock_irqsave(&card
->tst_lock
, flags
);
1662 res
= __fill_tst(card
, vc
, n
, opc
);
1664 set_bit(TST_SWITCH_PENDING
, &card
->tst_state
);
1665 if (!timer_pending(&card
->tst_timer
))
1666 mod_timer(&card
->tst_timer
, jiffies
+ 1);
1668 spin_unlock_irqrestore(&card
->tst_lock
, flags
);
1673 __clear_tst(struct idt77252_dev
*card
, struct vc_map
*vc
)
1678 idle
= card
->tst
[card
->tst_index
^ 1];
1680 for (e
= 0; e
< card
->tst_size
- 2; e
++) {
1681 if (card
->soft_tst
[e
].vc
== vc
) {
1682 card
->soft_tst
[e
].vc
= NULL
;
1684 card
->soft_tst
[e
].tste
= TSTE_OPC_VAR
;
1685 if (timer_pending(&card
->tst_timer
))
1686 card
->soft_tst
[e
].tste
|= TSTE_PUSH_ACTIVE
;
1688 write_sram(card
, idle
+ e
, TSTE_OPC_VAR
);
1689 card
->soft_tst
[e
].tste
|= TSTE_PUSH_IDLE
;
1698 clear_tst(struct idt77252_dev
*card
, struct vc_map
*vc
)
1700 unsigned long flags
;
1703 spin_lock_irqsave(&card
->tst_lock
, flags
);
1705 res
= __clear_tst(card
, vc
);
1707 set_bit(TST_SWITCH_PENDING
, &card
->tst_state
);
1708 if (!timer_pending(&card
->tst_timer
))
1709 mod_timer(&card
->tst_timer
, jiffies
+ 1);
1711 spin_unlock_irqrestore(&card
->tst_lock
, flags
);
1716 change_tst(struct idt77252_dev
*card
, struct vc_map
*vc
,
1717 int n
, unsigned int opc
)
1719 unsigned long flags
;
1722 spin_lock_irqsave(&card
->tst_lock
, flags
);
1724 __clear_tst(card
, vc
);
1725 res
= __fill_tst(card
, vc
, n
, opc
);
1727 set_bit(TST_SWITCH_PENDING
, &card
->tst_state
);
1728 if (!timer_pending(&card
->tst_timer
))
1729 mod_timer(&card
->tst_timer
, jiffies
+ 1);
1731 spin_unlock_irqrestore(&card
->tst_lock
, flags
);
1737 set_tct(struct idt77252_dev
*card
, struct vc_map
*vc
)
1741 tct
= (unsigned long) (card
->tct_base
+ vc
->index
* SAR_SRAM_TCT_SIZE
);
1743 switch (vc
->class) {
1745 OPRINTK("%s: writing TCT at 0x%lx, SCD 0x%lx.\n",
1746 card
->name
, tct
, vc
->scq
->scd
);
1748 write_sram(card
, tct
+ 0, TCT_CBR
| vc
->scq
->scd
);
1749 write_sram(card
, tct
+ 1, 0);
1750 write_sram(card
, tct
+ 2, 0);
1751 write_sram(card
, tct
+ 3, 0);
1752 write_sram(card
, tct
+ 4, 0);
1753 write_sram(card
, tct
+ 5, 0);
1754 write_sram(card
, tct
+ 6, 0);
1755 write_sram(card
, tct
+ 7, 0);
1759 OPRINTK("%s: writing TCT at 0x%lx, SCD 0x%lx.\n",
1760 card
->name
, tct
, vc
->scq
->scd
);
1762 write_sram(card
, tct
+ 0, TCT_UBR
| vc
->scq
->scd
);
1763 write_sram(card
, tct
+ 1, 0);
1764 write_sram(card
, tct
+ 2, TCT_TSIF
);
1765 write_sram(card
, tct
+ 3, TCT_HALT
| TCT_IDLE
);
1766 write_sram(card
, tct
+ 4, 0);
1767 write_sram(card
, tct
+ 5, vc
->init_er
);
1768 write_sram(card
, tct
+ 6, 0);
1769 write_sram(card
, tct
+ 7, TCT_FLAG_UBR
);
1781 /*****************************************************************************/
1785 /*****************************************************************************/
1787 static __inline__
int
1788 idt77252_fbq_full(struct idt77252_dev
*card
, int queue
)
1790 return (readl(SAR_REG_STAT
) >> (16 + (queue
<< 2))) == 0x0f;
1794 push_rx_skb(struct idt77252_dev
*card
, struct sk_buff
*skb
, int queue
)
1796 unsigned long flags
;
1800 skb
->data
= skb
->head
;
1801 skb_reset_tail_pointer(skb
);
1804 skb_reserve(skb
, 16);
1808 skb_put(skb
, SAR_FB_SIZE_0
);
1811 skb_put(skb
, SAR_FB_SIZE_1
);
1814 skb_put(skb
, SAR_FB_SIZE_2
);
1817 skb_put(skb
, SAR_FB_SIZE_3
);
1823 if (idt77252_fbq_full(card
, queue
))
1826 memset(&skb
->data
[(skb
->len
& ~(0x3f)) - 64], 0, 2 * sizeof(u32
));
1828 handle
= IDT77252_PRV_POOL(skb
);
1829 addr
= IDT77252_PRV_PADDR(skb
);
1831 spin_lock_irqsave(&card
->cmd_lock
, flags
);
1832 writel(handle
, card
->fbq
[queue
]);
1833 writel(addr
, card
->fbq
[queue
]);
1834 spin_unlock_irqrestore(&card
->cmd_lock
, flags
);
1840 add_rx_skb(struct idt77252_dev
*card
, int queue
,
1841 unsigned int size
, unsigned int count
)
1843 struct sk_buff
*skb
;
1848 skb
= dev_alloc_skb(size
);
1852 if (sb_pool_add(card
, skb
, queue
)) {
1853 printk("%s: SB POOL full\n", __func__
);
1857 paddr
= dma_map_single(&card
->pcidev
->dev
, skb
->data
,
1858 skb_end_pointer(skb
) - skb
->data
,
1860 IDT77252_PRV_PADDR(skb
) = paddr
;
1862 if (push_rx_skb(card
, skb
, queue
)) {
1863 printk("%s: FB QUEUE full\n", __func__
);
1871 dma_unmap_single(&card
->pcidev
->dev
, IDT77252_PRV_PADDR(skb
),
1872 skb_end_pointer(skb
) - skb
->data
, DMA_FROM_DEVICE
);
1874 handle
= IDT77252_PRV_POOL(skb
);
1875 card
->sbpool
[POOL_QUEUE(handle
)].skb
[POOL_INDEX(handle
)] = NULL
;
1883 recycle_rx_skb(struct idt77252_dev
*card
, struct sk_buff
*skb
)
1885 u32 handle
= IDT77252_PRV_POOL(skb
);
1888 dma_sync_single_for_device(&card
->pcidev
->dev
, IDT77252_PRV_PADDR(skb
),
1889 skb_end_pointer(skb
) - skb
->data
,
1892 err
= push_rx_skb(card
, skb
, POOL_QUEUE(handle
));
1894 dma_unmap_single(&card
->pcidev
->dev
, IDT77252_PRV_PADDR(skb
),
1895 skb_end_pointer(skb
) - skb
->data
,
1897 sb_pool_remove(card
, skb
);
1903 flush_rx_pool(struct idt77252_dev
*card
, struct rx_pool
*rpp
)
1905 skb_queue_head_init(&rpp
->queue
);
1910 recycle_rx_pool_skb(struct idt77252_dev
*card
, struct rx_pool
*rpp
)
1912 struct sk_buff
*skb
, *tmp
;
1914 skb_queue_walk_safe(&rpp
->queue
, skb
, tmp
)
1915 recycle_rx_skb(card
, skb
);
1917 flush_rx_pool(card
, rpp
);
1920 /*****************************************************************************/
1924 /*****************************************************************************/
1927 idt77252_phy_put(struct atm_dev
*dev
, unsigned char value
, unsigned long addr
)
1929 write_utility(dev
->dev_data
, 0x100 + (addr
& 0x1ff), value
);
1932 static unsigned char
1933 idt77252_phy_get(struct atm_dev
*dev
, unsigned long addr
)
1935 return read_utility(dev
->dev_data
, 0x100 + (addr
& 0x1ff));
1939 idt77252_send_skb(struct atm_vcc
*vcc
, struct sk_buff
*skb
, int oam
)
1941 struct atm_dev
*dev
= vcc
->dev
;
1942 struct idt77252_dev
*card
= dev
->dev_data
;
1943 struct vc_map
*vc
= vcc
->dev_data
;
1947 printk("%s: NULL connection in send().\n", card
->name
);
1948 atomic_inc(&vcc
->stats
->tx_err
);
1952 if (!test_bit(VCF_TX
, &vc
->flags
)) {
1953 printk("%s: Trying to transmit on a non-tx VC.\n", card
->name
);
1954 atomic_inc(&vcc
->stats
->tx_err
);
1959 switch (vcc
->qos
.aal
) {
1965 printk("%s: Unsupported AAL: %d\n", card
->name
, vcc
->qos
.aal
);
1966 atomic_inc(&vcc
->stats
->tx_err
);
1971 if (skb_shinfo(skb
)->nr_frags
!= 0) {
1972 printk("%s: No scatter-gather yet.\n", card
->name
);
1973 atomic_inc(&vcc
->stats
->tx_err
);
1977 ATM_SKB(skb
)->vcc
= vcc
;
1979 err
= queue_skb(card
, vc
, skb
, oam
);
1981 atomic_inc(&vcc
->stats
->tx_err
);
1989 static int idt77252_send(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
1991 return idt77252_send_skb(vcc
, skb
, 0);
1995 idt77252_send_oam(struct atm_vcc
*vcc
, void *cell
, int flags
)
1997 struct atm_dev
*dev
= vcc
->dev
;
1998 struct idt77252_dev
*card
= dev
->dev_data
;
1999 struct sk_buff
*skb
;
2001 skb
= dev_alloc_skb(64);
2003 printk("%s: Out of memory in send_oam().\n", card
->name
);
2004 atomic_inc(&vcc
->stats
->tx_err
);
2007 refcount_add(skb
->truesize
, &sk_atm(vcc
)->sk_wmem_alloc
);
2009 skb_put_data(skb
, cell
, 52);
2011 return idt77252_send_skb(vcc
, skb
, 1);
2014 static __inline__
unsigned int
2015 idt77252_fls(unsigned int x
)
2021 if (x
& 0xffff0000) {
2043 idt77252_int_to_atmfp(unsigned int rate
)
2049 e
= idt77252_fls(rate
) - 1;
2051 m
= (rate
- (1 << e
)) << (9 - e
);
2053 m
= (rate
- (1 << e
));
2055 m
= (rate
- (1 << e
)) >> (e
- 9);
2056 return 0x4000 | (e
<< 9) | m
;
2060 idt77252_rate_logindex(struct idt77252_dev
*card
, int pcr
)
2064 afp
= idt77252_int_to_atmfp(pcr
< 0 ? -pcr
: pcr
);
2066 return rate_to_log
[(afp
>> 5) & 0x1ff];
2067 return rate_to_log
[((afp
>> 5) + 1) & 0x1ff];
2071 idt77252_est_timer(struct timer_list
*t
)
2073 struct rate_estimator
*est
= from_timer(est
, t
, timer
);
2074 struct vc_map
*vc
= est
->vc
;
2075 struct idt77252_dev
*card
= vc
->card
;
2076 unsigned long flags
;
2081 spin_lock_irqsave(&vc
->lock
, flags
);
2084 ncells
= est
->cells
;
2086 rate
= ((u32
)(ncells
- est
->last_cells
)) << (7 - est
->interval
);
2087 est
->last_cells
= ncells
;
2088 est
->avcps
+= ((long)rate
- (long)est
->avcps
) >> est
->ewma_log
;
2089 est
->cps
= (est
->avcps
+ 0x1f) >> 5;
2092 if (cps
< (est
->maxcps
>> 4))
2093 cps
= est
->maxcps
>> 4;
2095 lacr
= idt77252_rate_logindex(card
, cps
);
2096 if (lacr
> vc
->max_er
)
2099 if (lacr
!= vc
->lacr
) {
2101 writel(TCMDQ_LACR
|(vc
->lacr
<< 16)|vc
->index
, SAR_REG_TCMDQ
);
2104 est
->timer
.expires
= jiffies
+ ((HZ
/ 4) << est
->interval
);
2105 add_timer(&est
->timer
);
2108 spin_unlock_irqrestore(&vc
->lock
, flags
);
2111 static struct rate_estimator
*
2112 idt77252_init_est(struct vc_map
*vc
, int pcr
)
2114 struct rate_estimator
*est
;
2116 est
= kzalloc(sizeof(struct rate_estimator
), GFP_KERNEL
);
2119 est
->maxcps
= pcr
< 0 ? -pcr
: pcr
;
2120 est
->cps
= est
->maxcps
;
2121 est
->avcps
= est
->cps
<< 5;
2124 est
->interval
= 2; /* XXX: make this configurable */
2125 est
->ewma_log
= 2; /* XXX: make this configurable */
2126 timer_setup(&est
->timer
, idt77252_est_timer
, 0);
2127 mod_timer(&est
->timer
, jiffies
+ ((HZ
/ 4) << est
->interval
));
2133 idt77252_init_cbr(struct idt77252_dev
*card
, struct vc_map
*vc
,
2134 struct atm_vcc
*vcc
, struct atm_qos
*qos
)
2136 int tst_free
, tst_used
, tst_entries
;
2137 unsigned long tmpl
, modl
;
2140 if ((qos
->txtp
.max_pcr
== 0) &&
2141 (qos
->txtp
.pcr
== 0) && (qos
->txtp
.min_pcr
== 0)) {
2142 printk("%s: trying to open a CBR VC with cell rate = 0\n",
2148 tst_free
= card
->tst_free
;
2149 if (test_bit(VCF_TX
, &vc
->flags
))
2150 tst_used
= vc
->ntste
;
2151 tst_free
+= tst_used
;
2153 tcr
= atm_pcr_goal(&qos
->txtp
);
2154 tcra
= tcr
>= 0 ? tcr
: -tcr
;
2156 TXPRINTK("%s: CBR target cell rate = %d\n", card
->name
, tcra
);
2158 tmpl
= (unsigned long) tcra
* ((unsigned long) card
->tst_size
- 2);
2159 modl
= tmpl
% (unsigned long)card
->utopia_pcr
;
2161 tst_entries
= (int) (tmpl
/ card
->utopia_pcr
);
2165 } else if (tcr
== 0) {
2166 tst_entries
= tst_free
- SAR_TST_RESERVED
;
2167 if (tst_entries
<= 0) {
2168 printk("%s: no CBR bandwidth free.\n", card
->name
);
2173 if (tst_entries
== 0) {
2174 printk("%s: selected CBR bandwidth < granularity.\n",
2179 if (tst_entries
> (tst_free
- SAR_TST_RESERVED
)) {
2180 printk("%s: not enough CBR bandwidth free.\n", card
->name
);
2184 vc
->ntste
= tst_entries
;
2186 card
->tst_free
= tst_free
- tst_entries
;
2187 if (test_bit(VCF_TX
, &vc
->flags
)) {
2188 if (tst_used
== tst_entries
)
2191 OPRINTK("%s: modify %d -> %d entries in TST.\n",
2192 card
->name
, tst_used
, tst_entries
);
2193 change_tst(card
, vc
, tst_entries
, TSTE_OPC_CBR
);
2197 OPRINTK("%s: setting %d entries in TST.\n", card
->name
, tst_entries
);
2198 fill_tst(card
, vc
, tst_entries
, TSTE_OPC_CBR
);
2203 idt77252_init_ubr(struct idt77252_dev
*card
, struct vc_map
*vc
,
2204 struct atm_vcc
*vcc
, struct atm_qos
*qos
)
2206 struct rate_estimator
*est
= NULL
;
2207 unsigned long flags
;
2210 spin_lock_irqsave(&vc
->lock
, flags
);
2211 if (vc
->estimator
) {
2212 est
= vc
->estimator
;
2213 vc
->estimator
= NULL
;
2215 spin_unlock_irqrestore(&vc
->lock
, flags
);
2217 timer_shutdown_sync(&est
->timer
);
2221 tcr
= atm_pcr_goal(&qos
->txtp
);
2223 tcr
= card
->link_pcr
;
2225 vc
->estimator
= idt77252_init_est(vc
, tcr
);
2227 vc
->class = SCHED_UBR
;
2228 vc
->init_er
= idt77252_rate_logindex(card
, tcr
);
2229 vc
->lacr
= vc
->init_er
;
2231 vc
->max_er
= vc
->init_er
;
2239 idt77252_init_tx(struct idt77252_dev
*card
, struct vc_map
*vc
,
2240 struct atm_vcc
*vcc
, struct atm_qos
*qos
)
2244 if (test_bit(VCF_TX
, &vc
->flags
))
2247 switch (qos
->txtp
.traffic_class
) {
2249 vc
->class = SCHED_CBR
;
2253 vc
->class = SCHED_UBR
;
2259 return -EPROTONOSUPPORT
;
2262 vc
->scq
= alloc_scq(card
, vc
->class);
2264 printk("%s: can't get SCQ.\n", card
->name
);
2268 vc
->scq
->scd
= get_free_scd(card
, vc
);
2269 if (vc
->scq
->scd
== 0) {
2270 printk("%s: no SCD available.\n", card
->name
);
2271 free_scq(card
, vc
->scq
);
2275 fill_scd(card
, vc
->scq
, vc
->class);
2277 if (set_tct(card
, vc
)) {
2278 printk("%s: class %d not supported.\n",
2279 card
->name
, qos
->txtp
.traffic_class
);
2281 card
->scd2vc
[vc
->scd_index
] = NULL
;
2282 free_scq(card
, vc
->scq
);
2283 return -EPROTONOSUPPORT
;
2286 switch (vc
->class) {
2288 error
= idt77252_init_cbr(card
, vc
, vcc
, qos
);
2290 card
->scd2vc
[vc
->scd_index
] = NULL
;
2291 free_scq(card
, vc
->scq
);
2295 clear_bit(VCF_IDLE
, &vc
->flags
);
2296 writel(TCMDQ_START
| vc
->index
, SAR_REG_TCMDQ
);
2300 error
= idt77252_init_ubr(card
, vc
, vcc
, qos
);
2302 card
->scd2vc
[vc
->scd_index
] = NULL
;
2303 free_scq(card
, vc
->scq
);
2307 set_bit(VCF_IDLE
, &vc
->flags
);
2312 set_bit(VCF_TX
, &vc
->flags
);
2317 idt77252_init_rx(struct idt77252_dev
*card
, struct vc_map
*vc
,
2318 struct atm_vcc
*vcc
, struct atm_qos
*qos
)
2320 unsigned long flags
;
2324 if (test_bit(VCF_RX
, &vc
->flags
))
2328 set_bit(VCF_RX
, &vc
->flags
);
2330 if ((vcc
->vci
== 3) || (vcc
->vci
== 4))
2333 flush_rx_pool(card
, &vc
->rcv
.rx_pool
);
2335 rcte
|= SAR_RCTE_CONNECTOPEN
;
2336 rcte
|= SAR_RCTE_RAWCELLINTEN
;
2340 rcte
|= SAR_RCTE_RCQ
;
2343 rcte
|= SAR_RCTE_OAM
; /* Let SAR drop Video */
2346 rcte
|= SAR_RCTE_AAL34
;
2349 rcte
|= SAR_RCTE_AAL5
;
2352 rcte
|= SAR_RCTE_RCQ
;
2356 if (qos
->aal
!= ATM_AAL5
)
2357 rcte
|= SAR_RCTE_FBP_1
;
2358 else if (qos
->rxtp
.max_sdu
> SAR_FB_SIZE_2
)
2359 rcte
|= SAR_RCTE_FBP_3
;
2360 else if (qos
->rxtp
.max_sdu
> SAR_FB_SIZE_1
)
2361 rcte
|= SAR_RCTE_FBP_2
;
2362 else if (qos
->rxtp
.max_sdu
> SAR_FB_SIZE_0
)
2363 rcte
|= SAR_RCTE_FBP_1
;
2365 rcte
|= SAR_RCTE_FBP_01
;
2367 addr
= card
->rct_base
+ (vc
->index
<< 2);
2369 OPRINTK("%s: writing RCT at 0x%lx\n", card
->name
, addr
);
2370 write_sram(card
, addr
, rcte
);
2372 spin_lock_irqsave(&card
->cmd_lock
, flags
);
2373 writel(SAR_CMD_OPEN_CONNECTION
| (addr
<< 2), SAR_REG_CMD
);
2375 spin_unlock_irqrestore(&card
->cmd_lock
, flags
);
2381 idt77252_open(struct atm_vcc
*vcc
)
2383 struct atm_dev
*dev
= vcc
->dev
;
2384 struct idt77252_dev
*card
= dev
->dev_data
;
2390 short vpi
= vcc
->vpi
;
2392 if (vpi
== ATM_VPI_UNSPEC
|| vci
== ATM_VCI_UNSPEC
)
2395 if (vpi
>= (1 << card
->vpibits
)) {
2396 printk("%s: unsupported VPI: %d\n", card
->name
, vpi
);
2400 if (vci
>= (1 << card
->vcibits
)) {
2401 printk("%s: unsupported VCI: %d\n", card
->name
, vci
);
2405 set_bit(ATM_VF_ADDR
, &vcc
->flags
);
2407 mutex_lock(&card
->mutex
);
2409 OPRINTK("%s: opening vpi.vci: %d.%d\n", card
->name
, vpi
, vci
);
2411 switch (vcc
->qos
.aal
) {
2417 printk("%s: Unsupported AAL: %d\n", card
->name
, vcc
->qos
.aal
);
2418 mutex_unlock(&card
->mutex
);
2419 return -EPROTONOSUPPORT
;
2422 index
= VPCI2VC(card
, vpi
, vci
);
2423 if (!card
->vcs
[index
]) {
2424 card
->vcs
[index
] = kzalloc(sizeof(struct vc_map
), GFP_KERNEL
);
2425 if (!card
->vcs
[index
]) {
2426 printk("%s: can't alloc vc in open()\n", card
->name
);
2427 mutex_unlock(&card
->mutex
);
2430 card
->vcs
[index
]->card
= card
;
2431 card
->vcs
[index
]->index
= index
;
2433 spin_lock_init(&card
->vcs
[index
]->lock
);
2435 vc
= card
->vcs
[index
];
2439 IPRINTK("%s: idt77252_open: vc = %d (%d.%d) %s/%s (max RX SDU: %u)\n",
2440 card
->name
, vc
->index
, vcc
->vpi
, vcc
->vci
,
2441 vcc
->qos
.rxtp
.traffic_class
!= ATM_NONE
? "rx" : "--",
2442 vcc
->qos
.txtp
.traffic_class
!= ATM_NONE
? "tx" : "--",
2443 vcc
->qos
.rxtp
.max_sdu
);
2446 if (vcc
->qos
.txtp
.traffic_class
!= ATM_NONE
&&
2447 test_bit(VCF_TX
, &vc
->flags
))
2449 if (vcc
->qos
.rxtp
.traffic_class
!= ATM_NONE
&&
2450 test_bit(VCF_RX
, &vc
->flags
))
2454 printk("%s: %s vci already in use.\n", card
->name
,
2455 inuse
== 1 ? "tx" : inuse
== 2 ? "rx" : "tx and rx");
2456 mutex_unlock(&card
->mutex
);
2460 if (vcc
->qos
.txtp
.traffic_class
!= ATM_NONE
) {
2461 error
= idt77252_init_tx(card
, vc
, vcc
, &vcc
->qos
);
2463 mutex_unlock(&card
->mutex
);
2468 if (vcc
->qos
.rxtp
.traffic_class
!= ATM_NONE
) {
2469 error
= idt77252_init_rx(card
, vc
, vcc
, &vcc
->qos
);
2471 mutex_unlock(&card
->mutex
);
2476 set_bit(ATM_VF_READY
, &vcc
->flags
);
2478 mutex_unlock(&card
->mutex
);
2483 idt77252_close(struct atm_vcc
*vcc
)
2485 struct atm_dev
*dev
= vcc
->dev
;
2486 struct idt77252_dev
*card
= dev
->dev_data
;
2487 struct vc_map
*vc
= vcc
->dev_data
;
2488 unsigned long flags
;
2490 unsigned long timeout
;
2492 mutex_lock(&card
->mutex
);
2494 IPRINTK("%s: idt77252_close: vc = %d (%d.%d)\n",
2495 card
->name
, vc
->index
, vcc
->vpi
, vcc
->vci
);
2497 clear_bit(ATM_VF_READY
, &vcc
->flags
);
2499 if (vcc
->qos
.rxtp
.traffic_class
!= ATM_NONE
) {
2501 spin_lock_irqsave(&vc
->lock
, flags
);
2502 clear_bit(VCF_RX
, &vc
->flags
);
2504 spin_unlock_irqrestore(&vc
->lock
, flags
);
2506 if ((vcc
->vci
== 3) || (vcc
->vci
== 4))
2509 addr
= card
->rct_base
+ vc
->index
* SAR_SRAM_RCT_SIZE
;
2511 spin_lock_irqsave(&card
->cmd_lock
, flags
);
2512 writel(SAR_CMD_CLOSE_CONNECTION
| (addr
<< 2), SAR_REG_CMD
);
2514 spin_unlock_irqrestore(&card
->cmd_lock
, flags
);
2516 if (skb_queue_len(&vc
->rcv
.rx_pool
.queue
) != 0) {
2517 DPRINTK("%s: closing a VC with pending rx buffers.\n",
2520 recycle_rx_pool_skb(card
, &vc
->rcv
.rx_pool
);
2525 if (vcc
->qos
.txtp
.traffic_class
!= ATM_NONE
) {
2527 spin_lock_irqsave(&vc
->lock
, flags
);
2528 clear_bit(VCF_TX
, &vc
->flags
);
2529 clear_bit(VCF_IDLE
, &vc
->flags
);
2530 clear_bit(VCF_RSV
, &vc
->flags
);
2533 if (vc
->estimator
) {
2534 timer_shutdown(&vc
->estimator
->timer
);
2535 kfree(vc
->estimator
);
2536 vc
->estimator
= NULL
;
2538 spin_unlock_irqrestore(&vc
->lock
, flags
);
2541 while (atomic_read(&vc
->scq
->used
) > 0) {
2542 timeout
= msleep_interruptible(timeout
);
2544 pr_warn("%s: SCQ drain timeout: %u used\n",
2545 card
->name
, atomic_read(&vc
->scq
->used
));
2550 writel(TCMDQ_HALT
| vc
->index
, SAR_REG_TCMDQ
);
2551 clear_scd(card
, vc
->scq
, vc
->class);
2553 if (vc
->class == SCHED_CBR
) {
2554 clear_tst(card
, vc
);
2555 card
->tst_free
+= vc
->ntste
;
2559 card
->scd2vc
[vc
->scd_index
] = NULL
;
2560 free_scq(card
, vc
->scq
);
2563 mutex_unlock(&card
->mutex
);
2567 idt77252_change_qos(struct atm_vcc
*vcc
, struct atm_qos
*qos
, int flags
)
2569 struct atm_dev
*dev
= vcc
->dev
;
2570 struct idt77252_dev
*card
= dev
->dev_data
;
2571 struct vc_map
*vc
= vcc
->dev_data
;
2574 mutex_lock(&card
->mutex
);
2576 if (qos
->txtp
.traffic_class
!= ATM_NONE
) {
2577 if (!test_bit(VCF_TX
, &vc
->flags
)) {
2578 error
= idt77252_init_tx(card
, vc
, vcc
, qos
);
2582 switch (qos
->txtp
.traffic_class
) {
2584 error
= idt77252_init_cbr(card
, vc
, vcc
, qos
);
2590 error
= idt77252_init_ubr(card
, vc
, vcc
, qos
);
2594 if (!test_bit(VCF_IDLE
, &vc
->flags
)) {
2595 writel(TCMDQ_LACR
| (vc
->lacr
<< 16) |
2596 vc
->index
, SAR_REG_TCMDQ
);
2602 error
= -EOPNOTSUPP
;
2608 if ((qos
->rxtp
.traffic_class
!= ATM_NONE
) &&
2609 !test_bit(VCF_RX
, &vc
->flags
)) {
2610 error
= idt77252_init_rx(card
, vc
, vcc
, qos
);
2615 memcpy(&vcc
->qos
, qos
, sizeof(struct atm_qos
));
2617 set_bit(ATM_VF_HASQOS
, &vcc
->flags
);
2620 mutex_unlock(&card
->mutex
);
2625 idt77252_proc_read(struct atm_dev
*dev
, loff_t
* pos
, char *page
)
2627 struct idt77252_dev
*card
= dev
->dev_data
;
2632 return sprintf(page
, "IDT77252 Interrupts:\n");
2634 return sprintf(page
, "TSIF: %lu\n", card
->irqstat
[15]);
2636 return sprintf(page
, "TXICP: %lu\n", card
->irqstat
[14]);
2638 return sprintf(page
, "TSQF: %lu\n", card
->irqstat
[12]);
2640 return sprintf(page
, "TMROF: %lu\n", card
->irqstat
[11]);
2642 return sprintf(page
, "PHYI: %lu\n", card
->irqstat
[10]);
2644 return sprintf(page
, "FBQ3A: %lu\n", card
->irqstat
[8]);
2646 return sprintf(page
, "FBQ2A: %lu\n", card
->irqstat
[7]);
2648 return sprintf(page
, "RSQF: %lu\n", card
->irqstat
[6]);
2650 return sprintf(page
, "EPDU: %lu\n", card
->irqstat
[5]);
2652 return sprintf(page
, "RAWCF: %lu\n", card
->irqstat
[4]);
2654 return sprintf(page
, "FBQ1A: %lu\n", card
->irqstat
[3]);
2656 return sprintf(page
, "FBQ0A: %lu\n", card
->irqstat
[2]);
2658 return sprintf(page
, "RSQAF: %lu\n", card
->irqstat
[1]);
2660 return sprintf(page
, "IDT77252 Transmit Connection Table:\n");
2662 for (i
= 0; i
< card
->tct_size
; i
++) {
2664 struct atm_vcc
*vcc
;
2681 p
+= sprintf(p
, " %4u: %u.%u: ", i
, vcc
->vpi
, vcc
->vci
);
2682 tct
= (unsigned long) (card
->tct_base
+ i
* SAR_SRAM_TCT_SIZE
);
2684 for (i
= 0; i
< 8; i
++)
2685 p
+= sprintf(p
, " %08x", read_sram(card
, tct
+ i
));
2686 p
+= sprintf(p
, "\n");
2692 /*****************************************************************************/
2694 /* Interrupt handler */
2696 /*****************************************************************************/
2699 idt77252_collect_stat(struct idt77252_dev
*card
)
2701 (void) readl(SAR_REG_CDC
);
2702 (void) readl(SAR_REG_VPEC
);
2703 (void) readl(SAR_REG_ICC
);
2708 idt77252_interrupt(int irq
, void *dev_id
)
2710 struct idt77252_dev
*card
= dev_id
;
2713 stat
= readl(SAR_REG_STAT
) & 0xffff;
2714 if (!stat
) /* no interrupt for us */
2717 if (test_and_set_bit(IDT77252_BIT_INTERRUPT
, &card
->flags
)) {
2718 printk("%s: Re-entering irq_handler()\n", card
->name
);
2722 writel(stat
, SAR_REG_STAT
); /* reset interrupt */
2724 if (stat
& SAR_STAT_TSIF
) { /* entry written to TSQ */
2725 INTPRINTK("%s: TSIF\n", card
->name
);
2726 card
->irqstat
[15]++;
2729 if (stat
& SAR_STAT_TXICP
) { /* Incomplete CS-PDU has */
2730 INTPRINTK("%s: TXICP\n", card
->name
);
2731 card
->irqstat
[14]++;
2732 #ifdef CONFIG_ATM_IDT77252_DEBUG
2733 idt77252_tx_dump(card
);
2736 if (stat
& SAR_STAT_TSQF
) { /* TSQ 7/8 full */
2737 INTPRINTK("%s: TSQF\n", card
->name
);
2738 card
->irqstat
[12]++;
2741 if (stat
& SAR_STAT_TMROF
) { /* Timer overflow */
2742 INTPRINTK("%s: TMROF\n", card
->name
);
2743 card
->irqstat
[11]++;
2744 idt77252_collect_stat(card
);
2747 if (stat
& SAR_STAT_EPDU
) { /* Got complete CS-PDU */
2748 INTPRINTK("%s: EPDU\n", card
->name
);
2752 if (stat
& SAR_STAT_RSQAF
) { /* RSQ is 7/8 full */
2753 INTPRINTK("%s: RSQAF\n", card
->name
);
2757 if (stat
& SAR_STAT_RSQF
) { /* RSQ is full */
2758 INTPRINTK("%s: RSQF\n", card
->name
);
2762 if (stat
& SAR_STAT_RAWCF
) { /* Raw cell received */
2763 INTPRINTK("%s: RAWCF\n", card
->name
);
2765 idt77252_rx_raw(card
);
2768 if (stat
& SAR_STAT_PHYI
) { /* PHY device interrupt */
2769 INTPRINTK("%s: PHYI", card
->name
);
2770 card
->irqstat
[10]++;
2771 if (card
->atmdev
->phy
&& card
->atmdev
->phy
->interrupt
)
2772 card
->atmdev
->phy
->interrupt(card
->atmdev
);
2775 if (stat
& (SAR_STAT_FBQ0A
| SAR_STAT_FBQ1A
|
2776 SAR_STAT_FBQ2A
| SAR_STAT_FBQ3A
)) {
2778 writel(readl(SAR_REG_CFG
) & ~(SAR_CFG_FBIE
), SAR_REG_CFG
);
2780 INTPRINTK("%s: FBQA: %04x\n", card
->name
, stat
);
2782 if (stat
& SAR_STAT_FBQ0A
)
2784 if (stat
& SAR_STAT_FBQ1A
)
2786 if (stat
& SAR_STAT_FBQ2A
)
2788 if (stat
& SAR_STAT_FBQ3A
)
2791 schedule_work(&card
->tqueue
);
2795 clear_bit(IDT77252_BIT_INTERRUPT
, &card
->flags
);
2800 idt77252_softint(struct work_struct
*work
)
2802 struct idt77252_dev
*card
=
2803 container_of(work
, struct idt77252_dev
, tqueue
);
2807 for (done
= 1; ; done
= 1) {
2808 stat
= readl(SAR_REG_STAT
) >> 16;
2810 if ((stat
& 0x0f) < SAR_FBQ0_HIGH
) {
2811 add_rx_skb(card
, 0, SAR_FB_SIZE_0
, 32);
2816 if ((stat
& 0x0f) < SAR_FBQ1_HIGH
) {
2817 add_rx_skb(card
, 1, SAR_FB_SIZE_1
, 32);
2822 if ((stat
& 0x0f) < SAR_FBQ2_HIGH
) {
2823 add_rx_skb(card
, 2, SAR_FB_SIZE_2
, 32);
2828 if ((stat
& 0x0f) < SAR_FBQ3_HIGH
) {
2829 add_rx_skb(card
, 3, SAR_FB_SIZE_3
, 32);
2837 writel(readl(SAR_REG_CFG
) | SAR_CFG_FBIE
, SAR_REG_CFG
);
2842 open_card_oam(struct idt77252_dev
*card
)
2844 unsigned long flags
;
2851 for (vpi
= 0; vpi
< (1 << card
->vpibits
); vpi
++) {
2852 for (vci
= 3; vci
< 5; vci
++) {
2853 index
= VPCI2VC(card
, vpi
, vci
);
2855 vc
= kzalloc(sizeof(struct vc_map
), GFP_KERNEL
);
2857 printk("%s: can't alloc vc\n", card
->name
);
2861 card
->vcs
[index
] = vc
;
2863 flush_rx_pool(card
, &vc
->rcv
.rx_pool
);
2865 rcte
= SAR_RCTE_CONNECTOPEN
|
2866 SAR_RCTE_RAWCELLINTEN
|
2870 addr
= card
->rct_base
+ (vc
->index
<< 2);
2871 write_sram(card
, addr
, rcte
);
2873 spin_lock_irqsave(&card
->cmd_lock
, flags
);
2874 writel(SAR_CMD_OPEN_CONNECTION
| (addr
<< 2),
2877 spin_unlock_irqrestore(&card
->cmd_lock
, flags
);
2885 close_card_oam(struct idt77252_dev
*card
)
2887 unsigned long flags
;
2893 for (vpi
= 0; vpi
< (1 << card
->vpibits
); vpi
++) {
2894 for (vci
= 3; vci
< 5; vci
++) {
2895 index
= VPCI2VC(card
, vpi
, vci
);
2896 vc
= card
->vcs
[index
];
2898 addr
= card
->rct_base
+ vc
->index
* SAR_SRAM_RCT_SIZE
;
2900 spin_lock_irqsave(&card
->cmd_lock
, flags
);
2901 writel(SAR_CMD_CLOSE_CONNECTION
| (addr
<< 2),
2904 spin_unlock_irqrestore(&card
->cmd_lock
, flags
);
2906 if (skb_queue_len(&vc
->rcv
.rx_pool
.queue
) != 0) {
2907 DPRINTK("%s: closing a VC "
2908 "with pending rx buffers.\n",
2911 recycle_rx_pool_skb(card
, &vc
->rcv
.rx_pool
);
2919 open_card_ubr0(struct idt77252_dev
*card
)
2923 vc
= kzalloc(sizeof(struct vc_map
), GFP_KERNEL
);
2925 printk("%s: can't alloc vc\n", card
->name
);
2929 vc
->class = SCHED_UBR0
;
2931 vc
->scq
= alloc_scq(card
, vc
->class);
2933 printk("%s: can't get SCQ.\n", card
->name
);
2934 kfree(card
->vcs
[0]);
2935 card
->vcs
[0] = NULL
;
2939 card
->scd2vc
[0] = vc
;
2941 vc
->scq
->scd
= card
->scd_base
;
2943 fill_scd(card
, vc
->scq
, vc
->class);
2945 write_sram(card
, card
->tct_base
+ 0, TCT_UBR
| card
->scd_base
);
2946 write_sram(card
, card
->tct_base
+ 1, 0);
2947 write_sram(card
, card
->tct_base
+ 2, 0);
2948 write_sram(card
, card
->tct_base
+ 3, 0);
2949 write_sram(card
, card
->tct_base
+ 4, 0);
2950 write_sram(card
, card
->tct_base
+ 5, 0);
2951 write_sram(card
, card
->tct_base
+ 6, 0);
2952 write_sram(card
, card
->tct_base
+ 7, TCT_FLAG_UBR
);
2954 clear_bit(VCF_IDLE
, &vc
->flags
);
2955 writel(TCMDQ_START
| 0, SAR_REG_TCMDQ
);
2960 close_card_ubr0(struct idt77252_dev
*card
)
2962 struct vc_map
*vc
= card
->vcs
[0];
2964 free_scq(card
, vc
->scq
);
2969 idt77252_dev_open(struct idt77252_dev
*card
)
2973 if (!test_bit(IDT77252_BIT_INIT
, &card
->flags
)) {
2974 printk("%s: SAR not yet initialized.\n", card
->name
);
2978 conf
= SAR_CFG_RXPTH
| /* enable receive path */
2979 SAR_RX_DELAY
| /* interrupt on complete PDU */
2980 SAR_CFG_RAWIE
| /* interrupt enable on raw cells */
2981 SAR_CFG_RQFIE
| /* interrupt on RSQ almost full */
2982 SAR_CFG_TMOIE
| /* interrupt on timer overflow */
2983 SAR_CFG_FBIE
| /* interrupt on low free buffers */
2984 SAR_CFG_TXEN
| /* transmit operation enable */
2985 SAR_CFG_TXINT
| /* interrupt on transmit status */
2986 SAR_CFG_TXUIE
| /* interrupt on transmit underrun */
2987 SAR_CFG_TXSFI
| /* interrupt on TSQ almost full */
2988 SAR_CFG_PHYIE
/* enable PHY interrupts */
2991 #ifdef CONFIG_ATM_IDT77252_RCV_ALL
2992 /* Test RAW cell receive. */
2993 conf
|= SAR_CFG_VPECA
;
2996 writel(readl(SAR_REG_CFG
) | conf
, SAR_REG_CFG
);
2998 if (open_card_oam(card
)) {
2999 printk("%s: Error initializing OAM.\n", card
->name
);
3003 if (open_card_ubr0(card
)) {
3004 printk("%s: Error initializing UBR0.\n", card
->name
);
3008 IPRINTK("%s: opened IDT77252 ABR SAR.\n", card
->name
);
3012 static void idt77252_dev_close(struct atm_dev
*dev
)
3014 struct idt77252_dev
*card
= dev
->dev_data
;
3017 close_card_ubr0(card
);
3018 close_card_oam(card
);
3020 conf
= SAR_CFG_RXPTH
| /* enable receive path */
3021 SAR_RX_DELAY
| /* interrupt on complete PDU */
3022 SAR_CFG_RAWIE
| /* interrupt enable on raw cells */
3023 SAR_CFG_RQFIE
| /* interrupt on RSQ almost full */
3024 SAR_CFG_TMOIE
| /* interrupt on timer overflow */
3025 SAR_CFG_FBIE
| /* interrupt on low free buffers */
3026 SAR_CFG_TXEN
| /* transmit operation enable */
3027 SAR_CFG_TXINT
| /* interrupt on transmit status */
3028 SAR_CFG_TXUIE
| /* interrupt on xmit underrun */
3029 SAR_CFG_TXSFI
/* interrupt on TSQ almost full */
3032 writel(readl(SAR_REG_CFG
) & ~(conf
), SAR_REG_CFG
);
3034 DIPRINTK("%s: closed IDT77252 ABR SAR.\n", card
->name
);
3038 /*****************************************************************************/
3040 /* Initialisation and Deinitialization of IDT77252 */
3042 /*****************************************************************************/
3046 deinit_card(struct idt77252_dev
*card
)
3048 struct sk_buff
*skb
;
3051 if (!test_bit(IDT77252_BIT_INIT
, &card
->flags
)) {
3052 printk("%s: SAR not yet initialized.\n", card
->name
);
3055 DIPRINTK("idt77252: deinitialize card %u\n", card
->index
);
3057 writel(0, SAR_REG_CFG
);
3060 atm_dev_deregister(card
->atmdev
);
3062 for (i
= 0; i
< 4; i
++) {
3063 for (j
= 0; j
< FBQ_SIZE
; j
++) {
3064 skb
= card
->sbpool
[i
].skb
[j
];
3066 dma_unmap_single(&card
->pcidev
->dev
,
3067 IDT77252_PRV_PADDR(skb
),
3068 (skb_end_pointer(skb
) -
3071 card
->sbpool
[i
].skb
[j
] = NULL
;
3077 vfree(card
->soft_tst
);
3079 vfree(card
->scd2vc
);
3083 if (card
->raw_cell_hnd
) {
3084 dma_free_coherent(&card
->pcidev
->dev
, 2 * sizeof(u32
),
3085 card
->raw_cell_hnd
, card
->raw_cell_paddr
);
3088 if (card
->rsq
.base
) {
3089 DIPRINTK("%s: Release RSQ ...\n", card
->name
);
3093 if (card
->tsq
.base
) {
3094 DIPRINTK("%s: Release TSQ ...\n", card
->name
);
3098 DIPRINTK("idt77252: Release IRQ.\n");
3099 free_irq(card
->pcidev
->irq
, card
);
3101 for (i
= 0; i
< 4; i
++) {
3103 iounmap(card
->fbq
[i
]);
3107 iounmap(card
->membase
);
3109 clear_bit(IDT77252_BIT_INIT
, &card
->flags
);
3110 DIPRINTK("%s: Card deinitialized.\n", card
->name
);
3114 static void init_sram(struct idt77252_dev
*card
)
3118 for (i
= 0; i
< card
->sramsize
; i
+= 4)
3119 write_sram(card
, (i
>> 2), 0);
3121 /* set SRAM layout for THIS card */
3122 if (card
->sramsize
== (512 * 1024)) {
3123 card
->tct_base
= SAR_SRAM_TCT_128_BASE
;
3124 card
->tct_size
= (SAR_SRAM_TCT_128_TOP
- card
->tct_base
+ 1)
3125 / SAR_SRAM_TCT_SIZE
;
3126 card
->rct_base
= SAR_SRAM_RCT_128_BASE
;
3127 card
->rct_size
= (SAR_SRAM_RCT_128_TOP
- card
->rct_base
+ 1)
3128 / SAR_SRAM_RCT_SIZE
;
3129 card
->rt_base
= SAR_SRAM_RT_128_BASE
;
3130 card
->scd_base
= SAR_SRAM_SCD_128_BASE
;
3131 card
->scd_size
= (SAR_SRAM_SCD_128_TOP
- card
->scd_base
+ 1)
3132 / SAR_SRAM_SCD_SIZE
;
3133 card
->tst
[0] = SAR_SRAM_TST1_128_BASE
;
3134 card
->tst
[1] = SAR_SRAM_TST2_128_BASE
;
3135 card
->tst_size
= SAR_SRAM_TST1_128_TOP
- card
->tst
[0] + 1;
3136 card
->abrst_base
= SAR_SRAM_ABRSTD_128_BASE
;
3137 card
->abrst_size
= SAR_ABRSTD_SIZE_8K
;
3138 card
->fifo_base
= SAR_SRAM_FIFO_128_BASE
;
3139 card
->fifo_size
= SAR_RXFD_SIZE_32K
;
3141 card
->tct_base
= SAR_SRAM_TCT_32_BASE
;
3142 card
->tct_size
= (SAR_SRAM_TCT_32_TOP
- card
->tct_base
+ 1)
3143 / SAR_SRAM_TCT_SIZE
;
3144 card
->rct_base
= SAR_SRAM_RCT_32_BASE
;
3145 card
->rct_size
= (SAR_SRAM_RCT_32_TOP
- card
->rct_base
+ 1)
3146 / SAR_SRAM_RCT_SIZE
;
3147 card
->rt_base
= SAR_SRAM_RT_32_BASE
;
3148 card
->scd_base
= SAR_SRAM_SCD_32_BASE
;
3149 card
->scd_size
= (SAR_SRAM_SCD_32_TOP
- card
->scd_base
+ 1)
3150 / SAR_SRAM_SCD_SIZE
;
3151 card
->tst
[0] = SAR_SRAM_TST1_32_BASE
;
3152 card
->tst
[1] = SAR_SRAM_TST2_32_BASE
;
3153 card
->tst_size
= (SAR_SRAM_TST1_32_TOP
- card
->tst
[0] + 1);
3154 card
->abrst_base
= SAR_SRAM_ABRSTD_32_BASE
;
3155 card
->abrst_size
= SAR_ABRSTD_SIZE_1K
;
3156 card
->fifo_base
= SAR_SRAM_FIFO_32_BASE
;
3157 card
->fifo_size
= SAR_RXFD_SIZE_4K
;
3160 /* Initialize TCT */
3161 for (i
= 0; i
< card
->tct_size
; i
++) {
3162 write_sram(card
, i
* SAR_SRAM_TCT_SIZE
+ 0, 0);
3163 write_sram(card
, i
* SAR_SRAM_TCT_SIZE
+ 1, 0);
3164 write_sram(card
, i
* SAR_SRAM_TCT_SIZE
+ 2, 0);
3165 write_sram(card
, i
* SAR_SRAM_TCT_SIZE
+ 3, 0);
3166 write_sram(card
, i
* SAR_SRAM_TCT_SIZE
+ 4, 0);
3167 write_sram(card
, i
* SAR_SRAM_TCT_SIZE
+ 5, 0);
3168 write_sram(card
, i
* SAR_SRAM_TCT_SIZE
+ 6, 0);
3169 write_sram(card
, i
* SAR_SRAM_TCT_SIZE
+ 7, 0);
3172 /* Initialize RCT */
3173 for (i
= 0; i
< card
->rct_size
; i
++) {
3174 write_sram(card
, card
->rct_base
+ i
* SAR_SRAM_RCT_SIZE
,
3175 (u32
) SAR_RCTE_RAWCELLINTEN
);
3176 write_sram(card
, card
->rct_base
+ i
* SAR_SRAM_RCT_SIZE
+ 1,
3178 write_sram(card
, card
->rct_base
+ i
* SAR_SRAM_RCT_SIZE
+ 2,
3180 write_sram(card
, card
->rct_base
+ i
* SAR_SRAM_RCT_SIZE
+ 3,
3184 writel((SAR_FBQ0_LOW
<< 28) | (SAR_FB_SIZE_0
/ 48), SAR_REG_FBQS0
);
3185 writel((SAR_FBQ1_LOW
<< 28) | (SAR_FB_SIZE_1
/ 48), SAR_REG_FBQS1
);
3186 writel((SAR_FBQ2_LOW
<< 28) | (SAR_FB_SIZE_2
/ 48), SAR_REG_FBQS2
);
3187 writel((SAR_FBQ3_LOW
<< 28) | (SAR_FB_SIZE_3
/ 48), SAR_REG_FBQS3
);
3189 /* Initialize rate table */
3190 for (i
= 0; i
< 256; i
++) {
3191 write_sram(card
, card
->rt_base
+ i
, log_to_rate
[i
]);
3194 for (i
= 0; i
< 128; i
++) {
3197 tmp
= rate_to_log
[(i
<< 2) + 0] << 0;
3198 tmp
|= rate_to_log
[(i
<< 2) + 1] << 8;
3199 tmp
|= rate_to_log
[(i
<< 2) + 2] << 16;
3200 tmp
|= rate_to_log
[(i
<< 2) + 3] << 24;
3201 write_sram(card
, card
->rt_base
+ 256 + i
, tmp
);
3204 #if 0 /* Fill RDF and AIR tables. */
3205 for (i
= 0; i
< 128; i
++) {
3208 tmp
= RDF
[0][(i
<< 1) + 0] << 16;
3209 tmp
|= RDF
[0][(i
<< 1) + 1] << 0;
3210 write_sram(card
, card
->rt_base
+ 512 + i
, tmp
);
3213 for (i
= 0; i
< 128; i
++) {
3216 tmp
= AIR
[0][(i
<< 1) + 0] << 16;
3217 tmp
|= AIR
[0][(i
<< 1) + 1] << 0;
3218 write_sram(card
, card
->rt_base
+ 640 + i
, tmp
);
3222 IPRINTK("%s: initialize rate table ...\n", card
->name
);
3223 writel(card
->rt_base
<< 2, SAR_REG_RTBL
);
3225 /* Initialize TSTs */
3226 IPRINTK("%s: initialize TST ...\n", card
->name
);
3227 card
->tst_free
= card
->tst_size
- 2; /* last two are jumps */
3229 for (i
= card
->tst
[0]; i
< card
->tst
[0] + card
->tst_size
- 2; i
++)
3230 write_sram(card
, i
, TSTE_OPC_VAR
);
3231 write_sram(card
, i
++, TSTE_OPC_JMP
| (card
->tst
[0] << 2));
3232 idt77252_sram_write_errors
= 1;
3233 write_sram(card
, i
++, TSTE_OPC_JMP
| (card
->tst
[1] << 2));
3234 idt77252_sram_write_errors
= 0;
3235 for (i
= card
->tst
[1]; i
< card
->tst
[1] + card
->tst_size
- 2; i
++)
3236 write_sram(card
, i
, TSTE_OPC_VAR
);
3237 write_sram(card
, i
++, TSTE_OPC_JMP
| (card
->tst
[1] << 2));
3238 idt77252_sram_write_errors
= 1;
3239 write_sram(card
, i
++, TSTE_OPC_JMP
| (card
->tst
[0] << 2));
3240 idt77252_sram_write_errors
= 0;
3242 card
->tst_index
= 0;
3243 writel(card
->tst
[0] << 2, SAR_REG_TSTB
);
3245 /* Initialize ABRSTD and Receive FIFO */
3246 IPRINTK("%s: initialize ABRSTD ...\n", card
->name
);
3247 writel(card
->abrst_size
| (card
->abrst_base
<< 2),
3250 IPRINTK("%s: initialize receive fifo ...\n", card
->name
);
3251 writel(card
->fifo_size
| (card
->fifo_base
<< 2),
3254 IPRINTK("%s: SRAM initialization complete.\n", card
->name
);
3257 static int init_card(struct atm_dev
*dev
)
3259 struct idt77252_dev
*card
= dev
->dev_data
;
3260 struct pci_dev
*pcidev
= card
->pcidev
;
3261 unsigned long tmpl
, modl
;
3262 unsigned int linkrate
, rsvdcr
;
3263 unsigned int tst_entries
;
3264 struct net_device
*tmp
;
3272 if (test_bit(IDT77252_BIT_INIT
, &card
->flags
)) {
3273 printk("Error: SAR already initialized.\n");
3277 /*****************************************************************/
3278 /* P C I C O N F I G U R A T I O N */
3279 /*****************************************************************/
3281 /* Set PCI Retry-Timeout and TRDY timeout */
3282 IPRINTK("%s: Checking PCI retries.\n", card
->name
);
3283 if (pci_read_config_byte(pcidev
, 0x40, &pci_byte
) != 0) {
3284 printk("%s: can't read PCI retry timeout.\n", card
->name
);
3288 if (pci_byte
!= 0) {
3289 IPRINTK("%s: PCI retry timeout: %d, set to 0.\n",
3290 card
->name
, pci_byte
);
3291 if (pci_write_config_byte(pcidev
, 0x40, 0) != 0) {
3292 printk("%s: can't set PCI retry timeout.\n",
3298 IPRINTK("%s: Checking PCI TRDY.\n", card
->name
);
3299 if (pci_read_config_byte(pcidev
, 0x41, &pci_byte
) != 0) {
3300 printk("%s: can't read PCI TRDY timeout.\n", card
->name
);
3304 if (pci_byte
!= 0) {
3305 IPRINTK("%s: PCI TRDY timeout: %d, set to 0.\n",
3306 card
->name
, pci_byte
);
3307 if (pci_write_config_byte(pcidev
, 0x41, 0) != 0) {
3308 printk("%s: can't set PCI TRDY timeout.\n", card
->name
);
3313 /* Reset Timer register */
3314 if (readl(SAR_REG_STAT
) & SAR_STAT_TMROF
) {
3315 printk("%s: resetting timer overflow.\n", card
->name
);
3316 writel(SAR_STAT_TMROF
, SAR_REG_STAT
);
3318 IPRINTK("%s: Request IRQ ... ", card
->name
);
3319 if (request_irq(pcidev
->irq
, idt77252_interrupt
, IRQF_SHARED
,
3320 card
->name
, card
) != 0) {
3321 printk("%s: can't allocate IRQ.\n", card
->name
);
3325 IPRINTK("got %d.\n", pcidev
->irq
);
3327 /*****************************************************************/
3328 /* C H E C K A N D I N I T S R A M */
3329 /*****************************************************************/
3331 IPRINTK("%s: Initializing SRAM\n", card
->name
);
3333 /* preset size of connecton table, so that init_sram() knows about it */
3334 conf
= SAR_CFG_TX_FIFO_SIZE_9
| /* Use maximum fifo size */
3335 SAR_CFG_RXSTQ_SIZE_8k
| /* Receive Status Queue is 8k */
3336 SAR_CFG_IDLE_CLP
| /* Set CLP on idle cells */
3337 #ifndef ATM_IDT77252_SEND_IDLE
3338 SAR_CFG_NO_IDLE
| /* Do not send idle cells */
3342 if (card
->sramsize
== (512 * 1024))
3343 conf
|= SAR_CFG_CNTBL_1k
;
3345 conf
|= SAR_CFG_CNTBL_512
;
3349 conf
|= SAR_CFG_VPVCS_0
;
3353 conf
|= SAR_CFG_VPVCS_1
;
3356 conf
|= SAR_CFG_VPVCS_2
;
3359 conf
|= SAR_CFG_VPVCS_8
;
3363 writel(readl(SAR_REG_CFG
) | conf
, SAR_REG_CFG
);
3367 /********************************************************************/
3368 /* A L L O C R A M A N D S E T V A R I O U S T H I N G S */
3369 /********************************************************************/
3370 /* Initialize TSQ */
3371 if (0 != init_tsq(card
)) {
3375 /* Initialize RSQ */
3376 if (0 != init_rsq(card
)) {
3381 card
->vpibits
= vpibits
;
3382 if (card
->sramsize
== (512 * 1024)) {
3383 card
->vcibits
= 10 - card
->vpibits
;
3385 card
->vcibits
= 9 - card
->vpibits
;
3389 for (k
= 0, i
= 1; k
< card
->vcibits
; k
++) {
3394 IPRINTK("%s: Setting VPI/VCI mask to zero.\n", card
->name
);
3395 writel(0, SAR_REG_VPM
);
3397 /* Little Endian Order */
3398 writel(0, SAR_REG_GP
);
3400 /* Initialize RAW Cell Handle Register */
3401 card
->raw_cell_hnd
= dma_alloc_coherent(&card
->pcidev
->dev
,
3403 &card
->raw_cell_paddr
,
3405 if (!card
->raw_cell_hnd
) {
3406 printk("%s: memory allocation failure.\n", card
->name
);
3410 writel(card
->raw_cell_paddr
, SAR_REG_RAWHND
);
3411 IPRINTK("%s: raw cell handle is at 0x%p.\n", card
->name
,
3412 card
->raw_cell_hnd
);
3414 size
= sizeof(struct vc_map
*) * card
->tct_size
;
3415 IPRINTK("%s: allocate %d byte for VC map.\n", card
->name
, size
);
3416 card
->vcs
= vzalloc(size
);
3418 printk("%s: memory allocation failure.\n", card
->name
);
3423 size
= sizeof(struct vc_map
*) * card
->scd_size
;
3424 IPRINTK("%s: allocate %d byte for SCD to VC mapping.\n",
3426 card
->scd2vc
= vzalloc(size
);
3427 if (!card
->scd2vc
) {
3428 printk("%s: memory allocation failure.\n", card
->name
);
3433 size
= sizeof(struct tst_info
) * (card
->tst_size
- 2);
3434 IPRINTK("%s: allocate %d byte for TST to VC mapping.\n",
3436 card
->soft_tst
= vmalloc(size
);
3437 if (!card
->soft_tst
) {
3438 printk("%s: memory allocation failure.\n", card
->name
);
3442 for (i
= 0; i
< card
->tst_size
- 2; i
++) {
3443 card
->soft_tst
[i
].tste
= TSTE_OPC_VAR
;
3444 card
->soft_tst
[i
].vc
= NULL
;
3447 if (dev
->phy
== NULL
) {
3448 printk("%s: No LT device defined.\n", card
->name
);
3452 if (dev
->phy
->ioctl
== NULL
) {
3453 printk("%s: LT had no IOCTL function defined.\n", card
->name
);
3458 #ifdef CONFIG_ATM_IDT77252_USE_SUNI
3460 * this is a jhs hack to get around special functionality in the
3461 * phy driver for the atecom hardware; the functionality doesn't
3462 * exist in the linux atm suni driver
3464 * it isn't the right way to do things, but as the guy from NIST
3465 * said, talking about their measurement of the fine structure
3466 * constant, "it's good enough for government work."
3468 linkrate
= 149760000;
3471 card
->link_pcr
= (linkrate
/ 8 / 53);
3472 printk("%s: Linkrate on ATM line : %u bit/s, %u cell/s.\n",
3473 card
->name
, linkrate
, card
->link_pcr
);
3475 #ifdef ATM_IDT77252_SEND_IDLE
3476 card
->utopia_pcr
= card
->link_pcr
;
3478 card
->utopia_pcr
= (160000000 / 8 / 54);
3482 if (card
->utopia_pcr
> card
->link_pcr
)
3483 rsvdcr
= card
->utopia_pcr
- card
->link_pcr
;
3485 tmpl
= (unsigned long) rsvdcr
* ((unsigned long) card
->tst_size
- 2);
3486 modl
= tmpl
% (unsigned long)card
->utopia_pcr
;
3487 tst_entries
= (int) (tmpl
/ (unsigned long)card
->utopia_pcr
);
3490 card
->tst_free
-= tst_entries
;
3491 fill_tst(card
, NULL
, tst_entries
, TSTE_OPC_NULL
);
3494 idt77252_eeprom_init(card
);
3495 printk("%s: EEPROM: %02x:", card
->name
,
3496 idt77252_eeprom_read_status(card
));
3498 for (i
= 0; i
< 0x80; i
++) {
3500 idt77252_eeprom_read_byte(card
, i
)
3504 #endif /* HAVE_EEPROM */
3509 sprintf(tname
, "eth%d", card
->index
);
3510 tmp
= dev_get_by_name(&init_net
, tname
); /* jhs: was "tmp = dev_get(tname);" */
3512 memcpy(card
->atmdev
->esi
, tmp
->dev_addr
, 6);
3514 printk("%s: ESI %pM\n", card
->name
, card
->atmdev
->esi
);
3520 /* Set Maximum Deficit Count for now. */
3521 writel(0xffff, SAR_REG_MDFCT
);
3523 set_bit(IDT77252_BIT_INIT
, &card
->flags
);
3525 XPRINTK("%s: IDT77252 ABR SAR initialization complete.\n", card
->name
);
3530 /*****************************************************************************/
3532 /* Probing of IDT77252 ABR SAR */
3534 /*****************************************************************************/
3537 static int idt77252_preset(struct idt77252_dev
*card
)
3541 /*****************************************************************/
3542 /* P C I C O N F I G U R A T I O N */
3543 /*****************************************************************/
3545 XPRINTK("%s: Enable PCI master and memory access for SAR.\n",
3547 if (pci_read_config_word(card
->pcidev
, PCI_COMMAND
, &pci_command
)) {
3548 printk("%s: can't read PCI_COMMAND.\n", card
->name
);
3552 if (!(pci_command
& PCI_COMMAND_IO
)) {
3553 printk("%s: PCI_COMMAND: %04x (?)\n",
3554 card
->name
, pci_command
);
3558 pci_command
|= (PCI_COMMAND_MEMORY
| PCI_COMMAND_MASTER
);
3559 if (pci_write_config_word(card
->pcidev
, PCI_COMMAND
, pci_command
)) {
3560 printk("%s: can't write PCI_COMMAND.\n", card
->name
);
3564 /*****************************************************************/
3565 /* G E N E R I C R E S E T */
3566 /*****************************************************************/
3568 /* Software reset */
3569 writel(SAR_CFG_SWRST
, SAR_REG_CFG
);
3571 writel(0, SAR_REG_CFG
);
3573 IPRINTK("%s: Software resetted.\n", card
->name
);
3578 static unsigned long probe_sram(struct idt77252_dev
*card
)
3582 writel(0, SAR_REG_DR0
);
3583 writel(SAR_CMD_WRITE_SRAM
| (0 << 2), SAR_REG_CMD
);
3585 for (addr
= 0x4000; addr
< 0x80000; addr
+= 0x4000) {
3586 writel(ATM_POISON
, SAR_REG_DR0
);
3587 writel(SAR_CMD_WRITE_SRAM
| (addr
<< 2), SAR_REG_CMD
);
3589 writel(SAR_CMD_READ_SRAM
| (0 << 2), SAR_REG_CMD
);
3590 data
= readl(SAR_REG_DR0
);
3596 return addr
* sizeof(u32
);
3599 static int idt77252_init_one(struct pci_dev
*pcidev
,
3600 const struct pci_device_id
*id
)
3602 static struct idt77252_dev
**last
= &idt77252_chain
;
3603 static int index
= 0;
3605 unsigned long membase
, srambase
;
3606 struct idt77252_dev
*card
;
3607 struct atm_dev
*dev
;
3611 if ((err
= pci_enable_device(pcidev
))) {
3612 printk("idt77252: can't enable PCI device at %s\n", pci_name(pcidev
));
3616 if ((err
= dma_set_mask_and_coherent(&pcidev
->dev
, DMA_BIT_MASK(32)))) {
3617 printk("idt77252: can't enable DMA for PCI device at %s\n", pci_name(pcidev
));
3618 goto err_out_disable_pdev
;
3621 card
= kzalloc(sizeof(struct idt77252_dev
), GFP_KERNEL
);
3623 printk("idt77252-%d: can't allocate private data\n", index
);
3625 goto err_out_disable_pdev
;
3627 card
->revision
= pcidev
->revision
;
3628 card
->index
= index
;
3629 card
->pcidev
= pcidev
;
3630 sprintf(card
->name
, "idt77252-%d", card
->index
);
3632 INIT_WORK(&card
->tqueue
, idt77252_softint
);
3634 membase
= pci_resource_start(pcidev
, 1);
3635 srambase
= pci_resource_start(pcidev
, 2);
3637 mutex_init(&card
->mutex
);
3638 spin_lock_init(&card
->cmd_lock
);
3639 spin_lock_init(&card
->tst_lock
);
3641 timer_setup(&card
->tst_timer
, tst_timer
, 0);
3643 /* Do the I/O remapping... */
3644 card
->membase
= ioremap(membase
, 1024);
3645 if (!card
->membase
) {
3646 printk("%s: can't ioremap() membase\n", card
->name
);
3648 goto err_out_free_card
;
3651 if (idt77252_preset(card
)) {
3652 printk("%s: preset failed\n", card
->name
);
3654 goto err_out_iounmap
;
3657 dev
= atm_dev_register("idt77252", &pcidev
->dev
, &idt77252_ops
, -1,
3660 printk("%s: can't register atm device\n", card
->name
);
3662 goto err_out_iounmap
;
3664 dev
->dev_data
= card
;
3667 #ifdef CONFIG_ATM_IDT77252_USE_SUNI
3670 printk("%s: can't init SUNI\n", card
->name
);
3672 goto err_out_deinit_card
;
3674 #endif /* CONFIG_ATM_IDT77252_USE_SUNI */
3676 card
->sramsize
= probe_sram(card
);
3678 for (i
= 0; i
< 4; i
++) {
3679 card
->fbq
[i
] = ioremap(srambase
| 0x200000 | (i
<< 18), 4);
3680 if (!card
->fbq
[i
]) {
3681 printk("%s: can't ioremap() FBQ%d\n", card
->name
, i
);
3683 goto err_out_deinit_card
;
3687 printk("%s: ABR SAR (Rev %c): MEM %08lx SRAM %08lx [%u KB]\n",
3688 card
->name
, ((card
->revision
> 1) && (card
->revision
< 25)) ?
3689 'A' + card
->revision
- 1 : '?', membase
, srambase
,
3690 card
->sramsize
/ 1024);
3692 if (init_card(dev
)) {
3693 printk("%s: init_card failed\n", card
->name
);
3695 goto err_out_deinit_card
;
3698 dev
->ci_range
.vpi_bits
= card
->vpibits
;
3699 dev
->ci_range
.vci_bits
= card
->vcibits
;
3700 dev
->link_rate
= card
->link_pcr
;
3702 if (dev
->phy
->start
)
3703 dev
->phy
->start(dev
);
3705 if (idt77252_dev_open(card
)) {
3706 printk("%s: dev_open failed\n", card
->name
);
3719 dev
->phy
->stop(dev
);
3721 err_out_deinit_card
:
3725 iounmap(card
->membase
);
3730 err_out_disable_pdev
:
3731 pci_disable_device(pcidev
);
3735 static const struct pci_device_id idt77252_pci_tbl
[] =
3737 { PCI_VDEVICE(IDT
, PCI_DEVICE_ID_IDT_IDT77252
), 0 },
3741 MODULE_DEVICE_TABLE(pci
, idt77252_pci_tbl
);
3743 static struct pci_driver idt77252_driver
= {
3745 .id_table
= idt77252_pci_tbl
,
3746 .probe
= idt77252_init_one
,
3749 static int __init
idt77252_init(void)
3751 struct sk_buff
*skb
;
3753 printk("%s: at %p\n", __func__
, idt77252_init
);
3754 BUILD_BUG_ON(sizeof(skb
->cb
) < sizeof(struct idt77252_skb_prv
) + sizeof(struct atm_skb_data
));
3755 return pci_register_driver(&idt77252_driver
);
3758 static void __exit
idt77252_exit(void)
3760 struct idt77252_dev
*card
;
3761 struct atm_dev
*dev
;
3763 pci_unregister_driver(&idt77252_driver
);
3765 while (idt77252_chain
) {
3766 card
= idt77252_chain
;
3768 idt77252_chain
= card
->next
;
3769 timer_shutdown_sync(&card
->tst_timer
);
3772 dev
->phy
->stop(dev
);
3774 pci_disable_device(card
->pcidev
);
3778 DIPRINTK("idt77252: finished cleanup-module().\n");
3781 module_init(idt77252_init
);
3782 module_exit(idt77252_exit
);
3784 MODULE_LICENSE("GPL");
3786 module_param(vpibits
, uint
, 0);
3787 MODULE_PARM_DESC(vpibits
, "number of VPI bits supported (0, 1, or 2)");
3788 #ifdef CONFIG_ATM_IDT77252_DEBUG
3789 module_param(debug
, ulong
, 0644);
3790 MODULE_PARM_DESC(debug
, "debug bitmap, see drivers/atm/idt77252.h");
3793 MODULE_AUTHOR("Eddie C. Dost <ecd@atecom.com>");
3794 MODULE_DESCRIPTION("IDT77252 ABR SAR Driver");