2 * driver for Microsemi PQI-based storage controllers
3 * Copyright (c) 2016-2017 Microsemi Corporation
4 * Copyright (c) 2016 PMC-Sierra, Inc.
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.
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.
15 * Questions/Comments/Bugfixes to esc.storagedev@microsemi.com
19 #include <linux/module.h>
20 #include <linux/kernel.h>
21 #include <linux/pci.h>
22 #include <linux/delay.h>
23 #include <linux/interrupt.h>
24 #include <linux/sched.h>
25 #include <linux/rtc.h>
26 #include <linux/bcd.h>
27 #include <linux/reboot.h>
28 #include <linux/cciss_ioctl.h>
29 #include <linux/blk-mq-pci.h>
30 #include <scsi/scsi_host.h>
31 #include <scsi/scsi_cmnd.h>
32 #include <scsi/scsi_device.h>
33 #include <scsi/scsi_eh.h>
34 #include <scsi/scsi_transport_sas.h>
35 #include <asm/unaligned.h>
37 #include "smartpqi_sis.h"
39 #if !defined(BUILD_TIMESTAMP)
40 #define BUILD_TIMESTAMP
43 #define DRIVER_VERSION "1.2.4-070"
44 #define DRIVER_MAJOR 1
45 #define DRIVER_MINOR 2
46 #define DRIVER_RELEASE 4
47 #define DRIVER_REVISION 70
49 #define DRIVER_NAME "Microsemi PQI Driver (v" \
50 DRIVER_VERSION BUILD_TIMESTAMP ")"
51 #define DRIVER_NAME_SHORT "smartpqi"
53 #define PQI_EXTRA_SGL_MEMORY (12 * sizeof(struct pqi_sg_descriptor))
55 MODULE_AUTHOR("Microsemi");
56 MODULE_DESCRIPTION("Driver for Microsemi Smart Family Controller version "
58 MODULE_SUPPORTED_DEVICE("Microsemi Smart Family Controllers");
59 MODULE_VERSION(DRIVER_VERSION
);
60 MODULE_LICENSE("GPL");
62 static void pqi_take_ctrl_offline(struct pqi_ctrl_info
*ctrl_info
);
63 static void pqi_ctrl_offline_worker(struct work_struct
*work
);
64 static void pqi_retry_raid_bypass_requests(struct pqi_ctrl_info
*ctrl_info
);
65 static int pqi_scan_scsi_devices(struct pqi_ctrl_info
*ctrl_info
);
66 static void pqi_scan_start(struct Scsi_Host
*shost
);
67 static void pqi_start_io(struct pqi_ctrl_info
*ctrl_info
,
68 struct pqi_queue_group
*queue_group
, enum pqi_io_path path
,
69 struct pqi_io_request
*io_request
);
70 static int pqi_submit_raid_request_synchronous(struct pqi_ctrl_info
*ctrl_info
,
71 struct pqi_iu_header
*request
, unsigned int flags
,
72 struct pqi_raid_error_info
*error_info
, unsigned long timeout_msecs
);
73 static int pqi_aio_submit_io(struct pqi_ctrl_info
*ctrl_info
,
74 struct scsi_cmnd
*scmd
, u32 aio_handle
, u8
*cdb
,
75 unsigned int cdb_length
, struct pqi_queue_group
*queue_group
,
76 struct pqi_encryption_info
*encryption_info
, bool raid_bypass
);
77 static void pqi_ofa_ctrl_quiesce(struct pqi_ctrl_info
*ctrl_info
);
78 static void pqi_ofa_ctrl_unquiesce(struct pqi_ctrl_info
*ctrl_info
);
79 static int pqi_ofa_ctrl_restart(struct pqi_ctrl_info
*ctrl_info
);
80 static void pqi_ofa_setup_host_buffer(struct pqi_ctrl_info
*ctrl_info
,
82 static void pqi_ofa_free_host_buffer(struct pqi_ctrl_info
*ctrl_info
);
83 static int pqi_ofa_host_memory_update(struct pqi_ctrl_info
*ctrl_info
);
84 static int pqi_device_wait_for_pending_io(struct pqi_ctrl_info
*ctrl_info
,
85 struct pqi_scsi_dev
*device
, unsigned long timeout_secs
);
87 /* for flags argument to pqi_submit_raid_request_synchronous() */
88 #define PQI_SYNC_FLAGS_INTERRUPTABLE 0x1
90 static struct scsi_transport_template
*pqi_sas_transport_template
;
92 static atomic_t pqi_controller_count
= ATOMIC_INIT(0);
94 enum pqi_lockup_action
{
100 static enum pqi_lockup_action pqi_lockup_action
= NONE
;
103 enum pqi_lockup_action action
;
105 } pqi_lockup_actions
[] = {
120 static unsigned int pqi_supported_event_types
[] = {
121 PQI_EVENT_TYPE_HOTPLUG
,
122 PQI_EVENT_TYPE_HARDWARE
,
123 PQI_EVENT_TYPE_PHYSICAL_DEVICE
,
124 PQI_EVENT_TYPE_LOGICAL_DEVICE
,
126 PQI_EVENT_TYPE_AIO_STATE_CHANGE
,
127 PQI_EVENT_TYPE_AIO_CONFIG_CHANGE
,
130 static int pqi_disable_device_id_wildcards
;
131 module_param_named(disable_device_id_wildcards
,
132 pqi_disable_device_id_wildcards
, int, 0644);
133 MODULE_PARM_DESC(disable_device_id_wildcards
,
134 "Disable device ID wildcards.");
136 static int pqi_disable_heartbeat
;
137 module_param_named(disable_heartbeat
,
138 pqi_disable_heartbeat
, int, 0644);
139 MODULE_PARM_DESC(disable_heartbeat
,
140 "Disable heartbeat.");
142 static int pqi_disable_ctrl_shutdown
;
143 module_param_named(disable_ctrl_shutdown
,
144 pqi_disable_ctrl_shutdown
, int, 0644);
145 MODULE_PARM_DESC(disable_ctrl_shutdown
,
146 "Disable controller shutdown when controller locked up.");
148 static char *pqi_lockup_action_param
;
149 module_param_named(lockup_action
,
150 pqi_lockup_action_param
, charp
, 0644);
151 MODULE_PARM_DESC(lockup_action
, "Action to take when controller locked up.\n"
152 "\t\tSupported: none, reboot, panic\n"
153 "\t\tDefault: none");
155 static char *raid_levels
[] = {
165 static char *pqi_raid_level_to_string(u8 raid_level
)
167 if (raid_level
< ARRAY_SIZE(raid_levels
))
168 return raid_levels
[raid_level
];
170 return "RAID UNKNOWN";
175 #define SA_RAID_1 2 /* also used for RAID 10 */
176 #define SA_RAID_5 3 /* also used for RAID 50 */
178 #define SA_RAID_6 5 /* also used for RAID 60 */
179 #define SA_RAID_ADM 6 /* also used for RAID 1+0 ADM */
180 #define SA_RAID_MAX SA_RAID_ADM
181 #define SA_RAID_UNKNOWN 0xff
183 static inline void pqi_scsi_done(struct scsi_cmnd
*scmd
)
185 pqi_prep_for_scsi_done(scmd
);
186 scmd
->scsi_done(scmd
);
189 static inline void pqi_disable_write_same(struct scsi_device
*sdev
)
191 sdev
->no_write_same
= 1;
194 static inline bool pqi_scsi3addr_equal(u8
*scsi3addr1
, u8
*scsi3addr2
)
196 return memcmp(scsi3addr1
, scsi3addr2
, 8) == 0;
199 static inline bool pqi_is_logical_device(struct pqi_scsi_dev
*device
)
201 return !device
->is_physical_device
;
204 static inline bool pqi_is_external_raid_addr(u8
*scsi3addr
)
206 return scsi3addr
[2] != 0;
209 static inline void pqi_check_ctrl_health(struct pqi_ctrl_info
*ctrl_info
)
211 if (ctrl_info
->controller_online
)
212 if (!sis_is_firmware_running(ctrl_info
))
213 pqi_take_ctrl_offline(ctrl_info
);
216 static inline bool pqi_is_hba_lunid(u8
*scsi3addr
)
218 return pqi_scsi3addr_equal(scsi3addr
, RAID_CTLR_LUNID
);
221 static inline enum pqi_ctrl_mode
pqi_get_ctrl_mode(
222 struct pqi_ctrl_info
*ctrl_info
)
224 return sis_read_driver_scratch(ctrl_info
);
227 static inline void pqi_save_ctrl_mode(struct pqi_ctrl_info
*ctrl_info
,
228 enum pqi_ctrl_mode mode
)
230 sis_write_driver_scratch(ctrl_info
, mode
);
233 static inline void pqi_ctrl_block_requests(struct pqi_ctrl_info
*ctrl_info
)
235 ctrl_info
->block_requests
= true;
236 scsi_block_requests(ctrl_info
->scsi_host
);
239 static inline void pqi_ctrl_unblock_requests(struct pqi_ctrl_info
*ctrl_info
)
241 ctrl_info
->block_requests
= false;
242 wake_up_all(&ctrl_info
->block_requests_wait
);
243 pqi_retry_raid_bypass_requests(ctrl_info
);
244 scsi_unblock_requests(ctrl_info
->scsi_host
);
247 static unsigned long pqi_wait_if_ctrl_blocked(struct pqi_ctrl_info
*ctrl_info
,
248 unsigned long timeout_msecs
)
250 unsigned long remaining_msecs
;
252 if (!pqi_ctrl_blocked(ctrl_info
))
253 return timeout_msecs
;
255 atomic_inc(&ctrl_info
->num_blocked_threads
);
257 if (timeout_msecs
== NO_TIMEOUT
) {
258 wait_event(ctrl_info
->block_requests_wait
,
259 !pqi_ctrl_blocked(ctrl_info
));
260 remaining_msecs
= timeout_msecs
;
262 unsigned long remaining_jiffies
;
265 wait_event_timeout(ctrl_info
->block_requests_wait
,
266 !pqi_ctrl_blocked(ctrl_info
),
267 msecs_to_jiffies(timeout_msecs
));
268 remaining_msecs
= jiffies_to_msecs(remaining_jiffies
);
271 atomic_dec(&ctrl_info
->num_blocked_threads
);
273 return remaining_msecs
;
276 static inline void pqi_ctrl_wait_until_quiesced(struct pqi_ctrl_info
*ctrl_info
)
278 while (atomic_read(&ctrl_info
->num_busy_threads
) >
279 atomic_read(&ctrl_info
->num_blocked_threads
))
280 usleep_range(1000, 2000);
283 static inline bool pqi_device_offline(struct pqi_scsi_dev
*device
)
285 return device
->device_offline
;
288 static inline void pqi_device_reset_start(struct pqi_scsi_dev
*device
)
290 device
->in_reset
= true;
293 static inline void pqi_device_reset_done(struct pqi_scsi_dev
*device
)
295 device
->in_reset
= false;
298 static inline bool pqi_device_in_reset(struct pqi_scsi_dev
*device
)
300 return device
->in_reset
;
303 static inline void pqi_ctrl_ofa_start(struct pqi_ctrl_info
*ctrl_info
)
305 ctrl_info
->in_ofa
= true;
308 static inline void pqi_ctrl_ofa_done(struct pqi_ctrl_info
*ctrl_info
)
310 ctrl_info
->in_ofa
= false;
313 static inline bool pqi_ctrl_in_ofa(struct pqi_ctrl_info
*ctrl_info
)
315 return ctrl_info
->in_ofa
;
318 static inline void pqi_device_remove_start(struct pqi_scsi_dev
*device
)
320 device
->in_remove
= true;
323 static inline bool pqi_device_in_remove(struct pqi_ctrl_info
*ctrl_info
,
324 struct pqi_scsi_dev
*device
)
326 return device
->in_remove
&& !ctrl_info
->in_shutdown
;
329 static inline void pqi_schedule_rescan_worker_with_delay(
330 struct pqi_ctrl_info
*ctrl_info
, unsigned long delay
)
332 if (pqi_ctrl_offline(ctrl_info
))
334 if (pqi_ctrl_in_ofa(ctrl_info
))
337 schedule_delayed_work(&ctrl_info
->rescan_work
, delay
);
340 static inline void pqi_schedule_rescan_worker(struct pqi_ctrl_info
*ctrl_info
)
342 pqi_schedule_rescan_worker_with_delay(ctrl_info
, 0);
345 #define PQI_RESCAN_WORK_DELAY (10 * PQI_HZ)
347 static inline void pqi_schedule_rescan_worker_delayed(
348 struct pqi_ctrl_info
*ctrl_info
)
350 pqi_schedule_rescan_worker_with_delay(ctrl_info
, PQI_RESCAN_WORK_DELAY
);
353 static inline void pqi_cancel_rescan_worker(struct pqi_ctrl_info
*ctrl_info
)
355 cancel_delayed_work_sync(&ctrl_info
->rescan_work
);
358 static inline u32
pqi_read_heartbeat_counter(struct pqi_ctrl_info
*ctrl_info
)
360 if (!ctrl_info
->heartbeat_counter
)
363 return readl(ctrl_info
->heartbeat_counter
);
366 static inline u8
pqi_read_soft_reset_status(struct pqi_ctrl_info
*ctrl_info
)
368 if (!ctrl_info
->soft_reset_status
)
371 return readb(ctrl_info
->soft_reset_status
);
374 static inline void pqi_clear_soft_reset_status(struct pqi_ctrl_info
*ctrl_info
,
379 if (!ctrl_info
->soft_reset_status
)
382 status
= pqi_read_soft_reset_status(ctrl_info
);
384 writeb(status
, ctrl_info
->soft_reset_status
);
387 static int pqi_map_single(struct pci_dev
*pci_dev
,
388 struct pqi_sg_descriptor
*sg_descriptor
, void *buffer
,
389 size_t buffer_length
, enum dma_data_direction data_direction
)
391 dma_addr_t bus_address
;
393 if (!buffer
|| buffer_length
== 0 || data_direction
== DMA_NONE
)
396 bus_address
= dma_map_single(&pci_dev
->dev
, buffer
, buffer_length
,
398 if (dma_mapping_error(&pci_dev
->dev
, bus_address
))
401 put_unaligned_le64((u64
)bus_address
, &sg_descriptor
->address
);
402 put_unaligned_le32(buffer_length
, &sg_descriptor
->length
);
403 put_unaligned_le32(CISS_SG_LAST
, &sg_descriptor
->flags
);
408 static void pqi_pci_unmap(struct pci_dev
*pci_dev
,
409 struct pqi_sg_descriptor
*descriptors
, int num_descriptors
,
410 enum dma_data_direction data_direction
)
414 if (data_direction
== DMA_NONE
)
417 for (i
= 0; i
< num_descriptors
; i
++)
418 dma_unmap_single(&pci_dev
->dev
,
419 (dma_addr_t
)get_unaligned_le64(&descriptors
[i
].address
),
420 get_unaligned_le32(&descriptors
[i
].length
),
424 static int pqi_build_raid_path_request(struct pqi_ctrl_info
*ctrl_info
,
425 struct pqi_raid_path_request
*request
, u8 cmd
,
426 u8
*scsi3addr
, void *buffer
, size_t buffer_length
,
427 u16 vpd_page
, enum dma_data_direction
*dir
)
430 size_t cdb_length
= buffer_length
;
432 memset(request
, 0, sizeof(*request
));
434 request
->header
.iu_type
= PQI_REQUEST_IU_RAID_PATH_IO
;
435 put_unaligned_le16(offsetof(struct pqi_raid_path_request
,
436 sg_descriptors
[1]) - PQI_REQUEST_HEADER_LENGTH
,
437 &request
->header
.iu_length
);
438 put_unaligned_le32(buffer_length
, &request
->buffer_length
);
439 memcpy(request
->lun_number
, scsi3addr
, sizeof(request
->lun_number
));
440 request
->task_attribute
= SOP_TASK_ATTRIBUTE_SIMPLE
;
441 request
->additional_cdb_bytes_usage
= SOP_ADDITIONAL_CDB_BYTES_0
;
447 request
->data_direction
= SOP_READ_FLAG
;
449 if (vpd_page
& VPD_PAGE
) {
451 cdb
[2] = (u8
)vpd_page
;
453 cdb
[4] = (u8
)cdb_length
;
455 case CISS_REPORT_LOG
:
456 case CISS_REPORT_PHYS
:
457 request
->data_direction
= SOP_READ_FLAG
;
459 if (cmd
== CISS_REPORT_PHYS
)
460 cdb
[1] = CISS_REPORT_PHYS_EXTENDED
;
462 cdb
[1] = CISS_REPORT_LOG_EXTENDED
;
463 put_unaligned_be32(cdb_length
, &cdb
[6]);
465 case CISS_GET_RAID_MAP
:
466 request
->data_direction
= SOP_READ_FLAG
;
468 cdb
[1] = CISS_GET_RAID_MAP
;
469 put_unaligned_be32(cdb_length
, &cdb
[6]);
472 request
->data_direction
= SOP_WRITE_FLAG
;
474 cdb
[6] = BMIC_FLUSH_CACHE
;
475 put_unaligned_be16(cdb_length
, &cdb
[7]);
477 case BMIC_SENSE_DIAG_OPTIONS
:
480 case BMIC_IDENTIFY_CONTROLLER
:
481 case BMIC_IDENTIFY_PHYSICAL_DEVICE
:
482 request
->data_direction
= SOP_READ_FLAG
;
485 put_unaligned_be16(cdb_length
, &cdb
[7]);
487 case BMIC_SET_DIAG_OPTIONS
:
490 case BMIC_WRITE_HOST_WELLNESS
:
491 request
->data_direction
= SOP_WRITE_FLAG
;
494 put_unaligned_be16(cdb_length
, &cdb
[7]);
496 case BMIC_CSMI_PASSTHRU
:
497 request
->data_direction
= SOP_BIDIRECTIONAL
;
499 cdb
[5] = CSMI_CC_SAS_SMP_PASSTHRU
;
501 put_unaligned_be16(cdb_length
, &cdb
[7]);
504 dev_err(&ctrl_info
->pci_dev
->dev
, "unknown command 0x%c\n",
509 switch (request
->data_direction
) {
511 *dir
= DMA_FROM_DEVICE
;
514 *dir
= DMA_TO_DEVICE
;
516 case SOP_NO_DIRECTION_FLAG
:
520 *dir
= DMA_BIDIRECTIONAL
;
524 return pqi_map_single(ctrl_info
->pci_dev
, &request
->sg_descriptors
[0],
525 buffer
, buffer_length
, *dir
);
528 static inline void pqi_reinit_io_request(struct pqi_io_request
*io_request
)
530 io_request
->scmd
= NULL
;
531 io_request
->status
= 0;
532 io_request
->error_info
= NULL
;
533 io_request
->raid_bypass
= false;
536 static struct pqi_io_request
*pqi_alloc_io_request(
537 struct pqi_ctrl_info
*ctrl_info
)
539 struct pqi_io_request
*io_request
;
540 u16 i
= ctrl_info
->next_io_request_slot
; /* benignly racy */
543 io_request
= &ctrl_info
->io_request_pool
[i
];
544 if (atomic_inc_return(&io_request
->refcount
) == 1)
546 atomic_dec(&io_request
->refcount
);
547 i
= (i
+ 1) % ctrl_info
->max_io_slots
;
551 ctrl_info
->next_io_request_slot
= (i
+ 1) % ctrl_info
->max_io_slots
;
553 pqi_reinit_io_request(io_request
);
558 static void pqi_free_io_request(struct pqi_io_request
*io_request
)
560 atomic_dec(&io_request
->refcount
);
563 static int pqi_send_scsi_raid_request(struct pqi_ctrl_info
*ctrl_info
, u8 cmd
,
564 u8
*scsi3addr
, void *buffer
, size_t buffer_length
, u16 vpd_page
,
565 struct pqi_raid_error_info
*error_info
,
566 unsigned long timeout_msecs
)
569 enum dma_data_direction dir
;
570 struct pqi_raid_path_request request
;
572 rc
= pqi_build_raid_path_request(ctrl_info
, &request
,
573 cmd
, scsi3addr
, buffer
,
574 buffer_length
, vpd_page
, &dir
);
578 rc
= pqi_submit_raid_request_synchronous(ctrl_info
, &request
.header
,
579 0, error_info
, timeout_msecs
);
581 pqi_pci_unmap(ctrl_info
->pci_dev
, request
.sg_descriptors
, 1, dir
);
585 /* Helper functions for pqi_send_scsi_raid_request */
587 static inline int pqi_send_ctrl_raid_request(struct pqi_ctrl_info
*ctrl_info
,
588 u8 cmd
, void *buffer
, size_t buffer_length
)
590 return pqi_send_scsi_raid_request(ctrl_info
, cmd
, RAID_CTLR_LUNID
,
591 buffer
, buffer_length
, 0, NULL
, NO_TIMEOUT
);
594 static inline int pqi_send_ctrl_raid_with_error(struct pqi_ctrl_info
*ctrl_info
,
595 u8 cmd
, void *buffer
, size_t buffer_length
,
596 struct pqi_raid_error_info
*error_info
)
598 return pqi_send_scsi_raid_request(ctrl_info
, cmd
, RAID_CTLR_LUNID
,
599 buffer
, buffer_length
, 0, error_info
, NO_TIMEOUT
);
603 static inline int pqi_identify_controller(struct pqi_ctrl_info
*ctrl_info
,
604 struct bmic_identify_controller
*buffer
)
606 return pqi_send_ctrl_raid_request(ctrl_info
, BMIC_IDENTIFY_CONTROLLER
,
607 buffer
, sizeof(*buffer
));
610 static inline int pqi_scsi_inquiry(struct pqi_ctrl_info
*ctrl_info
,
611 u8
*scsi3addr
, u16 vpd_page
, void *buffer
, size_t buffer_length
)
613 return pqi_send_scsi_raid_request(ctrl_info
, INQUIRY
, scsi3addr
,
614 buffer
, buffer_length
, vpd_page
, NULL
, NO_TIMEOUT
);
617 static bool pqi_vpd_page_supported(struct pqi_ctrl_info
*ctrl_info
,
618 u8
*scsi3addr
, u16 vpd_page
)
623 unsigned char *buf
, bufsize
;
625 buf
= kzalloc(256, GFP_KERNEL
);
629 /* Get the size of the page list first */
630 rc
= pqi_scsi_inquiry(ctrl_info
, scsi3addr
,
631 VPD_PAGE
| SCSI_VPD_SUPPORTED_PAGES
,
632 buf
, SCSI_VPD_HEADER_SZ
);
634 goto exit_unsupported
;
637 if ((pages
+ SCSI_VPD_HEADER_SZ
) <= 255)
638 bufsize
= pages
+ SCSI_VPD_HEADER_SZ
;
642 /* Get the whole VPD page list */
643 rc
= pqi_scsi_inquiry(ctrl_info
, scsi3addr
,
644 VPD_PAGE
| SCSI_VPD_SUPPORTED_PAGES
,
647 goto exit_unsupported
;
650 for (i
= 1; i
<= pages
; i
++)
651 if (buf
[3 + i
] == vpd_page
)
663 static int pqi_get_device_id(struct pqi_ctrl_info
*ctrl_info
,
664 u8
*scsi3addr
, u8
*device_id
, int buflen
)
669 if (!pqi_vpd_page_supported(ctrl_info
, scsi3addr
, SCSI_VPD_DEVICE_ID
))
670 return 1; /* function not supported */
672 buf
= kzalloc(64, GFP_KERNEL
);
676 rc
= pqi_scsi_inquiry(ctrl_info
, scsi3addr
,
677 VPD_PAGE
| SCSI_VPD_DEVICE_ID
,
682 memcpy(device_id
, &buf
[SCSI_VPD_DEVICE_ID_IDX
], buflen
);
690 static int pqi_identify_physical_device(struct pqi_ctrl_info
*ctrl_info
,
691 struct pqi_scsi_dev
*device
,
692 struct bmic_identify_physical_device
*buffer
,
693 size_t buffer_length
)
696 enum dma_data_direction dir
;
697 u16 bmic_device_index
;
698 struct pqi_raid_path_request request
;
700 rc
= pqi_build_raid_path_request(ctrl_info
, &request
,
701 BMIC_IDENTIFY_PHYSICAL_DEVICE
, RAID_CTLR_LUNID
, buffer
,
702 buffer_length
, 0, &dir
);
706 bmic_device_index
= CISS_GET_DRIVE_NUMBER(device
->scsi3addr
);
707 request
.cdb
[2] = (u8
)bmic_device_index
;
708 request
.cdb
[9] = (u8
)(bmic_device_index
>> 8);
710 rc
= pqi_submit_raid_request_synchronous(ctrl_info
, &request
.header
,
711 0, NULL
, NO_TIMEOUT
);
713 pqi_pci_unmap(ctrl_info
->pci_dev
, request
.sg_descriptors
, 1, dir
);
717 static int pqi_flush_cache(struct pqi_ctrl_info
*ctrl_info
,
718 enum bmic_flush_cache_shutdown_event shutdown_event
)
721 struct bmic_flush_cache
*flush_cache
;
724 * Don't bother trying to flush the cache if the controller is
727 if (pqi_ctrl_offline(ctrl_info
))
730 flush_cache
= kzalloc(sizeof(*flush_cache
), GFP_KERNEL
);
734 flush_cache
->shutdown_event
= shutdown_event
;
736 rc
= pqi_send_ctrl_raid_request(ctrl_info
, SA_FLUSH_CACHE
, flush_cache
,
737 sizeof(*flush_cache
));
744 int pqi_csmi_smp_passthru(struct pqi_ctrl_info
*ctrl_info
,
745 struct bmic_csmi_smp_passthru_buffer
*buffer
, size_t buffer_length
,
746 struct pqi_raid_error_info
*error_info
)
748 return pqi_send_ctrl_raid_with_error(ctrl_info
, BMIC_CSMI_PASSTHRU
,
749 buffer
, buffer_length
, error_info
);
752 #define PQI_FETCH_PTRAID_DATA (1UL<<31)
754 static int pqi_set_diag_rescan(struct pqi_ctrl_info
*ctrl_info
)
757 struct bmic_diag_options
*diag
;
759 diag
= kzalloc(sizeof(*diag
), GFP_KERNEL
);
763 rc
= pqi_send_ctrl_raid_request(ctrl_info
, BMIC_SENSE_DIAG_OPTIONS
,
764 diag
, sizeof(*diag
));
768 diag
->options
|= cpu_to_le32(PQI_FETCH_PTRAID_DATA
);
770 rc
= pqi_send_ctrl_raid_request(ctrl_info
, BMIC_SET_DIAG_OPTIONS
,
771 diag
, sizeof(*diag
));
778 static inline int pqi_write_host_wellness(struct pqi_ctrl_info
*ctrl_info
,
779 void *buffer
, size_t buffer_length
)
781 return pqi_send_ctrl_raid_request(ctrl_info
, BMIC_WRITE_HOST_WELLNESS
,
782 buffer
, buffer_length
);
787 struct bmic_host_wellness_driver_version
{
789 u8 driver_version_tag
[2];
790 __le16 driver_version_length
;
791 char driver_version
[32];
792 u8 dont_write_tag
[2];
798 static int pqi_write_driver_version_to_host_wellness(
799 struct pqi_ctrl_info
*ctrl_info
)
802 struct bmic_host_wellness_driver_version
*buffer
;
803 size_t buffer_length
;
805 buffer_length
= sizeof(*buffer
);
807 buffer
= kmalloc(buffer_length
, GFP_KERNEL
);
811 buffer
->start_tag
[0] = '<';
812 buffer
->start_tag
[1] = 'H';
813 buffer
->start_tag
[2] = 'W';
814 buffer
->start_tag
[3] = '>';
815 buffer
->driver_version_tag
[0] = 'D';
816 buffer
->driver_version_tag
[1] = 'V';
817 put_unaligned_le16(sizeof(buffer
->driver_version
),
818 &buffer
->driver_version_length
);
819 strncpy(buffer
->driver_version
, "Linux " DRIVER_VERSION
,
820 sizeof(buffer
->driver_version
) - 1);
821 buffer
->driver_version
[sizeof(buffer
->driver_version
) - 1] = '\0';
822 buffer
->dont_write_tag
[0] = 'D';
823 buffer
->dont_write_tag
[1] = 'W';
824 buffer
->end_tag
[0] = 'Z';
825 buffer
->end_tag
[1] = 'Z';
827 rc
= pqi_write_host_wellness(ctrl_info
, buffer
, buffer_length
);
836 struct bmic_host_wellness_time
{
841 u8 dont_write_tag
[2];
847 static int pqi_write_current_time_to_host_wellness(
848 struct pqi_ctrl_info
*ctrl_info
)
851 struct bmic_host_wellness_time
*buffer
;
852 size_t buffer_length
;
857 buffer_length
= sizeof(*buffer
);
859 buffer
= kmalloc(buffer_length
, GFP_KERNEL
);
863 buffer
->start_tag
[0] = '<';
864 buffer
->start_tag
[1] = 'H';
865 buffer
->start_tag
[2] = 'W';
866 buffer
->start_tag
[3] = '>';
867 buffer
->time_tag
[0] = 'T';
868 buffer
->time_tag
[1] = 'D';
869 put_unaligned_le16(sizeof(buffer
->time
),
870 &buffer
->time_length
);
872 local_time
= ktime_get_real_seconds();
873 time64_to_tm(local_time
, -sys_tz
.tz_minuteswest
* 60, &tm
);
874 year
= tm
.tm_year
+ 1900;
876 buffer
->time
[0] = bin2bcd(tm
.tm_hour
);
877 buffer
->time
[1] = bin2bcd(tm
.tm_min
);
878 buffer
->time
[2] = bin2bcd(tm
.tm_sec
);
880 buffer
->time
[4] = bin2bcd(tm
.tm_mon
+ 1);
881 buffer
->time
[5] = bin2bcd(tm
.tm_mday
);
882 buffer
->time
[6] = bin2bcd(year
/ 100);
883 buffer
->time
[7] = bin2bcd(year
% 100);
885 buffer
->dont_write_tag
[0] = 'D';
886 buffer
->dont_write_tag
[1] = 'W';
887 buffer
->end_tag
[0] = 'Z';
888 buffer
->end_tag
[1] = 'Z';
890 rc
= pqi_write_host_wellness(ctrl_info
, buffer
, buffer_length
);
897 #define PQI_UPDATE_TIME_WORK_INTERVAL (24UL * 60 * 60 * PQI_HZ)
899 static void pqi_update_time_worker(struct work_struct
*work
)
902 struct pqi_ctrl_info
*ctrl_info
;
904 ctrl_info
= container_of(to_delayed_work(work
), struct pqi_ctrl_info
,
907 if (pqi_ctrl_offline(ctrl_info
))
910 rc
= pqi_write_current_time_to_host_wellness(ctrl_info
);
912 dev_warn(&ctrl_info
->pci_dev
->dev
,
913 "error updating time on controller\n");
915 schedule_delayed_work(&ctrl_info
->update_time_work
,
916 PQI_UPDATE_TIME_WORK_INTERVAL
);
919 static inline void pqi_schedule_update_time_worker(
920 struct pqi_ctrl_info
*ctrl_info
)
922 schedule_delayed_work(&ctrl_info
->update_time_work
, 0);
925 static inline void pqi_cancel_update_time_worker(
926 struct pqi_ctrl_info
*ctrl_info
)
928 cancel_delayed_work_sync(&ctrl_info
->update_time_work
);
931 static inline int pqi_report_luns(struct pqi_ctrl_info
*ctrl_info
, u8 cmd
,
932 void *buffer
, size_t buffer_length
)
934 return pqi_send_ctrl_raid_request(ctrl_info
, cmd
, buffer
,
938 static int pqi_report_phys_logical_luns(struct pqi_ctrl_info
*ctrl_info
, u8 cmd
,
942 size_t lun_list_length
;
943 size_t lun_data_length
;
944 size_t new_lun_list_length
;
945 void *lun_data
= NULL
;
946 struct report_lun_header
*report_lun_header
;
948 report_lun_header
= kmalloc(sizeof(*report_lun_header
), GFP_KERNEL
);
949 if (!report_lun_header
) {
954 rc
= pqi_report_luns(ctrl_info
, cmd
, report_lun_header
,
955 sizeof(*report_lun_header
));
959 lun_list_length
= get_unaligned_be32(&report_lun_header
->list_length
);
962 lun_data_length
= sizeof(struct report_lun_header
) + lun_list_length
;
964 lun_data
= kmalloc(lun_data_length
, GFP_KERNEL
);
970 if (lun_list_length
== 0) {
971 memcpy(lun_data
, report_lun_header
, sizeof(*report_lun_header
));
975 rc
= pqi_report_luns(ctrl_info
, cmd
, lun_data
, lun_data_length
);
979 new_lun_list_length
= get_unaligned_be32(
980 &((struct report_lun_header
*)lun_data
)->list_length
);
982 if (new_lun_list_length
> lun_list_length
) {
983 lun_list_length
= new_lun_list_length
;
989 kfree(report_lun_header
);
1001 static inline int pqi_report_phys_luns(struct pqi_ctrl_info
*ctrl_info
,
1004 return pqi_report_phys_logical_luns(ctrl_info
, CISS_REPORT_PHYS
,
1008 static inline int pqi_report_logical_luns(struct pqi_ctrl_info
*ctrl_info
,
1011 return pqi_report_phys_logical_luns(ctrl_info
, CISS_REPORT_LOG
, buffer
);
1014 static int pqi_get_device_lists(struct pqi_ctrl_info
*ctrl_info
,
1015 struct report_phys_lun_extended
**physdev_list
,
1016 struct report_log_lun_extended
**logdev_list
)
1019 size_t logdev_list_length
;
1020 size_t logdev_data_length
;
1021 struct report_log_lun_extended
*internal_logdev_list
;
1022 struct report_log_lun_extended
*logdev_data
;
1023 struct report_lun_header report_lun_header
;
1025 rc
= pqi_report_phys_luns(ctrl_info
, (void **)physdev_list
);
1027 dev_err(&ctrl_info
->pci_dev
->dev
,
1028 "report physical LUNs failed\n");
1030 rc
= pqi_report_logical_luns(ctrl_info
, (void **)logdev_list
);
1032 dev_err(&ctrl_info
->pci_dev
->dev
,
1033 "report logical LUNs failed\n");
1036 * Tack the controller itself onto the end of the logical device list.
1039 logdev_data
= *logdev_list
;
1042 logdev_list_length
=
1043 get_unaligned_be32(&logdev_data
->header
.list_length
);
1045 memset(&report_lun_header
, 0, sizeof(report_lun_header
));
1047 (struct report_log_lun_extended
*)&report_lun_header
;
1048 logdev_list_length
= 0;
1051 logdev_data_length
= sizeof(struct report_lun_header
) +
1054 internal_logdev_list
= kmalloc(logdev_data_length
+
1055 sizeof(struct report_log_lun_extended
), GFP_KERNEL
);
1056 if (!internal_logdev_list
) {
1057 kfree(*logdev_list
);
1058 *logdev_list
= NULL
;
1062 memcpy(internal_logdev_list
, logdev_data
, logdev_data_length
);
1063 memset((u8
*)internal_logdev_list
+ logdev_data_length
, 0,
1064 sizeof(struct report_log_lun_extended_entry
));
1065 put_unaligned_be32(logdev_list_length
+
1066 sizeof(struct report_log_lun_extended_entry
),
1067 &internal_logdev_list
->header
.list_length
);
1069 kfree(*logdev_list
);
1070 *logdev_list
= internal_logdev_list
;
1075 static inline void pqi_set_bus_target_lun(struct pqi_scsi_dev
*device
,
1076 int bus
, int target
, int lun
)
1079 device
->target
= target
;
1083 static void pqi_assign_bus_target_lun(struct pqi_scsi_dev
*device
)
1091 scsi3addr
= device
->scsi3addr
;
1092 lunid
= get_unaligned_le32(scsi3addr
);
1094 if (pqi_is_hba_lunid(scsi3addr
)) {
1095 /* The specified device is the controller. */
1096 pqi_set_bus_target_lun(device
, PQI_HBA_BUS
, 0, lunid
& 0x3fff);
1097 device
->target_lun_valid
= true;
1101 if (pqi_is_logical_device(device
)) {
1102 if (device
->is_external_raid_device
) {
1103 bus
= PQI_EXTERNAL_RAID_VOLUME_BUS
;
1104 target
= (lunid
>> 16) & 0x3fff;
1107 bus
= PQI_RAID_VOLUME_BUS
;
1109 lun
= lunid
& 0x3fff;
1111 pqi_set_bus_target_lun(device
, bus
, target
, lun
);
1112 device
->target_lun_valid
= true;
1117 * Defer target and LUN assignment for non-controller physical devices
1118 * because the SAS transport layer will make these assignments later.
1120 pqi_set_bus_target_lun(device
, PQI_PHYSICAL_DEVICE_BUS
, 0, 0);
1123 static void pqi_get_raid_level(struct pqi_ctrl_info
*ctrl_info
,
1124 struct pqi_scsi_dev
*device
)
1130 raid_level
= SA_RAID_UNKNOWN
;
1132 buffer
= kmalloc(64, GFP_KERNEL
);
1134 rc
= pqi_scsi_inquiry(ctrl_info
, device
->scsi3addr
,
1135 VPD_PAGE
| CISS_VPD_LV_DEVICE_GEOMETRY
, buffer
, 64);
1137 raid_level
= buffer
[8];
1138 if (raid_level
> SA_RAID_MAX
)
1139 raid_level
= SA_RAID_UNKNOWN
;
1144 device
->raid_level
= raid_level
;
1147 static int pqi_validate_raid_map(struct pqi_ctrl_info
*ctrl_info
,
1148 struct pqi_scsi_dev
*device
, struct raid_map
*raid_map
)
1152 u32 r5or6_blocks_per_row
;
1154 raid_map_size
= get_unaligned_le32(&raid_map
->structure_size
);
1156 if (raid_map_size
< offsetof(struct raid_map
, disk_data
)) {
1157 err_msg
= "RAID map too small";
1161 if (device
->raid_level
== SA_RAID_1
) {
1162 if (get_unaligned_le16(&raid_map
->layout_map_count
) != 2) {
1163 err_msg
= "invalid RAID-1 map";
1166 } else if (device
->raid_level
== SA_RAID_ADM
) {
1167 if (get_unaligned_le16(&raid_map
->layout_map_count
) != 3) {
1168 err_msg
= "invalid RAID-1(ADM) map";
1171 } else if ((device
->raid_level
== SA_RAID_5
||
1172 device
->raid_level
== SA_RAID_6
) &&
1173 get_unaligned_le16(&raid_map
->layout_map_count
) > 1) {
1175 r5or6_blocks_per_row
=
1176 get_unaligned_le16(&raid_map
->strip_size
) *
1177 get_unaligned_le16(&raid_map
->data_disks_per_row
);
1178 if (r5or6_blocks_per_row
== 0) {
1179 err_msg
= "invalid RAID-5 or RAID-6 map";
1187 dev_warn(&ctrl_info
->pci_dev
->dev
,
1188 "logical device %08x%08x %s\n",
1189 *((u32
*)&device
->scsi3addr
),
1190 *((u32
*)&device
->scsi3addr
[4]), err_msg
);
1195 static int pqi_get_raid_map(struct pqi_ctrl_info
*ctrl_info
,
1196 struct pqi_scsi_dev
*device
)
1200 struct raid_map
*raid_map
;
1202 raid_map
= kmalloc(sizeof(*raid_map
), GFP_KERNEL
);
1206 rc
= pqi_send_scsi_raid_request(ctrl_info
, CISS_GET_RAID_MAP
,
1207 device
->scsi3addr
, raid_map
, sizeof(*raid_map
),
1208 0, NULL
, NO_TIMEOUT
);
1213 raid_map_size
= get_unaligned_le32(&raid_map
->structure_size
);
1215 if (raid_map_size
> sizeof(*raid_map
)) {
1219 raid_map
= kmalloc(raid_map_size
, GFP_KERNEL
);
1223 rc
= pqi_send_scsi_raid_request(ctrl_info
, CISS_GET_RAID_MAP
,
1224 device
->scsi3addr
, raid_map
, raid_map_size
,
1225 0, NULL
, NO_TIMEOUT
);
1229 if (get_unaligned_le32(&raid_map
->structure_size
)
1231 dev_warn(&ctrl_info
->pci_dev
->dev
,
1232 "Requested %d bytes, received %d bytes",
1234 get_unaligned_le32(&raid_map
->structure_size
));
1239 rc
= pqi_validate_raid_map(ctrl_info
, device
, raid_map
);
1243 device
->raid_map
= raid_map
;
1253 static void pqi_get_raid_bypass_status(struct pqi_ctrl_info
*ctrl_info
,
1254 struct pqi_scsi_dev
*device
)
1260 buffer
= kmalloc(64, GFP_KERNEL
);
1264 rc
= pqi_scsi_inquiry(ctrl_info
, device
->scsi3addr
,
1265 VPD_PAGE
| CISS_VPD_LV_BYPASS_STATUS
, buffer
, 64);
1269 #define RAID_BYPASS_STATUS 4
1270 #define RAID_BYPASS_CONFIGURED 0x1
1271 #define RAID_BYPASS_ENABLED 0x2
1273 bypass_status
= buffer
[RAID_BYPASS_STATUS
];
1274 device
->raid_bypass_configured
=
1275 (bypass_status
& RAID_BYPASS_CONFIGURED
) != 0;
1276 if (device
->raid_bypass_configured
&&
1277 (bypass_status
& RAID_BYPASS_ENABLED
) &&
1278 pqi_get_raid_map(ctrl_info
, device
) == 0)
1279 device
->raid_bypass_enabled
= true;
1286 * Use vendor-specific VPD to determine online/offline status of a volume.
1289 static void pqi_get_volume_status(struct pqi_ctrl_info
*ctrl_info
,
1290 struct pqi_scsi_dev
*device
)
1294 u8 volume_status
= CISS_LV_STATUS_UNAVAILABLE
;
1295 bool volume_offline
= true;
1297 struct ciss_vpd_logical_volume_status
*vpd
;
1299 vpd
= kmalloc(sizeof(*vpd
), GFP_KERNEL
);
1303 rc
= pqi_scsi_inquiry(ctrl_info
, device
->scsi3addr
,
1304 VPD_PAGE
| CISS_VPD_LV_STATUS
, vpd
, sizeof(*vpd
));
1308 if (vpd
->page_code
!= CISS_VPD_LV_STATUS
)
1311 page_length
= offsetof(struct ciss_vpd_logical_volume_status
,
1312 volume_status
) + vpd
->page_length
;
1313 if (page_length
< sizeof(*vpd
))
1316 volume_status
= vpd
->volume_status
;
1317 volume_flags
= get_unaligned_be32(&vpd
->flags
);
1318 volume_offline
= (volume_flags
& CISS_LV_FLAGS_NO_HOST_IO
) != 0;
1323 device
->volume_status
= volume_status
;
1324 device
->volume_offline
= volume_offline
;
1327 #define PQI_INQUIRY_PAGE0_RETRIES 3
1329 static int pqi_get_device_info(struct pqi_ctrl_info
*ctrl_info
,
1330 struct pqi_scsi_dev
*device
)
1334 unsigned int retries
;
1336 if (device
->is_expander_smp_device
)
1339 buffer
= kmalloc(64, GFP_KERNEL
);
1343 /* Send an inquiry to the device to see what it is. */
1344 for (retries
= 0;;) {
1345 rc
= pqi_scsi_inquiry(ctrl_info
, device
->scsi3addr
, 0,
1349 if (pqi_is_logical_device(device
) ||
1350 rc
!= PQI_CMD_STATUS_ABORTED
||
1351 ++retries
> PQI_INQUIRY_PAGE0_RETRIES
)
1355 scsi_sanitize_inquiry_string(&buffer
[8], 8);
1356 scsi_sanitize_inquiry_string(&buffer
[16], 16);
1358 device
->devtype
= buffer
[0] & 0x1f;
1359 memcpy(device
->vendor
, &buffer
[8], sizeof(device
->vendor
));
1360 memcpy(device
->model
, &buffer
[16], sizeof(device
->model
));
1362 if (pqi_is_logical_device(device
) && device
->devtype
== TYPE_DISK
) {
1363 if (device
->is_external_raid_device
) {
1364 device
->raid_level
= SA_RAID_UNKNOWN
;
1365 device
->volume_status
= CISS_LV_OK
;
1366 device
->volume_offline
= false;
1368 pqi_get_raid_level(ctrl_info
, device
);
1369 pqi_get_raid_bypass_status(ctrl_info
, device
);
1370 pqi_get_volume_status(ctrl_info
, device
);
1374 if (pqi_get_device_id(ctrl_info
, device
->scsi3addr
,
1375 device
->unique_id
, sizeof(device
->unique_id
)) < 0)
1376 dev_warn(&ctrl_info
->pci_dev
->dev
,
1377 "Can't get device id for scsi %d:%d:%d:%d\n",
1378 ctrl_info
->scsi_host
->host_no
,
1379 device
->bus
, device
->target
,
1388 static void pqi_get_physical_disk_info(struct pqi_ctrl_info
*ctrl_info
,
1389 struct pqi_scsi_dev
*device
,
1390 struct bmic_identify_physical_device
*id_phys
)
1394 memset(id_phys
, 0, sizeof(*id_phys
));
1396 rc
= pqi_identify_physical_device(ctrl_info
, device
,
1397 id_phys
, sizeof(*id_phys
));
1399 device
->queue_depth
= PQI_PHYSICAL_DISK_DEFAULT_MAX_QUEUE_DEPTH
;
1403 device
->queue_depth
=
1404 get_unaligned_le16(&id_phys
->current_queue_depth_limit
);
1405 device
->device_type
= id_phys
->device_type
;
1406 device
->active_path_index
= id_phys
->active_path_number
;
1407 device
->path_map
= id_phys
->redundant_path_present_map
;
1408 memcpy(&device
->box
,
1409 &id_phys
->alternate_paths_phys_box_on_port
,
1410 sizeof(device
->box
));
1411 memcpy(&device
->phys_connector
,
1412 &id_phys
->alternate_paths_phys_connector
,
1413 sizeof(device
->phys_connector
));
1414 device
->bay
= id_phys
->phys_bay_in_box
;
1417 static void pqi_show_volume_status(struct pqi_ctrl_info
*ctrl_info
,
1418 struct pqi_scsi_dev
*device
)
1421 static const char unknown_state_str
[] =
1422 "Volume is in an unknown state (%u)";
1423 char unknown_state_buffer
[sizeof(unknown_state_str
) + 10];
1425 switch (device
->volume_status
) {
1427 status
= "Volume online";
1429 case CISS_LV_FAILED
:
1430 status
= "Volume failed";
1432 case CISS_LV_NOT_CONFIGURED
:
1433 status
= "Volume not configured";
1435 case CISS_LV_DEGRADED
:
1436 status
= "Volume degraded";
1438 case CISS_LV_READY_FOR_RECOVERY
:
1439 status
= "Volume ready for recovery operation";
1441 case CISS_LV_UNDERGOING_RECOVERY
:
1442 status
= "Volume undergoing recovery";
1444 case CISS_LV_WRONG_PHYSICAL_DRIVE_REPLACED
:
1445 status
= "Wrong physical drive was replaced";
1447 case CISS_LV_PHYSICAL_DRIVE_CONNECTION_PROBLEM
:
1448 status
= "A physical drive not properly connected";
1450 case CISS_LV_HARDWARE_OVERHEATING
:
1451 status
= "Hardware is overheating";
1453 case CISS_LV_HARDWARE_HAS_OVERHEATED
:
1454 status
= "Hardware has overheated";
1456 case CISS_LV_UNDERGOING_EXPANSION
:
1457 status
= "Volume undergoing expansion";
1459 case CISS_LV_NOT_AVAILABLE
:
1460 status
= "Volume waiting for transforming volume";
1462 case CISS_LV_QUEUED_FOR_EXPANSION
:
1463 status
= "Volume queued for expansion";
1465 case CISS_LV_DISABLED_SCSI_ID_CONFLICT
:
1466 status
= "Volume disabled due to SCSI ID conflict";
1468 case CISS_LV_EJECTED
:
1469 status
= "Volume has been ejected";
1471 case CISS_LV_UNDERGOING_ERASE
:
1472 status
= "Volume undergoing background erase";
1474 case CISS_LV_READY_FOR_PREDICTIVE_SPARE_REBUILD
:
1475 status
= "Volume ready for predictive spare rebuild";
1477 case CISS_LV_UNDERGOING_RPI
:
1478 status
= "Volume undergoing rapid parity initialization";
1480 case CISS_LV_PENDING_RPI
:
1481 status
= "Volume queued for rapid parity initialization";
1483 case CISS_LV_ENCRYPTED_NO_KEY
:
1484 status
= "Encrypted volume inaccessible - key not present";
1486 case CISS_LV_UNDERGOING_ENCRYPTION
:
1487 status
= "Volume undergoing encryption process";
1489 case CISS_LV_UNDERGOING_ENCRYPTION_REKEYING
:
1490 status
= "Volume undergoing encryption re-keying process";
1492 case CISS_LV_ENCRYPTED_IN_NON_ENCRYPTED_CONTROLLER
:
1493 status
= "Volume encrypted but encryption is disabled";
1495 case CISS_LV_PENDING_ENCRYPTION
:
1496 status
= "Volume pending migration to encrypted state";
1498 case CISS_LV_PENDING_ENCRYPTION_REKEYING
:
1499 status
= "Volume pending encryption rekeying";
1501 case CISS_LV_NOT_SUPPORTED
:
1502 status
= "Volume not supported on this controller";
1504 case CISS_LV_STATUS_UNAVAILABLE
:
1505 status
= "Volume status not available";
1508 snprintf(unknown_state_buffer
, sizeof(unknown_state_buffer
),
1509 unknown_state_str
, device
->volume_status
);
1510 status
= unknown_state_buffer
;
1514 dev_info(&ctrl_info
->pci_dev
->dev
,
1515 "scsi %d:%d:%d:%d %s\n",
1516 ctrl_info
->scsi_host
->host_no
,
1517 device
->bus
, device
->target
, device
->lun
, status
);
1520 static void pqi_rescan_worker(struct work_struct
*work
)
1522 struct pqi_ctrl_info
*ctrl_info
;
1524 ctrl_info
= container_of(to_delayed_work(work
), struct pqi_ctrl_info
,
1527 pqi_scan_scsi_devices(ctrl_info
);
1530 static int pqi_add_device(struct pqi_ctrl_info
*ctrl_info
,
1531 struct pqi_scsi_dev
*device
)
1535 if (pqi_is_logical_device(device
))
1536 rc
= scsi_add_device(ctrl_info
->scsi_host
, device
->bus
,
1537 device
->target
, device
->lun
);
1539 rc
= pqi_add_sas_device(ctrl_info
->sas_host
, device
);
1544 #define PQI_PENDING_IO_TIMEOUT_SECS 20
1546 static inline void pqi_remove_device(struct pqi_ctrl_info
*ctrl_info
,
1547 struct pqi_scsi_dev
*device
)
1551 pqi_device_remove_start(device
);
1553 rc
= pqi_device_wait_for_pending_io(ctrl_info
, device
,
1554 PQI_PENDING_IO_TIMEOUT_SECS
);
1556 dev_err(&ctrl_info
->pci_dev
->dev
,
1557 "scsi %d:%d:%d:%d removing device with %d outstanding commands\n",
1558 ctrl_info
->scsi_host
->host_no
, device
->bus
,
1559 device
->target
, device
->lun
,
1560 atomic_read(&device
->scsi_cmds_outstanding
));
1562 if (pqi_is_logical_device(device
))
1563 scsi_remove_device(device
->sdev
);
1565 pqi_remove_sas_device(device
);
1568 /* Assumes the SCSI device list lock is held. */
1570 static struct pqi_scsi_dev
*pqi_find_scsi_dev(struct pqi_ctrl_info
*ctrl_info
,
1571 int bus
, int target
, int lun
)
1573 struct pqi_scsi_dev
*device
;
1575 list_for_each_entry(device
, &ctrl_info
->scsi_device_list
,
1576 scsi_device_list_entry
)
1577 if (device
->bus
== bus
&& device
->target
== target
&&
1584 static inline bool pqi_device_equal(struct pqi_scsi_dev
*dev1
,
1585 struct pqi_scsi_dev
*dev2
)
1587 if (dev1
->is_physical_device
!= dev2
->is_physical_device
)
1590 if (dev1
->is_physical_device
)
1591 return dev1
->wwid
== dev2
->wwid
;
1593 return memcmp(dev1
->volume_id
, dev2
->volume_id
,
1594 sizeof(dev1
->volume_id
)) == 0;
1597 enum pqi_find_result
{
1603 static enum pqi_find_result
pqi_scsi_find_entry(struct pqi_ctrl_info
*ctrl_info
,
1604 struct pqi_scsi_dev
*device_to_find
,
1605 struct pqi_scsi_dev
**matching_device
)
1607 struct pqi_scsi_dev
*device
;
1609 list_for_each_entry(device
, &ctrl_info
->scsi_device_list
,
1610 scsi_device_list_entry
) {
1611 if (pqi_scsi3addr_equal(device_to_find
->scsi3addr
,
1612 device
->scsi3addr
)) {
1613 *matching_device
= device
;
1614 if (pqi_device_equal(device_to_find
, device
)) {
1615 if (device_to_find
->volume_offline
)
1616 return DEVICE_CHANGED
;
1619 return DEVICE_CHANGED
;
1623 return DEVICE_NOT_FOUND
;
1626 static inline const char *pqi_device_type(struct pqi_scsi_dev
*device
)
1628 if (device
->is_expander_smp_device
)
1629 return "Enclosure SMP ";
1631 return scsi_device_type(device
->devtype
);
1634 #define PQI_DEV_INFO_BUFFER_LENGTH 128
1636 static void pqi_dev_info(struct pqi_ctrl_info
*ctrl_info
,
1637 char *action
, struct pqi_scsi_dev
*device
)
1640 char buffer
[PQI_DEV_INFO_BUFFER_LENGTH
];
1642 count
= snprintf(buffer
, PQI_DEV_INFO_BUFFER_LENGTH
,
1643 "%d:%d:", ctrl_info
->scsi_host
->host_no
, device
->bus
);
1645 if (device
->target_lun_valid
)
1646 count
+= snprintf(buffer
+ count
,
1647 PQI_DEV_INFO_BUFFER_LENGTH
- count
,
1652 count
+= snprintf(buffer
+ count
,
1653 PQI_DEV_INFO_BUFFER_LENGTH
- count
,
1656 if (pqi_is_logical_device(device
))
1657 count
+= snprintf(buffer
+ count
,
1658 PQI_DEV_INFO_BUFFER_LENGTH
- count
,
1660 *((u32
*)&device
->scsi3addr
),
1661 *((u32
*)&device
->scsi3addr
[4]));
1663 count
+= snprintf(buffer
+ count
,
1664 PQI_DEV_INFO_BUFFER_LENGTH
- count
,
1665 " %016llx", device
->sas_address
);
1667 count
+= snprintf(buffer
+ count
, PQI_DEV_INFO_BUFFER_LENGTH
- count
,
1669 pqi_device_type(device
),
1673 if (pqi_is_logical_device(device
)) {
1674 if (device
->devtype
== TYPE_DISK
)
1675 count
+= snprintf(buffer
+ count
,
1676 PQI_DEV_INFO_BUFFER_LENGTH
- count
,
1677 "SSDSmartPathCap%c En%c %-12s",
1678 device
->raid_bypass_configured
? '+' : '-',
1679 device
->raid_bypass_enabled
? '+' : '-',
1680 pqi_raid_level_to_string(device
->raid_level
));
1682 count
+= snprintf(buffer
+ count
,
1683 PQI_DEV_INFO_BUFFER_LENGTH
- count
,
1684 "AIO%c", device
->aio_enabled
? '+' : '-');
1685 if (device
->devtype
== TYPE_DISK
||
1686 device
->devtype
== TYPE_ZBC
)
1687 count
+= snprintf(buffer
+ count
,
1688 PQI_DEV_INFO_BUFFER_LENGTH
- count
,
1689 " qd=%-6d", device
->queue_depth
);
1692 dev_info(&ctrl_info
->pci_dev
->dev
, "%s %s\n", action
, buffer
);
1695 /* Assumes the SCSI device list lock is held. */
1697 static void pqi_scsi_update_device(struct pqi_scsi_dev
*existing_device
,
1698 struct pqi_scsi_dev
*new_device
)
1700 existing_device
->devtype
= new_device
->devtype
;
1701 existing_device
->device_type
= new_device
->device_type
;
1702 existing_device
->bus
= new_device
->bus
;
1703 if (new_device
->target_lun_valid
) {
1704 existing_device
->target
= new_device
->target
;
1705 existing_device
->lun
= new_device
->lun
;
1706 existing_device
->target_lun_valid
= true;
1709 /* By definition, the scsi3addr and wwid fields are already the same. */
1711 existing_device
->is_physical_device
= new_device
->is_physical_device
;
1712 existing_device
->is_external_raid_device
=
1713 new_device
->is_external_raid_device
;
1714 existing_device
->is_expander_smp_device
=
1715 new_device
->is_expander_smp_device
;
1716 existing_device
->aio_enabled
= new_device
->aio_enabled
;
1717 memcpy(existing_device
->vendor
, new_device
->vendor
,
1718 sizeof(existing_device
->vendor
));
1719 memcpy(existing_device
->model
, new_device
->model
,
1720 sizeof(existing_device
->model
));
1721 existing_device
->sas_address
= new_device
->sas_address
;
1722 existing_device
->raid_level
= new_device
->raid_level
;
1723 existing_device
->queue_depth
= new_device
->queue_depth
;
1724 existing_device
->aio_handle
= new_device
->aio_handle
;
1725 existing_device
->volume_status
= new_device
->volume_status
;
1726 existing_device
->active_path_index
= new_device
->active_path_index
;
1727 existing_device
->path_map
= new_device
->path_map
;
1728 existing_device
->bay
= new_device
->bay
;
1729 memcpy(existing_device
->box
, new_device
->box
,
1730 sizeof(existing_device
->box
));
1731 memcpy(existing_device
->phys_connector
, new_device
->phys_connector
,
1732 sizeof(existing_device
->phys_connector
));
1733 existing_device
->offload_to_mirror
= 0;
1734 kfree(existing_device
->raid_map
);
1735 existing_device
->raid_map
= new_device
->raid_map
;
1736 existing_device
->raid_bypass_configured
=
1737 new_device
->raid_bypass_configured
;
1738 existing_device
->raid_bypass_enabled
=
1739 new_device
->raid_bypass_enabled
;
1740 existing_device
->device_offline
= false;
1742 /* To prevent this from being freed later. */
1743 new_device
->raid_map
= NULL
;
1746 static inline void pqi_free_device(struct pqi_scsi_dev
*device
)
1749 kfree(device
->raid_map
);
1755 * Called when exposing a new device to the OS fails in order to re-adjust
1756 * our internal SCSI device list to match the SCSI ML's view.
1759 static inline void pqi_fixup_botched_add(struct pqi_ctrl_info
*ctrl_info
,
1760 struct pqi_scsi_dev
*device
)
1762 unsigned long flags
;
1764 spin_lock_irqsave(&ctrl_info
->scsi_device_list_lock
, flags
);
1765 list_del(&device
->scsi_device_list_entry
);
1766 spin_unlock_irqrestore(&ctrl_info
->scsi_device_list_lock
, flags
);
1768 /* Allow the device structure to be freed later. */
1769 device
->keep_device
= false;
1772 static inline bool pqi_is_device_added(struct pqi_scsi_dev
*device
)
1774 if (device
->is_expander_smp_device
)
1775 return device
->sas_port
!= NULL
;
1777 return device
->sdev
!= NULL
;
1780 static void pqi_update_device_list(struct pqi_ctrl_info
*ctrl_info
,
1781 struct pqi_scsi_dev
*new_device_list
[], unsigned int num_new_devices
)
1785 unsigned long flags
;
1786 enum pqi_find_result find_result
;
1787 struct pqi_scsi_dev
*device
;
1788 struct pqi_scsi_dev
*next
;
1789 struct pqi_scsi_dev
*matching_device
;
1790 LIST_HEAD(add_list
);
1791 LIST_HEAD(delete_list
);
1794 * The idea here is to do as little work as possible while holding the
1795 * spinlock. That's why we go to great pains to defer anything other
1796 * than updating the internal device list until after we release the
1800 spin_lock_irqsave(&ctrl_info
->scsi_device_list_lock
, flags
);
1802 /* Assume that all devices in the existing list have gone away. */
1803 list_for_each_entry(device
, &ctrl_info
->scsi_device_list
,
1804 scsi_device_list_entry
)
1805 device
->device_gone
= true;
1807 for (i
= 0; i
< num_new_devices
; i
++) {
1808 device
= new_device_list
[i
];
1810 find_result
= pqi_scsi_find_entry(ctrl_info
, device
,
1813 switch (find_result
) {
1816 * The newly found device is already in the existing
1819 device
->new_device
= false;
1820 matching_device
->device_gone
= false;
1821 pqi_scsi_update_device(matching_device
, device
);
1823 case DEVICE_NOT_FOUND
:
1825 * The newly found device is NOT in the existing device
1828 device
->new_device
= true;
1830 case DEVICE_CHANGED
:
1832 * The original device has gone away and we need to add
1835 device
->new_device
= true;
1840 /* Process all devices that have gone away. */
1841 list_for_each_entry_safe(device
, next
, &ctrl_info
->scsi_device_list
,
1842 scsi_device_list_entry
) {
1843 if (device
->device_gone
) {
1844 list_del(&device
->scsi_device_list_entry
);
1845 list_add_tail(&device
->delete_list_entry
, &delete_list
);
1849 /* Process all new devices. */
1850 for (i
= 0; i
< num_new_devices
; i
++) {
1851 device
= new_device_list
[i
];
1852 if (!device
->new_device
)
1854 if (device
->volume_offline
)
1856 list_add_tail(&device
->scsi_device_list_entry
,
1857 &ctrl_info
->scsi_device_list
);
1858 list_add_tail(&device
->add_list_entry
, &add_list
);
1859 /* To prevent this device structure from being freed later. */
1860 device
->keep_device
= true;
1863 spin_unlock_irqrestore(&ctrl_info
->scsi_device_list_lock
, flags
);
1865 if (pqi_ctrl_in_ofa(ctrl_info
))
1866 pqi_ctrl_ofa_done(ctrl_info
);
1868 /* Remove all devices that have gone away. */
1869 list_for_each_entry_safe(device
, next
, &delete_list
,
1870 delete_list_entry
) {
1871 if (device
->volume_offline
) {
1872 pqi_dev_info(ctrl_info
, "offline", device
);
1873 pqi_show_volume_status(ctrl_info
, device
);
1875 pqi_dev_info(ctrl_info
, "removed", device
);
1877 if (pqi_is_device_added(device
))
1878 pqi_remove_device(ctrl_info
, device
);
1879 list_del(&device
->delete_list_entry
);
1880 pqi_free_device(device
);
1884 * Notify the SCSI ML if the queue depth of any existing device has
1887 list_for_each_entry(device
, &ctrl_info
->scsi_device_list
,
1888 scsi_device_list_entry
) {
1889 if (device
->sdev
&& device
->queue_depth
!=
1890 device
->advertised_queue_depth
) {
1891 device
->advertised_queue_depth
= device
->queue_depth
;
1892 scsi_change_queue_depth(device
->sdev
,
1893 device
->advertised_queue_depth
);
1897 /* Expose any new devices. */
1898 list_for_each_entry_safe(device
, next
, &add_list
, add_list_entry
) {
1899 if (!pqi_is_device_added(device
)) {
1900 pqi_dev_info(ctrl_info
, "added", device
);
1901 rc
= pqi_add_device(ctrl_info
, device
);
1903 dev_warn(&ctrl_info
->pci_dev
->dev
,
1904 "scsi %d:%d:%d:%d addition failed, device not added\n",
1905 ctrl_info
->scsi_host
->host_no
,
1906 device
->bus
, device
->target
,
1908 pqi_fixup_botched_add(ctrl_info
, device
);
1914 static bool pqi_is_supported_device(struct pqi_scsi_dev
*device
)
1918 if (device
->is_expander_smp_device
)
1921 is_supported
= false;
1923 switch (device
->devtype
) {
1927 case TYPE_MEDIUM_CHANGER
:
1928 case TYPE_ENCLOSURE
:
1929 is_supported
= true;
1933 * Only support the HBA controller itself as a RAID
1934 * controller. If it's a RAID controller other than
1935 * the HBA itself (an external RAID controller, for
1936 * example), we don't support it.
1938 if (pqi_is_hba_lunid(device
->scsi3addr
))
1939 is_supported
= true;
1943 return is_supported
;
1946 static inline bool pqi_skip_device(u8
*scsi3addr
)
1948 /* Ignore all masked devices. */
1949 if (MASKED_DEVICE(scsi3addr
))
1955 static inline bool pqi_is_device_with_sas_address(struct pqi_scsi_dev
*device
)
1957 if (!device
->is_physical_device
)
1960 if (device
->is_expander_smp_device
)
1963 switch (device
->devtype
) {
1966 case TYPE_ENCLOSURE
:
1973 static inline bool pqi_expose_device(struct pqi_scsi_dev
*device
)
1975 return !device
->is_physical_device
||
1976 !pqi_skip_device(device
->scsi3addr
);
1979 static int pqi_update_scsi_devices(struct pqi_ctrl_info
*ctrl_info
)
1983 LIST_HEAD(new_device_list_head
);
1984 struct report_phys_lun_extended
*physdev_list
= NULL
;
1985 struct report_log_lun_extended
*logdev_list
= NULL
;
1986 struct report_phys_lun_extended_entry
*phys_lun_ext_entry
;
1987 struct report_log_lun_extended_entry
*log_lun_ext_entry
;
1988 struct bmic_identify_physical_device
*id_phys
= NULL
;
1991 struct pqi_scsi_dev
**new_device_list
= NULL
;
1992 struct pqi_scsi_dev
*device
;
1993 struct pqi_scsi_dev
*next
;
1994 unsigned int num_new_devices
;
1995 unsigned int num_valid_devices
;
1996 bool is_physical_device
;
1998 static char *out_of_memory_msg
=
1999 "failed to allocate memory, device discovery stopped";
2001 rc
= pqi_get_device_lists(ctrl_info
, &physdev_list
, &logdev_list
);
2007 get_unaligned_be32(&physdev_list
->header
.list_length
)
2008 / sizeof(physdev_list
->lun_entries
[0]);
2014 get_unaligned_be32(&logdev_list
->header
.list_length
)
2015 / sizeof(logdev_list
->lun_entries
[0]);
2019 if (num_physicals
) {
2021 * We need this buffer for calls to pqi_get_physical_disk_info()
2022 * below. We allocate it here instead of inside
2023 * pqi_get_physical_disk_info() because it's a fairly large
2026 id_phys
= kmalloc(sizeof(*id_phys
), GFP_KERNEL
);
2028 dev_warn(&ctrl_info
->pci_dev
->dev
, "%s\n",
2035 num_new_devices
= num_physicals
+ num_logicals
;
2037 new_device_list
= kmalloc_array(num_new_devices
,
2038 sizeof(*new_device_list
),
2040 if (!new_device_list
) {
2041 dev_warn(&ctrl_info
->pci_dev
->dev
, "%s\n", out_of_memory_msg
);
2046 for (i
= 0; i
< num_new_devices
; i
++) {
2047 device
= kzalloc(sizeof(*device
), GFP_KERNEL
);
2049 dev_warn(&ctrl_info
->pci_dev
->dev
, "%s\n",
2054 list_add_tail(&device
->new_device_list_entry
,
2055 &new_device_list_head
);
2059 num_valid_devices
= 0;
2061 for (i
= 0; i
< num_new_devices
; i
++) {
2063 if (i
< num_physicals
) {
2064 is_physical_device
= true;
2065 phys_lun_ext_entry
= &physdev_list
->lun_entries
[i
];
2066 log_lun_ext_entry
= NULL
;
2067 scsi3addr
= phys_lun_ext_entry
->lunid
;
2069 is_physical_device
= false;
2070 phys_lun_ext_entry
= NULL
;
2072 &logdev_list
->lun_entries
[i
- num_physicals
];
2073 scsi3addr
= log_lun_ext_entry
->lunid
;
2076 if (is_physical_device
&& pqi_skip_device(scsi3addr
))
2080 device
= list_next_entry(device
, new_device_list_entry
);
2082 device
= list_first_entry(&new_device_list_head
,
2083 struct pqi_scsi_dev
, new_device_list_entry
);
2085 memcpy(device
->scsi3addr
, scsi3addr
, sizeof(device
->scsi3addr
));
2086 device
->is_physical_device
= is_physical_device
;
2087 if (is_physical_device
) {
2088 if (phys_lun_ext_entry
->device_type
==
2089 SA_EXPANDER_SMP_DEVICE
)
2090 device
->is_expander_smp_device
= true;
2092 device
->is_external_raid_device
=
2093 pqi_is_external_raid_addr(scsi3addr
);
2096 /* Gather information about the device. */
2097 rc
= pqi_get_device_info(ctrl_info
, device
);
2098 if (rc
== -ENOMEM
) {
2099 dev_warn(&ctrl_info
->pci_dev
->dev
, "%s\n",
2104 if (device
->is_physical_device
)
2105 dev_warn(&ctrl_info
->pci_dev
->dev
,
2106 "obtaining device info failed, skipping physical device %016llx\n",
2108 &phys_lun_ext_entry
->wwid
));
2110 dev_warn(&ctrl_info
->pci_dev
->dev
,
2111 "obtaining device info failed, skipping logical device %08x%08x\n",
2112 *((u32
*)&device
->scsi3addr
),
2113 *((u32
*)&device
->scsi3addr
[4]));
2118 if (!pqi_is_supported_device(device
))
2121 pqi_assign_bus_target_lun(device
);
2123 if (device
->is_physical_device
) {
2124 device
->wwid
= phys_lun_ext_entry
->wwid
;
2125 if ((phys_lun_ext_entry
->device_flags
&
2126 REPORT_PHYS_LUN_DEV_FLAG_AIO_ENABLED
) &&
2127 phys_lun_ext_entry
->aio_handle
) {
2128 device
->aio_enabled
= true;
2129 device
->aio_handle
=
2130 phys_lun_ext_entry
->aio_handle
;
2132 if (device
->devtype
== TYPE_DISK
||
2133 device
->devtype
== TYPE_ZBC
) {
2134 pqi_get_physical_disk_info(ctrl_info
,
2138 memcpy(device
->volume_id
, log_lun_ext_entry
->volume_id
,
2139 sizeof(device
->volume_id
));
2142 if (pqi_is_device_with_sas_address(device
))
2143 device
->sas_address
= get_unaligned_be64(&device
->wwid
);
2145 new_device_list
[num_valid_devices
++] = device
;
2148 pqi_update_device_list(ctrl_info
, new_device_list
, num_valid_devices
);
2151 list_for_each_entry_safe(device
, next
, &new_device_list_head
,
2152 new_device_list_entry
) {
2153 if (device
->keep_device
)
2155 list_del(&device
->new_device_list_entry
);
2156 pqi_free_device(device
);
2159 kfree(new_device_list
);
2160 kfree(physdev_list
);
2167 static void pqi_remove_all_scsi_devices(struct pqi_ctrl_info
*ctrl_info
)
2169 unsigned long flags
;
2170 struct pqi_scsi_dev
*device
;
2173 spin_lock_irqsave(&ctrl_info
->scsi_device_list_lock
, flags
);
2175 device
= list_first_entry_or_null(&ctrl_info
->scsi_device_list
,
2176 struct pqi_scsi_dev
, scsi_device_list_entry
);
2178 list_del(&device
->scsi_device_list_entry
);
2180 spin_unlock_irqrestore(&ctrl_info
->scsi_device_list_lock
,
2186 if (pqi_is_device_added(device
))
2187 pqi_remove_device(ctrl_info
, device
);
2188 pqi_free_device(device
);
2192 static int pqi_scan_scsi_devices(struct pqi_ctrl_info
*ctrl_info
)
2196 if (pqi_ctrl_offline(ctrl_info
))
2199 mutex_lock(&ctrl_info
->scan_mutex
);
2201 rc
= pqi_update_scsi_devices(ctrl_info
);
2203 pqi_schedule_rescan_worker_delayed(ctrl_info
);
2205 mutex_unlock(&ctrl_info
->scan_mutex
);
2210 static void pqi_scan_start(struct Scsi_Host
*shost
)
2212 struct pqi_ctrl_info
*ctrl_info
;
2214 ctrl_info
= shost_to_hba(shost
);
2215 if (pqi_ctrl_in_ofa(ctrl_info
))
2218 pqi_scan_scsi_devices(ctrl_info
);
2221 /* Returns TRUE if scan is finished. */
2223 static int pqi_scan_finished(struct Scsi_Host
*shost
,
2224 unsigned long elapsed_time
)
2226 struct pqi_ctrl_info
*ctrl_info
;
2228 ctrl_info
= shost_priv(shost
);
2230 return !mutex_is_locked(&ctrl_info
->scan_mutex
);
2233 static void pqi_wait_until_scan_finished(struct pqi_ctrl_info
*ctrl_info
)
2235 mutex_lock(&ctrl_info
->scan_mutex
);
2236 mutex_unlock(&ctrl_info
->scan_mutex
);
2239 static void pqi_wait_until_lun_reset_finished(struct pqi_ctrl_info
*ctrl_info
)
2241 mutex_lock(&ctrl_info
->lun_reset_mutex
);
2242 mutex_unlock(&ctrl_info
->lun_reset_mutex
);
2245 static void pqi_wait_until_ofa_finished(struct pqi_ctrl_info
*ctrl_info
)
2247 mutex_lock(&ctrl_info
->ofa_mutex
);
2248 mutex_unlock(&ctrl_info
->ofa_mutex
);
2251 static inline void pqi_set_encryption_info(
2252 struct pqi_encryption_info
*encryption_info
, struct raid_map
*raid_map
,
2255 u32 volume_blk_size
;
2258 * Set the encryption tweak values based on logical block address.
2259 * If the block size is 512, the tweak value is equal to the LBA.
2260 * For other block sizes, tweak value is (LBA * block size) / 512.
2262 volume_blk_size
= get_unaligned_le32(&raid_map
->volume_blk_size
);
2263 if (volume_blk_size
!= 512)
2264 first_block
= (first_block
* volume_blk_size
) / 512;
2266 encryption_info
->data_encryption_key_index
=
2267 get_unaligned_le16(&raid_map
->data_encryption_key_index
);
2268 encryption_info
->encrypt_tweak_lower
= lower_32_bits(first_block
);
2269 encryption_info
->encrypt_tweak_upper
= upper_32_bits(first_block
);
2273 * Attempt to perform RAID bypass mapping for a logical volume I/O.
2276 #define PQI_RAID_BYPASS_INELIGIBLE 1
2278 static int pqi_raid_bypass_submit_scsi_cmd(struct pqi_ctrl_info
*ctrl_info
,
2279 struct pqi_scsi_dev
*device
, struct scsi_cmnd
*scmd
,
2280 struct pqi_queue_group
*queue_group
)
2282 struct raid_map
*raid_map
;
2283 bool is_write
= false;
2291 u32 first_row_offset
;
2292 u32 last_row_offset
;
2297 u32 r5or6_blocks_per_row
;
2298 u64 r5or6_first_row
;
2300 u32 r5or6_first_row_offset
;
2301 u32 r5or6_last_row_offset
;
2302 u32 r5or6_first_column
;
2303 u32 r5or6_last_column
;
2304 u16 data_disks_per_row
;
2305 u32 total_disks_per_row
;
2306 u16 layout_map_count
;
2318 int offload_to_mirror
;
2319 struct pqi_encryption_info
*encryption_info_ptr
;
2320 struct pqi_encryption_info encryption_info
;
2321 #if BITS_PER_LONG == 32
2325 /* Check for valid opcode, get LBA and block count. */
2326 switch (scmd
->cmnd
[0]) {
2331 first_block
= (u64
)(((scmd
->cmnd
[1] & 0x1f) << 16) |
2332 (scmd
->cmnd
[2] << 8) | scmd
->cmnd
[3]);
2333 block_cnt
= (u32
)scmd
->cmnd
[4];
2341 first_block
= (u64
)get_unaligned_be32(&scmd
->cmnd
[2]);
2342 block_cnt
= (u32
)get_unaligned_be16(&scmd
->cmnd
[7]);
2348 first_block
= (u64
)get_unaligned_be32(&scmd
->cmnd
[2]);
2349 block_cnt
= get_unaligned_be32(&scmd
->cmnd
[6]);
2355 first_block
= get_unaligned_be64(&scmd
->cmnd
[2]);
2356 block_cnt
= get_unaligned_be32(&scmd
->cmnd
[10]);
2359 /* Process via normal I/O path. */
2360 return PQI_RAID_BYPASS_INELIGIBLE
;
2363 /* Check for write to non-RAID-0. */
2364 if (is_write
&& device
->raid_level
!= SA_RAID_0
)
2365 return PQI_RAID_BYPASS_INELIGIBLE
;
2367 if (unlikely(block_cnt
== 0))
2368 return PQI_RAID_BYPASS_INELIGIBLE
;
2370 last_block
= first_block
+ block_cnt
- 1;
2371 raid_map
= device
->raid_map
;
2373 /* Check for invalid block or wraparound. */
2374 if (last_block
>= get_unaligned_le64(&raid_map
->volume_blk_cnt
) ||
2375 last_block
< first_block
)
2376 return PQI_RAID_BYPASS_INELIGIBLE
;
2378 data_disks_per_row
= get_unaligned_le16(&raid_map
->data_disks_per_row
);
2379 strip_size
= get_unaligned_le16(&raid_map
->strip_size
);
2380 layout_map_count
= get_unaligned_le16(&raid_map
->layout_map_count
);
2382 /* Calculate stripe information for the request. */
2383 blocks_per_row
= data_disks_per_row
* strip_size
;
2384 #if BITS_PER_LONG == 32
2385 tmpdiv
= first_block
;
2386 do_div(tmpdiv
, blocks_per_row
);
2388 tmpdiv
= last_block
;
2389 do_div(tmpdiv
, blocks_per_row
);
2391 first_row_offset
= (u32
)(first_block
- (first_row
* blocks_per_row
));
2392 last_row_offset
= (u32
)(last_block
- (last_row
* blocks_per_row
));
2393 tmpdiv
= first_row_offset
;
2394 do_div(tmpdiv
, strip_size
);
2395 first_column
= tmpdiv
;
2396 tmpdiv
= last_row_offset
;
2397 do_div(tmpdiv
, strip_size
);
2398 last_column
= tmpdiv
;
2400 first_row
= first_block
/ blocks_per_row
;
2401 last_row
= last_block
/ blocks_per_row
;
2402 first_row_offset
= (u32
)(first_block
- (first_row
* blocks_per_row
));
2403 last_row_offset
= (u32
)(last_block
- (last_row
* blocks_per_row
));
2404 first_column
= first_row_offset
/ strip_size
;
2405 last_column
= last_row_offset
/ strip_size
;
2408 /* If this isn't a single row/column then give to the controller. */
2409 if (first_row
!= last_row
|| first_column
!= last_column
)
2410 return PQI_RAID_BYPASS_INELIGIBLE
;
2412 /* Proceeding with driver mapping. */
2413 total_disks_per_row
= data_disks_per_row
+
2414 get_unaligned_le16(&raid_map
->metadata_disks_per_row
);
2415 map_row
= ((u32
)(first_row
>> raid_map
->parity_rotation_shift
)) %
2416 get_unaligned_le16(&raid_map
->row_cnt
);
2417 map_index
= (map_row
* total_disks_per_row
) + first_column
;
2420 if (device
->raid_level
== SA_RAID_1
) {
2421 if (device
->offload_to_mirror
)
2422 map_index
+= data_disks_per_row
;
2423 device
->offload_to_mirror
= !device
->offload_to_mirror
;
2424 } else if (device
->raid_level
== SA_RAID_ADM
) {
2427 * Handles N-way mirrors (R1-ADM) and R10 with # of drives
2430 offload_to_mirror
= device
->offload_to_mirror
;
2431 if (offload_to_mirror
== 0) {
2432 /* use physical disk in the first mirrored group. */
2433 map_index
%= data_disks_per_row
;
2437 * Determine mirror group that map_index
2440 current_group
= map_index
/ data_disks_per_row
;
2442 if (offload_to_mirror
!= current_group
) {
2444 layout_map_count
- 1) {
2446 * Select raid index from
2449 map_index
+= data_disks_per_row
;
2453 * Select raid index from first
2456 map_index
%= data_disks_per_row
;
2460 } while (offload_to_mirror
!= current_group
);
2463 /* Set mirror group to use next time. */
2465 (offload_to_mirror
>= layout_map_count
- 1) ?
2466 0 : offload_to_mirror
+ 1;
2467 WARN_ON(offload_to_mirror
>= layout_map_count
);
2468 device
->offload_to_mirror
= offload_to_mirror
;
2470 * Avoid direct use of device->offload_to_mirror within this
2471 * function since multiple threads might simultaneously
2472 * increment it beyond the range of device->layout_map_count -1.
2474 } else if ((device
->raid_level
== SA_RAID_5
||
2475 device
->raid_level
== SA_RAID_6
) && layout_map_count
> 1) {
2477 /* Verify first and last block are in same RAID group */
2478 r5or6_blocks_per_row
= strip_size
* data_disks_per_row
;
2479 stripesize
= r5or6_blocks_per_row
* layout_map_count
;
2480 #if BITS_PER_LONG == 32
2481 tmpdiv
= first_block
;
2482 first_group
= do_div(tmpdiv
, stripesize
);
2483 tmpdiv
= first_group
;
2484 do_div(tmpdiv
, r5or6_blocks_per_row
);
2485 first_group
= tmpdiv
;
2486 tmpdiv
= last_block
;
2487 last_group
= do_div(tmpdiv
, stripesize
);
2488 tmpdiv
= last_group
;
2489 do_div(tmpdiv
, r5or6_blocks_per_row
);
2490 last_group
= tmpdiv
;
2492 first_group
= (first_block
% stripesize
) / r5or6_blocks_per_row
;
2493 last_group
= (last_block
% stripesize
) / r5or6_blocks_per_row
;
2495 if (first_group
!= last_group
)
2496 return PQI_RAID_BYPASS_INELIGIBLE
;
2498 /* Verify request is in a single row of RAID 5/6 */
2499 #if BITS_PER_LONG == 32
2500 tmpdiv
= first_block
;
2501 do_div(tmpdiv
, stripesize
);
2502 first_row
= r5or6_first_row
= r0_first_row
= tmpdiv
;
2503 tmpdiv
= last_block
;
2504 do_div(tmpdiv
, stripesize
);
2505 r5or6_last_row
= r0_last_row
= tmpdiv
;
2507 first_row
= r5or6_first_row
= r0_first_row
=
2508 first_block
/ stripesize
;
2509 r5or6_last_row
= r0_last_row
= last_block
/ stripesize
;
2511 if (r5or6_first_row
!= r5or6_last_row
)
2512 return PQI_RAID_BYPASS_INELIGIBLE
;
2514 /* Verify request is in a single column */
2515 #if BITS_PER_LONG == 32
2516 tmpdiv
= first_block
;
2517 first_row_offset
= do_div(tmpdiv
, stripesize
);
2518 tmpdiv
= first_row_offset
;
2519 first_row_offset
= (u32
)do_div(tmpdiv
, r5or6_blocks_per_row
);
2520 r5or6_first_row_offset
= first_row_offset
;
2521 tmpdiv
= last_block
;
2522 r5or6_last_row_offset
= do_div(tmpdiv
, stripesize
);
2523 tmpdiv
= r5or6_last_row_offset
;
2524 r5or6_last_row_offset
= do_div(tmpdiv
, r5or6_blocks_per_row
);
2525 tmpdiv
= r5or6_first_row_offset
;
2526 do_div(tmpdiv
, strip_size
);
2527 first_column
= r5or6_first_column
= tmpdiv
;
2528 tmpdiv
= r5or6_last_row_offset
;
2529 do_div(tmpdiv
, strip_size
);
2530 r5or6_last_column
= tmpdiv
;
2532 first_row_offset
= r5or6_first_row_offset
=
2533 (u32
)((first_block
% stripesize
) %
2534 r5or6_blocks_per_row
);
2536 r5or6_last_row_offset
=
2537 (u32
)((last_block
% stripesize
) %
2538 r5or6_blocks_per_row
);
2540 first_column
= r5or6_first_row_offset
/ strip_size
;
2541 r5or6_first_column
= first_column
;
2542 r5or6_last_column
= r5or6_last_row_offset
/ strip_size
;
2544 if (r5or6_first_column
!= r5or6_last_column
)
2545 return PQI_RAID_BYPASS_INELIGIBLE
;
2547 /* Request is eligible */
2549 ((u32
)(first_row
>> raid_map
->parity_rotation_shift
)) %
2550 get_unaligned_le16(&raid_map
->row_cnt
);
2552 map_index
= (first_group
*
2553 (get_unaligned_le16(&raid_map
->row_cnt
) *
2554 total_disks_per_row
)) +
2555 (map_row
* total_disks_per_row
) + first_column
;
2558 aio_handle
= raid_map
->disk_data
[map_index
].aio_handle
;
2559 disk_block
= get_unaligned_le64(&raid_map
->disk_starting_blk
) +
2560 first_row
* strip_size
+
2561 (first_row_offset
- first_column
* strip_size
);
2562 disk_block_cnt
= block_cnt
;
2564 /* Handle differing logical/physical block sizes. */
2565 if (raid_map
->phys_blk_shift
) {
2566 disk_block
<<= raid_map
->phys_blk_shift
;
2567 disk_block_cnt
<<= raid_map
->phys_blk_shift
;
2570 if (unlikely(disk_block_cnt
> 0xffff))
2571 return PQI_RAID_BYPASS_INELIGIBLE
;
2573 /* Build the new CDB for the physical disk I/O. */
2574 if (disk_block
> 0xffffffff) {
2575 cdb
[0] = is_write
? WRITE_16
: READ_16
;
2577 put_unaligned_be64(disk_block
, &cdb
[2]);
2578 put_unaligned_be32(disk_block_cnt
, &cdb
[10]);
2583 cdb
[0] = is_write
? WRITE_10
: READ_10
;
2585 put_unaligned_be32((u32
)disk_block
, &cdb
[2]);
2587 put_unaligned_be16((u16
)disk_block_cnt
, &cdb
[7]);
2592 if (get_unaligned_le16(&raid_map
->flags
) &
2593 RAID_MAP_ENCRYPTION_ENABLED
) {
2594 pqi_set_encryption_info(&encryption_info
, raid_map
,
2596 encryption_info_ptr
= &encryption_info
;
2598 encryption_info_ptr
= NULL
;
2601 return pqi_aio_submit_io(ctrl_info
, scmd
, aio_handle
,
2602 cdb
, cdb_length
, queue_group
, encryption_info_ptr
, true);
2605 #define PQI_STATUS_IDLE 0x0
2607 #define PQI_CREATE_ADMIN_QUEUE_PAIR 1
2608 #define PQI_DELETE_ADMIN_QUEUE_PAIR 2
2610 #define PQI_DEVICE_STATE_POWER_ON_AND_RESET 0x0
2611 #define PQI_DEVICE_STATE_STATUS_AVAILABLE 0x1
2612 #define PQI_DEVICE_STATE_ALL_REGISTERS_READY 0x2
2613 #define PQI_DEVICE_STATE_ADMIN_QUEUE_PAIR_READY 0x3
2614 #define PQI_DEVICE_STATE_ERROR 0x4
2616 #define PQI_MODE_READY_TIMEOUT_SECS 30
2617 #define PQI_MODE_READY_POLL_INTERVAL_MSECS 1
2619 static int pqi_wait_for_pqi_mode_ready(struct pqi_ctrl_info
*ctrl_info
)
2621 struct pqi_device_registers __iomem
*pqi_registers
;
2622 unsigned long timeout
;
2626 pqi_registers
= ctrl_info
->pqi_registers
;
2627 timeout
= (PQI_MODE_READY_TIMEOUT_SECS
* PQI_HZ
) + jiffies
;
2630 signature
= readq(&pqi_registers
->signature
);
2631 if (memcmp(&signature
, PQI_DEVICE_SIGNATURE
,
2632 sizeof(signature
)) == 0)
2634 if (time_after(jiffies
, timeout
)) {
2635 dev_err(&ctrl_info
->pci_dev
->dev
,
2636 "timed out waiting for PQI signature\n");
2639 msleep(PQI_MODE_READY_POLL_INTERVAL_MSECS
);
2643 status
= readb(&pqi_registers
->function_and_status_code
);
2644 if (status
== PQI_STATUS_IDLE
)
2646 if (time_after(jiffies
, timeout
)) {
2647 dev_err(&ctrl_info
->pci_dev
->dev
,
2648 "timed out waiting for PQI IDLE\n");
2651 msleep(PQI_MODE_READY_POLL_INTERVAL_MSECS
);
2655 if (readl(&pqi_registers
->device_status
) ==
2656 PQI_DEVICE_STATE_ALL_REGISTERS_READY
)
2658 if (time_after(jiffies
, timeout
)) {
2659 dev_err(&ctrl_info
->pci_dev
->dev
,
2660 "timed out waiting for PQI all registers ready\n");
2663 msleep(PQI_MODE_READY_POLL_INTERVAL_MSECS
);
2669 static inline void pqi_aio_path_disabled(struct pqi_io_request
*io_request
)
2671 struct pqi_scsi_dev
*device
;
2673 device
= io_request
->scmd
->device
->hostdata
;
2674 device
->raid_bypass_enabled
= false;
2675 device
->aio_enabled
= false;
2678 static inline void pqi_take_device_offline(struct scsi_device
*sdev
, char *path
)
2680 struct pqi_ctrl_info
*ctrl_info
;
2681 struct pqi_scsi_dev
*device
;
2683 device
= sdev
->hostdata
;
2684 if (device
->device_offline
)
2687 device
->device_offline
= true;
2688 ctrl_info
= shost_to_hba(sdev
->host
);
2689 pqi_schedule_rescan_worker(ctrl_info
);
2690 dev_err(&ctrl_info
->pci_dev
->dev
, "re-scanning %s scsi %d:%d:%d:%d\n",
2691 path
, ctrl_info
->scsi_host
->host_no
, device
->bus
,
2692 device
->target
, device
->lun
);
2695 static void pqi_process_raid_io_error(struct pqi_io_request
*io_request
)
2699 struct scsi_cmnd
*scmd
;
2700 struct pqi_raid_error_info
*error_info
;
2701 size_t sense_data_length
;
2704 struct scsi_sense_hdr sshdr
;
2706 scmd
= io_request
->scmd
;
2710 error_info
= io_request
->error_info
;
2711 scsi_status
= error_info
->status
;
2714 switch (error_info
->data_out_result
) {
2715 case PQI_DATA_IN_OUT_GOOD
:
2717 case PQI_DATA_IN_OUT_UNDERFLOW
:
2719 get_unaligned_le32(&error_info
->data_out_transferred
);
2720 residual_count
= scsi_bufflen(scmd
) - xfer_count
;
2721 scsi_set_resid(scmd
, residual_count
);
2722 if (xfer_count
< scmd
->underflow
)
2723 host_byte
= DID_SOFT_ERROR
;
2725 case PQI_DATA_IN_OUT_UNSOLICITED_ABORT
:
2726 case PQI_DATA_IN_OUT_ABORTED
:
2727 host_byte
= DID_ABORT
;
2729 case PQI_DATA_IN_OUT_TIMEOUT
:
2730 host_byte
= DID_TIME_OUT
;
2732 case PQI_DATA_IN_OUT_BUFFER_OVERFLOW
:
2733 case PQI_DATA_IN_OUT_PROTOCOL_ERROR
:
2734 case PQI_DATA_IN_OUT_BUFFER_ERROR
:
2735 case PQI_DATA_IN_OUT_BUFFER_OVERFLOW_DESCRIPTOR_AREA
:
2736 case PQI_DATA_IN_OUT_BUFFER_OVERFLOW_BRIDGE
:
2737 case PQI_DATA_IN_OUT_ERROR
:
2738 case PQI_DATA_IN_OUT_HARDWARE_ERROR
:
2739 case PQI_DATA_IN_OUT_PCIE_FABRIC_ERROR
:
2740 case PQI_DATA_IN_OUT_PCIE_COMPLETION_TIMEOUT
:
2741 case PQI_DATA_IN_OUT_PCIE_COMPLETER_ABORT_RECEIVED
:
2742 case PQI_DATA_IN_OUT_PCIE_UNSUPPORTED_REQUEST_RECEIVED
:
2743 case PQI_DATA_IN_OUT_PCIE_ECRC_CHECK_FAILED
:
2744 case PQI_DATA_IN_OUT_PCIE_UNSUPPORTED_REQUEST
:
2745 case PQI_DATA_IN_OUT_PCIE_ACS_VIOLATION
:
2746 case PQI_DATA_IN_OUT_PCIE_TLP_PREFIX_BLOCKED
:
2747 case PQI_DATA_IN_OUT_PCIE_POISONED_MEMORY_READ
:
2749 host_byte
= DID_ERROR
;
2753 sense_data_length
= get_unaligned_le16(&error_info
->sense_data_length
);
2754 if (sense_data_length
== 0)
2756 get_unaligned_le16(&error_info
->response_data_length
);
2757 if (sense_data_length
) {
2758 if (sense_data_length
> sizeof(error_info
->data
))
2759 sense_data_length
= sizeof(error_info
->data
);
2761 if (scsi_status
== SAM_STAT_CHECK_CONDITION
&&
2762 scsi_normalize_sense(error_info
->data
,
2763 sense_data_length
, &sshdr
) &&
2764 sshdr
.sense_key
== HARDWARE_ERROR
&&
2765 sshdr
.asc
== 0x3e &&
2766 sshdr
.ascq
== 0x1) {
2767 pqi_take_device_offline(scmd
->device
, "RAID");
2768 host_byte
= DID_NO_CONNECT
;
2771 if (sense_data_length
> SCSI_SENSE_BUFFERSIZE
)
2772 sense_data_length
= SCSI_SENSE_BUFFERSIZE
;
2773 memcpy(scmd
->sense_buffer
, error_info
->data
,
2777 scmd
->result
= scsi_status
;
2778 set_host_byte(scmd
, host_byte
);
2781 static void pqi_process_aio_io_error(struct pqi_io_request
*io_request
)
2785 struct scsi_cmnd
*scmd
;
2786 struct pqi_aio_error_info
*error_info
;
2787 size_t sense_data_length
;
2790 bool device_offline
;
2792 scmd
= io_request
->scmd
;
2793 error_info
= io_request
->error_info
;
2795 sense_data_length
= 0;
2796 device_offline
= false;
2798 switch (error_info
->service_response
) {
2799 case PQI_AIO_SERV_RESPONSE_COMPLETE
:
2800 scsi_status
= error_info
->status
;
2802 case PQI_AIO_SERV_RESPONSE_FAILURE
:
2803 switch (error_info
->status
) {
2804 case PQI_AIO_STATUS_IO_ABORTED
:
2805 scsi_status
= SAM_STAT_TASK_ABORTED
;
2807 case PQI_AIO_STATUS_UNDERRUN
:
2808 scsi_status
= SAM_STAT_GOOD
;
2809 residual_count
= get_unaligned_le32(
2810 &error_info
->residual_count
);
2811 scsi_set_resid(scmd
, residual_count
);
2812 xfer_count
= scsi_bufflen(scmd
) - residual_count
;
2813 if (xfer_count
< scmd
->underflow
)
2814 host_byte
= DID_SOFT_ERROR
;
2816 case PQI_AIO_STATUS_OVERRUN
:
2817 scsi_status
= SAM_STAT_GOOD
;
2819 case PQI_AIO_STATUS_AIO_PATH_DISABLED
:
2820 pqi_aio_path_disabled(io_request
);
2821 scsi_status
= SAM_STAT_GOOD
;
2822 io_request
->status
= -EAGAIN
;
2824 case PQI_AIO_STATUS_NO_PATH_TO_DEVICE
:
2825 case PQI_AIO_STATUS_INVALID_DEVICE
:
2826 if (!io_request
->raid_bypass
) {
2827 device_offline
= true;
2828 pqi_take_device_offline(scmd
->device
, "AIO");
2829 host_byte
= DID_NO_CONNECT
;
2831 scsi_status
= SAM_STAT_CHECK_CONDITION
;
2833 case PQI_AIO_STATUS_IO_ERROR
:
2835 scsi_status
= SAM_STAT_CHECK_CONDITION
;
2839 case PQI_AIO_SERV_RESPONSE_TMF_COMPLETE
:
2840 case PQI_AIO_SERV_RESPONSE_TMF_SUCCEEDED
:
2841 scsi_status
= SAM_STAT_GOOD
;
2843 case PQI_AIO_SERV_RESPONSE_TMF_REJECTED
:
2844 case PQI_AIO_SERV_RESPONSE_TMF_INCORRECT_LUN
:
2846 scsi_status
= SAM_STAT_CHECK_CONDITION
;
2850 if (error_info
->data_present
) {
2852 get_unaligned_le16(&error_info
->data_length
);
2853 if (sense_data_length
) {
2854 if (sense_data_length
> sizeof(error_info
->data
))
2855 sense_data_length
= sizeof(error_info
->data
);
2856 if (sense_data_length
> SCSI_SENSE_BUFFERSIZE
)
2857 sense_data_length
= SCSI_SENSE_BUFFERSIZE
;
2858 memcpy(scmd
->sense_buffer
, error_info
->data
,
2863 if (device_offline
&& sense_data_length
== 0)
2864 scsi_build_sense_buffer(0, scmd
->sense_buffer
, HARDWARE_ERROR
,
2867 scmd
->result
= scsi_status
;
2868 set_host_byte(scmd
, host_byte
);
2871 static void pqi_process_io_error(unsigned int iu_type
,
2872 struct pqi_io_request
*io_request
)
2875 case PQI_RESPONSE_IU_RAID_PATH_IO_ERROR
:
2876 pqi_process_raid_io_error(io_request
);
2878 case PQI_RESPONSE_IU_AIO_PATH_IO_ERROR
:
2879 pqi_process_aio_io_error(io_request
);
2884 static int pqi_interpret_task_management_response(
2885 struct pqi_task_management_response
*response
)
2889 switch (response
->response_code
) {
2890 case SOP_TMF_COMPLETE
:
2891 case SOP_TMF_FUNCTION_SUCCEEDED
:
2894 case SOP_TMF_REJECTED
:
2905 static unsigned int pqi_process_io_intr(struct pqi_ctrl_info
*ctrl_info
,
2906 struct pqi_queue_group
*queue_group
)
2908 unsigned int num_responses
;
2911 struct pqi_io_request
*io_request
;
2912 struct pqi_io_response
*response
;
2916 oq_ci
= queue_group
->oq_ci_copy
;
2919 oq_pi
= readl(queue_group
->oq_pi
);
2924 response
= queue_group
->oq_element_array
+
2925 (oq_ci
* PQI_OPERATIONAL_OQ_ELEMENT_LENGTH
);
2927 request_id
= get_unaligned_le16(&response
->request_id
);
2928 WARN_ON(request_id
>= ctrl_info
->max_io_slots
);
2930 io_request
= &ctrl_info
->io_request_pool
[request_id
];
2931 WARN_ON(atomic_read(&io_request
->refcount
) == 0);
2933 switch (response
->header
.iu_type
) {
2934 case PQI_RESPONSE_IU_RAID_PATH_IO_SUCCESS
:
2935 case PQI_RESPONSE_IU_AIO_PATH_IO_SUCCESS
:
2936 if (io_request
->scmd
)
2937 io_request
->scmd
->result
= 0;
2939 case PQI_RESPONSE_IU_GENERAL_MANAGEMENT
:
2941 case PQI_RESPONSE_IU_VENDOR_GENERAL
:
2942 io_request
->status
=
2944 &((struct pqi_vendor_general_response
*)
2947 case PQI_RESPONSE_IU_TASK_MANAGEMENT
:
2948 io_request
->status
=
2949 pqi_interpret_task_management_response(
2952 case PQI_RESPONSE_IU_AIO_PATH_DISABLED
:
2953 pqi_aio_path_disabled(io_request
);
2954 io_request
->status
= -EAGAIN
;
2956 case PQI_RESPONSE_IU_RAID_PATH_IO_ERROR
:
2957 case PQI_RESPONSE_IU_AIO_PATH_IO_ERROR
:
2958 io_request
->error_info
= ctrl_info
->error_buffer
+
2959 (get_unaligned_le16(&response
->error_index
) *
2960 PQI_ERROR_BUFFER_ELEMENT_LENGTH
);
2961 pqi_process_io_error(response
->header
.iu_type
,
2965 dev_err(&ctrl_info
->pci_dev
->dev
,
2966 "unexpected IU type: 0x%x\n",
2967 response
->header
.iu_type
);
2971 io_request
->io_complete_callback(io_request
,
2972 io_request
->context
);
2975 * Note that the I/O request structure CANNOT BE TOUCHED after
2976 * returning from the I/O completion callback!
2979 oq_ci
= (oq_ci
+ 1) % ctrl_info
->num_elements_per_oq
;
2982 if (num_responses
) {
2983 queue_group
->oq_ci_copy
= oq_ci
;
2984 writel(oq_ci
, queue_group
->oq_ci
);
2987 return num_responses
;
2990 static inline unsigned int pqi_num_elements_free(unsigned int pi
,
2991 unsigned int ci
, unsigned int elements_in_queue
)
2993 unsigned int num_elements_used
;
2996 num_elements_used
= pi
- ci
;
2998 num_elements_used
= elements_in_queue
- ci
+ pi
;
3000 return elements_in_queue
- num_elements_used
- 1;
3003 static void pqi_send_event_ack(struct pqi_ctrl_info
*ctrl_info
,
3004 struct pqi_event_acknowledge_request
*iu
, size_t iu_length
)
3008 unsigned long flags
;
3010 struct pqi_queue_group
*queue_group
;
3012 queue_group
= &ctrl_info
->queue_groups
[PQI_DEFAULT_QUEUE_GROUP
];
3013 put_unaligned_le16(queue_group
->oq_id
, &iu
->header
.response_queue_id
);
3016 spin_lock_irqsave(&queue_group
->submit_lock
[RAID_PATH
], flags
);
3018 iq_pi
= queue_group
->iq_pi_copy
[RAID_PATH
];
3019 iq_ci
= readl(queue_group
->iq_ci
[RAID_PATH
]);
3021 if (pqi_num_elements_free(iq_pi
, iq_ci
,
3022 ctrl_info
->num_elements_per_iq
))
3025 spin_unlock_irqrestore(
3026 &queue_group
->submit_lock
[RAID_PATH
], flags
);
3028 if (pqi_ctrl_offline(ctrl_info
))
3032 next_element
= queue_group
->iq_element_array
[RAID_PATH
] +
3033 (iq_pi
* PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
);
3035 memcpy(next_element
, iu
, iu_length
);
3037 iq_pi
= (iq_pi
+ 1) % ctrl_info
->num_elements_per_iq
;
3038 queue_group
->iq_pi_copy
[RAID_PATH
] = iq_pi
;
3041 * This write notifies the controller that an IU is available to be
3044 writel(iq_pi
, queue_group
->iq_pi
[RAID_PATH
]);
3046 spin_unlock_irqrestore(&queue_group
->submit_lock
[RAID_PATH
], flags
);
3049 static void pqi_acknowledge_event(struct pqi_ctrl_info
*ctrl_info
,
3050 struct pqi_event
*event
)
3052 struct pqi_event_acknowledge_request request
;
3054 memset(&request
, 0, sizeof(request
));
3056 request
.header
.iu_type
= PQI_REQUEST_IU_ACKNOWLEDGE_VENDOR_EVENT
;
3057 put_unaligned_le16(sizeof(request
) - PQI_REQUEST_HEADER_LENGTH
,
3058 &request
.header
.iu_length
);
3059 request
.event_type
= event
->event_type
;
3060 request
.event_id
= event
->event_id
;
3061 request
.additional_event_id
= event
->additional_event_id
;
3063 pqi_send_event_ack(ctrl_info
, &request
, sizeof(request
));
3066 #define PQI_SOFT_RESET_STATUS_TIMEOUT_SECS 30
3067 #define PQI_SOFT_RESET_STATUS_POLL_INTERVAL_SECS 1
3069 static enum pqi_soft_reset_status
pqi_poll_for_soft_reset_status(
3070 struct pqi_ctrl_info
*ctrl_info
)
3072 unsigned long timeout
;
3075 timeout
= (PQI_SOFT_RESET_STATUS_TIMEOUT_SECS
* PQI_HZ
) + jiffies
;
3078 status
= pqi_read_soft_reset_status(ctrl_info
);
3079 if (status
& PQI_SOFT_RESET_INITIATE
)
3080 return RESET_INITIATE_DRIVER
;
3082 if (status
& PQI_SOFT_RESET_ABORT
)
3085 if (time_after(jiffies
, timeout
)) {
3086 dev_err(&ctrl_info
->pci_dev
->dev
,
3087 "timed out waiting for soft reset status\n");
3088 return RESET_TIMEDOUT
;
3091 if (!sis_is_firmware_running(ctrl_info
))
3092 return RESET_NORESPONSE
;
3094 ssleep(PQI_SOFT_RESET_STATUS_POLL_INTERVAL_SECS
);
3098 static void pqi_process_soft_reset(struct pqi_ctrl_info
*ctrl_info
,
3099 enum pqi_soft_reset_status reset_status
)
3103 switch (reset_status
) {
3104 case RESET_INITIATE_DRIVER
:
3106 case RESET_TIMEDOUT
:
3107 dev_info(&ctrl_info
->pci_dev
->dev
,
3108 "resetting controller %u\n", ctrl_info
->ctrl_id
);
3109 sis_soft_reset(ctrl_info
);
3111 case RESET_INITIATE_FIRMWARE
:
3112 rc
= pqi_ofa_ctrl_restart(ctrl_info
);
3113 pqi_ofa_free_host_buffer(ctrl_info
);
3114 dev_info(&ctrl_info
->pci_dev
->dev
,
3115 "Online Firmware Activation for controller %u: %s\n",
3116 ctrl_info
->ctrl_id
, rc
== 0 ? "SUCCESS" : "FAILED");
3119 pqi_ofa_ctrl_unquiesce(ctrl_info
);
3120 dev_info(&ctrl_info
->pci_dev
->dev
,
3121 "Online Firmware Activation for controller %u: %s\n",
3122 ctrl_info
->ctrl_id
, "ABORTED");
3124 case RESET_NORESPONSE
:
3125 pqi_ofa_free_host_buffer(ctrl_info
);
3126 pqi_take_ctrl_offline(ctrl_info
);
3131 static void pqi_ofa_process_event(struct pqi_ctrl_info
*ctrl_info
,
3132 struct pqi_event
*event
)
3135 enum pqi_soft_reset_status status
;
3137 event_id
= get_unaligned_le16(&event
->event_id
);
3139 mutex_lock(&ctrl_info
->ofa_mutex
);
3141 if (event_id
== PQI_EVENT_OFA_QUIESCE
) {
3142 dev_info(&ctrl_info
->pci_dev
->dev
,
3143 "Received Online Firmware Activation quiesce event for controller %u\n",
3144 ctrl_info
->ctrl_id
);
3145 pqi_ofa_ctrl_quiesce(ctrl_info
);
3146 pqi_acknowledge_event(ctrl_info
, event
);
3147 if (ctrl_info
->soft_reset_handshake_supported
) {
3148 status
= pqi_poll_for_soft_reset_status(ctrl_info
);
3149 pqi_process_soft_reset(ctrl_info
, status
);
3151 pqi_process_soft_reset(ctrl_info
,
3152 RESET_INITIATE_FIRMWARE
);
3155 } else if (event_id
== PQI_EVENT_OFA_MEMORY_ALLOCATION
) {
3156 pqi_acknowledge_event(ctrl_info
, event
);
3157 pqi_ofa_setup_host_buffer(ctrl_info
,
3158 le32_to_cpu(event
->ofa_bytes_requested
));
3159 pqi_ofa_host_memory_update(ctrl_info
);
3160 } else if (event_id
== PQI_EVENT_OFA_CANCELLED
) {
3161 pqi_ofa_free_host_buffer(ctrl_info
);
3162 pqi_acknowledge_event(ctrl_info
, event
);
3163 dev_info(&ctrl_info
->pci_dev
->dev
,
3164 "Online Firmware Activation(%u) cancel reason : %u\n",
3165 ctrl_info
->ctrl_id
, event
->ofa_cancel_reason
);
3168 mutex_unlock(&ctrl_info
->ofa_mutex
);
3171 static void pqi_event_worker(struct work_struct
*work
)
3174 struct pqi_ctrl_info
*ctrl_info
;
3175 struct pqi_event
*event
;
3177 ctrl_info
= container_of(work
, struct pqi_ctrl_info
, event_work
);
3179 pqi_ctrl_busy(ctrl_info
);
3180 pqi_wait_if_ctrl_blocked(ctrl_info
, NO_TIMEOUT
);
3181 if (pqi_ctrl_offline(ctrl_info
))
3184 pqi_schedule_rescan_worker_delayed(ctrl_info
);
3186 event
= ctrl_info
->events
;
3187 for (i
= 0; i
< PQI_NUM_SUPPORTED_EVENTS
; i
++) {
3188 if (event
->pending
) {
3189 event
->pending
= false;
3190 if (event
->event_type
== PQI_EVENT_TYPE_OFA
) {
3191 pqi_ctrl_unbusy(ctrl_info
);
3192 pqi_ofa_process_event(ctrl_info
, event
);
3195 pqi_acknowledge_event(ctrl_info
, event
);
3201 pqi_ctrl_unbusy(ctrl_info
);
3204 #define PQI_HEARTBEAT_TIMER_INTERVAL (10 * PQI_HZ)
3206 static void pqi_heartbeat_timer_handler(struct timer_list
*t
)
3209 u32 heartbeat_count
;
3210 struct pqi_ctrl_info
*ctrl_info
= from_timer(ctrl_info
, t
,
3213 pqi_check_ctrl_health(ctrl_info
);
3214 if (pqi_ctrl_offline(ctrl_info
))
3217 num_interrupts
= atomic_read(&ctrl_info
->num_interrupts
);
3218 heartbeat_count
= pqi_read_heartbeat_counter(ctrl_info
);
3220 if (num_interrupts
== ctrl_info
->previous_num_interrupts
) {
3221 if (heartbeat_count
== ctrl_info
->previous_heartbeat_count
) {
3222 dev_err(&ctrl_info
->pci_dev
->dev
,
3223 "no heartbeat detected - last heartbeat count: %u\n",
3225 pqi_take_ctrl_offline(ctrl_info
);
3229 ctrl_info
->previous_num_interrupts
= num_interrupts
;
3232 ctrl_info
->previous_heartbeat_count
= heartbeat_count
;
3233 mod_timer(&ctrl_info
->heartbeat_timer
,
3234 jiffies
+ PQI_HEARTBEAT_TIMER_INTERVAL
);
3237 static void pqi_start_heartbeat_timer(struct pqi_ctrl_info
*ctrl_info
)
3239 if (!ctrl_info
->heartbeat_counter
)
3242 ctrl_info
->previous_num_interrupts
=
3243 atomic_read(&ctrl_info
->num_interrupts
);
3244 ctrl_info
->previous_heartbeat_count
=
3245 pqi_read_heartbeat_counter(ctrl_info
);
3247 ctrl_info
->heartbeat_timer
.expires
=
3248 jiffies
+ PQI_HEARTBEAT_TIMER_INTERVAL
;
3249 add_timer(&ctrl_info
->heartbeat_timer
);
3252 static inline void pqi_stop_heartbeat_timer(struct pqi_ctrl_info
*ctrl_info
)
3254 del_timer_sync(&ctrl_info
->heartbeat_timer
);
3257 static inline int pqi_event_type_to_event_index(unsigned int event_type
)
3261 for (index
= 0; index
< ARRAY_SIZE(pqi_supported_event_types
); index
++)
3262 if (event_type
== pqi_supported_event_types
[index
])
3268 static inline bool pqi_is_supported_event(unsigned int event_type
)
3270 return pqi_event_type_to_event_index(event_type
) != -1;
3273 static void pqi_ofa_capture_event_payload(struct pqi_event
*event
,
3274 struct pqi_event_response
*response
)
3278 event_id
= get_unaligned_le16(&event
->event_id
);
3280 if (event
->event_type
== PQI_EVENT_TYPE_OFA
) {
3281 if (event_id
== PQI_EVENT_OFA_MEMORY_ALLOCATION
) {
3282 event
->ofa_bytes_requested
=
3283 response
->data
.ofa_memory_allocation
.bytes_requested
;
3284 } else if (event_id
== PQI_EVENT_OFA_CANCELLED
) {
3285 event
->ofa_cancel_reason
=
3286 response
->data
.ofa_cancelled
.reason
;
3291 static unsigned int pqi_process_event_intr(struct pqi_ctrl_info
*ctrl_info
)
3293 unsigned int num_events
;
3296 struct pqi_event_queue
*event_queue
;
3297 struct pqi_event_response
*response
;
3298 struct pqi_event
*event
;
3301 event_queue
= &ctrl_info
->event_queue
;
3303 oq_ci
= event_queue
->oq_ci_copy
;
3306 oq_pi
= readl(event_queue
->oq_pi
);
3311 response
= event_queue
->oq_element_array
+
3312 (oq_ci
* PQI_EVENT_OQ_ELEMENT_LENGTH
);
3315 pqi_event_type_to_event_index(response
->event_type
);
3317 if (event_index
>= 0) {
3318 if (response
->request_acknowlege
) {
3319 event
= &ctrl_info
->events
[event_index
];
3320 event
->pending
= true;
3321 event
->event_type
= response
->event_type
;
3322 event
->event_id
= response
->event_id
;
3323 event
->additional_event_id
=
3324 response
->additional_event_id
;
3325 pqi_ofa_capture_event_payload(event
, response
);
3329 oq_ci
= (oq_ci
+ 1) % PQI_NUM_EVENT_QUEUE_ELEMENTS
;
3333 event_queue
->oq_ci_copy
= oq_ci
;
3334 writel(oq_ci
, event_queue
->oq_ci
);
3335 schedule_work(&ctrl_info
->event_work
);
3341 #define PQI_LEGACY_INTX_MASK 0x1
3343 static inline void pqi_configure_legacy_intx(struct pqi_ctrl_info
*ctrl_info
,
3347 struct pqi_device_registers __iomem
*pqi_registers
;
3348 volatile void __iomem
*register_addr
;
3350 pqi_registers
= ctrl_info
->pqi_registers
;
3353 register_addr
= &pqi_registers
->legacy_intx_mask_clear
;
3355 register_addr
= &pqi_registers
->legacy_intx_mask_set
;
3357 intx_mask
= readl(register_addr
);
3358 intx_mask
|= PQI_LEGACY_INTX_MASK
;
3359 writel(intx_mask
, register_addr
);
3362 static void pqi_change_irq_mode(struct pqi_ctrl_info
*ctrl_info
,
3363 enum pqi_irq_mode new_mode
)
3365 switch (ctrl_info
->irq_mode
) {
3371 pqi_configure_legacy_intx(ctrl_info
, true);
3372 sis_enable_intx(ctrl_info
);
3381 pqi_configure_legacy_intx(ctrl_info
, false);
3382 sis_enable_msix(ctrl_info
);
3387 pqi_configure_legacy_intx(ctrl_info
, false);
3394 sis_enable_msix(ctrl_info
);
3397 pqi_configure_legacy_intx(ctrl_info
, true);
3398 sis_enable_intx(ctrl_info
);
3406 ctrl_info
->irq_mode
= new_mode
;
3409 #define PQI_LEGACY_INTX_PENDING 0x1
3411 static inline bool pqi_is_valid_irq(struct pqi_ctrl_info
*ctrl_info
)
3416 switch (ctrl_info
->irq_mode
) {
3422 readl(&ctrl_info
->pqi_registers
->legacy_intx_status
);
3423 if (intx_status
& PQI_LEGACY_INTX_PENDING
)
3437 static irqreturn_t
pqi_irq_handler(int irq
, void *data
)
3439 struct pqi_ctrl_info
*ctrl_info
;
3440 struct pqi_queue_group
*queue_group
;
3441 unsigned int num_responses_handled
;
3444 ctrl_info
= queue_group
->ctrl_info
;
3446 if (!pqi_is_valid_irq(ctrl_info
))
3449 num_responses_handled
= pqi_process_io_intr(ctrl_info
, queue_group
);
3451 if (irq
== ctrl_info
->event_irq
)
3452 num_responses_handled
+= pqi_process_event_intr(ctrl_info
);
3454 if (num_responses_handled
)
3455 atomic_inc(&ctrl_info
->num_interrupts
);
3457 pqi_start_io(ctrl_info
, queue_group
, RAID_PATH
, NULL
);
3458 pqi_start_io(ctrl_info
, queue_group
, AIO_PATH
, NULL
);
3463 static int pqi_request_irqs(struct pqi_ctrl_info
*ctrl_info
)
3465 struct pci_dev
*pci_dev
= ctrl_info
->pci_dev
;
3469 ctrl_info
->event_irq
= pci_irq_vector(pci_dev
, 0);
3471 for (i
= 0; i
< ctrl_info
->num_msix_vectors_enabled
; i
++) {
3472 rc
= request_irq(pci_irq_vector(pci_dev
, i
), pqi_irq_handler
, 0,
3473 DRIVER_NAME_SHORT
, &ctrl_info
->queue_groups
[i
]);
3475 dev_err(&pci_dev
->dev
,
3476 "irq %u init failed with error %d\n",
3477 pci_irq_vector(pci_dev
, i
), rc
);
3480 ctrl_info
->num_msix_vectors_initialized
++;
3486 static void pqi_free_irqs(struct pqi_ctrl_info
*ctrl_info
)
3490 for (i
= 0; i
< ctrl_info
->num_msix_vectors_initialized
; i
++)
3491 free_irq(pci_irq_vector(ctrl_info
->pci_dev
, i
),
3492 &ctrl_info
->queue_groups
[i
]);
3494 ctrl_info
->num_msix_vectors_initialized
= 0;
3497 static int pqi_enable_msix_interrupts(struct pqi_ctrl_info
*ctrl_info
)
3499 int num_vectors_enabled
;
3501 num_vectors_enabled
= pci_alloc_irq_vectors(ctrl_info
->pci_dev
,
3502 PQI_MIN_MSIX_VECTORS
, ctrl_info
->num_queue_groups
,
3503 PCI_IRQ_MSIX
| PCI_IRQ_AFFINITY
);
3504 if (num_vectors_enabled
< 0) {
3505 dev_err(&ctrl_info
->pci_dev
->dev
,
3506 "MSI-X init failed with error %d\n",
3507 num_vectors_enabled
);
3508 return num_vectors_enabled
;
3511 ctrl_info
->num_msix_vectors_enabled
= num_vectors_enabled
;
3512 ctrl_info
->irq_mode
= IRQ_MODE_MSIX
;
3516 static void pqi_disable_msix_interrupts(struct pqi_ctrl_info
*ctrl_info
)
3518 if (ctrl_info
->num_msix_vectors_enabled
) {
3519 pci_free_irq_vectors(ctrl_info
->pci_dev
);
3520 ctrl_info
->num_msix_vectors_enabled
= 0;
3524 static int pqi_alloc_operational_queues(struct pqi_ctrl_info
*ctrl_info
)
3527 size_t alloc_length
;
3528 size_t element_array_length_per_iq
;
3529 size_t element_array_length_per_oq
;
3530 void *element_array
;
3531 void __iomem
*next_queue_index
;
3532 void *aligned_pointer
;
3533 unsigned int num_inbound_queues
;
3534 unsigned int num_outbound_queues
;
3535 unsigned int num_queue_indexes
;
3536 struct pqi_queue_group
*queue_group
;
3538 element_array_length_per_iq
=
3539 PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
*
3540 ctrl_info
->num_elements_per_iq
;
3541 element_array_length_per_oq
=
3542 PQI_OPERATIONAL_OQ_ELEMENT_LENGTH
*
3543 ctrl_info
->num_elements_per_oq
;
3544 num_inbound_queues
= ctrl_info
->num_queue_groups
* 2;
3545 num_outbound_queues
= ctrl_info
->num_queue_groups
;
3546 num_queue_indexes
= (ctrl_info
->num_queue_groups
* 3) + 1;
3548 aligned_pointer
= NULL
;
3550 for (i
= 0; i
< num_inbound_queues
; i
++) {
3551 aligned_pointer
= PTR_ALIGN(aligned_pointer
,
3552 PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT
);
3553 aligned_pointer
+= element_array_length_per_iq
;
3556 for (i
= 0; i
< num_outbound_queues
; i
++) {
3557 aligned_pointer
= PTR_ALIGN(aligned_pointer
,
3558 PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT
);
3559 aligned_pointer
+= element_array_length_per_oq
;
3562 aligned_pointer
= PTR_ALIGN(aligned_pointer
,
3563 PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT
);
3564 aligned_pointer
+= PQI_NUM_EVENT_QUEUE_ELEMENTS
*
3565 PQI_EVENT_OQ_ELEMENT_LENGTH
;
3567 for (i
= 0; i
< num_queue_indexes
; i
++) {
3568 aligned_pointer
= PTR_ALIGN(aligned_pointer
,
3569 PQI_OPERATIONAL_INDEX_ALIGNMENT
);
3570 aligned_pointer
+= sizeof(pqi_index_t
);
3573 alloc_length
= (size_t)aligned_pointer
+
3574 PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT
;
3576 alloc_length
+= PQI_EXTRA_SGL_MEMORY
;
3578 ctrl_info
->queue_memory_base
=
3579 dma_alloc_coherent(&ctrl_info
->pci_dev
->dev
, alloc_length
,
3580 &ctrl_info
->queue_memory_base_dma_handle
,
3583 if (!ctrl_info
->queue_memory_base
)
3586 ctrl_info
->queue_memory_length
= alloc_length
;
3588 element_array
= PTR_ALIGN(ctrl_info
->queue_memory_base
,
3589 PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT
);
3591 for (i
= 0; i
< ctrl_info
->num_queue_groups
; i
++) {
3592 queue_group
= &ctrl_info
->queue_groups
[i
];
3593 queue_group
->iq_element_array
[RAID_PATH
] = element_array
;
3594 queue_group
->iq_element_array_bus_addr
[RAID_PATH
] =
3595 ctrl_info
->queue_memory_base_dma_handle
+
3596 (element_array
- ctrl_info
->queue_memory_base
);
3597 element_array
+= element_array_length_per_iq
;
3598 element_array
= PTR_ALIGN(element_array
,
3599 PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT
);
3600 queue_group
->iq_element_array
[AIO_PATH
] = element_array
;
3601 queue_group
->iq_element_array_bus_addr
[AIO_PATH
] =
3602 ctrl_info
->queue_memory_base_dma_handle
+
3603 (element_array
- ctrl_info
->queue_memory_base
);
3604 element_array
+= element_array_length_per_iq
;
3605 element_array
= PTR_ALIGN(element_array
,
3606 PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT
);
3609 for (i
= 0; i
< ctrl_info
->num_queue_groups
; i
++) {
3610 queue_group
= &ctrl_info
->queue_groups
[i
];
3611 queue_group
->oq_element_array
= element_array
;
3612 queue_group
->oq_element_array_bus_addr
=
3613 ctrl_info
->queue_memory_base_dma_handle
+
3614 (element_array
- ctrl_info
->queue_memory_base
);
3615 element_array
+= element_array_length_per_oq
;
3616 element_array
= PTR_ALIGN(element_array
,
3617 PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT
);
3620 ctrl_info
->event_queue
.oq_element_array
= element_array
;
3621 ctrl_info
->event_queue
.oq_element_array_bus_addr
=
3622 ctrl_info
->queue_memory_base_dma_handle
+
3623 (element_array
- ctrl_info
->queue_memory_base
);
3624 element_array
+= PQI_NUM_EVENT_QUEUE_ELEMENTS
*
3625 PQI_EVENT_OQ_ELEMENT_LENGTH
;
3627 next_queue_index
= (void __iomem
*)PTR_ALIGN(element_array
,
3628 PQI_OPERATIONAL_INDEX_ALIGNMENT
);
3630 for (i
= 0; i
< ctrl_info
->num_queue_groups
; i
++) {
3631 queue_group
= &ctrl_info
->queue_groups
[i
];
3632 queue_group
->iq_ci
[RAID_PATH
] = next_queue_index
;
3633 queue_group
->iq_ci_bus_addr
[RAID_PATH
] =
3634 ctrl_info
->queue_memory_base_dma_handle
+
3636 (void __iomem
*)ctrl_info
->queue_memory_base
);
3637 next_queue_index
+= sizeof(pqi_index_t
);
3638 next_queue_index
= PTR_ALIGN(next_queue_index
,
3639 PQI_OPERATIONAL_INDEX_ALIGNMENT
);
3640 queue_group
->iq_ci
[AIO_PATH
] = next_queue_index
;
3641 queue_group
->iq_ci_bus_addr
[AIO_PATH
] =
3642 ctrl_info
->queue_memory_base_dma_handle
+
3644 (void __iomem
*)ctrl_info
->queue_memory_base
);
3645 next_queue_index
+= sizeof(pqi_index_t
);
3646 next_queue_index
= PTR_ALIGN(next_queue_index
,
3647 PQI_OPERATIONAL_INDEX_ALIGNMENT
);
3648 queue_group
->oq_pi
= next_queue_index
;
3649 queue_group
->oq_pi_bus_addr
=
3650 ctrl_info
->queue_memory_base_dma_handle
+
3652 (void __iomem
*)ctrl_info
->queue_memory_base
);
3653 next_queue_index
+= sizeof(pqi_index_t
);
3654 next_queue_index
= PTR_ALIGN(next_queue_index
,
3655 PQI_OPERATIONAL_INDEX_ALIGNMENT
);
3658 ctrl_info
->event_queue
.oq_pi
= next_queue_index
;
3659 ctrl_info
->event_queue
.oq_pi_bus_addr
=
3660 ctrl_info
->queue_memory_base_dma_handle
+
3662 (void __iomem
*)ctrl_info
->queue_memory_base
);
3667 static void pqi_init_operational_queues(struct pqi_ctrl_info
*ctrl_info
)
3670 u16 next_iq_id
= PQI_MIN_OPERATIONAL_QUEUE_ID
;
3671 u16 next_oq_id
= PQI_MIN_OPERATIONAL_QUEUE_ID
;
3674 * Initialize the backpointers to the controller structure in
3675 * each operational queue group structure.
3677 for (i
= 0; i
< ctrl_info
->num_queue_groups
; i
++)
3678 ctrl_info
->queue_groups
[i
].ctrl_info
= ctrl_info
;
3681 * Assign IDs to all operational queues. Note that the IDs
3682 * assigned to operational IQs are independent of the IDs
3683 * assigned to operational OQs.
3685 ctrl_info
->event_queue
.oq_id
= next_oq_id
++;
3686 for (i
= 0; i
< ctrl_info
->num_queue_groups
; i
++) {
3687 ctrl_info
->queue_groups
[i
].iq_id
[RAID_PATH
] = next_iq_id
++;
3688 ctrl_info
->queue_groups
[i
].iq_id
[AIO_PATH
] = next_iq_id
++;
3689 ctrl_info
->queue_groups
[i
].oq_id
= next_oq_id
++;
3693 * Assign MSI-X table entry indexes to all queues. Note that the
3694 * interrupt for the event queue is shared with the first queue group.
3696 ctrl_info
->event_queue
.int_msg_num
= 0;
3697 for (i
= 0; i
< ctrl_info
->num_queue_groups
; i
++)
3698 ctrl_info
->queue_groups
[i
].int_msg_num
= i
;
3700 for (i
= 0; i
< ctrl_info
->num_queue_groups
; i
++) {
3701 spin_lock_init(&ctrl_info
->queue_groups
[i
].submit_lock
[0]);
3702 spin_lock_init(&ctrl_info
->queue_groups
[i
].submit_lock
[1]);
3703 INIT_LIST_HEAD(&ctrl_info
->queue_groups
[i
].request_list
[0]);
3704 INIT_LIST_HEAD(&ctrl_info
->queue_groups
[i
].request_list
[1]);
3708 static int pqi_alloc_admin_queues(struct pqi_ctrl_info
*ctrl_info
)
3710 size_t alloc_length
;
3711 struct pqi_admin_queues_aligned
*admin_queues_aligned
;
3712 struct pqi_admin_queues
*admin_queues
;
3714 alloc_length
= sizeof(struct pqi_admin_queues_aligned
) +
3715 PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT
;
3717 ctrl_info
->admin_queue_memory_base
=
3718 dma_alloc_coherent(&ctrl_info
->pci_dev
->dev
, alloc_length
,
3719 &ctrl_info
->admin_queue_memory_base_dma_handle
,
3722 if (!ctrl_info
->admin_queue_memory_base
)
3725 ctrl_info
->admin_queue_memory_length
= alloc_length
;
3727 admin_queues
= &ctrl_info
->admin_queues
;
3728 admin_queues_aligned
= PTR_ALIGN(ctrl_info
->admin_queue_memory_base
,
3729 PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT
);
3730 admin_queues
->iq_element_array
=
3731 &admin_queues_aligned
->iq_element_array
;
3732 admin_queues
->oq_element_array
=
3733 &admin_queues_aligned
->oq_element_array
;
3734 admin_queues
->iq_ci
= &admin_queues_aligned
->iq_ci
;
3735 admin_queues
->oq_pi
=
3736 (pqi_index_t __iomem
*)&admin_queues_aligned
->oq_pi
;
3738 admin_queues
->iq_element_array_bus_addr
=
3739 ctrl_info
->admin_queue_memory_base_dma_handle
+
3740 (admin_queues
->iq_element_array
-
3741 ctrl_info
->admin_queue_memory_base
);
3742 admin_queues
->oq_element_array_bus_addr
=
3743 ctrl_info
->admin_queue_memory_base_dma_handle
+
3744 (admin_queues
->oq_element_array
-
3745 ctrl_info
->admin_queue_memory_base
);
3746 admin_queues
->iq_ci_bus_addr
=
3747 ctrl_info
->admin_queue_memory_base_dma_handle
+
3748 ((void *)admin_queues
->iq_ci
-
3749 ctrl_info
->admin_queue_memory_base
);
3750 admin_queues
->oq_pi_bus_addr
=
3751 ctrl_info
->admin_queue_memory_base_dma_handle
+
3752 ((void __iomem
*)admin_queues
->oq_pi
-
3753 (void __iomem
*)ctrl_info
->admin_queue_memory_base
);
3758 #define PQI_ADMIN_QUEUE_CREATE_TIMEOUT_JIFFIES PQI_HZ
3759 #define PQI_ADMIN_QUEUE_CREATE_POLL_INTERVAL_MSECS 1
3761 static int pqi_create_admin_queues(struct pqi_ctrl_info
*ctrl_info
)
3763 struct pqi_device_registers __iomem
*pqi_registers
;
3764 struct pqi_admin_queues
*admin_queues
;
3765 unsigned long timeout
;
3769 pqi_registers
= ctrl_info
->pqi_registers
;
3770 admin_queues
= &ctrl_info
->admin_queues
;
3772 writeq((u64
)admin_queues
->iq_element_array_bus_addr
,
3773 &pqi_registers
->admin_iq_element_array_addr
);
3774 writeq((u64
)admin_queues
->oq_element_array_bus_addr
,
3775 &pqi_registers
->admin_oq_element_array_addr
);
3776 writeq((u64
)admin_queues
->iq_ci_bus_addr
,
3777 &pqi_registers
->admin_iq_ci_addr
);
3778 writeq((u64
)admin_queues
->oq_pi_bus_addr
,
3779 &pqi_registers
->admin_oq_pi_addr
);
3781 reg
= PQI_ADMIN_IQ_NUM_ELEMENTS
|
3782 (PQI_ADMIN_OQ_NUM_ELEMENTS
) << 8 |
3783 (admin_queues
->int_msg_num
<< 16);
3784 writel(reg
, &pqi_registers
->admin_iq_num_elements
);
3785 writel(PQI_CREATE_ADMIN_QUEUE_PAIR
,
3786 &pqi_registers
->function_and_status_code
);
3788 timeout
= PQI_ADMIN_QUEUE_CREATE_TIMEOUT_JIFFIES
+ jiffies
;
3790 status
= readb(&pqi_registers
->function_and_status_code
);
3791 if (status
== PQI_STATUS_IDLE
)
3793 if (time_after(jiffies
, timeout
))
3795 msleep(PQI_ADMIN_QUEUE_CREATE_POLL_INTERVAL_MSECS
);
3799 * The offset registers are not initialized to the correct
3800 * offsets until *after* the create admin queue pair command
3801 * completes successfully.
3803 admin_queues
->iq_pi
= ctrl_info
->iomem_base
+
3804 PQI_DEVICE_REGISTERS_OFFSET
+
3805 readq(&pqi_registers
->admin_iq_pi_offset
);
3806 admin_queues
->oq_ci
= ctrl_info
->iomem_base
+
3807 PQI_DEVICE_REGISTERS_OFFSET
+
3808 readq(&pqi_registers
->admin_oq_ci_offset
);
3813 static void pqi_submit_admin_request(struct pqi_ctrl_info
*ctrl_info
,
3814 struct pqi_general_admin_request
*request
)
3816 struct pqi_admin_queues
*admin_queues
;
3820 admin_queues
= &ctrl_info
->admin_queues
;
3821 iq_pi
= admin_queues
->iq_pi_copy
;
3823 next_element
= admin_queues
->iq_element_array
+
3824 (iq_pi
* PQI_ADMIN_IQ_ELEMENT_LENGTH
);
3826 memcpy(next_element
, request
, sizeof(*request
));
3828 iq_pi
= (iq_pi
+ 1) % PQI_ADMIN_IQ_NUM_ELEMENTS
;
3829 admin_queues
->iq_pi_copy
= iq_pi
;
3832 * This write notifies the controller that an IU is available to be
3835 writel(iq_pi
, admin_queues
->iq_pi
);
3838 #define PQI_ADMIN_REQUEST_TIMEOUT_SECS 60
3840 static int pqi_poll_for_admin_response(struct pqi_ctrl_info
*ctrl_info
,
3841 struct pqi_general_admin_response
*response
)
3843 struct pqi_admin_queues
*admin_queues
;
3846 unsigned long timeout
;
3848 admin_queues
= &ctrl_info
->admin_queues
;
3849 oq_ci
= admin_queues
->oq_ci_copy
;
3851 timeout
= (PQI_ADMIN_REQUEST_TIMEOUT_SECS
* PQI_HZ
) + jiffies
;
3854 oq_pi
= readl(admin_queues
->oq_pi
);
3857 if (time_after(jiffies
, timeout
)) {
3858 dev_err(&ctrl_info
->pci_dev
->dev
,
3859 "timed out waiting for admin response\n");
3862 if (!sis_is_firmware_running(ctrl_info
))
3864 usleep_range(1000, 2000);
3867 memcpy(response
, admin_queues
->oq_element_array
+
3868 (oq_ci
* PQI_ADMIN_OQ_ELEMENT_LENGTH
), sizeof(*response
));
3870 oq_ci
= (oq_ci
+ 1) % PQI_ADMIN_OQ_NUM_ELEMENTS
;
3871 admin_queues
->oq_ci_copy
= oq_ci
;
3872 writel(oq_ci
, admin_queues
->oq_ci
);
3877 static void pqi_start_io(struct pqi_ctrl_info
*ctrl_info
,
3878 struct pqi_queue_group
*queue_group
, enum pqi_io_path path
,
3879 struct pqi_io_request
*io_request
)
3881 struct pqi_io_request
*next
;
3886 unsigned long flags
;
3887 unsigned int num_elements_needed
;
3888 unsigned int num_elements_to_end_of_queue
;
3890 struct pqi_iu_header
*request
;
3892 spin_lock_irqsave(&queue_group
->submit_lock
[path
], flags
);
3895 io_request
->queue_group
= queue_group
;
3896 list_add_tail(&io_request
->request_list_entry
,
3897 &queue_group
->request_list
[path
]);
3900 iq_pi
= queue_group
->iq_pi_copy
[path
];
3902 list_for_each_entry_safe(io_request
, next
,
3903 &queue_group
->request_list
[path
], request_list_entry
) {
3905 request
= io_request
->iu
;
3907 iu_length
= get_unaligned_le16(&request
->iu_length
) +
3908 PQI_REQUEST_HEADER_LENGTH
;
3909 num_elements_needed
=
3910 DIV_ROUND_UP(iu_length
,
3911 PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
);
3913 iq_ci
= readl(queue_group
->iq_ci
[path
]);
3915 if (num_elements_needed
> pqi_num_elements_free(iq_pi
, iq_ci
,
3916 ctrl_info
->num_elements_per_iq
))
3919 put_unaligned_le16(queue_group
->oq_id
,
3920 &request
->response_queue_id
);
3922 next_element
= queue_group
->iq_element_array
[path
] +
3923 (iq_pi
* PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
);
3925 num_elements_to_end_of_queue
=
3926 ctrl_info
->num_elements_per_iq
- iq_pi
;
3928 if (num_elements_needed
<= num_elements_to_end_of_queue
) {
3929 memcpy(next_element
, request
, iu_length
);
3931 copy_count
= num_elements_to_end_of_queue
*
3932 PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
;
3933 memcpy(next_element
, request
, copy_count
);
3934 memcpy(queue_group
->iq_element_array
[path
],
3935 (u8
*)request
+ copy_count
,
3936 iu_length
- copy_count
);
3939 iq_pi
= (iq_pi
+ num_elements_needed
) %
3940 ctrl_info
->num_elements_per_iq
;
3942 list_del(&io_request
->request_list_entry
);
3945 if (iq_pi
!= queue_group
->iq_pi_copy
[path
]) {
3946 queue_group
->iq_pi_copy
[path
] = iq_pi
;
3948 * This write notifies the controller that one or more IUs are
3949 * available to be processed.
3951 writel(iq_pi
, queue_group
->iq_pi
[path
]);
3954 spin_unlock_irqrestore(&queue_group
->submit_lock
[path
], flags
);
3957 #define PQI_WAIT_FOR_COMPLETION_IO_TIMEOUT_SECS 10
3959 static int pqi_wait_for_completion_io(struct pqi_ctrl_info
*ctrl_info
,
3960 struct completion
*wait
)
3965 if (wait_for_completion_io_timeout(wait
,
3966 PQI_WAIT_FOR_COMPLETION_IO_TIMEOUT_SECS
* PQI_HZ
)) {
3971 pqi_check_ctrl_health(ctrl_info
);
3972 if (pqi_ctrl_offline(ctrl_info
)) {
3981 static void pqi_raid_synchronous_complete(struct pqi_io_request
*io_request
,
3984 struct completion
*waiting
= context
;
3989 static int pqi_process_raid_io_error_synchronous(struct pqi_raid_error_info
3994 switch (error_info
->data_out_result
) {
3995 case PQI_DATA_IN_OUT_GOOD
:
3996 if (error_info
->status
== SAM_STAT_GOOD
)
3999 case PQI_DATA_IN_OUT_UNDERFLOW
:
4000 if (error_info
->status
== SAM_STAT_GOOD
||
4001 error_info
->status
== SAM_STAT_CHECK_CONDITION
)
4004 case PQI_DATA_IN_OUT_ABORTED
:
4005 rc
= PQI_CMD_STATUS_ABORTED
;
4012 static int pqi_submit_raid_request_synchronous(struct pqi_ctrl_info
*ctrl_info
,
4013 struct pqi_iu_header
*request
, unsigned int flags
,
4014 struct pqi_raid_error_info
*error_info
, unsigned long timeout_msecs
)
4017 struct pqi_io_request
*io_request
;
4018 unsigned long start_jiffies
;
4019 unsigned long msecs_blocked
;
4021 DECLARE_COMPLETION_ONSTACK(wait
);
4024 * Note that specifying PQI_SYNC_FLAGS_INTERRUPTABLE and a timeout value
4025 * are mutually exclusive.
4028 if (flags
& PQI_SYNC_FLAGS_INTERRUPTABLE
) {
4029 if (down_interruptible(&ctrl_info
->sync_request_sem
))
4030 return -ERESTARTSYS
;
4032 if (timeout_msecs
== NO_TIMEOUT
) {
4033 down(&ctrl_info
->sync_request_sem
);
4035 start_jiffies
= jiffies
;
4036 if (down_timeout(&ctrl_info
->sync_request_sem
,
4037 msecs_to_jiffies(timeout_msecs
)))
4040 jiffies_to_msecs(jiffies
- start_jiffies
);
4041 if (msecs_blocked
>= timeout_msecs
)
4043 timeout_msecs
-= msecs_blocked
;
4047 pqi_ctrl_busy(ctrl_info
);
4048 timeout_msecs
= pqi_wait_if_ctrl_blocked(ctrl_info
, timeout_msecs
);
4049 if (timeout_msecs
== 0) {
4050 pqi_ctrl_unbusy(ctrl_info
);
4055 if (pqi_ctrl_offline(ctrl_info
)) {
4056 pqi_ctrl_unbusy(ctrl_info
);
4061 io_request
= pqi_alloc_io_request(ctrl_info
);
4063 put_unaligned_le16(io_request
->index
,
4064 &(((struct pqi_raid_path_request
*)request
)->request_id
));
4066 if (request
->iu_type
== PQI_REQUEST_IU_RAID_PATH_IO
)
4067 ((struct pqi_raid_path_request
*)request
)->error_index
=
4068 ((struct pqi_raid_path_request
*)request
)->request_id
;
4070 iu_length
= get_unaligned_le16(&request
->iu_length
) +
4071 PQI_REQUEST_HEADER_LENGTH
;
4072 memcpy(io_request
->iu
, request
, iu_length
);
4074 io_request
->io_complete_callback
= pqi_raid_synchronous_complete
;
4075 io_request
->context
= &wait
;
4077 pqi_start_io(ctrl_info
,
4078 &ctrl_info
->queue_groups
[PQI_DEFAULT_QUEUE_GROUP
], RAID_PATH
,
4081 pqi_ctrl_unbusy(ctrl_info
);
4083 if (timeout_msecs
== NO_TIMEOUT
) {
4084 pqi_wait_for_completion_io(ctrl_info
, &wait
);
4086 if (!wait_for_completion_io_timeout(&wait
,
4087 msecs_to_jiffies(timeout_msecs
))) {
4088 dev_warn(&ctrl_info
->pci_dev
->dev
,
4089 "command timed out\n");
4095 if (io_request
->error_info
)
4096 memcpy(error_info
, io_request
->error_info
,
4097 sizeof(*error_info
));
4099 memset(error_info
, 0, sizeof(*error_info
));
4100 } else if (rc
== 0 && io_request
->error_info
) {
4101 rc
= pqi_process_raid_io_error_synchronous(
4102 io_request
->error_info
);
4105 pqi_free_io_request(io_request
);
4108 up(&ctrl_info
->sync_request_sem
);
4113 static int pqi_validate_admin_response(
4114 struct pqi_general_admin_response
*response
, u8 expected_function_code
)
4116 if (response
->header
.iu_type
!= PQI_RESPONSE_IU_GENERAL_ADMIN
)
4119 if (get_unaligned_le16(&response
->header
.iu_length
) !=
4120 PQI_GENERAL_ADMIN_IU_LENGTH
)
4123 if (response
->function_code
!= expected_function_code
)
4126 if (response
->status
!= PQI_GENERAL_ADMIN_STATUS_SUCCESS
)
4132 static int pqi_submit_admin_request_synchronous(
4133 struct pqi_ctrl_info
*ctrl_info
,
4134 struct pqi_general_admin_request
*request
,
4135 struct pqi_general_admin_response
*response
)
4139 pqi_submit_admin_request(ctrl_info
, request
);
4141 rc
= pqi_poll_for_admin_response(ctrl_info
, response
);
4144 rc
= pqi_validate_admin_response(response
,
4145 request
->function_code
);
4150 static int pqi_report_device_capability(struct pqi_ctrl_info
*ctrl_info
)
4153 struct pqi_general_admin_request request
;
4154 struct pqi_general_admin_response response
;
4155 struct pqi_device_capability
*capability
;
4156 struct pqi_iu_layer_descriptor
*sop_iu_layer_descriptor
;
4158 capability
= kmalloc(sizeof(*capability
), GFP_KERNEL
);
4162 memset(&request
, 0, sizeof(request
));
4164 request
.header
.iu_type
= PQI_REQUEST_IU_GENERAL_ADMIN
;
4165 put_unaligned_le16(PQI_GENERAL_ADMIN_IU_LENGTH
,
4166 &request
.header
.iu_length
);
4167 request
.function_code
=
4168 PQI_GENERAL_ADMIN_FUNCTION_REPORT_DEVICE_CAPABILITY
;
4169 put_unaligned_le32(sizeof(*capability
),
4170 &request
.data
.report_device_capability
.buffer_length
);
4172 rc
= pqi_map_single(ctrl_info
->pci_dev
,
4173 &request
.data
.report_device_capability
.sg_descriptor
,
4174 capability
, sizeof(*capability
),
4179 rc
= pqi_submit_admin_request_synchronous(ctrl_info
, &request
,
4182 pqi_pci_unmap(ctrl_info
->pci_dev
,
4183 &request
.data
.report_device_capability
.sg_descriptor
, 1,
4189 if (response
.status
!= PQI_GENERAL_ADMIN_STATUS_SUCCESS
) {
4194 ctrl_info
->max_inbound_queues
=
4195 get_unaligned_le16(&capability
->max_inbound_queues
);
4196 ctrl_info
->max_elements_per_iq
=
4197 get_unaligned_le16(&capability
->max_elements_per_iq
);
4198 ctrl_info
->max_iq_element_length
=
4199 get_unaligned_le16(&capability
->max_iq_element_length
)
4201 ctrl_info
->max_outbound_queues
=
4202 get_unaligned_le16(&capability
->max_outbound_queues
);
4203 ctrl_info
->max_elements_per_oq
=
4204 get_unaligned_le16(&capability
->max_elements_per_oq
);
4205 ctrl_info
->max_oq_element_length
=
4206 get_unaligned_le16(&capability
->max_oq_element_length
)
4209 sop_iu_layer_descriptor
=
4210 &capability
->iu_layer_descriptors
[PQI_PROTOCOL_SOP
];
4212 ctrl_info
->max_inbound_iu_length_per_firmware
=
4214 &sop_iu_layer_descriptor
->max_inbound_iu_length
);
4215 ctrl_info
->inbound_spanning_supported
=
4216 sop_iu_layer_descriptor
->inbound_spanning_supported
;
4217 ctrl_info
->outbound_spanning_supported
=
4218 sop_iu_layer_descriptor
->outbound_spanning_supported
;
4226 static int pqi_validate_device_capability(struct pqi_ctrl_info
*ctrl_info
)
4228 if (ctrl_info
->max_iq_element_length
<
4229 PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
) {
4230 dev_err(&ctrl_info
->pci_dev
->dev
,
4231 "max. inbound queue element length of %d is less than the required length of %d\n",
4232 ctrl_info
->max_iq_element_length
,
4233 PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
);
4237 if (ctrl_info
->max_oq_element_length
<
4238 PQI_OPERATIONAL_OQ_ELEMENT_LENGTH
) {
4239 dev_err(&ctrl_info
->pci_dev
->dev
,
4240 "max. outbound queue element length of %d is less than the required length of %d\n",
4241 ctrl_info
->max_oq_element_length
,
4242 PQI_OPERATIONAL_OQ_ELEMENT_LENGTH
);
4246 if (ctrl_info
->max_inbound_iu_length_per_firmware
<
4247 PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
) {
4248 dev_err(&ctrl_info
->pci_dev
->dev
,
4249 "max. inbound IU length of %u is less than the min. required length of %d\n",
4250 ctrl_info
->max_inbound_iu_length_per_firmware
,
4251 PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
);
4255 if (!ctrl_info
->inbound_spanning_supported
) {
4256 dev_err(&ctrl_info
->pci_dev
->dev
,
4257 "the controller does not support inbound spanning\n");
4261 if (ctrl_info
->outbound_spanning_supported
) {
4262 dev_err(&ctrl_info
->pci_dev
->dev
,
4263 "the controller supports outbound spanning but this driver does not\n");
4270 static int pqi_create_event_queue(struct pqi_ctrl_info
*ctrl_info
)
4273 struct pqi_event_queue
*event_queue
;
4274 struct pqi_general_admin_request request
;
4275 struct pqi_general_admin_response response
;
4277 event_queue
= &ctrl_info
->event_queue
;
4280 * Create OQ (Outbound Queue - device to host queue) to dedicate
4283 memset(&request
, 0, sizeof(request
));
4284 request
.header
.iu_type
= PQI_REQUEST_IU_GENERAL_ADMIN
;
4285 put_unaligned_le16(PQI_GENERAL_ADMIN_IU_LENGTH
,
4286 &request
.header
.iu_length
);
4287 request
.function_code
= PQI_GENERAL_ADMIN_FUNCTION_CREATE_OQ
;
4288 put_unaligned_le16(event_queue
->oq_id
,
4289 &request
.data
.create_operational_oq
.queue_id
);
4290 put_unaligned_le64((u64
)event_queue
->oq_element_array_bus_addr
,
4291 &request
.data
.create_operational_oq
.element_array_addr
);
4292 put_unaligned_le64((u64
)event_queue
->oq_pi_bus_addr
,
4293 &request
.data
.create_operational_oq
.pi_addr
);
4294 put_unaligned_le16(PQI_NUM_EVENT_QUEUE_ELEMENTS
,
4295 &request
.data
.create_operational_oq
.num_elements
);
4296 put_unaligned_le16(PQI_EVENT_OQ_ELEMENT_LENGTH
/ 16,
4297 &request
.data
.create_operational_oq
.element_length
);
4298 request
.data
.create_operational_oq
.queue_protocol
= PQI_PROTOCOL_SOP
;
4299 put_unaligned_le16(event_queue
->int_msg_num
,
4300 &request
.data
.create_operational_oq
.int_msg_num
);
4302 rc
= pqi_submit_admin_request_synchronous(ctrl_info
, &request
,
4307 event_queue
->oq_ci
= ctrl_info
->iomem_base
+
4308 PQI_DEVICE_REGISTERS_OFFSET
+
4310 &response
.data
.create_operational_oq
.oq_ci_offset
);
4315 static int pqi_create_queue_group(struct pqi_ctrl_info
*ctrl_info
,
4316 unsigned int group_number
)
4319 struct pqi_queue_group
*queue_group
;
4320 struct pqi_general_admin_request request
;
4321 struct pqi_general_admin_response response
;
4323 queue_group
= &ctrl_info
->queue_groups
[group_number
];
4326 * Create IQ (Inbound Queue - host to device queue) for
4329 memset(&request
, 0, sizeof(request
));
4330 request
.header
.iu_type
= PQI_REQUEST_IU_GENERAL_ADMIN
;
4331 put_unaligned_le16(PQI_GENERAL_ADMIN_IU_LENGTH
,
4332 &request
.header
.iu_length
);
4333 request
.function_code
= PQI_GENERAL_ADMIN_FUNCTION_CREATE_IQ
;
4334 put_unaligned_le16(queue_group
->iq_id
[RAID_PATH
],
4335 &request
.data
.create_operational_iq
.queue_id
);
4337 (u64
)queue_group
->iq_element_array_bus_addr
[RAID_PATH
],
4338 &request
.data
.create_operational_iq
.element_array_addr
);
4339 put_unaligned_le64((u64
)queue_group
->iq_ci_bus_addr
[RAID_PATH
],
4340 &request
.data
.create_operational_iq
.ci_addr
);
4341 put_unaligned_le16(ctrl_info
->num_elements_per_iq
,
4342 &request
.data
.create_operational_iq
.num_elements
);
4343 put_unaligned_le16(PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
/ 16,
4344 &request
.data
.create_operational_iq
.element_length
);
4345 request
.data
.create_operational_iq
.queue_protocol
= PQI_PROTOCOL_SOP
;
4347 rc
= pqi_submit_admin_request_synchronous(ctrl_info
, &request
,
4350 dev_err(&ctrl_info
->pci_dev
->dev
,
4351 "error creating inbound RAID queue\n");
4355 queue_group
->iq_pi
[RAID_PATH
] = ctrl_info
->iomem_base
+
4356 PQI_DEVICE_REGISTERS_OFFSET
+
4358 &response
.data
.create_operational_iq
.iq_pi_offset
);
4361 * Create IQ (Inbound Queue - host to device queue) for
4362 * Advanced I/O (AIO) path.
4364 memset(&request
, 0, sizeof(request
));
4365 request
.header
.iu_type
= PQI_REQUEST_IU_GENERAL_ADMIN
;
4366 put_unaligned_le16(PQI_GENERAL_ADMIN_IU_LENGTH
,
4367 &request
.header
.iu_length
);
4368 request
.function_code
= PQI_GENERAL_ADMIN_FUNCTION_CREATE_IQ
;
4369 put_unaligned_le16(queue_group
->iq_id
[AIO_PATH
],
4370 &request
.data
.create_operational_iq
.queue_id
);
4371 put_unaligned_le64((u64
)queue_group
->
4372 iq_element_array_bus_addr
[AIO_PATH
],
4373 &request
.data
.create_operational_iq
.element_array_addr
);
4374 put_unaligned_le64((u64
)queue_group
->iq_ci_bus_addr
[AIO_PATH
],
4375 &request
.data
.create_operational_iq
.ci_addr
);
4376 put_unaligned_le16(ctrl_info
->num_elements_per_iq
,
4377 &request
.data
.create_operational_iq
.num_elements
);
4378 put_unaligned_le16(PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
/ 16,
4379 &request
.data
.create_operational_iq
.element_length
);
4380 request
.data
.create_operational_iq
.queue_protocol
= PQI_PROTOCOL_SOP
;
4382 rc
= pqi_submit_admin_request_synchronous(ctrl_info
, &request
,
4385 dev_err(&ctrl_info
->pci_dev
->dev
,
4386 "error creating inbound AIO queue\n");
4390 queue_group
->iq_pi
[AIO_PATH
] = ctrl_info
->iomem_base
+
4391 PQI_DEVICE_REGISTERS_OFFSET
+
4393 &response
.data
.create_operational_iq
.iq_pi_offset
);
4396 * Designate the 2nd IQ as the AIO path. By default, all IQs are
4397 * assumed to be for RAID path I/O unless we change the queue's
4400 memset(&request
, 0, sizeof(request
));
4401 request
.header
.iu_type
= PQI_REQUEST_IU_GENERAL_ADMIN
;
4402 put_unaligned_le16(PQI_GENERAL_ADMIN_IU_LENGTH
,
4403 &request
.header
.iu_length
);
4404 request
.function_code
= PQI_GENERAL_ADMIN_FUNCTION_CHANGE_IQ_PROPERTY
;
4405 put_unaligned_le16(queue_group
->iq_id
[AIO_PATH
],
4406 &request
.data
.change_operational_iq_properties
.queue_id
);
4407 put_unaligned_le32(PQI_IQ_PROPERTY_IS_AIO_QUEUE
,
4408 &request
.data
.change_operational_iq_properties
.vendor_specific
);
4410 rc
= pqi_submit_admin_request_synchronous(ctrl_info
, &request
,
4413 dev_err(&ctrl_info
->pci_dev
->dev
,
4414 "error changing queue property\n");
4419 * Create OQ (Outbound Queue - device to host queue).
4421 memset(&request
, 0, sizeof(request
));
4422 request
.header
.iu_type
= PQI_REQUEST_IU_GENERAL_ADMIN
;
4423 put_unaligned_le16(PQI_GENERAL_ADMIN_IU_LENGTH
,
4424 &request
.header
.iu_length
);
4425 request
.function_code
= PQI_GENERAL_ADMIN_FUNCTION_CREATE_OQ
;
4426 put_unaligned_le16(queue_group
->oq_id
,
4427 &request
.data
.create_operational_oq
.queue_id
);
4428 put_unaligned_le64((u64
)queue_group
->oq_element_array_bus_addr
,
4429 &request
.data
.create_operational_oq
.element_array_addr
);
4430 put_unaligned_le64((u64
)queue_group
->oq_pi_bus_addr
,
4431 &request
.data
.create_operational_oq
.pi_addr
);
4432 put_unaligned_le16(ctrl_info
->num_elements_per_oq
,
4433 &request
.data
.create_operational_oq
.num_elements
);
4434 put_unaligned_le16(PQI_OPERATIONAL_OQ_ELEMENT_LENGTH
/ 16,
4435 &request
.data
.create_operational_oq
.element_length
);
4436 request
.data
.create_operational_oq
.queue_protocol
= PQI_PROTOCOL_SOP
;
4437 put_unaligned_le16(queue_group
->int_msg_num
,
4438 &request
.data
.create_operational_oq
.int_msg_num
);
4440 rc
= pqi_submit_admin_request_synchronous(ctrl_info
, &request
,
4443 dev_err(&ctrl_info
->pci_dev
->dev
,
4444 "error creating outbound queue\n");
4448 queue_group
->oq_ci
= ctrl_info
->iomem_base
+
4449 PQI_DEVICE_REGISTERS_OFFSET
+
4451 &response
.data
.create_operational_oq
.oq_ci_offset
);
4456 static int pqi_create_queues(struct pqi_ctrl_info
*ctrl_info
)
4461 rc
= pqi_create_event_queue(ctrl_info
);
4463 dev_err(&ctrl_info
->pci_dev
->dev
,
4464 "error creating event queue\n");
4468 for (i
= 0; i
< ctrl_info
->num_queue_groups
; i
++) {
4469 rc
= pqi_create_queue_group(ctrl_info
, i
);
4471 dev_err(&ctrl_info
->pci_dev
->dev
,
4472 "error creating queue group number %u/%u\n",
4473 i
, ctrl_info
->num_queue_groups
);
4481 #define PQI_REPORT_EVENT_CONFIG_BUFFER_LENGTH \
4482 (offsetof(struct pqi_event_config, descriptors) + \
4483 (PQI_MAX_EVENT_DESCRIPTORS * sizeof(struct pqi_event_descriptor)))
4485 static int pqi_configure_events(struct pqi_ctrl_info
*ctrl_info
,
4490 struct pqi_event_config
*event_config
;
4491 struct pqi_event_descriptor
*event_descriptor
;
4492 struct pqi_general_management_request request
;
4494 event_config
= kmalloc(PQI_REPORT_EVENT_CONFIG_BUFFER_LENGTH
,
4499 memset(&request
, 0, sizeof(request
));
4501 request
.header
.iu_type
= PQI_REQUEST_IU_REPORT_VENDOR_EVENT_CONFIG
;
4502 put_unaligned_le16(offsetof(struct pqi_general_management_request
,
4503 data
.report_event_configuration
.sg_descriptors
[1]) -
4504 PQI_REQUEST_HEADER_LENGTH
, &request
.header
.iu_length
);
4505 put_unaligned_le32(PQI_REPORT_EVENT_CONFIG_BUFFER_LENGTH
,
4506 &request
.data
.report_event_configuration
.buffer_length
);
4508 rc
= pqi_map_single(ctrl_info
->pci_dev
,
4509 request
.data
.report_event_configuration
.sg_descriptors
,
4510 event_config
, PQI_REPORT_EVENT_CONFIG_BUFFER_LENGTH
,
4515 rc
= pqi_submit_raid_request_synchronous(ctrl_info
, &request
.header
,
4516 0, NULL
, NO_TIMEOUT
);
4518 pqi_pci_unmap(ctrl_info
->pci_dev
,
4519 request
.data
.report_event_configuration
.sg_descriptors
, 1,
4525 for (i
= 0; i
< event_config
->num_event_descriptors
; i
++) {
4526 event_descriptor
= &event_config
->descriptors
[i
];
4527 if (enable_events
&&
4528 pqi_is_supported_event(event_descriptor
->event_type
))
4529 put_unaligned_le16(ctrl_info
->event_queue
.oq_id
,
4530 &event_descriptor
->oq_id
);
4532 put_unaligned_le16(0, &event_descriptor
->oq_id
);
4535 memset(&request
, 0, sizeof(request
));
4537 request
.header
.iu_type
= PQI_REQUEST_IU_SET_VENDOR_EVENT_CONFIG
;
4538 put_unaligned_le16(offsetof(struct pqi_general_management_request
,
4539 data
.report_event_configuration
.sg_descriptors
[1]) -
4540 PQI_REQUEST_HEADER_LENGTH
, &request
.header
.iu_length
);
4541 put_unaligned_le32(PQI_REPORT_EVENT_CONFIG_BUFFER_LENGTH
,
4542 &request
.data
.report_event_configuration
.buffer_length
);
4544 rc
= pqi_map_single(ctrl_info
->pci_dev
,
4545 request
.data
.report_event_configuration
.sg_descriptors
,
4546 event_config
, PQI_REPORT_EVENT_CONFIG_BUFFER_LENGTH
,
4551 rc
= pqi_submit_raid_request_synchronous(ctrl_info
, &request
.header
, 0,
4554 pqi_pci_unmap(ctrl_info
->pci_dev
,
4555 request
.data
.report_event_configuration
.sg_descriptors
, 1,
4559 kfree(event_config
);
4564 static inline int pqi_enable_events(struct pqi_ctrl_info
*ctrl_info
)
4566 return pqi_configure_events(ctrl_info
, true);
4569 static inline int pqi_disable_events(struct pqi_ctrl_info
*ctrl_info
)
4571 return pqi_configure_events(ctrl_info
, false);
4574 static void pqi_free_all_io_requests(struct pqi_ctrl_info
*ctrl_info
)
4578 size_t sg_chain_buffer_length
;
4579 struct pqi_io_request
*io_request
;
4581 if (!ctrl_info
->io_request_pool
)
4584 dev
= &ctrl_info
->pci_dev
->dev
;
4585 sg_chain_buffer_length
= ctrl_info
->sg_chain_buffer_length
;
4586 io_request
= ctrl_info
->io_request_pool
;
4588 for (i
= 0; i
< ctrl_info
->max_io_slots
; i
++) {
4589 kfree(io_request
->iu
);
4590 if (!io_request
->sg_chain_buffer
)
4592 dma_free_coherent(dev
, sg_chain_buffer_length
,
4593 io_request
->sg_chain_buffer
,
4594 io_request
->sg_chain_buffer_dma_handle
);
4598 kfree(ctrl_info
->io_request_pool
);
4599 ctrl_info
->io_request_pool
= NULL
;
4602 static inline int pqi_alloc_error_buffer(struct pqi_ctrl_info
*ctrl_info
)
4604 ctrl_info
->error_buffer
= dma_alloc_coherent(&ctrl_info
->pci_dev
->dev
,
4605 ctrl_info
->error_buffer_length
,
4606 &ctrl_info
->error_buffer_dma_handle
,
4609 if (!ctrl_info
->error_buffer
)
4615 static int pqi_alloc_io_resources(struct pqi_ctrl_info
*ctrl_info
)
4618 void *sg_chain_buffer
;
4619 size_t sg_chain_buffer_length
;
4620 dma_addr_t sg_chain_buffer_dma_handle
;
4622 struct pqi_io_request
*io_request
;
4624 ctrl_info
->io_request_pool
=
4625 kcalloc(ctrl_info
->max_io_slots
,
4626 sizeof(ctrl_info
->io_request_pool
[0]), GFP_KERNEL
);
4628 if (!ctrl_info
->io_request_pool
) {
4629 dev_err(&ctrl_info
->pci_dev
->dev
,
4630 "failed to allocate I/O request pool\n");
4634 dev
= &ctrl_info
->pci_dev
->dev
;
4635 sg_chain_buffer_length
= ctrl_info
->sg_chain_buffer_length
;
4636 io_request
= ctrl_info
->io_request_pool
;
4638 for (i
= 0; i
< ctrl_info
->max_io_slots
; i
++) {
4640 kmalloc(ctrl_info
->max_inbound_iu_length
, GFP_KERNEL
);
4642 if (!io_request
->iu
) {
4643 dev_err(&ctrl_info
->pci_dev
->dev
,
4644 "failed to allocate IU buffers\n");
4648 sg_chain_buffer
= dma_alloc_coherent(dev
,
4649 sg_chain_buffer_length
, &sg_chain_buffer_dma_handle
,
4652 if (!sg_chain_buffer
) {
4653 dev_err(&ctrl_info
->pci_dev
->dev
,
4654 "failed to allocate PQI scatter-gather chain buffers\n");
4658 io_request
->index
= i
;
4659 io_request
->sg_chain_buffer
= sg_chain_buffer
;
4660 io_request
->sg_chain_buffer_dma_handle
=
4661 sg_chain_buffer_dma_handle
;
4668 pqi_free_all_io_requests(ctrl_info
);
4674 * Calculate required resources that are sized based on max. outstanding
4675 * requests and max. transfer size.
4678 static void pqi_calculate_io_resources(struct pqi_ctrl_info
*ctrl_info
)
4680 u32 max_transfer_size
;
4683 ctrl_info
->scsi_ml_can_queue
=
4684 ctrl_info
->max_outstanding_requests
- PQI_RESERVED_IO_SLOTS
;
4685 ctrl_info
->max_io_slots
= ctrl_info
->max_outstanding_requests
;
4687 ctrl_info
->error_buffer_length
=
4688 ctrl_info
->max_io_slots
* PQI_ERROR_BUFFER_ELEMENT_LENGTH
;
4691 max_transfer_size
= min(ctrl_info
->max_transfer_size
,
4692 PQI_MAX_TRANSFER_SIZE_KDUMP
);
4694 max_transfer_size
= min(ctrl_info
->max_transfer_size
,
4695 PQI_MAX_TRANSFER_SIZE
);
4697 max_sg_entries
= max_transfer_size
/ PAGE_SIZE
;
4699 /* +1 to cover when the buffer is not page-aligned. */
4702 max_sg_entries
= min(ctrl_info
->max_sg_entries
, max_sg_entries
);
4704 max_transfer_size
= (max_sg_entries
- 1) * PAGE_SIZE
;
4706 ctrl_info
->sg_chain_buffer_length
=
4707 (max_sg_entries
* sizeof(struct pqi_sg_descriptor
)) +
4708 PQI_EXTRA_SGL_MEMORY
;
4709 ctrl_info
->sg_tablesize
= max_sg_entries
;
4710 ctrl_info
->max_sectors
= max_transfer_size
/ 512;
4713 static void pqi_calculate_queue_resources(struct pqi_ctrl_info
*ctrl_info
)
4715 int num_queue_groups
;
4716 u16 num_elements_per_iq
;
4717 u16 num_elements_per_oq
;
4719 if (reset_devices
) {
4720 num_queue_groups
= 1;
4723 int max_queue_groups
;
4725 max_queue_groups
= min(ctrl_info
->max_inbound_queues
/ 2,
4726 ctrl_info
->max_outbound_queues
- 1);
4727 max_queue_groups
= min(max_queue_groups
, PQI_MAX_QUEUE_GROUPS
);
4729 num_cpus
= num_online_cpus();
4730 num_queue_groups
= min(num_cpus
, ctrl_info
->max_msix_vectors
);
4731 num_queue_groups
= min(num_queue_groups
, max_queue_groups
);
4734 ctrl_info
->num_queue_groups
= num_queue_groups
;
4735 ctrl_info
->max_hw_queue_index
= num_queue_groups
- 1;
4738 * Make sure that the max. inbound IU length is an even multiple
4739 * of our inbound element length.
4741 ctrl_info
->max_inbound_iu_length
=
4742 (ctrl_info
->max_inbound_iu_length_per_firmware
/
4743 PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
) *
4744 PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
;
4746 num_elements_per_iq
=
4747 (ctrl_info
->max_inbound_iu_length
/
4748 PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
);
4750 /* Add one because one element in each queue is unusable. */
4751 num_elements_per_iq
++;
4753 num_elements_per_iq
= min(num_elements_per_iq
,
4754 ctrl_info
->max_elements_per_iq
);
4756 num_elements_per_oq
= ((num_elements_per_iq
- 1) * 2) + 1;
4757 num_elements_per_oq
= min(num_elements_per_oq
,
4758 ctrl_info
->max_elements_per_oq
);
4760 ctrl_info
->num_elements_per_iq
= num_elements_per_iq
;
4761 ctrl_info
->num_elements_per_oq
= num_elements_per_oq
;
4763 ctrl_info
->max_sg_per_iu
=
4764 ((ctrl_info
->max_inbound_iu_length
-
4765 PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
) /
4766 sizeof(struct pqi_sg_descriptor
)) +
4767 PQI_MAX_EMBEDDED_SG_DESCRIPTORS
;
4770 static inline void pqi_set_sg_descriptor(
4771 struct pqi_sg_descriptor
*sg_descriptor
, struct scatterlist
*sg
)
4773 u64 address
= (u64
)sg_dma_address(sg
);
4774 unsigned int length
= sg_dma_len(sg
);
4776 put_unaligned_le64(address
, &sg_descriptor
->address
);
4777 put_unaligned_le32(length
, &sg_descriptor
->length
);
4778 put_unaligned_le32(0, &sg_descriptor
->flags
);
4781 static int pqi_build_raid_sg_list(struct pqi_ctrl_info
*ctrl_info
,
4782 struct pqi_raid_path_request
*request
, struct scsi_cmnd
*scmd
,
4783 struct pqi_io_request
*io_request
)
4789 unsigned int num_sg_in_iu
;
4790 unsigned int max_sg_per_iu
;
4791 struct scatterlist
*sg
;
4792 struct pqi_sg_descriptor
*sg_descriptor
;
4794 sg_count
= scsi_dma_map(scmd
);
4798 iu_length
= offsetof(struct pqi_raid_path_request
, sg_descriptors
) -
4799 PQI_REQUEST_HEADER_LENGTH
;
4804 sg
= scsi_sglist(scmd
);
4805 sg_descriptor
= request
->sg_descriptors
;
4806 max_sg_per_iu
= ctrl_info
->max_sg_per_iu
- 1;
4812 pqi_set_sg_descriptor(sg_descriptor
, sg
);
4819 if (i
== max_sg_per_iu
) {
4821 (u64
)io_request
->sg_chain_buffer_dma_handle
,
4822 &sg_descriptor
->address
);
4823 put_unaligned_le32((sg_count
- num_sg_in_iu
)
4824 * sizeof(*sg_descriptor
),
4825 &sg_descriptor
->length
);
4826 put_unaligned_le32(CISS_SG_CHAIN
,
4827 &sg_descriptor
->flags
);
4830 sg_descriptor
= io_request
->sg_chain_buffer
;
4835 put_unaligned_le32(CISS_SG_LAST
, &sg_descriptor
->flags
);
4836 request
->partial
= chained
;
4837 iu_length
+= num_sg_in_iu
* sizeof(*sg_descriptor
);
4840 put_unaligned_le16(iu_length
, &request
->header
.iu_length
);
4845 static int pqi_build_aio_sg_list(struct pqi_ctrl_info
*ctrl_info
,
4846 struct pqi_aio_path_request
*request
, struct scsi_cmnd
*scmd
,
4847 struct pqi_io_request
*io_request
)
4853 unsigned int num_sg_in_iu
;
4854 unsigned int max_sg_per_iu
;
4855 struct scatterlist
*sg
;
4856 struct pqi_sg_descriptor
*sg_descriptor
;
4858 sg_count
= scsi_dma_map(scmd
);
4862 iu_length
= offsetof(struct pqi_aio_path_request
, sg_descriptors
) -
4863 PQI_REQUEST_HEADER_LENGTH
;
4869 sg
= scsi_sglist(scmd
);
4870 sg_descriptor
= request
->sg_descriptors
;
4871 max_sg_per_iu
= ctrl_info
->max_sg_per_iu
- 1;
4876 pqi_set_sg_descriptor(sg_descriptor
, sg
);
4883 if (i
== max_sg_per_iu
) {
4885 (u64
)io_request
->sg_chain_buffer_dma_handle
,
4886 &sg_descriptor
->address
);
4887 put_unaligned_le32((sg_count
- num_sg_in_iu
)
4888 * sizeof(*sg_descriptor
),
4889 &sg_descriptor
->length
);
4890 put_unaligned_le32(CISS_SG_CHAIN
,
4891 &sg_descriptor
->flags
);
4894 sg_descriptor
= io_request
->sg_chain_buffer
;
4899 put_unaligned_le32(CISS_SG_LAST
, &sg_descriptor
->flags
);
4900 request
->partial
= chained
;
4901 iu_length
+= num_sg_in_iu
* sizeof(*sg_descriptor
);
4904 put_unaligned_le16(iu_length
, &request
->header
.iu_length
);
4905 request
->num_sg_descriptors
= num_sg_in_iu
;
4910 static void pqi_raid_io_complete(struct pqi_io_request
*io_request
,
4913 struct scsi_cmnd
*scmd
;
4915 scmd
= io_request
->scmd
;
4916 pqi_free_io_request(io_request
);
4917 scsi_dma_unmap(scmd
);
4918 pqi_scsi_done(scmd
);
4921 static int pqi_raid_submit_scsi_cmd_with_io_request(
4922 struct pqi_ctrl_info
*ctrl_info
, struct pqi_io_request
*io_request
,
4923 struct pqi_scsi_dev
*device
, struct scsi_cmnd
*scmd
,
4924 struct pqi_queue_group
*queue_group
)
4928 struct pqi_raid_path_request
*request
;
4930 io_request
->io_complete_callback
= pqi_raid_io_complete
;
4931 io_request
->scmd
= scmd
;
4933 request
= io_request
->iu
;
4935 offsetof(struct pqi_raid_path_request
, sg_descriptors
));
4937 request
->header
.iu_type
= PQI_REQUEST_IU_RAID_PATH_IO
;
4938 put_unaligned_le32(scsi_bufflen(scmd
), &request
->buffer_length
);
4939 request
->task_attribute
= SOP_TASK_ATTRIBUTE_SIMPLE
;
4940 put_unaligned_le16(io_request
->index
, &request
->request_id
);
4941 request
->error_index
= request
->request_id
;
4942 memcpy(request
->lun_number
, device
->scsi3addr
,
4943 sizeof(request
->lun_number
));
4945 cdb_length
= min_t(size_t, scmd
->cmd_len
, sizeof(request
->cdb
));
4946 memcpy(request
->cdb
, scmd
->cmnd
, cdb_length
);
4948 switch (cdb_length
) {
4953 /* No bytes in the Additional CDB bytes field */
4954 request
->additional_cdb_bytes_usage
=
4955 SOP_ADDITIONAL_CDB_BYTES_0
;
4958 /* 4 bytes in the Additional cdb field */
4959 request
->additional_cdb_bytes_usage
=
4960 SOP_ADDITIONAL_CDB_BYTES_4
;
4963 /* 8 bytes in the Additional cdb field */
4964 request
->additional_cdb_bytes_usage
=
4965 SOP_ADDITIONAL_CDB_BYTES_8
;
4968 /* 12 bytes in the Additional cdb field */
4969 request
->additional_cdb_bytes_usage
=
4970 SOP_ADDITIONAL_CDB_BYTES_12
;
4974 /* 16 bytes in the Additional cdb field */
4975 request
->additional_cdb_bytes_usage
=
4976 SOP_ADDITIONAL_CDB_BYTES_16
;
4980 switch (scmd
->sc_data_direction
) {
4982 request
->data_direction
= SOP_READ_FLAG
;
4984 case DMA_FROM_DEVICE
:
4985 request
->data_direction
= SOP_WRITE_FLAG
;
4988 request
->data_direction
= SOP_NO_DIRECTION_FLAG
;
4990 case DMA_BIDIRECTIONAL
:
4991 request
->data_direction
= SOP_BIDIRECTIONAL
;
4994 dev_err(&ctrl_info
->pci_dev
->dev
,
4995 "unknown data direction: %d\n",
4996 scmd
->sc_data_direction
);
5000 rc
= pqi_build_raid_sg_list(ctrl_info
, request
, scmd
, io_request
);
5002 pqi_free_io_request(io_request
);
5003 return SCSI_MLQUEUE_HOST_BUSY
;
5006 pqi_start_io(ctrl_info
, queue_group
, RAID_PATH
, io_request
);
5011 static inline int pqi_raid_submit_scsi_cmd(struct pqi_ctrl_info
*ctrl_info
,
5012 struct pqi_scsi_dev
*device
, struct scsi_cmnd
*scmd
,
5013 struct pqi_queue_group
*queue_group
)
5015 struct pqi_io_request
*io_request
;
5017 io_request
= pqi_alloc_io_request(ctrl_info
);
5019 return pqi_raid_submit_scsi_cmd_with_io_request(ctrl_info
, io_request
,
5020 device
, scmd
, queue_group
);
5023 static inline void pqi_schedule_bypass_retry(struct pqi_ctrl_info
*ctrl_info
)
5025 if (!pqi_ctrl_blocked(ctrl_info
))
5026 schedule_work(&ctrl_info
->raid_bypass_retry_work
);
5029 static bool pqi_raid_bypass_retry_needed(struct pqi_io_request
*io_request
)
5031 struct scsi_cmnd
*scmd
;
5032 struct pqi_scsi_dev
*device
;
5033 struct pqi_ctrl_info
*ctrl_info
;
5035 if (!io_request
->raid_bypass
)
5038 scmd
= io_request
->scmd
;
5039 if ((scmd
->result
& 0xff) == SAM_STAT_GOOD
)
5041 if (host_byte(scmd
->result
) == DID_NO_CONNECT
)
5044 device
= scmd
->device
->hostdata
;
5045 if (pqi_device_offline(device
))
5048 ctrl_info
= shost_to_hba(scmd
->device
->host
);
5049 if (pqi_ctrl_offline(ctrl_info
))
5055 static inline void pqi_add_to_raid_bypass_retry_list(
5056 struct pqi_ctrl_info
*ctrl_info
,
5057 struct pqi_io_request
*io_request
, bool at_head
)
5059 unsigned long flags
;
5061 spin_lock_irqsave(&ctrl_info
->raid_bypass_retry_list_lock
, flags
);
5063 list_add(&io_request
->request_list_entry
,
5064 &ctrl_info
->raid_bypass_retry_list
);
5066 list_add_tail(&io_request
->request_list_entry
,
5067 &ctrl_info
->raid_bypass_retry_list
);
5068 spin_unlock_irqrestore(&ctrl_info
->raid_bypass_retry_list_lock
, flags
);
5071 static void pqi_queued_raid_bypass_complete(struct pqi_io_request
*io_request
,
5074 struct scsi_cmnd
*scmd
;
5076 scmd
= io_request
->scmd
;
5077 pqi_free_io_request(io_request
);
5078 pqi_scsi_done(scmd
);
5081 static void pqi_queue_raid_bypass_retry(struct pqi_io_request
*io_request
)
5083 struct scsi_cmnd
*scmd
;
5084 struct pqi_ctrl_info
*ctrl_info
;
5086 io_request
->io_complete_callback
= pqi_queued_raid_bypass_complete
;
5087 scmd
= io_request
->scmd
;
5089 ctrl_info
= shost_to_hba(scmd
->device
->host
);
5091 pqi_add_to_raid_bypass_retry_list(ctrl_info
, io_request
, false);
5092 pqi_schedule_bypass_retry(ctrl_info
);
5095 static int pqi_retry_raid_bypass(struct pqi_io_request
*io_request
)
5097 struct scsi_cmnd
*scmd
;
5098 struct pqi_scsi_dev
*device
;
5099 struct pqi_ctrl_info
*ctrl_info
;
5100 struct pqi_queue_group
*queue_group
;
5102 scmd
= io_request
->scmd
;
5103 device
= scmd
->device
->hostdata
;
5104 if (pqi_device_in_reset(device
)) {
5105 pqi_free_io_request(io_request
);
5106 set_host_byte(scmd
, DID_RESET
);
5107 pqi_scsi_done(scmd
);
5111 ctrl_info
= shost_to_hba(scmd
->device
->host
);
5112 queue_group
= io_request
->queue_group
;
5114 pqi_reinit_io_request(io_request
);
5116 return pqi_raid_submit_scsi_cmd_with_io_request(ctrl_info
, io_request
,
5117 device
, scmd
, queue_group
);
5120 static inline struct pqi_io_request
*pqi_next_queued_raid_bypass_request(
5121 struct pqi_ctrl_info
*ctrl_info
)
5123 unsigned long flags
;
5124 struct pqi_io_request
*io_request
;
5126 spin_lock_irqsave(&ctrl_info
->raid_bypass_retry_list_lock
, flags
);
5127 io_request
= list_first_entry_or_null(
5128 &ctrl_info
->raid_bypass_retry_list
,
5129 struct pqi_io_request
, request_list_entry
);
5131 list_del(&io_request
->request_list_entry
);
5132 spin_unlock_irqrestore(&ctrl_info
->raid_bypass_retry_list_lock
, flags
);
5137 static void pqi_retry_raid_bypass_requests(struct pqi_ctrl_info
*ctrl_info
)
5140 struct pqi_io_request
*io_request
;
5142 pqi_ctrl_busy(ctrl_info
);
5145 if (pqi_ctrl_blocked(ctrl_info
))
5147 io_request
= pqi_next_queued_raid_bypass_request(ctrl_info
);
5150 rc
= pqi_retry_raid_bypass(io_request
);
5152 pqi_add_to_raid_bypass_retry_list(ctrl_info
, io_request
,
5154 pqi_schedule_bypass_retry(ctrl_info
);
5159 pqi_ctrl_unbusy(ctrl_info
);
5162 static void pqi_raid_bypass_retry_worker(struct work_struct
*work
)
5164 struct pqi_ctrl_info
*ctrl_info
;
5166 ctrl_info
= container_of(work
, struct pqi_ctrl_info
,
5167 raid_bypass_retry_work
);
5168 pqi_retry_raid_bypass_requests(ctrl_info
);
5171 static void pqi_clear_all_queued_raid_bypass_retries(
5172 struct pqi_ctrl_info
*ctrl_info
)
5174 unsigned long flags
;
5176 spin_lock_irqsave(&ctrl_info
->raid_bypass_retry_list_lock
, flags
);
5177 INIT_LIST_HEAD(&ctrl_info
->raid_bypass_retry_list
);
5178 spin_unlock_irqrestore(&ctrl_info
->raid_bypass_retry_list_lock
, flags
);
5181 static void pqi_aio_io_complete(struct pqi_io_request
*io_request
,
5184 struct scsi_cmnd
*scmd
;
5186 scmd
= io_request
->scmd
;
5187 scsi_dma_unmap(scmd
);
5188 if (io_request
->status
== -EAGAIN
)
5189 set_host_byte(scmd
, DID_IMM_RETRY
);
5190 else if (pqi_raid_bypass_retry_needed(io_request
)) {
5191 pqi_queue_raid_bypass_retry(io_request
);
5194 pqi_free_io_request(io_request
);
5195 pqi_scsi_done(scmd
);
5198 static inline int pqi_aio_submit_scsi_cmd(struct pqi_ctrl_info
*ctrl_info
,
5199 struct pqi_scsi_dev
*device
, struct scsi_cmnd
*scmd
,
5200 struct pqi_queue_group
*queue_group
)
5202 return pqi_aio_submit_io(ctrl_info
, scmd
, device
->aio_handle
,
5203 scmd
->cmnd
, scmd
->cmd_len
, queue_group
, NULL
, false);
5206 static int pqi_aio_submit_io(struct pqi_ctrl_info
*ctrl_info
,
5207 struct scsi_cmnd
*scmd
, u32 aio_handle
, u8
*cdb
,
5208 unsigned int cdb_length
, struct pqi_queue_group
*queue_group
,
5209 struct pqi_encryption_info
*encryption_info
, bool raid_bypass
)
5212 struct pqi_io_request
*io_request
;
5213 struct pqi_aio_path_request
*request
;
5215 io_request
= pqi_alloc_io_request(ctrl_info
);
5216 io_request
->io_complete_callback
= pqi_aio_io_complete
;
5217 io_request
->scmd
= scmd
;
5218 io_request
->raid_bypass
= raid_bypass
;
5220 request
= io_request
->iu
;
5222 offsetof(struct pqi_raid_path_request
, sg_descriptors
));
5224 request
->header
.iu_type
= PQI_REQUEST_IU_AIO_PATH_IO
;
5225 put_unaligned_le32(aio_handle
, &request
->nexus_id
);
5226 put_unaligned_le32(scsi_bufflen(scmd
), &request
->buffer_length
);
5227 request
->task_attribute
= SOP_TASK_ATTRIBUTE_SIMPLE
;
5228 put_unaligned_le16(io_request
->index
, &request
->request_id
);
5229 request
->error_index
= request
->request_id
;
5230 if (cdb_length
> sizeof(request
->cdb
))
5231 cdb_length
= sizeof(request
->cdb
);
5232 request
->cdb_length
= cdb_length
;
5233 memcpy(request
->cdb
, cdb
, cdb_length
);
5235 switch (scmd
->sc_data_direction
) {
5237 request
->data_direction
= SOP_READ_FLAG
;
5239 case DMA_FROM_DEVICE
:
5240 request
->data_direction
= SOP_WRITE_FLAG
;
5243 request
->data_direction
= SOP_NO_DIRECTION_FLAG
;
5245 case DMA_BIDIRECTIONAL
:
5246 request
->data_direction
= SOP_BIDIRECTIONAL
;
5249 dev_err(&ctrl_info
->pci_dev
->dev
,
5250 "unknown data direction: %d\n",
5251 scmd
->sc_data_direction
);
5255 if (encryption_info
) {
5256 request
->encryption_enable
= true;
5257 put_unaligned_le16(encryption_info
->data_encryption_key_index
,
5258 &request
->data_encryption_key_index
);
5259 put_unaligned_le32(encryption_info
->encrypt_tweak_lower
,
5260 &request
->encrypt_tweak_lower
);
5261 put_unaligned_le32(encryption_info
->encrypt_tweak_upper
,
5262 &request
->encrypt_tweak_upper
);
5265 rc
= pqi_build_aio_sg_list(ctrl_info
, request
, scmd
, io_request
);
5267 pqi_free_io_request(io_request
);
5268 return SCSI_MLQUEUE_HOST_BUSY
;
5271 pqi_start_io(ctrl_info
, queue_group
, AIO_PATH
, io_request
);
5276 static inline u16
pqi_get_hw_queue(struct pqi_ctrl_info
*ctrl_info
,
5277 struct scsi_cmnd
*scmd
)
5281 hw_queue
= blk_mq_unique_tag_to_hwq(blk_mq_unique_tag(scmd
->request
));
5282 if (hw_queue
> ctrl_info
->max_hw_queue_index
)
5289 * This function gets called just before we hand the completed SCSI request
5293 void pqi_prep_for_scsi_done(struct scsi_cmnd
*scmd
)
5295 struct pqi_scsi_dev
*device
;
5297 if (!scmd
->device
) {
5298 set_host_byte(scmd
, DID_NO_CONNECT
);
5302 device
= scmd
->device
->hostdata
;
5304 set_host_byte(scmd
, DID_NO_CONNECT
);
5308 atomic_dec(&device
->scsi_cmds_outstanding
);
5311 static int pqi_scsi_queue_command(struct Scsi_Host
*shost
,
5312 struct scsi_cmnd
*scmd
)
5315 struct pqi_ctrl_info
*ctrl_info
;
5316 struct pqi_scsi_dev
*device
;
5318 struct pqi_queue_group
*queue_group
;
5321 device
= scmd
->device
->hostdata
;
5322 ctrl_info
= shost_to_hba(shost
);
5325 set_host_byte(scmd
, DID_NO_CONNECT
);
5326 pqi_scsi_done(scmd
);
5330 atomic_inc(&device
->scsi_cmds_outstanding
);
5332 if (pqi_ctrl_offline(ctrl_info
) || pqi_device_in_remove(ctrl_info
,
5334 set_host_byte(scmd
, DID_NO_CONNECT
);
5335 pqi_scsi_done(scmd
);
5339 pqi_ctrl_busy(ctrl_info
);
5340 if (pqi_ctrl_blocked(ctrl_info
) || pqi_device_in_reset(device
) ||
5341 pqi_ctrl_in_ofa(ctrl_info
)) {
5342 rc
= SCSI_MLQUEUE_HOST_BUSY
;
5347 * This is necessary because the SML doesn't zero out this field during
5352 hw_queue
= pqi_get_hw_queue(ctrl_info
, scmd
);
5353 queue_group
= &ctrl_info
->queue_groups
[hw_queue
];
5355 if (pqi_is_logical_device(device
)) {
5356 raid_bypassed
= false;
5357 if (device
->raid_bypass_enabled
&&
5358 !blk_rq_is_passthrough(scmd
->request
)) {
5359 rc
= pqi_raid_bypass_submit_scsi_cmd(ctrl_info
, device
,
5361 if (rc
== 0 || rc
== SCSI_MLQUEUE_HOST_BUSY
)
5362 raid_bypassed
= true;
5365 rc
= pqi_raid_submit_scsi_cmd(ctrl_info
, device
, scmd
,
5368 if (device
->aio_enabled
)
5369 rc
= pqi_aio_submit_scsi_cmd(ctrl_info
, device
, scmd
,
5372 rc
= pqi_raid_submit_scsi_cmd(ctrl_info
, device
, scmd
,
5377 pqi_ctrl_unbusy(ctrl_info
);
5379 atomic_dec(&device
->scsi_cmds_outstanding
);
5384 static int pqi_wait_until_queued_io_drained(struct pqi_ctrl_info
*ctrl_info
,
5385 struct pqi_queue_group
*queue_group
)
5388 unsigned long flags
;
5391 for (path
= 0; path
< 2; path
++) {
5394 &queue_group
->submit_lock
[path
], flags
);
5396 list_empty(&queue_group
->request_list
[path
]);
5397 spin_unlock_irqrestore(
5398 &queue_group
->submit_lock
[path
], flags
);
5401 pqi_check_ctrl_health(ctrl_info
);
5402 if (pqi_ctrl_offline(ctrl_info
))
5404 usleep_range(1000, 2000);
5411 static int pqi_wait_until_inbound_queues_empty(struct pqi_ctrl_info
*ctrl_info
)
5416 struct pqi_queue_group
*queue_group
;
5420 for (i
= 0; i
< ctrl_info
->num_queue_groups
; i
++) {
5421 queue_group
= &ctrl_info
->queue_groups
[i
];
5423 rc
= pqi_wait_until_queued_io_drained(ctrl_info
, queue_group
);
5427 for (path
= 0; path
< 2; path
++) {
5428 iq_pi
= queue_group
->iq_pi_copy
[path
];
5431 iq_ci
= readl(queue_group
->iq_ci
[path
]);
5434 pqi_check_ctrl_health(ctrl_info
);
5435 if (pqi_ctrl_offline(ctrl_info
))
5437 usleep_range(1000, 2000);
5445 static void pqi_fail_io_queued_for_device(struct pqi_ctrl_info
*ctrl_info
,
5446 struct pqi_scsi_dev
*device
)
5450 struct pqi_queue_group
*queue_group
;
5451 unsigned long flags
;
5452 struct pqi_io_request
*io_request
;
5453 struct pqi_io_request
*next
;
5454 struct scsi_cmnd
*scmd
;
5455 struct pqi_scsi_dev
*scsi_device
;
5457 for (i
= 0; i
< ctrl_info
->num_queue_groups
; i
++) {
5458 queue_group
= &ctrl_info
->queue_groups
[i
];
5460 for (path
= 0; path
< 2; path
++) {
5462 &queue_group
->submit_lock
[path
], flags
);
5464 list_for_each_entry_safe(io_request
, next
,
5465 &queue_group
->request_list
[path
],
5466 request_list_entry
) {
5467 scmd
= io_request
->scmd
;
5471 scsi_device
= scmd
->device
->hostdata
;
5472 if (scsi_device
!= device
)
5475 list_del(&io_request
->request_list_entry
);
5476 set_host_byte(scmd
, DID_RESET
);
5477 pqi_scsi_done(scmd
);
5480 spin_unlock_irqrestore(
5481 &queue_group
->submit_lock
[path
], flags
);
5486 static void pqi_fail_io_queued_for_all_devices(struct pqi_ctrl_info
*ctrl_info
)
5490 struct pqi_queue_group
*queue_group
;
5491 unsigned long flags
;
5492 struct pqi_io_request
*io_request
;
5493 struct pqi_io_request
*next
;
5494 struct scsi_cmnd
*scmd
;
5496 for (i
= 0; i
< ctrl_info
->num_queue_groups
; i
++) {
5497 queue_group
= &ctrl_info
->queue_groups
[i
];
5499 for (path
= 0; path
< 2; path
++) {
5500 spin_lock_irqsave(&queue_group
->submit_lock
[path
],
5503 list_for_each_entry_safe(io_request
, next
,
5504 &queue_group
->request_list
[path
],
5505 request_list_entry
) {
5507 scmd
= io_request
->scmd
;
5511 list_del(&io_request
->request_list_entry
);
5512 set_host_byte(scmd
, DID_RESET
);
5513 pqi_scsi_done(scmd
);
5516 spin_unlock_irqrestore(
5517 &queue_group
->submit_lock
[path
], flags
);
5522 static int pqi_device_wait_for_pending_io(struct pqi_ctrl_info
*ctrl_info
,
5523 struct pqi_scsi_dev
*device
, unsigned long timeout_secs
)
5525 unsigned long timeout
;
5527 timeout
= (timeout_secs
* PQI_HZ
) + jiffies
;
5529 while (atomic_read(&device
->scsi_cmds_outstanding
)) {
5530 pqi_check_ctrl_health(ctrl_info
);
5531 if (pqi_ctrl_offline(ctrl_info
))
5533 if (timeout_secs
!= NO_TIMEOUT
) {
5534 if (time_after(jiffies
, timeout
)) {
5535 dev_err(&ctrl_info
->pci_dev
->dev
,
5536 "timed out waiting for pending IO\n");
5540 usleep_range(1000, 2000);
5546 static int pqi_ctrl_wait_for_pending_io(struct pqi_ctrl_info
*ctrl_info
,
5547 unsigned long timeout_secs
)
5550 unsigned long flags
;
5551 unsigned long timeout
;
5552 struct pqi_scsi_dev
*device
;
5554 timeout
= (timeout_secs
* PQI_HZ
) + jiffies
;
5558 spin_lock_irqsave(&ctrl_info
->scsi_device_list_lock
, flags
);
5559 list_for_each_entry(device
, &ctrl_info
->scsi_device_list
,
5560 scsi_device_list_entry
) {
5561 if (atomic_read(&device
->scsi_cmds_outstanding
)) {
5566 spin_unlock_irqrestore(&ctrl_info
->scsi_device_list_lock
,
5572 pqi_check_ctrl_health(ctrl_info
);
5573 if (pqi_ctrl_offline(ctrl_info
))
5576 if (timeout_secs
!= NO_TIMEOUT
) {
5577 if (time_after(jiffies
, timeout
)) {
5578 dev_err(&ctrl_info
->pci_dev
->dev
,
5579 "timed out waiting for pending IO\n");
5583 usleep_range(1000, 2000);
5589 static void pqi_lun_reset_complete(struct pqi_io_request
*io_request
,
5592 struct completion
*waiting
= context
;
5597 #define PQI_LUN_RESET_TIMEOUT_SECS 10
5599 static int pqi_wait_for_lun_reset_completion(struct pqi_ctrl_info
*ctrl_info
,
5600 struct pqi_scsi_dev
*device
, struct completion
*wait
)
5605 if (wait_for_completion_io_timeout(wait
,
5606 PQI_LUN_RESET_TIMEOUT_SECS
* PQI_HZ
)) {
5611 pqi_check_ctrl_health(ctrl_info
);
5612 if (pqi_ctrl_offline(ctrl_info
)) {
5621 static int pqi_lun_reset(struct pqi_ctrl_info
*ctrl_info
,
5622 struct pqi_scsi_dev
*device
)
5625 struct pqi_io_request
*io_request
;
5626 DECLARE_COMPLETION_ONSTACK(wait
);
5627 struct pqi_task_management_request
*request
;
5629 io_request
= pqi_alloc_io_request(ctrl_info
);
5630 io_request
->io_complete_callback
= pqi_lun_reset_complete
;
5631 io_request
->context
= &wait
;
5633 request
= io_request
->iu
;
5634 memset(request
, 0, sizeof(*request
));
5636 request
->header
.iu_type
= PQI_REQUEST_IU_TASK_MANAGEMENT
;
5637 put_unaligned_le16(sizeof(*request
) - PQI_REQUEST_HEADER_LENGTH
,
5638 &request
->header
.iu_length
);
5639 put_unaligned_le16(io_request
->index
, &request
->request_id
);
5640 memcpy(request
->lun_number
, device
->scsi3addr
,
5641 sizeof(request
->lun_number
));
5642 request
->task_management_function
= SOP_TASK_MANAGEMENT_LUN_RESET
;
5644 pqi_start_io(ctrl_info
,
5645 &ctrl_info
->queue_groups
[PQI_DEFAULT_QUEUE_GROUP
], RAID_PATH
,
5648 rc
= pqi_wait_for_lun_reset_completion(ctrl_info
, device
, &wait
);
5650 rc
= io_request
->status
;
5652 pqi_free_io_request(io_request
);
5657 #define PQI_LUN_RESET_RETRIES 3
5658 #define PQI_LUN_RESET_RETRY_INTERVAL_MSECS 10000
5659 /* Performs a reset at the LUN level. */
5661 static int _pqi_device_reset(struct pqi_ctrl_info
*ctrl_info
,
5662 struct pqi_scsi_dev
*device
)
5665 unsigned int retries
;
5666 unsigned long timeout_secs
;
5668 for (retries
= 0;;) {
5669 rc
= pqi_lun_reset(ctrl_info
, device
);
5670 if (rc
!= -EAGAIN
||
5671 ++retries
> PQI_LUN_RESET_RETRIES
)
5673 msleep(PQI_LUN_RESET_RETRY_INTERVAL_MSECS
);
5675 timeout_secs
= rc
? PQI_LUN_RESET_TIMEOUT_SECS
: NO_TIMEOUT
;
5677 rc
|= pqi_device_wait_for_pending_io(ctrl_info
, device
, timeout_secs
);
5679 return rc
== 0 ? SUCCESS
: FAILED
;
5682 static int pqi_device_reset(struct pqi_ctrl_info
*ctrl_info
,
5683 struct pqi_scsi_dev
*device
)
5687 mutex_lock(&ctrl_info
->lun_reset_mutex
);
5689 pqi_ctrl_block_requests(ctrl_info
);
5690 pqi_ctrl_wait_until_quiesced(ctrl_info
);
5691 pqi_fail_io_queued_for_device(ctrl_info
, device
);
5692 rc
= pqi_wait_until_inbound_queues_empty(ctrl_info
);
5693 pqi_device_reset_start(device
);
5694 pqi_ctrl_unblock_requests(ctrl_info
);
5699 rc
= _pqi_device_reset(ctrl_info
, device
);
5701 pqi_device_reset_done(device
);
5703 mutex_unlock(&ctrl_info
->lun_reset_mutex
);
5707 static int pqi_eh_device_reset_handler(struct scsi_cmnd
*scmd
)
5710 struct Scsi_Host
*shost
;
5711 struct pqi_ctrl_info
*ctrl_info
;
5712 struct pqi_scsi_dev
*device
;
5714 shost
= scmd
->device
->host
;
5715 ctrl_info
= shost_to_hba(shost
);
5716 device
= scmd
->device
->hostdata
;
5718 dev_err(&ctrl_info
->pci_dev
->dev
,
5719 "resetting scsi %d:%d:%d:%d\n",
5720 shost
->host_no
, device
->bus
, device
->target
, device
->lun
);
5722 pqi_check_ctrl_health(ctrl_info
);
5723 if (pqi_ctrl_offline(ctrl_info
)) {
5724 dev_err(&ctrl_info
->pci_dev
->dev
,
5725 "controller %u offlined - cannot send device reset\n",
5726 ctrl_info
->ctrl_id
);
5731 pqi_wait_until_ofa_finished(ctrl_info
);
5733 rc
= pqi_device_reset(ctrl_info
, device
);
5735 dev_err(&ctrl_info
->pci_dev
->dev
,
5736 "reset of scsi %d:%d:%d:%d: %s\n",
5737 shost
->host_no
, device
->bus
, device
->target
, device
->lun
,
5738 rc
== SUCCESS
? "SUCCESS" : "FAILED");
5743 static int pqi_slave_alloc(struct scsi_device
*sdev
)
5745 struct pqi_scsi_dev
*device
;
5746 unsigned long flags
;
5747 struct pqi_ctrl_info
*ctrl_info
;
5748 struct scsi_target
*starget
;
5749 struct sas_rphy
*rphy
;
5751 ctrl_info
= shost_to_hba(sdev
->host
);
5753 spin_lock_irqsave(&ctrl_info
->scsi_device_list_lock
, flags
);
5755 if (sdev_channel(sdev
) == PQI_PHYSICAL_DEVICE_BUS
) {
5756 starget
= scsi_target(sdev
);
5757 rphy
= target_to_rphy(starget
);
5758 device
= pqi_find_device_by_sas_rphy(ctrl_info
, rphy
);
5760 device
->target
= sdev_id(sdev
);
5761 device
->lun
= sdev
->lun
;
5762 device
->target_lun_valid
= true;
5765 device
= pqi_find_scsi_dev(ctrl_info
, sdev_channel(sdev
),
5766 sdev_id(sdev
), sdev
->lun
);
5770 sdev
->hostdata
= device
;
5771 device
->sdev
= sdev
;
5772 if (device
->queue_depth
) {
5773 device
->advertised_queue_depth
= device
->queue_depth
;
5774 scsi_change_queue_depth(sdev
,
5775 device
->advertised_queue_depth
);
5777 if (pqi_is_logical_device(device
))
5778 pqi_disable_write_same(sdev
);
5780 sdev
->allow_restart
= 1;
5783 spin_unlock_irqrestore(&ctrl_info
->scsi_device_list_lock
, flags
);
5788 static int pqi_map_queues(struct Scsi_Host
*shost
)
5790 struct pqi_ctrl_info
*ctrl_info
= shost_to_hba(shost
);
5792 return blk_mq_pci_map_queues(&shost
->tag_set
.map
[0],
5793 ctrl_info
->pci_dev
, 0);
5796 static int pqi_getpciinfo_ioctl(struct pqi_ctrl_info
*ctrl_info
,
5799 struct pci_dev
*pci_dev
;
5800 u32 subsystem_vendor
;
5801 u32 subsystem_device
;
5802 cciss_pci_info_struct pciinfo
;
5807 pci_dev
= ctrl_info
->pci_dev
;
5809 pciinfo
.domain
= pci_domain_nr(pci_dev
->bus
);
5810 pciinfo
.bus
= pci_dev
->bus
->number
;
5811 pciinfo
.dev_fn
= pci_dev
->devfn
;
5812 subsystem_vendor
= pci_dev
->subsystem_vendor
;
5813 subsystem_device
= pci_dev
->subsystem_device
;
5814 pciinfo
.board_id
= ((subsystem_device
<< 16) & 0xffff0000) |
5817 if (copy_to_user(arg
, &pciinfo
, sizeof(pciinfo
)))
5823 static int pqi_getdrivver_ioctl(void __user
*arg
)
5830 version
= (DRIVER_MAJOR
<< 28) | (DRIVER_MINOR
<< 24) |
5831 (DRIVER_RELEASE
<< 16) | DRIVER_REVISION
;
5833 if (copy_to_user(arg
, &version
, sizeof(version
)))
5839 struct ciss_error_info
{
5842 size_t sense_data_length
;
5845 static void pqi_error_info_to_ciss(struct pqi_raid_error_info
*pqi_error_info
,
5846 struct ciss_error_info
*ciss_error_info
)
5848 int ciss_cmd_status
;
5849 size_t sense_data_length
;
5851 switch (pqi_error_info
->data_out_result
) {
5852 case PQI_DATA_IN_OUT_GOOD
:
5853 ciss_cmd_status
= CISS_CMD_STATUS_SUCCESS
;
5855 case PQI_DATA_IN_OUT_UNDERFLOW
:
5856 ciss_cmd_status
= CISS_CMD_STATUS_DATA_UNDERRUN
;
5858 case PQI_DATA_IN_OUT_BUFFER_OVERFLOW
:
5859 ciss_cmd_status
= CISS_CMD_STATUS_DATA_OVERRUN
;
5861 case PQI_DATA_IN_OUT_PROTOCOL_ERROR
:
5862 case PQI_DATA_IN_OUT_BUFFER_ERROR
:
5863 case PQI_DATA_IN_OUT_BUFFER_OVERFLOW_DESCRIPTOR_AREA
:
5864 case PQI_DATA_IN_OUT_BUFFER_OVERFLOW_BRIDGE
:
5865 case PQI_DATA_IN_OUT_ERROR
:
5866 ciss_cmd_status
= CISS_CMD_STATUS_PROTOCOL_ERROR
;
5868 case PQI_DATA_IN_OUT_HARDWARE_ERROR
:
5869 case PQI_DATA_IN_OUT_PCIE_FABRIC_ERROR
:
5870 case PQI_DATA_IN_OUT_PCIE_COMPLETION_TIMEOUT
:
5871 case PQI_DATA_IN_OUT_PCIE_COMPLETER_ABORT_RECEIVED
:
5872 case PQI_DATA_IN_OUT_PCIE_UNSUPPORTED_REQUEST_RECEIVED
:
5873 case PQI_DATA_IN_OUT_PCIE_ECRC_CHECK_FAILED
:
5874 case PQI_DATA_IN_OUT_PCIE_UNSUPPORTED_REQUEST
:
5875 case PQI_DATA_IN_OUT_PCIE_ACS_VIOLATION
:
5876 case PQI_DATA_IN_OUT_PCIE_TLP_PREFIX_BLOCKED
:
5877 case PQI_DATA_IN_OUT_PCIE_POISONED_MEMORY_READ
:
5878 ciss_cmd_status
= CISS_CMD_STATUS_HARDWARE_ERROR
;
5880 case PQI_DATA_IN_OUT_UNSOLICITED_ABORT
:
5881 ciss_cmd_status
= CISS_CMD_STATUS_UNSOLICITED_ABORT
;
5883 case PQI_DATA_IN_OUT_ABORTED
:
5884 ciss_cmd_status
= CISS_CMD_STATUS_ABORTED
;
5886 case PQI_DATA_IN_OUT_TIMEOUT
:
5887 ciss_cmd_status
= CISS_CMD_STATUS_TIMEOUT
;
5890 ciss_cmd_status
= CISS_CMD_STATUS_TARGET_STATUS
;
5895 get_unaligned_le16(&pqi_error_info
->sense_data_length
);
5896 if (sense_data_length
== 0)
5898 get_unaligned_le16(&pqi_error_info
->response_data_length
);
5899 if (sense_data_length
)
5900 if (sense_data_length
> sizeof(pqi_error_info
->data
))
5901 sense_data_length
= sizeof(pqi_error_info
->data
);
5903 ciss_error_info
->scsi_status
= pqi_error_info
->status
;
5904 ciss_error_info
->command_status
= ciss_cmd_status
;
5905 ciss_error_info
->sense_data_length
= sense_data_length
;
5908 static int pqi_passthru_ioctl(struct pqi_ctrl_info
*ctrl_info
, void __user
*arg
)
5911 char *kernel_buffer
= NULL
;
5913 size_t sense_data_length
;
5914 IOCTL_Command_struct iocommand
;
5915 struct pqi_raid_path_request request
;
5916 struct pqi_raid_error_info pqi_error_info
;
5917 struct ciss_error_info ciss_error_info
;
5919 if (pqi_ctrl_offline(ctrl_info
))
5923 if (!capable(CAP_SYS_RAWIO
))
5925 if (copy_from_user(&iocommand
, arg
, sizeof(iocommand
)))
5927 if (iocommand
.buf_size
< 1 &&
5928 iocommand
.Request
.Type
.Direction
!= XFER_NONE
)
5930 if (iocommand
.Request
.CDBLen
> sizeof(request
.cdb
))
5932 if (iocommand
.Request
.Type
.Type
!= TYPE_CMD
)
5935 switch (iocommand
.Request
.Type
.Direction
) {
5939 case XFER_READ
| XFER_WRITE
:
5945 if (iocommand
.buf_size
> 0) {
5946 kernel_buffer
= kmalloc(iocommand
.buf_size
, GFP_KERNEL
);
5949 if (iocommand
.Request
.Type
.Direction
& XFER_WRITE
) {
5950 if (copy_from_user(kernel_buffer
, iocommand
.buf
,
5951 iocommand
.buf_size
)) {
5956 memset(kernel_buffer
, 0, iocommand
.buf_size
);
5960 memset(&request
, 0, sizeof(request
));
5962 request
.header
.iu_type
= PQI_REQUEST_IU_RAID_PATH_IO
;
5963 iu_length
= offsetof(struct pqi_raid_path_request
, sg_descriptors
) -
5964 PQI_REQUEST_HEADER_LENGTH
;
5965 memcpy(request
.lun_number
, iocommand
.LUN_info
.LunAddrBytes
,
5966 sizeof(request
.lun_number
));
5967 memcpy(request
.cdb
, iocommand
.Request
.CDB
, iocommand
.Request
.CDBLen
);
5968 request
.additional_cdb_bytes_usage
= SOP_ADDITIONAL_CDB_BYTES_0
;
5970 switch (iocommand
.Request
.Type
.Direction
) {
5972 request
.data_direction
= SOP_NO_DIRECTION_FLAG
;
5975 request
.data_direction
= SOP_WRITE_FLAG
;
5978 request
.data_direction
= SOP_READ_FLAG
;
5980 case XFER_READ
| XFER_WRITE
:
5981 request
.data_direction
= SOP_BIDIRECTIONAL
;
5985 request
.task_attribute
= SOP_TASK_ATTRIBUTE_SIMPLE
;
5987 if (iocommand
.buf_size
> 0) {
5988 put_unaligned_le32(iocommand
.buf_size
, &request
.buffer_length
);
5990 rc
= pqi_map_single(ctrl_info
->pci_dev
,
5991 &request
.sg_descriptors
[0], kernel_buffer
,
5992 iocommand
.buf_size
, DMA_BIDIRECTIONAL
);
5996 iu_length
+= sizeof(request
.sg_descriptors
[0]);
5999 put_unaligned_le16(iu_length
, &request
.header
.iu_length
);
6001 rc
= pqi_submit_raid_request_synchronous(ctrl_info
, &request
.header
,
6002 PQI_SYNC_FLAGS_INTERRUPTABLE
, &pqi_error_info
, NO_TIMEOUT
);
6004 if (iocommand
.buf_size
> 0)
6005 pqi_pci_unmap(ctrl_info
->pci_dev
, request
.sg_descriptors
, 1,
6008 memset(&iocommand
.error_info
, 0, sizeof(iocommand
.error_info
));
6011 pqi_error_info_to_ciss(&pqi_error_info
, &ciss_error_info
);
6012 iocommand
.error_info
.ScsiStatus
= ciss_error_info
.scsi_status
;
6013 iocommand
.error_info
.CommandStatus
=
6014 ciss_error_info
.command_status
;
6015 sense_data_length
= ciss_error_info
.sense_data_length
;
6016 if (sense_data_length
) {
6017 if (sense_data_length
>
6018 sizeof(iocommand
.error_info
.SenseInfo
))
6020 sizeof(iocommand
.error_info
.SenseInfo
);
6021 memcpy(iocommand
.error_info
.SenseInfo
,
6022 pqi_error_info
.data
, sense_data_length
);
6023 iocommand
.error_info
.SenseLen
= sense_data_length
;
6027 if (copy_to_user(arg
, &iocommand
, sizeof(iocommand
))) {
6032 if (rc
== 0 && iocommand
.buf_size
> 0 &&
6033 (iocommand
.Request
.Type
.Direction
& XFER_READ
)) {
6034 if (copy_to_user(iocommand
.buf
, kernel_buffer
,
6035 iocommand
.buf_size
)) {
6041 kfree(kernel_buffer
);
6046 static int pqi_ioctl(struct scsi_device
*sdev
, int cmd
, void __user
*arg
)
6049 struct pqi_ctrl_info
*ctrl_info
;
6051 ctrl_info
= shost_to_hba(sdev
->host
);
6053 if (pqi_ctrl_in_ofa(ctrl_info
))
6057 case CCISS_DEREGDISK
:
6058 case CCISS_REGNEWDISK
:
6060 rc
= pqi_scan_scsi_devices(ctrl_info
);
6062 case CCISS_GETPCIINFO
:
6063 rc
= pqi_getpciinfo_ioctl(ctrl_info
, arg
);
6065 case CCISS_GETDRIVVER
:
6066 rc
= pqi_getdrivver_ioctl(arg
);
6068 case CCISS_PASSTHRU
:
6069 rc
= pqi_passthru_ioctl(ctrl_info
, arg
);
6079 static ssize_t
pqi_version_show(struct device
*dev
,
6080 struct device_attribute
*attr
, char *buffer
)
6083 struct Scsi_Host
*shost
;
6084 struct pqi_ctrl_info
*ctrl_info
;
6086 shost
= class_to_shost(dev
);
6087 ctrl_info
= shost_to_hba(shost
);
6089 count
+= snprintf(buffer
+ count
, PAGE_SIZE
- count
,
6090 " driver: %s\n", DRIVER_VERSION BUILD_TIMESTAMP
);
6092 count
+= snprintf(buffer
+ count
, PAGE_SIZE
- count
,
6093 "firmware: %s\n", ctrl_info
->firmware_version
);
6098 static ssize_t
pqi_host_rescan_store(struct device
*dev
,
6099 struct device_attribute
*attr
, const char *buffer
, size_t count
)
6101 struct Scsi_Host
*shost
= class_to_shost(dev
);
6103 pqi_scan_start(shost
);
6108 static ssize_t
pqi_lockup_action_show(struct device
*dev
,
6109 struct device_attribute
*attr
, char *buffer
)
6114 for (i
= 0; i
< ARRAY_SIZE(pqi_lockup_actions
); i
++) {
6115 if (pqi_lockup_actions
[i
].action
== pqi_lockup_action
)
6116 count
+= snprintf(buffer
+ count
, PAGE_SIZE
- count
,
6117 "[%s] ", pqi_lockup_actions
[i
].name
);
6119 count
+= snprintf(buffer
+ count
, PAGE_SIZE
- count
,
6120 "%s ", pqi_lockup_actions
[i
].name
);
6123 count
+= snprintf(buffer
+ count
, PAGE_SIZE
- count
, "\n");
6128 static ssize_t
pqi_lockup_action_store(struct device
*dev
,
6129 struct device_attribute
*attr
, const char *buffer
, size_t count
)
6133 char action_name_buffer
[32];
6135 strlcpy(action_name_buffer
, buffer
, sizeof(action_name_buffer
));
6136 action_name
= strstrip(action_name_buffer
);
6138 for (i
= 0; i
< ARRAY_SIZE(pqi_lockup_actions
); i
++) {
6139 if (strcmp(action_name
, pqi_lockup_actions
[i
].name
) == 0) {
6140 pqi_lockup_action
= pqi_lockup_actions
[i
].action
;
6148 static DEVICE_ATTR(version
, 0444, pqi_version_show
, NULL
);
6149 static DEVICE_ATTR(rescan
, 0200, NULL
, pqi_host_rescan_store
);
6150 static DEVICE_ATTR(lockup_action
, 0644,
6151 pqi_lockup_action_show
, pqi_lockup_action_store
);
6153 static struct device_attribute
*pqi_shost_attrs
[] = {
6156 &dev_attr_lockup_action
,
6160 static ssize_t
pqi_unique_id_show(struct device
*dev
,
6161 struct device_attribute
*attr
, char *buffer
)
6163 struct pqi_ctrl_info
*ctrl_info
;
6164 struct scsi_device
*sdev
;
6165 struct pqi_scsi_dev
*device
;
6166 unsigned long flags
;
6167 unsigned char uid
[16];
6169 sdev
= to_scsi_device(dev
);
6170 ctrl_info
= shost_to_hba(sdev
->host
);
6172 spin_lock_irqsave(&ctrl_info
->scsi_device_list_lock
, flags
);
6174 device
= sdev
->hostdata
;
6176 spin_unlock_irqrestore(&ctrl_info
->scsi_device_list_lock
,
6180 memcpy(uid
, device
->unique_id
, sizeof(uid
));
6182 spin_unlock_irqrestore(&ctrl_info
->scsi_device_list_lock
, flags
);
6184 return snprintf(buffer
, PAGE_SIZE
,
6185 "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n",
6186 uid
[0], uid
[1], uid
[2], uid
[3],
6187 uid
[4], uid
[5], uid
[6], uid
[7],
6188 uid
[8], uid
[9], uid
[10], uid
[11],
6189 uid
[12], uid
[13], uid
[14], uid
[15]);
6192 static ssize_t
pqi_lunid_show(struct device
*dev
,
6193 struct device_attribute
*attr
, char *buffer
)
6195 struct pqi_ctrl_info
*ctrl_info
;
6196 struct scsi_device
*sdev
;
6197 struct pqi_scsi_dev
*device
;
6198 unsigned long flags
;
6201 sdev
= to_scsi_device(dev
);
6202 ctrl_info
= shost_to_hba(sdev
->host
);
6204 spin_lock_irqsave(&ctrl_info
->scsi_device_list_lock
, flags
);
6206 device
= sdev
->hostdata
;
6208 spin_unlock_irqrestore(&ctrl_info
->scsi_device_list_lock
,
6212 memcpy(lunid
, device
->scsi3addr
, sizeof(lunid
));
6214 spin_unlock_irqrestore(&ctrl_info
->scsi_device_list_lock
, flags
);
6216 return snprintf(buffer
, PAGE_SIZE
, "0x%8phN\n", lunid
);
6220 static ssize_t
pqi_path_info_show(struct device
*dev
,
6221 struct device_attribute
*attr
, char *buf
)
6223 struct pqi_ctrl_info
*ctrl_info
;
6224 struct scsi_device
*sdev
;
6225 struct pqi_scsi_dev
*device
;
6226 unsigned long flags
;
6231 u8 path_map_index
= 0;
6233 unsigned char phys_connector
[2];
6235 sdev
= to_scsi_device(dev
);
6236 ctrl_info
= shost_to_hba(sdev
->host
);
6238 spin_lock_irqsave(&ctrl_info
->scsi_device_list_lock
, flags
);
6240 device
= sdev
->hostdata
;
6242 spin_unlock_irqrestore(&ctrl_info
->scsi_device_list_lock
,
6248 for (i
= 0; i
< MAX_PATHS
; i
++) {
6249 path_map_index
= 1<<i
;
6250 if (i
== device
->active_path_index
)
6252 else if (device
->path_map
& path_map_index
)
6253 active
= "Inactive";
6257 output_len
+= scnprintf(buf
+ output_len
,
6258 PAGE_SIZE
- output_len
,
6259 "[%d:%d:%d:%d] %20.20s ",
6260 ctrl_info
->scsi_host
->host_no
,
6261 device
->bus
, device
->target
,
6263 scsi_device_type(device
->devtype
));
6265 if (device
->devtype
== TYPE_RAID
||
6266 pqi_is_logical_device(device
))
6269 memcpy(&phys_connector
, &device
->phys_connector
[i
],
6270 sizeof(phys_connector
));
6271 if (phys_connector
[0] < '0')
6272 phys_connector
[0] = '0';
6273 if (phys_connector
[1] < '0')
6274 phys_connector
[1] = '0';
6276 output_len
+= scnprintf(buf
+ output_len
,
6277 PAGE_SIZE
- output_len
,
6278 "PORT: %.2s ", phys_connector
);
6280 box
= device
->box
[i
];
6281 if (box
!= 0 && box
!= 0xFF)
6282 output_len
+= scnprintf(buf
+ output_len
,
6283 PAGE_SIZE
- output_len
,
6286 if ((device
->devtype
== TYPE_DISK
||
6287 device
->devtype
== TYPE_ZBC
) &&
6288 pqi_expose_device(device
))
6289 output_len
+= scnprintf(buf
+ output_len
,
6290 PAGE_SIZE
- output_len
,
6294 output_len
+= scnprintf(buf
+ output_len
,
6295 PAGE_SIZE
- output_len
,
6299 spin_unlock_irqrestore(&ctrl_info
->scsi_device_list_lock
, flags
);
6304 static ssize_t
pqi_sas_address_show(struct device
*dev
,
6305 struct device_attribute
*attr
, char *buffer
)
6307 struct pqi_ctrl_info
*ctrl_info
;
6308 struct scsi_device
*sdev
;
6309 struct pqi_scsi_dev
*device
;
6310 unsigned long flags
;
6313 sdev
= to_scsi_device(dev
);
6314 ctrl_info
= shost_to_hba(sdev
->host
);
6316 spin_lock_irqsave(&ctrl_info
->scsi_device_list_lock
, flags
);
6318 device
= sdev
->hostdata
;
6319 if (pqi_is_logical_device(device
)) {
6320 spin_unlock_irqrestore(&ctrl_info
->scsi_device_list_lock
,
6324 sas_address
= device
->sas_address
;
6326 spin_unlock_irqrestore(&ctrl_info
->scsi_device_list_lock
, flags
);
6328 return snprintf(buffer
, PAGE_SIZE
, "0x%016llx\n", sas_address
);
6331 static ssize_t
pqi_ssd_smart_path_enabled_show(struct device
*dev
,
6332 struct device_attribute
*attr
, char *buffer
)
6334 struct pqi_ctrl_info
*ctrl_info
;
6335 struct scsi_device
*sdev
;
6336 struct pqi_scsi_dev
*device
;
6337 unsigned long flags
;
6339 sdev
= to_scsi_device(dev
);
6340 ctrl_info
= shost_to_hba(sdev
->host
);
6342 spin_lock_irqsave(&ctrl_info
->scsi_device_list_lock
, flags
);
6344 device
= sdev
->hostdata
;
6345 buffer
[0] = device
->raid_bypass_enabled
? '1' : '0';
6349 spin_unlock_irqrestore(&ctrl_info
->scsi_device_list_lock
, flags
);
6354 static ssize_t
pqi_raid_level_show(struct device
*dev
,
6355 struct device_attribute
*attr
, char *buffer
)
6357 struct pqi_ctrl_info
*ctrl_info
;
6358 struct scsi_device
*sdev
;
6359 struct pqi_scsi_dev
*device
;
6360 unsigned long flags
;
6363 sdev
= to_scsi_device(dev
);
6364 ctrl_info
= shost_to_hba(sdev
->host
);
6366 spin_lock_irqsave(&ctrl_info
->scsi_device_list_lock
, flags
);
6368 device
= sdev
->hostdata
;
6370 if (pqi_is_logical_device(device
))
6371 raid_level
= pqi_raid_level_to_string(device
->raid_level
);
6375 spin_unlock_irqrestore(&ctrl_info
->scsi_device_list_lock
, flags
);
6377 return snprintf(buffer
, PAGE_SIZE
, "%s\n", raid_level
);
6380 static DEVICE_ATTR(lunid
, 0444, pqi_lunid_show
, NULL
);
6381 static DEVICE_ATTR(unique_id
, 0444, pqi_unique_id_show
, NULL
);
6382 static DEVICE_ATTR(path_info
, 0444, pqi_path_info_show
, NULL
);
6383 static DEVICE_ATTR(sas_address
, 0444, pqi_sas_address_show
, NULL
);
6384 static DEVICE_ATTR(ssd_smart_path_enabled
, 0444,
6385 pqi_ssd_smart_path_enabled_show
, NULL
);
6386 static DEVICE_ATTR(raid_level
, 0444, pqi_raid_level_show
, NULL
);
6388 static struct device_attribute
*pqi_sdev_attrs
[] = {
6390 &dev_attr_unique_id
,
6391 &dev_attr_path_info
,
6392 &dev_attr_sas_address
,
6393 &dev_attr_ssd_smart_path_enabled
,
6394 &dev_attr_raid_level
,
6398 static struct scsi_host_template pqi_driver_template
= {
6399 .module
= THIS_MODULE
,
6400 .name
= DRIVER_NAME_SHORT
,
6401 .proc_name
= DRIVER_NAME_SHORT
,
6402 .queuecommand
= pqi_scsi_queue_command
,
6403 .scan_start
= pqi_scan_start
,
6404 .scan_finished
= pqi_scan_finished
,
6406 .eh_device_reset_handler
= pqi_eh_device_reset_handler
,
6408 .slave_alloc
= pqi_slave_alloc
,
6409 .map_queues
= pqi_map_queues
,
6410 .sdev_attrs
= pqi_sdev_attrs
,
6411 .shost_attrs
= pqi_shost_attrs
,
6414 static int pqi_register_scsi(struct pqi_ctrl_info
*ctrl_info
)
6417 struct Scsi_Host
*shost
;
6419 shost
= scsi_host_alloc(&pqi_driver_template
, sizeof(ctrl_info
));
6421 dev_err(&ctrl_info
->pci_dev
->dev
,
6422 "scsi_host_alloc failed for controller %u\n",
6423 ctrl_info
->ctrl_id
);
6428 shost
->n_io_port
= 0;
6429 shost
->this_id
= -1;
6430 shost
->max_channel
= PQI_MAX_BUS
;
6431 shost
->max_cmd_len
= MAX_COMMAND_SIZE
;
6432 shost
->max_lun
= ~0;
6434 shost
->max_sectors
= ctrl_info
->max_sectors
;
6435 shost
->can_queue
= ctrl_info
->scsi_ml_can_queue
;
6436 shost
->cmd_per_lun
= shost
->can_queue
;
6437 shost
->sg_tablesize
= ctrl_info
->sg_tablesize
;
6438 shost
->transportt
= pqi_sas_transport_template
;
6439 shost
->irq
= pci_irq_vector(ctrl_info
->pci_dev
, 0);
6440 shost
->unique_id
= shost
->irq
;
6441 shost
->nr_hw_queues
= ctrl_info
->num_queue_groups
;
6442 shost
->hostdata
[0] = (unsigned long)ctrl_info
;
6444 rc
= scsi_add_host(shost
, &ctrl_info
->pci_dev
->dev
);
6446 dev_err(&ctrl_info
->pci_dev
->dev
,
6447 "scsi_add_host failed for controller %u\n",
6448 ctrl_info
->ctrl_id
);
6452 rc
= pqi_add_sas_host(shost
, ctrl_info
);
6454 dev_err(&ctrl_info
->pci_dev
->dev
,
6455 "add SAS host failed for controller %u\n",
6456 ctrl_info
->ctrl_id
);
6460 ctrl_info
->scsi_host
= shost
;
6465 scsi_remove_host(shost
);
6467 scsi_host_put(shost
);
6472 static void pqi_unregister_scsi(struct pqi_ctrl_info
*ctrl_info
)
6474 struct Scsi_Host
*shost
;
6476 pqi_delete_sas_host(ctrl_info
);
6478 shost
= ctrl_info
->scsi_host
;
6482 scsi_remove_host(shost
);
6483 scsi_host_put(shost
);
6486 static int pqi_wait_for_pqi_reset_completion(struct pqi_ctrl_info
*ctrl_info
)
6489 struct pqi_device_registers __iomem
*pqi_registers
;
6490 unsigned long timeout
;
6491 unsigned int timeout_msecs
;
6492 union pqi_reset_register reset_reg
;
6494 pqi_registers
= ctrl_info
->pqi_registers
;
6495 timeout_msecs
= readw(&pqi_registers
->max_reset_timeout
) * 100;
6496 timeout
= msecs_to_jiffies(timeout_msecs
) + jiffies
;
6499 msleep(PQI_RESET_POLL_INTERVAL_MSECS
);
6500 reset_reg
.all_bits
= readl(&pqi_registers
->device_reset
);
6501 if (reset_reg
.bits
.reset_action
== PQI_RESET_ACTION_COMPLETED
)
6503 pqi_check_ctrl_health(ctrl_info
);
6504 if (pqi_ctrl_offline(ctrl_info
)) {
6508 if (time_after(jiffies
, timeout
)) {
6517 static int pqi_reset(struct pqi_ctrl_info
*ctrl_info
)
6520 union pqi_reset_register reset_reg
;
6522 if (ctrl_info
->pqi_reset_quiesce_supported
) {
6523 rc
= sis_pqi_reset_quiesce(ctrl_info
);
6525 dev_err(&ctrl_info
->pci_dev
->dev
,
6526 "PQI reset failed during quiesce with error %d\n",
6532 reset_reg
.all_bits
= 0;
6533 reset_reg
.bits
.reset_type
= PQI_RESET_TYPE_HARD_RESET
;
6534 reset_reg
.bits
.reset_action
= PQI_RESET_ACTION_RESET
;
6536 writel(reset_reg
.all_bits
, &ctrl_info
->pqi_registers
->device_reset
);
6538 rc
= pqi_wait_for_pqi_reset_completion(ctrl_info
);
6540 dev_err(&ctrl_info
->pci_dev
->dev
,
6541 "PQI reset failed with error %d\n", rc
);
6546 static int pqi_get_ctrl_firmware_version(struct pqi_ctrl_info
*ctrl_info
)
6549 struct bmic_identify_controller
*identify
;
6551 identify
= kmalloc(sizeof(*identify
), GFP_KERNEL
);
6555 rc
= pqi_identify_controller(ctrl_info
, identify
);
6559 memcpy(ctrl_info
->firmware_version
, identify
->firmware_version
,
6560 sizeof(identify
->firmware_version
));
6561 ctrl_info
->firmware_version
[sizeof(identify
->firmware_version
)] = '\0';
6562 snprintf(ctrl_info
->firmware_version
+
6563 strlen(ctrl_info
->firmware_version
),
6564 sizeof(ctrl_info
->firmware_version
),
6565 "-%u", get_unaligned_le16(&identify
->firmware_build_number
));
6573 struct pqi_config_table_section_info
{
6574 struct pqi_ctrl_info
*ctrl_info
;
6577 void __iomem
*section_iomem_addr
;
6580 static inline bool pqi_is_firmware_feature_supported(
6581 struct pqi_config_table_firmware_features
*firmware_features
,
6582 unsigned int bit_position
)
6584 unsigned int byte_index
;
6586 byte_index
= bit_position
/ BITS_PER_BYTE
;
6588 if (byte_index
>= le16_to_cpu(firmware_features
->num_elements
))
6591 return firmware_features
->features_supported
[byte_index
] &
6592 (1 << (bit_position
% BITS_PER_BYTE
)) ? true : false;
6595 static inline bool pqi_is_firmware_feature_enabled(
6596 struct pqi_config_table_firmware_features
*firmware_features
,
6597 void __iomem
*firmware_features_iomem_addr
,
6598 unsigned int bit_position
)
6600 unsigned int byte_index
;
6601 u8 __iomem
*features_enabled_iomem_addr
;
6603 byte_index
= (bit_position
/ BITS_PER_BYTE
) +
6604 (le16_to_cpu(firmware_features
->num_elements
) * 2);
6606 features_enabled_iomem_addr
= firmware_features_iomem_addr
+
6607 offsetof(struct pqi_config_table_firmware_features
,
6608 features_supported
) + byte_index
;
6610 return *((__force u8
*)features_enabled_iomem_addr
) &
6611 (1 << (bit_position
% BITS_PER_BYTE
)) ? true : false;
6614 static inline void pqi_request_firmware_feature(
6615 struct pqi_config_table_firmware_features
*firmware_features
,
6616 unsigned int bit_position
)
6618 unsigned int byte_index
;
6620 byte_index
= (bit_position
/ BITS_PER_BYTE
) +
6621 le16_to_cpu(firmware_features
->num_elements
);
6623 firmware_features
->features_supported
[byte_index
] |=
6624 (1 << (bit_position
% BITS_PER_BYTE
));
6627 static int pqi_config_table_update(struct pqi_ctrl_info
*ctrl_info
,
6628 u16 first_section
, u16 last_section
)
6630 struct pqi_vendor_general_request request
;
6632 memset(&request
, 0, sizeof(request
));
6634 request
.header
.iu_type
= PQI_REQUEST_IU_VENDOR_GENERAL
;
6635 put_unaligned_le16(sizeof(request
) - PQI_REQUEST_HEADER_LENGTH
,
6636 &request
.header
.iu_length
);
6637 put_unaligned_le16(PQI_VENDOR_GENERAL_CONFIG_TABLE_UPDATE
,
6638 &request
.function_code
);
6639 put_unaligned_le16(first_section
,
6640 &request
.data
.config_table_update
.first_section
);
6641 put_unaligned_le16(last_section
,
6642 &request
.data
.config_table_update
.last_section
);
6644 return pqi_submit_raid_request_synchronous(ctrl_info
, &request
.header
,
6645 0, NULL
, NO_TIMEOUT
);
6648 static int pqi_enable_firmware_features(struct pqi_ctrl_info
*ctrl_info
,
6649 struct pqi_config_table_firmware_features
*firmware_features
,
6650 void __iomem
*firmware_features_iomem_addr
)
6652 void *features_requested
;
6653 void __iomem
*features_requested_iomem_addr
;
6655 features_requested
= firmware_features
->features_supported
+
6656 le16_to_cpu(firmware_features
->num_elements
);
6658 features_requested_iomem_addr
= firmware_features_iomem_addr
+
6659 (features_requested
- (void *)firmware_features
);
6661 memcpy_toio(features_requested_iomem_addr
, features_requested
,
6662 le16_to_cpu(firmware_features
->num_elements
));
6664 return pqi_config_table_update(ctrl_info
,
6665 PQI_CONFIG_TABLE_SECTION_FIRMWARE_FEATURES
,
6666 PQI_CONFIG_TABLE_SECTION_FIRMWARE_FEATURES
);
6669 struct pqi_firmware_feature
{
6671 unsigned int feature_bit
;
6674 void (*feature_status
)(struct pqi_ctrl_info
*ctrl_info
,
6675 struct pqi_firmware_feature
*firmware_feature
);
6678 static void pqi_firmware_feature_status(struct pqi_ctrl_info
*ctrl_info
,
6679 struct pqi_firmware_feature
*firmware_feature
)
6681 if (!firmware_feature
->supported
) {
6682 dev_info(&ctrl_info
->pci_dev
->dev
, "%s not supported by controller\n",
6683 firmware_feature
->feature_name
);
6687 if (firmware_feature
->enabled
) {
6688 dev_info(&ctrl_info
->pci_dev
->dev
,
6689 "%s enabled\n", firmware_feature
->feature_name
);
6693 dev_err(&ctrl_info
->pci_dev
->dev
, "failed to enable %s\n",
6694 firmware_feature
->feature_name
);
6697 static inline void pqi_firmware_feature_update(struct pqi_ctrl_info
*ctrl_info
,
6698 struct pqi_firmware_feature
*firmware_feature
)
6700 if (firmware_feature
->feature_status
)
6701 firmware_feature
->feature_status(ctrl_info
, firmware_feature
);
6704 static DEFINE_MUTEX(pqi_firmware_features_mutex
);
6706 static struct pqi_firmware_feature pqi_firmware_features
[] = {
6708 .feature_name
= "Online Firmware Activation",
6709 .feature_bit
= PQI_FIRMWARE_FEATURE_OFA
,
6710 .feature_status
= pqi_firmware_feature_status
,
6713 .feature_name
= "Serial Management Protocol",
6714 .feature_bit
= PQI_FIRMWARE_FEATURE_SMP
,
6715 .feature_status
= pqi_firmware_feature_status
,
6718 .feature_name
= "New Soft Reset Handshake",
6719 .feature_bit
= PQI_FIRMWARE_FEATURE_SOFT_RESET_HANDSHAKE
,
6720 .feature_status
= pqi_firmware_feature_status
,
6724 static void pqi_process_firmware_features(
6725 struct pqi_config_table_section_info
*section_info
)
6728 struct pqi_ctrl_info
*ctrl_info
;
6729 struct pqi_config_table_firmware_features
*firmware_features
;
6730 void __iomem
*firmware_features_iomem_addr
;
6732 unsigned int num_features_supported
;
6734 ctrl_info
= section_info
->ctrl_info
;
6735 firmware_features
= section_info
->section
;
6736 firmware_features_iomem_addr
= section_info
->section_iomem_addr
;
6738 for (i
= 0, num_features_supported
= 0;
6739 i
< ARRAY_SIZE(pqi_firmware_features
); i
++) {
6740 if (pqi_is_firmware_feature_supported(firmware_features
,
6741 pqi_firmware_features
[i
].feature_bit
)) {
6742 pqi_firmware_features
[i
].supported
= true;
6743 num_features_supported
++;
6745 pqi_firmware_feature_update(ctrl_info
,
6746 &pqi_firmware_features
[i
]);
6750 if (num_features_supported
== 0)
6753 for (i
= 0; i
< ARRAY_SIZE(pqi_firmware_features
); i
++) {
6754 if (!pqi_firmware_features
[i
].supported
)
6756 pqi_request_firmware_feature(firmware_features
,
6757 pqi_firmware_features
[i
].feature_bit
);
6760 rc
= pqi_enable_firmware_features(ctrl_info
, firmware_features
,
6761 firmware_features_iomem_addr
);
6763 dev_err(&ctrl_info
->pci_dev
->dev
,
6764 "failed to enable firmware features in PQI configuration table\n");
6765 for (i
= 0; i
< ARRAY_SIZE(pqi_firmware_features
); i
++) {
6766 if (!pqi_firmware_features
[i
].supported
)
6768 pqi_firmware_feature_update(ctrl_info
,
6769 &pqi_firmware_features
[i
]);
6774 ctrl_info
->soft_reset_handshake_supported
= false;
6775 for (i
= 0; i
< ARRAY_SIZE(pqi_firmware_features
); i
++) {
6776 if (!pqi_firmware_features
[i
].supported
)
6778 if (pqi_is_firmware_feature_enabled(firmware_features
,
6779 firmware_features_iomem_addr
,
6780 pqi_firmware_features
[i
].feature_bit
)) {
6781 pqi_firmware_features
[i
].enabled
= true;
6782 if (pqi_firmware_features
[i
].feature_bit
==
6783 PQI_FIRMWARE_FEATURE_SOFT_RESET_HANDSHAKE
)
6784 ctrl_info
->soft_reset_handshake_supported
=
6787 pqi_firmware_feature_update(ctrl_info
,
6788 &pqi_firmware_features
[i
]);
6792 static void pqi_init_firmware_features(void)
6796 for (i
= 0; i
< ARRAY_SIZE(pqi_firmware_features
); i
++) {
6797 pqi_firmware_features
[i
].supported
= false;
6798 pqi_firmware_features
[i
].enabled
= false;
6802 static void pqi_process_firmware_features_section(
6803 struct pqi_config_table_section_info
*section_info
)
6805 mutex_lock(&pqi_firmware_features_mutex
);
6806 pqi_init_firmware_features();
6807 pqi_process_firmware_features(section_info
);
6808 mutex_unlock(&pqi_firmware_features_mutex
);
6811 static int pqi_process_config_table(struct pqi_ctrl_info
*ctrl_info
)
6815 void __iomem
*table_iomem_addr
;
6816 struct pqi_config_table
*config_table
;
6817 struct pqi_config_table_section_header
*section
;
6818 struct pqi_config_table_section_info section_info
;
6820 table_length
= ctrl_info
->config_table_length
;
6821 if (table_length
== 0)
6824 config_table
= kmalloc(table_length
, GFP_KERNEL
);
6825 if (!config_table
) {
6826 dev_err(&ctrl_info
->pci_dev
->dev
,
6827 "failed to allocate memory for PQI configuration table\n");
6832 * Copy the config table contents from I/O memory space into the
6835 table_iomem_addr
= ctrl_info
->iomem_base
+
6836 ctrl_info
->config_table_offset
;
6837 memcpy_fromio(config_table
, table_iomem_addr
, table_length
);
6839 section_info
.ctrl_info
= ctrl_info
;
6841 get_unaligned_le32(&config_table
->first_section_offset
);
6843 while (section_offset
) {
6844 section
= (void *)config_table
+ section_offset
;
6846 section_info
.section
= section
;
6847 section_info
.section_offset
= section_offset
;
6848 section_info
.section_iomem_addr
=
6849 table_iomem_addr
+ section_offset
;
6851 switch (get_unaligned_le16(§ion
->section_id
)) {
6852 case PQI_CONFIG_TABLE_SECTION_FIRMWARE_FEATURES
:
6853 pqi_process_firmware_features_section(§ion_info
);
6855 case PQI_CONFIG_TABLE_SECTION_HEARTBEAT
:
6856 if (pqi_disable_heartbeat
)
6857 dev_warn(&ctrl_info
->pci_dev
->dev
,
6858 "heartbeat disabled by module parameter\n");
6860 ctrl_info
->heartbeat_counter
=
6864 struct pqi_config_table_heartbeat
,
6867 case PQI_CONFIG_TABLE_SECTION_SOFT_RESET
:
6868 ctrl_info
->soft_reset_status
=
6871 offsetof(struct pqi_config_table_soft_reset
,
6877 get_unaligned_le16(§ion
->next_section_offset
);
6880 kfree(config_table
);
6885 /* Switches the controller from PQI mode back into SIS mode. */
6887 static int pqi_revert_to_sis_mode(struct pqi_ctrl_info
*ctrl_info
)
6891 pqi_change_irq_mode(ctrl_info
, IRQ_MODE_NONE
);
6892 rc
= pqi_reset(ctrl_info
);
6895 rc
= sis_reenable_sis_mode(ctrl_info
);
6897 dev_err(&ctrl_info
->pci_dev
->dev
,
6898 "re-enabling SIS mode failed with error %d\n", rc
);
6901 pqi_save_ctrl_mode(ctrl_info
, SIS_MODE
);
6907 * If the controller isn't already in SIS mode, this function forces it into
6911 static int pqi_force_sis_mode(struct pqi_ctrl_info
*ctrl_info
)
6913 if (!sis_is_firmware_running(ctrl_info
))
6916 if (pqi_get_ctrl_mode(ctrl_info
) == SIS_MODE
)
6919 if (sis_is_kernel_up(ctrl_info
)) {
6920 pqi_save_ctrl_mode(ctrl_info
, SIS_MODE
);
6924 return pqi_revert_to_sis_mode(ctrl_info
);
6927 static int pqi_ctrl_init(struct pqi_ctrl_info
*ctrl_info
)
6931 rc
= pqi_force_sis_mode(ctrl_info
);
6936 * Wait until the controller is ready to start accepting SIS
6939 rc
= sis_wait_for_ctrl_ready(ctrl_info
);
6944 * Get the controller properties. This allows us to determine
6945 * whether or not it supports PQI mode.
6947 rc
= sis_get_ctrl_properties(ctrl_info
);
6949 dev_err(&ctrl_info
->pci_dev
->dev
,
6950 "error obtaining controller properties\n");
6954 rc
= sis_get_pqi_capabilities(ctrl_info
);
6956 dev_err(&ctrl_info
->pci_dev
->dev
,
6957 "error obtaining controller capabilities\n");
6961 if (reset_devices
) {
6962 if (ctrl_info
->max_outstanding_requests
>
6963 PQI_MAX_OUTSTANDING_REQUESTS_KDUMP
)
6964 ctrl_info
->max_outstanding_requests
=
6965 PQI_MAX_OUTSTANDING_REQUESTS_KDUMP
;
6967 if (ctrl_info
->max_outstanding_requests
>
6968 PQI_MAX_OUTSTANDING_REQUESTS
)
6969 ctrl_info
->max_outstanding_requests
=
6970 PQI_MAX_OUTSTANDING_REQUESTS
;
6973 pqi_calculate_io_resources(ctrl_info
);
6975 rc
= pqi_alloc_error_buffer(ctrl_info
);
6977 dev_err(&ctrl_info
->pci_dev
->dev
,
6978 "failed to allocate PQI error buffer\n");
6983 * If the function we are about to call succeeds, the
6984 * controller will transition from legacy SIS mode
6987 rc
= sis_init_base_struct_addr(ctrl_info
);
6989 dev_err(&ctrl_info
->pci_dev
->dev
,
6990 "error initializing PQI mode\n");
6994 /* Wait for the controller to complete the SIS -> PQI transition. */
6995 rc
= pqi_wait_for_pqi_mode_ready(ctrl_info
);
6997 dev_err(&ctrl_info
->pci_dev
->dev
,
6998 "transition to PQI mode failed\n");
7002 /* From here on, we are running in PQI mode. */
7003 ctrl_info
->pqi_mode_enabled
= true;
7004 pqi_save_ctrl_mode(ctrl_info
, PQI_MODE
);
7006 rc
= pqi_alloc_admin_queues(ctrl_info
);
7008 dev_err(&ctrl_info
->pci_dev
->dev
,
7009 "failed to allocate admin queues\n");
7013 rc
= pqi_create_admin_queues(ctrl_info
);
7015 dev_err(&ctrl_info
->pci_dev
->dev
,
7016 "error creating admin queues\n");
7020 rc
= pqi_report_device_capability(ctrl_info
);
7022 dev_err(&ctrl_info
->pci_dev
->dev
,
7023 "obtaining device capability failed\n");
7027 rc
= pqi_validate_device_capability(ctrl_info
);
7031 pqi_calculate_queue_resources(ctrl_info
);
7033 rc
= pqi_enable_msix_interrupts(ctrl_info
);
7037 if (ctrl_info
->num_msix_vectors_enabled
< ctrl_info
->num_queue_groups
) {
7038 ctrl_info
->max_msix_vectors
=
7039 ctrl_info
->num_msix_vectors_enabled
;
7040 pqi_calculate_queue_resources(ctrl_info
);
7043 rc
= pqi_alloc_io_resources(ctrl_info
);
7047 rc
= pqi_alloc_operational_queues(ctrl_info
);
7049 dev_err(&ctrl_info
->pci_dev
->dev
,
7050 "failed to allocate operational queues\n");
7054 pqi_init_operational_queues(ctrl_info
);
7056 rc
= pqi_request_irqs(ctrl_info
);
7060 rc
= pqi_create_queues(ctrl_info
);
7064 pqi_change_irq_mode(ctrl_info
, IRQ_MODE_MSIX
);
7066 ctrl_info
->controller_online
= true;
7068 rc
= pqi_process_config_table(ctrl_info
);
7072 pqi_start_heartbeat_timer(ctrl_info
);
7074 rc
= pqi_enable_events(ctrl_info
);
7076 dev_err(&ctrl_info
->pci_dev
->dev
,
7077 "error enabling events\n");
7081 /* Register with the SCSI subsystem. */
7082 rc
= pqi_register_scsi(ctrl_info
);
7086 rc
= pqi_get_ctrl_firmware_version(ctrl_info
);
7088 dev_err(&ctrl_info
->pci_dev
->dev
,
7089 "error obtaining firmware version\n");
7093 rc
= pqi_set_diag_rescan(ctrl_info
);
7095 dev_err(&ctrl_info
->pci_dev
->dev
,
7096 "error enabling multi-lun rescan\n");
7100 rc
= pqi_write_driver_version_to_host_wellness(ctrl_info
);
7102 dev_err(&ctrl_info
->pci_dev
->dev
,
7103 "error updating host wellness\n");
7107 pqi_schedule_update_time_worker(ctrl_info
);
7109 pqi_scan_scsi_devices(ctrl_info
);
7114 static void pqi_reinit_queues(struct pqi_ctrl_info
*ctrl_info
)
7117 struct pqi_admin_queues
*admin_queues
;
7118 struct pqi_event_queue
*event_queue
;
7120 admin_queues
= &ctrl_info
->admin_queues
;
7121 admin_queues
->iq_pi_copy
= 0;
7122 admin_queues
->oq_ci_copy
= 0;
7123 writel(0, admin_queues
->oq_pi
);
7125 for (i
= 0; i
< ctrl_info
->num_queue_groups
; i
++) {
7126 ctrl_info
->queue_groups
[i
].iq_pi_copy
[RAID_PATH
] = 0;
7127 ctrl_info
->queue_groups
[i
].iq_pi_copy
[AIO_PATH
] = 0;
7128 ctrl_info
->queue_groups
[i
].oq_ci_copy
= 0;
7130 writel(0, ctrl_info
->queue_groups
[i
].iq_ci
[RAID_PATH
]);
7131 writel(0, ctrl_info
->queue_groups
[i
].iq_ci
[AIO_PATH
]);
7132 writel(0, ctrl_info
->queue_groups
[i
].oq_pi
);
7135 event_queue
= &ctrl_info
->event_queue
;
7136 writel(0, event_queue
->oq_pi
);
7137 event_queue
->oq_ci_copy
= 0;
7140 static int pqi_ctrl_init_resume(struct pqi_ctrl_info
*ctrl_info
)
7144 rc
= pqi_force_sis_mode(ctrl_info
);
7149 * Wait until the controller is ready to start accepting SIS
7152 rc
= sis_wait_for_ctrl_ready_resume(ctrl_info
);
7157 * Get the controller properties. This allows us to determine
7158 * whether or not it supports PQI mode.
7160 rc
= sis_get_ctrl_properties(ctrl_info
);
7162 dev_err(&ctrl_info
->pci_dev
->dev
,
7163 "error obtaining controller properties\n");
7167 rc
= sis_get_pqi_capabilities(ctrl_info
);
7169 dev_err(&ctrl_info
->pci_dev
->dev
,
7170 "error obtaining controller capabilities\n");
7175 * If the function we are about to call succeeds, the
7176 * controller will transition from legacy SIS mode
7179 rc
= sis_init_base_struct_addr(ctrl_info
);
7181 dev_err(&ctrl_info
->pci_dev
->dev
,
7182 "error initializing PQI mode\n");
7186 /* Wait for the controller to complete the SIS -> PQI transition. */
7187 rc
= pqi_wait_for_pqi_mode_ready(ctrl_info
);
7189 dev_err(&ctrl_info
->pci_dev
->dev
,
7190 "transition to PQI mode failed\n");
7194 /* From here on, we are running in PQI mode. */
7195 ctrl_info
->pqi_mode_enabled
= true;
7196 pqi_save_ctrl_mode(ctrl_info
, PQI_MODE
);
7198 pqi_reinit_queues(ctrl_info
);
7200 rc
= pqi_create_admin_queues(ctrl_info
);
7202 dev_err(&ctrl_info
->pci_dev
->dev
,
7203 "error creating admin queues\n");
7207 rc
= pqi_create_queues(ctrl_info
);
7211 pqi_change_irq_mode(ctrl_info
, IRQ_MODE_MSIX
);
7213 ctrl_info
->controller_online
= true;
7214 pqi_ctrl_unblock_requests(ctrl_info
);
7216 rc
= pqi_process_config_table(ctrl_info
);
7220 pqi_start_heartbeat_timer(ctrl_info
);
7222 rc
= pqi_enable_events(ctrl_info
);
7224 dev_err(&ctrl_info
->pci_dev
->dev
,
7225 "error enabling events\n");
7229 rc
= pqi_get_ctrl_firmware_version(ctrl_info
);
7231 dev_err(&ctrl_info
->pci_dev
->dev
,
7232 "error obtaining firmware version\n");
7236 rc
= pqi_set_diag_rescan(ctrl_info
);
7238 dev_err(&ctrl_info
->pci_dev
->dev
,
7239 "error enabling multi-lun rescan\n");
7243 rc
= pqi_write_driver_version_to_host_wellness(ctrl_info
);
7245 dev_err(&ctrl_info
->pci_dev
->dev
,
7246 "error updating host wellness\n");
7250 pqi_schedule_update_time_worker(ctrl_info
);
7252 pqi_scan_scsi_devices(ctrl_info
);
7257 static inline int pqi_set_pcie_completion_timeout(struct pci_dev
*pci_dev
,
7260 return pcie_capability_clear_and_set_word(pci_dev
, PCI_EXP_DEVCTL2
,
7261 PCI_EXP_DEVCTL2_COMP_TIMEOUT
, timeout
);
7264 static int pqi_pci_init(struct pqi_ctrl_info
*ctrl_info
)
7269 rc
= pci_enable_device(ctrl_info
->pci_dev
);
7271 dev_err(&ctrl_info
->pci_dev
->dev
,
7272 "failed to enable PCI device\n");
7276 if (sizeof(dma_addr_t
) > 4)
7277 mask
= DMA_BIT_MASK(64);
7279 mask
= DMA_BIT_MASK(32);
7281 rc
= dma_set_mask(&ctrl_info
->pci_dev
->dev
, mask
);
7283 dev_err(&ctrl_info
->pci_dev
->dev
, "failed to set DMA mask\n");
7284 goto disable_device
;
7287 rc
= pci_request_regions(ctrl_info
->pci_dev
, DRIVER_NAME_SHORT
);
7289 dev_err(&ctrl_info
->pci_dev
->dev
,
7290 "failed to obtain PCI resources\n");
7291 goto disable_device
;
7294 ctrl_info
->iomem_base
= ioremap_nocache(pci_resource_start(
7295 ctrl_info
->pci_dev
, 0),
7296 sizeof(struct pqi_ctrl_registers
));
7297 if (!ctrl_info
->iomem_base
) {
7298 dev_err(&ctrl_info
->pci_dev
->dev
,
7299 "failed to map memory for controller registers\n");
7301 goto release_regions
;
7304 #define PCI_EXP_COMP_TIMEOUT_65_TO_210_MS 0x6
7306 /* Increase the PCIe completion timeout. */
7307 rc
= pqi_set_pcie_completion_timeout(ctrl_info
->pci_dev
,
7308 PCI_EXP_COMP_TIMEOUT_65_TO_210_MS
);
7310 dev_err(&ctrl_info
->pci_dev
->dev
,
7311 "failed to set PCIe completion timeout\n");
7312 goto release_regions
;
7315 /* Enable bus mastering. */
7316 pci_set_master(ctrl_info
->pci_dev
);
7318 ctrl_info
->registers
= ctrl_info
->iomem_base
;
7319 ctrl_info
->pqi_registers
= &ctrl_info
->registers
->pqi_registers
;
7321 pci_set_drvdata(ctrl_info
->pci_dev
, ctrl_info
);
7326 pci_release_regions(ctrl_info
->pci_dev
);
7328 pci_disable_device(ctrl_info
->pci_dev
);
7333 static void pqi_cleanup_pci_init(struct pqi_ctrl_info
*ctrl_info
)
7335 iounmap(ctrl_info
->iomem_base
);
7336 pci_release_regions(ctrl_info
->pci_dev
);
7337 if (pci_is_enabled(ctrl_info
->pci_dev
))
7338 pci_disable_device(ctrl_info
->pci_dev
);
7339 pci_set_drvdata(ctrl_info
->pci_dev
, NULL
);
7342 static struct pqi_ctrl_info
*pqi_alloc_ctrl_info(int numa_node
)
7344 struct pqi_ctrl_info
*ctrl_info
;
7346 ctrl_info
= kzalloc_node(sizeof(struct pqi_ctrl_info
),
7347 GFP_KERNEL
, numa_node
);
7351 mutex_init(&ctrl_info
->scan_mutex
);
7352 mutex_init(&ctrl_info
->lun_reset_mutex
);
7353 mutex_init(&ctrl_info
->ofa_mutex
);
7355 INIT_LIST_HEAD(&ctrl_info
->scsi_device_list
);
7356 spin_lock_init(&ctrl_info
->scsi_device_list_lock
);
7358 INIT_WORK(&ctrl_info
->event_work
, pqi_event_worker
);
7359 atomic_set(&ctrl_info
->num_interrupts
, 0);
7361 INIT_DELAYED_WORK(&ctrl_info
->rescan_work
, pqi_rescan_worker
);
7362 INIT_DELAYED_WORK(&ctrl_info
->update_time_work
, pqi_update_time_worker
);
7364 timer_setup(&ctrl_info
->heartbeat_timer
, pqi_heartbeat_timer_handler
, 0);
7365 INIT_WORK(&ctrl_info
->ctrl_offline_work
, pqi_ctrl_offline_worker
);
7367 sema_init(&ctrl_info
->sync_request_sem
,
7368 PQI_RESERVED_IO_SLOTS_SYNCHRONOUS_REQUESTS
);
7369 init_waitqueue_head(&ctrl_info
->block_requests_wait
);
7371 INIT_LIST_HEAD(&ctrl_info
->raid_bypass_retry_list
);
7372 spin_lock_init(&ctrl_info
->raid_bypass_retry_list_lock
);
7373 INIT_WORK(&ctrl_info
->raid_bypass_retry_work
,
7374 pqi_raid_bypass_retry_worker
);
7376 ctrl_info
->ctrl_id
= atomic_inc_return(&pqi_controller_count
) - 1;
7377 ctrl_info
->irq_mode
= IRQ_MODE_NONE
;
7378 ctrl_info
->max_msix_vectors
= PQI_MAX_MSIX_VECTORS
;
7383 static inline void pqi_free_ctrl_info(struct pqi_ctrl_info
*ctrl_info
)
7388 static void pqi_free_interrupts(struct pqi_ctrl_info
*ctrl_info
)
7390 pqi_free_irqs(ctrl_info
);
7391 pqi_disable_msix_interrupts(ctrl_info
);
7394 static void pqi_free_ctrl_resources(struct pqi_ctrl_info
*ctrl_info
)
7396 pqi_stop_heartbeat_timer(ctrl_info
);
7397 pqi_free_interrupts(ctrl_info
);
7398 if (ctrl_info
->queue_memory_base
)
7399 dma_free_coherent(&ctrl_info
->pci_dev
->dev
,
7400 ctrl_info
->queue_memory_length
,
7401 ctrl_info
->queue_memory_base
,
7402 ctrl_info
->queue_memory_base_dma_handle
);
7403 if (ctrl_info
->admin_queue_memory_base
)
7404 dma_free_coherent(&ctrl_info
->pci_dev
->dev
,
7405 ctrl_info
->admin_queue_memory_length
,
7406 ctrl_info
->admin_queue_memory_base
,
7407 ctrl_info
->admin_queue_memory_base_dma_handle
);
7408 pqi_free_all_io_requests(ctrl_info
);
7409 if (ctrl_info
->error_buffer
)
7410 dma_free_coherent(&ctrl_info
->pci_dev
->dev
,
7411 ctrl_info
->error_buffer_length
,
7412 ctrl_info
->error_buffer
,
7413 ctrl_info
->error_buffer_dma_handle
);
7414 if (ctrl_info
->iomem_base
)
7415 pqi_cleanup_pci_init(ctrl_info
);
7416 pqi_free_ctrl_info(ctrl_info
);
7419 static void pqi_remove_ctrl(struct pqi_ctrl_info
*ctrl_info
)
7421 pqi_cancel_rescan_worker(ctrl_info
);
7422 pqi_cancel_update_time_worker(ctrl_info
);
7423 pqi_remove_all_scsi_devices(ctrl_info
);
7424 pqi_unregister_scsi(ctrl_info
);
7425 if (ctrl_info
->pqi_mode_enabled
)
7426 pqi_revert_to_sis_mode(ctrl_info
);
7427 pqi_free_ctrl_resources(ctrl_info
);
7430 static void pqi_ofa_ctrl_quiesce(struct pqi_ctrl_info
*ctrl_info
)
7432 pqi_cancel_update_time_worker(ctrl_info
);
7433 pqi_cancel_rescan_worker(ctrl_info
);
7434 pqi_wait_until_lun_reset_finished(ctrl_info
);
7435 pqi_wait_until_scan_finished(ctrl_info
);
7436 pqi_ctrl_ofa_start(ctrl_info
);
7437 pqi_ctrl_block_requests(ctrl_info
);
7438 pqi_ctrl_wait_until_quiesced(ctrl_info
);
7439 pqi_ctrl_wait_for_pending_io(ctrl_info
, PQI_PENDING_IO_TIMEOUT_SECS
);
7440 pqi_fail_io_queued_for_all_devices(ctrl_info
);
7441 pqi_wait_until_inbound_queues_empty(ctrl_info
);
7442 pqi_stop_heartbeat_timer(ctrl_info
);
7443 ctrl_info
->pqi_mode_enabled
= false;
7444 pqi_save_ctrl_mode(ctrl_info
, SIS_MODE
);
7447 static void pqi_ofa_ctrl_unquiesce(struct pqi_ctrl_info
*ctrl_info
)
7449 pqi_ofa_free_host_buffer(ctrl_info
);
7450 ctrl_info
->pqi_mode_enabled
= true;
7451 pqi_save_ctrl_mode(ctrl_info
, PQI_MODE
);
7452 ctrl_info
->controller_online
= true;
7453 pqi_ctrl_unblock_requests(ctrl_info
);
7454 pqi_start_heartbeat_timer(ctrl_info
);
7455 pqi_schedule_update_time_worker(ctrl_info
);
7456 pqi_clear_soft_reset_status(ctrl_info
,
7457 PQI_SOFT_RESET_ABORT
);
7458 pqi_scan_scsi_devices(ctrl_info
);
7461 static int pqi_ofa_alloc_mem(struct pqi_ctrl_info
*ctrl_info
,
7462 u32 total_size
, u32 chunk_size
)
7467 struct pqi_sg_descriptor
*mem_descriptor
= NULL
;
7469 struct pqi_ofa_memory
*ofap
;
7471 dev
= &ctrl_info
->pci_dev
->dev
;
7473 sg_count
= (total_size
+ chunk_size
- 1);
7474 sg_count
/= chunk_size
;
7476 ofap
= ctrl_info
->pqi_ofa_mem_virt_addr
;
7478 if (sg_count
*chunk_size
< total_size
)
7481 ctrl_info
->pqi_ofa_chunk_virt_addr
=
7482 kcalloc(sg_count
, sizeof(void *), GFP_KERNEL
);
7483 if (!ctrl_info
->pqi_ofa_chunk_virt_addr
)
7486 for (size
= 0, i
= 0; size
< total_size
; size
+= chunk_size
, i
++) {
7487 dma_addr_t dma_handle
;
7489 ctrl_info
->pqi_ofa_chunk_virt_addr
[i
] =
7490 dma_alloc_coherent(dev
, chunk_size
, &dma_handle
,
7493 if (!ctrl_info
->pqi_ofa_chunk_virt_addr
[i
])
7496 mem_descriptor
= &ofap
->sg_descriptor
[i
];
7497 put_unaligned_le64 ((u64
) dma_handle
, &mem_descriptor
->address
);
7498 put_unaligned_le32 (chunk_size
, &mem_descriptor
->length
);
7501 if (!size
|| size
< total_size
)
7502 goto out_free_chunks
;
7504 put_unaligned_le32(CISS_SG_LAST
, &mem_descriptor
->flags
);
7505 put_unaligned_le16(sg_count
, &ofap
->num_memory_descriptors
);
7506 put_unaligned_le32(size
, &ofap
->bytes_allocated
);
7512 mem_descriptor
= &ofap
->sg_descriptor
[i
];
7513 dma_free_coherent(dev
, chunk_size
,
7514 ctrl_info
->pqi_ofa_chunk_virt_addr
[i
],
7515 get_unaligned_le64(&mem_descriptor
->address
));
7517 kfree(ctrl_info
->pqi_ofa_chunk_virt_addr
);
7520 put_unaligned_le32 (0, &ofap
->bytes_allocated
);
7524 static int pqi_ofa_alloc_host_buffer(struct pqi_ctrl_info
*ctrl_info
)
7530 total_size
= le32_to_cpu(
7531 ctrl_info
->pqi_ofa_mem_virt_addr
->bytes_allocated
);
7532 min_chunk_size
= total_size
/ PQI_OFA_MAX_SG_DESCRIPTORS
;
7534 for (chunk_sz
= total_size
; chunk_sz
>= min_chunk_size
; chunk_sz
/= 2)
7535 if (!pqi_ofa_alloc_mem(ctrl_info
, total_size
, chunk_sz
))
7541 static void pqi_ofa_setup_host_buffer(struct pqi_ctrl_info
*ctrl_info
,
7542 u32 bytes_requested
)
7544 struct pqi_ofa_memory
*pqi_ofa_memory
;
7547 dev
= &ctrl_info
->pci_dev
->dev
;
7548 pqi_ofa_memory
= dma_alloc_coherent(dev
,
7549 PQI_OFA_MEMORY_DESCRIPTOR_LENGTH
,
7550 &ctrl_info
->pqi_ofa_mem_dma_handle
,
7553 if (!pqi_ofa_memory
)
7556 put_unaligned_le16(PQI_OFA_VERSION
, &pqi_ofa_memory
->version
);
7557 memcpy(&pqi_ofa_memory
->signature
, PQI_OFA_SIGNATURE
,
7558 sizeof(pqi_ofa_memory
->signature
));
7559 pqi_ofa_memory
->bytes_allocated
= cpu_to_le32(bytes_requested
);
7561 ctrl_info
->pqi_ofa_mem_virt_addr
= pqi_ofa_memory
;
7563 if (pqi_ofa_alloc_host_buffer(ctrl_info
) < 0) {
7564 dev_err(dev
, "Failed to allocate host buffer of size = %u",
7569 static void pqi_ofa_free_host_buffer(struct pqi_ctrl_info
*ctrl_info
)
7572 struct pqi_sg_descriptor
*mem_descriptor
;
7573 struct pqi_ofa_memory
*ofap
;
7575 ofap
= ctrl_info
->pqi_ofa_mem_virt_addr
;
7580 if (!ofap
->bytes_allocated
)
7583 mem_descriptor
= ofap
->sg_descriptor
;
7585 for (i
= 0; i
< get_unaligned_le16(&ofap
->num_memory_descriptors
);
7587 dma_free_coherent(&ctrl_info
->pci_dev
->dev
,
7588 get_unaligned_le32(&mem_descriptor
[i
].length
),
7589 ctrl_info
->pqi_ofa_chunk_virt_addr
[i
],
7590 get_unaligned_le64(&mem_descriptor
[i
].address
));
7592 kfree(ctrl_info
->pqi_ofa_chunk_virt_addr
);
7595 dma_free_coherent(&ctrl_info
->pci_dev
->dev
,
7596 PQI_OFA_MEMORY_DESCRIPTOR_LENGTH
, ofap
,
7597 ctrl_info
->pqi_ofa_mem_dma_handle
);
7598 ctrl_info
->pqi_ofa_mem_virt_addr
= NULL
;
7601 static int pqi_ofa_host_memory_update(struct pqi_ctrl_info
*ctrl_info
)
7603 struct pqi_vendor_general_request request
;
7605 struct pqi_ofa_memory
*ofap
;
7607 memset(&request
, 0, sizeof(request
));
7609 ofap
= ctrl_info
->pqi_ofa_mem_virt_addr
;
7611 request
.header
.iu_type
= PQI_REQUEST_IU_VENDOR_GENERAL
;
7612 put_unaligned_le16(sizeof(request
) - PQI_REQUEST_HEADER_LENGTH
,
7613 &request
.header
.iu_length
);
7614 put_unaligned_le16(PQI_VENDOR_GENERAL_HOST_MEMORY_UPDATE
,
7615 &request
.function_code
);
7618 size
= offsetof(struct pqi_ofa_memory
, sg_descriptor
) +
7619 get_unaligned_le16(&ofap
->num_memory_descriptors
) *
7620 sizeof(struct pqi_sg_descriptor
);
7622 put_unaligned_le64((u64
)ctrl_info
->pqi_ofa_mem_dma_handle
,
7623 &request
.data
.ofa_memory_allocation
.buffer_address
);
7624 put_unaligned_le32(size
,
7625 &request
.data
.ofa_memory_allocation
.buffer_length
);
7629 return pqi_submit_raid_request_synchronous(ctrl_info
, &request
.header
,
7630 0, NULL
, NO_TIMEOUT
);
7633 #define PQI_POST_RESET_DELAY_B4_MSGU_READY 5000
7635 static int pqi_ofa_ctrl_restart(struct pqi_ctrl_info
*ctrl_info
)
7637 msleep(PQI_POST_RESET_DELAY_B4_MSGU_READY
);
7638 return pqi_ctrl_init_resume(ctrl_info
);
7641 static void pqi_perform_lockup_action(void)
7643 switch (pqi_lockup_action
) {
7645 panic("FATAL: Smart Family Controller lockup detected");
7648 emergency_restart();
7656 static struct pqi_raid_error_info pqi_ctrl_offline_raid_error_info
= {
7657 .data_out_result
= PQI_DATA_IN_OUT_HARDWARE_ERROR
,
7658 .status
= SAM_STAT_CHECK_CONDITION
,
7661 static void pqi_fail_all_outstanding_requests(struct pqi_ctrl_info
*ctrl_info
)
7664 struct pqi_io_request
*io_request
;
7665 struct scsi_cmnd
*scmd
;
7667 for (i
= 0; i
< ctrl_info
->max_io_slots
; i
++) {
7668 io_request
= &ctrl_info
->io_request_pool
[i
];
7669 if (atomic_read(&io_request
->refcount
) == 0)
7672 scmd
= io_request
->scmd
;
7674 set_host_byte(scmd
, DID_NO_CONNECT
);
7676 io_request
->status
= -ENXIO
;
7677 io_request
->error_info
=
7678 &pqi_ctrl_offline_raid_error_info
;
7681 io_request
->io_complete_callback(io_request
,
7682 io_request
->context
);
7686 static void pqi_take_ctrl_offline_deferred(struct pqi_ctrl_info
*ctrl_info
)
7688 pqi_perform_lockup_action();
7689 pqi_stop_heartbeat_timer(ctrl_info
);
7690 pqi_free_interrupts(ctrl_info
);
7691 pqi_cancel_rescan_worker(ctrl_info
);
7692 pqi_cancel_update_time_worker(ctrl_info
);
7693 pqi_ctrl_wait_until_quiesced(ctrl_info
);
7694 pqi_fail_all_outstanding_requests(ctrl_info
);
7695 pqi_clear_all_queued_raid_bypass_retries(ctrl_info
);
7696 pqi_ctrl_unblock_requests(ctrl_info
);
7699 static void pqi_ctrl_offline_worker(struct work_struct
*work
)
7701 struct pqi_ctrl_info
*ctrl_info
;
7703 ctrl_info
= container_of(work
, struct pqi_ctrl_info
, ctrl_offline_work
);
7704 pqi_take_ctrl_offline_deferred(ctrl_info
);
7707 static void pqi_take_ctrl_offline(struct pqi_ctrl_info
*ctrl_info
)
7709 if (!ctrl_info
->controller_online
)
7712 ctrl_info
->controller_online
= false;
7713 ctrl_info
->pqi_mode_enabled
= false;
7714 pqi_ctrl_block_requests(ctrl_info
);
7715 if (!pqi_disable_ctrl_shutdown
)
7716 sis_shutdown_ctrl(ctrl_info
);
7717 pci_disable_device(ctrl_info
->pci_dev
);
7718 dev_err(&ctrl_info
->pci_dev
->dev
, "controller offline\n");
7719 schedule_work(&ctrl_info
->ctrl_offline_work
);
7722 static void pqi_print_ctrl_info(struct pci_dev
*pci_dev
,
7723 const struct pci_device_id
*id
)
7725 char *ctrl_description
;
7727 if (id
->driver_data
)
7728 ctrl_description
= (char *)id
->driver_data
;
7730 ctrl_description
= "Microsemi Smart Family Controller";
7732 dev_info(&pci_dev
->dev
, "%s found\n", ctrl_description
);
7735 static int pqi_pci_probe(struct pci_dev
*pci_dev
,
7736 const struct pci_device_id
*id
)
7740 struct pqi_ctrl_info
*ctrl_info
;
7742 pqi_print_ctrl_info(pci_dev
, id
);
7744 if (pqi_disable_device_id_wildcards
&&
7745 id
->subvendor
== PCI_ANY_ID
&&
7746 id
->subdevice
== PCI_ANY_ID
) {
7747 dev_warn(&pci_dev
->dev
,
7748 "controller not probed because device ID wildcards are disabled\n");
7752 if (id
->subvendor
== PCI_ANY_ID
|| id
->subdevice
== PCI_ANY_ID
)
7753 dev_warn(&pci_dev
->dev
,
7754 "controller device ID matched using wildcards\n");
7756 node
= dev_to_node(&pci_dev
->dev
);
7757 if (node
== NUMA_NO_NODE
) {
7758 cp_node
= cpu_to_node(0);
7759 if (cp_node
== NUMA_NO_NODE
)
7761 set_dev_node(&pci_dev
->dev
, cp_node
);
7764 ctrl_info
= pqi_alloc_ctrl_info(node
);
7766 dev_err(&pci_dev
->dev
,
7767 "failed to allocate controller info block\n");
7771 ctrl_info
->pci_dev
= pci_dev
;
7773 rc
= pqi_pci_init(ctrl_info
);
7777 rc
= pqi_ctrl_init(ctrl_info
);
7784 pqi_remove_ctrl(ctrl_info
);
7789 static void pqi_pci_remove(struct pci_dev
*pci_dev
)
7791 struct pqi_ctrl_info
*ctrl_info
;
7793 ctrl_info
= pci_get_drvdata(pci_dev
);
7797 ctrl_info
->in_shutdown
= true;
7799 pqi_remove_ctrl(ctrl_info
);
7802 static void pqi_shutdown(struct pci_dev
*pci_dev
)
7805 struct pqi_ctrl_info
*ctrl_info
;
7807 ctrl_info
= pci_get_drvdata(pci_dev
);
7812 * Write all data in the controller's battery-backed cache to
7815 rc
= pqi_flush_cache(ctrl_info
, SHUTDOWN
);
7816 pqi_free_interrupts(ctrl_info
);
7817 pqi_reset(ctrl_info
);
7822 dev_warn(&pci_dev
->dev
,
7823 "unable to flush controller cache\n");
7826 static void pqi_process_lockup_action_param(void)
7830 if (!pqi_lockup_action_param
)
7833 for (i
= 0; i
< ARRAY_SIZE(pqi_lockup_actions
); i
++) {
7834 if (strcmp(pqi_lockup_action_param
,
7835 pqi_lockup_actions
[i
].name
) == 0) {
7836 pqi_lockup_action
= pqi_lockup_actions
[i
].action
;
7841 pr_warn("%s: invalid lockup action setting \"%s\" - supported settings: none, reboot, panic\n",
7842 DRIVER_NAME_SHORT
, pqi_lockup_action_param
);
7845 static void pqi_process_module_params(void)
7847 pqi_process_lockup_action_param();
7850 static __maybe_unused
int pqi_suspend(struct pci_dev
*pci_dev
, pm_message_t state
)
7852 struct pqi_ctrl_info
*ctrl_info
;
7854 ctrl_info
= pci_get_drvdata(pci_dev
);
7856 pqi_disable_events(ctrl_info
);
7857 pqi_cancel_update_time_worker(ctrl_info
);
7858 pqi_cancel_rescan_worker(ctrl_info
);
7859 pqi_wait_until_scan_finished(ctrl_info
);
7860 pqi_wait_until_lun_reset_finished(ctrl_info
);
7861 pqi_wait_until_ofa_finished(ctrl_info
);
7862 pqi_flush_cache(ctrl_info
, SUSPEND
);
7863 pqi_ctrl_block_requests(ctrl_info
);
7864 pqi_ctrl_wait_until_quiesced(ctrl_info
);
7865 pqi_wait_until_inbound_queues_empty(ctrl_info
);
7866 pqi_ctrl_wait_for_pending_io(ctrl_info
, NO_TIMEOUT
);
7867 pqi_stop_heartbeat_timer(ctrl_info
);
7869 if (state
.event
== PM_EVENT_FREEZE
)
7872 pci_save_state(pci_dev
);
7873 pci_set_power_state(pci_dev
, pci_choose_state(pci_dev
, state
));
7875 ctrl_info
->controller_online
= false;
7876 ctrl_info
->pqi_mode_enabled
= false;
7881 static __maybe_unused
int pqi_resume(struct pci_dev
*pci_dev
)
7884 struct pqi_ctrl_info
*ctrl_info
;
7886 ctrl_info
= pci_get_drvdata(pci_dev
);
7888 if (pci_dev
->current_state
!= PCI_D0
) {
7889 ctrl_info
->max_hw_queue_index
= 0;
7890 pqi_free_interrupts(ctrl_info
);
7891 pqi_change_irq_mode(ctrl_info
, IRQ_MODE_INTX
);
7892 rc
= request_irq(pci_irq_vector(pci_dev
, 0), pqi_irq_handler
,
7893 IRQF_SHARED
, DRIVER_NAME_SHORT
,
7894 &ctrl_info
->queue_groups
[0]);
7896 dev_err(&ctrl_info
->pci_dev
->dev
,
7897 "irq %u init failed with error %d\n",
7901 pqi_start_heartbeat_timer(ctrl_info
);
7902 pqi_ctrl_unblock_requests(ctrl_info
);
7906 pci_set_power_state(pci_dev
, PCI_D0
);
7907 pci_restore_state(pci_dev
);
7909 return pqi_ctrl_init_resume(ctrl_info
);
7912 /* Define the PCI IDs for the controllers that we support. */
7913 static const struct pci_device_id pqi_pci_id_table
[] = {
7915 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
7919 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
7923 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
7927 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
7931 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
7935 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
7939 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
7943 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
7947 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
7951 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
7955 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
7959 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
7963 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
7967 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
7971 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
7975 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
7979 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
7983 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
7987 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
7991 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
7995 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
7999 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8003 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8007 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8011 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8015 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8019 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8020 PCI_VENDOR_ID_ADAPTEC2
, 0x0110)
8023 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8024 PCI_VENDOR_ID_ADAPTEC2
, 0x0608)
8027 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8028 PCI_VENDOR_ID_ADAPTEC2
, 0x0800)
8031 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8032 PCI_VENDOR_ID_ADAPTEC2
, 0x0801)
8035 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8036 PCI_VENDOR_ID_ADAPTEC2
, 0x0802)
8039 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8040 PCI_VENDOR_ID_ADAPTEC2
, 0x0803)
8043 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8044 PCI_VENDOR_ID_ADAPTEC2
, 0x0804)
8047 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8048 PCI_VENDOR_ID_ADAPTEC2
, 0x0805)
8051 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8052 PCI_VENDOR_ID_ADAPTEC2
, 0x0806)
8055 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8056 PCI_VENDOR_ID_ADAPTEC2
, 0x0807)
8059 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8060 PCI_VENDOR_ID_ADAPTEC2
, 0x0900)
8063 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8064 PCI_VENDOR_ID_ADAPTEC2
, 0x0901)
8067 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8068 PCI_VENDOR_ID_ADAPTEC2
, 0x0902)
8071 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8072 PCI_VENDOR_ID_ADAPTEC2
, 0x0903)
8075 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8076 PCI_VENDOR_ID_ADAPTEC2
, 0x0904)
8079 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8080 PCI_VENDOR_ID_ADAPTEC2
, 0x0905)
8083 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8084 PCI_VENDOR_ID_ADAPTEC2
, 0x0906)
8087 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8088 PCI_VENDOR_ID_ADAPTEC2
, 0x0907)
8091 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8092 PCI_VENDOR_ID_ADAPTEC2
, 0x0908)
8095 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8096 PCI_VENDOR_ID_ADAPTEC2
, 0x090a)
8099 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8100 PCI_VENDOR_ID_ADAPTEC2
, 0x1200)
8103 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8104 PCI_VENDOR_ID_ADAPTEC2
, 0x1201)
8107 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8108 PCI_VENDOR_ID_ADAPTEC2
, 0x1202)
8111 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8112 PCI_VENDOR_ID_ADAPTEC2
, 0x1280)
8115 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8116 PCI_VENDOR_ID_ADAPTEC2
, 0x1281)
8119 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8120 PCI_VENDOR_ID_ADAPTEC2
, 0x1282)
8123 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8124 PCI_VENDOR_ID_ADAPTEC2
, 0x1300)
8127 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8128 PCI_VENDOR_ID_ADAPTEC2
, 0x1301)
8131 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8132 PCI_VENDOR_ID_ADAPTEC2
, 0x1302)
8135 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8136 PCI_VENDOR_ID_ADAPTEC2
, 0x1303)
8139 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8140 PCI_VENDOR_ID_ADAPTEC2
, 0x1380)
8143 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8144 PCI_VENDOR_ID_ADVANTECH
, 0x8312)
8147 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8148 PCI_VENDOR_ID_DELL
, 0x1fe0)
8151 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8152 PCI_VENDOR_ID_HP
, 0x0600)
8155 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8156 PCI_VENDOR_ID_HP
, 0x0601)
8159 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8160 PCI_VENDOR_ID_HP
, 0x0602)
8163 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8164 PCI_VENDOR_ID_HP
, 0x0603)
8167 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8168 PCI_VENDOR_ID_HP
, 0x0609)
8171 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8172 PCI_VENDOR_ID_HP
, 0x0650)
8175 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8176 PCI_VENDOR_ID_HP
, 0x0651)
8179 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8180 PCI_VENDOR_ID_HP
, 0x0652)
8183 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8184 PCI_VENDOR_ID_HP
, 0x0653)
8187 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8188 PCI_VENDOR_ID_HP
, 0x0654)
8191 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8192 PCI_VENDOR_ID_HP
, 0x0655)
8195 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8196 PCI_VENDOR_ID_HP
, 0x0700)
8199 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8200 PCI_VENDOR_ID_HP
, 0x0701)
8203 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8204 PCI_VENDOR_ID_HP
, 0x1001)
8207 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8208 PCI_VENDOR_ID_HP
, 0x1100)
8211 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8212 PCI_VENDOR_ID_HP
, 0x1101)
8215 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
8216 PCI_ANY_ID
, PCI_ANY_ID
)
8221 MODULE_DEVICE_TABLE(pci
, pqi_pci_id_table
);
8223 static struct pci_driver pqi_pci_driver
= {
8224 .name
= DRIVER_NAME_SHORT
,
8225 .id_table
= pqi_pci_id_table
,
8226 .probe
= pqi_pci_probe
,
8227 .remove
= pqi_pci_remove
,
8228 .shutdown
= pqi_shutdown
,
8229 #if defined(CONFIG_PM)
8230 .suspend
= pqi_suspend
,
8231 .resume
= pqi_resume
,
8235 static int __init
pqi_init(void)
8239 pr_info(DRIVER_NAME
"\n");
8241 pqi_sas_transport_template
=
8242 sas_attach_transport(&pqi_sas_transport_functions
);
8243 if (!pqi_sas_transport_template
)
8246 pqi_process_module_params();
8248 rc
= pci_register_driver(&pqi_pci_driver
);
8250 sas_release_transport(pqi_sas_transport_template
);
8255 static void __exit
pqi_cleanup(void)
8257 pci_unregister_driver(&pqi_pci_driver
);
8258 sas_release_transport(pqi_sas_transport_template
);
8261 module_init(pqi_init
);
8262 module_exit(pqi_cleanup
);
8264 static void __attribute__((unused
)) verify_structures(void)
8266 BUILD_BUG_ON(offsetof(struct pqi_ctrl_registers
,
8267 sis_host_to_ctrl_doorbell
) != 0x20);
8268 BUILD_BUG_ON(offsetof(struct pqi_ctrl_registers
,
8269 sis_interrupt_mask
) != 0x34);
8270 BUILD_BUG_ON(offsetof(struct pqi_ctrl_registers
,
8271 sis_ctrl_to_host_doorbell
) != 0x9c);
8272 BUILD_BUG_ON(offsetof(struct pqi_ctrl_registers
,
8273 sis_ctrl_to_host_doorbell_clear
) != 0xa0);
8274 BUILD_BUG_ON(offsetof(struct pqi_ctrl_registers
,
8275 sis_driver_scratch
) != 0xb0);
8276 BUILD_BUG_ON(offsetof(struct pqi_ctrl_registers
,
8277 sis_firmware_status
) != 0xbc);
8278 BUILD_BUG_ON(offsetof(struct pqi_ctrl_registers
,
8279 sis_mailbox
) != 0x1000);
8280 BUILD_BUG_ON(offsetof(struct pqi_ctrl_registers
,
8281 pqi_registers
) != 0x4000);
8283 BUILD_BUG_ON(offsetof(struct pqi_iu_header
,
8285 BUILD_BUG_ON(offsetof(struct pqi_iu_header
,
8287 BUILD_BUG_ON(offsetof(struct pqi_iu_header
,
8288 response_queue_id
) != 0x4);
8289 BUILD_BUG_ON(offsetof(struct pqi_iu_header
,
8291 BUILD_BUG_ON(sizeof(struct pqi_iu_header
) != 0x8);
8293 BUILD_BUG_ON(offsetof(struct pqi_aio_error_info
,
8295 BUILD_BUG_ON(offsetof(struct pqi_aio_error_info
,
8296 service_response
) != 0x1);
8297 BUILD_BUG_ON(offsetof(struct pqi_aio_error_info
,
8298 data_present
) != 0x2);
8299 BUILD_BUG_ON(offsetof(struct pqi_aio_error_info
,
8301 BUILD_BUG_ON(offsetof(struct pqi_aio_error_info
,
8302 residual_count
) != 0x4);
8303 BUILD_BUG_ON(offsetof(struct pqi_aio_error_info
,
8304 data_length
) != 0x8);
8305 BUILD_BUG_ON(offsetof(struct pqi_aio_error_info
,
8307 BUILD_BUG_ON(offsetof(struct pqi_aio_error_info
,
8309 BUILD_BUG_ON(sizeof(struct pqi_aio_error_info
) != 0x10c);
8311 BUILD_BUG_ON(offsetof(struct pqi_raid_error_info
,
8312 data_in_result
) != 0x0);
8313 BUILD_BUG_ON(offsetof(struct pqi_raid_error_info
,
8314 data_out_result
) != 0x1);
8315 BUILD_BUG_ON(offsetof(struct pqi_raid_error_info
,
8317 BUILD_BUG_ON(offsetof(struct pqi_raid_error_info
,
8319 BUILD_BUG_ON(offsetof(struct pqi_raid_error_info
,
8320 status_qualifier
) != 0x6);
8321 BUILD_BUG_ON(offsetof(struct pqi_raid_error_info
,
8322 sense_data_length
) != 0x8);
8323 BUILD_BUG_ON(offsetof(struct pqi_raid_error_info
,
8324 response_data_length
) != 0xa);
8325 BUILD_BUG_ON(offsetof(struct pqi_raid_error_info
,
8326 data_in_transferred
) != 0xc);
8327 BUILD_BUG_ON(offsetof(struct pqi_raid_error_info
,
8328 data_out_transferred
) != 0x10);
8329 BUILD_BUG_ON(offsetof(struct pqi_raid_error_info
,
8331 BUILD_BUG_ON(sizeof(struct pqi_raid_error_info
) != 0x114);
8333 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
8335 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
8336 function_and_status_code
) != 0x8);
8337 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
8338 max_admin_iq_elements
) != 0x10);
8339 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
8340 max_admin_oq_elements
) != 0x11);
8341 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
8342 admin_iq_element_length
) != 0x12);
8343 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
8344 admin_oq_element_length
) != 0x13);
8345 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
8346 max_reset_timeout
) != 0x14);
8347 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
8348 legacy_intx_status
) != 0x18);
8349 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
8350 legacy_intx_mask_set
) != 0x1c);
8351 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
8352 legacy_intx_mask_clear
) != 0x20);
8353 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
8354 device_status
) != 0x40);
8355 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
8356 admin_iq_pi_offset
) != 0x48);
8357 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
8358 admin_oq_ci_offset
) != 0x50);
8359 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
8360 admin_iq_element_array_addr
) != 0x58);
8361 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
8362 admin_oq_element_array_addr
) != 0x60);
8363 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
8364 admin_iq_ci_addr
) != 0x68);
8365 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
8366 admin_oq_pi_addr
) != 0x70);
8367 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
8368 admin_iq_num_elements
) != 0x78);
8369 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
8370 admin_oq_num_elements
) != 0x79);
8371 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
8372 admin_queue_int_msg_num
) != 0x7a);
8373 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
8374 device_error
) != 0x80);
8375 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
8376 error_details
) != 0x88);
8377 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
8378 device_reset
) != 0x90);
8379 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
8380 power_action
) != 0x94);
8381 BUILD_BUG_ON(sizeof(struct pqi_device_registers
) != 0x100);
8383 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
8384 header
.iu_type
) != 0);
8385 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
8386 header
.iu_length
) != 2);
8387 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
8388 header
.work_area
) != 6);
8389 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
8391 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
8392 function_code
) != 10);
8393 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
8394 data
.report_device_capability
.buffer_length
) != 44);
8395 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
8396 data
.report_device_capability
.sg_descriptor
) != 48);
8397 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
8398 data
.create_operational_iq
.queue_id
) != 12);
8399 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
8400 data
.create_operational_iq
.element_array_addr
) != 16);
8401 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
8402 data
.create_operational_iq
.ci_addr
) != 24);
8403 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
8404 data
.create_operational_iq
.num_elements
) != 32);
8405 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
8406 data
.create_operational_iq
.element_length
) != 34);
8407 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
8408 data
.create_operational_iq
.queue_protocol
) != 36);
8409 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
8410 data
.create_operational_oq
.queue_id
) != 12);
8411 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
8412 data
.create_operational_oq
.element_array_addr
) != 16);
8413 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
8414 data
.create_operational_oq
.pi_addr
) != 24);
8415 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
8416 data
.create_operational_oq
.num_elements
) != 32);
8417 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
8418 data
.create_operational_oq
.element_length
) != 34);
8419 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
8420 data
.create_operational_oq
.queue_protocol
) != 36);
8421 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
8422 data
.create_operational_oq
.int_msg_num
) != 40);
8423 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
8424 data
.create_operational_oq
.coalescing_count
) != 42);
8425 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
8426 data
.create_operational_oq
.min_coalescing_time
) != 44);
8427 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
8428 data
.create_operational_oq
.max_coalescing_time
) != 48);
8429 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
8430 data
.delete_operational_queue
.queue_id
) != 12);
8431 BUILD_BUG_ON(sizeof(struct pqi_general_admin_request
) != 64);
8432 BUILD_BUG_ON(FIELD_SIZEOF(struct pqi_general_admin_request
,
8433 data
.create_operational_iq
) != 64 - 11);
8434 BUILD_BUG_ON(FIELD_SIZEOF(struct pqi_general_admin_request
,
8435 data
.create_operational_oq
) != 64 - 11);
8436 BUILD_BUG_ON(FIELD_SIZEOF(struct pqi_general_admin_request
,
8437 data
.delete_operational_queue
) != 64 - 11);
8439 BUILD_BUG_ON(offsetof(struct pqi_general_admin_response
,
8440 header
.iu_type
) != 0);
8441 BUILD_BUG_ON(offsetof(struct pqi_general_admin_response
,
8442 header
.iu_length
) != 2);
8443 BUILD_BUG_ON(offsetof(struct pqi_general_admin_response
,
8444 header
.work_area
) != 6);
8445 BUILD_BUG_ON(offsetof(struct pqi_general_admin_response
,
8447 BUILD_BUG_ON(offsetof(struct pqi_general_admin_response
,
8448 function_code
) != 10);
8449 BUILD_BUG_ON(offsetof(struct pqi_general_admin_response
,
8451 BUILD_BUG_ON(offsetof(struct pqi_general_admin_response
,
8452 data
.create_operational_iq
.status_descriptor
) != 12);
8453 BUILD_BUG_ON(offsetof(struct pqi_general_admin_response
,
8454 data
.create_operational_iq
.iq_pi_offset
) != 16);
8455 BUILD_BUG_ON(offsetof(struct pqi_general_admin_response
,
8456 data
.create_operational_oq
.status_descriptor
) != 12);
8457 BUILD_BUG_ON(offsetof(struct pqi_general_admin_response
,
8458 data
.create_operational_oq
.oq_ci_offset
) != 16);
8459 BUILD_BUG_ON(sizeof(struct pqi_general_admin_response
) != 64);
8461 BUILD_BUG_ON(offsetof(struct pqi_raid_path_request
,
8462 header
.iu_type
) != 0);
8463 BUILD_BUG_ON(offsetof(struct pqi_raid_path_request
,
8464 header
.iu_length
) != 2);
8465 BUILD_BUG_ON(offsetof(struct pqi_raid_path_request
,
8466 header
.response_queue_id
) != 4);
8467 BUILD_BUG_ON(offsetof(struct pqi_raid_path_request
,
8468 header
.work_area
) != 6);
8469 BUILD_BUG_ON(offsetof(struct pqi_raid_path_request
,
8471 BUILD_BUG_ON(offsetof(struct pqi_raid_path_request
,
8473 BUILD_BUG_ON(offsetof(struct pqi_raid_path_request
,
8474 buffer_length
) != 12);
8475 BUILD_BUG_ON(offsetof(struct pqi_raid_path_request
,
8477 BUILD_BUG_ON(offsetof(struct pqi_raid_path_request
,
8478 protocol_specific
) != 24);
8479 BUILD_BUG_ON(offsetof(struct pqi_raid_path_request
,
8480 error_index
) != 27);
8481 BUILD_BUG_ON(offsetof(struct pqi_raid_path_request
,
8483 BUILD_BUG_ON(offsetof(struct pqi_raid_path_request
,
8484 sg_descriptors
) != 64);
8485 BUILD_BUG_ON(sizeof(struct pqi_raid_path_request
) !=
8486 PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
);
8488 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
8489 header
.iu_type
) != 0);
8490 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
8491 header
.iu_length
) != 2);
8492 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
8493 header
.response_queue_id
) != 4);
8494 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
8495 header
.work_area
) != 6);
8496 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
8498 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
8500 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
8501 buffer_length
) != 16);
8502 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
8503 data_encryption_key_index
) != 22);
8504 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
8505 encrypt_tweak_lower
) != 24);
8506 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
8507 encrypt_tweak_upper
) != 28);
8508 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
8510 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
8511 error_index
) != 48);
8512 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
8513 num_sg_descriptors
) != 50);
8514 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
8516 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
8518 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
8519 sg_descriptors
) != 64);
8520 BUILD_BUG_ON(sizeof(struct pqi_aio_path_request
) !=
8521 PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
);
8523 BUILD_BUG_ON(offsetof(struct pqi_io_response
,
8524 header
.iu_type
) != 0);
8525 BUILD_BUG_ON(offsetof(struct pqi_io_response
,
8526 header
.iu_length
) != 2);
8527 BUILD_BUG_ON(offsetof(struct pqi_io_response
,
8529 BUILD_BUG_ON(offsetof(struct pqi_io_response
,
8530 error_index
) != 10);
8532 BUILD_BUG_ON(offsetof(struct pqi_general_management_request
,
8533 header
.iu_type
) != 0);
8534 BUILD_BUG_ON(offsetof(struct pqi_general_management_request
,
8535 header
.iu_length
) != 2);
8536 BUILD_BUG_ON(offsetof(struct pqi_general_management_request
,
8537 header
.response_queue_id
) != 4);
8538 BUILD_BUG_ON(offsetof(struct pqi_general_management_request
,
8540 BUILD_BUG_ON(offsetof(struct pqi_general_management_request
,
8541 data
.report_event_configuration
.buffer_length
) != 12);
8542 BUILD_BUG_ON(offsetof(struct pqi_general_management_request
,
8543 data
.report_event_configuration
.sg_descriptors
) != 16);
8544 BUILD_BUG_ON(offsetof(struct pqi_general_management_request
,
8545 data
.set_event_configuration
.global_event_oq_id
) != 10);
8546 BUILD_BUG_ON(offsetof(struct pqi_general_management_request
,
8547 data
.set_event_configuration
.buffer_length
) != 12);
8548 BUILD_BUG_ON(offsetof(struct pqi_general_management_request
,
8549 data
.set_event_configuration
.sg_descriptors
) != 16);
8551 BUILD_BUG_ON(offsetof(struct pqi_iu_layer_descriptor
,
8552 max_inbound_iu_length
) != 6);
8553 BUILD_BUG_ON(offsetof(struct pqi_iu_layer_descriptor
,
8554 max_outbound_iu_length
) != 14);
8555 BUILD_BUG_ON(sizeof(struct pqi_iu_layer_descriptor
) != 16);
8557 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
8559 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
8560 iq_arbitration_priority_support_bitmask
) != 8);
8561 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
8562 maximum_aw_a
) != 9);
8563 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
8564 maximum_aw_b
) != 10);
8565 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
8566 maximum_aw_c
) != 11);
8567 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
8568 max_inbound_queues
) != 16);
8569 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
8570 max_elements_per_iq
) != 18);
8571 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
8572 max_iq_element_length
) != 24);
8573 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
8574 min_iq_element_length
) != 26);
8575 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
8576 max_outbound_queues
) != 30);
8577 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
8578 max_elements_per_oq
) != 32);
8579 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
8580 intr_coalescing_time_granularity
) != 34);
8581 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
8582 max_oq_element_length
) != 36);
8583 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
8584 min_oq_element_length
) != 38);
8585 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
8586 iu_layer_descriptors
) != 64);
8587 BUILD_BUG_ON(sizeof(struct pqi_device_capability
) != 576);
8589 BUILD_BUG_ON(offsetof(struct pqi_event_descriptor
,
8591 BUILD_BUG_ON(offsetof(struct pqi_event_descriptor
,
8593 BUILD_BUG_ON(sizeof(struct pqi_event_descriptor
) != 4);
8595 BUILD_BUG_ON(offsetof(struct pqi_event_config
,
8596 num_event_descriptors
) != 2);
8597 BUILD_BUG_ON(offsetof(struct pqi_event_config
,
8600 BUILD_BUG_ON(PQI_NUM_SUPPORTED_EVENTS
!=
8601 ARRAY_SIZE(pqi_supported_event_types
));
8603 BUILD_BUG_ON(offsetof(struct pqi_event_response
,
8604 header
.iu_type
) != 0);
8605 BUILD_BUG_ON(offsetof(struct pqi_event_response
,
8606 header
.iu_length
) != 2);
8607 BUILD_BUG_ON(offsetof(struct pqi_event_response
,
8609 BUILD_BUG_ON(offsetof(struct pqi_event_response
,
8611 BUILD_BUG_ON(offsetof(struct pqi_event_response
,
8612 additional_event_id
) != 12);
8613 BUILD_BUG_ON(offsetof(struct pqi_event_response
,
8615 BUILD_BUG_ON(sizeof(struct pqi_event_response
) != 32);
8617 BUILD_BUG_ON(offsetof(struct pqi_event_acknowledge_request
,
8618 header
.iu_type
) != 0);
8619 BUILD_BUG_ON(offsetof(struct pqi_event_acknowledge_request
,
8620 header
.iu_length
) != 2);
8621 BUILD_BUG_ON(offsetof(struct pqi_event_acknowledge_request
,
8623 BUILD_BUG_ON(offsetof(struct pqi_event_acknowledge_request
,
8625 BUILD_BUG_ON(offsetof(struct pqi_event_acknowledge_request
,
8626 additional_event_id
) != 12);
8627 BUILD_BUG_ON(sizeof(struct pqi_event_acknowledge_request
) != 16);
8629 BUILD_BUG_ON(offsetof(struct pqi_task_management_request
,
8630 header
.iu_type
) != 0);
8631 BUILD_BUG_ON(offsetof(struct pqi_task_management_request
,
8632 header
.iu_length
) != 2);
8633 BUILD_BUG_ON(offsetof(struct pqi_task_management_request
,
8635 BUILD_BUG_ON(offsetof(struct pqi_task_management_request
,
8637 BUILD_BUG_ON(offsetof(struct pqi_task_management_request
,
8639 BUILD_BUG_ON(offsetof(struct pqi_task_management_request
,
8640 protocol_specific
) != 24);
8641 BUILD_BUG_ON(offsetof(struct pqi_task_management_request
,
8642 outbound_queue_id_to_manage
) != 26);
8643 BUILD_BUG_ON(offsetof(struct pqi_task_management_request
,
8644 request_id_to_manage
) != 28);
8645 BUILD_BUG_ON(offsetof(struct pqi_task_management_request
,
8646 task_management_function
) != 30);
8647 BUILD_BUG_ON(sizeof(struct pqi_task_management_request
) != 32);
8649 BUILD_BUG_ON(offsetof(struct pqi_task_management_response
,
8650 header
.iu_type
) != 0);
8651 BUILD_BUG_ON(offsetof(struct pqi_task_management_response
,
8652 header
.iu_length
) != 2);
8653 BUILD_BUG_ON(offsetof(struct pqi_task_management_response
,
8655 BUILD_BUG_ON(offsetof(struct pqi_task_management_response
,
8657 BUILD_BUG_ON(offsetof(struct pqi_task_management_response
,
8658 additional_response_info
) != 12);
8659 BUILD_BUG_ON(offsetof(struct pqi_task_management_response
,
8660 response_code
) != 15);
8661 BUILD_BUG_ON(sizeof(struct pqi_task_management_response
) != 16);
8663 BUILD_BUG_ON(offsetof(struct bmic_identify_controller
,
8664 configured_logical_drive_count
) != 0);
8665 BUILD_BUG_ON(offsetof(struct bmic_identify_controller
,
8666 configuration_signature
) != 1);
8667 BUILD_BUG_ON(offsetof(struct bmic_identify_controller
,
8668 firmware_version
) != 5);
8669 BUILD_BUG_ON(offsetof(struct bmic_identify_controller
,
8670 extended_logical_unit_count
) != 154);
8671 BUILD_BUG_ON(offsetof(struct bmic_identify_controller
,
8672 firmware_build_number
) != 190);
8673 BUILD_BUG_ON(offsetof(struct bmic_identify_controller
,
8674 controller_mode
) != 292);
8676 BUILD_BUG_ON(offsetof(struct bmic_identify_physical_device
,
8677 phys_bay_in_box
) != 115);
8678 BUILD_BUG_ON(offsetof(struct bmic_identify_physical_device
,
8679 device_type
) != 120);
8680 BUILD_BUG_ON(offsetof(struct bmic_identify_physical_device
,
8681 redundant_path_present_map
) != 1736);
8682 BUILD_BUG_ON(offsetof(struct bmic_identify_physical_device
,
8683 active_path_number
) != 1738);
8684 BUILD_BUG_ON(offsetof(struct bmic_identify_physical_device
,
8685 alternate_paths_phys_connector
) != 1739);
8686 BUILD_BUG_ON(offsetof(struct bmic_identify_physical_device
,
8687 alternate_paths_phys_box_on_port
) != 1755);
8688 BUILD_BUG_ON(offsetof(struct bmic_identify_physical_device
,
8689 current_queue_depth_limit
) != 1796);
8690 BUILD_BUG_ON(sizeof(struct bmic_identify_physical_device
) != 2560);
8692 BUILD_BUG_ON(PQI_ADMIN_IQ_NUM_ELEMENTS
> 255);
8693 BUILD_BUG_ON(PQI_ADMIN_OQ_NUM_ELEMENTS
> 255);
8694 BUILD_BUG_ON(PQI_ADMIN_IQ_ELEMENT_LENGTH
%
8695 PQI_QUEUE_ELEMENT_LENGTH_ALIGNMENT
!= 0);
8696 BUILD_BUG_ON(PQI_ADMIN_OQ_ELEMENT_LENGTH
%
8697 PQI_QUEUE_ELEMENT_LENGTH_ALIGNMENT
!= 0);
8698 BUILD_BUG_ON(PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
> 1048560);
8699 BUILD_BUG_ON(PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
%
8700 PQI_QUEUE_ELEMENT_LENGTH_ALIGNMENT
!= 0);
8701 BUILD_BUG_ON(PQI_OPERATIONAL_OQ_ELEMENT_LENGTH
> 1048560);
8702 BUILD_BUG_ON(PQI_OPERATIONAL_OQ_ELEMENT_LENGTH
%
8703 PQI_QUEUE_ELEMENT_LENGTH_ALIGNMENT
!= 0);
8705 BUILD_BUG_ON(PQI_RESERVED_IO_SLOTS
>= PQI_MAX_OUTSTANDING_REQUESTS
);
8706 BUILD_BUG_ON(PQI_RESERVED_IO_SLOTS
>=
8707 PQI_MAX_OUTSTANDING_REQUESTS_KDUMP
);