Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* drivers/atm/eni.c - Efficient Networks ENI155P device driver */ |
| 2 | |
| 3 | /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */ |
| 4 | |
| 5 | |
| 6 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <linux/kernel.h> |
| 8 | #include <linux/mm.h> |
| 9 | #include <linux/pci.h> |
| 10 | #include <linux/errno.h> |
| 11 | #include <linux/atm.h> |
| 12 | #include <linux/atmdev.h> |
| 13 | #include <linux/sonet.h> |
| 14 | #include <linux/skbuff.h> |
| 15 | #include <linux/time.h> |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/uio.h> |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/atm_eni.h> |
| 20 | #include <linux/bitops.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 21 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <asm/io.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 23 | #include <linux/atomic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <asm/uaccess.h> |
| 25 | #include <asm/string.h> |
| 26 | #include <asm/byteorder.h> |
| 27 | |
| 28 | #include "tonga.h" |
| 29 | #include "midway.h" |
| 30 | #include "suni.h" |
| 31 | #include "eni.h" |
| 32 | |
| 33 | #if !defined(__i386__) && !defined(__x86_64__) |
| 34 | #ifndef ioremap_nocache |
| 35 | #define ioremap_nocache(X,Y) ioremap(X,Y) |
| 36 | #endif |
| 37 | #endif |
| 38 | |
| 39 | /* |
| 40 | * TODO: |
| 41 | * |
| 42 | * Show stoppers |
| 43 | * none |
| 44 | * |
| 45 | * Minor |
| 46 | * - OAM support |
| 47 | * - fix bugs listed below |
| 48 | */ |
| 49 | |
| 50 | /* |
| 51 | * KNOWN BUGS: |
| 52 | * |
| 53 | * - may run into JK-JK bug and deadlock |
| 54 | * - should allocate UBR channel first |
| 55 | * - buffer space allocation algorithm is stupid |
| 56 | * (RX: should be maxSDU+maxdelay*rate |
| 57 | * TX: should be maxSDU+min(maxSDU,maxdelay*rate) ) |
| 58 | * - doesn't support OAM cells |
| 59 | * - eni_put_free may hang if not putting memory fragments that _complete_ |
| 60 | * 2^n block (never happens in real life, though) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | */ |
| 62 | |
| 63 | |
| 64 | #if 0 |
| 65 | #define DPRINTK(format,args...) printk(KERN_DEBUG format,##args) |
| 66 | #else |
| 67 | #define DPRINTK(format,args...) |
| 68 | #endif |
| 69 | |
| 70 | |
| 71 | #ifndef CONFIG_ATM_ENI_TUNE_BURST |
| 72 | #define CONFIG_ATM_ENI_BURST_TX_8W |
| 73 | #define CONFIG_ATM_ENI_BURST_RX_4W |
| 74 | #endif |
| 75 | |
| 76 | |
| 77 | #ifndef CONFIG_ATM_ENI_DEBUG |
| 78 | |
| 79 | |
| 80 | #define NULLCHECK(x) |
| 81 | |
| 82 | #define EVENT(s,a,b) |
| 83 | |
| 84 | |
| 85 | static void event_dump(void) |
| 86 | { |
| 87 | } |
| 88 | |
| 89 | |
| 90 | #else |
| 91 | |
| 92 | |
| 93 | /* |
| 94 | * NULL pointer checking |
| 95 | */ |
| 96 | |
| 97 | #define NULLCHECK(x) \ |
| 98 | if ((unsigned long) (x) < 0x30) \ |
| 99 | printk(KERN_CRIT #x "==0x%lx\n",(unsigned long) (x)) |
| 100 | |
| 101 | /* |
| 102 | * Very extensive activity logging. Greatly improves bug detection speed but |
| 103 | * costs a few Mbps if enabled. |
| 104 | */ |
| 105 | |
| 106 | #define EV 64 |
| 107 | |
| 108 | static const char *ev[EV]; |
| 109 | static unsigned long ev_a[EV],ev_b[EV]; |
| 110 | static int ec = 0; |
| 111 | |
| 112 | |
| 113 | static void EVENT(const char *s,unsigned long a,unsigned long b) |
| 114 | { |
| 115 | ev[ec] = s; |
| 116 | ev_a[ec] = a; |
| 117 | ev_b[ec] = b; |
| 118 | ec = (ec+1) % EV; |
| 119 | } |
| 120 | |
| 121 | |
| 122 | static void event_dump(void) |
| 123 | { |
| 124 | int n,i; |
| 125 | |
| 126 | for (n = 0; n < EV; n++) { |
| 127 | i = (ec+n) % EV; |
| 128 | printk(KERN_NOTICE); |
| 129 | printk(ev[i] ? ev[i] : "(null)",ev_a[i],ev_b[i]); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | |
| 134 | #endif /* CONFIG_ATM_ENI_DEBUG */ |
| 135 | |
| 136 | |
| 137 | /* |
| 138 | * NExx must not be equal at end |
| 139 | * EExx may be equal at end |
| 140 | * xxPJOK verify validity of pointer jumps |
| 141 | * xxPMOK operating on a circular buffer of "c" words |
| 142 | */ |
| 143 | |
| 144 | #define NEPJOK(a0,a1,b) \ |
| 145 | ((a0) < (a1) ? (b) <= (a0) || (b) > (a1) : (b) <= (a0) && (b) > (a1)) |
| 146 | #define EEPJOK(a0,a1,b) \ |
| 147 | ((a0) < (a1) ? (b) < (a0) || (b) >= (a1) : (b) < (a0) && (b) >= (a1)) |
| 148 | #define NEPMOK(a0,d,b,c) NEPJOK(a0,(a0+d) & (c-1),b) |
| 149 | #define EEPMOK(a0,d,b,c) EEPJOK(a0,(a0+d) & (c-1),b) |
| 150 | |
| 151 | |
| 152 | static int tx_complete = 0,dma_complete = 0,queued = 0,requeued = 0, |
| 153 | backlogged = 0,rx_enqueued = 0,rx_dequeued = 0,pushed = 0,submitted = 0, |
| 154 | putting = 0; |
| 155 | |
| 156 | static struct atm_dev *eni_boards = NULL; |
| 157 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | /* Read/write registers on card */ |
| 159 | #define eni_in(r) readl(eni_dev->reg+(r)*4) |
| 160 | #define eni_out(v,r) writel((v),eni_dev->reg+(r)*4) |
| 161 | |
| 162 | |
| 163 | /*-------------------------------- utilities --------------------------------*/ |
| 164 | |
| 165 | |
| 166 | static void dump_mem(struct eni_dev *eni_dev) |
| 167 | { |
| 168 | int i; |
| 169 | |
| 170 | for (i = 0; i < eni_dev->free_len; i++) |
| 171 | printk(KERN_DEBUG " %d: %p %d\n",i, |
| 172 | eni_dev->free_list[i].start, |
| 173 | 1 << eni_dev->free_list[i].order); |
| 174 | } |
| 175 | |
| 176 | |
| 177 | static void dump(struct atm_dev *dev) |
| 178 | { |
| 179 | struct eni_dev *eni_dev; |
| 180 | |
| 181 | int i; |
| 182 | |
| 183 | eni_dev = ENI_DEV(dev); |
| 184 | printk(KERN_NOTICE "Free memory\n"); |
| 185 | dump_mem(eni_dev); |
| 186 | printk(KERN_NOTICE "TX buffers\n"); |
| 187 | for (i = 0; i < NR_CHAN; i++) |
| 188 | if (eni_dev->tx[i].send) |
| 189 | printk(KERN_NOTICE " TX %d @ %p: %ld\n",i, |
| 190 | eni_dev->tx[i].send,eni_dev->tx[i].words*4); |
| 191 | printk(KERN_NOTICE "RX buffers\n"); |
| 192 | for (i = 0; i < 1024; i++) |
| 193 | if (eni_dev->rx_map[i] && ENI_VCC(eni_dev->rx_map[i])->rx) |
| 194 | printk(KERN_NOTICE " RX %d @ %p: %ld\n",i, |
| 195 | ENI_VCC(eni_dev->rx_map[i])->recv, |
| 196 | ENI_VCC(eni_dev->rx_map[i])->words*4); |
| 197 | printk(KERN_NOTICE "----\n"); |
| 198 | } |
| 199 | |
| 200 | |
| 201 | static void eni_put_free(struct eni_dev *eni_dev, void __iomem *start, |
| 202 | unsigned long size) |
| 203 | { |
| 204 | struct eni_free *list; |
| 205 | int len,order; |
| 206 | |
| 207 | DPRINTK("init 0x%lx+%ld(0x%lx)\n",start,size,size); |
| 208 | start += eni_dev->base_diff; |
| 209 | list = eni_dev->free_list; |
| 210 | len = eni_dev->free_len; |
| 211 | while (size) { |
| 212 | if (len >= eni_dev->free_list_size) { |
| 213 | printk(KERN_CRIT "eni_put_free overflow (%p,%ld)\n", |
| 214 | start,size); |
| 215 | break; |
| 216 | } |
| 217 | for (order = 0; !(((unsigned long)start | size) & (1 << order)); order++); |
| 218 | if (MID_MIN_BUF_SIZE > (1 << order)) { |
| 219 | printk(KERN_CRIT "eni_put_free: order %d too small\n", |
| 220 | order); |
| 221 | break; |
| 222 | } |
| 223 | list[len].start = (void __iomem *) start; |
| 224 | list[len].order = order; |
| 225 | len++; |
| 226 | start += 1 << order; |
| 227 | size -= 1 << order; |
| 228 | } |
| 229 | eni_dev->free_len = len; |
| 230 | /*dump_mem(eni_dev);*/ |
| 231 | } |
| 232 | |
| 233 | |
| 234 | static void __iomem *eni_alloc_mem(struct eni_dev *eni_dev, unsigned long *size) |
| 235 | { |
| 236 | struct eni_free *list; |
| 237 | void __iomem *start; |
| 238 | int len,i,order,best_order,index; |
| 239 | |
| 240 | list = eni_dev->free_list; |
| 241 | len = eni_dev->free_len; |
| 242 | if (*size < MID_MIN_BUF_SIZE) *size = MID_MIN_BUF_SIZE; |
| 243 | if (*size > MID_MAX_BUF_SIZE) return NULL; |
| 244 | for (order = 0; (1 << order) < *size; order++); |
| 245 | DPRINTK("trying: %ld->%d\n",*size,order); |
| 246 | best_order = 65; /* we don't have more than 2^64 of anything ... */ |
| 247 | index = 0; /* silence GCC */ |
| 248 | for (i = 0; i < len; i++) |
| 249 | if (list[i].order == order) { |
| 250 | best_order = order; |
| 251 | index = i; |
| 252 | break; |
| 253 | } |
| 254 | else if (best_order > list[i].order && list[i].order > order) { |
| 255 | best_order = list[i].order; |
| 256 | index = i; |
| 257 | } |
| 258 | if (best_order == 65) return NULL; |
| 259 | start = list[index].start-eni_dev->base_diff; |
| 260 | list[index] = list[--len]; |
| 261 | eni_dev->free_len = len; |
| 262 | *size = 1 << order; |
| 263 | eni_put_free(eni_dev,start+*size,(1 << best_order)-*size); |
| 264 | DPRINTK("%ld bytes (order %d) at 0x%lx\n",*size,order,start); |
| 265 | memset_io(start,0,*size); /* never leak data */ |
| 266 | /*dump_mem(eni_dev);*/ |
| 267 | return start; |
| 268 | } |
| 269 | |
| 270 | |
| 271 | static void eni_free_mem(struct eni_dev *eni_dev, void __iomem *start, |
| 272 | unsigned long size) |
| 273 | { |
| 274 | struct eni_free *list; |
| 275 | int len,i,order; |
| 276 | |
| 277 | start += eni_dev->base_diff; |
| 278 | list = eni_dev->free_list; |
| 279 | len = eni_dev->free_len; |
| 280 | for (order = -1; size; order++) size >>= 1; |
| 281 | DPRINTK("eni_free_mem: %p+0x%lx (order %d)\n",start,size,order); |
| 282 | for (i = 0; i < len; i++) |
| 283 | if (((unsigned long) list[i].start) == ((unsigned long)start^(1 << order)) && |
| 284 | list[i].order == order) { |
| 285 | DPRINTK("match[%d]: 0x%lx/0x%lx(0x%x), %d/%d\n",i, |
| 286 | list[i].start,start,1 << order,list[i].order,order); |
| 287 | list[i] = list[--len]; |
| 288 | start = (void __iomem *) ((unsigned long) start & ~(unsigned long) (1 << order)); |
| 289 | order++; |
| 290 | i = -1; |
| 291 | continue; |
| 292 | } |
| 293 | if (len >= eni_dev->free_list_size) { |
| 294 | printk(KERN_ALERT "eni_free_mem overflow (%p,%d)\n",start, |
| 295 | order); |
| 296 | return; |
| 297 | } |
| 298 | list[len].start = start; |
| 299 | list[len].order = order; |
| 300 | eni_dev->free_len = len+1; |
| 301 | /*dump_mem(eni_dev);*/ |
| 302 | } |
| 303 | |
| 304 | |
| 305 | /*----------------------------------- RX ------------------------------------*/ |
| 306 | |
| 307 | |
| 308 | #define ENI_VCC_NOS ((struct atm_vcc *) 1) |
| 309 | |
| 310 | |
| 311 | static void rx_ident_err(struct atm_vcc *vcc) |
| 312 | { |
| 313 | struct atm_dev *dev; |
| 314 | struct eni_dev *eni_dev; |
| 315 | struct eni_vcc *eni_vcc; |
| 316 | |
| 317 | dev = vcc->dev; |
| 318 | eni_dev = ENI_DEV(dev); |
| 319 | /* immediately halt adapter */ |
| 320 | eni_out(eni_in(MID_MC_S) & |
| 321 | ~(MID_DMA_ENABLE | MID_TX_ENABLE | MID_RX_ENABLE),MID_MC_S); |
| 322 | /* dump useful information */ |
| 323 | eni_vcc = ENI_VCC(vcc); |
| 324 | printk(KERN_ALERT DEV_LABEL "(itf %d): driver error - RX ident " |
| 325 | "mismatch\n",dev->number); |
| 326 | printk(KERN_ALERT " VCI %d, rxing %d, words %ld\n",vcc->vci, |
| 327 | eni_vcc->rxing,eni_vcc->words); |
| 328 | printk(KERN_ALERT " host descr 0x%lx, rx pos 0x%lx, descr value " |
| 329 | "0x%x\n",eni_vcc->descr,eni_vcc->rx_pos, |
| 330 | (unsigned) readl(eni_vcc->recv+eni_vcc->descr*4)); |
| 331 | printk(KERN_ALERT " last %p, servicing %d\n",eni_vcc->last, |
| 332 | eni_vcc->servicing); |
| 333 | EVENT("---dump ends here---\n",0,0); |
| 334 | printk(KERN_NOTICE "---recent events---\n"); |
| 335 | event_dump(); |
| 336 | ENI_DEV(dev)->fast = NULL; /* really stop it */ |
| 337 | ENI_DEV(dev)->slow = NULL; |
| 338 | skb_queue_head_init(&ENI_DEV(dev)->rx_queue); |
| 339 | } |
| 340 | |
| 341 | |
| 342 | static int do_rx_dma(struct atm_vcc *vcc,struct sk_buff *skb, |
| 343 | unsigned long skip,unsigned long size,unsigned long eff) |
| 344 | { |
| 345 | struct eni_dev *eni_dev; |
| 346 | struct eni_vcc *eni_vcc; |
| 347 | u32 dma_rd,dma_wr; |
| 348 | u32 dma[RX_DMA_BUF*2]; |
| 349 | dma_addr_t paddr; |
| 350 | unsigned long here; |
| 351 | int i,j; |
| 352 | |
| 353 | eni_dev = ENI_DEV(vcc->dev); |
| 354 | eni_vcc = ENI_VCC(vcc); |
| 355 | paddr = 0; /* GCC, shut up */ |
| 356 | if (skb) { |
| 357 | paddr = pci_map_single(eni_dev->pci_dev,skb->data,skb->len, |
| 358 | PCI_DMA_FROMDEVICE); |
| 359 | ENI_PRV_PADDR(skb) = paddr; |
| 360 | if (paddr & 3) |
| 361 | printk(KERN_CRIT DEV_LABEL "(itf %d): VCI %d has " |
| 362 | "mis-aligned RX data (0x%lx)\n",vcc->dev->number, |
| 363 | vcc->vci,(unsigned long) paddr); |
| 364 | ENI_PRV_SIZE(skb) = size+skip; |
| 365 | /* PDU plus descriptor */ |
| 366 | ATM_SKB(skb)->vcc = vcc; |
| 367 | } |
| 368 | j = 0; |
| 369 | if ((eff && skip) || 1) { /* @@@ actually, skip is always == 1 ... */ |
| 370 | here = (eni_vcc->descr+skip) & (eni_vcc->words-1); |
| 371 | dma[j++] = (here << MID_DMA_COUNT_SHIFT) | (vcc->vci |
| 372 | << MID_DMA_VCI_SHIFT) | MID_DT_JK; |
| 373 | j++; |
| 374 | } |
| 375 | here = (eni_vcc->descr+size+skip) & (eni_vcc->words-1); |
| 376 | if (!eff) size += skip; |
| 377 | else { |
| 378 | unsigned long words; |
| 379 | |
| 380 | if (!size) { |
| 381 | DPRINTK("strange things happen ...\n"); |
| 382 | EVENT("strange things happen ... (skip=%ld,eff=%ld)\n", |
| 383 | size,eff); |
| 384 | } |
| 385 | words = eff; |
| 386 | if (paddr & 15) { |
| 387 | unsigned long init; |
| 388 | |
| 389 | init = 4-((paddr & 15) >> 2); |
| 390 | if (init > words) init = words; |
| 391 | dma[j++] = MID_DT_WORD | (init << MID_DMA_COUNT_SHIFT) | |
| 392 | (vcc->vci << MID_DMA_VCI_SHIFT); |
| 393 | dma[j++] = paddr; |
| 394 | paddr += init << 2; |
| 395 | words -= init; |
| 396 | } |
| 397 | #ifdef CONFIG_ATM_ENI_BURST_RX_16W /* may work with some PCI chipsets ... */ |
| 398 | if (words & ~15) { |
| 399 | dma[j++] = MID_DT_16W | ((words >> 4) << |
| 400 | MID_DMA_COUNT_SHIFT) | (vcc->vci << |
| 401 | MID_DMA_VCI_SHIFT); |
| 402 | dma[j++] = paddr; |
| 403 | paddr += (words & ~15) << 2; |
| 404 | words &= 15; |
| 405 | } |
| 406 | #endif |
| 407 | #ifdef CONFIG_ATM_ENI_BURST_RX_8W /* works only with *some* PCI chipsets ... */ |
| 408 | if (words & ~7) { |
| 409 | dma[j++] = MID_DT_8W | ((words >> 3) << |
| 410 | MID_DMA_COUNT_SHIFT) | (vcc->vci << |
| 411 | MID_DMA_VCI_SHIFT); |
| 412 | dma[j++] = paddr; |
| 413 | paddr += (words & ~7) << 2; |
| 414 | words &= 7; |
| 415 | } |
| 416 | #endif |
| 417 | #ifdef CONFIG_ATM_ENI_BURST_RX_4W /* recommended */ |
| 418 | if (words & ~3) { |
| 419 | dma[j++] = MID_DT_4W | ((words >> 2) << |
| 420 | MID_DMA_COUNT_SHIFT) | (vcc->vci << |
| 421 | MID_DMA_VCI_SHIFT); |
| 422 | dma[j++] = paddr; |
| 423 | paddr += (words & ~3) << 2; |
| 424 | words &= 3; |
| 425 | } |
| 426 | #endif |
| 427 | #ifdef CONFIG_ATM_ENI_BURST_RX_2W /* probably useless if RX_4W, RX_8W, ... */ |
| 428 | if (words & ~1) { |
| 429 | dma[j++] = MID_DT_2W | ((words >> 1) << |
| 430 | MID_DMA_COUNT_SHIFT) | (vcc->vci << |
| 431 | MID_DMA_VCI_SHIFT); |
| 432 | dma[j++] = paddr; |
| 433 | paddr += (words & ~1) << 2; |
| 434 | words &= 1; |
| 435 | } |
| 436 | #endif |
| 437 | if (words) { |
| 438 | dma[j++] = MID_DT_WORD | (words << MID_DMA_COUNT_SHIFT) |
| 439 | | (vcc->vci << MID_DMA_VCI_SHIFT); |
| 440 | dma[j++] = paddr; |
| 441 | } |
| 442 | } |
| 443 | if (size != eff) { |
| 444 | dma[j++] = (here << MID_DMA_COUNT_SHIFT) | |
| 445 | (vcc->vci << MID_DMA_VCI_SHIFT) | MID_DT_JK; |
| 446 | j++; |
| 447 | } |
| 448 | if (!j || j > 2*RX_DMA_BUF) { |
| 449 | printk(KERN_CRIT DEV_LABEL "!j or j too big!!!\n"); |
| 450 | goto trouble; |
| 451 | } |
| 452 | dma[j-2] |= MID_DMA_END; |
| 453 | j = j >> 1; |
| 454 | dma_wr = eni_in(MID_DMA_WR_RX); |
| 455 | dma_rd = eni_in(MID_DMA_RD_RX); |
| 456 | /* |
| 457 | * Can I move the dma_wr pointer by 2j+1 positions without overwriting |
| 458 | * data that hasn't been read (position of dma_rd) yet ? |
| 459 | */ |
| 460 | if (!NEPMOK(dma_wr,j+j+1,dma_rd,NR_DMA_RX)) { /* @@@ +1 is ugly */ |
| 461 | printk(KERN_WARNING DEV_LABEL "(itf %d): RX DMA full\n", |
| 462 | vcc->dev->number); |
| 463 | goto trouble; |
| 464 | } |
| 465 | for (i = 0; i < j; i++) { |
| 466 | writel(dma[i*2],eni_dev->rx_dma+dma_wr*8); |
| 467 | writel(dma[i*2+1],eni_dev->rx_dma+dma_wr*8+4); |
| 468 | dma_wr = (dma_wr+1) & (NR_DMA_RX-1); |
| 469 | } |
| 470 | if (skb) { |
| 471 | ENI_PRV_POS(skb) = eni_vcc->descr+size+1; |
| 472 | skb_queue_tail(&eni_dev->rx_queue,skb); |
| 473 | eni_vcc->last = skb; |
| 474 | rx_enqueued++; |
| 475 | } |
| 476 | eni_vcc->descr = here; |
| 477 | eni_out(dma_wr,MID_DMA_WR_RX); |
| 478 | return 0; |
| 479 | |
| 480 | trouble: |
| 481 | if (paddr) |
| 482 | pci_unmap_single(eni_dev->pci_dev,paddr,skb->len, |
| 483 | PCI_DMA_FROMDEVICE); |
| 484 | if (skb) dev_kfree_skb_irq(skb); |
| 485 | return -1; |
| 486 | } |
| 487 | |
| 488 | |
| 489 | static void discard(struct atm_vcc *vcc,unsigned long size) |
| 490 | { |
| 491 | struct eni_vcc *eni_vcc; |
| 492 | |
| 493 | eni_vcc = ENI_VCC(vcc); |
| 494 | EVENT("discard (size=%ld)\n",size,0); |
| 495 | while (do_rx_dma(vcc,NULL,1,size,0)) EVENT("BUSY LOOP",0,0); |
| 496 | /* could do a full fallback, but that might be more expensive */ |
| 497 | if (eni_vcc->rxing) ENI_PRV_POS(eni_vcc->last) += size+1; |
| 498 | else eni_vcc->rx_pos = (eni_vcc->rx_pos+size+1) & (eni_vcc->words-1); |
| 499 | } |
| 500 | |
| 501 | |
| 502 | /* |
| 503 | * TODO: should check whether direct copies (without DMA setup, dequeuing on |
| 504 | * interrupt, etc.) aren't much faster for AAL0 |
| 505 | */ |
| 506 | |
| 507 | static int rx_aal0(struct atm_vcc *vcc) |
| 508 | { |
| 509 | struct eni_vcc *eni_vcc; |
| 510 | unsigned long descr; |
| 511 | unsigned long length; |
| 512 | struct sk_buff *skb; |
| 513 | |
| 514 | DPRINTK(">rx_aal0\n"); |
| 515 | eni_vcc = ENI_VCC(vcc); |
| 516 | descr = readl(eni_vcc->recv+eni_vcc->descr*4); |
| 517 | if ((descr & MID_RED_IDEN) != (MID_RED_RX_ID << MID_RED_SHIFT)) { |
| 518 | rx_ident_err(vcc); |
| 519 | return 1; |
| 520 | } |
| 521 | if (descr & MID_RED_T) { |
| 522 | DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n", |
| 523 | vcc->dev->number); |
| 524 | length = 0; |
| 525 | atomic_inc(&vcc->stats->rx_err); |
| 526 | } |
| 527 | else { |
| 528 | length = ATM_CELL_SIZE-1; /* no HEC */ |
| 529 | } |
| 530 | skb = length ? atm_alloc_charge(vcc,length,GFP_ATOMIC) : NULL; |
| 531 | if (!skb) { |
| 532 | discard(vcc,length >> 2); |
| 533 | return 0; |
| 534 | } |
| 535 | skb_put(skb,length); |
YOSHIFUJI Hideaki | 8570419 | 2007-03-06 20:19:26 -0800 | [diff] [blame] | 536 | skb->tstamp = eni_vcc->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | DPRINTK("got len %ld\n",length); |
| 538 | if (do_rx_dma(vcc,skb,1,length >> 2,length >> 2)) return 1; |
| 539 | eni_vcc->rxing++; |
| 540 | return 0; |
| 541 | } |
| 542 | |
| 543 | |
| 544 | static int rx_aal5(struct atm_vcc *vcc) |
| 545 | { |
| 546 | struct eni_vcc *eni_vcc; |
| 547 | unsigned long descr; |
| 548 | unsigned long size,eff,length; |
| 549 | struct sk_buff *skb; |
| 550 | |
| 551 | EVENT("rx_aal5\n",0,0); |
| 552 | DPRINTK(">rx_aal5\n"); |
| 553 | eni_vcc = ENI_VCC(vcc); |
| 554 | descr = readl(eni_vcc->recv+eni_vcc->descr*4); |
| 555 | if ((descr & MID_RED_IDEN) != (MID_RED_RX_ID << MID_RED_SHIFT)) { |
| 556 | rx_ident_err(vcc); |
| 557 | return 1; |
| 558 | } |
| 559 | if (descr & (MID_RED_T | MID_RED_CRC_ERR)) { |
| 560 | if (descr & MID_RED_T) { |
| 561 | EVENT("empty cell (descr=0x%lx)\n",descr,0); |
| 562 | DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n", |
| 563 | vcc->dev->number); |
| 564 | size = 0; |
| 565 | } |
| 566 | else { |
| 567 | static unsigned long silence = 0; |
| 568 | |
| 569 | if (time_after(jiffies, silence) || silence == 0) { |
| 570 | printk(KERN_WARNING DEV_LABEL "(itf %d): " |
| 571 | "discarding PDU(s) with CRC error\n", |
| 572 | vcc->dev->number); |
| 573 | silence = (jiffies+2*HZ)|1; |
| 574 | } |
| 575 | size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2); |
| 576 | EVENT("CRC error (descr=0x%lx,size=%ld)\n",descr, |
| 577 | size); |
| 578 | } |
| 579 | eff = length = 0; |
| 580 | atomic_inc(&vcc->stats->rx_err); |
| 581 | } |
| 582 | else { |
| 583 | size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2); |
| 584 | DPRINTK("size=%ld\n",size); |
| 585 | length = readl(eni_vcc->recv+(((eni_vcc->descr+size-1) & |
| 586 | (eni_vcc->words-1)))*4) & 0xffff; |
| 587 | /* -trailer(2)+header(1) */ |
| 588 | if (length && length <= (size << 2)-8 && length <= |
| 589 | ATM_MAX_AAL5_PDU) eff = (length+3) >> 2; |
| 590 | else { /* ^ trailer length (8) */ |
| 591 | EVENT("bad PDU (descr=0x08%lx,length=%ld)\n",descr, |
| 592 | length); |
| 593 | printk(KERN_ERR DEV_LABEL "(itf %d): bad AAL5 PDU " |
| 594 | "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n", |
| 595 | vcc->dev->number,vcc->vci,length,size << 2,descr); |
| 596 | length = eff = 0; |
| 597 | atomic_inc(&vcc->stats->rx_err); |
| 598 | } |
| 599 | } |
| 600 | skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL; |
| 601 | if (!skb) { |
| 602 | discard(vcc,size); |
| 603 | return 0; |
| 604 | } |
| 605 | skb_put(skb,length); |
| 606 | DPRINTK("got len %ld\n",length); |
| 607 | if (do_rx_dma(vcc,skb,1,size,eff)) return 1; |
| 608 | eni_vcc->rxing++; |
| 609 | return 0; |
| 610 | } |
| 611 | |
| 612 | |
| 613 | static inline int rx_vcc(struct atm_vcc *vcc) |
| 614 | { |
| 615 | void __iomem *vci_dsc; |
| 616 | unsigned long tmp; |
| 617 | struct eni_vcc *eni_vcc; |
| 618 | |
| 619 | eni_vcc = ENI_VCC(vcc); |
| 620 | vci_dsc = ENI_DEV(vcc->dev)->vci+vcc->vci*16; |
| 621 | EVENT("rx_vcc(1)\n",0,0); |
| 622 | while (eni_vcc->descr != (tmp = (readl(vci_dsc+4) & MID_VCI_DESCR) >> |
| 623 | MID_VCI_DESCR_SHIFT)) { |
| 624 | EVENT("rx_vcc(2: host dsc=0x%lx, nic dsc=0x%lx)\n", |
| 625 | eni_vcc->descr,tmp); |
| 626 | DPRINTK("CB_DESCR %ld REG_DESCR %d\n",ENI_VCC(vcc)->descr, |
| 627 | (((unsigned) readl(vci_dsc+4) & MID_VCI_DESCR) >> |
| 628 | MID_VCI_DESCR_SHIFT)); |
| 629 | if (ENI_VCC(vcc)->rx(vcc)) return 1; |
| 630 | } |
| 631 | /* clear IN_SERVICE flag */ |
| 632 | writel(readl(vci_dsc) & ~MID_VCI_IN_SERVICE,vci_dsc); |
| 633 | /* |
| 634 | * If new data has arrived between evaluating the while condition and |
| 635 | * clearing IN_SERVICE, we wouldn't be notified until additional data |
| 636 | * follows. So we have to loop again to be sure. |
| 637 | */ |
| 638 | EVENT("rx_vcc(3)\n",0,0); |
| 639 | while (ENI_VCC(vcc)->descr != (tmp = (readl(vci_dsc+4) & MID_VCI_DESCR) |
| 640 | >> MID_VCI_DESCR_SHIFT)) { |
| 641 | EVENT("rx_vcc(4: host dsc=0x%lx, nic dsc=0x%lx)\n", |
| 642 | eni_vcc->descr,tmp); |
| 643 | DPRINTK("CB_DESCR %ld REG_DESCR %d\n",ENI_VCC(vcc)->descr, |
| 644 | (((unsigned) readl(vci_dsc+4) & MID_VCI_DESCR) >> |
| 645 | MID_VCI_DESCR_SHIFT)); |
| 646 | if (ENI_VCC(vcc)->rx(vcc)) return 1; |
| 647 | } |
| 648 | return 0; |
| 649 | } |
| 650 | |
| 651 | |
| 652 | static void poll_rx(struct atm_dev *dev) |
| 653 | { |
| 654 | struct eni_dev *eni_dev; |
| 655 | struct atm_vcc *curr; |
| 656 | |
| 657 | eni_dev = ENI_DEV(dev); |
| 658 | while ((curr = eni_dev->fast)) { |
| 659 | EVENT("poll_rx.fast\n",0,0); |
| 660 | if (rx_vcc(curr)) return; |
| 661 | eni_dev->fast = ENI_VCC(curr)->next; |
| 662 | ENI_VCC(curr)->next = ENI_VCC_NOS; |
| 663 | barrier(); |
| 664 | ENI_VCC(curr)->servicing--; |
| 665 | } |
| 666 | while ((curr = eni_dev->slow)) { |
| 667 | EVENT("poll_rx.slow\n",0,0); |
| 668 | if (rx_vcc(curr)) return; |
| 669 | eni_dev->slow = ENI_VCC(curr)->next; |
| 670 | ENI_VCC(curr)->next = ENI_VCC_NOS; |
| 671 | barrier(); |
| 672 | ENI_VCC(curr)->servicing--; |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | |
| 677 | static void get_service(struct atm_dev *dev) |
| 678 | { |
| 679 | struct eni_dev *eni_dev; |
| 680 | struct atm_vcc *vcc; |
| 681 | unsigned long vci; |
| 682 | |
| 683 | DPRINTK(">get_service\n"); |
| 684 | eni_dev = ENI_DEV(dev); |
| 685 | while (eni_in(MID_SERV_WRITE) != eni_dev->serv_read) { |
| 686 | vci = readl(eni_dev->service+eni_dev->serv_read*4); |
| 687 | eni_dev->serv_read = (eni_dev->serv_read+1) & (NR_SERVICE-1); |
| 688 | vcc = eni_dev->rx_map[vci & 1023]; |
| 689 | if (!vcc) { |
| 690 | printk(KERN_CRIT DEV_LABEL "(itf %d): VCI %ld not " |
| 691 | "found\n",dev->number,vci); |
| 692 | continue; /* nasty but we try to go on anyway */ |
| 693 | /* @@@ nope, doesn't work */ |
| 694 | } |
| 695 | EVENT("getting from service\n",0,0); |
| 696 | if (ENI_VCC(vcc)->next != ENI_VCC_NOS) { |
| 697 | EVENT("double service\n",0,0); |
| 698 | DPRINTK("Grr, servicing VCC %ld twice\n",vci); |
| 699 | continue; |
| 700 | } |
YOSHIFUJI Hideaki | 8570419 | 2007-03-06 20:19:26 -0800 | [diff] [blame] | 701 | ENI_VCC(vcc)->timestamp = ktime_get_real(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | ENI_VCC(vcc)->next = NULL; |
| 703 | if (vcc->qos.rxtp.traffic_class == ATM_CBR) { |
| 704 | if (eni_dev->fast) |
| 705 | ENI_VCC(eni_dev->last_fast)->next = vcc; |
| 706 | else eni_dev->fast = vcc; |
| 707 | eni_dev->last_fast = vcc; |
| 708 | } |
| 709 | else { |
| 710 | if (eni_dev->slow) |
| 711 | ENI_VCC(eni_dev->last_slow)->next = vcc; |
| 712 | else eni_dev->slow = vcc; |
| 713 | eni_dev->last_slow = vcc; |
| 714 | } |
| 715 | putting++; |
| 716 | ENI_VCC(vcc)->servicing++; |
| 717 | } |
| 718 | } |
| 719 | |
| 720 | |
| 721 | static void dequeue_rx(struct atm_dev *dev) |
| 722 | { |
| 723 | struct eni_dev *eni_dev; |
| 724 | struct eni_vcc *eni_vcc; |
| 725 | struct atm_vcc *vcc; |
| 726 | struct sk_buff *skb; |
| 727 | void __iomem *vci_dsc; |
| 728 | int first; |
| 729 | |
| 730 | eni_dev = ENI_DEV(dev); |
| 731 | first = 1; |
| 732 | while (1) { |
| 733 | skb = skb_dequeue(&eni_dev->rx_queue); |
| 734 | if (!skb) { |
| 735 | if (first) { |
| 736 | DPRINTK(DEV_LABEL "(itf %d): RX but not " |
| 737 | "rxing\n",dev->number); |
| 738 | EVENT("nothing to dequeue\n",0,0); |
| 739 | } |
| 740 | break; |
| 741 | } |
| 742 | EVENT("dequeued (size=%ld,pos=0x%lx)\n",ENI_PRV_SIZE(skb), |
| 743 | ENI_PRV_POS(skb)); |
| 744 | rx_dequeued++; |
| 745 | vcc = ATM_SKB(skb)->vcc; |
| 746 | eni_vcc = ENI_VCC(vcc); |
| 747 | first = 0; |
| 748 | vci_dsc = eni_dev->vci+vcc->vci*16; |
| 749 | if (!EEPMOK(eni_vcc->rx_pos,ENI_PRV_SIZE(skb), |
| 750 | (readl(vci_dsc+4) & MID_VCI_READ) >> MID_VCI_READ_SHIFT, |
| 751 | eni_vcc->words)) { |
| 752 | EVENT("requeuing\n",0,0); |
| 753 | skb_queue_head(&eni_dev->rx_queue,skb); |
| 754 | break; |
| 755 | } |
| 756 | eni_vcc->rxing--; |
| 757 | eni_vcc->rx_pos = ENI_PRV_POS(skb) & (eni_vcc->words-1); |
| 758 | pci_unmap_single(eni_dev->pci_dev,ENI_PRV_PADDR(skb),skb->len, |
| 759 | PCI_DMA_TODEVICE); |
| 760 | if (!skb->len) dev_kfree_skb_irq(skb); |
| 761 | else { |
| 762 | EVENT("pushing (len=%ld)\n",skb->len,0); |
| 763 | if (vcc->qos.aal == ATM_AAL0) |
| 764 | *(unsigned long *) skb->data = |
| 765 | ntohl(*(unsigned long *) skb->data); |
| 766 | memset(skb->cb,0,sizeof(struct eni_skb_prv)); |
| 767 | vcc->push(vcc,skb); |
| 768 | pushed++; |
| 769 | } |
| 770 | atomic_inc(&vcc->stats->rx); |
| 771 | } |
| 772 | wake_up(&eni_dev->rx_wait); |
| 773 | } |
| 774 | |
| 775 | |
| 776 | static int open_rx_first(struct atm_vcc *vcc) |
| 777 | { |
| 778 | struct eni_dev *eni_dev; |
| 779 | struct eni_vcc *eni_vcc; |
| 780 | unsigned long size; |
| 781 | |
| 782 | DPRINTK("open_rx_first\n"); |
| 783 | eni_dev = ENI_DEV(vcc->dev); |
| 784 | eni_vcc = ENI_VCC(vcc); |
| 785 | eni_vcc->rx = NULL; |
| 786 | if (vcc->qos.rxtp.traffic_class == ATM_NONE) return 0; |
| 787 | size = vcc->qos.rxtp.max_sdu*eni_dev->rx_mult/100; |
| 788 | if (size > MID_MAX_BUF_SIZE && vcc->qos.rxtp.max_sdu <= |
| 789 | MID_MAX_BUF_SIZE) |
| 790 | size = MID_MAX_BUF_SIZE; |
| 791 | eni_vcc->recv = eni_alloc_mem(eni_dev,&size); |
| 792 | DPRINTK("rx at 0x%lx\n",eni_vcc->recv); |
| 793 | eni_vcc->words = size >> 2; |
| 794 | if (!eni_vcc->recv) return -ENOBUFS; |
| 795 | eni_vcc->rx = vcc->qos.aal == ATM_AAL5 ? rx_aal5 : rx_aal0; |
| 796 | eni_vcc->descr = 0; |
| 797 | eni_vcc->rx_pos = 0; |
| 798 | eni_vcc->rxing = 0; |
| 799 | eni_vcc->servicing = 0; |
| 800 | eni_vcc->next = ENI_VCC_NOS; |
| 801 | return 0; |
| 802 | } |
| 803 | |
| 804 | |
| 805 | static int open_rx_second(struct atm_vcc *vcc) |
| 806 | { |
| 807 | void __iomem *here; |
| 808 | struct eni_dev *eni_dev; |
| 809 | struct eni_vcc *eni_vcc; |
| 810 | unsigned long size; |
| 811 | int order; |
| 812 | |
| 813 | DPRINTK("open_rx_second\n"); |
| 814 | eni_dev = ENI_DEV(vcc->dev); |
| 815 | eni_vcc = ENI_VCC(vcc); |
| 816 | if (!eni_vcc->rx) return 0; |
| 817 | /* set up VCI descriptor */ |
| 818 | here = eni_dev->vci+vcc->vci*16; |
| 819 | DPRINTK("loc 0x%x\n",(unsigned) (eni_vcc->recv-eni_dev->ram)/4); |
| 820 | size = eni_vcc->words >> 8; |
| 821 | for (order = -1; size; order++) size >>= 1; |
| 822 | writel(0,here+4); /* descr, read = 0 */ |
| 823 | writel(0,here+8); /* write, state, count = 0 */ |
| 824 | if (eni_dev->rx_map[vcc->vci]) |
| 825 | printk(KERN_CRIT DEV_LABEL "(itf %d): BUG - VCI %d already " |
| 826 | "in use\n",vcc->dev->number,vcc->vci); |
| 827 | eni_dev->rx_map[vcc->vci] = vcc; /* now it counts */ |
| 828 | writel(((vcc->qos.aal != ATM_AAL5 ? MID_MODE_RAW : MID_MODE_AAL5) << |
| 829 | MID_VCI_MODE_SHIFT) | MID_VCI_PTI_MODE | |
| 830 | (((eni_vcc->recv-eni_dev->ram) >> (MID_LOC_SKIP+2)) << |
| 831 | MID_VCI_LOCATION_SHIFT) | (order << MID_VCI_SIZE_SHIFT),here); |
| 832 | return 0; |
| 833 | } |
| 834 | |
| 835 | |
| 836 | static void close_rx(struct atm_vcc *vcc) |
| 837 | { |
| 838 | DECLARE_WAITQUEUE(wait,current); |
| 839 | void __iomem *here; |
| 840 | struct eni_dev *eni_dev; |
| 841 | struct eni_vcc *eni_vcc; |
| 842 | |
| 843 | eni_vcc = ENI_VCC(vcc); |
| 844 | if (!eni_vcc->rx) return; |
| 845 | eni_dev = ENI_DEV(vcc->dev); |
| 846 | if (vcc->vpi != ATM_VPI_UNSPEC && vcc->vci != ATM_VCI_UNSPEC) { |
| 847 | here = eni_dev->vci+vcc->vci*16; |
| 848 | /* block receiver */ |
| 849 | writel((readl(here) & ~MID_VCI_MODE) | (MID_MODE_TRASH << |
| 850 | MID_VCI_MODE_SHIFT),here); |
| 851 | /* wait for receiver to become idle */ |
| 852 | udelay(27); |
| 853 | /* discard pending cell */ |
| 854 | writel(readl(here) & ~MID_VCI_IN_SERVICE,here); |
| 855 | /* don't accept any new ones */ |
| 856 | eni_dev->rx_map[vcc->vci] = NULL; |
| 857 | /* wait for RX queue to drain */ |
| 858 | DPRINTK("eni_close: waiting for RX ...\n"); |
| 859 | EVENT("RX closing\n",0,0); |
| 860 | add_wait_queue(&eni_dev->rx_wait,&wait); |
| 861 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 862 | barrier(); |
| 863 | for (;;) { |
| 864 | /* transition service->rx: rxing++, servicing-- */ |
| 865 | if (!eni_vcc->servicing) { |
| 866 | barrier(); |
| 867 | if (!eni_vcc->rxing) break; |
| 868 | } |
| 869 | EVENT("drain PDUs (rx %ld, serv %ld)\n",eni_vcc->rxing, |
| 870 | eni_vcc->servicing); |
| 871 | printk(KERN_INFO "%d+%d RX left\n",eni_vcc->servicing, |
| 872 | eni_vcc->rxing); |
| 873 | schedule(); |
| 874 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 875 | } |
| 876 | for (;;) { |
| 877 | int at_end; |
| 878 | u32 tmp; |
| 879 | |
| 880 | tasklet_disable(&eni_dev->task); |
| 881 | tmp = readl(eni_dev->vci+vcc->vci*16+4) & MID_VCI_READ; |
| 882 | at_end = eni_vcc->rx_pos == tmp >> MID_VCI_READ_SHIFT; |
| 883 | tasklet_enable(&eni_dev->task); |
| 884 | if (at_end) break; |
| 885 | EVENT("drain discard (host 0x%lx, nic 0x%lx)\n", |
| 886 | eni_vcc->rx_pos,tmp); |
| 887 | printk(KERN_INFO "draining RX: host 0x%lx, nic 0x%x\n", |
| 888 | eni_vcc->rx_pos,tmp); |
| 889 | schedule(); |
| 890 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 891 | } |
| 892 | set_current_state(TASK_RUNNING); |
| 893 | remove_wait_queue(&eni_dev->rx_wait,&wait); |
| 894 | } |
| 895 | eni_free_mem(eni_dev,eni_vcc->recv,eni_vcc->words << 2); |
| 896 | eni_vcc->rx = NULL; |
| 897 | } |
| 898 | |
| 899 | |
| 900 | static int start_rx(struct atm_dev *dev) |
| 901 | { |
| 902 | struct eni_dev *eni_dev; |
| 903 | |
| 904 | eni_dev = ENI_DEV(dev); |
| 905 | eni_dev->rx_map = (struct atm_vcc **) get_zeroed_page(GFP_KERNEL); |
| 906 | if (!eni_dev->rx_map) { |
| 907 | printk(KERN_ERR DEV_LABEL "(itf %d): couldn't get free page\n", |
| 908 | dev->number); |
| 909 | free_page((unsigned long) eni_dev->free_list); |
| 910 | return -ENOMEM; |
| 911 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | eni_dev->rx_mult = DEFAULT_RX_MULT; |
| 913 | eni_dev->fast = eni_dev->last_fast = NULL; |
| 914 | eni_dev->slow = eni_dev->last_slow = NULL; |
| 915 | init_waitqueue_head(&eni_dev->rx_wait); |
| 916 | skb_queue_head_init(&eni_dev->rx_queue); |
| 917 | eni_dev->serv_read = eni_in(MID_SERV_WRITE); |
| 918 | eni_out(0,MID_DMA_WR_RX); |
| 919 | return 0; |
| 920 | } |
| 921 | |
| 922 | |
| 923 | /*----------------------------------- TX ------------------------------------*/ |
| 924 | |
| 925 | |
| 926 | enum enq_res { enq_ok,enq_next,enq_jam }; |
| 927 | |
| 928 | |
| 929 | static inline void put_dma(int chan,u32 *dma,int *j,dma_addr_t paddr, |
| 930 | u32 size) |
| 931 | { |
| 932 | u32 init,words; |
| 933 | |
| 934 | DPRINTK("put_dma: 0x%lx+0x%x\n",(unsigned long) paddr,size); |
| 935 | EVENT("put_dma: 0x%lx+0x%lx\n",(unsigned long) paddr,size); |
| 936 | #if 0 /* don't complain anymore */ |
| 937 | if (paddr & 3) |
| 938 | printk(KERN_ERR "put_dma: unaligned addr (0x%lx)\n",paddr); |
| 939 | if (size & 3) |
| 940 | printk(KERN_ERR "put_dma: unaligned size (0x%lx)\n",size); |
| 941 | #endif |
| 942 | if (paddr & 3) { |
| 943 | init = 4-(paddr & 3); |
| 944 | if (init > size || size < 7) init = size; |
| 945 | DPRINTK("put_dma: %lx DMA: %d/%d bytes\n", |
| 946 | (unsigned long) paddr,init,size); |
| 947 | dma[(*j)++] = MID_DT_BYTE | (init << MID_DMA_COUNT_SHIFT) | |
| 948 | (chan << MID_DMA_CHAN_SHIFT); |
| 949 | dma[(*j)++] = paddr; |
| 950 | paddr += init; |
| 951 | size -= init; |
| 952 | } |
| 953 | words = size >> 2; |
| 954 | size &= 3; |
| 955 | if (words && (paddr & 31)) { |
| 956 | init = 8-((paddr & 31) >> 2); |
| 957 | if (init > words) init = words; |
| 958 | DPRINTK("put_dma: %lx DMA: %d/%d words\n", |
| 959 | (unsigned long) paddr,init,words); |
| 960 | dma[(*j)++] = MID_DT_WORD | (init << MID_DMA_COUNT_SHIFT) | |
| 961 | (chan << MID_DMA_CHAN_SHIFT); |
| 962 | dma[(*j)++] = paddr; |
| 963 | paddr += init << 2; |
| 964 | words -= init; |
| 965 | } |
| 966 | #ifdef CONFIG_ATM_ENI_BURST_TX_16W /* may work with some PCI chipsets ... */ |
| 967 | if (words & ~15) { |
| 968 | DPRINTK("put_dma: %lx DMA: %d*16/%d words\n", |
| 969 | (unsigned long) paddr,words >> 4,words); |
| 970 | dma[(*j)++] = MID_DT_16W | ((words >> 4) << MID_DMA_COUNT_SHIFT) |
| 971 | | (chan << MID_DMA_CHAN_SHIFT); |
| 972 | dma[(*j)++] = paddr; |
| 973 | paddr += (words & ~15) << 2; |
| 974 | words &= 15; |
| 975 | } |
| 976 | #endif |
| 977 | #ifdef CONFIG_ATM_ENI_BURST_TX_8W /* recommended */ |
| 978 | if (words & ~7) { |
| 979 | DPRINTK("put_dma: %lx DMA: %d*8/%d words\n", |
| 980 | (unsigned long) paddr,words >> 3,words); |
| 981 | dma[(*j)++] = MID_DT_8W | ((words >> 3) << MID_DMA_COUNT_SHIFT) |
| 982 | | (chan << MID_DMA_CHAN_SHIFT); |
| 983 | dma[(*j)++] = paddr; |
| 984 | paddr += (words & ~7) << 2; |
| 985 | words &= 7; |
| 986 | } |
| 987 | #endif |
| 988 | #ifdef CONFIG_ATM_ENI_BURST_TX_4W /* probably useless if TX_8W or TX_16W */ |
| 989 | if (words & ~3) { |
| 990 | DPRINTK("put_dma: %lx DMA: %d*4/%d words\n", |
| 991 | (unsigned long) paddr,words >> 2,words); |
| 992 | dma[(*j)++] = MID_DT_4W | ((words >> 2) << MID_DMA_COUNT_SHIFT) |
| 993 | | (chan << MID_DMA_CHAN_SHIFT); |
| 994 | dma[(*j)++] = paddr; |
| 995 | paddr += (words & ~3) << 2; |
| 996 | words &= 3; |
| 997 | } |
| 998 | #endif |
| 999 | #ifdef CONFIG_ATM_ENI_BURST_TX_2W /* probably useless if TX_4W, TX_8W, ... */ |
| 1000 | if (words & ~1) { |
| 1001 | DPRINTK("put_dma: %lx DMA: %d*2/%d words\n", |
| 1002 | (unsigned long) paddr,words >> 1,words); |
| 1003 | dma[(*j)++] = MID_DT_2W | ((words >> 1) << MID_DMA_COUNT_SHIFT) |
| 1004 | | (chan << MID_DMA_CHAN_SHIFT); |
| 1005 | dma[(*j)++] = paddr; |
| 1006 | paddr += (words & ~1) << 2; |
| 1007 | words &= 1; |
| 1008 | } |
| 1009 | #endif |
| 1010 | if (words) { |
| 1011 | DPRINTK("put_dma: %lx DMA: %d words\n",(unsigned long) paddr, |
| 1012 | words); |
| 1013 | dma[(*j)++] = MID_DT_WORD | (words << MID_DMA_COUNT_SHIFT) | |
| 1014 | (chan << MID_DMA_CHAN_SHIFT); |
| 1015 | dma[(*j)++] = paddr; |
| 1016 | paddr += words << 2; |
| 1017 | } |
| 1018 | if (size) { |
| 1019 | DPRINTK("put_dma: %lx DMA: %d bytes\n",(unsigned long) paddr, |
| 1020 | size); |
| 1021 | dma[(*j)++] = MID_DT_BYTE | (size << MID_DMA_COUNT_SHIFT) | |
| 1022 | (chan << MID_DMA_CHAN_SHIFT); |
| 1023 | dma[(*j)++] = paddr; |
| 1024 | } |
| 1025 | } |
| 1026 | |
| 1027 | |
| 1028 | static enum enq_res do_tx(struct sk_buff *skb) |
| 1029 | { |
| 1030 | struct atm_vcc *vcc; |
| 1031 | struct eni_dev *eni_dev; |
| 1032 | struct eni_vcc *eni_vcc; |
| 1033 | struct eni_tx *tx; |
| 1034 | dma_addr_t paddr; |
| 1035 | u32 dma_rd,dma_wr; |
| 1036 | u32 size; /* in words */ |
| 1037 | int aal5,dma_size,i,j; |
| 1038 | |
| 1039 | DPRINTK(">do_tx\n"); |
| 1040 | NULLCHECK(skb); |
| 1041 | EVENT("do_tx: skb=0x%lx, %ld bytes\n",(unsigned long) skb,skb->len); |
| 1042 | vcc = ATM_SKB(skb)->vcc; |
| 1043 | NULLCHECK(vcc); |
| 1044 | eni_dev = ENI_DEV(vcc->dev); |
| 1045 | NULLCHECK(eni_dev); |
| 1046 | eni_vcc = ENI_VCC(vcc); |
| 1047 | tx = eni_vcc->tx; |
| 1048 | NULLCHECK(tx); |
| 1049 | #if 0 /* Enable this for testing with the "align" program */ |
| 1050 | { |
| 1051 | unsigned int hack = *((char *) skb->data)-'0'; |
| 1052 | |
| 1053 | if (hack < 8) { |
| 1054 | skb->data += hack; |
| 1055 | skb->len -= hack; |
| 1056 | } |
| 1057 | } |
| 1058 | #endif |
| 1059 | #if 0 /* should work now */ |
| 1060 | if ((unsigned long) skb->data & 3) |
| 1061 | printk(KERN_ERR DEV_LABEL "(itf %d): VCI %d has mis-aligned " |
| 1062 | "TX data\n",vcc->dev->number,vcc->vci); |
| 1063 | #endif |
| 1064 | /* |
| 1065 | * Potential future IP speedup: make hard_header big enough to put |
| 1066 | * segmentation descriptor directly into PDU. Saves: 4 slave writes, |
| 1067 | * 1 DMA xfer & 2 DMA'ed bytes (protocol layering is for wimps :-) |
| 1068 | */ |
| 1069 | |
| 1070 | aal5 = vcc->qos.aal == ATM_AAL5; |
| 1071 | /* check space in buffer */ |
| 1072 | if (!aal5) |
| 1073 | size = (ATM_CELL_PAYLOAD >> 2)+TX_DESCR_SIZE; |
| 1074 | /* cell without HEC plus segmentation header (includes |
| 1075 | four-byte cell header) */ |
| 1076 | else { |
| 1077 | size = skb->len+4*AAL5_TRAILER+ATM_CELL_PAYLOAD-1; |
| 1078 | /* add AAL5 trailer */ |
| 1079 | size = ((size-(size % ATM_CELL_PAYLOAD)) >> 2)+TX_DESCR_SIZE; |
| 1080 | /* add segmentation header */ |
| 1081 | } |
| 1082 | /* |
| 1083 | * Can I move tx_pos by size bytes without getting closer than TX_GAP |
| 1084 | * to the read pointer ? TX_GAP means to leave some space for what |
| 1085 | * the manual calls "too close". |
| 1086 | */ |
| 1087 | if (!NEPMOK(tx->tx_pos,size+TX_GAP, |
| 1088 | eni_in(MID_TX_RDPTR(tx->index)),tx->words)) { |
| 1089 | DPRINTK(DEV_LABEL "(itf %d): TX full (size %d)\n", |
| 1090 | vcc->dev->number,size); |
| 1091 | return enq_next; |
| 1092 | } |
| 1093 | /* check DMA */ |
| 1094 | dma_wr = eni_in(MID_DMA_WR_TX); |
| 1095 | dma_rd = eni_in(MID_DMA_RD_TX); |
| 1096 | dma_size = 3; /* JK for descriptor and final fill, plus final size |
| 1097 | mis-alignment fix */ |
| 1098 | DPRINTK("iovcnt = %d\n",skb_shinfo(skb)->nr_frags); |
| 1099 | if (!skb_shinfo(skb)->nr_frags) dma_size += 5; |
| 1100 | else dma_size += 5*(skb_shinfo(skb)->nr_frags+1); |
| 1101 | if (dma_size > TX_DMA_BUF) { |
| 1102 | printk(KERN_CRIT DEV_LABEL "(itf %d): needs %d DMA entries " |
| 1103 | "(got only %d)\n",vcc->dev->number,dma_size,TX_DMA_BUF); |
| 1104 | } |
| 1105 | DPRINTK("dma_wr is %d, tx_pos is %ld\n",dma_wr,tx->tx_pos); |
| 1106 | if (dma_wr != dma_rd && ((dma_rd+NR_DMA_TX-dma_wr) & (NR_DMA_TX-1)) < |
| 1107 | dma_size) { |
| 1108 | printk(KERN_WARNING DEV_LABEL "(itf %d): TX DMA full\n", |
| 1109 | vcc->dev->number); |
| 1110 | return enq_jam; |
| 1111 | } |
| 1112 | paddr = pci_map_single(eni_dev->pci_dev,skb->data,skb->len, |
| 1113 | PCI_DMA_TODEVICE); |
| 1114 | ENI_PRV_PADDR(skb) = paddr; |
| 1115 | /* prepare DMA queue entries */ |
| 1116 | j = 0; |
| 1117 | eni_dev->dma[j++] = (((tx->tx_pos+TX_DESCR_SIZE) & (tx->words-1)) << |
| 1118 | MID_DMA_COUNT_SHIFT) | (tx->index << MID_DMA_CHAN_SHIFT) | |
| 1119 | MID_DT_JK; |
| 1120 | j++; |
| 1121 | if (!skb_shinfo(skb)->nr_frags) |
| 1122 | if (aal5) put_dma(tx->index,eni_dev->dma,&j,paddr,skb->len); |
| 1123 | else put_dma(tx->index,eni_dev->dma,&j,paddr+4,skb->len-4); |
| 1124 | else { |
| 1125 | DPRINTK("doing direct send\n"); /* @@@ well, this doesn't work anyway */ |
| 1126 | for (i = -1; i < skb_shinfo(skb)->nr_frags; i++) |
| 1127 | if (i == -1) |
| 1128 | put_dma(tx->index,eni_dev->dma,&j,(unsigned long) |
| 1129 | skb->data, |
Eric Dumazet | e743d31 | 2010-04-14 15:59:40 -0700 | [diff] [blame] | 1130 | skb_headlen(skb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | else |
| 1132 | put_dma(tx->index,eni_dev->dma,&j,(unsigned long) |
Ian Campbell | c517202 | 2011-08-24 22:28:07 +0000 | [diff] [blame] | 1133 | skb_frag_page(&skb_shinfo(skb)->frags[i]) + |
| 1134 | skb_shinfo(skb)->frags[i].page_offset, |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 1135 | skb_frag_size(&skb_shinfo(skb)->frags[i])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | } |
françois romieu | 126a3fd | 2012-03-16 01:52:04 +0000 | [diff] [blame] | 1137 | if (skb->len & 3) { |
| 1138 | put_dma(tx->index, eni_dev->dma, &j, eni_dev->zero.dma, |
| 1139 | 4 - (skb->len & 3)); |
| 1140 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | /* JK for AAL5 trailer - AAL0 doesn't need it, but who cares ... */ |
| 1142 | eni_dev->dma[j++] = (((tx->tx_pos+size) & (tx->words-1)) << |
| 1143 | MID_DMA_COUNT_SHIFT) | (tx->index << MID_DMA_CHAN_SHIFT) | |
| 1144 | MID_DMA_END | MID_DT_JK; |
| 1145 | j++; |
| 1146 | DPRINTK("DMA at end: %d\n",j); |
| 1147 | /* store frame */ |
| 1148 | writel((MID_SEG_TX_ID << MID_SEG_ID_SHIFT) | |
| 1149 | (aal5 ? MID_SEG_AAL5 : 0) | (tx->prescaler << MID_SEG_PR_SHIFT) | |
| 1150 | (tx->resolution << MID_SEG_RATE_SHIFT) | |
| 1151 | (size/(ATM_CELL_PAYLOAD/4)),tx->send+tx->tx_pos*4); |
| 1152 | /*printk("dsc = 0x%08lx\n",(unsigned long) readl(tx->send+tx->tx_pos*4));*/ |
| 1153 | writel((vcc->vci << MID_SEG_VCI_SHIFT) | |
| 1154 | (aal5 ? 0 : (skb->data[3] & 0xf)) | |
| 1155 | (ATM_SKB(skb)->atm_options & ATM_ATMOPT_CLP ? MID_SEG_CLP : 0), |
| 1156 | tx->send+((tx->tx_pos+1) & (tx->words-1))*4); |
| 1157 | DPRINTK("size: %d, len:%d\n",size,skb->len); |
| 1158 | if (aal5) |
| 1159 | writel(skb->len,tx->send+ |
| 1160 | ((tx->tx_pos+size-AAL5_TRAILER) & (tx->words-1))*4); |
| 1161 | j = j >> 1; |
| 1162 | for (i = 0; i < j; i++) { |
| 1163 | writel(eni_dev->dma[i*2],eni_dev->tx_dma+dma_wr*8); |
| 1164 | writel(eni_dev->dma[i*2+1],eni_dev->tx_dma+dma_wr*8+4); |
| 1165 | dma_wr = (dma_wr+1) & (NR_DMA_TX-1); |
| 1166 | } |
| 1167 | ENI_PRV_POS(skb) = tx->tx_pos; |
| 1168 | ENI_PRV_SIZE(skb) = size; |
| 1169 | ENI_VCC(vcc)->txing += size; |
| 1170 | tx->tx_pos = (tx->tx_pos+size) & (tx->words-1); |
| 1171 | DPRINTK("dma_wr set to %d, tx_pos is now %ld\n",dma_wr,tx->tx_pos); |
| 1172 | eni_out(dma_wr,MID_DMA_WR_TX); |
| 1173 | skb_queue_tail(&eni_dev->tx_queue,skb); |
| 1174 | queued++; |
| 1175 | return enq_ok; |
| 1176 | } |
| 1177 | |
| 1178 | |
| 1179 | static void poll_tx(struct atm_dev *dev) |
| 1180 | { |
| 1181 | struct eni_tx *tx; |
| 1182 | struct sk_buff *skb; |
| 1183 | enum enq_res res; |
| 1184 | int i; |
| 1185 | |
| 1186 | DPRINTK(">poll_tx\n"); |
| 1187 | for (i = NR_CHAN-1; i >= 0; i--) { |
| 1188 | tx = &ENI_DEV(dev)->tx[i]; |
| 1189 | if (tx->send) |
| 1190 | while ((skb = skb_dequeue(&tx->backlog))) { |
| 1191 | res = do_tx(skb); |
| 1192 | if (res == enq_ok) continue; |
| 1193 | DPRINTK("re-queuing TX PDU\n"); |
| 1194 | skb_queue_head(&tx->backlog,skb); |
| 1195 | requeued++; |
| 1196 | if (res == enq_jam) return; |
| 1197 | break; |
| 1198 | } |
| 1199 | } |
| 1200 | } |
| 1201 | |
| 1202 | |
| 1203 | static void dequeue_tx(struct atm_dev *dev) |
| 1204 | { |
| 1205 | struct eni_dev *eni_dev; |
| 1206 | struct atm_vcc *vcc; |
| 1207 | struct sk_buff *skb; |
| 1208 | struct eni_tx *tx; |
| 1209 | |
| 1210 | NULLCHECK(dev); |
| 1211 | eni_dev = ENI_DEV(dev); |
| 1212 | NULLCHECK(eni_dev); |
| 1213 | while ((skb = skb_dequeue(&eni_dev->tx_queue))) { |
| 1214 | vcc = ATM_SKB(skb)->vcc; |
| 1215 | NULLCHECK(vcc); |
| 1216 | tx = ENI_VCC(vcc)->tx; |
| 1217 | NULLCHECK(ENI_VCC(vcc)->tx); |
| 1218 | DPRINTK("dequeue_tx: next 0x%lx curr 0x%x\n",ENI_PRV_POS(skb), |
| 1219 | (unsigned) eni_in(MID_TX_DESCRSTART(tx->index))); |
| 1220 | if (ENI_VCC(vcc)->txing < tx->words && ENI_PRV_POS(skb) == |
| 1221 | eni_in(MID_TX_DESCRSTART(tx->index))) { |
| 1222 | skb_queue_head(&eni_dev->tx_queue,skb); |
| 1223 | break; |
| 1224 | } |
| 1225 | ENI_VCC(vcc)->txing -= ENI_PRV_SIZE(skb); |
| 1226 | pci_unmap_single(eni_dev->pci_dev,ENI_PRV_PADDR(skb),skb->len, |
| 1227 | PCI_DMA_TODEVICE); |
| 1228 | if (vcc->pop) vcc->pop(vcc,skb); |
| 1229 | else dev_kfree_skb_irq(skb); |
| 1230 | atomic_inc(&vcc->stats->tx); |
| 1231 | wake_up(&eni_dev->tx_wait); |
| 1232 | dma_complete++; |
| 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | |
| 1237 | static struct eni_tx *alloc_tx(struct eni_dev *eni_dev,int ubr) |
| 1238 | { |
| 1239 | int i; |
| 1240 | |
| 1241 | for (i = !ubr; i < NR_CHAN; i++) |
| 1242 | if (!eni_dev->tx[i].send) return eni_dev->tx+i; |
| 1243 | return NULL; |
| 1244 | } |
| 1245 | |
| 1246 | |
| 1247 | static int comp_tx(struct eni_dev *eni_dev,int *pcr,int reserved,int *pre, |
| 1248 | int *res,int unlimited) |
| 1249 | { |
| 1250 | static const int pre_div[] = { 4,16,128,2048 }; |
| 1251 | /* 2^(((x+2)^2-(x+2))/2+1) */ |
| 1252 | |
| 1253 | if (unlimited) *pre = *res = 0; |
| 1254 | else { |
| 1255 | if (*pcr > 0) { |
| 1256 | int div; |
| 1257 | |
| 1258 | for (*pre = 0; *pre < 3; (*pre)++) |
| 1259 | if (TS_CLOCK/pre_div[*pre]/64 <= *pcr) break; |
| 1260 | div = pre_div[*pre]**pcr; |
| 1261 | DPRINTK("min div %d\n",div); |
| 1262 | *res = TS_CLOCK/div-1; |
| 1263 | } |
| 1264 | else { |
| 1265 | int div; |
| 1266 | |
| 1267 | if (!*pcr) *pcr = eni_dev->tx_bw+reserved; |
| 1268 | for (*pre = 3; *pre >= 0; (*pre)--) |
| 1269 | if (TS_CLOCK/pre_div[*pre]/64 > -*pcr) break; |
| 1270 | if (*pre < 3) (*pre)++; /* else fail later */ |
| 1271 | div = pre_div[*pre]*-*pcr; |
| 1272 | DPRINTK("max div %d\n",div); |
Julia Lawall | 6a19309 | 2008-09-22 19:22:58 -0700 | [diff] [blame] | 1273 | *res = DIV_ROUND_UP(TS_CLOCK, div)-1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | } |
| 1275 | if (*res < 0) *res = 0; |
| 1276 | if (*res > MID_SEG_MAX_RATE) *res = MID_SEG_MAX_RATE; |
| 1277 | } |
| 1278 | *pcr = TS_CLOCK/pre_div[*pre]/(*res+1); |
| 1279 | DPRINTK("out pcr: %d (%d:%d)\n",*pcr,*pre,*res); |
| 1280 | return 0; |
| 1281 | } |
| 1282 | |
| 1283 | |
| 1284 | static int reserve_or_set_tx(struct atm_vcc *vcc,struct atm_trafprm *txtp, |
| 1285 | int set_rsv,int set_shp) |
| 1286 | { |
| 1287 | struct eni_dev *eni_dev = ENI_DEV(vcc->dev); |
| 1288 | struct eni_vcc *eni_vcc = ENI_VCC(vcc); |
| 1289 | struct eni_tx *tx; |
| 1290 | unsigned long size; |
| 1291 | void __iomem *mem; |
| 1292 | int rate,ubr,unlimited,new_tx; |
| 1293 | int pre,res,order; |
| 1294 | int error; |
| 1295 | |
| 1296 | rate = atm_pcr_goal(txtp); |
| 1297 | ubr = txtp->traffic_class == ATM_UBR; |
| 1298 | unlimited = ubr && (!rate || rate <= -ATM_OC3_PCR || |
| 1299 | rate >= ATM_OC3_PCR); |
| 1300 | if (!unlimited) { |
| 1301 | size = txtp->max_sdu*eni_dev->tx_mult/100; |
| 1302 | if (size > MID_MAX_BUF_SIZE && txtp->max_sdu <= |
| 1303 | MID_MAX_BUF_SIZE) |
| 1304 | size = MID_MAX_BUF_SIZE; |
| 1305 | } |
| 1306 | else { |
| 1307 | if (eni_dev->ubr) { |
| 1308 | eni_vcc->tx = eni_dev->ubr; |
| 1309 | txtp->pcr = ATM_OC3_PCR; |
| 1310 | return 0; |
| 1311 | } |
| 1312 | size = UBR_BUFFER; |
| 1313 | } |
| 1314 | new_tx = !eni_vcc->tx; |
| 1315 | mem = NULL; /* for gcc */ |
| 1316 | if (!new_tx) tx = eni_vcc->tx; |
| 1317 | else { |
| 1318 | mem = eni_alloc_mem(eni_dev,&size); |
| 1319 | if (!mem) return -ENOBUFS; |
| 1320 | tx = alloc_tx(eni_dev,unlimited); |
| 1321 | if (!tx) { |
| 1322 | eni_free_mem(eni_dev,mem,size); |
| 1323 | return -EBUSY; |
| 1324 | } |
| 1325 | DPRINTK("got chan %d\n",tx->index); |
| 1326 | tx->reserved = tx->shaping = 0; |
| 1327 | tx->send = mem; |
| 1328 | tx->words = size >> 2; |
| 1329 | skb_queue_head_init(&tx->backlog); |
| 1330 | for (order = 0; size > (1 << (order+10)); order++); |
| 1331 | eni_out((order << MID_SIZE_SHIFT) | |
| 1332 | ((tx->send-eni_dev->ram) >> (MID_LOC_SKIP+2)), |
| 1333 | MID_TX_PLACE(tx->index)); |
| 1334 | tx->tx_pos = eni_in(MID_TX_DESCRSTART(tx->index)) & |
| 1335 | MID_DESCR_START; |
| 1336 | } |
| 1337 | error = comp_tx(eni_dev,&rate,tx->reserved,&pre,&res,unlimited); |
| 1338 | if (!error && txtp->min_pcr > rate) error = -EINVAL; |
| 1339 | if (!error && txtp->max_pcr && txtp->max_pcr != ATM_MAX_PCR && |
| 1340 | txtp->max_pcr < rate) error = -EINVAL; |
| 1341 | if (!error && !ubr && rate > eni_dev->tx_bw+tx->reserved) |
| 1342 | error = -EINVAL; |
| 1343 | if (!error && set_rsv && !set_shp && rate < tx->shaping) |
| 1344 | error = -EINVAL; |
| 1345 | if (!error && !set_rsv && rate > tx->reserved && !ubr) |
| 1346 | error = -EINVAL; |
| 1347 | if (error) { |
| 1348 | if (new_tx) { |
| 1349 | tx->send = NULL; |
| 1350 | eni_free_mem(eni_dev,mem,size); |
| 1351 | } |
| 1352 | return error; |
| 1353 | } |
| 1354 | txtp->pcr = rate; |
| 1355 | if (set_rsv && !ubr) { |
| 1356 | eni_dev->tx_bw += tx->reserved; |
| 1357 | tx->reserved = rate; |
| 1358 | eni_dev->tx_bw -= rate; |
| 1359 | } |
| 1360 | if (set_shp || (unlimited && new_tx)) { |
| 1361 | if (unlimited && new_tx) eni_dev->ubr = tx; |
| 1362 | tx->prescaler = pre; |
| 1363 | tx->resolution = res; |
| 1364 | tx->shaping = rate; |
| 1365 | } |
| 1366 | if (set_shp) eni_vcc->tx = tx; |
| 1367 | DPRINTK("rsv %d shp %d\n",tx->reserved,tx->shaping); |
| 1368 | return 0; |
| 1369 | } |
| 1370 | |
| 1371 | |
| 1372 | static int open_tx_first(struct atm_vcc *vcc) |
| 1373 | { |
| 1374 | ENI_VCC(vcc)->tx = NULL; |
| 1375 | if (vcc->qos.txtp.traffic_class == ATM_NONE) return 0; |
| 1376 | ENI_VCC(vcc)->txing = 0; |
| 1377 | return reserve_or_set_tx(vcc,&vcc->qos.txtp,1,1); |
| 1378 | } |
| 1379 | |
| 1380 | |
| 1381 | static int open_tx_second(struct atm_vcc *vcc) |
| 1382 | { |
| 1383 | return 0; /* nothing to do */ |
| 1384 | } |
| 1385 | |
| 1386 | |
| 1387 | static void close_tx(struct atm_vcc *vcc) |
| 1388 | { |
| 1389 | DECLARE_WAITQUEUE(wait,current); |
| 1390 | struct eni_dev *eni_dev; |
| 1391 | struct eni_vcc *eni_vcc; |
| 1392 | |
| 1393 | eni_vcc = ENI_VCC(vcc); |
| 1394 | if (!eni_vcc->tx) return; |
| 1395 | eni_dev = ENI_DEV(vcc->dev); |
| 1396 | /* wait for TX queue to drain */ |
| 1397 | DPRINTK("eni_close: waiting for TX ...\n"); |
| 1398 | add_wait_queue(&eni_dev->tx_wait,&wait); |
| 1399 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 1400 | for (;;) { |
| 1401 | int txing; |
| 1402 | |
| 1403 | tasklet_disable(&eni_dev->task); |
| 1404 | txing = skb_peek(&eni_vcc->tx->backlog) || eni_vcc->txing; |
| 1405 | tasklet_enable(&eni_dev->task); |
| 1406 | if (!txing) break; |
| 1407 | DPRINTK("%d TX left\n",eni_vcc->txing); |
| 1408 | schedule(); |
| 1409 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 1410 | } |
| 1411 | set_current_state(TASK_RUNNING); |
| 1412 | remove_wait_queue(&eni_dev->tx_wait,&wait); |
| 1413 | if (eni_vcc->tx != eni_dev->ubr) { |
| 1414 | /* |
| 1415 | * Looping a few times in here is probably far cheaper than |
| 1416 | * keeping track of TX completions all the time, so let's poll |
| 1417 | * a bit ... |
| 1418 | */ |
| 1419 | while (eni_in(MID_TX_RDPTR(eni_vcc->tx->index)) != |
| 1420 | eni_in(MID_TX_DESCRSTART(eni_vcc->tx->index))) |
| 1421 | schedule(); |
| 1422 | eni_free_mem(eni_dev,eni_vcc->tx->send,eni_vcc->tx->words << 2); |
| 1423 | eni_vcc->tx->send = NULL; |
| 1424 | eni_dev->tx_bw += eni_vcc->tx->reserved; |
| 1425 | } |
| 1426 | eni_vcc->tx = NULL; |
| 1427 | } |
| 1428 | |
| 1429 | |
| 1430 | static int start_tx(struct atm_dev *dev) |
| 1431 | { |
| 1432 | struct eni_dev *eni_dev; |
| 1433 | int i; |
| 1434 | |
| 1435 | eni_dev = ENI_DEV(dev); |
| 1436 | eni_dev->lost = 0; |
| 1437 | eni_dev->tx_bw = ATM_OC3_PCR; |
| 1438 | eni_dev->tx_mult = DEFAULT_TX_MULT; |
| 1439 | init_waitqueue_head(&eni_dev->tx_wait); |
| 1440 | eni_dev->ubr = NULL; |
| 1441 | skb_queue_head_init(&eni_dev->tx_queue); |
| 1442 | eni_out(0,MID_DMA_WR_TX); |
| 1443 | for (i = 0; i < NR_CHAN; i++) { |
| 1444 | eni_dev->tx[i].send = NULL; |
| 1445 | eni_dev->tx[i].index = i; |
| 1446 | } |
| 1447 | return 0; |
| 1448 | } |
| 1449 | |
| 1450 | |
| 1451 | /*--------------------------------- common ----------------------------------*/ |
| 1452 | |
| 1453 | |
| 1454 | #if 0 /* may become useful again when tuning things */ |
| 1455 | |
| 1456 | static void foo(void) |
| 1457 | { |
| 1458 | printk(KERN_INFO |
| 1459 | "tx_complete=%d,dma_complete=%d,queued=%d,requeued=%d,sub=%d,\n" |
| 1460 | "backlogged=%d,rx_enqueued=%d,rx_dequeued=%d,putting=%d,pushed=%d\n", |
| 1461 | tx_complete,dma_complete,queued,requeued,submitted,backlogged, |
| 1462 | rx_enqueued,rx_dequeued,putting,pushed); |
| 1463 | if (eni_boards) printk(KERN_INFO "loss: %ld\n",ENI_DEV(eni_boards)->lost); |
| 1464 | } |
| 1465 | |
| 1466 | #endif |
| 1467 | |
| 1468 | |
| 1469 | static void bug_int(struct atm_dev *dev,unsigned long reason) |
| 1470 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | DPRINTK(">bug_int\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | if (reason & MID_DMA_ERR_ACK) |
| 1473 | printk(KERN_CRIT DEV_LABEL "(itf %d): driver error - DMA " |
| 1474 | "error\n",dev->number); |
| 1475 | if (reason & MID_TX_IDENT_MISM) |
| 1476 | printk(KERN_CRIT DEV_LABEL "(itf %d): driver error - ident " |
| 1477 | "mismatch\n",dev->number); |
| 1478 | if (reason & MID_TX_DMA_OVFL) |
| 1479 | printk(KERN_CRIT DEV_LABEL "(itf %d): driver error - DMA " |
| 1480 | "overflow\n",dev->number); |
| 1481 | EVENT("---dump ends here---\n",0,0); |
| 1482 | printk(KERN_NOTICE "---recent events---\n"); |
| 1483 | event_dump(); |
| 1484 | } |
| 1485 | |
| 1486 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1487 | static irqreturn_t eni_int(int irq,void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | { |
| 1489 | struct atm_dev *dev; |
| 1490 | struct eni_dev *eni_dev; |
| 1491 | u32 reason; |
| 1492 | |
| 1493 | DPRINTK(">eni_int\n"); |
| 1494 | dev = dev_id; |
| 1495 | eni_dev = ENI_DEV(dev); |
| 1496 | reason = eni_in(MID_ISA); |
| 1497 | DPRINTK(DEV_LABEL ": int 0x%lx\n",(unsigned long) reason); |
| 1498 | /* |
| 1499 | * Must handle these two right now, because reading ISA doesn't clear |
| 1500 | * them, so they re-occur and we never make it to the tasklet. Since |
| 1501 | * they're rare, we don't mind the occasional invocation of eni_tasklet |
| 1502 | * with eni_dev->events == 0. |
| 1503 | */ |
| 1504 | if (reason & MID_STAT_OVFL) { |
| 1505 | EVENT("stat overflow\n",0,0); |
| 1506 | eni_dev->lost += eni_in(MID_STAT) & MID_OVFL_TRASH; |
| 1507 | } |
| 1508 | if (reason & MID_SUNI_INT) { |
| 1509 | EVENT("SUNI int\n",0,0); |
| 1510 | dev->phy->interrupt(dev); |
| 1511 | #if 0 |
| 1512 | foo(); |
| 1513 | #endif |
| 1514 | } |
| 1515 | spin_lock(&eni_dev->lock); |
| 1516 | eni_dev->events |= reason; |
| 1517 | spin_unlock(&eni_dev->lock); |
| 1518 | tasklet_schedule(&eni_dev->task); |
| 1519 | return IRQ_HANDLED; |
| 1520 | } |
| 1521 | |
| 1522 | |
| 1523 | static void eni_tasklet(unsigned long data) |
| 1524 | { |
| 1525 | struct atm_dev *dev = (struct atm_dev *) data; |
| 1526 | struct eni_dev *eni_dev = ENI_DEV(dev); |
| 1527 | unsigned long flags; |
| 1528 | u32 events; |
| 1529 | |
| 1530 | DPRINTK("eni_tasklet (dev %p)\n",dev); |
| 1531 | spin_lock_irqsave(&eni_dev->lock,flags); |
| 1532 | events = xchg(&eni_dev->events,0); |
| 1533 | spin_unlock_irqrestore(&eni_dev->lock,flags); |
| 1534 | if (events & MID_RX_DMA_COMPLETE) { |
| 1535 | EVENT("INT: RX DMA complete, starting dequeue_rx\n",0,0); |
| 1536 | dequeue_rx(dev); |
| 1537 | EVENT("dequeue_rx done, starting poll_rx\n",0,0); |
| 1538 | poll_rx(dev); |
| 1539 | EVENT("poll_rx done\n",0,0); |
| 1540 | /* poll_tx ? */ |
| 1541 | } |
| 1542 | if (events & MID_SERVICE) { |
| 1543 | EVENT("INT: service, starting get_service\n",0,0); |
| 1544 | get_service(dev); |
| 1545 | EVENT("get_service done, starting poll_rx\n",0,0); |
| 1546 | poll_rx(dev); |
| 1547 | EVENT("poll_rx done\n",0,0); |
| 1548 | } |
| 1549 | if (events & MID_TX_DMA_COMPLETE) { |
| 1550 | EVENT("INT: TX DMA COMPLETE\n",0,0); |
| 1551 | dequeue_tx(dev); |
| 1552 | } |
| 1553 | if (events & MID_TX_COMPLETE) { |
| 1554 | EVENT("INT: TX COMPLETE\n",0,0); |
| 1555 | tx_complete++; |
| 1556 | wake_up(&eni_dev->tx_wait); |
| 1557 | /* poll_rx ? */ |
| 1558 | } |
| 1559 | if (events & (MID_DMA_ERR_ACK | MID_TX_IDENT_MISM | MID_TX_DMA_OVFL)) { |
| 1560 | EVENT("bug interrupt\n",0,0); |
| 1561 | bug_int(dev,events); |
| 1562 | } |
| 1563 | poll_tx(dev); |
| 1564 | } |
| 1565 | |
| 1566 | |
| 1567 | /*--------------------------------- entries ---------------------------------*/ |
| 1568 | |
| 1569 | |
| 1570 | static const char *media_name[] __devinitdata = { |
| 1571 | "MMF", "SMF", "MMF", "03?", /* 0- 3 */ |
| 1572 | "UTP", "05?", "06?", "07?", /* 4- 7 */ |
| 1573 | "TAXI","09?", "10?", "11?", /* 8-11 */ |
| 1574 | "12?", "13?", "14?", "15?", /* 12-15 */ |
| 1575 | "MMF", "SMF", "18?", "19?", /* 16-19 */ |
| 1576 | "UTP", "21?", "22?", "23?", /* 20-23 */ |
| 1577 | "24?", "25?", "26?", "27?", /* 24-27 */ |
| 1578 | "28?", "29?", "30?", "31?" /* 28-31 */ |
| 1579 | }; |
| 1580 | |
| 1581 | |
| 1582 | #define SET_SEPROM \ |
| 1583 | ({ if (!error && !pci_error) { \ |
| 1584 | pci_error = pci_write_config_byte(eni_dev->pci_dev,PCI_TONGA_CTRL,tonga); \ |
| 1585 | udelay(10); /* 10 usecs */ \ |
| 1586 | } }) |
| 1587 | #define GET_SEPROM \ |
| 1588 | ({ if (!error && !pci_error) { \ |
| 1589 | pci_error = pci_read_config_byte(eni_dev->pci_dev,PCI_TONGA_CTRL,&tonga); \ |
| 1590 | udelay(10); /* 10 usecs */ \ |
| 1591 | } }) |
| 1592 | |
| 1593 | |
| 1594 | static int __devinit get_esi_asic(struct atm_dev *dev) |
| 1595 | { |
| 1596 | struct eni_dev *eni_dev; |
| 1597 | unsigned char tonga; |
| 1598 | int error,failed,pci_error; |
| 1599 | int address,i,j; |
| 1600 | |
| 1601 | eni_dev = ENI_DEV(dev); |
| 1602 | error = pci_error = 0; |
| 1603 | tonga = SEPROM_MAGIC | SEPROM_DATA | SEPROM_CLK; |
| 1604 | SET_SEPROM; |
| 1605 | for (i = 0; i < ESI_LEN && !error && !pci_error; i++) { |
| 1606 | /* start operation */ |
| 1607 | tonga |= SEPROM_DATA; |
| 1608 | SET_SEPROM; |
| 1609 | tonga |= SEPROM_CLK; |
| 1610 | SET_SEPROM; |
| 1611 | tonga &= ~SEPROM_DATA; |
| 1612 | SET_SEPROM; |
| 1613 | tonga &= ~SEPROM_CLK; |
| 1614 | SET_SEPROM; |
| 1615 | /* send address */ |
| 1616 | address = ((i+SEPROM_ESI_BASE) << 1)+1; |
| 1617 | for (j = 7; j >= 0; j--) { |
| 1618 | tonga = (address >> j) & 1 ? tonga | SEPROM_DATA : |
| 1619 | tonga & ~SEPROM_DATA; |
| 1620 | SET_SEPROM; |
| 1621 | tonga |= SEPROM_CLK; |
| 1622 | SET_SEPROM; |
| 1623 | tonga &= ~SEPROM_CLK; |
| 1624 | SET_SEPROM; |
| 1625 | } |
| 1626 | /* get ack */ |
| 1627 | tonga |= SEPROM_DATA; |
| 1628 | SET_SEPROM; |
| 1629 | tonga |= SEPROM_CLK; |
| 1630 | SET_SEPROM; |
| 1631 | GET_SEPROM; |
| 1632 | failed = tonga & SEPROM_DATA; |
| 1633 | tonga &= ~SEPROM_CLK; |
| 1634 | SET_SEPROM; |
| 1635 | tonga |= SEPROM_DATA; |
| 1636 | SET_SEPROM; |
| 1637 | if (failed) error = -EIO; |
| 1638 | else { |
| 1639 | dev->esi[i] = 0; |
| 1640 | for (j = 7; j >= 0; j--) { |
| 1641 | dev->esi[i] <<= 1; |
| 1642 | tonga |= SEPROM_DATA; |
| 1643 | SET_SEPROM; |
| 1644 | tonga |= SEPROM_CLK; |
| 1645 | SET_SEPROM; |
| 1646 | GET_SEPROM; |
| 1647 | if (tonga & SEPROM_DATA) dev->esi[i] |= 1; |
| 1648 | tonga &= ~SEPROM_CLK; |
| 1649 | SET_SEPROM; |
| 1650 | tonga |= SEPROM_DATA; |
| 1651 | SET_SEPROM; |
| 1652 | } |
| 1653 | /* get ack */ |
| 1654 | tonga |= SEPROM_DATA; |
| 1655 | SET_SEPROM; |
| 1656 | tonga |= SEPROM_CLK; |
| 1657 | SET_SEPROM; |
| 1658 | GET_SEPROM; |
| 1659 | if (!(tonga & SEPROM_DATA)) error = -EIO; |
| 1660 | tonga &= ~SEPROM_CLK; |
| 1661 | SET_SEPROM; |
| 1662 | tonga |= SEPROM_DATA; |
| 1663 | SET_SEPROM; |
| 1664 | } |
| 1665 | /* stop operation */ |
| 1666 | tonga &= ~SEPROM_DATA; |
| 1667 | SET_SEPROM; |
| 1668 | tonga |= SEPROM_CLK; |
| 1669 | SET_SEPROM; |
| 1670 | tonga |= SEPROM_DATA; |
| 1671 | SET_SEPROM; |
| 1672 | } |
| 1673 | if (pci_error) { |
| 1674 | printk(KERN_ERR DEV_LABEL "(itf %d): error reading ESI " |
| 1675 | "(0x%02x)\n",dev->number,pci_error); |
| 1676 | error = -EIO; |
| 1677 | } |
| 1678 | return error; |
| 1679 | } |
| 1680 | |
| 1681 | |
| 1682 | #undef SET_SEPROM |
| 1683 | #undef GET_SEPROM |
| 1684 | |
| 1685 | |
| 1686 | static int __devinit get_esi_fpga(struct atm_dev *dev, void __iomem *base) |
| 1687 | { |
| 1688 | void __iomem *mac_base; |
| 1689 | int i; |
| 1690 | |
| 1691 | mac_base = base+EPROM_SIZE-sizeof(struct midway_eprom); |
| 1692 | for (i = 0; i < ESI_LEN; i++) dev->esi[i] = readb(mac_base+(i^3)); |
| 1693 | return 0; |
| 1694 | } |
| 1695 | |
| 1696 | |
| 1697 | static int __devinit eni_do_init(struct atm_dev *dev) |
| 1698 | { |
| 1699 | struct midway_eprom __iomem *eprom; |
| 1700 | struct eni_dev *eni_dev; |
| 1701 | struct pci_dev *pci_dev; |
| 1702 | unsigned long real_base; |
| 1703 | void __iomem *base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | int error,i,last; |
| 1705 | |
| 1706 | DPRINTK(">eni_init\n"); |
| 1707 | dev->ci_range.vpi_bits = 0; |
| 1708 | dev->ci_range.vci_bits = NR_VCI_LD; |
| 1709 | dev->link_rate = ATM_OC3_PCR; |
| 1710 | eni_dev = ENI_DEV(dev); |
| 1711 | pci_dev = eni_dev->pci_dev; |
| 1712 | real_base = pci_resource_start(pci_dev, 0); |
| 1713 | eni_dev->irq = pci_dev->irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | if ((error = pci_write_config_word(pci_dev,PCI_COMMAND, |
| 1715 | PCI_COMMAND_MEMORY | |
| 1716 | (eni_dev->asic ? PCI_COMMAND_PARITY | PCI_COMMAND_SERR : 0)))) { |
| 1717 | printk(KERN_ERR DEV_LABEL "(itf %d): can't enable memory " |
| 1718 | "(0x%02x)\n",dev->number,error); |
| 1719 | return -EIO; |
| 1720 | } |
| 1721 | printk(KERN_NOTICE DEV_LABEL "(itf %d): rev.%d,base=0x%lx,irq=%d,", |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 1722 | dev->number,pci_dev->revision,real_base,eni_dev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | if (!(base = ioremap_nocache(real_base,MAP_MAX_SIZE))) { |
| 1724 | printk("\n"); |
| 1725 | printk(KERN_ERR DEV_LABEL "(itf %d): can't set up page " |
| 1726 | "mapping\n",dev->number); |
| 1727 | return error; |
| 1728 | } |
françois romieu | 126a3fd | 2012-03-16 01:52:04 +0000 | [diff] [blame] | 1729 | eni_dev->ioaddr = base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1730 | eni_dev->base_diff = real_base - (unsigned long) base; |
| 1731 | /* id may not be present in ASIC Tonga boards - check this @@@ */ |
| 1732 | if (!eni_dev->asic) { |
| 1733 | eprom = (base+EPROM_SIZE-sizeof(struct midway_eprom)); |
| 1734 | if (readl(&eprom->magic) != ENI155_MAGIC) { |
| 1735 | printk("\n"); |
Joe Perches | 1941bf8 | 2010-10-25 16:44:20 +0000 | [diff] [blame] | 1736 | printk(KERN_ERR DEV_LABEL |
| 1737 | "(itf %d): bad magic - expected 0x%x, got 0x%x\n", |
| 1738 | dev->number, ENI155_MAGIC, |
| 1739 | (unsigned)readl(&eprom->magic)); |
Amol Lad | 78e4be1 | 2007-07-16 18:34:36 -0700 | [diff] [blame] | 1740 | error = -EINVAL; |
| 1741 | goto unmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | } |
| 1743 | } |
| 1744 | eni_dev->phy = base+PHY_BASE; |
| 1745 | eni_dev->reg = base+REG_BASE; |
| 1746 | eni_dev->ram = base+RAM_BASE; |
| 1747 | last = MAP_MAX_SIZE-RAM_BASE; |
| 1748 | for (i = last-RAM_INCREMENT; i >= 0; i -= RAM_INCREMENT) { |
| 1749 | writel(0x55555555,eni_dev->ram+i); |
| 1750 | if (readl(eni_dev->ram+i) != 0x55555555) last = i; |
| 1751 | else { |
| 1752 | writel(0xAAAAAAAA,eni_dev->ram+i); |
| 1753 | if (readl(eni_dev->ram+i) != 0xAAAAAAAA) last = i; |
| 1754 | else writel(i,eni_dev->ram+i); |
| 1755 | } |
| 1756 | } |
| 1757 | for (i = 0; i < last; i += RAM_INCREMENT) |
| 1758 | if (readl(eni_dev->ram+i) != i) break; |
| 1759 | eni_dev->mem = i; |
| 1760 | memset_io(eni_dev->ram,0,eni_dev->mem); |
| 1761 | /* TODO: should shrink allocation now */ |
| 1762 | printk("mem=%dkB (",eni_dev->mem >> 10); |
| 1763 | /* TODO: check for non-SUNI, check for TAXI ? */ |
| 1764 | if (!(eni_in(MID_RES_ID_MCON) & 0x200) != !eni_dev->asic) { |
| 1765 | printk(")\n"); |
| 1766 | printk(KERN_ERR DEV_LABEL "(itf %d): ERROR - wrong id 0x%x\n", |
| 1767 | dev->number,(unsigned) eni_in(MID_RES_ID_MCON)); |
Amol Lad | 78e4be1 | 2007-07-16 18:34:36 -0700 | [diff] [blame] | 1768 | error = -EINVAL; |
| 1769 | goto unmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | } |
| 1771 | error = eni_dev->asic ? get_esi_asic(dev) : get_esi_fpga(dev,base); |
Amol Lad | 78e4be1 | 2007-07-16 18:34:36 -0700 | [diff] [blame] | 1772 | if (error) |
| 1773 | goto unmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1774 | for (i = 0; i < ESI_LEN; i++) |
| 1775 | printk("%s%02X",i ? "-" : "",dev->esi[i]); |
| 1776 | printk(")\n"); |
| 1777 | printk(KERN_NOTICE DEV_LABEL "(itf %d): %s,%s\n",dev->number, |
| 1778 | eni_in(MID_RES_ID_MCON) & 0x200 ? "ASIC" : "FPGA", |
| 1779 | media_name[eni_in(MID_RES_ID_MCON) & DAUGTHER_ID]); |
Amol Lad | 78e4be1 | 2007-07-16 18:34:36 -0700 | [diff] [blame] | 1780 | |
| 1781 | error = suni_init(dev); |
| 1782 | if (error) |
| 1783 | goto unmap; |
| 1784 | out: |
| 1785 | return error; |
| 1786 | unmap: |
| 1787 | iounmap(base); |
| 1788 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | } |
| 1790 | |
françois romieu | 126a3fd | 2012-03-16 01:52:04 +0000 | [diff] [blame] | 1791 | static void eni_do_release(struct atm_dev *dev) |
| 1792 | { |
| 1793 | struct eni_dev *ed = ENI_DEV(dev); |
| 1794 | |
| 1795 | dev->phy->stop(dev); |
| 1796 | dev->phy = NULL; |
| 1797 | iounmap(ed->ioaddr); |
| 1798 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | |
| 1800 | static int __devinit eni_start(struct atm_dev *dev) |
| 1801 | { |
| 1802 | struct eni_dev *eni_dev; |
| 1803 | |
| 1804 | void __iomem *buf; |
| 1805 | unsigned long buffer_mem; |
| 1806 | int error; |
| 1807 | |
| 1808 | DPRINTK(">eni_start\n"); |
| 1809 | eni_dev = ENI_DEV(dev); |
Thomas Gleixner | dace145 | 2006-07-01 19:29:38 -0700 | [diff] [blame] | 1810 | if (request_irq(eni_dev->irq,&eni_int,IRQF_SHARED,DEV_LABEL,dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | printk(KERN_ERR DEV_LABEL "(itf %d): IRQ%d is already in use\n", |
| 1812 | dev->number,eni_dev->irq); |
Andrew Morton | 758d11b | 2005-04-24 19:14:36 -0700 | [diff] [blame] | 1813 | error = -EAGAIN; |
| 1814 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | pci_set_master(eni_dev->pci_dev); |
| 1817 | if ((error = pci_write_config_word(eni_dev->pci_dev,PCI_COMMAND, |
| 1818 | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | |
| 1819 | (eni_dev->asic ? PCI_COMMAND_PARITY | PCI_COMMAND_SERR : 0)))) { |
| 1820 | printk(KERN_ERR DEV_LABEL "(itf %d): can't enable memory+" |
| 1821 | "master (0x%02x)\n",dev->number,error); |
Andrew Morton | 758d11b | 2005-04-24 19:14:36 -0700 | [diff] [blame] | 1822 | goto free_irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | } |
| 1824 | if ((error = pci_write_config_byte(eni_dev->pci_dev,PCI_TONGA_CTRL, |
| 1825 | END_SWAP_DMA))) { |
| 1826 | printk(KERN_ERR DEV_LABEL "(itf %d): can't set endian swap " |
| 1827 | "(0x%02x)\n",dev->number,error); |
Andrew Morton | 758d11b | 2005-04-24 19:14:36 -0700 | [diff] [blame] | 1828 | goto free_irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1829 | } |
| 1830 | /* determine addresses of internal tables */ |
| 1831 | eni_dev->vci = eni_dev->ram; |
| 1832 | eni_dev->rx_dma = eni_dev->ram+NR_VCI*16; |
| 1833 | eni_dev->tx_dma = eni_dev->rx_dma+NR_DMA_RX*8; |
| 1834 | eni_dev->service = eni_dev->tx_dma+NR_DMA_TX*8; |
| 1835 | buf = eni_dev->service+NR_SERVICE*4; |
| 1836 | DPRINTK("vci 0x%lx,rx 0x%lx, tx 0x%lx,srv 0x%lx,buf 0x%lx\n", |
| 1837 | eni_dev->vci,eni_dev->rx_dma,eni_dev->tx_dma, |
| 1838 | eni_dev->service,buf); |
| 1839 | spin_lock_init(&eni_dev->lock); |
| 1840 | tasklet_init(&eni_dev->task,eni_tasklet,(unsigned long) dev); |
| 1841 | eni_dev->events = 0; |
| 1842 | /* initialize memory management */ |
| 1843 | buffer_mem = eni_dev->mem - (buf - eni_dev->ram); |
| 1844 | eni_dev->free_list_size = buffer_mem/MID_MIN_BUF_SIZE/2; |
Robert P. J. Day | 5cbded5 | 2006-12-13 00:35:56 -0800 | [diff] [blame] | 1845 | eni_dev->free_list = kmalloc( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | sizeof(struct eni_free)*(eni_dev->free_list_size+1),GFP_KERNEL); |
| 1847 | if (!eni_dev->free_list) { |
| 1848 | printk(KERN_ERR DEV_LABEL "(itf %d): couldn't get free page\n", |
| 1849 | dev->number); |
Andrew Morton | 758d11b | 2005-04-24 19:14:36 -0700 | [diff] [blame] | 1850 | error = -ENOMEM; |
| 1851 | goto free_irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | } |
| 1853 | eni_dev->free_len = 0; |
| 1854 | eni_put_free(eni_dev,buf,buffer_mem); |
| 1855 | memset_io(eni_dev->vci,0,16*NR_VCI); /* clear VCI table */ |
| 1856 | /* |
| 1857 | * byte_addr free (k) |
| 1858 | * 0x00000000 512 VCI table |
| 1859 | * 0x00004000 496 RX DMA |
| 1860 | * 0x00005000 492 TX DMA |
| 1861 | * 0x00006000 488 service list |
| 1862 | * 0x00007000 484 buffers |
| 1863 | * 0x00080000 0 end (512kB) |
| 1864 | */ |
| 1865 | eni_out(0xffffffff,MID_IE); |
| 1866 | error = start_tx(dev); |
Andrew Morton | 758d11b | 2005-04-24 19:14:36 -0700 | [diff] [blame] | 1867 | if (error) goto free_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | error = start_rx(dev); |
Andrew Morton | 758d11b | 2005-04-24 19:14:36 -0700 | [diff] [blame] | 1869 | if (error) goto free_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | error = dev->phy->start(dev); |
Andrew Morton | 758d11b | 2005-04-24 19:14:36 -0700 | [diff] [blame] | 1871 | if (error) goto free_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | eni_out(eni_in(MID_MC_S) | (1 << MID_INT_SEL_SHIFT) | |
| 1873 | MID_TX_LOCK_MODE | MID_DMA_ENABLE | MID_TX_ENABLE | MID_RX_ENABLE, |
| 1874 | MID_MC_S); |
| 1875 | /* Tonga uses SBus INTReq1 */ |
| 1876 | (void) eni_in(MID_ISA); /* clear Midway interrupts */ |
| 1877 | return 0; |
Andrew Morton | 758d11b | 2005-04-24 19:14:36 -0700 | [diff] [blame] | 1878 | |
| 1879 | free_list: |
| 1880 | kfree(eni_dev->free_list); |
| 1881 | |
| 1882 | free_irq: |
Julia Lawall | 5eac5f6 | 2012-03-11 11:16:25 +0000 | [diff] [blame] | 1883 | free_irq(eni_dev->irq, dev); |
Andrew Morton | 758d11b | 2005-04-24 19:14:36 -0700 | [diff] [blame] | 1884 | |
| 1885 | out: |
| 1886 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 | } |
| 1888 | |
| 1889 | |
| 1890 | static void eni_close(struct atm_vcc *vcc) |
| 1891 | { |
| 1892 | DPRINTK(">eni_close\n"); |
| 1893 | if (!ENI_VCC(vcc)) return; |
| 1894 | clear_bit(ATM_VF_READY,&vcc->flags); |
| 1895 | close_rx(vcc); |
| 1896 | close_tx(vcc); |
| 1897 | DPRINTK("eni_close: done waiting\n"); |
| 1898 | /* deallocate memory */ |
| 1899 | kfree(ENI_VCC(vcc)); |
| 1900 | vcc->dev_data = NULL; |
| 1901 | clear_bit(ATM_VF_ADDR,&vcc->flags); |
| 1902 | /*foo();*/ |
| 1903 | } |
| 1904 | |
| 1905 | |
| 1906 | static int eni_open(struct atm_vcc *vcc) |
| 1907 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | struct eni_vcc *eni_vcc; |
| 1909 | int error; |
| 1910 | short vpi = vcc->vpi; |
| 1911 | int vci = vcc->vci; |
| 1912 | |
| 1913 | DPRINTK(">eni_open\n"); |
| 1914 | EVENT("eni_open\n",0,0); |
| 1915 | if (!test_bit(ATM_VF_PARTIAL,&vcc->flags)) |
| 1916 | vcc->dev_data = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | if (vci != ATM_VPI_UNSPEC && vpi != ATM_VCI_UNSPEC) |
| 1918 | set_bit(ATM_VF_ADDR,&vcc->flags); |
| 1919 | if (vcc->qos.aal != ATM_AAL0 && vcc->qos.aal != ATM_AAL5) |
| 1920 | return -EINVAL; |
| 1921 | DPRINTK(DEV_LABEL "(itf %d): open %d.%d\n",vcc->dev->number,vcc->vpi, |
| 1922 | vcc->vci); |
| 1923 | if (!test_bit(ATM_VF_PARTIAL,&vcc->flags)) { |
| 1924 | eni_vcc = kmalloc(sizeof(struct eni_vcc),GFP_KERNEL); |
| 1925 | if (!eni_vcc) return -ENOMEM; |
| 1926 | vcc->dev_data = eni_vcc; |
| 1927 | eni_vcc->tx = NULL; /* for eni_close after open_rx */ |
| 1928 | if ((error = open_rx_first(vcc))) { |
| 1929 | eni_close(vcc); |
| 1930 | return error; |
| 1931 | } |
| 1932 | if ((error = open_tx_first(vcc))) { |
| 1933 | eni_close(vcc); |
| 1934 | return error; |
| 1935 | } |
| 1936 | } |
| 1937 | if (vci == ATM_VPI_UNSPEC || vpi == ATM_VCI_UNSPEC) return 0; |
| 1938 | if ((error = open_rx_second(vcc))) { |
| 1939 | eni_close(vcc); |
| 1940 | return error; |
| 1941 | } |
| 1942 | if ((error = open_tx_second(vcc))) { |
| 1943 | eni_close(vcc); |
| 1944 | return error; |
| 1945 | } |
| 1946 | set_bit(ATM_VF_READY,&vcc->flags); |
| 1947 | /* should power down SUNI while !ref_count @@@ */ |
| 1948 | return 0; |
| 1949 | } |
| 1950 | |
| 1951 | |
| 1952 | static int eni_change_qos(struct atm_vcc *vcc,struct atm_qos *qos,int flgs) |
| 1953 | { |
| 1954 | struct eni_dev *eni_dev = ENI_DEV(vcc->dev); |
| 1955 | struct eni_tx *tx = ENI_VCC(vcc)->tx; |
| 1956 | struct sk_buff *skb; |
| 1957 | int error,rate,rsv,shp; |
| 1958 | |
| 1959 | if (qos->txtp.traffic_class == ATM_NONE) return 0; |
| 1960 | if (tx == eni_dev->ubr) return -EBADFD; |
| 1961 | rate = atm_pcr_goal(&qos->txtp); |
| 1962 | if (rate < 0) rate = -rate; |
| 1963 | rsv = shp = 0; |
| 1964 | if ((flgs & ATM_MF_DEC_RSV) && rate && rate < tx->reserved) rsv = 1; |
| 1965 | if ((flgs & ATM_MF_INC_RSV) && (!rate || rate > tx->reserved)) rsv = 1; |
| 1966 | if ((flgs & ATM_MF_DEC_SHP) && rate && rate < tx->shaping) shp = 1; |
| 1967 | if ((flgs & ATM_MF_INC_SHP) && (!rate || rate > tx->shaping)) shp = 1; |
| 1968 | if (!rsv && !shp) return 0; |
| 1969 | error = reserve_or_set_tx(vcc,&qos->txtp,rsv,shp); |
| 1970 | if (error) return error; |
| 1971 | if (shp && !(flgs & ATM_MF_IMMED)) return 0; |
| 1972 | /* |
| 1973 | * Walk through the send buffer and patch the rate information in all |
| 1974 | * segmentation buffer descriptors of this VCC. |
| 1975 | */ |
| 1976 | tasklet_disable(&eni_dev->task); |
| 1977 | skb_queue_walk(&eni_dev->tx_queue, skb) { |
| 1978 | void __iomem *dsc; |
| 1979 | |
| 1980 | if (ATM_SKB(skb)->vcc != vcc) continue; |
| 1981 | dsc = tx->send+ENI_PRV_POS(skb)*4; |
| 1982 | writel((readl(dsc) & ~(MID_SEG_RATE | MID_SEG_PR)) | |
| 1983 | (tx->prescaler << MID_SEG_PR_SHIFT) | |
| 1984 | (tx->resolution << MID_SEG_RATE_SHIFT), dsc); |
| 1985 | } |
| 1986 | tasklet_enable(&eni_dev->task); |
| 1987 | return 0; |
| 1988 | } |
| 1989 | |
| 1990 | |
| 1991 | static int eni_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg) |
| 1992 | { |
| 1993 | struct eni_dev *eni_dev = ENI_DEV(dev); |
| 1994 | |
| 1995 | if (cmd == ENI_MEMDUMP) { |
| 1996 | if (!capable(CAP_NET_ADMIN)) return -EPERM; |
| 1997 | printk(KERN_WARNING "Please use /proc/atm/" DEV_LABEL ":%d " |
| 1998 | "instead of obsolete ioctl ENI_MEMDUMP\n",dev->number); |
| 1999 | dump(dev); |
| 2000 | return 0; |
| 2001 | } |
| 2002 | if (cmd == ENI_SETMULT) { |
| 2003 | struct eni_multipliers mult; |
| 2004 | |
| 2005 | if (!capable(CAP_NET_ADMIN)) return -EPERM; |
| 2006 | if (copy_from_user(&mult, arg, |
| 2007 | sizeof(struct eni_multipliers))) |
| 2008 | return -EFAULT; |
| 2009 | if ((mult.tx && mult.tx <= 100) || (mult.rx &&mult.rx <= 100) || |
| 2010 | mult.tx > 65536 || mult.rx > 65536) |
| 2011 | return -EINVAL; |
| 2012 | if (mult.tx) eni_dev->tx_mult = mult.tx; |
| 2013 | if (mult.rx) eni_dev->rx_mult = mult.rx; |
| 2014 | return 0; |
| 2015 | } |
| 2016 | if (cmd == ATM_SETCIRANGE) { |
| 2017 | struct atm_cirange ci; |
| 2018 | |
| 2019 | if (copy_from_user(&ci, arg,sizeof(struct atm_cirange))) |
| 2020 | return -EFAULT; |
| 2021 | if ((ci.vpi_bits == 0 || ci.vpi_bits == ATM_CI_MAX) && |
| 2022 | (ci.vci_bits == NR_VCI_LD || ci.vpi_bits == ATM_CI_MAX)) |
| 2023 | return 0; |
| 2024 | return -EINVAL; |
| 2025 | } |
| 2026 | if (!dev->phy->ioctl) return -ENOIOCTLCMD; |
| 2027 | return dev->phy->ioctl(dev,cmd,arg); |
| 2028 | } |
| 2029 | |
| 2030 | |
| 2031 | static int eni_getsockopt(struct atm_vcc *vcc,int level,int optname, |
| 2032 | void __user *optval,int optlen) |
| 2033 | { |
| 2034 | return -EINVAL; |
| 2035 | } |
| 2036 | |
| 2037 | |
| 2038 | static int eni_setsockopt(struct atm_vcc *vcc,int level,int optname, |
David S. Miller | b705884 | 2009-09-30 16:12:20 -0700 | [diff] [blame] | 2039 | void __user *optval,unsigned int optlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | { |
| 2041 | return -EINVAL; |
| 2042 | } |
| 2043 | |
| 2044 | |
| 2045 | static int eni_send(struct atm_vcc *vcc,struct sk_buff *skb) |
| 2046 | { |
| 2047 | enum enq_res res; |
| 2048 | |
| 2049 | DPRINTK(">eni_send\n"); |
| 2050 | if (!ENI_VCC(vcc)->tx) { |
| 2051 | if (vcc->pop) vcc->pop(vcc,skb); |
| 2052 | else dev_kfree_skb(skb); |
| 2053 | return -EINVAL; |
| 2054 | } |
| 2055 | if (!skb) { |
| 2056 | printk(KERN_CRIT "!skb in eni_send ?\n"); |
| 2057 | if (vcc->pop) vcc->pop(vcc,skb); |
| 2058 | return -EINVAL; |
| 2059 | } |
| 2060 | if (vcc->qos.aal == ATM_AAL0) { |
| 2061 | if (skb->len != ATM_CELL_SIZE-1) { |
| 2062 | if (vcc->pop) vcc->pop(vcc,skb); |
| 2063 | else dev_kfree_skb(skb); |
| 2064 | return -EINVAL; |
| 2065 | } |
| 2066 | *(u32 *) skb->data = htonl(*(u32 *) skb->data); |
| 2067 | } |
| 2068 | submitted++; |
| 2069 | ATM_SKB(skb)->vcc = vcc; |
| 2070 | tasklet_disable(&ENI_DEV(vcc->dev)->task); |
| 2071 | res = do_tx(skb); |
| 2072 | tasklet_enable(&ENI_DEV(vcc->dev)->task); |
| 2073 | if (res == enq_ok) return 0; |
| 2074 | skb_queue_tail(&ENI_VCC(vcc)->tx->backlog,skb); |
| 2075 | backlogged++; |
| 2076 | tasklet_schedule(&ENI_DEV(vcc->dev)->task); |
| 2077 | return 0; |
| 2078 | } |
| 2079 | |
| 2080 | static void eni_phy_put(struct atm_dev *dev,unsigned char value, |
| 2081 | unsigned long addr) |
| 2082 | { |
| 2083 | writel(value,ENI_DEV(dev)->phy+addr*4); |
| 2084 | } |
| 2085 | |
| 2086 | |
| 2087 | |
| 2088 | static unsigned char eni_phy_get(struct atm_dev *dev,unsigned long addr) |
| 2089 | { |
| 2090 | return readl(ENI_DEV(dev)->phy+addr*4); |
| 2091 | } |
| 2092 | |
| 2093 | |
| 2094 | static int eni_proc_read(struct atm_dev *dev,loff_t *pos,char *page) |
| 2095 | { |
| 2096 | struct hlist_node *node; |
| 2097 | struct sock *s; |
| 2098 | static const char *signal[] = { "LOST","unknown","okay" }; |
| 2099 | struct eni_dev *eni_dev = ENI_DEV(dev); |
| 2100 | struct atm_vcc *vcc; |
| 2101 | int left,i; |
| 2102 | |
| 2103 | left = *pos; |
| 2104 | if (!left) |
| 2105 | return sprintf(page,DEV_LABEL "(itf %d) signal %s, %dkB, " |
| 2106 | "%d cps remaining\n",dev->number,signal[(int) dev->signal], |
| 2107 | eni_dev->mem >> 10,eni_dev->tx_bw); |
| 2108 | if (!--left) |
| 2109 | return sprintf(page,"%4sBursts: TX" |
| 2110 | #if !defined(CONFIG_ATM_ENI_BURST_TX_16W) && \ |
| 2111 | !defined(CONFIG_ATM_ENI_BURST_TX_8W) && \ |
| 2112 | !defined(CONFIG_ATM_ENI_BURST_TX_4W) && \ |
| 2113 | !defined(CONFIG_ATM_ENI_BURST_TX_2W) |
| 2114 | " none" |
| 2115 | #endif |
| 2116 | #ifdef CONFIG_ATM_ENI_BURST_TX_16W |
| 2117 | " 16W" |
| 2118 | #endif |
| 2119 | #ifdef CONFIG_ATM_ENI_BURST_TX_8W |
| 2120 | " 8W" |
| 2121 | #endif |
| 2122 | #ifdef CONFIG_ATM_ENI_BURST_TX_4W |
| 2123 | " 4W" |
| 2124 | #endif |
| 2125 | #ifdef CONFIG_ATM_ENI_BURST_TX_2W |
| 2126 | " 2W" |
| 2127 | #endif |
| 2128 | ", RX" |
| 2129 | #if !defined(CONFIG_ATM_ENI_BURST_RX_16W) && \ |
| 2130 | !defined(CONFIG_ATM_ENI_BURST_RX_8W) && \ |
| 2131 | !defined(CONFIG_ATM_ENI_BURST_RX_4W) && \ |
| 2132 | !defined(CONFIG_ATM_ENI_BURST_RX_2W) |
| 2133 | " none" |
| 2134 | #endif |
| 2135 | #ifdef CONFIG_ATM_ENI_BURST_RX_16W |
| 2136 | " 16W" |
| 2137 | #endif |
| 2138 | #ifdef CONFIG_ATM_ENI_BURST_RX_8W |
| 2139 | " 8W" |
| 2140 | #endif |
| 2141 | #ifdef CONFIG_ATM_ENI_BURST_RX_4W |
| 2142 | " 4W" |
| 2143 | #endif |
| 2144 | #ifdef CONFIG_ATM_ENI_BURST_RX_2W |
| 2145 | " 2W" |
| 2146 | #endif |
| 2147 | #ifndef CONFIG_ATM_ENI_TUNE_BURST |
| 2148 | " (default)" |
| 2149 | #endif |
| 2150 | "\n",""); |
| 2151 | if (!--left) |
| 2152 | return sprintf(page,"%4sBuffer multipliers: tx %d%%, rx %d%%\n", |
| 2153 | "",eni_dev->tx_mult,eni_dev->rx_mult); |
| 2154 | for (i = 0; i < NR_CHAN; i++) { |
| 2155 | struct eni_tx *tx = eni_dev->tx+i; |
| 2156 | |
| 2157 | if (!tx->send) continue; |
| 2158 | if (!--left) { |
| 2159 | return sprintf(page,"tx[%d]: 0x%ld-0x%ld " |
| 2160 | "(%6ld bytes), rsv %d cps, shp %d cps%s\n",i, |
| 2161 | (unsigned long) (tx->send - eni_dev->ram), |
| 2162 | tx->send-eni_dev->ram+tx->words*4-1,tx->words*4, |
| 2163 | tx->reserved,tx->shaping, |
| 2164 | tx == eni_dev->ubr ? " (UBR)" : ""); |
| 2165 | } |
| 2166 | if (--left) continue; |
| 2167 | return sprintf(page,"%10sbacklog %u packets\n","", |
| 2168 | skb_queue_len(&tx->backlog)); |
| 2169 | } |
| 2170 | read_lock(&vcc_sklist_lock); |
| 2171 | for(i = 0; i < VCC_HTABLE_SIZE; ++i) { |
| 2172 | struct hlist_head *head = &vcc_hash[i]; |
| 2173 | |
| 2174 | sk_for_each(s, node, head) { |
| 2175 | struct eni_vcc *eni_vcc; |
| 2176 | int length; |
| 2177 | |
| 2178 | vcc = atm_sk(s); |
| 2179 | if (vcc->dev != dev) |
| 2180 | continue; |
| 2181 | eni_vcc = ENI_VCC(vcc); |
| 2182 | if (--left) continue; |
| 2183 | length = sprintf(page,"vcc %4d: ",vcc->vci); |
| 2184 | if (eni_vcc->rx) { |
| 2185 | length += sprintf(page+length,"0x%ld-0x%ld " |
| 2186 | "(%6ld bytes)", |
| 2187 | (unsigned long) (eni_vcc->recv - eni_dev->ram), |
| 2188 | eni_vcc->recv-eni_dev->ram+eni_vcc->words*4-1, |
| 2189 | eni_vcc->words*4); |
| 2190 | if (eni_vcc->tx) length += sprintf(page+length,", "); |
| 2191 | } |
| 2192 | if (eni_vcc->tx) |
| 2193 | length += sprintf(page+length,"tx[%d], txing %d bytes", |
| 2194 | eni_vcc->tx->index,eni_vcc->txing); |
| 2195 | page[length] = '\n'; |
| 2196 | read_unlock(&vcc_sklist_lock); |
| 2197 | return length+1; |
| 2198 | } |
| 2199 | } |
| 2200 | read_unlock(&vcc_sklist_lock); |
| 2201 | for (i = 0; i < eni_dev->free_len; i++) { |
| 2202 | struct eni_free *fe = eni_dev->free_list+i; |
| 2203 | unsigned long offset; |
| 2204 | |
| 2205 | if (--left) continue; |
| 2206 | offset = (unsigned long) eni_dev->ram+eni_dev->base_diff; |
| 2207 | return sprintf(page,"free %p-%p (%6d bytes)\n", |
| 2208 | fe->start-offset,fe->start-offset+(1 << fe->order)-1, |
| 2209 | 1 << fe->order); |
| 2210 | } |
| 2211 | return 0; |
| 2212 | } |
| 2213 | |
| 2214 | |
| 2215 | static const struct atmdev_ops ops = { |
| 2216 | .open = eni_open, |
| 2217 | .close = eni_close, |
| 2218 | .ioctl = eni_ioctl, |
| 2219 | .getsockopt = eni_getsockopt, |
| 2220 | .setsockopt = eni_setsockopt, |
| 2221 | .send = eni_send, |
| 2222 | .phy_put = eni_phy_put, |
| 2223 | .phy_get = eni_phy_get, |
| 2224 | .change_qos = eni_change_qos, |
| 2225 | .proc_read = eni_proc_read |
| 2226 | }; |
| 2227 | |
| 2228 | |
| 2229 | static int __devinit eni_init_one(struct pci_dev *pci_dev, |
françois romieu | 126a3fd | 2012-03-16 01:52:04 +0000 | [diff] [blame] | 2230 | const struct pci_device_id *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2231 | { |
| 2232 | struct atm_dev *dev; |
| 2233 | struct eni_dev *eni_dev; |
françois romieu | 126a3fd | 2012-03-16 01:52:04 +0000 | [diff] [blame] | 2234 | struct eni_zero *zero; |
| 2235 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | |
françois romieu | 126a3fd | 2012-03-16 01:52:04 +0000 | [diff] [blame] | 2237 | rc = pci_enable_device(pci_dev); |
| 2238 | if (rc < 0) |
| 2239 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2240 | |
françois romieu | 126a3fd | 2012-03-16 01:52:04 +0000 | [diff] [blame] | 2241 | rc = -ENOMEM; |
| 2242 | eni_dev = kmalloc(sizeof(struct eni_dev), GFP_KERNEL); |
| 2243 | if (!eni_dev) |
| 2244 | goto err_disable; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2245 | |
françois romieu | 126a3fd | 2012-03-16 01:52:04 +0000 | [diff] [blame] | 2246 | zero = &eni_dev->zero; |
| 2247 | zero->addr = pci_alloc_consistent(pci_dev, ENI_ZEROES_SIZE, &zero->dma); |
| 2248 | if (!zero->addr) |
| 2249 | goto err_kfree; |
| 2250 | |
Dan Williams | d9ca676 | 2010-12-08 19:40:47 +0000 | [diff] [blame] | 2251 | dev = atm_dev_register(DEV_LABEL, &pci_dev->dev, &ops, -1, NULL); |
françois romieu | 126a3fd | 2012-03-16 01:52:04 +0000 | [diff] [blame] | 2252 | if (!dev) |
| 2253 | goto err_free_consistent; |
| 2254 | |
| 2255 | dev->dev_data = eni_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2256 | pci_set_drvdata(pci_dev, dev); |
| 2257 | eni_dev->pci_dev = pci_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | eni_dev->asic = ent->driver_data; |
françois romieu | 126a3fd | 2012-03-16 01:52:04 +0000 | [diff] [blame] | 2259 | |
| 2260 | rc = eni_do_init(dev); |
| 2261 | if (rc < 0) |
| 2262 | goto err_unregister; |
| 2263 | |
| 2264 | rc = eni_start(dev); |
| 2265 | if (rc < 0) |
| 2266 | goto err_eni_release; |
| 2267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2268 | eni_dev->more = eni_boards; |
| 2269 | eni_boards = dev; |
françois romieu | 126a3fd | 2012-03-16 01:52:04 +0000 | [diff] [blame] | 2270 | out: |
| 2271 | return rc; |
| 2272 | |
| 2273 | err_eni_release: |
| 2274 | eni_do_release(dev); |
| 2275 | err_unregister: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2276 | atm_dev_deregister(dev); |
françois romieu | 126a3fd | 2012-03-16 01:52:04 +0000 | [diff] [blame] | 2277 | err_free_consistent: |
| 2278 | pci_free_consistent(pci_dev, ENI_ZEROES_SIZE, zero->addr, zero->dma); |
| 2279 | err_kfree: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2280 | kfree(eni_dev); |
françois romieu | 126a3fd | 2012-03-16 01:52:04 +0000 | [diff] [blame] | 2281 | err_disable: |
| 2282 | pci_disable_device(pci_dev); |
| 2283 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2284 | } |
| 2285 | |
| 2286 | |
| 2287 | static struct pci_device_id eni_pci_tbl[] = { |
Peter Huewe | 5352228 | 2010-07-15 08:41:08 +0000 | [diff] [blame] | 2288 | { PCI_VDEVICE(EF, PCI_DEVICE_ID_EF_ATM_FPGA), 0 /* FPGA */ }, |
| 2289 | { PCI_VDEVICE(EF, PCI_DEVICE_ID_EF_ATM_ASIC), 1 /* ASIC */ }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2290 | { 0, } |
| 2291 | }; |
| 2292 | MODULE_DEVICE_TABLE(pci,eni_pci_tbl); |
| 2293 | |
| 2294 | |
françois romieu | 126a3fd | 2012-03-16 01:52:04 +0000 | [diff] [blame] | 2295 | static void __devexit eni_remove_one(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2296 | { |
françois romieu | 126a3fd | 2012-03-16 01:52:04 +0000 | [diff] [blame] | 2297 | struct atm_dev *dev = pci_get_drvdata(pdev); |
| 2298 | struct eni_dev *ed = ENI_DEV(dev); |
| 2299 | struct eni_zero *zero = &ed->zero; |
| 2300 | |
| 2301 | eni_do_release(dev); |
| 2302 | atm_dev_deregister(dev); |
| 2303 | pci_free_consistent(pdev, ENI_ZEROES_SIZE, zero->addr, zero->dma); |
| 2304 | kfree(ed); |
| 2305 | pci_disable_device(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2306 | } |
| 2307 | |
| 2308 | |
| 2309 | static struct pci_driver eni_driver = { |
| 2310 | .name = DEV_LABEL, |
| 2311 | .id_table = eni_pci_tbl, |
| 2312 | .probe = eni_init_one, |
| 2313 | .remove = __devexit_p(eni_remove_one), |
| 2314 | }; |
| 2315 | |
| 2316 | |
| 2317 | static int __init eni_init(void) |
| 2318 | { |
| 2319 | struct sk_buff *skb; /* dummy for sizeof */ |
| 2320 | |
| 2321 | if (sizeof(skb->cb) < sizeof(struct eni_skb_prv)) { |
| 2322 | printk(KERN_ERR "eni_detect: skb->cb is too small (%Zd < %Zd)\n", |
| 2323 | sizeof(skb->cb),sizeof(struct eni_skb_prv)); |
| 2324 | return -EIO; |
| 2325 | } |
| 2326 | return pci_register_driver(&eni_driver); |
| 2327 | } |
| 2328 | |
| 2329 | |
| 2330 | module_init(eni_init); |
| 2331 | /* @@@ since exit routine not defined, this module can not be unloaded */ |
| 2332 | |
| 2333 | MODULE_LICENSE("GPL"); |