Blame view

drivers/atm/fore200e.c 83.7 KB
1a59d1b8e   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-or-later
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3
4
5
6
7
8
9
    A FORE Systems 200E-series driver for ATM on Linux.
    Christophe Lizzi (lizzi@cnam.fr), October 1999-March 2003.
  
    Based on the PCA-200E driver from Uwe Dannowski (Uwe.Dannowski@inf.tu-dresden.de).
  
    This driver simultaneously supports PCA-200E and SBA-200E adapters
    on i386, alpha (untested), powerpc, sparc and sparc64 architectures.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
10
  */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
11
12
13
14
  #include <linux/kernel.h>
  #include <linux/slab.h>
  #include <linux/init.h>
  #include <linux/capability.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
15
16
17
18
19
20
21
22
23
  #include <linux/interrupt.h>
  #include <linux/bitops.h>
  #include <linux/pci.h>
  #include <linux/module.h>
  #include <linux/atmdev.h>
  #include <linux/sonet.h>
  #include <linux/atm_suni.h>
  #include <linux/dma-mapping.h>
  #include <linux/delay.h>
e92481f95   Chas Williams   atm: [fore200e] c...
24
  #include <linux/firmware.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
25
26
27
28
29
30
  #include <asm/io.h>
  #include <asm/string.h>
  #include <asm/page.h>
  #include <asm/irq.h>
  #include <asm/dma.h>
  #include <asm/byteorder.h>
7c0f6ba68   Linus Torvalds   Replace <asm/uacc...
31
  #include <linux/uaccess.h>
60063497a   Arun Sharma   atomic: use <linu...
32
  #include <linux/atomic.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
33

e92481f95   Chas Williams   atm: [fore200e] c...
34
  #ifdef CONFIG_SBUS
826b6cfcd   David S. Miller   fore200e: Convert...
35
36
  #include <linux/of.h>
  #include <linux/of_device.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
