ambassador.h 16 KB

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