chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * nicstar.c |
| 3 | * |
| 4 | * Device driver supporting CBR for IDT 77201/77211 "NICStAR" based cards. |
| 5 | * |
| 6 | * IMPORTANT: The included file nicstarmac.c was NOT WRITTEN BY ME. |
| 7 | * It was taken from the frle-0.22 device driver. |
| 8 | * As the file doesn't have a copyright notice, in the file |
| 9 | * nicstarmac.copyright I put the copyright notice from the |
| 10 | * frle-0.22 device driver. |
| 11 | * Some code is based on the nicstar driver by M. Welsh. |
| 12 | * |
| 13 | * Author: Rui Prior (rprior@inescn.pt) |
| 14 | * PowerPC support by Jay Talbott (jay_talbott@mcg.mot.com) April 1999 |
| 15 | * |
| 16 | * |
| 17 | * (C) INESC 1999 |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 18 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 20 | /* |
| 21 | * IMPORTANT INFORMATION |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | * |
| 23 | * There are currently three types of spinlocks: |
| 24 | * |
| 25 | * 1 - Per card interrupt spinlock (to protect structures and such) |
| 26 | * 2 - Per SCQ scq spinlock |
| 27 | * 3 - Per card resource spinlock (to access registers, etc.) |
| 28 | * |
| 29 | * These must NEVER be grabbed in reverse order. |
| 30 | * |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 31 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 33 | /* Header files */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
| 35 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/kernel.h> |
| 37 | #include <linux/skbuff.h> |
| 38 | #include <linux/atmdev.h> |
| 39 | #include <linux/atm.h> |
| 40 | #include <linux/pci.h> |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 41 | #include <linux/dma-mapping.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/types.h> |
| 43 | #include <linux/string.h> |
| 44 | #include <linux/delay.h> |
| 45 | #include <linux/init.h> |
| 46 | #include <linux/sched.h> |
| 47 | #include <linux/timer.h> |
| 48 | #include <linux/interrupt.h> |
| 49 | #include <linux/bitops.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 50 | #include <linux/slab.h> |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 51 | #include <linux/idr.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <asm/io.h> |
| 53 | #include <asm/uaccess.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 54 | #include <linux/atomic.h> |
dingtianhong | 4c55a46 | 2013-12-26 19:41:02 +0800 | [diff] [blame] | 55 | #include <linux/etherdevice.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #include "nicstar.h" |
| 57 | #ifdef CONFIG_ATM_NICSTAR_USE_SUNI |
| 58 | #include "suni.h" |
| 59 | #endif /* CONFIG_ATM_NICSTAR_USE_SUNI */ |
| 60 | #ifdef CONFIG_ATM_NICSTAR_USE_IDT77105 |
| 61 | #include "idt77105.h" |
| 62 | #endif /* CONFIG_ATM_NICSTAR_USE_IDT77105 */ |
| 63 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 64 | /* Additional code */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
| 66 | #include "nicstarmac.c" |
| 67 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 68 | /* Configurable parameters */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
| 70 | #undef PHY_LOOPBACK |
| 71 | #undef TX_DEBUG |
| 72 | #undef RX_DEBUG |
| 73 | #undef GENERAL_DEBUG |
| 74 | #undef EXTRA_DEBUG |
| 75 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 76 | /* Do not touch these */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
| 78 | #ifdef TX_DEBUG |
| 79 | #define TXPRINTK(args...) printk(args) |
| 80 | #else |
| 81 | #define TXPRINTK(args...) |
| 82 | #endif /* TX_DEBUG */ |
| 83 | |
| 84 | #ifdef RX_DEBUG |
| 85 | #define RXPRINTK(args...) printk(args) |
| 86 | #else |
| 87 | #define RXPRINTK(args...) |
| 88 | #endif /* RX_DEBUG */ |
| 89 | |
| 90 | #ifdef GENERAL_DEBUG |
| 91 | #define PRINTK(args...) printk(args) |
| 92 | #else |
| 93 | #define PRINTK(args...) |
| 94 | #endif /* GENERAL_DEBUG */ |
| 95 | |
| 96 | #ifdef EXTRA_DEBUG |
| 97 | #define XPRINTK(args...) printk(args) |
| 98 | #else |
| 99 | #define XPRINTK(args...) |
| 100 | #endif /* EXTRA_DEBUG */ |
| 101 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 102 | /* Macros */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
| 104 | #define CMD_BUSY(card) (readl((card)->membase + STAT) & NS_STAT_CMDBZ) |
| 105 | |
| 106 | #define NS_DELAY mdelay(1) |
| 107 | |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 108 | #define PTR_DIFF(a, b) ((u32)((unsigned long)(a) - (unsigned long)(b))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
| 110 | #ifndef ATM_SKB |
| 111 | #define ATM_SKB(s) (&(s)->atm) |
| 112 | #endif |
| 113 | |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 114 | #define scq_virt_to_bus(scq, p) \ |
| 115 | (scq->dma + ((unsigned long)(p) - (unsigned long)(scq)->org)) |
| 116 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 117 | /* Function declarations */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 119 | static u32 ns_read_sram(ns_dev * card, u32 sram_address); |
| 120 | static void ns_write_sram(ns_dev * card, u32 sram_address, u32 * value, |
| 121 | int count); |
Greg Kroah-Hartman | 6c44512 | 2012-12-21 13:25:04 -0800 | [diff] [blame] | 122 | static int ns_init_card(int i, struct pci_dev *pcidev); |
| 123 | static void ns_init_card_error(ns_dev * card, int error); |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 124 | static scq_info *get_scq(ns_dev *card, int size, u32 scd); |
| 125 | static void free_scq(ns_dev *card, scq_info * scq, struct atm_vcc *vcc); |
David S. Miller | 8728b83 | 2005-08-09 19:25:21 -0700 | [diff] [blame] | 126 | static void push_rxbufs(ns_dev *, struct sk_buff *); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 127 | static irqreturn_t ns_irq_handler(int irq, void *dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | static int ns_open(struct atm_vcc *vcc); |
| 129 | static void ns_close(struct atm_vcc *vcc); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 130 | static void fill_tst(ns_dev * card, int n, vc_map * vc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 132 | static int push_scqe(ns_dev * card, vc_map * vc, scq_info * scq, ns_scqe * tbd, |
| 133 | struct sk_buff *skb); |
| 134 | static void process_tsq(ns_dev * card); |
| 135 | static void drain_scq(ns_dev * card, scq_info * scq, int pos); |
| 136 | static void process_rsq(ns_dev * card); |
| 137 | static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 138 | static void recycle_rx_buf(ns_dev * card, struct sk_buff *skb); |
| 139 | static void recycle_iovec_rx_bufs(ns_dev * card, struct iovec *iov, int count); |
| 140 | static void recycle_iov_buf(ns_dev * card, struct sk_buff *iovb); |
| 141 | static void dequeue_sm_buf(ns_dev * card, struct sk_buff *sb); |
| 142 | static void dequeue_lg_buf(ns_dev * card, struct sk_buff *lb); |
| 143 | static int ns_proc_read(struct atm_dev *dev, loff_t * pos, char *page); |
| 144 | static int ns_ioctl(struct atm_dev *dev, unsigned int cmd, void __user * arg); |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 145 | #ifdef EXTRA_DEBUG |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 146 | static void which_list(ns_dev * card, struct sk_buff *skb); |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 147 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | static void ns_poll(unsigned long arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | static void ns_phy_put(struct atm_dev *dev, unsigned char value, |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 150 | unsigned long addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | static unsigned char ns_phy_get(struct atm_dev *dev, unsigned long addr); |
| 152 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 153 | /* Global variables */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | |
| 155 | static struct ns_dev *cards[NS_MAX_CARDS]; |
| 156 | static unsigned num_cards; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 157 | static struct atmdev_ops atm_ops = { |
| 158 | .open = ns_open, |
| 159 | .close = ns_close, |
| 160 | .ioctl = ns_ioctl, |
| 161 | .send = ns_send, |
| 162 | .phy_put = ns_phy_put, |
| 163 | .phy_get = ns_phy_get, |
| 164 | .proc_read = ns_proc_read, |
| 165 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | }; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 167 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | static struct timer_list ns_timer; |
| 169 | static char *mac[NS_MAX_CARDS]; |
| 170 | module_param_array(mac, charp, NULL, 0); |
| 171 | MODULE_LICENSE("GPL"); |
| 172 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 173 | /* Functions */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
Greg Kroah-Hartman | 6c44512 | 2012-12-21 13:25:04 -0800 | [diff] [blame] | 175 | static int nicstar_init_one(struct pci_dev *pcidev, |
| 176 | const struct pci_device_id *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 178 | static int index = -1; |
| 179 | unsigned int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 181 | index++; |
| 182 | cards[index] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 184 | error = ns_init_card(index, pcidev); |
| 185 | if (error) { |
| 186 | cards[index--] = NULL; /* don't increment index */ |
| 187 | goto err_out; |
| 188 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 190 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | err_out: |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 192 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Greg Kroah-Hartman | 6c44512 | 2012-12-21 13:25:04 -0800 | [diff] [blame] | 195 | static void nicstar_remove_one(struct pci_dev *pcidev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 197 | int i, j; |
| 198 | ns_dev *card = pci_get_drvdata(pcidev); |
| 199 | struct sk_buff *hb; |
| 200 | struct sk_buff *iovb; |
| 201 | struct sk_buff *lb; |
| 202 | struct sk_buff *sb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 204 | i = card->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 206 | if (cards[i] == NULL) |
| 207 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 209 | if (card->atmdev->phy && card->atmdev->phy->stop) |
| 210 | card->atmdev->phy->stop(card->atmdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 212 | /* Stop everything */ |
| 213 | writel(0x00000000, card->membase + CFG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 215 | /* De-register device */ |
| 216 | atm_dev_deregister(card->atmdev); |
| 217 | |
| 218 | /* Disable PCI device */ |
| 219 | pci_disable_device(pcidev); |
| 220 | |
| 221 | /* Free up resources */ |
| 222 | j = 0; |
| 223 | PRINTK("nicstar%d: freeing %d huge buffers.\n", i, card->hbpool.count); |
| 224 | while ((hb = skb_dequeue(&card->hbpool.queue)) != NULL) { |
| 225 | dev_kfree_skb_any(hb); |
| 226 | j++; |
| 227 | } |
| 228 | PRINTK("nicstar%d: %d huge buffers freed.\n", i, j); |
| 229 | j = 0; |
| 230 | PRINTK("nicstar%d: freeing %d iovec buffers.\n", i, |
| 231 | card->iovpool.count); |
| 232 | while ((iovb = skb_dequeue(&card->iovpool.queue)) != NULL) { |
| 233 | dev_kfree_skb_any(iovb); |
| 234 | j++; |
| 235 | } |
| 236 | PRINTK("nicstar%d: %d iovec buffers freed.\n", i, j); |
| 237 | while ((lb = skb_dequeue(&card->lbpool.queue)) != NULL) |
| 238 | dev_kfree_skb_any(lb); |
| 239 | while ((sb = skb_dequeue(&card->sbpool.queue)) != NULL) |
| 240 | dev_kfree_skb_any(sb); |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 241 | free_scq(card, card->scq0, NULL); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 242 | for (j = 0; j < NS_FRSCD_NUM; j++) { |
| 243 | if (card->scd2vc[j] != NULL) |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 244 | free_scq(card, card->scd2vc[j]->scq, card->scd2vc[j]->tx_vcc); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 245 | } |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 246 | idr_destroy(&card->idr); |
chas williams - CONTRACTOR | ede58ef | 2015-01-16 08:57:21 -0500 | [diff] [blame] | 247 | dma_free_coherent(&card->pcidev->dev, NS_RSQSIZE + NS_RSQ_ALIGNMENT, |
| 248 | card->rsq.org, card->rsq.dma); |
| 249 | dma_free_coherent(&card->pcidev->dev, NS_TSQSIZE + NS_TSQ_ALIGNMENT, |
| 250 | card->tsq.org, card->tsq.dma); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 251 | free_irq(card->pcidev->irq, card); |
| 252 | iounmap(card->membase); |
| 253 | kfree(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Greg Kroah-Hartman | 6c44512 | 2012-12-21 13:25:04 -0800 | [diff] [blame] | 256 | static struct pci_device_id nicstar_pci_tbl[] = { |
Peter Huewe | 6df7b80 | 2010-07-15 08:48:26 +0000 | [diff] [blame] | 257 | { PCI_VDEVICE(IDT, PCI_DEVICE_ID_IDT_IDT77201), 0 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | {0,} /* terminate list */ |
| 259 | }; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 260 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | MODULE_DEVICE_TABLE(pci, nicstar_pci_tbl); |
| 262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | static struct pci_driver nicstar_driver = { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 264 | .name = "nicstar", |
| 265 | .id_table = nicstar_pci_tbl, |
| 266 | .probe = nicstar_init_one, |
Greg Kroah-Hartman | 6c44512 | 2012-12-21 13:25:04 -0800 | [diff] [blame] | 267 | .remove = nicstar_remove_one, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | }; |
| 269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | static int __init nicstar_init(void) |
| 271 | { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 272 | unsigned error = 0; /* Initialized to remove compile warning */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 274 | XPRINTK("nicstar: nicstar_init() called.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 276 | error = pci_register_driver(&nicstar_driver); |
| 277 | |
| 278 | TXPRINTK("nicstar: TX debug enabled.\n"); |
| 279 | RXPRINTK("nicstar: RX debug enabled.\n"); |
| 280 | PRINTK("nicstar: General debug enabled.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | #ifdef PHY_LOOPBACK |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 282 | printk("nicstar: using PHY loopback.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | #endif /* PHY_LOOPBACK */ |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 284 | XPRINTK("nicstar: nicstar_init() returned.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 286 | if (!error) { |
| 287 | init_timer(&ns_timer); |
| 288 | ns_timer.expires = jiffies + NS_POLL_PERIOD; |
| 289 | ns_timer.data = 0UL; |
| 290 | ns_timer.function = ns_poll; |
| 291 | add_timer(&ns_timer); |
| 292 | } |
| 293 | |
| 294 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | static void __exit nicstar_cleanup(void) |
| 298 | { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 299 | XPRINTK("nicstar: nicstar_cleanup() called.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 301 | del_timer(&ns_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 303 | pci_unregister_driver(&nicstar_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 305 | XPRINTK("nicstar: nicstar_cleanup() returned.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | } |
| 307 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 308 | static u32 ns_read_sram(ns_dev * card, u32 sram_address) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 310 | unsigned long flags; |
| 311 | u32 data; |
| 312 | sram_address <<= 2; |
| 313 | sram_address &= 0x0007FFFC; /* address must be dword aligned */ |
| 314 | sram_address |= 0x50000000; /* SRAM read command */ |
| 315 | spin_lock_irqsave(&card->res_lock, flags); |
| 316 | while (CMD_BUSY(card)) ; |
| 317 | writel(sram_address, card->membase + CMD); |
| 318 | while (CMD_BUSY(card)) ; |
| 319 | data = readl(card->membase + DR0); |
| 320 | spin_unlock_irqrestore(&card->res_lock, flags); |
| 321 | return data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | } |
| 323 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 324 | static void ns_write_sram(ns_dev * card, u32 sram_address, u32 * value, |
| 325 | int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 327 | unsigned long flags; |
| 328 | int i, c; |
| 329 | count--; /* count range now is 0..3 instead of 1..4 */ |
| 330 | c = count; |
| 331 | c <<= 2; /* to use increments of 4 */ |
| 332 | spin_lock_irqsave(&card->res_lock, flags); |
| 333 | while (CMD_BUSY(card)) ; |
| 334 | for (i = 0; i <= c; i += 4) |
| 335 | writel(*(value++), card->membase + i); |
| 336 | /* Note: DR# registers are the first 4 dwords in nicstar's memspace, |
| 337 | so card->membase + DR0 == card->membase */ |
| 338 | sram_address <<= 2; |
| 339 | sram_address &= 0x0007FFFC; |
| 340 | sram_address |= (0x40000000 | count); |
| 341 | writel(sram_address, card->membase + CMD); |
| 342 | spin_unlock_irqrestore(&card->res_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Greg Kroah-Hartman | 6c44512 | 2012-12-21 13:25:04 -0800 | [diff] [blame] | 345 | static int ns_init_card(int i, struct pci_dev *pcidev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 347 | int j; |
| 348 | struct ns_dev *card = NULL; |
| 349 | unsigned char pci_latency; |
| 350 | unsigned error; |
| 351 | u32 data; |
| 352 | u32 u32d[4]; |
| 353 | u32 ns_cfg_rctsize; |
| 354 | int bcount; |
| 355 | unsigned long membase; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 357 | error = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 359 | if (pci_enable_device(pcidev)) { |
| 360 | printk("nicstar%d: can't enable PCI device\n", i); |
| 361 | error = 2; |
| 362 | ns_init_card_error(card, error); |
| 363 | return error; |
| 364 | } |
chas williams - CONTRACTOR | ede58ef | 2015-01-16 08:57:21 -0500 | [diff] [blame] | 365 | if (dma_set_mask_and_coherent(&pcidev->dev, DMA_BIT_MASK(32)) != 0) { |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 366 | printk(KERN_WARNING |
| 367 | "nicstar%d: No suitable DMA available.\n", i); |
| 368 | error = 2; |
| 369 | ns_init_card_error(card, error); |
| 370 | return error; |
| 371 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 373 | if ((card = kmalloc(sizeof(ns_dev), GFP_KERNEL)) == NULL) { |
| 374 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 385 | pci_set_drvdata(pcidev, card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 387 | 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 - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 398 | PRINTK("nicstar%d: membase at 0x%p.\n", i, card->membase); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 399 | |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | #ifdef NS_PCI_LATENCY |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 409 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | #endif /* NS_PCI_LATENCY */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 428 | /* Clear timer overflow */ |
| 429 | data = readl(card->membase + STAT); |
| 430 | if (data & NS_STAT_TMROF) |
| 431 | writel(NS_STAT_TMROF, card->membase + STAT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 433 | /* 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | #ifdef PHY_LOOPBACK |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 462 | while (CMD_BUSY(card)) ; |
| 463 | writel(0x00000022, card->membase + DR0); |
| 464 | writel(NS_CMD_WRITE_UTILITY | 0x00000202, card->membase + CMD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | #endif /* PHY_LOOPBACK */ |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 466 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | #ifdef PHY_LOOPBACK |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 472 | while (CMD_BUSY(card)) ; |
| 473 | writel(0x00000002, card->membase + DR0); |
| 474 | writel(NS_CMD_WRITE_UTILITY | 0x00000205, card->membase + CMD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | #endif /* PHY_LOOPBACK */ |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 476 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 485 | /* 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 497 | card->rct_size = NS_MAX_RCTSIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | |
| 499 | #if (NS_MAX_RCTSIZE == 4096) |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 500 | if (card->sram_size == 128) |
| 501 | printk |
| 502 | ("nicstar%d: limiting maximum VCI. See NS_MAX_RCTSIZE in nicstar.h\n", |
| 503 | i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | #elif (NS_MAX_RCTSIZE == 16384) |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 505 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | #else |
| 512 | #error NS_MAX_RCTSIZE must be either 4096 or 16384 in nicstar.c |
| 513 | #endif |
| 514 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 515 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 521 | /* Initialize the nicstar eeprom/eprom stuff, for the MAC addr */ |
| 522 | if (mac[i] == NULL) |
| 523 | nicstar_init_eprom(card->membase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 525 | /* Set the VPI/VCI MSb mask to zero so we can receive OAM cells */ |
| 526 | writel(0x00000000, card->membase + VPM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 528 | /* Initialize TSQ */ |
chas williams - CONTRACTOR | ede58ef | 2015-01-16 08:57:21 -0500 | [diff] [blame] | 529 | card->tsq.org = dma_alloc_coherent(&card->pcidev->dev, |
| 530 | NS_TSQSIZE + NS_TSQ_ALIGNMENT, |
| 531 | &card->tsq.dma, GFP_KERNEL); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 532 | 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 - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 538 | card->tsq.base = PTR_ALIGN(card->tsq.org, NS_TSQ_ALIGNMENT); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 539 | 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 - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 544 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 547 | /* Initialize RSQ */ |
chas williams - CONTRACTOR | ede58ef | 2015-01-16 08:57:21 -0500 | [diff] [blame] | 548 | card->rsq.org = dma_alloc_coherent(&card->pcidev->dev, |
| 549 | NS_RSQSIZE + NS_RSQ_ALIGNMENT, |
| 550 | &card->rsq.dma, GFP_KERNEL); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 551 | 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 - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 557 | card->rsq.base = PTR_ALIGN(card->rsq.org, NS_RSQ_ALIGNMENT); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 558 | 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 - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 563 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 566 | /* Initialize SCQ0, the only VBR SCQ used */ |
| 567 | card->scq1 = NULL; |
| 568 | card->scq2 = NULL; |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 569 | card->scq0 = get_scq(card, VBR_SCQSIZE, NS_VRSCD0); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 570 | 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 - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 576 | u32d[0] = scq_virt_to_bus(card->scq0, card->scq0->base); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 577 | 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 - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 584 | PRINTK("nicstar%d: VBR-SCQ0 base at 0x%p.\n", i, card->scq0->base); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 585 | |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | #ifdef RCQ_SUPPORT |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 604 | u32d[0] = NS_RCTE_RAWCELLINTEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | #else |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 606 | u32d[0] = 0x00000000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | #endif /* RCQ_SUPPORT */ |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 608 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 614 | memset(card->vcmap, 0, NS_MAX_RCTSIZE * sizeof(vc_map)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 616 | for (j = 0; j < NS_FRSCD_NUM; j++) |
| 617 | card->scd2vc[j] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 619 | /* 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | |
Daeseok Youn | c664d63 | 2014-02-19 10:10:11 +0900 | [diff] [blame] | 633 | card->sm_handle = NULL; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 634 | card->sm_addr = 0x00000000; |
Daeseok Youn | c664d63 | 2014-02-19 10:10:11 +0900 | [diff] [blame] | 635 | card->lg_handle = NULL; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 636 | card->lg_addr = 0x00000000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 638 | card->efbie = 1; /* To prevent push_rxbufs from enabling the interrupt */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 640 | idr_init(&card->idr); |
| 641 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 642 | /* 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 - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 656 | NS_PRV_BUFTYPE(hb) = BUF_NONE; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 657 | skb_queue_tail(&card->hbpool.queue, hb); |
| 658 | card->hbpool.count++; |
| 659 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 661 | /* 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 - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 675 | NS_PRV_BUFTYPE(lb) = BUF_LG; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 676 | 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 - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 682 | card->rawcell = (struct ns_rcqe *) lb->data; |
| 683 | card->rawch = NS_PRV_DMA(lb); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 684 | } |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 697 | /* 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 - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 711 | NS_PRV_BUFTYPE(sb) = BUF_SM; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 712 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 727 | /* 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 - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 741 | NS_PRV_BUFTYPE(iovb) = BUF_NONE; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 742 | skb_queue_tail(&card->iovpool.queue, iovb); |
| 743 | card->iovpool.count++; |
| 744 | } |
Chas Williams | 5296195 | 2008-01-07 00:26:22 -0800 | [diff] [blame] | 745 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 746 | /* 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 752 | card->efbie = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 754 | card->intcnt = 0; |
| 755 | if (request_irq |
chas williams - CONTRACTOR | 06df277 | 2010-07-10 03:42:02 +0000 | [diff] [blame] | 756 | (pcidev->irq, &ns_irq_handler, IRQF_SHARED, "nicstar", card) != 0) { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 757 | 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 Williams | d9ca676 | 2010-12-08 19:40:47 +0000 | [diff] [blame] | 764 | card->atmdev = atm_dev_register("nicstar", &card->pcidev->dev, &atm_ops, |
| 765 | -1, NULL); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 766 | 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 Shevchenko | d2bb3905 | 2013-09-13 18:00:58 +0300 | [diff] [blame] | 773 | if (mac[i] == NULL || !mac_pton(mac[i], card->atmdev->esi)) { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 774 | nicstar_read_eprom(card->membase, NICSTAR_EPROM_MAC_ADDR_OFFSET, |
| 775 | card->atmdev->esi, 6); |
dingtianhong | 4c55a46 | 2013-12-26 19:41:02 +0800 | [diff] [blame] | 776 | if (ether_addr_equal(card->atmdev->esi, "\x00\x00\x00\x00\x00\x00")) { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 777 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | |
| 791 | #ifdef CONFIG_ATM_NICSTAR_USE_SUNI |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 792 | if (card->max_pcr == ATM_OC3_PCR) |
| 793 | suni_init(card->atmdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | #endif /* CONFIG_ATM_NICSTAR_USE_SUNI */ |
| 795 | |
| 796 | #ifdef CONFIG_ATM_NICSTAR_USE_IDT77105 |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 797 | if (card->max_pcr == ATM_25_PCR) |
| 798 | idt77105_init(card->atmdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | #endif /* CONFIG_ATM_NICSTAR_USE_IDT77105 */ |
| 800 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 801 | if (card->atmdev->phy && card->atmdev->phy->start) |
| 802 | card->atmdev->phy->start(card->atmdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 804 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 808 | num_cards++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 810 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | } |
| 812 | |
Greg Kroah-Hartman | 6c44512 | 2012-12-21 13:25:04 -0800 | [diff] [blame] | 813 | static void ns_init_card_error(ns_dev *card, int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 815 | 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 - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 827 | free_scq(card, card->scq0, NULL); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 828 | } |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | } |
| 856 | |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 857 | static scq_info *get_scq(ns_dev *card, int size, u32 scd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 859 | scq_info *scq; |
| 860 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 862 | if (size != VBR_SCQSIZE && size != CBR_SCQSIZE) |
| 863 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 865 | scq = kmalloc(sizeof(scq_info), GFP_KERNEL); |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 866 | if (!scq) |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 867 | return NULL; |
chas williams - CONTRACTOR | ede58ef | 2015-01-16 08:57:21 -0500 | [diff] [blame] | 868 | scq->org = dma_alloc_coherent(&card->pcidev->dev, |
| 869 | 2 * size, &scq->dma, GFP_KERNEL); |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 870 | if (!scq->org) { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 871 | kfree(scq); |
| 872 | return NULL; |
| 873 | } |
| 874 | scq->skb = kmalloc(sizeof(struct sk_buff *) * |
| 875 | (size / NS_SCQE_SIZE), GFP_KERNEL); |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 876 | if (!scq->skb) { |
Christophe Jaillet | eab8146 | 2016-07-17 09:03:24 +0200 | [diff] [blame] | 877 | dma_free_coherent(&card->pcidev->dev, |
| 878 | 2 * size, scq->org, scq->dma); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 879 | kfree(scq); |
| 880 | return NULL; |
| 881 | } |
| 882 | scq->num_entries = size / NS_SCQE_SIZE; |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 883 | scq->base = PTR_ALIGN(scq->org, size); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 884 | scq->next = scq->base; |
| 885 | scq->last = scq->base + (scq->num_entries - 1); |
| 886 | scq->tail = scq->last; |
| 887 | scq->scd = scd; |
| 888 | scq->num_entries = size / NS_SCQE_SIZE; |
| 889 | scq->tbd_count = 0; |
| 890 | init_waitqueue_head(&scq->scqfull_waitq); |
| 891 | scq->full = 0; |
| 892 | spin_lock_init(&scq->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 894 | for (i = 0; i < scq->num_entries; i++) |
| 895 | scq->skb[i] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 897 | return scq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | } |
| 899 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | /* For variable rate SCQ vcc must be NULL */ |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 901 | static void free_scq(ns_dev *card, scq_info *scq, struct atm_vcc *vcc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 903 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 905 | if (scq->num_entries == VBR_SCQ_NUM_ENTRIES) |
| 906 | for (i = 0; i < scq->num_entries; i++) { |
| 907 | if (scq->skb[i] != NULL) { |
| 908 | vcc = ATM_SKB(scq->skb[i])->vcc; |
| 909 | if (vcc->pop != NULL) |
| 910 | vcc->pop(vcc, scq->skb[i]); |
| 911 | else |
| 912 | dev_kfree_skb_any(scq->skb[i]); |
| 913 | } |
| 914 | } else { /* vcc must be != NULL */ |
| 915 | |
| 916 | if (vcc == NULL) { |
| 917 | printk |
| 918 | ("nicstar: free_scq() called with vcc == NULL for fixed rate scq."); |
| 919 | for (i = 0; i < scq->num_entries; i++) |
| 920 | dev_kfree_skb_any(scq->skb[i]); |
| 921 | } else |
| 922 | for (i = 0; i < scq->num_entries; i++) { |
| 923 | if (scq->skb[i] != NULL) { |
| 924 | if (vcc->pop != NULL) |
| 925 | vcc->pop(vcc, scq->skb[i]); |
| 926 | else |
| 927 | dev_kfree_skb_any(scq->skb[i]); |
| 928 | } |
| 929 | } |
| 930 | } |
| 931 | kfree(scq->skb); |
chas williams - CONTRACTOR | ede58ef | 2015-01-16 08:57:21 -0500 | [diff] [blame] | 932 | dma_free_coherent(&card->pcidev->dev, |
| 933 | 2 * (scq->num_entries == VBR_SCQ_NUM_ENTRIES ? |
| 934 | VBR_SCQSIZE : CBR_SCQSIZE), |
| 935 | scq->org, scq->dma); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 936 | kfree(scq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | } |
| 938 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | /* The handles passed must be pointers to the sk_buff containing the small |
| 940 | or large buffer(s) cast to u32. */ |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 941 | static void push_rxbufs(ns_dev * card, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | { |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 943 | struct sk_buff *handle1, *handle2; |
Tejun Heo | b051f6e | 2013-02-27 17:04:00 -0800 | [diff] [blame] | 944 | int id1, id2; |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 945 | u32 addr1, addr2; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 946 | u32 stat; |
| 947 | unsigned long flags; |
| 948 | |
| 949 | /* *BARF* */ |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 950 | handle2 = NULL; |
| 951 | addr2 = 0; |
| 952 | handle1 = skb; |
chas williams - CONTRACTOR | ede58ef | 2015-01-16 08:57:21 -0500 | [diff] [blame] | 953 | addr1 = dma_map_single(&card->pcidev->dev, |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 954 | skb->data, |
| 955 | (NS_PRV_BUFTYPE(skb) == BUF_SM |
| 956 | ? NS_SMSKBSIZE : NS_LGSKBSIZE), |
chas williams - CONTRACTOR | ede58ef | 2015-01-16 08:57:21 -0500 | [diff] [blame] | 957 | DMA_TO_DEVICE); |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 958 | NS_PRV_DMA(skb) = addr1; /* save so we can unmap later */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | |
| 960 | #ifdef GENERAL_DEBUG |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 961 | if (!addr1) |
| 962 | printk("nicstar%d: push_rxbufs called with addr1 = 0.\n", |
| 963 | card->index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | #endif /* GENERAL_DEBUG */ |
| 965 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 966 | stat = readl(card->membase + STAT); |
| 967 | card->sbfqc = ns_stat_sfbqc_get(stat); |
| 968 | card->lbfqc = ns_stat_lfbqc_get(stat); |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 969 | if (NS_PRV_BUFTYPE(skb) == BUF_SM) { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 970 | if (!addr2) { |
| 971 | if (card->sm_addr) { |
| 972 | addr2 = card->sm_addr; |
| 973 | handle2 = card->sm_handle; |
| 974 | card->sm_addr = 0x00000000; |
Daeseok Youn | c664d63 | 2014-02-19 10:10:11 +0900 | [diff] [blame] | 975 | card->sm_handle = NULL; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 976 | } else { /* (!sm_addr) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 978 | card->sm_addr = addr1; |
| 979 | card->sm_handle = handle1; |
| 980 | } |
| 981 | } |
| 982 | } else { /* buf_type == BUF_LG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 984 | if (!addr2) { |
| 985 | if (card->lg_addr) { |
| 986 | addr2 = card->lg_addr; |
| 987 | handle2 = card->lg_handle; |
| 988 | card->lg_addr = 0x00000000; |
Daeseok Youn | c664d63 | 2014-02-19 10:10:11 +0900 | [diff] [blame] | 989 | card->lg_handle = NULL; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 990 | } else { /* (!lg_addr) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 992 | card->lg_addr = addr1; |
| 993 | card->lg_handle = handle1; |
| 994 | } |
| 995 | } |
| 996 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 998 | if (addr2) { |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 999 | if (NS_PRV_BUFTYPE(skb) == BUF_SM) { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1000 | if (card->sbfqc >= card->sbnr.max) { |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1001 | skb_unlink(handle1, &card->sbpool.queue); |
| 1002 | dev_kfree_skb_any(handle1); |
| 1003 | skb_unlink(handle2, &card->sbpool.queue); |
| 1004 | dev_kfree_skb_any(handle2); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1005 | return; |
| 1006 | } else |
| 1007 | card->sbfqc += 2; |
| 1008 | } else { /* (buf_type == BUF_LG) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1010 | if (card->lbfqc >= card->lbnr.max) { |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1011 | skb_unlink(handle1, &card->lbpool.queue); |
| 1012 | dev_kfree_skb_any(handle1); |
| 1013 | skb_unlink(handle2, &card->lbpool.queue); |
| 1014 | dev_kfree_skb_any(handle2); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1015 | return; |
| 1016 | } else |
| 1017 | card->lbfqc += 2; |
| 1018 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | |
Tejun Heo | b051f6e | 2013-02-27 17:04:00 -0800 | [diff] [blame] | 1020 | id1 = idr_alloc(&card->idr, handle1, 0, 0, GFP_ATOMIC); |
| 1021 | if (id1 < 0) |
| 1022 | goto out; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1023 | |
Tejun Heo | b051f6e | 2013-02-27 17:04:00 -0800 | [diff] [blame] | 1024 | id2 = idr_alloc(&card->idr, handle2, 0, 0, GFP_ATOMIC); |
| 1025 | if (id2 < 0) |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1026 | goto out; |
| 1027 | |
| 1028 | spin_lock_irqsave(&card->res_lock, flags); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1029 | while (CMD_BUSY(card)) ; |
| 1030 | writel(addr2, card->membase + DR3); |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1031 | writel(id2, card->membase + DR2); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1032 | writel(addr1, card->membase + DR1); |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1033 | writel(id1, card->membase + DR0); |
| 1034 | writel(NS_CMD_WRITE_FREEBUFQ | NS_PRV_BUFTYPE(skb), |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1035 | card->membase + CMD); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1036 | spin_unlock_irqrestore(&card->res_lock, flags); |
| 1037 | |
| 1038 | XPRINTK("nicstar%d: Pushing %s buffers at 0x%x and 0x%x.\n", |
| 1039 | card->index, |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1040 | (NS_PRV_BUFTYPE(skb) == BUF_SM ? "small" : "large"), |
| 1041 | addr1, addr2); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | if (!card->efbie && card->sbfqc >= card->sbnr.min && |
| 1045 | card->lbfqc >= card->lbnr.min) { |
| 1046 | card->efbie = 1; |
| 1047 | writel((readl(card->membase + CFG) | NS_CFG_EFBIE), |
| 1048 | card->membase + CFG); |
| 1049 | } |
| 1050 | |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1051 | out: |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1052 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | } |
| 1054 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1055 | static irqreturn_t ns_irq_handler(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1057 | u32 stat_r; |
| 1058 | ns_dev *card; |
| 1059 | struct atm_dev *dev; |
| 1060 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1062 | card = (ns_dev *) dev_id; |
| 1063 | dev = card->atmdev; |
| 1064 | card->intcnt++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1066 | PRINTK("nicstar%d: NICStAR generated an interrupt\n", card->index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1068 | spin_lock_irqsave(&card->int_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1070 | stat_r = readl(card->membase + STAT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1072 | /* Transmit Status Indicator has been written to T. S. Queue */ |
| 1073 | if (stat_r & NS_STAT_TSIF) { |
| 1074 | TXPRINTK("nicstar%d: TSI interrupt\n", card->index); |
| 1075 | process_tsq(card); |
| 1076 | writel(NS_STAT_TSIF, card->membase + STAT); |
| 1077 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1079 | /* Incomplete CS-PDU has been transmitted */ |
| 1080 | if (stat_r & NS_STAT_TXICP) { |
| 1081 | writel(NS_STAT_TXICP, card->membase + STAT); |
| 1082 | TXPRINTK("nicstar%d: Incomplete CS-PDU transmitted.\n", |
| 1083 | card->index); |
| 1084 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1086 | /* Transmit Status Queue 7/8 full */ |
| 1087 | if (stat_r & NS_STAT_TSQF) { |
| 1088 | writel(NS_STAT_TSQF, card->membase + STAT); |
| 1089 | PRINTK("nicstar%d: TSQ full.\n", card->index); |
| 1090 | process_tsq(card); |
| 1091 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1093 | /* Timer overflow */ |
| 1094 | if (stat_r & NS_STAT_TMROF) { |
| 1095 | writel(NS_STAT_TMROF, card->membase + STAT); |
| 1096 | PRINTK("nicstar%d: Timer overflow.\n", card->index); |
| 1097 | } |
| 1098 | |
| 1099 | /* PHY device interrupt signal active */ |
| 1100 | if (stat_r & NS_STAT_PHYI) { |
| 1101 | writel(NS_STAT_PHYI, card->membase + STAT); |
| 1102 | PRINTK("nicstar%d: PHY interrupt.\n", card->index); |
| 1103 | if (dev->phy && dev->phy->interrupt) { |
| 1104 | dev->phy->interrupt(dev); |
| 1105 | } |
| 1106 | } |
| 1107 | |
| 1108 | /* Small Buffer Queue is full */ |
| 1109 | if (stat_r & NS_STAT_SFBQF) { |
| 1110 | writel(NS_STAT_SFBQF, card->membase + STAT); |
| 1111 | printk("nicstar%d: Small free buffer queue is full.\n", |
| 1112 | card->index); |
| 1113 | } |
| 1114 | |
| 1115 | /* Large Buffer Queue is full */ |
| 1116 | if (stat_r & NS_STAT_LFBQF) { |
| 1117 | writel(NS_STAT_LFBQF, card->membase + STAT); |
| 1118 | printk("nicstar%d: Large free buffer queue is full.\n", |
| 1119 | card->index); |
| 1120 | } |
| 1121 | |
| 1122 | /* Receive Status Queue is full */ |
| 1123 | if (stat_r & NS_STAT_RSQF) { |
| 1124 | writel(NS_STAT_RSQF, card->membase + STAT); |
| 1125 | printk("nicstar%d: RSQ full.\n", card->index); |
| 1126 | process_rsq(card); |
| 1127 | } |
| 1128 | |
| 1129 | /* Complete CS-PDU received */ |
| 1130 | if (stat_r & NS_STAT_EOPDU) { |
| 1131 | RXPRINTK("nicstar%d: End of CS-PDU received.\n", card->index); |
| 1132 | process_rsq(card); |
| 1133 | writel(NS_STAT_EOPDU, card->membase + STAT); |
| 1134 | } |
| 1135 | |
| 1136 | /* Raw cell received */ |
| 1137 | if (stat_r & NS_STAT_RAWCF) { |
| 1138 | writel(NS_STAT_RAWCF, card->membase + STAT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | #ifndef RCQ_SUPPORT |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1140 | printk("nicstar%d: Raw cell received and no support yet...\n", |
| 1141 | card->index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | #endif /* RCQ_SUPPORT */ |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1143 | /* NOTE: the following procedure may keep a raw cell pending until the |
| 1144 | next interrupt. As this preliminary support is only meant to |
| 1145 | avoid buffer leakage, this is not an issue. */ |
| 1146 | while (readl(card->membase + RAWCT) != card->rawch) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1148 | if (ns_rcqe_islast(card->rawcell)) { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1149 | struct sk_buff *oldbuf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1151 | oldbuf = card->rcbuf; |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1152 | card->rcbuf = idr_find(&card->idr, |
| 1153 | ns_rcqe_nextbufhandle(card->rawcell)); |
| 1154 | card->rawch = NS_PRV_DMA(card->rcbuf); |
| 1155 | card->rawcell = (struct ns_rcqe *) |
| 1156 | card->rcbuf->data; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1157 | recycle_rx_buf(card, oldbuf); |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1158 | } else { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1159 | card->rawch += NS_RCQE_SIZE; |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1160 | card->rawcell++; |
| 1161 | } |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1162 | } |
| 1163 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1165 | /* Small buffer queue is empty */ |
| 1166 | if (stat_r & NS_STAT_SFBQE) { |
| 1167 | int i; |
| 1168 | struct sk_buff *sb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1170 | writel(NS_STAT_SFBQE, card->membase + STAT); |
| 1171 | printk("nicstar%d: Small free buffer queue empty.\n", |
| 1172 | card->index); |
| 1173 | for (i = 0; i < card->sbnr.min; i++) { |
| 1174 | sb = dev_alloc_skb(NS_SMSKBSIZE); |
| 1175 | if (sb == NULL) { |
| 1176 | writel(readl(card->membase + CFG) & |
| 1177 | ~NS_CFG_EFBIE, card->membase + CFG); |
| 1178 | card->efbie = 0; |
| 1179 | break; |
| 1180 | } |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1181 | NS_PRV_BUFTYPE(sb) = BUF_SM; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1182 | skb_queue_tail(&card->sbpool.queue, sb); |
| 1183 | skb_reserve(sb, NS_AAL0_HEADER); |
| 1184 | push_rxbufs(card, sb); |
| 1185 | } |
| 1186 | card->sbfqc = i; |
| 1187 | process_rsq(card); |
| 1188 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1190 | /* Large buffer queue empty */ |
| 1191 | if (stat_r & NS_STAT_LFBQE) { |
| 1192 | int i; |
| 1193 | struct sk_buff *lb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1195 | writel(NS_STAT_LFBQE, card->membase + STAT); |
| 1196 | printk("nicstar%d: Large free buffer queue empty.\n", |
| 1197 | card->index); |
| 1198 | for (i = 0; i < card->lbnr.min; i++) { |
| 1199 | lb = dev_alloc_skb(NS_LGSKBSIZE); |
| 1200 | if (lb == NULL) { |
| 1201 | writel(readl(card->membase + CFG) & |
| 1202 | ~NS_CFG_EFBIE, card->membase + CFG); |
| 1203 | card->efbie = 0; |
| 1204 | break; |
| 1205 | } |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1206 | NS_PRV_BUFTYPE(lb) = BUF_LG; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1207 | skb_queue_tail(&card->lbpool.queue, lb); |
| 1208 | skb_reserve(lb, NS_SMBUFSIZE); |
| 1209 | push_rxbufs(card, lb); |
| 1210 | } |
| 1211 | card->lbfqc = i; |
| 1212 | process_rsq(card); |
| 1213 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1215 | /* Receive Status Queue is 7/8 full */ |
| 1216 | if (stat_r & NS_STAT_RSQAF) { |
| 1217 | writel(NS_STAT_RSQAF, card->membase + STAT); |
| 1218 | RXPRINTK("nicstar%d: RSQ almost full.\n", card->index); |
| 1219 | process_rsq(card); |
| 1220 | } |
| 1221 | |
| 1222 | spin_unlock_irqrestore(&card->int_lock, flags); |
| 1223 | PRINTK("nicstar%d: end of interrupt service\n", card->index); |
| 1224 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | } |
| 1226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | static int ns_open(struct atm_vcc *vcc) |
| 1228 | { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1229 | ns_dev *card; |
| 1230 | vc_map *vc; |
| 1231 | unsigned long tmpl, modl; |
| 1232 | int tcr, tcra; /* target cell rate, and absolute value */ |
| 1233 | int n = 0; /* Number of entries in the TST. Initialized to remove |
| 1234 | the compiler warning. */ |
| 1235 | u32 u32d[4]; |
| 1236 | int frscdi = 0; /* Index of the SCD. Initialized to remove the compiler |
| 1237 | warning. How I wish compilers were clever enough to |
| 1238 | tell which variables can truly be used |
| 1239 | uninitialized... */ |
| 1240 | int inuse; /* tx or rx vc already in use by another vcc */ |
| 1241 | short vpi = vcc->vpi; |
| 1242 | int vci = vcc->vci; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1244 | card = (ns_dev *) vcc->dev->dev_data; |
| 1245 | PRINTK("nicstar%d: opening vpi.vci %d.%d \n", card->index, (int)vpi, |
| 1246 | vci); |
| 1247 | if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) { |
| 1248 | PRINTK("nicstar%d: unsupported AAL.\n", card->index); |
| 1249 | return -EINVAL; |
| 1250 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1252 | vc = &(card->vcmap[vpi << card->vcibits | vci]); |
| 1253 | vcc->dev_data = vc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1255 | inuse = 0; |
| 1256 | if (vcc->qos.txtp.traffic_class != ATM_NONE && vc->tx) |
| 1257 | inuse = 1; |
| 1258 | if (vcc->qos.rxtp.traffic_class != ATM_NONE && vc->rx) |
| 1259 | inuse += 2; |
| 1260 | if (inuse) { |
| 1261 | printk("nicstar%d: %s vci already in use.\n", card->index, |
| 1262 | inuse == 1 ? "tx" : inuse == 2 ? "rx" : "tx and rx"); |
| 1263 | return -EINVAL; |
| 1264 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1266 | set_bit(ATM_VF_ADDR, &vcc->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1268 | /* NOTE: You are not allowed to modify an open connection's QOS. To change |
| 1269 | that, remove the ATM_VF_PARTIAL flag checking. There may be other changes |
| 1270 | needed to do that. */ |
| 1271 | if (!test_bit(ATM_VF_PARTIAL, &vcc->flags)) { |
| 1272 | scq_info *scq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1274 | set_bit(ATM_VF_PARTIAL, &vcc->flags); |
| 1275 | if (vcc->qos.txtp.traffic_class == ATM_CBR) { |
| 1276 | /* Check requested cell rate and availability of SCD */ |
| 1277 | if (vcc->qos.txtp.max_pcr == 0 && vcc->qos.txtp.pcr == 0 |
| 1278 | && vcc->qos.txtp.min_pcr == 0) { |
| 1279 | PRINTK |
| 1280 | ("nicstar%d: trying to open a CBR vc with cell rate = 0 \n", |
| 1281 | card->index); |
| 1282 | clear_bit(ATM_VF_PARTIAL, &vcc->flags); |
| 1283 | clear_bit(ATM_VF_ADDR, &vcc->flags); |
| 1284 | return -EINVAL; |
| 1285 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1287 | tcr = atm_pcr_goal(&(vcc->qos.txtp)); |
| 1288 | tcra = tcr >= 0 ? tcr : -tcr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1290 | PRINTK("nicstar%d: target cell rate = %d.\n", |
| 1291 | card->index, vcc->qos.txtp.max_pcr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1293 | tmpl = |
| 1294 | (unsigned long)tcra *(unsigned long) |
| 1295 | NS_TST_NUM_ENTRIES; |
| 1296 | modl = tmpl % card->max_pcr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1298 | n = (int)(tmpl / card->max_pcr); |
| 1299 | if (tcr > 0) { |
| 1300 | if (modl > 0) |
| 1301 | n++; |
| 1302 | } else if (tcr == 0) { |
| 1303 | if ((n = |
| 1304 | (card->tst_free_entries - |
| 1305 | NS_TST_RESERVED)) <= 0) { |
| 1306 | PRINTK |
| 1307 | ("nicstar%d: no CBR bandwidth free.\n", |
| 1308 | card->index); |
| 1309 | clear_bit(ATM_VF_PARTIAL, &vcc->flags); |
| 1310 | clear_bit(ATM_VF_ADDR, &vcc->flags); |
| 1311 | return -EINVAL; |
| 1312 | } |
| 1313 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1315 | if (n == 0) { |
| 1316 | printk |
| 1317 | ("nicstar%d: selected bandwidth < granularity.\n", |
| 1318 | card->index); |
| 1319 | clear_bit(ATM_VF_PARTIAL, &vcc->flags); |
| 1320 | clear_bit(ATM_VF_ADDR, &vcc->flags); |
| 1321 | return -EINVAL; |
| 1322 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1324 | if (n > (card->tst_free_entries - NS_TST_RESERVED)) { |
| 1325 | PRINTK |
| 1326 | ("nicstar%d: not enough free CBR bandwidth.\n", |
| 1327 | card->index); |
| 1328 | clear_bit(ATM_VF_PARTIAL, &vcc->flags); |
| 1329 | clear_bit(ATM_VF_ADDR, &vcc->flags); |
| 1330 | return -EINVAL; |
| 1331 | } else |
| 1332 | card->tst_free_entries -= n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1334 | XPRINTK("nicstar%d: writing %d tst entries.\n", |
| 1335 | card->index, n); |
| 1336 | for (frscdi = 0; frscdi < NS_FRSCD_NUM; frscdi++) { |
| 1337 | if (card->scd2vc[frscdi] == NULL) { |
| 1338 | card->scd2vc[frscdi] = vc; |
| 1339 | break; |
| 1340 | } |
| 1341 | } |
| 1342 | if (frscdi == NS_FRSCD_NUM) { |
| 1343 | PRINTK |
| 1344 | ("nicstar%d: no SCD available for CBR channel.\n", |
| 1345 | card->index); |
| 1346 | card->tst_free_entries += n; |
| 1347 | clear_bit(ATM_VF_PARTIAL, &vcc->flags); |
| 1348 | clear_bit(ATM_VF_ADDR, &vcc->flags); |
| 1349 | return -EBUSY; |
| 1350 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1352 | vc->cbr_scd = NS_FRSCD + frscdi * NS_FRSCD_SIZE; |
| 1353 | |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1354 | scq = get_scq(card, CBR_SCQSIZE, vc->cbr_scd); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1355 | if (scq == NULL) { |
| 1356 | PRINTK("nicstar%d: can't get fixed rate SCQ.\n", |
| 1357 | card->index); |
| 1358 | card->scd2vc[frscdi] = NULL; |
| 1359 | card->tst_free_entries += n; |
| 1360 | clear_bit(ATM_VF_PARTIAL, &vcc->flags); |
| 1361 | clear_bit(ATM_VF_ADDR, &vcc->flags); |
| 1362 | return -ENOMEM; |
| 1363 | } |
| 1364 | vc->scq = scq; |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1365 | u32d[0] = scq_virt_to_bus(scq, scq->base); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1366 | u32d[1] = (u32) 0x00000000; |
| 1367 | u32d[2] = (u32) 0xffffffff; |
| 1368 | u32d[3] = (u32) 0x00000000; |
| 1369 | ns_write_sram(card, vc->cbr_scd, u32d, 4); |
| 1370 | |
| 1371 | fill_tst(card, n, vc); |
| 1372 | } else if (vcc->qos.txtp.traffic_class == ATM_UBR) { |
| 1373 | vc->cbr_scd = 0x00000000; |
| 1374 | vc->scq = card->scq0; |
| 1375 | } |
| 1376 | |
| 1377 | if (vcc->qos.txtp.traffic_class != ATM_NONE) { |
| 1378 | vc->tx = 1; |
| 1379 | vc->tx_vcc = vcc; |
| 1380 | vc->tbd_count = 0; |
| 1381 | } |
| 1382 | if (vcc->qos.rxtp.traffic_class != ATM_NONE) { |
| 1383 | u32 status; |
| 1384 | |
| 1385 | vc->rx = 1; |
| 1386 | vc->rx_vcc = vcc; |
| 1387 | vc->rx_iov = NULL; |
| 1388 | |
| 1389 | /* Open the connection in hardware */ |
| 1390 | if (vcc->qos.aal == ATM_AAL5) |
| 1391 | status = NS_RCTE_AAL5 | NS_RCTE_CONNECTOPEN; |
| 1392 | else /* vcc->qos.aal == ATM_AAL0 */ |
| 1393 | status = NS_RCTE_AAL0 | NS_RCTE_CONNECTOPEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1394 | #ifdef RCQ_SUPPORT |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1395 | status |= NS_RCTE_RAWCELLINTEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | #endif /* RCQ_SUPPORT */ |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1397 | ns_write_sram(card, |
| 1398 | NS_RCT + |
| 1399 | (vpi << card->vcibits | vci) * |
| 1400 | NS_RCT_ENTRY_SIZE, &status, 1); |
| 1401 | } |
| 1402 | |
| 1403 | } |
| 1404 | |
| 1405 | set_bit(ATM_VF_READY, &vcc->flags); |
| 1406 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1407 | } |
| 1408 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | static void ns_close(struct atm_vcc *vcc) |
| 1410 | { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1411 | vc_map *vc; |
| 1412 | ns_dev *card; |
| 1413 | u32 data; |
| 1414 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1416 | vc = vcc->dev_data; |
| 1417 | card = vcc->dev->dev_data; |
| 1418 | PRINTK("nicstar%d: closing vpi.vci %d.%d \n", card->index, |
| 1419 | (int)vcc->vpi, vcc->vci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1421 | clear_bit(ATM_VF_READY, &vcc->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1423 | if (vcc->qos.rxtp.traffic_class != ATM_NONE) { |
| 1424 | u32 addr; |
| 1425 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1427 | addr = |
| 1428 | NS_RCT + |
| 1429 | (vcc->vpi << card->vcibits | vcc->vci) * NS_RCT_ENTRY_SIZE; |
| 1430 | spin_lock_irqsave(&card->res_lock, flags); |
| 1431 | while (CMD_BUSY(card)) ; |
| 1432 | writel(NS_CMD_CLOSE_CONNECTION | addr << 2, |
| 1433 | card->membase + CMD); |
| 1434 | spin_unlock_irqrestore(&card->res_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1436 | vc->rx = 0; |
| 1437 | if (vc->rx_iov != NULL) { |
| 1438 | struct sk_buff *iovb; |
| 1439 | u32 stat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1441 | stat = readl(card->membase + STAT); |
| 1442 | card->sbfqc = ns_stat_sfbqc_get(stat); |
| 1443 | card->lbfqc = ns_stat_lfbqc_get(stat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1445 | PRINTK |
| 1446 | ("nicstar%d: closing a VC with pending rx buffers.\n", |
| 1447 | card->index); |
| 1448 | iovb = vc->rx_iov; |
| 1449 | recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data, |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1450 | NS_PRV_IOVCNT(iovb)); |
| 1451 | NS_PRV_IOVCNT(iovb) = 0; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1452 | spin_lock_irqsave(&card->int_lock, flags); |
| 1453 | recycle_iov_buf(card, iovb); |
| 1454 | spin_unlock_irqrestore(&card->int_lock, flags); |
| 1455 | vc->rx_iov = NULL; |
| 1456 | } |
| 1457 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1459 | if (vcc->qos.txtp.traffic_class != ATM_NONE) { |
| 1460 | vc->tx = 0; |
| 1461 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1463 | if (vcc->qos.txtp.traffic_class == ATM_CBR) { |
| 1464 | unsigned long flags; |
| 1465 | ns_scqe *scqep; |
| 1466 | scq_info *scq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1468 | scq = vc->scq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1470 | for (;;) { |
| 1471 | spin_lock_irqsave(&scq->lock, flags); |
| 1472 | scqep = scq->next; |
| 1473 | if (scqep == scq->base) |
| 1474 | scqep = scq->last; |
| 1475 | else |
| 1476 | scqep--; |
| 1477 | if (scqep == scq->tail) { |
| 1478 | spin_unlock_irqrestore(&scq->lock, flags); |
| 1479 | break; |
| 1480 | } |
| 1481 | /* If the last entry is not a TSR, place one in the SCQ in order to |
| 1482 | be able to completely drain it and then close. */ |
| 1483 | if (!ns_scqe_is_tsr(scqep) && scq->tail != scq->next) { |
| 1484 | ns_scqe tsr; |
| 1485 | u32 scdi, scqi; |
| 1486 | u32 data; |
| 1487 | int index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1489 | tsr.word_1 = ns_tsr_mkword_1(NS_TSR_INTENABLE); |
| 1490 | scdi = (vc->cbr_scd - NS_FRSCD) / NS_FRSCD_SIZE; |
| 1491 | scqi = scq->next - scq->base; |
| 1492 | tsr.word_2 = ns_tsr_mkword_2(scdi, scqi); |
| 1493 | tsr.word_3 = 0x00000000; |
| 1494 | tsr.word_4 = 0x00000000; |
| 1495 | *scq->next = tsr; |
| 1496 | index = (int)scqi; |
| 1497 | scq->skb[index] = NULL; |
| 1498 | if (scq->next == scq->last) |
| 1499 | scq->next = scq->base; |
| 1500 | else |
| 1501 | scq->next++; |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1502 | data = scq_virt_to_bus(scq, scq->next); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1503 | ns_write_sram(card, scq->scd, &data, 1); |
| 1504 | } |
| 1505 | spin_unlock_irqrestore(&scq->lock, flags); |
| 1506 | schedule(); |
| 1507 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1509 | /* Free all TST entries */ |
| 1510 | data = NS_TST_OPCODE_VARIABLE; |
| 1511 | for (i = 0; i < NS_TST_NUM_ENTRIES; i++) { |
| 1512 | if (card->tste2vc[i] == vc) { |
| 1513 | ns_write_sram(card, card->tst_addr + i, &data, |
| 1514 | 1); |
| 1515 | card->tste2vc[i] = NULL; |
| 1516 | card->tst_free_entries++; |
| 1517 | } |
| 1518 | } |
| 1519 | |
| 1520 | card->scd2vc[(vc->cbr_scd - NS_FRSCD) / NS_FRSCD_SIZE] = NULL; |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1521 | free_scq(card, vc->scq, vcc); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | /* remove all references to vcc before deleting it */ |
| 1525 | if (vcc->qos.txtp.traffic_class != ATM_NONE) { |
| 1526 | unsigned long flags; |
| 1527 | scq_info *scq = card->scq0; |
| 1528 | |
| 1529 | spin_lock_irqsave(&scq->lock, flags); |
| 1530 | |
| 1531 | for (i = 0; i < scq->num_entries; i++) { |
| 1532 | if (scq->skb[i] && ATM_SKB(scq->skb[i])->vcc == vcc) { |
| 1533 | ATM_SKB(scq->skb[i])->vcc = NULL; |
| 1534 | atm_return(vcc, scq->skb[i]->truesize); |
| 1535 | PRINTK |
| 1536 | ("nicstar: deleted pending vcc mapping\n"); |
| 1537 | } |
| 1538 | } |
| 1539 | |
| 1540 | spin_unlock_irqrestore(&scq->lock, flags); |
| 1541 | } |
| 1542 | |
| 1543 | vcc->dev_data = NULL; |
| 1544 | clear_bit(ATM_VF_PARTIAL, &vcc->flags); |
| 1545 | clear_bit(ATM_VF_ADDR, &vcc->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1546 | |
| 1547 | #ifdef RX_DEBUG |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1548 | { |
| 1549 | u32 stat, cfg; |
| 1550 | stat = readl(card->membase + STAT); |
| 1551 | cfg = readl(card->membase + CFG); |
| 1552 | printk("STAT = 0x%08X CFG = 0x%08X \n", stat, cfg); |
| 1553 | printk |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1554 | ("TSQ: base = 0x%p next = 0x%p last = 0x%p TSQT = 0x%08X \n", |
| 1555 | card->tsq.base, card->tsq.next, |
| 1556 | card->tsq.last, readl(card->membase + TSQT)); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1557 | printk |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1558 | ("RSQ: base = 0x%p next = 0x%p last = 0x%p RSQT = 0x%08X \n", |
| 1559 | card->rsq.base, card->rsq.next, |
| 1560 | card->rsq.last, readl(card->membase + RSQT)); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1561 | printk("Empty free buffer queue interrupt %s \n", |
| 1562 | card->efbie ? "enabled" : "disabled"); |
| 1563 | printk("SBCNT = %d count = %d LBCNT = %d count = %d \n", |
| 1564 | ns_stat_sfbqc_get(stat), card->sbpool.count, |
| 1565 | ns_stat_lfbqc_get(stat), card->lbpool.count); |
| 1566 | printk("hbpool.count = %d iovpool.count = %d \n", |
| 1567 | card->hbpool.count, card->iovpool.count); |
| 1568 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | #endif /* RX_DEBUG */ |
| 1570 | } |
| 1571 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1572 | static void fill_tst(ns_dev * card, int n, vc_map * vc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1574 | u32 new_tst; |
| 1575 | unsigned long cl; |
| 1576 | int e, r; |
| 1577 | u32 data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1579 | /* It would be very complicated to keep the two TSTs synchronized while |
| 1580 | assuring that writes are only made to the inactive TST. So, for now I |
| 1581 | will use only one TST. If problems occur, I will change this again */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1583 | new_tst = card->tst_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1585 | /* Fill procedure */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1587 | for (e = 0; e < NS_TST_NUM_ENTRIES; e++) { |
| 1588 | if (card->tste2vc[e] == NULL) |
| 1589 | break; |
| 1590 | } |
| 1591 | if (e == NS_TST_NUM_ENTRIES) { |
| 1592 | printk("nicstar%d: No free TST entries found. \n", card->index); |
| 1593 | return; |
| 1594 | } |
| 1595 | |
| 1596 | r = n; |
| 1597 | cl = NS_TST_NUM_ENTRIES; |
| 1598 | data = ns_tste_make(NS_TST_OPCODE_FIXED, vc->cbr_scd); |
| 1599 | |
| 1600 | while (r > 0) { |
| 1601 | if (cl >= NS_TST_NUM_ENTRIES && card->tste2vc[e] == NULL) { |
| 1602 | card->tste2vc[e] = vc; |
| 1603 | ns_write_sram(card, new_tst + e, &data, 1); |
| 1604 | cl -= NS_TST_NUM_ENTRIES; |
| 1605 | r--; |
| 1606 | } |
| 1607 | |
| 1608 | if (++e == NS_TST_NUM_ENTRIES) { |
| 1609 | e = 0; |
| 1610 | } |
| 1611 | cl += n; |
| 1612 | } |
| 1613 | |
| 1614 | /* End of fill procedure */ |
| 1615 | |
| 1616 | data = ns_tste_make(NS_TST_OPCODE_END, new_tst); |
| 1617 | ns_write_sram(card, new_tst + NS_TST_NUM_ENTRIES, &data, 1); |
| 1618 | ns_write_sram(card, card->tst_addr + NS_TST_NUM_ENTRIES, &data, 1); |
| 1619 | card->tst_addr = new_tst; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1620 | } |
| 1621 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb) |
| 1623 | { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1624 | ns_dev *card; |
| 1625 | vc_map *vc; |
| 1626 | scq_info *scq; |
| 1627 | unsigned long buflen; |
| 1628 | ns_scqe scqe; |
| 1629 | u32 flags; /* TBD flags, not CPU flags */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1630 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1631 | card = vcc->dev->dev_data; |
| 1632 | TXPRINTK("nicstar%d: ns_send() called.\n", card->index); |
| 1633 | if ((vc = (vc_map *) vcc->dev_data) == NULL) { |
| 1634 | printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n", |
| 1635 | card->index); |
| 1636 | atomic_inc(&vcc->stats->tx_err); |
| 1637 | dev_kfree_skb_any(skb); |
| 1638 | return -EINVAL; |
| 1639 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1641 | if (!vc->tx) { |
| 1642 | printk("nicstar%d: Trying to transmit on a non-tx VC.\n", |
| 1643 | card->index); |
| 1644 | atomic_inc(&vcc->stats->tx_err); |
| 1645 | dev_kfree_skb_any(skb); |
| 1646 | return -EINVAL; |
| 1647 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1649 | if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) { |
| 1650 | printk("nicstar%d: Only AAL0 and AAL5 are supported.\n", |
| 1651 | card->index); |
| 1652 | atomic_inc(&vcc->stats->tx_err); |
| 1653 | dev_kfree_skb_any(skb); |
| 1654 | return -EINVAL; |
| 1655 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1657 | if (skb_shinfo(skb)->nr_frags != 0) { |
| 1658 | printk("nicstar%d: No scatter-gather yet.\n", card->index); |
| 1659 | atomic_inc(&vcc->stats->tx_err); |
| 1660 | dev_kfree_skb_any(skb); |
| 1661 | return -EINVAL; |
| 1662 | } |
| 1663 | |
| 1664 | ATM_SKB(skb)->vcc = vcc; |
| 1665 | |
chas williams - CONTRACTOR | ede58ef | 2015-01-16 08:57:21 -0500 | [diff] [blame] | 1666 | NS_PRV_DMA(skb) = dma_map_single(&card->pcidev->dev, skb->data, |
| 1667 | skb->len, DMA_TO_DEVICE); |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1668 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1669 | if (vcc->qos.aal == ATM_AAL5) { |
| 1670 | buflen = (skb->len + 47 + 8) / 48 * 48; /* Multiple of 48 */ |
| 1671 | flags = NS_TBD_AAL5; |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1672 | scqe.word_2 = cpu_to_le32(NS_PRV_DMA(skb)); |
| 1673 | scqe.word_3 = cpu_to_le32(skb->len); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1674 | scqe.word_4 = |
| 1675 | ns_tbd_mkword_4(0, (u32) vcc->vpi, (u32) vcc->vci, 0, |
| 1676 | ATM_SKB(skb)-> |
| 1677 | atm_options & ATM_ATMOPT_CLP ? 1 : 0); |
| 1678 | flags |= NS_TBD_EOPDU; |
| 1679 | } else { /* (vcc->qos.aal == ATM_AAL0) */ |
| 1680 | |
| 1681 | buflen = ATM_CELL_PAYLOAD; /* i.e., 48 bytes */ |
| 1682 | flags = NS_TBD_AAL0; |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1683 | scqe.word_2 = cpu_to_le32(NS_PRV_DMA(skb) + NS_AAL0_HEADER); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1684 | scqe.word_3 = cpu_to_le32(0x00000000); |
| 1685 | if (*skb->data & 0x02) /* Payload type 1 - end of pdu */ |
| 1686 | flags |= NS_TBD_EOPDU; |
| 1687 | scqe.word_4 = |
| 1688 | cpu_to_le32(*((u32 *) skb->data) & ~NS_TBD_VC_MASK); |
| 1689 | /* Force the VPI/VCI to be the same as in VCC struct */ |
| 1690 | scqe.word_4 |= |
| 1691 | cpu_to_le32((((u32) vcc-> |
| 1692 | vpi) << NS_TBD_VPI_SHIFT | ((u32) vcc-> |
| 1693 | vci) << |
| 1694 | NS_TBD_VCI_SHIFT) & NS_TBD_VC_MASK); |
| 1695 | } |
| 1696 | |
| 1697 | if (vcc->qos.txtp.traffic_class == ATM_CBR) { |
| 1698 | scqe.word_1 = ns_tbd_mkword_1_novbr(flags, (u32) buflen); |
| 1699 | scq = ((vc_map *) vcc->dev_data)->scq; |
| 1700 | } else { |
| 1701 | scqe.word_1 = |
| 1702 | ns_tbd_mkword_1(flags, (u32) 1, (u32) 1, (u32) buflen); |
| 1703 | scq = card->scq0; |
| 1704 | } |
| 1705 | |
| 1706 | if (push_scqe(card, vc, scq, &scqe, skb) != 0) { |
| 1707 | atomic_inc(&vcc->stats->tx_err); |
| 1708 | dev_kfree_skb_any(skb); |
| 1709 | return -EIO; |
| 1710 | } |
| 1711 | atomic_inc(&vcc->stats->tx); |
| 1712 | |
| 1713 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | } |
| 1715 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1716 | static int push_scqe(ns_dev * card, vc_map * vc, scq_info * scq, ns_scqe * tbd, |
| 1717 | struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1719 | unsigned long flags; |
| 1720 | ns_scqe tsr; |
| 1721 | u32 scdi, scqi; |
| 1722 | int scq_is_vbr; |
| 1723 | u32 data; |
| 1724 | int index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1726 | spin_lock_irqsave(&scq->lock, flags); |
| 1727 | while (scq->tail == scq->next) { |
| 1728 | if (in_interrupt()) { |
| 1729 | spin_unlock_irqrestore(&scq->lock, flags); |
| 1730 | printk("nicstar%d: Error pushing TBD.\n", card->index); |
| 1731 | return 1; |
| 1732 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1734 | scq->full = 1; |
Arnd Bergmann | 118ce7a | 2014-02-27 19:51:54 +0100 | [diff] [blame] | 1735 | wait_event_interruptible_lock_irq_timeout(scq->scqfull_waitq, |
| 1736 | scq->tail != scq->next, |
| 1737 | scq->lock, |
| 1738 | SCQFULL_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1740 | if (scq->full) { |
| 1741 | spin_unlock_irqrestore(&scq->lock, flags); |
| 1742 | printk("nicstar%d: Timeout pushing TBD.\n", |
| 1743 | card->index); |
| 1744 | return 1; |
| 1745 | } |
| 1746 | } |
| 1747 | *scq->next = *tbd; |
| 1748 | index = (int)(scq->next - scq->base); |
| 1749 | scq->skb[index] = skb; |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1750 | XPRINTK("nicstar%d: sending skb at 0x%p (pos %d).\n", |
| 1751 | card->index, skb, index); |
| 1752 | XPRINTK("nicstar%d: TBD written:\n0x%x\n0x%x\n0x%x\n0x%x\n at 0x%p.\n", |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1753 | card->index, le32_to_cpu(tbd->word_1), le32_to_cpu(tbd->word_2), |
| 1754 | le32_to_cpu(tbd->word_3), le32_to_cpu(tbd->word_4), |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1755 | scq->next); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1756 | if (scq->next == scq->last) |
| 1757 | scq->next = scq->base; |
| 1758 | else |
| 1759 | scq->next++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1761 | vc->tbd_count++; |
| 1762 | if (scq->num_entries == VBR_SCQ_NUM_ENTRIES) { |
| 1763 | scq->tbd_count++; |
| 1764 | scq_is_vbr = 1; |
| 1765 | } else |
| 1766 | scq_is_vbr = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1767 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1768 | if (vc->tbd_count >= MAX_TBD_PER_VC |
| 1769 | || scq->tbd_count >= MAX_TBD_PER_SCQ) { |
| 1770 | int has_run = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1771 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1772 | while (scq->tail == scq->next) { |
| 1773 | if (in_interrupt()) { |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1774 | data = scq_virt_to_bus(scq, scq->next); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1775 | ns_write_sram(card, scq->scd, &data, 1); |
| 1776 | spin_unlock_irqrestore(&scq->lock, flags); |
| 1777 | printk("nicstar%d: Error pushing TSR.\n", |
| 1778 | card->index); |
| 1779 | return 0; |
| 1780 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1782 | scq->full = 1; |
| 1783 | if (has_run++) |
| 1784 | break; |
Arnd Bergmann | 118ce7a | 2014-02-27 19:51:54 +0100 | [diff] [blame] | 1785 | wait_event_interruptible_lock_irq_timeout(scq->scqfull_waitq, |
| 1786 | scq->tail != scq->next, |
| 1787 | scq->lock, |
| 1788 | SCQFULL_TIMEOUT); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1789 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1791 | if (!scq->full) { |
| 1792 | tsr.word_1 = ns_tsr_mkword_1(NS_TSR_INTENABLE); |
| 1793 | if (scq_is_vbr) |
| 1794 | scdi = NS_TSR_SCDISVBR; |
| 1795 | else |
| 1796 | scdi = (vc->cbr_scd - NS_FRSCD) / NS_FRSCD_SIZE; |
| 1797 | scqi = scq->next - scq->base; |
| 1798 | tsr.word_2 = ns_tsr_mkword_2(scdi, scqi); |
| 1799 | tsr.word_3 = 0x00000000; |
| 1800 | tsr.word_4 = 0x00000000; |
| 1801 | |
| 1802 | *scq->next = tsr; |
| 1803 | index = (int)scqi; |
| 1804 | scq->skb[index] = NULL; |
| 1805 | XPRINTK |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1806 | ("nicstar%d: TSR written:\n0x%x\n0x%x\n0x%x\n0x%x\n at 0x%p.\n", |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1807 | card->index, le32_to_cpu(tsr.word_1), |
| 1808 | le32_to_cpu(tsr.word_2), le32_to_cpu(tsr.word_3), |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1809 | le32_to_cpu(tsr.word_4), scq->next); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1810 | if (scq->next == scq->last) |
| 1811 | scq->next = scq->base; |
| 1812 | else |
| 1813 | scq->next++; |
| 1814 | vc->tbd_count = 0; |
| 1815 | scq->tbd_count = 0; |
| 1816 | } else |
| 1817 | PRINTK("nicstar%d: Timeout pushing TSR.\n", |
| 1818 | card->index); |
| 1819 | } |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1820 | data = scq_virt_to_bus(scq, scq->next); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1821 | ns_write_sram(card, scq->scd, &data, 1); |
| 1822 | |
| 1823 | spin_unlock_irqrestore(&scq->lock, flags); |
| 1824 | |
| 1825 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | } |
| 1827 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1828 | static void process_tsq(ns_dev * card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1829 | { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1830 | u32 scdi; |
| 1831 | scq_info *scq; |
| 1832 | ns_tsi *previous = NULL, *one_ahead, *two_ahead; |
| 1833 | int serviced_entries; /* flag indicating at least on entry was serviced */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1835 | serviced_entries = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1837 | if (card->tsq.next == card->tsq.last) |
| 1838 | one_ahead = card->tsq.base; |
| 1839 | else |
| 1840 | one_ahead = card->tsq.next + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1841 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1842 | if (one_ahead == card->tsq.last) |
| 1843 | two_ahead = card->tsq.base; |
| 1844 | else |
| 1845 | two_ahead = one_ahead + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1847 | while (!ns_tsi_isempty(card->tsq.next) || !ns_tsi_isempty(one_ahead) || |
| 1848 | !ns_tsi_isempty(two_ahead)) |
| 1849 | /* At most two empty, as stated in the 77201 errata */ |
| 1850 | { |
| 1851 | serviced_entries = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1853 | /* Skip the one or two possible empty entries */ |
| 1854 | while (ns_tsi_isempty(card->tsq.next)) { |
| 1855 | if (card->tsq.next == card->tsq.last) |
| 1856 | card->tsq.next = card->tsq.base; |
| 1857 | else |
| 1858 | card->tsq.next++; |
| 1859 | } |
| 1860 | |
| 1861 | if (!ns_tsi_tmrof(card->tsq.next)) { |
| 1862 | scdi = ns_tsi_getscdindex(card->tsq.next); |
| 1863 | if (scdi == NS_TSI_SCDISVBR) |
| 1864 | scq = card->scq0; |
| 1865 | else { |
| 1866 | if (card->scd2vc[scdi] == NULL) { |
| 1867 | printk |
| 1868 | ("nicstar%d: could not find VC from SCD index.\n", |
| 1869 | card->index); |
| 1870 | ns_tsi_init(card->tsq.next); |
| 1871 | return; |
| 1872 | } |
| 1873 | scq = card->scd2vc[scdi]->scq; |
| 1874 | } |
| 1875 | drain_scq(card, scq, ns_tsi_getscqpos(card->tsq.next)); |
| 1876 | scq->full = 0; |
| 1877 | wake_up_interruptible(&(scq->scqfull_waitq)); |
| 1878 | } |
| 1879 | |
| 1880 | ns_tsi_init(card->tsq.next); |
| 1881 | previous = card->tsq.next; |
| 1882 | if (card->tsq.next == card->tsq.last) |
| 1883 | card->tsq.next = card->tsq.base; |
| 1884 | else |
| 1885 | card->tsq.next++; |
| 1886 | |
| 1887 | if (card->tsq.next == card->tsq.last) |
| 1888 | one_ahead = card->tsq.base; |
| 1889 | else |
| 1890 | one_ahead = card->tsq.next + 1; |
| 1891 | |
| 1892 | if (one_ahead == card->tsq.last) |
| 1893 | two_ahead = card->tsq.base; |
| 1894 | else |
| 1895 | two_ahead = one_ahead + 1; |
| 1896 | } |
| 1897 | |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1898 | if (serviced_entries) |
| 1899 | writel(PTR_DIFF(previous, card->tsq.base), |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1900 | card->membase + TSQH); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | } |
| 1902 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1903 | static void drain_scq(ns_dev * card, scq_info * scq, int pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1904 | { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1905 | struct atm_vcc *vcc; |
| 1906 | struct sk_buff *skb; |
| 1907 | int i; |
| 1908 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1910 | XPRINTK("nicstar%d: drain_scq() called, scq at 0x%p, pos %d.\n", |
| 1911 | card->index, scq, pos); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1912 | if (pos >= scq->num_entries) { |
| 1913 | printk("nicstar%d: Bad index on drain_scq().\n", card->index); |
| 1914 | return; |
| 1915 | } |
| 1916 | |
| 1917 | spin_lock_irqsave(&scq->lock, flags); |
| 1918 | i = (int)(scq->tail - scq->base); |
| 1919 | if (++i == scq->num_entries) |
| 1920 | i = 0; |
| 1921 | while (i != pos) { |
| 1922 | skb = scq->skb[i]; |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1923 | XPRINTK("nicstar%d: freeing skb at 0x%p (index %d).\n", |
| 1924 | card->index, skb, i); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1925 | if (skb != NULL) { |
chas williams - CONTRACTOR | ede58ef | 2015-01-16 08:57:21 -0500 | [diff] [blame] | 1926 | dma_unmap_single(&card->pcidev->dev, |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1927 | NS_PRV_DMA(skb), |
| 1928 | skb->len, |
chas williams - CONTRACTOR | ede58ef | 2015-01-16 08:57:21 -0500 | [diff] [blame] | 1929 | DMA_TO_DEVICE); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1930 | vcc = ATM_SKB(skb)->vcc; |
| 1931 | if (vcc && vcc->pop != NULL) { |
| 1932 | vcc->pop(vcc, skb); |
| 1933 | } else { |
| 1934 | dev_kfree_skb_irq(skb); |
| 1935 | } |
| 1936 | scq->skb[i] = NULL; |
| 1937 | } |
| 1938 | if (++i == scq->num_entries) |
| 1939 | i = 0; |
| 1940 | } |
| 1941 | scq->tail = scq->base + pos; |
| 1942 | spin_unlock_irqrestore(&scq->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | } |
| 1944 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1945 | static void process_rsq(ns_dev * card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1947 | ns_rsqe *previous; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1949 | if (!ns_rsqe_valid(card->rsq.next)) |
| 1950 | return; |
| 1951 | do { |
| 1952 | dequeue_rx(card, card->rsq.next); |
| 1953 | ns_rsqe_init(card->rsq.next); |
| 1954 | previous = card->rsq.next; |
| 1955 | if (card->rsq.next == card->rsq.last) |
| 1956 | card->rsq.next = card->rsq.base; |
| 1957 | else |
| 1958 | card->rsq.next++; |
| 1959 | } while (ns_rsqe_valid(card->rsq.next)); |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1960 | writel(PTR_DIFF(previous, card->rsq.base), card->membase + RSQH); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | } |
| 1962 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1963 | static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1965 | u32 vpi, vci; |
| 1966 | vc_map *vc; |
| 1967 | struct sk_buff *iovb; |
| 1968 | struct iovec *iov; |
| 1969 | struct atm_vcc *vcc; |
| 1970 | struct sk_buff *skb; |
| 1971 | unsigned short aal5_len; |
| 1972 | int len; |
| 1973 | u32 stat; |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1974 | u32 id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1975 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1976 | stat = readl(card->membase + STAT); |
| 1977 | card->sbfqc = ns_stat_sfbqc_get(stat); |
| 1978 | card->lbfqc = ns_stat_lfbqc_get(stat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1979 | |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1980 | id = le32_to_cpu(rsqe->buffer_handle); |
| 1981 | skb = idr_find(&card->idr, id); |
| 1982 | if (!skb) { |
| 1983 | RXPRINTK(KERN_ERR |
| 1984 | "nicstar%d: idr_find() failed!\n", card->index); |
| 1985 | return; |
| 1986 | } |
| 1987 | idr_remove(&card->idr, id); |
chas williams - CONTRACTOR | ede58ef | 2015-01-16 08:57:21 -0500 | [diff] [blame] | 1988 | dma_sync_single_for_cpu(&card->pcidev->dev, |
| 1989 | NS_PRV_DMA(skb), |
| 1990 | (NS_PRV_BUFTYPE(skb) == BUF_SM |
| 1991 | ? NS_SMSKBSIZE : NS_LGSKBSIZE), |
| 1992 | DMA_FROM_DEVICE); |
| 1993 | dma_unmap_single(&card->pcidev->dev, |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 1994 | NS_PRV_DMA(skb), |
| 1995 | (NS_PRV_BUFTYPE(skb) == BUF_SM |
| 1996 | ? NS_SMSKBSIZE : NS_LGSKBSIZE), |
chas williams - CONTRACTOR | ede58ef | 2015-01-16 08:57:21 -0500 | [diff] [blame] | 1997 | DMA_FROM_DEVICE); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 1998 | vpi = ns_rsqe_vpi(rsqe); |
| 1999 | vci = ns_rsqe_vci(rsqe); |
| 2000 | if (vpi >= 1UL << card->vpibits || vci >= 1UL << card->vcibits) { |
| 2001 | printk("nicstar%d: SDU received for out-of-range vc %d.%d.\n", |
| 2002 | card->index, vpi, vci); |
| 2003 | recycle_rx_buf(card, skb); |
| 2004 | return; |
| 2005 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2007 | vc = &(card->vcmap[vpi << card->vcibits | vci]); |
| 2008 | if (!vc->rx) { |
| 2009 | RXPRINTK("nicstar%d: SDU received on non-rx vc %d.%d.\n", |
| 2010 | card->index, vpi, vci); |
| 2011 | recycle_rx_buf(card, skb); |
| 2012 | return; |
| 2013 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2014 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2015 | vcc = vc->rx_vcc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2017 | if (vcc->qos.aal == ATM_AAL0) { |
| 2018 | struct sk_buff *sb; |
| 2019 | unsigned char *cell; |
| 2020 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2022 | cell = skb->data; |
| 2023 | for (i = ns_rsqe_cellcount(rsqe); i; i--) { |
| 2024 | if ((sb = dev_alloc_skb(NS_SMSKBSIZE)) == NULL) { |
| 2025 | printk |
| 2026 | ("nicstar%d: Can't allocate buffers for aal0.\n", |
| 2027 | card->index); |
| 2028 | atomic_add(i, &vcc->stats->rx_drop); |
| 2029 | break; |
| 2030 | } |
| 2031 | if (!atm_charge(vcc, sb->truesize)) { |
| 2032 | RXPRINTK |
| 2033 | ("nicstar%d: atm_charge() dropped aal0 packets.\n", |
| 2034 | card->index); |
| 2035 | atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */ |
| 2036 | dev_kfree_skb_any(sb); |
| 2037 | break; |
| 2038 | } |
| 2039 | /* Rebuild the header */ |
| 2040 | *((u32 *) sb->data) = le32_to_cpu(rsqe->word_1) << 4 | |
| 2041 | (ns_rsqe_clp(rsqe) ? 0x00000001 : 0x00000000); |
| 2042 | if (i == 1 && ns_rsqe_eopdu(rsqe)) |
| 2043 | *((u32 *) sb->data) |= 0x00000002; |
| 2044 | skb_put(sb, NS_AAL0_HEADER); |
| 2045 | memcpy(skb_tail_pointer(sb), cell, ATM_CELL_PAYLOAD); |
| 2046 | skb_put(sb, ATM_CELL_PAYLOAD); |
| 2047 | ATM_SKB(sb)->vcc = vcc; |
| 2048 | __net_timestamp(sb); |
| 2049 | vcc->push(vcc, sb); |
| 2050 | atomic_inc(&vcc->stats->rx); |
| 2051 | cell += ATM_CELL_PAYLOAD; |
| 2052 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2053 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2054 | recycle_rx_buf(card, skb); |
| 2055 | return; |
| 2056 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2057 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2058 | /* To reach this point, the AAL layer can only be AAL5 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2059 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2060 | if ((iovb = vc->rx_iov) == NULL) { |
| 2061 | iovb = skb_dequeue(&(card->iovpool.queue)); |
| 2062 | if (iovb == NULL) { /* No buffers in the queue */ |
| 2063 | iovb = alloc_skb(NS_IOVBUFSIZE, GFP_ATOMIC); |
| 2064 | if (iovb == NULL) { |
| 2065 | printk("nicstar%d: Out of iovec buffers.\n", |
| 2066 | card->index); |
| 2067 | atomic_inc(&vcc->stats->rx_drop); |
| 2068 | recycle_rx_buf(card, skb); |
| 2069 | return; |
| 2070 | } |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2071 | NS_PRV_BUFTYPE(iovb) = BUF_NONE; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2072 | } else if (--card->iovpool.count < card->iovnr.min) { |
| 2073 | struct sk_buff *new_iovb; |
| 2074 | if ((new_iovb = |
| 2075 | alloc_skb(NS_IOVBUFSIZE, GFP_ATOMIC)) != NULL) { |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2076 | NS_PRV_BUFTYPE(iovb) = BUF_NONE; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2077 | skb_queue_tail(&card->iovpool.queue, new_iovb); |
| 2078 | card->iovpool.count++; |
| 2079 | } |
| 2080 | } |
| 2081 | vc->rx_iov = iovb; |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2082 | NS_PRV_IOVCNT(iovb) = 0; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2083 | iovb->len = 0; |
| 2084 | iovb->data = iovb->head; |
| 2085 | skb_reset_tail_pointer(iovb); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2086 | /* IMPORTANT: a pointer to the sk_buff containing the small or large |
| 2087 | buffer is stored as iovec base, NOT a pointer to the |
| 2088 | small or large buffer itself. */ |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2089 | } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2090 | printk("nicstar%d: received too big AAL5 SDU.\n", card->index); |
| 2091 | atomic_inc(&vcc->stats->rx_err); |
| 2092 | recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data, |
| 2093 | NS_MAX_IOVECS); |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2094 | NS_PRV_IOVCNT(iovb) = 0; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2095 | iovb->len = 0; |
| 2096 | iovb->data = iovb->head; |
| 2097 | skb_reset_tail_pointer(iovb); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2098 | } |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2099 | iov = &((struct iovec *)iovb->data)[NS_PRV_IOVCNT(iovb)++]; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2100 | iov->iov_base = (void *)skb; |
| 2101 | iov->iov_len = ns_rsqe_cellcount(rsqe) * 48; |
| 2102 | iovb->len += iov->iov_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2104 | #ifdef EXTRA_DEBUG |
| 2105 | if (NS_PRV_IOVCNT(iovb) == 1) { |
| 2106 | if (NS_PRV_BUFTYPE(skb) != BUF_SM) { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2107 | printk |
| 2108 | ("nicstar%d: Expected a small buffer, and this is not one.\n", |
| 2109 | card->index); |
| 2110 | which_list(card, skb); |
| 2111 | atomic_inc(&vcc->stats->rx_err); |
| 2112 | recycle_rx_buf(card, skb); |
| 2113 | vc->rx_iov = NULL; |
| 2114 | recycle_iov_buf(card, iovb); |
| 2115 | return; |
| 2116 | } |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2117 | } else { /* NS_PRV_IOVCNT(iovb) >= 2 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2119 | if (NS_PRV_BUFTYPE(skb) != BUF_LG) { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2120 | printk |
| 2121 | ("nicstar%d: Expected a large buffer, and this is not one.\n", |
| 2122 | card->index); |
| 2123 | which_list(card, skb); |
| 2124 | atomic_inc(&vcc->stats->rx_err); |
| 2125 | recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data, |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2126 | NS_PRV_IOVCNT(iovb)); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2127 | vc->rx_iov = NULL; |
| 2128 | recycle_iov_buf(card, iovb); |
| 2129 | return; |
| 2130 | } |
| 2131 | } |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2132 | #endif /* EXTRA_DEBUG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2133 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2134 | if (ns_rsqe_eopdu(rsqe)) { |
| 2135 | /* This works correctly regardless of the endianness of the host */ |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2136 | unsigned char *L1L2 = (unsigned char *) |
| 2137 | (skb->data + iov->iov_len - 6); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2138 | aal5_len = L1L2[0] << 8 | L1L2[1]; |
| 2139 | len = (aal5_len == 0x0000) ? 0x10000 : aal5_len; |
| 2140 | if (ns_rsqe_crcerr(rsqe) || |
| 2141 | len + 8 > iovb->len || len + (47 + 8) < iovb->len) { |
| 2142 | printk("nicstar%d: AAL5 CRC error", card->index); |
| 2143 | if (len + 8 > iovb->len || len + (47 + 8) < iovb->len) |
| 2144 | printk(" - PDU size mismatch.\n"); |
| 2145 | else |
| 2146 | printk(".\n"); |
| 2147 | atomic_inc(&vcc->stats->rx_err); |
| 2148 | recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data, |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2149 | NS_PRV_IOVCNT(iovb)); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2150 | vc->rx_iov = NULL; |
| 2151 | recycle_iov_buf(card, iovb); |
| 2152 | return; |
| 2153 | } |
| 2154 | |
| 2155 | /* By this point we (hopefully) have a complete SDU without errors. */ |
| 2156 | |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2157 | if (NS_PRV_IOVCNT(iovb) == 1) { /* Just a small buffer */ |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2158 | /* skb points to a small buffer */ |
| 2159 | if (!atm_charge(vcc, skb->truesize)) { |
| 2160 | push_rxbufs(card, skb); |
| 2161 | atomic_inc(&vcc->stats->rx_drop); |
| 2162 | } else { |
| 2163 | skb_put(skb, len); |
| 2164 | dequeue_sm_buf(card, skb); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2165 | ATM_SKB(skb)->vcc = vcc; |
| 2166 | __net_timestamp(skb); |
| 2167 | vcc->push(vcc, skb); |
| 2168 | atomic_inc(&vcc->stats->rx); |
| 2169 | } |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2170 | } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */ |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2171 | struct sk_buff *sb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2173 | sb = (struct sk_buff *)(iov - 1)->iov_base; |
| 2174 | /* skb points to a large buffer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2176 | if (len <= NS_SMBUFSIZE) { |
| 2177 | if (!atm_charge(vcc, sb->truesize)) { |
| 2178 | push_rxbufs(card, sb); |
| 2179 | atomic_inc(&vcc->stats->rx_drop); |
| 2180 | } else { |
| 2181 | skb_put(sb, len); |
| 2182 | dequeue_sm_buf(card, sb); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2183 | ATM_SKB(sb)->vcc = vcc; |
| 2184 | __net_timestamp(sb); |
| 2185 | vcc->push(vcc, sb); |
| 2186 | atomic_inc(&vcc->stats->rx); |
| 2187 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2188 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2189 | push_rxbufs(card, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2190 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2191 | } else { /* len > NS_SMBUFSIZE, the usual case */ |
| 2192 | |
| 2193 | if (!atm_charge(vcc, skb->truesize)) { |
| 2194 | push_rxbufs(card, skb); |
| 2195 | atomic_inc(&vcc->stats->rx_drop); |
| 2196 | } else { |
| 2197 | dequeue_lg_buf(card, skb); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2198 | skb_push(skb, NS_SMBUFSIZE); |
| 2199 | skb_copy_from_linear_data(sb, skb->data, |
| 2200 | NS_SMBUFSIZE); |
| 2201 | skb_put(skb, len - NS_SMBUFSIZE); |
| 2202 | ATM_SKB(skb)->vcc = vcc; |
| 2203 | __net_timestamp(skb); |
| 2204 | vcc->push(vcc, skb); |
| 2205 | atomic_inc(&vcc->stats->rx); |
| 2206 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2207 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2208 | push_rxbufs(card, sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2210 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2211 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2212 | } else { /* Must push a huge buffer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2213 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2214 | struct sk_buff *hb, *sb, *lb; |
| 2215 | int remaining, tocopy; |
| 2216 | int j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2217 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2218 | hb = skb_dequeue(&(card->hbpool.queue)); |
| 2219 | if (hb == NULL) { /* No buffers in the queue */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2221 | hb = dev_alloc_skb(NS_HBUFSIZE); |
| 2222 | if (hb == NULL) { |
| 2223 | printk |
| 2224 | ("nicstar%d: Out of huge buffers.\n", |
| 2225 | card->index); |
| 2226 | atomic_inc(&vcc->stats->rx_drop); |
| 2227 | recycle_iovec_rx_bufs(card, |
| 2228 | (struct iovec *) |
| 2229 | iovb->data, |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2230 | NS_PRV_IOVCNT(iovb)); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2231 | vc->rx_iov = NULL; |
| 2232 | recycle_iov_buf(card, iovb); |
| 2233 | return; |
| 2234 | } else if (card->hbpool.count < card->hbnr.min) { |
| 2235 | struct sk_buff *new_hb; |
| 2236 | if ((new_hb = |
| 2237 | dev_alloc_skb(NS_HBUFSIZE)) != |
| 2238 | NULL) { |
| 2239 | skb_queue_tail(&card->hbpool. |
| 2240 | queue, new_hb); |
| 2241 | card->hbpool.count++; |
| 2242 | } |
| 2243 | } |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2244 | NS_PRV_BUFTYPE(hb) = BUF_NONE; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2245 | } else if (--card->hbpool.count < card->hbnr.min) { |
| 2246 | struct sk_buff *new_hb; |
| 2247 | if ((new_hb = |
| 2248 | dev_alloc_skb(NS_HBUFSIZE)) != NULL) { |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2249 | NS_PRV_BUFTYPE(new_hb) = BUF_NONE; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2250 | skb_queue_tail(&card->hbpool.queue, |
| 2251 | new_hb); |
| 2252 | card->hbpool.count++; |
| 2253 | } |
| 2254 | if (card->hbpool.count < card->hbnr.min) { |
| 2255 | if ((new_hb = |
| 2256 | dev_alloc_skb(NS_HBUFSIZE)) != |
| 2257 | NULL) { |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2258 | NS_PRV_BUFTYPE(new_hb) = |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2259 | BUF_NONE; |
| 2260 | skb_queue_tail(&card->hbpool. |
| 2261 | queue, new_hb); |
| 2262 | card->hbpool.count++; |
| 2263 | } |
| 2264 | } |
| 2265 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2267 | iov = (struct iovec *)iovb->data; |
| 2268 | |
| 2269 | if (!atm_charge(vcc, hb->truesize)) { |
| 2270 | recycle_iovec_rx_bufs(card, iov, |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2271 | NS_PRV_IOVCNT(iovb)); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2272 | if (card->hbpool.count < card->hbnr.max) { |
| 2273 | skb_queue_tail(&card->hbpool.queue, hb); |
| 2274 | card->hbpool.count++; |
| 2275 | } else |
| 2276 | dev_kfree_skb_any(hb); |
| 2277 | atomic_inc(&vcc->stats->rx_drop); |
| 2278 | } else { |
| 2279 | /* Copy the small buffer to the huge buffer */ |
| 2280 | sb = (struct sk_buff *)iov->iov_base; |
| 2281 | skb_copy_from_linear_data(sb, hb->data, |
| 2282 | iov->iov_len); |
| 2283 | skb_put(hb, iov->iov_len); |
| 2284 | remaining = len - iov->iov_len; |
| 2285 | iov++; |
| 2286 | /* Free the small buffer */ |
| 2287 | push_rxbufs(card, sb); |
| 2288 | |
| 2289 | /* Copy all large buffers to the huge buffer and free them */ |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2290 | for (j = 1; j < NS_PRV_IOVCNT(iovb); j++) { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2291 | lb = (struct sk_buff *)iov->iov_base; |
| 2292 | tocopy = |
| 2293 | min_t(int, remaining, iov->iov_len); |
| 2294 | skb_copy_from_linear_data(lb, |
| 2295 | skb_tail_pointer |
| 2296 | (hb), tocopy); |
| 2297 | skb_put(hb, tocopy); |
| 2298 | iov++; |
| 2299 | remaining -= tocopy; |
| 2300 | push_rxbufs(card, lb); |
| 2301 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2302 | #ifdef EXTRA_DEBUG |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2303 | if (remaining != 0 || hb->len != len) |
| 2304 | printk |
| 2305 | ("nicstar%d: Huge buffer len mismatch.\n", |
| 2306 | card->index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2307 | #endif /* EXTRA_DEBUG */ |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2308 | ATM_SKB(hb)->vcc = vcc; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2309 | __net_timestamp(hb); |
| 2310 | vcc->push(vcc, hb); |
| 2311 | atomic_inc(&vcc->stats->rx); |
| 2312 | } |
| 2313 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2314 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2315 | vc->rx_iov = NULL; |
| 2316 | recycle_iov_buf(card, iovb); |
| 2317 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | |
| 2319 | } |
| 2320 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2321 | static void recycle_rx_buf(ns_dev * card, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2322 | { |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2323 | if (unlikely(NS_PRV_BUFTYPE(skb) == BUF_NONE)) { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2324 | printk("nicstar%d: What kind of rx buffer is this?\n", |
| 2325 | card->index); |
David S. Miller | 8728b83 | 2005-08-09 19:25:21 -0700 | [diff] [blame] | 2326 | dev_kfree_skb_any(skb); |
| 2327 | } else |
| 2328 | push_rxbufs(card, skb); |
| 2329 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2331 | static void recycle_iovec_rx_bufs(ns_dev * card, struct iovec *iov, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2332 | { |
David S. Miller | 8728b83 | 2005-08-09 19:25:21 -0700 | [diff] [blame] | 2333 | while (count-- > 0) |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2334 | recycle_rx_buf(card, (struct sk_buff *)(iov++)->iov_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2335 | } |
| 2336 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2337 | static void recycle_iov_buf(ns_dev * card, struct sk_buff *iovb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2338 | { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2339 | if (card->iovpool.count < card->iovnr.max) { |
| 2340 | skb_queue_tail(&card->iovpool.queue, iovb); |
| 2341 | card->iovpool.count++; |
| 2342 | } else |
| 2343 | dev_kfree_skb_any(iovb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2344 | } |
| 2345 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2346 | static void dequeue_sm_buf(ns_dev * card, struct sk_buff *sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2348 | skb_unlink(sb, &card->sbpool.queue); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2349 | if (card->sbfqc < card->sbnr.init) { |
| 2350 | struct sk_buff *new_sb; |
| 2351 | if ((new_sb = dev_alloc_skb(NS_SMSKBSIZE)) != NULL) { |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2352 | NS_PRV_BUFTYPE(new_sb) = BUF_SM; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2353 | skb_queue_tail(&card->sbpool.queue, new_sb); |
| 2354 | skb_reserve(new_sb, NS_AAL0_HEADER); |
| 2355 | push_rxbufs(card, new_sb); |
| 2356 | } |
| 2357 | } |
| 2358 | if (card->sbfqc < card->sbnr.init) |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2359 | { |
| 2360 | struct sk_buff *new_sb; |
| 2361 | if ((new_sb = dev_alloc_skb(NS_SMSKBSIZE)) != NULL) { |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2362 | NS_PRV_BUFTYPE(new_sb) = BUF_SM; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2363 | skb_queue_tail(&card->sbpool.queue, new_sb); |
| 2364 | skb_reserve(new_sb, NS_AAL0_HEADER); |
| 2365 | push_rxbufs(card, new_sb); |
| 2366 | } |
| 2367 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2368 | } |
| 2369 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2370 | static void dequeue_lg_buf(ns_dev * card, struct sk_buff *lb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2371 | { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2372 | skb_unlink(lb, &card->lbpool.queue); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2373 | if (card->lbfqc < card->lbnr.init) { |
| 2374 | struct sk_buff *new_lb; |
| 2375 | if ((new_lb = dev_alloc_skb(NS_LGSKBSIZE)) != NULL) { |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2376 | NS_PRV_BUFTYPE(new_lb) = BUF_LG; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2377 | skb_queue_tail(&card->lbpool.queue, new_lb); |
| 2378 | skb_reserve(new_lb, NS_SMBUFSIZE); |
| 2379 | push_rxbufs(card, new_lb); |
| 2380 | } |
| 2381 | } |
| 2382 | if (card->lbfqc < card->lbnr.init) |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2383 | { |
| 2384 | struct sk_buff *new_lb; |
| 2385 | if ((new_lb = dev_alloc_skb(NS_LGSKBSIZE)) != NULL) { |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2386 | NS_PRV_BUFTYPE(new_lb) = BUF_LG; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2387 | skb_queue_tail(&card->lbpool.queue, new_lb); |
| 2388 | skb_reserve(new_lb, NS_SMBUFSIZE); |
| 2389 | push_rxbufs(card, new_lb); |
| 2390 | } |
| 2391 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2392 | } |
| 2393 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2394 | static int ns_proc_read(struct atm_dev *dev, loff_t * pos, char *page) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2395 | { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2396 | u32 stat; |
| 2397 | ns_dev *card; |
| 2398 | int left; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2399 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2400 | left = (int)*pos; |
| 2401 | card = (ns_dev *) dev->dev_data; |
| 2402 | stat = readl(card->membase + STAT); |
| 2403 | if (!left--) |
| 2404 | return sprintf(page, "Pool count min init max \n"); |
| 2405 | if (!left--) |
| 2406 | return sprintf(page, "Small %5d %5d %5d %5d \n", |
| 2407 | ns_stat_sfbqc_get(stat), card->sbnr.min, |
| 2408 | card->sbnr.init, card->sbnr.max); |
| 2409 | if (!left--) |
| 2410 | return sprintf(page, "Large %5d %5d %5d %5d \n", |
| 2411 | ns_stat_lfbqc_get(stat), card->lbnr.min, |
| 2412 | card->lbnr.init, card->lbnr.max); |
| 2413 | if (!left--) |
| 2414 | return sprintf(page, "Huge %5d %5d %5d %5d \n", |
| 2415 | card->hbpool.count, card->hbnr.min, |
| 2416 | card->hbnr.init, card->hbnr.max); |
| 2417 | if (!left--) |
| 2418 | return sprintf(page, "Iovec %5d %5d %5d %5d \n", |
| 2419 | card->iovpool.count, card->iovnr.min, |
| 2420 | card->iovnr.init, card->iovnr.max); |
| 2421 | if (!left--) { |
| 2422 | int retval; |
| 2423 | retval = |
| 2424 | sprintf(page, "Interrupt counter: %u \n", card->intcnt); |
| 2425 | card->intcnt = 0; |
| 2426 | return retval; |
| 2427 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2428 | #if 0 |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2429 | /* Dump 25.6 Mbps PHY registers */ |
| 2430 | /* Now there's a 25.6 Mbps PHY driver this code isn't needed. I left it |
| 2431 | here just in case it's needed for debugging. */ |
| 2432 | if (card->max_pcr == ATM_25_PCR && !left--) { |
| 2433 | u32 phy_regs[4]; |
| 2434 | u32 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2435 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2436 | for (i = 0; i < 4; i++) { |
| 2437 | while (CMD_BUSY(card)) ; |
| 2438 | writel(NS_CMD_READ_UTILITY | 0x00000200 | i, |
| 2439 | card->membase + CMD); |
| 2440 | while (CMD_BUSY(card)) ; |
| 2441 | phy_regs[i] = readl(card->membase + DR0) & 0x000000FF; |
| 2442 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2443 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2444 | return sprintf(page, "PHY regs: 0x%02X 0x%02X 0x%02X 0x%02X \n", |
| 2445 | phy_regs[0], phy_regs[1], phy_regs[2], |
| 2446 | phy_regs[3]); |
| 2447 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2448 | #endif /* 0 - Dump 25.6 Mbps PHY registers */ |
| 2449 | #if 0 |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2450 | /* Dump TST */ |
| 2451 | if (left-- < NS_TST_NUM_ENTRIES) { |
| 2452 | if (card->tste2vc[left + 1] == NULL) |
| 2453 | return sprintf(page, "%5d - VBR/UBR \n", left + 1); |
| 2454 | else |
| 2455 | return sprintf(page, "%5d - %d %d \n", left + 1, |
| 2456 | card->tste2vc[left + 1]->tx_vcc->vpi, |
| 2457 | card->tste2vc[left + 1]->tx_vcc->vci); |
| 2458 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2459 | #endif /* 0 */ |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2460 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2461 | } |
| 2462 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2463 | static int ns_ioctl(struct atm_dev *dev, unsigned int cmd, void __user * arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2464 | { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2465 | ns_dev *card; |
| 2466 | pool_levels pl; |
| 2467 | long btype; |
| 2468 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2469 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2470 | card = dev->dev_data; |
| 2471 | switch (cmd) { |
| 2472 | case NS_GETPSTAT: |
| 2473 | if (get_user |
| 2474 | (pl.buftype, &((pool_levels __user *) arg)->buftype)) |
| 2475 | return -EFAULT; |
| 2476 | switch (pl.buftype) { |
| 2477 | case NS_BUFTYPE_SMALL: |
| 2478 | pl.count = |
| 2479 | ns_stat_sfbqc_get(readl(card->membase + STAT)); |
| 2480 | pl.level.min = card->sbnr.min; |
| 2481 | pl.level.init = card->sbnr.init; |
| 2482 | pl.level.max = card->sbnr.max; |
| 2483 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2484 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2485 | case NS_BUFTYPE_LARGE: |
| 2486 | pl.count = |
| 2487 | ns_stat_lfbqc_get(readl(card->membase + STAT)); |
| 2488 | pl.level.min = card->lbnr.min; |
| 2489 | pl.level.init = card->lbnr.init; |
| 2490 | pl.level.max = card->lbnr.max; |
| 2491 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2492 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2493 | case NS_BUFTYPE_HUGE: |
| 2494 | pl.count = card->hbpool.count; |
| 2495 | pl.level.min = card->hbnr.min; |
| 2496 | pl.level.init = card->hbnr.init; |
| 2497 | pl.level.max = card->hbnr.max; |
| 2498 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2499 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2500 | case NS_BUFTYPE_IOVEC: |
| 2501 | pl.count = card->iovpool.count; |
| 2502 | pl.level.min = card->iovnr.min; |
| 2503 | pl.level.init = card->iovnr.init; |
| 2504 | pl.level.max = card->iovnr.max; |
| 2505 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2506 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2507 | default: |
| 2508 | return -ENOIOCTLCMD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2509 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2510 | } |
| 2511 | if (!copy_to_user((pool_levels __user *) arg, &pl, sizeof(pl))) |
| 2512 | return (sizeof(pl)); |
| 2513 | else |
| 2514 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2515 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2516 | case NS_SETBUFLEV: |
| 2517 | if (!capable(CAP_NET_ADMIN)) |
| 2518 | return -EPERM; |
| 2519 | if (copy_from_user(&pl, (pool_levels __user *) arg, sizeof(pl))) |
| 2520 | return -EFAULT; |
| 2521 | if (pl.level.min >= pl.level.init |
| 2522 | || pl.level.init >= pl.level.max) |
| 2523 | return -EINVAL; |
| 2524 | if (pl.level.min == 0) |
| 2525 | return -EINVAL; |
| 2526 | switch (pl.buftype) { |
| 2527 | case NS_BUFTYPE_SMALL: |
| 2528 | if (pl.level.max > TOP_SB) |
| 2529 | return -EINVAL; |
| 2530 | card->sbnr.min = pl.level.min; |
| 2531 | card->sbnr.init = pl.level.init; |
| 2532 | card->sbnr.max = pl.level.max; |
| 2533 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2534 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2535 | case NS_BUFTYPE_LARGE: |
| 2536 | if (pl.level.max > TOP_LB) |
| 2537 | return -EINVAL; |
| 2538 | card->lbnr.min = pl.level.min; |
| 2539 | card->lbnr.init = pl.level.init; |
| 2540 | card->lbnr.max = pl.level.max; |
| 2541 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2542 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2543 | case NS_BUFTYPE_HUGE: |
| 2544 | if (pl.level.max > TOP_HB) |
| 2545 | return -EINVAL; |
| 2546 | card->hbnr.min = pl.level.min; |
| 2547 | card->hbnr.init = pl.level.init; |
| 2548 | card->hbnr.max = pl.level.max; |
| 2549 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2550 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2551 | case NS_BUFTYPE_IOVEC: |
| 2552 | if (pl.level.max > TOP_IOVB) |
| 2553 | return -EINVAL; |
| 2554 | card->iovnr.min = pl.level.min; |
| 2555 | card->iovnr.init = pl.level.init; |
| 2556 | card->iovnr.max = pl.level.max; |
| 2557 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2558 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2559 | default: |
| 2560 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2561 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2562 | } |
| 2563 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2564 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2565 | case NS_ADJBUFLEV: |
| 2566 | if (!capable(CAP_NET_ADMIN)) |
| 2567 | return -EPERM; |
| 2568 | btype = (long)arg; /* a long is the same size as a pointer or bigger */ |
| 2569 | switch (btype) { |
| 2570 | case NS_BUFTYPE_SMALL: |
| 2571 | while (card->sbfqc < card->sbnr.init) { |
| 2572 | struct sk_buff *sb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2573 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2574 | sb = __dev_alloc_skb(NS_SMSKBSIZE, GFP_KERNEL); |
| 2575 | if (sb == NULL) |
| 2576 | return -ENOMEM; |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2577 | NS_PRV_BUFTYPE(sb) = BUF_SM; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2578 | skb_queue_tail(&card->sbpool.queue, sb); |
| 2579 | skb_reserve(sb, NS_AAL0_HEADER); |
| 2580 | push_rxbufs(card, sb); |
| 2581 | } |
| 2582 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2583 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2584 | case NS_BUFTYPE_LARGE: |
| 2585 | while (card->lbfqc < card->lbnr.init) { |
| 2586 | struct sk_buff *lb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2587 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2588 | lb = __dev_alloc_skb(NS_LGSKBSIZE, GFP_KERNEL); |
| 2589 | if (lb == NULL) |
| 2590 | return -ENOMEM; |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2591 | NS_PRV_BUFTYPE(lb) = BUF_LG; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2592 | skb_queue_tail(&card->lbpool.queue, lb); |
| 2593 | skb_reserve(lb, NS_SMBUFSIZE); |
| 2594 | push_rxbufs(card, lb); |
| 2595 | } |
| 2596 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2597 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2598 | case NS_BUFTYPE_HUGE: |
| 2599 | while (card->hbpool.count > card->hbnr.init) { |
| 2600 | struct sk_buff *hb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2601 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2602 | spin_lock_irqsave(&card->int_lock, flags); |
| 2603 | hb = skb_dequeue(&card->hbpool.queue); |
| 2604 | card->hbpool.count--; |
| 2605 | spin_unlock_irqrestore(&card->int_lock, flags); |
| 2606 | if (hb == NULL) |
| 2607 | printk |
| 2608 | ("nicstar%d: huge buffer count inconsistent.\n", |
| 2609 | card->index); |
| 2610 | else |
| 2611 | dev_kfree_skb_any(hb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2612 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2613 | } |
| 2614 | while (card->hbpool.count < card->hbnr.init) { |
| 2615 | struct sk_buff *hb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2616 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2617 | hb = __dev_alloc_skb(NS_HBUFSIZE, GFP_KERNEL); |
| 2618 | if (hb == NULL) |
| 2619 | return -ENOMEM; |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2620 | NS_PRV_BUFTYPE(hb) = BUF_NONE; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2621 | spin_lock_irqsave(&card->int_lock, flags); |
| 2622 | skb_queue_tail(&card->hbpool.queue, hb); |
| 2623 | card->hbpool.count++; |
| 2624 | spin_unlock_irqrestore(&card->int_lock, flags); |
| 2625 | } |
| 2626 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2627 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2628 | case NS_BUFTYPE_IOVEC: |
| 2629 | while (card->iovpool.count > card->iovnr.init) { |
| 2630 | struct sk_buff *iovb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2631 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2632 | spin_lock_irqsave(&card->int_lock, flags); |
| 2633 | iovb = skb_dequeue(&card->iovpool.queue); |
| 2634 | card->iovpool.count--; |
| 2635 | spin_unlock_irqrestore(&card->int_lock, flags); |
| 2636 | if (iovb == NULL) |
| 2637 | printk |
| 2638 | ("nicstar%d: iovec buffer count inconsistent.\n", |
| 2639 | card->index); |
| 2640 | else |
| 2641 | dev_kfree_skb_any(iovb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2642 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2643 | } |
| 2644 | while (card->iovpool.count < card->iovnr.init) { |
| 2645 | struct sk_buff *iovb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2646 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2647 | iovb = alloc_skb(NS_IOVBUFSIZE, GFP_KERNEL); |
| 2648 | if (iovb == NULL) |
| 2649 | return -ENOMEM; |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2650 | NS_PRV_BUFTYPE(iovb) = BUF_NONE; |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2651 | spin_lock_irqsave(&card->int_lock, flags); |
| 2652 | skb_queue_tail(&card->iovpool.queue, iovb); |
| 2653 | card->iovpool.count++; |
| 2654 | spin_unlock_irqrestore(&card->int_lock, flags); |
| 2655 | } |
| 2656 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2657 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2658 | default: |
| 2659 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2660 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2661 | } |
| 2662 | return 0; |
| 2663 | |
| 2664 | default: |
| 2665 | if (dev->phy && dev->phy->ioctl) { |
| 2666 | return dev->phy->ioctl(dev, cmd, arg); |
| 2667 | } else { |
| 2668 | printk("nicstar%d: %s == NULL \n", card->index, |
| 2669 | dev->phy ? "dev->phy->ioctl" : "dev->phy"); |
| 2670 | return -ENOIOCTLCMD; |
| 2671 | } |
| 2672 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2673 | } |
| 2674 | |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2675 | #ifdef EXTRA_DEBUG |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2676 | static void which_list(ns_dev * card, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2677 | { |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2678 | printk("skb buf_type: 0x%08x\n", NS_PRV_BUFTYPE(skb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2679 | } |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2680 | #endif /* EXTRA_DEBUG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2681 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2682 | static void ns_poll(unsigned long arg) |
| 2683 | { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2684 | int i; |
| 2685 | ns_dev *card; |
| 2686 | unsigned long flags; |
| 2687 | u32 stat_r, stat_w; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2688 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2689 | PRINTK("nicstar: Entering ns_poll().\n"); |
| 2690 | for (i = 0; i < num_cards; i++) { |
| 2691 | card = cards[i]; |
| 2692 | if (spin_is_locked(&card->int_lock)) { |
| 2693 | /* Probably it isn't worth spinning */ |
| 2694 | continue; |
| 2695 | } |
| 2696 | spin_lock_irqsave(&card->int_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2697 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2698 | stat_w = 0; |
| 2699 | stat_r = readl(card->membase + STAT); |
| 2700 | if (stat_r & NS_STAT_TSIF) |
| 2701 | stat_w |= NS_STAT_TSIF; |
| 2702 | if (stat_r & NS_STAT_EOPDU) |
| 2703 | stat_w |= NS_STAT_EOPDU; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2705 | process_tsq(card); |
| 2706 | process_rsq(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2707 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2708 | writel(stat_w, card->membase + STAT); |
| 2709 | spin_unlock_irqrestore(&card->int_lock, flags); |
| 2710 | } |
| 2711 | mod_timer(&ns_timer, jiffies + NS_POLL_PERIOD); |
| 2712 | PRINTK("nicstar: Leaving ns_poll().\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2713 | } |
| 2714 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2715 | static void ns_phy_put(struct atm_dev *dev, unsigned char value, |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2716 | unsigned long addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2717 | { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2718 | ns_dev *card; |
| 2719 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2720 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2721 | card = dev->dev_data; |
| 2722 | spin_lock_irqsave(&card->res_lock, flags); |
| 2723 | while (CMD_BUSY(card)) ; |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2724 | writel((u32) value, card->membase + DR0); |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2725 | writel(NS_CMD_WRITE_UTILITY | 0x00000200 | (addr & 0x000000FF), |
| 2726 | card->membase + CMD); |
| 2727 | spin_unlock_irqrestore(&card->res_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2728 | } |
| 2729 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2730 | static unsigned char ns_phy_get(struct atm_dev *dev, unsigned long addr) |
| 2731 | { |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2732 | ns_dev *card; |
| 2733 | unsigned long flags; |
chas williams - CONTRACTOR | 864a3ff | 2010-05-29 09:04:25 +0000 | [diff] [blame] | 2734 | u32 data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | |
chas williams - CONTRACTOR | 098fde1 | 2010-05-29 09:03:44 +0000 | [diff] [blame] | 2736 | card = dev->dev_data; |
| 2737 | spin_lock_irqsave(&card->res_lock, flags); |
| 2738 | while (CMD_BUSY(card)) ; |
| 2739 | writel(NS_CMD_READ_UTILITY | 0x00000200 | (addr & 0x000000FF), |
| 2740 | card->membase + CMD); |
| 2741 | while (CMD_BUSY(card)) ; |
| 2742 | data = readl(card->membase + DR0) & 0x000000FF; |
| 2743 | spin_unlock_irqrestore(&card->res_lock, flags); |
| 2744 | return (unsigned char)data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 | } |
| 2746 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2747 | module_init(nicstar_init); |
| 2748 | module_exit(nicstar_cleanup); |