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