hpsa.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. /*
  2. * Disk Array driver for HP Smart Array SAS controllers
  3. * Copyright 2016 Microsemi Corporation
  4. * Copyright 2014-2015 PMC-Sierra, Inc.
  5. * Copyright 2000,2009-2015 Hewlett-Packard Development Company, L.P.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; version 2 of the License.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  14. * NON INFRINGEMENT. See the GNU General Public License for more details.
  15. *
  16. * Questions/Comments/Bugfixes to esc.storagedev@microsemi.com
  17. *
  18. */
  19. #ifndef HPSA_H
  20. #define HPSA_H
  21. #include <scsi/scsicam.h>
  22. #define IO_OK 0
  23. #define IO_ERROR 1
  24. struct ctlr_info;
  25. struct access_method {
  26. void (*submit_command)(struct ctlr_info *h,
  27. struct CommandList *c);
  28. void (*set_intr_mask)(struct ctlr_info *h, unsigned long val);
  29. bool (*intr_pending)(struct ctlr_info *h);
  30. unsigned long (*command_completed)(struct ctlr_info *h, u8 q);
  31. };
  32. /* for SAS hosts and SAS expanders */
  33. struct hpsa_sas_node {
  34. struct device *parent_dev;
  35. struct list_head port_list_head;
  36. };
  37. struct hpsa_sas_port {
  38. struct list_head port_list_entry;
  39. u64 sas_address;
  40. struct sas_port *port;
  41. int next_phy_index;
  42. struct list_head phy_list_head;
  43. struct hpsa_sas_node *parent_node;
  44. struct sas_rphy *rphy;
  45. };
  46. struct hpsa_sas_phy {
  47. struct list_head phy_list_entry;
  48. struct sas_phy *phy;
  49. struct hpsa_sas_port *parent_port;
  50. bool added_to_port;
  51. };
  52. #define EXTERNAL_QD 7
  53. struct hpsa_scsi_dev_t {
  54. unsigned int devtype;
  55. int bus, target, lun; /* as presented to the OS */
  56. unsigned char scsi3addr[8]; /* as presented to the HW */
  57. u8 physical_device : 1;
  58. u8 expose_device;
  59. u8 removed : 1; /* device is marked for death */
  60. #define RAID_CTLR_LUNID "\0\0\0\0\0\0\0\0"
  61. unsigned char device_id[16]; /* from inquiry pg. 0x83 */
  62. u64 sas_address;
  63. u64 eli; /* from report diags. */
  64. unsigned char vendor[8]; /* bytes 8-15 of inquiry data */
  65. unsigned char model[16]; /* bytes 16-31 of inquiry data */
  66. unsigned char rev; /* byte 2 of inquiry data */
  67. unsigned char raid_level; /* from inquiry page 0xC1 */
  68. unsigned char volume_offline; /* discovered via TUR or VPD */
  69. u16 queue_depth; /* max queue_depth for this device */
  70. atomic_t reset_cmds_out; /* Count of commands to-be affected */
  71. atomic_t ioaccel_cmds_out; /* Only used for physical devices
  72. * counts commands sent to physical
  73. * device via "ioaccel" path.
  74. */
  75. u32 ioaccel_handle;
  76. u8 active_path_index;
  77. u8 path_map;
  78. u8 bay;
  79. u8 box[8];
  80. u16 phys_connector[8];
  81. int offload_config; /* I/O accel RAID offload configured */
  82. int offload_enabled; /* I/O accel RAID offload enabled */
  83. int offload_to_be_enabled;
  84. int hba_ioaccel_enabled;
  85. int offload_to_mirror; /* Send next I/O accelerator RAID
  86. * offload request to mirror drive
  87. */
  88. struct raid_map_data raid_map; /* I/O accelerator RAID map */
  89. /*
  90. * Pointers from logical drive map indices to the phys drives that
  91. * make those logical drives. Note, multiple logical drives may
  92. * share physical drives. You can have for instance 5 physical
  93. * drives with 3 logical drives each using those same 5 physical
  94. * disks. We need these pointers for counting i/o's out to physical
  95. * devices in order to honor physical device queue depth limits.
  96. */
  97. struct hpsa_scsi_dev_t *phys_disk[RAID_MAP_MAX_ENTRIES];
  98. int nphysical_disks;
  99. int supports_aborts;
  100. struct hpsa_sas_port *sas_port;
  101. int external; /* 1-from external array 0-not <0-unknown */
  102. };
  103. struct reply_queue_buffer {
  104. u64 *head;
  105. size_t size;
  106. u8 wraparound;
  107. u32 current_entry;
  108. dma_addr_t busaddr;
  109. };
  110. #pragma pack(1)
  111. struct bmic_controller_parameters {
  112. u8 led_flags;
  113. u8 enable_command_list_verification;
  114. u8 backed_out_write_drives;
  115. u16 stripes_for_parity;
  116. u8 parity_distribution_mode_flags;
  117. u16 max_driver_requests;
  118. u16 elevator_trend_count;
  119. u8 disable_elevator;
  120. u8 force_scan_complete;
  121. u8 scsi_transfer_mode;
  122. u8 force_narrow;
  123. u8 rebuild_priority;
  124. u8 expand_priority;
  125. u8 host_sdb_asic_fix;
  126. u8 pdpi_burst_from_host_disabled;
  127. char software_name[64];
  128. char hardware_name[32];
  129. u8 bridge_revision;
  130. u8 snapshot_priority;
  131. u32 os_specific;
  132. u8 post_prompt_timeout;
  133. u8 automatic_drive_slamming;
  134. u8 reserved1;
  135. u8 nvram_flags;
  136. u8 cache_nvram_flags;
  137. u8 drive_config_flags;
  138. u16 reserved2;
  139. u8 temp_warning_level;
  140. u8 temp_shutdown_level;
  141. u8 temp_condition_reset;
  142. u8 max_coalesce_commands;
  143. u32 max_coalesce_delay;
  144. u8 orca_password[4];
  145. u8 access_id[16];
  146. u8 reserved[356];
  147. };
  148. #pragma pack()
  149. struct ctlr_info {
  150. unsigned int *reply_map;
  151. int ctlr;
  152. char devname[8];
  153. char *product_name;
  154. struct pci_dev *pdev;
  155. u32 board_id;
  156. u64 sas_address;
  157. void __iomem *vaddr;
  158. unsigned long paddr;
  159. int nr_cmds; /* Number of commands allowed on this controller */
  160. #define HPSA_CMDS_RESERVED_FOR_ABORTS 2
  161. #define HPSA_CMDS_RESERVED_FOR_DRIVER 1
  162. struct CfgTable __iomem *cfgtable;
  163. int interrupts_enabled;
  164. int max_commands;
  165. atomic_t commands_outstanding;
  166. # define PERF_MODE_INT 0
  167. # define DOORBELL_INT 1
  168. # define SIMPLE_MODE_INT 2
  169. # define MEMQ_MODE_INT 3
  170. unsigned int msix_vectors;
  171. int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
  172. struct access_method access;
  173. /* queue and queue Info */
  174. unsigned int Qdepth;
  175. unsigned int maxSG;
  176. spinlock_t lock;
  177. int maxsgentries;
  178. u8 max_cmd_sg_entries;
  179. int chainsize;
  180. struct SGDescriptor **cmd_sg_list;
  181. struct ioaccel2_sg_element **ioaccel2_cmd_sg_list;
  182. /* pointers to command and error info pool */
  183. struct CommandList *cmd_pool;
  184. dma_addr_t cmd_pool_dhandle;
  185. struct io_accel1_cmd *ioaccel_cmd_pool;
  186. dma_addr_t ioaccel_cmd_pool_dhandle;
  187. struct io_accel2_cmd *ioaccel2_cmd_pool;
  188. dma_addr_t ioaccel2_cmd_pool_dhandle;
  189. struct ErrorInfo *errinfo_pool;
  190. dma_addr_t errinfo_pool_dhandle;
  191. unsigned long *cmd_pool_bits;
  192. int scan_finished;
  193. u8 scan_waiting : 1;
  194. spinlock_t scan_lock;
  195. wait_queue_head_t scan_wait_queue;
  196. struct Scsi_Host *scsi_host;
  197. spinlock_t devlock; /* to protect hba[ctlr]->dev[]; */
  198. int ndevices; /* number of used elements in .dev[] array. */
  199. struct hpsa_scsi_dev_t *dev[HPSA_MAX_DEVICES];
  200. /*
  201. * Performant mode tables.
  202. */
  203. u32 trans_support;
  204. u32 trans_offset;
  205. struct TransTable_struct __iomem *transtable;
  206. unsigned long transMethod;
  207. /* cap concurrent passthrus at some reasonable maximum */
  208. #define HPSA_MAX_CONCURRENT_PASSTHRUS (10)
  209. atomic_t passthru_cmds_avail;
  210. /*
  211. * Performant mode completion buffers
  212. */
  213. size_t reply_queue_size;
  214. struct reply_queue_buffer reply_queue[MAX_REPLY_QUEUES];
  215. u8 nreply_queues;
  216. u32 *blockFetchTable;
  217. u32 *ioaccel1_blockFetchTable;
  218. u32 *ioaccel2_blockFetchTable;
  219. u32 __iomem *ioaccel2_bft2_regs;
  220. unsigned char *hba_inquiry_data;
  221. u32 driver_support;
  222. u32 fw_support;
  223. int ioaccel_support;
  224. int ioaccel_maxsg;
  225. u64 last_intr_timestamp;
  226. u32 last_heartbeat;
  227. u64 last_heartbeat_timestamp;
  228. u32 heartbeat_sample_interval;
  229. atomic_t firmware_flash_in_progress;
  230. u32 __percpu *lockup_detected;
  231. struct delayed_work monitor_ctlr_work;
  232. struct delayed_work rescan_ctlr_work;
  233. struct delayed_work event_monitor_work;
  234. int remove_in_progress;
  235. /* Address of h->q[x] is passed to intr handler to know which queue */
  236. u8 q[MAX_REPLY_QUEUES];
  237. char intrname[MAX_REPLY_QUEUES][16]; /* "hpsa0-msix00" names */
  238. u32 TMFSupportFlags; /* cache what task mgmt funcs are supported. */
  239. #define HPSATMF_BITS_SUPPORTED (1 << 0)
  240. #define HPSATMF_PHYS_LUN_RESET (1 << 1)
  241. #define HPSATMF_PHYS_NEX_RESET (1 << 2)
  242. #define HPSATMF_PHYS_TASK_ABORT (1 << 3)
  243. #define HPSATMF_PHYS_TSET_ABORT (1 << 4)
  244. #define HPSATMF_PHYS_CLEAR_ACA (1 << 5)
  245. #define HPSATMF_PHYS_CLEAR_TSET (1 << 6)
  246. #define HPSATMF_PHYS_QRY_TASK (1 << 7)
  247. #define HPSATMF_PHYS_QRY_TSET (1 << 8)
  248. #define HPSATMF_PHYS_QRY_ASYNC (1 << 9)
  249. #define HPSATMF_IOACCEL_ENABLED (1 << 15)
  250. #define HPSATMF_MASK_SUPPORTED (1 << 16)
  251. #define HPSATMF_LOG_LUN_RESET (1 << 17)
  252. #define HPSATMF_LOG_NEX_RESET (1 << 18)
  253. #define HPSATMF_LOG_TASK_ABORT (1 << 19)
  254. #define HPSATMF_LOG_TSET_ABORT (1 << 20)
  255. #define HPSATMF_LOG_CLEAR_ACA (1 << 21)
  256. #define HPSATMF_LOG_CLEAR_TSET (1 << 22)
  257. #define HPSATMF_LOG_QRY_TASK (1 << 23)
  258. #define HPSATMF_LOG_QRY_TSET (1 << 24)
  259. #define HPSATMF_LOG_QRY_ASYNC (1 << 25)
  260. u32 events;
  261. #define CTLR_STATE_CHANGE_EVENT (1 << 0)
  262. #define CTLR_ENCLOSURE_HOT_PLUG_EVENT (1 << 1)
  263. #define CTLR_STATE_CHANGE_EVENT_PHYSICAL_DRV (1 << 4)
  264. #define CTLR_STATE_CHANGE_EVENT_LOGICAL_DRV (1 << 5)
  265. #define CTLR_STATE_CHANGE_EVENT_REDUNDANT_CNTRL (1 << 6)
  266. #define CTLR_STATE_CHANGE_EVENT_AIO_ENABLED_DISABLED (1 << 30)
  267. #define CTLR_STATE_CHANGE_EVENT_AIO_CONFIG_CHANGE (1 << 31)
  268. #define RESCAN_REQUIRED_EVENT_BITS \
  269. (CTLR_ENCLOSURE_HOT_PLUG_EVENT | \
  270. CTLR_STATE_CHANGE_EVENT_PHYSICAL_DRV | \
  271. CTLR_STATE_CHANGE_EVENT_LOGICAL_DRV | \
  272. CTLR_STATE_CHANGE_EVENT_AIO_ENABLED_DISABLED | \
  273. CTLR_STATE_CHANGE_EVENT_AIO_CONFIG_CHANGE)
  274. spinlock_t offline_device_lock;
  275. struct list_head offline_device_list;
  276. int acciopath_status;
  277. int drv_req_rescan;
  278. int raid_offload_debug;
  279. int discovery_polling;
  280. int legacy_board;
  281. struct ReportLUNdata *lastlogicals;
  282. int needs_abort_tags_swizzled;
  283. struct workqueue_struct *resubmit_wq;
  284. struct workqueue_struct *rescan_ctlr_wq;
  285. atomic_t abort_cmds_available;
  286. wait_queue_head_t event_sync_wait_queue;
  287. struct mutex reset_mutex;
  288. u8 reset_in_progress;
  289. struct hpsa_sas_node *sas_host;
  290. spinlock_t reset_lock;
  291. };
  292. struct offline_device_entry {
  293. unsigned char scsi3addr[8];
  294. struct list_head offline_list;
  295. };
  296. #define HPSA_ABORT_MSG 0
  297. #define HPSA_DEVICE_RESET_MSG 1
  298. #define HPSA_RESET_TYPE_CONTROLLER 0x00
  299. #define HPSA_RESET_TYPE_BUS 0x01
  300. #define HPSA_RESET_TYPE_LUN 0x04
  301. #define HPSA_PHYS_TARGET_RESET 0x99 /* not defined by cciss spec */
  302. #define HPSA_MSG_SEND_RETRY_LIMIT 10
  303. #define HPSA_MSG_SEND_RETRY_INTERVAL_MSECS (10000)
  304. /* Maximum time in seconds driver will wait for command completions
  305. * when polling before giving up.
  306. */
  307. #define HPSA_MAX_POLL_TIME_SECS (20)
  308. /* During SCSI error recovery, HPSA_TUR_RETRY_LIMIT defines
  309. * how many times to retry TEST UNIT READY on a device
  310. * while waiting for it to become ready before giving up.
  311. * HPSA_MAX_WAIT_INTERVAL_SECS is the max wait interval
  312. * between sending TURs while waiting for a device
  313. * to become ready.
  314. */
  315. #define HPSA_TUR_RETRY_LIMIT (20)
  316. #define HPSA_MAX_WAIT_INTERVAL_SECS (30)
  317. /* HPSA_BOARD_READY_WAIT_SECS is how long to wait for a board
  318. * to become ready, in seconds, before giving up on it.
  319. * HPSA_BOARD_READY_POLL_INTERVAL_MSECS * is how long to wait
  320. * between polling the board to see if it is ready, in
  321. * milliseconds. HPSA_BOARD_READY_POLL_INTERVAL and
  322. * HPSA_BOARD_READY_ITERATIONS are derived from those.
  323. */
  324. #define HPSA_BOARD_READY_WAIT_SECS (120)
  325. #define HPSA_BOARD_NOT_READY_WAIT_SECS (100)
  326. #define HPSA_BOARD_READY_POLL_INTERVAL_MSECS (100)
  327. #define HPSA_BOARD_READY_POLL_INTERVAL \
  328. ((HPSA_BOARD_READY_POLL_INTERVAL_MSECS * HZ) / 1000)
  329. #define HPSA_BOARD_READY_ITERATIONS \
  330. ((HPSA_BOARD_READY_WAIT_SECS * 1000) / \
  331. HPSA_BOARD_READY_POLL_INTERVAL_MSECS)
  332. #define HPSA_BOARD_NOT_READY_ITERATIONS \
  333. ((HPSA_BOARD_NOT_READY_WAIT_SECS * 1000) / \
  334. HPSA_BOARD_READY_POLL_INTERVAL_MSECS)
  335. #define HPSA_POST_RESET_PAUSE_MSECS (3000)
  336. #define HPSA_POST_RESET_NOOP_RETRIES (12)
  337. /* Defining the diffent access_menthods */
  338. /*
  339. * Memory mapped FIFO interface (SMART 53xx cards)
  340. */
  341. #define SA5_DOORBELL 0x20
  342. #define SA5_REQUEST_PORT_OFFSET 0x40
  343. #define SA5_REQUEST_PORT64_LO_OFFSET 0xC0
  344. #define SA5_REQUEST_PORT64_HI_OFFSET 0xC4
  345. #define SA5_REPLY_INTR_MASK_OFFSET 0x34
  346. #define SA5_REPLY_PORT_OFFSET 0x44
  347. #define SA5_INTR_STATUS 0x30
  348. #define SA5_SCRATCHPAD_OFFSET 0xB0
  349. #define SA5_CTCFG_OFFSET 0xB4
  350. #define SA5_CTMEM_OFFSET 0xB8
  351. #define SA5_INTR_OFF 0x08
  352. #define SA5B_INTR_OFF 0x04
  353. #define SA5_INTR_PENDING 0x08
  354. #define SA5B_INTR_PENDING 0x04
  355. #define FIFO_EMPTY 0xffffffff
  356. #define HPSA_FIRMWARE_READY 0xffff0000 /* value in scratchpad register */
  357. #define HPSA_ERROR_BIT 0x02
  358. /* Performant mode flags */
  359. #define SA5_PERF_INTR_PENDING 0x04
  360. #define SA5_PERF_INTR_OFF 0x05
  361. #define SA5_OUTDB_STATUS_PERF_BIT 0x01
  362. #define SA5_OUTDB_CLEAR_PERF_BIT 0x01
  363. #define SA5_OUTDB_CLEAR 0xA0
  364. #define SA5_OUTDB_CLEAR_PERF_BIT 0x01
  365. #define SA5_OUTDB_STATUS 0x9C
  366. #define HPSA_INTR_ON 1
  367. #define HPSA_INTR_OFF 0
  368. /*
  369. * Inbound Post Queue offsets for IO Accelerator Mode 2
  370. */
  371. #define IOACCEL2_INBOUND_POSTQ_32 0x48
  372. #define IOACCEL2_INBOUND_POSTQ_64_LOW 0xd0
  373. #define IOACCEL2_INBOUND_POSTQ_64_HI 0xd4
  374. #define HPSA_PHYSICAL_DEVICE_BUS 0
  375. #define HPSA_RAID_VOLUME_BUS 1
  376. #define HPSA_EXTERNAL_RAID_VOLUME_BUS 2
  377. #define HPSA_HBA_BUS 0
  378. #define HPSA_LEGACY_HBA_BUS 3
  379. /*
  380. Send the command to the hardware
  381. */
  382. static void SA5_submit_command(struct ctlr_info *h,
  383. struct CommandList *c)
  384. {
  385. writel(c->busaddr, h->vaddr + SA5_REQUEST_PORT_OFFSET);
  386. (void) readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
  387. }
  388. static void SA5_submit_command_no_read(struct ctlr_info *h,
  389. struct CommandList *c)
  390. {
  391. writel(c->busaddr, h->vaddr + SA5_REQUEST_PORT_OFFSET);
  392. }
  393. static void SA5_submit_command_ioaccel2(struct ctlr_info *h,
  394. struct CommandList *c)
  395. {
  396. writel(c->busaddr, h->vaddr + SA5_REQUEST_PORT_OFFSET);
  397. }
  398. /*
  399. * This card is the opposite of the other cards.
  400. * 0 turns interrupts on...
  401. * 0x08 turns them off...
  402. */
  403. static void SA5_intr_mask(struct ctlr_info *h, unsigned long val)
  404. {
  405. if (val) { /* Turn interrupts on */
  406. h->interrupts_enabled = 1;
  407. writel(0, h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  408. (void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  409. } else { /* Turn them off */
  410. h->interrupts_enabled = 0;
  411. writel(SA5_INTR_OFF,
  412. h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  413. (void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  414. }
  415. }
  416. /*
  417. * Variant of the above; 0x04 turns interrupts off...
  418. */
  419. static void SA5B_intr_mask(struct ctlr_info *h, unsigned long val)
  420. {
  421. if (val) { /* Turn interrupts on */
  422. h->interrupts_enabled = 1;
  423. writel(0, h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  424. (void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  425. } else { /* Turn them off */
  426. h->interrupts_enabled = 0;
  427. writel(SA5B_INTR_OFF,
  428. h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  429. (void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  430. }
  431. }
  432. static void SA5_performant_intr_mask(struct ctlr_info *h, unsigned long val)
  433. {
  434. if (val) { /* turn on interrupts */
  435. h->interrupts_enabled = 1;
  436. writel(0, h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  437. (void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  438. } else {
  439. h->interrupts_enabled = 0;
  440. writel(SA5_PERF_INTR_OFF,
  441. h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  442. (void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
  443. }
  444. }
  445. static unsigned long SA5_performant_completed(struct ctlr_info *h, u8 q)
  446. {
  447. struct reply_queue_buffer *rq = &h->reply_queue[q];
  448. unsigned long register_value = FIFO_EMPTY;
  449. /* msi auto clears the interrupt pending bit. */
  450. if (unlikely(!(h->pdev->msi_enabled || h->msix_vectors))) {
  451. /* flush the controller write of the reply queue by reading
  452. * outbound doorbell status register.
  453. */
  454. (void) readl(h->vaddr + SA5_OUTDB_STATUS);
  455. writel(SA5_OUTDB_CLEAR_PERF_BIT, h->vaddr + SA5_OUTDB_CLEAR);
  456. /* Do a read in order to flush the write to the controller
  457. * (as per spec.)
  458. */
  459. (void) readl(h->vaddr + SA5_OUTDB_STATUS);
  460. }
  461. if ((((u32) rq->head[rq->current_entry]) & 1) == rq->wraparound) {
  462. register_value = rq->head[rq->current_entry];
  463. rq->current_entry++;
  464. atomic_dec(&h->commands_outstanding);
  465. } else {
  466. register_value = FIFO_EMPTY;
  467. }
  468. /* Check for wraparound */
  469. if (rq->current_entry == h->max_commands) {
  470. rq->current_entry = 0;
  471. rq->wraparound ^= 1;
  472. }
  473. return register_value;
  474. }
  475. /*
  476. * returns value read from hardware.
  477. * returns FIFO_EMPTY if there is nothing to read
  478. */
  479. static unsigned long SA5_completed(struct ctlr_info *h,
  480. __attribute__((unused)) u8 q)
  481. {
  482. unsigned long register_value
  483. = readl(h->vaddr + SA5_REPLY_PORT_OFFSET);
  484. if (register_value != FIFO_EMPTY)
  485. atomic_dec(&h->commands_outstanding);
  486. #ifdef HPSA_DEBUG
  487. if (register_value != FIFO_EMPTY)
  488. dev_dbg(&h->pdev->dev, "Read %lx back from board\n",
  489. register_value);
  490. else
  491. dev_dbg(&h->pdev->dev, "FIFO Empty read\n");
  492. #endif
  493. return register_value;
  494. }
  495. /*
  496. * Returns true if an interrupt is pending..
  497. */
  498. static bool SA5_intr_pending(struct ctlr_info *h)
  499. {
  500. unsigned long register_value =
  501. readl(h->vaddr + SA5_INTR_STATUS);
  502. return register_value & SA5_INTR_PENDING;
  503. }
  504. static bool SA5_performant_intr_pending(struct ctlr_info *h)
  505. {
  506. unsigned long register_value = readl(h->vaddr + SA5_INTR_STATUS);
  507. if (!register_value)
  508. return false;
  509. /* Read outbound doorbell to flush */
  510. register_value = readl(h->vaddr + SA5_OUTDB_STATUS);
  511. return register_value & SA5_OUTDB_STATUS_PERF_BIT;
  512. }
  513. #define SA5_IOACCEL_MODE1_INTR_STATUS_CMP_BIT 0x100
  514. static bool SA5_ioaccel_mode1_intr_pending(struct ctlr_info *h)
  515. {
  516. unsigned long register_value = readl(h->vaddr + SA5_INTR_STATUS);
  517. return (register_value & SA5_IOACCEL_MODE1_INTR_STATUS_CMP_BIT) ?
  518. true : false;
  519. }
  520. /*
  521. * Returns true if an interrupt is pending..
  522. */
  523. static bool SA5B_intr_pending(struct ctlr_info *h)
  524. {
  525. return readl(h->vaddr + SA5_INTR_STATUS) & SA5B_INTR_PENDING;
  526. }
  527. #define IOACCEL_MODE1_REPLY_QUEUE_INDEX 0x1A0
  528. #define IOACCEL_MODE1_PRODUCER_INDEX 0x1B8
  529. #define IOACCEL_MODE1_CONSUMER_INDEX 0x1BC
  530. #define IOACCEL_MODE1_REPLY_UNUSED 0xFFFFFFFFFFFFFFFFULL
  531. static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
  532. {
  533. u64 register_value;
  534. struct reply_queue_buffer *rq = &h->reply_queue[q];
  535. BUG_ON(q >= h->nreply_queues);
  536. register_value = rq->head[rq->current_entry];
  537. if (register_value != IOACCEL_MODE1_REPLY_UNUSED) {
  538. rq->head[rq->current_entry] = IOACCEL_MODE1_REPLY_UNUSED;
  539. if (++rq->current_entry == rq->size)
  540. rq->current_entry = 0;
  541. /*
  542. * @todo
  543. *
  544. * Don't really need to write the new index after each command,
  545. * but with current driver design this is easiest.
  546. */
  547. wmb();
  548. writel((q << 24) | rq->current_entry, h->vaddr +
  549. IOACCEL_MODE1_CONSUMER_INDEX);
  550. atomic_dec(&h->commands_outstanding);
  551. }
  552. return (unsigned long) register_value;
  553. }
  554. static struct access_method SA5_access = {
  555. .submit_command = SA5_submit_command,
  556. .set_intr_mask = SA5_intr_mask,
  557. .intr_pending = SA5_intr_pending,
  558. .command_completed = SA5_completed,
  559. };
  560. /* Duplicate entry of the above to mark unsupported boards */
  561. static struct access_method SA5A_access = {
  562. .submit_command = SA5_submit_command,
  563. .set_intr_mask = SA5_intr_mask,
  564. .intr_pending = SA5_intr_pending,
  565. .command_completed = SA5_completed,
  566. };
  567. static struct access_method SA5B_access = {
  568. .submit_command = SA5_submit_command,
  569. .set_intr_mask = SA5B_intr_mask,
  570. .intr_pending = SA5B_intr_pending,
  571. .command_completed = SA5_completed,
  572. };
  573. static struct access_method SA5_ioaccel_mode1_access = {
  574. .submit_command = SA5_submit_command,
  575. .set_intr_mask = SA5_performant_intr_mask,
  576. .intr_pending = SA5_ioaccel_mode1_intr_pending,
  577. .command_completed = SA5_ioaccel_mode1_completed,
  578. };
  579. static struct access_method SA5_ioaccel_mode2_access = {
  580. .submit_command = SA5_submit_command_ioaccel2,
  581. .set_intr_mask = SA5_performant_intr_mask,
  582. .intr_pending = SA5_performant_intr_pending,
  583. .command_completed = SA5_performant_completed,
  584. };
  585. static struct access_method SA5_performant_access = {
  586. .submit_command = SA5_submit_command,
  587. .set_intr_mask = SA5_performant_intr_mask,
  588. .intr_pending = SA5_performant_intr_pending,
  589. .command_completed = SA5_performant_completed,
  590. };
  591. static struct access_method SA5_performant_access_no_read = {
  592. .submit_command = SA5_submit_command_no_read,
  593. .set_intr_mask = SA5_performant_intr_mask,
  594. .intr_pending = SA5_performant_intr_pending,
  595. .command_completed = SA5_performant_completed,
  596. };
  597. struct board_type {
  598. u32 board_id;
  599. char *product_name;
  600. struct access_method *access;
  601. };
  602. #endif /* HPSA_H */