2 A FORE Systems 200E-series driver for ATM on Linux.
3 Christophe Lizzi (lizzi@cnam.fr), October 1999-March 2003.
5 Based on the PCA-200E driver from Uwe Dannowski (Uwe.Dannowski@inf.tu-dresden.de).
7 This driver simultaneously supports PCA-200E and SBA-200E adapters
8 on i386, alpha (untested), powerpc, sparc and sparc64 architectures.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
28 #include <linux/init.h>
29 #include <linux/capability.h>
30 #include <linux/interrupt.h>
31 #include <linux/bitops.h>
32 #include <linux/pci.h>
33 #include <linux/module.h>
34 #include <linux/atmdev.h>
35 #include <linux/sonet.h>
36 #include <linux/atm_suni.h>
37 #include <linux/dma-mapping.h>
38 #include <linux/delay.h>
39 #include <linux/firmware.h>
41 #include <asm/string.h>
45 #include <asm/byteorder.h>
46 #include <linux/uaccess.h>
47 #include <linux/atomic.h>
51 #include <linux/of_device.h>
52 #include <asm/idprom.h>
53 #include <asm/openprom.h>
54 #include <asm/oplib.h>
55 #include <asm/pgtable.h>
58 #if defined(CONFIG_ATM_FORE200E_USE_TASKLET) /* defer interrupt work to a tasklet */
59 #define FORE200E_USE_TASKLET
62 #if 0 /* enable the debugging code of the buffer supply queues */
63 #define FORE200E_BSQ_DEBUG
66 #if 1 /* ensure correct handling of 52-byte AAL0 SDUs expected by atmdump-like apps */
67 #define FORE200E_52BYTE_AAL0_SDU
73 #define FORE200E_VERSION "0.3e"
75 #define FORE200E "fore200e: "
77 #if 0 /* override .config */
78 #define CONFIG_ATM_FORE200E_DEBUG 1
80 #if defined(CONFIG_ATM_FORE200E_DEBUG) && (CONFIG_ATM_FORE200E_DEBUG > 0)
81 #define DPRINTK(level, format, args...) do { if (CONFIG_ATM_FORE200E_DEBUG >= (level)) \
82 printk(FORE200E format, ##args); } while (0)
84 #define DPRINTK(level, format, args...) do {} while (0)
88 #define FORE200E_ALIGN(addr, alignment) \
89 ((((unsigned long)(addr) + (alignment - 1)) & ~(alignment - 1)) - (unsigned long)(addr))
91 #define FORE200E_DMA_INDEX(dma_addr, type, index) ((dma_addr) + (index) * sizeof(type))
93 #define FORE200E_INDEX(virt_addr, type, index) (&((type *)(virt_addr))[ index ])
95 #define FORE200E_NEXT_ENTRY(index, modulo) (index = ((index) + 1) % (modulo))
98 #define ASSERT(expr) if (!(expr)) { \
99 printk(FORE200E "assertion failed! %s[%d]: %s\n", \
100 __func__, __LINE__, #expr); \
101 panic(FORE200E "%s", __func__); \
104 #define ASSERT(expr) do {} while (0)
108 static const struct atmdev_ops fore200e_ops
;
110 static LIST_HEAD(fore200e_boards
);
113 MODULE_AUTHOR("Christophe Lizzi - credits to Uwe Dannowski and Heikki Vatiainen");
114 MODULE_DESCRIPTION("FORE Systems 200E-series ATM driver - version " FORE200E_VERSION
);
115 MODULE_SUPPORTED_DEVICE("PCA-200E, SBA-200E");
118 static const int fore200e_rx_buf_nbr
[ BUFFER_SCHEME_NBR
][ BUFFER_MAGN_NBR
] = {
119 { BUFFER_S1_NBR
, BUFFER_L1_NBR
},
120 { BUFFER_S2_NBR
, BUFFER_L2_NBR
}
123 static const int fore200e_rx_buf_size
[ BUFFER_SCHEME_NBR
][ BUFFER_MAGN_NBR
] = {
124 { BUFFER_S1_SIZE
, BUFFER_L1_SIZE
},
125 { BUFFER_S2_SIZE
, BUFFER_L2_SIZE
}
129 #if defined(CONFIG_ATM_FORE200E_DEBUG) && (CONFIG_ATM_FORE200E_DEBUG > 0)
130 static const char* fore200e_traffic_class
[] = { "NONE", "UBR", "CBR", "VBR", "ABR", "ANY" };
134 #if 0 /* currently unused */
136 fore200e_fore2atm_aal(enum fore200e_aal aal
)
139 case FORE200E_AAL0
: return ATM_AAL0
;
140 case FORE200E_AAL34
: return ATM_AAL34
;
141 case FORE200E_AAL5
: return ATM_AAL5
;
149 static enum fore200e_aal
150 fore200e_atm2fore_aal(int aal
)
153 case ATM_AAL0
: return FORE200E_AAL0
;
154 case ATM_AAL34
: return FORE200E_AAL34
;
157 case ATM_AAL5
: return FORE200E_AAL5
;
165 fore200e_irq_itoa(int irq
)
168 sprintf(str
, "%d", irq
);
173 /* allocate and align a chunk of memory intended to hold the data behing exchanged
174 between the driver and the adapter (using streaming DVMA) */
177 fore200e_chunk_alloc(struct fore200e
* fore200e
, struct chunk
* chunk
, int size
, int alignment
, int direction
)
179 unsigned long offset
= 0;
181 if (alignment
<= sizeof(int))
184 chunk
->alloc_size
= size
+ alignment
;
185 chunk
->direction
= direction
;
187 chunk
->alloc_addr
= kzalloc(chunk
->alloc_size
, GFP_KERNEL
);
188 if (chunk
->alloc_addr
== NULL
)
192 offset
= FORE200E_ALIGN(chunk
->alloc_addr
, alignment
);
194 chunk
->align_addr
= chunk
->alloc_addr
+ offset
;
196 chunk
->dma_addr
= dma_map_single(fore200e
->dev
, chunk
->align_addr
,
198 if (dma_mapping_error(fore200e
->dev
, chunk
->dma_addr
)) {
199 kfree(chunk
->alloc_addr
);
206 /* free a chunk of memory */
209 fore200e_chunk_free(struct fore200e
* fore200e
, struct chunk
* chunk
)
211 dma_unmap_single(fore200e
->dev
, chunk
->dma_addr
, chunk
->dma_size
,
213 kfree(chunk
->alloc_addr
);
217 * Allocate a DMA consistent chunk of memory intended to act as a communication
218 * mechanism (to hold descriptors, status, queues, etc.) shared by the driver
222 fore200e_dma_chunk_alloc(struct fore200e
*fore200e
, struct chunk
*chunk
,
223 int size
, int nbr
, int alignment
)
225 /* returned chunks are page-aligned */
226 chunk
->alloc_size
= size
* nbr
;
227 chunk
->alloc_addr
= dma_alloc_coherent(fore200e
->dev
, chunk
->alloc_size
,
228 &chunk
->dma_addr
, GFP_KERNEL
);
229 if (!chunk
->alloc_addr
)
231 chunk
->align_addr
= chunk
->alloc_addr
;
236 * Free a DMA consistent chunk of memory.
239 fore200e_dma_chunk_free(struct fore200e
* fore200e
, struct chunk
* chunk
)
241 dma_free_coherent(fore200e
->dev
, chunk
->alloc_size
, chunk
->alloc_addr
,
246 fore200e_spin(int msecs
)
248 unsigned long timeout
= jiffies
+ msecs_to_jiffies(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_to_jiffies(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 __iomem
*addr
, u32 val
, int msecs
)
280 unsigned long timeout
= jiffies
+ msecs_to_jiffies(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_dma_chunk_free(fore200e
, status
);
338 if (rbd_block
->alloc_addr
)
339 fore200e_dma_chunk_free(fore200e
, rbd_block
);
346 fore200e_reset(struct fore200e
* fore200e
, int diag
)
350 fore200e
->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
:
389 kfree(fore200e
->stats
);
392 case FORE200E_STATE_IRQ
:
393 free_irq(fore200e
->irq
, fore200e
->atm_dev
);
396 case FORE200E_STATE_ALLOC_BUF
:
397 fore200e_free_rx_buf(fore200e
);
400 case FORE200E_STATE_INIT_BSQ
:
401 fore200e_uninit_bs_queue(fore200e
);
404 case FORE200E_STATE_INIT_RXQ
:
405 fore200e_dma_chunk_free(fore200e
, &fore200e
->host_rxq
.status
);
406 fore200e_dma_chunk_free(fore200e
, &fore200e
->host_rxq
.rpd
);
409 case FORE200E_STATE_INIT_TXQ
:
410 fore200e_dma_chunk_free(fore200e
, &fore200e
->host_txq
.status
);
411 fore200e_dma_chunk_free(fore200e
, &fore200e
->host_txq
.tpd
);
414 case FORE200E_STATE_INIT_CMDQ
:
415 fore200e_dma_chunk_free(fore200e
, &fore200e
->host_cmdq
.status
);
418 case FORE200E_STATE_INITIALIZE
:
419 /* nothing to do for that state */
421 case FORE200E_STATE_START_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
);
431 case FORE200E_STATE_CONFIGURE
:
432 /* nothing to do for that state */
434 case FORE200E_STATE_REGISTER
:
435 /* XXX shouldn't we *start* by deregistering the device? */
436 atm_dev_deregister(fore200e
->atm_dev
);
438 case FORE200E_STATE_BLANK
:
439 /* nothing to do for that state */
447 static u32
fore200e_pca_read(volatile u32 __iomem
*addr
)
449 /* on big-endian hosts, the board is configured to convert
450 the endianess of slave RAM accesses */
451 return le32_to_cpu(readl(addr
));
455 static void fore200e_pca_write(u32 val
, volatile u32 __iomem
*addr
)
457 /* on big-endian hosts, the board is configured to convert
458 the endianess of slave RAM accesses */
459 writel(cpu_to_le32(val
), addr
);
463 fore200e_pca_irq_check(struct fore200e
* fore200e
)
465 /* this is a 1 bit register */
466 int irq_posted
= readl(fore200e
->regs
.pca
.psr
);
468 #if defined(CONFIG_ATM_FORE200E_DEBUG) && (CONFIG_ATM_FORE200E_DEBUG == 2)
469 if (irq_posted
&& (readl(fore200e
->regs
.pca
.hcr
) & PCA200E_HCR_OUTFULL
)) {
470 DPRINTK(2,"FIFO OUT full, device %d\n", fore200e
->atm_dev
->number
);
479 fore200e_pca_irq_ack(struct fore200e
* fore200e
)
481 writel(PCA200E_HCR_CLRINTR
, fore200e
->regs
.pca
.hcr
);
486 fore200e_pca_reset(struct fore200e
* fore200e
)
488 writel(PCA200E_HCR_RESET
, fore200e
->regs
.pca
.hcr
);
490 writel(0, fore200e
->regs
.pca
.hcr
);
494 static int fore200e_pca_map(struct fore200e
* fore200e
)
496 DPRINTK(2, "device %s being mapped in memory\n", fore200e
->name
);
498 fore200e
->virt_base
= ioremap(fore200e
->phys_base
, PCA200E_IOSPACE_LENGTH
);
500 if (fore200e
->virt_base
== NULL
) {
501 printk(FORE200E
"can't map device %s\n", fore200e
->name
);
505 DPRINTK(1, "device %s mapped to 0x%p\n", fore200e
->name
, fore200e
->virt_base
);
507 /* gain access to the PCA specific registers */
508 fore200e
->regs
.pca
.hcr
= fore200e
->virt_base
+ PCA200E_HCR_OFFSET
;
509 fore200e
->regs
.pca
.imr
= fore200e
->virt_base
+ PCA200E_IMR_OFFSET
;
510 fore200e
->regs
.pca
.psr
= fore200e
->virt_base
+ PCA200E_PSR_OFFSET
;
512 fore200e
->state
= FORE200E_STATE_MAP
;
518 fore200e_pca_unmap(struct fore200e
* fore200e
)
520 DPRINTK(2, "device %s being unmapped from memory\n", fore200e
->name
);
522 if (fore200e
->virt_base
!= NULL
)
523 iounmap(fore200e
->virt_base
);
527 static int fore200e_pca_configure(struct fore200e
*fore200e
)
529 struct pci_dev
*pci_dev
= to_pci_dev(fore200e
->dev
);
530 u8 master_ctrl
, latency
;
532 DPRINTK(2, "device %s being configured\n", fore200e
->name
);
534 if ((pci_dev
->irq
== 0) || (pci_dev
->irq
== 0xFF)) {
535 printk(FORE200E
"incorrect IRQ setting - misconfigured PCI-PCI bridge?\n");
539 pci_read_config_byte(pci_dev
, PCA200E_PCI_MASTER_CTRL
, &master_ctrl
);
541 master_ctrl
= master_ctrl
542 #if defined(__BIG_ENDIAN)
543 /* request the PCA board to convert the endianess of slave RAM accesses */
544 | PCA200E_CTRL_CONVERT_ENDIAN
547 | PCA200E_CTRL_DIS_CACHE_RD
548 | PCA200E_CTRL_DIS_WRT_INVAL
549 | PCA200E_CTRL_ENA_CONT_REQ_MODE
550 | PCA200E_CTRL_2_CACHE_WRT_INVAL
552 | PCA200E_CTRL_LARGE_PCI_BURSTS
;
554 pci_write_config_byte(pci_dev
, PCA200E_PCI_MASTER_CTRL
, master_ctrl
);
556 /* raise latency from 32 (default) to 192, as this seems to prevent NIC
557 lockups (under heavy rx loads) due to continuous 'FIFO OUT full' condition.
558 this may impact the performances of other PCI devices on the same bus, though */
560 pci_write_config_byte(pci_dev
, PCI_LATENCY_TIMER
, latency
);
562 fore200e
->state
= FORE200E_STATE_CONFIGURE
;
568 fore200e_pca_prom_read(struct fore200e
* fore200e
, struct prom_data
* prom
)
570 struct host_cmdq
* cmdq
= &fore200e
->host_cmdq
;
571 struct host_cmdq_entry
* entry
= &cmdq
->host_entry
[ cmdq
->head
];
572 struct prom_opcode opcode
;
576 FORE200E_NEXT_ENTRY(cmdq
->head
, QUEUE_SIZE_CMD
);
578 opcode
.opcode
= OPCODE_GET_PROM
;
581 prom_dma
= dma_map_single(fore200e
->dev
, prom
, sizeof(struct prom_data
),
583 if (dma_mapping_error(fore200e
->dev
, prom_dma
))
586 fore200e
->bus
->write(prom_dma
, &entry
->cp_entry
->cmd
.prom_block
.prom_haddr
);
588 *entry
->status
= STATUS_PENDING
;
590 fore200e
->bus
->write(*(u32
*)&opcode
, (u32 __iomem
*)&entry
->cp_entry
->cmd
.prom_block
.opcode
);
592 ok
= fore200e_poll(fore200e
, entry
->status
, STATUS_COMPLETE
, 400);
594 *entry
->status
= STATUS_FREE
;
596 dma_unmap_single(fore200e
->dev
, prom_dma
, sizeof(struct prom_data
), DMA_FROM_DEVICE
);
599 printk(FORE200E
"unable to get PROM data from device %s\n", fore200e
->name
);
603 #if defined(__BIG_ENDIAN)
605 #define swap_here(addr) (*((u32*)(addr)) = swab32( *((u32*)(addr)) ))
607 /* MAC address is stored as little-endian */
608 swap_here(&prom
->mac_addr
[0]);
609 swap_here(&prom
->mac_addr
[4]);
617 fore200e_pca_proc_read(struct fore200e
* fore200e
, char *page
)
619 struct pci_dev
*pci_dev
= to_pci_dev(fore200e
->dev
);
621 return sprintf(page
, " PCI bus/slot/function:\t%d/%d/%d\n",
622 pci_dev
->bus
->number
, PCI_SLOT(pci_dev
->devfn
), PCI_FUNC(pci_dev
->devfn
));
625 static const struct fore200e_bus fore200e_pci_ops
= {
626 .model_name
= "PCA-200E",
627 .proc_name
= "pca200e",
628 .descr_alignment
= 32,
629 .buffer_alignment
= 4,
630 .status_alignment
= 32,
631 .read
= fore200e_pca_read
,
632 .write
= fore200e_pca_write
,
633 .configure
= fore200e_pca_configure
,
634 .map
= fore200e_pca_map
,
635 .reset
= fore200e_pca_reset
,
636 .prom_read
= fore200e_pca_prom_read
,
637 .unmap
= fore200e_pca_unmap
,
638 .irq_check
= fore200e_pca_irq_check
,
639 .irq_ack
= fore200e_pca_irq_ack
,
640 .proc_read
= fore200e_pca_proc_read
,
642 #endif /* CONFIG_PCI */
646 static u32
fore200e_sba_read(volatile u32 __iomem
*addr
)
648 return sbus_readl(addr
);
651 static void fore200e_sba_write(u32 val
, volatile u32 __iomem
*addr
)
653 sbus_writel(val
, addr
);
656 static void fore200e_sba_irq_enable(struct fore200e
*fore200e
)
658 u32 hcr
= fore200e
->bus
->read(fore200e
->regs
.sba
.hcr
) & SBA200E_HCR_STICKY
;
659 fore200e
->bus
->write(hcr
| SBA200E_HCR_INTR_ENA
, fore200e
->regs
.sba
.hcr
);
662 static int fore200e_sba_irq_check(struct fore200e
*fore200e
)
664 return fore200e
->bus
->read(fore200e
->regs
.sba
.hcr
) & SBA200E_HCR_INTR_REQ
;
667 static void fore200e_sba_irq_ack(struct fore200e
*fore200e
)
669 u32 hcr
= fore200e
->bus
->read(fore200e
->regs
.sba
.hcr
) & SBA200E_HCR_STICKY
;
670 fore200e
->bus
->write(hcr
| SBA200E_HCR_INTR_CLR
, fore200e
->regs
.sba
.hcr
);
673 static void fore200e_sba_reset(struct fore200e
*fore200e
)
675 fore200e
->bus
->write(SBA200E_HCR_RESET
, fore200e
->regs
.sba
.hcr
);
677 fore200e
->bus
->write(0, fore200e
->regs
.sba
.hcr
);
680 static int __init
fore200e_sba_map(struct fore200e
*fore200e
)
682 struct platform_device
*op
= to_platform_device(fore200e
->dev
);
685 /* gain access to the SBA specific registers */
686 fore200e
->regs
.sba
.hcr
= of_ioremap(&op
->resource
[0], 0, SBA200E_HCR_LENGTH
, "SBA HCR");
687 fore200e
->regs
.sba
.bsr
= of_ioremap(&op
->resource
[1], 0, SBA200E_BSR_LENGTH
, "SBA BSR");
688 fore200e
->regs
.sba
.isr
= of_ioremap(&op
->resource
[2], 0, SBA200E_ISR_LENGTH
, "SBA ISR");
689 fore200e
->virt_base
= of_ioremap(&op
->resource
[3], 0, SBA200E_RAM_LENGTH
, "SBA RAM");
691 if (!fore200e
->virt_base
) {
692 printk(FORE200E
"unable to map RAM of device %s\n", fore200e
->name
);
696 DPRINTK(1, "device %s mapped to 0x%p\n", fore200e
->name
, fore200e
->virt_base
);
698 fore200e
->bus
->write(0x02, fore200e
->regs
.sba
.isr
); /* XXX hardwired interrupt level */
700 /* get the supported DVMA burst sizes */
701 bursts
= of_getintprop_default(op
->dev
.of_node
->parent
, "burst-sizes", 0x00);
703 if (sbus_can_dma_64bit())
704 sbus_set_sbus64(&op
->dev
, bursts
);
706 fore200e
->state
= FORE200E_STATE_MAP
;
710 static void fore200e_sba_unmap(struct fore200e
*fore200e
)
712 struct platform_device
*op
= to_platform_device(fore200e
->dev
);
714 of_iounmap(&op
->resource
[0], fore200e
->regs
.sba
.hcr
, SBA200E_HCR_LENGTH
);
715 of_iounmap(&op
->resource
[1], fore200e
->regs
.sba
.bsr
, SBA200E_BSR_LENGTH
);
716 of_iounmap(&op
->resource
[2], fore200e
->regs
.sba
.isr
, SBA200E_ISR_LENGTH
);
717 of_iounmap(&op
->resource
[3], fore200e
->virt_base
, SBA200E_RAM_LENGTH
);
720 static int __init
fore200e_sba_configure(struct fore200e
*fore200e
)
722 fore200e
->state
= FORE200E_STATE_CONFIGURE
;
726 static int __init
fore200e_sba_prom_read(struct fore200e
*fore200e
, struct prom_data
*prom
)
728 struct platform_device
*op
= to_platform_device(fore200e
->dev
);
732 prop
= of_get_property(op
->dev
.of_node
, "madaddrlo2", &len
);
735 memcpy(&prom
->mac_addr
[4], prop
, 4);
737 prop
= of_get_property(op
->dev
.of_node
, "madaddrhi4", &len
);
740 memcpy(&prom
->mac_addr
[2], prop
, 4);
742 prom
->serial_number
= of_getintprop_default(op
->dev
.of_node
,
744 prom
->hw_revision
= of_getintprop_default(op
->dev
.of_node
,
750 static int fore200e_sba_proc_read(struct fore200e
*fore200e
, char *page
)
752 struct platform_device
*op
= to_platform_device(fore200e
->dev
);
753 const struct linux_prom_registers
*regs
;
755 regs
= of_get_property(op
->dev
.of_node
, "reg", NULL
);
757 return sprintf(page
, " SBUS slot/device:\t\t%d/'%pOFn'\n",
758 (regs
? regs
->which_io
: 0), op
->dev
.of_node
);
761 static const struct fore200e_bus fore200e_sbus_ops
= {
762 .model_name
= "SBA-200E",
763 .proc_name
= "sba200e",
764 .descr_alignment
= 32,
765 .buffer_alignment
= 64,
766 .status_alignment
= 32,
767 .read
= fore200e_sba_read
,
768 .write
= fore200e_sba_write
,
769 .configure
= fore200e_sba_configure
,
770 .map
= fore200e_sba_map
,
771 .reset
= fore200e_sba_reset
,
772 .prom_read
= fore200e_sba_prom_read
,
773 .unmap
= fore200e_sba_unmap
,
774 .irq_enable
= fore200e_sba_irq_enable
,
775 .irq_check
= fore200e_sba_irq_check
,
776 .irq_ack
= fore200e_sba_irq_ack
,
777 .proc_read
= fore200e_sba_proc_read
,
779 #endif /* CONFIG_SBUS */
782 fore200e_tx_irq(struct fore200e
* fore200e
)
784 struct host_txq
* txq
= &fore200e
->host_txq
;
785 struct host_txq_entry
* entry
;
787 struct fore200e_vc_map
* vc_map
;
789 if (fore200e
->host_txq
.txing
== 0)
794 entry
= &txq
->host_entry
[ txq
->tail
];
796 if ((*entry
->status
& STATUS_COMPLETE
) == 0) {
800 DPRINTK(3, "TX COMPLETED: entry = %p [tail = %d], vc_map = %p, skb = %p\n",
801 entry
, txq
->tail
, entry
->vc_map
, entry
->skb
);
803 /* free copy of misaligned data */
806 /* remove DMA mapping */
807 dma_unmap_single(fore200e
->dev
, entry
->tpd
->tsd
[ 0 ].buffer
, entry
->tpd
->tsd
[ 0 ].length
,
810 vc_map
= entry
->vc_map
;
812 /* vcc closed since the time the entry was submitted for tx? */
813 if ((vc_map
->vcc
== NULL
) ||
814 (test_bit(ATM_VF_READY
, &vc_map
->vcc
->flags
) == 0)) {
816 DPRINTK(1, "no ready vcc found for PDU sent on device %d\n",
817 fore200e
->atm_dev
->number
);
819 dev_kfree_skb_any(entry
->skb
);
824 /* vcc closed then immediately re-opened? */
825 if (vc_map
->incarn
!= entry
->incarn
) {
827 /* when a vcc is closed, some PDUs may be still pending in the tx queue.
828 if the same vcc is immediately re-opened, those pending PDUs must
829 not be popped after the completion of their emission, as they refer
830 to the prior incarnation of that vcc. otherwise, sk_atm(vcc)->sk_wmem_alloc
831 would be decremented by the size of the (unrelated) skb, possibly
832 leading to a negative sk->sk_wmem_alloc count, ultimately freezing the vcc.
833 we thus bind the tx entry to the current incarnation of the vcc
834 when the entry is submitted for tx. When the tx later completes,
835 if the incarnation number of the tx entry does not match the one
836 of the vcc, then this implies that the vcc has been closed then re-opened.
837 we thus just drop the skb here. */
839 DPRINTK(1, "vcc closed-then-re-opened; dropping PDU sent on device %d\n",
840 fore200e
->atm_dev
->number
);
842 dev_kfree_skb_any(entry
->skb
);
848 /* notify tx completion */
850 vcc
->pop(vcc
, entry
->skb
);
853 dev_kfree_skb_any(entry
->skb
);
856 /* check error condition */
857 if (*entry
->status
& STATUS_ERROR
)
858 atomic_inc(&vcc
->stats
->tx_err
);
860 atomic_inc(&vcc
->stats
->tx
);
864 *entry
->status
= STATUS_FREE
;
866 fore200e
->host_txq
.txing
--;
868 FORE200E_NEXT_ENTRY(txq
->tail
, QUEUE_SIZE_TX
);
873 #ifdef FORE200E_BSQ_DEBUG
874 int bsq_audit(int where
, struct host_bsq
* bsq
, int scheme
, int magn
)
876 struct buffer
* buffer
;
879 buffer
= bsq
->freebuf
;
882 if (buffer
->supplied
) {
883 printk(FORE200E
"bsq_audit(%d): queue %d.%d, buffer %ld supplied but in free list!\n",
884 where
, scheme
, magn
, buffer
->index
);
887 if (buffer
->magn
!= magn
) {
888 printk(FORE200E
"bsq_audit(%d): queue %d.%d, buffer %ld, unexpected magn = %d\n",
889 where
, scheme
, magn
, buffer
->index
, buffer
->magn
);
892 if (buffer
->scheme
!= scheme
) {
893 printk(FORE200E
"bsq_audit(%d): queue %d.%d, buffer %ld, unexpected scheme = %d\n",
894 where
, scheme
, magn
, buffer
->index
, buffer
->scheme
);
897 if ((buffer
->index
< 0) || (buffer
->index
>= fore200e_rx_buf_nbr
[ scheme
][ magn
])) {
898 printk(FORE200E
"bsq_audit(%d): queue %d.%d, out of range buffer index = %ld !\n",
899 where
, scheme
, magn
, buffer
->index
);
903 buffer
= buffer
->next
;
906 if (count
!= bsq
->freebuf_count
) {
907 printk(FORE200E
"bsq_audit(%d): queue %d.%d, %d bufs in free list, but freebuf_count = %d\n",
908 where
, scheme
, magn
, count
, bsq
->freebuf_count
);
916 fore200e_supply(struct fore200e
* fore200e
)
920 struct host_bsq
* bsq
;
921 struct host_bsq_entry
* entry
;
922 struct buffer
* buffer
;
924 for (scheme
= 0; scheme
< BUFFER_SCHEME_NBR
; scheme
++) {
925 for (magn
= 0; magn
< BUFFER_MAGN_NBR
; magn
++) {
927 bsq
= &fore200e
->host_bsq
[ scheme
][ magn
];
929 #ifdef FORE200E_BSQ_DEBUG
930 bsq_audit(1, bsq
, scheme
, magn
);
932 while (bsq
->freebuf_count
>= RBD_BLK_SIZE
) {
934 DPRINTK(2, "supplying %d rx buffers to queue %d / %d, freebuf_count = %d\n",
935 RBD_BLK_SIZE
, scheme
, magn
, bsq
->freebuf_count
);
937 entry
= &bsq
->host_entry
[ bsq
->head
];
939 for (i
= 0; i
< RBD_BLK_SIZE
; i
++) {
941 /* take the first buffer in the free buffer list */
942 buffer
= bsq
->freebuf
;
944 printk(FORE200E
"no more free bufs in queue %d.%d, but freebuf_count = %d\n",
945 scheme
, magn
, bsq
->freebuf_count
);
948 bsq
->freebuf
= buffer
->next
;
950 #ifdef FORE200E_BSQ_DEBUG
951 if (buffer
->supplied
)
952 printk(FORE200E
"queue %d.%d, buffer %lu already supplied\n",
953 scheme
, magn
, buffer
->index
);
954 buffer
->supplied
= 1;
956 entry
->rbd_block
->rbd
[ i
].buffer_haddr
= buffer
->data
.dma_addr
;
957 entry
->rbd_block
->rbd
[ i
].handle
= FORE200E_BUF2HDL(buffer
);
960 FORE200E_NEXT_ENTRY(bsq
->head
, QUEUE_SIZE_BS
);
962 /* decrease accordingly the number of free rx buffers */
963 bsq
->freebuf_count
-= RBD_BLK_SIZE
;
965 *entry
->status
= STATUS_PENDING
;
966 fore200e
->bus
->write(entry
->rbd_block_dma
, &entry
->cp_entry
->rbd_block_haddr
);
974 fore200e_push_rpd(struct fore200e
* fore200e
, struct atm_vcc
* vcc
, struct rpd
* rpd
)
977 struct buffer
* buffer
;
978 struct fore200e_vcc
* fore200e_vcc
;
980 #ifdef FORE200E_52BYTE_AAL0_SDU
986 fore200e_vcc
= FORE200E_VCC(vcc
);
987 ASSERT(fore200e_vcc
);
989 #ifdef FORE200E_52BYTE_AAL0_SDU
990 if ((vcc
->qos
.aal
== ATM_AAL0
) && (vcc
->qos
.rxtp
.max_sdu
== ATM_AAL0_SDU
)) {
992 cell_header
= (rpd
->atm_header
.gfc
<< ATM_HDR_GFC_SHIFT
) |
993 (rpd
->atm_header
.vpi
<< ATM_HDR_VPI_SHIFT
) |
994 (rpd
->atm_header
.vci
<< ATM_HDR_VCI_SHIFT
) |
995 (rpd
->atm_header
.plt
<< ATM_HDR_PTI_SHIFT
) |
1001 /* compute total PDU length */
1002 for (i
= 0; i
< rpd
->nseg
; i
++)
1003 pdu_len
+= rpd
->rsd
[ i
].length
;
1005 skb
= alloc_skb(pdu_len
, GFP_ATOMIC
);
1007 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len
);
1009 atomic_inc(&vcc
->stats
->rx_drop
);
1013 __net_timestamp(skb
);
1015 #ifdef FORE200E_52BYTE_AAL0_SDU
1017 *((u32
*)skb_put(skb
, 4)) = cell_header
;
1021 /* reassemble segments */
1022 for (i
= 0; i
< rpd
->nseg
; i
++) {
1024 /* rebuild rx buffer address from rsd handle */
1025 buffer
= FORE200E_HDL2BUF(rpd
->rsd
[ i
].handle
);
1027 /* Make device DMA transfer visible to CPU. */
1028 dma_sync_single_for_cpu(fore200e
->dev
, buffer
->data
.dma_addr
,
1029 rpd
->rsd
[i
].length
, DMA_FROM_DEVICE
);
1031 skb_put_data(skb
, buffer
->data
.align_addr
, rpd
->rsd
[i
].length
);
1033 /* Now let the device get at it again. */
1034 dma_sync_single_for_device(fore200e
->dev
, buffer
->data
.dma_addr
,
1035 rpd
->rsd
[i
].length
, DMA_FROM_DEVICE
);
1038 DPRINTK(3, "rx skb: len = %d, truesize = %d\n", skb
->len
, skb
->truesize
);
1040 if (pdu_len
< fore200e_vcc
->rx_min_pdu
)
1041 fore200e_vcc
->rx_min_pdu
= pdu_len
;
1042 if (pdu_len
> fore200e_vcc
->rx_max_pdu
)
1043 fore200e_vcc
->rx_max_pdu
= pdu_len
;
1044 fore200e_vcc
->rx_pdu
++;
1047 if (atm_charge(vcc
, skb
->truesize
) == 0) {
1049 DPRINTK(2, "receive buffers saturated for %d.%d.%d - PDU dropped\n",
1050 vcc
->itf
, vcc
->vpi
, vcc
->vci
);
1052 dev_kfree_skb_any(skb
);
1054 atomic_inc(&vcc
->stats
->rx_drop
);
1058 vcc
->push(vcc
, skb
);
1059 atomic_inc(&vcc
->stats
->rx
);
1066 fore200e_collect_rpd(struct fore200e
* fore200e
, struct rpd
* rpd
)
1068 struct host_bsq
* bsq
;
1069 struct buffer
* buffer
;
1072 for (i
= 0; i
< rpd
->nseg
; i
++) {
1074 /* rebuild rx buffer address from rsd handle */
1075 buffer
= FORE200E_HDL2BUF(rpd
->rsd
[ i
].handle
);
1077 bsq
= &fore200e
->host_bsq
[ buffer
->scheme
][ buffer
->magn
];
1079 #ifdef FORE200E_BSQ_DEBUG
1080 bsq_audit(2, bsq
, buffer
->scheme
, buffer
->magn
);
1082 if (buffer
->supplied
== 0)
1083 printk(FORE200E
"queue %d.%d, buffer %ld was not supplied\n",
1084 buffer
->scheme
, buffer
->magn
, buffer
->index
);
1085 buffer
->supplied
= 0;
1088 /* re-insert the buffer into the free buffer list */
1089 buffer
->next
= bsq
->freebuf
;
1090 bsq
->freebuf
= buffer
;
1092 /* then increment the number of free rx buffers */
1093 bsq
->freebuf_count
++;
1099 fore200e_rx_irq(struct fore200e
* fore200e
)
1101 struct host_rxq
* rxq
= &fore200e
->host_rxq
;
1102 struct host_rxq_entry
* entry
;
1103 struct atm_vcc
* vcc
;
1104 struct fore200e_vc_map
* vc_map
;
1108 entry
= &rxq
->host_entry
[ rxq
->head
];
1110 /* no more received PDUs */
1111 if ((*entry
->status
& STATUS_COMPLETE
) == 0)
1114 vc_map
= FORE200E_VC_MAP(fore200e
, entry
->rpd
->atm_header
.vpi
, entry
->rpd
->atm_header
.vci
);
1116 if ((vc_map
->vcc
== NULL
) ||
1117 (test_bit(ATM_VF_READY
, &vc_map
->vcc
->flags
) == 0)) {
1119 DPRINTK(1, "no ready VC found for PDU received on %d.%d.%d\n",
1120 fore200e
->atm_dev
->number
,
1121 entry
->rpd
->atm_header
.vpi
, entry
->rpd
->atm_header
.vci
);
1127 if ((*entry
->status
& STATUS_ERROR
) == 0) {
1129 fore200e_push_rpd(fore200e
, vcc
, entry
->rpd
);
1132 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
1133 fore200e
->atm_dev
->number
,
1134 entry
->rpd
->atm_header
.vpi
, entry
->rpd
->atm_header
.vci
);
1135 atomic_inc(&vcc
->stats
->rx_err
);
1139 FORE200E_NEXT_ENTRY(rxq
->head
, QUEUE_SIZE_RX
);
1141 fore200e_collect_rpd(fore200e
, entry
->rpd
);
1143 /* rewrite the rpd address to ack the received PDU */
1144 fore200e
->bus
->write(entry
->rpd_dma
, &entry
->cp_entry
->rpd_haddr
);
1145 *entry
->status
= STATUS_FREE
;
1147 fore200e_supply(fore200e
);
1152 #ifndef FORE200E_USE_TASKLET
1154 fore200e_irq(struct fore200e
* fore200e
)
1156 unsigned long flags
;
1158 spin_lock_irqsave(&fore200e
->q_lock
, flags
);
1159 fore200e_rx_irq(fore200e
);
1160 spin_unlock_irqrestore(&fore200e
->q_lock
, flags
);
1162 spin_lock_irqsave(&fore200e
->q_lock
, flags
);
1163 fore200e_tx_irq(fore200e
);
1164 spin_unlock_irqrestore(&fore200e
->q_lock
, flags
);
1170 fore200e_interrupt(int irq
, void* dev
)
1172 struct fore200e
* fore200e
= FORE200E_DEV((struct atm_dev
*)dev
);
1174 if (fore200e
->bus
->irq_check(fore200e
) == 0) {
1176 DPRINTK(3, "interrupt NOT triggered by device %d\n", fore200e
->atm_dev
->number
);
1179 DPRINTK(3, "interrupt triggered by device %d\n", fore200e
->atm_dev
->number
);
1181 #ifdef FORE200E_USE_TASKLET
1182 tasklet_schedule(&fore200e
->tx_tasklet
);
1183 tasklet_schedule(&fore200e
->rx_tasklet
);
1185 fore200e_irq(fore200e
);
1188 fore200e
->bus
->irq_ack(fore200e
);
1193 #ifdef FORE200E_USE_TASKLET
1195 fore200e_tx_tasklet(unsigned long data
)
1197 struct fore200e
* fore200e
= (struct fore200e
*) data
;
1198 unsigned long flags
;
1200 DPRINTK(3, "tx tasklet scheduled for device %d\n", fore200e
->atm_dev
->number
);
1202 spin_lock_irqsave(&fore200e
->q_lock
, flags
);
1203 fore200e_tx_irq(fore200e
);
1204 spin_unlock_irqrestore(&fore200e
->q_lock
, flags
);
1209 fore200e_rx_tasklet(unsigned long data
)
1211 struct fore200e
* fore200e
= (struct fore200e
*) data
;
1212 unsigned long flags
;
1214 DPRINTK(3, "rx tasklet scheduled for device %d\n", fore200e
->atm_dev
->number
);
1216 spin_lock_irqsave(&fore200e
->q_lock
, flags
);
1217 fore200e_rx_irq((struct fore200e
*) data
);
1218 spin_unlock_irqrestore(&fore200e
->q_lock
, flags
);
1224 fore200e_select_scheme(struct atm_vcc
* vcc
)
1226 /* fairly balance the VCs over (identical) buffer schemes */
1227 int scheme
= vcc
->vci
% 2 ? BUFFER_SCHEME_ONE
: BUFFER_SCHEME_TWO
;
1229 DPRINTK(1, "VC %d.%d.%d uses buffer scheme %d\n",
1230 vcc
->itf
, vcc
->vpi
, vcc
->vci
, scheme
);
1237 fore200e_activate_vcin(struct fore200e
* fore200e
, int activate
, struct atm_vcc
* vcc
, int mtu
)
1239 struct host_cmdq
* cmdq
= &fore200e
->host_cmdq
;
1240 struct host_cmdq_entry
* entry
= &cmdq
->host_entry
[ cmdq
->head
];
1241 struct activate_opcode activ_opcode
;
1242 struct deactivate_opcode deactiv_opcode
;
1245 enum fore200e_aal aal
= fore200e_atm2fore_aal(vcc
->qos
.aal
);
1247 FORE200E_NEXT_ENTRY(cmdq
->head
, QUEUE_SIZE_CMD
);
1250 FORE200E_VCC(vcc
)->scheme
= fore200e_select_scheme(vcc
);
1252 activ_opcode
.opcode
= OPCODE_ACTIVATE_VCIN
;
1253 activ_opcode
.aal
= aal
;
1254 activ_opcode
.scheme
= FORE200E_VCC(vcc
)->scheme
;
1255 activ_opcode
.pad
= 0;
1258 deactiv_opcode
.opcode
= OPCODE_DEACTIVATE_VCIN
;
1259 deactiv_opcode
.pad
= 0;
1262 vpvc
.vci
= vcc
->vci
;
1263 vpvc
.vpi
= vcc
->vpi
;
1265 *entry
->status
= STATUS_PENDING
;
1269 #ifdef FORE200E_52BYTE_AAL0_SDU
1272 /* the MTU is not used by the cp, except in the case of AAL0 */
1273 fore200e
->bus
->write(mtu
, &entry
->cp_entry
->cmd
.activate_block
.mtu
);
1274 fore200e
->bus
->write(*(u32
*)&vpvc
, (u32 __iomem
*)&entry
->cp_entry
->cmd
.activate_block
.vpvc
);
1275 fore200e
->bus
->write(*(u32
*)&activ_opcode
, (u32 __iomem
*)&entry
->cp_entry
->cmd
.activate_block
.opcode
);
1278 fore200e
->bus
->write(*(u32
*)&vpvc
, (u32 __iomem
*)&entry
->cp_entry
->cmd
.deactivate_block
.vpvc
);
1279 fore200e
->bus
->write(*(u32
*)&deactiv_opcode
, (u32 __iomem
*)&entry
->cp_entry
->cmd
.deactivate_block
.opcode
);
1282 ok
= fore200e_poll(fore200e
, entry
->status
, STATUS_COMPLETE
, 400);
1284 *entry
->status
= STATUS_FREE
;
1287 printk(FORE200E
"unable to %s VC %d.%d.%d\n",
1288 activate
? "open" : "close", vcc
->itf
, vcc
->vpi
, vcc
->vci
);
1292 DPRINTK(1, "VC %d.%d.%d %sed\n", vcc
->itf
, vcc
->vpi
, vcc
->vci
,
1293 activate
? "open" : "clos");
1299 #define FORE200E_MAX_BACK2BACK_CELLS 255 /* XXX depends on CDVT */
1302 fore200e_rate_ctrl(struct atm_qos
* qos
, struct tpd_rate
* rate
)
1304 if (qos
->txtp
.max_pcr
< ATM_OC3_PCR
) {
1306 /* compute the data cells to idle cells ratio from the tx PCR */
1307 rate
->data_cells
= qos
->txtp
.max_pcr
* FORE200E_MAX_BACK2BACK_CELLS
/ ATM_OC3_PCR
;
1308 rate
->idle_cells
= FORE200E_MAX_BACK2BACK_CELLS
- rate
->data_cells
;
1311 /* disable rate control */
1312 rate
->data_cells
= rate
->idle_cells
= 0;
1318 fore200e_open(struct atm_vcc
*vcc
)
1320 struct fore200e
* fore200e
= FORE200E_DEV(vcc
->dev
);
1321 struct fore200e_vcc
* fore200e_vcc
;
1322 struct fore200e_vc_map
* vc_map
;
1323 unsigned long flags
;
1325 short vpi
= vcc
->vpi
;
1327 ASSERT((vpi
>= 0) && (vpi
< 1<<FORE200E_VPI_BITS
));
1328 ASSERT((vci
>= 0) && (vci
< 1<<FORE200E_VCI_BITS
));
1330 spin_lock_irqsave(&fore200e
->q_lock
, flags
);
1332 vc_map
= FORE200E_VC_MAP(fore200e
, vpi
, vci
);
1335 spin_unlock_irqrestore(&fore200e
->q_lock
, flags
);
1337 printk(FORE200E
"VC %d.%d.%d already in use\n",
1338 fore200e
->atm_dev
->number
, vpi
, vci
);
1345 spin_unlock_irqrestore(&fore200e
->q_lock
, flags
);
1347 fore200e_vcc
= kzalloc(sizeof(struct fore200e_vcc
), GFP_ATOMIC
);
1348 if (fore200e_vcc
== NULL
) {
1353 DPRINTK(2, "opening %d.%d.%d:%d QoS = (tx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d; "
1354 "rx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d)\n",
1355 vcc
->itf
, vcc
->vpi
, vcc
->vci
, fore200e_atm2fore_aal(vcc
->qos
.aal
),
1356 fore200e_traffic_class
[ vcc
->qos
.txtp
.traffic_class
],
1357 vcc
->qos
.txtp
.min_pcr
, vcc
->qos
.txtp
.max_pcr
, vcc
->qos
.txtp
.max_cdv
, vcc
->qos
.txtp
.max_sdu
,
1358 fore200e_traffic_class
[ vcc
->qos
.rxtp
.traffic_class
],
1359 vcc
->qos
.rxtp
.min_pcr
, vcc
->qos
.rxtp
.max_pcr
, vcc
->qos
.rxtp
.max_cdv
, vcc
->qos
.rxtp
.max_sdu
);
1361 /* pseudo-CBR bandwidth requested? */
1362 if ((vcc
->qos
.txtp
.traffic_class
== ATM_CBR
) && (vcc
->qos
.txtp
.max_pcr
> 0)) {
1364 mutex_lock(&fore200e
->rate_mtx
);
1365 if (fore200e
->available_cell_rate
< vcc
->qos
.txtp
.max_pcr
) {
1366 mutex_unlock(&fore200e
->rate_mtx
);
1368 kfree(fore200e_vcc
);
1373 /* reserve bandwidth */
1374 fore200e
->available_cell_rate
-= vcc
->qos
.txtp
.max_pcr
;
1375 mutex_unlock(&fore200e
->rate_mtx
);
1378 vcc
->itf
= vcc
->dev
->number
;
1380 set_bit(ATM_VF_PARTIAL
,&vcc
->flags
);
1381 set_bit(ATM_VF_ADDR
, &vcc
->flags
);
1383 vcc
->dev_data
= fore200e_vcc
;
1385 if (fore200e_activate_vcin(fore200e
, 1, vcc
, vcc
->qos
.rxtp
.max_sdu
) < 0) {
1389 clear_bit(ATM_VF_ADDR
, &vcc
->flags
);
1390 clear_bit(ATM_VF_PARTIAL
,&vcc
->flags
);
1392 vcc
->dev_data
= NULL
;
1394 fore200e
->available_cell_rate
+= vcc
->qos
.txtp
.max_pcr
;
1396 kfree(fore200e_vcc
);
1400 /* compute rate control parameters */
1401 if ((vcc
->qos
.txtp
.traffic_class
== ATM_CBR
) && (vcc
->qos
.txtp
.max_pcr
> 0)) {
1403 fore200e_rate_ctrl(&vcc
->qos
, &fore200e_vcc
->rate
);
1404 set_bit(ATM_VF_HASQOS
, &vcc
->flags
);
1406 DPRINTK(3, "tx on %d.%d.%d:%d, tx PCR = %d, rx PCR = %d, data_cells = %u, idle_cells = %u\n",
1407 vcc
->itf
, vcc
->vpi
, vcc
->vci
, fore200e_atm2fore_aal(vcc
->qos
.aal
),
1408 vcc
->qos
.txtp
.max_pcr
, vcc
->qos
.rxtp
.max_pcr
,
1409 fore200e_vcc
->rate
.data_cells
, fore200e_vcc
->rate
.idle_cells
);
1412 fore200e_vcc
->tx_min_pdu
= fore200e_vcc
->rx_min_pdu
= MAX_PDU_SIZE
+ 1;
1413 fore200e_vcc
->tx_max_pdu
= fore200e_vcc
->rx_max_pdu
= 0;
1414 fore200e_vcc
->tx_pdu
= fore200e_vcc
->rx_pdu
= 0;
1416 /* new incarnation of the vcc */
1417 vc_map
->incarn
= ++fore200e
->incarn_count
;
1419 /* VC unusable before this flag is set */
1420 set_bit(ATM_VF_READY
, &vcc
->flags
);
1427 fore200e_close(struct atm_vcc
* vcc
)
1429 struct fore200e
* fore200e
= FORE200E_DEV(vcc
->dev
);
1430 struct fore200e_vcc
* fore200e_vcc
;
1431 struct fore200e_vc_map
* vc_map
;
1432 unsigned long flags
;
1435 ASSERT((vcc
->vpi
>= 0) && (vcc
->vpi
< 1<<FORE200E_VPI_BITS
));
1436 ASSERT((vcc
->vci
>= 0) && (vcc
->vci
< 1<<FORE200E_VCI_BITS
));
1438 DPRINTK(2, "closing %d.%d.%d:%d\n", vcc
->itf
, vcc
->vpi
, vcc
->vci
, fore200e_atm2fore_aal(vcc
->qos
.aal
));
1440 clear_bit(ATM_VF_READY
, &vcc
->flags
);
1442 fore200e_activate_vcin(fore200e
, 0, vcc
, 0);
1444 spin_lock_irqsave(&fore200e
->q_lock
, flags
);
1446 vc_map
= FORE200E_VC_MAP(fore200e
, vcc
->vpi
, vcc
->vci
);
1448 /* the vc is no longer considered as "in use" by fore200e_open() */
1451 vcc
->itf
= vcc
->vci
= vcc
->vpi
= 0;
1453 fore200e_vcc
= FORE200E_VCC(vcc
);
1454 vcc
->dev_data
= NULL
;
1456 spin_unlock_irqrestore(&fore200e
->q_lock
, flags
);
1458 /* release reserved bandwidth, if any */
1459 if ((vcc
->qos
.txtp
.traffic_class
== ATM_CBR
) && (vcc
->qos
.txtp
.max_pcr
> 0)) {
1461 mutex_lock(&fore200e
->rate_mtx
);
1462 fore200e
->available_cell_rate
+= vcc
->qos
.txtp
.max_pcr
;
1463 mutex_unlock(&fore200e
->rate_mtx
);
1465 clear_bit(ATM_VF_HASQOS
, &vcc
->flags
);
1468 clear_bit(ATM_VF_ADDR
, &vcc
->flags
);
1469 clear_bit(ATM_VF_PARTIAL
,&vcc
->flags
);
1471 ASSERT(fore200e_vcc
);
1472 kfree(fore200e_vcc
);
1477 fore200e_send(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
1479 struct fore200e
* fore200e
= FORE200E_DEV(vcc
->dev
);
1480 struct fore200e_vcc
* fore200e_vcc
= FORE200E_VCC(vcc
);
1481 struct fore200e_vc_map
* vc_map
;
1482 struct host_txq
* txq
= &fore200e
->host_txq
;
1483 struct host_txq_entry
* entry
;
1485 struct tpd_haddr tpd_haddr
;
1486 int retry
= CONFIG_ATM_FORE200E_TX_RETRY
;
1488 int tx_len
= skb
->len
;
1489 u32
* cell_header
= NULL
;
1490 unsigned char* skb_data
;
1492 unsigned char* data
;
1493 unsigned long flags
;
1497 ASSERT(fore200e_vcc
);
1499 if (!test_bit(ATM_VF_READY
, &vcc
->flags
)) {
1500 DPRINTK(1, "VC %d.%d.%d not ready for tx\n", vcc
->itf
, vcc
->vpi
, vcc
->vpi
);
1501 dev_kfree_skb_any(skb
);
1505 #ifdef FORE200E_52BYTE_AAL0_SDU
1506 if ((vcc
->qos
.aal
== ATM_AAL0
) && (vcc
->qos
.txtp
.max_sdu
== ATM_AAL0_SDU
)) {
1507 cell_header
= (u32
*) skb
->data
;
1508 skb_data
= skb
->data
+ 4; /* skip 4-byte cell header */
1509 skb_len
= tx_len
= skb
->len
- 4;
1511 DPRINTK(3, "user-supplied cell header = 0x%08x\n", *cell_header
);
1516 skb_data
= skb
->data
;
1520 if (((unsigned long)skb_data
) & 0x3) {
1522 DPRINTK(2, "misaligned tx PDU on device %s\n", fore200e
->name
);
1527 if ((vcc
->qos
.aal
== ATM_AAL0
) && (skb_len
% ATM_CELL_PAYLOAD
)) {
1529 /* this simply NUKES the PCA board */
1530 DPRINTK(2, "incomplete tx AAL0 PDU on device %s\n", fore200e
->name
);
1532 tx_len
= ((skb_len
/ ATM_CELL_PAYLOAD
) + 1) * ATM_CELL_PAYLOAD
;
1536 data
= kmalloc(tx_len
, GFP_ATOMIC
);
1542 dev_kfree_skb_any(skb
);
1547 memcpy(data
, skb_data
, skb_len
);
1548 if (skb_len
< tx_len
)
1549 memset(data
+ skb_len
, 0x00, tx_len
- skb_len
);
1555 vc_map
= FORE200E_VC_MAP(fore200e
, vcc
->vpi
, vcc
->vci
);
1556 ASSERT(vc_map
->vcc
== vcc
);
1560 spin_lock_irqsave(&fore200e
->q_lock
, flags
);
1562 entry
= &txq
->host_entry
[ txq
->head
];
1564 if ((*entry
->status
!= STATUS_FREE
) || (txq
->txing
>= QUEUE_SIZE_TX
- 2)) {
1566 /* try to free completed tx queue entries */
1567 fore200e_tx_irq(fore200e
);
1569 if (*entry
->status
!= STATUS_FREE
) {
1571 spin_unlock_irqrestore(&fore200e
->q_lock
, flags
);
1573 /* retry once again? */
1579 atomic_inc(&vcc
->stats
->tx_err
);
1582 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
1583 fore200e
->name
, fore200e
->cp_queues
->heartbeat
);
1588 dev_kfree_skb_any(skb
);
1598 entry
->incarn
= vc_map
->incarn
;
1599 entry
->vc_map
= vc_map
;
1601 entry
->data
= tx_copy
? data
: NULL
;
1604 tpd
->tsd
[ 0 ].buffer
= dma_map_single(fore200e
->dev
, data
, tx_len
,
1606 if (dma_mapping_error(fore200e
->dev
, tpd
->tsd
[0].buffer
)) {
1609 spin_unlock_irqrestore(&fore200e
->q_lock
, flags
);
1612 tpd
->tsd
[ 0 ].length
= tx_len
;
1614 FORE200E_NEXT_ENTRY(txq
->head
, QUEUE_SIZE_TX
);
1617 /* The dma_map call above implies a dma_sync so the device can use it,
1618 * thus no explicit dma_sync call is necessary here.
1621 DPRINTK(3, "tx on %d.%d.%d:%d, len = %u (%u)\n",
1622 vcc
->itf
, vcc
->vpi
, vcc
->vci
, fore200e_atm2fore_aal(vcc
->qos
.aal
),
1623 tpd
->tsd
[0].length
, skb_len
);
1625 if (skb_len
< fore200e_vcc
->tx_min_pdu
)
1626 fore200e_vcc
->tx_min_pdu
= skb_len
;
1627 if (skb_len
> fore200e_vcc
->tx_max_pdu
)
1628 fore200e_vcc
->tx_max_pdu
= skb_len
;
1629 fore200e_vcc
->tx_pdu
++;
1631 /* set tx rate control information */
1632 tpd
->rate
.data_cells
= fore200e_vcc
->rate
.data_cells
;
1633 tpd
->rate
.idle_cells
= fore200e_vcc
->rate
.idle_cells
;
1636 tpd
->atm_header
.clp
= (*cell_header
& ATM_HDR_CLP
);
1637 tpd
->atm_header
.plt
= (*cell_header
& ATM_HDR_PTI_MASK
) >> ATM_HDR_PTI_SHIFT
;
1638 tpd
->atm_header
.vci
= (*cell_header
& ATM_HDR_VCI_MASK
) >> ATM_HDR_VCI_SHIFT
;
1639 tpd
->atm_header
.vpi
= (*cell_header
& ATM_HDR_VPI_MASK
) >> ATM_HDR_VPI_SHIFT
;
1640 tpd
->atm_header
.gfc
= (*cell_header
& ATM_HDR_GFC_MASK
) >> ATM_HDR_GFC_SHIFT
;
1643 /* set the ATM header, common to all cells conveying the PDU */
1644 tpd
->atm_header
.clp
= 0;
1645 tpd
->atm_header
.plt
= 0;
1646 tpd
->atm_header
.vci
= vcc
->vci
;
1647 tpd
->atm_header
.vpi
= vcc
->vpi
;
1648 tpd
->atm_header
.gfc
= 0;
1651 tpd
->spec
.length
= tx_len
;
1653 tpd
->spec
.aal
= fore200e_atm2fore_aal(vcc
->qos
.aal
);
1656 tpd_haddr
.size
= sizeof(struct tpd
) / (1<<TPD_HADDR_SHIFT
); /* size is expressed in 32 byte blocks */
1658 tpd_haddr
.haddr
= entry
->tpd_dma
>> TPD_HADDR_SHIFT
; /* shift the address, as we are in a bitfield */
1660 *entry
->status
= STATUS_PENDING
;
1661 fore200e
->bus
->write(*(u32
*)&tpd_haddr
, (u32 __iomem
*)&entry
->cp_entry
->tpd_haddr
);
1663 spin_unlock_irqrestore(&fore200e
->q_lock
, flags
);
1670 fore200e_getstats(struct fore200e
* fore200e
)
1672 struct host_cmdq
* cmdq
= &fore200e
->host_cmdq
;
1673 struct host_cmdq_entry
* entry
= &cmdq
->host_entry
[ cmdq
->head
];
1674 struct stats_opcode opcode
;
1678 if (fore200e
->stats
== NULL
) {
1679 fore200e
->stats
= kzalloc(sizeof(struct stats
), GFP_KERNEL
);
1680 if (fore200e
->stats
== NULL
)
1684 stats_dma_addr
= dma_map_single(fore200e
->dev
, fore200e
->stats
,
1685 sizeof(struct stats
), DMA_FROM_DEVICE
);
1686 if (dma_mapping_error(fore200e
->dev
, stats_dma_addr
))
1689 FORE200E_NEXT_ENTRY(cmdq
->head
, QUEUE_SIZE_CMD
);
1691 opcode
.opcode
= OPCODE_GET_STATS
;
1694 fore200e
->bus
->write(stats_dma_addr
, &entry
->cp_entry
->cmd
.stats_block
.stats_haddr
);
1696 *entry
->status
= STATUS_PENDING
;
1698 fore200e
->bus
->write(*(u32
*)&opcode
, (u32 __iomem
*)&entry
->cp_entry
->cmd
.stats_block
.opcode
);
1700 ok
= fore200e_poll(fore200e
, entry
->status
, STATUS_COMPLETE
, 400);
1702 *entry
->status
= STATUS_FREE
;
1704 dma_unmap_single(fore200e
->dev
, stats_dma_addr
, sizeof(struct stats
), DMA_FROM_DEVICE
);
1707 printk(FORE200E
"unable to get statistics from device %s\n", fore200e
->name
);
1716 fore200e_getsockopt(struct atm_vcc
* vcc
, int level
, int optname
, void __user
*optval
, int optlen
)
1718 /* struct fore200e* fore200e = FORE200E_DEV(vcc->dev); */
1720 DPRINTK(2, "getsockopt %d.%d.%d, level = %d, optname = 0x%x, optval = 0x%p, optlen = %d\n",
1721 vcc
->itf
, vcc
->vpi
, vcc
->vci
, level
, optname
, optval
, optlen
);
1728 fore200e_setsockopt(struct atm_vcc
* vcc
, int level
, int optname
, void __user
*optval
, unsigned int optlen
)
1730 /* struct fore200e* fore200e = FORE200E_DEV(vcc->dev); */
1732 DPRINTK(2, "setsockopt %d.%d.%d, level = %d, optname = 0x%x, optval = 0x%p, optlen = %d\n",
1733 vcc
->itf
, vcc
->vpi
, vcc
->vci
, level
, optname
, optval
, optlen
);
1739 #if 0 /* currently unused */
1741 fore200e_get_oc3(struct fore200e
* fore200e
, struct oc3_regs
* regs
)
1743 struct host_cmdq
* cmdq
= &fore200e
->host_cmdq
;
1744 struct host_cmdq_entry
* entry
= &cmdq
->host_entry
[ cmdq
->head
];
1745 struct oc3_opcode opcode
;
1747 u32 oc3_regs_dma_addr
;
1749 oc3_regs_dma_addr
= fore200e
->bus
->dma_map(fore200e
, regs
, sizeof(struct oc3_regs
), DMA_FROM_DEVICE
);
1751 FORE200E_NEXT_ENTRY(cmdq
->head
, QUEUE_SIZE_CMD
);
1753 opcode
.opcode
= OPCODE_GET_OC3
;
1758 fore200e
->bus
->write(oc3_regs_dma_addr
, &entry
->cp_entry
->cmd
.oc3_block
.regs_haddr
);
1760 *entry
->status
= STATUS_PENDING
;
1762 fore200e
->bus
->write(*(u32
*)&opcode
, (u32
*)&entry
->cp_entry
->cmd
.oc3_block
.opcode
);
1764 ok
= fore200e_poll(fore200e
, entry
->status
, STATUS_COMPLETE
, 400);
1766 *entry
->status
= STATUS_FREE
;
1768 fore200e
->bus
->dma_unmap(fore200e
, oc3_regs_dma_addr
, sizeof(struct oc3_regs
), DMA_FROM_DEVICE
);
1771 printk(FORE200E
"unable to get OC-3 regs of device %s\n", fore200e
->name
);
1781 fore200e_set_oc3(struct fore200e
* fore200e
, u32 reg
, u32 value
, u32 mask
)
1783 struct host_cmdq
* cmdq
= &fore200e
->host_cmdq
;
1784 struct host_cmdq_entry
* entry
= &cmdq
->host_entry
[ cmdq
->head
];
1785 struct oc3_opcode opcode
;
1788 DPRINTK(2, "set OC-3 reg = 0x%02x, value = 0x%02x, mask = 0x%02x\n", reg
, value
, mask
);
1790 FORE200E_NEXT_ENTRY(cmdq
->head
, QUEUE_SIZE_CMD
);
1792 opcode
.opcode
= OPCODE_SET_OC3
;
1794 opcode
.value
= value
;
1797 fore200e
->bus
->write(0, &entry
->cp_entry
->cmd
.oc3_block
.regs_haddr
);
1799 *entry
->status
= STATUS_PENDING
;
1801 fore200e
->bus
->write(*(u32
*)&opcode
, (u32 __iomem
*)&entry
->cp_entry
->cmd
.oc3_block
.opcode
);
1803 ok
= fore200e_poll(fore200e
, entry
->status
, STATUS_COMPLETE
, 400);
1805 *entry
->status
= STATUS_FREE
;
1808 printk(FORE200E
"unable to set OC-3 reg 0x%02x of device %s\n", reg
, fore200e
->name
);
1817 fore200e_setloop(struct fore200e
* fore200e
, int loop_mode
)
1819 u32 mct_value
, mct_mask
;
1822 if (!capable(CAP_NET_ADMIN
))
1825 switch (loop_mode
) {
1829 mct_mask
= SUNI_MCT_DLE
| SUNI_MCT_LLE
;
1832 case ATM_LM_LOC_PHY
:
1833 mct_value
= mct_mask
= SUNI_MCT_DLE
;
1836 case ATM_LM_RMT_PHY
:
1837 mct_value
= mct_mask
= SUNI_MCT_LLE
;
1844 error
= fore200e_set_oc3(fore200e
, SUNI_MCT
, mct_value
, mct_mask
);
1846 fore200e
->loop_mode
= loop_mode
;
1853 fore200e_fetch_stats(struct fore200e
* fore200e
, struct sonet_stats __user
*arg
)
1855 struct sonet_stats tmp
;
1857 if (fore200e_getstats(fore200e
) < 0)
1860 tmp
.section_bip
= be32_to_cpu(fore200e
->stats
->oc3
.section_bip8_errors
);
1861 tmp
.line_bip
= be32_to_cpu(fore200e
->stats
->oc3
.line_bip24_errors
);
1862 tmp
.path_bip
= be32_to_cpu(fore200e
->stats
->oc3
.path_bip8_errors
);
1863 tmp
.line_febe
= be32_to_cpu(fore200e
->stats
->oc3
.line_febe_errors
);
1864 tmp
.path_febe
= be32_to_cpu(fore200e
->stats
->oc3
.path_febe_errors
);
1865 tmp
.corr_hcs
= be32_to_cpu(fore200e
->stats
->oc3
.corr_hcs_errors
);
1866 tmp
.uncorr_hcs
= be32_to_cpu(fore200e
->stats
->oc3
.ucorr_hcs_errors
);
1867 tmp
.tx_cells
= be32_to_cpu(fore200e
->stats
->aal0
.cells_transmitted
) +
1868 be32_to_cpu(fore200e
->stats
->aal34
.cells_transmitted
) +
1869 be32_to_cpu(fore200e
->stats
->aal5
.cells_transmitted
);
1870 tmp
.rx_cells
= be32_to_cpu(fore200e
->stats
->aal0
.cells_received
) +
1871 be32_to_cpu(fore200e
->stats
->aal34
.cells_received
) +
1872 be32_to_cpu(fore200e
->stats
->aal5
.cells_received
);
1875 return copy_to_user(arg
, &tmp
, sizeof(struct sonet_stats
)) ? -EFAULT
: 0;
1882 fore200e_ioctl(struct atm_dev
* dev
, unsigned int cmd
, void __user
* arg
)
1884 struct fore200e
* fore200e
= FORE200E_DEV(dev
);
1886 DPRINTK(2, "ioctl cmd = 0x%x (%u), arg = 0x%p (%lu)\n", cmd
, cmd
, arg
, (unsigned long)arg
);
1891 return fore200e_fetch_stats(fore200e
, (struct sonet_stats __user
*)arg
);
1894 return put_user(0, (int __user
*)arg
) ? -EFAULT
: 0;
1897 return fore200e_setloop(fore200e
, (int)(unsigned long)arg
);
1900 return put_user(fore200e
->loop_mode
, (int __user
*)arg
) ? -EFAULT
: 0;
1903 return put_user(ATM_LM_LOC_PHY
| ATM_LM_RMT_PHY
, (int __user
*)arg
) ? -EFAULT
: 0;
1906 return -ENOSYS
; /* not implemented */
1911 fore200e_change_qos(struct atm_vcc
* vcc
,struct atm_qos
* qos
, int flags
)
1913 struct fore200e_vcc
* fore200e_vcc
= FORE200E_VCC(vcc
);
1914 struct fore200e
* fore200e
= FORE200E_DEV(vcc
->dev
);
1916 if (!test_bit(ATM_VF_READY
, &vcc
->flags
)) {
1917 DPRINTK(1, "VC %d.%d.%d not ready for QoS change\n", vcc
->itf
, vcc
->vpi
, vcc
->vpi
);
1921 DPRINTK(2, "change_qos %d.%d.%d, "
1922 "(tx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d; "
1923 "rx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d), flags = 0x%x\n"
1924 "available_cell_rate = %u",
1925 vcc
->itf
, vcc
->vpi
, vcc
->vci
,
1926 fore200e_traffic_class
[ qos
->txtp
.traffic_class
],
1927 qos
->txtp
.min_pcr
, qos
->txtp
.max_pcr
, qos
->txtp
.max_cdv
, qos
->txtp
.max_sdu
,
1928 fore200e_traffic_class
[ qos
->rxtp
.traffic_class
],
1929 qos
->rxtp
.min_pcr
, qos
->rxtp
.max_pcr
, qos
->rxtp
.max_cdv
, qos
->rxtp
.max_sdu
,
1930 flags
, fore200e
->available_cell_rate
);
1932 if ((qos
->txtp
.traffic_class
== ATM_CBR
) && (qos
->txtp
.max_pcr
> 0)) {
1934 mutex_lock(&fore200e
->rate_mtx
);
1935 if (fore200e
->available_cell_rate
+ vcc
->qos
.txtp
.max_pcr
< qos
->txtp
.max_pcr
) {
1936 mutex_unlock(&fore200e
->rate_mtx
);
1940 fore200e
->available_cell_rate
+= vcc
->qos
.txtp
.max_pcr
;
1941 fore200e
->available_cell_rate
-= qos
->txtp
.max_pcr
;
1943 mutex_unlock(&fore200e
->rate_mtx
);
1945 memcpy(&vcc
->qos
, qos
, sizeof(struct atm_qos
));
1947 /* update rate control parameters */
1948 fore200e_rate_ctrl(qos
, &fore200e_vcc
->rate
);
1950 set_bit(ATM_VF_HASQOS
, &vcc
->flags
);
1959 static int fore200e_irq_request(struct fore200e
*fore200e
)
1961 if (request_irq(fore200e
->irq
, fore200e_interrupt
, IRQF_SHARED
, fore200e
->name
, fore200e
->atm_dev
) < 0) {
1963 printk(FORE200E
"unable to reserve IRQ %s for device %s\n",
1964 fore200e_irq_itoa(fore200e
->irq
), fore200e
->name
);
1968 printk(FORE200E
"IRQ %s reserved for device %s\n",
1969 fore200e_irq_itoa(fore200e
->irq
), fore200e
->name
);
1971 #ifdef FORE200E_USE_TASKLET
1972 tasklet_init(&fore200e
->tx_tasklet
, fore200e_tx_tasklet
, (unsigned long)fore200e
);
1973 tasklet_init(&fore200e
->rx_tasklet
, fore200e_rx_tasklet
, (unsigned long)fore200e
);
1976 fore200e
->state
= FORE200E_STATE_IRQ
;
1981 static int fore200e_get_esi(struct fore200e
*fore200e
)
1983 struct prom_data
* prom
= kzalloc(sizeof(struct prom_data
), GFP_KERNEL
);
1989 ok
= fore200e
->bus
->prom_read(fore200e
, prom
);
1995 printk(FORE200E
"device %s, rev. %c, S/N: %d, ESI: %pM\n",
1997 (prom
->hw_revision
& 0xFF) + '@', /* probably meaningless with SBA boards */
1998 prom
->serial_number
& 0xFFFF, &prom
->mac_addr
[2]);
2000 for (i
= 0; i
< ESI_LEN
; i
++) {
2001 fore200e
->esi
[ i
] = fore200e
->atm_dev
->esi
[ i
] = prom
->mac_addr
[ i
+ 2 ];
2010 static int fore200e_alloc_rx_buf(struct fore200e
*fore200e
)
2012 int scheme
, magn
, nbr
, size
, i
;
2014 struct host_bsq
* bsq
;
2015 struct buffer
* buffer
;
2017 for (scheme
= 0; scheme
< BUFFER_SCHEME_NBR
; scheme
++) {
2018 for (magn
= 0; magn
< BUFFER_MAGN_NBR
; magn
++) {
2020 bsq
= &fore200e
->host_bsq
[ scheme
][ magn
];
2022 nbr
= fore200e_rx_buf_nbr
[ scheme
][ magn
];
2023 size
= fore200e_rx_buf_size
[ scheme
][ magn
];
2025 DPRINTK(2, "rx buffers %d / %d are being allocated\n", scheme
, magn
);
2027 /* allocate the array of receive buffers */
2028 buffer
= bsq
->buffer
= kcalloc(nbr
, sizeof(struct buffer
),
2034 bsq
->freebuf
= NULL
;
2036 for (i
= 0; i
< nbr
; i
++) {
2038 buffer
[ i
].scheme
= scheme
;
2039 buffer
[ i
].magn
= magn
;
2040 #ifdef FORE200E_BSQ_DEBUG
2041 buffer
[ i
].index
= i
;
2042 buffer
[ i
].supplied
= 0;
2045 /* allocate the receive buffer body */
2046 if (fore200e_chunk_alloc(fore200e
,
2047 &buffer
[ i
].data
, size
, fore200e
->bus
->buffer_alignment
,
2048 DMA_FROM_DEVICE
) < 0) {
2051 fore200e_chunk_free(fore200e
, &buffer
[ --i
].data
);
2057 /* insert the buffer into the free buffer list */
2058 buffer
[ i
].next
= bsq
->freebuf
;
2059 bsq
->freebuf
= &buffer
[ i
];
2061 /* all the buffers are free, initially */
2062 bsq
->freebuf_count
= nbr
;
2064 #ifdef FORE200E_BSQ_DEBUG
2065 bsq_audit(3, bsq
, scheme
, magn
);
2070 fore200e
->state
= FORE200E_STATE_ALLOC_BUF
;
2075 static int fore200e_init_bs_queue(struct fore200e
*fore200e
)
2077 int scheme
, magn
, i
;
2079 struct host_bsq
* bsq
;
2080 struct cp_bsq_entry __iomem
* cp_entry
;
2082 for (scheme
= 0; scheme
< BUFFER_SCHEME_NBR
; scheme
++) {
2083 for (magn
= 0; magn
< BUFFER_MAGN_NBR
; magn
++) {
2085 DPRINTK(2, "buffer supply queue %d / %d is being initialized\n", scheme
, magn
);
2087 bsq
= &fore200e
->host_bsq
[ scheme
][ magn
];
2089 /* allocate and align the array of status words */
2090 if (fore200e_dma_chunk_alloc(fore200e
,
2092 sizeof(enum status
),
2094 fore200e
->bus
->status_alignment
) < 0) {
2098 /* allocate and align the array of receive buffer descriptors */
2099 if (fore200e_dma_chunk_alloc(fore200e
,
2101 sizeof(struct rbd_block
),
2103 fore200e
->bus
->descr_alignment
) < 0) {
2105 fore200e_dma_chunk_free(fore200e
, &bsq
->status
);
2109 /* get the base address of the cp resident buffer supply queue entries */
2110 cp_entry
= fore200e
->virt_base
+
2111 fore200e
->bus
->read(&fore200e
->cp_queues
->cp_bsq
[ scheme
][ magn
]);
2113 /* fill the host resident and cp resident buffer supply queue entries */
2114 for (i
= 0; i
< QUEUE_SIZE_BS
; i
++) {
2116 bsq
->host_entry
[ i
].status
=
2117 FORE200E_INDEX(bsq
->status
.align_addr
, enum status
, i
);
2118 bsq
->host_entry
[ i
].rbd_block
=
2119 FORE200E_INDEX(bsq
->rbd_block
.align_addr
, struct rbd_block
, i
);
2120 bsq
->host_entry
[ i
].rbd_block_dma
=
2121 FORE200E_DMA_INDEX(bsq
->rbd_block
.dma_addr
, struct rbd_block
, i
);
2122 bsq
->host_entry
[ i
].cp_entry
= &cp_entry
[ i
];
2124 *bsq
->host_entry
[ i
].status
= STATUS_FREE
;
2126 fore200e
->bus
->write(FORE200E_DMA_INDEX(bsq
->status
.dma_addr
, enum status
, i
),
2127 &cp_entry
[ i
].status_haddr
);
2132 fore200e
->state
= FORE200E_STATE_INIT_BSQ
;
2137 static int fore200e_init_rx_queue(struct fore200e
*fore200e
)
2139 struct host_rxq
* rxq
= &fore200e
->host_rxq
;
2140 struct cp_rxq_entry __iomem
* cp_entry
;
2143 DPRINTK(2, "receive queue is being initialized\n");
2145 /* allocate and align the array of status words */
2146 if (fore200e_dma_chunk_alloc(fore200e
,
2148 sizeof(enum status
),
2150 fore200e
->bus
->status_alignment
) < 0) {
2154 /* allocate and align the array of receive PDU descriptors */
2155 if (fore200e_dma_chunk_alloc(fore200e
,
2159 fore200e
->bus
->descr_alignment
) < 0) {
2161 fore200e_dma_chunk_free(fore200e
, &rxq
->status
);
2165 /* get the base address of the cp resident rx queue entries */
2166 cp_entry
= fore200e
->virt_base
+ fore200e
->bus
->read(&fore200e
->cp_queues
->cp_rxq
);
2168 /* fill the host resident and cp resident rx entries */
2169 for (i
=0; i
< QUEUE_SIZE_RX
; i
++) {
2171 rxq
->host_entry
[ i
].status
=
2172 FORE200E_INDEX(rxq
->status
.align_addr
, enum status
, i
);
2173 rxq
->host_entry
[ i
].rpd
=
2174 FORE200E_INDEX(rxq
->rpd
.align_addr
, struct rpd
, i
);
2175 rxq
->host_entry
[ i
].rpd_dma
=
2176 FORE200E_DMA_INDEX(rxq
->rpd
.dma_addr
, struct rpd
, i
);
2177 rxq
->host_entry
[ i
].cp_entry
= &cp_entry
[ i
];
2179 *rxq
->host_entry
[ i
].status
= STATUS_FREE
;
2181 fore200e
->bus
->write(FORE200E_DMA_INDEX(rxq
->status
.dma_addr
, enum status
, i
),
2182 &cp_entry
[ i
].status_haddr
);
2184 fore200e
->bus
->write(FORE200E_DMA_INDEX(rxq
->rpd
.dma_addr
, struct rpd
, i
),
2185 &cp_entry
[ i
].rpd_haddr
);
2188 /* set the head entry of the queue */
2191 fore200e
->state
= FORE200E_STATE_INIT_RXQ
;
2196 static int fore200e_init_tx_queue(struct fore200e
*fore200e
)
2198 struct host_txq
* txq
= &fore200e
->host_txq
;
2199 struct cp_txq_entry __iomem
* cp_entry
;
2202 DPRINTK(2, "transmit queue is being initialized\n");
2204 /* allocate and align the array of status words */
2205 if (fore200e_dma_chunk_alloc(fore200e
,
2207 sizeof(enum status
),
2209 fore200e
->bus
->status_alignment
) < 0) {
2213 /* allocate and align the array of transmit PDU descriptors */
2214 if (fore200e_dma_chunk_alloc(fore200e
,
2218 fore200e
->bus
->descr_alignment
) < 0) {
2220 fore200e_dma_chunk_free(fore200e
, &txq
->status
);
2224 /* get the base address of the cp resident tx queue entries */
2225 cp_entry
= fore200e
->virt_base
+ fore200e
->bus
->read(&fore200e
->cp_queues
->cp_txq
);
2227 /* fill the host resident and cp resident tx entries */
2228 for (i
=0; i
< QUEUE_SIZE_TX
; i
++) {
2230 txq
->host_entry
[ i
].status
=
2231 FORE200E_INDEX(txq
->status
.align_addr
, enum status
, i
);
2232 txq
->host_entry
[ i
].tpd
=
2233 FORE200E_INDEX(txq
->tpd
.align_addr
, struct tpd
, i
);
2234 txq
->host_entry
[ i
].tpd_dma
=
2235 FORE200E_DMA_INDEX(txq
->tpd
.dma_addr
, struct tpd
, i
);
2236 txq
->host_entry
[ i
].cp_entry
= &cp_entry
[ i
];
2238 *txq
->host_entry
[ i
].status
= STATUS_FREE
;
2240 fore200e
->bus
->write(FORE200E_DMA_INDEX(txq
->status
.dma_addr
, enum status
, i
),
2241 &cp_entry
[ i
].status_haddr
);
2243 /* although there is a one-to-one mapping of tx queue entries and tpds,
2244 we do not write here the DMA (physical) base address of each tpd into
2245 the related cp resident entry, because the cp relies on this write
2246 operation to detect that a new pdu has been submitted for tx */
2249 /* set the head and tail entries of the queue */
2253 fore200e
->state
= FORE200E_STATE_INIT_TXQ
;
2258 static int fore200e_init_cmd_queue(struct fore200e
*fore200e
)
2260 struct host_cmdq
* cmdq
= &fore200e
->host_cmdq
;
2261 struct cp_cmdq_entry __iomem
* cp_entry
;
2264 DPRINTK(2, "command queue is being initialized\n");
2266 /* allocate and align the array of status words */
2267 if (fore200e_dma_chunk_alloc(fore200e
,
2269 sizeof(enum status
),
2271 fore200e
->bus
->status_alignment
) < 0) {
2275 /* get the base address of the cp resident cmd queue entries */
2276 cp_entry
= fore200e
->virt_base
+ fore200e
->bus
->read(&fore200e
->cp_queues
->cp_cmdq
);
2278 /* fill the host resident and cp resident cmd entries */
2279 for (i
=0; i
< QUEUE_SIZE_CMD
; i
++) {
2281 cmdq
->host_entry
[ i
].status
=
2282 FORE200E_INDEX(cmdq
->status
.align_addr
, enum status
, i
);
2283 cmdq
->host_entry
[ i
].cp_entry
= &cp_entry
[ i
];
2285 *cmdq
->host_entry
[ i
].status
= STATUS_FREE
;
2287 fore200e
->bus
->write(FORE200E_DMA_INDEX(cmdq
->status
.dma_addr
, enum status
, i
),
2288 &cp_entry
[ i
].status_haddr
);
2291 /* set the head entry of the queue */
2294 fore200e
->state
= FORE200E_STATE_INIT_CMDQ
;
2299 static void fore200e_param_bs_queue(struct fore200e
*fore200e
,
2300 enum buffer_scheme scheme
,
2301 enum buffer_magn magn
, int queue_length
,
2302 int pool_size
, int supply_blksize
)
2304 struct bs_spec __iomem
* bs_spec
= &fore200e
->cp_queues
->init
.bs_spec
[ scheme
][ magn
];
2306 fore200e
->bus
->write(queue_length
, &bs_spec
->queue_length
);
2307 fore200e
->bus
->write(fore200e_rx_buf_size
[ scheme
][ magn
], &bs_spec
->buffer_size
);
2308 fore200e
->bus
->write(pool_size
, &bs_spec
->pool_size
);
2309 fore200e
->bus
->write(supply_blksize
, &bs_spec
->supply_blksize
);
2313 static int fore200e_initialize(struct fore200e
*fore200e
)
2315 struct cp_queues __iomem
* cpq
;
2316 int ok
, scheme
, magn
;
2318 DPRINTK(2, "device %s being initialized\n", fore200e
->name
);
2320 mutex_init(&fore200e
->rate_mtx
);
2321 spin_lock_init(&fore200e
->q_lock
);
2323 cpq
= fore200e
->cp_queues
= fore200e
->virt_base
+ FORE200E_CP_QUEUES_OFFSET
;
2325 /* enable cp to host interrupts */
2326 fore200e
->bus
->write(1, &cpq
->imask
);
2328 if (fore200e
->bus
->irq_enable
)
2329 fore200e
->bus
->irq_enable(fore200e
);
2331 fore200e
->bus
->write(NBR_CONNECT
, &cpq
->init
.num_connect
);
2333 fore200e
->bus
->write(QUEUE_SIZE_CMD
, &cpq
->init
.cmd_queue_len
);
2334 fore200e
->bus
->write(QUEUE_SIZE_RX
, &cpq
->init
.rx_queue_len
);
2335 fore200e
->bus
->write(QUEUE_SIZE_TX
, &cpq
->init
.tx_queue_len
);
2337 fore200e
->bus
->write(RSD_EXTENSION
, &cpq
->init
.rsd_extension
);
2338 fore200e
->bus
->write(TSD_EXTENSION
, &cpq
->init
.tsd_extension
);
2340 for (scheme
= 0; scheme
< BUFFER_SCHEME_NBR
; scheme
++)
2341 for (magn
= 0; magn
< BUFFER_MAGN_NBR
; magn
++)
2342 fore200e_param_bs_queue(fore200e
, scheme
, magn
,
2344 fore200e_rx_buf_nbr
[ scheme
][ magn
],
2347 /* issue the initialize command */
2348 fore200e
->bus
->write(STATUS_PENDING
, &cpq
->init
.status
);
2349 fore200e
->bus
->write(OPCODE_INITIALIZE
, &cpq
->init
.opcode
);
2351 ok
= fore200e_io_poll(fore200e
, &cpq
->init
.status
, STATUS_COMPLETE
, 3000);
2353 printk(FORE200E
"device %s initialization failed\n", fore200e
->name
);
2357 printk(FORE200E
"device %s initialized\n", fore200e
->name
);
2359 fore200e
->state
= FORE200E_STATE_INITIALIZE
;
2364 static void fore200e_monitor_putc(struct fore200e
*fore200e
, char c
)
2366 struct cp_monitor __iomem
* monitor
= fore200e
->cp_monitor
;
2371 fore200e
->bus
->write(((u32
) c
) | FORE200E_CP_MONITOR_UART_AVAIL
, &monitor
->soft_uart
.send
);
2375 static int fore200e_monitor_getc(struct fore200e
*fore200e
)
2377 struct cp_monitor __iomem
* monitor
= fore200e
->cp_monitor
;
2378 unsigned long timeout
= jiffies
+ msecs_to_jiffies(50);
2381 while (time_before(jiffies
, timeout
)) {
2383 c
= (int) fore200e
->bus
->read(&monitor
->soft_uart
.recv
);
2385 if (c
& FORE200E_CP_MONITOR_UART_AVAIL
) {
2387 fore200e
->bus
->write(FORE200E_CP_MONITOR_UART_FREE
, &monitor
->soft_uart
.recv
);
2389 printk("%c", c
& 0xFF);
2399 static void fore200e_monitor_puts(struct fore200e
*fore200e
, char *str
)
2403 /* the i960 monitor doesn't accept any new character if it has something to say */
2404 while (fore200e_monitor_getc(fore200e
) >= 0);
2406 fore200e_monitor_putc(fore200e
, *str
++);
2409 while (fore200e_monitor_getc(fore200e
) >= 0);
2412 #ifdef __LITTLE_ENDIAN
2413 #define FW_EXT ".bin"
2415 #define FW_EXT "_ecd.bin2"
2418 static int fore200e_load_and_start_fw(struct fore200e
*fore200e
)
2420 const struct firmware
*firmware
;
2421 const struct fw_header
*fw_header
;
2422 const __le32
*fw_data
;
2424 u32 __iomem
*load_addr
;
2428 sprintf(buf
, "%s%s", fore200e
->bus
->proc_name
, FW_EXT
);
2429 if ((err
= request_firmware(&firmware
, buf
, fore200e
->dev
)) < 0) {
2430 printk(FORE200E
"problem loading firmware image %s\n", fore200e
->bus
->model_name
);
2434 fw_data
= (const __le32
*)firmware
->data
;
2435 fw_size
= firmware
->size
/ sizeof(u32
);
2436 fw_header
= (const struct fw_header
*)firmware
->data
;
2437 load_addr
= fore200e
->virt_base
+ le32_to_cpu(fw_header
->load_offset
);
2439 DPRINTK(2, "device %s firmware being loaded at 0x%p (%d words)\n",
2440 fore200e
->name
, load_addr
, fw_size
);
2442 if (le32_to_cpu(fw_header
->magic
) != FW_HEADER_MAGIC
) {
2443 printk(FORE200E
"corrupted %s firmware image\n", fore200e
->bus
->model_name
);
2447 for (; fw_size
--; fw_data
++, load_addr
++)
2448 fore200e
->bus
->write(le32_to_cpu(*fw_data
), load_addr
);
2450 DPRINTK(2, "device %s firmware being started\n", fore200e
->name
);
2452 #if defined(__sparc_v9__)
2453 /* reported to be required by SBA cards on some sparc64 hosts */
2457 sprintf(buf
, "\rgo %x\r", le32_to_cpu(fw_header
->start_offset
));
2458 fore200e_monitor_puts(fore200e
, buf
);
2460 if (fore200e_io_poll(fore200e
, &fore200e
->cp_monitor
->bstat
, BSTAT_CP_RUNNING
, 1000) == 0) {
2461 printk(FORE200E
"device %s firmware didn't start\n", fore200e
->name
);
2465 printk(FORE200E
"device %s firmware started\n", fore200e
->name
);
2467 fore200e
->state
= FORE200E_STATE_START_FW
;
2471 release_firmware(firmware
);
2476 static int fore200e_register(struct fore200e
*fore200e
, struct device
*parent
)
2478 struct atm_dev
* atm_dev
;
2480 DPRINTK(2, "device %s being registered\n", fore200e
->name
);
2482 atm_dev
= atm_dev_register(fore200e
->bus
->proc_name
, parent
, &fore200e_ops
,
2484 if (atm_dev
== NULL
) {
2485 printk(FORE200E
"unable to register device %s\n", fore200e
->name
);
2489 atm_dev
->dev_data
= fore200e
;
2490 fore200e
->atm_dev
= atm_dev
;
2492 atm_dev
->ci_range
.vpi_bits
= FORE200E_VPI_BITS
;
2493 atm_dev
->ci_range
.vci_bits
= FORE200E_VCI_BITS
;
2495 fore200e
->available_cell_rate
= ATM_OC3_PCR
;
2497 fore200e
->state
= FORE200E_STATE_REGISTER
;
2502 static int fore200e_init(struct fore200e
*fore200e
, struct device
*parent
)
2504 if (fore200e_register(fore200e
, parent
) < 0)
2507 if (fore200e
->bus
->configure(fore200e
) < 0)
2510 if (fore200e
->bus
->map(fore200e
) < 0)
2513 if (fore200e_reset(fore200e
, 1) < 0)
2516 if (fore200e_load_and_start_fw(fore200e
) < 0)
2519 if (fore200e_initialize(fore200e
) < 0)
2522 if (fore200e_init_cmd_queue(fore200e
) < 0)
2525 if (fore200e_init_tx_queue(fore200e
) < 0)
2528 if (fore200e_init_rx_queue(fore200e
) < 0)
2531 if (fore200e_init_bs_queue(fore200e
) < 0)
2534 if (fore200e_alloc_rx_buf(fore200e
) < 0)
2537 if (fore200e_get_esi(fore200e
) < 0)
2540 if (fore200e_irq_request(fore200e
) < 0)
2543 fore200e_supply(fore200e
);
2545 /* all done, board initialization is now complete */
2546 fore200e
->state
= FORE200E_STATE_COMPLETE
;
2551 static const struct of_device_id fore200e_sba_match
[];
2552 static int fore200e_sba_probe(struct platform_device
*op
)
2554 const struct of_device_id
*match
;
2555 struct fore200e
*fore200e
;
2556 static int index
= 0;
2559 match
= of_match_device(fore200e_sba_match
, &op
->dev
);
2563 fore200e
= kzalloc(sizeof(struct fore200e
), GFP_KERNEL
);
2567 fore200e
->bus
= &fore200e_sbus_ops
;
2568 fore200e
->dev
= &op
->dev
;
2569 fore200e
->irq
= op
->archdata
.irqs
[0];
2570 fore200e
->phys_base
= op
->resource
[0].start
;
2572 sprintf(fore200e
->name
, "SBA-200E-%d", index
);
2574 err
= fore200e_init(fore200e
, &op
->dev
);
2576 fore200e_shutdown(fore200e
);
2582 dev_set_drvdata(&op
->dev
, fore200e
);
2587 static int fore200e_sba_remove(struct platform_device
*op
)
2589 struct fore200e
*fore200e
= dev_get_drvdata(&op
->dev
);
2591 fore200e_shutdown(fore200e
);
2597 static const struct of_device_id fore200e_sba_match
[] = {
2599 .name
= SBA200E_PROM_NAME
,
2603 MODULE_DEVICE_TABLE(of
, fore200e_sba_match
);
2605 static struct platform_driver fore200e_sba_driver
= {
2607 .name
= "fore_200e",
2608 .of_match_table
= fore200e_sba_match
,
2610 .probe
= fore200e_sba_probe
,
2611 .remove
= fore200e_sba_remove
,
2616 static int fore200e_pca_detect(struct pci_dev
*pci_dev
,
2617 const struct pci_device_id
*pci_ent
)
2619 struct fore200e
* fore200e
;
2621 static int index
= 0;
2623 if (pci_enable_device(pci_dev
)) {
2628 if (dma_set_mask_and_coherent(&pci_dev
->dev
, DMA_BIT_MASK(32))) {
2633 fore200e
= kzalloc(sizeof(struct fore200e
), GFP_KERNEL
);
2634 if (fore200e
== NULL
) {
2639 fore200e
->bus
= &fore200e_pci_ops
;
2640 fore200e
->dev
= &pci_dev
->dev
;
2641 fore200e
->irq
= pci_dev
->irq
;
2642 fore200e
->phys_base
= pci_resource_start(pci_dev
, 0);
2644 sprintf(fore200e
->name
, "PCA-200E-%d", index
- 1);
2646 pci_set_master(pci_dev
);
2648 printk(FORE200E
"device PCA-200E found at 0x%lx, IRQ %s\n",
2649 fore200e
->phys_base
, fore200e_irq_itoa(fore200e
->irq
));
2651 sprintf(fore200e
->name
, "PCA-200E-%d", index
);
2653 err
= fore200e_init(fore200e
, &pci_dev
->dev
);
2655 fore200e_shutdown(fore200e
);
2660 pci_set_drvdata(pci_dev
, fore200e
);
2668 pci_disable_device(pci_dev
);
2673 static void fore200e_pca_remove_one(struct pci_dev
*pci_dev
)
2675 struct fore200e
*fore200e
;
2677 fore200e
= pci_get_drvdata(pci_dev
);
2679 fore200e_shutdown(fore200e
);
2681 pci_disable_device(pci_dev
);
2685 static const struct pci_device_id fore200e_pca_tbl
[] = {
2686 { PCI_VENDOR_ID_FORE
, PCI_DEVICE_ID_FORE_PCA200E
, PCI_ANY_ID
, PCI_ANY_ID
},
2690 MODULE_DEVICE_TABLE(pci
, fore200e_pca_tbl
);
2692 static struct pci_driver fore200e_pca_driver
= {
2693 .name
= "fore_200e",
2694 .probe
= fore200e_pca_detect
,
2695 .remove
= fore200e_pca_remove_one
,
2696 .id_table
= fore200e_pca_tbl
,
2700 static int __init
fore200e_module_init(void)
2704 printk(FORE200E
"FORE Systems 200E-series ATM driver - version " FORE200E_VERSION
"\n");
2707 err
= platform_driver_register(&fore200e_sba_driver
);
2713 err
= pci_register_driver(&fore200e_pca_driver
);
2718 platform_driver_unregister(&fore200e_sba_driver
);
2724 static void __exit
fore200e_module_cleanup(void)
2727 pci_unregister_driver(&fore200e_pca_driver
);
2730 platform_driver_unregister(&fore200e_sba_driver
);
2735 fore200e_proc_read(struct atm_dev
*dev
, loff_t
* pos
, char* page
)
2737 struct fore200e
* fore200e
= FORE200E_DEV(dev
);
2738 struct fore200e_vcc
* fore200e_vcc
;
2739 struct atm_vcc
* vcc
;
2740 int i
, len
, left
= *pos
;
2741 unsigned long flags
;
2745 if (fore200e_getstats(fore200e
) < 0)
2748 len
= sprintf(page
,"\n"
2750 " internal name:\t\t%s\n", fore200e
->name
);
2752 /* print bus-specific information */
2753 if (fore200e
->bus
->proc_read
)
2754 len
+= fore200e
->bus
->proc_read(fore200e
, page
+ len
);
2756 len
+= sprintf(page
+ len
,
2757 " interrupt line:\t\t%s\n"
2758 " physical base address:\t0x%p\n"
2759 " virtual base address:\t0x%p\n"
2760 " factory address (ESI):\t%pM\n"
2761 " board serial number:\t\t%d\n\n",
2762 fore200e_irq_itoa(fore200e
->irq
),
2763 (void*)fore200e
->phys_base
,
2764 fore200e
->virt_base
,
2766 fore200e
->esi
[4] * 256 + fore200e
->esi
[5]);
2772 return sprintf(page
,
2773 " free small bufs, scheme 1:\t%d\n"
2774 " free large bufs, scheme 1:\t%d\n"
2775 " free small bufs, scheme 2:\t%d\n"
2776 " free large bufs, scheme 2:\t%d\n",
2777 fore200e
->host_bsq
[ BUFFER_SCHEME_ONE
][ BUFFER_MAGN_SMALL
].freebuf_count
,
2778 fore200e
->host_bsq
[ BUFFER_SCHEME_ONE
][ BUFFER_MAGN_LARGE
].freebuf_count
,
2779 fore200e
->host_bsq
[ BUFFER_SCHEME_TWO
][ BUFFER_MAGN_SMALL
].freebuf_count
,
2780 fore200e
->host_bsq
[ BUFFER_SCHEME_TWO
][ BUFFER_MAGN_LARGE
].freebuf_count
);
2783 u32 hb
= fore200e
->bus
->read(&fore200e
->cp_queues
->heartbeat
);
2785 len
= sprintf(page
,"\n\n"
2786 " cell processor:\n"
2787 " heartbeat state:\t\t");
2789 if (hb
>> 16 != 0xDEAD)
2790 len
+= sprintf(page
+ len
, "0x%08x\n", hb
);
2792 len
+= sprintf(page
+ len
, "*** FATAL ERROR %04x ***\n", hb
& 0xFFFF);
2798 static const char* media_name
[] = {
2799 "unshielded twisted pair",
2800 "multimode optical fiber ST",
2801 "multimode optical fiber SC",
2802 "single-mode optical fiber ST",
2803 "single-mode optical fiber SC",
2807 static const char* oc3_mode
[] = {
2809 "diagnostic loopback",
2814 u32 fw_release
= fore200e
->bus
->read(&fore200e
->cp_queues
->fw_release
);
2815 u32 mon960_release
= fore200e
->bus
->read(&fore200e
->cp_queues
->mon960_release
);
2816 u32 oc3_revision
= fore200e
->bus
->read(&fore200e
->cp_queues
->oc3_revision
);
2817 u32 media_index
= FORE200E_MEDIA_INDEX(fore200e
->bus
->read(&fore200e
->cp_queues
->media_type
));
2820 if (media_index
> 4)
2823 switch (fore200e
->loop_mode
) {
2824 case ATM_LM_NONE
: oc3_index
= 0;
2826 case ATM_LM_LOC_PHY
: oc3_index
= 1;
2828 case ATM_LM_RMT_PHY
: oc3_index
= 2;
2830 default: oc3_index
= 3;
2833 return sprintf(page
,
2834 " firmware release:\t\t%d.%d.%d\n"
2835 " monitor release:\t\t%d.%d\n"
2836 " media type:\t\t\t%s\n"
2837 " OC-3 revision:\t\t0x%x\n"
2838 " OC-3 mode:\t\t\t%s",
2839 fw_release
>> 16, fw_release
<< 16 >> 24, fw_release
<< 24 >> 24,
2840 mon960_release
>> 16, mon960_release
<< 16 >> 16,
2841 media_name
[ media_index
],
2843 oc3_mode
[ oc3_index
]);
2847 struct cp_monitor __iomem
* cp_monitor
= fore200e
->cp_monitor
;
2849 return sprintf(page
,
2852 " version number:\t\t%d\n"
2853 " boot status word:\t\t0x%08x\n",
2854 fore200e
->bus
->read(&cp_monitor
->mon_version
),
2855 fore200e
->bus
->read(&cp_monitor
->bstat
));
2859 return sprintf(page
,
2861 " device statistics:\n"
2863 " crc_header_errors:\t\t%10u\n"
2864 " framing_errors:\t\t%10u\n",
2865 be32_to_cpu(fore200e
->stats
->phy
.crc_header_errors
),
2866 be32_to_cpu(fore200e
->stats
->phy
.framing_errors
));
2869 return sprintf(page
, "\n"
2871 " section_bip8_errors:\t%10u\n"
2872 " path_bip8_errors:\t\t%10u\n"
2873 " line_bip24_errors:\t\t%10u\n"
2874 " line_febe_errors:\t\t%10u\n"
2875 " path_febe_errors:\t\t%10u\n"
2876 " corr_hcs_errors:\t\t%10u\n"
2877 " ucorr_hcs_errors:\t\t%10u\n",
2878 be32_to_cpu(fore200e
->stats
->oc3
.section_bip8_errors
),
2879 be32_to_cpu(fore200e
->stats
->oc3
.path_bip8_errors
),
2880 be32_to_cpu(fore200e
->stats
->oc3
.line_bip24_errors
),
2881 be32_to_cpu(fore200e
->stats
->oc3
.line_febe_errors
),
2882 be32_to_cpu(fore200e
->stats
->oc3
.path_febe_errors
),
2883 be32_to_cpu(fore200e
->stats
->oc3
.corr_hcs_errors
),
2884 be32_to_cpu(fore200e
->stats
->oc3
.ucorr_hcs_errors
));
2887 return sprintf(page
,"\n"
2888 " ATM:\t\t\t\t cells\n"
2891 " vpi out of range:\t\t%10u\n"
2892 " vpi no conn:\t\t%10u\n"
2893 " vci out of range:\t\t%10u\n"
2894 " vci no conn:\t\t%10u\n",
2895 be32_to_cpu(fore200e
->stats
->atm
.cells_transmitted
),
2896 be32_to_cpu(fore200e
->stats
->atm
.cells_received
),
2897 be32_to_cpu(fore200e
->stats
->atm
.vpi_bad_range
),
2898 be32_to_cpu(fore200e
->stats
->atm
.vpi_no_conn
),
2899 be32_to_cpu(fore200e
->stats
->atm
.vci_bad_range
),
2900 be32_to_cpu(fore200e
->stats
->atm
.vci_no_conn
));
2903 return sprintf(page
,"\n"
2904 " AAL0:\t\t\t cells\n"
2907 " dropped:\t\t\t%10u\n",
2908 be32_to_cpu(fore200e
->stats
->aal0
.cells_transmitted
),
2909 be32_to_cpu(fore200e
->stats
->aal0
.cells_received
),
2910 be32_to_cpu(fore200e
->stats
->aal0
.cells_dropped
));
2913 return sprintf(page
,"\n"
2915 " SAR sublayer:\t\t cells\n"
2918 " dropped:\t\t\t%10u\n"
2919 " CRC errors:\t\t%10u\n"
2920 " protocol errors:\t\t%10u\n\n"
2921 " CS sublayer:\t\t PDUs\n"
2924 " dropped:\t\t\t%10u\n"
2925 " protocol errors:\t\t%10u\n",
2926 be32_to_cpu(fore200e
->stats
->aal34
.cells_transmitted
),
2927 be32_to_cpu(fore200e
->stats
->aal34
.cells_received
),
2928 be32_to_cpu(fore200e
->stats
->aal34
.cells_dropped
),
2929 be32_to_cpu(fore200e
->stats
->aal34
.cells_crc_errors
),
2930 be32_to_cpu(fore200e
->stats
->aal34
.cells_protocol_errors
),
2931 be32_to_cpu(fore200e
->stats
->aal34
.cspdus_transmitted
),
2932 be32_to_cpu(fore200e
->stats
->aal34
.cspdus_received
),
2933 be32_to_cpu(fore200e
->stats
->aal34
.cspdus_dropped
),
2934 be32_to_cpu(fore200e
->stats
->aal34
.cspdus_protocol_errors
));
2937 return sprintf(page
,"\n"
2939 " SAR sublayer:\t\t cells\n"
2942 " dropped:\t\t\t%10u\n"
2943 " congestions:\t\t%10u\n\n"
2944 " CS sublayer:\t\t PDUs\n"
2947 " dropped:\t\t\t%10u\n"
2948 " CRC errors:\t\t%10u\n"
2949 " protocol errors:\t\t%10u\n",
2950 be32_to_cpu(fore200e
->stats
->aal5
.cells_transmitted
),
2951 be32_to_cpu(fore200e
->stats
->aal5
.cells_received
),
2952 be32_to_cpu(fore200e
->stats
->aal5
.cells_dropped
),
2953 be32_to_cpu(fore200e
->stats
->aal5
.congestion_experienced
),
2954 be32_to_cpu(fore200e
->stats
->aal5
.cspdus_transmitted
),
2955 be32_to_cpu(fore200e
->stats
->aal5
.cspdus_received
),
2956 be32_to_cpu(fore200e
->stats
->aal5
.cspdus_dropped
),
2957 be32_to_cpu(fore200e
->stats
->aal5
.cspdus_crc_errors
),
2958 be32_to_cpu(fore200e
->stats
->aal5
.cspdus_protocol_errors
));
2961 return sprintf(page
,"\n"
2962 " AUX:\t\t allocation failures\n"
2963 " small b1:\t\t\t%10u\n"
2964 " large b1:\t\t\t%10u\n"
2965 " small b2:\t\t\t%10u\n"
2966 " large b2:\t\t\t%10u\n"
2967 " RX PDUs:\t\t\t%10u\n"
2968 " TX PDUs:\t\t\t%10lu\n",
2969 be32_to_cpu(fore200e
->stats
->aux
.small_b1_failed
),
2970 be32_to_cpu(fore200e
->stats
->aux
.large_b1_failed
),
2971 be32_to_cpu(fore200e
->stats
->aux
.small_b2_failed
),
2972 be32_to_cpu(fore200e
->stats
->aux
.large_b2_failed
),
2973 be32_to_cpu(fore200e
->stats
->aux
.rpd_alloc_failed
),
2977 return sprintf(page
,"\n"
2978 " receive carrier:\t\t\t%s\n",
2979 fore200e
->stats
->aux
.receive_carrier
? "ON" : "OFF!");
2982 return sprintf(page
,"\n"
2983 " VCCs:\n address VPI VCI AAL "
2984 "TX PDUs TX min/max size RX PDUs RX min/max size\n");
2987 for (i
= 0; i
< NBR_CONNECT
; i
++) {
2989 vcc
= fore200e
->vc_map
[i
].vcc
;
2994 spin_lock_irqsave(&fore200e
->q_lock
, flags
);
2996 if (vcc
&& test_bit(ATM_VF_READY
, &vcc
->flags
) && !left
--) {
2998 fore200e_vcc
= FORE200E_VCC(vcc
);
2999 ASSERT(fore200e_vcc
);
3002 " %pK %03d %05d %1d %09lu %05d/%05d %09lu %05d/%05d\n",
3004 vcc
->vpi
, vcc
->vci
, fore200e_atm2fore_aal(vcc
->qos
.aal
),
3005 fore200e_vcc
->tx_pdu
,
3006 fore200e_vcc
->tx_min_pdu
> 0xFFFF ? 0 : fore200e_vcc
->tx_min_pdu
,
3007 fore200e_vcc
->tx_max_pdu
,
3008 fore200e_vcc
->rx_pdu
,
3009 fore200e_vcc
->rx_min_pdu
> 0xFFFF ? 0 : fore200e_vcc
->rx_min_pdu
,
3010 fore200e_vcc
->rx_max_pdu
);
3012 spin_unlock_irqrestore(&fore200e
->q_lock
, flags
);
3016 spin_unlock_irqrestore(&fore200e
->q_lock
, flags
);
3022 module_init(fore200e_module_init
);
3023 module_exit(fore200e_module_cleanup
);
3026 static const struct atmdev_ops fore200e_ops
= {
3027 .open
= fore200e_open
,
3028 .close
= fore200e_close
,
3029 .ioctl
= fore200e_ioctl
,
3030 .getsockopt
= fore200e_getsockopt
,
3031 .setsockopt
= fore200e_setsockopt
,
3032 .send
= fore200e_send
,
3033 .change_qos
= fore200e_change_qos
,
3034 .proc_read
= fore200e_proc_read
,
3035 .owner
= THIS_MODULE
3038 MODULE_LICENSE("GPL");
3040 #ifdef __LITTLE_ENDIAN__
3041 MODULE_FIRMWARE("pca200e.bin");
3043 MODULE_FIRMWARE("pca200e_ecd.bin2");
3045 #endif /* CONFIG_PCI */
3047 MODULE_FIRMWARE("sba200e_ecd.bin2");