1 /******************************************************************************
5 * Device driver supporting CBR for IDT 77201/77211 "NICStAR" based cards.
7 * IMPORTANT: The included file nicstarmac.c was NOT WRITTEN BY ME.
8 * It was taken from the frle-0.22 device driver.
9 * As the file doesn't have a copyright notice, in the file
10 * nicstarmac.copyright I put the copyright notice from the
11 * frle-0.22 device driver.
12 * Some code is based on the nicstar driver by M. Welsh.
14 * Author: Rui Prior (rprior@inescn.pt)
15 * PowerPC support by Jay Talbott (jay_talbott@mcg.mot.com) April 1999
21 ******************************************************************************/
24 /**** IMPORTANT INFORMATION ***************************************************
26 * There are currently three types of spinlocks:
28 * 1 - Per card interrupt spinlock (to protect structures and such)
29 * 2 - Per SCQ scq spinlock
30 * 3 - Per card resource spinlock (to access registers, etc.)
32 * These must NEVER be grabbed in reverse order.
34 ******************************************************************************/
36 /* Header files ***************************************************************/
38 #include <linux/module.h>
39 #include <linux/config.h>
40 #include <linux/kernel.h>
41 #include <linux/skbuff.h>
42 #include <linux/atmdev.h>
43 #include <linux/atm.h>
44 #include <linux/pci.h>
45 #include <linux/types.h>
46 #include <linux/string.h>
47 #include <linux/delay.h>
48 #include <linux/init.h>
49 #include <linux/sched.h>
50 #include <linux/timer.h>
51 #include <linux/interrupt.h>
52 #include <linux/bitops.h>
54 #include <asm/uaccess.h>
55 #include <asm/atomic.h>
57 #ifdef CONFIG_ATM_NICSTAR_USE_SUNI
59 #endif /* CONFIG_ATM_NICSTAR_USE_SUNI */
60 #ifdef CONFIG_ATM_NICSTAR_USE_IDT77105
62 #endif /* CONFIG_ATM_NICSTAR_USE_IDT77105 */
64 #if BITS_PER_LONG != 32
65 # error FIXME: this driver requires a 32-bit platform
68 /* Additional code ************************************************************/
70 #include "nicstarmac.c"
73 /* Configurable parameters ****************************************************/
81 #undef NS_USE_DESTRUCTORS /* For now keep this undefined unless you know
82 you're going to use only raw ATM */
85 /* Do not touch these *********************************************************/
88 #define TXPRINTK(args...) printk(args)
90 #define TXPRINTK(args...)
94 #define RXPRINTK(args...) printk(args)
96 #define RXPRINTK(args...)
100 #define PRINTK(args...) printk(args)
102 #define PRINTK(args...)
103 #endif /* GENERAL_DEBUG */
106 #define XPRINTK(args...) printk(args)
108 #define XPRINTK(args...)
109 #endif /* EXTRA_DEBUG */
112 /* Macros *********************************************************************/
114 #define CMD_BUSY(card) (readl((card)->membase + STAT) & NS_STAT_CMDBZ)
116 #define NS_DELAY mdelay(1)
118 #define ALIGN_BUS_ADDR(addr, alignment) \
119 ((((u32) (addr)) + (((u32) (alignment)) - 1)) & ~(((u32) (alignment)) - 1))
120 #define ALIGN_ADDRESS(addr, alignment) \
121 bus_to_virt(ALIGN_BUS_ADDR(virt_to_bus(addr), alignment))
126 #define ATM_SKB(s) (&(s)->atm)
129 /* Spinlock debugging stuff */
130 #ifdef NS_DEBUG_SPINLOCKS /* See nicstar.h */
131 #define ns_grab_int_lock(card,flags) \
133 unsigned long nsdsf, nsdsf2; \
134 local_irq_save(flags); \
135 save_flags(nsdsf); cli();\
136 if (nsdsf & (1<<9)) printk ("nicstar.c: ints %sabled -> enabled.\n", \
137 (flags)&(1<<9)?"en":"dis"); \
138 if (spin_is_locked(&(card)->int_lock) && \
139 (card)->cpu_int == smp_processor_id()) { \
140 printk("nicstar.c: line %d (cpu %d) int_lock already locked at line %d (cpu %d)\n", \
141 __LINE__, smp_processor_id(), (card)->has_int_lock, \
143 printk("nicstar.c: ints were %sabled.\n", ((flags)&(1<<9)?"en":"dis")); \
145 if (spin_is_locked(&(card)->res_lock) && \
146 (card)->cpu_res == smp_processor_id()) { \
147 printk("nicstar.c: line %d (cpu %d) res_lock locked at line %d (cpu %d)(trying int)\n", \
148 __LINE__, smp_processor_id(), (card)->has_res_lock, \
150 printk("nicstar.c: ints were %sabled.\n", ((flags)&(1<<9)?"en":"dis")); \
152 spin_lock_irq(&(card)->int_lock); \
153 (card)->has_int_lock = __LINE__; \
154 (card)->cpu_int = smp_processor_id(); \
155 restore_flags(nsdsf); } while (0)
156 #define ns_grab_res_lock(card,flags) \
158 unsigned long nsdsf, nsdsf2; \
159 local_irq_save(flags); \
160 save_flags(nsdsf); cli();\
161 if (nsdsf & (1<<9)) printk ("nicstar.c: ints %sabled -> enabled.\n", \
162 (flags)&(1<<9)?"en":"dis"); \
163 if (spin_is_locked(&(card)->res_lock) && \
164 (card)->cpu_res == smp_processor_id()) { \
165 printk("nicstar.c: line %d (cpu %d) res_lock already locked at line %d (cpu %d)\n", \
166 __LINE__, smp_processor_id(), (card)->has_res_lock, \
168 printk("nicstar.c: ints were %sabled.\n", ((flags)&(1<<9)?"en":"dis")); \
170 spin_lock_irq(&(card)->res_lock); \
171 (card)->has_res_lock = __LINE__; \
172 (card)->cpu_res = smp_processor_id(); \
173 restore_flags(nsdsf); } while (0)
174 #define ns_grab_scq_lock(card,scq,flags) \
176 unsigned long nsdsf, nsdsf2; \
177 local_irq_save(flags); \
178 save_flags(nsdsf); cli();\
179 if (nsdsf & (1<<9)) printk ("nicstar.c: ints %sabled -> enabled.\n", \
180 (flags)&(1<<9)?"en":"dis"); \
181 if (spin_is_locked(&(scq)->lock) && \
182 (scq)->cpu_lock == smp_processor_id()) { \
183 printk("nicstar.c: line %d (cpu %d) this scq_lock already locked at line %d (cpu %d)\n", \
184 __LINE__, smp_processor_id(), (scq)->has_lock, \
186 printk("nicstar.c: ints were %sabled.\n", ((flags)&(1<<9)?"en":"dis")); \
188 if (spin_is_locked(&(card)->res_lock) && \
189 (card)->cpu_res == smp_processor_id()) { \
190 printk("nicstar.c: line %d (cpu %d) res_lock locked at line %d (cpu %d)(trying scq)\n", \
191 __LINE__, smp_processor_id(), (card)->has_res_lock, \
193 printk("nicstar.c: ints were %sabled.\n", ((flags)&(1<<9)?"en":"dis")); \
195 spin_lock_irq(&(scq)->lock); \
196 (scq)->has_lock = __LINE__; \
197 (scq)->cpu_lock = smp_processor_id(); \
198 restore_flags(nsdsf); } while (0)
199 #else /* !NS_DEBUG_SPINLOCKS */
200 #define ns_grab_int_lock(card,flags) \
201 spin_lock_irqsave(&(card)->int_lock,(flags))
202 #define ns_grab_res_lock(card,flags) \
203 spin_lock_irqsave(&(card)->res_lock,(flags))
204 #define ns_grab_scq_lock(card,scq,flags) \
205 spin_lock_irqsave(&(scq)->lock,flags)
206 #endif /* NS_DEBUG_SPINLOCKS */
209 /* Function declarations ******************************************************/
211 static u32
ns_read_sram(ns_dev
*card
, u32 sram_address
);
212 static void ns_write_sram(ns_dev
*card
, u32 sram_address
, u32
*value
, int count
);
213 static int __devinit
ns_init_card(int i
, struct pci_dev
*pcidev
);
214 static void __devinit
ns_init_card_error(ns_dev
*card
, int error
);
215 static scq_info
*get_scq(int size
, u32 scd
);
216 static void free_scq(scq_info
*scq
, struct atm_vcc
*vcc
);
217 static void push_rxbufs(ns_dev
*card
, u32 type
, u32 handle1
, u32 addr1
,
218 u32 handle2
, u32 addr2
);
219 static irqreturn_t
ns_irq_handler(int irq
, void *dev_id
, struct pt_regs
*regs
);
220 static int ns_open(struct atm_vcc
*vcc
);
221 static void ns_close(struct atm_vcc
*vcc
);
222 static void fill_tst(ns_dev
*card
, int n
, vc_map
*vc
);
223 static int ns_send(struct atm_vcc
*vcc
, struct sk_buff
*skb
);
224 static int push_scqe(ns_dev
*card
, vc_map
*vc
, scq_info
*scq
, ns_scqe
*tbd
,
225 struct sk_buff
*skb
);
226 static void process_tsq(ns_dev
*card
);
227 static void drain_scq(ns_dev
*card
, scq_info
*scq
, int pos
);
228 static void process_rsq(ns_dev
*card
);
229 static void dequeue_rx(ns_dev
*card
, ns_rsqe
*rsqe
);
230 #ifdef NS_USE_DESTRUCTORS
231 static void ns_sb_destructor(struct sk_buff
*sb
);
232 static void ns_lb_destructor(struct sk_buff
*lb
);
233 static void ns_hb_destructor(struct sk_buff
*hb
);
234 #endif /* NS_USE_DESTRUCTORS */
235 static void recycle_rx_buf(ns_dev
*card
, struct sk_buff
*skb
);
236 static void recycle_iovec_rx_bufs(ns_dev
*card
, struct iovec
*iov
, int count
);
237 static void recycle_iov_buf(ns_dev
*card
, struct sk_buff
*iovb
);
238 static void dequeue_sm_buf(ns_dev
*card
, struct sk_buff
*sb
);
239 static void dequeue_lg_buf(ns_dev
*card
, struct sk_buff
*lb
);
240 static int ns_proc_read(struct atm_dev
*dev
, loff_t
*pos
, char *page
);
241 static int ns_ioctl(struct atm_dev
*dev
, unsigned int cmd
, void __user
*arg
);
242 static void which_list(ns_dev
*card
, struct sk_buff
*skb
);
243 static void ns_poll(unsigned long arg
);
244 static int ns_parse_mac(char *mac
, unsigned char *esi
);
245 static short ns_h2i(char c
);
246 static void ns_phy_put(struct atm_dev
*dev
, unsigned char value
,
248 static unsigned char ns_phy_get(struct atm_dev
*dev
, unsigned long addr
);
252 /* Global variables ***********************************************************/
254 static struct ns_dev
*cards
[NS_MAX_CARDS
];
255 static unsigned num_cards
;
256 static struct atmdev_ops atm_ops
=
262 .phy_put
= ns_phy_put
,
263 .phy_get
= ns_phy_get
,
264 .proc_read
= ns_proc_read
,
265 .owner
= THIS_MODULE
,
267 static struct timer_list ns_timer
;
268 static char *mac
[NS_MAX_CARDS
];
269 module_param_array(mac
, charp
, NULL
, 0);
270 MODULE_LICENSE("GPL");
273 /* Functions*******************************************************************/
275 static int __devinit
nicstar_init_one(struct pci_dev
*pcidev
,
276 const struct pci_device_id
*ent
)
278 static int index
= -1;
284 error
= ns_init_card(index
, pcidev
);
286 cards
[index
--] = NULL
; /* don't increment index */
297 static void __devexit
nicstar_remove_one(struct pci_dev
*pcidev
)
300 ns_dev
*card
= pci_get_drvdata(pcidev
);
302 struct sk_buff
*iovb
;
308 if (cards
[i
] == NULL
)
311 if (card
->atmdev
->phy
&& card
->atmdev
->phy
->stop
)
312 card
->atmdev
->phy
->stop(card
->atmdev
);
314 /* Stop everything */
315 writel(0x00000000, card
->membase
+ CFG
);
317 /* De-register device */
318 atm_dev_deregister(card
->atmdev
);
320 /* Disable PCI device */
321 pci_disable_device(pcidev
);
323 /* Free up resources */
325 PRINTK("nicstar%d: freeing %d huge buffers.\n", i
, card
->hbpool
.count
);
326 while ((hb
= skb_dequeue(&card
->hbpool
.queue
)) != NULL
)
328 dev_kfree_skb_any(hb
);
331 PRINTK("nicstar%d: %d huge buffers freed.\n", i
, j
);
333 PRINTK("nicstar%d: freeing %d iovec buffers.\n", i
, card
->iovpool
.count
);
334 while ((iovb
= skb_dequeue(&card
->iovpool
.queue
)) != NULL
)
336 dev_kfree_skb_any(iovb
);
339 PRINTK("nicstar%d: %d iovec buffers freed.\n", i
, j
);
340 while ((lb
= skb_dequeue(&card
->lbpool
.queue
)) != NULL
)
341 dev_kfree_skb_any(lb
);
342 while ((sb
= skb_dequeue(&card
->sbpool
.queue
)) != NULL
)
343 dev_kfree_skb_any(sb
);
344 free_scq(card
->scq0
, NULL
);
345 for (j
= 0; j
< NS_FRSCD_NUM
; j
++)
347 if (card
->scd2vc
[j
] != NULL
)
348 free_scq(card
->scd2vc
[j
]->scq
, card
->scd2vc
[j
]->tx_vcc
);
350 kfree(card
->rsq
.org
);
351 kfree(card
->tsq
.org
);
352 free_irq(card
->pcidev
->irq
, card
);
353 iounmap(card
->membase
);
359 static struct pci_device_id nicstar_pci_tbl
[] __devinitdata
=
361 {PCI_VENDOR_ID_IDT
, PCI_DEVICE_ID_IDT_IDT77201
,
362 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
363 {0,} /* terminate list */
365 MODULE_DEVICE_TABLE(pci
, nicstar_pci_tbl
);
369 static struct pci_driver nicstar_driver
= {
371 .id_table
= nicstar_pci_tbl
,
372 .probe
= nicstar_init_one
,
373 .remove
= __devexit_p(nicstar_remove_one
),
378 static int __init
nicstar_init(void)
380 unsigned error
= 0; /* Initialized to remove compile warning */
382 XPRINTK("nicstar: nicstar_init() called.\n");
384 error
= pci_register_driver(&nicstar_driver
);
386 TXPRINTK("nicstar: TX debug enabled.\n");
387 RXPRINTK("nicstar: RX debug enabled.\n");
388 PRINTK("nicstar: General debug enabled.\n");
390 printk("nicstar: using PHY loopback.\n");
391 #endif /* PHY_LOOPBACK */
392 XPRINTK("nicstar: nicstar_init() returned.\n");
395 init_timer(&ns_timer
);
396 ns_timer
.expires
= jiffies
+ NS_POLL_PERIOD
;
398 ns_timer
.function
= ns_poll
;
399 add_timer(&ns_timer
);
407 static void __exit
nicstar_cleanup(void)
409 XPRINTK("nicstar: nicstar_cleanup() called.\n");
411 del_timer(&ns_timer
);
413 pci_unregister_driver(&nicstar_driver
);
415 XPRINTK("nicstar: nicstar_cleanup() returned.\n");
420 static u32
ns_read_sram(ns_dev
*card
, u32 sram_address
)
425 sram_address
&= 0x0007FFFC; /* address must be dword aligned */
426 sram_address
|= 0x50000000; /* SRAM read command */
427 ns_grab_res_lock(card
, flags
);
428 while (CMD_BUSY(card
));
429 writel(sram_address
, card
->membase
+ CMD
);
430 while (CMD_BUSY(card
));
431 data
= readl(card
->membase
+ DR0
);
432 spin_unlock_irqrestore(&card
->res_lock
, flags
);
438 static void ns_write_sram(ns_dev
*card
, u32 sram_address
, u32
*value
, int count
)
442 count
--; /* count range now is 0..3 instead of 1..4 */
444 c
<<= 2; /* to use increments of 4 */
445 ns_grab_res_lock(card
, flags
);
446 while (CMD_BUSY(card
));
447 for (i
= 0; i
<= c
; i
+= 4)
448 writel(*(value
++), card
->membase
+ i
);
449 /* Note: DR# registers are the first 4 dwords in nicstar's memspace,
450 so card->membase + DR0 == card->membase */
452 sram_address
&= 0x0007FFFC;
453 sram_address
|= (0x40000000 | count
);
454 writel(sram_address
, card
->membase
+ CMD
);
455 spin_unlock_irqrestore(&card
->res_lock
, flags
);
459 static int __devinit
ns_init_card(int i
, struct pci_dev
*pcidev
)
462 struct ns_dev
*card
= NULL
;
463 unsigned char pci_latency
;
469 unsigned long membase
;
473 if (pci_enable_device(pcidev
))
475 printk("nicstar%d: can't enable PCI device\n", i
);
477 ns_init_card_error(card
, error
);
481 if ((card
= kmalloc(sizeof(ns_dev
), GFP_KERNEL
)) == NULL
)
483 printk("nicstar%d: can't allocate memory for device structure.\n", i
);
485 ns_init_card_error(card
, error
);
489 spin_lock_init(&card
->int_lock
);
490 spin_lock_init(&card
->res_lock
);
492 pci_set_drvdata(pcidev
, card
);
496 card
->pcidev
= pcidev
;
497 membase
= pci_resource_start(pcidev
, 1);
498 card
->membase
= ioremap(membase
, NS_IOREMAP_SIZE
);
499 if (card
->membase
== 0)
501 printk("nicstar%d: can't ioremap() membase.\n",i
);
503 ns_init_card_error(card
, error
);
506 PRINTK("nicstar%d: membase at 0x%x.\n", i
, card
->membase
);
508 pci_set_master(pcidev
);
510 if (pci_read_config_byte(pcidev
, PCI_LATENCY_TIMER
, &pci_latency
) != 0)
512 printk("nicstar%d: can't read PCI latency timer.\n", i
);
514 ns_init_card_error(card
, error
);
517 #ifdef NS_PCI_LATENCY
518 if (pci_latency
< NS_PCI_LATENCY
)
520 PRINTK("nicstar%d: setting PCI latency timer to %d.\n", i
, NS_PCI_LATENCY
);
521 for (j
= 1; j
< 4; j
++)
523 if (pci_write_config_byte(pcidev
, PCI_LATENCY_TIMER
, NS_PCI_LATENCY
) != 0)
528 printk("nicstar%d: can't set PCI latency timer to %d.\n", i
, NS_PCI_LATENCY
);
530 ns_init_card_error(card
, error
);
534 #endif /* NS_PCI_LATENCY */
536 /* Clear timer overflow */
537 data
= readl(card
->membase
+ STAT
);
538 if (data
& NS_STAT_TMROF
)
539 writel(NS_STAT_TMROF
, card
->membase
+ STAT
);
542 writel(NS_CFG_SWRST
, card
->membase
+ CFG
);
544 writel(0x00000000, card
->membase
+ CFG
);
547 writel(0x00000008, card
->membase
+ GP
);
549 writel(0x00000001, card
->membase
+ GP
);
551 while (CMD_BUSY(card
));
552 writel(NS_CMD_WRITE_UTILITY
| 0x00000100, card
->membase
+ CMD
); /* Sync UTOPIA with SAR clock */
555 /* Detect PHY type */
556 while (CMD_BUSY(card
));
557 writel(NS_CMD_READ_UTILITY
| 0x00000200, card
->membase
+ CMD
);
558 while (CMD_BUSY(card
));
559 data
= readl(card
->membase
+ DR0
);
562 printk("nicstar%d: PHY seems to be 25 Mbps.\n", i
);
563 card
->max_pcr
= ATM_25_PCR
;
564 while(CMD_BUSY(card
));
565 writel(0x00000008, card
->membase
+ DR0
);
566 writel(NS_CMD_WRITE_UTILITY
| 0x00000200, card
->membase
+ CMD
);
567 /* Clear an eventual pending interrupt */
568 writel(NS_STAT_SFBQF
, card
->membase
+ STAT
);
570 while(CMD_BUSY(card
));
571 writel(0x00000022, card
->membase
+ DR0
);
572 writel(NS_CMD_WRITE_UTILITY
| 0x00000202, card
->membase
+ CMD
);
573 #endif /* PHY_LOOPBACK */
577 printk("nicstar%d: PHY seems to be 155 Mbps.\n", i
);
578 card
->max_pcr
= ATM_OC3_PCR
;
580 while(CMD_BUSY(card
));
581 writel(0x00000002, card
->membase
+ DR0
);
582 writel(NS_CMD_WRITE_UTILITY
| 0x00000205, card
->membase
+ CMD
);
583 #endif /* PHY_LOOPBACK */
586 printk("nicstar%d: unknown PHY type (0x%08X).\n", i
, data
);
588 ns_init_card_error(card
, error
);
591 writel(0x00000000, card
->membase
+ GP
);
593 /* Determine SRAM size */
595 ns_write_sram(card
, 0x1C003, &data
, 1);
597 ns_write_sram(card
, 0x14003, &data
, 1);
598 if (ns_read_sram(card
, 0x14003) == 0x89ABCDEF &&
599 ns_read_sram(card
, 0x1C003) == 0x76543210)
600 card
->sram_size
= 128;
602 card
->sram_size
= 32;
603 PRINTK("nicstar%d: %dK x 32bit SRAM size.\n", i
, card
->sram_size
);
605 card
->rct_size
= NS_MAX_RCTSIZE
;
607 #if (NS_MAX_RCTSIZE == 4096)
608 if (card
->sram_size
== 128)
609 printk("nicstar%d: limiting maximum VCI. See NS_MAX_RCTSIZE in nicstar.h\n", i
);
610 #elif (NS_MAX_RCTSIZE == 16384)
611 if (card
->sram_size
== 32)
613 printk("nicstar%d: wasting memory. See NS_MAX_RCTSIZE in nicstar.h\n", i
);
614 card
->rct_size
= 4096;
617 #error NS_MAX_RCTSIZE must be either 4096 or 16384 in nicstar.c
620 card
->vpibits
= NS_VPIBITS
;
621 if (card
->rct_size
== 4096)
622 card
->vcibits
= 12 - NS_VPIBITS
;
623 else /* card->rct_size == 16384 */
624 card
->vcibits
= 14 - NS_VPIBITS
;
626 /* Initialize the nicstar eeprom/eprom stuff, for the MAC addr */
628 nicstar_init_eprom(card
->membase
);
630 if (request_irq(pcidev
->irq
, &ns_irq_handler
, SA_INTERRUPT
| SA_SHIRQ
, "nicstar", card
) != 0)
632 printk("nicstar%d: can't allocate IRQ %d.\n", i
, pcidev
->irq
);
634 ns_init_card_error(card
, error
);
638 /* Set the VPI/VCI MSb mask to zero so we can receive OAM cells */
639 writel(0x00000000, card
->membase
+ VPM
);
642 card
->tsq
.org
= kmalloc(NS_TSQSIZE
+ NS_TSQ_ALIGNMENT
, GFP_KERNEL
);
643 if (card
->tsq
.org
== NULL
)
645 printk("nicstar%d: can't allocate TSQ.\n", i
);
647 ns_init_card_error(card
, error
);
650 card
->tsq
.base
= (ns_tsi
*) ALIGN_ADDRESS(card
->tsq
.org
, NS_TSQ_ALIGNMENT
);
651 card
->tsq
.next
= card
->tsq
.base
;
652 card
->tsq
.last
= card
->tsq
.base
+ (NS_TSQ_NUM_ENTRIES
- 1);
653 for (j
= 0; j
< NS_TSQ_NUM_ENTRIES
; j
++)
654 ns_tsi_init(card
->tsq
.base
+ j
);
655 writel(0x00000000, card
->membase
+ TSQH
);
656 writel((u32
) virt_to_bus(card
->tsq
.base
), card
->membase
+ TSQB
);
657 PRINTK("nicstar%d: TSQ base at 0x%x 0x%x 0x%x.\n", i
, (u32
) card
->tsq
.base
,
658 (u32
) virt_to_bus(card
->tsq
.base
), readl(card
->membase
+ TSQB
));
661 card
->rsq
.org
= kmalloc(NS_RSQSIZE
+ NS_RSQ_ALIGNMENT
, GFP_KERNEL
);
662 if (card
->rsq
.org
== NULL
)
664 printk("nicstar%d: can't allocate RSQ.\n", i
);
666 ns_init_card_error(card
, error
);
669 card
->rsq
.base
= (ns_rsqe
*) ALIGN_ADDRESS(card
->rsq
.org
, NS_RSQ_ALIGNMENT
);
670 card
->rsq
.next
= card
->rsq
.base
;
671 card
->rsq
.last
= card
->rsq
.base
+ (NS_RSQ_NUM_ENTRIES
- 1);
672 for (j
= 0; j
< NS_RSQ_NUM_ENTRIES
; j
++)
673 ns_rsqe_init(card
->rsq
.base
+ j
);
674 writel(0x00000000, card
->membase
+ RSQH
);
675 writel((u32
) virt_to_bus(card
->rsq
.base
), card
->membase
+ RSQB
);
676 PRINTK("nicstar%d: RSQ base at 0x%x.\n", i
, (u32
) card
->rsq
.base
);
678 /* Initialize SCQ0, the only VBR SCQ used */
679 card
->scq1
= (scq_info
*) NULL
;
680 card
->scq2
= (scq_info
*) NULL
;
681 card
->scq0
= get_scq(VBR_SCQSIZE
, NS_VRSCD0
);
682 if (card
->scq0
== (scq_info
*) NULL
)
684 printk("nicstar%d: can't get SCQ0.\n", i
);
686 ns_init_card_error(card
, error
);
689 u32d
[0] = (u32
) virt_to_bus(card
->scq0
->base
);
690 u32d
[1] = (u32
) 0x00000000;
691 u32d
[2] = (u32
) 0xffffffff;
692 u32d
[3] = (u32
) 0x00000000;
693 ns_write_sram(card
, NS_VRSCD0
, u32d
, 4);
694 ns_write_sram(card
, NS_VRSCD1
, u32d
, 4); /* These last two won't be used */
695 ns_write_sram(card
, NS_VRSCD2
, u32d
, 4); /* but are initialized, just in case... */
696 card
->scq0
->scd
= NS_VRSCD0
;
697 PRINTK("nicstar%d: VBR-SCQ0 base at 0x%x.\n", i
, (u32
) card
->scq0
->base
);
699 /* Initialize TSTs */
700 card
->tst_addr
= NS_TST0
;
701 card
->tst_free_entries
= NS_TST_NUM_ENTRIES
;
702 data
= NS_TST_OPCODE_VARIABLE
;
703 for (j
= 0; j
< NS_TST_NUM_ENTRIES
; j
++)
704 ns_write_sram(card
, NS_TST0
+ j
, &data
, 1);
705 data
= ns_tste_make(NS_TST_OPCODE_END
, NS_TST0
);
706 ns_write_sram(card
, NS_TST0
+ NS_TST_NUM_ENTRIES
, &data
, 1);
707 for (j
= 0; j
< NS_TST_NUM_ENTRIES
; j
++)
708 ns_write_sram(card
, NS_TST1
+ j
, &data
, 1);
709 data
= ns_tste_make(NS_TST_OPCODE_END
, NS_TST1
);
710 ns_write_sram(card
, NS_TST1
+ NS_TST_NUM_ENTRIES
, &data
, 1);
711 for (j
= 0; j
< NS_TST_NUM_ENTRIES
; j
++)
712 card
->tste2vc
[j
] = NULL
;
713 writel(NS_TST0
<< 2, card
->membase
+ TSTB
);
716 /* Initialize RCT. AAL type is set on opening the VC. */
718 u32d
[0] = NS_RCTE_RAWCELLINTEN
;
720 u32d
[0] = 0x00000000;
721 #endif /* RCQ_SUPPORT */
722 u32d
[1] = 0x00000000;
723 u32d
[2] = 0x00000000;
724 u32d
[3] = 0xFFFFFFFF;
725 for (j
= 0; j
< card
->rct_size
; j
++)
726 ns_write_sram(card
, j
* 4, u32d
, 4);
728 memset(card
->vcmap
, 0, NS_MAX_RCTSIZE
* sizeof(vc_map
));
730 for (j
= 0; j
< NS_FRSCD_NUM
; j
++)
731 card
->scd2vc
[j
] = NULL
;
733 /* Initialize buffer levels */
734 card
->sbnr
.min
= MIN_SB
;
735 card
->sbnr
.init
= NUM_SB
;
736 card
->sbnr
.max
= MAX_SB
;
737 card
->lbnr
.min
= MIN_LB
;
738 card
->lbnr
.init
= NUM_LB
;
739 card
->lbnr
.max
= MAX_LB
;
740 card
->iovnr
.min
= MIN_IOVB
;
741 card
->iovnr
.init
= NUM_IOVB
;
742 card
->iovnr
.max
= MAX_IOVB
;
743 card
->hbnr
.min
= MIN_HB
;
744 card
->hbnr
.init
= NUM_HB
;
745 card
->hbnr
.max
= MAX_HB
;
747 card
->sm_handle
= 0x00000000;
748 card
->sm_addr
= 0x00000000;
749 card
->lg_handle
= 0x00000000;
750 card
->lg_addr
= 0x00000000;
752 card
->efbie
= 1; /* To prevent push_rxbufs from enabling the interrupt */
754 /* Pre-allocate some huge buffers */
755 skb_queue_head_init(&card
->hbpool
.queue
);
756 card
->hbpool
.count
= 0;
757 for (j
= 0; j
< NUM_HB
; j
++)
760 hb
= __dev_alloc_skb(NS_HBUFSIZE
, GFP_KERNEL
);
763 printk("nicstar%d: can't allocate %dth of %d huge buffers.\n",
766 ns_init_card_error(card
, error
);
769 skb_queue_tail(&card
->hbpool
.queue
, hb
);
770 card
->hbpool
.count
++;
774 /* Allocate large buffers */
775 skb_queue_head_init(&card
->lbpool
.queue
);
776 card
->lbpool
.count
= 0; /* Not used */
777 for (j
= 0; j
< NUM_LB
; j
++)
780 lb
= __dev_alloc_skb(NS_LGSKBSIZE
, GFP_KERNEL
);
783 printk("nicstar%d: can't allocate %dth of %d large buffers.\n",
786 ns_init_card_error(card
, error
);
789 skb_queue_tail(&card
->lbpool
.queue
, lb
);
790 skb_reserve(lb
, NS_SMBUFSIZE
);
791 push_rxbufs(card
, BUF_LG
, (u32
) lb
, (u32
) virt_to_bus(lb
->data
), 0, 0);
792 /* Due to the implementation of push_rxbufs() this is 1, not 0 */
796 card
->rawch
= (u32
) virt_to_bus(lb
->data
);
799 /* Test for strange behaviour which leads to crashes */
800 if ((bcount
= ns_stat_lfbqc_get(readl(card
->membase
+ STAT
))) < card
->lbnr
.min
)
802 printk("nicstar%d: Strange... Just allocated %d large buffers and lfbqc = %d.\n",
805 ns_init_card_error(card
, error
);
810 /* Allocate small buffers */
811 skb_queue_head_init(&card
->sbpool
.queue
);
812 card
->sbpool
.count
= 0; /* Not used */
813 for (j
= 0; j
< NUM_SB
; j
++)
816 sb
= __dev_alloc_skb(NS_SMSKBSIZE
, GFP_KERNEL
);
819 printk("nicstar%d: can't allocate %dth of %d small buffers.\n",
822 ns_init_card_error(card
, error
);
825 skb_queue_tail(&card
->sbpool
.queue
, sb
);
826 skb_reserve(sb
, NS_AAL0_HEADER
);
827 push_rxbufs(card
, BUF_SM
, (u32
) sb
, (u32
) virt_to_bus(sb
->data
), 0, 0);
829 /* Test for strange behaviour which leads to crashes */
830 if ((bcount
= ns_stat_sfbqc_get(readl(card
->membase
+ STAT
))) < card
->sbnr
.min
)
832 printk("nicstar%d: Strange... Just allocated %d small buffers and sfbqc = %d.\n",
835 ns_init_card_error(card
, error
);
840 /* Allocate iovec buffers */
841 skb_queue_head_init(&card
->iovpool
.queue
);
842 card
->iovpool
.count
= 0;
843 for (j
= 0; j
< NUM_IOVB
; j
++)
845 struct sk_buff
*iovb
;
846 iovb
= alloc_skb(NS_IOVBUFSIZE
, GFP_KERNEL
);
849 printk("nicstar%d: can't allocate %dth of %d iovec buffers.\n",
852 ns_init_card_error(card
, error
);
855 skb_queue_tail(&card
->iovpool
.queue
, iovb
);
856 card
->iovpool
.count
++;
861 /* Configure NICStAR */
862 if (card
->rct_size
== 4096)
863 ns_cfg_rctsize
= NS_CFG_RCTSIZE_4096_ENTRIES
;
864 else /* (card->rct_size == 16384) */
865 ns_cfg_rctsize
= NS_CFG_RCTSIZE_16384_ENTRIES
;
869 /* Register device */
870 card
->atmdev
= atm_dev_register("nicstar", &atm_ops
, -1, NULL
);
871 if (card
->atmdev
== NULL
)
873 printk("nicstar%d: can't register device.\n", i
);
875 ns_init_card_error(card
, error
);
879 if (ns_parse_mac(mac
[i
], card
->atmdev
->esi
)) {
880 nicstar_read_eprom(card
->membase
, NICSTAR_EPROM_MAC_ADDR_OFFSET
,
881 card
->atmdev
->esi
, 6);
882 if (memcmp(card
->atmdev
->esi
, "\x00\x00\x00\x00\x00\x00", 6) == 0) {
883 nicstar_read_eprom(card
->membase
, NICSTAR_EPROM_MAC_ADDR_OFFSET_ALT
,
884 card
->atmdev
->esi
, 6);
888 printk("nicstar%d: MAC address %02X:%02X:%02X:%02X:%02X:%02X\n", i
,
889 card
->atmdev
->esi
[0], card
->atmdev
->esi
[1], card
->atmdev
->esi
[2],
890 card
->atmdev
->esi
[3], card
->atmdev
->esi
[4], card
->atmdev
->esi
[5]);
892 card
->atmdev
->dev_data
= card
;
893 card
->atmdev
->ci_range
.vpi_bits
= card
->vpibits
;
894 card
->atmdev
->ci_range
.vci_bits
= card
->vcibits
;
895 card
->atmdev
->link_rate
= card
->max_pcr
;
896 card
->atmdev
->phy
= NULL
;
898 #ifdef CONFIG_ATM_NICSTAR_USE_SUNI
899 if (card
->max_pcr
== ATM_OC3_PCR
)
900 suni_init(card
->atmdev
);
901 #endif /* CONFIG_ATM_NICSTAR_USE_SUNI */
903 #ifdef CONFIG_ATM_NICSTAR_USE_IDT77105
904 if (card
->max_pcr
== ATM_25_PCR
)
905 idt77105_init(card
->atmdev
);
906 #endif /* CONFIG_ATM_NICSTAR_USE_IDT77105 */
908 if (card
->atmdev
->phy
&& card
->atmdev
->phy
->start
)
909 card
->atmdev
->phy
->start(card
->atmdev
);
911 writel(NS_CFG_RXPATH
|
918 NS_CFG_RXINT_NODELAY
|
919 NS_CFG_RAWIE
| /* Only enabled if RCQ_SUPPORT */
923 NS_CFG_TSQFIE_OPT
| /* Only enabled if ENABLE_TSQFIE */
925 card
->membase
+ CFG
);
934 static void __devinit
ns_init_card_error(ns_dev
*card
, int error
)
938 writel(0x00000000, card
->membase
+ CFG
);
942 struct sk_buff
*iovb
;
943 while ((iovb
= skb_dequeue(&card
->iovpool
.queue
)) != NULL
)
944 dev_kfree_skb_any(iovb
);
949 while ((sb
= skb_dequeue(&card
->sbpool
.queue
)) != NULL
)
950 dev_kfree_skb_any(sb
);
951 free_scq(card
->scq0
, NULL
);
956 while ((lb
= skb_dequeue(&card
->lbpool
.queue
)) != NULL
)
957 dev_kfree_skb_any(lb
);
962 while ((hb
= skb_dequeue(&card
->hbpool
.queue
)) != NULL
)
963 dev_kfree_skb_any(hb
);
967 kfree(card
->rsq
.org
);
971 kfree(card
->tsq
.org
);
975 free_irq(card
->pcidev
->irq
, card
);
979 iounmap(card
->membase
);
983 pci_disable_device(card
->pcidev
);
990 static scq_info
*get_scq(int size
, u32 scd
)
995 if (size
!= VBR_SCQSIZE
&& size
!= CBR_SCQSIZE
)
996 return (scq_info
*) NULL
;
998 scq
= (scq_info
*) kmalloc(sizeof(scq_info
), GFP_KERNEL
);
999 if (scq
== (scq_info
*) NULL
)
1000 return (scq_info
*) NULL
;
1001 scq
->org
= kmalloc(2 * size
, GFP_KERNEL
);
1002 if (scq
->org
== NULL
)
1005 return (scq_info
*) NULL
;
1007 scq
->skb
= (struct sk_buff
**) kmalloc(sizeof(struct sk_buff
*) *
1008 (size
/ NS_SCQE_SIZE
), GFP_KERNEL
);
1009 if (scq
->skb
== (struct sk_buff
**) NULL
)
1013 return (scq_info
*) NULL
;
1015 scq
->num_entries
= size
/ NS_SCQE_SIZE
;
1016 scq
->base
= (ns_scqe
*) ALIGN_ADDRESS(scq
->org
, size
);
1017 scq
->next
= scq
->base
;
1018 scq
->last
= scq
->base
+ (scq
->num_entries
- 1);
1019 scq
->tail
= scq
->last
;
1021 scq
->num_entries
= size
/ NS_SCQE_SIZE
;
1023 init_waitqueue_head(&scq
->scqfull_waitq
);
1025 spin_lock_init(&scq
->lock
);
1027 for (i
= 0; i
< scq
->num_entries
; i
++)
1035 /* For variable rate SCQ vcc must be NULL */
1036 static void free_scq(scq_info
*scq
, struct atm_vcc
*vcc
)
1040 if (scq
->num_entries
== VBR_SCQ_NUM_ENTRIES
)
1041 for (i
= 0; i
< scq
->num_entries
; i
++)
1043 if (scq
->skb
[i
] != NULL
)
1045 vcc
= ATM_SKB(scq
->skb
[i
])->vcc
;
1046 if (vcc
->pop
!= NULL
)
1047 vcc
->pop(vcc
, scq
->skb
[i
]);
1049 dev_kfree_skb_any(scq
->skb
[i
]);
1052 else /* vcc must be != NULL */
1056 printk("nicstar: free_scq() called with vcc == NULL for fixed rate scq.");
1057 for (i
= 0; i
< scq
->num_entries
; i
++)
1058 dev_kfree_skb_any(scq
->skb
[i
]);
1061 for (i
= 0; i
< scq
->num_entries
; i
++)
1063 if (scq
->skb
[i
] != NULL
)
1065 if (vcc
->pop
!= NULL
)
1066 vcc
->pop(vcc
, scq
->skb
[i
]);
1068 dev_kfree_skb_any(scq
->skb
[i
]);
1079 /* The handles passed must be pointers to the sk_buff containing the small
1080 or large buffer(s) cast to u32. */
1081 static void push_rxbufs(ns_dev
*card
, u32 type
, u32 handle1
, u32 addr1
,
1082 u32 handle2
, u32 addr2
)
1085 unsigned long flags
;
1088 #ifdef GENERAL_DEBUG
1090 printk("nicstar%d: push_rxbufs called with addr1 = 0.\n", card
->index
);
1091 #endif /* GENERAL_DEBUG */
1093 stat
= readl(card
->membase
+ STAT
);
1094 card
->sbfqc
= ns_stat_sfbqc_get(stat
);
1095 card
->lbfqc
= ns_stat_lfbqc_get(stat
);
1102 addr2
= card
->sm_addr
;
1103 handle2
= card
->sm_handle
;
1104 card
->sm_addr
= 0x00000000;
1105 card
->sm_handle
= 0x00000000;
1107 else /* (!sm_addr) */
1109 card
->sm_addr
= addr1
;
1110 card
->sm_handle
= handle1
;
1114 else /* type == BUF_LG */
1120 addr2
= card
->lg_addr
;
1121 handle2
= card
->lg_handle
;
1122 card
->lg_addr
= 0x00000000;
1123 card
->lg_handle
= 0x00000000;
1125 else /* (!lg_addr) */
1127 card
->lg_addr
= addr1
;
1128 card
->lg_handle
= handle1
;
1137 if (card
->sbfqc
>= card
->sbnr
.max
)
1139 skb_unlink((struct sk_buff
*) handle1
);
1140 dev_kfree_skb_any((struct sk_buff
*) handle1
);
1141 skb_unlink((struct sk_buff
*) handle2
);
1142 dev_kfree_skb_any((struct sk_buff
*) handle2
);
1148 else /* (type == BUF_LG) */
1150 if (card
->lbfqc
>= card
->lbnr
.max
)
1152 skb_unlink((struct sk_buff
*) handle1
);
1153 dev_kfree_skb_any((struct sk_buff
*) handle1
);
1154 skb_unlink((struct sk_buff
*) handle2
);
1155 dev_kfree_skb_any((struct sk_buff
*) handle2
);
1162 ns_grab_res_lock(card
, flags
);
1164 while (CMD_BUSY(card
));
1165 writel(addr2
, card
->membase
+ DR3
);
1166 writel(handle2
, card
->membase
+ DR2
);
1167 writel(addr1
, card
->membase
+ DR1
);
1168 writel(handle1
, card
->membase
+ DR0
);
1169 writel(NS_CMD_WRITE_FREEBUFQ
| (u32
) type
, card
->membase
+ CMD
);
1171 spin_unlock_irqrestore(&card
->res_lock
, flags
);
1173 XPRINTK("nicstar%d: Pushing %s buffers at 0x%x and 0x%x.\n", card
->index
,
1174 (type
== BUF_SM
? "small" : "large"), addr1
, addr2
);
1177 if (!card
->efbie
&& card
->sbfqc
>= card
->sbnr
.min
&&
1178 card
->lbfqc
>= card
->lbnr
.min
)
1181 writel((readl(card
->membase
+ CFG
) | NS_CFG_EFBIE
), card
->membase
+ CFG
);
1189 static irqreturn_t
ns_irq_handler(int irq
, void *dev_id
, struct pt_regs
*regs
)
1193 struct atm_dev
*dev
;
1194 unsigned long flags
;
1196 card
= (ns_dev
*) dev_id
;
1200 PRINTK("nicstar%d: NICStAR generated an interrupt\n", card
->index
);
1202 ns_grab_int_lock(card
, flags
);
1204 stat_r
= readl(card
->membase
+ STAT
);
1206 /* Transmit Status Indicator has been written to T. S. Queue */
1207 if (stat_r
& NS_STAT_TSIF
)
1209 TXPRINTK("nicstar%d: TSI interrupt\n", card
->index
);
1211 writel(NS_STAT_TSIF
, card
->membase
+ STAT
);
1214 /* Incomplete CS-PDU has been transmitted */
1215 if (stat_r
& NS_STAT_TXICP
)
1217 writel(NS_STAT_TXICP
, card
->membase
+ STAT
);
1218 TXPRINTK("nicstar%d: Incomplete CS-PDU transmitted.\n",
1222 /* Transmit Status Queue 7/8 full */
1223 if (stat_r
& NS_STAT_TSQF
)
1225 writel(NS_STAT_TSQF
, card
->membase
+ STAT
);
1226 PRINTK("nicstar%d: TSQ full.\n", card
->index
);
1230 /* Timer overflow */
1231 if (stat_r
& NS_STAT_TMROF
)
1233 writel(NS_STAT_TMROF
, card
->membase
+ STAT
);
1234 PRINTK("nicstar%d: Timer overflow.\n", card
->index
);
1237 /* PHY device interrupt signal active */
1238 if (stat_r
& NS_STAT_PHYI
)
1240 writel(NS_STAT_PHYI
, card
->membase
+ STAT
);
1241 PRINTK("nicstar%d: PHY interrupt.\n", card
->index
);
1242 if (dev
->phy
&& dev
->phy
->interrupt
) {
1243 dev
->phy
->interrupt(dev
);
1247 /* Small Buffer Queue is full */
1248 if (stat_r
& NS_STAT_SFBQF
)
1250 writel(NS_STAT_SFBQF
, card
->membase
+ STAT
);
1251 printk("nicstar%d: Small free buffer queue is full.\n", card
->index
);
1254 /* Large Buffer Queue is full */
1255 if (stat_r
& NS_STAT_LFBQF
)
1257 writel(NS_STAT_LFBQF
, card
->membase
+ STAT
);
1258 printk("nicstar%d: Large free buffer queue is full.\n", card
->index
);
1261 /* Receive Status Queue is full */
1262 if (stat_r
& NS_STAT_RSQF
)
1264 writel(NS_STAT_RSQF
, card
->membase
+ STAT
);
1265 printk("nicstar%d: RSQ full.\n", card
->index
);
1269 /* Complete CS-PDU received */
1270 if (stat_r
& NS_STAT_EOPDU
)
1272 RXPRINTK("nicstar%d: End of CS-PDU received.\n", card
->index
);
1274 writel(NS_STAT_EOPDU
, card
->membase
+ STAT
);
1277 /* Raw cell received */
1278 if (stat_r
& NS_STAT_RAWCF
)
1280 writel(NS_STAT_RAWCF
, card
->membase
+ STAT
);
1282 printk("nicstar%d: Raw cell received and no support yet...\n",
1284 #endif /* RCQ_SUPPORT */
1285 /* NOTE: the following procedure may keep a raw cell pending until the
1286 next interrupt. As this preliminary support is only meant to
1287 avoid buffer leakage, this is not an issue. */
1288 while (readl(card
->membase
+ RAWCT
) != card
->rawch
)
1292 rawcell
= (ns_rcqe
*) bus_to_virt(card
->rawch
);
1293 if (ns_rcqe_islast(rawcell
))
1295 struct sk_buff
*oldbuf
;
1297 oldbuf
= card
->rcbuf
;
1298 card
->rcbuf
= (struct sk_buff
*) ns_rcqe_nextbufhandle(rawcell
);
1299 card
->rawch
= (u32
) virt_to_bus(card
->rcbuf
->data
);
1300 recycle_rx_buf(card
, oldbuf
);
1303 card
->rawch
+= NS_RCQE_SIZE
;
1307 /* Small buffer queue is empty */
1308 if (stat_r
& NS_STAT_SFBQE
)
1313 writel(NS_STAT_SFBQE
, card
->membase
+ STAT
);
1314 printk("nicstar%d: Small free buffer queue empty.\n",
1316 for (i
= 0; i
< card
->sbnr
.min
; i
++)
1318 sb
= dev_alloc_skb(NS_SMSKBSIZE
);
1321 writel(readl(card
->membase
+ CFG
) & ~NS_CFG_EFBIE
, card
->membase
+ CFG
);
1325 skb_queue_tail(&card
->sbpool
.queue
, sb
);
1326 skb_reserve(sb
, NS_AAL0_HEADER
);
1327 push_rxbufs(card
, BUF_SM
, (u32
) sb
, (u32
) virt_to_bus(sb
->data
), 0, 0);
1333 /* Large buffer queue empty */
1334 if (stat_r
& NS_STAT_LFBQE
)
1339 writel(NS_STAT_LFBQE
, card
->membase
+ STAT
);
1340 printk("nicstar%d: Large free buffer queue empty.\n",
1342 for (i
= 0; i
< card
->lbnr
.min
; i
++)
1344 lb
= dev_alloc_skb(NS_LGSKBSIZE
);
1347 writel(readl(card
->membase
+ CFG
) & ~NS_CFG_EFBIE
, card
->membase
+ CFG
);
1351 skb_queue_tail(&card
->lbpool
.queue
, lb
);
1352 skb_reserve(lb
, NS_SMBUFSIZE
);
1353 push_rxbufs(card
, BUF_LG
, (u32
) lb
, (u32
) virt_to_bus(lb
->data
), 0, 0);
1359 /* Receive Status Queue is 7/8 full */
1360 if (stat_r
& NS_STAT_RSQAF
)
1362 writel(NS_STAT_RSQAF
, card
->membase
+ STAT
);
1363 RXPRINTK("nicstar%d: RSQ almost full.\n", card
->index
);
1367 spin_unlock_irqrestore(&card
->int_lock
, flags
);
1368 PRINTK("nicstar%d: end of interrupt service\n", card
->index
);
1374 static int ns_open(struct atm_vcc
*vcc
)
1378 unsigned long tmpl
, modl
;
1379 int tcr
, tcra
; /* target cell rate, and absolute value */
1380 int n
= 0; /* Number of entries in the TST. Initialized to remove
1381 the compiler warning. */
1383 int frscdi
= 0; /* Index of the SCD. Initialized to remove the compiler
1384 warning. How I wish compilers were clever enough to
1385 tell which variables can truly be used
1387 int inuse
; /* tx or rx vc already in use by another vcc */
1388 short vpi
= vcc
->vpi
;
1391 card
= (ns_dev
*) vcc
->dev
->dev_data
;
1392 PRINTK("nicstar%d: opening vpi.vci %d.%d \n", card
->index
, (int) vpi
, vci
);
1393 if (vcc
->qos
.aal
!= ATM_AAL5
&& vcc
->qos
.aal
!= ATM_AAL0
)
1395 PRINTK("nicstar%d: unsupported AAL.\n", card
->index
);
1399 vc
= &(card
->vcmap
[vpi
<< card
->vcibits
| vci
]);
1403 if (vcc
->qos
.txtp
.traffic_class
!= ATM_NONE
&& vc
->tx
)
1405 if (vcc
->qos
.rxtp
.traffic_class
!= ATM_NONE
&& vc
->rx
)
1409 printk("nicstar%d: %s vci already in use.\n", card
->index
,
1410 inuse
== 1 ? "tx" : inuse
== 2 ? "rx" : "tx and rx");
1414 set_bit(ATM_VF_ADDR
,&vcc
->flags
);
1416 /* NOTE: You are not allowed to modify an open connection's QOS. To change
1417 that, remove the ATM_VF_PARTIAL flag checking. There may be other changes
1418 needed to do that. */
1419 if (!test_bit(ATM_VF_PARTIAL
,&vcc
->flags
))
1423 set_bit(ATM_VF_PARTIAL
,&vcc
->flags
);
1424 if (vcc
->qos
.txtp
.traffic_class
== ATM_CBR
)
1426 /* Check requested cell rate and availability of SCD */
1427 if (vcc
->qos
.txtp
.max_pcr
== 0 && vcc
->qos
.txtp
.pcr
== 0 &&
1428 vcc
->qos
.txtp
.min_pcr
== 0)
1430 PRINTK("nicstar%d: trying to open a CBR vc with cell rate = 0 \n",
1432 clear_bit(ATM_VF_PARTIAL
,&vcc
->flags
);
1433 clear_bit(ATM_VF_ADDR
,&vcc
->flags
);
1437 tcr
= atm_pcr_goal(&(vcc
->qos
.txtp
));
1438 tcra
= tcr
>= 0 ? tcr
: -tcr
;
1440 PRINTK("nicstar%d: target cell rate = %d.\n", card
->index
,
1441 vcc
->qos
.txtp
.max_pcr
);
1443 tmpl
= (unsigned long)tcra
* (unsigned long)NS_TST_NUM_ENTRIES
;
1444 modl
= tmpl
% card
->max_pcr
;
1446 n
= (int)(tmpl
/ card
->max_pcr
);
1453 if ((n
= (card
->tst_free_entries
- NS_TST_RESERVED
)) <= 0)
1455 PRINTK("nicstar%d: no CBR bandwidth free.\n", card
->index
);
1456 clear_bit(ATM_VF_PARTIAL
,&vcc
->flags
);
1457 clear_bit(ATM_VF_ADDR
,&vcc
->flags
);
1464 printk("nicstar%d: selected bandwidth < granularity.\n", card
->index
);
1465 clear_bit(ATM_VF_PARTIAL
,&vcc
->flags
);
1466 clear_bit(ATM_VF_ADDR
,&vcc
->flags
);
1470 if (n
> (card
->tst_free_entries
- NS_TST_RESERVED
))
1472 PRINTK("nicstar%d: not enough free CBR bandwidth.\n", card
->index
);
1473 clear_bit(ATM_VF_PARTIAL
,&vcc
->flags
);
1474 clear_bit(ATM_VF_ADDR
,&vcc
->flags
);
1478 card
->tst_free_entries
-= n
;
1480 XPRINTK("nicstar%d: writing %d tst entries.\n", card
->index
, n
);
1481 for (frscdi
= 0; frscdi
< NS_FRSCD_NUM
; frscdi
++)
1483 if (card
->scd2vc
[frscdi
] == NULL
)
1485 card
->scd2vc
[frscdi
] = vc
;
1489 if (frscdi
== NS_FRSCD_NUM
)
1491 PRINTK("nicstar%d: no SCD available for CBR channel.\n", card
->index
);
1492 card
->tst_free_entries
+= n
;
1493 clear_bit(ATM_VF_PARTIAL
,&vcc
->flags
);
1494 clear_bit(ATM_VF_ADDR
,&vcc
->flags
);
1498 vc
->cbr_scd
= NS_FRSCD
+ frscdi
* NS_FRSCD_SIZE
;
1500 scq
= get_scq(CBR_SCQSIZE
, vc
->cbr_scd
);
1501 if (scq
== (scq_info
*) NULL
)
1503 PRINTK("nicstar%d: can't get fixed rate SCQ.\n", card
->index
);
1504 card
->scd2vc
[frscdi
] = NULL
;
1505 card
->tst_free_entries
+= n
;
1506 clear_bit(ATM_VF_PARTIAL
,&vcc
->flags
);
1507 clear_bit(ATM_VF_ADDR
,&vcc
->flags
);
1511 u32d
[0] = (u32
) virt_to_bus(scq
->base
);
1512 u32d
[1] = (u32
) 0x00000000;
1513 u32d
[2] = (u32
) 0xffffffff;
1514 u32d
[3] = (u32
) 0x00000000;
1515 ns_write_sram(card
, vc
->cbr_scd
, u32d
, 4);
1517 fill_tst(card
, n
, vc
);
1519 else if (vcc
->qos
.txtp
.traffic_class
== ATM_UBR
)
1521 vc
->cbr_scd
= 0x00000000;
1522 vc
->scq
= card
->scq0
;
1525 if (vcc
->qos
.txtp
.traffic_class
!= ATM_NONE
)
1531 if (vcc
->qos
.rxtp
.traffic_class
!= ATM_NONE
)
1539 /* Open the connection in hardware */
1540 if (vcc
->qos
.aal
== ATM_AAL5
)
1541 status
= NS_RCTE_AAL5
| NS_RCTE_CONNECTOPEN
;
1542 else /* vcc->qos.aal == ATM_AAL0 */
1543 status
= NS_RCTE_AAL0
| NS_RCTE_CONNECTOPEN
;
1545 status
|= NS_RCTE_RAWCELLINTEN
;
1546 #endif /* RCQ_SUPPORT */
1547 ns_write_sram(card
, NS_RCT
+ (vpi
<< card
->vcibits
| vci
) *
1548 NS_RCT_ENTRY_SIZE
, &status
, 1);
1553 set_bit(ATM_VF_READY
,&vcc
->flags
);
1559 static void ns_close(struct atm_vcc
*vcc
)
1567 card
= vcc
->dev
->dev_data
;
1568 PRINTK("nicstar%d: closing vpi.vci %d.%d \n", card
->index
,
1569 (int) vcc
->vpi
, vcc
->vci
);
1571 clear_bit(ATM_VF_READY
,&vcc
->flags
);
1573 if (vcc
->qos
.rxtp
.traffic_class
!= ATM_NONE
)
1576 unsigned long flags
;
1578 addr
= NS_RCT
+ (vcc
->vpi
<< card
->vcibits
| vcc
->vci
) * NS_RCT_ENTRY_SIZE
;
1579 ns_grab_res_lock(card
, flags
);
1580 while(CMD_BUSY(card
));
1581 writel(NS_CMD_CLOSE_CONNECTION
| addr
<< 2, card
->membase
+ CMD
);
1582 spin_unlock_irqrestore(&card
->res_lock
, flags
);
1585 if (vc
->rx_iov
!= NULL
)
1587 struct sk_buff
*iovb
;
1590 stat
= readl(card
->membase
+ STAT
);
1591 card
->sbfqc
= ns_stat_sfbqc_get(stat
);
1592 card
->lbfqc
= ns_stat_lfbqc_get(stat
);
1594 PRINTK("nicstar%d: closing a VC with pending rx buffers.\n",
1597 recycle_iovec_rx_bufs(card
, (struct iovec
*) iovb
->data
,
1598 NS_SKB(iovb
)->iovcnt
);
1599 NS_SKB(iovb
)->iovcnt
= 0;
1600 NS_SKB(iovb
)->vcc
= NULL
;
1601 ns_grab_int_lock(card
, flags
);
1602 recycle_iov_buf(card
, iovb
);
1603 spin_unlock_irqrestore(&card
->int_lock
, flags
);
1608 if (vcc
->qos
.txtp
.traffic_class
!= ATM_NONE
)
1613 if (vcc
->qos
.txtp
.traffic_class
== ATM_CBR
)
1615 unsigned long flags
;
1623 ns_grab_scq_lock(card
, scq
, flags
);
1625 if (scqep
== scq
->base
)
1629 if (scqep
== scq
->tail
)
1631 spin_unlock_irqrestore(&scq
->lock
, flags
);
1634 /* If the last entry is not a TSR, place one in the SCQ in order to
1635 be able to completely drain it and then close. */
1636 if (!ns_scqe_is_tsr(scqep
) && scq
->tail
!= scq
->next
)
1643 tsr
.word_1
= ns_tsr_mkword_1(NS_TSR_INTENABLE
);
1644 scdi
= (vc
->cbr_scd
- NS_FRSCD
) / NS_FRSCD_SIZE
;
1645 scqi
= scq
->next
- scq
->base
;
1646 tsr
.word_2
= ns_tsr_mkword_2(scdi
, scqi
);
1647 tsr
.word_3
= 0x00000000;
1648 tsr
.word_4
= 0x00000000;
1651 scq
->skb
[index
] = NULL
;
1652 if (scq
->next
== scq
->last
)
1653 scq
->next
= scq
->base
;
1656 data
= (u32
) virt_to_bus(scq
->next
);
1657 ns_write_sram(card
, scq
->scd
, &data
, 1);
1659 spin_unlock_irqrestore(&scq
->lock
, flags
);
1663 /* Free all TST entries */
1664 data
= NS_TST_OPCODE_VARIABLE
;
1665 for (i
= 0; i
< NS_TST_NUM_ENTRIES
; i
++)
1667 if (card
->tste2vc
[i
] == vc
)
1669 ns_write_sram(card
, card
->tst_addr
+ i
, &data
, 1);
1670 card
->tste2vc
[i
] = NULL
;
1671 card
->tst_free_entries
++;
1675 card
->scd2vc
[(vc
->cbr_scd
- NS_FRSCD
) / NS_FRSCD_SIZE
] = NULL
;
1676 free_scq(vc
->scq
, vcc
);
1679 /* remove all references to vcc before deleting it */
1680 if (vcc
->qos
.txtp
.traffic_class
!= ATM_NONE
)
1682 unsigned long flags
;
1683 scq_info
*scq
= card
->scq0
;
1685 ns_grab_scq_lock(card
, scq
, flags
);
1687 for(i
= 0; i
< scq
->num_entries
; i
++) {
1688 if(scq
->skb
[i
] && ATM_SKB(scq
->skb
[i
])->vcc
== vcc
) {
1689 ATM_SKB(scq
->skb
[i
])->vcc
= NULL
;
1690 atm_return(vcc
, scq
->skb
[i
]->truesize
);
1691 PRINTK("nicstar: deleted pending vcc mapping\n");
1695 spin_unlock_irqrestore(&scq
->lock
, flags
);
1698 vcc
->dev_data
= NULL
;
1699 clear_bit(ATM_VF_PARTIAL
,&vcc
->flags
);
1700 clear_bit(ATM_VF_ADDR
,&vcc
->flags
);
1705 stat
= readl(card
->membase
+ STAT
);
1706 cfg
= readl(card
->membase
+ CFG
);
1707 printk("STAT = 0x%08X CFG = 0x%08X \n", stat
, cfg
);
1708 printk("TSQ: base = 0x%08X next = 0x%08X last = 0x%08X TSQT = 0x%08X \n",
1709 (u32
) card
->tsq
.base
, (u32
) card
->tsq
.next
,(u32
) card
->tsq
.last
,
1710 readl(card
->membase
+ TSQT
));
1711 printk("RSQ: base = 0x%08X next = 0x%08X last = 0x%08X RSQT = 0x%08X \n",
1712 (u32
) card
->rsq
.base
, (u32
) card
->rsq
.next
,(u32
) card
->rsq
.last
,
1713 readl(card
->membase
+ RSQT
));
1714 printk("Empty free buffer queue interrupt %s \n",
1715 card
->efbie
? "enabled" : "disabled");
1716 printk("SBCNT = %d count = %d LBCNT = %d count = %d \n",
1717 ns_stat_sfbqc_get(stat
), card
->sbpool
.count
,
1718 ns_stat_lfbqc_get(stat
), card
->lbpool
.count
);
1719 printk("hbpool.count = %d iovpool.count = %d \n",
1720 card
->hbpool
.count
, card
->iovpool
.count
);
1722 #endif /* RX_DEBUG */
1727 static void fill_tst(ns_dev
*card
, int n
, vc_map
*vc
)
1734 /* It would be very complicated to keep the two TSTs synchronized while
1735 assuring that writes are only made to the inactive TST. So, for now I
1736 will use only one TST. If problems occur, I will change this again */
1738 new_tst
= card
->tst_addr
;
1740 /* Fill procedure */
1742 for (e
= 0; e
< NS_TST_NUM_ENTRIES
; e
++)
1744 if (card
->tste2vc
[e
] == NULL
)
1747 if (e
== NS_TST_NUM_ENTRIES
) {
1748 printk("nicstar%d: No free TST entries found. \n", card
->index
);
1753 cl
= NS_TST_NUM_ENTRIES
;
1754 data
= ns_tste_make(NS_TST_OPCODE_FIXED
, vc
->cbr_scd
);
1758 if (cl
>= NS_TST_NUM_ENTRIES
&& card
->tste2vc
[e
] == NULL
)
1760 card
->tste2vc
[e
] = vc
;
1761 ns_write_sram(card
, new_tst
+ e
, &data
, 1);
1762 cl
-= NS_TST_NUM_ENTRIES
;
1766 if (++e
== NS_TST_NUM_ENTRIES
) {
1772 /* End of fill procedure */
1774 data
= ns_tste_make(NS_TST_OPCODE_END
, new_tst
);
1775 ns_write_sram(card
, new_tst
+ NS_TST_NUM_ENTRIES
, &data
, 1);
1776 ns_write_sram(card
, card
->tst_addr
+ NS_TST_NUM_ENTRIES
, &data
, 1);
1777 card
->tst_addr
= new_tst
;
1782 static int ns_send(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
1787 unsigned long buflen
;
1789 u32 flags
; /* TBD flags, not CPU flags */
1791 card
= vcc
->dev
->dev_data
;
1792 TXPRINTK("nicstar%d: ns_send() called.\n", card
->index
);
1793 if ((vc
= (vc_map
*) vcc
->dev_data
) == NULL
)
1795 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n", card
->index
);
1796 atomic_inc(&vcc
->stats
->tx_err
);
1797 dev_kfree_skb_any(skb
);
1803 printk("nicstar%d: Trying to transmit on a non-tx VC.\n", card
->index
);
1804 atomic_inc(&vcc
->stats
->tx_err
);
1805 dev_kfree_skb_any(skb
);
1809 if (vcc
->qos
.aal
!= ATM_AAL5
&& vcc
->qos
.aal
!= ATM_AAL0
)
1811 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n", card
->index
);
1812 atomic_inc(&vcc
->stats
->tx_err
);
1813 dev_kfree_skb_any(skb
);
1817 if (skb_shinfo(skb
)->nr_frags
!= 0)
1819 printk("nicstar%d: No scatter-gather yet.\n", card
->index
);
1820 atomic_inc(&vcc
->stats
->tx_err
);
1821 dev_kfree_skb_any(skb
);
1825 ATM_SKB(skb
)->vcc
= vcc
;
1827 if (vcc
->qos
.aal
== ATM_AAL5
)
1829 buflen
= (skb
->len
+ 47 + 8) / 48 * 48; /* Multiple of 48 */
1830 flags
= NS_TBD_AAL5
;
1831 scqe
.word_2
= cpu_to_le32((u32
) virt_to_bus(skb
->data
));
1832 scqe
.word_3
= cpu_to_le32((u32
) skb
->len
);
1833 scqe
.word_4
= ns_tbd_mkword_4(0, (u32
) vcc
->vpi
, (u32
) vcc
->vci
, 0,
1834 ATM_SKB(skb
)->atm_options
& ATM_ATMOPT_CLP
? 1 : 0);
1835 flags
|= NS_TBD_EOPDU
;
1837 else /* (vcc->qos.aal == ATM_AAL0) */
1839 buflen
= ATM_CELL_PAYLOAD
; /* i.e., 48 bytes */
1840 flags
= NS_TBD_AAL0
;
1841 scqe
.word_2
= cpu_to_le32((u32
) virt_to_bus(skb
->data
) + NS_AAL0_HEADER
);
1842 scqe
.word_3
= cpu_to_le32(0x00000000);
1843 if (*skb
->data
& 0x02) /* Payload type 1 - end of pdu */
1844 flags
|= NS_TBD_EOPDU
;
1845 scqe
.word_4
= cpu_to_le32(*((u32
*) skb
->data
) & ~NS_TBD_VC_MASK
);
1846 /* Force the VPI/VCI to be the same as in VCC struct */
1847 scqe
.word_4
|= cpu_to_le32((((u32
) vcc
->vpi
) << NS_TBD_VPI_SHIFT
|
1848 ((u32
) vcc
->vci
) << NS_TBD_VCI_SHIFT
) &
1852 if (vcc
->qos
.txtp
.traffic_class
== ATM_CBR
)
1854 scqe
.word_1
= ns_tbd_mkword_1_novbr(flags
, (u32
) buflen
);
1855 scq
= ((vc_map
*) vcc
->dev_data
)->scq
;
1859 scqe
.word_1
= ns_tbd_mkword_1(flags
, (u32
) 1, (u32
) 1, (u32
) buflen
);
1863 if (push_scqe(card
, vc
, scq
, &scqe
, skb
) != 0)
1865 atomic_inc(&vcc
->stats
->tx_err
);
1866 dev_kfree_skb_any(skb
);
1869 atomic_inc(&vcc
->stats
->tx
);
1876 static int push_scqe(ns_dev
*card
, vc_map
*vc
, scq_info
*scq
, ns_scqe
*tbd
,
1877 struct sk_buff
*skb
)
1879 unsigned long flags
;
1886 ns_grab_scq_lock(card
, scq
, flags
);
1887 while (scq
->tail
== scq
->next
)
1889 if (in_interrupt()) {
1890 spin_unlock_irqrestore(&scq
->lock
, flags
);
1891 printk("nicstar%d: Error pushing TBD.\n", card
->index
);
1896 spin_unlock_irqrestore(&scq
->lock
, flags
);
1897 interruptible_sleep_on_timeout(&scq
->scqfull_waitq
, SCQFULL_TIMEOUT
);
1898 ns_grab_scq_lock(card
, scq
, flags
);
1901 spin_unlock_irqrestore(&scq
->lock
, flags
);
1902 printk("nicstar%d: Timeout pushing TBD.\n", card
->index
);
1907 index
= (int) (scq
->next
- scq
->base
);
1908 scq
->skb
[index
] = skb
;
1909 XPRINTK("nicstar%d: sending skb at 0x%x (pos %d).\n",
1910 card
->index
, (u32
) skb
, index
);
1911 XPRINTK("nicstar%d: TBD written:\n0x%x\n0x%x\n0x%x\n0x%x\n at 0x%x.\n",
1912 card
->index
, le32_to_cpu(tbd
->word_1
), le32_to_cpu(tbd
->word_2
),
1913 le32_to_cpu(tbd
->word_3
), le32_to_cpu(tbd
->word_4
),
1915 if (scq
->next
== scq
->last
)
1916 scq
->next
= scq
->base
;
1921 if (scq
->num_entries
== VBR_SCQ_NUM_ENTRIES
)
1929 if (vc
->tbd_count
>= MAX_TBD_PER_VC
|| scq
->tbd_count
>= MAX_TBD_PER_SCQ
)
1933 while (scq
->tail
== scq
->next
)
1935 if (in_interrupt()) {
1936 data
= (u32
) virt_to_bus(scq
->next
);
1937 ns_write_sram(card
, scq
->scd
, &data
, 1);
1938 spin_unlock_irqrestore(&scq
->lock
, flags
);
1939 printk("nicstar%d: Error pushing TSR.\n", card
->index
);
1944 if (has_run
++) break;
1945 spin_unlock_irqrestore(&scq
->lock
, flags
);
1946 interruptible_sleep_on_timeout(&scq
->scqfull_waitq
, SCQFULL_TIMEOUT
);
1947 ns_grab_scq_lock(card
, scq
, flags
);
1952 tsr
.word_1
= ns_tsr_mkword_1(NS_TSR_INTENABLE
);
1954 scdi
= NS_TSR_SCDISVBR
;
1956 scdi
= (vc
->cbr_scd
- NS_FRSCD
) / NS_FRSCD_SIZE
;
1957 scqi
= scq
->next
- scq
->base
;
1958 tsr
.word_2
= ns_tsr_mkword_2(scdi
, scqi
);
1959 tsr
.word_3
= 0x00000000;
1960 tsr
.word_4
= 0x00000000;
1964 scq
->skb
[index
] = NULL
;
1965 XPRINTK("nicstar%d: TSR written:\n0x%x\n0x%x\n0x%x\n0x%x\n at 0x%x.\n",
1966 card
->index
, le32_to_cpu(tsr
.word_1
), le32_to_cpu(tsr
.word_2
),
1967 le32_to_cpu(tsr
.word_3
), le32_to_cpu(tsr
.word_4
),
1969 if (scq
->next
== scq
->last
)
1970 scq
->next
= scq
->base
;
1977 PRINTK("nicstar%d: Timeout pushing TSR.\n", card
->index
);
1979 data
= (u32
) virt_to_bus(scq
->next
);
1980 ns_write_sram(card
, scq
->scd
, &data
, 1);
1982 spin_unlock_irqrestore(&scq
->lock
, flags
);
1989 static void process_tsq(ns_dev
*card
)
1993 ns_tsi
*previous
= NULL
, *one_ahead
, *two_ahead
;
1994 int serviced_entries
; /* flag indicating at least on entry was serviced */
1996 serviced_entries
= 0;
1998 if (card
->tsq
.next
== card
->tsq
.last
)
1999 one_ahead
= card
->tsq
.base
;
2001 one_ahead
= card
->tsq
.next
+ 1;
2003 if (one_ahead
== card
->tsq
.last
)
2004 two_ahead
= card
->tsq
.base
;
2006 two_ahead
= one_ahead
+ 1;
2008 while (!ns_tsi_isempty(card
->tsq
.next
) || !ns_tsi_isempty(one_ahead
) ||
2009 !ns_tsi_isempty(two_ahead
))
2010 /* At most two empty, as stated in the 77201 errata */
2012 serviced_entries
= 1;
2014 /* Skip the one or two possible empty entries */
2015 while (ns_tsi_isempty(card
->tsq
.next
)) {
2016 if (card
->tsq
.next
== card
->tsq
.last
)
2017 card
->tsq
.next
= card
->tsq
.base
;
2022 if (!ns_tsi_tmrof(card
->tsq
.next
))
2024 scdi
= ns_tsi_getscdindex(card
->tsq
.next
);
2025 if (scdi
== NS_TSI_SCDISVBR
)
2029 if (card
->scd2vc
[scdi
] == NULL
)
2031 printk("nicstar%d: could not find VC from SCD index.\n",
2033 ns_tsi_init(card
->tsq
.next
);
2036 scq
= card
->scd2vc
[scdi
]->scq
;
2038 drain_scq(card
, scq
, ns_tsi_getscqpos(card
->tsq
.next
));
2040 wake_up_interruptible(&(scq
->scqfull_waitq
));
2043 ns_tsi_init(card
->tsq
.next
);
2044 previous
= card
->tsq
.next
;
2045 if (card
->tsq
.next
== card
->tsq
.last
)
2046 card
->tsq
.next
= card
->tsq
.base
;
2050 if (card
->tsq
.next
== card
->tsq
.last
)
2051 one_ahead
= card
->tsq
.base
;
2053 one_ahead
= card
->tsq
.next
+ 1;
2055 if (one_ahead
== card
->tsq
.last
)
2056 two_ahead
= card
->tsq
.base
;
2058 two_ahead
= one_ahead
+ 1;
2061 if (serviced_entries
) {
2062 writel((((u32
) previous
) - ((u32
) card
->tsq
.base
)),
2063 card
->membase
+ TSQH
);
2069 static void drain_scq(ns_dev
*card
, scq_info
*scq
, int pos
)
2071 struct atm_vcc
*vcc
;
2072 struct sk_buff
*skb
;
2074 unsigned long flags
;
2076 XPRINTK("nicstar%d: drain_scq() called, scq at 0x%x, pos %d.\n",
2077 card
->index
, (u32
) scq
, pos
);
2078 if (pos
>= scq
->num_entries
)
2080 printk("nicstar%d: Bad index on drain_scq().\n", card
->index
);
2084 ns_grab_scq_lock(card
, scq
, flags
);
2085 i
= (int) (scq
->tail
- scq
->base
);
2086 if (++i
== scq
->num_entries
)
2091 XPRINTK("nicstar%d: freeing skb at 0x%x (index %d).\n",
2092 card
->index
, (u32
) skb
, i
);
2095 vcc
= ATM_SKB(skb
)->vcc
;
2096 if (vcc
&& vcc
->pop
!= NULL
) {
2099 dev_kfree_skb_irq(skb
);
2103 if (++i
== scq
->num_entries
)
2106 scq
->tail
= scq
->base
+ pos
;
2107 spin_unlock_irqrestore(&scq
->lock
, flags
);
2112 static void process_rsq(ns_dev
*card
)
2116 if (!ns_rsqe_valid(card
->rsq
.next
))
2118 while (ns_rsqe_valid(card
->rsq
.next
))
2120 dequeue_rx(card
, card
->rsq
.next
);
2121 ns_rsqe_init(card
->rsq
.next
);
2122 previous
= card
->rsq
.next
;
2123 if (card
->rsq
.next
== card
->rsq
.last
)
2124 card
->rsq
.next
= card
->rsq
.base
;
2128 writel((((u32
) previous
) - ((u32
) card
->rsq
.base
)),
2129 card
->membase
+ RSQH
);
2134 static void dequeue_rx(ns_dev
*card
, ns_rsqe
*rsqe
)
2138 struct sk_buff
*iovb
;
2140 struct atm_vcc
*vcc
;
2141 struct sk_buff
*skb
;
2142 unsigned short aal5_len
;
2146 stat
= readl(card
->membase
+ STAT
);
2147 card
->sbfqc
= ns_stat_sfbqc_get(stat
);
2148 card
->lbfqc
= ns_stat_lfbqc_get(stat
);
2150 skb
= (struct sk_buff
*) le32_to_cpu(rsqe
->buffer_handle
);
2151 vpi
= ns_rsqe_vpi(rsqe
);
2152 vci
= ns_rsqe_vci(rsqe
);
2153 if (vpi
>= 1UL << card
->vpibits
|| vci
>= 1UL << card
->vcibits
)
2155 printk("nicstar%d: SDU received for out-of-range vc %d.%d.\n",
2156 card
->index
, vpi
, vci
);
2157 recycle_rx_buf(card
, skb
);
2161 vc
= &(card
->vcmap
[vpi
<< card
->vcibits
| vci
]);
2164 RXPRINTK("nicstar%d: SDU received on non-rx vc %d.%d.\n",
2165 card
->index
, vpi
, vci
);
2166 recycle_rx_buf(card
, skb
);
2172 if (vcc
->qos
.aal
== ATM_AAL0
)
2175 unsigned char *cell
;
2179 for (i
= ns_rsqe_cellcount(rsqe
); i
; i
--)
2181 if ((sb
= dev_alloc_skb(NS_SMSKBSIZE
)) == NULL
)
2183 printk("nicstar%d: Can't allocate buffers for aal0.\n",
2185 atomic_add(i
,&vcc
->stats
->rx_drop
);
2188 if (!atm_charge(vcc
, sb
->truesize
))
2190 RXPRINTK("nicstar%d: atm_charge() dropped aal0 packets.\n",
2192 atomic_add(i
-1,&vcc
->stats
->rx_drop
); /* already increased by 1 */
2193 dev_kfree_skb_any(sb
);
2196 /* Rebuild the header */
2197 *((u32
*) sb
->data
) = le32_to_cpu(rsqe
->word_1
) << 4 |
2198 (ns_rsqe_clp(rsqe
) ? 0x00000001 : 0x00000000);
2199 if (i
== 1 && ns_rsqe_eopdu(rsqe
))
2200 *((u32
*) sb
->data
) |= 0x00000002;
2201 skb_put(sb
, NS_AAL0_HEADER
);
2202 memcpy(sb
->tail
, cell
, ATM_CELL_PAYLOAD
);
2203 skb_put(sb
, ATM_CELL_PAYLOAD
);
2204 ATM_SKB(sb
)->vcc
= vcc
;
2205 do_gettimeofday(&sb
->stamp
);
2207 atomic_inc(&vcc
->stats
->rx
);
2208 cell
+= ATM_CELL_PAYLOAD
;
2211 recycle_rx_buf(card
, skb
);
2215 /* To reach this point, the AAL layer can only be AAL5 */
2217 if ((iovb
= vc
->rx_iov
) == NULL
)
2219 iovb
= skb_dequeue(&(card
->iovpool
.queue
));
2220 if (iovb
== NULL
) /* No buffers in the queue */
2222 iovb
= alloc_skb(NS_IOVBUFSIZE
, GFP_ATOMIC
);
2225 printk("nicstar%d: Out of iovec buffers.\n", card
->index
);
2226 atomic_inc(&vcc
->stats
->rx_drop
);
2227 recycle_rx_buf(card
, skb
);
2232 if (--card
->iovpool
.count
< card
->iovnr
.min
)
2234 struct sk_buff
*new_iovb
;
2235 if ((new_iovb
= alloc_skb(NS_IOVBUFSIZE
, GFP_ATOMIC
)) != NULL
)
2237 skb_queue_tail(&card
->iovpool
.queue
, new_iovb
);
2238 card
->iovpool
.count
++;
2242 NS_SKB(iovb
)->iovcnt
= 0;
2244 iovb
->tail
= iovb
->data
= iovb
->head
;
2245 NS_SKB(iovb
)->vcc
= vcc
;
2246 /* IMPORTANT: a pointer to the sk_buff containing the small or large
2247 buffer is stored as iovec base, NOT a pointer to the
2248 small or large buffer itself. */
2250 else if (NS_SKB(iovb
)->iovcnt
>= NS_MAX_IOVECS
)
2252 printk("nicstar%d: received too big AAL5 SDU.\n", card
->index
);
2253 atomic_inc(&vcc
->stats
->rx_err
);
2254 recycle_iovec_rx_bufs(card
, (struct iovec
*) iovb
->data
, NS_MAX_IOVECS
);
2255 NS_SKB(iovb
)->iovcnt
= 0;
2257 iovb
->tail
= iovb
->data
= iovb
->head
;
2258 NS_SKB(iovb
)->vcc
= vcc
;
2260 iov
= &((struct iovec
*) iovb
->data
)[NS_SKB(iovb
)->iovcnt
++];
2261 iov
->iov_base
= (void *) skb
;
2262 iov
->iov_len
= ns_rsqe_cellcount(rsqe
) * 48;
2263 iovb
->len
+= iov
->iov_len
;
2265 if (NS_SKB(iovb
)->iovcnt
== 1)
2267 if (skb
->list
!= &card
->sbpool
.queue
)
2269 printk("nicstar%d: Expected a small buffer, and this is not one.\n",
2271 which_list(card
, skb
);
2272 atomic_inc(&vcc
->stats
->rx_err
);
2273 recycle_rx_buf(card
, skb
);
2275 recycle_iov_buf(card
, iovb
);
2279 else /* NS_SKB(iovb)->iovcnt >= 2 */
2281 if (skb
->list
!= &card
->lbpool
.queue
)
2283 printk("nicstar%d: Expected a large buffer, and this is not one.\n",
2285 which_list(card
, skb
);
2286 atomic_inc(&vcc
->stats
->rx_err
);
2287 recycle_iovec_rx_bufs(card
, (struct iovec
*) iovb
->data
,
2288 NS_SKB(iovb
)->iovcnt
);
2290 recycle_iov_buf(card
, iovb
);
2295 if (ns_rsqe_eopdu(rsqe
))
2297 /* This works correctly regardless of the endianness of the host */
2298 unsigned char *L1L2
= (unsigned char *)((u32
)skb
->data
+
2300 aal5_len
= L1L2
[0] << 8 | L1L2
[1];
2301 len
= (aal5_len
== 0x0000) ? 0x10000 : aal5_len
;
2302 if (ns_rsqe_crcerr(rsqe
) ||
2303 len
+ 8 > iovb
->len
|| len
+ (47 + 8) < iovb
->len
)
2305 printk("nicstar%d: AAL5 CRC error", card
->index
);
2306 if (len
+ 8 > iovb
->len
|| len
+ (47 + 8) < iovb
->len
)
2307 printk(" - PDU size mismatch.\n");
2310 atomic_inc(&vcc
->stats
->rx_err
);
2311 recycle_iovec_rx_bufs(card
, (struct iovec
*) iovb
->data
,
2312 NS_SKB(iovb
)->iovcnt
);
2314 recycle_iov_buf(card
, iovb
);
2318 /* By this point we (hopefully) have a complete SDU without errors. */
2320 if (NS_SKB(iovb
)->iovcnt
== 1) /* Just a small buffer */
2322 /* skb points to a small buffer */
2323 if (!atm_charge(vcc
, skb
->truesize
))
2325 push_rxbufs(card
, BUF_SM
, (u32
) skb
, (u32
) virt_to_bus(skb
->data
),
2327 atomic_inc(&vcc
->stats
->rx_drop
);
2332 dequeue_sm_buf(card
, skb
);
2333 #ifdef NS_USE_DESTRUCTORS
2334 skb
->destructor
= ns_sb_destructor
;
2335 #endif /* NS_USE_DESTRUCTORS */
2336 ATM_SKB(skb
)->vcc
= vcc
;
2337 do_gettimeofday(&skb
->stamp
);
2338 vcc
->push(vcc
, skb
);
2339 atomic_inc(&vcc
->stats
->rx
);
2342 else if (NS_SKB(iovb
)->iovcnt
== 2) /* One small plus one large buffer */
2346 sb
= (struct sk_buff
*) (iov
- 1)->iov_base
;
2347 /* skb points to a large buffer */
2349 if (len
<= NS_SMBUFSIZE
)
2351 if (!atm_charge(vcc
, sb
->truesize
))
2353 push_rxbufs(card
, BUF_SM
, (u32
) sb
, (u32
) virt_to_bus(sb
->data
),
2355 atomic_inc(&vcc
->stats
->rx_drop
);
2360 dequeue_sm_buf(card
, sb
);
2361 #ifdef NS_USE_DESTRUCTORS
2362 sb
->destructor
= ns_sb_destructor
;
2363 #endif /* NS_USE_DESTRUCTORS */
2364 ATM_SKB(sb
)->vcc
= vcc
;
2365 do_gettimeofday(&sb
->stamp
);
2367 atomic_inc(&vcc
->stats
->rx
);
2370 push_rxbufs(card
, BUF_LG
, (u32
) skb
,
2371 (u32
) virt_to_bus(skb
->data
), 0, 0);
2374 else /* len > NS_SMBUFSIZE, the usual case */
2376 if (!atm_charge(vcc
, skb
->truesize
))
2378 push_rxbufs(card
, BUF_LG
, (u32
) skb
,
2379 (u32
) virt_to_bus(skb
->data
), 0, 0);
2380 atomic_inc(&vcc
->stats
->rx_drop
);
2384 dequeue_lg_buf(card
, skb
);
2385 #ifdef NS_USE_DESTRUCTORS
2386 skb
->destructor
= ns_lb_destructor
;
2387 #endif /* NS_USE_DESTRUCTORS */
2388 skb_push(skb
, NS_SMBUFSIZE
);
2389 memcpy(skb
->data
, sb
->data
, NS_SMBUFSIZE
);
2390 skb_put(skb
, len
- NS_SMBUFSIZE
);
2391 ATM_SKB(skb
)->vcc
= vcc
;
2392 do_gettimeofday(&skb
->stamp
);
2393 vcc
->push(vcc
, skb
);
2394 atomic_inc(&vcc
->stats
->rx
);
2397 push_rxbufs(card
, BUF_SM
, (u32
) sb
, (u32
) virt_to_bus(sb
->data
),
2403 else /* Must push a huge buffer */
2405 struct sk_buff
*hb
, *sb
, *lb
;
2406 int remaining
, tocopy
;
2409 hb
= skb_dequeue(&(card
->hbpool
.queue
));
2410 if (hb
== NULL
) /* No buffers in the queue */
2413 hb
= dev_alloc_skb(NS_HBUFSIZE
);
2416 printk("nicstar%d: Out of huge buffers.\n", card
->index
);
2417 atomic_inc(&vcc
->stats
->rx_drop
);
2418 recycle_iovec_rx_bufs(card
, (struct iovec
*) iovb
->data
,
2419 NS_SKB(iovb
)->iovcnt
);
2421 recycle_iov_buf(card
, iovb
);
2424 else if (card
->hbpool
.count
< card
->hbnr
.min
)
2426 struct sk_buff
*new_hb
;
2427 if ((new_hb
= dev_alloc_skb(NS_HBUFSIZE
)) != NULL
)
2429 skb_queue_tail(&card
->hbpool
.queue
, new_hb
);
2430 card
->hbpool
.count
++;
2435 if (--card
->hbpool
.count
< card
->hbnr
.min
)
2437 struct sk_buff
*new_hb
;
2438 if ((new_hb
= dev_alloc_skb(NS_HBUFSIZE
)) != NULL
)
2440 skb_queue_tail(&card
->hbpool
.queue
, new_hb
);
2441 card
->hbpool
.count
++;
2443 if (card
->hbpool
.count
< card
->hbnr
.min
)
2445 if ((new_hb
= dev_alloc_skb(NS_HBUFSIZE
)) != NULL
)
2447 skb_queue_tail(&card
->hbpool
.queue
, new_hb
);
2448 card
->hbpool
.count
++;
2453 iov
= (struct iovec
*) iovb
->data
;
2455 if (!atm_charge(vcc
, hb
->truesize
))
2457 recycle_iovec_rx_bufs(card
, iov
, NS_SKB(iovb
)->iovcnt
);
2458 if (card
->hbpool
.count
< card
->hbnr
.max
)
2460 skb_queue_tail(&card
->hbpool
.queue
, hb
);
2461 card
->hbpool
.count
++;
2464 dev_kfree_skb_any(hb
);
2465 atomic_inc(&vcc
->stats
->rx_drop
);
2469 /* Copy the small buffer to the huge buffer */
2470 sb
= (struct sk_buff
*) iov
->iov_base
;
2471 memcpy(hb
->data
, sb
->data
, iov
->iov_len
);
2472 skb_put(hb
, iov
->iov_len
);
2473 remaining
= len
- iov
->iov_len
;
2475 /* Free the small buffer */
2476 push_rxbufs(card
, BUF_SM
, (u32
) sb
, (u32
) virt_to_bus(sb
->data
),
2479 /* Copy all large buffers to the huge buffer and free them */
2480 for (j
= 1; j
< NS_SKB(iovb
)->iovcnt
; j
++)
2482 lb
= (struct sk_buff
*) iov
->iov_base
;
2483 tocopy
= min_t(int, remaining
, iov
->iov_len
);
2484 memcpy(hb
->tail
, lb
->data
, tocopy
);
2485 skb_put(hb
, tocopy
);
2487 remaining
-= tocopy
;
2488 push_rxbufs(card
, BUF_LG
, (u32
) lb
,
2489 (u32
) virt_to_bus(lb
->data
), 0, 0);
2492 if (remaining
!= 0 || hb
->len
!= len
)
2493 printk("nicstar%d: Huge buffer len mismatch.\n", card
->index
);
2494 #endif /* EXTRA_DEBUG */
2495 ATM_SKB(hb
)->vcc
= vcc
;
2496 #ifdef NS_USE_DESTRUCTORS
2497 hb
->destructor
= ns_hb_destructor
;
2498 #endif /* NS_USE_DESTRUCTORS */
2499 do_gettimeofday(&hb
->stamp
);
2501 atomic_inc(&vcc
->stats
->rx
);
2506 recycle_iov_buf(card
, iovb
);
2513 #ifdef NS_USE_DESTRUCTORS
2515 static void ns_sb_destructor(struct sk_buff
*sb
)
2520 card
= (ns_dev
*) ATM_SKB(sb
)->vcc
->dev
->dev_data
;
2521 stat
= readl(card
->membase
+ STAT
);
2522 card
->sbfqc
= ns_stat_sfbqc_get(stat
);
2523 card
->lbfqc
= ns_stat_lfbqc_get(stat
);
2527 sb
= __dev_alloc_skb(NS_SMSKBSIZE
, GFP_KERNEL
);
2530 skb_queue_tail(&card
->sbpool
.queue
, sb
);
2531 skb_reserve(sb
, NS_AAL0_HEADER
);
2532 push_rxbufs(card
, BUF_SM
, (u32
) sb
, (u32
) virt_to_bus(sb
->data
), 0, 0);
2533 } while (card
->sbfqc
< card
->sbnr
.min
);
2538 static void ns_lb_destructor(struct sk_buff
*lb
)
2543 card
= (ns_dev
*) ATM_SKB(lb
)->vcc
->dev
->dev_data
;
2544 stat
= readl(card
->membase
+ STAT
);
2545 card
->sbfqc
= ns_stat_sfbqc_get(stat
);
2546 card
->lbfqc
= ns_stat_lfbqc_get(stat
);
2550 lb
= __dev_alloc_skb(NS_LGSKBSIZE
, GFP_KERNEL
);
2553 skb_queue_tail(&card
->lbpool
.queue
, lb
);
2554 skb_reserve(lb
, NS_SMBUFSIZE
);
2555 push_rxbufs(card
, BUF_LG
, (u32
) lb
, (u32
) virt_to_bus(lb
->data
), 0, 0);
2556 } while (card
->lbfqc
< card
->lbnr
.min
);
2561 static void ns_hb_destructor(struct sk_buff
*hb
)
2565 card
= (ns_dev
*) ATM_SKB(hb
)->vcc
->dev
->dev_data
;
2567 while (card
->hbpool
.count
< card
->hbnr
.init
)
2569 hb
= __dev_alloc_skb(NS_HBUFSIZE
, GFP_KERNEL
);
2572 skb_queue_tail(&card
->hbpool
.queue
, hb
);
2573 card
->hbpool
.count
++;
2577 #endif /* NS_USE_DESTRUCTORS */
2581 static void recycle_rx_buf(ns_dev
*card
, struct sk_buff
*skb
)
2583 if (skb
->list
== &card
->sbpool
.queue
)
2584 push_rxbufs(card
, BUF_SM
, (u32
) skb
, (u32
) virt_to_bus(skb
->data
), 0, 0);
2585 else if (skb
->list
== &card
->lbpool
.queue
)
2586 push_rxbufs(card
, BUF_LG
, (u32
) skb
, (u32
) virt_to_bus(skb
->data
), 0, 0);
2589 printk("nicstar%d: What kind of rx buffer is this?\n", card
->index
);
2590 dev_kfree_skb_any(skb
);
2596 static void recycle_iovec_rx_bufs(ns_dev
*card
, struct iovec
*iov
, int count
)
2598 struct sk_buff
*skb
;
2600 for (; count
> 0; count
--)
2602 skb
= (struct sk_buff
*) (iov
++)->iov_base
;
2603 if (skb
->list
== &card
->sbpool
.queue
)
2604 push_rxbufs(card
, BUF_SM
, (u32
) skb
, (u32
) virt_to_bus(skb
->data
),
2606 else if (skb
->list
== &card
->lbpool
.queue
)
2607 push_rxbufs(card
, BUF_LG
, (u32
) skb
, (u32
) virt_to_bus(skb
->data
),
2611 printk("nicstar%d: What kind of rx buffer is this?\n", card
->index
);
2612 dev_kfree_skb_any(skb
);
2619 static void recycle_iov_buf(ns_dev
*card
, struct sk_buff
*iovb
)
2621 if (card
->iovpool
.count
< card
->iovnr
.max
)
2623 skb_queue_tail(&card
->iovpool
.queue
, iovb
);
2624 card
->iovpool
.count
++;
2627 dev_kfree_skb_any(iovb
);
2632 static void dequeue_sm_buf(ns_dev
*card
, struct sk_buff
*sb
)
2635 #ifdef NS_USE_DESTRUCTORS
2636 if (card
->sbfqc
< card
->sbnr
.min
)
2638 if (card
->sbfqc
< card
->sbnr
.init
)
2640 struct sk_buff
*new_sb
;
2641 if ((new_sb
= dev_alloc_skb(NS_SMSKBSIZE
)) != NULL
)
2643 skb_queue_tail(&card
->sbpool
.queue
, new_sb
);
2644 skb_reserve(new_sb
, NS_AAL0_HEADER
);
2645 push_rxbufs(card
, BUF_SM
, (u32
) new_sb
,
2646 (u32
) virt_to_bus(new_sb
->data
), 0, 0);
2649 if (card
->sbfqc
< card
->sbnr
.init
)
2650 #endif /* NS_USE_DESTRUCTORS */
2652 struct sk_buff
*new_sb
;
2653 if ((new_sb
= dev_alloc_skb(NS_SMSKBSIZE
)) != NULL
)
2655 skb_queue_tail(&card
->sbpool
.queue
, new_sb
);
2656 skb_reserve(new_sb
, NS_AAL0_HEADER
);
2657 push_rxbufs(card
, BUF_SM
, (u32
) new_sb
,
2658 (u32
) virt_to_bus(new_sb
->data
), 0, 0);
2665 static void dequeue_lg_buf(ns_dev
*card
, struct sk_buff
*lb
)
2668 #ifdef NS_USE_DESTRUCTORS
2669 if (card
->lbfqc
< card
->lbnr
.min
)
2671 if (card
->lbfqc
< card
->lbnr
.init
)
2673 struct sk_buff
*new_lb
;
2674 if ((new_lb
= dev_alloc_skb(NS_LGSKBSIZE
)) != NULL
)
2676 skb_queue_tail(&card
->lbpool
.queue
, new_lb
);
2677 skb_reserve(new_lb
, NS_SMBUFSIZE
);
2678 push_rxbufs(card
, BUF_LG
, (u32
) new_lb
,
2679 (u32
) virt_to_bus(new_lb
->data
), 0, 0);
2682 if (card
->lbfqc
< card
->lbnr
.init
)
2683 #endif /* NS_USE_DESTRUCTORS */
2685 struct sk_buff
*new_lb
;
2686 if ((new_lb
= dev_alloc_skb(NS_LGSKBSIZE
)) != NULL
)
2688 skb_queue_tail(&card
->lbpool
.queue
, new_lb
);
2689 skb_reserve(new_lb
, NS_SMBUFSIZE
);
2690 push_rxbufs(card
, BUF_LG
, (u32
) new_lb
,
2691 (u32
) virt_to_bus(new_lb
->data
), 0, 0);
2698 static int ns_proc_read(struct atm_dev
*dev
, loff_t
*pos
, char *page
)
2705 card
= (ns_dev
*) dev
->dev_data
;
2706 stat
= readl(card
->membase
+ STAT
);
2708 return sprintf(page
, "Pool count min init max \n");
2710 return sprintf(page
, "Small %5d %5d %5d %5d \n",
2711 ns_stat_sfbqc_get(stat
), card
->sbnr
.min
, card
->sbnr
.init
,
2714 return sprintf(page
, "Large %5d %5d %5d %5d \n",
2715 ns_stat_lfbqc_get(stat
), card
->lbnr
.min
, card
->lbnr
.init
,
2718 return sprintf(page
, "Huge %5d %5d %5d %5d \n", card
->hbpool
.count
,
2719 card
->hbnr
.min
, card
->hbnr
.init
, card
->hbnr
.max
);
2721 return sprintf(page
, "Iovec %5d %5d %5d %5d \n", card
->iovpool
.count
,
2722 card
->iovnr
.min
, card
->iovnr
.init
, card
->iovnr
.max
);
2726 retval
= sprintf(page
, "Interrupt counter: %u \n", card
->intcnt
);
2731 /* Dump 25.6 Mbps PHY registers */
2732 /* Now there's a 25.6 Mbps PHY driver this code isn't needed. I left it
2733 here just in case it's needed for debugging. */
2734 if (card
->max_pcr
== ATM_25_PCR
&& !left
--)
2739 for (i
= 0; i
< 4; i
++)
2741 while (CMD_BUSY(card
));
2742 writel(NS_CMD_READ_UTILITY
| 0x00000200 | i
, card
->membase
+ CMD
);
2743 while (CMD_BUSY(card
));
2744 phy_regs
[i
] = readl(card
->membase
+ DR0
) & 0x000000FF;
2747 return sprintf(page
, "PHY regs: 0x%02X 0x%02X 0x%02X 0x%02X \n",
2748 phy_regs
[0], phy_regs
[1], phy_regs
[2], phy_regs
[3]);
2750 #endif /* 0 - Dump 25.6 Mbps PHY registers */
2753 if (left
-- < NS_TST_NUM_ENTRIES
)
2755 if (card
->tste2vc
[left
+ 1] == NULL
)
2756 return sprintf(page
, "%5d - VBR/UBR \n", left
+ 1);
2758 return sprintf(page
, "%5d - %d %d \n", left
+ 1,
2759 card
->tste2vc
[left
+ 1]->tx_vcc
->vpi
,
2760 card
->tste2vc
[left
+ 1]->tx_vcc
->vci
);
2768 static int ns_ioctl(struct atm_dev
*dev
, unsigned int cmd
, void __user
*arg
)
2773 unsigned long flags
;
2775 card
= dev
->dev_data
;
2779 if (get_user(pl
.buftype
, &((pool_levels __user
*) arg
)->buftype
))
2783 case NS_BUFTYPE_SMALL
:
2784 pl
.count
= ns_stat_sfbqc_get(readl(card
->membase
+ STAT
));
2785 pl
.level
.min
= card
->sbnr
.min
;
2786 pl
.level
.init
= card
->sbnr
.init
;
2787 pl
.level
.max
= card
->sbnr
.max
;
2790 case NS_BUFTYPE_LARGE
:
2791 pl
.count
= ns_stat_lfbqc_get(readl(card
->membase
+ STAT
));
2792 pl
.level
.min
= card
->lbnr
.min
;
2793 pl
.level
.init
= card
->lbnr
.init
;
2794 pl
.level
.max
= card
->lbnr
.max
;
2797 case NS_BUFTYPE_HUGE
:
2798 pl
.count
= card
->hbpool
.count
;
2799 pl
.level
.min
= card
->hbnr
.min
;
2800 pl
.level
.init
= card
->hbnr
.init
;
2801 pl
.level
.max
= card
->hbnr
.max
;
2804 case NS_BUFTYPE_IOVEC
:
2805 pl
.count
= card
->iovpool
.count
;
2806 pl
.level
.min
= card
->iovnr
.min
;
2807 pl
.level
.init
= card
->iovnr
.init
;
2808 pl
.level
.max
= card
->iovnr
.max
;
2812 return -ENOIOCTLCMD
;
2815 if (!copy_to_user((pool_levels __user
*) arg
, &pl
, sizeof(pl
)))
2816 return (sizeof(pl
));
2821 if (!capable(CAP_NET_ADMIN
))
2823 if (copy_from_user(&pl
, (pool_levels __user
*) arg
, sizeof(pl
)))
2825 if (pl
.level
.min
>= pl
.level
.init
|| pl
.level
.init
>= pl
.level
.max
)
2827 if (pl
.level
.min
== 0)
2831 case NS_BUFTYPE_SMALL
:
2832 if (pl
.level
.max
> TOP_SB
)
2834 card
->sbnr
.min
= pl
.level
.min
;
2835 card
->sbnr
.init
= pl
.level
.init
;
2836 card
->sbnr
.max
= pl
.level
.max
;
2839 case NS_BUFTYPE_LARGE
:
2840 if (pl
.level
.max
> TOP_LB
)
2842 card
->lbnr
.min
= pl
.level
.min
;
2843 card
->lbnr
.init
= pl
.level
.init
;
2844 card
->lbnr
.max
= pl
.level
.max
;
2847 case NS_BUFTYPE_HUGE
:
2848 if (pl
.level
.max
> TOP_HB
)
2850 card
->hbnr
.min
= pl
.level
.min
;
2851 card
->hbnr
.init
= pl
.level
.init
;
2852 card
->hbnr
.max
= pl
.level
.max
;
2855 case NS_BUFTYPE_IOVEC
:
2856 if (pl
.level
.max
> TOP_IOVB
)
2858 card
->iovnr
.min
= pl
.level
.min
;
2859 card
->iovnr
.init
= pl
.level
.init
;
2860 card
->iovnr
.max
= pl
.level
.max
;
2870 if (!capable(CAP_NET_ADMIN
))
2872 btype
= (int) arg
; /* an int is the same size as a pointer */
2875 case NS_BUFTYPE_SMALL
:
2876 while (card
->sbfqc
< card
->sbnr
.init
)
2880 sb
= __dev_alloc_skb(NS_SMSKBSIZE
, GFP_KERNEL
);
2883 skb_queue_tail(&card
->sbpool
.queue
, sb
);
2884 skb_reserve(sb
, NS_AAL0_HEADER
);
2885 push_rxbufs(card
, BUF_SM
, (u32
) sb
, (u32
) virt_to_bus(sb
->data
), 0, 0);
2889 case NS_BUFTYPE_LARGE
:
2890 while (card
->lbfqc
< card
->lbnr
.init
)
2894 lb
= __dev_alloc_skb(NS_LGSKBSIZE
, GFP_KERNEL
);
2897 skb_queue_tail(&card
->lbpool
.queue
, lb
);
2898 skb_reserve(lb
, NS_SMBUFSIZE
);
2899 push_rxbufs(card
, BUF_LG
, (u32
) lb
, (u32
) virt_to_bus(lb
->data
), 0, 0);
2903 case NS_BUFTYPE_HUGE
:
2904 while (card
->hbpool
.count
> card
->hbnr
.init
)
2908 ns_grab_int_lock(card
, flags
);
2909 hb
= skb_dequeue(&card
->hbpool
.queue
);
2910 card
->hbpool
.count
--;
2911 spin_unlock_irqrestore(&card
->int_lock
, flags
);
2913 printk("nicstar%d: huge buffer count inconsistent.\n",
2916 dev_kfree_skb_any(hb
);
2919 while (card
->hbpool
.count
< card
->hbnr
.init
)
2923 hb
= __dev_alloc_skb(NS_HBUFSIZE
, GFP_KERNEL
);
2926 ns_grab_int_lock(card
, flags
);
2927 skb_queue_tail(&card
->hbpool
.queue
, hb
);
2928 card
->hbpool
.count
++;
2929 spin_unlock_irqrestore(&card
->int_lock
, flags
);
2933 case NS_BUFTYPE_IOVEC
:
2934 while (card
->iovpool
.count
> card
->iovnr
.init
)
2936 struct sk_buff
*iovb
;
2938 ns_grab_int_lock(card
, flags
);
2939 iovb
= skb_dequeue(&card
->iovpool
.queue
);
2940 card
->iovpool
.count
--;
2941 spin_unlock_irqrestore(&card
->int_lock
, flags
);
2943 printk("nicstar%d: iovec buffer count inconsistent.\n",
2946 dev_kfree_skb_any(iovb
);
2949 while (card
->iovpool
.count
< card
->iovnr
.init
)
2951 struct sk_buff
*iovb
;
2953 iovb
= alloc_skb(NS_IOVBUFSIZE
, GFP_KERNEL
);
2956 ns_grab_int_lock(card
, flags
);
2957 skb_queue_tail(&card
->iovpool
.queue
, iovb
);
2958 card
->iovpool
.count
++;
2959 spin_unlock_irqrestore(&card
->int_lock
, flags
);
2970 if (dev
->phy
&& dev
->phy
->ioctl
) {
2971 return dev
->phy
->ioctl(dev
, cmd
, arg
);
2974 printk("nicstar%d: %s == NULL \n", card
->index
,
2975 dev
->phy
? "dev->phy->ioctl" : "dev->phy");
2976 return -ENOIOCTLCMD
;
2983 static void which_list(ns_dev
*card
, struct sk_buff
*skb
)
2985 printk("It's a %s buffer.\n", skb
->list
== &card
->sbpool
.queue
?
2986 "small" : skb
->list
== &card
->lbpool
.queue
? "large" :
2987 skb
->list
== &card
->hbpool
.queue
? "huge" :
2988 skb
->list
== &card
->iovpool
.queue
? "iovec" : "unknown");
2993 static void ns_poll(unsigned long arg
)
2997 unsigned long flags
;
3000 PRINTK("nicstar: Entering ns_poll().\n");
3001 for (i
= 0; i
< num_cards
; i
++)
3004 if (spin_is_locked(&card
->int_lock
)) {
3005 /* Probably it isn't worth spinning */
3008 ns_grab_int_lock(card
, flags
);
3011 stat_r
= readl(card
->membase
+ STAT
);
3012 if (stat_r
& NS_STAT_TSIF
)
3013 stat_w
|= NS_STAT_TSIF
;
3014 if (stat_r
& NS_STAT_EOPDU
)
3015 stat_w
|= NS_STAT_EOPDU
;
3020 writel(stat_w
, card
->membase
+ STAT
);
3021 spin_unlock_irqrestore(&card
->int_lock
, flags
);
3023 mod_timer(&ns_timer
, jiffies
+ NS_POLL_PERIOD
);
3024 PRINTK("nicstar: Leaving ns_poll().\n");
3029 static int ns_parse_mac(char *mac
, unsigned char *esi
)
3034 if (mac
== NULL
|| esi
== NULL
)
3037 for (i
= 0; i
< 6; i
++)
3039 if ((byte1
= ns_h2i(mac
[j
++])) < 0)
3041 if ((byte0
= ns_h2i(mac
[j
++])) < 0)
3043 esi
[i
] = (unsigned char) (byte1
* 16 + byte0
);
3046 if (mac
[j
++] != ':')
3055 static short ns_h2i(char c
)
3057 if (c
>= '0' && c
<= '9')
3058 return (short) (c
- '0');
3059 if (c
>= 'A' && c
<= 'F')
3060 return (short) (c
- 'A' + 10);
3061 if (c
>= 'a' && c
<= 'f')
3062 return (short) (c
- 'a' + 10);
3068 static void ns_phy_put(struct atm_dev
*dev
, unsigned char value
,
3072 unsigned long flags
;
3074 card
= dev
->dev_data
;
3075 ns_grab_res_lock(card
, flags
);
3076 while(CMD_BUSY(card
));
3077 writel((unsigned long) value
, card
->membase
+ DR0
);
3078 writel(NS_CMD_WRITE_UTILITY
| 0x00000200 | (addr
& 0x000000FF),
3079 card
->membase
+ CMD
);
3080 spin_unlock_irqrestore(&card
->res_lock
, flags
);
3085 static unsigned char ns_phy_get(struct atm_dev
*dev
, unsigned long addr
)
3088 unsigned long flags
;
3091 card
= dev
->dev_data
;
3092 ns_grab_res_lock(card
, flags
);
3093 while(CMD_BUSY(card
));
3094 writel(NS_CMD_READ_UTILITY
| 0x00000200 | (addr
& 0x000000FF),
3095 card
->membase
+ CMD
);
3096 while(CMD_BUSY(card
));
3097 data
= readl(card
->membase
+ DR0
) & 0x000000FF;
3098 spin_unlock_irqrestore(&card
->res_lock
, flags
);
3099 return (unsigned char) data
;
3104 module_init(nicstar_init
);
3105 module_exit(nicstar_cleanup
);