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 <asm/uaccess.h>
47 #include <asm/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 \
60 #define FORE200E_USE_TASKLET
64 #define FORE200E_52BYTE_AAL0_SDU
69 #define FORE200E_VERSION "0.3e"
71 #define FORE200E "fore200e: "
73 #if defined(CONFIG_ATM_FORE200E_DEBUG) && (CONFIG_ATM_FORE200E_DEBUG > 0)
74 #define DPRINTK(level, format, args...) do { if (CONFIG_ATM_FORE200E_DEBUG >= (level)) \
75 printk(FORE200E format, ##args); } while (0)
77 #define DPRINTK(level, format, args...) do {} while (0)
81 #define FORE200E_ALIGN(addr, alignment) \
82 ((((unsigned long)(addr) + (alignment - 1)) & ~(alignment - 1)) - (unsigned long)(addr))
84 #define FORE200E_DMA_INDEX(dma_addr, type, index) ((dma_addr) + (index) * sizeof(type))
86 #define FORE200E_INDEX(virt_addr, type, index) (&((type *)(virt_addr))[ index ])
88 #define FORE200E_NEXT_ENTRY(index, modulo) (index = ++(index) % (modulo))
90 #define ASSERT(expr) if (!(expr)) { \
91 printk(FORE200E "assertion failed! %s[%d]: %s\n", \
92 __func__, __LINE__, #expr); \
93 panic(FORE200E "%s", __func__); \
97 static const struct atmdev_ops fore200e_ops
;
98 static const struct fore200e_bus fore200e_bus
[];
100 static LIST_HEAD(fore200e_boards
);
103 MODULE_AUTHOR("Christophe Lizzi - credits to Uwe Dannowski and Heikki Vatiainen");
104 MODULE_DESCRIPTION("FORE Systems 200E-series ATM driver - version " FORE200E_VERSION
);
105 MODULE_SUPPORTED_DEVICE("PCA-200E, SBA-200E");
108 static const int fore200e_rx_buf_nbr
[ BUFFER_SCHEME_NBR
][ BUFFER_MAGN_NBR
] = {
109 { BUFFER_S1_NBR
, BUFFER_L1_NBR
},
110 { BUFFER_S2_NBR
, BUFFER_L2_NBR
}
113 static const int fore200e_rx_buf_size
[ BUFFER_SCHEME_NBR
][ BUFFER_MAGN_NBR
] = {
114 { BUFFER_S1_SIZE
, BUFFER_L1_SIZE
},
115 { BUFFER_S2_SIZE
, BUFFER_L2_SIZE
}
119 #if defined(CONFIG_ATM_FORE200E_DEBUG) && (CONFIG_ATM_FORE200E_DEBUG > 0)
120 static const char* fore200e_traffic_class
[] = { "NONE", "UBR", "CBR", "VBR", "ABR", "ANY" };
126 static enum fore200e_aal
127 fore200e_atm2fore_aal(int aal
)
130 case ATM_AAL0
: return FORE200E_AAL0
;
131 case ATM_AAL34
: return FORE200E_AAL34
;
134 case ATM_AAL5
: return FORE200E_AAL5
;
142 fore200e_irq_itoa(int irq
)
145 sprintf(str
, "%d", irq
);
150 /* allocate and align a chunk of memory intended to hold the data behing exchanged
151 between the driver and the adapter (using streaming DVMA) */
154 fore200e_chunk_alloc(struct fore200e
* fore200e
, struct chunk
* chunk
, int size
, int alignment
, int direction
)
156 unsigned long offset
= 0;
158 if (alignment
<= sizeof(int))
161 chunk
->alloc_size
= size
+ alignment
;
162 chunk
->align_size
= size
;
163 chunk
->direction
= direction
;
165 chunk
->alloc_addr
= kzalloc(chunk
->alloc_size
, GFP_KERNEL
| GFP_DMA
);
166 if (chunk
->alloc_addr
== NULL
)
170 offset
= FORE200E_ALIGN(chunk
->alloc_addr
, alignment
);
172 chunk
->align_addr
= chunk
->alloc_addr
+ offset
;
174 chunk
->dma_addr
= fore200e
->bus
->dma_map(fore200e
, chunk
->align_addr
, chunk
->align_size
, direction
);
180 /* free a chunk of memory */
183 fore200e_chunk_free(struct fore200e
* fore200e
, struct chunk
* chunk
)
185 fore200e
->bus
->dma_unmap(fore200e
, chunk
->dma_addr
, chunk
->dma_size
, chunk
->direction
);
187 kfree(chunk
->alloc_addr
);
192 fore200e_spin(int msecs
)
194 unsigned long timeout
= jiffies
+ msecs_to_jiffies(msecs
);
195 while (time_before(jiffies
, timeout
));
200 fore200e_poll(struct fore200e
* fore200e
, volatile u32
* addr
, u32 val
, int msecs
)
202 unsigned long timeout
= jiffies
+ msecs_to_jiffies(msecs
);
207 if ((ok
= (*addr
== val
)) || (*addr
& STATUS_ERROR
))
210 } while (time_before(jiffies
, timeout
));
213 printk(FORE200E
"cmd polling failed, got status 0x%08x, expected 0x%08x\n",
222 fore200e_io_poll(struct fore200e
* fore200e
, volatile u32 __iomem
*addr
, u32 val
, int msecs
)
224 unsigned long timeout
= jiffies
+ msecs_to_jiffies(msecs
);
228 if ((ok
= (fore200e
->bus
->read(addr
) == val
)))
231 } while (time_before(jiffies
, timeout
));
234 printk(FORE200E
"I/O polling failed, got status 0x%08x, expected 0x%08x\n",
235 fore200e
->bus
->read(addr
), val
);
243 fore200e_free_rx_buf(struct fore200e
* fore200e
)
245 int scheme
, magn
, nbr
;
246 struct buffer
* buffer
;
248 for (scheme
= 0; scheme
< BUFFER_SCHEME_NBR
; scheme
++) {
249 for (magn
= 0; magn
< BUFFER_MAGN_NBR
; magn
++) {
251 if ((buffer
= fore200e
->host_bsq
[ scheme
][ magn
].buffer
) != NULL
) {
253 for (nbr
= 0; nbr
< fore200e_rx_buf_nbr
[ scheme
][ magn
]; nbr
++) {
255 struct chunk
* data
= &buffer
[ nbr
].data
;
257 if (data
->alloc_addr
!= NULL
)
258 fore200e_chunk_free(fore200e
, data
);
267 fore200e_uninit_bs_queue(struct fore200e
* fore200e
)
271 for (scheme
= 0; scheme
< BUFFER_SCHEME_NBR
; scheme
++) {
272 for (magn
= 0; magn
< BUFFER_MAGN_NBR
; magn
++) {
274 struct chunk
* status
= &fore200e
->host_bsq
[ scheme
][ magn
].status
;
275 struct chunk
* rbd_block
= &fore200e
->host_bsq
[ scheme
][ magn
].rbd_block
;
277 if (status
->alloc_addr
)
278 fore200e
->bus
->dma_chunk_free(fore200e
, status
);
280 if (rbd_block
->alloc_addr
)
281 fore200e
->bus
->dma_chunk_free(fore200e
, rbd_block
);
288 fore200e_reset(struct fore200e
* fore200e
, int diag
)
292 fore200e
->cp_monitor
= fore200e
->virt_base
+ FORE200E_CP_MONITOR_OFFSET
;
294 fore200e
->bus
->write(BSTAT_COLD_START
, &fore200e
->cp_monitor
->bstat
);
296 fore200e
->bus
->reset(fore200e
);
299 ok
= fore200e_io_poll(fore200e
, &fore200e
->cp_monitor
->bstat
, BSTAT_SELFTEST_OK
, 1000);
302 printk(FORE200E
"device %s self-test failed\n", fore200e
->name
);
306 printk(FORE200E
"device %s self-test passed\n", fore200e
->name
);
308 fore200e
->state
= FORE200E_STATE_RESET
;
316 fore200e_shutdown(struct fore200e
* fore200e
)
318 printk(FORE200E
"removing device %s at 0x%lx, IRQ %s\n",
319 fore200e
->name
, fore200e
->phys_base
,
320 fore200e_irq_itoa(fore200e
->irq
));
322 if (fore200e
->state
> FORE200E_STATE_RESET
) {
323 /* first, reset the board to prevent further interrupts or data transfers */
324 fore200e_reset(fore200e
, 0);
327 /* then, release all allocated resources */
328 switch(fore200e
->state
) {
330 case FORE200E_STATE_COMPLETE
:
331 kfree(fore200e
->stats
);
333 case FORE200E_STATE_IRQ
:
334 free_irq(fore200e
->irq
, fore200e
->atm_dev
);
336 case FORE200E_STATE_ALLOC_BUF
:
337 fore200e_free_rx_buf(fore200e
);
339 case FORE200E_STATE_INIT_BSQ
:
340 fore200e_uninit_bs_queue(fore200e
);
342 case FORE200E_STATE_INIT_RXQ
:
343 fore200e
->bus
->dma_chunk_free(fore200e
, &fore200e
->host_rxq
.status
);
344 fore200e
->bus
->dma_chunk_free(fore200e
, &fore200e
->host_rxq
.rpd
);
346 case FORE200E_STATE_INIT_TXQ
:
347 fore200e
->bus
->dma_chunk_free(fore200e
, &fore200e
->host_txq
.status
);
348 fore200e
->bus
->dma_chunk_free(fore200e
, &fore200e
->host_txq
.tpd
);
350 case FORE200E_STATE_INIT_CMDQ
:
351 fore200e
->bus
->dma_chunk_free(fore200e
, &fore200e
->host_cmdq
.status
);
353 case FORE200E_STATE_INITIALIZE
:
354 /* nothing to do for that state */
356 case FORE200E_STATE_START_FW
:
357 /* nothing to do for that state */
359 case FORE200E_STATE_RESET
:
360 /* nothing to do for that state */
362 case FORE200E_STATE_MAP
:
363 fore200e
->bus
->unmap(fore200e
);
365 case FORE200E_STATE_CONFIGURE
:
366 /* nothing to do for that state */
368 case FORE200E_STATE_REGISTER
:
369 atm_dev_deregister(fore200e
->atm_dev
);
371 case FORE200E_STATE_BLANK
:
372 /* nothing to do for that state */
380 static u32
fore200e_pca_read(volatile u32 __iomem
*addr
)
382 /* on big-endian hosts, the board is configured to convert
383 the endianess of slave RAM accesses */
384 return le32_to_cpu(readl(addr
));
388 static void fore200e_pca_write(u32 val
, volatile u32 __iomem
*addr
)
390 /* on big-endian hosts, the board is configured to convert
391 the endianess of slave RAM accesses */
392 writel(cpu_to_le32(val
), addr
);
397 fore200e_pca_dma_map(struct fore200e
* fore200e
, void* virt_addr
, int size
, int direction
)
399 u32 dma_addr
= pci_map_single((struct pci_dev
*)fore200e
->bus_dev
, virt_addr
, size
, direction
);
401 DPRINTK(3, "PCI DVMA mapping: virt_addr = 0x%p, size = %d, direction = %d, --> dma_addr = 0x%08x\n",
402 virt_addr
, size
, direction
, dma_addr
);
409 fore200e_pca_dma_unmap(struct fore200e
* fore200e
, u32 dma_addr
, int size
, int direction
)
411 DPRINTK(3, "PCI DVMA unmapping: dma_addr = 0x%08x, size = %d, direction = %d\n",
412 dma_addr
, size
, direction
);
414 pci_unmap_single((struct pci_dev
*)fore200e
->bus_dev
, dma_addr
, size
, direction
);
419 fore200e_pca_dma_sync_for_cpu(struct fore200e
* fore200e
, u32 dma_addr
, int size
, int direction
)
421 DPRINTK(3, "PCI DVMA sync: dma_addr = 0x%08x, size = %d, direction = %d\n", dma_addr
, size
, direction
);
423 pci_dma_sync_single_for_cpu((struct pci_dev
*)fore200e
->bus_dev
, dma_addr
, size
, direction
);
427 fore200e_pca_dma_sync_for_device(struct fore200e
* fore200e
, u32 dma_addr
, int size
, int direction
)
429 DPRINTK(3, "PCI DVMA sync: dma_addr = 0x%08x, size = %d, direction = %d\n", dma_addr
, size
, direction
);
431 pci_dma_sync_single_for_device((struct pci_dev
*)fore200e
->bus_dev
, dma_addr
, size
, direction
);
435 /* allocate a DMA consistent chunk of memory intended to act as a communication mechanism
436 (to hold descriptors, status, queues, etc.) shared by the driver and the adapter */
439 fore200e_pca_dma_chunk_alloc(struct fore200e
* fore200e
, struct chunk
* chunk
,
440 int size
, int nbr
, int alignment
)
442 /* returned chunks are page-aligned */
443 chunk
->alloc_size
= size
* nbr
;
444 chunk
->alloc_addr
= pci_alloc_consistent((struct pci_dev
*)fore200e
->bus_dev
,
448 if ((chunk
->alloc_addr
== NULL
) || (chunk
->dma_addr
== 0))
451 chunk
->align_addr
= chunk
->alloc_addr
;
457 /* free a DMA consistent chunk of memory */
460 fore200e_pca_dma_chunk_free(struct fore200e
* fore200e
, struct chunk
* chunk
)
462 pci_free_consistent((struct pci_dev
*)fore200e
->bus_dev
,
470 fore200e_pca_irq_check(struct fore200e
* fore200e
)
472 /* this is a 1 bit register */
473 int irq_posted
= readl(fore200e
->regs
.pca
.psr
);
475 #if defined(CONFIG_ATM_FORE200E_DEBUG) && (CONFIG_ATM_FORE200E_DEBUG == 2)
476 if (irq_posted
&& (readl(fore200e
->regs
.pca
.hcr
) & PCA200E_HCR_OUTFULL
)) {
477 DPRINTK(2,"FIFO OUT full, device %d\n", fore200e
->atm_dev
->number
);
486 fore200e_pca_irq_ack(struct fore200e
* fore200e
)
488 writel(PCA200E_HCR_CLRINTR
, fore200e
->regs
.pca
.hcr
);
493 fore200e_pca_reset(struct fore200e
* fore200e
)
495 writel(PCA200E_HCR_RESET
, fore200e
->regs
.pca
.hcr
);
497 writel(0, fore200e
->regs
.pca
.hcr
);
502 fore200e_pca_map(struct fore200e
* fore200e
)
504 DPRINTK(2, "device %s being mapped in memory\n", fore200e
->name
);
506 fore200e
->virt_base
= ioremap(fore200e
->phys_base
, PCA200E_IOSPACE_LENGTH
);
508 if (fore200e
->virt_base
== NULL
) {
509 printk(FORE200E
"can't map device %s\n", fore200e
->name
);
513 DPRINTK(1, "device %s mapped to 0x%p\n", fore200e
->name
, fore200e
->virt_base
);
515 /* gain access to the PCA specific registers */
516 fore200e
->regs
.pca
.hcr
= fore200e
->virt_base
+ PCA200E_HCR_OFFSET
;
517 fore200e
->regs
.pca
.imr
= fore200e
->virt_base
+ PCA200E_IMR_OFFSET
;
518 fore200e
->regs
.pca
.psr
= fore200e
->virt_base
+ PCA200E_PSR_OFFSET
;
520 fore200e
->state
= FORE200E_STATE_MAP
;
526 fore200e_pca_unmap(struct fore200e
* fore200e
)
528 DPRINTK(2, "device %s being unmapped from memory\n", fore200e
->name
);
530 if (fore200e
->virt_base
!= NULL
)
531 iounmap(fore200e
->virt_base
);
536 fore200e_pca_configure(struct fore200e
* fore200e
)
538 struct pci_dev
* pci_dev
= (struct pci_dev
*)fore200e
->bus_dev
;
539 u8 master_ctrl
, latency
;
541 DPRINTK(2, "device %s being configured\n", fore200e
->name
);
543 if ((pci_dev
->irq
== 0) || (pci_dev
->irq
== 0xFF)) {
544 printk(FORE200E
"incorrect IRQ setting - misconfigured PCI-PCI bridge?\n");
548 pci_read_config_byte(pci_dev
, PCA200E_PCI_MASTER_CTRL
, &master_ctrl
);
550 master_ctrl
= master_ctrl
551 #if defined(__BIG_ENDIAN)
552 /* request the PCA board to convert the endianess of slave RAM accesses */
553 | PCA200E_CTRL_CONVERT_ENDIAN
555 | PCA200E_CTRL_LARGE_PCI_BURSTS
;
557 pci_write_config_byte(pci_dev
, PCA200E_PCI_MASTER_CTRL
, master_ctrl
);
559 /* raise latency from 32 (default) to 192, as this seems to prevent NIC
560 lockups (under heavy rx loads) due to continuous 'FIFO OUT full' condition.
561 this may impact the performances of other PCI devices on the same bus, though */
563 pci_write_config_byte(pci_dev
, PCI_LATENCY_TIMER
, latency
);
565 fore200e
->state
= FORE200E_STATE_CONFIGURE
;
571 fore200e_pca_prom_read(struct fore200e
* fore200e
, struct prom_data
* prom
)
573 struct host_cmdq
* cmdq
= &fore200e
->host_cmdq
;
574 struct host_cmdq_entry
* entry
= &cmdq
->host_entry
[ cmdq
->head
];
575 struct prom_opcode opcode
;
579 FORE200E_NEXT_ENTRY(cmdq
->head
, QUEUE_SIZE_CMD
);
581 opcode
.opcode
= OPCODE_GET_PROM
;
584 prom_dma
= fore200e
->bus
->dma_map(fore200e
, prom
, sizeof(struct prom_data
), DMA_FROM_DEVICE
);
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 fore200e
->bus
->dma_unmap(fore200e
, 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
= (struct pci_dev
*)fore200e
->bus_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 #endif /* CONFIG_PCI */
630 static u32
fore200e_sba_read(volatile u32 __iomem
*addr
)
632 return sbus_readl(addr
);
635 static void fore200e_sba_write(u32 val
, volatile u32 __iomem
*addr
)
637 sbus_writel(val
, addr
);
640 static u32
fore200e_sba_dma_map(struct fore200e
*fore200e
, void* virt_addr
, int size
, int direction
)
642 struct platform_device
*op
= fore200e
->bus_dev
;
645 dma_addr
= dma_map_single(&op
->dev
, virt_addr
, size
, direction
);
647 DPRINTK(3, "SBUS DVMA mapping: virt_addr = 0x%p, size = %d, direction = %d --> dma_addr = 0x%08x\n",
648 virt_addr
, size
, direction
, dma_addr
);
653 static void fore200e_sba_dma_unmap(struct fore200e
*fore200e
, u32 dma_addr
, int size
, int direction
)
655 struct platform_device
*op
= fore200e
->bus_dev
;
657 DPRINTK(3, "SBUS DVMA unmapping: dma_addr = 0x%08x, size = %d, direction = %d,\n",
658 dma_addr
, size
, direction
);
660 dma_unmap_single(&op
->dev
, dma_addr
, size
, direction
);
663 static void fore200e_sba_dma_sync_for_cpu(struct fore200e
*fore200e
, u32 dma_addr
, int size
, int direction
)
665 struct platform_device
*op
= fore200e
->bus_dev
;
667 DPRINTK(3, "SBUS DVMA sync: dma_addr = 0x%08x, size = %d, direction = %d\n", dma_addr
, size
, direction
);
669 dma_sync_single_for_cpu(&op
->dev
, dma_addr
, size
, direction
);
672 static void fore200e_sba_dma_sync_for_device(struct fore200e
*fore200e
, u32 dma_addr
, int size
, int direction
)
674 struct platform_device
*op
= fore200e
->bus_dev
;
676 DPRINTK(3, "SBUS DVMA sync: dma_addr = 0x%08x, size = %d, direction = %d\n", dma_addr
, size
, direction
);
678 dma_sync_single_for_device(&op
->dev
, dma_addr
, size
, direction
);
681 /* Allocate a DVMA consistent chunk of memory intended to act as a communication mechanism
682 * (to hold descriptors, status, queues, etc.) shared by the driver and the adapter.
684 static int fore200e_sba_dma_chunk_alloc(struct fore200e
*fore200e
, struct chunk
*chunk
,
685 int size
, int nbr
, int alignment
)
687 struct platform_device
*op
= fore200e
->bus_dev
;
689 chunk
->alloc_size
= chunk
->align_size
= size
* nbr
;
691 /* returned chunks are page-aligned */
692 chunk
->alloc_addr
= dma_alloc_coherent(&op
->dev
, chunk
->alloc_size
,
693 &chunk
->dma_addr
, GFP_ATOMIC
);
695 if ((chunk
->alloc_addr
== NULL
) || (chunk
->dma_addr
== 0))
698 chunk
->align_addr
= chunk
->alloc_addr
;
703 /* free a DVMA consistent chunk of memory */
704 static void fore200e_sba_dma_chunk_free(struct fore200e
*fore200e
, struct chunk
*chunk
)
706 struct platform_device
*op
= fore200e
->bus_dev
;
708 dma_free_coherent(&op
->dev
, chunk
->alloc_size
,
709 chunk
->alloc_addr
, chunk
->dma_addr
);
712 static void fore200e_sba_irq_enable(struct fore200e
*fore200e
)
714 u32 hcr
= fore200e
->bus
->read(fore200e
->regs
.sba
.hcr
) & SBA200E_HCR_STICKY
;
715 fore200e
->bus
->write(hcr
| SBA200E_HCR_INTR_ENA
, fore200e
->regs
.sba
.hcr
);
718 static int fore200e_sba_irq_check(struct fore200e
*fore200e
)
720 return fore200e
->bus
->read(fore200e
->regs
.sba
.hcr
) & SBA200E_HCR_INTR_REQ
;
723 static void fore200e_sba_irq_ack(struct fore200e
*fore200e
)
725 u32 hcr
= fore200e
->bus
->read(fore200e
->regs
.sba
.hcr
) & SBA200E_HCR_STICKY
;
726 fore200e
->bus
->write(hcr
| SBA200E_HCR_INTR_CLR
, fore200e
->regs
.sba
.hcr
);
729 static void fore200e_sba_reset(struct fore200e
*fore200e
)
731 fore200e
->bus
->write(SBA200E_HCR_RESET
, fore200e
->regs
.sba
.hcr
);
733 fore200e
->bus
->write(0, fore200e
->regs
.sba
.hcr
);
736 static int __init
fore200e_sba_map(struct fore200e
*fore200e
)
738 struct platform_device
*op
= fore200e
->bus_dev
;
741 /* gain access to the SBA specific registers */
742 fore200e
->regs
.sba
.hcr
= of_ioremap(&op
->resource
[0], 0, SBA200E_HCR_LENGTH
, "SBA HCR");
743 fore200e
->regs
.sba
.bsr
= of_ioremap(&op
->resource
[1], 0, SBA200E_BSR_LENGTH
, "SBA BSR");
744 fore200e
->regs
.sba
.isr
= of_ioremap(&op
->resource
[2], 0, SBA200E_ISR_LENGTH
, "SBA ISR");
745 fore200e
->virt_base
= of_ioremap(&op
->resource
[3], 0, SBA200E_RAM_LENGTH
, "SBA RAM");
747 if (!fore200e
->virt_base
) {
748 printk(FORE200E
"unable to map RAM of device %s\n", fore200e
->name
);
752 DPRINTK(1, "device %s mapped to 0x%p\n", fore200e
->name
, fore200e
->virt_base
);
754 fore200e
->bus
->write(0x02, fore200e
->regs
.sba
.isr
);
756 /* get the supported DVMA burst sizes */
757 bursts
= of_getintprop_default(op
->dev
.of_node
->parent
, "burst-sizes", 0x00);
759 if (sbus_can_dma_64bit())
760 sbus_set_sbus64(&op
->dev
, bursts
);
762 fore200e
->state
= FORE200E_STATE_MAP
;
766 static void fore200e_sba_unmap(struct fore200e
*fore200e
)
768 struct platform_device
*op
= fore200e
->bus_dev
;
770 of_iounmap(&op
->resource
[0], fore200e
->regs
.sba
.hcr
, SBA200E_HCR_LENGTH
);
771 of_iounmap(&op
->resource
[1], fore200e
->regs
.sba
.bsr
, SBA200E_BSR_LENGTH
);
772 of_iounmap(&op
->resource
[2], fore200e
->regs
.sba
.isr
, SBA200E_ISR_LENGTH
);
773 of_iounmap(&op
->resource
[3], fore200e
->virt_base
, SBA200E_RAM_LENGTH
);
776 static int __init
fore200e_sba_configure(struct fore200e
*fore200e
)
778 fore200e
->state
= FORE200E_STATE_CONFIGURE
;
782 static int __init
fore200e_sba_prom_read(struct fore200e
*fore200e
, struct prom_data
*prom
)
784 struct platform_device
*op
= fore200e
->bus_dev
;
788 prop
= of_get_property(op
->dev
.of_node
, "madaddrlo2", &len
);
791 memcpy(&prom
->mac_addr
[4], prop
, 4);
793 prop
= of_get_property(op
->dev
.of_node
, "madaddrhi4", &len
);
796 memcpy(&prom
->mac_addr
[2], prop
, 4);
798 prom
->serial_number
= of_getintprop_default(op
->dev
.of_node
,
800 prom
->hw_revision
= of_getintprop_default(op
->dev
.of_node
,
806 static int fore200e_sba_proc_read(struct fore200e
*fore200e
, char *page
)
808 struct platform_device
*op
= fore200e
->bus_dev
;
809 const struct linux_prom_registers
*regs
;
811 regs
= of_get_property(op
->dev
.of_node
, "reg", NULL
);
813 return sprintf(page
, " SBUS slot/device:\t\t%d/'%s'\n",
814 (regs
? regs
->which_io
: 0), op
->dev
.of_node
->name
);
816 #endif /* CONFIG_SBUS */
820 fore200e_tx_irq(struct fore200e
* fore200e
)
822 struct host_txq
* txq
= &fore200e
->host_txq
;
823 struct host_txq_entry
* entry
;
825 struct fore200e_vc_map
* vc_map
;
827 if (fore200e
->host_txq
.txing
== 0)
832 entry
= &txq
->host_entry
[ txq
->tail
];
834 if ((*entry
->status
& STATUS_COMPLETE
) == 0) {
838 DPRINTK(3, "TX COMPLETED: entry = %p [tail = %d], vc_map = %p, skb = %p\n",
839 entry
, txq
->tail
, entry
->vc_map
, entry
->skb
);
841 /* free copy of misaligned data */
844 /* remove DMA mapping */
845 fore200e
->bus
->dma_unmap(fore200e
, entry
->tpd
->tsd
[ 0 ].buffer
, entry
->tpd
->tsd
[ 0 ].length
,
848 vc_map
= entry
->vc_map
;
850 /* vcc closed since the time the entry was submitted for tx? */
851 if ((vc_map
->vcc
== NULL
) ||
852 (test_bit(ATM_VF_READY
, &vc_map
->vcc
->flags
) == 0)) {
854 DPRINTK(1, "no ready vcc found for PDU sent on device %d\n",
855 fore200e
->atm_dev
->number
);
857 dev_kfree_skb_any(entry
->skb
);
862 /* vcc closed then immediately re-opened? */
863 if (vc_map
->incarn
!= entry
->incarn
) {
865 /* when a vcc is closed, some PDUs may be still pending in the tx queue.
866 if the same vcc is immediately re-opened, those pending PDUs must
867 not be popped after the completion of their emission, as they refer
868 to the prior incarnation of that vcc. otherwise, sk_atm(vcc)->sk_wmem_alloc
869 would be decremented by the size of the (unrelated) skb, possibly
870 leading to a negative sk->sk_wmem_alloc count, ultimately freezing the vcc.
871 we thus bind the tx entry to the current incarnation of the vcc
872 when the entry is submitted for tx. When the tx later completes,
873 if the incarnation number of the tx entry does not match the one
874 of the vcc, then this implies that the vcc has been closed then re-opened.
875 we thus just drop the skb here. */
877 DPRINTK(1, "vcc closed-then-re-opened; dropping PDU sent on device %d\n",
878 fore200e
->atm_dev
->number
);
880 dev_kfree_skb_any(entry
->skb
);
886 /* notify tx completion */
888 vcc
->pop(vcc
, entry
->skb
);
891 dev_kfree_skb_any(entry
->skb
);
893 /* race fixed by the above incarnation mechanism, but... */
894 if (atomic_read(&sk_atm(vcc
)->sk_wmem_alloc
) < 0) {
895 atomic_set(&sk_atm(vcc
)->sk_wmem_alloc
, 0);
897 /* check error condition */
898 if (*entry
->status
& STATUS_ERROR
)
899 atomic_inc(&vcc
->stats
->tx_err
);
901 atomic_inc(&vcc
->stats
->tx
);
905 *entry
->status
= STATUS_FREE
;
907 fore200e
->host_txq
.txing
--;
909 FORE200E_NEXT_ENTRY(txq
->tail
, QUEUE_SIZE_TX
);
914 #ifdef FORE200E_BSQ_DEBUG
915 int bsq_audit(int where
, struct host_bsq
* bsq
, int scheme
, int magn
)
917 struct buffer
* buffer
;
920 buffer
= bsq
->freebuf
;
923 if (buffer
->supplied
) {
924 printk(FORE200E
"bsq_audit(%d): queue %d.%d, buffer %ld supplied but in free list!\n",
925 where
, scheme
, magn
, buffer
->index
);
928 if (buffer
->magn
!= magn
) {
929 printk(FORE200E
"bsq_audit(%d): queue %d.%d, buffer %ld, unexpected magn = %d\n",
930 where
, scheme
, magn
, buffer
->index
, buffer
->magn
);
933 if (buffer
->scheme
!= scheme
) {
934 printk(FORE200E
"bsq_audit(%d): queue %d.%d, buffer %ld, unexpected scheme = %d\n",
935 where
, scheme
, magn
, buffer
->index
, buffer
->scheme
);
938 if ((buffer
->index
< 0) || (buffer
->index
>= fore200e_rx_buf_nbr
[ scheme
][ magn
])) {
939 printk(FORE200E
"bsq_audit(%d): queue %d.%d, out of range buffer index = %ld !\n",
940 where
, scheme
, magn
, buffer
->index
);
944 buffer
= buffer
->next
;
947 if (count
!= bsq
->freebuf_count
) {
948 printk(FORE200E
"bsq_audit(%d): queue %d.%d, %d bufs in free list, but freebuf_count = %d\n",
949 where
, scheme
, magn
, count
, bsq
->freebuf_count
);
957 fore200e_supply(struct fore200e
* fore200e
)
961 struct host_bsq
* bsq
;
962 struct host_bsq_entry
* entry
;
963 struct buffer
* buffer
;
965 for (scheme
= 0; scheme
< BUFFER_SCHEME_NBR
; scheme
++) {
966 for (magn
= 0; magn
< BUFFER_MAGN_NBR
; magn
++) {
968 bsq
= &fore200e
->host_bsq
[ scheme
][ magn
];
970 #ifdef FORE200E_BSQ_DEBUG
971 bsq_audit(1, bsq
, scheme
, magn
);
973 while (bsq
->freebuf_count
>= RBD_BLK_SIZE
) {
975 DPRINTK(2, "supplying %d rx buffers to queue %d / %d, freebuf_count = %d\n",
976 RBD_BLK_SIZE
, scheme
, magn
, bsq
->freebuf_count
);
978 entry
= &bsq
->host_entry
[ bsq
->head
];
980 for (i
= 0; i
< RBD_BLK_SIZE
; i
++) {
982 /* take the first buffer in the free buffer list */
983 buffer
= bsq
->freebuf
;
985 printk(FORE200E
"no more free bufs in queue %d.%d, but freebuf_count = %d\n",
986 scheme
, magn
, bsq
->freebuf_count
);
989 bsq
->freebuf
= buffer
->next
;
991 #ifdef FORE200E_BSQ_DEBUG
992 if (buffer
->supplied
)
993 printk(FORE200E
"queue %d.%d, buffer %lu already supplied\n",
994 scheme
, magn
, buffer
->index
);
995 buffer
->supplied
= 1;
997 entry
->rbd_block
->rbd
[ i
].buffer_haddr
= buffer
->data
.dma_addr
;
998 entry
->rbd_block
->rbd
[ i
].handle
= FORE200E_BUF2HDL(buffer
);
1001 FORE200E_NEXT_ENTRY(bsq
->head
, QUEUE_SIZE_BS
);
1003 /* decrease accordingly the number of free rx buffers */
1004 bsq
->freebuf_count
-= RBD_BLK_SIZE
;
1006 *entry
->status
= STATUS_PENDING
;
1007 fore200e
->bus
->write(entry
->rbd_block_dma
, &entry
->cp_entry
->rbd_block_haddr
);
1015 fore200e_push_rpd(struct fore200e
* fore200e
, struct atm_vcc
* vcc
, struct rpd
* rpd
)
1017 struct sk_buff
* skb
;
1018 struct buffer
* buffer
;
1019 struct fore200e_vcc
* fore200e_vcc
;
1021 #ifdef FORE200E_52BYTE_AAL0_SDU
1022 u32 cell_header
= 0;
1027 fore200e_vcc
= FORE200E_VCC(vcc
);
1028 ASSERT(fore200e_vcc
);
1030 #ifdef FORE200E_52BYTE_AAL0_SDU
1031 if ((vcc
->qos
.aal
== ATM_AAL0
) && (vcc
->qos
.rxtp
.max_sdu
== ATM_AAL0_SDU
)) {
1033 cell_header
= (rpd
->atm_header
.gfc
<< ATM_HDR_GFC_SHIFT
) |
1034 (rpd
->atm_header
.vpi
<< ATM_HDR_VPI_SHIFT
) |
1035 (rpd
->atm_header
.vci
<< ATM_HDR_VCI_SHIFT
) |
1036 (rpd
->atm_header
.plt
<< ATM_HDR_PTI_SHIFT
) |
1037 rpd
->atm_header
.clp
;
1042 /* compute total PDU length */
1043 for (i
= 0; i
< rpd
->nseg
; i
++)
1044 pdu_len
+= rpd
->rsd
[ i
].length
;
1046 skb
= alloc_skb(pdu_len
, GFP_ATOMIC
);
1048 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len
);
1050 atomic_inc(&vcc
->stats
->rx_drop
);
1054 __net_timestamp(skb
);
1056 #ifdef FORE200E_52BYTE_AAL0_SDU
1058 *((u32
*)skb_put(skb
, 4)) = cell_header
;
1062 /* reassemble segments */
1063 for (i
= 0; i
< rpd
->nseg
; i
++) {
1065 /* rebuild rx buffer address from rsd handle */
1066 buffer
= FORE200E_HDL2BUF(rpd
->rsd
[ i
].handle
);
1068 /* Make device DMA transfer visible to CPU. */
1069 fore200e
->bus
->dma_sync_for_cpu(fore200e
, buffer
->data
.dma_addr
, rpd
->rsd
[ i
].length
, DMA_FROM_DEVICE
);
1071 memcpy(skb_put(skb
, rpd
->rsd
[ i
].length
), buffer
->data
.align_addr
, rpd
->rsd
[ i
].length
);
1073 /* Now let the device get at it again. */
1074 fore200e
->bus
->dma_sync_for_device(fore200e
, buffer
->data
.dma_addr
, rpd
->rsd
[ i
].length
, DMA_FROM_DEVICE
);
1077 DPRINTK(3, "rx skb: len = %d, truesize = %d\n", skb
->len
, skb
->truesize
);
1079 if (pdu_len
< fore200e_vcc
->rx_min_pdu
)
1080 fore200e_vcc
->rx_min_pdu
= pdu_len
;
1081 if (pdu_len
> fore200e_vcc
->rx_max_pdu
)
1082 fore200e_vcc
->rx_max_pdu
= pdu_len
;
1083 fore200e_vcc
->rx_pdu
++;
1086 if (atm_charge(vcc
, skb
->truesize
) == 0) {
1088 DPRINTK(2, "receive buffers saturated for %d.%d.%d - PDU dropped\n",
1089 vcc
->itf
, vcc
->vpi
, vcc
->vci
);
1091 dev_kfree_skb_any(skb
);
1093 atomic_inc(&vcc
->stats
->rx_drop
);
1097 ASSERT(atomic_read(&sk_atm(vcc
)->sk_wmem_alloc
) >= 0);
1099 vcc
->push(vcc
, skb
);
1100 atomic_inc(&vcc
->stats
->rx
);
1102 ASSERT(atomic_read(&sk_atm(vcc
)->sk_wmem_alloc
) >= 0);
1109 fore200e_collect_rpd(struct fore200e
* fore200e
, struct rpd
* rpd
)
1111 struct host_bsq
* bsq
;
1112 struct buffer
* buffer
;
1115 for (i
= 0; i
< rpd
->nseg
; i
++) {
1117 /* rebuild rx buffer address from rsd handle */
1118 buffer
= FORE200E_HDL2BUF(rpd
->rsd
[ i
].handle
);
1120 bsq
= &fore200e
->host_bsq
[ buffer
->scheme
][ buffer
->magn
];
1122 #ifdef FORE200E_BSQ_DEBUG
1123 bsq_audit(2, bsq
, buffer
->scheme
, buffer
->magn
);
1125 if (buffer
->supplied
== 0)
1126 printk(FORE200E
"queue %d.%d, buffer %ld was not supplied\n",
1127 buffer
->scheme
, buffer
->magn
, buffer
->index
);
1128 buffer
->supplied
= 0;
1131 /* re-insert the buffer into the free buffer list */
1132 buffer
->next
= bsq
->freebuf
;
1133 bsq
->freebuf
= buffer
;
1135 /* then increment the number of free rx buffers */
1136 bsq
->freebuf_count
++;
1142 fore200e_rx_irq(struct fore200e
* fore200e
)
1144 struct host_rxq
* rxq
= &fore200e
->host_rxq
;
1145 struct host_rxq_entry
* entry
;
1146 struct atm_vcc
* vcc
;
1147 struct fore200e_vc_map
* vc_map
;
1151 entry
= &rxq
->host_entry
[ rxq
->head
];
1153 /* no more received PDUs */
1154 if ((*entry
->status
& STATUS_COMPLETE
) == 0)
1157 vc_map
= FORE200E_VC_MAP(fore200e
, entry
->rpd
->atm_header
.vpi
, entry
->rpd
->atm_header
.vci
);
1159 if ((vc_map
->vcc
== NULL
) ||
1160 (test_bit(ATM_VF_READY
, &vc_map
->vcc
->flags
) == 0)) {
1162 DPRINTK(1, "no ready VC found for PDU received on %d.%d.%d\n",
1163 fore200e
->atm_dev
->number
,
1164 entry
->rpd
->atm_header
.vpi
, entry
->rpd
->atm_header
.vci
);
1170 if ((*entry
->status
& STATUS_ERROR
) == 0) {
1172 fore200e_push_rpd(fore200e
, vcc
, entry
->rpd
);
1175 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
1176 fore200e
->atm_dev
->number
,
1177 entry
->rpd
->atm_header
.vpi
, entry
->rpd
->atm_header
.vci
);
1178 atomic_inc(&vcc
->stats
->rx_err
);
1182 FORE200E_NEXT_ENTRY(rxq
->head
, QUEUE_SIZE_RX
);
1184 fore200e_collect_rpd(fore200e
, entry
->rpd
);
1186 /* rewrite the rpd address to ack the received PDU */
1187 fore200e
->bus
->write(entry
->rpd_dma
, &entry
->cp_entry
->rpd_haddr
);
1188 *entry
->status
= STATUS_FREE
;
1190 fore200e_supply(fore200e
);
1195 #ifndef FORE200E_USE_TASKLET
1197 fore200e_irq(struct fore200e
* fore200e
)
1199 unsigned long flags
;
1201 spin_lock_irqsave(&fore200e
->q_lock
, flags
);
1202 fore200e_rx_irq(fore200e
);
1203 spin_unlock_irqrestore(&fore200e
->q_lock
, flags
);
1205 spin_lock_irqsave(&fore200e
->q_lock
, flags
);
1206 fore200e_tx_irq(fore200e
);
1207 spin_unlock_irqrestore(&fore200e
->q_lock
, flags
);
1213 fore200e_interrupt(int irq
, void* dev
)
1215 struct fore200e
* fore200e
= FORE200E_DEV((struct atm_dev
*)dev
);
1217 if (fore200e
->bus
->irq_check(fore200e
) == 0) {
1219 DPRINTK(3, "interrupt NOT triggered by device %d\n", fore200e
->atm_dev
->number
);
1222 DPRINTK(3, "interrupt triggered by device %d\n", fore200e
->atm_dev
->number
);
1224 #ifdef FORE200E_USE_TASKLET
1225 tasklet_schedule(&fore200e
->tx_tasklet
);
1226 tasklet_schedule(&fore200e
->rx_tasklet
);
1228 fore200e_irq(fore200e
);
1231 fore200e
->bus
->irq_ack(fore200e
);
1236 #ifdef FORE200E_USE_TASKLET
1238 fore200e_tx_tasklet(unsigned long data
)
1240 struct fore200e
* fore200e
= (struct fore200e
*) data
;
1241 unsigned long flags
;
1243 DPRINTK(3, "tx tasklet scheduled for device %d\n", fore200e
->atm_dev
->number
);
1245 spin_lock_irqsave(&fore200e
->q_lock
, flags
);
1246 fore200e_tx_irq(fore200e
);
1247 spin_unlock_irqrestore(&fore200e
->q_lock
, flags
);
1252 fore200e_rx_tasklet(unsigned long data
)
1254 struct fore200e
* fore200e
= (struct fore200e
*) data
;
1255 unsigned long flags
;
1257 DPRINTK(3, "rx tasklet scheduled for device %d\n", fore200e
->atm_dev
->number
);
1259 spin_lock_irqsave(&fore200e
->q_lock
, flags
);
1260 fore200e_rx_irq((struct fore200e
*) data
);
1261 spin_unlock_irqrestore(&fore200e
->q_lock
, flags
);
1267 fore200e_select_scheme(struct atm_vcc
* vcc
)
1269 /* fairly balance the VCs over (identical) buffer schemes */
1270 int scheme
= vcc
->vci
% 2 ? BUFFER_SCHEME_ONE
: BUFFER_SCHEME_TWO
;
1272 DPRINTK(1, "VC %d.%d.%d uses buffer scheme %d\n",
1273 vcc
->itf
, vcc
->vpi
, vcc
->vci
, scheme
);
1280 fore200e_activate_vcin(struct fore200e
* fore200e
, int activate
, struct atm_vcc
* vcc
, int mtu
)
1282 struct host_cmdq
* cmdq
= &fore200e
->host_cmdq
;
1283 struct host_cmdq_entry
* entry
= &cmdq
->host_entry
[ cmdq
->head
];
1284 struct activate_opcode activ_opcode
;
1285 struct deactivate_opcode deactiv_opcode
;
1288 enum fore200e_aal aal
= fore200e_atm2fore_aal(vcc
->qos
.aal
);
1290 FORE200E_NEXT_ENTRY(cmdq
->head
, QUEUE_SIZE_CMD
);
1293 FORE200E_VCC(vcc
)->scheme
= fore200e_select_scheme(vcc
);
1295 activ_opcode
.opcode
= OPCODE_ACTIVATE_VCIN
;
1296 activ_opcode
.aal
= aal
;
1297 activ_opcode
.scheme
= FORE200E_VCC(vcc
)->scheme
;
1298 activ_opcode
.pad
= 0;
1301 deactiv_opcode
.opcode
= OPCODE_DEACTIVATE_VCIN
;
1302 deactiv_opcode
.pad
= 0;
1305 vpvc
.vci
= vcc
->vci
;
1306 vpvc
.vpi
= vcc
->vpi
;
1308 *entry
->status
= STATUS_PENDING
;
1312 #ifdef FORE200E_52BYTE_AAL0_SDU
1315 /* the MTU is not used by the cp, except in the case of AAL0 */
1316 fore200e
->bus
->write(mtu
, &entry
->cp_entry
->cmd
.activate_block
.mtu
);
1317 fore200e
->bus
->write(*(u32
*)&vpvc
, (u32 __iomem
*)&entry
->cp_entry
->cmd
.activate_block
.vpvc
);
1318 fore200e
->bus
->write(*(u32
*)&activ_opcode
, (u32 __iomem
*)&entry
->cp_entry
->cmd
.activate_block
.opcode
);
1321 fore200e
->bus
->write(*(u32
*)&vpvc
, (u32 __iomem
*)&entry
->cp_entry
->cmd
.deactivate_block
.vpvc
);
1322 fore200e
->bus
->write(*(u32
*)&deactiv_opcode
, (u32 __iomem
*)&entry
->cp_entry
->cmd
.deactivate_block
.opcode
);
1325 ok
= fore200e_poll(fore200e
, entry
->status
, STATUS_COMPLETE
, 400);
1327 *entry
->status
= STATUS_FREE
;
1330 printk(FORE200E
"unable to %s VC %d.%d.%d\n",
1331 activate
? "open" : "close", vcc
->itf
, vcc
->vpi
, vcc
->vci
);
1335 DPRINTK(1, "VC %d.%d.%d %sed\n", vcc
->itf
, vcc
->vpi
, vcc
->vci
,
1336 activate
? "open" : "clos");
1342 #define FORE200E_MAX_BACK2BACK_CELLS 255
1345 fore200e_rate_ctrl(struct atm_qos
* qos
, struct tpd_rate
* rate
)
1347 if (qos
->txtp
.max_pcr
< ATM_OC3_PCR
) {
1349 /* compute the data cells to idle cells ratio from the tx PCR */
1350 rate
->data_cells
= qos
->txtp
.max_pcr
* FORE200E_MAX_BACK2BACK_CELLS
/ ATM_OC3_PCR
;
1351 rate
->idle_cells
= FORE200E_MAX_BACK2BACK_CELLS
- rate
->data_cells
;
1354 /* disable rate control */
1355 rate
->data_cells
= rate
->idle_cells
= 0;
1361 fore200e_open(struct atm_vcc
*vcc
)
1363 struct fore200e
* fore200e
= FORE200E_DEV(vcc
->dev
);
1364 struct fore200e_vcc
* fore200e_vcc
;
1365 struct fore200e_vc_map
* vc_map
;
1366 unsigned long flags
;
1368 short vpi
= vcc
->vpi
;
1370 ASSERT((vpi
>= 0) && (vpi
< 1<<FORE200E_VPI_BITS
));
1371 ASSERT((vci
>= 0) && (vci
< 1<<FORE200E_VCI_BITS
));
1373 spin_lock_irqsave(&fore200e
->q_lock
, flags
);
1375 vc_map
= FORE200E_VC_MAP(fore200e
, vpi
, vci
);
1378 spin_unlock_irqrestore(&fore200e
->q_lock
, flags
);
1380 printk(FORE200E
"VC %d.%d.%d already in use\n",
1381 fore200e
->atm_dev
->number
, vpi
, vci
);
1388 spin_unlock_irqrestore(&fore200e
->q_lock
, flags
);
1390 fore200e_vcc
= kzalloc(sizeof(struct fore200e_vcc
), GFP_ATOMIC
);
1391 if (fore200e_vcc
== NULL
) {
1396 DPRINTK(2, "opening %d.%d.%d:%d QoS = (tx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d; "
1397 "rx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d)\n",
1398 vcc
->itf
, vcc
->vpi
, vcc
->vci
, fore200e_atm2fore_aal(vcc
->qos
.aal
),
1399 fore200e_traffic_class
[ vcc
->qos
.txtp
.traffic_class
],
1400 vcc
->qos
.txtp
.min_pcr
, vcc
->qos
.txtp
.max_pcr
, vcc
->qos
.txtp
.max_cdv
, vcc
->qos
.txtp
.max_sdu
,
1401 fore200e_traffic_class
[ vcc
->qos
.rxtp
.traffic_class
],
1402 vcc
->qos
.rxtp
.min_pcr
, vcc
->qos
.rxtp
.max_pcr
, vcc
->qos
.rxtp
.max_cdv
, vcc
->qos
.rxtp
.max_sdu
);
1404 /* pseudo-CBR bandwidth requested? */
1405 if ((vcc
->qos
.txtp
.traffic_class
== ATM_CBR
) && (vcc
->qos
.txtp
.max_pcr
> 0)) {
1407 mutex_lock(&fore200e
->rate_mtx
);
1408 if (fore200e
->available_cell_rate
< vcc
->qos
.txtp
.max_pcr
) {
1409 mutex_unlock(&fore200e
->rate_mtx
);
1411 kfree(fore200e_vcc
);
1416 /* reserve bandwidth */
1417 fore200e
->available_cell_rate
-= vcc
->qos
.txtp
.max_pcr
;
1418 mutex_unlock(&fore200e
->rate_mtx
);
1421 vcc
->itf
= vcc
->dev
->number
;
1423 set_bit(ATM_VF_PARTIAL
,&vcc
->flags
);
1424 set_bit(ATM_VF_ADDR
, &vcc
->flags
);
1426 vcc
->dev_data
= fore200e_vcc
;
1428 if (fore200e_activate_vcin(fore200e
, 1, vcc
, vcc
->qos
.rxtp
.max_sdu
) < 0) {
1432 clear_bit(ATM_VF_ADDR
, &vcc
->flags
);
1433 clear_bit(ATM_VF_PARTIAL
,&vcc
->flags
);
1435 vcc
->dev_data
= NULL
;
1437 fore200e
->available_cell_rate
+= vcc
->qos
.txtp
.max_pcr
;
1439 kfree(fore200e_vcc
);
1443 /* compute rate control parameters */
1444 if ((vcc
->qos
.txtp
.traffic_class
== ATM_CBR
) && (vcc
->qos
.txtp
.max_pcr
> 0)) {
1446 fore200e_rate_ctrl(&vcc
->qos
, &fore200e_vcc
->rate
);
1447 set_bit(ATM_VF_HASQOS
, &vcc
->flags
);
1449 DPRINTK(3, "tx on %d.%d.%d:%d, tx PCR = %d, rx PCR = %d, data_cells = %u, idle_cells = %u\n",
1450 vcc
->itf
, vcc
->vpi
, vcc
->vci
, fore200e_atm2fore_aal(vcc
->qos
.aal
),
1451 vcc
->qos
.txtp
.max_pcr
, vcc
->qos
.rxtp
.max_pcr
,
1452 fore200e_vcc
->rate
.data_cells
, fore200e_vcc
->rate
.idle_cells
);
1455 fore200e_vcc
->tx_min_pdu
= fore200e_vcc
->rx_min_pdu
= MAX_PDU_SIZE
+ 1;
1456 fore200e_vcc
->tx_max_pdu
= fore200e_vcc
->rx_max_pdu
= 0;
1457 fore200e_vcc
->tx_pdu
= fore200e_vcc
->rx_pdu
= 0;
1459 /* new incarnation of the vcc */
1460 vc_map
->incarn
= ++fore200e
->incarn_count
;
1462 /* VC unusable before this flag is set */
1463 set_bit(ATM_VF_READY
, &vcc
->flags
);
1470 fore200e_close(struct atm_vcc
* vcc
)
1472 struct fore200e
* fore200e
= FORE200E_DEV(vcc
->dev
);
1473 struct fore200e_vcc
* fore200e_vcc
;
1474 struct fore200e_vc_map
* vc_map
;
1475 unsigned long flags
;
1478 ASSERT((vcc
->vpi
>= 0) && (vcc
->vpi
< 1<<FORE200E_VPI_BITS
));
1479 ASSERT((vcc
->vci
>= 0) && (vcc
->vci
< 1<<FORE200E_VCI_BITS
));
1481 DPRINTK(2, "closing %d.%d.%d:%d\n", vcc
->itf
, vcc
->vpi
, vcc
->vci
, fore200e_atm2fore_aal(vcc
->qos
.aal
));
1483 clear_bit(ATM_VF_READY
, &vcc
->flags
);
1485 fore200e_activate_vcin(fore200e
, 0, vcc
, 0);
1487 spin_lock_irqsave(&fore200e
->q_lock
, flags
);
1489 vc_map
= FORE200E_VC_MAP(fore200e
, vcc
->vpi
, vcc
->vci
);
1491 /* the vc is no longer considered as "in use" by fore200e_open() */
1494 vcc
->itf
= vcc
->vci
= vcc
->vpi
= 0;
1496 fore200e_vcc
= FORE200E_VCC(vcc
);
1497 vcc
->dev_data
= NULL
;
1499 spin_unlock_irqrestore(&fore200e
->q_lock
, flags
);
1501 /* release reserved bandwidth, if any */
1502 if ((vcc
->qos
.txtp
.traffic_class
== ATM_CBR
) && (vcc
->qos
.txtp
.max_pcr
> 0)) {
1504 mutex_lock(&fore200e
->rate_mtx
);
1505 fore200e
->available_cell_rate
+= vcc
->qos
.txtp
.max_pcr
;
1506 mutex_unlock(&fore200e
->rate_mtx
);
1508 clear_bit(ATM_VF_HASQOS
, &vcc
->flags
);
1511 clear_bit(ATM_VF_ADDR
, &vcc
->flags
);
1512 clear_bit(ATM_VF_PARTIAL
,&vcc
->flags
);
1514 ASSERT(fore200e_vcc
);
1515 kfree(fore200e_vcc
);
1520 fore200e_send(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
1522 struct fore200e
* fore200e
= FORE200E_DEV(vcc
->dev
);
1523 struct fore200e_vcc
* fore200e_vcc
= FORE200E_VCC(vcc
);
1524 struct fore200e_vc_map
* vc_map
;
1525 struct host_txq
* txq
= &fore200e
->host_txq
;
1526 struct host_txq_entry
* entry
;
1528 struct tpd_haddr tpd_haddr
;
1529 int retry
= CONFIG_ATM_FORE200E_TX_RETRY
;
1531 int tx_len
= skb
->len
;
1532 u32
* cell_header
= NULL
;
1533 unsigned char* skb_data
;
1535 unsigned char* data
;
1536 unsigned long flags
;
1539 ASSERT(atomic_read(&sk_atm(vcc
)->sk_wmem_alloc
) >= 0);
1541 ASSERT(fore200e_vcc
);
1543 if (!test_bit(ATM_VF_READY
, &vcc
->flags
)) {
1544 DPRINTK(1, "VC %d.%d.%d not ready for tx\n", vcc
->itf
, vcc
->vpi
, vcc
->vpi
);
1545 dev_kfree_skb_any(skb
);
1549 #ifdef FORE200E_52BYTE_AAL0_SDU
1550 if ((vcc
->qos
.aal
== ATM_AAL0
) && (vcc
->qos
.txtp
.max_sdu
== ATM_AAL0_SDU
)) {
1551 cell_header
= (u32
*) skb
->data
;
1552 skb_data
= skb
->data
+ 4; /* skip 4-byte cell header */
1553 skb_len
= tx_len
= skb
->len
- 4;
1555 DPRINTK(3, "user-supplied cell header = 0x%08x\n", *cell_header
);
1560 skb_data
= skb
->data
;
1564 if (((unsigned long)skb_data
) & 0x3) {
1566 DPRINTK(2, "misaligned tx PDU on device %s\n", fore200e
->name
);
1571 if ((vcc
->qos
.aal
== ATM_AAL0
) && (skb_len
% ATM_CELL_PAYLOAD
)) {
1573 /* this simply NUKES the PCA board */
1574 DPRINTK(2, "incomplete tx AAL0 PDU on device %s\n", fore200e
->name
);
1576 tx_len
= ((skb_len
/ ATM_CELL_PAYLOAD
) + 1) * ATM_CELL_PAYLOAD
;
1580 data
= kmalloc(tx_len
, GFP_ATOMIC
| GFP_DMA
);
1586 dev_kfree_skb_any(skb
);
1591 memcpy(data
, skb_data
, skb_len
);
1592 if (skb_len
< tx_len
)
1593 memset(data
+ skb_len
, 0x00, tx_len
- skb_len
);
1599 vc_map
= FORE200E_VC_MAP(fore200e
, vcc
->vpi
, vcc
->vci
);
1600 ASSERT(vc_map
->vcc
== vcc
);
1604 spin_lock_irqsave(&fore200e
->q_lock
, flags
);
1606 entry
= &txq
->host_entry
[ txq
->head
];
1608 if ((*entry
->status
!= STATUS_FREE
) || (txq
->txing
>= QUEUE_SIZE_TX
- 2)) {
1610 /* try to free completed tx queue entries */
1611 fore200e_tx_irq(fore200e
);
1613 if (*entry
->status
!= STATUS_FREE
) {
1615 spin_unlock_irqrestore(&fore200e
->q_lock
, flags
);
1617 /* retry once again? */
1623 atomic_inc(&vcc
->stats
->tx_err
);
1626 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
1627 fore200e
->name
, fore200e
->cp_queues
->heartbeat
);
1632 dev_kfree_skb_any(skb
);
1642 entry
->incarn
= vc_map
->incarn
;
1643 entry
->vc_map
= vc_map
;
1645 entry
->data
= tx_copy
? data
: NULL
;
1648 tpd
->tsd
[ 0 ].buffer
= fore200e
->bus
->dma_map(fore200e
, data
, tx_len
, DMA_TO_DEVICE
);
1649 tpd
->tsd
[ 0 ].length
= tx_len
;
1651 FORE200E_NEXT_ENTRY(txq
->head
, QUEUE_SIZE_TX
);
1654 /* The dma_map call above implies a dma_sync so the device can use it,
1655 * thus no explicit dma_sync call is necessary here.
1658 DPRINTK(3, "tx on %d.%d.%d:%d, len = %u (%u)\n",
1659 vcc
->itf
, vcc
->vpi
, vcc
->vci
, fore200e_atm2fore_aal(vcc
->qos
.aal
),
1660 tpd
->tsd
[0].length
, skb_len
);
1662 if (skb_len
< fore200e_vcc
->tx_min_pdu
)
1663 fore200e_vcc
->tx_min_pdu
= skb_len
;
1664 if (skb_len
> fore200e_vcc
->tx_max_pdu
)
1665 fore200e_vcc
->tx_max_pdu
= skb_len
;
1666 fore200e_vcc
->tx_pdu
++;
1668 /* set tx rate control information */
1669 tpd
->rate
.data_cells
= fore200e_vcc
->rate
.data_cells
;
1670 tpd
->rate
.idle_cells
= fore200e_vcc
->rate
.idle_cells
;
1673 tpd
->atm_header
.clp
= (*cell_header
& ATM_HDR_CLP
);
1674 tpd
->atm_header
.plt
= (*cell_header
& ATM_HDR_PTI_MASK
) >> ATM_HDR_PTI_SHIFT
;
1675 tpd
->atm_header
.vci
= (*cell_header
& ATM_HDR_VCI_MASK
) >> ATM_HDR_VCI_SHIFT
;
1676 tpd
->atm_header
.vpi
= (*cell_header
& ATM_HDR_VPI_MASK
) >> ATM_HDR_VPI_SHIFT
;
1677 tpd
->atm_header
.gfc
= (*cell_header
& ATM_HDR_GFC_MASK
) >> ATM_HDR_GFC_SHIFT
;
1680 /* set the ATM header, common to all cells conveying the PDU */
1681 tpd
->atm_header
.clp
= 0;
1682 tpd
->atm_header
.plt
= 0;
1683 tpd
->atm_header
.vci
= vcc
->vci
;
1684 tpd
->atm_header
.vpi
= vcc
->vpi
;
1685 tpd
->atm_header
.gfc
= 0;
1688 tpd
->spec
.length
= tx_len
;
1690 tpd
->spec
.aal
= fore200e_atm2fore_aal(vcc
->qos
.aal
);
1693 tpd_haddr
.size
= sizeof(struct tpd
) / (1<<TPD_HADDR_SHIFT
); /* size is expressed in 32 byte blocks */
1695 tpd_haddr
.haddr
= entry
->tpd_dma
>> TPD_HADDR_SHIFT
; /* shift the address, as we are in a bitfield */
1697 *entry
->status
= STATUS_PENDING
;
1698 fore200e
->bus
->write(*(u32
*)&tpd_haddr
, (u32 __iomem
*)&entry
->cp_entry
->tpd_haddr
);
1700 spin_unlock_irqrestore(&fore200e
->q_lock
, flags
);
1707 fore200e_getstats(struct fore200e
* fore200e
)
1709 struct host_cmdq
* cmdq
= &fore200e
->host_cmdq
;
1710 struct host_cmdq_entry
* entry
= &cmdq
->host_entry
[ cmdq
->head
];
1711 struct stats_opcode opcode
;
1715 if (fore200e
->stats
== NULL
) {
1716 fore200e
->stats
= kzalloc(sizeof(struct stats
), GFP_KERNEL
| GFP_DMA
);
1717 if (fore200e
->stats
== NULL
)
1721 stats_dma_addr
= fore200e
->bus
->dma_map(fore200e
, fore200e
->stats
,
1722 sizeof(struct stats
), DMA_FROM_DEVICE
);
1724 FORE200E_NEXT_ENTRY(cmdq
->head
, QUEUE_SIZE_CMD
);
1726 opcode
.opcode
= OPCODE_GET_STATS
;
1729 fore200e
->bus
->write(stats_dma_addr
, &entry
->cp_entry
->cmd
.stats_block
.stats_haddr
);
1731 *entry
->status
= STATUS_PENDING
;
1733 fore200e
->bus
->write(*(u32
*)&opcode
, (u32 __iomem
*)&entry
->cp_entry
->cmd
.stats_block
.opcode
);
1735 ok
= fore200e_poll(fore200e
, entry
->status
, STATUS_COMPLETE
, 400);
1737 *entry
->status
= STATUS_FREE
;
1739 fore200e
->bus
->dma_unmap(fore200e
, stats_dma_addr
, sizeof(struct stats
), DMA_FROM_DEVICE
);
1742 printk(FORE200E
"unable to get statistics from device %s\n", fore200e
->name
);
1751 fore200e_getsockopt(struct atm_vcc
* vcc
, int level
, int optname
, void __user
*optval
, int optlen
)
1753 /* struct fore200e* fore200e = FORE200E_DEV(vcc->dev); */
1755 DPRINTK(2, "getsockopt %d.%d.%d, level = %d, optname = 0x%x, optval = 0x%p, optlen = %d\n",
1756 vcc
->itf
, vcc
->vpi
, vcc
->vci
, level
, optname
, optval
, optlen
);
1763 fore200e_setsockopt(struct atm_vcc
* vcc
, int level
, int optname
, void __user
*optval
, unsigned int optlen
)
1765 /* struct fore200e* fore200e = FORE200E_DEV(vcc->dev); */
1767 DPRINTK(2, "setsockopt %d.%d.%d, level = %d, optname = 0x%x, optval = 0x%p, optlen = %d\n",
1768 vcc
->itf
, vcc
->vpi
, vcc
->vci
, level
, optname
, optval
, optlen
);
1777 fore200e_set_oc3(struct fore200e
* fore200e
, u32 reg
, u32 value
, u32 mask
)
1779 struct host_cmdq
* cmdq
= &fore200e
->host_cmdq
;
1780 struct host_cmdq_entry
* entry
= &cmdq
->host_entry
[ cmdq
->head
];
1781 struct oc3_opcode opcode
;
1784 DPRINTK(2, "set OC-3 reg = 0x%02x, value = 0x%02x, mask = 0x%02x\n", reg
, value
, mask
);
1786 FORE200E_NEXT_ENTRY(cmdq
->head
, QUEUE_SIZE_CMD
);
1788 opcode
.opcode
= OPCODE_SET_OC3
;
1790 opcode
.value
= value
;
1793 fore200e
->bus
->write(0, &entry
->cp_entry
->cmd
.oc3_block
.regs_haddr
);
1795 *entry
->status
= STATUS_PENDING
;
1797 fore200e
->bus
->write(*(u32
*)&opcode
, (u32 __iomem
*)&entry
->cp_entry
->cmd
.oc3_block
.opcode
);
1799 ok
= fore200e_poll(fore200e
, entry
->status
, STATUS_COMPLETE
, 400);
1801 *entry
->status
= STATUS_FREE
;
1804 printk(FORE200E
"unable to set OC-3 reg 0x%02x of device %s\n", reg
, fore200e
->name
);
1813 fore200e_setloop(struct fore200e
* fore200e
, int loop_mode
)
1815 u32 mct_value
, mct_mask
;
1818 if (!capable(CAP_NET_ADMIN
))
1821 switch (loop_mode
) {
1825 mct_mask
= SUNI_MCT_DLE
| SUNI_MCT_LLE
;
1828 case ATM_LM_LOC_PHY
:
1829 mct_value
= mct_mask
= SUNI_MCT_DLE
;
1832 case ATM_LM_RMT_PHY
:
1833 mct_value
= mct_mask
= SUNI_MCT_LLE
;
1840 error
= fore200e_set_oc3(fore200e
, SUNI_MCT
, mct_value
, mct_mask
);
1842 fore200e
->loop_mode
= loop_mode
;
1849 fore200e_fetch_stats(struct fore200e
* fore200e
, struct sonet_stats __user
*arg
)
1851 struct sonet_stats tmp
;
1853 if (fore200e_getstats(fore200e
) < 0)
1856 tmp
.section_bip
= be32_to_cpu(fore200e
->stats
->oc3
.section_bip8_errors
);
1857 tmp
.line_bip
= be32_to_cpu(fore200e
->stats
->oc3
.line_bip24_errors
);
1858 tmp
.path_bip
= be32_to_cpu(fore200e
->stats
->oc3
.path_bip8_errors
);
1859 tmp
.line_febe
= be32_to_cpu(fore200e
->stats
->oc3
.line_febe_errors
);
1860 tmp
.path_febe
= be32_to_cpu(fore200e
->stats
->oc3
.path_febe_errors
);
1861 tmp
.corr_hcs
= be32_to_cpu(fore200e
->stats
->oc3
.corr_hcs_errors
);
1862 tmp
.uncorr_hcs
= be32_to_cpu(fore200e
->stats
->oc3
.ucorr_hcs_errors
);
1863 tmp
.tx_cells
= be32_to_cpu(fore200e
->stats
->aal0
.cells_transmitted
) +
1864 be32_to_cpu(fore200e
->stats
->aal34
.cells_transmitted
) +
1865 be32_to_cpu(fore200e
->stats
->aal5
.cells_transmitted
);
1866 tmp
.rx_cells
= be32_to_cpu(fore200e
->stats
->aal0
.cells_received
) +
1867 be32_to_cpu(fore200e
->stats
->aal34
.cells_received
) +
1868 be32_to_cpu(fore200e
->stats
->aal5
.cells_received
);
1871 return copy_to_user(arg
, &tmp
, sizeof(struct sonet_stats
)) ? -EFAULT
: 0;
1878 fore200e_ioctl(struct atm_dev
* dev
, unsigned int cmd
, void __user
* arg
)
1880 struct fore200e
* fore200e
= FORE200E_DEV(dev
);
1882 DPRINTK(2, "ioctl cmd = 0x%x (%u), arg = 0x%p (%lu)\n", cmd
, cmd
, arg
, (unsigned long)arg
);
1887 return fore200e_fetch_stats(fore200e
, (struct sonet_stats __user
*)arg
);
1890 return put_user(0, (int __user
*)arg
) ? -EFAULT
: 0;
1893 return fore200e_setloop(fore200e
, (int)(unsigned long)arg
);
1896 return put_user(fore200e
->loop_mode
, (int __user
*)arg
) ? -EFAULT
: 0;
1899 return put_user(ATM_LM_LOC_PHY
| ATM_LM_RMT_PHY
, (int __user
*)arg
) ? -EFAULT
: 0;
1902 return -ENOSYS
; /* not implemented */
1907 fore200e_change_qos(struct atm_vcc
* vcc
,struct atm_qos
* qos
, int flags
)
1909 struct fore200e_vcc
* fore200e_vcc
= FORE200E_VCC(vcc
);
1910 struct fore200e
* fore200e
= FORE200E_DEV(vcc
->dev
);
1912 if (!test_bit(ATM_VF_READY
, &vcc
->flags
)) {
1913 DPRINTK(1, "VC %d.%d.%d not ready for QoS change\n", vcc
->itf
, vcc
->vpi
, vcc
->vpi
);
1917 DPRINTK(2, "change_qos %d.%d.%d, "
1918 "(tx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d; "
1919 "rx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d), flags = 0x%x\n"
1920 "available_cell_rate = %u",
1921 vcc
->itf
, vcc
->vpi
, vcc
->vci
,
1922 fore200e_traffic_class
[ qos
->txtp
.traffic_class
],
1923 qos
->txtp
.min_pcr
, qos
->txtp
.max_pcr
, qos
->txtp
.max_cdv
, qos
->txtp
.max_sdu
,
1924 fore200e_traffic_class
[ qos
->rxtp
.traffic_class
],
1925 qos
->rxtp
.min_pcr
, qos
->rxtp
.max_pcr
, qos
->rxtp
.max_cdv
, qos
->rxtp
.max_sdu
,
1926 flags
, fore200e
->available_cell_rate
);
1928 if ((qos
->txtp
.traffic_class
== ATM_CBR
) && (qos
->txtp
.max_pcr
> 0)) {
1930 mutex_lock(&fore200e
->rate_mtx
);
1931 if (fore200e
->available_cell_rate
+ vcc
->qos
.txtp
.max_pcr
< qos
->txtp
.max_pcr
) {
1932 mutex_unlock(&fore200e
->rate_mtx
);
1936 fore200e
->available_cell_rate
+= vcc
->qos
.txtp
.max_pcr
;
1937 fore200e
->available_cell_rate
-= qos
->txtp
.max_pcr
;
1939 mutex_unlock(&fore200e
->rate_mtx
);
1941 memcpy(&vcc
->qos
, qos
, sizeof(struct atm_qos
));
1943 /* update rate control parameters */
1944 fore200e_rate_ctrl(qos
, &fore200e_vcc
->rate
);
1946 set_bit(ATM_VF_HASQOS
, &vcc
->flags
);
1955 static int __devinit
1956 fore200e_irq_request(struct fore200e
* fore200e
)
1958 if (request_irq(fore200e
->irq
, fore200e_interrupt
, IRQF_SHARED
, fore200e
->name
, fore200e
->atm_dev
) < 0) {
1960 printk(FORE200E
"unable to reserve IRQ %s for device %s\n",
1961 fore200e_irq_itoa(fore200e
->irq
), fore200e
->name
);
1965 printk(FORE200E
"IRQ %s reserved for device %s\n",
1966 fore200e_irq_itoa(fore200e
->irq
), fore200e
->name
);
1968 #ifdef FORE200E_USE_TASKLET
1969 tasklet_init(&fore200e
->tx_tasklet
, fore200e_tx_tasklet
, (unsigned long)fore200e
);
1970 tasklet_init(&fore200e
->rx_tasklet
, fore200e_rx_tasklet
, (unsigned long)fore200e
);
1973 fore200e
->state
= FORE200E_STATE_IRQ
;
1978 static int __devinit
1979 fore200e_get_esi(struct fore200e
* fore200e
)
1981 struct prom_data
* prom
= kzalloc(sizeof(struct prom_data
), GFP_KERNEL
| GFP_DMA
);
1987 ok
= fore200e
->bus
->prom_read(fore200e
, prom
);
1993 printk(FORE200E
"device %s, rev. %c, S/N: %d, ESI: %pM\n",
1995 (prom
->hw_revision
& 0xFF) + '@', /* probably meaningless with SBA boards */
1996 prom
->serial_number
& 0xFFFF, &prom
->mac_addr
[2]);
1998 for (i
= 0; i
< ESI_LEN
; i
++) {
1999 fore200e
->esi
[ i
] = fore200e
->atm_dev
->esi
[ i
] = prom
->mac_addr
[ i
+ 2 ];
2008 static int __devinit
2009 fore200e_alloc_rx_buf(struct fore200e
* fore200e
)
2011 int scheme
, magn
, nbr
, size
, i
;
2013 struct host_bsq
* bsq
;
2014 struct buffer
* buffer
;
2016 for (scheme
= 0; scheme
< BUFFER_SCHEME_NBR
; scheme
++) {
2017 for (magn
= 0; magn
< BUFFER_MAGN_NBR
; magn
++) {
2019 bsq
= &fore200e
->host_bsq
[ scheme
][ magn
];
2021 nbr
= fore200e_rx_buf_nbr
[ scheme
][ magn
];
2022 size
= fore200e_rx_buf_size
[ scheme
][ magn
];
2024 DPRINTK(2, "rx buffers %d / %d are being allocated\n", scheme
, magn
);
2026 /* allocate the array of receive buffers */
2027 buffer
= bsq
->buffer
= kzalloc(nbr
* sizeof(struct buffer
), GFP_KERNEL
);
2032 bsq
->freebuf
= NULL
;
2034 for (i
= 0; i
< nbr
; i
++) {
2036 buffer
[ i
].scheme
= scheme
;
2037 buffer
[ i
].magn
= magn
;
2038 #ifdef FORE200E_BSQ_DEBUG
2039 buffer
[ i
].index
= i
;
2040 buffer
[ i
].supplied
= 0;
2043 /* allocate the receive buffer body */
2044 if (fore200e_chunk_alloc(fore200e
,
2045 &buffer
[ i
].data
, size
, fore200e
->bus
->buffer_alignment
,
2046 DMA_FROM_DEVICE
) < 0) {
2049 fore200e_chunk_free(fore200e
, &buffer
[ --i
].data
);
2055 /* insert the buffer into the free buffer list */
2056 buffer
[ i
].next
= bsq
->freebuf
;
2057 bsq
->freebuf
= &buffer
[ i
];
2059 /* all the buffers are free, initially */
2060 bsq
->freebuf_count
= nbr
;
2062 #ifdef FORE200E_BSQ_DEBUG
2063 bsq_audit(3, bsq
, scheme
, magn
);
2068 fore200e
->state
= FORE200E_STATE_ALLOC_BUF
;
2073 static int __devinit
2074 fore200e_init_bs_queue(struct fore200e
* fore200e
)
2076 int scheme
, magn
, i
;
2078 struct host_bsq
* bsq
;
2079 struct cp_bsq_entry __iomem
* cp_entry
;
2081 for (scheme
= 0; scheme
< BUFFER_SCHEME_NBR
; scheme
++) {
2082 for (magn
= 0; magn
< BUFFER_MAGN_NBR
; magn
++) {
2084 DPRINTK(2, "buffer supply queue %d / %d is being initialized\n", scheme
, magn
);
2086 bsq
= &fore200e
->host_bsq
[ scheme
][ magn
];
2088 /* allocate and align the array of status words */
2089 if (fore200e
->bus
->dma_chunk_alloc(fore200e
,
2091 sizeof(enum status
),
2093 fore200e
->bus
->status_alignment
) < 0) {
2097 /* allocate and align the array of receive buffer descriptors */
2098 if (fore200e
->bus
->dma_chunk_alloc(fore200e
,
2100 sizeof(struct rbd_block
),
2102 fore200e
->bus
->descr_alignment
) < 0) {
2104 fore200e
->bus
->dma_chunk_free(fore200e
, &bsq
->status
);
2108 /* get the base address of the cp resident buffer supply queue entries */
2109 cp_entry
= fore200e
->virt_base
+
2110 fore200e
->bus
->read(&fore200e
->cp_queues
->cp_bsq
[ scheme
][ magn
]);
2112 /* fill the host resident and cp resident buffer supply queue entries */
2113 for (i
= 0; i
< QUEUE_SIZE_BS
; i
++) {
2115 bsq
->host_entry
[ i
].status
=
2116 FORE200E_INDEX(bsq
->status
.align_addr
, enum status
, i
);
2117 bsq
->host_entry
[ i
].rbd_block
=
2118 FORE200E_INDEX(bsq
->rbd_block
.align_addr
, struct rbd_block
, i
);
2119 bsq
->host_entry
[ i
].rbd_block_dma
=
2120 FORE200E_DMA_INDEX(bsq
->rbd_block
.dma_addr
, struct rbd_block
, i
);
2121 bsq
->host_entry
[ i
].cp_entry
= &cp_entry
[ i
];
2123 *bsq
->host_entry
[ i
].status
= STATUS_FREE
;
2125 fore200e
->bus
->write(FORE200E_DMA_INDEX(bsq
->status
.dma_addr
, enum status
, i
),
2126 &cp_entry
[ i
].status_haddr
);
2131 fore200e
->state
= FORE200E_STATE_INIT_BSQ
;
2136 static int __devinit
2137 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
->bus
->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
->bus
->dma_chunk_alloc(fore200e
,
2159 fore200e
->bus
->descr_alignment
) < 0) {
2161 fore200e
->bus
->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 __devinit
2197 fore200e_init_tx_queue(struct fore200e
* fore200e
)
2199 struct host_txq
* txq
= &fore200e
->host_txq
;
2200 struct cp_txq_entry __iomem
* cp_entry
;
2203 DPRINTK(2, "transmit queue is being initialized\n");
2205 /* allocate and align the array of status words */
2206 if (fore200e
->bus
->dma_chunk_alloc(fore200e
,
2208 sizeof(enum status
),
2210 fore200e
->bus
->status_alignment
) < 0) {
2214 /* allocate and align the array of transmit PDU descriptors */
2215 if (fore200e
->bus
->dma_chunk_alloc(fore200e
,
2219 fore200e
->bus
->descr_alignment
) < 0) {
2221 fore200e
->bus
->dma_chunk_free(fore200e
, &txq
->status
);
2225 /* get the base address of the cp resident tx queue entries */
2226 cp_entry
= fore200e
->virt_base
+ fore200e
->bus
->read(&fore200e
->cp_queues
->cp_txq
);
2228 /* fill the host resident and cp resident tx entries */
2229 for (i
=0; i
< QUEUE_SIZE_TX
; i
++) {
2231 txq
->host_entry
[ i
].status
=
2232 FORE200E_INDEX(txq
->status
.align_addr
, enum status
, i
);
2233 txq
->host_entry
[ i
].tpd
=
2234 FORE200E_INDEX(txq
->tpd
.align_addr
, struct tpd
, i
);
2235 txq
->host_entry
[ i
].tpd_dma
=
2236 FORE200E_DMA_INDEX(txq
->tpd
.dma_addr
, struct tpd
, i
);
2237 txq
->host_entry
[ i
].cp_entry
= &cp_entry
[ i
];
2239 *txq
->host_entry
[ i
].status
= STATUS_FREE
;
2241 fore200e
->bus
->write(FORE200E_DMA_INDEX(txq
->status
.dma_addr
, enum status
, i
),
2242 &cp_entry
[ i
].status_haddr
);
2244 /* although there is a one-to-one mapping of tx queue entries and tpds,
2245 we do not write here the DMA (physical) base address of each tpd into
2246 the related cp resident entry, because the cp relies on this write
2247 operation to detect that a new pdu has been submitted for tx */
2250 /* set the head and tail entries of the queue */
2254 fore200e
->state
= FORE200E_STATE_INIT_TXQ
;
2259 static int __devinit
2260 fore200e_init_cmd_queue(struct fore200e
* fore200e
)
2262 struct host_cmdq
* cmdq
= &fore200e
->host_cmdq
;
2263 struct cp_cmdq_entry __iomem
* cp_entry
;
2266 DPRINTK(2, "command queue is being initialized\n");
2268 /* allocate and align the array of status words */
2269 if (fore200e
->bus
->dma_chunk_alloc(fore200e
,
2271 sizeof(enum status
),
2273 fore200e
->bus
->status_alignment
) < 0) {
2277 /* get the base address of the cp resident cmd queue entries */
2278 cp_entry
= fore200e
->virt_base
+ fore200e
->bus
->read(&fore200e
->cp_queues
->cp_cmdq
);
2280 /* fill the host resident and cp resident cmd entries */
2281 for (i
=0; i
< QUEUE_SIZE_CMD
; i
++) {
2283 cmdq
->host_entry
[ i
].status
=
2284 FORE200E_INDEX(cmdq
->status
.align_addr
, enum status
, i
);
2285 cmdq
->host_entry
[ i
].cp_entry
= &cp_entry
[ i
];
2287 *cmdq
->host_entry
[ i
].status
= STATUS_FREE
;
2289 fore200e
->bus
->write(FORE200E_DMA_INDEX(cmdq
->status
.dma_addr
, enum status
, i
),
2290 &cp_entry
[ i
].status_haddr
);
2293 /* set the head entry of the queue */
2296 fore200e
->state
= FORE200E_STATE_INIT_CMDQ
;
2301 static void __devinit
2302 fore200e_param_bs_queue(struct fore200e
* fore200e
,
2303 enum buffer_scheme scheme
, enum buffer_magn magn
,
2304 int queue_length
, int pool_size
, int supply_blksize
)
2306 struct bs_spec __iomem
* bs_spec
= &fore200e
->cp_queues
->init
.bs_spec
[ scheme
][ magn
];
2308 fore200e
->bus
->write(queue_length
, &bs_spec
->queue_length
);
2309 fore200e
->bus
->write(fore200e_rx_buf_size
[ scheme
][ magn
], &bs_spec
->buffer_size
);
2310 fore200e
->bus
->write(pool_size
, &bs_spec
->pool_size
);
2311 fore200e
->bus
->write(supply_blksize
, &bs_spec
->supply_blksize
);
2315 static int __devinit
2316 fore200e_initialize(struct fore200e
* fore200e
)
2318 struct cp_queues __iomem
* cpq
;
2319 int ok
, scheme
, magn
;
2321 DPRINTK(2, "device %s being initialized\n", fore200e
->name
);
2323 mutex_init(&fore200e
->rate_mtx
);
2324 spin_lock_init(&fore200e
->q_lock
);
2326 cpq
= fore200e
->cp_queues
= fore200e
->virt_base
+ FORE200E_CP_QUEUES_OFFSET
;
2328 /* enable cp to host interrupts */
2329 fore200e
->bus
->write(1, &cpq
->imask
);
2331 if (fore200e
->bus
->irq_enable
)
2332 fore200e
->bus
->irq_enable(fore200e
);
2334 fore200e
->bus
->write(NBR_CONNECT
, &cpq
->init
.num_connect
);
2336 fore200e
->bus
->write(QUEUE_SIZE_CMD
, &cpq
->init
.cmd_queue_len
);
2337 fore200e
->bus
->write(QUEUE_SIZE_RX
, &cpq
->init
.rx_queue_len
);
2338 fore200e
->bus
->write(QUEUE_SIZE_TX
, &cpq
->init
.tx_queue_len
);
2340 fore200e
->bus
->write(RSD_EXTENSION
, &cpq
->init
.rsd_extension
);
2341 fore200e
->bus
->write(TSD_EXTENSION
, &cpq
->init
.tsd_extension
);
2343 for (scheme
= 0; scheme
< BUFFER_SCHEME_NBR
; scheme
++)
2344 for (magn
= 0; magn
< BUFFER_MAGN_NBR
; magn
++)
2345 fore200e_param_bs_queue(fore200e
, scheme
, magn
,
2347 fore200e_rx_buf_nbr
[ scheme
][ magn
],
2350 /* issue the initialize command */
2351 fore200e
->bus
->write(STATUS_PENDING
, &cpq
->init
.status
);
2352 fore200e
->bus
->write(OPCODE_INITIALIZE
, &cpq
->init
.opcode
);
2354 ok
= fore200e_io_poll(fore200e
, &cpq
->init
.status
, STATUS_COMPLETE
, 3000);
2356 printk(FORE200E
"device %s initialization failed\n", fore200e
->name
);
2360 printk(FORE200E
"device %s initialized\n", fore200e
->name
);
2362 fore200e
->state
= FORE200E_STATE_INITIALIZE
;
2367 static void __devinit
2368 fore200e_monitor_putc(struct fore200e
* fore200e
, char c
)
2370 struct cp_monitor __iomem
* monitor
= fore200e
->cp_monitor
;
2372 fore200e
->bus
->write(((u32
) c
) | FORE200E_CP_MONITOR_UART_AVAIL
, &monitor
->soft_uart
.send
);
2376 static int __devinit
2377 fore200e_monitor_getc(struct fore200e
* fore200e
)
2379 struct cp_monitor __iomem
* monitor
= fore200e
->cp_monitor
;
2380 unsigned long timeout
= jiffies
+ msecs_to_jiffies(50);
2383 while (time_before(jiffies
, timeout
)) {
2385 c
= (int) fore200e
->bus
->read(&monitor
->soft_uart
.recv
);
2387 if (c
& FORE200E_CP_MONITOR_UART_AVAIL
) {
2389 fore200e
->bus
->write(FORE200E_CP_MONITOR_UART_FREE
, &monitor
->soft_uart
.recv
);
2398 static void __devinit
2399 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 __devinit
2419 fore200e_load_and_start_fw(struct fore200e
* fore200e
)
2421 const struct firmware
*firmware
;
2422 struct device
*device
;
2423 struct fw_header
*fw_header
;
2424 const __le32
*fw_data
;
2426 u32 __iomem
*load_addr
;
2430 if (strcmp(fore200e
->bus
->model_name
, "PCA-200E") == 0)
2431 device
= &((struct pci_dev
*) fore200e
->bus_dev
)->dev
;
2433 else if (strcmp(fore200e
->bus
->model_name
, "SBA-200E") == 0)
2434 device
= &((struct platform_device
*) fore200e
->bus_dev
)->dev
;
2439 sprintf(buf
, "%s%s", fore200e
->bus
->proc_name
, FW_EXT
);
2440 if ((err
= request_firmware(&firmware
, buf
, device
)) < 0) {
2441 printk(FORE200E
"problem loading firmware image %s\n", fore200e
->bus
->model_name
);
2445 fw_data
= (__le32
*) firmware
->data
;
2446 fw_size
= firmware
->size
/ sizeof(u32
);
2447 fw_header
= (struct fw_header
*) firmware
->data
;
2448 load_addr
= fore200e
->virt_base
+ le32_to_cpu(fw_header
->load_offset
);
2450 DPRINTK(2, "device %s firmware being loaded at 0x%p (%d words)\n",
2451 fore200e
->name
, load_addr
, fw_size
);
2453 if (le32_to_cpu(fw_header
->magic
) != FW_HEADER_MAGIC
) {
2454 printk(FORE200E
"corrupted %s firmware image\n", fore200e
->bus
->model_name
);
2458 for (; fw_size
--; fw_data
++, load_addr
++)
2459 fore200e
->bus
->write(le32_to_cpu(*fw_data
), load_addr
);
2461 DPRINTK(2, "device %s firmware being started\n", fore200e
->name
);
2463 #if defined(__sparc_v9__)
2464 /* reported to be required by SBA cards on some sparc64 hosts */
2468 sprintf(buf
, "\rgo %x\r", le32_to_cpu(fw_header
->start_offset
));
2469 fore200e_monitor_puts(fore200e
, buf
);
2471 if (fore200e_io_poll(fore200e
, &fore200e
->cp_monitor
->bstat
, BSTAT_CP_RUNNING
, 1000) == 0) {
2472 printk(FORE200E
"device %s firmware didn't start\n", fore200e
->name
);
2476 printk(FORE200E
"device %s firmware started\n", fore200e
->name
);
2478 fore200e
->state
= FORE200E_STATE_START_FW
;
2482 release_firmware(firmware
);
2487 static int __devinit
2488 fore200e_register(struct fore200e
* fore200e
)
2490 struct atm_dev
* atm_dev
;
2492 DPRINTK(2, "device %s being registered\n", fore200e
->name
);
2494 atm_dev
= atm_dev_register(fore200e
->bus
->proc_name
, &fore200e_ops
, -1,
2496 if (atm_dev
== NULL
) {
2497 printk(FORE200E
"unable to register device %s\n", fore200e
->name
);
2501 atm_dev
->dev_data
= fore200e
;
2502 fore200e
->atm_dev
= atm_dev
;
2504 atm_dev
->ci_range
.vpi_bits
= FORE200E_VPI_BITS
;
2505 atm_dev
->ci_range
.vci_bits
= FORE200E_VCI_BITS
;
2507 fore200e
->available_cell_rate
= ATM_OC3_PCR
;
2509 fore200e
->state
= FORE200E_STATE_REGISTER
;
2514 static int __devinit
2515 fore200e_init(struct fore200e
* fore200e
)
2517 if (fore200e_register(fore200e
) < 0)
2520 if (fore200e
->bus
->configure(fore200e
) < 0)
2523 if (fore200e
->bus
->map(fore200e
) < 0)
2526 if (fore200e_reset(fore200e
, 1) < 0)
2529 if (fore200e_load_and_start_fw(fore200e
) < 0)
2532 if (fore200e_initialize(fore200e
) < 0)
2535 if (fore200e_init_cmd_queue(fore200e
) < 0)
2538 if (fore200e_init_tx_queue(fore200e
) < 0)
2541 if (fore200e_init_rx_queue(fore200e
) < 0)
2544 if (fore200e_init_bs_queue(fore200e
) < 0)
2547 if (fore200e_alloc_rx_buf(fore200e
) < 0)
2550 if (fore200e_get_esi(fore200e
) < 0)
2553 if (fore200e_irq_request(fore200e
) < 0)
2556 fore200e_supply(fore200e
);
2558 /* all done, board initialization is now complete */
2559 fore200e
->state
= FORE200E_STATE_COMPLETE
;
2564 static int __devinit
fore200e_sba_probe(struct platform_device
*op
,
2565 const struct of_device_id
*match
)
2567 const struct fore200e_bus
*bus
= match
->data
;
2568 struct fore200e
*fore200e
;
2569 static int index
= 0;
2572 fore200e
= kzalloc(sizeof(struct fore200e
), GFP_KERNEL
);
2576 fore200e
->bus
= bus
;
2577 fore200e
->bus_dev
= op
;
2578 fore200e
->irq
= op
->archdata
.irqs
[0];
2579 fore200e
->phys_base
= op
->resource
[0].start
;
2581 sprintf(fore200e
->name
, "%s-%d", bus
->model_name
, index
);
2583 err
= fore200e_init(fore200e
);
2585 fore200e_shutdown(fore200e
);
2591 dev_set_drvdata(&op
->dev
, fore200e
);
2596 static int __devexit
fore200e_sba_remove(struct platform_device
*op
)
2598 struct fore200e
*fore200e
= dev_get_drvdata(&op
->dev
);
2600 fore200e_shutdown(fore200e
);
2606 static const struct of_device_id fore200e_sba_match
[] = {
2608 .name
= SBA200E_PROM_NAME
,
2609 .data
= (void *) &fore200e_bus
[1],
2613 MODULE_DEVICE_TABLE(of
, fore200e_sba_match
);
2615 static struct of_platform_driver fore200e_sba_driver
= {
2617 .name
= "fore_200e",
2618 .owner
= THIS_MODULE
,
2619 .of_match_table
= fore200e_sba_match
,
2621 .probe
= fore200e_sba_probe
,
2622 .remove
= __devexit_p(fore200e_sba_remove
),
2627 static int __devinit
2628 fore200e_pca_detect(struct pci_dev
*pci_dev
, const struct pci_device_id
*pci_ent
)
2630 const struct fore200e_bus
* bus
= (struct fore200e_bus
*) pci_ent
->driver_data
;
2631 struct fore200e
* fore200e
;
2633 static int index
= 0;
2635 if (pci_enable_device(pci_dev
)) {
2640 fore200e
= kzalloc(sizeof(struct fore200e
), GFP_KERNEL
);
2641 if (fore200e
== NULL
) {
2646 fore200e
->bus
= bus
;
2647 fore200e
->bus_dev
= pci_dev
;
2648 fore200e
->irq
= pci_dev
->irq
;
2649 fore200e
->phys_base
= pci_resource_start(pci_dev
, 0);
2651 sprintf(fore200e
->name
, "%s-%d", bus
->model_name
, index
- 1);
2653 pci_set_master(pci_dev
);
2655 printk(FORE200E
"device %s found at 0x%lx, IRQ %s\n",
2656 fore200e
->bus
->model_name
,
2657 fore200e
->phys_base
, fore200e_irq_itoa(fore200e
->irq
));
2659 sprintf(fore200e
->name
, "%s-%d", bus
->model_name
, index
);
2661 err
= fore200e_init(fore200e
);
2663 fore200e_shutdown(fore200e
);
2668 pci_set_drvdata(pci_dev
, fore200e
);
2676 pci_disable_device(pci_dev
);
2681 static void __devexit
fore200e_pca_remove_one(struct pci_dev
*pci_dev
)
2683 struct fore200e
*fore200e
;
2685 fore200e
= pci_get_drvdata(pci_dev
);
2687 fore200e_shutdown(fore200e
);
2689 pci_disable_device(pci_dev
);
2693 static struct pci_device_id fore200e_pca_tbl
[] = {
2694 { PCI_VENDOR_ID_FORE
, PCI_DEVICE_ID_FORE_PCA200E
, PCI_ANY_ID
, PCI_ANY_ID
,
2695 0, 0, (unsigned long) &fore200e_bus
[0] },
2699 MODULE_DEVICE_TABLE(pci
, fore200e_pca_tbl
);
2701 static struct pci_driver fore200e_pca_driver
= {
2702 .name
= "fore_200e",
2703 .probe
= fore200e_pca_detect
,
2704 .remove
= __devexit_p(fore200e_pca_remove_one
),
2705 .id_table
= fore200e_pca_tbl
,
2709 static int __init
fore200e_module_init(void)
2713 printk(FORE200E
"FORE Systems 200E-series ATM driver - version " FORE200E_VERSION
"\n");
2716 err
= of_register_platform_driver(&fore200e_sba_driver
);
2722 err
= pci_register_driver(&fore200e_pca_driver
);
2727 of_unregister_platform_driver(&fore200e_sba_driver
);
2733 static void __exit
fore200e_module_cleanup(void)
2736 pci_unregister_driver(&fore200e_pca_driver
);
2739 of_unregister_platform_driver(&fore200e_sba_driver
);
2744 fore200e_proc_read(struct atm_dev
*dev
, loff_t
* pos
, char* page
)
2746 struct fore200e
* fore200e
= FORE200E_DEV(dev
);
2747 struct fore200e_vcc
* fore200e_vcc
;
2748 struct atm_vcc
* vcc
;
2749 int i
, len
, left
= *pos
;
2750 unsigned long flags
;
2754 if (fore200e_getstats(fore200e
) < 0)
2757 len
= sprintf(page
,"\n"
2759 " internal name:\t\t%s\n", fore200e
->name
);
2761 /* print bus-specific information */
2762 if (fore200e
->bus
->proc_read
)
2763 len
+= fore200e
->bus
->proc_read(fore200e
, page
+ len
);
2765 len
+= sprintf(page
+ len
,
2766 " interrupt line:\t\t%s\n"
2767 " physical base address:\t0x%p\n"
2768 " virtual base address:\t0x%p\n"
2769 " factory address (ESI):\t%pM\n"
2770 " board serial number:\t\t%d\n\n",
2771 fore200e_irq_itoa(fore200e
->irq
),
2772 (void*)fore200e
->phys_base
,
2773 fore200e
->virt_base
,
2775 fore200e
->esi
[4] * 256 + fore200e
->esi
[5]);
2781 return sprintf(page
,
2782 " free small bufs, scheme 1:\t%d\n"
2783 " free large bufs, scheme 1:\t%d\n"
2784 " free small bufs, scheme 2:\t%d\n"
2785 " free large bufs, scheme 2:\t%d\n",
2786 fore200e
->host_bsq
[ BUFFER_SCHEME_ONE
][ BUFFER_MAGN_SMALL
].freebuf_count
,
2787 fore200e
->host_bsq
[ BUFFER_SCHEME_ONE
][ BUFFER_MAGN_LARGE
].freebuf_count
,
2788 fore200e
->host_bsq
[ BUFFER_SCHEME_TWO
][ BUFFER_MAGN_SMALL
].freebuf_count
,
2789 fore200e
->host_bsq
[ BUFFER_SCHEME_TWO
][ BUFFER_MAGN_LARGE
].freebuf_count
);
2792 u32 hb
= fore200e
->bus
->read(&fore200e
->cp_queues
->heartbeat
);
2794 len
= sprintf(page
,"\n\n"
2795 " cell processor:\n"
2796 " heartbeat state:\t\t");
2798 if (hb
>> 16 != 0xDEAD)
2799 len
+= sprintf(page
+ len
, "0x%08x\n", hb
);
2801 len
+= sprintf(page
+ len
, "*** FATAL ERROR %04x ***\n", hb
& 0xFFFF);
2807 static const char* media_name
[] = {
2808 "unshielded twisted pair",
2809 "multimode optical fiber ST",
2810 "multimode optical fiber SC",
2811 "single-mode optical fiber ST",
2812 "single-mode optical fiber SC",
2816 static const char* oc3_mode
[] = {
2818 "diagnostic loopback",
2823 u32 fw_release
= fore200e
->bus
->read(&fore200e
->cp_queues
->fw_release
);
2824 u32 mon960_release
= fore200e
->bus
->read(&fore200e
->cp_queues
->mon960_release
);
2825 u32 oc3_revision
= fore200e
->bus
->read(&fore200e
->cp_queues
->oc3_revision
);
2826 u32 media_index
= FORE200E_MEDIA_INDEX(fore200e
->bus
->read(&fore200e
->cp_queues
->media_type
));
2829 if (media_index
> 4)
2832 switch (fore200e
->loop_mode
) {
2833 case ATM_LM_NONE
: oc3_index
= 0;
2835 case ATM_LM_LOC_PHY
: oc3_index
= 1;
2837 case ATM_LM_RMT_PHY
: oc3_index
= 2;
2839 default: oc3_index
= 3;
2842 return sprintf(page
,
2843 " firmware release:\t\t%d.%d.%d\n"
2844 " monitor release:\t\t%d.%d\n"
2845 " media type:\t\t\t%s\n"
2846 " OC-3 revision:\t\t0x%x\n"
2847 " OC-3 mode:\t\t\t%s",
2848 fw_release
>> 16, fw_release
<< 16 >> 24, fw_release
<< 24 >> 24,
2849 mon960_release
>> 16, mon960_release
<< 16 >> 16,
2850 media_name
[ media_index
],
2852 oc3_mode
[ oc3_index
]);
2856 struct cp_monitor __iomem
* cp_monitor
= fore200e
->cp_monitor
;
2858 return sprintf(page
,
2861 " version number:\t\t%d\n"
2862 " boot status word:\t\t0x%08x\n",
2863 fore200e
->bus
->read(&cp_monitor
->mon_version
),
2864 fore200e
->bus
->read(&cp_monitor
->bstat
));
2868 return sprintf(page
,
2870 " device statistics:\n"
2872 " crc_header_errors:\t\t%10u\n"
2873 " framing_errors:\t\t%10u\n",
2874 be32_to_cpu(fore200e
->stats
->phy
.crc_header_errors
),
2875 be32_to_cpu(fore200e
->stats
->phy
.framing_errors
));
2878 return sprintf(page
, "\n"
2880 " section_bip8_errors:\t%10u\n"
2881 " path_bip8_errors:\t\t%10u\n"
2882 " line_bip24_errors:\t\t%10u\n"
2883 " line_febe_errors:\t\t%10u\n"
2884 " path_febe_errors:\t\t%10u\n"
2885 " corr_hcs_errors:\t\t%10u\n"
2886 " ucorr_hcs_errors:\t\t%10u\n",
2887 be32_to_cpu(fore200e
->stats
->oc3
.section_bip8_errors
),
2888 be32_to_cpu(fore200e
->stats
->oc3
.path_bip8_errors
),
2889 be32_to_cpu(fore200e
->stats
->oc3
.line_bip24_errors
),
2890 be32_to_cpu(fore200e
->stats
->oc3
.line_febe_errors
),
2891 be32_to_cpu(fore200e
->stats
->oc3
.path_febe_errors
),
2892 be32_to_cpu(fore200e
->stats
->oc3
.corr_hcs_errors
),
2893 be32_to_cpu(fore200e
->stats
->oc3
.ucorr_hcs_errors
));
2896 return sprintf(page
,"\n"
2897 " ATM:\t\t\t\t cells\n"
2900 " vpi out of range:\t\t%10u\n"
2901 " vpi no conn:\t\t%10u\n"
2902 " vci out of range:\t\t%10u\n"
2903 " vci no conn:\t\t%10u\n",
2904 be32_to_cpu(fore200e
->stats
->atm
.cells_transmitted
),
2905 be32_to_cpu(fore200e
->stats
->atm
.cells_received
),
2906 be32_to_cpu(fore200e
->stats
->atm
.vpi_bad_range
),
2907 be32_to_cpu(fore200e
->stats
->atm
.vpi_no_conn
),
2908 be32_to_cpu(fore200e
->stats
->atm
.vci_bad_range
),
2909 be32_to_cpu(fore200e
->stats
->atm
.vci_no_conn
));
2912 return sprintf(page
,"\n"
2913 " AAL0:\t\t\t cells\n"
2916 " dropped:\t\t\t%10u\n",
2917 be32_to_cpu(fore200e
->stats
->aal0
.cells_transmitted
),
2918 be32_to_cpu(fore200e
->stats
->aal0
.cells_received
),
2919 be32_to_cpu(fore200e
->stats
->aal0
.cells_dropped
));
2922 return sprintf(page
,"\n"
2924 " SAR sublayer:\t\t cells\n"
2927 " dropped:\t\t\t%10u\n"
2928 " CRC errors:\t\t%10u\n"
2929 " protocol errors:\t\t%10u\n\n"
2930 " CS sublayer:\t\t PDUs\n"
2933 " dropped:\t\t\t%10u\n"
2934 " protocol errors:\t\t%10u\n",
2935 be32_to_cpu(fore200e
->stats
->aal34
.cells_transmitted
),
2936 be32_to_cpu(fore200e
->stats
->aal34
.cells_received
),
2937 be32_to_cpu(fore200e
->stats
->aal34
.cells_dropped
),
2938 be32_to_cpu(fore200e
->stats
->aal34
.cells_crc_errors
),
2939 be32_to_cpu(fore200e
->stats
->aal34
.cells_protocol_errors
),
2940 be32_to_cpu(fore200e
->stats
->aal34
.cspdus_transmitted
),
2941 be32_to_cpu(fore200e
->stats
->aal34
.cspdus_received
),
2942 be32_to_cpu(fore200e
->stats
->aal34
.cspdus_dropped
),
2943 be32_to_cpu(fore200e
->stats
->aal34
.cspdus_protocol_errors
));
2946 return sprintf(page
,"\n"
2948 " SAR sublayer:\t\t cells\n"
2951 " dropped:\t\t\t%10u\n"
2952 " congestions:\t\t%10u\n\n"
2953 " CS sublayer:\t\t PDUs\n"
2956 " dropped:\t\t\t%10u\n"
2957 " CRC errors:\t\t%10u\n"
2958 " protocol errors:\t\t%10u\n",
2959 be32_to_cpu(fore200e
->stats
->aal5
.cells_transmitted
),
2960 be32_to_cpu(fore200e
->stats
->aal5
.cells_received
),
2961 be32_to_cpu(fore200e
->stats
->aal5
.cells_dropped
),
2962 be32_to_cpu(fore200e
->stats
->aal5
.congestion_experienced
),
2963 be32_to_cpu(fore200e
->stats
->aal5
.cspdus_transmitted
),
2964 be32_to_cpu(fore200e
->stats
->aal5
.cspdus_received
),
2965 be32_to_cpu(fore200e
->stats
->aal5
.cspdus_dropped
),
2966 be32_to_cpu(fore200e
->stats
->aal5
.cspdus_crc_errors
),
2967 be32_to_cpu(fore200e
->stats
->aal5
.cspdus_protocol_errors
));
2970 return sprintf(page
,"\n"
2971 " AUX:\t\t allocation failures\n"
2972 " small b1:\t\t\t%10u\n"
2973 " large b1:\t\t\t%10u\n"
2974 " small b2:\t\t\t%10u\n"
2975 " large b2:\t\t\t%10u\n"
2976 " RX PDUs:\t\t\t%10u\n"
2977 " TX PDUs:\t\t\t%10lu\n",
2978 be32_to_cpu(fore200e
->stats
->aux
.small_b1_failed
),
2979 be32_to_cpu(fore200e
->stats
->aux
.large_b1_failed
),
2980 be32_to_cpu(fore200e
->stats
->aux
.small_b2_failed
),
2981 be32_to_cpu(fore200e
->stats
->aux
.large_b2_failed
),
2982 be32_to_cpu(fore200e
->stats
->aux
.rpd_alloc_failed
),
2986 return sprintf(page
,"\n"
2987 " receive carrier:\t\t\t%s\n",
2988 fore200e
->stats
->aux
.receive_carrier
? "ON" : "OFF!");
2991 return sprintf(page
,"\n"
2992 " VCCs:\n address VPI VCI AAL "
2993 "TX PDUs TX min/max size RX PDUs RX min/max size\n");
2996 for (i
= 0; i
< NBR_CONNECT
; i
++) {
2998 vcc
= fore200e
->vc_map
[i
].vcc
;
3003 spin_lock_irqsave(&fore200e
->q_lock
, flags
);
3005 if (vcc
&& test_bit(ATM_VF_READY
, &vcc
->flags
) && !left
--) {
3007 fore200e_vcc
= FORE200E_VCC(vcc
);
3008 ASSERT(fore200e_vcc
);
3011 " %08x %03d %05d %1d %09lu %05d/%05d %09lu %05d/%05d\n",
3012 (u32
)(unsigned long)vcc
,
3013 vcc
->vpi
, vcc
->vci
, fore200e_atm2fore_aal(vcc
->qos
.aal
),
3014 fore200e_vcc
->tx_pdu
,
3015 fore200e_vcc
->tx_min_pdu
> 0xFFFF ? 0 : fore200e_vcc
->tx_min_pdu
,
3016 fore200e_vcc
->tx_max_pdu
,
3017 fore200e_vcc
->rx_pdu
,
3018 fore200e_vcc
->rx_min_pdu
> 0xFFFF ? 0 : fore200e_vcc
->rx_min_pdu
,
3019 fore200e_vcc
->rx_max_pdu
);
3021 spin_unlock_irqrestore(&fore200e
->q_lock
, flags
);
3025 spin_unlock_irqrestore(&fore200e
->q_lock
, flags
);
3031 module_init(fore200e_module_init
);
3032 module_exit(fore200e_module_cleanup
);
3035 static const struct atmdev_ops fore200e_ops
=
3037 .open
= fore200e_open
,
3038 .close
= fore200e_close
,
3039 .ioctl
= fore200e_ioctl
,
3040 .getsockopt
= fore200e_getsockopt
,
3041 .setsockopt
= fore200e_setsockopt
,
3042 .send
= fore200e_send
,
3043 .change_qos
= fore200e_change_qos
,
3044 .proc_read
= fore200e_proc_read
,
3045 .owner
= THIS_MODULE
3049 static const struct fore200e_bus fore200e_bus
[] = {
3051 { "PCA-200E", "pca200e", 32, 4, 32,
3054 fore200e_pca_dma_map
,
3055 fore200e_pca_dma_unmap
,
3056 fore200e_pca_dma_sync_for_cpu
,
3057 fore200e_pca_dma_sync_for_device
,
3058 fore200e_pca_dma_chunk_alloc
,
3059 fore200e_pca_dma_chunk_free
,
3060 fore200e_pca_configure
,
3063 fore200e_pca_prom_read
,
3066 fore200e_pca_irq_check
,
3067 fore200e_pca_irq_ack
,
3068 fore200e_pca_proc_read
,
3072 { "SBA-200E", "sba200e", 32, 64, 32,
3075 fore200e_sba_dma_map
,
3076 fore200e_sba_dma_unmap
,
3077 fore200e_sba_dma_sync_for_cpu
,
3078 fore200e_sba_dma_sync_for_device
,
3079 fore200e_sba_dma_chunk_alloc
,
3080 fore200e_sba_dma_chunk_free
,
3081 fore200e_sba_configure
,
3084 fore200e_sba_prom_read
,
3086 fore200e_sba_irq_enable
,
3087 fore200e_sba_irq_check
,
3088 fore200e_sba_irq_ack
,
3089 fore200e_sba_proc_read
,
3095 MODULE_LICENSE("GPL");
3097 #ifdef __LITTLE_ENDIAN__
3098 MODULE_FIRMWARE("pca200e.bin");
3100 MODULE_FIRMWARE("pca200e_ecd.bin2");
3102 #endif /* CONFIG_PCI */
3104 MODULE_FIRMWARE("sba200e_ecd.bin2");