hpsa.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. /*
  2. * Disk Array driver for HP Smart Array SAS controllers
  3. * Copyright 2000, 2009 Hewlett-Packard Development Company, L.P.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; version 2 of the License.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  12. * NON INFRINGEMENT. See the GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. *
  18. * Questions/Comments/Bugfixes to iss_storagedev@hp.com
  19. *
  20. */
  21. #ifndef HPSA_H
  22. #define HPSA_H
  23. #include <scsi/scsicam.h>
  24. #define IO_OK 0
  25. #define IO_ERROR 1
  26. struct ctlr_info;
  27. struct access_method {
  28. void (*submit_command)(struct ctlr_info *h,
  29. struct CommandList *c);
  30. void (*set_intr_mask)(struct ctlr_info *h, unsigned long val);
  31. unsigned long (*fifo_full)(struct ctlr_info *h);
  32. bool (*intr_pending)(struct ctlr_info *h);
  33. unsigned long (*command_completed)(struct ctlr_info *h);
  34. };
  35. struct hpsa_scsi_dev_t {
  36. int devtype;
  37. int bus, target, lun; /* as presented to the OS */
  38. unsigned char scsi3addr[8]; /* as presented to the HW */
  39. #define RAID_CTLR_LUNID "\0\0\0\0\0\0\0\0"
  40. unsigned char device_id[16]; /* from inquiry pg. 0x83 */
  41. unsigned char vendor[8]; /* bytes 8-15 of inquiry data */
  42. unsigned char model[16]; /* bytes 16-31 of inquiry data */
  43. unsigned char revision[4]; /* bytes 32-35 of inquiry data */
  44. unsigned char raid_level; /* from inquiry page 0xC1 */
  45. };
  46. struct ctlr_info {
  47. int ctlr;
  48. char devname[8];
  49. char *product_name;
  50. char firm_ver[4]; /* Firmware version */
  51. struct pci_dev *pdev;
  52. u32 board_id;
  53. void __iomem *vaddr;
  54. unsigned long paddr;
  55. int nr_cmds; /* Number of commands allowed on this controller */
  56. struct CfgTable __iomem *cfgtable;
  57. int max_sg_entries;
  58. int interrupts_enabled;
  59. int major;
  60. int max_commands;
  61. int commands_outstanding;
  62. int max_outstanding; /* Debug */
  63. int usage_count; /* number of opens all all minor devices */
  64. # define PERF_MODE_INT 0
  65. # define DOORBELL_INT 1
  66. # define SIMPLE_MODE_INT 2
  67. # define MEMQ_MODE_INT 3
  68. unsigned int intr[4];
  69. unsigned int msix_vector;
  70. unsigned int msi_vector;
  71. struct access_method access;
  72. /* queue and queue Info */
  73. struct hlist_head reqQ;
  74. struct hlist_head cmpQ;
  75. unsigned int Qdepth;
  76. unsigned int maxQsinceinit;
  77. unsigned int maxSG;
  78. spinlock_t lock;
  79. /* pointers to command and error info pool */
  80. struct CommandList *cmd_pool;
  81. dma_addr_t cmd_pool_dhandle;
  82. struct ErrorInfo *errinfo_pool;
  83. dma_addr_t errinfo_pool_dhandle;
  84. unsigned long *cmd_pool_bits;
  85. int nr_allocs;
  86. int nr_frees;
  87. int busy_initializing;
  88. int busy_scanning;
  89. int scan_finished;
  90. spinlock_t scan_lock;
  91. wait_queue_head_t scan_wait_queue;
  92. struct Scsi_Host *scsi_host;
  93. spinlock_t devlock; /* to protect hba[ctlr]->dev[]; */
  94. int ndevices; /* number of used elements in .dev[] array. */
  95. #define HPSA_MAX_SCSI_DEVS_PER_HBA 256
  96. struct hpsa_scsi_dev_t *dev[HPSA_MAX_SCSI_DEVS_PER_HBA];
  97. /*
  98. * Performant mode tables.
  99. */
  100. u32 trans_support;
  101. u32 trans_offset;
  102. struct TransTable_struct *transtable;
  103. unsigned long transMethod;
  104. /*
  105. * Performant mode completion buffer
  106. */
  107. u64 *reply_pool;
  108. dma_addr_t reply_pool_dhandle;
  109. u64 *reply_pool_head;
  110. size_t reply_pool_size;
  111. unsigned char reply_pool_wraparound;
  112. u32 *blockFetchTable;
  113. unsigned char *hba_inquiry_data;
  114. };
  115. #define HPSA_ABORT_MSG 0
  116. #define HPSA_DEVICE_RESET_MSG 1
  117. #define HPSA_BUS_RESET_MSG 2
  118. #define HPSA_HOST_RESET_MSG 3
  119. #define HPSA_MSG_SEND_RETRY_LIMIT 10
  120. #define HPSA_MSG_SEND_RETRY_INTERVAL_MSECS 1000
  121. /* Maximum time in seconds driver will wait for command completions
  122. * when polling before giving up.
  123. */
  124. #define HPSA_MAX_POLL_TIME_SECS (20)
  125. /* During SCSI error recovery, HPSA_TUR_RETRY_LIMIT defines
  126. * how many times to retry TEST UNIT READY on a device
  127. * while waiting for it to become ready before giving up.
  128. * HPSA_MAX_WAIT_INTERVAL_SECS is the max wait interval
  129. * between sending TURs while waiting for a device
  130. * to become ready.
  131. */
  132. #define HPSA_TUR_RETRY_LIMIT (20)
  133. #define HPSA_MAX_WAIT_INTERVAL_SECS (30)
  134. /* HPSA_BOARD_READY_WAIT_SECS is how long to wait for a board
  135. * to become ready, in seconds, before giving up on it.
  136. * HPSA_BOARD_READY_POLL_INTERVAL_MSECS * is how long to wait
  137. * between polling the board to see if it is ready, in
  138. * milliseconds. HPSA_BOARD_READY_POLL_INTERVAL and
  139. * HPSA_BOARD_READY_ITERATIONS are derived from those.
  140. */
  141. #define HPSA_BOARD_READY_WAIT_SECS (120)
  142. #define HPSA_BOARD_READY_POLL_INTERVAL_MSECS (100)
  143. #define HPSA_BOARD_READY_POLL_INTERVAL \
  144. ((HPSA_BOARD_READY_POLL_INTERVAL_MSECS * HZ) / 1000)
  145. #define HPSA_BOARD_READY_ITERATIONS \
  146. ((HPSA_BOARD_READY_WAIT_SECS * 1000) / \
  147. HPSA_BOARD_READY_POLL_INTERVAL_MSECS)
  148. #define HPSA_POST_RESET_PAUSE_MSECS (3000)
  149. #define HPSA_POST_RESET_NOOP_RETRIES (12)
  150. /* Defining the diffent access_menthods */
  151. /*
  152. * Memory mapped FIFO interface (SMART 53xx cards)
  153. */
  154. #define SA5_DOORBELL 0x20
  155. #define SA5_REQUEST_PORT_OFFSET 0x40
  156. #define SA5_REPLY_INTR_MASK_OFFSET 0x34
  157. #define SA5_REPLY_PORT_OFFSET 0x44
  158. #define SA5_INTR_STATUS 0x30
  159. #define SA5_SCRATCHPAD_OFFSET 0xB0
  160. #define SA5_CTCFG_OFFSET 0xB4
  161. #define SA5_CTMEM_OFFSET 0xB8
  162. #define SA5_INTR_OFF 0x08
  163. #define SA5B_INTR_OFF 0x04
  164. #define SA5_INTR_PENDING 0x08
  165. #define SA5B_INTR_PENDING 0x04
  166. #define FIFO_EMPTY 0xffffffff
  167. #define HPSA_FIRMWARE_READY 0xffff0000 /* value in scratchpad register */
  168. #define HPSA_ERROR_BIT 0x02
  169. /* Performant mode flags */
  170. #define SA5_PERF_INTR_PENDING 0x04
  171. #define SA5_PERF_INTR_OFF 0x05
  172. #define SA5_OUTDB_STATUS_PERF_BIT 0x01
  173. #define SA5_OUTDB_CLEAR_PERF_BIT 0x01
  174. #define SA5_OUTDB_CLEAR 0xA0
  175. #define SA5_OUTDB_CLEAR_PERF_BIT 0x01
  176. #define SA5_OUTDB_STATUS 0x9C
  177. #define HPSA_INTR_ON 1
  178. #define HPSA_INTR_OFF 0
  179. /*
  180. Send the command to the hardware
  181. */
  182. static void SA5_submit_command(struct ctlr_info *h,
  183. struct CommandList *c)
  184. {
  185. dev_dbg(&h->pdev->dev, "Sending %x, tag = %x\n", c->busaddr,
  186. c->Header.Tag.lower);
  187. writel(c->busaddr, h->vaddr + SA5_REQUEST_PORT_OFFSET);
  188. h->commands_outstanding++;
  189. if (h->commands_outstanding > h->max_outstanding)
  190. h->max_outstanding = h->commands_outstanding;
  191. }
  192. /*
  193. * This card is the opposite of the other cards.
  194. * 0 turns interrupts on...
  195. * 0x08 turns them off...
  196. */
  197. static void SA5_intr_mask(struct ctlr_info *h, unsigned long val)
  198. {
  199. if (val) { /* Turn interrupts on */
  200. h->interrupts_enabled = 1;
  201. writel(0, h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  202. } else { /* Turn them off */
  203. h->interrupts_enabled = 0;
  204. writel(SA5_INTR_OFF,
  205. h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  206. }
  207. }
  208. static void SA5_performant_intr_mask(struct ctlr_info *h, unsigned long val)
  209. {
  210. if (val) { /* turn on interrupts */
  211. h->interrupts_enabled = 1;
  212. writel(0, h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  213. } else {
  214. h->interrupts_enabled = 0;
  215. writel(SA5_PERF_INTR_OFF,
  216. h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  217. }
  218. }
  219. static unsigned long SA5_performant_completed(struct ctlr_info *h)
  220. {
  221. unsigned long register_value = FIFO_EMPTY;
  222. /* flush the controller write of the reply queue by reading
  223. * outbound doorbell status register.
  224. */
  225. register_value = readl(h->vaddr + SA5_OUTDB_STATUS);
  226. /* msi auto clears the interrupt pending bit. */
  227. if (!(h->msi_vector || h->msix_vector)) {
  228. writel(SA5_OUTDB_CLEAR_PERF_BIT, h->vaddr + SA5_OUTDB_CLEAR);
  229. /* Do a read in order to flush the write to the controller
  230. * (as per spec.)
  231. */
  232. register_value = readl(h->vaddr + SA5_OUTDB_STATUS);
  233. }
  234. if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
  235. register_value = *(h->reply_pool_head);
  236. (h->reply_pool_head)++;
  237. h->commands_outstanding--;
  238. } else {
  239. register_value = FIFO_EMPTY;
  240. }
  241. /* Check for wraparound */
  242. if (h->reply_pool_head == (h->reply_pool + h->max_commands)) {
  243. h->reply_pool_head = h->reply_pool;
  244. h->reply_pool_wraparound ^= 1;
  245. }
  246. return register_value;
  247. }
  248. /*
  249. * Returns true if fifo is full.
  250. *
  251. */
  252. static unsigned long SA5_fifo_full(struct ctlr_info *h)
  253. {
  254. if (h->commands_outstanding >= h->max_commands)
  255. return 1;
  256. else
  257. return 0;
  258. }
  259. /*
  260. * returns value read from hardware.
  261. * returns FIFO_EMPTY if there is nothing to read
  262. */
  263. static unsigned long SA5_completed(struct ctlr_info *h)
  264. {
  265. unsigned long register_value
  266. = readl(h->vaddr + SA5_REPLY_PORT_OFFSET);
  267. if (register_value != FIFO_EMPTY)
  268. h->commands_outstanding--;
  269. #ifdef HPSA_DEBUG
  270. if (register_value != FIFO_EMPTY)
  271. dev_dbg(&h->pdev->dev, "Read %lx back from board\n",
  272. register_value);
  273. else
  274. dev_dbg(&h->pdev->dev, "hpsa: FIFO Empty read\n");
  275. #endif
  276. return register_value;
  277. }
  278. /*
  279. * Returns true if an interrupt is pending..
  280. */
  281. static bool SA5_intr_pending(struct ctlr_info *h)
  282. {
  283. unsigned long register_value =
  284. readl(h->vaddr + SA5_INTR_STATUS);
  285. dev_dbg(&h->pdev->dev, "intr_pending %lx\n", register_value);
  286. return register_value & SA5_INTR_PENDING;
  287. }
  288. static bool SA5_performant_intr_pending(struct ctlr_info *h)
  289. {
  290. unsigned long register_value = readl(h->vaddr + SA5_INTR_STATUS);
  291. if (!register_value)
  292. return false;
  293. if (h->msi_vector || h->msix_vector)
  294. return true;
  295. /* Read outbound doorbell to flush */
  296. register_value = readl(h->vaddr + SA5_OUTDB_STATUS);
  297. return register_value & SA5_OUTDB_STATUS_PERF_BIT;
  298. }
  299. static struct access_method SA5_access = {
  300. SA5_submit_command,
  301. SA5_intr_mask,
  302. SA5_fifo_full,
  303. SA5_intr_pending,
  304. SA5_completed,
  305. };
  306. static struct access_method SA5_performant_access = {
  307. SA5_submit_command,
  308. SA5_performant_intr_mask,
  309. SA5_fifo_full,
  310. SA5_performant_intr_pending,
  311. SA5_performant_completed,
  312. };
  313. struct board_type {
  314. u32 board_id;
  315. char *product_name;
  316. struct access_method *access;
  317. };
  318. #endif /* HPSA_H */