ambassador.h 15 KB

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