1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57#include <linux/module.h>
58#include <linux/mm.h>
59#include <linux/atmdev.h>
60#include <asm/io.h>
61#include <asm/byteorder.h>
62#include <linux/spinlock.h>
63#include <linux/pci.h>
64#include <linux/init.h>
65#include <linux/delay.h>
66#include <linux/interrupt.h>
67
68
69
70
71
72
73
74
75#define NUM_VCI (1024)
76
77
78
79
80#define DEBUG
81
82
83
84
85
86#undef DEBUG_RW
87
88
89
90
91
92#define FULL_MEMORY_TEST
93
94
95
96
97
98
99#define SERVICE_ENTRIES (1024)
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116#define TX_FIFO_DEPTH (7)
117
118
119
120
121
122
123#define LANAI_POLL_PERIOD (10*HZ)
124
125
126
127
128
129
130#define AAL5_RX_MULTIPLIER (3)
131
132
133
134
135
136#define AAL5_TX_MULTIPLIER (3)
137
138
139
140
141
142
143
144#define AAL0_TX_MULTIPLIER (40)
145
146
147
148
149
150
151#define AAL0_RX_BUFFER_SIZE (PAGE_SIZE)
152
153
154
155
156
157
158
159
160
161
162#define DEV_LABEL "lanai"
163
164#ifdef DEBUG
165
166#define DPRINTK(format, args...) \
167 printk(KERN_DEBUG DEV_LABEL ": " format, ##args)
168#define APRINTK(truth, format, args...) \
169 do { \
170 if (unlikely(!(truth))) \
171 printk(KERN_ERR DEV_LABEL ": " format, ##args); \
172 } while (0)
173
174#else
175
176#define DPRINTK(format, args...)
177#define APRINTK(truth, format, args...)
178
179#endif
180
181#ifdef DEBUG_RW
182#define RWDEBUG(format, args...) \
183 printk(KERN_DEBUG DEV_LABEL ": " format, ##args)
184#else
185#define RWDEBUG(format, args...)
186#endif
187
188
189
190#define LANAI_MAPPING_SIZE (0x40000)
191#define LANAI_EEPROM_SIZE (128)
192
193typedef int vci_t;
194typedef unsigned long bus_addr_t;
195
196
197struct lanai_buffer {
198 u32 *start;
199 u32 *end;
200 u32 *ptr;
201 dma_addr_t dmaaddr;
202};
203
204struct lanai_vcc_stats {
205 unsigned rx_nomem;
206 union {
207 struct {
208 unsigned rx_badlen;
209 unsigned service_trash;
210 unsigned service_stream;
211 unsigned service_rxcrc;
212 } aal5;
213 struct {
214 } aal0;
215 } x;
216};
217
218struct lanai_dev;
219
220
221
222
223
224
225
226
227
228struct lanai_vcc {
229 bus_addr_t vbase;
230 struct lanai_vcc_stats stats;
231 int nref;
232 vci_t vci;
233 struct {
234 struct lanai_buffer buf;
235 struct atm_vcc *atmvcc;
236 } rx;
237 struct {
238 struct lanai_buffer buf;
239 struct atm_vcc *atmvcc;
240 int endptr;
241 struct sk_buff_head backlog;
242 void (*unqueue)(struct lanai_dev *, struct lanai_vcc *, int);
243 } tx;
244};
245
246enum lanai_type {
247 lanai2 = PCI_VENDOR_ID_EF_ATM_LANAI2,
248 lanaihb = PCI_VENDOR_ID_EF_ATM_LANAIHB
249};
250
251struct lanai_dev_stats {
252 unsigned ovfl_trash;
253 unsigned vci_trash;
254 unsigned hec_err;
255 unsigned atm_ovfl;
256 unsigned pcierr_parity_detect;
257 unsigned pcierr_serr_set;
258 unsigned pcierr_master_abort;
259 unsigned pcierr_m_target_abort;
260 unsigned pcierr_s_target_abort;
261 unsigned pcierr_master_parity;
262 unsigned service_notx;
263 unsigned service_norx;
264 unsigned service_rxnotaal5;
265 unsigned dma_reenable;
266 unsigned card_reset;
267};
268
269struct lanai_dev {
270 bus_addr_t base;
271 struct lanai_dev_stats stats;
272 struct lanai_buffer service;
273 struct lanai_vcc **vccs;
274#ifdef USE_POWERDOWN
275 int nbound;
276#endif
277 enum lanai_type type;
278 vci_t num_vci;
279 u8 eeprom[LANAI_EEPROM_SIZE];
280 u32 serialno, magicno;
281 struct pci_dev *pci;
282 DECLARE_BITMAP(backlog_vccs, NUM_VCI);
283 DECLARE_BITMAP(transmit_ready, NUM_VCI);
284 struct timer_list timer;
285 int naal0;
286 struct lanai_buffer aal0buf;
287 u32 conf1, conf2;
288 u32 status;
289 spinlock_t endtxlock;
290 spinlock_t servicelock;
291 struct atm_vcc *cbrvcc;
292 int number;
293 int board_rev;
294 u8 pci_revision;
295
296
297
298};
299
300
301
302
303
304
305static void vci_bitfield_iterate(struct lanai_dev *lanai,
306 unsigned long *lp,
307 void (*func)(struct lanai_dev *,vci_t vci))
308{
309 vci_t vci = find_first_bit(lp, NUM_VCI);
310 while (vci < NUM_VCI) {
311 func(lanai, vci);
312 vci = find_next_bit(lp, NUM_VCI, vci + 1);
313 }
314}
315
316
317
318
319
320
321
322
323#define LANAI_PAGE_SIZE ((PAGE_SIZE >= 1024) ? PAGE_SIZE : 1024)
324
325
326
327
328
329
330
331
332static void lanai_buf_allocate(struct lanai_buffer *buf,
333 size_t bytes, size_t minbytes, struct pci_dev *pci)
334{
335 int size;
336
337 if (bytes > (128 * 1024))
338 bytes = 128 * 1024;
339 for (size = LANAI_PAGE_SIZE; size < bytes; size *= 2)
340 ;
341 if (minbytes < LANAI_PAGE_SIZE)
342 minbytes = LANAI_PAGE_SIZE;
343 do {
344
345
346
347
348
349 buf->start = pci_alloc_consistent(pci, size, &buf->dmaaddr);
350 if (buf->start != NULL) {
351
352 APRINTK((buf->dmaaddr & ~0xFFFFFF00) == 0,
353 "bad dmaaddr: 0x%lx\n",
354 (unsigned long) buf->dmaaddr);
355 buf->ptr = buf->start;
356 buf->end = (u32 *)
357 (&((unsigned char *) buf->start)[size]);
358 memset(buf->start, 0, size);
359 break;
360 }
361 size /= 2;
362 } while (size >= minbytes);
363}
364
365
366static inline size_t lanai_buf_size(const struct lanai_buffer *buf)
367{
368 return ((unsigned long) buf->end) - ((unsigned long) buf->start);
369}
370
371static void lanai_buf_deallocate(struct lanai_buffer *buf,
372 struct pci_dev *pci)
373{
374 if (buf->start != NULL) {
375 pci_free_consistent(pci, lanai_buf_size(buf),
376 buf->start, buf->dmaaddr);
377 buf->start = buf->end = buf->ptr = NULL;
378 }
379}
380
381
382static int lanai_buf_size_cardorder(const struct lanai_buffer *buf)
383{
384 int order = get_order(lanai_buf_size(buf)) + (PAGE_SHIFT - 10);
385
386
387 if (order > 7)
388 order = 7;
389 return order;
390}
391
392
393
394
395enum lanai_register {
396 Reset_Reg = 0x00,
397#define RESET_GET_BOARD_REV(x) (((x)>> 0)&0x03)
398#define RESET_GET_BOARD_ID(x) (((x)>> 2)&0x03)
399#define BOARD_ID_LANAI256 (0)
400 Endian_Reg = 0x04,
401 IntStatus_Reg = 0x08,
402 IntStatusMasked_Reg = 0x0C,
403 IntAck_Reg = 0x10,
404 IntAckMasked_Reg = 0x14,
405 IntStatusSet_Reg = 0x18,
406 IntStatusSetMasked_Reg = 0x1C,
407 IntControlEna_Reg = 0x20,
408 IntControlDis_Reg = 0x24,
409 Status_Reg = 0x28,
410#define STATUS_PROMDATA (0x00000001)
411#define STATUS_WAITING (0x00000002)
412#define STATUS_SOOL (0x00000004)
413#define STATUS_LOCD (0x00000008)
414#define STATUS_LED (0x00000010)
415#define STATUS_GPIN (0x00000020)
416#define STATUS_BUTTBUSY (0x00000040)
417 Config1_Reg = 0x2C,
418#define CONFIG1_PROMDATA (0x00000001)
419#define CONFIG1_PROMCLK (0x00000002)
420#define CONFIG1_SET_READMODE(x) ((x)*0x004)
421#define READMODE_PLAIN (0)
422#define READMODE_LINE (2)
423#define READMODE_MULTIPLE (3)
424#define CONFIG1_DMA_ENABLE (0x00000010)
425#define CONFIG1_POWERDOWN (0x00000020)
426#define CONFIG1_SET_LOOPMODE(x) ((x)*0x080)
427#define LOOPMODE_NORMAL (0)
428#define LOOPMODE_TIME (1)
429#define LOOPMODE_DIAG (2)
430#define LOOPMODE_LINE (3)
431#define CONFIG1_MASK_LOOPMODE (0x00000180)
432#define CONFIG1_SET_LEDMODE(x) ((x)*0x0200)
433#define LEDMODE_NOT_SOOL (0)
434#define LEDMODE_OFF (1)
435#define LEDMODE_ON (2)
436#define LEDMODE_NOT_LOCD (3)
437#define LEDMORE_GPIN (4)
438#define LEDMODE_NOT_GPIN (7)
439#define CONFIG1_MASK_LEDMODE (0x00000E00)
440#define CONFIG1_GPOUT1 (0x00001000)
441#define CONFIG1_GPOUT2 (0x00002000)
442#define CONFIG1_GPOUT3 (0x00004000)
443 Config2_Reg = 0x30,
444#define CONFIG2_HOWMANY (0x00000001)
445#define CONFIG2_PTI7_MODE (0x00000002)
446#define CONFIG2_VPI_CHK_DIS (0x00000004)
447#define CONFIG2_HEC_DROP (0x00000008)
448#define CONFIG2_VCI0_NORMAL (0x00000010)
449#define CONFIG2_CBR_ENABLE (0x00000020)
450#define CONFIG2_TRASH_ALL (0x00000040)
451#define CONFIG2_TX_DISABLE (0x00000080)
452#define CONFIG2_SET_TRASH (0x00000100)
453 Statistics_Reg = 0x34,
454#define STATS_GET_FIFO_OVFL(x) (((x)>> 0)&0xFF)
455#define STATS_GET_HEC_ERR(x) (((x)>> 8)&0xFF)
456#define STATS_GET_BAD_VCI(x) (((x)>>16)&0xFF)
457#define STATS_GET_BUF_OVFL(x) (((x)>>24)&0xFF)
458 ServiceStuff_Reg = 0x38,
459#define SSTUFF_SET_SIZE(x) ((x)*0x20000000)
460#define SSTUFF_SET_ADDR(x) ((x)>>8)
461 ServWrite_Reg = 0x3C,
462 ServRead_Reg = 0x40,
463 TxDepth_Reg = 0x44,
464 Butt_Reg = 0x48,
465 CBR_ICG_Reg = 0x50,
466 CBR_PTR_Reg = 0x54,
467 PingCount_Reg = 0x58,
468 DMA_Addr_Reg = 0x5C
469};
470
471static inline bus_addr_t reg_addr(const struct lanai_dev *lanai,
472 enum lanai_register reg)
473{
474 return lanai->base + (bus_addr_t) reg;
475}
476
477static inline u32 reg_read(const struct lanai_dev *lanai,
478 enum lanai_register reg)
479{
480 u32 t;
481 t = readl(reg_addr(lanai, reg));
482 RWDEBUG("R [0x%08X] 0x%02X = 0x%08X\n", (unsigned int) lanai->base,
483 (int) reg, t);
484 return t;
485}
486
487static inline void reg_write(const struct lanai_dev *lanai, u32 val,
488 enum lanai_register reg)
489{
490 RWDEBUG("W [0x%08X] 0x%02X < 0x%08X\n", (unsigned int) lanai->base,
491 (int) reg, val);
492 writel(val, reg_addr(lanai, reg));
493}
494
495static inline void conf1_write(const struct lanai_dev *lanai)
496{
497 reg_write(lanai, lanai->conf1, Config1_Reg);
498}
499
500static inline void conf2_write(const struct lanai_dev *lanai)
501{
502 reg_write(lanai, lanai->conf2, Config2_Reg);
503}
504
505
506static inline void conf2_write_if_powerup(const struct lanai_dev *lanai)
507{
508#ifdef USE_POWERDOWN
509 if (unlikely((lanai->conf1 & CONFIG1_POWERDOWN) != 0))
510 return;
511#endif
512 conf2_write(lanai);
513}
514
515static inline void reset_board(const struct lanai_dev *lanai)
516{
517 DPRINTK("about to reset board\n");
518 reg_write(lanai, 0, Reset_Reg);
519
520
521
522
523
524
525 udelay(5);
526}
527
528
529
530
531
532
533
534
535#define SRAM_START (0x20000)
536#define SRAM_BYTES (0x20000)
537
538static inline bus_addr_t sram_addr(const struct lanai_dev *lanai, int offset)
539{
540 return lanai->base + SRAM_START + offset;
541}
542
543static inline u32 sram_read(const struct lanai_dev *lanai, int offset)
544{
545 return readl(sram_addr(lanai, offset));
546}
547
548static inline void sram_write(const struct lanai_dev *lanai,
549 u32 val, int offset)
550{
551 writel(val, sram_addr(lanai, offset));
552}
553
554static int __init sram_test_word(
555 const struct lanai_dev *lanai, int offset, u32 pattern)
556{
557 u32 readback;
558 sram_write(lanai, pattern, offset);
559 readback = sram_read(lanai, offset);
560 if (likely(readback == pattern))
561 return 0;
562 printk(KERN_ERR DEV_LABEL
563 "(itf %d): SRAM word at %d bad: wrote 0x%X, read 0x%X\n",
564 lanai->number, offset,
565 (unsigned int) pattern, (unsigned int) readback);
566 return -EIO;
567}
568
569static int __init sram_test_pass(const struct lanai_dev *lanai, u32 pattern)
570{
571 int offset, result = 0;
572 for (offset = 0; offset < SRAM_BYTES && result == 0; offset += 4)
573 result = sram_test_word(lanai, offset, pattern);
574 return result;
575}
576
577static int __init sram_test_and_clear(const struct lanai_dev *lanai)
578{
579#ifdef FULL_MEMORY_TEST
580 int result;
581 DPRINTK("testing SRAM\n");
582 if ((result = sram_test_pass(lanai, 0x5555)) != 0)
583 return result;
584 if ((result = sram_test_pass(lanai, 0xAAAA)) != 0)
585 return result;
586#endif
587 DPRINTK("clearing SRAM\n");
588 return sram_test_pass(lanai, 0x0000);
589}
590
591
592
593
594enum lanai_vcc_offset {
595 vcc_rxaddr1 = 0x00,
596#define RXADDR1_SET_SIZE(x) ((x)*0x0000100)
597#define RXADDR1_SET_RMMODE(x) ((x)*0x00800)
598#define RMMODE_TRASH (0)
599#define RMMODE_PRESERVE (1)
600#define RMMODE_PIPE (2)
601#define RMMODE_PIPEALL (3)
602#define RXADDR1_OAM_PRESERVE (0x00002000)
603#define RXADDR1_SET_MODE(x) ((x)*0x0004000)
604#define RXMODE_TRASH (0)
605#define RXMODE_AAL0 (1)
606#define RXMODE_AAL5 (2)
607#define RXMODE_AAL5_STREAM (3)
608 vcc_rxaddr2 = 0x04,
609 vcc_rxcrc1 = 0x08,
610 vcc_rxcrc2 = 0x0C,
611 vcc_rxwriteptr = 0x10,
612#define RXWRITEPTR_LASTEFCI (0x00002000)
613#define RXWRITEPTR_DROPPING (0x00004000)
614#define RXWRITEPTR_TRASHING (0x00008000)
615 vcc_rxbufstart = 0x14,
616#define RXBUFSTART_CLP (0x00004000)
617#define RXBUFSTART_CI (0x00008000)
618 vcc_rxreadptr = 0x18,
619 vcc_txicg = 0x1C,
620 vcc_txaddr1 = 0x20,
621#define TXADDR1_SET_SIZE(x) ((x)*0x0000100)
622#define TXADDR1_ABR (0x00008000)
623 vcc_txaddr2 = 0x24,
624 vcc_txcrc1 = 0x28,
625 vcc_txcrc2 = 0x2C,
626 vcc_txreadptr = 0x30,
627#define TXREADPTR_GET_PTR(x) ((x)&0x01FFF)
628#define TXREADPTR_MASK_DELTA (0x0000E000)
629 vcc_txendptr = 0x34,
630#define TXENDPTR_CLP (0x00002000)
631#define TXENDPTR_MASK_PDUMODE (0x0000C000)
632#define PDUMODE_AAL0 (0*0x04000)
633#define PDUMODE_AAL5 (2*0x04000)
634#define PDUMODE_AAL5STREAM (3*0x04000)
635 vcc_txwriteptr = 0x38,
636#define TXWRITEPTR_GET_PTR(x) ((x)&0x1FFF)
637 vcc_txcbr_next = 0x3C
638#define TXCBR_NEXT_BOZO (0x00008000)
639};
640
641#define CARDVCC_SIZE (0x40)
642
643static inline bus_addr_t cardvcc_addr(const struct lanai_dev *lanai,
644 vci_t vci)
645{
646 return sram_addr(lanai, vci * CARDVCC_SIZE);
647}
648
649static inline u32 cardvcc_read(const struct lanai_vcc *lvcc,
650 enum lanai_vcc_offset offset)
651{
652 u32 val;
653 APRINTK(lvcc->vbase != 0, "cardvcc_read: unbound vcc!\n");
654 val= readl(lvcc->vbase + (bus_addr_t) offset);
655 RWDEBUG("VR vci=%04d 0x%02X = 0x%08X\n",
656 lvcc->vci, (int) offset, val);
657 return val;
658}
659
660static inline void cardvcc_write(const struct lanai_vcc *lvcc,
661 u32 val, enum lanai_vcc_offset offset)
662{
663 APRINTK(lvcc->vbase != 0, "cardvcc_write: unbound vcc!\n");
664 APRINTK((val & ~0xFFFF) == 0,
665 "cardvcc_write: bad val 0x%X (vci=%d, addr=0x%02X)\n",
666 (unsigned int) val, lvcc->vci, (unsigned int) offset);
667 RWDEBUG("VW vci=%04d 0x%02X > 0x%08X\n",
668 lvcc->vci, (unsigned int) offset, (unsigned int) val);
669 writel(val, lvcc->vbase + (bus_addr_t) offset);
670}
671
672
673
674
675
676
677
678static inline int aal5_size(int size)
679{
680 int cells = (size + 8 + 47) / 48;
681 return cells * 48;
682}
683
684
685
686
687static inline int aal5_spacefor(int space)
688{
689 int cells = space / 48;
690 return cells * 48;
691}
692
693
694
695static inline void lanai_free_skb(struct atm_vcc *atmvcc, struct sk_buff *skb)
696{
697 if (atmvcc->pop != NULL)
698 atmvcc->pop(atmvcc, skb);
699 else
700 dev_kfree_skb_any(skb);
701}
702
703
704
705static void host_vcc_start_rx(const struct lanai_vcc *lvcc)
706{
707 u32 addr1;
708 if (lvcc->rx.atmvcc->qos.aal == ATM_AAL5) {
709 dma_addr_t dmaaddr = lvcc->rx.buf.dmaaddr;
710 cardvcc_write(lvcc, 0xFFFF, vcc_rxcrc1);
711 cardvcc_write(lvcc, 0xFFFF, vcc_rxcrc2);
712 cardvcc_write(lvcc, 0, vcc_rxwriteptr);
713 cardvcc_write(lvcc, 0, vcc_rxbufstart);
714 cardvcc_write(lvcc, 0, vcc_rxreadptr);
715 cardvcc_write(lvcc, (dmaaddr >> 16) & 0xFFFF, vcc_rxaddr2);
716 addr1 = ((dmaaddr >> 8) & 0xFF) |
717 RXADDR1_SET_SIZE(lanai_buf_size_cardorder(&lvcc->rx.buf))|
718 RXADDR1_SET_RMMODE(RMMODE_TRASH) |
719
720 RXADDR1_SET_MODE(RXMODE_AAL5);
721 } else
722 addr1 = RXADDR1_SET_RMMODE(RMMODE_PRESERVE) |
723 RXADDR1_OAM_PRESERVE |
724 RXADDR1_SET_MODE(RXMODE_AAL0);
725
726 cardvcc_write(lvcc, addr1, vcc_rxaddr1);
727}
728
729static void host_vcc_start_tx(const struct lanai_vcc *lvcc)
730{
731 dma_addr_t dmaaddr = lvcc->tx.buf.dmaaddr;
732 cardvcc_write(lvcc, 0, vcc_txicg);
733 cardvcc_write(lvcc, 0xFFFF, vcc_txcrc1);
734 cardvcc_write(lvcc, 0xFFFF, vcc_txcrc2);
735 cardvcc_write(lvcc, 0, vcc_txreadptr);
736 cardvcc_write(lvcc, 0, vcc_txendptr);
737 cardvcc_write(lvcc, 0, vcc_txwriteptr);
738 cardvcc_write(lvcc,
739 (lvcc->tx.atmvcc->qos.txtp.traffic_class == ATM_CBR) ?
740 TXCBR_NEXT_BOZO | lvcc->vci : 0, vcc_txcbr_next);
741 cardvcc_write(lvcc, (dmaaddr >> 16) & 0xFFFF, vcc_txaddr2);
742 cardvcc_write(lvcc,
743 ((dmaaddr >> 8) & 0xFF) |
744 TXADDR1_SET_SIZE(lanai_buf_size_cardorder(&lvcc->tx.buf)),
745 vcc_txaddr1);
746}
747
748
749static void lanai_shutdown_rx_vci(const struct lanai_vcc *lvcc)
750{
751 if (lvcc->vbase == 0)
752 return;
753
754 cardvcc_write(lvcc,
755 RXADDR1_SET_RMMODE(RMMODE_TRASH) |
756 RXADDR1_SET_MODE(RXMODE_TRASH), vcc_rxaddr1);
757 udelay(15);
758
759 cardvcc_write(lvcc, 0, vcc_rxaddr2);
760 cardvcc_write(lvcc, 0, vcc_rxcrc1);
761 cardvcc_write(lvcc, 0, vcc_rxcrc2);
762 cardvcc_write(lvcc, 0, vcc_rxwriteptr);
763 cardvcc_write(lvcc, 0, vcc_rxbufstart);
764 cardvcc_write(lvcc, 0, vcc_rxreadptr);
765}
766
767
768
769
770
771
772
773
774static void lanai_shutdown_tx_vci(struct lanai_dev *lanai,
775 struct lanai_vcc *lvcc)
776{
777 struct sk_buff *skb;
778 unsigned long flags, timeout;
779 int read, write, lastread = -1;
780 APRINTK(!in_interrupt(),
781 "lanai_shutdown_tx_vci called w/o process context!\n");
782 if (lvcc->vbase == 0)
783 return;
784
785 while ((skb = skb_dequeue(&lvcc->tx.backlog)) != NULL)
786 lanai_free_skb(lvcc->tx.atmvcc, skb);
787 read_lock_irqsave(&vcc_sklist_lock, flags);
788 __clear_bit(lvcc->vci, lanai->backlog_vccs);
789 read_unlock_irqrestore(&vcc_sklist_lock, flags);
790
791
792
793
794
795 timeout = jiffies +
796 (((lanai_buf_size(&lvcc->tx.buf) / 1024) * HZ) >> 7);
797 write = TXWRITEPTR_GET_PTR(cardvcc_read(lvcc, vcc_txwriteptr));
798 for (;;) {
799 read = TXREADPTR_GET_PTR(cardvcc_read(lvcc, vcc_txreadptr));
800 if (read == write &&
801 (lvcc->tx.atmvcc->qos.txtp.traffic_class != ATM_CBR ||
802 (cardvcc_read(lvcc, vcc_txcbr_next) &
803 TXCBR_NEXT_BOZO) == 0))
804 break;
805 if (read != lastread) {
806 lastread = read;
807 timeout += HZ / 10;
808 }
809 if (unlikely(time_after(jiffies, timeout))) {
810 printk(KERN_ERR DEV_LABEL "(itf %d): Timed out on "
811 "backlog closing vci %d\n",
812 lvcc->tx.atmvcc->dev->number, lvcc->vci);
813 DPRINTK("read, write = %d, %d\n", read, write);
814 break;
815 }
816 schedule_timeout(HZ / 25);
817 }
818
819 cardvcc_write(lvcc, 0, vcc_txreadptr);
820 cardvcc_write(lvcc, 0, vcc_txwriteptr);
821 cardvcc_write(lvcc, 0, vcc_txendptr);
822 cardvcc_write(lvcc, 0, vcc_txcrc1);
823 cardvcc_write(lvcc, 0, vcc_txcrc2);
824 cardvcc_write(lvcc, 0, vcc_txaddr2);
825 cardvcc_write(lvcc, 0, vcc_txaddr1);
826}
827
828
829
830static inline int aal0_buffer_allocate(struct lanai_dev *lanai)
831{
832 DPRINTK("aal0_buffer_allocate: allocating AAL0 RX buffer\n");
833 lanai_buf_allocate(&lanai->aal0buf, AAL0_RX_BUFFER_SIZE, 80,
834 lanai->pci);
835 return (lanai->aal0buf.start == NULL) ? -ENOMEM : 0;
836}
837
838static inline void aal0_buffer_free(struct lanai_dev *lanai)
839{
840 DPRINTK("aal0_buffer_allocate: freeing AAL0 RX buffer\n");
841 lanai_buf_deallocate(&lanai->aal0buf, lanai->pci);
842}
843
844
845
846
847#define EEPROM_COPYRIGHT (0)
848#define EEPROM_COPYRIGHT_LEN (44)
849#define EEPROM_CHECKSUM (62)
850#define EEPROM_CHECKSUM_REV (63)
851#define EEPROM_MAC (64)
852#define EEPROM_MAC_REV (70)
853#define EEPROM_SERIAL (112)
854#define EEPROM_SERIAL_REV (116)
855#define EEPROM_MAGIC (120)
856#define EEPROM_MAGIC_REV (124)
857
858#define EEPROM_MAGIC_VALUE (0x5AB478D2)
859
860#ifndef READ_EEPROM
861
862
863static int __init eeprom_read(struct lanai_dev *lanai)
864{
865 printk(KERN_INFO DEV_LABEL "(itf %d): *NOT* reading EEPROM\n",
866 lanai->number);
867 memset(&lanai->eeprom[EEPROM_MAC], 0, 6);
868 return 0;
869}
870
871static int __init eeprom_validate(struct lanai_dev *lanai)
872{
873 lanai->serialno = 0;
874 lanai->magicno = EEPROM_MAGIC_VALUE;
875 return 0;
876}
877
878#else
879
880static int __init eeprom_read(struct lanai_dev *lanai)
881{
882 int i, address;
883 u8 data;
884 u32 tmp;
885#define set_config1(x) do { lanai->conf1 = x; conf1_write(lanai); \
886 } while (0)
887#define clock_h() set_config1(lanai->conf1 | CONFIG1_PROMCLK)
888#define clock_l() set_config1(lanai->conf1 &~ CONFIG1_PROMCLK)
889#define data_h() set_config1(lanai->conf1 | CONFIG1_PROMDATA)
890#define data_l() set_config1(lanai->conf1 &~ CONFIG1_PROMDATA)
891#define pre_read() do { data_h(); clock_h(); udelay(5); } while (0)
892#define read_pin() (reg_read(lanai, Status_Reg) & STATUS_PROMDATA)
893#define send_stop() do { data_l(); udelay(5); clock_h(); udelay(5); \
894 data_h(); udelay(5); } while (0)
895
896 data_h(); clock_h(); udelay(5);
897 for (address = 0; address < LANAI_EEPROM_SIZE; address++) {
898 data = (address << 1) | 1;
899
900 data_l(); udelay(5);
901 clock_l(); udelay(5);
902 for (i = 128; i != 0; i >>= 1) {
903 tmp = (lanai->conf1 & ~CONFIG1_PROMDATA) |
904 (data & i) ? CONFIG1_PROMDATA : 0;
905 if (lanai->conf1 != tmp) {
906 set_config1(tmp);
907 udelay(5);
908 }
909 clock_h(); udelay(5); clock_l(); udelay(5);
910 }
911
912 data_h(); clock_h(); udelay(5);
913 if (read_pin() != 0)
914 goto error;
915 clock_l(); udelay(5);
916
917 for (data = 0, i = 7; i >= 0; i--) {
918 data_h(); clock_h(); udelay(5);
919 data = (data << 1) | !!read_pin();
920 clock_l(); udelay(5);
921 }
922
923 data_h(); clock_h(); udelay(5);
924 if (read_pin() == 0)
925 goto error;
926 clock_l(); udelay(5);
927 send_stop();
928 lanai->eeprom[address] = data;
929 DPRINTK("EEPROM 0x%04X %02X\n",
930 (unsigned int) address, (unsigned int) data);
931 }
932 return 0;
933 error:
934 clock_l(); udelay(5);
935 send_stop();
936 printk(KERN_ERR DEV_LABEL "(itf %d): error reading EEPROM byte %d\n",
937 lanai->number, address);
938 return -EIO;
939#undef set_config1
940#undef clock_h
941#undef clock_l
942#undef data_h
943#undef data_l
944#undef pre_read
945#undef read_pin
946#undef send_stop
947}
948
949
950static inline u32 eeprom_be4(const struct lanai_dev *lanai, int address)
951{
952 return be32_to_cpup((u32 *) (&lanai->eeprom[address]));
953}
954
955
956static int __init eeprom_validate(struct lanai_dev *lanai)
957{
958 int i, s;
959 u32 v;
960 const u8 *e = lanai->eeprom;
961#ifdef DEBUG
962
963 for (i = EEPROM_COPYRIGHT;
964 i < (EEPROM_COPYRIGHT + EEPROM_COPYRIGHT_LEN); i++)
965 if (e[i] < 0x20 || e[i] > 0x7E)
966 break;
967 if ( i != EEPROM_COPYRIGHT &&
968 i != EEPROM_COPYRIGHT + EEPROM_COPYRIGHT_LEN && e[i] == '\0')
969 DPRINTK("eeprom: copyright = \"%s\"\n",
970 (char *) &e[EEPROM_COPYRIGHT]);
971 else
972 DPRINTK("eeprom: copyright not found\n");
973#endif
974
975 for (i = s = 0; i < EEPROM_CHECKSUM; i++)
976 s += e[i];
977 s &= 0xFF;
978 if (s != e[EEPROM_CHECKSUM]) {
979 printk(KERN_ERR DEV_LABEL "(itf %d): EEPROM checksum bad "
980 "(wanted 0x%02X, got 0x%02X)\n", lanai->number,
981 (unsigned int) s, (unsigned int) e[EEPROM_CHECKSUM]);
982 return -EIO;
983 }
984 s ^= 0xFF;
985 if (s != e[EEPROM_CHECKSUM_REV]) {
986 printk(KERN_ERR DEV_LABEL "(itf %d): EEPROM inverse checksum "
987 "bad (wanted 0x%02X, got 0x%02X)\n", lanai->number,
988 (unsigned int) s, (unsigned int) e[EEPROM_CHECKSUM_REV]);
989 return -EIO;
990 }
991
992 for (i = 0; i < 6; i++)
993 if ((e[EEPROM_MAC + i] ^ e[EEPROM_MAC_REV + i]) != 0xFF) {
994 printk(KERN_ERR DEV_LABEL
995 "(itf %d) : EEPROM MAC addresses don't match "
996 "(0x%02X, inverse 0x%02X)\n", lanai->number,
997 (unsigned int) e[EEPROM_MAC + i],
998 (unsigned int) e[EEPROM_MAC_REV + i]);
999 return -EIO;
1000 }
1001 DPRINTK("eeprom: MAC address = %02X:%02X:%02X:%02X:%02X:%02X\n",
1002 e[EEPROM_MAC + 0], e[EEPROM_MAC + 1], e[EEPROM_MAC + 2],
1003 e[EEPROM_MAC + 3], e[EEPROM_MAC + 4], e[EEPROM_MAC + 5]);
1004
1005 lanai->serialno = eeprom_be4(lanai, EEPROM_SERIAL);
1006 v = eeprom_be4(lanai, EEPROM_SERIAL_REV);
1007 if ((lanai->serialno ^ v) != 0xFFFFFFFF) {
1008 printk(KERN_ERR DEV_LABEL "(itf %d): EEPROM serial numbers "
1009 "don't match (0x%08X, inverse 0x%08X)\n", lanai->number,
1010 (unsigned int) lanai->serialno, (unsigned int) v);
1011 return -EIO;
1012 }
1013 DPRINTK("eeprom: Serial number = %d\n", (unsigned int) lanai->serialno);
1014
1015 lanai->magicno = eeprom_be4(lanai, EEPROM_MAGIC);
1016 v = eeprom_be4(lanai, EEPROM_MAGIC_REV);
1017 if ((lanai->magicno ^ v) != 0xFFFFFFFF) {
1018 printk(KERN_ERR DEV_LABEL "(itf %d): EEPROM magic numbers "
1019 "don't match (0x%08X, inverse 0x%08X)\n", lanai->number,
1020 lanai->magicno, v);
1021 return -EIO;
1022 }
1023 DPRINTK("eeprom: Magic number = 0x%08X\n", lanai->magicno);
1024 if (lanai->magicno != EEPROM_MAGIC_VALUE)
1025 printk(KERN_WARNING DEV_LABEL "(itf %d): warning - EEPROM "
1026 "magic not what expected (got 0x%08X, not 0x%08X)\n",
1027 lanai->number, (unsigned int) lanai->magicno,
1028 (unsigned int) EEPROM_MAGIC_VALUE);
1029 return 0;
1030}
1031
1032#endif
1033
1034static inline const u8 *eeprom_mac(const struct lanai_dev *lanai)
1035{
1036 return &lanai->eeprom[EEPROM_MAC];
1037}
1038
1039
1040
1041
1042#define INT_STATS (0x00000002)
1043#define INT_SOOL (0x00000004)
1044#define INT_LOCD (0x00000008)
1045#define INT_LED (0x00000010)
1046#define INT_GPIN (0x00000020)
1047#define INT_PING (0x00000040)
1048#define INT_WAKE (0x00000080)
1049#define INT_CBR0 (0x00000100)
1050#define INT_LOCK (0x00000200)
1051#define INT_MISMATCH (0x00000400)
1052#define INT_AAL0_STR (0x00000800)
1053#define INT_AAL0 (0x00001000)
1054#define INT_SERVICE (0x00002000)
1055#define INT_TABORTSENT (0x00004000)
1056#define INT_TABORTBM (0x00008000)
1057#define INT_TIMEOUTBM (0x00010000)
1058#define INT_PCIPARITY (0x00020000)
1059
1060
1061#define INT_ALL (0x0003FFFE)
1062#define INT_STATUS (0x0000003C)
1063#define INT_DMASHUT (0x00038000)
1064#define INT_SEGSHUT (0x00000700)
1065
1066static inline u32 intr_pending(const struct lanai_dev *lanai)
1067{
1068 return reg_read(lanai, IntStatusMasked_Reg);
1069}
1070
1071static inline void intr_enable(const struct lanai_dev *lanai, u32 i)
1072{
1073 reg_write(lanai, i, IntControlEna_Reg);
1074}
1075
1076static inline void intr_disable(const struct lanai_dev *lanai, u32 i)
1077{
1078 reg_write(lanai, i, IntControlDis_Reg);
1079}
1080
1081
1082
1083static void status_message(int itf, const char *name, int status)
1084{
1085 static const char *onoff[2] = { "off to on", "on to off" };
1086 printk(KERN_INFO DEV_LABEL "(itf %d): %s changed from %s\n",
1087 itf, name, onoff[!status]);
1088}
1089
1090static void lanai_check_status(struct lanai_dev *lanai)
1091{
1092 u32 new = reg_read(lanai, Status_Reg);
1093 u32 changes = new ^ lanai->status;
1094 lanai->status = new;
1095#define e(flag, name) \
1096 if (changes & flag) \
1097 status_message(lanai->number, name, new & flag)
1098 e(STATUS_SOOL, "SOOL");
1099 e(STATUS_LOCD, "LOCD");
1100 e(STATUS_LED, "LED");
1101 e(STATUS_GPIN, "GPIN");
1102#undef e
1103}
1104
1105static void pcistatus_got(int itf, const char *name)
1106{
1107 printk(KERN_INFO DEV_LABEL "(itf %d): PCI got %s error\n", itf, name);
1108}
1109
1110static void pcistatus_check(struct lanai_dev *lanai, int clearonly)
1111{
1112 u16 s;
1113 int result;
1114 result = pci_read_config_word(lanai->pci, PCI_STATUS, &s);
1115 if (result != PCIBIOS_SUCCESSFUL) {
1116 printk(KERN_ERR DEV_LABEL "(itf %d): can't read PCI_STATUS: "
1117 "%d\n", lanai->number, result);
1118 return;
1119 }
1120 s &= PCI_STATUS_DETECTED_PARITY | PCI_STATUS_SIG_SYSTEM_ERROR |
1121 PCI_STATUS_REC_MASTER_ABORT | PCI_STATUS_REC_TARGET_ABORT |
1122 PCI_STATUS_SIG_TARGET_ABORT | PCI_STATUS_PARITY;
1123 if (s == 0)
1124 return;
1125 result = pci_write_config_word(lanai->pci, PCI_STATUS, s);
1126 if (result != PCIBIOS_SUCCESSFUL)
1127 printk(KERN_ERR DEV_LABEL "(itf %d): can't write PCI_STATUS: "
1128 "%d\n", lanai->number, result);
1129 if (clearonly)
1130 return;
1131#define e(flag, name, stat) \
1132 if (s & flag) { \
1133 pcistatus_got(lanai->number, name); \
1134 ++lanai->stats.pcierr_##stat; \
1135 }
1136 e(PCI_STATUS_DETECTED_PARITY, "parity", parity_detect);
1137 e(PCI_STATUS_SIG_SYSTEM_ERROR, "signalled system", serr_set);
1138 e(PCI_STATUS_REC_MASTER_ABORT, "master", master_abort);
1139 e(PCI_STATUS_REC_TARGET_ABORT, "master target", m_target_abort);
1140 e(PCI_STATUS_SIG_TARGET_ABORT, "slave", s_target_abort);
1141 e(PCI_STATUS_PARITY, "master parity", master_parity);
1142#undef e
1143}
1144
1145
1146
1147
1148static inline int vcc_tx_space(const struct lanai_vcc *lvcc, int endptr)
1149{
1150 int r;
1151 r = endptr * 16;
1152 r -= ((unsigned long) lvcc->tx.buf.ptr) -
1153 ((unsigned long) lvcc->tx.buf.start);
1154 r -= 16;
1155 if (r < 0)
1156 r += lanai_buf_size(&lvcc->tx.buf);
1157 return r;
1158}
1159
1160
1161static inline int vcc_is_backlogged( struct lanai_vcc *lvcc)
1162{
1163 return !skb_queue_empty(&lvcc->tx.backlog);
1164}
1165
1166
1167#define DESCRIPTOR_MAGIC (0xD0000000)
1168#define DESCRIPTOR_AAL5 (0x00008000)
1169#define DESCRIPTOR_AAL5_STREAM (0x00004000)
1170#define DESCRIPTOR_CLP (0x00002000)
1171
1172
1173static inline void vcc_tx_add_aal5_descriptor(struct lanai_vcc *lvcc,
1174 u32 flags, int len)
1175{
1176 int pos;
1177 APRINTK((((unsigned long) lvcc->tx.buf.ptr) & 15) == 0,
1178 "vcc_tx_add_aal5_descriptor: bad ptr=%p\n", lvcc->tx.buf.ptr);
1179 lvcc->tx.buf.ptr += 4;
1180 pos = ((unsigned char *) lvcc->tx.buf.ptr) -
1181 (unsigned char *) lvcc->tx.buf.start;
1182 APRINTK((pos & ~0x0001FFF0) == 0,
1183 "vcc_tx_add_aal5_descriptor: bad pos (%d) before, vci=%d, "
1184 "start,ptr,end=%p,%p,%p\n", pos, lvcc->vci,
1185 lvcc->tx.buf.start, lvcc->tx.buf.ptr, lvcc->tx.buf.end);
1186 pos = (pos + len) & (lanai_buf_size(&lvcc->tx.buf) - 1);
1187 APRINTK((pos & ~0x0001FFF0) == 0,
1188 "vcc_tx_add_aal5_descriptor: bad pos (%d) after, vci=%d, "
1189 "start,ptr,end=%p,%p,%p\n", pos, lvcc->vci,
1190 lvcc->tx.buf.start, lvcc->tx.buf.ptr, lvcc->tx.buf.end);
1191 lvcc->tx.buf.ptr[-1] =
1192 cpu_to_le32(DESCRIPTOR_MAGIC | DESCRIPTOR_AAL5 |
1193 ((lvcc->tx.atmvcc->atm_options & ATM_ATMOPT_CLP) ?
1194 DESCRIPTOR_CLP : 0) | flags | pos >> 4);
1195 if (lvcc->tx.buf.ptr >= lvcc->tx.buf.end)
1196 lvcc->tx.buf.ptr = lvcc->tx.buf.start;
1197}
1198
1199
1200static inline void vcc_tx_add_aal5_trailer(struct lanai_vcc *lvcc,
1201 int len, int cpi, int uu)
1202{
1203 APRINTK((((unsigned long) lvcc->tx.buf.ptr) & 15) == 8,
1204 "vcc_tx_add_aal5_trailer: bad ptr=%p\n", lvcc->tx.buf.ptr);
1205 lvcc->tx.buf.ptr += 2;
1206 lvcc->tx.buf.ptr[-2] = cpu_to_be32((uu << 24) | (cpi << 16) | len);
1207 if (lvcc->tx.buf.ptr >= lvcc->tx.buf.end)
1208 lvcc->tx.buf.ptr = lvcc->tx.buf.start;
1209}
1210
1211static inline void vcc_tx_memcpy(struct lanai_vcc *lvcc,
1212 const unsigned char *src, int n)
1213{
1214 unsigned char *e;
1215 int m;
1216 e = ((unsigned char *) lvcc->tx.buf.ptr) + n;
1217 m = e - (unsigned char *) lvcc->tx.buf.end;
1218 if (m < 0)
1219 m = 0;
1220 memcpy(lvcc->tx.buf.ptr, src, n - m);
1221 if (m != 0) {
1222 memcpy(lvcc->tx.buf.start, src + n - m, m);
1223 e = ((unsigned char *) lvcc->tx.buf.start) + m;
1224 }
1225 lvcc->tx.buf.ptr = (u32 *) e;
1226}
1227
1228static inline void vcc_tx_memzero(struct lanai_vcc *lvcc, int n)
1229{
1230 unsigned char *e;
1231 int m;
1232 if (n == 0)
1233 return;
1234 e = ((unsigned char *) lvcc->tx.buf.ptr) + n;
1235 m = e - (unsigned char *) lvcc->tx.buf.end;
1236 if (m < 0)
1237 m = 0;
1238 memset(lvcc->tx.buf.ptr, 0, n - m);
1239 if (m != 0) {
1240 memset(lvcc->tx.buf.start, 0, m);
1241 e = ((unsigned char *) lvcc->tx.buf.start) + m;
1242 }
1243 lvcc->tx.buf.ptr = (u32 *) e;
1244}
1245
1246
1247static inline void lanai_endtx(struct lanai_dev *lanai,
1248 const struct lanai_vcc *lvcc)
1249{
1250 int i, ptr = ((unsigned char *) lvcc->tx.buf.ptr) -
1251 (unsigned char *) lvcc->tx.buf.start;
1252 APRINTK((ptr & ~0x0001FFF0) == 0,
1253 "lanai_endtx: bad ptr (%d), vci=%d, start,ptr,end=%p,%p,%p\n",
1254 ptr, lvcc->vci, lvcc->tx.buf.start, lvcc->tx.buf.ptr,
1255 lvcc->tx.buf.end);
1256
1257
1258
1259
1260
1261
1262
1263 spin_lock(&lanai->endtxlock);
1264
1265
1266
1267
1268
1269
1270 for (i = 0; reg_read(lanai, Status_Reg) & STATUS_BUTTBUSY; i++) {
1271 if (unlikely(i > 50)) {
1272 printk(KERN_ERR DEV_LABEL "(itf %d): butt register "
1273 "always busy!\n", lanai->number);
1274 break;
1275 }
1276 udelay(5);
1277 }
1278
1279
1280
1281
1282
1283 wmb();
1284 reg_write(lanai, (ptr << 12) | lvcc->vci, Butt_Reg);
1285 spin_unlock(&lanai->endtxlock);
1286}
1287
1288
1289
1290
1291
1292static void lanai_send_one_aal5(struct lanai_dev *lanai,
1293 struct lanai_vcc *lvcc, struct sk_buff *skb, int pdusize)
1294{
1295 int pad;
1296 APRINTK(pdusize == aal5_size(skb->len),
1297 "lanai_send_one_aal5: wrong size packet (%d != %d)\n",
1298 pdusize, aal5_size(skb->len));
1299 vcc_tx_add_aal5_descriptor(lvcc, 0, pdusize);
1300 pad = pdusize - skb->len - 8;
1301 APRINTK(pad >= 0, "pad is negative (%d)\n", pad);
1302 APRINTK(pad < 48, "pad is too big (%d)\n", pad);
1303 vcc_tx_memcpy(lvcc, skb->data, skb->len);
1304 vcc_tx_memzero(lvcc, pad);
1305 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
1306 lanai_endtx(lanai, lvcc);
1307 lanai_free_skb(lvcc->tx.atmvcc, skb);
1308 atomic_inc(&lvcc->tx.atmvcc->stats->tx);
1309}
1310
1311
1312static void vcc_tx_unqueue_aal5(struct lanai_dev *lanai,
1313 struct lanai_vcc *lvcc, int endptr)
1314{
1315 int n;
1316 struct sk_buff *skb;
1317 int space = vcc_tx_space(lvcc, endptr);
1318 APRINTK(vcc_is_backlogged(lvcc),
1319 "vcc_tx_unqueue() called with empty backlog (vci=%d)\n",
1320 lvcc->vci);
1321 while (space >= 64) {
1322 skb = skb_dequeue(&lvcc->tx.backlog);
1323 if (skb == NULL)
1324 goto no_backlog;
1325 n = aal5_size(skb->len);
1326 if (n + 16 > space) {
1327
1328 skb_queue_head(&lvcc->tx.backlog, skb);
1329 return;
1330 }
1331 lanai_send_one_aal5(lanai, lvcc, skb, n);
1332 space -= n + 16;
1333 }
1334 if (!vcc_is_backlogged(lvcc)) {
1335 no_backlog:
1336 __clear_bit(lvcc->vci, lanai->backlog_vccs);
1337 }
1338}
1339
1340
1341static void vcc_tx_aal5(struct lanai_dev *lanai, struct lanai_vcc *lvcc,
1342 struct sk_buff *skb)
1343{
1344 int space, n;
1345 if (vcc_is_backlogged(lvcc))
1346 goto queue_it;
1347 space = vcc_tx_space(lvcc,
1348 TXREADPTR_GET_PTR(cardvcc_read(lvcc, vcc_txreadptr)));
1349 n = aal5_size(skb->len);
1350 APRINTK(n + 16 >= 64, "vcc_tx_aal5: n too small (%d)\n", n);
1351 if (space < n + 16) {
1352 __set_bit(lvcc->vci, lanai->backlog_vccs);
1353 queue_it:
1354 skb_queue_tail(&lvcc->tx.backlog, skb);
1355 return;
1356 }
1357 lanai_send_one_aal5(lanai, lvcc, skb, n);
1358}
1359
1360static void vcc_tx_unqueue_aal0(struct lanai_dev *lanai,
1361 struct lanai_vcc *lvcc, int endptr)
1362{
1363 printk(KERN_INFO DEV_LABEL
1364 ": vcc_tx_unqueue_aal0: not implemented\n");
1365}
1366
1367static void vcc_tx_aal0(struct lanai_dev *lanai, struct lanai_vcc *lvcc,
1368 struct sk_buff *skb)
1369{
1370 printk(KERN_INFO DEV_LABEL ": vcc_tx_aal0: not implemented\n");
1371
1372 lanai_free_skb(lvcc->tx.atmvcc, skb);
1373}
1374
1375
1376
1377
1378static inline void vcc_rx_memcpy(unsigned char *dest,
1379 const struct lanai_vcc *lvcc, int n)
1380{
1381 int m = ((const unsigned char *) lvcc->rx.buf.ptr) + n -
1382 ((const unsigned char *) (lvcc->rx.buf.end));
1383 if (m < 0)
1384 m = 0;
1385 memcpy(dest, lvcc->rx.buf.ptr, n - m);
1386 memcpy(dest + n - m, lvcc->rx.buf.start, m);
1387
1388 barrier();
1389}
1390
1391
1392static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
1393{
1394 int size;
1395 struct sk_buff *skb;
1396 u32 *x, *end = &lvcc->rx.buf.start[endptr * 4];
1397 int n = ((unsigned long) end) - ((unsigned long) lvcc->rx.buf.ptr);
1398 if (n < 0)
1399 n += lanai_buf_size(&lvcc->rx.buf);
1400 APRINTK(n >= 0 && n < lanai_buf_size(&lvcc->rx.buf) && !(n & 15),
1401 "vcc_rx_aal5: n out of range (%d/%Zu)\n",
1402 n, lanai_buf_size(&lvcc->rx.buf));
1403
1404 if ((x = &end[-2]) < lvcc->rx.buf.start)
1405 x = &lvcc->rx.buf.end[-2];
1406
1407
1408
1409
1410 rmb();
1411 size = be32_to_cpup(x) & 0xffff;
1412 if (unlikely(n != aal5_size(size))) {
1413
1414 printk(KERN_INFO DEV_LABEL "(itf %d): Got bad AAL5 length "
1415 "on vci=%d - size=%d n=%d\n",
1416 lvcc->rx.atmvcc->dev->number, lvcc->vci, size, n);
1417 lvcc->stats.x.aal5.rx_badlen++;
1418 goto out;
1419 }
1420 skb = atm_alloc_charge(lvcc->rx.atmvcc, size, GFP_ATOMIC);
1421 if (unlikely(skb == NULL)) {
1422 lvcc->stats.rx_nomem++;
1423 goto out;
1424 }
1425 skb_put(skb, size);
1426 vcc_rx_memcpy(skb->data, lvcc, size);
1427 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
1428 do_gettimeofday(&skb->stamp);
1429 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
1430 atomic_inc(&lvcc->rx.atmvcc->stats->rx);
1431 out:
1432 lvcc->rx.buf.ptr = end;
1433 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
1434}
1435
1436static void vcc_rx_aal0(struct lanai_dev *lanai)
1437{
1438 printk(KERN_INFO DEV_LABEL ": vcc_rx_aal0: not implemented\n");
1439
1440
1441}
1442
1443
1444
1445
1446#if (NUM_VCI * BITS_PER_LONG) <= PAGE_SIZE
1447#define VCCTABLE_GETFREEPAGE
1448#else
1449#include <linux/vmalloc.h>
1450#endif
1451
1452static int __init vcc_table_allocate(struct lanai_dev *lanai)
1453{
1454#ifdef VCCTABLE_GETFREEPAGE
1455 APRINTK((lanai->num_vci) * sizeof(struct lanai_vcc *) <= PAGE_SIZE,
1456 "vcc table > PAGE_SIZE!");
1457 lanai->vccs = (struct lanai_vcc **) get_zeroed_page(GFP_KERNEL);
1458 return (lanai->vccs == NULL) ? -ENOMEM : 0;
1459#else
1460 int bytes = (lanai->num_vci) * sizeof(struct lanai_vcc *);
1461 lanai->vccs = (struct lanai_vcc **) vmalloc(bytes);
1462 if (unlikely(lanai->vccs == NULL))
1463 return -ENOMEM;
1464 memset(lanai->vccs, 0, bytes);
1465 return 0;
1466#endif
1467}
1468
1469static inline void vcc_table_deallocate(const struct lanai_dev *lanai)
1470{
1471#ifdef VCCTABLE_GETFREEPAGE
1472 free_page((unsigned long) lanai->vccs);
1473#else
1474 vfree(lanai->vccs);
1475#endif
1476}
1477
1478
1479static inline struct lanai_vcc *new_lanai_vcc(void)
1480{
1481 struct lanai_vcc *lvcc;
1482 lvcc = (struct lanai_vcc *) kmalloc(sizeof(*lvcc), GFP_KERNEL);
1483 if (likely(lvcc != NULL)) {
1484 lvcc->vbase = 0;
1485 lvcc->rx.atmvcc = lvcc->tx.atmvcc = NULL;
1486 lvcc->nref = 0;
1487 memset(&lvcc->stats, 0, sizeof lvcc->stats);
1488 lvcc->rx.buf.start = lvcc->tx.buf.start = NULL;
1489 skb_queue_head_init(&lvcc->tx.backlog);
1490#ifdef DEBUG
1491 lvcc->tx.unqueue = NULL;
1492 lvcc->vci = -1;
1493#endif
1494 }
1495 return lvcc;
1496}
1497
1498static int lanai_get_sized_buffer(struct lanai_dev *lanai,
1499 struct lanai_buffer *buf, int max_sdu, int multiplier,
1500 const char *name)
1501{
1502 int size;
1503 if (unlikely(max_sdu < 1))
1504 max_sdu = 1;
1505 max_sdu = aal5_size(max_sdu);
1506 size = (max_sdu + 16) * multiplier + 16;
1507 lanai_buf_allocate(buf, size, max_sdu + 32, lanai->pci);
1508 if (unlikely(buf->start == NULL))
1509 return -ENOMEM;
1510 if (unlikely(lanai_buf_size(buf) < size))
1511 printk(KERN_WARNING DEV_LABEL "(itf %d): wanted %d bytes "
1512 "for %s buffer, got only %Zu\n", lanai->number, size,
1513 name, lanai_buf_size(buf));
1514 DPRINTK("Allocated %Zu byte %s buffer\n", lanai_buf_size(buf), name);
1515 return 0;
1516}
1517
1518
1519static inline int lanai_setup_rx_vci_aal5(struct lanai_dev *lanai,
1520 struct lanai_vcc *lvcc, const struct atm_qos *qos)
1521{
1522 return lanai_get_sized_buffer(lanai, &lvcc->rx.buf,
1523 qos->rxtp.max_sdu, AAL5_RX_MULTIPLIER, "RX");
1524}
1525
1526
1527static int lanai_setup_tx_vci(struct lanai_dev *lanai, struct lanai_vcc *lvcc,
1528 const struct atm_qos *qos)
1529{
1530 int max_sdu, multiplier;
1531 if (qos->aal == ATM_AAL0) {
1532 lvcc->tx.unqueue = vcc_tx_unqueue_aal0;
1533 max_sdu = ATM_CELL_SIZE - 1;
1534 multiplier = AAL0_TX_MULTIPLIER;
1535 } else {
1536 lvcc->tx.unqueue = vcc_tx_unqueue_aal5;
1537 max_sdu = qos->txtp.max_sdu;
1538 multiplier = AAL5_TX_MULTIPLIER;
1539 }
1540 return lanai_get_sized_buffer(lanai, &lvcc->tx.buf, max_sdu,
1541 multiplier, "TX");
1542}
1543
1544static inline void host_vcc_bind(struct lanai_dev *lanai,
1545 struct lanai_vcc *lvcc, vci_t vci)
1546{
1547 if (lvcc->vbase != 0)
1548 return;
1549 DPRINTK("Binding vci %d\n", vci);
1550#ifdef USE_POWERDOWN
1551 if (lanai->nbound++ == 0) {
1552 DPRINTK("Coming out of powerdown\n");
1553 lanai->conf1 &= ~CONFIG1_POWERDOWN;
1554 conf1_write(lanai);
1555 conf2_write(lanai);
1556 }
1557#endif
1558 lvcc->vbase = cardvcc_addr(lanai, vci);
1559 lanai->vccs[lvcc->vci = vci] = lvcc;
1560}
1561
1562static inline void host_vcc_unbind(struct lanai_dev *lanai,
1563 struct lanai_vcc *lvcc)
1564{
1565 if (lvcc->vbase == 0)
1566 return;
1567 DPRINTK("Unbinding vci %d\n", lvcc->vci);
1568 lvcc->vbase = 0;
1569 lanai->vccs[lvcc->vci] = NULL;
1570#ifdef USE_POWERDOWN
1571 if (--lanai->nbound == 0) {
1572 DPRINTK("Going into powerdown\n");
1573 lanai->conf1 |= CONFIG1_POWERDOWN;
1574 conf1_write(lanai);
1575 }
1576#endif
1577}
1578
1579
1580
1581static void lanai_reset(struct lanai_dev *lanai)
1582{
1583 printk(KERN_CRIT DEV_LABEL "(itf %d): *NOT* reseting - not "
1584 "implemented\n", lanai->number);
1585
1586
1587
1588
1589
1590 reg_write(lanai, INT_ALL, IntAck_Reg);
1591 lanai->stats.card_reset++;
1592}
1593
1594
1595
1596
1597
1598
1599static int __init service_buffer_allocate(struct lanai_dev *lanai)
1600{
1601 lanai_buf_allocate(&lanai->service, SERVICE_ENTRIES * 4, 8,
1602 lanai->pci);
1603 if (unlikely(lanai->service.start == NULL))
1604 return -ENOMEM;
1605 DPRINTK("allocated service buffer at 0x%08lX, size %Zu(%d)\n",
1606 (unsigned long) lanai->service.start,
1607 lanai_buf_size(&lanai->service),
1608 lanai_buf_size_cardorder(&lanai->service));
1609
1610 reg_write(lanai, 0, ServWrite_Reg);
1611
1612 reg_write(lanai,
1613 SSTUFF_SET_SIZE(lanai_buf_size_cardorder(&lanai->service)) |
1614 SSTUFF_SET_ADDR(lanai->service.dmaaddr),
1615 ServiceStuff_Reg);
1616 return 0;
1617}
1618
1619static inline void service_buffer_deallocate(struct lanai_dev *lanai)
1620{
1621 lanai_buf_deallocate(&lanai->service, lanai->pci);
1622}
1623
1624
1625#define SERVICE_TX (0x80000000)
1626#define SERVICE_TRASH (0x40000000)
1627#define SERVICE_CRCERR (0x20000000)
1628#define SERVICE_CI (0x10000000)
1629#define SERVICE_CLP (0x08000000)
1630#define SERVICE_STREAM (0x04000000)
1631#define SERVICE_GET_VCI(x) (((x)>>16)&0x3FF)
1632#define SERVICE_GET_END(x) ((x)&0x1FFF)
1633
1634
1635
1636
1637static int handle_service(struct lanai_dev *lanai, u32 s)
1638{
1639 vci_t vci = SERVICE_GET_VCI(s);
1640 struct lanai_vcc *lvcc;
1641 read_lock(&vcc_sklist_lock);
1642 lvcc = lanai->vccs[vci];
1643 if (unlikely(lvcc == NULL)) {
1644 read_unlock(&vcc_sklist_lock);
1645 DPRINTK("(itf %d) got service entry 0x%X for nonexistent "
1646 "vcc %d\n", lanai->number, (unsigned int) s, vci);
1647 if (s & SERVICE_TX)
1648 lanai->stats.service_notx++;
1649 else
1650 lanai->stats.service_norx++;
1651 return 0;
1652 }
1653 if (s & SERVICE_TX) {
1654 if (unlikely(lvcc->tx.atmvcc == NULL)) {
1655 read_unlock(&vcc_sklist_lock);
1656 DPRINTK("(itf %d) got service entry 0x%X for non-TX "
1657 "vcc %d\n", lanai->number, (unsigned int) s, vci);
1658 lanai->stats.service_notx++;
1659 return 0;
1660 }
1661 __set_bit(vci, lanai->transmit_ready);
1662 lvcc->tx.endptr = SERVICE_GET_END(s);
1663 read_unlock(&vcc_sklist_lock);
1664 return 1;
1665 }
1666 if (unlikely(lvcc->rx.atmvcc == NULL)) {
1667 read_unlock(&vcc_sklist_lock);
1668 DPRINTK("(itf %d) got service entry 0x%X for non-RX "
1669 "vcc %d\n", lanai->number, (unsigned int) s, vci);
1670 lanai->stats.service_norx++;
1671 return 0;
1672 }
1673 if (unlikely(lvcc->rx.atmvcc->qos.aal != ATM_AAL5)) {
1674 read_unlock(&vcc_sklist_lock);
1675 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
1676 "vcc %d\n", lanai->number, (unsigned int) s, vci);
1677 lanai->stats.service_rxnotaal5++;
1678 atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
1679 return 0;
1680 }
1681 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
1682 vcc_rx_aal5(lvcc, SERVICE_GET_END(s));
1683 read_unlock(&vcc_sklist_lock);
1684 return 0;
1685 }
1686 if (s & SERVICE_TRASH) {
1687 int bytes;
1688 read_unlock(&vcc_sklist_lock);
1689 DPRINTK("got trashed rx pdu on vci %d\n", vci);
1690 atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
1691 lvcc->stats.x.aal5.service_trash++;
1692 bytes = (SERVICE_GET_END(s) * 16) -
1693 (((unsigned long) lvcc->rx.buf.ptr) -
1694 ((unsigned long) lvcc->rx.buf.start)) + 47;
1695 if (bytes < 0)
1696 bytes += lanai_buf_size(&lvcc->rx.buf);
1697 lanai->stats.ovfl_trash += (bytes / 48);
1698 return 0;
1699 }
1700 if (s & SERVICE_STREAM) {
1701 read_unlock(&vcc_sklist_lock);
1702 atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
1703 lvcc->stats.x.aal5.service_stream++;
1704 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
1705 "PDU on VCI %d!\n", lanai->number, vci);
1706 lanai_reset(lanai);
1707 return 0;
1708 }
1709 DPRINTK("got rx crc error on vci %d\n", vci);
1710 atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
1711 lvcc->stats.x.aal5.service_rxcrc++;
1712 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
1713 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
1714 read_unlock(&vcc_sklist_lock);
1715 return 0;
1716}
1717
1718
1719static void iter_transmit(struct lanai_dev *lanai, vci_t vci)
1720{
1721 struct lanai_vcc *lvcc = lanai->vccs[vci];
1722 if (vcc_is_backlogged(lvcc))
1723 lvcc->tx.unqueue(lanai, lvcc, lvcc->tx.endptr);
1724}
1725
1726
1727
1728
1729
1730static void run_service(struct lanai_dev *lanai)
1731{
1732 int ntx = 0;
1733 u32 wreg = reg_read(lanai, ServWrite_Reg);
1734 const u32 *end = lanai->service.start + wreg;
1735 while (lanai->service.ptr != end) {
1736 ntx += handle_service(lanai,
1737 le32_to_cpup(lanai->service.ptr++));
1738 if (lanai->service.ptr >= lanai->service.end)
1739 lanai->service.ptr = lanai->service.start;
1740 }
1741 reg_write(lanai, wreg, ServRead_Reg);
1742 if (ntx != 0) {
1743 read_lock(&vcc_sklist_lock);
1744 vci_bitfield_iterate(lanai, lanai->transmit_ready,
1745 iter_transmit);
1746 bitmap_zero(lanai->transmit_ready, NUM_VCI);
1747 read_unlock(&vcc_sklist_lock);
1748 }
1749}
1750
1751
1752
1753static void get_statistics(struct lanai_dev *lanai)
1754{
1755 u32 statreg = reg_read(lanai, Statistics_Reg);
1756 lanai->stats.atm_ovfl += STATS_GET_FIFO_OVFL(statreg);
1757 lanai->stats.hec_err += STATS_GET_HEC_ERR(statreg);
1758 lanai->stats.vci_trash += STATS_GET_BAD_VCI(statreg);
1759 lanai->stats.ovfl_trash += STATS_GET_BUF_OVFL(statreg);
1760}
1761
1762
1763
1764#ifndef DEBUG_RW
1765
1766static void iter_dequeue(struct lanai_dev *lanai, vci_t vci)
1767{
1768 struct lanai_vcc *lvcc = lanai->vccs[vci];
1769 int endptr;
1770 if (lvcc == NULL || lvcc->tx.atmvcc == NULL ||
1771 !vcc_is_backlogged(lvcc)) {
1772 __clear_bit(vci, lanai->backlog_vccs);
1773 return;
1774 }
1775 endptr = TXREADPTR_GET_PTR(cardvcc_read(lvcc, vcc_txreadptr));
1776 lvcc->tx.unqueue(lanai, lvcc, endptr);
1777}
1778#endif
1779
1780static void lanai_timed_poll(unsigned long arg)
1781{
1782 struct lanai_dev *lanai = (struct lanai_dev *) arg;
1783#ifndef DEBUG_RW
1784 unsigned long flags;
1785#ifdef USE_POWERDOWN
1786 if (lanai->conf1 & CONFIG1_POWERDOWN)
1787 return;
1788#endif
1789 local_irq_save(flags);
1790
1791 if (spin_trylock(&lanai->servicelock)) {
1792 run_service(lanai);
1793 spin_unlock(&lanai->servicelock);
1794 }
1795
1796
1797 read_lock(&vcc_sklist_lock);
1798 vci_bitfield_iterate(lanai, lanai->backlog_vccs, iter_dequeue);
1799 read_unlock(&vcc_sklist_lock);
1800 local_irq_restore(flags);
1801
1802 get_statistics(lanai);
1803#endif
1804 mod_timer(&lanai->timer, jiffies + LANAI_POLL_PERIOD);
1805}
1806
1807static inline void lanai_timed_poll_start(struct lanai_dev *lanai)
1808{
1809 init_timer(&lanai->timer);
1810 lanai->timer.expires = jiffies + LANAI_POLL_PERIOD;
1811 lanai->timer.data = (unsigned long) lanai;
1812 lanai->timer.function = lanai_timed_poll;
1813 add_timer(&lanai->timer);
1814}
1815
1816static inline void lanai_timed_poll_stop(struct lanai_dev *lanai)
1817{
1818 del_timer_sync(&lanai->timer);
1819}
1820
1821
1822
1823static inline void lanai_int_1(struct lanai_dev *lanai, u32 reason)
1824{
1825 u32 ack = 0;
1826 if (reason & INT_SERVICE) {
1827 ack = INT_SERVICE;
1828 spin_lock(&lanai->servicelock);
1829 run_service(lanai);
1830 spin_unlock(&lanai->servicelock);
1831 }
1832 if (reason & (INT_AAL0_STR | INT_AAL0)) {
1833 ack |= reason & (INT_AAL0_STR | INT_AAL0);
1834 vcc_rx_aal0(lanai);
1835 }
1836
1837 if (ack == reason)
1838 goto done;
1839 if (reason & INT_STATS) {
1840 reason &= ~INT_STATS;
1841 get_statistics(lanai);
1842 }
1843 if (reason & INT_STATUS) {
1844 ack |= reason & INT_STATUS;
1845 lanai_check_status(lanai);
1846 }
1847 if (unlikely(reason & INT_DMASHUT)) {
1848 printk(KERN_ERR DEV_LABEL "(itf %d): driver error - DMA "
1849 "shutdown, reason=0x%08X, address=0x%08X\n",
1850 lanai->number, (unsigned int) (reason & INT_DMASHUT),
1851 (unsigned int) reg_read(lanai, DMA_Addr_Reg));
1852 if (reason & INT_TABORTBM) {
1853 lanai_reset(lanai);
1854 return;
1855 }
1856 ack |= (reason & INT_DMASHUT);
1857 printk(KERN_ERR DEV_LABEL "(itf %d): re-enabling DMA\n",
1858 lanai->number);
1859 conf1_write(lanai);
1860 lanai->stats.dma_reenable++;
1861 pcistatus_check(lanai, 0);
1862 }
1863 if (unlikely(reason & INT_TABORTSENT)) {
1864 ack |= (reason & INT_TABORTSENT);
1865 printk(KERN_ERR DEV_LABEL "(itf %d): sent PCI target abort\n",
1866 lanai->number);
1867 pcistatus_check(lanai, 0);
1868 }
1869 if (unlikely(reason & INT_SEGSHUT)) {
1870 printk(KERN_ERR DEV_LABEL "(itf %d): driver error - "
1871 "segmentation shutdown, reason=0x%08X\n", lanai->number,
1872 (unsigned int) (reason & INT_SEGSHUT));
1873 lanai_reset(lanai);
1874 return;
1875 }
1876 if (unlikely(reason & (INT_PING | INT_WAKE))) {
1877 printk(KERN_ERR DEV_LABEL "(itf %d): driver error - "
1878 "unexpected interrupt 0x%08X, resetting\n",
1879 lanai->number,
1880 (unsigned int) (reason & (INT_PING | INT_WAKE)));
1881 lanai_reset(lanai);
1882 return;
1883 }
1884#ifdef DEBUG
1885 if (unlikely(ack != reason)) {
1886 DPRINTK("unacked ints: 0x%08X\n",
1887 (unsigned int) (reason & ~ack));
1888 ack = reason;
1889 }
1890#endif
1891 done:
1892 if (ack != 0)
1893 reg_write(lanai, ack, IntAck_Reg);
1894}
1895
1896static irqreturn_t lanai_int(int irq, void *devid, struct pt_regs *regs)
1897{
1898 struct lanai_dev *lanai = (struct lanai_dev *) devid;
1899 u32 reason;
1900
1901 (void) irq; (void) regs;
1902
1903#ifdef USE_POWERDOWN
1904
1905
1906
1907
1908
1909 if (unlikely(lanai->conf1 & CONFIG1_POWERDOWN))
1910 return IRQ_NONE;
1911#endif
1912
1913 reason = intr_pending(lanai);
1914 if (reason == 0)
1915 return IRQ_NONE;
1916
1917 do {
1918 if (unlikely(reason == 0xFFFFFFFF))
1919 break;
1920 lanai_int_1(lanai, reason);
1921 reason = intr_pending(lanai);
1922 } while (reason != 0);
1923
1924 return IRQ_HANDLED;
1925}
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938static int check_board_id_and_rev(const char *name, u32 val, int *revp)
1939{
1940 DPRINTK("%s says board_id=%d, board_rev=%d\n", name,
1941 (int) RESET_GET_BOARD_ID(val),
1942 (int) RESET_GET_BOARD_REV(val));
1943 if (RESET_GET_BOARD_ID(val) != BOARD_ID_LANAI256) {
1944 printk(KERN_ERR DEV_LABEL ": Found %s board-id %d -- not a "
1945 "Lanai 25.6\n", name, (int) RESET_GET_BOARD_ID(val));
1946 return -ENODEV;
1947 }
1948 if (revp != NULL)
1949 *revp = RESET_GET_BOARD_REV(val);
1950 return 0;
1951}
1952
1953
1954
1955static int __init lanai_pci_start(struct lanai_dev *lanai)
1956{
1957 struct pci_dev *pci = lanai->pci;
1958 int result;
1959 u16 w;
1960
1961 if (pci_enable_device(pci) != 0) {
1962 printk(KERN_ERR DEV_LABEL "(itf %d): can't enable "
1963 "PCI device", lanai->number);
1964 return -ENXIO;
1965 }
1966 pci_set_master(pci);
1967 if (pci_set_dma_mask(pci, 0xFFFFFFFF) != 0) {
1968 printk(KERN_WARNING DEV_LABEL
1969 "(itf %d): No suitable DMA available.\n", lanai->number);
1970 return -EBUSY;
1971 }
1972 if (pci_set_consistent_dma_mask(pci, 0xFFFFFFFF) != 0) {
1973 printk(KERN_WARNING DEV_LABEL
1974 "(itf %d): No suitable DMA available.\n", lanai->number);
1975 return -EBUSY;
1976 }
1977
1978 result = pci_read_config_byte(pci, PCI_REVISION_ID,
1979 &lanai->pci_revision);
1980 if (result != PCIBIOS_SUCCESSFUL) {
1981 printk(KERN_ERR DEV_LABEL "(itf %d): can't read "
1982 "PCI_REVISION_ID: %d\n", lanai->number, result);
1983 return -EINVAL;
1984 }
1985 result = pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &w);
1986 if (result != PCIBIOS_SUCCESSFUL) {
1987 printk(KERN_ERR DEV_LABEL "(itf %d): can't read "
1988 "PCI_SUBSYSTEM_ID: %d\n", lanai->number, result);
1989 return -EINVAL;
1990 }
1991 result = check_board_id_and_rev("PCI", w, NULL);
1992 if (result != 0)
1993 return result;
1994
1995 result = pci_write_config_byte(pci, PCI_LATENCY_TIMER, 0);
1996 if (result != PCIBIOS_SUCCESSFUL) {
1997 printk(KERN_ERR DEV_LABEL "(itf %d): can't write "
1998 "PCI_LATENCY_TIMER: %d\n", lanai->number, result);
1999 return -EINVAL;
2000 }
2001 pcistatus_check(lanai, 1);
2002 pcistatus_check(lanai, 0);
2003 return 0;
2004}
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014static inline int vci0_is_ok(struct lanai_dev *lanai,
2015 const struct atm_qos *qos)
2016{
2017 if (qos->txtp.traffic_class == ATM_CBR || qos->aal == ATM_AAL0)
2018 return 0;
2019 if (qos->rxtp.traffic_class != ATM_NONE) {
2020 if (lanai->naal0 != 0)
2021 return 0;
2022 lanai->conf2 |= CONFIG2_VCI0_NORMAL;
2023 conf2_write_if_powerup(lanai);
2024 }
2025 return 1;
2026}
2027
2028
2029
2030
2031static int vci_is_ok(struct lanai_dev *lanai, vci_t vci,
2032 const struct atm_vcc *atmvcc)
2033{
2034 const struct atm_qos *qos = &atmvcc->qos;
2035 const struct lanai_vcc *lvcc = lanai->vccs[vci];
2036 if (vci == 0 && !vci0_is_ok(lanai, qos))
2037 return 0;
2038 if (unlikely(lvcc != NULL)) {
2039 if (qos->rxtp.traffic_class != ATM_NONE &&
2040 lvcc->rx.atmvcc != NULL && lvcc->rx.atmvcc != atmvcc)
2041 return 0;
2042 if (qos->txtp.traffic_class != ATM_NONE &&
2043 lvcc->tx.atmvcc != NULL && lvcc->tx.atmvcc != atmvcc)
2044 return 0;
2045 if (qos->txtp.traffic_class == ATM_CBR &&
2046 lanai->cbrvcc != NULL && lanai->cbrvcc != atmvcc)
2047 return 0;
2048 }
2049 if (qos->aal == ATM_AAL0 && lanai->naal0 == 0 &&
2050 qos->rxtp.traffic_class != ATM_NONE) {
2051 const struct lanai_vcc *vci0 = lanai->vccs[0];
2052 if (vci0 != NULL && vci0->rx.atmvcc != NULL)
2053 return 0;
2054 lanai->conf2 &= ~CONFIG2_VCI0_NORMAL;
2055 conf2_write_if_powerup(lanai);
2056 }
2057 return 1;
2058}
2059
2060static int lanai_normalize_ci(struct lanai_dev *lanai,
2061 const struct atm_vcc *atmvcc, short *vpip, vci_t *vcip)
2062{
2063 switch (*vpip) {
2064 case ATM_VPI_ANY:
2065 *vpip = 0;
2066
2067 case 0:
2068 break;
2069 default:
2070 return -EADDRINUSE;
2071 }
2072 switch (*vcip) {
2073 case ATM_VCI_ANY:
2074 for (*vcip = ATM_NOT_RSV_VCI; *vcip < lanai->num_vci;
2075 (*vcip)++)
2076 if (vci_is_ok(lanai, *vcip, atmvcc))
2077 return 0;
2078 return -EADDRINUSE;
2079 default:
2080 if (*vcip >= lanai->num_vci || *vcip < 0 ||
2081 !vci_is_ok(lanai, *vcip, atmvcc))
2082 return -EADDRINUSE;
2083 }
2084 return 0;
2085}
2086
2087
2088
2089
2090
2091
2092
2093
2094#define CBRICG_FRAC_BITS (4)
2095#define CBRICG_MAX (2046 << CBRICG_FRAC_BITS)
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112static int pcr_to_cbricg( struct atm_qos *qos)
2113{
2114 int rounddown = 0;
2115 int x, icg, pcr = atm_pcr_goal(&qos->txtp);
2116 if (pcr == 0)
2117 return 0;
2118 if (pcr < 0) {
2119 rounddown = 1;
2120 pcr = -pcr;
2121 }
2122 x = pcr * 27;
2123 icg = (3125 << (9 + CBRICG_FRAC_BITS)) - (x << CBRICG_FRAC_BITS);
2124 if (rounddown)
2125 icg += x - 1;
2126 icg /= x;
2127 if (icg > CBRICG_MAX)
2128 icg = CBRICG_MAX;
2129 DPRINTK("pcr_to_cbricg: pcr=%d rounddown=%c icg=%d\n",
2130 pcr, rounddown ? 'Y' : 'N', icg);
2131 return icg;
2132}
2133
2134static inline void lanai_cbr_setup(struct lanai_dev *lanai)
2135{
2136 reg_write(lanai, pcr_to_cbricg(&lanai->cbrvcc->qos), CBR_ICG_Reg);
2137 reg_write(lanai, lanai->cbrvcc->vci, CBR_PTR_Reg);
2138 lanai->conf2 |= CONFIG2_CBR_ENABLE;
2139 conf2_write(lanai);
2140}
2141
2142static inline void lanai_cbr_shutdown(struct lanai_dev *lanai)
2143{
2144 lanai->conf2 &= ~CONFIG2_CBR_ENABLE;
2145 conf2_write(lanai);
2146}
2147
2148
2149
2150
2151static int __init lanai_dev_open(struct atm_dev *atmdev)
2152{
2153 struct lanai_dev *lanai = (struct lanai_dev *) atmdev->dev_data;
2154 unsigned long raw_base;
2155 int result;
2156
2157 DPRINTK("In lanai_dev_open()\n");
2158
2159 lanai->number = atmdev->number;
2160 lanai->num_vci = NUM_VCI;
2161 bitmap_zero(lanai->backlog_vccs, NUM_VCI);
2162 bitmap_zero(lanai->transmit_ready, NUM_VCI);
2163 lanai->naal0 = 0;
2164#ifdef USE_POWERDOWN
2165 lanai->nbound = 0;
2166#endif
2167 lanai->cbrvcc = NULL;
2168 memset(&lanai->stats, 0, sizeof lanai->stats);
2169 spin_lock_init(&lanai->endtxlock);
2170 spin_lock_init(&lanai->servicelock);
2171 atmdev->ci_range.vpi_bits = 0;
2172 atmdev->ci_range.vci_bits = 0;
2173 while (1 << atmdev->ci_range.vci_bits < lanai->num_vci)
2174 atmdev->ci_range.vci_bits++;
2175 atmdev->link_rate = ATM_25_PCR;
2176
2177
2178 if ((result = lanai_pci_start(lanai)) != 0)
2179 goto error;
2180 raw_base = (bus_addr_t) lanai->pci->resource[0].start;
2181 lanai->base = (bus_addr_t) ioremap(raw_base, LANAI_MAPPING_SIZE);
2182 if (lanai->base == 0) {
2183 printk(KERN_ERR DEV_LABEL ": couldn't remap I/O space\n");
2184 goto error_pci;
2185 }
2186
2187 reset_board(lanai);
2188 lanai->conf1 = reg_read(lanai, Config1_Reg);
2189 lanai->conf1 &= ~(CONFIG1_GPOUT1 | CONFIG1_POWERDOWN |
2190 CONFIG1_MASK_LEDMODE);
2191 lanai->conf1 |= CONFIG1_SET_LEDMODE(LEDMODE_NOT_SOOL);
2192 reg_write(lanai, lanai->conf1 | CONFIG1_GPOUT1, Config1_Reg);
2193 udelay(1000);
2194 conf1_write(lanai);
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205 result = check_board_id_and_rev("register",
2206 reg_read(lanai, Reset_Reg), &lanai->board_rev);
2207 if (result != 0)
2208 goto error_unmap;
2209
2210
2211 if ((result = eeprom_read(lanai)) != 0)
2212 goto error_unmap;
2213 if ((result = eeprom_validate(lanai)) != 0)
2214 goto error_unmap;
2215
2216
2217 reg_write(lanai, lanai->conf1 | CONFIG1_GPOUT1, Config1_Reg);
2218 udelay(1000);
2219 conf1_write(lanai);
2220
2221 lanai->conf1 |= (CONFIG1_GPOUT2 | CONFIG1_GPOUT3 | CONFIG1_DMA_ENABLE);
2222 conf1_write(lanai);
2223
2224
2225 if ((result = sram_test_and_clear(lanai)) != 0)
2226 goto error_unmap;
2227
2228
2229 lanai->conf1 |= CONFIG1_DMA_ENABLE;
2230 conf1_write(lanai);
2231 if ((result = service_buffer_allocate(lanai)) != 0)
2232 goto error_unmap;
2233 if ((result = vcc_table_allocate(lanai)) != 0)
2234 goto error_service;
2235 lanai->conf2 = (lanai->num_vci >= 512 ? CONFIG2_HOWMANY : 0) |
2236 CONFIG2_HEC_DROP | CONFIG2_PTI7_MODE;
2237 conf2_write(lanai);
2238 reg_write(lanai, TX_FIFO_DEPTH, TxDepth_Reg);
2239 reg_write(lanai, 0, CBR_ICG_Reg);
2240 if ((result = request_irq(lanai->pci->irq, lanai_int, SA_SHIRQ,
2241 DEV_LABEL, lanai)) != 0) {
2242 printk(KERN_ERR DEV_LABEL ": can't allocate interrupt\n");
2243 goto error_vcctable;
2244 }
2245 mb();
2246 intr_enable(lanai, INT_ALL & ~(INT_PING | INT_WAKE));
2247
2248 lanai->conf1 = (lanai->conf1 & ~CONFIG1_MASK_LOOPMODE) |
2249 CONFIG1_SET_LOOPMODE(LOOPMODE_NORMAL) |
2250 CONFIG1_GPOUT2 | CONFIG1_GPOUT3;
2251 conf1_write(lanai);
2252 lanai->status = reg_read(lanai, Status_Reg);
2253
2254#ifdef USE_POWERDOWN
2255 lanai->conf1 |= CONFIG1_POWERDOWN;
2256 conf1_write(lanai);
2257#endif
2258 memcpy(atmdev->esi, eeprom_mac(lanai), ESI_LEN);
2259 lanai_timed_poll_start(lanai);
2260 printk(KERN_NOTICE DEV_LABEL "(itf %d): rev.%d, base=0x%lx, irq=%u "
2261 "(%02X-%02X-%02X-%02X-%02X-%02X)\n", lanai->number,
2262 (int) lanai->pci_revision, (unsigned long) lanai->base,
2263 lanai->pci->irq,
2264 atmdev->esi[0], atmdev->esi[1], atmdev->esi[2],
2265 atmdev->esi[3], atmdev->esi[4], atmdev->esi[5]);
2266 printk(KERN_NOTICE DEV_LABEL "(itf %d): LANAI%s, serialno=%u(0x%X), "
2267 "board_rev=%d\n", lanai->number,
2268 lanai->type==lanai2 ? "2" : "HB", (unsigned int) lanai->serialno,
2269 (unsigned int) lanai->serialno, lanai->board_rev);
2270 return 0;
2271
2272 error_vcctable:
2273 vcc_table_deallocate(lanai);
2274 error_service:
2275 service_buffer_deallocate(lanai);
2276 error_unmap:
2277 reset_board(lanai);
2278#ifdef USE_POWERDOWN
2279 lanai->conf1 = reg_read(lanai, Config1_Reg) | CONFIG1_POWERDOWN;
2280 conf1_write(lanai);
2281#endif
2282 iounmap((void *) lanai->base);
2283 error_pci:
2284 pci_disable_device(lanai->pci);
2285 error:
2286 return result;
2287}
2288
2289
2290
2291
2292static void lanai_dev_close(struct atm_dev *atmdev)
2293{
2294 struct lanai_dev *lanai = (struct lanai_dev *) atmdev->dev_data;
2295 printk(KERN_INFO DEV_LABEL "(itf %d): shutting down interface\n",
2296 lanai->number);
2297 lanai_timed_poll_stop(lanai);
2298#ifdef USE_POWERDOWN
2299 lanai->conf1 = reg_read(lanai, Config1_Reg) & ~CONFIG1_POWERDOWN;
2300 conf1_write(lanai);
2301#endif
2302 intr_disable(lanai, INT_ALL);
2303 free_irq(lanai->pci->irq, lanai);
2304 reset_board(lanai);
2305#ifdef USE_POWERDOWN
2306 lanai->conf1 |= CONFIG1_POWERDOWN;
2307 conf1_write(lanai);
2308#endif
2309 pci_disable_device(lanai->pci);
2310 vcc_table_deallocate(lanai);
2311 service_buffer_deallocate(lanai);
2312 iounmap((void *) lanai->base);
2313 kfree(lanai);
2314}
2315
2316
2317static void lanai_close(struct atm_vcc *atmvcc)
2318{
2319 struct lanai_vcc *lvcc = (struct lanai_vcc *) atmvcc->dev_data;
2320 struct lanai_dev *lanai = (struct lanai_dev *) atmvcc->dev->dev_data;
2321 if (lvcc == NULL)
2322 return;
2323 clear_bit(ATM_VF_READY, &atmvcc->flags);
2324 clear_bit(ATM_VF_PARTIAL, &atmvcc->flags);
2325 if (lvcc->rx.atmvcc == atmvcc) {
2326 lanai_shutdown_rx_vci(lvcc);
2327 if (atmvcc->qos.aal == ATM_AAL0) {
2328 if (--lanai->naal0 <= 0)
2329 aal0_buffer_free(lanai);
2330 } else
2331 lanai_buf_deallocate(&lvcc->rx.buf, lanai->pci);
2332 lvcc->rx.atmvcc = NULL;
2333 }
2334 if (lvcc->tx.atmvcc == atmvcc) {
2335 if (atmvcc == lanai->cbrvcc) {
2336 if (lvcc->vbase != 0)
2337 lanai_cbr_shutdown(lanai);
2338 lanai->cbrvcc = NULL;
2339 }
2340 lanai_shutdown_tx_vci(lanai, lvcc);
2341 lanai_buf_deallocate(&lvcc->tx.buf, lanai->pci);
2342 lvcc->tx.atmvcc = NULL;
2343 }
2344 if (--lvcc->nref == 0) {
2345 host_vcc_unbind(lanai, lvcc);
2346 kfree(lvcc);
2347 }
2348 atmvcc->dev_data = NULL;
2349 clear_bit(ATM_VF_ADDR, &atmvcc->flags);
2350}
2351
2352
2353static int lanai_open(struct atm_vcc *atmvcc)
2354{
2355 struct lanai_dev *lanai;
2356 struct lanai_vcc *lvcc;
2357 int result = 0;
2358 int vci = atmvcc->vci;
2359 short vpi = atmvcc->vpi;
2360
2361 if ((test_bit(ATM_VF_PARTIAL, &atmvcc->flags)) ||
2362 (vpi == ATM_VPI_UNSPEC) || (vci == ATM_VCI_UNSPEC))
2363 return -EINVAL;
2364 lanai = (struct lanai_dev *) atmvcc->dev->dev_data;
2365 result = lanai_normalize_ci(lanai, atmvcc, &vpi, &vci);
2366 if (unlikely(result != 0))
2367 goto out;
2368 set_bit(ATM_VF_ADDR, &atmvcc->flags);
2369 if (atmvcc->qos.aal != ATM_AAL0 && atmvcc->qos.aal != ATM_AAL5)
2370 return -EINVAL;
2371 DPRINTK(DEV_LABEL "(itf %d): open %d.%d\n", lanai->number,
2372 (int) vpi, vci);
2373 lvcc = lanai->vccs[vci];
2374 if (lvcc == NULL) {
2375 lvcc = new_lanai_vcc();
2376 if (unlikely(lvcc == NULL))
2377 return -ENOMEM;
2378 atmvcc->dev_data = lvcc;
2379 }
2380 lvcc->nref++;
2381 if (atmvcc->qos.rxtp.traffic_class != ATM_NONE) {
2382 APRINTK(lvcc->rx.atmvcc == NULL, "rx.atmvcc!=NULL, vci=%d\n",
2383 vci);
2384 if (atmvcc->qos.aal == ATM_AAL0) {
2385 if (lanai->naal0 == 0)
2386 result = aal0_buffer_allocate(lanai);
2387 } else
2388 result = lanai_setup_rx_vci_aal5(
2389 lanai, lvcc, &atmvcc->qos);
2390 if (unlikely(result != 0))
2391 goto out_free;
2392 lvcc->rx.atmvcc = atmvcc;
2393 lvcc->stats.rx_nomem = 0;
2394 lvcc->stats.x.aal5.rx_badlen = 0;
2395 lvcc->stats.x.aal5.service_trash = 0;
2396 lvcc->stats.x.aal5.service_stream = 0;
2397 lvcc->stats.x.aal5.service_rxcrc = 0;
2398 if (atmvcc->qos.aal == ATM_AAL0)
2399 lanai->naal0++;
2400 }
2401 if (atmvcc->qos.txtp.traffic_class != ATM_NONE) {
2402 APRINTK(lvcc->tx.atmvcc == NULL, "tx.atmvcc!=NULL, vci=%d\n",
2403 vci);
2404 result = lanai_setup_tx_vci(lanai, lvcc, &atmvcc->qos);
2405 if (unlikely(result != 0))
2406 goto out_free;
2407 lvcc->tx.atmvcc = atmvcc;
2408 if (atmvcc->qos.txtp.traffic_class == ATM_CBR) {
2409 APRINTK(lanai->cbrvcc == NULL,
2410 "cbrvcc!=NULL, vci=%d\n", vci);
2411 lanai->cbrvcc = atmvcc;
2412 }
2413 }
2414 host_vcc_bind(lanai, lvcc, vci);
2415
2416
2417
2418
2419 wmb();
2420 if (atmvcc == lvcc->rx.atmvcc)
2421 host_vcc_start_rx(lvcc);
2422 if (atmvcc == lvcc->tx.atmvcc) {
2423 host_vcc_start_tx(lvcc);
2424 if (lanai->cbrvcc == atmvcc)
2425 lanai_cbr_setup(lanai);
2426 }
2427 set_bit(ATM_VF_READY, &atmvcc->flags);
2428 return 0;
2429 out_free:
2430 lanai_close(atmvcc);
2431 out:
2432 return result;
2433}
2434
2435#if 0
2436
2437
2438static int lanai_ioctl(struct atm_dev *atmdev, unsigned int cmd, void __user *arg)
2439{
2440 int result = 0;
2441 struct lanai_dev *lanai = (struct lanai_dev *) atmdev->dev_data;
2442 switch(cmd) {
2443 case 2106275:
2444 shutdown_atm_dev(atmdev);
2445 return 0;
2446 case 2200000: {
2447 unsigned long flags;
2448 spin_lock_irqsave(&lanai->servicelock, flags);
2449 run_service(lanai);
2450 spin_unlock_irqrestore(&lanai->servicelock, flags);
2451 return 0; }
2452 case 2200002:
2453 get_statistics(lanai);
2454 return 0;
2455 case 2200003: {
2456 unsigned int i;
2457 for (i = 0; i <= 0x5C ; i += 4) {
2458 if (i==0x48)
2459 continue;
2460 printk(KERN_CRIT DEV_LABEL " 0x%02X: "
2461 "0x%08X\n", i,
2462 (unsigned int) readl(lanai->base + i));
2463 barrier(); mb();
2464 pcistatus_check(lanai, 0);
2465 barrier(); mb();
2466 }
2467 return 0; }
2468 case 2200004: {
2469 u8 b;
2470 u16 w;
2471 u32 dw;
2472 struct pci_dev *pci = lanai->pci;
2473 (void) pci_read_config_word(pci, PCI_VENDOR_ID, &w);
2474 DPRINTK("vendor = 0x%X\n", (unsigned int) w);
2475 (void) pci_read_config_word(pci, PCI_DEVICE_ID, &w);
2476 DPRINTK("device = 0x%X\n", (unsigned int) w);
2477 (void) pci_read_config_word(pci, PCI_COMMAND, &w);
2478 DPRINTK("command = 0x%X\n", (unsigned int) w);
2479 (void) pci_read_config_word(pci, PCI_STATUS, &w);
2480 DPRINTK("status = 0x%X\n", (unsigned int) w);
2481 (void) pci_read_config_dword(pci,
2482 PCI_CLASS_REVISION, &dw);
2483 DPRINTK("class/revision = 0x%X\n", (unsigned int) dw);
2484 (void) pci_read_config_byte(pci,
2485 PCI_CACHE_LINE_SIZE, &b);
2486 DPRINTK("cache line size = 0x%X\n", (unsigned int) b);
2487 (void) pci_read_config_byte(pci, PCI_LATENCY_TIMER, &b);
2488 DPRINTK("latency = %d (0x%X)\n",
2489 (int) b, (unsigned int) b);
2490 (void) pci_read_config_byte(pci, PCI_HEADER_TYPE, &b);
2491 DPRINTK("header type = 0x%X\n", (unsigned int) b);
2492 (void) pci_read_config_byte(pci, PCI_BIST, &b);
2493 DPRINTK("bist = 0x%X\n", (unsigned int) b);
2494
2495 (void) pci_read_config_byte(pci,
2496 PCI_INTERRUPT_LINE, &b);
2497 DPRINTK("pci_int_line = 0x%X\n", (unsigned int) b);
2498 (void) pci_read_config_byte(pci,
2499 PCI_INTERRUPT_PIN, &b);
2500 DPRINTK("pci_int_pin = 0x%X\n", (unsigned int) b);
2501 (void) pci_read_config_byte(pci, PCI_MIN_GNT, &b);
2502 DPRINTK("min_gnt = 0x%X\n", (unsigned int) b);
2503 (void) pci_read_config_byte(pci, PCI_MAX_LAT, &b);
2504 DPRINTK("max_lat = 0x%X\n", (unsigned int) b); }
2505 return 0;
2506#ifdef USE_POWERDOWN
2507 case 2200005:
2508 DPRINTK("Coming out of powerdown\n");
2509 lanai->conf1 &= ~CONFIG1_POWERDOWN;
2510 conf1_write(lanai);
2511 return 0;
2512#endif
2513 default:
2514 result = -ENOIOCTLCMD;
2515 }
2516 return result;
2517}
2518#else
2519#define lanai_ioctl NULL
2520#endif
2521
2522static int lanai_send(struct atm_vcc *atmvcc, struct sk_buff *skb)
2523{
2524 struct lanai_vcc *lvcc = (struct lanai_vcc *) atmvcc->dev_data;
2525 struct lanai_dev *lanai = (struct lanai_dev *) atmvcc->dev->dev_data;
2526 unsigned long flags;
2527 if (unlikely(lvcc == NULL || lvcc->vbase == 0 ||
2528 lvcc->tx.atmvcc != atmvcc))
2529 goto einval;
2530#ifdef DEBUG
2531 if (unlikely(skb == NULL)) {
2532 DPRINTK("lanai_send: skb==NULL for vci=%d\n", atmvcc->vci);
2533 goto einval;
2534 }
2535 if (unlikely(lanai == NULL)) {
2536 DPRINTK("lanai_send: lanai==NULL for vci=%d\n", atmvcc->vci);
2537 goto einval;
2538 }
2539#endif
2540 ATM_SKB(skb)->vcc = atmvcc;
2541 switch (atmvcc->qos.aal) {
2542 case ATM_AAL5:
2543 read_lock_irqsave(&vcc_sklist_lock, flags);
2544 vcc_tx_aal5(lanai, lvcc, skb);
2545 read_unlock_irqrestore(&vcc_sklist_lock, flags);
2546 return 0;
2547 case ATM_AAL0:
2548 if (unlikely(skb->len != ATM_CELL_SIZE-1))
2549 goto einval;
2550
2551 cpu_to_be32s((u32 *) skb->data);
2552 read_lock_irqsave(&vcc_sklist_lock, flags);
2553 vcc_tx_aal0(lanai, lvcc, skb);
2554 read_unlock_irqrestore(&vcc_sklist_lock, flags);
2555 return 0;
2556 }
2557 DPRINTK("lanai_send: bad aal=%d on vci=%d\n", (int) atmvcc->qos.aal,
2558 atmvcc->vci);
2559 einval:
2560 lanai_free_skb(atmvcc, skb);
2561 return -EINVAL;
2562}
2563
2564static int lanai_change_qos(struct atm_vcc *atmvcc,
2565 struct atm_qos *qos, int flags)
2566{
2567 return -EBUSY;
2568}
2569
2570#ifndef CONFIG_PROC_FS
2571#define lanai_proc_read NULL
2572#else
2573static int lanai_proc_read(struct atm_dev *atmdev, loff_t *pos, char *page)
2574{
2575 struct lanai_dev *lanai = (struct lanai_dev *) atmdev->dev_data;
2576 loff_t left = *pos;
2577 struct lanai_vcc *lvcc;
2578 if (left-- == 0)
2579 return sprintf(page, DEV_LABEL "(itf %d): chip=LANAI%s, "
2580 "serial=%u, magic=0x%08X, num_vci=%d\n",
2581 atmdev->number, lanai->type==lanai2 ? "2" : "HB",
2582 (unsigned int) lanai->serialno,
2583 (unsigned int) lanai->magicno, lanai->num_vci);
2584 if (left-- == 0)
2585 return sprintf(page, "revision: board=%d, pci_if=%d\n",
2586 lanai->board_rev, (int) lanai->pci_revision);
2587 if (left-- == 0)
2588 return sprintf(page, "EEPROM ESI: "
2589 "%02X:%02X:%02X:%02X:%02X:%02X\n",
2590 lanai->eeprom[EEPROM_MAC + 0],
2591 lanai->eeprom[EEPROM_MAC + 1],
2592 lanai->eeprom[EEPROM_MAC + 2],
2593 lanai->eeprom[EEPROM_MAC + 3],
2594 lanai->eeprom[EEPROM_MAC + 4],
2595 lanai->eeprom[EEPROM_MAC + 5]);
2596 if (left-- == 0)
2597 return sprintf(page, "status: SOOL=%d, LOCD=%d, LED=%d, "
2598 "GPIN=%d\n", (lanai->status & STATUS_SOOL) ? 1 : 0,
2599 (lanai->status & STATUS_LOCD) ? 1 : 0,
2600 (lanai->status & STATUS_LED) ? 1 : 0,
2601 (lanai->status & STATUS_GPIN) ? 1 : 0);
2602 if (left-- == 0)
2603 return sprintf(page, "global buffer sizes: service=%Zu, "
2604 "aal0_rx=%Zu\n", lanai_buf_size(&lanai->service),
2605 lanai->naal0 ? lanai_buf_size(&lanai->aal0buf) : 0);
2606 if (left-- == 0) {
2607 get_statistics(lanai);
2608 return sprintf(page, "cells in error: overflow=%u, "
2609 "closed_vci=%u, bad_HEC=%u, rx_fifo=%u\n",
2610 lanai->stats.ovfl_trash, lanai->stats.vci_trash,
2611 lanai->stats.hec_err, lanai->stats.atm_ovfl);
2612 }
2613 if (left-- == 0)
2614 return sprintf(page, "PCI errors: parity_detect=%u, "
2615 "master_abort=%u, master_target_abort=%u,\n",
2616 lanai->stats.pcierr_parity_detect,
2617 lanai->stats.pcierr_serr_set,
2618 lanai->stats.pcierr_m_target_abort);
2619 if (left-- == 0)
2620 return sprintf(page, " slave_target_abort=%u, "
2621 "master_parity=%u\n", lanai->stats.pcierr_s_target_abort,
2622 lanai->stats.pcierr_master_parity);
2623 if (left-- == 0)
2624 return sprintf(page, " no_tx=%u, "
2625 "no_rx=%u, bad_rx_aal=%u\n", lanai->stats.service_norx,
2626 lanai->stats.service_notx,
2627 lanai->stats.service_rxnotaal5);
2628 if (left-- == 0)
2629 return sprintf(page, "resets: dma=%u, card=%u\n",
2630 lanai->stats.dma_reenable, lanai->stats.card_reset);
2631
2632 read_lock(&vcc_sklist_lock);
2633 for (; ; left++) {
2634 if (left >= NUM_VCI) {
2635 left = 0;
2636 goto out;
2637 }
2638 if ((lvcc = lanai->vccs[left]) != NULL)
2639 break;
2640 (*pos)++;
2641 }
2642
2643 left = sprintf(page, "VCI %4d: nref=%d, rx_nomem=%u", (vci_t) left,
2644 lvcc->nref, lvcc->stats.rx_nomem);
2645 if (lvcc->rx.atmvcc != NULL) {
2646 left += sprintf(&page[left], ",\n rx_AAL=%d",
2647 lvcc->rx.atmvcc->qos.aal == ATM_AAL5 ? 5 : 0);
2648 if (lvcc->rx.atmvcc->qos.aal == ATM_AAL5)
2649 left += sprintf(&page[left], ", rx_buf_size=%Zu, "
2650 "rx_bad_len=%u,\n rx_service_trash=%u, "
2651 "rx_service_stream=%u, rx_bad_crc=%u",
2652 lanai_buf_size(&lvcc->rx.buf),
2653 lvcc->stats.x.aal5.rx_badlen,
2654 lvcc->stats.x.aal5.service_trash,
2655 lvcc->stats.x.aal5.service_stream,
2656 lvcc->stats.x.aal5.service_rxcrc);
2657 }
2658 if (lvcc->tx.atmvcc != NULL)
2659 left += sprintf(&page[left], ",\n tx_AAL=%d, "
2660 "tx_buf_size=%Zu, tx_qos=%cBR, tx_backlogged=%c",
2661 lvcc->tx.atmvcc->qos.aal == ATM_AAL5 ? 5 : 0,
2662 lanai_buf_size(&lvcc->tx.buf),
2663 lvcc->tx.atmvcc == lanai->cbrvcc ? 'C' : 'U',
2664 vcc_is_backlogged(lvcc) ? 'Y' : 'N');
2665 page[left++] = '\n';
2666 page[left] = '\0';
2667 out:
2668 read_unlock(&vcc_sklist_lock);
2669 return left;
2670}
2671#endif
2672
2673
2674
2675static const struct atmdev_ops ops = {
2676 .dev_close = lanai_dev_close,
2677 .open = lanai_open,
2678 .close = lanai_close,
2679 .ioctl = lanai_ioctl,
2680 .getsockopt = NULL,
2681 .setsockopt = NULL,
2682 .send = lanai_send,
2683 .phy_put = NULL,
2684 .phy_get = NULL,
2685 .change_qos = lanai_change_qos,
2686 .proc_read = lanai_proc_read,
2687 .owner = THIS_MODULE
2688};
2689
2690
2691static int __devinit lanai_init_one(struct pci_dev *pci,
2692 const struct pci_device_id *ident)
2693{
2694 struct lanai_dev *lanai;
2695 struct atm_dev *atmdev;
2696 int result;
2697
2698 lanai = (struct lanai_dev *) kmalloc(sizeof(*lanai), GFP_KERNEL);
2699 if (lanai == NULL) {
2700 printk(KERN_ERR DEV_LABEL
2701 ": couldn't allocate dev_data structure!\n");
2702 return -ENOMEM;
2703 }
2704
2705 atmdev = atm_dev_register(DEV_LABEL, &ops, -1, NULL);
2706 if (atmdev == NULL) {
2707 printk(KERN_ERR DEV_LABEL
2708 ": couldn't register atm device!\n");
2709 kfree(lanai);
2710 return -EBUSY;
2711 }
2712
2713 atmdev->dev_data = lanai;
2714 lanai->pci = pci;
2715 lanai->type = (enum lanai_type) ident->device;
2716
2717 result = lanai_dev_open(atmdev);
2718 if (result != 0) {
2719 DPRINTK("lanai_start() failed, err=%d\n", -result);
2720 atm_dev_deregister(atmdev);
2721 kfree(lanai);
2722 }
2723 return result;
2724}
2725
2726static struct pci_device_id lanai_pci_tbl[] = {
2727 {
2728 PCI_VENDOR_ID_EF, PCI_VENDOR_ID_EF_ATM_LANAI2,
2729 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0
2730 },
2731 {
2732 PCI_VENDOR_ID_EF, PCI_VENDOR_ID_EF_ATM_LANAIHB,
2733 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0
2734 },
2735 { 0, }
2736};
2737MODULE_DEVICE_TABLE(pci, lanai_pci_tbl);
2738
2739static struct pci_driver lanai_driver = {
2740 .name = DEV_LABEL,
2741 .id_table = lanai_pci_tbl,
2742 .probe = lanai_init_one,
2743};
2744
2745static int __init lanai_module_init(void)
2746{
2747 int x;
2748
2749 x = pci_module_init(&lanai_driver);
2750 if (x != 0)
2751 printk(KERN_ERR DEV_LABEL ": no adapter found\n");
2752 return x;
2753}
2754
2755static void __exit lanai_module_exit(void)
2756{
2757
2758
2759
2760 DPRINTK("cleanup_module()\n");
2761}
2762
2763module_init(lanai_module_init);
2764module_exit(lanai_module_exit);
2765
2766MODULE_AUTHOR("Mitchell Blank Jr <mitch@sfgoth.com>");
2767MODULE_DESCRIPTION("Efficient Networks Speedstream 3010 driver");
2768MODULE_LICENSE("GPL");
2769