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/version.h>
29 #include <linux/config.h>
30 #include <linux/kernel.h>
31 #include <linux/slab.h>
32 #include <linux/init.h>
33 #include <linux/capability.h>
34 #include <linux/sched.h>
35 #include <linux/interrupt.h>
36 #include <linux/bitops.h>
37 #include <linux/pci.h>
38 #include <linux/module.h>
39 #include <linux/atmdev.h>
40 #include <linux/sonet.h>
41 #include <linux/atm_suni.h>
43 #include <asm/string.h>
44 #include <asm/segment.h>
48 #include <asm/byteorder.h>
49 #include <asm/uaccess.h>
50 #include <asm/atomic.h>
52 #ifdef CONFIG_ATM_FORE200E_SBA
53 #include <asm/idprom.h>
55 #include <asm/openprom.h>
56 #include <asm/oplib.h>
57 #include <asm/pgtable.h>
60 #if defined(CONFIG_ATM_FORE200E_USE_TASKLET) /* defer interrupt work to a tasklet */
61 #define FORE200E_USE_TASKLET
64 #if 0 /* enable the debugging code of the buffer supply queues */
65 #define FORE200E_BSQ_DEBUG
68 #if 1 /* ensure correct handling of 52-byte AAL0 SDUs expected by atmdump-like apps */
69 #define FORE200E_52BYTE_AAL0_SDU
75 #define FORE200E_VERSION "0.3e"
77 #define FORE200E "fore200e: "
79 #if 0 /* override .config */
80 #define CONFIG_ATM_FORE200E_DEBUG 1
82 #if defined(CONFIG_ATM_FORE200E_DEBUG) && (CONFIG_ATM_FORE200E_DEBUG > 0)
83 #define DPRINTK(level, format, args...) do { if (CONFIG_ATM_FORE200E_DEBUG >= (level)) \
84 printk(FORE200E format, ##args); } while (0)
86 #define DPRINTK(level, format, args...) do {} while (0)
90 #define FORE200E_ALIGN(addr, alignment) \
91 ((((unsigned long)(addr) + (alignment - 1)) & ~(alignment - 1)) - (unsigned long)(addr))
93 #define FORE200E_DMA_INDEX(dma_addr, type, index) ((dma_addr) + (index) * sizeof(type))
95 #define FORE200E_INDEX(virt_addr, type, index) (&((type *)(virt_addr))[ index ])
97 #define FORE200E_NEXT_ENTRY(index, modulo) (index = ++(index) % (modulo))
100 #define MSECS(ms) (((ms)*HZ/1000)+1)
105 #define ASSERT(expr) if (!(expr)) { \
106 printk(FORE200E "assertion failed! %s[%d]: %s\n", \
107 __FUNCTION__, __LINE__, #expr); \
108 panic(FORE200E "%s", __FUNCTION__); \
111 #define ASSERT(expr) do {} while (0)
115 static const struct atmdev_ops fore200e_ops;
116 static const struct fore200e_bus fore200e_bus[];
118 static struct fore200e* fore200e_boards = NULL;
121 MODULE_AUTHOR("Christophe Lizzi - credits to Uwe Dannowski and Heikki Vatiainen");
122 MODULE_DESCRIPTION("FORE Systems 200E-series ATM driver - version " FORE200E_VERSION);
123 MODULE_SUPPORTED_DEVICE("PCA-200E, SBA-200E");
127 static const int fore200e_rx_buf_nbr[ BUFFER_SCHEME_NBR ][ BUFFER_MAGN_NBR ] = {
128 { BUFFER_S1_NBR, BUFFER_L1_NBR },
129 { BUFFER_S2_NBR, BUFFER_L2_NBR }
132 static const int fore200e_rx_buf_size[ BUFFER_SCHEME_NBR ][ BUFFER_MAGN_NBR ] = {
133 { BUFFER_S1_SIZE, BUFFER_L1_SIZE },
134 { BUFFER_S2_SIZE, BUFFER_L2_SIZE }
138 #if defined(CONFIG_ATM_FORE200E_DEBUG) && (CONFIG_ATM_FORE200E_DEBUG > 0)
139 static const char* fore200e_traffic_class[] = { "NONE", "UBR", "CBR", "VBR", "ABR", "ANY" };
143 #if 0 /* currently unused */
145 fore200e_fore2atm_aal(enum fore200e_aal aal)
148 case FORE200E_AAL0: return ATM_AAL0;
149 case FORE200E_AAL34: return ATM_AAL34;
150 case FORE200E_AAL5: return ATM_AAL5;
158 static enum fore200e_aal
159 fore200e_atm2fore_aal(int aal)
162 case ATM_AAL0: return FORE200E_AAL0;
163 case ATM_AAL34: return FORE200E_AAL34;
166 case ATM_AAL5: return FORE200E_AAL5;
174 fore200e_irq_itoa(int irq)
176 #if defined(__sparc_v9__)
177 return __irq_itoa(irq);
180 sprintf(str, "%d", irq);
187 fore200e_kmalloc(int size, int flags)
189 void* chunk = kmalloc(size, flags);
192 memset(chunk, 0x00, size);
194 printk(FORE200E "kmalloc() failed, requested size = %d, flags = 0x%x\n", size, flags);
201 fore200e_kfree(void* chunk)
207 /* allocate and align a chunk of memory intended to hold the data behing exchanged
208 between the driver and the adapter (using streaming DVMA) */
211 fore200e_chunk_alloc(struct fore200e* fore200e, struct chunk* chunk, int size, int alignment, int direction)
213 unsigned long offset = 0;
215 if (alignment <= sizeof(int))
218 chunk->alloc_size = size + alignment;
219 chunk->align_size = size;
220 chunk->direction = direction;
222 chunk->alloc_addr = fore200e_kmalloc(chunk->alloc_size, GFP_KERNEL | GFP_DMA);
223 if (chunk->alloc_addr == NULL)
227 offset = FORE200E_ALIGN(chunk->alloc_addr, alignment);
229 chunk->align_addr = chunk->alloc_addr + offset;
231 chunk->dma_addr = fore200e->bus->dma_map(fore200e, chunk->align_addr, chunk->align_size, direction);
237 /* free a chunk of memory */
240 fore200e_chunk_free(struct fore200e* fore200e, struct chunk* chunk)
242 fore200e->bus->dma_unmap(fore200e, chunk->dma_addr, chunk->dma_size, chunk->direction);
244 fore200e_kfree(chunk->alloc_addr);
249 fore200e_spin(int msecs)
251 unsigned long timeout = jiffies + MSECS(msecs);
252 while (time_before(jiffies, timeout));
257 fore200e_poll(struct fore200e* fore200e, volatile u32* addr, u32 val, int msecs)
259 unsigned long timeout = jiffies + MSECS(msecs);
264 if ((ok = (*addr == val)) || (*addr & STATUS_ERROR))
267 } while (time_before(jiffies, timeout));
271 printk(FORE200E "cmd polling failed, got status 0x%08x, expected 0x%08x\n",
281 fore200e_io_poll(struct fore200e* fore200e, volatile u32* addr, u32 val, int msecs)
283 unsigned long timeout = jiffies + MSECS(msecs);
287 if ((ok = (fore200e->bus->read(addr) == val)))
290 } while (time_before(jiffies, timeout));
294 printk(FORE200E "I/O polling failed, got status 0x%08x, expected 0x%08x\n",
295 fore200e->bus->read(addr), val);
304 fore200e_free_rx_buf(struct fore200e* fore200e)
306 int scheme, magn, nbr;
307 struct buffer* buffer;
309 for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
310 for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
312 if ((buffer = fore200e->host_bsq[ scheme ][ magn ].buffer) != NULL) {
314 for (nbr = 0; nbr < fore200e_rx_buf_nbr[ scheme ][ magn ]; nbr++) {
316 struct chunk* data = &buffer[ nbr ].data;
318 if (data->alloc_addr != NULL)
319 fore200e_chunk_free(fore200e, data);
328 fore200e_uninit_bs_queue(struct fore200e* fore200e)
332 for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
333 for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
335 struct chunk* status = &fore200e->host_bsq[ scheme ][ magn ].status;
336 struct chunk* rbd_block = &fore200e->host_bsq[ scheme ][ magn ].rbd_block;
338 if (status->alloc_addr)
339 fore200e->bus->dma_chunk_free(fore200e, status);
341 if (rbd_block->alloc_addr)
342 fore200e->bus->dma_chunk_free(fore200e, rbd_block);
349 fore200e_reset(struct fore200e* fore200e, int diag)
353 fore200e->cp_monitor = (struct cp_monitor*)(fore200e->virt_base + FORE200E_CP_MONITOR_OFFSET);
355 fore200e->bus->write(BSTAT_COLD_START, &fore200e->cp_monitor->bstat);
357 fore200e->bus->reset(fore200e);
360 ok = fore200e_io_poll(fore200e, &fore200e->cp_monitor->bstat, BSTAT_SELFTEST_OK, 1000);
363 printk(FORE200E "device %s self-test failed\n", fore200e->name);
367 printk(FORE200E "device %s self-test passed\n", fore200e->name);
369 fore200e->state = FORE200E_STATE_RESET;
377 fore200e_shutdown(struct fore200e* fore200e)
379 printk(FORE200E "removing device %s at 0x%lx, IRQ %s\n",
380 fore200e->name, fore200e->phys_base,
381 fore200e_irq_itoa(fore200e->irq));
383 if (fore200e->state > FORE200E_STATE_RESET) {
384 /* first, reset the board to prevent further interrupts or data transfers */
385 fore200e_reset(fore200e, 0);
388 /* then, release all allocated resources */
389 switch(fore200e->state) {
391 case FORE200E_STATE_COMPLETE:
393 kfree(fore200e->stats);
395 case FORE200E_STATE_IRQ:
396 free_irq(fore200e->irq, fore200e->atm_dev);
398 case FORE200E_STATE_ALLOC_BUF:
399 fore200e_free_rx_buf(fore200e);
401 case FORE200E_STATE_INIT_BSQ:
402 fore200e_uninit_bs_queue(fore200e);
404 case FORE200E_STATE_INIT_RXQ:
405 fore200e->bus->dma_chunk_free(fore200e, &fore200e->host_rxq.status);
406 fore200e->bus->dma_chunk_free(fore200e, &fore200e->host_rxq.rpd);
408 case FORE200E_STATE_INIT_TXQ:
409 fore200e->bus->dma_chunk_free(fore200e, &fore200e->host_txq.status);
410 fore200e->bus->dma_chunk_free(fore200e, &fore200e->host_txq.tpd);
412 case FORE200E_STATE_INIT_CMDQ:
413 fore200e->bus->dma_chunk_free(fore200e, &fore200e->host_cmdq.status);
415 case FORE200E_STATE_INITIALIZE:
416 /* nothing to do for that state */
418 case FORE200E_STATE_START_FW:
419 /* nothing to do for that state */
421 case FORE200E_STATE_LOAD_FW:
422 /* nothing to do for that state */
424 case FORE200E_STATE_RESET:
425 /* nothing to do for that state */
427 case FORE200E_STATE_MAP:
428 fore200e->bus->unmap(fore200e);
430 case FORE200E_STATE_CONFIGURE:
431 /* nothing to do for that state */
433 case FORE200E_STATE_REGISTER:
434 /* XXX shouldn't we *start* by deregistering the device? */
435 atm_dev_deregister(fore200e->atm_dev);
437 case FORE200E_STATE_BLANK:
438 /* nothing to do for that state */
444 #ifdef CONFIG_ATM_FORE200E_PCA
446 static u32 fore200e_pca_read(volatile u32* addr)
448 /* on big-endian hosts, the board is configured to convert
449 the endianess of slave RAM accesses */
450 return le32_to_cpu(readl(addr));
454 static void fore200e_pca_write(u32 val, volatile u32* addr)
456 /* on big-endian hosts, the board is configured to convert
457 the endianess of slave RAM accesses */
458 writel(cpu_to_le32(val), addr);
463 fore200e_pca_dma_map(struct fore200e* fore200e, void* virt_addr, int size, int direction)
465 u32 dma_addr = pci_map_single((struct pci_dev*)fore200e->bus_dev, virt_addr, size, direction);
467 DPRINTK(3, "PCI DVMA mapping: virt_addr = 0x%p, size = %d, direction = %d, --> dma_addr = 0x%08x\n",
468 virt_addr, size, direction, dma_addr);
475 fore200e_pca_dma_unmap(struct fore200e* fore200e, u32 dma_addr, int size, int direction)
477 DPRINTK(3, "PCI DVMA unmapping: dma_addr = 0x%08x, size = %d, direction = %d\n",
478 dma_addr, size, direction);
480 pci_unmap_single((struct pci_dev*)fore200e->bus_dev, dma_addr, size, direction);
485 fore200e_pca_dma_sync(struct fore200e* fore200e, u32 dma_addr, int size, int direction)
487 DPRINTK(3, "PCI DVMA sync: dma_addr = 0x%08x, size = %d, direction = %d\n", dma_addr, size, direction);
489 pci_dma_sync_single((struct pci_dev*)fore200e->bus_dev, dma_addr, size, direction);
493 /* allocate a DMA consistent chunk of memory intended to act as a communication mechanism
494 (to hold descriptors, status, queues, etc.) shared by the driver and the adapter */
497 fore200e_pca_dma_chunk_alloc(struct fore200e* fore200e, struct chunk* chunk,
498 int size, int nbr, int alignment)
500 /* returned chunks are page-aligned */
501 chunk->alloc_size = size * nbr;
502 chunk->alloc_addr = pci_alloc_consistent((struct pci_dev*)fore200e->bus_dev,
506 if ((chunk->alloc_addr == NULL) || (chunk->dma_addr == 0))
509 chunk->align_addr = chunk->alloc_addr;
515 /* free a DMA consistent chunk of memory */
518 fore200e_pca_dma_chunk_free(struct fore200e* fore200e, struct chunk* chunk)
520 pci_free_consistent((struct pci_dev*)fore200e->bus_dev,
528 fore200e_pca_irq_check(struct fore200e* fore200e)
530 /* this is a 1 bit register */
531 int irq_posted = readl(fore200e->regs.pca.psr);
533 #if defined(CONFIG_ATM_FORE200E_DEBUG) && (CONFIG_ATM_FORE200E_DEBUG == 2)
534 if (irq_posted && (readl(fore200e->regs.pca.hcr) & PCA200E_HCR_OUTFULL)) {
535 DPRINTK(2,"FIFO OUT full, device %d\n", fore200e->atm_dev->number);
544 fore200e_pca_irq_ack(struct fore200e* fore200e)
546 writel(PCA200E_HCR_CLRINTR, fore200e->regs.pca.hcr);
551 fore200e_pca_reset(struct fore200e* fore200e)
553 writel(PCA200E_HCR_RESET, fore200e->regs.pca.hcr);
555 writel(0, fore200e->regs.pca.hcr);
560 fore200e_pca_map(struct fore200e* fore200e)
562 DPRINTK(2, "device %s being mapped in memory\n", fore200e->name);
564 fore200e->virt_base = ioremap(fore200e->phys_base, PCA200E_IOSPACE_LENGTH);
566 if (fore200e->virt_base == NULL) {
567 printk(FORE200E "can't map device %s\n", fore200e->name);
571 DPRINTK(1, "device %s mapped to 0x%p\n", fore200e->name, fore200e->virt_base);
573 /* gain access to the PCA specific registers */
574 fore200e->regs.pca.hcr = (u32*)(fore200e->virt_base + PCA200E_HCR_OFFSET);
575 fore200e->regs.pca.imr = (u32*)(fore200e->virt_base + PCA200E_IMR_OFFSET);
576 fore200e->regs.pca.psr = (u32*)(fore200e->virt_base + PCA200E_PSR_OFFSET);
578 fore200e->state = FORE200E_STATE_MAP;
584 fore200e_pca_unmap(struct fore200e* fore200e)
586 DPRINTK(2, "device %s being unmapped from memory\n", fore200e->name);
588 if (fore200e->virt_base != NULL)
589 iounmap(fore200e->virt_base);
594 fore200e_pca_configure(struct fore200e* fore200e)
596 struct pci_dev* pci_dev = (struct pci_dev*)fore200e->bus_dev;
597 u8 master_ctrl, latency;
599 DPRINTK(2, "device %s being configured\n", fore200e->name);
601 if ((pci_dev->irq == 0) || (pci_dev->irq == 0xFF)) {
602 printk(FORE200E "incorrect IRQ setting - misconfigured PCI-PCI bridge?\n");
606 pci_read_config_byte(pci_dev, PCA200E_PCI_MASTER_CTRL, &master_ctrl);
608 master_ctrl = master_ctrl
609 #if defined(__BIG_ENDIAN)
610 /* request the PCA board to convert the endianess of slave RAM accesses */
611 | PCA200E_CTRL_CONVERT_ENDIAN
614 | PCA200E_CTRL_DIS_CACHE_RD
615 | PCA200E_CTRL_DIS_WRT_INVAL
616 | PCA200E_CTRL_ENA_CONT_REQ_MODE
617 | PCA200E_CTRL_2_CACHE_WRT_INVAL
619 | PCA200E_CTRL_LARGE_PCI_BURSTS;
621 pci_write_config_byte(pci_dev, PCA200E_PCI_MASTER_CTRL, master_ctrl);
623 /* raise latency from 32 (default) to 192, as this seems to prevent NIC
624 lockups (under heavy rx loads) due to continuous 'FIFO OUT full' condition.
625 this may impact the performances of other PCI devices on the same bus, though */
627 pci_write_config_byte(pci_dev, PCI_LATENCY_TIMER, latency);
629 fore200e->state = FORE200E_STATE_CONFIGURE;
634 static struct fore200e* __init
635 fore200e_pca_detect(const struct fore200e_bus* bus, int index)
637 struct fore200e* fore200e;
638 struct pci_dev* pci_dev = NULL;
641 if (pci_present() == 0) {
642 printk(FORE200E "no PCI subsystem\n");
647 pci_dev = pci_find_device(PCI_VENDOR_ID_FORE, PCI_DEVICE_ID_FORE_PCA200E, pci_dev);
652 if (pci_enable_device(pci_dev))
655 fore200e = fore200e_kmalloc(sizeof(struct fore200e), GFP_KERNEL);
656 if (fore200e == NULL)
660 fore200e->bus_dev = pci_dev;
661 fore200e->irq = pci_dev->irq;
662 fore200e->phys_base = pci_resource_start(pci_dev, 0);
664 sprintf(fore200e->name, "%s-%d", bus->model_name, index - 1);
666 pci_set_master(pci_dev);
673 fore200e_pca_prom_read(struct fore200e* fore200e, struct prom_data* prom)
675 struct host_cmdq* cmdq = &fore200e->host_cmdq;
676 struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
677 struct prom_opcode opcode;
681 FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
683 opcode.opcode = OPCODE_GET_PROM;
686 prom_dma = fore200e->bus->dma_map(fore200e, prom, sizeof(struct prom_data), FORE200E_DMA_FROMDEVICE);
688 fore200e->bus->write(prom_dma, &entry->cp_entry->cmd.prom_block.prom_haddr);
690 *entry->status = STATUS_PENDING;
692 fore200e->bus->write(*(u32*)&opcode, (u32*)&entry->cp_entry->cmd.prom_block.opcode);
694 ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
696 *entry->status = STATUS_FREE;
698 fore200e->bus->dma_unmap(fore200e, prom_dma, sizeof(struct prom_data), FORE200E_DMA_FROMDEVICE);
701 printk(FORE200E "unable to get PROM data from device %s\n", fore200e->name);
705 #if defined(__BIG_ENDIAN)
707 #define swap_here(addr) (*((u32*)(addr)) = swab32( *((u32*)(addr)) ))
709 /* MAC address is stored as little-endian */
710 swap_here(&prom->mac_addr[0]);
711 swap_here(&prom->mac_addr[4]);
719 fore200e_pca_proc_read(struct fore200e* fore200e, char *page)
721 struct pci_dev* pci_dev = (struct pci_dev*)fore200e->bus_dev;
723 return sprintf(page, " PCI bus/slot/function:\t%d/%d/%d\n",
724 pci_dev->bus->number, PCI_SLOT(pci_dev->devfn), PCI_FUNC(pci_dev->devfn));
727 #endif /* CONFIG_ATM_FORE200E_PCA */
730 #ifdef CONFIG_ATM_FORE200E_SBA
733 fore200e_sba_read(volatile u32* addr)
735 return sbus_readl(addr);
740 fore200e_sba_write(u32 val, volatile u32* addr)
742 sbus_writel(val, addr);
747 fore200e_sba_dma_map(struct fore200e* fore200e, void* virt_addr, int size, int direction)
749 u32 dma_addr = sbus_map_single((struct sbus_dev*)fore200e->bus_dev, virt_addr, size, direction);
751 DPRINTK(3, "SBUS DVMA mapping: virt_addr = 0x%p, size = %d, direction = %d --> dma_addr = 0x%08x\n",
752 virt_addr, size, direction, dma_addr);
759 fore200e_sba_dma_unmap(struct fore200e* fore200e, u32 dma_addr, int size, int direction)
761 DPRINTK(3, "SBUS DVMA unmapping: dma_addr = 0x%08x, size = %d, direction = %d,\n",
762 dma_addr, size, direction);
764 sbus_unmap_single((struct sbus_dev*)fore200e->bus_dev, dma_addr, size, direction);
769 fore200e_sba_dma_sync(struct fore200e* fore200e, u32 dma_addr, int size, int direction)
771 DPRINTK(3, "SBUS DVMA sync: dma_addr = 0x%08x, size = %d, direction = %d\n", dma_addr, size, direction);
773 sbus_dma_sync_single((struct sbus_dev*)fore200e->bus_dev, dma_addr, size, direction);
777 /* allocate a DVMA consistent chunk of memory intended to act as a communication mechanism
778 (to hold descriptors, status, queues, etc.) shared by the driver and the adapter */
781 fore200e_sba_dma_chunk_alloc(struct fore200e* fore200e, struct chunk* chunk,
782 int size, int nbr, int alignment)
784 chunk->alloc_size = chunk->align_size = size * nbr;
786 /* returned chunks are page-aligned */
787 chunk->alloc_addr = sbus_alloc_consistent((struct sbus_dev*)fore200e->bus_dev,
791 if ((chunk->alloc_addr == NULL) || (chunk->dma_addr == 0))
794 chunk->align_addr = chunk->alloc_addr;
800 /* free a DVMA consistent chunk of memory */
803 fore200e_sba_dma_chunk_free(struct fore200e* fore200e, struct chunk* chunk)
805 sbus_free_consistent((struct sbus_dev*)fore200e->bus_dev,
813 fore200e_sba_irq_enable(struct fore200e* fore200e)
815 u32 hcr = fore200e->bus->read(fore200e->regs.sba.hcr) & SBA200E_HCR_STICKY;
816 fore200e->bus->write(hcr | SBA200E_HCR_INTR_ENA, fore200e->regs.sba.hcr);
821 fore200e_sba_irq_check(struct fore200e* fore200e)
823 return fore200e->bus->read(fore200e->regs.sba.hcr) & SBA200E_HCR_INTR_REQ;
828 fore200e_sba_irq_ack(struct fore200e* fore200e)
830 u32 hcr = fore200e->bus->read(fore200e->regs.sba.hcr) & SBA200E_HCR_STICKY;
831 fore200e->bus->write(hcr | SBA200E_HCR_INTR_CLR, fore200e->regs.sba.hcr);
836 fore200e_sba_reset(struct fore200e* fore200e)
838 fore200e->bus->write(SBA200E_HCR_RESET, fore200e->regs.sba.hcr);
840 fore200e->bus->write(0, fore200e->regs.sba.hcr);
845 fore200e_sba_map(struct fore200e* fore200e)
847 struct sbus_dev* sbus_dev = (struct sbus_dev*)fore200e->bus_dev;
850 /* gain access to the SBA specific registers */
851 fore200e->regs.sba.hcr = (u32*)sbus_ioremap(&sbus_dev->resource[0], 0, SBA200E_HCR_LENGTH, "SBA HCR");
852 fore200e->regs.sba.bsr = (u32*)sbus_ioremap(&sbus_dev->resource[1], 0, SBA200E_BSR_LENGTH, "SBA BSR");
853 fore200e->regs.sba.isr = (u32*)sbus_ioremap(&sbus_dev->resource[2], 0, SBA200E_ISR_LENGTH, "SBA ISR");
854 fore200e->virt_base = (u32*)sbus_ioremap(&sbus_dev->resource[3], 0, SBA200E_RAM_LENGTH, "SBA RAM");
856 if (fore200e->virt_base == NULL) {
857 printk(FORE200E "unable to map RAM of device %s\n", fore200e->name);
861 DPRINTK(1, "device %s mapped to 0x%p\n", fore200e->name, fore200e->virt_base);
863 fore200e->bus->write(0x02, fore200e->regs.sba.isr); /* XXX hardwired interrupt level */
865 /* get the supported DVMA burst sizes */
866 bursts = prom_getintdefault(sbus_dev->bus->prom_node, "burst-sizes", 0x00);
868 if (sbus_can_dma_64bit(sbus_dev))
869 sbus_set_sbus64(sbus_dev, bursts);
871 fore200e->state = FORE200E_STATE_MAP;
877 fore200e_sba_unmap(struct fore200e* fore200e)
879 sbus_iounmap((ulong)fore200e->regs.sba.hcr, SBA200E_HCR_LENGTH);
880 sbus_iounmap((ulong)fore200e->regs.sba.bsr, SBA200E_BSR_LENGTH);
881 sbus_iounmap((ulong)fore200e->regs.sba.isr, SBA200E_ISR_LENGTH);
882 sbus_iounmap((ulong)fore200e->virt_base, SBA200E_RAM_LENGTH);
887 fore200e_sba_configure(struct fore200e* fore200e)
889 fore200e->state = FORE200E_STATE_CONFIGURE;
894 static struct fore200e* __init
895 fore200e_sba_detect(const struct fore200e_bus* bus, int index)
897 struct fore200e* fore200e;
898 struct sbus_bus* sbus_bus;
899 struct sbus_dev* sbus_dev = NULL;
901 unsigned int count = 0;
903 for_each_sbus (sbus_bus) {
904 for_each_sbusdev (sbus_dev, sbus_bus) {
905 if (strcmp(sbus_dev->prom_name, SBA200E_PROM_NAME) == 0) {
915 if (sbus_dev->num_registers != 4) {
916 printk(FORE200E "this %s device has %d instead of 4 registers\n",
917 bus->model_name, sbus_dev->num_registers);
921 fore200e = fore200e_kmalloc(sizeof(struct fore200e), GFP_KERNEL);
922 if (fore200e == NULL)
926 fore200e->bus_dev = sbus_dev;
927 fore200e->irq = sbus_dev->irqs[ 0 ];
929 fore200e->phys_base = (unsigned long)sbus_dev;
931 sprintf(fore200e->name, "%s-%d", bus->model_name, index - 1);
938 fore200e_sba_prom_read(struct fore200e* fore200e, struct prom_data* prom)
940 struct sbus_dev* sbus_dev = (struct sbus_dev*) fore200e->bus_dev;
943 len = prom_getproperty(sbus_dev->prom_node, "macaddrlo2", &prom->mac_addr[ 4 ], 4);
947 len = prom_getproperty(sbus_dev->prom_node, "macaddrhi4", &prom->mac_addr[ 2 ], 4);
951 prom_getproperty(sbus_dev->prom_node, "serialnumber",
952 (char*)&prom->serial_number, sizeof(prom->serial_number));
954 prom_getproperty(sbus_dev->prom_node, "promversion",
955 (char*)&prom->hw_revision, sizeof(prom->hw_revision));
962 fore200e_sba_proc_read(struct fore200e* fore200e, char *page)
964 struct sbus_dev* sbus_dev = (struct sbus_dev*)fore200e->bus_dev;
966 return sprintf(page, " SBUS slot/device:\t\t%d/'%s'\n", sbus_dev->slot, sbus_dev->prom_name);
968 #endif /* CONFIG_ATM_FORE200E_SBA */
972 fore200e_tx_irq(struct fore200e* fore200e)
974 struct host_txq* txq = &fore200e->host_txq;
975 struct host_txq_entry* entry;
977 struct fore200e_vc_map* vc_map;
979 if (fore200e->host_txq.txing == 0)
984 entry = &txq->host_entry[ txq->tail ];
986 if ((*entry->status & STATUS_COMPLETE) == 0) {
990 DPRINTK(3, "TX COMPLETED: entry = %p [tail = %d], vc_map = %p, skb = %p\n",
991 entry, txq->tail, entry->vc_map, entry->skb);
993 /* free copy of misaligned data */
997 /* remove DMA mapping */
998 fore200e->bus->dma_unmap(fore200e, entry->tpd->tsd[ 0 ].buffer, entry->tpd->tsd[ 0 ].length,
999 FORE200E_DMA_TODEVICE);
1001 vc_map = entry->vc_map;
1003 /* vcc closed since the time the entry was submitted for tx? */
1004 if ((vc_map->vcc == NULL) ||
1005 (test_bit(ATM_VF_READY, &vc_map->vcc->flags) == 0)) {
1007 DPRINTK(1, "no ready vcc found for PDU sent on device %d\n",
1008 fore200e->atm_dev->number);
1010 dev_kfree_skb_any(entry->skb);
1013 ASSERT(vc_map->vcc);
1015 /* vcc closed then immediately re-opened? */
1016 if (vc_map->incarn != entry->incarn) {
1018 /* when a vcc is closed, some PDUs may be still pending in the tx queue.
1019 if the same vcc is immediately re-opened, those pending PDUs must
1020 not be popped after the completion of their emission, as they refer
1021 to the prior incarnation of that vcc. otherwise, vcc->sk->wmem_alloc
1022 would be decremented by the size of the (unrelated) skb, possibly
1023 leading to a negative sk->wmem_alloc count, ultimately freezing the vcc.
1024 we thus bind the tx entry to the current incarnation of the vcc
1025 when the entry is submitted for tx. When the tx later completes,
1026 if the incarnation number of the tx entry does not match the one
1027 of the vcc, then this implies that the vcc has been closed then re-opened.
1028 we thus just drop the skb here. */
1030 DPRINTK(1, "vcc closed-then-re-opened; dropping PDU sent on device %d\n",
1031 fore200e->atm_dev->number);
1033 dev_kfree_skb_any(entry->skb);
1039 /* notify tx completion */
1041 vcc->pop(vcc, entry->skb);
1044 dev_kfree_skb_any(entry->skb);
1047 /* race fixed by the above incarnation mechanism, but... */
1048 if (atomic_read(&vcc->sk->wmem_alloc) < 0) {
1049 atomic_set(&vcc->sk->wmem_alloc, 0);
1052 /* check error condition */
1053 if (*entry->status & STATUS_ERROR)
1054 atomic_inc(&vcc->stats->tx_err);
1056 atomic_inc(&vcc->stats->tx);
1060 *entry->status = STATUS_FREE;
1062 fore200e->host_txq.txing--;
1064 FORE200E_NEXT_ENTRY(txq->tail, QUEUE_SIZE_TX);
1069 #ifdef FORE200E_BSQ_DEBUG
1070 int bsq_audit(int where, struct host_bsq* bsq, int scheme, int magn)
1072 struct buffer* buffer;
1075 buffer = bsq->freebuf;
1078 if (buffer->supplied) {
1079 printk(FORE200E "bsq_audit(%d): queue %d.%d, buffer %ld supplied but in free list!\n",
1080 where, scheme, magn, buffer->index);
1083 if (buffer->magn != magn) {
1084 printk(FORE200E "bsq_audit(%d): queue %d.%d, buffer %ld, unexpected magn = %d\n",
1085 where, scheme, magn, buffer->index, buffer->magn);
1088 if (buffer->scheme != scheme) {
1089 printk(FORE200E "bsq_audit(%d): queue %d.%d, buffer %ld, unexpected scheme = %d\n",
1090 where, scheme, magn, buffer->index, buffer->scheme);
1093 if ((buffer->index < 0) || (buffer->index >= fore200e_rx_buf_nbr[ scheme ][ magn ])) {
1094 printk(FORE200E "bsq_audit(%d): queue %d.%d, out of range buffer index = %ld !\n",
1095 where, scheme, magn, buffer->index);
1099 buffer = buffer->next;
1102 if (count != bsq->freebuf_count) {
1103 printk(FORE200E "bsq_audit(%d): queue %d.%d, %d bufs in free list, but freebuf_count = %d\n",
1104 where, scheme, magn, count, bsq->freebuf_count);
1112 fore200e_supply(struct fore200e* fore200e)
1114 int scheme, magn, i;
1116 struct host_bsq* bsq;
1117 struct host_bsq_entry* entry;
1118 struct buffer* buffer;
1120 for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
1121 for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
1123 bsq = &fore200e->host_bsq[ scheme ][ magn ];
1125 #ifdef FORE200E_BSQ_DEBUG
1126 bsq_audit(1, bsq, scheme, magn);
1128 while (bsq->freebuf_count >= RBD_BLK_SIZE) {
1130 DPRINTK(2, "supplying %d rx buffers to queue %d / %d, freebuf_count = %d\n",
1131 RBD_BLK_SIZE, scheme, magn, bsq->freebuf_count);
1133 entry = &bsq->host_entry[ bsq->head ];
1135 for (i = 0; i < RBD_BLK_SIZE; i++) {
1137 /* take the first buffer in the free buffer list */
1138 buffer = bsq->freebuf;
1140 printk(FORE200E "no more free bufs in queue %d.%d, but freebuf_count = %d\n",
1141 scheme, magn, bsq->freebuf_count);
1144 bsq->freebuf = buffer->next;
1146 #ifdef FORE200E_BSQ_DEBUG
1147 if (buffer->supplied)
1148 printk(FORE200E "queue %d.%d, buffer %lu already supplied\n",
1149 scheme, magn, buffer->index);
1150 buffer->supplied = 1;
1152 entry->rbd_block->rbd[ i ].buffer_haddr = buffer->data.dma_addr;
1153 entry->rbd_block->rbd[ i ].handle = FORE200E_BUF2HDL(buffer);
1156 FORE200E_NEXT_ENTRY(bsq->head, QUEUE_SIZE_BS);
1158 /* decrease accordingly the number of free rx buffers */
1159 bsq->freebuf_count -= RBD_BLK_SIZE;
1161 *entry->status = STATUS_PENDING;
1162 fore200e->bus->write(entry->rbd_block_dma, &entry->cp_entry->rbd_block_haddr);
1170 fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rpd)
1172 struct sk_buff* skb;
1173 struct buffer* buffer;
1174 struct fore200e_vcc* fore200e_vcc;
1176 #ifdef FORE200E_52BYTE_AAL0_SDU
1177 u32 cell_header = 0;
1182 fore200e_vcc = FORE200E_VCC(vcc);
1183 ASSERT(fore200e_vcc);
1185 #ifdef FORE200E_52BYTE_AAL0_SDU
1186 if ((vcc->qos.aal == ATM_AAL0) && (vcc->qos.rxtp.max_sdu == ATM_AAL0_SDU)) {
1188 cell_header = (rpd->atm_header.gfc << ATM_HDR_GFC_SHIFT) |
1189 (rpd->atm_header.vpi << ATM_HDR_VPI_SHIFT) |
1190 (rpd->atm_header.vci << ATM_HDR_VCI_SHIFT) |
1191 (rpd->atm_header.plt << ATM_HDR_PTI_SHIFT) |
1192 rpd->atm_header.clp;
1197 /* compute total PDU length */
1198 for (i = 0; i < rpd->nseg; i++)
1199 pdu_len += rpd->rsd[ i ].length;
1201 skb = alloc_skb(pdu_len, GFP_ATOMIC);
1203 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
1205 atomic_inc(&vcc->stats->rx_drop);
1211 #ifdef FORE200E_52BYTE_AAL0_SDU
1213 *((u32*)skb_put(skb, 4)) = cell_header;
1217 /* reassemble segments */
1218 for (i = 0; i < rpd->nseg; i++) {
1220 /* rebuild rx buffer address from rsd handle */
1221 buffer = FORE200E_HDL2BUF(rpd->rsd[ i ].handle);
1223 /* ensure DMA synchronisation */
1224 fore200e->bus->dma_sync(fore200e, buffer->data.dma_addr, rpd->rsd[ i ].length, FORE200E_DMA_FROMDEVICE);
1226 memcpy(skb_put(skb, rpd->rsd[ i ].length), buffer->data.align_addr, rpd->rsd[ i ].length);
1229 DPRINTK(3, "rx skb: len = %d, truesize = %d\n", skb->len, skb->truesize);
1231 if (pdu_len < fore200e_vcc->rx_min_pdu)
1232 fore200e_vcc->rx_min_pdu = pdu_len;
1233 if (pdu_len > fore200e_vcc->rx_max_pdu)
1234 fore200e_vcc->rx_max_pdu = pdu_len;
1235 fore200e_vcc->rx_pdu++;
1238 if (atm_charge(vcc, skb->truesize) == 0) {
1240 DPRINTK(2, "receive buffers saturated for %d.%d.%d - PDU dropped\n",
1241 vcc->itf, vcc->vpi, vcc->vci);
1243 dev_kfree_skb_any(skb);
1245 atomic_inc(&vcc->stats->rx_drop);
1249 ASSERT(atomic_read(&vcc->sk->wmem_alloc) >= 0);
1251 vcc->push(vcc, skb);
1252 atomic_inc(&vcc->stats->rx);
1254 ASSERT(atomic_read(&vcc->sk->wmem_alloc) >= 0);
1261 fore200e_collect_rpd(struct fore200e* fore200e, struct rpd* rpd)
1263 struct host_bsq* bsq;
1264 struct buffer* buffer;
1267 for (i = 0; i < rpd->nseg; i++) {
1269 /* rebuild rx buffer address from rsd handle */
1270 buffer = FORE200E_HDL2BUF(rpd->rsd[ i ].handle);
1272 bsq = &fore200e->host_bsq[ buffer->scheme ][ buffer->magn ];
1274 #ifdef FORE200E_BSQ_DEBUG
1275 bsq_audit(2, bsq, buffer->scheme, buffer->magn);
1277 if (buffer->supplied == 0)
1278 printk(FORE200E "queue %d.%d, buffer %ld was not supplied\n",
1279 buffer->scheme, buffer->magn, buffer->index);
1280 buffer->supplied = 0;
1283 /* re-insert the buffer into the free buffer list */
1284 buffer->next = bsq->freebuf;
1285 bsq->freebuf = buffer;
1287 /* then increment the number of free rx buffers */
1288 bsq->freebuf_count++;
1294 fore200e_rx_irq(struct fore200e* fore200e)
1296 struct host_rxq* rxq = &fore200e->host_rxq;
1297 struct host_rxq_entry* entry;
1298 struct atm_vcc* vcc;
1299 struct fore200e_vc_map* vc_map;
1303 entry = &rxq->host_entry[ rxq->head ];
1305 /* no more received PDUs */
1306 if ((*entry->status & STATUS_COMPLETE) == 0)
1309 vc_map = FORE200E_VC_MAP(fore200e, entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
1311 if ((vc_map->vcc == NULL) ||
1312 (test_bit(ATM_VF_READY, &vc_map->vcc->flags) == 0)) {
1314 DPRINTK(1, "no ready VC found for PDU received on %d.%d.%d\n",
1315 fore200e->atm_dev->number,
1316 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
1322 if ((*entry->status & STATUS_ERROR) == 0) {
1324 fore200e_push_rpd(fore200e, vcc, entry->rpd);
1327 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
1328 fore200e->atm_dev->number,
1329 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
1330 atomic_inc(&vcc->stats->rx_err);
1334 FORE200E_NEXT_ENTRY(rxq->head, QUEUE_SIZE_RX);
1336 fore200e_collect_rpd(fore200e, entry->rpd);
1338 /* rewrite the rpd address to ack the received PDU */
1339 fore200e->bus->write(entry->rpd_dma, &entry->cp_entry->rpd_haddr);
1340 *entry->status = STATUS_FREE;
1342 fore200e_supply(fore200e);
1347 #ifndef FORE200E_USE_TASKLET
1349 fore200e_irq(struct fore200e* fore200e)
1351 unsigned long flags;
1353 spin_lock_irqsave(&fore200e->q_lock, flags);
1354 fore200e_rx_irq(fore200e);
1355 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1357 spin_lock_irqsave(&fore200e->q_lock, flags);
1358 fore200e_tx_irq(fore200e);
1359 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1365 fore200e_interrupt(int irq, void* dev, struct pt_regs* regs)
1367 struct fore200e* fore200e = FORE200E_DEV((struct atm_dev*)dev);
1369 if (fore200e->bus->irq_check(fore200e) == 0) {
1371 DPRINTK(3, "interrupt NOT triggered by device %d\n", fore200e->atm_dev->number);
1374 DPRINTK(3, "interrupt triggered by device %d\n", fore200e->atm_dev->number);
1376 #ifdef FORE200E_USE_TASKLET
1377 tasklet_schedule(&fore200e->tx_tasklet);
1378 tasklet_schedule(&fore200e->rx_tasklet);
1380 fore200e_irq(fore200e);
1383 fore200e->bus->irq_ack(fore200e);
1387 #ifdef FORE200E_USE_TASKLET
1389 fore200e_tx_tasklet(unsigned long data)
1391 struct fore200e* fore200e = (struct fore200e*) data;
1392 unsigned long flags;
1394 DPRINTK(3, "tx tasklet scheduled for device %d\n", fore200e->atm_dev->number);
1396 spin_lock_irqsave(&fore200e->q_lock, flags);
1397 fore200e_tx_irq(fore200e);
1398 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1403 fore200e_rx_tasklet(unsigned long data)
1405 struct fore200e* fore200e = (struct fore200e*) data;
1406 unsigned long flags;
1408 DPRINTK(3, "rx tasklet scheduled for device %d\n", fore200e->atm_dev->number);
1410 spin_lock_irqsave(&fore200e->q_lock, flags);
1411 fore200e_rx_irq((struct fore200e*) data);
1412 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1418 fore200e_select_scheme(struct atm_vcc* vcc)
1420 /* fairly balance the VCs over (identical) buffer schemes */
1421 int scheme = vcc->vci % 2 ? BUFFER_SCHEME_ONE : BUFFER_SCHEME_TWO;
1423 DPRINTK(1, "VC %d.%d.%d uses buffer scheme %d\n",
1424 vcc->itf, vcc->vpi, vcc->vci, scheme);
1431 fore200e_activate_vcin(struct fore200e* fore200e, int activate, struct atm_vcc* vcc, int mtu)
1433 struct host_cmdq* cmdq = &fore200e->host_cmdq;
1434 struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
1435 struct activate_opcode activ_opcode;
1436 struct deactivate_opcode deactiv_opcode;
1439 enum fore200e_aal aal = fore200e_atm2fore_aal(vcc->qos.aal);
1441 FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
1444 FORE200E_VCC(vcc)->scheme = fore200e_select_scheme(vcc);
1446 activ_opcode.opcode = OPCODE_ACTIVATE_VCIN;
1447 activ_opcode.aal = aal;
1448 activ_opcode.scheme = FORE200E_VCC(vcc)->scheme;
1449 activ_opcode.pad = 0;
1452 deactiv_opcode.opcode = OPCODE_DEACTIVATE_VCIN;
1453 deactiv_opcode.pad = 0;
1456 vpvc.vci = vcc->vci;
1457 vpvc.vpi = vcc->vpi;
1459 *entry->status = STATUS_PENDING;
1463 #ifdef FORE200E_52BYTE_AAL0_SDU
1466 /* the MTU is not used by the cp, except in the case of AAL0 */
1467 fore200e->bus->write(mtu, &entry->cp_entry->cmd.activate_block.mtu);
1468 fore200e->bus->write(*(u32*)&vpvc, (u32*)&entry->cp_entry->cmd.activate_block.vpvc);
1469 fore200e->bus->write(*(u32*)&activ_opcode, (u32*)&entry->cp_entry->cmd.activate_block.opcode);
1472 fore200e->bus->write(*(u32*)&vpvc, (u32*)&entry->cp_entry->cmd.deactivate_block.vpvc);
1473 fore200e->bus->write(*(u32*)&deactiv_opcode, (u32*)&entry->cp_entry->cmd.deactivate_block.opcode);
1476 ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
1478 *entry->status = STATUS_FREE;
1481 printk(FORE200E "unable to %s VC %d.%d.%d\n",
1482 activate ? "open" : "close", vcc->itf, vcc->vpi, vcc->vci);
1486 DPRINTK(1, "VC %d.%d.%d %sed\n", vcc->itf, vcc->vpi, vcc->vci,
1487 activate ? "open" : "clos");
1494 fore200e_walk_vccs(struct atm_vcc *vcc, short *vpi, int *vci)
1496 struct atm_vcc* walk;
1499 /* find a free VPI */
1501 read_lock(&vcc_sklist_lock);
1503 if (*vpi == ATM_VPI_ANY) {
1505 for (*vpi = 0, s = vcc_sklist; s; s = s->next) {
1506 walk = s->protinfo.af_atm;
1507 if (walk->dev != vcc->dev)
1510 if ((walk->vci == *vci) && (walk->vpi == *vpi)) {
1517 /* find a free VCI */
1518 if (*vci == ATM_VCI_ANY) {
1520 for (*vci = ATM_NOT_RSV_VCI, s = vcc_sklist; s; s = s->next) {
1521 walk = s->protinfo.af_atm;
1522 if (walk->dev != vcc->dev)
1525 if ((walk->vpi = *vpi) && (walk->vci == *vci)) {
1526 *vci = walk->vci + 1;
1532 read_unlock(&vcc_sklist_lock);
1538 #define FORE200E_MAX_BACK2BACK_CELLS 255 /* XXX depends on CDVT */
1541 fore200e_rate_ctrl(struct atm_qos* qos, struct tpd_rate* rate)
1543 if (qos->txtp.max_pcr < ATM_OC3_PCR) {
1545 /* compute the data cells to idle cells ratio from the tx PCR */
1546 rate->data_cells = qos->txtp.max_pcr * FORE200E_MAX_BACK2BACK_CELLS / ATM_OC3_PCR;
1547 rate->idle_cells = FORE200E_MAX_BACK2BACK_CELLS - rate->data_cells;
1550 /* disable rate control */
1551 rate->data_cells = rate->idle_cells = 0;
1557 fore200e_open(struct atm_vcc *vcc, short vpi, int vci)
1559 struct fore200e* fore200e = FORE200E_DEV(vcc->dev);
1560 struct fore200e_vcc* fore200e_vcc;
1561 struct fore200e_vc_map* vc_map;
1562 unsigned long flags;
1564 fore200e_walk_vccs(vcc, &vpi, &vci);
1566 ASSERT((vpi >= 0) && (vpi < 1<<FORE200E_VPI_BITS));
1567 ASSERT((vci >= 0) && (vci < 1<<FORE200E_VCI_BITS));
1569 spin_lock_irqsave(&fore200e->q_lock, flags);
1571 vc_map = FORE200E_VC_MAP(fore200e, vpi, vci);
1574 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1576 printk(FORE200E "VC %d.%d.%d already in use\n",
1577 fore200e->atm_dev->number, vpi, vci);
1584 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1586 fore200e_vcc = fore200e_kmalloc(sizeof(struct fore200e_vcc), GFP_ATOMIC);
1587 if (fore200e_vcc == NULL) {
1592 DPRINTK(2, "opening %d.%d.%d:%d QoS = (tx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d; "
1593 "rx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d)\n",
1594 vcc->itf, vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal),
1595 fore200e_traffic_class[ vcc->qos.txtp.traffic_class ],
1596 vcc->qos.txtp.min_pcr, vcc->qos.txtp.max_pcr, vcc->qos.txtp.max_cdv, vcc->qos.txtp.max_sdu,
1597 fore200e_traffic_class[ vcc->qos.rxtp.traffic_class ],
1598 vcc->qos.rxtp.min_pcr, vcc->qos.rxtp.max_pcr, vcc->qos.rxtp.max_cdv, vcc->qos.rxtp.max_sdu);
1600 /* pseudo-CBR bandwidth requested? */
1601 if ((vcc->qos.txtp.traffic_class == ATM_CBR) && (vcc->qos.txtp.max_pcr > 0)) {
1603 down(&fore200e->rate_sf);
1604 if (fore200e->available_cell_rate < vcc->qos.txtp.max_pcr) {
1605 up(&fore200e->rate_sf);
1607 fore200e_kfree(fore200e_vcc);
1612 /* reserve bandwidth */
1613 fore200e->available_cell_rate -= vcc->qos.txtp.max_pcr;
1614 up(&fore200e->rate_sf);
1617 vcc->itf = vcc->dev->number;
1621 set_bit(ATM_VF_PARTIAL,&vcc->flags);
1622 set_bit(ATM_VF_ADDR, &vcc->flags);
1624 vcc->dev_data = fore200e_vcc;
1626 if (fore200e_activate_vcin(fore200e, 1, vcc, vcc->qos.rxtp.max_sdu) < 0) {
1630 clear_bit(ATM_VF_ADDR, &vcc->flags);
1631 clear_bit(ATM_VF_PARTIAL,&vcc->flags);
1633 vcc->dev_data = NULL;
1635 fore200e->available_cell_rate += vcc->qos.txtp.max_pcr;
1637 fore200e_kfree(fore200e_vcc);
1641 /* compute rate control parameters */
1642 if ((vcc->qos.txtp.traffic_class == ATM_CBR) && (vcc->qos.txtp.max_pcr > 0)) {
1644 fore200e_rate_ctrl(&vcc->qos, &fore200e_vcc->rate);
1645 set_bit(ATM_VF_HASQOS, &vcc->flags);
1647 DPRINTK(3, "tx on %d.%d.%d:%d, tx PCR = %d, rx PCR = %d, data_cells = %u, idle_cells = %u\n",
1648 vcc->itf, vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal),
1649 vcc->qos.txtp.max_pcr, vcc->qos.rxtp.max_pcr,
1650 fore200e_vcc->rate.data_cells, fore200e_vcc->rate.idle_cells);
1653 fore200e_vcc->tx_min_pdu = fore200e_vcc->rx_min_pdu = MAX_PDU_SIZE + 1;
1654 fore200e_vcc->tx_max_pdu = fore200e_vcc->rx_max_pdu = 0;
1655 fore200e_vcc->tx_pdu = fore200e_vcc->rx_pdu = 0;
1657 /* new incarnation of the vcc */
1658 vc_map->incarn = ++fore200e->incarn_count;
1660 /* VC unusable before this flag is set */
1661 set_bit(ATM_VF_READY, &vcc->flags);
1668 fore200e_close(struct atm_vcc* vcc)
1670 struct fore200e* fore200e = FORE200E_DEV(vcc->dev);
1671 struct fore200e_vcc* fore200e_vcc;
1672 struct fore200e_vc_map* vc_map;
1673 unsigned long flags;
1676 ASSERT((vcc->vpi >= 0) && (vcc->vpi < 1<<FORE200E_VPI_BITS));
1677 ASSERT((vcc->vci >= 0) && (vcc->vci < 1<<FORE200E_VCI_BITS));
1679 DPRINTK(2, "closing %d.%d.%d:%d\n", vcc->itf, vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal));
1681 clear_bit(ATM_VF_READY, &vcc->flags);
1683 fore200e_activate_vcin(fore200e, 0, vcc, 0);
1685 spin_lock_irqsave(&fore200e->q_lock, flags);
1687 vc_map = FORE200E_VC_MAP(fore200e, vcc->vpi, vcc->vci);
1689 /* the vc is no longer considered as "in use" by fore200e_open() */
1692 vcc->itf = vcc->vci = vcc->vpi = 0;
1694 fore200e_vcc = FORE200E_VCC(vcc);
1695 vcc->dev_data = NULL;
1697 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1699 /* release reserved bandwidth, if any */
1700 if ((vcc->qos.txtp.traffic_class == ATM_CBR) && (vcc->qos.txtp.max_pcr > 0)) {
1702 down(&fore200e->rate_sf);
1703 fore200e->available_cell_rate += vcc->qos.txtp.max_pcr;
1704 up(&fore200e->rate_sf);
1706 clear_bit(ATM_VF_HASQOS, &vcc->flags);
1709 clear_bit(ATM_VF_ADDR, &vcc->flags);
1710 clear_bit(ATM_VF_PARTIAL,&vcc->flags);
1712 ASSERT(fore200e_vcc);
1713 fore200e_kfree(fore200e_vcc);
1718 fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
1720 struct fore200e* fore200e = FORE200E_DEV(vcc->dev);
1721 struct fore200e_vcc* fore200e_vcc = FORE200E_VCC(vcc);
1722 struct fore200e_vc_map* vc_map;
1723 struct host_txq* txq = &fore200e->host_txq;
1724 struct host_txq_entry* entry;
1726 struct tpd_haddr tpd_haddr;
1727 int retry = CONFIG_ATM_FORE200E_TX_RETRY;
1729 int tx_len = skb->len;
1730 u32* cell_header = NULL;
1731 unsigned char* skb_data;
1733 unsigned char* data;
1734 unsigned long flags;
1737 ASSERT(atomic_read(&vcc->sk->wmem_alloc) >= 0);
1739 ASSERT(fore200e_vcc);
1741 if (!test_bit(ATM_VF_READY, &vcc->flags)) {
1742 DPRINTK(1, "VC %d.%d.%d not ready for tx\n", vcc->itf, vcc->vpi, vcc->vpi);
1743 dev_kfree_skb_any(skb);
1747 #ifdef FORE200E_52BYTE_AAL0_SDU
1748 if ((vcc->qos.aal == ATM_AAL0) && (vcc->qos.txtp.max_sdu == ATM_AAL0_SDU)) {
1749 cell_header = (u32*) skb->data;
1750 skb_data = skb->data + 4; /* skip 4-byte cell header */
1751 skb_len = tx_len = skb->len - 4;
1753 DPRINTK(3, "user-supplied cell header = 0x%08x\n", *cell_header);
1758 skb_data = skb->data;
1762 if (((unsigned long)skb_data) & 0x3) {
1764 DPRINTK(2, "misaligned tx PDU on device %s\n", fore200e->name);
1769 if ((vcc->qos.aal == ATM_AAL0) && (skb_len % ATM_CELL_PAYLOAD)) {
1771 /* this simply NUKES the PCA board */
1772 DPRINTK(2, "incomplete tx AAL0 PDU on device %s\n", fore200e->name);
1774 tx_len = ((skb_len / ATM_CELL_PAYLOAD) + 1) * ATM_CELL_PAYLOAD;
1778 data = kmalloc(tx_len, GFP_ATOMIC | GFP_DMA);
1784 dev_kfree_skb_any(skb);
1789 memcpy(data, skb_data, skb_len);
1790 if (skb_len < tx_len)
1791 memset(data + skb_len, 0x00, tx_len - skb_len);
1797 vc_map = FORE200E_VC_MAP(fore200e, vcc->vpi, vcc->vci);
1798 ASSERT(vc_map->vcc == vcc);
1802 spin_lock_irqsave(&fore200e->q_lock, flags);
1804 entry = &txq->host_entry[ txq->head ];
1806 if ((*entry->status != STATUS_FREE) || (txq->txing >= QUEUE_SIZE_TX - 2)) {
1808 /* try to free completed tx queue entries */
1809 fore200e_tx_irq(fore200e);
1811 if (*entry->status != STATUS_FREE) {
1813 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1815 /* retry once again? */
1821 atomic_inc(&vcc->stats->tx_err);
1824 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
1825 fore200e->name, fore200e->cp_queues->heartbeat);
1830 dev_kfree_skb_any(skb);
1840 entry->incarn = vc_map->incarn;
1841 entry->vc_map = vc_map;
1843 entry->data = tx_copy ? data : NULL;
1846 tpd->tsd[ 0 ].buffer = fore200e->bus->dma_map(fore200e, data, tx_len, FORE200E_DMA_TODEVICE);
1847 tpd->tsd[ 0 ].length = tx_len;
1849 FORE200E_NEXT_ENTRY(txq->head, QUEUE_SIZE_TX);
1852 /* ensure DMA synchronisation */
1853 fore200e->bus->dma_sync(fore200e, tpd->tsd[ 0 ].buffer, tpd->tsd[ 0 ].length, FORE200E_DMA_TODEVICE);
1855 DPRINTK(3, "tx on %d.%d.%d:%d, len = %u (%u)\n",
1856 vcc->itf, vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal),
1857 tpd->tsd[0].length, skb_len);
1859 if (skb_len < fore200e_vcc->tx_min_pdu)
1860 fore200e_vcc->tx_min_pdu = skb_len;
1861 if (skb_len > fore200e_vcc->tx_max_pdu)
1862 fore200e_vcc->tx_max_pdu = skb_len;
1863 fore200e_vcc->tx_pdu++;
1865 /* set tx rate control information */
1866 tpd->rate.data_cells = fore200e_vcc->rate.data_cells;
1867 tpd->rate.idle_cells = fore200e_vcc->rate.idle_cells;
1870 tpd->atm_header.clp = (*cell_header & ATM_HDR_CLP);
1871 tpd->atm_header.plt = (*cell_header & ATM_HDR_PTI_MASK) >> ATM_HDR_PTI_SHIFT;
1872 tpd->atm_header.vci = (*cell_header & ATM_HDR_VCI_MASK) >> ATM_HDR_VCI_SHIFT;
1873 tpd->atm_header.vpi = (*cell_header & ATM_HDR_VPI_MASK) >> ATM_HDR_VPI_SHIFT;
1874 tpd->atm_header.gfc = (*cell_header & ATM_HDR_GFC_MASK) >> ATM_HDR_GFC_SHIFT;
1877 /* set the ATM header, common to all cells conveying the PDU */
1878 tpd->atm_header.clp = 0;
1879 tpd->atm_header.plt = 0;
1880 tpd->atm_header.vci = vcc->vci;
1881 tpd->atm_header.vpi = vcc->vpi;
1882 tpd->atm_header.gfc = 0;
1885 tpd->spec.length = tx_len;
1887 tpd->spec.aal = fore200e_atm2fore_aal(vcc->qos.aal);
1890 tpd_haddr.size = sizeof(struct tpd) / (1<<TPD_HADDR_SHIFT); /* size is expressed in 32 byte blocks */
1892 tpd_haddr.haddr = entry->tpd_dma >> TPD_HADDR_SHIFT; /* shift the address, as we are in a bitfield */
1894 *entry->status = STATUS_PENDING;
1895 fore200e->bus->write(*(u32*)&tpd_haddr, (u32*)&entry->cp_entry->tpd_haddr);
1897 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1904 fore200e_getstats(struct fore200e* fore200e)
1906 struct host_cmdq* cmdq = &fore200e->host_cmdq;
1907 struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
1908 struct stats_opcode opcode;
1912 if (fore200e->stats == NULL) {
1913 fore200e->stats = fore200e_kmalloc(sizeof(struct stats), GFP_KERNEL | GFP_DMA);
1914 if (fore200e->stats == NULL)
1918 stats_dma_addr = fore200e->bus->dma_map(fore200e, fore200e->stats,
1919 sizeof(struct stats), FORE200E_DMA_FROMDEVICE);
1921 FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
1923 opcode.opcode = OPCODE_GET_STATS;
1926 fore200e->bus->write(stats_dma_addr, &entry->cp_entry->cmd.stats_block.stats_haddr);
1928 *entry->status = STATUS_PENDING;
1930 fore200e->bus->write(*(u32*)&opcode, (u32*)&entry->cp_entry->cmd.stats_block.opcode);
1932 ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
1934 *entry->status = STATUS_FREE;
1936 fore200e->bus->dma_unmap(fore200e, stats_dma_addr, sizeof(struct stats), FORE200E_DMA_FROMDEVICE);
1939 printk(FORE200E "unable to get statistics from device %s\n", fore200e->name);
1948 fore200e_getsockopt(struct atm_vcc* vcc, int level, int optname, void* optval, int optlen)
1950 /* struct fore200e* fore200e = FORE200E_DEV(vcc->dev); */
1952 DPRINTK(2, "getsockopt %d.%d.%d, level = %d, optname = 0x%x, optval = 0x%p, optlen = %d\n",
1953 vcc->itf, vcc->vpi, vcc->vci, level, optname, optval, optlen);
1960 fore200e_setsockopt(struct atm_vcc* vcc, int level, int optname, void* optval, int optlen)
1962 /* struct fore200e* fore200e = FORE200E_DEV(vcc->dev); */
1964 DPRINTK(2, "setsockopt %d.%d.%d, level = %d, optname = 0x%x, optval = 0x%p, optlen = %d\n",
1965 vcc->itf, vcc->vpi, vcc->vci, level, optname, optval, optlen);
1971 #if 0 /* currently unused */
1973 fore200e_get_oc3(struct fore200e* fore200e, struct oc3_regs* regs)
1975 struct host_cmdq* cmdq = &fore200e->host_cmdq;
1976 struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
1977 struct oc3_opcode opcode;
1979 u32 oc3_regs_dma_addr;
1981 oc3_regs_dma_addr = fore200e->bus->dma_map(fore200e, regs, sizeof(struct oc3_regs), FORE200E_DMA_FROMDEVICE);
1983 FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
1985 opcode.opcode = OPCODE_GET_OC3;
1990 fore200e->bus->write(oc3_regs_dma_addr, &entry->cp_entry->cmd.oc3_block.regs_haddr);
1992 *entry->status = STATUS_PENDING;
1994 fore200e->bus->write(*(u32*)&opcode, (u32*)&entry->cp_entry->cmd.oc3_block.opcode);
1996 ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
1998 *entry->status = STATUS_FREE;
2000 fore200e->bus->dma_unmap(fore200e, oc3_regs_dma_addr, sizeof(struct oc3_regs), FORE200E_DMA_FROMDEVICE);
2003 printk(FORE200E "unable to get OC-3 regs of device %s\n", fore200e->name);
2013 fore200e_set_oc3(struct fore200e* fore200e, u32 reg, u32 value, u32 mask)
2015 struct host_cmdq* cmdq = &fore200e->host_cmdq;
2016 struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
2017 struct oc3_opcode opcode;
2020 DPRINTK(2, "set OC-3 reg = 0x%02x, value = 0x%02x, mask = 0x%02x\n", reg, value, mask);
2022 FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
2024 opcode.opcode = OPCODE_SET_OC3;
2026 opcode.value = value;
2029 fore200e->bus->write(0, &entry->cp_entry->cmd.oc3_block.regs_haddr);
2031 *entry->status = STATUS_PENDING;
2033 fore200e->bus->write(*(u32*)&opcode, (u32*)&entry->cp_entry->cmd.oc3_block.opcode);
2035 ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
2037 *entry->status = STATUS_FREE;
2040 printk(FORE200E "unable to set OC-3 reg 0x%02x of device %s\n", reg, fore200e->name);
2049 fore200e_setloop(struct fore200e* fore200e, int loop_mode)
2051 u32 mct_value, mct_mask;
2054 if (!capable(CAP_NET_ADMIN))
2057 switch (loop_mode) {
2061 mct_mask = SUNI_MCT_DLE | SUNI_MCT_LLE;
2064 case ATM_LM_LOC_PHY:
2065 mct_value = mct_mask = SUNI_MCT_DLE;
2068 case ATM_LM_RMT_PHY:
2069 mct_value = mct_mask = SUNI_MCT_LLE;
2076 error = fore200e_set_oc3(fore200e, SUNI_MCT, mct_value, mct_mask);
2078 fore200e->loop_mode = loop_mode;
2084 static inline unsigned int
2085 fore200e_swap(unsigned int in)
2087 #if defined(__LITTLE_ENDIAN)
2096 fore200e_fetch_stats(struct fore200e* fore200e, struct sonet_stats* arg)
2098 struct sonet_stats tmp;
2100 if (fore200e_getstats(fore200e) < 0)
2103 tmp.section_bip = fore200e_swap(fore200e->stats->oc3.section_bip8_errors);
2104 tmp.line_bip = fore200e_swap(fore200e->stats->oc3.line_bip24_errors);
2105 tmp.path_bip = fore200e_swap(fore200e->stats->oc3.path_bip8_errors);
2106 tmp.line_febe = fore200e_swap(fore200e->stats->oc3.line_febe_errors);
2107 tmp.path_febe = fore200e_swap(fore200e->stats->oc3.path_febe_errors);
2108 tmp.corr_hcs = fore200e_swap(fore200e->stats->oc3.corr_hcs_errors);
2109 tmp.uncorr_hcs = fore200e_swap(fore200e->stats->oc3.ucorr_hcs_errors);
2110 tmp.tx_cells = fore200e_swap(fore200e->stats->aal0.cells_transmitted) +
2111 fore200e_swap(fore200e->stats->aal34.cells_transmitted) +
2112 fore200e_swap(fore200e->stats->aal5.cells_transmitted);
2113 tmp.rx_cells = fore200e_swap(fore200e->stats->aal0.cells_received) +
2114 fore200e_swap(fore200e->stats->aal34.cells_received) +
2115 fore200e_swap(fore200e->stats->aal5.cells_received);
2118 return copy_to_user(arg, &tmp, sizeof(struct sonet_stats)) ? -EFAULT : 0;
2125 fore200e_ioctl(struct atm_dev* dev, unsigned int cmd, void* arg)
2127 struct fore200e* fore200e = FORE200E_DEV(dev);
2129 DPRINTK(2, "ioctl cmd = 0x%x (%u), arg = 0x%p (%lu)\n", cmd, cmd, arg, (unsigned long)arg);
2134 return fore200e_fetch_stats(fore200e, (struct sonet_stats*)arg);
2137 return put_user(0, (int*)arg) ? -EFAULT : 0;
2140 return fore200e_setloop(fore200e, (int)(unsigned long)arg);
2143 return put_user(fore200e->loop_mode, (int*)arg) ? -EFAULT : 0;
2146 return put_user(ATM_LM_LOC_PHY | ATM_LM_RMT_PHY, (int*)arg) ? -EFAULT : 0;
2149 return -ENOSYS; /* not implemented */
2154 fore200e_change_qos(struct atm_vcc* vcc,struct atm_qos* qos, int flags)
2156 struct fore200e_vcc* fore200e_vcc = FORE200E_VCC(vcc);
2157 struct fore200e* fore200e = FORE200E_DEV(vcc->dev);
2159 if (!test_bit(ATM_VF_READY, &vcc->flags)) {
2160 DPRINTK(1, "VC %d.%d.%d not ready for QoS change\n", vcc->itf, vcc->vpi, vcc->vpi);
2164 DPRINTK(2, "change_qos %d.%d.%d, "
2165 "(tx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d; "
2166 "rx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d), flags = 0x%x\n"
2167 "available_cell_rate = %u",
2168 vcc->itf, vcc->vpi, vcc->vci,
2169 fore200e_traffic_class[ qos->txtp.traffic_class ],
2170 qos->txtp.min_pcr, qos->txtp.max_pcr, qos->txtp.max_cdv, qos->txtp.max_sdu,
2171 fore200e_traffic_class[ qos->rxtp.traffic_class ],
2172 qos->rxtp.min_pcr, qos->rxtp.max_pcr, qos->rxtp.max_cdv, qos->rxtp.max_sdu,
2173 flags, fore200e->available_cell_rate);
2175 if ((qos->txtp.traffic_class == ATM_CBR) && (qos->txtp.max_pcr > 0)) {
2177 down(&fore200e->rate_sf);
2178 if (fore200e->available_cell_rate + vcc->qos.txtp.max_pcr < qos->txtp.max_pcr) {
2179 up(&fore200e->rate_sf);
2183 fore200e->available_cell_rate += vcc->qos.txtp.max_pcr;
2184 fore200e->available_cell_rate -= qos->txtp.max_pcr;
2186 up(&fore200e->rate_sf);
2188 memcpy(&vcc->qos, qos, sizeof(struct atm_qos));
2190 /* update rate control parameters */
2191 fore200e_rate_ctrl(qos, &fore200e_vcc->rate);
2193 set_bit(ATM_VF_HASQOS, &vcc->flags);
2203 fore200e_irq_request(struct fore200e* fore200e)
2205 if (request_irq(fore200e->irq, fore200e_interrupt, SA_SHIRQ, fore200e->name, fore200e->atm_dev) < 0) {
2207 printk(FORE200E "unable to reserve IRQ %s for device %s\n",
2208 fore200e_irq_itoa(fore200e->irq), fore200e->name);
2212 printk(FORE200E "IRQ %s reserved for device %s\n",
2213 fore200e_irq_itoa(fore200e->irq), fore200e->name);
2215 #ifdef FORE200E_USE_TASKLET
2216 tasklet_init(&fore200e->tx_tasklet, fore200e_tx_tasklet, (unsigned long)fore200e);
2217 tasklet_init(&fore200e->rx_tasklet, fore200e_rx_tasklet, (unsigned long)fore200e);
2220 fore200e->state = FORE200E_STATE_IRQ;
2226 fore200e_get_esi(struct fore200e* fore200e)
2228 struct prom_data* prom = fore200e_kmalloc(sizeof(struct prom_data), GFP_KERNEL | GFP_DMA);
2234 ok = fore200e->bus->prom_read(fore200e, prom);
2236 fore200e_kfree(prom);
2240 printk(FORE200E "device %s, rev. %c, S/N: %d, ESI: %02x:%02x:%02x:%02x:%02x:%02x\n",
2242 (prom->hw_revision & 0xFF) + '@', /* probably meaningless with SBA boards */
2243 prom->serial_number & 0xFFFF,
2244 prom->mac_addr[ 2 ], prom->mac_addr[ 3 ], prom->mac_addr[ 4 ],
2245 prom->mac_addr[ 5 ], prom->mac_addr[ 6 ], prom->mac_addr[ 7 ]);
2247 for (i = 0; i < ESI_LEN; i++) {
2248 fore200e->esi[ i ] = fore200e->atm_dev->esi[ i ] = prom->mac_addr[ i + 2 ];
2251 fore200e_kfree(prom);
2258 fore200e_alloc_rx_buf(struct fore200e* fore200e)
2260 int scheme, magn, nbr, size, i;
2262 struct host_bsq* bsq;
2263 struct buffer* buffer;
2265 for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
2266 for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
2268 bsq = &fore200e->host_bsq[ scheme ][ magn ];
2270 nbr = fore200e_rx_buf_nbr[ scheme ][ magn ];
2271 size = fore200e_rx_buf_size[ scheme ][ magn ];
2273 DPRINTK(2, "rx buffers %d / %d are being allocated\n", scheme, magn);
2275 /* allocate the array of receive buffers */
2276 buffer = bsq->buffer = fore200e_kmalloc(nbr * sizeof(struct buffer), GFP_KERNEL);
2281 bsq->freebuf = NULL;
2283 for (i = 0; i < nbr; i++) {
2285 buffer[ i ].scheme = scheme;
2286 buffer[ i ].magn = magn;
2287 #ifdef FORE200E_BSQ_DEBUG
2288 buffer[ i ].index = i;
2289 buffer[ i ].supplied = 0;
2292 /* allocate the receive buffer body */
2293 if (fore200e_chunk_alloc(fore200e,
2294 &buffer[ i ].data, size, fore200e->bus->buffer_alignment,
2295 FORE200E_DMA_FROMDEVICE) < 0) {
2298 fore200e_chunk_free(fore200e, &buffer[ --i ].data);
2299 fore200e_kfree(buffer);
2304 /* insert the buffer into the free buffer list */
2305 buffer[ i ].next = bsq->freebuf;
2306 bsq->freebuf = &buffer[ i ];
2308 /* all the buffers are free, initially */
2309 bsq->freebuf_count = nbr;
2311 #ifdef FORE200E_BSQ_DEBUG
2312 bsq_audit(3, bsq, scheme, magn);
2317 fore200e->state = FORE200E_STATE_ALLOC_BUF;
2323 fore200e_init_bs_queue(struct fore200e* fore200e)
2325 int scheme, magn, i;
2327 struct host_bsq* bsq;
2328 struct cp_bsq_entry* cp_entry;
2330 for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
2331 for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
2333 DPRINTK(2, "buffer supply queue %d / %d is being initialized\n", scheme, magn);
2335 bsq = &fore200e->host_bsq[ scheme ][ magn ];
2337 /* allocate and align the array of status words */
2338 if (fore200e->bus->dma_chunk_alloc(fore200e,
2340 sizeof(enum status),
2342 fore200e->bus->status_alignment) < 0) {
2346 /* allocate and align the array of receive buffer descriptors */
2347 if (fore200e->bus->dma_chunk_alloc(fore200e,
2349 sizeof(struct rbd_block),
2351 fore200e->bus->descr_alignment) < 0) {
2353 fore200e->bus->dma_chunk_free(fore200e, &bsq->status);
2357 /* get the base address of the cp resident buffer supply queue entries */
2358 cp_entry = (struct cp_bsq_entry*)(fore200e->virt_base +
2359 fore200e->bus->read(&fore200e->cp_queues->cp_bsq[ scheme ][ magn ]));
2361 /* fill the host resident and cp resident buffer supply queue entries */
2362 for (i = 0; i < QUEUE_SIZE_BS; i++) {
2364 bsq->host_entry[ i ].status =
2365 FORE200E_INDEX(bsq->status.align_addr, enum status, i);
2366 bsq->host_entry[ i ].rbd_block =
2367 FORE200E_INDEX(bsq->rbd_block.align_addr, struct rbd_block, i);
2368 bsq->host_entry[ i ].rbd_block_dma =
2369 FORE200E_DMA_INDEX(bsq->rbd_block.dma_addr, struct rbd_block, i);
2370 bsq->host_entry[ i ].cp_entry = &cp_entry[ i ];
2372 *bsq->host_entry[ i ].status = STATUS_FREE;
2374 fore200e->bus->write(FORE200E_DMA_INDEX(bsq->status.dma_addr, enum status, i),
2375 &cp_entry[ i ].status_haddr);
2380 fore200e->state = FORE200E_STATE_INIT_BSQ;
2386 fore200e_init_rx_queue(struct fore200e* fore200e)
2388 struct host_rxq* rxq = &fore200e->host_rxq;
2389 struct cp_rxq_entry* cp_entry;
2392 DPRINTK(2, "receive queue is being initialized\n");
2394 /* allocate and align the array of status words */
2395 if (fore200e->bus->dma_chunk_alloc(fore200e,
2397 sizeof(enum status),
2399 fore200e->bus->status_alignment) < 0) {
2403 /* allocate and align the array of receive PDU descriptors */
2404 if (fore200e->bus->dma_chunk_alloc(fore200e,
2408 fore200e->bus->descr_alignment) < 0) {
2410 fore200e->bus->dma_chunk_free(fore200e, &rxq->status);
2414 /* get the base address of the cp resident rx queue entries */
2415 cp_entry = (struct cp_rxq_entry*)(fore200e->virt_base +
2416 fore200e->bus->read(&fore200e->cp_queues->cp_rxq));
2418 /* fill the host resident and cp resident rx entries */
2419 for (i=0; i < QUEUE_SIZE_RX; i++) {
2421 rxq->host_entry[ i ].status =
2422 FORE200E_INDEX(rxq->status.align_addr, enum status, i);
2423 rxq->host_entry[ i ].rpd =
2424 FORE200E_INDEX(rxq->rpd.align_addr, struct rpd, i);
2425 rxq->host_entry[ i ].rpd_dma =
2426 FORE200E_DMA_INDEX(rxq->rpd.dma_addr, struct rpd, i);
2427 rxq->host_entry[ i ].cp_entry = &cp_entry[ i ];
2429 *rxq->host_entry[ i ].status = STATUS_FREE;
2431 fore200e->bus->write(FORE200E_DMA_INDEX(rxq->status.dma_addr, enum status, i),
2432 &cp_entry[ i ].status_haddr);
2434 fore200e->bus->write(FORE200E_DMA_INDEX(rxq->rpd.dma_addr, struct rpd, i),
2435 &cp_entry[ i ].rpd_haddr);
2438 /* set the head entry of the queue */
2441 fore200e->state = FORE200E_STATE_INIT_RXQ;
2447 fore200e_init_tx_queue(struct fore200e* fore200e)
2449 struct host_txq* txq = &fore200e->host_txq;
2450 struct cp_txq_entry* cp_entry;
2453 DPRINTK(2, "transmit queue is being initialized\n");
2455 /* allocate and align the array of status words */
2456 if (fore200e->bus->dma_chunk_alloc(fore200e,
2458 sizeof(enum status),
2460 fore200e->bus->status_alignment) < 0) {
2464 /* allocate and align the array of transmit PDU descriptors */
2465 if (fore200e->bus->dma_chunk_alloc(fore200e,
2469 fore200e->bus->descr_alignment) < 0) {
2471 fore200e->bus->dma_chunk_free(fore200e, &txq->status);
2475 /* get the base address of the cp resident tx queue entries */
2476 cp_entry = (struct cp_txq_entry*)(fore200e->virt_base +
2477 fore200e->bus->read(&fore200e->cp_queues->cp_txq));
2479 /* fill the host resident and cp resident tx entries */
2480 for (i=0; i < QUEUE_SIZE_TX; i++) {
2482 txq->host_entry[ i ].status =
2483 FORE200E_INDEX(txq->status.align_addr, enum status, i);
2484 txq->host_entry[ i ].tpd =
2485 FORE200E_INDEX(txq->tpd.align_addr, struct tpd, i);
2486 txq->host_entry[ i ].tpd_dma =
2487 FORE200E_DMA_INDEX(txq->tpd.dma_addr, struct tpd, i);
2488 txq->host_entry[ i ].cp_entry = &cp_entry[ i ];
2490 *txq->host_entry[ i ].status = STATUS_FREE;
2492 fore200e->bus->write(FORE200E_DMA_INDEX(txq->status.dma_addr, enum status, i),
2493 &cp_entry[ i ].status_haddr);
2495 /* although there is a one-to-one mapping of tx queue entries and tpds,
2496 we do not write here the DMA (physical) base address of each tpd into
2497 the related cp resident entry, because the cp relies on this write
2498 operation to detect that a new pdu has been submitted for tx */
2501 /* set the head and tail entries of the queue */
2505 fore200e->state = FORE200E_STATE_INIT_TXQ;
2511 fore200e_init_cmd_queue(struct fore200e* fore200e)
2513 struct host_cmdq* cmdq = &fore200e->host_cmdq;
2514 struct cp_cmdq_entry* cp_entry;
2517 DPRINTK(2, "command queue is being initialized\n");
2519 /* allocate and align the array of status words */
2520 if (fore200e->bus->dma_chunk_alloc(fore200e,
2522 sizeof(enum status),
2524 fore200e->bus->status_alignment) < 0) {
2528 /* get the base address of the cp resident cmd queue entries */
2529 cp_entry = (struct cp_cmdq_entry*)(fore200e->virt_base +
2530 fore200e->bus->read(&fore200e->cp_queues->cp_cmdq));
2532 /* fill the host resident and cp resident cmd entries */
2533 for (i=0; i < QUEUE_SIZE_CMD; i++) {
2535 cmdq->host_entry[ i ].status =
2536 FORE200E_INDEX(cmdq->status.align_addr, enum status, i);
2537 cmdq->host_entry[ i ].cp_entry = &cp_entry[ i ];
2539 *cmdq->host_entry[ i ].status = STATUS_FREE;
2541 fore200e->bus->write(FORE200E_DMA_INDEX(cmdq->status.dma_addr, enum status, i),
2542 &cp_entry[ i ].status_haddr);
2545 /* set the head entry of the queue */
2548 fore200e->state = FORE200E_STATE_INIT_CMDQ;
2554 fore200e_param_bs_queue(struct fore200e* fore200e,
2555 enum buffer_scheme scheme, enum buffer_magn magn,
2556 int queue_length, int pool_size, int supply_blksize)
2558 struct bs_spec* bs_spec = &fore200e->cp_queues->init.bs_spec[ scheme ][ magn ];
2560 fore200e->bus->write(queue_length, &bs_spec->queue_length);
2561 fore200e->bus->write(fore200e_rx_buf_size[ scheme ][ magn ], &bs_spec->buffer_size);
2562 fore200e->bus->write(pool_size, &bs_spec->pool_size);
2563 fore200e->bus->write(supply_blksize, &bs_spec->supply_blksize);
2568 fore200e_initialize(struct fore200e* fore200e)
2570 struct cp_queues* cpq;
2571 int ok, scheme, magn;
2573 DPRINTK(2, "device %s being initialized\n", fore200e->name);
2575 init_MUTEX(&fore200e->rate_sf);
2576 spin_lock_init(&fore200e->q_lock);
2578 cpq = fore200e->cp_queues = (struct cp_queues*) (fore200e->virt_base + FORE200E_CP_QUEUES_OFFSET);
2580 /* enable cp to host interrupts */
2581 fore200e->bus->write(1, &cpq->imask);
2583 if (fore200e->bus->irq_enable)
2584 fore200e->bus->irq_enable(fore200e);
2586 fore200e->bus->write(NBR_CONNECT, &cpq->init.num_connect);
2588 fore200e->bus->write(QUEUE_SIZE_CMD, &cpq->init.cmd_queue_len);
2589 fore200e->bus->write(QUEUE_SIZE_RX, &cpq->init.rx_queue_len);
2590 fore200e->bus->write(QUEUE_SIZE_TX, &cpq->init.tx_queue_len);
2592 fore200e->bus->write(RSD_EXTENSION, &cpq->init.rsd_extension);
2593 fore200e->bus->write(TSD_EXTENSION, &cpq->init.tsd_extension);
2595 for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++)
2596 for (magn = 0; magn < BUFFER_MAGN_NBR; magn++)
2597 fore200e_param_bs_queue(fore200e, scheme, magn,
2599 fore200e_rx_buf_nbr[ scheme ][ magn ],
2602 /* issue the initialize command */
2603 fore200e->bus->write(STATUS_PENDING, &cpq->init.status);
2604 fore200e->bus->write(OPCODE_INITIALIZE, &cpq->init.opcode);
2606 ok = fore200e_io_poll(fore200e, &cpq->init.status, STATUS_COMPLETE, 3000);
2608 printk(FORE200E "device %s initialization failed\n", fore200e->name);
2612 printk(FORE200E "device %s initialized\n", fore200e->name);
2614 fore200e->state = FORE200E_STATE_INITIALIZE;
2620 fore200e_monitor_putc(struct fore200e* fore200e, char c)
2622 struct cp_monitor* monitor = fore200e->cp_monitor;
2627 fore200e->bus->write(((u32) c) | FORE200E_CP_MONITOR_UART_AVAIL, &monitor->soft_uart.send);
2632 fore200e_monitor_getc(struct fore200e* fore200e)
2634 struct cp_monitor* monitor = fore200e->cp_monitor;
2635 unsigned long timeout = jiffies + MSECS(50);
2638 while (time_before(jiffies, timeout)) {
2640 c = (int) fore200e->bus->read(&monitor->soft_uart.recv);
2642 if (c & FORE200E_CP_MONITOR_UART_AVAIL) {
2644 fore200e->bus->write(FORE200E_CP_MONITOR_UART_FREE, &monitor->soft_uart.recv);
2646 printk("%c", c & 0xFF);
2657 fore200e_monitor_puts(struct fore200e* fore200e, char* str)
2661 /* the i960 monitor doesn't accept any new character if it has something to say */
2662 while (fore200e_monitor_getc(fore200e) >= 0);
2664 fore200e_monitor_putc(fore200e, *str++);
2667 while (fore200e_monitor_getc(fore200e) >= 0);
2672 fore200e_start_fw(struct fore200e* fore200e)
2676 struct fw_header* fw_header = (struct fw_header*) fore200e->bus->fw_data;
2678 DPRINTK(2, "device %s firmware being started\n", fore200e->name);
2680 #if defined(__sparc_v9__)
2681 /* reported to be required by SBA cards on some sparc64 hosts */
2685 sprintf(cmd, "\rgo %x\r", le32_to_cpu(fw_header->start_offset));
2687 fore200e_monitor_puts(fore200e, cmd);
2689 ok = fore200e_io_poll(fore200e, &fore200e->cp_monitor->bstat, BSTAT_CP_RUNNING, 1000);
2691 printk(FORE200E "device %s firmware didn't start\n", fore200e->name);
2695 printk(FORE200E "device %s firmware started\n", fore200e->name);
2697 fore200e->state = FORE200E_STATE_START_FW;
2703 fore200e_load_fw(struct fore200e* fore200e)
2705 u32* fw_data = (u32*) fore200e->bus->fw_data;
2706 u32 fw_size = (u32) *fore200e->bus->fw_size / sizeof(u32);
2708 struct fw_header* fw_header = (struct fw_header*) fw_data;
2710 u32* load_addr = fore200e->virt_base + le32_to_cpu(fw_header->load_offset);
2712 DPRINTK(2, "device %s firmware being loaded at 0x%p (%d words)\n",
2713 fore200e->name, load_addr, fw_size);
2715 if (le32_to_cpu(fw_header->magic) != FW_HEADER_MAGIC) {
2716 printk(FORE200E "corrupted %s firmware image\n", fore200e->bus->model_name);
2720 for (; fw_size--; fw_data++, load_addr++)
2721 fore200e->bus->write(le32_to_cpu(*fw_data), load_addr);
2723 fore200e->state = FORE200E_STATE_LOAD_FW;
2729 fore200e_register(struct fore200e* fore200e)
2731 struct atm_dev* atm_dev;
2733 DPRINTK(2, "device %s being registered\n", fore200e->name);
2735 atm_dev = atm_dev_register(fore200e->bus->proc_name, &fore200e_ops, -1,
2737 if (atm_dev == NULL) {
2738 printk(FORE200E "unable to register device %s\n", fore200e->name);
2742 atm_dev->dev_data = fore200e;
2743 fore200e->atm_dev = atm_dev;
2745 atm_dev->ci_range.vpi_bits = FORE200E_VPI_BITS;
2746 atm_dev->ci_range.vci_bits = FORE200E_VCI_BITS;
2748 fore200e->available_cell_rate = ATM_OC3_PCR;
2750 fore200e->state = FORE200E_STATE_REGISTER;
2756 fore200e_init(struct fore200e* fore200e)
2758 if (fore200e_register(fore200e) < 0)
2761 if (fore200e->bus->configure(fore200e) < 0)
2764 if (fore200e->bus->map(fore200e) < 0)
2767 if (fore200e_reset(fore200e, 1) < 0)
2770 if (fore200e_load_fw(fore200e) < 0)
2773 if (fore200e_start_fw(fore200e) < 0)
2776 if (fore200e_initialize(fore200e) < 0)
2779 if (fore200e_init_cmd_queue(fore200e) < 0)
2782 if (fore200e_init_tx_queue(fore200e) < 0)
2785 if (fore200e_init_rx_queue(fore200e) < 0)
2788 if (fore200e_init_bs_queue(fore200e) < 0)
2791 if (fore200e_alloc_rx_buf(fore200e) < 0)
2794 if (fore200e_get_esi(fore200e) < 0)
2797 if (fore200e_irq_request(fore200e) < 0)
2800 fore200e_supply(fore200e);
2802 /* all done, board initialization is now complete */
2803 fore200e->state = FORE200E_STATE_COMPLETE;
2809 fore200e_detect(void)
2811 const struct fore200e_bus* bus;
2812 struct fore200e* fore200e;
2815 printk(FORE200E "FORE Systems 200E-series ATM driver - version " FORE200E_VERSION "\n");
2817 /* for each configured bus interface */
2818 for (link = 0, bus = fore200e_bus; bus->model_name; bus++) {
2820 /* detect all boards present on that bus */
2821 for (index = 0; (fore200e = bus->detect(bus, index)); index++) {
2823 printk(FORE200E "device %s found at 0x%lx, IRQ %s\n",
2824 fore200e->bus->model_name,
2825 fore200e->phys_base, fore200e_irq_itoa(fore200e->irq));
2827 sprintf(fore200e->name, "%s-%d", bus->model_name, index);
2829 if (fore200e_init(fore200e) < 0) {
2831 fore200e_shutdown(fore200e);
2837 fore200e->next = fore200e_boards;
2838 fore200e_boards = fore200e;
2848 fore200e_cleanup(struct fore200e** head)
2850 struct fore200e* fore200e = *head;
2852 fore200e_shutdown(fore200e);
2854 *head = fore200e->next;
2862 fore200e_proc_read(struct atm_dev *dev, loff_t* pos, char* page)
2864 struct fore200e* fore200e = FORE200E_DEV(dev);
2865 struct fore200e_vcc* fore200e_vcc;
2866 struct atm_vcc* vcc;
2867 int i, len, left = *pos;
2868 unsigned long flags;
2872 if (fore200e_getstats(fore200e) < 0)
2875 len = sprintf(page,"\n"
2877 " internal name:\t\t%s\n", fore200e->name);
2879 /* print bus-specific information */
2880 if (fore200e->bus->proc_read)
2881 len += fore200e->bus->proc_read(fore200e, page + len);
2883 len += sprintf(page + len,
2884 " interrupt line:\t\t%s\n"
2885 " physical base address:\t0x%p\n"
2886 " virtual base address:\t0x%p\n"
2887 " factory address (ESI):\t%02x:%02x:%02x:%02x:%02x:%02x\n"
2888 " board serial number:\t\t%d\n\n",
2889 fore200e_irq_itoa(fore200e->irq),
2890 (void*)fore200e->phys_base,
2891 (void*)fore200e->virt_base,
2892 fore200e->esi[0], fore200e->esi[1], fore200e->esi[2],
2893 fore200e->esi[3], fore200e->esi[4], fore200e->esi[5],
2894 fore200e->esi[4] * 256 + fore200e->esi[5]);
2900 return sprintf(page,
2901 " free small bufs, scheme 1:\t%d\n"
2902 " free large bufs, scheme 1:\t%d\n"
2903 " free small bufs, scheme 2:\t%d\n"
2904 " free large bufs, scheme 2:\t%d\n",
2905 fore200e->host_bsq[ BUFFER_SCHEME_ONE ][ BUFFER_MAGN_SMALL ].freebuf_count,
2906 fore200e->host_bsq[ BUFFER_SCHEME_ONE ][ BUFFER_MAGN_LARGE ].freebuf_count,
2907 fore200e->host_bsq[ BUFFER_SCHEME_TWO ][ BUFFER_MAGN_SMALL ].freebuf_count,
2908 fore200e->host_bsq[ BUFFER_SCHEME_TWO ][ BUFFER_MAGN_LARGE ].freebuf_count);
2911 u32 hb = fore200e->bus->read(&fore200e->cp_queues->heartbeat);
2913 len = sprintf(page,"\n\n"
2914 " cell processor:\n"
2915 " heartbeat state:\t\t");
2917 if (hb >> 16 != 0xDEAD)
2918 len += sprintf(page + len, "0x%08x\n", hb);
2920 len += sprintf(page + len, "*** FATAL ERROR %04x ***\n", hb & 0xFFFF);
2926 static const char* media_name[] = {
2927 "unshielded twisted pair",
2928 "multimode optical fiber ST",
2929 "multimode optical fiber SC",
2930 "single-mode optical fiber ST",
2931 "single-mode optical fiber SC",
2935 static const char* oc3_mode[] = {
2937 "diagnostic loopback",
2942 u32 fw_release = fore200e->bus->read(&fore200e->cp_queues->fw_release);
2943 u32 mon960_release = fore200e->bus->read(&fore200e->cp_queues->mon960_release);
2944 u32 oc3_revision = fore200e->bus->read(&fore200e->cp_queues->oc3_revision);
2945 u32 media_index = FORE200E_MEDIA_INDEX(fore200e->bus->read(&fore200e->cp_queues->media_type));
2948 if ((media_index < 0) || (media_index > 4))
2951 switch (fore200e->loop_mode) {
2952 case ATM_LM_NONE: oc3_index = 0;
2954 case ATM_LM_LOC_PHY: oc3_index = 1;
2956 case ATM_LM_RMT_PHY: oc3_index = 2;
2958 default: oc3_index = 3;
2961 return sprintf(page,
2962 " firmware release:\t\t%d.%d.%d\n"
2963 " monitor release:\t\t%d.%d\n"
2964 " media type:\t\t\t%s\n"
2965 " OC-3 revision:\t\t0x%x\n"
2966 " OC-3 mode:\t\t\t%s",
2967 fw_release >> 16, fw_release << 16 >> 24, fw_release << 24 >> 24,
2968 mon960_release >> 16, mon960_release << 16 >> 16,
2969 media_name[ media_index ],
2971 oc3_mode[ oc3_index ]);
2975 struct cp_monitor* cp_monitor = fore200e->cp_monitor;
2977 return sprintf(page,
2980 " version number:\t\t%d\n"
2981 " boot status word:\t\t0x%08x\n",
2982 fore200e->bus->read(&cp_monitor->mon_version),
2983 fore200e->bus->read(&cp_monitor->bstat));
2987 return sprintf(page,
2989 " device statistics:\n"
2991 " crc_header_errors:\t\t%10u\n"
2992 " framing_errors:\t\t%10u\n",
2993 fore200e_swap(fore200e->stats->phy.crc_header_errors),
2994 fore200e_swap(fore200e->stats->phy.framing_errors));
2997 return sprintf(page, "\n"
2999 " section_bip8_errors:\t%10u\n"
3000 " path_bip8_errors:\t\t%10u\n"
3001 " line_bip24_errors:\t\t%10u\n"
3002 " line_febe_errors:\t\t%10u\n"
3003 " path_febe_errors:\t\t%10u\n"
3004 " corr_hcs_errors:\t\t%10u\n"
3005 " ucorr_hcs_errors:\t\t%10u\n",
3006 fore200e_swap(fore200e->stats->oc3.section_bip8_errors),
3007 fore200e_swap(fore200e->stats->oc3.path_bip8_errors),
3008 fore200e_swap(fore200e->stats->oc3.line_bip24_errors),
3009 fore200e_swap(fore200e->stats->oc3.line_febe_errors),
3010 fore200e_swap(fore200e->stats->oc3.path_febe_errors),
3011 fore200e_swap(fore200e->stats->oc3.corr_hcs_errors),
3012 fore200e_swap(fore200e->stats->oc3.ucorr_hcs_errors));
3015 return sprintf(page,"\n"
3016 " ATM:\t\t\t\t cells\n"
3019 " vpi out of range:\t\t%10u\n"
3020 " vpi no conn:\t\t%10u\n"
3021 " vci out of range:\t\t%10u\n"
3022 " vci no conn:\t\t%10u\n",
3023 fore200e_swap(fore200e->stats->atm.cells_transmitted),
3024 fore200e_swap(fore200e->stats->atm.cells_received),
3025 fore200e_swap(fore200e->stats->atm.vpi_bad_range),
3026 fore200e_swap(fore200e->stats->atm.vpi_no_conn),
3027 fore200e_swap(fore200e->stats->atm.vci_bad_range),
3028 fore200e_swap(fore200e->stats->atm.vci_no_conn));
3031 return sprintf(page,"\n"
3032 " AAL0:\t\t\t cells\n"
3035 " dropped:\t\t\t%10u\n",
3036 fore200e_swap(fore200e->stats->aal0.cells_transmitted),
3037 fore200e_swap(fore200e->stats->aal0.cells_received),
3038 fore200e_swap(fore200e->stats->aal0.cells_dropped));
3041 return sprintf(page,"\n"
3043 " SAR sublayer:\t\t cells\n"
3046 " dropped:\t\t\t%10u\n"
3047 " CRC errors:\t\t%10u\n"
3048 " protocol errors:\t\t%10u\n\n"
3049 " CS sublayer:\t\t PDUs\n"
3052 " dropped:\t\t\t%10u\n"
3053 " protocol errors:\t\t%10u\n",
3054 fore200e_swap(fore200e->stats->aal34.cells_transmitted),
3055 fore200e_swap(fore200e->stats->aal34.cells_received),
3056 fore200e_swap(fore200e->stats->aal34.cells_dropped),
3057 fore200e_swap(fore200e->stats->aal34.cells_crc_errors),
3058 fore200e_swap(fore200e->stats->aal34.cells_protocol_errors),
3059 fore200e_swap(fore200e->stats->aal34.cspdus_transmitted),
3060 fore200e_swap(fore200e->stats->aal34.cspdus_received),
3061 fore200e_swap(fore200e->stats->aal34.cspdus_dropped),
3062 fore200e_swap(fore200e->stats->aal34.cspdus_protocol_errors));
3065 return sprintf(page,"\n"
3067 " SAR sublayer:\t\t cells\n"
3070 " dropped:\t\t\t%10u\n"
3071 " congestions:\t\t%10u\n\n"
3072 " CS sublayer:\t\t PDUs\n"
3075 " dropped:\t\t\t%10u\n"
3076 " CRC errors:\t\t%10u\n"
3077 " protocol errors:\t\t%10u\n",
3078 fore200e_swap(fore200e->stats->aal5.cells_transmitted),
3079 fore200e_swap(fore200e->stats->aal5.cells_received),
3080 fore200e_swap(fore200e->stats->aal5.cells_dropped),
3081 fore200e_swap(fore200e->stats->aal5.congestion_experienced),
3082 fore200e_swap(fore200e->stats->aal5.cspdus_transmitted),
3083 fore200e_swap(fore200e->stats->aal5.cspdus_received),
3084 fore200e_swap(fore200e->stats->aal5.cspdus_dropped),
3085 fore200e_swap(fore200e->stats->aal5.cspdus_crc_errors),
3086 fore200e_swap(fore200e->stats->aal5.cspdus_protocol_errors));
3089 return sprintf(page,"\n"
3090 " AUX:\t\t allocation failures\n"
3091 " small b1:\t\t\t%10u\n"
3092 " large b1:\t\t\t%10u\n"
3093 " small b2:\t\t\t%10u\n"
3094 " large b2:\t\t\t%10u\n"
3095 " RX PDUs:\t\t\t%10u\n"
3096 " TX PDUs:\t\t\t%10lu\n",
3097 fore200e_swap(fore200e->stats->aux.small_b1_failed),
3098 fore200e_swap(fore200e->stats->aux.large_b1_failed),
3099 fore200e_swap(fore200e->stats->aux.small_b2_failed),
3100 fore200e_swap(fore200e->stats->aux.large_b2_failed),
3101 fore200e_swap(fore200e->stats->aux.rpd_alloc_failed),
3105 return sprintf(page,"\n"
3106 " receive carrier:\t\t\t%s\n",
3107 fore200e->stats->aux.receive_carrier ? "ON" : "OFF!");
3110 return sprintf(page,"\n"
3111 " VCCs:\n address VPI VCI AAL "
3112 "TX PDUs TX min/max size RX PDUs RX min/max size\n");
3116 for (i = 0; i < NBR_CONNECT; i++) {
3118 vcc = fore200e->vc_map[i].vcc;
3123 spin_lock_irqsave(&fore200e->q_lock, flags);
3125 if (vcc && test_bit(ATM_VF_READY, &vcc->flags) && !left--) {
3127 fore200e_vcc = FORE200E_VCC(vcc);
3128 ASSERT(fore200e_vcc);
3131 " %08x %03d %05d %1d %09lu %05d/%05d %09lu %05d/%05d\n",
3132 (u32)(unsigned long)vcc,
3133 vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal),
3134 fore200e_vcc->tx_pdu,
3135 fore200e_vcc->tx_min_pdu > 0xFFFF ? 0 : fore200e_vcc->tx_min_pdu,
3136 fore200e_vcc->tx_max_pdu,
3137 fore200e_vcc->rx_pdu,
3138 fore200e_vcc->rx_min_pdu > 0xFFFF ? 0 : fore200e_vcc->rx_min_pdu,
3139 fore200e_vcc->rx_max_pdu
3142 spin_unlock_irqrestore(&fore200e->q_lock, flags);
3146 spin_unlock_irqrestore(&fore200e->q_lock, flags);
3155 fore200e_module_init(void)
3157 DPRINTK(1, "module loaded\n");
3158 return fore200e_detect() == 0;
3162 fore200e_module_cleanup(void)
3164 while (fore200e_boards) {
3165 fore200e_cleanup(&fore200e_boards);
3167 DPRINTK(1, "module being removed\n");
3170 module_init(fore200e_module_init);
3171 module_exit(fore200e_module_cleanup);
3175 static const struct atmdev_ops fore200e_ops =
3177 open: fore200e_open,
3178 close: fore200e_close,
3179 ioctl: fore200e_ioctl,
3180 getsockopt: fore200e_getsockopt,
3181 setsockopt: fore200e_setsockopt,
3182 send: fore200e_send,
3183 change_qos: fore200e_change_qos,
3184 proc_read: fore200e_proc_read,
3189 #ifdef CONFIG_ATM_FORE200E_PCA
3190 extern const unsigned char _fore200e_pca_fw_data[];
3191 extern const unsigned int _fore200e_pca_fw_size;
3193 #ifdef CONFIG_ATM_FORE200E_SBA
3194 extern const unsigned char _fore200e_sba_fw_data[];
3195 extern const unsigned int _fore200e_sba_fw_size;
3198 static const struct fore200e_bus fore200e_bus[] = {
3199 #ifdef CONFIG_ATM_FORE200E_PCA
3200 { "PCA-200E", "pca200e", 32, 4, 32,
3201 _fore200e_pca_fw_data, &_fore200e_pca_fw_size,
3204 fore200e_pca_dma_map,
3205 fore200e_pca_dma_unmap,
3206 fore200e_pca_dma_sync,
3207 fore200e_pca_dma_chunk_alloc,
3208 fore200e_pca_dma_chunk_free,
3209 fore200e_pca_detect,
3210 fore200e_pca_configure,
3213 fore200e_pca_prom_read,
3216 fore200e_pca_irq_check,
3217 fore200e_pca_irq_ack,
3218 fore200e_pca_proc_read,
3221 #ifdef CONFIG_ATM_FORE200E_SBA
3222 { "SBA-200E", "sba200e", 32, 64, 32,
3223 _fore200e_sba_fw_data, &_fore200e_sba_fw_size,
3226 fore200e_sba_dma_map,
3227 fore200e_sba_dma_unmap,
3228 fore200e_sba_dma_sync,
3229 fore200e_sba_dma_chunk_alloc,
3230 fore200e_sba_dma_chunk_free,
3231 fore200e_sba_detect,
3232 fore200e_sba_configure,
3235 fore200e_sba_prom_read,
3237 fore200e_sba_irq_enable,
3238 fore200e_sba_irq_check,
3239 fore200e_sba_irq_ack,
3240 fore200e_sba_proc_read,
3246 #ifdef MODULE_LICENSE
3247 MODULE_LICENSE("GPL");