blob: 40d6ddbf1d5eef56be692525e721b82a16400500 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 A FORE Systems 200E-series driver for ATM on Linux.
3 Christophe Lizzi (lizzi@cnam.fr), October 1999-March 2003.
4
5 Based on the PCA-200E driver from Uwe Dannowski (Uwe.Dannowski@inf.tu-dresden.de).
6
7 This driver simultaneously supports PCA-200E and SBA-200E adapters
8 on i386, alpha (untested), powerpc, sparc and sparc64 architectures.
9
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.
14
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.
19
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
23*/
24
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/kernel.h>
27#include <linux/slab.h>
28#include <linux/init.h>
29#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#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>
Chas Williamse92481f2008-06-17 16:23:11 -070039#include <linux/firmware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <asm/io.h>
41#include <asm/string.h>
42#include <asm/page.h>
43#include <asm/irq.h>
44#include <asm/dma.h>
45#include <asm/byteorder.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080046#include <linux/uaccess.h>
Arun Sharma600634972011-07-26 16:09:06 -070047#include <linux/atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Chas Williamse92481f2008-06-17 16:23:11 -070049#ifdef CONFIG_SBUS
David S. Miller826b6cf2008-08-27 01:06:07 -070050#include <linux/of.h>
51#include <linux/of_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <asm/idprom.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#include <asm/openprom.h>
54#include <asm/oplib.h>
55#include <asm/pgtable.h>
56#endif
57
58#if defined(CONFIG_ATM_FORE200E_USE_TASKLET) /* defer interrupt work to a tasklet */
59#define FORE200E_USE_TASKLET
60#endif
61
62#if 0 /* enable the debugging code of the buffer supply queues */
63#define FORE200E_BSQ_DEBUG
64#endif
65
66#if 1 /* ensure correct handling of 52-byte AAL0 SDUs expected by atmdump-like apps */
67#define FORE200E_52BYTE_AAL0_SDU
68#endif
69
70#include "fore200e.h"
71#include "suni.h"
72
73#define FORE200E_VERSION "0.3e"
74
75#define FORE200E "fore200e: "
76
77#if 0 /* override .config */
78#define CONFIG_ATM_FORE200E_DEBUG 1
79#endif
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)
83#else
84#define DPRINTK(level, format, args...) do {} while (0)
85#endif
86
87
88#define FORE200E_ALIGN(addr, alignment) \
89 ((((unsigned long)(addr) + (alignment - 1)) & ~(alignment - 1)) - (unsigned long)(addr))
90
91#define FORE200E_DMA_INDEX(dma_addr, type, index) ((dma_addr) + (index) * sizeof(type))
92
93#define FORE200E_INDEX(virt_addr, type, index) (&((type *)(virt_addr))[ index ])
94
David S. Miller30dfe2c2010-11-18 11:49:25 -080095#define FORE200E_NEXT_ENTRY(index, modulo) (index = ((index) + 1) % (modulo))
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97#if 1
98#define ASSERT(expr) if (!(expr)) { \
99 printk(FORE200E "assertion failed! %s[%d]: %s\n", \
Harvey Harrison5a346a12008-03-05 18:38:07 -0800100 __func__, __LINE__, #expr); \
101 panic(FORE200E "%s", __func__); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 }
103#else
104#define ASSERT(expr) do {} while (0)
105#endif
106
107
108static const struct atmdev_ops fore200e_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110static LIST_HEAD(fore200e_boards);
111
112
113MODULE_AUTHOR("Christophe Lizzi - credits to Uwe Dannowski and Heikki Vatiainen");
114MODULE_DESCRIPTION("FORE Systems 200E-series ATM driver - version " FORE200E_VERSION);
115MODULE_SUPPORTED_DEVICE("PCA-200E, SBA-200E");
116
117
118static 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 }
121};
122
123static 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 }
126};
127
128
129#if defined(CONFIG_ATM_FORE200E_DEBUG) && (CONFIG_ATM_FORE200E_DEBUG > 0)
130static const char* fore200e_traffic_class[] = { "NONE", "UBR", "CBR", "VBR", "ABR", "ANY" };
131#endif
132
133
134#if 0 /* currently unused */
135static int
136fore200e_fore2atm_aal(enum fore200e_aal aal)
137{
138 switch(aal) {
139 case FORE200E_AAL0: return ATM_AAL0;
140 case FORE200E_AAL34: return ATM_AAL34;
141 case FORE200E_AAL5: return ATM_AAL5;
142 }
143
144 return -EINVAL;
145}
146#endif
147
148
149static enum fore200e_aal
150fore200e_atm2fore_aal(int aal)
151{
152 switch(aal) {
153 case ATM_AAL0: return FORE200E_AAL0;
154 case ATM_AAL34: return FORE200E_AAL34;
155 case ATM_AAL1:
156 case ATM_AAL2:
157 case ATM_AAL5: return FORE200E_AAL5;
158 }
159
160 return -EINVAL;
161}
162
163
164static char*
165fore200e_irq_itoa(int irq)
166{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 static char str[8];
168 sprintf(str, "%d", irq);
169 return str;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170}
171
172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173/* allocate and align a chunk of memory intended to hold the data behing exchanged
174 between the driver and the adapter (using streaming DVMA) */
175
176static int
177fore200e_chunk_alloc(struct fore200e* fore200e, struct chunk* chunk, int size, int alignment, int direction)
178{
179 unsigned long offset = 0;
180
181 if (alignment <= sizeof(int))
182 alignment = 0;
183
184 chunk->alloc_size = size + alignment;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 chunk->direction = direction;
186
Christoph Hellwig0e21b222018-10-09 16:57:19 +0200187 chunk->alloc_addr = kzalloc(chunk->alloc_size, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 if (chunk->alloc_addr == NULL)
189 return -ENOMEM;
190
191 if (alignment > 0)
192 offset = FORE200E_ALIGN(chunk->alloc_addr, alignment);
193
194 chunk->align_addr = chunk->alloc_addr + offset;
195
Christoph Hellwigf3fadcb2018-10-09 16:57:17 +0200196 chunk->dma_addr = dma_map_single(fore200e->dev, chunk->align_addr,
197 size, direction);
Christoph Hellwig1d9d8be92018-10-09 16:57:20 +0200198 if (dma_mapping_error(fore200e->dev, chunk->dma_addr)) {
199 kfree(chunk->alloc_addr);
200 return -ENOMEM;
201 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 return 0;
203}
204
205
206/* free a chunk of memory */
207
208static void
209fore200e_chunk_free(struct fore200e* fore200e, struct chunk* chunk)
210{
Christoph Hellwigf3fadcb2018-10-09 16:57:17 +0200211 dma_unmap_single(fore200e->dev, chunk->dma_addr, chunk->dma_size,
212 chunk->direction);
Adrian Bunk1f8a5fb2006-12-19 19:36:32 -0800213 kfree(chunk->alloc_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214}
215
Christoph Hellwig1335d6f2018-10-09 16:57:18 +0200216/*
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
219 * and the adapter.
220 */
221static int
222fore200e_dma_chunk_alloc(struct fore200e *fore200e, struct chunk *chunk,
223 int size, int nbr, int alignment)
224{
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)
230 return -ENOMEM;
231 chunk->align_addr = chunk->alloc_addr;
232 return 0;
233}
234
235/*
236 * Free a DMA consistent chunk of memory.
237 */
238static void
239fore200e_dma_chunk_free(struct fore200e* fore200e, struct chunk* chunk)
240{
241 dma_free_coherent(fore200e->dev, chunk->alloc_size, chunk->alloc_addr,
242 chunk->dma_addr);
243}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
245static void
246fore200e_spin(int msecs)
247{
248 unsigned long timeout = jiffies + msecs_to_jiffies(msecs);
249 while (time_before(jiffies, timeout));
250}
251
252
253static int
254fore200e_poll(struct fore200e* fore200e, volatile u32* addr, u32 val, int msecs)
255{
256 unsigned long timeout = jiffies + msecs_to_jiffies(msecs);
257 int ok;
258
259 mb();
260 do {
261 if ((ok = (*addr == val)) || (*addr & STATUS_ERROR))
262 break;
263
264 } while (time_before(jiffies, timeout));
265
266#if 1
267 if (!ok) {
268 printk(FORE200E "cmd polling failed, got status 0x%08x, expected 0x%08x\n",
269 *addr, val);
270 }
271#endif
272
273 return ok;
274}
275
276
277static int
278fore200e_io_poll(struct fore200e* fore200e, volatile u32 __iomem *addr, u32 val, int msecs)
279{
280 unsigned long timeout = jiffies + msecs_to_jiffies(msecs);
281 int ok;
282
283 do {
284 if ((ok = (fore200e->bus->read(addr) == val)))
285 break;
286
287 } while (time_before(jiffies, timeout));
288
289#if 1
290 if (!ok) {
291 printk(FORE200E "I/O polling failed, got status 0x%08x, expected 0x%08x\n",
292 fore200e->bus->read(addr), val);
293 }
294#endif
295
296 return ok;
297}
298
299
300static void
301fore200e_free_rx_buf(struct fore200e* fore200e)
302{
303 int scheme, magn, nbr;
304 struct buffer* buffer;
305
306 for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
307 for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
308
309 if ((buffer = fore200e->host_bsq[ scheme ][ magn ].buffer) != NULL) {
310
311 for (nbr = 0; nbr < fore200e_rx_buf_nbr[ scheme ][ magn ]; nbr++) {
312
313 struct chunk* data = &buffer[ nbr ].data;
314
315 if (data->alloc_addr != NULL)
316 fore200e_chunk_free(fore200e, data);
317 }
318 }
319 }
320 }
321}
322
323
324static void
325fore200e_uninit_bs_queue(struct fore200e* fore200e)
326{
327 int scheme, magn;
328
329 for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
330 for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
331
332 struct chunk* status = &fore200e->host_bsq[ scheme ][ magn ].status;
333 struct chunk* rbd_block = &fore200e->host_bsq[ scheme ][ magn ].rbd_block;
334
335 if (status->alloc_addr)
Christoph Hellwig1335d6f2018-10-09 16:57:18 +0200336 fore200e_dma_chunk_free(fore200e, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
338 if (rbd_block->alloc_addr)
Christoph Hellwig1335d6f2018-10-09 16:57:18 +0200339 fore200e_dma_chunk_free(fore200e, rbd_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 }
341 }
342}
343
344
345static int
346fore200e_reset(struct fore200e* fore200e, int diag)
347{
348 int ok;
349
350 fore200e->cp_monitor = fore200e->virt_base + FORE200E_CP_MONITOR_OFFSET;
351
352 fore200e->bus->write(BSTAT_COLD_START, &fore200e->cp_monitor->bstat);
353
354 fore200e->bus->reset(fore200e);
355
356 if (diag) {
357 ok = fore200e_io_poll(fore200e, &fore200e->cp_monitor->bstat, BSTAT_SELFTEST_OK, 1000);
358 if (ok == 0) {
359
360 printk(FORE200E "device %s self-test failed\n", fore200e->name);
361 return -ENODEV;
362 }
363
364 printk(FORE200E "device %s self-test passed\n", fore200e->name);
365
366 fore200e->state = FORE200E_STATE_RESET;
367 }
368
369 return 0;
370}
371
372
373static void
374fore200e_shutdown(struct fore200e* fore200e)
375{
376 printk(FORE200E "removing device %s at 0x%lx, IRQ %s\n",
377 fore200e->name, fore200e->phys_base,
378 fore200e_irq_itoa(fore200e->irq));
379
380 if (fore200e->state > FORE200E_STATE_RESET) {
381 /* first, reset the board to prevent further interrupts or data transfers */
382 fore200e_reset(fore200e, 0);
383 }
384
385 /* then, release all allocated resources */
386 switch(fore200e->state) {
387
388 case FORE200E_STATE_COMPLETE:
Jesper Juhla2c1aa52005-06-02 13:04:07 -0700389 kfree(fore200e->stats);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Gustavo A. R. Silvaec0d0982017-10-12 16:11:32 -0500391 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 case FORE200E_STATE_IRQ:
393 free_irq(fore200e->irq, fore200e->atm_dev);
394
Gustavo A. R. Silvaec0d0982017-10-12 16:11:32 -0500395 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 case FORE200E_STATE_ALLOC_BUF:
397 fore200e_free_rx_buf(fore200e);
398
Gustavo A. R. Silvaec0d0982017-10-12 16:11:32 -0500399 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 case FORE200E_STATE_INIT_BSQ:
401 fore200e_uninit_bs_queue(fore200e);
402
Gustavo A. R. Silvaec0d0982017-10-12 16:11:32 -0500403 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 case FORE200E_STATE_INIT_RXQ:
Christoph Hellwig1335d6f2018-10-09 16:57:18 +0200405 fore200e_dma_chunk_free(fore200e, &fore200e->host_rxq.status);
406 fore200e_dma_chunk_free(fore200e, &fore200e->host_rxq.rpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Gustavo A. R. Silvaec0d0982017-10-12 16:11:32 -0500408 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 case FORE200E_STATE_INIT_TXQ:
Christoph Hellwig1335d6f2018-10-09 16:57:18 +0200410 fore200e_dma_chunk_free(fore200e, &fore200e->host_txq.status);
411 fore200e_dma_chunk_free(fore200e, &fore200e->host_txq.tpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
Gustavo A. R. Silvaec0d0982017-10-12 16:11:32 -0500413 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 case FORE200E_STATE_INIT_CMDQ:
Christoph Hellwig1335d6f2018-10-09 16:57:18 +0200415 fore200e_dma_chunk_free(fore200e, &fore200e->host_cmdq.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
Gustavo A. R. Silvaec0d0982017-10-12 16:11:32 -0500417 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 case FORE200E_STATE_INITIALIZE:
419 /* nothing to do for that state */
420
421 case FORE200E_STATE_START_FW:
422 /* nothing to do for that state */
423
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 case FORE200E_STATE_RESET:
425 /* nothing to do for that state */
426
427 case FORE200E_STATE_MAP:
428 fore200e->bus->unmap(fore200e);
429
Gustavo A. R. Silvaec0d0982017-10-12 16:11:32 -0500430 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 case FORE200E_STATE_CONFIGURE:
432 /* nothing to do for that state */
433
434 case FORE200E_STATE_REGISTER:
435 /* XXX shouldn't we *start* by deregistering the device? */
436 atm_dev_deregister(fore200e->atm_dev);
437
438 case FORE200E_STATE_BLANK:
439 /* nothing to do for that state */
440 break;
441 }
442}
443
444
Chas Williamse92481f2008-06-17 16:23:11 -0700445#ifdef CONFIG_PCI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
447static u32 fore200e_pca_read(volatile u32 __iomem *addr)
448{
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));
452}
453
454
455static void fore200e_pca_write(u32 val, volatile u32 __iomem *addr)
456{
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);
460}
461
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462static int
463fore200e_pca_irq_check(struct fore200e* fore200e)
464{
465 /* this is a 1 bit register */
466 int irq_posted = readl(fore200e->regs.pca.psr);
467
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);
471 }
472#endif
473
474 return irq_posted;
475}
476
477
478static void
479fore200e_pca_irq_ack(struct fore200e* fore200e)
480{
481 writel(PCA200E_HCR_CLRINTR, fore200e->regs.pca.hcr);
482}
483
484
485static void
486fore200e_pca_reset(struct fore200e* fore200e)
487{
488 writel(PCA200E_HCR_RESET, fore200e->regs.pca.hcr);
489 fore200e_spin(10);
490 writel(0, fore200e->regs.pca.hcr);
491}
492
493
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -0800494static int fore200e_pca_map(struct fore200e* fore200e)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495{
496 DPRINTK(2, "device %s being mapped in memory\n", fore200e->name);
497
498 fore200e->virt_base = ioremap(fore200e->phys_base, PCA200E_IOSPACE_LENGTH);
499
500 if (fore200e->virt_base == NULL) {
501 printk(FORE200E "can't map device %s\n", fore200e->name);
502 return -EFAULT;
503 }
504
505 DPRINTK(1, "device %s mapped to 0x%p\n", fore200e->name, fore200e->virt_base);
506
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;
511
512 fore200e->state = FORE200E_STATE_MAP;
513 return 0;
514}
515
516
517static void
518fore200e_pca_unmap(struct fore200e* fore200e)
519{
520 DPRINTK(2, "device %s being unmapped from memory\n", fore200e->name);
521
522 if (fore200e->virt_base != NULL)
523 iounmap(fore200e->virt_base);
524}
525
526
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -0800527static int fore200e_pca_configure(struct fore200e *fore200e)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528{
Christoph Hellwigaff9d262018-10-09 16:57:15 +0200529 struct pci_dev *pci_dev = to_pci_dev(fore200e->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 u8 master_ctrl, latency;
531
532 DPRINTK(2, "device %s being configured\n", fore200e->name);
533
534 if ((pci_dev->irq == 0) || (pci_dev->irq == 0xFF)) {
535 printk(FORE200E "incorrect IRQ setting - misconfigured PCI-PCI bridge?\n");
536 return -EIO;
537 }
538
539 pci_read_config_byte(pci_dev, PCA200E_PCI_MASTER_CTRL, &master_ctrl);
540
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
545#endif
546#if 0
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
551#endif
552 | PCA200E_CTRL_LARGE_PCI_BURSTS;
553
554 pci_write_config_byte(pci_dev, PCA200E_PCI_MASTER_CTRL, master_ctrl);
555
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 */
559 latency = 192;
560 pci_write_config_byte(pci_dev, PCI_LATENCY_TIMER, latency);
561
562 fore200e->state = FORE200E_STATE_CONFIGURE;
563 return 0;
564}
565
566
567static int __init
568fore200e_pca_prom_read(struct fore200e* fore200e, struct prom_data* prom)
569{
570 struct host_cmdq* cmdq = &fore200e->host_cmdq;
571 struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
572 struct prom_opcode opcode;
573 int ok;
574 u32 prom_dma;
575
576 FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
577
578 opcode.opcode = OPCODE_GET_PROM;
579 opcode.pad = 0;
580
Christoph Hellwigf3fadcb2018-10-09 16:57:17 +0200581 prom_dma = dma_map_single(fore200e->dev, prom, sizeof(struct prom_data),
582 DMA_FROM_DEVICE);
Christoph Hellwig1d9d8be92018-10-09 16:57:20 +0200583 if (dma_mapping_error(fore200e->dev, prom_dma))
584 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
586 fore200e->bus->write(prom_dma, &entry->cp_entry->cmd.prom_block.prom_haddr);
587
588 *entry->status = STATUS_PENDING;
589
590 fore200e->bus->write(*(u32*)&opcode, (u32 __iomem *)&entry->cp_entry->cmd.prom_block.opcode);
591
592 ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
593
594 *entry->status = STATUS_FREE;
595
Christoph Hellwigf3fadcb2018-10-09 16:57:17 +0200596 dma_unmap_single(fore200e->dev, prom_dma, sizeof(struct prom_data), DMA_FROM_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
598 if (ok == 0) {
599 printk(FORE200E "unable to get PROM data from device %s\n", fore200e->name);
600 return -EIO;
601 }
602
603#if defined(__BIG_ENDIAN)
604
605#define swap_here(addr) (*((u32*)(addr)) = swab32( *((u32*)(addr)) ))
606
607 /* MAC address is stored as little-endian */
608 swap_here(&prom->mac_addr[0]);
609 swap_here(&prom->mac_addr[4]);
610#endif
611
612 return 0;
613}
614
615
616static int
617fore200e_pca_proc_read(struct fore200e* fore200e, char *page)
618{
Christoph Hellwigaff9d262018-10-09 16:57:15 +0200619 struct pci_dev *pci_dev = to_pci_dev(fore200e->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620
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));
623}
624
Christoph Hellwig0efe5522018-10-09 16:57:14 +0200625static 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,
Christoph Hellwig0efe5522018-10-09 16:57:14 +0200633 .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,
641};
Chas Williamse92481f2008-06-17 16:23:11 -0700642#endif /* CONFIG_PCI */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
Chas Williamse92481f2008-06-17 16:23:11 -0700644#ifdef CONFIG_SBUS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
David S. Miller826b6cf2008-08-27 01:06:07 -0700646static u32 fore200e_sba_read(volatile u32 __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647{
648 return sbus_readl(addr);
649}
650
David S. Miller826b6cf2008-08-27 01:06:07 -0700651static void fore200e_sba_write(u32 val, volatile u32 __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652{
653 sbus_writel(val, addr);
654}
655
David S. Miller826b6cf2008-08-27 01:06:07 -0700656static void fore200e_sba_irq_enable(struct fore200e *fore200e)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657{
David S. Miller826b6cf2008-08-27 01:06:07 -0700658 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660}
661
David S. Miller826b6cf2008-08-27 01:06:07 -0700662static int fore200e_sba_irq_check(struct fore200e *fore200e)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663{
David S. Miller826b6cf2008-08-27 01:06:07 -0700664 return fore200e->bus->read(fore200e->regs.sba.hcr) & SBA200E_HCR_INTR_REQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665}
666
David S. Miller826b6cf2008-08-27 01:06:07 -0700667static void fore200e_sba_irq_ack(struct fore200e *fore200e)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668{
David S. Miller826b6cf2008-08-27 01:06:07 -0700669 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671}
672
David S. Miller826b6cf2008-08-27 01:06:07 -0700673static void fore200e_sba_reset(struct fore200e *fore200e)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674{
David S. Miller826b6cf2008-08-27 01:06:07 -0700675 fore200e->bus->write(SBA200E_HCR_RESET, fore200e->regs.sba.hcr);
676 fore200e_spin(10);
677 fore200e->bus->write(0, fore200e->regs.sba.hcr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678}
679
David S. Miller826b6cf2008-08-27 01:06:07 -0700680static int __init fore200e_sba_map(struct fore200e *fore200e)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681{
Christoph Hellwigaff9d262018-10-09 16:57:15 +0200682 struct platform_device *op = to_platform_device(fore200e->dev);
David S. Miller826b6cf2008-08-27 01:06:07 -0700683 unsigned int bursts;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684
David S. Miller826b6cf2008-08-27 01:06:07 -0700685 /* 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");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
David S. Miller826b6cf2008-08-27 01:06:07 -0700691 if (!fore200e->virt_base) {
692 printk(FORE200E "unable to map RAM of device %s\n", fore200e->name);
693 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 }
David S. Miller826b6cf2008-08-27 01:06:07 -0700695
696 DPRINTK(1, "device %s mapped to 0x%p\n", fore200e->name, fore200e->virt_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
David S. Miller826b6cf2008-08-27 01:06:07 -0700698 fore200e->bus->write(0x02, fore200e->regs.sba.isr); /* XXX hardwired interrupt level */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
David S. Miller826b6cf2008-08-27 01:06:07 -0700700 /* get the supported DVMA burst sizes */
Grant Likely61c7a082010-04-13 16:12:29 -0700701 bursts = of_getintprop_default(op->dev.of_node->parent, "burst-sizes", 0x00);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
David S. Miller826b6cf2008-08-27 01:06:07 -0700703 if (sbus_can_dma_64bit())
704 sbus_set_sbus64(&op->dev, bursts);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
David S. Miller826b6cf2008-08-27 01:06:07 -0700706 fore200e->state = FORE200E_STATE_MAP;
707 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708}
709
David S. Miller826b6cf2008-08-27 01:06:07 -0700710static void fore200e_sba_unmap(struct fore200e *fore200e)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711{
Christoph Hellwigaff9d262018-10-09 16:57:15 +0200712 struct platform_device *op = to_platform_device(fore200e->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713
David S. Miller826b6cf2008-08-27 01:06:07 -0700714 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718}
719
David S. Miller826b6cf2008-08-27 01:06:07 -0700720static int __init fore200e_sba_configure(struct fore200e *fore200e)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721{
David S. Miller826b6cf2008-08-27 01:06:07 -0700722 fore200e->state = FORE200E_STATE_CONFIGURE;
723 return 0;
724}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
David S. Miller826b6cf2008-08-27 01:06:07 -0700726static int __init fore200e_sba_prom_read(struct fore200e *fore200e, struct prom_data *prom)
727{
Christoph Hellwigaff9d262018-10-09 16:57:15 +0200728 struct platform_device *op = to_platform_device(fore200e->dev);
David S. Miller826b6cf2008-08-27 01:06:07 -0700729 const u8 *prop;
730 int len;
731
Grant Likely61c7a082010-04-13 16:12:29 -0700732 prop = of_get_property(op->dev.of_node, "madaddrlo2", &len);
David S. Miller826b6cf2008-08-27 01:06:07 -0700733 if (!prop)
734 return -ENODEV;
735 memcpy(&prom->mac_addr[4], prop, 4);
736
Grant Likely61c7a082010-04-13 16:12:29 -0700737 prop = of_get_property(op->dev.of_node, "madaddrhi4", &len);
David S. Miller826b6cf2008-08-27 01:06:07 -0700738 if (!prop)
739 return -ENODEV;
740 memcpy(&prom->mac_addr[2], prop, 4);
741
Grant Likely61c7a082010-04-13 16:12:29 -0700742 prom->serial_number = of_getintprop_default(op->dev.of_node,
743 "serialnumber", 0);
744 prom->hw_revision = of_getintprop_default(op->dev.of_node,
745 "promversion", 0);
David S. Miller826b6cf2008-08-27 01:06:07 -0700746
747 return 0;
748}
749
750static int fore200e_sba_proc_read(struct fore200e *fore200e, char *page)
751{
Christoph Hellwigaff9d262018-10-09 16:57:15 +0200752 struct platform_device *op = to_platform_device(fore200e->dev);
David S. Miller826b6cf2008-08-27 01:06:07 -0700753 const struct linux_prom_registers *regs;
754
Grant Likely61c7a082010-04-13 16:12:29 -0700755 regs = of_get_property(op->dev.of_node, "reg", NULL);
David S. Miller826b6cf2008-08-27 01:06:07 -0700756
757 return sprintf(page, " SBUS slot/device:\t\t%d/'%s'\n",
Grant Likely61c7a082010-04-13 16:12:29 -0700758 (regs ? regs->which_io : 0), op->dev.of_node->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
Christoph Hellwig0efe5522018-10-09 16:57:14 +0200761static const struct fore200e_bus fore200e_sbus_ops = {
762 .model_name = "SBA-200E",
763 .proc_name = "sba200e",
764 .descr_alignment = 32,
Christoph Hellwig66604642018-10-12 10:17:51 +0200765 .buffer_alignment = 64,
Christoph Hellwig0efe5522018-10-09 16:57:14 +0200766 .status_alignment = 32,
767 .read = fore200e_sba_read,
768 .write = fore200e_sba_write,
Christoph Hellwig0efe5522018-10-09 16:57:14 +0200769 .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,
778};
779#endif /* CONFIG_SBUS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
781static void
782fore200e_tx_irq(struct fore200e* fore200e)
783{
784 struct host_txq* txq = &fore200e->host_txq;
785 struct host_txq_entry* entry;
786 struct atm_vcc* vcc;
787 struct fore200e_vc_map* vc_map;
788
789 if (fore200e->host_txq.txing == 0)
790 return;
791
792 for (;;) {
793
794 entry = &txq->host_entry[ txq->tail ];
795
796 if ((*entry->status & STATUS_COMPLETE) == 0) {
797 break;
798 }
799
800 DPRINTK(3, "TX COMPLETED: entry = %p [tail = %d], vc_map = %p, skb = %p\n",
801 entry, txq->tail, entry->vc_map, entry->skb);
802
803 /* free copy of misaligned data */
Jesper Juhla2c1aa52005-06-02 13:04:07 -0700804 kfree(entry->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
806 /* remove DMA mapping */
Christoph Hellwigf3fadcb2018-10-09 16:57:17 +0200807 dma_unmap_single(fore200e->dev, entry->tpd->tsd[ 0 ].buffer, entry->tpd->tsd[ 0 ].length,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 DMA_TO_DEVICE);
809
810 vc_map = entry->vc_map;
811
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)) {
815
816 DPRINTK(1, "no ready vcc found for PDU sent on device %d\n",
817 fore200e->atm_dev->number);
818
819 dev_kfree_skb_any(entry->skb);
820 }
821 else {
822 ASSERT(vc_map->vcc);
823
824 /* vcc closed then immediately re-opened? */
825 if (vc_map->incarn != entry->incarn) {
826
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. */
838
839 DPRINTK(1, "vcc closed-then-re-opened; dropping PDU sent on device %d\n",
840 fore200e->atm_dev->number);
841
842 dev_kfree_skb_any(entry->skb);
843 }
844 else {
845 vcc = vc_map->vcc;
846 ASSERT(vcc);
847
848 /* notify tx completion */
849 if (vcc->pop) {
850 vcc->pop(vcc, entry->skb);
851 }
852 else {
853 dev_kfree_skb_any(entry->skb);
854 }
Reshetova, Elena14afee42017-06-30 13:08:00 +0300855
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 /* check error condition */
857 if (*entry->status & STATUS_ERROR)
858 atomic_inc(&vcc->stats->tx_err);
859 else
860 atomic_inc(&vcc->stats->tx);
861 }
862 }
863
864 *entry->status = STATUS_FREE;
865
866 fore200e->host_txq.txing--;
867
868 FORE200E_NEXT_ENTRY(txq->tail, QUEUE_SIZE_TX);
869 }
870}
871
872
873#ifdef FORE200E_BSQ_DEBUG
874int bsq_audit(int where, struct host_bsq* bsq, int scheme, int magn)
875{
876 struct buffer* buffer;
877 int count = 0;
878
879 buffer = bsq->freebuf;
880 while (buffer) {
881
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);
885 }
886
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);
890 }
891
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);
895 }
896
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);
900 }
901
902 count++;
903 buffer = buffer->next;
904 }
905
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);
909 }
910 return 0;
911}
912#endif
913
914
915static void
916fore200e_supply(struct fore200e* fore200e)
917{
918 int scheme, magn, i;
919
920 struct host_bsq* bsq;
921 struct host_bsq_entry* entry;
922 struct buffer* buffer;
923
924 for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
925 for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
926
927 bsq = &fore200e->host_bsq[ scheme ][ magn ];
928
929#ifdef FORE200E_BSQ_DEBUG
930 bsq_audit(1, bsq, scheme, magn);
931#endif
932 while (bsq->freebuf_count >= RBD_BLK_SIZE) {
933
934 DPRINTK(2, "supplying %d rx buffers to queue %d / %d, freebuf_count = %d\n",
935 RBD_BLK_SIZE, scheme, magn, bsq->freebuf_count);
936
937 entry = &bsq->host_entry[ bsq->head ];
938
939 for (i = 0; i < RBD_BLK_SIZE; i++) {
940
941 /* take the first buffer in the free buffer list */
942 buffer = bsq->freebuf;
943 if (!buffer) {
944 printk(FORE200E "no more free bufs in queue %d.%d, but freebuf_count = %d\n",
945 scheme, magn, bsq->freebuf_count);
946 return;
947 }
948 bsq->freebuf = buffer->next;
949
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;
955#endif
956 entry->rbd_block->rbd[ i ].buffer_haddr = buffer->data.dma_addr;
957 entry->rbd_block->rbd[ i ].handle = FORE200E_BUF2HDL(buffer);
958 }
959
960 FORE200E_NEXT_ENTRY(bsq->head, QUEUE_SIZE_BS);
961
962 /* decrease accordingly the number of free rx buffers */
963 bsq->freebuf_count -= RBD_BLK_SIZE;
964
965 *entry->status = STATUS_PENDING;
966 fore200e->bus->write(entry->rbd_block_dma, &entry->cp_entry->rbd_block_haddr);
967 }
968 }
969 }
970}
971
972
973static int
974fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rpd)
975{
976 struct sk_buff* skb;
977 struct buffer* buffer;
978 struct fore200e_vcc* fore200e_vcc;
979 int i, pdu_len = 0;
980#ifdef FORE200E_52BYTE_AAL0_SDU
981 u32 cell_header = 0;
982#endif
983
984 ASSERT(vcc);
985
986 fore200e_vcc = FORE200E_VCC(vcc);
987 ASSERT(fore200e_vcc);
988
989#ifdef FORE200E_52BYTE_AAL0_SDU
990 if ((vcc->qos.aal == ATM_AAL0) && (vcc->qos.rxtp.max_sdu == ATM_AAL0_SDU)) {
991
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) |
996 rpd->atm_header.clp;
997 pdu_len = 4;
998 }
999#endif
1000
1001 /* compute total PDU length */
1002 for (i = 0; i < rpd->nseg; i++)
1003 pdu_len += rpd->rsd[ i ].length;
1004
1005 skb = alloc_skb(pdu_len, GFP_ATOMIC);
1006 if (skb == NULL) {
1007 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
1008
1009 atomic_inc(&vcc->stats->rx_drop);
1010 return -ENOMEM;
1011 }
1012
Patrick McHardya61bbcf2005-08-14 17:24:31 -07001013 __net_timestamp(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
1015#ifdef FORE200E_52BYTE_AAL0_SDU
1016 if (cell_header) {
1017 *((u32*)skb_put(skb, 4)) = cell_header;
1018 }
1019#endif
1020
1021 /* reassemble segments */
1022 for (i = 0; i < rpd->nseg; i++) {
1023
1024 /* rebuild rx buffer address from rsd handle */
1025 buffer = FORE200E_HDL2BUF(rpd->rsd[ i ].handle);
1026
1027 /* Make device DMA transfer visible to CPU. */
Christoph Hellwigf3fadcb2018-10-09 16:57:17 +02001028 dma_sync_single_for_cpu(fore200e->dev, buffer->data.dma_addr,
1029 rpd->rsd[i].length, DMA_FROM_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030
Johannes Berg59ae1d12017-06-16 14:29:20 +02001031 skb_put_data(skb, buffer->data.align_addr, rpd->rsd[i].length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032
1033 /* Now let the device get at it again. */
Christoph Hellwigf3fadcb2018-10-09 16:57:17 +02001034 dma_sync_single_for_device(fore200e->dev, buffer->data.dma_addr,
1035 rpd->rsd[i].length, DMA_FROM_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 }
1037
1038 DPRINTK(3, "rx skb: len = %d, truesize = %d\n", skb->len, skb->truesize);
1039
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++;
1045
1046 /* push PDU */
1047 if (atm_charge(vcc, skb->truesize) == 0) {
1048
1049 DPRINTK(2, "receive buffers saturated for %d.%d.%d - PDU dropped\n",
1050 vcc->itf, vcc->vpi, vcc->vci);
1051
1052 dev_kfree_skb_any(skb);
1053
1054 atomic_inc(&vcc->stats->rx_drop);
1055 return -ENOMEM;
1056 }
1057
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 vcc->push(vcc, skb);
1059 atomic_inc(&vcc->stats->rx);
1060
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 return 0;
1062}
1063
1064
1065static void
1066fore200e_collect_rpd(struct fore200e* fore200e, struct rpd* rpd)
1067{
1068 struct host_bsq* bsq;
1069 struct buffer* buffer;
1070 int i;
1071
1072 for (i = 0; i < rpd->nseg; i++) {
1073
1074 /* rebuild rx buffer address from rsd handle */
1075 buffer = FORE200E_HDL2BUF(rpd->rsd[ i ].handle);
1076
1077 bsq = &fore200e->host_bsq[ buffer->scheme ][ buffer->magn ];
1078
1079#ifdef FORE200E_BSQ_DEBUG
1080 bsq_audit(2, bsq, buffer->scheme, buffer->magn);
1081
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;
1086#endif
1087
1088 /* re-insert the buffer into the free buffer list */
1089 buffer->next = bsq->freebuf;
1090 bsq->freebuf = buffer;
1091
1092 /* then increment the number of free rx buffers */
1093 bsq->freebuf_count++;
1094 }
1095}
1096
1097
1098static void
1099fore200e_rx_irq(struct fore200e* fore200e)
1100{
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;
1105
1106 for (;;) {
1107
1108 entry = &rxq->host_entry[ rxq->head ];
1109
1110 /* no more received PDUs */
1111 if ((*entry->status & STATUS_COMPLETE) == 0)
1112 break;
1113
1114 vc_map = FORE200E_VC_MAP(fore200e, entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
1115
1116 if ((vc_map->vcc == NULL) ||
1117 (test_bit(ATM_VF_READY, &vc_map->vcc->flags) == 0)) {
1118
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);
1122 }
1123 else {
1124 vcc = vc_map->vcc;
1125 ASSERT(vcc);
1126
1127 if ((*entry->status & STATUS_ERROR) == 0) {
1128
1129 fore200e_push_rpd(fore200e, vcc, entry->rpd);
1130 }
1131 else {
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);
1136 }
1137 }
1138
1139 FORE200E_NEXT_ENTRY(rxq->head, QUEUE_SIZE_RX);
1140
1141 fore200e_collect_rpd(fore200e, entry->rpd);
1142
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;
1146
1147 fore200e_supply(fore200e);
1148 }
1149}
1150
1151
1152#ifndef FORE200E_USE_TASKLET
1153static void
1154fore200e_irq(struct fore200e* fore200e)
1155{
1156 unsigned long flags;
1157
1158 spin_lock_irqsave(&fore200e->q_lock, flags);
1159 fore200e_rx_irq(fore200e);
1160 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1161
1162 spin_lock_irqsave(&fore200e->q_lock, flags);
1163 fore200e_tx_irq(fore200e);
1164 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1165}
1166#endif
1167
1168
1169static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001170fore200e_interrupt(int irq, void* dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171{
1172 struct fore200e* fore200e = FORE200E_DEV((struct atm_dev*)dev);
1173
1174 if (fore200e->bus->irq_check(fore200e) == 0) {
1175
1176 DPRINTK(3, "interrupt NOT triggered by device %d\n", fore200e->atm_dev->number);
1177 return IRQ_NONE;
1178 }
1179 DPRINTK(3, "interrupt triggered by device %d\n", fore200e->atm_dev->number);
1180
1181#ifdef FORE200E_USE_TASKLET
1182 tasklet_schedule(&fore200e->tx_tasklet);
1183 tasklet_schedule(&fore200e->rx_tasklet);
1184#else
1185 fore200e_irq(fore200e);
1186#endif
1187
1188 fore200e->bus->irq_ack(fore200e);
1189 return IRQ_HANDLED;
1190}
1191
1192
1193#ifdef FORE200E_USE_TASKLET
1194static void
1195fore200e_tx_tasklet(unsigned long data)
1196{
1197 struct fore200e* fore200e = (struct fore200e*) data;
1198 unsigned long flags;
1199
1200 DPRINTK(3, "tx tasklet scheduled for device %d\n", fore200e->atm_dev->number);
1201
1202 spin_lock_irqsave(&fore200e->q_lock, flags);
1203 fore200e_tx_irq(fore200e);
1204 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1205}
1206
1207
1208static void
1209fore200e_rx_tasklet(unsigned long data)
1210{
1211 struct fore200e* fore200e = (struct fore200e*) data;
1212 unsigned long flags;
1213
1214 DPRINTK(3, "rx tasklet scheduled for device %d\n", fore200e->atm_dev->number);
1215
1216 spin_lock_irqsave(&fore200e->q_lock, flags);
1217 fore200e_rx_irq((struct fore200e*) data);
1218 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1219}
1220#endif
1221
1222
1223static int
1224fore200e_select_scheme(struct atm_vcc* vcc)
1225{
1226 /* fairly balance the VCs over (identical) buffer schemes */
1227 int scheme = vcc->vci % 2 ? BUFFER_SCHEME_ONE : BUFFER_SCHEME_TWO;
1228
1229 DPRINTK(1, "VC %d.%d.%d uses buffer scheme %d\n",
1230 vcc->itf, vcc->vpi, vcc->vci, scheme);
1231
1232 return scheme;
1233}
1234
1235
1236static int
1237fore200e_activate_vcin(struct fore200e* fore200e, int activate, struct atm_vcc* vcc, int mtu)
1238{
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;
1243 struct vpvc vpvc;
1244 int ok;
1245 enum fore200e_aal aal = fore200e_atm2fore_aal(vcc->qos.aal);
1246
1247 FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
1248
1249 if (activate) {
1250 FORE200E_VCC(vcc)->scheme = fore200e_select_scheme(vcc);
1251
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;
1256 }
1257 else {
1258 deactiv_opcode.opcode = OPCODE_DEACTIVATE_VCIN;
1259 deactiv_opcode.pad = 0;
1260 }
1261
1262 vpvc.vci = vcc->vci;
1263 vpvc.vpi = vcc->vpi;
1264
1265 *entry->status = STATUS_PENDING;
1266
1267 if (activate) {
1268
1269#ifdef FORE200E_52BYTE_AAL0_SDU
1270 mtu = 48;
1271#endif
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);
1276 }
1277 else {
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);
1280 }
1281
1282 ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
1283
1284 *entry->status = STATUS_FREE;
1285
1286 if (ok == 0) {
1287 printk(FORE200E "unable to %s VC %d.%d.%d\n",
1288 activate ? "open" : "close", vcc->itf, vcc->vpi, vcc->vci);
1289 return -EIO;
1290 }
1291
1292 DPRINTK(1, "VC %d.%d.%d %sed\n", vcc->itf, vcc->vpi, vcc->vci,
1293 activate ? "open" : "clos");
1294
1295 return 0;
1296}
1297
1298
1299#define FORE200E_MAX_BACK2BACK_CELLS 255 /* XXX depends on CDVT */
1300
1301static void
1302fore200e_rate_ctrl(struct atm_qos* qos, struct tpd_rate* rate)
1303{
1304 if (qos->txtp.max_pcr < ATM_OC3_PCR) {
1305
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;
1309 }
1310 else {
1311 /* disable rate control */
1312 rate->data_cells = rate->idle_cells = 0;
1313 }
1314}
1315
1316
1317static int
1318fore200e_open(struct atm_vcc *vcc)
1319{
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;
1324 int vci = vcc->vci;
1325 short vpi = vcc->vpi;
1326
1327 ASSERT((vpi >= 0) && (vpi < 1<<FORE200E_VPI_BITS));
1328 ASSERT((vci >= 0) && (vci < 1<<FORE200E_VCI_BITS));
1329
1330 spin_lock_irqsave(&fore200e->q_lock, flags);
1331
1332 vc_map = FORE200E_VC_MAP(fore200e, vpi, vci);
1333 if (vc_map->vcc) {
1334
1335 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1336
1337 printk(FORE200E "VC %d.%d.%d already in use\n",
1338 fore200e->atm_dev->number, vpi, vci);
1339
1340 return -EINVAL;
1341 }
1342
1343 vc_map->vcc = vcc;
1344
1345 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1346
Adrian Bunk1f8a5fb2006-12-19 19:36:32 -08001347 fore200e_vcc = kzalloc(sizeof(struct fore200e_vcc), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 if (fore200e_vcc == NULL) {
1349 vc_map->vcc = NULL;
1350 return -ENOMEM;
1351 }
1352
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);
1360
1361 /* pseudo-CBR bandwidth requested? */
1362 if ((vcc->qos.txtp.traffic_class == ATM_CBR) && (vcc->qos.txtp.max_pcr > 0)) {
1363
Matthias Kaehlckebfbf3c02007-04-26 01:41:49 -07001364 mutex_lock(&fore200e->rate_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 if (fore200e->available_cell_rate < vcc->qos.txtp.max_pcr) {
Matthias Kaehlckebfbf3c02007-04-26 01:41:49 -07001366 mutex_unlock(&fore200e->rate_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367
Adrian Bunk1f8a5fb2006-12-19 19:36:32 -08001368 kfree(fore200e_vcc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 vc_map->vcc = NULL;
1370 return -EAGAIN;
1371 }
1372
1373 /* reserve bandwidth */
1374 fore200e->available_cell_rate -= vcc->qos.txtp.max_pcr;
Matthias Kaehlckebfbf3c02007-04-26 01:41:49 -07001375 mutex_unlock(&fore200e->rate_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 }
1377
1378 vcc->itf = vcc->dev->number;
1379
1380 set_bit(ATM_VF_PARTIAL,&vcc->flags);
1381 set_bit(ATM_VF_ADDR, &vcc->flags);
1382
1383 vcc->dev_data = fore200e_vcc;
1384
1385 if (fore200e_activate_vcin(fore200e, 1, vcc, vcc->qos.rxtp.max_sdu) < 0) {
1386
1387 vc_map->vcc = NULL;
1388
1389 clear_bit(ATM_VF_ADDR, &vcc->flags);
1390 clear_bit(ATM_VF_PARTIAL,&vcc->flags);
1391
1392 vcc->dev_data = NULL;
1393
1394 fore200e->available_cell_rate += vcc->qos.txtp.max_pcr;
1395
Adrian Bunk1f8a5fb2006-12-19 19:36:32 -08001396 kfree(fore200e_vcc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 return -EINVAL;
1398 }
1399
1400 /* compute rate control parameters */
1401 if ((vcc->qos.txtp.traffic_class == ATM_CBR) && (vcc->qos.txtp.max_pcr > 0)) {
1402
1403 fore200e_rate_ctrl(&vcc->qos, &fore200e_vcc->rate);
1404 set_bit(ATM_VF_HASQOS, &vcc->flags);
1405
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);
1410 }
1411
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;
1415
1416 /* new incarnation of the vcc */
1417 vc_map->incarn = ++fore200e->incarn_count;
1418
1419 /* VC unusable before this flag is set */
1420 set_bit(ATM_VF_READY, &vcc->flags);
1421
1422 return 0;
1423}
1424
1425
1426static void
1427fore200e_close(struct atm_vcc* vcc)
1428{
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;
1433
1434 ASSERT(vcc);
1435 ASSERT((vcc->vpi >= 0) && (vcc->vpi < 1<<FORE200E_VPI_BITS));
1436 ASSERT((vcc->vci >= 0) && (vcc->vci < 1<<FORE200E_VCI_BITS));
1437
1438 DPRINTK(2, "closing %d.%d.%d:%d\n", vcc->itf, vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal));
1439
1440 clear_bit(ATM_VF_READY, &vcc->flags);
1441
1442 fore200e_activate_vcin(fore200e, 0, vcc, 0);
1443
1444 spin_lock_irqsave(&fore200e->q_lock, flags);
1445
1446 vc_map = FORE200E_VC_MAP(fore200e, vcc->vpi, vcc->vci);
1447
1448 /* the vc is no longer considered as "in use" by fore200e_open() */
1449 vc_map->vcc = NULL;
1450
1451 vcc->itf = vcc->vci = vcc->vpi = 0;
1452
1453 fore200e_vcc = FORE200E_VCC(vcc);
1454 vcc->dev_data = NULL;
1455
1456 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1457
1458 /* release reserved bandwidth, if any */
1459 if ((vcc->qos.txtp.traffic_class == ATM_CBR) && (vcc->qos.txtp.max_pcr > 0)) {
1460
Matthias Kaehlckebfbf3c02007-04-26 01:41:49 -07001461 mutex_lock(&fore200e->rate_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 fore200e->available_cell_rate += vcc->qos.txtp.max_pcr;
Matthias Kaehlckebfbf3c02007-04-26 01:41:49 -07001463 mutex_unlock(&fore200e->rate_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464
1465 clear_bit(ATM_VF_HASQOS, &vcc->flags);
1466 }
1467
1468 clear_bit(ATM_VF_ADDR, &vcc->flags);
1469 clear_bit(ATM_VF_PARTIAL,&vcc->flags);
1470
1471 ASSERT(fore200e_vcc);
Adrian Bunk1f8a5fb2006-12-19 19:36:32 -08001472 kfree(fore200e_vcc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473}
1474
1475
1476static int
1477fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
1478{
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;
1484 struct tpd* tpd;
1485 struct tpd_haddr tpd_haddr;
1486 int retry = CONFIG_ATM_FORE200E_TX_RETRY;
1487 int tx_copy = 0;
1488 int tx_len = skb->len;
1489 u32* cell_header = NULL;
1490 unsigned char* skb_data;
1491 int skb_len;
1492 unsigned char* data;
1493 unsigned long flags;
1494
1495 ASSERT(vcc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 ASSERT(fore200e);
1497 ASSERT(fore200e_vcc);
1498
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);
1502 return -EINVAL;
1503 }
1504
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;
1510
1511 DPRINTK(3, "user-supplied cell header = 0x%08x\n", *cell_header);
1512 }
1513 else
1514#endif
1515 {
1516 skb_data = skb->data;
1517 skb_len = skb->len;
1518 }
1519
1520 if (((unsigned long)skb_data) & 0x3) {
1521
1522 DPRINTK(2, "misaligned tx PDU on device %s\n", fore200e->name);
1523 tx_copy = 1;
1524 tx_len = skb_len;
1525 }
1526
1527 if ((vcc->qos.aal == ATM_AAL0) && (skb_len % ATM_CELL_PAYLOAD)) {
1528
1529 /* this simply NUKES the PCA board */
1530 DPRINTK(2, "incomplete tx AAL0 PDU on device %s\n", fore200e->name);
1531 tx_copy = 1;
1532 tx_len = ((skb_len / ATM_CELL_PAYLOAD) + 1) * ATM_CELL_PAYLOAD;
1533 }
1534
1535 if (tx_copy) {
Christoph Hellwig0e21b222018-10-09 16:57:19 +02001536 data = kmalloc(tx_len, GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 if (data == NULL) {
1538 if (vcc->pop) {
1539 vcc->pop(vcc, skb);
1540 }
1541 else {
1542 dev_kfree_skb_any(skb);
1543 }
1544 return -ENOMEM;
1545 }
1546
1547 memcpy(data, skb_data, skb_len);
1548 if (skb_len < tx_len)
1549 memset(data + skb_len, 0x00, tx_len - skb_len);
1550 }
1551 else {
1552 data = skb_data;
1553 }
1554
1555 vc_map = FORE200E_VC_MAP(fore200e, vcc->vpi, vcc->vci);
1556 ASSERT(vc_map->vcc == vcc);
1557
1558 retry_here:
1559
1560 spin_lock_irqsave(&fore200e->q_lock, flags);
1561
1562 entry = &txq->host_entry[ txq->head ];
1563
1564 if ((*entry->status != STATUS_FREE) || (txq->txing >= QUEUE_SIZE_TX - 2)) {
1565
1566 /* try to free completed tx queue entries */
1567 fore200e_tx_irq(fore200e);
1568
1569 if (*entry->status != STATUS_FREE) {
1570
1571 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1572
1573 /* retry once again? */
1574 if (--retry > 0) {
1575 udelay(50);
1576 goto retry_here;
1577 }
1578
1579 atomic_inc(&vcc->stats->tx_err);
1580
1581 fore200e->tx_sat++;
1582 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
1583 fore200e->name, fore200e->cp_queues->heartbeat);
1584 if (vcc->pop) {
1585 vcc->pop(vcc, skb);
1586 }
1587 else {
1588 dev_kfree_skb_any(skb);
1589 }
1590
1591 if (tx_copy)
1592 kfree(data);
1593
1594 return -ENOBUFS;
1595 }
1596 }
1597
1598 entry->incarn = vc_map->incarn;
1599 entry->vc_map = vc_map;
1600 entry->skb = skb;
1601 entry->data = tx_copy ? data : NULL;
1602
1603 tpd = entry->tpd;
Christoph Hellwigf3fadcb2018-10-09 16:57:17 +02001604 tpd->tsd[ 0 ].buffer = dma_map_single(fore200e->dev, data, tx_len,
1605 DMA_TO_DEVICE);
Christoph Hellwig1d9d8be92018-10-09 16:57:20 +02001606 if (dma_mapping_error(fore200e->dev, tpd->tsd[0].buffer)) {
1607 if (tx_copy)
1608 kfree(data);
1609 return -ENOMEM;
1610 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 tpd->tsd[ 0 ].length = tx_len;
1612
1613 FORE200E_NEXT_ENTRY(txq->head, QUEUE_SIZE_TX);
1614 txq->txing++;
1615
1616 /* The dma_map call above implies a dma_sync so the device can use it,
1617 * thus no explicit dma_sync call is necessary here.
1618 */
1619
1620 DPRINTK(3, "tx on %d.%d.%d:%d, len = %u (%u)\n",
1621 vcc->itf, vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal),
1622 tpd->tsd[0].length, skb_len);
1623
1624 if (skb_len < fore200e_vcc->tx_min_pdu)
1625 fore200e_vcc->tx_min_pdu = skb_len;
1626 if (skb_len > fore200e_vcc->tx_max_pdu)
1627 fore200e_vcc->tx_max_pdu = skb_len;
1628 fore200e_vcc->tx_pdu++;
1629
1630 /* set tx rate control information */
1631 tpd->rate.data_cells = fore200e_vcc->rate.data_cells;
1632 tpd->rate.idle_cells = fore200e_vcc->rate.idle_cells;
1633
1634 if (cell_header) {
1635 tpd->atm_header.clp = (*cell_header & ATM_HDR_CLP);
1636 tpd->atm_header.plt = (*cell_header & ATM_HDR_PTI_MASK) >> ATM_HDR_PTI_SHIFT;
1637 tpd->atm_header.vci = (*cell_header & ATM_HDR_VCI_MASK) >> ATM_HDR_VCI_SHIFT;
1638 tpd->atm_header.vpi = (*cell_header & ATM_HDR_VPI_MASK) >> ATM_HDR_VPI_SHIFT;
1639 tpd->atm_header.gfc = (*cell_header & ATM_HDR_GFC_MASK) >> ATM_HDR_GFC_SHIFT;
1640 }
1641 else {
1642 /* set the ATM header, common to all cells conveying the PDU */
1643 tpd->atm_header.clp = 0;
1644 tpd->atm_header.plt = 0;
1645 tpd->atm_header.vci = vcc->vci;
1646 tpd->atm_header.vpi = vcc->vpi;
1647 tpd->atm_header.gfc = 0;
1648 }
1649
1650 tpd->spec.length = tx_len;
1651 tpd->spec.nseg = 1;
1652 tpd->spec.aal = fore200e_atm2fore_aal(vcc->qos.aal);
1653 tpd->spec.intr = 1;
1654
1655 tpd_haddr.size = sizeof(struct tpd) / (1<<TPD_HADDR_SHIFT); /* size is expressed in 32 byte blocks */
1656 tpd_haddr.pad = 0;
1657 tpd_haddr.haddr = entry->tpd_dma >> TPD_HADDR_SHIFT; /* shift the address, as we are in a bitfield */
1658
1659 *entry->status = STATUS_PENDING;
1660 fore200e->bus->write(*(u32*)&tpd_haddr, (u32 __iomem *)&entry->cp_entry->tpd_haddr);
1661
1662 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1663
1664 return 0;
1665}
1666
1667
1668static int
1669fore200e_getstats(struct fore200e* fore200e)
1670{
1671 struct host_cmdq* cmdq = &fore200e->host_cmdq;
1672 struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
1673 struct stats_opcode opcode;
1674 int ok;
1675 u32 stats_dma_addr;
1676
1677 if (fore200e->stats == NULL) {
Christoph Hellwig0e21b222018-10-09 16:57:19 +02001678 fore200e->stats = kzalloc(sizeof(struct stats), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 if (fore200e->stats == NULL)
1680 return -ENOMEM;
1681 }
1682
Christoph Hellwigf3fadcb2018-10-09 16:57:17 +02001683 stats_dma_addr = dma_map_single(fore200e->dev, fore200e->stats,
1684 sizeof(struct stats), DMA_FROM_DEVICE);
Christoph Hellwig1d9d8be92018-10-09 16:57:20 +02001685 if (dma_mapping_error(fore200e->dev, stats_dma_addr))
1686 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687
1688 FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
1689
1690 opcode.opcode = OPCODE_GET_STATS;
1691 opcode.pad = 0;
1692
1693 fore200e->bus->write(stats_dma_addr, &entry->cp_entry->cmd.stats_block.stats_haddr);
1694
1695 *entry->status = STATUS_PENDING;
1696
1697 fore200e->bus->write(*(u32*)&opcode, (u32 __iomem *)&entry->cp_entry->cmd.stats_block.opcode);
1698
1699 ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
1700
1701 *entry->status = STATUS_FREE;
1702
Christoph Hellwigf3fadcb2018-10-09 16:57:17 +02001703 dma_unmap_single(fore200e->dev, stats_dma_addr, sizeof(struct stats), DMA_FROM_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704
1705 if (ok == 0) {
1706 printk(FORE200E "unable to get statistics from device %s\n", fore200e->name);
1707 return -EIO;
1708 }
1709
1710 return 0;
1711}
1712
1713
1714static int
1715fore200e_getsockopt(struct atm_vcc* vcc, int level, int optname, void __user *optval, int optlen)
1716{
1717 /* struct fore200e* fore200e = FORE200E_DEV(vcc->dev); */
1718
1719 DPRINTK(2, "getsockopt %d.%d.%d, level = %d, optname = 0x%x, optval = 0x%p, optlen = %d\n",
1720 vcc->itf, vcc->vpi, vcc->vci, level, optname, optval, optlen);
1721
1722 return -EINVAL;
1723}
1724
1725
1726static int
David S. Millerb7058842009-09-30 16:12:20 -07001727fore200e_setsockopt(struct atm_vcc* vcc, int level, int optname, void __user *optval, unsigned int optlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728{
1729 /* struct fore200e* fore200e = FORE200E_DEV(vcc->dev); */
1730
1731 DPRINTK(2, "setsockopt %d.%d.%d, level = %d, optname = 0x%x, optval = 0x%p, optlen = %d\n",
1732 vcc->itf, vcc->vpi, vcc->vci, level, optname, optval, optlen);
1733
1734 return -EINVAL;
1735}
1736
1737
1738#if 0 /* currently unused */
1739static int
1740fore200e_get_oc3(struct fore200e* fore200e, struct oc3_regs* regs)
1741{
1742 struct host_cmdq* cmdq = &fore200e->host_cmdq;
1743 struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
1744 struct oc3_opcode opcode;
1745 int ok;
1746 u32 oc3_regs_dma_addr;
1747
1748 oc3_regs_dma_addr = fore200e->bus->dma_map(fore200e, regs, sizeof(struct oc3_regs), DMA_FROM_DEVICE);
1749
1750 FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
1751
1752 opcode.opcode = OPCODE_GET_OC3;
1753 opcode.reg = 0;
1754 opcode.value = 0;
1755 opcode.mask = 0;
1756
1757 fore200e->bus->write(oc3_regs_dma_addr, &entry->cp_entry->cmd.oc3_block.regs_haddr);
1758
1759 *entry->status = STATUS_PENDING;
1760
1761 fore200e->bus->write(*(u32*)&opcode, (u32*)&entry->cp_entry->cmd.oc3_block.opcode);
1762
1763 ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
1764
1765 *entry->status = STATUS_FREE;
1766
1767 fore200e->bus->dma_unmap(fore200e, oc3_regs_dma_addr, sizeof(struct oc3_regs), DMA_FROM_DEVICE);
1768
1769 if (ok == 0) {
1770 printk(FORE200E "unable to get OC-3 regs of device %s\n", fore200e->name);
1771 return -EIO;
1772 }
1773
1774 return 0;
1775}
1776#endif
1777
1778
1779static int
1780fore200e_set_oc3(struct fore200e* fore200e, u32 reg, u32 value, u32 mask)
1781{
1782 struct host_cmdq* cmdq = &fore200e->host_cmdq;
1783 struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
1784 struct oc3_opcode opcode;
1785 int ok;
1786
1787 DPRINTK(2, "set OC-3 reg = 0x%02x, value = 0x%02x, mask = 0x%02x\n", reg, value, mask);
1788
1789 FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
1790
1791 opcode.opcode = OPCODE_SET_OC3;
1792 opcode.reg = reg;
1793 opcode.value = value;
1794 opcode.mask = mask;
1795
1796 fore200e->bus->write(0, &entry->cp_entry->cmd.oc3_block.regs_haddr);
1797
1798 *entry->status = STATUS_PENDING;
1799
1800 fore200e->bus->write(*(u32*)&opcode, (u32 __iomem *)&entry->cp_entry->cmd.oc3_block.opcode);
1801
1802 ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
1803
1804 *entry->status = STATUS_FREE;
1805
1806 if (ok == 0) {
1807 printk(FORE200E "unable to set OC-3 reg 0x%02x of device %s\n", reg, fore200e->name);
1808 return -EIO;
1809 }
1810
1811 return 0;
1812}
1813
1814
1815static int
1816fore200e_setloop(struct fore200e* fore200e, int loop_mode)
1817{
1818 u32 mct_value, mct_mask;
1819 int error;
1820
1821 if (!capable(CAP_NET_ADMIN))
1822 return -EPERM;
1823
1824 switch (loop_mode) {
1825
1826 case ATM_LM_NONE:
1827 mct_value = 0;
1828 mct_mask = SUNI_MCT_DLE | SUNI_MCT_LLE;
1829 break;
1830
1831 case ATM_LM_LOC_PHY:
1832 mct_value = mct_mask = SUNI_MCT_DLE;
1833 break;
1834
1835 case ATM_LM_RMT_PHY:
1836 mct_value = mct_mask = SUNI_MCT_LLE;
1837 break;
1838
1839 default:
1840 return -EINVAL;
1841 }
1842
1843 error = fore200e_set_oc3(fore200e, SUNI_MCT, mct_value, mct_mask);
1844 if (error == 0)
1845 fore200e->loop_mode = loop_mode;
1846
1847 return error;
1848}
1849
1850
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851static int
1852fore200e_fetch_stats(struct fore200e* fore200e, struct sonet_stats __user *arg)
1853{
1854 struct sonet_stats tmp;
1855
1856 if (fore200e_getstats(fore200e) < 0)
1857 return -EIO;
1858
Al Viro63734a32008-03-16 22:23:04 +00001859 tmp.section_bip = be32_to_cpu(fore200e->stats->oc3.section_bip8_errors);
1860 tmp.line_bip = be32_to_cpu(fore200e->stats->oc3.line_bip24_errors);
1861 tmp.path_bip = be32_to_cpu(fore200e->stats->oc3.path_bip8_errors);
1862 tmp.line_febe = be32_to_cpu(fore200e->stats->oc3.line_febe_errors);
1863 tmp.path_febe = be32_to_cpu(fore200e->stats->oc3.path_febe_errors);
1864 tmp.corr_hcs = be32_to_cpu(fore200e->stats->oc3.corr_hcs_errors);
1865 tmp.uncorr_hcs = be32_to_cpu(fore200e->stats->oc3.ucorr_hcs_errors);
1866 tmp.tx_cells = be32_to_cpu(fore200e->stats->aal0.cells_transmitted) +
1867 be32_to_cpu(fore200e->stats->aal34.cells_transmitted) +
1868 be32_to_cpu(fore200e->stats->aal5.cells_transmitted);
1869 tmp.rx_cells = be32_to_cpu(fore200e->stats->aal0.cells_received) +
1870 be32_to_cpu(fore200e->stats->aal34.cells_received) +
1871 be32_to_cpu(fore200e->stats->aal5.cells_received);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872
1873 if (arg)
1874 return copy_to_user(arg, &tmp, sizeof(struct sonet_stats)) ? -EFAULT : 0;
1875
1876 return 0;
1877}
1878
1879
1880static int
1881fore200e_ioctl(struct atm_dev* dev, unsigned int cmd, void __user * arg)
1882{
1883 struct fore200e* fore200e = FORE200E_DEV(dev);
1884
1885 DPRINTK(2, "ioctl cmd = 0x%x (%u), arg = 0x%p (%lu)\n", cmd, cmd, arg, (unsigned long)arg);
1886
1887 switch (cmd) {
1888
1889 case SONET_GETSTAT:
1890 return fore200e_fetch_stats(fore200e, (struct sonet_stats __user *)arg);
1891
1892 case SONET_GETDIAG:
1893 return put_user(0, (int __user *)arg) ? -EFAULT : 0;
1894
1895 case ATM_SETLOOP:
1896 return fore200e_setloop(fore200e, (int)(unsigned long)arg);
1897
1898 case ATM_GETLOOP:
1899 return put_user(fore200e->loop_mode, (int __user *)arg) ? -EFAULT : 0;
1900
1901 case ATM_QUERYLOOP:
1902 return put_user(ATM_LM_LOC_PHY | ATM_LM_RMT_PHY, (int __user *)arg) ? -EFAULT : 0;
1903 }
1904
1905 return -ENOSYS; /* not implemented */
1906}
1907
1908
1909static int
1910fore200e_change_qos(struct atm_vcc* vcc,struct atm_qos* qos, int flags)
1911{
1912 struct fore200e_vcc* fore200e_vcc = FORE200E_VCC(vcc);
1913 struct fore200e* fore200e = FORE200E_DEV(vcc->dev);
1914
1915 if (!test_bit(ATM_VF_READY, &vcc->flags)) {
1916 DPRINTK(1, "VC %d.%d.%d not ready for QoS change\n", vcc->itf, vcc->vpi, vcc->vpi);
1917 return -EINVAL;
1918 }
1919
1920 DPRINTK(2, "change_qos %d.%d.%d, "
1921 "(tx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d; "
1922 "rx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d), flags = 0x%x\n"
1923 "available_cell_rate = %u",
1924 vcc->itf, vcc->vpi, vcc->vci,
1925 fore200e_traffic_class[ qos->txtp.traffic_class ],
1926 qos->txtp.min_pcr, qos->txtp.max_pcr, qos->txtp.max_cdv, qos->txtp.max_sdu,
1927 fore200e_traffic_class[ qos->rxtp.traffic_class ],
1928 qos->rxtp.min_pcr, qos->rxtp.max_pcr, qos->rxtp.max_cdv, qos->rxtp.max_sdu,
1929 flags, fore200e->available_cell_rate);
1930
1931 if ((qos->txtp.traffic_class == ATM_CBR) && (qos->txtp.max_pcr > 0)) {
1932
Matthias Kaehlckebfbf3c02007-04-26 01:41:49 -07001933 mutex_lock(&fore200e->rate_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 if (fore200e->available_cell_rate + vcc->qos.txtp.max_pcr < qos->txtp.max_pcr) {
Matthias Kaehlckebfbf3c02007-04-26 01:41:49 -07001935 mutex_unlock(&fore200e->rate_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936 return -EAGAIN;
1937 }
1938
1939 fore200e->available_cell_rate += vcc->qos.txtp.max_pcr;
1940 fore200e->available_cell_rate -= qos->txtp.max_pcr;
1941
Matthias Kaehlckebfbf3c02007-04-26 01:41:49 -07001942 mutex_unlock(&fore200e->rate_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943
1944 memcpy(&vcc->qos, qos, sizeof(struct atm_qos));
1945
1946 /* update rate control parameters */
1947 fore200e_rate_ctrl(qos, &fore200e_vcc->rate);
1948
1949 set_bit(ATM_VF_HASQOS, &vcc->flags);
1950
1951 return 0;
1952 }
1953
1954 return -EINVAL;
1955}
1956
1957
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -08001958static int fore200e_irq_request(struct fore200e *fore200e)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959{
Thomas Gleixnerdace1452006-07-01 19:29:38 -07001960 if (request_irq(fore200e->irq, fore200e_interrupt, IRQF_SHARED, fore200e->name, fore200e->atm_dev) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961
1962 printk(FORE200E "unable to reserve IRQ %s for device %s\n",
1963 fore200e_irq_itoa(fore200e->irq), fore200e->name);
1964 return -EBUSY;
1965 }
1966
1967 printk(FORE200E "IRQ %s reserved for device %s\n",
1968 fore200e_irq_itoa(fore200e->irq), fore200e->name);
1969
1970#ifdef FORE200E_USE_TASKLET
1971 tasklet_init(&fore200e->tx_tasklet, fore200e_tx_tasklet, (unsigned long)fore200e);
1972 tasklet_init(&fore200e->rx_tasklet, fore200e_rx_tasklet, (unsigned long)fore200e);
1973#endif
1974
1975 fore200e->state = FORE200E_STATE_IRQ;
1976 return 0;
1977}
1978
1979
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -08001980static int fore200e_get_esi(struct fore200e *fore200e)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981{
Christoph Hellwig0e21b222018-10-09 16:57:19 +02001982 struct prom_data* prom = kzalloc(sizeof(struct prom_data), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 int ok, i;
1984
1985 if (!prom)
1986 return -ENOMEM;
1987
1988 ok = fore200e->bus->prom_read(fore200e, prom);
1989 if (ok < 0) {
Adrian Bunk1f8a5fb2006-12-19 19:36:32 -08001990 kfree(prom);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 return -EBUSY;
1992 }
1993
hartleys3008ab32010-01-05 06:22:20 +00001994 printk(FORE200E "device %s, rev. %c, S/N: %d, ESI: %pM\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995 fore200e->name,
1996 (prom->hw_revision & 0xFF) + '@', /* probably meaningless with SBA boards */
hartleys3008ab32010-01-05 06:22:20 +00001997 prom->serial_number & 0xFFFF, &prom->mac_addr[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998
1999 for (i = 0; i < ESI_LEN; i++) {
2000 fore200e->esi[ i ] = fore200e->atm_dev->esi[ i ] = prom->mac_addr[ i + 2 ];
2001 }
2002
Adrian Bunk1f8a5fb2006-12-19 19:36:32 -08002003 kfree(prom);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004
2005 return 0;
2006}
2007
2008
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -08002009static int fore200e_alloc_rx_buf(struct fore200e *fore200e)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010{
2011 int scheme, magn, nbr, size, i;
2012
2013 struct host_bsq* bsq;
2014 struct buffer* buffer;
2015
2016 for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
2017 for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
2018
2019 bsq = &fore200e->host_bsq[ scheme ][ magn ];
2020
2021 nbr = fore200e_rx_buf_nbr[ scheme ][ magn ];
2022 size = fore200e_rx_buf_size[ scheme ][ magn ];
2023
2024 DPRINTK(2, "rx buffers %d / %d are being allocated\n", scheme, magn);
2025
2026 /* allocate the array of receive buffers */
Kees Cook6396bb22018-06-12 14:03:40 -07002027 buffer = bsq->buffer = kcalloc(nbr, sizeof(struct buffer),
2028 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029
2030 if (buffer == NULL)
2031 return -ENOMEM;
2032
2033 bsq->freebuf = NULL;
2034
2035 for (i = 0; i < nbr; i++) {
2036
2037 buffer[ i ].scheme = scheme;
2038 buffer[ i ].magn = magn;
2039#ifdef FORE200E_BSQ_DEBUG
2040 buffer[ i ].index = i;
2041 buffer[ i ].supplied = 0;
2042#endif
2043
2044 /* allocate the receive buffer body */
2045 if (fore200e_chunk_alloc(fore200e,
2046 &buffer[ i ].data, size, fore200e->bus->buffer_alignment,
2047 DMA_FROM_DEVICE) < 0) {
2048
2049 while (i > 0)
2050 fore200e_chunk_free(fore200e, &buffer[ --i ].data);
Adrian Bunk1f8a5fb2006-12-19 19:36:32 -08002051 kfree(buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052
2053 return -ENOMEM;
2054 }
2055
2056 /* insert the buffer into the free buffer list */
2057 buffer[ i ].next = bsq->freebuf;
2058 bsq->freebuf = &buffer[ i ];
2059 }
2060 /* all the buffers are free, initially */
2061 bsq->freebuf_count = nbr;
2062
2063#ifdef FORE200E_BSQ_DEBUG
2064 bsq_audit(3, bsq, scheme, magn);
2065#endif
2066 }
2067 }
2068
2069 fore200e->state = FORE200E_STATE_ALLOC_BUF;
2070 return 0;
2071}
2072
2073
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -08002074static int fore200e_init_bs_queue(struct fore200e *fore200e)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075{
2076 int scheme, magn, i;
2077
2078 struct host_bsq* bsq;
2079 struct cp_bsq_entry __iomem * cp_entry;
2080
2081 for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
2082 for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
2083
2084 DPRINTK(2, "buffer supply queue %d / %d is being initialized\n", scheme, magn);
2085
2086 bsq = &fore200e->host_bsq[ scheme ][ magn ];
2087
2088 /* allocate and align the array of status words */
Christoph Hellwig1335d6f2018-10-09 16:57:18 +02002089 if (fore200e_dma_chunk_alloc(fore200e,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 &bsq->status,
2091 sizeof(enum status),
2092 QUEUE_SIZE_BS,
2093 fore200e->bus->status_alignment) < 0) {
2094 return -ENOMEM;
2095 }
2096
2097 /* allocate and align the array of receive buffer descriptors */
Christoph Hellwig1335d6f2018-10-09 16:57:18 +02002098 if (fore200e_dma_chunk_alloc(fore200e,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 &bsq->rbd_block,
2100 sizeof(struct rbd_block),
2101 QUEUE_SIZE_BS,
2102 fore200e->bus->descr_alignment) < 0) {
2103
Christoph Hellwig1335d6f2018-10-09 16:57:18 +02002104 fore200e_dma_chunk_free(fore200e, &bsq->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 return -ENOMEM;
2106 }
2107
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 ]);
2111
2112 /* fill the host resident and cp resident buffer supply queue entries */
2113 for (i = 0; i < QUEUE_SIZE_BS; i++) {
2114
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 ];
2122
2123 *bsq->host_entry[ i ].status = STATUS_FREE;
2124
2125 fore200e->bus->write(FORE200E_DMA_INDEX(bsq->status.dma_addr, enum status, i),
2126 &cp_entry[ i ].status_haddr);
2127 }
2128 }
2129 }
2130
2131 fore200e->state = FORE200E_STATE_INIT_BSQ;
2132 return 0;
2133}
2134
2135
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -08002136static int fore200e_init_rx_queue(struct fore200e *fore200e)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137{
2138 struct host_rxq* rxq = &fore200e->host_rxq;
2139 struct cp_rxq_entry __iomem * cp_entry;
2140 int i;
2141
2142 DPRINTK(2, "receive queue is being initialized\n");
2143
2144 /* allocate and align the array of status words */
Christoph Hellwig1335d6f2018-10-09 16:57:18 +02002145 if (fore200e_dma_chunk_alloc(fore200e,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 &rxq->status,
2147 sizeof(enum status),
2148 QUEUE_SIZE_RX,
2149 fore200e->bus->status_alignment) < 0) {
2150 return -ENOMEM;
2151 }
2152
2153 /* allocate and align the array of receive PDU descriptors */
Christoph Hellwig1335d6f2018-10-09 16:57:18 +02002154 if (fore200e_dma_chunk_alloc(fore200e,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 &rxq->rpd,
2156 sizeof(struct rpd),
2157 QUEUE_SIZE_RX,
2158 fore200e->bus->descr_alignment) < 0) {
2159
Christoph Hellwig1335d6f2018-10-09 16:57:18 +02002160 fore200e_dma_chunk_free(fore200e, &rxq->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 return -ENOMEM;
2162 }
2163
2164 /* get the base address of the cp resident rx queue entries */
2165 cp_entry = fore200e->virt_base + fore200e->bus->read(&fore200e->cp_queues->cp_rxq);
2166
2167 /* fill the host resident and cp resident rx entries */
2168 for (i=0; i < QUEUE_SIZE_RX; i++) {
2169
2170 rxq->host_entry[ i ].status =
2171 FORE200E_INDEX(rxq->status.align_addr, enum status, i);
2172 rxq->host_entry[ i ].rpd =
2173 FORE200E_INDEX(rxq->rpd.align_addr, struct rpd, i);
2174 rxq->host_entry[ i ].rpd_dma =
2175 FORE200E_DMA_INDEX(rxq->rpd.dma_addr, struct rpd, i);
2176 rxq->host_entry[ i ].cp_entry = &cp_entry[ i ];
2177
2178 *rxq->host_entry[ i ].status = STATUS_FREE;
2179
2180 fore200e->bus->write(FORE200E_DMA_INDEX(rxq->status.dma_addr, enum status, i),
2181 &cp_entry[ i ].status_haddr);
2182
2183 fore200e->bus->write(FORE200E_DMA_INDEX(rxq->rpd.dma_addr, struct rpd, i),
2184 &cp_entry[ i ].rpd_haddr);
2185 }
2186
2187 /* set the head entry of the queue */
2188 rxq->head = 0;
2189
2190 fore200e->state = FORE200E_STATE_INIT_RXQ;
2191 return 0;
2192}
2193
2194
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -08002195static int fore200e_init_tx_queue(struct fore200e *fore200e)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196{
2197 struct host_txq* txq = &fore200e->host_txq;
2198 struct cp_txq_entry __iomem * cp_entry;
2199 int i;
2200
2201 DPRINTK(2, "transmit queue is being initialized\n");
2202
2203 /* allocate and align the array of status words */
Christoph Hellwig1335d6f2018-10-09 16:57:18 +02002204 if (fore200e_dma_chunk_alloc(fore200e,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 &txq->status,
2206 sizeof(enum status),
2207 QUEUE_SIZE_TX,
2208 fore200e->bus->status_alignment) < 0) {
2209 return -ENOMEM;
2210 }
2211
2212 /* allocate and align the array of transmit PDU descriptors */
Christoph Hellwig1335d6f2018-10-09 16:57:18 +02002213 if (fore200e_dma_chunk_alloc(fore200e,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 &txq->tpd,
2215 sizeof(struct tpd),
2216 QUEUE_SIZE_TX,
2217 fore200e->bus->descr_alignment) < 0) {
2218
Christoph Hellwig1335d6f2018-10-09 16:57:18 +02002219 fore200e_dma_chunk_free(fore200e, &txq->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 return -ENOMEM;
2221 }
2222
2223 /* get the base address of the cp resident tx queue entries */
2224 cp_entry = fore200e->virt_base + fore200e->bus->read(&fore200e->cp_queues->cp_txq);
2225
2226 /* fill the host resident and cp resident tx entries */
2227 for (i=0; i < QUEUE_SIZE_TX; i++) {
2228
2229 txq->host_entry[ i ].status =
2230 FORE200E_INDEX(txq->status.align_addr, enum status, i);
2231 txq->host_entry[ i ].tpd =
2232 FORE200E_INDEX(txq->tpd.align_addr, struct tpd, i);
2233 txq->host_entry[ i ].tpd_dma =
2234 FORE200E_DMA_INDEX(txq->tpd.dma_addr, struct tpd, i);
2235 txq->host_entry[ i ].cp_entry = &cp_entry[ i ];
2236
2237 *txq->host_entry[ i ].status = STATUS_FREE;
2238
2239 fore200e->bus->write(FORE200E_DMA_INDEX(txq->status.dma_addr, enum status, i),
2240 &cp_entry[ i ].status_haddr);
2241
2242 /* although there is a one-to-one mapping of tx queue entries and tpds,
2243 we do not write here the DMA (physical) base address of each tpd into
2244 the related cp resident entry, because the cp relies on this write
2245 operation to detect that a new pdu has been submitted for tx */
2246 }
2247
2248 /* set the head and tail entries of the queue */
2249 txq->head = 0;
2250 txq->tail = 0;
2251
2252 fore200e->state = FORE200E_STATE_INIT_TXQ;
2253 return 0;
2254}
2255
2256
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -08002257static int fore200e_init_cmd_queue(struct fore200e *fore200e)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258{
2259 struct host_cmdq* cmdq = &fore200e->host_cmdq;
2260 struct cp_cmdq_entry __iomem * cp_entry;
2261 int i;
2262
2263 DPRINTK(2, "command queue is being initialized\n");
2264
2265 /* allocate and align the array of status words */
Christoph Hellwig1335d6f2018-10-09 16:57:18 +02002266 if (fore200e_dma_chunk_alloc(fore200e,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 &cmdq->status,
2268 sizeof(enum status),
2269 QUEUE_SIZE_CMD,
2270 fore200e->bus->status_alignment) < 0) {
2271 return -ENOMEM;
2272 }
2273
2274 /* get the base address of the cp resident cmd queue entries */
2275 cp_entry = fore200e->virt_base + fore200e->bus->read(&fore200e->cp_queues->cp_cmdq);
2276
2277 /* fill the host resident and cp resident cmd entries */
2278 for (i=0; i < QUEUE_SIZE_CMD; i++) {
2279
2280 cmdq->host_entry[ i ].status =
2281 FORE200E_INDEX(cmdq->status.align_addr, enum status, i);
2282 cmdq->host_entry[ i ].cp_entry = &cp_entry[ i ];
2283
2284 *cmdq->host_entry[ i ].status = STATUS_FREE;
2285
2286 fore200e->bus->write(FORE200E_DMA_INDEX(cmdq->status.dma_addr, enum status, i),
2287 &cp_entry[ i ].status_haddr);
2288 }
2289
2290 /* set the head entry of the queue */
2291 cmdq->head = 0;
2292
2293 fore200e->state = FORE200E_STATE_INIT_CMDQ;
2294 return 0;
2295}
2296
2297
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -08002298static void fore200e_param_bs_queue(struct fore200e *fore200e,
2299 enum buffer_scheme scheme,
2300 enum buffer_magn magn, int queue_length,
2301 int pool_size, int supply_blksize)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302{
2303 struct bs_spec __iomem * bs_spec = &fore200e->cp_queues->init.bs_spec[ scheme ][ magn ];
2304
2305 fore200e->bus->write(queue_length, &bs_spec->queue_length);
2306 fore200e->bus->write(fore200e_rx_buf_size[ scheme ][ magn ], &bs_spec->buffer_size);
2307 fore200e->bus->write(pool_size, &bs_spec->pool_size);
2308 fore200e->bus->write(supply_blksize, &bs_spec->supply_blksize);
2309}
2310
2311
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -08002312static int fore200e_initialize(struct fore200e *fore200e)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313{
2314 struct cp_queues __iomem * cpq;
2315 int ok, scheme, magn;
2316
2317 DPRINTK(2, "device %s being initialized\n", fore200e->name);
2318
Matthias Kaehlckebfbf3c02007-04-26 01:41:49 -07002319 mutex_init(&fore200e->rate_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 spin_lock_init(&fore200e->q_lock);
2321
2322 cpq = fore200e->cp_queues = fore200e->virt_base + FORE200E_CP_QUEUES_OFFSET;
2323
2324 /* enable cp to host interrupts */
2325 fore200e->bus->write(1, &cpq->imask);
2326
2327 if (fore200e->bus->irq_enable)
2328 fore200e->bus->irq_enable(fore200e);
2329
2330 fore200e->bus->write(NBR_CONNECT, &cpq->init.num_connect);
2331
2332 fore200e->bus->write(QUEUE_SIZE_CMD, &cpq->init.cmd_queue_len);
2333 fore200e->bus->write(QUEUE_SIZE_RX, &cpq->init.rx_queue_len);
2334 fore200e->bus->write(QUEUE_SIZE_TX, &cpq->init.tx_queue_len);
2335
2336 fore200e->bus->write(RSD_EXTENSION, &cpq->init.rsd_extension);
2337 fore200e->bus->write(TSD_EXTENSION, &cpq->init.tsd_extension);
2338
2339 for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++)
2340 for (magn = 0; magn < BUFFER_MAGN_NBR; magn++)
2341 fore200e_param_bs_queue(fore200e, scheme, magn,
2342 QUEUE_SIZE_BS,
2343 fore200e_rx_buf_nbr[ scheme ][ magn ],
2344 RBD_BLK_SIZE);
2345
2346 /* issue the initialize command */
2347 fore200e->bus->write(STATUS_PENDING, &cpq->init.status);
2348 fore200e->bus->write(OPCODE_INITIALIZE, &cpq->init.opcode);
2349
2350 ok = fore200e_io_poll(fore200e, &cpq->init.status, STATUS_COMPLETE, 3000);
2351 if (ok == 0) {
2352 printk(FORE200E "device %s initialization failed\n", fore200e->name);
2353 return -ENODEV;
2354 }
2355
2356 printk(FORE200E "device %s initialized\n", fore200e->name);
2357
2358 fore200e->state = FORE200E_STATE_INITIALIZE;
2359 return 0;
2360}
2361
2362
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -08002363static void fore200e_monitor_putc(struct fore200e *fore200e, char c)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364{
2365 struct cp_monitor __iomem * monitor = fore200e->cp_monitor;
2366
2367#if 0
2368 printk("%c", c);
2369#endif
2370 fore200e->bus->write(((u32) c) | FORE200E_CP_MONITOR_UART_AVAIL, &monitor->soft_uart.send);
2371}
2372
2373
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -08002374static int fore200e_monitor_getc(struct fore200e *fore200e)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375{
2376 struct cp_monitor __iomem * monitor = fore200e->cp_monitor;
2377 unsigned long timeout = jiffies + msecs_to_jiffies(50);
2378 int c;
2379
2380 while (time_before(jiffies, timeout)) {
2381
2382 c = (int) fore200e->bus->read(&monitor->soft_uart.recv);
2383
2384 if (c & FORE200E_CP_MONITOR_UART_AVAIL) {
2385
2386 fore200e->bus->write(FORE200E_CP_MONITOR_UART_FREE, &monitor->soft_uart.recv);
2387#if 0
2388 printk("%c", c & 0xFF);
2389#endif
2390 return c & 0xFF;
2391 }
2392 }
2393
2394 return -1;
2395}
2396
2397
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -08002398static void fore200e_monitor_puts(struct fore200e *fore200e, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399{
2400 while (*str) {
2401
2402 /* the i960 monitor doesn't accept any new character if it has something to say */
2403 while (fore200e_monitor_getc(fore200e) >= 0);
2404
2405 fore200e_monitor_putc(fore200e, *str++);
2406 }
2407
2408 while (fore200e_monitor_getc(fore200e) >= 0);
2409}
2410
Chas Williamse92481f2008-06-17 16:23:11 -07002411#ifdef __LITTLE_ENDIAN
2412#define FW_EXT ".bin"
2413#else
2414#define FW_EXT "_ecd.bin2"
2415#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -08002417static int fore200e_load_and_start_fw(struct fore200e *fore200e)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418{
Chas Williamse92481f2008-06-17 16:23:11 -07002419 const struct firmware *firmware;
LABBE Corentinb65b24d2016-08-17 15:56:45 +02002420 const struct fw_header *fw_header;
Chas Williams6f75a9b2008-07-23 20:29:21 -07002421 const __le32 *fw_data;
2422 u32 fw_size;
Chas Williamse92481f2008-06-17 16:23:11 -07002423 u32 __iomem *load_addr;
2424 char buf[48];
Christoph Hellwigaff9d262018-10-09 16:57:15 +02002425 int err;
Chas Williamse92481f2008-06-17 16:23:11 -07002426
2427 sprintf(buf, "%s%s", fore200e->bus->proc_name, FW_EXT);
Christoph Hellwigaff9d262018-10-09 16:57:15 +02002428 if ((err = request_firmware(&firmware, buf, fore200e->dev)) < 0) {
Meelis Roosfcffd0d2009-02-10 17:19:19 -08002429 printk(FORE200E "problem loading firmware image %s\n", fore200e->bus->model_name);
Chas Williamse92481f2008-06-17 16:23:11 -07002430 return err;
2431 }
2432
LABBE Corentinb65b24d2016-08-17 15:56:45 +02002433 fw_data = (const __le32 *)firmware->data;
Chas Williamse92481f2008-06-17 16:23:11 -07002434 fw_size = firmware->size / sizeof(u32);
LABBE Corentinb65b24d2016-08-17 15:56:45 +02002435 fw_header = (const struct fw_header *)firmware->data;
Chas Williamse92481f2008-06-17 16:23:11 -07002436 load_addr = fore200e->virt_base + le32_to_cpu(fw_header->load_offset);
2437
2438 DPRINTK(2, "device %s firmware being loaded at 0x%p (%d words)\n",
2439 fore200e->name, load_addr, fw_size);
2440
2441 if (le32_to_cpu(fw_header->magic) != FW_HEADER_MAGIC) {
2442 printk(FORE200E "corrupted %s firmware image\n", fore200e->bus->model_name);
2443 goto release;
2444 }
2445
2446 for (; fw_size--; fw_data++, load_addr++)
2447 fore200e->bus->write(le32_to_cpu(*fw_data), load_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448
2449 DPRINTK(2, "device %s firmware being started\n", fore200e->name);
2450
2451#if defined(__sparc_v9__)
2452 /* reported to be required by SBA cards on some sparc64 hosts */
2453 fore200e_spin(100);
2454#endif
2455
Chas Williamse92481f2008-06-17 16:23:11 -07002456 sprintf(buf, "\rgo %x\r", le32_to_cpu(fw_header->start_offset));
2457 fore200e_monitor_puts(fore200e, buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458
Chas Williamse92481f2008-06-17 16:23:11 -07002459 if (fore200e_io_poll(fore200e, &fore200e->cp_monitor->bstat, BSTAT_CP_RUNNING, 1000) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 printk(FORE200E "device %s firmware didn't start\n", fore200e->name);
Chas Williamse92481f2008-06-17 16:23:11 -07002461 goto release;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 }
2463
2464 printk(FORE200E "device %s firmware started\n", fore200e->name);
2465
2466 fore200e->state = FORE200E_STATE_START_FW;
Chas Williamse92481f2008-06-17 16:23:11 -07002467 err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468
Chas Williamse92481f2008-06-17 16:23:11 -07002469release:
2470 release_firmware(firmware);
2471 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472}
2473
2474
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -08002475static int fore200e_register(struct fore200e *fore200e, struct device *parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476{
2477 struct atm_dev* atm_dev;
2478
2479 DPRINTK(2, "device %s being registered\n", fore200e->name);
2480
Dan Williamsd9ca6762010-12-08 19:40:47 +00002481 atm_dev = atm_dev_register(fore200e->bus->proc_name, parent, &fore200e_ops,
2482 -1, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 if (atm_dev == NULL) {
2484 printk(FORE200E "unable to register device %s\n", fore200e->name);
2485 return -ENODEV;
2486 }
2487
2488 atm_dev->dev_data = fore200e;
2489 fore200e->atm_dev = atm_dev;
2490
2491 atm_dev->ci_range.vpi_bits = FORE200E_VPI_BITS;
2492 atm_dev->ci_range.vci_bits = FORE200E_VCI_BITS;
2493
2494 fore200e->available_cell_rate = ATM_OC3_PCR;
2495
2496 fore200e->state = FORE200E_STATE_REGISTER;
2497 return 0;
2498}
2499
2500
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -08002501static int fore200e_init(struct fore200e *fore200e, struct device *parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502{
Dan Williamsd9ca6762010-12-08 19:40:47 +00002503 if (fore200e_register(fore200e, parent) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 return -ENODEV;
2505
2506 if (fore200e->bus->configure(fore200e) < 0)
2507 return -ENODEV;
2508
2509 if (fore200e->bus->map(fore200e) < 0)
2510 return -ENODEV;
2511
2512 if (fore200e_reset(fore200e, 1) < 0)
2513 return -ENODEV;
2514
Chas Williamse92481f2008-06-17 16:23:11 -07002515 if (fore200e_load_and_start_fw(fore200e) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 return -ENODEV;
2517
2518 if (fore200e_initialize(fore200e) < 0)
2519 return -ENODEV;
2520
2521 if (fore200e_init_cmd_queue(fore200e) < 0)
2522 return -ENOMEM;
2523
2524 if (fore200e_init_tx_queue(fore200e) < 0)
2525 return -ENOMEM;
2526
2527 if (fore200e_init_rx_queue(fore200e) < 0)
2528 return -ENOMEM;
2529
2530 if (fore200e_init_bs_queue(fore200e) < 0)
2531 return -ENOMEM;
2532
2533 if (fore200e_alloc_rx_buf(fore200e) < 0)
2534 return -ENOMEM;
2535
2536 if (fore200e_get_esi(fore200e) < 0)
2537 return -EIO;
2538
2539 if (fore200e_irq_request(fore200e) < 0)
2540 return -EBUSY;
2541
2542 fore200e_supply(fore200e);
Sam Ravnborgc027f5f2006-03-03 17:50:37 -08002543
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 /* all done, board initialization is now complete */
2545 fore200e->state = FORE200E_STATE_COMPLETE;
2546 return 0;
2547}
2548
David S. Miller826b6cf2008-08-27 01:06:07 -07002549#ifdef CONFIG_SBUS
Grant Likelyb1608d62011-05-18 11:19:24 -06002550static const struct of_device_id fore200e_sba_match[];
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -08002551static int fore200e_sba_probe(struct platform_device *op)
David S. Miller826b6cf2008-08-27 01:06:07 -07002552{
Grant Likelyb1608d62011-05-18 11:19:24 -06002553 const struct of_device_id *match;
David S. Miller826b6cf2008-08-27 01:06:07 -07002554 struct fore200e *fore200e;
2555 static int index = 0;
2556 int err;
2557
Grant Likelyb1608d62011-05-18 11:19:24 -06002558 match = of_match_device(fore200e_sba_match, &op->dev);
2559 if (!match)
Grant Likely1c48a5c2011-02-17 02:43:24 -07002560 return -EINVAL;
Grant Likely1c48a5c2011-02-17 02:43:24 -07002561
David S. Miller826b6cf2008-08-27 01:06:07 -07002562 fore200e = kzalloc(sizeof(struct fore200e), GFP_KERNEL);
2563 if (!fore200e)
2564 return -ENOMEM;
2565
Christoph Hellwig0efe5522018-10-09 16:57:14 +02002566 fore200e->bus = &fore200e_sbus_ops;
Christoph Hellwigaff9d262018-10-09 16:57:15 +02002567 fore200e->dev = &op->dev;
Grant Likely1636f8a2010-06-18 11:09:58 -06002568 fore200e->irq = op->archdata.irqs[0];
David S. Miller826b6cf2008-08-27 01:06:07 -07002569 fore200e->phys_base = op->resource[0].start;
2570
Christoph Hellwig0efe5522018-10-09 16:57:14 +02002571 sprintf(fore200e->name, "SBA-200E-%d", index);
David S. Miller826b6cf2008-08-27 01:06:07 -07002572
Dan Williamsd9ca6762010-12-08 19:40:47 +00002573 err = fore200e_init(fore200e, &op->dev);
David S. Miller826b6cf2008-08-27 01:06:07 -07002574 if (err < 0) {
2575 fore200e_shutdown(fore200e);
2576 kfree(fore200e);
2577 return err;
2578 }
2579
2580 index++;
2581 dev_set_drvdata(&op->dev, fore200e);
2582
2583 return 0;
2584}
2585
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -08002586static int fore200e_sba_remove(struct platform_device *op)
David S. Miller826b6cf2008-08-27 01:06:07 -07002587{
2588 struct fore200e *fore200e = dev_get_drvdata(&op->dev);
2589
2590 fore200e_shutdown(fore200e);
2591 kfree(fore200e);
2592
2593 return 0;
2594}
2595
David S. Millerfd098312008-08-31 01:23:17 -07002596static const struct of_device_id fore200e_sba_match[] = {
David S. Miller826b6cf2008-08-27 01:06:07 -07002597 {
2598 .name = SBA200E_PROM_NAME,
David S. Miller826b6cf2008-08-27 01:06:07 -07002599 },
2600 {},
2601};
2602MODULE_DEVICE_TABLE(of, fore200e_sba_match);
2603
Grant Likely1c48a5c2011-02-17 02:43:24 -07002604static struct platform_driver fore200e_sba_driver = {
Grant Likely40182942010-04-13 16:13:02 -07002605 .driver = {
2606 .name = "fore_200e",
Grant Likely40182942010-04-13 16:13:02 -07002607 .of_match_table = fore200e_sba_match,
2608 },
David S. Miller826b6cf2008-08-27 01:06:07 -07002609 .probe = fore200e_sba_probe,
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -08002610 .remove = fore200e_sba_remove,
David S. Miller826b6cf2008-08-27 01:06:07 -07002611};
2612#endif
2613
Chas Williamse92481f2008-06-17 16:23:11 -07002614#ifdef CONFIG_PCI
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -08002615static int fore200e_pca_detect(struct pci_dev *pci_dev,
2616 const struct pci_device_id *pci_ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 struct fore200e* fore200e;
2619 int err = 0;
2620 static int index = 0;
2621
2622 if (pci_enable_device(pci_dev)) {
2623 err = -EINVAL;
2624 goto out;
2625 }
chas williams - CONTRACTORede58ef2015-01-16 08:57:21 -05002626
2627 if (dma_set_mask_and_coherent(&pci_dev->dev, DMA_BIT_MASK(32))) {
2628 err = -EINVAL;
2629 goto out;
2630 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631
Adrian Bunk1f8a5fb2006-12-19 19:36:32 -08002632 fore200e = kzalloc(sizeof(struct fore200e), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 if (fore200e == NULL) {
2634 err = -ENOMEM;
2635 goto out_disable;
2636 }
2637
Christoph Hellwig0efe5522018-10-09 16:57:14 +02002638 fore200e->bus = &fore200e_pci_ops;
Christoph Hellwigaff9d262018-10-09 16:57:15 +02002639 fore200e->dev = &pci_dev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 fore200e->irq = pci_dev->irq;
2641 fore200e->phys_base = pci_resource_start(pci_dev, 0);
2642
Christoph Hellwig0efe5522018-10-09 16:57:14 +02002643 sprintf(fore200e->name, "PCA-200E-%d", index - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644
2645 pci_set_master(pci_dev);
2646
Christoph Hellwig0efe5522018-10-09 16:57:14 +02002647 printk(FORE200E "device PCA-200E found at 0x%lx, IRQ %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648 fore200e->phys_base, fore200e_irq_itoa(fore200e->irq));
2649
Christoph Hellwig0efe5522018-10-09 16:57:14 +02002650 sprintf(fore200e->name, "PCA-200E-%d", index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651
Dan Williamsd9ca6762010-12-08 19:40:47 +00002652 err = fore200e_init(fore200e, &pci_dev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653 if (err < 0) {
2654 fore200e_shutdown(fore200e);
2655 goto out_free;
2656 }
2657
2658 ++index;
2659 pci_set_drvdata(pci_dev, fore200e);
2660
2661out:
2662 return err;
2663
2664out_free:
2665 kfree(fore200e);
2666out_disable:
2667 pci_disable_device(pci_dev);
2668 goto out;
2669}
2670
2671
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -08002672static void fore200e_pca_remove_one(struct pci_dev *pci_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673{
2674 struct fore200e *fore200e;
2675
2676 fore200e = pci_get_drvdata(pci_dev);
2677
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678 fore200e_shutdown(fore200e);
2679 kfree(fore200e);
2680 pci_disable_device(pci_dev);
2681}
2682
2683
Arvind Yadavd5c56652017-07-16 15:02:31 +05302684static const struct pci_device_id fore200e_pca_tbl[] = {
Christoph Hellwig0efe5522018-10-09 16:57:14 +02002685 { PCI_VENDOR_ID_FORE, PCI_DEVICE_ID_FORE_PCA200E, PCI_ANY_ID, PCI_ANY_ID },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 { 0, }
2687};
2688
2689MODULE_DEVICE_TABLE(pci, fore200e_pca_tbl);
2690
2691static struct pci_driver fore200e_pca_driver = {
2692 .name = "fore_200e",
2693 .probe = fore200e_pca_detect,
Greg Kroah-Hartman6c445122012-12-21 13:25:04 -08002694 .remove = fore200e_pca_remove_one,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 .id_table = fore200e_pca_tbl,
2696};
2697#endif
2698
David S. Miller826b6cf2008-08-27 01:06:07 -07002699static int __init fore200e_module_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700{
Rickard Strandqvist74e8ce32014-06-01 01:08:32 +02002701 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702
David S. Miller826b6cf2008-08-27 01:06:07 -07002703 printk(FORE200E "FORE Systems 200E-series ATM driver - version " FORE200E_VERSION "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704
David S. Miller826b6cf2008-08-27 01:06:07 -07002705#ifdef CONFIG_SBUS
Grant Likely1c48a5c2011-02-17 02:43:24 -07002706 err = platform_driver_register(&fore200e_sba_driver);
David S. Miller826b6cf2008-08-27 01:06:07 -07002707 if (err)
2708 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709#endif
2710
Chas Williamse92481f2008-06-17 16:23:11 -07002711#ifdef CONFIG_PCI
David S. Miller826b6cf2008-08-27 01:06:07 -07002712 err = pci_register_driver(&fore200e_pca_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713#endif
2714
David S. Miller826b6cf2008-08-27 01:06:07 -07002715#ifdef CONFIG_SBUS
2716 if (err)
Grant Likely1c48a5c2011-02-17 02:43:24 -07002717 platform_driver_unregister(&fore200e_sba_driver);
David S. Miller826b6cf2008-08-27 01:06:07 -07002718#endif
2719
2720 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721}
2722
David S. Miller826b6cf2008-08-27 01:06:07 -07002723static void __exit fore200e_module_cleanup(void)
2724{
2725#ifdef CONFIG_PCI
2726 pci_unregister_driver(&fore200e_pca_driver);
2727#endif
2728#ifdef CONFIG_SBUS
Grant Likely1c48a5c2011-02-17 02:43:24 -07002729 platform_driver_unregister(&fore200e_sba_driver);
David S. Miller826b6cf2008-08-27 01:06:07 -07002730#endif
2731}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732
2733static int
2734fore200e_proc_read(struct atm_dev *dev, loff_t* pos, char* page)
2735{
2736 struct fore200e* fore200e = FORE200E_DEV(dev);
2737 struct fore200e_vcc* fore200e_vcc;
2738 struct atm_vcc* vcc;
2739 int i, len, left = *pos;
2740 unsigned long flags;
2741
2742 if (!left--) {
2743
2744 if (fore200e_getstats(fore200e) < 0)
2745 return -EIO;
2746
2747 len = sprintf(page,"\n"
2748 " device:\n"
2749 " internal name:\t\t%s\n", fore200e->name);
2750
2751 /* print bus-specific information */
2752 if (fore200e->bus->proc_read)
2753 len += fore200e->bus->proc_read(fore200e, page + len);
2754
2755 len += sprintf(page + len,
2756 " interrupt line:\t\t%s\n"
2757 " physical base address:\t0x%p\n"
2758 " virtual base address:\t0x%p\n"
hartleys3008ab32010-01-05 06:22:20 +00002759 " factory address (ESI):\t%pM\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760 " board serial number:\t\t%d\n\n",
2761 fore200e_irq_itoa(fore200e->irq),
2762 (void*)fore200e->phys_base,
2763 fore200e->virt_base,
hartleys3008ab32010-01-05 06:22:20 +00002764 fore200e->esi,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765 fore200e->esi[4] * 256 + fore200e->esi[5]);
2766
2767 return len;
2768 }
2769
2770 if (!left--)
2771 return sprintf(page,
2772 " free small bufs, scheme 1:\t%d\n"
2773 " free large bufs, scheme 1:\t%d\n"
2774 " free small bufs, scheme 2:\t%d\n"
2775 " free large bufs, scheme 2:\t%d\n",
2776 fore200e->host_bsq[ BUFFER_SCHEME_ONE ][ BUFFER_MAGN_SMALL ].freebuf_count,
2777 fore200e->host_bsq[ BUFFER_SCHEME_ONE ][ BUFFER_MAGN_LARGE ].freebuf_count,
2778 fore200e->host_bsq[ BUFFER_SCHEME_TWO ][ BUFFER_MAGN_SMALL ].freebuf_count,
2779 fore200e->host_bsq[ BUFFER_SCHEME_TWO ][ BUFFER_MAGN_LARGE ].freebuf_count);
2780
2781 if (!left--) {
2782 u32 hb = fore200e->bus->read(&fore200e->cp_queues->heartbeat);
2783
2784 len = sprintf(page,"\n\n"
2785 " cell processor:\n"
2786 " heartbeat state:\t\t");
2787
2788 if (hb >> 16 != 0xDEAD)
2789 len += sprintf(page + len, "0x%08x\n", hb);
2790 else
2791 len += sprintf(page + len, "*** FATAL ERROR %04x ***\n", hb & 0xFFFF);
2792
2793 return len;
2794 }
2795
2796 if (!left--) {
2797 static const char* media_name[] = {
2798 "unshielded twisted pair",
2799 "multimode optical fiber ST",
2800 "multimode optical fiber SC",
2801 "single-mode optical fiber ST",
2802 "single-mode optical fiber SC",
2803 "unknown"
2804 };
2805
2806 static const char* oc3_mode[] = {
2807 "normal operation",
2808 "diagnostic loopback",
2809 "line loopback",
2810 "unknown"
2811 };
2812
2813 u32 fw_release = fore200e->bus->read(&fore200e->cp_queues->fw_release);
2814 u32 mon960_release = fore200e->bus->read(&fore200e->cp_queues->mon960_release);
2815 u32 oc3_revision = fore200e->bus->read(&fore200e->cp_queues->oc3_revision);
2816 u32 media_index = FORE200E_MEDIA_INDEX(fore200e->bus->read(&fore200e->cp_queues->media_type));
2817 u32 oc3_index;
2818
roel kluine0c55672009-10-23 06:09:55 +00002819 if (media_index > 4)
2820 media_index = 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821
2822 switch (fore200e->loop_mode) {
2823 case ATM_LM_NONE: oc3_index = 0;
2824 break;
2825 case ATM_LM_LOC_PHY: oc3_index = 1;
2826 break;
2827 case ATM_LM_RMT_PHY: oc3_index = 2;
2828 break;
2829 default: oc3_index = 3;
2830 }
2831
2832 return sprintf(page,
2833 " firmware release:\t\t%d.%d.%d\n"
2834 " monitor release:\t\t%d.%d\n"
2835 " media type:\t\t\t%s\n"
2836 " OC-3 revision:\t\t0x%x\n"
2837 " OC-3 mode:\t\t\t%s",
2838 fw_release >> 16, fw_release << 16 >> 24, fw_release << 24 >> 24,
2839 mon960_release >> 16, mon960_release << 16 >> 16,
2840 media_name[ media_index ],
2841 oc3_revision,
2842 oc3_mode[ oc3_index ]);
2843 }
2844
2845 if (!left--) {
2846 struct cp_monitor __iomem * cp_monitor = fore200e->cp_monitor;
2847
2848 return sprintf(page,
2849 "\n\n"
2850 " monitor:\n"
2851 " version number:\t\t%d\n"
2852 " boot status word:\t\t0x%08x\n",
2853 fore200e->bus->read(&cp_monitor->mon_version),
2854 fore200e->bus->read(&cp_monitor->bstat));
2855 }
2856
2857 if (!left--)
2858 return sprintf(page,
2859 "\n"
2860 " device statistics:\n"
2861 " 4b5b:\n"
2862 " crc_header_errors:\t\t%10u\n"
2863 " framing_errors:\t\t%10u\n",
Al Viro63734a32008-03-16 22:23:04 +00002864 be32_to_cpu(fore200e->stats->phy.crc_header_errors),
2865 be32_to_cpu(fore200e->stats->phy.framing_errors));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866
2867 if (!left--)
2868 return sprintf(page, "\n"
2869 " OC-3:\n"
2870 " section_bip8_errors:\t%10u\n"
2871 " path_bip8_errors:\t\t%10u\n"
2872 " line_bip24_errors:\t\t%10u\n"
2873 " line_febe_errors:\t\t%10u\n"
2874 " path_febe_errors:\t\t%10u\n"
2875 " corr_hcs_errors:\t\t%10u\n"
2876 " ucorr_hcs_errors:\t\t%10u\n",
Al Viro63734a32008-03-16 22:23:04 +00002877 be32_to_cpu(fore200e->stats->oc3.section_bip8_errors),
2878 be32_to_cpu(fore200e->stats->oc3.path_bip8_errors),
2879 be32_to_cpu(fore200e->stats->oc3.line_bip24_errors),
2880 be32_to_cpu(fore200e->stats->oc3.line_febe_errors),
2881 be32_to_cpu(fore200e->stats->oc3.path_febe_errors),
2882 be32_to_cpu(fore200e->stats->oc3.corr_hcs_errors),
2883 be32_to_cpu(fore200e->stats->oc3.ucorr_hcs_errors));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884
2885 if (!left--)
2886 return sprintf(page,"\n"
2887 " ATM:\t\t\t\t cells\n"
2888 " TX:\t\t\t%10u\n"
2889 " RX:\t\t\t%10u\n"
2890 " vpi out of range:\t\t%10u\n"
2891 " vpi no conn:\t\t%10u\n"
2892 " vci out of range:\t\t%10u\n"
2893 " vci no conn:\t\t%10u\n",
Al Viro63734a32008-03-16 22:23:04 +00002894 be32_to_cpu(fore200e->stats->atm.cells_transmitted),
2895 be32_to_cpu(fore200e->stats->atm.cells_received),
2896 be32_to_cpu(fore200e->stats->atm.vpi_bad_range),
2897 be32_to_cpu(fore200e->stats->atm.vpi_no_conn),
2898 be32_to_cpu(fore200e->stats->atm.vci_bad_range),
2899 be32_to_cpu(fore200e->stats->atm.vci_no_conn));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900
2901 if (!left--)
2902 return sprintf(page,"\n"
2903 " AAL0:\t\t\t cells\n"
2904 " TX:\t\t\t%10u\n"
2905 " RX:\t\t\t%10u\n"
2906 " dropped:\t\t\t%10u\n",
Al Viro63734a32008-03-16 22:23:04 +00002907 be32_to_cpu(fore200e->stats->aal0.cells_transmitted),
2908 be32_to_cpu(fore200e->stats->aal0.cells_received),
2909 be32_to_cpu(fore200e->stats->aal0.cells_dropped));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910
2911 if (!left--)
2912 return sprintf(page,"\n"
2913 " AAL3/4:\n"
2914 " SAR sublayer:\t\t cells\n"
2915 " TX:\t\t\t%10u\n"
2916 " RX:\t\t\t%10u\n"
2917 " dropped:\t\t\t%10u\n"
2918 " CRC errors:\t\t%10u\n"
2919 " protocol errors:\t\t%10u\n\n"
2920 " CS sublayer:\t\t PDUs\n"
2921 " TX:\t\t\t%10u\n"
2922 " RX:\t\t\t%10u\n"
2923 " dropped:\t\t\t%10u\n"
2924 " protocol errors:\t\t%10u\n",
Al Viro63734a32008-03-16 22:23:04 +00002925 be32_to_cpu(fore200e->stats->aal34.cells_transmitted),
2926 be32_to_cpu(fore200e->stats->aal34.cells_received),
2927 be32_to_cpu(fore200e->stats->aal34.cells_dropped),
2928 be32_to_cpu(fore200e->stats->aal34.cells_crc_errors),
2929 be32_to_cpu(fore200e->stats->aal34.cells_protocol_errors),
2930 be32_to_cpu(fore200e->stats->aal34.cspdus_transmitted),
2931 be32_to_cpu(fore200e->stats->aal34.cspdus_received),
2932 be32_to_cpu(fore200e->stats->aal34.cspdus_dropped),
2933 be32_to_cpu(fore200e->stats->aal34.cspdus_protocol_errors));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934
2935 if (!left--)
2936 return sprintf(page,"\n"
2937 " AAL5:\n"
2938 " SAR sublayer:\t\t cells\n"
2939 " TX:\t\t\t%10u\n"
2940 " RX:\t\t\t%10u\n"
2941 " dropped:\t\t\t%10u\n"
2942 " congestions:\t\t%10u\n\n"
2943 " CS sublayer:\t\t PDUs\n"
2944 " TX:\t\t\t%10u\n"
2945 " RX:\t\t\t%10u\n"
2946 " dropped:\t\t\t%10u\n"
2947 " CRC errors:\t\t%10u\n"
2948 " protocol errors:\t\t%10u\n",
Al Viro63734a32008-03-16 22:23:04 +00002949 be32_to_cpu(fore200e->stats->aal5.cells_transmitted),
2950 be32_to_cpu(fore200e->stats->aal5.cells_received),
2951 be32_to_cpu(fore200e->stats->aal5.cells_dropped),
2952 be32_to_cpu(fore200e->stats->aal5.congestion_experienced),
2953 be32_to_cpu(fore200e->stats->aal5.cspdus_transmitted),
2954 be32_to_cpu(fore200e->stats->aal5.cspdus_received),
2955 be32_to_cpu(fore200e->stats->aal5.cspdus_dropped),
2956 be32_to_cpu(fore200e->stats->aal5.cspdus_crc_errors),
2957 be32_to_cpu(fore200e->stats->aal5.cspdus_protocol_errors));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958
2959 if (!left--)
2960 return sprintf(page,"\n"
2961 " AUX:\t\t allocation failures\n"
2962 " small b1:\t\t\t%10u\n"
2963 " large b1:\t\t\t%10u\n"
2964 " small b2:\t\t\t%10u\n"
2965 " large b2:\t\t\t%10u\n"
2966 " RX PDUs:\t\t\t%10u\n"
2967 " TX PDUs:\t\t\t%10lu\n",
Al Viro63734a32008-03-16 22:23:04 +00002968 be32_to_cpu(fore200e->stats->aux.small_b1_failed),
2969 be32_to_cpu(fore200e->stats->aux.large_b1_failed),
2970 be32_to_cpu(fore200e->stats->aux.small_b2_failed),
2971 be32_to_cpu(fore200e->stats->aux.large_b2_failed),
2972 be32_to_cpu(fore200e->stats->aux.rpd_alloc_failed),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 fore200e->tx_sat);
2974
2975 if (!left--)
2976 return sprintf(page,"\n"
2977 " receive carrier:\t\t\t%s\n",
2978 fore200e->stats->aux.receive_carrier ? "ON" : "OFF!");
2979
2980 if (!left--) {
2981 return sprintf(page,"\n"
2982 " VCCs:\n address VPI VCI AAL "
2983 "TX PDUs TX min/max size RX PDUs RX min/max size\n");
2984 }
2985
2986 for (i = 0; i < NBR_CONNECT; i++) {
2987
2988 vcc = fore200e->vc_map[i].vcc;
2989
2990 if (vcc == NULL)
2991 continue;
2992
2993 spin_lock_irqsave(&fore200e->q_lock, flags);
2994
2995 if (vcc && test_bit(ATM_VF_READY, &vcc->flags) && !left--) {
2996
2997 fore200e_vcc = FORE200E_VCC(vcc);
2998 ASSERT(fore200e_vcc);
2999
3000 len = sprintf(page,
Colin Ian King22dac9f2017-11-27 13:24:15 +00003001 " %pK %03d %05d %1d %09lu %05d/%05d %09lu %05d/%05d\n",
3002 vcc,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal),
3004 fore200e_vcc->tx_pdu,
3005 fore200e_vcc->tx_min_pdu > 0xFFFF ? 0 : fore200e_vcc->tx_min_pdu,
3006 fore200e_vcc->tx_max_pdu,
3007 fore200e_vcc->rx_pdu,
3008 fore200e_vcc->rx_min_pdu > 0xFFFF ? 0 : fore200e_vcc->rx_min_pdu,
3009 fore200e_vcc->rx_max_pdu);
3010
3011 spin_unlock_irqrestore(&fore200e->q_lock, flags);
3012 return len;
3013 }
3014
3015 spin_unlock_irqrestore(&fore200e->q_lock, flags);
3016 }
3017
3018 return 0;
3019}
3020
3021module_init(fore200e_module_init);
3022module_exit(fore200e_module_cleanup);
3023
3024
Christoph Hellwig0efe5522018-10-09 16:57:14 +02003025static const struct atmdev_ops fore200e_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 .open = fore200e_open,
3027 .close = fore200e_close,
3028 .ioctl = fore200e_ioctl,
3029 .getsockopt = fore200e_getsockopt,
3030 .setsockopt = fore200e_setsockopt,
3031 .send = fore200e_send,
3032 .change_qos = fore200e_change_qos,
3033 .proc_read = fore200e_proc_read,
3034 .owner = THIS_MODULE
3035};
3036
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037MODULE_LICENSE("GPL");
Chas Williams6f75a9b2008-07-23 20:29:21 -07003038#ifdef CONFIG_PCI
3039#ifdef __LITTLE_ENDIAN__
3040MODULE_FIRMWARE("pca200e.bin");
3041#else
3042MODULE_FIRMWARE("pca200e_ecd.bin2");
3043#endif
3044#endif /* CONFIG_PCI */
3045#ifdef CONFIG_SBUS
3046MODULE_FIRMWARE("sba200e_ecd.bin2");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047#endif