blob: 6587dc295eb0e85178a29c11547c0bf04d410de6 [file] [log] [blame]
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * nicstar.c
3 *
4 * Device driver supporting CBR for IDT 77201/77211 "NICStAR" based cards.
5 *
6 * IMPORTANT: The included file nicstarmac.c was NOT WRITTEN BY ME.
7 * It was taken from the frle-0.22 device driver.
8 * As the file doesn't have a copyright notice, in the file
9 * nicstarmac.copyright I put the copyright notice from the
10 * frle-0.22 device driver.
11 * Some code is based on the nicstar driver by M. Welsh.
12 *
13 * Author: Rui Prior (rprior@inescn.pt)
14 * PowerPC support by Jay Talbott (jay_talbott@mcg.mot.com) April 1999
15 *
16 *
17 * (C) INESC 1999
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +000018 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +000020/*
21 * IMPORTANT INFORMATION
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 *
23 * There are currently three types of spinlocks:
24 *
25 * 1 - Per card interrupt spinlock (to protect structures and such)
26 * 2 - Per SCQ scq spinlock
27 * 3 - Per card resource spinlock (to access registers, etc.)
28 *
29 * These must NEVER be grabbed in reverse order.
30 *
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +000031 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +000033/* Header files */
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/kernel.h>
37#include <linux/skbuff.h>
38#include <linux/atmdev.h>
39#include <linux/atm.h>
40#include <linux/pci.h>
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +000041#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/types.h>
43#include <linux/string.h>
44#include <linux/delay.h>
45#include <linux/init.h>
46#include <linux/sched.h>
47#include <linux/timer.h>
48#include <linux/interrupt.h>
49#include <linux/bitops.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090050#include <linux/slab.h>
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +000051#include <linux/idr.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <asm/io.h>
53#include <asm/uaccess.h>
Arun Sharma600634972011-07-26 16:09:06 -070054#include <linux/atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#include "nicstar.h"
56#ifdef CONFIG_ATM_NICSTAR_USE_SUNI
57#include "suni.h"
58#endif /* CONFIG_ATM_NICSTAR_USE_SUNI */
59#ifdef CONFIG_ATM_NICSTAR_USE_IDT77105
60#include "idt77105.h"
61#endif /* CONFIG_ATM_NICSTAR_USE_IDT77105 */
62
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +000063/* Additional code */
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65#include "nicstarmac.c"
66
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +000067/* Configurable parameters */
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69#undef PHY_LOOPBACK
70#undef TX_DEBUG
71#undef RX_DEBUG
72#undef GENERAL_DEBUG
73#undef EXTRA_DEBUG
74
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +000075#undef NS_USE_DESTRUCTORS /* For now keep this undefined unless you know
76 you're going to use only raw ATM */
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +000078/* Do not touch these */
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80#ifdef TX_DEBUG
81#define TXPRINTK(args...) printk(args)
82#else
83#define TXPRINTK(args...)
84#endif /* TX_DEBUG */
85
86#ifdef RX_DEBUG
87#define RXPRINTK(args...) printk(args)
88#else
89#define RXPRINTK(args...)
90#endif /* RX_DEBUG */
91
92#ifdef GENERAL_DEBUG
93#define PRINTK(args...) printk(args)
94#else
95#define PRINTK(args...)
96#endif /* GENERAL_DEBUG */
97
98#ifdef EXTRA_DEBUG
99#define XPRINTK(args...) printk(args)
100#else
101#define XPRINTK(args...)
102#endif /* EXTRA_DEBUG */
103
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000104/* Macros */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106#define CMD_BUSY(card) (readl((card)->membase + STAT) & NS_STAT_CMDBZ)
107
108#define NS_DELAY mdelay(1)
109
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000110#define PTR_DIFF(a, b) ((u32)((unsigned long)(a) - (unsigned long)(b)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
112#ifndef ATM_SKB
113#define ATM_SKB(s) (&(s)->atm)
114#endif
115
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000116#define scq_virt_to_bus(scq, p) \
117 (scq->dma + ((unsigned long)(p) - (unsigned long)(scq)->org))
118
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000119/* Function declarations */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000121static u32 ns_read_sram(ns_dev * card, u32 sram_address);
122static void ns_write_sram(ns_dev * card, u32 sram_address, u32 * value,
123 int count);
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -0800124static int ns_init_card(int i, struct pci_dev *pcidev);
125static void ns_init_card_error(ns_dev * card, int error);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000126static scq_info *get_scq(ns_dev *card, int size, u32 scd);
127static void free_scq(ns_dev *card, scq_info * scq, struct atm_vcc *vcc);
David S. Miller8728b832005-08-09 19:25:21 -0700128static void push_rxbufs(ns_dev *, struct sk_buff *);
David Howells7d12e782006-10-05 14:55:46 +0100129static irqreturn_t ns_irq_handler(int irq, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130static int ns_open(struct atm_vcc *vcc);
131static void ns_close(struct atm_vcc *vcc);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000132static void fill_tst(ns_dev * card, int n, vc_map * vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000134static int push_scqe(ns_dev * card, vc_map * vc, scq_info * scq, ns_scqe * tbd,
135 struct sk_buff *skb);
136static void process_tsq(ns_dev * card);
137static void drain_scq(ns_dev * card, scq_info * scq, int pos);
138static void process_rsq(ns_dev * card);
139static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140#ifdef NS_USE_DESTRUCTORS
141static void ns_sb_destructor(struct sk_buff *sb);
142static void ns_lb_destructor(struct sk_buff *lb);
143static void ns_hb_destructor(struct sk_buff *hb);
144#endif /* NS_USE_DESTRUCTORS */
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000145static void recycle_rx_buf(ns_dev * card, struct sk_buff *skb);
146static void recycle_iovec_rx_bufs(ns_dev * card, struct iovec *iov, int count);
147static void recycle_iov_buf(ns_dev * card, struct sk_buff *iovb);
148static void dequeue_sm_buf(ns_dev * card, struct sk_buff *sb);
149static void dequeue_lg_buf(ns_dev * card, struct sk_buff *lb);
150static int ns_proc_read(struct atm_dev *dev, loff_t * pos, char *page);
151static int ns_ioctl(struct atm_dev *dev, unsigned int cmd, void __user * arg);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000152#ifdef EXTRA_DEBUG
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000153static void which_list(ns_dev * card, struct sk_buff *skb);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000154#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155static void ns_poll(unsigned long arg);
156static int ns_parse_mac(char *mac, unsigned char *esi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157static void ns_phy_put(struct atm_dev *dev, unsigned char value,
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000158 unsigned long addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159static unsigned char ns_phy_get(struct atm_dev *dev, unsigned long addr);
160
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000161/* Global variables */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163static struct ns_dev *cards[NS_MAX_CARDS];
164static unsigned num_cards;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000165static struct atmdev_ops atm_ops = {
166 .open = ns_open,
167 .close = ns_close,
168 .ioctl = ns_ioctl,
169 .send = ns_send,
170 .phy_put = ns_phy_put,
171 .phy_get = ns_phy_get,
172 .proc_read = ns_proc_read,
173 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174};
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000175
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176static struct timer_list ns_timer;
177static char *mac[NS_MAX_CARDS];
178module_param_array(mac, charp, NULL, 0);
179MODULE_LICENSE("GPL");
180
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000181/* Functions */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -0800183static int nicstar_init_one(struct pci_dev *pcidev,
184 const struct pci_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000186 static int index = -1;
187 unsigned int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000189 index++;
190 cards[index] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000192 error = ns_init_card(index, pcidev);
193 if (error) {
194 cards[index--] = NULL; /* don't increment index */
195 goto err_out;
196 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000198 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199err_out:
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000200 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201}
202
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -0800203static void nicstar_remove_one(struct pci_dev *pcidev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000205 int i, j;
206 ns_dev *card = pci_get_drvdata(pcidev);
207 struct sk_buff *hb;
208 struct sk_buff *iovb;
209 struct sk_buff *lb;
210 struct sk_buff *sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000212 i = card->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000214 if (cards[i] == NULL)
215 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000217 if (card->atmdev->phy && card->atmdev->phy->stop)
218 card->atmdev->phy->stop(card->atmdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000220 /* Stop everything */
221 writel(0x00000000, card->membase + CFG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000223 /* De-register device */
224 atm_dev_deregister(card->atmdev);
225
226 /* Disable PCI device */
227 pci_disable_device(pcidev);
228
229 /* Free up resources */
230 j = 0;
231 PRINTK("nicstar%d: freeing %d huge buffers.\n", i, card->hbpool.count);
232 while ((hb = skb_dequeue(&card->hbpool.queue)) != NULL) {
233 dev_kfree_skb_any(hb);
234 j++;
235 }
236 PRINTK("nicstar%d: %d huge buffers freed.\n", i, j);
237 j = 0;
238 PRINTK("nicstar%d: freeing %d iovec buffers.\n", i,
239 card->iovpool.count);
240 while ((iovb = skb_dequeue(&card->iovpool.queue)) != NULL) {
241 dev_kfree_skb_any(iovb);
242 j++;
243 }
244 PRINTK("nicstar%d: %d iovec buffers freed.\n", i, j);
245 while ((lb = skb_dequeue(&card->lbpool.queue)) != NULL)
246 dev_kfree_skb_any(lb);
247 while ((sb = skb_dequeue(&card->sbpool.queue)) != NULL)
248 dev_kfree_skb_any(sb);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000249 free_scq(card, card->scq0, NULL);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000250 for (j = 0; j < NS_FRSCD_NUM; j++) {
251 if (card->scd2vc[j] != NULL)
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000252 free_scq(card, card->scd2vc[j]->scq, card->scd2vc[j]->tx_vcc);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000253 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000254 idr_destroy(&card->idr);
255 pci_free_consistent(card->pcidev, NS_RSQSIZE + NS_RSQ_ALIGNMENT,
256 card->rsq.org, card->rsq.dma);
257 pci_free_consistent(card->pcidev, NS_TSQSIZE + NS_TSQ_ALIGNMENT,
258 card->tsq.org, card->tsq.dma);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000259 free_irq(card->pcidev->irq, card);
260 iounmap(card->membase);
261 kfree(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262}
263
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -0800264static struct pci_device_id nicstar_pci_tbl[] = {
Peter Huewe6df7b802010-07-15 08:48:26 +0000265 { PCI_VDEVICE(IDT, PCI_DEVICE_ID_IDT_IDT77201), 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 {0,} /* terminate list */
267};
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000268
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269MODULE_DEVICE_TABLE(pci, nicstar_pci_tbl);
270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271static struct pci_driver nicstar_driver = {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000272 .name = "nicstar",
273 .id_table = nicstar_pci_tbl,
274 .probe = nicstar_init_one,
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -0800275 .remove = nicstar_remove_one,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276};
277
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278static int __init nicstar_init(void)
279{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000280 unsigned error = 0; /* Initialized to remove compile warning */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000282 XPRINTK("nicstar: nicstar_init() called.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000284 error = pci_register_driver(&nicstar_driver);
285
286 TXPRINTK("nicstar: TX debug enabled.\n");
287 RXPRINTK("nicstar: RX debug enabled.\n");
288 PRINTK("nicstar: General debug enabled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289#ifdef PHY_LOOPBACK
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000290 printk("nicstar: using PHY loopback.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291#endif /* PHY_LOOPBACK */
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000292 XPRINTK("nicstar: nicstar_init() returned.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000294 if (!error) {
295 init_timer(&ns_timer);
296 ns_timer.expires = jiffies + NS_POLL_PERIOD;
297 ns_timer.data = 0UL;
298 ns_timer.function = ns_poll;
299 add_timer(&ns_timer);
300 }
301
302 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303}
304
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305static void __exit nicstar_cleanup(void)
306{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000307 XPRINTK("nicstar: nicstar_cleanup() called.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000309 del_timer(&ns_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000311 pci_unregister_driver(&nicstar_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000313 XPRINTK("nicstar: nicstar_cleanup() returned.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314}
315
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000316static u32 ns_read_sram(ns_dev * card, u32 sram_address)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000318 unsigned long flags;
319 u32 data;
320 sram_address <<= 2;
321 sram_address &= 0x0007FFFC; /* address must be dword aligned */
322 sram_address |= 0x50000000; /* SRAM read command */
323 spin_lock_irqsave(&card->res_lock, flags);
324 while (CMD_BUSY(card)) ;
325 writel(sram_address, card->membase + CMD);
326 while (CMD_BUSY(card)) ;
327 data = readl(card->membase + DR0);
328 spin_unlock_irqrestore(&card->res_lock, flags);
329 return data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330}
331
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000332static void ns_write_sram(ns_dev * card, u32 sram_address, u32 * value,
333 int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000335 unsigned long flags;
336 int i, c;
337 count--; /* count range now is 0..3 instead of 1..4 */
338 c = count;
339 c <<= 2; /* to use increments of 4 */
340 spin_lock_irqsave(&card->res_lock, flags);
341 while (CMD_BUSY(card)) ;
342 for (i = 0; i <= c; i += 4)
343 writel(*(value++), card->membase + i);
344 /* Note: DR# registers are the first 4 dwords in nicstar's memspace,
345 so card->membase + DR0 == card->membase */
346 sram_address <<= 2;
347 sram_address &= 0x0007FFFC;
348 sram_address |= (0x40000000 | count);
349 writel(sram_address, card->membase + CMD);
350 spin_unlock_irqrestore(&card->res_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351}
352
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -0800353static int ns_init_card(int i, struct pci_dev *pcidev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000355 int j;
356 struct ns_dev *card = NULL;
357 unsigned char pci_latency;
358 unsigned error;
359 u32 data;
360 u32 u32d[4];
361 u32 ns_cfg_rctsize;
362 int bcount;
363 unsigned long membase;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000365 error = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000367 if (pci_enable_device(pcidev)) {
368 printk("nicstar%d: can't enable PCI device\n", i);
369 error = 2;
370 ns_init_card_error(card, error);
371 return error;
372 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000373 if ((pci_set_dma_mask(pcidev, DMA_BIT_MASK(32)) != 0) ||
374 (pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(32)) != 0)) {
375 printk(KERN_WARNING
376 "nicstar%d: No suitable DMA available.\n", i);
377 error = 2;
378 ns_init_card_error(card, error);
379 return error;
380 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000382 if ((card = kmalloc(sizeof(ns_dev), GFP_KERNEL)) == NULL) {
383 printk
384 ("nicstar%d: can't allocate memory for device structure.\n",
385 i);
386 error = 2;
387 ns_init_card_error(card, error);
388 return error;
389 }
390 cards[i] = card;
391 spin_lock_init(&card->int_lock);
392 spin_lock_init(&card->res_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000394 pci_set_drvdata(pcidev, card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000396 card->index = i;
397 card->atmdev = NULL;
398 card->pcidev = pcidev;
399 membase = pci_resource_start(pcidev, 1);
400 card->membase = ioremap(membase, NS_IOREMAP_SIZE);
401 if (!card->membase) {
402 printk("nicstar%d: can't ioremap() membase.\n", i);
403 error = 3;
404 ns_init_card_error(card, error);
405 return error;
406 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000407 PRINTK("nicstar%d: membase at 0x%p.\n", i, card->membase);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000408
409 pci_set_master(pcidev);
410
411 if (pci_read_config_byte(pcidev, PCI_LATENCY_TIMER, &pci_latency) != 0) {
412 printk("nicstar%d: can't read PCI latency timer.\n", i);
413 error = 6;
414 ns_init_card_error(card, error);
415 return error;
416 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417#ifdef NS_PCI_LATENCY
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000418 if (pci_latency < NS_PCI_LATENCY) {
419 PRINTK("nicstar%d: setting PCI latency timer to %d.\n", i,
420 NS_PCI_LATENCY);
421 for (j = 1; j < 4; j++) {
422 if (pci_write_config_byte
423 (pcidev, PCI_LATENCY_TIMER, NS_PCI_LATENCY) != 0)
424 break;
425 }
426 if (j == 4) {
427 printk
428 ("nicstar%d: can't set PCI latency timer to %d.\n",
429 i, NS_PCI_LATENCY);
430 error = 7;
431 ns_init_card_error(card, error);
432 return error;
433 }
434 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435#endif /* NS_PCI_LATENCY */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000437 /* Clear timer overflow */
438 data = readl(card->membase + STAT);
439 if (data & NS_STAT_TMROF)
440 writel(NS_STAT_TMROF, card->membase + STAT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000442 /* Software reset */
443 writel(NS_CFG_SWRST, card->membase + CFG);
444 NS_DELAY;
445 writel(0x00000000, card->membase + CFG);
446
447 /* PHY reset */
448 writel(0x00000008, card->membase + GP);
449 NS_DELAY;
450 writel(0x00000001, card->membase + GP);
451 NS_DELAY;
452 while (CMD_BUSY(card)) ;
453 writel(NS_CMD_WRITE_UTILITY | 0x00000100, card->membase + CMD); /* Sync UTOPIA with SAR clock */
454 NS_DELAY;
455
456 /* Detect PHY type */
457 while (CMD_BUSY(card)) ;
458 writel(NS_CMD_READ_UTILITY | 0x00000200, card->membase + CMD);
459 while (CMD_BUSY(card)) ;
460 data = readl(card->membase + DR0);
461 switch (data) {
462 case 0x00000009:
463 printk("nicstar%d: PHY seems to be 25 Mbps.\n", i);
464 card->max_pcr = ATM_25_PCR;
465 while (CMD_BUSY(card)) ;
466 writel(0x00000008, card->membase + DR0);
467 writel(NS_CMD_WRITE_UTILITY | 0x00000200, card->membase + CMD);
468 /* Clear an eventual pending interrupt */
469 writel(NS_STAT_SFBQF, card->membase + STAT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470#ifdef PHY_LOOPBACK
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000471 while (CMD_BUSY(card)) ;
472 writel(0x00000022, card->membase + DR0);
473 writel(NS_CMD_WRITE_UTILITY | 0x00000202, card->membase + CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474#endif /* PHY_LOOPBACK */
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000475 break;
476 case 0x00000030:
477 case 0x00000031:
478 printk("nicstar%d: PHY seems to be 155 Mbps.\n", i);
479 card->max_pcr = ATM_OC3_PCR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480#ifdef PHY_LOOPBACK
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000481 while (CMD_BUSY(card)) ;
482 writel(0x00000002, card->membase + DR0);
483 writel(NS_CMD_WRITE_UTILITY | 0x00000205, card->membase + CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484#endif /* PHY_LOOPBACK */
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000485 break;
486 default:
487 printk("nicstar%d: unknown PHY type (0x%08X).\n", i, data);
488 error = 8;
489 ns_init_card_error(card, error);
490 return error;
491 }
492 writel(0x00000000, card->membase + GP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000494 /* Determine SRAM size */
495 data = 0x76543210;
496 ns_write_sram(card, 0x1C003, &data, 1);
497 data = 0x89ABCDEF;
498 ns_write_sram(card, 0x14003, &data, 1);
499 if (ns_read_sram(card, 0x14003) == 0x89ABCDEF &&
500 ns_read_sram(card, 0x1C003) == 0x76543210)
501 card->sram_size = 128;
502 else
503 card->sram_size = 32;
504 PRINTK("nicstar%d: %dK x 32bit SRAM size.\n", i, card->sram_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000506 card->rct_size = NS_MAX_RCTSIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
508#if (NS_MAX_RCTSIZE == 4096)
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000509 if (card->sram_size == 128)
510 printk
511 ("nicstar%d: limiting maximum VCI. See NS_MAX_RCTSIZE in nicstar.h\n",
512 i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513#elif (NS_MAX_RCTSIZE == 16384)
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000514 if (card->sram_size == 32) {
515 printk
516 ("nicstar%d: wasting memory. See NS_MAX_RCTSIZE in nicstar.h\n",
517 i);
518 card->rct_size = 4096;
519 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520#else
521#error NS_MAX_RCTSIZE must be either 4096 or 16384 in nicstar.c
522#endif
523
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000524 card->vpibits = NS_VPIBITS;
525 if (card->rct_size == 4096)
526 card->vcibits = 12 - NS_VPIBITS;
527 else /* card->rct_size == 16384 */
528 card->vcibits = 14 - NS_VPIBITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000530 /* Initialize the nicstar eeprom/eprom stuff, for the MAC addr */
531 if (mac[i] == NULL)
532 nicstar_init_eprom(card->membase);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000534 /* Set the VPI/VCI MSb mask to zero so we can receive OAM cells */
535 writel(0x00000000, card->membase + VPM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000537 /* Initialize TSQ */
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000538 card->tsq.org = pci_alloc_consistent(card->pcidev,
539 NS_TSQSIZE + NS_TSQ_ALIGNMENT,
540 &card->tsq.dma);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000541 if (card->tsq.org == NULL) {
542 printk("nicstar%d: can't allocate TSQ.\n", i);
543 error = 10;
544 ns_init_card_error(card, error);
545 return error;
546 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000547 card->tsq.base = PTR_ALIGN(card->tsq.org, NS_TSQ_ALIGNMENT);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000548 card->tsq.next = card->tsq.base;
549 card->tsq.last = card->tsq.base + (NS_TSQ_NUM_ENTRIES - 1);
550 for (j = 0; j < NS_TSQ_NUM_ENTRIES; j++)
551 ns_tsi_init(card->tsq.base + j);
552 writel(0x00000000, card->membase + TSQH);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000553 writel(ALIGN(card->tsq.dma, NS_TSQ_ALIGNMENT), card->membase + TSQB);
554 PRINTK("nicstar%d: TSQ base at 0x%p.\n", i, card->tsq.base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000556 /* Initialize RSQ */
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000557 card->rsq.org = pci_alloc_consistent(card->pcidev,
558 NS_RSQSIZE + NS_RSQ_ALIGNMENT,
559 &card->rsq.dma);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000560 if (card->rsq.org == NULL) {
561 printk("nicstar%d: can't allocate RSQ.\n", i);
562 error = 11;
563 ns_init_card_error(card, error);
564 return error;
565 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000566 card->rsq.base = PTR_ALIGN(card->rsq.org, NS_RSQ_ALIGNMENT);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000567 card->rsq.next = card->rsq.base;
568 card->rsq.last = card->rsq.base + (NS_RSQ_NUM_ENTRIES - 1);
569 for (j = 0; j < NS_RSQ_NUM_ENTRIES; j++)
570 ns_rsqe_init(card->rsq.base + j);
571 writel(0x00000000, card->membase + RSQH);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000572 writel(ALIGN(card->rsq.dma, NS_RSQ_ALIGNMENT), card->membase + RSQB);
573 PRINTK("nicstar%d: RSQ base at 0x%p.\n", i, card->rsq.base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000575 /* Initialize SCQ0, the only VBR SCQ used */
576 card->scq1 = NULL;
577 card->scq2 = NULL;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000578 card->scq0 = get_scq(card, VBR_SCQSIZE, NS_VRSCD0);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000579 if (card->scq0 == NULL) {
580 printk("nicstar%d: can't get SCQ0.\n", i);
581 error = 12;
582 ns_init_card_error(card, error);
583 return error;
584 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000585 u32d[0] = scq_virt_to_bus(card->scq0, card->scq0->base);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000586 u32d[1] = (u32) 0x00000000;
587 u32d[2] = (u32) 0xffffffff;
588 u32d[3] = (u32) 0x00000000;
589 ns_write_sram(card, NS_VRSCD0, u32d, 4);
590 ns_write_sram(card, NS_VRSCD1, u32d, 4); /* These last two won't be used */
591 ns_write_sram(card, NS_VRSCD2, u32d, 4); /* but are initialized, just in case... */
592 card->scq0->scd = NS_VRSCD0;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000593 PRINTK("nicstar%d: VBR-SCQ0 base at 0x%p.\n", i, card->scq0->base);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000594
595 /* Initialize TSTs */
596 card->tst_addr = NS_TST0;
597 card->tst_free_entries = NS_TST_NUM_ENTRIES;
598 data = NS_TST_OPCODE_VARIABLE;
599 for (j = 0; j < NS_TST_NUM_ENTRIES; j++)
600 ns_write_sram(card, NS_TST0 + j, &data, 1);
601 data = ns_tste_make(NS_TST_OPCODE_END, NS_TST0);
602 ns_write_sram(card, NS_TST0 + NS_TST_NUM_ENTRIES, &data, 1);
603 for (j = 0; j < NS_TST_NUM_ENTRIES; j++)
604 ns_write_sram(card, NS_TST1 + j, &data, 1);
605 data = ns_tste_make(NS_TST_OPCODE_END, NS_TST1);
606 ns_write_sram(card, NS_TST1 + NS_TST_NUM_ENTRIES, &data, 1);
607 for (j = 0; j < NS_TST_NUM_ENTRIES; j++)
608 card->tste2vc[j] = NULL;
609 writel(NS_TST0 << 2, card->membase + TSTB);
610
611 /* Initialize RCT. AAL type is set on opening the VC. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612#ifdef RCQ_SUPPORT
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000613 u32d[0] = NS_RCTE_RAWCELLINTEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614#else
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000615 u32d[0] = 0x00000000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616#endif /* RCQ_SUPPORT */
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000617 u32d[1] = 0x00000000;
618 u32d[2] = 0x00000000;
619 u32d[3] = 0xFFFFFFFF;
620 for (j = 0; j < card->rct_size; j++)
621 ns_write_sram(card, j * 4, u32d, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000623 memset(card->vcmap, 0, NS_MAX_RCTSIZE * sizeof(vc_map));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000625 for (j = 0; j < NS_FRSCD_NUM; j++)
626 card->scd2vc[j] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000628 /* Initialize buffer levels */
629 card->sbnr.min = MIN_SB;
630 card->sbnr.init = NUM_SB;
631 card->sbnr.max = MAX_SB;
632 card->lbnr.min = MIN_LB;
633 card->lbnr.init = NUM_LB;
634 card->lbnr.max = MAX_LB;
635 card->iovnr.min = MIN_IOVB;
636 card->iovnr.init = NUM_IOVB;
637 card->iovnr.max = MAX_IOVB;
638 card->hbnr.min = MIN_HB;
639 card->hbnr.init = NUM_HB;
640 card->hbnr.max = MAX_HB;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000642 card->sm_handle = 0x00000000;
643 card->sm_addr = 0x00000000;
644 card->lg_handle = 0x00000000;
645 card->lg_addr = 0x00000000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000647 card->efbie = 1; /* To prevent push_rxbufs from enabling the interrupt */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000649 idr_init(&card->idr);
650
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000651 /* Pre-allocate some huge buffers */
652 skb_queue_head_init(&card->hbpool.queue);
653 card->hbpool.count = 0;
654 for (j = 0; j < NUM_HB; j++) {
655 struct sk_buff *hb;
656 hb = __dev_alloc_skb(NS_HBUFSIZE, GFP_KERNEL);
657 if (hb == NULL) {
658 printk
659 ("nicstar%d: can't allocate %dth of %d huge buffers.\n",
660 i, j, NUM_HB);
661 error = 13;
662 ns_init_card_error(card, error);
663 return error;
664 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000665 NS_PRV_BUFTYPE(hb) = BUF_NONE;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000666 skb_queue_tail(&card->hbpool.queue, hb);
667 card->hbpool.count++;
668 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000670 /* Allocate large buffers */
671 skb_queue_head_init(&card->lbpool.queue);
672 card->lbpool.count = 0; /* Not used */
673 for (j = 0; j < NUM_LB; j++) {
674 struct sk_buff *lb;
675 lb = __dev_alloc_skb(NS_LGSKBSIZE, GFP_KERNEL);
676 if (lb == NULL) {
677 printk
678 ("nicstar%d: can't allocate %dth of %d large buffers.\n",
679 i, j, NUM_LB);
680 error = 14;
681 ns_init_card_error(card, error);
682 return error;
683 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000684 NS_PRV_BUFTYPE(lb) = BUF_LG;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000685 skb_queue_tail(&card->lbpool.queue, lb);
686 skb_reserve(lb, NS_SMBUFSIZE);
687 push_rxbufs(card, lb);
688 /* Due to the implementation of push_rxbufs() this is 1, not 0 */
689 if (j == 1) {
690 card->rcbuf = lb;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000691 card->rawcell = (struct ns_rcqe *) lb->data;
692 card->rawch = NS_PRV_DMA(lb);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000693 }
694 }
695 /* Test for strange behaviour which leads to crashes */
696 if ((bcount =
697 ns_stat_lfbqc_get(readl(card->membase + STAT))) < card->lbnr.min) {
698 printk
699 ("nicstar%d: Strange... Just allocated %d large buffers and lfbqc = %d.\n",
700 i, j, bcount);
701 error = 14;
702 ns_init_card_error(card, error);
703 return error;
704 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000706 /* Allocate small buffers */
707 skb_queue_head_init(&card->sbpool.queue);
708 card->sbpool.count = 0; /* Not used */
709 for (j = 0; j < NUM_SB; j++) {
710 struct sk_buff *sb;
711 sb = __dev_alloc_skb(NS_SMSKBSIZE, GFP_KERNEL);
712 if (sb == NULL) {
713 printk
714 ("nicstar%d: can't allocate %dth of %d small buffers.\n",
715 i, j, NUM_SB);
716 error = 15;
717 ns_init_card_error(card, error);
718 return error;
719 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000720 NS_PRV_BUFTYPE(sb) = BUF_SM;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000721 skb_queue_tail(&card->sbpool.queue, sb);
722 skb_reserve(sb, NS_AAL0_HEADER);
723 push_rxbufs(card, sb);
724 }
725 /* Test for strange behaviour which leads to crashes */
726 if ((bcount =
727 ns_stat_sfbqc_get(readl(card->membase + STAT))) < card->sbnr.min) {
728 printk
729 ("nicstar%d: Strange... Just allocated %d small buffers and sfbqc = %d.\n",
730 i, j, bcount);
731 error = 15;
732 ns_init_card_error(card, error);
733 return error;
734 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000736 /* Allocate iovec buffers */
737 skb_queue_head_init(&card->iovpool.queue);
738 card->iovpool.count = 0;
739 for (j = 0; j < NUM_IOVB; j++) {
740 struct sk_buff *iovb;
741 iovb = alloc_skb(NS_IOVBUFSIZE, GFP_KERNEL);
742 if (iovb == NULL) {
743 printk
744 ("nicstar%d: can't allocate %dth of %d iovec buffers.\n",
745 i, j, NUM_IOVB);
746 error = 16;
747 ns_init_card_error(card, error);
748 return error;
749 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000750 NS_PRV_BUFTYPE(iovb) = BUF_NONE;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000751 skb_queue_tail(&card->iovpool.queue, iovb);
752 card->iovpool.count++;
753 }
Chas Williams52961952008-01-07 00:26:22 -0800754
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000755 /* Configure NICStAR */
756 if (card->rct_size == 4096)
757 ns_cfg_rctsize = NS_CFG_RCTSIZE_4096_ENTRIES;
758 else /* (card->rct_size == 16384) */
759 ns_cfg_rctsize = NS_CFG_RCTSIZE_16384_ENTRIES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000761 card->efbie = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000763 card->intcnt = 0;
764 if (request_irq
chas williams - CONTRACTOR06df2772010-07-10 03:42:02 +0000765 (pcidev->irq, &ns_irq_handler, IRQF_SHARED, "nicstar", card) != 0) {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000766 printk("nicstar%d: can't allocate IRQ %d.\n", i, pcidev->irq);
767 error = 9;
768 ns_init_card_error(card, error);
769 return error;
770 }
771
772 /* Register device */
Dan Williamsd9ca6762010-12-08 19:40:47 +0000773 card->atmdev = atm_dev_register("nicstar", &card->pcidev->dev, &atm_ops,
774 -1, NULL);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000775 if (card->atmdev == NULL) {
776 printk("nicstar%d: can't register device.\n", i);
777 error = 17;
778 ns_init_card_error(card, error);
779 return error;
780 }
781
782 if (ns_parse_mac(mac[i], card->atmdev->esi)) {
783 nicstar_read_eprom(card->membase, NICSTAR_EPROM_MAC_ADDR_OFFSET,
784 card->atmdev->esi, 6);
785 if (memcmp(card->atmdev->esi, "\x00\x00\x00\x00\x00\x00", 6) ==
786 0) {
787 nicstar_read_eprom(card->membase,
788 NICSTAR_EPROM_MAC_ADDR_OFFSET_ALT,
789 card->atmdev->esi, 6);
790 }
791 }
792
793 printk("nicstar%d: MAC address %pM\n", i, card->atmdev->esi);
794
795 card->atmdev->dev_data = card;
796 card->atmdev->ci_range.vpi_bits = card->vpibits;
797 card->atmdev->ci_range.vci_bits = card->vcibits;
798 card->atmdev->link_rate = card->max_pcr;
799 card->atmdev->phy = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800
801#ifdef CONFIG_ATM_NICSTAR_USE_SUNI
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000802 if (card->max_pcr == ATM_OC3_PCR)
803 suni_init(card->atmdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804#endif /* CONFIG_ATM_NICSTAR_USE_SUNI */
805
806#ifdef CONFIG_ATM_NICSTAR_USE_IDT77105
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000807 if (card->max_pcr == ATM_25_PCR)
808 idt77105_init(card->atmdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809#endif /* CONFIG_ATM_NICSTAR_USE_IDT77105 */
810
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000811 if (card->atmdev->phy && card->atmdev->phy->start)
812 card->atmdev->phy->start(card->atmdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000814 writel(NS_CFG_RXPATH | NS_CFG_SMBUFSIZE | NS_CFG_LGBUFSIZE | NS_CFG_EFBIE | NS_CFG_RSQSIZE | NS_CFG_VPIBITS | ns_cfg_rctsize | NS_CFG_RXINT_NODELAY | NS_CFG_RAWIE | /* Only enabled if RCQ_SUPPORT */
815 NS_CFG_RSQAFIE | NS_CFG_TXEN | NS_CFG_TXIE | NS_CFG_TSQFIE_OPT | /* Only enabled if ENABLE_TSQFIE */
816 NS_CFG_PHYIE, card->membase + CFG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000818 num_cards++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000820 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821}
822
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -0800823static void ns_init_card_error(ns_dev *card, int error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000825 if (error >= 17) {
826 writel(0x00000000, card->membase + CFG);
827 }
828 if (error >= 16) {
829 struct sk_buff *iovb;
830 while ((iovb = skb_dequeue(&card->iovpool.queue)) != NULL)
831 dev_kfree_skb_any(iovb);
832 }
833 if (error >= 15) {
834 struct sk_buff *sb;
835 while ((sb = skb_dequeue(&card->sbpool.queue)) != NULL)
836 dev_kfree_skb_any(sb);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000837 free_scq(card, card->scq0, NULL);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000838 }
839 if (error >= 14) {
840 struct sk_buff *lb;
841 while ((lb = skb_dequeue(&card->lbpool.queue)) != NULL)
842 dev_kfree_skb_any(lb);
843 }
844 if (error >= 13) {
845 struct sk_buff *hb;
846 while ((hb = skb_dequeue(&card->hbpool.queue)) != NULL)
847 dev_kfree_skb_any(hb);
848 }
849 if (error >= 12) {
850 kfree(card->rsq.org);
851 }
852 if (error >= 11) {
853 kfree(card->tsq.org);
854 }
855 if (error >= 10) {
856 free_irq(card->pcidev->irq, card);
857 }
858 if (error >= 4) {
859 iounmap(card->membase);
860 }
861 if (error >= 3) {
862 pci_disable_device(card->pcidev);
863 kfree(card);
864 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865}
866
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000867static scq_info *get_scq(ns_dev *card, int size, u32 scd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000869 scq_info *scq;
870 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000872 if (size != VBR_SCQSIZE && size != CBR_SCQSIZE)
873 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000875 scq = kmalloc(sizeof(scq_info), GFP_KERNEL);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000876 if (!scq)
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000877 return NULL;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000878 scq->org = pci_alloc_consistent(card->pcidev, 2 * size, &scq->dma);
879 if (!scq->org) {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000880 kfree(scq);
881 return NULL;
882 }
883 scq->skb = kmalloc(sizeof(struct sk_buff *) *
884 (size / NS_SCQE_SIZE), GFP_KERNEL);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000885 if (!scq->skb) {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000886 kfree(scq->org);
887 kfree(scq);
888 return NULL;
889 }
890 scq->num_entries = size / NS_SCQE_SIZE;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000891 scq->base = PTR_ALIGN(scq->org, size);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000892 scq->next = scq->base;
893 scq->last = scq->base + (scq->num_entries - 1);
894 scq->tail = scq->last;
895 scq->scd = scd;
896 scq->num_entries = size / NS_SCQE_SIZE;
897 scq->tbd_count = 0;
898 init_waitqueue_head(&scq->scqfull_waitq);
899 scq->full = 0;
900 spin_lock_init(&scq->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000902 for (i = 0; i < scq->num_entries; i++)
903 scq->skb[i] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000905 return scq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906}
907
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908/* For variable rate SCQ vcc must be NULL */
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000909static void free_scq(ns_dev *card, scq_info *scq, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000911 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000913 if (scq->num_entries == VBR_SCQ_NUM_ENTRIES)
914 for (i = 0; i < scq->num_entries; i++) {
915 if (scq->skb[i] != NULL) {
916 vcc = ATM_SKB(scq->skb[i])->vcc;
917 if (vcc->pop != NULL)
918 vcc->pop(vcc, scq->skb[i]);
919 else
920 dev_kfree_skb_any(scq->skb[i]);
921 }
922 } else { /* vcc must be != NULL */
923
924 if (vcc == NULL) {
925 printk
926 ("nicstar: free_scq() called with vcc == NULL for fixed rate scq.");
927 for (i = 0; i < scq->num_entries; i++)
928 dev_kfree_skb_any(scq->skb[i]);
929 } else
930 for (i = 0; i < scq->num_entries; i++) {
931 if (scq->skb[i] != NULL) {
932 if (vcc->pop != NULL)
933 vcc->pop(vcc, scq->skb[i]);
934 else
935 dev_kfree_skb_any(scq->skb[i]);
936 }
937 }
938 }
939 kfree(scq->skb);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000940 pci_free_consistent(card->pcidev,
941 2 * (scq->num_entries == VBR_SCQ_NUM_ENTRIES ?
942 VBR_SCQSIZE : CBR_SCQSIZE),
943 scq->org, scq->dma);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000944 kfree(scq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945}
946
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947/* The handles passed must be pointers to the sk_buff containing the small
948 or large buffer(s) cast to u32. */
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000949static void push_rxbufs(ns_dev * card, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950{
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000951 struct sk_buff *handle1, *handle2;
Tejun Heob051f6e2013-02-27 17:04:00 -0800952 int id1, id2;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000953 u32 addr1, addr2;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000954 u32 stat;
955 unsigned long flags;
956
957 /* *BARF* */
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000958 handle2 = NULL;
959 addr2 = 0;
960 handle1 = skb;
961 addr1 = pci_map_single(card->pcidev,
962 skb->data,
963 (NS_PRV_BUFTYPE(skb) == BUF_SM
964 ? NS_SMSKBSIZE : NS_LGSKBSIZE),
965 PCI_DMA_TODEVICE);
966 NS_PRV_DMA(skb) = addr1; /* save so we can unmap later */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967
968#ifdef GENERAL_DEBUG
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000969 if (!addr1)
970 printk("nicstar%d: push_rxbufs called with addr1 = 0.\n",
971 card->index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972#endif /* GENERAL_DEBUG */
973
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000974 stat = readl(card->membase + STAT);
975 card->sbfqc = ns_stat_sfbqc_get(stat);
976 card->lbfqc = ns_stat_lfbqc_get(stat);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000977 if (NS_PRV_BUFTYPE(skb) == BUF_SM) {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000978 if (!addr2) {
979 if (card->sm_addr) {
980 addr2 = card->sm_addr;
981 handle2 = card->sm_handle;
982 card->sm_addr = 0x00000000;
983 card->sm_handle = 0x00000000;
984 } else { /* (!sm_addr) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000986 card->sm_addr = addr1;
987 card->sm_handle = handle1;
988 }
989 }
990 } else { /* buf_type == BUF_LG */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000992 if (!addr2) {
993 if (card->lg_addr) {
994 addr2 = card->lg_addr;
995 handle2 = card->lg_handle;
996 card->lg_addr = 0x00000000;
997 card->lg_handle = 0x00000000;
998 } else { /* (!lg_addr) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001000 card->lg_addr = addr1;
1001 card->lg_handle = handle1;
1002 }
1003 }
1004 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001006 if (addr2) {
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001007 if (NS_PRV_BUFTYPE(skb) == BUF_SM) {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001008 if (card->sbfqc >= card->sbnr.max) {
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001009 skb_unlink(handle1, &card->sbpool.queue);
1010 dev_kfree_skb_any(handle1);
1011 skb_unlink(handle2, &card->sbpool.queue);
1012 dev_kfree_skb_any(handle2);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001013 return;
1014 } else
1015 card->sbfqc += 2;
1016 } else { /* (buf_type == BUF_LG) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001018 if (card->lbfqc >= card->lbnr.max) {
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001019 skb_unlink(handle1, &card->lbpool.queue);
1020 dev_kfree_skb_any(handle1);
1021 skb_unlink(handle2, &card->lbpool.queue);
1022 dev_kfree_skb_any(handle2);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001023 return;
1024 } else
1025 card->lbfqc += 2;
1026 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027
Tejun Heob051f6e2013-02-27 17:04:00 -08001028 id1 = idr_alloc(&card->idr, handle1, 0, 0, GFP_ATOMIC);
1029 if (id1 < 0)
1030 goto out;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001031
Tejun Heob051f6e2013-02-27 17:04:00 -08001032 id2 = idr_alloc(&card->idr, handle2, 0, 0, GFP_ATOMIC);
1033 if (id2 < 0)
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001034 goto out;
1035
1036 spin_lock_irqsave(&card->res_lock, flags);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001037 while (CMD_BUSY(card)) ;
1038 writel(addr2, card->membase + DR3);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001039 writel(id2, card->membase + DR2);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001040 writel(addr1, card->membase + DR1);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001041 writel(id1, card->membase + DR0);
1042 writel(NS_CMD_WRITE_FREEBUFQ | NS_PRV_BUFTYPE(skb),
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001043 card->membase + CMD);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001044 spin_unlock_irqrestore(&card->res_lock, flags);
1045
1046 XPRINTK("nicstar%d: Pushing %s buffers at 0x%x and 0x%x.\n",
1047 card->index,
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001048 (NS_PRV_BUFTYPE(skb) == BUF_SM ? "small" : "large"),
1049 addr1, addr2);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001050 }
1051
1052 if (!card->efbie && card->sbfqc >= card->sbnr.min &&
1053 card->lbfqc >= card->lbnr.min) {
1054 card->efbie = 1;
1055 writel((readl(card->membase + CFG) | NS_CFG_EFBIE),
1056 card->membase + CFG);
1057 }
1058
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001059out:
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001060 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061}
1062
David Howells7d12e782006-10-05 14:55:46 +01001063static irqreturn_t ns_irq_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001065 u32 stat_r;
1066 ns_dev *card;
1067 struct atm_dev *dev;
1068 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001070 card = (ns_dev *) dev_id;
1071 dev = card->atmdev;
1072 card->intcnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001074 PRINTK("nicstar%d: NICStAR generated an interrupt\n", card->index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001076 spin_lock_irqsave(&card->int_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001078 stat_r = readl(card->membase + STAT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001080 /* Transmit Status Indicator has been written to T. S. Queue */
1081 if (stat_r & NS_STAT_TSIF) {
1082 TXPRINTK("nicstar%d: TSI interrupt\n", card->index);
1083 process_tsq(card);
1084 writel(NS_STAT_TSIF, card->membase + STAT);
1085 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001087 /* Incomplete CS-PDU has been transmitted */
1088 if (stat_r & NS_STAT_TXICP) {
1089 writel(NS_STAT_TXICP, card->membase + STAT);
1090 TXPRINTK("nicstar%d: Incomplete CS-PDU transmitted.\n",
1091 card->index);
1092 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001094 /* Transmit Status Queue 7/8 full */
1095 if (stat_r & NS_STAT_TSQF) {
1096 writel(NS_STAT_TSQF, card->membase + STAT);
1097 PRINTK("nicstar%d: TSQ full.\n", card->index);
1098 process_tsq(card);
1099 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001101 /* Timer overflow */
1102 if (stat_r & NS_STAT_TMROF) {
1103 writel(NS_STAT_TMROF, card->membase + STAT);
1104 PRINTK("nicstar%d: Timer overflow.\n", card->index);
1105 }
1106
1107 /* PHY device interrupt signal active */
1108 if (stat_r & NS_STAT_PHYI) {
1109 writel(NS_STAT_PHYI, card->membase + STAT);
1110 PRINTK("nicstar%d: PHY interrupt.\n", card->index);
1111 if (dev->phy && dev->phy->interrupt) {
1112 dev->phy->interrupt(dev);
1113 }
1114 }
1115
1116 /* Small Buffer Queue is full */
1117 if (stat_r & NS_STAT_SFBQF) {
1118 writel(NS_STAT_SFBQF, card->membase + STAT);
1119 printk("nicstar%d: Small free buffer queue is full.\n",
1120 card->index);
1121 }
1122
1123 /* Large Buffer Queue is full */
1124 if (stat_r & NS_STAT_LFBQF) {
1125 writel(NS_STAT_LFBQF, card->membase + STAT);
1126 printk("nicstar%d: Large free buffer queue is full.\n",
1127 card->index);
1128 }
1129
1130 /* Receive Status Queue is full */
1131 if (stat_r & NS_STAT_RSQF) {
1132 writel(NS_STAT_RSQF, card->membase + STAT);
1133 printk("nicstar%d: RSQ full.\n", card->index);
1134 process_rsq(card);
1135 }
1136
1137 /* Complete CS-PDU received */
1138 if (stat_r & NS_STAT_EOPDU) {
1139 RXPRINTK("nicstar%d: End of CS-PDU received.\n", card->index);
1140 process_rsq(card);
1141 writel(NS_STAT_EOPDU, card->membase + STAT);
1142 }
1143
1144 /* Raw cell received */
1145 if (stat_r & NS_STAT_RAWCF) {
1146 writel(NS_STAT_RAWCF, card->membase + STAT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147#ifndef RCQ_SUPPORT
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001148 printk("nicstar%d: Raw cell received and no support yet...\n",
1149 card->index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150#endif /* RCQ_SUPPORT */
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001151 /* NOTE: the following procedure may keep a raw cell pending until the
1152 next interrupt. As this preliminary support is only meant to
1153 avoid buffer leakage, this is not an issue. */
1154 while (readl(card->membase + RAWCT) != card->rawch) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001156 if (ns_rcqe_islast(card->rawcell)) {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001157 struct sk_buff *oldbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001159 oldbuf = card->rcbuf;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001160 card->rcbuf = idr_find(&card->idr,
1161 ns_rcqe_nextbufhandle(card->rawcell));
1162 card->rawch = NS_PRV_DMA(card->rcbuf);
1163 card->rawcell = (struct ns_rcqe *)
1164 card->rcbuf->data;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001165 recycle_rx_buf(card, oldbuf);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001166 } else {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001167 card->rawch += NS_RCQE_SIZE;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001168 card->rawcell++;
1169 }
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001170 }
1171 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001173 /* Small buffer queue is empty */
1174 if (stat_r & NS_STAT_SFBQE) {
1175 int i;
1176 struct sk_buff *sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001178 writel(NS_STAT_SFBQE, card->membase + STAT);
1179 printk("nicstar%d: Small free buffer queue empty.\n",
1180 card->index);
1181 for (i = 0; i < card->sbnr.min; i++) {
1182 sb = dev_alloc_skb(NS_SMSKBSIZE);
1183 if (sb == NULL) {
1184 writel(readl(card->membase + CFG) &
1185 ~NS_CFG_EFBIE, card->membase + CFG);
1186 card->efbie = 0;
1187 break;
1188 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001189 NS_PRV_BUFTYPE(sb) = BUF_SM;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001190 skb_queue_tail(&card->sbpool.queue, sb);
1191 skb_reserve(sb, NS_AAL0_HEADER);
1192 push_rxbufs(card, sb);
1193 }
1194 card->sbfqc = i;
1195 process_rsq(card);
1196 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001198 /* Large buffer queue empty */
1199 if (stat_r & NS_STAT_LFBQE) {
1200 int i;
1201 struct sk_buff *lb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001203 writel(NS_STAT_LFBQE, card->membase + STAT);
1204 printk("nicstar%d: Large free buffer queue empty.\n",
1205 card->index);
1206 for (i = 0; i < card->lbnr.min; i++) {
1207 lb = dev_alloc_skb(NS_LGSKBSIZE);
1208 if (lb == NULL) {
1209 writel(readl(card->membase + CFG) &
1210 ~NS_CFG_EFBIE, card->membase + CFG);
1211 card->efbie = 0;
1212 break;
1213 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001214 NS_PRV_BUFTYPE(lb) = BUF_LG;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001215 skb_queue_tail(&card->lbpool.queue, lb);
1216 skb_reserve(lb, NS_SMBUFSIZE);
1217 push_rxbufs(card, lb);
1218 }
1219 card->lbfqc = i;
1220 process_rsq(card);
1221 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001223 /* Receive Status Queue is 7/8 full */
1224 if (stat_r & NS_STAT_RSQAF) {
1225 writel(NS_STAT_RSQAF, card->membase + STAT);
1226 RXPRINTK("nicstar%d: RSQ almost full.\n", card->index);
1227 process_rsq(card);
1228 }
1229
1230 spin_unlock_irqrestore(&card->int_lock, flags);
1231 PRINTK("nicstar%d: end of interrupt service\n", card->index);
1232 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233}
1234
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235static int ns_open(struct atm_vcc *vcc)
1236{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001237 ns_dev *card;
1238 vc_map *vc;
1239 unsigned long tmpl, modl;
1240 int tcr, tcra; /* target cell rate, and absolute value */
1241 int n = 0; /* Number of entries in the TST. Initialized to remove
1242 the compiler warning. */
1243 u32 u32d[4];
1244 int frscdi = 0; /* Index of the SCD. Initialized to remove the compiler
1245 warning. How I wish compilers were clever enough to
1246 tell which variables can truly be used
1247 uninitialized... */
1248 int inuse; /* tx or rx vc already in use by another vcc */
1249 short vpi = vcc->vpi;
1250 int vci = vcc->vci;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001252 card = (ns_dev *) vcc->dev->dev_data;
1253 PRINTK("nicstar%d: opening vpi.vci %d.%d \n", card->index, (int)vpi,
1254 vci);
1255 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
1256 PRINTK("nicstar%d: unsupported AAL.\n", card->index);
1257 return -EINVAL;
1258 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001260 vc = &(card->vcmap[vpi << card->vcibits | vci]);
1261 vcc->dev_data = vc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001263 inuse = 0;
1264 if (vcc->qos.txtp.traffic_class != ATM_NONE && vc->tx)
1265 inuse = 1;
1266 if (vcc->qos.rxtp.traffic_class != ATM_NONE && vc->rx)
1267 inuse += 2;
1268 if (inuse) {
1269 printk("nicstar%d: %s vci already in use.\n", card->index,
1270 inuse == 1 ? "tx" : inuse == 2 ? "rx" : "tx and rx");
1271 return -EINVAL;
1272 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001274 set_bit(ATM_VF_ADDR, &vcc->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001276 /* NOTE: You are not allowed to modify an open connection's QOS. To change
1277 that, remove the ATM_VF_PARTIAL flag checking. There may be other changes
1278 needed to do that. */
1279 if (!test_bit(ATM_VF_PARTIAL, &vcc->flags)) {
1280 scq_info *scq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001282 set_bit(ATM_VF_PARTIAL, &vcc->flags);
1283 if (vcc->qos.txtp.traffic_class == ATM_CBR) {
1284 /* Check requested cell rate and availability of SCD */
1285 if (vcc->qos.txtp.max_pcr == 0 && vcc->qos.txtp.pcr == 0
1286 && vcc->qos.txtp.min_pcr == 0) {
1287 PRINTK
1288 ("nicstar%d: trying to open a CBR vc with cell rate = 0 \n",
1289 card->index);
1290 clear_bit(ATM_VF_PARTIAL, &vcc->flags);
1291 clear_bit(ATM_VF_ADDR, &vcc->flags);
1292 return -EINVAL;
1293 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001295 tcr = atm_pcr_goal(&(vcc->qos.txtp));
1296 tcra = tcr >= 0 ? tcr : -tcr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001298 PRINTK("nicstar%d: target cell rate = %d.\n",
1299 card->index, vcc->qos.txtp.max_pcr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001301 tmpl =
1302 (unsigned long)tcra *(unsigned long)
1303 NS_TST_NUM_ENTRIES;
1304 modl = tmpl % card->max_pcr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001306 n = (int)(tmpl / card->max_pcr);
1307 if (tcr > 0) {
1308 if (modl > 0)
1309 n++;
1310 } else if (tcr == 0) {
1311 if ((n =
1312 (card->tst_free_entries -
1313 NS_TST_RESERVED)) <= 0) {
1314 PRINTK
1315 ("nicstar%d: no CBR bandwidth free.\n",
1316 card->index);
1317 clear_bit(ATM_VF_PARTIAL, &vcc->flags);
1318 clear_bit(ATM_VF_ADDR, &vcc->flags);
1319 return -EINVAL;
1320 }
1321 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001323 if (n == 0) {
1324 printk
1325 ("nicstar%d: selected bandwidth < granularity.\n",
1326 card->index);
1327 clear_bit(ATM_VF_PARTIAL, &vcc->flags);
1328 clear_bit(ATM_VF_ADDR, &vcc->flags);
1329 return -EINVAL;
1330 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001332 if (n > (card->tst_free_entries - NS_TST_RESERVED)) {
1333 PRINTK
1334 ("nicstar%d: not enough free CBR bandwidth.\n",
1335 card->index);
1336 clear_bit(ATM_VF_PARTIAL, &vcc->flags);
1337 clear_bit(ATM_VF_ADDR, &vcc->flags);
1338 return -EINVAL;
1339 } else
1340 card->tst_free_entries -= n;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001342 XPRINTK("nicstar%d: writing %d tst entries.\n",
1343 card->index, n);
1344 for (frscdi = 0; frscdi < NS_FRSCD_NUM; frscdi++) {
1345 if (card->scd2vc[frscdi] == NULL) {
1346 card->scd2vc[frscdi] = vc;
1347 break;
1348 }
1349 }
1350 if (frscdi == NS_FRSCD_NUM) {
1351 PRINTK
1352 ("nicstar%d: no SCD available for CBR channel.\n",
1353 card->index);
1354 card->tst_free_entries += n;
1355 clear_bit(ATM_VF_PARTIAL, &vcc->flags);
1356 clear_bit(ATM_VF_ADDR, &vcc->flags);
1357 return -EBUSY;
1358 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001360 vc->cbr_scd = NS_FRSCD + frscdi * NS_FRSCD_SIZE;
1361
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001362 scq = get_scq(card, CBR_SCQSIZE, vc->cbr_scd);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001363 if (scq == NULL) {
1364 PRINTK("nicstar%d: can't get fixed rate SCQ.\n",
1365 card->index);
1366 card->scd2vc[frscdi] = NULL;
1367 card->tst_free_entries += n;
1368 clear_bit(ATM_VF_PARTIAL, &vcc->flags);
1369 clear_bit(ATM_VF_ADDR, &vcc->flags);
1370 return -ENOMEM;
1371 }
1372 vc->scq = scq;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001373 u32d[0] = scq_virt_to_bus(scq, scq->base);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001374 u32d[1] = (u32) 0x00000000;
1375 u32d[2] = (u32) 0xffffffff;
1376 u32d[3] = (u32) 0x00000000;
1377 ns_write_sram(card, vc->cbr_scd, u32d, 4);
1378
1379 fill_tst(card, n, vc);
1380 } else if (vcc->qos.txtp.traffic_class == ATM_UBR) {
1381 vc->cbr_scd = 0x00000000;
1382 vc->scq = card->scq0;
1383 }
1384
1385 if (vcc->qos.txtp.traffic_class != ATM_NONE) {
1386 vc->tx = 1;
1387 vc->tx_vcc = vcc;
1388 vc->tbd_count = 0;
1389 }
1390 if (vcc->qos.rxtp.traffic_class != ATM_NONE) {
1391 u32 status;
1392
1393 vc->rx = 1;
1394 vc->rx_vcc = vcc;
1395 vc->rx_iov = NULL;
1396
1397 /* Open the connection in hardware */
1398 if (vcc->qos.aal == ATM_AAL5)
1399 status = NS_RCTE_AAL5 | NS_RCTE_CONNECTOPEN;
1400 else /* vcc->qos.aal == ATM_AAL0 */
1401 status = NS_RCTE_AAL0 | NS_RCTE_CONNECTOPEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402#ifdef RCQ_SUPPORT
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001403 status |= NS_RCTE_RAWCELLINTEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404#endif /* RCQ_SUPPORT */
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001405 ns_write_sram(card,
1406 NS_RCT +
1407 (vpi << card->vcibits | vci) *
1408 NS_RCT_ENTRY_SIZE, &status, 1);
1409 }
1410
1411 }
1412
1413 set_bit(ATM_VF_READY, &vcc->flags);
1414 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415}
1416
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417static void ns_close(struct atm_vcc *vcc)
1418{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001419 vc_map *vc;
1420 ns_dev *card;
1421 u32 data;
1422 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001424 vc = vcc->dev_data;
1425 card = vcc->dev->dev_data;
1426 PRINTK("nicstar%d: closing vpi.vci %d.%d \n", card->index,
1427 (int)vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001429 clear_bit(ATM_VF_READY, &vcc->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001431 if (vcc->qos.rxtp.traffic_class != ATM_NONE) {
1432 u32 addr;
1433 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001435 addr =
1436 NS_RCT +
1437 (vcc->vpi << card->vcibits | vcc->vci) * NS_RCT_ENTRY_SIZE;
1438 spin_lock_irqsave(&card->res_lock, flags);
1439 while (CMD_BUSY(card)) ;
1440 writel(NS_CMD_CLOSE_CONNECTION | addr << 2,
1441 card->membase + CMD);
1442 spin_unlock_irqrestore(&card->res_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001444 vc->rx = 0;
1445 if (vc->rx_iov != NULL) {
1446 struct sk_buff *iovb;
1447 u32 stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001449 stat = readl(card->membase + STAT);
1450 card->sbfqc = ns_stat_sfbqc_get(stat);
1451 card->lbfqc = ns_stat_lfbqc_get(stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001453 PRINTK
1454 ("nicstar%d: closing a VC with pending rx buffers.\n",
1455 card->index);
1456 iovb = vc->rx_iov;
1457 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001458 NS_PRV_IOVCNT(iovb));
1459 NS_PRV_IOVCNT(iovb) = 0;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001460 spin_lock_irqsave(&card->int_lock, flags);
1461 recycle_iov_buf(card, iovb);
1462 spin_unlock_irqrestore(&card->int_lock, flags);
1463 vc->rx_iov = NULL;
1464 }
1465 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001467 if (vcc->qos.txtp.traffic_class != ATM_NONE) {
1468 vc->tx = 0;
1469 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001471 if (vcc->qos.txtp.traffic_class == ATM_CBR) {
1472 unsigned long flags;
1473 ns_scqe *scqep;
1474 scq_info *scq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001476 scq = vc->scq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001478 for (;;) {
1479 spin_lock_irqsave(&scq->lock, flags);
1480 scqep = scq->next;
1481 if (scqep == scq->base)
1482 scqep = scq->last;
1483 else
1484 scqep--;
1485 if (scqep == scq->tail) {
1486 spin_unlock_irqrestore(&scq->lock, flags);
1487 break;
1488 }
1489 /* If the last entry is not a TSR, place one in the SCQ in order to
1490 be able to completely drain it and then close. */
1491 if (!ns_scqe_is_tsr(scqep) && scq->tail != scq->next) {
1492 ns_scqe tsr;
1493 u32 scdi, scqi;
1494 u32 data;
1495 int index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001497 tsr.word_1 = ns_tsr_mkword_1(NS_TSR_INTENABLE);
1498 scdi = (vc->cbr_scd - NS_FRSCD) / NS_FRSCD_SIZE;
1499 scqi = scq->next - scq->base;
1500 tsr.word_2 = ns_tsr_mkword_2(scdi, scqi);
1501 tsr.word_3 = 0x00000000;
1502 tsr.word_4 = 0x00000000;
1503 *scq->next = tsr;
1504 index = (int)scqi;
1505 scq->skb[index] = NULL;
1506 if (scq->next == scq->last)
1507 scq->next = scq->base;
1508 else
1509 scq->next++;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001510 data = scq_virt_to_bus(scq, scq->next);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001511 ns_write_sram(card, scq->scd, &data, 1);
1512 }
1513 spin_unlock_irqrestore(&scq->lock, flags);
1514 schedule();
1515 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001517 /* Free all TST entries */
1518 data = NS_TST_OPCODE_VARIABLE;
1519 for (i = 0; i < NS_TST_NUM_ENTRIES; i++) {
1520 if (card->tste2vc[i] == vc) {
1521 ns_write_sram(card, card->tst_addr + i, &data,
1522 1);
1523 card->tste2vc[i] = NULL;
1524 card->tst_free_entries++;
1525 }
1526 }
1527
1528 card->scd2vc[(vc->cbr_scd - NS_FRSCD) / NS_FRSCD_SIZE] = NULL;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001529 free_scq(card, vc->scq, vcc);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001530 }
1531
1532 /* remove all references to vcc before deleting it */
1533 if (vcc->qos.txtp.traffic_class != ATM_NONE) {
1534 unsigned long flags;
1535 scq_info *scq = card->scq0;
1536
1537 spin_lock_irqsave(&scq->lock, flags);
1538
1539 for (i = 0; i < scq->num_entries; i++) {
1540 if (scq->skb[i] && ATM_SKB(scq->skb[i])->vcc == vcc) {
1541 ATM_SKB(scq->skb[i])->vcc = NULL;
1542 atm_return(vcc, scq->skb[i]->truesize);
1543 PRINTK
1544 ("nicstar: deleted pending vcc mapping\n");
1545 }
1546 }
1547
1548 spin_unlock_irqrestore(&scq->lock, flags);
1549 }
1550
1551 vcc->dev_data = NULL;
1552 clear_bit(ATM_VF_PARTIAL, &vcc->flags);
1553 clear_bit(ATM_VF_ADDR, &vcc->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
1555#ifdef RX_DEBUG
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001556 {
1557 u32 stat, cfg;
1558 stat = readl(card->membase + STAT);
1559 cfg = readl(card->membase + CFG);
1560 printk("STAT = 0x%08X CFG = 0x%08X \n", stat, cfg);
1561 printk
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001562 ("TSQ: base = 0x%p next = 0x%p last = 0x%p TSQT = 0x%08X \n",
1563 card->tsq.base, card->tsq.next,
1564 card->tsq.last, readl(card->membase + TSQT));
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001565 printk
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001566 ("RSQ: base = 0x%p next = 0x%p last = 0x%p RSQT = 0x%08X \n",
1567 card->rsq.base, card->rsq.next,
1568 card->rsq.last, readl(card->membase + RSQT));
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001569 printk("Empty free buffer queue interrupt %s \n",
1570 card->efbie ? "enabled" : "disabled");
1571 printk("SBCNT = %d count = %d LBCNT = %d count = %d \n",
1572 ns_stat_sfbqc_get(stat), card->sbpool.count,
1573 ns_stat_lfbqc_get(stat), card->lbpool.count);
1574 printk("hbpool.count = %d iovpool.count = %d \n",
1575 card->hbpool.count, card->iovpool.count);
1576 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577#endif /* RX_DEBUG */
1578}
1579
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001580static void fill_tst(ns_dev * card, int n, vc_map * vc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001582 u32 new_tst;
1583 unsigned long cl;
1584 int e, r;
1585 u32 data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001587 /* It would be very complicated to keep the two TSTs synchronized while
1588 assuring that writes are only made to the inactive TST. So, for now I
1589 will use only one TST. If problems occur, I will change this again */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001591 new_tst = card->tst_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001593 /* Fill procedure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001595 for (e = 0; e < NS_TST_NUM_ENTRIES; e++) {
1596 if (card->tste2vc[e] == NULL)
1597 break;
1598 }
1599 if (e == NS_TST_NUM_ENTRIES) {
1600 printk("nicstar%d: No free TST entries found. \n", card->index);
1601 return;
1602 }
1603
1604 r = n;
1605 cl = NS_TST_NUM_ENTRIES;
1606 data = ns_tste_make(NS_TST_OPCODE_FIXED, vc->cbr_scd);
1607
1608 while (r > 0) {
1609 if (cl >= NS_TST_NUM_ENTRIES && card->tste2vc[e] == NULL) {
1610 card->tste2vc[e] = vc;
1611 ns_write_sram(card, new_tst + e, &data, 1);
1612 cl -= NS_TST_NUM_ENTRIES;
1613 r--;
1614 }
1615
1616 if (++e == NS_TST_NUM_ENTRIES) {
1617 e = 0;
1618 }
1619 cl += n;
1620 }
1621
1622 /* End of fill procedure */
1623
1624 data = ns_tste_make(NS_TST_OPCODE_END, new_tst);
1625 ns_write_sram(card, new_tst + NS_TST_NUM_ENTRIES, &data, 1);
1626 ns_write_sram(card, card->tst_addr + NS_TST_NUM_ENTRIES, &data, 1);
1627 card->tst_addr = new_tst;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628}
1629
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
1631{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001632 ns_dev *card;
1633 vc_map *vc;
1634 scq_info *scq;
1635 unsigned long buflen;
1636 ns_scqe scqe;
1637 u32 flags; /* TBD flags, not CPU flags */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001639 card = vcc->dev->dev_data;
1640 TXPRINTK("nicstar%d: ns_send() called.\n", card->index);
1641 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
1642 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
1643 card->index);
1644 atomic_inc(&vcc->stats->tx_err);
1645 dev_kfree_skb_any(skb);
1646 return -EINVAL;
1647 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001649 if (!vc->tx) {
1650 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
1651 card->index);
1652 atomic_inc(&vcc->stats->tx_err);
1653 dev_kfree_skb_any(skb);
1654 return -EINVAL;
1655 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001657 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
1658 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
1659 card->index);
1660 atomic_inc(&vcc->stats->tx_err);
1661 dev_kfree_skb_any(skb);
1662 return -EINVAL;
1663 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001665 if (skb_shinfo(skb)->nr_frags != 0) {
1666 printk("nicstar%d: No scatter-gather yet.\n", card->index);
1667 atomic_inc(&vcc->stats->tx_err);
1668 dev_kfree_skb_any(skb);
1669 return -EINVAL;
1670 }
1671
1672 ATM_SKB(skb)->vcc = vcc;
1673
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001674 NS_PRV_DMA(skb) = pci_map_single(card->pcidev, skb->data,
1675 skb->len, PCI_DMA_TODEVICE);
1676
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001677 if (vcc->qos.aal == ATM_AAL5) {
1678 buflen = (skb->len + 47 + 8) / 48 * 48; /* Multiple of 48 */
1679 flags = NS_TBD_AAL5;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001680 scqe.word_2 = cpu_to_le32(NS_PRV_DMA(skb));
1681 scqe.word_3 = cpu_to_le32(skb->len);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001682 scqe.word_4 =
1683 ns_tbd_mkword_4(0, (u32) vcc->vpi, (u32) vcc->vci, 0,
1684 ATM_SKB(skb)->
1685 atm_options & ATM_ATMOPT_CLP ? 1 : 0);
1686 flags |= NS_TBD_EOPDU;
1687 } else { /* (vcc->qos.aal == ATM_AAL0) */
1688
1689 buflen = ATM_CELL_PAYLOAD; /* i.e., 48 bytes */
1690 flags = NS_TBD_AAL0;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001691 scqe.word_2 = cpu_to_le32(NS_PRV_DMA(skb) + NS_AAL0_HEADER);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001692 scqe.word_3 = cpu_to_le32(0x00000000);
1693 if (*skb->data & 0x02) /* Payload type 1 - end of pdu */
1694 flags |= NS_TBD_EOPDU;
1695 scqe.word_4 =
1696 cpu_to_le32(*((u32 *) skb->data) & ~NS_TBD_VC_MASK);
1697 /* Force the VPI/VCI to be the same as in VCC struct */
1698 scqe.word_4 |=
1699 cpu_to_le32((((u32) vcc->
1700 vpi) << NS_TBD_VPI_SHIFT | ((u32) vcc->
1701 vci) <<
1702 NS_TBD_VCI_SHIFT) & NS_TBD_VC_MASK);
1703 }
1704
1705 if (vcc->qos.txtp.traffic_class == ATM_CBR) {
1706 scqe.word_1 = ns_tbd_mkword_1_novbr(flags, (u32) buflen);
1707 scq = ((vc_map *) vcc->dev_data)->scq;
1708 } else {
1709 scqe.word_1 =
1710 ns_tbd_mkword_1(flags, (u32) 1, (u32) 1, (u32) buflen);
1711 scq = card->scq0;
1712 }
1713
1714 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
1715 atomic_inc(&vcc->stats->tx_err);
1716 dev_kfree_skb_any(skb);
1717 return -EIO;
1718 }
1719 atomic_inc(&vcc->stats->tx);
1720
1721 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722}
1723
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001724static int push_scqe(ns_dev * card, vc_map * vc, scq_info * scq, ns_scqe * tbd,
1725 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001727 unsigned long flags;
1728 ns_scqe tsr;
1729 u32 scdi, scqi;
1730 int scq_is_vbr;
1731 u32 data;
1732 int index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001734 spin_lock_irqsave(&scq->lock, flags);
1735 while (scq->tail == scq->next) {
1736 if (in_interrupt()) {
1737 spin_unlock_irqrestore(&scq->lock, flags);
1738 printk("nicstar%d: Error pushing TBD.\n", card->index);
1739 return 1;
1740 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001742 scq->full = 1;
1743 spin_unlock_irqrestore(&scq->lock, flags);
1744 interruptible_sleep_on_timeout(&scq->scqfull_waitq,
1745 SCQFULL_TIMEOUT);
1746 spin_lock_irqsave(&scq->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001748 if (scq->full) {
1749 spin_unlock_irqrestore(&scq->lock, flags);
1750 printk("nicstar%d: Timeout pushing TBD.\n",
1751 card->index);
1752 return 1;
1753 }
1754 }
1755 *scq->next = *tbd;
1756 index = (int)(scq->next - scq->base);
1757 scq->skb[index] = skb;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001758 XPRINTK("nicstar%d: sending skb at 0x%p (pos %d).\n",
1759 card->index, skb, index);
1760 XPRINTK("nicstar%d: TBD written:\n0x%x\n0x%x\n0x%x\n0x%x\n at 0x%p.\n",
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001761 card->index, le32_to_cpu(tbd->word_1), le32_to_cpu(tbd->word_2),
1762 le32_to_cpu(tbd->word_3), le32_to_cpu(tbd->word_4),
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001763 scq->next);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001764 if (scq->next == scq->last)
1765 scq->next = scq->base;
1766 else
1767 scq->next++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001769 vc->tbd_count++;
1770 if (scq->num_entries == VBR_SCQ_NUM_ENTRIES) {
1771 scq->tbd_count++;
1772 scq_is_vbr = 1;
1773 } else
1774 scq_is_vbr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001776 if (vc->tbd_count >= MAX_TBD_PER_VC
1777 || scq->tbd_count >= MAX_TBD_PER_SCQ) {
1778 int has_run = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001780 while (scq->tail == scq->next) {
1781 if (in_interrupt()) {
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001782 data = scq_virt_to_bus(scq, scq->next);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001783 ns_write_sram(card, scq->scd, &data, 1);
1784 spin_unlock_irqrestore(&scq->lock, flags);
1785 printk("nicstar%d: Error pushing TSR.\n",
1786 card->index);
1787 return 0;
1788 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001790 scq->full = 1;
1791 if (has_run++)
1792 break;
1793 spin_unlock_irqrestore(&scq->lock, flags);
1794 interruptible_sleep_on_timeout(&scq->scqfull_waitq,
1795 SCQFULL_TIMEOUT);
1796 spin_lock_irqsave(&scq->lock, flags);
1797 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001799 if (!scq->full) {
1800 tsr.word_1 = ns_tsr_mkword_1(NS_TSR_INTENABLE);
1801 if (scq_is_vbr)
1802 scdi = NS_TSR_SCDISVBR;
1803 else
1804 scdi = (vc->cbr_scd - NS_FRSCD) / NS_FRSCD_SIZE;
1805 scqi = scq->next - scq->base;
1806 tsr.word_2 = ns_tsr_mkword_2(scdi, scqi);
1807 tsr.word_3 = 0x00000000;
1808 tsr.word_4 = 0x00000000;
1809
1810 *scq->next = tsr;
1811 index = (int)scqi;
1812 scq->skb[index] = NULL;
1813 XPRINTK
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001814 ("nicstar%d: TSR written:\n0x%x\n0x%x\n0x%x\n0x%x\n at 0x%p.\n",
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001815 card->index, le32_to_cpu(tsr.word_1),
1816 le32_to_cpu(tsr.word_2), le32_to_cpu(tsr.word_3),
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001817 le32_to_cpu(tsr.word_4), scq->next);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001818 if (scq->next == scq->last)
1819 scq->next = scq->base;
1820 else
1821 scq->next++;
1822 vc->tbd_count = 0;
1823 scq->tbd_count = 0;
1824 } else
1825 PRINTK("nicstar%d: Timeout pushing TSR.\n",
1826 card->index);
1827 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001828 data = scq_virt_to_bus(scq, scq->next);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001829 ns_write_sram(card, scq->scd, &data, 1);
1830
1831 spin_unlock_irqrestore(&scq->lock, flags);
1832
1833 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834}
1835
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001836static void process_tsq(ns_dev * card)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001838 u32 scdi;
1839 scq_info *scq;
1840 ns_tsi *previous = NULL, *one_ahead, *two_ahead;
1841 int serviced_entries; /* flag indicating at least on entry was serviced */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001843 serviced_entries = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001845 if (card->tsq.next == card->tsq.last)
1846 one_ahead = card->tsq.base;
1847 else
1848 one_ahead = card->tsq.next + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001850 if (one_ahead == card->tsq.last)
1851 two_ahead = card->tsq.base;
1852 else
1853 two_ahead = one_ahead + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001855 while (!ns_tsi_isempty(card->tsq.next) || !ns_tsi_isempty(one_ahead) ||
1856 !ns_tsi_isempty(two_ahead))
1857 /* At most two empty, as stated in the 77201 errata */
1858 {
1859 serviced_entries = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001861 /* Skip the one or two possible empty entries */
1862 while (ns_tsi_isempty(card->tsq.next)) {
1863 if (card->tsq.next == card->tsq.last)
1864 card->tsq.next = card->tsq.base;
1865 else
1866 card->tsq.next++;
1867 }
1868
1869 if (!ns_tsi_tmrof(card->tsq.next)) {
1870 scdi = ns_tsi_getscdindex(card->tsq.next);
1871 if (scdi == NS_TSI_SCDISVBR)
1872 scq = card->scq0;
1873 else {
1874 if (card->scd2vc[scdi] == NULL) {
1875 printk
1876 ("nicstar%d: could not find VC from SCD index.\n",
1877 card->index);
1878 ns_tsi_init(card->tsq.next);
1879 return;
1880 }
1881 scq = card->scd2vc[scdi]->scq;
1882 }
1883 drain_scq(card, scq, ns_tsi_getscqpos(card->tsq.next));
1884 scq->full = 0;
1885 wake_up_interruptible(&(scq->scqfull_waitq));
1886 }
1887
1888 ns_tsi_init(card->tsq.next);
1889 previous = card->tsq.next;
1890 if (card->tsq.next == card->tsq.last)
1891 card->tsq.next = card->tsq.base;
1892 else
1893 card->tsq.next++;
1894
1895 if (card->tsq.next == card->tsq.last)
1896 one_ahead = card->tsq.base;
1897 else
1898 one_ahead = card->tsq.next + 1;
1899
1900 if (one_ahead == card->tsq.last)
1901 two_ahead = card->tsq.base;
1902 else
1903 two_ahead = one_ahead + 1;
1904 }
1905
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001906 if (serviced_entries)
1907 writel(PTR_DIFF(previous, card->tsq.base),
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001908 card->membase + TSQH);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909}
1910
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001911static void drain_scq(ns_dev * card, scq_info * scq, int pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001913 struct atm_vcc *vcc;
1914 struct sk_buff *skb;
1915 int i;
1916 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001918 XPRINTK("nicstar%d: drain_scq() called, scq at 0x%p, pos %d.\n",
1919 card->index, scq, pos);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001920 if (pos >= scq->num_entries) {
1921 printk("nicstar%d: Bad index on drain_scq().\n", card->index);
1922 return;
1923 }
1924
1925 spin_lock_irqsave(&scq->lock, flags);
1926 i = (int)(scq->tail - scq->base);
1927 if (++i == scq->num_entries)
1928 i = 0;
1929 while (i != pos) {
1930 skb = scq->skb[i];
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001931 XPRINTK("nicstar%d: freeing skb at 0x%p (index %d).\n",
1932 card->index, skb, i);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001933 if (skb != NULL) {
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001934 pci_unmap_single(card->pcidev,
1935 NS_PRV_DMA(skb),
1936 skb->len,
1937 PCI_DMA_TODEVICE);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001938 vcc = ATM_SKB(skb)->vcc;
1939 if (vcc && vcc->pop != NULL) {
1940 vcc->pop(vcc, skb);
1941 } else {
1942 dev_kfree_skb_irq(skb);
1943 }
1944 scq->skb[i] = NULL;
1945 }
1946 if (++i == scq->num_entries)
1947 i = 0;
1948 }
1949 scq->tail = scq->base + pos;
1950 spin_unlock_irqrestore(&scq->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951}
1952
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001953static void process_rsq(ns_dev * card)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001955 ns_rsqe *previous;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001957 if (!ns_rsqe_valid(card->rsq.next))
1958 return;
1959 do {
1960 dequeue_rx(card, card->rsq.next);
1961 ns_rsqe_init(card->rsq.next);
1962 previous = card->rsq.next;
1963 if (card->rsq.next == card->rsq.last)
1964 card->rsq.next = card->rsq.base;
1965 else
1966 card->rsq.next++;
1967 } while (ns_rsqe_valid(card->rsq.next));
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001968 writel(PTR_DIFF(previous, card->rsq.base), card->membase + RSQH);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969}
1970
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001971static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001973 u32 vpi, vci;
1974 vc_map *vc;
1975 struct sk_buff *iovb;
1976 struct iovec *iov;
1977 struct atm_vcc *vcc;
1978 struct sk_buff *skb;
1979 unsigned short aal5_len;
1980 int len;
1981 u32 stat;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001982 u32 id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001984 stat = readl(card->membase + STAT);
1985 card->sbfqc = ns_stat_sfbqc_get(stat);
1986 card->lbfqc = ns_stat_lfbqc_get(stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001988 id = le32_to_cpu(rsqe->buffer_handle);
1989 skb = idr_find(&card->idr, id);
1990 if (!skb) {
1991 RXPRINTK(KERN_ERR
1992 "nicstar%d: idr_find() failed!\n", card->index);
1993 return;
1994 }
1995 idr_remove(&card->idr, id);
1996 pci_dma_sync_single_for_cpu(card->pcidev,
1997 NS_PRV_DMA(skb),
1998 (NS_PRV_BUFTYPE(skb) == BUF_SM
1999 ? NS_SMSKBSIZE : NS_LGSKBSIZE),
2000 PCI_DMA_FROMDEVICE);
2001 pci_unmap_single(card->pcidev,
2002 NS_PRV_DMA(skb),
2003 (NS_PRV_BUFTYPE(skb) == BUF_SM
2004 ? NS_SMSKBSIZE : NS_LGSKBSIZE),
2005 PCI_DMA_FROMDEVICE);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002006 vpi = ns_rsqe_vpi(rsqe);
2007 vci = ns_rsqe_vci(rsqe);
2008 if (vpi >= 1UL << card->vpibits || vci >= 1UL << card->vcibits) {
2009 printk("nicstar%d: SDU received for out-of-range vc %d.%d.\n",
2010 card->index, vpi, vci);
2011 recycle_rx_buf(card, skb);
2012 return;
2013 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002015 vc = &(card->vcmap[vpi << card->vcibits | vci]);
2016 if (!vc->rx) {
2017 RXPRINTK("nicstar%d: SDU received on non-rx vc %d.%d.\n",
2018 card->index, vpi, vci);
2019 recycle_rx_buf(card, skb);
2020 return;
2021 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002023 vcc = vc->rx_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002025 if (vcc->qos.aal == ATM_AAL0) {
2026 struct sk_buff *sb;
2027 unsigned char *cell;
2028 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002030 cell = skb->data;
2031 for (i = ns_rsqe_cellcount(rsqe); i; i--) {
2032 if ((sb = dev_alloc_skb(NS_SMSKBSIZE)) == NULL) {
2033 printk
2034 ("nicstar%d: Can't allocate buffers for aal0.\n",
2035 card->index);
2036 atomic_add(i, &vcc->stats->rx_drop);
2037 break;
2038 }
2039 if (!atm_charge(vcc, sb->truesize)) {
2040 RXPRINTK
2041 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
2042 card->index);
2043 atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
2044 dev_kfree_skb_any(sb);
2045 break;
2046 }
2047 /* Rebuild the header */
2048 *((u32 *) sb->data) = le32_to_cpu(rsqe->word_1) << 4 |
2049 (ns_rsqe_clp(rsqe) ? 0x00000001 : 0x00000000);
2050 if (i == 1 && ns_rsqe_eopdu(rsqe))
2051 *((u32 *) sb->data) |= 0x00000002;
2052 skb_put(sb, NS_AAL0_HEADER);
2053 memcpy(skb_tail_pointer(sb), cell, ATM_CELL_PAYLOAD);
2054 skb_put(sb, ATM_CELL_PAYLOAD);
2055 ATM_SKB(sb)->vcc = vcc;
2056 __net_timestamp(sb);
2057 vcc->push(vcc, sb);
2058 atomic_inc(&vcc->stats->rx);
2059 cell += ATM_CELL_PAYLOAD;
2060 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002062 recycle_rx_buf(card, skb);
2063 return;
2064 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002066 /* To reach this point, the AAL layer can only be AAL5 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002068 if ((iovb = vc->rx_iov) == NULL) {
2069 iovb = skb_dequeue(&(card->iovpool.queue));
2070 if (iovb == NULL) { /* No buffers in the queue */
2071 iovb = alloc_skb(NS_IOVBUFSIZE, GFP_ATOMIC);
2072 if (iovb == NULL) {
2073 printk("nicstar%d: Out of iovec buffers.\n",
2074 card->index);
2075 atomic_inc(&vcc->stats->rx_drop);
2076 recycle_rx_buf(card, skb);
2077 return;
2078 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002079 NS_PRV_BUFTYPE(iovb) = BUF_NONE;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002080 } else if (--card->iovpool.count < card->iovnr.min) {
2081 struct sk_buff *new_iovb;
2082 if ((new_iovb =
2083 alloc_skb(NS_IOVBUFSIZE, GFP_ATOMIC)) != NULL) {
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002084 NS_PRV_BUFTYPE(iovb) = BUF_NONE;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002085 skb_queue_tail(&card->iovpool.queue, new_iovb);
2086 card->iovpool.count++;
2087 }
2088 }
2089 vc->rx_iov = iovb;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002090 NS_PRV_IOVCNT(iovb) = 0;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002091 iovb->len = 0;
2092 iovb->data = iovb->head;
2093 skb_reset_tail_pointer(iovb);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002094 /* IMPORTANT: a pointer to the sk_buff containing the small or large
2095 buffer is stored as iovec base, NOT a pointer to the
2096 small or large buffer itself. */
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002097 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002098 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
2099 atomic_inc(&vcc->stats->rx_err);
2100 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
2101 NS_MAX_IOVECS);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002102 NS_PRV_IOVCNT(iovb) = 0;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002103 iovb->len = 0;
2104 iovb->data = iovb->head;
2105 skb_reset_tail_pointer(iovb);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002106 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002107 iov = &((struct iovec *)iovb->data)[NS_PRV_IOVCNT(iovb)++];
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002108 iov->iov_base = (void *)skb;
2109 iov->iov_len = ns_rsqe_cellcount(rsqe) * 48;
2110 iovb->len += iov->iov_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002112#ifdef EXTRA_DEBUG
2113 if (NS_PRV_IOVCNT(iovb) == 1) {
2114 if (NS_PRV_BUFTYPE(skb) != BUF_SM) {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002115 printk
2116 ("nicstar%d: Expected a small buffer, and this is not one.\n",
2117 card->index);
2118 which_list(card, skb);
2119 atomic_inc(&vcc->stats->rx_err);
2120 recycle_rx_buf(card, skb);
2121 vc->rx_iov = NULL;
2122 recycle_iov_buf(card, iovb);
2123 return;
2124 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002125 } else { /* NS_PRV_IOVCNT(iovb) >= 2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002127 if (NS_PRV_BUFTYPE(skb) != BUF_LG) {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002128 printk
2129 ("nicstar%d: Expected a large buffer, and this is not one.\n",
2130 card->index);
2131 which_list(card, skb);
2132 atomic_inc(&vcc->stats->rx_err);
2133 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002134 NS_PRV_IOVCNT(iovb));
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002135 vc->rx_iov = NULL;
2136 recycle_iov_buf(card, iovb);
2137 return;
2138 }
2139 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002140#endif /* EXTRA_DEBUG */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002142 if (ns_rsqe_eopdu(rsqe)) {
2143 /* This works correctly regardless of the endianness of the host */
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002144 unsigned char *L1L2 = (unsigned char *)
2145 (skb->data + iov->iov_len - 6);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002146 aal5_len = L1L2[0] << 8 | L1L2[1];
2147 len = (aal5_len == 0x0000) ? 0x10000 : aal5_len;
2148 if (ns_rsqe_crcerr(rsqe) ||
2149 len + 8 > iovb->len || len + (47 + 8) < iovb->len) {
2150 printk("nicstar%d: AAL5 CRC error", card->index);
2151 if (len + 8 > iovb->len || len + (47 + 8) < iovb->len)
2152 printk(" - PDU size mismatch.\n");
2153 else
2154 printk(".\n");
2155 atomic_inc(&vcc->stats->rx_err);
2156 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002157 NS_PRV_IOVCNT(iovb));
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002158 vc->rx_iov = NULL;
2159 recycle_iov_buf(card, iovb);
2160 return;
2161 }
2162
2163 /* By this point we (hopefully) have a complete SDU without errors. */
2164
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002165 if (NS_PRV_IOVCNT(iovb) == 1) { /* Just a small buffer */
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002166 /* skb points to a small buffer */
2167 if (!atm_charge(vcc, skb->truesize)) {
2168 push_rxbufs(card, skb);
2169 atomic_inc(&vcc->stats->rx_drop);
2170 } else {
2171 skb_put(skb, len);
2172 dequeue_sm_buf(card, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173#ifdef NS_USE_DESTRUCTORS
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002174 skb->destructor = ns_sb_destructor;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175#endif /* NS_USE_DESTRUCTORS */
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002176 ATM_SKB(skb)->vcc = vcc;
2177 __net_timestamp(skb);
2178 vcc->push(vcc, skb);
2179 atomic_inc(&vcc->stats->rx);
2180 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002181 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002182 struct sk_buff *sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002184 sb = (struct sk_buff *)(iov - 1)->iov_base;
2185 /* skb points to a large buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002187 if (len <= NS_SMBUFSIZE) {
2188 if (!atm_charge(vcc, sb->truesize)) {
2189 push_rxbufs(card, sb);
2190 atomic_inc(&vcc->stats->rx_drop);
2191 } else {
2192 skb_put(sb, len);
2193 dequeue_sm_buf(card, sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194#ifdef NS_USE_DESTRUCTORS
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002195 sb->destructor = ns_sb_destructor;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196#endif /* NS_USE_DESTRUCTORS */
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002197 ATM_SKB(sb)->vcc = vcc;
2198 __net_timestamp(sb);
2199 vcc->push(vcc, sb);
2200 atomic_inc(&vcc->stats->rx);
2201 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002203 push_rxbufs(card, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002205 } else { /* len > NS_SMBUFSIZE, the usual case */
2206
2207 if (!atm_charge(vcc, skb->truesize)) {
2208 push_rxbufs(card, skb);
2209 atomic_inc(&vcc->stats->rx_drop);
2210 } else {
2211 dequeue_lg_buf(card, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212#ifdef NS_USE_DESTRUCTORS
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002213 skb->destructor = ns_lb_destructor;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214#endif /* NS_USE_DESTRUCTORS */
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002215 skb_push(skb, NS_SMBUFSIZE);
2216 skb_copy_from_linear_data(sb, skb->data,
2217 NS_SMBUFSIZE);
2218 skb_put(skb, len - NS_SMBUFSIZE);
2219 ATM_SKB(skb)->vcc = vcc;
2220 __net_timestamp(skb);
2221 vcc->push(vcc, skb);
2222 atomic_inc(&vcc->stats->rx);
2223 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002225 push_rxbufs(card, sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002227 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002229 } else { /* Must push a huge buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002231 struct sk_buff *hb, *sb, *lb;
2232 int remaining, tocopy;
2233 int j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002235 hb = skb_dequeue(&(card->hbpool.queue));
2236 if (hb == NULL) { /* No buffers in the queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002238 hb = dev_alloc_skb(NS_HBUFSIZE);
2239 if (hb == NULL) {
2240 printk
2241 ("nicstar%d: Out of huge buffers.\n",
2242 card->index);
2243 atomic_inc(&vcc->stats->rx_drop);
2244 recycle_iovec_rx_bufs(card,
2245 (struct iovec *)
2246 iovb->data,
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002247 NS_PRV_IOVCNT(iovb));
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002248 vc->rx_iov = NULL;
2249 recycle_iov_buf(card, iovb);
2250 return;
2251 } else if (card->hbpool.count < card->hbnr.min) {
2252 struct sk_buff *new_hb;
2253 if ((new_hb =
2254 dev_alloc_skb(NS_HBUFSIZE)) !=
2255 NULL) {
2256 skb_queue_tail(&card->hbpool.
2257 queue, new_hb);
2258 card->hbpool.count++;
2259 }
2260 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002261 NS_PRV_BUFTYPE(hb) = BUF_NONE;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002262 } else if (--card->hbpool.count < card->hbnr.min) {
2263 struct sk_buff *new_hb;
2264 if ((new_hb =
2265 dev_alloc_skb(NS_HBUFSIZE)) != NULL) {
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002266 NS_PRV_BUFTYPE(new_hb) = BUF_NONE;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002267 skb_queue_tail(&card->hbpool.queue,
2268 new_hb);
2269 card->hbpool.count++;
2270 }
2271 if (card->hbpool.count < card->hbnr.min) {
2272 if ((new_hb =
2273 dev_alloc_skb(NS_HBUFSIZE)) !=
2274 NULL) {
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002275 NS_PRV_BUFTYPE(new_hb) =
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002276 BUF_NONE;
2277 skb_queue_tail(&card->hbpool.
2278 queue, new_hb);
2279 card->hbpool.count++;
2280 }
2281 }
2282 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002284 iov = (struct iovec *)iovb->data;
2285
2286 if (!atm_charge(vcc, hb->truesize)) {
2287 recycle_iovec_rx_bufs(card, iov,
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002288 NS_PRV_IOVCNT(iovb));
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002289 if (card->hbpool.count < card->hbnr.max) {
2290 skb_queue_tail(&card->hbpool.queue, hb);
2291 card->hbpool.count++;
2292 } else
2293 dev_kfree_skb_any(hb);
2294 atomic_inc(&vcc->stats->rx_drop);
2295 } else {
2296 /* Copy the small buffer to the huge buffer */
2297 sb = (struct sk_buff *)iov->iov_base;
2298 skb_copy_from_linear_data(sb, hb->data,
2299 iov->iov_len);
2300 skb_put(hb, iov->iov_len);
2301 remaining = len - iov->iov_len;
2302 iov++;
2303 /* Free the small buffer */
2304 push_rxbufs(card, sb);
2305
2306 /* Copy all large buffers to the huge buffer and free them */
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002307 for (j = 1; j < NS_PRV_IOVCNT(iovb); j++) {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002308 lb = (struct sk_buff *)iov->iov_base;
2309 tocopy =
2310 min_t(int, remaining, iov->iov_len);
2311 skb_copy_from_linear_data(lb,
2312 skb_tail_pointer
2313 (hb), tocopy);
2314 skb_put(hb, tocopy);
2315 iov++;
2316 remaining -= tocopy;
2317 push_rxbufs(card, lb);
2318 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319#ifdef EXTRA_DEBUG
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002320 if (remaining != 0 || hb->len != len)
2321 printk
2322 ("nicstar%d: Huge buffer len mismatch.\n",
2323 card->index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324#endif /* EXTRA_DEBUG */
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002325 ATM_SKB(hb)->vcc = vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326#ifdef NS_USE_DESTRUCTORS
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002327 hb->destructor = ns_hb_destructor;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328#endif /* NS_USE_DESTRUCTORS */
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002329 __net_timestamp(hb);
2330 vcc->push(vcc, hb);
2331 atomic_inc(&vcc->stats->rx);
2332 }
2333 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002335 vc->rx_iov = NULL;
2336 recycle_iov_buf(card, iovb);
2337 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338
2339}
2340
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341#ifdef NS_USE_DESTRUCTORS
2342
2343static void ns_sb_destructor(struct sk_buff *sb)
2344{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002345 ns_dev *card;
2346 u32 stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002348 card = (ns_dev *) ATM_SKB(sb)->vcc->dev->dev_data;
2349 stat = readl(card->membase + STAT);
2350 card->sbfqc = ns_stat_sfbqc_get(stat);
2351 card->lbfqc = ns_stat_lfbqc_get(stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002353 do {
2354 sb = __dev_alloc_skb(NS_SMSKBSIZE, GFP_KERNEL);
2355 if (sb == NULL)
2356 break;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002357 NS_PRV_BUFTYPE(sb) = BUF_SM;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002358 skb_queue_tail(&card->sbpool.queue, sb);
2359 skb_reserve(sb, NS_AAL0_HEADER);
2360 push_rxbufs(card, sb);
2361 } while (card->sbfqc < card->sbnr.min);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362}
2363
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364static void ns_lb_destructor(struct sk_buff *lb)
2365{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002366 ns_dev *card;
2367 u32 stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002369 card = (ns_dev *) ATM_SKB(lb)->vcc->dev->dev_data;
2370 stat = readl(card->membase + STAT);
2371 card->sbfqc = ns_stat_sfbqc_get(stat);
2372 card->lbfqc = ns_stat_lfbqc_get(stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002374 do {
2375 lb = __dev_alloc_skb(NS_LGSKBSIZE, GFP_KERNEL);
2376 if (lb == NULL)
2377 break;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002378 NS_PRV_BUFTYPE(lb) = BUF_LG;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002379 skb_queue_tail(&card->lbpool.queue, lb);
2380 skb_reserve(lb, NS_SMBUFSIZE);
2381 push_rxbufs(card, lb);
2382 } while (card->lbfqc < card->lbnr.min);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383}
2384
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385static void ns_hb_destructor(struct sk_buff *hb)
2386{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002387 ns_dev *card;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002389 card = (ns_dev *) ATM_SKB(hb)->vcc->dev->dev_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002391 while (card->hbpool.count < card->hbnr.init) {
2392 hb = __dev_alloc_skb(NS_HBUFSIZE, GFP_KERNEL);
2393 if (hb == NULL)
2394 break;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002395 NS_PRV_BUFTYPE(hb) = BUF_NONE;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002396 skb_queue_tail(&card->hbpool.queue, hb);
2397 card->hbpool.count++;
2398 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399}
2400
2401#endif /* NS_USE_DESTRUCTORS */
2402
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002403static void recycle_rx_buf(ns_dev * card, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404{
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002405 if (unlikely(NS_PRV_BUFTYPE(skb) == BUF_NONE)) {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002406 printk("nicstar%d: What kind of rx buffer is this?\n",
2407 card->index);
David S. Miller8728b832005-08-09 19:25:21 -07002408 dev_kfree_skb_any(skb);
2409 } else
2410 push_rxbufs(card, skb);
2411}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002413static void recycle_iovec_rx_bufs(ns_dev * card, struct iovec *iov, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414{
David S. Miller8728b832005-08-09 19:25:21 -07002415 while (count-- > 0)
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002416 recycle_rx_buf(card, (struct sk_buff *)(iov++)->iov_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417}
2418
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002419static void recycle_iov_buf(ns_dev * card, struct sk_buff *iovb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002421 if (card->iovpool.count < card->iovnr.max) {
2422 skb_queue_tail(&card->iovpool.queue, iovb);
2423 card->iovpool.count++;
2424 } else
2425 dev_kfree_skb_any(iovb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426}
2427
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002428static void dequeue_sm_buf(ns_dev * card, struct sk_buff *sb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002430 skb_unlink(sb, &card->sbpool.queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431#ifdef NS_USE_DESTRUCTORS
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002432 if (card->sbfqc < card->sbnr.min)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433#else
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002434 if (card->sbfqc < card->sbnr.init) {
2435 struct sk_buff *new_sb;
2436 if ((new_sb = dev_alloc_skb(NS_SMSKBSIZE)) != NULL) {
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002437 NS_PRV_BUFTYPE(new_sb) = BUF_SM;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002438 skb_queue_tail(&card->sbpool.queue, new_sb);
2439 skb_reserve(new_sb, NS_AAL0_HEADER);
2440 push_rxbufs(card, new_sb);
2441 }
2442 }
2443 if (card->sbfqc < card->sbnr.init)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444#endif /* NS_USE_DESTRUCTORS */
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002445 {
2446 struct sk_buff *new_sb;
2447 if ((new_sb = dev_alloc_skb(NS_SMSKBSIZE)) != NULL) {
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002448 NS_PRV_BUFTYPE(new_sb) = BUF_SM;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002449 skb_queue_tail(&card->sbpool.queue, new_sb);
2450 skb_reserve(new_sb, NS_AAL0_HEADER);
2451 push_rxbufs(card, new_sb);
2452 }
2453 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454}
2455
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002456static void dequeue_lg_buf(ns_dev * card, struct sk_buff *lb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002458 skb_unlink(lb, &card->lbpool.queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459#ifdef NS_USE_DESTRUCTORS
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002460 if (card->lbfqc < card->lbnr.min)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461#else
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002462 if (card->lbfqc < card->lbnr.init) {
2463 struct sk_buff *new_lb;
2464 if ((new_lb = dev_alloc_skb(NS_LGSKBSIZE)) != NULL) {
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002465 NS_PRV_BUFTYPE(new_lb) = BUF_LG;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002466 skb_queue_tail(&card->lbpool.queue, new_lb);
2467 skb_reserve(new_lb, NS_SMBUFSIZE);
2468 push_rxbufs(card, new_lb);
2469 }
2470 }
2471 if (card->lbfqc < card->lbnr.init)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472#endif /* NS_USE_DESTRUCTORS */
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002473 {
2474 struct sk_buff *new_lb;
2475 if ((new_lb = dev_alloc_skb(NS_LGSKBSIZE)) != NULL) {
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002476 NS_PRV_BUFTYPE(new_lb) = BUF_LG;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002477 skb_queue_tail(&card->lbpool.queue, new_lb);
2478 skb_reserve(new_lb, NS_SMBUFSIZE);
2479 push_rxbufs(card, new_lb);
2480 }
2481 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482}
2483
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002484static int ns_proc_read(struct atm_dev *dev, loff_t * pos, char *page)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002486 u32 stat;
2487 ns_dev *card;
2488 int left;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002490 left = (int)*pos;
2491 card = (ns_dev *) dev->dev_data;
2492 stat = readl(card->membase + STAT);
2493 if (!left--)
2494 return sprintf(page, "Pool count min init max \n");
2495 if (!left--)
2496 return sprintf(page, "Small %5d %5d %5d %5d \n",
2497 ns_stat_sfbqc_get(stat), card->sbnr.min,
2498 card->sbnr.init, card->sbnr.max);
2499 if (!left--)
2500 return sprintf(page, "Large %5d %5d %5d %5d \n",
2501 ns_stat_lfbqc_get(stat), card->lbnr.min,
2502 card->lbnr.init, card->lbnr.max);
2503 if (!left--)
2504 return sprintf(page, "Huge %5d %5d %5d %5d \n",
2505 card->hbpool.count, card->hbnr.min,
2506 card->hbnr.init, card->hbnr.max);
2507 if (!left--)
2508 return sprintf(page, "Iovec %5d %5d %5d %5d \n",
2509 card->iovpool.count, card->iovnr.min,
2510 card->iovnr.init, card->iovnr.max);
2511 if (!left--) {
2512 int retval;
2513 retval =
2514 sprintf(page, "Interrupt counter: %u \n", card->intcnt);
2515 card->intcnt = 0;
2516 return retval;
2517 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518#if 0
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002519 /* Dump 25.6 Mbps PHY registers */
2520 /* Now there's a 25.6 Mbps PHY driver this code isn't needed. I left it
2521 here just in case it's needed for debugging. */
2522 if (card->max_pcr == ATM_25_PCR && !left--) {
2523 u32 phy_regs[4];
2524 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002526 for (i = 0; i < 4; i++) {
2527 while (CMD_BUSY(card)) ;
2528 writel(NS_CMD_READ_UTILITY | 0x00000200 | i,
2529 card->membase + CMD);
2530 while (CMD_BUSY(card)) ;
2531 phy_regs[i] = readl(card->membase + DR0) & 0x000000FF;
2532 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002534 return sprintf(page, "PHY regs: 0x%02X 0x%02X 0x%02X 0x%02X \n",
2535 phy_regs[0], phy_regs[1], phy_regs[2],
2536 phy_regs[3]);
2537 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538#endif /* 0 - Dump 25.6 Mbps PHY registers */
2539#if 0
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002540 /* Dump TST */
2541 if (left-- < NS_TST_NUM_ENTRIES) {
2542 if (card->tste2vc[left + 1] == NULL)
2543 return sprintf(page, "%5d - VBR/UBR \n", left + 1);
2544 else
2545 return sprintf(page, "%5d - %d %d \n", left + 1,
2546 card->tste2vc[left + 1]->tx_vcc->vpi,
2547 card->tste2vc[left + 1]->tx_vcc->vci);
2548 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549#endif /* 0 */
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002550 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551}
2552
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002553static int ns_ioctl(struct atm_dev *dev, unsigned int cmd, void __user * arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002555 ns_dev *card;
2556 pool_levels pl;
2557 long btype;
2558 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002560 card = dev->dev_data;
2561 switch (cmd) {
2562 case NS_GETPSTAT:
2563 if (get_user
2564 (pl.buftype, &((pool_levels __user *) arg)->buftype))
2565 return -EFAULT;
2566 switch (pl.buftype) {
2567 case NS_BUFTYPE_SMALL:
2568 pl.count =
2569 ns_stat_sfbqc_get(readl(card->membase + STAT));
2570 pl.level.min = card->sbnr.min;
2571 pl.level.init = card->sbnr.init;
2572 pl.level.max = card->sbnr.max;
2573 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002575 case NS_BUFTYPE_LARGE:
2576 pl.count =
2577 ns_stat_lfbqc_get(readl(card->membase + STAT));
2578 pl.level.min = card->lbnr.min;
2579 pl.level.init = card->lbnr.init;
2580 pl.level.max = card->lbnr.max;
2581 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002583 case NS_BUFTYPE_HUGE:
2584 pl.count = card->hbpool.count;
2585 pl.level.min = card->hbnr.min;
2586 pl.level.init = card->hbnr.init;
2587 pl.level.max = card->hbnr.max;
2588 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002590 case NS_BUFTYPE_IOVEC:
2591 pl.count = card->iovpool.count;
2592 pl.level.min = card->iovnr.min;
2593 pl.level.init = card->iovnr.init;
2594 pl.level.max = card->iovnr.max;
2595 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002597 default:
2598 return -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002600 }
2601 if (!copy_to_user((pool_levels __user *) arg, &pl, sizeof(pl)))
2602 return (sizeof(pl));
2603 else
2604 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002606 case NS_SETBUFLEV:
2607 if (!capable(CAP_NET_ADMIN))
2608 return -EPERM;
2609 if (copy_from_user(&pl, (pool_levels __user *) arg, sizeof(pl)))
2610 return -EFAULT;
2611 if (pl.level.min >= pl.level.init
2612 || pl.level.init >= pl.level.max)
2613 return -EINVAL;
2614 if (pl.level.min == 0)
2615 return -EINVAL;
2616 switch (pl.buftype) {
2617 case NS_BUFTYPE_SMALL:
2618 if (pl.level.max > TOP_SB)
2619 return -EINVAL;
2620 card->sbnr.min = pl.level.min;
2621 card->sbnr.init = pl.level.init;
2622 card->sbnr.max = pl.level.max;
2623 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002625 case NS_BUFTYPE_LARGE:
2626 if (pl.level.max > TOP_LB)
2627 return -EINVAL;
2628 card->lbnr.min = pl.level.min;
2629 card->lbnr.init = pl.level.init;
2630 card->lbnr.max = pl.level.max;
2631 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002633 case NS_BUFTYPE_HUGE:
2634 if (pl.level.max > TOP_HB)
2635 return -EINVAL;
2636 card->hbnr.min = pl.level.min;
2637 card->hbnr.init = pl.level.init;
2638 card->hbnr.max = pl.level.max;
2639 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002641 case NS_BUFTYPE_IOVEC:
2642 if (pl.level.max > TOP_IOVB)
2643 return -EINVAL;
2644 card->iovnr.min = pl.level.min;
2645 card->iovnr.init = pl.level.init;
2646 card->iovnr.max = pl.level.max;
2647 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002649 default:
2650 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002652 }
2653 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002655 case NS_ADJBUFLEV:
2656 if (!capable(CAP_NET_ADMIN))
2657 return -EPERM;
2658 btype = (long)arg; /* a long is the same size as a pointer or bigger */
2659 switch (btype) {
2660 case NS_BUFTYPE_SMALL:
2661 while (card->sbfqc < card->sbnr.init) {
2662 struct sk_buff *sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002664 sb = __dev_alloc_skb(NS_SMSKBSIZE, GFP_KERNEL);
2665 if (sb == NULL)
2666 return -ENOMEM;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002667 NS_PRV_BUFTYPE(sb) = BUF_SM;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002668 skb_queue_tail(&card->sbpool.queue, sb);
2669 skb_reserve(sb, NS_AAL0_HEADER);
2670 push_rxbufs(card, sb);
2671 }
2672 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002674 case NS_BUFTYPE_LARGE:
2675 while (card->lbfqc < card->lbnr.init) {
2676 struct sk_buff *lb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002678 lb = __dev_alloc_skb(NS_LGSKBSIZE, GFP_KERNEL);
2679 if (lb == NULL)
2680 return -ENOMEM;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002681 NS_PRV_BUFTYPE(lb) = BUF_LG;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002682 skb_queue_tail(&card->lbpool.queue, lb);
2683 skb_reserve(lb, NS_SMBUFSIZE);
2684 push_rxbufs(card, lb);
2685 }
2686 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002688 case NS_BUFTYPE_HUGE:
2689 while (card->hbpool.count > card->hbnr.init) {
2690 struct sk_buff *hb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002692 spin_lock_irqsave(&card->int_lock, flags);
2693 hb = skb_dequeue(&card->hbpool.queue);
2694 card->hbpool.count--;
2695 spin_unlock_irqrestore(&card->int_lock, flags);
2696 if (hb == NULL)
2697 printk
2698 ("nicstar%d: huge buffer count inconsistent.\n",
2699 card->index);
2700 else
2701 dev_kfree_skb_any(hb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002703 }
2704 while (card->hbpool.count < card->hbnr.init) {
2705 struct sk_buff *hb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002707 hb = __dev_alloc_skb(NS_HBUFSIZE, GFP_KERNEL);
2708 if (hb == NULL)
2709 return -ENOMEM;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002710 NS_PRV_BUFTYPE(hb) = BUF_NONE;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002711 spin_lock_irqsave(&card->int_lock, flags);
2712 skb_queue_tail(&card->hbpool.queue, hb);
2713 card->hbpool.count++;
2714 spin_unlock_irqrestore(&card->int_lock, flags);
2715 }
2716 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002718 case NS_BUFTYPE_IOVEC:
2719 while (card->iovpool.count > card->iovnr.init) {
2720 struct sk_buff *iovb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002722 spin_lock_irqsave(&card->int_lock, flags);
2723 iovb = skb_dequeue(&card->iovpool.queue);
2724 card->iovpool.count--;
2725 spin_unlock_irqrestore(&card->int_lock, flags);
2726 if (iovb == NULL)
2727 printk
2728 ("nicstar%d: iovec buffer count inconsistent.\n",
2729 card->index);
2730 else
2731 dev_kfree_skb_any(iovb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002733 }
2734 while (card->iovpool.count < card->iovnr.init) {
2735 struct sk_buff *iovb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002737 iovb = alloc_skb(NS_IOVBUFSIZE, GFP_KERNEL);
2738 if (iovb == NULL)
2739 return -ENOMEM;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002740 NS_PRV_BUFTYPE(iovb) = BUF_NONE;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002741 spin_lock_irqsave(&card->int_lock, flags);
2742 skb_queue_tail(&card->iovpool.queue, iovb);
2743 card->iovpool.count++;
2744 spin_unlock_irqrestore(&card->int_lock, flags);
2745 }
2746 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002748 default:
2749 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002751 }
2752 return 0;
2753
2754 default:
2755 if (dev->phy && dev->phy->ioctl) {
2756 return dev->phy->ioctl(dev, cmd, arg);
2757 } else {
2758 printk("nicstar%d: %s == NULL \n", card->index,
2759 dev->phy ? "dev->phy->ioctl" : "dev->phy");
2760 return -ENOIOCTLCMD;
2761 }
2762 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763}
2764
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002765#ifdef EXTRA_DEBUG
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002766static void which_list(ns_dev * card, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767{
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002768 printk("skb buf_type: 0x%08x\n", NS_PRV_BUFTYPE(skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769}
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002770#endif /* EXTRA_DEBUG */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772static void ns_poll(unsigned long arg)
2773{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002774 int i;
2775 ns_dev *card;
2776 unsigned long flags;
2777 u32 stat_r, stat_w;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002779 PRINTK("nicstar: Entering ns_poll().\n");
2780 for (i = 0; i < num_cards; i++) {
2781 card = cards[i];
2782 if (spin_is_locked(&card->int_lock)) {
2783 /* Probably it isn't worth spinning */
2784 continue;
2785 }
2786 spin_lock_irqsave(&card->int_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002788 stat_w = 0;
2789 stat_r = readl(card->membase + STAT);
2790 if (stat_r & NS_STAT_TSIF)
2791 stat_w |= NS_STAT_TSIF;
2792 if (stat_r & NS_STAT_EOPDU)
2793 stat_w |= NS_STAT_EOPDU;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002795 process_tsq(card);
2796 process_rsq(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002798 writel(stat_w, card->membase + STAT);
2799 spin_unlock_irqrestore(&card->int_lock, flags);
2800 }
2801 mod_timer(&ns_timer, jiffies + NS_POLL_PERIOD);
2802 PRINTK("nicstar: Leaving ns_poll().\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803}
2804
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805static int ns_parse_mac(char *mac, unsigned char *esi)
2806{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002807 int i, j;
2808 short byte1, byte0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002810 if (mac == NULL || esi == NULL)
2811 return -1;
2812 j = 0;
2813 for (i = 0; i < 6; i++) {
Andy Shevchenko2b278222010-07-23 03:18:06 +00002814 if ((byte1 = hex_to_bin(mac[j++])) < 0)
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002815 return -1;
Andy Shevchenko2b278222010-07-23 03:18:06 +00002816 if ((byte0 = hex_to_bin(mac[j++])) < 0)
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002817 return -1;
2818 esi[i] = (unsigned char)(byte1 * 16 + byte0);
2819 if (i < 5) {
2820 if (mac[j++] != ':')
2821 return -1;
2822 }
2823 }
2824 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825}
2826
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828static void ns_phy_put(struct atm_dev *dev, unsigned char value,
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002829 unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002831 ns_dev *card;
2832 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002834 card = dev->dev_data;
2835 spin_lock_irqsave(&card->res_lock, flags);
2836 while (CMD_BUSY(card)) ;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002837 writel((u32) value, card->membase + DR0);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002838 writel(NS_CMD_WRITE_UTILITY | 0x00000200 | (addr & 0x000000FF),
2839 card->membase + CMD);
2840 spin_unlock_irqrestore(&card->res_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841}
2842
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843static unsigned char ns_phy_get(struct atm_dev *dev, unsigned long addr)
2844{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002845 ns_dev *card;
2846 unsigned long flags;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002847 u32 data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002849 card = dev->dev_data;
2850 spin_lock_irqsave(&card->res_lock, flags);
2851 while (CMD_BUSY(card)) ;
2852 writel(NS_CMD_READ_UTILITY | 0x00000200 | (addr & 0x000000FF),
2853 card->membase + CMD);
2854 while (CMD_BUSY(card)) ;
2855 data = readl(card->membase + DR0) & 0x000000FF;
2856 spin_unlock_irqrestore(&card->res_lock, flags);
2857 return (unsigned char)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858}
2859
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860module_init(nicstar_init);
2861module_exit(nicstar_cleanup);