37
  #include <asm/idprom.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
  #include <asm/openprom.h>
  #include <asm/oplib.h>
  #include <asm/pgtable.h>
  #endif
  
  #if defined(CONFIG_ATM_FORE200E_USE_TASKLET) /* defer interrupt work to a tasklet */
  #define FORE200E_USE_TASKLET
  #endif
  
  #if 0 /* enable the debugging code of the buffer supply queues */
  #define FORE200E_BSQ_DEBUG
  #endif
  
  #if 1 /* ensure correct handling of 52-byte AAL0 SDUs expected by atmdump-like apps */
  #define FORE200E_52BYTE_AAL0_SDU
  #endif
  
  #include "fore200e.h"
  #include "suni.h"
  
  #define FORE200E_VERSION "0.3e"
  
  #define FORE200E         "fore200e: "
  
  #if 0 /* override .config */
  #define CONFIG_ATM_FORE200E_DEBUG 1
  #endif
  #if defined(CONFIG_ATM_FORE200E_DEBUG) && (CONFIG_ATM_FORE200E_DEBUG > 0)
  #define DPRINTK(level, format, args...)  do { if (CONFIG_ATM_FORE200E_DEBUG >= (level)) \
                                                    printk(FORE200E format, ##args); } while (0)
  #else
  #define DPRINTK(level, format, args...)  do {} while (0)
  #endif
  
  
  #define FORE200E_ALIGN(addr, alignment) \
          ((((unsigned long)(addr) + (alignment - 1)) & ~(alignment - 1)) - (unsigned long)(addr))
  
  #define FORE200E_DMA_INDEX(dma_addr, type, index)  ((dma_addr) + (index) * sizeof(type))
  
  #define FORE200E_INDEX(virt_addr, type, index)     (&((type *)(virt_addr))[ index ])
30dfe2c05   David S. Miller   atm: fore200e: Fi...
79
  #define FORE200E_NEXT_ENTRY(index, modulo)         (index = ((index) + 1) % (modulo))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
80
81
82
83
84
  
  #if 1
  #define ASSERT(expr)     if (!(expr)) { \
  			     printk(FORE200E "assertion failed! %s[%d]: %s
  ", \
5a346a10c   Harvey Harrison   atm: replace rema...
85
86
  				    __func__, __LINE__, #expr); \
  			     panic(FORE200E "%s", __func__); \
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
87
88
89
90
91
92
93
  			 }
  #else
  #define ASSERT(expr)     do {} while (0)
  #endif
  
  
  static const struct atmdev_ops   fore200e_ops;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
  
  static LIST_HEAD(fore200e_boards);
  
  
  MODULE_AUTHOR("Christophe Lizzi - credits to Uwe Dannowski and Heikki Vatiainen");
  MODULE_DESCRIPTION("FORE Systems 200E-series ATM driver - version " FORE200E_VERSION);
  MODULE_SUPPORTED_DEVICE("PCA-200E, SBA-200E");
  
  
  static const int fore200e_rx_buf_nbr[ BUFFER_SCHEME_NBR ][ BUFFER_MAGN_NBR ] = {
      { BUFFER_S1_NBR, BUFFER_L1_NBR },
      { BUFFER_S2_NBR, BUFFER_L2_NBR }
  };
  
  static const int fore200e_rx_buf_size[ BUFFER_SCHEME_NBR ][ BUFFER_MAGN_NBR ] = {
      { BUFFER_S1_SIZE, BUFFER_L1_SIZE },
      { BUFFER_S2_SIZE, BUFFER_L2_SIZE }
  };
  
  
  #if defined(CONFIG_ATM_FORE200E_DEBUG) && (CONFIG_ATM_FORE200E_DEBUG > 0)
  static const char* fore200e_traffic_class[] = { "NONE", "UBR", "CBR", "VBR", "ABR", "ANY" };
  #endif
  
  
  #if 0 /* currently unused */
  static int 
  fore200e_fore2atm_aal(enum fore200e_aal aal)
  {
      switch(aal) {
      case FORE200E_AAL0:  return ATM_AAL0;
      case FORE200E_AAL34: return ATM_AAL34;
      case FORE200E_AAL5:  return ATM_AAL5;
      }
  
      return -EINVAL;
  }
  #endif
  
  
  static enum fore200e_aal
  fore200e_atm2fore_aal(int aal)
  {
      switch(aal) {
      case ATM_AAL0:  return FORE200E_AAL0;
      case ATM_AAL34: return FORE200E_AAL34;
      case ATM_AAL1:
      case ATM_AAL2:
      case ATM_AAL5:  return FORE200E_AAL5;
      }
  
      return -EINVAL;
  }
  
  
  static char*
  fore200e_irq_itoa(int irq)
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
152
153
154
      static char str[8];
      sprintf(str, "%d", irq);
      return str;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
155
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
156
157
158
159
160
161
162
163
164
165
166
167
  /* allocate and align a chunk of memory intended to hold the data behing exchanged
     between the driver and the adapter (using streaming DVMA) */
  
  static int
  fore200e_chunk_alloc(struct fore200e* fore200e, struct chunk* chunk, int size, int alignment, int direction)
  {
      unsigned long offset = 0;
  
      if (alignment <= sizeof(int))
  	alignment = 0;
  
      chunk->alloc_size = size + alignment;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
168
      chunk->direction  = direction;
0e21b2258   Christoph Hellwig   fore200e: don't u...
169
      chunk->alloc_addr = kzalloc(chunk->alloc_size, GFP_KERNEL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
170
171
172
173
174
175
176
      if (chunk->alloc_addr == NULL)
  	return -ENOMEM;
  
      if (alignment > 0)
  	offset = FORE200E_ALIGN(chunk->alloc_addr, alignment); 
      
      chunk->align_addr = chunk->alloc_addr + offset;
f3fadcb56   Christoph Hellwig   fore200e: devirtu...
177
178
      chunk->dma_addr = dma_map_single(fore200e->dev, chunk->align_addr,
  				     size, direction);
1d9d8be91   Christoph Hellwig   fore200e: check f...
179
180
181
182
      if (dma_mapping_error(fore200e->dev, chunk->dma_addr)) {
  	kfree(chunk->alloc_addr);
  	return -ENOMEM;
      }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
183
184
185
186
187
188
189
190
191
      return 0;
  }
  
  
  /* free a chunk of memory */
  
  static void
  fore200e_chunk_free(struct fore200e* fore200e, struct chunk* chunk)
  {
f3fadcb56   Christoph Hellwig   fore200e: devirtu...
192
193
      dma_unmap_single(fore200e->dev, chunk->dma_addr, chunk->dma_size,
  		     chunk->direction);
1f8a5fb80   Adrian Bunk   [ATM] drivers/atm...
194
      kfree(chunk->alloc_addr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
195
  }
1335d6fd6   Christoph Hellwig   fore200e: devirtu...
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
  /*
   * Allocate a DMA consistent chunk of memory intended to act as a communication
   * mechanism (to hold descriptors, status, queues, etc.) shared by the driver
   * and the adapter.
   */
  static int
  fore200e_dma_chunk_alloc(struct fore200e *fore200e, struct chunk *chunk,
  		int size, int nbr, int alignment)
  {
  	/* returned chunks are page-aligned */
  	chunk->alloc_size = size * nbr;
  	chunk->alloc_addr = dma_alloc_coherent(fore200e->dev, chunk->alloc_size,
  					       &chunk->dma_addr, GFP_KERNEL);
  	if (!chunk->alloc_addr)
  		return -ENOMEM;
  	chunk->align_addr = chunk->alloc_addr;
  	return 0;
  }
  
  /*
   * Free a DMA consistent chunk of memory.
   */
  static void
  fore200e_dma_chunk_free(struct fore200e* fore200e, struct chunk* chunk)
  {
  	dma_free_coherent(fore200e->dev, chunk->alloc_size, chunk->alloc_addr,
  			  chunk->dma_addr);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
  
  static void
  fore200e_spin(int msecs)
  {
      unsigned long timeout = jiffies + msecs_to_jiffies(msecs);
      while (time_before(jiffies, timeout));
  }
  
  
  static int
  fore200e_poll(struct fore200e* fore200e, volatile u32* addr, u32 val, int msecs)
  {
      unsigned long timeout = jiffies + msecs_to_jiffies(msecs);
      int           ok;
  
      mb();
      do {
  	if ((ok = (*addr == val)) || (*addr & STATUS_ERROR))
  	    break;
  
      } while (time_before(jiffies, timeout));
  
  #if 1
      if (!ok) {
  	printk(FORE200E "cmd polling failed, got status 0x%08x, expected 0x%08x
  ",
  	       *addr, val);
      }
  #endif
  
      return ok;
  }
  
  
  static int
  fore200e_io_poll(struct fore200e* fore200e, volatile u32 __iomem *addr, u32 val, int msecs)
  {
      unsigned long timeout = jiffies + msecs_to_jiffies(msecs);
      int           ok;
  
      do {
  	if ((ok = (fore200e->bus->read(addr) == val)))
  	    break;
  
      } while (time_before(jiffies, timeout));
  
  #if 1
      if (!ok) {
  	printk(FORE200E "I/O polling failed, got status 0x%08x, expected 0x%08x
  ",
  	       fore200e->bus->read(addr), val);
      }
  #endif
  
      return ok;
  }
  
  
  static void
  fore200e_free_rx_buf(struct fore200e* fore200e)
  {
      int scheme, magn, nbr;
      struct buffer* buffer;
  
      for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
  	for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
  
  	    if ((buffer = fore200e->host_bsq[ scheme ][ magn ].buffer) != NULL) {
  
  		for (nbr = 0; nbr < fore200e_rx_buf_nbr[ scheme ][ magn ]; nbr++) {
  
  		    struct chunk* data = &buffer[ nbr ].data;
  
  		    if (data->alloc_addr != NULL)
  			fore200e_chunk_free(fore200e, data);
  		}
  	    }
  	}
      }
  }
  
  
  static void
  fore200e_uninit_bs_queue(struct fore200e* fore200e)
  {
      int scheme, magn;
      
      for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
  	for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
  
  	    struct chunk* status    = &fore200e->host_bsq[ scheme ][ magn ].status;
  	    struct chunk* rbd_block = &fore200e->host_bsq[ scheme ][ magn ].rbd_block;
  	    
  	    if (status->alloc_addr)
1335d6fd6   Christoph Hellwig   fore200e: devirtu...
318
  		fore200e_dma_chunk_free(fore200e, status);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
319
320
  	    
  	    if (rbd_block->alloc_addr)
1335d6fd6   Christoph Hellwig   fore200e: devirtu...
321
  		fore200e_dma_chunk_free(fore200e, rbd_block);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
  	}
      }
  }
  
  
  static int
  fore200e_reset(struct fore200e* fore200e, int diag)
  {
      int ok;
  
      fore200e->cp_monitor = fore200e->virt_base + FORE200E_CP_MONITOR_OFFSET;
      
      fore200e->bus->write(BSTAT_COLD_START, &fore200e->cp_monitor->bstat);
  
      fore200e->bus->reset(fore200e);
  
      if (diag) {
  	ok = fore200e_io_poll(fore200e, &fore200e->cp_monitor->bstat, BSTAT_SELFTEST_OK, 1000);
  	if (ok == 0) {
  	    
  	    printk(FORE200E "device %s self-test failed
  ", fore200e->name);
  	    return -ENODEV;
  	}
  
  	printk(FORE200E "device %s self-test passed
  ", fore200e->name);
  	
  	fore200e->state = FORE200E_STATE_RESET;
      }
  
      return 0;
  }
  
  
  static void
  fore200e_shutdown(struct fore200e* fore200e)
  {
      printk(FORE200E "removing device %s at 0x%lx, IRQ %s
  ",
  	   fore200e->name, fore200e->phys_base, 
  	   fore200e_irq_itoa(fore200e->irq));
      
      if (fore200e->state > FORE200E_STATE_RESET) {
  	/* first, reset the board to prevent further interrupts or data transfers */
  	fore200e_reset(fore200e, 0);
      }
      
      /* then, release all allocated resources */
      switch(fore200e->state) {
  
      case FORE200E_STATE_COMPLETE:
a2c1aa547   Jesper Juhl   [ATM]: [drivers] ...
374
  	kfree(fore200e->stats);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
375

ec0d0987f   Gustavo A. R. Silva   atm: fore200e: ma...
376
  	/* fall through */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
377
378
      case FORE200E_STATE_IRQ:
  	free_irq(fore200e->irq, fore200e->atm_dev);
ec0d0987f   Gustavo A. R. Silva   atm: fore200e: ma...
379
  	/* fall through */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
380
381
      case FORE200E_STATE_ALLOC_BUF:
  	fore200e_free_rx_buf(fore200e);
ec0d0987f   Gustavo A. R. Silva   atm: fore200e: ma...
382
  	/* fall through */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
383
384
      case FORE200E_STATE_INIT_BSQ:
  	fore200e_uninit_bs_queue(fore200e);
ec0d0987f   Gustavo A. R. Silva   atm: fore200e: ma...
385
  	/* fall through */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
386
      case FORE200E_STATE_INIT_RXQ:
1335d6fd6   Christoph Hellwig   fore200e: devirtu...
387
388
  	fore200e_dma_chunk_free(fore200e, &fore200e->host_rxq.status);
  	fore200e_dma_chunk_free(fore200e, &fore200e->host_rxq.rpd);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
389

ec0d0987f   Gustavo A. R. Silva   atm: fore200e: ma...
390
  	/* fall through */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
391
      case FORE200E_STATE_INIT_TXQ:
1335d6fd6   Christoph Hellwig   fore200e: devirtu...
392
393
  	fore200e_dma_chunk_free(fore200e, &fore200e->host_txq.status);
  	fore200e_dma_chunk_free(fore200e, &fore200e->host_txq.tpd);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
394

ec0d0987f   Gustavo A. R. Silva   atm: fore200e: ma...
395
  	/* fall through */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
396
      case FORE200E_STATE_INIT_CMDQ:
1335d6fd6   Christoph Hellwig   fore200e: devirtu...
397
  	fore200e_dma_chunk_free(fore200e, &fore200e->host_cmdq.status);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
398

ec0d0987f   Gustavo A. R. Silva   atm: fore200e: ma...
399
  	/* fall through */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
400
401
402
403
404
      case FORE200E_STATE_INITIALIZE:
  	/* nothing to do for that state */
  
      case FORE200E_STATE_START_FW:
  	/* nothing to do for that state */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
405
406
407
408
409
      case FORE200E_STATE_RESET:
  	/* nothing to do for that state */
  
      case FORE200E_STATE_MAP:
  	fore200e->bus->unmap(fore200e);
ec0d0987f   Gustavo A. R. Silva   atm: fore200e: ma...
410
  	/* fall through */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
411
412
413
414
415
416
417
418
419
420
421
422
      case FORE200E_STATE_CONFIGURE:
  	/* nothing to do for that state */
  
      case FORE200E_STATE_REGISTER:
  	/* XXX shouldn't we *start* by deregistering the device? */
  	atm_dev_deregister(fore200e->atm_dev);
  
      case FORE200E_STATE_BLANK:
  	/* nothing to do for that state */
  	break;
      }
  }
e92481f95   Chas Williams   atm: [fore200e] c...
423
  #ifdef CONFIG_PCI
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
  
  static u32 fore200e_pca_read(volatile u32 __iomem *addr)
  {
      /* on big-endian hosts, the board is configured to convert
         the endianess of slave RAM accesses  */
      return le32_to_cpu(readl(addr));
  }
  
  
  static void fore200e_pca_write(u32 val, volatile u32 __iomem *addr)
  {
      /* on big-endian hosts, the board is configured to convert
         the endianess of slave RAM accesses  */
      writel(cpu_to_le32(val), addr);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
  static int
  fore200e_pca_irq_check(struct fore200e* fore200e)
  {
      /* this is a 1 bit register */
      int irq_posted = readl(fore200e->regs.pca.psr);
  
  #if defined(CONFIG_ATM_FORE200E_DEBUG) && (CONFIG_ATM_FORE200E_DEBUG == 2)
      if (irq_posted && (readl(fore200e->regs.pca.hcr) & PCA200E_HCR_OUTFULL)) {
  	DPRINTK(2,"FIFO OUT full, device %d
  ", fore200e->atm_dev->number);
      }
  #endif
  
      return irq_posted;
  }
  
  
  static void
  fore200e_pca_irq_ack(struct fore200e* fore200e)
  {
      writel(PCA200E_HCR_CLRINTR, fore200e->regs.pca.hcr);
  }
  
  
  static void
  fore200e_pca_reset(struct fore200e* fore200e)
  {
      writel(PCA200E_HCR_RESET, fore200e->regs.pca.hcr);
      fore200e_spin(10);
      writel(0, fore200e->regs.pca.hcr);
  }
6c44512d0   Greg Kroah-Hartman   Drivers: atm: rem...
470
  static int fore200e_pca_map(struct fore200e* fore200e)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
  {
      DPRINTK(2, "device %s being mapped in memory
  ", fore200e->name);
  
      fore200e->virt_base = ioremap(fore200e->phys_base, PCA200E_IOSPACE_LENGTH);
      
      if (fore200e->virt_base == NULL) {
  	printk(FORE200E "can't map device %s
  ", fore200e->name);
  	return -EFAULT;
      }
  
      DPRINTK(1, "device %s mapped to 0x%p
  ", fore200e->name, fore200e->virt_base);
  
      /* gain access to the PCA specific registers  */
      fore200e->regs.pca.hcr = fore200e->virt_base + PCA200E_HCR_OFFSET;
      fore200e->regs.pca.imr = fore200e->virt_base + PCA200E_IMR_OFFSET;
      fore200e->regs.pca.psr = fore200e->virt_base + PCA200E_PSR_OFFSET;
  
      fore200e->state = FORE200E_STATE_MAP;
      return 0;
  }
  
  
  static void
  fore200e_pca_unmap(struct fore200e* fore200e)
  {
      DPRINTK(2, "device %s being unmapped from memory
  ", fore200e->name);
  
      if (fore200e->virt_base != NULL)
  	iounmap(fore200e->virt_base);
  }
6c44512d0   Greg Kroah-Hartman   Drivers: atm: rem...
505
  static int fore200e_pca_configure(struct fore200e *fore200e)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
506
  {
aff9d262f   Christoph Hellwig   fore200e: store a...
507
      struct pci_dev *pci_dev = to_pci_dev(fore200e->dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
      u8              master_ctrl, latency;
  
      DPRINTK(2, "device %s being configured
  ", fore200e->name);
  
      if ((pci_dev->irq == 0) || (pci_dev->irq == 0xFF)) {
  	printk(FORE200E "incorrect IRQ setting - misconfigured PCI-PCI bridge?
  ");
  	return -EIO;
      }
  
      pci_read_config_byte(pci_dev, PCA200E_PCI_MASTER_CTRL, &master_ctrl);
  
      master_ctrl = master_ctrl
  #if defined(__BIG_ENDIAN)
  	/* request the PCA board to convert the endianess of slave RAM accesses */
  	| PCA200E_CTRL_CONVERT_ENDIAN
  #endif
  #if 0
          | PCA200E_CTRL_DIS_CACHE_RD
          | PCA200E_CTRL_DIS_WRT_INVAL
          | PCA200E_CTRL_ENA_CONT_REQ_MODE
          | PCA200E_CTRL_2_CACHE_WRT_INVAL
  #endif
  	| PCA200E_CTRL_LARGE_PCI_BURSTS;
      
      pci_write_config_byte(pci_dev, PCA200E_PCI_MASTER_CTRL, master_ctrl);
  
      /* raise latency from 32 (default) to 192, as this seems to prevent NIC
         lockups (under heavy rx loads) due to continuous 'FIFO OUT full' condition.
         this may impact the performances of other PCI devices on the same bus, though */
      latency = 192;
      pci_write_config_byte(pci_dev, PCI_LATENCY_TIMER, latency);
  
      fore200e->state = FORE200E_STATE_CONFIGURE;
      return 0;
  }
  
  
  static int __init
  fore200e_pca_prom_read(struct fore200e* fore200e, struct prom_data* prom)
  {
      struct host_cmdq*       cmdq  = &fore200e->host_cmdq;
      struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
      struct prom_opcode      opcode;
      int                     ok;
      u32                     prom_dma;
  
      FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
  
      opcode.opcode = OPCODE_GET_PROM;
      opcode.pad    = 0;
f3fadcb56   Christoph Hellwig   fore200e: devirtu...
560
561
      prom_dma = dma_map_single(fore200e->dev, prom, sizeof(struct prom_data),
  			      DMA_FROM_DEVICE);
1d9d8be91   Christoph Hellwig   fore200e: check f...
562
563
      if (dma_mapping_error(fore200e->dev, prom_dma))
  	return -ENOMEM;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
564
565
566
567
568
569
570
571
572
573
  
      fore200e->bus->write(prom_dma, &entry->cp_entry->cmd.prom_block.prom_haddr);
      
      *entry->status = STATUS_PENDING;
  
      fore200e->bus->write(*(u32*)&opcode, (u32 __iomem *)&entry->cp_entry->cmd.prom_block.opcode);
  
      ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
  
      *entry->status = STATUS_FREE;
f3fadcb56   Christoph Hellwig   fore200e: devirtu...
574
      dma_unmap_single(fore200e->dev, prom_dma, sizeof(struct prom_data), DMA_FROM_DEVICE);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
  
      if (ok == 0) {
  	printk(FORE200E "unable to get PROM data from device %s
  ", fore200e->name);
  	return -EIO;
      }
  
  #if defined(__BIG_ENDIAN)
      
  #define swap_here(addr) (*((u32*)(addr)) = swab32( *((u32*)(addr)) ))
  
      /* MAC address is stored as little-endian */
      swap_here(&prom->mac_addr[0]);
      swap_here(&prom->mac_addr[4]);
  #endif
      
      return 0;
  }
  
  
  static int
  fore200e_pca_proc_read(struct fore200e* fore200e, char *page)
  {
aff9d262f   Christoph Hellwig   fore200e: store a...
598
      struct pci_dev *pci_dev = to_pci_dev(fore200e->dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
599
600
601
602
603
  
      return sprintf(page, "   PCI bus/slot/function:\t%d/%d/%d
  ",
  		   pci_dev->bus->number, PCI_SLOT(pci_dev->devfn), PCI_FUNC(pci_dev->devfn));
  }
0efe55238   Christoph Hellwig   fore200e: simplif...
604
605
606
607
608
609
610
611
  static const struct fore200e_bus fore200e_pci_ops = {
  	.model_name		= "PCA-200E",
  	.proc_name		= "pca200e",
  	.descr_alignment	= 32,
  	.buffer_alignment	= 4,
  	.status_alignment	= 32,
  	.read			= fore200e_pca_read,
  	.write			= fore200e_pca_write,
0efe55238   Christoph Hellwig   fore200e: simplif...
612
613
614
615
616
617
618
619
620
  	.configure		= fore200e_pca_configure,
  	.map			= fore200e_pca_map,
  	.reset			= fore200e_pca_reset,
  	.prom_read		= fore200e_pca_prom_read,
  	.unmap			= fore200e_pca_unmap,
  	.irq_check		= fore200e_pca_irq_check,
  	.irq_ack		= fore200e_pca_irq_ack,
  	.proc_read		= fore200e_pca_proc_read,
  };
e92481f95   Chas Williams   atm: [fore200e] c...
621
  #endif /* CONFIG_PCI */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
622

e92481f95   Chas Williams   atm: [fore200e] c...
623
  #ifdef CONFIG_SBUS
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
624

826b6cfcd   David S. Miller   fore200e: Convert...
625
  static u32 fore200e_sba_read(volatile u32 __iomem *addr)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
626
627
628
  {
      return sbus_readl(addr);
  }
826b6cfcd   David S. Miller   fore200e: Convert...
629
  static void fore200e_sba_write(u32 val, volatile u32 __iomem *addr)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
630
631
632
  {
      sbus_writel(val, addr);
  }
826b6cfcd   David S. Miller   fore200e: Convert...
633
  static void fore200e_sba_irq_enable(struct fore200e *fore200e)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
634
  {
826b6cfcd   David S. Miller   fore200e: Convert...
635
636
  	u32 hcr = fore200e->bus->read(fore200e->regs.sba.hcr) & SBA200E_HCR_STICKY;
  	fore200e->bus->write(hcr | SBA200E_HCR_INTR_ENA, fore200e->regs.sba.hcr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
637
  }
826b6cfcd   David S. Miller   fore200e: Convert...
638
  static int fore200e_sba_irq_check(struct fore200e *fore200e)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
639
  {
826b6cfcd   David S. Miller   fore200e: Convert...
640
  	return fore200e->bus->read(fore200e->regs.sba.hcr) & SBA200E_HCR_INTR_REQ;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
641
  }
826b6cfcd   David S. Miller   fore200e: Convert...
642
  static void fore200e_sba_irq_ack(struct fore200e *fore200e)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
643
  {
826b6cfcd   David S. Miller   fore200e: Convert...
644
645
  	u32 hcr = fore200e->bus->read(fore200e->regs.sba.hcr) & SBA200E_HCR_STICKY;
  	fore200e->bus->write(hcr | SBA200E_HCR_INTR_CLR, fore200e->regs.sba.hcr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
646
  }
826b6cfcd   David S. Miller   fore200e: Convert...
647
  static void fore200e_sba_reset(struct fore200e *fore200e)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
648
  {
826b6cfcd   David S. Miller   fore200e: Convert...
649
650
651
  	fore200e->bus->write(SBA200E_HCR_RESET, fore200e->regs.sba.hcr);
  	fore200e_spin(10);
  	fore200e->bus->write(0, fore200e->regs.sba.hcr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
652
  }
826b6cfcd   David S. Miller   fore200e: Convert...
653
  static int __init fore200e_sba_map(struct fore200e *fore200e)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
654
  {
aff9d262f   Christoph Hellwig   fore200e: store a...
655
  	struct platform_device *op = to_platform_device(fore200e->dev);
826b6cfcd   David S. Miller   fore200e: Convert...
656
  	unsigned int bursts;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
657

826b6cfcd   David S. Miller   fore200e: Convert...
658
659
660
661
662
  	/* gain access to the SBA specific registers  */
  	fore200e->regs.sba.hcr = of_ioremap(&op->resource[0], 0, SBA200E_HCR_LENGTH, "SBA HCR");
  	fore200e->regs.sba.bsr = of_ioremap(&op->resource[1], 0, SBA200E_BSR_LENGTH, "SBA BSR");
  	fore200e->regs.sba.isr = of_ioremap(&op->resource[2], 0, SBA200E_ISR_LENGTH, "SBA ISR");
  	fore200e->virt_base    = of_ioremap(&op->resource[3], 0, SBA200E_RAM_LENGTH, "SBA RAM");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
663

826b6cfcd   David S. Miller   fore200e: Convert...
664
665
666
667
668
  	if (!fore200e->virt_base) {
  		printk(FORE200E "unable to map RAM of device %s
  ", fore200e->name);
  		return -EFAULT;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
669

826b6cfcd   David S. Miller   fore200e: Convert...
670
671
  	DPRINTK(1, "device %s mapped to 0x%p
  ", fore200e->name, fore200e->virt_base);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
672
      
826b6cfcd   David S. Miller   fore200e: Convert...
673
  	fore200e->bus->write(0x02, fore200e->regs.sba.isr); /* XXX hardwired interrupt level */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
674

826b6cfcd   David S. Miller   fore200e: Convert...
675
  	/* get the supported DVMA burst sizes */
61c7a080a   Grant Likely   of: Always use 's...
676
  	bursts = of_getintprop_default(op->dev.of_node->parent, "burst-sizes", 0x00);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
677

826b6cfcd   David S. Miller   fore200e: Convert...
678
679
  	if (sbus_can_dma_64bit())
  		sbus_set_sbus64(&op->dev, bursts);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
680

826b6cfcd   David S. Miller   fore200e: Convert...
681
682
  	fore200e->state = FORE200E_STATE_MAP;
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
683
  }
826b6cfcd   David S. Miller   fore200e: Convert...
684
  static void fore200e_sba_unmap(struct fore200e *fore200e)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
685
  {
aff9d262f   Christoph Hellwig   fore200e: store a...
686
  	struct platform_device *op = to_platform_device(fore200e->dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
687

826b6cfcd   David S. Miller   fore200e: Convert...
688
689
690
691
692
  	of_iounmap(&op->resource[0], fore200e->regs.sba.hcr, SBA200E_HCR_LENGTH);
  	of_iounmap(&op->resource[1], fore200e->regs.sba.bsr, SBA200E_BSR_LENGTH);
  	of_iounmap(&op->resource[2], fore200e->regs.sba.isr, SBA200E_ISR_LENGTH);
  	of_iounmap(&op->resource[3], fore200e->virt_base,    SBA200E_RAM_LENGTH);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
693

826b6cfcd   David S. Miller   fore200e: Convert...
694
  static int __init fore200e_sba_configure(struct fore200e *fore200e)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
695
  {
826b6cfcd   David S. Miller   fore200e: Convert...
696
697
  	fore200e->state = FORE200E_STATE_CONFIGURE;
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
698
  }
826b6cfcd   David S. Miller   fore200e: Convert...
699
  static int __init fore200e_sba_prom_read(struct fore200e *fore200e, struct prom_data *prom)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
700
  {
aff9d262f   Christoph Hellwig   fore200e: store a...
701
  	struct platform_device *op = to_platform_device(fore200e->dev);
826b6cfcd   David S. Miller   fore200e: Convert...
702
703
  	const u8 *prop;
  	int len;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
704

61c7a080a   Grant Likely   of: Always use 's...
705
  	prop = of_get_property(op->dev.of_node, "madaddrlo2", &len);
826b6cfcd   David S. Miller   fore200e: Convert...
706
707
708
  	if (!prop)
  		return -ENODEV;
  	memcpy(&prom->mac_addr[4], prop, 4);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
709

61c7a080a   Grant Likely   of: Always use 's...
710
  	prop = of_get_property(op->dev.of_node, "madaddrhi4", &len);
826b6cfcd   David S. Miller   fore200e: Convert...
711
712
713
  	if (!prop)
  		return -ENODEV;
  	memcpy(&prom->mac_addr[2], prop, 4);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
714

61c7a080a   Grant Likely   of: Always use 's...
715
716
717
718
  	prom->serial_number = of_getintprop_default(op->dev.of_node,
  						    "serialnumber", 0);
  	prom->hw_revision = of_getintprop_default(op->dev.of_node,
  						  "promversion", 0);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
719
      
826b6cfcd   David S. Miller   fore200e: Convert...
720
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
721
  }
826b6cfcd   David S. Miller   fore200e: Convert...
722
  static int fore200e_sba_proc_read(struct fore200e *fore200e, char *page)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
723
  {
aff9d262f   Christoph Hellwig   fore200e: store a...
724
  	struct platform_device *op = to_platform_device(fore200e->dev);
826b6cfcd   David S. Miller   fore200e: Convert...
725
  	const struct linux_prom_registers *regs;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
726

61c7a080a   Grant Likely   of: Always use 's...
727
  	regs = of_get_property(op->dev.of_node, "reg", NULL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
728

ee5b60eba   Rob Herring   atm: Convert to u...
729
730
731
  	return sprintf(page, "   SBUS slot/device:\t\t%d/'%pOFn'
  ",
  		       (regs ? regs->which_io : 0), op->dev.of_node);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
732
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
733

0efe55238   Christoph Hellwig   fore200e: simplif...
734
735
736
737
  static const struct fore200e_bus fore200e_sbus_ops = {
  	.model_name		= "SBA-200E",
  	.proc_name		= "sba200e",
  	.descr_alignment	= 32,
666046418   Christoph Hellwig   fore200e: fix sbu...
738
  	.buffer_alignment	= 64,
0efe55238   Christoph Hellwig   fore200e: simplif...
739
740
741
  	.status_alignment	= 32,
  	.read			= fore200e_sba_read,
  	.write			= fore200e_sba_write,
0efe55238   Christoph Hellwig   fore200e: simplif...
742
743
744
745
746
747
748
749
750
751
752
  	.configure		= fore200e_sba_configure,
  	.map			= fore200e_sba_map,
  	.reset			= fore200e_sba_reset,
  	.prom_read		= fore200e_sba_prom_read,
  	.unmap			= fore200e_sba_unmap,
  	.irq_enable		= fore200e_sba_irq_enable,
  	.irq_check		= fore200e_sba_irq_check,
  	.irq_ack		= fore200e_sba_irq_ack,
  	.proc_read		= fore200e_sba_proc_read,
  };
  #endif /* CONFIG_SBUS */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
  
  static void
  fore200e_tx_irq(struct fore200e* fore200e)
  {
      struct host_txq*        txq = &fore200e->host_txq;
      struct host_txq_entry*  entry;
      struct atm_vcc*         vcc;
      struct fore200e_vc_map* vc_map;
  
      if (fore200e->host_txq.txing == 0)
  	return;
  
      for (;;) {
  	
  	entry = &txq->host_entry[ txq->tail ];
  
          if ((*entry->status & STATUS_COMPLETE) == 0) {
  	    break;
  	}
  
  	DPRINTK(3, "TX COMPLETED: entry = %p [tail = %d], vc_map = %p, skb = %p
  ", 
  		entry, txq->tail, entry->vc_map, entry->skb);
  
  	/* free copy of misaligned data */
a2c1aa547   Jesper Juhl   [ATM]: [drivers] ...
778
  	kfree(entry->data);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
779
780
  	
  	/* remove DMA mapping */
f3fadcb56   Christoph Hellwig   fore200e: devirtu...
781
  	dma_unmap_single(fore200e->dev, entry->tpd->tsd[ 0 ].buffer, entry->tpd->tsd[ 0 ].length,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
  				 DMA_TO_DEVICE);
  
  	vc_map = entry->vc_map;
  
  	/* vcc closed since the time the entry was submitted for tx? */
  	if ((vc_map->vcc == NULL) ||
  	    (test_bit(ATM_VF_READY, &vc_map->vcc->flags) == 0)) {
  
  	    DPRINTK(1, "no ready vcc found for PDU sent on device %d
  ",
  		    fore200e->atm_dev->number);
  
  	    dev_kfree_skb_any(entry->skb);
  	}
  	else {
  	    ASSERT(vc_map->vcc);
  
  	    /* vcc closed then immediately re-opened? */
  	    if (vc_map->incarn != entry->incarn) {
  
  		/* when a vcc is closed, some PDUs may be still pending in the tx queue.
  		   if the same vcc is immediately re-opened, those pending PDUs must
  		   not be popped after the completion of their emission, as they refer
  		   to the prior incarnation of that vcc. otherwise, sk_atm(vcc)->sk_wmem_alloc
  		   would be decremented by the size of the (unrelated) skb, possibly
  		   leading to a negative sk->sk_wmem_alloc count, ultimately freezing the vcc.
  		   we thus bind the tx entry to the current incarnation of the vcc
  		   when the entry is submitted for tx. When the tx later completes,
  		   if the incarnation number of the tx entry does not match the one
  		   of the vcc, then this implies that the vcc has been closed then re-opened.
  		   we thus just drop the skb here. */
  
  		DPRINTK(1, "vcc closed-then-re-opened; dropping PDU sent on device %d
  ",
  			fore200e->atm_dev->number);
  
  		dev_kfree_skb_any(entry->skb);
  	    }
  	    else {
  		vcc = vc_map->vcc;
  		ASSERT(vcc);
  
  		/* notify tx completion */
  		if (vcc->pop) {
  		    vcc->pop(vcc, entry->skb);
  		}
  		else {
  		    dev_kfree_skb_any(entry->skb);
  		}
14afee4b6   Reshetova, Elena   net: convert sock...
831

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
  		/* check error condition */
  		if (*entry->status & STATUS_ERROR)
  		    atomic_inc(&vcc->stats->tx_err);
  		else
  		    atomic_inc(&vcc->stats->tx);
  	    }
  	}
  
  	*entry->status = STATUS_FREE;
  
  	fore200e->host_txq.txing--;
  
  	FORE200E_NEXT_ENTRY(txq->tail, QUEUE_SIZE_TX);
      }
  }
  
  
  #ifdef FORE200E_BSQ_DEBUG
  int bsq_audit(int where, struct host_bsq* bsq, int scheme, int magn)
  {
      struct buffer* buffer;
      int count = 0;
  
      buffer = bsq->freebuf;
      while (buffer) {
  
  	if (buffer->supplied) {
  	    printk(FORE200E "bsq_audit(%d): queue %d.%d, buffer %ld supplied but in free list!
  ",
  		   where, scheme, magn, buffer->index);
  	}
  
  	if (buffer->magn != magn) {
  	    printk(FORE200E "bsq_audit(%d): queue %d.%d, buffer %ld, unexpected magn = %d
  ",
  		   where, scheme, magn, buffer->index, buffer->magn);
  	}
  
  	if (buffer->scheme != scheme) {
  	    printk(FORE200E "bsq_audit(%d): queue %d.%d, buffer %ld, unexpected scheme = %d
  ",
  		   where, scheme, magn, buffer->index, buffer->scheme);
  	}
  
  	if ((buffer->index < 0) || (buffer->index >= fore200e_rx_buf_nbr[ scheme ][ magn ])) {
  	    printk(FORE200E "bsq_audit(%d): queue %d.%d, out of range buffer index = %ld !
  ",
  		   where, scheme, magn, buffer->index);
  	}
  
  	count++;
  	buffer = buffer->next;
      }
  
      if (count != bsq->freebuf_count) {
  	printk(FORE200E "bsq_audit(%d): queue %d.%d, %d bufs in free list, but freebuf_count = %d
  ",
  	       where, scheme, magn, count, bsq->freebuf_count);
      }
      return 0;
  }
  #endif
  
  
  static void
  fore200e_supply(struct fore200e* fore200e)
  {
      int  scheme, magn, i;
  
      struct host_bsq*       bsq;
      struct host_bsq_entry* entry;
      struct buffer*         buffer;
  
      for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
  	for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
  
  	    bsq = &fore200e->host_bsq[ scheme ][ magn ];
  
  #ifdef FORE200E_BSQ_DEBUG
  	    bsq_audit(1, bsq, scheme, magn);
  #endif
  	    while (bsq->freebuf_count >= RBD_BLK_SIZE) {
  
  		DPRINTK(2, "supplying %d rx buffers to queue %d / %d, freebuf_count = %d
  ",
  			RBD_BLK_SIZE, scheme, magn, bsq->freebuf_count);
  
  		entry = &bsq->host_entry[ bsq->head ];
  
  		for (i = 0; i < RBD_BLK_SIZE; i++) {
  
  		    /* take the first buffer in the free buffer list */
  		    buffer = bsq->freebuf;
  		    if (!buffer) {
  			printk(FORE200E "no more free bufs in queue %d.%d, but freebuf_count = %d
  ",
  			       scheme, magn, bsq->freebuf_count);
  			return;
  		    }
  		    bsq->freebuf = buffer->next;
  		    
  #ifdef FORE200E_BSQ_DEBUG
  		    if (buffer->supplied)
  			printk(FORE200E "queue %d.%d, buffer %lu already supplied
  ",
  			       scheme, magn, buffer->index);
  		    buffer->supplied = 1;
  #endif
  		    entry->rbd_block->rbd[ i ].buffer_haddr = buffer->data.dma_addr;
  		    entry->rbd_block->rbd[ i ].handle       = FORE200E_BUF2HDL(buffer);
  		}
  
  		FORE200E_NEXT_ENTRY(bsq->head, QUEUE_SIZE_BS);
  
   		/* decrease accordingly the number of free rx buffers */
  		bsq->freebuf_count -= RBD_BLK_SIZE;
  
  		*entry->status = STATUS_PENDING;
  		fore200e->bus->write(entry->rbd_block_dma, &entry->cp_entry->rbd_block_haddr);
  	    }
  	}
      }
  }
  
  
  static int
  fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rpd)
  {
      struct sk_buff*      skb;
      struct buffer*       buffer;
      struct fore200e_vcc* fore200e_vcc;
      int                  i, pdu_len = 0;
  #ifdef FORE200E_52BYTE_AAL0_SDU
      u32                  cell_header = 0;
  #endif
  
      ASSERT(vcc);
      
      fore200e_vcc = FORE200E_VCC(vcc);
      ASSERT(fore200e_vcc);
  
  #ifdef FORE200E_52BYTE_AAL0_SDU
      if ((vcc->qos.aal == ATM_AAL0) && (vcc->qos.rxtp.max_sdu == ATM_AAL0_SDU)) {
  
  	cell_header = (rpd->atm_header.gfc << ATM_HDR_GFC_SHIFT) |
  	              (rpd->atm_header.vpi << ATM_HDR_VPI_SHIFT) |
                        (rpd->atm_header.vci << ATM_HDR_VCI_SHIFT) |
                        (rpd->atm_header.plt << ATM_HDR_PTI_SHIFT) | 
                         rpd->atm_header.clp;
  	pdu_len = 4;
      }
  #endif
      
      /* compute total PDU length */
      for (i = 0; i < rpd->nseg; i++)
  	pdu_len += rpd->rsd[ i ].length;
      
      skb = alloc_skb(pdu_len, GFP_ATOMIC);
      if (skb == NULL) {
  	DPRINTK(2, "unable to alloc new skb, rx PDU length = %d
  ", pdu_len);
  
  	atomic_inc(&vcc->stats->rx_drop);
  	return -ENOMEM;
      } 
a61bbcf28   Patrick McHardy   [NET]: Store skb-...
997
      __net_timestamp(skb);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
      
  #ifdef FORE200E_52BYTE_AAL0_SDU
      if (cell_header) {
  	*((u32*)skb_put(skb, 4)) = cell_header;
      }
  #endif
  
      /* reassemble segments */
      for (i = 0; i < rpd->nseg; i++) {
  	
  	/* rebuild rx buffer address from rsd handle */
  	buffer = FORE200E_HDL2BUF(rpd->rsd[ i ].handle);
  	
  	/* Make device DMA transfer visible to CPU.  */
f3fadcb56   Christoph Hellwig   fore200e: devirtu...
1012
1013
  	dma_sync_single_for_cpu(fore200e->dev, buffer->data.dma_addr,
  				rpd->rsd[i].length, DMA_FROM_DEVICE);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1014
  	
59ae1d127   Johannes Berg   networking: intro...
1015
  	skb_put_data(skb, buffer->data.align_addr, rpd->rsd[i].length);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1016
1017
  
  	/* Now let the device get at it again.  */
f3fadcb56   Christoph Hellwig   fore200e: devirtu...
1018
1019
  	dma_sync_single_for_device(fore200e->dev, buffer->data.dma_addr,
  				   rpd->rsd[i].length, DMA_FROM_DEVICE);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
      }
  
      DPRINTK(3, "rx skb: len = %d, truesize = %d
  ", skb->len, skb->truesize);
      
      if (pdu_len < fore200e_vcc->rx_min_pdu)
  	fore200e_vcc->rx_min_pdu = pdu_len;
      if (pdu_len > fore200e_vcc->rx_max_pdu)
  	fore200e_vcc->rx_max_pdu = pdu_len;
      fore200e_vcc->rx_pdu++;
  
      /* push PDU */
      if (atm_charge(vcc, skb->truesize) == 0) {
  
  	DPRINTK(2, "receive buffers saturated for %d.%d.%d - PDU dropped
  ",
  		vcc->itf, vcc->vpi, vcc->vci);
  
  	dev_kfree_skb_any(skb);
  
  	atomic_inc(&vcc->stats->rx_drop);
  	return -ENOMEM;
      }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1043
1044
      vcc->push(vcc, skb);
      atomic_inc(&vcc->stats->rx);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
      return 0;
  }
  
  
  static void
  fore200e_collect_rpd(struct fore200e* fore200e, struct rpd* rpd)
  {
      struct host_bsq* bsq;
      struct buffer*   buffer;
      int              i;
      
      for (i = 0; i < rpd->nseg; i++) {
  
  	/* rebuild rx buffer address from rsd handle */
  	buffer = FORE200E_HDL2BUF(rpd->rsd[ i ].handle);
  
  	bsq = &fore200e->host_bsq[ buffer->scheme ][ buffer->magn ];
  
  #ifdef FORE200E_BSQ_DEBUG
  	bsq_audit(2, bsq, buffer->scheme, buffer->magn);
  
  	if (buffer->supplied == 0)
  	    printk(FORE200E "queue %d.%d, buffer %ld was not supplied
  ",
  		   buffer->scheme, buffer->magn, buffer->index);
  	buffer->supplied = 0;
  #endif
  
  	/* re-insert the buffer into the free buffer list */
  	buffer->next = bsq->freebuf;
  	bsq->freebuf = buffer;
  
  	/* then increment the number of free rx buffers */
  	bsq->freebuf_count++;
      }
  }
  
  
  static void
  fore200e_rx_irq(struct fore200e* fore200e)
  {
      struct host_rxq*        rxq = &fore200e->host_rxq;
      struct host_rxq_entry*  entry;
      struct atm_vcc*         vcc;
      struct fore200e_vc_map* vc_map;
  
      for (;;) {
  	
  	entry = &rxq->host_entry[ rxq->head ];
  
  	/* no more received PDUs */
  	if ((*entry->status & STATUS_COMPLETE) == 0)
  	    break;
  
  	vc_map = FORE200E_VC_MAP(fore200e, entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
  
  	if ((vc_map->vcc == NULL) ||
  	    (test_bit(ATM_VF_READY, &vc_map->vcc->flags) == 0)) {
  
  	    DPRINTK(1, "no ready VC found for PDU received on %d.%d.%d
  ",
  		    fore200e->atm_dev->number,
  		    entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
  	}
  	else {
  	    vcc = vc_map->vcc;
  	    ASSERT(vcc);
  
  	    if ((*entry->status & STATUS_ERROR) == 0) {
  
  		fore200e_push_rpd(fore200e, vcc, entry->rpd);
  	    }
  	    else {
  		DPRINTK(2, "damaged PDU on %d.%d.%d
  ",
  			fore200e->atm_dev->number,
  			entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
  		atomic_inc(&vcc->stats->rx_err);
  	    }
  	}
  
  	FORE200E_NEXT_ENTRY(rxq->head, QUEUE_SIZE_RX);
  
  	fore200e_collect_rpd(fore200e, entry->rpd);
  
  	/* rewrite the rpd address to ack the received PDU */
  	fore200e->bus->write(entry->rpd_dma, &entry->cp_entry->rpd_haddr);
  	*entry->status = STATUS_FREE;
  
  	fore200e_supply(fore200e);
      }
  }
  
  
  #ifndef FORE200E_USE_TASKLET
  static void
  fore200e_irq(struct fore200e* fore200e)
  {
      unsigned long flags;
  
      spin_lock_irqsave(&fore200e->q_lock, flags);
      fore200e_rx_irq(fore200e);
      spin_unlock_irqrestore(&fore200e->q_lock, flags);
  
      spin_lock_irqsave(&fore200e->q_lock, flags);
      fore200e_tx_irq(fore200e);
      spin_unlock_irqrestore(&fore200e->q_lock, flags);
  }
  #endif
  
  
  static irqreturn_t
7d12e780e   David Howells   IRQ: Maintain reg...
1157
  fore200e_interrupt(int irq, void* dev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
  {
      struct fore200e* fore200e = FORE200E_DEV((struct atm_dev*)dev);
  
      if (fore200e->bus->irq_check(fore200e) == 0) {
  	
  	DPRINTK(3, "interrupt NOT triggered by device %d
  ", fore200e->atm_dev->number);
  	return IRQ_NONE;
      }
      DPRINTK(3, "interrupt triggered by device %d
  ", fore200e->atm_dev->number);
  
  #ifdef FORE200E_USE_TASKLET
      tasklet_schedule(&fore200e->tx_tasklet);
      tasklet_schedule(&fore200e->rx_tasklet);
  #else
      fore200e_irq(fore200e);
  #endif
      
      fore200e->bus->irq_ack(fore200e);
      return IRQ_HANDLED;
  }
  
  
  #ifdef FORE200E_USE_TASKLET
  static void
  fore200e_tx_tasklet(unsigned long data)
  {
      struct fore200e* fore200e = (struct fore200e*) data;
      unsigned long flags;
  
      DPRINTK(3, "tx tasklet scheduled for device %d
  ", fore200e->atm_dev->number);
  
      spin_lock_irqsave(&fore200e->q_lock, flags);
      fore200e_tx_irq(fore200e);
      spin_unlock_irqrestore(&fore200e->q_lock, flags);
  }
  
  
  static void
  fore200e_rx_tasklet(unsigned long data)
  {
      struct fore200e* fore200e = (struct fore200e*) data;
      unsigned long    flags;
  
      DPRINTK(3, "rx tasklet scheduled for device %d
  ", fore200e->atm_dev->number);
  
      spin_lock_irqsave(&fore200e->q_lock, flags);
      fore200e_rx_irq((struct fore200e*) data);
      spin_unlock_irqrestore(&fore200e->q_lock, flags);
  }
  #endif
  
  
  static int
  fore200e_select_scheme(struct atm_vcc* vcc)
  {
      /* fairly balance the VCs over (identical) buffer schemes */
      int scheme = vcc->vci % 2 ? BUFFER_SCHEME_ONE : BUFFER_SCHEME_TWO;
  
      DPRINTK(1, "VC %d.%d.%d uses buffer scheme %d
  ",
  	    vcc->itf, vcc->vpi, vcc->vci, scheme);
  
      return scheme;
  }
  
  
  static int 
  fore200e_activate_vcin(struct fore200e* fore200e, int activate, struct atm_vcc* vcc, int mtu)
  {
      struct host_cmdq*        cmdq  = &fore200e->host_cmdq;
      struct host_cmdq_entry*  entry = &cmdq->host_entry[ cmdq->head ];
      struct activate_opcode   activ_opcode;
      struct deactivate_opcode deactiv_opcode;
      struct vpvc              vpvc;
      int                      ok;
      enum fore200e_aal        aal = fore200e_atm2fore_aal(vcc->qos.aal);
  
      FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
      
      if (activate) {
  	FORE200E_VCC(vcc)->scheme = fore200e_select_scheme(vcc);
  	
  	activ_opcode.opcode = OPCODE_ACTIVATE_VCIN;
  	activ_opcode.aal    = aal;
  	activ_opcode.scheme = FORE200E_VCC(vcc)->scheme;
  	activ_opcode.pad    = 0;
      }
      else {
  	deactiv_opcode.opcode = OPCODE_DEACTIVATE_VCIN;
  	deactiv_opcode.pad    = 0;
      }
  
      vpvc.vci = vcc->vci;
      vpvc.vpi = vcc->vpi;
  
      *entry->status = STATUS_PENDING;
  
      if (activate) {
  
  #ifdef FORE200E_52BYTE_AAL0_SDU
  	mtu = 48;
  #endif
  	/* the MTU is not used by the cp, except in the case of AAL0 */
  	fore200e->bus->write(mtu,                        &entry->cp_entry->cmd.activate_block.mtu);
  	fore200e->bus->write(*(u32*)&vpvc,         (u32 __iomem *)&entry->cp_entry->cmd.activate_block.vpvc);
  	fore200e->bus->write(*(u32*)&activ_opcode, (u32 __iomem *)&entry->cp_entry->cmd.activate_block.opcode);
      }
      else {
  	fore200e->bus->write(*(u32*)&vpvc,         (u32 __iomem *)&entry->cp_entry->cmd.deactivate_block.vpvc);
  	fore200e->bus->write(*(u32*)&deactiv_opcode, (u32 __iomem *)&entry->cp_entry->cmd.deactivate_block.opcode);
      }
  
      ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
  
      *entry->status = STATUS_FREE;
  
      if (ok == 0) {
  	printk(FORE200E "unable to %s VC %d.%d.%d
  ",
  	       activate ? "open" : "close", vcc->itf, vcc->vpi, vcc->vci);
  	return -EIO;
      }
  
      DPRINTK(1, "VC %d.%d.%d %sed
  ", vcc->itf, vcc->vpi, vcc->vci, 
  	    activate ? "open" : "clos");
  
      return 0;
  }
  
  
  #define FORE200E_MAX_BACK2BACK_CELLS 255    /* XXX depends on CDVT */
  
  static void
  fore200e_rate_ctrl(struct atm_qos* qos, struct tpd_rate* rate)
  {
      if (qos->txtp.max_pcr < ATM_OC3_PCR) {
      
  	/* compute the data cells to idle cells ratio from the tx PCR */
  	rate->data_cells = qos->txtp.max_pcr * FORE200E_MAX_BACK2BACK_CELLS / ATM_OC3_PCR;
  	rate->idle_cells = FORE200E_MAX_BACK2BACK_CELLS - rate->data_cells;
      }
      else {
  	/* disable rate control */
  	rate->data_cells = rate->idle_cells = 0;
      }
  }
  
  
  static int
  fore200e_open(struct atm_vcc *vcc)
  {
      struct fore200e*        fore200e = FORE200E_DEV(vcc->dev);
      struct fore200e_vcc*    fore200e_vcc;
      struct fore200e_vc_map* vc_map;
      unsigned long	    flags;
      int			    vci = vcc->vci;
      short		    vpi = vcc->vpi;
  
      ASSERT((vpi >= 0) && (vpi < 1<<FORE200E_VPI_BITS));
      ASSERT((vci >= 0) && (vci < 1<<FORE200E_VCI_BITS));
  
      spin_lock_irqsave(&fore200e->q_lock, flags);
  
      vc_map = FORE200E_VC_MAP(fore200e, vpi, vci);
      if (vc_map->vcc) {
  
  	spin_unlock_irqrestore(&fore200e->q_lock, flags);
  
  	printk(FORE200E "VC %d.%d.%d already in use
  ",
  	       fore200e->atm_dev->number, vpi, vci);
  
  	return -EINVAL;
      }
  
      vc_map->vcc = vcc;
  
      spin_unlock_irqrestore(&fore200e->q_lock, flags);
1f8a5fb80   Adrian Bunk   [ATM] drivers/atm...
1341
      fore200e_vcc = kzalloc(sizeof(struct fore200e_vcc), GFP_ATOMIC);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
      if (fore200e_vcc == NULL) {
  	vc_map->vcc = NULL;
  	return -ENOMEM;
      }
  
      DPRINTK(2, "opening %d.%d.%d:%d QoS = (tx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d; "
  	    "rx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d)
  ",
  	    vcc->itf, vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal),
  	    fore200e_traffic_class[ vcc->qos.txtp.traffic_class ],
  	    vcc->qos.txtp.min_pcr, vcc->qos.txtp.max_pcr, vcc->qos.txtp.max_cdv, vcc->qos.txtp.max_sdu,
  	    fore200e_traffic_class[ vcc->qos.rxtp.traffic_class ],
  	    vcc->qos.rxtp.min_pcr, vcc->qos.rxtp.max_pcr, vcc->qos.rxtp.max_cdv, vcc->qos.rxtp.max_sdu);
      
      /* pseudo-CBR bandwidth requested? */
      if ((vcc->qos.txtp.traffic_class == ATM_CBR) && (vcc->qos.txtp.max_pcr > 0)) {
  	
bfbf3c096   Matthias Kaehlcke   [ATM]: Use mutex ...
1359
  	mutex_lock(&fore200e->rate_mtx);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1360
  	if (fore200e->available_cell_rate < vcc->qos.txtp.max_pcr) {
bfbf3c096   Matthias Kaehlcke   [ATM]: Use mutex ...
1361
  	    mutex_unlock(&fore200e->rate_mtx);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1362

1f8a5fb80   Adrian Bunk   [ATM] drivers/atm...
1363
  	    kfree(fore200e_vcc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1364
1365
1366
1367
1368
1369
  	    vc_map->vcc = NULL;
  	    return -EAGAIN;
  	}
  
  	/* reserve bandwidth */
  	fore200e->available_cell_rate -= vcc->qos.txtp.max_pcr;
bfbf3c096   Matthias Kaehlcke   [ATM]: Use mutex ...
1370
  	mutex_unlock(&fore200e->rate_mtx);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
      }
      
      vcc->itf = vcc->dev->number;
  
      set_bit(ATM_VF_PARTIAL,&vcc->flags);
      set_bit(ATM_VF_ADDR, &vcc->flags);
  
      vcc->dev_data = fore200e_vcc;
      
      if (fore200e_activate_vcin(fore200e, 1, vcc, vcc->qos.rxtp.max_sdu) < 0) {
  
  	vc_map->vcc = NULL;
  
  	clear_bit(ATM_VF_ADDR, &vcc->flags);
  	clear_bit(ATM_VF_PARTIAL,&vcc->flags);
  
  	vcc->dev_data = NULL;
  
  	fore200e->available_cell_rate += vcc->qos.txtp.max_pcr;
1f8a5fb80   Adrian Bunk   [ATM] drivers/atm...
1390
  	kfree(fore200e_vcc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
  	return -EINVAL;
      }
      
      /* compute rate control parameters */
      if ((vcc->qos.txtp.traffic_class == ATM_CBR) && (vcc->qos.txtp.max_pcr > 0)) {
  	
  	fore200e_rate_ctrl(&vcc->qos, &fore200e_vcc->rate);
  	set_bit(ATM_VF_HASQOS, &vcc->flags);
  
  	DPRINTK(3, "tx on %d.%d.%d:%d, tx PCR = %d, rx PCR = %d, data_cells = %u, idle_cells = %u
  ",
  		vcc->itf, vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal),
  		vcc->qos.txtp.max_pcr, vcc->qos.rxtp.max_pcr, 
  		fore200e_vcc->rate.data_cells, fore200e_vcc->rate.idle_cells);
      }
      
      fore200e_vcc->tx_min_pdu = fore200e_vcc->rx_min_pdu = MAX_PDU_SIZE + 1;
      fore200e_vcc->tx_max_pdu = fore200e_vcc->rx_max_pdu = 0;
      fore200e_vcc->tx_pdu     = fore200e_vcc->rx_pdu     = 0;
  
      /* new incarnation of the vcc */
      vc_map->incarn = ++fore200e->incarn_count;
  
      /* VC unusable before this flag is set */
      set_bit(ATM_VF_READY, &vcc->flags);
  
      return 0;
  }
  
  
  static void
  fore200e_close(struct atm_vcc* vcc)
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1424
      struct fore200e_vcc*    fore200e_vcc;
bbd20c939   Aditya Pakki   fore200e: Fix inc...
1425
      struct fore200e*        fore200e;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1426
1427
1428
1429
      struct fore200e_vc_map* vc_map;
      unsigned long           flags;
  
      ASSERT(vcc);
bbd20c939   Aditya Pakki   fore200e: Fix inc...
1430
      fore200e = FORE200E_DEV(vcc->dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
      ASSERT((vcc->vpi >= 0) && (vcc->vpi < 1<<FORE200E_VPI_BITS));
      ASSERT((vcc->vci >= 0) && (vcc->vci < 1<<FORE200E_VCI_BITS));
  
      DPRINTK(2, "closing %d.%d.%d:%d
  ", vcc->itf, vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal));
  
      clear_bit(ATM_VF_READY, &vcc->flags);
  
      fore200e_activate_vcin(fore200e, 0, vcc, 0);
  
      spin_lock_irqsave(&fore200e->q_lock, flags);
  
      vc_map = FORE200E_VC_MAP(fore200e, vcc->vpi, vcc->vci);
  
      /* the vc is no longer considered as "in use" by fore200e_open() */
      vc_map->vcc = NULL;
  
      vcc->itf = vcc->vci = vcc->vpi = 0;
  
      fore200e_vcc = FORE200E_VCC(vcc);
      vcc->dev_data = NULL;
  
      spin_unlock_irqrestore(&fore200e->q_lock, flags);
  
      /* release reserved bandwidth, if any */
      if ((vcc->qos.txtp.traffic_class == ATM_CBR) && (vcc->qos.txtp.max_pcr > 0)) {
bfbf3c096   Matthias Kaehlcke   [ATM]: Use mutex ...
1457
  	mutex_lock(&fore200e->rate_mtx);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1458
  	fore200e->available_cell_rate += vcc->qos.txtp.max_pcr;
bfbf3c096   Matthias Kaehlcke   [ATM]: Use mutex ...
1459
  	mutex_unlock(&fore200e->rate_mtx);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1460
1461
1462
1463
1464
1465
1466
1467
  
  	clear_bit(ATM_VF_HASQOS, &vcc->flags);
      }
  
      clear_bit(ATM_VF_ADDR, &vcc->flags);
      clear_bit(ATM_VF_PARTIAL,&vcc->flags);
  
      ASSERT(fore200e_vcc);
1f8a5fb80   Adrian Bunk   [ATM] drivers/atm...
1468
      kfree(fore200e_vcc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1469
1470
1471
1472
1473
1474
  }
  
  
  static int
  fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
  {
bbd20c939   Aditya Pakki   fore200e: Fix inc...
1475
1476
      struct fore200e*        fore200e;
      struct fore200e_vcc*    fore200e_vcc;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1477
      struct fore200e_vc_map* vc_map;
bbd20c939   Aditya Pakki   fore200e: Fix inc...
1478
      struct host_txq*        txq;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
      struct host_txq_entry*  entry;
      struct tpd*             tpd;
      struct tpd_haddr        tpd_haddr;
      int                     retry        = CONFIG_ATM_FORE200E_TX_RETRY;
      int                     tx_copy      = 0;
      int                     tx_len       = skb->len;
      u32*                    cell_header  = NULL;
      unsigned char*          skb_data;
      int                     skb_len;
      unsigned char*          data;
      unsigned long           flags;
bbd20c939   Aditya Pakki   fore200e: Fix inc...
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
      if (!vcc)
          return -EINVAL;
  
      fore200e = FORE200E_DEV(vcc->dev);
      fore200e_vcc = FORE200E_VCC(vcc);
  
      if (!fore200e)
          return -EINVAL;
  
      txq = &fore200e->host_txq;
      if (!fore200e_vcc)
          return -EINVAL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
  
      if (!test_bit(ATM_VF_READY, &vcc->flags)) {
  	DPRINTK(1, "VC %d.%d.%d not ready for tx
  ", vcc->itf, vcc->vpi, vcc->vpi);
  	dev_kfree_skb_any(skb);
  	return -EINVAL;
      }
  
  #ifdef FORE200E_52BYTE_AAL0_SDU
      if ((vcc->qos.aal == ATM_AAL0) && (vcc->qos.txtp.max_sdu == ATM_AAL0_SDU)) {
  	cell_header = (u32*) skb->data;
  	skb_data    = skb->data + 4;    /* skip 4-byte cell header */
  	skb_len     = tx_len = skb->len  - 4;
  
  	DPRINTK(3, "user-supplied cell header = 0x%08x
  ", *cell_header);
      }
      else 
  #endif
      {
  	skb_data = skb->data;
  	skb_len  = skb->len;
      }
      
      if (((unsigned long)skb_data) & 0x3) {
  
  	DPRINTK(2, "misaligned tx PDU on device %s
  ", fore200e->name);
  	tx_copy = 1;
  	tx_len  = skb_len;
      }
  
      if ((vcc->qos.aal == ATM_AAL0) && (skb_len % ATM_CELL_PAYLOAD)) {
  
          /* this simply NUKES the PCA board */
  	DPRINTK(2, "incomplete tx AAL0 PDU on device %s
  ", fore200e->name);
  	tx_copy = 1;
  	tx_len  = ((skb_len / ATM_CELL_PAYLOAD) + 1) * ATM_CELL_PAYLOAD;
      }
      
      if (tx_copy) {
0e21b2258   Christoph Hellwig   fore200e: don't u...
1544
  	data = kmalloc(tx_len, GFP_ATOMIC);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
  	if (data == NULL) {
  	    if (vcc->pop) {
  		vcc->pop(vcc, skb);
  	    }
  	    else {
  		dev_kfree_skb_any(skb);
  	    }
  	    return -ENOMEM;
  	}
  
  	memcpy(data, skb_data, skb_len);
  	if (skb_len < tx_len)
  	    memset(data + skb_len, 0x00, tx_len - skb_len);
      }
      else {
  	data = skb_data;
      }
  
      vc_map = FORE200E_VC_MAP(fore200e, vcc->vpi, vcc->vci);
      ASSERT(vc_map->vcc == vcc);
  
    retry_here:
  
      spin_lock_irqsave(&fore200e->q_lock, flags);
  
      entry = &txq->host_entry[ txq->head ];
  
      if ((*entry->status != STATUS_FREE) || (txq->txing >= QUEUE_SIZE_TX - 2)) {
  
  	/* try to free completed tx queue entries */
  	fore200e_tx_irq(fore200e);
  
  	if (*entry->status != STATUS_FREE) {
  
  	    spin_unlock_irqrestore(&fore200e->q_lock, flags);
  
  	    /* retry once again? */
  	    if (--retry > 0) {
  		udelay(50);
  		goto retry_here;
  	    }
  
  	    atomic_inc(&vcc->stats->tx_err);
  
  	    fore200e->tx_sat++;
  	    DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x
  ",
  		    fore200e->name, fore200e->cp_queues->heartbeat);
  	    if (vcc->pop) {
  		vcc->pop(vcc, skb);
  	    }
  	    else {
  		dev_kfree_skb_any(skb);
  	    }
  
  	    if (tx_copy)
  		kfree(data);
  
  	    return -ENOBUFS;
  	}
      }
  
      entry->incarn = vc_map->incarn;
      entry->vc_map = vc_map;
      entry->skb    = skb;
      entry->data   = tx_copy ? data : NULL;
  
      tpd = entry->tpd;
f3fadcb56   Christoph Hellwig   fore200e: devirtu...
1613
1614
      tpd->tsd[ 0 ].buffer = dma_map_single(fore200e->dev, data, tx_len,
  					  DMA_TO_DEVICE);
1d9d8be91   Christoph Hellwig   fore200e: check f...
1615
1616
1617
      if (dma_mapping_error(fore200e->dev, tpd->tsd[0].buffer)) {
  	if (tx_copy)
  	    kfree(data);
d275444cc   Wei Yongjun   fore200e: fix mis...
1618
  	spin_unlock_irqrestore(&fore200e->q_lock, flags);
1d9d8be91   Christoph Hellwig   fore200e: check f...
1619
1620
  	return -ENOMEM;
      }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
      tpd->tsd[ 0 ].length = tx_len;
  
      FORE200E_NEXT_ENTRY(txq->head, QUEUE_SIZE_TX);
      txq->txing++;
  
      /* The dma_map call above implies a dma_sync so the device can use it,
       * thus no explicit dma_sync call is necessary here.
       */
      
      DPRINTK(3, "tx on %d.%d.%d:%d, len = %u (%u)
  ", 
  	    vcc->itf, vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal),
  	    tpd->tsd[0].length, skb_len);
  
      if (skb_len < fore200e_vcc->tx_min_pdu)
  	fore200e_vcc->tx_min_pdu = skb_len;
      if (skb_len > fore200e_vcc->tx_max_pdu)
  	fore200e_vcc->tx_max_pdu = skb_len;
      fore200e_vcc->tx_pdu++;
  
      /* set tx rate control information */
      tpd->rate.data_cells = fore200e_vcc->rate.data_cells;
      tpd->rate.idle_cells = fore200e_vcc->rate.idle_cells;
  
      if (cell_header) {
  	tpd->atm_header.clp = (*cell_header & ATM_HDR_CLP);
  	tpd->atm_header.plt = (*cell_header & ATM_HDR_PTI_MASK) >> ATM_HDR_PTI_SHIFT;
  	tpd->atm_header.vci = (*cell_header & ATM_HDR_VCI_MASK) >> ATM_HDR_VCI_SHIFT;
  	tpd->atm_header.vpi = (*cell_header & ATM_HDR_VPI_MASK) >> ATM_HDR_VPI_SHIFT;
  	tpd->atm_header.gfc = (*cell_header & ATM_HDR_GFC_MASK) >> ATM_HDR_GFC_SHIFT;
      }
      else {
  	/* set the ATM header, common to all cells conveying the PDU */
  	tpd->atm_header.clp = 0;
  	tpd->atm_header.plt = 0;
  	tpd->atm_header.vci = vcc->vci;
  	tpd->atm_header.vpi = vcc->vpi;
  	tpd->atm_header.gfc = 0;
      }
  
      tpd->spec.length = tx_len;
      tpd->spec.nseg   = 1;
      tpd->spec.aal    = fore200e_atm2fore_aal(vcc->qos.aal);
      tpd->spec.intr   = 1;
  
      tpd_haddr.size  = sizeof(struct tpd) / (1<<TPD_HADDR_SHIFT);  /* size is expressed in 32 byte blocks */
      tpd_haddr.pad   = 0;
      tpd_haddr.haddr = entry->tpd_dma >> TPD_HADDR_SHIFT;          /* shift the address, as we are in a bitfield */
  
      *entry->status = STATUS_PENDING;
      fore200e->bus->write(*(u32*)&tpd_haddr, (u32 __iomem *)&entry->cp_entry->tpd_haddr);
  
      spin_unlock_irqrestore(&fore200e->q_lock, flags);
  
      return 0;
  }
  
  
  static int
  fore200e_getstats(struct fore200e* fore200e)
  {
      struct host_cmdq*       cmdq  = &fore200e->host_cmdq;
      struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
      struct stats_opcode     opcode;
      int                     ok;
      u32                     stats_dma_addr;
  
      if (fore200e->stats == NULL) {
0e21b2258   Christoph Hellwig   fore200e: don't u...
1689
  	fore200e->stats = kzalloc(sizeof(struct stats), GFP_KERNEL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1690
1691
1692
1693
  	if (fore200e->stats == NULL)
  	    return -ENOMEM;
      }
      
f3fadcb56   Christoph Hellwig   fore200e: devirtu...
1694
1695
      stats_dma_addr = dma_map_single(fore200e->dev, fore200e->stats,
  				    sizeof(struct stats), DMA_FROM_DEVICE);
1d9d8be91   Christoph Hellwig   fore200e: check f...
1696
1697
      if (dma_mapping_error(fore200e->dev, stats_dma_addr))
      	return -ENOMEM;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
      
      FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
  
      opcode.opcode = OPCODE_GET_STATS;
      opcode.pad    = 0;
  
      fore200e->bus->write(stats_dma_addr, &entry->cp_entry->cmd.stats_block.stats_haddr);
      
      *entry->status = STATUS_PENDING;
  
      fore200e->bus->write(*(u32*)&opcode, (u32 __iomem *)&entry->cp_entry->cmd.stats_block.opcode);
  
      ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
  
      *entry->status = STATUS_FREE;
f3fadcb56   Christoph Hellwig   fore200e: devirtu...
1713
      dma_unmap_single(fore200e->dev, stats_dma_addr, sizeof(struct stats), DMA_FROM_DEVICE);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
      
      if (ok == 0) {
  	printk(FORE200E "unable to get statistics from device %s
  ", fore200e->name);
  	return -EIO;
      }
  
      return 0;
  }
  
  
  static int
  fore200e_getsockopt(struct atm_vcc* vcc, int level, int optname, void __user *optval, int optlen)
  {
      /* struct fore200e* fore200e = FORE200E_DEV(vcc->dev); */
  
      DPRINTK(2, "getsockopt %d.%d.%d, level = %d, optname = 0x%x, optval = 0x%p, optlen = %d
  ",
  	    vcc->itf, vcc->vpi, vcc->vci, level, optname, optval, optlen);
  
      return -EINVAL;
  }
  
  
  static int
b7058842c   David S. Miller   net: Make setsock...
1739
  fore200e_setsockopt(struct atm_vcc* vcc, int level, int optname, void __user *optval, unsigned int optlen)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
  {
      /* struct fore200e* fore200e = FORE200E_DEV(vcc->dev); */
      
      DPRINTK(2, "setsockopt %d.%d.%d, level = %d, optname = 0x%x, optval = 0x%p, optlen = %d
  ",
  	    vcc->itf, vcc->vpi, vcc->vci, level, optname, optval, optlen);
      
      return -EINVAL;
  }
  
  
  #if 0 /* currently unused */
  static int
  fore200e_get_oc3(struct fore200e* fore200e, struct oc3_regs* regs)
  {
      struct host_cmdq*       cmdq  = &fore200e->host_cmdq;
      struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
      struct oc3_opcode       opcode;
      int                     ok;
      u32                     oc3_regs_dma_addr;
  
      oc3_regs_dma_addr = fore200e->bus->dma_map(fore200e, regs, sizeof(struct oc3_regs), DMA_FROM_DEVICE);
  
      FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
  
      opcode.opcode = OPCODE_GET_OC3;
      opcode.reg    = 0;
      opcode.value  = 0;
      opcode.mask   = 0;
  
      fore200e->bus->write(oc3_regs_dma_addr, &entry->cp_entry->cmd.oc3_block.regs_haddr);
      
      *entry->status = STATUS_PENDING;
  
      fore200e->bus->write(*(u32*)&opcode, (u32*)&entry->cp_entry->cmd.oc3_block.opcode);
  
      ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
  
      *entry->status = STATUS_FREE;
  
      fore200e->bus->dma_unmap(fore200e, oc3_regs_dma_addr, sizeof(struct oc3_regs), DMA_FROM_DEVICE);
      
      if (ok == 0) {
  	printk(FORE200E "unable to get OC-3 regs of device %s
  ", fore200e->name);
  	return -EIO;
      }
  
      return 0;
  }
  #endif
  
  
  static int
  fore200e_set_oc3(struct fore200e* fore200e, u32 reg, u32 value, u32 mask)
  {
      struct host_cmdq*       cmdq  = &fore200e->host_cmdq;
      struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
      struct oc3_opcode       opcode;
      int                     ok;
  
      DPRINTK(2, "set OC-3 reg = 0x%02x, value = 0x%02x, mask = 0x%02x
  ", reg, value, mask);
  
      FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
  
      opcode.opcode = OPCODE_SET_OC3;
      opcode.reg    = reg;
      opcode.value  = value;
      opcode.mask   = mask;
  
      fore200e->bus->write(0, &entry->cp_entry->cmd.oc3_block.regs_haddr);
      
      *entry->status = STATUS_PENDING;
  
      fore200e->bus->write(*(u32*)&opcode, (u32 __iomem *)&entry->cp_entry->cmd.oc3_block.opcode);
  
      ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
  
      *entry->status = STATUS_FREE;
  
      if (ok == 0) {
  	printk(FORE200E "unable to set OC-3 reg 0x%02x of device %s
  ", reg, fore200e->name);
  	return -EIO;
      }
  
      return 0;
  }
  
  
  static int
  fore200e_setloop(struct fore200e* fore200e, int loop_mode)
  {
      u32 mct_value, mct_mask;
      int error;
  
      if (!capable(CAP_NET_ADMIN))
  	return -EPERM;
      
      switch (loop_mode) {
  
      case ATM_LM_NONE:
  	mct_value = 0; 
  	mct_mask  = SUNI_MCT_DLE | SUNI_MCT_LLE;
  	break;
  	
      case ATM_LM_LOC_PHY:
  	mct_value = mct_mask = SUNI_MCT_DLE;
  	break;
  
      case ATM_LM_RMT_PHY:
  	mct_value = mct_mask = SUNI_MCT_LLE;
  	break;
  
      default:
  	return -EINVAL;
      }
  
      error = fore200e_set_oc3(fore200e, SUNI_MCT, mct_value, mct_mask);
      if (error == 0)
  	fore200e->loop_mode = loop_mode;
  
      return error;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1865
1866
1867
1868
1869
1870
1871
  static int
  fore200e_fetch_stats(struct fore200e* fore200e, struct sonet_stats __user *arg)
  {
      struct sonet_stats tmp;
  
      if (fore200e_getstats(fore200e) < 0)
  	return -EIO;
63734a32a   Al Viro   fore2000 - fix mi...
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
      tmp.section_bip = be32_to_cpu(fore200e->stats->oc3.section_bip8_errors);
      tmp.line_bip    = be32_to_cpu(fore200e->stats->oc3.line_bip24_errors);
      tmp.path_bip    = be32_to_cpu(fore200e->stats->oc3.path_bip8_errors);
      tmp.line_febe   = be32_to_cpu(fore200e->stats->oc3.line_febe_errors);
      tmp.path_febe   = be32_to_cpu(fore200e->stats->oc3.path_febe_errors);
      tmp.corr_hcs    = be32_to_cpu(fore200e->stats->oc3.corr_hcs_errors);
      tmp.uncorr_hcs  = be32_to_cpu(fore200e->stats->oc3.ucorr_hcs_errors);
      tmp.tx_cells    = be32_to_cpu(fore200e->stats->aal0.cells_transmitted)  +
  	              be32_to_cpu(fore200e->stats->aal34.cells_transmitted) +
  	              be32_to_cpu(fore200e->stats->aal5.cells_transmitted);
      tmp.rx_cells    = be32_to_cpu(fore200e->stats->aal0.cells_received)     +
  	              be32_to_cpu(fore200e->stats->aal34.cells_received)    +
  	              be32_to_cpu(fore200e->stats->aal5.cells_received);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
  
      if (arg)
  	return copy_to_user(arg, &tmp, sizeof(struct sonet_stats)) ? -EFAULT : 0;	
      
      return 0;
  }
  
  
  static int
  fore200e_ioctl(struct atm_dev* dev, unsigned int cmd, void __user * arg)
  {
      struct fore200e* fore200e = FORE200E_DEV(dev);
      
      DPRINTK(2, "ioctl cmd = 0x%x (%u), arg = 0x%p (%lu)
  ", cmd, cmd, arg, (unsigned long)arg);
  
      switch (cmd) {
  
      case SONET_GETSTAT:
  	return fore200e_fetch_stats(fore200e, (struct sonet_stats __user *)arg);
  
      case SONET_GETDIAG:
  	return put_user(0, (int __user *)arg) ? -EFAULT : 0;
  
      case ATM_SETLOOP:
  	return fore200e_setloop(fore200e, (int)(unsigned long)arg);
  
      case ATM_GETLOOP:
  	return put_user(fore200e->loop_mode, (int __user *)arg) ? -EFAULT : 0;
  
      case ATM_QUERYLOOP:
  	return put_user(ATM_LM_LOC_PHY | ATM_LM_RMT_PHY, (int __user *)arg) ? -EFAULT : 0;
      }
  
      return -ENOSYS; /* not implemented */
  }
  
  
  static int
  fore200e_change_qos(struct atm_vcc* vcc,struct atm_qos* qos, int flags)
  {
      struct fore200e_vcc* fore200e_vcc = FORE200E_VCC(vcc);
      struct fore200e*     fore200e     = FORE200E_DEV(vcc->dev);
  
      if (!test_bit(ATM_VF_READY, &vcc->flags)) {
  	DPRINTK(1, "VC %d.%d.%d not ready for QoS change
  ", vcc->itf, vcc->vpi, vcc->vpi);
  	return -EINVAL;
      }
  
      DPRINTK(2, "change_qos %d.%d.%d, "
  	    "(tx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d; "
  	    "rx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d), flags = 0x%x
  "
  	    "available_cell_rate = %u",
  	    vcc->itf, vcc->vpi, vcc->vci,
  	    fore200e_traffic_class[ qos->txtp.traffic_class ],
  	    qos->txtp.min_pcr, qos->txtp.max_pcr, qos->txtp.max_cdv, qos->txtp.max_sdu,
  	    fore200e_traffic_class[ qos->rxtp.traffic_class ],
  	    qos->rxtp.min_pcr, qos->rxtp.max_pcr, qos->rxtp.max_cdv, qos->rxtp.max_sdu,
  	    flags, fore200e->available_cell_rate);
  
      if ((qos->txtp.traffic_class == ATM_CBR) && (qos->txtp.max_pcr > 0)) {
bfbf3c096   Matthias Kaehlcke   [ATM]: Use mutex ...
1948
  	mutex_lock(&fore200e->rate_mtx);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1949
  	if (fore200e->available_cell_rate + vcc->qos.txtp.max_pcr < qos->txtp.max_pcr) {
bfbf3c096   Matthias Kaehlcke   [ATM]: Use mutex ...
1950
  	    mutex_unlock(&fore200e->rate_mtx);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1951
1952
1953
1954
1955
  	    return -EAGAIN;
  	}
  
  	fore200e->available_cell_rate += vcc->qos.txtp.max_pcr;
  	fore200e->available_cell_rate -= qos->txtp.max_pcr;
bfbf3c096   Matthias Kaehlcke   [ATM]: Use mutex ...
1956
  	mutex_unlock(&fore200e->rate_mtx);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
  	
  	memcpy(&vcc->qos, qos, sizeof(struct atm_qos));
  	
  	/* update rate control parameters */
  	fore200e_rate_ctrl(qos, &fore200e_vcc->rate);
  
  	set_bit(ATM_VF_HASQOS, &vcc->flags);
  
  	return 0;
      }
      
      return -EINVAL;
  }
      
6c44512d0   Greg Kroah-Hartman   Drivers: atm: rem...
1971
  static int fore200e_irq_request(struct fore200e *fore200e)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1972
  {
dace14537   Thomas Gleixner   [PATCH] irq-flags...
1973
      if (request_irq(fore200e->irq, fore200e_interrupt, IRQF_SHARED, fore200e->name, fore200e->atm_dev) < 0) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
  
  	printk(FORE200E "unable to reserve IRQ %s for device %s
  ",
  	       fore200e_irq_itoa(fore200e->irq), fore200e->name);
  	return -EBUSY;
      }
  
      printk(FORE200E "IRQ %s reserved for device %s
  ",
  	   fore200e_irq_itoa(fore200e->irq), fore200e->name);
  
  #ifdef FORE200E_USE_TASKLET
      tasklet_init(&fore200e->tx_tasklet, fore200e_tx_tasklet, (unsigned long)fore200e);
      tasklet_init(&fore200e->rx_tasklet, fore200e_rx_tasklet, (unsigned long)fore200e);
  #endif
  
      fore200e->state = FORE200E_STATE_IRQ;
      return 0;
  }
6c44512d0   Greg Kroah-Hartman   Drivers: atm: rem...
1993
  static int fore200e_get_esi(struct fore200e *fore200e)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1994
  {
0e21b2258   Christoph Hellwig   fore200e: don't u...
1995
      struct prom_data* prom = kzalloc(sizeof(struct prom_data), GFP_KERNEL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1996
1997
1998
1999
2000
2001
2002
      int ok, i;
  
      if (!prom)
  	return -ENOMEM;
  
      ok = fore200e->bus->prom_read(fore200e, prom);
      if (ok < 0) {
1f8a5fb80   Adrian Bunk   [ATM] drivers/atm...
2003
  	kfree(prom);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2004
2005
2006
  	return -EBUSY;
      }
  	
3008ab36e   hartleys   drivers/atm/fore2...
2007
2008
      printk(FORE200E "device %s, rev. %c, S/N: %d, ESI: %pM
  ",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2009
2010
  	   fore200e->name, 
  	   (prom->hw_revision & 0xFF) + '@',    /* probably meaningless with SBA boards */
3008ab36e   hartleys   drivers/atm/fore2...
2011
  	   prom->serial_number & 0xFFFF, &prom->mac_addr[2]);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2012
2013
2014
2015
2016
  	
      for (i = 0; i < ESI_LEN; i++) {
  	fore200e->esi[ i ] = fore200e->atm_dev->esi[ i ] = prom->mac_addr[ i + 2 ];
      }
      
1f8a5fb80   Adrian Bunk   [ATM] drivers/atm...
2017
      kfree(prom);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2018
2019
2020
  
      return 0;
  }
6c44512d0   Greg Kroah-Hartman   Drivers: atm: rem...
2021
  static int fore200e_alloc_rx_buf(struct fore200e *fore200e)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
  {
      int scheme, magn, nbr, size, i;
  
      struct host_bsq* bsq;
      struct buffer*   buffer;
  
      for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
  	for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
  
  	    bsq = &fore200e->host_bsq[ scheme ][ magn ];
  
  	    nbr  = fore200e_rx_buf_nbr[ scheme ][ magn ];
  	    size = fore200e_rx_buf_size[ scheme ][ magn ];
  
  	    DPRINTK(2, "rx buffers %d / %d are being allocated
  ", scheme, magn);
  
  	    /* allocate the array of receive buffers */
6396bb221   Kees Cook   treewide: kzalloc...
2040
2041
  	    buffer = bsq->buffer = kcalloc(nbr, sizeof(struct buffer),
                                             GFP_KERNEL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
  
  	    if (buffer == NULL)
  		return -ENOMEM;
  
  	    bsq->freebuf = NULL;
  
  	    for (i = 0; i < nbr; i++) {
  
  		buffer[ i ].scheme = scheme;
  		buffer[ i ].magn   = magn;
  #ifdef FORE200E_BSQ_DEBUG
  		buffer[ i ].index  = i;
  		buffer[ i ].supplied = 0;
  #endif
  
  		/* allocate the receive buffer body */
  		if (fore200e_chunk_alloc(fore200e,
  					 &buffer[ i ].data, size, fore200e->bus->buffer_alignment,
  					 DMA_FROM_DEVICE) < 0) {
  		    
  		    while (i > 0)
  			fore200e_chunk_free(fore200e, &buffer[ --i ].data);
1f8a5fb80   Adrian Bunk   [ATM] drivers/atm...
2064
  		    kfree(buffer);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
  		    
  		    return -ENOMEM;
  		}
  
  		/* insert the buffer into the free buffer list */
  		buffer[ i ].next = bsq->freebuf;
  		bsq->freebuf = &buffer[ i ];
  	    }
  	    /* all the buffers are free, initially */
  	    bsq->freebuf_count = nbr;
  
  #ifdef FORE200E_BSQ_DEBUG
  	    bsq_audit(3, bsq, scheme, magn);
  #endif
  	}
      }
  
      fore200e->state = FORE200E_STATE_ALLOC_BUF;
      return 0;
  }
6c44512d0   Greg Kroah-Hartman   Drivers: atm: rem...
2085
  static int fore200e_init_bs_queue(struct fore200e *fore200e)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
  {
      int scheme, magn, i;
  
      struct host_bsq*     bsq;
      struct cp_bsq_entry __iomem * cp_entry;
  
      for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
  	for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
  
  	    DPRINTK(2, "buffer supply queue %d / %d is being initialized
  ", scheme, magn);
  
  	    bsq = &fore200e->host_bsq[ scheme ][ magn ];
  
  	    /* allocate and align the array of status words */
1335d6fd6   Christoph Hellwig   fore200e: devirtu...
2101
  	    if (fore200e_dma_chunk_alloc(fore200e,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2102
2103
2104
2105
2106
2107
2108
2109
  					       &bsq->status,
  					       sizeof(enum status), 
  					       QUEUE_SIZE_BS,
  					       fore200e->bus->status_alignment) < 0) {
  		return -ENOMEM;
  	    }
  
  	    /* allocate and align the array of receive buffer descriptors */
1335d6fd6   Christoph Hellwig   fore200e: devirtu...
2110
  	    if (fore200e_dma_chunk_alloc(fore200e,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2111
2112
2113
2114
2115
  					       &bsq->rbd_block,
  					       sizeof(struct rbd_block),
  					       QUEUE_SIZE_BS,
  					       fore200e->bus->descr_alignment) < 0) {
  		
1335d6fd6   Christoph Hellwig   fore200e: devirtu...
2116
  		fore200e_dma_chunk_free(fore200e, &bsq->status);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
  		return -ENOMEM;
  	    }
  	    
  	    /* get the base address of the cp resident buffer supply queue entries */
  	    cp_entry = fore200e->virt_base + 
  		       fore200e->bus->read(&fore200e->cp_queues->cp_bsq[ scheme ][ magn ]);
  	    
  	    /* fill the host resident and cp resident buffer supply queue entries */
  	    for (i = 0; i < QUEUE_SIZE_BS; i++) {
  		
  		bsq->host_entry[ i ].status = 
  		                     FORE200E_INDEX(bsq->status.align_addr, enum status, i);
  	        bsq->host_entry[ i ].rbd_block =
  		                     FORE200E_INDEX(bsq->rbd_block.align_addr, struct rbd_block, i);
  		bsq->host_entry[ i ].rbd_block_dma =
  		                     FORE200E_DMA_INDEX(bsq->rbd_block.dma_addr, struct rbd_block, i);
  		bsq->host_entry[ i ].cp_entry = &cp_entry[ i ];
  		
  		*bsq->host_entry[ i ].status = STATUS_FREE;
  		
  		fore200e->bus->write(FORE200E_DMA_INDEX(bsq->status.dma_addr, enum status, i), 
  				     &cp_entry[ i ].status_haddr);
  	    }
  	}
      }
  
      fore200e->state = FORE200E_STATE_INIT_BSQ;
      return 0;
  }
6c44512d0   Greg Kroah-Hartman   Drivers: atm: rem...
2146
  static int fore200e_init_rx_queue(struct fore200e *fore200e)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2147
2148
2149
2150
2151
2152
2153
2154
2155
  {
      struct host_rxq*     rxq =  &fore200e->host_rxq;
      struct cp_rxq_entry __iomem * cp_entry;
      int i;
  
      DPRINTK(2, "receive queue is being initialized
  ");
  
      /* allocate and align the array of status words */
1335d6fd6   Christoph Hellwig   fore200e: devirtu...
2156
      if (fore200e_dma_chunk_alloc(fore200e,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2157
2158
2159
2160
2161
2162
2163
2164
  				       &rxq->status,
  				       sizeof(enum status), 
  				       QUEUE_SIZE_RX,
  				       fore200e->bus->status_alignment) < 0) {
  	return -ENOMEM;
      }
  
      /* allocate and align the array of receive PDU descriptors */
1335d6fd6   Christoph Hellwig   fore200e: devirtu...
2165
      if (fore200e_dma_chunk_alloc(fore200e,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2166
2167
2168
2169
2170
  				       &rxq->rpd,
  				       sizeof(struct rpd), 
  				       QUEUE_SIZE_RX,
  				       fore200e->bus->descr_alignment) < 0) {
  	
1335d6fd6   Christoph Hellwig   fore200e: devirtu...
2171
  	fore200e_dma_chunk_free(fore200e, &rxq->status);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
  	return -ENOMEM;
      }
  
      /* get the base address of the cp resident rx queue entries */
      cp_entry = fore200e->virt_base + fore200e->bus->read(&fore200e->cp_queues->cp_rxq);
  
      /* fill the host resident and cp resident rx entries */
      for (i=0; i < QUEUE_SIZE_RX; i++) {
  	
  	rxq->host_entry[ i ].status = 
  	                     FORE200E_INDEX(rxq->status.align_addr, enum status, i);
  	rxq->host_entry[ i ].rpd = 
  	                     FORE200E_INDEX(rxq->rpd.align_addr, struct rpd, i);
  	rxq->host_entry[ i ].rpd_dma = 
  	                     FORE200E_DMA_INDEX(rxq->rpd.dma_addr, struct rpd, i);
  	rxq->host_entry[ i ].cp_entry = &cp_entry[ i ];
  
  	*rxq->host_entry[ i ].status = STATUS_FREE;
  
  	fore200e->bus->write(FORE200E_DMA_INDEX(rxq->status.dma_addr, enum status, i), 
  			     &cp_entry[ i ].status_haddr);
  
  	fore200e->bus->write(FORE200E_DMA_INDEX(rxq->rpd.dma_addr, struct rpd, i),
  			     &cp_entry[ i ].rpd_haddr);
      }
  
      /* set the head entry of the queue */
      rxq->head = 0;
  
      fore200e->state = FORE200E_STATE_INIT_RXQ;
      return 0;
  }
6c44512d0   Greg Kroah-Hartman   Drivers: atm: rem...
2204
  static int fore200e_init_tx_queue(struct fore200e *fore200e)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2205
2206
2207
2208
2209
2210
2211
2212
2213
  {
      struct host_txq*     txq =  &fore200e->host_txq;
      struct cp_txq_entry __iomem * cp_entry;
      int i;
  
      DPRINTK(2, "transmit queue is being initialized
  ");
  
      /* allocate and align the array of status words */
1335d6fd6   Christoph Hellwig   fore200e: devirtu...
2214
      if (fore200e_dma_chunk_alloc(fore200e,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2215
2216
2217
2218
2219
2220
2221
2222
  				       &txq->status,
  				       sizeof(enum status), 
  				       QUEUE_SIZE_TX,
  				       fore200e->bus->status_alignment) < 0) {
  	return -ENOMEM;
      }
  
      /* allocate and align the array of transmit PDU descriptors */
1335d6fd6   Christoph Hellwig   fore200e: devirtu...
2223
      if (fore200e_dma_chunk_alloc(fore200e,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2224
2225
2226
2227
2228
  				       &txq->tpd,
  				       sizeof(struct tpd), 
  				       QUEUE_SIZE_TX,
  				       fore200e->bus->descr_alignment) < 0) {
  	
1335d6fd6   Christoph Hellwig   fore200e: devirtu...
2229
  	fore200e_dma_chunk_free(fore200e, &txq->status);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
  	return -ENOMEM;
      }
  
      /* get the base address of the cp resident tx queue entries */
      cp_entry = fore200e->virt_base + fore200e->bus->read(&fore200e->cp_queues->cp_txq);
  
      /* fill the host resident and cp resident tx entries */
      for (i=0; i < QUEUE_SIZE_TX; i++) {
  	
  	txq->host_entry[ i ].status = 
  	                     FORE200E_INDEX(txq->status.align_addr, enum status, i);
  	txq->host_entry[ i ].tpd = 
  	                     FORE200E_INDEX(txq->tpd.align_addr, struct tpd, i);
  	txq->host_entry[ i ].tpd_dma  = 
                               FORE200E_DMA_INDEX(txq->tpd.dma_addr, struct tpd, i);
  	txq->host_entry[ i ].cp_entry = &cp_entry[ i ];
  
  	*txq->host_entry[ i ].status = STATUS_FREE;
  	
  	fore200e->bus->write(FORE200E_DMA_INDEX(txq->status.dma_addr, enum status, i), 
  			     &cp_entry[ i ].status_haddr);
  	
          /* although there is a one-to-one mapping of tx queue entries and tpds,
  	   we do not write here the DMA (physical) base address of each tpd into
  	   the related cp resident entry, because the cp relies on this write
  	   operation to detect that a new pdu has been submitted for tx */
      }
  
      /* set the head and tail entries of the queue */
      txq->head = 0;
      txq->tail = 0;
  
      fore200e->state = FORE200E_STATE_INIT_TXQ;
      return 0;
  }
6c44512d0   Greg Kroah-Hartman   Drivers: atm: rem...
2265
  static int fore200e_init_cmd_queue(struct fore200e *fore200e)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2266
2267
2268
2269
2270
2271
2272
2273
2274
  {
      struct host_cmdq*     cmdq =  &fore200e->host_cmdq;
      struct cp_cmdq_entry __iomem * cp_entry;
      int i;
  
      DPRINTK(2, "command queue is being initialized
  ");
  
      /* allocate and align the array of status words */
1335d6fd6   Christoph Hellwig   fore200e: devirtu...
2275
      if (fore200e_dma_chunk_alloc(fore200e,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
  				       &cmdq->status,
  				       sizeof(enum status), 
  				       QUEUE_SIZE_CMD,
  				       fore200e->bus->status_alignment) < 0) {
  	return -ENOMEM;
      }
      
      /* get the base address of the cp resident cmd queue entries */
      cp_entry = fore200e->virt_base + fore200e->bus->read(&fore200e->cp_queues->cp_cmdq);
  
      /* fill the host resident and cp resident cmd entries */
      for (i=0; i < QUEUE_SIZE_CMD; i++) {
  	
  	cmdq->host_entry[ i ].status   = 
                                FORE200E_INDEX(cmdq->status.align_addr, enum status, i);
  	cmdq->host_entry[ i ].cp_entry = &cp_entry[ i ];
  
  	*cmdq->host_entry[ i ].status = STATUS_FREE;
  
  	fore200e->bus->write(FORE200E_DMA_INDEX(cmdq->status.dma_addr, enum status, i), 
                               &cp_entry[ i ].status_haddr);
      }
  
      /* set the head entry of the queue */
      cmdq->head = 0;
  
      fore200e->state = FORE200E_STATE_INIT_CMDQ;
      return 0;
  }
6c44512d0   Greg Kroah-Hartman   Drivers: atm: rem...
2305
2306
2307
2308
  static void fore200e_param_bs_queue(struct fore200e *fore200e,
  				    enum buffer_scheme scheme,
  				    enum buffer_magn magn, int queue_length,
  				    int pool_size, int supply_blksize)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2309
2310
2311
2312
2313
2314
2315
2316
  {
      struct bs_spec __iomem * bs_spec = &fore200e->cp_queues->init.bs_spec[ scheme ][ magn ];
  
      fore200e->bus->write(queue_length,                           &bs_spec->queue_length);
      fore200e->bus->write(fore200e_rx_buf_size[ scheme ][ magn ], &bs_spec->buffer_size);
      fore200e->bus->write(pool_size,                              &bs_spec->pool_size);
      fore200e->bus->write(supply_blksize,                         &bs_spec->supply_blksize);
  }
6c44512d0   Greg Kroah-Hartman   Drivers: atm: rem...
2317
  static int fore200e_initialize(struct fore200e *fore200e)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2318
2319
2320
2321
2322
2323
  {
      struct cp_queues __iomem * cpq;
      int               ok, scheme, magn;
  
      DPRINTK(2, "device %s being initialized
  ", fore200e->name);
bfbf3c096   Matthias Kaehlcke   [ATM]: Use mutex ...
2324
      mutex_init(&fore200e->rate_mtx);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
      spin_lock_init(&fore200e->q_lock);
  
      cpq = fore200e->cp_queues = fore200e->virt_base + FORE200E_CP_QUEUES_OFFSET;
  
      /* enable cp to host interrupts */
      fore200e->bus->write(1, &cpq->imask);
  
      if (fore200e->bus->irq_enable)
  	fore200e->bus->irq_enable(fore200e);
      
      fore200e->bus->write(NBR_CONNECT, &cpq->init.num_connect);
  
      fore200e->bus->write(QUEUE_SIZE_CMD, &cpq->init.cmd_queue_len);
      fore200e->bus->write(QUEUE_SIZE_RX,  &cpq->init.rx_queue_len);
      fore200e->bus->write(QUEUE_SIZE_TX,  &cpq->init.tx_queue_len);
  
      fore200e->bus->write(RSD_EXTENSION,  &cpq->init.rsd_extension);
      fore200e->bus->write(TSD_EXTENSION,  &cpq->init.tsd_extension);
  
      for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++)
  	for (magn = 0; magn < BUFFER_MAGN_NBR; magn++)
  	    fore200e_param_bs_queue(fore200e, scheme, magn,
  				    QUEUE_SIZE_BS, 
  				    fore200e_rx_buf_nbr[ scheme ][ magn ],
  				    RBD_BLK_SIZE);
  
      /* issue the initialize command */
      fore200e->bus->write(STATUS_PENDING,    &cpq->init.status);
      fore200e->bus->write(OPCODE_INITIALIZE, &cpq->init.opcode);
  
      ok = fore200e_io_poll(fore200e, &cpq->init.status, STATUS_COMPLETE, 3000);
      if (ok == 0) {
  	printk(FORE200E "device %s initialization failed
  ", fore200e->name);
  	return -ENODEV;
      }
  
      printk(FORE200E "device %s initialized
  ", fore200e->name);
  
      fore200e->state = FORE200E_STATE_INITIALIZE;
      return 0;
  }
6c44512d0   Greg Kroah-Hartman   Drivers: atm: rem...
2368
  static void fore200e_monitor_putc(struct fore200e *fore200e, char c)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2369
2370
2371
2372
2373
2374
2375
2376
  {
      struct cp_monitor __iomem * monitor = fore200e->cp_monitor;
  
  #if 0
      printk("%c", c);
  #endif
      fore200e->bus->write(((u32) c) | FORE200E_CP_MONITOR_UART_AVAIL, &monitor->soft_uart.send);
  }
6c44512d0   Greg Kroah-Hartman   Drivers: atm: rem...
2377
  static int fore200e_monitor_getc(struct fore200e *fore200e)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
  {
      struct cp_monitor __iomem * monitor = fore200e->cp_monitor;
      unsigned long      timeout = jiffies + msecs_to_jiffies(50);
      int                c;
  
      while (time_before(jiffies, timeout)) {
  
  	c = (int) fore200e->bus->read(&monitor->soft_uart.recv);
  
  	if (c & FORE200E_CP_MONITOR_UART_AVAIL) {
  
  	    fore200e->bus->write(FORE200E_CP_MONITOR_UART_FREE, &monitor->soft_uart.recv);
  #if 0
  	    printk("%c", c & 0xFF);
  #endif
  	    return c & 0xFF;
  	}
      }
  
      return -1;
  }
6c44512d0   Greg Kroah-Hartman   Drivers: atm: rem...
2399
  static void fore200e_monitor_puts(struct fore200e *fore200e, char *str)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
  {
      while (*str) {
  
  	/* the i960 monitor doesn't accept any new character if it has something to say */
  	while (fore200e_monitor_getc(fore200e) >= 0);
  	
  	fore200e_monitor_putc(fore200e, *str++);
      }
  
      while (fore200e_monitor_getc(fore200e) >= 0);
  }
e92481f95   Chas Williams   atm: [fore200e] c...
2411
2412
2413
2414
2415
  #ifdef __LITTLE_ENDIAN
  #define FW_EXT ".bin"
  #else
  #define FW_EXT "_ecd.bin2"
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2416

6c44512d0   Greg Kroah-Hartman   Drivers: atm: rem...
2417
  static int fore200e_load_and_start_fw(struct fore200e *fore200e)
e92481f95   Chas Williams   atm: [fore200e] c...
2418
2419
  {
      const struct firmware *firmware;
b65b24d42   LABBE Corentin   atm: fore200e: Do...
2420
      const struct fw_header *fw_header;
6f75a9b64   Chas Williams   atm: [fore200e] u...
2421
2422
      const __le32 *fw_data;
      u32 fw_size;
e92481f95   Chas Williams   atm: [fore200e] c...
2423
2424
      u32 __iomem *load_addr;
      char buf[48];
aff9d262f   Christoph Hellwig   fore200e: store a...
2425
      int err;
e92481f95   Chas Williams   atm: [fore200e] c...
2426
2427
  
      sprintf(buf, "%s%s", fore200e->bus->proc_name, FW_EXT);
aff9d262f   Christoph Hellwig   fore200e: store a...
2428
      if ((err = request_firmware(&firmware, buf, fore200e->dev)) < 0) {
fcffd0d8b   Meelis Roos   fore200: fix oops...
2429
2430
  	printk(FORE200E "problem loading firmware image %s
  ", fore200e->bus->model_name);
e92481f95   Chas Williams   atm: [fore200e] c...
2431
2432
  	return err;
      }
b65b24d42   LABBE Corentin   atm: fore200e: Do...
2433
      fw_data = (const __le32 *)firmware->data;
e92481f95   Chas Williams   atm: [fore200e] c...
2434
      fw_size = firmware->size / sizeof(u32);
b65b24d42   LABBE Corentin   atm: fore200e: Do...
2435
      fw_header = (const struct fw_header *)firmware->data;
e92481f95   Chas Williams   atm: [fore200e] c...
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
      load_addr = fore200e->virt_base + le32_to_cpu(fw_header->load_offset);
  
      DPRINTK(2, "device %s firmware being loaded at 0x%p (%d words)
  ",
  	    fore200e->name, load_addr, fw_size);
  
      if (le32_to_cpu(fw_header->magic) != FW_HEADER_MAGIC) {
  	printk(FORE200E "corrupted %s firmware image
  ", fore200e->bus->model_name);
  	goto release;
      }
  
      for (; fw_size--; fw_data++, load_addr++)
  	fore200e->bus->write(le32_to_cpu(*fw_data), load_addr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2450
2451
2452
2453
2454
2455
2456
2457
  
      DPRINTK(2, "device %s firmware being started
  ", fore200e->name);
  
  #if defined(__sparc_v9__)
      /* reported to be required by SBA cards on some sparc64 hosts */
      fore200e_spin(100);
  #endif
e92481f95   Chas Williams   atm: [fore200e] c...
2458
2459
      sprintf(buf, "\rgo %x\r", le32_to_cpu(fw_header->start_offset));
      fore200e_monitor_puts(fore200e, buf);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2460

e92481f95   Chas Williams   atm: [fore200e] c...
2461
      if (fore200e_io_poll(fore200e, &fore200e->cp_monitor->bstat, BSTAT_CP_RUNNING, 1000) == 0) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2462
2463
  	printk(FORE200E "device %s firmware didn't start
  ", fore200e->name);
e92481f95   Chas Williams   atm: [fore200e] c...
2464
  	goto release;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2465
2466
2467
2468
2469
2470
      }
  
      printk(FORE200E "device %s firmware started
  ", fore200e->name);
  
      fore200e->state = FORE200E_STATE_START_FW;
e92481f95   Chas Williams   atm: [fore200e] c...
2471
      err = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2472

e92481f95   Chas Williams   atm: [fore200e] c...
2473
2474
2475
  release:
      release_firmware(firmware);
      return err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2476
  }
6c44512d0   Greg Kroah-Hartman   Drivers: atm: rem...
2477
  static int fore200e_register(struct fore200e *fore200e, struct device *parent)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2478
2479
2480
2481
2482
  {
      struct atm_dev* atm_dev;
  
      DPRINTK(2, "device %s being registered
  ", fore200e->name);
d9ca676bc   Dan Williams   atm: correct sysf...
2483
2484
      atm_dev = atm_dev_register(fore200e->bus->proc_name, parent, &fore200e_ops,
                                 -1, NULL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
      if (atm_dev == NULL) {
  	printk(FORE200E "unable to register device %s
  ", fore200e->name);
  	return -ENODEV;
      }
  
      atm_dev->dev_data = fore200e;
      fore200e->atm_dev = atm_dev;
  
      atm_dev->ci_range.vpi_bits = FORE200E_VPI_BITS;
      atm_dev->ci_range.vci_bits = FORE200E_VCI_BITS;
  
      fore200e->available_cell_rate = ATM_OC3_PCR;
  
      fore200e->state = FORE200E_STATE_REGISTER;
      return 0;
  }
6c44512d0   Greg Kroah-Hartman   Drivers: atm: rem...
2502
  static int fore200e_init(struct fore200e *fore200e, struct device *parent)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2503
  {
d9ca676bc   Dan Williams   atm: correct sysf...
2504
      if (fore200e_register(fore200e, parent) < 0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
  	return -ENODEV;
      
      if (fore200e->bus->configure(fore200e) < 0)
  	return -ENODEV;
  
      if (fore200e->bus->map(fore200e) < 0)
  	return -ENODEV;
  
      if (fore200e_reset(fore200e, 1) < 0)
  	return -ENODEV;
e92481f95   Chas Williams   atm: [fore200e] c...
2515
      if (fore200e_load_and_start_fw(fore200e) < 0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
  	return -ENODEV;
  
      if (fore200e_initialize(fore200e) < 0)
  	return -ENODEV;
  
      if (fore200e_init_cmd_queue(fore200e) < 0)
  	return -ENOMEM;
  
      if (fore200e_init_tx_queue(fore200e) < 0)
  	return -ENOMEM;
  
      if (fore200e_init_rx_queue(fore200e) < 0)
  	return -ENOMEM;
  
      if (fore200e_init_bs_queue(fore200e) < 0)
  	return -ENOMEM;
  
      if (fore200e_alloc_rx_buf(fore200e) < 0)
  	return -ENOMEM;
  
      if (fore200e_get_esi(fore200e) < 0)
  	return -EIO;
  
      if (fore200e_irq_request(fore200e) < 0)
  	return -EBUSY;
  
      fore200e_supply(fore200e);
c027f5f99   Sam Ravnborg   [ATM]: [fore200e]...
2543

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2544
2545
2546
2547
      /* all done, board initialization is now complete */
      fore200e->state = FORE200E_STATE_COMPLETE;
      return 0;
  }
826b6cfcd   David S. Miller   fore200e: Convert...
2548
  #ifdef CONFIG_SBUS
b1608d69c   Grant Likely   drivercore: rever...
2549
  static const struct of_device_id fore200e_sba_match[];
6c44512d0   Greg Kroah-Hartman   Drivers: atm: rem...
2550
  static int fore200e_sba_probe(struct platform_device *op)
826b6cfcd   David S. Miller   fore200e: Convert...
2551
  {
b1608d69c   Grant Likely   drivercore: rever...
2552
  	const struct of_device_id *match;
826b6cfcd   David S. Miller   fore200e: Convert...
2553
2554
2555
  	struct fore200e *fore200e;
  	static int index = 0;
  	int err;
b1608d69c   Grant Likely   drivercore: rever...
2556
2557
  	match = of_match_device(fore200e_sba_match, &op->dev);
  	if (!match)
1c48a5c93   Grant Likely   dt: Eliminate of_...
2558
  		return -EINVAL;
1c48a5c93   Grant Likely   dt: Eliminate of_...
2559

826b6cfcd   David S. Miller   fore200e: Convert...
2560
2561
2562
  	fore200e = kzalloc(sizeof(struct fore200e), GFP_KERNEL);
  	if (!fore200e)
  		return -ENOMEM;
0efe55238   Christoph Hellwig   fore200e: simplif...
2563
  	fore200e->bus = &fore200e_sbus_ops;
aff9d262f   Christoph Hellwig   fore200e: store a...
2564
  	fore200e->dev = &op->dev;
1636f8ac2   Grant Likely   sparc/of: Move of...
2565
  	fore200e->irq = op->archdata.irqs[0];
826b6cfcd   David S. Miller   fore200e: Convert...
2566
  	fore200e->phys_base = op->resource[0].start;
0efe55238   Christoph Hellwig   fore200e: simplif...
2567
  	sprintf(fore200e->name, "SBA-200E-%d", index);
826b6cfcd   David S. Miller   fore200e: Convert...
2568

d9ca676bc   Dan Williams   atm: correct sysf...
2569
  	err = fore200e_init(fore200e, &op->dev);
826b6cfcd   David S. Miller   fore200e: Convert...
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
  	if (err < 0) {
  		fore200e_shutdown(fore200e);
  		kfree(fore200e);
  		return err;
  	}
  
  	index++;
  	dev_set_drvdata(&op->dev, fore200e);
  
  	return 0;
  }
6c44512d0   Greg Kroah-Hartman   Drivers: atm: rem...
2581
  static int fore200e_sba_remove(struct platform_device *op)
826b6cfcd   David S. Miller   fore200e: Convert...
2582
2583
2584
2585
2586
2587
2588
2589
  {
  	struct fore200e *fore200e = dev_get_drvdata(&op->dev);
  
  	fore200e_shutdown(fore200e);
  	kfree(fore200e);
  
  	return 0;
  }
fd098316e   David S. Miller   sparc: Annotate o...
2590
  static const struct of_device_id fore200e_sba_match[] = {
826b6cfcd   David S. Miller   fore200e: Convert...
2591
2592
  	{
  		.name = SBA200E_PROM_NAME,
826b6cfcd   David S. Miller   fore200e: Convert...
2593
2594
2595
2596
  	},
  	{},
  };
  MODULE_DEVICE_TABLE(of, fore200e_sba_match);
1c48a5c93   Grant Likely   dt: Eliminate of_...
2597
  static struct platform_driver fore200e_sba_driver = {
4018294b5   Grant Likely   of: Remove duplic...
2598
2599
  	.driver = {
  		.name = "fore_200e",
4018294b5   Grant Likely   of: Remove duplic...
2600
2601
  		.of_match_table = fore200e_sba_match,
  	},
826b6cfcd   David S. Miller   fore200e: Convert...
2602
  	.probe		= fore200e_sba_probe,
6c44512d0   Greg Kroah-Hartman   Drivers: atm: rem...
2603
  	.remove		= fore200e_sba_remove,
826b6cfcd   David S. Miller   fore200e: Convert...
2604
2605
  };
  #endif
e92481f95   Chas Williams   atm: [fore200e] c...
2606
  #ifdef CONFIG_PCI
6c44512d0   Greg Kroah-Hartman   Drivers: atm: rem...
2607
2608
  static int fore200e_pca_detect(struct pci_dev *pci_dev,
  			       const struct pci_device_id *pci_ent)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2609
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2610
2611
2612
2613
2614
2615
2616
2617
      struct fore200e* fore200e;
      int err = 0;
      static int index = 0;
  
      if (pci_enable_device(pci_dev)) {
  	err = -EINVAL;
  	goto out;
      }
ede58ef28   chas williams - CONTRACTOR   atm: remove depre...
2618
2619
2620
2621
2622
  
      if (dma_set_mask_and_coherent(&pci_dev->dev, DMA_BIT_MASK(32))) {
  	err = -EINVAL;
  	goto out;
      }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2623
      
1f8a5fb80   Adrian Bunk   [ATM] drivers/atm...
2624
      fore200e = kzalloc(sizeof(struct fore200e), GFP_KERNEL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2625
2626
2627
2628
      if (fore200e == NULL) {
  	err = -ENOMEM;
  	goto out_disable;
      }
0efe55238   Christoph Hellwig   fore200e: simplif...
2629
      fore200e->bus       = &fore200e_pci_ops;
aff9d262f   Christoph Hellwig   fore200e: store a...
2630
      fore200e->dev	= &pci_dev->dev;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2631
2632
      fore200e->irq       = pci_dev->irq;
      fore200e->phys_base = pci_resource_start(pci_dev, 0);
0efe55238   Christoph Hellwig   fore200e: simplif...
2633
      sprintf(fore200e->name, "PCA-200E-%d", index - 1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2634
2635
  
      pci_set_master(pci_dev);
0efe55238   Christoph Hellwig   fore200e: simplif...
2636
2637
      printk(FORE200E "device PCA-200E found at 0x%lx, IRQ %s
  ",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2638
  	   fore200e->phys_base, fore200e_irq_itoa(fore200e->irq));
0efe55238   Christoph Hellwig   fore200e: simplif...
2639
      sprintf(fore200e->name, "PCA-200E-%d", index);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2640

d9ca676bc   Dan Williams   atm: correct sysf...
2641
      err = fore200e_init(fore200e, &pci_dev->dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
      if (err < 0) {
  	fore200e_shutdown(fore200e);
  	goto out_free;
      }
  
      ++index;
      pci_set_drvdata(pci_dev, fore200e);
  
  out:
      return err;
  
  out_free:
      kfree(fore200e);
  out_disable:
      pci_disable_device(pci_dev);
      goto out;
  }
6c44512d0   Greg Kroah-Hartman   Drivers: atm: rem...
2659
  static void fore200e_pca_remove_one(struct pci_dev *pci_dev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2660
2661
2662
2663
  {
      struct fore200e *fore200e;
  
      fore200e = pci_get_drvdata(pci_dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2664
2665
2666
2667
      fore200e_shutdown(fore200e);
      kfree(fore200e);
      pci_disable_device(pci_dev);
  }
d5c5665d1   Arvind Yadav   atm: fore200e: co...
2668
  static const struct pci_device_id fore200e_pca_tbl[] = {
0efe55238   Christoph Hellwig   fore200e: simplif...
2669
      { PCI_VENDOR_ID_FORE, PCI_DEVICE_ID_FORE_PCA200E, PCI_ANY_ID, PCI_ANY_ID },
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2670
2671
2672
2673
2674
2675
2676
2677
      { 0, }
  };
  
  MODULE_DEVICE_TABLE(pci, fore200e_pca_tbl);
  
  static struct pci_driver fore200e_pca_driver = {
      .name =     "fore_200e",
      .probe =    fore200e_pca_detect,
6c44512d0   Greg Kroah-Hartman   Drivers: atm: rem...
2678
      .remove =   fore200e_pca_remove_one,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2679
2680
2681
      .id_table = fore200e_pca_tbl,
  };
  #endif
826b6cfcd   David S. Miller   fore200e: Convert...
2682
  static int __init fore200e_module_init(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2683
  {
74e8ce34a   Rickard Strandqvist   atm: fore200e.c: ...
2684
  	int err = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2685

826b6cfcd   David S. Miller   fore200e: Convert...
2686
2687
  	printk(FORE200E "FORE Systems 200E-series ATM driver - version " FORE200E_VERSION "
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2688

826b6cfcd   David S. Miller   fore200e: Convert...
2689
  #ifdef CONFIG_SBUS
1c48a5c93   Grant Likely   dt: Eliminate of_...
2690
  	err = platform_driver_register(&fore200e_sba_driver);
826b6cfcd   David S. Miller   fore200e: Convert...
2691
2692
2693
  	if (err)
  		return err;
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2694

e92481f95   Chas Williams   atm: [fore200e] c...
2695
  #ifdef CONFIG_PCI
826b6cfcd   David S. Miller   fore200e: Convert...
2696
  	err = pci_register_driver(&fore200e_pca_driver);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2697
  #endif
826b6cfcd   David S. Miller   fore200e: Convert...
2698
2699
  #ifdef CONFIG_SBUS
  	if (err)
1c48a5c93   Grant Likely   dt: Eliminate of_...
2700
  		platform_driver_unregister(&fore200e_sba_driver);
826b6cfcd   David S. Miller   fore200e: Convert...
2701
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2702

826b6cfcd   David S. Miller   fore200e: Convert...
2703
  	return err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2704
  }
826b6cfcd   David S. Miller   fore200e: Convert...
2705
  static void __exit fore200e_module_cleanup(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2706
  {
e92481f95   Chas Williams   atm: [fore200e] c...
2707
  #ifdef CONFIG_PCI
826b6cfcd   David S. Miller   fore200e: Convert...
2708
2709
2710
  	pci_unregister_driver(&fore200e_pca_driver);
  #endif
  #ifdef CONFIG_SBUS
1c48a5c93   Grant Likely   dt: Eliminate of_...
2711
  	platform_driver_unregister(&fore200e_sba_driver);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2712
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2713
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
  static int
  fore200e_proc_read(struct atm_dev *dev, loff_t* pos, char* page)
  {
      struct fore200e*     fore200e  = FORE200E_DEV(dev);
      struct fore200e_vcc* fore200e_vcc;
      struct atm_vcc*      vcc;
      int                  i, len, left = *pos;
      unsigned long        flags;
  
      if (!left--) {
  
  	if (fore200e_getstats(fore200e) < 0)
  	    return -EIO;
  
  	len = sprintf(page,"
  "
  		       " device:
  "
  		       "   internal name:\t\t%s
  ", fore200e->name);
  
  	/* print bus-specific information */
  	if (fore200e->bus->proc_read)
  	    len += fore200e->bus->proc_read(fore200e, page + len);
  	
  	len += sprintf(page + len,
  		"   interrupt line:\t\t%s
  "
  		"   physical base address:\t0x%p
  "
  		"   virtual base address:\t0x%p
  "
3008ab36e   hartleys   drivers/atm/fore2...
2746
2747
  		"   factory address (ESI):\t%pM
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2748
2749
2750
2751
2752
2753
  		"   board serial number:\t\t%d
  
  ",
  		fore200e_irq_itoa(fore200e->irq),
  		(void*)fore200e->phys_base,
  		fore200e->virt_base,
3008ab36e   hartleys   drivers/atm/fore2...
2754
  		fore200e->esi,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
  		fore200e->esi[4] * 256 + fore200e->esi[5]);
  
  	return len;
      }
  
      if (!left--)
  	return sprintf(page,
  		       "   free small bufs, scheme 1:\t%d
  "
  		       "   free large bufs, scheme 1:\t%d
  "
  		       "   free small bufs, scheme 2:\t%d
  "
  		       "   free large bufs, scheme 2:\t%d
  ",
  		       fore200e->host_bsq[ BUFFER_SCHEME_ONE ][ BUFFER_MAGN_SMALL ].freebuf_count,
  		       fore200e->host_bsq[ BUFFER_SCHEME_ONE ][ BUFFER_MAGN_LARGE ].freebuf_count,
  		       fore200e->host_bsq[ BUFFER_SCHEME_TWO ][ BUFFER_MAGN_SMALL ].freebuf_count,
  		       fore200e->host_bsq[ BUFFER_SCHEME_TWO ][ BUFFER_MAGN_LARGE ].freebuf_count);
  
      if (!left--) {
  	u32 hb = fore200e->bus->read(&fore200e->cp_queues->heartbeat);
  
  	len = sprintf(page,"
  
  "
  		      " cell processor:
  "
  		      "   heartbeat state:\t\t");
  	
  	if (hb >> 16 != 0xDEAD)
  	    len += sprintf(page + len, "0x%08x
  ", hb);
  	else
  	    len += sprintf(page + len, "*** FATAL ERROR %04x ***
  ", hb & 0xFFFF);
  
  	return len;
      }
  
      if (!left--) {
  	static const char* media_name[] = {
  	    "unshielded twisted pair",
  	    "multimode optical fiber ST",
  	    "multimode optical fiber SC",
  	    "single-mode optical fiber ST",
  	    "single-mode optical fiber SC",
  	    "unknown"
  	};
  
  	static const char* oc3_mode[] = {
  	    "normal operation",
  	    "diagnostic loopback",
  	    "line loopback",
  	    "unknown"
  	};
  
  	u32 fw_release     = fore200e->bus->read(&fore200e->cp_queues->fw_release);
  	u32 mon960_release = fore200e->bus->read(&fore200e->cp_queues->mon960_release);
  	u32 oc3_revision   = fore200e->bus->read(&fore200e->cp_queues->oc3_revision);
  	u32 media_index    = FORE200E_MEDIA_INDEX(fore200e->bus->read(&fore200e->cp_queues->media_type));
  	u32 oc3_index;
e0c5567d0   roel kluin   atm: Cleanup redu...
2817
2818
  	if (media_index > 4)
  		media_index = 5;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
  	
  	switch (fore200e->loop_mode) {
  	    case ATM_LM_NONE:    oc3_index = 0;
  		                 break;
  	    case ATM_LM_LOC_PHY: oc3_index = 1;
  		                 break;
  	    case ATM_LM_RMT_PHY: oc3_index = 2;
  		                 break;
  	    default:             oc3_index = 3;
  	}
  
  	return sprintf(page,
  		       "   firmware release:\t\t%d.%d.%d
  "
  		       "   monitor release:\t\t%d.%d
  "
  		       "   media type:\t\t\t%s
  "
  		       "   OC-3 revision:\t\t0x%x
  "
                         "   OC-3 mode:\t\t\t%s",
  		       fw_release >> 16, fw_release << 16 >> 24,  fw_release << 24 >> 24,
  		       mon960_release >> 16, mon960_release << 16 >> 16,
  		       media_name[ media_index ],
  		       oc3_revision,
  		       oc3_mode[ oc3_index ]);
      }
  
      if (!left--) {
  	struct cp_monitor __iomem * cp_monitor = fore200e->cp_monitor;
  
  	return sprintf(page,
  		       "
  
  "
  		       " monitor:
  "
  		       "   version number:\t\t%d
  "
  		       "   boot status word:\t\t0x%08x
  ",
  		       fore200e->bus->read(&cp_monitor->mon_version),
  		       fore200e->bus->read(&cp_monitor->bstat));
      }
  
      if (!left--)
  	return sprintf(page,
  		       "
  "
  		       " device statistics:
  "
  		       "  4b5b:
  "
  		       "     crc_header_errors:\t\t%10u
  "
  		       "     framing_errors:\t\t%10u
  ",
63734a32a   Al Viro   fore2000 - fix mi...
2876
2877
  		       be32_to_cpu(fore200e->stats->phy.crc_header_errors),
  		       be32_to_cpu(fore200e->stats->phy.framing_errors));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
      
      if (!left--)
  	return sprintf(page, "
  "
  		       "  OC-3:
  "
  		       "     section_bip8_errors:\t%10u
  "
  		       "     path_bip8_errors:\t\t%10u
  "
  		       "     line_bip24_errors:\t\t%10u
  "
  		       "     line_febe_errors:\t\t%10u
  "
  		       "     path_febe_errors:\t\t%10u
  "
  		       "     corr_hcs_errors:\t\t%10u
  "
  		       "     ucorr_hcs_errors:\t\t%10u
  ",
63734a32a   Al Viro   fore2000 - fix mi...
2898
2899
2900
2901
2902
2903
2904
  		       be32_to_cpu(fore200e->stats->oc3.section_bip8_errors),
  		       be32_to_cpu(fore200e->stats->oc3.path_bip8_errors),
  		       be32_to_cpu(fore200e->stats->oc3.line_bip24_errors),
  		       be32_to_cpu(fore200e->stats->oc3.line_febe_errors),
  		       be32_to_cpu(fore200e->stats->oc3.path_febe_errors),
  		       be32_to_cpu(fore200e->stats->oc3.corr_hcs_errors),
  		       be32_to_cpu(fore200e->stats->oc3.ucorr_hcs_errors));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
  
      if (!left--)
  	return sprintf(page,"
  "
  		       "   ATM:\t\t\t\t     cells
  "
  		       "     TX:\t\t\t%10u
  "
  		       "     RX:\t\t\t%10u
  "
  		       "     vpi out of range:\t\t%10u
  "
  		       "     vpi no conn:\t\t%10u
  "
  		       "     vci out of range:\t\t%10u
  "
  		       "     vci no conn:\t\t%10u
  ",
63734a32a   Al Viro   fore2000 - fix mi...
2923
2924
2925
2926
2927
2928
  		       be32_to_cpu(fore200e->stats->atm.cells_transmitted),
  		       be32_to_cpu(fore200e->stats->atm.cells_received),
  		       be32_to_cpu(fore200e->stats->atm.vpi_bad_range),
  		       be32_to_cpu(fore200e->stats->atm.vpi_no_conn),
  		       be32_to_cpu(fore200e->stats->atm.vci_bad_range),
  		       be32_to_cpu(fore200e->stats->atm.vci_no_conn));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
      
      if (!left--)
  	return sprintf(page,"
  "
  		       "   AAL0:\t\t\t     cells
  "
  		       "     TX:\t\t\t%10u
  "
  		       "     RX:\t\t\t%10u
  "
  		       "     dropped:\t\t\t%10u
  ",
63734a32a   Al Viro   fore2000 - fix mi...
2941
2942
2943
  		       be32_to_cpu(fore200e->stats->aal0.cells_transmitted),
  		       be32_to_cpu(fore200e->stats->aal0.cells_received),
  		       be32_to_cpu(fore200e->stats->aal0.cells_dropped));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
      
      if (!left--)
  	return sprintf(page,"
  "
  		       "   AAL3/4:
  "
  		       "     SAR sublayer:\t\t     cells
  "
  		       "       TX:\t\t\t%10u
  "
  		       "       RX:\t\t\t%10u
  "
  		       "       dropped:\t\t\t%10u
  "
  		       "       CRC errors:\t\t%10u
  "
  		       "       protocol errors:\t\t%10u
  
  "
  		       "     CS  sublayer:\t\t      PDUs
  "
  		       "       TX:\t\t\t%10u
  "
  		       "       RX:\t\t\t%10u
  "
  		       "       dropped:\t\t\t%10u
  "
  		       "       protocol errors:\t\t%10u
  ",
63734a32a   Al Viro   fore2000 - fix mi...
2973
2974
2975
2976
2977
2978
2979
2980
2981
  		       be32_to_cpu(fore200e->stats->aal34.cells_transmitted),
  		       be32_to_cpu(fore200e->stats->aal34.cells_received),
  		       be32_to_cpu(fore200e->stats->aal34.cells_dropped),
  		       be32_to_cpu(fore200e->stats->aal34.cells_crc_errors),
  		       be32_to_cpu(fore200e->stats->aal34.cells_protocol_errors),
  		       be32_to_cpu(fore200e->stats->aal34.cspdus_transmitted),
  		       be32_to_cpu(fore200e->stats->aal34.cspdus_received),
  		       be32_to_cpu(fore200e->stats->aal34.cspdus_dropped),
  		       be32_to_cpu(fore200e->stats->aal34.cspdus_protocol_errors));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
      
      if (!left--)
  	return sprintf(page,"
  "
  		       "   AAL5:
  "
  		       "     SAR sublayer:\t\t     cells
  "
  		       "       TX:\t\t\t%10u
  "
  		       "       RX:\t\t\t%10u
  "
  		       "       dropped:\t\t\t%10u
  "
  		       "       congestions:\t\t%10u
  
  "
  		       "     CS  sublayer:\t\t      PDUs
  "
  		       "       TX:\t\t\t%10u
  "
  		       "       RX:\t\t\t%10u
  "
  		       "       dropped:\t\t\t%10u
  "
  		       "       CRC errors:\t\t%10u
  "
  		       "       protocol errors:\t\t%10u
  ",
63734a32a   Al Viro   fore2000 - fix mi...
3011
3012
3013
3014
3015
3016
3017
3018
3019
  		       be32_to_cpu(fore200e->stats->aal5.cells_transmitted),
  		       be32_to_cpu(fore200e->stats->aal5.cells_received),
  		       be32_to_cpu(fore200e->stats->aal5.cells_dropped),
  		       be32_to_cpu(fore200e->stats->aal5.congestion_experienced),
  		       be32_to_cpu(fore200e->stats->aal5.cspdus_transmitted),
  		       be32_to_cpu(fore200e->stats->aal5.cspdus_received),
  		       be32_to_cpu(fore200e->stats->aal5.cspdus_dropped),
  		       be32_to_cpu(fore200e->stats->aal5.cspdus_crc_errors),
  		       be32_to_cpu(fore200e->stats->aal5.cspdus_protocol_errors));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
      
      if (!left--)
  	return sprintf(page,"
  "
  		       "   AUX:\t\t       allocation failures
  "
  		       "     small b1:\t\t\t%10u
  "
  		       "     large b1:\t\t\t%10u
  "
  		       "     small b2:\t\t\t%10u
  "
  		       "     large b2:\t\t\t%10u
  "
  		       "     RX PDUs:\t\t\t%10u
  "
  		       "     TX PDUs:\t\t\t%10lu
  ",
63734a32a   Al Viro   fore2000 - fix mi...
3038
3039
3040
3041
3042
  		       be32_to_cpu(fore200e->stats->aux.small_b1_failed),
  		       be32_to_cpu(fore200e->stats->aux.large_b1_failed),
  		       be32_to_cpu(fore200e->stats->aux.small_b2_failed),
  		       be32_to_cpu(fore200e->stats->aux.large_b2_failed),
  		       be32_to_cpu(fore200e->stats->aux.rpd_alloc_failed),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
  		       fore200e->tx_sat);
      
      if (!left--)
  	return sprintf(page,"
  "
  		       " receive carrier:\t\t\t%s
  ",
  		       fore200e->stats->aux.receive_carrier ? "ON" : "OFF!");
      
      if (!left--) {
          return sprintf(page,"
  "
  		       " VCCs:
    address   VPI VCI   AAL "
  		       "TX PDUs   TX min/max size  RX PDUs   RX min/max size
  ");
      }
  
      for (i = 0; i < NBR_CONNECT; i++) {
  
  	vcc = fore200e->vc_map[i].vcc;
  
  	if (vcc == NULL)
  	    continue;
  
  	spin_lock_irqsave(&fore200e->q_lock, flags);
  
  	if (vcc && test_bit(ATM_VF_READY, &vcc->flags) && !left--) {
  
  	    fore200e_vcc = FORE200E_VCC(vcc);
  	    ASSERT(fore200e_vcc);
  
  	    len = sprintf(page,
22dac9f1f   Colin Ian King   atm: fore200e: us...
3076
3077
3078
  			  "  %pK  %03d %05d %1d   %09lu %05d/%05d      %09lu %05d/%05d
  ",
  			  vcc,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
  			  vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal),
  			  fore200e_vcc->tx_pdu,
  			  fore200e_vcc->tx_min_pdu > 0xFFFF ? 0 : fore200e_vcc->tx_min_pdu,
  			  fore200e_vcc->tx_max_pdu,
  			  fore200e_vcc->rx_pdu,
  			  fore200e_vcc->rx_min_pdu > 0xFFFF ? 0 : fore200e_vcc->rx_min_pdu,
  			  fore200e_vcc->rx_max_pdu);
  
  	    spin_unlock_irqrestore(&fore200e->q_lock, flags);
  	    return len;
  	}
  
  	spin_unlock_irqrestore(&fore200e->q_lock, flags);
      }
      
      return 0;
  }
  
  module_init(fore200e_module_init);
  module_exit(fore200e_module_cleanup);
0efe55238   Christoph Hellwig   fore200e: simplif...
3099
  static const struct atmdev_ops fore200e_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
  	.open       = fore200e_open,
  	.close      = fore200e_close,
  	.ioctl      = fore200e_ioctl,
  	.getsockopt = fore200e_getsockopt,
  	.setsockopt = fore200e_setsockopt,
  	.send       = fore200e_send,
  	.change_qos = fore200e_change_qos,
  	.proc_read  = fore200e_proc_read,
  	.owner      = THIS_MODULE
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3110
  MODULE_LICENSE("GPL");
6f75a9b64   Chas Williams   atm: [fore200e] u...
3111
3112
3113
3114
3115
3116
3117
3118
3119
  #ifdef CONFIG_PCI
  #ifdef __LITTLE_ENDIAN__
  MODULE_FIRMWARE("pca200e.bin");
  #else
  MODULE_FIRMWARE("pca200e_ecd.bin2");
  #endif
  #endif /* CONFIG_PCI */
  #ifdef CONFIG_SBUS
  MODULE_FIRMWARE("sba200e_ecd.bin2");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3120
  #endif