1 // SPDX-License-Identifier: GPL-2.0-only
2 /* drivers/atm/eni.c - Efficient Networks ENI155P device driver */
4 /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
7 #include <linux/module.h>
8 #include <linux/kernel.h>
10 #include <linux/pci.h>
11 #include <linux/errno.h>
12 #include <linux/atm.h>
13 #include <linux/atmdev.h>
14 #include <linux/sonet.h>
15 #include <linux/skbuff.h>
16 #include <linux/time.h>
17 #include <linux/delay.h>
18 #include <linux/uio.h>
19 #include <linux/init.h>
20 #include <linux/atm_eni.h>
21 #include <linux/bitops.h>
22 #include <linux/slab.h>
24 #include <linux/atomic.h>
25 #include <linux/uaccess.h>
26 #include <asm/string.h>
27 #include <asm/byteorder.h>
42 * - fix bugs listed below
48 * - may run into JK-JK bug and deadlock
49 * - should allocate UBR channel first
50 * - buffer space allocation algorithm is stupid
51 * (RX: should be maxSDU+maxdelay*rate
52 * TX: should be maxSDU+min(maxSDU,maxdelay*rate) )
53 * - doesn't support OAM cells
54 * - eni_put_free may hang if not putting memory fragments that _complete_
55 * 2^n block (never happens in real life, though)
60 #define DPRINTK(format,args...) printk(KERN_DEBUG format,##args)
62 #define DPRINTK(format,args...)
66 #ifndef CONFIG_ATM_ENI_TUNE_BURST
67 #define CONFIG_ATM_ENI_BURST_TX_8W
68 #define CONFIG_ATM_ENI_BURST_RX_4W
72 #ifndef CONFIG_ATM_ENI_DEBUG
80 static void event_dump(void)
89 * NULL pointer checking
92 #define NULLCHECK(x) \
93 if ((unsigned long) (x) < 0x30) \
94 printk(KERN_CRIT #x "==0x%lx\n",(unsigned long) (x))
97 * Very extensive activity logging. Greatly improves bug detection speed but
98 * costs a few Mbps if enabled.
103 static const char *ev[EV];
104 static unsigned long ev_a[EV],ev_b[EV];
108 static void EVENT(const char *s,unsigned long a,unsigned long b)
117 static void event_dump(void)
121 for (n = 0; n < EV; n++) {
124 printk(ev[i] ? ev[i] : "(null)",ev_a[i],ev_b[i]);
129 #endif /* CONFIG_ATM_ENI_DEBUG */
133 * NExx must not be equal at end
134 * EExx may be equal at end
135 * xxPJOK verify validity of pointer jumps
136 * xxPMOK operating on a circular buffer of "c" words
139 #define NEPJOK(a0,a1,b) \
140 ((a0) < (a1) ? (b) <= (a0) || (b) > (a1) : (b) <= (a0) && (b) > (a1))
141 #define EEPJOK(a0,a1,b) \
142 ((a0) < (a1) ? (b) < (a0) || (b) >= (a1) : (b) < (a0) && (b) >= (a1))
143 #define NEPMOK(a0,d,b,c) NEPJOK(a0,(a0+d) & (c-1),b)
144 #define EEPMOK(a0,d,b,c) EEPJOK(a0,(a0+d) & (c-1),b)
147 static int tx_complete = 0,dma_complete = 0,queued = 0,requeued = 0,
148 backlogged = 0,rx_enqueued = 0,rx_dequeued = 0,pushed = 0,submitted = 0,
151 static struct atm_dev *eni_boards = NULL;
153 /* Read/write registers on card */
154 #define eni_in(r) readl(eni_dev->reg+(r)*4)
155 #define eni_out(v,r) writel((v),eni_dev->reg+(r)*4)
158 /*-------------------------------- utilities --------------------------------*/
161 static void dump_mem(struct eni_dev *eni_dev)
165 for (i = 0; i < eni_dev->free_len; i++)
166 printk(KERN_DEBUG " %d: %p %d\n",i,
167 eni_dev->free_list[i].start,
168 1 << eni_dev->free_list[i].order);
172 static void dump(struct atm_dev *dev)
174 struct eni_dev *eni_dev;
178 eni_dev = ENI_DEV(dev);
179 printk(KERN_NOTICE "Free memory\n");
181 printk(KERN_NOTICE "TX buffers\n");
182 for (i = 0; i < NR_CHAN; i++)
183 if (eni_dev->tx[i].send)
184 printk(KERN_NOTICE " TX %d @ %p: %ld\n",i,
185 eni_dev->tx[i].send,eni_dev->tx[i].words*4);
186 printk(KERN_NOTICE "RX buffers\n");
187 for (i = 0; i < 1024; i++)
188 if (eni_dev->rx_map[i] && ENI_VCC(eni_dev->rx_map[i])->rx)
189 printk(KERN_NOTICE " RX %d @ %p: %ld\n",i,
190 ENI_VCC(eni_dev->rx_map[i])->recv,
191 ENI_VCC(eni_dev->rx_map[i])->words*4);
192 printk(KERN_NOTICE "----\n");
196 static void eni_put_free(struct eni_dev *eni_dev, void __iomem *start,
199 struct eni_free *list;
202 DPRINTK("init 0x%lx+%ld(0x%lx)\n",start,size,size);
203 start += eni_dev->base_diff;
204 list = eni_dev->free_list;
205 len = eni_dev->free_len;
207 if (len >= eni_dev->free_list_size) {
208 printk(KERN_CRIT "eni_put_free overflow (%p,%ld)\n",
212 for (order = 0; !(((unsigned long)start | size) & (1 << order)); order++);
213 if (MID_MIN_BUF_SIZE > (1 << order)) {
214 printk(KERN_CRIT "eni_put_free: order %d too small\n",
218 list[len].start = (void __iomem *) start;
219 list[len].order = order;
224 eni_dev->free_len = len;
225 /*dump_mem(eni_dev);*/
229 static void __iomem *eni_alloc_mem(struct eni_dev *eni_dev, unsigned long *size)
231 struct eni_free *list;
233 int len,i,order,best_order,index;
235 list = eni_dev->free_list;
236 len = eni_dev->free_len;
237 if (*size < MID_MIN_BUF_SIZE) *size = MID_MIN_BUF_SIZE;
238 if (*size > MID_MAX_BUF_SIZE) return NULL;
239 for (order = 0; (1 << order) < *size; order++)
241 DPRINTK("trying: %ld->%d\n",*size,order);
242 best_order = 65; /* we don't have more than 2^64 of anything ... */
243 index = 0; /* silence GCC */
244 for (i = 0; i < len; i++)
245 if (list[i].order == order) {
250 else if (best_order > list[i].order && list[i].order > order) {
251 best_order = list[i].order;
254 if (best_order == 65) return NULL;
255 start = list[index].start-eni_dev->base_diff;
256 list[index] = list[--len];
257 eni_dev->free_len = len;
259 eni_put_free(eni_dev,start+*size,(1 << best_order)-*size);
260 DPRINTK("%ld bytes (order %d) at 0x%lx\n",*size,order,start);
261 memset_io(start,0,*size); /* never leak data */
262 /*dump_mem(eni_dev);*/
267 static void eni_free_mem(struct eni_dev *eni_dev, void __iomem *start,
270 struct eni_free *list;
273 start += eni_dev->base_diff;
274 list = eni_dev->free_list;
275 len = eni_dev->free_len;
276 for (order = -1; size; order++) size >>= 1;
277 DPRINTK("eni_free_mem: %p+0x%lx (order %d)\n",start,size,order);
278 for (i = 0; i < len; i++)
279 if (((unsigned long) list[i].start) == ((unsigned long)start^(1 << order)) &&
280 list[i].order == order) {
281 DPRINTK("match[%d]: 0x%lx/0x%lx(0x%x), %d/%d\n",i,
282 list[i].start,start,1 << order,list[i].order,order);
283 list[i] = list[--len];
284 start = (void __iomem *) ((unsigned long) start & ~(unsigned long) (1 << order));
289 if (len >= eni_dev->free_list_size) {
290 printk(KERN_ALERT "eni_free_mem overflow (%p,%d)\n",start,
294 list[len].start = start;
295 list[len].order = order;
296 eni_dev->free_len = len+1;
297 /*dump_mem(eni_dev);*/
301 /*----------------------------------- RX ------------------------------------*/
304 #define ENI_VCC_NOS ((struct atm_vcc *) 1)
307 static void rx_ident_err(struct atm_vcc *vcc)
310 struct eni_dev *eni_dev;
311 struct eni_vcc *eni_vcc;
314 eni_dev = ENI_DEV(dev);
315 /* immediately halt adapter */
316 eni_out(eni_in(MID_MC_S) &
317 ~(MID_DMA_ENABLE | MID_TX_ENABLE | MID_RX_ENABLE),MID_MC_S);
318 /* dump useful information */
319 eni_vcc = ENI_VCC(vcc);
320 printk(KERN_ALERT DEV_LABEL "(itf %d): driver error - RX ident "
321 "mismatch\n",dev->number);
322 printk(KERN_ALERT " VCI %d, rxing %d, words %ld\n",vcc->vci,
323 eni_vcc->rxing,eni_vcc->words);
324 printk(KERN_ALERT " host descr 0x%lx, rx pos 0x%lx, descr value "
325 "0x%x\n",eni_vcc->descr,eni_vcc->rx_pos,
326 (unsigned) readl(eni_vcc->recv+eni_vcc->descr*4));
327 printk(KERN_ALERT " last %p, servicing %d\n",eni_vcc->last,
329 EVENT("---dump ends here---\n",0,0);
330 printk(KERN_NOTICE "---recent events---\n");
332 ENI_DEV(dev)->fast = NULL; /* really stop it */
333 ENI_DEV(dev)->slow = NULL;
334 skb_queue_head_init(&ENI_DEV(dev)->rx_queue);
338 static int do_rx_dma(struct atm_vcc *vcc,struct sk_buff *skb,
339 unsigned long skip,unsigned long size,unsigned long eff)
341 struct eni_dev *eni_dev;
342 struct eni_vcc *eni_vcc;
344 u32 dma[RX_DMA_BUF*2];
349 eni_dev = ENI_DEV(vcc->dev);
350 eni_vcc = ENI_VCC(vcc);
351 paddr = 0; /* GCC, shut up */
353 paddr = dma_map_single(&eni_dev->pci_dev->dev,skb->data,skb->len,
355 if (dma_mapping_error(&eni_dev->pci_dev->dev, paddr))
357 ENI_PRV_PADDR(skb) = paddr;
359 printk(KERN_CRIT DEV_LABEL "(itf %d): VCI %d has "
360 "mis-aligned RX data (0x%lx)\n",vcc->dev->number,
361 vcc->vci,(unsigned long) paddr);
362 ENI_PRV_SIZE(skb) = size+skip;
363 /* PDU plus descriptor */
364 ATM_SKB(skb)->vcc = vcc;
367 if ((eff && skip) || 1) { /* @@@ actually, skip is always == 1 ... */
368 here = (eni_vcc->descr+skip) & (eni_vcc->words-1);
369 dma[j++] = (here << MID_DMA_COUNT_SHIFT) | (vcc->vci
370 << MID_DMA_VCI_SHIFT) | MID_DT_JK;
373 here = (eni_vcc->descr+size+skip) & (eni_vcc->words-1);
374 if (!eff) size += skip;
379 DPRINTK("strange things happen ...\n");
380 EVENT("strange things happen ... (skip=%ld,eff=%ld)\n",
387 init = 4-((paddr & 15) >> 2);
388 if (init > words) init = words;
389 dma[j++] = MID_DT_WORD | (init << MID_DMA_COUNT_SHIFT) |
390 (vcc->vci << MID_DMA_VCI_SHIFT);
395 #ifdef CONFIG_ATM_ENI_BURST_RX_16W /* may work with some PCI chipsets ... */
397 dma[j++] = MID_DT_16W | ((words >> 4) <<
398 MID_DMA_COUNT_SHIFT) | (vcc->vci <<
401 paddr += (words & ~15) << 2;
405 #ifdef CONFIG_ATM_ENI_BURST_RX_8W /* works only with *some* PCI chipsets ... */
407 dma[j++] = MID_DT_8W | ((words >> 3) <<
408 MID_DMA_COUNT_SHIFT) | (vcc->vci <<
411 paddr += (words & ~7) << 2;
415 #ifdef CONFIG_ATM_ENI_BURST_RX_4W /* recommended */
417 dma[j++] = MID_DT_4W | ((words >> 2) <<
418 MID_DMA_COUNT_SHIFT) | (vcc->vci <<
421 paddr += (words & ~3) << 2;
425 #ifdef CONFIG_ATM_ENI_BURST_RX_2W /* probably useless if RX_4W, RX_8W, ... */
427 dma[j++] = MID_DT_2W | ((words >> 1) <<
428 MID_DMA_COUNT_SHIFT) | (vcc->vci <<
431 paddr += (words & ~1) << 2;
436 dma[j++] = MID_DT_WORD | (words << MID_DMA_COUNT_SHIFT)
437 | (vcc->vci << MID_DMA_VCI_SHIFT);
442 dma[j++] = (here << MID_DMA_COUNT_SHIFT) |
443 (vcc->vci << MID_DMA_VCI_SHIFT) | MID_DT_JK;
446 if (!j || j > 2*RX_DMA_BUF) {
447 printk(KERN_CRIT DEV_LABEL "!j or j too big!!!\n");
450 dma[j-2] |= MID_DMA_END;
452 dma_wr = eni_in(MID_DMA_WR_RX);
453 dma_rd = eni_in(MID_DMA_RD_RX);
455 * Can I move the dma_wr pointer by 2j+1 positions without overwriting
456 * data that hasn't been read (position of dma_rd) yet ?
458 if (!NEPMOK(dma_wr,j+j+1,dma_rd,NR_DMA_RX)) { /* @@@ +1 is ugly */
459 printk(KERN_WARNING DEV_LABEL "(itf %d): RX DMA full\n",
463 for (i = 0; i < j; i++) {
464 writel(dma[i*2],eni_dev->rx_dma+dma_wr*8);
465 writel(dma[i*2+1],eni_dev->rx_dma+dma_wr*8+4);
466 dma_wr = (dma_wr+1) & (NR_DMA_RX-1);
469 ENI_PRV_POS(skb) = eni_vcc->descr+size+1;
470 skb_queue_tail(&eni_dev->rx_queue,skb);
474 eni_vcc->descr = here;
475 eni_out(dma_wr,MID_DMA_WR_RX);
480 dma_unmap_single(&eni_dev->pci_dev->dev,paddr,skb->len,
483 if (skb) dev_kfree_skb_irq(skb);
488 static void discard(struct atm_vcc *vcc,unsigned long size)
490 struct eni_vcc *eni_vcc;
492 eni_vcc = ENI_VCC(vcc);
493 EVENT("discard (size=%ld)\n",size,0);
494 while (do_rx_dma(vcc,NULL,1,size,0)) EVENT("BUSY LOOP",0,0);
495 /* could do a full fallback, but that might be more expensive */
496 if (eni_vcc->rxing) ENI_PRV_POS(eni_vcc->last) += size+1;
497 else eni_vcc->rx_pos = (eni_vcc->rx_pos+size+1) & (eni_vcc->words-1);
502 * TODO: should check whether direct copies (without DMA setup, dequeuing on
503 * interrupt, etc.) aren't much faster for AAL0
506 static int rx_aal0(struct atm_vcc *vcc)
508 struct eni_vcc *eni_vcc;
510 unsigned long length;
513 DPRINTK(">rx_aal0\n");
514 eni_vcc = ENI_VCC(vcc);
515 descr = readl(eni_vcc->recv+eni_vcc->descr*4);
516 if ((descr & MID_RED_IDEN) != (MID_RED_RX_ID << MID_RED_SHIFT)) {
520 if (descr & MID_RED_T) {
521 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
524 atomic_inc(&vcc->stats->rx_err);
527 length = ATM_CELL_SIZE-1; /* no HEC */
529 skb = length ? atm_alloc_charge(vcc,length,GFP_ATOMIC) : NULL;
531 discard(vcc,length >> 2);
535 skb->tstamp = eni_vcc->timestamp;
536 DPRINTK("got len %ld\n",length);
537 if (do_rx_dma(vcc,skb,1,length >> 2,length >> 2)) return 1;
543 static int rx_aal5(struct atm_vcc *vcc)
545 struct eni_vcc *eni_vcc;
547 unsigned long size,eff,length;
550 EVENT("rx_aal5\n",0,0);
551 DPRINTK(">rx_aal5\n");
552 eni_vcc = ENI_VCC(vcc);
553 descr = readl(eni_vcc->recv+eni_vcc->descr*4);
554 if ((descr & MID_RED_IDEN) != (MID_RED_RX_ID << MID_RED_SHIFT)) {
558 if (descr & (MID_RED_T | MID_RED_CRC_ERR)) {
559 if (descr & MID_RED_T) {
560 EVENT("empty cell (descr=0x%lx)\n",descr,0);
561 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
566 static unsigned long silence = 0;
568 if (time_after(jiffies, silence) || silence == 0) {
569 printk(KERN_WARNING DEV_LABEL "(itf %d): "
570 "discarding PDU(s) with CRC error\n",
572 silence = (jiffies+2*HZ)|1;
574 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
575 EVENT("CRC error (descr=0x%lx,size=%ld)\n",descr,
579 atomic_inc(&vcc->stats->rx_err);
582 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
583 DPRINTK("size=%ld\n",size);
584 length = readl(eni_vcc->recv+(((eni_vcc->descr+size-1) &
585 (eni_vcc->words-1)))*4) & 0xffff;
586 /* -trailer(2)+header(1) */
587 if (length && length <= (size << 2)-8 && length <=
588 ATM_MAX_AAL5_PDU) eff = (length+3) >> 2;
589 else { /* ^ trailer length (8) */
590 EVENT("bad PDU (descr=0x08%lx,length=%ld)\n",descr,
592 printk(KERN_ERR DEV_LABEL "(itf %d): bad AAL5 PDU "
593 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
594 vcc->dev->number,vcc->vci,length,size << 2,descr);
596 atomic_inc(&vcc->stats->rx_err);
599 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
605 DPRINTK("got len %ld\n",length);
606 if (do_rx_dma(vcc,skb,1,size,eff)) return 1;
612 static inline int rx_vcc(struct atm_vcc *vcc)
614 void __iomem *vci_dsc;
616 struct eni_vcc *eni_vcc;
618 eni_vcc = ENI_VCC(vcc);
619 vci_dsc = ENI_DEV(vcc->dev)->vci+vcc->vci*16;
620 EVENT("rx_vcc(1)\n",0,0);
621 while (eni_vcc->descr != (tmp = (readl(vci_dsc+4) & MID_VCI_DESCR) >>
622 MID_VCI_DESCR_SHIFT)) {
623 EVENT("rx_vcc(2: host dsc=0x%lx, nic dsc=0x%lx)\n",
625 DPRINTK("CB_DESCR %ld REG_DESCR %d\n",ENI_VCC(vcc)->descr,
626 (((unsigned) readl(vci_dsc+4) & MID_VCI_DESCR) >>
627 MID_VCI_DESCR_SHIFT));
628 if (ENI_VCC(vcc)->rx(vcc)) return 1;
630 /* clear IN_SERVICE flag */
631 writel(readl(vci_dsc) & ~MID_VCI_IN_SERVICE,vci_dsc);
633 * If new data has arrived between evaluating the while condition and
634 * clearing IN_SERVICE, we wouldn't be notified until additional data
635 * follows. So we have to loop again to be sure.
637 EVENT("rx_vcc(3)\n",0,0);
638 while (ENI_VCC(vcc)->descr != (tmp = (readl(vci_dsc+4) & MID_VCI_DESCR)
639 >> MID_VCI_DESCR_SHIFT)) {
640 EVENT("rx_vcc(4: host dsc=0x%lx, nic dsc=0x%lx)\n",
642 DPRINTK("CB_DESCR %ld REG_DESCR %d\n",ENI_VCC(vcc)->descr,
643 (((unsigned) readl(vci_dsc+4) & MID_VCI_DESCR) >>
644 MID_VCI_DESCR_SHIFT));
645 if (ENI_VCC(vcc)->rx(vcc)) return 1;
651 static void poll_rx(struct atm_dev *dev)
653 struct eni_dev *eni_dev;
654 struct atm_vcc *curr;
656 eni_dev = ENI_DEV(dev);
657 while ((curr = eni_dev->fast)) {
658 EVENT("poll_rx.fast\n",0,0);
659 if (rx_vcc(curr)) return;
660 eni_dev->fast = ENI_VCC(curr)->next;
661 ENI_VCC(curr)->next = ENI_VCC_NOS;
663 ENI_VCC(curr)->servicing--;
665 while ((curr = eni_dev->slow)) {
666 EVENT("poll_rx.slow\n",0,0);
667 if (rx_vcc(curr)) return;
668 eni_dev->slow = ENI_VCC(curr)->next;
669 ENI_VCC(curr)->next = ENI_VCC_NOS;
671 ENI_VCC(curr)->servicing--;
676 static void get_service(struct atm_dev *dev)
678 struct eni_dev *eni_dev;
682 DPRINTK(">get_service\n");
683 eni_dev = ENI_DEV(dev);
684 while (eni_in(MID_SERV_WRITE) != eni_dev->serv_read) {
685 vci = readl(eni_dev->service+eni_dev->serv_read*4);
686 eni_dev->serv_read = (eni_dev->serv_read+1) & (NR_SERVICE-1);
687 vcc = eni_dev->rx_map[vci & 1023];
689 printk(KERN_CRIT DEV_LABEL "(itf %d): VCI %ld not "
690 "found\n",dev->number,vci);
691 continue; /* nasty but we try to go on anyway */
692 /* @@@ nope, doesn't work */
694 EVENT("getting from service\n",0,0);
695 if (ENI_VCC(vcc)->next != ENI_VCC_NOS) {
696 EVENT("double service\n",0,0);
697 DPRINTK("Grr, servicing VCC %ld twice\n",vci);
700 ENI_VCC(vcc)->timestamp = ktime_get_real();
701 ENI_VCC(vcc)->next = NULL;
702 if (vcc->qos.rxtp.traffic_class == ATM_CBR) {
704 ENI_VCC(eni_dev->last_fast)->next = vcc;
705 else eni_dev->fast = vcc;
706 eni_dev->last_fast = vcc;
710 ENI_VCC(eni_dev->last_slow)->next = vcc;
711 else eni_dev->slow = vcc;
712 eni_dev->last_slow = vcc;
715 ENI_VCC(vcc)->servicing++;
720 static void dequeue_rx(struct atm_dev *dev)
722 struct eni_dev *eni_dev;
723 struct eni_vcc *eni_vcc;
726 void __iomem *vci_dsc;
729 eni_dev = ENI_DEV(dev);
732 skb = skb_dequeue(&eni_dev->rx_queue);
735 DPRINTK(DEV_LABEL "(itf %d): RX but not "
736 "rxing\n",dev->number);
737 EVENT("nothing to dequeue\n",0,0);
741 EVENT("dequeued (size=%ld,pos=0x%lx)\n",ENI_PRV_SIZE(skb),
744 vcc = ATM_SKB(skb)->vcc;
745 eni_vcc = ENI_VCC(vcc);
747 vci_dsc = eni_dev->vci+vcc->vci*16;
748 if (!EEPMOK(eni_vcc->rx_pos,ENI_PRV_SIZE(skb),
749 (readl(vci_dsc+4) & MID_VCI_READ) >> MID_VCI_READ_SHIFT,
751 EVENT("requeuing\n",0,0);
752 skb_queue_head(&eni_dev->rx_queue,skb);
756 eni_vcc->rx_pos = ENI_PRV_POS(skb) & (eni_vcc->words-1);
757 dma_unmap_single(&eni_dev->pci_dev->dev,ENI_PRV_PADDR(skb),skb->len,
759 if (!skb->len) dev_kfree_skb_irq(skb);
761 EVENT("pushing (len=%ld)\n",skb->len,0);
762 if (vcc->qos.aal == ATM_AAL0)
763 *(unsigned long *) skb->data =
764 ntohl(*(unsigned long *) skb->data);
765 memset(skb->cb,0,sizeof(struct eni_skb_prv));
769 atomic_inc(&vcc->stats->rx);
771 wake_up(&eni_dev->rx_wait);
775 static int open_rx_first(struct atm_vcc *vcc)
777 struct eni_dev *eni_dev;
778 struct eni_vcc *eni_vcc;
781 DPRINTK("open_rx_first\n");
782 eni_dev = ENI_DEV(vcc->dev);
783 eni_vcc = ENI_VCC(vcc);
785 if (vcc->qos.rxtp.traffic_class == ATM_NONE) return 0;
786 size = vcc->qos.rxtp.max_sdu*eni_dev->rx_mult/100;
787 if (size > MID_MAX_BUF_SIZE && vcc->qos.rxtp.max_sdu <=
789 size = MID_MAX_BUF_SIZE;
790 eni_vcc->recv = eni_alloc_mem(eni_dev,&size);
791 DPRINTK("rx at 0x%lx\n",eni_vcc->recv);
792 eni_vcc->words = size >> 2;
793 if (!eni_vcc->recv) return -ENOBUFS;
794 eni_vcc->rx = vcc->qos.aal == ATM_AAL5 ? rx_aal5 : rx_aal0;
798 eni_vcc->servicing = 0;
799 eni_vcc->next = ENI_VCC_NOS;
804 static int open_rx_second(struct atm_vcc *vcc)
807 struct eni_dev *eni_dev;
808 struct eni_vcc *eni_vcc;
812 DPRINTK("open_rx_second\n");
813 eni_dev = ENI_DEV(vcc->dev);
814 eni_vcc = ENI_VCC(vcc);
815 if (!eni_vcc->rx) return 0;
816 /* set up VCI descriptor */
817 here = eni_dev->vci+vcc->vci*16;
818 DPRINTK("loc 0x%x\n",(unsigned) (eni_vcc->recv-eni_dev->ram)/4);
819 size = eni_vcc->words >> 8;
820 for (order = -1; size; order++) size >>= 1;
821 writel(0,here+4); /* descr, read = 0 */
822 writel(0,here+8); /* write, state, count = 0 */
823 if (eni_dev->rx_map[vcc->vci])
824 printk(KERN_CRIT DEV_LABEL "(itf %d): BUG - VCI %d already "
825 "in use\n",vcc->dev->number,vcc->vci);
826 eni_dev->rx_map[vcc->vci] = vcc; /* now it counts */
827 writel(((vcc->qos.aal != ATM_AAL5 ? MID_MODE_RAW : MID_MODE_AAL5) <<
828 MID_VCI_MODE_SHIFT) | MID_VCI_PTI_MODE |
829 (((eni_vcc->recv-eni_dev->ram) >> (MID_LOC_SKIP+2)) <<
830 MID_VCI_LOCATION_SHIFT) | (order << MID_VCI_SIZE_SHIFT),here);
835 static void close_rx(struct atm_vcc *vcc)
837 DECLARE_WAITQUEUE(wait,current);
839 struct eni_dev *eni_dev;
840 struct eni_vcc *eni_vcc;
842 eni_vcc = ENI_VCC(vcc);
843 if (!eni_vcc->rx) return;
844 eni_dev = ENI_DEV(vcc->dev);
845 if (vcc->vpi != ATM_VPI_UNSPEC && vcc->vci != ATM_VCI_UNSPEC) {
846 here = eni_dev->vci+vcc->vci*16;
848 writel((readl(here) & ~MID_VCI_MODE) | (MID_MODE_TRASH <<
849 MID_VCI_MODE_SHIFT),here);
850 /* wait for receiver to become idle */
852 /* discard pending cell */
853 writel(readl(here) & ~MID_VCI_IN_SERVICE,here);
854 /* don't accept any new ones */
855 eni_dev->rx_map[vcc->vci] = NULL;
856 /* wait for RX queue to drain */
857 DPRINTK("eni_close: waiting for RX ...\n");
858 EVENT("RX closing\n",0,0);
859 add_wait_queue(&eni_dev->rx_wait,&wait);
860 set_current_state(TASK_UNINTERRUPTIBLE);
863 /* transition service->rx: rxing++, servicing-- */
864 if (!eni_vcc->servicing) {
866 if (!eni_vcc->rxing) break;
868 EVENT("drain PDUs (rx %ld, serv %ld)\n",eni_vcc->rxing,
870 printk(KERN_INFO "%d+%d RX left\n",eni_vcc->servicing,
873 set_current_state(TASK_UNINTERRUPTIBLE);
879 tasklet_disable(&eni_dev->task);
880 tmp = readl(eni_dev->vci+vcc->vci*16+4) & MID_VCI_READ;
881 at_end = eni_vcc->rx_pos == tmp >> MID_VCI_READ_SHIFT;
882 tasklet_enable(&eni_dev->task);
884 EVENT("drain discard (host 0x%lx, nic 0x%lx)\n",
885 eni_vcc->rx_pos,tmp);
886 printk(KERN_INFO "draining RX: host 0x%lx, nic 0x%x\n",
887 eni_vcc->rx_pos,tmp);
889 set_current_state(TASK_UNINTERRUPTIBLE);
891 set_current_state(TASK_RUNNING);
892 remove_wait_queue(&eni_dev->rx_wait,&wait);
894 eni_free_mem(eni_dev,eni_vcc->recv,eni_vcc->words << 2);
899 static int start_rx(struct atm_dev *dev)
901 struct eni_dev *eni_dev;
903 eni_dev = ENI_DEV(dev);
904 eni_dev->rx_map = (struct atm_vcc **) get_zeroed_page(GFP_KERNEL);
905 if (!eni_dev->rx_map) {
906 printk(KERN_ERR DEV_LABEL "(itf %d): couldn't get free page\n",
908 free_page((unsigned long) eni_dev->free_list);
911 eni_dev->rx_mult = DEFAULT_RX_MULT;
912 eni_dev->fast = eni_dev->last_fast = NULL;
913 eni_dev->slow = eni_dev->last_slow = NULL;
914 init_waitqueue_head(&eni_dev->rx_wait);
915 skb_queue_head_init(&eni_dev->rx_queue);
916 eni_dev->serv_read = eni_in(MID_SERV_WRITE);
917 eni_out(0,MID_DMA_WR_RX);
922 /*----------------------------------- TX ------------------------------------*/
925 enum enq_res { enq_ok,enq_next,enq_jam };
928 static inline void put_dma(int chan,u32 *dma,int *j,dma_addr_t paddr,
933 DPRINTK("put_dma: 0x%lx+0x%x\n",(unsigned long) paddr,size);
934 EVENT("put_dma: 0x%lx+0x%lx\n",(unsigned long) paddr,size);
935 #if 0 /* don't complain anymore */
937 printk(KERN_ERR "put_dma: unaligned addr (0x%lx)\n",paddr);
939 printk(KERN_ERR "put_dma: unaligned size (0x%lx)\n",size);
942 init = 4-(paddr & 3);
943 if (init > size || size < 7) init = size;
944 DPRINTK("put_dma: %lx DMA: %d/%d bytes\n",
945 (unsigned long) paddr,init,size);
946 dma[(*j)++] = MID_DT_BYTE | (init << MID_DMA_COUNT_SHIFT) |
947 (chan << MID_DMA_CHAN_SHIFT);
954 if (words && (paddr & 31)) {
955 init = 8-((paddr & 31) >> 2);
956 if (init > words) init = words;
957 DPRINTK("put_dma: %lx DMA: %d/%d words\n",
958 (unsigned long) paddr,init,words);
959 dma[(*j)++] = MID_DT_WORD | (init << MID_DMA_COUNT_SHIFT) |
960 (chan << MID_DMA_CHAN_SHIFT);
965 #ifdef CONFIG_ATM_ENI_BURST_TX_16W /* may work with some PCI chipsets ... */
967 DPRINTK("put_dma: %lx DMA: %d*16/%d words\n",
968 (unsigned long) paddr,words >> 4,words);
969 dma[(*j)++] = MID_DT_16W | ((words >> 4) << MID_DMA_COUNT_SHIFT)
970 | (chan << MID_DMA_CHAN_SHIFT);
972 paddr += (words & ~15) << 2;
976 #ifdef CONFIG_ATM_ENI_BURST_TX_8W /* recommended */
978 DPRINTK("put_dma: %lx DMA: %d*8/%d words\n",
979 (unsigned long) paddr,words >> 3,words);
980 dma[(*j)++] = MID_DT_8W | ((words >> 3) << MID_DMA_COUNT_SHIFT)
981 | (chan << MID_DMA_CHAN_SHIFT);
983 paddr += (words & ~7) << 2;
987 #ifdef CONFIG_ATM_ENI_BURST_TX_4W /* probably useless if TX_8W or TX_16W */
989 DPRINTK("put_dma: %lx DMA: %d*4/%d words\n",
990 (unsigned long) paddr,words >> 2,words);
991 dma[(*j)++] = MID_DT_4W | ((words >> 2) << MID_DMA_COUNT_SHIFT)
992 | (chan << MID_DMA_CHAN_SHIFT);
994 paddr += (words & ~3) << 2;
998 #ifdef CONFIG_ATM_ENI_BURST_TX_2W /* probably useless if TX_4W, TX_8W, ... */
1000 DPRINTK("put_dma: %lx DMA: %d*2/%d words\n",
1001 (unsigned long) paddr,words >> 1,words);
1002 dma[(*j)++] = MID_DT_2W | ((words >> 1) << MID_DMA_COUNT_SHIFT)
1003 | (chan << MID_DMA_CHAN_SHIFT);
1004 dma[(*j)++] = paddr;
1005 paddr += (words & ~1) << 2;
1010 DPRINTK("put_dma: %lx DMA: %d words\n",(unsigned long) paddr,
1012 dma[(*j)++] = MID_DT_WORD | (words << MID_DMA_COUNT_SHIFT) |
1013 (chan << MID_DMA_CHAN_SHIFT);
1014 dma[(*j)++] = paddr;
1015 paddr += words << 2;
1018 DPRINTK("put_dma: %lx DMA: %d bytes\n",(unsigned long) paddr,
1020 dma[(*j)++] = MID_DT_BYTE | (size << MID_DMA_COUNT_SHIFT) |
1021 (chan << MID_DMA_CHAN_SHIFT);
1022 dma[(*j)++] = paddr;
1027 static enum enq_res do_tx(struct sk_buff *skb)
1029 struct atm_vcc *vcc;
1030 struct eni_dev *eni_dev;
1031 struct eni_vcc *eni_vcc;
1035 u32 size; /* in words */
1036 int aal5,dma_size,i,j;
1037 unsigned char skb_data3;
1039 DPRINTK(">do_tx\n");
1041 EVENT("do_tx: skb=0x%lx, %ld bytes\n",(unsigned long) skb,skb->len);
1042 vcc = ATM_SKB(skb)->vcc;
1044 eni_dev = ENI_DEV(vcc->dev);
1046 eni_vcc = ENI_VCC(vcc);
1049 #if 0 /* Enable this for testing with the "align" program */
1051 unsigned int hack = *((char *) skb->data)-'0';
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);
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 :-)
1070 aal5 = vcc->qos.aal == ATM_AAL5;
1071 /* check space in buffer */
1073 size = (ATM_CELL_PAYLOAD >> 2)+TX_DESCR_SIZE;
1074 /* cell without HEC plus segmentation header (includes
1075 four-byte cell header) */
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 */
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".
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);
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);
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)) <
1108 printk(KERN_WARNING DEV_LABEL "(itf %d): TX DMA full\n",
1112 skb_data3 = skb->data[3];
1113 paddr = dma_map_single(&eni_dev->pci_dev->dev,skb->data,skb->len,
1115 if (dma_mapping_error(&eni_dev->pci_dev->dev, paddr))
1117 ENI_PRV_PADDR(skb) = paddr;
1118 /* prepare DMA queue entries */
1120 eni_dev->dma[j++] = (((tx->tx_pos+TX_DESCR_SIZE) & (tx->words-1)) <<
1121 MID_DMA_COUNT_SHIFT) | (tx->index << MID_DMA_CHAN_SHIFT) |
1124 if (!skb_shinfo(skb)->nr_frags)
1125 if (aal5) put_dma(tx->index,eni_dev->dma,&j,paddr,skb->len);
1126 else put_dma(tx->index,eni_dev->dma,&j,paddr+4,skb->len-4);
1128 DPRINTK("doing direct send\n"); /* @@@ well, this doesn't work anyway */
1129 for (i = -1; i < skb_shinfo(skb)->nr_frags; i++)
1131 put_dma(tx->index,eni_dev->dma,&j,(unsigned long)
1135 put_dma(tx->index,eni_dev->dma,&j,(unsigned long)
1136 skb_frag_page(&skb_shinfo(skb)->frags[i]) +
1137 skb_frag_off(&skb_shinfo(skb)->frags[i]),
1138 skb_frag_size(&skb_shinfo(skb)->frags[i]));
1141 put_dma(tx->index, eni_dev->dma, &j, eni_dev->zero.dma,
1142 4 - (skb->len & 3));
1144 /* JK for AAL5 trailer - AAL0 doesn't need it, but who cares ... */
1145 eni_dev->dma[j++] = (((tx->tx_pos+size) & (tx->words-1)) <<
1146 MID_DMA_COUNT_SHIFT) | (tx->index << MID_DMA_CHAN_SHIFT) |
1147 MID_DMA_END | MID_DT_JK;
1149 DPRINTK("DMA at end: %d\n",j);
1151 writel((MID_SEG_TX_ID << MID_SEG_ID_SHIFT) |
1152 (aal5 ? MID_SEG_AAL5 : 0) | (tx->prescaler << MID_SEG_PR_SHIFT) |
1153 (tx->resolution << MID_SEG_RATE_SHIFT) |
1154 (size/(ATM_CELL_PAYLOAD/4)),tx->send+tx->tx_pos*4);
1155 /*printk("dsc = 0x%08lx\n",(unsigned long) readl(tx->send+tx->tx_pos*4));*/
1156 writel((vcc->vci << MID_SEG_VCI_SHIFT) |
1157 (aal5 ? 0 : (skb_data3 & 0xf)) |
1158 (ATM_SKB(skb)->atm_options & ATM_ATMOPT_CLP ? MID_SEG_CLP : 0),
1159 tx->send+((tx->tx_pos+1) & (tx->words-1))*4);
1160 DPRINTK("size: %d, len:%d\n",size,skb->len);
1162 writel(skb->len,tx->send+
1163 ((tx->tx_pos+size-AAL5_TRAILER) & (tx->words-1))*4);
1165 for (i = 0; i < j; i++) {
1166 writel(eni_dev->dma[i*2],eni_dev->tx_dma+dma_wr*8);
1167 writel(eni_dev->dma[i*2+1],eni_dev->tx_dma+dma_wr*8+4);
1168 dma_wr = (dma_wr+1) & (NR_DMA_TX-1);
1170 ENI_PRV_POS(skb) = tx->tx_pos;
1171 ENI_PRV_SIZE(skb) = size;
1172 ENI_VCC(vcc)->txing += size;
1173 tx->tx_pos = (tx->tx_pos+size) & (tx->words-1);
1174 DPRINTK("dma_wr set to %d, tx_pos is now %ld\n",dma_wr,tx->tx_pos);
1175 eni_out(dma_wr,MID_DMA_WR_TX);
1176 skb_queue_tail(&eni_dev->tx_queue,skb);
1182 static void poll_tx(struct atm_dev *dev)
1185 struct sk_buff *skb;
1189 DPRINTK(">poll_tx\n");
1190 for (i = NR_CHAN-1; i >= 0; i--) {
1191 tx = &ENI_DEV(dev)->tx[i];
1193 while ((skb = skb_dequeue(&tx->backlog))) {
1195 if (res == enq_ok) continue;
1196 DPRINTK("re-queuing TX PDU\n");
1197 skb_queue_head(&tx->backlog,skb);
1199 if (res == enq_jam) return;
1206 static void dequeue_tx(struct atm_dev *dev)
1208 struct eni_dev *eni_dev;
1209 struct atm_vcc *vcc;
1210 struct sk_buff *skb;
1214 eni_dev = ENI_DEV(dev);
1216 while ((skb = skb_dequeue(&eni_dev->tx_queue))) {
1217 vcc = ATM_SKB(skb)->vcc;
1219 tx = ENI_VCC(vcc)->tx;
1220 NULLCHECK(ENI_VCC(vcc)->tx);
1221 DPRINTK("dequeue_tx: next 0x%lx curr 0x%x\n",ENI_PRV_POS(skb),
1222 (unsigned) eni_in(MID_TX_DESCRSTART(tx->index)));
1223 if (ENI_VCC(vcc)->txing < tx->words && ENI_PRV_POS(skb) ==
1224 eni_in(MID_TX_DESCRSTART(tx->index))) {
1225 skb_queue_head(&eni_dev->tx_queue,skb);
1228 ENI_VCC(vcc)->txing -= ENI_PRV_SIZE(skb);
1229 dma_unmap_single(&eni_dev->pci_dev->dev,ENI_PRV_PADDR(skb),skb->len,
1231 if (vcc->pop) vcc->pop(vcc,skb);
1232 else dev_kfree_skb_irq(skb);
1233 atomic_inc(&vcc->stats->tx);
1234 wake_up(&eni_dev->tx_wait);
1240 static struct eni_tx *alloc_tx(struct eni_dev *eni_dev,int ubr)
1244 for (i = !ubr; i < NR_CHAN; i++)
1245 if (!eni_dev->tx[i].send) return eni_dev->tx+i;
1250 static int comp_tx(struct eni_dev *eni_dev,int *pcr,int reserved,int *pre,
1251 int *res,int unlimited)
1253 static const int pre_div[] = { 4,16,128,2048 };
1254 /* 2^(((x+2)^2-(x+2))/2+1) */
1256 if (unlimited) *pre = *res = 0;
1261 for (*pre = 0; *pre < 3; (*pre)++)
1262 if (TS_CLOCK/pre_div[*pre]/64 <= *pcr) break;
1263 div = pre_div[*pre]**pcr;
1264 DPRINTK("min div %d\n",div);
1265 *res = TS_CLOCK/div-1;
1270 if (!*pcr) *pcr = eni_dev->tx_bw+reserved;
1271 for (*pre = 3; *pre >= 0; (*pre)--)
1272 if (TS_CLOCK/pre_div[*pre]/64 > -*pcr) break;
1273 if (*pre < 3) (*pre)++; /* else fail later */
1274 div = pre_div[*pre]*-*pcr;
1275 DPRINTK("max div %d\n",div);
1276 *res = DIV_ROUND_UP(TS_CLOCK, div)-1;
1278 if (*res < 0) *res = 0;
1279 if (*res > MID_SEG_MAX_RATE) *res = MID_SEG_MAX_RATE;
1281 *pcr = TS_CLOCK/pre_div[*pre]/(*res+1);
1282 DPRINTK("out pcr: %d (%d:%d)\n",*pcr,*pre,*res);
1287 static int reserve_or_set_tx(struct atm_vcc *vcc,struct atm_trafprm *txtp,
1288 int set_rsv,int set_shp)
1290 struct eni_dev *eni_dev = ENI_DEV(vcc->dev);
1291 struct eni_vcc *eni_vcc = ENI_VCC(vcc);
1295 int rate,ubr,unlimited,new_tx;
1299 rate = atm_pcr_goal(txtp);
1300 ubr = txtp->traffic_class == ATM_UBR;
1301 unlimited = ubr && (!rate || rate <= -ATM_OC3_PCR ||
1302 rate >= ATM_OC3_PCR);
1304 size = txtp->max_sdu*eni_dev->tx_mult/100;
1305 if (size > MID_MAX_BUF_SIZE && txtp->max_sdu <=
1307 size = MID_MAX_BUF_SIZE;
1311 eni_vcc->tx = eni_dev->ubr;
1312 txtp->pcr = ATM_OC3_PCR;
1317 new_tx = !eni_vcc->tx;
1318 mem = NULL; /* for gcc */
1319 if (!new_tx) tx = eni_vcc->tx;
1321 mem = eni_alloc_mem(eni_dev,&size);
1322 if (!mem) return -ENOBUFS;
1323 tx = alloc_tx(eni_dev,unlimited);
1325 eni_free_mem(eni_dev,mem,size);
1328 DPRINTK("got chan %d\n",tx->index);
1329 tx->reserved = tx->shaping = 0;
1331 tx->words = size >> 2;
1332 skb_queue_head_init(&tx->backlog);
1333 for (order = 0; size > (1 << (order+10)); order++);
1334 eni_out((order << MID_SIZE_SHIFT) |
1335 ((tx->send-eni_dev->ram) >> (MID_LOC_SKIP+2)),
1336 MID_TX_PLACE(tx->index));
1337 tx->tx_pos = eni_in(MID_TX_DESCRSTART(tx->index)) &
1340 error = comp_tx(eni_dev,&rate,tx->reserved,&pre,&res,unlimited);
1341 if (!error && txtp->min_pcr > rate) error = -EINVAL;
1342 if (!error && txtp->max_pcr && txtp->max_pcr != ATM_MAX_PCR &&
1343 txtp->max_pcr < rate) error = -EINVAL;
1344 if (!error && !ubr && rate > eni_dev->tx_bw+tx->reserved)
1346 if (!error && set_rsv && !set_shp && rate < tx->shaping)
1348 if (!error && !set_rsv && rate > tx->reserved && !ubr)
1353 eni_free_mem(eni_dev,mem,size);
1358 if (set_rsv && !ubr) {
1359 eni_dev->tx_bw += tx->reserved;
1360 tx->reserved = rate;
1361 eni_dev->tx_bw -= rate;
1363 if (set_shp || (unlimited && new_tx)) {
1364 if (unlimited && new_tx) eni_dev->ubr = tx;
1365 tx->prescaler = pre;
1366 tx->resolution = res;
1369 if (set_shp) eni_vcc->tx = tx;
1370 DPRINTK("rsv %d shp %d\n",tx->reserved,tx->shaping);
1375 static int open_tx_first(struct atm_vcc *vcc)
1377 ENI_VCC(vcc)->tx = NULL;
1378 if (vcc->qos.txtp.traffic_class == ATM_NONE) return 0;
1379 ENI_VCC(vcc)->txing = 0;
1380 return reserve_or_set_tx(vcc,&vcc->qos.txtp,1,1);
1384 static int open_tx_second(struct atm_vcc *vcc)
1386 return 0; /* nothing to do */
1390 static void close_tx(struct atm_vcc *vcc)
1392 DECLARE_WAITQUEUE(wait,current);
1393 struct eni_dev *eni_dev;
1394 struct eni_vcc *eni_vcc;
1396 eni_vcc = ENI_VCC(vcc);
1397 if (!eni_vcc->tx) return;
1398 eni_dev = ENI_DEV(vcc->dev);
1399 /* wait for TX queue to drain */
1400 DPRINTK("eni_close: waiting for TX ...\n");
1401 add_wait_queue(&eni_dev->tx_wait,&wait);
1402 set_current_state(TASK_UNINTERRUPTIBLE);
1406 tasklet_disable(&eni_dev->task);
1407 txing = skb_peek(&eni_vcc->tx->backlog) || eni_vcc->txing;
1408 tasklet_enable(&eni_dev->task);
1410 DPRINTK("%d TX left\n",eni_vcc->txing);
1412 set_current_state(TASK_UNINTERRUPTIBLE);
1414 set_current_state(TASK_RUNNING);
1415 remove_wait_queue(&eni_dev->tx_wait,&wait);
1416 if (eni_vcc->tx != eni_dev->ubr) {
1418 * Looping a few times in here is probably far cheaper than
1419 * keeping track of TX completions all the time, so let's poll
1422 while (eni_in(MID_TX_RDPTR(eni_vcc->tx->index)) !=
1423 eni_in(MID_TX_DESCRSTART(eni_vcc->tx->index)))
1425 eni_free_mem(eni_dev,eni_vcc->tx->send,eni_vcc->tx->words << 2);
1426 eni_vcc->tx->send = NULL;
1427 eni_dev->tx_bw += eni_vcc->tx->reserved;
1433 static int start_tx(struct atm_dev *dev)
1435 struct eni_dev *eni_dev;
1438 eni_dev = ENI_DEV(dev);
1440 eni_dev->tx_bw = ATM_OC3_PCR;
1441 eni_dev->tx_mult = DEFAULT_TX_MULT;
1442 init_waitqueue_head(&eni_dev->tx_wait);
1443 eni_dev->ubr = NULL;
1444 skb_queue_head_init(&eni_dev->tx_queue);
1445 eni_out(0,MID_DMA_WR_TX);
1446 for (i = 0; i < NR_CHAN; i++) {
1447 eni_dev->tx[i].send = NULL;
1448 eni_dev->tx[i].index = i;
1454 /*--------------------------------- common ----------------------------------*/
1457 #if 0 /* may become useful again when tuning things */
1459 static void foo(void)
1462 "tx_complete=%d,dma_complete=%d,queued=%d,requeued=%d,sub=%d,\n"
1463 "backlogged=%d,rx_enqueued=%d,rx_dequeued=%d,putting=%d,pushed=%d\n",
1464 tx_complete,dma_complete,queued,requeued,submitted,backlogged,
1465 rx_enqueued,rx_dequeued,putting,pushed);
1466 if (eni_boards) printk(KERN_INFO "loss: %ld\n",ENI_DEV(eni_boards)->lost);
1472 static void bug_int(struct atm_dev *dev,unsigned long reason)
1474 DPRINTK(">bug_int\n");
1475 if (reason & MID_DMA_ERR_ACK)
1476 printk(KERN_CRIT DEV_LABEL "(itf %d): driver error - DMA "
1477 "error\n",dev->number);
1478 if (reason & MID_TX_IDENT_MISM)
1479 printk(KERN_CRIT DEV_LABEL "(itf %d): driver error - ident "
1480 "mismatch\n",dev->number);
1481 if (reason & MID_TX_DMA_OVFL)
1482 printk(KERN_CRIT DEV_LABEL "(itf %d): driver error - DMA "
1483 "overflow\n",dev->number);
1484 EVENT("---dump ends here---\n",0,0);
1485 printk(KERN_NOTICE "---recent events---\n");
1490 static irqreturn_t eni_int(int irq,void *dev_id)
1492 struct atm_dev *dev;
1493 struct eni_dev *eni_dev;
1496 DPRINTK(">eni_int\n");
1498 eni_dev = ENI_DEV(dev);
1499 reason = eni_in(MID_ISA);
1500 DPRINTK(DEV_LABEL ": int 0x%lx\n",(unsigned long) reason);
1502 * Must handle these two right now, because reading ISA doesn't clear
1503 * them, so they re-occur and we never make it to the tasklet. Since
1504 * they're rare, we don't mind the occasional invocation of eni_tasklet
1505 * with eni_dev->events == 0.
1507 if (reason & MID_STAT_OVFL) {
1508 EVENT("stat overflow\n",0,0);
1509 eni_dev->lost += eni_in(MID_STAT) & MID_OVFL_TRASH;
1511 if (reason & MID_SUNI_INT) {
1512 EVENT("SUNI int\n",0,0);
1513 dev->phy->interrupt(dev);
1518 spin_lock(&eni_dev->lock);
1519 eni_dev->events |= reason;
1520 spin_unlock(&eni_dev->lock);
1521 tasklet_schedule(&eni_dev->task);
1526 static void eni_tasklet(unsigned long data)
1528 struct atm_dev *dev = (struct atm_dev *) data;
1529 struct eni_dev *eni_dev = ENI_DEV(dev);
1530 unsigned long flags;
1533 DPRINTK("eni_tasklet (dev %p)\n",dev);
1534 spin_lock_irqsave(&eni_dev->lock,flags);
1535 events = xchg(&eni_dev->events,0);
1536 spin_unlock_irqrestore(&eni_dev->lock,flags);
1537 if (events & MID_RX_DMA_COMPLETE) {
1538 EVENT("INT: RX DMA complete, starting dequeue_rx\n",0,0);
1540 EVENT("dequeue_rx done, starting poll_rx\n",0,0);
1542 EVENT("poll_rx done\n",0,0);
1545 if (events & MID_SERVICE) {
1546 EVENT("INT: service, starting get_service\n",0,0);
1548 EVENT("get_service done, starting poll_rx\n",0,0);
1550 EVENT("poll_rx done\n",0,0);
1552 if (events & MID_TX_DMA_COMPLETE) {
1553 EVENT("INT: TX DMA COMPLETE\n",0,0);
1556 if (events & MID_TX_COMPLETE) {
1557 EVENT("INT: TX COMPLETE\n",0,0);
1559 wake_up(&eni_dev->tx_wait);
1562 if (events & (MID_DMA_ERR_ACK | MID_TX_IDENT_MISM | MID_TX_DMA_OVFL)) {
1563 EVENT("bug interrupt\n",0,0);
1564 bug_int(dev,events);
1570 /*--------------------------------- entries ---------------------------------*/
1573 static char * const media_name[] = {
1574 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
1575 "UTP", "05?", "06?", "07?", /* 4- 7 */
1576 "TAXI","09?", "10?", "11?", /* 8-11 */
1577 "12?", "13?", "14?", "15?", /* 12-15 */
1578 "MMF", "SMF", "18?", "19?", /* 16-19 */
1579 "UTP", "21?", "22?", "23?", /* 20-23 */
1580 "24?", "25?", "26?", "27?", /* 24-27 */
1581 "28?", "29?", "30?", "31?" /* 28-31 */
1585 #define SET_SEPROM \
1586 ({ if (!error && !pci_error) { \
1587 pci_error = pci_write_config_byte(eni_dev->pci_dev,PCI_TONGA_CTRL,tonga); \
1588 udelay(10); /* 10 usecs */ \
1590 #define GET_SEPROM \
1591 ({ if (!error && !pci_error) { \
1592 pci_error = pci_read_config_byte(eni_dev->pci_dev,PCI_TONGA_CTRL,&tonga); \
1593 udelay(10); /* 10 usecs */ \
1597 static int get_esi_asic(struct atm_dev *dev)
1599 struct eni_dev *eni_dev;
1600 unsigned char tonga;
1601 int error,failed,pci_error;
1604 eni_dev = ENI_DEV(dev);
1605 error = pci_error = 0;
1606 tonga = SEPROM_MAGIC | SEPROM_DATA | SEPROM_CLK;
1608 for (i = 0; i < ESI_LEN && !error && !pci_error; i++) {
1609 /* start operation */
1610 tonga |= SEPROM_DATA;
1612 tonga |= SEPROM_CLK;
1614 tonga &= ~SEPROM_DATA;
1616 tonga &= ~SEPROM_CLK;
1619 address = ((i+SEPROM_ESI_BASE) << 1)+1;
1620 for (j = 7; j >= 0; j--) {
1621 tonga = (address >> j) & 1 ? tonga | SEPROM_DATA :
1622 tonga & ~SEPROM_DATA;
1624 tonga |= SEPROM_CLK;
1626 tonga &= ~SEPROM_CLK;
1630 tonga |= SEPROM_DATA;
1632 tonga |= SEPROM_CLK;
1635 failed = tonga & SEPROM_DATA;
1636 tonga &= ~SEPROM_CLK;
1638 tonga |= SEPROM_DATA;
1640 if (failed) error = -EIO;
1643 for (j = 7; j >= 0; j--) {
1645 tonga |= SEPROM_DATA;
1647 tonga |= SEPROM_CLK;
1650 if (tonga & SEPROM_DATA) dev->esi[i] |= 1;
1651 tonga &= ~SEPROM_CLK;
1653 tonga |= SEPROM_DATA;
1657 tonga |= SEPROM_DATA;
1659 tonga |= SEPROM_CLK;
1662 if (!(tonga & SEPROM_DATA)) error = -EIO;
1663 tonga &= ~SEPROM_CLK;
1665 tonga |= SEPROM_DATA;
1668 /* stop operation */
1669 tonga &= ~SEPROM_DATA;
1671 tonga |= SEPROM_CLK;
1673 tonga |= SEPROM_DATA;
1677 printk(KERN_ERR DEV_LABEL "(itf %d): error reading ESI "
1678 "(0x%02x)\n",dev->number,pci_error);
1689 static int get_esi_fpga(struct atm_dev *dev, void __iomem *base)
1691 void __iomem *mac_base;
1694 mac_base = base+EPROM_SIZE-sizeof(struct midway_eprom);
1695 for (i = 0; i < ESI_LEN; i++) dev->esi[i] = readb(mac_base+(i^3));
1700 static int eni_do_init(struct atm_dev *dev)
1702 struct midway_eprom __iomem *eprom;
1703 struct eni_dev *eni_dev;
1704 struct pci_dev *pci_dev;
1705 unsigned long real_base;
1709 DPRINTK(">eni_init\n");
1710 dev->ci_range.vpi_bits = 0;
1711 dev->ci_range.vci_bits = NR_VCI_LD;
1712 dev->link_rate = ATM_OC3_PCR;
1713 eni_dev = ENI_DEV(dev);
1714 pci_dev = eni_dev->pci_dev;
1715 real_base = pci_resource_start(pci_dev, 0);
1716 eni_dev->irq = pci_dev->irq;
1717 if ((error = pci_write_config_word(pci_dev,PCI_COMMAND,
1718 PCI_COMMAND_MEMORY |
1719 (eni_dev->asic ? PCI_COMMAND_PARITY | PCI_COMMAND_SERR : 0)))) {
1720 printk(KERN_ERR DEV_LABEL "(itf %d): can't enable memory "
1721 "(0x%02x)\n",dev->number,error);
1724 printk(KERN_NOTICE DEV_LABEL "(itf %d): rev.%d,base=0x%lx,irq=%d,",
1725 dev->number,pci_dev->revision,real_base,eni_dev->irq);
1726 if (!(base = ioremap(real_base,MAP_MAX_SIZE))) {
1728 printk(KERN_ERR DEV_LABEL "(itf %d): can't set up page "
1729 "mapping\n",dev->number);
1732 eni_dev->ioaddr = base;
1733 eni_dev->base_diff = real_base - (unsigned long) base;
1734 /* id may not be present in ASIC Tonga boards - check this @@@ */
1735 if (!eni_dev->asic) {
1736 eprom = (base+EPROM_SIZE-sizeof(struct midway_eprom));
1737 if (readl(&eprom->magic) != ENI155_MAGIC) {
1739 printk(KERN_ERR DEV_LABEL
1740 "(itf %d): bad magic - expected 0x%x, got 0x%x\n",
1741 dev->number, ENI155_MAGIC,
1742 (unsigned)readl(&eprom->magic));
1747 eni_dev->phy = base+PHY_BASE;
1748 eni_dev->reg = base+REG_BASE;
1749 eni_dev->ram = base+RAM_BASE;
1750 last = MAP_MAX_SIZE-RAM_BASE;
1751 for (i = last-RAM_INCREMENT; i >= 0; i -= RAM_INCREMENT) {
1752 writel(0x55555555,eni_dev->ram+i);
1753 if (readl(eni_dev->ram+i) != 0x55555555) last = i;
1755 writel(0xAAAAAAAA,eni_dev->ram+i);
1756 if (readl(eni_dev->ram+i) != 0xAAAAAAAA) last = i;
1757 else writel(i,eni_dev->ram+i);
1760 for (i = 0; i < last; i += RAM_INCREMENT)
1761 if (readl(eni_dev->ram+i) != i) break;
1763 memset_io(eni_dev->ram,0,eni_dev->mem);
1764 /* TODO: should shrink allocation now */
1765 printk("mem=%dkB (",eni_dev->mem >> 10);
1766 /* TODO: check for non-SUNI, check for TAXI ? */
1767 if (!(eni_in(MID_RES_ID_MCON) & 0x200) != !eni_dev->asic) {
1769 printk(KERN_ERR DEV_LABEL "(itf %d): ERROR - wrong id 0x%x\n",
1770 dev->number,(unsigned) eni_in(MID_RES_ID_MCON));
1774 error = eni_dev->asic ? get_esi_asic(dev) : get_esi_fpga(dev,base);
1777 for (i = 0; i < ESI_LEN; i++)
1778 printk("%s%02X",i ? "-" : "",dev->esi[i]);
1780 printk(KERN_NOTICE DEV_LABEL "(itf %d): %s,%s\n",dev->number,
1781 eni_in(MID_RES_ID_MCON) & 0x200 ? "ASIC" : "FPGA",
1782 media_name[eni_in(MID_RES_ID_MCON) & DAUGHTER_ID]);
1784 error = suni_init(dev);
1794 static void eni_do_release(struct atm_dev *dev)
1796 struct eni_dev *ed = ENI_DEV(dev);
1798 dev->phy->stop(dev);
1800 iounmap(ed->ioaddr);
1803 static int eni_start(struct atm_dev *dev)
1805 struct eni_dev *eni_dev;
1808 unsigned long buffer_mem;
1811 DPRINTK(">eni_start\n");
1812 eni_dev = ENI_DEV(dev);
1813 if (request_irq(eni_dev->irq,&eni_int,IRQF_SHARED,DEV_LABEL,dev)) {
1814 printk(KERN_ERR DEV_LABEL "(itf %d): IRQ%d is already in use\n",
1815 dev->number,eni_dev->irq);
1819 pci_set_master(eni_dev->pci_dev);
1820 if ((error = pci_write_config_word(eni_dev->pci_dev,PCI_COMMAND,
1821 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |
1822 (eni_dev->asic ? PCI_COMMAND_PARITY | PCI_COMMAND_SERR : 0)))) {
1823 printk(KERN_ERR DEV_LABEL "(itf %d): can't enable memory+"
1824 "master (0x%02x)\n",dev->number,error);
1827 if ((error = pci_write_config_byte(eni_dev->pci_dev,PCI_TONGA_CTRL,
1829 printk(KERN_ERR DEV_LABEL "(itf %d): can't set endian swap "
1830 "(0x%02x)\n",dev->number,error);
1833 /* determine addresses of internal tables */
1834 eni_dev->vci = eni_dev->ram;
1835 eni_dev->rx_dma = eni_dev->ram+NR_VCI*16;
1836 eni_dev->tx_dma = eni_dev->rx_dma+NR_DMA_RX*8;
1837 eni_dev->service = eni_dev->tx_dma+NR_DMA_TX*8;
1838 buf = eni_dev->service+NR_SERVICE*4;
1839 DPRINTK("vci 0x%lx,rx 0x%lx, tx 0x%lx,srv 0x%lx,buf 0x%lx\n",
1840 eni_dev->vci,eni_dev->rx_dma,eni_dev->tx_dma,
1841 eni_dev->service,buf);
1842 spin_lock_init(&eni_dev->lock);
1843 tasklet_init(&eni_dev->task,eni_tasklet,(unsigned long) dev);
1844 eni_dev->events = 0;
1845 /* initialize memory management */
1846 buffer_mem = eni_dev->mem - (buf - eni_dev->ram);
1847 eni_dev->free_list_size = buffer_mem/MID_MIN_BUF_SIZE/2;
1848 eni_dev->free_list = kmalloc_array(eni_dev->free_list_size + 1,
1849 sizeof(*eni_dev->free_list),
1851 if (!eni_dev->free_list) {
1852 printk(KERN_ERR DEV_LABEL "(itf %d): couldn't get free page\n",
1857 eni_dev->free_len = 0;
1858 eni_put_free(eni_dev,buf,buffer_mem);
1859 memset_io(eni_dev->vci,0,16*NR_VCI); /* clear VCI table */
1861 * byte_addr free (k)
1862 * 0x00000000 512 VCI table
1863 * 0x00004000 496 RX DMA
1864 * 0x00005000 492 TX DMA
1865 * 0x00006000 488 service list
1866 * 0x00007000 484 buffers
1867 * 0x00080000 0 end (512kB)
1869 eni_out(0xffffffff,MID_IE);
1870 error = start_tx(dev);
1871 if (error) goto free_list;
1872 error = start_rx(dev);
1873 if (error) goto free_list;
1874 error = dev->phy->start(dev);
1875 if (error) goto free_list;
1876 eni_out(eni_in(MID_MC_S) | (1 << MID_INT_SEL_SHIFT) |
1877 MID_TX_LOCK_MODE | MID_DMA_ENABLE | MID_TX_ENABLE | MID_RX_ENABLE,
1879 /* Tonga uses SBus INTReq1 */
1880 (void) eni_in(MID_ISA); /* clear Midway interrupts */
1884 kfree(eni_dev->free_list);
1887 free_irq(eni_dev->irq, dev);
1894 static void eni_close(struct atm_vcc *vcc)
1896 DPRINTK(">eni_close\n");
1897 if (!ENI_VCC(vcc)) return;
1898 clear_bit(ATM_VF_READY,&vcc->flags);
1901 DPRINTK("eni_close: done waiting\n");
1902 /* deallocate memory */
1903 kfree(ENI_VCC(vcc));
1904 vcc->dev_data = NULL;
1905 clear_bit(ATM_VF_ADDR,&vcc->flags);
1910 static int eni_open(struct atm_vcc *vcc)
1912 struct eni_vcc *eni_vcc;
1914 short vpi = vcc->vpi;
1917 DPRINTK(">eni_open\n");
1918 EVENT("eni_open\n",0,0);
1919 if (!test_bit(ATM_VF_PARTIAL,&vcc->flags))
1920 vcc->dev_data = NULL;
1921 if (vci != ATM_VPI_UNSPEC && vpi != ATM_VCI_UNSPEC)
1922 set_bit(ATM_VF_ADDR,&vcc->flags);
1923 if (vcc->qos.aal != ATM_AAL0 && vcc->qos.aal != ATM_AAL5)
1925 DPRINTK(DEV_LABEL "(itf %d): open %d.%d\n",vcc->dev->number,vcc->vpi,
1927 if (!test_bit(ATM_VF_PARTIAL,&vcc->flags)) {
1928 eni_vcc = kmalloc(sizeof(struct eni_vcc),GFP_KERNEL);
1929 if (!eni_vcc) return -ENOMEM;
1930 vcc->dev_data = eni_vcc;
1931 eni_vcc->tx = NULL; /* for eni_close after open_rx */
1932 if ((error = open_rx_first(vcc))) {
1936 if ((error = open_tx_first(vcc))) {
1941 if (vci == ATM_VPI_UNSPEC || vpi == ATM_VCI_UNSPEC) return 0;
1942 if ((error = open_rx_second(vcc))) {
1946 if ((error = open_tx_second(vcc))) {
1950 set_bit(ATM_VF_READY,&vcc->flags);
1951 /* should power down SUNI while !ref_count @@@ */
1956 static int eni_change_qos(struct atm_vcc *vcc,struct atm_qos *qos,int flgs)
1958 struct eni_dev *eni_dev = ENI_DEV(vcc->dev);
1959 struct eni_tx *tx = ENI_VCC(vcc)->tx;
1960 struct sk_buff *skb;
1961 int error,rate,rsv,shp;
1963 if (qos->txtp.traffic_class == ATM_NONE) return 0;
1964 if (tx == eni_dev->ubr) return -EBADFD;
1965 rate = atm_pcr_goal(&qos->txtp);
1966 if (rate < 0) rate = -rate;
1968 if ((flgs & ATM_MF_DEC_RSV) && rate && rate < tx->reserved) rsv = 1;
1969 if ((flgs & ATM_MF_INC_RSV) && (!rate || rate > tx->reserved)) rsv = 1;
1970 if ((flgs & ATM_MF_DEC_SHP) && rate && rate < tx->shaping) shp = 1;
1971 if ((flgs & ATM_MF_INC_SHP) && (!rate || rate > tx->shaping)) shp = 1;
1972 if (!rsv && !shp) return 0;
1973 error = reserve_or_set_tx(vcc,&qos->txtp,rsv,shp);
1974 if (error) return error;
1975 if (shp && !(flgs & ATM_MF_IMMED)) return 0;
1977 * Walk through the send buffer and patch the rate information in all
1978 * segmentation buffer descriptors of this VCC.
1980 tasklet_disable(&eni_dev->task);
1981 skb_queue_walk(&eni_dev->tx_queue, skb) {
1984 if (ATM_SKB(skb)->vcc != vcc) continue;
1985 dsc = tx->send+ENI_PRV_POS(skb)*4;
1986 writel((readl(dsc) & ~(MID_SEG_RATE | MID_SEG_PR)) |
1987 (tx->prescaler << MID_SEG_PR_SHIFT) |
1988 (tx->resolution << MID_SEG_RATE_SHIFT), dsc);
1990 tasklet_enable(&eni_dev->task);
1995 static int eni_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
1997 struct eni_dev *eni_dev = ENI_DEV(dev);
1999 if (cmd == ENI_MEMDUMP) {
2000 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2001 printk(KERN_WARNING "Please use /proc/atm/" DEV_LABEL ":%d "
2002 "instead of obsolete ioctl ENI_MEMDUMP\n",dev->number);
2006 if (cmd == ENI_SETMULT) {
2007 struct eni_multipliers mult;
2009 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2010 if (copy_from_user(&mult, arg,
2011 sizeof(struct eni_multipliers)))
2013 if ((mult.tx && mult.tx <= 100) || (mult.rx &&mult.rx <= 100) ||
2014 mult.tx > 65536 || mult.rx > 65536)
2016 if (mult.tx) eni_dev->tx_mult = mult.tx;
2017 if (mult.rx) eni_dev->rx_mult = mult.rx;
2020 if (cmd == ATM_SETCIRANGE) {
2021 struct atm_cirange ci;
2023 if (copy_from_user(&ci, arg,sizeof(struct atm_cirange)))
2025 if ((ci.vpi_bits == 0 || ci.vpi_bits == ATM_CI_MAX) &&
2026 (ci.vci_bits == NR_VCI_LD || ci.vpi_bits == ATM_CI_MAX))
2030 if (!dev->phy->ioctl) return -ENOIOCTLCMD;
2031 return dev->phy->ioctl(dev,cmd,arg);
2034 static int eni_send(struct atm_vcc *vcc,struct sk_buff *skb)
2038 DPRINTK(">eni_send\n");
2039 if (!ENI_VCC(vcc)->tx) {
2040 if (vcc->pop) vcc->pop(vcc,skb);
2041 else dev_kfree_skb(skb);
2045 printk(KERN_CRIT "!skb in eni_send ?\n");
2046 if (vcc->pop) vcc->pop(vcc,skb);
2049 if (vcc->qos.aal == ATM_AAL0) {
2050 if (skb->len != ATM_CELL_SIZE-1) {
2051 if (vcc->pop) vcc->pop(vcc,skb);
2052 else dev_kfree_skb(skb);
2055 *(u32 *) skb->data = htonl(*(u32 *) skb->data);
2058 ATM_SKB(skb)->vcc = vcc;
2059 tasklet_disable_in_atomic(&ENI_DEV(vcc->dev)->task);
2061 tasklet_enable(&ENI_DEV(vcc->dev)->task);
2062 if (res == enq_ok) return 0;
2063 skb_queue_tail(&ENI_VCC(vcc)->tx->backlog,skb);
2065 tasklet_schedule(&ENI_DEV(vcc->dev)->task);
2069 static void eni_phy_put(struct atm_dev *dev,unsigned char value,
2072 writel(value,ENI_DEV(dev)->phy+addr*4);
2077 static unsigned char eni_phy_get(struct atm_dev *dev,unsigned long addr)
2079 return readl(ENI_DEV(dev)->phy+addr*4);
2083 static int eni_proc_read(struct atm_dev *dev,loff_t *pos,char *page)
2086 static const char *signal[] = { "LOST","unknown","okay" };
2087 struct eni_dev *eni_dev = ENI_DEV(dev);
2088 struct atm_vcc *vcc;
2093 return sprintf(page,DEV_LABEL "(itf %d) signal %s, %dkB, "
2094 "%d cps remaining\n",dev->number,signal[(int) dev->signal],
2095 eni_dev->mem >> 10,eni_dev->tx_bw);
2097 return sprintf(page,"%4sBursts: TX"
2098 #if !defined(CONFIG_ATM_ENI_BURST_TX_16W) && \
2099 !defined(CONFIG_ATM_ENI_BURST_TX_8W) && \
2100 !defined(CONFIG_ATM_ENI_BURST_TX_4W) && \
2101 !defined(CONFIG_ATM_ENI_BURST_TX_2W)
2104 #ifdef CONFIG_ATM_ENI_BURST_TX_16W
2107 #ifdef CONFIG_ATM_ENI_BURST_TX_8W
2110 #ifdef CONFIG_ATM_ENI_BURST_TX_4W
2113 #ifdef CONFIG_ATM_ENI_BURST_TX_2W
2117 #if !defined(CONFIG_ATM_ENI_BURST_RX_16W) && \
2118 !defined(CONFIG_ATM_ENI_BURST_RX_8W) && \
2119 !defined(CONFIG_ATM_ENI_BURST_RX_4W) && \
2120 !defined(CONFIG_ATM_ENI_BURST_RX_2W)
2123 #ifdef CONFIG_ATM_ENI_BURST_RX_16W
2126 #ifdef CONFIG_ATM_ENI_BURST_RX_8W
2129 #ifdef CONFIG_ATM_ENI_BURST_RX_4W
2132 #ifdef CONFIG_ATM_ENI_BURST_RX_2W
2135 #ifndef CONFIG_ATM_ENI_TUNE_BURST
2140 return sprintf(page,"%4sBuffer multipliers: tx %d%%, rx %d%%\n",
2141 "",eni_dev->tx_mult,eni_dev->rx_mult);
2142 for (i = 0; i < NR_CHAN; i++) {
2143 struct eni_tx *tx = eni_dev->tx+i;
2145 if (!tx->send) continue;
2147 return sprintf(page, "tx[%d]: 0x%lx-0x%lx "
2148 "(%6ld bytes), rsv %d cps, shp %d cps%s\n",i,
2149 (unsigned long) (tx->send - eni_dev->ram),
2150 tx->send-eni_dev->ram+tx->words*4-1,tx->words*4,
2151 tx->reserved,tx->shaping,
2152 tx == eni_dev->ubr ? " (UBR)" : "");
2154 if (--left) continue;
2155 return sprintf(page,"%10sbacklog %u packets\n","",
2156 skb_queue_len(&tx->backlog));
2158 read_lock(&vcc_sklist_lock);
2159 for(i = 0; i < VCC_HTABLE_SIZE; ++i) {
2160 struct hlist_head *head = &vcc_hash[i];
2162 sk_for_each(s, head) {
2163 struct eni_vcc *eni_vcc;
2167 if (vcc->dev != dev)
2169 eni_vcc = ENI_VCC(vcc);
2170 if (--left) continue;
2171 length = sprintf(page,"vcc %4d: ",vcc->vci);
2173 length += sprintf(page+length, "0x%lx-0x%lx "
2175 (unsigned long) (eni_vcc->recv - eni_dev->ram),
2176 eni_vcc->recv-eni_dev->ram+eni_vcc->words*4-1,
2178 if (eni_vcc->tx) length += sprintf(page+length,", ");
2181 length += sprintf(page+length,"tx[%d], txing %d bytes",
2182 eni_vcc->tx->index,eni_vcc->txing);
2183 page[length] = '\n';
2184 read_unlock(&vcc_sklist_lock);
2188 read_unlock(&vcc_sklist_lock);
2189 for (i = 0; i < eni_dev->free_len; i++) {
2190 struct eni_free *fe = eni_dev->free_list+i;
2191 unsigned long offset;
2193 if (--left) continue;
2194 offset = (unsigned long) eni_dev->ram+eni_dev->base_diff;
2195 return sprintf(page,"free %p-%p (%6d bytes)\n",
2196 fe->start-offset,fe->start-offset+(1 << fe->order)-1,
2203 static const struct atmdev_ops ops = {
2208 .phy_put = eni_phy_put,
2209 .phy_get = eni_phy_get,
2210 .change_qos = eni_change_qos,
2211 .proc_read = eni_proc_read
2215 static int eni_init_one(struct pci_dev *pci_dev,
2216 const struct pci_device_id *ent)
2218 struct atm_dev *dev;
2219 struct eni_dev *eni_dev;
2220 struct eni_zero *zero;
2223 rc = pci_enable_device(pci_dev);
2227 rc = dma_set_mask_and_coherent(&pci_dev->dev, DMA_BIT_MASK(32));
2232 eni_dev = kmalloc(sizeof(struct eni_dev), GFP_KERNEL);
2236 zero = &eni_dev->zero;
2237 zero->addr = dma_alloc_coherent(&pci_dev->dev,
2238 ENI_ZEROES_SIZE, &zero->dma, GFP_KERNEL);
2242 dev = atm_dev_register(DEV_LABEL, &pci_dev->dev, &ops, -1, NULL);
2244 goto err_free_consistent;
2246 dev->dev_data = eni_dev;
2247 pci_set_drvdata(pci_dev, dev);
2248 eni_dev->pci_dev = pci_dev;
2249 eni_dev->asic = ent->driver_data;
2251 rc = eni_do_init(dev);
2253 goto err_unregister;
2255 rc = eni_start(dev);
2257 goto err_eni_release;
2259 eni_dev->more = eni_boards;
2266 iounmap(ENI_DEV(dev)->ioaddr);
2268 atm_dev_deregister(dev);
2269 err_free_consistent:
2270 dma_free_coherent(&pci_dev->dev, ENI_ZEROES_SIZE, zero->addr, zero->dma);
2274 pci_disable_device(pci_dev);
2279 static const struct pci_device_id eni_pci_tbl[] = {
2280 { PCI_VDEVICE(EF, PCI_DEVICE_ID_EF_ATM_FPGA), 0 /* FPGA */ },
2281 { PCI_VDEVICE(EF, PCI_DEVICE_ID_EF_ATM_ASIC), 1 /* ASIC */ },
2284 MODULE_DEVICE_TABLE(pci,eni_pci_tbl);
2287 static void eni_remove_one(struct pci_dev *pdev)
2289 struct atm_dev *dev = pci_get_drvdata(pdev);
2290 struct eni_dev *ed = ENI_DEV(dev);
2291 struct eni_zero *zero = &ed->zero;
2293 eni_do_release(dev);
2294 atm_dev_deregister(dev);
2295 dma_free_coherent(&pdev->dev, ENI_ZEROES_SIZE, zero->addr, zero->dma);
2297 pci_disable_device(pdev);
2301 static struct pci_driver eni_driver = {
2303 .id_table = eni_pci_tbl,
2304 .probe = eni_init_one,
2305 .remove = eni_remove_one,
2309 static int __init eni_init(void)
2311 struct sk_buff *skb; /* dummy for sizeof */
2313 BUILD_BUG_ON(sizeof(skb->cb) < sizeof(struct eni_skb_prv));
2314 return pci_register_driver(&eni_driver);
2318 module_init(eni_init);
2319 /* @@@ since exit routine not defined, this module can not be unloaded */
2321 MODULE_LICENSE("GPL");