2 $Id: fore200e.c,v 1.5 2000/04/14 10:10:34 davem Exp $
4 A FORE Systems 200E-series driver for ATM on Linux.
5 Christophe Lizzi (lizzi@cnam.fr), October 1999-March 2003.
7 Based on the PCA-200E driver from Uwe Dannowski (Uwe.Dannowski@inf.tu-dresden.de).
9 This driver simultaneously supports PCA-200E and SBA-200E adapters
10 on i386, alpha (untested), powerpc, sparc and sparc64 architectures.
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <linux/kernel.h>
29 #include <linux/slab.h>
30 #include <linux/init.h>
31 #include <linux/capability.h>
32 #include <linux/sched.h>
33 #include <linux/interrupt.h>
34 #include <linux/bitops.h>
35 #include <linux/pci.h>
36 #include <linux/module.h>
37 #include <linux/atmdev.h>
38 #include <linux/sonet.h>
39 #include <linux/atm_suni.h>
40 #include <linux/dma-mapping.h>
41 #include <linux/delay.h>
43 #include <asm/string.h>
47 #include <asm/byteorder.h>
48 #include <asm/uaccess.h>
49 #include <asm/atomic.h>
51 #ifdef CONFIG_ATM_FORE200E_SBA
52 #include <asm/idprom.h>
54 #include <asm/openprom.h>
55 #include <asm/oplib.h>
56 #include <asm/pgtable.h>
59 #if defined(CONFIG_ATM_FORE200E_USE_TASKLET) /* defer interrupt work to a tasklet */
60 #define FORE200E_USE_TASKLET
63 #if 0 /* enable the debugging code of the buffer supply queues */
64 #define FORE200E_BSQ_DEBUG
67 #if 1 /* ensure correct handling of 52-byte AAL0 SDUs expected by atmdump-like apps */
68 #define FORE200E_52BYTE_AAL0_SDU
74 #define FORE200E_VERSION "0.3e"
76 #define FORE200E "fore200e: "
78 #if 0 /* override .config */
79 #define CONFIG_ATM_FORE200E_DEBUG 1
81 #if defined(CONFIG_ATM_FORE200E_DEBUG) && (CONFIG_ATM_FORE200E_DEBUG > 0)
82 #define DPRINTK(level, format, args...) do { if (CONFIG_ATM_FORE200E_DEBUG >= (level)) \
83 printk(FORE200E format, ##args); } while (0)
85 #define DPRINTK(level, format, args...) do {} while (0)
89 #define FORE200E_ALIGN(addr, alignment) \
90 ((((unsigned long)(addr) + (alignment - 1)) & ~(alignment - 1)) - (unsigned long)(addr))
92 #define FORE200E_DMA_INDEX(dma_addr, type, index) ((dma_addr) + (index) * sizeof(type))
94 #define FORE200E_INDEX(virt_addr, type, index) (&((type *)(virt_addr))[ index ])
96 #define FORE200E_NEXT_ENTRY(index, modulo) (index = ++(index) % (modulo))
99 #define ASSERT(expr) if (!(expr)) { \
100 printk(FORE200E "assertion failed! %s[%d]: %s\n", \
101 __FUNCTION__, __LINE__, #expr); \
102 panic(FORE200E "%s", __FUNCTION__); \
105 #define ASSERT(expr) do {} while (0)
109 static const struct atmdev_ops fore200e_ops;
110 static const struct fore200e_bus fore200e_bus[];
112 static LIST_HEAD(fore200e_boards);
115 MODULE_AUTHOR("Christophe Lizzi - credits to Uwe Dannowski and Heikki Vatiainen");
116 MODULE_DESCRIPTION("FORE Systems 200E-series ATM driver - version " FORE200E_VERSION);
117 MODULE_SUPPORTED_DEVICE("PCA-200E, SBA-200E");
120 static const int fore200e_rx_buf_nbr[ BUFFER_SCHEME_NBR ][ BUFFER_MAGN_NBR ] = {
121 { BUFFER_S1_NBR, BUFFER_L1_NBR },
122 { BUFFER_S2_NBR, BUFFER_L2_NBR }
125 static const int fore200e_rx_buf_size[ BUFFER_SCHEME_NBR ][ BUFFER_MAGN_NBR ] = {
126 { BUFFER_S1_SIZE, BUFFER_L1_SIZE },
127 { BUFFER_S2_SIZE, BUFFER_L2_SIZE }
131 #if defined(CONFIG_ATM_FORE200E_DEBUG) && (CONFIG_ATM_FORE200E_DEBUG > 0)
132 static const char* fore200e_traffic_class[] = { "NONE", "UBR", "CBR", "VBR", "ABR", "ANY" };
136 #if 0 /* currently unused */
138 fore200e_fore2atm_aal(enum fore200e_aal aal)
141 case FORE200E_AAL0: return ATM_AAL0;
142 case FORE200E_AAL34: return ATM_AAL34;
143 case FORE200E_AAL5: return ATM_AAL5;
151 static enum fore200e_aal
152 fore200e_atm2fore_aal(int aal)
155 case ATM_AAL0: return FORE200E_AAL0;
156 case ATM_AAL34: return FORE200E_AAL34;
159 case ATM_AAL5: return FORE200E_AAL5;
167 fore200e_irq_itoa(int irq)
170 sprintf(str, "%d", irq);
175 /* allocate and align a chunk of memory intended to hold the data behing exchanged
176 between the driver and the adapter (using streaming DVMA) */
179 fore200e_chunk_alloc(struct fore200e* fore200e, struct chunk* chunk, int size, int alignment, int direction)
181 unsigned long offset = 0;
183 if (alignment <= sizeof(int))
186 chunk->alloc_size = size + alignment;
187 chunk->align_size = size;
188 chunk->direction = direction;
190 chunk->alloc_addr = kzalloc(chunk->alloc_size, GFP_KERNEL | GFP_DMA);
191 if (chunk->alloc_addr == NULL)
195 offset = FORE200E_ALIGN(chunk->alloc_addr, alignment);
197 chunk->align_addr = chunk->alloc_addr + offset;
199 chunk->dma_addr = fore200e->bus->dma_map(fore200e, chunk->align_addr, chunk->align_size, direction);
205 /* free a chunk of memory */
208 fore200e_chunk_free(struct fore200e* fore200e, struct chunk* chunk)
210 fore200e->bus->dma_unmap(fore200e, chunk->dma_addr, chunk->dma_size, chunk->direction);
212 kfree(chunk->alloc_addr);
217 fore200e_spin(int msecs)
219 unsigned long timeout = jiffies + msecs_to_jiffies(msecs);
220 while (time_before(jiffies, timeout));
225 fore200e_poll(struct fore200e* fore200e, volatile u32* addr, u32 val, int msecs)
227 unsigned long timeout = jiffies + msecs_to_jiffies(msecs);
232 if ((ok = (*addr == val)) || (*addr & STATUS_ERROR))
235 } while (time_before(jiffies, timeout));
239 printk(FORE200E "cmd polling failed, got status 0x%08x, expected 0x%08x\n",
249 fore200e_io_poll(struct fore200e* fore200e, volatile u32 __iomem *addr, u32 val, int msecs)
251 unsigned long timeout = jiffies + msecs_to_jiffies(msecs);
255 if ((ok = (fore200e->bus->read(addr) == val)))
258 } while (time_before(jiffies, timeout));
262 printk(FORE200E "I/O polling failed, got status 0x%08x, expected 0x%08x\n",
263 fore200e->bus->read(addr), val);
272 fore200e_free_rx_buf(struct fore200e* fore200e)
274 int scheme, magn, nbr;
275 struct buffer* buffer;
277 for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
278 for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
280 if ((buffer = fore200e->host_bsq[ scheme ][ magn ].buffer) != NULL) {
282 for (nbr = 0; nbr < fore200e_rx_buf_nbr[ scheme ][ magn ]; nbr++) {
284 struct chunk* data = &buffer[ nbr ].data;
286 if (data->alloc_addr != NULL)
287 fore200e_chunk_free(fore200e, data);
296 fore200e_uninit_bs_queue(struct fore200e* fore200e)
300 for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
301 for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
303 struct chunk* status = &fore200e->host_bsq[ scheme ][ magn ].status;
304 struct chunk* rbd_block = &fore200e->host_bsq[ scheme ][ magn ].rbd_block;
306 if (status->alloc_addr)
307 fore200e->bus->dma_chunk_free(fore200e, status);
309 if (rbd_block->alloc_addr)
310 fore200e->bus->dma_chunk_free(fore200e, rbd_block);
317 fore200e_reset(struct fore200e* fore200e, int diag)
321 fore200e->cp_monitor = fore200e->virt_base + FORE200E_CP_MONITOR_OFFSET;
323 fore200e->bus->write(BSTAT_COLD_START, &fore200e->cp_monitor->bstat);
325 fore200e->bus->reset(fore200e);
328 ok = fore200e_io_poll(fore200e, &fore200e->cp_monitor->bstat, BSTAT_SELFTEST_OK, 1000);
331 printk(FORE200E "device %s self-test failed\n", fore200e->name);
335 printk(FORE200E "device %s self-test passed\n", fore200e->name);
337 fore200e->state = FORE200E_STATE_RESET;
345 fore200e_shutdown(struct fore200e* fore200e)
347 printk(FORE200E "removing device %s at 0x%lx, IRQ %s\n",
348 fore200e->name, fore200e->phys_base,
349 fore200e_irq_itoa(fore200e->irq));
351 if (fore200e->state > FORE200E_STATE_RESET) {
352 /* first, reset the board to prevent further interrupts or data transfers */
353 fore200e_reset(fore200e, 0);
356 /* then, release all allocated resources */
357 switch(fore200e->state) {
359 case FORE200E_STATE_COMPLETE:
360 kfree(fore200e->stats);
362 case FORE200E_STATE_IRQ:
363 free_irq(fore200e->irq, fore200e->atm_dev);
365 case FORE200E_STATE_ALLOC_BUF:
366 fore200e_free_rx_buf(fore200e);
368 case FORE200E_STATE_INIT_BSQ:
369 fore200e_uninit_bs_queue(fore200e);
371 case FORE200E_STATE_INIT_RXQ:
372 fore200e->bus->dma_chunk_free(fore200e, &fore200e->host_rxq.status);
373 fore200e->bus->dma_chunk_free(fore200e, &fore200e->host_rxq.rpd);
375 case FORE200E_STATE_INIT_TXQ:
376 fore200e->bus->dma_chunk_free(fore200e, &fore200e->host_txq.status);
377 fore200e->bus->dma_chunk_free(fore200e, &fore200e->host_txq.tpd);
379 case FORE200E_STATE_INIT_CMDQ:
380 fore200e->bus->dma_chunk_free(fore200e, &fore200e->host_cmdq.status);
382 case FORE200E_STATE_INITIALIZE:
383 /* nothing to do for that state */
385 case FORE200E_STATE_START_FW:
386 /* nothing to do for that state */
388 case FORE200E_STATE_LOAD_FW:
389 /* nothing to do for that state */
391 case FORE200E_STATE_RESET:
392 /* nothing to do for that state */
394 case FORE200E_STATE_MAP:
395 fore200e->bus->unmap(fore200e);
397 case FORE200E_STATE_CONFIGURE:
398 /* nothing to do for that state */
400 case FORE200E_STATE_REGISTER:
401 /* XXX shouldn't we *start* by deregistering the device? */
402 atm_dev_deregister(fore200e->atm_dev);
404 case FORE200E_STATE_BLANK:
405 /* nothing to do for that state */
411 #ifdef CONFIG_ATM_FORE200E_PCA
413 static u32 fore200e_pca_read(volatile u32 __iomem *addr)
415 /* on big-endian hosts, the board is configured to convert
416 the endianess of slave RAM accesses */
417 return le32_to_cpu(readl(addr));
421 static void fore200e_pca_write(u32 val, volatile u32 __iomem *addr)
423 /* on big-endian hosts, the board is configured to convert
424 the endianess of slave RAM accesses */
425 writel(cpu_to_le32(val), addr);
430 fore200e_pca_dma_map(struct fore200e* fore200e, void* virt_addr, int size, int direction)
432 u32 dma_addr = pci_map_single((struct pci_dev*)fore200e->bus_dev, virt_addr, size, direction);
434 DPRINTK(3, "PCI DVMA mapping: virt_addr = 0x%p, size = %d, direction = %d, --> dma_addr = 0x%08x\n",
435 virt_addr, size, direction, dma_addr);
442 fore200e_pca_dma_unmap(struct fore200e* fore200e, u32 dma_addr, int size, int direction)
444 DPRINTK(3, "PCI DVMA unmapping: dma_addr = 0x%08x, size = %d, direction = %d\n",
445 dma_addr, size, direction);
447 pci_unmap_single((struct pci_dev*)fore200e->bus_dev, dma_addr, size, direction);
452 fore200e_pca_dma_sync_for_cpu(struct fore200e* fore200e, u32 dma_addr, int size, int direction)
454 DPRINTK(3, "PCI DVMA sync: dma_addr = 0x%08x, size = %d, direction = %d\n", dma_addr, size, direction);
456 pci_dma_sync_single_for_cpu((struct pci_dev*)fore200e->bus_dev, dma_addr, size, direction);
460 fore200e_pca_dma_sync_for_device(struct fore200e* fore200e, u32 dma_addr, int size, int direction)
462 DPRINTK(3, "PCI DVMA sync: dma_addr = 0x%08x, size = %d, direction = %d\n", dma_addr, size, direction);
464 pci_dma_sync_single_for_device((struct pci_dev*)fore200e->bus_dev, dma_addr, size, direction);
468 /* allocate a DMA consistent chunk of memory intended to act as a communication mechanism
469 (to hold descriptors, status, queues, etc.) shared by the driver and the adapter */
472 fore200e_pca_dma_chunk_alloc(struct fore200e* fore200e, struct chunk* chunk,
473 int size, int nbr, int alignment)
475 /* returned chunks are page-aligned */
476 chunk->alloc_size = size * nbr;
477 chunk->alloc_addr = pci_alloc_consistent((struct pci_dev*)fore200e->bus_dev,
481 if ((chunk->alloc_addr == NULL) || (chunk->dma_addr == 0))
484 chunk->align_addr = chunk->alloc_addr;
490 /* free a DMA consistent chunk of memory */
493 fore200e_pca_dma_chunk_free(struct fore200e* fore200e, struct chunk* chunk)
495 pci_free_consistent((struct pci_dev*)fore200e->bus_dev,
503 fore200e_pca_irq_check(struct fore200e* fore200e)
505 /* this is a 1 bit register */
506 int irq_posted = readl(fore200e->regs.pca.psr);
508 #if defined(CONFIG_ATM_FORE200E_DEBUG) && (CONFIG_ATM_FORE200E_DEBUG == 2)
509 if (irq_posted && (readl(fore200e->regs.pca.hcr) & PCA200E_HCR_OUTFULL)) {
510 DPRINTK(2,"FIFO OUT full, device %d\n", fore200e->atm_dev->number);
519 fore200e_pca_irq_ack(struct fore200e* fore200e)
521 writel(PCA200E_HCR_CLRINTR, fore200e->regs.pca.hcr);
526 fore200e_pca_reset(struct fore200e* fore200e)
528 writel(PCA200E_HCR_RESET, fore200e->regs.pca.hcr);
530 writel(0, fore200e->regs.pca.hcr);
535 fore200e_pca_map(struct fore200e* fore200e)
537 DPRINTK(2, "device %s being mapped in memory\n", fore200e->name);
539 fore200e->virt_base = ioremap(fore200e->phys_base, PCA200E_IOSPACE_LENGTH);
541 if (fore200e->virt_base == NULL) {
542 printk(FORE200E "can't map device %s\n", fore200e->name);
546 DPRINTK(1, "device %s mapped to 0x%p\n", fore200e->name, fore200e->virt_base);
548 /* gain access to the PCA specific registers */
549 fore200e->regs.pca.hcr = fore200e->virt_base + PCA200E_HCR_OFFSET;
550 fore200e->regs.pca.imr = fore200e->virt_base + PCA200E_IMR_OFFSET;
551 fore200e->regs.pca.psr = fore200e->virt_base + PCA200E_PSR_OFFSET;
553 fore200e->state = FORE200E_STATE_MAP;
559 fore200e_pca_unmap(struct fore200e* fore200e)
561 DPRINTK(2, "device %s being unmapped from memory\n", fore200e->name);
563 if (fore200e->virt_base != NULL)
564 iounmap(fore200e->virt_base);
569 fore200e_pca_configure(struct fore200e* fore200e)
571 struct pci_dev* pci_dev = (struct pci_dev*)fore200e->bus_dev;
572 u8 master_ctrl, latency;
574 DPRINTK(2, "device %s being configured\n", fore200e->name);
576 if ((pci_dev->irq == 0) || (pci_dev->irq == 0xFF)) {
577 printk(FORE200E "incorrect IRQ setting - misconfigured PCI-PCI bridge?\n");
581 pci_read_config_byte(pci_dev, PCA200E_PCI_MASTER_CTRL, &master_ctrl);
583 master_ctrl = master_ctrl
584 #if defined(__BIG_ENDIAN)
585 /* request the PCA board to convert the endianess of slave RAM accesses */
586 | PCA200E_CTRL_CONVERT_ENDIAN
589 | PCA200E_CTRL_DIS_CACHE_RD
590 | PCA200E_CTRL_DIS_WRT_INVAL
591 | PCA200E_CTRL_ENA_CONT_REQ_MODE
592 | PCA200E_CTRL_2_CACHE_WRT_INVAL
594 | PCA200E_CTRL_LARGE_PCI_BURSTS;
596 pci_write_config_byte(pci_dev, PCA200E_PCI_MASTER_CTRL, master_ctrl);
598 /* raise latency from 32 (default) to 192, as this seems to prevent NIC
599 lockups (under heavy rx loads) due to continuous 'FIFO OUT full' condition.
600 this may impact the performances of other PCI devices on the same bus, though */
602 pci_write_config_byte(pci_dev, PCI_LATENCY_TIMER, latency);
604 fore200e->state = FORE200E_STATE_CONFIGURE;
610 fore200e_pca_prom_read(struct fore200e* fore200e, struct prom_data* prom)
612 struct host_cmdq* cmdq = &fore200e->host_cmdq;
613 struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
614 struct prom_opcode opcode;
618 FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
620 opcode.opcode = OPCODE_GET_PROM;
623 prom_dma = fore200e->bus->dma_map(fore200e, prom, sizeof(struct prom_data), DMA_FROM_DEVICE);
625 fore200e->bus->write(prom_dma, &entry->cp_entry->cmd.prom_block.prom_haddr);
627 *entry->status = STATUS_PENDING;
629 fore200e->bus->write(*(u32*)&opcode, (u32 __iomem *)&entry->cp_entry->cmd.prom_block.opcode);
631 ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
633 *entry->status = STATUS_FREE;
635 fore200e->bus->dma_unmap(fore200e, prom_dma, sizeof(struct prom_data), DMA_FROM_DEVICE);
638 printk(FORE200E "unable to get PROM data from device %s\n", fore200e->name);
642 #if defined(__BIG_ENDIAN)
644 #define swap_here(addr) (*((u32*)(addr)) = swab32( *((u32*)(addr)) ))
646 /* MAC address is stored as little-endian */
647 swap_here(&prom->mac_addr[0]);
648 swap_here(&prom->mac_addr[4]);
656 fore200e_pca_proc_read(struct fore200e* fore200e, char *page)
658 struct pci_dev* pci_dev = (struct pci_dev*)fore200e->bus_dev;
660 return sprintf(page, " PCI bus/slot/function:\t%d/%d/%d\n",
661 pci_dev->bus->number, PCI_SLOT(pci_dev->devfn), PCI_FUNC(pci_dev->devfn));
664 #endif /* CONFIG_ATM_FORE200E_PCA */
667 #ifdef CONFIG_ATM_FORE200E_SBA
670 fore200e_sba_read(volatile u32 __iomem *addr)
672 return sbus_readl(addr);
677 fore200e_sba_write(u32 val, volatile u32 __iomem *addr)
679 sbus_writel(val, addr);
684 fore200e_sba_dma_map(struct fore200e* fore200e, void* virt_addr, int size, int direction)
686 u32 dma_addr = sbus_map_single((struct sbus_dev*)fore200e->bus_dev, virt_addr, size, direction);
688 DPRINTK(3, "SBUS DVMA mapping: virt_addr = 0x%p, size = %d, direction = %d --> dma_addr = 0x%08x\n",
689 virt_addr, size, direction, dma_addr);
696 fore200e_sba_dma_unmap(struct fore200e* fore200e, u32 dma_addr, int size, int direction)
698 DPRINTK(3, "SBUS DVMA unmapping: dma_addr = 0x%08x, size = %d, direction = %d,\n",
699 dma_addr, size, direction);
701 sbus_unmap_single((struct sbus_dev*)fore200e->bus_dev, dma_addr, size, direction);
706 fore200e_sba_dma_sync_for_cpu(struct fore200e* fore200e, u32 dma_addr, int size, int direction)
708 DPRINTK(3, "SBUS DVMA sync: dma_addr = 0x%08x, size = %d, direction = %d\n", dma_addr, size, direction);
710 sbus_dma_sync_single_for_cpu((struct sbus_dev*)fore200e->bus_dev, dma_addr, size, direction);
714 fore200e_sba_dma_sync_for_device(struct fore200e* fore200e, u32 dma_addr, int size, int direction)
716 DPRINTK(3, "SBUS DVMA sync: dma_addr = 0x%08x, size = %d, direction = %d\n", dma_addr, size, direction);
718 sbus_dma_sync_single_for_device((struct sbus_dev*)fore200e->bus_dev, dma_addr, size, direction);
722 /* allocate a DVMA consistent chunk of memory intended to act as a communication mechanism
723 (to hold descriptors, status, queues, etc.) shared by the driver and the adapter */
726 fore200e_sba_dma_chunk_alloc(struct fore200e* fore200e, struct chunk* chunk,
727 int size, int nbr, int alignment)
729 chunk->alloc_size = chunk->align_size = size * nbr;
731 /* returned chunks are page-aligned */
732 chunk->alloc_addr = sbus_alloc_consistent((struct sbus_dev*)fore200e->bus_dev,
736 if ((chunk->alloc_addr == NULL) || (chunk->dma_addr == 0))
739 chunk->align_addr = chunk->alloc_addr;
745 /* free a DVMA consistent chunk of memory */
748 fore200e_sba_dma_chunk_free(struct fore200e* fore200e, struct chunk* chunk)
750 sbus_free_consistent((struct sbus_dev*)fore200e->bus_dev,
758 fore200e_sba_irq_enable(struct fore200e* fore200e)
760 u32 hcr = fore200e->bus->read(fore200e->regs.sba.hcr) & SBA200E_HCR_STICKY;
761 fore200e->bus->write(hcr | SBA200E_HCR_INTR_ENA, fore200e->regs.sba.hcr);
766 fore200e_sba_irq_check(struct fore200e* fore200e)
768 return fore200e->bus->read(fore200e->regs.sba.hcr) & SBA200E_HCR_INTR_REQ;
773 fore200e_sba_irq_ack(struct fore200e* fore200e)
775 u32 hcr = fore200e->bus->read(fore200e->regs.sba.hcr) & SBA200E_HCR_STICKY;
776 fore200e->bus->write(hcr | SBA200E_HCR_INTR_CLR, fore200e->regs.sba.hcr);
781 fore200e_sba_reset(struct fore200e* fore200e)
783 fore200e->bus->write(SBA200E_HCR_RESET, fore200e->regs.sba.hcr);
785 fore200e->bus->write(0, fore200e->regs.sba.hcr);
790 fore200e_sba_map(struct fore200e* fore200e)
792 struct sbus_dev* sbus_dev = (struct sbus_dev*)fore200e->bus_dev;
795 /* gain access to the SBA specific registers */
796 fore200e->regs.sba.hcr = sbus_ioremap(&sbus_dev->resource[0], 0, SBA200E_HCR_LENGTH, "SBA HCR");
797 fore200e->regs.sba.bsr = sbus_ioremap(&sbus_dev->resource[1], 0, SBA200E_BSR_LENGTH, "SBA BSR");
798 fore200e->regs.sba.isr = sbus_ioremap(&sbus_dev->resource[2], 0, SBA200E_ISR_LENGTH, "SBA ISR");
799 fore200e->virt_base = sbus_ioremap(&sbus_dev->resource[3], 0, SBA200E_RAM_LENGTH, "SBA RAM");
801 if (fore200e->virt_base == NULL) {
802 printk(FORE200E "unable to map RAM of device %s\n", fore200e->name);
806 DPRINTK(1, "device %s mapped to 0x%p\n", fore200e->name, fore200e->virt_base);
808 fore200e->bus->write(0x02, fore200e->regs.sba.isr); /* XXX hardwired interrupt level */
810 /* get the supported DVMA burst sizes */
811 bursts = prom_getintdefault(sbus_dev->bus->prom_node, "burst-sizes", 0x00);
813 if (sbus_can_dma_64bit(sbus_dev))
814 sbus_set_sbus64(sbus_dev, bursts);
816 fore200e->state = FORE200E_STATE_MAP;
822 fore200e_sba_unmap(struct fore200e* fore200e)
824 sbus_iounmap(fore200e->regs.sba.hcr, SBA200E_HCR_LENGTH);
825 sbus_iounmap(fore200e->regs.sba.bsr, SBA200E_BSR_LENGTH);
826 sbus_iounmap(fore200e->regs.sba.isr, SBA200E_ISR_LENGTH);
827 sbus_iounmap(fore200e->virt_base, SBA200E_RAM_LENGTH);
832 fore200e_sba_configure(struct fore200e* fore200e)
834 fore200e->state = FORE200E_STATE_CONFIGURE;
839 static struct fore200e* __init
840 fore200e_sba_detect(const struct fore200e_bus* bus, int index)
842 struct fore200e* fore200e;
843 struct sbus_bus* sbus_bus;
844 struct sbus_dev* sbus_dev = NULL;
846 unsigned int count = 0;
848 for_each_sbus (sbus_bus) {
849 for_each_sbusdev (sbus_dev, sbus_bus) {
850 if (strcmp(sbus_dev->prom_name, SBA200E_PROM_NAME) == 0) {
860 if (sbus_dev->num_registers != 4) {
861 printk(FORE200E "this %s device has %d instead of 4 registers\n",
862 bus->model_name, sbus_dev->num_registers);
866 fore200e = kzalloc(sizeof(struct fore200e), GFP_KERNEL);
867 if (fore200e == NULL)
871 fore200e->bus_dev = sbus_dev;
872 fore200e->irq = sbus_dev->irqs[ 0 ];
874 fore200e->phys_base = (unsigned long)sbus_dev;
876 sprintf(fore200e->name, "%s-%d", bus->model_name, index - 1);
883 fore200e_sba_prom_read(struct fore200e* fore200e, struct prom_data* prom)
885 struct sbus_dev* sbus_dev = (struct sbus_dev*) fore200e->bus_dev;
888 len = prom_getproperty(sbus_dev->prom_node, "macaddrlo2", &prom->mac_addr[ 4 ], 4);
892 len = prom_getproperty(sbus_dev->prom_node, "macaddrhi4", &prom->mac_addr[ 2 ], 4);
896 prom_getproperty(sbus_dev->prom_node, "serialnumber",
897 (char*)&prom->serial_number, sizeof(prom->serial_number));
899 prom_getproperty(sbus_dev->prom_node, "promversion",
900 (char*)&prom->hw_revision, sizeof(prom->hw_revision));
907 fore200e_sba_proc_read(struct fore200e* fore200e, char *page)
909 struct sbus_dev* sbus_dev = (struct sbus_dev*)fore200e->bus_dev;
911 return sprintf(page, " SBUS slot/device:\t\t%d/'%s'\n", sbus_dev->slot, sbus_dev->prom_name);
913 #endif /* CONFIG_ATM_FORE200E_SBA */
917 fore200e_tx_irq(struct fore200e* fore200e)
919 struct host_txq* txq = &fore200e->host_txq;
920 struct host_txq_entry* entry;
922 struct fore200e_vc_map* vc_map;
924 if (fore200e->host_txq.txing == 0)
929 entry = &txq->host_entry[ txq->tail ];
931 if ((*entry->status & STATUS_COMPLETE) == 0) {
935 DPRINTK(3, "TX COMPLETED: entry = %p [tail = %d], vc_map = %p, skb = %p\n",
936 entry, txq->tail, entry->vc_map, entry->skb);
938 /* free copy of misaligned data */
941 /* remove DMA mapping */
942 fore200e->bus->dma_unmap(fore200e, entry->tpd->tsd[ 0 ].buffer, entry->tpd->tsd[ 0 ].length,
945 vc_map = entry->vc_map;
947 /* vcc closed since the time the entry was submitted for tx? */
948 if ((vc_map->vcc == NULL) ||
949 (test_bit(ATM_VF_READY, &vc_map->vcc->flags) == 0)) {
951 DPRINTK(1, "no ready vcc found for PDU sent on device %d\n",
952 fore200e->atm_dev->number);
954 dev_kfree_skb_any(entry->skb);
959 /* vcc closed then immediately re-opened? */
960 if (vc_map->incarn != entry->incarn) {
962 /* when a vcc is closed, some PDUs may be still pending in the tx queue.
963 if the same vcc is immediately re-opened, those pending PDUs must
964 not be popped after the completion of their emission, as they refer
965 to the prior incarnation of that vcc. otherwise, sk_atm(vcc)->sk_wmem_alloc
966 would be decremented by the size of the (unrelated) skb, possibly
967 leading to a negative sk->sk_wmem_alloc count, ultimately freezing the vcc.
968 we thus bind the tx entry to the current incarnation of the vcc
969 when the entry is submitted for tx. When the tx later completes,
970 if the incarnation number of the tx entry does not match the one
971 of the vcc, then this implies that the vcc has been closed then re-opened.
972 we thus just drop the skb here. */
974 DPRINTK(1, "vcc closed-then-re-opened; dropping PDU sent on device %d\n",
975 fore200e->atm_dev->number);
977 dev_kfree_skb_any(entry->skb);
983 /* notify tx completion */
985 vcc->pop(vcc, entry->skb);
988 dev_kfree_skb_any(entry->skb);
991 /* race fixed by the above incarnation mechanism, but... */
992 if (atomic_read(&sk_atm(vcc)->sk_wmem_alloc) < 0) {
993 atomic_set(&sk_atm(vcc)->sk_wmem_alloc, 0);
996 /* check error condition */
997 if (*entry->status & STATUS_ERROR)
998 atomic_inc(&vcc->stats->tx_err);
1000 atomic_inc(&vcc->stats->tx);
1004 *entry->status = STATUS_FREE;
1006 fore200e->host_txq.txing--;
1008 FORE200E_NEXT_ENTRY(txq->tail, QUEUE_SIZE_TX);
1013 #ifdef FORE200E_BSQ_DEBUG
1014 int bsq_audit(int where, struct host_bsq* bsq, int scheme, int magn)
1016 struct buffer* buffer;
1019 buffer = bsq->freebuf;
1022 if (buffer->supplied) {
1023 printk(FORE200E "bsq_audit(%d): queue %d.%d, buffer %ld supplied but in free list!\n",
1024 where, scheme, magn, buffer->index);
1027 if (buffer->magn != magn) {
1028 printk(FORE200E "bsq_audit(%d): queue %d.%d, buffer %ld, unexpected magn = %d\n",
1029 where, scheme, magn, buffer->index, buffer->magn);
1032 if (buffer->scheme != scheme) {
1033 printk(FORE200E "bsq_audit(%d): queue %d.%d, buffer %ld, unexpected scheme = %d\n",
1034 where, scheme, magn, buffer->index, buffer->scheme);
1037 if ((buffer->index < 0) || (buffer->index >= fore200e_rx_buf_nbr[ scheme ][ magn ])) {
1038 printk(FORE200E "bsq_audit(%d): queue %d.%d, out of range buffer index = %ld !\n",
1039 where, scheme, magn, buffer->index);
1043 buffer = buffer->next;
1046 if (count != bsq->freebuf_count) {
1047 printk(FORE200E "bsq_audit(%d): queue %d.%d, %d bufs in free list, but freebuf_count = %d\n",
1048 where, scheme, magn, count, bsq->freebuf_count);
1056 fore200e_supply(struct fore200e* fore200e)
1058 int scheme, magn, i;
1060 struct host_bsq* bsq;
1061 struct host_bsq_entry* entry;
1062 struct buffer* buffer;
1064 for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
1065 for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
1067 bsq = &fore200e->host_bsq[ scheme ][ magn ];
1069 #ifdef FORE200E_BSQ_DEBUG
1070 bsq_audit(1, bsq, scheme, magn);
1072 while (bsq->freebuf_count >= RBD_BLK_SIZE) {
1074 DPRINTK(2, "supplying %d rx buffers to queue %d / %d, freebuf_count = %d\n",
1075 RBD_BLK_SIZE, scheme, magn, bsq->freebuf_count);
1077 entry = &bsq->host_entry[ bsq->head ];
1079 for (i = 0; i < RBD_BLK_SIZE; i++) {
1081 /* take the first buffer in the free buffer list */
1082 buffer = bsq->freebuf;
1084 printk(FORE200E "no more free bufs in queue %d.%d, but freebuf_count = %d\n",
1085 scheme, magn, bsq->freebuf_count);
1088 bsq->freebuf = buffer->next;
1090 #ifdef FORE200E_BSQ_DEBUG
1091 if (buffer->supplied)
1092 printk(FORE200E "queue %d.%d, buffer %lu already supplied\n",
1093 scheme, magn, buffer->index);
1094 buffer->supplied = 1;
1096 entry->rbd_block->rbd[ i ].buffer_haddr = buffer->data.dma_addr;
1097 entry->rbd_block->rbd[ i ].handle = FORE200E_BUF2HDL(buffer);
1100 FORE200E_NEXT_ENTRY(bsq->head, QUEUE_SIZE_BS);
1102 /* decrease accordingly the number of free rx buffers */
1103 bsq->freebuf_count -= RBD_BLK_SIZE;
1105 *entry->status = STATUS_PENDING;
1106 fore200e->bus->write(entry->rbd_block_dma, &entry->cp_entry->rbd_block_haddr);
1114 fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rpd)
1116 struct sk_buff* skb;
1117 struct buffer* buffer;
1118 struct fore200e_vcc* fore200e_vcc;
1120 #ifdef FORE200E_52BYTE_AAL0_SDU
1121 u32 cell_header = 0;
1126 fore200e_vcc = FORE200E_VCC(vcc);
1127 ASSERT(fore200e_vcc);
1129 #ifdef FORE200E_52BYTE_AAL0_SDU
1130 if ((vcc->qos.aal == ATM_AAL0) && (vcc->qos.rxtp.max_sdu == ATM_AAL0_SDU)) {
1132 cell_header = (rpd->atm_header.gfc << ATM_HDR_GFC_SHIFT) |
1133 (rpd->atm_header.vpi << ATM_HDR_VPI_SHIFT) |
1134 (rpd->atm_header.vci << ATM_HDR_VCI_SHIFT) |
1135 (rpd->atm_header.plt << ATM_HDR_PTI_SHIFT) |
1136 rpd->atm_header.clp;
1141 /* compute total PDU length */
1142 for (i = 0; i < rpd->nseg; i++)
1143 pdu_len += rpd->rsd[ i ].length;
1145 skb = alloc_skb(pdu_len, GFP_ATOMIC);
1147 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
1149 atomic_inc(&vcc->stats->rx_drop);
1153 __net_timestamp(skb);
1155 #ifdef FORE200E_52BYTE_AAL0_SDU
1157 *((u32*)skb_put(skb, 4)) = cell_header;
1161 /* reassemble segments */
1162 for (i = 0; i < rpd->nseg; i++) {
1164 /* rebuild rx buffer address from rsd handle */
1165 buffer = FORE200E_HDL2BUF(rpd->rsd[ i ].handle);
1167 /* Make device DMA transfer visible to CPU. */
1168 fore200e->bus->dma_sync_for_cpu(fore200e, buffer->data.dma_addr, rpd->rsd[ i ].length, DMA_FROM_DEVICE);
1170 memcpy(skb_put(skb, rpd->rsd[ i ].length), buffer->data.align_addr, rpd->rsd[ i ].length);
1172 /* Now let the device get at it again. */
1173 fore200e->bus->dma_sync_for_device(fore200e, buffer->data.dma_addr, rpd->rsd[ i ].length, DMA_FROM_DEVICE);
1176 DPRINTK(3, "rx skb: len = %d, truesize = %d\n", skb->len, skb->truesize);
1178 if (pdu_len < fore200e_vcc->rx_min_pdu)
1179 fore200e_vcc->rx_min_pdu = pdu_len;
1180 if (pdu_len > fore200e_vcc->rx_max_pdu)
1181 fore200e_vcc->rx_max_pdu = pdu_len;
1182 fore200e_vcc->rx_pdu++;
1185 if (atm_charge(vcc, skb->truesize) == 0) {
1187 DPRINTK(2, "receive buffers saturated for %d.%d.%d - PDU dropped\n",
1188 vcc->itf, vcc->vpi, vcc->vci);
1190 dev_kfree_skb_any(skb);
1192 atomic_inc(&vcc->stats->rx_drop);
1196 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
1198 vcc->push(vcc, skb);
1199 atomic_inc(&vcc->stats->rx);
1201 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
1208 fore200e_collect_rpd(struct fore200e* fore200e, struct rpd* rpd)
1210 struct host_bsq* bsq;
1211 struct buffer* buffer;
1214 for (i = 0; i < rpd->nseg; i++) {
1216 /* rebuild rx buffer address from rsd handle */
1217 buffer = FORE200E_HDL2BUF(rpd->rsd[ i ].handle);
1219 bsq = &fore200e->host_bsq[ buffer->scheme ][ buffer->magn ];
1221 #ifdef FORE200E_BSQ_DEBUG
1222 bsq_audit(2, bsq, buffer->scheme, buffer->magn);
1224 if (buffer->supplied == 0)
1225 printk(FORE200E "queue %d.%d, buffer %ld was not supplied\n",
1226 buffer->scheme, buffer->magn, buffer->index);
1227 buffer->supplied = 0;
1230 /* re-insert the buffer into the free buffer list */
1231 buffer->next = bsq->freebuf;
1232 bsq->freebuf = buffer;
1234 /* then increment the number of free rx buffers */
1235 bsq->freebuf_count++;
1241 fore200e_rx_irq(struct fore200e* fore200e)
1243 struct host_rxq* rxq = &fore200e->host_rxq;
1244 struct host_rxq_entry* entry;
1245 struct atm_vcc* vcc;
1246 struct fore200e_vc_map* vc_map;
1250 entry = &rxq->host_entry[ rxq->head ];
1252 /* no more received PDUs */
1253 if ((*entry->status & STATUS_COMPLETE) == 0)
1256 vc_map = FORE200E_VC_MAP(fore200e, entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
1258 if ((vc_map->vcc == NULL) ||
1259 (test_bit(ATM_VF_READY, &vc_map->vcc->flags) == 0)) {
1261 DPRINTK(1, "no ready VC found for PDU received on %d.%d.%d\n",
1262 fore200e->atm_dev->number,
1263 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
1269 if ((*entry->status & STATUS_ERROR) == 0) {
1271 fore200e_push_rpd(fore200e, vcc, entry->rpd);
1274 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
1275 fore200e->atm_dev->number,
1276 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
1277 atomic_inc(&vcc->stats->rx_err);
1281 FORE200E_NEXT_ENTRY(rxq->head, QUEUE_SIZE_RX);
1283 fore200e_collect_rpd(fore200e, entry->rpd);
1285 /* rewrite the rpd address to ack the received PDU */
1286 fore200e->bus->write(entry->rpd_dma, &entry->cp_entry->rpd_haddr);
1287 *entry->status = STATUS_FREE;
1289 fore200e_supply(fore200e);
1294 #ifndef FORE200E_USE_TASKLET
1296 fore200e_irq(struct fore200e* fore200e)
1298 unsigned long flags;
1300 spin_lock_irqsave(&fore200e->q_lock, flags);
1301 fore200e_rx_irq(fore200e);
1302 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1304 spin_lock_irqsave(&fore200e->q_lock, flags);
1305 fore200e_tx_irq(fore200e);
1306 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1312 fore200e_interrupt(int irq, void* dev)
1314 struct fore200e* fore200e = FORE200E_DEV((struct atm_dev*)dev);
1316 if (fore200e->bus->irq_check(fore200e) == 0) {
1318 DPRINTK(3, "interrupt NOT triggered by device %d\n", fore200e->atm_dev->number);
1321 DPRINTK(3, "interrupt triggered by device %d\n", fore200e->atm_dev->number);
1323 #ifdef FORE200E_USE_TASKLET
1324 tasklet_schedule(&fore200e->tx_tasklet);
1325 tasklet_schedule(&fore200e->rx_tasklet);
1327 fore200e_irq(fore200e);
1330 fore200e->bus->irq_ack(fore200e);
1335 #ifdef FORE200E_USE_TASKLET
1337 fore200e_tx_tasklet(unsigned long data)
1339 struct fore200e* fore200e = (struct fore200e*) data;
1340 unsigned long flags;
1342 DPRINTK(3, "tx tasklet scheduled for device %d\n", fore200e->atm_dev->number);
1344 spin_lock_irqsave(&fore200e->q_lock, flags);
1345 fore200e_tx_irq(fore200e);
1346 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1351 fore200e_rx_tasklet(unsigned long data)
1353 struct fore200e* fore200e = (struct fore200e*) data;
1354 unsigned long flags;
1356 DPRINTK(3, "rx tasklet scheduled for device %d\n", fore200e->atm_dev->number);
1358 spin_lock_irqsave(&fore200e->q_lock, flags);
1359 fore200e_rx_irq((struct fore200e*) data);
1360 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1366 fore200e_select_scheme(struct atm_vcc* vcc)
1368 /* fairly balance the VCs over (identical) buffer schemes */
1369 int scheme = vcc->vci % 2 ? BUFFER_SCHEME_ONE : BUFFER_SCHEME_TWO;
1371 DPRINTK(1, "VC %d.%d.%d uses buffer scheme %d\n",
1372 vcc->itf, vcc->vpi, vcc->vci, scheme);
1379 fore200e_activate_vcin(struct fore200e* fore200e, int activate, struct atm_vcc* vcc, int mtu)
1381 struct host_cmdq* cmdq = &fore200e->host_cmdq;
1382 struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
1383 struct activate_opcode activ_opcode;
1384 struct deactivate_opcode deactiv_opcode;
1387 enum fore200e_aal aal = fore200e_atm2fore_aal(vcc->qos.aal);
1389 FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
1392 FORE200E_VCC(vcc)->scheme = fore200e_select_scheme(vcc);
1394 activ_opcode.opcode = OPCODE_ACTIVATE_VCIN;
1395 activ_opcode.aal = aal;
1396 activ_opcode.scheme = FORE200E_VCC(vcc)->scheme;
1397 activ_opcode.pad = 0;
1400 deactiv_opcode.opcode = OPCODE_DEACTIVATE_VCIN;
1401 deactiv_opcode.pad = 0;
1404 vpvc.vci = vcc->vci;
1405 vpvc.vpi = vcc->vpi;
1407 *entry->status = STATUS_PENDING;
1411 #ifdef FORE200E_52BYTE_AAL0_SDU
1414 /* the MTU is not used by the cp, except in the case of AAL0 */
1415 fore200e->bus->write(mtu, &entry->cp_entry->cmd.activate_block.mtu);
1416 fore200e->bus->write(*(u32*)&vpvc, (u32 __iomem *)&entry->cp_entry->cmd.activate_block.vpvc);
1417 fore200e->bus->write(*(u32*)&activ_opcode, (u32 __iomem *)&entry->cp_entry->cmd.activate_block.opcode);
1420 fore200e->bus->write(*(u32*)&vpvc, (u32 __iomem *)&entry->cp_entry->cmd.deactivate_block.vpvc);
1421 fore200e->bus->write(*(u32*)&deactiv_opcode, (u32 __iomem *)&entry->cp_entry->cmd.deactivate_block.opcode);
1424 ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
1426 *entry->status = STATUS_FREE;
1429 printk(FORE200E "unable to %s VC %d.%d.%d\n",
1430 activate ? "open" : "close", vcc->itf, vcc->vpi, vcc->vci);
1434 DPRINTK(1, "VC %d.%d.%d %sed\n", vcc->itf, vcc->vpi, vcc->vci,
1435 activate ? "open" : "clos");
1441 #define FORE200E_MAX_BACK2BACK_CELLS 255 /* XXX depends on CDVT */
1444 fore200e_rate_ctrl(struct atm_qos* qos, struct tpd_rate* rate)
1446 if (qos->txtp.max_pcr < ATM_OC3_PCR) {
1448 /* compute the data cells to idle cells ratio from the tx PCR */
1449 rate->data_cells = qos->txtp.max_pcr * FORE200E_MAX_BACK2BACK_CELLS / ATM_OC3_PCR;
1450 rate->idle_cells = FORE200E_MAX_BACK2BACK_CELLS - rate->data_cells;
1453 /* disable rate control */
1454 rate->data_cells = rate->idle_cells = 0;
1460 fore200e_open(struct atm_vcc *vcc)
1462 struct fore200e* fore200e = FORE200E_DEV(vcc->dev);
1463 struct fore200e_vcc* fore200e_vcc;
1464 struct fore200e_vc_map* vc_map;
1465 unsigned long flags;
1467 short vpi = vcc->vpi;
1469 ASSERT((vpi >= 0) && (vpi < 1<<FORE200E_VPI_BITS));
1470 ASSERT((vci >= 0) && (vci < 1<<FORE200E_VCI_BITS));
1472 spin_lock_irqsave(&fore200e->q_lock, flags);
1474 vc_map = FORE200E_VC_MAP(fore200e, vpi, vci);
1477 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1479 printk(FORE200E "VC %d.%d.%d already in use\n",
1480 fore200e->atm_dev->number, vpi, vci);
1487 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1489 fore200e_vcc = kzalloc(sizeof(struct fore200e_vcc), GFP_ATOMIC);
1490 if (fore200e_vcc == NULL) {
1495 DPRINTK(2, "opening %d.%d.%d:%d QoS = (tx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d; "
1496 "rx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d)\n",
1497 vcc->itf, vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal),
1498 fore200e_traffic_class[ vcc->qos.txtp.traffic_class ],
1499 vcc->qos.txtp.min_pcr, vcc->qos.txtp.max_pcr, vcc->qos.txtp.max_cdv, vcc->qos.txtp.max_sdu,
1500 fore200e_traffic_class[ vcc->qos.rxtp.traffic_class ],
1501 vcc->qos.rxtp.min_pcr, vcc->qos.rxtp.max_pcr, vcc->qos.rxtp.max_cdv, vcc->qos.rxtp.max_sdu);
1503 /* pseudo-CBR bandwidth requested? */
1504 if ((vcc->qos.txtp.traffic_class == ATM_CBR) && (vcc->qos.txtp.max_pcr > 0)) {
1506 down(&fore200e->rate_sf);
1507 if (fore200e->available_cell_rate < vcc->qos.txtp.max_pcr) {
1508 up(&fore200e->rate_sf);
1510 kfree(fore200e_vcc);
1515 /* reserve bandwidth */
1516 fore200e->available_cell_rate -= vcc->qos.txtp.max_pcr;
1517 up(&fore200e->rate_sf);
1520 vcc->itf = vcc->dev->number;
1522 set_bit(ATM_VF_PARTIAL,&vcc->flags);
1523 set_bit(ATM_VF_ADDR, &vcc->flags);
1525 vcc->dev_data = fore200e_vcc;
1527 if (fore200e_activate_vcin(fore200e, 1, vcc, vcc->qos.rxtp.max_sdu) < 0) {
1531 clear_bit(ATM_VF_ADDR, &vcc->flags);
1532 clear_bit(ATM_VF_PARTIAL,&vcc->flags);
1534 vcc->dev_data = NULL;
1536 fore200e->available_cell_rate += vcc->qos.txtp.max_pcr;
1538 kfree(fore200e_vcc);
1542 /* compute rate control parameters */
1543 if ((vcc->qos.txtp.traffic_class == ATM_CBR) && (vcc->qos.txtp.max_pcr > 0)) {
1545 fore200e_rate_ctrl(&vcc->qos, &fore200e_vcc->rate);
1546 set_bit(ATM_VF_HASQOS, &vcc->flags);
1548 DPRINTK(3, "tx on %d.%d.%d:%d, tx PCR = %d, rx PCR = %d, data_cells = %u, idle_cells = %u\n",
1549 vcc->itf, vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal),
1550 vcc->qos.txtp.max_pcr, vcc->qos.rxtp.max_pcr,
1551 fore200e_vcc->rate.data_cells, fore200e_vcc->rate.idle_cells);
1554 fore200e_vcc->tx_min_pdu = fore200e_vcc->rx_min_pdu = MAX_PDU_SIZE + 1;
1555 fore200e_vcc->tx_max_pdu = fore200e_vcc->rx_max_pdu = 0;
1556 fore200e_vcc->tx_pdu = fore200e_vcc->rx_pdu = 0;
1558 /* new incarnation of the vcc */
1559 vc_map->incarn = ++fore200e->incarn_count;
1561 /* VC unusable before this flag is set */
1562 set_bit(ATM_VF_READY, &vcc->flags);
1569 fore200e_close(struct atm_vcc* vcc)
1571 struct fore200e* fore200e = FORE200E_DEV(vcc->dev);
1572 struct fore200e_vcc* fore200e_vcc;
1573 struct fore200e_vc_map* vc_map;
1574 unsigned long flags;
1577 ASSERT((vcc->vpi >= 0) && (vcc->vpi < 1<<FORE200E_VPI_BITS));
1578 ASSERT((vcc->vci >= 0) && (vcc->vci < 1<<FORE200E_VCI_BITS));
1580 DPRINTK(2, "closing %d.%d.%d:%d\n", vcc->itf, vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal));
1582 clear_bit(ATM_VF_READY, &vcc->flags);
1584 fore200e_activate_vcin(fore200e, 0, vcc, 0);
1586 spin_lock_irqsave(&fore200e->q_lock, flags);
1588 vc_map = FORE200E_VC_MAP(fore200e, vcc->vpi, vcc->vci);
1590 /* the vc is no longer considered as "in use" by fore200e_open() */
1593 vcc->itf = vcc->vci = vcc->vpi = 0;
1595 fore200e_vcc = FORE200E_VCC(vcc);
1596 vcc->dev_data = NULL;
1598 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1600 /* release reserved bandwidth, if any */
1601 if ((vcc->qos.txtp.traffic_class == ATM_CBR) && (vcc->qos.txtp.max_pcr > 0)) {
1603 down(&fore200e->rate_sf);
1604 fore200e->available_cell_rate += vcc->qos.txtp.max_pcr;
1605 up(&fore200e->rate_sf);
1607 clear_bit(ATM_VF_HASQOS, &vcc->flags);
1610 clear_bit(ATM_VF_ADDR, &vcc->flags);
1611 clear_bit(ATM_VF_PARTIAL,&vcc->flags);
1613 ASSERT(fore200e_vcc);
1614 kfree(fore200e_vcc);
1619 fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
1621 struct fore200e* fore200e = FORE200E_DEV(vcc->dev);
1622 struct fore200e_vcc* fore200e_vcc = FORE200E_VCC(vcc);
1623 struct fore200e_vc_map* vc_map;
1624 struct host_txq* txq = &fore200e->host_txq;
1625 struct host_txq_entry* entry;
1627 struct tpd_haddr tpd_haddr;
1628 int retry = CONFIG_ATM_FORE200E_TX_RETRY;
1630 int tx_len = skb->len;
1631 u32* cell_header = NULL;
1632 unsigned char* skb_data;
1634 unsigned char* data;
1635 unsigned long flags;
1638 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
1640 ASSERT(fore200e_vcc);
1642 if (!test_bit(ATM_VF_READY, &vcc->flags)) {
1643 DPRINTK(1, "VC %d.%d.%d not ready for tx\n", vcc->itf, vcc->vpi, vcc->vpi);
1644 dev_kfree_skb_any(skb);
1648 #ifdef FORE200E_52BYTE_AAL0_SDU
1649 if ((vcc->qos.aal == ATM_AAL0) && (vcc->qos.txtp.max_sdu == ATM_AAL0_SDU)) {
1650 cell_header = (u32*) skb->data;
1651 skb_data = skb->data + 4; /* skip 4-byte cell header */
1652 skb_len = tx_len = skb->len - 4;
1654 DPRINTK(3, "user-supplied cell header = 0x%08x\n", *cell_header);
1659 skb_data = skb->data;
1663 if (((unsigned long)skb_data) & 0x3) {
1665 DPRINTK(2, "misaligned tx PDU on device %s\n", fore200e->name);
1670 if ((vcc->qos.aal == ATM_AAL0) && (skb_len % ATM_CELL_PAYLOAD)) {
1672 /* this simply NUKES the PCA board */
1673 DPRINTK(2, "incomplete tx AAL0 PDU on device %s\n", fore200e->name);
1675 tx_len = ((skb_len / ATM_CELL_PAYLOAD) + 1) * ATM_CELL_PAYLOAD;
1679 data = kmalloc(tx_len, GFP_ATOMIC | GFP_DMA);
1685 dev_kfree_skb_any(skb);
1690 memcpy(data, skb_data, skb_len);
1691 if (skb_len < tx_len)
1692 memset(data + skb_len, 0x00, tx_len - skb_len);
1698 vc_map = FORE200E_VC_MAP(fore200e, vcc->vpi, vcc->vci);
1699 ASSERT(vc_map->vcc == vcc);
1703 spin_lock_irqsave(&fore200e->q_lock, flags);
1705 entry = &txq->host_entry[ txq->head ];
1707 if ((*entry->status != STATUS_FREE) || (txq->txing >= QUEUE_SIZE_TX - 2)) {
1709 /* try to free completed tx queue entries */
1710 fore200e_tx_irq(fore200e);
1712 if (*entry->status != STATUS_FREE) {
1714 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1716 /* retry once again? */
1722 atomic_inc(&vcc->stats->tx_err);
1725 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
1726 fore200e->name, fore200e->cp_queues->heartbeat);
1731 dev_kfree_skb_any(skb);
1741 entry->incarn = vc_map->incarn;
1742 entry->vc_map = vc_map;
1744 entry->data = tx_copy ? data : NULL;
1747 tpd->tsd[ 0 ].buffer = fore200e->bus->dma_map(fore200e, data, tx_len, DMA_TO_DEVICE);
1748 tpd->tsd[ 0 ].length = tx_len;
1750 FORE200E_NEXT_ENTRY(txq->head, QUEUE_SIZE_TX);
1753 /* The dma_map call above implies a dma_sync so the device can use it,
1754 * thus no explicit dma_sync call is necessary here.
1757 DPRINTK(3, "tx on %d.%d.%d:%d, len = %u (%u)\n",
1758 vcc->itf, vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal),
1759 tpd->tsd[0].length, skb_len);
1761 if (skb_len < fore200e_vcc->tx_min_pdu)
1762 fore200e_vcc->tx_min_pdu = skb_len;
1763 if (skb_len > fore200e_vcc->tx_max_pdu)
1764 fore200e_vcc->tx_max_pdu = skb_len;
1765 fore200e_vcc->tx_pdu++;
1767 /* set tx rate control information */
1768 tpd->rate.data_cells = fore200e_vcc->rate.data_cells;
1769 tpd->rate.idle_cells = fore200e_vcc->rate.idle_cells;
1772 tpd->atm_header.clp = (*cell_header & ATM_HDR_CLP);
1773 tpd->atm_header.plt = (*cell_header & ATM_HDR_PTI_MASK) >> ATM_HDR_PTI_SHIFT;
1774 tpd->atm_header.vci = (*cell_header & ATM_HDR_VCI_MASK) >> ATM_HDR_VCI_SHIFT;
1775 tpd->atm_header.vpi = (*cell_header & ATM_HDR_VPI_MASK) >> ATM_HDR_VPI_SHIFT;
1776 tpd->atm_header.gfc = (*cell_header & ATM_HDR_GFC_MASK) >> ATM_HDR_GFC_SHIFT;
1779 /* set the ATM header, common to all cells conveying the PDU */
1780 tpd->atm_header.clp = 0;
1781 tpd->atm_header.plt = 0;
1782 tpd->atm_header.vci = vcc->vci;
1783 tpd->atm_header.vpi = vcc->vpi;
1784 tpd->atm_header.gfc = 0;
1787 tpd->spec.length = tx_len;
1789 tpd->spec.aal = fore200e_atm2fore_aal(vcc->qos.aal);
1792 tpd_haddr.size = sizeof(struct tpd) / (1<<TPD_HADDR_SHIFT); /* size is expressed in 32 byte blocks */
1794 tpd_haddr.haddr = entry->tpd_dma >> TPD_HADDR_SHIFT; /* shift the address, as we are in a bitfield */
1796 *entry->status = STATUS_PENDING;
1797 fore200e->bus->write(*(u32*)&tpd_haddr, (u32 __iomem *)&entry->cp_entry->tpd_haddr);
1799 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1806 fore200e_getstats(struct fore200e* fore200e)
1808 struct host_cmdq* cmdq = &fore200e->host_cmdq;
1809 struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
1810 struct stats_opcode opcode;
1814 if (fore200e->stats == NULL) {
1815 fore200e->stats = kzalloc(sizeof(struct stats), GFP_KERNEL | GFP_DMA);
1816 if (fore200e->stats == NULL)
1820 stats_dma_addr = fore200e->bus->dma_map(fore200e, fore200e->stats,
1821 sizeof(struct stats), DMA_FROM_DEVICE);
1823 FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
1825 opcode.opcode = OPCODE_GET_STATS;
1828 fore200e->bus->write(stats_dma_addr, &entry->cp_entry->cmd.stats_block.stats_haddr);
1830 *entry->status = STATUS_PENDING;
1832 fore200e->bus->write(*(u32*)&opcode, (u32 __iomem *)&entry->cp_entry->cmd.stats_block.opcode);
1834 ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
1836 *entry->status = STATUS_FREE;
1838 fore200e->bus->dma_unmap(fore200e, stats_dma_addr, sizeof(struct stats), DMA_FROM_DEVICE);
1841 printk(FORE200E "unable to get statistics from device %s\n", fore200e->name);
1850 fore200e_getsockopt(struct atm_vcc* vcc, int level, int optname, void __user *optval, int optlen)
1852 /* struct fore200e* fore200e = FORE200E_DEV(vcc->dev); */
1854 DPRINTK(2, "getsockopt %d.%d.%d, level = %d, optname = 0x%x, optval = 0x%p, optlen = %d\n",
1855 vcc->itf, vcc->vpi, vcc->vci, level, optname, optval, optlen);
1862 fore200e_setsockopt(struct atm_vcc* vcc, int level, int optname, void __user *optval, int optlen)
1864 /* struct fore200e* fore200e = FORE200E_DEV(vcc->dev); */
1866 DPRINTK(2, "setsockopt %d.%d.%d, level = %d, optname = 0x%x, optval = 0x%p, optlen = %d\n",
1867 vcc->itf, vcc->vpi, vcc->vci, level, optname, optval, optlen);
1873 #if 0 /* currently unused */
1875 fore200e_get_oc3(struct fore200e* fore200e, struct oc3_regs* regs)
1877 struct host_cmdq* cmdq = &fore200e->host_cmdq;
1878 struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
1879 struct oc3_opcode opcode;
1881 u32 oc3_regs_dma_addr;
1883 oc3_regs_dma_addr = fore200e->bus->dma_map(fore200e, regs, sizeof(struct oc3_regs), DMA_FROM_DEVICE);
1885 FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
1887 opcode.opcode = OPCODE_GET_OC3;
1892 fore200e->bus->write(oc3_regs_dma_addr, &entry->cp_entry->cmd.oc3_block.regs_haddr);
1894 *entry->status = STATUS_PENDING;
1896 fore200e->bus->write(*(u32*)&opcode, (u32*)&entry->cp_entry->cmd.oc3_block.opcode);
1898 ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
1900 *entry->status = STATUS_FREE;
1902 fore200e->bus->dma_unmap(fore200e, oc3_regs_dma_addr, sizeof(struct oc3_regs), DMA_FROM_DEVICE);
1905 printk(FORE200E "unable to get OC-3 regs of device %s\n", fore200e->name);
1915 fore200e_set_oc3(struct fore200e* fore200e, u32 reg, u32 value, u32 mask)
1917 struct host_cmdq* cmdq = &fore200e->host_cmdq;
1918 struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
1919 struct oc3_opcode opcode;
1922 DPRINTK(2, "set OC-3 reg = 0x%02x, value = 0x%02x, mask = 0x%02x\n", reg, value, mask);
1924 FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
1926 opcode.opcode = OPCODE_SET_OC3;
1928 opcode.value = value;
1931 fore200e->bus->write(0, &entry->cp_entry->cmd.oc3_block.regs_haddr);
1933 *entry->status = STATUS_PENDING;
1935 fore200e->bus->write(*(u32*)&opcode, (u32 __iomem *)&entry->cp_entry->cmd.oc3_block.opcode);
1937 ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
1939 *entry->status = STATUS_FREE;
1942 printk(FORE200E "unable to set OC-3 reg 0x%02x of device %s\n", reg, fore200e->name);
1951 fore200e_setloop(struct fore200e* fore200e, int loop_mode)
1953 u32 mct_value, mct_mask;
1956 if (!capable(CAP_NET_ADMIN))
1959 switch (loop_mode) {
1963 mct_mask = SUNI_MCT_DLE | SUNI_MCT_LLE;
1966 case ATM_LM_LOC_PHY:
1967 mct_value = mct_mask = SUNI_MCT_DLE;
1970 case ATM_LM_RMT_PHY:
1971 mct_value = mct_mask = SUNI_MCT_LLE;
1978 error = fore200e_set_oc3(fore200e, SUNI_MCT, mct_value, mct_mask);
1980 fore200e->loop_mode = loop_mode;
1987 fore200e_fetch_stats(struct fore200e* fore200e, struct sonet_stats __user *arg)
1989 struct sonet_stats tmp;
1991 if (fore200e_getstats(fore200e) < 0)
1994 tmp.section_bip = cpu_to_be32(fore200e->stats->oc3.section_bip8_errors);
1995 tmp.line_bip = cpu_to_be32(fore200e->stats->oc3.line_bip24_errors);
1996 tmp.path_bip = cpu_to_be32(fore200e->stats->oc3.path_bip8_errors);
1997 tmp.line_febe = cpu_to_be32(fore200e->stats->oc3.line_febe_errors);
1998 tmp.path_febe = cpu_to_be32(fore200e->stats->oc3.path_febe_errors);
1999 tmp.corr_hcs = cpu_to_be32(fore200e->stats->oc3.corr_hcs_errors);
2000 tmp.uncorr_hcs = cpu_to_be32(fore200e->stats->oc3.ucorr_hcs_errors);
2001 tmp.tx_cells = cpu_to_be32(fore200e->stats->aal0.cells_transmitted) +
2002 cpu_to_be32(fore200e->stats->aal34.cells_transmitted) +
2003 cpu_to_be32(fore200e->stats->aal5.cells_transmitted);
2004 tmp.rx_cells = cpu_to_be32(fore200e->stats->aal0.cells_received) +
2005 cpu_to_be32(fore200e->stats->aal34.cells_received) +
2006 cpu_to_be32(fore200e->stats->aal5.cells_received);
2009 return copy_to_user(arg, &tmp, sizeof(struct sonet_stats)) ? -EFAULT : 0;
2016 fore200e_ioctl(struct atm_dev* dev, unsigned int cmd, void __user * arg)
2018 struct fore200e* fore200e = FORE200E_DEV(dev);
2020 DPRINTK(2, "ioctl cmd = 0x%x (%u), arg = 0x%p (%lu)\n", cmd, cmd, arg, (unsigned long)arg);
2025 return fore200e_fetch_stats(fore200e, (struct sonet_stats __user *)arg);
2028 return put_user(0, (int __user *)arg) ? -EFAULT : 0;
2031 return fore200e_setloop(fore200e, (int)(unsigned long)arg);
2034 return put_user(fore200e->loop_mode, (int __user *)arg) ? -EFAULT : 0;
2037 return put_user(ATM_LM_LOC_PHY | ATM_LM_RMT_PHY, (int __user *)arg) ? -EFAULT : 0;
2040 return -ENOSYS; /* not implemented */
2045 fore200e_change_qos(struct atm_vcc* vcc,struct atm_qos* qos, int flags)
2047 struct fore200e_vcc* fore200e_vcc = FORE200E_VCC(vcc);
2048 struct fore200e* fore200e = FORE200E_DEV(vcc->dev);
2050 if (!test_bit(ATM_VF_READY, &vcc->flags)) {
2051 DPRINTK(1, "VC %d.%d.%d not ready for QoS change\n", vcc->itf, vcc->vpi, vcc->vpi);
2055 DPRINTK(2, "change_qos %d.%d.%d, "
2056 "(tx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d; "
2057 "rx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d), flags = 0x%x\n"
2058 "available_cell_rate = %u",
2059 vcc->itf, vcc->vpi, vcc->vci,
2060 fore200e_traffic_class[ qos->txtp.traffic_class ],
2061 qos->txtp.min_pcr, qos->txtp.max_pcr, qos->txtp.max_cdv, qos->txtp.max_sdu,
2062 fore200e_traffic_class[ qos->rxtp.traffic_class ],
2063 qos->rxtp.min_pcr, qos->rxtp.max_pcr, qos->rxtp.max_cdv, qos->rxtp.max_sdu,
2064 flags, fore200e->available_cell_rate);
2066 if ((qos->txtp.traffic_class == ATM_CBR) && (qos->txtp.max_pcr > 0)) {
2068 down(&fore200e->rate_sf);
2069 if (fore200e->available_cell_rate + vcc->qos.txtp.max_pcr < qos->txtp.max_pcr) {
2070 up(&fore200e->rate_sf);
2074 fore200e->available_cell_rate += vcc->qos.txtp.max_pcr;
2075 fore200e->available_cell_rate -= qos->txtp.max_pcr;
2077 up(&fore200e->rate_sf);
2079 memcpy(&vcc->qos, qos, sizeof(struct atm_qos));
2081 /* update rate control parameters */
2082 fore200e_rate_ctrl(qos, &fore200e_vcc->rate);
2084 set_bit(ATM_VF_HASQOS, &vcc->flags);
2093 static int __devinit
2094 fore200e_irq_request(struct fore200e* fore200e)
2096 if (request_irq(fore200e->irq, fore200e_interrupt, IRQF_SHARED, fore200e->name, fore200e->atm_dev) < 0) {
2098 printk(FORE200E "unable to reserve IRQ %s for device %s\n",
2099 fore200e_irq_itoa(fore200e->irq), fore200e->name);
2103 printk(FORE200E "IRQ %s reserved for device %s\n",
2104 fore200e_irq_itoa(fore200e->irq), fore200e->name);
2106 #ifdef FORE200E_USE_TASKLET
2107 tasklet_init(&fore200e->tx_tasklet, fore200e_tx_tasklet, (unsigned long)fore200e);
2108 tasklet_init(&fore200e->rx_tasklet, fore200e_rx_tasklet, (unsigned long)fore200e);
2111 fore200e->state = FORE200E_STATE_IRQ;
2116 static int __devinit
2117 fore200e_get_esi(struct fore200e* fore200e)
2119 struct prom_data* prom = kzalloc(sizeof(struct prom_data), GFP_KERNEL | GFP_DMA);
2125 ok = fore200e->bus->prom_read(fore200e, prom);
2131 printk(FORE200E "device %s, rev. %c, S/N: %d, ESI: %02x:%02x:%02x:%02x:%02x:%02x\n",
2133 (prom->hw_revision & 0xFF) + '@', /* probably meaningless with SBA boards */
2134 prom->serial_number & 0xFFFF,
2135 prom->mac_addr[ 2 ], prom->mac_addr[ 3 ], prom->mac_addr[ 4 ],
2136 prom->mac_addr[ 5 ], prom->mac_addr[ 6 ], prom->mac_addr[ 7 ]);
2138 for (i = 0; i < ESI_LEN; i++) {
2139 fore200e->esi[ i ] = fore200e->atm_dev->esi[ i ] = prom->mac_addr[ i + 2 ];
2148 static int __devinit
2149 fore200e_alloc_rx_buf(struct fore200e* fore200e)
2151 int scheme, magn, nbr, size, i;
2153 struct host_bsq* bsq;
2154 struct buffer* buffer;
2156 for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
2157 for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
2159 bsq = &fore200e->host_bsq[ scheme ][ magn ];
2161 nbr = fore200e_rx_buf_nbr[ scheme ][ magn ];
2162 size = fore200e_rx_buf_size[ scheme ][ magn ];
2164 DPRINTK(2, "rx buffers %d / %d are being allocated\n", scheme, magn);
2166 /* allocate the array of receive buffers */
2167 buffer = bsq->buffer = kzalloc(nbr * sizeof(struct buffer), GFP_KERNEL);
2172 bsq->freebuf = NULL;
2174 for (i = 0; i < nbr; i++) {
2176 buffer[ i ].scheme = scheme;
2177 buffer[ i ].magn = magn;
2178 #ifdef FORE200E_BSQ_DEBUG
2179 buffer[ i ].index = i;
2180 buffer[ i ].supplied = 0;
2183 /* allocate the receive buffer body */
2184 if (fore200e_chunk_alloc(fore200e,
2185 &buffer[ i ].data, size, fore200e->bus->buffer_alignment,
2186 DMA_FROM_DEVICE) < 0) {
2189 fore200e_chunk_free(fore200e, &buffer[ --i ].data);
2195 /* insert the buffer into the free buffer list */
2196 buffer[ i ].next = bsq->freebuf;
2197 bsq->freebuf = &buffer[ i ];
2199 /* all the buffers are free, initially */
2200 bsq->freebuf_count = nbr;
2202 #ifdef FORE200E_BSQ_DEBUG
2203 bsq_audit(3, bsq, scheme, magn);
2208 fore200e->state = FORE200E_STATE_ALLOC_BUF;
2213 static int __devinit
2214 fore200e_init_bs_queue(struct fore200e* fore200e)
2216 int scheme, magn, i;
2218 struct host_bsq* bsq;
2219 struct cp_bsq_entry __iomem * cp_entry;
2221 for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
2222 for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
2224 DPRINTK(2, "buffer supply queue %d / %d is being initialized\n", scheme, magn);
2226 bsq = &fore200e->host_bsq[ scheme ][ magn ];
2228 /* allocate and align the array of status words */
2229 if (fore200e->bus->dma_chunk_alloc(fore200e,
2231 sizeof(enum status),
2233 fore200e->bus->status_alignment) < 0) {
2237 /* allocate and align the array of receive buffer descriptors */
2238 if (fore200e->bus->dma_chunk_alloc(fore200e,
2240 sizeof(struct rbd_block),
2242 fore200e->bus->descr_alignment) < 0) {
2244 fore200e->bus->dma_chunk_free(fore200e, &bsq->status);
2248 /* get the base address of the cp resident buffer supply queue entries */
2249 cp_entry = fore200e->virt_base +
2250 fore200e->bus->read(&fore200e->cp_queues->cp_bsq[ scheme ][ magn ]);
2252 /* fill the host resident and cp resident buffer supply queue entries */
2253 for (i = 0; i < QUEUE_SIZE_BS; i++) {
2255 bsq->host_entry[ i ].status =
2256 FORE200E_INDEX(bsq->status.align_addr, enum status, i);
2257 bsq->host_entry[ i ].rbd_block =
2258 FORE200E_INDEX(bsq->rbd_block.align_addr, struct rbd_block, i);
2259 bsq->host_entry[ i ].rbd_block_dma =
2260 FORE200E_DMA_INDEX(bsq->rbd_block.dma_addr, struct rbd_block, i);
2261 bsq->host_entry[ i ].cp_entry = &cp_entry[ i ];
2263 *bsq->host_entry[ i ].status = STATUS_FREE;
2265 fore200e->bus->write(FORE200E_DMA_INDEX(bsq->status.dma_addr, enum status, i),
2266 &cp_entry[ i ].status_haddr);
2271 fore200e->state = FORE200E_STATE_INIT_BSQ;
2276 static int __devinit
2277 fore200e_init_rx_queue(struct fore200e* fore200e)
2279 struct host_rxq* rxq = &fore200e->host_rxq;
2280 struct cp_rxq_entry __iomem * cp_entry;
2283 DPRINTK(2, "receive queue is being initialized\n");
2285 /* allocate and align the array of status words */
2286 if (fore200e->bus->dma_chunk_alloc(fore200e,
2288 sizeof(enum status),
2290 fore200e->bus->status_alignment) < 0) {
2294 /* allocate and align the array of receive PDU descriptors */
2295 if (fore200e->bus->dma_chunk_alloc(fore200e,
2299 fore200e->bus->descr_alignment) < 0) {
2301 fore200e->bus->dma_chunk_free(fore200e, &rxq->status);
2305 /* get the base address of the cp resident rx queue entries */
2306 cp_entry = fore200e->virt_base + fore200e->bus->read(&fore200e->cp_queues->cp_rxq);
2308 /* fill the host resident and cp resident rx entries */
2309 for (i=0; i < QUEUE_SIZE_RX; i++) {
2311 rxq->host_entry[ i ].status =
2312 FORE200E_INDEX(rxq->status.align_addr, enum status, i);
2313 rxq->host_entry[ i ].rpd =
2314 FORE200E_INDEX(rxq->rpd.align_addr, struct rpd, i);
2315 rxq->host_entry[ i ].rpd_dma =
2316 FORE200E_DMA_INDEX(rxq->rpd.dma_addr, struct rpd, i);
2317 rxq->host_entry[ i ].cp_entry = &cp_entry[ i ];
2319 *rxq->host_entry[ i ].status = STATUS_FREE;
2321 fore200e->bus->write(FORE200E_DMA_INDEX(rxq->status.dma_addr, enum status, i),
2322 &cp_entry[ i ].status_haddr);
2324 fore200e->bus->write(FORE200E_DMA_INDEX(rxq->rpd.dma_addr, struct rpd, i),
2325 &cp_entry[ i ].rpd_haddr);
2328 /* set the head entry of the queue */
2331 fore200e->state = FORE200E_STATE_INIT_RXQ;
2336 static int __devinit
2337 fore200e_init_tx_queue(struct fore200e* fore200e)
2339 struct host_txq* txq = &fore200e->host_txq;
2340 struct cp_txq_entry __iomem * cp_entry;
2343 DPRINTK(2, "transmit queue is being initialized\n");
2345 /* allocate and align the array of status words */
2346 if (fore200e->bus->dma_chunk_alloc(fore200e,
2348 sizeof(enum status),
2350 fore200e->bus->status_alignment) < 0) {
2354 /* allocate and align the array of transmit PDU descriptors */
2355 if (fore200e->bus->dma_chunk_alloc(fore200e,
2359 fore200e->bus->descr_alignment) < 0) {
2361 fore200e->bus->dma_chunk_free(fore200e, &txq->status);
2365 /* get the base address of the cp resident tx queue entries */
2366 cp_entry = fore200e->virt_base + fore200e->bus->read(&fore200e->cp_queues->cp_txq);
2368 /* fill the host resident and cp resident tx entries */
2369 for (i=0; i < QUEUE_SIZE_TX; i++) {
2371 txq->host_entry[ i ].status =
2372 FORE200E_INDEX(txq->status.align_addr, enum status, i);
2373 txq->host_entry[ i ].tpd =
2374 FORE200E_INDEX(txq->tpd.align_addr, struct tpd, i);
2375 txq->host_entry[ i ].tpd_dma =
2376 FORE200E_DMA_INDEX(txq->tpd.dma_addr, struct tpd, i);
2377 txq->host_entry[ i ].cp_entry = &cp_entry[ i ];
2379 *txq->host_entry[ i ].status = STATUS_FREE;
2381 fore200e->bus->write(FORE200E_DMA_INDEX(txq->status.dma_addr, enum status, i),
2382 &cp_entry[ i ].status_haddr);
2384 /* although there is a one-to-one mapping of tx queue entries and tpds,
2385 we do not write here the DMA (physical) base address of each tpd into
2386 the related cp resident entry, because the cp relies on this write
2387 operation to detect that a new pdu has been submitted for tx */
2390 /* set the head and tail entries of the queue */
2394 fore200e->state = FORE200E_STATE_INIT_TXQ;
2399 static int __devinit
2400 fore200e_init_cmd_queue(struct fore200e* fore200e)
2402 struct host_cmdq* cmdq = &fore200e->host_cmdq;
2403 struct cp_cmdq_entry __iomem * cp_entry;
2406 DPRINTK(2, "command queue is being initialized\n");
2408 /* allocate and align the array of status words */
2409 if (fore200e->bus->dma_chunk_alloc(fore200e,
2411 sizeof(enum status),
2413 fore200e->bus->status_alignment) < 0) {
2417 /* get the base address of the cp resident cmd queue entries */
2418 cp_entry = fore200e->virt_base + fore200e->bus->read(&fore200e->cp_queues->cp_cmdq);
2420 /* fill the host resident and cp resident cmd entries */
2421 for (i=0; i < QUEUE_SIZE_CMD; i++) {
2423 cmdq->host_entry[ i ].status =
2424 FORE200E_INDEX(cmdq->status.align_addr, enum status, i);
2425 cmdq->host_entry[ i ].cp_entry = &cp_entry[ i ];
2427 *cmdq->host_entry[ i ].status = STATUS_FREE;
2429 fore200e->bus->write(FORE200E_DMA_INDEX(cmdq->status.dma_addr, enum status, i),
2430 &cp_entry[ i ].status_haddr);
2433 /* set the head entry of the queue */
2436 fore200e->state = FORE200E_STATE_INIT_CMDQ;
2442 fore200e_param_bs_queue(struct fore200e* fore200e,
2443 enum buffer_scheme scheme, enum buffer_magn magn,
2444 int queue_length, int pool_size, int supply_blksize)
2446 struct bs_spec __iomem * bs_spec = &fore200e->cp_queues->init.bs_spec[ scheme ][ magn ];
2448 fore200e->bus->write(queue_length, &bs_spec->queue_length);
2449 fore200e->bus->write(fore200e_rx_buf_size[ scheme ][ magn ], &bs_spec->buffer_size);
2450 fore200e->bus->write(pool_size, &bs_spec->pool_size);
2451 fore200e->bus->write(supply_blksize, &bs_spec->supply_blksize);
2455 static int __devinit
2456 fore200e_initialize(struct fore200e* fore200e)
2458 struct cp_queues __iomem * cpq;
2459 int ok, scheme, magn;
2461 DPRINTK(2, "device %s being initialized\n", fore200e->name);
2463 init_MUTEX(&fore200e->rate_sf);
2464 spin_lock_init(&fore200e->q_lock);
2466 cpq = fore200e->cp_queues = fore200e->virt_base + FORE200E_CP_QUEUES_OFFSET;
2468 /* enable cp to host interrupts */
2469 fore200e->bus->write(1, &cpq->imask);
2471 if (fore200e->bus->irq_enable)
2472 fore200e->bus->irq_enable(fore200e);
2474 fore200e->bus->write(NBR_CONNECT, &cpq->init.num_connect);
2476 fore200e->bus->write(QUEUE_SIZE_CMD, &cpq->init.cmd_queue_len);
2477 fore200e->bus->write(QUEUE_SIZE_RX, &cpq->init.rx_queue_len);
2478 fore200e->bus->write(QUEUE_SIZE_TX, &cpq->init.tx_queue_len);
2480 fore200e->bus->write(RSD_EXTENSION, &cpq->init.rsd_extension);
2481 fore200e->bus->write(TSD_EXTENSION, &cpq->init.tsd_extension);
2483 for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++)
2484 for (magn = 0; magn < BUFFER_MAGN_NBR; magn++)
2485 fore200e_param_bs_queue(fore200e, scheme, magn,
2487 fore200e_rx_buf_nbr[ scheme ][ magn ],
2490 /* issue the initialize command */
2491 fore200e->bus->write(STATUS_PENDING, &cpq->init.status);
2492 fore200e->bus->write(OPCODE_INITIALIZE, &cpq->init.opcode);
2494 ok = fore200e_io_poll(fore200e, &cpq->init.status, STATUS_COMPLETE, 3000);
2496 printk(FORE200E "device %s initialization failed\n", fore200e->name);
2500 printk(FORE200E "device %s initialized\n", fore200e->name);
2502 fore200e->state = FORE200E_STATE_INITIALIZE;
2507 static void __devinit
2508 fore200e_monitor_putc(struct fore200e* fore200e, char c)
2510 struct cp_monitor __iomem * monitor = fore200e->cp_monitor;
2515 fore200e->bus->write(((u32) c) | FORE200E_CP_MONITOR_UART_AVAIL, &monitor->soft_uart.send);
2519 static int __devinit
2520 fore200e_monitor_getc(struct fore200e* fore200e)
2522 struct cp_monitor __iomem * monitor = fore200e->cp_monitor;
2523 unsigned long timeout = jiffies + msecs_to_jiffies(50);
2526 while (time_before(jiffies, timeout)) {
2528 c = (int) fore200e->bus->read(&monitor->soft_uart.recv);
2530 if (c & FORE200E_CP_MONITOR_UART_AVAIL) {
2532 fore200e->bus->write(FORE200E_CP_MONITOR_UART_FREE, &monitor->soft_uart.recv);
2534 printk("%c", c & 0xFF);
2544 static void __devinit
2545 fore200e_monitor_puts(struct fore200e* fore200e, char* str)
2549 /* the i960 monitor doesn't accept any new character if it has something to say */
2550 while (fore200e_monitor_getc(fore200e) >= 0);
2552 fore200e_monitor_putc(fore200e, *str++);
2555 while (fore200e_monitor_getc(fore200e) >= 0);
2559 static int __devinit
2560 fore200e_start_fw(struct fore200e* fore200e)
2564 struct fw_header* fw_header = (struct fw_header*) fore200e->bus->fw_data;
2566 DPRINTK(2, "device %s firmware being started\n", fore200e->name);
2568 #if defined(__sparc_v9__)
2569 /* reported to be required by SBA cards on some sparc64 hosts */
2573 sprintf(cmd, "\rgo %x\r", le32_to_cpu(fw_header->start_offset));
2575 fore200e_monitor_puts(fore200e, cmd);
2577 ok = fore200e_io_poll(fore200e, &fore200e->cp_monitor->bstat, BSTAT_CP_RUNNING, 1000);
2579 printk(FORE200E "device %s firmware didn't start\n", fore200e->name);
2583 printk(FORE200E "device %s firmware started\n", fore200e->name);
2585 fore200e->state = FORE200E_STATE_START_FW;
2590 static int __devinit
2591 fore200e_load_fw(struct fore200e* fore200e)
2593 u32* fw_data = (u32*) fore200e->bus->fw_data;
2594 u32 fw_size = (u32) *fore200e->bus->fw_size / sizeof(u32);
2596 struct fw_header* fw_header = (struct fw_header*) fw_data;
2598 u32 __iomem *load_addr = fore200e->virt_base + le32_to_cpu(fw_header->load_offset);
2600 DPRINTK(2, "device %s firmware being loaded at 0x%p (%d words)\n",
2601 fore200e->name, load_addr, fw_size);
2603 if (le32_to_cpu(fw_header->magic) != FW_HEADER_MAGIC) {
2604 printk(FORE200E "corrupted %s firmware image\n", fore200e->bus->model_name);
2608 for (; fw_size--; fw_data++, load_addr++)
2609 fore200e->bus->write(le32_to_cpu(*fw_data), load_addr);
2611 fore200e->state = FORE200E_STATE_LOAD_FW;
2616 static int __devinit
2617 fore200e_register(struct fore200e* fore200e)
2619 struct atm_dev* atm_dev;
2621 DPRINTK(2, "device %s being registered\n", fore200e->name);
2623 atm_dev = atm_dev_register(fore200e->bus->proc_name, &fore200e_ops, -1,
2625 if (atm_dev == NULL) {
2626 printk(FORE200E "unable to register device %s\n", fore200e->name);
2630 atm_dev->dev_data = fore200e;
2631 fore200e->atm_dev = atm_dev;
2633 atm_dev->ci_range.vpi_bits = FORE200E_VPI_BITS;
2634 atm_dev->ci_range.vci_bits = FORE200E_VCI_BITS;
2636 fore200e->available_cell_rate = ATM_OC3_PCR;
2638 fore200e->state = FORE200E_STATE_REGISTER;
2643 static int __devinit
2644 fore200e_init(struct fore200e* fore200e)
2646 if (fore200e_register(fore200e) < 0)
2649 if (fore200e->bus->configure(fore200e) < 0)
2652 if (fore200e->bus->map(fore200e) < 0)
2655 if (fore200e_reset(fore200e, 1) < 0)
2658 if (fore200e_load_fw(fore200e) < 0)
2661 if (fore200e_start_fw(fore200e) < 0)
2664 if (fore200e_initialize(fore200e) < 0)
2667 if (fore200e_init_cmd_queue(fore200e) < 0)
2670 if (fore200e_init_tx_queue(fore200e) < 0)
2673 if (fore200e_init_rx_queue(fore200e) < 0)
2676 if (fore200e_init_bs_queue(fore200e) < 0)
2679 if (fore200e_alloc_rx_buf(fore200e) < 0)
2682 if (fore200e_get_esi(fore200e) < 0)
2685 if (fore200e_irq_request(fore200e) < 0)
2688 fore200e_supply(fore200e);
2690 /* all done, board initialization is now complete */
2691 fore200e->state = FORE200E_STATE_COMPLETE;
2696 static int __devinit
2697 fore200e_pca_detect(struct pci_dev *pci_dev, const struct pci_device_id *pci_ent)
2699 const struct fore200e_bus* bus = (struct fore200e_bus*) pci_ent->driver_data;
2700 struct fore200e* fore200e;
2702 static int index = 0;
2704 if (pci_enable_device(pci_dev)) {
2709 fore200e = kzalloc(sizeof(struct fore200e), GFP_KERNEL);
2710 if (fore200e == NULL) {
2715 fore200e->bus = bus;
2716 fore200e->bus_dev = pci_dev;
2717 fore200e->irq = pci_dev->irq;
2718 fore200e->phys_base = pci_resource_start(pci_dev, 0);
2720 sprintf(fore200e->name, "%s-%d", bus->model_name, index - 1);
2722 pci_set_master(pci_dev);
2724 printk(FORE200E "device %s found at 0x%lx, IRQ %s\n",
2725 fore200e->bus->model_name,
2726 fore200e->phys_base, fore200e_irq_itoa(fore200e->irq));
2728 sprintf(fore200e->name, "%s-%d", bus->model_name, index);
2730 err = fore200e_init(fore200e);
2732 fore200e_shutdown(fore200e);
2737 pci_set_drvdata(pci_dev, fore200e);
2745 pci_disable_device(pci_dev);
2750 static void __devexit fore200e_pca_remove_one(struct pci_dev *pci_dev)
2752 struct fore200e *fore200e;
2754 fore200e = pci_get_drvdata(pci_dev);
2756 fore200e_shutdown(fore200e);
2758 pci_disable_device(pci_dev);
2762 #ifdef CONFIG_ATM_FORE200E_PCA
2763 static struct pci_device_id fore200e_pca_tbl[] = {
2764 { PCI_VENDOR_ID_FORE, PCI_DEVICE_ID_FORE_PCA200E, PCI_ANY_ID, PCI_ANY_ID,
2765 0, 0, (unsigned long) &fore200e_bus[0] },
2769 MODULE_DEVICE_TABLE(pci, fore200e_pca_tbl);
2771 static struct pci_driver fore200e_pca_driver = {
2772 .name = "fore_200e",
2773 .probe = fore200e_pca_detect,
2774 .remove = __devexit_p(fore200e_pca_remove_one),
2775 .id_table = fore200e_pca_tbl,
2781 fore200e_module_init(void)
2783 const struct fore200e_bus* bus;
2784 struct fore200e* fore200e;
2787 printk(FORE200E "FORE Systems 200E-series ATM driver - version " FORE200E_VERSION "\n");
2789 /* for each configured bus interface */
2790 for (bus = fore200e_bus; bus->model_name; bus++) {
2792 /* detect all boards present on that bus */
2793 for (index = 0; bus->detect && (fore200e = bus->detect(bus, index)); index++) {
2795 printk(FORE200E "device %s found at 0x%lx, IRQ %s\n",
2796 fore200e->bus->model_name,
2797 fore200e->phys_base, fore200e_irq_itoa(fore200e->irq));
2799 sprintf(fore200e->name, "%s-%d", bus->model_name, index);
2801 if (fore200e_init(fore200e) < 0) {
2803 fore200e_shutdown(fore200e);
2807 list_add(&fore200e->entry, &fore200e_boards);
2811 #ifdef CONFIG_ATM_FORE200E_PCA
2812 if (!pci_register_driver(&fore200e_pca_driver))
2816 if (!list_empty(&fore200e_boards))
2824 fore200e_module_cleanup(void)
2826 struct fore200e *fore200e, *next;
2828 #ifdef CONFIG_ATM_FORE200E_PCA
2829 pci_unregister_driver(&fore200e_pca_driver);
2832 list_for_each_entry_safe(fore200e, next, &fore200e_boards, entry) {
2833 fore200e_shutdown(fore200e);
2836 DPRINTK(1, "module being removed\n");
2841 fore200e_proc_read(struct atm_dev *dev, loff_t* pos, char* page)
2843 struct fore200e* fore200e = FORE200E_DEV(dev);
2844 struct fore200e_vcc* fore200e_vcc;
2845 struct atm_vcc* vcc;
2846 int i, len, left = *pos;
2847 unsigned long flags;
2851 if (fore200e_getstats(fore200e) < 0)
2854 len = sprintf(page,"\n"
2856 " internal name:\t\t%s\n", fore200e->name);
2858 /* print bus-specific information */
2859 if (fore200e->bus->proc_read)
2860 len += fore200e->bus->proc_read(fore200e, page + len);
2862 len += sprintf(page + len,
2863 " interrupt line:\t\t%s\n"
2864 " physical base address:\t0x%p\n"
2865 " virtual base address:\t0x%p\n"
2866 " factory address (ESI):\t%02x:%02x:%02x:%02x:%02x:%02x\n"
2867 " board serial number:\t\t%d\n\n",
2868 fore200e_irq_itoa(fore200e->irq),
2869 (void*)fore200e->phys_base,
2870 fore200e->virt_base,
2871 fore200e->esi[0], fore200e->esi[1], fore200e->esi[2],
2872 fore200e->esi[3], fore200e->esi[4], fore200e->esi[5],
2873 fore200e->esi[4] * 256 + fore200e->esi[5]);
2879 return sprintf(page,
2880 " free small bufs, scheme 1:\t%d\n"
2881 " free large bufs, scheme 1:\t%d\n"
2882 " free small bufs, scheme 2:\t%d\n"
2883 " free large bufs, scheme 2:\t%d\n",
2884 fore200e->host_bsq[ BUFFER_SCHEME_ONE ][ BUFFER_MAGN_SMALL ].freebuf_count,
2885 fore200e->host_bsq[ BUFFER_SCHEME_ONE ][ BUFFER_MAGN_LARGE ].freebuf_count,
2886 fore200e->host_bsq[ BUFFER_SCHEME_TWO ][ BUFFER_MAGN_SMALL ].freebuf_count,
2887 fore200e->host_bsq[ BUFFER_SCHEME_TWO ][ BUFFER_MAGN_LARGE ].freebuf_count);
2890 u32 hb = fore200e->bus->read(&fore200e->cp_queues->heartbeat);
2892 len = sprintf(page,"\n\n"
2893 " cell processor:\n"
2894 " heartbeat state:\t\t");
2896 if (hb >> 16 != 0xDEAD)
2897 len += sprintf(page + len, "0x%08x\n", hb);
2899 len += sprintf(page + len, "*** FATAL ERROR %04x ***\n", hb & 0xFFFF);
2905 static const char* media_name[] = {
2906 "unshielded twisted pair",
2907 "multimode optical fiber ST",
2908 "multimode optical fiber SC",
2909 "single-mode optical fiber ST",
2910 "single-mode optical fiber SC",
2914 static const char* oc3_mode[] = {
2916 "diagnostic loopback",
2921 u32 fw_release = fore200e->bus->read(&fore200e->cp_queues->fw_release);
2922 u32 mon960_release = fore200e->bus->read(&fore200e->cp_queues->mon960_release);
2923 u32 oc3_revision = fore200e->bus->read(&fore200e->cp_queues->oc3_revision);
2924 u32 media_index = FORE200E_MEDIA_INDEX(fore200e->bus->read(&fore200e->cp_queues->media_type));
2927 if ((media_index < 0) || (media_index > 4))
2930 switch (fore200e->loop_mode) {
2931 case ATM_LM_NONE: oc3_index = 0;
2933 case ATM_LM_LOC_PHY: oc3_index = 1;
2935 case ATM_LM_RMT_PHY: oc3_index = 2;
2937 default: oc3_index = 3;
2940 return sprintf(page,
2941 " firmware release:\t\t%d.%d.%d\n"
2942 " monitor release:\t\t%d.%d\n"
2943 " media type:\t\t\t%s\n"
2944 " OC-3 revision:\t\t0x%x\n"
2945 " OC-3 mode:\t\t\t%s",
2946 fw_release >> 16, fw_release << 16 >> 24, fw_release << 24 >> 24,
2947 mon960_release >> 16, mon960_release << 16 >> 16,
2948 media_name[ media_index ],
2950 oc3_mode[ oc3_index ]);
2954 struct cp_monitor __iomem * cp_monitor = fore200e->cp_monitor;
2956 return sprintf(page,
2959 " version number:\t\t%d\n"
2960 " boot status word:\t\t0x%08x\n",
2961 fore200e->bus->read(&cp_monitor->mon_version),
2962 fore200e->bus->read(&cp_monitor->bstat));
2966 return sprintf(page,
2968 " device statistics:\n"
2970 " crc_header_errors:\t\t%10u\n"
2971 " framing_errors:\t\t%10u\n",
2972 cpu_to_be32(fore200e->stats->phy.crc_header_errors),
2973 cpu_to_be32(fore200e->stats->phy.framing_errors));
2976 return sprintf(page, "\n"
2978 " section_bip8_errors:\t%10u\n"
2979 " path_bip8_errors:\t\t%10u\n"
2980 " line_bip24_errors:\t\t%10u\n"
2981 " line_febe_errors:\t\t%10u\n"
2982 " path_febe_errors:\t\t%10u\n"
2983 " corr_hcs_errors:\t\t%10u\n"
2984 " ucorr_hcs_errors:\t\t%10u\n",
2985 cpu_to_be32(fore200e->stats->oc3.section_bip8_errors),
2986 cpu_to_be32(fore200e->stats->oc3.path_bip8_errors),
2987 cpu_to_be32(fore200e->stats->oc3.line_bip24_errors),
2988 cpu_to_be32(fore200e->stats->oc3.line_febe_errors),
2989 cpu_to_be32(fore200e->stats->oc3.path_febe_errors),
2990 cpu_to_be32(fore200e->stats->oc3.corr_hcs_errors),
2991 cpu_to_be32(fore200e->stats->oc3.ucorr_hcs_errors));
2994 return sprintf(page,"\n"
2995 " ATM:\t\t\t\t cells\n"
2998 " vpi out of range:\t\t%10u\n"
2999 " vpi no conn:\t\t%10u\n"
3000 " vci out of range:\t\t%10u\n"
3001 " vci no conn:\t\t%10u\n",
3002 cpu_to_be32(fore200e->stats->atm.cells_transmitted),
3003 cpu_to_be32(fore200e->stats->atm.cells_received),
3004 cpu_to_be32(fore200e->stats->atm.vpi_bad_range),
3005 cpu_to_be32(fore200e->stats->atm.vpi_no_conn),
3006 cpu_to_be32(fore200e->stats->atm.vci_bad_range),
3007 cpu_to_be32(fore200e->stats->atm.vci_no_conn));
3010 return sprintf(page,"\n"
3011 " AAL0:\t\t\t cells\n"
3014 " dropped:\t\t\t%10u\n",
3015 cpu_to_be32(fore200e->stats->aal0.cells_transmitted),
3016 cpu_to_be32(fore200e->stats->aal0.cells_received),
3017 cpu_to_be32(fore200e->stats->aal0.cells_dropped));
3020 return sprintf(page,"\n"
3022 " SAR sublayer:\t\t cells\n"
3025 " dropped:\t\t\t%10u\n"
3026 " CRC errors:\t\t%10u\n"
3027 " protocol errors:\t\t%10u\n\n"
3028 " CS sublayer:\t\t PDUs\n"
3031 " dropped:\t\t\t%10u\n"
3032 " protocol errors:\t\t%10u\n",
3033 cpu_to_be32(fore200e->stats->aal34.cells_transmitted),
3034 cpu_to_be32(fore200e->stats->aal34.cells_received),
3035 cpu_to_be32(fore200e->stats->aal34.cells_dropped),
3036 cpu_to_be32(fore200e->stats->aal34.cells_crc_errors),
3037 cpu_to_be32(fore200e->stats->aal34.cells_protocol_errors),
3038 cpu_to_be32(fore200e->stats->aal34.cspdus_transmitted),
3039 cpu_to_be32(fore200e->stats->aal34.cspdus_received),
3040 cpu_to_be32(fore200e->stats->aal34.cspdus_dropped),
3041 cpu_to_be32(fore200e->stats->aal34.cspdus_protocol_errors));
3044 return sprintf(page,"\n"
3046 " SAR sublayer:\t\t cells\n"
3049 " dropped:\t\t\t%10u\n"
3050 " congestions:\t\t%10u\n\n"
3051 " CS sublayer:\t\t PDUs\n"
3054 " dropped:\t\t\t%10u\n"
3055 " CRC errors:\t\t%10u\n"
3056 " protocol errors:\t\t%10u\n",
3057 cpu_to_be32(fore200e->stats->aal5.cells_transmitted),
3058 cpu_to_be32(fore200e->stats->aal5.cells_received),
3059 cpu_to_be32(fore200e->stats->aal5.cells_dropped),
3060 cpu_to_be32(fore200e->stats->aal5.congestion_experienced),
3061 cpu_to_be32(fore200e->stats->aal5.cspdus_transmitted),
3062 cpu_to_be32(fore200e->stats->aal5.cspdus_received),
3063 cpu_to_be32(fore200e->stats->aal5.cspdus_dropped),
3064 cpu_to_be32(fore200e->stats->aal5.cspdus_crc_errors),
3065 cpu_to_be32(fore200e->stats->aal5.cspdus_protocol_errors));
3068 return sprintf(page,"\n"
3069 " AUX:\t\t allocation failures\n"
3070 " small b1:\t\t\t%10u\n"
3071 " large b1:\t\t\t%10u\n"
3072 " small b2:\t\t\t%10u\n"
3073 " large b2:\t\t\t%10u\n"
3074 " RX PDUs:\t\t\t%10u\n"
3075 " TX PDUs:\t\t\t%10lu\n",
3076 cpu_to_be32(fore200e->stats->aux.small_b1_failed),
3077 cpu_to_be32(fore200e->stats->aux.large_b1_failed),
3078 cpu_to_be32(fore200e->stats->aux.small_b2_failed),
3079 cpu_to_be32(fore200e->stats->aux.large_b2_failed),
3080 cpu_to_be32(fore200e->stats->aux.rpd_alloc_failed),
3084 return sprintf(page,"\n"
3085 " receive carrier:\t\t\t%s\n",
3086 fore200e->stats->aux.receive_carrier ? "ON" : "OFF!");
3089 return sprintf(page,"\n"
3090 " VCCs:\n address VPI VCI AAL "
3091 "TX PDUs TX min/max size RX PDUs RX min/max size\n");
3094 for (i = 0; i < NBR_CONNECT; i++) {
3096 vcc = fore200e->vc_map[i].vcc;
3101 spin_lock_irqsave(&fore200e->q_lock, flags);
3103 if (vcc && test_bit(ATM_VF_READY, &vcc->flags) && !left--) {
3105 fore200e_vcc = FORE200E_VCC(vcc);
3106 ASSERT(fore200e_vcc);
3109 " %08x %03d %05d %1d %09lu %05d/%05d %09lu %05d/%05d\n",
3110 (u32)(unsigned long)vcc,
3111 vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal),
3112 fore200e_vcc->tx_pdu,
3113 fore200e_vcc->tx_min_pdu > 0xFFFF ? 0 : fore200e_vcc->tx_min_pdu,
3114 fore200e_vcc->tx_max_pdu,
3115 fore200e_vcc->rx_pdu,
3116 fore200e_vcc->rx_min_pdu > 0xFFFF ? 0 : fore200e_vcc->rx_min_pdu,
3117 fore200e_vcc->rx_max_pdu);
3119 spin_unlock_irqrestore(&fore200e->q_lock, flags);
3123 spin_unlock_irqrestore(&fore200e->q_lock, flags);
3129 module_init(fore200e_module_init);
3130 module_exit(fore200e_module_cleanup);
3133 static const struct atmdev_ops fore200e_ops =
3135 .open = fore200e_open,
3136 .close = fore200e_close,
3137 .ioctl = fore200e_ioctl,
3138 .getsockopt = fore200e_getsockopt,
3139 .setsockopt = fore200e_setsockopt,
3140 .send = fore200e_send,
3141 .change_qos = fore200e_change_qos,
3142 .proc_read = fore200e_proc_read,
3143 .owner = THIS_MODULE
3147 #ifdef CONFIG_ATM_FORE200E_PCA
3148 extern const unsigned char _fore200e_pca_fw_data[];
3149 extern const unsigned int _fore200e_pca_fw_size;
3151 #ifdef CONFIG_ATM_FORE200E_SBA
3152 extern const unsigned char _fore200e_sba_fw_data[];
3153 extern const unsigned int _fore200e_sba_fw_size;
3156 static const struct fore200e_bus fore200e_bus[] = {
3157 #ifdef CONFIG_ATM_FORE200E_PCA
3158 { "PCA-200E", "pca200e", 32, 4, 32,
3159 _fore200e_pca_fw_data, &_fore200e_pca_fw_size,
3162 fore200e_pca_dma_map,
3163 fore200e_pca_dma_unmap,
3164 fore200e_pca_dma_sync_for_cpu,
3165 fore200e_pca_dma_sync_for_device,
3166 fore200e_pca_dma_chunk_alloc,
3167 fore200e_pca_dma_chunk_free,
3169 fore200e_pca_configure,
3172 fore200e_pca_prom_read,
3175 fore200e_pca_irq_check,
3176 fore200e_pca_irq_ack,
3177 fore200e_pca_proc_read,
3180 #ifdef CONFIG_ATM_FORE200E_SBA
3181 { "SBA-200E", "sba200e", 32, 64, 32,
3182 _fore200e_sba_fw_data, &_fore200e_sba_fw_size,
3185 fore200e_sba_dma_map,
3186 fore200e_sba_dma_unmap,
3187 fore200e_sba_dma_sync_for_cpu,
3188 fore200e_sba_dma_sync_for_device,
3189 fore200e_sba_dma_chunk_alloc,
3190 fore200e_sba_dma_chunk_free,
3191 fore200e_sba_detect,
3192 fore200e_sba_configure,
3195 fore200e_sba_prom_read,
3197 fore200e_sba_irq_enable,
3198 fore200e_sba_irq_check,
3199 fore200e_sba_irq_ack,
3200 fore200e_sba_proc_read,
3206 #ifdef MODULE_LICENSE
3207 MODULE_LICENSE("GPL");