blob: 09ad73361879e1a7b84944382e8927a01d4d00e4 [file] [log] [blame]
Thomas Gleixner09c434b2019-05-19 13:08:20 +01001// SPDX-License-Identifier: GPL-2.0-only
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * nicstar.c
4 *
5 * Device driver supporting CBR for IDT 77201/77211 "NICStAR" based cards.
6 *
7 * IMPORTANT: The included file nicstarmac.c was NOT WRITTEN BY ME.
8 * It was taken from the frle-0.22 device driver.
9 * As the file doesn't have a copyright notice, in the file
10 * nicstarmac.copyright I put the copyright notice from the
11 * frle-0.22 device driver.
12 * Some code is based on the nicstar driver by M. Welsh.
13 *
14 * Author: Rui Prior (rprior@inescn.pt)
15 * PowerPC support by Jay Talbott (jay_talbott@mcg.mot.com) April 1999
16 *
17 *
18 * (C) INESC 1999
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +000019 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +000021/*
22 * IMPORTANT INFORMATION
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 *
24 * There are currently three types of spinlocks:
25 *
26 * 1 - Per card interrupt spinlock (to protect structures and such)
27 * 2 - Per SCQ scq spinlock
28 * 3 - Per card resource spinlock (to access registers, etc.)
29 *
30 * These must NEVER be grabbed in reverse order.
31 *
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +000032 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +000034/* Header files */
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/kernel.h>
38#include <linux/skbuff.h>
39#include <linux/atmdev.h>
40#include <linux/atm.h>
41#include <linux/pci.h>
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +000042#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/types.h>
44#include <linux/string.h>
45#include <linux/delay.h>
46#include <linux/init.h>
47#include <linux/sched.h>
48#include <linux/timer.h>
49#include <linux/interrupt.h>
50#include <linux/bitops.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090051#include <linux/slab.h>
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +000052#include <linux/idr.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#include <asm/io.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080054#include <linux/uaccess.h>
Arun Sharma600634972011-07-26 16:09:06 -070055#include <linux/atomic.h>
dingtianhong4c55a462013-12-26 19:41:02 +080056#include <linux/etherdevice.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#include "nicstar.h"
58#ifdef CONFIG_ATM_NICSTAR_USE_SUNI
59#include "suni.h"
60#endif /* CONFIG_ATM_NICSTAR_USE_SUNI */
61#ifdef CONFIG_ATM_NICSTAR_USE_IDT77105
62#include "idt77105.h"
63#endif /* CONFIG_ATM_NICSTAR_USE_IDT77105 */
64
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +000065/* Additional code */
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67#include "nicstarmac.c"
68
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +000069/* Configurable parameters */
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71#undef PHY_LOOPBACK
72#undef TX_DEBUG
73#undef RX_DEBUG
74#undef GENERAL_DEBUG
75#undef EXTRA_DEBUG
76
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +000077/* Do not touch these */
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79#ifdef TX_DEBUG
80#define TXPRINTK(args...) printk(args)
81#else
82#define TXPRINTK(args...)
83#endif /* TX_DEBUG */
84
85#ifdef RX_DEBUG
86#define RXPRINTK(args...) printk(args)
87#else
88#define RXPRINTK(args...)
89#endif /* RX_DEBUG */
90
91#ifdef GENERAL_DEBUG
92#define PRINTK(args...) printk(args)
93#else
Randy Dunlap8a171c52020-02-27 18:09:44 -080094#define PRINTK(args...) do {} while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095#endif /* GENERAL_DEBUG */
96
97#ifdef EXTRA_DEBUG
98#define XPRINTK(args...) printk(args)
99#else
100#define XPRINTK(args...)
101#endif /* EXTRA_DEBUG */
102
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000103/* Macros */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105#define CMD_BUSY(card) (readl((card)->membase + STAT) & NS_STAT_CMDBZ)
106
107#define NS_DELAY mdelay(1)
108
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000109#define PTR_DIFF(a, b) ((u32)((unsigned long)(a) - (unsigned long)(b)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111#ifndef ATM_SKB
112#define ATM_SKB(s) (&(s)->atm)
113#endif
114
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000115#define scq_virt_to_bus(scq, p) \
116 (scq->dma + ((unsigned long)(p) - (unsigned long)(scq)->org))
117
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000118/* Function declarations */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000120static u32 ns_read_sram(ns_dev * card, u32 sram_address);
121static void ns_write_sram(ns_dev * card, u32 sram_address, u32 * value,
122 int count);
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -0800123static int ns_init_card(int i, struct pci_dev *pcidev);
124static void ns_init_card_error(ns_dev * card, int error);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000125static scq_info *get_scq(ns_dev *card, int size, u32 scd);
126static void free_scq(ns_dev *card, scq_info * scq, struct atm_vcc *vcc);
David S. Miller8728b832005-08-09 19:25:21 -0700127static void push_rxbufs(ns_dev *, struct sk_buff *);
David Howells7d12e782006-10-05 14:55:46 +0100128static irqreturn_t ns_irq_handler(int irq, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129static int ns_open(struct atm_vcc *vcc);
130static void ns_close(struct atm_vcc *vcc);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000131static void fill_tst(ns_dev * card, int n, vc_map * vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000133static int push_scqe(ns_dev * card, vc_map * vc, scq_info * scq, ns_scqe * tbd,
134 struct sk_buff *skb);
135static void process_tsq(ns_dev * card);
136static void drain_scq(ns_dev * card, scq_info * scq, int pos);
137static void process_rsq(ns_dev * card);
138static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000139static void recycle_rx_buf(ns_dev * card, struct sk_buff *skb);
140static void recycle_iovec_rx_bufs(ns_dev * card, struct iovec *iov, int count);
141static void recycle_iov_buf(ns_dev * card, struct sk_buff *iovb);
142static void dequeue_sm_buf(ns_dev * card, struct sk_buff *sb);
143static void dequeue_lg_buf(ns_dev * card, struct sk_buff *lb);
144static int ns_proc_read(struct atm_dev *dev, loff_t * pos, char *page);
145static int ns_ioctl(struct atm_dev *dev, unsigned int cmd, void __user * arg);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000146#ifdef EXTRA_DEBUG
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000147static void which_list(ns_dev * card, struct sk_buff *skb);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000148#endif
Kees Cooke99e88a2017-10-16 14:43:17 -0700149static void ns_poll(struct timer_list *unused);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150static void ns_phy_put(struct atm_dev *dev, unsigned char value,
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000151 unsigned long addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152static unsigned char ns_phy_get(struct atm_dev *dev, unsigned long addr);
153
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000154/* Global variables */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
156static struct ns_dev *cards[NS_MAX_CARDS];
157static unsigned num_cards;
Bhumika Goyal46c4b7a2017-08-09 14:49:15 +0530158static const struct atmdev_ops atm_ops = {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000159 .open = ns_open,
160 .close = ns_close,
161 .ioctl = ns_ioctl,
162 .send = ns_send,
163 .phy_put = ns_phy_put,
164 .phy_get = ns_phy_get,
165 .proc_read = ns_proc_read,
166 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167};
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169static struct timer_list ns_timer;
170static char *mac[NS_MAX_CARDS];
171module_param_array(mac, charp, NULL, 0);
172MODULE_LICENSE("GPL");
173
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000174/* Functions */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -0800176static int nicstar_init_one(struct pci_dev *pcidev,
177 const struct pci_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000179 static int index = -1;
180 unsigned int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000182 index++;
183 cards[index] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000185 error = ns_init_card(index, pcidev);
186 if (error) {
187 cards[index--] = NULL; /* don't increment index */
188 goto err_out;
189 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000191 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192err_out:
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000193 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194}
195
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -0800196static void nicstar_remove_one(struct pci_dev *pcidev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000198 int i, j;
199 ns_dev *card = pci_get_drvdata(pcidev);
200 struct sk_buff *hb;
201 struct sk_buff *iovb;
202 struct sk_buff *lb;
203 struct sk_buff *sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000205 i = card->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000207 if (cards[i] == NULL)
208 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000210 if (card->atmdev->phy && card->atmdev->phy->stop)
211 card->atmdev->phy->stop(card->atmdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000213 /* Stop everything */
214 writel(0x00000000, card->membase + CFG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000216 /* De-register device */
217 atm_dev_deregister(card->atmdev);
218
219 /* Disable PCI device */
220 pci_disable_device(pcidev);
221
222 /* Free up resources */
223 j = 0;
224 PRINTK("nicstar%d: freeing %d huge buffers.\n", i, card->hbpool.count);
225 while ((hb = skb_dequeue(&card->hbpool.queue)) != NULL) {
226 dev_kfree_skb_any(hb);
227 j++;
228 }
229 PRINTK("nicstar%d: %d huge buffers freed.\n", i, j);
230 j = 0;
231 PRINTK("nicstar%d: freeing %d iovec buffers.\n", i,
232 card->iovpool.count);
233 while ((iovb = skb_dequeue(&card->iovpool.queue)) != NULL) {
234 dev_kfree_skb_any(iovb);
235 j++;
236 }
237 PRINTK("nicstar%d: %d iovec buffers freed.\n", i, j);
238 while ((lb = skb_dequeue(&card->lbpool.queue)) != NULL)
239 dev_kfree_skb_any(lb);
240 while ((sb = skb_dequeue(&card->sbpool.queue)) != NULL)
241 dev_kfree_skb_any(sb);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000242 free_scq(card, card->scq0, NULL);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000243 for (j = 0; j < NS_FRSCD_NUM; j++) {
244 if (card->scd2vc[j] != NULL)
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000245 free_scq(card, card->scd2vc[j]->scq, card->scd2vc[j]->tx_vcc);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000246 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000247 idr_destroy(&card->idr);
chas williams - CONTRACTORede58ef2015-01-16 08:57:21 -0500248 dma_free_coherent(&card->pcidev->dev, NS_RSQSIZE + NS_RSQ_ALIGNMENT,
249 card->rsq.org, card->rsq.dma);
250 dma_free_coherent(&card->pcidev->dev, NS_TSQSIZE + NS_TSQ_ALIGNMENT,
251 card->tsq.org, card->tsq.dma);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000252 free_irq(card->pcidev->irq, card);
253 iounmap(card->membase);
254 kfree(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255}
256
Arvind Yadav2f3e2602017-07-16 15:02:32 +0530257static const struct pci_device_id nicstar_pci_tbl[] = {
Peter Huewe6df7b802010-07-15 08:48:26 +0000258 { PCI_VDEVICE(IDT, PCI_DEVICE_ID_IDT_IDT77201), 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 {0,} /* terminate list */
260};
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000261
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262MODULE_DEVICE_TABLE(pci, nicstar_pci_tbl);
263
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264static struct pci_driver nicstar_driver = {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000265 .name = "nicstar",
266 .id_table = nicstar_pci_tbl,
267 .probe = nicstar_init_one,
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -0800268 .remove = nicstar_remove_one,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269};
270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271static int __init nicstar_init(void)
272{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000273 unsigned error = 0; /* Initialized to remove compile warning */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000275 XPRINTK("nicstar: nicstar_init() called.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000277 error = pci_register_driver(&nicstar_driver);
278
279 TXPRINTK("nicstar: TX debug enabled.\n");
280 RXPRINTK("nicstar: RX debug enabled.\n");
281 PRINTK("nicstar: General debug enabled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282#ifdef PHY_LOOPBACK
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000283 printk("nicstar: using PHY loopback.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284#endif /* PHY_LOOPBACK */
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000285 XPRINTK("nicstar: nicstar_init() returned.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000287 if (!error) {
Kees Cooke99e88a2017-10-16 14:43:17 -0700288 timer_setup(&ns_timer, ns_poll, 0);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000289 ns_timer.expires = jiffies + NS_POLL_PERIOD;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000290 add_timer(&ns_timer);
291 }
292
293 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294}
295
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296static void __exit nicstar_cleanup(void)
297{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000298 XPRINTK("nicstar: nicstar_cleanup() called.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000300 del_timer(&ns_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000302 pci_unregister_driver(&nicstar_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000304 XPRINTK("nicstar: nicstar_cleanup() returned.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305}
306
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000307static u32 ns_read_sram(ns_dev * card, u32 sram_address)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000309 unsigned long flags;
310 u32 data;
311 sram_address <<= 2;
312 sram_address &= 0x0007FFFC; /* address must be dword aligned */
313 sram_address |= 0x50000000; /* SRAM read command */
314 spin_lock_irqsave(&card->res_lock, flags);
315 while (CMD_BUSY(card)) ;
316 writel(sram_address, card->membase + CMD);
317 while (CMD_BUSY(card)) ;
318 data = readl(card->membase + DR0);
319 spin_unlock_irqrestore(&card->res_lock, flags);
320 return data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321}
322
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000323static void ns_write_sram(ns_dev * card, u32 sram_address, u32 * value,
324 int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000326 unsigned long flags;
327 int i, c;
328 count--; /* count range now is 0..3 instead of 1..4 */
329 c = count;
330 c <<= 2; /* to use increments of 4 */
331 spin_lock_irqsave(&card->res_lock, flags);
332 while (CMD_BUSY(card)) ;
333 for (i = 0; i <= c; i += 4)
334 writel(*(value++), card->membase + i);
335 /* Note: DR# registers are the first 4 dwords in nicstar's memspace,
336 so card->membase + DR0 == card->membase */
337 sram_address <<= 2;
338 sram_address &= 0x0007FFFC;
339 sram_address |= (0x40000000 | count);
340 writel(sram_address, card->membase + CMD);
341 spin_unlock_irqrestore(&card->res_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342}
343
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -0800344static int ns_init_card(int i, struct pci_dev *pcidev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000346 int j;
347 struct ns_dev *card = NULL;
348 unsigned char pci_latency;
349 unsigned error;
350 u32 data;
351 u32 u32d[4];
352 u32 ns_cfg_rctsize;
353 int bcount;
354 unsigned long membase;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000356 error = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000358 if (pci_enable_device(pcidev)) {
359 printk("nicstar%d: can't enable PCI device\n", i);
360 error = 2;
361 ns_init_card_error(card, error);
362 return error;
363 }
chas williams - CONTRACTORede58ef2015-01-16 08:57:21 -0500364 if (dma_set_mask_and_coherent(&pcidev->dev, DMA_BIT_MASK(32)) != 0) {
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000365 printk(KERN_WARNING
366 "nicstar%d: No suitable DMA available.\n", i);
367 error = 2;
368 ns_init_card_error(card, error);
369 return error;
370 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Markus Elfring304f0a4e2016-09-10 08:48:17 +0200372 card = kmalloc(sizeof(*card), GFP_KERNEL);
373 if (!card) {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000374 printk
375 ("nicstar%d: can't allocate memory for device structure.\n",
376 i);
377 error = 2;
378 ns_init_card_error(card, error);
379 return error;
380 }
381 cards[i] = card;
382 spin_lock_init(&card->int_lock);
383 spin_lock_init(&card->res_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000385 pci_set_drvdata(pcidev, card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000387 card->index = i;
388 card->atmdev = NULL;
389 card->pcidev = pcidev;
390 membase = pci_resource_start(pcidev, 1);
391 card->membase = ioremap(membase, NS_IOREMAP_SIZE);
392 if (!card->membase) {
393 printk("nicstar%d: can't ioremap() membase.\n", i);
394 error = 3;
395 ns_init_card_error(card, error);
396 return error;
397 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000398 PRINTK("nicstar%d: membase at 0x%p.\n", i, card->membase);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000399
400 pci_set_master(pcidev);
401
402 if (pci_read_config_byte(pcidev, PCI_LATENCY_TIMER, &pci_latency) != 0) {
403 printk("nicstar%d: can't read PCI latency timer.\n", i);
404 error = 6;
405 ns_init_card_error(card, error);
406 return error;
407 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408#ifdef NS_PCI_LATENCY
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000409 if (pci_latency < NS_PCI_LATENCY) {
410 PRINTK("nicstar%d: setting PCI latency timer to %d.\n", i,
411 NS_PCI_LATENCY);
412 for (j = 1; j < 4; j++) {
413 if (pci_write_config_byte
414 (pcidev, PCI_LATENCY_TIMER, NS_PCI_LATENCY) != 0)
415 break;
416 }
417 if (j == 4) {
418 printk
419 ("nicstar%d: can't set PCI latency timer to %d.\n",
420 i, NS_PCI_LATENCY);
421 error = 7;
422 ns_init_card_error(card, error);
423 return error;
424 }
425 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426#endif /* NS_PCI_LATENCY */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000428 /* Clear timer overflow */
429 data = readl(card->membase + STAT);
430 if (data & NS_STAT_TMROF)
431 writel(NS_STAT_TMROF, card->membase + STAT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000433 /* Software reset */
434 writel(NS_CFG_SWRST, card->membase + CFG);
435 NS_DELAY;
436 writel(0x00000000, card->membase + CFG);
437
438 /* PHY reset */
439 writel(0x00000008, card->membase + GP);
440 NS_DELAY;
441 writel(0x00000001, card->membase + GP);
442 NS_DELAY;
443 while (CMD_BUSY(card)) ;
444 writel(NS_CMD_WRITE_UTILITY | 0x00000100, card->membase + CMD); /* Sync UTOPIA with SAR clock */
445 NS_DELAY;
446
447 /* Detect PHY type */
448 while (CMD_BUSY(card)) ;
449 writel(NS_CMD_READ_UTILITY | 0x00000200, card->membase + CMD);
450 while (CMD_BUSY(card)) ;
451 data = readl(card->membase + DR0);
452 switch (data) {
453 case 0x00000009:
454 printk("nicstar%d: PHY seems to be 25 Mbps.\n", i);
455 card->max_pcr = ATM_25_PCR;
456 while (CMD_BUSY(card)) ;
457 writel(0x00000008, card->membase + DR0);
458 writel(NS_CMD_WRITE_UTILITY | 0x00000200, card->membase + CMD);
459 /* Clear an eventual pending interrupt */
460 writel(NS_STAT_SFBQF, card->membase + STAT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461#ifdef PHY_LOOPBACK
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000462 while (CMD_BUSY(card)) ;
463 writel(0x00000022, card->membase + DR0);
464 writel(NS_CMD_WRITE_UTILITY | 0x00000202, card->membase + CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465#endif /* PHY_LOOPBACK */
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000466 break;
467 case 0x00000030:
468 case 0x00000031:
469 printk("nicstar%d: PHY seems to be 155 Mbps.\n", i);
470 card->max_pcr = ATM_OC3_PCR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471#ifdef PHY_LOOPBACK
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000472 while (CMD_BUSY(card)) ;
473 writel(0x00000002, card->membase + DR0);
474 writel(NS_CMD_WRITE_UTILITY | 0x00000205, card->membase + CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475#endif /* PHY_LOOPBACK */
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000476 break;
477 default:
478 printk("nicstar%d: unknown PHY type (0x%08X).\n", i, data);
479 error = 8;
480 ns_init_card_error(card, error);
481 return error;
482 }
483 writel(0x00000000, card->membase + GP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000485 /* Determine SRAM size */
486 data = 0x76543210;
487 ns_write_sram(card, 0x1C003, &data, 1);
488 data = 0x89ABCDEF;
489 ns_write_sram(card, 0x14003, &data, 1);
490 if (ns_read_sram(card, 0x14003) == 0x89ABCDEF &&
491 ns_read_sram(card, 0x1C003) == 0x76543210)
492 card->sram_size = 128;
493 else
494 card->sram_size = 32;
495 PRINTK("nicstar%d: %dK x 32bit SRAM size.\n", i, card->sram_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000497 card->rct_size = NS_MAX_RCTSIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
499#if (NS_MAX_RCTSIZE == 4096)
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000500 if (card->sram_size == 128)
501 printk
502 ("nicstar%d: limiting maximum VCI. See NS_MAX_RCTSIZE in nicstar.h\n",
503 i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504#elif (NS_MAX_RCTSIZE == 16384)
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000505 if (card->sram_size == 32) {
506 printk
507 ("nicstar%d: wasting memory. See NS_MAX_RCTSIZE in nicstar.h\n",
508 i);
509 card->rct_size = 4096;
510 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511#else
512#error NS_MAX_RCTSIZE must be either 4096 or 16384 in nicstar.c
513#endif
514
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000515 card->vpibits = NS_VPIBITS;
516 if (card->rct_size == 4096)
517 card->vcibits = 12 - NS_VPIBITS;
518 else /* card->rct_size == 16384 */
519 card->vcibits = 14 - NS_VPIBITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000521 /* Initialize the nicstar eeprom/eprom stuff, for the MAC addr */
522 if (mac[i] == NULL)
523 nicstar_init_eprom(card->membase);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000525 /* Set the VPI/VCI MSb mask to zero so we can receive OAM cells */
526 writel(0x00000000, card->membase + VPM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000528 /* Initialize TSQ */
chas williams - CONTRACTORede58ef2015-01-16 08:57:21 -0500529 card->tsq.org = dma_alloc_coherent(&card->pcidev->dev,
530 NS_TSQSIZE + NS_TSQ_ALIGNMENT,
531 &card->tsq.dma, GFP_KERNEL);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000532 if (card->tsq.org == NULL) {
533 printk("nicstar%d: can't allocate TSQ.\n", i);
534 error = 10;
535 ns_init_card_error(card, error);
536 return error;
537 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000538 card->tsq.base = PTR_ALIGN(card->tsq.org, NS_TSQ_ALIGNMENT);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000539 card->tsq.next = card->tsq.base;
540 card->tsq.last = card->tsq.base + (NS_TSQ_NUM_ENTRIES - 1);
541 for (j = 0; j < NS_TSQ_NUM_ENTRIES; j++)
542 ns_tsi_init(card->tsq.base + j);
543 writel(0x00000000, card->membase + TSQH);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000544 writel(ALIGN(card->tsq.dma, NS_TSQ_ALIGNMENT), card->membase + TSQB);
545 PRINTK("nicstar%d: TSQ base at 0x%p.\n", i, card->tsq.base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000547 /* Initialize RSQ */
chas williams - CONTRACTORede58ef2015-01-16 08:57:21 -0500548 card->rsq.org = dma_alloc_coherent(&card->pcidev->dev,
549 NS_RSQSIZE + NS_RSQ_ALIGNMENT,
550 &card->rsq.dma, GFP_KERNEL);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000551 if (card->rsq.org == NULL) {
552 printk("nicstar%d: can't allocate RSQ.\n", i);
553 error = 11;
554 ns_init_card_error(card, error);
555 return error;
556 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000557 card->rsq.base = PTR_ALIGN(card->rsq.org, NS_RSQ_ALIGNMENT);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000558 card->rsq.next = card->rsq.base;
559 card->rsq.last = card->rsq.base + (NS_RSQ_NUM_ENTRIES - 1);
560 for (j = 0; j < NS_RSQ_NUM_ENTRIES; j++)
561 ns_rsqe_init(card->rsq.base + j);
562 writel(0x00000000, card->membase + RSQH);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000563 writel(ALIGN(card->rsq.dma, NS_RSQ_ALIGNMENT), card->membase + RSQB);
564 PRINTK("nicstar%d: RSQ base at 0x%p.\n", i, card->rsq.base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000566 /* Initialize SCQ0, the only VBR SCQ used */
567 card->scq1 = NULL;
568 card->scq2 = NULL;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000569 card->scq0 = get_scq(card, VBR_SCQSIZE, NS_VRSCD0);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000570 if (card->scq0 == NULL) {
571 printk("nicstar%d: can't get SCQ0.\n", i);
572 error = 12;
573 ns_init_card_error(card, error);
574 return error;
575 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000576 u32d[0] = scq_virt_to_bus(card->scq0, card->scq0->base);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000577 u32d[1] = (u32) 0x00000000;
578 u32d[2] = (u32) 0xffffffff;
579 u32d[3] = (u32) 0x00000000;
580 ns_write_sram(card, NS_VRSCD0, u32d, 4);
581 ns_write_sram(card, NS_VRSCD1, u32d, 4); /* These last two won't be used */
582 ns_write_sram(card, NS_VRSCD2, u32d, 4); /* but are initialized, just in case... */
583 card->scq0->scd = NS_VRSCD0;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000584 PRINTK("nicstar%d: VBR-SCQ0 base at 0x%p.\n", i, card->scq0->base);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000585
586 /* Initialize TSTs */
587 card->tst_addr = NS_TST0;
588 card->tst_free_entries = NS_TST_NUM_ENTRIES;
589 data = NS_TST_OPCODE_VARIABLE;
590 for (j = 0; j < NS_TST_NUM_ENTRIES; j++)
591 ns_write_sram(card, NS_TST0 + j, &data, 1);
592 data = ns_tste_make(NS_TST_OPCODE_END, NS_TST0);
593 ns_write_sram(card, NS_TST0 + NS_TST_NUM_ENTRIES, &data, 1);
594 for (j = 0; j < NS_TST_NUM_ENTRIES; j++)
595 ns_write_sram(card, NS_TST1 + j, &data, 1);
596 data = ns_tste_make(NS_TST_OPCODE_END, NS_TST1);
597 ns_write_sram(card, NS_TST1 + NS_TST_NUM_ENTRIES, &data, 1);
598 for (j = 0; j < NS_TST_NUM_ENTRIES; j++)
599 card->tste2vc[j] = NULL;
600 writel(NS_TST0 << 2, card->membase + TSTB);
601
602 /* Initialize RCT. AAL type is set on opening the VC. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603#ifdef RCQ_SUPPORT
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000604 u32d[0] = NS_RCTE_RAWCELLINTEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605#else
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000606 u32d[0] = 0x00000000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607#endif /* RCQ_SUPPORT */
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000608 u32d[1] = 0x00000000;
609 u32d[2] = 0x00000000;
610 u32d[3] = 0xFFFFFFFF;
611 for (j = 0; j < card->rct_size; j++)
612 ns_write_sram(card, j * 4, u32d, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
Markus Elfringee41f072016-09-10 08:30:09 +0200614 memset(card->vcmap, 0, sizeof(card->vcmap));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000616 for (j = 0; j < NS_FRSCD_NUM; j++)
617 card->scd2vc[j] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000619 /* Initialize buffer levels */
620 card->sbnr.min = MIN_SB;
621 card->sbnr.init = NUM_SB;
622 card->sbnr.max = MAX_SB;
623 card->lbnr.min = MIN_LB;
624 card->lbnr.init = NUM_LB;
625 card->lbnr.max = MAX_LB;
626 card->iovnr.min = MIN_IOVB;
627 card->iovnr.init = NUM_IOVB;
628 card->iovnr.max = MAX_IOVB;
629 card->hbnr.min = MIN_HB;
630 card->hbnr.init = NUM_HB;
631 card->hbnr.max = MAX_HB;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
Daeseok Younc664d632014-02-19 10:10:11 +0900633 card->sm_handle = NULL;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000634 card->sm_addr = 0x00000000;
Daeseok Younc664d632014-02-19 10:10:11 +0900635 card->lg_handle = NULL;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000636 card->lg_addr = 0x00000000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000638 card->efbie = 1; /* To prevent push_rxbufs from enabling the interrupt */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000640 idr_init(&card->idr);
641
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000642 /* Pre-allocate some huge buffers */
643 skb_queue_head_init(&card->hbpool.queue);
644 card->hbpool.count = 0;
645 for (j = 0; j < NUM_HB; j++) {
646 struct sk_buff *hb;
647 hb = __dev_alloc_skb(NS_HBUFSIZE, GFP_KERNEL);
648 if (hb == NULL) {
649 printk
650 ("nicstar%d: can't allocate %dth of %d huge buffers.\n",
651 i, j, NUM_HB);
652 error = 13;
653 ns_init_card_error(card, error);
654 return error;
655 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000656 NS_PRV_BUFTYPE(hb) = BUF_NONE;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000657 skb_queue_tail(&card->hbpool.queue, hb);
658 card->hbpool.count++;
659 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000661 /* Allocate large buffers */
662 skb_queue_head_init(&card->lbpool.queue);
663 card->lbpool.count = 0; /* Not used */
664 for (j = 0; j < NUM_LB; j++) {
665 struct sk_buff *lb;
666 lb = __dev_alloc_skb(NS_LGSKBSIZE, GFP_KERNEL);
667 if (lb == NULL) {
668 printk
669 ("nicstar%d: can't allocate %dth of %d large buffers.\n",
670 i, j, NUM_LB);
671 error = 14;
672 ns_init_card_error(card, error);
673 return error;
674 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000675 NS_PRV_BUFTYPE(lb) = BUF_LG;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000676 skb_queue_tail(&card->lbpool.queue, lb);
677 skb_reserve(lb, NS_SMBUFSIZE);
678 push_rxbufs(card, lb);
679 /* Due to the implementation of push_rxbufs() this is 1, not 0 */
680 if (j == 1) {
681 card->rcbuf = lb;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000682 card->rawcell = (struct ns_rcqe *) lb->data;
683 card->rawch = NS_PRV_DMA(lb);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000684 }
685 }
686 /* Test for strange behaviour which leads to crashes */
687 if ((bcount =
688 ns_stat_lfbqc_get(readl(card->membase + STAT))) < card->lbnr.min) {
689 printk
690 ("nicstar%d: Strange... Just allocated %d large buffers and lfbqc = %d.\n",
691 i, j, bcount);
692 error = 14;
693 ns_init_card_error(card, error);
694 return error;
695 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000697 /* Allocate small buffers */
698 skb_queue_head_init(&card->sbpool.queue);
699 card->sbpool.count = 0; /* Not used */
700 for (j = 0; j < NUM_SB; j++) {
701 struct sk_buff *sb;
702 sb = __dev_alloc_skb(NS_SMSKBSIZE, GFP_KERNEL);
703 if (sb == NULL) {
704 printk
705 ("nicstar%d: can't allocate %dth of %d small buffers.\n",
706 i, j, NUM_SB);
707 error = 15;
708 ns_init_card_error(card, error);
709 return error;
710 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000711 NS_PRV_BUFTYPE(sb) = BUF_SM;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000712 skb_queue_tail(&card->sbpool.queue, sb);
713 skb_reserve(sb, NS_AAL0_HEADER);
714 push_rxbufs(card, sb);
715 }
716 /* Test for strange behaviour which leads to crashes */
717 if ((bcount =
718 ns_stat_sfbqc_get(readl(card->membase + STAT))) < card->sbnr.min) {
719 printk
720 ("nicstar%d: Strange... Just allocated %d small buffers and sfbqc = %d.\n",
721 i, j, bcount);
722 error = 15;
723 ns_init_card_error(card, error);
724 return error;
725 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000727 /* Allocate iovec buffers */
728 skb_queue_head_init(&card->iovpool.queue);
729 card->iovpool.count = 0;
730 for (j = 0; j < NUM_IOVB; j++) {
731 struct sk_buff *iovb;
732 iovb = alloc_skb(NS_IOVBUFSIZE, GFP_KERNEL);
733 if (iovb == NULL) {
734 printk
735 ("nicstar%d: can't allocate %dth of %d iovec buffers.\n",
736 i, j, NUM_IOVB);
737 error = 16;
738 ns_init_card_error(card, error);
739 return error;
740 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000741 NS_PRV_BUFTYPE(iovb) = BUF_NONE;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000742 skb_queue_tail(&card->iovpool.queue, iovb);
743 card->iovpool.count++;
744 }
Chas Williams52961952008-01-07 00:26:22 -0800745
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000746 /* Configure NICStAR */
747 if (card->rct_size == 4096)
748 ns_cfg_rctsize = NS_CFG_RCTSIZE_4096_ENTRIES;
749 else /* (card->rct_size == 16384) */
750 ns_cfg_rctsize = NS_CFG_RCTSIZE_16384_ENTRIES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000752 card->efbie = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000754 card->intcnt = 0;
755 if (request_irq
chas williams - CONTRACTOR06df2772010-07-10 03:42:02 +0000756 (pcidev->irq, &ns_irq_handler, IRQF_SHARED, "nicstar", card) != 0) {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000757 printk("nicstar%d: can't allocate IRQ %d.\n", i, pcidev->irq);
758 error = 9;
759 ns_init_card_error(card, error);
760 return error;
761 }
762
763 /* Register device */
Dan Williamsd9ca6762010-12-08 19:40:47 +0000764 card->atmdev = atm_dev_register("nicstar", &card->pcidev->dev, &atm_ops,
765 -1, NULL);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000766 if (card->atmdev == NULL) {
767 printk("nicstar%d: can't register device.\n", i);
768 error = 17;
769 ns_init_card_error(card, error);
770 return error;
771 }
772
Andy Shevchenkod2bb39052013-09-13 18:00:58 +0300773 if (mac[i] == NULL || !mac_pton(mac[i], card->atmdev->esi)) {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000774 nicstar_read_eprom(card->membase, NICSTAR_EPROM_MAC_ADDR_OFFSET,
775 card->atmdev->esi, 6);
dingtianhong4c55a462013-12-26 19:41:02 +0800776 if (ether_addr_equal(card->atmdev->esi, "\x00\x00\x00\x00\x00\x00")) {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000777 nicstar_read_eprom(card->membase,
778 NICSTAR_EPROM_MAC_ADDR_OFFSET_ALT,
779 card->atmdev->esi, 6);
780 }
781 }
782
783 printk("nicstar%d: MAC address %pM\n", i, card->atmdev->esi);
784
785 card->atmdev->dev_data = card;
786 card->atmdev->ci_range.vpi_bits = card->vpibits;
787 card->atmdev->ci_range.vci_bits = card->vcibits;
788 card->atmdev->link_rate = card->max_pcr;
789 card->atmdev->phy = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
791#ifdef CONFIG_ATM_NICSTAR_USE_SUNI
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000792 if (card->max_pcr == ATM_OC3_PCR)
793 suni_init(card->atmdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794#endif /* CONFIG_ATM_NICSTAR_USE_SUNI */
795
796#ifdef CONFIG_ATM_NICSTAR_USE_IDT77105
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000797 if (card->max_pcr == ATM_25_PCR)
798 idt77105_init(card->atmdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799#endif /* CONFIG_ATM_NICSTAR_USE_IDT77105 */
800
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000801 if (card->atmdev->phy && card->atmdev->phy->start)
802 card->atmdev->phy->start(card->atmdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000804 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 */
805 NS_CFG_RSQAFIE | NS_CFG_TXEN | NS_CFG_TXIE | NS_CFG_TSQFIE_OPT | /* Only enabled if ENABLE_TSQFIE */
806 NS_CFG_PHYIE, card->membase + CFG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000808 num_cards++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000810 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811}
812
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -0800813static void ns_init_card_error(ns_dev *card, int error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000815 if (error >= 17) {
816 writel(0x00000000, card->membase + CFG);
817 }
818 if (error >= 16) {
819 struct sk_buff *iovb;
820 while ((iovb = skb_dequeue(&card->iovpool.queue)) != NULL)
821 dev_kfree_skb_any(iovb);
822 }
823 if (error >= 15) {
824 struct sk_buff *sb;
825 while ((sb = skb_dequeue(&card->sbpool.queue)) != NULL)
826 dev_kfree_skb_any(sb);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000827 free_scq(card, card->scq0, NULL);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000828 }
829 if (error >= 14) {
830 struct sk_buff *lb;
831 while ((lb = skb_dequeue(&card->lbpool.queue)) != NULL)
832 dev_kfree_skb_any(lb);
833 }
834 if (error >= 13) {
835 struct sk_buff *hb;
836 while ((hb = skb_dequeue(&card->hbpool.queue)) != NULL)
837 dev_kfree_skb_any(hb);
838 }
839 if (error >= 12) {
840 kfree(card->rsq.org);
841 }
842 if (error >= 11) {
843 kfree(card->tsq.org);
844 }
845 if (error >= 10) {
846 free_irq(card->pcidev->irq, card);
847 }
848 if (error >= 4) {
849 iounmap(card->membase);
850 }
851 if (error >= 3) {
852 pci_disable_device(card->pcidev);
853 kfree(card);
854 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855}
856
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000857static scq_info *get_scq(ns_dev *card, int size, u32 scd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000859 scq_info *scq;
860 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000862 if (size != VBR_SCQSIZE && size != CBR_SCQSIZE)
863 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
Markus Elfring24310fd2016-09-10 08:18:10 +0200865 scq = kmalloc(sizeof(*scq), GFP_KERNEL);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000866 if (!scq)
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000867 return NULL;
chas williams - CONTRACTORede58ef2015-01-16 08:57:21 -0500868 scq->org = dma_alloc_coherent(&card->pcidev->dev,
869 2 * size, &scq->dma, GFP_KERNEL);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000870 if (!scq->org) {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000871 kfree(scq);
872 return NULL;
873 }
Markus Elfring78706122016-09-10 08:02:06 +0200874 scq->skb = kmalloc_array(size / NS_SCQE_SIZE,
875 sizeof(*scq->skb),
876 GFP_KERNEL);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000877 if (!scq->skb) {
Christophe Jailleteab81462016-07-17 09:03:24 +0200878 dma_free_coherent(&card->pcidev->dev,
879 2 * size, scq->org, scq->dma);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000880 kfree(scq);
881 return NULL;
882 }
883 scq->num_entries = size / NS_SCQE_SIZE;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000884 scq->base = PTR_ALIGN(scq->org, size);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000885 scq->next = scq->base;
886 scq->last = scq->base + (scq->num_entries - 1);
887 scq->tail = scq->last;
888 scq->scd = scd;
889 scq->num_entries = size / NS_SCQE_SIZE;
890 scq->tbd_count = 0;
891 init_waitqueue_head(&scq->scqfull_waitq);
892 scq->full = 0;
893 spin_lock_init(&scq->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000895 for (i = 0; i < scq->num_entries; i++)
896 scq->skb[i] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000898 return scq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899}
900
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901/* For variable rate SCQ vcc must be NULL */
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000902static void free_scq(ns_dev *card, scq_info *scq, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000904 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000906 if (scq->num_entries == VBR_SCQ_NUM_ENTRIES)
907 for (i = 0; i < scq->num_entries; i++) {
908 if (scq->skb[i] != NULL) {
909 vcc = ATM_SKB(scq->skb[i])->vcc;
910 if (vcc->pop != NULL)
911 vcc->pop(vcc, scq->skb[i]);
912 else
913 dev_kfree_skb_any(scq->skb[i]);
914 }
915 } else { /* vcc must be != NULL */
916
917 if (vcc == NULL) {
918 printk
919 ("nicstar: free_scq() called with vcc == NULL for fixed rate scq.");
920 for (i = 0; i < scq->num_entries; i++)
921 dev_kfree_skb_any(scq->skb[i]);
922 } else
923 for (i = 0; i < scq->num_entries; i++) {
924 if (scq->skb[i] != NULL) {
925 if (vcc->pop != NULL)
926 vcc->pop(vcc, scq->skb[i]);
927 else
928 dev_kfree_skb_any(scq->skb[i]);
929 }
930 }
931 }
932 kfree(scq->skb);
chas williams - CONTRACTORede58ef2015-01-16 08:57:21 -0500933 dma_free_coherent(&card->pcidev->dev,
934 2 * (scq->num_entries == VBR_SCQ_NUM_ENTRIES ?
935 VBR_SCQSIZE : CBR_SCQSIZE),
936 scq->org, scq->dma);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000937 kfree(scq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938}
939
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940/* The handles passed must be pointers to the sk_buff containing the small
941 or large buffer(s) cast to u32. */
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000942static void push_rxbufs(ns_dev * card, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943{
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000944 struct sk_buff *handle1, *handle2;
Tejun Heob051f6e2013-02-27 17:04:00 -0800945 int id1, id2;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000946 u32 addr1, addr2;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000947 u32 stat;
948 unsigned long flags;
949
950 /* *BARF* */
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000951 handle2 = NULL;
952 addr2 = 0;
953 handle1 = skb;
chas williams - CONTRACTORede58ef2015-01-16 08:57:21 -0500954 addr1 = dma_map_single(&card->pcidev->dev,
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000955 skb->data,
956 (NS_PRV_BUFTYPE(skb) == BUF_SM
957 ? NS_SMSKBSIZE : NS_LGSKBSIZE),
chas williams - CONTRACTORede58ef2015-01-16 08:57:21 -0500958 DMA_TO_DEVICE);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000959 NS_PRV_DMA(skb) = addr1; /* save so we can unmap later */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960
961#ifdef GENERAL_DEBUG
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000962 if (!addr1)
963 printk("nicstar%d: push_rxbufs called with addr1 = 0.\n",
964 card->index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965#endif /* GENERAL_DEBUG */
966
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000967 stat = readl(card->membase + STAT);
968 card->sbfqc = ns_stat_sfbqc_get(stat);
969 card->lbfqc = ns_stat_lfbqc_get(stat);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +0000970 if (NS_PRV_BUFTYPE(skb) == BUF_SM) {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000971 if (!addr2) {
972 if (card->sm_addr) {
973 addr2 = card->sm_addr;
974 handle2 = card->sm_handle;
975 card->sm_addr = 0x00000000;
Daeseok Younc664d632014-02-19 10:10:11 +0900976 card->sm_handle = NULL;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000977 } else { /* (!sm_addr) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000979 card->sm_addr = addr1;
980 card->sm_handle = handle1;
981 }
982 }
983 } else { /* buf_type == BUF_LG */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000985 if (!addr2) {
986 if (card->lg_addr) {
987 addr2 = card->lg_addr;
988 handle2 = card->lg_handle;
989 card->lg_addr = 0x00000000;
Daeseok Younc664d632014-02-19 10:10:11 +0900990 card->lg_handle = NULL;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000991 } else { /* (!lg_addr) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000993 card->lg_addr = addr1;
994 card->lg_handle = handle1;
995 }
996 }
997 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +0000999 if (addr2) {
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001000 if (NS_PRV_BUFTYPE(skb) == BUF_SM) {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001001 if (card->sbfqc >= card->sbnr.max) {
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001002 skb_unlink(handle1, &card->sbpool.queue);
1003 dev_kfree_skb_any(handle1);
1004 skb_unlink(handle2, &card->sbpool.queue);
1005 dev_kfree_skb_any(handle2);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001006 return;
1007 } else
1008 card->sbfqc += 2;
1009 } else { /* (buf_type == BUF_LG) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001011 if (card->lbfqc >= card->lbnr.max) {
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001012 skb_unlink(handle1, &card->lbpool.queue);
1013 dev_kfree_skb_any(handle1);
1014 skb_unlink(handle2, &card->lbpool.queue);
1015 dev_kfree_skb_any(handle2);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001016 return;
1017 } else
1018 card->lbfqc += 2;
1019 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020
Tejun Heob051f6e2013-02-27 17:04:00 -08001021 id1 = idr_alloc(&card->idr, handle1, 0, 0, GFP_ATOMIC);
1022 if (id1 < 0)
1023 goto out;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001024
Tejun Heob051f6e2013-02-27 17:04:00 -08001025 id2 = idr_alloc(&card->idr, handle2, 0, 0, GFP_ATOMIC);
1026 if (id2 < 0)
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001027 goto out;
1028
1029 spin_lock_irqsave(&card->res_lock, flags);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001030 while (CMD_BUSY(card)) ;
1031 writel(addr2, card->membase + DR3);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001032 writel(id2, card->membase + DR2);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001033 writel(addr1, card->membase + DR1);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001034 writel(id1, card->membase + DR0);
1035 writel(NS_CMD_WRITE_FREEBUFQ | NS_PRV_BUFTYPE(skb),
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001036 card->membase + CMD);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001037 spin_unlock_irqrestore(&card->res_lock, flags);
1038
1039 XPRINTK("nicstar%d: Pushing %s buffers at 0x%x and 0x%x.\n",
1040 card->index,
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001041 (NS_PRV_BUFTYPE(skb) == BUF_SM ? "small" : "large"),
1042 addr1, addr2);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001043 }
1044
1045 if (!card->efbie && card->sbfqc >= card->sbnr.min &&
1046 card->lbfqc >= card->lbnr.min) {
1047 card->efbie = 1;
1048 writel((readl(card->membase + CFG) | NS_CFG_EFBIE),
1049 card->membase + CFG);
1050 }
1051
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001052out:
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001053 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054}
1055
David Howells7d12e782006-10-05 14:55:46 +01001056static irqreturn_t ns_irq_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001058 u32 stat_r;
1059 ns_dev *card;
1060 struct atm_dev *dev;
1061 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001063 card = (ns_dev *) dev_id;
1064 dev = card->atmdev;
1065 card->intcnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001067 PRINTK("nicstar%d: NICStAR generated an interrupt\n", card->index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001069 spin_lock_irqsave(&card->int_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001071 stat_r = readl(card->membase + STAT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001073 /* Transmit Status Indicator has been written to T. S. Queue */
1074 if (stat_r & NS_STAT_TSIF) {
1075 TXPRINTK("nicstar%d: TSI interrupt\n", card->index);
1076 process_tsq(card);
1077 writel(NS_STAT_TSIF, card->membase + STAT);
1078 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001080 /* Incomplete CS-PDU has been transmitted */
1081 if (stat_r & NS_STAT_TXICP) {
1082 writel(NS_STAT_TXICP, card->membase + STAT);
1083 TXPRINTK("nicstar%d: Incomplete CS-PDU transmitted.\n",
1084 card->index);
1085 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001087 /* Transmit Status Queue 7/8 full */
1088 if (stat_r & NS_STAT_TSQF) {
1089 writel(NS_STAT_TSQF, card->membase + STAT);
1090 PRINTK("nicstar%d: TSQ full.\n", card->index);
1091 process_tsq(card);
1092 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001094 /* Timer overflow */
1095 if (stat_r & NS_STAT_TMROF) {
1096 writel(NS_STAT_TMROF, card->membase + STAT);
1097 PRINTK("nicstar%d: Timer overflow.\n", card->index);
1098 }
1099
1100 /* PHY device interrupt signal active */
1101 if (stat_r & NS_STAT_PHYI) {
1102 writel(NS_STAT_PHYI, card->membase + STAT);
1103 PRINTK("nicstar%d: PHY interrupt.\n", card->index);
1104 if (dev->phy && dev->phy->interrupt) {
1105 dev->phy->interrupt(dev);
1106 }
1107 }
1108
1109 /* Small Buffer Queue is full */
1110 if (stat_r & NS_STAT_SFBQF) {
1111 writel(NS_STAT_SFBQF, card->membase + STAT);
1112 printk("nicstar%d: Small free buffer queue is full.\n",
1113 card->index);
1114 }
1115
1116 /* Large Buffer Queue is full */
1117 if (stat_r & NS_STAT_LFBQF) {
1118 writel(NS_STAT_LFBQF, card->membase + STAT);
1119 printk("nicstar%d: Large free buffer queue is full.\n",
1120 card->index);
1121 }
1122
1123 /* Receive Status Queue is full */
1124 if (stat_r & NS_STAT_RSQF) {
1125 writel(NS_STAT_RSQF, card->membase + STAT);
1126 printk("nicstar%d: RSQ full.\n", card->index);
1127 process_rsq(card);
1128 }
1129
1130 /* Complete CS-PDU received */
1131 if (stat_r & NS_STAT_EOPDU) {
1132 RXPRINTK("nicstar%d: End of CS-PDU received.\n", card->index);
1133 process_rsq(card);
1134 writel(NS_STAT_EOPDU, card->membase + STAT);
1135 }
1136
1137 /* Raw cell received */
1138 if (stat_r & NS_STAT_RAWCF) {
1139 writel(NS_STAT_RAWCF, card->membase + STAT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140#ifndef RCQ_SUPPORT
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001141 printk("nicstar%d: Raw cell received and no support yet...\n",
1142 card->index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143#endif /* RCQ_SUPPORT */
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001144 /* NOTE: the following procedure may keep a raw cell pending until the
1145 next interrupt. As this preliminary support is only meant to
1146 avoid buffer leakage, this is not an issue. */
1147 while (readl(card->membase + RAWCT) != card->rawch) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001149 if (ns_rcqe_islast(card->rawcell)) {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001150 struct sk_buff *oldbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001152 oldbuf = card->rcbuf;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001153 card->rcbuf = idr_find(&card->idr,
1154 ns_rcqe_nextbufhandle(card->rawcell));
1155 card->rawch = NS_PRV_DMA(card->rcbuf);
1156 card->rawcell = (struct ns_rcqe *)
1157 card->rcbuf->data;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001158 recycle_rx_buf(card, oldbuf);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001159 } else {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001160 card->rawch += NS_RCQE_SIZE;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001161 card->rawcell++;
1162 }
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001163 }
1164 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001166 /* Small buffer queue is empty */
1167 if (stat_r & NS_STAT_SFBQE) {
1168 int i;
1169 struct sk_buff *sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001171 writel(NS_STAT_SFBQE, card->membase + STAT);
1172 printk("nicstar%d: Small free buffer queue empty.\n",
1173 card->index);
1174 for (i = 0; i < card->sbnr.min; i++) {
1175 sb = dev_alloc_skb(NS_SMSKBSIZE);
1176 if (sb == NULL) {
1177 writel(readl(card->membase + CFG) &
1178 ~NS_CFG_EFBIE, card->membase + CFG);
1179 card->efbie = 0;
1180 break;
1181 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001182 NS_PRV_BUFTYPE(sb) = BUF_SM;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001183 skb_queue_tail(&card->sbpool.queue, sb);
1184 skb_reserve(sb, NS_AAL0_HEADER);
1185 push_rxbufs(card, sb);
1186 }
1187 card->sbfqc = i;
1188 process_rsq(card);
1189 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001191 /* Large buffer queue empty */
1192 if (stat_r & NS_STAT_LFBQE) {
1193 int i;
1194 struct sk_buff *lb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001196 writel(NS_STAT_LFBQE, card->membase + STAT);
1197 printk("nicstar%d: Large free buffer queue empty.\n",
1198 card->index);
1199 for (i = 0; i < card->lbnr.min; i++) {
1200 lb = dev_alloc_skb(NS_LGSKBSIZE);
1201 if (lb == NULL) {
1202 writel(readl(card->membase + CFG) &
1203 ~NS_CFG_EFBIE, card->membase + CFG);
1204 card->efbie = 0;
1205 break;
1206 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001207 NS_PRV_BUFTYPE(lb) = BUF_LG;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001208 skb_queue_tail(&card->lbpool.queue, lb);
1209 skb_reserve(lb, NS_SMBUFSIZE);
1210 push_rxbufs(card, lb);
1211 }
1212 card->lbfqc = i;
1213 process_rsq(card);
1214 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001216 /* Receive Status Queue is 7/8 full */
1217 if (stat_r & NS_STAT_RSQAF) {
1218 writel(NS_STAT_RSQAF, card->membase + STAT);
1219 RXPRINTK("nicstar%d: RSQ almost full.\n", card->index);
1220 process_rsq(card);
1221 }
1222
1223 spin_unlock_irqrestore(&card->int_lock, flags);
1224 PRINTK("nicstar%d: end of interrupt service\n", card->index);
1225 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226}
1227
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228static int ns_open(struct atm_vcc *vcc)
1229{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001230 ns_dev *card;
1231 vc_map *vc;
1232 unsigned long tmpl, modl;
1233 int tcr, tcra; /* target cell rate, and absolute value */
1234 int n = 0; /* Number of entries in the TST. Initialized to remove
1235 the compiler warning. */
1236 u32 u32d[4];
1237 int frscdi = 0; /* Index of the SCD. Initialized to remove the compiler
1238 warning. How I wish compilers were clever enough to
1239 tell which variables can truly be used
1240 uninitialized... */
1241 int inuse; /* tx or rx vc already in use by another vcc */
1242 short vpi = vcc->vpi;
1243 int vci = vcc->vci;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001245 card = (ns_dev *) vcc->dev->dev_data;
1246 PRINTK("nicstar%d: opening vpi.vci %d.%d \n", card->index, (int)vpi,
1247 vci);
1248 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
1249 PRINTK("nicstar%d: unsupported AAL.\n", card->index);
1250 return -EINVAL;
1251 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001253 vc = &(card->vcmap[vpi << card->vcibits | vci]);
1254 vcc->dev_data = vc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001256 inuse = 0;
1257 if (vcc->qos.txtp.traffic_class != ATM_NONE && vc->tx)
1258 inuse = 1;
1259 if (vcc->qos.rxtp.traffic_class != ATM_NONE && vc->rx)
1260 inuse += 2;
1261 if (inuse) {
1262 printk("nicstar%d: %s vci already in use.\n", card->index,
1263 inuse == 1 ? "tx" : inuse == 2 ? "rx" : "tx and rx");
1264 return -EINVAL;
1265 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001267 set_bit(ATM_VF_ADDR, &vcc->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001269 /* NOTE: You are not allowed to modify an open connection's QOS. To change
1270 that, remove the ATM_VF_PARTIAL flag checking. There may be other changes
1271 needed to do that. */
1272 if (!test_bit(ATM_VF_PARTIAL, &vcc->flags)) {
1273 scq_info *scq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001275 set_bit(ATM_VF_PARTIAL, &vcc->flags);
1276 if (vcc->qos.txtp.traffic_class == ATM_CBR) {
1277 /* Check requested cell rate and availability of SCD */
1278 if (vcc->qos.txtp.max_pcr == 0 && vcc->qos.txtp.pcr == 0
1279 && vcc->qos.txtp.min_pcr == 0) {
1280 PRINTK
1281 ("nicstar%d: trying to open a CBR vc with cell rate = 0 \n",
1282 card->index);
1283 clear_bit(ATM_VF_PARTIAL, &vcc->flags);
1284 clear_bit(ATM_VF_ADDR, &vcc->flags);
1285 return -EINVAL;
1286 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001288 tcr = atm_pcr_goal(&(vcc->qos.txtp));
1289 tcra = tcr >= 0 ? tcr : -tcr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001291 PRINTK("nicstar%d: target cell rate = %d.\n",
1292 card->index, vcc->qos.txtp.max_pcr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001294 tmpl =
1295 (unsigned long)tcra *(unsigned long)
1296 NS_TST_NUM_ENTRIES;
1297 modl = tmpl % card->max_pcr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001299 n = (int)(tmpl / card->max_pcr);
1300 if (tcr > 0) {
1301 if (modl > 0)
1302 n++;
1303 } else if (tcr == 0) {
1304 if ((n =
1305 (card->tst_free_entries -
1306 NS_TST_RESERVED)) <= 0) {
1307 PRINTK
1308 ("nicstar%d: no CBR bandwidth free.\n",
1309 card->index);
1310 clear_bit(ATM_VF_PARTIAL, &vcc->flags);
1311 clear_bit(ATM_VF_ADDR, &vcc->flags);
1312 return -EINVAL;
1313 }
1314 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001316 if (n == 0) {
1317 printk
1318 ("nicstar%d: selected bandwidth < granularity.\n",
1319 card->index);
1320 clear_bit(ATM_VF_PARTIAL, &vcc->flags);
1321 clear_bit(ATM_VF_ADDR, &vcc->flags);
1322 return -EINVAL;
1323 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001325 if (n > (card->tst_free_entries - NS_TST_RESERVED)) {
1326 PRINTK
1327 ("nicstar%d: not enough free CBR bandwidth.\n",
1328 card->index);
1329 clear_bit(ATM_VF_PARTIAL, &vcc->flags);
1330 clear_bit(ATM_VF_ADDR, &vcc->flags);
1331 return -EINVAL;
1332 } else
1333 card->tst_free_entries -= n;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001335 XPRINTK("nicstar%d: writing %d tst entries.\n",
1336 card->index, n);
1337 for (frscdi = 0; frscdi < NS_FRSCD_NUM; frscdi++) {
1338 if (card->scd2vc[frscdi] == NULL) {
1339 card->scd2vc[frscdi] = vc;
1340 break;
1341 }
1342 }
1343 if (frscdi == NS_FRSCD_NUM) {
1344 PRINTK
1345 ("nicstar%d: no SCD available for CBR channel.\n",
1346 card->index);
1347 card->tst_free_entries += n;
1348 clear_bit(ATM_VF_PARTIAL, &vcc->flags);
1349 clear_bit(ATM_VF_ADDR, &vcc->flags);
1350 return -EBUSY;
1351 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001353 vc->cbr_scd = NS_FRSCD + frscdi * NS_FRSCD_SIZE;
1354
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001355 scq = get_scq(card, CBR_SCQSIZE, vc->cbr_scd);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001356 if (scq == NULL) {
1357 PRINTK("nicstar%d: can't get fixed rate SCQ.\n",
1358 card->index);
1359 card->scd2vc[frscdi] = NULL;
1360 card->tst_free_entries += n;
1361 clear_bit(ATM_VF_PARTIAL, &vcc->flags);
1362 clear_bit(ATM_VF_ADDR, &vcc->flags);
1363 return -ENOMEM;
1364 }
1365 vc->scq = scq;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001366 u32d[0] = scq_virt_to_bus(scq, scq->base);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001367 u32d[1] = (u32) 0x00000000;
1368 u32d[2] = (u32) 0xffffffff;
1369 u32d[3] = (u32) 0x00000000;
1370 ns_write_sram(card, vc->cbr_scd, u32d, 4);
1371
1372 fill_tst(card, n, vc);
1373 } else if (vcc->qos.txtp.traffic_class == ATM_UBR) {
1374 vc->cbr_scd = 0x00000000;
1375 vc->scq = card->scq0;
1376 }
1377
1378 if (vcc->qos.txtp.traffic_class != ATM_NONE) {
1379 vc->tx = 1;
1380 vc->tx_vcc = vcc;
1381 vc->tbd_count = 0;
1382 }
1383 if (vcc->qos.rxtp.traffic_class != ATM_NONE) {
1384 u32 status;
1385
1386 vc->rx = 1;
1387 vc->rx_vcc = vcc;
1388 vc->rx_iov = NULL;
1389
1390 /* Open the connection in hardware */
1391 if (vcc->qos.aal == ATM_AAL5)
1392 status = NS_RCTE_AAL5 | NS_RCTE_CONNECTOPEN;
1393 else /* vcc->qos.aal == ATM_AAL0 */
1394 status = NS_RCTE_AAL0 | NS_RCTE_CONNECTOPEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395#ifdef RCQ_SUPPORT
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001396 status |= NS_RCTE_RAWCELLINTEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397#endif /* RCQ_SUPPORT */
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001398 ns_write_sram(card,
1399 NS_RCT +
1400 (vpi << card->vcibits | vci) *
1401 NS_RCT_ENTRY_SIZE, &status, 1);
1402 }
1403
1404 }
1405
1406 set_bit(ATM_VF_READY, &vcc->flags);
1407 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408}
1409
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410static void ns_close(struct atm_vcc *vcc)
1411{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001412 vc_map *vc;
1413 ns_dev *card;
1414 u32 data;
1415 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001417 vc = vcc->dev_data;
1418 card = vcc->dev->dev_data;
1419 PRINTK("nicstar%d: closing vpi.vci %d.%d \n", card->index,
1420 (int)vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001422 clear_bit(ATM_VF_READY, &vcc->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001424 if (vcc->qos.rxtp.traffic_class != ATM_NONE) {
1425 u32 addr;
1426 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001428 addr =
1429 NS_RCT +
1430 (vcc->vpi << card->vcibits | vcc->vci) * NS_RCT_ENTRY_SIZE;
1431 spin_lock_irqsave(&card->res_lock, flags);
1432 while (CMD_BUSY(card)) ;
1433 writel(NS_CMD_CLOSE_CONNECTION | addr << 2,
1434 card->membase + CMD);
1435 spin_unlock_irqrestore(&card->res_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001437 vc->rx = 0;
1438 if (vc->rx_iov != NULL) {
1439 struct sk_buff *iovb;
1440 u32 stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001442 stat = readl(card->membase + STAT);
1443 card->sbfqc = ns_stat_sfbqc_get(stat);
1444 card->lbfqc = ns_stat_lfbqc_get(stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001446 PRINTK
1447 ("nicstar%d: closing a VC with pending rx buffers.\n",
1448 card->index);
1449 iovb = vc->rx_iov;
1450 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001451 NS_PRV_IOVCNT(iovb));
1452 NS_PRV_IOVCNT(iovb) = 0;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001453 spin_lock_irqsave(&card->int_lock, flags);
1454 recycle_iov_buf(card, iovb);
1455 spin_unlock_irqrestore(&card->int_lock, flags);
1456 vc->rx_iov = NULL;
1457 }
1458 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001460 if (vcc->qos.txtp.traffic_class != ATM_NONE) {
1461 vc->tx = 0;
1462 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001464 if (vcc->qos.txtp.traffic_class == ATM_CBR) {
1465 unsigned long flags;
1466 ns_scqe *scqep;
1467 scq_info *scq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001469 scq = vc->scq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001471 for (;;) {
1472 spin_lock_irqsave(&scq->lock, flags);
1473 scqep = scq->next;
1474 if (scqep == scq->base)
1475 scqep = scq->last;
1476 else
1477 scqep--;
1478 if (scqep == scq->tail) {
1479 spin_unlock_irqrestore(&scq->lock, flags);
1480 break;
1481 }
1482 /* If the last entry is not a TSR, place one in the SCQ in order to
1483 be able to completely drain it and then close. */
1484 if (!ns_scqe_is_tsr(scqep) && scq->tail != scq->next) {
1485 ns_scqe tsr;
1486 u32 scdi, scqi;
1487 u32 data;
1488 int index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001490 tsr.word_1 = ns_tsr_mkword_1(NS_TSR_INTENABLE);
1491 scdi = (vc->cbr_scd - NS_FRSCD) / NS_FRSCD_SIZE;
1492 scqi = scq->next - scq->base;
1493 tsr.word_2 = ns_tsr_mkword_2(scdi, scqi);
1494 tsr.word_3 = 0x00000000;
1495 tsr.word_4 = 0x00000000;
1496 *scq->next = tsr;
1497 index = (int)scqi;
1498 scq->skb[index] = NULL;
1499 if (scq->next == scq->last)
1500 scq->next = scq->base;
1501 else
1502 scq->next++;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001503 data = scq_virt_to_bus(scq, scq->next);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001504 ns_write_sram(card, scq->scd, &data, 1);
1505 }
1506 spin_unlock_irqrestore(&scq->lock, flags);
1507 schedule();
1508 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001510 /* Free all TST entries */
1511 data = NS_TST_OPCODE_VARIABLE;
1512 for (i = 0; i < NS_TST_NUM_ENTRIES; i++) {
1513 if (card->tste2vc[i] == vc) {
1514 ns_write_sram(card, card->tst_addr + i, &data,
1515 1);
1516 card->tste2vc[i] = NULL;
1517 card->tst_free_entries++;
1518 }
1519 }
1520
1521 card->scd2vc[(vc->cbr_scd - NS_FRSCD) / NS_FRSCD_SIZE] = NULL;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001522 free_scq(card, vc->scq, vcc);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001523 }
1524
1525 /* remove all references to vcc before deleting it */
1526 if (vcc->qos.txtp.traffic_class != ATM_NONE) {
1527 unsigned long flags;
1528 scq_info *scq = card->scq0;
1529
1530 spin_lock_irqsave(&scq->lock, flags);
1531
1532 for (i = 0; i < scq->num_entries; i++) {
1533 if (scq->skb[i] && ATM_SKB(scq->skb[i])->vcc == vcc) {
1534 ATM_SKB(scq->skb[i])->vcc = NULL;
1535 atm_return(vcc, scq->skb[i]->truesize);
1536 PRINTK
1537 ("nicstar: deleted pending vcc mapping\n");
1538 }
1539 }
1540
1541 spin_unlock_irqrestore(&scq->lock, flags);
1542 }
1543
1544 vcc->dev_data = NULL;
1545 clear_bit(ATM_VF_PARTIAL, &vcc->flags);
1546 clear_bit(ATM_VF_ADDR, &vcc->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547
1548#ifdef RX_DEBUG
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001549 {
1550 u32 stat, cfg;
1551 stat = readl(card->membase + STAT);
1552 cfg = readl(card->membase + CFG);
1553 printk("STAT = 0x%08X CFG = 0x%08X \n", stat, cfg);
1554 printk
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001555 ("TSQ: base = 0x%p next = 0x%p last = 0x%p TSQT = 0x%08X \n",
1556 card->tsq.base, card->tsq.next,
1557 card->tsq.last, readl(card->membase + TSQT));
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001558 printk
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001559 ("RSQ: base = 0x%p next = 0x%p last = 0x%p RSQT = 0x%08X \n",
1560 card->rsq.base, card->rsq.next,
1561 card->rsq.last, readl(card->membase + RSQT));
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001562 printk("Empty free buffer queue interrupt %s \n",
1563 card->efbie ? "enabled" : "disabled");
1564 printk("SBCNT = %d count = %d LBCNT = %d count = %d \n",
1565 ns_stat_sfbqc_get(stat), card->sbpool.count,
1566 ns_stat_lfbqc_get(stat), card->lbpool.count);
1567 printk("hbpool.count = %d iovpool.count = %d \n",
1568 card->hbpool.count, card->iovpool.count);
1569 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570#endif /* RX_DEBUG */
1571}
1572
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001573static void fill_tst(ns_dev * card, int n, vc_map * vc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001575 u32 new_tst;
1576 unsigned long cl;
1577 int e, r;
1578 u32 data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001580 /* It would be very complicated to keep the two TSTs synchronized while
1581 assuring that writes are only made to the inactive TST. So, for now I
1582 will use only one TST. If problems occur, I will change this again */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001584 new_tst = card->tst_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001586 /* Fill procedure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001588 for (e = 0; e < NS_TST_NUM_ENTRIES; e++) {
1589 if (card->tste2vc[e] == NULL)
1590 break;
1591 }
1592 if (e == NS_TST_NUM_ENTRIES) {
1593 printk("nicstar%d: No free TST entries found. \n", card->index);
1594 return;
1595 }
1596
1597 r = n;
1598 cl = NS_TST_NUM_ENTRIES;
1599 data = ns_tste_make(NS_TST_OPCODE_FIXED, vc->cbr_scd);
1600
1601 while (r > 0) {
1602 if (cl >= NS_TST_NUM_ENTRIES && card->tste2vc[e] == NULL) {
1603 card->tste2vc[e] = vc;
1604 ns_write_sram(card, new_tst + e, &data, 1);
1605 cl -= NS_TST_NUM_ENTRIES;
1606 r--;
1607 }
1608
1609 if (++e == NS_TST_NUM_ENTRIES) {
1610 e = 0;
1611 }
1612 cl += n;
1613 }
1614
1615 /* End of fill procedure */
1616
1617 data = ns_tste_make(NS_TST_OPCODE_END, new_tst);
1618 ns_write_sram(card, new_tst + NS_TST_NUM_ENTRIES, &data, 1);
1619 ns_write_sram(card, card->tst_addr + NS_TST_NUM_ENTRIES, &data, 1);
1620 card->tst_addr = new_tst;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621}
1622
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
1624{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001625 ns_dev *card;
1626 vc_map *vc;
1627 scq_info *scq;
1628 unsigned long buflen;
1629 ns_scqe scqe;
1630 u32 flags; /* TBD flags, not CPU flags */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001632 card = vcc->dev->dev_data;
1633 TXPRINTK("nicstar%d: ns_send() called.\n", card->index);
1634 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
1635 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
1636 card->index);
1637 atomic_inc(&vcc->stats->tx_err);
1638 dev_kfree_skb_any(skb);
1639 return -EINVAL;
1640 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001642 if (!vc->tx) {
1643 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
1644 card->index);
1645 atomic_inc(&vcc->stats->tx_err);
1646 dev_kfree_skb_any(skb);
1647 return -EINVAL;
1648 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001650 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
1651 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
1652 card->index);
1653 atomic_inc(&vcc->stats->tx_err);
1654 dev_kfree_skb_any(skb);
1655 return -EINVAL;
1656 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001658 if (skb_shinfo(skb)->nr_frags != 0) {
1659 printk("nicstar%d: No scatter-gather yet.\n", card->index);
1660 atomic_inc(&vcc->stats->tx_err);
1661 dev_kfree_skb_any(skb);
1662 return -EINVAL;
1663 }
1664
1665 ATM_SKB(skb)->vcc = vcc;
1666
chas williams - CONTRACTORede58ef2015-01-16 08:57:21 -05001667 NS_PRV_DMA(skb) = dma_map_single(&card->pcidev->dev, skb->data,
1668 skb->len, DMA_TO_DEVICE);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001669
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001670 if (vcc->qos.aal == ATM_AAL5) {
1671 buflen = (skb->len + 47 + 8) / 48 * 48; /* Multiple of 48 */
1672 flags = NS_TBD_AAL5;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001673 scqe.word_2 = cpu_to_le32(NS_PRV_DMA(skb));
1674 scqe.word_3 = cpu_to_le32(skb->len);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001675 scqe.word_4 =
1676 ns_tbd_mkword_4(0, (u32) vcc->vpi, (u32) vcc->vci, 0,
1677 ATM_SKB(skb)->
1678 atm_options & ATM_ATMOPT_CLP ? 1 : 0);
1679 flags |= NS_TBD_EOPDU;
1680 } else { /* (vcc->qos.aal == ATM_AAL0) */
1681
1682 buflen = ATM_CELL_PAYLOAD; /* i.e., 48 bytes */
1683 flags = NS_TBD_AAL0;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001684 scqe.word_2 = cpu_to_le32(NS_PRV_DMA(skb) + NS_AAL0_HEADER);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001685 scqe.word_3 = cpu_to_le32(0x00000000);
1686 if (*skb->data & 0x02) /* Payload type 1 - end of pdu */
1687 flags |= NS_TBD_EOPDU;
1688 scqe.word_4 =
1689 cpu_to_le32(*((u32 *) skb->data) & ~NS_TBD_VC_MASK);
1690 /* Force the VPI/VCI to be the same as in VCC struct */
1691 scqe.word_4 |=
1692 cpu_to_le32((((u32) vcc->
1693 vpi) << NS_TBD_VPI_SHIFT | ((u32) vcc->
1694 vci) <<
1695 NS_TBD_VCI_SHIFT) & NS_TBD_VC_MASK);
1696 }
1697
1698 if (vcc->qos.txtp.traffic_class == ATM_CBR) {
1699 scqe.word_1 = ns_tbd_mkword_1_novbr(flags, (u32) buflen);
1700 scq = ((vc_map *) vcc->dev_data)->scq;
1701 } else {
1702 scqe.word_1 =
1703 ns_tbd_mkword_1(flags, (u32) 1, (u32) 1, (u32) buflen);
1704 scq = card->scq0;
1705 }
1706
1707 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
1708 atomic_inc(&vcc->stats->tx_err);
Sebastian Andrzej Siewior6dceaa92020-11-16 17:21:14 +01001709 dma_unmap_single(&card->pcidev->dev, NS_PRV_DMA(skb), skb->len,
1710 DMA_TO_DEVICE);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001711 dev_kfree_skb_any(skb);
1712 return -EIO;
1713 }
1714 atomic_inc(&vcc->stats->tx);
1715
1716 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717}
1718
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001719static int push_scqe(ns_dev * card, vc_map * vc, scq_info * scq, ns_scqe * tbd,
1720 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001722 unsigned long flags;
1723 ns_scqe tsr;
1724 u32 scdi, scqi;
1725 int scq_is_vbr;
1726 u32 data;
1727 int index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001729 spin_lock_irqsave(&scq->lock, flags);
1730 while (scq->tail == scq->next) {
1731 if (in_interrupt()) {
1732 spin_unlock_irqrestore(&scq->lock, flags);
1733 printk("nicstar%d: Error pushing TBD.\n", card->index);
1734 return 1;
1735 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001737 scq->full = 1;
Arnd Bergmann118ce7a2014-02-27 19:51:54 +01001738 wait_event_interruptible_lock_irq_timeout(scq->scqfull_waitq,
1739 scq->tail != scq->next,
1740 scq->lock,
1741 SCQFULL_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001743 if (scq->full) {
1744 spin_unlock_irqrestore(&scq->lock, flags);
1745 printk("nicstar%d: Timeout pushing TBD.\n",
1746 card->index);
1747 return 1;
1748 }
1749 }
1750 *scq->next = *tbd;
1751 index = (int)(scq->next - scq->base);
1752 scq->skb[index] = skb;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001753 XPRINTK("nicstar%d: sending skb at 0x%p (pos %d).\n",
1754 card->index, skb, index);
1755 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 +00001756 card->index, le32_to_cpu(tbd->word_1), le32_to_cpu(tbd->word_2),
1757 le32_to_cpu(tbd->word_3), le32_to_cpu(tbd->word_4),
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001758 scq->next);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001759 if (scq->next == scq->last)
1760 scq->next = scq->base;
1761 else
1762 scq->next++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001764 vc->tbd_count++;
1765 if (scq->num_entries == VBR_SCQ_NUM_ENTRIES) {
1766 scq->tbd_count++;
1767 scq_is_vbr = 1;
1768 } else
1769 scq_is_vbr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001771 if (vc->tbd_count >= MAX_TBD_PER_VC
1772 || scq->tbd_count >= MAX_TBD_PER_SCQ) {
1773 int has_run = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001775 while (scq->tail == scq->next) {
1776 if (in_interrupt()) {
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001777 data = scq_virt_to_bus(scq, scq->next);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001778 ns_write_sram(card, scq->scd, &data, 1);
1779 spin_unlock_irqrestore(&scq->lock, flags);
1780 printk("nicstar%d: Error pushing TSR.\n",
1781 card->index);
1782 return 0;
1783 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001785 scq->full = 1;
1786 if (has_run++)
1787 break;
Arnd Bergmann118ce7a2014-02-27 19:51:54 +01001788 wait_event_interruptible_lock_irq_timeout(scq->scqfull_waitq,
1789 scq->tail != scq->next,
1790 scq->lock,
1791 SCQFULL_TIMEOUT);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001792 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001794 if (!scq->full) {
1795 tsr.word_1 = ns_tsr_mkword_1(NS_TSR_INTENABLE);
1796 if (scq_is_vbr)
1797 scdi = NS_TSR_SCDISVBR;
1798 else
1799 scdi = (vc->cbr_scd - NS_FRSCD) / NS_FRSCD_SIZE;
1800 scqi = scq->next - scq->base;
1801 tsr.word_2 = ns_tsr_mkword_2(scdi, scqi);
1802 tsr.word_3 = 0x00000000;
1803 tsr.word_4 = 0x00000000;
1804
1805 *scq->next = tsr;
1806 index = (int)scqi;
1807 scq->skb[index] = NULL;
1808 XPRINTK
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001809 ("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 +00001810 card->index, le32_to_cpu(tsr.word_1),
1811 le32_to_cpu(tsr.word_2), le32_to_cpu(tsr.word_3),
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001812 le32_to_cpu(tsr.word_4), scq->next);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001813 if (scq->next == scq->last)
1814 scq->next = scq->base;
1815 else
1816 scq->next++;
1817 vc->tbd_count = 0;
1818 scq->tbd_count = 0;
1819 } else
1820 PRINTK("nicstar%d: Timeout pushing TSR.\n",
1821 card->index);
1822 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001823 data = scq_virt_to_bus(scq, scq->next);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001824 ns_write_sram(card, scq->scd, &data, 1);
1825
1826 spin_unlock_irqrestore(&scq->lock, flags);
1827
1828 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829}
1830
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001831static void process_tsq(ns_dev * card)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001833 u32 scdi;
1834 scq_info *scq;
1835 ns_tsi *previous = NULL, *one_ahead, *two_ahead;
1836 int serviced_entries; /* flag indicating at least on entry was serviced */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001838 serviced_entries = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001840 if (card->tsq.next == card->tsq.last)
1841 one_ahead = card->tsq.base;
1842 else
1843 one_ahead = card->tsq.next + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001845 if (one_ahead == card->tsq.last)
1846 two_ahead = card->tsq.base;
1847 else
1848 two_ahead = one_ahead + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001850 while (!ns_tsi_isempty(card->tsq.next) || !ns_tsi_isempty(one_ahead) ||
1851 !ns_tsi_isempty(two_ahead))
1852 /* At most two empty, as stated in the 77201 errata */
1853 {
1854 serviced_entries = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001856 /* Skip the one or two possible empty entries */
1857 while (ns_tsi_isempty(card->tsq.next)) {
1858 if (card->tsq.next == card->tsq.last)
1859 card->tsq.next = card->tsq.base;
1860 else
1861 card->tsq.next++;
1862 }
1863
1864 if (!ns_tsi_tmrof(card->tsq.next)) {
1865 scdi = ns_tsi_getscdindex(card->tsq.next);
1866 if (scdi == NS_TSI_SCDISVBR)
1867 scq = card->scq0;
1868 else {
1869 if (card->scd2vc[scdi] == NULL) {
1870 printk
1871 ("nicstar%d: could not find VC from SCD index.\n",
1872 card->index);
1873 ns_tsi_init(card->tsq.next);
1874 return;
1875 }
1876 scq = card->scd2vc[scdi]->scq;
1877 }
1878 drain_scq(card, scq, ns_tsi_getscqpos(card->tsq.next));
1879 scq->full = 0;
1880 wake_up_interruptible(&(scq->scqfull_waitq));
1881 }
1882
1883 ns_tsi_init(card->tsq.next);
1884 previous = card->tsq.next;
1885 if (card->tsq.next == card->tsq.last)
1886 card->tsq.next = card->tsq.base;
1887 else
1888 card->tsq.next++;
1889
1890 if (card->tsq.next == card->tsq.last)
1891 one_ahead = card->tsq.base;
1892 else
1893 one_ahead = card->tsq.next + 1;
1894
1895 if (one_ahead == card->tsq.last)
1896 two_ahead = card->tsq.base;
1897 else
1898 two_ahead = one_ahead + 1;
1899 }
1900
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001901 if (serviced_entries)
1902 writel(PTR_DIFF(previous, card->tsq.base),
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001903 card->membase + TSQH);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904}
1905
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001906static void drain_scq(ns_dev * card, scq_info * scq, int pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001908 struct atm_vcc *vcc;
1909 struct sk_buff *skb;
1910 int i;
1911 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001913 XPRINTK("nicstar%d: drain_scq() called, scq at 0x%p, pos %d.\n",
1914 card->index, scq, pos);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001915 if (pos >= scq->num_entries) {
1916 printk("nicstar%d: Bad index on drain_scq().\n", card->index);
1917 return;
1918 }
1919
1920 spin_lock_irqsave(&scq->lock, flags);
1921 i = (int)(scq->tail - scq->base);
1922 if (++i == scq->num_entries)
1923 i = 0;
1924 while (i != pos) {
1925 skb = scq->skb[i];
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001926 XPRINTK("nicstar%d: freeing skb at 0x%p (index %d).\n",
1927 card->index, skb, i);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001928 if (skb != NULL) {
chas williams - CONTRACTORede58ef2015-01-16 08:57:21 -05001929 dma_unmap_single(&card->pcidev->dev,
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001930 NS_PRV_DMA(skb),
1931 skb->len,
chas williams - CONTRACTORede58ef2015-01-16 08:57:21 -05001932 DMA_TO_DEVICE);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001933 vcc = ATM_SKB(skb)->vcc;
1934 if (vcc && vcc->pop != NULL) {
1935 vcc->pop(vcc, skb);
1936 } else {
1937 dev_kfree_skb_irq(skb);
1938 }
1939 scq->skb[i] = NULL;
1940 }
1941 if (++i == scq->num_entries)
1942 i = 0;
1943 }
1944 scq->tail = scq->base + pos;
1945 spin_unlock_irqrestore(&scq->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946}
1947
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001948static void process_rsq(ns_dev * card)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001950 ns_rsqe *previous;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001952 if (!ns_rsqe_valid(card->rsq.next))
1953 return;
1954 do {
1955 dequeue_rx(card, card->rsq.next);
1956 ns_rsqe_init(card->rsq.next);
1957 previous = card->rsq.next;
1958 if (card->rsq.next == card->rsq.last)
1959 card->rsq.next = card->rsq.base;
1960 else
1961 card->rsq.next++;
1962 } while (ns_rsqe_valid(card->rsq.next));
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001963 writel(PTR_DIFF(previous, card->rsq.base), card->membase + RSQH);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964}
1965
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001966static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001968 u32 vpi, vci;
1969 vc_map *vc;
1970 struct sk_buff *iovb;
1971 struct iovec *iov;
1972 struct atm_vcc *vcc;
1973 struct sk_buff *skb;
1974 unsigned short aal5_len;
1975 int len;
1976 u32 stat;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001977 u32 id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00001979 stat = readl(card->membase + STAT);
1980 card->sbfqc = ns_stat_sfbqc_get(stat);
1981 card->lbfqc = ns_stat_lfbqc_get(stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001983 id = le32_to_cpu(rsqe->buffer_handle);
Matthew Wilcoxd3e709e2016-12-22 13:30:22 -05001984 skb = idr_remove(&card->idr, id);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001985 if (!skb) {
1986 RXPRINTK(KERN_ERR
Matthew Wilcoxd3e709e2016-12-22 13:30:22 -05001987 "nicstar%d: skb not found!\n", card->index);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001988 return;
1989 }
chas williams - CONTRACTORede58ef2015-01-16 08:57:21 -05001990 dma_sync_single_for_cpu(&card->pcidev->dev,
1991 NS_PRV_DMA(skb),
1992 (NS_PRV_BUFTYPE(skb) == BUF_SM
1993 ? NS_SMSKBSIZE : NS_LGSKBSIZE),
1994 DMA_FROM_DEVICE);
1995 dma_unmap_single(&card->pcidev->dev,
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00001996 NS_PRV_DMA(skb),
1997 (NS_PRV_BUFTYPE(skb) == BUF_SM
1998 ? NS_SMSKBSIZE : NS_LGSKBSIZE),
chas williams - CONTRACTORede58ef2015-01-16 08:57:21 -05001999 DMA_FROM_DEVICE);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002000 vpi = ns_rsqe_vpi(rsqe);
2001 vci = ns_rsqe_vci(rsqe);
2002 if (vpi >= 1UL << card->vpibits || vci >= 1UL << card->vcibits) {
2003 printk("nicstar%d: SDU received for out-of-range vc %d.%d.\n",
2004 card->index, vpi, vci);
2005 recycle_rx_buf(card, skb);
2006 return;
2007 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002009 vc = &(card->vcmap[vpi << card->vcibits | vci]);
2010 if (!vc->rx) {
2011 RXPRINTK("nicstar%d: SDU received on non-rx vc %d.%d.\n",
2012 card->index, vpi, vci);
2013 recycle_rx_buf(card, skb);
2014 return;
2015 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002017 vcc = vc->rx_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002019 if (vcc->qos.aal == ATM_AAL0) {
2020 struct sk_buff *sb;
2021 unsigned char *cell;
2022 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002024 cell = skb->data;
2025 for (i = ns_rsqe_cellcount(rsqe); i; i--) {
Markus Elfring0ba8abb2016-09-10 08:56:03 +02002026 sb = dev_alloc_skb(NS_SMSKBSIZE);
2027 if (!sb) {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002028 printk
2029 ("nicstar%d: Can't allocate buffers for aal0.\n",
2030 card->index);
2031 atomic_add(i, &vcc->stats->rx_drop);
2032 break;
2033 }
2034 if (!atm_charge(vcc, sb->truesize)) {
2035 RXPRINTK
2036 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
2037 card->index);
2038 atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
2039 dev_kfree_skb_any(sb);
2040 break;
2041 }
2042 /* Rebuild the header */
2043 *((u32 *) sb->data) = le32_to_cpu(rsqe->word_1) << 4 |
2044 (ns_rsqe_clp(rsqe) ? 0x00000001 : 0x00000000);
2045 if (i == 1 && ns_rsqe_eopdu(rsqe))
2046 *((u32 *) sb->data) |= 0x00000002;
2047 skb_put(sb, NS_AAL0_HEADER);
2048 memcpy(skb_tail_pointer(sb), cell, ATM_CELL_PAYLOAD);
2049 skb_put(sb, ATM_CELL_PAYLOAD);
2050 ATM_SKB(sb)->vcc = vcc;
2051 __net_timestamp(sb);
2052 vcc->push(vcc, sb);
2053 atomic_inc(&vcc->stats->rx);
2054 cell += ATM_CELL_PAYLOAD;
2055 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002057 recycle_rx_buf(card, skb);
2058 return;
2059 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002061 /* To reach this point, the AAL layer can only be AAL5 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002063 if ((iovb = vc->rx_iov) == NULL) {
2064 iovb = skb_dequeue(&(card->iovpool.queue));
2065 if (iovb == NULL) { /* No buffers in the queue */
2066 iovb = alloc_skb(NS_IOVBUFSIZE, GFP_ATOMIC);
2067 if (iovb == NULL) {
2068 printk("nicstar%d: Out of iovec buffers.\n",
2069 card->index);
2070 atomic_inc(&vcc->stats->rx_drop);
2071 recycle_rx_buf(card, skb);
2072 return;
2073 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002074 NS_PRV_BUFTYPE(iovb) = BUF_NONE;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002075 } else if (--card->iovpool.count < card->iovnr.min) {
2076 struct sk_buff *new_iovb;
2077 if ((new_iovb =
2078 alloc_skb(NS_IOVBUFSIZE, GFP_ATOMIC)) != NULL) {
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002079 NS_PRV_BUFTYPE(iovb) = BUF_NONE;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002080 skb_queue_tail(&card->iovpool.queue, new_iovb);
2081 card->iovpool.count++;
2082 }
2083 }
2084 vc->rx_iov = iovb;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002085 NS_PRV_IOVCNT(iovb) = 0;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002086 iovb->len = 0;
2087 iovb->data = iovb->head;
2088 skb_reset_tail_pointer(iovb);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002089 /* IMPORTANT: a pointer to the sk_buff containing the small or large
2090 buffer is stored as iovec base, NOT a pointer to the
2091 small or large buffer itself. */
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002092 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002093 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
2094 atomic_inc(&vcc->stats->rx_err);
2095 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
2096 NS_MAX_IOVECS);
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002097 NS_PRV_IOVCNT(iovb) = 0;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002098 iovb->len = 0;
2099 iovb->data = iovb->head;
2100 skb_reset_tail_pointer(iovb);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002101 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002102 iov = &((struct iovec *)iovb->data)[NS_PRV_IOVCNT(iovb)++];
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002103 iov->iov_base = (void *)skb;
2104 iov->iov_len = ns_rsqe_cellcount(rsqe) * 48;
2105 iovb->len += iov->iov_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002107#ifdef EXTRA_DEBUG
2108 if (NS_PRV_IOVCNT(iovb) == 1) {
2109 if (NS_PRV_BUFTYPE(skb) != BUF_SM) {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002110 printk
2111 ("nicstar%d: Expected a small buffer, and this is not one.\n",
2112 card->index);
2113 which_list(card, skb);
2114 atomic_inc(&vcc->stats->rx_err);
2115 recycle_rx_buf(card, skb);
2116 vc->rx_iov = NULL;
2117 recycle_iov_buf(card, iovb);
2118 return;
2119 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002120 } else { /* NS_PRV_IOVCNT(iovb) >= 2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002122 if (NS_PRV_BUFTYPE(skb) != BUF_LG) {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002123 printk
2124 ("nicstar%d: Expected a large buffer, and this is not one.\n",
2125 card->index);
2126 which_list(card, skb);
2127 atomic_inc(&vcc->stats->rx_err);
2128 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002129 NS_PRV_IOVCNT(iovb));
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002130 vc->rx_iov = NULL;
2131 recycle_iov_buf(card, iovb);
2132 return;
2133 }
2134 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002135#endif /* EXTRA_DEBUG */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002137 if (ns_rsqe_eopdu(rsqe)) {
2138 /* This works correctly regardless of the endianness of the host */
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002139 unsigned char *L1L2 = (unsigned char *)
2140 (skb->data + iov->iov_len - 6);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002141 aal5_len = L1L2[0] << 8 | L1L2[1];
2142 len = (aal5_len == 0x0000) ? 0x10000 : aal5_len;
2143 if (ns_rsqe_crcerr(rsqe) ||
2144 len + 8 > iovb->len || len + (47 + 8) < iovb->len) {
2145 printk("nicstar%d: AAL5 CRC error", card->index);
2146 if (len + 8 > iovb->len || len + (47 + 8) < iovb->len)
2147 printk(" - PDU size mismatch.\n");
2148 else
2149 printk(".\n");
2150 atomic_inc(&vcc->stats->rx_err);
2151 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002152 NS_PRV_IOVCNT(iovb));
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002153 vc->rx_iov = NULL;
2154 recycle_iov_buf(card, iovb);
2155 return;
2156 }
2157
2158 /* By this point we (hopefully) have a complete SDU without errors. */
2159
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002160 if (NS_PRV_IOVCNT(iovb) == 1) { /* Just a small buffer */
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002161 /* skb points to a small buffer */
2162 if (!atm_charge(vcc, skb->truesize)) {
2163 push_rxbufs(card, skb);
2164 atomic_inc(&vcc->stats->rx_drop);
2165 } else {
2166 skb_put(skb, len);
2167 dequeue_sm_buf(card, skb);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002168 ATM_SKB(skb)->vcc = vcc;
2169 __net_timestamp(skb);
2170 vcc->push(vcc, skb);
2171 atomic_inc(&vcc->stats->rx);
2172 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002173 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002174 struct sk_buff *sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002176 sb = (struct sk_buff *)(iov - 1)->iov_base;
2177 /* skb points to a large buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002179 if (len <= NS_SMBUFSIZE) {
2180 if (!atm_charge(vcc, sb->truesize)) {
2181 push_rxbufs(card, sb);
2182 atomic_inc(&vcc->stats->rx_drop);
2183 } else {
2184 skb_put(sb, len);
2185 dequeue_sm_buf(card, sb);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002186 ATM_SKB(sb)->vcc = vcc;
2187 __net_timestamp(sb);
2188 vcc->push(vcc, sb);
2189 atomic_inc(&vcc->stats->rx);
2190 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002192 push_rxbufs(card, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002194 } else { /* len > NS_SMBUFSIZE, the usual case */
2195
2196 if (!atm_charge(vcc, skb->truesize)) {
2197 push_rxbufs(card, skb);
2198 atomic_inc(&vcc->stats->rx_drop);
2199 } else {
2200 dequeue_lg_buf(card, skb);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002201 skb_push(skb, NS_SMBUFSIZE);
2202 skb_copy_from_linear_data(sb, skb->data,
2203 NS_SMBUFSIZE);
2204 skb_put(skb, len - NS_SMBUFSIZE);
2205 ATM_SKB(skb)->vcc = vcc;
2206 __net_timestamp(skb);
2207 vcc->push(vcc, skb);
2208 atomic_inc(&vcc->stats->rx);
2209 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002211 push_rxbufs(card, sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002213 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002215 } else { /* Must push a huge buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002217 struct sk_buff *hb, *sb, *lb;
2218 int remaining, tocopy;
2219 int j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002221 hb = skb_dequeue(&(card->hbpool.queue));
2222 if (hb == NULL) { /* No buffers in the queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002224 hb = dev_alloc_skb(NS_HBUFSIZE);
2225 if (hb == NULL) {
2226 printk
2227 ("nicstar%d: Out of huge buffers.\n",
2228 card->index);
2229 atomic_inc(&vcc->stats->rx_drop);
2230 recycle_iovec_rx_bufs(card,
2231 (struct iovec *)
2232 iovb->data,
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002233 NS_PRV_IOVCNT(iovb));
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002234 vc->rx_iov = NULL;
2235 recycle_iov_buf(card, iovb);
2236 return;
2237 } else if (card->hbpool.count < card->hbnr.min) {
2238 struct sk_buff *new_hb;
2239 if ((new_hb =
2240 dev_alloc_skb(NS_HBUFSIZE)) !=
2241 NULL) {
2242 skb_queue_tail(&card->hbpool.
2243 queue, new_hb);
2244 card->hbpool.count++;
2245 }
2246 }
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002247 NS_PRV_BUFTYPE(hb) = BUF_NONE;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002248 } else if (--card->hbpool.count < card->hbnr.min) {
2249 struct sk_buff *new_hb;
2250 if ((new_hb =
2251 dev_alloc_skb(NS_HBUFSIZE)) != NULL) {
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002252 NS_PRV_BUFTYPE(new_hb) = BUF_NONE;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002253 skb_queue_tail(&card->hbpool.queue,
2254 new_hb);
2255 card->hbpool.count++;
2256 }
2257 if (card->hbpool.count < card->hbnr.min) {
2258 if ((new_hb =
2259 dev_alloc_skb(NS_HBUFSIZE)) !=
2260 NULL) {
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002261 NS_PRV_BUFTYPE(new_hb) =
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002262 BUF_NONE;
2263 skb_queue_tail(&card->hbpool.
2264 queue, new_hb);
2265 card->hbpool.count++;
2266 }
2267 }
2268 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002270 iov = (struct iovec *)iovb->data;
2271
2272 if (!atm_charge(vcc, hb->truesize)) {
2273 recycle_iovec_rx_bufs(card, iov,
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002274 NS_PRV_IOVCNT(iovb));
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002275 if (card->hbpool.count < card->hbnr.max) {
2276 skb_queue_tail(&card->hbpool.queue, hb);
2277 card->hbpool.count++;
2278 } else
2279 dev_kfree_skb_any(hb);
2280 atomic_inc(&vcc->stats->rx_drop);
2281 } else {
2282 /* Copy the small buffer to the huge buffer */
2283 sb = (struct sk_buff *)iov->iov_base;
2284 skb_copy_from_linear_data(sb, hb->data,
2285 iov->iov_len);
2286 skb_put(hb, iov->iov_len);
2287 remaining = len - iov->iov_len;
2288 iov++;
2289 /* Free the small buffer */
2290 push_rxbufs(card, sb);
2291
2292 /* Copy all large buffers to the huge buffer and free them */
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002293 for (j = 1; j < NS_PRV_IOVCNT(iovb); j++) {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002294 lb = (struct sk_buff *)iov->iov_base;
2295 tocopy =
2296 min_t(int, remaining, iov->iov_len);
2297 skb_copy_from_linear_data(lb,
2298 skb_tail_pointer
2299 (hb), tocopy);
2300 skb_put(hb, tocopy);
2301 iov++;
2302 remaining -= tocopy;
2303 push_rxbufs(card, lb);
2304 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305#ifdef EXTRA_DEBUG
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002306 if (remaining != 0 || hb->len != len)
2307 printk
2308 ("nicstar%d: Huge buffer len mismatch.\n",
2309 card->index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310#endif /* EXTRA_DEBUG */
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002311 ATM_SKB(hb)->vcc = vcc;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002312 __net_timestamp(hb);
2313 vcc->push(vcc, hb);
2314 atomic_inc(&vcc->stats->rx);
2315 }
2316 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002318 vc->rx_iov = NULL;
2319 recycle_iov_buf(card, iovb);
2320 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321
2322}
2323
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002324static void recycle_rx_buf(ns_dev * card, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325{
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002326 if (unlikely(NS_PRV_BUFTYPE(skb) == BUF_NONE)) {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002327 printk("nicstar%d: What kind of rx buffer is this?\n",
2328 card->index);
David S. Miller8728b832005-08-09 19:25:21 -07002329 dev_kfree_skb_any(skb);
2330 } else
2331 push_rxbufs(card, skb);
2332}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002334static void recycle_iovec_rx_bufs(ns_dev * card, struct iovec *iov, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335{
David S. Miller8728b832005-08-09 19:25:21 -07002336 while (count-- > 0)
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002337 recycle_rx_buf(card, (struct sk_buff *)(iov++)->iov_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338}
2339
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002340static void recycle_iov_buf(ns_dev * card, struct sk_buff *iovb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002342 if (card->iovpool.count < card->iovnr.max) {
2343 skb_queue_tail(&card->iovpool.queue, iovb);
2344 card->iovpool.count++;
2345 } else
2346 dev_kfree_skb_any(iovb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347}
2348
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002349static void dequeue_sm_buf(ns_dev * card, struct sk_buff *sb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002351 skb_unlink(sb, &card->sbpool.queue);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002352 if (card->sbfqc < card->sbnr.init) {
2353 struct sk_buff *new_sb;
2354 if ((new_sb = dev_alloc_skb(NS_SMSKBSIZE)) != NULL) {
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002355 NS_PRV_BUFTYPE(new_sb) = BUF_SM;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002356 skb_queue_tail(&card->sbpool.queue, new_sb);
2357 skb_reserve(new_sb, NS_AAL0_HEADER);
2358 push_rxbufs(card, new_sb);
2359 }
2360 }
2361 if (card->sbfqc < card->sbnr.init)
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002362 {
2363 struct sk_buff *new_sb;
2364 if ((new_sb = dev_alloc_skb(NS_SMSKBSIZE)) != NULL) {
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002365 NS_PRV_BUFTYPE(new_sb) = BUF_SM;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002366 skb_queue_tail(&card->sbpool.queue, new_sb);
2367 skb_reserve(new_sb, NS_AAL0_HEADER);
2368 push_rxbufs(card, new_sb);
2369 }
2370 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371}
2372
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002373static void dequeue_lg_buf(ns_dev * card, struct sk_buff *lb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002375 skb_unlink(lb, &card->lbpool.queue);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002376 if (card->lbfqc < card->lbnr.init) {
2377 struct sk_buff *new_lb;
2378 if ((new_lb = dev_alloc_skb(NS_LGSKBSIZE)) != NULL) {
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002379 NS_PRV_BUFTYPE(new_lb) = BUF_LG;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002380 skb_queue_tail(&card->lbpool.queue, new_lb);
2381 skb_reserve(new_lb, NS_SMBUFSIZE);
2382 push_rxbufs(card, new_lb);
2383 }
2384 }
2385 if (card->lbfqc < card->lbnr.init)
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002386 {
2387 struct sk_buff *new_lb;
2388 if ((new_lb = dev_alloc_skb(NS_LGSKBSIZE)) != NULL) {
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002389 NS_PRV_BUFTYPE(new_lb) = BUF_LG;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002390 skb_queue_tail(&card->lbpool.queue, new_lb);
2391 skb_reserve(new_lb, NS_SMBUFSIZE);
2392 push_rxbufs(card, new_lb);
2393 }
2394 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395}
2396
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002397static int ns_proc_read(struct atm_dev *dev, loff_t * pos, char *page)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002399 u32 stat;
2400 ns_dev *card;
2401 int left;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002403 left = (int)*pos;
2404 card = (ns_dev *) dev->dev_data;
2405 stat = readl(card->membase + STAT);
2406 if (!left--)
2407 return sprintf(page, "Pool count min init max \n");
2408 if (!left--)
2409 return sprintf(page, "Small %5d %5d %5d %5d \n",
2410 ns_stat_sfbqc_get(stat), card->sbnr.min,
2411 card->sbnr.init, card->sbnr.max);
2412 if (!left--)
2413 return sprintf(page, "Large %5d %5d %5d %5d \n",
2414 ns_stat_lfbqc_get(stat), card->lbnr.min,
2415 card->lbnr.init, card->lbnr.max);
2416 if (!left--)
2417 return sprintf(page, "Huge %5d %5d %5d %5d \n",
2418 card->hbpool.count, card->hbnr.min,
2419 card->hbnr.init, card->hbnr.max);
2420 if (!left--)
2421 return sprintf(page, "Iovec %5d %5d %5d %5d \n",
2422 card->iovpool.count, card->iovnr.min,
2423 card->iovnr.init, card->iovnr.max);
2424 if (!left--) {
2425 int retval;
2426 retval =
2427 sprintf(page, "Interrupt counter: %u \n", card->intcnt);
2428 card->intcnt = 0;
2429 return retval;
2430 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431#if 0
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002432 /* Dump 25.6 Mbps PHY registers */
2433 /* Now there's a 25.6 Mbps PHY driver this code isn't needed. I left it
2434 here just in case it's needed for debugging. */
2435 if (card->max_pcr == ATM_25_PCR && !left--) {
2436 u32 phy_regs[4];
2437 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002439 for (i = 0; i < 4; i++) {
2440 while (CMD_BUSY(card)) ;
2441 writel(NS_CMD_READ_UTILITY | 0x00000200 | i,
2442 card->membase + CMD);
2443 while (CMD_BUSY(card)) ;
2444 phy_regs[i] = readl(card->membase + DR0) & 0x000000FF;
2445 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002447 return sprintf(page, "PHY regs: 0x%02X 0x%02X 0x%02X 0x%02X \n",
2448 phy_regs[0], phy_regs[1], phy_regs[2],
2449 phy_regs[3]);
2450 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451#endif /* 0 - Dump 25.6 Mbps PHY registers */
2452#if 0
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002453 /* Dump TST */
2454 if (left-- < NS_TST_NUM_ENTRIES) {
2455 if (card->tste2vc[left + 1] == NULL)
2456 return sprintf(page, "%5d - VBR/UBR \n", left + 1);
2457 else
2458 return sprintf(page, "%5d - %d %d \n", left + 1,
2459 card->tste2vc[left + 1]->tx_vcc->vpi,
2460 card->tste2vc[left + 1]->tx_vcc->vci);
2461 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462#endif /* 0 */
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002463 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464}
2465
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002466static int ns_ioctl(struct atm_dev *dev, unsigned int cmd, void __user * arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002468 ns_dev *card;
2469 pool_levels pl;
2470 long btype;
2471 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002473 card = dev->dev_data;
2474 switch (cmd) {
2475 case NS_GETPSTAT:
2476 if (get_user
2477 (pl.buftype, &((pool_levels __user *) arg)->buftype))
2478 return -EFAULT;
2479 switch (pl.buftype) {
2480 case NS_BUFTYPE_SMALL:
2481 pl.count =
2482 ns_stat_sfbqc_get(readl(card->membase + STAT));
2483 pl.level.min = card->sbnr.min;
2484 pl.level.init = card->sbnr.init;
2485 pl.level.max = card->sbnr.max;
2486 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002488 case NS_BUFTYPE_LARGE:
2489 pl.count =
2490 ns_stat_lfbqc_get(readl(card->membase + STAT));
2491 pl.level.min = card->lbnr.min;
2492 pl.level.init = card->lbnr.init;
2493 pl.level.max = card->lbnr.max;
2494 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002496 case NS_BUFTYPE_HUGE:
2497 pl.count = card->hbpool.count;
2498 pl.level.min = card->hbnr.min;
2499 pl.level.init = card->hbnr.init;
2500 pl.level.max = card->hbnr.max;
2501 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002503 case NS_BUFTYPE_IOVEC:
2504 pl.count = card->iovpool.count;
2505 pl.level.min = card->iovnr.min;
2506 pl.level.init = card->iovnr.init;
2507 pl.level.max = card->iovnr.max;
2508 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002510 default:
2511 return -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002513 }
2514 if (!copy_to_user((pool_levels __user *) arg, &pl, sizeof(pl)))
2515 return (sizeof(pl));
2516 else
2517 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002519 case NS_SETBUFLEV:
2520 if (!capable(CAP_NET_ADMIN))
2521 return -EPERM;
2522 if (copy_from_user(&pl, (pool_levels __user *) arg, sizeof(pl)))
2523 return -EFAULT;
2524 if (pl.level.min >= pl.level.init
2525 || pl.level.init >= pl.level.max)
2526 return -EINVAL;
2527 if (pl.level.min == 0)
2528 return -EINVAL;
2529 switch (pl.buftype) {
2530 case NS_BUFTYPE_SMALL:
2531 if (pl.level.max > TOP_SB)
2532 return -EINVAL;
2533 card->sbnr.min = pl.level.min;
2534 card->sbnr.init = pl.level.init;
2535 card->sbnr.max = pl.level.max;
2536 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002538 case NS_BUFTYPE_LARGE:
2539 if (pl.level.max > TOP_LB)
2540 return -EINVAL;
2541 card->lbnr.min = pl.level.min;
2542 card->lbnr.init = pl.level.init;
2543 card->lbnr.max = pl.level.max;
2544 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002546 case NS_BUFTYPE_HUGE:
2547 if (pl.level.max > TOP_HB)
2548 return -EINVAL;
2549 card->hbnr.min = pl.level.min;
2550 card->hbnr.init = pl.level.init;
2551 card->hbnr.max = pl.level.max;
2552 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002554 case NS_BUFTYPE_IOVEC:
2555 if (pl.level.max > TOP_IOVB)
2556 return -EINVAL;
2557 card->iovnr.min = pl.level.min;
2558 card->iovnr.init = pl.level.init;
2559 card->iovnr.max = pl.level.max;
2560 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002562 default:
2563 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002565 }
2566 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002568 case NS_ADJBUFLEV:
2569 if (!capable(CAP_NET_ADMIN))
2570 return -EPERM;
2571 btype = (long)arg; /* a long is the same size as a pointer or bigger */
2572 switch (btype) {
2573 case NS_BUFTYPE_SMALL:
2574 while (card->sbfqc < card->sbnr.init) {
2575 struct sk_buff *sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002577 sb = __dev_alloc_skb(NS_SMSKBSIZE, GFP_KERNEL);
2578 if (sb == NULL)
2579 return -ENOMEM;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002580 NS_PRV_BUFTYPE(sb) = BUF_SM;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002581 skb_queue_tail(&card->sbpool.queue, sb);
2582 skb_reserve(sb, NS_AAL0_HEADER);
2583 push_rxbufs(card, sb);
2584 }
2585 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002587 case NS_BUFTYPE_LARGE:
2588 while (card->lbfqc < card->lbnr.init) {
2589 struct sk_buff *lb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002591 lb = __dev_alloc_skb(NS_LGSKBSIZE, GFP_KERNEL);
2592 if (lb == NULL)
2593 return -ENOMEM;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002594 NS_PRV_BUFTYPE(lb) = BUF_LG;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002595 skb_queue_tail(&card->lbpool.queue, lb);
2596 skb_reserve(lb, NS_SMBUFSIZE);
2597 push_rxbufs(card, lb);
2598 }
2599 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002601 case NS_BUFTYPE_HUGE:
2602 while (card->hbpool.count > card->hbnr.init) {
2603 struct sk_buff *hb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002605 spin_lock_irqsave(&card->int_lock, flags);
2606 hb = skb_dequeue(&card->hbpool.queue);
2607 card->hbpool.count--;
2608 spin_unlock_irqrestore(&card->int_lock, flags);
2609 if (hb == NULL)
2610 printk
2611 ("nicstar%d: huge buffer count inconsistent.\n",
2612 card->index);
2613 else
2614 dev_kfree_skb_any(hb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002616 }
2617 while (card->hbpool.count < card->hbnr.init) {
2618 struct sk_buff *hb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002620 hb = __dev_alloc_skb(NS_HBUFSIZE, GFP_KERNEL);
2621 if (hb == NULL)
2622 return -ENOMEM;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002623 NS_PRV_BUFTYPE(hb) = BUF_NONE;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002624 spin_lock_irqsave(&card->int_lock, flags);
2625 skb_queue_tail(&card->hbpool.queue, hb);
2626 card->hbpool.count++;
2627 spin_unlock_irqrestore(&card->int_lock, flags);
2628 }
2629 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002631 case NS_BUFTYPE_IOVEC:
2632 while (card->iovpool.count > card->iovnr.init) {
2633 struct sk_buff *iovb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002635 spin_lock_irqsave(&card->int_lock, flags);
2636 iovb = skb_dequeue(&card->iovpool.queue);
2637 card->iovpool.count--;
2638 spin_unlock_irqrestore(&card->int_lock, flags);
2639 if (iovb == NULL)
2640 printk
2641 ("nicstar%d: iovec buffer count inconsistent.\n",
2642 card->index);
2643 else
2644 dev_kfree_skb_any(iovb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002646 }
2647 while (card->iovpool.count < card->iovnr.init) {
2648 struct sk_buff *iovb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002650 iovb = alloc_skb(NS_IOVBUFSIZE, GFP_KERNEL);
2651 if (iovb == NULL)
2652 return -ENOMEM;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002653 NS_PRV_BUFTYPE(iovb) = BUF_NONE;
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002654 spin_lock_irqsave(&card->int_lock, flags);
2655 skb_queue_tail(&card->iovpool.queue, iovb);
2656 card->iovpool.count++;
2657 spin_unlock_irqrestore(&card->int_lock, flags);
2658 }
2659 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002661 default:
2662 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002664 }
2665 return 0;
2666
2667 default:
2668 if (dev->phy && dev->phy->ioctl) {
2669 return dev->phy->ioctl(dev, cmd, arg);
2670 } else {
2671 printk("nicstar%d: %s == NULL \n", card->index,
2672 dev->phy ? "dev->phy->ioctl" : "dev->phy");
2673 return -ENOIOCTLCMD;
2674 }
2675 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676}
2677
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002678#ifdef EXTRA_DEBUG
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002679static void which_list(ns_dev * card, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680{
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002681 printk("skb buf_type: 0x%08x\n", NS_PRV_BUFTYPE(skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682}
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002683#endif /* EXTRA_DEBUG */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684
Kees Cooke99e88a2017-10-16 14:43:17 -07002685static void ns_poll(struct timer_list *unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002687 int i;
2688 ns_dev *card;
2689 unsigned long flags;
2690 u32 stat_r, stat_w;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002692 PRINTK("nicstar: Entering ns_poll().\n");
2693 for (i = 0; i < num_cards; i++) {
2694 card = cards[i];
Lance Roy9a694c12018-10-04 00:46:57 -07002695 if (!spin_trylock_irqsave(&card->int_lock, flags)) {
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002696 /* Probably it isn't worth spinning */
2697 continue;
2698 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002700 stat_w = 0;
2701 stat_r = readl(card->membase + STAT);
2702 if (stat_r & NS_STAT_TSIF)
2703 stat_w |= NS_STAT_TSIF;
2704 if (stat_r & NS_STAT_EOPDU)
2705 stat_w |= NS_STAT_EOPDU;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002707 process_tsq(card);
2708 process_rsq(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002710 writel(stat_w, card->membase + STAT);
2711 spin_unlock_irqrestore(&card->int_lock, flags);
2712 }
2713 mod_timer(&ns_timer, jiffies + NS_POLL_PERIOD);
2714 PRINTK("nicstar: Leaving ns_poll().\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715}
2716
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717static void ns_phy_put(struct atm_dev *dev, unsigned char value,
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002718 unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002720 ns_dev *card;
2721 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002723 card = dev->dev_data;
2724 spin_lock_irqsave(&card->res_lock, flags);
2725 while (CMD_BUSY(card)) ;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002726 writel((u32) value, card->membase + DR0);
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002727 writel(NS_CMD_WRITE_UTILITY | 0x00000200 | (addr & 0x000000FF),
2728 card->membase + CMD);
2729 spin_unlock_irqrestore(&card->res_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730}
2731
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732static unsigned char ns_phy_get(struct atm_dev *dev, unsigned long addr)
2733{
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002734 ns_dev *card;
2735 unsigned long flags;
chas williams - CONTRACTOR864a3ff2010-05-29 09:04:25 +00002736 u32 data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737
chas williams - CONTRACTOR098fde12010-05-29 09:03:44 +00002738 card = dev->dev_data;
2739 spin_lock_irqsave(&card->res_lock, flags);
2740 while (CMD_BUSY(card)) ;
2741 writel(NS_CMD_READ_UTILITY | 0x00000200 | (addr & 0x000000FF),
2742 card->membase + CMD);
2743 while (CMD_BUSY(card)) ;
2744 data = readl(card->membase + DR0) & 0x000000FF;
2745 spin_unlock_irqrestore(&card->res_lock, flags);
2746 return (unsigned char)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747}
2748
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749module_init(nicstar_init);
2750module_exit(nicstar_cleanup);