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/kernel.h>
40 #include <linux/skbuff.h>
41 #include <linux/atmdev.h>
42 #include <linux/atm.h>
43 #include <linux/pci.h>
44 #include <linux/types.h>
45 #include <linux/string.h>
46 #include <linux/delay.h>
47 #include <linux/init.h>
48 #include <linux/sched.h>
49 #include <linux/timer.h>
50 #include <linux/interrupt.h>
51 #include <linux/bitops.h>
53 #include <asm/uaccess.h>
54 #include <asm/atomic.h>
56 #ifdef CONFIG_ATM_NICSTAR_USE_SUNI
58 #endif /* CONFIG_ATM_NICSTAR_USE_SUNI */
59 #ifdef CONFIG_ATM_NICSTAR_USE_IDT77105
61 #endif /* CONFIG_ATM_NICSTAR_USE_IDT77105 */
63 #if BITS_PER_LONG != 32
64 # error FIXME: this driver requires a 32-bit platform
67 /* Additional code ************************************************************/
69 #include "nicstarmac.c"
72 /* Configurable parameters ****************************************************/
80 #undef NS_USE_DESTRUCTORS /* For now keep this undefined unless you know
81 you're going to use only raw ATM */
84 /* Do not touch these *********************************************************/
87 #define TXPRINTK(args...) printk(args)
89 #define TXPRINTK(args...)
93 #define RXPRINTK(args...) printk(args)
95 #define RXPRINTK(args...)
99 #define PRINTK(args...) printk(args)
101 #define PRINTK(args...)
102 #endif /* GENERAL_DEBUG */
105 #define XPRINTK(args...) printk(args)
107 #define XPRINTK(args...)
108 #endif /* EXTRA_DEBUG */
111 /* Macros *********************************************************************/
113 #define CMD_BUSY(card) (readl((card)->membase + STAT) & NS_STAT_CMDBZ)
115 #define NS_DELAY mdelay(1)
117 #define ALIGN_BUS_ADDR(addr, alignment) \
118 ((((u32) (addr)) + (((u32) (alignment)) - 1)) & ~(((u32) (alignment)) - 1))
119 #define ALIGN_ADDRESS(addr, alignment) \
120 bus_to_virt(ALIGN_BUS_ADDR(virt_to_bus(addr), alignment))
125 #define ATM_SKB(s) (&(s)->atm)
129 /* Function declarations ******************************************************/
131 static u32
ns_read_sram(ns_dev
*card
, u32 sram_address
);
132 static void ns_write_sram(ns_dev
*card
, u32 sram_address
, u32
*value
, int count
);
133 static int __devinit
ns_init_card(int i
, struct pci_dev
*pcidev
);
134 static void __devinit
ns_init_card_error(ns_dev
*card
, int error
);
135 static scq_info
*get_scq(int size
, u32 scd
);
136 static void free_scq(scq_info
*scq
, struct atm_vcc
*vcc
);
137 static void push_rxbufs(ns_dev
*, struct sk_buff
*);
138 static irqreturn_t
ns_irq_handler(int irq
, void *dev_id
);
139 static int ns_open(struct atm_vcc
*vcc
);
140 static void ns_close(struct atm_vcc
*vcc
);
141 static void fill_tst(ns_dev
*card
, int n
, vc_map
*vc
);
142 static int ns_send(struct atm_vcc
*vcc
, struct sk_buff
*skb
);
143 static int push_scqe(ns_dev
*card
, vc_map
*vc
, scq_info
*scq
, ns_scqe
*tbd
,
144 struct sk_buff
*skb
);
145 static void process_tsq(ns_dev
*card
);
146 static void drain_scq(ns_dev
*card
, scq_info
*scq
, int pos
);
147 static void process_rsq(ns_dev
*card
);
148 static void dequeue_rx(ns_dev
*card
, ns_rsqe
*rsqe
);
149 #ifdef NS_USE_DESTRUCTORS
150 static void ns_sb_destructor(struct sk_buff
*sb
);
151 static void ns_lb_destructor(struct sk_buff
*lb
);
152 static void ns_hb_destructor(struct sk_buff
*hb
);
153 #endif /* NS_USE_DESTRUCTORS */
154 static void recycle_rx_buf(ns_dev
*card
, struct sk_buff
*skb
);
155 static void recycle_iovec_rx_bufs(ns_dev
*card
, struct iovec
*iov
, int count
);
156 static void recycle_iov_buf(ns_dev
*card
, struct sk_buff
*iovb
);
157 static void dequeue_sm_buf(ns_dev
*card
, struct sk_buff
*sb
);
158 static void dequeue_lg_buf(ns_dev
*card
, struct sk_buff
*lb
);
159 static int ns_proc_read(struct atm_dev
*dev
, loff_t
*pos
, char *page
);
160 static int ns_ioctl(struct atm_dev
*dev
, unsigned int cmd
, void __user
*arg
);
161 static void which_list(ns_dev
*card
, struct sk_buff
*skb
);
162 static void ns_poll(unsigned long arg
);
163 static int ns_parse_mac(char *mac
, unsigned char *esi
);
164 static short ns_h2i(char c
);
165 static void ns_phy_put(struct atm_dev
*dev
, unsigned char value
,
167 static unsigned char ns_phy_get(struct atm_dev
*dev
, unsigned long addr
);
171 /* Global variables ***********************************************************/
173 static struct ns_dev
*cards
[NS_MAX_CARDS
];
174 static unsigned num_cards
;
175 static struct atmdev_ops atm_ops
=
181 .phy_put
= ns_phy_put
,
182 .phy_get
= ns_phy_get
,
183 .proc_read
= ns_proc_read
,
184 .owner
= THIS_MODULE
,
186 static struct timer_list ns_timer
;
187 static char *mac
[NS_MAX_CARDS
];
188 module_param_array(mac
, charp
, NULL
, 0);
189 MODULE_LICENSE("GPL");
192 /* Functions*******************************************************************/
194 static int __devinit
nicstar_init_one(struct pci_dev
*pcidev
,
195 const struct pci_device_id
*ent
)
197 static int index
= -1;
203 error
= ns_init_card(index
, pcidev
);
205 cards
[index
--] = NULL
; /* don't increment index */
216 static void __devexit
nicstar_remove_one(struct pci_dev
*pcidev
)
219 ns_dev
*card
= pci_get_drvdata(pcidev
);
221 struct sk_buff
*iovb
;
227 if (cards
[i
] == NULL
)
230 if (card
->atmdev
->phy
&& card
->atmdev
->phy
->stop
)
231 card
->atmdev
->phy
->stop(card
->atmdev
);
233 /* Stop everything */
234 writel(0x00000000, card
->membase
+ CFG
);
236 /* De-register device */
237 atm_dev_deregister(card
->atmdev
);
239 /* Disable PCI device */
240 pci_disable_device(pcidev
);
242 /* Free up resources */
244 PRINTK("nicstar%d: freeing %d huge buffers.\n", i
, card
->hbpool
.count
);
245 while ((hb
= skb_dequeue(&card
->hbpool
.queue
)) != NULL
)
247 dev_kfree_skb_any(hb
);
250 PRINTK("nicstar%d: %d huge buffers freed.\n", i
, j
);
252 PRINTK("nicstar%d: freeing %d iovec buffers.\n", i
, card
->iovpool
.count
);
253 while ((iovb
= skb_dequeue(&card
->iovpool
.queue
)) != NULL
)
255 dev_kfree_skb_any(iovb
);
258 PRINTK("nicstar%d: %d iovec buffers freed.\n", i
, j
);
259 while ((lb
= skb_dequeue(&card
->lbpool
.queue
)) != NULL
)
260 dev_kfree_skb_any(lb
);
261 while ((sb
= skb_dequeue(&card
->sbpool
.queue
)) != NULL
)
262 dev_kfree_skb_any(sb
);
263 free_scq(card
->scq0
, NULL
);
264 for (j
= 0; j
< NS_FRSCD_NUM
; j
++)
266 if (card
->scd2vc
[j
] != NULL
)
267 free_scq(card
->scd2vc
[j
]->scq
, card
->scd2vc
[j
]->tx_vcc
);
269 kfree(card
->rsq
.org
);
270 kfree(card
->tsq
.org
);
271 free_irq(card
->pcidev
->irq
, card
);
272 iounmap(card
->membase
);
278 static struct pci_device_id nicstar_pci_tbl
[] __devinitdata
=
280 {PCI_VENDOR_ID_IDT
, PCI_DEVICE_ID_IDT_IDT77201
,
281 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
282 {0,} /* terminate list */
284 MODULE_DEVICE_TABLE(pci
, nicstar_pci_tbl
);
288 static struct pci_driver nicstar_driver
= {
290 .id_table
= nicstar_pci_tbl
,
291 .probe
= nicstar_init_one
,
292 .remove
= __devexit_p(nicstar_remove_one
),
297 static int __init
nicstar_init(void)
299 unsigned error
= 0; /* Initialized to remove compile warning */
301 XPRINTK("nicstar: nicstar_init() called.\n");
303 error
= pci_register_driver(&nicstar_driver
);
305 TXPRINTK("nicstar: TX debug enabled.\n");
306 RXPRINTK("nicstar: RX debug enabled.\n");
307 PRINTK("nicstar: General debug enabled.\n");
309 printk("nicstar: using PHY loopback.\n");
310 #endif /* PHY_LOOPBACK */
311 XPRINTK("nicstar: nicstar_init() returned.\n");
314 init_timer(&ns_timer
);
315 ns_timer
.expires
= jiffies
+ NS_POLL_PERIOD
;
317 ns_timer
.function
= ns_poll
;
318 add_timer(&ns_timer
);
326 static void __exit
nicstar_cleanup(void)
328 XPRINTK("nicstar: nicstar_cleanup() called.\n");
330 del_timer(&ns_timer
);
332 pci_unregister_driver(&nicstar_driver
);
334 XPRINTK("nicstar: nicstar_cleanup() returned.\n");
339 static u32
ns_read_sram(ns_dev
*card
, u32 sram_address
)
344 sram_address
&= 0x0007FFFC; /* address must be dword aligned */
345 sram_address
|= 0x50000000; /* SRAM read command */
346 spin_lock_irqsave(&card
->res_lock
, flags
);
347 while (CMD_BUSY(card
));
348 writel(sram_address
, card
->membase
+ CMD
);
349 while (CMD_BUSY(card
));
350 data
= readl(card
->membase
+ DR0
);
351 spin_unlock_irqrestore(&card
->res_lock
, flags
);
357 static void ns_write_sram(ns_dev
*card
, u32 sram_address
, u32
*value
, int count
)
361 count
--; /* count range now is 0..3 instead of 1..4 */
363 c
<<= 2; /* to use increments of 4 */
364 spin_lock_irqsave(&card
->res_lock
, flags
);
365 while (CMD_BUSY(card
));
366 for (i
= 0; i
<= c
; i
+= 4)
367 writel(*(value
++), card
->membase
+ i
);
368 /* Note: DR# registers are the first 4 dwords in nicstar's memspace,
369 so card->membase + DR0 == card->membase */
371 sram_address
&= 0x0007FFFC;
372 sram_address
|= (0x40000000 | count
);
373 writel(sram_address
, card
->membase
+ CMD
);
374 spin_unlock_irqrestore(&card
->res_lock
, flags
);
378 static int __devinit
ns_init_card(int i
, struct pci_dev
*pcidev
)
381 struct ns_dev
*card
= NULL
;
382 unsigned char pci_latency
;
388 unsigned long membase
;
392 if (pci_enable_device(pcidev
))
394 printk("nicstar%d: can't enable PCI device\n", i
);
396 ns_init_card_error(card
, error
);
400 if ((card
= kmalloc(sizeof(ns_dev
), GFP_KERNEL
)) == NULL
)
402 printk("nicstar%d: can't allocate memory for device structure.\n", i
);
404 ns_init_card_error(card
, error
);
408 spin_lock_init(&card
->int_lock
);
409 spin_lock_init(&card
->res_lock
);
411 pci_set_drvdata(pcidev
, card
);
415 card
->pcidev
= pcidev
;
416 membase
= pci_resource_start(pcidev
, 1);
417 card
->membase
= ioremap(membase
, NS_IOREMAP_SIZE
);
420 printk("nicstar%d: can't ioremap() membase.\n",i
);
422 ns_init_card_error(card
, error
);
425 PRINTK("nicstar%d: membase at 0x%x.\n", i
, card
->membase
);
427 pci_set_master(pcidev
);
429 if (pci_read_config_byte(pcidev
, PCI_LATENCY_TIMER
, &pci_latency
) != 0)
431 printk("nicstar%d: can't read PCI latency timer.\n", i
);
433 ns_init_card_error(card
, error
);
436 #ifdef NS_PCI_LATENCY
437 if (pci_latency
< NS_PCI_LATENCY
)
439 PRINTK("nicstar%d: setting PCI latency timer to %d.\n", i
, NS_PCI_LATENCY
);
440 for (j
= 1; j
< 4; j
++)
442 if (pci_write_config_byte(pcidev
, PCI_LATENCY_TIMER
, NS_PCI_LATENCY
) != 0)
447 printk("nicstar%d: can't set PCI latency timer to %d.\n", i
, NS_PCI_LATENCY
);
449 ns_init_card_error(card
, error
);
453 #endif /* NS_PCI_LATENCY */
455 /* Clear timer overflow */
456 data
= readl(card
->membase
+ STAT
);
457 if (data
& NS_STAT_TMROF
)
458 writel(NS_STAT_TMROF
, card
->membase
+ STAT
);
461 writel(NS_CFG_SWRST
, card
->membase
+ CFG
);
463 writel(0x00000000, card
->membase
+ CFG
);
466 writel(0x00000008, card
->membase
+ GP
);
468 writel(0x00000001, card
->membase
+ GP
);
470 while (CMD_BUSY(card
));
471 writel(NS_CMD_WRITE_UTILITY
| 0x00000100, card
->membase
+ CMD
); /* Sync UTOPIA with SAR clock */
474 /* Detect PHY type */
475 while (CMD_BUSY(card
));
476 writel(NS_CMD_READ_UTILITY
| 0x00000200, card
->membase
+ CMD
);
477 while (CMD_BUSY(card
));
478 data
= readl(card
->membase
+ DR0
);
481 printk("nicstar%d: PHY seems to be 25 Mbps.\n", i
);
482 card
->max_pcr
= ATM_25_PCR
;
483 while(CMD_BUSY(card
));
484 writel(0x00000008, card
->membase
+ DR0
);
485 writel(NS_CMD_WRITE_UTILITY
| 0x00000200, card
->membase
+ CMD
);
486 /* Clear an eventual pending interrupt */
487 writel(NS_STAT_SFBQF
, card
->membase
+ STAT
);
489 while(CMD_BUSY(card
));
490 writel(0x00000022, card
->membase
+ DR0
);
491 writel(NS_CMD_WRITE_UTILITY
| 0x00000202, card
->membase
+ CMD
);
492 #endif /* PHY_LOOPBACK */
496 printk("nicstar%d: PHY seems to be 155 Mbps.\n", i
);
497 card
->max_pcr
= ATM_OC3_PCR
;
499 while(CMD_BUSY(card
));
500 writel(0x00000002, card
->membase
+ DR0
);
501 writel(NS_CMD_WRITE_UTILITY
| 0x00000205, card
->membase
+ CMD
);
502 #endif /* PHY_LOOPBACK */
505 printk("nicstar%d: unknown PHY type (0x%08X).\n", i
, data
);
507 ns_init_card_error(card
, error
);
510 writel(0x00000000, card
->membase
+ GP
);
512 /* Determine SRAM size */
514 ns_write_sram(card
, 0x1C003, &data
, 1);
516 ns_write_sram(card
, 0x14003, &data
, 1);
517 if (ns_read_sram(card
, 0x14003) == 0x89ABCDEF &&
518 ns_read_sram(card
, 0x1C003) == 0x76543210)
519 card
->sram_size
= 128;
521 card
->sram_size
= 32;
522 PRINTK("nicstar%d: %dK x 32bit SRAM size.\n", i
, card
->sram_size
);
524 card
->rct_size
= NS_MAX_RCTSIZE
;
526 #if (NS_MAX_RCTSIZE == 4096)
527 if (card
->sram_size
== 128)
528 printk("nicstar%d: limiting maximum VCI. See NS_MAX_RCTSIZE in nicstar.h\n", i
);
529 #elif (NS_MAX_RCTSIZE == 16384)
530 if (card
->sram_size
== 32)
532 printk("nicstar%d: wasting memory. See NS_MAX_RCTSIZE in nicstar.h\n", i
);
533 card
->rct_size
= 4096;
536 #error NS_MAX_RCTSIZE must be either 4096 or 16384 in nicstar.c
539 card
->vpibits
= NS_VPIBITS
;
540 if (card
->rct_size
== 4096)
541 card
->vcibits
= 12 - NS_VPIBITS
;
542 else /* card->rct_size == 16384 */
543 card
->vcibits
= 14 - NS_VPIBITS
;
545 /* Initialize the nicstar eeprom/eprom stuff, for the MAC addr */
547 nicstar_init_eprom(card
->membase
);
549 /* Set the VPI/VCI MSb mask to zero so we can receive OAM cells */
550 writel(0x00000000, card
->membase
+ VPM
);
553 card
->tsq
.org
= kmalloc(NS_TSQSIZE
+ NS_TSQ_ALIGNMENT
, GFP_KERNEL
);
554 if (card
->tsq
.org
== NULL
)
556 printk("nicstar%d: can't allocate TSQ.\n", i
);
558 ns_init_card_error(card
, error
);
561 card
->tsq
.base
= (ns_tsi
*) ALIGN_ADDRESS(card
->tsq
.org
, NS_TSQ_ALIGNMENT
);
562 card
->tsq
.next
= card
->tsq
.base
;
563 card
->tsq
.last
= card
->tsq
.base
+ (NS_TSQ_NUM_ENTRIES
- 1);
564 for (j
= 0; j
< NS_TSQ_NUM_ENTRIES
; j
++)
565 ns_tsi_init(card
->tsq
.base
+ j
);
566 writel(0x00000000, card
->membase
+ TSQH
);
567 writel((u32
) virt_to_bus(card
->tsq
.base
), card
->membase
+ TSQB
);
568 PRINTK("nicstar%d: TSQ base at 0x%x 0x%x 0x%x.\n", i
, (u32
) card
->tsq
.base
,
569 (u32
) virt_to_bus(card
->tsq
.base
), readl(card
->membase
+ TSQB
));
572 card
->rsq
.org
= kmalloc(NS_RSQSIZE
+ NS_RSQ_ALIGNMENT
, GFP_KERNEL
);
573 if (card
->rsq
.org
== NULL
)
575 printk("nicstar%d: can't allocate RSQ.\n", i
);
577 ns_init_card_error(card
, error
);
580 card
->rsq
.base
= (ns_rsqe
*) ALIGN_ADDRESS(card
->rsq
.org
, NS_RSQ_ALIGNMENT
);
581 card
->rsq
.next
= card
->rsq
.base
;
582 card
->rsq
.last
= card
->rsq
.base
+ (NS_RSQ_NUM_ENTRIES
- 1);
583 for (j
= 0; j
< NS_RSQ_NUM_ENTRIES
; j
++)
584 ns_rsqe_init(card
->rsq
.base
+ j
);
585 writel(0x00000000, card
->membase
+ RSQH
);
586 writel((u32
) virt_to_bus(card
->rsq
.base
), card
->membase
+ RSQB
);
587 PRINTK("nicstar%d: RSQ base at 0x%x.\n", i
, (u32
) card
->rsq
.base
);
589 /* Initialize SCQ0, the only VBR SCQ used */
592 card
->scq0
= get_scq(VBR_SCQSIZE
, NS_VRSCD0
);
593 if (card
->scq0
== NULL
)
595 printk("nicstar%d: can't get SCQ0.\n", i
);
597 ns_init_card_error(card
, error
);
600 u32d
[0] = (u32
) virt_to_bus(card
->scq0
->base
);
601 u32d
[1] = (u32
) 0x00000000;
602 u32d
[2] = (u32
) 0xffffffff;
603 u32d
[3] = (u32
) 0x00000000;
604 ns_write_sram(card
, NS_VRSCD0
, u32d
, 4);
605 ns_write_sram(card
, NS_VRSCD1
, u32d
, 4); /* These last two won't be used */
606 ns_write_sram(card
, NS_VRSCD2
, u32d
, 4); /* but are initialized, just in case... */
607 card
->scq0
->scd
= NS_VRSCD0
;
608 PRINTK("nicstar%d: VBR-SCQ0 base at 0x%x.\n", i
, (u32
) card
->scq0
->base
);
610 /* Initialize TSTs */
611 card
->tst_addr
= NS_TST0
;
612 card
->tst_free_entries
= NS_TST_NUM_ENTRIES
;
613 data
= NS_TST_OPCODE_VARIABLE
;
614 for (j
= 0; j
< NS_TST_NUM_ENTRIES
; j
++)
615 ns_write_sram(card
, NS_TST0
+ j
, &data
, 1);
616 data
= ns_tste_make(NS_TST_OPCODE_END
, NS_TST0
);
617 ns_write_sram(card
, NS_TST0
+ NS_TST_NUM_ENTRIES
, &data
, 1);
618 for (j
= 0; j
< NS_TST_NUM_ENTRIES
; j
++)
619 ns_write_sram(card
, NS_TST1
+ j
, &data
, 1);
620 data
= ns_tste_make(NS_TST_OPCODE_END
, NS_TST1
);
621 ns_write_sram(card
, NS_TST1
+ NS_TST_NUM_ENTRIES
, &data
, 1);
622 for (j
= 0; j
< NS_TST_NUM_ENTRIES
; j
++)
623 card
->tste2vc
[j
] = NULL
;
624 writel(NS_TST0
<< 2, card
->membase
+ TSTB
);
627 /* Initialize RCT. AAL type is set on opening the VC. */
629 u32d
[0] = NS_RCTE_RAWCELLINTEN
;
631 u32d
[0] = 0x00000000;
632 #endif /* RCQ_SUPPORT */
633 u32d
[1] = 0x00000000;
634 u32d
[2] = 0x00000000;
635 u32d
[3] = 0xFFFFFFFF;
636 for (j
= 0; j
< card
->rct_size
; j
++)
637 ns_write_sram(card
, j
* 4, u32d
, 4);
639 memset(card
->vcmap
, 0, NS_MAX_RCTSIZE
* sizeof(vc_map
));
641 for (j
= 0; j
< NS_FRSCD_NUM
; j
++)
642 card
->scd2vc
[j
] = NULL
;
644 /* Initialize buffer levels */
645 card
->sbnr
.min
= MIN_SB
;
646 card
->sbnr
.init
= NUM_SB
;
647 card
->sbnr
.max
= MAX_SB
;
648 card
->lbnr
.min
= MIN_LB
;
649 card
->lbnr
.init
= NUM_LB
;
650 card
->lbnr
.max
= MAX_LB
;
651 card
->iovnr
.min
= MIN_IOVB
;
652 card
->iovnr
.init
= NUM_IOVB
;
653 card
->iovnr
.max
= MAX_IOVB
;
654 card
->hbnr
.min
= MIN_HB
;
655 card
->hbnr
.init
= NUM_HB
;
656 card
->hbnr
.max
= MAX_HB
;
658 card
->sm_handle
= 0x00000000;
659 card
->sm_addr
= 0x00000000;
660 card
->lg_handle
= 0x00000000;
661 card
->lg_addr
= 0x00000000;
663 card
->efbie
= 1; /* To prevent push_rxbufs from enabling the interrupt */
665 /* Pre-allocate some huge buffers */
666 skb_queue_head_init(&card
->hbpool
.queue
);
667 card
->hbpool
.count
= 0;
668 for (j
= 0; j
< NUM_HB
; j
++)
671 hb
= __dev_alloc_skb(NS_HBUFSIZE
, GFP_KERNEL
);
674 printk("nicstar%d: can't allocate %dth of %d huge buffers.\n",
677 ns_init_card_error(card
, error
);
680 NS_SKB_CB(hb
)->buf_type
= BUF_NONE
;
681 skb_queue_tail(&card
->hbpool
.queue
, hb
);
682 card
->hbpool
.count
++;
686 /* Allocate large buffers */
687 skb_queue_head_init(&card
->lbpool
.queue
);
688 card
->lbpool
.count
= 0; /* Not used */
689 for (j
= 0; j
< NUM_LB
; j
++)
692 lb
= __dev_alloc_skb(NS_LGSKBSIZE
, GFP_KERNEL
);
695 printk("nicstar%d: can't allocate %dth of %d large buffers.\n",
698 ns_init_card_error(card
, error
);
701 NS_SKB_CB(lb
)->buf_type
= BUF_LG
;
702 skb_queue_tail(&card
->lbpool
.queue
, lb
);
703 skb_reserve(lb
, NS_SMBUFSIZE
);
704 push_rxbufs(card
, lb
);
705 /* Due to the implementation of push_rxbufs() this is 1, not 0 */
709 card
->rawch
= (u32
) virt_to_bus(lb
->data
);
712 /* Test for strange behaviour which leads to crashes */
713 if ((bcount
= ns_stat_lfbqc_get(readl(card
->membase
+ STAT
))) < card
->lbnr
.min
)
715 printk("nicstar%d: Strange... Just allocated %d large buffers and lfbqc = %d.\n",
718 ns_init_card_error(card
, error
);
723 /* Allocate small buffers */
724 skb_queue_head_init(&card
->sbpool
.queue
);
725 card
->sbpool
.count
= 0; /* Not used */
726 for (j
= 0; j
< NUM_SB
; j
++)
729 sb
= __dev_alloc_skb(NS_SMSKBSIZE
, GFP_KERNEL
);
732 printk("nicstar%d: can't allocate %dth of %d small buffers.\n",
735 ns_init_card_error(card
, error
);
738 NS_SKB_CB(sb
)->buf_type
= BUF_SM
;
739 skb_queue_tail(&card
->sbpool
.queue
, sb
);
740 skb_reserve(sb
, NS_AAL0_HEADER
);
741 push_rxbufs(card
, sb
);
743 /* Test for strange behaviour which leads to crashes */
744 if ((bcount
= ns_stat_sfbqc_get(readl(card
->membase
+ STAT
))) < card
->sbnr
.min
)
746 printk("nicstar%d: Strange... Just allocated %d small buffers and sfbqc = %d.\n",
749 ns_init_card_error(card
, error
);
754 /* Allocate iovec buffers */
755 skb_queue_head_init(&card
->iovpool
.queue
);
756 card
->iovpool
.count
= 0;
757 for (j
= 0; j
< NUM_IOVB
; j
++)
759 struct sk_buff
*iovb
;
760 iovb
= alloc_skb(NS_IOVBUFSIZE
, GFP_KERNEL
);
763 printk("nicstar%d: can't allocate %dth of %d iovec buffers.\n",
766 ns_init_card_error(card
, error
);
769 NS_SKB_CB(iovb
)->buf_type
= BUF_NONE
;
770 skb_queue_tail(&card
->iovpool
.queue
, iovb
);
771 card
->iovpool
.count
++;
774 /* Configure NICStAR */
775 if (card
->rct_size
== 4096)
776 ns_cfg_rctsize
= NS_CFG_RCTSIZE_4096_ENTRIES
;
777 else /* (card->rct_size == 16384) */
778 ns_cfg_rctsize
= NS_CFG_RCTSIZE_16384_ENTRIES
;
783 if (request_irq(pcidev
->irq
, &ns_irq_handler
, IRQF_DISABLED
| IRQF_SHARED
, "nicstar", card
) != 0)
785 printk("nicstar%d: can't allocate IRQ %d.\n", i
, pcidev
->irq
);
787 ns_init_card_error(card
, error
);
791 /* Register device */
792 card
->atmdev
= atm_dev_register("nicstar", &atm_ops
, -1, NULL
);
793 if (card
->atmdev
== NULL
)
795 printk("nicstar%d: can't register device.\n", i
);
797 ns_init_card_error(card
, error
);
801 if (ns_parse_mac(mac
[i
], card
->atmdev
->esi
)) {
802 nicstar_read_eprom(card
->membase
, NICSTAR_EPROM_MAC_ADDR_OFFSET
,
803 card
->atmdev
->esi
, 6);
804 if (memcmp(card
->atmdev
->esi
, "\x00\x00\x00\x00\x00\x00", 6) == 0) {
805 nicstar_read_eprom(card
->membase
, NICSTAR_EPROM_MAC_ADDR_OFFSET_ALT
,
806 card
->atmdev
->esi
, 6);
810 printk("nicstar%d: MAC address %pM\n", i
, card
->atmdev
->esi
);
812 card
->atmdev
->dev_data
= card
;
813 card
->atmdev
->ci_range
.vpi_bits
= card
->vpibits
;
814 card
->atmdev
->ci_range
.vci_bits
= card
->vcibits
;
815 card
->atmdev
->link_rate
= card
->max_pcr
;
816 card
->atmdev
->phy
= NULL
;
818 #ifdef CONFIG_ATM_NICSTAR_USE_SUNI
819 if (card
->max_pcr
== ATM_OC3_PCR
)
820 suni_init(card
->atmdev
);
821 #endif /* CONFIG_ATM_NICSTAR_USE_SUNI */
823 #ifdef CONFIG_ATM_NICSTAR_USE_IDT77105
824 if (card
->max_pcr
== ATM_25_PCR
)
825 idt77105_init(card
->atmdev
);
826 #endif /* CONFIG_ATM_NICSTAR_USE_IDT77105 */
828 if (card
->atmdev
->phy
&& card
->atmdev
->phy
->start
)
829 card
->atmdev
->phy
->start(card
->atmdev
);
831 writel(NS_CFG_RXPATH
|
838 NS_CFG_RXINT_NODELAY
|
839 NS_CFG_RAWIE
| /* Only enabled if RCQ_SUPPORT */
843 NS_CFG_TSQFIE_OPT
| /* Only enabled if ENABLE_TSQFIE */
845 card
->membase
+ CFG
);
854 static void __devinit
ns_init_card_error(ns_dev
*card
, int error
)
858 writel(0x00000000, card
->membase
+ CFG
);
862 struct sk_buff
*iovb
;
863 while ((iovb
= skb_dequeue(&card
->iovpool
.queue
)) != NULL
)
864 dev_kfree_skb_any(iovb
);
869 while ((sb
= skb_dequeue(&card
->sbpool
.queue
)) != NULL
)
870 dev_kfree_skb_any(sb
);
871 free_scq(card
->scq0
, NULL
);
876 while ((lb
= skb_dequeue(&card
->lbpool
.queue
)) != NULL
)
877 dev_kfree_skb_any(lb
);
882 while ((hb
= skb_dequeue(&card
->hbpool
.queue
)) != NULL
)
883 dev_kfree_skb_any(hb
);
887 kfree(card
->rsq
.org
);
891 kfree(card
->tsq
.org
);
895 free_irq(card
->pcidev
->irq
, card
);
899 iounmap(card
->membase
);
903 pci_disable_device(card
->pcidev
);
910 static scq_info
*get_scq(int size
, u32 scd
)
915 if (size
!= VBR_SCQSIZE
&& size
!= CBR_SCQSIZE
)
918 scq
= kmalloc(sizeof(scq_info
), GFP_KERNEL
);
921 scq
->org
= kmalloc(2 * size
, GFP_KERNEL
);
922 if (scq
->org
== NULL
)
927 scq
->skb
= kmalloc(sizeof(struct sk_buff
*) *
928 (size
/ NS_SCQE_SIZE
), GFP_KERNEL
);
929 if (scq
->skb
== NULL
)
935 scq
->num_entries
= size
/ NS_SCQE_SIZE
;
936 scq
->base
= (ns_scqe
*) ALIGN_ADDRESS(scq
->org
, size
);
937 scq
->next
= scq
->base
;
938 scq
->last
= scq
->base
+ (scq
->num_entries
- 1);
939 scq
->tail
= scq
->last
;
941 scq
->num_entries
= size
/ NS_SCQE_SIZE
;
943 init_waitqueue_head(&scq
->scqfull_waitq
);
945 spin_lock_init(&scq
->lock
);
947 for (i
= 0; i
< scq
->num_entries
; i
++)
955 /* For variable rate SCQ vcc must be NULL */
956 static void free_scq(scq_info
*scq
, struct atm_vcc
*vcc
)
960 if (scq
->num_entries
== VBR_SCQ_NUM_ENTRIES
)
961 for (i
= 0; i
< scq
->num_entries
; i
++)
963 if (scq
->skb
[i
] != NULL
)
965 vcc
= ATM_SKB(scq
->skb
[i
])->vcc
;
966 if (vcc
->pop
!= NULL
)
967 vcc
->pop(vcc
, scq
->skb
[i
]);
969 dev_kfree_skb_any(scq
->skb
[i
]);
972 else /* vcc must be != NULL */
976 printk("nicstar: free_scq() called with vcc == NULL for fixed rate scq.");
977 for (i
= 0; i
< scq
->num_entries
; i
++)
978 dev_kfree_skb_any(scq
->skb
[i
]);
981 for (i
= 0; i
< scq
->num_entries
; i
++)
983 if (scq
->skb
[i
] != NULL
)
985 if (vcc
->pop
!= NULL
)
986 vcc
->pop(vcc
, scq
->skb
[i
]);
988 dev_kfree_skb_any(scq
->skb
[i
]);
999 /* The handles passed must be pointers to the sk_buff containing the small
1000 or large buffer(s) cast to u32. */
1001 static void push_rxbufs(ns_dev
*card
, struct sk_buff
*skb
)
1003 struct ns_skb_cb
*cb
= NS_SKB_CB(skb
);
1007 unsigned long flags
;
1010 handle2
= addr2
= 0;
1012 addr1
= (u32
)virt_to_bus(skb
->data
);
1014 #ifdef GENERAL_DEBUG
1016 printk("nicstar%d: push_rxbufs called with addr1 = 0.\n", card
->index
);
1017 #endif /* GENERAL_DEBUG */
1019 stat
= readl(card
->membase
+ STAT
);
1020 card
->sbfqc
= ns_stat_sfbqc_get(stat
);
1021 card
->lbfqc
= ns_stat_lfbqc_get(stat
);
1022 if (cb
->buf_type
== BUF_SM
)
1028 addr2
= card
->sm_addr
;
1029 handle2
= card
->sm_handle
;
1030 card
->sm_addr
= 0x00000000;
1031 card
->sm_handle
= 0x00000000;
1033 else /* (!sm_addr) */
1035 card
->sm_addr
= addr1
;
1036 card
->sm_handle
= handle1
;
1040 else /* buf_type == BUF_LG */
1046 addr2
= card
->lg_addr
;
1047 handle2
= card
->lg_handle
;
1048 card
->lg_addr
= 0x00000000;
1049 card
->lg_handle
= 0x00000000;
1051 else /* (!lg_addr) */
1053 card
->lg_addr
= addr1
;
1054 card
->lg_handle
= handle1
;
1061 if (cb
->buf_type
== BUF_SM
)
1063 if (card
->sbfqc
>= card
->sbnr
.max
)
1065 skb_unlink((struct sk_buff
*) handle1
, &card
->sbpool
.queue
);
1066 dev_kfree_skb_any((struct sk_buff
*) handle1
);
1067 skb_unlink((struct sk_buff
*) handle2
, &card
->sbpool
.queue
);
1068 dev_kfree_skb_any((struct sk_buff
*) handle2
);
1074 else /* (buf_type == BUF_LG) */
1076 if (card
->lbfqc
>= card
->lbnr
.max
)
1078 skb_unlink((struct sk_buff
*) handle1
, &card
->lbpool
.queue
);
1079 dev_kfree_skb_any((struct sk_buff
*) handle1
);
1080 skb_unlink((struct sk_buff
*) handle2
, &card
->lbpool
.queue
);
1081 dev_kfree_skb_any((struct sk_buff
*) handle2
);
1088 spin_lock_irqsave(&card
->res_lock
, flags
);
1090 while (CMD_BUSY(card
));
1091 writel(addr2
, card
->membase
+ DR3
);
1092 writel(handle2
, card
->membase
+ DR2
);
1093 writel(addr1
, card
->membase
+ DR1
);
1094 writel(handle1
, card
->membase
+ DR0
);
1095 writel(NS_CMD_WRITE_FREEBUFQ
| cb
->buf_type
, card
->membase
+ CMD
);
1097 spin_unlock_irqrestore(&card
->res_lock
, flags
);
1099 XPRINTK("nicstar%d: Pushing %s buffers at 0x%x and 0x%x.\n", card
->index
,
1100 (cb
->buf_type
== BUF_SM
? "small" : "large"), addr1
, addr2
);
1103 if (!card
->efbie
&& card
->sbfqc
>= card
->sbnr
.min
&&
1104 card
->lbfqc
>= card
->lbnr
.min
)
1107 writel((readl(card
->membase
+ CFG
) | NS_CFG_EFBIE
), card
->membase
+ CFG
);
1115 static irqreturn_t
ns_irq_handler(int irq
, void *dev_id
)
1119 struct atm_dev
*dev
;
1120 unsigned long flags
;
1122 card
= (ns_dev
*) dev_id
;
1126 PRINTK("nicstar%d: NICStAR generated an interrupt\n", card
->index
);
1128 spin_lock_irqsave(&card
->int_lock
, flags
);
1130 stat_r
= readl(card
->membase
+ STAT
);
1132 /* Transmit Status Indicator has been written to T. S. Queue */
1133 if (stat_r
& NS_STAT_TSIF
)
1135 TXPRINTK("nicstar%d: TSI interrupt\n", card
->index
);
1137 writel(NS_STAT_TSIF
, card
->membase
+ STAT
);
1140 /* Incomplete CS-PDU has been transmitted */
1141 if (stat_r
& NS_STAT_TXICP
)
1143 writel(NS_STAT_TXICP
, card
->membase
+ STAT
);
1144 TXPRINTK("nicstar%d: Incomplete CS-PDU transmitted.\n",
1148 /* Transmit Status Queue 7/8 full */
1149 if (stat_r
& NS_STAT_TSQF
)
1151 writel(NS_STAT_TSQF
, card
->membase
+ STAT
);
1152 PRINTK("nicstar%d: TSQ full.\n", card
->index
);
1156 /* Timer overflow */
1157 if (stat_r
& NS_STAT_TMROF
)
1159 writel(NS_STAT_TMROF
, card
->membase
+ STAT
);
1160 PRINTK("nicstar%d: Timer overflow.\n", card
->index
);
1163 /* PHY device interrupt signal active */
1164 if (stat_r
& NS_STAT_PHYI
)
1166 writel(NS_STAT_PHYI
, card
->membase
+ STAT
);
1167 PRINTK("nicstar%d: PHY interrupt.\n", card
->index
);
1168 if (dev
->phy
&& dev
->phy
->interrupt
) {
1169 dev
->phy
->interrupt(dev
);
1173 /* Small Buffer Queue is full */
1174 if (stat_r
& NS_STAT_SFBQF
)
1176 writel(NS_STAT_SFBQF
, card
->membase
+ STAT
);
1177 printk("nicstar%d: Small free buffer queue is full.\n", card
->index
);
1180 /* Large Buffer Queue is full */
1181 if (stat_r
& NS_STAT_LFBQF
)
1183 writel(NS_STAT_LFBQF
, card
->membase
+ STAT
);
1184 printk("nicstar%d: Large free buffer queue is full.\n", card
->index
);
1187 /* Receive Status Queue is full */
1188 if (stat_r
& NS_STAT_RSQF
)
1190 writel(NS_STAT_RSQF
, card
->membase
+ STAT
);
1191 printk("nicstar%d: RSQ full.\n", card
->index
);
1195 /* Complete CS-PDU received */
1196 if (stat_r
& NS_STAT_EOPDU
)
1198 RXPRINTK("nicstar%d: End of CS-PDU received.\n", card
->index
);
1200 writel(NS_STAT_EOPDU
, card
->membase
+ STAT
);
1203 /* Raw cell received */
1204 if (stat_r
& NS_STAT_RAWCF
)
1206 writel(NS_STAT_RAWCF
, card
->membase
+ STAT
);
1208 printk("nicstar%d: Raw cell received and no support yet...\n",
1210 #endif /* RCQ_SUPPORT */
1211 /* NOTE: the following procedure may keep a raw cell pending until the
1212 next interrupt. As this preliminary support is only meant to
1213 avoid buffer leakage, this is not an issue. */
1214 while (readl(card
->membase
+ RAWCT
) != card
->rawch
)
1218 rawcell
= (ns_rcqe
*) bus_to_virt(card
->rawch
);
1219 if (ns_rcqe_islast(rawcell
))
1221 struct sk_buff
*oldbuf
;
1223 oldbuf
= card
->rcbuf
;
1224 card
->rcbuf
= (struct sk_buff
*) ns_rcqe_nextbufhandle(rawcell
);
1225 card
->rawch
= (u32
) virt_to_bus(card
->rcbuf
->data
);
1226 recycle_rx_buf(card
, oldbuf
);
1229 card
->rawch
+= NS_RCQE_SIZE
;
1233 /* Small buffer queue is empty */
1234 if (stat_r
& NS_STAT_SFBQE
)
1239 writel(NS_STAT_SFBQE
, card
->membase
+ STAT
);
1240 printk("nicstar%d: Small free buffer queue empty.\n",
1242 for (i
= 0; i
< card
->sbnr
.min
; i
++)
1244 sb
= dev_alloc_skb(NS_SMSKBSIZE
);
1247 writel(readl(card
->membase
+ CFG
) & ~NS_CFG_EFBIE
, card
->membase
+ CFG
);
1251 NS_SKB_CB(sb
)->buf_type
= BUF_SM
;
1252 skb_queue_tail(&card
->sbpool
.queue
, sb
);
1253 skb_reserve(sb
, NS_AAL0_HEADER
);
1254 push_rxbufs(card
, sb
);
1260 /* Large buffer queue empty */
1261 if (stat_r
& NS_STAT_LFBQE
)
1266 writel(NS_STAT_LFBQE
, card
->membase
+ STAT
);
1267 printk("nicstar%d: Large free buffer queue empty.\n",
1269 for (i
= 0; i
< card
->lbnr
.min
; i
++)
1271 lb
= dev_alloc_skb(NS_LGSKBSIZE
);
1274 writel(readl(card
->membase
+ CFG
) & ~NS_CFG_EFBIE
, card
->membase
+ CFG
);
1278 NS_SKB_CB(lb
)->buf_type
= BUF_LG
;
1279 skb_queue_tail(&card
->lbpool
.queue
, lb
);
1280 skb_reserve(lb
, NS_SMBUFSIZE
);
1281 push_rxbufs(card
, lb
);
1287 /* Receive Status Queue is 7/8 full */
1288 if (stat_r
& NS_STAT_RSQAF
)
1290 writel(NS_STAT_RSQAF
, card
->membase
+ STAT
);
1291 RXPRINTK("nicstar%d: RSQ almost full.\n", card
->index
);
1295 spin_unlock_irqrestore(&card
->int_lock
, flags
);
1296 PRINTK("nicstar%d: end of interrupt service\n", card
->index
);
1302 static int ns_open(struct atm_vcc
*vcc
)
1306 unsigned long tmpl
, modl
;
1307 int tcr
, tcra
; /* target cell rate, and absolute value */
1308 int n
= 0; /* Number of entries in the TST. Initialized to remove
1309 the compiler warning. */
1311 int frscdi
= 0; /* Index of the SCD. Initialized to remove the compiler
1312 warning. How I wish compilers were clever enough to
1313 tell which variables can truly be used
1315 int inuse
; /* tx or rx vc already in use by another vcc */
1316 short vpi
= vcc
->vpi
;
1319 card
= (ns_dev
*) vcc
->dev
->dev_data
;
1320 PRINTK("nicstar%d: opening vpi.vci %d.%d \n", card
->index
, (int) vpi
, vci
);
1321 if (vcc
->qos
.aal
!= ATM_AAL5
&& vcc
->qos
.aal
!= ATM_AAL0
)
1323 PRINTK("nicstar%d: unsupported AAL.\n", card
->index
);
1327 vc
= &(card
->vcmap
[vpi
<< card
->vcibits
| vci
]);
1331 if (vcc
->qos
.txtp
.traffic_class
!= ATM_NONE
&& vc
->tx
)
1333 if (vcc
->qos
.rxtp
.traffic_class
!= ATM_NONE
&& vc
->rx
)
1337 printk("nicstar%d: %s vci already in use.\n", card
->index
,
1338 inuse
== 1 ? "tx" : inuse
== 2 ? "rx" : "tx and rx");
1342 set_bit(ATM_VF_ADDR
,&vcc
->flags
);
1344 /* NOTE: You are not allowed to modify an open connection's QOS. To change
1345 that, remove the ATM_VF_PARTIAL flag checking. There may be other changes
1346 needed to do that. */
1347 if (!test_bit(ATM_VF_PARTIAL
,&vcc
->flags
))
1351 set_bit(ATM_VF_PARTIAL
,&vcc
->flags
);
1352 if (vcc
->qos
.txtp
.traffic_class
== ATM_CBR
)
1354 /* Check requested cell rate and availability of SCD */
1355 if (vcc
->qos
.txtp
.max_pcr
== 0 && vcc
->qos
.txtp
.pcr
== 0 &&
1356 vcc
->qos
.txtp
.min_pcr
== 0)
1358 PRINTK("nicstar%d: trying to open a CBR vc with cell rate = 0 \n",
1360 clear_bit(ATM_VF_PARTIAL
,&vcc
->flags
);
1361 clear_bit(ATM_VF_ADDR
,&vcc
->flags
);
1365 tcr
= atm_pcr_goal(&(vcc
->qos
.txtp
));
1366 tcra
= tcr
>= 0 ? tcr
: -tcr
;
1368 PRINTK("nicstar%d: target cell rate = %d.\n", card
->index
,
1369 vcc
->qos
.txtp
.max_pcr
);
1371 tmpl
= (unsigned long)tcra
* (unsigned long)NS_TST_NUM_ENTRIES
;
1372 modl
= tmpl
% card
->max_pcr
;
1374 n
= (int)(tmpl
/ card
->max_pcr
);
1381 if ((n
= (card
->tst_free_entries
- NS_TST_RESERVED
)) <= 0)
1383 PRINTK("nicstar%d: no CBR bandwidth free.\n", card
->index
);
1384 clear_bit(ATM_VF_PARTIAL
,&vcc
->flags
);
1385 clear_bit(ATM_VF_ADDR
,&vcc
->flags
);
1392 printk("nicstar%d: selected bandwidth < granularity.\n", card
->index
);
1393 clear_bit(ATM_VF_PARTIAL
,&vcc
->flags
);
1394 clear_bit(ATM_VF_ADDR
,&vcc
->flags
);
1398 if (n
> (card
->tst_free_entries
- NS_TST_RESERVED
))
1400 PRINTK("nicstar%d: not enough free CBR bandwidth.\n", card
->index
);
1401 clear_bit(ATM_VF_PARTIAL
,&vcc
->flags
);
1402 clear_bit(ATM_VF_ADDR
,&vcc
->flags
);
1406 card
->tst_free_entries
-= n
;
1408 XPRINTK("nicstar%d: writing %d tst entries.\n", card
->index
, n
);
1409 for (frscdi
= 0; frscdi
< NS_FRSCD_NUM
; frscdi
++)
1411 if (card
->scd2vc
[frscdi
] == NULL
)
1413 card
->scd2vc
[frscdi
] = vc
;
1417 if (frscdi
== NS_FRSCD_NUM
)
1419 PRINTK("nicstar%d: no SCD available for CBR channel.\n", card
->index
);
1420 card
->tst_free_entries
+= n
;
1421 clear_bit(ATM_VF_PARTIAL
,&vcc
->flags
);
1422 clear_bit(ATM_VF_ADDR
,&vcc
->flags
);
1426 vc
->cbr_scd
= NS_FRSCD
+ frscdi
* NS_FRSCD_SIZE
;
1428 scq
= get_scq(CBR_SCQSIZE
, vc
->cbr_scd
);
1431 PRINTK("nicstar%d: can't get fixed rate SCQ.\n", card
->index
);
1432 card
->scd2vc
[frscdi
] = NULL
;
1433 card
->tst_free_entries
+= n
;
1434 clear_bit(ATM_VF_PARTIAL
,&vcc
->flags
);
1435 clear_bit(ATM_VF_ADDR
,&vcc
->flags
);
1439 u32d
[0] = (u32
) virt_to_bus(scq
->base
);
1440 u32d
[1] = (u32
) 0x00000000;
1441 u32d
[2] = (u32
) 0xffffffff;
1442 u32d
[3] = (u32
) 0x00000000;
1443 ns_write_sram(card
, vc
->cbr_scd
, u32d
, 4);
1445 fill_tst(card
, n
, vc
);
1447 else if (vcc
->qos
.txtp
.traffic_class
== ATM_UBR
)
1449 vc
->cbr_scd
= 0x00000000;
1450 vc
->scq
= card
->scq0
;
1453 if (vcc
->qos
.txtp
.traffic_class
!= ATM_NONE
)
1459 if (vcc
->qos
.rxtp
.traffic_class
!= ATM_NONE
)
1467 /* Open the connection in hardware */
1468 if (vcc
->qos
.aal
== ATM_AAL5
)
1469 status
= NS_RCTE_AAL5
| NS_RCTE_CONNECTOPEN
;
1470 else /* vcc->qos.aal == ATM_AAL0 */
1471 status
= NS_RCTE_AAL0
| NS_RCTE_CONNECTOPEN
;
1473 status
|= NS_RCTE_RAWCELLINTEN
;
1474 #endif /* RCQ_SUPPORT */
1475 ns_write_sram(card
, NS_RCT
+ (vpi
<< card
->vcibits
| vci
) *
1476 NS_RCT_ENTRY_SIZE
, &status
, 1);
1481 set_bit(ATM_VF_READY
,&vcc
->flags
);
1487 static void ns_close(struct atm_vcc
*vcc
)
1495 card
= vcc
->dev
->dev_data
;
1496 PRINTK("nicstar%d: closing vpi.vci %d.%d \n", card
->index
,
1497 (int) vcc
->vpi
, vcc
->vci
);
1499 clear_bit(ATM_VF_READY
,&vcc
->flags
);
1501 if (vcc
->qos
.rxtp
.traffic_class
!= ATM_NONE
)
1504 unsigned long flags
;
1506 addr
= NS_RCT
+ (vcc
->vpi
<< card
->vcibits
| vcc
->vci
) * NS_RCT_ENTRY_SIZE
;
1507 spin_lock_irqsave(&card
->res_lock
, flags
);
1508 while(CMD_BUSY(card
));
1509 writel(NS_CMD_CLOSE_CONNECTION
| addr
<< 2, card
->membase
+ CMD
);
1510 spin_unlock_irqrestore(&card
->res_lock
, flags
);
1513 if (vc
->rx_iov
!= NULL
)
1515 struct sk_buff
*iovb
;
1518 stat
= readl(card
->membase
+ STAT
);
1519 card
->sbfqc
= ns_stat_sfbqc_get(stat
);
1520 card
->lbfqc
= ns_stat_lfbqc_get(stat
);
1522 PRINTK("nicstar%d: closing a VC with pending rx buffers.\n",
1525 recycle_iovec_rx_bufs(card
, (struct iovec
*) iovb
->data
,
1526 NS_SKB(iovb
)->iovcnt
);
1527 NS_SKB(iovb
)->iovcnt
= 0;
1528 NS_SKB(iovb
)->vcc
= NULL
;
1529 spin_lock_irqsave(&card
->int_lock
, flags
);
1530 recycle_iov_buf(card
, iovb
);
1531 spin_unlock_irqrestore(&card
->int_lock
, flags
);
1536 if (vcc
->qos
.txtp
.traffic_class
!= ATM_NONE
)
1541 if (vcc
->qos
.txtp
.traffic_class
== ATM_CBR
)
1543 unsigned long flags
;
1551 spin_lock_irqsave(&scq
->lock
, flags
);
1553 if (scqep
== scq
->base
)
1557 if (scqep
== scq
->tail
)
1559 spin_unlock_irqrestore(&scq
->lock
, flags
);
1562 /* If the last entry is not a TSR, place one in the SCQ in order to
1563 be able to completely drain it and then close. */
1564 if (!ns_scqe_is_tsr(scqep
) && scq
->tail
!= scq
->next
)
1571 tsr
.word_1
= ns_tsr_mkword_1(NS_TSR_INTENABLE
);
1572 scdi
= (vc
->cbr_scd
- NS_FRSCD
) / NS_FRSCD_SIZE
;
1573 scqi
= scq
->next
- scq
->base
;
1574 tsr
.word_2
= ns_tsr_mkword_2(scdi
, scqi
);
1575 tsr
.word_3
= 0x00000000;
1576 tsr
.word_4
= 0x00000000;
1579 scq
->skb
[index
] = NULL
;
1580 if (scq
->next
== scq
->last
)
1581 scq
->next
= scq
->base
;
1584 data
= (u32
) virt_to_bus(scq
->next
);
1585 ns_write_sram(card
, scq
->scd
, &data
, 1);
1587 spin_unlock_irqrestore(&scq
->lock
, flags
);
1591 /* Free all TST entries */
1592 data
= NS_TST_OPCODE_VARIABLE
;
1593 for (i
= 0; i
< NS_TST_NUM_ENTRIES
; i
++)
1595 if (card
->tste2vc
[i
] == vc
)
1597 ns_write_sram(card
, card
->tst_addr
+ i
, &data
, 1);
1598 card
->tste2vc
[i
] = NULL
;
1599 card
->tst_free_entries
++;
1603 card
->scd2vc
[(vc
->cbr_scd
- NS_FRSCD
) / NS_FRSCD_SIZE
] = NULL
;
1604 free_scq(vc
->scq
, vcc
);
1607 /* remove all references to vcc before deleting it */
1608 if (vcc
->qos
.txtp
.traffic_class
!= ATM_NONE
)
1610 unsigned long flags
;
1611 scq_info
*scq
= card
->scq0
;
1613 spin_lock_irqsave(&scq
->lock
, flags
);
1615 for(i
= 0; i
< scq
->num_entries
; i
++) {
1616 if(scq
->skb
[i
] && ATM_SKB(scq
->skb
[i
])->vcc
== vcc
) {
1617 ATM_SKB(scq
->skb
[i
])->vcc
= NULL
;
1618 atm_return(vcc
, scq
->skb
[i
]->truesize
);
1619 PRINTK("nicstar: deleted pending vcc mapping\n");
1623 spin_unlock_irqrestore(&scq
->lock
, flags
);
1626 vcc
->dev_data
= NULL
;
1627 clear_bit(ATM_VF_PARTIAL
,&vcc
->flags
);
1628 clear_bit(ATM_VF_ADDR
,&vcc
->flags
);
1633 stat
= readl(card
->membase
+ STAT
);
1634 cfg
= readl(card
->membase
+ CFG
);
1635 printk("STAT = 0x%08X CFG = 0x%08X \n", stat
, cfg
);
1636 printk("TSQ: base = 0x%08X next = 0x%08X last = 0x%08X TSQT = 0x%08X \n",
1637 (u32
) card
->tsq
.base
, (u32
) card
->tsq
.next
,(u32
) card
->tsq
.last
,
1638 readl(card
->membase
+ TSQT
));
1639 printk("RSQ: base = 0x%08X next = 0x%08X last = 0x%08X RSQT = 0x%08X \n",
1640 (u32
) card
->rsq
.base
, (u32
) card
->rsq
.next
,(u32
) card
->rsq
.last
,
1641 readl(card
->membase
+ RSQT
));
1642 printk("Empty free buffer queue interrupt %s \n",
1643 card
->efbie
? "enabled" : "disabled");
1644 printk("SBCNT = %d count = %d LBCNT = %d count = %d \n",
1645 ns_stat_sfbqc_get(stat
), card
->sbpool
.count
,
1646 ns_stat_lfbqc_get(stat
), card
->lbpool
.count
);
1647 printk("hbpool.count = %d iovpool.count = %d \n",
1648 card
->hbpool
.count
, card
->iovpool
.count
);
1650 #endif /* RX_DEBUG */
1655 static void fill_tst(ns_dev
*card
, int n
, vc_map
*vc
)
1662 /* It would be very complicated to keep the two TSTs synchronized while
1663 assuring that writes are only made to the inactive TST. So, for now I
1664 will use only one TST. If problems occur, I will change this again */
1666 new_tst
= card
->tst_addr
;
1668 /* Fill procedure */
1670 for (e
= 0; e
< NS_TST_NUM_ENTRIES
; e
++)
1672 if (card
->tste2vc
[e
] == NULL
)
1675 if (e
== NS_TST_NUM_ENTRIES
) {
1676 printk("nicstar%d: No free TST entries found. \n", card
->index
);
1681 cl
= NS_TST_NUM_ENTRIES
;
1682 data
= ns_tste_make(NS_TST_OPCODE_FIXED
, vc
->cbr_scd
);
1686 if (cl
>= NS_TST_NUM_ENTRIES
&& card
->tste2vc
[e
] == NULL
)
1688 card
->tste2vc
[e
] = vc
;
1689 ns_write_sram(card
, new_tst
+ e
, &data
, 1);
1690 cl
-= NS_TST_NUM_ENTRIES
;
1694 if (++e
== NS_TST_NUM_ENTRIES
) {
1700 /* End of fill procedure */
1702 data
= ns_tste_make(NS_TST_OPCODE_END
, new_tst
);
1703 ns_write_sram(card
, new_tst
+ NS_TST_NUM_ENTRIES
, &data
, 1);
1704 ns_write_sram(card
, card
->tst_addr
+ NS_TST_NUM_ENTRIES
, &data
, 1);
1705 card
->tst_addr
= new_tst
;
1710 static int ns_send(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
1715 unsigned long buflen
;
1717 u32 flags
; /* TBD flags, not CPU flags */
1719 card
= vcc
->dev
->dev_data
;
1720 TXPRINTK("nicstar%d: ns_send() called.\n", card
->index
);
1721 if ((vc
= (vc_map
*) vcc
->dev_data
) == NULL
)
1723 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n", card
->index
);
1724 atomic_inc(&vcc
->stats
->tx_err
);
1725 dev_kfree_skb_any(skb
);
1731 printk("nicstar%d: Trying to transmit on a non-tx VC.\n", card
->index
);
1732 atomic_inc(&vcc
->stats
->tx_err
);
1733 dev_kfree_skb_any(skb
);
1737 if (vcc
->qos
.aal
!= ATM_AAL5
&& vcc
->qos
.aal
!= ATM_AAL0
)
1739 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n", card
->index
);
1740 atomic_inc(&vcc
->stats
->tx_err
);
1741 dev_kfree_skb_any(skb
);
1745 if (skb_shinfo(skb
)->nr_frags
!= 0)
1747 printk("nicstar%d: No scatter-gather yet.\n", card
->index
);
1748 atomic_inc(&vcc
->stats
->tx_err
);
1749 dev_kfree_skb_any(skb
);
1753 ATM_SKB(skb
)->vcc
= vcc
;
1755 if (vcc
->qos
.aal
== ATM_AAL5
)
1757 buflen
= (skb
->len
+ 47 + 8) / 48 * 48; /* Multiple of 48 */
1758 flags
= NS_TBD_AAL5
;
1759 scqe
.word_2
= cpu_to_le32((u32
) virt_to_bus(skb
->data
));
1760 scqe
.word_3
= cpu_to_le32((u32
) skb
->len
);
1761 scqe
.word_4
= ns_tbd_mkword_4(0, (u32
) vcc
->vpi
, (u32
) vcc
->vci
, 0,
1762 ATM_SKB(skb
)->atm_options
& ATM_ATMOPT_CLP
? 1 : 0);
1763 flags
|= NS_TBD_EOPDU
;
1765 else /* (vcc->qos.aal == ATM_AAL0) */
1767 buflen
= ATM_CELL_PAYLOAD
; /* i.e., 48 bytes */
1768 flags
= NS_TBD_AAL0
;
1769 scqe
.word_2
= cpu_to_le32((u32
) virt_to_bus(skb
->data
) + NS_AAL0_HEADER
);
1770 scqe
.word_3
= cpu_to_le32(0x00000000);
1771 if (*skb
->data
& 0x02) /* Payload type 1 - end of pdu */
1772 flags
|= NS_TBD_EOPDU
;
1773 scqe
.word_4
= cpu_to_le32(*((u32
*) skb
->data
) & ~NS_TBD_VC_MASK
);
1774 /* Force the VPI/VCI to be the same as in VCC struct */
1775 scqe
.word_4
|= cpu_to_le32((((u32
) vcc
->vpi
) << NS_TBD_VPI_SHIFT
|
1776 ((u32
) vcc
->vci
) << NS_TBD_VCI_SHIFT
) &
1780 if (vcc
->qos
.txtp
.traffic_class
== ATM_CBR
)
1782 scqe
.word_1
= ns_tbd_mkword_1_novbr(flags
, (u32
) buflen
);
1783 scq
= ((vc_map
*) vcc
->dev_data
)->scq
;
1787 scqe
.word_1
= ns_tbd_mkword_1(flags
, (u32
) 1, (u32
) 1, (u32
) buflen
);
1791 if (push_scqe(card
, vc
, scq
, &scqe
, skb
) != 0)
1793 atomic_inc(&vcc
->stats
->tx_err
);
1794 dev_kfree_skb_any(skb
);
1797 atomic_inc(&vcc
->stats
->tx
);
1804 static int push_scqe(ns_dev
*card
, vc_map
*vc
, scq_info
*scq
, ns_scqe
*tbd
,
1805 struct sk_buff
*skb
)
1807 unsigned long flags
;
1814 spin_lock_irqsave(&scq
->lock
, flags
);
1815 while (scq
->tail
== scq
->next
)
1817 if (in_interrupt()) {
1818 spin_unlock_irqrestore(&scq
->lock
, flags
);
1819 printk("nicstar%d: Error pushing TBD.\n", card
->index
);
1824 spin_unlock_irqrestore(&scq
->lock
, flags
);
1825 interruptible_sleep_on_timeout(&scq
->scqfull_waitq
, SCQFULL_TIMEOUT
);
1826 spin_lock_irqsave(&scq
->lock
, flags
);
1829 spin_unlock_irqrestore(&scq
->lock
, flags
);
1830 printk("nicstar%d: Timeout pushing TBD.\n", card
->index
);
1835 index
= (int) (scq
->next
- scq
->base
);
1836 scq
->skb
[index
] = skb
;
1837 XPRINTK("nicstar%d: sending skb at 0x%x (pos %d).\n",
1838 card
->index
, (u32
) skb
, index
);
1839 XPRINTK("nicstar%d: TBD written:\n0x%x\n0x%x\n0x%x\n0x%x\n at 0x%x.\n",
1840 card
->index
, le32_to_cpu(tbd
->word_1
), le32_to_cpu(tbd
->word_2
),
1841 le32_to_cpu(tbd
->word_3
), le32_to_cpu(tbd
->word_4
),
1843 if (scq
->next
== scq
->last
)
1844 scq
->next
= scq
->base
;
1849 if (scq
->num_entries
== VBR_SCQ_NUM_ENTRIES
)
1857 if (vc
->tbd_count
>= MAX_TBD_PER_VC
|| scq
->tbd_count
>= MAX_TBD_PER_SCQ
)
1861 while (scq
->tail
== scq
->next
)
1863 if (in_interrupt()) {
1864 data
= (u32
) virt_to_bus(scq
->next
);
1865 ns_write_sram(card
, scq
->scd
, &data
, 1);
1866 spin_unlock_irqrestore(&scq
->lock
, flags
);
1867 printk("nicstar%d: Error pushing TSR.\n", card
->index
);
1872 if (has_run
++) break;
1873 spin_unlock_irqrestore(&scq
->lock
, flags
);
1874 interruptible_sleep_on_timeout(&scq
->scqfull_waitq
, SCQFULL_TIMEOUT
);
1875 spin_lock_irqsave(&scq
->lock
, flags
);
1880 tsr
.word_1
= ns_tsr_mkword_1(NS_TSR_INTENABLE
);
1882 scdi
= NS_TSR_SCDISVBR
;
1884 scdi
= (vc
->cbr_scd
- NS_FRSCD
) / NS_FRSCD_SIZE
;
1885 scqi
= scq
->next
- scq
->base
;
1886 tsr
.word_2
= ns_tsr_mkword_2(scdi
, scqi
);
1887 tsr
.word_3
= 0x00000000;
1888 tsr
.word_4
= 0x00000000;
1892 scq
->skb
[index
] = NULL
;
1893 XPRINTK("nicstar%d: TSR written:\n0x%x\n0x%x\n0x%x\n0x%x\n at 0x%x.\n",
1894 card
->index
, le32_to_cpu(tsr
.word_1
), le32_to_cpu(tsr
.word_2
),
1895 le32_to_cpu(tsr
.word_3
), le32_to_cpu(tsr
.word_4
),
1897 if (scq
->next
== scq
->last
)
1898 scq
->next
= scq
->base
;
1905 PRINTK("nicstar%d: Timeout pushing TSR.\n", card
->index
);
1907 data
= (u32
) virt_to_bus(scq
->next
);
1908 ns_write_sram(card
, scq
->scd
, &data
, 1);
1910 spin_unlock_irqrestore(&scq
->lock
, flags
);
1917 static void process_tsq(ns_dev
*card
)
1921 ns_tsi
*previous
= NULL
, *one_ahead
, *two_ahead
;
1922 int serviced_entries
; /* flag indicating at least on entry was serviced */
1924 serviced_entries
= 0;
1926 if (card
->tsq
.next
== card
->tsq
.last
)
1927 one_ahead
= card
->tsq
.base
;
1929 one_ahead
= card
->tsq
.next
+ 1;
1931 if (one_ahead
== card
->tsq
.last
)
1932 two_ahead
= card
->tsq
.base
;
1934 two_ahead
= one_ahead
+ 1;
1936 while (!ns_tsi_isempty(card
->tsq
.next
) || !ns_tsi_isempty(one_ahead
) ||
1937 !ns_tsi_isempty(two_ahead
))
1938 /* At most two empty, as stated in the 77201 errata */
1940 serviced_entries
= 1;
1942 /* Skip the one or two possible empty entries */
1943 while (ns_tsi_isempty(card
->tsq
.next
)) {
1944 if (card
->tsq
.next
== card
->tsq
.last
)
1945 card
->tsq
.next
= card
->tsq
.base
;
1950 if (!ns_tsi_tmrof(card
->tsq
.next
))
1952 scdi
= ns_tsi_getscdindex(card
->tsq
.next
);
1953 if (scdi
== NS_TSI_SCDISVBR
)
1957 if (card
->scd2vc
[scdi
] == NULL
)
1959 printk("nicstar%d: could not find VC from SCD index.\n",
1961 ns_tsi_init(card
->tsq
.next
);
1964 scq
= card
->scd2vc
[scdi
]->scq
;
1966 drain_scq(card
, scq
, ns_tsi_getscqpos(card
->tsq
.next
));
1968 wake_up_interruptible(&(scq
->scqfull_waitq
));
1971 ns_tsi_init(card
->tsq
.next
);
1972 previous
= card
->tsq
.next
;
1973 if (card
->tsq
.next
== card
->tsq
.last
)
1974 card
->tsq
.next
= card
->tsq
.base
;
1978 if (card
->tsq
.next
== card
->tsq
.last
)
1979 one_ahead
= card
->tsq
.base
;
1981 one_ahead
= card
->tsq
.next
+ 1;
1983 if (one_ahead
== card
->tsq
.last
)
1984 two_ahead
= card
->tsq
.base
;
1986 two_ahead
= one_ahead
+ 1;
1989 if (serviced_entries
) {
1990 writel((((u32
) previous
) - ((u32
) card
->tsq
.base
)),
1991 card
->membase
+ TSQH
);
1997 static void drain_scq(ns_dev
*card
, scq_info
*scq
, int pos
)
1999 struct atm_vcc
*vcc
;
2000 struct sk_buff
*skb
;
2002 unsigned long flags
;
2004 XPRINTK("nicstar%d: drain_scq() called, scq at 0x%x, pos %d.\n",
2005 card
->index
, (u32
) scq
, pos
);
2006 if (pos
>= scq
->num_entries
)
2008 printk("nicstar%d: Bad index on drain_scq().\n", card
->index
);
2012 spin_lock_irqsave(&scq
->lock
, flags
);
2013 i
= (int) (scq
->tail
- scq
->base
);
2014 if (++i
== scq
->num_entries
)
2019 XPRINTK("nicstar%d: freeing skb at 0x%x (index %d).\n",
2020 card
->index
, (u32
) skb
, i
);
2023 vcc
= ATM_SKB(skb
)->vcc
;
2024 if (vcc
&& vcc
->pop
!= NULL
) {
2027 dev_kfree_skb_irq(skb
);
2031 if (++i
== scq
->num_entries
)
2034 scq
->tail
= scq
->base
+ pos
;
2035 spin_unlock_irqrestore(&scq
->lock
, flags
);
2040 static void process_rsq(ns_dev
*card
)
2044 if (!ns_rsqe_valid(card
->rsq
.next
))
2047 dequeue_rx(card
, card
->rsq
.next
);
2048 ns_rsqe_init(card
->rsq
.next
);
2049 previous
= card
->rsq
.next
;
2050 if (card
->rsq
.next
== card
->rsq
.last
)
2051 card
->rsq
.next
= card
->rsq
.base
;
2054 } while (ns_rsqe_valid(card
->rsq
.next
));
2055 writel((((u32
) previous
) - ((u32
) card
->rsq
.base
)),
2056 card
->membase
+ RSQH
);
2061 static void dequeue_rx(ns_dev
*card
, ns_rsqe
*rsqe
)
2065 struct sk_buff
*iovb
;
2067 struct atm_vcc
*vcc
;
2068 struct sk_buff
*skb
;
2069 unsigned short aal5_len
;
2073 stat
= readl(card
->membase
+ STAT
);
2074 card
->sbfqc
= ns_stat_sfbqc_get(stat
);
2075 card
->lbfqc
= ns_stat_lfbqc_get(stat
);
2077 skb
= (struct sk_buff
*) le32_to_cpu(rsqe
->buffer_handle
);
2078 vpi
= ns_rsqe_vpi(rsqe
);
2079 vci
= ns_rsqe_vci(rsqe
);
2080 if (vpi
>= 1UL << card
->vpibits
|| vci
>= 1UL << card
->vcibits
)
2082 printk("nicstar%d: SDU received for out-of-range vc %d.%d.\n",
2083 card
->index
, vpi
, vci
);
2084 recycle_rx_buf(card
, skb
);
2088 vc
= &(card
->vcmap
[vpi
<< card
->vcibits
| vci
]);
2091 RXPRINTK("nicstar%d: SDU received on non-rx vc %d.%d.\n",
2092 card
->index
, vpi
, vci
);
2093 recycle_rx_buf(card
, skb
);
2099 if (vcc
->qos
.aal
== ATM_AAL0
)
2102 unsigned char *cell
;
2106 for (i
= ns_rsqe_cellcount(rsqe
); i
; i
--)
2108 if ((sb
= dev_alloc_skb(NS_SMSKBSIZE
)) == NULL
)
2110 printk("nicstar%d: Can't allocate buffers for aal0.\n",
2112 atomic_add(i
,&vcc
->stats
->rx_drop
);
2115 if (!atm_charge(vcc
, sb
->truesize
))
2117 RXPRINTK("nicstar%d: atm_charge() dropped aal0 packets.\n",
2119 atomic_add(i
-1,&vcc
->stats
->rx_drop
); /* already increased by 1 */
2120 dev_kfree_skb_any(sb
);
2123 /* Rebuild the header */
2124 *((u32
*) sb
->data
) = le32_to_cpu(rsqe
->word_1
) << 4 |
2125 (ns_rsqe_clp(rsqe
) ? 0x00000001 : 0x00000000);
2126 if (i
== 1 && ns_rsqe_eopdu(rsqe
))
2127 *((u32
*) sb
->data
) |= 0x00000002;
2128 skb_put(sb
, NS_AAL0_HEADER
);
2129 memcpy(skb_tail_pointer(sb
), cell
, ATM_CELL_PAYLOAD
);
2130 skb_put(sb
, ATM_CELL_PAYLOAD
);
2131 ATM_SKB(sb
)->vcc
= vcc
;
2132 __net_timestamp(sb
);
2134 atomic_inc(&vcc
->stats
->rx
);
2135 cell
+= ATM_CELL_PAYLOAD
;
2138 recycle_rx_buf(card
, skb
);
2142 /* To reach this point, the AAL layer can only be AAL5 */
2144 if ((iovb
= vc
->rx_iov
) == NULL
)
2146 iovb
= skb_dequeue(&(card
->iovpool
.queue
));
2147 if (iovb
== NULL
) /* No buffers in the queue */
2149 iovb
= alloc_skb(NS_IOVBUFSIZE
, GFP_ATOMIC
);
2152 printk("nicstar%d: Out of iovec buffers.\n", card
->index
);
2153 atomic_inc(&vcc
->stats
->rx_drop
);
2154 recycle_rx_buf(card
, skb
);
2157 NS_SKB_CB(iovb
)->buf_type
= BUF_NONE
;
2160 if (--card
->iovpool
.count
< card
->iovnr
.min
)
2162 struct sk_buff
*new_iovb
;
2163 if ((new_iovb
= alloc_skb(NS_IOVBUFSIZE
, GFP_ATOMIC
)) != NULL
)
2165 NS_SKB_CB(iovb
)->buf_type
= BUF_NONE
;
2166 skb_queue_tail(&card
->iovpool
.queue
, new_iovb
);
2167 card
->iovpool
.count
++;
2171 NS_SKB(iovb
)->iovcnt
= 0;
2173 iovb
->data
= iovb
->head
;
2174 skb_reset_tail_pointer(iovb
);
2175 NS_SKB(iovb
)->vcc
= vcc
;
2176 /* IMPORTANT: a pointer to the sk_buff containing the small or large
2177 buffer is stored as iovec base, NOT a pointer to the
2178 small or large buffer itself. */
2180 else if (NS_SKB(iovb
)->iovcnt
>= NS_MAX_IOVECS
)
2182 printk("nicstar%d: received too big AAL5 SDU.\n", card
->index
);
2183 atomic_inc(&vcc
->stats
->rx_err
);
2184 recycle_iovec_rx_bufs(card
, (struct iovec
*) iovb
->data
, NS_MAX_IOVECS
);
2185 NS_SKB(iovb
)->iovcnt
= 0;
2187 iovb
->data
= iovb
->head
;
2188 skb_reset_tail_pointer(iovb
);
2189 NS_SKB(iovb
)->vcc
= vcc
;
2191 iov
= &((struct iovec
*) iovb
->data
)[NS_SKB(iovb
)->iovcnt
++];
2192 iov
->iov_base
= (void *) skb
;
2193 iov
->iov_len
= ns_rsqe_cellcount(rsqe
) * 48;
2194 iovb
->len
+= iov
->iov_len
;
2196 if (NS_SKB(iovb
)->iovcnt
== 1)
2198 if (NS_SKB_CB(skb
)->buf_type
!= BUF_SM
)
2200 printk("nicstar%d: Expected a small buffer, and this is not one.\n",
2202 which_list(card
, skb
);
2203 atomic_inc(&vcc
->stats
->rx_err
);
2204 recycle_rx_buf(card
, skb
);
2206 recycle_iov_buf(card
, iovb
);
2210 else /* NS_SKB(iovb)->iovcnt >= 2 */
2212 if (NS_SKB_CB(skb
)->buf_type
!= BUF_LG
)
2214 printk("nicstar%d: Expected a large buffer, and this is not one.\n",
2216 which_list(card
, skb
);
2217 atomic_inc(&vcc
->stats
->rx_err
);
2218 recycle_iovec_rx_bufs(card
, (struct iovec
*) iovb
->data
,
2219 NS_SKB(iovb
)->iovcnt
);
2221 recycle_iov_buf(card
, iovb
);
2226 if (ns_rsqe_eopdu(rsqe
))
2228 /* This works correctly regardless of the endianness of the host */
2229 unsigned char *L1L2
= (unsigned char *)((u32
)skb
->data
+
2231 aal5_len
= L1L2
[0] << 8 | L1L2
[1];
2232 len
= (aal5_len
== 0x0000) ? 0x10000 : aal5_len
;
2233 if (ns_rsqe_crcerr(rsqe
) ||
2234 len
+ 8 > iovb
->len
|| len
+ (47 + 8) < iovb
->len
)
2236 printk("nicstar%d: AAL5 CRC error", card
->index
);
2237 if (len
+ 8 > iovb
->len
|| len
+ (47 + 8) < iovb
->len
)
2238 printk(" - PDU size mismatch.\n");
2241 atomic_inc(&vcc
->stats
->rx_err
);
2242 recycle_iovec_rx_bufs(card
, (struct iovec
*) iovb
->data
,
2243 NS_SKB(iovb
)->iovcnt
);
2245 recycle_iov_buf(card
, iovb
);
2249 /* By this point we (hopefully) have a complete SDU without errors. */
2251 if (NS_SKB(iovb
)->iovcnt
== 1) /* Just a small buffer */
2253 /* skb points to a small buffer */
2254 if (!atm_charge(vcc
, skb
->truesize
))
2256 push_rxbufs(card
, skb
);
2257 atomic_inc(&vcc
->stats
->rx_drop
);
2262 dequeue_sm_buf(card
, skb
);
2263 #ifdef NS_USE_DESTRUCTORS
2264 skb
->destructor
= ns_sb_destructor
;
2265 #endif /* NS_USE_DESTRUCTORS */
2266 ATM_SKB(skb
)->vcc
= vcc
;
2267 __net_timestamp(skb
);
2268 vcc
->push(vcc
, skb
);
2269 atomic_inc(&vcc
->stats
->rx
);
2272 else if (NS_SKB(iovb
)->iovcnt
== 2) /* One small plus one large buffer */
2276 sb
= (struct sk_buff
*) (iov
- 1)->iov_base
;
2277 /* skb points to a large buffer */
2279 if (len
<= NS_SMBUFSIZE
)
2281 if (!atm_charge(vcc
, sb
->truesize
))
2283 push_rxbufs(card
, sb
);
2284 atomic_inc(&vcc
->stats
->rx_drop
);
2289 dequeue_sm_buf(card
, sb
);
2290 #ifdef NS_USE_DESTRUCTORS
2291 sb
->destructor
= ns_sb_destructor
;
2292 #endif /* NS_USE_DESTRUCTORS */
2293 ATM_SKB(sb
)->vcc
= vcc
;
2294 __net_timestamp(sb
);
2296 atomic_inc(&vcc
->stats
->rx
);
2299 push_rxbufs(card
, skb
);
2302 else /* len > NS_SMBUFSIZE, the usual case */
2304 if (!atm_charge(vcc
, skb
->truesize
))
2306 push_rxbufs(card
, skb
);
2307 atomic_inc(&vcc
->stats
->rx_drop
);
2311 dequeue_lg_buf(card
, skb
);
2312 #ifdef NS_USE_DESTRUCTORS
2313 skb
->destructor
= ns_lb_destructor
;
2314 #endif /* NS_USE_DESTRUCTORS */
2315 skb_push(skb
, NS_SMBUFSIZE
);
2316 skb_copy_from_linear_data(sb
, skb
->data
, NS_SMBUFSIZE
);
2317 skb_put(skb
, len
- NS_SMBUFSIZE
);
2318 ATM_SKB(skb
)->vcc
= vcc
;
2319 __net_timestamp(skb
);
2320 vcc
->push(vcc
, skb
);
2321 atomic_inc(&vcc
->stats
->rx
);
2324 push_rxbufs(card
, sb
);
2329 else /* Must push a huge buffer */
2331 struct sk_buff
*hb
, *sb
, *lb
;
2332 int remaining
, tocopy
;
2335 hb
= skb_dequeue(&(card
->hbpool
.queue
));
2336 if (hb
== NULL
) /* No buffers in the queue */
2339 hb
= dev_alloc_skb(NS_HBUFSIZE
);
2342 printk("nicstar%d: Out of huge buffers.\n", card
->index
);
2343 atomic_inc(&vcc
->stats
->rx_drop
);
2344 recycle_iovec_rx_bufs(card
, (struct iovec
*) iovb
->data
,
2345 NS_SKB(iovb
)->iovcnt
);
2347 recycle_iov_buf(card
, iovb
);
2350 else if (card
->hbpool
.count
< card
->hbnr
.min
)
2352 struct sk_buff
*new_hb
;
2353 if ((new_hb
= dev_alloc_skb(NS_HBUFSIZE
)) != NULL
)
2355 skb_queue_tail(&card
->hbpool
.queue
, new_hb
);
2356 card
->hbpool
.count
++;
2359 NS_SKB_CB(hb
)->buf_type
= BUF_NONE
;
2362 if (--card
->hbpool
.count
< card
->hbnr
.min
)
2364 struct sk_buff
*new_hb
;
2365 if ((new_hb
= dev_alloc_skb(NS_HBUFSIZE
)) != NULL
)
2367 NS_SKB_CB(new_hb
)->buf_type
= BUF_NONE
;
2368 skb_queue_tail(&card
->hbpool
.queue
, new_hb
);
2369 card
->hbpool
.count
++;
2371 if (card
->hbpool
.count
< card
->hbnr
.min
)
2373 if ((new_hb
= dev_alloc_skb(NS_HBUFSIZE
)) != NULL
)
2375 NS_SKB_CB(new_hb
)->buf_type
= BUF_NONE
;
2376 skb_queue_tail(&card
->hbpool
.queue
, new_hb
);
2377 card
->hbpool
.count
++;
2382 iov
= (struct iovec
*) iovb
->data
;
2384 if (!atm_charge(vcc
, hb
->truesize
))
2386 recycle_iovec_rx_bufs(card
, iov
, NS_SKB(iovb
)->iovcnt
);
2387 if (card
->hbpool
.count
< card
->hbnr
.max
)
2389 skb_queue_tail(&card
->hbpool
.queue
, hb
);
2390 card
->hbpool
.count
++;
2393 dev_kfree_skb_any(hb
);
2394 atomic_inc(&vcc
->stats
->rx_drop
);
2398 /* Copy the small buffer to the huge buffer */
2399 sb
= (struct sk_buff
*) iov
->iov_base
;
2400 skb_copy_from_linear_data(sb
, hb
->data
, iov
->iov_len
);
2401 skb_put(hb
, iov
->iov_len
);
2402 remaining
= len
- iov
->iov_len
;
2404 /* Free the small buffer */
2405 push_rxbufs(card
, sb
);
2407 /* Copy all large buffers to the huge buffer and free them */
2408 for (j
= 1; j
< NS_SKB(iovb
)->iovcnt
; j
++)
2410 lb
= (struct sk_buff
*) iov
->iov_base
;
2411 tocopy
= min_t(int, remaining
, iov
->iov_len
);
2412 skb_copy_from_linear_data(lb
, skb_tail_pointer(hb
), tocopy
);
2413 skb_put(hb
, tocopy
);
2415 remaining
-= tocopy
;
2416 push_rxbufs(card
, lb
);
2419 if (remaining
!= 0 || hb
->len
!= len
)
2420 printk("nicstar%d: Huge buffer len mismatch.\n", card
->index
);
2421 #endif /* EXTRA_DEBUG */
2422 ATM_SKB(hb
)->vcc
= vcc
;
2423 #ifdef NS_USE_DESTRUCTORS
2424 hb
->destructor
= ns_hb_destructor
;
2425 #endif /* NS_USE_DESTRUCTORS */
2426 __net_timestamp(hb
);
2428 atomic_inc(&vcc
->stats
->rx
);
2433 recycle_iov_buf(card
, iovb
);
2440 #ifdef NS_USE_DESTRUCTORS
2442 static void ns_sb_destructor(struct sk_buff
*sb
)
2447 card
= (ns_dev
*) ATM_SKB(sb
)->vcc
->dev
->dev_data
;
2448 stat
= readl(card
->membase
+ STAT
);
2449 card
->sbfqc
= ns_stat_sfbqc_get(stat
);
2450 card
->lbfqc
= ns_stat_lfbqc_get(stat
);
2454 sb
= __dev_alloc_skb(NS_SMSKBSIZE
, GFP_KERNEL
);
2457 NS_SKB_CB(sb
)->buf_type
= BUF_SM
;
2458 skb_queue_tail(&card
->sbpool
.queue
, sb
);
2459 skb_reserve(sb
, NS_AAL0_HEADER
);
2460 push_rxbufs(card
, sb
);
2461 } while (card
->sbfqc
< card
->sbnr
.min
);
2466 static void ns_lb_destructor(struct sk_buff
*lb
)
2471 card
= (ns_dev
*) ATM_SKB(lb
)->vcc
->dev
->dev_data
;
2472 stat
= readl(card
->membase
+ STAT
);
2473 card
->sbfqc
= ns_stat_sfbqc_get(stat
);
2474 card
->lbfqc
= ns_stat_lfbqc_get(stat
);
2478 lb
= __dev_alloc_skb(NS_LGSKBSIZE
, GFP_KERNEL
);
2481 NS_SKB_CB(lb
)->buf_type
= BUF_LG
;
2482 skb_queue_tail(&card
->lbpool
.queue
, lb
);
2483 skb_reserve(lb
, NS_SMBUFSIZE
);
2484 push_rxbufs(card
, lb
);
2485 } while (card
->lbfqc
< card
->lbnr
.min
);
2490 static void ns_hb_destructor(struct sk_buff
*hb
)
2494 card
= (ns_dev
*) ATM_SKB(hb
)->vcc
->dev
->dev_data
;
2496 while (card
->hbpool
.count
< card
->hbnr
.init
)
2498 hb
= __dev_alloc_skb(NS_HBUFSIZE
, GFP_KERNEL
);
2501 NS_SKB_CB(hb
)->buf_type
= BUF_NONE
;
2502 skb_queue_tail(&card
->hbpool
.queue
, hb
);
2503 card
->hbpool
.count
++;
2507 #endif /* NS_USE_DESTRUCTORS */
2510 static void recycle_rx_buf(ns_dev
*card
, struct sk_buff
*skb
)
2512 struct ns_skb_cb
*cb
= NS_SKB_CB(skb
);
2514 if (unlikely(cb
->buf_type
== BUF_NONE
)) {
2515 printk("nicstar%d: What kind of rx buffer is this?\n", card
->index
);
2516 dev_kfree_skb_any(skb
);
2518 push_rxbufs(card
, skb
);
2522 static void recycle_iovec_rx_bufs(ns_dev
*card
, struct iovec
*iov
, int count
)
2525 recycle_rx_buf(card
, (struct sk_buff
*) (iov
++)->iov_base
);
2529 static void recycle_iov_buf(ns_dev
*card
, struct sk_buff
*iovb
)
2531 if (card
->iovpool
.count
< card
->iovnr
.max
)
2533 skb_queue_tail(&card
->iovpool
.queue
, iovb
);
2534 card
->iovpool
.count
++;
2537 dev_kfree_skb_any(iovb
);
2542 static void dequeue_sm_buf(ns_dev
*card
, struct sk_buff
*sb
)
2544 skb_unlink(sb
, &card
->sbpool
.queue
);
2545 #ifdef NS_USE_DESTRUCTORS
2546 if (card
->sbfqc
< card
->sbnr
.min
)
2548 if (card
->sbfqc
< card
->sbnr
.init
)
2550 struct sk_buff
*new_sb
;
2551 if ((new_sb
= dev_alloc_skb(NS_SMSKBSIZE
)) != NULL
)
2553 NS_SKB_CB(new_sb
)->buf_type
= BUF_SM
;
2554 skb_queue_tail(&card
->sbpool
.queue
, new_sb
);
2555 skb_reserve(new_sb
, NS_AAL0_HEADER
);
2556 push_rxbufs(card
, new_sb
);
2559 if (card
->sbfqc
< card
->sbnr
.init
)
2560 #endif /* NS_USE_DESTRUCTORS */
2562 struct sk_buff
*new_sb
;
2563 if ((new_sb
= dev_alloc_skb(NS_SMSKBSIZE
)) != NULL
)
2565 NS_SKB_CB(new_sb
)->buf_type
= BUF_SM
;
2566 skb_queue_tail(&card
->sbpool
.queue
, new_sb
);
2567 skb_reserve(new_sb
, NS_AAL0_HEADER
);
2568 push_rxbufs(card
, new_sb
);
2575 static void dequeue_lg_buf(ns_dev
*card
, struct sk_buff
*lb
)
2577 skb_unlink(lb
, &card
->lbpool
.queue
);
2578 #ifdef NS_USE_DESTRUCTORS
2579 if (card
->lbfqc
< card
->lbnr
.min
)
2581 if (card
->lbfqc
< card
->lbnr
.init
)
2583 struct sk_buff
*new_lb
;
2584 if ((new_lb
= dev_alloc_skb(NS_LGSKBSIZE
)) != NULL
)
2586 NS_SKB_CB(new_lb
)->buf_type
= BUF_LG
;
2587 skb_queue_tail(&card
->lbpool
.queue
, new_lb
);
2588 skb_reserve(new_lb
, NS_SMBUFSIZE
);
2589 push_rxbufs(card
, new_lb
);
2592 if (card
->lbfqc
< card
->lbnr
.init
)
2593 #endif /* NS_USE_DESTRUCTORS */
2595 struct sk_buff
*new_lb
;
2596 if ((new_lb
= dev_alloc_skb(NS_LGSKBSIZE
)) != NULL
)
2598 NS_SKB_CB(new_lb
)->buf_type
= BUF_LG
;
2599 skb_queue_tail(&card
->lbpool
.queue
, new_lb
);
2600 skb_reserve(new_lb
, NS_SMBUFSIZE
);
2601 push_rxbufs(card
, new_lb
);
2608 static int ns_proc_read(struct atm_dev
*dev
, loff_t
*pos
, char *page
)
2615 card
= (ns_dev
*) dev
->dev_data
;
2616 stat
= readl(card
->membase
+ STAT
);
2618 return sprintf(page
, "Pool count min init max \n");
2620 return sprintf(page
, "Small %5d %5d %5d %5d \n",
2621 ns_stat_sfbqc_get(stat
), card
->sbnr
.min
, card
->sbnr
.init
,
2624 return sprintf(page
, "Large %5d %5d %5d %5d \n",
2625 ns_stat_lfbqc_get(stat
), card
->lbnr
.min
, card
->lbnr
.init
,
2628 return sprintf(page
, "Huge %5d %5d %5d %5d \n", card
->hbpool
.count
,
2629 card
->hbnr
.min
, card
->hbnr
.init
, card
->hbnr
.max
);
2631 return sprintf(page
, "Iovec %5d %5d %5d %5d \n", card
->iovpool
.count
,
2632 card
->iovnr
.min
, card
->iovnr
.init
, card
->iovnr
.max
);
2636 retval
= sprintf(page
, "Interrupt counter: %u \n", card
->intcnt
);
2641 /* Dump 25.6 Mbps PHY registers */
2642 /* Now there's a 25.6 Mbps PHY driver this code isn't needed. I left it
2643 here just in case it's needed for debugging. */
2644 if (card
->max_pcr
== ATM_25_PCR
&& !left
--)
2649 for (i
= 0; i
< 4; i
++)
2651 while (CMD_BUSY(card
));
2652 writel(NS_CMD_READ_UTILITY
| 0x00000200 | i
, card
->membase
+ CMD
);
2653 while (CMD_BUSY(card
));
2654 phy_regs
[i
] = readl(card
->membase
+ DR0
) & 0x000000FF;
2657 return sprintf(page
, "PHY regs: 0x%02X 0x%02X 0x%02X 0x%02X \n",
2658 phy_regs
[0], phy_regs
[1], phy_regs
[2], phy_regs
[3]);
2660 #endif /* 0 - Dump 25.6 Mbps PHY registers */
2663 if (left
-- < NS_TST_NUM_ENTRIES
)
2665 if (card
->tste2vc
[left
+ 1] == NULL
)
2666 return sprintf(page
, "%5d - VBR/UBR \n", left
+ 1);
2668 return sprintf(page
, "%5d - %d %d \n", left
+ 1,
2669 card
->tste2vc
[left
+ 1]->tx_vcc
->vpi
,
2670 card
->tste2vc
[left
+ 1]->tx_vcc
->vci
);
2678 static int ns_ioctl(struct atm_dev
*dev
, unsigned int cmd
, void __user
*arg
)
2683 unsigned long flags
;
2685 card
= dev
->dev_data
;
2689 if (get_user(pl
.buftype
, &((pool_levels __user
*) arg
)->buftype
))
2693 case NS_BUFTYPE_SMALL
:
2694 pl
.count
= ns_stat_sfbqc_get(readl(card
->membase
+ STAT
));
2695 pl
.level
.min
= card
->sbnr
.min
;
2696 pl
.level
.init
= card
->sbnr
.init
;
2697 pl
.level
.max
= card
->sbnr
.max
;
2700 case NS_BUFTYPE_LARGE
:
2701 pl
.count
= ns_stat_lfbqc_get(readl(card
->membase
+ STAT
));
2702 pl
.level
.min
= card
->lbnr
.min
;
2703 pl
.level
.init
= card
->lbnr
.init
;
2704 pl
.level
.max
= card
->lbnr
.max
;
2707 case NS_BUFTYPE_HUGE
:
2708 pl
.count
= card
->hbpool
.count
;
2709 pl
.level
.min
= card
->hbnr
.min
;
2710 pl
.level
.init
= card
->hbnr
.init
;
2711 pl
.level
.max
= card
->hbnr
.max
;
2714 case NS_BUFTYPE_IOVEC
:
2715 pl
.count
= card
->iovpool
.count
;
2716 pl
.level
.min
= card
->iovnr
.min
;
2717 pl
.level
.init
= card
->iovnr
.init
;
2718 pl
.level
.max
= card
->iovnr
.max
;
2722 return -ENOIOCTLCMD
;
2725 if (!copy_to_user((pool_levels __user
*) arg
, &pl
, sizeof(pl
)))
2726 return (sizeof(pl
));
2731 if (!capable(CAP_NET_ADMIN
))
2733 if (copy_from_user(&pl
, (pool_levels __user
*) arg
, sizeof(pl
)))
2735 if (pl
.level
.min
>= pl
.level
.init
|| pl
.level
.init
>= pl
.level
.max
)
2737 if (pl
.level
.min
== 0)
2741 case NS_BUFTYPE_SMALL
:
2742 if (pl
.level
.max
> TOP_SB
)
2744 card
->sbnr
.min
= pl
.level
.min
;
2745 card
->sbnr
.init
= pl
.level
.init
;
2746 card
->sbnr
.max
= pl
.level
.max
;
2749 case NS_BUFTYPE_LARGE
:
2750 if (pl
.level
.max
> TOP_LB
)
2752 card
->lbnr
.min
= pl
.level
.min
;
2753 card
->lbnr
.init
= pl
.level
.init
;
2754 card
->lbnr
.max
= pl
.level
.max
;
2757 case NS_BUFTYPE_HUGE
:
2758 if (pl
.level
.max
> TOP_HB
)
2760 card
->hbnr
.min
= pl
.level
.min
;
2761 card
->hbnr
.init
= pl
.level
.init
;
2762 card
->hbnr
.max
= pl
.level
.max
;
2765 case NS_BUFTYPE_IOVEC
:
2766 if (pl
.level
.max
> TOP_IOVB
)
2768 card
->iovnr
.min
= pl
.level
.min
;
2769 card
->iovnr
.init
= pl
.level
.init
;
2770 card
->iovnr
.max
= pl
.level
.max
;
2780 if (!capable(CAP_NET_ADMIN
))
2782 btype
= (long) arg
; /* a long is the same size as a pointer or bigger */
2785 case NS_BUFTYPE_SMALL
:
2786 while (card
->sbfqc
< card
->sbnr
.init
)
2790 sb
= __dev_alloc_skb(NS_SMSKBSIZE
, GFP_KERNEL
);
2793 NS_SKB_CB(sb
)->buf_type
= BUF_SM
;
2794 skb_queue_tail(&card
->sbpool
.queue
, sb
);
2795 skb_reserve(sb
, NS_AAL0_HEADER
);
2796 push_rxbufs(card
, sb
);
2800 case NS_BUFTYPE_LARGE
:
2801 while (card
->lbfqc
< card
->lbnr
.init
)
2805 lb
= __dev_alloc_skb(NS_LGSKBSIZE
, GFP_KERNEL
);
2808 NS_SKB_CB(lb
)->buf_type
= BUF_LG
;
2809 skb_queue_tail(&card
->lbpool
.queue
, lb
);
2810 skb_reserve(lb
, NS_SMBUFSIZE
);
2811 push_rxbufs(card
, lb
);
2815 case NS_BUFTYPE_HUGE
:
2816 while (card
->hbpool
.count
> card
->hbnr
.init
)
2820 spin_lock_irqsave(&card
->int_lock
, flags
);
2821 hb
= skb_dequeue(&card
->hbpool
.queue
);
2822 card
->hbpool
.count
--;
2823 spin_unlock_irqrestore(&card
->int_lock
, flags
);
2825 printk("nicstar%d: huge buffer count inconsistent.\n",
2828 dev_kfree_skb_any(hb
);
2831 while (card
->hbpool
.count
< card
->hbnr
.init
)
2835 hb
= __dev_alloc_skb(NS_HBUFSIZE
, GFP_KERNEL
);
2838 NS_SKB_CB(hb
)->buf_type
= BUF_NONE
;
2839 spin_lock_irqsave(&card
->int_lock
, flags
);
2840 skb_queue_tail(&card
->hbpool
.queue
, hb
);
2841 card
->hbpool
.count
++;
2842 spin_unlock_irqrestore(&card
->int_lock
, flags
);
2846 case NS_BUFTYPE_IOVEC
:
2847 while (card
->iovpool
.count
> card
->iovnr
.init
)
2849 struct sk_buff
*iovb
;
2851 spin_lock_irqsave(&card
->int_lock
, flags
);
2852 iovb
= skb_dequeue(&card
->iovpool
.queue
);
2853 card
->iovpool
.count
--;
2854 spin_unlock_irqrestore(&card
->int_lock
, flags
);
2856 printk("nicstar%d: iovec buffer count inconsistent.\n",
2859 dev_kfree_skb_any(iovb
);
2862 while (card
->iovpool
.count
< card
->iovnr
.init
)
2864 struct sk_buff
*iovb
;
2866 iovb
= alloc_skb(NS_IOVBUFSIZE
, GFP_KERNEL
);
2869 NS_SKB_CB(iovb
)->buf_type
= BUF_NONE
;
2870 spin_lock_irqsave(&card
->int_lock
, flags
);
2871 skb_queue_tail(&card
->iovpool
.queue
, iovb
);
2872 card
->iovpool
.count
++;
2873 spin_unlock_irqrestore(&card
->int_lock
, flags
);
2884 if (dev
->phy
&& dev
->phy
->ioctl
) {
2885 return dev
->phy
->ioctl(dev
, cmd
, arg
);
2888 printk("nicstar%d: %s == NULL \n", card
->index
,
2889 dev
->phy
? "dev->phy->ioctl" : "dev->phy");
2890 return -ENOIOCTLCMD
;
2896 static void which_list(ns_dev
*card
, struct sk_buff
*skb
)
2898 printk("skb buf_type: 0x%08x\n", NS_SKB_CB(skb
)->buf_type
);
2902 static void ns_poll(unsigned long arg
)
2906 unsigned long flags
;
2909 PRINTK("nicstar: Entering ns_poll().\n");
2910 for (i
= 0; i
< num_cards
; i
++)
2913 if (spin_is_locked(&card
->int_lock
)) {
2914 /* Probably it isn't worth spinning */
2917 spin_lock_irqsave(&card
->int_lock
, flags
);
2920 stat_r
= readl(card
->membase
+ STAT
);
2921 if (stat_r
& NS_STAT_TSIF
)
2922 stat_w
|= NS_STAT_TSIF
;
2923 if (stat_r
& NS_STAT_EOPDU
)
2924 stat_w
|= NS_STAT_EOPDU
;
2929 writel(stat_w
, card
->membase
+ STAT
);
2930 spin_unlock_irqrestore(&card
->int_lock
, flags
);
2932 mod_timer(&ns_timer
, jiffies
+ NS_POLL_PERIOD
);
2933 PRINTK("nicstar: Leaving ns_poll().\n");
2938 static int ns_parse_mac(char *mac
, unsigned char *esi
)
2943 if (mac
== NULL
|| esi
== NULL
)
2946 for (i
= 0; i
< 6; i
++)
2948 if ((byte1
= ns_h2i(mac
[j
++])) < 0)
2950 if ((byte0
= ns_h2i(mac
[j
++])) < 0)
2952 esi
[i
] = (unsigned char) (byte1
* 16 + byte0
);
2955 if (mac
[j
++] != ':')
2964 static short ns_h2i(char c
)
2966 if (c
>= '0' && c
<= '9')
2967 return (short) (c
- '0');
2968 if (c
>= 'A' && c
<= 'F')
2969 return (short) (c
- 'A' + 10);
2970 if (c
>= 'a' && c
<= 'f')
2971 return (short) (c
- 'a' + 10);
2977 static void ns_phy_put(struct atm_dev
*dev
, unsigned char value
,
2981 unsigned long flags
;
2983 card
= dev
->dev_data
;
2984 spin_lock_irqsave(&card
->res_lock
, flags
);
2985 while(CMD_BUSY(card
));
2986 writel((unsigned long) value
, card
->membase
+ DR0
);
2987 writel(NS_CMD_WRITE_UTILITY
| 0x00000200 | (addr
& 0x000000FF),
2988 card
->membase
+ CMD
);
2989 spin_unlock_irqrestore(&card
->res_lock
, flags
);
2994 static unsigned char ns_phy_get(struct atm_dev
*dev
, unsigned long addr
)
2997 unsigned long flags
;
3000 card
= dev
->dev_data
;
3001 spin_lock_irqsave(&card
->res_lock
, flags
);
3002 while(CMD_BUSY(card
));
3003 writel(NS_CMD_READ_UTILITY
| 0x00000200 | (addr
& 0x000000FF),
3004 card
->membase
+ CMD
);
3005 while(CMD_BUSY(card
));
3006 data
= readl(card
->membase
+ DR0
) & 0x000000FF;
3007 spin_unlock_irqrestore(&card
->res_lock
, flags
);
3008 return (unsigned char) data
;
3013 module_init(nicstar_init
);
3014 module_exit(nicstar_cleanup
);