0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053 #include <linux/module.h>
0054 #include <linux/slab.h>
0055 #include <linux/mm.h>
0056 #include <linux/atmdev.h>
0057 #include <asm/io.h>
0058 #include <asm/byteorder.h>
0059 #include <linux/spinlock.h>
0060 #include <linux/pci.h>
0061 #include <linux/dma-mapping.h>
0062 #include <linux/init.h>
0063 #include <linux/delay.h>
0064 #include <linux/interrupt.h>
0065
0066
0067
0068
0069
0070
0071
0072
0073 #define NUM_VCI (1024)
0074
0075
0076
0077
0078 #define DEBUG
0079
0080
0081
0082
0083
0084 #undef DEBUG_RW
0085
0086
0087
0088
0089
0090 #define FULL_MEMORY_TEST
0091
0092
0093
0094
0095
0096
0097 #define SERVICE_ENTRIES (1024)
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114 #define TX_FIFO_DEPTH (7)
0115
0116
0117
0118
0119
0120
0121 #define LANAI_POLL_PERIOD (10*HZ)
0122
0123
0124
0125
0126
0127
0128 #define AAL5_RX_MULTIPLIER (3)
0129
0130
0131
0132
0133
0134 #define AAL5_TX_MULTIPLIER (3)
0135
0136
0137
0138
0139
0140
0141
0142 #define AAL0_TX_MULTIPLIER (40)
0143
0144
0145
0146
0147
0148
0149 #define AAL0_RX_BUFFER_SIZE (PAGE_SIZE)
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160 #define DEV_LABEL "lanai"
0161
0162 #ifdef DEBUG
0163
0164 #define DPRINTK(format, args...) \
0165 printk(KERN_DEBUG DEV_LABEL ": " format, ##args)
0166 #define APRINTK(truth, format, args...) \
0167 do { \
0168 if (unlikely(!(truth))) \
0169 printk(KERN_ERR DEV_LABEL ": " format, ##args); \
0170 } while (0)
0171
0172 #else
0173
0174 #define DPRINTK(format, args...)
0175 #define APRINTK(truth, format, args...)
0176
0177 #endif
0178
0179 #ifdef DEBUG_RW
0180 #define RWDEBUG(format, args...) \
0181 printk(KERN_DEBUG DEV_LABEL ": " format, ##args)
0182 #else
0183 #define RWDEBUG(format, args...)
0184 #endif
0185
0186
0187
0188 #define LANAI_MAPPING_SIZE (0x40000)
0189 #define LANAI_EEPROM_SIZE (128)
0190
0191 typedef int vci_t;
0192 typedef void __iomem *bus_addr_t;
0193
0194
0195 struct lanai_buffer {
0196 u32 *start;
0197 u32 *end;
0198 u32 *ptr;
0199 dma_addr_t dmaaddr;
0200 };
0201
0202 struct lanai_vcc_stats {
0203 unsigned rx_nomem;
0204 union {
0205 struct {
0206 unsigned rx_badlen;
0207 unsigned service_trash;
0208 unsigned service_stream;
0209 unsigned service_rxcrc;
0210 } aal5;
0211 struct {
0212 } aal0;
0213 } x;
0214 };
0215
0216 struct lanai_dev;
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226 struct lanai_vcc {
0227 bus_addr_t vbase;
0228 struct lanai_vcc_stats stats;
0229 int nref;
0230 vci_t vci;
0231 struct {
0232 struct lanai_buffer buf;
0233 struct atm_vcc *atmvcc;
0234 } rx;
0235 struct {
0236 struct lanai_buffer buf;
0237 struct atm_vcc *atmvcc;
0238 int endptr;
0239 struct sk_buff_head backlog;
0240 void (*unqueue)(struct lanai_dev *, struct lanai_vcc *, int);
0241 } tx;
0242 };
0243
0244 enum lanai_type {
0245 lanai2 = PCI_DEVICE_ID_EF_ATM_LANAI2,
0246 lanaihb = PCI_DEVICE_ID_EF_ATM_LANAIHB
0247 };
0248
0249 struct lanai_dev_stats {
0250 unsigned ovfl_trash;
0251 unsigned vci_trash;
0252 unsigned hec_err;
0253 unsigned atm_ovfl;
0254 unsigned pcierr_parity_detect;
0255 unsigned pcierr_serr_set;
0256 unsigned pcierr_master_abort;
0257 unsigned pcierr_m_target_abort;
0258 unsigned pcierr_s_target_abort;
0259 unsigned pcierr_master_parity;
0260 unsigned service_notx;
0261 unsigned service_norx;
0262 unsigned service_rxnotaal5;
0263 unsigned dma_reenable;
0264 unsigned card_reset;
0265 };
0266
0267 struct lanai_dev {
0268 bus_addr_t base;
0269 struct lanai_dev_stats stats;
0270 struct lanai_buffer service;
0271 struct lanai_vcc **vccs;
0272 #ifdef USE_POWERDOWN
0273 int nbound;
0274 #endif
0275 enum lanai_type type;
0276 vci_t num_vci;
0277 u8 eeprom[LANAI_EEPROM_SIZE];
0278 u32 serialno, magicno;
0279 struct pci_dev *pci;
0280 DECLARE_BITMAP(backlog_vccs, NUM_VCI);
0281 DECLARE_BITMAP(transmit_ready, NUM_VCI);
0282 struct timer_list timer;
0283 int naal0;
0284 struct lanai_buffer aal0buf;
0285 u32 conf1, conf2;
0286 u32 status;
0287 spinlock_t endtxlock;
0288 spinlock_t servicelock;
0289 struct atm_vcc *cbrvcc;
0290 int number;
0291 int board_rev;
0292
0293
0294
0295 };
0296
0297
0298
0299
0300
0301
0302 static void vci_bitfield_iterate(struct lanai_dev *lanai,
0303 const unsigned long *lp,
0304 void (*func)(struct lanai_dev *,vci_t vci))
0305 {
0306 vci_t vci;
0307
0308 for_each_set_bit(vci, lp, NUM_VCI)
0309 func(lanai, vci);
0310 }
0311
0312
0313
0314
0315
0316
0317
0318
0319 #define LANAI_PAGE_SIZE ((PAGE_SIZE >= 1024) ? PAGE_SIZE : 1024)
0320
0321
0322
0323
0324
0325
0326
0327
0328 static void lanai_buf_allocate(struct lanai_buffer *buf,
0329 size_t bytes, size_t minbytes, struct pci_dev *pci)
0330 {
0331 int size;
0332
0333 if (bytes > (128 * 1024))
0334 bytes = 128 * 1024;
0335 for (size = LANAI_PAGE_SIZE; size < bytes; size *= 2)
0336 ;
0337 if (minbytes < LANAI_PAGE_SIZE)
0338 minbytes = LANAI_PAGE_SIZE;
0339 do {
0340
0341
0342
0343
0344
0345 buf->start = dma_alloc_coherent(&pci->dev,
0346 size, &buf->dmaaddr, GFP_KERNEL);
0347 if (buf->start != NULL) {
0348
0349 APRINTK((buf->dmaaddr & ~0xFFFFFF00) == 0,
0350 "bad dmaaddr: 0x%lx\n",
0351 (unsigned long) buf->dmaaddr);
0352 buf->ptr = buf->start;
0353 buf->end = (u32 *)
0354 (&((unsigned char *) buf->start)[size]);
0355 memset(buf->start, 0, size);
0356 break;
0357 }
0358 size /= 2;
0359 } while (size >= minbytes);
0360 }
0361
0362
0363 static inline size_t lanai_buf_size(const struct lanai_buffer *buf)
0364 {
0365 return ((unsigned long) buf->end) - ((unsigned long) buf->start);
0366 }
0367
0368 static void lanai_buf_deallocate(struct lanai_buffer *buf,
0369 struct pci_dev *pci)
0370 {
0371 if (buf->start != NULL) {
0372 dma_free_coherent(&pci->dev, lanai_buf_size(buf),
0373 buf->start, buf->dmaaddr);
0374 buf->start = buf->end = buf->ptr = NULL;
0375 }
0376 }
0377
0378
0379 static int lanai_buf_size_cardorder(const struct lanai_buffer *buf)
0380 {
0381 int order = get_order(lanai_buf_size(buf)) + (PAGE_SHIFT - 10);
0382
0383
0384 if (order > 7)
0385 order = 7;
0386 return order;
0387 }
0388
0389
0390
0391
0392 enum lanai_register {
0393 Reset_Reg = 0x00,
0394 #define RESET_GET_BOARD_REV(x) (((x)>> 0)&0x03)
0395 #define RESET_GET_BOARD_ID(x) (((x)>> 2)&0x03)
0396 #define BOARD_ID_LANAI256 (0)
0397 Endian_Reg = 0x04,
0398 IntStatus_Reg = 0x08,
0399 IntStatusMasked_Reg = 0x0C,
0400 IntAck_Reg = 0x10,
0401 IntAckMasked_Reg = 0x14,
0402 IntStatusSet_Reg = 0x18,
0403 IntStatusSetMasked_Reg = 0x1C,
0404 IntControlEna_Reg = 0x20,
0405 IntControlDis_Reg = 0x24,
0406 Status_Reg = 0x28,
0407 #define STATUS_PROMDATA (0x00000001)
0408 #define STATUS_WAITING (0x00000002)
0409 #define STATUS_SOOL (0x00000004)
0410 #define STATUS_LOCD (0x00000008)
0411 #define STATUS_LED (0x00000010)
0412 #define STATUS_GPIN (0x00000020)
0413 #define STATUS_BUTTBUSY (0x00000040)
0414 Config1_Reg = 0x2C,
0415 #define CONFIG1_PROMDATA (0x00000001)
0416 #define CONFIG1_PROMCLK (0x00000002)
0417 #define CONFIG1_SET_READMODE(x) ((x)*0x004)
0418 #define READMODE_PLAIN (0)
0419 #define READMODE_LINE (2)
0420 #define READMODE_MULTIPLE (3)
0421 #define CONFIG1_DMA_ENABLE (0x00000010)
0422 #define CONFIG1_POWERDOWN (0x00000020)
0423 #define CONFIG1_SET_LOOPMODE(x) ((x)*0x080)
0424 #define LOOPMODE_NORMAL (0)
0425 #define LOOPMODE_TIME (1)
0426 #define LOOPMODE_DIAG (2)
0427 #define LOOPMODE_LINE (3)
0428 #define CONFIG1_MASK_LOOPMODE (0x00000180)
0429 #define CONFIG1_SET_LEDMODE(x) ((x)*0x0200)
0430 #define LEDMODE_NOT_SOOL (0)
0431 #define LEDMODE_OFF (1)
0432 #define LEDMODE_ON (2)
0433 #define LEDMODE_NOT_LOCD (3)
0434 #define LEDMORE_GPIN (4)
0435 #define LEDMODE_NOT_GPIN (7)
0436 #define CONFIG1_MASK_LEDMODE (0x00000E00)
0437 #define CONFIG1_GPOUT1 (0x00001000)
0438 #define CONFIG1_GPOUT2 (0x00002000)
0439 #define CONFIG1_GPOUT3 (0x00004000)
0440 Config2_Reg = 0x30,
0441 #define CONFIG2_HOWMANY (0x00000001)
0442 #define CONFIG2_PTI7_MODE (0x00000002)
0443 #define CONFIG2_VPI_CHK_DIS (0x00000004)
0444 #define CONFIG2_HEC_DROP (0x00000008)
0445 #define CONFIG2_VCI0_NORMAL (0x00000010)
0446 #define CONFIG2_CBR_ENABLE (0x00000020)
0447 #define CONFIG2_TRASH_ALL (0x00000040)
0448 #define CONFIG2_TX_DISABLE (0x00000080)
0449 #define CONFIG2_SET_TRASH (0x00000100)
0450 Statistics_Reg = 0x34,
0451 #define STATS_GET_FIFO_OVFL(x) (((x)>> 0)&0xFF)
0452 #define STATS_GET_HEC_ERR(x) (((x)>> 8)&0xFF)
0453 #define STATS_GET_BAD_VCI(x) (((x)>>16)&0xFF)
0454 #define STATS_GET_BUF_OVFL(x) (((x)>>24)&0xFF)
0455 ServiceStuff_Reg = 0x38,
0456 #define SSTUFF_SET_SIZE(x) ((x)*0x20000000)
0457 #define SSTUFF_SET_ADDR(x) ((x)>>8)
0458 ServWrite_Reg = 0x3C,
0459 ServRead_Reg = 0x40,
0460 TxDepth_Reg = 0x44,
0461 Butt_Reg = 0x48,
0462 CBR_ICG_Reg = 0x50,
0463 CBR_PTR_Reg = 0x54,
0464 PingCount_Reg = 0x58,
0465 DMA_Addr_Reg = 0x5C
0466 };
0467
0468 static inline bus_addr_t reg_addr(const struct lanai_dev *lanai,
0469 enum lanai_register reg)
0470 {
0471 return lanai->base + reg;
0472 }
0473
0474 static inline u32 reg_read(const struct lanai_dev *lanai,
0475 enum lanai_register reg)
0476 {
0477 u32 t;
0478 t = readl(reg_addr(lanai, reg));
0479 RWDEBUG("R [0x%08X] 0x%02X = 0x%08X\n", (unsigned int) lanai->base,
0480 (int) reg, t);
0481 return t;
0482 }
0483
0484 static inline void reg_write(const struct lanai_dev *lanai, u32 val,
0485 enum lanai_register reg)
0486 {
0487 RWDEBUG("W [0x%08X] 0x%02X < 0x%08X\n", (unsigned int) lanai->base,
0488 (int) reg, val);
0489 writel(val, reg_addr(lanai, reg));
0490 }
0491
0492 static inline void conf1_write(const struct lanai_dev *lanai)
0493 {
0494 reg_write(lanai, lanai->conf1, Config1_Reg);
0495 }
0496
0497 static inline void conf2_write(const struct lanai_dev *lanai)
0498 {
0499 reg_write(lanai, lanai->conf2, Config2_Reg);
0500 }
0501
0502
0503 static inline void conf2_write_if_powerup(const struct lanai_dev *lanai)
0504 {
0505 #ifdef USE_POWERDOWN
0506 if (unlikely((lanai->conf1 & CONFIG1_POWERDOWN) != 0))
0507 return;
0508 #endif
0509 conf2_write(lanai);
0510 }
0511
0512 static inline void reset_board(const struct lanai_dev *lanai)
0513 {
0514 DPRINTK("about to reset board\n");
0515 reg_write(lanai, 0, Reset_Reg);
0516
0517
0518
0519
0520
0521
0522 udelay(5);
0523 }
0524
0525
0526
0527
0528
0529
0530
0531
0532 #define SRAM_START (0x20000)
0533 #define SRAM_BYTES (0x20000)
0534
0535 static inline bus_addr_t sram_addr(const struct lanai_dev *lanai, int offset)
0536 {
0537 return lanai->base + SRAM_START + offset;
0538 }
0539
0540 static inline u32 sram_read(const struct lanai_dev *lanai, int offset)
0541 {
0542 return readl(sram_addr(lanai, offset));
0543 }
0544
0545 static inline void sram_write(const struct lanai_dev *lanai,
0546 u32 val, int offset)
0547 {
0548 writel(val, sram_addr(lanai, offset));
0549 }
0550
0551 static int sram_test_word(const struct lanai_dev *lanai, int offset,
0552 u32 pattern)
0553 {
0554 u32 readback;
0555 sram_write(lanai, pattern, offset);
0556 readback = sram_read(lanai, offset);
0557 if (likely(readback == pattern))
0558 return 0;
0559 printk(KERN_ERR DEV_LABEL
0560 "(itf %d): SRAM word at %d bad: wrote 0x%X, read 0x%X\n",
0561 lanai->number, offset,
0562 (unsigned int) pattern, (unsigned int) readback);
0563 return -EIO;
0564 }
0565
0566 static int sram_test_pass(const struct lanai_dev *lanai, u32 pattern)
0567 {
0568 int offset, result = 0;
0569 for (offset = 0; offset < SRAM_BYTES && result == 0; offset += 4)
0570 result = sram_test_word(lanai, offset, pattern);
0571 return result;
0572 }
0573
0574 static int sram_test_and_clear(const struct lanai_dev *lanai)
0575 {
0576 #ifdef FULL_MEMORY_TEST
0577 int result;
0578 DPRINTK("testing SRAM\n");
0579 if ((result = sram_test_pass(lanai, 0x5555)) != 0)
0580 return result;
0581 if ((result = sram_test_pass(lanai, 0xAAAA)) != 0)
0582 return result;
0583 #endif
0584 DPRINTK("clearing SRAM\n");
0585 return sram_test_pass(lanai, 0x0000);
0586 }
0587
0588
0589
0590
0591 enum lanai_vcc_offset {
0592 vcc_rxaddr1 = 0x00,
0593 #define RXADDR1_SET_SIZE(x) ((x)*0x0000100)
0594 #define RXADDR1_SET_RMMODE(x) ((x)*0x00800)
0595 #define RMMODE_TRASH (0)
0596 #define RMMODE_PRESERVE (1)
0597 #define RMMODE_PIPE (2)
0598 #define RMMODE_PIPEALL (3)
0599 #define RXADDR1_OAM_PRESERVE (0x00002000)
0600 #define RXADDR1_SET_MODE(x) ((x)*0x0004000)
0601 #define RXMODE_TRASH (0)
0602 #define RXMODE_AAL0 (1)
0603 #define RXMODE_AAL5 (2)
0604 #define RXMODE_AAL5_STREAM (3)
0605 vcc_rxaddr2 = 0x04,
0606 vcc_rxcrc1 = 0x08,
0607 vcc_rxcrc2 = 0x0C,
0608 vcc_rxwriteptr = 0x10,
0609 #define RXWRITEPTR_LASTEFCI (0x00002000)
0610 #define RXWRITEPTR_DROPPING (0x00004000)
0611 #define RXWRITEPTR_TRASHING (0x00008000)
0612 vcc_rxbufstart = 0x14,
0613 #define RXBUFSTART_CLP (0x00004000)
0614 #define RXBUFSTART_CI (0x00008000)
0615 vcc_rxreadptr = 0x18,
0616 vcc_txicg = 0x1C,
0617 vcc_txaddr1 = 0x20,
0618 #define TXADDR1_SET_SIZE(x) ((x)*0x0000100)
0619 #define TXADDR1_ABR (0x00008000)
0620 vcc_txaddr2 = 0x24,
0621 vcc_txcrc1 = 0x28,
0622 vcc_txcrc2 = 0x2C,
0623 vcc_txreadptr = 0x30,
0624 #define TXREADPTR_GET_PTR(x) ((x)&0x01FFF)
0625 #define TXREADPTR_MASK_DELTA (0x0000E000)
0626 vcc_txendptr = 0x34,
0627 #define TXENDPTR_CLP (0x00002000)
0628 #define TXENDPTR_MASK_PDUMODE (0x0000C000)
0629 #define PDUMODE_AAL0 (0*0x04000)
0630 #define PDUMODE_AAL5 (2*0x04000)
0631 #define PDUMODE_AAL5STREAM (3*0x04000)
0632 vcc_txwriteptr = 0x38,
0633 #define TXWRITEPTR_GET_PTR(x) ((x)&0x1FFF)
0634 vcc_txcbr_next = 0x3C
0635 #define TXCBR_NEXT_BOZO (0x00008000)
0636 };
0637
0638 #define CARDVCC_SIZE (0x40)
0639
0640 static inline bus_addr_t cardvcc_addr(const struct lanai_dev *lanai,
0641 vci_t vci)
0642 {
0643 return sram_addr(lanai, vci * CARDVCC_SIZE);
0644 }
0645
0646 static inline u32 cardvcc_read(const struct lanai_vcc *lvcc,
0647 enum lanai_vcc_offset offset)
0648 {
0649 u32 val;
0650 APRINTK(lvcc->vbase != NULL, "cardvcc_read: unbound vcc!\n");
0651 val= readl(lvcc->vbase + offset);
0652 RWDEBUG("VR vci=%04d 0x%02X = 0x%08X\n",
0653 lvcc->vci, (int) offset, val);
0654 return val;
0655 }
0656
0657 static inline void cardvcc_write(const struct lanai_vcc *lvcc,
0658 u32 val, enum lanai_vcc_offset offset)
0659 {
0660 APRINTK(lvcc->vbase != NULL, "cardvcc_write: unbound vcc!\n");
0661 APRINTK((val & ~0xFFFF) == 0,
0662 "cardvcc_write: bad val 0x%X (vci=%d, addr=0x%02X)\n",
0663 (unsigned int) val, lvcc->vci, (unsigned int) offset);
0664 RWDEBUG("VW vci=%04d 0x%02X > 0x%08X\n",
0665 lvcc->vci, (unsigned int) offset, (unsigned int) val);
0666 writel(val, lvcc->vbase + offset);
0667 }
0668
0669
0670
0671
0672
0673
0674
0675 static inline int aal5_size(int size)
0676 {
0677 int cells = (size + 8 + 47) / 48;
0678 return cells * 48;
0679 }
0680
0681
0682
0683 static inline void lanai_free_skb(struct atm_vcc *atmvcc, struct sk_buff *skb)
0684 {
0685 if (atmvcc->pop != NULL)
0686 atmvcc->pop(atmvcc, skb);
0687 else
0688 dev_kfree_skb_any(skb);
0689 }
0690
0691
0692
0693 static void host_vcc_start_rx(const struct lanai_vcc *lvcc)
0694 {
0695 u32 addr1;
0696 if (lvcc->rx.atmvcc->qos.aal == ATM_AAL5) {
0697 dma_addr_t dmaaddr = lvcc->rx.buf.dmaaddr;
0698 cardvcc_write(lvcc, 0xFFFF, vcc_rxcrc1);
0699 cardvcc_write(lvcc, 0xFFFF, vcc_rxcrc2);
0700 cardvcc_write(lvcc, 0, vcc_rxwriteptr);
0701 cardvcc_write(lvcc, 0, vcc_rxbufstart);
0702 cardvcc_write(lvcc, 0, vcc_rxreadptr);
0703 cardvcc_write(lvcc, (dmaaddr >> 16) & 0xFFFF, vcc_rxaddr2);
0704 addr1 = ((dmaaddr >> 8) & 0xFF) |
0705 RXADDR1_SET_SIZE(lanai_buf_size_cardorder(&lvcc->rx.buf))|
0706 RXADDR1_SET_RMMODE(RMMODE_TRASH) |
0707
0708 RXADDR1_SET_MODE(RXMODE_AAL5);
0709 } else
0710 addr1 = RXADDR1_SET_RMMODE(RMMODE_PRESERVE) |
0711 RXADDR1_OAM_PRESERVE |
0712 RXADDR1_SET_MODE(RXMODE_AAL0);
0713
0714 cardvcc_write(lvcc, addr1, vcc_rxaddr1);
0715 }
0716
0717 static void host_vcc_start_tx(const struct lanai_vcc *lvcc)
0718 {
0719 dma_addr_t dmaaddr = lvcc->tx.buf.dmaaddr;
0720 cardvcc_write(lvcc, 0, vcc_txicg);
0721 cardvcc_write(lvcc, 0xFFFF, vcc_txcrc1);
0722 cardvcc_write(lvcc, 0xFFFF, vcc_txcrc2);
0723 cardvcc_write(lvcc, 0, vcc_txreadptr);
0724 cardvcc_write(lvcc, 0, vcc_txendptr);
0725 cardvcc_write(lvcc, 0, vcc_txwriteptr);
0726 cardvcc_write(lvcc,
0727 (lvcc->tx.atmvcc->qos.txtp.traffic_class == ATM_CBR) ?
0728 TXCBR_NEXT_BOZO | lvcc->vci : 0, vcc_txcbr_next);
0729 cardvcc_write(lvcc, (dmaaddr >> 16) & 0xFFFF, vcc_txaddr2);
0730 cardvcc_write(lvcc,
0731 ((dmaaddr >> 8) & 0xFF) |
0732 TXADDR1_SET_SIZE(lanai_buf_size_cardorder(&lvcc->tx.buf)),
0733 vcc_txaddr1);
0734 }
0735
0736
0737 static void lanai_shutdown_rx_vci(const struct lanai_vcc *lvcc)
0738 {
0739 if (lvcc->vbase == NULL)
0740 return;
0741
0742 cardvcc_write(lvcc,
0743 RXADDR1_SET_RMMODE(RMMODE_TRASH) |
0744 RXADDR1_SET_MODE(RXMODE_TRASH), vcc_rxaddr1);
0745 udelay(15);
0746
0747 cardvcc_write(lvcc, 0, vcc_rxaddr2);
0748 cardvcc_write(lvcc, 0, vcc_rxcrc1);
0749 cardvcc_write(lvcc, 0, vcc_rxcrc2);
0750 cardvcc_write(lvcc, 0, vcc_rxwriteptr);
0751 cardvcc_write(lvcc, 0, vcc_rxbufstart);
0752 cardvcc_write(lvcc, 0, vcc_rxreadptr);
0753 }
0754
0755
0756
0757
0758
0759
0760
0761
0762 static void lanai_shutdown_tx_vci(struct lanai_dev *lanai,
0763 struct lanai_vcc *lvcc)
0764 {
0765 struct sk_buff *skb;
0766 unsigned long flags, timeout;
0767 int read, write, lastread = -1;
0768
0769 if (lvcc->vbase == NULL)
0770 return;
0771
0772 while ((skb = skb_dequeue(&lvcc->tx.backlog)) != NULL)
0773 lanai_free_skb(lvcc->tx.atmvcc, skb);
0774 read_lock_irqsave(&vcc_sklist_lock, flags);
0775 __clear_bit(lvcc->vci, lanai->backlog_vccs);
0776 read_unlock_irqrestore(&vcc_sklist_lock, flags);
0777
0778
0779
0780
0781
0782 timeout = jiffies +
0783 (((lanai_buf_size(&lvcc->tx.buf) / 1024) * HZ) >> 7);
0784 write = TXWRITEPTR_GET_PTR(cardvcc_read(lvcc, vcc_txwriteptr));
0785 for (;;) {
0786 read = TXREADPTR_GET_PTR(cardvcc_read(lvcc, vcc_txreadptr));
0787 if (read == write &&
0788 (lvcc->tx.atmvcc->qos.txtp.traffic_class != ATM_CBR ||
0789 (cardvcc_read(lvcc, vcc_txcbr_next) &
0790 TXCBR_NEXT_BOZO) == 0))
0791 break;
0792 if (read != lastread) {
0793 lastread = read;
0794 timeout += HZ / 10;
0795 }
0796 if (unlikely(time_after(jiffies, timeout))) {
0797 printk(KERN_ERR DEV_LABEL "(itf %d): Timed out on "
0798 "backlog closing vci %d\n",
0799 lvcc->tx.atmvcc->dev->number, lvcc->vci);
0800 DPRINTK("read, write = %d, %d\n", read, write);
0801 break;
0802 }
0803 msleep(40);
0804 }
0805
0806 cardvcc_write(lvcc, 0, vcc_txreadptr);
0807 cardvcc_write(lvcc, 0, vcc_txwriteptr);
0808 cardvcc_write(lvcc, 0, vcc_txendptr);
0809 cardvcc_write(lvcc, 0, vcc_txcrc1);
0810 cardvcc_write(lvcc, 0, vcc_txcrc2);
0811 cardvcc_write(lvcc, 0, vcc_txaddr2);
0812 cardvcc_write(lvcc, 0, vcc_txaddr1);
0813 }
0814
0815
0816
0817 static inline int aal0_buffer_allocate(struct lanai_dev *lanai)
0818 {
0819 DPRINTK("aal0_buffer_allocate: allocating AAL0 RX buffer\n");
0820 lanai_buf_allocate(&lanai->aal0buf, AAL0_RX_BUFFER_SIZE, 80,
0821 lanai->pci);
0822 return (lanai->aal0buf.start == NULL) ? -ENOMEM : 0;
0823 }
0824
0825 static inline void aal0_buffer_free(struct lanai_dev *lanai)
0826 {
0827 DPRINTK("aal0_buffer_allocate: freeing AAL0 RX buffer\n");
0828 lanai_buf_deallocate(&lanai->aal0buf, lanai->pci);
0829 }
0830
0831
0832
0833
0834 #define EEPROM_COPYRIGHT (0)
0835 #define EEPROM_COPYRIGHT_LEN (44)
0836 #define EEPROM_CHECKSUM (62)
0837 #define EEPROM_CHECKSUM_REV (63)
0838 #define EEPROM_MAC (64)
0839 #define EEPROM_MAC_REV (70)
0840 #define EEPROM_SERIAL (112)
0841 #define EEPROM_SERIAL_REV (116)
0842 #define EEPROM_MAGIC (120)
0843 #define EEPROM_MAGIC_REV (124)
0844
0845 #define EEPROM_MAGIC_VALUE (0x5AB478D2)
0846
0847 #ifndef READ_EEPROM
0848
0849
0850 static int eeprom_read(struct lanai_dev *lanai)
0851 {
0852 printk(KERN_INFO DEV_LABEL "(itf %d): *NOT* reading EEPROM\n",
0853 lanai->number);
0854 memset(&lanai->eeprom[EEPROM_MAC], 0, 6);
0855 return 0;
0856 }
0857
0858 static int eeprom_validate(struct lanai_dev *lanai)
0859 {
0860 lanai->serialno = 0;
0861 lanai->magicno = EEPROM_MAGIC_VALUE;
0862 return 0;
0863 }
0864
0865 #else
0866
0867 static int eeprom_read(struct lanai_dev *lanai)
0868 {
0869 int i, address;
0870 u8 data;
0871 u32 tmp;
0872 #define set_config1(x) do { lanai->conf1 = x; conf1_write(lanai); \
0873 } while (0)
0874 #define clock_h() set_config1(lanai->conf1 | CONFIG1_PROMCLK)
0875 #define clock_l() set_config1(lanai->conf1 &~ CONFIG1_PROMCLK)
0876 #define data_h() set_config1(lanai->conf1 | CONFIG1_PROMDATA)
0877 #define data_l() set_config1(lanai->conf1 &~ CONFIG1_PROMDATA)
0878 #define pre_read() do { data_h(); clock_h(); udelay(5); } while (0)
0879 #define read_pin() (reg_read(lanai, Status_Reg) & STATUS_PROMDATA)
0880 #define send_stop() do { data_l(); udelay(5); clock_h(); udelay(5); \
0881 data_h(); udelay(5); } while (0)
0882
0883 data_h(); clock_h(); udelay(5);
0884 for (address = 0; address < LANAI_EEPROM_SIZE; address++) {
0885 data = (address << 1) | 1;
0886
0887 data_l(); udelay(5);
0888 clock_l(); udelay(5);
0889 for (i = 128; i != 0; i >>= 1) {
0890 tmp = (lanai->conf1 & ~CONFIG1_PROMDATA) |
0891 ((data & i) ? CONFIG1_PROMDATA : 0);
0892 if (lanai->conf1 != tmp) {
0893 set_config1(tmp);
0894 udelay(5);
0895 }
0896 clock_h(); udelay(5); clock_l(); udelay(5);
0897 }
0898
0899 data_h(); clock_h(); udelay(5);
0900 if (read_pin() != 0)
0901 goto error;
0902 clock_l(); udelay(5);
0903
0904 for (data = 0, i = 7; i >= 0; i--) {
0905 data_h(); clock_h(); udelay(5);
0906 data = (data << 1) | !!read_pin();
0907 clock_l(); udelay(5);
0908 }
0909
0910 data_h(); clock_h(); udelay(5);
0911 if (read_pin() == 0)
0912 goto error;
0913 clock_l(); udelay(5);
0914 send_stop();
0915 lanai->eeprom[address] = data;
0916 DPRINTK("EEPROM 0x%04X %02X\n",
0917 (unsigned int) address, (unsigned int) data);
0918 }
0919 return 0;
0920 error:
0921 clock_l(); udelay(5);
0922 send_stop();
0923 printk(KERN_ERR DEV_LABEL "(itf %d): error reading EEPROM byte %d\n",
0924 lanai->number, address);
0925 return -EIO;
0926 #undef set_config1
0927 #undef clock_h
0928 #undef clock_l
0929 #undef data_h
0930 #undef data_l
0931 #undef pre_read
0932 #undef read_pin
0933 #undef send_stop
0934 }
0935
0936
0937 static inline u32 eeprom_be4(const struct lanai_dev *lanai, int address)
0938 {
0939 return be32_to_cpup((const u32 *) &lanai->eeprom[address]);
0940 }
0941
0942
0943 static int eeprom_validate(struct lanai_dev *lanai)
0944 {
0945 int i, s;
0946 u32 v;
0947 const u8 *e = lanai->eeprom;
0948 #ifdef DEBUG
0949
0950 for (i = EEPROM_COPYRIGHT;
0951 i < (EEPROM_COPYRIGHT + EEPROM_COPYRIGHT_LEN); i++)
0952 if (e[i] < 0x20 || e[i] > 0x7E)
0953 break;
0954 if ( i != EEPROM_COPYRIGHT &&
0955 i != EEPROM_COPYRIGHT + EEPROM_COPYRIGHT_LEN && e[i] == '\0')
0956 DPRINTK("eeprom: copyright = \"%s\"\n",
0957 (char *) &e[EEPROM_COPYRIGHT]);
0958 else
0959 DPRINTK("eeprom: copyright not found\n");
0960 #endif
0961
0962 for (i = s = 0; i < EEPROM_CHECKSUM; i++)
0963 s += e[i];
0964 s &= 0xFF;
0965 if (s != e[EEPROM_CHECKSUM]) {
0966 printk(KERN_ERR DEV_LABEL "(itf %d): EEPROM checksum bad "
0967 "(wanted 0x%02X, got 0x%02X)\n", lanai->number,
0968 (unsigned int) s, (unsigned int) e[EEPROM_CHECKSUM]);
0969 return -EIO;
0970 }
0971 s ^= 0xFF;
0972 if (s != e[EEPROM_CHECKSUM_REV]) {
0973 printk(KERN_ERR DEV_LABEL "(itf %d): EEPROM inverse checksum "
0974 "bad (wanted 0x%02X, got 0x%02X)\n", lanai->number,
0975 (unsigned int) s, (unsigned int) e[EEPROM_CHECKSUM_REV]);
0976 return -EIO;
0977 }
0978
0979 for (i = 0; i < 6; i++)
0980 if ((e[EEPROM_MAC + i] ^ e[EEPROM_MAC_REV + i]) != 0xFF) {
0981 printk(KERN_ERR DEV_LABEL
0982 "(itf %d) : EEPROM MAC addresses don't match "
0983 "(0x%02X, inverse 0x%02X)\n", lanai->number,
0984 (unsigned int) e[EEPROM_MAC + i],
0985 (unsigned int) e[EEPROM_MAC_REV + i]);
0986 return -EIO;
0987 }
0988 DPRINTK("eeprom: MAC address = %pM\n", &e[EEPROM_MAC]);
0989
0990 lanai->serialno = eeprom_be4(lanai, EEPROM_SERIAL);
0991 v = eeprom_be4(lanai, EEPROM_SERIAL_REV);
0992 if ((lanai->serialno ^ v) != 0xFFFFFFFF) {
0993 printk(KERN_ERR DEV_LABEL "(itf %d): EEPROM serial numbers "
0994 "don't match (0x%08X, inverse 0x%08X)\n", lanai->number,
0995 (unsigned int) lanai->serialno, (unsigned int) v);
0996 return -EIO;
0997 }
0998 DPRINTK("eeprom: Serial number = %d\n", (unsigned int) lanai->serialno);
0999
1000 lanai->magicno = eeprom_be4(lanai, EEPROM_MAGIC);
1001 v = eeprom_be4(lanai, EEPROM_MAGIC_REV);
1002 if ((lanai->magicno ^ v) != 0xFFFFFFFF) {
1003 printk(KERN_ERR DEV_LABEL "(itf %d): EEPROM magic numbers "
1004 "don't match (0x%08X, inverse 0x%08X)\n", lanai->number,
1005 lanai->magicno, v);
1006 return -EIO;
1007 }
1008 DPRINTK("eeprom: Magic number = 0x%08X\n", lanai->magicno);
1009 if (lanai->magicno != EEPROM_MAGIC_VALUE)
1010 printk(KERN_WARNING DEV_LABEL "(itf %d): warning - EEPROM "
1011 "magic not what expected (got 0x%08X, not 0x%08X)\n",
1012 lanai->number, (unsigned int) lanai->magicno,
1013 (unsigned int) EEPROM_MAGIC_VALUE);
1014 return 0;
1015 }
1016
1017 #endif
1018
1019 static inline const u8 *eeprom_mac(const struct lanai_dev *lanai)
1020 {
1021 return &lanai->eeprom[EEPROM_MAC];
1022 }
1023
1024
1025
1026
1027 #define INT_STATS (0x00000002)
1028 #define INT_SOOL (0x00000004)
1029 #define INT_LOCD (0x00000008)
1030 #define INT_LED (0x00000010)
1031 #define INT_GPIN (0x00000020)
1032 #define INT_PING (0x00000040)
1033 #define INT_WAKE (0x00000080)
1034 #define INT_CBR0 (0x00000100)
1035 #define INT_LOCK (0x00000200)
1036 #define INT_MISMATCH (0x00000400)
1037 #define INT_AAL0_STR (0x00000800)
1038 #define INT_AAL0 (0x00001000)
1039 #define INT_SERVICE (0x00002000)
1040 #define INT_TABORTSENT (0x00004000)
1041 #define INT_TABORTBM (0x00008000)
1042 #define INT_TIMEOUTBM (0x00010000)
1043 #define INT_PCIPARITY (0x00020000)
1044
1045
1046 #define INT_ALL (0x0003FFFE)
1047 #define INT_STATUS (0x0000003C)
1048 #define INT_DMASHUT (0x00038000)
1049 #define INT_SEGSHUT (0x00000700)
1050
1051 static inline u32 intr_pending(const struct lanai_dev *lanai)
1052 {
1053 return reg_read(lanai, IntStatusMasked_Reg);
1054 }
1055
1056 static inline void intr_enable(const struct lanai_dev *lanai, u32 i)
1057 {
1058 reg_write(lanai, i, IntControlEna_Reg);
1059 }
1060
1061 static inline void intr_disable(const struct lanai_dev *lanai, u32 i)
1062 {
1063 reg_write(lanai, i, IntControlDis_Reg);
1064 }
1065
1066
1067
1068 static void status_message(int itf, const char *name, int status)
1069 {
1070 static const char *onoff[2] = { "off to on", "on to off" };
1071 printk(KERN_INFO DEV_LABEL "(itf %d): %s changed from %s\n",
1072 itf, name, onoff[!status]);
1073 }
1074
1075 static void lanai_check_status(struct lanai_dev *lanai)
1076 {
1077 u32 new = reg_read(lanai, Status_Reg);
1078 u32 changes = new ^ lanai->status;
1079 lanai->status = new;
1080 #define e(flag, name) \
1081 if (changes & flag) \
1082 status_message(lanai->number, name, new & flag)
1083 e(STATUS_SOOL, "SOOL");
1084 e(STATUS_LOCD, "LOCD");
1085 e(STATUS_LED, "LED");
1086 e(STATUS_GPIN, "GPIN");
1087 #undef e
1088 }
1089
1090 static void pcistatus_got(int itf, const char *name)
1091 {
1092 printk(KERN_INFO DEV_LABEL "(itf %d): PCI got %s error\n", itf, name);
1093 }
1094
1095 static void pcistatus_check(struct lanai_dev *lanai, int clearonly)
1096 {
1097 u16 s;
1098 int result;
1099 result = pci_read_config_word(lanai->pci, PCI_STATUS, &s);
1100 if (result != PCIBIOS_SUCCESSFUL) {
1101 printk(KERN_ERR DEV_LABEL "(itf %d): can't read PCI_STATUS: "
1102 "%d\n", lanai->number, result);
1103 return;
1104 }
1105 s &= PCI_STATUS_DETECTED_PARITY | PCI_STATUS_SIG_SYSTEM_ERROR |
1106 PCI_STATUS_REC_MASTER_ABORT | PCI_STATUS_REC_TARGET_ABORT |
1107 PCI_STATUS_SIG_TARGET_ABORT | PCI_STATUS_PARITY;
1108 if (s == 0)
1109 return;
1110 result = pci_write_config_word(lanai->pci, PCI_STATUS, s);
1111 if (result != PCIBIOS_SUCCESSFUL)
1112 printk(KERN_ERR DEV_LABEL "(itf %d): can't write PCI_STATUS: "
1113 "%d\n", lanai->number, result);
1114 if (clearonly)
1115 return;
1116 #define e(flag, name, stat) \
1117 if (s & flag) { \
1118 pcistatus_got(lanai->number, name); \
1119 ++lanai->stats.pcierr_##stat; \
1120 }
1121 e(PCI_STATUS_DETECTED_PARITY, "parity", parity_detect);
1122 e(PCI_STATUS_SIG_SYSTEM_ERROR, "signalled system", serr_set);
1123 e(PCI_STATUS_REC_MASTER_ABORT, "master", master_abort);
1124 e(PCI_STATUS_REC_TARGET_ABORT, "master target", m_target_abort);
1125 e(PCI_STATUS_SIG_TARGET_ABORT, "slave", s_target_abort);
1126 e(PCI_STATUS_PARITY, "master parity", master_parity);
1127 #undef e
1128 }
1129
1130
1131
1132
1133 static inline int vcc_tx_space(const struct lanai_vcc *lvcc, int endptr)
1134 {
1135 int r;
1136 r = endptr * 16;
1137 r -= ((unsigned long) lvcc->tx.buf.ptr) -
1138 ((unsigned long) lvcc->tx.buf.start);
1139 r -= 16;
1140 if (r < 0)
1141 r += lanai_buf_size(&lvcc->tx.buf);
1142 return r;
1143 }
1144
1145
1146 static inline int vcc_is_backlogged(const struct lanai_vcc *lvcc)
1147 {
1148 return !skb_queue_empty(&lvcc->tx.backlog);
1149 }
1150
1151
1152 #define DESCRIPTOR_MAGIC (0xD0000000)
1153 #define DESCRIPTOR_AAL5 (0x00008000)
1154 #define DESCRIPTOR_AAL5_STREAM (0x00004000)
1155 #define DESCRIPTOR_CLP (0x00002000)
1156
1157
1158 static inline void vcc_tx_add_aal5_descriptor(struct lanai_vcc *lvcc,
1159 u32 flags, int len)
1160 {
1161 int pos;
1162 APRINTK((((unsigned long) lvcc->tx.buf.ptr) & 15) == 0,
1163 "vcc_tx_add_aal5_descriptor: bad ptr=%p\n", lvcc->tx.buf.ptr);
1164 lvcc->tx.buf.ptr += 4;
1165 pos = ((unsigned char *) lvcc->tx.buf.ptr) -
1166 (unsigned char *) lvcc->tx.buf.start;
1167 APRINTK((pos & ~0x0001FFF0) == 0,
1168 "vcc_tx_add_aal5_descriptor: bad pos (%d) before, vci=%d, "
1169 "start,ptr,end=%p,%p,%p\n", pos, lvcc->vci,
1170 lvcc->tx.buf.start, lvcc->tx.buf.ptr, lvcc->tx.buf.end);
1171 pos = (pos + len) & (lanai_buf_size(&lvcc->tx.buf) - 1);
1172 APRINTK((pos & ~0x0001FFF0) == 0,
1173 "vcc_tx_add_aal5_descriptor: bad pos (%d) after, vci=%d, "
1174 "start,ptr,end=%p,%p,%p\n", pos, lvcc->vci,
1175 lvcc->tx.buf.start, lvcc->tx.buf.ptr, lvcc->tx.buf.end);
1176 lvcc->tx.buf.ptr[-1] =
1177 cpu_to_le32(DESCRIPTOR_MAGIC | DESCRIPTOR_AAL5 |
1178 ((lvcc->tx.atmvcc->atm_options & ATM_ATMOPT_CLP) ?
1179 DESCRIPTOR_CLP : 0) | flags | pos >> 4);
1180 if (lvcc->tx.buf.ptr >= lvcc->tx.buf.end)
1181 lvcc->tx.buf.ptr = lvcc->tx.buf.start;
1182 }
1183
1184
1185 static inline void vcc_tx_add_aal5_trailer(struct lanai_vcc *lvcc,
1186 int len, int cpi, int uu)
1187 {
1188 APRINTK((((unsigned long) lvcc->tx.buf.ptr) & 15) == 8,
1189 "vcc_tx_add_aal5_trailer: bad ptr=%p\n", lvcc->tx.buf.ptr);
1190 lvcc->tx.buf.ptr += 2;
1191 lvcc->tx.buf.ptr[-2] = cpu_to_be32((uu << 24) | (cpi << 16) | len);
1192 if (lvcc->tx.buf.ptr >= lvcc->tx.buf.end)
1193 lvcc->tx.buf.ptr = lvcc->tx.buf.start;
1194 }
1195
1196 static inline void vcc_tx_memcpy(struct lanai_vcc *lvcc,
1197 const unsigned char *src, int n)
1198 {
1199 unsigned char *e;
1200 int m;
1201 e = ((unsigned char *) lvcc->tx.buf.ptr) + n;
1202 m = e - (unsigned char *) lvcc->tx.buf.end;
1203 if (m < 0)
1204 m = 0;
1205 memcpy(lvcc->tx.buf.ptr, src, n - m);
1206 if (m != 0) {
1207 memcpy(lvcc->tx.buf.start, src + n - m, m);
1208 e = ((unsigned char *) lvcc->tx.buf.start) + m;
1209 }
1210 lvcc->tx.buf.ptr = (u32 *) e;
1211 }
1212
1213 static inline void vcc_tx_memzero(struct lanai_vcc *lvcc, int n)
1214 {
1215 unsigned char *e;
1216 int m;
1217 if (n == 0)
1218 return;
1219 e = ((unsigned char *) lvcc->tx.buf.ptr) + n;
1220 m = e - (unsigned char *) lvcc->tx.buf.end;
1221 if (m < 0)
1222 m = 0;
1223 memset(lvcc->tx.buf.ptr, 0, n - m);
1224 if (m != 0) {
1225 memset(lvcc->tx.buf.start, 0, m);
1226 e = ((unsigned char *) lvcc->tx.buf.start) + m;
1227 }
1228 lvcc->tx.buf.ptr = (u32 *) e;
1229 }
1230
1231
1232 static inline void lanai_endtx(struct lanai_dev *lanai,
1233 const struct lanai_vcc *lvcc)
1234 {
1235 int i, ptr = ((unsigned char *) lvcc->tx.buf.ptr) -
1236 (unsigned char *) lvcc->tx.buf.start;
1237 APRINTK((ptr & ~0x0001FFF0) == 0,
1238 "lanai_endtx: bad ptr (%d), vci=%d, start,ptr,end=%p,%p,%p\n",
1239 ptr, lvcc->vci, lvcc->tx.buf.start, lvcc->tx.buf.ptr,
1240 lvcc->tx.buf.end);
1241
1242
1243
1244
1245
1246
1247
1248 spin_lock(&lanai->endtxlock);
1249
1250
1251
1252
1253
1254
1255 for (i = 0; reg_read(lanai, Status_Reg) & STATUS_BUTTBUSY; i++) {
1256 if (unlikely(i > 50)) {
1257 printk(KERN_ERR DEV_LABEL "(itf %d): butt register "
1258 "always busy!\n", lanai->number);
1259 break;
1260 }
1261 udelay(5);
1262 }
1263
1264
1265
1266
1267
1268 wmb();
1269 reg_write(lanai, (ptr << 12) | lvcc->vci, Butt_Reg);
1270 spin_unlock(&lanai->endtxlock);
1271 }
1272
1273
1274
1275
1276
1277 static void lanai_send_one_aal5(struct lanai_dev *lanai,
1278 struct lanai_vcc *lvcc, struct sk_buff *skb, int pdusize)
1279 {
1280 int pad;
1281 APRINTK(pdusize == aal5_size(skb->len),
1282 "lanai_send_one_aal5: wrong size packet (%d != %d)\n",
1283 pdusize, aal5_size(skb->len));
1284 vcc_tx_add_aal5_descriptor(lvcc, 0, pdusize);
1285 pad = pdusize - skb->len - 8;
1286 APRINTK(pad >= 0, "pad is negative (%d)\n", pad);
1287 APRINTK(pad < 48, "pad is too big (%d)\n", pad);
1288 vcc_tx_memcpy(lvcc, skb->data, skb->len);
1289 vcc_tx_memzero(lvcc, pad);
1290 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
1291 lanai_endtx(lanai, lvcc);
1292 lanai_free_skb(lvcc->tx.atmvcc, skb);
1293 atomic_inc(&lvcc->tx.atmvcc->stats->tx);
1294 }
1295
1296
1297 static void vcc_tx_unqueue_aal5(struct lanai_dev *lanai,
1298 struct lanai_vcc *lvcc, int endptr)
1299 {
1300 int n;
1301 struct sk_buff *skb;
1302 int space = vcc_tx_space(lvcc, endptr);
1303 APRINTK(vcc_is_backlogged(lvcc),
1304 "vcc_tx_unqueue() called with empty backlog (vci=%d)\n",
1305 lvcc->vci);
1306 while (space >= 64) {
1307 skb = skb_dequeue(&lvcc->tx.backlog);
1308 if (skb == NULL)
1309 goto no_backlog;
1310 n = aal5_size(skb->len);
1311 if (n + 16 > space) {
1312
1313 skb_queue_head(&lvcc->tx.backlog, skb);
1314 return;
1315 }
1316 lanai_send_one_aal5(lanai, lvcc, skb, n);
1317 space -= n + 16;
1318 }
1319 if (!vcc_is_backlogged(lvcc)) {
1320 no_backlog:
1321 __clear_bit(lvcc->vci, lanai->backlog_vccs);
1322 }
1323 }
1324
1325
1326 static void vcc_tx_aal5(struct lanai_dev *lanai, struct lanai_vcc *lvcc,
1327 struct sk_buff *skb)
1328 {
1329 int space, n;
1330 if (vcc_is_backlogged(lvcc))
1331 goto queue_it;
1332 space = vcc_tx_space(lvcc,
1333 TXREADPTR_GET_PTR(cardvcc_read(lvcc, vcc_txreadptr)));
1334 n = aal5_size(skb->len);
1335 APRINTK(n + 16 >= 64, "vcc_tx_aal5: n too small (%d)\n", n);
1336 if (space < n + 16) {
1337 __set_bit(lvcc->vci, lanai->backlog_vccs);
1338 queue_it:
1339 skb_queue_tail(&lvcc->tx.backlog, skb);
1340 return;
1341 }
1342 lanai_send_one_aal5(lanai, lvcc, skb, n);
1343 }
1344
1345 static void vcc_tx_unqueue_aal0(struct lanai_dev *lanai,
1346 struct lanai_vcc *lvcc, int endptr)
1347 {
1348 printk(KERN_INFO DEV_LABEL
1349 ": vcc_tx_unqueue_aal0: not implemented\n");
1350 }
1351
1352 static void vcc_tx_aal0(struct lanai_dev *lanai, struct lanai_vcc *lvcc,
1353 struct sk_buff *skb)
1354 {
1355 printk(KERN_INFO DEV_LABEL ": vcc_tx_aal0: not implemented\n");
1356
1357 lanai_free_skb(lvcc->tx.atmvcc, skb);
1358 }
1359
1360
1361
1362
1363 static inline void vcc_rx_memcpy(unsigned char *dest,
1364 const struct lanai_vcc *lvcc, int n)
1365 {
1366 int m = ((const unsigned char *) lvcc->rx.buf.ptr) + n -
1367 ((const unsigned char *) (lvcc->rx.buf.end));
1368 if (m < 0)
1369 m = 0;
1370 memcpy(dest, lvcc->rx.buf.ptr, n - m);
1371 memcpy(dest + n - m, lvcc->rx.buf.start, m);
1372
1373 barrier();
1374 }
1375
1376
1377 static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
1378 {
1379 int size;
1380 struct sk_buff *skb;
1381 const u32 *x;
1382 u32 *end = &lvcc->rx.buf.start[endptr * 4];
1383 int n = ((unsigned long) end) - ((unsigned long) lvcc->rx.buf.ptr);
1384 if (n < 0)
1385 n += lanai_buf_size(&lvcc->rx.buf);
1386 APRINTK(n >= 0 && n < lanai_buf_size(&lvcc->rx.buf) && !(n & 15),
1387 "vcc_rx_aal5: n out of range (%d/%zu)\n",
1388 n, lanai_buf_size(&lvcc->rx.buf));
1389
1390 if ((x = &end[-2]) < lvcc->rx.buf.start)
1391 x = &lvcc->rx.buf.end[-2];
1392
1393
1394
1395
1396 rmb();
1397 size = be32_to_cpup(x) & 0xffff;
1398 if (unlikely(n != aal5_size(size))) {
1399
1400 printk(KERN_INFO DEV_LABEL "(itf %d): Got bad AAL5 length "
1401 "on vci=%d - size=%d n=%d\n",
1402 lvcc->rx.atmvcc->dev->number, lvcc->vci, size, n);
1403 lvcc->stats.x.aal5.rx_badlen++;
1404 goto out;
1405 }
1406 skb = atm_alloc_charge(lvcc->rx.atmvcc, size, GFP_ATOMIC);
1407 if (unlikely(skb == NULL)) {
1408 lvcc->stats.rx_nomem++;
1409 goto out;
1410 }
1411 skb_put(skb, size);
1412 vcc_rx_memcpy(skb->data, lvcc, size);
1413 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
1414 __net_timestamp(skb);
1415 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
1416 atomic_inc(&lvcc->rx.atmvcc->stats->rx);
1417 out:
1418 lvcc->rx.buf.ptr = end;
1419 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
1420 }
1421
1422 static void vcc_rx_aal0(struct lanai_dev *lanai)
1423 {
1424 printk(KERN_INFO DEV_LABEL ": vcc_rx_aal0: not implemented\n");
1425
1426
1427 }
1428
1429
1430
1431
1432 #if (NUM_VCI * BITS_PER_LONG) <= PAGE_SIZE
1433 #define VCCTABLE_GETFREEPAGE
1434 #else
1435 #include <linux/vmalloc.h>
1436 #endif
1437
1438 static int vcc_table_allocate(struct lanai_dev *lanai)
1439 {
1440 #ifdef VCCTABLE_GETFREEPAGE
1441 APRINTK((lanai->num_vci) * sizeof(struct lanai_vcc *) <= PAGE_SIZE,
1442 "vcc table > PAGE_SIZE!");
1443 lanai->vccs = (struct lanai_vcc **) get_zeroed_page(GFP_KERNEL);
1444 return (lanai->vccs == NULL) ? -ENOMEM : 0;
1445 #else
1446 int bytes = (lanai->num_vci) * sizeof(struct lanai_vcc *);
1447 lanai->vccs = vzalloc(bytes);
1448 if (unlikely(lanai->vccs == NULL))
1449 return -ENOMEM;
1450 return 0;
1451 #endif
1452 }
1453
1454 static inline void vcc_table_deallocate(const struct lanai_dev *lanai)
1455 {
1456 #ifdef VCCTABLE_GETFREEPAGE
1457 free_page((unsigned long) lanai->vccs);
1458 #else
1459 vfree(lanai->vccs);
1460 #endif
1461 }
1462
1463
1464 static inline struct lanai_vcc *new_lanai_vcc(void)
1465 {
1466 struct lanai_vcc *lvcc;
1467 lvcc = kzalloc(sizeof(*lvcc), GFP_KERNEL);
1468 if (likely(lvcc != NULL)) {
1469 skb_queue_head_init(&lvcc->tx.backlog);
1470 #ifdef DEBUG
1471 lvcc->vci = -1;
1472 #endif
1473 }
1474 return lvcc;
1475 }
1476
1477 static int lanai_get_sized_buffer(struct lanai_dev *lanai,
1478 struct lanai_buffer *buf, int max_sdu, int multiplier,
1479 const char *name)
1480 {
1481 int size;
1482 if (unlikely(max_sdu < 1))
1483 max_sdu = 1;
1484 max_sdu = aal5_size(max_sdu);
1485 size = (max_sdu + 16) * multiplier + 16;
1486 lanai_buf_allocate(buf, size, max_sdu + 32, lanai->pci);
1487 if (unlikely(buf->start == NULL))
1488 return -ENOMEM;
1489 if (unlikely(lanai_buf_size(buf) < size))
1490 printk(KERN_WARNING DEV_LABEL "(itf %d): wanted %d bytes "
1491 "for %s buffer, got only %zu\n", lanai->number, size,
1492 name, lanai_buf_size(buf));
1493 DPRINTK("Allocated %zu byte %s buffer\n", lanai_buf_size(buf), name);
1494 return 0;
1495 }
1496
1497
1498 static inline int lanai_setup_rx_vci_aal5(struct lanai_dev *lanai,
1499 struct lanai_vcc *lvcc, const struct atm_qos *qos)
1500 {
1501 return lanai_get_sized_buffer(lanai, &lvcc->rx.buf,
1502 qos->rxtp.max_sdu, AAL5_RX_MULTIPLIER, "RX");
1503 }
1504
1505
1506 static int lanai_setup_tx_vci(struct lanai_dev *lanai, struct lanai_vcc *lvcc,
1507 const struct atm_qos *qos)
1508 {
1509 int max_sdu, multiplier;
1510 if (qos->aal == ATM_AAL0) {
1511 lvcc->tx.unqueue = vcc_tx_unqueue_aal0;
1512 max_sdu = ATM_CELL_SIZE - 1;
1513 multiplier = AAL0_TX_MULTIPLIER;
1514 } else {
1515 lvcc->tx.unqueue = vcc_tx_unqueue_aal5;
1516 max_sdu = qos->txtp.max_sdu;
1517 multiplier = AAL5_TX_MULTIPLIER;
1518 }
1519 return lanai_get_sized_buffer(lanai, &lvcc->tx.buf, max_sdu,
1520 multiplier, "TX");
1521 }
1522
1523 static inline void host_vcc_bind(struct lanai_dev *lanai,
1524 struct lanai_vcc *lvcc, vci_t vci)
1525 {
1526 if (lvcc->vbase != NULL)
1527 return;
1528 DPRINTK("Binding vci %d\n", vci);
1529 #ifdef USE_POWERDOWN
1530 if (lanai->nbound++ == 0) {
1531 DPRINTK("Coming out of powerdown\n");
1532 lanai->conf1 &= ~CONFIG1_POWERDOWN;
1533 conf1_write(lanai);
1534 conf2_write(lanai);
1535 }
1536 #endif
1537 lvcc->vbase = cardvcc_addr(lanai, vci);
1538 lanai->vccs[lvcc->vci = vci] = lvcc;
1539 }
1540
1541 static inline void host_vcc_unbind(struct lanai_dev *lanai,
1542 struct lanai_vcc *lvcc)
1543 {
1544 if (lvcc->vbase == NULL)
1545 return;
1546 DPRINTK("Unbinding vci %d\n", lvcc->vci);
1547 lvcc->vbase = NULL;
1548 lanai->vccs[lvcc->vci] = NULL;
1549 #ifdef USE_POWERDOWN
1550 if (--lanai->nbound == 0) {
1551 DPRINTK("Going into powerdown\n");
1552 lanai->conf1 |= CONFIG1_POWERDOWN;
1553 conf1_write(lanai);
1554 }
1555 #endif
1556 }
1557
1558
1559
1560 static void lanai_reset(struct lanai_dev *lanai)
1561 {
1562 printk(KERN_CRIT DEV_LABEL "(itf %d): *NOT* resetting - not "
1563 "implemented\n", lanai->number);
1564
1565
1566
1567
1568
1569 reg_write(lanai, INT_ALL, IntAck_Reg);
1570 lanai->stats.card_reset++;
1571 }
1572
1573
1574
1575
1576
1577
1578 static int service_buffer_allocate(struct lanai_dev *lanai)
1579 {
1580 lanai_buf_allocate(&lanai->service, SERVICE_ENTRIES * 4, 8,
1581 lanai->pci);
1582 if (unlikely(lanai->service.start == NULL))
1583 return -ENOMEM;
1584 DPRINTK("allocated service buffer at %p, size %zu(%d)\n",
1585 lanai->service.start,
1586 lanai_buf_size(&lanai->service),
1587 lanai_buf_size_cardorder(&lanai->service));
1588
1589 reg_write(lanai, 0, ServWrite_Reg);
1590
1591 reg_write(lanai,
1592 SSTUFF_SET_SIZE(lanai_buf_size_cardorder(&lanai->service)) |
1593 SSTUFF_SET_ADDR(lanai->service.dmaaddr),
1594 ServiceStuff_Reg);
1595 return 0;
1596 }
1597
1598 static inline void service_buffer_deallocate(struct lanai_dev *lanai)
1599 {
1600 lanai_buf_deallocate(&lanai->service, lanai->pci);
1601 }
1602
1603
1604 #define SERVICE_TX (0x80000000)
1605 #define SERVICE_TRASH (0x40000000)
1606 #define SERVICE_CRCERR (0x20000000)
1607 #define SERVICE_CI (0x10000000)
1608 #define SERVICE_CLP (0x08000000)
1609 #define SERVICE_STREAM (0x04000000)
1610 #define SERVICE_GET_VCI(x) (((x)>>16)&0x3FF)
1611 #define SERVICE_GET_END(x) ((x)&0x1FFF)
1612
1613
1614
1615
1616 static int handle_service(struct lanai_dev *lanai, u32 s)
1617 {
1618 vci_t vci = SERVICE_GET_VCI(s);
1619 struct lanai_vcc *lvcc;
1620 read_lock(&vcc_sklist_lock);
1621 lvcc = lanai->vccs[vci];
1622 if (unlikely(lvcc == NULL)) {
1623 read_unlock(&vcc_sklist_lock);
1624 DPRINTK("(itf %d) got service entry 0x%X for nonexistent "
1625 "vcc %d\n", lanai->number, (unsigned int) s, vci);
1626 if (s & SERVICE_TX)
1627 lanai->stats.service_notx++;
1628 else
1629 lanai->stats.service_norx++;
1630 return 0;
1631 }
1632 if (s & SERVICE_TX) {
1633 if (unlikely(lvcc->tx.atmvcc == NULL)) {
1634 read_unlock(&vcc_sklist_lock);
1635 DPRINTK("(itf %d) got service entry 0x%X for non-TX "
1636 "vcc %d\n", lanai->number, (unsigned int) s, vci);
1637 lanai->stats.service_notx++;
1638 return 0;
1639 }
1640 __set_bit(vci, lanai->transmit_ready);
1641 lvcc->tx.endptr = SERVICE_GET_END(s);
1642 read_unlock(&vcc_sklist_lock);
1643 return 1;
1644 }
1645 if (unlikely(lvcc->rx.atmvcc == NULL)) {
1646 read_unlock(&vcc_sklist_lock);
1647 DPRINTK("(itf %d) got service entry 0x%X for non-RX "
1648 "vcc %d\n", lanai->number, (unsigned int) s, vci);
1649 lanai->stats.service_norx++;
1650 return 0;
1651 }
1652 if (unlikely(lvcc->rx.atmvcc->qos.aal != ATM_AAL5)) {
1653 read_unlock(&vcc_sklist_lock);
1654 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
1655 "vcc %d\n", lanai->number, (unsigned int) s, vci);
1656 lanai->stats.service_rxnotaal5++;
1657 atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
1658 return 0;
1659 }
1660 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
1661 vcc_rx_aal5(lvcc, SERVICE_GET_END(s));
1662 read_unlock(&vcc_sklist_lock);
1663 return 0;
1664 }
1665 if (s & SERVICE_TRASH) {
1666 int bytes;
1667 read_unlock(&vcc_sklist_lock);
1668 DPRINTK("got trashed rx pdu on vci %d\n", vci);
1669 atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
1670 lvcc->stats.x.aal5.service_trash++;
1671 bytes = (SERVICE_GET_END(s) * 16) -
1672 (((unsigned long) lvcc->rx.buf.ptr) -
1673 ((unsigned long) lvcc->rx.buf.start)) + 47;
1674 if (bytes < 0)
1675 bytes += lanai_buf_size(&lvcc->rx.buf);
1676 lanai->stats.ovfl_trash += (bytes / 48);
1677 return 0;
1678 }
1679 if (s & SERVICE_STREAM) {
1680 read_unlock(&vcc_sklist_lock);
1681 atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
1682 lvcc->stats.x.aal5.service_stream++;
1683 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
1684 "PDU on VCI %d!\n", lanai->number, vci);
1685 lanai_reset(lanai);
1686 return 0;
1687 }
1688 DPRINTK("got rx crc error on vci %d\n", vci);
1689 atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
1690 lvcc->stats.x.aal5.service_rxcrc++;
1691 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
1692 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
1693 read_unlock(&vcc_sklist_lock);
1694 return 0;
1695 }
1696
1697
1698 static void iter_transmit(struct lanai_dev *lanai, vci_t vci)
1699 {
1700 struct lanai_vcc *lvcc = lanai->vccs[vci];
1701 if (vcc_is_backlogged(lvcc))
1702 lvcc->tx.unqueue(lanai, lvcc, lvcc->tx.endptr);
1703 }
1704
1705
1706
1707
1708
1709 static void run_service(struct lanai_dev *lanai)
1710 {
1711 int ntx = 0;
1712 u32 wreg = reg_read(lanai, ServWrite_Reg);
1713 const u32 *end = lanai->service.start + wreg;
1714 while (lanai->service.ptr != end) {
1715 ntx += handle_service(lanai,
1716 le32_to_cpup(lanai->service.ptr++));
1717 if (lanai->service.ptr >= lanai->service.end)
1718 lanai->service.ptr = lanai->service.start;
1719 }
1720 reg_write(lanai, wreg, ServRead_Reg);
1721 if (ntx != 0) {
1722 read_lock(&vcc_sklist_lock);
1723 vci_bitfield_iterate(lanai, lanai->transmit_ready,
1724 iter_transmit);
1725 bitmap_zero(lanai->transmit_ready, NUM_VCI);
1726 read_unlock(&vcc_sklist_lock);
1727 }
1728 }
1729
1730
1731
1732 static void get_statistics(struct lanai_dev *lanai)
1733 {
1734 u32 statreg = reg_read(lanai, Statistics_Reg);
1735 lanai->stats.atm_ovfl += STATS_GET_FIFO_OVFL(statreg);
1736 lanai->stats.hec_err += STATS_GET_HEC_ERR(statreg);
1737 lanai->stats.vci_trash += STATS_GET_BAD_VCI(statreg);
1738 lanai->stats.ovfl_trash += STATS_GET_BUF_OVFL(statreg);
1739 }
1740
1741
1742
1743 #ifndef DEBUG_RW
1744
1745 static void iter_dequeue(struct lanai_dev *lanai, vci_t vci)
1746 {
1747 struct lanai_vcc *lvcc = lanai->vccs[vci];
1748 int endptr;
1749 if (lvcc == NULL || lvcc->tx.atmvcc == NULL ||
1750 !vcc_is_backlogged(lvcc)) {
1751 __clear_bit(vci, lanai->backlog_vccs);
1752 return;
1753 }
1754 endptr = TXREADPTR_GET_PTR(cardvcc_read(lvcc, vcc_txreadptr));
1755 lvcc->tx.unqueue(lanai, lvcc, endptr);
1756 }
1757 #endif
1758
1759 static void lanai_timed_poll(struct timer_list *t)
1760 {
1761 struct lanai_dev *lanai = from_timer(lanai, t, timer);
1762 #ifndef DEBUG_RW
1763 unsigned long flags;
1764 #ifdef USE_POWERDOWN
1765 if (lanai->conf1 & CONFIG1_POWERDOWN)
1766 return;
1767 #endif
1768 local_irq_save(flags);
1769
1770 if (spin_trylock(&lanai->servicelock)) {
1771 run_service(lanai);
1772 spin_unlock(&lanai->servicelock);
1773 }
1774
1775
1776 read_lock(&vcc_sklist_lock);
1777 vci_bitfield_iterate(lanai, lanai->backlog_vccs, iter_dequeue);
1778 read_unlock(&vcc_sklist_lock);
1779 local_irq_restore(flags);
1780
1781 get_statistics(lanai);
1782 #endif
1783 mod_timer(&lanai->timer, jiffies + LANAI_POLL_PERIOD);
1784 }
1785
1786 static inline void lanai_timed_poll_start(struct lanai_dev *lanai)
1787 {
1788 timer_setup(&lanai->timer, lanai_timed_poll, 0);
1789 lanai->timer.expires = jiffies + LANAI_POLL_PERIOD;
1790 add_timer(&lanai->timer);
1791 }
1792
1793 static inline void lanai_timed_poll_stop(struct lanai_dev *lanai)
1794 {
1795 del_timer_sync(&lanai->timer);
1796 }
1797
1798
1799
1800 static inline void lanai_int_1(struct lanai_dev *lanai, u32 reason)
1801 {
1802 u32 ack = 0;
1803 if (reason & INT_SERVICE) {
1804 ack = INT_SERVICE;
1805 spin_lock(&lanai->servicelock);
1806 run_service(lanai);
1807 spin_unlock(&lanai->servicelock);
1808 }
1809 if (reason & (INT_AAL0_STR | INT_AAL0)) {
1810 ack |= reason & (INT_AAL0_STR | INT_AAL0);
1811 vcc_rx_aal0(lanai);
1812 }
1813
1814 if (ack == reason)
1815 goto done;
1816 if (reason & INT_STATS) {
1817 reason &= ~INT_STATS;
1818 get_statistics(lanai);
1819 }
1820 if (reason & INT_STATUS) {
1821 ack |= reason & INT_STATUS;
1822 lanai_check_status(lanai);
1823 }
1824 if (unlikely(reason & INT_DMASHUT)) {
1825 printk(KERN_ERR DEV_LABEL "(itf %d): driver error - DMA "
1826 "shutdown, reason=0x%08X, address=0x%08X\n",
1827 lanai->number, (unsigned int) (reason & INT_DMASHUT),
1828 (unsigned int) reg_read(lanai, DMA_Addr_Reg));
1829 if (reason & INT_TABORTBM) {
1830 lanai_reset(lanai);
1831 return;
1832 }
1833 ack |= (reason & INT_DMASHUT);
1834 printk(KERN_ERR DEV_LABEL "(itf %d): re-enabling DMA\n",
1835 lanai->number);
1836 conf1_write(lanai);
1837 lanai->stats.dma_reenable++;
1838 pcistatus_check(lanai, 0);
1839 }
1840 if (unlikely(reason & INT_TABORTSENT)) {
1841 ack |= (reason & INT_TABORTSENT);
1842 printk(KERN_ERR DEV_LABEL "(itf %d): sent PCI target abort\n",
1843 lanai->number);
1844 pcistatus_check(lanai, 0);
1845 }
1846 if (unlikely(reason & INT_SEGSHUT)) {
1847 printk(KERN_ERR DEV_LABEL "(itf %d): driver error - "
1848 "segmentation shutdown, reason=0x%08X\n", lanai->number,
1849 (unsigned int) (reason & INT_SEGSHUT));
1850 lanai_reset(lanai);
1851 return;
1852 }
1853 if (unlikely(reason & (INT_PING | INT_WAKE))) {
1854 printk(KERN_ERR DEV_LABEL "(itf %d): driver error - "
1855 "unexpected interrupt 0x%08X, resetting\n",
1856 lanai->number,
1857 (unsigned int) (reason & (INT_PING | INT_WAKE)));
1858 lanai_reset(lanai);
1859 return;
1860 }
1861 #ifdef DEBUG
1862 if (unlikely(ack != reason)) {
1863 DPRINTK("unacked ints: 0x%08X\n",
1864 (unsigned int) (reason & ~ack));
1865 ack = reason;
1866 }
1867 #endif
1868 done:
1869 if (ack != 0)
1870 reg_write(lanai, ack, IntAck_Reg);
1871 }
1872
1873 static irqreturn_t lanai_int(int irq, void *devid)
1874 {
1875 struct lanai_dev *lanai = devid;
1876 u32 reason;
1877
1878 #ifdef USE_POWERDOWN
1879
1880
1881
1882
1883
1884 if (unlikely(lanai->conf1 & CONFIG1_POWERDOWN))
1885 return IRQ_NONE;
1886 #endif
1887
1888 reason = intr_pending(lanai);
1889 if (reason == 0)
1890 return IRQ_NONE;
1891
1892 do {
1893 if (unlikely(reason == 0xFFFFFFFF))
1894 break;
1895 lanai_int_1(lanai, reason);
1896 reason = intr_pending(lanai);
1897 } while (reason != 0);
1898
1899 return IRQ_HANDLED;
1900 }
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913 static int check_board_id_and_rev(const char *name, u32 val, int *revp)
1914 {
1915 DPRINTK("%s says board_id=%d, board_rev=%d\n", name,
1916 (int) RESET_GET_BOARD_ID(val),
1917 (int) RESET_GET_BOARD_REV(val));
1918 if (RESET_GET_BOARD_ID(val) != BOARD_ID_LANAI256) {
1919 printk(KERN_ERR DEV_LABEL ": Found %s board-id %d -- not a "
1920 "Lanai 25.6\n", name, (int) RESET_GET_BOARD_ID(val));
1921 return -ENODEV;
1922 }
1923 if (revp != NULL)
1924 *revp = RESET_GET_BOARD_REV(val);
1925 return 0;
1926 }
1927
1928
1929
1930 static int lanai_pci_start(struct lanai_dev *lanai)
1931 {
1932 struct pci_dev *pci = lanai->pci;
1933 int result;
1934
1935 if (pci_enable_device(pci) != 0) {
1936 printk(KERN_ERR DEV_LABEL "(itf %d): can't enable "
1937 "PCI device", lanai->number);
1938 return -ENXIO;
1939 }
1940 pci_set_master(pci);
1941 if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(32)) != 0) {
1942 printk(KERN_WARNING DEV_LABEL
1943 "(itf %d): No suitable DMA available.\n", lanai->number);
1944 return -EBUSY;
1945 }
1946 result = check_board_id_and_rev("PCI", pci->subsystem_device, NULL);
1947 if (result != 0)
1948 return result;
1949
1950 result = pci_write_config_byte(pci, PCI_LATENCY_TIMER, 0);
1951 if (result != PCIBIOS_SUCCESSFUL) {
1952 printk(KERN_ERR DEV_LABEL "(itf %d): can't write "
1953 "PCI_LATENCY_TIMER: %d\n", lanai->number, result);
1954 return -EINVAL;
1955 }
1956 pcistatus_check(lanai, 1);
1957 pcistatus_check(lanai, 0);
1958 return 0;
1959 }
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969 static inline int vci0_is_ok(struct lanai_dev *lanai,
1970 const struct atm_qos *qos)
1971 {
1972 if (qos->txtp.traffic_class == ATM_CBR || qos->aal == ATM_AAL0)
1973 return 0;
1974 if (qos->rxtp.traffic_class != ATM_NONE) {
1975 if (lanai->naal0 != 0)
1976 return 0;
1977 lanai->conf2 |= CONFIG2_VCI0_NORMAL;
1978 conf2_write_if_powerup(lanai);
1979 }
1980 return 1;
1981 }
1982
1983
1984
1985
1986 static int vci_is_ok(struct lanai_dev *lanai, vci_t vci,
1987 const struct atm_vcc *atmvcc)
1988 {
1989 const struct atm_qos *qos = &atmvcc->qos;
1990 const struct lanai_vcc *lvcc = lanai->vccs[vci];
1991 if (vci == 0 && !vci0_is_ok(lanai, qos))
1992 return 0;
1993 if (unlikely(lvcc != NULL)) {
1994 if (qos->rxtp.traffic_class != ATM_NONE &&
1995 lvcc->rx.atmvcc != NULL && lvcc->rx.atmvcc != atmvcc)
1996 return 0;
1997 if (qos->txtp.traffic_class != ATM_NONE &&
1998 lvcc->tx.atmvcc != NULL && lvcc->tx.atmvcc != atmvcc)
1999 return 0;
2000 if (qos->txtp.traffic_class == ATM_CBR &&
2001 lanai->cbrvcc != NULL && lanai->cbrvcc != atmvcc)
2002 return 0;
2003 }
2004 if (qos->aal == ATM_AAL0 && lanai->naal0 == 0 &&
2005 qos->rxtp.traffic_class != ATM_NONE) {
2006 const struct lanai_vcc *vci0 = lanai->vccs[0];
2007 if (vci0 != NULL && vci0->rx.atmvcc != NULL)
2008 return 0;
2009 lanai->conf2 &= ~CONFIG2_VCI0_NORMAL;
2010 conf2_write_if_powerup(lanai);
2011 }
2012 return 1;
2013 }
2014
2015 static int lanai_normalize_ci(struct lanai_dev *lanai,
2016 const struct atm_vcc *atmvcc, short *vpip, vci_t *vcip)
2017 {
2018 switch (*vpip) {
2019 case ATM_VPI_ANY:
2020 *vpip = 0;
2021 fallthrough;
2022 case 0:
2023 break;
2024 default:
2025 return -EADDRINUSE;
2026 }
2027 switch (*vcip) {
2028 case ATM_VCI_ANY:
2029 for (*vcip = ATM_NOT_RSV_VCI; *vcip < lanai->num_vci;
2030 (*vcip)++)
2031 if (vci_is_ok(lanai, *vcip, atmvcc))
2032 return 0;
2033 return -EADDRINUSE;
2034 default:
2035 if (*vcip >= lanai->num_vci || *vcip < 0 ||
2036 !vci_is_ok(lanai, *vcip, atmvcc))
2037 return -EADDRINUSE;
2038 }
2039 return 0;
2040 }
2041
2042
2043
2044
2045
2046
2047
2048
2049 #define CBRICG_FRAC_BITS (4)
2050 #define CBRICG_MAX (2046 << CBRICG_FRAC_BITS)
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067 static int pcr_to_cbricg(const struct atm_qos *qos)
2068 {
2069 int rounddown = 0;
2070 int x, icg, pcr = atm_pcr_goal(&qos->txtp);
2071 if (pcr == 0)
2072 return 0;
2073 if (pcr < 0) {
2074 rounddown = 1;
2075 pcr = -pcr;
2076 }
2077 x = pcr * 27;
2078 icg = (3125 << (9 + CBRICG_FRAC_BITS)) - (x << CBRICG_FRAC_BITS);
2079 if (rounddown)
2080 icg += x - 1;
2081 icg /= x;
2082 if (icg > CBRICG_MAX)
2083 icg = CBRICG_MAX;
2084 DPRINTK("pcr_to_cbricg: pcr=%d rounddown=%c icg=%d\n",
2085 pcr, rounddown ? 'Y' : 'N', icg);
2086 return icg;
2087 }
2088
2089 static inline void lanai_cbr_setup(struct lanai_dev *lanai)
2090 {
2091 reg_write(lanai, pcr_to_cbricg(&lanai->cbrvcc->qos), CBR_ICG_Reg);
2092 reg_write(lanai, lanai->cbrvcc->vci, CBR_PTR_Reg);
2093 lanai->conf2 |= CONFIG2_CBR_ENABLE;
2094 conf2_write(lanai);
2095 }
2096
2097 static inline void lanai_cbr_shutdown(struct lanai_dev *lanai)
2098 {
2099 lanai->conf2 &= ~CONFIG2_CBR_ENABLE;
2100 conf2_write(lanai);
2101 }
2102
2103
2104
2105
2106 static int lanai_dev_open(struct atm_dev *atmdev)
2107 {
2108 struct lanai_dev *lanai = (struct lanai_dev *) atmdev->dev_data;
2109 unsigned long raw_base;
2110 int result;
2111
2112 DPRINTK("In lanai_dev_open()\n");
2113
2114 lanai->number = atmdev->number;
2115 lanai->num_vci = NUM_VCI;
2116 bitmap_zero(lanai->backlog_vccs, NUM_VCI);
2117 bitmap_zero(lanai->transmit_ready, NUM_VCI);
2118 lanai->naal0 = 0;
2119 #ifdef USE_POWERDOWN
2120 lanai->nbound = 0;
2121 #endif
2122 lanai->cbrvcc = NULL;
2123 memset(&lanai->stats, 0, sizeof lanai->stats);
2124 spin_lock_init(&lanai->endtxlock);
2125 spin_lock_init(&lanai->servicelock);
2126 atmdev->ci_range.vpi_bits = 0;
2127 atmdev->ci_range.vci_bits = 0;
2128 while (1 << atmdev->ci_range.vci_bits < lanai->num_vci)
2129 atmdev->ci_range.vci_bits++;
2130 atmdev->link_rate = ATM_25_PCR;
2131
2132
2133 if ((result = lanai_pci_start(lanai)) != 0)
2134 goto error;
2135 raw_base = lanai->pci->resource[0].start;
2136 lanai->base = (bus_addr_t) ioremap(raw_base, LANAI_MAPPING_SIZE);
2137 if (lanai->base == NULL) {
2138 printk(KERN_ERR DEV_LABEL ": couldn't remap I/O space\n");
2139 result = -ENOMEM;
2140 goto error_pci;
2141 }
2142
2143 reset_board(lanai);
2144 lanai->conf1 = reg_read(lanai, Config1_Reg);
2145 lanai->conf1 &= ~(CONFIG1_GPOUT1 | CONFIG1_POWERDOWN |
2146 CONFIG1_MASK_LEDMODE);
2147 lanai->conf1 |= CONFIG1_SET_LEDMODE(LEDMODE_NOT_SOOL);
2148 reg_write(lanai, lanai->conf1 | CONFIG1_GPOUT1, Config1_Reg);
2149 udelay(1000);
2150 conf1_write(lanai);
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161 result = check_board_id_and_rev("register",
2162 reg_read(lanai, Reset_Reg), &lanai->board_rev);
2163 if (result != 0)
2164 goto error_unmap;
2165
2166
2167 if ((result = eeprom_read(lanai)) != 0)
2168 goto error_unmap;
2169 if ((result = eeprom_validate(lanai)) != 0)
2170 goto error_unmap;
2171
2172
2173 reg_write(lanai, lanai->conf1 | CONFIG1_GPOUT1, Config1_Reg);
2174 udelay(1000);
2175 conf1_write(lanai);
2176
2177 lanai->conf1 |= (CONFIG1_GPOUT2 | CONFIG1_GPOUT3 | CONFIG1_DMA_ENABLE);
2178 conf1_write(lanai);
2179
2180
2181 if ((result = sram_test_and_clear(lanai)) != 0)
2182 goto error_unmap;
2183
2184
2185 lanai->conf1 |= CONFIG1_DMA_ENABLE;
2186 conf1_write(lanai);
2187 if ((result = service_buffer_allocate(lanai)) != 0)
2188 goto error_unmap;
2189 if ((result = vcc_table_allocate(lanai)) != 0)
2190 goto error_service;
2191 lanai->conf2 = (lanai->num_vci >= 512 ? CONFIG2_HOWMANY : 0) |
2192 CONFIG2_HEC_DROP | CONFIG2_PTI7_MODE;
2193 conf2_write(lanai);
2194 reg_write(lanai, TX_FIFO_DEPTH, TxDepth_Reg);
2195 reg_write(lanai, 0, CBR_ICG_Reg);
2196 if ((result = request_irq(lanai->pci->irq, lanai_int, IRQF_SHARED,
2197 DEV_LABEL, lanai)) != 0) {
2198 printk(KERN_ERR DEV_LABEL ": can't allocate interrupt\n");
2199 goto error_vcctable;
2200 }
2201 mb();
2202 intr_enable(lanai, INT_ALL & ~(INT_PING | INT_WAKE));
2203
2204 lanai->conf1 = (lanai->conf1 & ~CONFIG1_MASK_LOOPMODE) |
2205 CONFIG1_SET_LOOPMODE(LOOPMODE_NORMAL) |
2206 CONFIG1_GPOUT2 | CONFIG1_GPOUT3;
2207 conf1_write(lanai);
2208 lanai->status = reg_read(lanai, Status_Reg);
2209
2210 #ifdef USE_POWERDOWN
2211 lanai->conf1 |= CONFIG1_POWERDOWN;
2212 conf1_write(lanai);
2213 #endif
2214 memcpy(atmdev->esi, eeprom_mac(lanai), ESI_LEN);
2215 lanai_timed_poll_start(lanai);
2216 printk(KERN_NOTICE DEV_LABEL "(itf %d): rev.%d, base=%p, irq=%u "
2217 "(%pMF)\n", lanai->number, (int) lanai->pci->revision,
2218 lanai->base, lanai->pci->irq, atmdev->esi);
2219 printk(KERN_NOTICE DEV_LABEL "(itf %d): LANAI%s, serialno=%u(0x%X), "
2220 "board_rev=%d\n", lanai->number,
2221 lanai->type==lanai2 ? "2" : "HB", (unsigned int) lanai->serialno,
2222 (unsigned int) lanai->serialno, lanai->board_rev);
2223 return 0;
2224
2225 error_vcctable:
2226 vcc_table_deallocate(lanai);
2227 error_service:
2228 service_buffer_deallocate(lanai);
2229 error_unmap:
2230 reset_board(lanai);
2231 #ifdef USE_POWERDOWN
2232 lanai->conf1 = reg_read(lanai, Config1_Reg) | CONFIG1_POWERDOWN;
2233 conf1_write(lanai);
2234 #endif
2235 iounmap(lanai->base);
2236 lanai->base = NULL;
2237 error_pci:
2238 pci_disable_device(lanai->pci);
2239 error:
2240 return result;
2241 }
2242
2243
2244
2245
2246 static void lanai_dev_close(struct atm_dev *atmdev)
2247 {
2248 struct lanai_dev *lanai = (struct lanai_dev *) atmdev->dev_data;
2249 if (lanai->base==NULL)
2250 return;
2251 printk(KERN_INFO DEV_LABEL "(itf %d): shutting down interface\n",
2252 lanai->number);
2253 lanai_timed_poll_stop(lanai);
2254 #ifdef USE_POWERDOWN
2255 lanai->conf1 = reg_read(lanai, Config1_Reg) & ~CONFIG1_POWERDOWN;
2256 conf1_write(lanai);
2257 #endif
2258 intr_disable(lanai, INT_ALL);
2259 free_irq(lanai->pci->irq, lanai);
2260 reset_board(lanai);
2261 #ifdef USE_POWERDOWN
2262 lanai->conf1 |= CONFIG1_POWERDOWN;
2263 conf1_write(lanai);
2264 #endif
2265 pci_disable_device(lanai->pci);
2266 vcc_table_deallocate(lanai);
2267 service_buffer_deallocate(lanai);
2268 iounmap(lanai->base);
2269 kfree(lanai);
2270 }
2271
2272
2273 static void lanai_close(struct atm_vcc *atmvcc)
2274 {
2275 struct lanai_vcc *lvcc = (struct lanai_vcc *) atmvcc->dev_data;
2276 struct lanai_dev *lanai = (struct lanai_dev *) atmvcc->dev->dev_data;
2277 if (lvcc == NULL)
2278 return;
2279 clear_bit(ATM_VF_READY, &atmvcc->flags);
2280 clear_bit(ATM_VF_PARTIAL, &atmvcc->flags);
2281 if (lvcc->rx.atmvcc == atmvcc) {
2282 lanai_shutdown_rx_vci(lvcc);
2283 if (atmvcc->qos.aal == ATM_AAL0) {
2284 if (--lanai->naal0 <= 0)
2285 aal0_buffer_free(lanai);
2286 } else
2287 lanai_buf_deallocate(&lvcc->rx.buf, lanai->pci);
2288 lvcc->rx.atmvcc = NULL;
2289 }
2290 if (lvcc->tx.atmvcc == atmvcc) {
2291 if (atmvcc == lanai->cbrvcc) {
2292 if (lvcc->vbase != NULL)
2293 lanai_cbr_shutdown(lanai);
2294 lanai->cbrvcc = NULL;
2295 }
2296 lanai_shutdown_tx_vci(lanai, lvcc);
2297 lanai_buf_deallocate(&lvcc->tx.buf, lanai->pci);
2298 lvcc->tx.atmvcc = NULL;
2299 }
2300 if (--lvcc->nref == 0) {
2301 host_vcc_unbind(lanai, lvcc);
2302 kfree(lvcc);
2303 }
2304 atmvcc->dev_data = NULL;
2305 clear_bit(ATM_VF_ADDR, &atmvcc->flags);
2306 }
2307
2308
2309 static int lanai_open(struct atm_vcc *atmvcc)
2310 {
2311 struct lanai_dev *lanai;
2312 struct lanai_vcc *lvcc;
2313 int result = 0;
2314 int vci = atmvcc->vci;
2315 short vpi = atmvcc->vpi;
2316
2317 if ((test_bit(ATM_VF_PARTIAL, &atmvcc->flags)) ||
2318 (vpi == ATM_VPI_UNSPEC) || (vci == ATM_VCI_UNSPEC))
2319 return -EINVAL;
2320 lanai = (struct lanai_dev *) atmvcc->dev->dev_data;
2321 result = lanai_normalize_ci(lanai, atmvcc, &vpi, &vci);
2322 if (unlikely(result != 0))
2323 goto out;
2324 set_bit(ATM_VF_ADDR, &atmvcc->flags);
2325 if (atmvcc->qos.aal != ATM_AAL0 && atmvcc->qos.aal != ATM_AAL5)
2326 return -EINVAL;
2327 DPRINTK(DEV_LABEL "(itf %d): open %d.%d\n", lanai->number,
2328 (int) vpi, vci);
2329 lvcc = lanai->vccs[vci];
2330 if (lvcc == NULL) {
2331 lvcc = new_lanai_vcc();
2332 if (unlikely(lvcc == NULL))
2333 return -ENOMEM;
2334 atmvcc->dev_data = lvcc;
2335 }
2336 lvcc->nref++;
2337 if (atmvcc->qos.rxtp.traffic_class != ATM_NONE) {
2338 APRINTK(lvcc->rx.atmvcc == NULL, "rx.atmvcc!=NULL, vci=%d\n",
2339 vci);
2340 if (atmvcc->qos.aal == ATM_AAL0) {
2341 if (lanai->naal0 == 0)
2342 result = aal0_buffer_allocate(lanai);
2343 } else
2344 result = lanai_setup_rx_vci_aal5(
2345 lanai, lvcc, &atmvcc->qos);
2346 if (unlikely(result != 0))
2347 goto out_free;
2348 lvcc->rx.atmvcc = atmvcc;
2349 lvcc->stats.rx_nomem = 0;
2350 lvcc->stats.x.aal5.rx_badlen = 0;
2351 lvcc->stats.x.aal5.service_trash = 0;
2352 lvcc->stats.x.aal5.service_stream = 0;
2353 lvcc->stats.x.aal5.service_rxcrc = 0;
2354 if (atmvcc->qos.aal == ATM_AAL0)
2355 lanai->naal0++;
2356 }
2357 if (atmvcc->qos.txtp.traffic_class != ATM_NONE) {
2358 APRINTK(lvcc->tx.atmvcc == NULL, "tx.atmvcc!=NULL, vci=%d\n",
2359 vci);
2360 result = lanai_setup_tx_vci(lanai, lvcc, &atmvcc->qos);
2361 if (unlikely(result != 0))
2362 goto out_free;
2363 lvcc->tx.atmvcc = atmvcc;
2364 if (atmvcc->qos.txtp.traffic_class == ATM_CBR) {
2365 APRINTK(lanai->cbrvcc == NULL,
2366 "cbrvcc!=NULL, vci=%d\n", vci);
2367 lanai->cbrvcc = atmvcc;
2368 }
2369 }
2370 host_vcc_bind(lanai, lvcc, vci);
2371
2372
2373
2374
2375 wmb();
2376 if (atmvcc == lvcc->rx.atmvcc)
2377 host_vcc_start_rx(lvcc);
2378 if (atmvcc == lvcc->tx.atmvcc) {
2379 host_vcc_start_tx(lvcc);
2380 if (lanai->cbrvcc == atmvcc)
2381 lanai_cbr_setup(lanai);
2382 }
2383 set_bit(ATM_VF_READY, &atmvcc->flags);
2384 return 0;
2385 out_free:
2386 lanai_close(atmvcc);
2387 out:
2388 return result;
2389 }
2390
2391 static int lanai_send(struct atm_vcc *atmvcc, struct sk_buff *skb)
2392 {
2393 struct lanai_vcc *lvcc = (struct lanai_vcc *) atmvcc->dev_data;
2394 struct lanai_dev *lanai = (struct lanai_dev *) atmvcc->dev->dev_data;
2395 unsigned long flags;
2396 if (unlikely(lvcc == NULL || lvcc->vbase == NULL ||
2397 lvcc->tx.atmvcc != atmvcc))
2398 goto einval;
2399 #ifdef DEBUG
2400 if (unlikely(skb == NULL)) {
2401 DPRINTK("lanai_send: skb==NULL for vci=%d\n", atmvcc->vci);
2402 goto einval;
2403 }
2404 if (unlikely(lanai == NULL)) {
2405 DPRINTK("lanai_send: lanai==NULL for vci=%d\n", atmvcc->vci);
2406 goto einval;
2407 }
2408 #endif
2409 ATM_SKB(skb)->vcc = atmvcc;
2410 switch (atmvcc->qos.aal) {
2411 case ATM_AAL5:
2412 read_lock_irqsave(&vcc_sklist_lock, flags);
2413 vcc_tx_aal5(lanai, lvcc, skb);
2414 read_unlock_irqrestore(&vcc_sklist_lock, flags);
2415 return 0;
2416 case ATM_AAL0:
2417 if (unlikely(skb->len != ATM_CELL_SIZE-1))
2418 goto einval;
2419
2420 cpu_to_be32s((u32 *) skb->data);
2421 read_lock_irqsave(&vcc_sklist_lock, flags);
2422 vcc_tx_aal0(lanai, lvcc, skb);
2423 read_unlock_irqrestore(&vcc_sklist_lock, flags);
2424 return 0;
2425 }
2426 DPRINTK("lanai_send: bad aal=%d on vci=%d\n", (int) atmvcc->qos.aal,
2427 atmvcc->vci);
2428 einval:
2429 lanai_free_skb(atmvcc, skb);
2430 return -EINVAL;
2431 }
2432
2433 static int lanai_change_qos(struct atm_vcc *atmvcc,
2434 struct atm_qos *qos, int flags)
2435 {
2436 return -EBUSY;
2437 }
2438
2439 #ifndef CONFIG_PROC_FS
2440 #define lanai_proc_read NULL
2441 #else
2442 static int lanai_proc_read(struct atm_dev *atmdev, loff_t *pos, char *page)
2443 {
2444 struct lanai_dev *lanai = (struct lanai_dev *) atmdev->dev_data;
2445 loff_t left = *pos;
2446 struct lanai_vcc *lvcc;
2447 if (left-- == 0)
2448 return sprintf(page, DEV_LABEL "(itf %d): chip=LANAI%s, "
2449 "serial=%u, magic=0x%08X, num_vci=%d\n",
2450 atmdev->number, lanai->type==lanai2 ? "2" : "HB",
2451 (unsigned int) lanai->serialno,
2452 (unsigned int) lanai->magicno, lanai->num_vci);
2453 if (left-- == 0)
2454 return sprintf(page, "revision: board=%d, pci_if=%d\n",
2455 lanai->board_rev, (int) lanai->pci->revision);
2456 if (left-- == 0)
2457 return sprintf(page, "EEPROM ESI: %pM\n",
2458 &lanai->eeprom[EEPROM_MAC]);
2459 if (left-- == 0)
2460 return sprintf(page, "status: SOOL=%d, LOCD=%d, LED=%d, "
2461 "GPIN=%d\n", (lanai->status & STATUS_SOOL) ? 1 : 0,
2462 (lanai->status & STATUS_LOCD) ? 1 : 0,
2463 (lanai->status & STATUS_LED) ? 1 : 0,
2464 (lanai->status & STATUS_GPIN) ? 1 : 0);
2465 if (left-- == 0)
2466 return sprintf(page, "global buffer sizes: service=%zu, "
2467 "aal0_rx=%zu\n", lanai_buf_size(&lanai->service),
2468 lanai->naal0 ? lanai_buf_size(&lanai->aal0buf) : 0);
2469 if (left-- == 0) {
2470 get_statistics(lanai);
2471 return sprintf(page, "cells in error: overflow=%u, "
2472 "closed_vci=%u, bad_HEC=%u, rx_fifo=%u\n",
2473 lanai->stats.ovfl_trash, lanai->stats.vci_trash,
2474 lanai->stats.hec_err, lanai->stats.atm_ovfl);
2475 }
2476 if (left-- == 0)
2477 return sprintf(page, "PCI errors: parity_detect=%u, "
2478 "master_abort=%u, master_target_abort=%u,\n",
2479 lanai->stats.pcierr_parity_detect,
2480 lanai->stats.pcierr_serr_set,
2481 lanai->stats.pcierr_m_target_abort);
2482 if (left-- == 0)
2483 return sprintf(page, " slave_target_abort=%u, "
2484 "master_parity=%u\n", lanai->stats.pcierr_s_target_abort,
2485 lanai->stats.pcierr_master_parity);
2486 if (left-- == 0)
2487 return sprintf(page, " no_tx=%u, "
2488 "no_rx=%u, bad_rx_aal=%u\n", lanai->stats.service_norx,
2489 lanai->stats.service_notx,
2490 lanai->stats.service_rxnotaal5);
2491 if (left-- == 0)
2492 return sprintf(page, "resets: dma=%u, card=%u\n",
2493 lanai->stats.dma_reenable, lanai->stats.card_reset);
2494
2495 read_lock(&vcc_sklist_lock);
2496 for (; ; left++) {
2497 if (left >= NUM_VCI) {
2498 left = 0;
2499 goto out;
2500 }
2501 if ((lvcc = lanai->vccs[left]) != NULL)
2502 break;
2503 (*pos)++;
2504 }
2505
2506 left = sprintf(page, "VCI %4d: nref=%d, rx_nomem=%u", (vci_t) left,
2507 lvcc->nref, lvcc->stats.rx_nomem);
2508 if (lvcc->rx.atmvcc != NULL) {
2509 left += sprintf(&page[left], ",\n rx_AAL=%d",
2510 lvcc->rx.atmvcc->qos.aal == ATM_AAL5 ? 5 : 0);
2511 if (lvcc->rx.atmvcc->qos.aal == ATM_AAL5)
2512 left += sprintf(&page[left], ", rx_buf_size=%zu, "
2513 "rx_bad_len=%u,\n rx_service_trash=%u, "
2514 "rx_service_stream=%u, rx_bad_crc=%u",
2515 lanai_buf_size(&lvcc->rx.buf),
2516 lvcc->stats.x.aal5.rx_badlen,
2517 lvcc->stats.x.aal5.service_trash,
2518 lvcc->stats.x.aal5.service_stream,
2519 lvcc->stats.x.aal5.service_rxcrc);
2520 }
2521 if (lvcc->tx.atmvcc != NULL)
2522 left += sprintf(&page[left], ",\n tx_AAL=%d, "
2523 "tx_buf_size=%zu, tx_qos=%cBR, tx_backlogged=%c",
2524 lvcc->tx.atmvcc->qos.aal == ATM_AAL5 ? 5 : 0,
2525 lanai_buf_size(&lvcc->tx.buf),
2526 lvcc->tx.atmvcc == lanai->cbrvcc ? 'C' : 'U',
2527 vcc_is_backlogged(lvcc) ? 'Y' : 'N');
2528 page[left++] = '\n';
2529 page[left] = '\0';
2530 out:
2531 read_unlock(&vcc_sklist_lock);
2532 return left;
2533 }
2534 #endif
2535
2536
2537
2538 static const struct atmdev_ops ops = {
2539 .dev_close = lanai_dev_close,
2540 .open = lanai_open,
2541 .close = lanai_close,
2542 .send = lanai_send,
2543 .phy_put = NULL,
2544 .phy_get = NULL,
2545 .change_qos = lanai_change_qos,
2546 .proc_read = lanai_proc_read,
2547 .owner = THIS_MODULE
2548 };
2549
2550
2551 static int lanai_init_one(struct pci_dev *pci,
2552 const struct pci_device_id *ident)
2553 {
2554 struct lanai_dev *lanai;
2555 struct atm_dev *atmdev;
2556 int result;
2557
2558 lanai = kzalloc(sizeof(*lanai), GFP_KERNEL);
2559 if (lanai == NULL) {
2560 printk(KERN_ERR DEV_LABEL
2561 ": couldn't allocate dev_data structure!\n");
2562 return -ENOMEM;
2563 }
2564
2565 atmdev = atm_dev_register(DEV_LABEL, &pci->dev, &ops, -1, NULL);
2566 if (atmdev == NULL) {
2567 printk(KERN_ERR DEV_LABEL
2568 ": couldn't register atm device!\n");
2569 kfree(lanai);
2570 return -EBUSY;
2571 }
2572
2573 atmdev->dev_data = lanai;
2574 lanai->pci = pci;
2575 lanai->type = (enum lanai_type) ident->device;
2576
2577 result = lanai_dev_open(atmdev);
2578 if (result != 0) {
2579 DPRINTK("lanai_start() failed, err=%d\n", -result);
2580 atm_dev_deregister(atmdev);
2581 kfree(lanai);
2582 }
2583 return result;
2584 }
2585
2586 static const struct pci_device_id lanai_pci_tbl[] = {
2587 { PCI_VDEVICE(EF, PCI_DEVICE_ID_EF_ATM_LANAI2) },
2588 { PCI_VDEVICE(EF, PCI_DEVICE_ID_EF_ATM_LANAIHB) },
2589 { 0, }
2590 };
2591 MODULE_DEVICE_TABLE(pci, lanai_pci_tbl);
2592
2593 static struct pci_driver lanai_driver = {
2594 .name = DEV_LABEL,
2595 .id_table = lanai_pci_tbl,
2596 .probe = lanai_init_one,
2597 };
2598
2599 module_pci_driver(lanai_driver);
2600
2601 MODULE_AUTHOR("Mitchell Blank Jr <mitch@sfgoth.com>");
2602 MODULE_DESCRIPTION("Efficient Networks Speedstream 3010 driver");
2603 MODULE_LICENSE("GPL");