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.0.4-100"
44 #define DRIVER_MAJOR 1
45 #define DRIVER_MINOR 0
46 #define DRIVER_RELEASE 4
47 #define DRIVER_REVISION 100
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
);
78 /* for flags argument to pqi_submit_raid_request_synchronous() */
79 #define PQI_SYNC_FLAGS_INTERRUPTABLE 0x1
81 static struct scsi_transport_template
*pqi_sas_transport_template
;
83 static atomic_t pqi_controller_count
= ATOMIC_INIT(0);
85 enum pqi_lockup_action
{
91 static enum pqi_lockup_action pqi_lockup_action
= NONE
;
94 enum pqi_lockup_action action
;
96 } pqi_lockup_actions
[] = {
111 static unsigned int pqi_supported_event_types
[] = {
112 PQI_EVENT_TYPE_HOTPLUG
,
113 PQI_EVENT_TYPE_HARDWARE
,
114 PQI_EVENT_TYPE_PHYSICAL_DEVICE
,
115 PQI_EVENT_TYPE_LOGICAL_DEVICE
,
116 PQI_EVENT_TYPE_AIO_STATE_CHANGE
,
117 PQI_EVENT_TYPE_AIO_CONFIG_CHANGE
,
120 static int pqi_disable_device_id_wildcards
;
121 module_param_named(disable_device_id_wildcards
,
122 pqi_disable_device_id_wildcards
, int, 0644);
123 MODULE_PARM_DESC(disable_device_id_wildcards
,
124 "Disable device ID wildcards.");
126 static int pqi_disable_heartbeat
;
127 module_param_named(disable_heartbeat
,
128 pqi_disable_heartbeat
, int, 0644);
129 MODULE_PARM_DESC(disable_heartbeat
,
130 "Disable heartbeat.");
132 static int pqi_disable_ctrl_shutdown
;
133 module_param_named(disable_ctrl_shutdown
,
134 pqi_disable_ctrl_shutdown
, int, 0644);
135 MODULE_PARM_DESC(disable_ctrl_shutdown
,
136 "Disable controller shutdown when controller locked up.");
138 static char *pqi_lockup_action_param
;
139 module_param_named(lockup_action
,
140 pqi_lockup_action_param
, charp
, 0644);
141 MODULE_PARM_DESC(lockup_action
, "Action to take when controller locked up.\n"
142 "\t\tSupported: none, reboot, panic\n"
143 "\t\tDefault: none");
145 static char *raid_levels
[] = {
155 static char *pqi_raid_level_to_string(u8 raid_level
)
157 if (raid_level
< ARRAY_SIZE(raid_levels
))
158 return raid_levels
[raid_level
];
160 return "RAID UNKNOWN";
165 #define SA_RAID_1 2 /* also used for RAID 10 */
166 #define SA_RAID_5 3 /* also used for RAID 50 */
168 #define SA_RAID_6 5 /* also used for RAID 60 */
169 #define SA_RAID_ADM 6 /* also used for RAID 1+0 ADM */
170 #define SA_RAID_MAX SA_RAID_ADM
171 #define SA_RAID_UNKNOWN 0xff
173 static inline void pqi_scsi_done(struct scsi_cmnd
*scmd
)
175 pqi_prep_for_scsi_done(scmd
);
176 scmd
->scsi_done(scmd
);
179 static inline bool pqi_scsi3addr_equal(u8
*scsi3addr1
, u8
*scsi3addr2
)
181 return memcmp(scsi3addr1
, scsi3addr2
, 8) == 0;
184 static inline struct pqi_ctrl_info
*shost_to_hba(struct Scsi_Host
*shost
)
186 void *hostdata
= shost_priv(shost
);
188 return *((struct pqi_ctrl_info
**)hostdata
);
191 static inline bool pqi_is_logical_device(struct pqi_scsi_dev
*device
)
193 return !device
->is_physical_device
;
196 static inline bool pqi_is_external_raid_addr(u8
*scsi3addr
)
198 return scsi3addr
[2] != 0;
201 static inline bool pqi_ctrl_offline(struct pqi_ctrl_info
*ctrl_info
)
203 return !ctrl_info
->controller_online
;
206 static inline void pqi_check_ctrl_health(struct pqi_ctrl_info
*ctrl_info
)
208 if (ctrl_info
->controller_online
)
209 if (!sis_is_firmware_running(ctrl_info
))
210 pqi_take_ctrl_offline(ctrl_info
);
213 static inline bool pqi_is_hba_lunid(u8
*scsi3addr
)
215 return pqi_scsi3addr_equal(scsi3addr
, RAID_CTLR_LUNID
);
218 static inline enum pqi_ctrl_mode
pqi_get_ctrl_mode(
219 struct pqi_ctrl_info
*ctrl_info
)
221 return sis_read_driver_scratch(ctrl_info
);
224 static inline void pqi_save_ctrl_mode(struct pqi_ctrl_info
*ctrl_info
,
225 enum pqi_ctrl_mode mode
)
227 sis_write_driver_scratch(ctrl_info
, mode
);
230 static inline void pqi_ctrl_block_requests(struct pqi_ctrl_info
*ctrl_info
)
232 ctrl_info
->block_requests
= true;
233 scsi_block_requests(ctrl_info
->scsi_host
);
236 static inline void pqi_ctrl_unblock_requests(struct pqi_ctrl_info
*ctrl_info
)
238 ctrl_info
->block_requests
= false;
239 wake_up_all(&ctrl_info
->block_requests_wait
);
240 pqi_retry_raid_bypass_requests(ctrl_info
);
241 scsi_unblock_requests(ctrl_info
->scsi_host
);
244 static inline bool pqi_ctrl_blocked(struct pqi_ctrl_info
*ctrl_info
)
246 return ctrl_info
->block_requests
;
249 static unsigned long pqi_wait_if_ctrl_blocked(struct pqi_ctrl_info
*ctrl_info
,
250 unsigned long timeout_msecs
)
252 unsigned long remaining_msecs
;
254 if (!pqi_ctrl_blocked(ctrl_info
))
255 return timeout_msecs
;
257 atomic_inc(&ctrl_info
->num_blocked_threads
);
259 if (timeout_msecs
== NO_TIMEOUT
) {
260 wait_event(ctrl_info
->block_requests_wait
,
261 !pqi_ctrl_blocked(ctrl_info
));
262 remaining_msecs
= timeout_msecs
;
264 unsigned long remaining_jiffies
;
267 wait_event_timeout(ctrl_info
->block_requests_wait
,
268 !pqi_ctrl_blocked(ctrl_info
),
269 msecs_to_jiffies(timeout_msecs
));
270 remaining_msecs
= jiffies_to_msecs(remaining_jiffies
);
273 atomic_dec(&ctrl_info
->num_blocked_threads
);
275 return remaining_msecs
;
278 static inline void pqi_ctrl_busy(struct pqi_ctrl_info
*ctrl_info
)
280 atomic_inc(&ctrl_info
->num_busy_threads
);
283 static inline void pqi_ctrl_unbusy(struct pqi_ctrl_info
*ctrl_info
)
285 atomic_dec(&ctrl_info
->num_busy_threads
);
288 static inline void pqi_ctrl_wait_until_quiesced(struct pqi_ctrl_info
*ctrl_info
)
290 while (atomic_read(&ctrl_info
->num_busy_threads
) >
291 atomic_read(&ctrl_info
->num_blocked_threads
))
292 usleep_range(1000, 2000);
295 static inline bool pqi_device_offline(struct pqi_scsi_dev
*device
)
297 return device
->device_offline
;
300 static inline void pqi_device_reset_start(struct pqi_scsi_dev
*device
)
302 device
->in_reset
= true;
305 static inline void pqi_device_reset_done(struct pqi_scsi_dev
*device
)
307 device
->in_reset
= false;
310 static inline bool pqi_device_in_reset(struct pqi_scsi_dev
*device
)
312 return device
->in_reset
;
315 static inline void pqi_schedule_rescan_worker_with_delay(
316 struct pqi_ctrl_info
*ctrl_info
, unsigned long delay
)
318 if (pqi_ctrl_offline(ctrl_info
))
321 schedule_delayed_work(&ctrl_info
->rescan_work
, delay
);
324 static inline void pqi_schedule_rescan_worker(struct pqi_ctrl_info
*ctrl_info
)
326 pqi_schedule_rescan_worker_with_delay(ctrl_info
, 0);
329 #define PQI_RESCAN_WORK_DELAY (10 * HZ)
331 static inline void pqi_schedule_rescan_worker_delayed(
332 struct pqi_ctrl_info
*ctrl_info
)
334 pqi_schedule_rescan_worker_with_delay(ctrl_info
, PQI_RESCAN_WORK_DELAY
);
337 static inline void pqi_cancel_rescan_worker(struct pqi_ctrl_info
*ctrl_info
)
339 cancel_delayed_work_sync(&ctrl_info
->rescan_work
);
342 static inline u32
pqi_read_heartbeat_counter(struct pqi_ctrl_info
*ctrl_info
)
344 if (!ctrl_info
->heartbeat_counter
)
347 return readl(ctrl_info
->heartbeat_counter
);
350 static int pqi_map_single(struct pci_dev
*pci_dev
,
351 struct pqi_sg_descriptor
*sg_descriptor
, void *buffer
,
352 size_t buffer_length
, int data_direction
)
354 dma_addr_t bus_address
;
356 if (!buffer
|| buffer_length
== 0 || data_direction
== PCI_DMA_NONE
)
359 bus_address
= pci_map_single(pci_dev
, buffer
, buffer_length
,
361 if (pci_dma_mapping_error(pci_dev
, bus_address
))
364 put_unaligned_le64((u64
)bus_address
, &sg_descriptor
->address
);
365 put_unaligned_le32(buffer_length
, &sg_descriptor
->length
);
366 put_unaligned_le32(CISS_SG_LAST
, &sg_descriptor
->flags
);
371 static void pqi_pci_unmap(struct pci_dev
*pci_dev
,
372 struct pqi_sg_descriptor
*descriptors
, int num_descriptors
,
377 if (data_direction
== PCI_DMA_NONE
)
380 for (i
= 0; i
< num_descriptors
; i
++)
381 pci_unmap_single(pci_dev
,
382 (dma_addr_t
)get_unaligned_le64(&descriptors
[i
].address
),
383 get_unaligned_le32(&descriptors
[i
].length
),
387 static int pqi_build_raid_path_request(struct pqi_ctrl_info
*ctrl_info
,
388 struct pqi_raid_path_request
*request
, u8 cmd
,
389 u8
*scsi3addr
, void *buffer
, size_t buffer_length
,
390 u16 vpd_page
, int *pci_direction
)
395 memset(request
, 0, sizeof(*request
));
397 request
->header
.iu_type
= PQI_REQUEST_IU_RAID_PATH_IO
;
398 put_unaligned_le16(offsetof(struct pqi_raid_path_request
,
399 sg_descriptors
[1]) - PQI_REQUEST_HEADER_LENGTH
,
400 &request
->header
.iu_length
);
401 put_unaligned_le32(buffer_length
, &request
->buffer_length
);
402 memcpy(request
->lun_number
, scsi3addr
, sizeof(request
->lun_number
));
403 request
->task_attribute
= SOP_TASK_ATTRIBUTE_SIMPLE
;
404 request
->additional_cdb_bytes_usage
= SOP_ADDITIONAL_CDB_BYTES_0
;
410 request
->data_direction
= SOP_READ_FLAG
;
412 if (vpd_page
& VPD_PAGE
) {
414 cdb
[2] = (u8
)vpd_page
;
416 cdb
[4] = (u8
)buffer_length
;
418 case CISS_REPORT_LOG
:
419 case CISS_REPORT_PHYS
:
420 request
->data_direction
= SOP_READ_FLAG
;
422 if (cmd
== CISS_REPORT_PHYS
)
423 cdb
[1] = CISS_REPORT_PHYS_EXTENDED
;
425 cdb
[1] = CISS_REPORT_LOG_EXTENDED
;
426 put_unaligned_be32(buffer_length
, &cdb
[6]);
428 case CISS_GET_RAID_MAP
:
429 request
->data_direction
= SOP_READ_FLAG
;
431 cdb
[1] = CISS_GET_RAID_MAP
;
432 put_unaligned_be32(buffer_length
, &cdb
[6]);
435 request
->data_direction
= SOP_WRITE_FLAG
;
437 cdb
[6] = BMIC_CACHE_FLUSH
;
438 put_unaligned_be16(buffer_length
, &cdb
[7]);
440 case BMIC_IDENTIFY_CONTROLLER
:
441 case BMIC_IDENTIFY_PHYSICAL_DEVICE
:
442 request
->data_direction
= SOP_READ_FLAG
;
445 put_unaligned_be16(buffer_length
, &cdb
[7]);
447 case BMIC_WRITE_HOST_WELLNESS
:
448 request
->data_direction
= SOP_WRITE_FLAG
;
451 put_unaligned_be16(buffer_length
, &cdb
[7]);
454 dev_err(&ctrl_info
->pci_dev
->dev
, "unknown command 0x%c\n",
459 switch (request
->data_direction
) {
461 pci_dir
= PCI_DMA_FROMDEVICE
;
464 pci_dir
= PCI_DMA_TODEVICE
;
466 case SOP_NO_DIRECTION_FLAG
:
467 pci_dir
= PCI_DMA_NONE
;
470 pci_dir
= PCI_DMA_BIDIRECTIONAL
;
474 *pci_direction
= pci_dir
;
476 return pqi_map_single(ctrl_info
->pci_dev
, &request
->sg_descriptors
[0],
477 buffer
, buffer_length
, pci_dir
);
480 static inline void pqi_reinit_io_request(struct pqi_io_request
*io_request
)
482 io_request
->scmd
= NULL
;
483 io_request
->status
= 0;
484 io_request
->error_info
= NULL
;
485 io_request
->raid_bypass
= false;
488 static struct pqi_io_request
*pqi_alloc_io_request(
489 struct pqi_ctrl_info
*ctrl_info
)
491 struct pqi_io_request
*io_request
;
492 u16 i
= ctrl_info
->next_io_request_slot
; /* benignly racy */
495 io_request
= &ctrl_info
->io_request_pool
[i
];
496 if (atomic_inc_return(&io_request
->refcount
) == 1)
498 atomic_dec(&io_request
->refcount
);
499 i
= (i
+ 1) % ctrl_info
->max_io_slots
;
503 ctrl_info
->next_io_request_slot
= (i
+ 1) % ctrl_info
->max_io_slots
;
505 pqi_reinit_io_request(io_request
);
510 static void pqi_free_io_request(struct pqi_io_request
*io_request
)
512 atomic_dec(&io_request
->refcount
);
515 static int pqi_identify_controller(struct pqi_ctrl_info
*ctrl_info
,
516 struct bmic_identify_controller
*buffer
)
520 struct pqi_raid_path_request request
;
522 rc
= pqi_build_raid_path_request(ctrl_info
, &request
,
523 BMIC_IDENTIFY_CONTROLLER
, RAID_CTLR_LUNID
, buffer
,
524 sizeof(*buffer
), 0, &pci_direction
);
528 rc
= pqi_submit_raid_request_synchronous(ctrl_info
, &request
.header
, 0,
531 pqi_pci_unmap(ctrl_info
->pci_dev
, request
.sg_descriptors
, 1,
537 static int pqi_scsi_inquiry(struct pqi_ctrl_info
*ctrl_info
,
538 u8
*scsi3addr
, u16 vpd_page
, void *buffer
, size_t buffer_length
)
542 struct pqi_raid_path_request request
;
544 rc
= pqi_build_raid_path_request(ctrl_info
, &request
,
545 INQUIRY
, scsi3addr
, buffer
, buffer_length
, vpd_page
,
550 rc
= pqi_submit_raid_request_synchronous(ctrl_info
, &request
.header
, 0,
553 pqi_pci_unmap(ctrl_info
->pci_dev
, request
.sg_descriptors
, 1,
559 static int pqi_identify_physical_device(struct pqi_ctrl_info
*ctrl_info
,
560 struct pqi_scsi_dev
*device
,
561 struct bmic_identify_physical_device
*buffer
,
562 size_t buffer_length
)
566 u16 bmic_device_index
;
567 struct pqi_raid_path_request request
;
569 rc
= pqi_build_raid_path_request(ctrl_info
, &request
,
570 BMIC_IDENTIFY_PHYSICAL_DEVICE
, RAID_CTLR_LUNID
, buffer
,
571 buffer_length
, 0, &pci_direction
);
575 bmic_device_index
= CISS_GET_DRIVE_NUMBER(device
->scsi3addr
);
576 request
.cdb
[2] = (u8
)bmic_device_index
;
577 request
.cdb
[9] = (u8
)(bmic_device_index
>> 8);
579 rc
= pqi_submit_raid_request_synchronous(ctrl_info
, &request
.header
,
580 0, NULL
, NO_TIMEOUT
);
582 pqi_pci_unmap(ctrl_info
->pci_dev
, request
.sg_descriptors
, 1,
588 #define SA_CACHE_FLUSH_BUFFER_LENGTH 4
590 static int pqi_flush_cache(struct pqi_ctrl_info
*ctrl_info
)
593 struct pqi_raid_path_request request
;
598 * Don't bother trying to flush the cache if the controller is
601 if (pqi_ctrl_offline(ctrl_info
))
604 buffer
= kzalloc(SA_CACHE_FLUSH_BUFFER_LENGTH
, GFP_KERNEL
);
608 rc
= pqi_build_raid_path_request(ctrl_info
, &request
,
609 SA_CACHE_FLUSH
, RAID_CTLR_LUNID
, buffer
,
610 SA_CACHE_FLUSH_BUFFER_LENGTH
, 0, &pci_direction
);
614 rc
= pqi_submit_raid_request_synchronous(ctrl_info
, &request
.header
,
615 0, NULL
, NO_TIMEOUT
);
617 pqi_pci_unmap(ctrl_info
->pci_dev
, request
.sg_descriptors
, 1,
626 static int pqi_write_host_wellness(struct pqi_ctrl_info
*ctrl_info
,
627 void *buffer
, size_t buffer_length
)
630 struct pqi_raid_path_request request
;
633 rc
= pqi_build_raid_path_request(ctrl_info
, &request
,
634 BMIC_WRITE_HOST_WELLNESS
, RAID_CTLR_LUNID
, buffer
,
635 buffer_length
, 0, &pci_direction
);
639 rc
= pqi_submit_raid_request_synchronous(ctrl_info
, &request
.header
,
640 0, NULL
, NO_TIMEOUT
);
642 pqi_pci_unmap(ctrl_info
->pci_dev
, request
.sg_descriptors
, 1,
650 struct bmic_host_wellness_driver_version
{
652 u8 driver_version_tag
[2];
653 __le16 driver_version_length
;
654 char driver_version
[32];
660 static int pqi_write_driver_version_to_host_wellness(
661 struct pqi_ctrl_info
*ctrl_info
)
664 struct bmic_host_wellness_driver_version
*buffer
;
665 size_t buffer_length
;
667 buffer_length
= sizeof(*buffer
);
669 buffer
= kmalloc(buffer_length
, GFP_KERNEL
);
673 buffer
->start_tag
[0] = '<';
674 buffer
->start_tag
[1] = 'H';
675 buffer
->start_tag
[2] = 'W';
676 buffer
->start_tag
[3] = '>';
677 buffer
->driver_version_tag
[0] = 'D';
678 buffer
->driver_version_tag
[1] = 'V';
679 put_unaligned_le16(sizeof(buffer
->driver_version
),
680 &buffer
->driver_version_length
);
681 strncpy(buffer
->driver_version
, "Linux " DRIVER_VERSION
,
682 sizeof(buffer
->driver_version
) - 1);
683 buffer
->driver_version
[sizeof(buffer
->driver_version
) - 1] = '\0';
684 buffer
->end_tag
[0] = 'Z';
685 buffer
->end_tag
[1] = 'Z';
687 rc
= pqi_write_host_wellness(ctrl_info
, buffer
, buffer_length
);
696 struct bmic_host_wellness_time
{
701 u8 dont_write_tag
[2];
707 static int pqi_write_current_time_to_host_wellness(
708 struct pqi_ctrl_info
*ctrl_info
)
711 struct bmic_host_wellness_time
*buffer
;
712 size_t buffer_length
;
717 buffer_length
= sizeof(*buffer
);
719 buffer
= kmalloc(buffer_length
, GFP_KERNEL
);
723 buffer
->start_tag
[0] = '<';
724 buffer
->start_tag
[1] = 'H';
725 buffer
->start_tag
[2] = 'W';
726 buffer
->start_tag
[3] = '>';
727 buffer
->time_tag
[0] = 'T';
728 buffer
->time_tag
[1] = 'D';
729 put_unaligned_le16(sizeof(buffer
->time
),
730 &buffer
->time_length
);
732 local_time
= ktime_get_real_seconds();
733 time64_to_tm(local_time
, -sys_tz
.tz_minuteswest
* 60, &tm
);
734 year
= tm
.tm_year
+ 1900;
736 buffer
->time
[0] = bin2bcd(tm
.tm_hour
);
737 buffer
->time
[1] = bin2bcd(tm
.tm_min
);
738 buffer
->time
[2] = bin2bcd(tm
.tm_sec
);
740 buffer
->time
[4] = bin2bcd(tm
.tm_mon
+ 1);
741 buffer
->time
[5] = bin2bcd(tm
.tm_mday
);
742 buffer
->time
[6] = bin2bcd(year
/ 100);
743 buffer
->time
[7] = bin2bcd(year
% 100);
745 buffer
->dont_write_tag
[0] = 'D';
746 buffer
->dont_write_tag
[1] = 'W';
747 buffer
->end_tag
[0] = 'Z';
748 buffer
->end_tag
[1] = 'Z';
750 rc
= pqi_write_host_wellness(ctrl_info
, buffer
, buffer_length
);
757 #define PQI_UPDATE_TIME_WORK_INTERVAL (24UL * 60 * 60 * HZ)
759 static void pqi_update_time_worker(struct work_struct
*work
)
762 struct pqi_ctrl_info
*ctrl_info
;
764 ctrl_info
= container_of(to_delayed_work(work
), struct pqi_ctrl_info
,
767 if (pqi_ctrl_offline(ctrl_info
))
770 rc
= pqi_write_current_time_to_host_wellness(ctrl_info
);
772 dev_warn(&ctrl_info
->pci_dev
->dev
,
773 "error updating time on controller\n");
775 schedule_delayed_work(&ctrl_info
->update_time_work
,
776 PQI_UPDATE_TIME_WORK_INTERVAL
);
779 static inline void pqi_schedule_update_time_worker(
780 struct pqi_ctrl_info
*ctrl_info
)
782 schedule_delayed_work(&ctrl_info
->update_time_work
, 0);
785 static inline void pqi_cancel_update_time_worker(
786 struct pqi_ctrl_info
*ctrl_info
)
788 cancel_delayed_work_sync(&ctrl_info
->update_time_work
);
791 static int pqi_report_luns(struct pqi_ctrl_info
*ctrl_info
, u8 cmd
,
792 void *buffer
, size_t buffer_length
)
796 struct pqi_raid_path_request request
;
798 rc
= pqi_build_raid_path_request(ctrl_info
, &request
,
799 cmd
, RAID_CTLR_LUNID
, buffer
, buffer_length
, 0, &pci_direction
);
803 rc
= pqi_submit_raid_request_synchronous(ctrl_info
, &request
.header
, 0,
806 pqi_pci_unmap(ctrl_info
->pci_dev
, request
.sg_descriptors
, 1,
812 static int pqi_report_phys_logical_luns(struct pqi_ctrl_info
*ctrl_info
, u8 cmd
,
816 size_t lun_list_length
;
817 size_t lun_data_length
;
818 size_t new_lun_list_length
;
819 void *lun_data
= NULL
;
820 struct report_lun_header
*report_lun_header
;
822 report_lun_header
= kmalloc(sizeof(*report_lun_header
), GFP_KERNEL
);
823 if (!report_lun_header
) {
828 rc
= pqi_report_luns(ctrl_info
, cmd
, report_lun_header
,
829 sizeof(*report_lun_header
));
833 lun_list_length
= get_unaligned_be32(&report_lun_header
->list_length
);
836 lun_data_length
= sizeof(struct report_lun_header
) + lun_list_length
;
838 lun_data
= kmalloc(lun_data_length
, GFP_KERNEL
);
844 if (lun_list_length
== 0) {
845 memcpy(lun_data
, report_lun_header
, sizeof(*report_lun_header
));
849 rc
= pqi_report_luns(ctrl_info
, cmd
, lun_data
, lun_data_length
);
853 new_lun_list_length
= get_unaligned_be32(
854 &((struct report_lun_header
*)lun_data
)->list_length
);
856 if (new_lun_list_length
> lun_list_length
) {
857 lun_list_length
= new_lun_list_length
;
863 kfree(report_lun_header
);
875 static inline int pqi_report_phys_luns(struct pqi_ctrl_info
*ctrl_info
,
878 return pqi_report_phys_logical_luns(ctrl_info
, CISS_REPORT_PHYS
,
882 static inline int pqi_report_logical_luns(struct pqi_ctrl_info
*ctrl_info
,
885 return pqi_report_phys_logical_luns(ctrl_info
, CISS_REPORT_LOG
, buffer
);
888 static int pqi_get_device_lists(struct pqi_ctrl_info
*ctrl_info
,
889 struct report_phys_lun_extended
**physdev_list
,
890 struct report_log_lun_extended
**logdev_list
)
893 size_t logdev_list_length
;
894 size_t logdev_data_length
;
895 struct report_log_lun_extended
*internal_logdev_list
;
896 struct report_log_lun_extended
*logdev_data
;
897 struct report_lun_header report_lun_header
;
899 rc
= pqi_report_phys_luns(ctrl_info
, (void **)physdev_list
);
901 dev_err(&ctrl_info
->pci_dev
->dev
,
902 "report physical LUNs failed\n");
904 rc
= pqi_report_logical_luns(ctrl_info
, (void **)logdev_list
);
906 dev_err(&ctrl_info
->pci_dev
->dev
,
907 "report logical LUNs failed\n");
910 * Tack the controller itself onto the end of the logical device list.
913 logdev_data
= *logdev_list
;
917 get_unaligned_be32(&logdev_data
->header
.list_length
);
919 memset(&report_lun_header
, 0, sizeof(report_lun_header
));
921 (struct report_log_lun_extended
*)&report_lun_header
;
922 logdev_list_length
= 0;
925 logdev_data_length
= sizeof(struct report_lun_header
) +
928 internal_logdev_list
= kmalloc(logdev_data_length
+
929 sizeof(struct report_log_lun_extended
), GFP_KERNEL
);
930 if (!internal_logdev_list
) {
936 memcpy(internal_logdev_list
, logdev_data
, logdev_data_length
);
937 memset((u8
*)internal_logdev_list
+ logdev_data_length
, 0,
938 sizeof(struct report_log_lun_extended_entry
));
939 put_unaligned_be32(logdev_list_length
+
940 sizeof(struct report_log_lun_extended_entry
),
941 &internal_logdev_list
->header
.list_length
);
944 *logdev_list
= internal_logdev_list
;
949 static inline void pqi_set_bus_target_lun(struct pqi_scsi_dev
*device
,
950 int bus
, int target
, int lun
)
953 device
->target
= target
;
957 static void pqi_assign_bus_target_lun(struct pqi_scsi_dev
*device
)
965 scsi3addr
= device
->scsi3addr
;
966 lunid
= get_unaligned_le32(scsi3addr
);
968 if (pqi_is_hba_lunid(scsi3addr
)) {
969 /* The specified device is the controller. */
970 pqi_set_bus_target_lun(device
, PQI_HBA_BUS
, 0, lunid
& 0x3fff);
971 device
->target_lun_valid
= true;
975 if (pqi_is_logical_device(device
)) {
976 if (device
->is_external_raid_device
) {
977 bus
= PQI_EXTERNAL_RAID_VOLUME_BUS
;
978 target
= (lunid
>> 16) & 0x3fff;
981 bus
= PQI_RAID_VOLUME_BUS
;
983 lun
= lunid
& 0x3fff;
985 pqi_set_bus_target_lun(device
, bus
, target
, lun
);
986 device
->target_lun_valid
= true;
991 * Defer target and LUN assignment for non-controller physical devices
992 * because the SAS transport layer will make these assignments later.
994 pqi_set_bus_target_lun(device
, PQI_PHYSICAL_DEVICE_BUS
, 0, 0);
997 static void pqi_get_raid_level(struct pqi_ctrl_info
*ctrl_info
,
998 struct pqi_scsi_dev
*device
)
1004 raid_level
= SA_RAID_UNKNOWN
;
1006 buffer
= kmalloc(64, GFP_KERNEL
);
1008 rc
= pqi_scsi_inquiry(ctrl_info
, device
->scsi3addr
,
1009 VPD_PAGE
| CISS_VPD_LV_DEVICE_GEOMETRY
, buffer
, 64);
1011 raid_level
= buffer
[8];
1012 if (raid_level
> SA_RAID_MAX
)
1013 raid_level
= SA_RAID_UNKNOWN
;
1018 device
->raid_level
= raid_level
;
1021 static int pqi_validate_raid_map(struct pqi_ctrl_info
*ctrl_info
,
1022 struct pqi_scsi_dev
*device
, struct raid_map
*raid_map
)
1026 u32 r5or6_blocks_per_row
;
1027 unsigned int num_phys_disks
;
1028 unsigned int num_raid_map_entries
;
1030 raid_map_size
= get_unaligned_le32(&raid_map
->structure_size
);
1032 if (raid_map_size
< offsetof(struct raid_map
, disk_data
)) {
1033 err_msg
= "RAID map too small";
1037 if (raid_map_size
> sizeof(*raid_map
)) {
1038 err_msg
= "RAID map too large";
1042 num_phys_disks
= get_unaligned_le16(&raid_map
->layout_map_count
) *
1043 (get_unaligned_le16(&raid_map
->data_disks_per_row
) +
1044 get_unaligned_le16(&raid_map
->metadata_disks_per_row
));
1045 num_raid_map_entries
= num_phys_disks
*
1046 get_unaligned_le16(&raid_map
->row_cnt
);
1048 if (num_raid_map_entries
> RAID_MAP_MAX_ENTRIES
) {
1049 err_msg
= "invalid number of map entries in RAID map";
1053 if (device
->raid_level
== SA_RAID_1
) {
1054 if (get_unaligned_le16(&raid_map
->layout_map_count
) != 2) {
1055 err_msg
= "invalid RAID-1 map";
1058 } else if (device
->raid_level
== SA_RAID_ADM
) {
1059 if (get_unaligned_le16(&raid_map
->layout_map_count
) != 3) {
1060 err_msg
= "invalid RAID-1(ADM) map";
1063 } else if ((device
->raid_level
== SA_RAID_5
||
1064 device
->raid_level
== SA_RAID_6
) &&
1065 get_unaligned_le16(&raid_map
->layout_map_count
) > 1) {
1067 r5or6_blocks_per_row
=
1068 get_unaligned_le16(&raid_map
->strip_size
) *
1069 get_unaligned_le16(&raid_map
->data_disks_per_row
);
1070 if (r5or6_blocks_per_row
== 0) {
1071 err_msg
= "invalid RAID-5 or RAID-6 map";
1079 dev_warn(&ctrl_info
->pci_dev
->dev
,
1080 "scsi %d:%d:%d:%d %s\n",
1081 ctrl_info
->scsi_host
->host_no
,
1082 device
->bus
, device
->target
, device
->lun
, err_msg
);
1087 static int pqi_get_raid_map(struct pqi_ctrl_info
*ctrl_info
,
1088 struct pqi_scsi_dev
*device
)
1092 struct pqi_raid_path_request request
;
1093 struct raid_map
*raid_map
;
1095 raid_map
= kmalloc(sizeof(*raid_map
), GFP_KERNEL
);
1099 rc
= pqi_build_raid_path_request(ctrl_info
, &request
,
1100 CISS_GET_RAID_MAP
, device
->scsi3addr
, raid_map
,
1101 sizeof(*raid_map
), 0, &pci_direction
);
1105 rc
= pqi_submit_raid_request_synchronous(ctrl_info
, &request
.header
, 0,
1108 pqi_pci_unmap(ctrl_info
->pci_dev
, request
.sg_descriptors
, 1,
1114 rc
= pqi_validate_raid_map(ctrl_info
, device
, raid_map
);
1118 device
->raid_map
= raid_map
;
1128 static void pqi_get_raid_bypass_status(struct pqi_ctrl_info
*ctrl_info
,
1129 struct pqi_scsi_dev
*device
)
1135 buffer
= kmalloc(64, GFP_KERNEL
);
1139 rc
= pqi_scsi_inquiry(ctrl_info
, device
->scsi3addr
,
1140 VPD_PAGE
| CISS_VPD_LV_BYPASS_STATUS
, buffer
, 64);
1144 #define RAID_BYPASS_STATUS 4
1145 #define RAID_BYPASS_CONFIGURED 0x1
1146 #define RAID_BYPASS_ENABLED 0x2
1148 bypass_status
= buffer
[RAID_BYPASS_STATUS
];
1149 device
->raid_bypass_configured
=
1150 (bypass_status
& RAID_BYPASS_CONFIGURED
) != 0;
1151 if (device
->raid_bypass_configured
&&
1152 (bypass_status
& RAID_BYPASS_ENABLED
) &&
1153 pqi_get_raid_map(ctrl_info
, device
) == 0)
1154 device
->raid_bypass_enabled
= true;
1161 * Use vendor-specific VPD to determine online/offline status of a volume.
1164 static void pqi_get_volume_status(struct pqi_ctrl_info
*ctrl_info
,
1165 struct pqi_scsi_dev
*device
)
1169 u8 volume_status
= CISS_LV_STATUS_UNAVAILABLE
;
1170 bool volume_offline
= true;
1172 struct ciss_vpd_logical_volume_status
*vpd
;
1174 vpd
= kmalloc(sizeof(*vpd
), GFP_KERNEL
);
1178 rc
= pqi_scsi_inquiry(ctrl_info
, device
->scsi3addr
,
1179 VPD_PAGE
| CISS_VPD_LV_STATUS
, vpd
, sizeof(*vpd
));
1183 page_length
= offsetof(struct ciss_vpd_logical_volume_status
,
1184 volume_status
) + vpd
->page_length
;
1185 if (page_length
< sizeof(*vpd
))
1188 volume_status
= vpd
->volume_status
;
1189 volume_flags
= get_unaligned_be32(&vpd
->flags
);
1190 volume_offline
= (volume_flags
& CISS_LV_FLAGS_NO_HOST_IO
) != 0;
1195 device
->volume_status
= volume_status
;
1196 device
->volume_offline
= volume_offline
;
1199 static int pqi_get_device_info(struct pqi_ctrl_info
*ctrl_info
,
1200 struct pqi_scsi_dev
*device
)
1205 buffer
= kmalloc(64, GFP_KERNEL
);
1209 /* Send an inquiry to the device to see what it is. */
1210 rc
= pqi_scsi_inquiry(ctrl_info
, device
->scsi3addr
, 0, buffer
, 64);
1214 scsi_sanitize_inquiry_string(&buffer
[8], 8);
1215 scsi_sanitize_inquiry_string(&buffer
[16], 16);
1217 device
->devtype
= buffer
[0] & 0x1f;
1218 memcpy(device
->vendor
, &buffer
[8], sizeof(device
->vendor
));
1219 memcpy(device
->model
, &buffer
[16], sizeof(device
->model
));
1221 if (pqi_is_logical_device(device
) && device
->devtype
== TYPE_DISK
) {
1222 if (device
->is_external_raid_device
) {
1223 device
->raid_level
= SA_RAID_UNKNOWN
;
1224 device
->volume_status
= CISS_LV_OK
;
1225 device
->volume_offline
= false;
1227 pqi_get_raid_level(ctrl_info
, device
);
1228 pqi_get_raid_bypass_status(ctrl_info
, device
);
1229 pqi_get_volume_status(ctrl_info
, device
);
1239 static void pqi_get_physical_disk_info(struct pqi_ctrl_info
*ctrl_info
,
1240 struct pqi_scsi_dev
*device
,
1241 struct bmic_identify_physical_device
*id_phys
)
1245 memset(id_phys
, 0, sizeof(*id_phys
));
1247 rc
= pqi_identify_physical_device(ctrl_info
, device
,
1248 id_phys
, sizeof(*id_phys
));
1250 device
->queue_depth
= PQI_PHYSICAL_DISK_DEFAULT_MAX_QUEUE_DEPTH
;
1254 device
->queue_depth
=
1255 get_unaligned_le16(&id_phys
->current_queue_depth_limit
);
1256 device
->device_type
= id_phys
->device_type
;
1257 device
->active_path_index
= id_phys
->active_path_number
;
1258 device
->path_map
= id_phys
->redundant_path_present_map
;
1259 memcpy(&device
->box
,
1260 &id_phys
->alternate_paths_phys_box_on_port
,
1261 sizeof(device
->box
));
1262 memcpy(&device
->phys_connector
,
1263 &id_phys
->alternate_paths_phys_connector
,
1264 sizeof(device
->phys_connector
));
1265 device
->bay
= id_phys
->phys_bay_in_box
;
1268 static void pqi_show_volume_status(struct pqi_ctrl_info
*ctrl_info
,
1269 struct pqi_scsi_dev
*device
)
1272 static const char unknown_state_str
[] =
1273 "Volume is in an unknown state (%u)";
1274 char unknown_state_buffer
[sizeof(unknown_state_str
) + 10];
1276 switch (device
->volume_status
) {
1278 status
= "Volume online";
1280 case CISS_LV_FAILED
:
1281 status
= "Volume failed";
1283 case CISS_LV_NOT_CONFIGURED
:
1284 status
= "Volume not configured";
1286 case CISS_LV_DEGRADED
:
1287 status
= "Volume degraded";
1289 case CISS_LV_READY_FOR_RECOVERY
:
1290 status
= "Volume ready for recovery operation";
1292 case CISS_LV_UNDERGOING_RECOVERY
:
1293 status
= "Volume undergoing recovery";
1295 case CISS_LV_WRONG_PHYSICAL_DRIVE_REPLACED
:
1296 status
= "Wrong physical drive was replaced";
1298 case CISS_LV_PHYSICAL_DRIVE_CONNECTION_PROBLEM
:
1299 status
= "A physical drive not properly connected";
1301 case CISS_LV_HARDWARE_OVERHEATING
:
1302 status
= "Hardware is overheating";
1304 case CISS_LV_HARDWARE_HAS_OVERHEATED
:
1305 status
= "Hardware has overheated";
1307 case CISS_LV_UNDERGOING_EXPANSION
:
1308 status
= "Volume undergoing expansion";
1310 case CISS_LV_NOT_AVAILABLE
:
1311 status
= "Volume waiting for transforming volume";
1313 case CISS_LV_QUEUED_FOR_EXPANSION
:
1314 status
= "Volume queued for expansion";
1316 case CISS_LV_DISABLED_SCSI_ID_CONFLICT
:
1317 status
= "Volume disabled due to SCSI ID conflict";
1319 case CISS_LV_EJECTED
:
1320 status
= "Volume has been ejected";
1322 case CISS_LV_UNDERGOING_ERASE
:
1323 status
= "Volume undergoing background erase";
1325 case CISS_LV_READY_FOR_PREDICTIVE_SPARE_REBUILD
:
1326 status
= "Volume ready for predictive spare rebuild";
1328 case CISS_LV_UNDERGOING_RPI
:
1329 status
= "Volume undergoing rapid parity initialization";
1331 case CISS_LV_PENDING_RPI
:
1332 status
= "Volume queued for rapid parity initialization";
1334 case CISS_LV_ENCRYPTED_NO_KEY
:
1335 status
= "Encrypted volume inaccessible - key not present";
1337 case CISS_LV_UNDERGOING_ENCRYPTION
:
1338 status
= "Volume undergoing encryption process";
1340 case CISS_LV_UNDERGOING_ENCRYPTION_REKEYING
:
1341 status
= "Volume undergoing encryption re-keying process";
1343 case CISS_LV_ENCRYPTED_IN_NON_ENCRYPTED_CONTROLLER
:
1344 status
= "Volume encrypted but encryption is disabled";
1346 case CISS_LV_PENDING_ENCRYPTION
:
1347 status
= "Volume pending migration to encrypted state";
1349 case CISS_LV_PENDING_ENCRYPTION_REKEYING
:
1350 status
= "Volume pending encryption rekeying";
1352 case CISS_LV_NOT_SUPPORTED
:
1353 status
= "Volume not supported on this controller";
1355 case CISS_LV_STATUS_UNAVAILABLE
:
1356 status
= "Volume status not available";
1359 snprintf(unknown_state_buffer
, sizeof(unknown_state_buffer
),
1360 unknown_state_str
, device
->volume_status
);
1361 status
= unknown_state_buffer
;
1365 dev_info(&ctrl_info
->pci_dev
->dev
,
1366 "scsi %d:%d:%d:%d %s\n",
1367 ctrl_info
->scsi_host
->host_no
,
1368 device
->bus
, device
->target
, device
->lun
, status
);
1371 static void pqi_rescan_worker(struct work_struct
*work
)
1373 struct pqi_ctrl_info
*ctrl_info
;
1375 ctrl_info
= container_of(to_delayed_work(work
), struct pqi_ctrl_info
,
1378 pqi_scan_scsi_devices(ctrl_info
);
1381 static int pqi_add_device(struct pqi_ctrl_info
*ctrl_info
,
1382 struct pqi_scsi_dev
*device
)
1386 if (pqi_is_logical_device(device
))
1387 rc
= scsi_add_device(ctrl_info
->scsi_host
, device
->bus
,
1388 device
->target
, device
->lun
);
1390 rc
= pqi_add_sas_device(ctrl_info
->sas_host
, device
);
1395 static inline void pqi_remove_device(struct pqi_ctrl_info
*ctrl_info
,
1396 struct pqi_scsi_dev
*device
)
1398 if (pqi_is_logical_device(device
))
1399 scsi_remove_device(device
->sdev
);
1401 pqi_remove_sas_device(device
);
1404 /* Assumes the SCSI device list lock is held. */
1406 static struct pqi_scsi_dev
*pqi_find_scsi_dev(struct pqi_ctrl_info
*ctrl_info
,
1407 int bus
, int target
, int lun
)
1409 struct pqi_scsi_dev
*device
;
1411 list_for_each_entry(device
, &ctrl_info
->scsi_device_list
,
1412 scsi_device_list_entry
)
1413 if (device
->bus
== bus
&& device
->target
== target
&&
1420 static inline bool pqi_device_equal(struct pqi_scsi_dev
*dev1
,
1421 struct pqi_scsi_dev
*dev2
)
1423 if (dev1
->is_physical_device
!= dev2
->is_physical_device
)
1426 if (dev1
->is_physical_device
)
1427 return dev1
->wwid
== dev2
->wwid
;
1429 return memcmp(dev1
->volume_id
, dev2
->volume_id
,
1430 sizeof(dev1
->volume_id
)) == 0;
1433 enum pqi_find_result
{
1439 static enum pqi_find_result
pqi_scsi_find_entry(struct pqi_ctrl_info
*ctrl_info
,
1440 struct pqi_scsi_dev
*device_to_find
,
1441 struct pqi_scsi_dev
**matching_device
)
1443 struct pqi_scsi_dev
*device
;
1445 list_for_each_entry(device
, &ctrl_info
->scsi_device_list
,
1446 scsi_device_list_entry
) {
1447 if (pqi_scsi3addr_equal(device_to_find
->scsi3addr
,
1448 device
->scsi3addr
)) {
1449 *matching_device
= device
;
1450 if (pqi_device_equal(device_to_find
, device
)) {
1451 if (device_to_find
->volume_offline
)
1452 return DEVICE_CHANGED
;
1455 return DEVICE_CHANGED
;
1459 return DEVICE_NOT_FOUND
;
1462 #define PQI_DEV_INFO_BUFFER_LENGTH 128
1464 static void pqi_dev_info(struct pqi_ctrl_info
*ctrl_info
,
1465 char *action
, struct pqi_scsi_dev
*device
)
1468 char buffer
[PQI_DEV_INFO_BUFFER_LENGTH
];
1470 count
= snprintf(buffer
, PQI_DEV_INFO_BUFFER_LENGTH
,
1471 "%d:%d:", ctrl_info
->scsi_host
->host_no
, device
->bus
);
1473 if (device
->target_lun_valid
)
1474 count
+= snprintf(buffer
+ count
,
1475 PQI_DEV_INFO_BUFFER_LENGTH
- count
,
1480 count
+= snprintf(buffer
+ count
,
1481 PQI_DEV_INFO_BUFFER_LENGTH
- count
,
1484 if (pqi_is_logical_device(device
))
1485 count
+= snprintf(buffer
+ count
,
1486 PQI_DEV_INFO_BUFFER_LENGTH
- count
,
1488 *((u32
*)&device
->scsi3addr
),
1489 *((u32
*)&device
->scsi3addr
[4]));
1491 count
+= snprintf(buffer
+ count
,
1492 PQI_DEV_INFO_BUFFER_LENGTH
- count
,
1493 " %016llx", device
->sas_address
);
1495 count
+= snprintf(buffer
+ count
, PQI_DEV_INFO_BUFFER_LENGTH
- count
,
1497 scsi_device_type(device
->devtype
),
1501 if (pqi_is_logical_device(device
)) {
1502 if (device
->devtype
== TYPE_DISK
)
1503 count
+= snprintf(buffer
+ count
,
1504 PQI_DEV_INFO_BUFFER_LENGTH
- count
,
1505 "SSDSmartPathCap%c En%c %-12s",
1506 device
->raid_bypass_configured
? '+' : '-',
1507 device
->raid_bypass_enabled
? '+' : '-',
1508 pqi_raid_level_to_string(device
->raid_level
));
1510 count
+= snprintf(buffer
+ count
,
1511 PQI_DEV_INFO_BUFFER_LENGTH
- count
,
1512 "AIO%c", device
->aio_enabled
? '+' : '-');
1513 if (device
->devtype
== TYPE_DISK
||
1514 device
->devtype
== TYPE_ZBC
)
1515 count
+= snprintf(buffer
+ count
,
1516 PQI_DEV_INFO_BUFFER_LENGTH
- count
,
1517 " qd=%-6d", device
->queue_depth
);
1520 dev_info(&ctrl_info
->pci_dev
->dev
, "%s %s\n", action
, buffer
);
1523 /* Assumes the SCSI device list lock is held. */
1525 static void pqi_scsi_update_device(struct pqi_scsi_dev
*existing_device
,
1526 struct pqi_scsi_dev
*new_device
)
1528 existing_device
->devtype
= new_device
->devtype
;
1529 existing_device
->device_type
= new_device
->device_type
;
1530 existing_device
->bus
= new_device
->bus
;
1531 if (new_device
->target_lun_valid
) {
1532 existing_device
->target
= new_device
->target
;
1533 existing_device
->lun
= new_device
->lun
;
1534 existing_device
->target_lun_valid
= true;
1537 /* By definition, the scsi3addr and wwid fields are already the same. */
1539 existing_device
->is_physical_device
= new_device
->is_physical_device
;
1540 existing_device
->is_external_raid_device
=
1541 new_device
->is_external_raid_device
;
1542 existing_device
->aio_enabled
= new_device
->aio_enabled
;
1543 memcpy(existing_device
->vendor
, new_device
->vendor
,
1544 sizeof(existing_device
->vendor
));
1545 memcpy(existing_device
->model
, new_device
->model
,
1546 sizeof(existing_device
->model
));
1547 existing_device
->sas_address
= new_device
->sas_address
;
1548 existing_device
->raid_level
= new_device
->raid_level
;
1549 existing_device
->queue_depth
= new_device
->queue_depth
;
1550 existing_device
->aio_handle
= new_device
->aio_handle
;
1551 existing_device
->volume_status
= new_device
->volume_status
;
1552 existing_device
->active_path_index
= new_device
->active_path_index
;
1553 existing_device
->path_map
= new_device
->path_map
;
1554 existing_device
->bay
= new_device
->bay
;
1555 memcpy(existing_device
->box
, new_device
->box
,
1556 sizeof(existing_device
->box
));
1557 memcpy(existing_device
->phys_connector
, new_device
->phys_connector
,
1558 sizeof(existing_device
->phys_connector
));
1559 existing_device
->offload_to_mirror
= 0;
1560 kfree(existing_device
->raid_map
);
1561 existing_device
->raid_map
= new_device
->raid_map
;
1562 existing_device
->raid_bypass_configured
=
1563 new_device
->raid_bypass_configured
;
1564 existing_device
->raid_bypass_enabled
=
1565 new_device
->raid_bypass_enabled
;
1567 /* To prevent this from being freed later. */
1568 new_device
->raid_map
= NULL
;
1571 static inline void pqi_free_device(struct pqi_scsi_dev
*device
)
1574 kfree(device
->raid_map
);
1580 * Called when exposing a new device to the OS fails in order to re-adjust
1581 * our internal SCSI device list to match the SCSI ML's view.
1584 static inline void pqi_fixup_botched_add(struct pqi_ctrl_info
*ctrl_info
,
1585 struct pqi_scsi_dev
*device
)
1587 unsigned long flags
;
1589 spin_lock_irqsave(&ctrl_info
->scsi_device_list_lock
, flags
);
1590 list_del(&device
->scsi_device_list_entry
);
1591 spin_unlock_irqrestore(&ctrl_info
->scsi_device_list_lock
, flags
);
1593 /* Allow the device structure to be freed later. */
1594 device
->keep_device
= false;
1597 static void pqi_update_device_list(struct pqi_ctrl_info
*ctrl_info
,
1598 struct pqi_scsi_dev
*new_device_list
[], unsigned int num_new_devices
)
1602 unsigned long flags
;
1603 enum pqi_find_result find_result
;
1604 struct pqi_scsi_dev
*device
;
1605 struct pqi_scsi_dev
*next
;
1606 struct pqi_scsi_dev
*matching_device
;
1607 LIST_HEAD(add_list
);
1608 LIST_HEAD(delete_list
);
1611 * The idea here is to do as little work as possible while holding the
1612 * spinlock. That's why we go to great pains to defer anything other
1613 * than updating the internal device list until after we release the
1617 spin_lock_irqsave(&ctrl_info
->scsi_device_list_lock
, flags
);
1619 /* Assume that all devices in the existing list have gone away. */
1620 list_for_each_entry(device
, &ctrl_info
->scsi_device_list
,
1621 scsi_device_list_entry
)
1622 device
->device_gone
= true;
1624 for (i
= 0; i
< num_new_devices
; i
++) {
1625 device
= new_device_list
[i
];
1627 find_result
= pqi_scsi_find_entry(ctrl_info
, device
,
1630 switch (find_result
) {
1633 * The newly found device is already in the existing
1636 device
->new_device
= false;
1637 matching_device
->device_gone
= false;
1638 pqi_scsi_update_device(matching_device
, device
);
1640 case DEVICE_NOT_FOUND
:
1642 * The newly found device is NOT in the existing device
1645 device
->new_device
= true;
1647 case DEVICE_CHANGED
:
1649 * The original device has gone away and we need to add
1652 device
->new_device
= true;
1657 /* Process all devices that have gone away. */
1658 list_for_each_entry_safe(device
, next
, &ctrl_info
->scsi_device_list
,
1659 scsi_device_list_entry
) {
1660 if (device
->device_gone
) {
1661 list_del(&device
->scsi_device_list_entry
);
1662 list_add_tail(&device
->delete_list_entry
, &delete_list
);
1666 /* Process all new devices. */
1667 for (i
= 0; i
< num_new_devices
; i
++) {
1668 device
= new_device_list
[i
];
1669 if (!device
->new_device
)
1671 if (device
->volume_offline
)
1673 list_add_tail(&device
->scsi_device_list_entry
,
1674 &ctrl_info
->scsi_device_list
);
1675 list_add_tail(&device
->add_list_entry
, &add_list
);
1676 /* To prevent this device structure from being freed later. */
1677 device
->keep_device
= true;
1680 spin_unlock_irqrestore(&ctrl_info
->scsi_device_list_lock
, flags
);
1682 /* Remove all devices that have gone away. */
1683 list_for_each_entry_safe(device
, next
, &delete_list
,
1684 delete_list_entry
) {
1685 if (device
->volume_offline
) {
1686 pqi_dev_info(ctrl_info
, "offline", device
);
1687 pqi_show_volume_status(ctrl_info
, device
);
1689 pqi_dev_info(ctrl_info
, "removed", device
);
1692 pqi_remove_device(ctrl_info
, device
);
1693 list_del(&device
->delete_list_entry
);
1694 pqi_free_device(device
);
1698 * Notify the SCSI ML if the queue depth of any existing device has
1701 list_for_each_entry(device
, &ctrl_info
->scsi_device_list
,
1702 scsi_device_list_entry
) {
1703 if (device
->sdev
&& device
->queue_depth
!=
1704 device
->advertised_queue_depth
) {
1705 device
->advertised_queue_depth
= device
->queue_depth
;
1706 scsi_change_queue_depth(device
->sdev
,
1707 device
->advertised_queue_depth
);
1711 /* Expose any new devices. */
1712 list_for_each_entry_safe(device
, next
, &add_list
, add_list_entry
) {
1713 if (!device
->sdev
) {
1714 pqi_dev_info(ctrl_info
, "added", device
);
1715 rc
= pqi_add_device(ctrl_info
, device
);
1717 dev_warn(&ctrl_info
->pci_dev
->dev
,
1718 "scsi %d:%d:%d:%d addition failed, device not added\n",
1719 ctrl_info
->scsi_host
->host_no
,
1720 device
->bus
, device
->target
,
1722 pqi_fixup_botched_add(ctrl_info
, device
);
1728 static bool pqi_is_supported_device(struct pqi_scsi_dev
*device
)
1730 bool is_supported
= false;
1732 switch (device
->devtype
) {
1736 case TYPE_MEDIUM_CHANGER
:
1737 case TYPE_ENCLOSURE
:
1738 is_supported
= true;
1742 * Only support the HBA controller itself as a RAID
1743 * controller. If it's a RAID controller other than
1744 * the HBA itself (an external RAID controller, for
1745 * example), we don't support it.
1747 if (pqi_is_hba_lunid(device
->scsi3addr
))
1748 is_supported
= true;
1752 return is_supported
;
1755 static inline bool pqi_skip_device(u8
*scsi3addr
)
1757 /* Ignore all masked devices. */
1758 if (MASKED_DEVICE(scsi3addr
))
1764 static int pqi_update_scsi_devices(struct pqi_ctrl_info
*ctrl_info
)
1768 LIST_HEAD(new_device_list_head
);
1769 struct report_phys_lun_extended
*physdev_list
= NULL
;
1770 struct report_log_lun_extended
*logdev_list
= NULL
;
1771 struct report_phys_lun_extended_entry
*phys_lun_ext_entry
;
1772 struct report_log_lun_extended_entry
*log_lun_ext_entry
;
1773 struct bmic_identify_physical_device
*id_phys
= NULL
;
1776 struct pqi_scsi_dev
**new_device_list
= NULL
;
1777 struct pqi_scsi_dev
*device
;
1778 struct pqi_scsi_dev
*next
;
1779 unsigned int num_new_devices
;
1780 unsigned int num_valid_devices
;
1781 bool is_physical_device
;
1783 static char *out_of_memory_msg
=
1784 "failed to allocate memory, device discovery stopped";
1786 rc
= pqi_get_device_lists(ctrl_info
, &physdev_list
, &logdev_list
);
1792 get_unaligned_be32(&physdev_list
->header
.list_length
)
1793 / sizeof(physdev_list
->lun_entries
[0]);
1799 get_unaligned_be32(&logdev_list
->header
.list_length
)
1800 / sizeof(logdev_list
->lun_entries
[0]);
1804 if (num_physicals
) {
1806 * We need this buffer for calls to pqi_get_physical_disk_info()
1807 * below. We allocate it here instead of inside
1808 * pqi_get_physical_disk_info() because it's a fairly large
1811 id_phys
= kmalloc(sizeof(*id_phys
), GFP_KERNEL
);
1813 dev_warn(&ctrl_info
->pci_dev
->dev
, "%s\n",
1820 num_new_devices
= num_physicals
+ num_logicals
;
1822 new_device_list
= kmalloc(sizeof(*new_device_list
) *
1823 num_new_devices
, GFP_KERNEL
);
1824 if (!new_device_list
) {
1825 dev_warn(&ctrl_info
->pci_dev
->dev
, "%s\n", out_of_memory_msg
);
1830 for (i
= 0; i
< num_new_devices
; i
++) {
1831 device
= kzalloc(sizeof(*device
), GFP_KERNEL
);
1833 dev_warn(&ctrl_info
->pci_dev
->dev
, "%s\n",
1838 list_add_tail(&device
->new_device_list_entry
,
1839 &new_device_list_head
);
1843 num_valid_devices
= 0;
1845 for (i
= 0; i
< num_new_devices
; i
++) {
1847 if (i
< num_physicals
) {
1848 is_physical_device
= true;
1849 phys_lun_ext_entry
= &physdev_list
->lun_entries
[i
];
1850 log_lun_ext_entry
= NULL
;
1851 scsi3addr
= phys_lun_ext_entry
->lunid
;
1853 is_physical_device
= false;
1854 phys_lun_ext_entry
= NULL
;
1856 &logdev_list
->lun_entries
[i
- num_physicals
];
1857 scsi3addr
= log_lun_ext_entry
->lunid
;
1860 if (is_physical_device
&& pqi_skip_device(scsi3addr
))
1864 device
= list_next_entry(device
, new_device_list_entry
);
1866 device
= list_first_entry(&new_device_list_head
,
1867 struct pqi_scsi_dev
, new_device_list_entry
);
1869 memcpy(device
->scsi3addr
, scsi3addr
, sizeof(device
->scsi3addr
));
1870 device
->is_physical_device
= is_physical_device
;
1871 if (!is_physical_device
)
1872 device
->is_external_raid_device
=
1873 pqi_is_external_raid_addr(scsi3addr
);
1875 /* Gather information about the device. */
1876 rc
= pqi_get_device_info(ctrl_info
, device
);
1877 if (rc
== -ENOMEM
) {
1878 dev_warn(&ctrl_info
->pci_dev
->dev
, "%s\n",
1883 if (device
->is_physical_device
)
1884 dev_warn(&ctrl_info
->pci_dev
->dev
,
1885 "obtaining device info failed, skipping physical device %016llx\n",
1887 &phys_lun_ext_entry
->wwid
));
1889 dev_warn(&ctrl_info
->pci_dev
->dev
,
1890 "obtaining device info failed, skipping logical device %08x%08x\n",
1891 *((u32
*)&device
->scsi3addr
),
1892 *((u32
*)&device
->scsi3addr
[4]));
1897 if (!pqi_is_supported_device(device
))
1900 pqi_assign_bus_target_lun(device
);
1902 if (device
->is_physical_device
) {
1903 device
->wwid
= phys_lun_ext_entry
->wwid
;
1904 if ((phys_lun_ext_entry
->device_flags
&
1905 REPORT_PHYS_LUN_DEV_FLAG_AIO_ENABLED
) &&
1906 phys_lun_ext_entry
->aio_handle
)
1907 device
->aio_enabled
= true;
1909 memcpy(device
->volume_id
, log_lun_ext_entry
->volume_id
,
1910 sizeof(device
->volume_id
));
1913 switch (device
->devtype
) {
1916 case TYPE_ENCLOSURE
:
1917 if (device
->is_physical_device
) {
1918 device
->sas_address
=
1919 get_unaligned_be64(&device
->wwid
);
1920 if (device
->devtype
== TYPE_DISK
||
1921 device
->devtype
== TYPE_ZBC
) {
1922 device
->aio_handle
=
1923 phys_lun_ext_entry
->aio_handle
;
1924 pqi_get_physical_disk_info(ctrl_info
,
1931 new_device_list
[num_valid_devices
++] = device
;
1934 pqi_update_device_list(ctrl_info
, new_device_list
, num_valid_devices
);
1937 list_for_each_entry_safe(device
, next
, &new_device_list_head
,
1938 new_device_list_entry
) {
1939 if (device
->keep_device
)
1941 list_del(&device
->new_device_list_entry
);
1942 pqi_free_device(device
);
1945 kfree(new_device_list
);
1946 kfree(physdev_list
);
1953 static void pqi_remove_all_scsi_devices(struct pqi_ctrl_info
*ctrl_info
)
1955 unsigned long flags
;
1956 struct pqi_scsi_dev
*device
;
1959 spin_lock_irqsave(&ctrl_info
->scsi_device_list_lock
, flags
);
1961 device
= list_first_entry_or_null(&ctrl_info
->scsi_device_list
,
1962 struct pqi_scsi_dev
, scsi_device_list_entry
);
1964 list_del(&device
->scsi_device_list_entry
);
1966 spin_unlock_irqrestore(&ctrl_info
->scsi_device_list_lock
,
1973 pqi_remove_device(ctrl_info
, device
);
1974 pqi_free_device(device
);
1978 static int pqi_scan_scsi_devices(struct pqi_ctrl_info
*ctrl_info
)
1982 if (pqi_ctrl_offline(ctrl_info
))
1985 mutex_lock(&ctrl_info
->scan_mutex
);
1987 rc
= pqi_update_scsi_devices(ctrl_info
);
1989 pqi_schedule_rescan_worker_delayed(ctrl_info
);
1991 mutex_unlock(&ctrl_info
->scan_mutex
);
1996 static void pqi_scan_start(struct Scsi_Host
*shost
)
1998 pqi_scan_scsi_devices(shost_to_hba(shost
));
2001 /* Returns TRUE if scan is finished. */
2003 static int pqi_scan_finished(struct Scsi_Host
*shost
,
2004 unsigned long elapsed_time
)
2006 struct pqi_ctrl_info
*ctrl_info
;
2008 ctrl_info
= shost_priv(shost
);
2010 return !mutex_is_locked(&ctrl_info
->scan_mutex
);
2013 static void pqi_wait_until_scan_finished(struct pqi_ctrl_info
*ctrl_info
)
2015 mutex_lock(&ctrl_info
->scan_mutex
);
2016 mutex_unlock(&ctrl_info
->scan_mutex
);
2019 static void pqi_wait_until_lun_reset_finished(struct pqi_ctrl_info
*ctrl_info
)
2021 mutex_lock(&ctrl_info
->lun_reset_mutex
);
2022 mutex_unlock(&ctrl_info
->lun_reset_mutex
);
2025 static inline void pqi_set_encryption_info(
2026 struct pqi_encryption_info
*encryption_info
, struct raid_map
*raid_map
,
2029 u32 volume_blk_size
;
2032 * Set the encryption tweak values based on logical block address.
2033 * If the block size is 512, the tweak value is equal to the LBA.
2034 * For other block sizes, tweak value is (LBA * block size) / 512.
2036 volume_blk_size
= get_unaligned_le32(&raid_map
->volume_blk_size
);
2037 if (volume_blk_size
!= 512)
2038 first_block
= (first_block
* volume_blk_size
) / 512;
2040 encryption_info
->data_encryption_key_index
=
2041 get_unaligned_le16(&raid_map
->data_encryption_key_index
);
2042 encryption_info
->encrypt_tweak_lower
= lower_32_bits(first_block
);
2043 encryption_info
->encrypt_tweak_upper
= upper_32_bits(first_block
);
2047 * Attempt to perform RAID bypass mapping for a logical volume I/O.
2050 #define PQI_RAID_BYPASS_INELIGIBLE 1
2052 static int pqi_raid_bypass_submit_scsi_cmd(struct pqi_ctrl_info
*ctrl_info
,
2053 struct pqi_scsi_dev
*device
, struct scsi_cmnd
*scmd
,
2054 struct pqi_queue_group
*queue_group
)
2056 struct raid_map
*raid_map
;
2057 bool is_write
= false;
2065 u32 first_row_offset
;
2066 u32 last_row_offset
;
2071 u32 r5or6_blocks_per_row
;
2072 u64 r5or6_first_row
;
2074 u32 r5or6_first_row_offset
;
2075 u32 r5or6_last_row_offset
;
2076 u32 r5or6_first_column
;
2077 u32 r5or6_last_column
;
2078 u16 data_disks_per_row
;
2079 u32 total_disks_per_row
;
2080 u16 layout_map_count
;
2092 int offload_to_mirror
;
2093 struct pqi_encryption_info
*encryption_info_ptr
;
2094 struct pqi_encryption_info encryption_info
;
2095 #if BITS_PER_LONG == 32
2099 /* Check for valid opcode, get LBA and block count. */
2100 switch (scmd
->cmnd
[0]) {
2105 first_block
= (u64
)(((scmd
->cmnd
[1] & 0x1f) << 16) |
2106 (scmd
->cmnd
[2] << 8) | scmd
->cmnd
[3]);
2107 block_cnt
= (u32
)scmd
->cmnd
[4];
2115 first_block
= (u64
)get_unaligned_be32(&scmd
->cmnd
[2]);
2116 block_cnt
= (u32
)get_unaligned_be16(&scmd
->cmnd
[7]);
2122 first_block
= (u64
)get_unaligned_be32(&scmd
->cmnd
[2]);
2123 block_cnt
= get_unaligned_be32(&scmd
->cmnd
[6]);
2129 first_block
= get_unaligned_be64(&scmd
->cmnd
[2]);
2130 block_cnt
= get_unaligned_be32(&scmd
->cmnd
[10]);
2133 /* Process via normal I/O path. */
2134 return PQI_RAID_BYPASS_INELIGIBLE
;
2137 /* Check for write to non-RAID-0. */
2138 if (is_write
&& device
->raid_level
!= SA_RAID_0
)
2139 return PQI_RAID_BYPASS_INELIGIBLE
;
2141 if (unlikely(block_cnt
== 0))
2142 return PQI_RAID_BYPASS_INELIGIBLE
;
2144 last_block
= first_block
+ block_cnt
- 1;
2145 raid_map
= device
->raid_map
;
2147 /* Check for invalid block or wraparound. */
2148 if (last_block
>= get_unaligned_le64(&raid_map
->volume_blk_cnt
) ||
2149 last_block
< first_block
)
2150 return PQI_RAID_BYPASS_INELIGIBLE
;
2152 data_disks_per_row
= get_unaligned_le16(&raid_map
->data_disks_per_row
);
2153 strip_size
= get_unaligned_le16(&raid_map
->strip_size
);
2154 layout_map_count
= get_unaligned_le16(&raid_map
->layout_map_count
);
2156 /* Calculate stripe information for the request. */
2157 blocks_per_row
= data_disks_per_row
* strip_size
;
2158 #if BITS_PER_LONG == 32
2159 tmpdiv
= first_block
;
2160 do_div(tmpdiv
, blocks_per_row
);
2162 tmpdiv
= last_block
;
2163 do_div(tmpdiv
, blocks_per_row
);
2165 first_row_offset
= (u32
)(first_block
- (first_row
* blocks_per_row
));
2166 last_row_offset
= (u32
)(last_block
- (last_row
* blocks_per_row
));
2167 tmpdiv
= first_row_offset
;
2168 do_div(tmpdiv
, strip_size
);
2169 first_column
= tmpdiv
;
2170 tmpdiv
= last_row_offset
;
2171 do_div(tmpdiv
, strip_size
);
2172 last_column
= tmpdiv
;
2174 first_row
= first_block
/ blocks_per_row
;
2175 last_row
= last_block
/ blocks_per_row
;
2176 first_row_offset
= (u32
)(first_block
- (first_row
* blocks_per_row
));
2177 last_row_offset
= (u32
)(last_block
- (last_row
* blocks_per_row
));
2178 first_column
= first_row_offset
/ strip_size
;
2179 last_column
= last_row_offset
/ strip_size
;
2182 /* If this isn't a single row/column then give to the controller. */
2183 if (first_row
!= last_row
|| first_column
!= last_column
)
2184 return PQI_RAID_BYPASS_INELIGIBLE
;
2186 /* Proceeding with driver mapping. */
2187 total_disks_per_row
= data_disks_per_row
+
2188 get_unaligned_le16(&raid_map
->metadata_disks_per_row
);
2189 map_row
= ((u32
)(first_row
>> raid_map
->parity_rotation_shift
)) %
2190 get_unaligned_le16(&raid_map
->row_cnt
);
2191 map_index
= (map_row
* total_disks_per_row
) + first_column
;
2194 if (device
->raid_level
== SA_RAID_1
) {
2195 if (device
->offload_to_mirror
)
2196 map_index
+= data_disks_per_row
;
2197 device
->offload_to_mirror
= !device
->offload_to_mirror
;
2198 } else if (device
->raid_level
== SA_RAID_ADM
) {
2201 * Handles N-way mirrors (R1-ADM) and R10 with # of drives
2204 offload_to_mirror
= device
->offload_to_mirror
;
2205 if (offload_to_mirror
== 0) {
2206 /* use physical disk in the first mirrored group. */
2207 map_index
%= data_disks_per_row
;
2211 * Determine mirror group that map_index
2214 current_group
= map_index
/ data_disks_per_row
;
2216 if (offload_to_mirror
!= current_group
) {
2218 layout_map_count
- 1) {
2220 * Select raid index from
2223 map_index
+= data_disks_per_row
;
2227 * Select raid index from first
2230 map_index
%= data_disks_per_row
;
2234 } while (offload_to_mirror
!= current_group
);
2237 /* Set mirror group to use next time. */
2239 (offload_to_mirror
>= layout_map_count
- 1) ?
2240 0 : offload_to_mirror
+ 1;
2241 WARN_ON(offload_to_mirror
>= layout_map_count
);
2242 device
->offload_to_mirror
= offload_to_mirror
;
2244 * Avoid direct use of device->offload_to_mirror within this
2245 * function since multiple threads might simultaneously
2246 * increment it beyond the range of device->layout_map_count -1.
2248 } else if ((device
->raid_level
== SA_RAID_5
||
2249 device
->raid_level
== SA_RAID_6
) && layout_map_count
> 1) {
2251 /* Verify first and last block are in same RAID group */
2252 r5or6_blocks_per_row
= strip_size
* data_disks_per_row
;
2253 stripesize
= r5or6_blocks_per_row
* layout_map_count
;
2254 #if BITS_PER_LONG == 32
2255 tmpdiv
= first_block
;
2256 first_group
= do_div(tmpdiv
, stripesize
);
2257 tmpdiv
= first_group
;
2258 do_div(tmpdiv
, r5or6_blocks_per_row
);
2259 first_group
= tmpdiv
;
2260 tmpdiv
= last_block
;
2261 last_group
= do_div(tmpdiv
, stripesize
);
2262 tmpdiv
= last_group
;
2263 do_div(tmpdiv
, r5or6_blocks_per_row
);
2264 last_group
= tmpdiv
;
2266 first_group
= (first_block
% stripesize
) / r5or6_blocks_per_row
;
2267 last_group
= (last_block
% stripesize
) / r5or6_blocks_per_row
;
2269 if (first_group
!= last_group
)
2270 return PQI_RAID_BYPASS_INELIGIBLE
;
2272 /* Verify request is in a single row of RAID 5/6 */
2273 #if BITS_PER_LONG == 32
2274 tmpdiv
= first_block
;
2275 do_div(tmpdiv
, stripesize
);
2276 first_row
= r5or6_first_row
= r0_first_row
= tmpdiv
;
2277 tmpdiv
= last_block
;
2278 do_div(tmpdiv
, stripesize
);
2279 r5or6_last_row
= r0_last_row
= tmpdiv
;
2281 first_row
= r5or6_first_row
= r0_first_row
=
2282 first_block
/ stripesize
;
2283 r5or6_last_row
= r0_last_row
= last_block
/ stripesize
;
2285 if (r5or6_first_row
!= r5or6_last_row
)
2286 return PQI_RAID_BYPASS_INELIGIBLE
;
2288 /* Verify request is in a single column */
2289 #if BITS_PER_LONG == 32
2290 tmpdiv
= first_block
;
2291 first_row_offset
= do_div(tmpdiv
, stripesize
);
2292 tmpdiv
= first_row_offset
;
2293 first_row_offset
= (u32
)do_div(tmpdiv
, r5or6_blocks_per_row
);
2294 r5or6_first_row_offset
= first_row_offset
;
2295 tmpdiv
= last_block
;
2296 r5or6_last_row_offset
= do_div(tmpdiv
, stripesize
);
2297 tmpdiv
= r5or6_last_row_offset
;
2298 r5or6_last_row_offset
= do_div(tmpdiv
, r5or6_blocks_per_row
);
2299 tmpdiv
= r5or6_first_row_offset
;
2300 do_div(tmpdiv
, strip_size
);
2301 first_column
= r5or6_first_column
= tmpdiv
;
2302 tmpdiv
= r5or6_last_row_offset
;
2303 do_div(tmpdiv
, strip_size
);
2304 r5or6_last_column
= tmpdiv
;
2306 first_row_offset
= r5or6_first_row_offset
=
2307 (u32
)((first_block
% stripesize
) %
2308 r5or6_blocks_per_row
);
2310 r5or6_last_row_offset
=
2311 (u32
)((last_block
% stripesize
) %
2312 r5or6_blocks_per_row
);
2314 first_column
= r5or6_first_row_offset
/ strip_size
;
2315 r5or6_first_column
= first_column
;
2316 r5or6_last_column
= r5or6_last_row_offset
/ strip_size
;
2318 if (r5or6_first_column
!= r5or6_last_column
)
2319 return PQI_RAID_BYPASS_INELIGIBLE
;
2321 /* Request is eligible */
2323 ((u32
)(first_row
>> raid_map
->parity_rotation_shift
)) %
2324 get_unaligned_le16(&raid_map
->row_cnt
);
2326 map_index
= (first_group
*
2327 (get_unaligned_le16(&raid_map
->row_cnt
) *
2328 total_disks_per_row
)) +
2329 (map_row
* total_disks_per_row
) + first_column
;
2332 if (unlikely(map_index
>= RAID_MAP_MAX_ENTRIES
))
2333 return PQI_RAID_BYPASS_INELIGIBLE
;
2335 aio_handle
= raid_map
->disk_data
[map_index
].aio_handle
;
2336 disk_block
= get_unaligned_le64(&raid_map
->disk_starting_blk
) +
2337 first_row
* strip_size
+
2338 (first_row_offset
- first_column
* strip_size
);
2339 disk_block_cnt
= block_cnt
;
2341 /* Handle differing logical/physical block sizes. */
2342 if (raid_map
->phys_blk_shift
) {
2343 disk_block
<<= raid_map
->phys_blk_shift
;
2344 disk_block_cnt
<<= raid_map
->phys_blk_shift
;
2347 if (unlikely(disk_block_cnt
> 0xffff))
2348 return PQI_RAID_BYPASS_INELIGIBLE
;
2350 /* Build the new CDB for the physical disk I/O. */
2351 if (disk_block
> 0xffffffff) {
2352 cdb
[0] = is_write
? WRITE_16
: READ_16
;
2354 put_unaligned_be64(disk_block
, &cdb
[2]);
2355 put_unaligned_be32(disk_block_cnt
, &cdb
[10]);
2360 cdb
[0] = is_write
? WRITE_10
: READ_10
;
2362 put_unaligned_be32((u32
)disk_block
, &cdb
[2]);
2364 put_unaligned_be16((u16
)disk_block_cnt
, &cdb
[7]);
2369 if (get_unaligned_le16(&raid_map
->flags
) &
2370 RAID_MAP_ENCRYPTION_ENABLED
) {
2371 pqi_set_encryption_info(&encryption_info
, raid_map
,
2373 encryption_info_ptr
= &encryption_info
;
2375 encryption_info_ptr
= NULL
;
2378 return pqi_aio_submit_io(ctrl_info
, scmd
, aio_handle
,
2379 cdb
, cdb_length
, queue_group
, encryption_info_ptr
, true);
2382 #define PQI_STATUS_IDLE 0x0
2384 #define PQI_CREATE_ADMIN_QUEUE_PAIR 1
2385 #define PQI_DELETE_ADMIN_QUEUE_PAIR 2
2387 #define PQI_DEVICE_STATE_POWER_ON_AND_RESET 0x0
2388 #define PQI_DEVICE_STATE_STATUS_AVAILABLE 0x1
2389 #define PQI_DEVICE_STATE_ALL_REGISTERS_READY 0x2
2390 #define PQI_DEVICE_STATE_ADMIN_QUEUE_PAIR_READY 0x3
2391 #define PQI_DEVICE_STATE_ERROR 0x4
2393 #define PQI_MODE_READY_TIMEOUT_SECS 30
2394 #define PQI_MODE_READY_POLL_INTERVAL_MSECS 1
2396 static int pqi_wait_for_pqi_mode_ready(struct pqi_ctrl_info
*ctrl_info
)
2398 struct pqi_device_registers __iomem
*pqi_registers
;
2399 unsigned long timeout
;
2403 pqi_registers
= ctrl_info
->pqi_registers
;
2404 timeout
= (PQI_MODE_READY_TIMEOUT_SECS
* HZ
) + jiffies
;
2407 signature
= readq(&pqi_registers
->signature
);
2408 if (memcmp(&signature
, PQI_DEVICE_SIGNATURE
,
2409 sizeof(signature
)) == 0)
2411 if (time_after(jiffies
, timeout
)) {
2412 dev_err(&ctrl_info
->pci_dev
->dev
,
2413 "timed out waiting for PQI signature\n");
2416 msleep(PQI_MODE_READY_POLL_INTERVAL_MSECS
);
2420 status
= readb(&pqi_registers
->function_and_status_code
);
2421 if (status
== PQI_STATUS_IDLE
)
2423 if (time_after(jiffies
, timeout
)) {
2424 dev_err(&ctrl_info
->pci_dev
->dev
,
2425 "timed out waiting for PQI IDLE\n");
2428 msleep(PQI_MODE_READY_POLL_INTERVAL_MSECS
);
2432 if (readl(&pqi_registers
->device_status
) ==
2433 PQI_DEVICE_STATE_ALL_REGISTERS_READY
)
2435 if (time_after(jiffies
, timeout
)) {
2436 dev_err(&ctrl_info
->pci_dev
->dev
,
2437 "timed out waiting for PQI all registers ready\n");
2440 msleep(PQI_MODE_READY_POLL_INTERVAL_MSECS
);
2446 static inline void pqi_aio_path_disabled(struct pqi_io_request
*io_request
)
2448 struct pqi_scsi_dev
*device
;
2450 device
= io_request
->scmd
->device
->hostdata
;
2451 device
->raid_bypass_enabled
= false;
2452 device
->aio_enabled
= false;
2455 static inline void pqi_take_device_offline(struct scsi_device
*sdev
, char *path
)
2457 struct pqi_ctrl_info
*ctrl_info
;
2458 struct pqi_scsi_dev
*device
;
2460 device
= sdev
->hostdata
;
2461 if (device
->device_offline
)
2464 device
->device_offline
= true;
2465 scsi_device_set_state(sdev
, SDEV_OFFLINE
);
2466 ctrl_info
= shost_to_hba(sdev
->host
);
2467 pqi_schedule_rescan_worker(ctrl_info
);
2468 dev_err(&ctrl_info
->pci_dev
->dev
, "offlined %s scsi %d:%d:%d:%d\n",
2469 path
, ctrl_info
->scsi_host
->host_no
, device
->bus
,
2470 device
->target
, device
->lun
);
2473 static void pqi_process_raid_io_error(struct pqi_io_request
*io_request
)
2477 struct scsi_cmnd
*scmd
;
2478 struct pqi_raid_error_info
*error_info
;
2479 size_t sense_data_length
;
2482 struct scsi_sense_hdr sshdr
;
2484 scmd
= io_request
->scmd
;
2488 error_info
= io_request
->error_info
;
2489 scsi_status
= error_info
->status
;
2492 switch (error_info
->data_out_result
) {
2493 case PQI_DATA_IN_OUT_GOOD
:
2495 case PQI_DATA_IN_OUT_UNDERFLOW
:
2497 get_unaligned_le32(&error_info
->data_out_transferred
);
2498 residual_count
= scsi_bufflen(scmd
) - xfer_count
;
2499 scsi_set_resid(scmd
, residual_count
);
2500 if (xfer_count
< scmd
->underflow
)
2501 host_byte
= DID_SOFT_ERROR
;
2503 case PQI_DATA_IN_OUT_UNSOLICITED_ABORT
:
2504 case PQI_DATA_IN_OUT_ABORTED
:
2505 host_byte
= DID_ABORT
;
2507 case PQI_DATA_IN_OUT_TIMEOUT
:
2508 host_byte
= DID_TIME_OUT
;
2510 case PQI_DATA_IN_OUT_BUFFER_OVERFLOW
:
2511 case PQI_DATA_IN_OUT_PROTOCOL_ERROR
:
2512 case PQI_DATA_IN_OUT_BUFFER_ERROR
:
2513 case PQI_DATA_IN_OUT_BUFFER_OVERFLOW_DESCRIPTOR_AREA
:
2514 case PQI_DATA_IN_OUT_BUFFER_OVERFLOW_BRIDGE
:
2515 case PQI_DATA_IN_OUT_ERROR
:
2516 case PQI_DATA_IN_OUT_HARDWARE_ERROR
:
2517 case PQI_DATA_IN_OUT_PCIE_FABRIC_ERROR
:
2518 case PQI_DATA_IN_OUT_PCIE_COMPLETION_TIMEOUT
:
2519 case PQI_DATA_IN_OUT_PCIE_COMPLETER_ABORT_RECEIVED
:
2520 case PQI_DATA_IN_OUT_PCIE_UNSUPPORTED_REQUEST_RECEIVED
:
2521 case PQI_DATA_IN_OUT_PCIE_ECRC_CHECK_FAILED
:
2522 case PQI_DATA_IN_OUT_PCIE_UNSUPPORTED_REQUEST
:
2523 case PQI_DATA_IN_OUT_PCIE_ACS_VIOLATION
:
2524 case PQI_DATA_IN_OUT_PCIE_TLP_PREFIX_BLOCKED
:
2525 case PQI_DATA_IN_OUT_PCIE_POISONED_MEMORY_READ
:
2527 host_byte
= DID_ERROR
;
2531 sense_data_length
= get_unaligned_le16(&error_info
->sense_data_length
);
2532 if (sense_data_length
== 0)
2534 get_unaligned_le16(&error_info
->response_data_length
);
2535 if (sense_data_length
) {
2536 if (sense_data_length
> sizeof(error_info
->data
))
2537 sense_data_length
= sizeof(error_info
->data
);
2539 if (scsi_status
== SAM_STAT_CHECK_CONDITION
&&
2540 scsi_normalize_sense(error_info
->data
,
2541 sense_data_length
, &sshdr
) &&
2542 sshdr
.sense_key
== HARDWARE_ERROR
&&
2543 sshdr
.asc
== 0x3e &&
2544 sshdr
.ascq
== 0x1) {
2545 pqi_take_device_offline(scmd
->device
, "RAID");
2546 host_byte
= DID_NO_CONNECT
;
2549 if (sense_data_length
> SCSI_SENSE_BUFFERSIZE
)
2550 sense_data_length
= SCSI_SENSE_BUFFERSIZE
;
2551 memcpy(scmd
->sense_buffer
, error_info
->data
,
2555 scmd
->result
= scsi_status
;
2556 set_host_byte(scmd
, host_byte
);
2559 static void pqi_process_aio_io_error(struct pqi_io_request
*io_request
)
2563 struct scsi_cmnd
*scmd
;
2564 struct pqi_aio_error_info
*error_info
;
2565 size_t sense_data_length
;
2568 bool device_offline
;
2570 scmd
= io_request
->scmd
;
2571 error_info
= io_request
->error_info
;
2573 sense_data_length
= 0;
2574 device_offline
= false;
2576 switch (error_info
->service_response
) {
2577 case PQI_AIO_SERV_RESPONSE_COMPLETE
:
2578 scsi_status
= error_info
->status
;
2580 case PQI_AIO_SERV_RESPONSE_FAILURE
:
2581 switch (error_info
->status
) {
2582 case PQI_AIO_STATUS_IO_ABORTED
:
2583 scsi_status
= SAM_STAT_TASK_ABORTED
;
2585 case PQI_AIO_STATUS_UNDERRUN
:
2586 scsi_status
= SAM_STAT_GOOD
;
2587 residual_count
= get_unaligned_le32(
2588 &error_info
->residual_count
);
2589 scsi_set_resid(scmd
, residual_count
);
2590 xfer_count
= scsi_bufflen(scmd
) - residual_count
;
2591 if (xfer_count
< scmd
->underflow
)
2592 host_byte
= DID_SOFT_ERROR
;
2594 case PQI_AIO_STATUS_OVERRUN
:
2595 scsi_status
= SAM_STAT_GOOD
;
2597 case PQI_AIO_STATUS_AIO_PATH_DISABLED
:
2598 pqi_aio_path_disabled(io_request
);
2599 scsi_status
= SAM_STAT_GOOD
;
2600 io_request
->status
= -EAGAIN
;
2602 case PQI_AIO_STATUS_NO_PATH_TO_DEVICE
:
2603 case PQI_AIO_STATUS_INVALID_DEVICE
:
2604 if (!io_request
->raid_bypass
) {
2605 device_offline
= true;
2606 pqi_take_device_offline(scmd
->device
, "AIO");
2607 host_byte
= DID_NO_CONNECT
;
2609 scsi_status
= SAM_STAT_CHECK_CONDITION
;
2611 case PQI_AIO_STATUS_IO_ERROR
:
2613 scsi_status
= SAM_STAT_CHECK_CONDITION
;
2617 case PQI_AIO_SERV_RESPONSE_TMF_COMPLETE
:
2618 case PQI_AIO_SERV_RESPONSE_TMF_SUCCEEDED
:
2619 scsi_status
= SAM_STAT_GOOD
;
2621 case PQI_AIO_SERV_RESPONSE_TMF_REJECTED
:
2622 case PQI_AIO_SERV_RESPONSE_TMF_INCORRECT_LUN
:
2624 scsi_status
= SAM_STAT_CHECK_CONDITION
;
2628 if (error_info
->data_present
) {
2630 get_unaligned_le16(&error_info
->data_length
);
2631 if (sense_data_length
) {
2632 if (sense_data_length
> sizeof(error_info
->data
))
2633 sense_data_length
= sizeof(error_info
->data
);
2634 if (sense_data_length
> SCSI_SENSE_BUFFERSIZE
)
2635 sense_data_length
= SCSI_SENSE_BUFFERSIZE
;
2636 memcpy(scmd
->sense_buffer
, error_info
->data
,
2641 if (device_offline
&& sense_data_length
== 0)
2642 scsi_build_sense_buffer(0, scmd
->sense_buffer
, HARDWARE_ERROR
,
2645 scmd
->result
= scsi_status
;
2646 set_host_byte(scmd
, host_byte
);
2649 static void pqi_process_io_error(unsigned int iu_type
,
2650 struct pqi_io_request
*io_request
)
2653 case PQI_RESPONSE_IU_RAID_PATH_IO_ERROR
:
2654 pqi_process_raid_io_error(io_request
);
2656 case PQI_RESPONSE_IU_AIO_PATH_IO_ERROR
:
2657 pqi_process_aio_io_error(io_request
);
2662 static int pqi_interpret_task_management_response(
2663 struct pqi_task_management_response
*response
)
2667 switch (response
->response_code
) {
2668 case SOP_TMF_COMPLETE
:
2669 case SOP_TMF_FUNCTION_SUCCEEDED
:
2680 static unsigned int pqi_process_io_intr(struct pqi_ctrl_info
*ctrl_info
,
2681 struct pqi_queue_group
*queue_group
)
2683 unsigned int num_responses
;
2686 struct pqi_io_request
*io_request
;
2687 struct pqi_io_response
*response
;
2691 oq_ci
= queue_group
->oq_ci_copy
;
2694 oq_pi
= *queue_group
->oq_pi
;
2699 response
= queue_group
->oq_element_array
+
2700 (oq_ci
* PQI_OPERATIONAL_OQ_ELEMENT_LENGTH
);
2702 request_id
= get_unaligned_le16(&response
->request_id
);
2703 WARN_ON(request_id
>= ctrl_info
->max_io_slots
);
2705 io_request
= &ctrl_info
->io_request_pool
[request_id
];
2706 WARN_ON(atomic_read(&io_request
->refcount
) == 0);
2708 switch (response
->header
.iu_type
) {
2709 case PQI_RESPONSE_IU_RAID_PATH_IO_SUCCESS
:
2710 case PQI_RESPONSE_IU_AIO_PATH_IO_SUCCESS
:
2711 case PQI_RESPONSE_IU_GENERAL_MANAGEMENT
:
2713 case PQI_RESPONSE_IU_TASK_MANAGEMENT
:
2714 io_request
->status
=
2715 pqi_interpret_task_management_response(
2718 case PQI_RESPONSE_IU_AIO_PATH_DISABLED
:
2719 pqi_aio_path_disabled(io_request
);
2720 io_request
->status
= -EAGAIN
;
2722 case PQI_RESPONSE_IU_RAID_PATH_IO_ERROR
:
2723 case PQI_RESPONSE_IU_AIO_PATH_IO_ERROR
:
2724 io_request
->error_info
= ctrl_info
->error_buffer
+
2725 (get_unaligned_le16(&response
->error_index
) *
2726 PQI_ERROR_BUFFER_ELEMENT_LENGTH
);
2727 pqi_process_io_error(response
->header
.iu_type
,
2731 dev_err(&ctrl_info
->pci_dev
->dev
,
2732 "unexpected IU type: 0x%x\n",
2733 response
->header
.iu_type
);
2737 io_request
->io_complete_callback(io_request
,
2738 io_request
->context
);
2741 * Note that the I/O request structure CANNOT BE TOUCHED after
2742 * returning from the I/O completion callback!
2745 oq_ci
= (oq_ci
+ 1) % ctrl_info
->num_elements_per_oq
;
2748 if (num_responses
) {
2749 queue_group
->oq_ci_copy
= oq_ci
;
2750 writel(oq_ci
, queue_group
->oq_ci
);
2753 return num_responses
;
2756 static inline unsigned int pqi_num_elements_free(unsigned int pi
,
2757 unsigned int ci
, unsigned int elements_in_queue
)
2759 unsigned int num_elements_used
;
2762 num_elements_used
= pi
- ci
;
2764 num_elements_used
= elements_in_queue
- ci
+ pi
;
2766 return elements_in_queue
- num_elements_used
- 1;
2769 static void pqi_send_event_ack(struct pqi_ctrl_info
*ctrl_info
,
2770 struct pqi_event_acknowledge_request
*iu
, size_t iu_length
)
2774 unsigned long flags
;
2776 struct pqi_queue_group
*queue_group
;
2778 queue_group
= &ctrl_info
->queue_groups
[PQI_DEFAULT_QUEUE_GROUP
];
2779 put_unaligned_le16(queue_group
->oq_id
, &iu
->header
.response_queue_id
);
2782 spin_lock_irqsave(&queue_group
->submit_lock
[RAID_PATH
], flags
);
2784 iq_pi
= queue_group
->iq_pi_copy
[RAID_PATH
];
2785 iq_ci
= *queue_group
->iq_ci
[RAID_PATH
];
2787 if (pqi_num_elements_free(iq_pi
, iq_ci
,
2788 ctrl_info
->num_elements_per_iq
))
2791 spin_unlock_irqrestore(
2792 &queue_group
->submit_lock
[RAID_PATH
], flags
);
2794 if (pqi_ctrl_offline(ctrl_info
))
2798 next_element
= queue_group
->iq_element_array
[RAID_PATH
] +
2799 (iq_pi
* PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
);
2801 memcpy(next_element
, iu
, iu_length
);
2803 iq_pi
= (iq_pi
+ 1) % ctrl_info
->num_elements_per_iq
;
2804 queue_group
->iq_pi_copy
[RAID_PATH
] = iq_pi
;
2807 * This write notifies the controller that an IU is available to be
2810 writel(iq_pi
, queue_group
->iq_pi
[RAID_PATH
]);
2812 spin_unlock_irqrestore(&queue_group
->submit_lock
[RAID_PATH
], flags
);
2815 static void pqi_acknowledge_event(struct pqi_ctrl_info
*ctrl_info
,
2816 struct pqi_event
*event
)
2818 struct pqi_event_acknowledge_request request
;
2820 memset(&request
, 0, sizeof(request
));
2822 request
.header
.iu_type
= PQI_REQUEST_IU_ACKNOWLEDGE_VENDOR_EVENT
;
2823 put_unaligned_le16(sizeof(request
) - PQI_REQUEST_HEADER_LENGTH
,
2824 &request
.header
.iu_length
);
2825 request
.event_type
= event
->event_type
;
2826 request
.event_id
= event
->event_id
;
2827 request
.additional_event_id
= event
->additional_event_id
;
2829 pqi_send_event_ack(ctrl_info
, &request
, sizeof(request
));
2832 static void pqi_event_worker(struct work_struct
*work
)
2835 struct pqi_ctrl_info
*ctrl_info
;
2836 struct pqi_event
*event
;
2838 ctrl_info
= container_of(work
, struct pqi_ctrl_info
, event_work
);
2840 pqi_ctrl_busy(ctrl_info
);
2841 pqi_wait_if_ctrl_blocked(ctrl_info
, NO_TIMEOUT
);
2842 if (pqi_ctrl_offline(ctrl_info
))
2845 pqi_schedule_rescan_worker_delayed(ctrl_info
);
2847 event
= ctrl_info
->events
;
2848 for (i
= 0; i
< PQI_NUM_SUPPORTED_EVENTS
; i
++) {
2849 if (event
->pending
) {
2850 event
->pending
= false;
2851 pqi_acknowledge_event(ctrl_info
, event
);
2857 pqi_ctrl_unbusy(ctrl_info
);
2860 #define PQI_HEARTBEAT_TIMER_INTERVAL (10 * HZ)
2862 static void pqi_heartbeat_timer_handler(unsigned long data
)
2865 u32 heartbeat_count
;
2866 struct pqi_ctrl_info
*ctrl_info
= (struct pqi_ctrl_info
*)data
;
2868 pqi_check_ctrl_health(ctrl_info
);
2869 if (pqi_ctrl_offline(ctrl_info
))
2872 num_interrupts
= atomic_read(&ctrl_info
->num_interrupts
);
2873 heartbeat_count
= pqi_read_heartbeat_counter(ctrl_info
);
2875 if (num_interrupts
== ctrl_info
->previous_num_interrupts
) {
2876 if (heartbeat_count
== ctrl_info
->previous_heartbeat_count
) {
2877 dev_err(&ctrl_info
->pci_dev
->dev
,
2878 "no heartbeat detected - last heartbeat count: %u\n",
2880 pqi_take_ctrl_offline(ctrl_info
);
2884 ctrl_info
->previous_num_interrupts
= num_interrupts
;
2887 ctrl_info
->previous_heartbeat_count
= heartbeat_count
;
2888 mod_timer(&ctrl_info
->heartbeat_timer
,
2889 jiffies
+ PQI_HEARTBEAT_TIMER_INTERVAL
);
2892 static void pqi_start_heartbeat_timer(struct pqi_ctrl_info
*ctrl_info
)
2894 if (!ctrl_info
->heartbeat_counter
)
2897 ctrl_info
->previous_num_interrupts
=
2898 atomic_read(&ctrl_info
->num_interrupts
);
2899 ctrl_info
->previous_heartbeat_count
=
2900 pqi_read_heartbeat_counter(ctrl_info
);
2902 ctrl_info
->heartbeat_timer
.expires
=
2903 jiffies
+ PQI_HEARTBEAT_TIMER_INTERVAL
;
2904 ctrl_info
->heartbeat_timer
.data
= (unsigned long)ctrl_info
;
2905 ctrl_info
->heartbeat_timer
.function
= pqi_heartbeat_timer_handler
;
2906 add_timer(&ctrl_info
->heartbeat_timer
);
2909 static inline void pqi_stop_heartbeat_timer(struct pqi_ctrl_info
*ctrl_info
)
2911 del_timer_sync(&ctrl_info
->heartbeat_timer
);
2914 static inline int pqi_event_type_to_event_index(unsigned int event_type
)
2918 for (index
= 0; index
< ARRAY_SIZE(pqi_supported_event_types
); index
++)
2919 if (event_type
== pqi_supported_event_types
[index
])
2925 static inline bool pqi_is_supported_event(unsigned int event_type
)
2927 return pqi_event_type_to_event_index(event_type
) != -1;
2930 static unsigned int pqi_process_event_intr(struct pqi_ctrl_info
*ctrl_info
)
2932 unsigned int num_events
;
2935 struct pqi_event_queue
*event_queue
;
2936 struct pqi_event_response
*response
;
2937 struct pqi_event
*event
;
2940 event_queue
= &ctrl_info
->event_queue
;
2942 oq_ci
= event_queue
->oq_ci_copy
;
2945 oq_pi
= *event_queue
->oq_pi
;
2950 response
= event_queue
->oq_element_array
+
2951 (oq_ci
* PQI_EVENT_OQ_ELEMENT_LENGTH
);
2954 pqi_event_type_to_event_index(response
->event_type
);
2956 if (event_index
>= 0) {
2957 if (response
->request_acknowlege
) {
2958 event
= &ctrl_info
->events
[event_index
];
2959 event
->pending
= true;
2960 event
->event_type
= response
->event_type
;
2961 event
->event_id
= response
->event_id
;
2962 event
->additional_event_id
=
2963 response
->additional_event_id
;
2967 oq_ci
= (oq_ci
+ 1) % PQI_NUM_EVENT_QUEUE_ELEMENTS
;
2971 event_queue
->oq_ci_copy
= oq_ci
;
2972 writel(oq_ci
, event_queue
->oq_ci
);
2973 schedule_work(&ctrl_info
->event_work
);
2979 #define PQI_LEGACY_INTX_MASK 0x1
2981 static inline void pqi_configure_legacy_intx(struct pqi_ctrl_info
*ctrl_info
,
2985 struct pqi_device_registers __iomem
*pqi_registers
;
2986 volatile void __iomem
*register_addr
;
2988 pqi_registers
= ctrl_info
->pqi_registers
;
2991 register_addr
= &pqi_registers
->legacy_intx_mask_clear
;
2993 register_addr
= &pqi_registers
->legacy_intx_mask_set
;
2995 intx_mask
= readl(register_addr
);
2996 intx_mask
|= PQI_LEGACY_INTX_MASK
;
2997 writel(intx_mask
, register_addr
);
3000 static void pqi_change_irq_mode(struct pqi_ctrl_info
*ctrl_info
,
3001 enum pqi_irq_mode new_mode
)
3003 switch (ctrl_info
->irq_mode
) {
3009 pqi_configure_legacy_intx(ctrl_info
, true);
3010 sis_disable_msix(ctrl_info
);
3011 sis_enable_intx(ctrl_info
);
3014 sis_disable_msix(ctrl_info
);
3021 pqi_configure_legacy_intx(ctrl_info
, false);
3022 sis_disable_intx(ctrl_info
);
3023 sis_enable_msix(ctrl_info
);
3028 pqi_configure_legacy_intx(ctrl_info
, false);
3029 sis_disable_intx(ctrl_info
);
3036 sis_enable_msix(ctrl_info
);
3039 pqi_configure_legacy_intx(ctrl_info
, true);
3040 sis_enable_intx(ctrl_info
);
3048 ctrl_info
->irq_mode
= new_mode
;
3051 #define PQI_LEGACY_INTX_PENDING 0x1
3053 static inline bool pqi_is_valid_irq(struct pqi_ctrl_info
*ctrl_info
)
3058 switch (ctrl_info
->irq_mode
) {
3064 readl(&ctrl_info
->pqi_registers
->legacy_intx_status
);
3065 if (intx_status
& PQI_LEGACY_INTX_PENDING
)
3079 static irqreturn_t
pqi_irq_handler(int irq
, void *data
)
3081 struct pqi_ctrl_info
*ctrl_info
;
3082 struct pqi_queue_group
*queue_group
;
3083 unsigned int num_responses_handled
;
3086 ctrl_info
= queue_group
->ctrl_info
;
3088 if (!pqi_is_valid_irq(ctrl_info
))
3091 num_responses_handled
= pqi_process_io_intr(ctrl_info
, queue_group
);
3093 if (irq
== ctrl_info
->event_irq
)
3094 num_responses_handled
+= pqi_process_event_intr(ctrl_info
);
3096 if (num_responses_handled
)
3097 atomic_inc(&ctrl_info
->num_interrupts
);
3099 pqi_start_io(ctrl_info
, queue_group
, RAID_PATH
, NULL
);
3100 pqi_start_io(ctrl_info
, queue_group
, AIO_PATH
, NULL
);
3105 static int pqi_request_irqs(struct pqi_ctrl_info
*ctrl_info
)
3107 struct pci_dev
*pci_dev
= ctrl_info
->pci_dev
;
3111 ctrl_info
->event_irq
= pci_irq_vector(pci_dev
, 0);
3113 for (i
= 0; i
< ctrl_info
->num_msix_vectors_enabled
; i
++) {
3114 rc
= request_irq(pci_irq_vector(pci_dev
, i
), pqi_irq_handler
, 0,
3115 DRIVER_NAME_SHORT
, &ctrl_info
->queue_groups
[i
]);
3117 dev_err(&pci_dev
->dev
,
3118 "irq %u init failed with error %d\n",
3119 pci_irq_vector(pci_dev
, i
), rc
);
3122 ctrl_info
->num_msix_vectors_initialized
++;
3128 static void pqi_free_irqs(struct pqi_ctrl_info
*ctrl_info
)
3132 for (i
= 0; i
< ctrl_info
->num_msix_vectors_initialized
; i
++)
3133 free_irq(pci_irq_vector(ctrl_info
->pci_dev
, i
),
3134 &ctrl_info
->queue_groups
[i
]);
3136 ctrl_info
->num_msix_vectors_initialized
= 0;
3139 static int pqi_enable_msix_interrupts(struct pqi_ctrl_info
*ctrl_info
)
3141 int num_vectors_enabled
;
3143 num_vectors_enabled
= pci_alloc_irq_vectors(ctrl_info
->pci_dev
,
3144 PQI_MIN_MSIX_VECTORS
, ctrl_info
->num_queue_groups
,
3145 PCI_IRQ_MSIX
| PCI_IRQ_AFFINITY
);
3146 if (num_vectors_enabled
< 0) {
3147 dev_err(&ctrl_info
->pci_dev
->dev
,
3148 "MSI-X init failed with error %d\n",
3149 num_vectors_enabled
);
3150 return num_vectors_enabled
;
3153 ctrl_info
->num_msix_vectors_enabled
= num_vectors_enabled
;
3154 ctrl_info
->irq_mode
= IRQ_MODE_MSIX
;
3158 static void pqi_disable_msix_interrupts(struct pqi_ctrl_info
*ctrl_info
)
3160 if (ctrl_info
->num_msix_vectors_enabled
) {
3161 pci_free_irq_vectors(ctrl_info
->pci_dev
);
3162 ctrl_info
->num_msix_vectors_enabled
= 0;
3166 static int pqi_alloc_operational_queues(struct pqi_ctrl_info
*ctrl_info
)
3169 size_t alloc_length
;
3170 size_t element_array_length_per_iq
;
3171 size_t element_array_length_per_oq
;
3172 void *element_array
;
3173 void *next_queue_index
;
3174 void *aligned_pointer
;
3175 unsigned int num_inbound_queues
;
3176 unsigned int num_outbound_queues
;
3177 unsigned int num_queue_indexes
;
3178 struct pqi_queue_group
*queue_group
;
3180 element_array_length_per_iq
=
3181 PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
*
3182 ctrl_info
->num_elements_per_iq
;
3183 element_array_length_per_oq
=
3184 PQI_OPERATIONAL_OQ_ELEMENT_LENGTH
*
3185 ctrl_info
->num_elements_per_oq
;
3186 num_inbound_queues
= ctrl_info
->num_queue_groups
* 2;
3187 num_outbound_queues
= ctrl_info
->num_queue_groups
;
3188 num_queue_indexes
= (ctrl_info
->num_queue_groups
* 3) + 1;
3190 aligned_pointer
= NULL
;
3192 for (i
= 0; i
< num_inbound_queues
; i
++) {
3193 aligned_pointer
= PTR_ALIGN(aligned_pointer
,
3194 PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT
);
3195 aligned_pointer
+= element_array_length_per_iq
;
3198 for (i
= 0; i
< num_outbound_queues
; i
++) {
3199 aligned_pointer
= PTR_ALIGN(aligned_pointer
,
3200 PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT
);
3201 aligned_pointer
+= element_array_length_per_oq
;
3204 aligned_pointer
= PTR_ALIGN(aligned_pointer
,
3205 PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT
);
3206 aligned_pointer
+= PQI_NUM_EVENT_QUEUE_ELEMENTS
*
3207 PQI_EVENT_OQ_ELEMENT_LENGTH
;
3209 for (i
= 0; i
< num_queue_indexes
; i
++) {
3210 aligned_pointer
= PTR_ALIGN(aligned_pointer
,
3211 PQI_OPERATIONAL_INDEX_ALIGNMENT
);
3212 aligned_pointer
+= sizeof(pqi_index_t
);
3215 alloc_length
= (size_t)aligned_pointer
+
3216 PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT
;
3218 alloc_length
+= PQI_EXTRA_SGL_MEMORY
;
3220 ctrl_info
->queue_memory_base
=
3221 dma_zalloc_coherent(&ctrl_info
->pci_dev
->dev
,
3223 &ctrl_info
->queue_memory_base_dma_handle
, GFP_KERNEL
);
3225 if (!ctrl_info
->queue_memory_base
)
3228 ctrl_info
->queue_memory_length
= alloc_length
;
3230 element_array
= PTR_ALIGN(ctrl_info
->queue_memory_base
,
3231 PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT
);
3233 for (i
= 0; i
< ctrl_info
->num_queue_groups
; i
++) {
3234 queue_group
= &ctrl_info
->queue_groups
[i
];
3235 queue_group
->iq_element_array
[RAID_PATH
] = element_array
;
3236 queue_group
->iq_element_array_bus_addr
[RAID_PATH
] =
3237 ctrl_info
->queue_memory_base_dma_handle
+
3238 (element_array
- ctrl_info
->queue_memory_base
);
3239 element_array
+= element_array_length_per_iq
;
3240 element_array
= PTR_ALIGN(element_array
,
3241 PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT
);
3242 queue_group
->iq_element_array
[AIO_PATH
] = element_array
;
3243 queue_group
->iq_element_array_bus_addr
[AIO_PATH
] =
3244 ctrl_info
->queue_memory_base_dma_handle
+
3245 (element_array
- ctrl_info
->queue_memory_base
);
3246 element_array
+= element_array_length_per_iq
;
3247 element_array
= PTR_ALIGN(element_array
,
3248 PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT
);
3251 for (i
= 0; i
< ctrl_info
->num_queue_groups
; i
++) {
3252 queue_group
= &ctrl_info
->queue_groups
[i
];
3253 queue_group
->oq_element_array
= element_array
;
3254 queue_group
->oq_element_array_bus_addr
=
3255 ctrl_info
->queue_memory_base_dma_handle
+
3256 (element_array
- ctrl_info
->queue_memory_base
);
3257 element_array
+= element_array_length_per_oq
;
3258 element_array
= PTR_ALIGN(element_array
,
3259 PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT
);
3262 ctrl_info
->event_queue
.oq_element_array
= element_array
;
3263 ctrl_info
->event_queue
.oq_element_array_bus_addr
=
3264 ctrl_info
->queue_memory_base_dma_handle
+
3265 (element_array
- ctrl_info
->queue_memory_base
);
3266 element_array
+= PQI_NUM_EVENT_QUEUE_ELEMENTS
*
3267 PQI_EVENT_OQ_ELEMENT_LENGTH
;
3269 next_queue_index
= PTR_ALIGN(element_array
,
3270 PQI_OPERATIONAL_INDEX_ALIGNMENT
);
3272 for (i
= 0; i
< ctrl_info
->num_queue_groups
; i
++) {
3273 queue_group
= &ctrl_info
->queue_groups
[i
];
3274 queue_group
->iq_ci
[RAID_PATH
] = next_queue_index
;
3275 queue_group
->iq_ci_bus_addr
[RAID_PATH
] =
3276 ctrl_info
->queue_memory_base_dma_handle
+
3277 (next_queue_index
- ctrl_info
->queue_memory_base
);
3278 next_queue_index
+= sizeof(pqi_index_t
);
3279 next_queue_index
= PTR_ALIGN(next_queue_index
,
3280 PQI_OPERATIONAL_INDEX_ALIGNMENT
);
3281 queue_group
->iq_ci
[AIO_PATH
] = next_queue_index
;
3282 queue_group
->iq_ci_bus_addr
[AIO_PATH
] =
3283 ctrl_info
->queue_memory_base_dma_handle
+
3284 (next_queue_index
- ctrl_info
->queue_memory_base
);
3285 next_queue_index
+= sizeof(pqi_index_t
);
3286 next_queue_index
= PTR_ALIGN(next_queue_index
,
3287 PQI_OPERATIONAL_INDEX_ALIGNMENT
);
3288 queue_group
->oq_pi
= next_queue_index
;
3289 queue_group
->oq_pi_bus_addr
=
3290 ctrl_info
->queue_memory_base_dma_handle
+
3291 (next_queue_index
- ctrl_info
->queue_memory_base
);
3292 next_queue_index
+= sizeof(pqi_index_t
);
3293 next_queue_index
= PTR_ALIGN(next_queue_index
,
3294 PQI_OPERATIONAL_INDEX_ALIGNMENT
);
3297 ctrl_info
->event_queue
.oq_pi
= next_queue_index
;
3298 ctrl_info
->event_queue
.oq_pi_bus_addr
=
3299 ctrl_info
->queue_memory_base_dma_handle
+
3300 (next_queue_index
- ctrl_info
->queue_memory_base
);
3305 static void pqi_init_operational_queues(struct pqi_ctrl_info
*ctrl_info
)
3308 u16 next_iq_id
= PQI_MIN_OPERATIONAL_QUEUE_ID
;
3309 u16 next_oq_id
= PQI_MIN_OPERATIONAL_QUEUE_ID
;
3312 * Initialize the backpointers to the controller structure in
3313 * each operational queue group structure.
3315 for (i
= 0; i
< ctrl_info
->num_queue_groups
; i
++)
3316 ctrl_info
->queue_groups
[i
].ctrl_info
= ctrl_info
;
3319 * Assign IDs to all operational queues. Note that the IDs
3320 * assigned to operational IQs are independent of the IDs
3321 * assigned to operational OQs.
3323 ctrl_info
->event_queue
.oq_id
= next_oq_id
++;
3324 for (i
= 0; i
< ctrl_info
->num_queue_groups
; i
++) {
3325 ctrl_info
->queue_groups
[i
].iq_id
[RAID_PATH
] = next_iq_id
++;
3326 ctrl_info
->queue_groups
[i
].iq_id
[AIO_PATH
] = next_iq_id
++;
3327 ctrl_info
->queue_groups
[i
].oq_id
= next_oq_id
++;
3331 * Assign MSI-X table entry indexes to all queues. Note that the
3332 * interrupt for the event queue is shared with the first queue group.
3334 ctrl_info
->event_queue
.int_msg_num
= 0;
3335 for (i
= 0; i
< ctrl_info
->num_queue_groups
; i
++)
3336 ctrl_info
->queue_groups
[i
].int_msg_num
= i
;
3338 for (i
= 0; i
< ctrl_info
->num_queue_groups
; i
++) {
3339 spin_lock_init(&ctrl_info
->queue_groups
[i
].submit_lock
[0]);
3340 spin_lock_init(&ctrl_info
->queue_groups
[i
].submit_lock
[1]);
3341 INIT_LIST_HEAD(&ctrl_info
->queue_groups
[i
].request_list
[0]);
3342 INIT_LIST_HEAD(&ctrl_info
->queue_groups
[i
].request_list
[1]);
3346 static int pqi_alloc_admin_queues(struct pqi_ctrl_info
*ctrl_info
)
3348 size_t alloc_length
;
3349 struct pqi_admin_queues_aligned
*admin_queues_aligned
;
3350 struct pqi_admin_queues
*admin_queues
;
3352 alloc_length
= sizeof(struct pqi_admin_queues_aligned
) +
3353 PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT
;
3355 ctrl_info
->admin_queue_memory_base
=
3356 dma_zalloc_coherent(&ctrl_info
->pci_dev
->dev
,
3358 &ctrl_info
->admin_queue_memory_base_dma_handle
,
3361 if (!ctrl_info
->admin_queue_memory_base
)
3364 ctrl_info
->admin_queue_memory_length
= alloc_length
;
3366 admin_queues
= &ctrl_info
->admin_queues
;
3367 admin_queues_aligned
= PTR_ALIGN(ctrl_info
->admin_queue_memory_base
,
3368 PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT
);
3369 admin_queues
->iq_element_array
=
3370 &admin_queues_aligned
->iq_element_array
;
3371 admin_queues
->oq_element_array
=
3372 &admin_queues_aligned
->oq_element_array
;
3373 admin_queues
->iq_ci
= &admin_queues_aligned
->iq_ci
;
3374 admin_queues
->oq_pi
= &admin_queues_aligned
->oq_pi
;
3376 admin_queues
->iq_element_array_bus_addr
=
3377 ctrl_info
->admin_queue_memory_base_dma_handle
+
3378 (admin_queues
->iq_element_array
-
3379 ctrl_info
->admin_queue_memory_base
);
3380 admin_queues
->oq_element_array_bus_addr
=
3381 ctrl_info
->admin_queue_memory_base_dma_handle
+
3382 (admin_queues
->oq_element_array
-
3383 ctrl_info
->admin_queue_memory_base
);
3384 admin_queues
->iq_ci_bus_addr
=
3385 ctrl_info
->admin_queue_memory_base_dma_handle
+
3386 ((void *)admin_queues
->iq_ci
-
3387 ctrl_info
->admin_queue_memory_base
);
3388 admin_queues
->oq_pi_bus_addr
=
3389 ctrl_info
->admin_queue_memory_base_dma_handle
+
3390 ((void *)admin_queues
->oq_pi
-
3391 ctrl_info
->admin_queue_memory_base
);
3396 #define PQI_ADMIN_QUEUE_CREATE_TIMEOUT_JIFFIES HZ
3397 #define PQI_ADMIN_QUEUE_CREATE_POLL_INTERVAL_MSECS 1
3399 static int pqi_create_admin_queues(struct pqi_ctrl_info
*ctrl_info
)
3401 struct pqi_device_registers __iomem
*pqi_registers
;
3402 struct pqi_admin_queues
*admin_queues
;
3403 unsigned long timeout
;
3407 pqi_registers
= ctrl_info
->pqi_registers
;
3408 admin_queues
= &ctrl_info
->admin_queues
;
3410 writeq((u64
)admin_queues
->iq_element_array_bus_addr
,
3411 &pqi_registers
->admin_iq_element_array_addr
);
3412 writeq((u64
)admin_queues
->oq_element_array_bus_addr
,
3413 &pqi_registers
->admin_oq_element_array_addr
);
3414 writeq((u64
)admin_queues
->iq_ci_bus_addr
,
3415 &pqi_registers
->admin_iq_ci_addr
);
3416 writeq((u64
)admin_queues
->oq_pi_bus_addr
,
3417 &pqi_registers
->admin_oq_pi_addr
);
3419 reg
= PQI_ADMIN_IQ_NUM_ELEMENTS
|
3420 (PQI_ADMIN_OQ_NUM_ELEMENTS
) << 8 |
3421 (admin_queues
->int_msg_num
<< 16);
3422 writel(reg
, &pqi_registers
->admin_iq_num_elements
);
3423 writel(PQI_CREATE_ADMIN_QUEUE_PAIR
,
3424 &pqi_registers
->function_and_status_code
);
3426 timeout
= PQI_ADMIN_QUEUE_CREATE_TIMEOUT_JIFFIES
+ jiffies
;
3428 status
= readb(&pqi_registers
->function_and_status_code
);
3429 if (status
== PQI_STATUS_IDLE
)
3431 if (time_after(jiffies
, timeout
))
3433 msleep(PQI_ADMIN_QUEUE_CREATE_POLL_INTERVAL_MSECS
);
3437 * The offset registers are not initialized to the correct
3438 * offsets until *after* the create admin queue pair command
3439 * completes successfully.
3441 admin_queues
->iq_pi
= ctrl_info
->iomem_base
+
3442 PQI_DEVICE_REGISTERS_OFFSET
+
3443 readq(&pqi_registers
->admin_iq_pi_offset
);
3444 admin_queues
->oq_ci
= ctrl_info
->iomem_base
+
3445 PQI_DEVICE_REGISTERS_OFFSET
+
3446 readq(&pqi_registers
->admin_oq_ci_offset
);
3451 static void pqi_submit_admin_request(struct pqi_ctrl_info
*ctrl_info
,
3452 struct pqi_general_admin_request
*request
)
3454 struct pqi_admin_queues
*admin_queues
;
3458 admin_queues
= &ctrl_info
->admin_queues
;
3459 iq_pi
= admin_queues
->iq_pi_copy
;
3461 next_element
= admin_queues
->iq_element_array
+
3462 (iq_pi
* PQI_ADMIN_IQ_ELEMENT_LENGTH
);
3464 memcpy(next_element
, request
, sizeof(*request
));
3466 iq_pi
= (iq_pi
+ 1) % PQI_ADMIN_IQ_NUM_ELEMENTS
;
3467 admin_queues
->iq_pi_copy
= iq_pi
;
3470 * This write notifies the controller that an IU is available to be
3473 writel(iq_pi
, admin_queues
->iq_pi
);
3476 #define PQI_ADMIN_REQUEST_TIMEOUT_SECS 60
3478 static int pqi_poll_for_admin_response(struct pqi_ctrl_info
*ctrl_info
,
3479 struct pqi_general_admin_response
*response
)
3481 struct pqi_admin_queues
*admin_queues
;
3484 unsigned long timeout
;
3486 admin_queues
= &ctrl_info
->admin_queues
;
3487 oq_ci
= admin_queues
->oq_ci_copy
;
3489 timeout
= (PQI_ADMIN_REQUEST_TIMEOUT_SECS
* HZ
) + jiffies
;
3492 oq_pi
= *admin_queues
->oq_pi
;
3495 if (time_after(jiffies
, timeout
)) {
3496 dev_err(&ctrl_info
->pci_dev
->dev
,
3497 "timed out waiting for admin response\n");
3500 if (!sis_is_firmware_running(ctrl_info
))
3502 usleep_range(1000, 2000);
3505 memcpy(response
, admin_queues
->oq_element_array
+
3506 (oq_ci
* PQI_ADMIN_OQ_ELEMENT_LENGTH
), sizeof(*response
));
3508 oq_ci
= (oq_ci
+ 1) % PQI_ADMIN_OQ_NUM_ELEMENTS
;
3509 admin_queues
->oq_ci_copy
= oq_ci
;
3510 writel(oq_ci
, admin_queues
->oq_ci
);
3515 static void pqi_start_io(struct pqi_ctrl_info
*ctrl_info
,
3516 struct pqi_queue_group
*queue_group
, enum pqi_io_path path
,
3517 struct pqi_io_request
*io_request
)
3519 struct pqi_io_request
*next
;
3524 unsigned long flags
;
3525 unsigned int num_elements_needed
;
3526 unsigned int num_elements_to_end_of_queue
;
3528 struct pqi_iu_header
*request
;
3530 spin_lock_irqsave(&queue_group
->submit_lock
[path
], flags
);
3533 io_request
->queue_group
= queue_group
;
3534 list_add_tail(&io_request
->request_list_entry
,
3535 &queue_group
->request_list
[path
]);
3538 iq_pi
= queue_group
->iq_pi_copy
[path
];
3540 list_for_each_entry_safe(io_request
, next
,
3541 &queue_group
->request_list
[path
], request_list_entry
) {
3543 request
= io_request
->iu
;
3545 iu_length
= get_unaligned_le16(&request
->iu_length
) +
3546 PQI_REQUEST_HEADER_LENGTH
;
3547 num_elements_needed
=
3548 DIV_ROUND_UP(iu_length
,
3549 PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
);
3551 iq_ci
= *queue_group
->iq_ci
[path
];
3553 if (num_elements_needed
> pqi_num_elements_free(iq_pi
, iq_ci
,
3554 ctrl_info
->num_elements_per_iq
))
3557 put_unaligned_le16(queue_group
->oq_id
,
3558 &request
->response_queue_id
);
3560 next_element
= queue_group
->iq_element_array
[path
] +
3561 (iq_pi
* PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
);
3563 num_elements_to_end_of_queue
=
3564 ctrl_info
->num_elements_per_iq
- iq_pi
;
3566 if (num_elements_needed
<= num_elements_to_end_of_queue
) {
3567 memcpy(next_element
, request
, iu_length
);
3569 copy_count
= num_elements_to_end_of_queue
*
3570 PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
;
3571 memcpy(next_element
, request
, copy_count
);
3572 memcpy(queue_group
->iq_element_array
[path
],
3573 (u8
*)request
+ copy_count
,
3574 iu_length
- copy_count
);
3577 iq_pi
= (iq_pi
+ num_elements_needed
) %
3578 ctrl_info
->num_elements_per_iq
;
3580 list_del(&io_request
->request_list_entry
);
3583 if (iq_pi
!= queue_group
->iq_pi_copy
[path
]) {
3584 queue_group
->iq_pi_copy
[path
] = iq_pi
;
3586 * This write notifies the controller that one or more IUs are
3587 * available to be processed.
3589 writel(iq_pi
, queue_group
->iq_pi
[path
]);
3592 spin_unlock_irqrestore(&queue_group
->submit_lock
[path
], flags
);
3595 #define PQI_WAIT_FOR_COMPLETION_IO_TIMEOUT_SECS 10
3597 static int pqi_wait_for_completion_io(struct pqi_ctrl_info
*ctrl_info
,
3598 struct completion
*wait
)
3603 if (wait_for_completion_io_timeout(wait
,
3604 PQI_WAIT_FOR_COMPLETION_IO_TIMEOUT_SECS
* HZ
)) {
3609 pqi_check_ctrl_health(ctrl_info
);
3610 if (pqi_ctrl_offline(ctrl_info
)) {
3619 static void pqi_raid_synchronous_complete(struct pqi_io_request
*io_request
,
3622 struct completion
*waiting
= context
;
3627 static int pqi_submit_raid_request_synchronous_with_io_request(
3628 struct pqi_ctrl_info
*ctrl_info
, struct pqi_io_request
*io_request
,
3629 unsigned long timeout_msecs
)
3632 DECLARE_COMPLETION_ONSTACK(wait
);
3634 io_request
->io_complete_callback
= pqi_raid_synchronous_complete
;
3635 io_request
->context
= &wait
;
3637 pqi_start_io(ctrl_info
,
3638 &ctrl_info
->queue_groups
[PQI_DEFAULT_QUEUE_GROUP
], RAID_PATH
,
3641 if (timeout_msecs
== NO_TIMEOUT
) {
3642 pqi_wait_for_completion_io(ctrl_info
, &wait
);
3644 if (!wait_for_completion_io_timeout(&wait
,
3645 msecs_to_jiffies(timeout_msecs
))) {
3646 dev_warn(&ctrl_info
->pci_dev
->dev
,
3647 "command timed out\n");
3655 static int pqi_submit_raid_request_synchronous(struct pqi_ctrl_info
*ctrl_info
,
3656 struct pqi_iu_header
*request
, unsigned int flags
,
3657 struct pqi_raid_error_info
*error_info
, unsigned long timeout_msecs
)
3660 struct pqi_io_request
*io_request
;
3661 unsigned long start_jiffies
;
3662 unsigned long msecs_blocked
;
3666 * Note that specifying PQI_SYNC_FLAGS_INTERRUPTABLE and a timeout value
3667 * are mutually exclusive.
3670 if (flags
& PQI_SYNC_FLAGS_INTERRUPTABLE
) {
3671 if (down_interruptible(&ctrl_info
->sync_request_sem
))
3672 return -ERESTARTSYS
;
3674 if (timeout_msecs
== NO_TIMEOUT
) {
3675 down(&ctrl_info
->sync_request_sem
);
3677 start_jiffies
= jiffies
;
3678 if (down_timeout(&ctrl_info
->sync_request_sem
,
3679 msecs_to_jiffies(timeout_msecs
)))
3682 jiffies_to_msecs(jiffies
- start_jiffies
);
3683 if (msecs_blocked
>= timeout_msecs
)
3685 timeout_msecs
-= msecs_blocked
;
3689 pqi_ctrl_busy(ctrl_info
);
3690 timeout_msecs
= pqi_wait_if_ctrl_blocked(ctrl_info
, timeout_msecs
);
3691 if (timeout_msecs
== 0) {
3696 if (pqi_ctrl_offline(ctrl_info
)) {
3701 io_request
= pqi_alloc_io_request(ctrl_info
);
3703 put_unaligned_le16(io_request
->index
,
3704 &(((struct pqi_raid_path_request
*)request
)->request_id
));
3706 if (request
->iu_type
== PQI_REQUEST_IU_RAID_PATH_IO
)
3707 ((struct pqi_raid_path_request
*)request
)->error_index
=
3708 ((struct pqi_raid_path_request
*)request
)->request_id
;
3710 iu_length
= get_unaligned_le16(&request
->iu_length
) +
3711 PQI_REQUEST_HEADER_LENGTH
;
3712 memcpy(io_request
->iu
, request
, iu_length
);
3714 rc
= pqi_submit_raid_request_synchronous_with_io_request(ctrl_info
,
3715 io_request
, timeout_msecs
);
3718 if (io_request
->error_info
)
3719 memcpy(error_info
, io_request
->error_info
,
3720 sizeof(*error_info
));
3722 memset(error_info
, 0, sizeof(*error_info
));
3723 } else if (rc
== 0 && io_request
->error_info
) {
3725 struct pqi_raid_error_info
*raid_error_info
;
3727 raid_error_info
= io_request
->error_info
;
3728 scsi_status
= raid_error_info
->status
;
3730 if (scsi_status
== SAM_STAT_CHECK_CONDITION
&&
3731 raid_error_info
->data_out_result
==
3732 PQI_DATA_IN_OUT_UNDERFLOW
)
3733 scsi_status
= SAM_STAT_GOOD
;
3735 if (scsi_status
!= SAM_STAT_GOOD
)
3739 pqi_free_io_request(io_request
);
3742 pqi_ctrl_unbusy(ctrl_info
);
3743 up(&ctrl_info
->sync_request_sem
);
3748 static int pqi_validate_admin_response(
3749 struct pqi_general_admin_response
*response
, u8 expected_function_code
)
3751 if (response
->header
.iu_type
!= PQI_RESPONSE_IU_GENERAL_ADMIN
)
3754 if (get_unaligned_le16(&response
->header
.iu_length
) !=
3755 PQI_GENERAL_ADMIN_IU_LENGTH
)
3758 if (response
->function_code
!= expected_function_code
)
3761 if (response
->status
!= PQI_GENERAL_ADMIN_STATUS_SUCCESS
)
3767 static int pqi_submit_admin_request_synchronous(
3768 struct pqi_ctrl_info
*ctrl_info
,
3769 struct pqi_general_admin_request
*request
,
3770 struct pqi_general_admin_response
*response
)
3774 pqi_submit_admin_request(ctrl_info
, request
);
3776 rc
= pqi_poll_for_admin_response(ctrl_info
, response
);
3779 rc
= pqi_validate_admin_response(response
,
3780 request
->function_code
);
3785 static int pqi_report_device_capability(struct pqi_ctrl_info
*ctrl_info
)
3788 struct pqi_general_admin_request request
;
3789 struct pqi_general_admin_response response
;
3790 struct pqi_device_capability
*capability
;
3791 struct pqi_iu_layer_descriptor
*sop_iu_layer_descriptor
;
3793 capability
= kmalloc(sizeof(*capability
), GFP_KERNEL
);
3797 memset(&request
, 0, sizeof(request
));
3799 request
.header
.iu_type
= PQI_REQUEST_IU_GENERAL_ADMIN
;
3800 put_unaligned_le16(PQI_GENERAL_ADMIN_IU_LENGTH
,
3801 &request
.header
.iu_length
);
3802 request
.function_code
=
3803 PQI_GENERAL_ADMIN_FUNCTION_REPORT_DEVICE_CAPABILITY
;
3804 put_unaligned_le32(sizeof(*capability
),
3805 &request
.data
.report_device_capability
.buffer_length
);
3807 rc
= pqi_map_single(ctrl_info
->pci_dev
,
3808 &request
.data
.report_device_capability
.sg_descriptor
,
3809 capability
, sizeof(*capability
),
3810 PCI_DMA_FROMDEVICE
);
3814 rc
= pqi_submit_admin_request_synchronous(ctrl_info
, &request
,
3817 pqi_pci_unmap(ctrl_info
->pci_dev
,
3818 &request
.data
.report_device_capability
.sg_descriptor
, 1,
3819 PCI_DMA_FROMDEVICE
);
3824 if (response
.status
!= PQI_GENERAL_ADMIN_STATUS_SUCCESS
) {
3829 ctrl_info
->max_inbound_queues
=
3830 get_unaligned_le16(&capability
->max_inbound_queues
);
3831 ctrl_info
->max_elements_per_iq
=
3832 get_unaligned_le16(&capability
->max_elements_per_iq
);
3833 ctrl_info
->max_iq_element_length
=
3834 get_unaligned_le16(&capability
->max_iq_element_length
)
3836 ctrl_info
->max_outbound_queues
=
3837 get_unaligned_le16(&capability
->max_outbound_queues
);
3838 ctrl_info
->max_elements_per_oq
=
3839 get_unaligned_le16(&capability
->max_elements_per_oq
);
3840 ctrl_info
->max_oq_element_length
=
3841 get_unaligned_le16(&capability
->max_oq_element_length
)
3844 sop_iu_layer_descriptor
=
3845 &capability
->iu_layer_descriptors
[PQI_PROTOCOL_SOP
];
3847 ctrl_info
->max_inbound_iu_length_per_firmware
=
3849 &sop_iu_layer_descriptor
->max_inbound_iu_length
);
3850 ctrl_info
->inbound_spanning_supported
=
3851 sop_iu_layer_descriptor
->inbound_spanning_supported
;
3852 ctrl_info
->outbound_spanning_supported
=
3853 sop_iu_layer_descriptor
->outbound_spanning_supported
;
3861 static int pqi_validate_device_capability(struct pqi_ctrl_info
*ctrl_info
)
3863 if (ctrl_info
->max_iq_element_length
<
3864 PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
) {
3865 dev_err(&ctrl_info
->pci_dev
->dev
,
3866 "max. inbound queue element length of %d is less than the required length of %d\n",
3867 ctrl_info
->max_iq_element_length
,
3868 PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
);
3872 if (ctrl_info
->max_oq_element_length
<
3873 PQI_OPERATIONAL_OQ_ELEMENT_LENGTH
) {
3874 dev_err(&ctrl_info
->pci_dev
->dev
,
3875 "max. outbound queue element length of %d is less than the required length of %d\n",
3876 ctrl_info
->max_oq_element_length
,
3877 PQI_OPERATIONAL_OQ_ELEMENT_LENGTH
);
3881 if (ctrl_info
->max_inbound_iu_length_per_firmware
<
3882 PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
) {
3883 dev_err(&ctrl_info
->pci_dev
->dev
,
3884 "max. inbound IU length of %u is less than the min. required length of %d\n",
3885 ctrl_info
->max_inbound_iu_length_per_firmware
,
3886 PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
);
3890 if (!ctrl_info
->inbound_spanning_supported
) {
3891 dev_err(&ctrl_info
->pci_dev
->dev
,
3892 "the controller does not support inbound spanning\n");
3896 if (ctrl_info
->outbound_spanning_supported
) {
3897 dev_err(&ctrl_info
->pci_dev
->dev
,
3898 "the controller supports outbound spanning but this driver does not\n");
3905 static int pqi_delete_operational_queue(struct pqi_ctrl_info
*ctrl_info
,
3906 bool inbound_queue
, u16 queue_id
)
3908 struct pqi_general_admin_request request
;
3909 struct pqi_general_admin_response response
;
3911 memset(&request
, 0, sizeof(request
));
3912 request
.header
.iu_type
= PQI_REQUEST_IU_GENERAL_ADMIN
;
3913 put_unaligned_le16(PQI_GENERAL_ADMIN_IU_LENGTH
,
3914 &request
.header
.iu_length
);
3916 request
.function_code
=
3917 PQI_GENERAL_ADMIN_FUNCTION_DELETE_IQ
;
3919 request
.function_code
=
3920 PQI_GENERAL_ADMIN_FUNCTION_DELETE_OQ
;
3921 put_unaligned_le16(queue_id
,
3922 &request
.data
.delete_operational_queue
.queue_id
);
3924 return pqi_submit_admin_request_synchronous(ctrl_info
, &request
,
3928 static int pqi_create_event_queue(struct pqi_ctrl_info
*ctrl_info
)
3931 struct pqi_event_queue
*event_queue
;
3932 struct pqi_general_admin_request request
;
3933 struct pqi_general_admin_response response
;
3935 event_queue
= &ctrl_info
->event_queue
;
3938 * Create OQ (Outbound Queue - device to host queue) to dedicate
3941 memset(&request
, 0, sizeof(request
));
3942 request
.header
.iu_type
= PQI_REQUEST_IU_GENERAL_ADMIN
;
3943 put_unaligned_le16(PQI_GENERAL_ADMIN_IU_LENGTH
,
3944 &request
.header
.iu_length
);
3945 request
.function_code
= PQI_GENERAL_ADMIN_FUNCTION_CREATE_OQ
;
3946 put_unaligned_le16(event_queue
->oq_id
,
3947 &request
.data
.create_operational_oq
.queue_id
);
3948 put_unaligned_le64((u64
)event_queue
->oq_element_array_bus_addr
,
3949 &request
.data
.create_operational_oq
.element_array_addr
);
3950 put_unaligned_le64((u64
)event_queue
->oq_pi_bus_addr
,
3951 &request
.data
.create_operational_oq
.pi_addr
);
3952 put_unaligned_le16(PQI_NUM_EVENT_QUEUE_ELEMENTS
,
3953 &request
.data
.create_operational_oq
.num_elements
);
3954 put_unaligned_le16(PQI_EVENT_OQ_ELEMENT_LENGTH
/ 16,
3955 &request
.data
.create_operational_oq
.element_length
);
3956 request
.data
.create_operational_oq
.queue_protocol
= PQI_PROTOCOL_SOP
;
3957 put_unaligned_le16(event_queue
->int_msg_num
,
3958 &request
.data
.create_operational_oq
.int_msg_num
);
3960 rc
= pqi_submit_admin_request_synchronous(ctrl_info
, &request
,
3965 event_queue
->oq_ci
= ctrl_info
->iomem_base
+
3966 PQI_DEVICE_REGISTERS_OFFSET
+
3968 &response
.data
.create_operational_oq
.oq_ci_offset
);
3973 static int pqi_create_queue_group(struct pqi_ctrl_info
*ctrl_info
,
3974 unsigned int group_number
)
3977 struct pqi_queue_group
*queue_group
;
3978 struct pqi_general_admin_request request
;
3979 struct pqi_general_admin_response response
;
3981 queue_group
= &ctrl_info
->queue_groups
[group_number
];
3984 * Create IQ (Inbound Queue - host to device queue) for
3987 memset(&request
, 0, sizeof(request
));
3988 request
.header
.iu_type
= PQI_REQUEST_IU_GENERAL_ADMIN
;
3989 put_unaligned_le16(PQI_GENERAL_ADMIN_IU_LENGTH
,
3990 &request
.header
.iu_length
);
3991 request
.function_code
= PQI_GENERAL_ADMIN_FUNCTION_CREATE_IQ
;
3992 put_unaligned_le16(queue_group
->iq_id
[RAID_PATH
],
3993 &request
.data
.create_operational_iq
.queue_id
);
3995 (u64
)queue_group
->iq_element_array_bus_addr
[RAID_PATH
],
3996 &request
.data
.create_operational_iq
.element_array_addr
);
3997 put_unaligned_le64((u64
)queue_group
->iq_ci_bus_addr
[RAID_PATH
],
3998 &request
.data
.create_operational_iq
.ci_addr
);
3999 put_unaligned_le16(ctrl_info
->num_elements_per_iq
,
4000 &request
.data
.create_operational_iq
.num_elements
);
4001 put_unaligned_le16(PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
/ 16,
4002 &request
.data
.create_operational_iq
.element_length
);
4003 request
.data
.create_operational_iq
.queue_protocol
= PQI_PROTOCOL_SOP
;
4005 rc
= pqi_submit_admin_request_synchronous(ctrl_info
, &request
,
4008 dev_err(&ctrl_info
->pci_dev
->dev
,
4009 "error creating inbound RAID queue\n");
4013 queue_group
->iq_pi
[RAID_PATH
] = ctrl_info
->iomem_base
+
4014 PQI_DEVICE_REGISTERS_OFFSET
+
4016 &response
.data
.create_operational_iq
.iq_pi_offset
);
4019 * Create IQ (Inbound Queue - host to device queue) for
4020 * Advanced I/O (AIO) path.
4022 memset(&request
, 0, sizeof(request
));
4023 request
.header
.iu_type
= PQI_REQUEST_IU_GENERAL_ADMIN
;
4024 put_unaligned_le16(PQI_GENERAL_ADMIN_IU_LENGTH
,
4025 &request
.header
.iu_length
);
4026 request
.function_code
= PQI_GENERAL_ADMIN_FUNCTION_CREATE_IQ
;
4027 put_unaligned_le16(queue_group
->iq_id
[AIO_PATH
],
4028 &request
.data
.create_operational_iq
.queue_id
);
4029 put_unaligned_le64((u64
)queue_group
->
4030 iq_element_array_bus_addr
[AIO_PATH
],
4031 &request
.data
.create_operational_iq
.element_array_addr
);
4032 put_unaligned_le64((u64
)queue_group
->iq_ci_bus_addr
[AIO_PATH
],
4033 &request
.data
.create_operational_iq
.ci_addr
);
4034 put_unaligned_le16(ctrl_info
->num_elements_per_iq
,
4035 &request
.data
.create_operational_iq
.num_elements
);
4036 put_unaligned_le16(PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
/ 16,
4037 &request
.data
.create_operational_iq
.element_length
);
4038 request
.data
.create_operational_iq
.queue_protocol
= PQI_PROTOCOL_SOP
;
4040 rc
= pqi_submit_admin_request_synchronous(ctrl_info
, &request
,
4043 dev_err(&ctrl_info
->pci_dev
->dev
,
4044 "error creating inbound AIO queue\n");
4045 goto delete_inbound_queue_raid
;
4048 queue_group
->iq_pi
[AIO_PATH
] = ctrl_info
->iomem_base
+
4049 PQI_DEVICE_REGISTERS_OFFSET
+
4051 &response
.data
.create_operational_iq
.iq_pi_offset
);
4054 * Designate the 2nd IQ as the AIO path. By default, all IQs are
4055 * assumed to be for RAID path I/O unless we change the queue's
4058 memset(&request
, 0, sizeof(request
));
4059 request
.header
.iu_type
= PQI_REQUEST_IU_GENERAL_ADMIN
;
4060 put_unaligned_le16(PQI_GENERAL_ADMIN_IU_LENGTH
,
4061 &request
.header
.iu_length
);
4062 request
.function_code
= PQI_GENERAL_ADMIN_FUNCTION_CHANGE_IQ_PROPERTY
;
4063 put_unaligned_le16(queue_group
->iq_id
[AIO_PATH
],
4064 &request
.data
.change_operational_iq_properties
.queue_id
);
4065 put_unaligned_le32(PQI_IQ_PROPERTY_IS_AIO_QUEUE
,
4066 &request
.data
.change_operational_iq_properties
.vendor_specific
);
4068 rc
= pqi_submit_admin_request_synchronous(ctrl_info
, &request
,
4071 dev_err(&ctrl_info
->pci_dev
->dev
,
4072 "error changing queue property\n");
4073 goto delete_inbound_queue_aio
;
4077 * Create OQ (Outbound Queue - device to host queue).
4079 memset(&request
, 0, sizeof(request
));
4080 request
.header
.iu_type
= PQI_REQUEST_IU_GENERAL_ADMIN
;
4081 put_unaligned_le16(PQI_GENERAL_ADMIN_IU_LENGTH
,
4082 &request
.header
.iu_length
);
4083 request
.function_code
= PQI_GENERAL_ADMIN_FUNCTION_CREATE_OQ
;
4084 put_unaligned_le16(queue_group
->oq_id
,
4085 &request
.data
.create_operational_oq
.queue_id
);
4086 put_unaligned_le64((u64
)queue_group
->oq_element_array_bus_addr
,
4087 &request
.data
.create_operational_oq
.element_array_addr
);
4088 put_unaligned_le64((u64
)queue_group
->oq_pi_bus_addr
,
4089 &request
.data
.create_operational_oq
.pi_addr
);
4090 put_unaligned_le16(ctrl_info
->num_elements_per_oq
,
4091 &request
.data
.create_operational_oq
.num_elements
);
4092 put_unaligned_le16(PQI_OPERATIONAL_OQ_ELEMENT_LENGTH
/ 16,
4093 &request
.data
.create_operational_oq
.element_length
);
4094 request
.data
.create_operational_oq
.queue_protocol
= PQI_PROTOCOL_SOP
;
4095 put_unaligned_le16(queue_group
->int_msg_num
,
4096 &request
.data
.create_operational_oq
.int_msg_num
);
4098 rc
= pqi_submit_admin_request_synchronous(ctrl_info
, &request
,
4101 dev_err(&ctrl_info
->pci_dev
->dev
,
4102 "error creating outbound queue\n");
4103 goto delete_inbound_queue_aio
;
4106 queue_group
->oq_ci
= ctrl_info
->iomem_base
+
4107 PQI_DEVICE_REGISTERS_OFFSET
+
4109 &response
.data
.create_operational_oq
.oq_ci_offset
);
4113 delete_inbound_queue_aio
:
4114 pqi_delete_operational_queue(ctrl_info
, true,
4115 queue_group
->iq_id
[AIO_PATH
]);
4117 delete_inbound_queue_raid
:
4118 pqi_delete_operational_queue(ctrl_info
, true,
4119 queue_group
->iq_id
[RAID_PATH
]);
4124 static int pqi_create_queues(struct pqi_ctrl_info
*ctrl_info
)
4129 rc
= pqi_create_event_queue(ctrl_info
);
4131 dev_err(&ctrl_info
->pci_dev
->dev
,
4132 "error creating event queue\n");
4136 for (i
= 0; i
< ctrl_info
->num_queue_groups
; i
++) {
4137 rc
= pqi_create_queue_group(ctrl_info
, i
);
4139 dev_err(&ctrl_info
->pci_dev
->dev
,
4140 "error creating queue group number %u/%u\n",
4141 i
, ctrl_info
->num_queue_groups
);
4149 #define PQI_REPORT_EVENT_CONFIG_BUFFER_LENGTH \
4150 (offsetof(struct pqi_event_config, descriptors) + \
4151 (PQI_MAX_EVENT_DESCRIPTORS * sizeof(struct pqi_event_descriptor)))
4153 static int pqi_configure_events(struct pqi_ctrl_info
*ctrl_info
,
4158 struct pqi_event_config
*event_config
;
4159 struct pqi_event_descriptor
*event_descriptor
;
4160 struct pqi_general_management_request request
;
4162 event_config
= kmalloc(PQI_REPORT_EVENT_CONFIG_BUFFER_LENGTH
,
4167 memset(&request
, 0, sizeof(request
));
4169 request
.header
.iu_type
= PQI_REQUEST_IU_REPORT_VENDOR_EVENT_CONFIG
;
4170 put_unaligned_le16(offsetof(struct pqi_general_management_request
,
4171 data
.report_event_configuration
.sg_descriptors
[1]) -
4172 PQI_REQUEST_HEADER_LENGTH
, &request
.header
.iu_length
);
4173 put_unaligned_le32(PQI_REPORT_EVENT_CONFIG_BUFFER_LENGTH
,
4174 &request
.data
.report_event_configuration
.buffer_length
);
4176 rc
= pqi_map_single(ctrl_info
->pci_dev
,
4177 request
.data
.report_event_configuration
.sg_descriptors
,
4178 event_config
, PQI_REPORT_EVENT_CONFIG_BUFFER_LENGTH
,
4179 PCI_DMA_FROMDEVICE
);
4183 rc
= pqi_submit_raid_request_synchronous(ctrl_info
, &request
.header
,
4184 0, NULL
, NO_TIMEOUT
);
4186 pqi_pci_unmap(ctrl_info
->pci_dev
,
4187 request
.data
.report_event_configuration
.sg_descriptors
, 1,
4188 PCI_DMA_FROMDEVICE
);
4193 for (i
= 0; i
< event_config
->num_event_descriptors
; i
++) {
4194 event_descriptor
= &event_config
->descriptors
[i
];
4195 if (enable_events
&&
4196 pqi_is_supported_event(event_descriptor
->event_type
))
4197 put_unaligned_le16(ctrl_info
->event_queue
.oq_id
,
4198 &event_descriptor
->oq_id
);
4200 put_unaligned_le16(0, &event_descriptor
->oq_id
);
4203 memset(&request
, 0, sizeof(request
));
4205 request
.header
.iu_type
= PQI_REQUEST_IU_SET_VENDOR_EVENT_CONFIG
;
4206 put_unaligned_le16(offsetof(struct pqi_general_management_request
,
4207 data
.report_event_configuration
.sg_descriptors
[1]) -
4208 PQI_REQUEST_HEADER_LENGTH
, &request
.header
.iu_length
);
4209 put_unaligned_le32(PQI_REPORT_EVENT_CONFIG_BUFFER_LENGTH
,
4210 &request
.data
.report_event_configuration
.buffer_length
);
4212 rc
= pqi_map_single(ctrl_info
->pci_dev
,
4213 request
.data
.report_event_configuration
.sg_descriptors
,
4214 event_config
, PQI_REPORT_EVENT_CONFIG_BUFFER_LENGTH
,
4219 rc
= pqi_submit_raid_request_synchronous(ctrl_info
, &request
.header
, 0,
4222 pqi_pci_unmap(ctrl_info
->pci_dev
,
4223 request
.data
.report_event_configuration
.sg_descriptors
, 1,
4227 kfree(event_config
);
4232 static inline int pqi_enable_events(struct pqi_ctrl_info
*ctrl_info
)
4234 return pqi_configure_events(ctrl_info
, true);
4237 static inline int pqi_disable_events(struct pqi_ctrl_info
*ctrl_info
)
4239 return pqi_configure_events(ctrl_info
, false);
4242 static void pqi_free_all_io_requests(struct pqi_ctrl_info
*ctrl_info
)
4246 size_t sg_chain_buffer_length
;
4247 struct pqi_io_request
*io_request
;
4249 if (!ctrl_info
->io_request_pool
)
4252 dev
= &ctrl_info
->pci_dev
->dev
;
4253 sg_chain_buffer_length
= ctrl_info
->sg_chain_buffer_length
;
4254 io_request
= ctrl_info
->io_request_pool
;
4256 for (i
= 0; i
< ctrl_info
->max_io_slots
; i
++) {
4257 kfree(io_request
->iu
);
4258 if (!io_request
->sg_chain_buffer
)
4260 dma_free_coherent(dev
, sg_chain_buffer_length
,
4261 io_request
->sg_chain_buffer
,
4262 io_request
->sg_chain_buffer_dma_handle
);
4266 kfree(ctrl_info
->io_request_pool
);
4267 ctrl_info
->io_request_pool
= NULL
;
4270 static inline int pqi_alloc_error_buffer(struct pqi_ctrl_info
*ctrl_info
)
4272 ctrl_info
->error_buffer
= dma_zalloc_coherent(&ctrl_info
->pci_dev
->dev
,
4273 ctrl_info
->error_buffer_length
,
4274 &ctrl_info
->error_buffer_dma_handle
, GFP_KERNEL
);
4276 if (!ctrl_info
->error_buffer
)
4282 static int pqi_alloc_io_resources(struct pqi_ctrl_info
*ctrl_info
)
4285 void *sg_chain_buffer
;
4286 size_t sg_chain_buffer_length
;
4287 dma_addr_t sg_chain_buffer_dma_handle
;
4289 struct pqi_io_request
*io_request
;
4291 ctrl_info
->io_request_pool
= kzalloc(ctrl_info
->max_io_slots
*
4292 sizeof(ctrl_info
->io_request_pool
[0]), GFP_KERNEL
);
4294 if (!ctrl_info
->io_request_pool
) {
4295 dev_err(&ctrl_info
->pci_dev
->dev
,
4296 "failed to allocate I/O request pool\n");
4300 dev
= &ctrl_info
->pci_dev
->dev
;
4301 sg_chain_buffer_length
= ctrl_info
->sg_chain_buffer_length
;
4302 io_request
= ctrl_info
->io_request_pool
;
4304 for (i
= 0; i
< ctrl_info
->max_io_slots
; i
++) {
4306 kmalloc(ctrl_info
->max_inbound_iu_length
, GFP_KERNEL
);
4308 if (!io_request
->iu
) {
4309 dev_err(&ctrl_info
->pci_dev
->dev
,
4310 "failed to allocate IU buffers\n");
4314 sg_chain_buffer
= dma_alloc_coherent(dev
,
4315 sg_chain_buffer_length
, &sg_chain_buffer_dma_handle
,
4318 if (!sg_chain_buffer
) {
4319 dev_err(&ctrl_info
->pci_dev
->dev
,
4320 "failed to allocate PQI scatter-gather chain buffers\n");
4324 io_request
->index
= i
;
4325 io_request
->sg_chain_buffer
= sg_chain_buffer
;
4326 io_request
->sg_chain_buffer_dma_handle
=
4327 sg_chain_buffer_dma_handle
;
4334 pqi_free_all_io_requests(ctrl_info
);
4340 * Calculate required resources that are sized based on max. outstanding
4341 * requests and max. transfer size.
4344 static void pqi_calculate_io_resources(struct pqi_ctrl_info
*ctrl_info
)
4346 u32 max_transfer_size
;
4349 ctrl_info
->scsi_ml_can_queue
=
4350 ctrl_info
->max_outstanding_requests
- PQI_RESERVED_IO_SLOTS
;
4351 ctrl_info
->max_io_slots
= ctrl_info
->max_outstanding_requests
;
4353 ctrl_info
->error_buffer_length
=
4354 ctrl_info
->max_io_slots
* PQI_ERROR_BUFFER_ELEMENT_LENGTH
;
4357 max_transfer_size
= min(ctrl_info
->max_transfer_size
,
4358 PQI_MAX_TRANSFER_SIZE_KDUMP
);
4360 max_transfer_size
= min(ctrl_info
->max_transfer_size
,
4361 PQI_MAX_TRANSFER_SIZE
);
4363 max_sg_entries
= max_transfer_size
/ PAGE_SIZE
;
4365 /* +1 to cover when the buffer is not page-aligned. */
4368 max_sg_entries
= min(ctrl_info
->max_sg_entries
, max_sg_entries
);
4370 max_transfer_size
= (max_sg_entries
- 1) * PAGE_SIZE
;
4372 ctrl_info
->sg_chain_buffer_length
=
4373 (max_sg_entries
* sizeof(struct pqi_sg_descriptor
)) +
4374 PQI_EXTRA_SGL_MEMORY
;
4375 ctrl_info
->sg_tablesize
= max_sg_entries
;
4376 ctrl_info
->max_sectors
= max_transfer_size
/ 512;
4379 static void pqi_calculate_queue_resources(struct pqi_ctrl_info
*ctrl_info
)
4381 int num_queue_groups
;
4382 u16 num_elements_per_iq
;
4383 u16 num_elements_per_oq
;
4385 if (reset_devices
) {
4386 num_queue_groups
= 1;
4389 int max_queue_groups
;
4391 max_queue_groups
= min(ctrl_info
->max_inbound_queues
/ 2,
4392 ctrl_info
->max_outbound_queues
- 1);
4393 max_queue_groups
= min(max_queue_groups
, PQI_MAX_QUEUE_GROUPS
);
4395 num_cpus
= num_online_cpus();
4396 num_queue_groups
= min(num_cpus
, ctrl_info
->max_msix_vectors
);
4397 num_queue_groups
= min(num_queue_groups
, max_queue_groups
);
4400 ctrl_info
->num_queue_groups
= num_queue_groups
;
4401 ctrl_info
->max_hw_queue_index
= num_queue_groups
- 1;
4404 * Make sure that the max. inbound IU length is an even multiple
4405 * of our inbound element length.
4407 ctrl_info
->max_inbound_iu_length
=
4408 (ctrl_info
->max_inbound_iu_length_per_firmware
/
4409 PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
) *
4410 PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
;
4412 num_elements_per_iq
=
4413 (ctrl_info
->max_inbound_iu_length
/
4414 PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
);
4416 /* Add one because one element in each queue is unusable. */
4417 num_elements_per_iq
++;
4419 num_elements_per_iq
= min(num_elements_per_iq
,
4420 ctrl_info
->max_elements_per_iq
);
4422 num_elements_per_oq
= ((num_elements_per_iq
- 1) * 2) + 1;
4423 num_elements_per_oq
= min(num_elements_per_oq
,
4424 ctrl_info
->max_elements_per_oq
);
4426 ctrl_info
->num_elements_per_iq
= num_elements_per_iq
;
4427 ctrl_info
->num_elements_per_oq
= num_elements_per_oq
;
4429 ctrl_info
->max_sg_per_iu
=
4430 ((ctrl_info
->max_inbound_iu_length
-
4431 PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
) /
4432 sizeof(struct pqi_sg_descriptor
)) +
4433 PQI_MAX_EMBEDDED_SG_DESCRIPTORS
;
4436 static inline void pqi_set_sg_descriptor(
4437 struct pqi_sg_descriptor
*sg_descriptor
, struct scatterlist
*sg
)
4439 u64 address
= (u64
)sg_dma_address(sg
);
4440 unsigned int length
= sg_dma_len(sg
);
4442 put_unaligned_le64(address
, &sg_descriptor
->address
);
4443 put_unaligned_le32(length
, &sg_descriptor
->length
);
4444 put_unaligned_le32(0, &sg_descriptor
->flags
);
4447 static int pqi_build_raid_sg_list(struct pqi_ctrl_info
*ctrl_info
,
4448 struct pqi_raid_path_request
*request
, struct scsi_cmnd
*scmd
,
4449 struct pqi_io_request
*io_request
)
4455 unsigned int num_sg_in_iu
;
4456 unsigned int max_sg_per_iu
;
4457 struct scatterlist
*sg
;
4458 struct pqi_sg_descriptor
*sg_descriptor
;
4460 sg_count
= scsi_dma_map(scmd
);
4464 iu_length
= offsetof(struct pqi_raid_path_request
, sg_descriptors
) -
4465 PQI_REQUEST_HEADER_LENGTH
;
4470 sg
= scsi_sglist(scmd
);
4471 sg_descriptor
= request
->sg_descriptors
;
4472 max_sg_per_iu
= ctrl_info
->max_sg_per_iu
- 1;
4478 pqi_set_sg_descriptor(sg_descriptor
, sg
);
4485 if (i
== max_sg_per_iu
) {
4487 (u64
)io_request
->sg_chain_buffer_dma_handle
,
4488 &sg_descriptor
->address
);
4489 put_unaligned_le32((sg_count
- num_sg_in_iu
)
4490 * sizeof(*sg_descriptor
),
4491 &sg_descriptor
->length
);
4492 put_unaligned_le32(CISS_SG_CHAIN
,
4493 &sg_descriptor
->flags
);
4496 sg_descriptor
= io_request
->sg_chain_buffer
;
4501 put_unaligned_le32(CISS_SG_LAST
, &sg_descriptor
->flags
);
4502 request
->partial
= chained
;
4503 iu_length
+= num_sg_in_iu
* sizeof(*sg_descriptor
);
4506 put_unaligned_le16(iu_length
, &request
->header
.iu_length
);
4511 static int pqi_build_aio_sg_list(struct pqi_ctrl_info
*ctrl_info
,
4512 struct pqi_aio_path_request
*request
, struct scsi_cmnd
*scmd
,
4513 struct pqi_io_request
*io_request
)
4519 unsigned int num_sg_in_iu
;
4520 unsigned int max_sg_per_iu
;
4521 struct scatterlist
*sg
;
4522 struct pqi_sg_descriptor
*sg_descriptor
;
4524 sg_count
= scsi_dma_map(scmd
);
4528 iu_length
= offsetof(struct pqi_aio_path_request
, sg_descriptors
) -
4529 PQI_REQUEST_HEADER_LENGTH
;
4535 sg
= scsi_sglist(scmd
);
4536 sg_descriptor
= request
->sg_descriptors
;
4537 max_sg_per_iu
= ctrl_info
->max_sg_per_iu
- 1;
4542 pqi_set_sg_descriptor(sg_descriptor
, sg
);
4549 if (i
== max_sg_per_iu
) {
4551 (u64
)io_request
->sg_chain_buffer_dma_handle
,
4552 &sg_descriptor
->address
);
4553 put_unaligned_le32((sg_count
- num_sg_in_iu
)
4554 * sizeof(*sg_descriptor
),
4555 &sg_descriptor
->length
);
4556 put_unaligned_le32(CISS_SG_CHAIN
,
4557 &sg_descriptor
->flags
);
4560 sg_descriptor
= io_request
->sg_chain_buffer
;
4565 put_unaligned_le32(CISS_SG_LAST
, &sg_descriptor
->flags
);
4566 request
->partial
= chained
;
4567 iu_length
+= num_sg_in_iu
* sizeof(*sg_descriptor
);
4570 put_unaligned_le16(iu_length
, &request
->header
.iu_length
);
4571 request
->num_sg_descriptors
= num_sg_in_iu
;
4576 static void pqi_raid_io_complete(struct pqi_io_request
*io_request
,
4579 struct scsi_cmnd
*scmd
;
4581 scmd
= io_request
->scmd
;
4582 pqi_free_io_request(io_request
);
4583 scsi_dma_unmap(scmd
);
4584 pqi_scsi_done(scmd
);
4587 static int pqi_raid_submit_scsi_cmd_with_io_request(
4588 struct pqi_ctrl_info
*ctrl_info
, struct pqi_io_request
*io_request
,
4589 struct pqi_scsi_dev
*device
, struct scsi_cmnd
*scmd
,
4590 struct pqi_queue_group
*queue_group
)
4594 struct pqi_raid_path_request
*request
;
4596 io_request
->io_complete_callback
= pqi_raid_io_complete
;
4597 io_request
->scmd
= scmd
;
4599 request
= io_request
->iu
;
4601 offsetof(struct pqi_raid_path_request
, sg_descriptors
));
4603 request
->header
.iu_type
= PQI_REQUEST_IU_RAID_PATH_IO
;
4604 put_unaligned_le32(scsi_bufflen(scmd
), &request
->buffer_length
);
4605 request
->task_attribute
= SOP_TASK_ATTRIBUTE_SIMPLE
;
4606 put_unaligned_le16(io_request
->index
, &request
->request_id
);
4607 request
->error_index
= request
->request_id
;
4608 memcpy(request
->lun_number
, device
->scsi3addr
,
4609 sizeof(request
->lun_number
));
4611 cdb_length
= min_t(size_t, scmd
->cmd_len
, sizeof(request
->cdb
));
4612 memcpy(request
->cdb
, scmd
->cmnd
, cdb_length
);
4614 switch (cdb_length
) {
4619 /* No bytes in the Additional CDB bytes field */
4620 request
->additional_cdb_bytes_usage
=
4621 SOP_ADDITIONAL_CDB_BYTES_0
;
4624 /* 4 bytes in the Additional cdb field */
4625 request
->additional_cdb_bytes_usage
=
4626 SOP_ADDITIONAL_CDB_BYTES_4
;
4629 /* 8 bytes in the Additional cdb field */
4630 request
->additional_cdb_bytes_usage
=
4631 SOP_ADDITIONAL_CDB_BYTES_8
;
4634 /* 12 bytes in the Additional cdb field */
4635 request
->additional_cdb_bytes_usage
=
4636 SOP_ADDITIONAL_CDB_BYTES_12
;
4640 /* 16 bytes in the Additional cdb field */
4641 request
->additional_cdb_bytes_usage
=
4642 SOP_ADDITIONAL_CDB_BYTES_16
;
4646 switch (scmd
->sc_data_direction
) {
4648 request
->data_direction
= SOP_READ_FLAG
;
4650 case DMA_FROM_DEVICE
:
4651 request
->data_direction
= SOP_WRITE_FLAG
;
4654 request
->data_direction
= SOP_NO_DIRECTION_FLAG
;
4656 case DMA_BIDIRECTIONAL
:
4657 request
->data_direction
= SOP_BIDIRECTIONAL
;
4660 dev_err(&ctrl_info
->pci_dev
->dev
,
4661 "unknown data direction: %d\n",
4662 scmd
->sc_data_direction
);
4666 rc
= pqi_build_raid_sg_list(ctrl_info
, request
, scmd
, io_request
);
4668 pqi_free_io_request(io_request
);
4669 return SCSI_MLQUEUE_HOST_BUSY
;
4672 pqi_start_io(ctrl_info
, queue_group
, RAID_PATH
, io_request
);
4677 static inline int pqi_raid_submit_scsi_cmd(struct pqi_ctrl_info
*ctrl_info
,
4678 struct pqi_scsi_dev
*device
, struct scsi_cmnd
*scmd
,
4679 struct pqi_queue_group
*queue_group
)
4681 struct pqi_io_request
*io_request
;
4683 io_request
= pqi_alloc_io_request(ctrl_info
);
4685 return pqi_raid_submit_scsi_cmd_with_io_request(ctrl_info
, io_request
,
4686 device
, scmd
, queue_group
);
4689 static inline void pqi_schedule_bypass_retry(struct pqi_ctrl_info
*ctrl_info
)
4691 if (!pqi_ctrl_blocked(ctrl_info
))
4692 schedule_work(&ctrl_info
->raid_bypass_retry_work
);
4695 static bool pqi_raid_bypass_retry_needed(struct pqi_io_request
*io_request
)
4697 struct scsi_cmnd
*scmd
;
4698 struct pqi_scsi_dev
*device
;
4699 struct pqi_ctrl_info
*ctrl_info
;
4701 if (!io_request
->raid_bypass
)
4704 scmd
= io_request
->scmd
;
4705 if ((scmd
->result
& 0xff) == SAM_STAT_GOOD
)
4707 if (host_byte(scmd
->result
) == DID_NO_CONNECT
)
4710 device
= scmd
->device
->hostdata
;
4711 if (pqi_device_offline(device
))
4714 ctrl_info
= shost_to_hba(scmd
->device
->host
);
4715 if (pqi_ctrl_offline(ctrl_info
))
4721 static inline void pqi_add_to_raid_bypass_retry_list(
4722 struct pqi_ctrl_info
*ctrl_info
,
4723 struct pqi_io_request
*io_request
, bool at_head
)
4725 unsigned long flags
;
4727 spin_lock_irqsave(&ctrl_info
->raid_bypass_retry_list_lock
, flags
);
4729 list_add(&io_request
->request_list_entry
,
4730 &ctrl_info
->raid_bypass_retry_list
);
4732 list_add_tail(&io_request
->request_list_entry
,
4733 &ctrl_info
->raid_bypass_retry_list
);
4734 spin_unlock_irqrestore(&ctrl_info
->raid_bypass_retry_list_lock
, flags
);
4737 static void pqi_queued_raid_bypass_complete(struct pqi_io_request
*io_request
,
4740 struct scsi_cmnd
*scmd
;
4742 scmd
= io_request
->scmd
;
4743 pqi_free_io_request(io_request
);
4744 pqi_scsi_done(scmd
);
4747 static void pqi_queue_raid_bypass_retry(struct pqi_io_request
*io_request
)
4749 struct scsi_cmnd
*scmd
;
4750 struct pqi_ctrl_info
*ctrl_info
;
4752 io_request
->io_complete_callback
= pqi_queued_raid_bypass_complete
;
4753 scmd
= io_request
->scmd
;
4755 ctrl_info
= shost_to_hba(scmd
->device
->host
);
4757 pqi_add_to_raid_bypass_retry_list(ctrl_info
, io_request
, false);
4758 pqi_schedule_bypass_retry(ctrl_info
);
4761 static int pqi_retry_raid_bypass(struct pqi_io_request
*io_request
)
4763 struct scsi_cmnd
*scmd
;
4764 struct pqi_scsi_dev
*device
;
4765 struct pqi_ctrl_info
*ctrl_info
;
4766 struct pqi_queue_group
*queue_group
;
4768 scmd
= io_request
->scmd
;
4769 device
= scmd
->device
->hostdata
;
4770 if (pqi_device_in_reset(device
)) {
4771 pqi_free_io_request(io_request
);
4772 set_host_byte(scmd
, DID_RESET
);
4773 pqi_scsi_done(scmd
);
4777 ctrl_info
= shost_to_hba(scmd
->device
->host
);
4778 queue_group
= io_request
->queue_group
;
4780 pqi_reinit_io_request(io_request
);
4782 return pqi_raid_submit_scsi_cmd_with_io_request(ctrl_info
, io_request
,
4783 device
, scmd
, queue_group
);
4786 static inline struct pqi_io_request
*pqi_next_queued_raid_bypass_request(
4787 struct pqi_ctrl_info
*ctrl_info
)
4789 unsigned long flags
;
4790 struct pqi_io_request
*io_request
;
4792 spin_lock_irqsave(&ctrl_info
->raid_bypass_retry_list_lock
, flags
);
4793 io_request
= list_first_entry_or_null(
4794 &ctrl_info
->raid_bypass_retry_list
,
4795 struct pqi_io_request
, request_list_entry
);
4797 list_del(&io_request
->request_list_entry
);
4798 spin_unlock_irqrestore(&ctrl_info
->raid_bypass_retry_list_lock
, flags
);
4803 static void pqi_retry_raid_bypass_requests(struct pqi_ctrl_info
*ctrl_info
)
4806 struct pqi_io_request
*io_request
;
4808 pqi_ctrl_busy(ctrl_info
);
4811 if (pqi_ctrl_blocked(ctrl_info
))
4813 io_request
= pqi_next_queued_raid_bypass_request(ctrl_info
);
4816 rc
= pqi_retry_raid_bypass(io_request
);
4818 pqi_add_to_raid_bypass_retry_list(ctrl_info
, io_request
,
4820 pqi_schedule_bypass_retry(ctrl_info
);
4825 pqi_ctrl_unbusy(ctrl_info
);
4828 static void pqi_raid_bypass_retry_worker(struct work_struct
*work
)
4830 struct pqi_ctrl_info
*ctrl_info
;
4832 ctrl_info
= container_of(work
, struct pqi_ctrl_info
,
4833 raid_bypass_retry_work
);
4834 pqi_retry_raid_bypass_requests(ctrl_info
);
4837 static void pqi_clear_all_queued_raid_bypass_retries(
4838 struct pqi_ctrl_info
*ctrl_info
)
4840 unsigned long flags
;
4842 spin_lock_irqsave(&ctrl_info
->raid_bypass_retry_list_lock
, flags
);
4843 INIT_LIST_HEAD(&ctrl_info
->raid_bypass_retry_list
);
4844 spin_unlock_irqrestore(&ctrl_info
->raid_bypass_retry_list_lock
, flags
);
4847 static void pqi_aio_io_complete(struct pqi_io_request
*io_request
,
4850 struct scsi_cmnd
*scmd
;
4852 scmd
= io_request
->scmd
;
4853 scsi_dma_unmap(scmd
);
4854 if (io_request
->status
== -EAGAIN
)
4855 set_host_byte(scmd
, DID_IMM_RETRY
);
4856 else if (pqi_raid_bypass_retry_needed(io_request
)) {
4857 pqi_queue_raid_bypass_retry(io_request
);
4860 pqi_free_io_request(io_request
);
4861 pqi_scsi_done(scmd
);
4864 static inline int pqi_aio_submit_scsi_cmd(struct pqi_ctrl_info
*ctrl_info
,
4865 struct pqi_scsi_dev
*device
, struct scsi_cmnd
*scmd
,
4866 struct pqi_queue_group
*queue_group
)
4868 return pqi_aio_submit_io(ctrl_info
, scmd
, device
->aio_handle
,
4869 scmd
->cmnd
, scmd
->cmd_len
, queue_group
, NULL
, false);
4872 static int pqi_aio_submit_io(struct pqi_ctrl_info
*ctrl_info
,
4873 struct scsi_cmnd
*scmd
, u32 aio_handle
, u8
*cdb
,
4874 unsigned int cdb_length
, struct pqi_queue_group
*queue_group
,
4875 struct pqi_encryption_info
*encryption_info
, bool raid_bypass
)
4878 struct pqi_io_request
*io_request
;
4879 struct pqi_aio_path_request
*request
;
4881 io_request
= pqi_alloc_io_request(ctrl_info
);
4882 io_request
->io_complete_callback
= pqi_aio_io_complete
;
4883 io_request
->scmd
= scmd
;
4884 io_request
->raid_bypass
= raid_bypass
;
4886 request
= io_request
->iu
;
4888 offsetof(struct pqi_raid_path_request
, sg_descriptors
));
4890 request
->header
.iu_type
= PQI_REQUEST_IU_AIO_PATH_IO
;
4891 put_unaligned_le32(aio_handle
, &request
->nexus_id
);
4892 put_unaligned_le32(scsi_bufflen(scmd
), &request
->buffer_length
);
4893 request
->task_attribute
= SOP_TASK_ATTRIBUTE_SIMPLE
;
4894 put_unaligned_le16(io_request
->index
, &request
->request_id
);
4895 request
->error_index
= request
->request_id
;
4896 if (cdb_length
> sizeof(request
->cdb
))
4897 cdb_length
= sizeof(request
->cdb
);
4898 request
->cdb_length
= cdb_length
;
4899 memcpy(request
->cdb
, cdb
, cdb_length
);
4901 switch (scmd
->sc_data_direction
) {
4903 request
->data_direction
= SOP_READ_FLAG
;
4905 case DMA_FROM_DEVICE
:
4906 request
->data_direction
= SOP_WRITE_FLAG
;
4909 request
->data_direction
= SOP_NO_DIRECTION_FLAG
;
4911 case DMA_BIDIRECTIONAL
:
4912 request
->data_direction
= SOP_BIDIRECTIONAL
;
4915 dev_err(&ctrl_info
->pci_dev
->dev
,
4916 "unknown data direction: %d\n",
4917 scmd
->sc_data_direction
);
4921 if (encryption_info
) {
4922 request
->encryption_enable
= true;
4923 put_unaligned_le16(encryption_info
->data_encryption_key_index
,
4924 &request
->data_encryption_key_index
);
4925 put_unaligned_le32(encryption_info
->encrypt_tweak_lower
,
4926 &request
->encrypt_tweak_lower
);
4927 put_unaligned_le32(encryption_info
->encrypt_tweak_upper
,
4928 &request
->encrypt_tweak_upper
);
4931 rc
= pqi_build_aio_sg_list(ctrl_info
, request
, scmd
, io_request
);
4933 pqi_free_io_request(io_request
);
4934 return SCSI_MLQUEUE_HOST_BUSY
;
4937 pqi_start_io(ctrl_info
, queue_group
, AIO_PATH
, io_request
);
4942 static inline u16
pqi_get_hw_queue(struct pqi_ctrl_info
*ctrl_info
,
4943 struct scsi_cmnd
*scmd
)
4947 hw_queue
= blk_mq_unique_tag_to_hwq(blk_mq_unique_tag(scmd
->request
));
4948 if (hw_queue
> ctrl_info
->max_hw_queue_index
)
4955 * This function gets called just before we hand the completed SCSI request
4959 void pqi_prep_for_scsi_done(struct scsi_cmnd
*scmd
)
4961 struct pqi_scsi_dev
*device
;
4963 device
= scmd
->device
->hostdata
;
4964 atomic_dec(&device
->scsi_cmds_outstanding
);
4967 static int pqi_scsi_queue_command(struct Scsi_Host
*shost
,
4968 struct scsi_cmnd
*scmd
)
4971 struct pqi_ctrl_info
*ctrl_info
;
4972 struct pqi_scsi_dev
*device
;
4974 struct pqi_queue_group
*queue_group
;
4977 device
= scmd
->device
->hostdata
;
4978 ctrl_info
= shost_to_hba(shost
);
4980 atomic_inc(&device
->scsi_cmds_outstanding
);
4982 if (pqi_ctrl_offline(ctrl_info
)) {
4983 set_host_byte(scmd
, DID_NO_CONNECT
);
4984 pqi_scsi_done(scmd
);
4988 pqi_ctrl_busy(ctrl_info
);
4989 if (pqi_ctrl_blocked(ctrl_info
) || pqi_device_in_reset(device
)) {
4990 rc
= SCSI_MLQUEUE_HOST_BUSY
;
4995 * This is necessary because the SML doesn't zero out this field during
5000 hw_queue
= pqi_get_hw_queue(ctrl_info
, scmd
);
5001 queue_group
= &ctrl_info
->queue_groups
[hw_queue
];
5003 if (pqi_is_logical_device(device
)) {
5004 raid_bypassed
= false;
5005 if (device
->raid_bypass_enabled
&&
5006 !blk_rq_is_passthrough(scmd
->request
)) {
5007 rc
= pqi_raid_bypass_submit_scsi_cmd(ctrl_info
, device
,
5009 if (rc
== 0 || rc
== SCSI_MLQUEUE_HOST_BUSY
)
5010 raid_bypassed
= true;
5013 rc
= pqi_raid_submit_scsi_cmd(ctrl_info
, device
, scmd
,
5016 if (device
->aio_enabled
)
5017 rc
= pqi_aio_submit_scsi_cmd(ctrl_info
, device
, scmd
,
5020 rc
= pqi_raid_submit_scsi_cmd(ctrl_info
, device
, scmd
,
5025 pqi_ctrl_unbusy(ctrl_info
);
5027 atomic_dec(&device
->scsi_cmds_outstanding
);
5032 static int pqi_wait_until_queued_io_drained(struct pqi_ctrl_info
*ctrl_info
,
5033 struct pqi_queue_group
*queue_group
)
5036 unsigned long flags
;
5039 for (path
= 0; path
< 2; path
++) {
5042 &queue_group
->submit_lock
[path
], flags
);
5044 list_empty(&queue_group
->request_list
[path
]);
5045 spin_unlock_irqrestore(
5046 &queue_group
->submit_lock
[path
], flags
);
5049 pqi_check_ctrl_health(ctrl_info
);
5050 if (pqi_ctrl_offline(ctrl_info
))
5052 usleep_range(1000, 2000);
5059 static int pqi_wait_until_inbound_queues_empty(struct pqi_ctrl_info
*ctrl_info
)
5064 struct pqi_queue_group
*queue_group
;
5068 for (i
= 0; i
< ctrl_info
->num_queue_groups
; i
++) {
5069 queue_group
= &ctrl_info
->queue_groups
[i
];
5071 rc
= pqi_wait_until_queued_io_drained(ctrl_info
, queue_group
);
5075 for (path
= 0; path
< 2; path
++) {
5076 iq_pi
= queue_group
->iq_pi_copy
[path
];
5079 iq_ci
= *queue_group
->iq_ci
[path
];
5082 pqi_check_ctrl_health(ctrl_info
);
5083 if (pqi_ctrl_offline(ctrl_info
))
5085 usleep_range(1000, 2000);
5093 static void pqi_fail_io_queued_for_device(struct pqi_ctrl_info
*ctrl_info
,
5094 struct pqi_scsi_dev
*device
)
5098 struct pqi_queue_group
*queue_group
;
5099 unsigned long flags
;
5100 struct pqi_io_request
*io_request
;
5101 struct pqi_io_request
*next
;
5102 struct scsi_cmnd
*scmd
;
5103 struct pqi_scsi_dev
*scsi_device
;
5105 for (i
= 0; i
< ctrl_info
->num_queue_groups
; i
++) {
5106 queue_group
= &ctrl_info
->queue_groups
[i
];
5108 for (path
= 0; path
< 2; path
++) {
5110 &queue_group
->submit_lock
[path
], flags
);
5112 list_for_each_entry_safe(io_request
, next
,
5113 &queue_group
->request_list
[path
],
5114 request_list_entry
) {
5115 scmd
= io_request
->scmd
;
5119 scsi_device
= scmd
->device
->hostdata
;
5120 if (scsi_device
!= device
)
5123 list_del(&io_request
->request_list_entry
);
5124 set_host_byte(scmd
, DID_RESET
);
5125 pqi_scsi_done(scmd
);
5128 spin_unlock_irqrestore(
5129 &queue_group
->submit_lock
[path
], flags
);
5134 static int pqi_device_wait_for_pending_io(struct pqi_ctrl_info
*ctrl_info
,
5135 struct pqi_scsi_dev
*device
)
5137 while (atomic_read(&device
->scsi_cmds_outstanding
)) {
5138 pqi_check_ctrl_health(ctrl_info
);
5139 if (pqi_ctrl_offline(ctrl_info
))
5141 usleep_range(1000, 2000);
5147 static int pqi_ctrl_wait_for_pending_io(struct pqi_ctrl_info
*ctrl_info
)
5150 unsigned long flags
;
5151 struct pqi_scsi_dev
*device
;
5156 spin_lock_irqsave(&ctrl_info
->scsi_device_list_lock
, flags
);
5157 list_for_each_entry(device
, &ctrl_info
->scsi_device_list
,
5158 scsi_device_list_entry
) {
5159 if (atomic_read(&device
->scsi_cmds_outstanding
)) {
5164 spin_unlock_irqrestore(&ctrl_info
->scsi_device_list_lock
,
5170 pqi_check_ctrl_health(ctrl_info
);
5171 if (pqi_ctrl_offline(ctrl_info
))
5174 usleep_range(1000, 2000);
5180 static void pqi_lun_reset_complete(struct pqi_io_request
*io_request
,
5183 struct completion
*waiting
= context
;
5188 #define PQI_LUN_RESET_TIMEOUT_SECS 10
5190 static int pqi_wait_for_lun_reset_completion(struct pqi_ctrl_info
*ctrl_info
,
5191 struct pqi_scsi_dev
*device
, struct completion
*wait
)
5196 if (wait_for_completion_io_timeout(wait
,
5197 PQI_LUN_RESET_TIMEOUT_SECS
* HZ
)) {
5202 pqi_check_ctrl_health(ctrl_info
);
5203 if (pqi_ctrl_offline(ctrl_info
)) {
5212 static int pqi_lun_reset(struct pqi_ctrl_info
*ctrl_info
,
5213 struct pqi_scsi_dev
*device
)
5216 struct pqi_io_request
*io_request
;
5217 DECLARE_COMPLETION_ONSTACK(wait
);
5218 struct pqi_task_management_request
*request
;
5220 io_request
= pqi_alloc_io_request(ctrl_info
);
5221 io_request
->io_complete_callback
= pqi_lun_reset_complete
;
5222 io_request
->context
= &wait
;
5224 request
= io_request
->iu
;
5225 memset(request
, 0, sizeof(*request
));
5227 request
->header
.iu_type
= PQI_REQUEST_IU_TASK_MANAGEMENT
;
5228 put_unaligned_le16(sizeof(*request
) - PQI_REQUEST_HEADER_LENGTH
,
5229 &request
->header
.iu_length
);
5230 put_unaligned_le16(io_request
->index
, &request
->request_id
);
5231 memcpy(request
->lun_number
, device
->scsi3addr
,
5232 sizeof(request
->lun_number
));
5233 request
->task_management_function
= SOP_TASK_MANAGEMENT_LUN_RESET
;
5235 pqi_start_io(ctrl_info
,
5236 &ctrl_info
->queue_groups
[PQI_DEFAULT_QUEUE_GROUP
], RAID_PATH
,
5239 rc
= pqi_wait_for_lun_reset_completion(ctrl_info
, device
, &wait
);
5241 rc
= io_request
->status
;
5243 pqi_free_io_request(io_request
);
5248 /* Performs a reset at the LUN level. */
5250 static int pqi_device_reset(struct pqi_ctrl_info
*ctrl_info
,
5251 struct pqi_scsi_dev
*device
)
5255 rc
= pqi_lun_reset(ctrl_info
, device
);
5257 rc
= pqi_device_wait_for_pending_io(ctrl_info
, device
);
5259 return rc
== 0 ? SUCCESS
: FAILED
;
5262 static int pqi_eh_device_reset_handler(struct scsi_cmnd
*scmd
)
5265 struct Scsi_Host
*shost
;
5266 struct pqi_ctrl_info
*ctrl_info
;
5267 struct pqi_scsi_dev
*device
;
5269 shost
= scmd
->device
->host
;
5270 ctrl_info
= shost_to_hba(shost
);
5271 device
= scmd
->device
->hostdata
;
5273 dev_err(&ctrl_info
->pci_dev
->dev
,
5274 "resetting scsi %d:%d:%d:%d\n",
5275 shost
->host_no
, device
->bus
, device
->target
, device
->lun
);
5277 pqi_check_ctrl_health(ctrl_info
);
5278 if (pqi_ctrl_offline(ctrl_info
)) {
5283 mutex_lock(&ctrl_info
->lun_reset_mutex
);
5285 pqi_ctrl_block_requests(ctrl_info
);
5286 pqi_ctrl_wait_until_quiesced(ctrl_info
);
5287 pqi_fail_io_queued_for_device(ctrl_info
, device
);
5288 rc
= pqi_wait_until_inbound_queues_empty(ctrl_info
);
5289 pqi_device_reset_start(device
);
5290 pqi_ctrl_unblock_requests(ctrl_info
);
5295 rc
= pqi_device_reset(ctrl_info
, device
);
5297 pqi_device_reset_done(device
);
5299 mutex_unlock(&ctrl_info
->lun_reset_mutex
);
5302 dev_err(&ctrl_info
->pci_dev
->dev
,
5303 "reset of scsi %d:%d:%d:%d: %s\n",
5304 shost
->host_no
, device
->bus
, device
->target
, device
->lun
,
5305 rc
== SUCCESS
? "SUCCESS" : "FAILED");
5310 static int pqi_slave_alloc(struct scsi_device
*sdev
)
5312 struct pqi_scsi_dev
*device
;
5313 unsigned long flags
;
5314 struct pqi_ctrl_info
*ctrl_info
;
5315 struct scsi_target
*starget
;
5316 struct sas_rphy
*rphy
;
5318 ctrl_info
= shost_to_hba(sdev
->host
);
5320 spin_lock_irqsave(&ctrl_info
->scsi_device_list_lock
, flags
);
5322 if (sdev_channel(sdev
) == PQI_PHYSICAL_DEVICE_BUS
) {
5323 starget
= scsi_target(sdev
);
5324 rphy
= target_to_rphy(starget
);
5325 device
= pqi_find_device_by_sas_rphy(ctrl_info
, rphy
);
5327 device
->target
= sdev_id(sdev
);
5328 device
->lun
= sdev
->lun
;
5329 device
->target_lun_valid
= true;
5332 device
= pqi_find_scsi_dev(ctrl_info
, sdev_channel(sdev
),
5333 sdev_id(sdev
), sdev
->lun
);
5337 sdev
->hostdata
= device
;
5338 device
->sdev
= sdev
;
5339 if (device
->queue_depth
) {
5340 device
->advertised_queue_depth
= device
->queue_depth
;
5341 scsi_change_queue_depth(sdev
,
5342 device
->advertised_queue_depth
);
5346 spin_unlock_irqrestore(&ctrl_info
->scsi_device_list_lock
, flags
);
5351 static int pqi_map_queues(struct Scsi_Host
*shost
)
5353 struct pqi_ctrl_info
*ctrl_info
= shost_to_hba(shost
);
5355 return blk_mq_pci_map_queues(&shost
->tag_set
, ctrl_info
->pci_dev
);
5358 static int pqi_getpciinfo_ioctl(struct pqi_ctrl_info
*ctrl_info
,
5361 struct pci_dev
*pci_dev
;
5362 u32 subsystem_vendor
;
5363 u32 subsystem_device
;
5364 cciss_pci_info_struct pciinfo
;
5369 pci_dev
= ctrl_info
->pci_dev
;
5371 pciinfo
.domain
= pci_domain_nr(pci_dev
->bus
);
5372 pciinfo
.bus
= pci_dev
->bus
->number
;
5373 pciinfo
.dev_fn
= pci_dev
->devfn
;
5374 subsystem_vendor
= pci_dev
->subsystem_vendor
;
5375 subsystem_device
= pci_dev
->subsystem_device
;
5376 pciinfo
.board_id
= ((subsystem_device
<< 16) & 0xffff0000) |
5379 if (copy_to_user(arg
, &pciinfo
, sizeof(pciinfo
)))
5385 static int pqi_getdrivver_ioctl(void __user
*arg
)
5392 version
= (DRIVER_MAJOR
<< 28) | (DRIVER_MINOR
<< 24) |
5393 (DRIVER_RELEASE
<< 16) | DRIVER_REVISION
;
5395 if (copy_to_user(arg
, &version
, sizeof(version
)))
5401 struct ciss_error_info
{
5404 size_t sense_data_length
;
5407 static void pqi_error_info_to_ciss(struct pqi_raid_error_info
*pqi_error_info
,
5408 struct ciss_error_info
*ciss_error_info
)
5410 int ciss_cmd_status
;
5411 size_t sense_data_length
;
5413 switch (pqi_error_info
->data_out_result
) {
5414 case PQI_DATA_IN_OUT_GOOD
:
5415 ciss_cmd_status
= CISS_CMD_STATUS_SUCCESS
;
5417 case PQI_DATA_IN_OUT_UNDERFLOW
:
5418 ciss_cmd_status
= CISS_CMD_STATUS_DATA_UNDERRUN
;
5420 case PQI_DATA_IN_OUT_BUFFER_OVERFLOW
:
5421 ciss_cmd_status
= CISS_CMD_STATUS_DATA_OVERRUN
;
5423 case PQI_DATA_IN_OUT_PROTOCOL_ERROR
:
5424 case PQI_DATA_IN_OUT_BUFFER_ERROR
:
5425 case PQI_DATA_IN_OUT_BUFFER_OVERFLOW_DESCRIPTOR_AREA
:
5426 case PQI_DATA_IN_OUT_BUFFER_OVERFLOW_BRIDGE
:
5427 case PQI_DATA_IN_OUT_ERROR
:
5428 ciss_cmd_status
= CISS_CMD_STATUS_PROTOCOL_ERROR
;
5430 case PQI_DATA_IN_OUT_HARDWARE_ERROR
:
5431 case PQI_DATA_IN_OUT_PCIE_FABRIC_ERROR
:
5432 case PQI_DATA_IN_OUT_PCIE_COMPLETION_TIMEOUT
:
5433 case PQI_DATA_IN_OUT_PCIE_COMPLETER_ABORT_RECEIVED
:
5434 case PQI_DATA_IN_OUT_PCIE_UNSUPPORTED_REQUEST_RECEIVED
:
5435 case PQI_DATA_IN_OUT_PCIE_ECRC_CHECK_FAILED
:
5436 case PQI_DATA_IN_OUT_PCIE_UNSUPPORTED_REQUEST
:
5437 case PQI_DATA_IN_OUT_PCIE_ACS_VIOLATION
:
5438 case PQI_DATA_IN_OUT_PCIE_TLP_PREFIX_BLOCKED
:
5439 case PQI_DATA_IN_OUT_PCIE_POISONED_MEMORY_READ
:
5440 ciss_cmd_status
= CISS_CMD_STATUS_HARDWARE_ERROR
;
5442 case PQI_DATA_IN_OUT_UNSOLICITED_ABORT
:
5443 ciss_cmd_status
= CISS_CMD_STATUS_UNSOLICITED_ABORT
;
5445 case PQI_DATA_IN_OUT_ABORTED
:
5446 ciss_cmd_status
= CISS_CMD_STATUS_ABORTED
;
5448 case PQI_DATA_IN_OUT_TIMEOUT
:
5449 ciss_cmd_status
= CISS_CMD_STATUS_TIMEOUT
;
5452 ciss_cmd_status
= CISS_CMD_STATUS_TARGET_STATUS
;
5457 get_unaligned_le16(&pqi_error_info
->sense_data_length
);
5458 if (sense_data_length
== 0)
5460 get_unaligned_le16(&pqi_error_info
->response_data_length
);
5461 if (sense_data_length
)
5462 if (sense_data_length
> sizeof(pqi_error_info
->data
))
5463 sense_data_length
= sizeof(pqi_error_info
->data
);
5465 ciss_error_info
->scsi_status
= pqi_error_info
->status
;
5466 ciss_error_info
->command_status
= ciss_cmd_status
;
5467 ciss_error_info
->sense_data_length
= sense_data_length
;
5470 static int pqi_passthru_ioctl(struct pqi_ctrl_info
*ctrl_info
, void __user
*arg
)
5473 char *kernel_buffer
= NULL
;
5475 size_t sense_data_length
;
5476 IOCTL_Command_struct iocommand
;
5477 struct pqi_raid_path_request request
;
5478 struct pqi_raid_error_info pqi_error_info
;
5479 struct ciss_error_info ciss_error_info
;
5481 if (pqi_ctrl_offline(ctrl_info
))
5485 if (!capable(CAP_SYS_RAWIO
))
5487 if (copy_from_user(&iocommand
, arg
, sizeof(iocommand
)))
5489 if (iocommand
.buf_size
< 1 &&
5490 iocommand
.Request
.Type
.Direction
!= XFER_NONE
)
5492 if (iocommand
.Request
.CDBLen
> sizeof(request
.cdb
))
5494 if (iocommand
.Request
.Type
.Type
!= TYPE_CMD
)
5497 switch (iocommand
.Request
.Type
.Direction
) {
5506 if (iocommand
.buf_size
> 0) {
5507 kernel_buffer
= kmalloc(iocommand
.buf_size
, GFP_KERNEL
);
5510 if (iocommand
.Request
.Type
.Direction
& XFER_WRITE
) {
5511 if (copy_from_user(kernel_buffer
, iocommand
.buf
,
5512 iocommand
.buf_size
)) {
5517 memset(kernel_buffer
, 0, iocommand
.buf_size
);
5521 memset(&request
, 0, sizeof(request
));
5523 request
.header
.iu_type
= PQI_REQUEST_IU_RAID_PATH_IO
;
5524 iu_length
= offsetof(struct pqi_raid_path_request
, sg_descriptors
) -
5525 PQI_REQUEST_HEADER_LENGTH
;
5526 memcpy(request
.lun_number
, iocommand
.LUN_info
.LunAddrBytes
,
5527 sizeof(request
.lun_number
));
5528 memcpy(request
.cdb
, iocommand
.Request
.CDB
, iocommand
.Request
.CDBLen
);
5529 request
.additional_cdb_bytes_usage
= SOP_ADDITIONAL_CDB_BYTES_0
;
5531 switch (iocommand
.Request
.Type
.Direction
) {
5533 request
.data_direction
= SOP_NO_DIRECTION_FLAG
;
5536 request
.data_direction
= SOP_WRITE_FLAG
;
5539 request
.data_direction
= SOP_READ_FLAG
;
5543 request
.task_attribute
= SOP_TASK_ATTRIBUTE_SIMPLE
;
5545 if (iocommand
.buf_size
> 0) {
5546 put_unaligned_le32(iocommand
.buf_size
, &request
.buffer_length
);
5548 rc
= pqi_map_single(ctrl_info
->pci_dev
,
5549 &request
.sg_descriptors
[0], kernel_buffer
,
5550 iocommand
.buf_size
, PCI_DMA_BIDIRECTIONAL
);
5554 iu_length
+= sizeof(request
.sg_descriptors
[0]);
5557 put_unaligned_le16(iu_length
, &request
.header
.iu_length
);
5559 rc
= pqi_submit_raid_request_synchronous(ctrl_info
, &request
.header
,
5560 PQI_SYNC_FLAGS_INTERRUPTABLE
, &pqi_error_info
, NO_TIMEOUT
);
5562 if (iocommand
.buf_size
> 0)
5563 pqi_pci_unmap(ctrl_info
->pci_dev
, request
.sg_descriptors
, 1,
5564 PCI_DMA_BIDIRECTIONAL
);
5566 memset(&iocommand
.error_info
, 0, sizeof(iocommand
.error_info
));
5569 pqi_error_info_to_ciss(&pqi_error_info
, &ciss_error_info
);
5570 iocommand
.error_info
.ScsiStatus
= ciss_error_info
.scsi_status
;
5571 iocommand
.error_info
.CommandStatus
=
5572 ciss_error_info
.command_status
;
5573 sense_data_length
= ciss_error_info
.sense_data_length
;
5574 if (sense_data_length
) {
5575 if (sense_data_length
>
5576 sizeof(iocommand
.error_info
.SenseInfo
))
5578 sizeof(iocommand
.error_info
.SenseInfo
);
5579 memcpy(iocommand
.error_info
.SenseInfo
,
5580 pqi_error_info
.data
, sense_data_length
);
5581 iocommand
.error_info
.SenseLen
= sense_data_length
;
5585 if (copy_to_user(arg
, &iocommand
, sizeof(iocommand
))) {
5590 if (rc
== 0 && iocommand
.buf_size
> 0 &&
5591 (iocommand
.Request
.Type
.Direction
& XFER_READ
)) {
5592 if (copy_to_user(iocommand
.buf
, kernel_buffer
,
5593 iocommand
.buf_size
)) {
5599 kfree(kernel_buffer
);
5604 static int pqi_ioctl(struct scsi_device
*sdev
, int cmd
, void __user
*arg
)
5607 struct pqi_ctrl_info
*ctrl_info
;
5609 ctrl_info
= shost_to_hba(sdev
->host
);
5612 case CCISS_DEREGDISK
:
5613 case CCISS_REGNEWDISK
:
5615 rc
= pqi_scan_scsi_devices(ctrl_info
);
5617 case CCISS_GETPCIINFO
:
5618 rc
= pqi_getpciinfo_ioctl(ctrl_info
, arg
);
5620 case CCISS_GETDRIVVER
:
5621 rc
= pqi_getdrivver_ioctl(arg
);
5623 case CCISS_PASSTHRU
:
5624 rc
= pqi_passthru_ioctl(ctrl_info
, arg
);
5634 static ssize_t
pqi_version_show(struct device
*dev
,
5635 struct device_attribute
*attr
, char *buffer
)
5638 struct Scsi_Host
*shost
;
5639 struct pqi_ctrl_info
*ctrl_info
;
5641 shost
= class_to_shost(dev
);
5642 ctrl_info
= shost_to_hba(shost
);
5644 count
+= snprintf(buffer
+ count
, PAGE_SIZE
- count
,
5645 " driver: %s\n", DRIVER_VERSION BUILD_TIMESTAMP
);
5647 count
+= snprintf(buffer
+ count
, PAGE_SIZE
- count
,
5648 "firmware: %s\n", ctrl_info
->firmware_version
);
5653 static ssize_t
pqi_host_rescan_store(struct device
*dev
,
5654 struct device_attribute
*attr
, const char *buffer
, size_t count
)
5656 struct Scsi_Host
*shost
= class_to_shost(dev
);
5658 pqi_scan_start(shost
);
5663 static ssize_t
pqi_lockup_action_show(struct device
*dev
,
5664 struct device_attribute
*attr
, char *buffer
)
5669 for (i
= 0; i
< ARRAY_SIZE(pqi_lockup_actions
); i
++) {
5670 if (pqi_lockup_actions
[i
].action
== pqi_lockup_action
)
5671 count
+= snprintf(buffer
+ count
, PAGE_SIZE
- count
,
5672 "[%s] ", pqi_lockup_actions
[i
].name
);
5674 count
+= snprintf(buffer
+ count
, PAGE_SIZE
- count
,
5675 "%s ", pqi_lockup_actions
[i
].name
);
5678 count
+= snprintf(buffer
+ count
, PAGE_SIZE
- count
, "\n");
5683 static ssize_t
pqi_lockup_action_store(struct device
*dev
,
5684 struct device_attribute
*attr
, const char *buffer
, size_t count
)
5688 char action_name_buffer
[32];
5690 strlcpy(action_name_buffer
, buffer
, sizeof(action_name_buffer
));
5691 action_name
= strstrip(action_name_buffer
);
5693 for (i
= 0; i
< ARRAY_SIZE(pqi_lockup_actions
); i
++) {
5694 if (strcmp(action_name
, pqi_lockup_actions
[i
].name
) == 0) {
5695 pqi_lockup_action
= pqi_lockup_actions
[i
].action
;
5703 static DEVICE_ATTR(version
, 0444, pqi_version_show
, NULL
);
5704 static DEVICE_ATTR(rescan
, 0200, NULL
, pqi_host_rescan_store
);
5705 static DEVICE_ATTR(lockup_action
, 0644,
5706 pqi_lockup_action_show
, pqi_lockup_action_store
);
5708 static struct device_attribute
*pqi_shost_attrs
[] = {
5711 &dev_attr_lockup_action
,
5715 static ssize_t
pqi_sas_address_show(struct device
*dev
,
5716 struct device_attribute
*attr
, char *buffer
)
5718 struct pqi_ctrl_info
*ctrl_info
;
5719 struct scsi_device
*sdev
;
5720 struct pqi_scsi_dev
*device
;
5721 unsigned long flags
;
5724 sdev
= to_scsi_device(dev
);
5725 ctrl_info
= shost_to_hba(sdev
->host
);
5727 spin_lock_irqsave(&ctrl_info
->scsi_device_list_lock
, flags
);
5729 device
= sdev
->hostdata
;
5730 if (pqi_is_logical_device(device
)) {
5731 spin_unlock_irqrestore(&ctrl_info
->scsi_device_list_lock
,
5735 sas_address
= device
->sas_address
;
5737 spin_unlock_irqrestore(&ctrl_info
->scsi_device_list_lock
, flags
);
5739 return snprintf(buffer
, PAGE_SIZE
, "0x%016llx\n", sas_address
);
5742 static ssize_t
pqi_ssd_smart_path_enabled_show(struct device
*dev
,
5743 struct device_attribute
*attr
, char *buffer
)
5745 struct pqi_ctrl_info
*ctrl_info
;
5746 struct scsi_device
*sdev
;
5747 struct pqi_scsi_dev
*device
;
5748 unsigned long flags
;
5750 sdev
= to_scsi_device(dev
);
5751 ctrl_info
= shost_to_hba(sdev
->host
);
5753 spin_lock_irqsave(&ctrl_info
->scsi_device_list_lock
, flags
);
5755 device
= sdev
->hostdata
;
5756 buffer
[0] = device
->raid_bypass_enabled
? '1' : '0';
5760 spin_unlock_irqrestore(&ctrl_info
->scsi_device_list_lock
, flags
);
5765 static ssize_t
pqi_raid_level_show(struct device
*dev
,
5766 struct device_attribute
*attr
, char *buffer
)
5768 struct pqi_ctrl_info
*ctrl_info
;
5769 struct scsi_device
*sdev
;
5770 struct pqi_scsi_dev
*device
;
5771 unsigned long flags
;
5774 sdev
= to_scsi_device(dev
);
5775 ctrl_info
= shost_to_hba(sdev
->host
);
5777 spin_lock_irqsave(&ctrl_info
->scsi_device_list_lock
, flags
);
5779 device
= sdev
->hostdata
;
5781 if (pqi_is_logical_device(device
))
5782 raid_level
= pqi_raid_level_to_string(device
->raid_level
);
5786 spin_unlock_irqrestore(&ctrl_info
->scsi_device_list_lock
, flags
);
5788 return snprintf(buffer
, PAGE_SIZE
, "%s\n", raid_level
);
5791 static DEVICE_ATTR(sas_address
, 0444, pqi_sas_address_show
, NULL
);
5792 static DEVICE_ATTR(ssd_smart_path_enabled
, 0444,
5793 pqi_ssd_smart_path_enabled_show
, NULL
);
5794 static DEVICE_ATTR(raid_level
, 0444, pqi_raid_level_show
, NULL
);
5796 static struct device_attribute
*pqi_sdev_attrs
[] = {
5797 &dev_attr_sas_address
,
5798 &dev_attr_ssd_smart_path_enabled
,
5799 &dev_attr_raid_level
,
5803 static struct scsi_host_template pqi_driver_template
= {
5804 .module
= THIS_MODULE
,
5805 .name
= DRIVER_NAME_SHORT
,
5806 .proc_name
= DRIVER_NAME_SHORT
,
5807 .queuecommand
= pqi_scsi_queue_command
,
5808 .scan_start
= pqi_scan_start
,
5809 .scan_finished
= pqi_scan_finished
,
5811 .use_clustering
= ENABLE_CLUSTERING
,
5812 .eh_device_reset_handler
= pqi_eh_device_reset_handler
,
5814 .slave_alloc
= pqi_slave_alloc
,
5815 .map_queues
= pqi_map_queues
,
5816 .sdev_attrs
= pqi_sdev_attrs
,
5817 .shost_attrs
= pqi_shost_attrs
,
5820 static int pqi_register_scsi(struct pqi_ctrl_info
*ctrl_info
)
5823 struct Scsi_Host
*shost
;
5825 shost
= scsi_host_alloc(&pqi_driver_template
, sizeof(ctrl_info
));
5827 dev_err(&ctrl_info
->pci_dev
->dev
,
5828 "scsi_host_alloc failed for controller %u\n",
5829 ctrl_info
->ctrl_id
);
5834 shost
->n_io_port
= 0;
5835 shost
->this_id
= -1;
5836 shost
->max_channel
= PQI_MAX_BUS
;
5837 shost
->max_cmd_len
= MAX_COMMAND_SIZE
;
5838 shost
->max_lun
= ~0;
5840 shost
->max_sectors
= ctrl_info
->max_sectors
;
5841 shost
->can_queue
= ctrl_info
->scsi_ml_can_queue
;
5842 shost
->cmd_per_lun
= shost
->can_queue
;
5843 shost
->sg_tablesize
= ctrl_info
->sg_tablesize
;
5844 shost
->transportt
= pqi_sas_transport_template
;
5845 shost
->irq
= pci_irq_vector(ctrl_info
->pci_dev
, 0);
5846 shost
->unique_id
= shost
->irq
;
5847 shost
->nr_hw_queues
= ctrl_info
->num_queue_groups
;
5848 shost
->hostdata
[0] = (unsigned long)ctrl_info
;
5850 rc
= scsi_add_host(shost
, &ctrl_info
->pci_dev
->dev
);
5852 dev_err(&ctrl_info
->pci_dev
->dev
,
5853 "scsi_add_host failed for controller %u\n",
5854 ctrl_info
->ctrl_id
);
5858 rc
= pqi_add_sas_host(shost
, ctrl_info
);
5860 dev_err(&ctrl_info
->pci_dev
->dev
,
5861 "add SAS host failed for controller %u\n",
5862 ctrl_info
->ctrl_id
);
5866 ctrl_info
->scsi_host
= shost
;
5871 scsi_remove_host(shost
);
5873 scsi_host_put(shost
);
5878 static void pqi_unregister_scsi(struct pqi_ctrl_info
*ctrl_info
)
5880 struct Scsi_Host
*shost
;
5882 pqi_delete_sas_host(ctrl_info
);
5884 shost
= ctrl_info
->scsi_host
;
5888 scsi_remove_host(shost
);
5889 scsi_host_put(shost
);
5892 #define PQI_RESET_ACTION_RESET 0x1
5894 #define PQI_RESET_TYPE_NO_RESET 0x0
5895 #define PQI_RESET_TYPE_SOFT_RESET 0x1
5896 #define PQI_RESET_TYPE_FIRM_RESET 0x2
5897 #define PQI_RESET_TYPE_HARD_RESET 0x3
5899 static int pqi_reset(struct pqi_ctrl_info
*ctrl_info
)
5904 reset_params
= (PQI_RESET_ACTION_RESET
<< 5) |
5905 PQI_RESET_TYPE_HARD_RESET
;
5907 writel(reset_params
,
5908 &ctrl_info
->pqi_registers
->device_reset
);
5910 rc
= pqi_wait_for_pqi_mode_ready(ctrl_info
);
5912 dev_err(&ctrl_info
->pci_dev
->dev
,
5913 "PQI reset failed\n");
5918 static int pqi_get_ctrl_firmware_version(struct pqi_ctrl_info
*ctrl_info
)
5921 struct bmic_identify_controller
*identify
;
5923 identify
= kmalloc(sizeof(*identify
), GFP_KERNEL
);
5927 rc
= pqi_identify_controller(ctrl_info
, identify
);
5931 memcpy(ctrl_info
->firmware_version
, identify
->firmware_version
,
5932 sizeof(identify
->firmware_version
));
5933 ctrl_info
->firmware_version
[sizeof(identify
->firmware_version
)] = '\0';
5934 snprintf(ctrl_info
->firmware_version
+
5935 strlen(ctrl_info
->firmware_version
),
5936 sizeof(ctrl_info
->firmware_version
),
5937 "-%u", get_unaligned_le16(&identify
->firmware_build_number
));
5945 static int pqi_process_config_table(struct pqi_ctrl_info
*ctrl_info
)
5949 void __iomem
*table_iomem_addr
;
5950 struct pqi_config_table
*config_table
;
5951 struct pqi_config_table_section_header
*section
;
5953 table_length
= ctrl_info
->config_table_length
;
5955 config_table
= kmalloc(table_length
, GFP_KERNEL
);
5956 if (!config_table
) {
5957 dev_err(&ctrl_info
->pci_dev
->dev
,
5958 "failed to allocate memory for PQI configuration table\n");
5963 * Copy the config table contents from I/O memory space into the
5966 table_iomem_addr
= ctrl_info
->iomem_base
+
5967 ctrl_info
->config_table_offset
;
5968 memcpy_fromio(config_table
, table_iomem_addr
, table_length
);
5971 get_unaligned_le32(&config_table
->first_section_offset
);
5973 while (section_offset
) {
5974 section
= (void *)config_table
+ section_offset
;
5976 switch (get_unaligned_le16(§ion
->section_id
)) {
5977 case PQI_CONFIG_TABLE_SECTION_HEARTBEAT
:
5978 if (pqi_disable_heartbeat
)
5979 dev_warn(&ctrl_info
->pci_dev
->dev
,
5980 "heartbeat disabled by module parameter\n");
5982 ctrl_info
->heartbeat_counter
=
5986 struct pqi_config_table_heartbeat
,
5992 get_unaligned_le16(§ion
->next_section_offset
);
5995 kfree(config_table
);
6000 /* Switches the controller from PQI mode back into SIS mode. */
6002 static int pqi_revert_to_sis_mode(struct pqi_ctrl_info
*ctrl_info
)
6006 pqi_change_irq_mode(ctrl_info
, IRQ_MODE_NONE
);
6007 rc
= pqi_reset(ctrl_info
);
6010 sis_reenable_sis_mode(ctrl_info
);
6011 pqi_save_ctrl_mode(ctrl_info
, SIS_MODE
);
6017 * If the controller isn't already in SIS mode, this function forces it into
6021 static int pqi_force_sis_mode(struct pqi_ctrl_info
*ctrl_info
)
6023 if (!sis_is_firmware_running(ctrl_info
))
6026 if (pqi_get_ctrl_mode(ctrl_info
) == SIS_MODE
)
6029 if (sis_is_kernel_up(ctrl_info
)) {
6030 pqi_save_ctrl_mode(ctrl_info
, SIS_MODE
);
6034 return pqi_revert_to_sis_mode(ctrl_info
);
6037 static int pqi_ctrl_init(struct pqi_ctrl_info
*ctrl_info
)
6041 rc
= pqi_force_sis_mode(ctrl_info
);
6046 * Wait until the controller is ready to start accepting SIS
6049 rc
= sis_wait_for_ctrl_ready(ctrl_info
);
6054 * Get the controller properties. This allows us to determine
6055 * whether or not it supports PQI mode.
6057 rc
= sis_get_ctrl_properties(ctrl_info
);
6059 dev_err(&ctrl_info
->pci_dev
->dev
,
6060 "error obtaining controller properties\n");
6064 rc
= sis_get_pqi_capabilities(ctrl_info
);
6066 dev_err(&ctrl_info
->pci_dev
->dev
,
6067 "error obtaining controller capabilities\n");
6071 if (reset_devices
) {
6072 if (ctrl_info
->max_outstanding_requests
>
6073 PQI_MAX_OUTSTANDING_REQUESTS_KDUMP
)
6074 ctrl_info
->max_outstanding_requests
=
6075 PQI_MAX_OUTSTANDING_REQUESTS_KDUMP
;
6077 if (ctrl_info
->max_outstanding_requests
>
6078 PQI_MAX_OUTSTANDING_REQUESTS
)
6079 ctrl_info
->max_outstanding_requests
=
6080 PQI_MAX_OUTSTANDING_REQUESTS
;
6083 pqi_calculate_io_resources(ctrl_info
);
6085 rc
= pqi_alloc_error_buffer(ctrl_info
);
6087 dev_err(&ctrl_info
->pci_dev
->dev
,
6088 "failed to allocate PQI error buffer\n");
6093 * If the function we are about to call succeeds, the
6094 * controller will transition from legacy SIS mode
6097 rc
= sis_init_base_struct_addr(ctrl_info
);
6099 dev_err(&ctrl_info
->pci_dev
->dev
,
6100 "error initializing PQI mode\n");
6104 /* Wait for the controller to complete the SIS -> PQI transition. */
6105 rc
= pqi_wait_for_pqi_mode_ready(ctrl_info
);
6107 dev_err(&ctrl_info
->pci_dev
->dev
,
6108 "transition to PQI mode failed\n");
6112 /* From here on, we are running in PQI mode. */
6113 ctrl_info
->pqi_mode_enabled
= true;
6114 pqi_save_ctrl_mode(ctrl_info
, PQI_MODE
);
6116 rc
= pqi_process_config_table(ctrl_info
);
6120 rc
= pqi_alloc_admin_queues(ctrl_info
);
6122 dev_err(&ctrl_info
->pci_dev
->dev
,
6123 "failed to allocate admin queues\n");
6127 rc
= pqi_create_admin_queues(ctrl_info
);
6129 dev_err(&ctrl_info
->pci_dev
->dev
,
6130 "error creating admin queues\n");
6134 rc
= pqi_report_device_capability(ctrl_info
);
6136 dev_err(&ctrl_info
->pci_dev
->dev
,
6137 "obtaining device capability failed\n");
6141 rc
= pqi_validate_device_capability(ctrl_info
);
6145 pqi_calculate_queue_resources(ctrl_info
);
6147 rc
= pqi_enable_msix_interrupts(ctrl_info
);
6151 if (ctrl_info
->num_msix_vectors_enabled
< ctrl_info
->num_queue_groups
) {
6152 ctrl_info
->max_msix_vectors
=
6153 ctrl_info
->num_msix_vectors_enabled
;
6154 pqi_calculate_queue_resources(ctrl_info
);
6157 rc
= pqi_alloc_io_resources(ctrl_info
);
6161 rc
= pqi_alloc_operational_queues(ctrl_info
);
6163 dev_err(&ctrl_info
->pci_dev
->dev
,
6164 "failed to allocate operational queues\n");
6168 pqi_init_operational_queues(ctrl_info
);
6170 rc
= pqi_request_irqs(ctrl_info
);
6174 rc
= pqi_create_queues(ctrl_info
);
6178 pqi_change_irq_mode(ctrl_info
, IRQ_MODE_MSIX
);
6180 ctrl_info
->controller_online
= true;
6181 pqi_start_heartbeat_timer(ctrl_info
);
6183 rc
= pqi_enable_events(ctrl_info
);
6185 dev_err(&ctrl_info
->pci_dev
->dev
,
6186 "error enabling events\n");
6190 /* Register with the SCSI subsystem. */
6191 rc
= pqi_register_scsi(ctrl_info
);
6195 rc
= pqi_get_ctrl_firmware_version(ctrl_info
);
6197 dev_err(&ctrl_info
->pci_dev
->dev
,
6198 "error obtaining firmware version\n");
6202 rc
= pqi_write_driver_version_to_host_wellness(ctrl_info
);
6204 dev_err(&ctrl_info
->pci_dev
->dev
,
6205 "error updating host wellness\n");
6209 pqi_schedule_update_time_worker(ctrl_info
);
6211 pqi_scan_scsi_devices(ctrl_info
);
6216 static void pqi_reinit_queues(struct pqi_ctrl_info
*ctrl_info
)
6219 struct pqi_admin_queues
*admin_queues
;
6220 struct pqi_event_queue
*event_queue
;
6222 admin_queues
= &ctrl_info
->admin_queues
;
6223 admin_queues
->iq_pi_copy
= 0;
6224 admin_queues
->oq_ci_copy
= 0;
6225 *admin_queues
->oq_pi
= 0;
6227 for (i
= 0; i
< ctrl_info
->num_queue_groups
; i
++) {
6228 ctrl_info
->queue_groups
[i
].iq_pi_copy
[RAID_PATH
] = 0;
6229 ctrl_info
->queue_groups
[i
].iq_pi_copy
[AIO_PATH
] = 0;
6230 ctrl_info
->queue_groups
[i
].oq_ci_copy
= 0;
6232 *ctrl_info
->queue_groups
[i
].iq_ci
[RAID_PATH
] = 0;
6233 *ctrl_info
->queue_groups
[i
].iq_ci
[AIO_PATH
] = 0;
6234 *ctrl_info
->queue_groups
[i
].oq_pi
= 0;
6237 event_queue
= &ctrl_info
->event_queue
;
6238 *event_queue
->oq_pi
= 0;
6239 event_queue
->oq_ci_copy
= 0;
6242 static int pqi_ctrl_init_resume(struct pqi_ctrl_info
*ctrl_info
)
6246 rc
= pqi_force_sis_mode(ctrl_info
);
6251 * Wait until the controller is ready to start accepting SIS
6254 rc
= sis_wait_for_ctrl_ready_resume(ctrl_info
);
6259 * If the function we are about to call succeeds, the
6260 * controller will transition from legacy SIS mode
6263 rc
= sis_init_base_struct_addr(ctrl_info
);
6265 dev_err(&ctrl_info
->pci_dev
->dev
,
6266 "error initializing PQI mode\n");
6270 /* Wait for the controller to complete the SIS -> PQI transition. */
6271 rc
= pqi_wait_for_pqi_mode_ready(ctrl_info
);
6273 dev_err(&ctrl_info
->pci_dev
->dev
,
6274 "transition to PQI mode failed\n");
6278 /* From here on, we are running in PQI mode. */
6279 ctrl_info
->pqi_mode_enabled
= true;
6280 pqi_save_ctrl_mode(ctrl_info
, PQI_MODE
);
6282 pqi_reinit_queues(ctrl_info
);
6284 rc
= pqi_create_admin_queues(ctrl_info
);
6286 dev_err(&ctrl_info
->pci_dev
->dev
,
6287 "error creating admin queues\n");
6291 rc
= pqi_create_queues(ctrl_info
);
6295 pqi_change_irq_mode(ctrl_info
, IRQ_MODE_MSIX
);
6297 ctrl_info
->controller_online
= true;
6298 pqi_start_heartbeat_timer(ctrl_info
);
6299 pqi_ctrl_unblock_requests(ctrl_info
);
6301 rc
= pqi_enable_events(ctrl_info
);
6303 dev_err(&ctrl_info
->pci_dev
->dev
,
6304 "error enabling events\n");
6308 rc
= pqi_write_driver_version_to_host_wellness(ctrl_info
);
6310 dev_err(&ctrl_info
->pci_dev
->dev
,
6311 "error updating host wellness\n");
6315 pqi_schedule_update_time_worker(ctrl_info
);
6317 pqi_scan_scsi_devices(ctrl_info
);
6322 static inline int pqi_set_pcie_completion_timeout(struct pci_dev
*pci_dev
,
6325 return pcie_capability_clear_and_set_word(pci_dev
, PCI_EXP_DEVCTL2
,
6326 PCI_EXP_DEVCTL2_COMP_TIMEOUT
, timeout
);
6329 static int pqi_pci_init(struct pqi_ctrl_info
*ctrl_info
)
6334 rc
= pci_enable_device(ctrl_info
->pci_dev
);
6336 dev_err(&ctrl_info
->pci_dev
->dev
,
6337 "failed to enable PCI device\n");
6341 if (sizeof(dma_addr_t
) > 4)
6342 mask
= DMA_BIT_MASK(64);
6344 mask
= DMA_BIT_MASK(32);
6346 rc
= dma_set_mask(&ctrl_info
->pci_dev
->dev
, mask
);
6348 dev_err(&ctrl_info
->pci_dev
->dev
, "failed to set DMA mask\n");
6349 goto disable_device
;
6352 rc
= pci_request_regions(ctrl_info
->pci_dev
, DRIVER_NAME_SHORT
);
6354 dev_err(&ctrl_info
->pci_dev
->dev
,
6355 "failed to obtain PCI resources\n");
6356 goto disable_device
;
6359 ctrl_info
->iomem_base
= ioremap_nocache(pci_resource_start(
6360 ctrl_info
->pci_dev
, 0),
6361 sizeof(struct pqi_ctrl_registers
));
6362 if (!ctrl_info
->iomem_base
) {
6363 dev_err(&ctrl_info
->pci_dev
->dev
,
6364 "failed to map memory for controller registers\n");
6366 goto release_regions
;
6369 #define PCI_EXP_COMP_TIMEOUT_65_TO_210_MS 0x6
6371 /* Increase the PCIe completion timeout. */
6372 rc
= pqi_set_pcie_completion_timeout(ctrl_info
->pci_dev
,
6373 PCI_EXP_COMP_TIMEOUT_65_TO_210_MS
);
6375 dev_err(&ctrl_info
->pci_dev
->dev
,
6376 "failed to set PCIe completion timeout\n");
6377 goto release_regions
;
6380 /* Enable bus mastering. */
6381 pci_set_master(ctrl_info
->pci_dev
);
6383 ctrl_info
->registers
= ctrl_info
->iomem_base
;
6384 ctrl_info
->pqi_registers
= &ctrl_info
->registers
->pqi_registers
;
6386 pci_set_drvdata(ctrl_info
->pci_dev
, ctrl_info
);
6391 pci_release_regions(ctrl_info
->pci_dev
);
6393 pci_disable_device(ctrl_info
->pci_dev
);
6398 static void pqi_cleanup_pci_init(struct pqi_ctrl_info
*ctrl_info
)
6400 iounmap(ctrl_info
->iomem_base
);
6401 pci_release_regions(ctrl_info
->pci_dev
);
6402 if (pci_is_enabled(ctrl_info
->pci_dev
))
6403 pci_disable_device(ctrl_info
->pci_dev
);
6404 pci_set_drvdata(ctrl_info
->pci_dev
, NULL
);
6407 static struct pqi_ctrl_info
*pqi_alloc_ctrl_info(int numa_node
)
6409 struct pqi_ctrl_info
*ctrl_info
;
6411 ctrl_info
= kzalloc_node(sizeof(struct pqi_ctrl_info
),
6412 GFP_KERNEL
, numa_node
);
6416 mutex_init(&ctrl_info
->scan_mutex
);
6417 mutex_init(&ctrl_info
->lun_reset_mutex
);
6419 INIT_LIST_HEAD(&ctrl_info
->scsi_device_list
);
6420 spin_lock_init(&ctrl_info
->scsi_device_list_lock
);
6422 INIT_WORK(&ctrl_info
->event_work
, pqi_event_worker
);
6423 atomic_set(&ctrl_info
->num_interrupts
, 0);
6425 INIT_DELAYED_WORK(&ctrl_info
->rescan_work
, pqi_rescan_worker
);
6426 INIT_DELAYED_WORK(&ctrl_info
->update_time_work
, pqi_update_time_worker
);
6428 init_timer(&ctrl_info
->heartbeat_timer
);
6429 INIT_WORK(&ctrl_info
->ctrl_offline_work
, pqi_ctrl_offline_worker
);
6431 sema_init(&ctrl_info
->sync_request_sem
,
6432 PQI_RESERVED_IO_SLOTS_SYNCHRONOUS_REQUESTS
);
6433 init_waitqueue_head(&ctrl_info
->block_requests_wait
);
6435 INIT_LIST_HEAD(&ctrl_info
->raid_bypass_retry_list
);
6436 spin_lock_init(&ctrl_info
->raid_bypass_retry_list_lock
);
6437 INIT_WORK(&ctrl_info
->raid_bypass_retry_work
,
6438 pqi_raid_bypass_retry_worker
);
6440 ctrl_info
->ctrl_id
= atomic_inc_return(&pqi_controller_count
) - 1;
6441 ctrl_info
->irq_mode
= IRQ_MODE_NONE
;
6442 ctrl_info
->max_msix_vectors
= PQI_MAX_MSIX_VECTORS
;
6447 static inline void pqi_free_ctrl_info(struct pqi_ctrl_info
*ctrl_info
)
6452 static void pqi_free_interrupts(struct pqi_ctrl_info
*ctrl_info
)
6454 pqi_free_irqs(ctrl_info
);
6455 pqi_disable_msix_interrupts(ctrl_info
);
6458 static void pqi_free_ctrl_resources(struct pqi_ctrl_info
*ctrl_info
)
6460 pqi_stop_heartbeat_timer(ctrl_info
);
6461 pqi_free_interrupts(ctrl_info
);
6462 if (ctrl_info
->queue_memory_base
)
6463 dma_free_coherent(&ctrl_info
->pci_dev
->dev
,
6464 ctrl_info
->queue_memory_length
,
6465 ctrl_info
->queue_memory_base
,
6466 ctrl_info
->queue_memory_base_dma_handle
);
6467 if (ctrl_info
->admin_queue_memory_base
)
6468 dma_free_coherent(&ctrl_info
->pci_dev
->dev
,
6469 ctrl_info
->admin_queue_memory_length
,
6470 ctrl_info
->admin_queue_memory_base
,
6471 ctrl_info
->admin_queue_memory_base_dma_handle
);
6472 pqi_free_all_io_requests(ctrl_info
);
6473 if (ctrl_info
->error_buffer
)
6474 dma_free_coherent(&ctrl_info
->pci_dev
->dev
,
6475 ctrl_info
->error_buffer_length
,
6476 ctrl_info
->error_buffer
,
6477 ctrl_info
->error_buffer_dma_handle
);
6478 if (ctrl_info
->iomem_base
)
6479 pqi_cleanup_pci_init(ctrl_info
);
6480 pqi_free_ctrl_info(ctrl_info
);
6483 static void pqi_remove_ctrl(struct pqi_ctrl_info
*ctrl_info
)
6485 pqi_cancel_rescan_worker(ctrl_info
);
6486 pqi_cancel_update_time_worker(ctrl_info
);
6487 pqi_remove_all_scsi_devices(ctrl_info
);
6488 pqi_unregister_scsi(ctrl_info
);
6489 if (ctrl_info
->pqi_mode_enabled
)
6490 pqi_revert_to_sis_mode(ctrl_info
);
6491 pqi_free_ctrl_resources(ctrl_info
);
6494 static void pqi_perform_lockup_action(void)
6496 switch (pqi_lockup_action
) {
6498 panic("FATAL: Smart Family Controller lockup detected");
6501 emergency_restart();
6509 static struct pqi_raid_error_info pqi_ctrl_offline_raid_error_info
= {
6510 .data_out_result
= PQI_DATA_IN_OUT_HARDWARE_ERROR
,
6511 .status
= SAM_STAT_CHECK_CONDITION
,
6514 static void pqi_fail_all_outstanding_requests(struct pqi_ctrl_info
*ctrl_info
)
6517 struct pqi_io_request
*io_request
;
6518 struct scsi_cmnd
*scmd
;
6520 for (i
= 0; i
< ctrl_info
->max_io_slots
; i
++) {
6521 io_request
= &ctrl_info
->io_request_pool
[i
];
6522 if (atomic_read(&io_request
->refcount
) == 0)
6525 scmd
= io_request
->scmd
;
6527 set_host_byte(scmd
, DID_NO_CONNECT
);
6529 io_request
->status
= -ENXIO
;
6530 io_request
->error_info
=
6531 &pqi_ctrl_offline_raid_error_info
;
6534 io_request
->io_complete_callback(io_request
,
6535 io_request
->context
);
6539 static void pqi_take_ctrl_offline_deferred(struct pqi_ctrl_info
*ctrl_info
)
6541 pqi_perform_lockup_action();
6542 pqi_stop_heartbeat_timer(ctrl_info
);
6543 pqi_free_interrupts(ctrl_info
);
6544 pqi_cancel_rescan_worker(ctrl_info
);
6545 pqi_cancel_update_time_worker(ctrl_info
);
6546 pqi_ctrl_wait_until_quiesced(ctrl_info
);
6547 pqi_fail_all_outstanding_requests(ctrl_info
);
6548 pqi_clear_all_queued_raid_bypass_retries(ctrl_info
);
6549 pqi_ctrl_unblock_requests(ctrl_info
);
6552 static void pqi_ctrl_offline_worker(struct work_struct
*work
)
6554 struct pqi_ctrl_info
*ctrl_info
;
6556 ctrl_info
= container_of(work
, struct pqi_ctrl_info
, ctrl_offline_work
);
6557 pqi_take_ctrl_offline_deferred(ctrl_info
);
6560 static void pqi_take_ctrl_offline(struct pqi_ctrl_info
*ctrl_info
)
6562 if (!ctrl_info
->controller_online
)
6565 ctrl_info
->controller_online
= false;
6566 ctrl_info
->pqi_mode_enabled
= false;
6567 pqi_ctrl_block_requests(ctrl_info
);
6568 if (!pqi_disable_ctrl_shutdown
)
6569 sis_shutdown_ctrl(ctrl_info
);
6570 pci_disable_device(ctrl_info
->pci_dev
);
6571 dev_err(&ctrl_info
->pci_dev
->dev
, "controller offline\n");
6572 schedule_work(&ctrl_info
->ctrl_offline_work
);
6575 static void pqi_print_ctrl_info(struct pci_dev
*pci_dev
,
6576 const struct pci_device_id
*id
)
6578 char *ctrl_description
;
6580 if (id
->driver_data
)
6581 ctrl_description
= (char *)id
->driver_data
;
6583 ctrl_description
= "Microsemi Smart Family Controller";
6585 dev_info(&pci_dev
->dev
, "%s found\n", ctrl_description
);
6588 static int pqi_pci_probe(struct pci_dev
*pci_dev
,
6589 const struct pci_device_id
*id
)
6593 struct pqi_ctrl_info
*ctrl_info
;
6595 pqi_print_ctrl_info(pci_dev
, id
);
6597 if (pqi_disable_device_id_wildcards
&&
6598 id
->subvendor
== PCI_ANY_ID
&&
6599 id
->subdevice
== PCI_ANY_ID
) {
6600 dev_warn(&pci_dev
->dev
,
6601 "controller not probed because device ID wildcards are disabled\n");
6605 if (id
->subvendor
== PCI_ANY_ID
|| id
->subdevice
== PCI_ANY_ID
)
6606 dev_warn(&pci_dev
->dev
,
6607 "controller device ID matched using wildcards\n");
6609 node
= dev_to_node(&pci_dev
->dev
);
6610 if (node
== NUMA_NO_NODE
)
6611 set_dev_node(&pci_dev
->dev
, 0);
6613 ctrl_info
= pqi_alloc_ctrl_info(node
);
6615 dev_err(&pci_dev
->dev
,
6616 "failed to allocate controller info block\n");
6620 ctrl_info
->pci_dev
= pci_dev
;
6622 rc
= pqi_pci_init(ctrl_info
);
6626 rc
= pqi_ctrl_init(ctrl_info
);
6633 pqi_remove_ctrl(ctrl_info
);
6638 static void pqi_pci_remove(struct pci_dev
*pci_dev
)
6640 struct pqi_ctrl_info
*ctrl_info
;
6642 ctrl_info
= pci_get_drvdata(pci_dev
);
6646 pqi_remove_ctrl(ctrl_info
);
6649 static void pqi_shutdown(struct pci_dev
*pci_dev
)
6652 struct pqi_ctrl_info
*ctrl_info
;
6654 ctrl_info
= pci_get_drvdata(pci_dev
);
6659 * Write all data in the controller's battery-backed cache to
6662 rc
= pqi_flush_cache(ctrl_info
);
6667 dev_warn(&pci_dev
->dev
,
6668 "unable to flush controller cache\n");
6671 static void pqi_process_lockup_action_param(void)
6675 if (!pqi_lockup_action_param
)
6678 for (i
= 0; i
< ARRAY_SIZE(pqi_lockup_actions
); i
++) {
6679 if (strcmp(pqi_lockup_action_param
,
6680 pqi_lockup_actions
[i
].name
) == 0) {
6681 pqi_lockup_action
= pqi_lockup_actions
[i
].action
;
6686 pr_warn("%s: invalid lockup action setting \"%s\" - supported settings: none, reboot, panic\n",
6687 DRIVER_NAME_SHORT
, pqi_lockup_action_param
);
6690 static void pqi_process_module_params(void)
6692 pqi_process_lockup_action_param();
6695 static __maybe_unused
int pqi_suspend(struct pci_dev
*pci_dev
, pm_message_t state
)
6697 struct pqi_ctrl_info
*ctrl_info
;
6699 ctrl_info
= pci_get_drvdata(pci_dev
);
6701 pqi_disable_events(ctrl_info
);
6702 pqi_cancel_update_time_worker(ctrl_info
);
6703 pqi_cancel_rescan_worker(ctrl_info
);
6704 pqi_wait_until_scan_finished(ctrl_info
);
6705 pqi_wait_until_lun_reset_finished(ctrl_info
);
6706 pqi_flush_cache(ctrl_info
);
6707 pqi_ctrl_block_requests(ctrl_info
);
6708 pqi_ctrl_wait_until_quiesced(ctrl_info
);
6709 pqi_wait_until_inbound_queues_empty(ctrl_info
);
6710 pqi_ctrl_wait_for_pending_io(ctrl_info
);
6711 pqi_stop_heartbeat_timer(ctrl_info
);
6713 if (state
.event
== PM_EVENT_FREEZE
)
6716 pci_save_state(pci_dev
);
6717 pci_set_power_state(pci_dev
, pci_choose_state(pci_dev
, state
));
6719 ctrl_info
->controller_online
= false;
6720 ctrl_info
->pqi_mode_enabled
= false;
6725 static __maybe_unused
int pqi_resume(struct pci_dev
*pci_dev
)
6728 struct pqi_ctrl_info
*ctrl_info
;
6730 ctrl_info
= pci_get_drvdata(pci_dev
);
6732 if (pci_dev
->current_state
!= PCI_D0
) {
6733 ctrl_info
->max_hw_queue_index
= 0;
6734 pqi_free_interrupts(ctrl_info
);
6735 pqi_change_irq_mode(ctrl_info
, IRQ_MODE_INTX
);
6736 rc
= request_irq(pci_irq_vector(pci_dev
, 0), pqi_irq_handler
,
6737 IRQF_SHARED
, DRIVER_NAME_SHORT
,
6738 &ctrl_info
->queue_groups
[0]);
6740 dev_err(&ctrl_info
->pci_dev
->dev
,
6741 "irq %u init failed with error %d\n",
6745 pqi_start_heartbeat_timer(ctrl_info
);
6746 pqi_ctrl_unblock_requests(ctrl_info
);
6750 pci_set_power_state(pci_dev
, PCI_D0
);
6751 pci_restore_state(pci_dev
);
6753 return pqi_ctrl_init_resume(ctrl_info
);
6756 /* Define the PCI IDs for the controllers that we support. */
6757 static const struct pci_device_id pqi_pci_id_table
[] = {
6759 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6763 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6767 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6771 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6775 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6779 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6780 PCI_VENDOR_ID_ADAPTEC2
, 0x0110)
6783 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6784 PCI_VENDOR_ID_ADAPTEC2
, 0x0605)
6787 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6788 PCI_VENDOR_ID_ADAPTEC2
, 0x0800)
6791 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6792 PCI_VENDOR_ID_ADAPTEC2
, 0x0801)
6795 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6796 PCI_VENDOR_ID_ADAPTEC2
, 0x0802)
6799 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6800 PCI_VENDOR_ID_ADAPTEC2
, 0x0803)
6803 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6804 PCI_VENDOR_ID_ADAPTEC2
, 0x0804)
6807 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6808 PCI_VENDOR_ID_ADAPTEC2
, 0x0805)
6811 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6812 PCI_VENDOR_ID_ADAPTEC2
, 0x0806)
6815 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6816 PCI_VENDOR_ID_ADAPTEC2
, 0x0900)
6819 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6820 PCI_VENDOR_ID_ADAPTEC2
, 0x0901)
6823 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6824 PCI_VENDOR_ID_ADAPTEC2
, 0x0902)
6827 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6828 PCI_VENDOR_ID_ADAPTEC2
, 0x0903)
6831 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6832 PCI_VENDOR_ID_ADAPTEC2
, 0x0904)
6835 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6836 PCI_VENDOR_ID_ADAPTEC2
, 0x0905)
6839 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6840 PCI_VENDOR_ID_ADAPTEC2
, 0x0906)
6843 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6844 PCI_VENDOR_ID_ADAPTEC2
, 0x0907)
6847 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6848 PCI_VENDOR_ID_ADAPTEC2
, 0x0908)
6851 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6852 PCI_VENDOR_ID_ADAPTEC2
, 0x1200)
6855 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6856 PCI_VENDOR_ID_ADAPTEC2
, 0x1201)
6859 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6860 PCI_VENDOR_ID_ADAPTEC2
, 0x1202)
6863 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6864 PCI_VENDOR_ID_ADAPTEC2
, 0x1280)
6867 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6868 PCI_VENDOR_ID_ADAPTEC2
, 0x1281)
6871 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6872 PCI_VENDOR_ID_ADAPTEC2
, 0x1300)
6875 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6876 PCI_VENDOR_ID_ADAPTEC2
, 0x1301)
6879 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6880 PCI_VENDOR_ID_ADAPTEC2
, 0x1380)
6883 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6884 PCI_VENDOR_ID_HP
, 0x0600)
6887 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6888 PCI_VENDOR_ID_HP
, 0x0601)
6891 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6892 PCI_VENDOR_ID_HP
, 0x0602)
6895 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6896 PCI_VENDOR_ID_HP
, 0x0603)
6899 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6900 PCI_VENDOR_ID_HP
, 0x0604)
6903 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6904 PCI_VENDOR_ID_HP
, 0x0606)
6907 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6908 PCI_VENDOR_ID_HP
, 0x0650)
6911 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6912 PCI_VENDOR_ID_HP
, 0x0651)
6915 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6916 PCI_VENDOR_ID_HP
, 0x0652)
6919 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6920 PCI_VENDOR_ID_HP
, 0x0653)
6923 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6924 PCI_VENDOR_ID_HP
, 0x0654)
6927 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6928 PCI_VENDOR_ID_HP
, 0x0655)
6931 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6932 PCI_VENDOR_ID_HP
, 0x0656)
6935 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6936 PCI_VENDOR_ID_HP
, 0x0657)
6939 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6940 PCI_VENDOR_ID_HP
, 0x0700)
6943 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6944 PCI_VENDOR_ID_HP
, 0x0701)
6947 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6948 PCI_VENDOR_ID_HP
, 0x1001)
6951 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6952 PCI_VENDOR_ID_HP
, 0x1100)
6955 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6956 PCI_VENDOR_ID_HP
, 0x1101)
6959 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6960 PCI_VENDOR_ID_HP
, 0x1102)
6963 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6964 PCI_VENDOR_ID_HP
, 0x1150)
6967 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2
, 0x028f,
6968 PCI_ANY_ID
, PCI_ANY_ID
)
6973 MODULE_DEVICE_TABLE(pci
, pqi_pci_id_table
);
6975 static struct pci_driver pqi_pci_driver
= {
6976 .name
= DRIVER_NAME_SHORT
,
6977 .id_table
= pqi_pci_id_table
,
6978 .probe
= pqi_pci_probe
,
6979 .remove
= pqi_pci_remove
,
6980 .shutdown
= pqi_shutdown
,
6981 #if defined(CONFIG_PM)
6982 .suspend
= pqi_suspend
,
6983 .resume
= pqi_resume
,
6987 static int __init
pqi_init(void)
6991 pr_info(DRIVER_NAME
"\n");
6993 pqi_sas_transport_template
=
6994 sas_attach_transport(&pqi_sas_transport_functions
);
6995 if (!pqi_sas_transport_template
)
6998 pqi_process_module_params();
7000 rc
= pci_register_driver(&pqi_pci_driver
);
7002 sas_release_transport(pqi_sas_transport_template
);
7007 static void __exit
pqi_cleanup(void)
7009 pci_unregister_driver(&pqi_pci_driver
);
7010 sas_release_transport(pqi_sas_transport_template
);
7013 module_init(pqi_init
);
7014 module_exit(pqi_cleanup
);
7016 static void __attribute__((unused
)) verify_structures(void)
7018 BUILD_BUG_ON(offsetof(struct pqi_ctrl_registers
,
7019 sis_host_to_ctrl_doorbell
) != 0x20);
7020 BUILD_BUG_ON(offsetof(struct pqi_ctrl_registers
,
7021 sis_interrupt_mask
) != 0x34);
7022 BUILD_BUG_ON(offsetof(struct pqi_ctrl_registers
,
7023 sis_ctrl_to_host_doorbell
) != 0x9c);
7024 BUILD_BUG_ON(offsetof(struct pqi_ctrl_registers
,
7025 sis_ctrl_to_host_doorbell_clear
) != 0xa0);
7026 BUILD_BUG_ON(offsetof(struct pqi_ctrl_registers
,
7027 sis_driver_scratch
) != 0xb0);
7028 BUILD_BUG_ON(offsetof(struct pqi_ctrl_registers
,
7029 sis_firmware_status
) != 0xbc);
7030 BUILD_BUG_ON(offsetof(struct pqi_ctrl_registers
,
7031 sis_mailbox
) != 0x1000);
7032 BUILD_BUG_ON(offsetof(struct pqi_ctrl_registers
,
7033 pqi_registers
) != 0x4000);
7035 BUILD_BUG_ON(offsetof(struct pqi_iu_header
,
7037 BUILD_BUG_ON(offsetof(struct pqi_iu_header
,
7039 BUILD_BUG_ON(offsetof(struct pqi_iu_header
,
7040 response_queue_id
) != 0x4);
7041 BUILD_BUG_ON(offsetof(struct pqi_iu_header
,
7043 BUILD_BUG_ON(sizeof(struct pqi_iu_header
) != 0x8);
7045 BUILD_BUG_ON(offsetof(struct pqi_aio_error_info
,
7047 BUILD_BUG_ON(offsetof(struct pqi_aio_error_info
,
7048 service_response
) != 0x1);
7049 BUILD_BUG_ON(offsetof(struct pqi_aio_error_info
,
7050 data_present
) != 0x2);
7051 BUILD_BUG_ON(offsetof(struct pqi_aio_error_info
,
7053 BUILD_BUG_ON(offsetof(struct pqi_aio_error_info
,
7054 residual_count
) != 0x4);
7055 BUILD_BUG_ON(offsetof(struct pqi_aio_error_info
,
7056 data_length
) != 0x8);
7057 BUILD_BUG_ON(offsetof(struct pqi_aio_error_info
,
7059 BUILD_BUG_ON(offsetof(struct pqi_aio_error_info
,
7061 BUILD_BUG_ON(sizeof(struct pqi_aio_error_info
) != 0x10c);
7063 BUILD_BUG_ON(offsetof(struct pqi_raid_error_info
,
7064 data_in_result
) != 0x0);
7065 BUILD_BUG_ON(offsetof(struct pqi_raid_error_info
,
7066 data_out_result
) != 0x1);
7067 BUILD_BUG_ON(offsetof(struct pqi_raid_error_info
,
7069 BUILD_BUG_ON(offsetof(struct pqi_raid_error_info
,
7071 BUILD_BUG_ON(offsetof(struct pqi_raid_error_info
,
7072 status_qualifier
) != 0x6);
7073 BUILD_BUG_ON(offsetof(struct pqi_raid_error_info
,
7074 sense_data_length
) != 0x8);
7075 BUILD_BUG_ON(offsetof(struct pqi_raid_error_info
,
7076 response_data_length
) != 0xa);
7077 BUILD_BUG_ON(offsetof(struct pqi_raid_error_info
,
7078 data_in_transferred
) != 0xc);
7079 BUILD_BUG_ON(offsetof(struct pqi_raid_error_info
,
7080 data_out_transferred
) != 0x10);
7081 BUILD_BUG_ON(offsetof(struct pqi_raid_error_info
,
7083 BUILD_BUG_ON(sizeof(struct pqi_raid_error_info
) != 0x114);
7085 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
7087 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
7088 function_and_status_code
) != 0x8);
7089 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
7090 max_admin_iq_elements
) != 0x10);
7091 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
7092 max_admin_oq_elements
) != 0x11);
7093 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
7094 admin_iq_element_length
) != 0x12);
7095 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
7096 admin_oq_element_length
) != 0x13);
7097 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
7098 max_reset_timeout
) != 0x14);
7099 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
7100 legacy_intx_status
) != 0x18);
7101 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
7102 legacy_intx_mask_set
) != 0x1c);
7103 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
7104 legacy_intx_mask_clear
) != 0x20);
7105 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
7106 device_status
) != 0x40);
7107 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
7108 admin_iq_pi_offset
) != 0x48);
7109 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
7110 admin_oq_ci_offset
) != 0x50);
7111 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
7112 admin_iq_element_array_addr
) != 0x58);
7113 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
7114 admin_oq_element_array_addr
) != 0x60);
7115 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
7116 admin_iq_ci_addr
) != 0x68);
7117 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
7118 admin_oq_pi_addr
) != 0x70);
7119 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
7120 admin_iq_num_elements
) != 0x78);
7121 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
7122 admin_oq_num_elements
) != 0x79);
7123 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
7124 admin_queue_int_msg_num
) != 0x7a);
7125 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
7126 device_error
) != 0x80);
7127 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
7128 error_details
) != 0x88);
7129 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
7130 device_reset
) != 0x90);
7131 BUILD_BUG_ON(offsetof(struct pqi_device_registers
,
7132 power_action
) != 0x94);
7133 BUILD_BUG_ON(sizeof(struct pqi_device_registers
) != 0x100);
7135 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
7136 header
.iu_type
) != 0);
7137 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
7138 header
.iu_length
) != 2);
7139 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
7140 header
.work_area
) != 6);
7141 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
7143 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
7144 function_code
) != 10);
7145 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
7146 data
.report_device_capability
.buffer_length
) != 44);
7147 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
7148 data
.report_device_capability
.sg_descriptor
) != 48);
7149 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
7150 data
.create_operational_iq
.queue_id
) != 12);
7151 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
7152 data
.create_operational_iq
.element_array_addr
) != 16);
7153 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
7154 data
.create_operational_iq
.ci_addr
) != 24);
7155 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
7156 data
.create_operational_iq
.num_elements
) != 32);
7157 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
7158 data
.create_operational_iq
.element_length
) != 34);
7159 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
7160 data
.create_operational_iq
.queue_protocol
) != 36);
7161 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
7162 data
.create_operational_oq
.queue_id
) != 12);
7163 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
7164 data
.create_operational_oq
.element_array_addr
) != 16);
7165 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
7166 data
.create_operational_oq
.pi_addr
) != 24);
7167 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
7168 data
.create_operational_oq
.num_elements
) != 32);
7169 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
7170 data
.create_operational_oq
.element_length
) != 34);
7171 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
7172 data
.create_operational_oq
.queue_protocol
) != 36);
7173 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
7174 data
.create_operational_oq
.int_msg_num
) != 40);
7175 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
7176 data
.create_operational_oq
.coalescing_count
) != 42);
7177 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
7178 data
.create_operational_oq
.min_coalescing_time
) != 44);
7179 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
7180 data
.create_operational_oq
.max_coalescing_time
) != 48);
7181 BUILD_BUG_ON(offsetof(struct pqi_general_admin_request
,
7182 data
.delete_operational_queue
.queue_id
) != 12);
7183 BUILD_BUG_ON(sizeof(struct pqi_general_admin_request
) != 64);
7184 BUILD_BUG_ON(FIELD_SIZEOF(struct pqi_general_admin_request
,
7185 data
.create_operational_iq
) != 64 - 11);
7186 BUILD_BUG_ON(FIELD_SIZEOF(struct pqi_general_admin_request
,
7187 data
.create_operational_oq
) != 64 - 11);
7188 BUILD_BUG_ON(FIELD_SIZEOF(struct pqi_general_admin_request
,
7189 data
.delete_operational_queue
) != 64 - 11);
7191 BUILD_BUG_ON(offsetof(struct pqi_general_admin_response
,
7192 header
.iu_type
) != 0);
7193 BUILD_BUG_ON(offsetof(struct pqi_general_admin_response
,
7194 header
.iu_length
) != 2);
7195 BUILD_BUG_ON(offsetof(struct pqi_general_admin_response
,
7196 header
.work_area
) != 6);
7197 BUILD_BUG_ON(offsetof(struct pqi_general_admin_response
,
7199 BUILD_BUG_ON(offsetof(struct pqi_general_admin_response
,
7200 function_code
) != 10);
7201 BUILD_BUG_ON(offsetof(struct pqi_general_admin_response
,
7203 BUILD_BUG_ON(offsetof(struct pqi_general_admin_response
,
7204 data
.create_operational_iq
.status_descriptor
) != 12);
7205 BUILD_BUG_ON(offsetof(struct pqi_general_admin_response
,
7206 data
.create_operational_iq
.iq_pi_offset
) != 16);
7207 BUILD_BUG_ON(offsetof(struct pqi_general_admin_response
,
7208 data
.create_operational_oq
.status_descriptor
) != 12);
7209 BUILD_BUG_ON(offsetof(struct pqi_general_admin_response
,
7210 data
.create_operational_oq
.oq_ci_offset
) != 16);
7211 BUILD_BUG_ON(sizeof(struct pqi_general_admin_response
) != 64);
7213 BUILD_BUG_ON(offsetof(struct pqi_raid_path_request
,
7214 header
.iu_type
) != 0);
7215 BUILD_BUG_ON(offsetof(struct pqi_raid_path_request
,
7216 header
.iu_length
) != 2);
7217 BUILD_BUG_ON(offsetof(struct pqi_raid_path_request
,
7218 header
.response_queue_id
) != 4);
7219 BUILD_BUG_ON(offsetof(struct pqi_raid_path_request
,
7220 header
.work_area
) != 6);
7221 BUILD_BUG_ON(offsetof(struct pqi_raid_path_request
,
7223 BUILD_BUG_ON(offsetof(struct pqi_raid_path_request
,
7225 BUILD_BUG_ON(offsetof(struct pqi_raid_path_request
,
7226 buffer_length
) != 12);
7227 BUILD_BUG_ON(offsetof(struct pqi_raid_path_request
,
7229 BUILD_BUG_ON(offsetof(struct pqi_raid_path_request
,
7230 protocol_specific
) != 24);
7231 BUILD_BUG_ON(offsetof(struct pqi_raid_path_request
,
7232 error_index
) != 27);
7233 BUILD_BUG_ON(offsetof(struct pqi_raid_path_request
,
7235 BUILD_BUG_ON(offsetof(struct pqi_raid_path_request
,
7236 sg_descriptors
) != 64);
7237 BUILD_BUG_ON(sizeof(struct pqi_raid_path_request
) !=
7238 PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
);
7240 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
7241 header
.iu_type
) != 0);
7242 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
7243 header
.iu_length
) != 2);
7244 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
7245 header
.response_queue_id
) != 4);
7246 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
7247 header
.work_area
) != 6);
7248 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
7250 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
7252 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
7253 buffer_length
) != 16);
7254 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
7255 data_encryption_key_index
) != 22);
7256 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
7257 encrypt_tweak_lower
) != 24);
7258 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
7259 encrypt_tweak_upper
) != 28);
7260 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
7262 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
7263 error_index
) != 48);
7264 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
7265 num_sg_descriptors
) != 50);
7266 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
7268 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
7270 BUILD_BUG_ON(offsetof(struct pqi_aio_path_request
,
7271 sg_descriptors
) != 64);
7272 BUILD_BUG_ON(sizeof(struct pqi_aio_path_request
) !=
7273 PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
);
7275 BUILD_BUG_ON(offsetof(struct pqi_io_response
,
7276 header
.iu_type
) != 0);
7277 BUILD_BUG_ON(offsetof(struct pqi_io_response
,
7278 header
.iu_length
) != 2);
7279 BUILD_BUG_ON(offsetof(struct pqi_io_response
,
7281 BUILD_BUG_ON(offsetof(struct pqi_io_response
,
7282 error_index
) != 10);
7284 BUILD_BUG_ON(offsetof(struct pqi_general_management_request
,
7285 header
.iu_type
) != 0);
7286 BUILD_BUG_ON(offsetof(struct pqi_general_management_request
,
7287 header
.iu_length
) != 2);
7288 BUILD_BUG_ON(offsetof(struct pqi_general_management_request
,
7289 header
.response_queue_id
) != 4);
7290 BUILD_BUG_ON(offsetof(struct pqi_general_management_request
,
7292 BUILD_BUG_ON(offsetof(struct pqi_general_management_request
,
7293 data
.report_event_configuration
.buffer_length
) != 12);
7294 BUILD_BUG_ON(offsetof(struct pqi_general_management_request
,
7295 data
.report_event_configuration
.sg_descriptors
) != 16);
7296 BUILD_BUG_ON(offsetof(struct pqi_general_management_request
,
7297 data
.set_event_configuration
.global_event_oq_id
) != 10);
7298 BUILD_BUG_ON(offsetof(struct pqi_general_management_request
,
7299 data
.set_event_configuration
.buffer_length
) != 12);
7300 BUILD_BUG_ON(offsetof(struct pqi_general_management_request
,
7301 data
.set_event_configuration
.sg_descriptors
) != 16);
7303 BUILD_BUG_ON(offsetof(struct pqi_iu_layer_descriptor
,
7304 max_inbound_iu_length
) != 6);
7305 BUILD_BUG_ON(offsetof(struct pqi_iu_layer_descriptor
,
7306 max_outbound_iu_length
) != 14);
7307 BUILD_BUG_ON(sizeof(struct pqi_iu_layer_descriptor
) != 16);
7309 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
7311 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
7312 iq_arbitration_priority_support_bitmask
) != 8);
7313 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
7314 maximum_aw_a
) != 9);
7315 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
7316 maximum_aw_b
) != 10);
7317 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
7318 maximum_aw_c
) != 11);
7319 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
7320 max_inbound_queues
) != 16);
7321 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
7322 max_elements_per_iq
) != 18);
7323 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
7324 max_iq_element_length
) != 24);
7325 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
7326 min_iq_element_length
) != 26);
7327 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
7328 max_outbound_queues
) != 30);
7329 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
7330 max_elements_per_oq
) != 32);
7331 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
7332 intr_coalescing_time_granularity
) != 34);
7333 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
7334 max_oq_element_length
) != 36);
7335 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
7336 min_oq_element_length
) != 38);
7337 BUILD_BUG_ON(offsetof(struct pqi_device_capability
,
7338 iu_layer_descriptors
) != 64);
7339 BUILD_BUG_ON(sizeof(struct pqi_device_capability
) != 576);
7341 BUILD_BUG_ON(offsetof(struct pqi_event_descriptor
,
7343 BUILD_BUG_ON(offsetof(struct pqi_event_descriptor
,
7345 BUILD_BUG_ON(sizeof(struct pqi_event_descriptor
) != 4);
7347 BUILD_BUG_ON(offsetof(struct pqi_event_config
,
7348 num_event_descriptors
) != 2);
7349 BUILD_BUG_ON(offsetof(struct pqi_event_config
,
7352 BUILD_BUG_ON(PQI_NUM_SUPPORTED_EVENTS
!=
7353 ARRAY_SIZE(pqi_supported_event_types
));
7355 BUILD_BUG_ON(offsetof(struct pqi_event_response
,
7356 header
.iu_type
) != 0);
7357 BUILD_BUG_ON(offsetof(struct pqi_event_response
,
7358 header
.iu_length
) != 2);
7359 BUILD_BUG_ON(offsetof(struct pqi_event_response
,
7361 BUILD_BUG_ON(offsetof(struct pqi_event_response
,
7363 BUILD_BUG_ON(offsetof(struct pqi_event_response
,
7364 additional_event_id
) != 12);
7365 BUILD_BUG_ON(offsetof(struct pqi_event_response
,
7367 BUILD_BUG_ON(sizeof(struct pqi_event_response
) != 32);
7369 BUILD_BUG_ON(offsetof(struct pqi_event_acknowledge_request
,
7370 header
.iu_type
) != 0);
7371 BUILD_BUG_ON(offsetof(struct pqi_event_acknowledge_request
,
7372 header
.iu_length
) != 2);
7373 BUILD_BUG_ON(offsetof(struct pqi_event_acknowledge_request
,
7375 BUILD_BUG_ON(offsetof(struct pqi_event_acknowledge_request
,
7377 BUILD_BUG_ON(offsetof(struct pqi_event_acknowledge_request
,
7378 additional_event_id
) != 12);
7379 BUILD_BUG_ON(sizeof(struct pqi_event_acknowledge_request
) != 16);
7381 BUILD_BUG_ON(offsetof(struct pqi_task_management_request
,
7382 header
.iu_type
) != 0);
7383 BUILD_BUG_ON(offsetof(struct pqi_task_management_request
,
7384 header
.iu_length
) != 2);
7385 BUILD_BUG_ON(offsetof(struct pqi_task_management_request
,
7387 BUILD_BUG_ON(offsetof(struct pqi_task_management_request
,
7389 BUILD_BUG_ON(offsetof(struct pqi_task_management_request
,
7391 BUILD_BUG_ON(offsetof(struct pqi_task_management_request
,
7392 protocol_specific
) != 24);
7393 BUILD_BUG_ON(offsetof(struct pqi_task_management_request
,
7394 outbound_queue_id_to_manage
) != 26);
7395 BUILD_BUG_ON(offsetof(struct pqi_task_management_request
,
7396 request_id_to_manage
) != 28);
7397 BUILD_BUG_ON(offsetof(struct pqi_task_management_request
,
7398 task_management_function
) != 30);
7399 BUILD_BUG_ON(sizeof(struct pqi_task_management_request
) != 32);
7401 BUILD_BUG_ON(offsetof(struct pqi_task_management_response
,
7402 header
.iu_type
) != 0);
7403 BUILD_BUG_ON(offsetof(struct pqi_task_management_response
,
7404 header
.iu_length
) != 2);
7405 BUILD_BUG_ON(offsetof(struct pqi_task_management_response
,
7407 BUILD_BUG_ON(offsetof(struct pqi_task_management_response
,
7409 BUILD_BUG_ON(offsetof(struct pqi_task_management_response
,
7410 additional_response_info
) != 12);
7411 BUILD_BUG_ON(offsetof(struct pqi_task_management_response
,
7412 response_code
) != 15);
7413 BUILD_BUG_ON(sizeof(struct pqi_task_management_response
) != 16);
7415 BUILD_BUG_ON(offsetof(struct bmic_identify_controller
,
7416 configured_logical_drive_count
) != 0);
7417 BUILD_BUG_ON(offsetof(struct bmic_identify_controller
,
7418 configuration_signature
) != 1);
7419 BUILD_BUG_ON(offsetof(struct bmic_identify_controller
,
7420 firmware_version
) != 5);
7421 BUILD_BUG_ON(offsetof(struct bmic_identify_controller
,
7422 extended_logical_unit_count
) != 154);
7423 BUILD_BUG_ON(offsetof(struct bmic_identify_controller
,
7424 firmware_build_number
) != 190);
7425 BUILD_BUG_ON(offsetof(struct bmic_identify_controller
,
7426 controller_mode
) != 292);
7428 BUILD_BUG_ON(offsetof(struct bmic_identify_physical_device
,
7429 phys_bay_in_box
) != 115);
7430 BUILD_BUG_ON(offsetof(struct bmic_identify_physical_device
,
7431 device_type
) != 120);
7432 BUILD_BUG_ON(offsetof(struct bmic_identify_physical_device
,
7433 redundant_path_present_map
) != 1736);
7434 BUILD_BUG_ON(offsetof(struct bmic_identify_physical_device
,
7435 active_path_number
) != 1738);
7436 BUILD_BUG_ON(offsetof(struct bmic_identify_physical_device
,
7437 alternate_paths_phys_connector
) != 1739);
7438 BUILD_BUG_ON(offsetof(struct bmic_identify_physical_device
,
7439 alternate_paths_phys_box_on_port
) != 1755);
7440 BUILD_BUG_ON(offsetof(struct bmic_identify_physical_device
,
7441 current_queue_depth_limit
) != 1796);
7442 BUILD_BUG_ON(sizeof(struct bmic_identify_physical_device
) != 2560);
7444 BUILD_BUG_ON(PQI_ADMIN_IQ_NUM_ELEMENTS
> 255);
7445 BUILD_BUG_ON(PQI_ADMIN_OQ_NUM_ELEMENTS
> 255);
7446 BUILD_BUG_ON(PQI_ADMIN_IQ_ELEMENT_LENGTH
%
7447 PQI_QUEUE_ELEMENT_LENGTH_ALIGNMENT
!= 0);
7448 BUILD_BUG_ON(PQI_ADMIN_OQ_ELEMENT_LENGTH
%
7449 PQI_QUEUE_ELEMENT_LENGTH_ALIGNMENT
!= 0);
7450 BUILD_BUG_ON(PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
> 1048560);
7451 BUILD_BUG_ON(PQI_OPERATIONAL_IQ_ELEMENT_LENGTH
%
7452 PQI_QUEUE_ELEMENT_LENGTH_ALIGNMENT
!= 0);
7453 BUILD_BUG_ON(PQI_OPERATIONAL_OQ_ELEMENT_LENGTH
> 1048560);
7454 BUILD_BUG_ON(PQI_OPERATIONAL_OQ_ELEMENT_LENGTH
%
7455 PQI_QUEUE_ELEMENT_LENGTH_ALIGNMENT
!= 0);
7457 BUILD_BUG_ON(PQI_RESERVED_IO_SLOTS
>= PQI_MAX_OUTSTANDING_REQUESTS
);
7458 BUILD_BUG_ON(PQI_RESERVED_IO_SLOTS
>=
7459 PQI_MAX_OUTSTANDING_REQUESTS_KDUMP
);