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