blob: 053be6be20778d6a1879485b4f3ec72e4c208ff5 [file] [log] [blame]
Kevin Barnett6c223762016-06-27 16:41:00 -05001/*
2 * driver for Microsemi PQI-based storage controllers
3 * Copyright (c) 2016 Microsemi Corporation
4 * Copyright (c) 2016 PMC-Sierra, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
13 * NON INFRINGEMENT. See the GNU General Public License for more details.
14 *
15 * Questions/Comments/Bugfixes to esc.storagedev@microsemi.com
16 *
17 */
18
19#if !defined(_SMARTPQI_H)
20#define _SMARTPQI_H
21
22#pragma pack(1)
23
24#define PQI_DEVICE_SIGNATURE "PQI DREG"
25
26/* This structure is defined by the PQI specification. */
27struct pqi_device_registers {
28 __le64 signature;
29 u8 function_and_status_code;
30 u8 reserved[7];
31 u8 max_admin_iq_elements;
32 u8 max_admin_oq_elements;
33 u8 admin_iq_element_length; /* in 16-byte units */
34 u8 admin_oq_element_length; /* in 16-byte units */
35 __le16 max_reset_timeout; /* in 100-millisecond units */
36 u8 reserved1[2];
37 __le32 legacy_intx_status;
38 __le32 legacy_intx_mask_set;
39 __le32 legacy_intx_mask_clear;
40 u8 reserved2[28];
41 __le32 device_status;
42 u8 reserved3[4];
43 __le64 admin_iq_pi_offset;
44 __le64 admin_oq_ci_offset;
45 __le64 admin_iq_element_array_addr;
46 __le64 admin_oq_element_array_addr;
47 __le64 admin_iq_ci_addr;
48 __le64 admin_oq_pi_addr;
49 u8 admin_iq_num_elements;
50 u8 admin_oq_num_elements;
51 __le16 admin_queue_int_msg_num;
52 u8 reserved4[4];
53 __le32 device_error;
54 u8 reserved5[4];
55 __le64 error_details;
56 __le32 device_reset;
57 __le32 power_action;
58 u8 reserved6[104];
59};
60
61/*
62 * controller registers
63 *
64 * These are defined by the PMC implementation.
65 *
66 * Some registers (those named sis_*) are only used when in
67 * legacy SIS mode before we transition the controller into
68 * PQI mode. There are a number of other SIS mode registers,
69 * but we don't use them, so only the SIS registers that we
70 * care about are defined here. The offsets mentioned in the
71 * comments are the offsets from the PCIe BAR 0.
72 */
73struct pqi_ctrl_registers {
74 u8 reserved[0x20];
75 __le32 sis_host_to_ctrl_doorbell; /* 20h */
76 u8 reserved1[0x34 - (0x20 + sizeof(__le32))];
77 __le32 sis_interrupt_mask; /* 34h */
78 u8 reserved2[0x9c - (0x34 + sizeof(__le32))];
79 __le32 sis_ctrl_to_host_doorbell; /* 9Ch */
80 u8 reserved3[0xa0 - (0x9c + sizeof(__le32))];
81 __le32 sis_ctrl_to_host_doorbell_clear; /* A0h */
82 u8 reserved4[0xbc - (0xa0 + sizeof(__le32))];
83 __le32 sis_firmware_status; /* BCh */
84 u8 reserved5[0x1000 - (0xbc + sizeof(__le32))];
85 __le32 sis_mailbox[8]; /* 1000h */
86 u8 reserved6[0x4000 - (0x1000 + (sizeof(__le32) * 8))];
87 /*
88 * The PQI spec states that the PQI registers should be at
89 * offset 0 from the PCIe BAR 0. However, we can't map
90 * them at offset 0 because that would break compatibility
91 * with the SIS registers. So we map them at offset 4000h.
92 */
93 struct pqi_device_registers pqi_registers; /* 4000h */
94};
95
96#define PQI_DEVICE_REGISTERS_OFFSET 0x4000
97
98enum pqi_io_path {
99 RAID_PATH = 0,
100 AIO_PATH = 1
101};
102
103struct pqi_sg_descriptor {
104 __le64 address;
105 __le32 length;
106 __le32 flags;
107};
108
109/* manifest constants for the flags field of pqi_sg_descriptor */
110#define CISS_SG_LAST 0x40000000
111#define CISS_SG_CHAIN 0x80000000
112
113struct pqi_iu_header {
114 u8 iu_type;
115 u8 reserved;
116 __le16 iu_length; /* in bytes - does not include the length */
117 /* of this header */
118 __le16 response_queue_id; /* specifies the OQ where the */
119 /* response IU is to be delivered */
120 u8 work_area[2]; /* reserved for driver use */
121};
122
123/*
124 * According to the PQI spec, the IU header is only the first 4 bytes of our
125 * pqi_iu_header structure.
126 */
127#define PQI_REQUEST_HEADER_LENGTH 4
128
129struct pqi_general_admin_request {
130 struct pqi_iu_header header;
131 __le16 request_id;
132 u8 function_code;
133 union {
134 struct {
135 u8 reserved[33];
136 __le32 buffer_length;
137 struct pqi_sg_descriptor sg_descriptor;
138 } report_device_capability;
139
140 struct {
141 u8 reserved;
142 __le16 queue_id;
143 u8 reserved1[2];
144 __le64 element_array_addr;
145 __le64 ci_addr;
146 __le16 num_elements;
147 __le16 element_length;
148 u8 queue_protocol;
149 u8 reserved2[23];
150 __le32 vendor_specific;
151 } create_operational_iq;
152
153 struct {
154 u8 reserved;
155 __le16 queue_id;
156 u8 reserved1[2];
157 __le64 element_array_addr;
158 __le64 pi_addr;
159 __le16 num_elements;
160 __le16 element_length;
161 u8 queue_protocol;
162 u8 reserved2[3];
163 __le16 int_msg_num;
164 __le16 coalescing_count;
165 __le32 min_coalescing_time;
166 __le32 max_coalescing_time;
167 u8 reserved3[8];
168 __le32 vendor_specific;
169 } create_operational_oq;
170
171 struct {
172 u8 reserved;
173 __le16 queue_id;
174 u8 reserved1[50];
175 } delete_operational_queue;
176
177 struct {
178 u8 reserved;
179 __le16 queue_id;
180 u8 reserved1[46];
181 __le32 vendor_specific;
182 } change_operational_iq_properties;
183
184 } data;
185};
186
187struct pqi_general_admin_response {
188 struct pqi_iu_header header;
189 __le16 request_id;
190 u8 function_code;
191 u8 status;
192 union {
193 struct {
194 u8 status_descriptor[4];
195 __le64 iq_pi_offset;
196 u8 reserved[40];
197 } create_operational_iq;
198
199 struct {
200 u8 status_descriptor[4];
201 __le64 oq_ci_offset;
202 u8 reserved[40];
203 } create_operational_oq;
204 } data;
205};
206
207struct pqi_iu_layer_descriptor {
208 u8 inbound_spanning_supported : 1;
209 u8 reserved : 7;
210 u8 reserved1[5];
211 __le16 max_inbound_iu_length;
212 u8 outbound_spanning_supported : 1;
213 u8 reserved2 : 7;
214 u8 reserved3[5];
215 __le16 max_outbound_iu_length;
216};
217
218struct pqi_device_capability {
219 __le16 data_length;
220 u8 reserved[6];
221 u8 iq_arbitration_priority_support_bitmask;
222 u8 maximum_aw_a;
223 u8 maximum_aw_b;
224 u8 maximum_aw_c;
225 u8 max_arbitration_burst : 3;
226 u8 reserved1 : 4;
227 u8 iqa : 1;
228 u8 reserved2[2];
229 u8 iq_freeze : 1;
230 u8 reserved3 : 7;
231 __le16 max_inbound_queues;
232 __le16 max_elements_per_iq;
233 u8 reserved4[4];
234 __le16 max_iq_element_length;
235 __le16 min_iq_element_length;
236 u8 reserved5[2];
237 __le16 max_outbound_queues;
238 __le16 max_elements_per_oq;
239 __le16 intr_coalescing_time_granularity;
240 __le16 max_oq_element_length;
241 __le16 min_oq_element_length;
242 u8 reserved6[24];
243 struct pqi_iu_layer_descriptor iu_layer_descriptors[32];
244};
245
246#define PQI_MAX_EMBEDDED_SG_DESCRIPTORS 4
247
248struct pqi_raid_path_request {
249 struct pqi_iu_header header;
250 __le16 request_id;
251 __le16 nexus_id;
252 __le32 buffer_length;
253 u8 lun_number[8];
254 __le16 protocol_specific;
255 u8 data_direction : 2;
256 u8 partial : 1;
257 u8 reserved1 : 4;
258 u8 fence : 1;
259 __le16 error_index;
260 u8 reserved2;
261 u8 task_attribute : 3;
262 u8 command_priority : 4;
263 u8 reserved3 : 1;
264 u8 reserved4 : 2;
265 u8 additional_cdb_bytes_usage : 3;
266 u8 reserved5 : 3;
267 u8 cdb[32];
268 struct pqi_sg_descriptor
269 sg_descriptors[PQI_MAX_EMBEDDED_SG_DESCRIPTORS];
270};
271
272struct pqi_aio_path_request {
273 struct pqi_iu_header header;
274 __le16 request_id;
275 u8 reserved1[2];
276 __le32 nexus_id;
277 __le32 buffer_length;
278 u8 data_direction : 2;
279 u8 partial : 1;
280 u8 memory_type : 1;
281 u8 fence : 1;
282 u8 encryption_enable : 1;
283 u8 reserved2 : 2;
284 u8 task_attribute : 3;
285 u8 command_priority : 4;
286 u8 reserved3 : 1;
287 __le16 data_encryption_key_index;
288 __le32 encrypt_tweak_lower;
289 __le32 encrypt_tweak_upper;
290 u8 cdb[16];
291 __le16 error_index;
292 u8 num_sg_descriptors;
293 u8 cdb_length;
294 u8 lun_number[8];
295 u8 reserved4[4];
296 struct pqi_sg_descriptor
297 sg_descriptors[PQI_MAX_EMBEDDED_SG_DESCRIPTORS];
298};
299
300struct pqi_io_response {
301 struct pqi_iu_header header;
302 __le16 request_id;
303 __le16 error_index;
304 u8 reserved2[4];
305};
306
307struct pqi_general_management_request {
308 struct pqi_iu_header header;
309 __le16 request_id;
310 union {
311 struct {
312 u8 reserved[2];
313 __le32 buffer_length;
314 struct pqi_sg_descriptor sg_descriptors[3];
315 } report_event_configuration;
316
317 struct {
318 __le16 global_event_oq_id;
319 __le32 buffer_length;
320 struct pqi_sg_descriptor sg_descriptors[3];
321 } set_event_configuration;
322 } data;
323};
324
325struct pqi_event_descriptor {
326 u8 event_type;
327 u8 reserved;
328 __le16 oq_id;
329};
330
331struct pqi_event_config {
332 u8 reserved[2];
333 u8 num_event_descriptors;
334 u8 reserved1;
335 struct pqi_event_descriptor descriptors[1];
336};
337
338#define PQI_MAX_EVENT_DESCRIPTORS 255
339
340struct pqi_event_response {
341 struct pqi_iu_header header;
342 u8 event_type;
343 u8 reserved2 : 7;
344 u8 request_acknowlege : 1;
345 __le16 event_id;
346 __le32 additional_event_id;
347 u8 data[16];
348};
349
350struct pqi_event_acknowledge_request {
351 struct pqi_iu_header header;
352 u8 event_type;
353 u8 reserved2;
354 __le16 event_id;
355 __le32 additional_event_id;
356};
357
358struct pqi_task_management_request {
359 struct pqi_iu_header header;
360 __le16 request_id;
361 __le16 nexus_id;
362 u8 reserved[4];
363 u8 lun_number[8];
364 __le16 protocol_specific;
365 __le16 outbound_queue_id_to_manage;
366 __le16 request_id_to_manage;
367 u8 task_management_function;
368 u8 reserved2 : 7;
369 u8 fence : 1;
370};
371
372#define SOP_TASK_MANAGEMENT_LUN_RESET 0x8
Kevin Barnett6c223762016-06-27 16:41:00 -0500373
374struct pqi_task_management_response {
375 struct pqi_iu_header header;
376 __le16 request_id;
377 __le16 nexus_id;
378 u8 additional_response_info[3];
379 u8 response_code;
380};
381
382struct pqi_aio_error_info {
383 u8 status;
384 u8 service_response;
385 u8 data_present;
386 u8 reserved;
387 __le32 residual_count;
388 __le16 data_length;
389 __le16 reserved1;
390 u8 data[256];
391};
392
393struct pqi_raid_error_info {
394 u8 data_in_result;
395 u8 data_out_result;
396 u8 reserved[3];
397 u8 status;
398 __le16 status_qualifier;
399 __le16 sense_data_length;
400 __le16 response_data_length;
401 __le32 data_in_transferred;
402 __le32 data_out_transferred;
403 u8 data[256];
404};
405
406#define PQI_REQUEST_IU_TASK_MANAGEMENT 0x13
407#define PQI_REQUEST_IU_RAID_PATH_IO 0x14
408#define PQI_REQUEST_IU_AIO_PATH_IO 0x15
409#define PQI_REQUEST_IU_GENERAL_ADMIN 0x60
410#define PQI_REQUEST_IU_REPORT_VENDOR_EVENT_CONFIG 0x72
411#define PQI_REQUEST_IU_SET_VENDOR_EVENT_CONFIG 0x73
412#define PQI_REQUEST_IU_ACKNOWLEDGE_VENDOR_EVENT 0xf6
413
414#define PQI_RESPONSE_IU_GENERAL_MANAGEMENT 0x81
415#define PQI_RESPONSE_IU_TASK_MANAGEMENT 0x93
416#define PQI_RESPONSE_IU_GENERAL_ADMIN 0xe0
417#define PQI_RESPONSE_IU_RAID_PATH_IO_SUCCESS 0xf0
418#define PQI_RESPONSE_IU_AIO_PATH_IO_SUCCESS 0xf1
419#define PQI_RESPONSE_IU_RAID_PATH_IO_ERROR 0xf2
420#define PQI_RESPONSE_IU_AIO_PATH_IO_ERROR 0xf3
421#define PQI_RESPONSE_IU_AIO_PATH_DISABLED 0xf4
422#define PQI_RESPONSE_IU_VENDOR_EVENT 0xf5
423
424#define PQI_GENERAL_ADMIN_FUNCTION_REPORT_DEVICE_CAPABILITY 0x0
425#define PQI_GENERAL_ADMIN_FUNCTION_CREATE_IQ 0x10
426#define PQI_GENERAL_ADMIN_FUNCTION_CREATE_OQ 0x11
427#define PQI_GENERAL_ADMIN_FUNCTION_DELETE_IQ 0x12
428#define PQI_GENERAL_ADMIN_FUNCTION_DELETE_OQ 0x13
429#define PQI_GENERAL_ADMIN_FUNCTION_CHANGE_IQ_PROPERTY 0x14
430
431#define PQI_GENERAL_ADMIN_STATUS_SUCCESS 0x0
432
433#define PQI_IQ_PROPERTY_IS_AIO_QUEUE 0x1
434
435#define PQI_GENERAL_ADMIN_IU_LENGTH 0x3c
436#define PQI_PROTOCOL_SOP 0x0
437
438#define PQI_DATA_IN_OUT_GOOD 0x0
439#define PQI_DATA_IN_OUT_UNDERFLOW 0x1
440#define PQI_DATA_IN_OUT_BUFFER_ERROR 0x40
441#define PQI_DATA_IN_OUT_BUFFER_OVERFLOW 0x41
442#define PQI_DATA_IN_OUT_BUFFER_OVERFLOW_DESCRIPTOR_AREA 0x42
443#define PQI_DATA_IN_OUT_BUFFER_OVERFLOW_BRIDGE 0x43
444#define PQI_DATA_IN_OUT_PCIE_FABRIC_ERROR 0x60
445#define PQI_DATA_IN_OUT_PCIE_COMPLETION_TIMEOUT 0x61
446#define PQI_DATA_IN_OUT_PCIE_COMPLETER_ABORT_RECEIVED 0x62
447#define PQI_DATA_IN_OUT_PCIE_UNSUPPORTED_REQUEST_RECEIVED 0x63
448#define PQI_DATA_IN_OUT_PCIE_ECRC_CHECK_FAILED 0x64
449#define PQI_DATA_IN_OUT_PCIE_UNSUPPORTED_REQUEST 0x65
450#define PQI_DATA_IN_OUT_PCIE_ACS_VIOLATION 0x66
451#define PQI_DATA_IN_OUT_PCIE_TLP_PREFIX_BLOCKED 0x67
452#define PQI_DATA_IN_OUT_PCIE_POISONED_MEMORY_READ 0x6F
453#define PQI_DATA_IN_OUT_ERROR 0xf0
454#define PQI_DATA_IN_OUT_PROTOCOL_ERROR 0xf1
455#define PQI_DATA_IN_OUT_HARDWARE_ERROR 0xf2
456#define PQI_DATA_IN_OUT_UNSOLICITED_ABORT 0xf3
457#define PQI_DATA_IN_OUT_ABORTED 0xf4
458#define PQI_DATA_IN_OUT_TIMEOUT 0xf5
459
460#define CISS_CMD_STATUS_SUCCESS 0x0
461#define CISS_CMD_STATUS_TARGET_STATUS 0x1
462#define CISS_CMD_STATUS_DATA_UNDERRUN 0x2
463#define CISS_CMD_STATUS_DATA_OVERRUN 0x3
464#define CISS_CMD_STATUS_INVALID 0x4
465#define CISS_CMD_STATUS_PROTOCOL_ERROR 0x5
466#define CISS_CMD_STATUS_HARDWARE_ERROR 0x6
467#define CISS_CMD_STATUS_CONNECTION_LOST 0x7
468#define CISS_CMD_STATUS_ABORTED 0x8
469#define CISS_CMD_STATUS_ABORT_FAILED 0x9
470#define CISS_CMD_STATUS_UNSOLICITED_ABORT 0xa
471#define CISS_CMD_STATUS_TIMEOUT 0xb
472#define CISS_CMD_STATUS_UNABORTABLE 0xc
473#define CISS_CMD_STATUS_TMF 0xd
474#define CISS_CMD_STATUS_AIO_DISABLED 0xe
475
476#define PQI_NUM_EVENT_QUEUE_ELEMENTS 32
477#define PQI_EVENT_OQ_ELEMENT_LENGTH sizeof(struct pqi_event_response)
478
479#define PQI_EVENT_TYPE_HOTPLUG 0x1
480#define PQI_EVENT_TYPE_HARDWARE 0x2
481#define PQI_EVENT_TYPE_PHYSICAL_DEVICE 0x4
482#define PQI_EVENT_TYPE_LOGICAL_DEVICE 0x5
483#define PQI_EVENT_TYPE_AIO_STATE_CHANGE 0xfd
484#define PQI_EVENT_TYPE_AIO_CONFIG_CHANGE 0xfe
485#define PQI_EVENT_TYPE_HEARTBEAT 0xff
486
487#pragma pack()
488
489#define PQI_ERROR_BUFFER_ELEMENT_LENGTH \
490 sizeof(struct pqi_raid_error_info)
491
492/* these values are based on our implementation */
493#define PQI_ADMIN_IQ_NUM_ELEMENTS 8
494#define PQI_ADMIN_OQ_NUM_ELEMENTS 20
495#define PQI_ADMIN_IQ_ELEMENT_LENGTH 64
496#define PQI_ADMIN_OQ_ELEMENT_LENGTH 64
497
498#define PQI_OPERATIONAL_IQ_ELEMENT_LENGTH 128
499#define PQI_OPERATIONAL_OQ_ELEMENT_LENGTH 16
500
501#define PQI_MIN_MSIX_VECTORS 1
502#define PQI_MAX_MSIX_VECTORS 64
503
504/* these values are defined by the PQI spec */
505#define PQI_MAX_NUM_ELEMENTS_ADMIN_QUEUE 255
506#define PQI_MAX_NUM_ELEMENTS_OPERATIONAL_QUEUE 65535
507#define PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT 64
508#define PQI_QUEUE_ELEMENT_LENGTH_ALIGNMENT 16
509#define PQI_ADMIN_INDEX_ALIGNMENT 64
510#define PQI_OPERATIONAL_INDEX_ALIGNMENT 4
511
512#define PQI_MIN_OPERATIONAL_QUEUE_ID 1
513#define PQI_MAX_OPERATIONAL_QUEUE_ID 65535
514
515#define PQI_AIO_SERV_RESPONSE_COMPLETE 0
516#define PQI_AIO_SERV_RESPONSE_FAILURE 1
517#define PQI_AIO_SERV_RESPONSE_TMF_COMPLETE 2
518#define PQI_AIO_SERV_RESPONSE_TMF_SUCCEEDED 3
519#define PQI_AIO_SERV_RESPONSE_TMF_REJECTED 4
520#define PQI_AIO_SERV_RESPONSE_TMF_INCORRECT_LUN 5
521
522#define PQI_AIO_STATUS_IO_ERROR 0x1
523#define PQI_AIO_STATUS_IO_ABORTED 0x2
524#define PQI_AIO_STATUS_NO_PATH_TO_DEVICE 0x3
525#define PQI_AIO_STATUS_INVALID_DEVICE 0x4
526#define PQI_AIO_STATUS_AIO_PATH_DISABLED 0xe
527#define PQI_AIO_STATUS_UNDERRUN 0x51
528#define PQI_AIO_STATUS_OVERRUN 0x75
529
530typedef u32 pqi_index_t;
531
532/* SOP data direction flags */
533#define SOP_NO_DIRECTION_FLAG 0
534#define SOP_WRITE_FLAG 1 /* host writes data to Data-Out */
535 /* buffer */
536#define SOP_READ_FLAG 2 /* host receives data from Data-In */
537 /* buffer */
538#define SOP_BIDIRECTIONAL 3 /* data is transferred from the */
539 /* Data-Out buffer and data is */
540 /* transferred to the Data-In buffer */
541
542#define SOP_TASK_ATTRIBUTE_SIMPLE 0
543#define SOP_TASK_ATTRIBUTE_HEAD_OF_QUEUE 1
544#define SOP_TASK_ATTRIBUTE_ORDERED 2
545#define SOP_TASK_ATTRIBUTE_ACA 4
546
Kevin Barnettb17f0482016-08-31 14:54:17 -0500547#define SOP_TMF_COMPLETE 0x0
548#define SOP_TMF_FUNCTION_SUCCEEDED 0x8
Kevin Barnett6c223762016-06-27 16:41:00 -0500549
550/* additional CDB bytes usage field codes */
551#define SOP_ADDITIONAL_CDB_BYTES_0 0 /* 16-byte CDB */
552#define SOP_ADDITIONAL_CDB_BYTES_4 1 /* 20-byte CDB */
553#define SOP_ADDITIONAL_CDB_BYTES_8 2 /* 24-byte CDB */
554#define SOP_ADDITIONAL_CDB_BYTES_12 3 /* 28-byte CDB */
555#define SOP_ADDITIONAL_CDB_BYTES_16 4 /* 32-byte CDB */
556
557/*
558 * The purpose of this structure is to obtain proper alignment of objects in
559 * an admin queue pair.
560 */
561struct pqi_admin_queues_aligned {
562 __aligned(PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT)
563 u8 iq_element_array[PQI_ADMIN_IQ_ELEMENT_LENGTH]
564 [PQI_ADMIN_IQ_NUM_ELEMENTS];
565 __aligned(PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT)
566 u8 oq_element_array[PQI_ADMIN_OQ_ELEMENT_LENGTH]
567 [PQI_ADMIN_OQ_NUM_ELEMENTS];
568 __aligned(PQI_ADMIN_INDEX_ALIGNMENT) pqi_index_t iq_ci;
569 __aligned(PQI_ADMIN_INDEX_ALIGNMENT) pqi_index_t oq_pi;
570};
571
572struct pqi_admin_queues {
573 void *iq_element_array;
574 void *oq_element_array;
575 volatile pqi_index_t *iq_ci;
576 volatile pqi_index_t *oq_pi;
577 dma_addr_t iq_element_array_bus_addr;
578 dma_addr_t oq_element_array_bus_addr;
579 dma_addr_t iq_ci_bus_addr;
580 dma_addr_t oq_pi_bus_addr;
581 __le32 __iomem *iq_pi;
582 pqi_index_t iq_pi_copy;
583 __le32 __iomem *oq_ci;
584 pqi_index_t oq_ci_copy;
585 struct task_struct *task;
586 u16 int_msg_num;
587};
588
589struct pqi_queue_group {
590 struct pqi_ctrl_info *ctrl_info; /* backpointer */
591 u16 iq_id[2];
592 u16 oq_id;
593 u16 int_msg_num;
594 void *iq_element_array[2];
595 void *oq_element_array;
596 dma_addr_t iq_element_array_bus_addr[2];
597 dma_addr_t oq_element_array_bus_addr;
598 __le32 __iomem *iq_pi[2];
599 pqi_index_t iq_pi_copy[2];
600 volatile pqi_index_t *iq_ci[2];
601 volatile pqi_index_t *oq_pi;
602 dma_addr_t iq_ci_bus_addr[2];
603 dma_addr_t oq_pi_bus_addr;
604 __le32 __iomem *oq_ci;
605 pqi_index_t oq_ci_copy;
606 spinlock_t submit_lock[2]; /* protect submission queue */
607 struct list_head request_list[2];
608};
609
610struct pqi_event_queue {
611 u16 oq_id;
612 u16 int_msg_num;
613 void *oq_element_array;
614 volatile pqi_index_t *oq_pi;
615 dma_addr_t oq_element_array_bus_addr;
616 dma_addr_t oq_pi_bus_addr;
617 __le32 __iomem *oq_ci;
618 pqi_index_t oq_ci_copy;
619};
620
621#define PQI_DEFAULT_QUEUE_GROUP 0
622#define PQI_MAX_QUEUE_GROUPS PQI_MAX_MSIX_VECTORS
623
624struct pqi_encryption_info {
625 u16 data_encryption_key_index;
626 u32 encrypt_tweak_lower;
627 u32 encrypt_tweak_upper;
628};
629
630#define PQI_MAX_OUTSTANDING_REQUESTS ((u32)~0)
631#define PQI_MAX_TRANSFER_SIZE (4 * 1024U * 1024U)
632
633#define RAID_MAP_MAX_ENTRIES 1024
634
635#define PQI_RESERVED_IO_SLOTS_LUN_RESET 1
636#define PQI_RESERVED_IO_SLOTS_EVENT_ACK 1
637#define PQI_RESERVED_IO_SLOTS_SYNCHRONOUS_REQUESTS 3
638#define PQI_RESERVED_IO_SLOTS \
639 (PQI_RESERVED_IO_SLOTS_LUN_RESET + PQI_RESERVED_IO_SLOTS_EVENT_ACK + \
640 PQI_RESERVED_IO_SLOTS_SYNCHRONOUS_REQUESTS)
641
642#define PQI_PHYSICAL_DEVICE_BUS 0
643#define PQI_RAID_VOLUME_BUS 1
644#define PQI_HBA_BUS 2
645#define PQI_MAX_BUS PQI_HBA_BUS
646
647#pragma pack(1)
648
649struct report_lun_header {
650 __be32 list_length;
651 u8 extended_response;
652 u8 reserved[3];
653};
654
655struct report_log_lun_extended_entry {
656 u8 lunid[8];
657 u8 volume_id[16];
658};
659
660struct report_log_lun_extended {
661 struct report_lun_header header;
662 struct report_log_lun_extended_entry lun_entries[1];
663};
664
665struct report_phys_lun_extended_entry {
666 u8 lunid[8];
667 __be64 wwid;
668 u8 device_type;
669 u8 device_flags;
670 u8 lun_count; /* number of LUNs in a multi-LUN device */
671 u8 redundant_paths;
672 u32 aio_handle;
673};
674
675/* for device_flags field of struct report_phys_lun_extended_entry */
676#define REPORT_PHYS_LUN_DEV_FLAG_NON_DISK 0x1
677#define REPORT_PHYS_LUN_DEV_FLAG_AIO_ENABLED 0x8
678
679struct report_phys_lun_extended {
680 struct report_lun_header header;
681 struct report_phys_lun_extended_entry lun_entries[1];
682};
683
684struct raid_map_disk_data {
685 u32 aio_handle;
686 u8 xor_mult[2];
687 u8 reserved[2];
688};
689
690/* constants for flags field of RAID map */
691#define RAID_MAP_ENCRYPTION_ENABLED 0x1
692
693struct raid_map {
694 __le32 structure_size; /* size of entire structure in bytes */
695 __le32 volume_blk_size; /* bytes / block in the volume */
696 __le64 volume_blk_cnt; /* logical blocks on the volume */
697 u8 phys_blk_shift; /* shift factor to convert between */
698 /* units of logical blocks and */
699 /* physical disk blocks */
700 u8 parity_rotation_shift; /* shift factor to convert between */
701 /* units of logical stripes and */
702 /* physical stripes */
703 __le16 strip_size; /* blocks used on each disk / stripe */
704 __le64 disk_starting_blk; /* first disk block used in volume */
705 __le64 disk_blk_cnt; /* disk blocks used by volume / disk */
706 __le16 data_disks_per_row; /* data disk entries / row in the map */
707 __le16 metadata_disks_per_row; /* mirror/parity disk entries / row */
708 /* in the map */
709 __le16 row_cnt; /* rows in each layout map */
710 __le16 layout_map_count; /* layout maps (1 map per */
711 /* mirror parity group) */
712 __le16 flags;
713 __le16 data_encryption_key_index;
714 u8 reserved[16];
715 struct raid_map_disk_data disk_data[RAID_MAP_MAX_ENTRIES];
716};
717
718#pragma pack()
719
720#define RAID_CTLR_LUNID "\0\0\0\0\0\0\0\0"
721
722struct pqi_scsi_dev {
723 int devtype; /* as reported by INQUIRY commmand */
724 u8 device_type; /* as reported by */
725 /* BMIC_IDENTIFY_PHYSICAL_DEVICE */
726 /* only valid for devtype = TYPE_DISK */
727 int bus;
728 int target;
729 int lun;
730 u8 scsi3addr[8];
731 __be64 wwid;
732 u8 volume_id[16];
733 u8 is_physical_device : 1;
734 u8 target_lun_valid : 1;
735 u8 expose_device : 1;
736 u8 no_uld_attach : 1;
737 u8 aio_enabled : 1; /* only valid for physical disks */
738 u8 device_gone : 1;
739 u8 new_device : 1;
740 u8 keep_device : 1;
741 u8 volume_offline : 1;
742 u8 vendor[8]; /* bytes 8-15 of inquiry data */
743 u8 model[16]; /* bytes 16-31 of inquiry data */
744 u64 sas_address;
745 u8 raid_level;
746 u16 queue_depth; /* max. queue_depth for this device */
747 u16 advertised_queue_depth;
748 u32 aio_handle;
749 u8 volume_status;
750 u8 active_path_index;
751 u8 path_map;
752 u8 bay;
753 u8 box[8];
754 u16 phys_connector[8];
755 int offload_configured; /* I/O accel RAID offload configured */
756 int offload_enabled; /* I/O accel RAID offload enabled */
757 int offload_enabled_pending;
758 int offload_to_mirror; /* Send next I/O accelerator RAID */
759 /* offload request to mirror drive. */
760 struct raid_map *raid_map; /* I/O accelerator RAID map */
761
762 struct pqi_sas_port *sas_port;
763 struct scsi_device *sdev;
Kevin Barnett6c223762016-06-27 16:41:00 -0500764
765 struct list_head scsi_device_list_entry;
766 struct list_head new_device_list_entry;
767 struct list_head add_list_entry;
768 struct list_head delete_list_entry;
769};
770
771/* VPD inquiry pages */
772#define SCSI_VPD_SUPPORTED_PAGES 0x0 /* standard page */
773#define SCSI_VPD_DEVICE_ID 0x83 /* standard page */
774#define CISS_VPD_LV_DEVICE_GEOMETRY 0xc1 /* vendor-specific page */
775#define CISS_VPD_LV_OFFLOAD_STATUS 0xc2 /* vendor-specific page */
776#define CISS_VPD_LV_STATUS 0xc3 /* vendor-specific page */
777
778#define VPD_PAGE (1 << 8)
779
780#pragma pack(1)
781
782/* structure for CISS_VPD_LV_STATUS */
783struct ciss_vpd_logical_volume_status {
784 u8 peripheral_info;
785 u8 page_code;
786 u8 reserved;
787 u8 page_length;
788 u8 volume_status;
789 u8 reserved2[3];
790 __be32 flags;
791};
792
793#pragma pack()
794
795/* constants for volume_status field of ciss_vpd_logical_volume_status */
796#define CISS_LV_OK 0
797#define CISS_LV_FAILED 1
798#define CISS_LV_NOT_CONFIGURED 2
799#define CISS_LV_DEGRADED 3
800#define CISS_LV_READY_FOR_RECOVERY 4
801#define CISS_LV_UNDERGOING_RECOVERY 5
802#define CISS_LV_WRONG_PHYSICAL_DRIVE_REPLACED 6
803#define CISS_LV_PHYSICAL_DRIVE_CONNECTION_PROBLEM 7
804#define CISS_LV_HARDWARE_OVERHEATING 8
805#define CISS_LV_HARDWARE_HAS_OVERHEATED 9
806#define CISS_LV_UNDERGOING_EXPANSION 10
807#define CISS_LV_NOT_AVAILABLE 11
808#define CISS_LV_QUEUED_FOR_EXPANSION 12
809#define CISS_LV_DISABLED_SCSI_ID_CONFLICT 13
810#define CISS_LV_EJECTED 14
811#define CISS_LV_UNDERGOING_ERASE 15
812/* state 16 not used */
813#define CISS_LV_READY_FOR_PREDICTIVE_SPARE_REBUILD 17
814#define CISS_LV_UNDERGOING_RPI 18
815#define CISS_LV_PENDING_RPI 19
816#define CISS_LV_ENCRYPTED_NO_KEY 20
817/* state 21 not used */
818#define CISS_LV_UNDERGOING_ENCRYPTION 22
819#define CISS_LV_UNDERGOING_ENCRYPTION_REKEYING 23
820#define CISS_LV_ENCRYPTED_IN_NON_ENCRYPTED_CONTROLLER 24
821#define CISS_LV_PENDING_ENCRYPTION 25
822#define CISS_LV_PENDING_ENCRYPTION_REKEYING 26
823#define CISS_LV_NOT_SUPPORTED 27
824#define CISS_LV_STATUS_UNAVAILABLE 255
825
826/* constants for flags field of ciss_vpd_logical_volume_status */
827#define CISS_LV_FLAGS_NO_HOST_IO 0x1 /* volume not available for */
828 /* host I/O */
829
830/* for SAS hosts and SAS expanders */
831struct pqi_sas_node {
832 struct device *parent_dev;
833 struct list_head port_list_head;
834};
835
836struct pqi_sas_port {
837 struct list_head port_list_entry;
838 u64 sas_address;
839 struct sas_port *port;
840 int next_phy_index;
841 struct list_head phy_list_head;
842 struct pqi_sas_node *parent_node;
843 struct sas_rphy *rphy;
844};
845
846struct pqi_sas_phy {
847 struct list_head phy_list_entry;
848 struct sas_phy *phy;
849 struct pqi_sas_port *parent_port;
850 bool added_to_port;
851};
852
853struct pqi_io_request {
854 atomic_t refcount;
855 u16 index;
856 void (*io_complete_callback)(struct pqi_io_request *io_request,
857 void *context);
858 void *context;
859 int status;
860 struct scsi_cmnd *scmd;
861 void *error_info;
862 struct pqi_sg_descriptor *sg_chain_buffer;
863 dma_addr_t sg_chain_buffer_dma_handle;
864 void *iu;
865 struct list_head request_list_entry;
866};
867
868/* for indexing into the pending_events[] field of struct pqi_ctrl_info */
869#define PQI_EVENT_HEARTBEAT 0
870#define PQI_EVENT_HOTPLUG 1
871#define PQI_EVENT_HARDWARE 2
872#define PQI_EVENT_PHYSICAL_DEVICE 3
873#define PQI_EVENT_LOGICAL_DEVICE 4
874#define PQI_EVENT_AIO_STATE_CHANGE 5
875#define PQI_EVENT_AIO_CONFIG_CHANGE 6
876#define PQI_NUM_SUPPORTED_EVENTS 7
877
878struct pqi_event {
879 bool pending;
880 u8 event_type;
881 __le16 event_id;
882 __le32 additional_event_id;
883};
884
885struct pqi_ctrl_info {
886 unsigned int ctrl_id;
887 struct pci_dev *pci_dev;
888 char firmware_version[11];
889 void __iomem *iomem_base;
890 struct pqi_ctrl_registers __iomem *registers;
891 struct pqi_device_registers __iomem *pqi_registers;
892 u32 max_sg_entries;
893 u32 config_table_offset;
894 u32 config_table_length;
895 u16 max_inbound_queues;
896 u16 max_elements_per_iq;
897 u16 max_iq_element_length;
898 u16 max_outbound_queues;
899 u16 max_elements_per_oq;
900 u16 max_oq_element_length;
901 u32 max_transfer_size;
902 u32 max_outstanding_requests;
903 u32 max_io_slots;
904 unsigned int scsi_ml_can_queue;
905 unsigned short sg_tablesize;
906 unsigned int max_sectors;
907 u32 error_buffer_length;
908 void *error_buffer;
909 dma_addr_t error_buffer_dma_handle;
910 size_t sg_chain_buffer_length;
911 unsigned int num_queue_groups;
912 unsigned int num_active_queue_groups;
913 u16 num_elements_per_iq;
914 u16 num_elements_per_oq;
915 u16 max_inbound_iu_length_per_firmware;
916 u16 max_inbound_iu_length;
917 unsigned int max_sg_per_iu;
918 void *admin_queue_memory_base;
919 u32 admin_queue_memory_length;
920 dma_addr_t admin_queue_memory_base_dma_handle;
921 void *queue_memory_base;
922 u32 queue_memory_length;
923 dma_addr_t queue_memory_base_dma_handle;
924 struct pqi_admin_queues admin_queues;
925 struct pqi_queue_group queue_groups[PQI_MAX_QUEUE_GROUPS];
926 struct pqi_event_queue event_queue;
927 int max_msix_vectors;
928 int num_msix_vectors_enabled;
929 int num_msix_vectors_initialized;
930 u32 msix_vectors[PQI_MAX_MSIX_VECTORS];
931 void *intr_data[PQI_MAX_MSIX_VECTORS];
932 int event_irq;
933 struct Scsi_Host *scsi_host;
934
935 struct mutex scan_mutex;
936 u8 inbound_spanning_supported : 1;
937 u8 outbound_spanning_supported : 1;
938 u8 pqi_mode_enabled : 1;
939 u8 controller_online : 1;
940 u8 heartbeat_timer_started : 1;
941
942 struct list_head scsi_device_list;
943 spinlock_t scsi_device_list_lock;
944
945 struct delayed_work rescan_work;
946 struct delayed_work update_time_work;
947
948 struct pqi_sas_node *sas_host;
949 u64 sas_address;
950
951 struct pqi_io_request *io_request_pool;
952 u16 next_io_request_slot;
953
954 struct pqi_event pending_events[PQI_NUM_SUPPORTED_EVENTS];
955 struct work_struct event_work;
956
957 atomic_t num_interrupts;
958 int previous_num_interrupts;
959 unsigned int num_heartbeats_requested;
960 struct timer_list heartbeat_timer;
961
962 struct semaphore sync_request_sem;
963 struct semaphore lun_reset_sem;
964};
965
966/*
967 * assume worst case: SATA queue depth of 31 minus 4 internal firmware commands
968 */
969#define PQI_PHYSICAL_DISK_DEFAULT_MAX_QUEUE_DEPTH 27
970
971/* 0 = no limit */
972#define PQI_LOGICAL_DRIVE_DEFAULT_MAX_QUEUE_DEPTH 0
973
974/* CISS commands */
975#define CISS_READ 0xc0
976#define CISS_REPORT_LOG 0xc2 /* Report Logical LUNs */
977#define CISS_REPORT_PHYS 0xc3 /* Report Physical LUNs */
978#define CISS_GET_RAID_MAP 0xc8
979
980/* constants for CISS_REPORT_LOG/CISS_REPORT_PHYS commands */
981#define CISS_REPORT_LOG_EXTENDED 0x1
982#define CISS_REPORT_PHYS_EXTENDED 0x2
983
984/* BMIC commands */
985#define BMIC_IDENTIFY_CONTROLLER 0x11
986#define BMIC_IDENTIFY_PHYSICAL_DEVICE 0x15
987#define BMIC_READ 0x26
988#define BMIC_WRITE 0x27
989#define BMIC_SENSE_CONTROLLER_PARAMETERS 0x64
990#define BMIC_SENSE_SUBSYSTEM_INFORMATION 0x66
991#define BMIC_WRITE_HOST_WELLNESS 0xa5
992#define BMIC_CACHE_FLUSH 0xc2
993
994#define SA_CACHE_FLUSH 0x01
995
996#define MASKED_DEVICE(lunid) ((lunid)[3] & 0xc0)
997#define CISS_GET_BUS(lunid) ((lunid)[7] & 0x3f)
998#define CISS_GET_LEVEL_2_TARGET(lunid) ((lunid)[6])
999#define CISS_GET_DRIVE_NUMBER(lunid) \
1000 (((CISS_GET_BUS((lunid)) - 1) << 8) + \
1001 CISS_GET_LEVEL_2_TARGET((lunid)))
1002
1003#define NO_TIMEOUT ((unsigned long) -1)
1004
1005#pragma pack(1)
1006
1007struct bmic_identify_controller {
1008 u8 configured_logical_drive_count;
1009 __le32 configuration_signature;
1010 u8 firmware_version[4];
1011 u8 reserved[145];
1012 __le16 extended_logical_unit_count;
1013 u8 reserved1[34];
1014 __le16 firmware_build_number;
1015 u8 reserved2[100];
1016 u8 controller_mode;
1017 u8 reserved3[32];
1018};
1019
1020struct bmic_identify_physical_device {
1021 u8 scsi_bus; /* SCSI Bus number on controller */
1022 u8 scsi_id; /* SCSI ID on this bus */
1023 __le16 block_size; /* sector size in bytes */
1024 __le32 total_blocks; /* number for sectors on drive */
1025 __le32 reserved_blocks; /* controller reserved (RIS) */
1026 u8 model[40]; /* Physical Drive Model */
1027 u8 serial_number[40]; /* Drive Serial Number */
1028 u8 firmware_revision[8]; /* drive firmware revision */
1029 u8 scsi_inquiry_bits; /* inquiry byte 7 bits */
1030 u8 compaq_drive_stamp; /* 0 means drive not stamped */
1031 u8 last_failure_reason;
1032 u8 flags;
1033 u8 more_flags;
1034 u8 scsi_lun; /* SCSI LUN for phys drive */
1035 u8 yet_more_flags;
1036 u8 even_more_flags;
1037 __le32 spi_speed_rules;
1038 u8 phys_connector[2]; /* connector number on controller */
1039 u8 phys_box_on_bus; /* phys enclosure this drive resides */
1040 u8 phys_bay_in_box; /* phys drv bay this drive resides */
1041 __le32 rpm; /* drive rotational speed in RPM */
1042 u8 device_type; /* type of drive */
1043 u8 sata_version; /* only valid when device_type = */
1044 /* BMIC_DEVICE_TYPE_SATA */
1045 __le64 big_total_block_count;
1046 __le64 ris_starting_lba;
1047 __le32 ris_size;
1048 u8 wwid[20];
1049 u8 controller_phy_map[32];
1050 __le16 phy_count;
1051 u8 phy_connected_dev_type[256];
1052 u8 phy_to_drive_bay_num[256];
1053 __le16 phy_to_attached_dev_index[256];
1054 u8 box_index;
1055 u8 reserved;
1056 __le16 extra_physical_drive_flags;
1057 u8 negotiated_link_rate[256];
1058 u8 phy_to_phy_map[256];
1059 u8 redundant_path_present_map;
1060 u8 redundant_path_failure_map;
1061 u8 active_path_number;
1062 __le16 alternate_paths_phys_connector[8];
1063 u8 alternate_paths_phys_box_on_port[8];
1064 u8 multi_lun_device_lun_count;
1065 u8 minimum_good_fw_revision[8];
1066 u8 unique_inquiry_bytes[20];
1067 u8 current_temperature_degreesC;
1068 u8 temperature_threshold_degreesC;
1069 u8 max_temperature_degreesC;
1070 u8 logical_blocks_per_phys_block_exp;
1071 __le16 current_queue_depth_limit;
1072 u8 switch_name[10];
1073 __le16 switch_port;
1074 u8 alternate_paths_switch_name[40];
1075 u8 alternate_paths_switch_port[8];
1076 __le16 power_on_hours;
1077 __le16 percent_endurance_used;
1078 u8 drive_authentication;
1079 u8 smart_carrier_authentication;
1080 u8 smart_carrier_app_fw_version;
1081 u8 smart_carrier_bootloader_fw_version;
1082 u8 encryption_key_name[64];
1083 __le32 misc_drive_flags;
1084 __le16 dek_index;
1085 u8 padding[112];
1086};
1087
1088#pragma pack()
1089
1090int pqi_add_sas_host(struct Scsi_Host *shost, struct pqi_ctrl_info *ctrl_info);
1091void pqi_delete_sas_host(struct pqi_ctrl_info *ctrl_info);
1092int pqi_add_sas_device(struct pqi_sas_node *pqi_sas_node,
1093 struct pqi_scsi_dev *device);
1094void pqi_remove_sas_device(struct pqi_scsi_dev *device);
1095struct pqi_scsi_dev *pqi_find_device_by_sas_rphy(
1096 struct pqi_ctrl_info *ctrl_info, struct sas_rphy *rphy);
1097
1098extern struct sas_function_template pqi_sas_transport_functions;
1099
1100#if !defined(readq)
1101#define readq readq
1102static inline u64 readq(const volatile void __iomem *addr)
1103{
1104 u32 lower32;
1105 u32 upper32;
1106
1107 lower32 = readl(addr);
1108 upper32 = readl(addr + 4);
1109
1110 return ((u64)upper32 << 32) | lower32;
1111}
1112#endif
1113
1114#if !defined(writeq)
1115#define writeq writeq
1116static inline void writeq(u64 value, volatile void __iomem *addr)
1117{
1118 u32 lower32;
1119 u32 upper32;
1120
1121 lower32 = lower_32_bits(value);
1122 upper32 = upper_32_bits(value);
1123
1124 writel(lower32, addr);
1125 writel(upper32, addr + 4);
1126}
1127#endif
1128
1129#endif /* _SMARTPQI_H */