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>
34 #if !defined(__i386__) && !defined(__x86_64__)
35 #ifndef ioremap_nocache
36 #define ioremap_nocache(X,Y) ioremap(X,Y)
48 * - fix bugs listed below
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)
66 #define DPRINTK(format,args...) printk(KERN_DEBUG format,##args)
68 #define DPRINTK(format,args...)
72 #ifndef CONFIG_ATM_ENI_TUNE_BURST
73 #define CONFIG_ATM_ENI_BURST_TX_8W
74 #define CONFIG_ATM_ENI_BURST_RX_4W
78 #ifndef CONFIG_ATM_ENI_DEBUG
86 static void event_dump(void)
95 * NULL pointer checking
98 #define NULLCHECK(x) \
99 if ((unsigned long) (x) < 0x30) \
100 printk(KERN_CRIT #x "==0x%lx\n",(unsigned long) (x))
103 * Very extensive activity logging. Greatly improves bug detection speed but
104 * costs a few Mbps if enabled.
109 static const char *ev
[EV
];
110 static unsigned long ev_a
[EV
],ev_b
[EV
];
114 static void EVENT(const char *s
,unsigned long a
,unsigned long b
)
123 static void event_dump(void)
127 for (n
= 0; n
< EV
; n
++) {
130 printk(ev
[i
] ? ev
[i
] : "(null)",ev_a
[i
],ev_b
[i
]);
135 #endif /* CONFIG_ATM_ENI_DEBUG */
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
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)
153 static int tx_complete
= 0,dma_complete
= 0,queued
= 0,requeued
= 0,
154 backlogged
= 0,rx_enqueued
= 0,rx_dequeued
= 0,pushed
= 0,submitted
= 0,
157 static struct atm_dev
*eni_boards
= NULL
;
159 /* 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)
164 /*-------------------------------- utilities --------------------------------*/
167 static void dump_mem(struct eni_dev
*eni_dev
)
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
);
178 static void dump(struct atm_dev
*dev
)
180 struct eni_dev
*eni_dev
;
184 eni_dev
= ENI_DEV(dev
);
185 printk(KERN_NOTICE
"Free memory\n");
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");
202 static void eni_put_free(struct eni_dev
*eni_dev
, void __iomem
*start
,
205 struct eni_free
*list
;
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
;
213 if (len
>= eni_dev
->free_list_size
) {
214 printk(KERN_CRIT
"eni_put_free overflow (%p,%ld)\n",
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",
224 list
[len
].start
= (void __iomem
*) start
;
225 list
[len
].order
= order
;
230 eni_dev
->free_len
= len
;
231 /*dump_mem(eni_dev);*/
235 static void __iomem
*eni_alloc_mem(struct eni_dev
*eni_dev
, unsigned long *size
)
237 struct eni_free
*list
;
239 int len
,i
,order
,best_order
,index
;
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
++)
247 DPRINTK("trying: %ld->%d\n",*size
,order
);
248 best_order
= 65; /* we don't have more than 2^64 of anything ... */
249 index
= 0; /* silence GCC */
250 for (i
= 0; i
< len
; i
++)
251 if (list
[i
].order
== order
) {
256 else if (best_order
> list
[i
].order
&& list
[i
].order
> order
) {
257 best_order
= list
[i
].order
;
260 if (best_order
== 65) return NULL
;
261 start
= list
[index
].start
-eni_dev
->base_diff
;
262 list
[index
] = list
[--len
];
263 eni_dev
->free_len
= len
;
265 eni_put_free(eni_dev
,start
+*size
,(1 << best_order
)-*size
);
266 DPRINTK("%ld bytes (order %d) at 0x%lx\n",*size
,order
,start
);
267 memset_io(start
,0,*size
); /* never leak data */
268 /*dump_mem(eni_dev);*/
273 static void eni_free_mem(struct eni_dev
*eni_dev
, void __iomem
*start
,
276 struct eni_free
*list
;
279 start
+= eni_dev
->base_diff
;
280 list
= eni_dev
->free_list
;
281 len
= eni_dev
->free_len
;
282 for (order
= -1; size
; order
++) size
>>= 1;
283 DPRINTK("eni_free_mem: %p+0x%lx (order %d)\n",start
,size
,order
);
284 for (i
= 0; i
< len
; i
++)
285 if (((unsigned long) list
[i
].start
) == ((unsigned long)start
^(1 << order
)) &&
286 list
[i
].order
== order
) {
287 DPRINTK("match[%d]: 0x%lx/0x%lx(0x%x), %d/%d\n",i
,
288 list
[i
].start
,start
,1 << order
,list
[i
].order
,order
);
289 list
[i
] = list
[--len
];
290 start
= (void __iomem
*) ((unsigned long) start
& ~(unsigned long) (1 << order
));
295 if (len
>= eni_dev
->free_list_size
) {
296 printk(KERN_ALERT
"eni_free_mem overflow (%p,%d)\n",start
,
300 list
[len
].start
= start
;
301 list
[len
].order
= order
;
302 eni_dev
->free_len
= len
+1;
303 /*dump_mem(eni_dev);*/
307 /*----------------------------------- RX ------------------------------------*/
310 #define ENI_VCC_NOS ((struct atm_vcc *) 1)
313 static void rx_ident_err(struct atm_vcc
*vcc
)
316 struct eni_dev
*eni_dev
;
317 struct eni_vcc
*eni_vcc
;
320 eni_dev
= ENI_DEV(dev
);
321 /* immediately halt adapter */
322 eni_out(eni_in(MID_MC_S
) &
323 ~(MID_DMA_ENABLE
| MID_TX_ENABLE
| MID_RX_ENABLE
),MID_MC_S
);
324 /* dump useful information */
325 eni_vcc
= ENI_VCC(vcc
);
326 printk(KERN_ALERT DEV_LABEL
"(itf %d): driver error - RX ident "
327 "mismatch\n",dev
->number
);
328 printk(KERN_ALERT
" VCI %d, rxing %d, words %ld\n",vcc
->vci
,
329 eni_vcc
->rxing
,eni_vcc
->words
);
330 printk(KERN_ALERT
" host descr 0x%lx, rx pos 0x%lx, descr value "
331 "0x%x\n",eni_vcc
->descr
,eni_vcc
->rx_pos
,
332 (unsigned) readl(eni_vcc
->recv
+eni_vcc
->descr
*4));
333 printk(KERN_ALERT
" last %p, servicing %d\n",eni_vcc
->last
,
335 EVENT("---dump ends here---\n",0,0);
336 printk(KERN_NOTICE
"---recent events---\n");
338 ENI_DEV(dev
)->fast
= NULL
; /* really stop it */
339 ENI_DEV(dev
)->slow
= NULL
;
340 skb_queue_head_init(&ENI_DEV(dev
)->rx_queue
);
344 static int do_rx_dma(struct atm_vcc
*vcc
,struct sk_buff
*skb
,
345 unsigned long skip
,unsigned long size
,unsigned long eff
)
347 struct eni_dev
*eni_dev
;
348 struct eni_vcc
*eni_vcc
;
350 u32 dma
[RX_DMA_BUF
*2];
355 eni_dev
= ENI_DEV(vcc
->dev
);
356 eni_vcc
= ENI_VCC(vcc
);
357 paddr
= 0; /* GCC, shut up */
359 paddr
= dma_map_single(&eni_dev
->pci_dev
->dev
,skb
->data
,skb
->len
,
361 if (dma_mapping_error(&eni_dev
->pci_dev
->dev
, paddr
))
363 ENI_PRV_PADDR(skb
) = paddr
;
365 printk(KERN_CRIT DEV_LABEL
"(itf %d): VCI %d has "
366 "mis-aligned RX data (0x%lx)\n",vcc
->dev
->number
,
367 vcc
->vci
,(unsigned long) paddr
);
368 ENI_PRV_SIZE(skb
) = size
+skip
;
369 /* PDU plus descriptor */
370 ATM_SKB(skb
)->vcc
= vcc
;
373 if ((eff
&& skip
) || 1) { /* @@@ actually, skip is always == 1 ... */
374 here
= (eni_vcc
->descr
+skip
) & (eni_vcc
->words
-1);
375 dma
[j
++] = (here
<< MID_DMA_COUNT_SHIFT
) | (vcc
->vci
376 << MID_DMA_VCI_SHIFT
) | MID_DT_JK
;
379 here
= (eni_vcc
->descr
+size
+skip
) & (eni_vcc
->words
-1);
380 if (!eff
) size
+= skip
;
385 DPRINTK("strange things happen ...\n");
386 EVENT("strange things happen ... (skip=%ld,eff=%ld)\n",
393 init
= 4-((paddr
& 15) >> 2);
394 if (init
> words
) init
= words
;
395 dma
[j
++] = MID_DT_WORD
| (init
<< MID_DMA_COUNT_SHIFT
) |
396 (vcc
->vci
<< MID_DMA_VCI_SHIFT
);
401 #ifdef CONFIG_ATM_ENI_BURST_RX_16W /* may work with some PCI chipsets ... */
403 dma
[j
++] = MID_DT_16W
| ((words
>> 4) <<
404 MID_DMA_COUNT_SHIFT
) | (vcc
->vci
<<
407 paddr
+= (words
& ~15) << 2;
411 #ifdef CONFIG_ATM_ENI_BURST_RX_8W /* works only with *some* PCI chipsets ... */
413 dma
[j
++] = MID_DT_8W
| ((words
>> 3) <<
414 MID_DMA_COUNT_SHIFT
) | (vcc
->vci
<<
417 paddr
+= (words
& ~7) << 2;
421 #ifdef CONFIG_ATM_ENI_BURST_RX_4W /* recommended */
423 dma
[j
++] = MID_DT_4W
| ((words
>> 2) <<
424 MID_DMA_COUNT_SHIFT
) | (vcc
->vci
<<
427 paddr
+= (words
& ~3) << 2;
431 #ifdef CONFIG_ATM_ENI_BURST_RX_2W /* probably useless if RX_4W, RX_8W, ... */
433 dma
[j
++] = MID_DT_2W
| ((words
>> 1) <<
434 MID_DMA_COUNT_SHIFT
) | (vcc
->vci
<<
437 paddr
+= (words
& ~1) << 2;
442 dma
[j
++] = MID_DT_WORD
| (words
<< MID_DMA_COUNT_SHIFT
)
443 | (vcc
->vci
<< MID_DMA_VCI_SHIFT
);
448 dma
[j
++] = (here
<< MID_DMA_COUNT_SHIFT
) |
449 (vcc
->vci
<< MID_DMA_VCI_SHIFT
) | MID_DT_JK
;
452 if (!j
|| j
> 2*RX_DMA_BUF
) {
453 printk(KERN_CRIT DEV_LABEL
"!j or j too big!!!\n");
456 dma
[j
-2] |= MID_DMA_END
;
458 dma_wr
= eni_in(MID_DMA_WR_RX
);
459 dma_rd
= eni_in(MID_DMA_RD_RX
);
461 * Can I move the dma_wr pointer by 2j+1 positions without overwriting
462 * data that hasn't been read (position of dma_rd) yet ?
464 if (!NEPMOK(dma_wr
,j
+j
+1,dma_rd
,NR_DMA_RX
)) { /* @@@ +1 is ugly */
465 printk(KERN_WARNING DEV_LABEL
"(itf %d): RX DMA full\n",
469 for (i
= 0; i
< j
; i
++) {
470 writel(dma
[i
*2],eni_dev
->rx_dma
+dma_wr
*8);
471 writel(dma
[i
*2+1],eni_dev
->rx_dma
+dma_wr
*8+4);
472 dma_wr
= (dma_wr
+1) & (NR_DMA_RX
-1);
475 ENI_PRV_POS(skb
) = eni_vcc
->descr
+size
+1;
476 skb_queue_tail(&eni_dev
->rx_queue
,skb
);
480 eni_vcc
->descr
= here
;
481 eni_out(dma_wr
,MID_DMA_WR_RX
);
486 dma_unmap_single(&eni_dev
->pci_dev
->dev
,paddr
,skb
->len
,
489 if (skb
) dev_kfree_skb_irq(skb
);
494 static void discard(struct atm_vcc
*vcc
,unsigned long size
)
496 struct eni_vcc
*eni_vcc
;
498 eni_vcc
= ENI_VCC(vcc
);
499 EVENT("discard (size=%ld)\n",size
,0);
500 while (do_rx_dma(vcc
,NULL
,1,size
,0)) EVENT("BUSY LOOP",0,0);
501 /* could do a full fallback, but that might be more expensive */
502 if (eni_vcc
->rxing
) ENI_PRV_POS(eni_vcc
->last
) += size
+1;
503 else eni_vcc
->rx_pos
= (eni_vcc
->rx_pos
+size
+1) & (eni_vcc
->words
-1);
508 * TODO: should check whether direct copies (without DMA setup, dequeuing on
509 * interrupt, etc.) aren't much faster for AAL0
512 static int rx_aal0(struct atm_vcc
*vcc
)
514 struct eni_vcc
*eni_vcc
;
516 unsigned long length
;
519 DPRINTK(">rx_aal0\n");
520 eni_vcc
= ENI_VCC(vcc
);
521 descr
= readl(eni_vcc
->recv
+eni_vcc
->descr
*4);
522 if ((descr
& MID_RED_IDEN
) != (MID_RED_RX_ID
<< MID_RED_SHIFT
)) {
526 if (descr
& MID_RED_T
) {
527 DPRINTK(DEV_LABEL
"(itf %d): trashing empty cell\n",
530 atomic_inc(&vcc
->stats
->rx_err
);
533 length
= ATM_CELL_SIZE
-1; /* no HEC */
535 skb
= length
? atm_alloc_charge(vcc
,length
,GFP_ATOMIC
) : NULL
;
537 discard(vcc
,length
>> 2);
541 skb
->tstamp
= eni_vcc
->timestamp
;
542 DPRINTK("got len %ld\n",length
);
543 if (do_rx_dma(vcc
,skb
,1,length
>> 2,length
>> 2)) return 1;
549 static int rx_aal5(struct atm_vcc
*vcc
)
551 struct eni_vcc
*eni_vcc
;
553 unsigned long size
,eff
,length
;
556 EVENT("rx_aal5\n",0,0);
557 DPRINTK(">rx_aal5\n");
558 eni_vcc
= ENI_VCC(vcc
);
559 descr
= readl(eni_vcc
->recv
+eni_vcc
->descr
*4);
560 if ((descr
& MID_RED_IDEN
) != (MID_RED_RX_ID
<< MID_RED_SHIFT
)) {
564 if (descr
& (MID_RED_T
| MID_RED_CRC_ERR
)) {
565 if (descr
& MID_RED_T
) {
566 EVENT("empty cell (descr=0x%lx)\n",descr
,0);
567 DPRINTK(DEV_LABEL
"(itf %d): trashing empty cell\n",
572 static unsigned long silence
= 0;
574 if (time_after(jiffies
, silence
) || silence
== 0) {
575 printk(KERN_WARNING DEV_LABEL
"(itf %d): "
576 "discarding PDU(s) with CRC error\n",
578 silence
= (jiffies
+2*HZ
)|1;
580 size
= (descr
& MID_RED_COUNT
)*(ATM_CELL_PAYLOAD
>> 2);
581 EVENT("CRC error (descr=0x%lx,size=%ld)\n",descr
,
585 atomic_inc(&vcc
->stats
->rx_err
);
588 size
= (descr
& MID_RED_COUNT
)*(ATM_CELL_PAYLOAD
>> 2);
589 DPRINTK("size=%ld\n",size
);
590 length
= readl(eni_vcc
->recv
+(((eni_vcc
->descr
+size
-1) &
591 (eni_vcc
->words
-1)))*4) & 0xffff;
592 /* -trailer(2)+header(1) */
593 if (length
&& length
<= (size
<< 2)-8 && length
<=
594 ATM_MAX_AAL5_PDU
) eff
= (length
+3) >> 2;
595 else { /* ^ trailer length (8) */
596 EVENT("bad PDU (descr=0x08%lx,length=%ld)\n",descr
,
598 printk(KERN_ERR DEV_LABEL
"(itf %d): bad AAL5 PDU "
599 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
600 vcc
->dev
->number
,vcc
->vci
,length
,size
<< 2,descr
);
602 atomic_inc(&vcc
->stats
->rx_err
);
605 skb
= eff
? atm_alloc_charge(vcc
,eff
<< 2,GFP_ATOMIC
) : NULL
;
611 DPRINTK("got len %ld\n",length
);
612 if (do_rx_dma(vcc
,skb
,1,size
,eff
)) return 1;
618 static inline int rx_vcc(struct atm_vcc
*vcc
)
620 void __iomem
*vci_dsc
;
622 struct eni_vcc
*eni_vcc
;
624 eni_vcc
= ENI_VCC(vcc
);
625 vci_dsc
= ENI_DEV(vcc
->dev
)->vci
+vcc
->vci
*16;
626 EVENT("rx_vcc(1)\n",0,0);
627 while (eni_vcc
->descr
!= (tmp
= (readl(vci_dsc
+4) & MID_VCI_DESCR
) >>
628 MID_VCI_DESCR_SHIFT
)) {
629 EVENT("rx_vcc(2: host dsc=0x%lx, nic dsc=0x%lx)\n",
631 DPRINTK("CB_DESCR %ld REG_DESCR %d\n",ENI_VCC(vcc
)->descr
,
632 (((unsigned) readl(vci_dsc
+4) & MID_VCI_DESCR
) >>
633 MID_VCI_DESCR_SHIFT
));
634 if (ENI_VCC(vcc
)->rx(vcc
)) return 1;
636 /* clear IN_SERVICE flag */
637 writel(readl(vci_dsc
) & ~MID_VCI_IN_SERVICE
,vci_dsc
);
639 * If new data has arrived between evaluating the while condition and
640 * clearing IN_SERVICE, we wouldn't be notified until additional data
641 * follows. So we have to loop again to be sure.
643 EVENT("rx_vcc(3)\n",0,0);
644 while (ENI_VCC(vcc
)->descr
!= (tmp
= (readl(vci_dsc
+4) & MID_VCI_DESCR
)
645 >> MID_VCI_DESCR_SHIFT
)) {
646 EVENT("rx_vcc(4: host dsc=0x%lx, nic dsc=0x%lx)\n",
648 DPRINTK("CB_DESCR %ld REG_DESCR %d\n",ENI_VCC(vcc
)->descr
,
649 (((unsigned) readl(vci_dsc
+4) & MID_VCI_DESCR
) >>
650 MID_VCI_DESCR_SHIFT
));
651 if (ENI_VCC(vcc
)->rx(vcc
)) return 1;
657 static void poll_rx(struct atm_dev
*dev
)
659 struct eni_dev
*eni_dev
;
660 struct atm_vcc
*curr
;
662 eni_dev
= ENI_DEV(dev
);
663 while ((curr
= eni_dev
->fast
)) {
664 EVENT("poll_rx.fast\n",0,0);
665 if (rx_vcc(curr
)) return;
666 eni_dev
->fast
= ENI_VCC(curr
)->next
;
667 ENI_VCC(curr
)->next
= ENI_VCC_NOS
;
669 ENI_VCC(curr
)->servicing
--;
671 while ((curr
= eni_dev
->slow
)) {
672 EVENT("poll_rx.slow\n",0,0);
673 if (rx_vcc(curr
)) return;
674 eni_dev
->slow
= ENI_VCC(curr
)->next
;
675 ENI_VCC(curr
)->next
= ENI_VCC_NOS
;
677 ENI_VCC(curr
)->servicing
--;
682 static void get_service(struct atm_dev
*dev
)
684 struct eni_dev
*eni_dev
;
688 DPRINTK(">get_service\n");
689 eni_dev
= ENI_DEV(dev
);
690 while (eni_in(MID_SERV_WRITE
) != eni_dev
->serv_read
) {
691 vci
= readl(eni_dev
->service
+eni_dev
->serv_read
*4);
692 eni_dev
->serv_read
= (eni_dev
->serv_read
+1) & (NR_SERVICE
-1);
693 vcc
= eni_dev
->rx_map
[vci
& 1023];
695 printk(KERN_CRIT DEV_LABEL
"(itf %d): VCI %ld not "
696 "found\n",dev
->number
,vci
);
697 continue; /* nasty but we try to go on anyway */
698 /* @@@ nope, doesn't work */
700 EVENT("getting from service\n",0,0);
701 if (ENI_VCC(vcc
)->next
!= ENI_VCC_NOS
) {
702 EVENT("double service\n",0,0);
703 DPRINTK("Grr, servicing VCC %ld twice\n",vci
);
706 ENI_VCC(vcc
)->timestamp
= ktime_get_real();
707 ENI_VCC(vcc
)->next
= NULL
;
708 if (vcc
->qos
.rxtp
.traffic_class
== ATM_CBR
) {
710 ENI_VCC(eni_dev
->last_fast
)->next
= vcc
;
711 else eni_dev
->fast
= vcc
;
712 eni_dev
->last_fast
= vcc
;
716 ENI_VCC(eni_dev
->last_slow
)->next
= vcc
;
717 else eni_dev
->slow
= vcc
;
718 eni_dev
->last_slow
= vcc
;
721 ENI_VCC(vcc
)->servicing
++;
726 static void dequeue_rx(struct atm_dev
*dev
)
728 struct eni_dev
*eni_dev
;
729 struct eni_vcc
*eni_vcc
;
732 void __iomem
*vci_dsc
;
735 eni_dev
= ENI_DEV(dev
);
738 skb
= skb_dequeue(&eni_dev
->rx_queue
);
741 DPRINTK(DEV_LABEL
"(itf %d): RX but not "
742 "rxing\n",dev
->number
);
743 EVENT("nothing to dequeue\n",0,0);
747 EVENT("dequeued (size=%ld,pos=0x%lx)\n",ENI_PRV_SIZE(skb
),
750 vcc
= ATM_SKB(skb
)->vcc
;
751 eni_vcc
= ENI_VCC(vcc
);
753 vci_dsc
= eni_dev
->vci
+vcc
->vci
*16;
754 if (!EEPMOK(eni_vcc
->rx_pos
,ENI_PRV_SIZE(skb
),
755 (readl(vci_dsc
+4) & MID_VCI_READ
) >> MID_VCI_READ_SHIFT
,
757 EVENT("requeuing\n",0,0);
758 skb_queue_head(&eni_dev
->rx_queue
,skb
);
762 eni_vcc
->rx_pos
= ENI_PRV_POS(skb
) & (eni_vcc
->words
-1);
763 dma_unmap_single(&eni_dev
->pci_dev
->dev
,ENI_PRV_PADDR(skb
),skb
->len
,
765 if (!skb
->len
) dev_kfree_skb_irq(skb
);
767 EVENT("pushing (len=%ld)\n",skb
->len
,0);
768 if (vcc
->qos
.aal
== ATM_AAL0
)
769 *(unsigned long *) skb
->data
=
770 ntohl(*(unsigned long *) skb
->data
);
771 memset(skb
->cb
,0,sizeof(struct eni_skb_prv
));
775 atomic_inc(&vcc
->stats
->rx
);
777 wake_up(&eni_dev
->rx_wait
);
781 static int open_rx_first(struct atm_vcc
*vcc
)
783 struct eni_dev
*eni_dev
;
784 struct eni_vcc
*eni_vcc
;
787 DPRINTK("open_rx_first\n");
788 eni_dev
= ENI_DEV(vcc
->dev
);
789 eni_vcc
= ENI_VCC(vcc
);
791 if (vcc
->qos
.rxtp
.traffic_class
== ATM_NONE
) return 0;
792 size
= vcc
->qos
.rxtp
.max_sdu
*eni_dev
->rx_mult
/100;
793 if (size
> MID_MAX_BUF_SIZE
&& vcc
->qos
.rxtp
.max_sdu
<=
795 size
= MID_MAX_BUF_SIZE
;
796 eni_vcc
->recv
= eni_alloc_mem(eni_dev
,&size
);
797 DPRINTK("rx at 0x%lx\n",eni_vcc
->recv
);
798 eni_vcc
->words
= size
>> 2;
799 if (!eni_vcc
->recv
) return -ENOBUFS
;
800 eni_vcc
->rx
= vcc
->qos
.aal
== ATM_AAL5
? rx_aal5
: rx_aal0
;
804 eni_vcc
->servicing
= 0;
805 eni_vcc
->next
= ENI_VCC_NOS
;
810 static int open_rx_second(struct atm_vcc
*vcc
)
813 struct eni_dev
*eni_dev
;
814 struct eni_vcc
*eni_vcc
;
818 DPRINTK("open_rx_second\n");
819 eni_dev
= ENI_DEV(vcc
->dev
);
820 eni_vcc
= ENI_VCC(vcc
);
821 if (!eni_vcc
->rx
) return 0;
822 /* set up VCI descriptor */
823 here
= eni_dev
->vci
+vcc
->vci
*16;
824 DPRINTK("loc 0x%x\n",(unsigned) (eni_vcc
->recv
-eni_dev
->ram
)/4);
825 size
= eni_vcc
->words
>> 8;
826 for (order
= -1; size
; order
++) size
>>= 1;
827 writel(0,here
+4); /* descr, read = 0 */
828 writel(0,here
+8); /* write, state, count = 0 */
829 if (eni_dev
->rx_map
[vcc
->vci
])
830 printk(KERN_CRIT DEV_LABEL
"(itf %d): BUG - VCI %d already "
831 "in use\n",vcc
->dev
->number
,vcc
->vci
);
832 eni_dev
->rx_map
[vcc
->vci
] = vcc
; /* now it counts */
833 writel(((vcc
->qos
.aal
!= ATM_AAL5
? MID_MODE_RAW
: MID_MODE_AAL5
) <<
834 MID_VCI_MODE_SHIFT
) | MID_VCI_PTI_MODE
|
835 (((eni_vcc
->recv
-eni_dev
->ram
) >> (MID_LOC_SKIP
+2)) <<
836 MID_VCI_LOCATION_SHIFT
) | (order
<< MID_VCI_SIZE_SHIFT
),here
);
841 static void close_rx(struct atm_vcc
*vcc
)
843 DECLARE_WAITQUEUE(wait
,current
);
845 struct eni_dev
*eni_dev
;
846 struct eni_vcc
*eni_vcc
;
848 eni_vcc
= ENI_VCC(vcc
);
849 if (!eni_vcc
->rx
) return;
850 eni_dev
= ENI_DEV(vcc
->dev
);
851 if (vcc
->vpi
!= ATM_VPI_UNSPEC
&& vcc
->vci
!= ATM_VCI_UNSPEC
) {
852 here
= eni_dev
->vci
+vcc
->vci
*16;
854 writel((readl(here
) & ~MID_VCI_MODE
) | (MID_MODE_TRASH
<<
855 MID_VCI_MODE_SHIFT
),here
);
856 /* wait for receiver to become idle */
858 /* discard pending cell */
859 writel(readl(here
) & ~MID_VCI_IN_SERVICE
,here
);
860 /* don't accept any new ones */
861 eni_dev
->rx_map
[vcc
->vci
] = NULL
;
862 /* wait for RX queue to drain */
863 DPRINTK("eni_close: waiting for RX ...\n");
864 EVENT("RX closing\n",0,0);
865 add_wait_queue(&eni_dev
->rx_wait
,&wait
);
866 set_current_state(TASK_UNINTERRUPTIBLE
);
869 /* transition service->rx: rxing++, servicing-- */
870 if (!eni_vcc
->servicing
) {
872 if (!eni_vcc
->rxing
) break;
874 EVENT("drain PDUs (rx %ld, serv %ld)\n",eni_vcc
->rxing
,
876 printk(KERN_INFO
"%d+%d RX left\n",eni_vcc
->servicing
,
879 set_current_state(TASK_UNINTERRUPTIBLE
);
885 tasklet_disable(&eni_dev
->task
);
886 tmp
= readl(eni_dev
->vci
+vcc
->vci
*16+4) & MID_VCI_READ
;
887 at_end
= eni_vcc
->rx_pos
== tmp
>> MID_VCI_READ_SHIFT
;
888 tasklet_enable(&eni_dev
->task
);
890 EVENT("drain discard (host 0x%lx, nic 0x%lx)\n",
891 eni_vcc
->rx_pos
,tmp
);
892 printk(KERN_INFO
"draining RX: host 0x%lx, nic 0x%x\n",
893 eni_vcc
->rx_pos
,tmp
);
895 set_current_state(TASK_UNINTERRUPTIBLE
);
897 set_current_state(TASK_RUNNING
);
898 remove_wait_queue(&eni_dev
->rx_wait
,&wait
);
900 eni_free_mem(eni_dev
,eni_vcc
->recv
,eni_vcc
->words
<< 2);
905 static int start_rx(struct atm_dev
*dev
)
907 struct eni_dev
*eni_dev
;
909 eni_dev
= ENI_DEV(dev
);
910 eni_dev
->rx_map
= (struct atm_vcc
**) get_zeroed_page(GFP_KERNEL
);
911 if (!eni_dev
->rx_map
) {
912 printk(KERN_ERR DEV_LABEL
"(itf %d): couldn't get free page\n",
914 free_page((unsigned long) eni_dev
->free_list
);
917 eni_dev
->rx_mult
= DEFAULT_RX_MULT
;
918 eni_dev
->fast
= eni_dev
->last_fast
= NULL
;
919 eni_dev
->slow
= eni_dev
->last_slow
= NULL
;
920 init_waitqueue_head(&eni_dev
->rx_wait
);
921 skb_queue_head_init(&eni_dev
->rx_queue
);
922 eni_dev
->serv_read
= eni_in(MID_SERV_WRITE
);
923 eni_out(0,MID_DMA_WR_RX
);
928 /*----------------------------------- TX ------------------------------------*/
931 enum enq_res
{ enq_ok
,enq_next
,enq_jam
};
934 static inline void put_dma(int chan
,u32
*dma
,int *j
,dma_addr_t paddr
,
939 DPRINTK("put_dma: 0x%lx+0x%x\n",(unsigned long) paddr
,size
);
940 EVENT("put_dma: 0x%lx+0x%lx\n",(unsigned long) paddr
,size
);
941 #if 0 /* don't complain anymore */
943 printk(KERN_ERR
"put_dma: unaligned addr (0x%lx)\n",paddr
);
945 printk(KERN_ERR
"put_dma: unaligned size (0x%lx)\n",size
);
948 init
= 4-(paddr
& 3);
949 if (init
> size
|| size
< 7) init
= size
;
950 DPRINTK("put_dma: %lx DMA: %d/%d bytes\n",
951 (unsigned long) paddr
,init
,size
);
952 dma
[(*j
)++] = MID_DT_BYTE
| (init
<< MID_DMA_COUNT_SHIFT
) |
953 (chan
<< MID_DMA_CHAN_SHIFT
);
960 if (words
&& (paddr
& 31)) {
961 init
= 8-((paddr
& 31) >> 2);
962 if (init
> words
) init
= words
;
963 DPRINTK("put_dma: %lx DMA: %d/%d words\n",
964 (unsigned long) paddr
,init
,words
);
965 dma
[(*j
)++] = MID_DT_WORD
| (init
<< MID_DMA_COUNT_SHIFT
) |
966 (chan
<< MID_DMA_CHAN_SHIFT
);
971 #ifdef CONFIG_ATM_ENI_BURST_TX_16W /* may work with some PCI chipsets ... */
973 DPRINTK("put_dma: %lx DMA: %d*16/%d words\n",
974 (unsigned long) paddr
,words
>> 4,words
);
975 dma
[(*j
)++] = MID_DT_16W
| ((words
>> 4) << MID_DMA_COUNT_SHIFT
)
976 | (chan
<< MID_DMA_CHAN_SHIFT
);
978 paddr
+= (words
& ~15) << 2;
982 #ifdef CONFIG_ATM_ENI_BURST_TX_8W /* recommended */
984 DPRINTK("put_dma: %lx DMA: %d*8/%d words\n",
985 (unsigned long) paddr
,words
>> 3,words
);
986 dma
[(*j
)++] = MID_DT_8W
| ((words
>> 3) << MID_DMA_COUNT_SHIFT
)
987 | (chan
<< MID_DMA_CHAN_SHIFT
);
989 paddr
+= (words
& ~7) << 2;
993 #ifdef CONFIG_ATM_ENI_BURST_TX_4W /* probably useless if TX_8W or TX_16W */
995 DPRINTK("put_dma: %lx DMA: %d*4/%d words\n",
996 (unsigned long) paddr
,words
>> 2,words
);
997 dma
[(*j
)++] = MID_DT_4W
| ((words
>> 2) << MID_DMA_COUNT_SHIFT
)
998 | (chan
<< MID_DMA_CHAN_SHIFT
);
1000 paddr
+= (words
& ~3) << 2;
1004 #ifdef CONFIG_ATM_ENI_BURST_TX_2W /* probably useless if TX_4W, TX_8W, ... */
1006 DPRINTK("put_dma: %lx DMA: %d*2/%d words\n",
1007 (unsigned long) paddr
,words
>> 1,words
);
1008 dma
[(*j
)++] = MID_DT_2W
| ((words
>> 1) << MID_DMA_COUNT_SHIFT
)
1009 | (chan
<< MID_DMA_CHAN_SHIFT
);
1010 dma
[(*j
)++] = paddr
;
1011 paddr
+= (words
& ~1) << 2;
1016 DPRINTK("put_dma: %lx DMA: %d words\n",(unsigned long) paddr
,
1018 dma
[(*j
)++] = MID_DT_WORD
| (words
<< MID_DMA_COUNT_SHIFT
) |
1019 (chan
<< MID_DMA_CHAN_SHIFT
);
1020 dma
[(*j
)++] = paddr
;
1021 paddr
+= words
<< 2;
1024 DPRINTK("put_dma: %lx DMA: %d bytes\n",(unsigned long) paddr
,
1026 dma
[(*j
)++] = MID_DT_BYTE
| (size
<< MID_DMA_COUNT_SHIFT
) |
1027 (chan
<< MID_DMA_CHAN_SHIFT
);
1028 dma
[(*j
)++] = paddr
;
1033 static enum enq_res
do_tx(struct sk_buff
*skb
)
1035 struct atm_vcc
*vcc
;
1036 struct eni_dev
*eni_dev
;
1037 struct eni_vcc
*eni_vcc
;
1041 u32 size
; /* in words */
1042 int aal5
,dma_size
,i
,j
;
1044 DPRINTK(">do_tx\n");
1046 EVENT("do_tx: skb=0x%lx, %ld bytes\n",(unsigned long) skb
,skb
->len
);
1047 vcc
= ATM_SKB(skb
)->vcc
;
1049 eni_dev
= ENI_DEV(vcc
->dev
);
1051 eni_vcc
= ENI_VCC(vcc
);
1054 #if 0 /* Enable this for testing with the "align" program */
1056 unsigned int hack
= *((char *) skb
->data
)-'0';
1064 #if 0 /* should work now */
1065 if ((unsigned long) skb
->data
& 3)
1066 printk(KERN_ERR DEV_LABEL
"(itf %d): VCI %d has mis-aligned "
1067 "TX data\n",vcc
->dev
->number
,vcc
->vci
);
1070 * Potential future IP speedup: make hard_header big enough to put
1071 * segmentation descriptor directly into PDU. Saves: 4 slave writes,
1072 * 1 DMA xfer & 2 DMA'ed bytes (protocol layering is for wimps :-)
1075 aal5
= vcc
->qos
.aal
== ATM_AAL5
;
1076 /* check space in buffer */
1078 size
= (ATM_CELL_PAYLOAD
>> 2)+TX_DESCR_SIZE
;
1079 /* cell without HEC plus segmentation header (includes
1080 four-byte cell header) */
1082 size
= skb
->len
+4*AAL5_TRAILER
+ATM_CELL_PAYLOAD
-1;
1083 /* add AAL5 trailer */
1084 size
= ((size
-(size
% ATM_CELL_PAYLOAD
)) >> 2)+TX_DESCR_SIZE
;
1085 /* add segmentation header */
1088 * Can I move tx_pos by size bytes without getting closer than TX_GAP
1089 * to the read pointer ? TX_GAP means to leave some space for what
1090 * the manual calls "too close".
1092 if (!NEPMOK(tx
->tx_pos
,size
+TX_GAP
,
1093 eni_in(MID_TX_RDPTR(tx
->index
)),tx
->words
)) {
1094 DPRINTK(DEV_LABEL
"(itf %d): TX full (size %d)\n",
1095 vcc
->dev
->number
,size
);
1099 dma_wr
= eni_in(MID_DMA_WR_TX
);
1100 dma_rd
= eni_in(MID_DMA_RD_TX
);
1101 dma_size
= 3; /* JK for descriptor and final fill, plus final size
1102 mis-alignment fix */
1103 DPRINTK("iovcnt = %d\n",skb_shinfo(skb
)->nr_frags
);
1104 if (!skb_shinfo(skb
)->nr_frags
) dma_size
+= 5;
1105 else dma_size
+= 5*(skb_shinfo(skb
)->nr_frags
+1);
1106 if (dma_size
> TX_DMA_BUF
) {
1107 printk(KERN_CRIT DEV_LABEL
"(itf %d): needs %d DMA entries "
1108 "(got only %d)\n",vcc
->dev
->number
,dma_size
,TX_DMA_BUF
);
1110 DPRINTK("dma_wr is %d, tx_pos is %ld\n",dma_wr
,tx
->tx_pos
);
1111 if (dma_wr
!= dma_rd
&& ((dma_rd
+NR_DMA_TX
-dma_wr
) & (NR_DMA_TX
-1)) <
1113 printk(KERN_WARNING DEV_LABEL
"(itf %d): TX DMA full\n",
1117 paddr
= dma_map_single(&eni_dev
->pci_dev
->dev
,skb
->data
,skb
->len
,
1119 ENI_PRV_PADDR(skb
) = paddr
;
1120 /* prepare DMA queue entries */
1122 eni_dev
->dma
[j
++] = (((tx
->tx_pos
+TX_DESCR_SIZE
) & (tx
->words
-1)) <<
1123 MID_DMA_COUNT_SHIFT
) | (tx
->index
<< MID_DMA_CHAN_SHIFT
) |
1126 if (!skb_shinfo(skb
)->nr_frags
)
1127 if (aal5
) put_dma(tx
->index
,eni_dev
->dma
,&j
,paddr
,skb
->len
);
1128 else put_dma(tx
->index
,eni_dev
->dma
,&j
,paddr
+4,skb
->len
-4);
1130 DPRINTK("doing direct send\n"); /* @@@ well, this doesn't work anyway */
1131 for (i
= -1; i
< skb_shinfo(skb
)->nr_frags
; i
++)
1133 put_dma(tx
->index
,eni_dev
->dma
,&j
,(unsigned long)
1137 put_dma(tx
->index
,eni_dev
->dma
,&j
,(unsigned long)
1138 skb_frag_page(&skb_shinfo(skb
)->frags
[i
]) +
1139 skb_shinfo(skb
)->frags
[i
].page_offset
,
1140 skb_frag_size(&skb_shinfo(skb
)->frags
[i
]));
1143 put_dma(tx
->index
, eni_dev
->dma
, &j
, eni_dev
->zero
.dma
,
1144 4 - (skb
->len
& 3));
1146 /* JK for AAL5 trailer - AAL0 doesn't need it, but who cares ... */
1147 eni_dev
->dma
[j
++] = (((tx
->tx_pos
+size
) & (tx
->words
-1)) <<
1148 MID_DMA_COUNT_SHIFT
) | (tx
->index
<< MID_DMA_CHAN_SHIFT
) |
1149 MID_DMA_END
| MID_DT_JK
;
1151 DPRINTK("DMA at end: %d\n",j
);
1153 writel((MID_SEG_TX_ID
<< MID_SEG_ID_SHIFT
) |
1154 (aal5
? MID_SEG_AAL5
: 0) | (tx
->prescaler
<< MID_SEG_PR_SHIFT
) |
1155 (tx
->resolution
<< MID_SEG_RATE_SHIFT
) |
1156 (size
/(ATM_CELL_PAYLOAD
/4)),tx
->send
+tx
->tx_pos
*4);
1157 /*printk("dsc = 0x%08lx\n",(unsigned long) readl(tx->send+tx->tx_pos*4));*/
1158 writel((vcc
->vci
<< MID_SEG_VCI_SHIFT
) |
1159 (aal5
? 0 : (skb
->data
[3] & 0xf)) |
1160 (ATM_SKB(skb
)->atm_options
& ATM_ATMOPT_CLP
? MID_SEG_CLP
: 0),
1161 tx
->send
+((tx
->tx_pos
+1) & (tx
->words
-1))*4);
1162 DPRINTK("size: %d, len:%d\n",size
,skb
->len
);
1164 writel(skb
->len
,tx
->send
+
1165 ((tx
->tx_pos
+size
-AAL5_TRAILER
) & (tx
->words
-1))*4);
1167 for (i
= 0; i
< j
; i
++) {
1168 writel(eni_dev
->dma
[i
*2],eni_dev
->tx_dma
+dma_wr
*8);
1169 writel(eni_dev
->dma
[i
*2+1],eni_dev
->tx_dma
+dma_wr
*8+4);
1170 dma_wr
= (dma_wr
+1) & (NR_DMA_TX
-1);
1172 ENI_PRV_POS(skb
) = tx
->tx_pos
;
1173 ENI_PRV_SIZE(skb
) = size
;
1174 ENI_VCC(vcc
)->txing
+= size
;
1175 tx
->tx_pos
= (tx
->tx_pos
+size
) & (tx
->words
-1);
1176 DPRINTK("dma_wr set to %d, tx_pos is now %ld\n",dma_wr
,tx
->tx_pos
);
1177 eni_out(dma_wr
,MID_DMA_WR_TX
);
1178 skb_queue_tail(&eni_dev
->tx_queue
,skb
);
1184 static void poll_tx(struct atm_dev
*dev
)
1187 struct sk_buff
*skb
;
1191 DPRINTK(">poll_tx\n");
1192 for (i
= NR_CHAN
-1; i
>= 0; i
--) {
1193 tx
= &ENI_DEV(dev
)->tx
[i
];
1195 while ((skb
= skb_dequeue(&tx
->backlog
))) {
1197 if (res
== enq_ok
) continue;
1198 DPRINTK("re-queuing TX PDU\n");
1199 skb_queue_head(&tx
->backlog
,skb
);
1201 if (res
== enq_jam
) return;
1208 static void dequeue_tx(struct atm_dev
*dev
)
1210 struct eni_dev
*eni_dev
;
1211 struct atm_vcc
*vcc
;
1212 struct sk_buff
*skb
;
1216 eni_dev
= ENI_DEV(dev
);
1218 while ((skb
= skb_dequeue(&eni_dev
->tx_queue
))) {
1219 vcc
= ATM_SKB(skb
)->vcc
;
1221 tx
= ENI_VCC(vcc
)->tx
;
1222 NULLCHECK(ENI_VCC(vcc
)->tx
);
1223 DPRINTK("dequeue_tx: next 0x%lx curr 0x%x\n",ENI_PRV_POS(skb
),
1224 (unsigned) eni_in(MID_TX_DESCRSTART(tx
->index
)));
1225 if (ENI_VCC(vcc
)->txing
< tx
->words
&& ENI_PRV_POS(skb
) ==
1226 eni_in(MID_TX_DESCRSTART(tx
->index
))) {
1227 skb_queue_head(&eni_dev
->tx_queue
,skb
);
1230 ENI_VCC(vcc
)->txing
-= ENI_PRV_SIZE(skb
);
1231 dma_unmap_single(&eni_dev
->pci_dev
->dev
,ENI_PRV_PADDR(skb
),skb
->len
,
1233 if (vcc
->pop
) vcc
->pop(vcc
,skb
);
1234 else dev_kfree_skb_irq(skb
);
1235 atomic_inc(&vcc
->stats
->tx
);
1236 wake_up(&eni_dev
->tx_wait
);
1242 static struct eni_tx
*alloc_tx(struct eni_dev
*eni_dev
,int ubr
)
1246 for (i
= !ubr
; i
< NR_CHAN
; i
++)
1247 if (!eni_dev
->tx
[i
].send
) return eni_dev
->tx
+i
;
1252 static int comp_tx(struct eni_dev
*eni_dev
,int *pcr
,int reserved
,int *pre
,
1253 int *res
,int unlimited
)
1255 static const int pre_div
[] = { 4,16,128,2048 };
1256 /* 2^(((x+2)^2-(x+2))/2+1) */
1258 if (unlimited
) *pre
= *res
= 0;
1263 for (*pre
= 0; *pre
< 3; (*pre
)++)
1264 if (TS_CLOCK
/pre_div
[*pre
]/64 <= *pcr
) break;
1265 div
= pre_div
[*pre
]**pcr
;
1266 DPRINTK("min div %d\n",div
);
1267 *res
= TS_CLOCK
/div
-1;
1272 if (!*pcr
) *pcr
= eni_dev
->tx_bw
+reserved
;
1273 for (*pre
= 3; *pre
>= 0; (*pre
)--)
1274 if (TS_CLOCK
/pre_div
[*pre
]/64 > -*pcr
) break;
1275 if (*pre
< 3) (*pre
)++; /* else fail later */
1276 div
= pre_div
[*pre
]*-*pcr
;
1277 DPRINTK("max div %d\n",div
);
1278 *res
= DIV_ROUND_UP(TS_CLOCK
, div
)-1;
1280 if (*res
< 0) *res
= 0;
1281 if (*res
> MID_SEG_MAX_RATE
) *res
= MID_SEG_MAX_RATE
;
1283 *pcr
= TS_CLOCK
/pre_div
[*pre
]/(*res
+1);
1284 DPRINTK("out pcr: %d (%d:%d)\n",*pcr
,*pre
,*res
);
1289 static int reserve_or_set_tx(struct atm_vcc
*vcc
,struct atm_trafprm
*txtp
,
1290 int set_rsv
,int set_shp
)
1292 struct eni_dev
*eni_dev
= ENI_DEV(vcc
->dev
);
1293 struct eni_vcc
*eni_vcc
= ENI_VCC(vcc
);
1297 int rate
,ubr
,unlimited
,new_tx
;
1301 rate
= atm_pcr_goal(txtp
);
1302 ubr
= txtp
->traffic_class
== ATM_UBR
;
1303 unlimited
= ubr
&& (!rate
|| rate
<= -ATM_OC3_PCR
||
1304 rate
>= ATM_OC3_PCR
);
1306 size
= txtp
->max_sdu
*eni_dev
->tx_mult
/100;
1307 if (size
> MID_MAX_BUF_SIZE
&& txtp
->max_sdu
<=
1309 size
= MID_MAX_BUF_SIZE
;
1313 eni_vcc
->tx
= eni_dev
->ubr
;
1314 txtp
->pcr
= ATM_OC3_PCR
;
1319 new_tx
= !eni_vcc
->tx
;
1320 mem
= NULL
; /* for gcc */
1321 if (!new_tx
) tx
= eni_vcc
->tx
;
1323 mem
= eni_alloc_mem(eni_dev
,&size
);
1324 if (!mem
) return -ENOBUFS
;
1325 tx
= alloc_tx(eni_dev
,unlimited
);
1327 eni_free_mem(eni_dev
,mem
,size
);
1330 DPRINTK("got chan %d\n",tx
->index
);
1331 tx
->reserved
= tx
->shaping
= 0;
1333 tx
->words
= size
>> 2;
1334 skb_queue_head_init(&tx
->backlog
);
1335 for (order
= 0; size
> (1 << (order
+10)); order
++);
1336 eni_out((order
<< MID_SIZE_SHIFT
) |
1337 ((tx
->send
-eni_dev
->ram
) >> (MID_LOC_SKIP
+2)),
1338 MID_TX_PLACE(tx
->index
));
1339 tx
->tx_pos
= eni_in(MID_TX_DESCRSTART(tx
->index
)) &
1342 error
= comp_tx(eni_dev
,&rate
,tx
->reserved
,&pre
,&res
,unlimited
);
1343 if (!error
&& txtp
->min_pcr
> rate
) error
= -EINVAL
;
1344 if (!error
&& txtp
->max_pcr
&& txtp
->max_pcr
!= ATM_MAX_PCR
&&
1345 txtp
->max_pcr
< rate
) error
= -EINVAL
;
1346 if (!error
&& !ubr
&& rate
> eni_dev
->tx_bw
+tx
->reserved
)
1348 if (!error
&& set_rsv
&& !set_shp
&& rate
< tx
->shaping
)
1350 if (!error
&& !set_rsv
&& rate
> tx
->reserved
&& !ubr
)
1355 eni_free_mem(eni_dev
,mem
,size
);
1360 if (set_rsv
&& !ubr
) {
1361 eni_dev
->tx_bw
+= tx
->reserved
;
1362 tx
->reserved
= rate
;
1363 eni_dev
->tx_bw
-= rate
;
1365 if (set_shp
|| (unlimited
&& new_tx
)) {
1366 if (unlimited
&& new_tx
) eni_dev
->ubr
= tx
;
1367 tx
->prescaler
= pre
;
1368 tx
->resolution
= res
;
1371 if (set_shp
) eni_vcc
->tx
= tx
;
1372 DPRINTK("rsv %d shp %d\n",tx
->reserved
,tx
->shaping
);
1377 static int open_tx_first(struct atm_vcc
*vcc
)
1379 ENI_VCC(vcc
)->tx
= NULL
;
1380 if (vcc
->qos
.txtp
.traffic_class
== ATM_NONE
) return 0;
1381 ENI_VCC(vcc
)->txing
= 0;
1382 return reserve_or_set_tx(vcc
,&vcc
->qos
.txtp
,1,1);
1386 static int open_tx_second(struct atm_vcc
*vcc
)
1388 return 0; /* nothing to do */
1392 static void close_tx(struct atm_vcc
*vcc
)
1394 DECLARE_WAITQUEUE(wait
,current
);
1395 struct eni_dev
*eni_dev
;
1396 struct eni_vcc
*eni_vcc
;
1398 eni_vcc
= ENI_VCC(vcc
);
1399 if (!eni_vcc
->tx
) return;
1400 eni_dev
= ENI_DEV(vcc
->dev
);
1401 /* wait for TX queue to drain */
1402 DPRINTK("eni_close: waiting for TX ...\n");
1403 add_wait_queue(&eni_dev
->tx_wait
,&wait
);
1404 set_current_state(TASK_UNINTERRUPTIBLE
);
1408 tasklet_disable(&eni_dev
->task
);
1409 txing
= skb_peek(&eni_vcc
->tx
->backlog
) || eni_vcc
->txing
;
1410 tasklet_enable(&eni_dev
->task
);
1412 DPRINTK("%d TX left\n",eni_vcc
->txing
);
1414 set_current_state(TASK_UNINTERRUPTIBLE
);
1416 set_current_state(TASK_RUNNING
);
1417 remove_wait_queue(&eni_dev
->tx_wait
,&wait
);
1418 if (eni_vcc
->tx
!= eni_dev
->ubr
) {
1420 * Looping a few times in here is probably far cheaper than
1421 * keeping track of TX completions all the time, so let's poll
1424 while (eni_in(MID_TX_RDPTR(eni_vcc
->tx
->index
)) !=
1425 eni_in(MID_TX_DESCRSTART(eni_vcc
->tx
->index
)))
1427 eni_free_mem(eni_dev
,eni_vcc
->tx
->send
,eni_vcc
->tx
->words
<< 2);
1428 eni_vcc
->tx
->send
= NULL
;
1429 eni_dev
->tx_bw
+= eni_vcc
->tx
->reserved
;
1435 static int start_tx(struct atm_dev
*dev
)
1437 struct eni_dev
*eni_dev
;
1440 eni_dev
= ENI_DEV(dev
);
1442 eni_dev
->tx_bw
= ATM_OC3_PCR
;
1443 eni_dev
->tx_mult
= DEFAULT_TX_MULT
;
1444 init_waitqueue_head(&eni_dev
->tx_wait
);
1445 eni_dev
->ubr
= NULL
;
1446 skb_queue_head_init(&eni_dev
->tx_queue
);
1447 eni_out(0,MID_DMA_WR_TX
);
1448 for (i
= 0; i
< NR_CHAN
; i
++) {
1449 eni_dev
->tx
[i
].send
= NULL
;
1450 eni_dev
->tx
[i
].index
= i
;
1456 /*--------------------------------- common ----------------------------------*/
1459 #if 0 /* may become useful again when tuning things */
1461 static void foo(void)
1464 "tx_complete=%d,dma_complete=%d,queued=%d,requeued=%d,sub=%d,\n"
1465 "backlogged=%d,rx_enqueued=%d,rx_dequeued=%d,putting=%d,pushed=%d\n",
1466 tx_complete
,dma_complete
,queued
,requeued
,submitted
,backlogged
,
1467 rx_enqueued
,rx_dequeued
,putting
,pushed
);
1468 if (eni_boards
) printk(KERN_INFO
"loss: %ld\n",ENI_DEV(eni_boards
)->lost
);
1474 static void bug_int(struct atm_dev
*dev
,unsigned long reason
)
1476 DPRINTK(">bug_int\n");
1477 if (reason
& MID_DMA_ERR_ACK
)
1478 printk(KERN_CRIT DEV_LABEL
"(itf %d): driver error - DMA "
1479 "error\n",dev
->number
);
1480 if (reason
& MID_TX_IDENT_MISM
)
1481 printk(KERN_CRIT DEV_LABEL
"(itf %d): driver error - ident "
1482 "mismatch\n",dev
->number
);
1483 if (reason
& MID_TX_DMA_OVFL
)
1484 printk(KERN_CRIT DEV_LABEL
"(itf %d): driver error - DMA "
1485 "overflow\n",dev
->number
);
1486 EVENT("---dump ends here---\n",0,0);
1487 printk(KERN_NOTICE
"---recent events---\n");
1492 static irqreturn_t
eni_int(int irq
,void *dev_id
)
1494 struct atm_dev
*dev
;
1495 struct eni_dev
*eni_dev
;
1498 DPRINTK(">eni_int\n");
1500 eni_dev
= ENI_DEV(dev
);
1501 reason
= eni_in(MID_ISA
);
1502 DPRINTK(DEV_LABEL
": int 0x%lx\n",(unsigned long) reason
);
1504 * Must handle these two right now, because reading ISA doesn't clear
1505 * them, so they re-occur and we never make it to the tasklet. Since
1506 * they're rare, we don't mind the occasional invocation of eni_tasklet
1507 * with eni_dev->events == 0.
1509 if (reason
& MID_STAT_OVFL
) {
1510 EVENT("stat overflow\n",0,0);
1511 eni_dev
->lost
+= eni_in(MID_STAT
) & MID_OVFL_TRASH
;
1513 if (reason
& MID_SUNI_INT
) {
1514 EVENT("SUNI int\n",0,0);
1515 dev
->phy
->interrupt(dev
);
1520 spin_lock(&eni_dev
->lock
);
1521 eni_dev
->events
|= reason
;
1522 spin_unlock(&eni_dev
->lock
);
1523 tasklet_schedule(&eni_dev
->task
);
1528 static void eni_tasklet(unsigned long data
)
1530 struct atm_dev
*dev
= (struct atm_dev
*) data
;
1531 struct eni_dev
*eni_dev
= ENI_DEV(dev
);
1532 unsigned long flags
;
1535 DPRINTK("eni_tasklet (dev %p)\n",dev
);
1536 spin_lock_irqsave(&eni_dev
->lock
,flags
);
1537 events
= xchg(&eni_dev
->events
,0);
1538 spin_unlock_irqrestore(&eni_dev
->lock
,flags
);
1539 if (events
& MID_RX_DMA_COMPLETE
) {
1540 EVENT("INT: RX DMA complete, starting dequeue_rx\n",0,0);
1542 EVENT("dequeue_rx done, starting poll_rx\n",0,0);
1544 EVENT("poll_rx done\n",0,0);
1547 if (events
& MID_SERVICE
) {
1548 EVENT("INT: service, starting get_service\n",0,0);
1550 EVENT("get_service done, starting poll_rx\n",0,0);
1552 EVENT("poll_rx done\n",0,0);
1554 if (events
& MID_TX_DMA_COMPLETE
) {
1555 EVENT("INT: TX DMA COMPLETE\n",0,0);
1558 if (events
& MID_TX_COMPLETE
) {
1559 EVENT("INT: TX COMPLETE\n",0,0);
1561 wake_up(&eni_dev
->tx_wait
);
1564 if (events
& (MID_DMA_ERR_ACK
| MID_TX_IDENT_MISM
| MID_TX_DMA_OVFL
)) {
1565 EVENT("bug interrupt\n",0,0);
1566 bug_int(dev
,events
);
1572 /*--------------------------------- entries ---------------------------------*/
1575 static char * const media_name
[] = {
1576 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
1577 "UTP", "05?", "06?", "07?", /* 4- 7 */
1578 "TAXI","09?", "10?", "11?", /* 8-11 */
1579 "12?", "13?", "14?", "15?", /* 12-15 */
1580 "MMF", "SMF", "18?", "19?", /* 16-19 */
1581 "UTP", "21?", "22?", "23?", /* 20-23 */
1582 "24?", "25?", "26?", "27?", /* 24-27 */
1583 "28?", "29?", "30?", "31?" /* 28-31 */
1587 #define SET_SEPROM \
1588 ({ if (!error && !pci_error) { \
1589 pci_error = pci_write_config_byte(eni_dev->pci_dev,PCI_TONGA_CTRL,tonga); \
1590 udelay(10); /* 10 usecs */ \
1592 #define GET_SEPROM \
1593 ({ if (!error && !pci_error) { \
1594 pci_error = pci_read_config_byte(eni_dev->pci_dev,PCI_TONGA_CTRL,&tonga); \
1595 udelay(10); /* 10 usecs */ \
1599 static int get_esi_asic(struct atm_dev
*dev
)
1601 struct eni_dev
*eni_dev
;
1602 unsigned char tonga
;
1603 int error
,failed
,pci_error
;
1606 eni_dev
= ENI_DEV(dev
);
1607 error
= pci_error
= 0;
1608 tonga
= SEPROM_MAGIC
| SEPROM_DATA
| SEPROM_CLK
;
1610 for (i
= 0; i
< ESI_LEN
&& !error
&& !pci_error
; i
++) {
1611 /* start operation */
1612 tonga
|= SEPROM_DATA
;
1614 tonga
|= SEPROM_CLK
;
1616 tonga
&= ~SEPROM_DATA
;
1618 tonga
&= ~SEPROM_CLK
;
1621 address
= ((i
+SEPROM_ESI_BASE
) << 1)+1;
1622 for (j
= 7; j
>= 0; j
--) {
1623 tonga
= (address
>> j
) & 1 ? tonga
| SEPROM_DATA
:
1624 tonga
& ~SEPROM_DATA
;
1626 tonga
|= SEPROM_CLK
;
1628 tonga
&= ~SEPROM_CLK
;
1632 tonga
|= SEPROM_DATA
;
1634 tonga
|= SEPROM_CLK
;
1637 failed
= tonga
& SEPROM_DATA
;
1638 tonga
&= ~SEPROM_CLK
;
1640 tonga
|= SEPROM_DATA
;
1642 if (failed
) error
= -EIO
;
1645 for (j
= 7; j
>= 0; j
--) {
1647 tonga
|= SEPROM_DATA
;
1649 tonga
|= SEPROM_CLK
;
1652 if (tonga
& SEPROM_DATA
) dev
->esi
[i
] |= 1;
1653 tonga
&= ~SEPROM_CLK
;
1655 tonga
|= SEPROM_DATA
;
1659 tonga
|= SEPROM_DATA
;
1661 tonga
|= SEPROM_CLK
;
1664 if (!(tonga
& SEPROM_DATA
)) error
= -EIO
;
1665 tonga
&= ~SEPROM_CLK
;
1667 tonga
|= SEPROM_DATA
;
1670 /* stop operation */
1671 tonga
&= ~SEPROM_DATA
;
1673 tonga
|= SEPROM_CLK
;
1675 tonga
|= SEPROM_DATA
;
1679 printk(KERN_ERR DEV_LABEL
"(itf %d): error reading ESI "
1680 "(0x%02x)\n",dev
->number
,pci_error
);
1691 static int get_esi_fpga(struct atm_dev
*dev
, void __iomem
*base
)
1693 void __iomem
*mac_base
;
1696 mac_base
= base
+EPROM_SIZE
-sizeof(struct midway_eprom
);
1697 for (i
= 0; i
< ESI_LEN
; i
++) dev
->esi
[i
] = readb(mac_base
+(i
^3));
1702 static int eni_do_init(struct atm_dev
*dev
)
1704 struct midway_eprom __iomem
*eprom
;
1705 struct eni_dev
*eni_dev
;
1706 struct pci_dev
*pci_dev
;
1707 unsigned long real_base
;
1711 DPRINTK(">eni_init\n");
1712 dev
->ci_range
.vpi_bits
= 0;
1713 dev
->ci_range
.vci_bits
= NR_VCI_LD
;
1714 dev
->link_rate
= ATM_OC3_PCR
;
1715 eni_dev
= ENI_DEV(dev
);
1716 pci_dev
= eni_dev
->pci_dev
;
1717 real_base
= pci_resource_start(pci_dev
, 0);
1718 eni_dev
->irq
= pci_dev
->irq
;
1719 if ((error
= pci_write_config_word(pci_dev
,PCI_COMMAND
,
1720 PCI_COMMAND_MEMORY
|
1721 (eni_dev
->asic
? PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
: 0)))) {
1722 printk(KERN_ERR DEV_LABEL
"(itf %d): can't enable memory "
1723 "(0x%02x)\n",dev
->number
,error
);
1726 printk(KERN_NOTICE DEV_LABEL
"(itf %d): rev.%d,base=0x%lx,irq=%d,",
1727 dev
->number
,pci_dev
->revision
,real_base
,eni_dev
->irq
);
1728 if (!(base
= ioremap_nocache(real_base
,MAP_MAX_SIZE
))) {
1730 printk(KERN_ERR DEV_LABEL
"(itf %d): can't set up page "
1731 "mapping\n",dev
->number
);
1734 eni_dev
->ioaddr
= base
;
1735 eni_dev
->base_diff
= real_base
- (unsigned long) base
;
1736 /* id may not be present in ASIC Tonga boards - check this @@@ */
1737 if (!eni_dev
->asic
) {
1738 eprom
= (base
+EPROM_SIZE
-sizeof(struct midway_eprom
));
1739 if (readl(&eprom
->magic
) != ENI155_MAGIC
) {
1741 printk(KERN_ERR DEV_LABEL
1742 "(itf %d): bad magic - expected 0x%x, got 0x%x\n",
1743 dev
->number
, ENI155_MAGIC
,
1744 (unsigned)readl(&eprom
->magic
));
1749 eni_dev
->phy
= base
+PHY_BASE
;
1750 eni_dev
->reg
= base
+REG_BASE
;
1751 eni_dev
->ram
= base
+RAM_BASE
;
1752 last
= MAP_MAX_SIZE
-RAM_BASE
;
1753 for (i
= last
-RAM_INCREMENT
; i
>= 0; i
-= RAM_INCREMENT
) {
1754 writel(0x55555555,eni_dev
->ram
+i
);
1755 if (readl(eni_dev
->ram
+i
) != 0x55555555) last
= i
;
1757 writel(0xAAAAAAAA,eni_dev
->ram
+i
);
1758 if (readl(eni_dev
->ram
+i
) != 0xAAAAAAAA) last
= i
;
1759 else writel(i
,eni_dev
->ram
+i
);
1762 for (i
= 0; i
< last
; i
+= RAM_INCREMENT
)
1763 if (readl(eni_dev
->ram
+i
) != i
) break;
1765 memset_io(eni_dev
->ram
,0,eni_dev
->mem
);
1766 /* TODO: should shrink allocation now */
1767 printk("mem=%dkB (",eni_dev
->mem
>> 10);
1768 /* TODO: check for non-SUNI, check for TAXI ? */
1769 if (!(eni_in(MID_RES_ID_MCON
) & 0x200) != !eni_dev
->asic
) {
1771 printk(KERN_ERR DEV_LABEL
"(itf %d): ERROR - wrong id 0x%x\n",
1772 dev
->number
,(unsigned) eni_in(MID_RES_ID_MCON
));
1776 error
= eni_dev
->asic
? get_esi_asic(dev
) : get_esi_fpga(dev
,base
);
1779 for (i
= 0; i
< ESI_LEN
; i
++)
1780 printk("%s%02X",i
? "-" : "",dev
->esi
[i
]);
1782 printk(KERN_NOTICE DEV_LABEL
"(itf %d): %s,%s\n",dev
->number
,
1783 eni_in(MID_RES_ID_MCON
) & 0x200 ? "ASIC" : "FPGA",
1784 media_name
[eni_in(MID_RES_ID_MCON
) & DAUGHTER_ID
]);
1786 error
= suni_init(dev
);
1796 static void eni_do_release(struct atm_dev
*dev
)
1798 struct eni_dev
*ed
= ENI_DEV(dev
);
1800 dev
->phy
->stop(dev
);
1802 iounmap(ed
->ioaddr
);
1805 static int eni_start(struct atm_dev
*dev
)
1807 struct eni_dev
*eni_dev
;
1810 unsigned long buffer_mem
;
1813 DPRINTK(">eni_start\n");
1814 eni_dev
= ENI_DEV(dev
);
1815 if (request_irq(eni_dev
->irq
,&eni_int
,IRQF_SHARED
,DEV_LABEL
,dev
)) {
1816 printk(KERN_ERR DEV_LABEL
"(itf %d): IRQ%d is already in use\n",
1817 dev
->number
,eni_dev
->irq
);
1821 pci_set_master(eni_dev
->pci_dev
);
1822 if ((error
= pci_write_config_word(eni_dev
->pci_dev
,PCI_COMMAND
,
1823 PCI_COMMAND_MEMORY
| PCI_COMMAND_MASTER
|
1824 (eni_dev
->asic
? PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
: 0)))) {
1825 printk(KERN_ERR DEV_LABEL
"(itf %d): can't enable memory+"
1826 "master (0x%02x)\n",dev
->number
,error
);
1829 if ((error
= pci_write_config_byte(eni_dev
->pci_dev
,PCI_TONGA_CTRL
,
1831 printk(KERN_ERR DEV_LABEL
"(itf %d): can't set endian swap "
1832 "(0x%02x)\n",dev
->number
,error
);
1835 /* determine addresses of internal tables */
1836 eni_dev
->vci
= eni_dev
->ram
;
1837 eni_dev
->rx_dma
= eni_dev
->ram
+NR_VCI
*16;
1838 eni_dev
->tx_dma
= eni_dev
->rx_dma
+NR_DMA_RX
*8;
1839 eni_dev
->service
= eni_dev
->tx_dma
+NR_DMA_TX
*8;
1840 buf
= eni_dev
->service
+NR_SERVICE
*4;
1841 DPRINTK("vci 0x%lx,rx 0x%lx, tx 0x%lx,srv 0x%lx,buf 0x%lx\n",
1842 eni_dev
->vci
,eni_dev
->rx_dma
,eni_dev
->tx_dma
,
1843 eni_dev
->service
,buf
);
1844 spin_lock_init(&eni_dev
->lock
);
1845 tasklet_init(&eni_dev
->task
,eni_tasklet
,(unsigned long) dev
);
1846 eni_dev
->events
= 0;
1847 /* initialize memory management */
1848 buffer_mem
= eni_dev
->mem
- (buf
- eni_dev
->ram
);
1849 eni_dev
->free_list_size
= buffer_mem
/MID_MIN_BUF_SIZE
/2;
1850 eni_dev
->free_list
= kmalloc_array(eni_dev
->free_list_size
+ 1,
1851 sizeof(*eni_dev
->free_list
),
1853 if (!eni_dev
->free_list
) {
1854 printk(KERN_ERR DEV_LABEL
"(itf %d): couldn't get free page\n",
1859 eni_dev
->free_len
= 0;
1860 eni_put_free(eni_dev
,buf
,buffer_mem
);
1861 memset_io(eni_dev
->vci
,0,16*NR_VCI
); /* clear VCI table */
1863 * byte_addr free (k)
1864 * 0x00000000 512 VCI table
1865 * 0x00004000 496 RX DMA
1866 * 0x00005000 492 TX DMA
1867 * 0x00006000 488 service list
1868 * 0x00007000 484 buffers
1869 * 0x00080000 0 end (512kB)
1871 eni_out(0xffffffff,MID_IE
);
1872 error
= start_tx(dev
);
1873 if (error
) goto free_list
;
1874 error
= start_rx(dev
);
1875 if (error
) goto free_list
;
1876 error
= dev
->phy
->start(dev
);
1877 if (error
) goto free_list
;
1878 eni_out(eni_in(MID_MC_S
) | (1 << MID_INT_SEL_SHIFT
) |
1879 MID_TX_LOCK_MODE
| MID_DMA_ENABLE
| MID_TX_ENABLE
| MID_RX_ENABLE
,
1881 /* Tonga uses SBus INTReq1 */
1882 (void) eni_in(MID_ISA
); /* clear Midway interrupts */
1886 kfree(eni_dev
->free_list
);
1889 free_irq(eni_dev
->irq
, dev
);
1896 static void eni_close(struct atm_vcc
*vcc
)
1898 DPRINTK(">eni_close\n");
1899 if (!ENI_VCC(vcc
)) return;
1900 clear_bit(ATM_VF_READY
,&vcc
->flags
);
1903 DPRINTK("eni_close: done waiting\n");
1904 /* deallocate memory */
1905 kfree(ENI_VCC(vcc
));
1906 vcc
->dev_data
= NULL
;
1907 clear_bit(ATM_VF_ADDR
,&vcc
->flags
);
1912 static int eni_open(struct atm_vcc
*vcc
)
1914 struct eni_vcc
*eni_vcc
;
1916 short vpi
= vcc
->vpi
;
1919 DPRINTK(">eni_open\n");
1920 EVENT("eni_open\n",0,0);
1921 if (!test_bit(ATM_VF_PARTIAL
,&vcc
->flags
))
1922 vcc
->dev_data
= NULL
;
1923 if (vci
!= ATM_VPI_UNSPEC
&& vpi
!= ATM_VCI_UNSPEC
)
1924 set_bit(ATM_VF_ADDR
,&vcc
->flags
);
1925 if (vcc
->qos
.aal
!= ATM_AAL0
&& vcc
->qos
.aal
!= ATM_AAL5
)
1927 DPRINTK(DEV_LABEL
"(itf %d): open %d.%d\n",vcc
->dev
->number
,vcc
->vpi
,
1929 if (!test_bit(ATM_VF_PARTIAL
,&vcc
->flags
)) {
1930 eni_vcc
= kmalloc(sizeof(struct eni_vcc
),GFP_KERNEL
);
1931 if (!eni_vcc
) return -ENOMEM
;
1932 vcc
->dev_data
= eni_vcc
;
1933 eni_vcc
->tx
= NULL
; /* for eni_close after open_rx */
1934 if ((error
= open_rx_first(vcc
))) {
1938 if ((error
= open_tx_first(vcc
))) {
1943 if (vci
== ATM_VPI_UNSPEC
|| vpi
== ATM_VCI_UNSPEC
) return 0;
1944 if ((error
= open_rx_second(vcc
))) {
1948 if ((error
= open_tx_second(vcc
))) {
1952 set_bit(ATM_VF_READY
,&vcc
->flags
);
1953 /* should power down SUNI while !ref_count @@@ */
1958 static int eni_change_qos(struct atm_vcc
*vcc
,struct atm_qos
*qos
,int flgs
)
1960 struct eni_dev
*eni_dev
= ENI_DEV(vcc
->dev
);
1961 struct eni_tx
*tx
= ENI_VCC(vcc
)->tx
;
1962 struct sk_buff
*skb
;
1963 int error
,rate
,rsv
,shp
;
1965 if (qos
->txtp
.traffic_class
== ATM_NONE
) return 0;
1966 if (tx
== eni_dev
->ubr
) return -EBADFD
;
1967 rate
= atm_pcr_goal(&qos
->txtp
);
1968 if (rate
< 0) rate
= -rate
;
1970 if ((flgs
& ATM_MF_DEC_RSV
) && rate
&& rate
< tx
->reserved
) rsv
= 1;
1971 if ((flgs
& ATM_MF_INC_RSV
) && (!rate
|| rate
> tx
->reserved
)) rsv
= 1;
1972 if ((flgs
& ATM_MF_DEC_SHP
) && rate
&& rate
< tx
->shaping
) shp
= 1;
1973 if ((flgs
& ATM_MF_INC_SHP
) && (!rate
|| rate
> tx
->shaping
)) shp
= 1;
1974 if (!rsv
&& !shp
) return 0;
1975 error
= reserve_or_set_tx(vcc
,&qos
->txtp
,rsv
,shp
);
1976 if (error
) return error
;
1977 if (shp
&& !(flgs
& ATM_MF_IMMED
)) return 0;
1979 * Walk through the send buffer and patch the rate information in all
1980 * segmentation buffer descriptors of this VCC.
1982 tasklet_disable(&eni_dev
->task
);
1983 skb_queue_walk(&eni_dev
->tx_queue
, skb
) {
1986 if (ATM_SKB(skb
)->vcc
!= vcc
) continue;
1987 dsc
= tx
->send
+ENI_PRV_POS(skb
)*4;
1988 writel((readl(dsc
) & ~(MID_SEG_RATE
| MID_SEG_PR
)) |
1989 (tx
->prescaler
<< MID_SEG_PR_SHIFT
) |
1990 (tx
->resolution
<< MID_SEG_RATE_SHIFT
), dsc
);
1992 tasklet_enable(&eni_dev
->task
);
1997 static int eni_ioctl(struct atm_dev
*dev
,unsigned int cmd
,void __user
*arg
)
1999 struct eni_dev
*eni_dev
= ENI_DEV(dev
);
2001 if (cmd
== ENI_MEMDUMP
) {
2002 if (!capable(CAP_NET_ADMIN
)) return -EPERM
;
2003 printk(KERN_WARNING
"Please use /proc/atm/" DEV_LABEL
":%d "
2004 "instead of obsolete ioctl ENI_MEMDUMP\n",dev
->number
);
2008 if (cmd
== ENI_SETMULT
) {
2009 struct eni_multipliers mult
;
2011 if (!capable(CAP_NET_ADMIN
)) return -EPERM
;
2012 if (copy_from_user(&mult
, arg
,
2013 sizeof(struct eni_multipliers
)))
2015 if ((mult
.tx
&& mult
.tx
<= 100) || (mult
.rx
&&mult
.rx
<= 100) ||
2016 mult
.tx
> 65536 || mult
.rx
> 65536)
2018 if (mult
.tx
) eni_dev
->tx_mult
= mult
.tx
;
2019 if (mult
.rx
) eni_dev
->rx_mult
= mult
.rx
;
2022 if (cmd
== ATM_SETCIRANGE
) {
2023 struct atm_cirange ci
;
2025 if (copy_from_user(&ci
, arg
,sizeof(struct atm_cirange
)))
2027 if ((ci
.vpi_bits
== 0 || ci
.vpi_bits
== ATM_CI_MAX
) &&
2028 (ci
.vci_bits
== NR_VCI_LD
|| ci
.vpi_bits
== ATM_CI_MAX
))
2032 if (!dev
->phy
->ioctl
) return -ENOIOCTLCMD
;
2033 return dev
->phy
->ioctl(dev
,cmd
,arg
);
2037 static int eni_getsockopt(struct atm_vcc
*vcc
,int level
,int optname
,
2038 void __user
*optval
,int optlen
)
2044 static int eni_setsockopt(struct atm_vcc
*vcc
,int level
,int optname
,
2045 void __user
*optval
,unsigned int optlen
)
2051 static int eni_send(struct atm_vcc
*vcc
,struct sk_buff
*skb
)
2055 DPRINTK(">eni_send\n");
2056 if (!ENI_VCC(vcc
)->tx
) {
2057 if (vcc
->pop
) vcc
->pop(vcc
,skb
);
2058 else dev_kfree_skb(skb
);
2062 printk(KERN_CRIT
"!skb in eni_send ?\n");
2063 if (vcc
->pop
) vcc
->pop(vcc
,skb
);
2066 if (vcc
->qos
.aal
== ATM_AAL0
) {
2067 if (skb
->len
!= ATM_CELL_SIZE
-1) {
2068 if (vcc
->pop
) vcc
->pop(vcc
,skb
);
2069 else dev_kfree_skb(skb
);
2072 *(u32
*) skb
->data
= htonl(*(u32
*) skb
->data
);
2075 ATM_SKB(skb
)->vcc
= vcc
;
2076 tasklet_disable(&ENI_DEV(vcc
->dev
)->task
);
2078 tasklet_enable(&ENI_DEV(vcc
->dev
)->task
);
2079 if (res
== enq_ok
) return 0;
2080 skb_queue_tail(&ENI_VCC(vcc
)->tx
->backlog
,skb
);
2082 tasklet_schedule(&ENI_DEV(vcc
->dev
)->task
);
2086 static void eni_phy_put(struct atm_dev
*dev
,unsigned char value
,
2089 writel(value
,ENI_DEV(dev
)->phy
+addr
*4);
2094 static unsigned char eni_phy_get(struct atm_dev
*dev
,unsigned long addr
)
2096 return readl(ENI_DEV(dev
)->phy
+addr
*4);
2100 static int eni_proc_read(struct atm_dev
*dev
,loff_t
*pos
,char *page
)
2103 static const char *signal
[] = { "LOST","unknown","okay" };
2104 struct eni_dev
*eni_dev
= ENI_DEV(dev
);
2105 struct atm_vcc
*vcc
;
2110 return sprintf(page
,DEV_LABEL
"(itf %d) signal %s, %dkB, "
2111 "%d cps remaining\n",dev
->number
,signal
[(int) dev
->signal
],
2112 eni_dev
->mem
>> 10,eni_dev
->tx_bw
);
2114 return sprintf(page
,"%4sBursts: TX"
2115 #if !defined(CONFIG_ATM_ENI_BURST_TX_16W) && \
2116 !defined(CONFIG_ATM_ENI_BURST_TX_8W) && \
2117 !defined(CONFIG_ATM_ENI_BURST_TX_4W) && \
2118 !defined(CONFIG_ATM_ENI_BURST_TX_2W)
2121 #ifdef CONFIG_ATM_ENI_BURST_TX_16W
2124 #ifdef CONFIG_ATM_ENI_BURST_TX_8W
2127 #ifdef CONFIG_ATM_ENI_BURST_TX_4W
2130 #ifdef CONFIG_ATM_ENI_BURST_TX_2W
2134 #if !defined(CONFIG_ATM_ENI_BURST_RX_16W) && \
2135 !defined(CONFIG_ATM_ENI_BURST_RX_8W) && \
2136 !defined(CONFIG_ATM_ENI_BURST_RX_4W) && \
2137 !defined(CONFIG_ATM_ENI_BURST_RX_2W)
2140 #ifdef CONFIG_ATM_ENI_BURST_RX_16W
2143 #ifdef CONFIG_ATM_ENI_BURST_RX_8W
2146 #ifdef CONFIG_ATM_ENI_BURST_RX_4W
2149 #ifdef CONFIG_ATM_ENI_BURST_RX_2W
2152 #ifndef CONFIG_ATM_ENI_TUNE_BURST
2157 return sprintf(page
,"%4sBuffer multipliers: tx %d%%, rx %d%%\n",
2158 "",eni_dev
->tx_mult
,eni_dev
->rx_mult
);
2159 for (i
= 0; i
< NR_CHAN
; i
++) {
2160 struct eni_tx
*tx
= eni_dev
->tx
+i
;
2162 if (!tx
->send
) continue;
2164 return sprintf(page
, "tx[%d]: 0x%lx-0x%lx "
2165 "(%6ld bytes), rsv %d cps, shp %d cps%s\n",i
,
2166 (unsigned long) (tx
->send
- eni_dev
->ram
),
2167 tx
->send
-eni_dev
->ram
+tx
->words
*4-1,tx
->words
*4,
2168 tx
->reserved
,tx
->shaping
,
2169 tx
== eni_dev
->ubr
? " (UBR)" : "");
2171 if (--left
) continue;
2172 return sprintf(page
,"%10sbacklog %u packets\n","",
2173 skb_queue_len(&tx
->backlog
));
2175 read_lock(&vcc_sklist_lock
);
2176 for(i
= 0; i
< VCC_HTABLE_SIZE
; ++i
) {
2177 struct hlist_head
*head
= &vcc_hash
[i
];
2179 sk_for_each(s
, head
) {
2180 struct eni_vcc
*eni_vcc
;
2184 if (vcc
->dev
!= dev
)
2186 eni_vcc
= ENI_VCC(vcc
);
2187 if (--left
) continue;
2188 length
= sprintf(page
,"vcc %4d: ",vcc
->vci
);
2190 length
+= sprintf(page
+length
, "0x%lx-0x%lx "
2192 (unsigned long) (eni_vcc
->recv
- eni_dev
->ram
),
2193 eni_vcc
->recv
-eni_dev
->ram
+eni_vcc
->words
*4-1,
2195 if (eni_vcc
->tx
) length
+= sprintf(page
+length
,", ");
2198 length
+= sprintf(page
+length
,"tx[%d], txing %d bytes",
2199 eni_vcc
->tx
->index
,eni_vcc
->txing
);
2200 page
[length
] = '\n';
2201 read_unlock(&vcc_sklist_lock
);
2205 read_unlock(&vcc_sklist_lock
);
2206 for (i
= 0; i
< eni_dev
->free_len
; i
++) {
2207 struct eni_free
*fe
= eni_dev
->free_list
+i
;
2208 unsigned long offset
;
2210 if (--left
) continue;
2211 offset
= (unsigned long) eni_dev
->ram
+eni_dev
->base_diff
;
2212 return sprintf(page
,"free %p-%p (%6d bytes)\n",
2213 fe
->start
-offset
,fe
->start
-offset
+(1 << fe
->order
)-1,
2220 static const struct atmdev_ops ops
= {
2224 .getsockopt
= eni_getsockopt
,
2225 .setsockopt
= eni_setsockopt
,
2227 .phy_put
= eni_phy_put
,
2228 .phy_get
= eni_phy_get
,
2229 .change_qos
= eni_change_qos
,
2230 .proc_read
= eni_proc_read
2234 static int eni_init_one(struct pci_dev
*pci_dev
,
2235 const struct pci_device_id
*ent
)
2237 struct atm_dev
*dev
;
2238 struct eni_dev
*eni_dev
;
2239 struct eni_zero
*zero
;
2242 rc
= pci_enable_device(pci_dev
);
2246 rc
= dma_set_mask_and_coherent(&pci_dev
->dev
, DMA_BIT_MASK(32));
2251 eni_dev
= kmalloc(sizeof(struct eni_dev
), GFP_KERNEL
);
2255 zero
= &eni_dev
->zero
;
2256 zero
->addr
= dma_alloc_coherent(&pci_dev
->dev
,
2257 ENI_ZEROES_SIZE
, &zero
->dma
, GFP_KERNEL
);
2261 dev
= atm_dev_register(DEV_LABEL
, &pci_dev
->dev
, &ops
, -1, NULL
);
2263 goto err_free_consistent
;
2265 dev
->dev_data
= eni_dev
;
2266 pci_set_drvdata(pci_dev
, dev
);
2267 eni_dev
->pci_dev
= pci_dev
;
2268 eni_dev
->asic
= ent
->driver_data
;
2270 rc
= eni_do_init(dev
);
2272 goto err_unregister
;
2274 rc
= eni_start(dev
);
2276 goto err_eni_release
;
2278 eni_dev
->more
= eni_boards
;
2284 eni_do_release(dev
);
2286 atm_dev_deregister(dev
);
2287 err_free_consistent
:
2288 dma_free_coherent(&pci_dev
->dev
, ENI_ZEROES_SIZE
, zero
->addr
, zero
->dma
);
2292 pci_disable_device(pci_dev
);
2297 static const struct pci_device_id eni_pci_tbl
[] = {
2298 { PCI_VDEVICE(EF
, PCI_DEVICE_ID_EF_ATM_FPGA
), 0 /* FPGA */ },
2299 { PCI_VDEVICE(EF
, PCI_DEVICE_ID_EF_ATM_ASIC
), 1 /* ASIC */ },
2302 MODULE_DEVICE_TABLE(pci
,eni_pci_tbl
);
2305 static void eni_remove_one(struct pci_dev
*pdev
)
2307 struct atm_dev
*dev
= pci_get_drvdata(pdev
);
2308 struct eni_dev
*ed
= ENI_DEV(dev
);
2309 struct eni_zero
*zero
= &ed
->zero
;
2311 eni_do_release(dev
);
2312 atm_dev_deregister(dev
);
2313 dma_free_coherent(&pdev
->dev
, ENI_ZEROES_SIZE
, zero
->addr
, zero
->dma
);
2315 pci_disable_device(pdev
);
2319 static struct pci_driver eni_driver
= {
2321 .id_table
= eni_pci_tbl
,
2322 .probe
= eni_init_one
,
2323 .remove
= eni_remove_one
,
2327 static int __init
eni_init(void)
2329 struct sk_buff
*skb
; /* dummy for sizeof */
2331 BUILD_BUG_ON(sizeof(skb
->cb
) < sizeof(struct eni_skb_prv
));
2332 return pci_register_driver(&eni_driver
);
2336 module_init(eni_init
);
2337 /* @@@ since exit routine not defined, this module can not be unloaded */
2339 MODULE_LICENSE("GPL");