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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.   Madge Ambassador ATM Adapter driver.
  3.   Copyright (C) 1995-1999  Madge Networks Ltd.
  4.   This program is free software; you can redistribute it and/or modify
  5.   it under the terms of the GNU General Public License as published by
  6.   the Free Software Foundation; either version 2 of the License, or
  7.   (at your option) any later version.
  8.   This program is distributed in the hope that it will be useful,
  9.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.   GNU General Public License for more details.
  12.   You should have received a copy of the GNU General Public License
  13.   along with this program; if not, write to the Free Software
  14.   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  15.   The GNU GPL is contained in /usr/doc/copyright/GPL on a Debian
  16.   system and in the file COPYING in the Linux kernel source.
  17. */
  18. #ifndef AMBASSADOR_H
  19. #define AMBASSADOR_H
  20. #include <linux/config.h>
  21. #ifdef CONFIG_ATM_AMBASSADOR_DEBUG
  22. #define DEBUG_AMBASSADOR
  23. #endif
  24. #define DEV_LABEL                          "amb"
  25. #ifndef PCI_VENDOR_ID_MADGE
  26. #define PCI_VENDOR_ID_MADGE                0x10B6
  27. #endif
  28. #ifndef PCI_VENDOR_ID_MADGE_AMBASSADOR
  29. #define PCI_DEVICE_ID_MADGE_AMBASSADOR     0x1001
  30. #endif
  31. #ifndef PCI_VENDOR_ID_MADGE_AMBASSADOR_BAD
  32. #define PCI_DEVICE_ID_MADGE_AMBASSADOR_BAD 0x1002
  33. #endif
  34. // diagnostic output
  35. #define PRINTK(severity,format,args...) 
  36.   printk(severity DEV_LABEL ": " format "n" , ## args)
  37. #ifdef DEBUG_AMBASSADOR
  38. #define DBG_ERR  0x0001
  39. #define DBG_WARN 0x0002
  40. #define DBG_INFO 0x0004
  41. #define DBG_INIT 0x0008
  42. #define DBG_LOAD 0x0010
  43. #define DBG_VCC  0x0020
  44. #define DBG_QOS  0x0040
  45. #define DBG_CMD  0x0080
  46. #define DBG_TX   0x0100
  47. #define DBG_RX   0x0200
  48. #define DBG_SKB  0x0400
  49. #define DBG_POOL 0x0800
  50. #define DBG_IRQ  0x1000
  51. #define DBG_FLOW 0x2000
  52. #define DBG_REGS 0x4000
  53. #define DBG_DATA 0x8000
  54. #define DBG_MASK 0xffff
  55. /* the ## prevents the annoying double expansion of the macro arguments */
  56. /* KERN_INFO is used since KERN_DEBUG often does not make it to the console */
  57. #define PRINTDB(bits,format,args...) 
  58.   ( (debug & (bits)) ? printk (KERN_INFO DEV_LABEL ": " format , ## args) : 1 )
  59. #define PRINTDM(bits,format,args...) 
  60.   ( (debug & (bits)) ? printk (format , ## args) : 1 )
  61. #define PRINTDE(bits,format,args...) 
  62.   ( (debug & (bits)) ? printk (format "n" , ## args) : 1 )
  63. #define PRINTD(bits,format,args...) 
  64.   ( (debug & (bits)) ? printk (KERN_INFO DEV_LABEL ": " format "n" , ## args) : 1 )
  65. #else
  66. #define PRINTD(bits,format,args...)
  67. #define PRINTDB(bits,format,args...)
  68. #define PRINTDM(bits,format,args...)
  69. #define PRINTDE(bits,format,args...)
  70. #endif
  71. #define PRINTDD(bits,format,args...)
  72. #define PRINTDDB(sec,fmt,args...)
  73. #define PRINTDDM(sec,fmt,args...)
  74. #define PRINTDDE(sec,fmt,args...)
  75. // tunable values (?)
  76. /* MUST be powers of two -- why ? */
  77. #define COM_Q_ENTRIES        8
  78. #define TX_Q_ENTRIES        32
  79. #define RX_Q_ENTRIES        64
  80. // fixed values
  81. // guessing
  82. #define AMB_EXTENT         0x80
  83. // Minimum allowed size for an Ambassador queue
  84. #define MIN_QUEUE_SIZE     2
  85. // Ambassador microcode allows 1 to 4 pools, we use 4 (simpler)
  86. #define NUM_RX_POOLS    4
  87. // minimum RX buffers required to cope with replenishing delay
  88. #define MIN_RX_BUFFERS    1
  89. // minimum PCI latency we will tolerate (32 IS TOO SMALL)
  90. #define MIN_PCI_LATENCY   64 // 255
  91. // VCs supported by card (VPI always 0)
  92. #define NUM_VPI_BITS       0
  93. #define NUM_VCI_BITS      10
  94. #define NUM_VCS         1024
  95. /* The status field bits defined so far. */
  96. #define RX_ERR 0x8000 // always present if there is an error (hmm)
  97. #define CRC_ERR 0x4000 // AAL5 CRC error
  98. #define LEN_ERR 0x2000 // overlength frame
  99. #define ABORT_ERR 0x1000 // zero length field in received frame
  100. #define UNUSED_ERR 0x0800 // buffer returned unused
  101. // Adaptor commands
  102. #define SRB_OPEN_VC 0
  103. /* par_0: dwordswap(VC_number) */
  104. /* par_1: dwordswap(flags<<16) or wordswap(flags)*/ 
  105. /* flags: */
  106. /* LANE: 0x0004 */
  107. /* NOT_UBR: 0x0008 */
  108. /* ABR: 0x0010 */
  109. /* RxPool0: 0x0000 */
  110. /* RxPool1: 0x0020 */
  111. /* RxPool2: 0x0040 */
  112. /* RxPool3: 0x0060 */
  113. /* par_2: dwordswap(fp_rate<<16) or wordswap(fp_rate) */
  114. #define SRB_CLOSE_VC 1
  115. /* par_0: dwordswap(VC_number) */
  116. #define SRB_GET_BIA 2
  117. /* returns  */
  118. /* par_0: dwordswap(half BIA) */
  119. /* par_1: dwordswap(half BIA) */
  120. #define SRB_GET_SUNI_STATS 3
  121. /* par_0: dwordswap(physical_host_address) */
  122. #define SRB_SET_BITS_8 4
  123. #define SRB_SET_BITS_16 5
  124. #define SRB_SET_BITS_32 6
  125. #define SRB_CLEAR_BITS_8 7
  126. #define SRB_CLEAR_BITS_16 8
  127. #define SRB_CLEAR_BITS_32 9
  128. /* par_0: dwordswap(ATMizer address) */
  129. /* par_1: dwordswap(mask) */
  130. #define SRB_SET_8 10
  131. #define SRB_SET_16 11
  132. #define SRB_SET_32 12
  133. /* par_0: dwordswap(ATMizer address) */
  134. /* par_1: dwordswap(data) */
  135. #define SRB_GET_32 13
  136. /* par_0: dwordswap(ATMizer address) */
  137. /* returns */
  138. /* par_1: dwordswap(ATMizer data) */
  139. #define SRB_GET_VERSION 14
  140. /* returns  */
  141. /* par_0: dwordswap(Major Version) */
  142. /* par_1: dwordswap(Minor Version) */
  143. #define SRB_FLUSH_BUFFER_Q 15
  144. /* Only flags to define which buffer pool; all others must be zero */
  145. /* par_0: dwordswap(flags<<16) or wordswap(flags)*/ 
  146. #define SRB_GET_DMA_SPEEDS 16
  147. /* returns  */
  148. /* par_0: dwordswap(Read speed (bytes/sec)) */
  149. /* par_1: dwordswap(Write speed (bytes/sec)) */
  150. #define SRB_MODIFY_VC_RATE 17
  151. /* par_0: dwordswap(VC_number) */
  152. /* par_1: dwordswap(fp_rate<<16) or wordswap(fp_rate) */
  153. #define SRB_MODIFY_VC_FLAGS 18
  154. /* par_0: dwordswap(VC_number) */
  155. /* par_1: dwordswap(flags<<16) or wordswap(flags)*/ 
  156. /* flags: */
  157. /* LANE: 0x0004 */
  158. /* NOT_UBR: 0x0008 */
  159. /* ABR: 0x0010 */
  160. /* RxPool0: 0x0000 */
  161. /* RxPool1: 0x0020 */
  162. /* RxPool2: 0x0040 */
  163. /* RxPool3: 0x0060 */
  164. #define SRB_RATE_SHIFT          16
  165. #define SRB_POOL_SHIFT          (SRB_FLAGS_SHIFT+5)
  166. #define SRB_FLAGS_SHIFT         16
  167. #define SRB_STOP_TASKING 19
  168. #define SRB_START_TASKING 20
  169. #define SRB_SHUT_DOWN 21
  170. #define MAX_SRB 21
  171. #define SRB_COMPLETE 0xffffffff
  172. #define TX_FRAME           0x80000000
  173. // number of types of SRB MUST be a power of two -- why?
  174. #define NUM_OF_SRB 32
  175. // number of bits of period info for rate
  176. #define MAX_RATE_BITS 6
  177. #define TX_UBR          0x0000
  178. #define TX_UBR_CAPPED   0x0008
  179. #define TX_ABR          0x0018
  180. #define TX_FRAME_NOTCAP 0x0000
  181. #define TX_FRAME_CAPPED 0x8000
  182. #define FP_155_RATE 0x24b1
  183. #define FP_25_RATE 0x1f9d
  184. /* #define VERSION_NUMBER 0x01000000 // initial release */
  185. /* #define VERSION_NUMBER 0x01010000 // fixed startup probs PLX MB0 not cleared */
  186. /* #define VERSION_NUMBER 0x01020000 // changed SUNI reset timings; allowed r/w onchip */
  187. /* #define VERSION_NUMBER 0x01030000 // clear local doorbell int reg on reset */
  188. /* #define VERSION_NUMBER 0x01040000 // PLX bug work around version PLUS */
  189. /* remove race conditions on basic interface */
  190. /* indicate to the host that diagnostics */
  191. /* have finished; if failed, how and what  */
  192. /* failed */
  193. /* fix host memory test to fix PLX bug */
  194. /* allow flash upgrade and BIA upgrade directly */
  195. /*  */
  196. #define VERSION_NUMBER 0x01050025 /* Jason's first hacked version. */
  197. /* Change in download algorithm */
  198. #define DMA_VALID 0xb728e149 /* completely random */
  199. #define FLASH_BASE 0xa0c00000
  200. #define FLASH_SIZE 0x00020000 /* 128K */
  201. #define BIA_BASE (FLASH_BASE+0x0001c000) /* Flash Sector 7 */
  202. #define BIA_ADDRESS ((void *)0xa0c1c000)
  203. #define PLX_BASE 0xe0000000
  204. typedef enum {
  205.   host_memory_test = 1,
  206.   read_adapter_memory,
  207.   write_adapter_memory,
  208.   adapter_start,
  209.   get_version_number,
  210.   interrupt_host,
  211.   flash_erase_sector,
  212.   adap_download_block = 0x20,
  213.   adap_erase_flash,
  214.   adap_run_in_iram,
  215.   adap_end_download
  216. } loader_command;
  217. #define BAD_COMMAND                     (-1)
  218. #define COMMAND_IN_PROGRESS             1
  219. #define COMMAND_PASSED_TEST             2
  220. #define COMMAND_FAILED_TEST             3
  221. #define COMMAND_READ_DATA_OK            4
  222. #define COMMAND_READ_BAD_ADDRESS        5
  223. #define COMMAND_WRITE_DATA_OK           6
  224. #define COMMAND_WRITE_BAD_ADDRESS       7
  225. #define COMMAND_WRITE_FLASH_FAILURE     8
  226. #define COMMAND_COMPLETE                9
  227. #define COMMAND_FLASH_ERASE_FAILURE 10
  228. #define COMMAND_WRITE_BAD_DATA 11
  229. /* bit fields for mailbox[0] return values */
  230. #define GPINT_TST_FAILURE               0x00000001      
  231. #define SUNI_DATA_PATTERN_FAILURE       0x00000002
  232. #define SUNI_DATA_BITS_FAILURE          0x00000004
  233. #define SUNI_UTOPIA_FAILURE             0x00000008
  234. #define SUNI_FIFO_FAILURE               0x00000010
  235. #define SRAM_FAILURE                    0x00000020
  236. #define SELF_TEST_FAILURE               0x0000003f
  237. /* mailbox[1] = 0 in progress, -1 on completion */
  238. /* mailbox[2] = current test 00 00 test(8 bit) phase(8 bit) */
  239. /* mailbox[3] = last failure, 00 00 test(8 bit) phase(8 bit) */
  240. /* mailbox[4],mailbox[5],mailbox[6] random failure values */
  241. /* PLX/etc. memory map including command structure */
  242. /* These registers may also be memory mapped in PCI memory */
  243. #define UNUSED_LOADER_MAILBOXES 6
  244. typedef struct {
  245.   u32 stuff[16];
  246.   union {
  247.     struct {
  248.       u32 result;
  249.       u32 ready;
  250.       u32 stuff[UNUSED_LOADER_MAILBOXES];
  251.     } loader;
  252.     struct {
  253.       u32 cmd_address;
  254.       u32 tx_address;
  255.       u32 rx_address[NUM_RX_POOLS];
  256.       u32 gen_counter;
  257.       u32 spare;
  258.     } adapter;
  259.   } mb;
  260.   u32 doorbell;
  261.   u32 interrupt;
  262.   u32 interrupt_control;
  263.   u32 reset_control;
  264. } amb_mem;
  265. /* RESET bit, IRQ (card to host) and doorbell (host to card) enable bits */
  266. #define AMB_RESET_BITS    0x40000000
  267. #define AMB_INTERRUPT_BITS 0x00000300
  268. #define AMB_DOORBELL_BITS  0x00030000
  269. /* loader commands */
  270. #define MAX_COMMAND_DATA 13
  271. #define MAX_TRANSFER_DATA 11
  272. typedef struct {
  273.   u32 address;
  274.   u32 count;
  275.   u32 data[MAX_TRANSFER_DATA];
  276. } transfer_block;
  277. typedef struct {
  278.   u32 result;
  279.   u32 command;
  280.   union {
  281.     transfer_block transfer;
  282.     u32 version;
  283.     u32 start;
  284.     u32 data[MAX_COMMAND_DATA];
  285.   } payload;
  286.   u32 valid;
  287. } loader_block;
  288. /* command queue */
  289. /* Again all data are BIG ENDIAN */
  290. typedef struct {
  291.   union {
  292.     struct {
  293.       u32 vc;
  294.       u32 flags;
  295.       u32 rate;
  296.     } open;
  297.     struct {
  298.       u32 vc;
  299.       u32 rate;
  300.     } modify_rate;
  301.     struct {
  302.       u32 vc;
  303.       u32 flags;
  304.     } modify_flags;
  305.     struct {
  306.       u32 vc;
  307.     } close;
  308.     struct {
  309.       u32 lower4;
  310.       u32 upper2;
  311.     } bia;
  312.     struct {
  313.       u32 address;
  314.     } suni;
  315.     struct {
  316.       u32 major;
  317.       u32 minor;
  318.     } version;
  319.     struct {
  320.       u32 read;
  321.       u32 write;
  322.     } speed;
  323.     struct {
  324.       u32 flags;
  325.     } flush;
  326.     struct {
  327.       u32 address;
  328.       u32 data;
  329.     } memory;
  330.     u32 par[3];
  331.   } args;
  332.   u32 request;
  333. } command;
  334. /* transmit queues and associated structures */
  335. /* The hosts transmit structure. All BIG ENDIAN; host address
  336.    restricted to first 1GByte, but address passed to the card must
  337.    have the top MS bit or'ed in. -- check this */
  338. /* TX is described by 1+ tx_frags followed by a tx_frag_end */
  339. typedef struct {
  340.   u32 bytes;
  341.   u32 address;
  342. } tx_frag;
  343. /* apart from handle the fields here are for the adapter to play with
  344.    and should be set to zero */
  345. typedef struct {
  346.   u32 handle;
  347.   u16 vc;
  348.   u16 next_descriptor_length;
  349.   u32 next_descriptor;
  350. #ifdef AMB_NEW_MICROCODE
  351.   u8    cpcs_uu;
  352.   u8    cpi;
  353.   u16   pad;
  354. #endif
  355. } tx_frag_end;
  356. typedef struct {
  357.   tx_frag tx_frag;
  358.   tx_frag_end tx_frag_end;
  359.   struct sk_buff * skb;
  360. } tx_simple;
  361. #if 0
  362. typedef union {
  363.   tx_frag fragment;
  364.   tx_frag_end end_of_list;
  365. } tx_descr;
  366. #endif
  367. /* this "points" to the sequence of fragments and trailer */
  368. typedef struct {
  369.   u16 vc;
  370.   u16 tx_descr_length;
  371.   u32 tx_descr_addr;
  372. } tx_in;
  373. /* handle is the handle from tx_in */
  374. typedef struct {
  375.   u32 handle;
  376. } tx_out;
  377. /* receive frame structure */
  378. /* All BIG ENDIAN; handle is as passed from host; length is zero for
  379.    aborted frames, and frames with errors. Header is actually VC
  380.    number, lec-id is NOT yet supported. */
  381. typedef struct {
  382.   u32  handle;
  383.   u16  vc;
  384.   u16  lec_id; // unused
  385.   u16  status;
  386.   u16  length;
  387. } rx_out;
  388. /* buffer supply structure */
  389. typedef struct {
  390.   u32 handle;
  391.   u32 host_address;
  392. } rx_in;
  393. /* This first structure is the area in host memory where the adapter
  394.    writes its pointer values. These pointer values are BIG ENDIAN and
  395.    reside in the same 4MB 'page' as this structure. The host gives the
  396.    adapter the address of this block by sending a doorbell interrupt
  397.    to the adapter after downloading the code and setting it going. The
  398.    addresses have the top 10 bits set to 1010000010b -- really?
  399.    
  400.    The host must initialise these before handing the block to the
  401.    adapter. */
  402. typedef struct {
  403.   u32 command_start; /* SRB commands completions */
  404.   u32 command_end; /* SRB commands completions */
  405.   u32 tx_start;
  406.   u32 tx_end;
  407.   u32 txcom_start; /* tx completions */
  408.   u32 txcom_end; /* tx completions */
  409.   struct {
  410.     u32 buffer_start;
  411.     u32 buffer_end;
  412.     u32 buffer_q_get;
  413.     u32 buffer_q_end;
  414.     u32 buffer_aptr;
  415.     u32 rx_start; /* rx completions */
  416.     u32 rx_end;
  417.     u32 rx_ptr;
  418.     u32 buffer_size; /* size of host buffer */
  419.   } rec_struct[NUM_RX_POOLS];
  420. #ifdef AMB_NEW_MICROCODE
  421.   u16 init_flags;
  422.   u16 talk_block_spare;
  423. #endif
  424. } adap_talk_block;
  425. /* This structure must be kept in line with the vcr image in sarmain.h
  426.    
  427.    This is the structure in the host filled in by the adapter by
  428.    GET_SUNI_STATS */
  429. typedef struct {
  430.   u8 racp_chcs;
  431.   u8 racp_uhcs;
  432.   u16 spare;
  433.   u32 racp_rcell;
  434.   u32 tacp_tcell;
  435.   u32 flags;
  436.   u32 dropped_cells;
  437.   u32 dropped_frames;
  438. } suni_stats;
  439. typedef enum {
  440.   dead
  441. } amb_flags;
  442. #define NEXTQ(current,start,limit) 
  443.   ( (current)+1 < (limit) ? (current)+1 : (start) ) 
  444. typedef struct {
  445.   command * start;
  446.   command * in;
  447.   command * out;
  448.   command * limit;
  449. } amb_cq_ptrs;
  450. typedef struct {
  451.   spinlock_t lock;
  452.   unsigned int pending;
  453.   unsigned int high;
  454.   unsigned int filled;
  455.   unsigned int maximum; // size - 1 (q implementation)
  456.   amb_cq_ptrs ptrs;
  457. } amb_cq;
  458. typedef struct {
  459.   spinlock_t lock;
  460.   unsigned int pending;
  461.   unsigned int high;
  462.   unsigned int filled;
  463.   unsigned int maximum; // size - 1 (q implementation)
  464.   struct {
  465.     tx_in * start;
  466.     tx_in * ptr;
  467.     tx_in * limit;
  468.   } in;
  469.   struct {
  470.     tx_out * start;
  471.     tx_out * ptr;
  472.     tx_out * limit;
  473.   } out;
  474. } amb_txq;
  475. typedef struct {
  476.   spinlock_t lock;
  477.   unsigned int pending;
  478.   unsigned int low;
  479.   unsigned int emptied;
  480.   unsigned int maximum; // size - 1 (q implementation)
  481.   struct {
  482.     rx_in * start;
  483.     rx_in * ptr;
  484.     rx_in * limit;
  485.   } in;
  486.   struct {
  487.     rx_out * start;
  488.     rx_out * ptr;
  489.     rx_out * limit;
  490.   } out;
  491.   unsigned int buffers_wanted;
  492.   unsigned int buffer_size;
  493. } amb_rxq;
  494. typedef struct {
  495.   unsigned long tx_ok;
  496.   struct {
  497.     unsigned long ok;
  498.     unsigned long error;
  499.     unsigned long badcrc;
  500.     unsigned long toolong;
  501.     unsigned long aborted;
  502.     unsigned long unused;
  503.   } rx;
  504. } amb_stats;
  505. // a single struct pointed to by atm_vcc->dev_data
  506. typedef struct {
  507.   u8               tx_vc_bits:7;
  508.   u8               tx_present:1;
  509. } amb_tx_info;
  510. typedef struct {
  511.   unsigned char    pool;
  512. } amb_rx_info;
  513. typedef struct {
  514.   amb_rx_info      rx_info;
  515.   u16              tx_frame_bits;
  516.   unsigned int     tx_rate;
  517.   unsigned int     rx_rate;
  518. } amb_vcc;
  519. struct amb_dev {
  520.   u8               irq;
  521.   u8               flags;
  522.   u32              iobase;
  523.   u32 *            membase;
  524. #ifdef FILL_RX_POOLS_IN_BH
  525.   struct tq_struct bh;
  526. #endif
  527.   
  528.   amb_cq           cq;
  529.   amb_txq          txq;
  530.   amb_rxq          rxq[NUM_RX_POOLS];
  531.   
  532.   struct semaphore vcc_sf;
  533.   amb_tx_info      txer[NUM_VCS];
  534.   struct atm_vcc * rxer[NUM_VCS];
  535.   unsigned int     tx_avail;
  536.   unsigned int     rx_avail;
  537.   
  538.   amb_stats        stats;
  539.   
  540.   struct atm_dev * atm_dev;
  541.   struct pci_dev * pci_dev;
  542.   struct amb_dev * prev;
  543. };
  544. typedef struct amb_dev amb_dev;
  545. #define AMB_DEV(atm_dev) ((amb_dev *) (atm_dev)->dev_data)
  546. #define AMB_VCC(atm_vcc) ((amb_vcc *) (atm_vcc)->dev_data)
  547. /* the microcode */
  548. typedef struct {
  549.   u32 start;
  550.   unsigned int count;
  551. } region;
  552. static region ucode_regions[];
  553. static u32 ucode_data[];
  554. static u32 ucode_start;
  555. /* rate rounding */
  556. typedef enum {
  557.   round_up,
  558.   round_down,
  559.   round_nearest
  560. } rounding;
  561. #endif