hpsa.h 18 KB

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