cciss.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. #ifndef CCISS_H
  2. #define CCISS_H
  3. #include <linux/genhd.h>
  4. #include <linux/mutex.h>
  5. #include "cciss_cmd.h"
  6. #define NWD_SHIFT 4
  7. #define MAX_PART (1 << NWD_SHIFT)
  8. #define IO_OK 0
  9. #define IO_ERROR 1
  10. #define IO_NEEDS_RETRY 3
  11. #define VENDOR_LEN 8
  12. #define MODEL_LEN 16
  13. #define REV_LEN 4
  14. struct ctlr_info;
  15. typedef struct ctlr_info ctlr_info_t;
  16. struct access_method {
  17. void (*submit_command)(ctlr_info_t *h, CommandList_struct *c);
  18. void (*set_intr_mask)(ctlr_info_t *h, unsigned long val);
  19. unsigned long (*fifo_full)(ctlr_info_t *h);
  20. bool (*intr_pending)(ctlr_info_t *h);
  21. unsigned long (*command_completed)(ctlr_info_t *h);
  22. };
  23. typedef struct _drive_info_struct
  24. {
  25. unsigned char LunID[8];
  26. int usage_count;
  27. struct request_queue *queue;
  28. sector_t nr_blocks;
  29. int block_size;
  30. int heads;
  31. int sectors;
  32. int cylinders;
  33. int raid_level; /* set to -1 to indicate that
  34. * the drive is not in use/configured
  35. */
  36. int busy_configuring; /* This is set when a drive is being removed
  37. * to prevent it from being opened or it's
  38. * queue from being started.
  39. */
  40. struct device dev;
  41. __u8 serial_no[16]; /* from inquiry page 0x83,
  42. * not necc. null terminated.
  43. */
  44. char vendor[VENDOR_LEN + 1]; /* SCSI vendor string */
  45. char model[MODEL_LEN + 1]; /* SCSI model string */
  46. char rev[REV_LEN + 1]; /* SCSI revision string */
  47. char device_initialized; /* indicates whether dev is initialized */
  48. } drive_info_struct;
  49. struct ctlr_info
  50. {
  51. int ctlr;
  52. char devname[8];
  53. char *product_name;
  54. char firm_ver[4]; /* Firmware version */
  55. struct pci_dev *pdev;
  56. __u32 board_id;
  57. void __iomem *vaddr;
  58. unsigned long paddr;
  59. int nr_cmds; /* Number of commands allowed on this controller */
  60. CfgTable_struct __iomem *cfgtable;
  61. int interrupts_enabled;
  62. int major;
  63. int max_commands;
  64. int commands_outstanding;
  65. int max_outstanding; /* Debug */
  66. int num_luns;
  67. int highest_lun;
  68. int usage_count; /* number of opens all all minor devices */
  69. /* Need space for temp sg list
  70. * number of scatter/gathers supported
  71. * number of scatter/gathers in chained block
  72. */
  73. struct scatterlist **scatter_list;
  74. int maxsgentries;
  75. int chainsize;
  76. int max_cmd_sgentries;
  77. SGDescriptor_struct **cmd_sg_list;
  78. # define PERF_MODE_INT 0
  79. # define DOORBELL_INT 1
  80. # define SIMPLE_MODE_INT 2
  81. # define MEMQ_MODE_INT 3
  82. unsigned int intr[4];
  83. unsigned int msix_vector;
  84. unsigned int msi_vector;
  85. int intr_mode;
  86. int cciss_max_sectors;
  87. BYTE cciss_read;
  88. BYTE cciss_write;
  89. BYTE cciss_read_capacity;
  90. /* information about each logical volume */
  91. drive_info_struct *drv[CISS_MAX_LUN];
  92. struct access_method access;
  93. /* queue and queue Info */
  94. struct list_head reqQ;
  95. struct list_head cmpQ;
  96. unsigned int Qdepth;
  97. unsigned int maxQsinceinit;
  98. unsigned int maxSG;
  99. spinlock_t lock;
  100. /* pointers to command and error info pool */
  101. CommandList_struct *cmd_pool;
  102. dma_addr_t cmd_pool_dhandle;
  103. ErrorInfo_struct *errinfo_pool;
  104. dma_addr_t errinfo_pool_dhandle;
  105. unsigned long *cmd_pool_bits;
  106. int nr_allocs;
  107. int nr_frees;
  108. int busy_configuring;
  109. int busy_initializing;
  110. int busy_scanning;
  111. struct mutex busy_shutting_down;
  112. /* This element holds the zero based queue number of the last
  113. * queue to be started. It is used for fairness.
  114. */
  115. int next_to_run;
  116. /* Disk structures we need to pass back */
  117. struct gendisk *gendisk[CISS_MAX_LUN];
  118. #ifdef CONFIG_CISS_SCSI_TAPE
  119. struct cciss_scsi_adapter_data_t *scsi_ctlr;
  120. #endif
  121. unsigned char alive;
  122. struct list_head scan_list;
  123. struct completion scan_wait;
  124. struct device dev;
  125. /*
  126. * Performant mode tables.
  127. */
  128. u32 trans_support;
  129. u32 trans_offset;
  130. struct TransTable_struct *transtable;
  131. unsigned long transMethod;
  132. /*
  133. * Performant mode completion buffer
  134. */
  135. u64 *reply_pool;
  136. dma_addr_t reply_pool_dhandle;
  137. u64 *reply_pool_head;
  138. size_t reply_pool_size;
  139. unsigned char reply_pool_wraparound;
  140. u32 *blockFetchTable;
  141. };
  142. /* Defining the diffent access_methods
  143. *
  144. * Memory mapped FIFO interface (SMART 53xx cards)
  145. */
  146. #define SA5_DOORBELL 0x20
  147. #define SA5_REQUEST_PORT_OFFSET 0x40
  148. #define SA5_REPLY_INTR_MASK_OFFSET 0x34
  149. #define SA5_REPLY_PORT_OFFSET 0x44
  150. #define SA5_INTR_STATUS 0x30
  151. #define SA5_SCRATCHPAD_OFFSET 0xB0
  152. #define SA5_CTCFG_OFFSET 0xB4
  153. #define SA5_CTMEM_OFFSET 0xB8
  154. #define SA5_INTR_OFF 0x08
  155. #define SA5B_INTR_OFF 0x04
  156. #define SA5_INTR_PENDING 0x08
  157. #define SA5B_INTR_PENDING 0x04
  158. #define FIFO_EMPTY 0xffffffff
  159. #define CCISS_FIRMWARE_READY 0xffff0000 /* value in scratchpad register */
  160. /* Perf. mode flags */
  161. #define SA5_PERF_INTR_PENDING 0x04
  162. #define SA5_PERF_INTR_OFF 0x05
  163. #define SA5_OUTDB_STATUS_PERF_BIT 0x01
  164. #define SA5_OUTDB_CLEAR_PERF_BIT 0x01
  165. #define SA5_OUTDB_CLEAR 0xA0
  166. #define SA5_OUTDB_CLEAR_PERF_BIT 0x01
  167. #define SA5_OUTDB_STATUS 0x9C
  168. #define CISS_ERROR_BIT 0x02
  169. #define CCISS_INTR_ON 1
  170. #define CCISS_INTR_OFF 0
  171. /* CCISS_BOARD_READY_WAIT_SECS is how long to wait for a board
  172. * to become ready, in seconds, before giving up on it.
  173. * CCISS_BOARD_READY_POLL_INTERVAL_MSECS * is how long to wait
  174. * between polling the board to see if it is ready, in
  175. * milliseconds. CCISS_BOARD_READY_ITERATIONS is derived
  176. * the above.
  177. */
  178. #define CCISS_BOARD_READY_WAIT_SECS (120)
  179. #define CCISS_BOARD_NOT_READY_WAIT_SECS (100)
  180. #define CCISS_BOARD_READY_POLL_INTERVAL_MSECS (100)
  181. #define CCISS_BOARD_READY_ITERATIONS \
  182. ((CCISS_BOARD_READY_WAIT_SECS * 1000) / \
  183. CCISS_BOARD_READY_POLL_INTERVAL_MSECS)
  184. #define CCISS_BOARD_NOT_READY_ITERATIONS \
  185. ((CCISS_BOARD_NOT_READY_WAIT_SECS * 1000) / \
  186. CCISS_BOARD_READY_POLL_INTERVAL_MSECS)
  187. #define CCISS_POST_RESET_PAUSE_MSECS (3000)
  188. #define CCISS_POST_RESET_NOOP_INTERVAL_MSECS (4000)
  189. #define CCISS_POST_RESET_NOOP_RETRIES (12)
  190. #define CCISS_POST_RESET_NOOP_TIMEOUT_MSECS (10000)
  191. /*
  192. Send the command to the hardware
  193. */
  194. static void SA5_submit_command( ctlr_info_t *h, CommandList_struct *c)
  195. {
  196. #ifdef CCISS_DEBUG
  197. printk(KERN_WARNING "cciss%d: Sending %08x - down to controller\n",
  198. h->ctlr, c->busaddr);
  199. #endif /* CCISS_DEBUG */
  200. writel(c->busaddr, h->vaddr + SA5_REQUEST_PORT_OFFSET);
  201. readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
  202. h->commands_outstanding++;
  203. if ( h->commands_outstanding > h->max_outstanding)
  204. h->max_outstanding = h->commands_outstanding;
  205. }
  206. /*
  207. * This card is the opposite of the other cards.
  208. * 0 turns interrupts on...
  209. * 0x08 turns them off...
  210. */
  211. static void SA5_intr_mask(ctlr_info_t *h, unsigned long val)
  212. {
  213. if (val)
  214. { /* Turn interrupts on */
  215. h->interrupts_enabled = 1;
  216. writel(0, h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  217. (void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  218. } else /* Turn them off */
  219. {
  220. h->interrupts_enabled = 0;
  221. writel( SA5_INTR_OFF,
  222. h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  223. (void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  224. }
  225. }
  226. /*
  227. * This card is the opposite of the other cards.
  228. * 0 turns interrupts on...
  229. * 0x04 turns them off...
  230. */
  231. static void SA5B_intr_mask(ctlr_info_t *h, unsigned long val)
  232. {
  233. if (val)
  234. { /* Turn interrupts on */
  235. h->interrupts_enabled = 1;
  236. writel(0, h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  237. (void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  238. } else /* Turn them off */
  239. {
  240. h->interrupts_enabled = 0;
  241. writel( SA5B_INTR_OFF,
  242. h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  243. (void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  244. }
  245. }
  246. /* Performant mode intr_mask */
  247. static void SA5_performant_intr_mask(ctlr_info_t *h, unsigned long val)
  248. {
  249. if (val) { /* turn on interrupts */
  250. h->interrupts_enabled = 1;
  251. writel(0, h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  252. (void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  253. } else {
  254. h->interrupts_enabled = 0;
  255. writel(SA5_PERF_INTR_OFF,
  256. h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  257. (void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  258. }
  259. }
  260. /*
  261. * Returns true if fifo is full.
  262. *
  263. */
  264. static unsigned long SA5_fifo_full(ctlr_info_t *h)
  265. {
  266. if( h->commands_outstanding >= h->max_commands)
  267. return(1);
  268. else
  269. return(0);
  270. }
  271. /*
  272. * returns value read from hardware.
  273. * returns FIFO_EMPTY if there is nothing to read
  274. */
  275. static unsigned long SA5_completed(ctlr_info_t *h)
  276. {
  277. unsigned long register_value
  278. = readl(h->vaddr + SA5_REPLY_PORT_OFFSET);
  279. if(register_value != FIFO_EMPTY)
  280. {
  281. h->commands_outstanding--;
  282. #ifdef CCISS_DEBUG
  283. printk("cciss: Read %lx back from board\n", register_value);
  284. #endif /* CCISS_DEBUG */
  285. }
  286. #ifdef CCISS_DEBUG
  287. else
  288. {
  289. printk("cciss: FIFO Empty read\n");
  290. }
  291. #endif
  292. return ( register_value);
  293. }
  294. /* Performant mode command completed */
  295. static unsigned long SA5_performant_completed(ctlr_info_t *h)
  296. {
  297. unsigned long register_value = FIFO_EMPTY;
  298. /* flush the controller write of the reply queue by reading
  299. * outbound doorbell status register.
  300. */
  301. register_value = readl(h->vaddr + SA5_OUTDB_STATUS);
  302. /* msi auto clears the interrupt pending bit. */
  303. if (!(h->msi_vector || h->msix_vector)) {
  304. writel(SA5_OUTDB_CLEAR_PERF_BIT, h->vaddr + SA5_OUTDB_CLEAR);
  305. /* Do a read in order to flush the write to the controller
  306. * (as per spec.)
  307. */
  308. register_value = readl(h->vaddr + SA5_OUTDB_STATUS);
  309. }
  310. if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
  311. register_value = *(h->reply_pool_head);
  312. (h->reply_pool_head)++;
  313. h->commands_outstanding--;
  314. } else {
  315. register_value = FIFO_EMPTY;
  316. }
  317. /* Check for wraparound */
  318. if (h->reply_pool_head == (h->reply_pool + h->max_commands)) {
  319. h->reply_pool_head = h->reply_pool;
  320. h->reply_pool_wraparound ^= 1;
  321. }
  322. return register_value;
  323. }
  324. /*
  325. * Returns true if an interrupt is pending..
  326. */
  327. static bool SA5_intr_pending(ctlr_info_t *h)
  328. {
  329. unsigned long register_value =
  330. readl(h->vaddr + SA5_INTR_STATUS);
  331. #ifdef CCISS_DEBUG
  332. printk("cciss: intr_pending %lx\n", register_value);
  333. #endif /* CCISS_DEBUG */
  334. if( register_value & SA5_INTR_PENDING)
  335. return 1;
  336. return 0 ;
  337. }
  338. /*
  339. * Returns true if an interrupt is pending..
  340. */
  341. static bool SA5B_intr_pending(ctlr_info_t *h)
  342. {
  343. unsigned long register_value =
  344. readl(h->vaddr + SA5_INTR_STATUS);
  345. #ifdef CCISS_DEBUG
  346. printk("cciss: intr_pending %lx\n", register_value);
  347. #endif /* CCISS_DEBUG */
  348. if( register_value & SA5B_INTR_PENDING)
  349. return 1;
  350. return 0 ;
  351. }
  352. static bool SA5_performant_intr_pending(ctlr_info_t *h)
  353. {
  354. unsigned long register_value = readl(h->vaddr + SA5_INTR_STATUS);
  355. if (!register_value)
  356. return false;
  357. if (h->msi_vector || h->msix_vector)
  358. return true;
  359. /* Read outbound doorbell to flush */
  360. register_value = readl(h->vaddr + SA5_OUTDB_STATUS);
  361. return register_value & SA5_OUTDB_STATUS_PERF_BIT;
  362. }
  363. static struct access_method SA5_access = {
  364. SA5_submit_command,
  365. SA5_intr_mask,
  366. SA5_fifo_full,
  367. SA5_intr_pending,
  368. SA5_completed,
  369. };
  370. static struct access_method SA5B_access = {
  371. SA5_submit_command,
  372. SA5B_intr_mask,
  373. SA5_fifo_full,
  374. SA5B_intr_pending,
  375. SA5_completed,
  376. };
  377. static struct access_method SA5_performant_access = {
  378. SA5_submit_command,
  379. SA5_performant_intr_mask,
  380. SA5_fifo_full,
  381. SA5_performant_intr_pending,
  382. SA5_performant_completed,
  383. };
  384. struct board_type {
  385. __u32 board_id;
  386. char *product_name;
  387. struct access_method *access;
  388. int nr_cmds; /* Max cmds this kind of ctlr can handle. */
  389. };
  390. #endif /* CCISS_H */