hpsa.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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 raid_level; /* from inquiry page 0xC1 */
  44. };
  45. struct ctlr_info {
  46. int ctlr;
  47. char devname[8];
  48. char *product_name;
  49. struct pci_dev *pdev;
  50. u32 board_id;
  51. void __iomem *vaddr;
  52. unsigned long paddr;
  53. int nr_cmds; /* Number of commands allowed on this controller */
  54. struct CfgTable __iomem *cfgtable;
  55. int interrupts_enabled;
  56. int major;
  57. int max_commands;
  58. int commands_outstanding;
  59. int max_outstanding; /* Debug */
  60. int usage_count; /* number of opens all all minor devices */
  61. # define PERF_MODE_INT 0
  62. # define DOORBELL_INT 1
  63. # define SIMPLE_MODE_INT 2
  64. # define MEMQ_MODE_INT 3
  65. unsigned int intr[4];
  66. unsigned int msix_vector;
  67. unsigned int msi_vector;
  68. int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
  69. struct access_method access;
  70. /* queue and queue Info */
  71. struct list_head reqQ;
  72. struct list_head cmpQ;
  73. unsigned int Qdepth;
  74. unsigned int maxQsinceinit;
  75. unsigned int maxSG;
  76. spinlock_t lock;
  77. int maxsgentries;
  78. u8 max_cmd_sg_entries;
  79. int chainsize;
  80. struct SGDescriptor **cmd_sg_list;
  81. /* pointers to command and error info pool */
  82. struct CommandList *cmd_pool;
  83. dma_addr_t cmd_pool_dhandle;
  84. struct ErrorInfo *errinfo_pool;
  85. dma_addr_t errinfo_pool_dhandle;
  86. unsigned long *cmd_pool_bits;
  87. int nr_allocs;
  88. int nr_frees;
  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. struct hpsa_scsi_dev_t *dev[HPSA_MAX_DEVICES];
  96. /*
  97. * Performant mode tables.
  98. */
  99. u32 trans_support;
  100. u32 trans_offset;
  101. struct TransTable_struct *transtable;
  102. unsigned long transMethod;
  103. /*
  104. * Performant mode completion buffer
  105. */
  106. u64 *reply_pool;
  107. dma_addr_t reply_pool_dhandle;
  108. u64 *reply_pool_head;
  109. size_t reply_pool_size;
  110. unsigned char reply_pool_wraparound;
  111. u32 *blockFetchTable;
  112. unsigned char *hba_inquiry_data;
  113. u64 last_intr_timestamp;
  114. u32 last_heartbeat;
  115. u64 last_heartbeat_timestamp;
  116. u32 heartbeat_sample_interval;
  117. atomic_t firmware_flash_in_progress;
  118. u32 lockup_detected;
  119. struct list_head lockup_list;
  120. };
  121. #define HPSA_ABORT_MSG 0
  122. #define HPSA_DEVICE_RESET_MSG 1
  123. #define HPSA_RESET_TYPE_CONTROLLER 0x00
  124. #define HPSA_RESET_TYPE_BUS 0x01
  125. #define HPSA_RESET_TYPE_TARGET 0x03
  126. #define HPSA_RESET_TYPE_LUN 0x04
  127. #define HPSA_MSG_SEND_RETRY_LIMIT 10
  128. #define HPSA_MSG_SEND_RETRY_INTERVAL_MSECS (10000)
  129. /* Maximum time in seconds driver will wait for command completions
  130. * when polling before giving up.
  131. */
  132. #define HPSA_MAX_POLL_TIME_SECS (20)
  133. /* During SCSI error recovery, HPSA_TUR_RETRY_LIMIT defines
  134. * how many times to retry TEST UNIT READY on a device
  135. * while waiting for it to become ready before giving up.
  136. * HPSA_MAX_WAIT_INTERVAL_SECS is the max wait interval
  137. * between sending TURs while waiting for a device
  138. * to become ready.
  139. */
  140. #define HPSA_TUR_RETRY_LIMIT (20)
  141. #define HPSA_MAX_WAIT_INTERVAL_SECS (30)
  142. /* HPSA_BOARD_READY_WAIT_SECS is how long to wait for a board
  143. * to become ready, in seconds, before giving up on it.
  144. * HPSA_BOARD_READY_POLL_INTERVAL_MSECS * is how long to wait
  145. * between polling the board to see if it is ready, in
  146. * milliseconds. HPSA_BOARD_READY_POLL_INTERVAL and
  147. * HPSA_BOARD_READY_ITERATIONS are derived from those.
  148. */
  149. #define HPSA_BOARD_READY_WAIT_SECS (120)
  150. #define HPSA_BOARD_NOT_READY_WAIT_SECS (100)
  151. #define HPSA_BOARD_READY_POLL_INTERVAL_MSECS (100)
  152. #define HPSA_BOARD_READY_POLL_INTERVAL \
  153. ((HPSA_BOARD_READY_POLL_INTERVAL_MSECS * HZ) / 1000)
  154. #define HPSA_BOARD_READY_ITERATIONS \
  155. ((HPSA_BOARD_READY_WAIT_SECS * 1000) / \
  156. HPSA_BOARD_READY_POLL_INTERVAL_MSECS)
  157. #define HPSA_BOARD_NOT_READY_ITERATIONS \
  158. ((HPSA_BOARD_NOT_READY_WAIT_SECS * 1000) / \
  159. HPSA_BOARD_READY_POLL_INTERVAL_MSECS)
  160. #define HPSA_POST_RESET_PAUSE_MSECS (3000)
  161. #define HPSA_POST_RESET_NOOP_RETRIES (12)
  162. /* Defining the diffent access_menthods */
  163. /*
  164. * Memory mapped FIFO interface (SMART 53xx cards)
  165. */
  166. #define SA5_DOORBELL 0x20
  167. #define SA5_REQUEST_PORT_OFFSET 0x40
  168. #define SA5_REPLY_INTR_MASK_OFFSET 0x34
  169. #define SA5_REPLY_PORT_OFFSET 0x44
  170. #define SA5_INTR_STATUS 0x30
  171. #define SA5_SCRATCHPAD_OFFSET 0xB0
  172. #define SA5_CTCFG_OFFSET 0xB4
  173. #define SA5_CTMEM_OFFSET 0xB8
  174. #define SA5_INTR_OFF 0x08
  175. #define SA5B_INTR_OFF 0x04
  176. #define SA5_INTR_PENDING 0x08
  177. #define SA5B_INTR_PENDING 0x04
  178. #define FIFO_EMPTY 0xffffffff
  179. #define HPSA_FIRMWARE_READY 0xffff0000 /* value in scratchpad register */
  180. #define HPSA_ERROR_BIT 0x02
  181. /* Performant mode flags */
  182. #define SA5_PERF_INTR_PENDING 0x04
  183. #define SA5_PERF_INTR_OFF 0x05
  184. #define SA5_OUTDB_STATUS_PERF_BIT 0x01
  185. #define SA5_OUTDB_CLEAR_PERF_BIT 0x01
  186. #define SA5_OUTDB_CLEAR 0xA0
  187. #define SA5_OUTDB_CLEAR_PERF_BIT 0x01
  188. #define SA5_OUTDB_STATUS 0x9C
  189. #define HPSA_INTR_ON 1
  190. #define HPSA_INTR_OFF 0
  191. /*
  192. Send the command to the hardware
  193. */
  194. static void SA5_submit_command(struct ctlr_info *h,
  195. struct CommandList *c)
  196. {
  197. dev_dbg(&h->pdev->dev, "Sending %x, tag = %x\n", c->busaddr,
  198. c->Header.Tag.lower);
  199. writel(c->busaddr, h->vaddr + SA5_REQUEST_PORT_OFFSET);
  200. (void) readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
  201. h->commands_outstanding++;
  202. if (h->commands_outstanding > h->max_outstanding)
  203. h->max_outstanding = h->commands_outstanding;
  204. }
  205. /*
  206. * This card is the opposite of the other cards.
  207. * 0 turns interrupts on...
  208. * 0x08 turns them off...
  209. */
  210. static void SA5_intr_mask(struct ctlr_info *h, unsigned long val)
  211. {
  212. if (val) { /* Turn interrupts on */
  213. h->interrupts_enabled = 1;
  214. writel(0, h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  215. (void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  216. } else { /* Turn them off */
  217. h->interrupts_enabled = 0;
  218. writel(SA5_INTR_OFF,
  219. h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  220. (void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  221. }
  222. }
  223. static void SA5_performant_intr_mask(struct ctlr_info *h, unsigned long val)
  224. {
  225. if (val) { /* turn on interrupts */
  226. h->interrupts_enabled = 1;
  227. writel(0, h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  228. (void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  229. } else {
  230. h->interrupts_enabled = 0;
  231. writel(SA5_PERF_INTR_OFF,
  232. h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  233. (void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  234. }
  235. }
  236. static unsigned long SA5_performant_completed(struct ctlr_info *h)
  237. {
  238. unsigned long register_value = FIFO_EMPTY;
  239. /* flush the controller write of the reply queue by reading
  240. * outbound doorbell status register.
  241. */
  242. register_value = readl(h->vaddr + SA5_OUTDB_STATUS);
  243. /* msi auto clears the interrupt pending bit. */
  244. if (!(h->msi_vector || h->msix_vector)) {
  245. writel(SA5_OUTDB_CLEAR_PERF_BIT, h->vaddr + SA5_OUTDB_CLEAR);
  246. /* Do a read in order to flush the write to the controller
  247. * (as per spec.)
  248. */
  249. register_value = readl(h->vaddr + SA5_OUTDB_STATUS);
  250. }
  251. if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
  252. register_value = *(h->reply_pool_head);
  253. (h->reply_pool_head)++;
  254. h->commands_outstanding--;
  255. } else {
  256. register_value = FIFO_EMPTY;
  257. }
  258. /* Check for wraparound */
  259. if (h->reply_pool_head == (h->reply_pool + h->max_commands)) {
  260. h->reply_pool_head = h->reply_pool;
  261. h->reply_pool_wraparound ^= 1;
  262. }
  263. return register_value;
  264. }
  265. /*
  266. * Returns true if fifo is full.
  267. *
  268. */
  269. static unsigned long SA5_fifo_full(struct ctlr_info *h)
  270. {
  271. if (h->commands_outstanding >= h->max_commands)
  272. return 1;
  273. else
  274. return 0;
  275. }
  276. /*
  277. * returns value read from hardware.
  278. * returns FIFO_EMPTY if there is nothing to read
  279. */
  280. static unsigned long SA5_completed(struct ctlr_info *h)
  281. {
  282. unsigned long register_value
  283. = readl(h->vaddr + SA5_REPLY_PORT_OFFSET);
  284. if (register_value != FIFO_EMPTY)
  285. h->commands_outstanding--;
  286. #ifdef HPSA_DEBUG
  287. if (register_value != FIFO_EMPTY)
  288. dev_dbg(&h->pdev->dev, "Read %lx back from board\n",
  289. register_value);
  290. else
  291. dev_dbg(&h->pdev->dev, "FIFO Empty read\n");
  292. #endif
  293. return register_value;
  294. }
  295. /*
  296. * Returns true if an interrupt is pending..
  297. */
  298. static bool SA5_intr_pending(struct ctlr_info *h)
  299. {
  300. unsigned long register_value =
  301. readl(h->vaddr + SA5_INTR_STATUS);
  302. dev_dbg(&h->pdev->dev, "intr_pending %lx\n", register_value);
  303. return register_value & SA5_INTR_PENDING;
  304. }
  305. static bool SA5_performant_intr_pending(struct ctlr_info *h)
  306. {
  307. unsigned long register_value = readl(h->vaddr + SA5_INTR_STATUS);
  308. if (!register_value)
  309. return false;
  310. if (h->msi_vector || h->msix_vector)
  311. return true;
  312. /* Read outbound doorbell to flush */
  313. register_value = readl(h->vaddr + SA5_OUTDB_STATUS);
  314. return register_value & SA5_OUTDB_STATUS_PERF_BIT;
  315. }
  316. static struct access_method SA5_access = {
  317. SA5_submit_command,
  318. SA5_intr_mask,
  319. SA5_fifo_full,
  320. SA5_intr_pending,
  321. SA5_completed,
  322. };
  323. static struct access_method SA5_performant_access = {
  324. SA5_submit_command,
  325. SA5_performant_intr_mask,
  326. SA5_fifo_full,
  327. SA5_performant_intr_pending,
  328. SA5_performant_completed,
  329. };
  330. struct board_type {
  331. u32 board_id;
  332. char *product_name;
  333. struct access_method *access;
  334. };
  335. #endif /* HPSA_H */