horizon.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. /*
  2. Madge Horizon 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. /*
  19. IMPORTANT NOTE: Madge Networks no longer makes the adapters
  20. supported by this driver and makes no commitment to maintain it.
  21. */
  22. /* too many macros - change to inline functions */
  23. #ifndef DRIVER_ATM_HORIZON_H
  24. #define DRIVER_ATM_HORIZON_H
  25. #ifdef CONFIG_ATM_HORIZON_DEBUG
  26. #define DEBUG_HORIZON
  27. #endif
  28. #define DEV_LABEL "hrz"
  29. #ifndef PCI_VENDOR_ID_MADGE
  30. #define PCI_VENDOR_ID_MADGE 0x10B6
  31. #endif
  32. #ifndef PCI_DEVICE_ID_MADGE_HORIZON
  33. #define PCI_DEVICE_ID_MADGE_HORIZON 0x1000
  34. #endif
  35. // diagnostic output
  36. #define PRINTK(severity,format,args...) \
  37. printk(severity DEV_LABEL ": " format "\n" , ## args)
  38. #ifdef DEBUG_HORIZON
  39. #define DBG_ERR 0x0001
  40. #define DBG_WARN 0x0002
  41. #define DBG_INFO 0x0004
  42. #define DBG_VCC 0x0008
  43. #define DBG_QOS 0x0010
  44. #define DBG_TX 0x0020
  45. #define DBG_RX 0x0040
  46. #define DBG_SKB 0x0080
  47. #define DBG_IRQ 0x0100
  48. #define DBG_FLOW 0x0200
  49. #define DBG_BUS 0x0400
  50. #define DBG_REGS 0x0800
  51. #define DBG_DATA 0x1000
  52. #define DBG_MASK 0x1fff
  53. /* the ## prevents the annoying double expansion of the macro arguments */
  54. /* KERN_INFO is used since KERN_DEBUG often does not make it to the console */
  55. #define PRINTDB(bits,format,args...) \
  56. ( (debug & (bits)) ? printk (KERN_INFO DEV_LABEL ": " format , ## args) : 1 )
  57. #define PRINTDM(bits,format,args...) \
  58. ( (debug & (bits)) ? printk (format , ## args) : 1 )
  59. #define PRINTDE(bits,format,args...) \
  60. ( (debug & (bits)) ? printk (format "\n" , ## args) : 1 )
  61. #define PRINTD(bits,format,args...) \
  62. ( (debug & (bits)) ? printk (KERN_INFO DEV_LABEL ": " format "\n" , ## args) : 1 )
  63. #else
  64. #define PRINTD(bits,format,args...)
  65. #define PRINTDB(bits,format,args...)
  66. #define PRINTDM(bits,format,args...)
  67. #define PRINTDE(bits,format,args...)
  68. #endif
  69. #define PRINTDD(sec,fmt,args...)
  70. #define PRINTDDB(sec,fmt,args...)
  71. #define PRINTDDM(sec,fmt,args...)
  72. #define PRINTDDE(sec,fmt,args...)
  73. // fixed constants
  74. #define SPARE_BUFFER_POOL_SIZE MAX_VCS
  75. #define HRZ_MAX_VPI 4
  76. #define MIN_PCI_LATENCY 48 // 24 IS TOO SMALL
  77. /* Horizon specific bits */
  78. /* Register offsets */
  79. #define HRZ_IO_EXTENT 0x80
  80. #define DATA_PORT_OFF 0x00
  81. #define TX_CHANNEL_PORT_OFF 0x04
  82. #define TX_DESCRIPTOR_PORT_OFF 0x08
  83. #define MEMORY_PORT_OFF 0x0C
  84. #define MEM_WR_ADDR_REG_OFF 0x14
  85. #define MEM_RD_ADDR_REG_OFF 0x18
  86. #define CONTROL_0_REG 0x1C
  87. #define INT_SOURCE_REG_OFF 0x20
  88. #define INT_ENABLE_REG_OFF 0x24
  89. #define MASTER_RX_ADDR_REG_OFF 0x28
  90. #define MASTER_RX_COUNT_REG_OFF 0x2C
  91. #define MASTER_TX_ADDR_REG_OFF 0x30
  92. #define MASTER_TX_COUNT_REG_OFF 0x34
  93. #define TX_DESCRIPTOR_REG_OFF 0x38
  94. #define TX_CHANNEL_CONFIG_COMMAND_OFF 0x40
  95. #define TX_CHANNEL_CONFIG_DATA_OFF 0x44
  96. #define TX_FREE_BUFFER_COUNT_OFF 0x48
  97. #define RX_FREE_BUFFER_COUNT_OFF 0x4C
  98. #define TX_CONFIG_OFF 0x50
  99. #define TX_STATUS_OFF 0x54
  100. #define RX_CONFIG_OFF 0x58
  101. #define RX_LINE_CONFIG_OFF 0x5C
  102. #define RX_QUEUE_RD_PTR_OFF 0x60
  103. #define RX_QUEUE_WR_PTR_OFF 0x64
  104. #define MAX_AAL5_CELL_COUNT_OFF 0x68
  105. #define RX_CHANNEL_PORT_OFF 0x6C
  106. #define TX_CELL_COUNT_OFF 0x70
  107. #define RX_CELL_COUNT_OFF 0x74
  108. #define HEC_ERROR_COUNT_OFF 0x78
  109. #define UNASSIGNED_CELL_COUNT_OFF 0x7C
  110. /* Register bit definitions */
  111. /* Control 0 register */
  112. #define SEEPROM_DO 0x00000001
  113. #define SEEPROM_DI 0x00000002
  114. #define SEEPROM_SK 0x00000004
  115. #define SEEPROM_CS 0x00000008
  116. #define DEBUG_BIT_0 0x00000010
  117. #define DEBUG_BIT_1 0x00000020
  118. #define DEBUG_BIT_2 0x00000040
  119. // RESERVED 0x00000080
  120. #define DEBUG_BIT_0_OE 0x00000100
  121. #define DEBUG_BIT_1_OE 0x00000200
  122. #define DEBUG_BIT_2_OE 0x00000400
  123. // RESERVED 0x00000800
  124. #define DEBUG_BIT_0_STATE 0x00001000
  125. #define DEBUG_BIT_1_STATE 0x00002000
  126. #define DEBUG_BIT_2_STATE 0x00004000
  127. // RESERVED 0x00008000
  128. #define GENERAL_BIT_0 0x00010000
  129. #define GENERAL_BIT_1 0x00020000
  130. #define GENERAL_BIT_2 0x00040000
  131. #define GENERAL_BIT_3 0x00080000
  132. #define RESET_HORIZON 0x00100000
  133. #define RESET_ATM 0x00200000
  134. #define RESET_RX 0x00400000
  135. #define RESET_TX 0x00800000
  136. #define RESET_HOST 0x01000000
  137. // RESERVED 0x02000000
  138. #define TARGET_RETRY_DISABLE 0x04000000
  139. #define ATM_LAYER_SELECT 0x08000000
  140. #define ATM_LAYER_STATUS 0x10000000
  141. // RESERVED 0xE0000000
  142. /* Interrupt source and enable registers */
  143. #define RX_DATA_AV 0x00000001
  144. #define RX_DISABLED 0x00000002
  145. #define TIMING_MARKER 0x00000004
  146. #define FORCED 0x00000008
  147. #define RX_BUS_MASTER_COMPLETE 0x00000010
  148. #define TX_BUS_MASTER_COMPLETE 0x00000020
  149. #define ABR_TX_CELL_COUNT_INT 0x00000040
  150. #define DEBUG_INT 0x00000080
  151. // RESERVED 0xFFFFFF00
  152. /* PIO and Bus Mastering */
  153. #define MAX_PIO_COUNT 0x000000ff // 255 - make tunable?
  154. // 8188 is a hard limit for bus mastering
  155. #define MAX_TRANSFER_COUNT 0x00001ffc // 8188
  156. #define MASTER_TX_AUTO_APPEND_DESC 0x80000000
  157. /* TX channel config command port */
  158. #define PCR_TIMER_ACCESS 0x0000
  159. #define SCR_TIMER_ACCESS 0x0001
  160. #define BUCKET_CAPACITY_ACCESS 0x0002
  161. #define BUCKET_FULLNESS_ACCESS 0x0003
  162. #define RATE_TYPE_ACCESS 0x0004
  163. // UNUSED 0x00F8
  164. #define TX_CHANNEL_CONFIG_MULT 0x0100
  165. // UNUSED 0xF800
  166. #define BUCKET_MAX_SIZE 0x003f
  167. /* TX channel config data port */
  168. #define CLOCK_SELECT_SHIFT 4
  169. #define CLOCK_DISABLE 0x00ff
  170. #define IDLE_RATE_TYPE 0x0
  171. #define ABR_RATE_TYPE 0x1
  172. #define VBR_RATE_TYPE 0x2
  173. #define CBR_RATE_TYPE 0x3
  174. /* TX config register */
  175. #define DRVR_DRVRBAR_ENABLE 0x0001
  176. #define TXCLK_MUX_SELECT_RCLK 0x0002
  177. #define TRANSMIT_TIMING_MARKER 0x0004
  178. #define LOOPBACK_TIMING_MARKER 0x0008
  179. #define TX_TEST_MODE_16MHz 0x0000
  180. #define TX_TEST_MODE_8MHz 0x0010
  181. #define TX_TEST_MODE_5_33MHz 0x0020
  182. #define TX_TEST_MODE_4MHz 0x0030
  183. #define TX_TEST_MODE_3_2MHz 0x0040
  184. #define TX_TEST_MODE_2_66MHz 0x0050
  185. #define TX_TEST_MODE_2_29MHz 0x0060
  186. #define TX_NORMAL_OPERATION 0x0070
  187. #define ABR_ROUND_ROBIN 0x0080
  188. /* TX status register */
  189. #define IDLE_CHANNELS_MASK 0x00FF
  190. #define ABR_CELL_COUNT_REACHED_MULT 0x0100
  191. #define ABR_CELL_COUNT_REACHED_MASK 0xFF
  192. /* RX config register */
  193. #define NON_USER_CELLS_IN_ONE_CHANNEL 0x0008
  194. #define RX_ENABLE 0x0010
  195. #define IGNORE_UNUSED_VPI_VCI_BITS_SET 0x0000
  196. #define NON_USER_UNUSED_VPI_VCI_BITS_SET 0x0020
  197. #define DISCARD_UNUSED_VPI_VCI_BITS_SET 0x0040
  198. /* RX line config register */
  199. #define SIGNAL_LOSS 0x0001
  200. #define FREQUENCY_DETECT_ERROR 0x0002
  201. #define LOCK_DETECT_ERROR 0x0004
  202. #define SELECT_INTERNAL_LOOPBACK 0x0008
  203. #define LOCK_DETECT_ENABLE 0x0010
  204. #define FREQUENCY_DETECT_ENABLE 0x0020
  205. #define USER_FRAQ 0x0040
  206. #define GXTALOUT_SELECT_DIV4 0x0080
  207. #define GXTALOUT_SELECT_NO_GATING 0x0100
  208. #define TIMING_MARKER_RECEIVED 0x0200
  209. /* RX channel port */
  210. #define RX_CHANNEL_MASK 0x03FF
  211. // UNUSED 0x3C00
  212. #define FLUSH_CHANNEL 0x4000
  213. #define RX_CHANNEL_UPDATE_IN_PROGRESS 0x8000
  214. /* Receive queue entry */
  215. #define RX_Q_ENTRY_LENGTH_MASK 0x0000FFFF
  216. #define RX_Q_ENTRY_CHANNEL_SHIFT 16
  217. #define SIMONS_DODGEY_MARKER 0x08000000
  218. #define RX_CONGESTION_EXPERIENCED 0x10000000
  219. #define RX_CRC_10_OK 0x20000000
  220. #define RX_CRC_32_OK 0x40000000
  221. #define RX_COMPLETE_FRAME 0x80000000
  222. /* Offsets and constants for use with the buffer memory */
  223. /* Buffer pointers and channel types */
  224. #define BUFFER_PTR_MASK 0x0000FFFF
  225. #define RX_INT_THRESHOLD_MULT 0x00010000
  226. #define RX_INT_THRESHOLD_MASK 0x07FF
  227. #define INT_EVERY_N_CELLS 0x08000000
  228. #define CONGESTION_EXPERIENCED 0x10000000
  229. #define FIRST_CELL_OF_AAL5_FRAME 0x20000000
  230. #define CHANNEL_TYPE_AAL5 0x00000000
  231. #define CHANNEL_TYPE_RAW_CELLS 0x40000000
  232. #define CHANNEL_TYPE_AAL3_4 0x80000000
  233. /* Buffer status stuff */
  234. #define BUFF_STATUS_MASK 0x00030000
  235. #define BUFF_STATUS_EMPTY 0x00000000
  236. #define BUFF_STATUS_CELL_AV 0x00010000
  237. #define BUFF_STATUS_LAST_CELL_AV 0x00020000
  238. /* Transmit channel stuff */
  239. /* Receive channel stuff */
  240. #define RX_CHANNEL_DISABLED 0x00000000
  241. #define RX_CHANNEL_IDLE 0x00000001
  242. /* General things */
  243. #define INITIAL_CRC 0xFFFFFFFF
  244. // A Horizon u32, a byte! Really nasty. Horizon pointers are (32 bit)
  245. // word addresses and so standard C pointer operations break (as they
  246. // assume byte addresses); so we pretend that Horizon words (and word
  247. // pointers) are bytes (and byte pointers) for the purposes of having
  248. // a memory map that works.
  249. typedef u8 HDW;
  250. typedef struct cell_buf {
  251. HDW payload[12];
  252. HDW next;
  253. HDW cell_count; // AAL5 rx bufs
  254. HDW res;
  255. union {
  256. HDW partial_crc; // AAL5 rx bufs
  257. HDW cell_header; // RAW bufs
  258. } u;
  259. } cell_buf;
  260. typedef struct tx_ch_desc {
  261. HDW rd_buf_type;
  262. HDW wr_buf_type;
  263. HDW partial_crc;
  264. HDW cell_header;
  265. } tx_ch_desc;
  266. typedef struct rx_ch_desc {
  267. HDW wr_buf_type;
  268. HDW rd_buf_type;
  269. } rx_ch_desc;
  270. typedef struct rx_q_entry {
  271. HDW entry;
  272. } rx_q_entry;
  273. #define TX_CHANS 8
  274. #define RX_CHANS 1024
  275. #define RX_QS 1024
  276. #define MAX_VCS RX_CHANS
  277. /* Horizon buffer memory map */
  278. // TX Channel Descriptors 2
  279. // TX Initial Buffers 8 // TX_CHANS
  280. #define BUFN1_SIZE 118 // (126 - TX_CHANS)
  281. // RX/TX Start/End Buffers 4
  282. #define BUFN2_SIZE 124
  283. // RX Queue Entries 64
  284. #define BUFN3_SIZE 192
  285. // RX Channel Descriptors 128
  286. #define BUFN4_SIZE 1408
  287. // TOTAL cell_buff chunks 2048
  288. // cell_buf bufs[2048];
  289. // HDW dws[32768];
  290. typedef struct MEMMAP {
  291. tx_ch_desc tx_descs[TX_CHANS]; // 8 * 4 = 32 , 0x0020
  292. cell_buf inittxbufs[TX_CHANS]; // these are really
  293. cell_buf bufn1[BUFN1_SIZE]; // part of this pool
  294. cell_buf txfreebufstart;
  295. cell_buf txfreebufend;
  296. cell_buf rxfreebufstart;
  297. cell_buf rxfreebufend; // 8+118+1+1+1+1+124 = 254
  298. cell_buf bufn2[BUFN2_SIZE]; // 16 * 254 = 4064 , 0x1000
  299. rx_q_entry rx_q_entries[RX_QS]; // 1 * 1024 = 1024 , 0x1400
  300. cell_buf bufn3[BUFN3_SIZE]; // 16 * 192 = 3072 , 0x2000
  301. rx_ch_desc rx_descs[MAX_VCS]; // 2 * 1024 = 2048 , 0x2800
  302. cell_buf bufn4[BUFN4_SIZE]; // 16 * 1408 = 22528 , 0x8000
  303. } MEMMAP;
  304. #define memmap ((MEMMAP *)0)
  305. /* end horizon specific bits */
  306. typedef enum {
  307. aal0,
  308. aal34,
  309. aal5
  310. } hrz_aal;
  311. typedef enum {
  312. tx_busy,
  313. rx_busy,
  314. ultra
  315. } hrz_flags;
  316. // a single struct pointed to by atm_vcc->dev_data
  317. typedef struct {
  318. unsigned int tx_rate;
  319. unsigned int rx_rate;
  320. u16 channel;
  321. u16 tx_xbr_bits;
  322. u16 tx_pcr_bits;
  323. #if 0
  324. u16 tx_scr_bits;
  325. u16 tx_bucket_bits;
  326. #endif
  327. hrz_aal aal;
  328. } hrz_vcc;
  329. struct hrz_dev {
  330. u32 iobase;
  331. u32 * membase;
  332. struct sk_buff * rx_skb; // skb being RXed
  333. unsigned int rx_bytes; // bytes remaining to RX within region
  334. void * rx_addr; // addr to send bytes to (for PIO)
  335. unsigned int rx_channel; // channel that the skb is going out on
  336. struct sk_buff * tx_skb; // skb being TXed
  337. unsigned int tx_bytes; // bytes remaining to TX within region
  338. void * tx_addr; // addr to send bytes from (for PIO)
  339. struct iovec * tx_iovec; // remaining regions
  340. unsigned int tx_regions; // number of remaining regions
  341. spinlock_t mem_lock;
  342. wait_queue_head_t tx_queue;
  343. u8 irq;
  344. unsigned long flags;
  345. u8 tx_last;
  346. u8 tx_idle;
  347. rx_q_entry * rx_q_reset;
  348. rx_q_entry * rx_q_entry;
  349. rx_q_entry * rx_q_wrap;
  350. struct atm_dev * atm_dev;
  351. u32 last_vc;
  352. int noof_spare_buffers;
  353. u16 spare_buffers[SPARE_BUFFER_POOL_SIZE];
  354. u16 tx_channel_record[TX_CHANS];
  355. // this is what we follow when we get incoming data
  356. u32 txer[MAX_VCS/32];
  357. struct atm_vcc * rxer[MAX_VCS];
  358. // cell rate allocation
  359. spinlock_t rate_lock;
  360. unsigned int rx_avail;
  361. unsigned int tx_avail;
  362. // dev stats
  363. unsigned long tx_cell_count;
  364. unsigned long rx_cell_count;
  365. unsigned long hec_error_count;
  366. unsigned long unassigned_cell_count;
  367. struct pci_dev * pci_dev;
  368. struct timer_list housekeeping;
  369. };
  370. typedef struct hrz_dev hrz_dev;
  371. /* macros for use later */
  372. #define BUF_PTR(cbptr) ((cbptr) - (cell_buf *) 0)
  373. #define INTERESTING_INTERRUPTS \
  374. (RX_DATA_AV | RX_DISABLED | TX_BUS_MASTER_COMPLETE | RX_BUS_MASTER_COMPLETE)
  375. // 190 cells by default (192 TX buffers - 2 elbow room, see docs)
  376. #define TX_AAL5_LIMIT (190*ATM_CELL_PAYLOAD-ATM_AAL5_TRAILER) // 9112
  377. // Have enough RX buffers (unless we allow other buffer splits)
  378. #define RX_AAL5_LIMIT ATM_MAX_AAL5_PDU
  379. /* multi-statement macro protector */
  380. #define DW(x) do{ x } while(0)
  381. #define HRZ_DEV(atm_dev) ((hrz_dev *) (atm_dev)->dev_data)
  382. #define HRZ_VCC(atm_vcc) ((hrz_vcc *) (atm_vcc)->dev_data)
  383. /* Turn the LEDs on and off */
  384. // The LEDs bits are upside down in that setting the bit in the debug
  385. // register will turn the appropriate LED off.
  386. #define YELLOW_LED DEBUG_BIT_0
  387. #define GREEN_LED DEBUG_BIT_1
  388. #define YELLOW_LED_OE DEBUG_BIT_0_OE
  389. #define GREEN_LED_OE DEBUG_BIT_1_OE
  390. #define GREEN_LED_OFF(dev) \
  391. wr_regl (dev, CONTROL_0_REG, rd_regl (dev, CONTROL_0_REG) | GREEN_LED)
  392. #define GREEN_LED_ON(dev) \
  393. wr_regl (dev, CONTROL_0_REG, rd_regl (dev, CONTROL_0_REG) &~ GREEN_LED)
  394. #define YELLOW_LED_OFF(dev) \
  395. wr_regl (dev, CONTROL_0_REG, rd_regl (dev, CONTROL_0_REG) | YELLOW_LED)
  396. #define YELLOW_LED_ON(dev) \
  397. wr_regl (dev, CONTROL_0_REG, rd_regl (dev, CONTROL_0_REG) &~ YELLOW_LED)
  398. typedef enum {
  399. round_up,
  400. round_down,
  401. round_nearest
  402. } rounding;
  403. #endif /* DRIVER_ATM_HORIZON_H */