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/config.h>
29 #include <linux/kernel.h>
30 #include <linux/slab.h>
31 #include <linux/init.h>
32 #include <linux/capability.h>
33 #include <linux/sched.h>
34 #include <linux/interrupt.h>
35 #include <linux/bitops.h>
36 #include <linux/pci.h>
37 #include <linux/module.h>
38 #include <linux/atmdev.h>
39 #include <linux/sonet.h>
40 #include <linux/atm_suni.h>
41 #include <linux/dma-mapping.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 MSECS(ms) (((ms)*HZ/1000)+1)
103 #define ASSERT(expr) if (!(expr)) { \
104 printk(FORE200E "assertion failed! %s[%d]: %s\n", \
105 __FUNCTION__, __LINE__, #expr); \
106 panic(FORE200E "%s", __FUNCTION__); \
109 #define ASSERT(expr) do {} while (0)
113 static const struct atmdev_ops fore200e_ops;
114 static const struct fore200e_bus fore200e_bus[];
116 static struct fore200e* fore200e_boards = NULL;
119 MODULE_AUTHOR("Christophe Lizzi - credits to Uwe Dannowski and Heikki Vatiainen");
120 MODULE_DESCRIPTION("FORE Systems 200E-series ATM driver - version " FORE200E_VERSION);
121 MODULE_SUPPORTED_DEVICE("PCA-200E, SBA-200E");
124 static const int fore200e_rx_buf_nbr[ BUFFER_SCHEME_NBR ][ BUFFER_MAGN_NBR ] = {
125 { BUFFER_S1_NBR, BUFFER_L1_NBR },
126 { BUFFER_S2_NBR, BUFFER_L2_NBR }
129 static const int fore200e_rx_buf_size[ BUFFER_SCHEME_NBR ][ BUFFER_MAGN_NBR ] = {
130 { BUFFER_S1_SIZE, BUFFER_L1_SIZE },
131 { BUFFER_S2_SIZE, BUFFER_L2_SIZE }
135 #if defined(CONFIG_ATM_FORE200E_DEBUG) && (CONFIG_ATM_FORE200E_DEBUG > 0)
136 static const char* fore200e_traffic_class[] = { "NONE", "UBR", "CBR", "VBR", "ABR", "ANY" };
140 #if 0 /* currently unused */
142 fore200e_fore2atm_aal(enum fore200e_aal aal)
145 case FORE200E_AAL0: return ATM_AAL0;
146 case FORE200E_AAL34: return ATM_AAL34;
147 case FORE200E_AAL5: return ATM_AAL5;
155 static enum fore200e_aal
156 fore200e_atm2fore_aal(int aal)
159 case ATM_AAL0: return FORE200E_AAL0;
160 case ATM_AAL34: return FORE200E_AAL34;
163 case ATM_AAL5: return FORE200E_AAL5;
171 fore200e_irq_itoa(int irq)
173 #if defined(__sparc_v9__)
174 return __irq_itoa(irq);
177 sprintf(str, "%d", irq);
184 fore200e_kmalloc(int size, int flags)
186 void* chunk = kmalloc(size, flags);
189 memset(chunk, 0x00, size);
191 printk(FORE200E "kmalloc() failed, requested size = %d, flags = 0x%x\n", size, flags);
198 fore200e_kfree(void* chunk)
204 /* allocate and align a chunk of memory intended to hold the data behing exchanged
205 between the driver and the adapter (using streaming DVMA) */
208 fore200e_chunk_alloc(struct fore200e* fore200e, struct chunk* chunk, int size, int alignment, int direction)
210 unsigned long offset = 0;
212 if (alignment <= sizeof(int))
215 chunk->alloc_size = size + alignment;
216 chunk->align_size = size;
217 chunk->direction = direction;
219 chunk->alloc_addr = fore200e_kmalloc(chunk->alloc_size, GFP_KERNEL | GFP_DMA);
220 if (chunk->alloc_addr == NULL)
224 offset = FORE200E_ALIGN(chunk->alloc_addr, alignment);
226 chunk->align_addr = chunk->alloc_addr + offset;
228 chunk->dma_addr = fore200e->bus->dma_map(fore200e, chunk->align_addr, chunk->align_size, direction);
234 /* free a chunk of memory */
237 fore200e_chunk_free(struct fore200e* fore200e, struct chunk* chunk)
239 fore200e->bus->dma_unmap(fore200e, chunk->dma_addr, chunk->dma_size, chunk->direction);
241 fore200e_kfree(chunk->alloc_addr);
246 fore200e_spin(int msecs)
248 unsigned long timeout = jiffies + MSECS(msecs);
249 while (time_before(jiffies, timeout));
254 fore200e_poll(struct fore200e* fore200e, volatile u32* addr, u32 val, int msecs)
256 unsigned long timeout = jiffies + MSECS(msecs);
261 if ((ok = (*addr == val)) || (*addr & STATUS_ERROR))
264 } while (time_before(jiffies, timeout));
268 printk(FORE200E "cmd polling failed, got status 0x%08x, expected 0x%08x\n",
278 fore200e_io_poll(struct fore200e* fore200e, volatile u32* addr, u32 val, int msecs)
280 unsigned long timeout = jiffies + MSECS(msecs);
284 if ((ok = (fore200e->bus->read(addr) == val)))
287 } while (time_before(jiffies, timeout));
291 printk(FORE200E "I/O polling failed, got status 0x%08x, expected 0x%08x\n",
292 fore200e->bus->read(addr), val);
301 fore200e_free_rx_buf(struct fore200e* fore200e)
303 int scheme, magn, nbr;
304 struct buffer* buffer;
306 for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
307 for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
309 if ((buffer = fore200e->host_bsq[ scheme ][ magn ].buffer) != NULL) {
311 for (nbr = 0; nbr < fore200e_rx_buf_nbr[ scheme ][ magn ]; nbr++) {
313 struct chunk* data = &buffer[ nbr ].data;
315 if (data->alloc_addr != NULL)
316 fore200e_chunk_free(fore200e, data);
325 fore200e_uninit_bs_queue(struct fore200e* fore200e)
329 for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
330 for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
332 struct chunk* status = &fore200e->host_bsq[ scheme ][ magn ].status;
333 struct chunk* rbd_block = &fore200e->host_bsq[ scheme ][ magn ].rbd_block;
335 if (status->alloc_addr)
336 fore200e->bus->dma_chunk_free(fore200e, status);
338 if (rbd_block->alloc_addr)
339 fore200e->bus->dma_chunk_free(fore200e, rbd_block);
346 fore200e_reset(struct fore200e* fore200e, int diag)
350 fore200e->cp_monitor = (struct cp_monitor*)(fore200e->virt_base + FORE200E_CP_MONITOR_OFFSET);
352 fore200e->bus->write(BSTAT_COLD_START, &fore200e->cp_monitor->bstat);
354 fore200e->bus->reset(fore200e);
357 ok = fore200e_io_poll(fore200e, &fore200e->cp_monitor->bstat, BSTAT_SELFTEST_OK, 1000);
360 printk(FORE200E "device %s self-test failed\n", fore200e->name);
364 printk(FORE200E "device %s self-test passed\n", fore200e->name);
366 fore200e->state = FORE200E_STATE_RESET;
374 fore200e_shutdown(struct fore200e* fore200e)
376 printk(FORE200E "removing device %s at 0x%lx, IRQ %s\n",
377 fore200e->name, fore200e->phys_base,
378 fore200e_irq_itoa(fore200e->irq));
380 if (fore200e->state > FORE200E_STATE_RESET) {
381 /* first, reset the board to prevent further interrupts or data transfers */
382 fore200e_reset(fore200e, 0);
385 /* then, release all allocated resources */
386 switch(fore200e->state) {
388 case FORE200E_STATE_COMPLETE:
390 kfree(fore200e->stats);
392 case FORE200E_STATE_IRQ:
393 free_irq(fore200e->irq, fore200e->atm_dev);
395 case FORE200E_STATE_ALLOC_BUF:
396 fore200e_free_rx_buf(fore200e);
398 case FORE200E_STATE_INIT_BSQ:
399 fore200e_uninit_bs_queue(fore200e);
401 case FORE200E_STATE_INIT_RXQ:
402 fore200e->bus->dma_chunk_free(fore200e, &fore200e->host_rxq.status);
403 fore200e->bus->dma_chunk_free(fore200e, &fore200e->host_rxq.rpd);
405 case FORE200E_STATE_INIT_TXQ:
406 fore200e->bus->dma_chunk_free(fore200e, &fore200e->host_txq.status);
407 fore200e->bus->dma_chunk_free(fore200e, &fore200e->host_txq.tpd);
409 case FORE200E_STATE_INIT_CMDQ:
410 fore200e->bus->dma_chunk_free(fore200e, &fore200e->host_cmdq.status);
412 case FORE200E_STATE_INITIALIZE:
413 /* nothing to do for that state */
415 case FORE200E_STATE_START_FW:
416 /* nothing to do for that state */
418 case FORE200E_STATE_LOAD_FW:
419 /* nothing to do for that state */
421 case FORE200E_STATE_RESET:
422 /* nothing to do for that state */
424 case FORE200E_STATE_MAP:
425 fore200e->bus->unmap(fore200e);
427 case FORE200E_STATE_CONFIGURE:
428 /* nothing to do for that state */
430 case FORE200E_STATE_REGISTER:
431 /* XXX shouldn't we *start* by deregistering the device? */
432 atm_dev_deregister(fore200e->atm_dev);
434 case FORE200E_STATE_BLANK:
435 /* nothing to do for that state */
441 #ifdef CONFIG_ATM_FORE200E_PCA
443 static u32 fore200e_pca_read(volatile u32* addr)
445 /* on big-endian hosts, the board is configured to convert
446 the endianess of slave RAM accesses */
447 return le32_to_cpu(readl(addr));
451 static void fore200e_pca_write(u32 val, volatile u32* addr)
453 /* on big-endian hosts, the board is configured to convert
454 the endianess of slave RAM accesses */
455 writel(cpu_to_le32(val), addr);
460 fore200e_pca_dma_map(struct fore200e* fore200e, void* virt_addr, int size, int direction)
462 u32 dma_addr = pci_map_single((struct pci_dev*)fore200e->bus_dev, virt_addr, size, direction);
464 DPRINTK(3, "PCI DVMA mapping: virt_addr = 0x%p, size = %d, direction = %d, --> dma_addr = 0x%08x\n",
465 virt_addr, size, direction, dma_addr);
472 fore200e_pca_dma_unmap(struct fore200e* fore200e, u32 dma_addr, int size, int direction)
474 DPRINTK(3, "PCI DVMA unmapping: dma_addr = 0x%08x, size = %d, direction = %d\n",
475 dma_addr, size, direction);
477 pci_unmap_single((struct pci_dev*)fore200e->bus_dev, dma_addr, size, direction);
482 fore200e_pca_dma_sync_for_cpu(struct fore200e* fore200e, u32 dma_addr, int size, int direction)
484 DPRINTK(3, "PCI DVMA sync: dma_addr = 0x%08x, size = %d, direction = %d\n", dma_addr, size, direction);
486 pci_dma_sync_single_for_cpu((struct pci_dev*)fore200e->bus_dev, dma_addr, size, direction);
490 fore200e_pca_dma_sync_for_device(struct fore200e* fore200e, u32 dma_addr, int size, int direction)
492 DPRINTK(3, "PCI DVMA sync: dma_addr = 0x%08x, size = %d, direction = %d\n", dma_addr, size, direction);
494 pci_dma_sync_single_for_device((struct pci_dev*)fore200e->bus_dev, dma_addr, size, direction);
498 /* allocate a DMA consistent chunk of memory intended to act as a communication mechanism
499 (to hold descriptors, status, queues, etc.) shared by the driver and the adapter */
502 fore200e_pca_dma_chunk_alloc(struct fore200e* fore200e, struct chunk* chunk,
503 int size, int nbr, int alignment)
505 /* returned chunks are page-aligned */
506 chunk->alloc_size = size * nbr;
507 chunk->alloc_addr = pci_alloc_consistent((struct pci_dev*)fore200e->bus_dev,
511 if ((chunk->alloc_addr == NULL) || (chunk->dma_addr == 0))
514 chunk->align_addr = chunk->alloc_addr;
520 /* free a DMA consistent chunk of memory */
523 fore200e_pca_dma_chunk_free(struct fore200e* fore200e, struct chunk* chunk)
525 pci_free_consistent((struct pci_dev*)fore200e->bus_dev,
533 fore200e_pca_irq_check(struct fore200e* fore200e)
535 /* this is a 1 bit register */
536 int irq_posted = readl(fore200e->regs.pca.psr);
538 #if defined(CONFIG_ATM_FORE200E_DEBUG) && (CONFIG_ATM_FORE200E_DEBUG == 2)
539 if (irq_posted && (readl(fore200e->regs.pca.hcr) & PCA200E_HCR_OUTFULL)) {
540 DPRINTK(2,"FIFO OUT full, device %d\n", fore200e->atm_dev->number);
549 fore200e_pca_irq_ack(struct fore200e* fore200e)
551 writel(PCA200E_HCR_CLRINTR, fore200e->regs.pca.hcr);
556 fore200e_pca_reset(struct fore200e* fore200e)
558 writel(PCA200E_HCR_RESET, fore200e->regs.pca.hcr);
560 writel(0, fore200e->regs.pca.hcr);
565 fore200e_pca_map(struct fore200e* fore200e)
567 DPRINTK(2, "device %s being mapped in memory\n", fore200e->name);
569 fore200e->virt_base = ioremap(fore200e->phys_base, PCA200E_IOSPACE_LENGTH);
571 if (fore200e->virt_base == NULL) {
572 printk(FORE200E "can't map device %s\n", fore200e->name);
576 DPRINTK(1, "device %s mapped to 0x%p\n", fore200e->name, fore200e->virt_base);
578 /* gain access to the PCA specific registers */
579 fore200e->regs.pca.hcr = (u32*)(fore200e->virt_base + PCA200E_HCR_OFFSET);
580 fore200e->regs.pca.imr = (u32*)(fore200e->virt_base + PCA200E_IMR_OFFSET);
581 fore200e->regs.pca.psr = (u32*)(fore200e->virt_base + PCA200E_PSR_OFFSET);
583 fore200e->state = FORE200E_STATE_MAP;
589 fore200e_pca_unmap(struct fore200e* fore200e)
591 DPRINTK(2, "device %s being unmapped from memory\n", fore200e->name);
593 if (fore200e->virt_base != NULL)
594 iounmap(fore200e->virt_base);
599 fore200e_pca_configure(struct fore200e* fore200e)
601 struct pci_dev* pci_dev = (struct pci_dev*)fore200e->bus_dev;
602 u8 master_ctrl, latency;
604 DPRINTK(2, "device %s being configured\n", fore200e->name);
606 if ((pci_dev->irq == 0) || (pci_dev->irq == 0xFF)) {
607 printk(FORE200E "incorrect IRQ setting - misconfigured PCI-PCI bridge?\n");
611 pci_read_config_byte(pci_dev, PCA200E_PCI_MASTER_CTRL, &master_ctrl);
613 master_ctrl = master_ctrl
614 #if defined(__BIG_ENDIAN)
615 /* request the PCA board to convert the endianess of slave RAM accesses */
616 | PCA200E_CTRL_CONVERT_ENDIAN
619 | PCA200E_CTRL_DIS_CACHE_RD
620 | PCA200E_CTRL_DIS_WRT_INVAL
621 | PCA200E_CTRL_ENA_CONT_REQ_MODE
622 | PCA200E_CTRL_2_CACHE_WRT_INVAL
624 | PCA200E_CTRL_LARGE_PCI_BURSTS;
626 pci_write_config_byte(pci_dev, PCA200E_PCI_MASTER_CTRL, master_ctrl);
628 /* raise latency from 32 (default) to 192, as this seems to prevent NIC
629 lockups (under heavy rx loads) due to continuous 'FIFO OUT full' condition.
630 this may impact the performances of other PCI devices on the same bus, though */
632 pci_write_config_byte(pci_dev, PCI_LATENCY_TIMER, latency);
634 fore200e->state = FORE200E_STATE_CONFIGURE;
639 static struct fore200e* __init
640 fore200e_pca_detect(const struct fore200e_bus* bus, int index)
642 struct fore200e* fore200e;
643 struct pci_dev* pci_dev = NULL;
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), DMA_FROM_DEVICE);
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), DMA_FROM_DEVICE);
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_for_cpu(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_for_cpu((struct sbus_dev*)fore200e->bus_dev, dma_addr, size, direction);
777 fore200e_sba_dma_sync_for_device(struct fore200e* fore200e, u32 dma_addr, int size, int direction)
779 DPRINTK(3, "SBUS DVMA sync: dma_addr = 0x%08x, size = %d, direction = %d\n", dma_addr, size, direction);
781 sbus_dma_sync_single_for_device((struct sbus_dev*)fore200e->bus_dev, dma_addr, size, direction);
785 /* allocate a DVMA consistent chunk of memory intended to act as a communication mechanism
786 (to hold descriptors, status, queues, etc.) shared by the driver and the adapter */
789 fore200e_sba_dma_chunk_alloc(struct fore200e* fore200e, struct chunk* chunk,
790 int size, int nbr, int alignment)
792 chunk->alloc_size = chunk->align_size = size * nbr;
794 /* returned chunks are page-aligned */
795 chunk->alloc_addr = sbus_alloc_consistent((struct sbus_dev*)fore200e->bus_dev,
799 if ((chunk->alloc_addr == NULL) || (chunk->dma_addr == 0))
802 chunk->align_addr = chunk->alloc_addr;
808 /* free a DVMA consistent chunk of memory */
811 fore200e_sba_dma_chunk_free(struct fore200e* fore200e, struct chunk* chunk)
813 sbus_free_consistent((struct sbus_dev*)fore200e->bus_dev,
821 fore200e_sba_irq_enable(struct fore200e* fore200e)
823 u32 hcr = fore200e->bus->read(fore200e->regs.sba.hcr) & SBA200E_HCR_STICKY;
824 fore200e->bus->write(hcr | SBA200E_HCR_INTR_ENA, fore200e->regs.sba.hcr);
829 fore200e_sba_irq_check(struct fore200e* fore200e)
831 return fore200e->bus->read(fore200e->regs.sba.hcr) & SBA200E_HCR_INTR_REQ;
836 fore200e_sba_irq_ack(struct fore200e* fore200e)
838 u32 hcr = fore200e->bus->read(fore200e->regs.sba.hcr) & SBA200E_HCR_STICKY;
839 fore200e->bus->write(hcr | SBA200E_HCR_INTR_CLR, fore200e->regs.sba.hcr);
844 fore200e_sba_reset(struct fore200e* fore200e)
846 fore200e->bus->write(SBA200E_HCR_RESET, fore200e->regs.sba.hcr);
848 fore200e->bus->write(0, fore200e->regs.sba.hcr);
853 fore200e_sba_map(struct fore200e* fore200e)
855 struct sbus_dev* sbus_dev = (struct sbus_dev*)fore200e->bus_dev;
858 /* gain access to the SBA specific registers */
859 fore200e->regs.sba.hcr = (u32*)sbus_ioremap(&sbus_dev->resource[0], 0, SBA200E_HCR_LENGTH, "SBA HCR");
860 fore200e->regs.sba.bsr = (u32*)sbus_ioremap(&sbus_dev->resource[1], 0, SBA200E_BSR_LENGTH, "SBA BSR");
861 fore200e->regs.sba.isr = (u32*)sbus_ioremap(&sbus_dev->resource[2], 0, SBA200E_ISR_LENGTH, "SBA ISR");
862 fore200e->virt_base = (u32*)sbus_ioremap(&sbus_dev->resource[3], 0, SBA200E_RAM_LENGTH, "SBA RAM");
864 if (fore200e->virt_base == NULL) {
865 printk(FORE200E "unable to map RAM of device %s\n", fore200e->name);
869 DPRINTK(1, "device %s mapped to 0x%p\n", fore200e->name, fore200e->virt_base);
871 fore200e->bus->write(0x02, fore200e->regs.sba.isr); /* XXX hardwired interrupt level */
873 /* get the supported DVMA burst sizes */
874 bursts = prom_getintdefault(sbus_dev->bus->prom_node, "burst-sizes", 0x00);
876 if (sbus_can_dma_64bit(sbus_dev))
877 sbus_set_sbus64(sbus_dev, bursts);
879 fore200e->state = FORE200E_STATE_MAP;
885 fore200e_sba_unmap(struct fore200e* fore200e)
887 sbus_iounmap((ulong)fore200e->regs.sba.hcr, SBA200E_HCR_LENGTH);
888 sbus_iounmap((ulong)fore200e->regs.sba.bsr, SBA200E_BSR_LENGTH);
889 sbus_iounmap((ulong)fore200e->regs.sba.isr, SBA200E_ISR_LENGTH);
890 sbus_iounmap((ulong)fore200e->virt_base, SBA200E_RAM_LENGTH);
895 fore200e_sba_configure(struct fore200e* fore200e)
897 fore200e->state = FORE200E_STATE_CONFIGURE;
902 static struct fore200e* __init
903 fore200e_sba_detect(const struct fore200e_bus* bus, int index)
905 struct fore200e* fore200e;
906 struct sbus_bus* sbus_bus;
907 struct sbus_dev* sbus_dev = NULL;
909 unsigned int count = 0;
911 for_each_sbus (sbus_bus) {
912 for_each_sbusdev (sbus_dev, sbus_bus) {
913 if (strcmp(sbus_dev->prom_name, SBA200E_PROM_NAME) == 0) {
923 if (sbus_dev->num_registers != 4) {
924 printk(FORE200E "this %s device has %d instead of 4 registers\n",
925 bus->model_name, sbus_dev->num_registers);
929 fore200e = fore200e_kmalloc(sizeof(struct fore200e), GFP_KERNEL);
930 if (fore200e == NULL)
934 fore200e->bus_dev = sbus_dev;
935 fore200e->irq = sbus_dev->irqs[ 0 ];
937 fore200e->phys_base = (unsigned long)sbus_dev;
939 sprintf(fore200e->name, "%s-%d", bus->model_name, index - 1);
946 fore200e_sba_prom_read(struct fore200e* fore200e, struct prom_data* prom)
948 struct sbus_dev* sbus_dev = (struct sbus_dev*) fore200e->bus_dev;
951 len = prom_getproperty(sbus_dev->prom_node, "macaddrlo2", &prom->mac_addr[ 4 ], 4);
955 len = prom_getproperty(sbus_dev->prom_node, "macaddrhi4", &prom->mac_addr[ 2 ], 4);
959 prom_getproperty(sbus_dev->prom_node, "serialnumber",
960 (char*)&prom->serial_number, sizeof(prom->serial_number));
962 prom_getproperty(sbus_dev->prom_node, "promversion",
963 (char*)&prom->hw_revision, sizeof(prom->hw_revision));
970 fore200e_sba_proc_read(struct fore200e* fore200e, char *page)
972 struct sbus_dev* sbus_dev = (struct sbus_dev*)fore200e->bus_dev;
974 return sprintf(page, " SBUS slot/device:\t\t%d/'%s'\n", sbus_dev->slot, sbus_dev->prom_name);
976 #endif /* CONFIG_ATM_FORE200E_SBA */
980 fore200e_tx_irq(struct fore200e* fore200e)
982 struct host_txq* txq = &fore200e->host_txq;
983 struct host_txq_entry* entry;
985 struct fore200e_vc_map* vc_map;
987 if (fore200e->host_txq.txing == 0)
992 entry = &txq->host_entry[ txq->tail ];
994 if ((*entry->status & STATUS_COMPLETE) == 0) {
998 DPRINTK(3, "TX COMPLETED: entry = %p [tail = %d], vc_map = %p, skb = %p\n",
999 entry, txq->tail, entry->vc_map, entry->skb);
1001 /* free copy of misaligned data */
1005 /* remove DMA mapping */
1006 fore200e->bus->dma_unmap(fore200e, entry->tpd->tsd[ 0 ].buffer, entry->tpd->tsd[ 0 ].length,
1009 vc_map = entry->vc_map;
1011 /* vcc closed since the time the entry was submitted for tx? */
1012 if ((vc_map->vcc == NULL) ||
1013 (test_bit(ATM_VF_READY, &vc_map->vcc->flags) == 0)) {
1015 DPRINTK(1, "no ready vcc found for PDU sent on device %d\n",
1016 fore200e->atm_dev->number);
1018 dev_kfree_skb_any(entry->skb);
1021 ASSERT(vc_map->vcc);
1023 /* vcc closed then immediately re-opened? */
1024 if (vc_map->incarn != entry->incarn) {
1026 /* when a vcc is closed, some PDUs may be still pending in the tx queue.
1027 if the same vcc is immediately re-opened, those pending PDUs must
1028 not be popped after the completion of their emission, as they refer
1029 to the prior incarnation of that vcc. otherwise, vcc->sk->sk_wmem_alloc
1030 would be decremented by the size of the (unrelated) skb, possibly
1031 leading to a negative sk->sk_wmem_alloc count, ultimately freezing the vcc.
1032 we thus bind the tx entry to the current incarnation of the vcc
1033 when the entry is submitted for tx. When the tx later completes,
1034 if the incarnation number of the tx entry does not match the one
1035 of the vcc, then this implies that the vcc has been closed then re-opened.
1036 we thus just drop the skb here. */
1038 DPRINTK(1, "vcc closed-then-re-opened; dropping PDU sent on device %d\n",
1039 fore200e->atm_dev->number);
1041 dev_kfree_skb_any(entry->skb);
1047 /* notify tx completion */
1049 vcc->pop(vcc, entry->skb);
1052 dev_kfree_skb_any(entry->skb);
1055 /* race fixed by the above incarnation mechanism, but... */
1056 if (atomic_read(&vcc->sk->sk_wmem_alloc) < 0) {
1057 atomic_set(&vcc->sk->sk_wmem_alloc, 0);
1060 /* check error condition */
1061 if (*entry->status & STATUS_ERROR)
1062 atomic_inc(&vcc->stats->tx_err);
1064 atomic_inc(&vcc->stats->tx);
1068 *entry->status = STATUS_FREE;
1070 fore200e->host_txq.txing--;
1072 FORE200E_NEXT_ENTRY(txq->tail, QUEUE_SIZE_TX);
1077 #ifdef FORE200E_BSQ_DEBUG
1078 int bsq_audit(int where, struct host_bsq* bsq, int scheme, int magn)
1080 struct buffer* buffer;
1083 buffer = bsq->freebuf;
1086 if (buffer->supplied) {
1087 printk(FORE200E "bsq_audit(%d): queue %d.%d, buffer %ld supplied but in free list!\n",
1088 where, scheme, magn, buffer->index);
1091 if (buffer->magn != magn) {
1092 printk(FORE200E "bsq_audit(%d): queue %d.%d, buffer %ld, unexpected magn = %d\n",
1093 where, scheme, magn, buffer->index, buffer->magn);
1096 if (buffer->scheme != scheme) {
1097 printk(FORE200E "bsq_audit(%d): queue %d.%d, buffer %ld, unexpected scheme = %d\n",
1098 where, scheme, magn, buffer->index, buffer->scheme);
1101 if ((buffer->index < 0) || (buffer->index >= fore200e_rx_buf_nbr[ scheme ][ magn ])) {
1102 printk(FORE200E "bsq_audit(%d): queue %d.%d, out of range buffer index = %ld !\n",
1103 where, scheme, magn, buffer->index);
1107 buffer = buffer->next;
1110 if (count != bsq->freebuf_count) {
1111 printk(FORE200E "bsq_audit(%d): queue %d.%d, %d bufs in free list, but freebuf_count = %d\n",
1112 where, scheme, magn, count, bsq->freebuf_count);
1120 fore200e_supply(struct fore200e* fore200e)
1122 int scheme, magn, i;
1124 struct host_bsq* bsq;
1125 struct host_bsq_entry* entry;
1126 struct buffer* buffer;
1128 for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
1129 for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
1131 bsq = &fore200e->host_bsq[ scheme ][ magn ];
1133 #ifdef FORE200E_BSQ_DEBUG
1134 bsq_audit(1, bsq, scheme, magn);
1136 while (bsq->freebuf_count >= RBD_BLK_SIZE) {
1138 DPRINTK(2, "supplying %d rx buffers to queue %d / %d, freebuf_count = %d\n",
1139 RBD_BLK_SIZE, scheme, magn, bsq->freebuf_count);
1141 entry = &bsq->host_entry[ bsq->head ];
1143 for (i = 0; i < RBD_BLK_SIZE; i++) {
1145 /* take the first buffer in the free buffer list */
1146 buffer = bsq->freebuf;
1148 printk(FORE200E "no more free bufs in queue %d.%d, but freebuf_count = %d\n",
1149 scheme, magn, bsq->freebuf_count);
1152 bsq->freebuf = buffer->next;
1154 #ifdef FORE200E_BSQ_DEBUG
1155 if (buffer->supplied)
1156 printk(FORE200E "queue %d.%d, buffer %lu already supplied\n",
1157 scheme, magn, buffer->index);
1158 buffer->supplied = 1;
1160 entry->rbd_block->rbd[ i ].buffer_haddr = buffer->data.dma_addr;
1161 entry->rbd_block->rbd[ i ].handle = FORE200E_BUF2HDL(buffer);
1164 FORE200E_NEXT_ENTRY(bsq->head, QUEUE_SIZE_BS);
1166 /* decrease accordingly the number of free rx buffers */
1167 bsq->freebuf_count -= RBD_BLK_SIZE;
1169 *entry->status = STATUS_PENDING;
1170 fore200e->bus->write(entry->rbd_block_dma, &entry->cp_entry->rbd_block_haddr);
1178 fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rpd)
1180 struct sk_buff* skb;
1181 struct buffer* buffer;
1182 struct fore200e_vcc* fore200e_vcc;
1184 #ifdef FORE200E_52BYTE_AAL0_SDU
1185 u32 cell_header = 0;
1190 fore200e_vcc = FORE200E_VCC(vcc);
1191 ASSERT(fore200e_vcc);
1193 #ifdef FORE200E_52BYTE_AAL0_SDU
1194 if ((vcc->qos.aal == ATM_AAL0) && (vcc->qos.rxtp.max_sdu == ATM_AAL0_SDU)) {
1196 cell_header = (rpd->atm_header.gfc << ATM_HDR_GFC_SHIFT) |
1197 (rpd->atm_header.vpi << ATM_HDR_VPI_SHIFT) |
1198 (rpd->atm_header.vci << ATM_HDR_VCI_SHIFT) |
1199 (rpd->atm_header.plt << ATM_HDR_PTI_SHIFT) |
1200 rpd->atm_header.clp;
1205 /* compute total PDU length */
1206 for (i = 0; i < rpd->nseg; i++)
1207 pdu_len += rpd->rsd[ i ].length;
1209 skb = alloc_skb(pdu_len, GFP_ATOMIC);
1211 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
1213 atomic_inc(&vcc->stats->rx_drop);
1217 do_gettimeofday(&skb->stamp);
1219 #ifdef FORE200E_52BYTE_AAL0_SDU
1221 *((u32*)skb_put(skb, 4)) = cell_header;
1225 /* reassemble segments */
1226 for (i = 0; i < rpd->nseg; i++) {
1228 /* rebuild rx buffer address from rsd handle */
1229 buffer = FORE200E_HDL2BUF(rpd->rsd[ i ].handle);
1231 /* Make device DMA transfer visible to CPU. */
1232 fore200e->bus->dma_sync_for_cpu(fore200e, buffer->data.dma_addr, rpd->rsd[ i ].length, DMA_FROM_DEVICE);
1234 memcpy(skb_put(skb, rpd->rsd[ i ].length), buffer->data.align_addr, rpd->rsd[ i ].length);
1236 /* Now let the device get at it again. */
1237 fore200e->bus->dma_sync_for_device(fore200e, buffer->data.dma_addr, rpd->rsd[ i ].length, DMA_FROM_DEVICE);
1240 DPRINTK(3, "rx skb: len = %d, truesize = %d\n", skb->len, skb->truesize);
1242 if (pdu_len < fore200e_vcc->rx_min_pdu)
1243 fore200e_vcc->rx_min_pdu = pdu_len;
1244 if (pdu_len > fore200e_vcc->rx_max_pdu)
1245 fore200e_vcc->rx_max_pdu = pdu_len;
1246 fore200e_vcc->rx_pdu++;
1249 if (atm_charge(vcc, skb->truesize) == 0) {
1251 DPRINTK(2, "receive buffers saturated for %d.%d.%d - PDU dropped\n",
1252 vcc->itf, vcc->vpi, vcc->vci);
1254 dev_kfree_skb_any(skb);
1256 atomic_inc(&vcc->stats->rx_drop);
1260 ASSERT(atomic_read(&vcc->sk->sk_wmem_alloc) >= 0);
1262 vcc->push(vcc, skb);
1263 atomic_inc(&vcc->stats->rx);
1265 ASSERT(atomic_read(&vcc->sk->sk_wmem_alloc) >= 0);
1272 fore200e_collect_rpd(struct fore200e* fore200e, struct rpd* rpd)
1274 struct host_bsq* bsq;
1275 struct buffer* buffer;
1278 for (i = 0; i < rpd->nseg; i++) {
1280 /* rebuild rx buffer address from rsd handle */
1281 buffer = FORE200E_HDL2BUF(rpd->rsd[ i ].handle);
1283 bsq = &fore200e->host_bsq[ buffer->scheme ][ buffer->magn ];
1285 #ifdef FORE200E_BSQ_DEBUG
1286 bsq_audit(2, bsq, buffer->scheme, buffer->magn);
1288 if (buffer->supplied == 0)
1289 printk(FORE200E "queue %d.%d, buffer %ld was not supplied\n",
1290 buffer->scheme, buffer->magn, buffer->index);
1291 buffer->supplied = 0;
1294 /* re-insert the buffer into the free buffer list */
1295 buffer->next = bsq->freebuf;
1296 bsq->freebuf = buffer;
1298 /* then increment the number of free rx buffers */
1299 bsq->freebuf_count++;
1305 fore200e_rx_irq(struct fore200e* fore200e)
1307 struct host_rxq* rxq = &fore200e->host_rxq;
1308 struct host_rxq_entry* entry;
1309 struct atm_vcc* vcc;
1310 struct fore200e_vc_map* vc_map;
1314 entry = &rxq->host_entry[ rxq->head ];
1316 /* no more received PDUs */
1317 if ((*entry->status & STATUS_COMPLETE) == 0)
1320 vc_map = FORE200E_VC_MAP(fore200e, entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
1322 if ((vc_map->vcc == NULL) ||
1323 (test_bit(ATM_VF_READY, &vc_map->vcc->flags) == 0)) {
1325 DPRINTK(1, "no ready VC found for PDU received on %d.%d.%d\n",
1326 fore200e->atm_dev->number,
1327 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
1333 if ((*entry->status & STATUS_ERROR) == 0) {
1335 fore200e_push_rpd(fore200e, vcc, entry->rpd);
1338 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
1339 fore200e->atm_dev->number,
1340 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
1341 atomic_inc(&vcc->stats->rx_err);
1345 FORE200E_NEXT_ENTRY(rxq->head, QUEUE_SIZE_RX);
1347 fore200e_collect_rpd(fore200e, entry->rpd);
1349 /* rewrite the rpd address to ack the received PDU */
1350 fore200e->bus->write(entry->rpd_dma, &entry->cp_entry->rpd_haddr);
1351 *entry->status = STATUS_FREE;
1353 fore200e_supply(fore200e);
1358 #ifndef FORE200E_USE_TASKLET
1360 fore200e_irq(struct fore200e* fore200e)
1362 unsigned long flags;
1364 spin_lock_irqsave(&fore200e->q_lock, flags);
1365 fore200e_rx_irq(fore200e);
1366 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1368 spin_lock_irqsave(&fore200e->q_lock, flags);
1369 fore200e_tx_irq(fore200e);
1370 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1376 fore200e_interrupt(int irq, void* dev, struct pt_regs* regs)
1378 struct fore200e* fore200e = FORE200E_DEV((struct atm_dev*)dev);
1380 if (fore200e->bus->irq_check(fore200e) == 0) {
1382 DPRINTK(3, "interrupt NOT triggered by device %d\n", fore200e->atm_dev->number);
1385 DPRINTK(3, "interrupt triggered by device %d\n", fore200e->atm_dev->number);
1387 #ifdef FORE200E_USE_TASKLET
1388 tasklet_schedule(&fore200e->tx_tasklet);
1389 tasklet_schedule(&fore200e->rx_tasklet);
1391 fore200e_irq(fore200e);
1394 fore200e->bus->irq_ack(fore200e);
1399 #ifdef FORE200E_USE_TASKLET
1401 fore200e_tx_tasklet(unsigned long data)
1403 struct fore200e* fore200e = (struct fore200e*) data;
1404 unsigned long flags;
1406 DPRINTK(3, "tx tasklet scheduled for device %d\n", fore200e->atm_dev->number);
1408 spin_lock_irqsave(&fore200e->q_lock, flags);
1409 fore200e_tx_irq(fore200e);
1410 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1415 fore200e_rx_tasklet(unsigned long data)
1417 struct fore200e* fore200e = (struct fore200e*) data;
1418 unsigned long flags;
1420 DPRINTK(3, "rx tasklet scheduled for device %d\n", fore200e->atm_dev->number);
1422 spin_lock_irqsave(&fore200e->q_lock, flags);
1423 fore200e_rx_irq((struct fore200e*) data);
1424 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1430 fore200e_select_scheme(struct atm_vcc* vcc)
1432 /* fairly balance the VCs over (identical) buffer schemes */
1433 int scheme = vcc->vci % 2 ? BUFFER_SCHEME_ONE : BUFFER_SCHEME_TWO;
1435 DPRINTK(1, "VC %d.%d.%d uses buffer scheme %d\n",
1436 vcc->itf, vcc->vpi, vcc->vci, scheme);
1443 fore200e_activate_vcin(struct fore200e* fore200e, int activate, struct atm_vcc* vcc, int mtu)
1445 struct host_cmdq* cmdq = &fore200e->host_cmdq;
1446 struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
1447 struct activate_opcode activ_opcode;
1448 struct deactivate_opcode deactiv_opcode;
1451 enum fore200e_aal aal = fore200e_atm2fore_aal(vcc->qos.aal);
1453 FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
1456 FORE200E_VCC(vcc)->scheme = fore200e_select_scheme(vcc);
1458 activ_opcode.opcode = OPCODE_ACTIVATE_VCIN;
1459 activ_opcode.aal = aal;
1460 activ_opcode.scheme = FORE200E_VCC(vcc)->scheme;
1461 activ_opcode.pad = 0;
1464 deactiv_opcode.opcode = OPCODE_DEACTIVATE_VCIN;
1465 deactiv_opcode.pad = 0;
1468 vpvc.vci = vcc->vci;
1469 vpvc.vpi = vcc->vpi;
1471 *entry->status = STATUS_PENDING;
1475 #ifdef FORE200E_52BYTE_AAL0_SDU
1478 /* the MTU is not used by the cp, except in the case of AAL0 */
1479 fore200e->bus->write(mtu, &entry->cp_entry->cmd.activate_block.mtu);
1480 fore200e->bus->write(*(u32*)&vpvc, (u32*)&entry->cp_entry->cmd.activate_block.vpvc);
1481 fore200e->bus->write(*(u32*)&activ_opcode, (u32*)&entry->cp_entry->cmd.activate_block.opcode);
1484 fore200e->bus->write(*(u32*)&vpvc, (u32*)&entry->cp_entry->cmd.deactivate_block.vpvc);
1485 fore200e->bus->write(*(u32*)&deactiv_opcode, (u32*)&entry->cp_entry->cmd.deactivate_block.opcode);
1488 ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
1490 *entry->status = STATUS_FREE;
1493 printk(FORE200E "unable to %s VC %d.%d.%d\n",
1494 activate ? "open" : "close", vcc->itf, vcc->vpi, vcc->vci);
1498 DPRINTK(1, "VC %d.%d.%d %sed\n", vcc->itf, vcc->vpi, vcc->vci,
1499 activate ? "open" : "clos");
1505 #define FORE200E_MAX_BACK2BACK_CELLS 255 /* XXX depends on CDVT */
1508 fore200e_rate_ctrl(struct atm_qos* qos, struct tpd_rate* rate)
1510 if (qos->txtp.max_pcr < ATM_OC3_PCR) {
1512 /* compute the data cells to idle cells ratio from the tx PCR */
1513 rate->data_cells = qos->txtp.max_pcr * FORE200E_MAX_BACK2BACK_CELLS / ATM_OC3_PCR;
1514 rate->idle_cells = FORE200E_MAX_BACK2BACK_CELLS - rate->data_cells;
1517 /* disable rate control */
1518 rate->data_cells = rate->idle_cells = 0;
1524 fore200e_open(struct atm_vcc *vcc)
1526 struct fore200e* fore200e = FORE200E_DEV(vcc->dev);
1527 struct fore200e_vcc* fore200e_vcc;
1528 struct fore200e_vc_map* vc_map;
1529 unsigned long flags;
1531 short vpi = vcc->vpi;
1533 ASSERT((vpi >= 0) && (vpi < 1<<FORE200E_VPI_BITS));
1534 ASSERT((vci >= 0) && (vci < 1<<FORE200E_VCI_BITS));
1536 spin_lock_irqsave(&fore200e->q_lock, flags);
1538 vc_map = FORE200E_VC_MAP(fore200e, vpi, vci);
1541 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1543 printk(FORE200E "VC %d.%d.%d already in use\n",
1544 fore200e->atm_dev->number, vpi, vci);
1551 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1553 fore200e_vcc = fore200e_kmalloc(sizeof(struct fore200e_vcc), GFP_ATOMIC);
1554 if (fore200e_vcc == NULL) {
1559 DPRINTK(2, "opening %d.%d.%d:%d QoS = (tx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d; "
1560 "rx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d)\n",
1561 vcc->itf, vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal),
1562 fore200e_traffic_class[ vcc->qos.txtp.traffic_class ],
1563 vcc->qos.txtp.min_pcr, vcc->qos.txtp.max_pcr, vcc->qos.txtp.max_cdv, vcc->qos.txtp.max_sdu,
1564 fore200e_traffic_class[ vcc->qos.rxtp.traffic_class ],
1565 vcc->qos.rxtp.min_pcr, vcc->qos.rxtp.max_pcr, vcc->qos.rxtp.max_cdv, vcc->qos.rxtp.max_sdu);
1567 /* pseudo-CBR bandwidth requested? */
1568 if ((vcc->qos.txtp.traffic_class == ATM_CBR) && (vcc->qos.txtp.max_pcr > 0)) {
1570 down(&fore200e->rate_sf);
1571 if (fore200e->available_cell_rate < vcc->qos.txtp.max_pcr) {
1572 up(&fore200e->rate_sf);
1574 fore200e_kfree(fore200e_vcc);
1579 /* reserve bandwidth */
1580 fore200e->available_cell_rate -= vcc->qos.txtp.max_pcr;
1581 up(&fore200e->rate_sf);
1584 vcc->itf = vcc->dev->number;
1586 set_bit(ATM_VF_PARTIAL,&vcc->flags);
1587 set_bit(ATM_VF_ADDR, &vcc->flags);
1589 vcc->dev_data = fore200e_vcc;
1591 if (fore200e_activate_vcin(fore200e, 1, vcc, vcc->qos.rxtp.max_sdu) < 0) {
1595 clear_bit(ATM_VF_ADDR, &vcc->flags);
1596 clear_bit(ATM_VF_PARTIAL,&vcc->flags);
1598 vcc->dev_data = NULL;
1600 fore200e->available_cell_rate += vcc->qos.txtp.max_pcr;
1602 fore200e_kfree(fore200e_vcc);
1606 /* compute rate control parameters */
1607 if ((vcc->qos.txtp.traffic_class == ATM_CBR) && (vcc->qos.txtp.max_pcr > 0)) {
1609 fore200e_rate_ctrl(&vcc->qos, &fore200e_vcc->rate);
1610 set_bit(ATM_VF_HASQOS, &vcc->flags);
1612 DPRINTK(3, "tx on %d.%d.%d:%d, tx PCR = %d, rx PCR = %d, data_cells = %u, idle_cells = %u\n",
1613 vcc->itf, vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal),
1614 vcc->qos.txtp.max_pcr, vcc->qos.rxtp.max_pcr,
1615 fore200e_vcc->rate.data_cells, fore200e_vcc->rate.idle_cells);
1618 fore200e_vcc->tx_min_pdu = fore200e_vcc->rx_min_pdu = MAX_PDU_SIZE + 1;
1619 fore200e_vcc->tx_max_pdu = fore200e_vcc->rx_max_pdu = 0;
1620 fore200e_vcc->tx_pdu = fore200e_vcc->rx_pdu = 0;
1622 /* new incarnation of the vcc */
1623 vc_map->incarn = ++fore200e->incarn_count;
1625 /* VC unusable before this flag is set */
1626 set_bit(ATM_VF_READY, &vcc->flags);
1633 fore200e_close(struct atm_vcc* vcc)
1635 struct fore200e* fore200e = FORE200E_DEV(vcc->dev);
1636 struct fore200e_vcc* fore200e_vcc;
1637 struct fore200e_vc_map* vc_map;
1638 unsigned long flags;
1641 ASSERT((vcc->vpi >= 0) && (vcc->vpi < 1<<FORE200E_VPI_BITS));
1642 ASSERT((vcc->vci >= 0) && (vcc->vci < 1<<FORE200E_VCI_BITS));
1644 DPRINTK(2, "closing %d.%d.%d:%d\n", vcc->itf, vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal));
1646 clear_bit(ATM_VF_READY, &vcc->flags);
1648 fore200e_activate_vcin(fore200e, 0, vcc, 0);
1650 spin_lock_irqsave(&fore200e->q_lock, flags);
1652 vc_map = FORE200E_VC_MAP(fore200e, vcc->vpi, vcc->vci);
1654 /* the vc is no longer considered as "in use" by fore200e_open() */
1657 vcc->itf = vcc->vci = vcc->vpi = 0;
1659 fore200e_vcc = FORE200E_VCC(vcc);
1660 vcc->dev_data = NULL;
1662 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1664 /* release reserved bandwidth, if any */
1665 if ((vcc->qos.txtp.traffic_class == ATM_CBR) && (vcc->qos.txtp.max_pcr > 0)) {
1667 down(&fore200e->rate_sf);
1668 fore200e->available_cell_rate += vcc->qos.txtp.max_pcr;
1669 up(&fore200e->rate_sf);
1671 clear_bit(ATM_VF_HASQOS, &vcc->flags);
1674 clear_bit(ATM_VF_ADDR, &vcc->flags);
1675 clear_bit(ATM_VF_PARTIAL,&vcc->flags);
1677 ASSERT(fore200e_vcc);
1678 fore200e_kfree(fore200e_vcc);
1683 fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
1685 struct fore200e* fore200e = FORE200E_DEV(vcc->dev);
1686 struct fore200e_vcc* fore200e_vcc = FORE200E_VCC(vcc);
1687 struct fore200e_vc_map* vc_map;
1688 struct host_txq* txq = &fore200e->host_txq;
1689 struct host_txq_entry* entry;
1691 struct tpd_haddr tpd_haddr;
1692 int retry = CONFIG_ATM_FORE200E_TX_RETRY;
1694 int tx_len = skb->len;
1695 u32* cell_header = NULL;
1696 unsigned char* skb_data;
1698 unsigned char* data;
1699 unsigned long flags;
1702 ASSERT(atomic_read(&vcc->sk->sk_wmem_alloc) >= 0);
1704 ASSERT(fore200e_vcc);
1706 if (!test_bit(ATM_VF_READY, &vcc->flags)) {
1707 DPRINTK(1, "VC %d.%d.%d not ready for tx\n", vcc->itf, vcc->vpi, vcc->vpi);
1708 dev_kfree_skb_any(skb);
1712 #ifdef FORE200E_52BYTE_AAL0_SDU
1713 if ((vcc->qos.aal == ATM_AAL0) && (vcc->qos.txtp.max_sdu == ATM_AAL0_SDU)) {
1714 cell_header = (u32*) skb->data;
1715 skb_data = skb->data + 4; /* skip 4-byte cell header */
1716 skb_len = tx_len = skb->len - 4;
1718 DPRINTK(3, "user-supplied cell header = 0x%08x\n", *cell_header);
1723 skb_data = skb->data;
1727 if (((unsigned long)skb_data) & 0x3) {
1729 DPRINTK(2, "misaligned tx PDU on device %s\n", fore200e->name);
1734 if ((vcc->qos.aal == ATM_AAL0) && (skb_len % ATM_CELL_PAYLOAD)) {
1736 /* this simply NUKES the PCA board */
1737 DPRINTK(2, "incomplete tx AAL0 PDU on device %s\n", fore200e->name);
1739 tx_len = ((skb_len / ATM_CELL_PAYLOAD) + 1) * ATM_CELL_PAYLOAD;
1743 data = kmalloc(tx_len, GFP_ATOMIC | GFP_DMA);
1749 dev_kfree_skb_any(skb);
1754 memcpy(data, skb_data, skb_len);
1755 if (skb_len < tx_len)
1756 memset(data + skb_len, 0x00, tx_len - skb_len);
1762 vc_map = FORE200E_VC_MAP(fore200e, vcc->vpi, vcc->vci);
1763 ASSERT(vc_map->vcc == vcc);
1767 spin_lock_irqsave(&fore200e->q_lock, flags);
1769 entry = &txq->host_entry[ txq->head ];
1771 if ((*entry->status != STATUS_FREE) || (txq->txing >= QUEUE_SIZE_TX - 2)) {
1773 /* try to free completed tx queue entries */
1774 fore200e_tx_irq(fore200e);
1776 if (*entry->status != STATUS_FREE) {
1778 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1780 /* retry once again? */
1786 atomic_inc(&vcc->stats->tx_err);
1789 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
1790 fore200e->name, fore200e->cp_queues->heartbeat);
1795 dev_kfree_skb_any(skb);
1805 entry->incarn = vc_map->incarn;
1806 entry->vc_map = vc_map;
1808 entry->data = tx_copy ? data : NULL;
1811 tpd->tsd[ 0 ].buffer = fore200e->bus->dma_map(fore200e, data, tx_len, DMA_TO_DEVICE);
1812 tpd->tsd[ 0 ].length = tx_len;
1814 FORE200E_NEXT_ENTRY(txq->head, QUEUE_SIZE_TX);
1817 /* The dma_map call above implies a dma_sync so the device can use it,
1818 * thus no explicit dma_sync call is necessary here.
1821 DPRINTK(3, "tx on %d.%d.%d:%d, len = %u (%u)\n",
1822 vcc->itf, vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal),
1823 tpd->tsd[0].length, skb_len);
1825 if (skb_len < fore200e_vcc->tx_min_pdu)
1826 fore200e_vcc->tx_min_pdu = skb_len;
1827 if (skb_len > fore200e_vcc->tx_max_pdu)
1828 fore200e_vcc->tx_max_pdu = skb_len;
1829 fore200e_vcc->tx_pdu++;
1831 /* set tx rate control information */
1832 tpd->rate.data_cells = fore200e_vcc->rate.data_cells;
1833 tpd->rate.idle_cells = fore200e_vcc->rate.idle_cells;
1836 tpd->atm_header.clp = (*cell_header & ATM_HDR_CLP);
1837 tpd->atm_header.plt = (*cell_header & ATM_HDR_PTI_MASK) >> ATM_HDR_PTI_SHIFT;
1838 tpd->atm_header.vci = (*cell_header & ATM_HDR_VCI_MASK) >> ATM_HDR_VCI_SHIFT;
1839 tpd->atm_header.vpi = (*cell_header & ATM_HDR_VPI_MASK) >> ATM_HDR_VPI_SHIFT;
1840 tpd->atm_header.gfc = (*cell_header & ATM_HDR_GFC_MASK) >> ATM_HDR_GFC_SHIFT;
1843 /* set the ATM header, common to all cells conveying the PDU */
1844 tpd->atm_header.clp = 0;
1845 tpd->atm_header.plt = 0;
1846 tpd->atm_header.vci = vcc->vci;
1847 tpd->atm_header.vpi = vcc->vpi;
1848 tpd->atm_header.gfc = 0;
1851 tpd->spec.length = tx_len;
1853 tpd->spec.aal = fore200e_atm2fore_aal(vcc->qos.aal);
1856 tpd_haddr.size = sizeof(struct tpd) / (1<<TPD_HADDR_SHIFT); /* size is expressed in 32 byte blocks */
1858 tpd_haddr.haddr = entry->tpd_dma >> TPD_HADDR_SHIFT; /* shift the address, as we are in a bitfield */
1860 *entry->status = STATUS_PENDING;
1861 fore200e->bus->write(*(u32*)&tpd_haddr, (u32*)&entry->cp_entry->tpd_haddr);
1863 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1870 fore200e_getstats(struct fore200e* fore200e)
1872 struct host_cmdq* cmdq = &fore200e->host_cmdq;
1873 struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
1874 struct stats_opcode opcode;
1878 if (fore200e->stats == NULL) {
1879 fore200e->stats = fore200e_kmalloc(sizeof(struct stats), GFP_KERNEL | GFP_DMA);
1880 if (fore200e->stats == NULL)
1884 stats_dma_addr = fore200e->bus->dma_map(fore200e, fore200e->stats,
1885 sizeof(struct stats), DMA_FROM_DEVICE);
1887 FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
1889 opcode.opcode = OPCODE_GET_STATS;
1892 fore200e->bus->write(stats_dma_addr, &entry->cp_entry->cmd.stats_block.stats_haddr);
1894 *entry->status = STATUS_PENDING;
1896 fore200e->bus->write(*(u32*)&opcode, (u32*)&entry->cp_entry->cmd.stats_block.opcode);
1898 ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
1900 *entry->status = STATUS_FREE;
1902 fore200e->bus->dma_unmap(fore200e, stats_dma_addr, sizeof(struct stats), DMA_FROM_DEVICE);
1905 printk(FORE200E "unable to get statistics from device %s\n", fore200e->name);
1914 fore200e_getsockopt(struct atm_vcc* vcc, int level, int optname, void __user *optval, int optlen)
1916 /* struct fore200e* fore200e = FORE200E_DEV(vcc->dev); */
1918 DPRINTK(2, "getsockopt %d.%d.%d, level = %d, optname = 0x%x, optval = 0x%p, optlen = %d\n",
1919 vcc->itf, vcc->vpi, vcc->vci, level, optname, optval, optlen);
1926 fore200e_setsockopt(struct atm_vcc* vcc, int level, int optname, void __user *optval, int optlen)
1928 /* struct fore200e* fore200e = FORE200E_DEV(vcc->dev); */
1930 DPRINTK(2, "setsockopt %d.%d.%d, level = %d, optname = 0x%x, optval = 0x%p, optlen = %d\n",
1931 vcc->itf, vcc->vpi, vcc->vci, level, optname, optval, optlen);
1937 #if 0 /* currently unused */
1939 fore200e_get_oc3(struct fore200e* fore200e, struct oc3_regs* regs)
1941 struct host_cmdq* cmdq = &fore200e->host_cmdq;
1942 struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
1943 struct oc3_opcode opcode;
1945 u32 oc3_regs_dma_addr;
1947 oc3_regs_dma_addr = fore200e->bus->dma_map(fore200e, regs, sizeof(struct oc3_regs), DMA_FROM_DEVICE);
1949 FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
1951 opcode.opcode = OPCODE_GET_OC3;
1956 fore200e->bus->write(oc3_regs_dma_addr, &entry->cp_entry->cmd.oc3_block.regs_haddr);
1958 *entry->status = STATUS_PENDING;
1960 fore200e->bus->write(*(u32*)&opcode, (u32*)&entry->cp_entry->cmd.oc3_block.opcode);
1962 ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
1964 *entry->status = STATUS_FREE;
1966 fore200e->bus->dma_unmap(fore200e, oc3_regs_dma_addr, sizeof(struct oc3_regs), DMA_FROM_DEVICE);
1969 printk(FORE200E "unable to get OC-3 regs of device %s\n", fore200e->name);
1979 fore200e_set_oc3(struct fore200e* fore200e, u32 reg, u32 value, u32 mask)
1981 struct host_cmdq* cmdq = &fore200e->host_cmdq;
1982 struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
1983 struct oc3_opcode opcode;
1986 DPRINTK(2, "set OC-3 reg = 0x%02x, value = 0x%02x, mask = 0x%02x\n", reg, value, mask);
1988 FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
1990 opcode.opcode = OPCODE_SET_OC3;
1992 opcode.value = value;
1995 fore200e->bus->write(0, &entry->cp_entry->cmd.oc3_block.regs_haddr);
1997 *entry->status = STATUS_PENDING;
1999 fore200e->bus->write(*(u32*)&opcode, (u32*)&entry->cp_entry->cmd.oc3_block.opcode);
2001 ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
2003 *entry->status = STATUS_FREE;
2006 printk(FORE200E "unable to set OC-3 reg 0x%02x of device %s\n", reg, fore200e->name);
2015 fore200e_setloop(struct fore200e* fore200e, int loop_mode)
2017 u32 mct_value, mct_mask;
2020 if (!capable(CAP_NET_ADMIN))
2023 switch (loop_mode) {
2027 mct_mask = SUNI_MCT_DLE | SUNI_MCT_LLE;
2030 case ATM_LM_LOC_PHY:
2031 mct_value = mct_mask = SUNI_MCT_DLE;
2034 case ATM_LM_RMT_PHY:
2035 mct_value = mct_mask = SUNI_MCT_LLE;
2042 error = fore200e_set_oc3(fore200e, SUNI_MCT, mct_value, mct_mask);
2044 fore200e->loop_mode = loop_mode;
2050 static inline unsigned int
2051 fore200e_swap(unsigned int in)
2053 #if defined(__LITTLE_ENDIAN)
2062 fore200e_fetch_stats(struct fore200e* fore200e, struct sonet_stats __user *arg)
2064 struct sonet_stats tmp;
2066 if (fore200e_getstats(fore200e) < 0)
2069 tmp.section_bip = fore200e_swap(fore200e->stats->oc3.section_bip8_errors);
2070 tmp.line_bip = fore200e_swap(fore200e->stats->oc3.line_bip24_errors);
2071 tmp.path_bip = fore200e_swap(fore200e->stats->oc3.path_bip8_errors);
2072 tmp.line_febe = fore200e_swap(fore200e->stats->oc3.line_febe_errors);
2073 tmp.path_febe = fore200e_swap(fore200e->stats->oc3.path_febe_errors);
2074 tmp.corr_hcs = fore200e_swap(fore200e->stats->oc3.corr_hcs_errors);
2075 tmp.uncorr_hcs = fore200e_swap(fore200e->stats->oc3.ucorr_hcs_errors);
2076 tmp.tx_cells = fore200e_swap(fore200e->stats->aal0.cells_transmitted) +
2077 fore200e_swap(fore200e->stats->aal34.cells_transmitted) +
2078 fore200e_swap(fore200e->stats->aal5.cells_transmitted);
2079 tmp.rx_cells = fore200e_swap(fore200e->stats->aal0.cells_received) +
2080 fore200e_swap(fore200e->stats->aal34.cells_received) +
2081 fore200e_swap(fore200e->stats->aal5.cells_received);
2084 return copy_to_user(arg, &tmp, sizeof(struct sonet_stats)) ? -EFAULT : 0;
2091 fore200e_ioctl(struct atm_dev* dev, unsigned int cmd, void __user * arg)
2093 struct fore200e* fore200e = FORE200E_DEV(dev);
2095 DPRINTK(2, "ioctl cmd = 0x%x (%u), arg = 0x%p (%lu)\n", cmd, cmd, arg, (unsigned long)arg);
2100 return fore200e_fetch_stats(fore200e, (struct sonet_stats __user *)arg);
2103 return put_user(0, (int __user *)arg) ? -EFAULT : 0;
2106 return fore200e_setloop(fore200e, (int)(unsigned long)arg);
2109 return put_user(fore200e->loop_mode, (int __user *)arg) ? -EFAULT : 0;
2112 return put_user(ATM_LM_LOC_PHY | ATM_LM_RMT_PHY, (int __user *)arg) ? -EFAULT : 0;
2115 return -ENOSYS; /* not implemented */
2120 fore200e_change_qos(struct atm_vcc* vcc,struct atm_qos* qos, int flags)
2122 struct fore200e_vcc* fore200e_vcc = FORE200E_VCC(vcc);
2123 struct fore200e* fore200e = FORE200E_DEV(vcc->dev);
2125 if (!test_bit(ATM_VF_READY, &vcc->flags)) {
2126 DPRINTK(1, "VC %d.%d.%d not ready for QoS change\n", vcc->itf, vcc->vpi, vcc->vpi);
2130 DPRINTK(2, "change_qos %d.%d.%d, "
2131 "(tx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d; "
2132 "rx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d), flags = 0x%x\n"
2133 "available_cell_rate = %u",
2134 vcc->itf, vcc->vpi, vcc->vci,
2135 fore200e_traffic_class[ qos->txtp.traffic_class ],
2136 qos->txtp.min_pcr, qos->txtp.max_pcr, qos->txtp.max_cdv, qos->txtp.max_sdu,
2137 fore200e_traffic_class[ qos->rxtp.traffic_class ],
2138 qos->rxtp.min_pcr, qos->rxtp.max_pcr, qos->rxtp.max_cdv, qos->rxtp.max_sdu,
2139 flags, fore200e->available_cell_rate);
2141 if ((qos->txtp.traffic_class == ATM_CBR) && (qos->txtp.max_pcr > 0)) {
2143 down(&fore200e->rate_sf);
2144 if (fore200e->available_cell_rate + vcc->qos.txtp.max_pcr < qos->txtp.max_pcr) {
2145 up(&fore200e->rate_sf);
2149 fore200e->available_cell_rate += vcc->qos.txtp.max_pcr;
2150 fore200e->available_cell_rate -= qos->txtp.max_pcr;
2152 up(&fore200e->rate_sf);
2154 memcpy(&vcc->qos, qos, sizeof(struct atm_qos));
2156 /* update rate control parameters */
2157 fore200e_rate_ctrl(qos, &fore200e_vcc->rate);
2159 set_bit(ATM_VF_HASQOS, &vcc->flags);
2169 fore200e_irq_request(struct fore200e* fore200e)
2171 if (request_irq(fore200e->irq, fore200e_interrupt, SA_SHIRQ, fore200e->name, fore200e->atm_dev) < 0) {
2173 printk(FORE200E "unable to reserve IRQ %s for device %s\n",
2174 fore200e_irq_itoa(fore200e->irq), fore200e->name);
2178 printk(FORE200E "IRQ %s reserved for device %s\n",
2179 fore200e_irq_itoa(fore200e->irq), fore200e->name);
2181 #ifdef FORE200E_USE_TASKLET
2182 tasklet_init(&fore200e->tx_tasklet, fore200e_tx_tasklet, (unsigned long)fore200e);
2183 tasklet_init(&fore200e->rx_tasklet, fore200e_rx_tasklet, (unsigned long)fore200e);
2186 fore200e->state = FORE200E_STATE_IRQ;
2192 fore200e_get_esi(struct fore200e* fore200e)
2194 struct prom_data* prom = fore200e_kmalloc(sizeof(struct prom_data), GFP_KERNEL | GFP_DMA);
2200 ok = fore200e->bus->prom_read(fore200e, prom);
2202 fore200e_kfree(prom);
2206 printk(FORE200E "device %s, rev. %c, S/N: %d, ESI: %02x:%02x:%02x:%02x:%02x:%02x\n",
2208 (prom->hw_revision & 0xFF) + '@', /* probably meaningless with SBA boards */
2209 prom->serial_number & 0xFFFF,
2210 prom->mac_addr[ 2 ], prom->mac_addr[ 3 ], prom->mac_addr[ 4 ],
2211 prom->mac_addr[ 5 ], prom->mac_addr[ 6 ], prom->mac_addr[ 7 ]);
2213 for (i = 0; i < ESI_LEN; i++) {
2214 fore200e->esi[ i ] = fore200e->atm_dev->esi[ i ] = prom->mac_addr[ i + 2 ];
2217 fore200e_kfree(prom);
2224 fore200e_alloc_rx_buf(struct fore200e* fore200e)
2226 int scheme, magn, nbr, size, i;
2228 struct host_bsq* bsq;
2229 struct buffer* buffer;
2231 for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
2232 for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
2234 bsq = &fore200e->host_bsq[ scheme ][ magn ];
2236 nbr = fore200e_rx_buf_nbr[ scheme ][ magn ];
2237 size = fore200e_rx_buf_size[ scheme ][ magn ];
2239 DPRINTK(2, "rx buffers %d / %d are being allocated\n", scheme, magn);
2241 /* allocate the array of receive buffers */
2242 buffer = bsq->buffer = fore200e_kmalloc(nbr * sizeof(struct buffer), GFP_KERNEL);
2247 bsq->freebuf = NULL;
2249 for (i = 0; i < nbr; i++) {
2251 buffer[ i ].scheme = scheme;
2252 buffer[ i ].magn = magn;
2253 #ifdef FORE200E_BSQ_DEBUG
2254 buffer[ i ].index = i;
2255 buffer[ i ].supplied = 0;
2258 /* allocate the receive buffer body */
2259 if (fore200e_chunk_alloc(fore200e,
2260 &buffer[ i ].data, size, fore200e->bus->buffer_alignment,
2261 DMA_FROM_DEVICE) < 0) {
2264 fore200e_chunk_free(fore200e, &buffer[ --i ].data);
2265 fore200e_kfree(buffer);
2270 /* insert the buffer into the free buffer list */
2271 buffer[ i ].next = bsq->freebuf;
2272 bsq->freebuf = &buffer[ i ];
2274 /* all the buffers are free, initially */
2275 bsq->freebuf_count = nbr;
2277 #ifdef FORE200E_BSQ_DEBUG
2278 bsq_audit(3, bsq, scheme, magn);
2283 fore200e->state = FORE200E_STATE_ALLOC_BUF;
2289 fore200e_init_bs_queue(struct fore200e* fore200e)
2291 int scheme, magn, i;
2293 struct host_bsq* bsq;
2294 struct cp_bsq_entry* cp_entry;
2296 for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
2297 for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
2299 DPRINTK(2, "buffer supply queue %d / %d is being initialized\n", scheme, magn);
2301 bsq = &fore200e->host_bsq[ scheme ][ magn ];
2303 /* allocate and align the array of status words */
2304 if (fore200e->bus->dma_chunk_alloc(fore200e,
2306 sizeof(enum status),
2308 fore200e->bus->status_alignment) < 0) {
2312 /* allocate and align the array of receive buffer descriptors */
2313 if (fore200e->bus->dma_chunk_alloc(fore200e,
2315 sizeof(struct rbd_block),
2317 fore200e->bus->descr_alignment) < 0) {
2319 fore200e->bus->dma_chunk_free(fore200e, &bsq->status);
2323 /* get the base address of the cp resident buffer supply queue entries */
2324 cp_entry = (struct cp_bsq_entry*)(fore200e->virt_base +
2325 fore200e->bus->read(&fore200e->cp_queues->cp_bsq[ scheme ][ magn ]));
2327 /* fill the host resident and cp resident buffer supply queue entries */
2328 for (i = 0; i < QUEUE_SIZE_BS; i++) {
2330 bsq->host_entry[ i ].status =
2331 FORE200E_INDEX(bsq->status.align_addr, enum status, i);
2332 bsq->host_entry[ i ].rbd_block =
2333 FORE200E_INDEX(bsq->rbd_block.align_addr, struct rbd_block, i);
2334 bsq->host_entry[ i ].rbd_block_dma =
2335 FORE200E_DMA_INDEX(bsq->rbd_block.dma_addr, struct rbd_block, i);
2336 bsq->host_entry[ i ].cp_entry = &cp_entry[ i ];
2338 *bsq->host_entry[ i ].status = STATUS_FREE;
2340 fore200e->bus->write(FORE200E_DMA_INDEX(bsq->status.dma_addr, enum status, i),
2341 &cp_entry[ i ].status_haddr);
2346 fore200e->state = FORE200E_STATE_INIT_BSQ;
2352 fore200e_init_rx_queue(struct fore200e* fore200e)
2354 struct host_rxq* rxq = &fore200e->host_rxq;
2355 struct cp_rxq_entry* cp_entry;
2358 DPRINTK(2, "receive queue is being initialized\n");
2360 /* allocate and align the array of status words */
2361 if (fore200e->bus->dma_chunk_alloc(fore200e,
2363 sizeof(enum status),
2365 fore200e->bus->status_alignment) < 0) {
2369 /* allocate and align the array of receive PDU descriptors */
2370 if (fore200e->bus->dma_chunk_alloc(fore200e,
2374 fore200e->bus->descr_alignment) < 0) {
2376 fore200e->bus->dma_chunk_free(fore200e, &rxq->status);
2380 /* get the base address of the cp resident rx queue entries */
2381 cp_entry = (struct cp_rxq_entry*)(fore200e->virt_base +
2382 fore200e->bus->read(&fore200e->cp_queues->cp_rxq));
2384 /* fill the host resident and cp resident rx entries */
2385 for (i=0; i < QUEUE_SIZE_RX; i++) {
2387 rxq->host_entry[ i ].status =
2388 FORE200E_INDEX(rxq->status.align_addr, enum status, i);
2389 rxq->host_entry[ i ].rpd =
2390 FORE200E_INDEX(rxq->rpd.align_addr, struct rpd, i);
2391 rxq->host_entry[ i ].rpd_dma =
2392 FORE200E_DMA_INDEX(rxq->rpd.dma_addr, struct rpd, i);
2393 rxq->host_entry[ i ].cp_entry = &cp_entry[ i ];
2395 *rxq->host_entry[ i ].status = STATUS_FREE;
2397 fore200e->bus->write(FORE200E_DMA_INDEX(rxq->status.dma_addr, enum status, i),
2398 &cp_entry[ i ].status_haddr);
2400 fore200e->bus->write(FORE200E_DMA_INDEX(rxq->rpd.dma_addr, struct rpd, i),
2401 &cp_entry[ i ].rpd_haddr);
2404 /* set the head entry of the queue */
2407 fore200e->state = FORE200E_STATE_INIT_RXQ;
2413 fore200e_init_tx_queue(struct fore200e* fore200e)
2415 struct host_txq* txq = &fore200e->host_txq;
2416 struct cp_txq_entry* cp_entry;
2419 DPRINTK(2, "transmit queue is being initialized\n");
2421 /* allocate and align the array of status words */
2422 if (fore200e->bus->dma_chunk_alloc(fore200e,
2424 sizeof(enum status),
2426 fore200e->bus->status_alignment) < 0) {
2430 /* allocate and align the array of transmit PDU descriptors */
2431 if (fore200e->bus->dma_chunk_alloc(fore200e,
2435 fore200e->bus->descr_alignment) < 0) {
2437 fore200e->bus->dma_chunk_free(fore200e, &txq->status);
2441 /* get the base address of the cp resident tx queue entries */
2442 cp_entry = (struct cp_txq_entry*)(fore200e->virt_base +
2443 fore200e->bus->read(&fore200e->cp_queues->cp_txq));
2445 /* fill the host resident and cp resident tx entries */
2446 for (i=0; i < QUEUE_SIZE_TX; i++) {
2448 txq->host_entry[ i ].status =
2449 FORE200E_INDEX(txq->status.align_addr, enum status, i);
2450 txq->host_entry[ i ].tpd =
2451 FORE200E_INDEX(txq->tpd.align_addr, struct tpd, i);
2452 txq->host_entry[ i ].tpd_dma =
2453 FORE200E_DMA_INDEX(txq->tpd.dma_addr, struct tpd, i);
2454 txq->host_entry[ i ].cp_entry = &cp_entry[ i ];
2456 *txq->host_entry[ i ].status = STATUS_FREE;
2458 fore200e->bus->write(FORE200E_DMA_INDEX(txq->status.dma_addr, enum status, i),
2459 &cp_entry[ i ].status_haddr);
2461 /* although there is a one-to-one mapping of tx queue entries and tpds,
2462 we do not write here the DMA (physical) base address of each tpd into
2463 the related cp resident entry, because the cp relies on this write
2464 operation to detect that a new pdu has been submitted for tx */
2467 /* set the head and tail entries of the queue */
2471 fore200e->state = FORE200E_STATE_INIT_TXQ;
2477 fore200e_init_cmd_queue(struct fore200e* fore200e)
2479 struct host_cmdq* cmdq = &fore200e->host_cmdq;
2480 struct cp_cmdq_entry* cp_entry;
2483 DPRINTK(2, "command queue is being initialized\n");
2485 /* allocate and align the array of status words */
2486 if (fore200e->bus->dma_chunk_alloc(fore200e,
2488 sizeof(enum status),
2490 fore200e->bus->status_alignment) < 0) {
2494 /* get the base address of the cp resident cmd queue entries */
2495 cp_entry = (struct cp_cmdq_entry*)(fore200e->virt_base +
2496 fore200e->bus->read(&fore200e->cp_queues->cp_cmdq));
2498 /* fill the host resident and cp resident cmd entries */
2499 for (i=0; i < QUEUE_SIZE_CMD; i++) {
2501 cmdq->host_entry[ i ].status =
2502 FORE200E_INDEX(cmdq->status.align_addr, enum status, i);
2503 cmdq->host_entry[ i ].cp_entry = &cp_entry[ i ];
2505 *cmdq->host_entry[ i ].status = STATUS_FREE;
2507 fore200e->bus->write(FORE200E_DMA_INDEX(cmdq->status.dma_addr, enum status, i),
2508 &cp_entry[ i ].status_haddr);
2511 /* set the head entry of the queue */
2514 fore200e->state = FORE200E_STATE_INIT_CMDQ;
2520 fore200e_param_bs_queue(struct fore200e* fore200e,
2521 enum buffer_scheme scheme, enum buffer_magn magn,
2522 int queue_length, int pool_size, int supply_blksize)
2524 struct bs_spec* bs_spec = &fore200e->cp_queues->init.bs_spec[ scheme ][ magn ];
2526 fore200e->bus->write(queue_length, &bs_spec->queue_length);
2527 fore200e->bus->write(fore200e_rx_buf_size[ scheme ][ magn ], &bs_spec->buffer_size);
2528 fore200e->bus->write(pool_size, &bs_spec->pool_size);
2529 fore200e->bus->write(supply_blksize, &bs_spec->supply_blksize);
2534 fore200e_initialize(struct fore200e* fore200e)
2536 struct cp_queues* cpq;
2537 int ok, scheme, magn;
2539 DPRINTK(2, "device %s being initialized\n", fore200e->name);
2541 init_MUTEX(&fore200e->rate_sf);
2542 spin_lock_init(&fore200e->q_lock);
2544 cpq = fore200e->cp_queues = (struct cp_queues*) (fore200e->virt_base + FORE200E_CP_QUEUES_OFFSET);
2546 /* enable cp to host interrupts */
2547 fore200e->bus->write(1, &cpq->imask);
2549 if (fore200e->bus->irq_enable)
2550 fore200e->bus->irq_enable(fore200e);
2552 fore200e->bus->write(NBR_CONNECT, &cpq->init.num_connect);
2554 fore200e->bus->write(QUEUE_SIZE_CMD, &cpq->init.cmd_queue_len);
2555 fore200e->bus->write(QUEUE_SIZE_RX, &cpq->init.rx_queue_len);
2556 fore200e->bus->write(QUEUE_SIZE_TX, &cpq->init.tx_queue_len);
2558 fore200e->bus->write(RSD_EXTENSION, &cpq->init.rsd_extension);
2559 fore200e->bus->write(TSD_EXTENSION, &cpq->init.tsd_extension);
2561 for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++)
2562 for (magn = 0; magn < BUFFER_MAGN_NBR; magn++)
2563 fore200e_param_bs_queue(fore200e, scheme, magn,
2565 fore200e_rx_buf_nbr[ scheme ][ magn ],
2568 /* issue the initialize command */
2569 fore200e->bus->write(STATUS_PENDING, &cpq->init.status);
2570 fore200e->bus->write(OPCODE_INITIALIZE, &cpq->init.opcode);
2572 ok = fore200e_io_poll(fore200e, &cpq->init.status, STATUS_COMPLETE, 3000);
2574 printk(FORE200E "device %s initialization failed\n", fore200e->name);
2578 printk(FORE200E "device %s initialized\n", fore200e->name);
2580 fore200e->state = FORE200E_STATE_INITIALIZE;
2586 fore200e_monitor_putc(struct fore200e* fore200e, char c)
2588 struct cp_monitor* monitor = fore200e->cp_monitor;
2593 fore200e->bus->write(((u32) c) | FORE200E_CP_MONITOR_UART_AVAIL, &monitor->soft_uart.send);
2598 fore200e_monitor_getc(struct fore200e* fore200e)
2600 struct cp_monitor* monitor = fore200e->cp_monitor;
2601 unsigned long timeout = jiffies + MSECS(50);
2604 while (time_before(jiffies, timeout)) {
2606 c = (int) fore200e->bus->read(&monitor->soft_uart.recv);
2608 if (c & FORE200E_CP_MONITOR_UART_AVAIL) {
2610 fore200e->bus->write(FORE200E_CP_MONITOR_UART_FREE, &monitor->soft_uart.recv);
2612 printk("%c", c & 0xFF);
2623 fore200e_monitor_puts(struct fore200e* fore200e, char* str)
2627 /* the i960 monitor doesn't accept any new character if it has something to say */
2628 while (fore200e_monitor_getc(fore200e) >= 0);
2630 fore200e_monitor_putc(fore200e, *str++);
2633 while (fore200e_monitor_getc(fore200e) >= 0);
2638 fore200e_start_fw(struct fore200e* fore200e)
2642 struct fw_header* fw_header = (struct fw_header*) fore200e->bus->fw_data;
2644 DPRINTK(2, "device %s firmware being started\n", fore200e->name);
2646 #if defined(__sparc_v9__)
2647 /* reported to be required by SBA cards on some sparc64 hosts */
2651 sprintf(cmd, "\rgo %x\r", le32_to_cpu(fw_header->start_offset));
2653 fore200e_monitor_puts(fore200e, cmd);
2655 ok = fore200e_io_poll(fore200e, &fore200e->cp_monitor->bstat, BSTAT_CP_RUNNING, 1000);
2657 printk(FORE200E "device %s firmware didn't start\n", fore200e->name);
2661 printk(FORE200E "device %s firmware started\n", fore200e->name);
2663 fore200e->state = FORE200E_STATE_START_FW;
2669 fore200e_load_fw(struct fore200e* fore200e)
2671 u32* fw_data = (u32*) fore200e->bus->fw_data;
2672 u32 fw_size = (u32) *fore200e->bus->fw_size / sizeof(u32);
2674 struct fw_header* fw_header = (struct fw_header*) fw_data;
2676 u32* load_addr = fore200e->virt_base + le32_to_cpu(fw_header->load_offset);
2678 DPRINTK(2, "device %s firmware being loaded at 0x%p (%d words)\n",
2679 fore200e->name, load_addr, fw_size);
2681 if (le32_to_cpu(fw_header->magic) != FW_HEADER_MAGIC) {
2682 printk(FORE200E "corrupted %s firmware image\n", fore200e->bus->model_name);
2686 for (; fw_size--; fw_data++, load_addr++)
2687 fore200e->bus->write(le32_to_cpu(*fw_data), load_addr);
2689 fore200e->state = FORE200E_STATE_LOAD_FW;
2695 fore200e_register(struct fore200e* fore200e)
2697 struct atm_dev* atm_dev;
2699 DPRINTK(2, "device %s being registered\n", fore200e->name);
2701 atm_dev = atm_dev_register(fore200e->bus->proc_name, &fore200e_ops, -1,
2703 if (atm_dev == NULL) {
2704 printk(FORE200E "unable to register device %s\n", fore200e->name);
2708 atm_dev->dev_data = fore200e;
2709 fore200e->atm_dev = atm_dev;
2711 atm_dev->ci_range.vpi_bits = FORE200E_VPI_BITS;
2712 atm_dev->ci_range.vci_bits = FORE200E_VCI_BITS;
2714 fore200e->available_cell_rate = ATM_OC3_PCR;
2716 fore200e->state = FORE200E_STATE_REGISTER;
2722 fore200e_init(struct fore200e* fore200e)
2724 if (fore200e_register(fore200e) < 0)
2727 if (fore200e->bus->configure(fore200e) < 0)
2730 if (fore200e->bus->map(fore200e) < 0)
2733 if (fore200e_reset(fore200e, 1) < 0)
2736 if (fore200e_load_fw(fore200e) < 0)
2739 if (fore200e_start_fw(fore200e) < 0)
2742 if (fore200e_initialize(fore200e) < 0)
2745 if (fore200e_init_cmd_queue(fore200e) < 0)
2748 if (fore200e_init_tx_queue(fore200e) < 0)
2751 if (fore200e_init_rx_queue(fore200e) < 0)
2754 if (fore200e_init_bs_queue(fore200e) < 0)
2757 if (fore200e_alloc_rx_buf(fore200e) < 0)
2760 if (fore200e_get_esi(fore200e) < 0)
2763 if (fore200e_irq_request(fore200e) < 0)
2766 fore200e_supply(fore200e);
2768 /* all done, board initialization is now complete */
2769 fore200e->state = FORE200E_STATE_COMPLETE;
2774 fore200e_module_init(void)
2776 const struct fore200e_bus* bus;
2777 struct fore200e* fore200e;
2780 printk(FORE200E "FORE Systems 200E-series ATM driver - version " FORE200E_VERSION "\n");
2782 /* for each configured bus interface */
2783 for (link = 0, bus = fore200e_bus; bus->model_name; bus++) {
2785 /* detect all boards present on that bus */
2786 for (index = 0; (fore200e = bus->detect(bus, index)); index++) {
2788 printk(FORE200E "device %s found at 0x%lx, IRQ %s\n",
2789 fore200e->bus->model_name,
2790 fore200e->phys_base, fore200e_irq_itoa(fore200e->irq));
2792 sprintf(fore200e->name, "%s-%d", bus->model_name, index);
2794 if (fore200e_init(fore200e) < 0) {
2796 fore200e_shutdown(fore200e);
2802 fore200e->next = fore200e_boards;
2803 fore200e_boards = fore200e;
2814 fore200e_module_cleanup(void)
2816 while (fore200e_boards) {
2817 struct fore200e* fore200e = fore200e_boards;
2819 fore200e_shutdown(fore200e);
2820 fore200e_boards = fore200e->next;
2823 DPRINTK(1, "module being removed\n");
2828 fore200e_proc_read(struct atm_dev *dev, loff_t* pos, char* page)
2830 struct fore200e* fore200e = FORE200E_DEV(dev);
2831 struct fore200e_vcc* fore200e_vcc;
2832 struct atm_vcc* vcc;
2833 int i, len, left = *pos;
2834 unsigned long flags;
2838 if (fore200e_getstats(fore200e) < 0)
2841 len = sprintf(page,"\n"
2843 " internal name:\t\t%s\n", fore200e->name);
2845 /* print bus-specific information */
2846 if (fore200e->bus->proc_read)
2847 len += fore200e->bus->proc_read(fore200e, page + len);
2849 len += sprintf(page + len,
2850 " interrupt line:\t\t%s\n"
2851 " physical base address:\t0x%p\n"
2852 " virtual base address:\t0x%p\n"
2853 " factory address (ESI):\t%02x:%02x:%02x:%02x:%02x:%02x\n"
2854 " board serial number:\t\t%d\n\n",
2855 fore200e_irq_itoa(fore200e->irq),
2856 (void*)fore200e->phys_base,
2857 (void*)fore200e->virt_base,
2858 fore200e->esi[0], fore200e->esi[1], fore200e->esi[2],
2859 fore200e->esi[3], fore200e->esi[4], fore200e->esi[5],
2860 fore200e->esi[4] * 256 + fore200e->esi[5]);
2866 return sprintf(page,
2867 " free small bufs, scheme 1:\t%d\n"
2868 " free large bufs, scheme 1:\t%d\n"
2869 " free small bufs, scheme 2:\t%d\n"
2870 " free large bufs, scheme 2:\t%d\n",
2871 fore200e->host_bsq[ BUFFER_SCHEME_ONE ][ BUFFER_MAGN_SMALL ].freebuf_count,
2872 fore200e->host_bsq[ BUFFER_SCHEME_ONE ][ BUFFER_MAGN_LARGE ].freebuf_count,
2873 fore200e->host_bsq[ BUFFER_SCHEME_TWO ][ BUFFER_MAGN_SMALL ].freebuf_count,
2874 fore200e->host_bsq[ BUFFER_SCHEME_TWO ][ BUFFER_MAGN_LARGE ].freebuf_count);
2877 u32 hb = fore200e->bus->read(&fore200e->cp_queues->heartbeat);
2879 len = sprintf(page,"\n\n"
2880 " cell processor:\n"
2881 " heartbeat state:\t\t");
2883 if (hb >> 16 != 0xDEAD)
2884 len += sprintf(page + len, "0x%08x\n", hb);
2886 len += sprintf(page + len, "*** FATAL ERROR %04x ***\n", hb & 0xFFFF);
2892 static const char* media_name[] = {
2893 "unshielded twisted pair",
2894 "multimode optical fiber ST",
2895 "multimode optical fiber SC",
2896 "single-mode optical fiber ST",
2897 "single-mode optical fiber SC",
2901 static const char* oc3_mode[] = {
2903 "diagnostic loopback",
2908 u32 fw_release = fore200e->bus->read(&fore200e->cp_queues->fw_release);
2909 u32 mon960_release = fore200e->bus->read(&fore200e->cp_queues->mon960_release);
2910 u32 oc3_revision = fore200e->bus->read(&fore200e->cp_queues->oc3_revision);
2911 u32 media_index = FORE200E_MEDIA_INDEX(fore200e->bus->read(&fore200e->cp_queues->media_type));
2914 if ((media_index < 0) || (media_index > 4))
2917 switch (fore200e->loop_mode) {
2918 case ATM_LM_NONE: oc3_index = 0;
2920 case ATM_LM_LOC_PHY: oc3_index = 1;
2922 case ATM_LM_RMT_PHY: oc3_index = 2;
2924 default: oc3_index = 3;
2927 return sprintf(page,
2928 " firmware release:\t\t%d.%d.%d\n"
2929 " monitor release:\t\t%d.%d\n"
2930 " media type:\t\t\t%s\n"
2931 " OC-3 revision:\t\t0x%x\n"
2932 " OC-3 mode:\t\t\t%s",
2933 fw_release >> 16, fw_release << 16 >> 24, fw_release << 24 >> 24,
2934 mon960_release >> 16, mon960_release << 16 >> 16,
2935 media_name[ media_index ],
2937 oc3_mode[ oc3_index ]);
2941 struct cp_monitor* cp_monitor = fore200e->cp_monitor;
2943 return sprintf(page,
2946 " version number:\t\t%d\n"
2947 " boot status word:\t\t0x%08x\n",
2948 fore200e->bus->read(&cp_monitor->mon_version),
2949 fore200e->bus->read(&cp_monitor->bstat));
2953 return sprintf(page,
2955 " device statistics:\n"
2957 " crc_header_errors:\t\t%10u\n"
2958 " framing_errors:\t\t%10u\n",
2959 fore200e_swap(fore200e->stats->phy.crc_header_errors),
2960 fore200e_swap(fore200e->stats->phy.framing_errors));
2963 return sprintf(page, "\n"
2965 " section_bip8_errors:\t%10u\n"
2966 " path_bip8_errors:\t\t%10u\n"
2967 " line_bip24_errors:\t\t%10u\n"
2968 " line_febe_errors:\t\t%10u\n"
2969 " path_febe_errors:\t\t%10u\n"
2970 " corr_hcs_errors:\t\t%10u\n"
2971 " ucorr_hcs_errors:\t\t%10u\n",
2972 fore200e_swap(fore200e->stats->oc3.section_bip8_errors),
2973 fore200e_swap(fore200e->stats->oc3.path_bip8_errors),
2974 fore200e_swap(fore200e->stats->oc3.line_bip24_errors),
2975 fore200e_swap(fore200e->stats->oc3.line_febe_errors),
2976 fore200e_swap(fore200e->stats->oc3.path_febe_errors),
2977 fore200e_swap(fore200e->stats->oc3.corr_hcs_errors),
2978 fore200e_swap(fore200e->stats->oc3.ucorr_hcs_errors));
2981 return sprintf(page,"\n"
2982 " ATM:\t\t\t\t cells\n"
2985 " vpi out of range:\t\t%10u\n"
2986 " vpi no conn:\t\t%10u\n"
2987 " vci out of range:\t\t%10u\n"
2988 " vci no conn:\t\t%10u\n",
2989 fore200e_swap(fore200e->stats->atm.cells_transmitted),
2990 fore200e_swap(fore200e->stats->atm.cells_received),
2991 fore200e_swap(fore200e->stats->atm.vpi_bad_range),
2992 fore200e_swap(fore200e->stats->atm.vpi_no_conn),
2993 fore200e_swap(fore200e->stats->atm.vci_bad_range),
2994 fore200e_swap(fore200e->stats->atm.vci_no_conn));
2997 return sprintf(page,"\n"
2998 " AAL0:\t\t\t cells\n"
3001 " dropped:\t\t\t%10u\n",
3002 fore200e_swap(fore200e->stats->aal0.cells_transmitted),
3003 fore200e_swap(fore200e->stats->aal0.cells_received),
3004 fore200e_swap(fore200e->stats->aal0.cells_dropped));
3007 return sprintf(page,"\n"
3009 " SAR sublayer:\t\t cells\n"
3012 " dropped:\t\t\t%10u\n"
3013 " CRC errors:\t\t%10u\n"
3014 " protocol errors:\t\t%10u\n\n"
3015 " CS sublayer:\t\t PDUs\n"
3018 " dropped:\t\t\t%10u\n"
3019 " protocol errors:\t\t%10u\n",
3020 fore200e_swap(fore200e->stats->aal34.cells_transmitted),
3021 fore200e_swap(fore200e->stats->aal34.cells_received),
3022 fore200e_swap(fore200e->stats->aal34.cells_dropped),
3023 fore200e_swap(fore200e->stats->aal34.cells_crc_errors),
3024 fore200e_swap(fore200e->stats->aal34.cells_protocol_errors),
3025 fore200e_swap(fore200e->stats->aal34.cspdus_transmitted),
3026 fore200e_swap(fore200e->stats->aal34.cspdus_received),
3027 fore200e_swap(fore200e->stats->aal34.cspdus_dropped),
3028 fore200e_swap(fore200e->stats->aal34.cspdus_protocol_errors));
3031 return sprintf(page,"\n"
3033 " SAR sublayer:\t\t cells\n"
3036 " dropped:\t\t\t%10u\n"
3037 " congestions:\t\t%10u\n\n"
3038 " CS sublayer:\t\t PDUs\n"
3041 " dropped:\t\t\t%10u\n"
3042 " CRC errors:\t\t%10u\n"
3043 " protocol errors:\t\t%10u\n",
3044 fore200e_swap(fore200e->stats->aal5.cells_transmitted),
3045 fore200e_swap(fore200e->stats->aal5.cells_received),
3046 fore200e_swap(fore200e->stats->aal5.cells_dropped),
3047 fore200e_swap(fore200e->stats->aal5.congestion_experienced),
3048 fore200e_swap(fore200e->stats->aal5.cspdus_transmitted),
3049 fore200e_swap(fore200e->stats->aal5.cspdus_received),
3050 fore200e_swap(fore200e->stats->aal5.cspdus_dropped),
3051 fore200e_swap(fore200e->stats->aal5.cspdus_crc_errors),
3052 fore200e_swap(fore200e->stats->aal5.cspdus_protocol_errors));
3055 return sprintf(page,"\n"
3056 " AUX:\t\t allocation failures\n"
3057 " small b1:\t\t\t%10u\n"
3058 " large b1:\t\t\t%10u\n"
3059 " small b2:\t\t\t%10u\n"
3060 " large b2:\t\t\t%10u\n"
3061 " RX PDUs:\t\t\t%10u\n"
3062 " TX PDUs:\t\t\t%10lu\n",
3063 fore200e_swap(fore200e->stats->aux.small_b1_failed),
3064 fore200e_swap(fore200e->stats->aux.large_b1_failed),
3065 fore200e_swap(fore200e->stats->aux.small_b2_failed),
3066 fore200e_swap(fore200e->stats->aux.large_b2_failed),
3067 fore200e_swap(fore200e->stats->aux.rpd_alloc_failed),
3071 return sprintf(page,"\n"
3072 " receive carrier:\t\t\t%s\n",
3073 fore200e->stats->aux.receive_carrier ? "ON" : "OFF!");
3076 return sprintf(page,"\n"
3077 " VCCs:\n address VPI VCI AAL "
3078 "TX PDUs TX min/max size RX PDUs RX min/max size\n");
3081 for (i = 0; i < NBR_CONNECT; i++) {
3083 vcc = fore200e->vc_map[i].vcc;
3088 spin_lock_irqsave(&fore200e->q_lock, flags);
3090 if (vcc && test_bit(ATM_VF_READY, &vcc->flags) && !left--) {
3092 fore200e_vcc = FORE200E_VCC(vcc);
3093 ASSERT(fore200e_vcc);
3096 " %08x %03d %05d %1d %09lu %05d/%05d %09lu %05d/%05d\n",
3097 (u32)(unsigned long)vcc,
3098 vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal),
3099 fore200e_vcc->tx_pdu,
3100 fore200e_vcc->tx_min_pdu > 0xFFFF ? 0 : fore200e_vcc->tx_min_pdu,
3101 fore200e_vcc->tx_max_pdu,
3102 fore200e_vcc->rx_pdu,
3103 fore200e_vcc->rx_min_pdu > 0xFFFF ? 0 : fore200e_vcc->rx_min_pdu,
3104 fore200e_vcc->rx_max_pdu);
3106 spin_unlock_irqrestore(&fore200e->q_lock, flags);
3110 spin_unlock_irqrestore(&fore200e->q_lock, flags);
3116 module_init(fore200e_module_init);
3117 module_exit(fore200e_module_cleanup);
3120 static const struct atmdev_ops fore200e_ops =
3122 .open = fore200e_open,
3123 .close = fore200e_close,
3124 .ioctl = fore200e_ioctl,
3125 .getsockopt = fore200e_getsockopt,
3126 .setsockopt = fore200e_setsockopt,
3127 .send = fore200e_send,
3128 .change_qos = fore200e_change_qos,
3129 .proc_read = fore200e_proc_read,
3130 .owner = THIS_MODULE
3134 #ifdef CONFIG_ATM_FORE200E_PCA
3135 extern const unsigned char _fore200e_pca_fw_data[];
3136 extern const unsigned int _fore200e_pca_fw_size;
3138 #ifdef CONFIG_ATM_FORE200E_SBA
3139 extern const unsigned char _fore200e_sba_fw_data[];
3140 extern const unsigned int _fore200e_sba_fw_size;
3143 static const struct fore200e_bus fore200e_bus[] = {
3144 #ifdef CONFIG_ATM_FORE200E_PCA
3145 { "PCA-200E", "pca200e", 32, 4, 32,
3146 _fore200e_pca_fw_data, &_fore200e_pca_fw_size,
3149 fore200e_pca_dma_map,
3150 fore200e_pca_dma_unmap,
3151 fore200e_pca_dma_sync_for_cpu,
3152 fore200e_pca_dma_sync_for_device,
3153 fore200e_pca_dma_chunk_alloc,
3154 fore200e_pca_dma_chunk_free,
3155 fore200e_pca_detect,
3156 fore200e_pca_configure,
3159 fore200e_pca_prom_read,
3162 fore200e_pca_irq_check,
3163 fore200e_pca_irq_ack,
3164 fore200e_pca_proc_read,
3167 #ifdef CONFIG_ATM_FORE200E_SBA
3168 { "SBA-200E", "sba200e", 32, 64, 32,
3169 _fore200e_sba_fw_data, &_fore200e_sba_fw_size,
3172 fore200e_sba_dma_map,
3173 fore200e_sba_dma_unmap,
3174 fore200e_sba_dma_sync_for_cpu,
3175 fore200e_sba_dma_sync_for_device,
3176 fore200e_sba_dma_chunk_alloc,
3177 fore200e_sba_dma_chunk_free,
3178 fore200e_sba_detect,
3179 fore200e_sba_configure,
3182 fore200e_sba_prom_read,
3184 fore200e_sba_irq_enable,
3185 fore200e_sba_irq_check,
3186 fore200e_sba_irq_ack,
3187 fore200e_sba_proc_read,
3193 #ifdef MODULE_LICENSE
3194 MODULE_LICENSE("GPL");