hpsa.h 12 KB

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