fore200e.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:82k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.   $Id: fore200e.c,v 1.5 2000/04/14 10:10:34 davem Exp $
  3.   A FORE Systems 200E-series driver for ATM on Linux.
  4.   Christophe Lizzi (lizzi@cnam.fr), October 1999-March 2000.
  5.   Based on the PCA-200E driver from Uwe Dannowski (Uwe.Dannowski@inf.tu-dresden.de).
  6.   This driver simultaneously supports PCA-200E and SBA-200E adapters
  7.   on i386, alpha (untested), powerpc, sparc and sparc64 architectures.
  8.   This program is free software; you can redistribute it and/or modify
  9.   it under the terms of the GNU General Public License as published by
  10.   the Free Software Foundation; either version 2 of the License, or
  11.   (at your option) any later version.
  12.   This program is distributed in the hope that it will be useful,
  13.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.   GNU General Public License for more details.
  16.   You should have received a copy of the GNU General Public License
  17.   along with this program; if not, write to the Free Software
  18.   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19. */
  20. #include <linux/version.h>
  21. #include <linux/config.h>
  22. #include <linux/kernel.h>
  23. #include <linux/slab.h>
  24. #include <linux/init.h>
  25. #include <linux/capability.h>
  26. #include <linux/sched.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/bitops.h>
  29. #include <linux/atmdev.h>
  30. #include <linux/sonet.h>
  31. #include <linux/atm_suni.h>
  32. #include <asm/io.h>
  33. #include <asm/string.h>
  34. #include <asm/segment.h>
  35. #include <asm/page.h>
  36. #include <asm/irq.h>
  37. #include <asm/dma.h>
  38. #include <asm/byteorder.h>
  39. #include <asm/uaccess.h>
  40. #include <asm/atomic.h>
  41. #include <linux/pci.h>
  42. #ifdef CONFIG_ATM_FORE200E_SBA
  43. #include <asm/idprom.h>
  44. #include <asm/sbus.h>
  45. #include <asm/openprom.h>
  46. #include <asm/oplib.h>
  47. #include <asm/pgtable.h>
  48. #endif
  49. #include <linux/module.h>
  50. #include "fore200e.h"
  51. #include "suni.h"
  52. #if 1   /* ensure correct handling of 52-byte AAL0 SDUs used by atmdump-like apps */
  53. #define FORE200E_52BYTE_AAL0_SDU
  54. #endif
  55. #define FORE200E_VERSION "0.2d"
  56. #define FORE200E         "fore200e: "
  57. #if defined(CONFIG_ATM_FORE200E_DEBUG) && (CONFIG_ATM_FORE200E_DEBUG > 0)
  58. #define DPRINTK(level, format, args...)  do { if (CONFIG_ATM_FORE200E_DEBUG >= (level)) 
  59.                                                   printk(FORE200E format, ##args); } while(0)
  60. #else
  61. #define DPRINTK(level, format, args...)  while(0)
  62. #endif
  63. #define FORE200E_ALIGN(addr, alignment) 
  64.         ((((unsigned long)(addr) + (alignment - 1)) & ~(alignment - 1)) - (unsigned long)(addr))
  65. #define FORE200E_DMA_INDEX(dma_addr, type, index)  ((dma_addr) + (index) * sizeof(type))
  66. #define FORE200E_INDEX(virt_addr, type, index)     (&((type *)(virt_addr))[ index ])
  67. #define FORE200E_NEXT_ENTRY(index, modulo)    (index = ++(index) % (modulo))
  68. #define MSECS(ms)  (((ms)*HZ/1000)+1)
  69. extern const struct atmdev_ops   fore200e_ops;
  70. extern const struct fore200e_bus fore200e_bus[];
  71. static struct fore200e* fore200e_boards = NULL;
  72. #ifdef MODULE
  73. MODULE_AUTHOR("Christophe Lizzi - credits to Uwe Dannowski and Heikki Vatiainen");
  74. MODULE_DESCRIPTION("FORE Systems 200E-series ATM driver - version " FORE200E_VERSION);
  75. MODULE_SUPPORTED_DEVICE("PCA-200E, SBA-200E");
  76. #endif
  77. static const int fore200e_rx_buf_nbr[ BUFFER_SCHEME_NBR ][ BUFFER_MAGN_NBR ] = {
  78.     { BUFFER_S1_NBR, BUFFER_L1_NBR },
  79.     { BUFFER_S2_NBR, BUFFER_L2_NBR }
  80. };
  81. static const int fore200e_rx_buf_size[ BUFFER_SCHEME_NBR ][ BUFFER_MAGN_NBR ] = {
  82.     { BUFFER_S1_SIZE, BUFFER_L1_SIZE },
  83.     { BUFFER_S2_SIZE, BUFFER_L2_SIZE }
  84. };
  85. #if defined(CONFIG_ATM_FORE200E_DEBUG) && (CONFIG_ATM_FORE200E_DEBUG > 0)
  86. static const char* fore200e_traffic_class[] = { "NONE", "UBR", "CBR", "VBR", "ABR", "ANY" };
  87. #endif
  88. #if 0 /* currently unused */
  89. static int 
  90. fore200e_fore2atm_aal(enum fore200e_aal aal)
  91. {
  92.     switch(aal) {
  93.     case FORE200E_AAL0:  return ATM_AAL0;
  94.     case FORE200E_AAL34: return ATM_AAL34;
  95.     case FORE200E_AAL5:  return ATM_AAL5;
  96.     }
  97.     return -EINVAL;
  98. }
  99. #endif
  100. static enum fore200e_aal
  101. fore200e_atm2fore_aal(int aal)
  102. {
  103.     switch(aal) {
  104.     case ATM_AAL0:  return FORE200E_AAL0;
  105.     case ATM_AAL34: return FORE200E_AAL34;
  106.     case ATM_AAL1:
  107.     case ATM_AAL2:
  108.     case ATM_AAL5:  return FORE200E_AAL5;
  109.     }
  110.     return -EINVAL;
  111. }
  112. static char*
  113. fore200e_irq_itoa(int irq)
  114. {
  115. #if defined(__sparc_v9__)
  116.     return __irq_itoa(irq);
  117. #else
  118.     static char str[8];
  119.     sprintf(str, "%d", irq);
  120.     return str;
  121. #endif
  122. }
  123. static void*
  124. fore200e_kmalloc(int size, int flags)
  125. {
  126.     void* chunk = kmalloc(size, flags);
  127.     if (chunk)
  128. memset(chunk, 0x00, size);
  129.     else
  130. printk(FORE200E "kmalloc() failed, requested size = %d, flags = 0x%xn", size, flags);
  131.     
  132.     return chunk;
  133. }
  134. static void
  135. fore200e_kfree(void* chunk)
  136. {
  137.     kfree(chunk);
  138. }
  139. /* allocate and align a chunk of memory intended to hold the data behing exchanged
  140.    between the driver and the adapter (using streaming DVMA) */
  141. static int
  142. fore200e_chunk_alloc(struct fore200e* fore200e, struct chunk* chunk, int size, int alignment, int direction)
  143. {
  144.     unsigned long offset = 0;
  145.     if (alignment <= sizeof(int))
  146. alignment = 0;
  147.     chunk->alloc_size = size + alignment;
  148.     chunk->align_size = size;
  149.     chunk->direction  = direction;
  150.     chunk->alloc_addr = fore200e_kmalloc(chunk->alloc_size, GFP_KERNEL | GFP_DMA);
  151.     if (chunk->alloc_addr == NULL)
  152. return -ENOMEM;
  153.     if (alignment > 0)
  154. offset = FORE200E_ALIGN(chunk->alloc_addr, alignment); 
  155.     
  156.     chunk->align_addr = chunk->alloc_addr + offset;
  157.     chunk->dma_addr = fore200e->bus->dma_map(fore200e, chunk->align_addr, chunk->align_size, direction);
  158.     
  159.     return 0;
  160. }
  161. /* free a chunk of memory */
  162. static void
  163. fore200e_chunk_free(struct fore200e* fore200e, struct chunk* chunk)
  164. {
  165.     fore200e->bus->dma_unmap(fore200e, chunk->dma_addr, chunk->dma_size, chunk->direction);
  166.     fore200e_kfree(chunk->alloc_addr);
  167. }
  168. #if 0 /* currently unused */
  169. static int
  170. fore200e_checkup(struct fore200e* fore200e)
  171. {
  172.     u32 hb1, hb2;
  173.     hb1 = fore200e->bus->read(&fore200e->cp_queues->heartbeat);
  174.     fore200e_spin(10);
  175.     hb2 = fore200e->bus->read(&fore200e->cp_queues->heartbeat);
  176.     
  177.     if (hb2 <= hb1) {
  178. printk(FORE200E "device %s heartbeat is not counting upwards, hb1 = %x; hb2 = %xn",
  179.        fore200e->name, hb1, hb2);
  180. return -EIO;
  181.     }
  182.     printk(FORE200E "device %s heartbeat is okn", fore200e->name);
  183.     
  184.     return 0;
  185. }
  186. #endif 
  187. static void
  188. fore200e_spin(int msecs)
  189. {
  190.     unsigned long timeout = jiffies + MSECS(msecs);
  191.     while (time_before(jiffies, timeout));
  192. }
  193. static int
  194. fore200e_poll(struct fore200e* fore200e, volatile u32* addr, u32 val, int msecs)
  195. {
  196.     unsigned long timeout = jiffies + MSECS(msecs);
  197.     int           ok;
  198.     mb();
  199.     do {
  200. if ((ok = (*addr == val)) || (*addr & STATUS_ERROR))
  201.     break;
  202.     } while (time_before(jiffies, timeout));
  203. #if 1
  204.     if (!ok) {
  205. printk(FORE200E "cmd polling failed, got status 0x%08x, expected 0x%08xn",
  206.        *addr, val);
  207.     }
  208. #endif
  209.     return ok;
  210. }
  211. static int
  212. fore200e_io_poll(struct fore200e* fore200e, volatile u32* addr, u32 val, int msecs)
  213. {
  214.     unsigned long timeout = jiffies + MSECS(msecs);
  215.     int           ok;
  216.     do {
  217. if ((ok = (fore200e->bus->read(addr) == val)))
  218.     break;
  219.     } while (time_before(jiffies, timeout));
  220. #if 1
  221.     if (!ok) {
  222. printk(FORE200E "I/O polling failed, got status 0x%08x, expected 0x%08xn",
  223.        fore200e->bus->read(addr), val);
  224.     }
  225. #endif
  226.     return ok;
  227. }
  228. static void
  229. fore200e_free_rx_buf(struct fore200e* fore200e)
  230. {
  231.     int scheme, magn, nbr;
  232.     struct buffer* buffer;
  233.     for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
  234. for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
  235.     if ((buffer = fore200e->host_bsq[ scheme ][ magn ].buffer) != NULL) {
  236. for (nbr = 0; nbr < fore200e_rx_buf_nbr[ scheme ][ magn ]; nbr++) {
  237.     struct chunk* data = &buffer[ nbr ].data;
  238.     if (data->alloc_addr != NULL)
  239. fore200e_chunk_free(fore200e, data);
  240. }
  241.     }
  242. }
  243.     }
  244. }
  245. static void
  246. fore200e_uninit_bs_queue(struct fore200e* fore200e)
  247. {
  248.     int scheme, magn;
  249.     
  250.     for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
  251. for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
  252.     struct chunk* status    = &fore200e->host_bsq[ scheme ][ magn ].status;
  253.     struct chunk* rbd_block = &fore200e->host_bsq[ scheme ][ magn ].rbd_block;
  254.     
  255.     if (status->alloc_addr)
  256. fore200e->bus->dma_chunk_free(fore200e, status);
  257.     
  258.     if (rbd_block->alloc_addr)
  259. fore200e->bus->dma_chunk_free(fore200e, rbd_block);
  260. }
  261.     }
  262. }
  263. static int
  264. fore200e_reset(struct fore200e* fore200e, int diag)
  265. {
  266.     int ok;
  267.     fore200e->cp_monitor = (struct cp_monitor*)(fore200e->virt_base + FORE200E_CP_MONITOR_OFFSET);
  268.     
  269.     fore200e->bus->write(BSTAT_COLD_START, &fore200e->cp_monitor->bstat);
  270.     fore200e->bus->reset(fore200e);
  271.     if (diag) {
  272. ok = fore200e_io_poll(fore200e, &fore200e->cp_monitor->bstat, BSTAT_SELFTEST_OK, 1000);
  273. if (ok == 0) {
  274.     
  275.     printk(FORE200E "device %s self-test failedn", fore200e->name);
  276.     return -ENODEV;
  277. }
  278. printk(FORE200E "device %s self-test passedn", fore200e->name);
  279. fore200e->state = FORE200E_STATE_RESET;
  280.     }
  281.     return 0;
  282. }
  283. static void
  284. fore200e_shutdown(struct fore200e* fore200e)
  285. {
  286.     printk(FORE200E "removing device %s at 0x%lx, IRQ %sn",
  287.    fore200e->name, fore200e->phys_base, 
  288.    fore200e_irq_itoa(fore200e->irq));
  289.     
  290.     if (fore200e->state > FORE200E_STATE_RESET) {
  291. /* first, reset the board to prevent further interrupts or data transfers */
  292. fore200e_reset(fore200e, 0);
  293.     }
  294.     
  295.     /* then, release all allocated resources */
  296.     switch(fore200e->state) {
  297.     case FORE200E_STATE_COMPLETE:
  298. if (fore200e->stats)
  299.     kfree(fore200e->stats);
  300.     case FORE200E_STATE_IRQ:
  301. free_irq(fore200e->irq, fore200e->atm_dev);
  302.     case FORE200E_STATE_ALLOC_BUF:
  303. fore200e_free_rx_buf(fore200e);
  304.     case FORE200E_STATE_INIT_BSQ:
  305. fore200e_uninit_bs_queue(fore200e);
  306.     case FORE200E_STATE_INIT_RXQ:
  307. fore200e->bus->dma_chunk_free(fore200e, &fore200e->host_rxq.status);
  308. fore200e->bus->dma_chunk_free(fore200e, &fore200e->host_rxq.rpd);
  309.     case FORE200E_STATE_INIT_TXQ:
  310. fore200e->bus->dma_chunk_free(fore200e, &fore200e->host_txq.status);
  311. fore200e->bus->dma_chunk_free(fore200e, &fore200e->host_txq.tpd);
  312.     case FORE200E_STATE_INIT_CMDQ:
  313. fore200e->bus->dma_chunk_free(fore200e, &fore200e->host_cmdq.status);
  314.     case FORE200E_STATE_INITIALIZE:
  315. /* nothing to do for that state */
  316.     case FORE200E_STATE_START_FW:
  317. /* nothing to do for that state */
  318.     case FORE200E_STATE_LOAD_FW:
  319. /* nothing to do for that state */
  320.     case FORE200E_STATE_RESET:
  321. /* nothing to do for that state */
  322.     case FORE200E_STATE_MAP:
  323. fore200e->bus->unmap(fore200e);
  324.     case FORE200E_STATE_CONFIGURE:
  325. /* nothing to do for that state */
  326.     case FORE200E_STATE_REGISTER:
  327. /* XXX shouldn't we *start* by deregistering the device? */
  328. atm_dev_deregister(fore200e->atm_dev);
  329.     case FORE200E_STATE_BLANK:
  330. /* nothing to do for that state */
  331. break;
  332.     }
  333. }
  334. #ifdef CONFIG_ATM_FORE200E_PCA
  335. static u32 fore200e_pca_read(volatile u32* addr)
  336. {
  337.     /* on big-endian hosts, the board is configured to convert
  338.        the endianess of slave RAM accesses  */
  339.     return le32_to_cpu(readl(addr));
  340. }
  341. static void fore200e_pca_write(u32 val, volatile u32* addr)
  342. {
  343.     /* on big-endian hosts, the board is configured to convert
  344.        the endianess of slave RAM accesses  */
  345.     writel(cpu_to_le32(val), addr);
  346. }
  347. static u32
  348. fore200e_pca_dma_map(struct fore200e* fore200e, void* virt_addr, int size, int direction)
  349. {
  350.     u32 dma_addr = pci_map_single((struct pci_dev*)fore200e->bus_dev, virt_addr, size, direction);
  351.     DPRINTK(3, "PCI DVMA mapping: virt_addr = 0x%p, size = %d, direction = %d,  --> dma_addr = 0x%08xn",
  352.     virt_addr, size, direction, dma_addr);
  353.     
  354.     return dma_addr;
  355. }
  356. static void
  357. fore200e_pca_dma_unmap(struct fore200e* fore200e, u32 dma_addr, int size, int direction)
  358. {
  359.     DPRINTK(3, "PCI DVMA unmapping: dma_addr = 0x%08x, size = %d, direction = %dn",
  360.     dma_addr, size, direction);
  361.     pci_unmap_single((struct pci_dev*)fore200e->bus_dev, dma_addr, size, direction);
  362. }
  363. static void
  364. fore200e_pca_dma_sync(struct fore200e* fore200e, u32 dma_addr, int size, int direction)
  365. {
  366.     DPRINTK(3, "PCI DVMA sync: dma_addr = 0x%08x, size = %d, direction = %dn", dma_addr, size, direction);
  367.     pci_dma_sync_single((struct pci_dev*)fore200e->bus_dev, dma_addr, size, direction);
  368. }
  369. /* allocate a DMA consistent chunk of memory intended to act as a communication mechanism
  370.    (to hold descriptors, status, queues, etc.) shared by the driver and the adapter */
  371. static int
  372. fore200e_pca_dma_chunk_alloc(struct fore200e* fore200e, struct chunk* chunk,
  373.      int size, int nbr, int alignment)
  374. {
  375. #if defined(__sparc_v9__)
  376.     /* returned chunks are page-aligned */
  377.     chunk->alloc_addr = pci_alloc_consistent((struct pci_dev*)fore200e->bus_dev,
  378.      chunk->alloc_size,
  379.      &chunk->dma_addr);
  380.     
  381.     if (chunk->alloc_addr == NULL || chunk->dma_addr == 0)
  382. return -ENOMEM;
  383.     chunk->align_addr = chunk->alloc_addr;
  384. #else
  385.     if (fore200e_chunk_alloc(fore200e, chunk, size * nbr, alignment, FORE200E_DMA_BIDIRECTIONAL) < 0)
  386. return -ENOMEM;
  387. #endif
  388.     
  389.     return 0;
  390. }
  391. /* free a DMA consistent chunk of memory */
  392. static void
  393. fore200e_pca_dma_chunk_free(struct fore200e* fore200e, struct chunk* chunk)
  394. {
  395. #if defined(__sparc_v9__)
  396.     pci_free_consistent((struct pci_dev*)fore200e->bus_dev,
  397. chunk->alloc_size,
  398. chunk->alloc_addr,
  399. chunk->dma_addr);
  400. #else
  401.     fore200e_chunk_free(fore200e, chunk);
  402. #endif
  403. }
  404. static int
  405. fore200e_pca_irq_check(struct fore200e* fore200e)
  406. {
  407.     /* this is a 1 bit register */
  408.     return readl(fore200e->regs.pca.psr);
  409. }
  410. static void
  411. fore200e_pca_irq_ack(struct fore200e* fore200e)
  412. {
  413.     writel(PCA200E_HCR_CLRINTR, fore200e->regs.pca.hcr);
  414. }
  415. static void
  416. fore200e_pca_reset(struct fore200e* fore200e)
  417. {
  418.     writel(PCA200E_HCR_RESET, fore200e->regs.pca.hcr);
  419.     fore200e_spin(10);
  420.     writel(0, fore200e->regs.pca.hcr);
  421. }
  422. static int __init
  423. fore200e_pca_map(struct fore200e* fore200e)
  424. {
  425.     DPRINTK(2, "device %s being mapped in memoryn", fore200e->name);
  426.     fore200e->virt_base = ioremap(fore200e->phys_base, PCA200E_IOSPACE_LENGTH);
  427.     
  428.     if (fore200e->virt_base == NULL) {
  429. printk(FORE200E "can't map device %sn", fore200e->name);
  430. return -EFAULT;
  431.     }
  432.     DPRINTK(1, "device %s mapped to 0x%pn", fore200e->name, fore200e->virt_base);
  433.     /* gain access to the PCA-200E specific registers  */
  434.     fore200e->regs.pca.hcr = (u32*)(fore200e->virt_base + PCA200E_HCR_OFFSET);
  435.     fore200e->regs.pca.imr = (u32*)(fore200e->virt_base + PCA200E_IMR_OFFSET);
  436.     fore200e->regs.pca.psr = (u32*)(fore200e->virt_base + PCA200E_PSR_OFFSET);
  437.     fore200e->state = FORE200E_STATE_MAP;
  438.     return 0;
  439. }
  440. static void
  441. fore200e_pca_unmap(struct fore200e* fore200e)
  442. {
  443.     DPRINTK(2, "device %s being unmapped from memoryn", fore200e->name);
  444.     /* XXX iounmap() does nothing on PowerPC (at least in 2.2.12 and 2.3.41),
  445.        this leads to a kernel panic if the module is loaded and unloaded several times */
  446.     if (fore200e->virt_base != NULL)
  447. iounmap(fore200e->virt_base);
  448. }
  449. static int __init
  450. fore200e_pca_configure(struct fore200e* fore200e)
  451. {
  452.     struct pci_dev* pci_dev = (struct pci_dev*)fore200e->bus_dev;
  453.     u8              master_ctrl;
  454.     DPRINTK(2, "device %s being configuredn", fore200e->name);
  455.     if ((pci_dev->irq == 0) || (pci_dev->irq == 0xFF)) {
  456. printk(FORE200E "incorrect IRQ setting - misconfigured PCI-PCI bridge?n");
  457. return -EIO;
  458.     }
  459. pci_read_config_byte(pci_dev, PCA200E_PCI_MASTER_CTRL, &master_ctrl);
  460.     master_ctrl = master_ctrl
  461. #if 0
  462. | PCA200E_CTRL_DIS_CACHE_RD
  463.         | PCA200E_CTRL_DIS_WRT_INVAL
  464. #endif
  465. #if defined(__BIG_ENDIAN)
  466. /* request the PCA board to convert the endianess of slave RAM accesses */
  467. | PCA200E_CTRL_CONVERT_ENDIAN
  468. #endif
  469. | PCA200E_CTRL_LARGE_PCI_BURSTS;
  470.     
  471.     pci_write_config_byte(pci_dev, PCA200E_PCI_MASTER_CTRL, master_ctrl);
  472.     fore200e->state = FORE200E_STATE_CONFIGURE;
  473.     return 0;
  474. }
  475. static struct fore200e* __init
  476. fore200e_pca_detect(const struct fore200e_bus* bus, int index)
  477. {
  478.     struct fore200e* fore200e;
  479.     struct pci_dev*  pci_dev = NULL;
  480.     int              count = index;
  481.     
  482.     if (pci_present() == 0) {
  483. printk(FORE200E "no PCI subsystemn");
  484. return NULL;
  485.     }
  486.     do {
  487. pci_dev = pci_find_device(PCI_VENDOR_ID_FORE, PCI_DEVICE_ID_FORE_PCA200E, pci_dev);
  488. if (pci_dev == NULL)
  489.     return NULL;
  490.     } while (count--);
  491.     if (pci_enable_device(pci_dev))
  492. return NULL;
  493.     
  494.     fore200e = fore200e_kmalloc(sizeof(struct fore200e), GFP_KERNEL);
  495.     if (fore200e == NULL)
  496. return NULL;
  497.     fore200e->bus       = bus;
  498.     fore200e->bus_dev   = pci_dev;    
  499.     fore200e->irq       = pci_dev->irq;
  500.     fore200e->phys_base = pci_resource_start (pci_dev, 0);
  501. #if defined(__powerpc__)
  502.     fore200e->phys_base += KERNELBASE;
  503. #endif
  504.     sprintf(fore200e->name, "%s-%d", bus->model_name, index - 1);
  505.     pci_set_master(pci_dev);
  506.     return fore200e;
  507. }
  508. static int __init
  509. fore200e_pca_prom_read(struct fore200e* fore200e, struct prom_data* prom)
  510. {
  511.     struct host_cmdq*       cmdq  = &fore200e->host_cmdq;
  512.     struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
  513.     struct prom_opcode      opcode;
  514.     int                     ok;
  515.     u32                     prom_dma;
  516.     FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
  517.     opcode.opcode = OPCODE_GET_PROM;
  518.     opcode.pad    = 0;
  519.     prom_dma = fore200e->bus->dma_map(fore200e, prom, sizeof(struct prom_data), FORE200E_DMA_FROMDEVICE);
  520.     fore200e->bus->write(prom_dma, &entry->cp_entry->cmd.prom_block.prom_haddr);
  521.     
  522.     *entry->status = STATUS_PENDING;
  523.     fore200e->bus->write(*(u32*)&opcode, (u32*)&entry->cp_entry->cmd.prom_block.opcode);
  524.     ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
  525.     *entry->status = STATUS_FREE;
  526.     fore200e->bus->dma_unmap(fore200e, prom_dma, sizeof(struct prom_data), FORE200E_DMA_FROMDEVICE);
  527.     if (ok == 0) {
  528. printk(FORE200E "unable to get PROM data from device %sn", fore200e->name);
  529. return -EIO;
  530.     }
  531. #if defined(__BIG_ENDIAN)
  532.     
  533. #define swap_here(addr) (*((u32*)(addr)) = swab32( *((u32*)(addr)) ))
  534.     /* MAC address is stored as little-endian */
  535.     swap_here(&prom->mac_addr[0]);
  536.     swap_here(&prom->mac_addr[4]);
  537. #endif
  538.     
  539.     return 0;
  540. }
  541. static int
  542. fore200e_pca_proc_read(struct fore200e* fore200e, char *page)
  543. {
  544.     struct pci_dev* pci_dev = (struct pci_dev*)fore200e->bus_dev;
  545.     return sprintf(page, "   PCI bus/slot/function:t%d/%d/%dn",
  546.    pci_dev->bus->number, PCI_SLOT(pci_dev->devfn), PCI_FUNC(pci_dev->devfn));
  547. }
  548. #endif /* CONFIG_ATM_FORE200E_PCA */
  549. #ifdef CONFIG_ATM_FORE200E_SBA
  550. static u32
  551. fore200e_sba_read(volatile u32* addr)
  552. {
  553.     return sbus_readl(addr);
  554. }
  555. static void
  556. fore200e_sba_write(u32 val, volatile u32* addr)
  557. {
  558.     sbus_writel(val, addr);
  559. }
  560. static u32
  561. fore200e_sba_dma_map(struct fore200e* fore200e, void* virt_addr, int size, int direction)
  562. {
  563.     u32 dma_addr = sbus_map_single((struct sbus_dev*)fore200e->bus_dev, virt_addr, size, direction);
  564.     DPRINTK(3, "SBUS DVMA mapping: virt_addr = 0x%p, size = %d, direction = %d --> dma_addr = 0x%08xn",
  565.     virt_addr, size, direction, dma_addr);
  566.     
  567.     return dma_addr;
  568. }
  569. static void
  570. fore200e_sba_dma_unmap(struct fore200e* fore200e, u32 dma_addr, int size, int direction)
  571. {
  572.     DPRINTK(3, "SBUS DVMA unmapping: dma_addr = 0x%08x, size = %d, direction = %d,n",
  573.     dma_addr, size, direction);
  574.     sbus_unmap_single((struct sbus_dev*)fore200e->bus_dev, dma_addr, size, direction);
  575. }
  576. static void
  577. fore200e_sba_dma_sync(struct fore200e* fore200e, u32 dma_addr, int size, int direction)
  578. {
  579.     DPRINTK(3, "SBUS DVMA sync: dma_addr = 0x%08x, size = %d, direction = %dn", dma_addr, size, direction);
  580.     
  581.     sbus_dma_sync_single((struct sbus_dev*)fore200e->bus_dev, dma_addr, size, direction);
  582. }
  583. /* allocate a DVMA consistent chunk of memory intended to act as a communication mechanism
  584.    (to hold descriptors, status, queues, etc.) shared by the driver and the adapter */
  585. static int
  586. fore200e_sba_dma_chunk_alloc(struct fore200e* fore200e, struct chunk* chunk,
  587.      int size, int nbr, int alignment)
  588. {
  589.     chunk->alloc_size = chunk->align_size = size * nbr;
  590.     /* returned chunks are page-aligned */
  591.     chunk->alloc_addr = sbus_alloc_consistent((struct sbus_dev*)fore200e->bus_dev,
  592.       chunk->alloc_size,
  593.       &chunk->dma_addr);
  594.     if (chunk->alloc_addr == NULL || chunk->dma_addr == 0)
  595. return -ENOMEM;
  596.     chunk->align_addr = chunk->alloc_addr;
  597.     
  598.     return 0;
  599. }
  600. /* free a DVMA consistent chunk of memory */
  601. static void
  602. fore200e_sba_dma_chunk_free(struct fore200e* fore200e, struct chunk* chunk)
  603. {
  604.     sbus_free_consistent((struct sbus_dev*)fore200e->bus_dev,
  605.  chunk->alloc_size,
  606.  chunk->alloc_addr,
  607.  chunk->dma_addr);
  608. }
  609. static void
  610. fore200e_sba_irq_enable(struct fore200e* fore200e)
  611. {
  612.     u32 hcr = fore200e->bus->read(fore200e->regs.sba.hcr) & SBA200E_HCR_STICKY;
  613.     fore200e->bus->write(hcr | SBA200E_HCR_INTR_ENA, fore200e->regs.sba.hcr);
  614. }
  615. static int
  616. fore200e_sba_irq_check(struct fore200e* fore200e)
  617. {
  618.     return fore200e->bus->read(fore200e->regs.sba.hcr) & SBA200E_HCR_INTR_REQ;
  619. }
  620. static void
  621. fore200e_sba_irq_ack(struct fore200e* fore200e)
  622. {
  623.     u32 hcr = fore200e->bus->read(fore200e->regs.sba.hcr) & SBA200E_HCR_STICKY;
  624.     fore200e->bus->write(hcr | SBA200E_HCR_INTR_CLR, fore200e->regs.sba.hcr);
  625. }
  626. static void
  627. fore200e_sba_reset(struct fore200e* fore200e)
  628. {
  629.     fore200e->bus->write(SBA200E_HCR_RESET, fore200e->regs.sba.hcr);
  630.     fore200e_spin(10);
  631.     fore200e->bus->write(0, fore200e->regs.sba.hcr);
  632. }
  633. static int __init
  634. fore200e_sba_map(struct fore200e* fore200e)
  635. {
  636.     struct sbus_dev* sbus_dev = (struct sbus_dev*)fore200e->bus_dev;
  637.     unsigned int bursts;
  638.     /* gain access to the SBA-200E specific registers  */
  639.     
  640.     fore200e->regs.sba.hcr = (u32*)sbus_ioremap(&sbus_dev->resource[0], 0, SBA200E_HCR_LENGTH, "SBA HCR");
  641.     fore200e->regs.sba.bsr = (u32*)sbus_ioremap(&sbus_dev->resource[1], 0, SBA200E_BSR_LENGTH, "SBA BSR");
  642.     fore200e->regs.sba.isr = (u32*)sbus_ioremap(&sbus_dev->resource[2], 0, SBA200E_ISR_LENGTH, "SBA ISR");
  643.     fore200e->virt_base    = (u32*)sbus_ioremap(&sbus_dev->resource[3], 0, SBA200E_RAM_LENGTH, "SBA RAM");
  644.     if (fore200e->virt_base == NULL) {
  645. printk(FORE200E "unable to map RAM of device %sn", fore200e->name);
  646. return -EFAULT;
  647.     }
  648.     DPRINTK(1, "device %s mapped to 0x%pn", fore200e->name, fore200e->virt_base);
  649.     
  650.     fore200e->bus->write(0x02, fore200e->regs.sba.isr); /* XXX hardwired interrupt level */
  651.     /* get the supported DVMA burst sizes */
  652.     bursts = prom_getintdefault(sbus_dev->bus->prom_node, "burst-sizes", 0x00);
  653.     if (sbus_can_dma_64bit(sbus_dev))
  654. sbus_set_sbus64(sbus_dev, bursts);
  655. #if 0
  656.     if (bursts & DMA_BURST16)
  657. fore200e->bus->write(SBA200E_BSR_BURST16, fore200e->regs.sba.bsr);
  658.     else
  659.     if (bursts & DMA_BURST8)
  660.        fore200e->bus->write(SBA200E_BSR_BURST8, fore200e->regs.sba.bsr);
  661.     else
  662.     if (bursts & DMA_BURST4)
  663.         fore200e->bus->write(SBA200E_BSR_BURST4, fore200e->regs.sba.bsr);
  664. #endif
  665.     fore200e->state = FORE200E_STATE_MAP;
  666.     return 0;
  667. }
  668. static void
  669. fore200e_sba_unmap(struct fore200e* fore200e)
  670. {
  671.     sbus_iounmap((ulong)fore200e->regs.sba.hcr, SBA200E_HCR_LENGTH);
  672.     sbus_iounmap((ulong)fore200e->regs.sba.bsr, SBA200E_BSR_LENGTH);
  673.     sbus_iounmap((ulong)fore200e->regs.sba.isr, SBA200E_ISR_LENGTH);
  674.     sbus_iounmap((ulong)fore200e->virt_base,    SBA200E_RAM_LENGTH);
  675. }
  676. static int __init
  677. fore200e_sba_configure(struct fore200e* fore200e)
  678. {
  679.     fore200e->state = FORE200E_STATE_CONFIGURE;
  680.     return 0;
  681. }
  682. static struct fore200e* __init
  683. fore200e_sba_detect(const struct fore200e_bus* bus, int index)
  684. {
  685.     struct fore200e*          fore200e;
  686.     struct sbus_bus* sbus_bus;
  687.     struct sbus_dev* sbus_dev = NULL;
  688.     
  689.     unsigned int     count = 0;
  690.     
  691.     for_each_sbus (sbus_bus) {
  692. for_each_sbusdev (sbus_dev, sbus_bus) {
  693.     if (strcmp(sbus_dev->prom_name, SBA200E_PROM_NAME) == 0) {
  694. if (count >= index)
  695.     goto found;
  696. count++;
  697.     }
  698. }
  699.     }
  700.     return NULL;
  701.     
  702.   found:
  703. #if 1
  704.     if (sbus_dev->num_registers != 4) {
  705. printk(FORE200E "this %s device has %d instead of 4 registersn",
  706.        bus->model_name, sbus_dev->num_registers);
  707. return NULL;
  708.     }
  709. #endif
  710.     fore200e = fore200e_kmalloc(sizeof(struct fore200e), GFP_KERNEL);
  711.     if (fore200e == NULL)
  712. return NULL;
  713.     fore200e->bus     = bus;
  714.     fore200e->bus_dev = sbus_dev;
  715.     fore200e->irq     = sbus_dev->irqs[ 0 ];
  716.     fore200e->phys_base = (unsigned long)sbus_dev;
  717.     sprintf(fore200e->name, "%s-%d", bus->model_name, index - 1);
  718.     
  719.     return fore200e;
  720. }
  721. static int __init
  722. fore200e_sba_prom_read(struct fore200e* fore200e, struct prom_data* prom)
  723. {
  724.     struct sbus_dev* sbus_dev = (struct sbus_dev*) fore200e->bus_dev;
  725.     int                       len;
  726.     len = prom_getproperty(sbus_dev->prom_node, "macaddrlo2", &prom->mac_addr[ 4 ], 4);
  727.     if (len < 0)
  728. return -EBUSY;
  729.     len = prom_getproperty(sbus_dev->prom_node, "macaddrhi4", &prom->mac_addr[ 2 ], 4);
  730.     if (len < 0)
  731. return -EBUSY;
  732.     
  733.     prom_getproperty(sbus_dev->prom_node, "serialnumber",
  734.      (char*)&prom->serial_number, sizeof(prom->serial_number));
  735.     
  736.     prom_getproperty(sbus_dev->prom_node, "promversion",
  737.      (char*)&prom->hw_revision, sizeof(prom->hw_revision));
  738.     
  739.     return 0;
  740. }
  741. static int
  742. fore200e_sba_proc_read(struct fore200e* fore200e, char *page)
  743. {
  744.     struct sbus_dev* sbus_dev = (struct sbus_dev*)fore200e->bus_dev;
  745.     return sprintf(page, "   SBUS slot/device:tt%d/'%s'n", sbus_dev->slot, sbus_dev->prom_name);
  746. }
  747. #endif /* CONFIG_ATM_FORE200E_SBA */
  748. static void
  749. fore200e_irq_tx(struct fore200e* fore200e)
  750. {
  751.     struct host_txq_entry* entry;
  752.     int i;
  753.     
  754.     entry = fore200e->host_txq.host_entry;
  755.     for (i = 0; i < QUEUE_SIZE_TX; i++) {
  756. if (*entry->status & STATUS_COMPLETE) {
  757.     DPRINTK(3, "TX COMPLETED: entry = %p, vcc = %p, skb = %pn", entry, entry->vcc, entry->skb);
  758.     /* free copy of misaligned data */
  759.     if (entry->data)
  760. kfree(entry->data);
  761.     /* remove DMA mapping */
  762.     fore200e->bus->dma_unmap(fore200e, entry->tpd->tsd[ 0 ].buffer, entry->tpd->tsd[ 0 ].length,
  763.      FORE200E_DMA_TODEVICE);
  764.     /* notify tx completion */
  765.     if (entry->vcc->pop)
  766. entry->vcc->pop(entry->vcc, entry->skb);
  767.     else
  768. dev_kfree_skb_irq(entry->skb);
  769.     /* check error condition */
  770.     if (*entry->status & STATUS_ERROR)
  771. atomic_inc(&entry->vcc->stats->tx_err);
  772.     else
  773. atomic_inc(&entry->vcc->stats->tx);
  774.     *entry->status = STATUS_FREE;
  775.     
  776.     fore200e->host_txq.txing--;
  777. }
  778. entry++;
  779.     }
  780. }
  781. static void
  782. fore200e_supply(struct fore200e* fore200e)
  783. {
  784.     int  scheme, magn, i;
  785.     struct host_bsq*       bsq;
  786.     struct host_bsq_entry* entry;
  787.     struct buffer*         buffer;
  788.     for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
  789. for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
  790.     bsq = &fore200e->host_bsq[ scheme ][ magn ];
  791.     if (fore200e_rx_buf_nbr[ scheme ][ magn ] - bsq->count > RBD_BLK_SIZE) {
  792. DPRINTK(2, "supplying rx buffers to queue %d / %d, count = %dn",
  793. scheme, magn, bsq->count);
  794. entry = &bsq->host_entry[ bsq->head ];
  795. FORE200E_NEXT_ENTRY(bsq->head, QUEUE_SIZE_BS);
  796. for (i = 0; i < RBD_BLK_SIZE; i++) {
  797.     buffer = &bsq->buffer[ bsq->free ];
  798.     
  799.     FORE200E_NEXT_ENTRY(bsq->free, fore200e_rx_buf_nbr[ scheme ][ magn ]);
  800.     
  801.     entry->rbd_block->rbd[ i ].buffer_haddr = buffer->data.dma_addr;
  802.     entry->rbd_block->rbd[ i ].handle       = FORE200E_BUF2HDL(buffer);
  803. }
  804. /* increase the number of supplied rx buffers */
  805. bsq->count += RBD_BLK_SIZE;
  806. *entry->status = STATUS_PENDING;
  807. fore200e->bus->write(entry->rbd_block_dma, &entry->cp_entry->rbd_block_haddr);
  808.     }
  809. }
  810.     }
  811. }
  812. static struct atm_vcc* 
  813. fore200e_find_vcc(struct fore200e* fore200e, struct rpd* rpd)
  814. {
  815.     struct atm_vcc* vcc;
  816.     for (vcc = fore200e->atm_dev->vccs; vcc; vcc = vcc->next) {
  817. if (vcc->vpi == rpd->atm_header.vpi && vcc->vci == rpd->atm_header.vci)
  818.     break;
  819.     }
  820.     
  821.     return vcc;
  822. }
  823. static void
  824. fore200e_push_rpd(struct fore200e* fore200e, struct rpd* rpd)
  825. {
  826.     struct atm_vcc*      vcc;
  827.     struct sk_buff*      skb;
  828.     struct buffer*       buffer;
  829.     struct fore200e_vcc* fore200e_vcc;
  830.     int                  i, pdu_len = 0;
  831. #ifdef FORE200E_52BYTE_AAL0_SDU
  832.     u32                  cell_header = 0;
  833. #endif
  834.     vcc = fore200e_find_vcc(fore200e, rpd);
  835.     if (vcc == NULL) {
  836. printk(FORE200E "no vcc found for PDU received on %d.%d.%dn",
  837.        fore200e->atm_dev->number, rpd->atm_header.vpi, rpd->atm_header.vci);
  838. return;
  839.     }
  840.     fore200e_vcc = FORE200E_VCC(vcc);
  841. #ifdef FORE200E_52BYTE_AAL0_SDU
  842.     if ((vcc->qos.aal == ATM_AAL0) && (vcc->qos.rxtp.max_sdu == ATM_AAL0_SDU)) {
  843. cell_header = (rpd->atm_header.gfc << ATM_HDR_GFC_SHIFT) |
  844.               (rpd->atm_header.vpi << ATM_HDR_VPI_SHIFT) |
  845.                       (rpd->atm_header.vci << ATM_HDR_VCI_SHIFT) |
  846.                       (rpd->atm_header.plt << ATM_HDR_PTI_SHIFT) | 
  847.                        rpd->atm_header.clp;
  848. pdu_len = 4;
  849.     }
  850. #endif
  851.     
  852.     /* compute total PDU length */
  853.     for (i = 0; i < rpd->nseg; i++)
  854. pdu_len += rpd->rsd[ i ].length;
  855.     
  856.     skb = alloc_skb(pdu_len, GFP_ATOMIC);
  857.     if (skb == NULL) {
  858. printk(FORE200E "unable to alloc new skb, rx PDU length = %dn", pdu_len);
  859. atomic_inc(&vcc->stats->rx_drop);
  860. return;
  861.     } 
  862.     skb->stamp = vcc->timestamp = xtime;
  863.     
  864. #ifdef FORE200E_52BYTE_AAL0_SDU
  865.     if (cell_header) {
  866. *((u32*)skb_put(skb, 4)) = cell_header;
  867.     }
  868. #endif
  869.     /* reassemble segments */
  870.     for (i = 0; i < rpd->nseg; i++) {
  871. /* rebuild rx buffer address from rsd handle */
  872. buffer = FORE200E_HDL2BUF(rpd->rsd[ i ].handle);
  873. /* ensure DMA synchronisation */
  874. fore200e->bus->dma_sync(fore200e, buffer->data.dma_addr, rpd->rsd[ i ].length, FORE200E_DMA_FROMDEVICE);
  875. memcpy(skb_put(skb, rpd->rsd[ i ].length), buffer->data.align_addr, rpd->rsd[ i ].length);
  876.     }
  877.     
  878.     DPRINTK(3, "rx skb: len = %d, truesize = %dn", skb->len, skb->truesize);
  879.     
  880.     if (pdu_len < fore200e_vcc->rx_min_pdu)
  881. fore200e_vcc->rx_min_pdu = pdu_len;
  882.     if (pdu_len > fore200e_vcc->rx_max_pdu)
  883. fore200e_vcc->rx_max_pdu = pdu_len;
  884.     /* push PDU */
  885.     if (atm_charge(vcc, skb->truesize) == 0) {
  886. DPRINTK(2, "receive buffers saturated for %d.%d.%d - PDU droppedn",
  887. vcc->itf, vcc->vpi, vcc->vci);
  888. dev_kfree_skb_irq(skb);
  889. return;
  890.     }
  891.     vcc->push(vcc, skb);
  892.     atomic_inc(&vcc->stats->rx);
  893. }
  894. static void
  895. fore200e_collect_rpd(struct fore200e* fore200e, struct rpd* rpd)
  896. {
  897.     struct buffer* buffer;
  898.     int            i;
  899.     
  900.     for (i = 0; i < rpd->nseg; i++) {
  901. /* rebuild rx buffer address from rsd handle */
  902. buffer = FORE200E_HDL2BUF(rpd->rsd[ i ].handle);
  903. /* decrease the number of supplied rx buffers */
  904. fore200e->host_bsq[ buffer->scheme ][ buffer->magn ].count--;
  905.     }
  906. }
  907. static void
  908. fore200e_irq_rx(struct fore200e* fore200e)
  909. {
  910.     struct host_rxq*       rxq = &fore200e->host_rxq;
  911.     struct host_rxq_entry* entry;
  912.     for (;;) {
  913. entry = &rxq->host_entry[ rxq->head ];
  914. /* no more received PDUs */
  915. if ((*entry->status & STATUS_COMPLETE) == 0)
  916.     break;
  917. FORE200E_NEXT_ENTRY(rxq->head, QUEUE_SIZE_RX);
  918. if ((*entry->status & STATUS_ERROR) == 0) {
  919.     fore200e_push_rpd(fore200e, entry->rpd);
  920. }
  921. else {
  922.     printk(FORE200E "damaged PDU on %d.%d.%dn", 
  923.    fore200e->atm_dev->number, entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
  924. }
  925. fore200e_collect_rpd(fore200e, entry->rpd);
  926. fore200e_supply(fore200e);
  927. /* rewrite the rpd address to ack the received PDU */
  928. fore200e->bus->write(entry->rpd_dma, &entry->cp_entry->rpd_haddr);
  929. *entry->status = STATUS_FREE;
  930.     }
  931. }
  932. static void
  933. fore200e_interrupt(int irq, void* dev, struct pt_regs* regs)
  934. {
  935.     struct fore200e* fore200e = FORE200E_DEV((struct atm_dev*)dev);
  936.     if (fore200e->bus->irq_check(fore200e) == 0) {
  937. DPRINTK(3, "unexpected interrupt on device %cn", fore200e->name[9]);
  938. return;
  939.     }
  940.     DPRINTK(3, "valid interrupt on device %cn", fore200e->name[9]);
  941.     tasklet_schedule(&fore200e->tasklet);
  942.     
  943.     fore200e->bus->irq_ack(fore200e);
  944. }
  945. static void
  946. fore200e_tasklet(unsigned long data)
  947. {
  948.     struct fore200e* fore200e = (struct fore200e*) data;
  949.     fore200e_irq_rx(fore200e);
  950.     
  951.     if (fore200e->host_txq.txing)
  952. fore200e_irq_tx(fore200e);
  953. }
  954. static int
  955. fore200e_select_scheme(struct atm_vcc* vcc)
  956. {
  957.     int scheme;
  958. #if 1
  959.     /* fairly balance VCs over (identical) buffer schemes */
  960.     scheme =  vcc->vci % 2 ? BUFFER_SCHEME_ONE : BUFFER_SCHEME_TWO;
  961. #else
  962.     /* bit 7 of VPI magically selects the second buffer scheme */
  963.     if (vcc->vpi & (1<<7)) {
  964. vcc->vpi &= ((1<<7) - 1);    /* reset the magic bit */
  965. scheme = BUFFER_SCHEME_TWO;
  966.     }
  967.     else {
  968. scheme = BUFFER_SCHEME_ONE;
  969.     }
  970. #endif
  971.     
  972.     DPRINTK(1, "vpvc %d.%d.%d uses the %s buffer schemen",
  973.     vcc->itf, vcc->vpi, vcc->vci, scheme == BUFFER_SCHEME_ONE ? "first" : "second");
  974.     return scheme;
  975. }
  976. static int 
  977. fore200e_activate_vcin(struct fore200e* fore200e, int activate, struct atm_vcc* vcc, int mtu)
  978. {
  979.     struct host_cmdq*        cmdq  = &fore200e->host_cmdq;
  980.     struct host_cmdq_entry*  entry = &cmdq->host_entry[ cmdq->head ];
  981.     struct activate_opcode   activ_opcode;
  982.     struct deactivate_opcode deactiv_opcode;
  983.     struct vpvc              vpvc;
  984.     int                      ok;
  985.     enum fore200e_aal        aal = fore200e_atm2fore_aal(vcc->qos.aal);
  986.     FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
  987.     
  988.     if (activate) {
  989. FORE200E_VCC(vcc)->scheme = fore200e_select_scheme(vcc);
  990. activ_opcode.opcode = OPCODE_ACTIVATE_VCIN;
  991. activ_opcode.aal    = aal;
  992. activ_opcode.scheme = FORE200E_VCC(vcc)->scheme;
  993. activ_opcode.pad    = 0;
  994.     }
  995.     else {
  996. deactiv_opcode.opcode = OPCODE_DEACTIVATE_VCIN;
  997. deactiv_opcode.pad    = 0;
  998.     }
  999.     vpvc.vci = vcc->vci;
  1000.     vpvc.vpi = vcc->vpi;
  1001.     *entry->status = STATUS_PENDING;
  1002.     if (activate) {
  1003. #ifdef FORE200E_52BYTE_AAL0_SDU
  1004. mtu = 48;
  1005. #endif
  1006. /* the MTU is unused by the cp, except in the case of AAL0 */
  1007. fore200e->bus->write(mtu,                        &entry->cp_entry->cmd.activate_block.mtu);
  1008. fore200e->bus->write(*(u32*)&vpvc,         (u32*)&entry->cp_entry->cmd.activate_block.vpvc);
  1009. fore200e->bus->write(*(u32*)&activ_opcode, (u32*)&entry->cp_entry->cmd.activate_block.opcode);
  1010.     }
  1011.     else {
  1012. fore200e->bus->write(*(u32*)&vpvc,           (u32*)&entry->cp_entry->cmd.deactivate_block.vpvc);
  1013. fore200e->bus->write(*(u32*)&deactiv_opcode, (u32*)&entry->cp_entry->cmd.deactivate_block.opcode);
  1014.     }
  1015.     ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
  1016.     *entry->status = STATUS_FREE;
  1017.     if (ok == 0) {
  1018. printk(FORE200E "unable to %s vpvc %d.%d on device %sn",
  1019.        activate ? "open" : "close", vcc->vpi, vcc->vci, fore200e->name);
  1020. return -EIO;
  1021.     }
  1022.     DPRINTK(1, "vpvc %d.%d %sed on device %sn", vcc->vpi, vcc->vci, 
  1023.     activate ? "open" : "clos", fore200e->name);
  1024.     return 0;
  1025. }
  1026. static int
  1027. fore200e_walk_vccs(struct atm_vcc *vcc, short *vpi, int *vci)
  1028. {
  1029.     struct atm_vcc* walk;
  1030.     /* find a free VPI */
  1031.     if (*vpi == ATM_VPI_ANY) {
  1032. for (*vpi = 0, walk = vcc->dev->vccs; walk; walk = walk->next) {
  1033.     if ((walk->vci == *vci) && (walk->vpi == *vpi)) {
  1034. (*vpi)++;
  1035. walk = vcc->dev->vccs;
  1036.     }
  1037. }
  1038.     }
  1039.     /* find a free VCI */
  1040.     if (*vci == ATM_VCI_ANY) {
  1041. for (*vci = ATM_NOT_RSV_VCI, walk = vcc->dev->vccs; walk; walk = walk->next) {
  1042.     if ((walk->vpi = *vpi) && (walk->vci == *vci)) {
  1043. *vci = walk->vci + 1;
  1044. walk = vcc->dev->vccs;
  1045.     }
  1046. }
  1047.     }
  1048.     return 0;
  1049. }
  1050. #define FORE200E_MAX_BACK2BACK_CELLS 255    /* XXX depends on CDVT */
  1051. static void
  1052. fore200e_rate_ctrl(struct atm_qos* qos, struct tpd_rate* rate)
  1053. {
  1054.     if (qos->txtp.max_pcr < ATM_OC3_PCR) {
  1055.     
  1056. /* compute the data cells to idle cells ratio from the PCR */
  1057. rate->data_cells = qos->txtp.max_pcr * FORE200E_MAX_BACK2BACK_CELLS / ATM_OC3_PCR;
  1058. rate->idle_cells = FORE200E_MAX_BACK2BACK_CELLS - rate->data_cells;
  1059.     }
  1060.     else {
  1061. /* disable rate control */
  1062. rate->data_cells = rate->idle_cells = 0;
  1063.     }
  1064. }
  1065. static int
  1066. fore200e_open(struct atm_vcc *vcc, short vpi, int vci)
  1067. {
  1068.     struct fore200e*     fore200e = FORE200E_DEV(vcc->dev);
  1069.     struct fore200e_vcc* fore200e_vcc;
  1070.     
  1071.     /* find a free VPI/VCI */
  1072.     fore200e_walk_vccs(vcc, &vpi, &vci);
  1073.     vcc->vpi = vpi;
  1074.     vcc->vci = vci;
  1075.     /* ressource checking only? */
  1076.     if (vci == ATM_VCI_UNSPEC || vpi == ATM_VPI_UNSPEC)
  1077. return 0;
  1078.     set_bit(ATM_VF_ADDR, &vcc->flags);
  1079.     vcc->itf    = vcc->dev->number;
  1080.     DPRINTK(2, "opening %d.%d.%d:%d QoS = (tx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d; "
  1081.     "rx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d)n",
  1082.     vcc->itf, vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal),
  1083.     fore200e_traffic_class[ vcc->qos.txtp.traffic_class ],
  1084.     vcc->qos.txtp.min_pcr, vcc->qos.txtp.max_pcr, vcc->qos.txtp.max_cdv, vcc->qos.txtp.max_sdu,
  1085.     fore200e_traffic_class[ vcc->qos.rxtp.traffic_class ],
  1086.     vcc->qos.rxtp.min_pcr, vcc->qos.rxtp.max_pcr, vcc->qos.rxtp.max_cdv, vcc->qos.rxtp.max_sdu);
  1087.     
  1088.     if ((vcc->qos.txtp.traffic_class == ATM_CBR) && (vcc->qos.txtp.max_pcr > 0)) {
  1089. down(&fore200e->rate_sf);
  1090. if (fore200e->available_cell_rate < vcc->qos.txtp.max_pcr) {
  1091.     up(&fore200e->rate_sf);
  1092.     return -EAGAIN;
  1093. }
  1094. /* reserving the pseudo-CBR bandwidth at this point grants us
  1095.    to reduce the length of the critical section protected
  1096.    by 'rate_sf'. in counterpart, we have to reset the available
  1097.    bandwidth if we later encounter an error */
  1098. fore200e->available_cell_rate -= vcc->qos.txtp.max_pcr;
  1099. up(&fore200e->rate_sf);
  1100.     }
  1101.     
  1102.     fore200e_vcc = fore200e_kmalloc(sizeof(struct fore200e_vcc), GFP_KERNEL);
  1103.     if (fore200e_vcc == NULL) {
  1104. down(&fore200e->rate_sf);
  1105. fore200e->available_cell_rate += vcc->qos.txtp.max_pcr;
  1106. up(&fore200e->rate_sf);
  1107. return -ENOMEM;
  1108.     }
  1109.     FORE200E_VCC(vcc) = fore200e_vcc;
  1110.     
  1111.     if (fore200e_activate_vcin(fore200e, 1, vcc, vcc->qos.rxtp.max_sdu) < 0) {
  1112. kfree(fore200e_vcc);
  1113. down(&fore200e->rate_sf);
  1114. fore200e->available_cell_rate += vcc->qos.txtp.max_pcr;
  1115. up(&fore200e->rate_sf);
  1116. return -EBUSY;
  1117.     }
  1118.     
  1119.     /* compute rate control parameters */
  1120.     if ((vcc->qos.txtp.traffic_class == ATM_CBR) && (vcc->qos.txtp.max_pcr > 0)) {
  1121. fore200e_rate_ctrl(&vcc->qos, &fore200e_vcc->rate);
  1122. DPRINTK(3, "tx on %d.%d.%d:%d, tx PCR = %d, rx PCR = %d, data_cells = %u, idle_cells = %un",
  1123. vcc->itf, vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal),
  1124. vcc->qos.txtp.max_pcr, vcc->qos.rxtp.max_pcr, 
  1125. fore200e_vcc->rate.data_cells, fore200e_vcc->rate.idle_cells);
  1126.     }
  1127.     
  1128.     fore200e_vcc->tx_min_pdu = fore200e_vcc->rx_min_pdu = 65536;
  1129.     fore200e_vcc->tx_max_pdu = fore200e_vcc->rx_max_pdu = 0;
  1130.     
  1131.     set_bit(ATM_VF_READY, &vcc->flags);
  1132.     return 0;
  1133. }
  1134. static void
  1135. fore200e_close(struct atm_vcc* vcc)
  1136. {
  1137.     struct fore200e* fore200e = FORE200E_DEV(vcc->dev);
  1138.     
  1139.     DPRINTK(2, "closing %d.%d.%d:%dn", vcc->itf, vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal));
  1140.     
  1141.     fore200e_activate_vcin(fore200e, 0, vcc, 0);
  1142.     
  1143.     kfree(FORE200E_VCC(vcc));
  1144.     if ((vcc->qos.txtp.traffic_class == ATM_CBR) && (vcc->qos.txtp.max_pcr > 0)) {
  1145. down(&fore200e->rate_sf);
  1146. fore200e->available_cell_rate += vcc->qos.txtp.max_pcr;
  1147. up(&fore200e->rate_sf);
  1148.     }
  1149.     clear_bit(ATM_VF_READY, &vcc->flags);
  1150. }
  1151. #if 0
  1152. #define FORE200E_SYNC_SEND    /* wait tx completion before returning */
  1153. #endif
  1154. static int
  1155. fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
  1156. {
  1157.     struct fore200e*       fore200e     = FORE200E_DEV(vcc->dev);
  1158.     struct fore200e_vcc*   fore200e_vcc = FORE200E_VCC(vcc);
  1159.     struct host_txq*       txq          = &fore200e->host_txq;
  1160.     struct host_txq_entry* entry;
  1161.     struct tpd*            tpd;
  1162.     struct tpd_haddr       tpd_haddr;
  1163.     //unsigned long          flags;
  1164.     int                    retry        = CONFIG_ATM_FORE200E_TX_RETRY;
  1165.     int                    tx_copy      = 0;
  1166.     int                    tx_len       = skb->len;
  1167.     u32*                   cell_header  = NULL;
  1168.     unsigned char*         skb_data;
  1169.     int                    skb_len;
  1170. #ifdef FORE200E_52BYTE_AAL0_SDU
  1171.     if ((vcc->qos.aal == ATM_AAL0) && (vcc->qos.txtp.max_sdu == ATM_AAL0_SDU)) {
  1172. cell_header = (u32*) skb->data;
  1173. skb_data    = skb->data + 4;    /* skip 4-byte cell header */
  1174. skb_len     = tx_len = skb->len  - 4;
  1175. DPRINTK(3, "skipping user-supplied cell header 0x%08x", *cell_header);
  1176.     }
  1177.     else 
  1178. #endif
  1179.     {
  1180. skb_data = skb->data;
  1181. skb_len  = skb->len;
  1182.     }
  1183.     
  1184.   retry_here:
  1185.     
  1186.     tasklet_disable(&fore200e->tasklet);
  1187.     entry = &txq->host_entry[ txq->head ];
  1188.     
  1189.     if (*entry->status != STATUS_FREE) {
  1190. /* try to free completed tx queue entries */
  1191. fore200e_irq_tx(fore200e);
  1192. if (*entry->status != STATUS_FREE) {
  1193.     
  1194.     tasklet_enable(&fore200e->tasklet);
  1195.     /* retry once again? */
  1196.     if(--retry > 0)
  1197. goto retry_here;
  1198.     
  1199.     atomic_inc(&vcc->stats->tx_err);
  1200.     
  1201.     printk(FORE200E "tx queue of device %s is saturated, PDU dropped - heartbeat is %08xn",
  1202.    fore200e->name, fore200e->cp_queues->heartbeat);
  1203.     if (vcc->pop)
  1204. vcc->pop(vcc, skb);
  1205.     else
  1206. dev_kfree_skb(skb);
  1207.     return -EIO;
  1208. }
  1209.     }
  1210.     tpd = entry->tpd;
  1211.     if (((unsigned long)skb_data) & 0x3) {
  1212. DPRINTK(2, "misaligned tx PDU on device %sn", fore200e->name);
  1213. tx_copy = 1;
  1214. tx_len  = skb_len;
  1215.     }
  1216.     if ((vcc->qos.aal == ATM_AAL0) && (skb_len % ATM_CELL_PAYLOAD)) {
  1217. /* this simply NUKES the PCA-200E board */
  1218. DPRINTK(2, "incomplete tx AAL0 PDU on device %sn", fore200e->name);
  1219. tx_copy = 1;
  1220. tx_len  = ((skb_len / ATM_CELL_PAYLOAD) + 1) * ATM_CELL_PAYLOAD;
  1221.     }
  1222.     
  1223.     if (tx_copy) {
  1224. entry->data = kmalloc(tx_len, GFP_ATOMIC | GFP_DMA);
  1225. if (entry->data == NULL) {
  1226.     
  1227.     tasklet_enable(&fore200e->tasklet);
  1228.     if (vcc->pop)
  1229. vcc->pop(vcc, skb);
  1230.     else
  1231. dev_kfree_skb(skb);
  1232.     return -ENOMEM;
  1233. }
  1234. memcpy(entry->data, skb_data, skb_len);
  1235. if (skb_len < tx_len)
  1236.     memset(entry->data + skb_len, 0x00, tx_len - skb_len);
  1237. tpd->tsd[ 0 ].buffer = fore200e->bus->dma_map(fore200e, entry->data, tx_len, FORE200E_DMA_TODEVICE);
  1238.     }
  1239.     else {
  1240. entry->data = NULL;
  1241. tpd->tsd[ 0 ].buffer = fore200e->bus->dma_map(fore200e, skb_data, tx_len, FORE200E_DMA_TODEVICE);
  1242.     }
  1243.     tpd->tsd[ 0 ].length = tx_len;
  1244.     FORE200E_NEXT_ENTRY(txq->head, QUEUE_SIZE_TX);
  1245.     txq->txing++;
  1246.     tasklet_enable(&fore200e->tasklet);
  1247.     /* ensure DMA synchronisation */
  1248.     fore200e->bus->dma_sync(fore200e, tpd->tsd[ 0 ].buffer, tpd->tsd[ 0 ].length, FORE200E_DMA_TODEVICE);
  1249.     
  1250.     DPRINTK(3, "tx on %d.%d.%d:%d, len = %u (%u)n", 
  1251.     vcc->itf, vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal),
  1252.     tpd->tsd[0].length, skb_len);
  1253.     if (skb_len < fore200e_vcc->tx_min_pdu)
  1254. fore200e_vcc->tx_min_pdu = skb_len;
  1255.     if (skb_len > fore200e_vcc->tx_max_pdu)
  1256. fore200e_vcc->tx_max_pdu = skb_len;
  1257.     
  1258.     entry->vcc = vcc;
  1259.     entry->skb = skb;
  1260.     /* set tx rate control information */
  1261.     tpd->rate.data_cells = fore200e_vcc->rate.data_cells;
  1262.     tpd->rate.idle_cells = fore200e_vcc->rate.idle_cells;
  1263.     if (cell_header) {
  1264. tpd->atm_header.clp = (*cell_header & ATM_HDR_CLP);
  1265. tpd->atm_header.plt = (*cell_header & ATM_HDR_PTI_MASK) >> ATM_HDR_PTI_SHIFT;
  1266. tpd->atm_header.vci = (*cell_header & ATM_HDR_VCI_MASK) >> ATM_HDR_VCI_SHIFT;
  1267. tpd->atm_header.vpi = (*cell_header & ATM_HDR_VPI_MASK) >> ATM_HDR_VPI_SHIFT;
  1268. tpd->atm_header.gfc = (*cell_header & ATM_HDR_GFC_MASK) >> ATM_HDR_GFC_SHIFT;
  1269.     }
  1270.     else {
  1271. /* set the ATM header, common to all cells conveying the PDU */
  1272. tpd->atm_header.clp = 0;
  1273. tpd->atm_header.plt = 0;
  1274. tpd->atm_header.vci = vcc->vci;
  1275. tpd->atm_header.vpi = vcc->vpi;
  1276. tpd->atm_header.gfc = 0;
  1277.     }
  1278.     tpd->spec.length = tx_len;
  1279.     tpd->spec.nseg   = 1;
  1280.     tpd->spec.aal    = fore200e_atm2fore_aal(vcc->qos.aal);
  1281. #ifdef FORE200E_SYNC_SEND
  1282.     tpd->spec.intr   = 0;
  1283. #else
  1284.     tpd->spec.intr   = 1;
  1285. #endif
  1286.     tpd_haddr.size  = sizeof(struct tpd) / 32;    /* size is expressed in 32 byte blocks */
  1287.     tpd_haddr.pad   = 0;
  1288.     tpd_haddr.haddr = entry->tpd_dma >> 5;        /* shift the address, as we are in a bitfield */
  1289.     *entry->status = STATUS_PENDING;
  1290.     fore200e->bus->write(*(u32*)&tpd_haddr, (u32*)&entry->cp_entry->tpd_haddr);
  1291. #ifdef FORE200E_SYNC_SEND
  1292.     {
  1293. int ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 10);
  1294. fore200e->bus->dma_unmap(fore200e, entry->tpd->tsd[ 0 ].buffer, entry->tpd->tsd[ 0 ].length,
  1295.  FORE200E_DMA_TODEVICE);
  1296. /* free tmp copy of misaligned data */
  1297. if (entry->data)
  1298.     kfree(entry->data);
  1299. /* notify tx completion */
  1300. if (vcc->pop)
  1301.     vcc->pop(vcc, skb);
  1302. else
  1303.     dev_kfree_skb(skb);
  1304. if (ok == 0) {
  1305.     printk(FORE200E "synchronous tx on %d:%d:%d failedn", vcc->itf, vcc->vpi, vcc->vci);
  1306.     atomic_inc(&entry->vcc->stats->tx_err);
  1307.     return -EIO;
  1308. }
  1309. atomic_inc(&entry->vcc->stats->tx);
  1310. DPRINTK(3, "synchronous tx on %d:%d:%d succeededn", vcc->itf, vcc->vpi, vcc->vci);
  1311.     }
  1312. #endif
  1313.     return 0;
  1314. }
  1315. static int
  1316. fore200e_getstats(struct fore200e* fore200e)
  1317. {
  1318.     struct host_cmdq*       cmdq  = &fore200e->host_cmdq;
  1319.     struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
  1320.     struct stats_opcode     opcode;
  1321.     int                     ok;
  1322.     u32                     stats_dma_addr;
  1323.     if (fore200e->stats == NULL) {
  1324. fore200e->stats = fore200e_kmalloc(sizeof(struct stats), GFP_KERNEL | GFP_DMA);
  1325. if (fore200e->stats == NULL)
  1326.     return -ENOMEM;
  1327.     }
  1328.     
  1329.     stats_dma_addr = fore200e->bus->dma_map(fore200e, fore200e->stats, sizeof(struct stats), FORE200E_DMA_FROMDEVICE);
  1330.     
  1331.     FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
  1332.     opcode.opcode = OPCODE_GET_STATS;
  1333.     opcode.pad    = 0;
  1334.     fore200e->bus->write(stats_dma_addr, &entry->cp_entry->cmd.stats_block.stats_haddr);
  1335.     
  1336.     *entry->status = STATUS_PENDING;
  1337.     fore200e->bus->write(*(u32*)&opcode, (u32*)&entry->cp_entry->cmd.stats_block.opcode);
  1338.     ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
  1339.     *entry->status = STATUS_FREE;
  1340.     fore200e->bus->dma_unmap(fore200e, stats_dma_addr, sizeof(struct stats), FORE200E_DMA_FROMDEVICE);
  1341.     
  1342.     if (ok == 0) {
  1343. printk(FORE200E "unable to get statistics from device %sn", fore200e->name);
  1344. return -EIO;
  1345.     }
  1346.     return 0;
  1347. }
  1348. static int
  1349. fore200e_getsockopt (struct atm_vcc* vcc, int level, int optname, void* optval, int optlen)
  1350. {
  1351.     // struct fore200e* fore200e = FORE200E_DEV(vcc->dev);
  1352.     DPRINTK(2, "getsockopt %d.%d.%d, level = %d, optname = 0x%x, optval = 0x%p, optlen = %dn",
  1353.     vcc->itf, vcc->vpi, vcc->vci, level, optname, optval, optlen);
  1354.     return -EINVAL;
  1355. }
  1356. static int
  1357. fore200e_setsockopt(struct atm_vcc* vcc, int level, int optname, void* optval, int optlen)
  1358. {
  1359.     // struct fore200e* fore200e = FORE200E_DEV(vcc->dev);
  1360.     
  1361.     DPRINTK(2, "setsockopt %d.%d.%d, level = %d, optname = 0x%x, optval = 0x%p, optlen = %dn",
  1362.     vcc->itf, vcc->vpi, vcc->vci, level, optname, optval, optlen);
  1363.     
  1364.     return -EINVAL;
  1365. }
  1366. #if 0 /* currently unused */
  1367. static int
  1368. fore200e_get_oc3(struct fore200e* fore200e, struct oc3_regs* regs)
  1369. {
  1370.     struct host_cmdq*       cmdq  = &fore200e->host_cmdq;
  1371.     struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
  1372.     struct oc3_opcode       opcode;
  1373.     int                     ok;
  1374.     u32                     oc3_regs_dma_addr;
  1375.     oc3_regs_dma_addr = fore200e->bus->dma_map(fore200e, regs, sizeof(struct oc3_regs), FORE200E_DMA_FROMDEVICE);
  1376.     FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
  1377.     opcode.opcode = OPCODE_GET_OC3;
  1378.     opcode.reg    = 0;
  1379.     opcode.value  = 0;
  1380.     opcode.mask   = 0;
  1381.     fore200e->bus->write(oc3_regs_dma_addr, &entry->cp_entry->cmd.oc3_block.regs_haddr);
  1382.     
  1383.     *entry->status = STATUS_PENDING;
  1384.     fore200e->bus->write(*(u32*)&opcode, (u32*)&entry->cp_entry->cmd.oc3_block.opcode);
  1385.     ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
  1386.     *entry->status = STATUS_FREE;
  1387.     fore200e->bus->dma_unmap(fore200e, oc3_regs_dma_addr, sizeof(struct oc3_regs), FORE200E_DMA_FROMDEVICE);
  1388.     
  1389.     if (ok == 0) {
  1390. printk(FORE200E "unable to get OC-3 regs of device %sn", fore200e->name);
  1391. return -EIO;
  1392.     }
  1393.     return 0;
  1394. }
  1395. #endif
  1396. static int
  1397. fore200e_set_oc3(struct fore200e* fore200e, u32 reg, u32 value, u32 mask)
  1398. {
  1399.     struct host_cmdq*       cmdq  = &fore200e->host_cmdq;
  1400.     struct host_cmdq_entry* entry = &cmdq->host_entry[ cmdq->head ];
  1401.     struct oc3_opcode       opcode;
  1402.     int                     ok;
  1403.     FORE200E_NEXT_ENTRY(cmdq->head, QUEUE_SIZE_CMD);
  1404.     opcode.opcode = OPCODE_SET_OC3;
  1405.     opcode.reg    = reg;
  1406.     opcode.value  = value;
  1407.     opcode.mask   = mask;
  1408.     fore200e->bus->write(0, &entry->cp_entry->cmd.oc3_block.regs_haddr);
  1409.     
  1410.     *entry->status = STATUS_PENDING;
  1411.     fore200e->bus->write(*(u32*)&opcode, (u32*)&entry->cp_entry->cmd.oc3_block.opcode);
  1412.     ok = fore200e_poll(fore200e, entry->status, STATUS_COMPLETE, 400);
  1413.     *entry->status = STATUS_FREE;
  1414.     if (ok == 0) {
  1415. printk(FORE200E "unable to set OC-3 reg 0x%02x of device %sn", reg, fore200e->name);
  1416. return -EIO;
  1417.     }
  1418.     return 0;
  1419. }
  1420. static int
  1421. fore200e_setloop(struct fore200e* fore200e, int loop_mode)
  1422. {
  1423.     u32 mct_value, mct_mask;
  1424.     int error;
  1425.     if (!capable(CAP_NET_ADMIN))
  1426. return -EPERM;
  1427.     
  1428.     switch (loop_mode) {
  1429.     case ATM_LM_NONE:
  1430. mct_value = 0; 
  1431. mct_mask  = SUNI_MCT_DLE | SUNI_MCT_LLE;
  1432. break;
  1433.     case ATM_LM_LOC_PHY:
  1434. mct_value = mct_mask = SUNI_MCT_DLE;
  1435. break;
  1436.     case ATM_LM_RMT_PHY:
  1437. mct_value = mct_mask = SUNI_MCT_LLE;
  1438. break;
  1439.     default:
  1440. return -EINVAL;
  1441.     }
  1442.     error = fore200e_set_oc3(fore200e, SUNI_MCT, mct_value, mct_mask);
  1443.     if ( error == 0)
  1444. fore200e->loop_mode = loop_mode;
  1445.     return error;
  1446. }
  1447. static inline unsigned int
  1448. fore200e_swap(unsigned int in)
  1449. {
  1450. #if defined(__LITTLE_ENDIAN)
  1451.     return swab32(in);
  1452. #else
  1453.     return in;
  1454. #endif
  1455. }
  1456. static int
  1457. fore200e_fetch_stats(struct fore200e* fore200e, struct sonet_stats* arg)
  1458. {
  1459.     struct sonet_stats tmp;
  1460.     if (fore200e_getstats(fore200e) < 0)
  1461. return -EIO;
  1462.     tmp.section_bip = fore200e_swap(fore200e->stats->oc3.section_bip8_errors);
  1463.     tmp.line_bip    = fore200e_swap(fore200e->stats->oc3.line_bip24_errors);
  1464.     tmp.path_bip    = fore200e_swap(fore200e->stats->oc3.path_bip8_errors);
  1465.     tmp.line_febe   = fore200e_swap(fore200e->stats->oc3.line_febe_errors);
  1466.     tmp.path_febe   = fore200e_swap(fore200e->stats->oc3.path_febe_errors);
  1467.     tmp.corr_hcs    = fore200e_swap(fore200e->stats->oc3.corr_hcs_errors);
  1468.     tmp.uncorr_hcs  = fore200e_swap(fore200e->stats->oc3.ucorr_hcs_errors);
  1469.     tmp.tx_cells    = fore200e_swap(fore200e->stats->aal0.cells_transmitted)  +
  1470.               fore200e_swap(fore200e->stats->aal34.cells_transmitted) +
  1471.               fore200e_swap(fore200e->stats->aal5.cells_transmitted);
  1472.     tmp.rx_cells    = fore200e_swap(fore200e->stats->aal0.cells_received)     +
  1473.               fore200e_swap(fore200e->stats->aal34.cells_received)    +
  1474.               fore200e_swap(fore200e->stats->aal5.cells_received);
  1475.     if (arg)
  1476. return copy_to_user(arg, &tmp, sizeof(struct sonet_stats)) ? -EFAULT : 0;
  1477.     
  1478.     return 0;
  1479. }
  1480. static int
  1481. fore200e_ioctl(struct atm_dev* dev, unsigned int cmd, void* arg)
  1482. {
  1483.     struct fore200e* fore200e = FORE200E_DEV(dev);
  1484.     
  1485.     DPRINTK(2, "ioctl cmd = 0x%x (%u), arg = 0x%p (%lu)n", cmd, cmd, arg, (unsigned long)arg);
  1486.     switch (cmd) {
  1487.     case SONET_GETSTAT:
  1488. return fore200e_fetch_stats(fore200e, (struct sonet_stats*)arg);
  1489.     case SONET_GETDIAG:
  1490. return put_user(0, (int*)arg) ? -EFAULT : 0;
  1491.     case ATM_SETLOOP:
  1492. return fore200e_setloop(fore200e, (int)(unsigned long)arg);
  1493.     case ATM_GETLOOP:
  1494. return put_user(fore200e->loop_mode, (int*)arg) ? -EFAULT : 0;
  1495.     case ATM_QUERYLOOP:
  1496. return put_user(ATM_LM_LOC_PHY | ATM_LM_RMT_PHY, (int*)arg) ? -EFAULT : 0;
  1497.     }
  1498.     return -ENOSYS; /* not implemented */
  1499. }
  1500. static int
  1501. fore200e_change_qos(struct atm_vcc* vcc,struct atm_qos* qos, int flags)
  1502. {
  1503.     struct fore200e_vcc* fore200e_vcc = FORE200E_VCC(vcc);
  1504.     struct fore200e*     fore200e     = FORE200E_DEV(vcc->dev);
  1505.     DPRINTK(2, "change_qos %d.%d.%d, "
  1506.     "(tx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d; "
  1507.     "rx: cl=%s, pcr=%d-%d, cdv=%d, max_sdu=%d), flags = 0x%xn"
  1508.     "available_cell_rate = %u",
  1509.     vcc->itf, vcc->vpi, vcc->vci,
  1510.     fore200e_traffic_class[ qos->txtp.traffic_class ],
  1511.     qos->txtp.min_pcr, qos->txtp.max_pcr, qos->txtp.max_cdv, qos->txtp.max_sdu,
  1512.     fore200e_traffic_class[ qos->rxtp.traffic_class ],
  1513.     qos->rxtp.min_pcr, qos->rxtp.max_pcr, qos->rxtp.max_cdv, qos->rxtp.max_sdu,
  1514.     flags, fore200e->available_cell_rate);
  1515.     if ((qos->txtp.traffic_class == ATM_CBR) && (qos->txtp.max_pcr > 0)) {
  1516. down(&fore200e->rate_sf);
  1517. if (fore200e->available_cell_rate + vcc->qos.txtp.max_pcr < qos->txtp.max_pcr) {
  1518.     up(&fore200e->rate_sf);
  1519.     return -EAGAIN;
  1520. }
  1521. fore200e->available_cell_rate += vcc->qos.txtp.max_pcr;
  1522. fore200e->available_cell_rate -= qos->txtp.max_pcr;
  1523. up(&fore200e->rate_sf);
  1524. memcpy(&vcc->qos, qos, sizeof(struct atm_qos));
  1525. /* update rate control parameters */
  1526. fore200e_rate_ctrl(qos, &fore200e_vcc->rate);
  1527. set_bit(ATM_VF_HASQOS, &vcc->flags);
  1528. return 0;
  1529.     }
  1530.     
  1531.     return -EINVAL;
  1532. }
  1533.     
  1534. static int __init
  1535. fore200e_irq_request(struct fore200e* fore200e)
  1536. {
  1537.     if (request_irq(fore200e->irq, fore200e_interrupt, SA_SHIRQ, fore200e->name, fore200e->atm_dev) < 0) {
  1538. printk(FORE200E "unable to reserve IRQ %s for device %sn",
  1539.        fore200e_irq_itoa(fore200e->irq), fore200e->name);
  1540. return -EBUSY;
  1541.     }
  1542.     printk(FORE200E "IRQ %s reserved for device %sn",
  1543.    fore200e_irq_itoa(fore200e->irq), fore200e->name);
  1544.     tasklet_init(&fore200e->tasklet, fore200e_tasklet, (unsigned long)fore200e);
  1545.     fore200e->state = FORE200E_STATE_IRQ;
  1546.     return 0;
  1547. }
  1548. static int __init
  1549. fore200e_get_esi(struct fore200e* fore200e)
  1550. {
  1551.     struct prom_data* prom = fore200e_kmalloc(sizeof(struct prom_data), GFP_KERNEL | GFP_DMA);
  1552.     int ok, i;
  1553.     if (!prom)
  1554. return -ENOMEM;
  1555.     ok = fore200e->bus->prom_read(fore200e, prom);
  1556.     if (ok < 0) {
  1557. fore200e_kfree(prom);
  1558. return -EBUSY;
  1559.     }
  1560.     printk(FORE200E "device %s, rev. %c, S/N: %d, ESI: %02x:%02x:%02x:%02x:%02x:%02xn", 
  1561.    fore200e->name, 
  1562.    (prom->hw_revision & 0xFF) + '@',    /* probably meaningless with SBA boards */
  1563.    prom->serial_number & 0xFFFF,
  1564.    prom->mac_addr[ 2 ], prom->mac_addr[ 3 ], prom->mac_addr[ 4 ],
  1565.    prom->mac_addr[ 5 ], prom->mac_addr[ 6 ], prom->mac_addr[ 7 ]);
  1566.     for (i = 0; i < ESI_LEN; i++) {
  1567. fore200e->esi[ i ] = fore200e->atm_dev->esi[ i ] = prom->mac_addr[ i + 2 ];
  1568.     }
  1569.     
  1570.     fore200e_kfree(prom);
  1571.     return 0;
  1572. }
  1573. static int __init
  1574. fore200e_alloc_rx_buf(struct fore200e* fore200e)
  1575. {
  1576.     int scheme, magn, nbr, size, i;
  1577.     struct host_bsq* bsq;
  1578.     struct buffer*   buffer;
  1579.     for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
  1580. for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
  1581.     bsq = &fore200e->host_bsq[ scheme ][ magn ];
  1582.     nbr  = fore200e_rx_buf_nbr[ scheme ][ magn ];
  1583.     size = fore200e_rx_buf_size[ scheme ][ magn ];
  1584.     DPRINTK(2, "rx buffers %d / %d are being allocatedn", scheme, magn);
  1585.     /* allocate the array of receive buffers */
  1586.     buffer = bsq->buffer = fore200e_kmalloc(nbr * sizeof(struct buffer), GFP_KERNEL);
  1587.     if (buffer == NULL)
  1588. return -ENOMEM;
  1589.     for (i = 0; i < nbr; i++) {
  1590. buffer[ i ].scheme = scheme;
  1591. buffer[ i ].magn   = magn;
  1592. /* allocate the receive buffer body */
  1593. if (fore200e_chunk_alloc(fore200e,
  1594.  &buffer[ i ].data, size, fore200e->bus->buffer_alignment,
  1595.  FORE200E_DMA_FROMDEVICE) < 0) {
  1596.     
  1597.     while (i > 0)
  1598. fore200e_chunk_free(fore200e, &buffer[ --i ].data);
  1599.     fore200e_kfree(buffer);
  1600.     
  1601.     return -ENOMEM;
  1602. }
  1603.     }
  1604.     /* set next free buffer index */
  1605.     bsq->free = 0;
  1606. }
  1607.     }
  1608.     fore200e->state = FORE200E_STATE_ALLOC_BUF;
  1609.     return 0;
  1610. }
  1611. static int __init
  1612. fore200e_init_bs_queue(struct fore200e* fore200e)
  1613. {
  1614.     int scheme, magn, i;
  1615.     struct host_bsq*     bsq;
  1616.     struct cp_bsq_entry* cp_entry;
  1617.     for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++) {
  1618. for (magn = 0; magn < BUFFER_MAGN_NBR; magn++) {
  1619.     DPRINTK(2, "buffer supply queue %d / %d is being initializedn", scheme, magn);
  1620.     bsq = &fore200e->host_bsq[ scheme ][ magn ];
  1621.     /* allocate and align the array of status words */
  1622.     if (fore200e->bus->dma_chunk_alloc(fore200e,
  1623.        &bsq->status,
  1624.        sizeof(enum status), 
  1625.        QUEUE_SIZE_BS,
  1626.        fore200e->bus->status_alignment) < 0) {
  1627. return -ENOMEM;
  1628.     }
  1629.     /* allocate and align the array of receive buffer descriptors */
  1630.     if (fore200e->bus->dma_chunk_alloc(fore200e,
  1631.        &bsq->rbd_block,
  1632.        sizeof(struct rbd_block),
  1633.        QUEUE_SIZE_BS,
  1634.        fore200e->bus->descr_alignment) < 0) {
  1635. fore200e->bus->dma_chunk_free(fore200e, &bsq->status);
  1636. return -ENOMEM;
  1637.     }
  1638.     
  1639.     /* get the base address of the cp resident buffer supply queue entries */
  1640.     cp_entry = (struct cp_bsq_entry*)(fore200e->virt_base + 
  1641.        fore200e->bus->read(&fore200e->cp_queues->cp_bsq[ scheme ][ magn ]));
  1642.     
  1643.     /* fill the host resident and cp resident buffer supply queue entries */
  1644.     for (i = 0; i < QUEUE_SIZE_BS; i++) {
  1645. bsq->host_entry[ i ].status = 
  1646.                      FORE200E_INDEX(bsq->status.align_addr, enum status, i);
  1647.         bsq->host_entry[ i ].rbd_block =
  1648.                      FORE200E_INDEX(bsq->rbd_block.align_addr, struct rbd_block, i);
  1649. bsq->host_entry[ i ].rbd_block_dma =
  1650.                      FORE200E_DMA_INDEX(bsq->rbd_block.dma_addr, struct rbd_block, i);
  1651. bsq->host_entry[ i ].cp_entry      = &cp_entry[ i ];
  1652. *bsq->host_entry[ i ].status   = STATUS_FREE;
  1653. fore200e->bus->write(FORE200E_DMA_INDEX(bsq->status.dma_addr, enum status, i), 
  1654.      &cp_entry[ i ].status_haddr);
  1655.     }
  1656. }
  1657.     }
  1658.     fore200e->state = FORE200E_STATE_INIT_BSQ;
  1659.     return 0;
  1660. }
  1661. static int __init
  1662. fore200e_init_rx_queue(struct fore200e* fore200e)
  1663. {
  1664.     struct host_rxq*     rxq =  &fore200e->host_rxq;
  1665.     struct cp_rxq_entry* cp_entry;
  1666.     int i;
  1667.     DPRINTK(2, "receive queue is being initializedn");
  1668.     /* allocate and align the array of status words */
  1669.     if (fore200e->bus->dma_chunk_alloc(fore200e,
  1670.        &rxq->status,
  1671.        sizeof(enum status), 
  1672.        QUEUE_SIZE_RX,
  1673.        fore200e->bus->status_alignment) < 0) {
  1674. return -ENOMEM;
  1675.     }
  1676.     /* allocate and align the array of receive PDU descriptors */
  1677.     if (fore200e->bus->dma_chunk_alloc(fore200e,
  1678.        &rxq->rpd,
  1679.        sizeof(struct rpd), 
  1680.        QUEUE_SIZE_RX,
  1681.        fore200e->bus->descr_alignment) < 0) {
  1682. fore200e->bus->dma_chunk_free(fore200e, &rxq->status);
  1683. return -ENOMEM;
  1684.     }
  1685.     /* get the base address of the cp resident rx queue entries */
  1686.     cp_entry = (struct cp_rxq_entry*)(fore200e->virt_base + 
  1687.       fore200e->bus->read(&fore200e->cp_queues->cp_rxq));
  1688.     /* fill the host resident and cp resident rx entries */
  1689.     for (i=0; i < QUEUE_SIZE_RX; i++) {
  1690. rxq->host_entry[ i ].status = 
  1691.                      FORE200E_INDEX(rxq->status.align_addr, enum status, i);
  1692. rxq->host_entry[ i ].rpd = 
  1693.                      FORE200E_INDEX(rxq->rpd.align_addr, struct rpd, i);
  1694. rxq->host_entry[ i ].rpd_dma = 
  1695.                      FORE200E_DMA_INDEX(rxq->rpd.dma_addr, struct rpd, i);
  1696. rxq->host_entry[ i ].cp_entry = &cp_entry[ i ];
  1697. *rxq->host_entry[ i ].status = STATUS_FREE;
  1698. fore200e->bus->write(FORE200E_DMA_INDEX(rxq->status.dma_addr, enum status, i), 
  1699.      &cp_entry[ i ].status_haddr);
  1700. fore200e->bus->write(FORE200E_DMA_INDEX(rxq->rpd.dma_addr, struct rpd, i),
  1701.      &cp_entry[ i ].rpd_haddr);
  1702.     }
  1703.     /* set the head entry of the queue */
  1704.     rxq->head = 0;
  1705.     fore200e->state = FORE200E_STATE_INIT_RXQ;
  1706.     return 0;
  1707. }
  1708. static int __init
  1709. fore200e_init_tx_queue(struct fore200e* fore200e)
  1710. {
  1711.     struct host_txq*     txq =  &fore200e->host_txq;
  1712.     struct cp_txq_entry* cp_entry;
  1713.     int i;
  1714.     DPRINTK(2, "transmit queue is being initializedn");
  1715.     /* allocate and align the array of status words */
  1716.     if (fore200e->bus->dma_chunk_alloc(fore200e,
  1717.        &txq->status,
  1718.        sizeof(enum status), 
  1719.        QUEUE_SIZE_TX,
  1720.        fore200e->bus->status_alignment) < 0) {
  1721. return -ENOMEM;
  1722.     }
  1723.     /* allocate and align the array of transmit PDU descriptors */
  1724.     if (fore200e->bus->dma_chunk_alloc(fore200e,
  1725.        &txq->tpd,
  1726.        sizeof(struct tpd), 
  1727.        QUEUE_SIZE_TX,
  1728.        fore200e->bus->descr_alignment) < 0) {
  1729. fore200e->bus->dma_chunk_free(fore200e, &txq->status);
  1730. return -ENOMEM;
  1731.     }
  1732.     /* get the base address of the cp resident tx queue entries */
  1733.     cp_entry = (struct cp_txq_entry*)(fore200e->virt_base + 
  1734.       fore200e->bus->read(&fore200e->cp_queues->cp_txq));
  1735.     /* fill the host resident and cp resident tx entries */
  1736.     for (i=0; i < QUEUE_SIZE_TX; i++) {
  1737. txq->host_entry[ i ].status = 
  1738.                      FORE200E_INDEX(txq->status.align_addr, enum status, i);
  1739. txq->host_entry[ i ].tpd = 
  1740.                      FORE200E_INDEX(txq->tpd.align_addr, struct tpd, i);
  1741. txq->host_entry[ i ].tpd_dma  = 
  1742.                              FORE200E_DMA_INDEX(txq->tpd.dma_addr, struct tpd, i);
  1743. txq->host_entry[ i ].cp_entry = &cp_entry[ i ];
  1744. *txq->host_entry[ i ].status = STATUS_FREE;
  1745. fore200e->bus->write(FORE200E_DMA_INDEX(txq->status.dma_addr, enum status, i), 
  1746.      &cp_entry[ i ].status_haddr);
  1747.         /* although there is a one-to-one mapping of tx queue entries and tpds,
  1748.    we do not write here the DMA (physical) base address of each tpd into
  1749.    the related cp resident entry, because the cp relies on this write
  1750.    operation to detect that a new pdu has been submitted for tx */
  1751. }
  1752.     /* set the head entry of the queue */
  1753.     txq->head = 0;
  1754.     fore200e->state = FORE200E_STATE_INIT_TXQ;
  1755.     return 0;
  1756. }
  1757. static int __init
  1758. fore200e_init_cmd_queue(struct fore200e* fore200e)
  1759. {
  1760.     struct host_cmdq*     cmdq =  &fore200e->host_cmdq;
  1761.     struct cp_cmdq_entry* cp_entry;
  1762.     int i;
  1763.     DPRINTK(2, "command queue is being initializedn");
  1764.     /* allocate and align the array of status words */
  1765.     if (fore200e->bus->dma_chunk_alloc(fore200e,
  1766.        &cmdq->status,
  1767.  sizeof(enum status), 
  1768.  QUEUE_SIZE_CMD,
  1769.  fore200e->bus->status_alignment) < 0) {
  1770. return -ENOMEM;
  1771.     }
  1772.     
  1773.     /* get the base address of the cp resident cmd queue entries */
  1774.     cp_entry = (struct cp_cmdq_entry*)(fore200e->virt_base + 
  1775.        fore200e->bus->read(&fore200e->cp_queues->cp_cmdq));
  1776.     /* fill the host resident and cp resident cmd entries */
  1777.     for (i=0; i < QUEUE_SIZE_CMD; i++) {
  1778. cmdq->host_entry[ i ].status   = 
  1779.                               FORE200E_INDEX(cmdq->status.align_addr, enum status, i);
  1780. cmdq->host_entry[ i ].cp_entry = &cp_entry[ i ];
  1781. *cmdq->host_entry[ i ].status = STATUS_FREE;
  1782. fore200e->bus->write(FORE200E_DMA_INDEX(cmdq->status.dma_addr, enum status, i), 
  1783.                              &cp_entry[ i ].status_haddr);
  1784.     }
  1785.     /* set the head entry of the queue */
  1786.     cmdq->head = 0;
  1787.     fore200e->state = FORE200E_STATE_INIT_CMDQ;
  1788.     return 0;
  1789. }
  1790. static void __init
  1791. fore200e_param_bs_queue(struct fore200e* fore200e,
  1792. enum buffer_scheme scheme, enum buffer_magn magn,
  1793. int queue_length, int pool_size, int supply_blksize)
  1794. {
  1795.     struct bs_spec* bs_spec = &fore200e->cp_queues->init.bs_spec[ scheme ][ magn ];
  1796.     /* dumb value; the firmware doesn't allow us to activate a VC while
  1797.        selecting a buffer scheme with zero-sized rbd pools */
  1798.     if (pool_size == 0)
  1799. pool_size = 64;
  1800.     fore200e->bus->write(queue_length,                           &bs_spec->queue_length);
  1801.     fore200e->bus->write(fore200e_rx_buf_size[ scheme ][ magn ], &bs_spec->buffer_size);
  1802.     fore200e->bus->write(pool_size,                              &bs_spec->pool_size);
  1803.     fore200e->bus->write(supply_blksize,                         &bs_spec->supply_blksize);
  1804. }
  1805. static int __init
  1806. fore200e_initialize(struct fore200e* fore200e)
  1807. {
  1808.     struct cp_queues* cpq;
  1809.     int               ok, scheme, magn;
  1810.     DPRINTK(2, "device %s being initializedn", fore200e->name);
  1811.     init_MUTEX(&fore200e->rate_sf);
  1812.     
  1813.     cpq = fore200e->cp_queues = (struct cp_queues*) (fore200e->virt_base + FORE200E_CP_QUEUES_OFFSET);
  1814.     /* enable cp to host interrupts */
  1815.     fore200e->bus->write(1, &cpq->imask);
  1816.     if (fore200e->bus->irq_enable)
  1817. fore200e->bus->irq_enable(fore200e);
  1818.     
  1819.     fore200e->bus->write(NBR_CONNECT, &cpq->init.num_connect);
  1820.     fore200e->bus->write(QUEUE_SIZE_CMD, &cpq->init.cmd_queue_len);
  1821.     fore200e->bus->write(QUEUE_SIZE_RX,  &cpq->init.rx_queue_len);
  1822.     fore200e->bus->write(QUEUE_SIZE_TX,  &cpq->init.tx_queue_len);
  1823.     fore200e->bus->write(RSD_EXTENSION,  &cpq->init.rsd_extension);
  1824.     fore200e->bus->write(TSD_EXTENSION,  &cpq->init.tsd_extension);
  1825.     for (scheme = 0; scheme < BUFFER_SCHEME_NBR; scheme++)
  1826. for (magn = 0; magn < BUFFER_MAGN_NBR; magn++)
  1827.     fore200e_param_bs_queue(fore200e, scheme, magn,
  1828.     QUEUE_SIZE_BS, 
  1829.     fore200e_rx_buf_nbr[ scheme ][ magn ],
  1830.     RBD_BLK_SIZE);
  1831.     /* issue the initialize command */
  1832.     fore200e->bus->write(STATUS_PENDING,    &cpq->init.status);
  1833.     fore200e->bus->write(OPCODE_INITIALIZE, &cpq->init.opcode);
  1834.     ok = fore200e_io_poll(fore200e, &cpq->init.status, STATUS_COMPLETE, 3000);
  1835.     if (ok == 0) {
  1836. printk(FORE200E "device %s initialization failedn", fore200e->name);
  1837. return -ENODEV;
  1838.     }
  1839.     printk(FORE200E "device %s initializedn", fore200e->name);
  1840.     fore200e->state = FORE200E_STATE_INITIALIZE;
  1841.     return 0;
  1842. }
  1843. static void __init
  1844. fore200e_monitor_putc(struct fore200e* fore200e, char c)
  1845. {
  1846.     struct cp_monitor* monitor = fore200e->cp_monitor;
  1847. #if 0
  1848.     printk("%c", c);
  1849. #endif
  1850.     fore200e->bus->write(((u32) c) | FORE200E_CP_MONITOR_UART_AVAIL, &monitor->soft_uart.send);
  1851. }
  1852. static int __init
  1853. fore200e_monitor_getc(struct fore200e* fore200e)
  1854. {
  1855.     struct cp_monitor* monitor = fore200e->cp_monitor;
  1856.     unsigned long      timeout = jiffies + MSECS(50);
  1857.     int                c;
  1858.     while (time_before(jiffies, timeout)) {
  1859. c = (int) fore200e->bus->read(&monitor->soft_uart.recv);
  1860. if (c & FORE200E_CP_MONITOR_UART_AVAIL) {
  1861.     fore200e->bus->write(FORE200E_CP_MONITOR_UART_FREE, &monitor->soft_uart.recv);
  1862. #if 0
  1863.     printk("%c", c & 0xFF);
  1864. #endif
  1865.     return c & 0xFF;
  1866. }
  1867.     }
  1868.     return -1;
  1869. }
  1870. static void __init
  1871. fore200e_monitor_puts(struct fore200e* fore200e, char* str)
  1872. {
  1873.     while(*str) {
  1874. /* the i960 monitor doesn't accept any new character if it has something to say */
  1875. while (fore200e_monitor_getc(fore200e) >= 0);
  1876. fore200e_monitor_putc(fore200e, *str++);
  1877.     }
  1878.     while (fore200e_monitor_getc(fore200e) >= 0);
  1879. }
  1880. static int __init
  1881. fore200e_start_fw(struct fore200e* fore200e)
  1882. {
  1883.     int               ok;
  1884.     char              cmd[ 48 ];
  1885.     struct fw_header* fw_header = (struct fw_header*) fore200e->bus->fw_data;
  1886.     DPRINTK(2, "device %s firmware being startedn", fore200e->name);
  1887.     sprintf(cmd, "rgo %xr", le32_to_cpu(fw_header->start_offset));
  1888.     fore200e_monitor_puts(fore200e, cmd);
  1889.     ok = fore200e_io_poll(fore200e, &fore200e->cp_monitor->bstat, BSTAT_CP_RUNNING, 1000);
  1890.     if (ok == 0) {
  1891. printk(FORE200E "device %s firmware didn't startn", fore200e->name);
  1892. return -ENODEV;
  1893.     }
  1894.     printk(FORE200E "device %s firmware startedn", fore200e->name);
  1895.     fore200e->state = FORE200E_STATE_START_FW;
  1896.     return 0;
  1897. }
  1898. static int __init
  1899. fore200e_load_fw(struct fore200e* fore200e)
  1900. {
  1901.     u32* fw_data = (u32*) fore200e->bus->fw_data;
  1902.     u32  fw_size = (u32) *fore200e->bus->fw_size / sizeof(u32);
  1903.     struct fw_header* fw_header = (struct fw_header*) fw_data;
  1904.     u32* load_addr = fore200e->virt_base + le32_to_cpu(fw_header->load_offset);
  1905.     DPRINTK(2, "device %s firmware being loaded at 0x%p (%d words)n", 
  1906.     fore200e->name, load_addr, fw_size);
  1907. #if 1
  1908.     if (le32_to_cpu(fw_header->magic) != FW_HEADER_MAGIC) {
  1909. printk(FORE200E "corrupted %s firmware imagen", fore200e->bus->model_name);
  1910. return -ENODEV;
  1911.     }
  1912. #endif
  1913.     for (; fw_size--; fw_data++, load_addr++)
  1914. fore200e->bus->write(le32_to_cpu(*fw_data), load_addr);
  1915.     fore200e->state = FORE200E_STATE_LOAD_FW;
  1916.     return 0;
  1917. }
  1918. static int __init
  1919. fore200e_register(struct fore200e* fore200e)
  1920. {
  1921.     struct atm_dev* atm_dev;
  1922.     DPRINTK(2, "device %s being registeredn", fore200e->name);
  1923.     atm_dev = atm_dev_register(fore200e->bus->proc_name, &fore200e_ops, -1,
  1924.       NULL); 
  1925.     if (atm_dev == NULL) {
  1926. printk(FORE200E "unable to register device %sn", fore200e->name);
  1927. return -ENODEV;
  1928.     }
  1929.     FORE200E_DEV(atm_dev) = fore200e;
  1930.     fore200e->atm_dev = atm_dev;
  1931.     atm_dev->ci_range.vpi_bits = 8;
  1932.     atm_dev->ci_range.vci_bits = 10;
  1933.     fore200e->available_cell_rate = ATM_OC3_PCR;
  1934.     fore200e->state = FORE200E_STATE_REGISTER;
  1935.     return 0;
  1936. }
  1937. static int __init
  1938. fore200e_init(struct fore200e* fore200e)
  1939. {
  1940.     if (fore200e_register(fore200e) < 0)
  1941. return -ENODEV;
  1942.     
  1943.     if (fore200e->bus->configure(fore200e) < 0)
  1944. return -ENODEV;
  1945.     if (fore200e->bus->map(fore200e) < 0)
  1946. return -ENODEV;
  1947.     if (fore200e_reset(fore200e, 1) < 0)
  1948. return -ENODEV;
  1949.     if (fore200e_load_fw(fore200e) < 0)
  1950. return -ENODEV;
  1951.     if (fore200e_start_fw(fore200e) < 0)
  1952. return -ENODEV;
  1953.     if (fore200e_initialize(fore200e) < 0)
  1954. return -ENODEV;
  1955.     if (fore200e_init_cmd_queue(fore200e) < 0)
  1956. return -ENOMEM;
  1957.     if (fore200e_init_tx_queue(fore200e) < 0)
  1958. return -ENOMEM;
  1959.     if (fore200e_init_rx_queue(fore200e) < 0)
  1960. return -ENOMEM;
  1961.     if (fore200e_init_bs_queue(fore200e) < 0)
  1962. return -ENOMEM;
  1963.     if (fore200e_alloc_rx_buf(fore200e) < 0)
  1964. return -ENOMEM;
  1965.     if (fore200e_get_esi(fore200e) < 0)
  1966. return -EIO;
  1967.     if (fore200e_irq_request(fore200e) < 0)
  1968. return -EBUSY;
  1969.     fore200e_supply(fore200e);
  1970.     
  1971.     /* all done, board initialization is now complete */
  1972.     fore200e->state = FORE200E_STATE_COMPLETE;
  1973.     return 0;
  1974. }
  1975. int __init
  1976. fore200e_detect(void)
  1977. {
  1978.     const struct fore200e_bus* bus;
  1979.     struct       fore200e*     fore200e;
  1980.     int                        index, link;
  1981.     printk(FORE200E "FORE Systems 200E-series driver - version " FORE200E_VERSION "n");
  1982.     /* for each configured bus interface */
  1983.     for (link = 0, bus = fore200e_bus; bus->model_name; bus++) {
  1984. /* detect all boards present on that bus */
  1985. for (index = 0; (fore200e = bus->detect(bus, index)); index++) {
  1986.     
  1987.     printk(FORE200E "device %s found at 0x%lx, IRQ %sn",
  1988.    fore200e->bus->model_name, 
  1989.    fore200e->phys_base, fore200e_irq_itoa(fore200e->irq));
  1990.     sprintf(fore200e->name, "%s-%d", bus->model_name, index);
  1991.     if (fore200e_init(fore200e) < 0) {
  1992. fore200e_shutdown(fore200e);
  1993. break;
  1994.     }
  1995.     link++;
  1996.     fore200e->next  = fore200e_boards;
  1997.     fore200e_boards = fore200e;
  1998. }
  1999.     }
  2000.     return link;
  2001. }
  2002. #ifdef MODULE
  2003. static void
  2004. fore200e_cleanup(struct fore200e** head)
  2005. {
  2006.     struct fore200e* fore200e = *head;
  2007.     fore200e_shutdown(fore200e);
  2008.     *head = fore200e->next;
  2009.     kfree(fore200e);
  2010. }
  2011. #endif
  2012. static int
  2013. fore200e_proc_read(struct atm_dev *dev,loff_t* pos,char* page)
  2014. {
  2015.     struct fore200e* fore200e  = FORE200E_DEV(dev);
  2016.     int              len, left = *pos;
  2017.     if (!left--) {
  2018. if (fore200e_getstats(fore200e) < 0)
  2019.     return -EIO;
  2020. len = sprintf(page,"n"
  2021.        " device:n"
  2022.        "   internal name:tt%sn", fore200e->name);
  2023. /* print bus-specific information */
  2024. if (fore200e->bus->proc_read)
  2025.     len += fore200e->bus->proc_read(fore200e, page + len);
  2026. len += sprintf(page + len,
  2027. "   interrupt line:tt%sn"
  2028. "   physical base address:t0x%pn"
  2029. "   virtual base address:t0x%pn"
  2030. "   factory address (ESI):t%02x:%02x:%02x:%02x:%02x:%02xn"
  2031. "   board serial number:tt%dnn",
  2032. fore200e_irq_itoa(fore200e->irq),
  2033. (void*)fore200e->phys_base,
  2034. (void*)fore200e->virt_base,
  2035. fore200e->esi[0], fore200e->esi[1], fore200e->esi[2],
  2036. fore200e->esi[3], fore200e->esi[4], fore200e->esi[5],
  2037. fore200e->esi[4] * 256 + fore200e->esi[5]);
  2038. return len;
  2039.     }
  2040.     if (!left--)
  2041. return sprintf(page,
  2042.        "   supplied small bufs (1):t%dn"
  2043.        "   supplied large bufs (1):t%dn"
  2044.        "   supplied small bufs (2):t%dn"
  2045.        "   supplied large bufs (2):t%dn",
  2046.        fore200e->host_bsq[ BUFFER_SCHEME_ONE ][ BUFFER_MAGN_SMALL ].count,
  2047.        fore200e->host_bsq[ BUFFER_SCHEME_ONE ][ BUFFER_MAGN_LARGE ].count,
  2048.        fore200e->host_bsq[ BUFFER_SCHEME_TWO ][ BUFFER_MAGN_SMALL ].count,
  2049.        fore200e->host_bsq[ BUFFER_SCHEME_TWO ][ BUFFER_MAGN_LARGE ].count);
  2050.     if (!left--) {
  2051. u32 hb = fore200e->bus->read(&fore200e->cp_queues->heartbeat);
  2052. len = sprintf(page,"nn"
  2053.       " cell processor:n"
  2054.       "   heartbeat state:tt");
  2055. if (hb >> 16 != 0xDEAD)
  2056.     len += sprintf(page + len, "0x%08xn", hb);
  2057. else
  2058.     len += sprintf(page + len, "*** FATAL ERROR %04x ***n", hb & 0xFFFF);
  2059. return len;
  2060.     }
  2061.     if (!left--) {
  2062. static const char* media_name[] = {
  2063.     "unshielded twisted pair",
  2064.     "multimode optical fiber ST",
  2065.     "multimode optical fiber SC",
  2066.     "single-mode optical fiber ST",
  2067.     "single-mode optical fiber SC",
  2068.     "unknown"
  2069. };
  2070. static const char* oc3_mode[] = {
  2071.     "normal operation",
  2072.     "diagnostic loopback",
  2073.     "line loopback",
  2074.     "unknown"
  2075. };
  2076. u32 fw_release     = fore200e->bus->read(&fore200e->cp_queues->fw_release);
  2077. u32 mon960_release = fore200e->bus->read(&fore200e->cp_queues->mon960_release);
  2078. u32 oc3_revision   = fore200e->bus->read(&fore200e->cp_queues->oc3_revision);
  2079. u32 media_index    = FORE200E_MEDIA_INDEX(fore200e->bus->read(&fore200e->cp_queues->media_type));
  2080. u32 oc3_index;
  2081. if (media_index < 0 || media_index > 4)
  2082.     media_index = 5;
  2083. switch (fore200e->loop_mode) {
  2084.     case ATM_LM_NONE:    oc3_index = 0;
  2085.                  break;
  2086.     case ATM_LM_LOC_PHY: oc3_index = 1;
  2087.                  break;
  2088.     case ATM_LM_RMT_PHY: oc3_index = 2;
  2089.                  break;
  2090.     default:             oc3_index = 3;
  2091. }
  2092. return sprintf(page,
  2093.        "   firmware release:tt%d.%d.%dn"
  2094.        "   monitor release:tt%d.%dn"
  2095.        "   media type:ttt%sn"
  2096.        "   OC-3 revision:tt0x%xn"
  2097.                        "   OC-3 mode:ttt%s",
  2098.        fw_release >> 16, fw_release << 16 >> 24,  fw_release << 24 >> 24,
  2099.        mon960_release >> 16, mon960_release << 16 >> 16,
  2100.        media_name[ media_index ],
  2101.        oc3_revision,
  2102.        oc3_mode[ oc3_index ]);
  2103.     }
  2104.     if (!left--) {
  2105. struct cp_monitor* cp_monitor = fore200e->cp_monitor;
  2106. return sprintf(page,
  2107.        "nn"
  2108.        " monitor:n"
  2109.        "   version number:tt%dn"
  2110.        "   boot status word:tt0x%08xn",
  2111.        fore200e->bus->read(&cp_monitor->mon_version),
  2112.        fore200e->bus->read(&cp_monitor->bstat));
  2113.     }
  2114.     if (!left--)
  2115. return sprintf(page,
  2116.        "n"
  2117.        " device statistics:n"
  2118.        "  4b5b:n"
  2119.        "     crc_header_errors:tt%10un"
  2120.        "     framing_errors:tt%10un",
  2121.        fore200e_swap(fore200e->stats->phy.crc_header_errors),
  2122.        fore200e_swap(fore200e->stats->phy.framing_errors));
  2123.     
  2124.     if (!left--)
  2125. return sprintf(page, "n"
  2126.        "  OC-3:n"
  2127.        "     section_bip8_errors:t%10un"
  2128.        "     path_bip8_errors:tt%10un"
  2129.        "     line_bip24_errors:tt%10un"
  2130.        "     line_febe_errors:tt%10un"
  2131.        "     path_febe_errors:tt%10un"
  2132.        "     corr_hcs_errors:tt%10un"
  2133.        "     ucorr_hcs_errors:tt%10un",
  2134.        fore200e_swap(fore200e->stats->oc3.section_bip8_errors),
  2135.        fore200e_swap(fore200e->stats->oc3.path_bip8_errors),
  2136.        fore200e_swap(fore200e->stats->oc3.line_bip24_errors),
  2137.        fore200e_swap(fore200e->stats->oc3.line_febe_errors),
  2138.        fore200e_swap(fore200e->stats->oc3.path_febe_errors),
  2139.        fore200e_swap(fore200e->stats->oc3.corr_hcs_errors),
  2140.        fore200e_swap(fore200e->stats->oc3.ucorr_hcs_errors));
  2141.     if (!left--)
  2142. return sprintf(page,"n"
  2143.        "   ATM:tttt     cellsn"
  2144.        "     TX:ttt%10un"
  2145.        "     RX:ttt%10un"
  2146.        "     vpi out of range:tt%10un"
  2147.        "     vpi no conn:tt%10un"
  2148.        "     vci out of range:tt%10un"
  2149.        "     vci no conn:tt%10un",
  2150.        fore200e_swap(fore200e->stats->atm.cells_transmitted),
  2151.        fore200e_swap(fore200e->stats->atm.cells_received),
  2152.        fore200e_swap(fore200e->stats->atm.vpi_bad_range),
  2153.        fore200e_swap(fore200e->stats->atm.vpi_no_conn),
  2154.        fore200e_swap(fore200e->stats->atm.vci_bad_range),
  2155.        fore200e_swap(fore200e->stats->atm.vci_no_conn));
  2156.     
  2157.     if (!left--)
  2158. return sprintf(page,"n"
  2159.        "   AAL0:ttt     cellsn"
  2160.        "     TX:ttt%10un"
  2161.        "     RX:ttt%10un"
  2162.        "     dropped:ttt%10un",
  2163.        fore200e_swap(fore200e->stats->aal0.cells_transmitted),
  2164.        fore200e_swap(fore200e->stats->aal0.cells_received),
  2165.        fore200e_swap(fore200e->stats->aal0.cells_dropped));
  2166.     
  2167.     if (!left--)
  2168. return sprintf(page,"n"
  2169.        "   AAL3/4:n"
  2170.        "     SAR sublayer:tt     cellsn"
  2171.        "       TX:ttt%10un"
  2172.        "       RX:ttt%10un"
  2173.        "       dropped:ttt%10un"
  2174.        "       CRC errors:tt%10un"
  2175.        "       protocol errors:tt%10unn"
  2176.        "     CS  sublayer:tt      PDUsn"
  2177.        "       TX:ttt%10un"
  2178.        "       RX:ttt%10un"
  2179.        "       dropped:ttt%10un"
  2180.        "       protocol errors:tt%10un",
  2181.        fore200e_swap(fore200e->stats->aal34.cells_transmitted),
  2182.        fore200e_swap(fore200e->stats->aal34.cells_received),
  2183.        fore200e_swap(fore200e->stats->aal34.cells_dropped),
  2184.        fore200e_swap(fore200e->stats->aal34.cells_crc_errors),
  2185.        fore200e_swap(fore200e->stats->aal34.cells_protocol_errors),
  2186.        fore200e_swap(fore200e->stats->aal34.cspdus_transmitted),
  2187.        fore200e_swap(fore200e->stats->aal34.cspdus_received),
  2188.        fore200e_swap(fore200e->stats->aal34.cspdus_dropped),
  2189.        fore200e_swap(fore200e->stats->aal34.cspdus_protocol_errors));
  2190.     
  2191.     if (!left--)
  2192. return sprintf(page,"n"
  2193.        "   AAL5:n"
  2194.        "     SAR sublayer:tt     cellsn"
  2195.        "       TX:ttt%10un"
  2196.        "       RX:ttt%10un"
  2197.        "       dropped:ttt%10un"
  2198.        "       congestions:tt%10unn"
  2199.        "     CS  sublayer:tt      PDUsn"
  2200.        "       TX:ttt%10un"
  2201.        "       RX:ttt%10un"
  2202.        "       dropped:ttt%10un"
  2203.        "       CRC errors:tt%10un"
  2204.        "       protocol errors:tt%10un",
  2205.        fore200e_swap(fore200e->stats->aal5.cells_transmitted),
  2206.        fore200e_swap(fore200e->stats->aal5.cells_received),
  2207.        fore200e_swap(fore200e->stats->aal5.cells_dropped),
  2208.        fore200e_swap(fore200e->stats->aal5.congestion_experienced),
  2209.        fore200e_swap(fore200e->stats->aal5.cspdus_transmitted),
  2210.        fore200e_swap(fore200e->stats->aal5.cspdus_received),
  2211.        fore200e_swap(fore200e->stats->aal5.cspdus_dropped),
  2212.        fore200e_swap(fore200e->stats->aal5.cspdus_crc_errors),
  2213.        fore200e_swap(fore200e->stats->aal5.cspdus_protocol_errors));
  2214.     
  2215.     if (!left--)
  2216. return sprintf(page,"n"
  2217.        "   AUX:tt       allocation failuresn"
  2218.        "     small b1:ttt%10un"
  2219.        "     large b1:ttt%10un"
  2220.        "     small b2:ttt%10un"
  2221.        "     large b2:ttt%10un"
  2222.        "     RX PDUs:ttt%10un",
  2223.        fore200e_swap(fore200e->stats->aux.small_b1_failed),
  2224.        fore200e_swap(fore200e->stats->aux.large_b1_failed),
  2225.        fore200e_swap(fore200e->stats->aux.small_b2_failed),
  2226.        fore200e_swap(fore200e->stats->aux.large_b2_failed),
  2227.        fore200e_swap(fore200e->stats->aux.rpd_alloc_failed));
  2228.     
  2229.     if (!left--)
  2230. return sprintf(page,"n"
  2231.        " receive carrier:ttt%sn",
  2232.        fore200e->stats->aux.receive_carrier ? "ON" : "OFF!");
  2233.     
  2234.     if (!left--) {
  2235. struct atm_vcc *vcc;
  2236. struct fore200e_vcc* fore200e_vcc;
  2237. len = sprintf(page,"n"    
  2238.       " VCCs:n  addresstVPI.VCI:AALt(min/max tx PDU size) (min/max rx PDU size)n");
  2239. for (vcc = fore200e->atm_dev->vccs; vcc; vcc = vcc->next) {
  2240.     fore200e_vcc = FORE200E_VCC(vcc);
  2241.     
  2242.     len += sprintf(page + len,
  2243.    "  %xt%d.%d:%dtt(%d/%d)t(%d/%d)n",
  2244.    (u32)(unsigned long)vcc,
  2245.    vcc->vpi, vcc->vci, fore200e_atm2fore_aal(vcc->qos.aal),
  2246.    fore200e_vcc->tx_min_pdu > 0xFFFF ? 0 : fore200e_vcc->tx_min_pdu,
  2247.    fore200e_vcc->tx_max_pdu,
  2248.    fore200e_vcc->rx_min_pdu > 0xFFFF ? 0 : fore200e_vcc->rx_min_pdu,
  2249.    fore200e_vcc->rx_max_pdu
  2250. );
  2251. }
  2252. return len;
  2253.     }
  2254.     
  2255.     return 0;
  2256. }
  2257. #ifdef MODULE
  2258. static int __init
  2259. fore200e_module_init(void)
  2260. {
  2261.     DPRINTK(1, "module loadedn");
  2262.     return fore200e_detect() == 0;
  2263. }
  2264. static void __exit
  2265. fore200e_module_cleanup(void)
  2266. {
  2267.     while (fore200e_boards) {
  2268. fore200e_cleanup(&fore200e_boards);
  2269.     }
  2270.     DPRINTK(1, "module being removedn");
  2271. }
  2272. module_init(fore200e_module_init);
  2273. module_exit(fore200e_module_cleanup);
  2274. #endif
  2275. static const struct atmdev_ops fore200e_ops =
  2276. {
  2277. open:         fore200e_open,
  2278. close:        fore200e_close,
  2279. ioctl:        fore200e_ioctl,
  2280. getsockopt:   fore200e_getsockopt,
  2281. setsockopt:   fore200e_setsockopt,
  2282. send:         fore200e_send,
  2283. change_qos:   fore200e_change_qos,
  2284. proc_read:    fore200e_proc_read,
  2285. owner:        THIS_MODULE,
  2286. };
  2287. #ifdef CONFIG_ATM_FORE200E_PCA
  2288. extern const unsigned char _fore200e_pca_fw_data[];
  2289. extern const unsigned int  _fore200e_pca_fw_size;
  2290. #endif
  2291. #ifdef CONFIG_ATM_FORE200E_SBA
  2292. extern const unsigned char _fore200e_sba_fw_data[];
  2293. extern const unsigned int  _fore200e_sba_fw_size;
  2294. #endif
  2295. static const struct fore200e_bus fore200e_bus[] = {
  2296. #ifdef CONFIG_ATM_FORE200E_PCA
  2297.     { "PCA-200E", "pca200e", 32, 4, 32, 
  2298.       _fore200e_pca_fw_data, &_fore200e_pca_fw_size,
  2299.       fore200e_pca_read,
  2300.       fore200e_pca_write,
  2301.       fore200e_pca_dma_map,
  2302.       fore200e_pca_dma_unmap,
  2303.       fore200e_pca_dma_sync,
  2304.       fore200e_pca_dma_chunk_alloc,
  2305.       fore200e_pca_dma_chunk_free,
  2306.       fore200e_pca_detect,
  2307.       fore200e_pca_configure,
  2308.       fore200e_pca_map,
  2309.       fore200e_pca_reset,
  2310.       fore200e_pca_prom_read,
  2311.       fore200e_pca_unmap,
  2312.       NULL,
  2313.       fore200e_pca_irq_check,
  2314.       fore200e_pca_irq_ack,
  2315.       fore200e_pca_proc_read,
  2316.     },
  2317. #endif
  2318. #ifdef CONFIG_ATM_FORE200E_SBA
  2319.     { "SBA-200E", "sba200e", 32, 64, 32,
  2320.       _fore200e_sba_fw_data, &_fore200e_sba_fw_size,
  2321.       fore200e_sba_read,
  2322.       fore200e_sba_write,
  2323.       fore200e_sba_dma_map,
  2324.       fore200e_sba_dma_unmap,
  2325.       fore200e_sba_dma_sync,
  2326.       fore200e_sba_dma_chunk_alloc,
  2327.       fore200e_sba_dma_chunk_free,
  2328.       fore200e_sba_detect, 
  2329.       fore200e_sba_configure,
  2330.       fore200e_sba_map,
  2331.       fore200e_sba_reset,
  2332.       fore200e_sba_prom_read,
  2333.       fore200e_sba_unmap,
  2334.       fore200e_sba_irq_enable,
  2335.       fore200e_sba_irq_check,
  2336.       fore200e_sba_irq_ack,
  2337.       fore200e_sba_proc_read,
  2338.     },
  2339. #endif
  2340.     {}
  2341. };
  2342. MODULE_LICENSE("GPL");