hpsa.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. unsigned long (*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 interrupts_enabled;
  58. int major;
  59. int max_commands;
  60. int commands_outstanding;
  61. int max_outstanding; /* Debug */
  62. int usage_count; /* number of opens all all minor devices */
  63. # define DOORBELL_INT 0
  64. # define PERF_MODE_INT 1
  65. # define SIMPLE_MODE_INT 2
  66. # define MEMQ_MODE_INT 3
  67. unsigned int intr[4];
  68. unsigned int msix_vector;
  69. unsigned int msi_vector;
  70. struct access_method access;
  71. /* queue and queue Info */
  72. struct hlist_head reqQ;
  73. struct hlist_head cmpQ;
  74. unsigned int Qdepth;
  75. unsigned int maxQsinceinit;
  76. unsigned int maxSG;
  77. spinlock_t lock;
  78. /* pointers to command and error info pool */
  79. struct CommandList *cmd_pool;
  80. dma_addr_t cmd_pool_dhandle;
  81. struct ErrorInfo *errinfo_pool;
  82. dma_addr_t errinfo_pool_dhandle;
  83. unsigned long *cmd_pool_bits;
  84. int nr_allocs;
  85. int nr_frees;
  86. int busy_initializing;
  87. int busy_scanning;
  88. struct mutex busy_shutting_down;
  89. struct list_head scan_list;
  90. struct completion scan_wait;
  91. struct Scsi_Host *scsi_host;
  92. spinlock_t devlock; /* to protect hba[ctlr]->dev[]; */
  93. int ndevices; /* number of used elements in .dev[] array. */
  94. #define HPSA_MAX_SCSI_DEVS_PER_HBA 256
  95. struct hpsa_scsi_dev_t *dev[HPSA_MAX_SCSI_DEVS_PER_HBA];
  96. };
  97. #define HPSA_ABORT_MSG 0
  98. #define HPSA_DEVICE_RESET_MSG 1
  99. #define HPSA_BUS_RESET_MSG 2
  100. #define HPSA_HOST_RESET_MSG 3
  101. #define HPSA_MSG_SEND_RETRY_LIMIT 10
  102. #define HPSA_MSG_SEND_RETRY_INTERVAL_MSECS 1000
  103. /* Maximum time in seconds driver will wait for command completions
  104. * when polling before giving up.
  105. */
  106. #define HPSA_MAX_POLL_TIME_SECS (20)
  107. /* During SCSI error recovery, HPSA_TUR_RETRY_LIMIT defines
  108. * how many times to retry TEST UNIT READY on a device
  109. * while waiting for it to become ready before giving up.
  110. * HPSA_MAX_WAIT_INTERVAL_SECS is the max wait interval
  111. * between sending TURs while waiting for a device
  112. * to become ready.
  113. */
  114. #define HPSA_TUR_RETRY_LIMIT (20)
  115. #define HPSA_MAX_WAIT_INTERVAL_SECS (30)
  116. /* HPSA_BOARD_READY_WAIT_SECS is how long to wait for a board
  117. * to become ready, in seconds, before giving up on it.
  118. * HPSA_BOARD_READY_POLL_INTERVAL_MSECS * is how long to wait
  119. * between polling the board to see if it is ready, in
  120. * milliseconds. HPSA_BOARD_READY_POLL_INTERVAL and
  121. * HPSA_BOARD_READY_ITERATIONS are derived from those.
  122. */
  123. #define HPSA_BOARD_READY_WAIT_SECS (120)
  124. #define HPSA_BOARD_READY_POLL_INTERVAL_MSECS (100)
  125. #define HPSA_BOARD_READY_POLL_INTERVAL \
  126. ((HPSA_BOARD_READY_POLL_INTERVAL_MSECS * HZ) / 1000)
  127. #define HPSA_BOARD_READY_ITERATIONS \
  128. ((HPSA_BOARD_READY_WAIT_SECS * 1000) / \
  129. HPSA_BOARD_READY_POLL_INTERVAL_MSECS)
  130. #define HPSA_POST_RESET_PAUSE_MSECS (3000)
  131. #define HPSA_POST_RESET_NOOP_RETRIES (12)
  132. /* Defining the diffent access_menthods */
  133. /*
  134. * Memory mapped FIFO interface (SMART 53xx cards)
  135. */
  136. #define SA5_DOORBELL 0x20
  137. #define SA5_REQUEST_PORT_OFFSET 0x40
  138. #define SA5_REPLY_INTR_MASK_OFFSET 0x34
  139. #define SA5_REPLY_PORT_OFFSET 0x44
  140. #define SA5_INTR_STATUS 0x30
  141. #define SA5_SCRATCHPAD_OFFSET 0xB0
  142. #define SA5_CTCFG_OFFSET 0xB4
  143. #define SA5_CTMEM_OFFSET 0xB8
  144. #define SA5_INTR_OFF 0x08
  145. #define SA5B_INTR_OFF 0x04
  146. #define SA5_INTR_PENDING 0x08
  147. #define SA5B_INTR_PENDING 0x04
  148. #define FIFO_EMPTY 0xffffffff
  149. #define HPSA_FIRMWARE_READY 0xffff0000 /* value in scratchpad register */
  150. #define HPSA_ERROR_BIT 0x02
  151. #define HPSA_TAG_CONTAINS_INDEX(tag) ((tag) & 0x04)
  152. #define HPSA_TAG_TO_INDEX(tag) ((tag) >> 3)
  153. #define HPSA_TAG_DISCARD_ERROR_BITS(tag) ((tag) & ~3)
  154. #define HPSA_INTR_ON 1
  155. #define HPSA_INTR_OFF 0
  156. /*
  157. Send the command to the hardware
  158. */
  159. static void SA5_submit_command(struct ctlr_info *h,
  160. struct CommandList *c)
  161. {
  162. #ifdef HPSA_DEBUG
  163. printk(KERN_WARNING "hpsa: Sending %x - down to controller\n",
  164. c->busaddr);
  165. #endif /* HPSA_DEBUG */
  166. writel(c->busaddr, h->vaddr + SA5_REQUEST_PORT_OFFSET);
  167. h->commands_outstanding++;
  168. if (h->commands_outstanding > h->max_outstanding)
  169. h->max_outstanding = h->commands_outstanding;
  170. }
  171. /*
  172. * This card is the opposite of the other cards.
  173. * 0 turns interrupts on...
  174. * 0x08 turns them off...
  175. */
  176. static void SA5_intr_mask(struct ctlr_info *h, unsigned long val)
  177. {
  178. if (val) { /* Turn interrupts on */
  179. h->interrupts_enabled = 1;
  180. writel(0, h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  181. } else { /* Turn them off */
  182. h->interrupts_enabled = 0;
  183. writel(SA5_INTR_OFF,
  184. h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  185. }
  186. }
  187. /*
  188. * Returns true if fifo is full.
  189. *
  190. */
  191. static unsigned long SA5_fifo_full(struct ctlr_info *h)
  192. {
  193. if (h->commands_outstanding >= h->max_commands)
  194. return 1;
  195. else
  196. return 0;
  197. }
  198. /*
  199. * returns value read from hardware.
  200. * returns FIFO_EMPTY if there is nothing to read
  201. */
  202. static unsigned long SA5_completed(struct ctlr_info *h)
  203. {
  204. unsigned long register_value
  205. = readl(h->vaddr + SA5_REPLY_PORT_OFFSET);
  206. if (register_value != FIFO_EMPTY)
  207. h->commands_outstanding--;
  208. #ifdef HPSA_DEBUG
  209. if (register_value != FIFO_EMPTY)
  210. printk(KERN_INFO "hpsa: Read %lx back from board\n",
  211. register_value);
  212. else
  213. printk(KERN_INFO "hpsa: FIFO Empty read\n");
  214. #endif
  215. return register_value;
  216. }
  217. /*
  218. * Returns true if an interrupt is pending..
  219. */
  220. static unsigned long SA5_intr_pending(struct ctlr_info *h)
  221. {
  222. unsigned long register_value =
  223. readl(h->vaddr + SA5_INTR_STATUS);
  224. #ifdef HPSA_DEBUG
  225. printk(KERN_INFO "hpsa: intr_pending %lx\n", register_value);
  226. #endif /* HPSA_DEBUG */
  227. if (register_value & SA5_INTR_PENDING)
  228. return 1;
  229. return 0 ;
  230. }
  231. static struct access_method SA5_access = {
  232. SA5_submit_command,
  233. SA5_intr_mask,
  234. SA5_fifo_full,
  235. SA5_intr_pending,
  236. SA5_completed,
  237. };
  238. struct board_type {
  239. __u32 board_id;
  240. char *product_name;
  241. struct access_method *access;
  242. };
  243. /* end of old hpsa_scsi.h file */
  244. #endif /* HPSA_H */