1 /* drivers/atm/eni.c - Efficient Networks ENI155P device driver */
3 /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
6 #include <linux/module.h>
7 #include <linux/kernel.h>
10 #include <linux/errno.h>
11 #include <linux/atm.h>
12 #include <linux/atmdev.h>
13 #include <linux/sonet.h>
14 #include <linux/skbuff.h>
15 #include <linux/time.h>
16 #include <linux/delay.h>
17 #include <linux/uio.h>
18 #include <linux/init.h>
19 #include <linux/atm_eni.h>
20 #include <linux/bitops.h>
21 #include <asm/system.h>
23 #include <asm/atomic.h>
24 #include <asm/uaccess.h>
25 #include <asm/string.h>
26 #include <asm/byteorder.h>
33 #if !defined(__i386__) && !defined(__x86_64__)
34 #ifndef ioremap_nocache
35 #define ioremap_nocache(X,Y) ioremap(X,Y)
47 * - fix bugs listed below
53 * - may run into JK-JK bug and deadlock
54 * - should allocate UBR channel first
55 * - buffer space allocation algorithm is stupid
56 * (RX: should be maxSDU+maxdelay*rate
57 * TX: should be maxSDU+min(maxSDU,maxdelay*rate) )
58 * - doesn't support OAM cells
59 * - eni_put_free may hang if not putting memory fragments that _complete_
60 * 2^n block (never happens in real life, though)
65 #define DPRINTK(format,args...) printk(KERN_DEBUG format,##args)
67 #define DPRINTK(format,args...)
71 #ifndef CONFIG_ATM_ENI_TUNE_BURST
72 #define CONFIG_ATM_ENI_BURST_TX_8W
73 #define CONFIG_ATM_ENI_BURST_RX_4W
77 #ifndef CONFIG_ATM_ENI_DEBUG
85 static void event_dump(void)
94 * NULL pointer checking
97 #define NULLCHECK(x) \
98 if ((unsigned long) (x) < 0x30) \
99 printk(KERN_CRIT #x "==0x%lx\n",(unsigned long) (x))
102 * Very extensive activity logging. Greatly improves bug detection speed but
103 * costs a few Mbps if enabled.
108 static const char *ev
[EV
];
109 static unsigned long ev_a
[EV
],ev_b
[EV
];
113 static void EVENT(const char *s
,unsigned long a
,unsigned long b
)
122 static void event_dump(void)
126 for (n
= 0; n
< EV
; n
++) {
129 printk(ev
[i
] ? ev
[i
] : "(null)",ev_a
[i
],ev_b
[i
]);
134 #endif /* CONFIG_ATM_ENI_DEBUG */
138 * NExx must not be equal at end
139 * EExx may be equal at end
140 * xxPJOK verify validity of pointer jumps
141 * xxPMOK operating on a circular buffer of "c" words
144 #define NEPJOK(a0,a1,b) \
145 ((a0) < (a1) ? (b) <= (a0) || (b) > (a1) : (b) <= (a0) && (b) > (a1))
146 #define EEPJOK(a0,a1,b) \
147 ((a0) < (a1) ? (b) < (a0) || (b) >= (a1) : (b) < (a0) && (b) >= (a1))
148 #define NEPMOK(a0,d,b,c) NEPJOK(a0,(a0+d) & (c-1),b)
149 #define EEPMOK(a0,d,b,c) EEPJOK(a0,(a0+d) & (c-1),b)
152 static int tx_complete
= 0,dma_complete
= 0,queued
= 0,requeued
= 0,
153 backlogged
= 0,rx_enqueued
= 0,rx_dequeued
= 0,pushed
= 0,submitted
= 0,
156 static struct atm_dev
*eni_boards
= NULL
;
158 static u32
*cpu_zeroes
= NULL
; /* aligned "magic" zeroes */
159 static dma_addr_t zeroes
;
161 /* Read/write registers on card */
162 #define eni_in(r) readl(eni_dev->reg+(r)*4)
163 #define eni_out(v,r) writel((v),eni_dev->reg+(r)*4)
166 /*-------------------------------- utilities --------------------------------*/
169 static void dump_mem(struct eni_dev
*eni_dev
)
173 for (i
= 0; i
< eni_dev
->free_len
; i
++)
174 printk(KERN_DEBUG
" %d: %p %d\n",i
,
175 eni_dev
->free_list
[i
].start
,
176 1 << eni_dev
->free_list
[i
].order
);
180 static void dump(struct atm_dev
*dev
)
182 struct eni_dev
*eni_dev
;
186 eni_dev
= ENI_DEV(dev
);
187 printk(KERN_NOTICE
"Free memory\n");
189 printk(KERN_NOTICE
"TX buffers\n");
190 for (i
= 0; i
< NR_CHAN
; i
++)
191 if (eni_dev
->tx
[i
].send
)
192 printk(KERN_NOTICE
" TX %d @ %p: %ld\n",i
,
193 eni_dev
->tx
[i
].send
,eni_dev
->tx
[i
].words
*4);
194 printk(KERN_NOTICE
"RX buffers\n");
195 for (i
= 0; i
< 1024; i
++)
196 if (eni_dev
->rx_map
[i
] && ENI_VCC(eni_dev
->rx_map
[i
])->rx
)
197 printk(KERN_NOTICE
" RX %d @ %p: %ld\n",i
,
198 ENI_VCC(eni_dev
->rx_map
[i
])->recv
,
199 ENI_VCC(eni_dev
->rx_map
[i
])->words
*4);
200 printk(KERN_NOTICE
"----\n");
204 static void eni_put_free(struct eni_dev
*eni_dev
, void __iomem
*start
,
207 struct eni_free
*list
;
210 DPRINTK("init 0x%lx+%ld(0x%lx)\n",start
,size
,size
);
211 start
+= eni_dev
->base_diff
;
212 list
= eni_dev
->free_list
;
213 len
= eni_dev
->free_len
;
215 if (len
>= eni_dev
->free_list_size
) {
216 printk(KERN_CRIT
"eni_put_free overflow (%p,%ld)\n",
220 for (order
= 0; !(((unsigned long)start
| size
) & (1 << order
)); order
++);
221 if (MID_MIN_BUF_SIZE
> (1 << order
)) {
222 printk(KERN_CRIT
"eni_put_free: order %d too small\n",
226 list
[len
].start
= (void __iomem
*) start
;
227 list
[len
].order
= order
;
232 eni_dev
->free_len
= len
;
233 /*dump_mem(eni_dev);*/
237 static void __iomem
*eni_alloc_mem(struct eni_dev
*eni_dev
, unsigned long *size
)
239 struct eni_free
*list
;
241 int len
,i
,order
,best_order
,index
;
243 list
= eni_dev
->free_list
;
244 len
= eni_dev
->free_len
;
245 if (*size
< MID_MIN_BUF_SIZE
) *size
= MID_MIN_BUF_SIZE
;
246 if (*size
> MID_MAX_BUF_SIZE
) return NULL
;
247 for (order
= 0; (1 << order
) < *size
; order
++);
248 DPRINTK("trying: %ld->%d\n",*size
,order
);
249 best_order
= 65; /* we don't have more than 2^64 of anything ... */
250 index
= 0; /* silence GCC */
251 for (i
= 0; i
< len
; i
++)
252 if (list
[i
].order
== order
) {
257 else if (best_order
> list
[i
].order
&& list
[i
].order
> order
) {
258 best_order
= list
[i
].order
;
261 if (best_order
== 65) return NULL
;
262 start
= list
[index
].start
-eni_dev
->base_diff
;
263 list
[index
] = list
[--len
];
264 eni_dev
->free_len
= len
;
266 eni_put_free(eni_dev
,start
+*size
,(1 << best_order
)-*size
);
267 DPRINTK("%ld bytes (order %d) at 0x%lx\n",*size
,order
,start
);
268 memset_io(start
,0,*size
); /* never leak data */
269 /*dump_mem(eni_dev);*/
274 static void eni_free_mem(struct eni_dev
*eni_dev
, void __iomem
*start
,
277 struct eni_free
*list
;
280 start
+= eni_dev
->base_diff
;
281 list
= eni_dev
->free_list
;
282 len
= eni_dev
->free_len
;
283 for (order
= -1; size
; order
++) size
>>= 1;
284 DPRINTK("eni_free_mem: %p+0x%lx (order %d)\n",start
,size
,order
);
285 for (i
= 0; i
< len
; i
++)
286 if (((unsigned long) list
[i
].start
) == ((unsigned long)start
^(1 << order
)) &&
287 list
[i
].order
== order
) {
288 DPRINTK("match[%d]: 0x%lx/0x%lx(0x%x), %d/%d\n",i
,
289 list
[i
].start
,start
,1 << order
,list
[i
].order
,order
);
290 list
[i
] = list
[--len
];
291 start
= (void __iomem
*) ((unsigned long) start
& ~(unsigned long) (1 << order
));
296 if (len
>= eni_dev
->free_list_size
) {
297 printk(KERN_ALERT
"eni_free_mem overflow (%p,%d)\n",start
,
301 list
[len
].start
= start
;
302 list
[len
].order
= order
;
303 eni_dev
->free_len
= len
+1;
304 /*dump_mem(eni_dev);*/
308 /*----------------------------------- RX ------------------------------------*/
311 #define ENI_VCC_NOS ((struct atm_vcc *) 1)
314 static void rx_ident_err(struct atm_vcc
*vcc
)
317 struct eni_dev
*eni_dev
;
318 struct eni_vcc
*eni_vcc
;
321 eni_dev
= ENI_DEV(dev
);
322 /* immediately halt adapter */
323 eni_out(eni_in(MID_MC_S
) &
324 ~(MID_DMA_ENABLE
| MID_TX_ENABLE
| MID_RX_ENABLE
),MID_MC_S
);
325 /* dump useful information */
326 eni_vcc
= ENI_VCC(vcc
);
327 printk(KERN_ALERT DEV_LABEL
"(itf %d): driver error - RX ident "
328 "mismatch\n",dev
->number
);
329 printk(KERN_ALERT
" VCI %d, rxing %d, words %ld\n",vcc
->vci
,
330 eni_vcc
->rxing
,eni_vcc
->words
);
331 printk(KERN_ALERT
" host descr 0x%lx, rx pos 0x%lx, descr value "
332 "0x%x\n",eni_vcc
->descr
,eni_vcc
->rx_pos
,
333 (unsigned) readl(eni_vcc
->recv
+eni_vcc
->descr
*4));
334 printk(KERN_ALERT
" last %p, servicing %d\n",eni_vcc
->last
,
336 EVENT("---dump ends here---\n",0,0);
337 printk(KERN_NOTICE
"---recent events---\n");
339 ENI_DEV(dev
)->fast
= NULL
; /* really stop it */
340 ENI_DEV(dev
)->slow
= NULL
;
341 skb_queue_head_init(&ENI_DEV(dev
)->rx_queue
);
345 static int do_rx_dma(struct atm_vcc
*vcc
,struct sk_buff
*skb
,
346 unsigned long skip
,unsigned long size
,unsigned long eff
)
348 struct eni_dev
*eni_dev
;
349 struct eni_vcc
*eni_vcc
;
351 u32 dma
[RX_DMA_BUF
*2];
356 eni_dev
= ENI_DEV(vcc
->dev
);
357 eni_vcc
= ENI_VCC(vcc
);
358 paddr
= 0; /* GCC, shut up */
360 paddr
= pci_map_single(eni_dev
->pci_dev
,skb
->data
,skb
->len
,
362 ENI_PRV_PADDR(skb
) = paddr
;
364 printk(KERN_CRIT DEV_LABEL
"(itf %d): VCI %d has "
365 "mis-aligned RX data (0x%lx)\n",vcc
->dev
->number
,
366 vcc
->vci
,(unsigned long) paddr
);
367 ENI_PRV_SIZE(skb
) = size
+skip
;
368 /* PDU plus descriptor */
369 ATM_SKB(skb
)->vcc
= vcc
;
372 if ((eff
&& skip
) || 1) { /* @@@ actually, skip is always == 1 ... */
373 here
= (eni_vcc
->descr
+skip
) & (eni_vcc
->words
-1);
374 dma
[j
++] = (here
<< MID_DMA_COUNT_SHIFT
) | (vcc
->vci
375 << MID_DMA_VCI_SHIFT
) | MID_DT_JK
;
378 here
= (eni_vcc
->descr
+size
+skip
) & (eni_vcc
->words
-1);
379 if (!eff
) size
+= skip
;
384 DPRINTK("strange things happen ...\n");
385 EVENT("strange things happen ... (skip=%ld,eff=%ld)\n",
392 init
= 4-((paddr
& 15) >> 2);
393 if (init
> words
) init
= words
;
394 dma
[j
++] = MID_DT_WORD
| (init
<< MID_DMA_COUNT_SHIFT
) |
395 (vcc
->vci
<< MID_DMA_VCI_SHIFT
);
400 #ifdef CONFIG_ATM_ENI_BURST_RX_16W /* may work with some PCI chipsets ... */
402 dma
[j
++] = MID_DT_16W
| ((words
>> 4) <<
403 MID_DMA_COUNT_SHIFT
) | (vcc
->vci
<<
406 paddr
+= (words
& ~15) << 2;
410 #ifdef CONFIG_ATM_ENI_BURST_RX_8W /* works only with *some* PCI chipsets ... */
412 dma
[j
++] = MID_DT_8W
| ((words
>> 3) <<
413 MID_DMA_COUNT_SHIFT
) | (vcc
->vci
<<
416 paddr
+= (words
& ~7) << 2;
420 #ifdef CONFIG_ATM_ENI_BURST_RX_4W /* recommended */
422 dma
[j
++] = MID_DT_4W
| ((words
>> 2) <<
423 MID_DMA_COUNT_SHIFT
) | (vcc
->vci
<<
426 paddr
+= (words
& ~3) << 2;
430 #ifdef CONFIG_ATM_ENI_BURST_RX_2W /* probably useless if RX_4W, RX_8W, ... */
432 dma
[j
++] = MID_DT_2W
| ((words
>> 1) <<
433 MID_DMA_COUNT_SHIFT
) | (vcc
->vci
<<
436 paddr
+= (words
& ~1) << 2;
441 dma
[j
++] = MID_DT_WORD
| (words
<< MID_DMA_COUNT_SHIFT
)
442 | (vcc
->vci
<< MID_DMA_VCI_SHIFT
);
447 dma
[j
++] = (here
<< MID_DMA_COUNT_SHIFT
) |
448 (vcc
->vci
<< MID_DMA_VCI_SHIFT
) | MID_DT_JK
;
451 if (!j
|| j
> 2*RX_DMA_BUF
) {
452 printk(KERN_CRIT DEV_LABEL
"!j or j too big!!!\n");
455 dma
[j
-2] |= MID_DMA_END
;
457 dma_wr
= eni_in(MID_DMA_WR_RX
);
458 dma_rd
= eni_in(MID_DMA_RD_RX
);
460 * Can I move the dma_wr pointer by 2j+1 positions without overwriting
461 * data that hasn't been read (position of dma_rd) yet ?
463 if (!NEPMOK(dma_wr
,j
+j
+1,dma_rd
,NR_DMA_RX
)) { /* @@@ +1 is ugly */
464 printk(KERN_WARNING DEV_LABEL
"(itf %d): RX DMA full\n",
468 for (i
= 0; i
< j
; i
++) {
469 writel(dma
[i
*2],eni_dev
->rx_dma
+dma_wr
*8);
470 writel(dma
[i
*2+1],eni_dev
->rx_dma
+dma_wr
*8+4);
471 dma_wr
= (dma_wr
+1) & (NR_DMA_RX
-1);
474 ENI_PRV_POS(skb
) = eni_vcc
->descr
+size
+1;
475 skb_queue_tail(&eni_dev
->rx_queue
,skb
);
479 eni_vcc
->descr
= here
;
480 eni_out(dma_wr
,MID_DMA_WR_RX
);
485 pci_unmap_single(eni_dev
->pci_dev
,paddr
,skb
->len
,
487 if (skb
) dev_kfree_skb_irq(skb
);
492 static void discard(struct atm_vcc
*vcc
,unsigned long size
)
494 struct eni_vcc
*eni_vcc
;
496 eni_vcc
= ENI_VCC(vcc
);
497 EVENT("discard (size=%ld)\n",size
,0);
498 while (do_rx_dma(vcc
,NULL
,1,size
,0)) EVENT("BUSY LOOP",0,0);
499 /* could do a full fallback, but that might be more expensive */
500 if (eni_vcc
->rxing
) ENI_PRV_POS(eni_vcc
->last
) += size
+1;
501 else eni_vcc
->rx_pos
= (eni_vcc
->rx_pos
+size
+1) & (eni_vcc
->words
-1);
506 * TODO: should check whether direct copies (without DMA setup, dequeuing on
507 * interrupt, etc.) aren't much faster for AAL0
510 static int rx_aal0(struct atm_vcc
*vcc
)
512 struct eni_vcc
*eni_vcc
;
514 unsigned long length
;
517 DPRINTK(">rx_aal0\n");
518 eni_vcc
= ENI_VCC(vcc
);
519 descr
= readl(eni_vcc
->recv
+eni_vcc
->descr
*4);
520 if ((descr
& MID_RED_IDEN
) != (MID_RED_RX_ID
<< MID_RED_SHIFT
)) {
524 if (descr
& MID_RED_T
) {
525 DPRINTK(DEV_LABEL
"(itf %d): trashing empty cell\n",
528 atomic_inc(&vcc
->stats
->rx_err
);
531 length
= ATM_CELL_SIZE
-1; /* no HEC */
533 skb
= length
? atm_alloc_charge(vcc
,length
,GFP_ATOMIC
) : NULL
;
535 discard(vcc
,length
>> 2);
539 skb
->tstamp
= eni_vcc
->timestamp
;
540 DPRINTK("got len %ld\n",length
);
541 if (do_rx_dma(vcc
,skb
,1,length
>> 2,length
>> 2)) return 1;
547 static int rx_aal5(struct atm_vcc
*vcc
)
549 struct eni_vcc
*eni_vcc
;
551 unsigned long size
,eff
,length
;
554 EVENT("rx_aal5\n",0,0);
555 DPRINTK(">rx_aal5\n");
556 eni_vcc
= ENI_VCC(vcc
);
557 descr
= readl(eni_vcc
->recv
+eni_vcc
->descr
*4);
558 if ((descr
& MID_RED_IDEN
) != (MID_RED_RX_ID
<< MID_RED_SHIFT
)) {
562 if (descr
& (MID_RED_T
| MID_RED_CRC_ERR
)) {
563 if (descr
& MID_RED_T
) {
564 EVENT("empty cell (descr=0x%lx)\n",descr
,0);
565 DPRINTK(DEV_LABEL
"(itf %d): trashing empty cell\n",
570 static unsigned long silence
= 0;
572 if (time_after(jiffies
, silence
) || silence
== 0) {
573 printk(KERN_WARNING DEV_LABEL
"(itf %d): "
574 "discarding PDU(s) with CRC error\n",
576 silence
= (jiffies
+2*HZ
)|1;
578 size
= (descr
& MID_RED_COUNT
)*(ATM_CELL_PAYLOAD
>> 2);
579 EVENT("CRC error (descr=0x%lx,size=%ld)\n",descr
,
583 atomic_inc(&vcc
->stats
->rx_err
);
586 size
= (descr
& MID_RED_COUNT
)*(ATM_CELL_PAYLOAD
>> 2);
587 DPRINTK("size=%ld\n",size
);
588 length
= readl(eni_vcc
->recv
+(((eni_vcc
->descr
+size
-1) &
589 (eni_vcc
->words
-1)))*4) & 0xffff;
590 /* -trailer(2)+header(1) */
591 if (length
&& length
<= (size
<< 2)-8 && length
<=
592 ATM_MAX_AAL5_PDU
) eff
= (length
+3) >> 2;
593 else { /* ^ trailer length (8) */
594 EVENT("bad PDU (descr=0x08%lx,length=%ld)\n",descr
,
596 printk(KERN_ERR DEV_LABEL
"(itf %d): bad AAL5 PDU "
597 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
598 vcc
->dev
->number
,vcc
->vci
,length
,size
<< 2,descr
);
600 atomic_inc(&vcc
->stats
->rx_err
);
603 skb
= eff
? atm_alloc_charge(vcc
,eff
<< 2,GFP_ATOMIC
) : NULL
;
609 DPRINTK("got len %ld\n",length
);
610 if (do_rx_dma(vcc
,skb
,1,size
,eff
)) return 1;
616 static inline int rx_vcc(struct atm_vcc
*vcc
)
618 void __iomem
*vci_dsc
;
620 struct eni_vcc
*eni_vcc
;
622 eni_vcc
= ENI_VCC(vcc
);
623 vci_dsc
= ENI_DEV(vcc
->dev
)->vci
+vcc
->vci
*16;
624 EVENT("rx_vcc(1)\n",0,0);
625 while (eni_vcc
->descr
!= (tmp
= (readl(vci_dsc
+4) & MID_VCI_DESCR
) >>
626 MID_VCI_DESCR_SHIFT
)) {
627 EVENT("rx_vcc(2: host dsc=0x%lx, nic dsc=0x%lx)\n",
629 DPRINTK("CB_DESCR %ld REG_DESCR %d\n",ENI_VCC(vcc
)->descr
,
630 (((unsigned) readl(vci_dsc
+4) & MID_VCI_DESCR
) >>
631 MID_VCI_DESCR_SHIFT
));
632 if (ENI_VCC(vcc
)->rx(vcc
)) return 1;
634 /* clear IN_SERVICE flag */
635 writel(readl(vci_dsc
) & ~MID_VCI_IN_SERVICE
,vci_dsc
);
637 * If new data has arrived between evaluating the while condition and
638 * clearing IN_SERVICE, we wouldn't be notified until additional data
639 * follows. So we have to loop again to be sure.
641 EVENT("rx_vcc(3)\n",0,0);
642 while (ENI_VCC(vcc
)->descr
!= (tmp
= (readl(vci_dsc
+4) & MID_VCI_DESCR
)
643 >> MID_VCI_DESCR_SHIFT
)) {
644 EVENT("rx_vcc(4: host dsc=0x%lx, nic dsc=0x%lx)\n",
646 DPRINTK("CB_DESCR %ld REG_DESCR %d\n",ENI_VCC(vcc
)->descr
,
647 (((unsigned) readl(vci_dsc
+4) & MID_VCI_DESCR
) >>
648 MID_VCI_DESCR_SHIFT
));
649 if (ENI_VCC(vcc
)->rx(vcc
)) return 1;
655 static void poll_rx(struct atm_dev
*dev
)
657 struct eni_dev
*eni_dev
;
658 struct atm_vcc
*curr
;
660 eni_dev
= ENI_DEV(dev
);
661 while ((curr
= eni_dev
->fast
)) {
662 EVENT("poll_rx.fast\n",0,0);
663 if (rx_vcc(curr
)) return;
664 eni_dev
->fast
= ENI_VCC(curr
)->next
;
665 ENI_VCC(curr
)->next
= ENI_VCC_NOS
;
667 ENI_VCC(curr
)->servicing
--;
669 while ((curr
= eni_dev
->slow
)) {
670 EVENT("poll_rx.slow\n",0,0);
671 if (rx_vcc(curr
)) return;
672 eni_dev
->slow
= ENI_VCC(curr
)->next
;
673 ENI_VCC(curr
)->next
= ENI_VCC_NOS
;
675 ENI_VCC(curr
)->servicing
--;
680 static void get_service(struct atm_dev
*dev
)
682 struct eni_dev
*eni_dev
;
686 DPRINTK(">get_service\n");
687 eni_dev
= ENI_DEV(dev
);
688 while (eni_in(MID_SERV_WRITE
) != eni_dev
->serv_read
) {
689 vci
= readl(eni_dev
->service
+eni_dev
->serv_read
*4);
690 eni_dev
->serv_read
= (eni_dev
->serv_read
+1) & (NR_SERVICE
-1);
691 vcc
= eni_dev
->rx_map
[vci
& 1023];
693 printk(KERN_CRIT DEV_LABEL
"(itf %d): VCI %ld not "
694 "found\n",dev
->number
,vci
);
695 continue; /* nasty but we try to go on anyway */
696 /* @@@ nope, doesn't work */
698 EVENT("getting from service\n",0,0);
699 if (ENI_VCC(vcc
)->next
!= ENI_VCC_NOS
) {
700 EVENT("double service\n",0,0);
701 DPRINTK("Grr, servicing VCC %ld twice\n",vci
);
704 ENI_VCC(vcc
)->timestamp
= ktime_get_real();
705 ENI_VCC(vcc
)->next
= NULL
;
706 if (vcc
->qos
.rxtp
.traffic_class
== ATM_CBR
) {
708 ENI_VCC(eni_dev
->last_fast
)->next
= vcc
;
709 else eni_dev
->fast
= vcc
;
710 eni_dev
->last_fast
= vcc
;
714 ENI_VCC(eni_dev
->last_slow
)->next
= vcc
;
715 else eni_dev
->slow
= vcc
;
716 eni_dev
->last_slow
= vcc
;
719 ENI_VCC(vcc
)->servicing
++;
724 static void dequeue_rx(struct atm_dev
*dev
)
726 struct eni_dev
*eni_dev
;
727 struct eni_vcc
*eni_vcc
;
730 void __iomem
*vci_dsc
;
733 eni_dev
= ENI_DEV(dev
);
736 skb
= skb_dequeue(&eni_dev
->rx_queue
);
739 DPRINTK(DEV_LABEL
"(itf %d): RX but not "
740 "rxing\n",dev
->number
);
741 EVENT("nothing to dequeue\n",0,0);
745 EVENT("dequeued (size=%ld,pos=0x%lx)\n",ENI_PRV_SIZE(skb
),
748 vcc
= ATM_SKB(skb
)->vcc
;
749 eni_vcc
= ENI_VCC(vcc
);
751 vci_dsc
= eni_dev
->vci
+vcc
->vci
*16;
752 if (!EEPMOK(eni_vcc
->rx_pos
,ENI_PRV_SIZE(skb
),
753 (readl(vci_dsc
+4) & MID_VCI_READ
) >> MID_VCI_READ_SHIFT
,
755 EVENT("requeuing\n",0,0);
756 skb_queue_head(&eni_dev
->rx_queue
,skb
);
760 eni_vcc
->rx_pos
= ENI_PRV_POS(skb
) & (eni_vcc
->words
-1);
761 pci_unmap_single(eni_dev
->pci_dev
,ENI_PRV_PADDR(skb
),skb
->len
,
763 if (!skb
->len
) dev_kfree_skb_irq(skb
);
765 EVENT("pushing (len=%ld)\n",skb
->len
,0);
766 if (vcc
->qos
.aal
== ATM_AAL0
)
767 *(unsigned long *) skb
->data
=
768 ntohl(*(unsigned long *) skb
->data
);
769 memset(skb
->cb
,0,sizeof(struct eni_skb_prv
));
773 atomic_inc(&vcc
->stats
->rx
);
775 wake_up(&eni_dev
->rx_wait
);
779 static int open_rx_first(struct atm_vcc
*vcc
)
781 struct eni_dev
*eni_dev
;
782 struct eni_vcc
*eni_vcc
;
785 DPRINTK("open_rx_first\n");
786 eni_dev
= ENI_DEV(vcc
->dev
);
787 eni_vcc
= ENI_VCC(vcc
);
789 if (vcc
->qos
.rxtp
.traffic_class
== ATM_NONE
) return 0;
790 size
= vcc
->qos
.rxtp
.max_sdu
*eni_dev
->rx_mult
/100;
791 if (size
> MID_MAX_BUF_SIZE
&& vcc
->qos
.rxtp
.max_sdu
<=
793 size
= MID_MAX_BUF_SIZE
;
794 eni_vcc
->recv
= eni_alloc_mem(eni_dev
,&size
);
795 DPRINTK("rx at 0x%lx\n",eni_vcc
->recv
);
796 eni_vcc
->words
= size
>> 2;
797 if (!eni_vcc
->recv
) return -ENOBUFS
;
798 eni_vcc
->rx
= vcc
->qos
.aal
== ATM_AAL5
? rx_aal5
: rx_aal0
;
802 eni_vcc
->servicing
= 0;
803 eni_vcc
->next
= ENI_VCC_NOS
;
808 static int open_rx_second(struct atm_vcc
*vcc
)
811 struct eni_dev
*eni_dev
;
812 struct eni_vcc
*eni_vcc
;
816 DPRINTK("open_rx_second\n");
817 eni_dev
= ENI_DEV(vcc
->dev
);
818 eni_vcc
= ENI_VCC(vcc
);
819 if (!eni_vcc
->rx
) return 0;
820 /* set up VCI descriptor */
821 here
= eni_dev
->vci
+vcc
->vci
*16;
822 DPRINTK("loc 0x%x\n",(unsigned) (eni_vcc
->recv
-eni_dev
->ram
)/4);
823 size
= eni_vcc
->words
>> 8;
824 for (order
= -1; size
; order
++) size
>>= 1;
825 writel(0,here
+4); /* descr, read = 0 */
826 writel(0,here
+8); /* write, state, count = 0 */
827 if (eni_dev
->rx_map
[vcc
->vci
])
828 printk(KERN_CRIT DEV_LABEL
"(itf %d): BUG - VCI %d already "
829 "in use\n",vcc
->dev
->number
,vcc
->vci
);
830 eni_dev
->rx_map
[vcc
->vci
] = vcc
; /* now it counts */
831 writel(((vcc
->qos
.aal
!= ATM_AAL5
? MID_MODE_RAW
: MID_MODE_AAL5
) <<
832 MID_VCI_MODE_SHIFT
) | MID_VCI_PTI_MODE
|
833 (((eni_vcc
->recv
-eni_dev
->ram
) >> (MID_LOC_SKIP
+2)) <<
834 MID_VCI_LOCATION_SHIFT
) | (order
<< MID_VCI_SIZE_SHIFT
),here
);
839 static void close_rx(struct atm_vcc
*vcc
)
841 DECLARE_WAITQUEUE(wait
,current
);
843 struct eni_dev
*eni_dev
;
844 struct eni_vcc
*eni_vcc
;
846 eni_vcc
= ENI_VCC(vcc
);
847 if (!eni_vcc
->rx
) return;
848 eni_dev
= ENI_DEV(vcc
->dev
);
849 if (vcc
->vpi
!= ATM_VPI_UNSPEC
&& vcc
->vci
!= ATM_VCI_UNSPEC
) {
850 here
= eni_dev
->vci
+vcc
->vci
*16;
852 writel((readl(here
) & ~MID_VCI_MODE
) | (MID_MODE_TRASH
<<
853 MID_VCI_MODE_SHIFT
),here
);
854 /* wait for receiver to become idle */
856 /* discard pending cell */
857 writel(readl(here
) & ~MID_VCI_IN_SERVICE
,here
);
858 /* don't accept any new ones */
859 eni_dev
->rx_map
[vcc
->vci
] = NULL
;
860 /* wait for RX queue to drain */
861 DPRINTK("eni_close: waiting for RX ...\n");
862 EVENT("RX closing\n",0,0);
863 add_wait_queue(&eni_dev
->rx_wait
,&wait
);
864 set_current_state(TASK_UNINTERRUPTIBLE
);
867 /* transition service->rx: rxing++, servicing-- */
868 if (!eni_vcc
->servicing
) {
870 if (!eni_vcc
->rxing
) break;
872 EVENT("drain PDUs (rx %ld, serv %ld)\n",eni_vcc
->rxing
,
874 printk(KERN_INFO
"%d+%d RX left\n",eni_vcc
->servicing
,
877 set_current_state(TASK_UNINTERRUPTIBLE
);
883 tasklet_disable(&eni_dev
->task
);
884 tmp
= readl(eni_dev
->vci
+vcc
->vci
*16+4) & MID_VCI_READ
;
885 at_end
= eni_vcc
->rx_pos
== tmp
>> MID_VCI_READ_SHIFT
;
886 tasklet_enable(&eni_dev
->task
);
888 EVENT("drain discard (host 0x%lx, nic 0x%lx)\n",
889 eni_vcc
->rx_pos
,tmp
);
890 printk(KERN_INFO
"draining RX: host 0x%lx, nic 0x%x\n",
891 eni_vcc
->rx_pos
,tmp
);
893 set_current_state(TASK_UNINTERRUPTIBLE
);
895 set_current_state(TASK_RUNNING
);
896 remove_wait_queue(&eni_dev
->rx_wait
,&wait
);
898 eni_free_mem(eni_dev
,eni_vcc
->recv
,eni_vcc
->words
<< 2);
903 static int start_rx(struct atm_dev
*dev
)
905 struct eni_dev
*eni_dev
;
907 eni_dev
= ENI_DEV(dev
);
908 eni_dev
->rx_map
= (struct atm_vcc
**) get_zeroed_page(GFP_KERNEL
);
909 if (!eni_dev
->rx_map
) {
910 printk(KERN_ERR DEV_LABEL
"(itf %d): couldn't get free page\n",
912 free_page((unsigned long) eni_dev
->free_list
);
915 eni_dev
->rx_mult
= DEFAULT_RX_MULT
;
916 eni_dev
->fast
= eni_dev
->last_fast
= NULL
;
917 eni_dev
->slow
= eni_dev
->last_slow
= NULL
;
918 init_waitqueue_head(&eni_dev
->rx_wait
);
919 skb_queue_head_init(&eni_dev
->rx_queue
);
920 eni_dev
->serv_read
= eni_in(MID_SERV_WRITE
);
921 eni_out(0,MID_DMA_WR_RX
);
926 /*----------------------------------- TX ------------------------------------*/
929 enum enq_res
{ enq_ok
,enq_next
,enq_jam
};
932 static inline void put_dma(int chan
,u32
*dma
,int *j
,dma_addr_t paddr
,
937 DPRINTK("put_dma: 0x%lx+0x%x\n",(unsigned long) paddr
,size
);
938 EVENT("put_dma: 0x%lx+0x%lx\n",(unsigned long) paddr
,size
);
939 #if 0 /* don't complain anymore */
941 printk(KERN_ERR
"put_dma: unaligned addr (0x%lx)\n",paddr
);
943 printk(KERN_ERR
"put_dma: unaligned size (0x%lx)\n",size
);
946 init
= 4-(paddr
& 3);
947 if (init
> size
|| size
< 7) init
= size
;
948 DPRINTK("put_dma: %lx DMA: %d/%d bytes\n",
949 (unsigned long) paddr
,init
,size
);
950 dma
[(*j
)++] = MID_DT_BYTE
| (init
<< MID_DMA_COUNT_SHIFT
) |
951 (chan
<< MID_DMA_CHAN_SHIFT
);
958 if (words
&& (paddr
& 31)) {
959 init
= 8-((paddr
& 31) >> 2);
960 if (init
> words
) init
= words
;
961 DPRINTK("put_dma: %lx DMA: %d/%d words\n",
962 (unsigned long) paddr
,init
,words
);
963 dma
[(*j
)++] = MID_DT_WORD
| (init
<< MID_DMA_COUNT_SHIFT
) |
964 (chan
<< MID_DMA_CHAN_SHIFT
);
969 #ifdef CONFIG_ATM_ENI_BURST_TX_16W /* may work with some PCI chipsets ... */
971 DPRINTK("put_dma: %lx DMA: %d*16/%d words\n",
972 (unsigned long) paddr
,words
>> 4,words
);
973 dma
[(*j
)++] = MID_DT_16W
| ((words
>> 4) << MID_DMA_COUNT_SHIFT
)
974 | (chan
<< MID_DMA_CHAN_SHIFT
);
976 paddr
+= (words
& ~15) << 2;
980 #ifdef CONFIG_ATM_ENI_BURST_TX_8W /* recommended */
982 DPRINTK("put_dma: %lx DMA: %d*8/%d words\n",
983 (unsigned long) paddr
,words
>> 3,words
);
984 dma
[(*j
)++] = MID_DT_8W
| ((words
>> 3) << MID_DMA_COUNT_SHIFT
)
985 | (chan
<< MID_DMA_CHAN_SHIFT
);
987 paddr
+= (words
& ~7) << 2;
991 #ifdef CONFIG_ATM_ENI_BURST_TX_4W /* probably useless if TX_8W or TX_16W */
993 DPRINTK("put_dma: %lx DMA: %d*4/%d words\n",
994 (unsigned long) paddr
,words
>> 2,words
);
995 dma
[(*j
)++] = MID_DT_4W
| ((words
>> 2) << MID_DMA_COUNT_SHIFT
)
996 | (chan
<< MID_DMA_CHAN_SHIFT
);
998 paddr
+= (words
& ~3) << 2;
1002 #ifdef CONFIG_ATM_ENI_BURST_TX_2W /* probably useless if TX_4W, TX_8W, ... */
1004 DPRINTK("put_dma: %lx DMA: %d*2/%d words\n",
1005 (unsigned long) paddr
,words
>> 1,words
);
1006 dma
[(*j
)++] = MID_DT_2W
| ((words
>> 1) << MID_DMA_COUNT_SHIFT
)
1007 | (chan
<< MID_DMA_CHAN_SHIFT
);
1008 dma
[(*j
)++] = paddr
;
1009 paddr
+= (words
& ~1) << 2;
1014 DPRINTK("put_dma: %lx DMA: %d words\n",(unsigned long) paddr
,
1016 dma
[(*j
)++] = MID_DT_WORD
| (words
<< MID_DMA_COUNT_SHIFT
) |
1017 (chan
<< MID_DMA_CHAN_SHIFT
);
1018 dma
[(*j
)++] = paddr
;
1019 paddr
+= words
<< 2;
1022 DPRINTK("put_dma: %lx DMA: %d bytes\n",(unsigned long) paddr
,
1024 dma
[(*j
)++] = MID_DT_BYTE
| (size
<< MID_DMA_COUNT_SHIFT
) |
1025 (chan
<< MID_DMA_CHAN_SHIFT
);
1026 dma
[(*j
)++] = paddr
;
1031 static enum enq_res
do_tx(struct sk_buff
*skb
)
1033 struct atm_vcc
*vcc
;
1034 struct eni_dev
*eni_dev
;
1035 struct eni_vcc
*eni_vcc
;
1039 u32 size
; /* in words */
1040 int aal5
,dma_size
,i
,j
;
1042 DPRINTK(">do_tx\n");
1044 EVENT("do_tx: skb=0x%lx, %ld bytes\n",(unsigned long) skb
,skb
->len
);
1045 vcc
= ATM_SKB(skb
)->vcc
;
1047 eni_dev
= ENI_DEV(vcc
->dev
);
1049 eni_vcc
= ENI_VCC(vcc
);
1052 #if 0 /* Enable this for testing with the "align" program */
1054 unsigned int hack
= *((char *) skb
->data
)-'0';
1062 #if 0 /* should work now */
1063 if ((unsigned long) skb
->data
& 3)
1064 printk(KERN_ERR DEV_LABEL
"(itf %d): VCI %d has mis-aligned "
1065 "TX data\n",vcc
->dev
->number
,vcc
->vci
);
1068 * Potential future IP speedup: make hard_header big enough to put
1069 * segmentation descriptor directly into PDU. Saves: 4 slave writes,
1070 * 1 DMA xfer & 2 DMA'ed bytes (protocol layering is for wimps :-)
1073 aal5
= vcc
->qos
.aal
== ATM_AAL5
;
1074 /* check space in buffer */
1076 size
= (ATM_CELL_PAYLOAD
>> 2)+TX_DESCR_SIZE
;
1077 /* cell without HEC plus segmentation header (includes
1078 four-byte cell header) */
1080 size
= skb
->len
+4*AAL5_TRAILER
+ATM_CELL_PAYLOAD
-1;
1081 /* add AAL5 trailer */
1082 size
= ((size
-(size
% ATM_CELL_PAYLOAD
)) >> 2)+TX_DESCR_SIZE
;
1083 /* add segmentation header */
1086 * Can I move tx_pos by size bytes without getting closer than TX_GAP
1087 * to the read pointer ? TX_GAP means to leave some space for what
1088 * the manual calls "too close".
1090 if (!NEPMOK(tx
->tx_pos
,size
+TX_GAP
,
1091 eni_in(MID_TX_RDPTR(tx
->index
)),tx
->words
)) {
1092 DPRINTK(DEV_LABEL
"(itf %d): TX full (size %d)\n",
1093 vcc
->dev
->number
,size
);
1097 dma_wr
= eni_in(MID_DMA_WR_TX
);
1098 dma_rd
= eni_in(MID_DMA_RD_TX
);
1099 dma_size
= 3; /* JK for descriptor and final fill, plus final size
1100 mis-alignment fix */
1101 DPRINTK("iovcnt = %d\n",skb_shinfo(skb
)->nr_frags
);
1102 if (!skb_shinfo(skb
)->nr_frags
) dma_size
+= 5;
1103 else dma_size
+= 5*(skb_shinfo(skb
)->nr_frags
+1);
1104 if (dma_size
> TX_DMA_BUF
) {
1105 printk(KERN_CRIT DEV_LABEL
"(itf %d): needs %d DMA entries "
1106 "(got only %d)\n",vcc
->dev
->number
,dma_size
,TX_DMA_BUF
);
1108 DPRINTK("dma_wr is %d, tx_pos is %ld\n",dma_wr
,tx
->tx_pos
);
1109 if (dma_wr
!= dma_rd
&& ((dma_rd
+NR_DMA_TX
-dma_wr
) & (NR_DMA_TX
-1)) <
1111 printk(KERN_WARNING DEV_LABEL
"(itf %d): TX DMA full\n",
1115 paddr
= pci_map_single(eni_dev
->pci_dev
,skb
->data
,skb
->len
,
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)
1133 skb
->len
- skb
->data_len
);
1135 put_dma(tx
->index
,eni_dev
->dma
,&j
,(unsigned long)
1136 skb_shinfo(skb
)->frags
[i
].page
+ skb_shinfo(skb
)->frags
[i
].page_offset
,
1137 skb_shinfo(skb
)->frags
[i
].size
);
1140 put_dma(tx
->index
,eni_dev
->dma
,&j
,zeroes
,4-(skb
->len
& 3));
1141 /* JK for AAL5 trailer - AAL0 doesn't need it, but who cares ... */
1142 eni_dev
->dma
[j
++] = (((tx
->tx_pos
+size
) & (tx
->words
-1)) <<
1143 MID_DMA_COUNT_SHIFT
) | (tx
->index
<< MID_DMA_CHAN_SHIFT
) |
1144 MID_DMA_END
| MID_DT_JK
;
1146 DPRINTK("DMA at end: %d\n",j
);
1148 writel((MID_SEG_TX_ID
<< MID_SEG_ID_SHIFT
) |
1149 (aal5
? MID_SEG_AAL5
: 0) | (tx
->prescaler
<< MID_SEG_PR_SHIFT
) |
1150 (tx
->resolution
<< MID_SEG_RATE_SHIFT
) |
1151 (size
/(ATM_CELL_PAYLOAD
/4)),tx
->send
+tx
->tx_pos
*4);
1152 /*printk("dsc = 0x%08lx\n",(unsigned long) readl(tx->send+tx->tx_pos*4));*/
1153 writel((vcc
->vci
<< MID_SEG_VCI_SHIFT
) |
1154 (aal5
? 0 : (skb
->data
[3] & 0xf)) |
1155 (ATM_SKB(skb
)->atm_options
& ATM_ATMOPT_CLP
? MID_SEG_CLP
: 0),
1156 tx
->send
+((tx
->tx_pos
+1) & (tx
->words
-1))*4);
1157 DPRINTK("size: %d, len:%d\n",size
,skb
->len
);
1159 writel(skb
->len
,tx
->send
+
1160 ((tx
->tx_pos
+size
-AAL5_TRAILER
) & (tx
->words
-1))*4);
1162 for (i
= 0; i
< j
; i
++) {
1163 writel(eni_dev
->dma
[i
*2],eni_dev
->tx_dma
+dma_wr
*8);
1164 writel(eni_dev
->dma
[i
*2+1],eni_dev
->tx_dma
+dma_wr
*8+4);
1165 dma_wr
= (dma_wr
+1) & (NR_DMA_TX
-1);
1167 ENI_PRV_POS(skb
) = tx
->tx_pos
;
1168 ENI_PRV_SIZE(skb
) = size
;
1169 ENI_VCC(vcc
)->txing
+= size
;
1170 tx
->tx_pos
= (tx
->tx_pos
+size
) & (tx
->words
-1);
1171 DPRINTK("dma_wr set to %d, tx_pos is now %ld\n",dma_wr
,tx
->tx_pos
);
1172 eni_out(dma_wr
,MID_DMA_WR_TX
);
1173 skb_queue_tail(&eni_dev
->tx_queue
,skb
);
1179 static void poll_tx(struct atm_dev
*dev
)
1182 struct sk_buff
*skb
;
1186 DPRINTK(">poll_tx\n");
1187 for (i
= NR_CHAN
-1; i
>= 0; i
--) {
1188 tx
= &ENI_DEV(dev
)->tx
[i
];
1190 while ((skb
= skb_dequeue(&tx
->backlog
))) {
1192 if (res
== enq_ok
) continue;
1193 DPRINTK("re-queuing TX PDU\n");
1194 skb_queue_head(&tx
->backlog
,skb
);
1196 if (res
== enq_jam
) return;
1203 static void dequeue_tx(struct atm_dev
*dev
)
1205 struct eni_dev
*eni_dev
;
1206 struct atm_vcc
*vcc
;
1207 struct sk_buff
*skb
;
1211 eni_dev
= ENI_DEV(dev
);
1213 while ((skb
= skb_dequeue(&eni_dev
->tx_queue
))) {
1214 vcc
= ATM_SKB(skb
)->vcc
;
1216 tx
= ENI_VCC(vcc
)->tx
;
1217 NULLCHECK(ENI_VCC(vcc
)->tx
);
1218 DPRINTK("dequeue_tx: next 0x%lx curr 0x%x\n",ENI_PRV_POS(skb
),
1219 (unsigned) eni_in(MID_TX_DESCRSTART(tx
->index
)));
1220 if (ENI_VCC(vcc
)->txing
< tx
->words
&& ENI_PRV_POS(skb
) ==
1221 eni_in(MID_TX_DESCRSTART(tx
->index
))) {
1222 skb_queue_head(&eni_dev
->tx_queue
,skb
);
1225 ENI_VCC(vcc
)->txing
-= ENI_PRV_SIZE(skb
);
1226 pci_unmap_single(eni_dev
->pci_dev
,ENI_PRV_PADDR(skb
),skb
->len
,
1228 if (vcc
->pop
) vcc
->pop(vcc
,skb
);
1229 else dev_kfree_skb_irq(skb
);
1230 atomic_inc(&vcc
->stats
->tx
);
1231 wake_up(&eni_dev
->tx_wait
);
1237 static struct eni_tx
*alloc_tx(struct eni_dev
*eni_dev
,int ubr
)
1241 for (i
= !ubr
; i
< NR_CHAN
; i
++)
1242 if (!eni_dev
->tx
[i
].send
) return eni_dev
->tx
+i
;
1247 static int comp_tx(struct eni_dev
*eni_dev
,int *pcr
,int reserved
,int *pre
,
1248 int *res
,int unlimited
)
1250 static const int pre_div
[] = { 4,16,128,2048 };
1251 /* 2^(((x+2)^2-(x+2))/2+1) */
1253 if (unlimited
) *pre
= *res
= 0;
1258 for (*pre
= 0; *pre
< 3; (*pre
)++)
1259 if (TS_CLOCK
/pre_div
[*pre
]/64 <= *pcr
) break;
1260 div
= pre_div
[*pre
]**pcr
;
1261 DPRINTK("min div %d\n",div
);
1262 *res
= TS_CLOCK
/div
-1;
1267 if (!*pcr
) *pcr
= eni_dev
->tx_bw
+reserved
;
1268 for (*pre
= 3; *pre
>= 0; (*pre
)--)
1269 if (TS_CLOCK
/pre_div
[*pre
]/64 > -*pcr
) break;
1270 if (*pre
< 3) (*pre
)++; /* else fail later */
1271 div
= pre_div
[*pre
]*-*pcr
;
1272 DPRINTK("max div %d\n",div
);
1273 *res
= DIV_ROUND_UP(TS_CLOCK
, div
)-1;
1275 if (*res
< 0) *res
= 0;
1276 if (*res
> MID_SEG_MAX_RATE
) *res
= MID_SEG_MAX_RATE
;
1278 *pcr
= TS_CLOCK
/pre_div
[*pre
]/(*res
+1);
1279 DPRINTK("out pcr: %d (%d:%d)\n",*pcr
,*pre
,*res
);
1284 static int reserve_or_set_tx(struct atm_vcc
*vcc
,struct atm_trafprm
*txtp
,
1285 int set_rsv
,int set_shp
)
1287 struct eni_dev
*eni_dev
= ENI_DEV(vcc
->dev
);
1288 struct eni_vcc
*eni_vcc
= ENI_VCC(vcc
);
1292 int rate
,ubr
,unlimited
,new_tx
;
1296 rate
= atm_pcr_goal(txtp
);
1297 ubr
= txtp
->traffic_class
== ATM_UBR
;
1298 unlimited
= ubr
&& (!rate
|| rate
<= -ATM_OC3_PCR
||
1299 rate
>= ATM_OC3_PCR
);
1301 size
= txtp
->max_sdu
*eni_dev
->tx_mult
/100;
1302 if (size
> MID_MAX_BUF_SIZE
&& txtp
->max_sdu
<=
1304 size
= MID_MAX_BUF_SIZE
;
1308 eni_vcc
->tx
= eni_dev
->ubr
;
1309 txtp
->pcr
= ATM_OC3_PCR
;
1314 new_tx
= !eni_vcc
->tx
;
1315 mem
= NULL
; /* for gcc */
1316 if (!new_tx
) tx
= eni_vcc
->tx
;
1318 mem
= eni_alloc_mem(eni_dev
,&size
);
1319 if (!mem
) return -ENOBUFS
;
1320 tx
= alloc_tx(eni_dev
,unlimited
);
1322 eni_free_mem(eni_dev
,mem
,size
);
1325 DPRINTK("got chan %d\n",tx
->index
);
1326 tx
->reserved
= tx
->shaping
= 0;
1328 tx
->words
= size
>> 2;
1329 skb_queue_head_init(&tx
->backlog
);
1330 for (order
= 0; size
> (1 << (order
+10)); order
++);
1331 eni_out((order
<< MID_SIZE_SHIFT
) |
1332 ((tx
->send
-eni_dev
->ram
) >> (MID_LOC_SKIP
+2)),
1333 MID_TX_PLACE(tx
->index
));
1334 tx
->tx_pos
= eni_in(MID_TX_DESCRSTART(tx
->index
)) &
1337 error
= comp_tx(eni_dev
,&rate
,tx
->reserved
,&pre
,&res
,unlimited
);
1338 if (!error
&& txtp
->min_pcr
> rate
) error
= -EINVAL
;
1339 if (!error
&& txtp
->max_pcr
&& txtp
->max_pcr
!= ATM_MAX_PCR
&&
1340 txtp
->max_pcr
< rate
) error
= -EINVAL
;
1341 if (!error
&& !ubr
&& rate
> eni_dev
->tx_bw
+tx
->reserved
)
1343 if (!error
&& set_rsv
&& !set_shp
&& rate
< tx
->shaping
)
1345 if (!error
&& !set_rsv
&& rate
> tx
->reserved
&& !ubr
)
1350 eni_free_mem(eni_dev
,mem
,size
);
1355 if (set_rsv
&& !ubr
) {
1356 eni_dev
->tx_bw
+= tx
->reserved
;
1357 tx
->reserved
= rate
;
1358 eni_dev
->tx_bw
-= rate
;
1360 if (set_shp
|| (unlimited
&& new_tx
)) {
1361 if (unlimited
&& new_tx
) eni_dev
->ubr
= tx
;
1362 tx
->prescaler
= pre
;
1363 tx
->resolution
= res
;
1366 if (set_shp
) eni_vcc
->tx
= tx
;
1367 DPRINTK("rsv %d shp %d\n",tx
->reserved
,tx
->shaping
);
1372 static int open_tx_first(struct atm_vcc
*vcc
)
1374 ENI_VCC(vcc
)->tx
= NULL
;
1375 if (vcc
->qos
.txtp
.traffic_class
== ATM_NONE
) return 0;
1376 ENI_VCC(vcc
)->txing
= 0;
1377 return reserve_or_set_tx(vcc
,&vcc
->qos
.txtp
,1,1);
1381 static int open_tx_second(struct atm_vcc
*vcc
)
1383 return 0; /* nothing to do */
1387 static void close_tx(struct atm_vcc
*vcc
)
1389 DECLARE_WAITQUEUE(wait
,current
);
1390 struct eni_dev
*eni_dev
;
1391 struct eni_vcc
*eni_vcc
;
1393 eni_vcc
= ENI_VCC(vcc
);
1394 if (!eni_vcc
->tx
) return;
1395 eni_dev
= ENI_DEV(vcc
->dev
);
1396 /* wait for TX queue to drain */
1397 DPRINTK("eni_close: waiting for TX ...\n");
1398 add_wait_queue(&eni_dev
->tx_wait
,&wait
);
1399 set_current_state(TASK_UNINTERRUPTIBLE
);
1403 tasklet_disable(&eni_dev
->task
);
1404 txing
= skb_peek(&eni_vcc
->tx
->backlog
) || eni_vcc
->txing
;
1405 tasklet_enable(&eni_dev
->task
);
1407 DPRINTK("%d TX left\n",eni_vcc
->txing
);
1409 set_current_state(TASK_UNINTERRUPTIBLE
);
1411 set_current_state(TASK_RUNNING
);
1412 remove_wait_queue(&eni_dev
->tx_wait
,&wait
);
1413 if (eni_vcc
->tx
!= eni_dev
->ubr
) {
1415 * Looping a few times in here is probably far cheaper than
1416 * keeping track of TX completions all the time, so let's poll
1419 while (eni_in(MID_TX_RDPTR(eni_vcc
->tx
->index
)) !=
1420 eni_in(MID_TX_DESCRSTART(eni_vcc
->tx
->index
)))
1422 eni_free_mem(eni_dev
,eni_vcc
->tx
->send
,eni_vcc
->tx
->words
<< 2);
1423 eni_vcc
->tx
->send
= NULL
;
1424 eni_dev
->tx_bw
+= eni_vcc
->tx
->reserved
;
1430 static int start_tx(struct atm_dev
*dev
)
1432 struct eni_dev
*eni_dev
;
1435 eni_dev
= ENI_DEV(dev
);
1437 eni_dev
->tx_bw
= ATM_OC3_PCR
;
1438 eni_dev
->tx_mult
= DEFAULT_TX_MULT
;
1439 init_waitqueue_head(&eni_dev
->tx_wait
);
1440 eni_dev
->ubr
= NULL
;
1441 skb_queue_head_init(&eni_dev
->tx_queue
);
1442 eni_out(0,MID_DMA_WR_TX
);
1443 for (i
= 0; i
< NR_CHAN
; i
++) {
1444 eni_dev
->tx
[i
].send
= NULL
;
1445 eni_dev
->tx
[i
].index
= i
;
1451 /*--------------------------------- common ----------------------------------*/
1454 #if 0 /* may become useful again when tuning things */
1456 static void foo(void)
1459 "tx_complete=%d,dma_complete=%d,queued=%d,requeued=%d,sub=%d,\n"
1460 "backlogged=%d,rx_enqueued=%d,rx_dequeued=%d,putting=%d,pushed=%d\n",
1461 tx_complete
,dma_complete
,queued
,requeued
,submitted
,backlogged
,
1462 rx_enqueued
,rx_dequeued
,putting
,pushed
);
1463 if (eni_boards
) printk(KERN_INFO
"loss: %ld\n",ENI_DEV(eni_boards
)->lost
);
1469 static void bug_int(struct atm_dev
*dev
,unsigned long reason
)
1471 struct eni_dev
*eni_dev
;
1473 DPRINTK(">bug_int\n");
1474 eni_dev
= ENI_DEV(dev
);
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 const char *media_name
[] __devinitdata
= {
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 __devinit
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 __devinit
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 __devinit
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_nocache(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
->base_diff
= real_base
- (unsigned long) base
;
1733 /* id may not be present in ASIC Tonga boards - check this @@@ */
1734 if (!eni_dev
->asic
) {
1735 eprom
= (base
+EPROM_SIZE
-sizeof(struct midway_eprom
));
1736 if (readl(&eprom
->magic
) != ENI155_MAGIC
) {
1738 printk(KERN_ERR KERN_ERR DEV_LABEL
"(itf %d): bad "
1739 "magic - expected 0x%x, got 0x%x\n",dev
->number
,
1740 ENI155_MAGIC
,(unsigned) readl(&eprom
->magic
));
1745 eni_dev
->phy
= base
+PHY_BASE
;
1746 eni_dev
->reg
= base
+REG_BASE
;
1747 eni_dev
->ram
= base
+RAM_BASE
;
1748 last
= MAP_MAX_SIZE
-RAM_BASE
;
1749 for (i
= last
-RAM_INCREMENT
; i
>= 0; i
-= RAM_INCREMENT
) {
1750 writel(0x55555555,eni_dev
->ram
+i
);
1751 if (readl(eni_dev
->ram
+i
) != 0x55555555) last
= i
;
1753 writel(0xAAAAAAAA,eni_dev
->ram
+i
);
1754 if (readl(eni_dev
->ram
+i
) != 0xAAAAAAAA) last
= i
;
1755 else writel(i
,eni_dev
->ram
+i
);
1758 for (i
= 0; i
< last
; i
+= RAM_INCREMENT
)
1759 if (readl(eni_dev
->ram
+i
) != i
) break;
1761 memset_io(eni_dev
->ram
,0,eni_dev
->mem
);
1762 /* TODO: should shrink allocation now */
1763 printk("mem=%dkB (",eni_dev
->mem
>> 10);
1764 /* TODO: check for non-SUNI, check for TAXI ? */
1765 if (!(eni_in(MID_RES_ID_MCON
) & 0x200) != !eni_dev
->asic
) {
1767 printk(KERN_ERR DEV_LABEL
"(itf %d): ERROR - wrong id 0x%x\n",
1768 dev
->number
,(unsigned) eni_in(MID_RES_ID_MCON
));
1772 error
= eni_dev
->asic
? get_esi_asic(dev
) : get_esi_fpga(dev
,base
);
1775 for (i
= 0; i
< ESI_LEN
; i
++)
1776 printk("%s%02X",i
? "-" : "",dev
->esi
[i
]);
1778 printk(KERN_NOTICE DEV_LABEL
"(itf %d): %s,%s\n",dev
->number
,
1779 eni_in(MID_RES_ID_MCON
) & 0x200 ? "ASIC" : "FPGA",
1780 media_name
[eni_in(MID_RES_ID_MCON
) & DAUGTHER_ID
]);
1782 error
= suni_init(dev
);
1793 static int __devinit
eni_start(struct atm_dev
*dev
)
1795 struct eni_dev
*eni_dev
;
1798 unsigned long buffer_mem
;
1801 DPRINTK(">eni_start\n");
1802 eni_dev
= ENI_DEV(dev
);
1803 if (request_irq(eni_dev
->irq
,&eni_int
,IRQF_SHARED
,DEV_LABEL
,dev
)) {
1804 printk(KERN_ERR DEV_LABEL
"(itf %d): IRQ%d is already in use\n",
1805 dev
->number
,eni_dev
->irq
);
1809 pci_set_master(eni_dev
->pci_dev
);
1810 if ((error
= pci_write_config_word(eni_dev
->pci_dev
,PCI_COMMAND
,
1811 PCI_COMMAND_MEMORY
| PCI_COMMAND_MASTER
|
1812 (eni_dev
->asic
? PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
: 0)))) {
1813 printk(KERN_ERR DEV_LABEL
"(itf %d): can't enable memory+"
1814 "master (0x%02x)\n",dev
->number
,error
);
1817 if ((error
= pci_write_config_byte(eni_dev
->pci_dev
,PCI_TONGA_CTRL
,
1819 printk(KERN_ERR DEV_LABEL
"(itf %d): can't set endian swap "
1820 "(0x%02x)\n",dev
->number
,error
);
1823 /* determine addresses of internal tables */
1824 eni_dev
->vci
= eni_dev
->ram
;
1825 eni_dev
->rx_dma
= eni_dev
->ram
+NR_VCI
*16;
1826 eni_dev
->tx_dma
= eni_dev
->rx_dma
+NR_DMA_RX
*8;
1827 eni_dev
->service
= eni_dev
->tx_dma
+NR_DMA_TX
*8;
1828 buf
= eni_dev
->service
+NR_SERVICE
*4;
1829 DPRINTK("vci 0x%lx,rx 0x%lx, tx 0x%lx,srv 0x%lx,buf 0x%lx\n",
1830 eni_dev
->vci
,eni_dev
->rx_dma
,eni_dev
->tx_dma
,
1831 eni_dev
->service
,buf
);
1832 spin_lock_init(&eni_dev
->lock
);
1833 tasklet_init(&eni_dev
->task
,eni_tasklet
,(unsigned long) dev
);
1834 eni_dev
->events
= 0;
1835 /* initialize memory management */
1836 buffer_mem
= eni_dev
->mem
- (buf
- eni_dev
->ram
);
1837 eni_dev
->free_list_size
= buffer_mem
/MID_MIN_BUF_SIZE
/2;
1838 eni_dev
->free_list
= kmalloc(
1839 sizeof(struct eni_free
)*(eni_dev
->free_list_size
+1),GFP_KERNEL
);
1840 if (!eni_dev
->free_list
) {
1841 printk(KERN_ERR DEV_LABEL
"(itf %d): couldn't get free page\n",
1846 eni_dev
->free_len
= 0;
1847 eni_put_free(eni_dev
,buf
,buffer_mem
);
1848 memset_io(eni_dev
->vci
,0,16*NR_VCI
); /* clear VCI table */
1850 * byte_addr free (k)
1851 * 0x00000000 512 VCI table
1852 * 0x00004000 496 RX DMA
1853 * 0x00005000 492 TX DMA
1854 * 0x00006000 488 service list
1855 * 0x00007000 484 buffers
1856 * 0x00080000 0 end (512kB)
1858 eni_out(0xffffffff,MID_IE
);
1859 error
= start_tx(dev
);
1860 if (error
) goto free_list
;
1861 error
= start_rx(dev
);
1862 if (error
) goto free_list
;
1863 error
= dev
->phy
->start(dev
);
1864 if (error
) goto free_list
;
1865 eni_out(eni_in(MID_MC_S
) | (1 << MID_INT_SEL_SHIFT
) |
1866 MID_TX_LOCK_MODE
| MID_DMA_ENABLE
| MID_TX_ENABLE
| MID_RX_ENABLE
,
1868 /* Tonga uses SBus INTReq1 */
1869 (void) eni_in(MID_ISA
); /* clear Midway interrupts */
1873 kfree(eni_dev
->free_list
);
1876 free_irq(eni_dev
->irq
, eni_dev
);
1883 static void eni_close(struct atm_vcc
*vcc
)
1885 DPRINTK(">eni_close\n");
1886 if (!ENI_VCC(vcc
)) return;
1887 clear_bit(ATM_VF_READY
,&vcc
->flags
);
1890 DPRINTK("eni_close: done waiting\n");
1891 /* deallocate memory */
1892 kfree(ENI_VCC(vcc
));
1893 vcc
->dev_data
= NULL
;
1894 clear_bit(ATM_VF_ADDR
,&vcc
->flags
);
1899 static int eni_open(struct atm_vcc
*vcc
)
1901 struct eni_dev
*eni_dev
;
1902 struct eni_vcc
*eni_vcc
;
1904 short vpi
= vcc
->vpi
;
1907 DPRINTK(">eni_open\n");
1908 EVENT("eni_open\n",0,0);
1909 if (!test_bit(ATM_VF_PARTIAL
,&vcc
->flags
))
1910 vcc
->dev_data
= NULL
;
1911 eni_dev
= ENI_DEV(vcc
->dev
);
1912 if (vci
!= ATM_VPI_UNSPEC
&& vpi
!= ATM_VCI_UNSPEC
)
1913 set_bit(ATM_VF_ADDR
,&vcc
->flags
);
1914 if (vcc
->qos
.aal
!= ATM_AAL0
&& vcc
->qos
.aal
!= ATM_AAL5
)
1916 DPRINTK(DEV_LABEL
"(itf %d): open %d.%d\n",vcc
->dev
->number
,vcc
->vpi
,
1918 if (!test_bit(ATM_VF_PARTIAL
,&vcc
->flags
)) {
1919 eni_vcc
= kmalloc(sizeof(struct eni_vcc
),GFP_KERNEL
);
1920 if (!eni_vcc
) return -ENOMEM
;
1921 vcc
->dev_data
= eni_vcc
;
1922 eni_vcc
->tx
= NULL
; /* for eni_close after open_rx */
1923 if ((error
= open_rx_first(vcc
))) {
1927 if ((error
= open_tx_first(vcc
))) {
1932 if (vci
== ATM_VPI_UNSPEC
|| vpi
== ATM_VCI_UNSPEC
) return 0;
1933 if ((error
= open_rx_second(vcc
))) {
1937 if ((error
= open_tx_second(vcc
))) {
1941 set_bit(ATM_VF_READY
,&vcc
->flags
);
1942 /* should power down SUNI while !ref_count @@@ */
1947 static int eni_change_qos(struct atm_vcc
*vcc
,struct atm_qos
*qos
,int flgs
)
1949 struct eni_dev
*eni_dev
= ENI_DEV(vcc
->dev
);
1950 struct eni_tx
*tx
= ENI_VCC(vcc
)->tx
;
1951 struct sk_buff
*skb
;
1952 int error
,rate
,rsv
,shp
;
1954 if (qos
->txtp
.traffic_class
== ATM_NONE
) return 0;
1955 if (tx
== eni_dev
->ubr
) return -EBADFD
;
1956 rate
= atm_pcr_goal(&qos
->txtp
);
1957 if (rate
< 0) rate
= -rate
;
1959 if ((flgs
& ATM_MF_DEC_RSV
) && rate
&& rate
< tx
->reserved
) rsv
= 1;
1960 if ((flgs
& ATM_MF_INC_RSV
) && (!rate
|| rate
> tx
->reserved
)) rsv
= 1;
1961 if ((flgs
& ATM_MF_DEC_SHP
) && rate
&& rate
< tx
->shaping
) shp
= 1;
1962 if ((flgs
& ATM_MF_INC_SHP
) && (!rate
|| rate
> tx
->shaping
)) shp
= 1;
1963 if (!rsv
&& !shp
) return 0;
1964 error
= reserve_or_set_tx(vcc
,&qos
->txtp
,rsv
,shp
);
1965 if (error
) return error
;
1966 if (shp
&& !(flgs
& ATM_MF_IMMED
)) return 0;
1968 * Walk through the send buffer and patch the rate information in all
1969 * segmentation buffer descriptors of this VCC.
1971 tasklet_disable(&eni_dev
->task
);
1972 skb_queue_walk(&eni_dev
->tx_queue
, skb
) {
1975 if (ATM_SKB(skb
)->vcc
!= vcc
) continue;
1976 dsc
= tx
->send
+ENI_PRV_POS(skb
)*4;
1977 writel((readl(dsc
) & ~(MID_SEG_RATE
| MID_SEG_PR
)) |
1978 (tx
->prescaler
<< MID_SEG_PR_SHIFT
) |
1979 (tx
->resolution
<< MID_SEG_RATE_SHIFT
), dsc
);
1981 tasklet_enable(&eni_dev
->task
);
1986 static int eni_ioctl(struct atm_dev
*dev
,unsigned int cmd
,void __user
*arg
)
1988 struct eni_dev
*eni_dev
= ENI_DEV(dev
);
1990 if (cmd
== ENI_MEMDUMP
) {
1991 if (!capable(CAP_NET_ADMIN
)) return -EPERM
;
1992 printk(KERN_WARNING
"Please use /proc/atm/" DEV_LABEL
":%d "
1993 "instead of obsolete ioctl ENI_MEMDUMP\n",dev
->number
);
1997 if (cmd
== ENI_SETMULT
) {
1998 struct eni_multipliers mult
;
2000 if (!capable(CAP_NET_ADMIN
)) return -EPERM
;
2001 if (copy_from_user(&mult
, arg
,
2002 sizeof(struct eni_multipliers
)))
2004 if ((mult
.tx
&& mult
.tx
<= 100) || (mult
.rx
&&mult
.rx
<= 100) ||
2005 mult
.tx
> 65536 || mult
.rx
> 65536)
2007 if (mult
.tx
) eni_dev
->tx_mult
= mult
.tx
;
2008 if (mult
.rx
) eni_dev
->rx_mult
= mult
.rx
;
2011 if (cmd
== ATM_SETCIRANGE
) {
2012 struct atm_cirange ci
;
2014 if (copy_from_user(&ci
, arg
,sizeof(struct atm_cirange
)))
2016 if ((ci
.vpi_bits
== 0 || ci
.vpi_bits
== ATM_CI_MAX
) &&
2017 (ci
.vci_bits
== NR_VCI_LD
|| ci
.vpi_bits
== ATM_CI_MAX
))
2021 if (!dev
->phy
->ioctl
) return -ENOIOCTLCMD
;
2022 return dev
->phy
->ioctl(dev
,cmd
,arg
);
2026 static int eni_getsockopt(struct atm_vcc
*vcc
,int level
,int optname
,
2027 void __user
*optval
,int optlen
)
2033 static int eni_setsockopt(struct atm_vcc
*vcc
,int level
,int optname
,
2034 void __user
*optval
,unsigned int optlen
)
2040 static int eni_send(struct atm_vcc
*vcc
,struct sk_buff
*skb
)
2044 DPRINTK(">eni_send\n");
2045 if (!ENI_VCC(vcc
)->tx
) {
2046 if (vcc
->pop
) vcc
->pop(vcc
,skb
);
2047 else dev_kfree_skb(skb
);
2051 printk(KERN_CRIT
"!skb in eni_send ?\n");
2052 if (vcc
->pop
) vcc
->pop(vcc
,skb
);
2055 if (vcc
->qos
.aal
== ATM_AAL0
) {
2056 if (skb
->len
!= ATM_CELL_SIZE
-1) {
2057 if (vcc
->pop
) vcc
->pop(vcc
,skb
);
2058 else dev_kfree_skb(skb
);
2061 *(u32
*) skb
->data
= htonl(*(u32
*) skb
->data
);
2064 ATM_SKB(skb
)->vcc
= vcc
;
2065 tasklet_disable(&ENI_DEV(vcc
->dev
)->task
);
2067 tasklet_enable(&ENI_DEV(vcc
->dev
)->task
);
2068 if (res
== enq_ok
) return 0;
2069 skb_queue_tail(&ENI_VCC(vcc
)->tx
->backlog
,skb
);
2071 tasklet_schedule(&ENI_DEV(vcc
->dev
)->task
);
2075 static void eni_phy_put(struct atm_dev
*dev
,unsigned char value
,
2078 writel(value
,ENI_DEV(dev
)->phy
+addr
*4);
2083 static unsigned char eni_phy_get(struct atm_dev
*dev
,unsigned long addr
)
2085 return readl(ENI_DEV(dev
)->phy
+addr
*4);
2089 static int eni_proc_read(struct atm_dev
*dev
,loff_t
*pos
,char *page
)
2091 struct hlist_node
*node
;
2093 static const char *signal
[] = { "LOST","unknown","okay" };
2094 struct eni_dev
*eni_dev
= ENI_DEV(dev
);
2095 struct atm_vcc
*vcc
;
2100 return sprintf(page
,DEV_LABEL
"(itf %d) signal %s, %dkB, "
2101 "%d cps remaining\n",dev
->number
,signal
[(int) dev
->signal
],
2102 eni_dev
->mem
>> 10,eni_dev
->tx_bw
);
2104 return sprintf(page
,"%4sBursts: TX"
2105 #if !defined(CONFIG_ATM_ENI_BURST_TX_16W) && \
2106 !defined(CONFIG_ATM_ENI_BURST_TX_8W) && \
2107 !defined(CONFIG_ATM_ENI_BURST_TX_4W) && \
2108 !defined(CONFIG_ATM_ENI_BURST_TX_2W)
2111 #ifdef CONFIG_ATM_ENI_BURST_TX_16W
2114 #ifdef CONFIG_ATM_ENI_BURST_TX_8W
2117 #ifdef CONFIG_ATM_ENI_BURST_TX_4W
2120 #ifdef CONFIG_ATM_ENI_BURST_TX_2W
2124 #if !defined(CONFIG_ATM_ENI_BURST_RX_16W) && \
2125 !defined(CONFIG_ATM_ENI_BURST_RX_8W) && \
2126 !defined(CONFIG_ATM_ENI_BURST_RX_4W) && \
2127 !defined(CONFIG_ATM_ENI_BURST_RX_2W)
2130 #ifdef CONFIG_ATM_ENI_BURST_RX_16W
2133 #ifdef CONFIG_ATM_ENI_BURST_RX_8W
2136 #ifdef CONFIG_ATM_ENI_BURST_RX_4W
2139 #ifdef CONFIG_ATM_ENI_BURST_RX_2W
2142 #ifndef CONFIG_ATM_ENI_TUNE_BURST
2147 return sprintf(page
,"%4sBuffer multipliers: tx %d%%, rx %d%%\n",
2148 "",eni_dev
->tx_mult
,eni_dev
->rx_mult
);
2149 for (i
= 0; i
< NR_CHAN
; i
++) {
2150 struct eni_tx
*tx
= eni_dev
->tx
+i
;
2152 if (!tx
->send
) continue;
2154 return sprintf(page
,"tx[%d]: 0x%ld-0x%ld "
2155 "(%6ld bytes), rsv %d cps, shp %d cps%s\n",i
,
2156 (unsigned long) (tx
->send
- eni_dev
->ram
),
2157 tx
->send
-eni_dev
->ram
+tx
->words
*4-1,tx
->words
*4,
2158 tx
->reserved
,tx
->shaping
,
2159 tx
== eni_dev
->ubr
? " (UBR)" : "");
2161 if (--left
) continue;
2162 return sprintf(page
,"%10sbacklog %u packets\n","",
2163 skb_queue_len(&tx
->backlog
));
2165 read_lock(&vcc_sklist_lock
);
2166 for(i
= 0; i
< VCC_HTABLE_SIZE
; ++i
) {
2167 struct hlist_head
*head
= &vcc_hash
[i
];
2169 sk_for_each(s
, node
, head
) {
2170 struct eni_vcc
*eni_vcc
;
2174 if (vcc
->dev
!= dev
)
2176 eni_vcc
= ENI_VCC(vcc
);
2177 if (--left
) continue;
2178 length
= sprintf(page
,"vcc %4d: ",vcc
->vci
);
2180 length
+= sprintf(page
+length
,"0x%ld-0x%ld "
2182 (unsigned long) (eni_vcc
->recv
- eni_dev
->ram
),
2183 eni_vcc
->recv
-eni_dev
->ram
+eni_vcc
->words
*4-1,
2185 if (eni_vcc
->tx
) length
+= sprintf(page
+length
,", ");
2188 length
+= sprintf(page
+length
,"tx[%d], txing %d bytes",
2189 eni_vcc
->tx
->index
,eni_vcc
->txing
);
2190 page
[length
] = '\n';
2191 read_unlock(&vcc_sklist_lock
);
2195 read_unlock(&vcc_sklist_lock
);
2196 for (i
= 0; i
< eni_dev
->free_len
; i
++) {
2197 struct eni_free
*fe
= eni_dev
->free_list
+i
;
2198 unsigned long offset
;
2200 if (--left
) continue;
2201 offset
= (unsigned long) eni_dev
->ram
+eni_dev
->base_diff
;
2202 return sprintf(page
,"free %p-%p (%6d bytes)\n",
2203 fe
->start
-offset
,fe
->start
-offset
+(1 << fe
->order
)-1,
2210 static const struct atmdev_ops ops
= {
2214 .getsockopt
= eni_getsockopt
,
2215 .setsockopt
= eni_setsockopt
,
2217 .phy_put
= eni_phy_put
,
2218 .phy_get
= eni_phy_get
,
2219 .change_qos
= eni_change_qos
,
2220 .proc_read
= eni_proc_read
2224 static int __devinit
eni_init_one(struct pci_dev
*pci_dev
,
2225 const struct pci_device_id
*ent
)
2227 struct atm_dev
*dev
;
2228 struct eni_dev
*eni_dev
;
2229 int error
= -ENOMEM
;
2231 DPRINTK("eni_init_one\n");
2233 if (pci_enable_device(pci_dev
)) {
2238 eni_dev
= kmalloc(sizeof(struct eni_dev
),GFP_KERNEL
);
2239 if (!eni_dev
) goto out0
;
2241 cpu_zeroes
= pci_alloc_consistent(pci_dev
,ENI_ZEROES_SIZE
,
2243 if (!cpu_zeroes
) goto out1
;
2245 dev
= atm_dev_register(DEV_LABEL
,&ops
,-1,NULL
);
2246 if (!dev
) goto out2
;
2247 pci_set_drvdata(pci_dev
, dev
);
2248 eni_dev
->pci_dev
= pci_dev
;
2249 dev
->dev_data
= eni_dev
;
2250 eni_dev
->asic
= ent
->driver_data
;
2251 error
= eni_do_init(dev
);
2252 if (error
) goto out3
;
2253 error
= eni_start(dev
);
2254 if (error
) goto out3
;
2255 eni_dev
->more
= eni_boards
;
2259 atm_dev_deregister(dev
);
2261 pci_free_consistent(eni_dev
->pci_dev
,ENI_ZEROES_SIZE
,cpu_zeroes
,zeroes
);
2270 static struct pci_device_id eni_pci_tbl
[] = {
2271 { PCI_VENDOR_ID_EF
, PCI_DEVICE_ID_EF_ATM_FPGA
, PCI_ANY_ID
, PCI_ANY_ID
,
2272 0, 0, 0 /* FPGA */ },
2273 { PCI_VENDOR_ID_EF
, PCI_DEVICE_ID_EF_ATM_ASIC
, PCI_ANY_ID
, PCI_ANY_ID
,
2274 0, 0, 1 /* ASIC */ },
2277 MODULE_DEVICE_TABLE(pci
,eni_pci_tbl
);
2280 static void __devexit
eni_remove_one(struct pci_dev
*pci_dev
)
2286 static struct pci_driver eni_driver
= {
2288 .id_table
= eni_pci_tbl
,
2289 .probe
= eni_init_one
,
2290 .remove
= __devexit_p(eni_remove_one
),
2294 static int __init
eni_init(void)
2296 struct sk_buff
*skb
; /* dummy for sizeof */
2298 if (sizeof(skb
->cb
) < sizeof(struct eni_skb_prv
)) {
2299 printk(KERN_ERR
"eni_detect: skb->cb is too small (%Zd < %Zd)\n",
2300 sizeof(skb
->cb
),sizeof(struct eni_skb_prv
));
2303 return pci_register_driver(&eni_driver
);
2307 module_init(eni_init
);
2308 /* @@@ since exit routine not defined, this module can not be unloaded */
2310 MODULE_LICENSE("GPL");