Commit | Line | Data |
---|---|---|
2cc37b15 | 1 | // SPDX-License-Identifier: GPL-2.0 |
6c223761 KB |
2 | /* |
3 | * driver for Microsemi PQI-based storage controllers | |
2f4c4b92 DB |
4 | * Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries |
5 | * Copyright (c) 2016-2018 Microsemi Corporation | |
6c223761 KB |
6 | * Copyright (c) 2016 PMC-Sierra, Inc. |
7 | * | |
2f4c4b92 | 8 | * Questions/Comments/Bugfixes to storagedev@microchip.com |
6c223761 KB |
9 | * |
10 | */ | |
11 | ||
12 | #include <linux/module.h> | |
13 | #include <linux/kernel.h> | |
14 | #include <linux/pci.h> | |
15 | #include <linux/delay.h> | |
16 | #include <linux/interrupt.h> | |
17 | #include <linux/sched.h> | |
18 | #include <linux/rtc.h> | |
19 | #include <linux/bcd.h> | |
3c50976f | 20 | #include <linux/reboot.h> |
6c223761 | 21 | #include <linux/cciss_ioctl.h> |
52198226 | 22 | #include <linux/blk-mq-pci.h> |
6c223761 KB |
23 | #include <scsi/scsi_host.h> |
24 | #include <scsi/scsi_cmnd.h> | |
25 | #include <scsi/scsi_device.h> | |
26 | #include <scsi/scsi_eh.h> | |
27 | #include <scsi/scsi_transport_sas.h> | |
28 | #include <asm/unaligned.h> | |
29 | #include "smartpqi.h" | |
30 | #include "smartpqi_sis.h" | |
31 | ||
32 | #if !defined(BUILD_TIMESTAMP) | |
33 | #define BUILD_TIMESTAMP | |
34 | #endif | |
35 | ||
390e2808 | 36 | #define DRIVER_VERSION "1.2.10-025" |
2d154f5f | 37 | #define DRIVER_MAJOR 1 |
f7cb8ac6 | 38 | #define DRIVER_MINOR 2 |
390e2808 DB |
39 | #define DRIVER_RELEASE 10 |
40 | #define DRIVER_REVISION 25 | |
6c223761 | 41 | |
2d154f5f KB |
42 | #define DRIVER_NAME "Microsemi PQI Driver (v" \ |
43 | DRIVER_VERSION BUILD_TIMESTAMP ")" | |
6c223761 KB |
44 | #define DRIVER_NAME_SHORT "smartpqi" |
45 | ||
e1d213bd KB |
46 | #define PQI_EXTRA_SGL_MEMORY (12 * sizeof(struct pqi_sg_descriptor)) |
47 | ||
6c223761 KB |
48 | MODULE_AUTHOR("Microsemi"); |
49 | MODULE_DESCRIPTION("Driver for Microsemi Smart Family Controller version " | |
50 | DRIVER_VERSION); | |
51 | MODULE_SUPPORTED_DEVICE("Microsemi Smart Family Controllers"); | |
52 | MODULE_VERSION(DRIVER_VERSION); | |
53 | MODULE_LICENSE("GPL"); | |
54 | ||
6c223761 | 55 | static void pqi_take_ctrl_offline(struct pqi_ctrl_info *ctrl_info); |
5f310425 | 56 | static void pqi_ctrl_offline_worker(struct work_struct *work); |
376fb880 | 57 | static void pqi_retry_raid_bypass_requests(struct pqi_ctrl_info *ctrl_info); |
6c223761 KB |
58 | static int pqi_scan_scsi_devices(struct pqi_ctrl_info *ctrl_info); |
59 | static void pqi_scan_start(struct Scsi_Host *shost); | |
60 | static void pqi_start_io(struct pqi_ctrl_info *ctrl_info, | |
61 | struct pqi_queue_group *queue_group, enum pqi_io_path path, | |
62 | struct pqi_io_request *io_request); | |
63 | static int pqi_submit_raid_request_synchronous(struct pqi_ctrl_info *ctrl_info, | |
64 | struct pqi_iu_header *request, unsigned int flags, | |
65 | struct pqi_raid_error_info *error_info, unsigned long timeout_msecs); | |
66 | static int pqi_aio_submit_io(struct pqi_ctrl_info *ctrl_info, | |
67 | struct scsi_cmnd *scmd, u32 aio_handle, u8 *cdb, | |
68 | unsigned int cdb_length, struct pqi_queue_group *queue_group, | |
376fb880 | 69 | struct pqi_encryption_info *encryption_info, bool raid_bypass); |
4fd22c13 MR |
70 | static void pqi_ofa_ctrl_quiesce(struct pqi_ctrl_info *ctrl_info); |
71 | static void pqi_ofa_ctrl_unquiesce(struct pqi_ctrl_info *ctrl_info); | |
72 | static int pqi_ofa_ctrl_restart(struct pqi_ctrl_info *ctrl_info); | |
73 | static void pqi_ofa_setup_host_buffer(struct pqi_ctrl_info *ctrl_info, | |
74 | u32 bytes_requested); | |
75 | static void pqi_ofa_free_host_buffer(struct pqi_ctrl_info *ctrl_info); | |
76 | static int pqi_ofa_host_memory_update(struct pqi_ctrl_info *ctrl_info); | |
1e46731e MR |
77 | static int pqi_device_wait_for_pending_io(struct pqi_ctrl_info *ctrl_info, |
78 | struct pqi_scsi_dev *device, unsigned long timeout_secs); | |
6c223761 KB |
79 | |
80 | /* for flags argument to pqi_submit_raid_request_synchronous() */ | |
81 | #define PQI_SYNC_FLAGS_INTERRUPTABLE 0x1 | |
82 | ||
83 | static struct scsi_transport_template *pqi_sas_transport_template; | |
84 | ||
85 | static atomic_t pqi_controller_count = ATOMIC_INIT(0); | |
86 | ||
3c50976f KB |
87 | enum pqi_lockup_action { |
88 | NONE, | |
89 | REBOOT, | |
90 | PANIC | |
91 | }; | |
92 | ||
93 | static enum pqi_lockup_action pqi_lockup_action = NONE; | |
94 | ||
95 | static struct { | |
96 | enum pqi_lockup_action action; | |
97 | char *name; | |
98 | } pqi_lockup_actions[] = { | |
99 | { | |
100 | .action = NONE, | |
101 | .name = "none", | |
102 | }, | |
103 | { | |
104 | .action = REBOOT, | |
105 | .name = "reboot", | |
106 | }, | |
107 | { | |
108 | .action = PANIC, | |
109 | .name = "panic", | |
110 | }, | |
111 | }; | |
112 | ||
6a50d6ad KB |
113 | static unsigned int pqi_supported_event_types[] = { |
114 | PQI_EVENT_TYPE_HOTPLUG, | |
115 | PQI_EVENT_TYPE_HARDWARE, | |
116 | PQI_EVENT_TYPE_PHYSICAL_DEVICE, | |
117 | PQI_EVENT_TYPE_LOGICAL_DEVICE, | |
4fd22c13 | 118 | PQI_EVENT_TYPE_OFA, |
6a50d6ad KB |
119 | PQI_EVENT_TYPE_AIO_STATE_CHANGE, |
120 | PQI_EVENT_TYPE_AIO_CONFIG_CHANGE, | |
121 | }; | |
122 | ||
6c223761 KB |
123 | static int pqi_disable_device_id_wildcards; |
124 | module_param_named(disable_device_id_wildcards, | |
cbe0c7b1 | 125 | pqi_disable_device_id_wildcards, int, 0644); |
6c223761 KB |
126 | MODULE_PARM_DESC(disable_device_id_wildcards, |
127 | "Disable device ID wildcards."); | |
128 | ||
5a259e32 KB |
129 | static int pqi_disable_heartbeat; |
130 | module_param_named(disable_heartbeat, | |
131 | pqi_disable_heartbeat, int, 0644); | |
132 | MODULE_PARM_DESC(disable_heartbeat, | |
133 | "Disable heartbeat."); | |
134 | ||
135 | static int pqi_disable_ctrl_shutdown; | |
136 | module_param_named(disable_ctrl_shutdown, | |
137 | pqi_disable_ctrl_shutdown, int, 0644); | |
138 | MODULE_PARM_DESC(disable_ctrl_shutdown, | |
139 | "Disable controller shutdown when controller locked up."); | |
140 | ||
3c50976f KB |
141 | static char *pqi_lockup_action_param; |
142 | module_param_named(lockup_action, | |
143 | pqi_lockup_action_param, charp, 0644); | |
144 | MODULE_PARM_DESC(lockup_action, "Action to take when controller locked up.\n" | |
145 | "\t\tSupported: none, reboot, panic\n" | |
146 | "\t\tDefault: none"); | |
147 | ||
5e6a9760 GW |
148 | static int pqi_expose_ld_first; |
149 | module_param_named(expose_ld_first, | |
150 | pqi_expose_ld_first, int, 0644); | |
151 | MODULE_PARM_DESC(expose_ld_first, | |
152 | "Expose logical drives before physical drives."); | |
153 | ||
522bc026 DC |
154 | static int pqi_hide_vsep; |
155 | module_param_named(hide_vsep, | |
156 | pqi_hide_vsep, int, 0644); | |
157 | MODULE_PARM_DESC(hide_vsep, | |
158 | "Hide the virtual SEP for direct attached drives."); | |
159 | ||
6c223761 KB |
160 | static char *raid_levels[] = { |
161 | "RAID-0", | |
162 | "RAID-4", | |
163 | "RAID-1(1+0)", | |
164 | "RAID-5", | |
165 | "RAID-5+1", | |
166 | "RAID-ADG", | |
167 | "RAID-1(ADM)", | |
168 | }; | |
169 | ||
170 | static char *pqi_raid_level_to_string(u8 raid_level) | |
171 | { | |
172 | if (raid_level < ARRAY_SIZE(raid_levels)) | |
173 | return raid_levels[raid_level]; | |
174 | ||
a9f93392 | 175 | return "RAID UNKNOWN"; |
6c223761 KB |
176 | } |
177 | ||
178 | #define SA_RAID_0 0 | |
179 | #define SA_RAID_4 1 | |
180 | #define SA_RAID_1 2 /* also used for RAID 10 */ | |
181 | #define SA_RAID_5 3 /* also used for RAID 50 */ | |
182 | #define SA_RAID_51 4 | |
183 | #define SA_RAID_6 5 /* also used for RAID 60 */ | |
184 | #define SA_RAID_ADM 6 /* also used for RAID 1+0 ADM */ | |
185 | #define SA_RAID_MAX SA_RAID_ADM | |
186 | #define SA_RAID_UNKNOWN 0xff | |
187 | ||
188 | static inline void pqi_scsi_done(struct scsi_cmnd *scmd) | |
189 | { | |
7561a7e4 | 190 | pqi_prep_for_scsi_done(scmd); |
6c223761 KB |
191 | scmd->scsi_done(scmd); |
192 | } | |
193 | ||
b6e2ef67 | 194 | static inline void pqi_disable_write_same(struct scsi_device *sdev) |
6c223761 | 195 | { |
b6e2ef67 | 196 | sdev->no_write_same = 1; |
6c223761 KB |
197 | } |
198 | ||
6c223761 | 199 | static inline bool pqi_scsi3addr_equal(u8 *scsi3addr1, u8 *scsi3addr2) |
6c223761 | 200 | { |
6c223761 | 201 | return memcmp(scsi3addr1, scsi3addr2, 8) == 0; |
6c223761 KB |
202 | } |
203 | ||
204 | static inline bool pqi_is_logical_device(struct pqi_scsi_dev *device) | |
205 | { | |
206 | return !device->is_physical_device; | |
207 | } | |
208 | ||
bd10cf0b KB |
209 | static inline bool pqi_is_external_raid_addr(u8 *scsi3addr) |
210 | { | |
211 | return scsi3addr[2] != 0; | |
212 | } | |
213 | ||
694c5d5b KB |
214 | static inline bool pqi_ctrl_offline(struct pqi_ctrl_info *ctrl_info) |
215 | { | |
216 | return !ctrl_info->controller_online; | |
217 | } | |
218 | ||
6c223761 KB |
219 | static inline void pqi_check_ctrl_health(struct pqi_ctrl_info *ctrl_info) |
220 | { | |
221 | if (ctrl_info->controller_online) | |
222 | if (!sis_is_firmware_running(ctrl_info)) | |
223 | pqi_take_ctrl_offline(ctrl_info); | |
224 | } | |
225 | ||
226 | static inline bool pqi_is_hba_lunid(u8 *scsi3addr) | |
227 | { | |
228 | return pqi_scsi3addr_equal(scsi3addr, RAID_CTLR_LUNID); | |
229 | } | |
230 | ||
ff6abb73 KB |
231 | static inline enum pqi_ctrl_mode pqi_get_ctrl_mode( |
232 | struct pqi_ctrl_info *ctrl_info) | |
233 | { | |
234 | return sis_read_driver_scratch(ctrl_info); | |
235 | } | |
236 | ||
237 | static inline void pqi_save_ctrl_mode(struct pqi_ctrl_info *ctrl_info, | |
238 | enum pqi_ctrl_mode mode) | |
239 | { | |
240 | sis_write_driver_scratch(ctrl_info, mode); | |
241 | } | |
242 | ||
694c5d5b KB |
243 | static inline void pqi_ctrl_block_device_reset(struct pqi_ctrl_info *ctrl_info) |
244 | { | |
245 | ctrl_info->block_device_reset = true; | |
246 | } | |
247 | ||
248 | static inline bool pqi_device_reset_blocked(struct pqi_ctrl_info *ctrl_info) | |
249 | { | |
250 | return ctrl_info->block_device_reset; | |
251 | } | |
252 | ||
253 | static inline bool pqi_ctrl_blocked(struct pqi_ctrl_info *ctrl_info) | |
254 | { | |
255 | return ctrl_info->block_requests; | |
256 | } | |
257 | ||
7561a7e4 KB |
258 | static inline void pqi_ctrl_block_requests(struct pqi_ctrl_info *ctrl_info) |
259 | { | |
260 | ctrl_info->block_requests = true; | |
261 | scsi_block_requests(ctrl_info->scsi_host); | |
262 | } | |
263 | ||
264 | static inline void pqi_ctrl_unblock_requests(struct pqi_ctrl_info *ctrl_info) | |
265 | { | |
266 | ctrl_info->block_requests = false; | |
267 | wake_up_all(&ctrl_info->block_requests_wait); | |
376fb880 | 268 | pqi_retry_raid_bypass_requests(ctrl_info); |
7561a7e4 KB |
269 | scsi_unblock_requests(ctrl_info->scsi_host); |
270 | } | |
271 | ||
7561a7e4 KB |
272 | static unsigned long pqi_wait_if_ctrl_blocked(struct pqi_ctrl_info *ctrl_info, |
273 | unsigned long timeout_msecs) | |
274 | { | |
275 | unsigned long remaining_msecs; | |
276 | ||
277 | if (!pqi_ctrl_blocked(ctrl_info)) | |
278 | return timeout_msecs; | |
279 | ||
280 | atomic_inc(&ctrl_info->num_blocked_threads); | |
281 | ||
282 | if (timeout_msecs == NO_TIMEOUT) { | |
283 | wait_event(ctrl_info->block_requests_wait, | |
284 | !pqi_ctrl_blocked(ctrl_info)); | |
285 | remaining_msecs = timeout_msecs; | |
286 | } else { | |
287 | unsigned long remaining_jiffies; | |
288 | ||
289 | remaining_jiffies = | |
290 | wait_event_timeout(ctrl_info->block_requests_wait, | |
291 | !pqi_ctrl_blocked(ctrl_info), | |
292 | msecs_to_jiffies(timeout_msecs)); | |
293 | remaining_msecs = jiffies_to_msecs(remaining_jiffies); | |
294 | } | |
295 | ||
296 | atomic_dec(&ctrl_info->num_blocked_threads); | |
297 | ||
298 | return remaining_msecs; | |
299 | } | |
300 | ||
7561a7e4 KB |
301 | static inline void pqi_ctrl_wait_until_quiesced(struct pqi_ctrl_info *ctrl_info) |
302 | { | |
303 | while (atomic_read(&ctrl_info->num_busy_threads) > | |
304 | atomic_read(&ctrl_info->num_blocked_threads)) | |
305 | usleep_range(1000, 2000); | |
306 | } | |
307 | ||
03b288cf KB |
308 | static inline bool pqi_device_offline(struct pqi_scsi_dev *device) |
309 | { | |
310 | return device->device_offline; | |
311 | } | |
312 | ||
7561a7e4 KB |
313 | static inline void pqi_device_reset_start(struct pqi_scsi_dev *device) |
314 | { | |
315 | device->in_reset = true; | |
316 | } | |
317 | ||
318 | static inline void pqi_device_reset_done(struct pqi_scsi_dev *device) | |
319 | { | |
320 | device->in_reset = false; | |
321 | } | |
322 | ||
323 | static inline bool pqi_device_in_reset(struct pqi_scsi_dev *device) | |
324 | { | |
325 | return device->in_reset; | |
326 | } | |
6c223761 | 327 | |
4fd22c13 MR |
328 | static inline void pqi_ctrl_ofa_start(struct pqi_ctrl_info *ctrl_info) |
329 | { | |
330 | ctrl_info->in_ofa = true; | |
331 | } | |
332 | ||
333 | static inline void pqi_ctrl_ofa_done(struct pqi_ctrl_info *ctrl_info) | |
334 | { | |
335 | ctrl_info->in_ofa = false; | |
336 | } | |
337 | ||
338 | static inline bool pqi_ctrl_in_ofa(struct pqi_ctrl_info *ctrl_info) | |
339 | { | |
340 | return ctrl_info->in_ofa; | |
341 | } | |
342 | ||
1e46731e MR |
343 | static inline void pqi_device_remove_start(struct pqi_scsi_dev *device) |
344 | { | |
345 | device->in_remove = true; | |
346 | } | |
347 | ||
348 | static inline bool pqi_device_in_remove(struct pqi_ctrl_info *ctrl_info, | |
349 | struct pqi_scsi_dev *device) | |
350 | { | |
12de280b | 351 | return device->in_remove && !ctrl_info->in_shutdown; |
1e46731e MR |
352 | } |
353 | ||
0530736e KB |
354 | static inline void pqi_ctrl_shutdown_start(struct pqi_ctrl_info *ctrl_info) |
355 | { | |
356 | ctrl_info->in_shutdown = true; | |
357 | } | |
358 | ||
359 | static inline bool pqi_ctrl_in_shutdown(struct pqi_ctrl_info *ctrl_info) | |
360 | { | |
361 | return ctrl_info->in_shutdown; | |
362 | } | |
363 | ||
5f310425 KB |
364 | static inline void pqi_schedule_rescan_worker_with_delay( |
365 | struct pqi_ctrl_info *ctrl_info, unsigned long delay) | |
366 | { | |
367 | if (pqi_ctrl_offline(ctrl_info)) | |
368 | return; | |
4fd22c13 MR |
369 | if (pqi_ctrl_in_ofa(ctrl_info)) |
370 | return; | |
5f310425 KB |
371 | |
372 | schedule_delayed_work(&ctrl_info->rescan_work, delay); | |
373 | } | |
374 | ||
6c223761 KB |
375 | static inline void pqi_schedule_rescan_worker(struct pqi_ctrl_info *ctrl_info) |
376 | { | |
5f310425 KB |
377 | pqi_schedule_rescan_worker_with_delay(ctrl_info, 0); |
378 | } | |
379 | ||
4fd22c13 | 380 | #define PQI_RESCAN_WORK_DELAY (10 * PQI_HZ) |
5f310425 KB |
381 | |
382 | static inline void pqi_schedule_rescan_worker_delayed( | |
383 | struct pqi_ctrl_info *ctrl_info) | |
384 | { | |
385 | pqi_schedule_rescan_worker_with_delay(ctrl_info, PQI_RESCAN_WORK_DELAY); | |
6c223761 KB |
386 | } |
387 | ||
061ef06a KB |
388 | static inline void pqi_cancel_rescan_worker(struct pqi_ctrl_info *ctrl_info) |
389 | { | |
390 | cancel_delayed_work_sync(&ctrl_info->rescan_work); | |
391 | } | |
392 | ||
0530736e KB |
393 | static inline void pqi_cancel_event_worker(struct pqi_ctrl_info *ctrl_info) |
394 | { | |
395 | cancel_work_sync(&ctrl_info->event_work); | |
396 | } | |
397 | ||
98f87667 KB |
398 | static inline u32 pqi_read_heartbeat_counter(struct pqi_ctrl_info *ctrl_info) |
399 | { | |
400 | if (!ctrl_info->heartbeat_counter) | |
401 | return 0; | |
402 | ||
403 | return readl(ctrl_info->heartbeat_counter); | |
404 | } | |
405 | ||
4fd22c13 MR |
406 | static inline u8 pqi_read_soft_reset_status(struct pqi_ctrl_info *ctrl_info) |
407 | { | |
408 | if (!ctrl_info->soft_reset_status) | |
409 | return 0; | |
410 | ||
411 | return readb(ctrl_info->soft_reset_status); | |
412 | } | |
413 | ||
414 | static inline void pqi_clear_soft_reset_status(struct pqi_ctrl_info *ctrl_info, | |
694c5d5b | 415 | u8 clear) |
4fd22c13 MR |
416 | { |
417 | u8 status; | |
418 | ||
419 | if (!ctrl_info->soft_reset_status) | |
420 | return; | |
421 | ||
422 | status = pqi_read_soft_reset_status(ctrl_info); | |
423 | status &= ~clear; | |
424 | writeb(status, ctrl_info->soft_reset_status); | |
425 | } | |
426 | ||
6c223761 KB |
427 | static int pqi_map_single(struct pci_dev *pci_dev, |
428 | struct pqi_sg_descriptor *sg_descriptor, void *buffer, | |
6917a9cc | 429 | size_t buffer_length, enum dma_data_direction data_direction) |
6c223761 KB |
430 | { |
431 | dma_addr_t bus_address; | |
432 | ||
6917a9cc | 433 | if (!buffer || buffer_length == 0 || data_direction == DMA_NONE) |
6c223761 KB |
434 | return 0; |
435 | ||
6917a9cc | 436 | bus_address = dma_map_single(&pci_dev->dev, buffer, buffer_length, |
6c223761 | 437 | data_direction); |
6917a9cc | 438 | if (dma_mapping_error(&pci_dev->dev, bus_address)) |
6c223761 KB |
439 | return -ENOMEM; |
440 | ||
441 | put_unaligned_le64((u64)bus_address, &sg_descriptor->address); | |
442 | put_unaligned_le32(buffer_length, &sg_descriptor->length); | |
443 | put_unaligned_le32(CISS_SG_LAST, &sg_descriptor->flags); | |
444 | ||
445 | return 0; | |
446 | } | |
447 | ||
448 | static void pqi_pci_unmap(struct pci_dev *pci_dev, | |
449 | struct pqi_sg_descriptor *descriptors, int num_descriptors, | |
6917a9cc | 450 | enum dma_data_direction data_direction) |
6c223761 KB |
451 | { |
452 | int i; | |
453 | ||
6917a9cc | 454 | if (data_direction == DMA_NONE) |
6c223761 KB |
455 | return; |
456 | ||
457 | for (i = 0; i < num_descriptors; i++) | |
6917a9cc | 458 | dma_unmap_single(&pci_dev->dev, |
6c223761 KB |
459 | (dma_addr_t)get_unaligned_le64(&descriptors[i].address), |
460 | get_unaligned_le32(&descriptors[i].length), | |
461 | data_direction); | |
462 | } | |
463 | ||
464 | static int pqi_build_raid_path_request(struct pqi_ctrl_info *ctrl_info, | |
465 | struct pqi_raid_path_request *request, u8 cmd, | |
466 | u8 *scsi3addr, void *buffer, size_t buffer_length, | |
6917a9cc | 467 | u16 vpd_page, enum dma_data_direction *dir) |
6c223761 KB |
468 | { |
469 | u8 *cdb; | |
171c2865 | 470 | size_t cdb_length = buffer_length; |
6c223761 KB |
471 | |
472 | memset(request, 0, sizeof(*request)); | |
473 | ||
474 | request->header.iu_type = PQI_REQUEST_IU_RAID_PATH_IO; | |
475 | put_unaligned_le16(offsetof(struct pqi_raid_path_request, | |
476 | sg_descriptors[1]) - PQI_REQUEST_HEADER_LENGTH, | |
477 | &request->header.iu_length); | |
478 | put_unaligned_le32(buffer_length, &request->buffer_length); | |
479 | memcpy(request->lun_number, scsi3addr, sizeof(request->lun_number)); | |
480 | request->task_attribute = SOP_TASK_ATTRIBUTE_SIMPLE; | |
481 | request->additional_cdb_bytes_usage = SOP_ADDITIONAL_CDB_BYTES_0; | |
482 | ||
483 | cdb = request->cdb; | |
484 | ||
485 | switch (cmd) { | |
486 | case INQUIRY: | |
487 | request->data_direction = SOP_READ_FLAG; | |
488 | cdb[0] = INQUIRY; | |
489 | if (vpd_page & VPD_PAGE) { | |
490 | cdb[1] = 0x1; | |
491 | cdb[2] = (u8)vpd_page; | |
492 | } | |
171c2865 | 493 | cdb[4] = (u8)cdb_length; |
6c223761 KB |
494 | break; |
495 | case CISS_REPORT_LOG: | |
496 | case CISS_REPORT_PHYS: | |
497 | request->data_direction = SOP_READ_FLAG; | |
498 | cdb[0] = cmd; | |
499 | if (cmd == CISS_REPORT_PHYS) | |
694c5d5b | 500 | cdb[1] = CISS_REPORT_PHYS_FLAG_OTHER; |
6c223761 | 501 | else |
694c5d5b | 502 | cdb[1] = CISS_REPORT_LOG_FLAG_UNIQUE_LUN_ID; |
171c2865 | 503 | put_unaligned_be32(cdb_length, &cdb[6]); |
6c223761 KB |
504 | break; |
505 | case CISS_GET_RAID_MAP: | |
506 | request->data_direction = SOP_READ_FLAG; | |
507 | cdb[0] = CISS_READ; | |
508 | cdb[1] = CISS_GET_RAID_MAP; | |
171c2865 | 509 | put_unaligned_be32(cdb_length, &cdb[6]); |
6c223761 | 510 | break; |
58322fe0 | 511 | case SA_FLUSH_CACHE: |
6c223761 KB |
512 | request->data_direction = SOP_WRITE_FLAG; |
513 | cdb[0] = BMIC_WRITE; | |
58322fe0 | 514 | cdb[6] = BMIC_FLUSH_CACHE; |
171c2865 | 515 | put_unaligned_be16(cdb_length, &cdb[7]); |
6c223761 | 516 | break; |
171c2865 DC |
517 | case BMIC_SENSE_DIAG_OPTIONS: |
518 | cdb_length = 0; | |
e52c9e07 | 519 | /* fall through */ |
6c223761 KB |
520 | case BMIC_IDENTIFY_CONTROLLER: |
521 | case BMIC_IDENTIFY_PHYSICAL_DEVICE: | |
6d90615f | 522 | case BMIC_SENSE_SUBSYSTEM_INFORMATION: |
6c223761 KB |
523 | request->data_direction = SOP_READ_FLAG; |
524 | cdb[0] = BMIC_READ; | |
525 | cdb[6] = cmd; | |
171c2865 | 526 | put_unaligned_be16(cdb_length, &cdb[7]); |
6c223761 | 527 | break; |
171c2865 DC |
528 | case BMIC_SET_DIAG_OPTIONS: |
529 | cdb_length = 0; | |
e52c9e07 | 530 | /* fall through */ |
6c223761 KB |
531 | case BMIC_WRITE_HOST_WELLNESS: |
532 | request->data_direction = SOP_WRITE_FLAG; | |
533 | cdb[0] = BMIC_WRITE; | |
534 | cdb[6] = cmd; | |
171c2865 | 535 | put_unaligned_be16(cdb_length, &cdb[7]); |
6c223761 | 536 | break; |
3d46a59a DB |
537 | case BMIC_CSMI_PASSTHRU: |
538 | request->data_direction = SOP_BIDIRECTIONAL; | |
539 | cdb[0] = BMIC_WRITE; | |
540 | cdb[5] = CSMI_CC_SAS_SMP_PASSTHRU; | |
541 | cdb[6] = cmd; | |
542 | put_unaligned_be16(cdb_length, &cdb[7]); | |
6c223761 KB |
543 | break; |
544 | default: | |
545 | dev_err(&ctrl_info->pci_dev->dev, "unknown command 0x%c\n", | |
546 | cmd); | |
6c223761 KB |
547 | break; |
548 | } | |
549 | ||
550 | switch (request->data_direction) { | |
551 | case SOP_READ_FLAG: | |
6917a9cc | 552 | *dir = DMA_FROM_DEVICE; |
6c223761 KB |
553 | break; |
554 | case SOP_WRITE_FLAG: | |
6917a9cc | 555 | *dir = DMA_TO_DEVICE; |
6c223761 KB |
556 | break; |
557 | case SOP_NO_DIRECTION_FLAG: | |
6917a9cc | 558 | *dir = DMA_NONE; |
6c223761 KB |
559 | break; |
560 | default: | |
6917a9cc | 561 | *dir = DMA_BIDIRECTIONAL; |
6c223761 KB |
562 | break; |
563 | } | |
564 | ||
6c223761 | 565 | return pqi_map_single(ctrl_info->pci_dev, &request->sg_descriptors[0], |
6917a9cc | 566 | buffer, buffer_length, *dir); |
6c223761 KB |
567 | } |
568 | ||
376fb880 KB |
569 | static inline void pqi_reinit_io_request(struct pqi_io_request *io_request) |
570 | { | |
571 | io_request->scmd = NULL; | |
572 | io_request->status = 0; | |
573 | io_request->error_info = NULL; | |
574 | io_request->raid_bypass = false; | |
575 | } | |
576 | ||
6c223761 KB |
577 | static struct pqi_io_request *pqi_alloc_io_request( |
578 | struct pqi_ctrl_info *ctrl_info) | |
579 | { | |
580 | struct pqi_io_request *io_request; | |
581 | u16 i = ctrl_info->next_io_request_slot; /* benignly racy */ | |
582 | ||
583 | while (1) { | |
584 | io_request = &ctrl_info->io_request_pool[i]; | |
585 | if (atomic_inc_return(&io_request->refcount) == 1) | |
586 | break; | |
587 | atomic_dec(&io_request->refcount); | |
588 | i = (i + 1) % ctrl_info->max_io_slots; | |
589 | } | |
590 | ||
591 | /* benignly racy */ | |
592 | ctrl_info->next_io_request_slot = (i + 1) % ctrl_info->max_io_slots; | |
593 | ||
376fb880 | 594 | pqi_reinit_io_request(io_request); |
6c223761 KB |
595 | |
596 | return io_request; | |
597 | } | |
598 | ||
599 | static void pqi_free_io_request(struct pqi_io_request *io_request) | |
600 | { | |
601 | atomic_dec(&io_request->refcount); | |
602 | } | |
603 | ||
02133b68 | 604 | static int pqi_send_scsi_raid_request(struct pqi_ctrl_info *ctrl_info, u8 cmd, |
694c5d5b KB |
605 | u8 *scsi3addr, void *buffer, size_t buffer_length, u16 vpd_page, |
606 | struct pqi_raid_error_info *error_info, unsigned long timeout_msecs) | |
6c223761 KB |
607 | { |
608 | int rc; | |
6c223761 | 609 | struct pqi_raid_path_request request; |
694c5d5b | 610 | enum dma_data_direction dir; |
6c223761 KB |
611 | |
612 | rc = pqi_build_raid_path_request(ctrl_info, &request, | |
02133b68 DC |
613 | cmd, scsi3addr, buffer, |
614 | buffer_length, vpd_page, &dir); | |
6c223761 KB |
615 | if (rc) |
616 | return rc; | |
617 | ||
694c5d5b KB |
618 | rc = pqi_submit_raid_request_synchronous(ctrl_info, &request.header, 0, |
619 | error_info, timeout_msecs); | |
6c223761 | 620 | |
6917a9cc | 621 | pqi_pci_unmap(ctrl_info->pci_dev, request.sg_descriptors, 1, dir); |
694c5d5b | 622 | |
6c223761 KB |
623 | return rc; |
624 | } | |
625 | ||
694c5d5b | 626 | /* helper functions for pqi_send_scsi_raid_request */ |
02133b68 DC |
627 | |
628 | static inline int pqi_send_ctrl_raid_request(struct pqi_ctrl_info *ctrl_info, | |
694c5d5b | 629 | u8 cmd, void *buffer, size_t buffer_length) |
6c223761 | 630 | { |
02133b68 | 631 | return pqi_send_scsi_raid_request(ctrl_info, cmd, RAID_CTLR_LUNID, |
694c5d5b | 632 | buffer, buffer_length, 0, NULL, NO_TIMEOUT); |
02133b68 | 633 | } |
6c223761 | 634 | |
02133b68 | 635 | static inline int pqi_send_ctrl_raid_with_error(struct pqi_ctrl_info *ctrl_info, |
694c5d5b KB |
636 | u8 cmd, void *buffer, size_t buffer_length, |
637 | struct pqi_raid_error_info *error_info) | |
02133b68 DC |
638 | { |
639 | return pqi_send_scsi_raid_request(ctrl_info, cmd, RAID_CTLR_LUNID, | |
694c5d5b | 640 | buffer, buffer_length, 0, error_info, NO_TIMEOUT); |
02133b68 | 641 | } |
6c223761 | 642 | |
02133b68 | 643 | static inline int pqi_identify_controller(struct pqi_ctrl_info *ctrl_info, |
694c5d5b | 644 | struct bmic_identify_controller *buffer) |
02133b68 DC |
645 | { |
646 | return pqi_send_ctrl_raid_request(ctrl_info, BMIC_IDENTIFY_CONTROLLER, | |
694c5d5b | 647 | buffer, sizeof(*buffer)); |
02133b68 DC |
648 | } |
649 | ||
6d90615f | 650 | static inline int pqi_sense_subsystem_info(struct pqi_ctrl_info *ctrl_info, |
694c5d5b | 651 | struct bmic_sense_subsystem_info *sense_info) |
6d90615f MB |
652 | { |
653 | return pqi_send_ctrl_raid_request(ctrl_info, | |
694c5d5b KB |
654 | BMIC_SENSE_SUBSYSTEM_INFORMATION, sense_info, |
655 | sizeof(*sense_info)); | |
6d90615f MB |
656 | } |
657 | ||
02133b68 | 658 | static inline int pqi_scsi_inquiry(struct pqi_ctrl_info *ctrl_info, |
6c223761 | 659 | u8 *scsi3addr, u16 vpd_page, void *buffer, size_t buffer_length) |
02133b68 DC |
660 | { |
661 | return pqi_send_scsi_raid_request(ctrl_info, INQUIRY, scsi3addr, | |
662 | buffer, buffer_length, vpd_page, NULL, NO_TIMEOUT); | |
6c223761 KB |
663 | } |
664 | ||
665 | static int pqi_identify_physical_device(struct pqi_ctrl_info *ctrl_info, | |
666 | struct pqi_scsi_dev *device, | |
694c5d5b | 667 | struct bmic_identify_physical_device *buffer, size_t buffer_length) |
6c223761 KB |
668 | { |
669 | int rc; | |
6917a9cc | 670 | enum dma_data_direction dir; |
6c223761 KB |
671 | u16 bmic_device_index; |
672 | struct pqi_raid_path_request request; | |
673 | ||
674 | rc = pqi_build_raid_path_request(ctrl_info, &request, | |
675 | BMIC_IDENTIFY_PHYSICAL_DEVICE, RAID_CTLR_LUNID, buffer, | |
6917a9cc | 676 | buffer_length, 0, &dir); |
6c223761 KB |
677 | if (rc) |
678 | return rc; | |
679 | ||
680 | bmic_device_index = CISS_GET_DRIVE_NUMBER(device->scsi3addr); | |
681 | request.cdb[2] = (u8)bmic_device_index; | |
682 | request.cdb[9] = (u8)(bmic_device_index >> 8); | |
683 | ||
684 | rc = pqi_submit_raid_request_synchronous(ctrl_info, &request.header, | |
685 | 0, NULL, NO_TIMEOUT); | |
686 | ||
6917a9cc | 687 | pqi_pci_unmap(ctrl_info->pci_dev, request.sg_descriptors, 1, dir); |
694c5d5b | 688 | |
6c223761 KB |
689 | return rc; |
690 | } | |
691 | ||
58322fe0 KB |
692 | static int pqi_flush_cache(struct pqi_ctrl_info *ctrl_info, |
693 | enum bmic_flush_cache_shutdown_event shutdown_event) | |
6c223761 KB |
694 | { |
695 | int rc; | |
58322fe0 | 696 | struct bmic_flush_cache *flush_cache; |
6c223761 KB |
697 | |
698 | /* | |
699 | * Don't bother trying to flush the cache if the controller is | |
700 | * locked up. | |
701 | */ | |
702 | if (pqi_ctrl_offline(ctrl_info)) | |
703 | return -ENXIO; | |
704 | ||
58322fe0 KB |
705 | flush_cache = kzalloc(sizeof(*flush_cache), GFP_KERNEL); |
706 | if (!flush_cache) | |
6c223761 KB |
707 | return -ENOMEM; |
708 | ||
58322fe0 KB |
709 | flush_cache->shutdown_event = shutdown_event; |
710 | ||
02133b68 DC |
711 | rc = pqi_send_ctrl_raid_request(ctrl_info, SA_FLUSH_CACHE, flush_cache, |
712 | sizeof(*flush_cache)); | |
6c223761 | 713 | |
58322fe0 | 714 | kfree(flush_cache); |
6c223761 KB |
715 | |
716 | return rc; | |
717 | } | |
718 | ||
3d46a59a DB |
719 | int pqi_csmi_smp_passthru(struct pqi_ctrl_info *ctrl_info, |
720 | struct bmic_csmi_smp_passthru_buffer *buffer, size_t buffer_length, | |
721 | struct pqi_raid_error_info *error_info) | |
722 | { | |
723 | return pqi_send_ctrl_raid_with_error(ctrl_info, BMIC_CSMI_PASSTHRU, | |
724 | buffer, buffer_length, error_info); | |
725 | } | |
171c2865 | 726 | |
694c5d5b | 727 | #define PQI_FETCH_PTRAID_DATA (1 << 31) |
171c2865 DC |
728 | |
729 | static int pqi_set_diag_rescan(struct pqi_ctrl_info *ctrl_info) | |
6c223761 KB |
730 | { |
731 | int rc; | |
171c2865 | 732 | struct bmic_diag_options *diag; |
6c223761 | 733 | |
171c2865 DC |
734 | diag = kzalloc(sizeof(*diag), GFP_KERNEL); |
735 | if (!diag) | |
736 | return -ENOMEM; | |
737 | ||
02133b68 | 738 | rc = pqi_send_ctrl_raid_request(ctrl_info, BMIC_SENSE_DIAG_OPTIONS, |
694c5d5b | 739 | diag, sizeof(*diag)); |
6c223761 | 740 | if (rc) |
171c2865 | 741 | goto out; |
6c223761 | 742 | |
171c2865 DC |
743 | diag->options |= cpu_to_le32(PQI_FETCH_PTRAID_DATA); |
744 | ||
694c5d5b KB |
745 | rc = pqi_send_ctrl_raid_request(ctrl_info, BMIC_SET_DIAG_OPTIONS, diag, |
746 | sizeof(*diag)); | |
747 | ||
171c2865 DC |
748 | out: |
749 | kfree(diag); | |
6c223761 | 750 | |
6c223761 KB |
751 | return rc; |
752 | } | |
753 | ||
02133b68 | 754 | static inline int pqi_write_host_wellness(struct pqi_ctrl_info *ctrl_info, |
6c223761 KB |
755 | void *buffer, size_t buffer_length) |
756 | { | |
02133b68 | 757 | return pqi_send_ctrl_raid_request(ctrl_info, BMIC_WRITE_HOST_WELLNESS, |
694c5d5b | 758 | buffer, buffer_length); |
6c223761 KB |
759 | } |
760 | ||
761 | #pragma pack(1) | |
762 | ||
763 | struct bmic_host_wellness_driver_version { | |
764 | u8 start_tag[4]; | |
765 | u8 driver_version_tag[2]; | |
766 | __le16 driver_version_length; | |
767 | char driver_version[32]; | |
b2346b50 | 768 | u8 dont_write_tag[2]; |
6c223761 KB |
769 | u8 end_tag[2]; |
770 | }; | |
771 | ||
772 | #pragma pack() | |
773 | ||
774 | static int pqi_write_driver_version_to_host_wellness( | |
775 | struct pqi_ctrl_info *ctrl_info) | |
776 | { | |
777 | int rc; | |
778 | struct bmic_host_wellness_driver_version *buffer; | |
779 | size_t buffer_length; | |
780 | ||
781 | buffer_length = sizeof(*buffer); | |
782 | ||
783 | buffer = kmalloc(buffer_length, GFP_KERNEL); | |
784 | if (!buffer) | |
785 | return -ENOMEM; | |
786 | ||
787 | buffer->start_tag[0] = '<'; | |
788 | buffer->start_tag[1] = 'H'; | |
789 | buffer->start_tag[2] = 'W'; | |
790 | buffer->start_tag[3] = '>'; | |
791 | buffer->driver_version_tag[0] = 'D'; | |
792 | buffer->driver_version_tag[1] = 'V'; | |
793 | put_unaligned_le16(sizeof(buffer->driver_version), | |
794 | &buffer->driver_version_length); | |
061ef06a | 795 | strncpy(buffer->driver_version, "Linux " DRIVER_VERSION, |
6c223761 KB |
796 | sizeof(buffer->driver_version) - 1); |
797 | buffer->driver_version[sizeof(buffer->driver_version) - 1] = '\0'; | |
b2346b50 MR |
798 | buffer->dont_write_tag[0] = 'D'; |
799 | buffer->dont_write_tag[1] = 'W'; | |
6c223761 KB |
800 | buffer->end_tag[0] = 'Z'; |
801 | buffer->end_tag[1] = 'Z'; | |
802 | ||
803 | rc = pqi_write_host_wellness(ctrl_info, buffer, buffer_length); | |
804 | ||
805 | kfree(buffer); | |
806 | ||
807 | return rc; | |
808 | } | |
809 | ||
810 | #pragma pack(1) | |
811 | ||
812 | struct bmic_host_wellness_time { | |
813 | u8 start_tag[4]; | |
814 | u8 time_tag[2]; | |
815 | __le16 time_length; | |
816 | u8 time[8]; | |
817 | u8 dont_write_tag[2]; | |
818 | u8 end_tag[2]; | |
819 | }; | |
820 | ||
821 | #pragma pack() | |
822 | ||
823 | static int pqi_write_current_time_to_host_wellness( | |
824 | struct pqi_ctrl_info *ctrl_info) | |
825 | { | |
826 | int rc; | |
827 | struct bmic_host_wellness_time *buffer; | |
828 | size_t buffer_length; | |
829 | time64_t local_time; | |
830 | unsigned int year; | |
ed10858e | 831 | struct tm tm; |
6c223761 KB |
832 | |
833 | buffer_length = sizeof(*buffer); | |
834 | ||
835 | buffer = kmalloc(buffer_length, GFP_KERNEL); | |
836 | if (!buffer) | |
837 | return -ENOMEM; | |
838 | ||
839 | buffer->start_tag[0] = '<'; | |
840 | buffer->start_tag[1] = 'H'; | |
841 | buffer->start_tag[2] = 'W'; | |
842 | buffer->start_tag[3] = '>'; | |
843 | buffer->time_tag[0] = 'T'; | |
844 | buffer->time_tag[1] = 'D'; | |
845 | put_unaligned_le16(sizeof(buffer->time), | |
846 | &buffer->time_length); | |
847 | ||
ed10858e AB |
848 | local_time = ktime_get_real_seconds(); |
849 | time64_to_tm(local_time, -sys_tz.tz_minuteswest * 60, &tm); | |
6c223761 KB |
850 | year = tm.tm_year + 1900; |
851 | ||
852 | buffer->time[0] = bin2bcd(tm.tm_hour); | |
853 | buffer->time[1] = bin2bcd(tm.tm_min); | |
854 | buffer->time[2] = bin2bcd(tm.tm_sec); | |
855 | buffer->time[3] = 0; | |
856 | buffer->time[4] = bin2bcd(tm.tm_mon + 1); | |
857 | buffer->time[5] = bin2bcd(tm.tm_mday); | |
858 | buffer->time[6] = bin2bcd(year / 100); | |
859 | buffer->time[7] = bin2bcd(year % 100); | |
860 | ||
861 | buffer->dont_write_tag[0] = 'D'; | |
862 | buffer->dont_write_tag[1] = 'W'; | |
863 | buffer->end_tag[0] = 'Z'; | |
864 | buffer->end_tag[1] = 'Z'; | |
865 | ||
866 | rc = pqi_write_host_wellness(ctrl_info, buffer, buffer_length); | |
867 | ||
868 | kfree(buffer); | |
869 | ||
870 | return rc; | |
871 | } | |
872 | ||
4fd22c13 | 873 | #define PQI_UPDATE_TIME_WORK_INTERVAL (24UL * 60 * 60 * PQI_HZ) |
6c223761 KB |
874 | |
875 | static void pqi_update_time_worker(struct work_struct *work) | |
876 | { | |
877 | int rc; | |
878 | struct pqi_ctrl_info *ctrl_info; | |
879 | ||
880 | ctrl_info = container_of(to_delayed_work(work), struct pqi_ctrl_info, | |
881 | update_time_work); | |
882 | ||
5f310425 KB |
883 | if (pqi_ctrl_offline(ctrl_info)) |
884 | return; | |
885 | ||
6c223761 KB |
886 | rc = pqi_write_current_time_to_host_wellness(ctrl_info); |
887 | if (rc) | |
888 | dev_warn(&ctrl_info->pci_dev->dev, | |
889 | "error updating time on controller\n"); | |
890 | ||
891 | schedule_delayed_work(&ctrl_info->update_time_work, | |
892 | PQI_UPDATE_TIME_WORK_INTERVAL); | |
893 | } | |
894 | ||
895 | static inline void pqi_schedule_update_time_worker( | |
4fbebf1a | 896 | struct pqi_ctrl_info *ctrl_info) |
6c223761 | 897 | { |
4fbebf1a | 898 | schedule_delayed_work(&ctrl_info->update_time_work, 0); |
061ef06a KB |
899 | } |
900 | ||
901 | static inline void pqi_cancel_update_time_worker( | |
902 | struct pqi_ctrl_info *ctrl_info) | |
903 | { | |
061ef06a | 904 | cancel_delayed_work_sync(&ctrl_info->update_time_work); |
6c223761 KB |
905 | } |
906 | ||
02133b68 | 907 | static inline int pqi_report_luns(struct pqi_ctrl_info *ctrl_info, u8 cmd, |
6c223761 KB |
908 | void *buffer, size_t buffer_length) |
909 | { | |
02133b68 | 910 | return pqi_send_ctrl_raid_request(ctrl_info, cmd, buffer, |
694c5d5b | 911 | buffer_length); |
6c223761 KB |
912 | } |
913 | ||
914 | static int pqi_report_phys_logical_luns(struct pqi_ctrl_info *ctrl_info, u8 cmd, | |
915 | void **buffer) | |
916 | { | |
917 | int rc; | |
918 | size_t lun_list_length; | |
919 | size_t lun_data_length; | |
920 | size_t new_lun_list_length; | |
921 | void *lun_data = NULL; | |
922 | struct report_lun_header *report_lun_header; | |
923 | ||
924 | report_lun_header = kmalloc(sizeof(*report_lun_header), GFP_KERNEL); | |
925 | if (!report_lun_header) { | |
926 | rc = -ENOMEM; | |
927 | goto out; | |
928 | } | |
929 | ||
930 | rc = pqi_report_luns(ctrl_info, cmd, report_lun_header, | |
931 | sizeof(*report_lun_header)); | |
932 | if (rc) | |
933 | goto out; | |
934 | ||
935 | lun_list_length = get_unaligned_be32(&report_lun_header->list_length); | |
936 | ||
937 | again: | |
938 | lun_data_length = sizeof(struct report_lun_header) + lun_list_length; | |
939 | ||
940 | lun_data = kmalloc(lun_data_length, GFP_KERNEL); | |
941 | if (!lun_data) { | |
942 | rc = -ENOMEM; | |
943 | goto out; | |
944 | } | |
945 | ||
946 | if (lun_list_length == 0) { | |
947 | memcpy(lun_data, report_lun_header, sizeof(*report_lun_header)); | |
948 | goto out; | |
949 | } | |
950 | ||
951 | rc = pqi_report_luns(ctrl_info, cmd, lun_data, lun_data_length); | |
952 | if (rc) | |
953 | goto out; | |
954 | ||
955 | new_lun_list_length = get_unaligned_be32( | |
956 | &((struct report_lun_header *)lun_data)->list_length); | |
957 | ||
958 | if (new_lun_list_length > lun_list_length) { | |
959 | lun_list_length = new_lun_list_length; | |
960 | kfree(lun_data); | |
961 | goto again; | |
962 | } | |
963 | ||
964 | out: | |
965 | kfree(report_lun_header); | |
966 | ||
967 | if (rc) { | |
968 | kfree(lun_data); | |
969 | lun_data = NULL; | |
970 | } | |
971 | ||
972 | *buffer = lun_data; | |
973 | ||
974 | return rc; | |
975 | } | |
976 | ||
977 | static inline int pqi_report_phys_luns(struct pqi_ctrl_info *ctrl_info, | |
978 | void **buffer) | |
979 | { | |
980 | return pqi_report_phys_logical_luns(ctrl_info, CISS_REPORT_PHYS, | |
981 | buffer); | |
982 | } | |
983 | ||
984 | static inline int pqi_report_logical_luns(struct pqi_ctrl_info *ctrl_info, | |
985 | void **buffer) | |
986 | { | |
987 | return pqi_report_phys_logical_luns(ctrl_info, CISS_REPORT_LOG, buffer); | |
988 | } | |
989 | ||
990 | static int pqi_get_device_lists(struct pqi_ctrl_info *ctrl_info, | |
991 | struct report_phys_lun_extended **physdev_list, | |
992 | struct report_log_lun_extended **logdev_list) | |
993 | { | |
994 | int rc; | |
995 | size_t logdev_list_length; | |
996 | size_t logdev_data_length; | |
997 | struct report_log_lun_extended *internal_logdev_list; | |
998 | struct report_log_lun_extended *logdev_data; | |
999 | struct report_lun_header report_lun_header; | |
1000 | ||
1001 | rc = pqi_report_phys_luns(ctrl_info, (void **)physdev_list); | |
1002 | if (rc) | |
1003 | dev_err(&ctrl_info->pci_dev->dev, | |
1004 | "report physical LUNs failed\n"); | |
1005 | ||
1006 | rc = pqi_report_logical_luns(ctrl_info, (void **)logdev_list); | |
1007 | if (rc) | |
1008 | dev_err(&ctrl_info->pci_dev->dev, | |
1009 | "report logical LUNs failed\n"); | |
1010 | ||
1011 | /* | |
1012 | * Tack the controller itself onto the end of the logical device list. | |
1013 | */ | |
1014 | ||
1015 | logdev_data = *logdev_list; | |
1016 | ||
1017 | if (logdev_data) { | |
1018 | logdev_list_length = | |
1019 | get_unaligned_be32(&logdev_data->header.list_length); | |
1020 | } else { | |
1021 | memset(&report_lun_header, 0, sizeof(report_lun_header)); | |
1022 | logdev_data = | |
1023 | (struct report_log_lun_extended *)&report_lun_header; | |
1024 | logdev_list_length = 0; | |
1025 | } | |
1026 | ||
1027 | logdev_data_length = sizeof(struct report_lun_header) + | |
1028 | logdev_list_length; | |
1029 | ||
1030 | internal_logdev_list = kmalloc(logdev_data_length + | |
1031 | sizeof(struct report_log_lun_extended), GFP_KERNEL); | |
1032 | if (!internal_logdev_list) { | |
1033 | kfree(*logdev_list); | |
1034 | *logdev_list = NULL; | |
1035 | return -ENOMEM; | |
1036 | } | |
1037 | ||
1038 | memcpy(internal_logdev_list, logdev_data, logdev_data_length); | |
1039 | memset((u8 *)internal_logdev_list + logdev_data_length, 0, | |
1040 | sizeof(struct report_log_lun_extended_entry)); | |
1041 | put_unaligned_be32(logdev_list_length + | |
1042 | sizeof(struct report_log_lun_extended_entry), | |
1043 | &internal_logdev_list->header.list_length); | |
1044 | ||
1045 | kfree(*logdev_list); | |
1046 | *logdev_list = internal_logdev_list; | |
1047 | ||
1048 | return 0; | |
1049 | } | |
1050 | ||
1051 | static inline void pqi_set_bus_target_lun(struct pqi_scsi_dev *device, | |
1052 | int bus, int target, int lun) | |
1053 | { | |
1054 | device->bus = bus; | |
1055 | device->target = target; | |
1056 | device->lun = lun; | |
1057 | } | |
1058 | ||
1059 | static void pqi_assign_bus_target_lun(struct pqi_scsi_dev *device) | |
1060 | { | |
1061 | u8 *scsi3addr; | |
1062 | u32 lunid; | |
bd10cf0b KB |
1063 | int bus; |
1064 | int target; | |
1065 | int lun; | |
6c223761 KB |
1066 | |
1067 | scsi3addr = device->scsi3addr; | |
1068 | lunid = get_unaligned_le32(scsi3addr); | |
1069 | ||
1070 | if (pqi_is_hba_lunid(scsi3addr)) { | |
1071 | /* The specified device is the controller. */ | |
1072 | pqi_set_bus_target_lun(device, PQI_HBA_BUS, 0, lunid & 0x3fff); | |
1073 | device->target_lun_valid = true; | |
1074 | return; | |
1075 | } | |
1076 | ||
1077 | if (pqi_is_logical_device(device)) { | |
bd10cf0b KB |
1078 | if (device->is_external_raid_device) { |
1079 | bus = PQI_EXTERNAL_RAID_VOLUME_BUS; | |
1080 | target = (lunid >> 16) & 0x3fff; | |
1081 | lun = lunid & 0xff; | |
1082 | } else { | |
1083 | bus = PQI_RAID_VOLUME_BUS; | |
1084 | target = 0; | |
1085 | lun = lunid & 0x3fff; | |
1086 | } | |
1087 | pqi_set_bus_target_lun(device, bus, target, lun); | |
6c223761 KB |
1088 | device->target_lun_valid = true; |
1089 | return; | |
1090 | } | |
1091 | ||
1092 | /* | |
1093 | * Defer target and LUN assignment for non-controller physical devices | |
1094 | * because the SAS transport layer will make these assignments later. | |
1095 | */ | |
1096 | pqi_set_bus_target_lun(device, PQI_PHYSICAL_DEVICE_BUS, 0, 0); | |
1097 | } | |
1098 | ||
1099 | static void pqi_get_raid_level(struct pqi_ctrl_info *ctrl_info, | |
1100 | struct pqi_scsi_dev *device) | |
1101 | { | |
1102 | int rc; | |
1103 | u8 raid_level; | |
1104 | u8 *buffer; | |
1105 | ||
1106 | raid_level = SA_RAID_UNKNOWN; | |
1107 | ||
1108 | buffer = kmalloc(64, GFP_KERNEL); | |
1109 | if (buffer) { | |
1110 | rc = pqi_scsi_inquiry(ctrl_info, device->scsi3addr, | |
1111 | VPD_PAGE | CISS_VPD_LV_DEVICE_GEOMETRY, buffer, 64); | |
1112 | if (rc == 0) { | |
1113 | raid_level = buffer[8]; | |
1114 | if (raid_level > SA_RAID_MAX) | |
1115 | raid_level = SA_RAID_UNKNOWN; | |
1116 | } | |
1117 | kfree(buffer); | |
1118 | } | |
1119 | ||
1120 | device->raid_level = raid_level; | |
1121 | } | |
1122 | ||
1123 | static int pqi_validate_raid_map(struct pqi_ctrl_info *ctrl_info, | |
1124 | struct pqi_scsi_dev *device, struct raid_map *raid_map) | |
1125 | { | |
1126 | char *err_msg; | |
1127 | u32 raid_map_size; | |
1128 | u32 r5or6_blocks_per_row; | |
6c223761 KB |
1129 | |
1130 | raid_map_size = get_unaligned_le32(&raid_map->structure_size); | |
1131 | ||
1132 | if (raid_map_size < offsetof(struct raid_map, disk_data)) { | |
1133 | err_msg = "RAID map too small"; | |
1134 | goto bad_raid_map; | |
1135 | } | |
1136 | ||
6c223761 KB |
1137 | if (device->raid_level == SA_RAID_1) { |
1138 | if (get_unaligned_le16(&raid_map->layout_map_count) != 2) { | |
1139 | err_msg = "invalid RAID-1 map"; | |
1140 | goto bad_raid_map; | |
1141 | } | |
1142 | } else if (device->raid_level == SA_RAID_ADM) { | |
1143 | if (get_unaligned_le16(&raid_map->layout_map_count) != 3) { | |
1144 | err_msg = "invalid RAID-1(ADM) map"; | |
1145 | goto bad_raid_map; | |
1146 | } | |
1147 | } else if ((device->raid_level == SA_RAID_5 || | |
1148 | device->raid_level == SA_RAID_6) && | |
1149 | get_unaligned_le16(&raid_map->layout_map_count) > 1) { | |
1150 | /* RAID 50/60 */ | |
1151 | r5or6_blocks_per_row = | |
1152 | get_unaligned_le16(&raid_map->strip_size) * | |
1153 | get_unaligned_le16(&raid_map->data_disks_per_row); | |
1154 | if (r5or6_blocks_per_row == 0) { | |
1155 | err_msg = "invalid RAID-5 or RAID-6 map"; | |
1156 | goto bad_raid_map; | |
1157 | } | |
1158 | } | |
1159 | ||
1160 | return 0; | |
1161 | ||
1162 | bad_raid_map: | |
d87d5474 | 1163 | dev_warn(&ctrl_info->pci_dev->dev, |
38a7338a KB |
1164 | "logical device %08x%08x %s\n", |
1165 | *((u32 *)&device->scsi3addr), | |
1166 | *((u32 *)&device->scsi3addr[4]), err_msg); | |
6c223761 KB |
1167 | |
1168 | return -EINVAL; | |
1169 | } | |
1170 | ||
1171 | static int pqi_get_raid_map(struct pqi_ctrl_info *ctrl_info, | |
1172 | struct pqi_scsi_dev *device) | |
1173 | { | |
1174 | int rc; | |
a91aaae0 | 1175 | u32 raid_map_size; |
6c223761 KB |
1176 | struct raid_map *raid_map; |
1177 | ||
1178 | raid_map = kmalloc(sizeof(*raid_map), GFP_KERNEL); | |
1179 | if (!raid_map) | |
1180 | return -ENOMEM; | |
1181 | ||
a91aaae0 AK |
1182 | rc = pqi_send_scsi_raid_request(ctrl_info, CISS_GET_RAID_MAP, |
1183 | device->scsi3addr, raid_map, sizeof(*raid_map), | |
1184 | 0, NULL, NO_TIMEOUT); | |
1185 | ||
6c223761 KB |
1186 | if (rc) |
1187 | goto error; | |
1188 | ||
a91aaae0 | 1189 | raid_map_size = get_unaligned_le32(&raid_map->structure_size); |
6c223761 | 1190 | |
a91aaae0 | 1191 | if (raid_map_size > sizeof(*raid_map)) { |
6c223761 | 1192 | |
a91aaae0 AK |
1193 | kfree(raid_map); |
1194 | ||
1195 | raid_map = kmalloc(raid_map_size, GFP_KERNEL); | |
1196 | if (!raid_map) | |
1197 | return -ENOMEM; | |
1198 | ||
1199 | rc = pqi_send_scsi_raid_request(ctrl_info, CISS_GET_RAID_MAP, | |
1200 | device->scsi3addr, raid_map, raid_map_size, | |
1201 | 0, NULL, NO_TIMEOUT); | |
1202 | if (rc) | |
1203 | goto error; | |
1204 | ||
1205 | if (get_unaligned_le32(&raid_map->structure_size) | |
1206 | != raid_map_size) { | |
1207 | dev_warn(&ctrl_info->pci_dev->dev, | |
1208 | "Requested %d bytes, received %d bytes", | |
1209 | raid_map_size, | |
1210 | get_unaligned_le32(&raid_map->structure_size)); | |
1211 | goto error; | |
1212 | } | |
1213 | } | |
6c223761 KB |
1214 | |
1215 | rc = pqi_validate_raid_map(ctrl_info, device, raid_map); | |
1216 | if (rc) | |
1217 | goto error; | |
1218 | ||
1219 | device->raid_map = raid_map; | |
1220 | ||
1221 | return 0; | |
1222 | ||
1223 | error: | |
1224 | kfree(raid_map); | |
1225 | ||
1226 | return rc; | |
1227 | } | |
1228 | ||
588a63fe | 1229 | static void pqi_get_raid_bypass_status(struct pqi_ctrl_info *ctrl_info, |
6c223761 KB |
1230 | struct pqi_scsi_dev *device) |
1231 | { | |
1232 | int rc; | |
1233 | u8 *buffer; | |
588a63fe | 1234 | u8 bypass_status; |
6c223761 KB |
1235 | |
1236 | buffer = kmalloc(64, GFP_KERNEL); | |
1237 | if (!buffer) | |
1238 | return; | |
1239 | ||
1240 | rc = pqi_scsi_inquiry(ctrl_info, device->scsi3addr, | |
588a63fe | 1241 | VPD_PAGE | CISS_VPD_LV_BYPASS_STATUS, buffer, 64); |
6c223761 KB |
1242 | if (rc) |
1243 | goto out; | |
1244 | ||
694c5d5b KB |
1245 | #define RAID_BYPASS_STATUS 4 |
1246 | #define RAID_BYPASS_CONFIGURED 0x1 | |
1247 | #define RAID_BYPASS_ENABLED 0x2 | |
6c223761 | 1248 | |
588a63fe KB |
1249 | bypass_status = buffer[RAID_BYPASS_STATUS]; |
1250 | device->raid_bypass_configured = | |
1251 | (bypass_status & RAID_BYPASS_CONFIGURED) != 0; | |
1252 | if (device->raid_bypass_configured && | |
1253 | (bypass_status & RAID_BYPASS_ENABLED) && | |
1254 | pqi_get_raid_map(ctrl_info, device) == 0) | |
1255 | device->raid_bypass_enabled = true; | |
6c223761 KB |
1256 | |
1257 | out: | |
1258 | kfree(buffer); | |
1259 | } | |
1260 | ||
1261 | /* | |
1262 | * Use vendor-specific VPD to determine online/offline status of a volume. | |
1263 | */ | |
1264 | ||
1265 | static void pqi_get_volume_status(struct pqi_ctrl_info *ctrl_info, | |
1266 | struct pqi_scsi_dev *device) | |
1267 | { | |
1268 | int rc; | |
1269 | size_t page_length; | |
1270 | u8 volume_status = CISS_LV_STATUS_UNAVAILABLE; | |
1271 | bool volume_offline = true; | |
1272 | u32 volume_flags; | |
1273 | struct ciss_vpd_logical_volume_status *vpd; | |
1274 | ||
1275 | vpd = kmalloc(sizeof(*vpd), GFP_KERNEL); | |
1276 | if (!vpd) | |
1277 | goto no_buffer; | |
1278 | ||
1279 | rc = pqi_scsi_inquiry(ctrl_info, device->scsi3addr, | |
1280 | VPD_PAGE | CISS_VPD_LV_STATUS, vpd, sizeof(*vpd)); | |
1281 | if (rc) | |
1282 | goto out; | |
1283 | ||
7ff44499 DC |
1284 | if (vpd->page_code != CISS_VPD_LV_STATUS) |
1285 | goto out; | |
1286 | ||
6c223761 KB |
1287 | page_length = offsetof(struct ciss_vpd_logical_volume_status, |
1288 | volume_status) + vpd->page_length; | |
1289 | if (page_length < sizeof(*vpd)) | |
1290 | goto out; | |
1291 | ||
1292 | volume_status = vpd->volume_status; | |
1293 | volume_flags = get_unaligned_be32(&vpd->flags); | |
1294 | volume_offline = (volume_flags & CISS_LV_FLAGS_NO_HOST_IO) != 0; | |
1295 | ||
1296 | out: | |
1297 | kfree(vpd); | |
1298 | no_buffer: | |
1299 | device->volume_status = volume_status; | |
1300 | device->volume_offline = volume_offline; | |
1301 | } | |
1302 | ||
ce143793 KB |
1303 | static int pqi_get_physical_device_info(struct pqi_ctrl_info *ctrl_info, |
1304 | struct pqi_scsi_dev *device, | |
1305 | struct bmic_identify_physical_device *id_phys) | |
1306 | { | |
1307 | int rc; | |
26b390ab | 1308 | |
ce143793 KB |
1309 | memset(id_phys, 0, sizeof(*id_phys)); |
1310 | ||
1311 | rc = pqi_identify_physical_device(ctrl_info, device, | |
1312 | id_phys, sizeof(*id_phys)); | |
1313 | if (rc) { | |
1314 | device->queue_depth = PQI_PHYSICAL_DISK_DEFAULT_MAX_QUEUE_DEPTH; | |
1315 | return rc; | |
1316 | } | |
1317 | ||
1318 | scsi_sanitize_inquiry_string(&id_phys->model[0], 8); | |
1319 | scsi_sanitize_inquiry_string(&id_phys->model[8], 16); | |
1320 | ||
1321 | memcpy(device->vendor, &id_phys->model[0], sizeof(device->vendor)); | |
1322 | memcpy(device->model, &id_phys->model[8], sizeof(device->model)); | |
1323 | ||
1324 | device->box_index = id_phys->box_index; | |
1325 | device->phys_box_on_bus = id_phys->phys_box_on_bus; | |
1326 | device->phy_connected_dev_type = id_phys->phy_connected_dev_type[0]; | |
1327 | device->queue_depth = | |
1328 | get_unaligned_le16(&id_phys->current_queue_depth_limit); | |
1329 | device->active_path_index = id_phys->active_path_number; | |
1330 | device->path_map = id_phys->redundant_path_present_map; | |
1331 | memcpy(&device->box, | |
1332 | &id_phys->alternate_paths_phys_box_on_port, | |
1333 | sizeof(device->box)); | |
1334 | memcpy(&device->phys_connector, | |
1335 | &id_phys->alternate_paths_phys_connector, | |
1336 | sizeof(device->phys_connector)); | |
1337 | device->bay = id_phys->phys_bay_in_box; | |
1338 | ||
1339 | return 0; | |
1340 | } | |
1341 | ||
1342 | static int pqi_get_logical_device_info(struct pqi_ctrl_info *ctrl_info, | |
6c223761 KB |
1343 | struct pqi_scsi_dev *device) |
1344 | { | |
1345 | int rc; | |
1346 | u8 *buffer; | |
3d46a59a | 1347 | |
6c223761 KB |
1348 | buffer = kmalloc(64, GFP_KERNEL); |
1349 | if (!buffer) | |
1350 | return -ENOMEM; | |
1351 | ||
1352 | /* Send an inquiry to the device to see what it is. */ | |
ce143793 KB |
1353 | rc = pqi_scsi_inquiry(ctrl_info, device->scsi3addr, 0, buffer, 64); |
1354 | if (rc) | |
1355 | goto out; | |
6c223761 KB |
1356 | |
1357 | scsi_sanitize_inquiry_string(&buffer[8], 8); | |
1358 | scsi_sanitize_inquiry_string(&buffer[16], 16); | |
1359 | ||
1360 | device->devtype = buffer[0] & 0x1f; | |
cbe0c7b1 KB |
1361 | memcpy(device->vendor, &buffer[8], sizeof(device->vendor)); |
1362 | memcpy(device->model, &buffer[16], sizeof(device->model)); | |
6c223761 | 1363 | |
ce143793 | 1364 | if (device->devtype == TYPE_DISK) { |
bd10cf0b KB |
1365 | if (device->is_external_raid_device) { |
1366 | device->raid_level = SA_RAID_UNKNOWN; | |
1367 | device->volume_status = CISS_LV_OK; | |
1368 | device->volume_offline = false; | |
1369 | } else { | |
1370 | pqi_get_raid_level(ctrl_info, device); | |
588a63fe | 1371 | pqi_get_raid_bypass_status(ctrl_info, device); |
bd10cf0b KB |
1372 | pqi_get_volume_status(ctrl_info, device); |
1373 | } | |
6c223761 KB |
1374 | } |
1375 | ||
1376 | out: | |
1377 | kfree(buffer); | |
1378 | ||
1379 | return rc; | |
1380 | } | |
1381 | ||
ce143793 | 1382 | static int pqi_get_device_info(struct pqi_ctrl_info *ctrl_info, |
6c223761 KB |
1383 | struct pqi_scsi_dev *device, |
1384 | struct bmic_identify_physical_device *id_phys) | |
1385 | { | |
1386 | int rc; | |
1387 | ||
ce143793 KB |
1388 | if (device->is_expander_smp_device) |
1389 | return 0; | |
6c223761 | 1390 | |
ce143793 KB |
1391 | if (pqi_is_logical_device(device)) |
1392 | rc = pqi_get_logical_device_info(ctrl_info, device); | |
1393 | else | |
1394 | rc = pqi_get_physical_device_info(ctrl_info, device, id_phys); | |
694c5d5b | 1395 | |
ce143793 | 1396 | return rc; |
6c223761 KB |
1397 | } |
1398 | ||
1399 | static void pqi_show_volume_status(struct pqi_ctrl_info *ctrl_info, | |
1400 | struct pqi_scsi_dev *device) | |
1401 | { | |
1402 | char *status; | |
1403 | static const char unknown_state_str[] = | |
1404 | "Volume is in an unknown state (%u)"; | |
1405 | char unknown_state_buffer[sizeof(unknown_state_str) + 10]; | |
1406 | ||
1407 | switch (device->volume_status) { | |
1408 | case CISS_LV_OK: | |
1409 | status = "Volume online"; | |
1410 | break; | |
1411 | case CISS_LV_FAILED: | |
1412 | status = "Volume failed"; | |
1413 | break; | |
1414 | case CISS_LV_NOT_CONFIGURED: | |
1415 | status = "Volume not configured"; | |
1416 | break; | |
1417 | case CISS_LV_DEGRADED: | |
1418 | status = "Volume degraded"; | |
1419 | break; | |
1420 | case CISS_LV_READY_FOR_RECOVERY: | |
1421 | status = "Volume ready for recovery operation"; | |
1422 | break; | |
1423 | case CISS_LV_UNDERGOING_RECOVERY: | |
1424 | status = "Volume undergoing recovery"; | |
1425 | break; | |
1426 | case CISS_LV_WRONG_PHYSICAL_DRIVE_REPLACED: | |
1427 | status = "Wrong physical drive was replaced"; | |
1428 | break; | |
1429 | case CISS_LV_PHYSICAL_DRIVE_CONNECTION_PROBLEM: | |
1430 | status = "A physical drive not properly connected"; | |
1431 | break; | |
1432 | case CISS_LV_HARDWARE_OVERHEATING: | |
1433 | status = "Hardware is overheating"; | |
1434 | break; | |
1435 | case CISS_LV_HARDWARE_HAS_OVERHEATED: | |
1436 | status = "Hardware has overheated"; | |
1437 | break; | |
1438 | case CISS_LV_UNDERGOING_EXPANSION: | |
1439 | status = "Volume undergoing expansion"; | |
1440 | break; | |
1441 | case CISS_LV_NOT_AVAILABLE: | |
1442 | status = "Volume waiting for transforming volume"; | |
1443 | break; | |
1444 | case CISS_LV_QUEUED_FOR_EXPANSION: | |
1445 | status = "Volume queued for expansion"; | |
1446 | break; | |
1447 | case CISS_LV_DISABLED_SCSI_ID_CONFLICT: | |
1448 | status = "Volume disabled due to SCSI ID conflict"; | |
1449 | break; | |
1450 | case CISS_LV_EJECTED: | |
1451 | status = "Volume has been ejected"; | |
1452 | break; | |
1453 | case CISS_LV_UNDERGOING_ERASE: | |
1454 | status = "Volume undergoing background erase"; | |
1455 | break; | |
1456 | case CISS_LV_READY_FOR_PREDICTIVE_SPARE_REBUILD: | |
1457 | status = "Volume ready for predictive spare rebuild"; | |
1458 | break; | |
1459 | case CISS_LV_UNDERGOING_RPI: | |
1460 | status = "Volume undergoing rapid parity initialization"; | |
1461 | break; | |
1462 | case CISS_LV_PENDING_RPI: | |
1463 | status = "Volume queued for rapid parity initialization"; | |
1464 | break; | |
1465 | case CISS_LV_ENCRYPTED_NO_KEY: | |
1466 | status = "Encrypted volume inaccessible - key not present"; | |
1467 | break; | |
1468 | case CISS_LV_UNDERGOING_ENCRYPTION: | |
1469 | status = "Volume undergoing encryption process"; | |
1470 | break; | |
1471 | case CISS_LV_UNDERGOING_ENCRYPTION_REKEYING: | |
1472 | status = "Volume undergoing encryption re-keying process"; | |
1473 | break; | |
1474 | case CISS_LV_ENCRYPTED_IN_NON_ENCRYPTED_CONTROLLER: | |
d87d5474 | 1475 | status = "Volume encrypted but encryption is disabled"; |
6c223761 KB |
1476 | break; |
1477 | case CISS_LV_PENDING_ENCRYPTION: | |
1478 | status = "Volume pending migration to encrypted state"; | |
1479 | break; | |
1480 | case CISS_LV_PENDING_ENCRYPTION_REKEYING: | |
1481 | status = "Volume pending encryption rekeying"; | |
1482 | break; | |
1483 | case CISS_LV_NOT_SUPPORTED: | |
1484 | status = "Volume not supported on this controller"; | |
1485 | break; | |
1486 | case CISS_LV_STATUS_UNAVAILABLE: | |
1487 | status = "Volume status not available"; | |
1488 | break; | |
1489 | default: | |
1490 | snprintf(unknown_state_buffer, sizeof(unknown_state_buffer), | |
1491 | unknown_state_str, device->volume_status); | |
1492 | status = unknown_state_buffer; | |
1493 | break; | |
1494 | } | |
1495 | ||
1496 | dev_info(&ctrl_info->pci_dev->dev, | |
1497 | "scsi %d:%d:%d:%d %s\n", | |
1498 | ctrl_info->scsi_host->host_no, | |
1499 | device->bus, device->target, device->lun, status); | |
1500 | } | |
1501 | ||
6c223761 KB |
1502 | static void pqi_rescan_worker(struct work_struct *work) |
1503 | { | |
1504 | struct pqi_ctrl_info *ctrl_info; | |
1505 | ||
1506 | ctrl_info = container_of(to_delayed_work(work), struct pqi_ctrl_info, | |
1507 | rescan_work); | |
1508 | ||
1509 | pqi_scan_scsi_devices(ctrl_info); | |
1510 | } | |
1511 | ||
1512 | static int pqi_add_device(struct pqi_ctrl_info *ctrl_info, | |
1513 | struct pqi_scsi_dev *device) | |
1514 | { | |
1515 | int rc; | |
1516 | ||
1517 | if (pqi_is_logical_device(device)) | |
1518 | rc = scsi_add_device(ctrl_info->scsi_host, device->bus, | |
1519 | device->target, device->lun); | |
1520 | else | |
1521 | rc = pqi_add_sas_device(ctrl_info->sas_host, device); | |
1522 | ||
1523 | return rc; | |
1524 | } | |
1525 | ||
1e46731e MR |
1526 | #define PQI_PENDING_IO_TIMEOUT_SECS 20 |
1527 | ||
6c223761 KB |
1528 | static inline void pqi_remove_device(struct pqi_ctrl_info *ctrl_info, |
1529 | struct pqi_scsi_dev *device) | |
1530 | { | |
1e46731e MR |
1531 | int rc; |
1532 | ||
1533 | pqi_device_remove_start(device); | |
1534 | ||
1535 | rc = pqi_device_wait_for_pending_io(ctrl_info, device, | |
1536 | PQI_PENDING_IO_TIMEOUT_SECS); | |
1537 | if (rc) | |
1538 | dev_err(&ctrl_info->pci_dev->dev, | |
1539 | "scsi %d:%d:%d:%d removing device with %d outstanding commands\n", | |
1540 | ctrl_info->scsi_host->host_no, device->bus, | |
1541 | device->target, device->lun, | |
1542 | atomic_read(&device->scsi_cmds_outstanding)); | |
1543 | ||
6c223761 KB |
1544 | if (pqi_is_logical_device(device)) |
1545 | scsi_remove_device(device->sdev); | |
1546 | else | |
1547 | pqi_remove_sas_device(device); | |
1548 | } | |
1549 | ||
1550 | /* Assumes the SCSI device list lock is held. */ | |
1551 | ||
1552 | static struct pqi_scsi_dev *pqi_find_scsi_dev(struct pqi_ctrl_info *ctrl_info, | |
1553 | int bus, int target, int lun) | |
1554 | { | |
1555 | struct pqi_scsi_dev *device; | |
1556 | ||
1557 | list_for_each_entry(device, &ctrl_info->scsi_device_list, | |
1558 | scsi_device_list_entry) | |
1559 | if (device->bus == bus && device->target == target && | |
1560 | device->lun == lun) | |
1561 | return device; | |
1562 | ||
1563 | return NULL; | |
1564 | } | |
1565 | ||
1566 | static inline bool pqi_device_equal(struct pqi_scsi_dev *dev1, | |
1567 | struct pqi_scsi_dev *dev2) | |
1568 | { | |
1569 | if (dev1->is_physical_device != dev2->is_physical_device) | |
1570 | return false; | |
1571 | ||
1572 | if (dev1->is_physical_device) | |
1573 | return dev1->wwid == dev2->wwid; | |
1574 | ||
1575 | return memcmp(dev1->volume_id, dev2->volume_id, | |
1576 | sizeof(dev1->volume_id)) == 0; | |
1577 | } | |
1578 | ||
1579 | enum pqi_find_result { | |
1580 | DEVICE_NOT_FOUND, | |
1581 | DEVICE_CHANGED, | |
1582 | DEVICE_SAME, | |
1583 | }; | |
1584 | ||
1585 | static enum pqi_find_result pqi_scsi_find_entry(struct pqi_ctrl_info *ctrl_info, | |
1586 | struct pqi_scsi_dev *device_to_find, | |
1587 | struct pqi_scsi_dev **matching_device) | |
1588 | { | |
1589 | struct pqi_scsi_dev *device; | |
1590 | ||
1591 | list_for_each_entry(device, &ctrl_info->scsi_device_list, | |
1592 | scsi_device_list_entry) { | |
1593 | if (pqi_scsi3addr_equal(device_to_find->scsi3addr, | |
1594 | device->scsi3addr)) { | |
1595 | *matching_device = device; | |
1596 | if (pqi_device_equal(device_to_find, device)) { | |
1597 | if (device_to_find->volume_offline) | |
1598 | return DEVICE_CHANGED; | |
1599 | return DEVICE_SAME; | |
1600 | } | |
1601 | return DEVICE_CHANGED; | |
1602 | } | |
1603 | } | |
1604 | ||
1605 | return DEVICE_NOT_FOUND; | |
1606 | } | |
1607 | ||
3d46a59a DB |
1608 | static inline const char *pqi_device_type(struct pqi_scsi_dev *device) |
1609 | { | |
1610 | if (device->is_expander_smp_device) | |
1611 | return "Enclosure SMP "; | |
1612 | ||
1613 | return scsi_device_type(device->devtype); | |
1614 | } | |
1615 | ||
6de783f6 KB |
1616 | #define PQI_DEV_INFO_BUFFER_LENGTH 128 |
1617 | ||
6c223761 KB |
1618 | static void pqi_dev_info(struct pqi_ctrl_info *ctrl_info, |
1619 | char *action, struct pqi_scsi_dev *device) | |
1620 | { | |
6de783f6 KB |
1621 | ssize_t count; |
1622 | char buffer[PQI_DEV_INFO_BUFFER_LENGTH]; | |
1623 | ||
1624 | count = snprintf(buffer, PQI_DEV_INFO_BUFFER_LENGTH, | |
1625 | "%d:%d:", ctrl_info->scsi_host->host_no, device->bus); | |
1626 | ||
1627 | if (device->target_lun_valid) | |
181aea89 | 1628 | count += scnprintf(buffer + count, |
6de783f6 KB |
1629 | PQI_DEV_INFO_BUFFER_LENGTH - count, |
1630 | "%d:%d", | |
1631 | device->target, | |
1632 | device->lun); | |
1633 | else | |
181aea89 | 1634 | count += scnprintf(buffer + count, |
6de783f6 KB |
1635 | PQI_DEV_INFO_BUFFER_LENGTH - count, |
1636 | "-:-"); | |
1637 | ||
1638 | if (pqi_is_logical_device(device)) | |
181aea89 | 1639 | count += scnprintf(buffer + count, |
6de783f6 KB |
1640 | PQI_DEV_INFO_BUFFER_LENGTH - count, |
1641 | " %08x%08x", | |
1642 | *((u32 *)&device->scsi3addr), | |
1643 | *((u32 *)&device->scsi3addr[4])); | |
1644 | else | |
181aea89 | 1645 | count += scnprintf(buffer + count, |
6de783f6 KB |
1646 | PQI_DEV_INFO_BUFFER_LENGTH - count, |
1647 | " %016llx", device->sas_address); | |
1648 | ||
181aea89 | 1649 | count += scnprintf(buffer + count, PQI_DEV_INFO_BUFFER_LENGTH - count, |
6de783f6 | 1650 | " %s %.8s %.16s ", |
3d46a59a | 1651 | pqi_device_type(device), |
6c223761 | 1652 | device->vendor, |
6de783f6 KB |
1653 | device->model); |
1654 | ||
1655 | if (pqi_is_logical_device(device)) { | |
1656 | if (device->devtype == TYPE_DISK) | |
181aea89 | 1657 | count += scnprintf(buffer + count, |
6de783f6 KB |
1658 | PQI_DEV_INFO_BUFFER_LENGTH - count, |
1659 | "SSDSmartPathCap%c En%c %-12s", | |
588a63fe KB |
1660 | device->raid_bypass_configured ? '+' : '-', |
1661 | device->raid_bypass_enabled ? '+' : '-', | |
6de783f6 KB |
1662 | pqi_raid_level_to_string(device->raid_level)); |
1663 | } else { | |
181aea89 | 1664 | count += scnprintf(buffer + count, |
6de783f6 KB |
1665 | PQI_DEV_INFO_BUFFER_LENGTH - count, |
1666 | "AIO%c", device->aio_enabled ? '+' : '-'); | |
1667 | if (device->devtype == TYPE_DISK || | |
1668 | device->devtype == TYPE_ZBC) | |
181aea89 | 1669 | count += scnprintf(buffer + count, |
6de783f6 KB |
1670 | PQI_DEV_INFO_BUFFER_LENGTH - count, |
1671 | " qd=%-6d", device->queue_depth); | |
1672 | } | |
1673 | ||
1674 | dev_info(&ctrl_info->pci_dev->dev, "%s %s\n", action, buffer); | |
6c223761 KB |
1675 | } |
1676 | ||
1677 | /* Assumes the SCSI device list lock is held. */ | |
1678 | ||
1679 | static void pqi_scsi_update_device(struct pqi_scsi_dev *existing_device, | |
1680 | struct pqi_scsi_dev *new_device) | |
1681 | { | |
1682 | existing_device->devtype = new_device->devtype; | |
1683 | existing_device->device_type = new_device->device_type; | |
1684 | existing_device->bus = new_device->bus; | |
1685 | if (new_device->target_lun_valid) { | |
1686 | existing_device->target = new_device->target; | |
1687 | existing_device->lun = new_device->lun; | |
1688 | existing_device->target_lun_valid = true; | |
1689 | } | |
1690 | ||
244ca45e MR |
1691 | if ((existing_device->volume_status == CISS_LV_QUEUED_FOR_EXPANSION || |
1692 | existing_device->volume_status == CISS_LV_UNDERGOING_EXPANSION) && | |
1693 | new_device->volume_status == CISS_LV_OK) | |
1694 | existing_device->rescan = true; | |
1695 | ||
6c223761 KB |
1696 | /* By definition, the scsi3addr and wwid fields are already the same. */ |
1697 | ||
1698 | existing_device->is_physical_device = new_device->is_physical_device; | |
bd10cf0b KB |
1699 | existing_device->is_external_raid_device = |
1700 | new_device->is_external_raid_device; | |
3d46a59a DB |
1701 | existing_device->is_expander_smp_device = |
1702 | new_device->is_expander_smp_device; | |
6c223761 KB |
1703 | existing_device->aio_enabled = new_device->aio_enabled; |
1704 | memcpy(existing_device->vendor, new_device->vendor, | |
1705 | sizeof(existing_device->vendor)); | |
1706 | memcpy(existing_device->model, new_device->model, | |
1707 | sizeof(existing_device->model)); | |
1708 | existing_device->sas_address = new_device->sas_address; | |
1709 | existing_device->raid_level = new_device->raid_level; | |
1710 | existing_device->queue_depth = new_device->queue_depth; | |
1711 | existing_device->aio_handle = new_device->aio_handle; | |
1712 | existing_device->volume_status = new_device->volume_status; | |
1713 | existing_device->active_path_index = new_device->active_path_index; | |
1714 | existing_device->path_map = new_device->path_map; | |
1715 | existing_device->bay = new_device->bay; | |
2d2ad4bc GW |
1716 | existing_device->box_index = new_device->box_index; |
1717 | existing_device->phys_box_on_bus = new_device->phys_box_on_bus; | |
1718 | existing_device->phy_connected_dev_type = | |
1719 | new_device->phy_connected_dev_type; | |
6c223761 KB |
1720 | memcpy(existing_device->box, new_device->box, |
1721 | sizeof(existing_device->box)); | |
1722 | memcpy(existing_device->phys_connector, new_device->phys_connector, | |
1723 | sizeof(existing_device->phys_connector)); | |
6c223761 KB |
1724 | existing_device->offload_to_mirror = 0; |
1725 | kfree(existing_device->raid_map); | |
1726 | existing_device->raid_map = new_device->raid_map; | |
588a63fe KB |
1727 | existing_device->raid_bypass_configured = |
1728 | new_device->raid_bypass_configured; | |
1729 | existing_device->raid_bypass_enabled = | |
1730 | new_device->raid_bypass_enabled; | |
a9a68101 | 1731 | existing_device->device_offline = false; |
6c223761 KB |
1732 | |
1733 | /* To prevent this from being freed later. */ | |
1734 | new_device->raid_map = NULL; | |
1735 | } | |
1736 | ||
1737 | static inline void pqi_free_device(struct pqi_scsi_dev *device) | |
1738 | { | |
1739 | if (device) { | |
1740 | kfree(device->raid_map); | |
1741 | kfree(device); | |
1742 | } | |
1743 | } | |
1744 | ||
1745 | /* | |
1746 | * Called when exposing a new device to the OS fails in order to re-adjust | |
1747 | * our internal SCSI device list to match the SCSI ML's view. | |
1748 | */ | |
1749 | ||
1750 | static inline void pqi_fixup_botched_add(struct pqi_ctrl_info *ctrl_info, | |
1751 | struct pqi_scsi_dev *device) | |
1752 | { | |
1753 | unsigned long flags; | |
1754 | ||
1755 | spin_lock_irqsave(&ctrl_info->scsi_device_list_lock, flags); | |
1756 | list_del(&device->scsi_device_list_entry); | |
1757 | spin_unlock_irqrestore(&ctrl_info->scsi_device_list_lock, flags); | |
1758 | ||
1759 | /* Allow the device structure to be freed later. */ | |
1760 | device->keep_device = false; | |
1761 | } | |
1762 | ||
3d46a59a DB |
1763 | static inline bool pqi_is_device_added(struct pqi_scsi_dev *device) |
1764 | { | |
1765 | if (device->is_expander_smp_device) | |
1766 | return device->sas_port != NULL; | |
1767 | ||
1768 | return device->sdev != NULL; | |
1769 | } | |
1770 | ||
6c223761 KB |
1771 | static void pqi_update_device_list(struct pqi_ctrl_info *ctrl_info, |
1772 | struct pqi_scsi_dev *new_device_list[], unsigned int num_new_devices) | |
1773 | { | |
1774 | int rc; | |
1775 | unsigned int i; | |
1776 | unsigned long flags; | |
1777 | enum pqi_find_result find_result; | |
1778 | struct pqi_scsi_dev *device; | |
1779 | struct pqi_scsi_dev *next; | |
1780 | struct pqi_scsi_dev *matching_device; | |
8a994a04 KB |
1781 | LIST_HEAD(add_list); |
1782 | LIST_HEAD(delete_list); | |
6c223761 KB |
1783 | |
1784 | /* | |
1785 | * The idea here is to do as little work as possible while holding the | |
1786 | * spinlock. That's why we go to great pains to defer anything other | |
1787 | * than updating the internal device list until after we release the | |
1788 | * spinlock. | |
1789 | */ | |
1790 | ||
1791 | spin_lock_irqsave(&ctrl_info->scsi_device_list_lock, flags); | |
1792 | ||
1793 | /* Assume that all devices in the existing list have gone away. */ | |
1794 | list_for_each_entry(device, &ctrl_info->scsi_device_list, | |
1795 | scsi_device_list_entry) | |
1796 | device->device_gone = true; | |
1797 | ||
1798 | for (i = 0; i < num_new_devices; i++) { | |
1799 | device = new_device_list[i]; | |
1800 | ||
1801 | find_result = pqi_scsi_find_entry(ctrl_info, device, | |
694c5d5b | 1802 | &matching_device); |
6c223761 KB |
1803 | |
1804 | switch (find_result) { | |
1805 | case DEVICE_SAME: | |
1806 | /* | |
1807 | * The newly found device is already in the existing | |
1808 | * device list. | |
1809 | */ | |
1810 | device->new_device = false; | |
1811 | matching_device->device_gone = false; | |
1812 | pqi_scsi_update_device(matching_device, device); | |
1813 | break; | |
1814 | case DEVICE_NOT_FOUND: | |
1815 | /* | |
1816 | * The newly found device is NOT in the existing device | |
1817 | * list. | |
1818 | */ | |
1819 | device->new_device = true; | |
1820 | break; | |
1821 | case DEVICE_CHANGED: | |
1822 | /* | |
1823 | * The original device has gone away and we need to add | |
1824 | * the new device. | |
1825 | */ | |
1826 | device->new_device = true; | |
1827 | break; | |
6c223761 KB |
1828 | } |
1829 | } | |
1830 | ||
1831 | /* Process all devices that have gone away. */ | |
1832 | list_for_each_entry_safe(device, next, &ctrl_info->scsi_device_list, | |
1833 | scsi_device_list_entry) { | |
1834 | if (device->device_gone) { | |
1835 | list_del(&device->scsi_device_list_entry); | |
1836 | list_add_tail(&device->delete_list_entry, &delete_list); | |
1837 | } | |
1838 | } | |
1839 | ||
1840 | /* Process all new devices. */ | |
1841 | for (i = 0; i < num_new_devices; i++) { | |
1842 | device = new_device_list[i]; | |
1843 | if (!device->new_device) | |
1844 | continue; | |
1845 | if (device->volume_offline) | |
1846 | continue; | |
1847 | list_add_tail(&device->scsi_device_list_entry, | |
1848 | &ctrl_info->scsi_device_list); | |
1849 | list_add_tail(&device->add_list_entry, &add_list); | |
1850 | /* To prevent this device structure from being freed later. */ | |
1851 | device->keep_device = true; | |
1852 | } | |
1853 | ||
6c223761 KB |
1854 | spin_unlock_irqrestore(&ctrl_info->scsi_device_list_lock, flags); |
1855 | ||
4fd22c13 MR |
1856 | if (pqi_ctrl_in_ofa(ctrl_info)) |
1857 | pqi_ctrl_ofa_done(ctrl_info); | |
1858 | ||
6c223761 KB |
1859 | /* Remove all devices that have gone away. */ |
1860 | list_for_each_entry_safe(device, next, &delete_list, | |
1861 | delete_list_entry) { | |
6c223761 KB |
1862 | if (device->volume_offline) { |
1863 | pqi_dev_info(ctrl_info, "offline", device); | |
1864 | pqi_show_volume_status(ctrl_info, device); | |
1865 | } else { | |
1866 | pqi_dev_info(ctrl_info, "removed", device); | |
1867 | } | |
3d46a59a | 1868 | if (pqi_is_device_added(device)) |
6de783f6 | 1869 | pqi_remove_device(ctrl_info, device); |
6c223761 KB |
1870 | list_del(&device->delete_list_entry); |
1871 | pqi_free_device(device); | |
1872 | } | |
1873 | ||
1874 | /* | |
1875 | * Notify the SCSI ML if the queue depth of any existing device has | |
1876 | * changed. | |
1877 | */ | |
1878 | list_for_each_entry(device, &ctrl_info->scsi_device_list, | |
1879 | scsi_device_list_entry) { | |
244ca45e MR |
1880 | if (device->sdev) { |
1881 | if (device->queue_depth != | |
1882 | device->advertised_queue_depth) { | |
1883 | device->advertised_queue_depth = device->queue_depth; | |
1884 | scsi_change_queue_depth(device->sdev, | |
1885 | device->advertised_queue_depth); | |
1886 | } | |
1887 | if (device->rescan) { | |
1888 | scsi_rescan_device(&device->sdev->sdev_gendev); | |
1889 | device->rescan = false; | |
1890 | } | |
6c223761 KB |
1891 | } |
1892 | } | |
1893 | ||
1894 | /* Expose any new devices. */ | |
1895 | list_for_each_entry_safe(device, next, &add_list, add_list_entry) { | |
3d46a59a | 1896 | if (!pqi_is_device_added(device)) { |
6c223761 | 1897 | rc = pqi_add_device(ctrl_info, device); |
ce143793 KB |
1898 | if (rc == 0) { |
1899 | pqi_dev_info(ctrl_info, "added", device); | |
1900 | } else { | |
6c223761 KB |
1901 | dev_warn(&ctrl_info->pci_dev->dev, |
1902 | "scsi %d:%d:%d:%d addition failed, device not added\n", | |
1903 | ctrl_info->scsi_host->host_no, | |
1904 | device->bus, device->target, | |
1905 | device->lun); | |
1906 | pqi_fixup_botched_add(ctrl_info, device); | |
6c223761 KB |
1907 | } |
1908 | } | |
6c223761 KB |
1909 | } |
1910 | } | |
1911 | ||
ce143793 | 1912 | static inline bool pqi_is_supported_device(struct pqi_scsi_dev *device) |
6c223761 | 1913 | { |
ce143793 KB |
1914 | /* |
1915 | * Only support the HBA controller itself as a RAID | |
1916 | * controller. If it's a RAID controller other than | |
1917 | * the HBA itself (an external RAID controller, for | |
1918 | * example), we don't support it. | |
1919 | */ | |
1920 | if (device->device_type == SA_DEVICE_TYPE_CONTROLLER && | |
1921 | !pqi_is_hba_lunid(device->scsi3addr)) | |
1922 | return false; | |
6c223761 | 1923 | |
ce143793 | 1924 | return true; |
6c223761 KB |
1925 | } |
1926 | ||
94086f5b | 1927 | static inline bool pqi_skip_device(u8 *scsi3addr) |
6c223761 | 1928 | { |
94086f5b KB |
1929 | /* Ignore all masked devices. */ |
1930 | if (MASKED_DEVICE(scsi3addr)) | |
6c223761 | 1931 | return true; |
6c223761 KB |
1932 | |
1933 | return false; | |
1934 | } | |
1935 | ||
522bc026 DC |
1936 | static inline void pqi_mask_device(u8 *scsi3addr) |
1937 | { | |
1938 | scsi3addr[3] |= 0xc0; | |
1939 | } | |
1940 | ||
3d46a59a DB |
1941 | static inline bool pqi_is_device_with_sas_address(struct pqi_scsi_dev *device) |
1942 | { | |
ce143793 KB |
1943 | switch (device->device_type) { |
1944 | case SA_DEVICE_TYPE_SAS: | |
1945 | case SA_DEVICE_TYPE_EXPANDER_SMP: | |
1946 | case SA_DEVICE_TYPE_SES: | |
3d46a59a DB |
1947 | return true; |
1948 | } | |
1949 | ||
1950 | return false; | |
1951 | } | |
1952 | ||
cd128244 DC |
1953 | static inline bool pqi_expose_device(struct pqi_scsi_dev *device) |
1954 | { | |
1955 | return !device->is_physical_device || | |
1956 | !pqi_skip_device(device->scsi3addr); | |
1957 | } | |
1958 | ||
6c223761 KB |
1959 | static int pqi_update_scsi_devices(struct pqi_ctrl_info *ctrl_info) |
1960 | { | |
1961 | int i; | |
1962 | int rc; | |
8a994a04 | 1963 | LIST_HEAD(new_device_list_head); |
6c223761 KB |
1964 | struct report_phys_lun_extended *physdev_list = NULL; |
1965 | struct report_log_lun_extended *logdev_list = NULL; | |
1966 | struct report_phys_lun_extended_entry *phys_lun_ext_entry; | |
1967 | struct report_log_lun_extended_entry *log_lun_ext_entry; | |
1968 | struct bmic_identify_physical_device *id_phys = NULL; | |
1969 | u32 num_physicals; | |
1970 | u32 num_logicals; | |
1971 | struct pqi_scsi_dev **new_device_list = NULL; | |
1972 | struct pqi_scsi_dev *device; | |
1973 | struct pqi_scsi_dev *next; | |
1974 | unsigned int num_new_devices; | |
1975 | unsigned int num_valid_devices; | |
1976 | bool is_physical_device; | |
1977 | u8 *scsi3addr; | |
5e6a9760 GW |
1978 | unsigned int physical_index; |
1979 | unsigned int logical_index; | |
6c223761 | 1980 | static char *out_of_memory_msg = |
6de783f6 | 1981 | "failed to allocate memory, device discovery stopped"; |
6c223761 | 1982 | |
6c223761 KB |
1983 | rc = pqi_get_device_lists(ctrl_info, &physdev_list, &logdev_list); |
1984 | if (rc) | |
1985 | goto out; | |
1986 | ||
1987 | if (physdev_list) | |
1988 | num_physicals = | |
1989 | get_unaligned_be32(&physdev_list->header.list_length) | |
1990 | / sizeof(physdev_list->lun_entries[0]); | |
1991 | else | |
1992 | num_physicals = 0; | |
1993 | ||
1994 | if (logdev_list) | |
1995 | num_logicals = | |
1996 | get_unaligned_be32(&logdev_list->header.list_length) | |
1997 | / sizeof(logdev_list->lun_entries[0]); | |
1998 | else | |
1999 | num_logicals = 0; | |
2000 | ||
2001 | if (num_physicals) { | |
2002 | /* | |
2003 | * We need this buffer for calls to pqi_get_physical_disk_info() | |
2004 | * below. We allocate it here instead of inside | |
2005 | * pqi_get_physical_disk_info() because it's a fairly large | |
2006 | * buffer. | |
2007 | */ | |
2008 | id_phys = kmalloc(sizeof(*id_phys), GFP_KERNEL); | |
2009 | if (!id_phys) { | |
2010 | dev_warn(&ctrl_info->pci_dev->dev, "%s\n", | |
2011 | out_of_memory_msg); | |
2012 | rc = -ENOMEM; | |
2013 | goto out; | |
2014 | } | |
522bc026 | 2015 | |
694c5d5b | 2016 | if (pqi_hide_vsep) { |
522bc026 DC |
2017 | for (i = num_physicals - 1; i >= 0; i--) { |
2018 | phys_lun_ext_entry = | |
2019 | &physdev_list->lun_entries[i]; | |
2020 | if (CISS_GET_DRIVE_NUMBER( | |
2021 | phys_lun_ext_entry->lunid) == | |
2022 | PQI_VSEP_CISS_BTL) { | |
2023 | pqi_mask_device( | |
2024 | phys_lun_ext_entry->lunid); | |
2025 | break; | |
2026 | } | |
2027 | } | |
2028 | } | |
6c223761 KB |
2029 | } |
2030 | ||
2031 | num_new_devices = num_physicals + num_logicals; | |
2032 | ||
6da2ec56 KC |
2033 | new_device_list = kmalloc_array(num_new_devices, |
2034 | sizeof(*new_device_list), | |
2035 | GFP_KERNEL); | |
6c223761 KB |
2036 | if (!new_device_list) { |
2037 | dev_warn(&ctrl_info->pci_dev->dev, "%s\n", out_of_memory_msg); | |
2038 | rc = -ENOMEM; | |
2039 | goto out; | |
2040 | } | |
2041 | ||
2042 | for (i = 0; i < num_new_devices; i++) { | |
2043 | device = kzalloc(sizeof(*device), GFP_KERNEL); | |
2044 | if (!device) { | |
2045 | dev_warn(&ctrl_info->pci_dev->dev, "%s\n", | |
2046 | out_of_memory_msg); | |
2047 | rc = -ENOMEM; | |
2048 | goto out; | |
2049 | } | |
2050 | list_add_tail(&device->new_device_list_entry, | |
2051 | &new_device_list_head); | |
2052 | } | |
2053 | ||
2054 | device = NULL; | |
2055 | num_valid_devices = 0; | |
5e6a9760 GW |
2056 | physical_index = 0; |
2057 | logical_index = 0; | |
6c223761 KB |
2058 | |
2059 | for (i = 0; i < num_new_devices; i++) { | |
2060 | ||
5e6a9760 GW |
2061 | if ((!pqi_expose_ld_first && i < num_physicals) || |
2062 | (pqi_expose_ld_first && i >= num_logicals)) { | |
6c223761 | 2063 | is_physical_device = true; |
5e6a9760 GW |
2064 | phys_lun_ext_entry = |
2065 | &physdev_list->lun_entries[physical_index++]; | |
6c223761 KB |
2066 | log_lun_ext_entry = NULL; |
2067 | scsi3addr = phys_lun_ext_entry->lunid; | |
2068 | } else { | |
2069 | is_physical_device = false; | |
2070 | phys_lun_ext_entry = NULL; | |
2071 | log_lun_ext_entry = | |
5e6a9760 | 2072 | &logdev_list->lun_entries[logical_index++]; |
6c223761 KB |
2073 | scsi3addr = log_lun_ext_entry->lunid; |
2074 | } | |
2075 | ||
94086f5b | 2076 | if (is_physical_device && pqi_skip_device(scsi3addr)) |
6c223761 KB |
2077 | continue; |
2078 | ||
2079 | if (device) | |
2080 | device = list_next_entry(device, new_device_list_entry); | |
2081 | else | |
2082 | device = list_first_entry(&new_device_list_head, | |
2083 | struct pqi_scsi_dev, new_device_list_entry); | |
2084 | ||
2085 | memcpy(device->scsi3addr, scsi3addr, sizeof(device->scsi3addr)); | |
2086 | device->is_physical_device = is_physical_device; | |
3d46a59a | 2087 | if (is_physical_device) { |
ce143793 KB |
2088 | device->device_type = phys_lun_ext_entry->device_type; |
2089 | if (device->device_type == SA_DEVICE_TYPE_EXPANDER_SMP) | |
3d46a59a DB |
2090 | device->is_expander_smp_device = true; |
2091 | } else { | |
bd10cf0b KB |
2092 | device->is_external_raid_device = |
2093 | pqi_is_external_raid_addr(scsi3addr); | |
3d46a59a | 2094 | } |
6c223761 | 2095 | |
ce143793 KB |
2096 | if (!pqi_is_supported_device(device)) |
2097 | continue; | |
2098 | ||
6c223761 | 2099 | /* Gather information about the device. */ |
ce143793 | 2100 | rc = pqi_get_device_info(ctrl_info, device, id_phys); |
6c223761 KB |
2101 | if (rc == -ENOMEM) { |
2102 | dev_warn(&ctrl_info->pci_dev->dev, "%s\n", | |
2103 | out_of_memory_msg); | |
2104 | goto out; | |
2105 | } | |
2106 | if (rc) { | |
6de783f6 KB |
2107 | if (device->is_physical_device) |
2108 | dev_warn(&ctrl_info->pci_dev->dev, | |
2109 | "obtaining device info failed, skipping physical device %016llx\n", | |
2110 | get_unaligned_be64( | |
2111 | &phys_lun_ext_entry->wwid)); | |
2112 | else | |
2113 | dev_warn(&ctrl_info->pci_dev->dev, | |
2114 | "obtaining device info failed, skipping logical device %08x%08x\n", | |
2115 | *((u32 *)&device->scsi3addr), | |
2116 | *((u32 *)&device->scsi3addr[4])); | |
6c223761 KB |
2117 | rc = 0; |
2118 | continue; | |
2119 | } | |
2120 | ||
6c223761 KB |
2121 | pqi_assign_bus_target_lun(device); |
2122 | ||
6c223761 KB |
2123 | if (device->is_physical_device) { |
2124 | device->wwid = phys_lun_ext_entry->wwid; | |
2125 | if ((phys_lun_ext_entry->device_flags & | |
694c5d5b | 2126 | CISS_REPORT_PHYS_DEV_FLAG_AIO_ENABLED) && |
3d46a59a | 2127 | phys_lun_ext_entry->aio_handle) { |
6c223761 | 2128 | device->aio_enabled = true; |
9e322310 CIK |
2129 | device->aio_handle = |
2130 | phys_lun_ext_entry->aio_handle; | |
3d46a59a | 2131 | } |
6c223761 KB |
2132 | } else { |
2133 | memcpy(device->volume_id, log_lun_ext_entry->volume_id, | |
2134 | sizeof(device->volume_id)); | |
2135 | } | |
2136 | ||
3d46a59a DB |
2137 | if (pqi_is_device_with_sas_address(device)) |
2138 | device->sas_address = get_unaligned_be64(&device->wwid); | |
6c223761 KB |
2139 | |
2140 | new_device_list[num_valid_devices++] = device; | |
2141 | } | |
2142 | ||
2143 | pqi_update_device_list(ctrl_info, new_device_list, num_valid_devices); | |
2144 | ||
2145 | out: | |
2146 | list_for_each_entry_safe(device, next, &new_device_list_head, | |
2147 | new_device_list_entry) { | |
2148 | if (device->keep_device) | |
2149 | continue; | |
2150 | list_del(&device->new_device_list_entry); | |
2151 | pqi_free_device(device); | |
2152 | } | |
2153 | ||
2154 | kfree(new_device_list); | |
2155 | kfree(physdev_list); | |
2156 | kfree(logdev_list); | |
2157 | kfree(id_phys); | |
2158 | ||
2159 | return rc; | |
2160 | } | |
2161 | ||
2162 | static void pqi_remove_all_scsi_devices(struct pqi_ctrl_info *ctrl_info) | |
2163 | { | |
2164 | unsigned long flags; | |
2165 | struct pqi_scsi_dev *device; | |
6c223761 | 2166 | |
a37ef745 KB |
2167 | while (1) { |
2168 | spin_lock_irqsave(&ctrl_info->scsi_device_list_lock, flags); | |
2169 | ||
2170 | device = list_first_entry_or_null(&ctrl_info->scsi_device_list, | |
2171 | struct pqi_scsi_dev, scsi_device_list_entry); | |
2172 | if (device) | |
2173 | list_del(&device->scsi_device_list_entry); | |
2174 | ||
2175 | spin_unlock_irqrestore(&ctrl_info->scsi_device_list_lock, | |
2176 | flags); | |
2177 | ||
2178 | if (!device) | |
2179 | break; | |
6c223761 | 2180 | |
3d46a59a | 2181 | if (pqi_is_device_added(device)) |
6c223761 | 2182 | pqi_remove_device(ctrl_info, device); |
6c223761 KB |
2183 | pqi_free_device(device); |
2184 | } | |
6c223761 KB |
2185 | } |
2186 | ||
2187 | static int pqi_scan_scsi_devices(struct pqi_ctrl_info *ctrl_info) | |
2188 | { | |
530dd8a7 | 2189 | int rc = 0; |
6c223761 KB |
2190 | |
2191 | if (pqi_ctrl_offline(ctrl_info)) | |
2192 | return -ENXIO; | |
2193 | ||
530dd8a7 | 2194 | if (!mutex_trylock(&ctrl_info->scan_mutex)) { |
5f310425 | 2195 | pqi_schedule_rescan_worker_delayed(ctrl_info); |
9946a398 | 2196 | rc = -EINPROGRESS; |
530dd8a7 MR |
2197 | } else { |
2198 | rc = pqi_update_scsi_devices(ctrl_info); | |
2199 | if (rc) | |
2200 | pqi_schedule_rescan_worker_delayed(ctrl_info); | |
2201 | mutex_unlock(&ctrl_info->scan_mutex); | |
2202 | } | |
6c223761 KB |
2203 | |
2204 | return rc; | |
2205 | } | |
2206 | ||
2207 | static void pqi_scan_start(struct Scsi_Host *shost) | |
2208 | { | |
4fd22c13 MR |
2209 | struct pqi_ctrl_info *ctrl_info; |
2210 | ||
2211 | ctrl_info = shost_to_hba(shost); | |
2212 | if (pqi_ctrl_in_ofa(ctrl_info)) | |
2213 | return; | |
2214 | ||
2215 | pqi_scan_scsi_devices(ctrl_info); | |
6c223761 KB |
2216 | } |
2217 | ||
2218 | /* Returns TRUE if scan is finished. */ | |
2219 | ||
2220 | static int pqi_scan_finished(struct Scsi_Host *shost, | |
2221 | unsigned long elapsed_time) | |
2222 | { | |
2223 | struct pqi_ctrl_info *ctrl_info; | |
2224 | ||
2225 | ctrl_info = shost_priv(shost); | |
2226 | ||
2227 | return !mutex_is_locked(&ctrl_info->scan_mutex); | |
2228 | } | |
2229 | ||
061ef06a KB |
2230 | static void pqi_wait_until_scan_finished(struct pqi_ctrl_info *ctrl_info) |
2231 | { | |
2232 | mutex_lock(&ctrl_info->scan_mutex); | |
2233 | mutex_unlock(&ctrl_info->scan_mutex); | |
2234 | } | |
2235 | ||
2236 | static void pqi_wait_until_lun_reset_finished(struct pqi_ctrl_info *ctrl_info) | |
2237 | { | |
2238 | mutex_lock(&ctrl_info->lun_reset_mutex); | |
2239 | mutex_unlock(&ctrl_info->lun_reset_mutex); | |
2240 | } | |
2241 | ||
4fd22c13 MR |
2242 | static void pqi_wait_until_ofa_finished(struct pqi_ctrl_info *ctrl_info) |
2243 | { | |
2244 | mutex_lock(&ctrl_info->ofa_mutex); | |
2245 | mutex_unlock(&ctrl_info->ofa_mutex); | |
2246 | } | |
2247 | ||
6c223761 KB |
2248 | static inline void pqi_set_encryption_info( |
2249 | struct pqi_encryption_info *encryption_info, struct raid_map *raid_map, | |
2250 | u64 first_block) | |
2251 | { | |
2252 | u32 volume_blk_size; | |
2253 | ||
2254 | /* | |
2255 | * Set the encryption tweak values based on logical block address. | |
2256 | * If the block size is 512, the tweak value is equal to the LBA. | |
2257 | * For other block sizes, tweak value is (LBA * block size) / 512. | |
2258 | */ | |
2259 | volume_blk_size = get_unaligned_le32(&raid_map->volume_blk_size); | |
2260 | if (volume_blk_size != 512) | |
2261 | first_block = (first_block * volume_blk_size) / 512; | |
2262 | ||
2263 | encryption_info->data_encryption_key_index = | |
2264 | get_unaligned_le16(&raid_map->data_encryption_key_index); | |
2265 | encryption_info->encrypt_tweak_lower = lower_32_bits(first_block); | |
2266 | encryption_info->encrypt_tweak_upper = upper_32_bits(first_block); | |
2267 | } | |
2268 | ||
2269 | /* | |
588a63fe | 2270 | * Attempt to perform RAID bypass mapping for a logical volume I/O. |
6c223761 KB |
2271 | */ |
2272 | ||
2273 | #define PQI_RAID_BYPASS_INELIGIBLE 1 | |
2274 | ||
2275 | static int pqi_raid_bypass_submit_scsi_cmd(struct pqi_ctrl_info *ctrl_info, | |
2276 | struct pqi_scsi_dev *device, struct scsi_cmnd *scmd, | |
2277 | struct pqi_queue_group *queue_group) | |
2278 | { | |
2279 | struct raid_map *raid_map; | |
2280 | bool is_write = false; | |
2281 | u32 map_index; | |
2282 | u64 first_block; | |
2283 | u64 last_block; | |
2284 | u32 block_cnt; | |
2285 | u32 blocks_per_row; | |
2286 | u64 first_row; | |
2287 | u64 last_row; | |
2288 | u32 first_row_offset; | |
2289 | u32 last_row_offset; | |
2290 | u32 first_column; | |
2291 | u32 last_column; | |
2292 | u64 r0_first_row; | |
2293 | u64 r0_last_row; | |
2294 | u32 r5or6_blocks_per_row; | |
2295 | u64 r5or6_first_row; | |
2296 | u64 r5or6_last_row; | |
2297 | u32 r5or6_first_row_offset; | |
2298 | u32 r5or6_last_row_offset; | |
2299 | u32 r5or6_first_column; | |
2300 | u32 r5or6_last_column; | |
2301 | u16 data_disks_per_row; | |
2302 | u32 total_disks_per_row; | |
2303 | u16 layout_map_count; | |
2304 | u32 stripesize; | |
2305 | u16 strip_size; | |
2306 | u32 first_group; | |
2307 | u32 last_group; | |
2308 | u32 current_group; | |
2309 | u32 map_row; | |
2310 | u32 aio_handle; | |
2311 | u64 disk_block; | |
2312 | u32 disk_block_cnt; | |
2313 | u8 cdb[16]; | |
2314 | u8 cdb_length; | |
2315 | int offload_to_mirror; | |
2316 | struct pqi_encryption_info *encryption_info_ptr; | |
2317 | struct pqi_encryption_info encryption_info; | |
2318 | #if BITS_PER_LONG == 32 | |
2319 | u64 tmpdiv; | |
2320 | #endif | |
2321 | ||
2322 | /* Check for valid opcode, get LBA and block count. */ | |
2323 | switch (scmd->cmnd[0]) { | |
2324 | case WRITE_6: | |
2325 | is_write = true; | |
2326 | /* fall through */ | |
2327 | case READ_6: | |
e018ef57 B |
2328 | first_block = (u64)(((scmd->cmnd[1] & 0x1f) << 16) | |
2329 | (scmd->cmnd[2] << 8) | scmd->cmnd[3]); | |
6c223761 KB |
2330 | block_cnt = (u32)scmd->cmnd[4]; |
2331 | if (block_cnt == 0) | |
2332 | block_cnt = 256; | |
2333 | break; | |
2334 | case WRITE_10: | |
2335 | is_write = true; | |
2336 | /* fall through */ | |
2337 | case READ_10: | |
2338 | first_block = (u64)get_unaligned_be32(&scmd->cmnd[2]); | |
2339 | block_cnt = (u32)get_unaligned_be16(&scmd->cmnd[7]); | |
2340 | break; | |
2341 | case WRITE_12: | |
2342 | is_write = true; | |
2343 | /* fall through */ | |
2344 | case READ_12: | |
2345 | first_block = (u64)get_unaligned_be32(&scmd->cmnd[2]); | |
2346 | block_cnt = get_unaligned_be32(&scmd->cmnd[6]); | |
2347 | break; | |
2348 | case WRITE_16: | |
2349 | is_write = true; | |
2350 | /* fall through */ | |
2351 | case READ_16: | |
2352 | first_block = get_unaligned_be64(&scmd->cmnd[2]); | |
2353 | block_cnt = get_unaligned_be32(&scmd->cmnd[10]); | |
2354 | break; | |
2355 | default: | |
2356 | /* Process via normal I/O path. */ | |
2357 | return PQI_RAID_BYPASS_INELIGIBLE; | |
2358 | } | |
2359 | ||
2360 | /* Check for write to non-RAID-0. */ | |
2361 | if (is_write && device->raid_level != SA_RAID_0) | |
2362 | return PQI_RAID_BYPASS_INELIGIBLE; | |
2363 | ||
2364 | if (unlikely(block_cnt == 0)) | |
2365 | return PQI_RAID_BYPASS_INELIGIBLE; | |
2366 | ||
2367 | last_block = first_block + block_cnt - 1; | |
2368 | raid_map = device->raid_map; | |
2369 | ||
2370 | /* Check for invalid block or wraparound. */ | |
2371 | if (last_block >= get_unaligned_le64(&raid_map->volume_blk_cnt) || | |
2372 | last_block < first_block) | |
2373 | return PQI_RAID_BYPASS_INELIGIBLE; | |
2374 | ||
2375 | data_disks_per_row = get_unaligned_le16(&raid_map->data_disks_per_row); | |
2376 | strip_size = get_unaligned_le16(&raid_map->strip_size); | |
2377 | layout_map_count = get_unaligned_le16(&raid_map->layout_map_count); | |
2378 | ||
2379 | /* Calculate stripe information for the request. */ | |
2380 | blocks_per_row = data_disks_per_row * strip_size; | |
2381 | #if BITS_PER_LONG == 32 | |
2382 | tmpdiv = first_block; | |
2383 | do_div(tmpdiv, blocks_per_row); | |
2384 | first_row = tmpdiv; | |
2385 | tmpdiv = last_block; | |
2386 | do_div(tmpdiv, blocks_per_row); | |
2387 | last_row = tmpdiv; | |
2388 | first_row_offset = (u32)(first_block - (first_row * blocks_per_row)); | |
2389 | last_row_offset = (u32)(last_block - (last_row * blocks_per_row)); | |
2390 | tmpdiv = first_row_offset; | |
2391 | do_div(tmpdiv, strip_size); | |
2392 | first_column = tmpdiv; | |
2393 | tmpdiv = last_row_offset; | |
2394 | do_div(tmpdiv, strip_size); | |
2395 | last_column = tmpdiv; | |
2396 | #else | |
2397 | first_row = first_block / blocks_per_row; | |
2398 | last_row = last_block / blocks_per_row; | |
2399 | first_row_offset = (u32)(first_block - (first_row * blocks_per_row)); | |
2400 | last_row_offset = (u32)(last_block - (last_row * blocks_per_row)); | |
2401 | first_column = first_row_offset / strip_size; | |
2402 | last_column = last_row_offset / strip_size; | |
2403 | #endif | |
2404 | ||
2405 | /* If this isn't a single row/column then give to the controller. */ | |
2406 | if (first_row != last_row || first_column != last_column) | |
2407 | return PQI_RAID_BYPASS_INELIGIBLE; | |
2408 | ||
2409 | /* Proceeding with driver mapping. */ | |
2410 | total_disks_per_row = data_disks_per_row + | |
2411 | get_unaligned_le16(&raid_map->metadata_disks_per_row); | |
2412 | map_row = ((u32)(first_row >> raid_map->parity_rotation_shift)) % | |
2413 | get_unaligned_le16(&raid_map->row_cnt); | |
2414 | map_index = (map_row * total_disks_per_row) + first_column; | |
2415 | ||
2416 | /* RAID 1 */ | |
2417 | if (device->raid_level == SA_RAID_1) { | |
2418 | if (device->offload_to_mirror) | |
2419 | map_index += data_disks_per_row; | |
2420 | device->offload_to_mirror = !device->offload_to_mirror; | |
2421 | } else if (device->raid_level == SA_RAID_ADM) { | |
2422 | /* RAID ADM */ | |
2423 | /* | |
2424 | * Handles N-way mirrors (R1-ADM) and R10 with # of drives | |
2425 | * divisible by 3. | |
2426 | */ | |
2427 | offload_to_mirror = device->offload_to_mirror; | |
2428 | if (offload_to_mirror == 0) { | |
2429 | /* use physical disk in the first mirrored group. */ | |
2430 | map_index %= data_disks_per_row; | |
2431 | } else { | |
2432 | do { | |
2433 | /* | |
2434 | * Determine mirror group that map_index | |
2435 | * indicates. | |
2436 | */ | |
2437 | current_group = map_index / data_disks_per_row; | |
2438 | ||
2439 | if (offload_to_mirror != current_group) { | |
2440 | if (current_group < | |
2441 | layout_map_count - 1) { | |
2442 | /* | |
2443 | * Select raid index from | |
2444 | * next group. | |
2445 | */ | |
2446 | map_index += data_disks_per_row; | |
2447 | current_group++; | |
2448 | } else { | |
2449 | /* | |
2450 | * Select raid index from first | |
2451 | * group. | |
2452 | */ | |
2453 | map_index %= data_disks_per_row; | |
2454 | current_group = 0; | |
2455 | } | |
2456 | } | |
2457 | } while (offload_to_mirror != current_group); | |
2458 | } | |
2459 | ||
2460 | /* Set mirror group to use next time. */ | |
2461 | offload_to_mirror = | |
2462 | (offload_to_mirror >= layout_map_count - 1) ? | |
2463 | 0 : offload_to_mirror + 1; | |
2464 | WARN_ON(offload_to_mirror >= layout_map_count); | |
2465 | device->offload_to_mirror = offload_to_mirror; | |
2466 | /* | |
2467 | * Avoid direct use of device->offload_to_mirror within this | |
2468 | * function since multiple threads might simultaneously | |
2469 | * increment it beyond the range of device->layout_map_count -1. | |
2470 | */ | |
2471 | } else if ((device->raid_level == SA_RAID_5 || | |
2472 | device->raid_level == SA_RAID_6) && layout_map_count > 1) { | |
2473 | /* RAID 50/60 */ | |
2474 | /* Verify first and last block are in same RAID group */ | |
2475 | r5or6_blocks_per_row = strip_size * data_disks_per_row; | |
2476 | stripesize = r5or6_blocks_per_row * layout_map_count; | |
2477 | #if BITS_PER_LONG == 32 | |
2478 | tmpdiv = first_block; | |
2479 | first_group = do_div(tmpdiv, stripesize); | |
2480 | tmpdiv = first_group; | |
2481 | do_div(tmpdiv, r5or6_blocks_per_row); | |
2482 | first_group = tmpdiv; | |
2483 | tmpdiv = last_block; | |
2484 | last_group = do_div(tmpdiv, stripesize); | |
2485 | tmpdiv = last_group; | |
2486 | do_div(tmpdiv, r5or6_blocks_per_row); | |
2487 | last_group = tmpdiv; | |
2488 | #else | |
2489 | first_group = (first_block % stripesize) / r5or6_blocks_per_row; | |
2490 | last_group = (last_block % stripesize) / r5or6_blocks_per_row; | |
2491 | #endif | |
2492 | if (first_group != last_group) | |
2493 | return PQI_RAID_BYPASS_INELIGIBLE; | |
2494 | ||
2495 | /* Verify request is in a single row of RAID 5/6 */ | |
2496 | #if BITS_PER_LONG == 32 | |
2497 | tmpdiv = first_block; | |
2498 | do_div(tmpdiv, stripesize); | |
2499 | first_row = r5or6_first_row = r0_first_row = tmpdiv; | |
2500 | tmpdiv = last_block; | |
2501 | do_div(tmpdiv, stripesize); | |
2502 | r5or6_last_row = r0_last_row = tmpdiv; | |
2503 | #else | |
2504 | first_row = r5or6_first_row = r0_first_row = | |
2505 | first_block / stripesize; | |
2506 | r5or6_last_row = r0_last_row = last_block / stripesize; | |
2507 | #endif | |
2508 | if (r5or6_first_row != r5or6_last_row) | |
2509 | return PQI_RAID_BYPASS_INELIGIBLE; | |
2510 | ||
2511 | /* Verify request is in a single column */ | |
2512 | #if BITS_PER_LONG == 32 | |
2513 | tmpdiv = first_block; | |
2514 | first_row_offset = do_div(tmpdiv, stripesize); | |
2515 | tmpdiv = first_row_offset; | |
2516 | first_row_offset = (u32)do_div(tmpdiv, r5or6_blocks_per_row); | |
2517 | r5or6_first_row_offset = first_row_offset; | |
2518 | tmpdiv = last_block; | |
2519 | r5or6_last_row_offset = do_div(tmpdiv, stripesize); | |
2520 | tmpdiv = r5or6_last_row_offset; | |
2521 | r5or6_last_row_offset = do_div(tmpdiv, r5or6_blocks_per_row); | |
2522 | tmpdiv = r5or6_first_row_offset; | |
2523 | do_div(tmpdiv, strip_size); | |
2524 | first_column = r5or6_first_column = tmpdiv; | |
2525 | tmpdiv = r5or6_last_row_offset; | |
2526 | do_div(tmpdiv, strip_size); | |
2527 | r5or6_last_column = tmpdiv; | |
2528 | #else | |
2529 | first_row_offset = r5or6_first_row_offset = | |
2530 | (u32)((first_block % stripesize) % | |
2531 | r5or6_blocks_per_row); | |
2532 | ||
2533 | r5or6_last_row_offset = | |
2534 | (u32)((last_block % stripesize) % | |
2535 | r5or6_blocks_per_row); | |
2536 | ||
2537 | first_column = r5or6_first_row_offset / strip_size; | |
2538 | r5or6_first_column = first_column; | |
2539 | r5or6_last_column = r5or6_last_row_offset / strip_size; | |
2540 | #endif | |
2541 | if (r5or6_first_column != r5or6_last_column) | |
2542 | return PQI_RAID_BYPASS_INELIGIBLE; | |
2543 | ||
2544 | /* Request is eligible */ | |
2545 | map_row = | |
2546 | ((u32)(first_row >> raid_map->parity_rotation_shift)) % | |
2547 | get_unaligned_le16(&raid_map->row_cnt); | |
2548 | ||
2549 | map_index = (first_group * | |
2550 | (get_unaligned_le16(&raid_map->row_cnt) * | |
2551 | total_disks_per_row)) + | |
2552 | (map_row * total_disks_per_row) + first_column; | |
2553 | } | |
2554 | ||
6c223761 KB |
2555 | aio_handle = raid_map->disk_data[map_index].aio_handle; |
2556 | disk_block = get_unaligned_le64(&raid_map->disk_starting_blk) + | |
2557 | first_row * strip_size + | |
2558 | (first_row_offset - first_column * strip_size); | |
2559 | disk_block_cnt = block_cnt; | |
2560 | ||
2561 | /* Handle differing logical/physical block sizes. */ | |
2562 | if (raid_map->phys_blk_shift) { | |
2563 | disk_block <<= raid_map->phys_blk_shift; | |
2564 | disk_block_cnt <<= raid_map->phys_blk_shift; | |
2565 | } | |
2566 | ||
2567 | if (unlikely(disk_block_cnt > 0xffff)) | |
2568 | return PQI_RAID_BYPASS_INELIGIBLE; | |
2569 | ||
2570 | /* Build the new CDB for the physical disk I/O. */ | |
2571 | if (disk_block > 0xffffffff) { | |
2572 | cdb[0] = is_write ? WRITE_16 : READ_16; | |
2573 | cdb[1] = 0; | |
2574 | put_unaligned_be64(disk_block, &cdb[2]); | |
2575 | put_unaligned_be32(disk_block_cnt, &cdb[10]); | |
2576 | cdb[14] = 0; | |
2577 | cdb[15] = 0; | |
2578 | cdb_length = 16; | |
2579 | } else { | |
2580 | cdb[0] = is_write ? WRITE_10 : READ_10; | |
2581 | cdb[1] = 0; | |
2582 | put_unaligned_be32((u32)disk_block, &cdb[2]); | |
2583 | cdb[6] = 0; | |
2584 | put_unaligned_be16((u16)disk_block_cnt, &cdb[7]); | |
2585 | cdb[9] = 0; | |
2586 | cdb_length = 10; | |
2587 | } | |
2588 | ||
2589 | if (get_unaligned_le16(&raid_map->flags) & | |
2590 | RAID_MAP_ENCRYPTION_ENABLED) { | |
2591 | pqi_set_encryption_info(&encryption_info, raid_map, | |
2592 | first_block); | |
2593 | encryption_info_ptr = &encryption_info; | |
2594 | } else { | |
2595 | encryption_info_ptr = NULL; | |
2596 | } | |
2597 | ||
2598 | return pqi_aio_submit_io(ctrl_info, scmd, aio_handle, | |
376fb880 | 2599 | cdb, cdb_length, queue_group, encryption_info_ptr, true); |
6c223761 KB |
2600 | } |
2601 | ||
2602 | #define PQI_STATUS_IDLE 0x0 | |
2603 | ||
2604 | #define PQI_CREATE_ADMIN_QUEUE_PAIR 1 | |
2605 | #define PQI_DELETE_ADMIN_QUEUE_PAIR 2 | |
2606 | ||
2607 | #define PQI_DEVICE_STATE_POWER_ON_AND_RESET 0x0 | |
2608 | #define PQI_DEVICE_STATE_STATUS_AVAILABLE 0x1 | |
2609 | #define PQI_DEVICE_STATE_ALL_REGISTERS_READY 0x2 | |
2610 | #define PQI_DEVICE_STATE_ADMIN_QUEUE_PAIR_READY 0x3 | |
2611 | #define PQI_DEVICE_STATE_ERROR 0x4 | |
2612 | ||
2613 | #define PQI_MODE_READY_TIMEOUT_SECS 30 | |
2614 | #define PQI_MODE_READY_POLL_INTERVAL_MSECS 1 | |
2615 | ||
2616 | static int pqi_wait_for_pqi_mode_ready(struct pqi_ctrl_info *ctrl_info) | |
2617 | { | |
2618 | struct pqi_device_registers __iomem *pqi_registers; | |
2619 | unsigned long timeout; | |
2620 | u64 signature; | |
2621 | u8 status; | |
2622 | ||
2623 | pqi_registers = ctrl_info->pqi_registers; | |
4fd22c13 | 2624 | timeout = (PQI_MODE_READY_TIMEOUT_SECS * PQI_HZ) + jiffies; |
6c223761 KB |
2625 | |
2626 | while (1) { | |
2627 | signature = readq(&pqi_registers->signature); | |
2628 | if (memcmp(&signature, PQI_DEVICE_SIGNATURE, | |
2629 | sizeof(signature)) == 0) | |
2630 | break; | |
2631 | if (time_after(jiffies, timeout)) { | |
2632 | dev_err(&ctrl_info->pci_dev->dev, | |
2633 | "timed out waiting for PQI signature\n"); | |
2634 | return -ETIMEDOUT; | |
2635 | } | |
2636 | msleep(PQI_MODE_READY_POLL_INTERVAL_MSECS); | |
2637 | } | |
2638 | ||
2639 | while (1) { | |
2640 | status = readb(&pqi_registers->function_and_status_code); | |
2641 | if (status == PQI_STATUS_IDLE) | |
2642 | break; | |
2643 | if (time_after(jiffies, timeout)) { | |
2644 | dev_err(&ctrl_info->pci_dev->dev, | |
2645 | "timed out waiting for PQI IDLE\n"); | |
2646 | return -ETIMEDOUT; | |
2647 | } | |
2648 | msleep(PQI_MODE_READY_POLL_INTERVAL_MSECS); | |
2649 | } | |
2650 | ||
2651 | while (1) { | |
2652 | if (readl(&pqi_registers->device_status) == | |
2653 | PQI_DEVICE_STATE_ALL_REGISTERS_READY) | |
2654 | break; | |
2655 | if (time_after(jiffies, timeout)) { | |
2656 | dev_err(&ctrl_info->pci_dev->dev, | |
2657 | "timed out waiting for PQI all registers ready\n"); | |
2658 | return -ETIMEDOUT; | |
2659 | } | |
2660 | msleep(PQI_MODE_READY_POLL_INTERVAL_MSECS); | |
2661 | } | |
2662 | ||
2663 | return 0; | |
2664 | } | |
2665 | ||
2666 | static inline void pqi_aio_path_disabled(struct pqi_io_request *io_request) | |
2667 | { | |
2668 | struct pqi_scsi_dev *device; | |
2669 | ||
2670 | device = io_request->scmd->device->hostdata; | |
588a63fe | 2671 | device->raid_bypass_enabled = false; |
376fb880 | 2672 | device->aio_enabled = false; |
6c223761 KB |
2673 | } |
2674 | ||
d87d5474 | 2675 | static inline void pqi_take_device_offline(struct scsi_device *sdev, char *path) |
6c223761 KB |
2676 | { |
2677 | struct pqi_ctrl_info *ctrl_info; | |
e58081a7 | 2678 | struct pqi_scsi_dev *device; |
6c223761 | 2679 | |
03b288cf KB |
2680 | device = sdev->hostdata; |
2681 | if (device->device_offline) | |
2682 | return; | |
2683 | ||
2684 | device->device_offline = true; | |
03b288cf KB |
2685 | ctrl_info = shost_to_hba(sdev->host); |
2686 | pqi_schedule_rescan_worker(ctrl_info); | |
a9a68101 | 2687 | dev_err(&ctrl_info->pci_dev->dev, "re-scanning %s scsi %d:%d:%d:%d\n", |
03b288cf KB |
2688 | path, ctrl_info->scsi_host->host_no, device->bus, |
2689 | device->target, device->lun); | |
6c223761 KB |
2690 | } |
2691 | ||
2692 | static void pqi_process_raid_io_error(struct pqi_io_request *io_request) | |
2693 | { | |
2694 | u8 scsi_status; | |
2695 | u8 host_byte; | |
2696 | struct scsi_cmnd *scmd; | |
2697 | struct pqi_raid_error_info *error_info; | |
2698 | size_t sense_data_length; | |
2699 | int residual_count; | |
2700 | int xfer_count; | |
2701 | struct scsi_sense_hdr sshdr; | |
2702 | ||
2703 | scmd = io_request->scmd; | |
2704 | if (!scmd) | |
2705 | return; | |
2706 | ||
2707 | error_info = io_request->error_info; | |
2708 | scsi_status = error_info->status; | |
2709 | host_byte = DID_OK; | |
2710 | ||
f5b63206 KB |
2711 | switch (error_info->data_out_result) { |
2712 | case PQI_DATA_IN_OUT_GOOD: | |
2713 | break; | |
2714 | case PQI_DATA_IN_OUT_UNDERFLOW: | |
6c223761 KB |
2715 | xfer_count = |
2716 | get_unaligned_le32(&error_info->data_out_transferred); | |
2717 | residual_count = scsi_bufflen(scmd) - xfer_count; | |
2718 | scsi_set_resid(scmd, residual_count); | |
2719 | if (xfer_count < scmd->underflow) | |
2720 | host_byte = DID_SOFT_ERROR; | |
f5b63206 KB |
2721 | break; |
2722 | case PQI_DATA_IN_OUT_UNSOLICITED_ABORT: | |
2723 | case PQI_DATA_IN_OUT_ABORTED: | |
2724 | host_byte = DID_ABORT; | |
2725 | break; | |
2726 | case PQI_DATA_IN_OUT_TIMEOUT: | |
2727 | host_byte = DID_TIME_OUT; | |
2728 | break; | |
2729 | case PQI_DATA_IN_OUT_BUFFER_OVERFLOW: | |
2730 | case PQI_DATA_IN_OUT_PROTOCOL_ERROR: | |
2731 | case PQI_DATA_IN_OUT_BUFFER_ERROR: | |
2732 | case PQI_DATA_IN_OUT_BUFFER_OVERFLOW_DESCRIPTOR_AREA: | |
2733 | case PQI_DATA_IN_OUT_BUFFER_OVERFLOW_BRIDGE: | |
2734 | case PQI_DATA_IN_OUT_ERROR: | |
2735 | case PQI_DATA_IN_OUT_HARDWARE_ERROR: | |
2736 | case PQI_DATA_IN_OUT_PCIE_FABRIC_ERROR: | |
2737 | case PQI_DATA_IN_OUT_PCIE_COMPLETION_TIMEOUT: | |
2738 | case PQI_DATA_IN_OUT_PCIE_COMPLETER_ABORT_RECEIVED: | |
2739 | case PQI_DATA_IN_OUT_PCIE_UNSUPPORTED_REQUEST_RECEIVED: | |
2740 | case PQI_DATA_IN_OUT_PCIE_ECRC_CHECK_FAILED: | |
2741 | case PQI_DATA_IN_OUT_PCIE_UNSUPPORTED_REQUEST: | |
2742 | case PQI_DATA_IN_OUT_PCIE_ACS_VIOLATION: | |
2743 | case PQI_DATA_IN_OUT_PCIE_TLP_PREFIX_BLOCKED: | |
2744 | case PQI_DATA_IN_OUT_PCIE_POISONED_MEMORY_READ: | |
2745 | default: | |
2746 | host_byte = DID_ERROR; | |
2747 | break; | |
6c223761 KB |
2748 | } |
2749 | ||
2750 | sense_data_length = get_unaligned_le16(&error_info->sense_data_length); | |
2751 | if (sense_data_length == 0) | |
2752 | sense_data_length = | |
2753 | get_unaligned_le16(&error_info->response_data_length); | |
2754 | if (sense_data_length) { | |
2755 | if (sense_data_length > sizeof(error_info->data)) | |
2756 | sense_data_length = sizeof(error_info->data); | |
2757 | ||
2758 | if (scsi_status == SAM_STAT_CHECK_CONDITION && | |
2759 | scsi_normalize_sense(error_info->data, | |
2760 | sense_data_length, &sshdr) && | |
2761 | sshdr.sense_key == HARDWARE_ERROR && | |
8ef860ae | 2762 | sshdr.asc == 0x3e) { |
441b7195 EV |
2763 | struct pqi_ctrl_info *ctrl_info = shost_to_hba(scmd->device->host); |
2764 | struct pqi_scsi_dev *device = scmd->device->hostdata; | |
2765 | ||
8ef860ae EV |
2766 | switch (sshdr.ascq) { |
2767 | case 0x1: /* LOGICAL UNIT FAILURE */ | |
2768 | if (printk_ratelimit()) | |
2769 | scmd_printk(KERN_ERR, scmd, "received 'logical unit failure' from controller for scsi %d:%d:%d:%d\n", | |
2770 | ctrl_info->scsi_host->host_no, device->bus, device->target, device->lun); | |
2771 | pqi_take_device_offline(scmd->device, "RAID"); | |
2772 | host_byte = DID_NO_CONNECT; | |
2773 | break; | |
2774 | ||
2775 | default: /* See http://www.t10.org/lists/asc-num.htm#ASC_3E */ | |
2776 | if (printk_ratelimit()) | |
2777 | scmd_printk(KERN_ERR, scmd, "received unhandled error %d from controller for scsi %d:%d:%d:%d\n", | |
2778 | sshdr.ascq, ctrl_info->scsi_host->host_no, device->bus, device->target, device->lun); | |
2779 | break; | |
2780 | } | |
6c223761 KB |
2781 | } |
2782 | ||
2783 | if (sense_data_length > SCSI_SENSE_BUFFERSIZE) | |
2784 | sense_data_length = SCSI_SENSE_BUFFERSIZE; | |
2785 | memcpy(scmd->sense_buffer, error_info->data, | |
2786 | sense_data_length); | |
2787 | } | |
2788 | ||
2789 | scmd->result = scsi_status; | |
2790 | set_host_byte(scmd, host_byte); | |
2791 | } | |
2792 | ||
2793 | static void pqi_process_aio_io_error(struct pqi_io_request *io_request) | |
2794 | { | |
2795 | u8 scsi_status; | |
2796 | u8 host_byte; | |
2797 | struct scsi_cmnd *scmd; | |
2798 | struct pqi_aio_error_info *error_info; | |
2799 | size_t sense_data_length; | |
2800 | int residual_count; | |
2801 | int xfer_count; | |
2802 | bool device_offline; | |
2803 | ||
2804 | scmd = io_request->scmd; | |
2805 | error_info = io_request->error_info; | |
2806 | host_byte = DID_OK; | |
2807 | sense_data_length = 0; | |
2808 | device_offline = false; | |
2809 | ||
2810 | switch (error_info->service_response) { | |
2811 | case PQI_AIO_SERV_RESPONSE_COMPLETE: | |
2812 | scsi_status = error_info->status; | |
2813 | break; | |
2814 | case PQI_AIO_SERV_RESPONSE_FAILURE: | |
2815 | switch (error_info->status) { | |
2816 | case PQI_AIO_STATUS_IO_ABORTED: | |
2817 | scsi_status = SAM_STAT_TASK_ABORTED; | |
2818 | break; | |
2819 | case PQI_AIO_STATUS_UNDERRUN: | |
2820 | scsi_status = SAM_STAT_GOOD; | |
2821 | residual_count = get_unaligned_le32( | |
2822 | &error_info->residual_count); | |
2823 | scsi_set_resid(scmd, residual_count); | |
2824 | xfer_count = scsi_bufflen(scmd) - residual_count; | |
2825 | if (xfer_count < scmd->underflow) | |
2826 | host_byte = DID_SOFT_ERROR; | |
2827 | break; | |
2828 | case PQI_AIO_STATUS_OVERRUN: | |
2829 | scsi_status = SAM_STAT_GOOD; | |
2830 | break; | |
2831 | case PQI_AIO_STATUS_AIO_PATH_DISABLED: | |
2832 | pqi_aio_path_disabled(io_request); | |
2833 | scsi_status = SAM_STAT_GOOD; | |
2834 | io_request->status = -EAGAIN; | |
2835 | break; | |
2836 | case PQI_AIO_STATUS_NO_PATH_TO_DEVICE: | |
2837 | case PQI_AIO_STATUS_INVALID_DEVICE: | |
376fb880 KB |
2838 | if (!io_request->raid_bypass) { |
2839 | device_offline = true; | |
2840 | pqi_take_device_offline(scmd->device, "AIO"); | |
2841 | host_byte = DID_NO_CONNECT; | |
2842 | } | |
6c223761 KB |
2843 | scsi_status = SAM_STAT_CHECK_CONDITION; |
2844 | break; | |
2845 | case PQI_AIO_STATUS_IO_ERROR: | |
2846 | default: | |
2847 | scsi_status = SAM_STAT_CHECK_CONDITION; | |
2848 | break; | |
2849 | } | |
2850 | break; | |
2851 | case PQI_AIO_SERV_RESPONSE_TMF_COMPLETE: | |
2852 | case PQI_AIO_SERV_RESPONSE_TMF_SUCCEEDED: | |
2853 | scsi_status = SAM_STAT_GOOD; | |
2854 | break; | |
2855 | case PQI_AIO_SERV_RESPONSE_TMF_REJECTED: | |
2856 | case PQI_AIO_SERV_RESPONSE_TMF_INCORRECT_LUN: | |
2857 | default: | |
2858 | scsi_status = SAM_STAT_CHECK_CONDITION; | |
2859 | break; | |
2860 | } | |
2861 | ||
2862 | if (error_info->data_present) { | |
2863 | sense_data_length = | |
2864 | get_unaligned_le16(&error_info->data_length); | |
2865 | if (sense_data_length) { | |
2866 | if (sense_data_length > sizeof(error_info->data)) | |
2867 | sense_data_length = sizeof(error_info->data); | |
2868 | if (sense_data_length > SCSI_SENSE_BUFFERSIZE) | |
2869 | sense_data_length = SCSI_SENSE_BUFFERSIZE; | |
2870 | memcpy(scmd->sense_buffer, error_info->data, | |
2871 | sense_data_length); | |
2872 | } | |
2873 | } | |
2874 | ||
2875 | if (device_offline && sense_data_length == 0) | |
2876 | scsi_build_sense_buffer(0, scmd->sense_buffer, HARDWARE_ERROR, | |
2877 | 0x3e, 0x1); | |
2878 | ||
2879 | scmd->result = scsi_status; | |
2880 | set_host_byte(scmd, host_byte); | |
2881 | } | |
2882 | ||
2883 | static void pqi_process_io_error(unsigned int iu_type, | |
2884 | struct pqi_io_request *io_request) | |
2885 | { | |
2886 | switch (iu_type) { | |
2887 | case PQI_RESPONSE_IU_RAID_PATH_IO_ERROR: | |
2888 | pqi_process_raid_io_error(io_request); | |
2889 | break; | |
2890 | case PQI_RESPONSE_IU_AIO_PATH_IO_ERROR: | |
2891 | pqi_process_aio_io_error(io_request); | |
2892 | break; | |
2893 | } | |
2894 | } | |
2895 | ||
2896 | static int pqi_interpret_task_management_response( | |
2897 | struct pqi_task_management_response *response) | |
2898 | { | |
2899 | int rc; | |
2900 | ||
2901 | switch (response->response_code) { | |
b17f0486 KB |
2902 | case SOP_TMF_COMPLETE: |
2903 | case SOP_TMF_FUNCTION_SUCCEEDED: | |
6c223761 KB |
2904 | rc = 0; |
2905 | break; | |
3406384b MR |
2906 | case SOP_TMF_REJECTED: |
2907 | rc = -EAGAIN; | |
2908 | break; | |
6c223761 KB |
2909 | default: |
2910 | rc = -EIO; | |
2911 | break; | |
2912 | } | |
2913 | ||
2914 | return rc; | |
2915 | } | |
2916 | ||
2917 | static unsigned int pqi_process_io_intr(struct pqi_ctrl_info *ctrl_info, | |
2918 | struct pqi_queue_group *queue_group) | |
2919 | { | |
2920 | unsigned int num_responses; | |
2921 | pqi_index_t oq_pi; | |
2922 | pqi_index_t oq_ci; | |
2923 | struct pqi_io_request *io_request; | |
2924 | struct pqi_io_response *response; | |
2925 | u16 request_id; | |
2926 | ||
2927 | num_responses = 0; | |
2928 | oq_ci = queue_group->oq_ci_copy; | |
2929 | ||
2930 | while (1) { | |
dac12fbc | 2931 | oq_pi = readl(queue_group->oq_pi); |
6c223761 KB |
2932 | if (oq_pi == oq_ci) |
2933 | break; | |
2934 | ||
2935 | num_responses++; | |
2936 | response = queue_group->oq_element_array + | |
2937 | (oq_ci * PQI_OPERATIONAL_OQ_ELEMENT_LENGTH); | |
2938 | ||
2939 | request_id = get_unaligned_le16(&response->request_id); | |
2940 | WARN_ON(request_id >= ctrl_info->max_io_slots); | |
2941 | ||
2942 | io_request = &ctrl_info->io_request_pool[request_id]; | |
2943 | WARN_ON(atomic_read(&io_request->refcount) == 0); | |
2944 | ||
2945 | switch (response->header.iu_type) { | |
2946 | case PQI_RESPONSE_IU_RAID_PATH_IO_SUCCESS: | |
2947 | case PQI_RESPONSE_IU_AIO_PATH_IO_SUCCESS: | |
2ba55c98 KB |
2948 | if (io_request->scmd) |
2949 | io_request->scmd->result = 0; | |
2950 | /* fall through */ | |
6c223761 KB |
2951 | case PQI_RESPONSE_IU_GENERAL_MANAGEMENT: |
2952 | break; | |
b212c251 KB |
2953 | case PQI_RESPONSE_IU_VENDOR_GENERAL: |
2954 | io_request->status = | |
2955 | get_unaligned_le16( | |
2956 | &((struct pqi_vendor_general_response *) | |
2957 | response)->status); | |
2958 | break; | |
6c223761 KB |
2959 | case PQI_RESPONSE_IU_TASK_MANAGEMENT: |
2960 | io_request->status = | |
2961 | pqi_interpret_task_management_response( | |
2962 | (void *)response); | |
2963 | break; | |
2964 | case PQI_RESPONSE_IU_AIO_PATH_DISABLED: | |
2965 | pqi_aio_path_disabled(io_request); | |
2966 | io_request->status = -EAGAIN; | |
2967 | break; | |
2968 | case PQI_RESPONSE_IU_RAID_PATH_IO_ERROR: | |
2969 | case PQI_RESPONSE_IU_AIO_PATH_IO_ERROR: | |
2970 | io_request->error_info = ctrl_info->error_buffer + | |
2971 | (get_unaligned_le16(&response->error_index) * | |
2972 | PQI_ERROR_BUFFER_ELEMENT_LENGTH); | |
2973 | pqi_process_io_error(response->header.iu_type, | |
2974 | io_request); | |
2975 | break; | |
2976 | default: | |
2977 | dev_err(&ctrl_info->pci_dev->dev, | |
2978 | "unexpected IU type: 0x%x\n", | |
2979 | response->header.iu_type); | |
6c223761 KB |
2980 | break; |
2981 | } | |
2982 | ||
2983 | io_request->io_complete_callback(io_request, | |
2984 | io_request->context); | |
2985 | ||
2986 | /* | |
2987 | * Note that the I/O request structure CANNOT BE TOUCHED after | |
2988 | * returning from the I/O completion callback! | |
2989 | */ | |
2990 | ||
2991 | oq_ci = (oq_ci + 1) % ctrl_info->num_elements_per_oq; | |
2992 | } | |
2993 | ||
2994 | if (num_responses) { | |
2995 | queue_group->oq_ci_copy = oq_ci; | |
2996 | writel(oq_ci, queue_group->oq_ci); | |
2997 | } | |
2998 | ||
2999 | return num_responses; | |
3000 | } | |
3001 | ||
3002 | static inline unsigned int pqi_num_elements_free(unsigned int pi, | |
df7a1fcf | 3003 | unsigned int ci, unsigned int elements_in_queue) |
6c223761 KB |
3004 | { |
3005 | unsigned int num_elements_used; | |
3006 | ||
3007 | if (pi >= ci) | |
3008 | num_elements_used = pi - ci; | |
3009 | else | |
3010 | num_elements_used = elements_in_queue - ci + pi; | |
3011 | ||
3012 | return elements_in_queue - num_elements_used - 1; | |
3013 | } | |
3014 | ||
98f87667 | 3015 | static void pqi_send_event_ack(struct pqi_ctrl_info *ctrl_info, |
6c223761 KB |
3016 | struct pqi_event_acknowledge_request *iu, size_t iu_length) |
3017 | { | |
3018 | pqi_index_t iq_pi; | |
3019 | pqi_index_t iq_ci; | |
3020 | unsigned long flags; | |
3021 | void *next_element; | |
6c223761 KB |
3022 | struct pqi_queue_group *queue_group; |
3023 | ||
3024 | queue_group = &ctrl_info->queue_groups[PQI_DEFAULT_QUEUE_GROUP]; | |
3025 | put_unaligned_le16(queue_group->oq_id, &iu->header.response_queue_id); | |
3026 | ||
6c223761 KB |
3027 | while (1) { |
3028 | spin_lock_irqsave(&queue_group->submit_lock[RAID_PATH], flags); | |
3029 | ||
3030 | iq_pi = queue_group->iq_pi_copy[RAID_PATH]; | |
dac12fbc | 3031 | iq_ci = readl(queue_group->iq_ci[RAID_PATH]); |
6c223761 KB |
3032 | |
3033 | if (pqi_num_elements_free(iq_pi, iq_ci, | |
3034 | ctrl_info->num_elements_per_iq)) | |
3035 | break; | |
3036 | ||
3037 | spin_unlock_irqrestore( | |
3038 | &queue_group->submit_lock[RAID_PATH], flags); | |
3039 | ||
98f87667 | 3040 | if (pqi_ctrl_offline(ctrl_info)) |
6c223761 | 3041 | return; |
6c223761 KB |
3042 | } |
3043 | ||
3044 | next_element = queue_group->iq_element_array[RAID_PATH] + | |
3045 | (iq_pi * PQI_OPERATIONAL_IQ_ELEMENT_LENGTH); | |
3046 | ||
3047 | memcpy(next_element, iu, iu_length); | |
3048 | ||
3049 | iq_pi = (iq_pi + 1) % ctrl_info->num_elements_per_iq; | |
6c223761 KB |
3050 | queue_group->iq_pi_copy[RAID_PATH] = iq_pi; |
3051 | ||
3052 | /* | |
3053 | * This write notifies the controller that an IU is available to be | |
3054 | * processed. | |
3055 | */ | |
3056 | writel(iq_pi, queue_group->iq_pi[RAID_PATH]); | |
3057 | ||
3058 | spin_unlock_irqrestore(&queue_group->submit_lock[RAID_PATH], flags); | |
6c223761 KB |
3059 | } |
3060 | ||
3061 | static void pqi_acknowledge_event(struct pqi_ctrl_info *ctrl_info, | |
3062 | struct pqi_event *event) | |
3063 | { | |
3064 | struct pqi_event_acknowledge_request request; | |
3065 | ||
3066 | memset(&request, 0, sizeof(request)); | |
3067 | ||
3068 | request.header.iu_type = PQI_REQUEST_IU_ACKNOWLEDGE_VENDOR_EVENT; | |
3069 | put_unaligned_le16(sizeof(request) - PQI_REQUEST_HEADER_LENGTH, | |
3070 | &request.header.iu_length); | |
3071 | request.event_type = event->event_type; | |
3072 | request.event_id = event->event_id; | |
3073 | request.additional_event_id = event->additional_event_id; | |
3074 | ||
98f87667 | 3075 | pqi_send_event_ack(ctrl_info, &request, sizeof(request)); |
6c223761 KB |
3076 | } |
3077 | ||
4fd22c13 MR |
3078 | #define PQI_SOFT_RESET_STATUS_TIMEOUT_SECS 30 |
3079 | #define PQI_SOFT_RESET_STATUS_POLL_INTERVAL_SECS 1 | |
3080 | ||
3081 | static enum pqi_soft_reset_status pqi_poll_for_soft_reset_status( | |
3082 | struct pqi_ctrl_info *ctrl_info) | |
6c223761 | 3083 | { |
4fd22c13 MR |
3084 | unsigned long timeout; |
3085 | u8 status; | |
6c223761 | 3086 | |
4fd22c13 | 3087 | timeout = (PQI_SOFT_RESET_STATUS_TIMEOUT_SECS * PQI_HZ) + jiffies; |
6c223761 | 3088 | |
4fd22c13 MR |
3089 | while (1) { |
3090 | status = pqi_read_soft_reset_status(ctrl_info); | |
3091 | if (status & PQI_SOFT_RESET_INITIATE) | |
3092 | return RESET_INITIATE_DRIVER; | |
3093 | ||
3094 | if (status & PQI_SOFT_RESET_ABORT) | |
3095 | return RESET_ABORT; | |
3096 | ||
3097 | if (time_after(jiffies, timeout)) { | |
3098 | dev_err(&ctrl_info->pci_dev->dev, | |
3099 | "timed out waiting for soft reset status\n"); | |
3100 | return RESET_TIMEDOUT; | |
3101 | } | |
3102 | ||
3103 | if (!sis_is_firmware_running(ctrl_info)) | |
3104 | return RESET_NORESPONSE; | |
3105 | ||
3106 | ssleep(PQI_SOFT_RESET_STATUS_POLL_INTERVAL_SECS); | |
3107 | } | |
3108 | } | |
3109 | ||
3110 | static void pqi_process_soft_reset(struct pqi_ctrl_info *ctrl_info, | |
694c5d5b | 3111 | enum pqi_soft_reset_status reset_status) |
4fd22c13 MR |
3112 | { |
3113 | int rc; | |
3114 | ||
3115 | switch (reset_status) { | |
3116 | case RESET_INITIATE_DRIVER: | |
3117 | /* fall through */ | |
3118 | case RESET_TIMEDOUT: | |
3119 | dev_info(&ctrl_info->pci_dev->dev, | |
3120 | "resetting controller %u\n", ctrl_info->ctrl_id); | |
3121 | sis_soft_reset(ctrl_info); | |
3122 | /* fall through */ | |
3123 | case RESET_INITIATE_FIRMWARE: | |
3124 | rc = pqi_ofa_ctrl_restart(ctrl_info); | |
3125 | pqi_ofa_free_host_buffer(ctrl_info); | |
3126 | dev_info(&ctrl_info->pci_dev->dev, | |
3127 | "Online Firmware Activation for controller %u: %s\n", | |
3128 | ctrl_info->ctrl_id, rc == 0 ? "SUCCESS" : "FAILED"); | |
3129 | break; | |
3130 | case RESET_ABORT: | |
3131 | pqi_ofa_ctrl_unquiesce(ctrl_info); | |
3132 | dev_info(&ctrl_info->pci_dev->dev, | |
3133 | "Online Firmware Activation for controller %u: %s\n", | |
3134 | ctrl_info->ctrl_id, "ABORTED"); | |
3135 | break; | |
3136 | case RESET_NORESPONSE: | |
3137 | pqi_ofa_free_host_buffer(ctrl_info); | |
3138 | pqi_take_ctrl_offline(ctrl_info); | |
3139 | break; | |
3140 | } | |
3141 | } | |
3142 | ||
3143 | static void pqi_ofa_process_event(struct pqi_ctrl_info *ctrl_info, | |
3144 | struct pqi_event *event) | |
3145 | { | |
3146 | u16 event_id; | |
3147 | enum pqi_soft_reset_status status; | |
3148 | ||
3149 | event_id = get_unaligned_le16(&event->event_id); | |
3150 | ||
3151 | mutex_lock(&ctrl_info->ofa_mutex); | |
3152 | ||
3153 | if (event_id == PQI_EVENT_OFA_QUIESCE) { | |
3154 | dev_info(&ctrl_info->pci_dev->dev, | |
694c5d5b KB |
3155 | "Received Online Firmware Activation quiesce event for controller %u\n", |
3156 | ctrl_info->ctrl_id); | |
4fd22c13 MR |
3157 | pqi_ofa_ctrl_quiesce(ctrl_info); |
3158 | pqi_acknowledge_event(ctrl_info, event); | |
3159 | if (ctrl_info->soft_reset_handshake_supported) { | |
3160 | status = pqi_poll_for_soft_reset_status(ctrl_info); | |
3161 | pqi_process_soft_reset(ctrl_info, status); | |
3162 | } else { | |
3163 | pqi_process_soft_reset(ctrl_info, | |
3164 | RESET_INITIATE_FIRMWARE); | |
3165 | } | |
3166 | ||
3167 | } else if (event_id == PQI_EVENT_OFA_MEMORY_ALLOCATION) { | |
3168 | pqi_acknowledge_event(ctrl_info, event); | |
3169 | pqi_ofa_setup_host_buffer(ctrl_info, | |
3170 | le32_to_cpu(event->ofa_bytes_requested)); | |
3171 | pqi_ofa_host_memory_update(ctrl_info); | |
3172 | } else if (event_id == PQI_EVENT_OFA_CANCELLED) { | |
3173 | pqi_ofa_free_host_buffer(ctrl_info); | |
3174 | pqi_acknowledge_event(ctrl_info, event); | |
3175 | dev_info(&ctrl_info->pci_dev->dev, | |
694c5d5b KB |
3176 | "Online Firmware Activation(%u) cancel reason : %u\n", |
3177 | ctrl_info->ctrl_id, event->ofa_cancel_reason); | |
4fd22c13 MR |
3178 | } |
3179 | ||
3180 | mutex_unlock(&ctrl_info->ofa_mutex); | |
3181 | } | |
3182 | ||
6c223761 KB |
3183 | static void pqi_event_worker(struct work_struct *work) |
3184 | { | |
3185 | unsigned int i; | |
3186 | struct pqi_ctrl_info *ctrl_info; | |
6a50d6ad | 3187 | struct pqi_event *event; |
6c223761 KB |
3188 | |
3189 | ctrl_info = container_of(work, struct pqi_ctrl_info, event_work); | |
3190 | ||
7561a7e4 KB |
3191 | pqi_ctrl_busy(ctrl_info); |
3192 | pqi_wait_if_ctrl_blocked(ctrl_info, NO_TIMEOUT); | |
5f310425 KB |
3193 | if (pqi_ctrl_offline(ctrl_info)) |
3194 | goto out; | |
3195 | ||
3196 | pqi_schedule_rescan_worker_delayed(ctrl_info); | |
7561a7e4 | 3197 | |
6a50d6ad | 3198 | event = ctrl_info->events; |
6c223761 | 3199 | for (i = 0; i < PQI_NUM_SUPPORTED_EVENTS; i++) { |
6a50d6ad KB |
3200 | if (event->pending) { |
3201 | event->pending = false; | |
4fd22c13 MR |
3202 | if (event->event_type == PQI_EVENT_TYPE_OFA) { |
3203 | pqi_ctrl_unbusy(ctrl_info); | |
3204 | pqi_ofa_process_event(ctrl_info, event); | |
3205 | return; | |
3206 | } | |
6a50d6ad | 3207 | pqi_acknowledge_event(ctrl_info, event); |
6c223761 | 3208 | } |
6a50d6ad | 3209 | event++; |
6c223761 KB |
3210 | } |
3211 | ||
5f310425 | 3212 | out: |
7561a7e4 | 3213 | pqi_ctrl_unbusy(ctrl_info); |
6c223761 KB |
3214 | } |
3215 | ||
4fd22c13 | 3216 | #define PQI_HEARTBEAT_TIMER_INTERVAL (10 * PQI_HZ) |
6c223761 | 3217 | |
74a0f573 | 3218 | static void pqi_heartbeat_timer_handler(struct timer_list *t) |
6c223761 KB |
3219 | { |
3220 | int num_interrupts; | |
98f87667 | 3221 | u32 heartbeat_count; |
74a0f573 KC |
3222 | struct pqi_ctrl_info *ctrl_info = from_timer(ctrl_info, t, |
3223 | heartbeat_timer); | |
6c223761 | 3224 | |
98f87667 KB |
3225 | pqi_check_ctrl_health(ctrl_info); |
3226 | if (pqi_ctrl_offline(ctrl_info)) | |
061ef06a KB |
3227 | return; |
3228 | ||
6c223761 | 3229 | num_interrupts = atomic_read(&ctrl_info->num_interrupts); |
98f87667 | 3230 | heartbeat_count = pqi_read_heartbeat_counter(ctrl_info); |
6c223761 KB |
3231 | |
3232 | if (num_interrupts == ctrl_info->previous_num_interrupts) { | |
98f87667 KB |
3233 | if (heartbeat_count == ctrl_info->previous_heartbeat_count) { |
3234 | dev_err(&ctrl_info->pci_dev->dev, | |
3235 | "no heartbeat detected - last heartbeat count: %u\n", | |
3236 | heartbeat_count); | |
6c223761 KB |
3237 | pqi_take_ctrl_offline(ctrl_info); |
3238 | return; | |
3239 | } | |
6c223761 | 3240 | } else { |
98f87667 | 3241 | ctrl_info->previous_num_interrupts = num_interrupts; |
6c223761 KB |
3242 | } |
3243 | ||
98f87667 | 3244 | ctrl_info->previous_heartbeat_count = heartbeat_count; |
6c223761 KB |
3245 | mod_timer(&ctrl_info->heartbeat_timer, |
3246 | jiffies + PQI_HEARTBEAT_TIMER_INTERVAL); | |
3247 | } | |
3248 | ||
3249 | static void pqi_start_heartbeat_timer(struct pqi_ctrl_info *ctrl_info) | |
3250 | { | |
98f87667 KB |
3251 | if (!ctrl_info->heartbeat_counter) |
3252 | return; | |
3253 | ||
6c223761 KB |
3254 | ctrl_info->previous_num_interrupts = |
3255 | atomic_read(&ctrl_info->num_interrupts); | |
98f87667 KB |
3256 | ctrl_info->previous_heartbeat_count = |
3257 | pqi_read_heartbeat_counter(ctrl_info); | |
6c223761 | 3258 | |
6c223761 KB |
3259 | ctrl_info->heartbeat_timer.expires = |
3260 | jiffies + PQI_HEARTBEAT_TIMER_INTERVAL; | |
061ef06a | 3261 | add_timer(&ctrl_info->heartbeat_timer); |
6c223761 KB |
3262 | } |
3263 | ||
3264 | static inline void pqi_stop_heartbeat_timer(struct pqi_ctrl_info *ctrl_info) | |
3265 | { | |
98f87667 | 3266 | del_timer_sync(&ctrl_info->heartbeat_timer); |
6c223761 KB |
3267 | } |
3268 | ||
6a50d6ad | 3269 | static inline int pqi_event_type_to_event_index(unsigned int event_type) |
6c223761 KB |
3270 | { |
3271 | int index; | |
3272 | ||
6a50d6ad KB |
3273 | for (index = 0; index < ARRAY_SIZE(pqi_supported_event_types); index++) |
3274 | if (event_type == pqi_supported_event_types[index]) | |
3275 | return index; | |
6c223761 | 3276 | |
6a50d6ad KB |
3277 | return -1; |
3278 | } | |
3279 | ||
3280 | static inline bool pqi_is_supported_event(unsigned int event_type) | |
3281 | { | |
3282 | return pqi_event_type_to_event_index(event_type) != -1; | |
6c223761 KB |
3283 | } |
3284 | ||
4fd22c13 MR |
3285 | static void pqi_ofa_capture_event_payload(struct pqi_event *event, |
3286 | struct pqi_event_response *response) | |
3287 | { | |
3288 | u16 event_id; | |
3289 | ||
3290 | event_id = get_unaligned_le16(&event->event_id); | |
3291 | ||
3292 | if (event->event_type == PQI_EVENT_TYPE_OFA) { | |
3293 | if (event_id == PQI_EVENT_OFA_MEMORY_ALLOCATION) { | |
3294 | event->ofa_bytes_requested = | |
3295 | response->data.ofa_memory_allocation.bytes_requested; | |
3296 | } else if (event_id == PQI_EVENT_OFA_CANCELLED) { | |
3297 | event->ofa_cancel_reason = | |
3298 | response->data.ofa_cancelled.reason; | |
3299 | } | |
3300 | } | |
3301 | } | |
3302 | ||
6c223761 KB |
3303 | static unsigned int pqi_process_event_intr(struct pqi_ctrl_info *ctrl_info) |
3304 | { | |
3305 | unsigned int num_events; | |
3306 | pqi_index_t oq_pi; | |
3307 | pqi_index_t oq_ci; | |
3308 | struct pqi_event_queue *event_queue; | |
3309 | struct pqi_event_response *response; | |
6a50d6ad | 3310 | struct pqi_event *event; |
6c223761 KB |
3311 | int event_index; |
3312 | ||
3313 | event_queue = &ctrl_info->event_queue; | |
3314 | num_events = 0; | |
6c223761 KB |
3315 | oq_ci = event_queue->oq_ci_copy; |
3316 | ||
3317 | while (1) { | |
dac12fbc | 3318 | oq_pi = readl(event_queue->oq_pi); |
6c223761 KB |
3319 | if (oq_pi == oq_ci) |
3320 | break; | |
3321 | ||
3322 | num_events++; | |
3323 | response = event_queue->oq_element_array + | |
3324 | (oq_ci * PQI_EVENT_OQ_ELEMENT_LENGTH); | |
3325 | ||
3326 | event_index = | |
3327 | pqi_event_type_to_event_index(response->event_type); | |
3328 | ||
3329 | if (event_index >= 0) { | |
3330 | if (response->request_acknowlege) { | |
6a50d6ad KB |
3331 | event = &ctrl_info->events[event_index]; |
3332 | event->pending = true; | |
3333 | event->event_type = response->event_type; | |
3334 | event->event_id = response->event_id; | |
3335 | event->additional_event_id = | |
6c223761 | 3336 | response->additional_event_id; |
4fd22c13 | 3337 | pqi_ofa_capture_event_payload(event, response); |
6c223761 KB |
3338 | } |
3339 | } | |
3340 | ||
3341 | oq_ci = (oq_ci + 1) % PQI_NUM_EVENT_QUEUE_ELEMENTS; | |
3342 | } | |
3343 | ||
3344 | if (num_events) { | |
3345 | event_queue->oq_ci_copy = oq_ci; | |
3346 | writel(oq_ci, event_queue->oq_ci); | |
98f87667 | 3347 | schedule_work(&ctrl_info->event_work); |
6c223761 KB |
3348 | } |
3349 | ||
3350 | return num_events; | |
3351 | } | |
3352 | ||
061ef06a KB |
3353 | #define PQI_LEGACY_INTX_MASK 0x1 |
3354 | ||
3355 | static inline void pqi_configure_legacy_intx(struct pqi_ctrl_info *ctrl_info, | |
694c5d5b | 3356 | bool enable_intx) |
061ef06a KB |
3357 | { |
3358 | u32 intx_mask; | |
3359 | struct pqi_device_registers __iomem *pqi_registers; | |
3360 | volatile void __iomem *register_addr; | |
3361 | ||
3362 | pqi_registers = ctrl_info->pqi_registers; | |
3363 | ||
3364 | if (enable_intx) | |
3365 | register_addr = &pqi_registers->legacy_intx_mask_clear; | |
3366 | else | |
3367 | register_addr = &pqi_registers->legacy_intx_mask_set; | |
3368 | ||
3369 | intx_mask = readl(register_addr); | |
3370 | intx_mask |= PQI_LEGACY_INTX_MASK; | |
3371 | writel(intx_mask, register_addr); | |
3372 | } | |
3373 | ||
3374 | static void pqi_change_irq_mode(struct pqi_ctrl_info *ctrl_info, | |
3375 | enum pqi_irq_mode new_mode) | |
3376 | { | |
3377 | switch (ctrl_info->irq_mode) { | |
3378 | case IRQ_MODE_MSIX: | |
3379 | switch (new_mode) { | |
3380 | case IRQ_MODE_MSIX: | |
3381 | break; | |
3382 | case IRQ_MODE_INTX: | |
3383 | pqi_configure_legacy_intx(ctrl_info, true); | |
061ef06a KB |
3384 | sis_enable_intx(ctrl_info); |
3385 | break; | |
3386 | case IRQ_MODE_NONE: | |
061ef06a KB |
3387 | break; |
3388 | } | |
3389 | break; | |
3390 | case IRQ_MODE_INTX: | |
3391 | switch (new_mode) { | |
3392 | case IRQ_MODE_MSIX: | |
3393 | pqi_configure_legacy_intx(ctrl_info, false); | |
061ef06a KB |
3394 | sis_enable_msix(ctrl_info); |
3395 | break; | |
3396 | case IRQ_MODE_INTX: | |
3397 | break; | |
3398 | case IRQ_MODE_NONE: | |
3399 | pqi_configure_legacy_intx(ctrl_info, false); | |
061ef06a KB |
3400 | break; |
3401 | } | |
3402 | break; | |
3403 | case IRQ_MODE_NONE: | |
3404 | switch (new_mode) { | |
3405 | case IRQ_MODE_MSIX: | |
3406 | sis_enable_msix(ctrl_info); | |
3407 | break; | |
3408 | case IRQ_MODE_INTX: | |
3409 | pqi_configure_legacy_intx(ctrl_info, true); | |
3410 | sis_enable_intx(ctrl_info); | |
3411 | break; | |
3412 | case IRQ_MODE_NONE: | |
3413 | break; | |
3414 | } | |
3415 | break; | |
3416 | } | |
3417 | ||
3418 | ctrl_info->irq_mode = new_mode; | |
3419 | } | |
3420 | ||
3421 | #define PQI_LEGACY_INTX_PENDING 0x1 | |
3422 | ||
3423 | static inline bool pqi_is_valid_irq(struct pqi_ctrl_info *ctrl_info) | |
3424 | { | |
3425 | bool valid_irq; | |
3426 | u32 intx_status; | |
3427 | ||
3428 | switch (ctrl_info->irq_mode) { | |
3429 | case IRQ_MODE_MSIX: | |
3430 | valid_irq = true; | |
3431 | break; | |
3432 | case IRQ_MODE_INTX: | |
3433 | intx_status = | |
3434 | readl(&ctrl_info->pqi_registers->legacy_intx_status); | |
3435 | if (intx_status & PQI_LEGACY_INTX_PENDING) | |
3436 | valid_irq = true; | |
3437 | else | |
3438 | valid_irq = false; | |
3439 | break; | |
3440 | case IRQ_MODE_NONE: | |
3441 | default: | |
3442 | valid_irq = false; | |
3443 | break; | |
3444 | } | |
3445 | ||
3446 | return valid_irq; | |
3447 | } | |
3448 | ||
6c223761 KB |
3449 | static irqreturn_t pqi_irq_handler(int irq, void *data) |
3450 | { | |
3451 | struct pqi_ctrl_info *ctrl_info; | |
3452 | struct pqi_queue_group *queue_group; | |
3453 | unsigned int num_responses_handled; | |
3454 | ||
3455 | queue_group = data; | |
3456 | ctrl_info = queue_group->ctrl_info; | |
3457 | ||
061ef06a | 3458 | if (!pqi_is_valid_irq(ctrl_info)) |
6c223761 KB |
3459 | return IRQ_NONE; |
3460 | ||
3461 | num_responses_handled = pqi_process_io_intr(ctrl_info, queue_group); | |
3462 | ||
3463 | if (irq == ctrl_info->event_irq) | |
3464 | num_responses_handled += pqi_process_event_intr(ctrl_info); | |
3465 | ||
3466 | if (num_responses_handled) | |
3467 | atomic_inc(&ctrl_info->num_interrupts); | |
3468 | ||
3469 | pqi_start_io(ctrl_info, queue_group, RAID_PATH, NULL); | |
3470 | pqi_start_io(ctrl_info, queue_group, AIO_PATH, NULL); | |
3471 | ||
3472 | return IRQ_HANDLED; | |
3473 | } | |
3474 | ||
3475 | static int pqi_request_irqs(struct pqi_ctrl_info *ctrl_info) | |
3476 | { | |
d91d7820 | 3477 | struct pci_dev *pci_dev = ctrl_info->pci_dev; |
6c223761 KB |
3478 | int i; |
3479 | int rc; | |
3480 | ||
d91d7820 | 3481 | ctrl_info->event_irq = pci_irq_vector(pci_dev, 0); |
6c223761 KB |
3482 | |
3483 | for (i = 0; i < ctrl_info->num_msix_vectors_enabled; i++) { | |
d91d7820 | 3484 | rc = request_irq(pci_irq_vector(pci_dev, i), pqi_irq_handler, 0, |
52198226 | 3485 | DRIVER_NAME_SHORT, &ctrl_info->queue_groups[i]); |
6c223761 | 3486 | if (rc) { |
d91d7820 | 3487 | dev_err(&pci_dev->dev, |
6c223761 | 3488 | "irq %u init failed with error %d\n", |
d91d7820 | 3489 | pci_irq_vector(pci_dev, i), rc); |
6c223761 KB |
3490 | return rc; |
3491 | } | |
3492 | ctrl_info->num_msix_vectors_initialized++; | |
3493 | } | |
3494 | ||
3495 | return 0; | |
3496 | } | |
3497 | ||
98bf061b KB |
3498 | static void pqi_free_irqs(struct pqi_ctrl_info *ctrl_info) |
3499 | { | |
3500 | int i; | |
3501 | ||
3502 | for (i = 0; i < ctrl_info->num_msix_vectors_initialized; i++) | |
3503 | free_irq(pci_irq_vector(ctrl_info->pci_dev, i), | |
3504 | &ctrl_info->queue_groups[i]); | |
3505 | ||
3506 | ctrl_info->num_msix_vectors_initialized = 0; | |
3507 | } | |
3508 | ||
6c223761 KB |
3509 | static int pqi_enable_msix_interrupts(struct pqi_ctrl_info *ctrl_info) |
3510 | { | |
98bf061b | 3511 | int num_vectors_enabled; |
6c223761 | 3512 | |
98bf061b | 3513 | num_vectors_enabled = pci_alloc_irq_vectors(ctrl_info->pci_dev, |
52198226 CH |
3514 | PQI_MIN_MSIX_VECTORS, ctrl_info->num_queue_groups, |
3515 | PCI_IRQ_MSIX | PCI_IRQ_AFFINITY); | |
98bf061b | 3516 | if (num_vectors_enabled < 0) { |
6c223761 | 3517 | dev_err(&ctrl_info->pci_dev->dev, |
98bf061b KB |
3518 | "MSI-X init failed with error %d\n", |
3519 | num_vectors_enabled); | |
3520 | return num_vectors_enabled; | |
6c223761 KB |
3521 | } |
3522 | ||
98bf061b | 3523 | ctrl_info->num_msix_vectors_enabled = num_vectors_enabled; |
061ef06a | 3524 | ctrl_info->irq_mode = IRQ_MODE_MSIX; |
6c223761 KB |
3525 | return 0; |
3526 | } | |
3527 | ||
98bf061b KB |
3528 | static void pqi_disable_msix_interrupts(struct pqi_ctrl_info *ctrl_info) |
3529 | { | |
3530 | if (ctrl_info->num_msix_vectors_enabled) { | |
3531 | pci_free_irq_vectors(ctrl_info->pci_dev); | |
3532 | ctrl_info->num_msix_vectors_enabled = 0; | |
3533 | } | |
3534 | } | |
3535 | ||
6c223761 KB |
3536 | static int pqi_alloc_operational_queues(struct pqi_ctrl_info *ctrl_info) |
3537 | { | |
3538 | unsigned int i; | |
3539 | size_t alloc_length; | |
3540 | size_t element_array_length_per_iq; | |
3541 | size_t element_array_length_per_oq; | |
3542 | void *element_array; | |
dac12fbc | 3543 | void __iomem *next_queue_index; |
6c223761 KB |
3544 | void *aligned_pointer; |
3545 | unsigned int num_inbound_queues; | |
3546 | unsigned int num_outbound_queues; | |
3547 | unsigned int num_queue_indexes; | |
3548 | struct pqi_queue_group *queue_group; | |
3549 | ||
3550 | element_array_length_per_iq = | |
3551 | PQI_OPERATIONAL_IQ_ELEMENT_LENGTH * | |
3552 | ctrl_info->num_elements_per_iq; | |
3553 | element_array_length_per_oq = | |
3554 | PQI_OPERATIONAL_OQ_ELEMENT_LENGTH * | |
3555 | ctrl_info->num_elements_per_oq; | |
3556 | num_inbound_queues = ctrl_info->num_queue_groups * 2; | |
3557 | num_outbound_queues = ctrl_info->num_queue_groups; | |
3558 | num_queue_indexes = (ctrl_info->num_queue_groups * 3) + 1; | |
3559 | ||
3560 | aligned_pointer = NULL; | |
3561 | ||
3562 | for (i = 0; i < num_inbound_queues; i++) { | |
3563 | aligned_pointer = PTR_ALIGN(aligned_pointer, | |
3564 | PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT); | |
3565 | aligned_pointer += element_array_length_per_iq; | |
3566 | } | |
3567 | ||
3568 | for (i = 0; i < num_outbound_queues; i++) { | |
3569 | aligned_pointer = PTR_ALIGN(aligned_pointer, | |
3570 | PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT); | |
3571 | aligned_pointer += element_array_length_per_oq; | |
3572 | } | |
3573 | ||
3574 | aligned_pointer = PTR_ALIGN(aligned_pointer, | |
3575 | PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT); | |
3576 | aligned_pointer += PQI_NUM_EVENT_QUEUE_ELEMENTS * | |
3577 | PQI_EVENT_OQ_ELEMENT_LENGTH; | |
3578 | ||
3579 | for (i = 0; i < num_queue_indexes; i++) { | |
3580 | aligned_pointer = PTR_ALIGN(aligned_pointer, | |
3581 | PQI_OPERATIONAL_INDEX_ALIGNMENT); | |
3582 | aligned_pointer += sizeof(pqi_index_t); | |
3583 | } | |
3584 | ||
3585 | alloc_length = (size_t)aligned_pointer + | |
3586 | PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT; | |
3587 | ||
e1d213bd KB |
3588 | alloc_length += PQI_EXTRA_SGL_MEMORY; |
3589 | ||
6c223761 | 3590 | ctrl_info->queue_memory_base = |
750afb08 LC |
3591 | dma_alloc_coherent(&ctrl_info->pci_dev->dev, alloc_length, |
3592 | &ctrl_info->queue_memory_base_dma_handle, | |
3593 | GFP_KERNEL); | |
6c223761 | 3594 | |
d87d5474 | 3595 | if (!ctrl_info->queue_memory_base) |
6c223761 | 3596 | return -ENOMEM; |
6c223761 KB |
3597 | |
3598 | ctrl_info->queue_memory_length = alloc_length; | |
3599 | ||
3600 | element_array = PTR_ALIGN(ctrl_info->queue_memory_base, | |
3601 | PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT); | |
3602 | ||
3603 | for (i = 0; i < ctrl_info->num_queue_groups; i++) { | |
3604 | queue_group = &ctrl_info->queue_groups[i]; | |
3605 | queue_group->iq_element_array[RAID_PATH] = element_array; | |
3606 | queue_group->iq_element_array_bus_addr[RAID_PATH] = | |
3607 | ctrl_info->queue_memory_base_dma_handle + | |
3608 | (element_array - ctrl_info->queue_memory_base); | |
3609 | element_array += element_array_length_per_iq; | |
3610 | element_array = PTR_ALIGN(element_array, | |
3611 | PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT); | |
3612 | queue_group->iq_element_array[AIO_PATH] = element_array; | |
3613 | queue_group->iq_element_array_bus_addr[AIO_PATH] = | |
3614 | ctrl_info->queue_memory_base_dma_handle + | |
3615 | (element_array - ctrl_info->queue_memory_base); | |
3616 | element_array += element_array_length_per_iq; | |
3617 | element_array = PTR_ALIGN(element_array, | |
3618 | PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT); | |
3619 | } | |
3620 | ||
3621 | for (i = 0; i < ctrl_info->num_queue_groups; i++) { | |
3622 | queue_group = &ctrl_info->queue_groups[i]; | |
3623 | queue_group->oq_element_array = element_array; | |
3624 | queue_group->oq_element_array_bus_addr = | |
3625 | ctrl_info->queue_memory_base_dma_handle + | |
3626 | (element_array - ctrl_info->queue_memory_base); | |
3627 | element_array += element_array_length_per_oq; | |
3628 | element_array = PTR_ALIGN(element_array, | |
3629 | PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT); | |
3630 | } | |
3631 | ||
3632 | ctrl_info->event_queue.oq_element_array = element_array; | |
3633 | ctrl_info->event_queue.oq_element_array_bus_addr = | |
3634 | ctrl_info->queue_memory_base_dma_handle + | |
3635 | (element_array - ctrl_info->queue_memory_base); | |
3636 | element_array += PQI_NUM_EVENT_QUEUE_ELEMENTS * | |
3637 | PQI_EVENT_OQ_ELEMENT_LENGTH; | |
3638 | ||
dac12fbc | 3639 | next_queue_index = (void __iomem *)PTR_ALIGN(element_array, |
6c223761 KB |
3640 | PQI_OPERATIONAL_INDEX_ALIGNMENT); |
3641 | ||
3642 | for (i = 0; i < ctrl_info->num_queue_groups; i++) { | |
3643 | queue_group = &ctrl_info->queue_groups[i]; | |
3644 | queue_group->iq_ci[RAID_PATH] = next_queue_index; | |
3645 | queue_group->iq_ci_bus_addr[RAID_PATH] = | |
3646 | ctrl_info->queue_memory_base_dma_handle + | |
dac12fbc KB |
3647 | (next_queue_index - |
3648 | (void __iomem *)ctrl_info->queue_memory_base); | |
6c223761 KB |
3649 | next_queue_index += sizeof(pqi_index_t); |
3650 | next_queue_index = PTR_ALIGN(next_queue_index, | |
3651 | PQI_OPERATIONAL_INDEX_ALIGNMENT); | |
3652 | queue_group->iq_ci[AIO_PATH] = next_queue_index; | |
3653 | queue_group->iq_ci_bus_addr[AIO_PATH] = | |
3654 | ctrl_info->queue_memory_base_dma_handle + | |
dac12fbc KB |
3655 | (next_queue_index - |
3656 | (void __iomem *)ctrl_info->queue_memory_base); | |
6c223761 KB |
3657 | next_queue_index += sizeof(pqi_index_t); |
3658 | next_queue_index = PTR_ALIGN(next_queue_index, | |
3659 | PQI_OPERATIONAL_INDEX_ALIGNMENT); | |
3660 | queue_group->oq_pi = next_queue_index; | |
3661 | queue_group->oq_pi_bus_addr = | |
3662 | ctrl_info->queue_memory_base_dma_handle + | |
dac12fbc KB |
3663 | (next_queue_index - |
3664 | (void __iomem *)ctrl_info->queue_memory_base); | |
6c223761 KB |
3665 | next_queue_index += sizeof(pqi_index_t); |
3666 | next_queue_index = PTR_ALIGN(next_queue_index, | |
3667 | PQI_OPERATIONAL_INDEX_ALIGNMENT); | |
3668 | } | |
3669 | ||
3670 | ctrl_info->event_queue.oq_pi = next_queue_index; | |
3671 | ctrl_info->event_queue.oq_pi_bus_addr = | |
3672 | ctrl_info->queue_memory_base_dma_handle + | |
dac12fbc KB |
3673 | (next_queue_index - |
3674 | (void __iomem *)ctrl_info->queue_memory_base); | |
6c223761 KB |
3675 | |
3676 | return 0; | |
3677 | } | |
3678 | ||
3679 | static void pqi_init_operational_queues(struct pqi_ctrl_info *ctrl_info) | |
3680 | { | |
3681 | unsigned int i; | |
3682 | u16 next_iq_id = PQI_MIN_OPERATIONAL_QUEUE_ID; | |
3683 | u16 next_oq_id = PQI_MIN_OPERATIONAL_QUEUE_ID; | |
3684 | ||
3685 | /* | |
3686 | * Initialize the backpointers to the controller structure in | |
3687 | * each operational queue group structure. | |
3688 | */ | |
3689 | for (i = 0; i < ctrl_info->num_queue_groups; i++) | |
3690 | ctrl_info->queue_groups[i].ctrl_info = ctrl_info; | |
3691 | ||
3692 | /* | |
3693 | * Assign IDs to all operational queues. Note that the IDs | |
3694 | * assigned to operational IQs are independent of the IDs | |
3695 | * assigned to operational OQs. | |
3696 | */ | |
3697 | ctrl_info->event_queue.oq_id = next_oq_id++; | |
3698 | for (i = 0; i < ctrl_info->num_queue_groups; i++) { | |
3699 | ctrl_info->queue_groups[i].iq_id[RAID_PATH] = next_iq_id++; | |
3700 | ctrl_info->queue_groups[i].iq_id[AIO_PATH] = next_iq_id++; | |
3701 | ctrl_info->queue_groups[i].oq_id = next_oq_id++; | |
3702 | } | |
3703 | ||
3704 | /* | |
3705 | * Assign MSI-X table entry indexes to all queues. Note that the | |
3706 | * interrupt for the event queue is shared with the first queue group. | |
3707 | */ | |
3708 | ctrl_info->event_queue.int_msg_num = 0; | |
3709 | for (i = 0; i < ctrl_info->num_queue_groups; i++) | |
3710 | ctrl_info->queue_groups[i].int_msg_num = i; | |
3711 | ||
3712 | for (i = 0; i < ctrl_info->num_queue_groups; i++) { | |
3713 | spin_lock_init(&ctrl_info->queue_groups[i].submit_lock[0]); | |
3714 | spin_lock_init(&ctrl_info->queue_groups[i].submit_lock[1]); | |
3715 | INIT_LIST_HEAD(&ctrl_info->queue_groups[i].request_list[0]); | |
3716 | INIT_LIST_HEAD(&ctrl_info->queue_groups[i].request_list[1]); | |
3717 | } | |
3718 | } | |
3719 | ||
3720 | static int pqi_alloc_admin_queues(struct pqi_ctrl_info *ctrl_info) | |
3721 | { | |
3722 | size_t alloc_length; | |
3723 | struct pqi_admin_queues_aligned *admin_queues_aligned; | |
3724 | struct pqi_admin_queues *admin_queues; | |
3725 | ||
3726 | alloc_length = sizeof(struct pqi_admin_queues_aligned) + | |
3727 | PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT; | |
3728 | ||
3729 | ctrl_info->admin_queue_memory_base = | |
750afb08 LC |
3730 | dma_alloc_coherent(&ctrl_info->pci_dev->dev, alloc_length, |
3731 | &ctrl_info->admin_queue_memory_base_dma_handle, | |
3732 | GFP_KERNEL); | |
6c223761 KB |
3733 | |
3734 | if (!ctrl_info->admin_queue_memory_base) | |
3735 | return -ENOMEM; | |
3736 | ||
3737 | ctrl_info->admin_queue_memory_length = alloc_length; | |
3738 | ||
3739 | admin_queues = &ctrl_info->admin_queues; | |
3740 | admin_queues_aligned = PTR_ALIGN(ctrl_info->admin_queue_memory_base, | |
3741 | PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT); | |
3742 | admin_queues->iq_element_array = | |
3743 | &admin_queues_aligned->iq_element_array; | |
3744 | admin_queues->oq_element_array = | |
3745 | &admin_queues_aligned->oq_element_array; | |
3746 | admin_queues->iq_ci = &admin_queues_aligned->iq_ci; | |
dac12fbc KB |
3747 | admin_queues->oq_pi = |
3748 | (pqi_index_t __iomem *)&admin_queues_aligned->oq_pi; | |
6c223761 KB |
3749 | |
3750 | admin_queues->iq_element_array_bus_addr = | |
3751 | ctrl_info->admin_queue_memory_base_dma_handle + | |
3752 | (admin_queues->iq_element_array - | |
3753 | ctrl_info->admin_queue_memory_base); | |
3754 | admin_queues->oq_element_array_bus_addr = | |
3755 | ctrl_info->admin_queue_memory_base_dma_handle + | |
3756 | (admin_queues->oq_element_array - | |
3757 | ctrl_info->admin_queue_memory_base); | |
3758 | admin_queues->iq_ci_bus_addr = | |
3759 | ctrl_info->admin_queue_memory_base_dma_handle + | |
3760 | ((void *)admin_queues->iq_ci - | |
3761 | ctrl_info->admin_queue_memory_base); | |
3762 | admin_queues->oq_pi_bus_addr = | |
3763 | ctrl_info->admin_queue_memory_base_dma_handle + | |
dac12fbc KB |
3764 | ((void __iomem *)admin_queues->oq_pi - |
3765 | (void __iomem *)ctrl_info->admin_queue_memory_base); | |
6c223761 KB |
3766 | |
3767 | return 0; | |
3768 | } | |
3769 | ||
4fd22c13 | 3770 | #define PQI_ADMIN_QUEUE_CREATE_TIMEOUT_JIFFIES PQI_HZ |
6c223761 KB |
3771 | #define PQI_ADMIN_QUEUE_CREATE_POLL_INTERVAL_MSECS 1 |
3772 | ||
3773 | static int pqi_create_admin_queues(struct pqi_ctrl_info *ctrl_info) | |
3774 | { | |
3775 | struct pqi_device_registers __iomem *pqi_registers; | |
3776 | struct pqi_admin_queues *admin_queues; | |
3777 | unsigned long timeout; | |
3778 | u8 status; | |
3779 | u32 reg; | |
3780 | ||
3781 | pqi_registers = ctrl_info->pqi_registers; | |
3782 | admin_queues = &ctrl_info->admin_queues; | |
3783 | ||
3784 | writeq((u64)admin_queues->iq_element_array_bus_addr, | |
3785 | &pqi_registers->admin_iq_element_array_addr); | |
3786 | writeq((u64)admin_queues->oq_element_array_bus_addr, | |
3787 | &pqi_registers->admin_oq_element_array_addr); | |
3788 | writeq((u64)admin_queues->iq_ci_bus_addr, | |
3789 | &pqi_registers->admin_iq_ci_addr); | |
3790 | writeq((u64)admin_queues->oq_pi_bus_addr, | |
3791 | &pqi_registers->admin_oq_pi_addr); | |
3792 | ||
3793 | reg = PQI_ADMIN_IQ_NUM_ELEMENTS | | |
e655d469 | 3794 | (PQI_ADMIN_OQ_NUM_ELEMENTS << 8) | |
6c223761 KB |
3795 | (admin_queues->int_msg_num << 16); |
3796 | writel(reg, &pqi_registers->admin_iq_num_elements); | |
3797 | writel(PQI_CREATE_ADMIN_QUEUE_PAIR, | |
3798 | &pqi_registers->function_and_status_code); | |
3799 | ||
3800 | timeout = PQI_ADMIN_QUEUE_CREATE_TIMEOUT_JIFFIES + jiffies; | |
3801 | while (1) { | |
3802 | status = readb(&pqi_registers->function_and_status_code); | |
3803 | if (status == PQI_STATUS_IDLE) | |
3804 | break; | |
3805 | if (time_after(jiffies, timeout)) | |
3806 | return -ETIMEDOUT; | |
3807 | msleep(PQI_ADMIN_QUEUE_CREATE_POLL_INTERVAL_MSECS); | |
3808 | } | |
3809 | ||
3810 | /* | |
3811 | * The offset registers are not initialized to the correct | |
3812 | * offsets until *after* the create admin queue pair command | |
3813 | * completes successfully. | |
3814 | */ | |
3815 | admin_queues->iq_pi = ctrl_info->iomem_base + | |
3816 | PQI_DEVICE_REGISTERS_OFFSET + | |
3817 | readq(&pqi_registers->admin_iq_pi_offset); | |
3818 | admin_queues->oq_ci = ctrl_info->iomem_base + | |
3819 | PQI_DEVICE_REGISTERS_OFFSET + | |
3820 | readq(&pqi_registers->admin_oq_ci_offset); | |
3821 | ||
3822 | return 0; | |
3823 | } | |
3824 | ||
3825 | static void pqi_submit_admin_request(struct pqi_ctrl_info *ctrl_info, | |
3826 | struct pqi_general_admin_request *request) | |
3827 | { | |
3828 | struct pqi_admin_queues *admin_queues; | |
3829 | void *next_element; | |
3830 | pqi_index_t iq_pi; | |
3831 | ||
3832 | admin_queues = &ctrl_info->admin_queues; | |
3833 | iq_pi = admin_queues->iq_pi_copy; | |
3834 | ||
3835 | next_element = admin_queues->iq_element_array + | |
3836 | (iq_pi * PQI_ADMIN_IQ_ELEMENT_LENGTH); | |
3837 | ||
3838 | memcpy(next_element, request, sizeof(*request)); | |
3839 | ||
3840 | iq_pi = (iq_pi + 1) % PQI_ADMIN_IQ_NUM_ELEMENTS; | |
3841 | admin_queues->iq_pi_copy = iq_pi; | |
3842 | ||
3843 | /* | |
3844 | * This write notifies the controller that an IU is available to be | |
3845 | * processed. | |
3846 | */ | |
3847 | writel(iq_pi, admin_queues->iq_pi); | |
3848 | } | |
3849 | ||
13bede67 KB |
3850 | #define PQI_ADMIN_REQUEST_TIMEOUT_SECS 60 |
3851 | ||
6c223761 KB |
3852 | static int pqi_poll_for_admin_response(struct pqi_ctrl_info *ctrl_info, |
3853 | struct pqi_general_admin_response *response) | |
3854 | { | |
3855 | struct pqi_admin_queues *admin_queues; | |
3856 | pqi_index_t oq_pi; | |
3857 | pqi_index_t oq_ci; | |
3858 | unsigned long timeout; | |
3859 | ||
3860 | admin_queues = &ctrl_info->admin_queues; | |
3861 | oq_ci = admin_queues->oq_ci_copy; | |
3862 | ||
4fd22c13 | 3863 | timeout = (PQI_ADMIN_REQUEST_TIMEOUT_SECS * PQI_HZ) + jiffies; |
6c223761 KB |
3864 | |
3865 | while (1) { | |
dac12fbc | 3866 | oq_pi = readl(admin_queues->oq_pi); |
6c223761 KB |
3867 | if (oq_pi != oq_ci) |
3868 | break; | |
3869 | if (time_after(jiffies, timeout)) { | |
3870 | dev_err(&ctrl_info->pci_dev->dev, | |
3871 | "timed out waiting for admin response\n"); | |
3872 | return -ETIMEDOUT; | |
3873 | } | |
13bede67 KB |
3874 | if (!sis_is_firmware_running(ctrl_info)) |
3875 | return -ENXIO; | |
6c223761 KB |
3876 | usleep_range(1000, 2000); |
3877 | } | |
3878 | ||
3879 | memcpy(response, admin_queues->oq_element_array + | |
3880 | (oq_ci * PQI_ADMIN_OQ_ELEMENT_LENGTH), sizeof(*response)); | |
3881 | ||
3882 | oq_ci = (oq_ci + 1) % PQI_ADMIN_OQ_NUM_ELEMENTS; | |
3883 | admin_queues->oq_ci_copy = oq_ci; | |
3884 | writel(oq_ci, admin_queues->oq_ci); | |
3885 | ||
3886 | return 0; | |
3887 | } | |
3888 | ||
3889 | static void pqi_start_io(struct pqi_ctrl_info *ctrl_info, | |
3890 | struct pqi_queue_group *queue_group, enum pqi_io_path path, | |
3891 | struct pqi_io_request *io_request) | |
3892 | { | |
3893 | struct pqi_io_request *next; | |
3894 | void *next_element; | |
3895 | pqi_index_t iq_pi; | |
3896 | pqi_index_t iq_ci; | |
3897 | size_t iu_length; | |
3898 | unsigned long flags; | |
3899 | unsigned int num_elements_needed; | |
3900 | unsigned int num_elements_to_end_of_queue; | |
3901 | size_t copy_count; | |
3902 | struct pqi_iu_header *request; | |
3903 | ||
3904 | spin_lock_irqsave(&queue_group->submit_lock[path], flags); | |
3905 | ||
376fb880 KB |
3906 | if (io_request) { |
3907 | io_request->queue_group = queue_group; | |
6c223761 KB |
3908 | list_add_tail(&io_request->request_list_entry, |
3909 | &queue_group->request_list[path]); | |
376fb880 | 3910 | } |
6c223761 KB |
3911 | |
3912 | iq_pi = queue_group->iq_pi_copy[path]; | |
3913 | ||
3914 | list_for_each_entry_safe(io_request, next, | |
3915 | &queue_group->request_list[path], request_list_entry) { | |
3916 | ||
3917 | request = io_request->iu; | |
3918 | ||
3919 | iu_length = get_unaligned_le16(&request->iu_length) + | |
3920 | PQI_REQUEST_HEADER_LENGTH; | |
3921 | num_elements_needed = | |
3922 | DIV_ROUND_UP(iu_length, | |
3923 | PQI_OPERATIONAL_IQ_ELEMENT_LENGTH); | |
3924 | ||
dac12fbc | 3925 | iq_ci = readl(queue_group->iq_ci[path]); |
6c223761 KB |
3926 | |
3927 | if (num_elements_needed > pqi_num_elements_free(iq_pi, iq_ci, | |
3928 | ctrl_info->num_elements_per_iq)) | |
3929 | break; | |
3930 | ||
3931 | put_unaligned_le16(queue_group->oq_id, | |
3932 | &request->response_queue_id); | |
3933 | ||
3934 | next_element = queue_group->iq_element_array[path] + | |
3935 | (iq_pi * PQI_OPERATIONAL_IQ_ELEMENT_LENGTH); | |
3936 | ||
3937 | num_elements_to_end_of_queue = | |
3938 | ctrl_info->num_elements_per_iq - iq_pi; | |
3939 | ||
3940 | if (num_elements_needed <= num_elements_to_end_of_queue) { | |
3941 | memcpy(next_element, request, iu_length); | |
3942 | } else { | |
3943 | copy_count = num_elements_to_end_of_queue * | |
3944 | PQI_OPERATIONAL_IQ_ELEMENT_LENGTH; | |
3945 | memcpy(next_element, request, copy_count); | |
3946 | memcpy(queue_group->iq_element_array[path], | |
3947 | (u8 *)request + copy_count, | |
3948 | iu_length - copy_count); | |
3949 | } | |
3950 | ||
3951 | iq_pi = (iq_pi + num_elements_needed) % | |
3952 | ctrl_info->num_elements_per_iq; | |
3953 | ||
3954 | list_del(&io_request->request_list_entry); | |
3955 | } | |
3956 | ||
3957 | if (iq_pi != queue_group->iq_pi_copy[path]) { | |
3958 | queue_group->iq_pi_copy[path] = iq_pi; | |
3959 | /* | |
3960 | * This write notifies the controller that one or more IUs are | |
3961 | * available to be processed. | |
3962 | */ | |
3963 | writel(iq_pi, queue_group->iq_pi[path]); | |
3964 | } | |
3965 | ||
3966 | spin_unlock_irqrestore(&queue_group->submit_lock[path], flags); | |
3967 | } | |
3968 | ||
1f37e992 KB |
3969 | #define PQI_WAIT_FOR_COMPLETION_IO_TIMEOUT_SECS 10 |
3970 | ||
3971 | static int pqi_wait_for_completion_io(struct pqi_ctrl_info *ctrl_info, | |
3972 | struct completion *wait) | |
3973 | { | |
3974 | int rc; | |
1f37e992 KB |
3975 | |
3976 | while (1) { | |
3977 | if (wait_for_completion_io_timeout(wait, | |
4fd22c13 | 3978 | PQI_WAIT_FOR_COMPLETION_IO_TIMEOUT_SECS * PQI_HZ)) { |
1f37e992 KB |
3979 | rc = 0; |
3980 | break; | |
3981 | } | |
3982 | ||
3983 | pqi_check_ctrl_health(ctrl_info); | |
3984 | if (pqi_ctrl_offline(ctrl_info)) { | |
3985 | rc = -ENXIO; | |
3986 | break; | |
3987 | } | |
1f37e992 KB |
3988 | } |
3989 | ||
3990 | return rc; | |
3991 | } | |
3992 | ||
6c223761 KB |
3993 | static void pqi_raid_synchronous_complete(struct pqi_io_request *io_request, |
3994 | void *context) | |
3995 | { | |
3996 | struct completion *waiting = context; | |
3997 | ||
3998 | complete(waiting); | |
3999 | } | |
4000 | ||
694c5d5b KB |
4001 | static int pqi_process_raid_io_error_synchronous( |
4002 | struct pqi_raid_error_info *error_info) | |
26b390ab KB |
4003 | { |
4004 | int rc = -EIO; | |
4005 | ||
4006 | switch (error_info->data_out_result) { | |
4007 | case PQI_DATA_IN_OUT_GOOD: | |
4008 | if (error_info->status == SAM_STAT_GOOD) | |
4009 | rc = 0; | |
4010 | break; | |
4011 | case PQI_DATA_IN_OUT_UNDERFLOW: | |
4012 | if (error_info->status == SAM_STAT_GOOD || | |
4013 | error_info->status == SAM_STAT_CHECK_CONDITION) | |
4014 | rc = 0; | |
4015 | break; | |
4016 | case PQI_DATA_IN_OUT_ABORTED: | |
4017 | rc = PQI_CMD_STATUS_ABORTED; | |
4018 | break; | |
4019 | } | |
4020 | ||
4021 | return rc; | |
4022 | } | |
4023 | ||
6c223761 KB |
4024 | static int pqi_submit_raid_request_synchronous(struct pqi_ctrl_info *ctrl_info, |
4025 | struct pqi_iu_header *request, unsigned int flags, | |
4026 | struct pqi_raid_error_info *error_info, unsigned long timeout_msecs) | |
4027 | { | |
957c5ab1 | 4028 | int rc = 0; |
6c223761 KB |
4029 | struct pqi_io_request *io_request; |
4030 | unsigned long start_jiffies; | |
4031 | unsigned long msecs_blocked; | |
4032 | size_t iu_length; | |
957c5ab1 | 4033 | DECLARE_COMPLETION_ONSTACK(wait); |
6c223761 KB |
4034 | |
4035 | /* | |
4036 | * Note that specifying PQI_SYNC_FLAGS_INTERRUPTABLE and a timeout value | |
4037 | * are mutually exclusive. | |
4038 | */ | |
4039 | ||
4040 | if (flags & PQI_SYNC_FLAGS_INTERRUPTABLE) { | |
4041 | if (down_interruptible(&ctrl_info->sync_request_sem)) | |
4042 | return -ERESTARTSYS; | |
4043 | } else { | |
4044 | if (timeout_msecs == NO_TIMEOUT) { | |
4045 | down(&ctrl_info->sync_request_sem); | |
4046 | } else { | |
4047 | start_jiffies = jiffies; | |
4048 | if (down_timeout(&ctrl_info->sync_request_sem, | |
4049 | msecs_to_jiffies(timeout_msecs))) | |
4050 | return -ETIMEDOUT; | |
4051 | msecs_blocked = | |
4052 | jiffies_to_msecs(jiffies - start_jiffies); | |
cc8f5260 DC |
4053 | if (msecs_blocked >= timeout_msecs) { |
4054 | rc = -ETIMEDOUT; | |
4055 | goto out; | |
4056 | } | |
6c223761 KB |
4057 | timeout_msecs -= msecs_blocked; |
4058 | } | |
4059 | } | |
4060 | ||
7561a7e4 KB |
4061 | pqi_ctrl_busy(ctrl_info); |
4062 | timeout_msecs = pqi_wait_if_ctrl_blocked(ctrl_info, timeout_msecs); | |
4063 | if (timeout_msecs == 0) { | |
957c5ab1 | 4064 | pqi_ctrl_unbusy(ctrl_info); |
7561a7e4 KB |
4065 | rc = -ETIMEDOUT; |
4066 | goto out; | |
4067 | } | |
4068 | ||
376fb880 | 4069 | if (pqi_ctrl_offline(ctrl_info)) { |
957c5ab1 | 4070 | pqi_ctrl_unbusy(ctrl_info); |
376fb880 KB |
4071 | rc = -ENXIO; |
4072 | goto out; | |
4073 | } | |
4074 | ||
0530736e KB |
4075 | atomic_inc(&ctrl_info->sync_cmds_outstanding); |
4076 | ||
6c223761 KB |
4077 | io_request = pqi_alloc_io_request(ctrl_info); |
4078 | ||
4079 | put_unaligned_le16(io_request->index, | |
4080 | &(((struct pqi_raid_path_request *)request)->request_id)); | |
4081 | ||
4082 | if (request->iu_type == PQI_REQUEST_IU_RAID_PATH_IO) | |
4083 | ((struct pqi_raid_path_request *)request)->error_index = | |
4084 | ((struct pqi_raid_path_request *)request)->request_id; | |
4085 | ||
4086 | iu_length = get_unaligned_le16(&request->iu_length) + | |
4087 | PQI_REQUEST_HEADER_LENGTH; | |
4088 | memcpy(io_request->iu, request, iu_length); | |
4089 | ||
957c5ab1 KB |
4090 | io_request->io_complete_callback = pqi_raid_synchronous_complete; |
4091 | io_request->context = &wait; | |
4092 | ||
4093 | pqi_start_io(ctrl_info, | |
4094 | &ctrl_info->queue_groups[PQI_DEFAULT_QUEUE_GROUP], RAID_PATH, | |
4095 | io_request); | |
4096 | ||
4097 | pqi_ctrl_unbusy(ctrl_info); | |
4098 | ||
4099 | if (timeout_msecs == NO_TIMEOUT) { | |
4100 | pqi_wait_for_completion_io(ctrl_info, &wait); | |
4101 | } else { | |
4102 | if (!wait_for_completion_io_timeout(&wait, | |
4103 | msecs_to_jiffies(timeout_msecs))) { | |
4104 | dev_warn(&ctrl_info->pci_dev->dev, | |
4105 | "command timed out\n"); | |
4106 | rc = -ETIMEDOUT; | |
4107 | } | |
4108 | } | |
6c223761 KB |
4109 | |
4110 | if (error_info) { | |
4111 | if (io_request->error_info) | |
4112 | memcpy(error_info, io_request->error_info, | |
4113 | sizeof(*error_info)); | |
4114 | else | |
4115 | memset(error_info, 0, sizeof(*error_info)); | |
4116 | } else if (rc == 0 && io_request->error_info) { | |
26b390ab KB |
4117 | rc = pqi_process_raid_io_error_synchronous( |
4118 | io_request->error_info); | |
6c223761 KB |
4119 | } |
4120 | ||
4121 | pqi_free_io_request(io_request); | |
4122 | ||
0530736e | 4123 | atomic_dec(&ctrl_info->sync_cmds_outstanding); |
7561a7e4 | 4124 | out: |
6c223761 KB |
4125 | up(&ctrl_info->sync_request_sem); |
4126 | ||
4127 | return rc; | |
4128 | } | |
4129 | ||
4130 | static int pqi_validate_admin_response( | |
4131 | struct pqi_general_admin_response *response, u8 expected_function_code) | |
4132 | { | |
4133 | if (response->header.iu_type != PQI_RESPONSE_IU_GENERAL_ADMIN) | |
4134 | return -EINVAL; | |
4135 | ||
4136 | if (get_unaligned_le16(&response->header.iu_length) != | |
4137 | PQI_GENERAL_ADMIN_IU_LENGTH) | |
4138 | return -EINVAL; | |
4139 | ||
4140 | if (response->function_code != expected_function_code) | |
4141 | return -EINVAL; | |
4142 | ||
4143 | if (response->status != PQI_GENERAL_ADMIN_STATUS_SUCCESS) | |
4144 | return -EINVAL; | |
4145 | ||
4146 | return 0; | |
4147 | } | |
4148 | ||
4149 | static int pqi_submit_admin_request_synchronous( | |
4150 | struct pqi_ctrl_info *ctrl_info, | |
4151 | struct pqi_general_admin_request *request, | |
4152 | struct pqi_general_admin_response *response) | |
4153 | { | |
4154 | int rc; | |
4155 | ||
4156 | pqi_submit_admin_request(ctrl_info, request); | |
4157 | ||
4158 | rc = pqi_poll_for_admin_response(ctrl_info, response); | |
4159 | ||
4160 | if (rc == 0) | |
4161 | rc = pqi_validate_admin_response(response, | |
4162 | request->function_code); | |
4163 | ||
4164 | return rc; | |
4165 | } | |
4166 | ||
4167 | static int pqi_report_device_capability(struct pqi_ctrl_info *ctrl_info) | |
4168 | { | |
4169 | int rc; | |
4170 | struct pqi_general_admin_request request; | |
4171 | struct pqi_general_admin_response response; | |
4172 | struct pqi_device_capability *capability; | |
4173 | struct pqi_iu_layer_descriptor *sop_iu_layer_descriptor; | |
4174 | ||
4175 | capability = kmalloc(sizeof(*capability), GFP_KERNEL); | |
4176 | if (!capability) | |
4177 | return -ENOMEM; | |
4178 | ||
4179 | memset(&request, 0, sizeof(request)); | |
4180 | ||
4181 | request.header.iu_type = PQI_REQUEST_IU_GENERAL_ADMIN; | |
4182 | put_unaligned_le16(PQI_GENERAL_ADMIN_IU_LENGTH, | |
4183 | &request.header.iu_length); | |
4184 | request.function_code = | |
4185 | PQI_GENERAL_ADMIN_FUNCTION_REPORT_DEVICE_CAPABILITY; | |
4186 | put_unaligned_le32(sizeof(*capability), | |
4187 | &request.data.report_device_capability.buffer_length); | |
4188 | ||
4189 | rc = pqi_map_single(ctrl_info->pci_dev, | |
4190 | &request.data.report_device_capability.sg_descriptor, | |
4191 | capability, sizeof(*capability), | |
6917a9cc | 4192 | DMA_FROM_DEVICE); |
6c223761 KB |
4193 | if (rc) |
4194 | goto out; | |
4195 | ||
4196 | rc = pqi_submit_admin_request_synchronous(ctrl_info, &request, | |
4197 | &response); | |
4198 | ||
4199 | pqi_pci_unmap(ctrl_info->pci_dev, | |
4200 | &request.data.report_device_capability.sg_descriptor, 1, | |
6917a9cc | 4201 | DMA_FROM_DEVICE); |
6c223761 KB |
4202 | |
4203 | if (rc) | |
4204 | goto out; | |
4205 | ||
4206 | if (response.status != PQI_GENERAL_ADMIN_STATUS_SUCCESS) { | |
4207 | rc = -EIO; | |
4208 | goto out; | |
4209 | } | |
4210 | ||
4211 | ctrl_info->max_inbound_queues = | |
4212 | get_unaligned_le16(&capability->max_inbound_queues); | |
4213 | ctrl_info->max_elements_per_iq = | |
4214 | get_unaligned_le16(&capability->max_elements_per_iq); | |
4215 | ctrl_info->max_iq_element_length = | |
4216 | get_unaligned_le16(&capability->max_iq_element_length) | |
4217 | * 16; | |
4218 | ctrl_info->max_outbound_queues = | |
4219 | get_unaligned_le16(&capability->max_outbound_queues); | |
4220 | ctrl_info->max_elements_per_oq = | |
4221 | get_unaligned_le16(&capability->max_elements_per_oq); | |
4222 | ctrl_info->max_oq_element_length = | |
4223 | get_unaligned_le16(&capability->max_oq_element_length) | |
4224 | * 16; | |
4225 | ||
4226 | sop_iu_layer_descriptor = | |
4227 | &capability->iu_layer_descriptors[PQI_PROTOCOL_SOP]; | |
4228 | ||
4229 | ctrl_info->max_inbound_iu_length_per_firmware = | |
4230 | get_unaligned_le16( | |
4231 | &sop_iu_layer_descriptor->max_inbound_iu_length); | |
4232 | ctrl_info->inbound_spanning_supported = | |
4233 | sop_iu_layer_descriptor->inbound_spanning_supported; | |
4234 | ctrl_info->outbound_spanning_supported = | |
4235 | sop_iu_layer_descriptor->outbound_spanning_supported; | |
4236 | ||
4237 | out: | |
4238 | kfree(capability); | |
4239 | ||
4240 | return rc; | |
4241 | } | |
4242 | ||
4243 | static int pqi_validate_device_capability(struct pqi_ctrl_info *ctrl_info) | |
4244 | { | |
4245 | if (ctrl_info->max_iq_element_length < | |
4246 | PQI_OPERATIONAL_IQ_ELEMENT_LENGTH) { | |
4247 | dev_err(&ctrl_info->pci_dev->dev, | |
4248 | "max. inbound queue element length of %d is less than the required length of %d\n", | |
4249 | ctrl_info->max_iq_element_length, | |
4250 | PQI_OPERATIONAL_IQ_ELEMENT_LENGTH); | |
4251 | return -EINVAL; | |
4252 | } | |
4253 | ||
4254 | if (ctrl_info->max_oq_element_length < | |
4255 | PQI_OPERATIONAL_OQ_ELEMENT_LENGTH) { | |
4256 | dev_err(&ctrl_info->pci_dev->dev, | |
4257 | "max. outbound queue element length of %d is less than the required length of %d\n", | |
4258 | ctrl_info->max_oq_element_length, | |
4259 | PQI_OPERATIONAL_OQ_ELEMENT_LENGTH); | |
4260 | return -EINVAL; | |
4261 | } | |
4262 | ||
4263 | if (ctrl_info->max_inbound_iu_length_per_firmware < | |
4264 | PQI_OPERATIONAL_IQ_ELEMENT_LENGTH) { | |
4265 | dev_err(&ctrl_info->pci_dev->dev, | |
4266 | "max. inbound IU length of %u is less than the min. required length of %d\n", | |
4267 | ctrl_info->max_inbound_iu_length_per_firmware, | |
4268 | PQI_OPERATIONAL_IQ_ELEMENT_LENGTH); | |
4269 | return -EINVAL; | |
4270 | } | |
4271 | ||
77668f41 KB |
4272 | if (!ctrl_info->inbound_spanning_supported) { |
4273 | dev_err(&ctrl_info->pci_dev->dev, | |
4274 | "the controller does not support inbound spanning\n"); | |
4275 | return -EINVAL; | |
4276 | } | |
4277 | ||
4278 | if (ctrl_info->outbound_spanning_supported) { | |
4279 | dev_err(&ctrl_info->pci_dev->dev, | |
4280 | "the controller supports outbound spanning but this driver does not\n"); | |
4281 | return -EINVAL; | |
4282 | } | |
4283 | ||
6c223761 KB |
4284 | return 0; |
4285 | } | |
4286 | ||
6c223761 KB |
4287 | static int pqi_create_event_queue(struct pqi_ctrl_info *ctrl_info) |
4288 | { | |
4289 | int rc; | |
4290 | struct pqi_event_queue *event_queue; | |
4291 | struct pqi_general_admin_request request; | |
4292 | struct pqi_general_admin_response response; | |
4293 | ||
4294 | event_queue = &ctrl_info->event_queue; | |
4295 | ||
4296 | /* | |
4297 | * Create OQ (Outbound Queue - device to host queue) to dedicate | |
4298 | * to events. | |
4299 | */ | |
4300 | memset(&request, 0, sizeof(request)); | |
4301 | request.header.iu_type = PQI_REQUEST_IU_GENERAL_ADMIN; | |
4302 | put_unaligned_le16(PQI_GENERAL_ADMIN_IU_LENGTH, | |
4303 | &request.header.iu_length); | |
4304 | request.function_code = PQI_GENERAL_ADMIN_FUNCTION_CREATE_OQ; | |
4305 | put_unaligned_le16(event_queue->oq_id, | |
4306 | &request.data.create_operational_oq.queue_id); | |
4307 | put_unaligned_le64((u64)event_queue->oq_element_array_bus_addr, | |
4308 | &request.data.create_operational_oq.element_array_addr); | |
4309 | put_unaligned_le64((u64)event_queue->oq_pi_bus_addr, | |
4310 | &request.data.create_operational_oq.pi_addr); | |
4311 | put_unaligned_le16(PQI_NUM_EVENT_QUEUE_ELEMENTS, | |
4312 | &request.data.create_operational_oq.num_elements); | |
4313 | put_unaligned_le16(PQI_EVENT_OQ_ELEMENT_LENGTH / 16, | |
4314 | &request.data.create_operational_oq.element_length); | |
4315 | request.data.create_operational_oq.queue_protocol = PQI_PROTOCOL_SOP; | |
4316 | put_unaligned_le16(event_queue->int_msg_num, | |
4317 | &request.data.create_operational_oq.int_msg_num); | |
4318 | ||
4319 | rc = pqi_submit_admin_request_synchronous(ctrl_info, &request, | |
4320 | &response); | |
4321 | if (rc) | |
4322 | return rc; | |
4323 | ||
4324 | event_queue->oq_ci = ctrl_info->iomem_base + | |
4325 | PQI_DEVICE_REGISTERS_OFFSET + | |
4326 | get_unaligned_le64( | |
4327 | &response.data.create_operational_oq.oq_ci_offset); | |
4328 | ||
4329 | return 0; | |
4330 | } | |
4331 | ||
061ef06a KB |
4332 | static int pqi_create_queue_group(struct pqi_ctrl_info *ctrl_info, |
4333 | unsigned int group_number) | |
6c223761 | 4334 | { |
6c223761 KB |
4335 | int rc; |
4336 | struct pqi_queue_group *queue_group; | |
4337 | struct pqi_general_admin_request request; | |
4338 | struct pqi_general_admin_response response; | |
4339 | ||
061ef06a | 4340 | queue_group = &ctrl_info->queue_groups[group_number]; |
6c223761 KB |
4341 | |
4342 | /* | |
4343 | * Create IQ (Inbound Queue - host to device queue) for | |
4344 | * RAID path. | |
4345 | */ | |
4346 | memset(&request, 0, sizeof(request)); | |
4347 | request.header.iu_type = PQI_REQUEST_IU_GENERAL_ADMIN; | |
4348 | put_unaligned_le16(PQI_GENERAL_ADMIN_IU_LENGTH, | |
4349 | &request.header.iu_length); | |
4350 | request.function_code = PQI_GENERAL_ADMIN_FUNCTION_CREATE_IQ; | |
4351 | put_unaligned_le16(queue_group->iq_id[RAID_PATH], | |
4352 | &request.data.create_operational_iq.queue_id); | |
4353 | put_unaligned_le64( | |
4354 | (u64)queue_group->iq_element_array_bus_addr[RAID_PATH], | |
4355 | &request.data.create_operational_iq.element_array_addr); | |
4356 | put_unaligned_le64((u64)queue_group->iq_ci_bus_addr[RAID_PATH], | |
4357 | &request.data.create_operational_iq.ci_addr); | |
4358 | put_unaligned_le16(ctrl_info->num_elements_per_iq, | |
4359 | &request.data.create_operational_iq.num_elements); | |
4360 | put_unaligned_le16(PQI_OPERATIONAL_IQ_ELEMENT_LENGTH / 16, | |
4361 | &request.data.create_operational_iq.element_length); | |
4362 | request.data.create_operational_iq.queue_protocol = PQI_PROTOCOL_SOP; | |
4363 | ||
4364 | rc = pqi_submit_admin_request_synchronous(ctrl_info, &request, | |
4365 | &response); | |
4366 | if (rc) { | |
4367 | dev_err(&ctrl_info->pci_dev->dev, | |
4368 | "error creating inbound RAID queue\n"); | |
4369 | return rc; | |
4370 | } | |
4371 | ||
4372 | queue_group->iq_pi[RAID_PATH] = ctrl_info->iomem_base + | |
4373 | PQI_DEVICE_REGISTERS_OFFSET + | |
4374 | get_unaligned_le64( | |
4375 | &response.data.create_operational_iq.iq_pi_offset); | |
4376 | ||
4377 | /* | |
4378 | * Create IQ (Inbound Queue - host to device queue) for | |
4379 | * Advanced I/O (AIO) path. | |
4380 | */ | |
4381 | memset(&request, 0, sizeof(request)); | |
4382 | request.header.iu_type = PQI_REQUEST_IU_GENERAL_ADMIN; | |
4383 | put_unaligned_le16(PQI_GENERAL_ADMIN_IU_LENGTH, | |
4384 | &request.header.iu_length); | |
4385 | request.function_code = PQI_GENERAL_ADMIN_FUNCTION_CREATE_IQ; | |
4386 | put_unaligned_le16(queue_group->iq_id[AIO_PATH], | |
4387 | &request.data.create_operational_iq.queue_id); | |
4388 | put_unaligned_le64((u64)queue_group-> | |
4389 | iq_element_array_bus_addr[AIO_PATH], | |
4390 | &request.data.create_operational_iq.element_array_addr); | |
4391 | put_unaligned_le64((u64)queue_group->iq_ci_bus_addr[AIO_PATH], | |
4392 | &request.data.create_operational_iq.ci_addr); | |
4393 | put_unaligned_le16(ctrl_info->num_elements_per_iq, | |
4394 | &request.data.create_operational_iq.num_elements); | |
4395 | put_unaligned_le16(PQI_OPERATIONAL_IQ_ELEMENT_LENGTH / 16, | |
4396 | &request.data.create_operational_iq.element_length); | |
4397 | request.data.create_operational_iq.queue_protocol = PQI_PROTOCOL_SOP; | |
4398 | ||
4399 | rc = pqi_submit_admin_request_synchronous(ctrl_info, &request, | |
4400 | &response); | |
4401 | if (rc) { | |
4402 | dev_err(&ctrl_info->pci_dev->dev, | |
4403 | "error creating inbound AIO queue\n"); | |
339faa81 | 4404 | return rc; |
6c223761 KB |
4405 | } |
4406 | ||
4407 | queue_group->iq_pi[AIO_PATH] = ctrl_info->iomem_base + | |
4408 | PQI_DEVICE_REGISTERS_OFFSET + | |
4409 | get_unaligned_le64( | |
4410 | &response.data.create_operational_iq.iq_pi_offset); | |
4411 | ||
4412 | /* | |
4413 | * Designate the 2nd IQ as the AIO path. By default, all IQs are | |
4414 | * assumed to be for RAID path I/O unless we change the queue's | |
4415 | * property. | |
4416 | */ | |
4417 | memset(&request, 0, sizeof(request)); | |
4418 | request.header.iu_type = PQI_REQUEST_IU_GENERAL_ADMIN; | |
4419 | put_unaligned_le16(PQI_GENERAL_ADMIN_IU_LENGTH, | |
4420 | &request.header.iu_length); | |
4421 | request.function_code = PQI_GENERAL_ADMIN_FUNCTION_CHANGE_IQ_PROPERTY; | |
4422 | put_unaligned_le16(queue_group->iq_id[AIO_PATH], | |
4423 | &request.data.change_operational_iq_properties.queue_id); | |
4424 | put_unaligned_le32(PQI_IQ_PROPERTY_IS_AIO_QUEUE, | |
4425 | &request.data.change_operational_iq_properties.vendor_specific); | |
4426 | ||
4427 | rc = pqi_submit_admin_request_synchronous(ctrl_info, &request, | |
4428 | &response); | |
4429 | if (rc) { | |
4430 | dev_err(&ctrl_info->pci_dev->dev, | |
4431 | "error changing queue property\n"); | |
339faa81 | 4432 | return rc; |
6c223761 KB |
4433 | } |
4434 | ||
4435 | /* | |
4436 | * Create OQ (Outbound Queue - device to host queue). | |
4437 | */ | |
4438 | memset(&request, 0, sizeof(request)); | |
4439 | request.header.iu_type = PQI_REQUEST_IU_GENERAL_ADMIN; | |
4440 | put_unaligned_le16(PQI_GENERAL_ADMIN_IU_LENGTH, | |
4441 | &request.header.iu_length); | |
4442 | request.function_code = PQI_GENERAL_ADMIN_FUNCTION_CREATE_OQ; | |
4443 | put_unaligned_le16(queue_group->oq_id, | |
4444 | &request.data.create_operational_oq.queue_id); | |
4445 | put_unaligned_le64((u64)queue_group->oq_element_array_bus_addr, | |
4446 | &request.data.create_operational_oq.element_array_addr); | |
4447 | put_unaligned_le64((u64)queue_group->oq_pi_bus_addr, | |
4448 | &request.data.create_operational_oq.pi_addr); | |
4449 | put_unaligned_le16(ctrl_info->num_elements_per_oq, | |
4450 | &request.data.create_operational_oq.num_elements); | |
4451 | put_unaligned_le16(PQI_OPERATIONAL_OQ_ELEMENT_LENGTH / 16, | |
4452 | &request.data.create_operational_oq.element_length); | |
4453 | request.data.create_operational_oq.queue_protocol = PQI_PROTOCOL_SOP; | |
4454 | put_unaligned_le16(queue_group->int_msg_num, | |
4455 | &request.data.create_operational_oq.int_msg_num); | |
4456 | ||
4457 | rc = pqi_submit_admin_request_synchronous(ctrl_info, &request, | |
4458 | &response); | |
4459 | if (rc) { | |
4460 | dev_err(&ctrl_info->pci_dev->dev, | |
4461 | "error creating outbound queue\n"); | |
339faa81 | 4462 | return rc; |
6c223761 KB |
4463 | } |
4464 | ||
4465 | queue_group->oq_ci = ctrl_info->iomem_base + | |
4466 | PQI_DEVICE_REGISTERS_OFFSET + | |
4467 | get_unaligned_le64( | |
4468 | &response.data.create_operational_oq.oq_ci_offset); | |
4469 | ||
6c223761 | 4470 | return 0; |
6c223761 KB |
4471 | } |
4472 | ||
4473 | static int pqi_create_queues(struct pqi_ctrl_info *ctrl_info) | |
4474 | { | |
4475 | int rc; | |
4476 | unsigned int i; | |
4477 | ||
4478 | rc = pqi_create_event_queue(ctrl_info); | |
4479 | if (rc) { | |
4480 | dev_err(&ctrl_info->pci_dev->dev, | |
4481 | "error creating event queue\n"); | |
4482 | return rc; | |
4483 | } | |
4484 | ||
4485 | for (i = 0; i < ctrl_info->num_queue_groups; i++) { | |
061ef06a | 4486 | rc = pqi_create_queue_group(ctrl_info, i); |
6c223761 KB |
4487 | if (rc) { |
4488 | dev_err(&ctrl_info->pci_dev->dev, | |
4489 | "error creating queue group number %u/%u\n", | |
4490 | i, ctrl_info->num_queue_groups); | |
4491 | return rc; | |
4492 | } | |
4493 | } | |
4494 | ||
4495 | return 0; | |
4496 | } | |
4497 | ||
4498 | #define PQI_REPORT_EVENT_CONFIG_BUFFER_LENGTH \ | |
4499 | (offsetof(struct pqi_event_config, descriptors) + \ | |
4500 | (PQI_MAX_EVENT_DESCRIPTORS * sizeof(struct pqi_event_descriptor))) | |
4501 | ||
6a50d6ad KB |
4502 | static int pqi_configure_events(struct pqi_ctrl_info *ctrl_info, |
4503 | bool enable_events) | |
6c223761 KB |
4504 | { |
4505 | int rc; | |
4506 | unsigned int i; | |
4507 | struct pqi_event_config *event_config; | |
6a50d6ad | 4508 | struct pqi_event_descriptor *event_descriptor; |
6c223761 KB |
4509 | struct pqi_general_management_request request; |
4510 | ||
4511 | event_config = kmalloc(PQI_REPORT_EVENT_CONFIG_BUFFER_LENGTH, | |
4512 | GFP_KERNEL); | |
4513 | if (!event_config) | |
4514 | return -ENOMEM; | |
4515 | ||
4516 | memset(&request, 0, sizeof(request)); | |
4517 | ||
4518 | request.header.iu_type = PQI_REQUEST_IU_REPORT_VENDOR_EVENT_CONFIG; | |
4519 | put_unaligned_le16(offsetof(struct pqi_general_management_request, | |
4520 | data.report_event_configuration.sg_descriptors[1]) - | |
4521 | PQI_REQUEST_HEADER_LENGTH, &request.header.iu_length); | |
4522 | put_unaligned_le32(PQI_REPORT_EVENT_CONFIG_BUFFER_LENGTH, | |
4523 | &request.data.report_event_configuration.buffer_length); | |
4524 | ||
4525 | rc = pqi_map_single(ctrl_info->pci_dev, | |
4526 | request.data.report_event_configuration.sg_descriptors, | |
4527 | event_config, PQI_REPORT_EVENT_CONFIG_BUFFER_LENGTH, | |
6917a9cc | 4528 | DMA_FROM_DEVICE); |
6c223761 KB |
4529 | if (rc) |
4530 | goto out; | |
4531 | ||
4532 | rc = pqi_submit_raid_request_synchronous(ctrl_info, &request.header, | |
4533 | 0, NULL, NO_TIMEOUT); | |
4534 | ||
4535 | pqi_pci_unmap(ctrl_info->pci_dev, | |
4536 | request.data.report_event_configuration.sg_descriptors, 1, | |
6917a9cc | 4537 | DMA_FROM_DEVICE); |
6c223761 KB |
4538 | |
4539 | if (rc) | |
4540 | goto out; | |
4541 | ||
6a50d6ad KB |
4542 | for (i = 0; i < event_config->num_event_descriptors; i++) { |
4543 | event_descriptor = &event_config->descriptors[i]; | |
4544 | if (enable_events && | |
4545 | pqi_is_supported_event(event_descriptor->event_type)) | |
4546 | put_unaligned_le16(ctrl_info->event_queue.oq_id, | |
4547 | &event_descriptor->oq_id); | |
4548 | else | |
4549 | put_unaligned_le16(0, &event_descriptor->oq_id); | |
4550 | } | |
6c223761 KB |
4551 | |
4552 | memset(&request, 0, sizeof(request)); | |
4553 | ||
4554 | request.header.iu_type = PQI_REQUEST_IU_SET_VENDOR_EVENT_CONFIG; | |
4555 | put_unaligned_le16(offsetof(struct pqi_general_management_request, | |
4556 | data.report_event_configuration.sg_descriptors[1]) - | |
4557 | PQI_REQUEST_HEADER_LENGTH, &request.header.iu_length); | |
4558 | put_unaligned_le32(PQI_REPORT_EVENT_CONFIG_BUFFER_LENGTH, | |
4559 | &request.data.report_event_configuration.buffer_length); | |
4560 | ||
4561 | rc = pqi_map_single(ctrl_info->pci_dev, | |
4562 | request.data.report_event_configuration.sg_descriptors, | |
4563 | event_config, PQI_REPORT_EVENT_CONFIG_BUFFER_LENGTH, | |
6917a9cc | 4564 | DMA_TO_DEVICE); |
6c223761 KB |
4565 | if (rc) |
4566 | goto out; | |
4567 | ||
4568 | rc = pqi_submit_raid_request_synchronous(ctrl_info, &request.header, 0, | |
4569 | NULL, NO_TIMEOUT); | |
4570 | ||
4571 | pqi_pci_unmap(ctrl_info->pci_dev, | |
4572 | request.data.report_event_configuration.sg_descriptors, 1, | |
6917a9cc | 4573 | DMA_TO_DEVICE); |
6c223761 KB |
4574 | |
4575 | out: | |
4576 | kfree(event_config); | |
4577 | ||
4578 | return rc; | |
4579 | } | |
4580 | ||
6a50d6ad KB |
4581 | static inline int pqi_enable_events(struct pqi_ctrl_info *ctrl_info) |
4582 | { | |
4583 | return pqi_configure_events(ctrl_info, true); | |
4584 | } | |
4585 | ||
4586 | static inline int pqi_disable_events(struct pqi_ctrl_info *ctrl_info) | |
4587 | { | |
4588 | return pqi_configure_events(ctrl_info, false); | |
4589 | } | |
4590 | ||
6c223761 KB |
4591 | static void pqi_free_all_io_requests(struct pqi_ctrl_info *ctrl_info) |
4592 | { | |
4593 | unsigned int i; | |
4594 | struct device *dev; | |
4595 | size_t sg_chain_buffer_length; | |
4596 | struct pqi_io_request *io_request; | |
4597 | ||
4598 | if (!ctrl_info->io_request_pool) | |
4599 | return; | |
4600 | ||
4601 | dev = &ctrl_info->pci_dev->dev; | |
4602 | sg_chain_buffer_length = ctrl_info->sg_chain_buffer_length; | |
4603 | io_request = ctrl_info->io_request_pool; | |
4604 | ||
4605 | for (i = 0; i < ctrl_info->max_io_slots; i++) { | |
4606 | kfree(io_request->iu); | |
4607 | if (!io_request->sg_chain_buffer) | |
4608 | break; | |
4609 | dma_free_coherent(dev, sg_chain_buffer_length, | |
4610 | io_request->sg_chain_buffer, | |
4611 | io_request->sg_chain_buffer_dma_handle); | |
4612 | io_request++; | |
4613 | } | |
4614 | ||
4615 | kfree(ctrl_info->io_request_pool); | |
4616 | ctrl_info->io_request_pool = NULL; | |
4617 | } | |
4618 | ||
4619 | static inline int pqi_alloc_error_buffer(struct pqi_ctrl_info *ctrl_info) | |
4620 | { | |
6c223761 | 4621 | |
694c5d5b KB |
4622 | ctrl_info->error_buffer = dma_alloc_coherent(&ctrl_info->pci_dev->dev, |
4623 | ctrl_info->error_buffer_length, | |
4624 | &ctrl_info->error_buffer_dma_handle, | |
4625 | GFP_KERNEL); | |
6c223761 KB |
4626 | if (!ctrl_info->error_buffer) |
4627 | return -ENOMEM; | |
4628 | ||
4629 | return 0; | |
4630 | } | |
4631 | ||
4632 | static int pqi_alloc_io_resources(struct pqi_ctrl_info *ctrl_info) | |
4633 | { | |
4634 | unsigned int i; | |
4635 | void *sg_chain_buffer; | |
4636 | size_t sg_chain_buffer_length; | |
4637 | dma_addr_t sg_chain_buffer_dma_handle; | |
4638 | struct device *dev; | |
4639 | struct pqi_io_request *io_request; | |
4640 | ||
6396bb22 KC |
4641 | ctrl_info->io_request_pool = |
4642 | kcalloc(ctrl_info->max_io_slots, | |
4643 | sizeof(ctrl_info->io_request_pool[0]), GFP_KERNEL); | |
6c223761 KB |
4644 | |
4645 | if (!ctrl_info->io_request_pool) { | |
4646 | dev_err(&ctrl_info->pci_dev->dev, | |
4647 | "failed to allocate I/O request pool\n"); | |
4648 | goto error; | |
4649 | } | |
4650 | ||
4651 | dev = &ctrl_info->pci_dev->dev; | |
4652 | sg_chain_buffer_length = ctrl_info->sg_chain_buffer_length; | |
4653 | io_request = ctrl_info->io_request_pool; | |
4654 | ||
4655 | for (i = 0; i < ctrl_info->max_io_slots; i++) { | |
4656 | io_request->iu = | |
4657 | kmalloc(ctrl_info->max_inbound_iu_length, GFP_KERNEL); | |
4658 | ||
4659 | if (!io_request->iu) { | |
4660 | dev_err(&ctrl_info->pci_dev->dev, | |
4661 | "failed to allocate IU buffers\n"); | |
4662 | goto error; | |
4663 | } | |
4664 | ||
4665 | sg_chain_buffer = dma_alloc_coherent(dev, | |
4666 | sg_chain_buffer_length, &sg_chain_buffer_dma_handle, | |
4667 | GFP_KERNEL); | |
4668 | ||
4669 | if (!sg_chain_buffer) { | |
4670 | dev_err(&ctrl_info->pci_dev->dev, | |
4671 | "failed to allocate PQI scatter-gather chain buffers\n"); | |
4672 | goto error; | |
4673 | } | |
4674 | ||
4675 | io_request->index = i; | |
4676 | io_request->sg_chain_buffer = sg_chain_buffer; | |
4677 | io_request->sg_chain_buffer_dma_handle = | |
4678 | sg_chain_buffer_dma_handle; | |
4679 | io_request++; | |
4680 | } | |
4681 | ||
4682 | return 0; | |
4683 | ||
4684 | error: | |
4685 | pqi_free_all_io_requests(ctrl_info); | |
4686 | ||
4687 | return -ENOMEM; | |
4688 | } | |
4689 | ||
4690 | /* | |
4691 | * Calculate required resources that are sized based on max. outstanding | |
4692 | * requests and max. transfer size. | |
4693 | */ | |
4694 | ||
4695 | static void pqi_calculate_io_resources(struct pqi_ctrl_info *ctrl_info) | |
4696 | { | |
4697 | u32 max_transfer_size; | |
4698 | u32 max_sg_entries; | |
4699 | ||
4700 | ctrl_info->scsi_ml_can_queue = | |
4701 | ctrl_info->max_outstanding_requests - PQI_RESERVED_IO_SLOTS; | |
4702 | ctrl_info->max_io_slots = ctrl_info->max_outstanding_requests; | |
4703 | ||
4704 | ctrl_info->error_buffer_length = | |
4705 | ctrl_info->max_io_slots * PQI_ERROR_BUFFER_ELEMENT_LENGTH; | |
4706 | ||
d727a776 KB |
4707 | if (reset_devices) |
4708 | max_transfer_size = min(ctrl_info->max_transfer_size, | |
4709 | PQI_MAX_TRANSFER_SIZE_KDUMP); | |
4710 | else | |
4711 | max_transfer_size = min(ctrl_info->max_transfer_size, | |
4712 | PQI_MAX_TRANSFER_SIZE); | |
6c223761 KB |
4713 | |
4714 | max_sg_entries = max_transfer_size / PAGE_SIZE; | |
4715 | ||
4716 | /* +1 to cover when the buffer is not page-aligned. */ | |
4717 | max_sg_entries++; | |
4718 | ||
4719 | max_sg_entries = min(ctrl_info->max_sg_entries, max_sg_entries); | |
4720 | ||
4721 | max_transfer_size = (max_sg_entries - 1) * PAGE_SIZE; | |
4722 | ||
4723 | ctrl_info->sg_chain_buffer_length = | |
e1d213bd KB |
4724 | (max_sg_entries * sizeof(struct pqi_sg_descriptor)) + |
4725 | PQI_EXTRA_SGL_MEMORY; | |
6c223761 KB |
4726 | ctrl_info->sg_tablesize = max_sg_entries; |
4727 | ctrl_info->max_sectors = max_transfer_size / 512; | |
4728 | } | |
4729 | ||
4730 | static void pqi_calculate_queue_resources(struct pqi_ctrl_info *ctrl_info) | |
4731 | { | |
6c223761 KB |
4732 | int num_queue_groups; |
4733 | u16 num_elements_per_iq; | |
4734 | u16 num_elements_per_oq; | |
4735 | ||
d727a776 KB |
4736 | if (reset_devices) { |
4737 | num_queue_groups = 1; | |
4738 | } else { | |
4739 | int num_cpus; | |
4740 | int max_queue_groups; | |
4741 | ||
4742 | max_queue_groups = min(ctrl_info->max_inbound_queues / 2, | |
4743 | ctrl_info->max_outbound_queues - 1); | |
4744 | max_queue_groups = min(max_queue_groups, PQI_MAX_QUEUE_GROUPS); | |
6c223761 | 4745 | |
d727a776 KB |
4746 | num_cpus = num_online_cpus(); |
4747 | num_queue_groups = min(num_cpus, ctrl_info->max_msix_vectors); | |
4748 | num_queue_groups = min(num_queue_groups, max_queue_groups); | |
4749 | } | |
6c223761 KB |
4750 | |
4751 | ctrl_info->num_queue_groups = num_queue_groups; | |
061ef06a | 4752 | ctrl_info->max_hw_queue_index = num_queue_groups - 1; |
6c223761 | 4753 | |
77668f41 KB |
4754 | /* |
4755 | * Make sure that the max. inbound IU length is an even multiple | |
4756 | * of our inbound element length. | |
4757 | */ | |
4758 | ctrl_info->max_inbound_iu_length = | |
4759 | (ctrl_info->max_inbound_iu_length_per_firmware / | |
4760 | PQI_OPERATIONAL_IQ_ELEMENT_LENGTH) * | |
4761 | PQI_OPERATIONAL_IQ_ELEMENT_LENGTH; | |
6c223761 KB |
4762 | |
4763 | num_elements_per_iq = | |
4764 | (ctrl_info->max_inbound_iu_length / | |
4765 | PQI_OPERATIONAL_IQ_ELEMENT_LENGTH); | |
4766 | ||
4767 | /* Add one because one element in each queue is unusable. */ | |
4768 | num_elements_per_iq++; | |
4769 | ||
4770 | num_elements_per_iq = min(num_elements_per_iq, | |
4771 | ctrl_info->max_elements_per_iq); | |
4772 | ||
4773 | num_elements_per_oq = ((num_elements_per_iq - 1) * 2) + 1; | |
4774 | num_elements_per_oq = min(num_elements_per_oq, | |
4775 | ctrl_info->max_elements_per_oq); | |
4776 | ||
4777 | ctrl_info->num_elements_per_iq = num_elements_per_iq; | |
4778 | ctrl_info->num_elements_per_oq = num_elements_per_oq; | |
4779 | ||
4780 | ctrl_info->max_sg_per_iu = | |
4781 | ((ctrl_info->max_inbound_iu_length - | |
4782 | PQI_OPERATIONAL_IQ_ELEMENT_LENGTH) / | |
4783 | sizeof(struct pqi_sg_descriptor)) + | |
4784 | PQI_MAX_EMBEDDED_SG_DESCRIPTORS; | |
4785 | } | |
4786 | ||
4787 | static inline void pqi_set_sg_descriptor( | |
4788 | struct pqi_sg_descriptor *sg_descriptor, struct scatterlist *sg) | |
4789 | { | |
4790 | u64 address = (u64)sg_dma_address(sg); | |
4791 | unsigned int length = sg_dma_len(sg); | |
4792 | ||
4793 | put_unaligned_le64(address, &sg_descriptor->address); | |
4794 | put_unaligned_le32(length, &sg_descriptor->length); | |
4795 | put_unaligned_le32(0, &sg_descriptor->flags); | |
4796 | } | |
4797 | ||
4798 | static int pqi_build_raid_sg_list(struct pqi_ctrl_info *ctrl_info, | |
4799 | struct pqi_raid_path_request *request, struct scsi_cmnd *scmd, | |
4800 | struct pqi_io_request *io_request) | |
4801 | { | |
4802 | int i; | |
4803 | u16 iu_length; | |
4804 | int sg_count; | |
4805 | bool chained; | |
4806 | unsigned int num_sg_in_iu; | |
4807 | unsigned int max_sg_per_iu; | |
4808 | struct scatterlist *sg; | |
4809 | struct pqi_sg_descriptor *sg_descriptor; | |
4810 | ||
4811 | sg_count = scsi_dma_map(scmd); | |
4812 | if (sg_count < 0) | |
4813 | return sg_count; | |
4814 | ||
4815 | iu_length = offsetof(struct pqi_raid_path_request, sg_descriptors) - | |
4816 | PQI_REQUEST_HEADER_LENGTH; | |
4817 | ||
4818 | if (sg_count == 0) | |
4819 | goto out; | |
4820 | ||
4821 | sg = scsi_sglist(scmd); | |
4822 | sg_descriptor = request->sg_descriptors; | |
4823 | max_sg_per_iu = ctrl_info->max_sg_per_iu - 1; | |
4824 | chained = false; | |
4825 | num_sg_in_iu = 0; | |
4826 | i = 0; | |
4827 | ||
4828 | while (1) { | |
4829 | pqi_set_sg_descriptor(sg_descriptor, sg); | |
4830 | if (!chained) | |
4831 | num_sg_in_iu++; | |
4832 | i++; | |
4833 | if (i == sg_count) | |
4834 | break; | |
4835 | sg_descriptor++; | |
4836 | if (i == max_sg_per_iu) { | |
4837 | put_unaligned_le64( | |
4838 | (u64)io_request->sg_chain_buffer_dma_handle, | |
4839 | &sg_descriptor->address); | |
4840 | put_unaligned_le32((sg_count - num_sg_in_iu) | |
4841 | * sizeof(*sg_descriptor), | |
4842 | &sg_descriptor->length); | |
4843 | put_unaligned_le32(CISS_SG_CHAIN, | |
4844 | &sg_descriptor->flags); | |
4845 | chained = true; | |
4846 | num_sg_in_iu++; | |
4847 | sg_descriptor = io_request->sg_chain_buffer; | |
4848 | } | |
4849 | sg = sg_next(sg); | |
4850 | } | |
4851 | ||
4852 | put_unaligned_le32(CISS_SG_LAST, &sg_descriptor->flags); | |
4853 | request->partial = chained; | |
4854 | iu_length += num_sg_in_iu * sizeof(*sg_descriptor); | |
4855 | ||
4856 | out: | |
4857 | put_unaligned_le16(iu_length, &request->header.iu_length); | |
4858 | ||
4859 | return 0; | |
4860 | } | |
4861 | ||
4862 | static int pqi_build_aio_sg_list(struct pqi_ctrl_info *ctrl_info, | |
4863 | struct pqi_aio_path_request *request, struct scsi_cmnd *scmd, | |
4864 | struct pqi_io_request *io_request) | |
4865 | { | |
4866 | int i; | |
4867 | u16 iu_length; | |
4868 | int sg_count; | |
a60eec02 KB |
4869 | bool chained; |
4870 | unsigned int num_sg_in_iu; | |
4871 | unsigned int max_sg_per_iu; | |
6c223761 KB |
4872 | struct scatterlist *sg; |
4873 | struct pqi_sg_descriptor *sg_descriptor; | |
4874 | ||
4875 | sg_count = scsi_dma_map(scmd); | |
4876 | if (sg_count < 0) | |
4877 | return sg_count; | |
a60eec02 KB |
4878 | |
4879 | iu_length = offsetof(struct pqi_aio_path_request, sg_descriptors) - | |
4880 | PQI_REQUEST_HEADER_LENGTH; | |
4881 | num_sg_in_iu = 0; | |
4882 | ||
6c223761 KB |
4883 | if (sg_count == 0) |
4884 | goto out; | |
4885 | ||
a60eec02 KB |
4886 | sg = scsi_sglist(scmd); |
4887 | sg_descriptor = request->sg_descriptors; | |
4888 | max_sg_per_iu = ctrl_info->max_sg_per_iu - 1; | |
4889 | chained = false; | |
4890 | i = 0; | |
4891 | ||
4892 | while (1) { | |
4893 | pqi_set_sg_descriptor(sg_descriptor, sg); | |
4894 | if (!chained) | |
4895 | num_sg_in_iu++; | |
4896 | i++; | |
4897 | if (i == sg_count) | |
4898 | break; | |
4899 | sg_descriptor++; | |
4900 | if (i == max_sg_per_iu) { | |
4901 | put_unaligned_le64( | |
4902 | (u64)io_request->sg_chain_buffer_dma_handle, | |
4903 | &sg_descriptor->address); | |
4904 | put_unaligned_le32((sg_count - num_sg_in_iu) | |
4905 | * sizeof(*sg_descriptor), | |
4906 | &sg_descriptor->length); | |
4907 | put_unaligned_le32(CISS_SG_CHAIN, | |
4908 | &sg_descriptor->flags); | |
4909 | chained = true; | |
4910 | num_sg_in_iu++; | |
4911 | sg_descriptor = io_request->sg_chain_buffer; | |
6c223761 | 4912 | } |
a60eec02 | 4913 | sg = sg_next(sg); |
6c223761 KB |
4914 | } |
4915 | ||
a60eec02 KB |
4916 | put_unaligned_le32(CISS_SG_LAST, &sg_descriptor->flags); |
4917 | request->partial = chained; | |
6c223761 | 4918 | iu_length += num_sg_in_iu * sizeof(*sg_descriptor); |
a60eec02 KB |
4919 | |
4920 | out: | |
6c223761 KB |
4921 | put_unaligned_le16(iu_length, &request->header.iu_length); |
4922 | request->num_sg_descriptors = num_sg_in_iu; | |
4923 | ||
4924 | return 0; | |
4925 | } | |
4926 | ||
4927 | static void pqi_raid_io_complete(struct pqi_io_request *io_request, | |
4928 | void *context) | |
4929 | { | |
4930 | struct scsi_cmnd *scmd; | |
4931 | ||
4932 | scmd = io_request->scmd; | |
4933 | pqi_free_io_request(io_request); | |
4934 | scsi_dma_unmap(scmd); | |
4935 | pqi_scsi_done(scmd); | |
4936 | } | |
4937 | ||
376fb880 KB |
4938 | static int pqi_raid_submit_scsi_cmd_with_io_request( |
4939 | struct pqi_ctrl_info *ctrl_info, struct pqi_io_request *io_request, | |
6c223761 KB |
4940 | struct pqi_scsi_dev *device, struct scsi_cmnd *scmd, |
4941 | struct pqi_queue_group *queue_group) | |
4942 | { | |
4943 | int rc; | |
4944 | size_t cdb_length; | |
6c223761 KB |
4945 | struct pqi_raid_path_request *request; |
4946 | ||
6c223761 KB |
4947 | io_request->io_complete_callback = pqi_raid_io_complete; |
4948 | io_request->scmd = scmd; | |
4949 | ||
6c223761 KB |
4950 | request = io_request->iu; |
4951 | memset(request, 0, | |
4952 | offsetof(struct pqi_raid_path_request, sg_descriptors)); | |
4953 | ||
4954 | request->header.iu_type = PQI_REQUEST_IU_RAID_PATH_IO; | |
4955 | put_unaligned_le32(scsi_bufflen(scmd), &request->buffer_length); | |
4956 | request->task_attribute = SOP_TASK_ATTRIBUTE_SIMPLE; | |
4957 | put_unaligned_le16(io_request->index, &request->request_id); | |
4958 | request->error_index = request->request_id; | |
4959 | memcpy(request->lun_number, device->scsi3addr, | |
4960 | sizeof(request->lun_number)); | |
4961 | ||
4962 | cdb_length = min_t(size_t, scmd->cmd_len, sizeof(request->cdb)); | |
4963 | memcpy(request->cdb, scmd->cmnd, cdb_length); | |
4964 | ||
4965 | switch (cdb_length) { | |
4966 | case 6: | |
4967 | case 10: | |
4968 | case 12: | |
4969 | case 16: | |
4970 | /* No bytes in the Additional CDB bytes field */ | |
4971 | request->additional_cdb_bytes_usage = | |
4972 | SOP_ADDITIONAL_CDB_BYTES_0; | |
4973 | break; | |
4974 | case 20: | |
4975 | /* 4 bytes in the Additional cdb field */ | |
4976 | request->additional_cdb_bytes_usage = | |
4977 | SOP_ADDITIONAL_CDB_BYTES_4; | |
4978 | break; | |
4979 | case 24: | |
4980 | /* 8 bytes in the Additional cdb field */ | |
4981 | request->additional_cdb_bytes_usage = | |
4982 | SOP_ADDITIONAL_CDB_BYTES_8; | |
4983 | break; | |
4984 | case 28: | |
4985 | /* 12 bytes in the Additional cdb field */ | |
4986 | request->additional_cdb_bytes_usage = | |
4987 | SOP_ADDITIONAL_CDB_BYTES_12; | |
4988 | break; | |
4989 | case 32: | |
4990 | default: | |
4991 | /* 16 bytes in the Additional cdb field */ | |
4992 | request->additional_cdb_bytes_usage = | |
4993 | SOP_ADDITIONAL_CDB_BYTES_16; | |
4994 | break; | |
4995 | } | |
4996 | ||
4997 | switch (scmd->sc_data_direction) { | |
4998 | case DMA_TO_DEVICE: | |
4999 | request->data_direction = SOP_READ_FLAG; | |
5000 | break; | |
5001 | case DMA_FROM_DEVICE: | |
5002 | request->data_direction = SOP_WRITE_FLAG; | |
5003 | break; | |
5004 | case DMA_NONE: | |
5005 | request->data_direction = SOP_NO_DIRECTION_FLAG; | |
5006 | break; | |
5007 | case DMA_BIDIRECTIONAL: | |
5008 | request->data_direction = SOP_BIDIRECTIONAL; | |
5009 | break; | |
5010 | default: | |
5011 | dev_err(&ctrl_info->pci_dev->dev, | |
5012 | "unknown data direction: %d\n", | |
5013 | scmd->sc_data_direction); | |
6c223761 KB |
5014 | break; |
5015 | } | |
5016 | ||
5017 | rc = pqi_build_raid_sg_list(ctrl_info, request, scmd, io_request); | |
5018 | if (rc) { | |
5019 | pqi_free_io_request(io_request); | |
5020 | return SCSI_MLQUEUE_HOST_BUSY; | |
5021 | } | |
5022 | ||
5023 | pqi_start_io(ctrl_info, queue_group, RAID_PATH, io_request); | |
5024 | ||
5025 | return 0; | |
5026 | } | |
5027 | ||
376fb880 KB |
5028 | static inline int pqi_raid_submit_scsi_cmd(struct pqi_ctrl_info *ctrl_info, |
5029 | struct pqi_scsi_dev *device, struct scsi_cmnd *scmd, | |
5030 | struct pqi_queue_group *queue_group) | |
5031 | { | |
5032 | struct pqi_io_request *io_request; | |
5033 | ||
5034 | io_request = pqi_alloc_io_request(ctrl_info); | |
5035 | ||
5036 | return pqi_raid_submit_scsi_cmd_with_io_request(ctrl_info, io_request, | |
5037 | device, scmd, queue_group); | |
5038 | } | |
5039 | ||
5040 | static inline void pqi_schedule_bypass_retry(struct pqi_ctrl_info *ctrl_info) | |
5041 | { | |
5042 | if (!pqi_ctrl_blocked(ctrl_info)) | |
5043 | schedule_work(&ctrl_info->raid_bypass_retry_work); | |
5044 | } | |
5045 | ||
5046 | static bool pqi_raid_bypass_retry_needed(struct pqi_io_request *io_request) | |
5047 | { | |
5048 | struct scsi_cmnd *scmd; | |
03b288cf | 5049 | struct pqi_scsi_dev *device; |
376fb880 KB |
5050 | struct pqi_ctrl_info *ctrl_info; |
5051 | ||
5052 | if (!io_request->raid_bypass) | |
5053 | return false; | |
5054 | ||
5055 | scmd = io_request->scmd; | |
5056 | if ((scmd->result & 0xff) == SAM_STAT_GOOD) | |
5057 | return false; | |
5058 | if (host_byte(scmd->result) == DID_NO_CONNECT) | |
5059 | return false; | |
5060 | ||
03b288cf KB |
5061 | device = scmd->device->hostdata; |
5062 | if (pqi_device_offline(device)) | |
5063 | return false; | |
5064 | ||
376fb880 KB |
5065 | ctrl_info = shost_to_hba(scmd->device->host); |
5066 | if (pqi_ctrl_offline(ctrl_info)) | |
5067 | return false; | |
5068 | ||
5069 | return true; | |
5070 | } | |
5071 | ||
5072 | static inline void pqi_add_to_raid_bypass_retry_list( | |
5073 | struct pqi_ctrl_info *ctrl_info, | |
5074 | struct pqi_io_request *io_request, bool at_head) | |
5075 | { | |
5076 | unsigned long flags; | |
5077 | ||
5078 | spin_lock_irqsave(&ctrl_info->raid_bypass_retry_list_lock, flags); | |
5079 | if (at_head) | |
5080 | list_add(&io_request->request_list_entry, | |
5081 | &ctrl_info->raid_bypass_retry_list); | |
5082 | else | |
5083 | list_add_tail(&io_request->request_list_entry, | |
5084 | &ctrl_info->raid_bypass_retry_list); | |
5085 | spin_unlock_irqrestore(&ctrl_info->raid_bypass_retry_list_lock, flags); | |
5086 | } | |
5087 | ||
5088 | static void pqi_queued_raid_bypass_complete(struct pqi_io_request *io_request, | |
5089 | void *context) | |
5090 | { | |
5091 | struct scsi_cmnd *scmd; | |
5092 | ||
5093 | scmd = io_request->scmd; | |
5094 | pqi_free_io_request(io_request); | |
5095 | pqi_scsi_done(scmd); | |
5096 | } | |
5097 | ||
5098 | static void pqi_queue_raid_bypass_retry(struct pqi_io_request *io_request) | |
5099 | { | |
5100 | struct scsi_cmnd *scmd; | |
5101 | struct pqi_ctrl_info *ctrl_info; | |
5102 | ||
5103 | io_request->io_complete_callback = pqi_queued_raid_bypass_complete; | |
5104 | scmd = io_request->scmd; | |
5105 | scmd->result = 0; | |
5106 | ctrl_info = shost_to_hba(scmd->device->host); | |
5107 | ||
5108 | pqi_add_to_raid_bypass_retry_list(ctrl_info, io_request, false); | |
5109 | pqi_schedule_bypass_retry(ctrl_info); | |
5110 | } | |
5111 | ||
5112 | static int pqi_retry_raid_bypass(struct pqi_io_request *io_request) | |
5113 | { | |
5114 | struct scsi_cmnd *scmd; | |
5115 | struct pqi_scsi_dev *device; | |
5116 | struct pqi_ctrl_info *ctrl_info; | |
5117 | struct pqi_queue_group *queue_group; | |
5118 | ||
5119 | scmd = io_request->scmd; | |
5120 | device = scmd->device->hostdata; | |
5121 | if (pqi_device_in_reset(device)) { | |
5122 | pqi_free_io_request(io_request); | |
5123 | set_host_byte(scmd, DID_RESET); | |
5124 | pqi_scsi_done(scmd); | |
5125 | return 0; | |
5126 | } | |
5127 | ||
5128 | ctrl_info = shost_to_hba(scmd->device->host); | |
5129 | queue_group = io_request->queue_group; | |
5130 | ||
5131 | pqi_reinit_io_request(io_request); | |
5132 | ||
5133 | return pqi_raid_submit_scsi_cmd_with_io_request(ctrl_info, io_request, | |
5134 | device, scmd, queue_group); | |
5135 | } | |
5136 | ||
5137 | static inline struct pqi_io_request *pqi_next_queued_raid_bypass_request( | |
5138 | struct pqi_ctrl_info *ctrl_info) | |
5139 | { | |
5140 | unsigned long flags; | |
5141 | struct pqi_io_request *io_request; | |
5142 | ||
5143 | spin_lock_irqsave(&ctrl_info->raid_bypass_retry_list_lock, flags); | |
5144 | io_request = list_first_entry_or_null( | |
5145 | &ctrl_info->raid_bypass_retry_list, | |
5146 | struct pqi_io_request, request_list_entry); | |
5147 | if (io_request) | |
5148 | list_del(&io_request->request_list_entry); | |
5149 | spin_unlock_irqrestore(&ctrl_info->raid_bypass_retry_list_lock, flags); | |
5150 | ||
5151 | return io_request; | |
5152 | } | |
5153 | ||
5154 | static void pqi_retry_raid_bypass_requests(struct pqi_ctrl_info *ctrl_info) | |
5155 | { | |
5156 | int rc; | |
5157 | struct pqi_io_request *io_request; | |
5158 | ||
5159 | pqi_ctrl_busy(ctrl_info); | |
5160 | ||
5161 | while (1) { | |
5162 | if (pqi_ctrl_blocked(ctrl_info)) | |
5163 | break; | |
5164 | io_request = pqi_next_queued_raid_bypass_request(ctrl_info); | |
5165 | if (!io_request) | |
5166 | break; | |
5167 | rc = pqi_retry_raid_bypass(io_request); | |
5168 | if (rc) { | |
5169 | pqi_add_to_raid_bypass_retry_list(ctrl_info, io_request, | |
5170 | true); | |
5171 | pqi_schedule_bypass_retry(ctrl_info); | |
5172 | break; | |
5173 | } | |
5174 | } | |
5175 | ||
5176 | pqi_ctrl_unbusy(ctrl_info); | |
5177 | } | |
5178 | ||
5179 | static void pqi_raid_bypass_retry_worker(struct work_struct *work) | |
5180 | { | |
5181 | struct pqi_ctrl_info *ctrl_info; | |
5182 | ||
5183 | ctrl_info = container_of(work, struct pqi_ctrl_info, | |
5184 | raid_bypass_retry_work); | |
5185 | pqi_retry_raid_bypass_requests(ctrl_info); | |
5186 | } | |
5187 | ||
5f310425 KB |
5188 | static void pqi_clear_all_queued_raid_bypass_retries( |
5189 | struct pqi_ctrl_info *ctrl_info) | |
376fb880 KB |
5190 | { |
5191 | unsigned long flags; | |
376fb880 KB |
5192 | |
5193 | spin_lock_irqsave(&ctrl_info->raid_bypass_retry_list_lock, flags); | |
5f310425 | 5194 | INIT_LIST_HEAD(&ctrl_info->raid_bypass_retry_list); |
376fb880 KB |
5195 | spin_unlock_irqrestore(&ctrl_info->raid_bypass_retry_list_lock, flags); |
5196 | } | |
5197 | ||
6c223761 KB |
5198 | static void pqi_aio_io_complete(struct pqi_io_request *io_request, |
5199 | void *context) | |
5200 | { | |
5201 | struct scsi_cmnd *scmd; | |
5202 | ||
5203 | scmd = io_request->scmd; | |
5204 | scsi_dma_unmap(scmd); | |
5205 | if (io_request->status == -EAGAIN) | |
5206 | set_host_byte(scmd, DID_IMM_RETRY); | |
376fb880 KB |
5207 | else if (pqi_raid_bypass_retry_needed(io_request)) { |
5208 | pqi_queue_raid_bypass_retry(io_request); | |
5209 | return; | |
5210 | } | |
6c223761 KB |
5211 | pqi_free_io_request(io_request); |
5212 | pqi_scsi_done(scmd); | |
5213 | } | |
5214 | ||
5215 | static inline int pqi_aio_submit_scsi_cmd(struct pqi_ctrl_info *ctrl_info, | |
5216 | struct pqi_scsi_dev *device, struct scsi_cmnd *scmd, | |
5217 | struct pqi_queue_group *queue_group) | |
5218 | { | |
5219 | return pqi_aio_submit_io(ctrl_info, scmd, device->aio_handle, | |
376fb880 | 5220 | scmd->cmnd, scmd->cmd_len, queue_group, NULL, false); |
6c223761 KB |
5221 | } |
5222 | ||
5223 | static int pqi_aio_submit_io(struct pqi_ctrl_info *ctrl_info, | |
5224 | struct scsi_cmnd *scmd, u32 aio_handle, u8 *cdb, | |
5225 | unsigned int cdb_length, struct pqi_queue_group *queue_group, | |
376fb880 | 5226 | struct pqi_encryption_info *encryption_info, bool raid_bypass) |
6c223761 KB |
5227 | { |
5228 | int rc; | |
5229 | struct pqi_io_request *io_request; | |
5230 | struct pqi_aio_path_request *request; | |
5231 | ||
5232 | io_request = pqi_alloc_io_request(ctrl_info); | |
5233 | io_request->io_complete_callback = pqi_aio_io_complete; | |
5234 | io_request->scmd = scmd; | |
376fb880 | 5235 | io_request->raid_bypass = raid_bypass; |
6c223761 KB |
5236 | |
5237 | request = io_request->iu; | |
5238 | memset(request, 0, | |
5239 | offsetof(struct pqi_raid_path_request, sg_descriptors)); | |
5240 | ||
5241 | request->header.iu_type = PQI_REQUEST_IU_AIO_PATH_IO; | |
5242 | put_unaligned_le32(aio_handle, &request->nexus_id); | |
5243 | put_unaligned_le32(scsi_bufflen(scmd), &request->buffer_length); | |
5244 | request->task_attribute = SOP_TASK_ATTRIBUTE_SIMPLE; | |
5245 | put_unaligned_le16(io_request->index, &request->request_id); | |
5246 | request->error_index = request->request_id; | |
5247 | if (cdb_length > sizeof(request->cdb)) | |
5248 | cdb_length = sizeof(request->cdb); | |
5249 | request->cdb_length = cdb_length; | |
5250 | memcpy(request->cdb, cdb, cdb_length); | |
5251 | ||
5252 | switch (scmd->sc_data_direction) { | |
5253 | case DMA_TO_DEVICE: | |
5254 | request->data_direction = SOP_READ_FLAG; | |
5255 | break; | |
5256 | case DMA_FROM_DEVICE: | |
5257 | request->data_direction = SOP_WRITE_FLAG; | |
5258 | break; | |
5259 | case DMA_NONE: | |
5260 | request->data_direction = SOP_NO_DIRECTION_FLAG; | |
5261 | break; | |
5262 | case DMA_BIDIRECTIONAL: | |
5263 | request->data_direction = SOP_BIDIRECTIONAL; | |
5264 | break; | |
5265 | default: | |
5266 | dev_err(&ctrl_info->pci_dev->dev, | |
5267 | "unknown data direction: %d\n", | |
5268 | scmd->sc_data_direction); | |
6c223761 KB |
5269 | break; |
5270 | } | |
5271 | ||
5272 | if (encryption_info) { | |
5273 | request->encryption_enable = true; | |
5274 | put_unaligned_le16(encryption_info->data_encryption_key_index, | |
5275 | &request->data_encryption_key_index); | |
5276 | put_unaligned_le32(encryption_info->encrypt_tweak_lower, | |
5277 | &request->encrypt_tweak_lower); | |
5278 | put_unaligned_le32(encryption_info->encrypt_tweak_upper, | |
5279 | &request->encrypt_tweak_upper); | |
5280 | } | |
5281 | ||
5282 | rc = pqi_build_aio_sg_list(ctrl_info, request, scmd, io_request); | |
5283 | if (rc) { | |
5284 | pqi_free_io_request(io_request); | |
5285 | return SCSI_MLQUEUE_HOST_BUSY; | |
5286 | } | |
5287 | ||
5288 | pqi_start_io(ctrl_info, queue_group, AIO_PATH, io_request); | |
5289 | ||
5290 | return 0; | |
5291 | } | |
5292 | ||
061ef06a KB |
5293 | static inline u16 pqi_get_hw_queue(struct pqi_ctrl_info *ctrl_info, |
5294 | struct scsi_cmnd *scmd) | |
5295 | { | |
5296 | u16 hw_queue; | |
5297 | ||
5298 | hw_queue = blk_mq_unique_tag_to_hwq(blk_mq_unique_tag(scmd->request)); | |
5299 | if (hw_queue > ctrl_info->max_hw_queue_index) | |
5300 | hw_queue = 0; | |
5301 | ||
5302 | return hw_queue; | |
5303 | } | |
5304 | ||
7561a7e4 KB |
5305 | /* |
5306 | * This function gets called just before we hand the completed SCSI request | |
5307 | * back to the SML. | |
5308 | */ | |
5309 | ||
5310 | void pqi_prep_for_scsi_done(struct scsi_cmnd *scmd) | |
5311 | { | |
5312 | struct pqi_scsi_dev *device; | |
5313 | ||
1e46731e MR |
5314 | if (!scmd->device) { |
5315 | set_host_byte(scmd, DID_NO_CONNECT); | |
5316 | return; | |
5317 | } | |
5318 | ||
7561a7e4 | 5319 | device = scmd->device->hostdata; |
1e46731e MR |
5320 | if (!device) { |
5321 | set_host_byte(scmd, DID_NO_CONNECT); | |
5322 | return; | |
5323 | } | |
5324 | ||
7561a7e4 KB |
5325 | atomic_dec(&device->scsi_cmds_outstanding); |
5326 | } | |
5327 | ||
6c223761 | 5328 | static int pqi_scsi_queue_command(struct Scsi_Host *shost, |
7d81d2b8 | 5329 | struct scsi_cmnd *scmd) |
6c223761 KB |
5330 | { |
5331 | int rc; | |
5332 | struct pqi_ctrl_info *ctrl_info; | |
5333 | struct pqi_scsi_dev *device; | |
061ef06a | 5334 | u16 hw_queue; |
6c223761 KB |
5335 | struct pqi_queue_group *queue_group; |
5336 | bool raid_bypassed; | |
5337 | ||
5338 | device = scmd->device->hostdata; | |
6c223761 KB |
5339 | ctrl_info = shost_to_hba(shost); |
5340 | ||
1e46731e MR |
5341 | if (!device) { |
5342 | set_host_byte(scmd, DID_NO_CONNECT); | |
5343 | pqi_scsi_done(scmd); | |
5344 | return 0; | |
5345 | } | |
5346 | ||
7561a7e4 KB |
5347 | atomic_inc(&device->scsi_cmds_outstanding); |
5348 | ||
1e46731e MR |
5349 | if (pqi_ctrl_offline(ctrl_info) || pqi_device_in_remove(ctrl_info, |
5350 | device)) { | |
6c223761 KB |
5351 | set_host_byte(scmd, DID_NO_CONNECT); |
5352 | pqi_scsi_done(scmd); | |
5353 | return 0; | |
5354 | } | |
5355 | ||
7561a7e4 | 5356 | pqi_ctrl_busy(ctrl_info); |
4fd22c13 | 5357 | if (pqi_ctrl_blocked(ctrl_info) || pqi_device_in_reset(device) || |
0530736e | 5358 | pqi_ctrl_in_ofa(ctrl_info) || pqi_ctrl_in_shutdown(ctrl_info)) { |
7561a7e4 KB |
5359 | rc = SCSI_MLQUEUE_HOST_BUSY; |
5360 | goto out; | |
5361 | } | |
5362 | ||
7d81d2b8 KB |
5363 | /* |
5364 | * This is necessary because the SML doesn't zero out this field during | |
5365 | * error recovery. | |
5366 | */ | |
5367 | scmd->result = 0; | |
5368 | ||
061ef06a KB |
5369 | hw_queue = pqi_get_hw_queue(ctrl_info, scmd); |
5370 | queue_group = &ctrl_info->queue_groups[hw_queue]; | |
6c223761 KB |
5371 | |
5372 | if (pqi_is_logical_device(device)) { | |
5373 | raid_bypassed = false; | |
588a63fe | 5374 | if (device->raid_bypass_enabled && |
694c5d5b | 5375 | !blk_rq_is_passthrough(scmd->request)) { |
6c223761 KB |
5376 | rc = pqi_raid_bypass_submit_scsi_cmd(ctrl_info, device, |
5377 | scmd, queue_group); | |
376fb880 KB |
5378 | if (rc == 0 || rc == SCSI_MLQUEUE_HOST_BUSY) |
5379 | raid_bypassed = true; | |
6c223761 KB |
5380 | } |
5381 | if (!raid_bypassed) | |
5382 | rc = pqi_raid_submit_scsi_cmd(ctrl_info, device, scmd, | |
5383 | queue_group); | |
5384 | } else { | |
5385 | if (device->aio_enabled) | |
5386 | rc = pqi_aio_submit_scsi_cmd(ctrl_info, device, scmd, | |
5387 | queue_group); | |
5388 | else | |
5389 | rc = pqi_raid_submit_scsi_cmd(ctrl_info, device, scmd, | |
5390 | queue_group); | |
5391 | } | |
5392 | ||
7561a7e4 KB |
5393 | out: |
5394 | pqi_ctrl_unbusy(ctrl_info); | |
5395 | if (rc) | |
5396 | atomic_dec(&device->scsi_cmds_outstanding); | |
5397 | ||
6c223761 KB |
5398 | return rc; |
5399 | } | |
5400 | ||
7561a7e4 KB |
5401 | static int pqi_wait_until_queued_io_drained(struct pqi_ctrl_info *ctrl_info, |
5402 | struct pqi_queue_group *queue_group) | |
5403 | { | |
5404 | unsigned int path; | |
5405 | unsigned long flags; | |
5406 | bool list_is_empty; | |
5407 | ||
5408 | for (path = 0; path < 2; path++) { | |
5409 | while (1) { | |
5410 | spin_lock_irqsave( | |
5411 | &queue_group->submit_lock[path], flags); | |
5412 | list_is_empty = | |
5413 | list_empty(&queue_group->request_list[path]); | |
5414 | spin_unlock_irqrestore( | |
5415 | &queue_group->submit_lock[path], flags); | |
5416 | if (list_is_empty) | |
5417 | break; | |
5418 | pqi_check_ctrl_health(ctrl_info); | |
5419 | if (pqi_ctrl_offline(ctrl_info)) | |
5420 | return -ENXIO; | |
5421 | usleep_range(1000, 2000); | |
5422 | } | |
5423 | } | |
5424 | ||
5425 | return 0; | |
5426 | } | |
5427 | ||
5428 | static int pqi_wait_until_inbound_queues_empty(struct pqi_ctrl_info *ctrl_info) | |
5429 | { | |
5430 | int rc; | |
5431 | unsigned int i; | |
5432 | unsigned int path; | |
5433 | struct pqi_queue_group *queue_group; | |
5434 | pqi_index_t iq_pi; | |
5435 | pqi_index_t iq_ci; | |
5436 | ||
5437 | for (i = 0; i < ctrl_info->num_queue_groups; i++) { | |
5438 | queue_group = &ctrl_info->queue_groups[i]; | |
5439 | ||
5440 | rc = pqi_wait_until_queued_io_drained(ctrl_info, queue_group); | |
5441 | if (rc) | |
5442 | return rc; | |
5443 | ||
5444 | for (path = 0; path < 2; path++) { | |
5445 | iq_pi = queue_group->iq_pi_copy[path]; | |
5446 | ||
5447 | while (1) { | |
dac12fbc | 5448 | iq_ci = readl(queue_group->iq_ci[path]); |
7561a7e4 KB |
5449 | if (iq_ci == iq_pi) |
5450 | break; | |
5451 | pqi_check_ctrl_health(ctrl_info); | |
5452 | if (pqi_ctrl_offline(ctrl_info)) | |
5453 | return -ENXIO; | |
5454 | usleep_range(1000, 2000); | |
5455 | } | |
5456 | } | |
5457 | } | |
5458 | ||
5459 | return 0; | |
5460 | } | |
5461 | ||
5462 | static void pqi_fail_io_queued_for_device(struct pqi_ctrl_info *ctrl_info, | |
5463 | struct pqi_scsi_dev *device) | |
5464 | { | |
5465 | unsigned int i; | |
5466 | unsigned int path; | |
5467 | struct pqi_queue_group *queue_group; | |
5468 | unsigned long flags; | |
5469 | struct pqi_io_request *io_request; | |
5470 | struct pqi_io_request *next; | |
5471 | struct scsi_cmnd *scmd; | |
5472 | struct pqi_scsi_dev *scsi_device; | |
5473 | ||
5474 | for (i = 0; i < ctrl_info->num_queue_groups; i++) { | |
5475 | queue_group = &ctrl_info->queue_groups[i]; | |
5476 | ||
5477 | for (path = 0; path < 2; path++) { | |
5478 | spin_lock_irqsave( | |
5479 | &queue_group->submit_lock[path], flags); | |
5480 | ||
5481 | list_for_each_entry_safe(io_request, next, | |
5482 | &queue_group->request_list[path], | |
5483 | request_list_entry) { | |
5484 | scmd = io_request->scmd; | |
5485 | if (!scmd) | |
5486 | continue; | |
5487 | ||
5488 | scsi_device = scmd->device->hostdata; | |
5489 | if (scsi_device != device) | |
5490 | continue; | |
5491 | ||
5492 | list_del(&io_request->request_list_entry); | |
5493 | set_host_byte(scmd, DID_RESET); | |
5494 | pqi_scsi_done(scmd); | |
5495 | } | |
5496 | ||
5497 | spin_unlock_irqrestore( | |
5498 | &queue_group->submit_lock[path], flags); | |
5499 | } | |
5500 | } | |
5501 | } | |
5502 | ||
4fd22c13 MR |
5503 | static void pqi_fail_io_queued_for_all_devices(struct pqi_ctrl_info *ctrl_info) |
5504 | { | |
5505 | unsigned int i; | |
5506 | unsigned int path; | |
5507 | struct pqi_queue_group *queue_group; | |
5508 | unsigned long flags; | |
5509 | struct pqi_io_request *io_request; | |
5510 | struct pqi_io_request *next; | |
5511 | struct scsi_cmnd *scmd; | |
5512 | ||
5513 | for (i = 0; i < ctrl_info->num_queue_groups; i++) { | |
5514 | queue_group = &ctrl_info->queue_groups[i]; | |
5515 | ||
5516 | for (path = 0; path < 2; path++) { | |
5517 | spin_lock_irqsave(&queue_group->submit_lock[path], | |
5518 | flags); | |
5519 | ||
5520 | list_for_each_entry_safe(io_request, next, | |
5521 | &queue_group->request_list[path], | |
5522 | request_list_entry) { | |
5523 | ||
5524 | scmd = io_request->scmd; | |
5525 | if (!scmd) | |
5526 | continue; | |
5527 | ||
5528 | list_del(&io_request->request_list_entry); | |
5529 | set_host_byte(scmd, DID_RESET); | |
5530 | pqi_scsi_done(scmd); | |
5531 | } | |
5532 | ||
5533 | spin_unlock_irqrestore( | |
5534 | &queue_group->submit_lock[path], flags); | |
5535 | } | |
5536 | } | |
5537 | } | |
5538 | ||
061ef06a | 5539 | static int pqi_device_wait_for_pending_io(struct pqi_ctrl_info *ctrl_info, |
1e46731e | 5540 | struct pqi_scsi_dev *device, unsigned long timeout_secs) |
061ef06a | 5541 | { |
1e46731e MR |
5542 | unsigned long timeout; |
5543 | ||
4fd22c13 | 5544 | timeout = (timeout_secs * PQI_HZ) + jiffies; |
1e46731e | 5545 | |
061ef06a KB |
5546 | while (atomic_read(&device->scsi_cmds_outstanding)) { |
5547 | pqi_check_ctrl_health(ctrl_info); | |
5548 | if (pqi_ctrl_offline(ctrl_info)) | |
5549 | return -ENXIO; | |
1e46731e MR |
5550 | if (timeout_secs != NO_TIMEOUT) { |
5551 | if (time_after(jiffies, timeout)) { | |
5552 | dev_err(&ctrl_info->pci_dev->dev, | |
5553 | "timed out waiting for pending IO\n"); | |
5554 | return -ETIMEDOUT; | |
5555 | } | |
5556 | } | |
061ef06a KB |
5557 | usleep_range(1000, 2000); |
5558 | } | |
5559 | ||
5560 | return 0; | |
5561 | } | |
5562 | ||
4fd22c13 MR |
5563 | static int pqi_ctrl_wait_for_pending_io(struct pqi_ctrl_info *ctrl_info, |
5564 | unsigned long timeout_secs) | |
061ef06a KB |
5565 | { |
5566 | bool io_pending; | |
5567 | unsigned long flags; | |
4fd22c13 | 5568 | unsigned long timeout; |
061ef06a KB |
5569 | struct pqi_scsi_dev *device; |
5570 | ||
4fd22c13 | 5571 | timeout = (timeout_secs * PQI_HZ) + jiffies; |
061ef06a KB |
5572 | while (1) { |
5573 | io_pending = false; | |
5574 | ||
5575 | spin_lock_irqsave(&ctrl_info->scsi_device_list_lock, flags); | |
5576 | list_for_each_entry(device, &ctrl_info->scsi_device_list, | |
5577 | scsi_device_list_entry) { | |
5578 | if (atomic_read(&device->scsi_cmds_outstanding)) { | |
5579 | io_pending = true; | |
5580 | break; | |
5581 | } | |
5582 | } | |
5583 | spin_unlock_irqrestore(&ctrl_info->scsi_device_list_lock, | |
5584 | flags); | |
5585 | ||
5586 | if (!io_pending) | |
5587 | break; | |
5588 | ||
5589 | pqi_check_ctrl_health(ctrl_info); | |
5590 | if (pqi_ctrl_offline(ctrl_info)) | |
5591 | return -ENXIO; | |
5592 | ||
4fd22c13 MR |
5593 | if (timeout_secs != NO_TIMEOUT) { |
5594 | if (time_after(jiffies, timeout)) { | |
5595 | dev_err(&ctrl_info->pci_dev->dev, | |
5596 | "timed out waiting for pending IO\n"); | |
5597 | return -ETIMEDOUT; | |
5598 | } | |
5599 | } | |
061ef06a KB |
5600 | usleep_range(1000, 2000); |
5601 | } | |
5602 | ||
5603 | return 0; | |
5604 | } | |
5605 | ||
0530736e KB |
5606 | static int pqi_ctrl_wait_for_pending_sync_cmds(struct pqi_ctrl_info *ctrl_info) |
5607 | { | |
5608 | while (atomic_read(&ctrl_info->sync_cmds_outstanding)) { | |
5609 | pqi_check_ctrl_health(ctrl_info); | |
5610 | if (pqi_ctrl_offline(ctrl_info)) | |
5611 | return -ENXIO; | |
5612 | usleep_range(1000, 2000); | |
5613 | } | |
5614 | ||
5615 | return 0; | |
5616 | } | |
5617 | ||
14bb215d KB |
5618 | static void pqi_lun_reset_complete(struct pqi_io_request *io_request, |
5619 | void *context) | |
6c223761 | 5620 | { |
14bb215d | 5621 | struct completion *waiting = context; |
6c223761 | 5622 | |
14bb215d KB |
5623 | complete(waiting); |
5624 | } | |
6c223761 | 5625 | |
bb9af08c | 5626 | #define PQI_LUN_RESET_TIMEOUT_SECS 30 |
c2922f17 | 5627 | #define PQI_LUN_RESET_POLL_COMPLETION_SECS 10 |
14bb215d KB |
5628 | |
5629 | static int pqi_wait_for_lun_reset_completion(struct pqi_ctrl_info *ctrl_info, | |
5630 | struct pqi_scsi_dev *device, struct completion *wait) | |
5631 | { | |
5632 | int rc; | |
14bb215d KB |
5633 | |
5634 | while (1) { | |
5635 | if (wait_for_completion_io_timeout(wait, | |
c2922f17 | 5636 | PQI_LUN_RESET_POLL_COMPLETION_SECS * PQI_HZ)) { |
14bb215d KB |
5637 | rc = 0; |
5638 | break; | |
6c223761 KB |
5639 | } |
5640 | ||
14bb215d KB |
5641 | pqi_check_ctrl_health(ctrl_info); |
5642 | if (pqi_ctrl_offline(ctrl_info)) { | |
4e8415e3 | 5643 | rc = -ENXIO; |
14bb215d KB |
5644 | break; |
5645 | } | |
6c223761 | 5646 | } |
6c223761 | 5647 | |
14bb215d | 5648 | return rc; |
6c223761 KB |
5649 | } |
5650 | ||
14bb215d | 5651 | static int pqi_lun_reset(struct pqi_ctrl_info *ctrl_info, |
6c223761 KB |
5652 | struct pqi_scsi_dev *device) |
5653 | { | |
5654 | int rc; | |
5655 | struct pqi_io_request *io_request; | |
5656 | DECLARE_COMPLETION_ONSTACK(wait); | |
5657 | struct pqi_task_management_request *request; | |
5658 | ||
6c223761 | 5659 | io_request = pqi_alloc_io_request(ctrl_info); |
14bb215d | 5660 | io_request->io_complete_callback = pqi_lun_reset_complete; |
6c223761 KB |
5661 | io_request->context = &wait; |
5662 | ||
5663 | request = io_request->iu; | |
5664 | memset(request, 0, sizeof(*request)); | |
5665 | ||
5666 | request->header.iu_type = PQI_REQUEST_IU_TASK_MANAGEMENT; | |
5667 | put_unaligned_le16(sizeof(*request) - PQI_REQUEST_HEADER_LENGTH, | |
5668 | &request->header.iu_length); | |
5669 | put_unaligned_le16(io_request->index, &request->request_id); | |
5670 | memcpy(request->lun_number, device->scsi3addr, | |
5671 | sizeof(request->lun_number)); | |
5672 | request->task_management_function = SOP_TASK_MANAGEMENT_LUN_RESET; | |
c2922f17 MB |
5673 | if (ctrl_info->tmf_iu_timeout_supported) |
5674 | put_unaligned_le16(PQI_LUN_RESET_TIMEOUT_SECS, | |
5675 | &request->timeout); | |
6c223761 KB |
5676 | |
5677 | pqi_start_io(ctrl_info, | |
5678 | &ctrl_info->queue_groups[PQI_DEFAULT_QUEUE_GROUP], RAID_PATH, | |
5679 | io_request); | |
5680 | ||
14bb215d KB |
5681 | rc = pqi_wait_for_lun_reset_completion(ctrl_info, device, &wait); |
5682 | if (rc == 0) | |
6c223761 | 5683 | rc = io_request->status; |
6c223761 KB |
5684 | |
5685 | pqi_free_io_request(io_request); | |
6c223761 KB |
5686 | |
5687 | return rc; | |
5688 | } | |
5689 | ||
429fab70 KB |
5690 | /* Performs a reset at the LUN level. */ |
5691 | ||
3406384b MR |
5692 | #define PQI_LUN_RESET_RETRIES 3 |
5693 | #define PQI_LUN_RESET_RETRY_INTERVAL_MSECS 10000 | |
429fab70 | 5694 | #define PQI_LUN_RESET_PENDING_IO_TIMEOUT_SECS 120 |
6c223761 | 5695 | |
4fd22c13 | 5696 | static int _pqi_device_reset(struct pqi_ctrl_info *ctrl_info, |
6c223761 KB |
5697 | struct pqi_scsi_dev *device) |
5698 | { | |
5699 | int rc; | |
3406384b | 5700 | unsigned int retries; |
4fd22c13 | 5701 | unsigned long timeout_secs; |
6c223761 | 5702 | |
3406384b MR |
5703 | for (retries = 0;;) { |
5704 | rc = pqi_lun_reset(ctrl_info, device); | |
c2922f17 | 5705 | if (rc == 0 || ++retries > PQI_LUN_RESET_RETRIES) |
3406384b MR |
5706 | break; |
5707 | msleep(PQI_LUN_RESET_RETRY_INTERVAL_MSECS); | |
5708 | } | |
429fab70 KB |
5709 | |
5710 | timeout_secs = rc ? PQI_LUN_RESET_PENDING_IO_TIMEOUT_SECS : NO_TIMEOUT; | |
4fd22c13 MR |
5711 | |
5712 | rc |= pqi_device_wait_for_pending_io(ctrl_info, device, timeout_secs); | |
6c223761 | 5713 | |
14bb215d | 5714 | return rc == 0 ? SUCCESS : FAILED; |
6c223761 KB |
5715 | } |
5716 | ||
4fd22c13 MR |
5717 | static int pqi_device_reset(struct pqi_ctrl_info *ctrl_info, |
5718 | struct pqi_scsi_dev *device) | |
5719 | { | |
5720 | int rc; | |
5721 | ||
5722 | mutex_lock(&ctrl_info->lun_reset_mutex); | |
5723 | ||
5724 | pqi_ctrl_block_requests(ctrl_info); | |
5725 | pqi_ctrl_wait_until_quiesced(ctrl_info); | |
5726 | pqi_fail_io_queued_for_device(ctrl_info, device); | |
5727 | rc = pqi_wait_until_inbound_queues_empty(ctrl_info); | |
5728 | pqi_device_reset_start(device); | |
5729 | pqi_ctrl_unblock_requests(ctrl_info); | |
5730 | ||
5731 | if (rc) | |
5732 | rc = FAILED; | |
5733 | else | |
5734 | rc = _pqi_device_reset(ctrl_info, device); | |
5735 | ||
5736 | pqi_device_reset_done(device); | |
5737 | ||
5738 | mutex_unlock(&ctrl_info->lun_reset_mutex); | |
429fab70 | 5739 | |
4fd22c13 MR |
5740 | return rc; |
5741 | } | |
5742 | ||
6c223761 KB |
5743 | static int pqi_eh_device_reset_handler(struct scsi_cmnd *scmd) |
5744 | { | |
5745 | int rc; | |
7561a7e4 | 5746 | struct Scsi_Host *shost; |
6c223761 KB |
5747 | struct pqi_ctrl_info *ctrl_info; |
5748 | struct pqi_scsi_dev *device; | |
5749 | ||
7561a7e4 KB |
5750 | shost = scmd->device->host; |
5751 | ctrl_info = shost_to_hba(shost); | |
6c223761 KB |
5752 | device = scmd->device->hostdata; |
5753 | ||
5754 | dev_err(&ctrl_info->pci_dev->dev, | |
5755 | "resetting scsi %d:%d:%d:%d\n", | |
7561a7e4 | 5756 | shost->host_no, device->bus, device->target, device->lun); |
6c223761 | 5757 | |
7561a7e4 | 5758 | pqi_check_ctrl_health(ctrl_info); |
0530736e KB |
5759 | if (pqi_ctrl_offline(ctrl_info) || |
5760 | pqi_device_reset_blocked(ctrl_info)) { | |
7561a7e4 KB |
5761 | rc = FAILED; |
5762 | goto out; | |
5763 | } | |
6c223761 | 5764 | |
4fd22c13 | 5765 | pqi_wait_until_ofa_finished(ctrl_info); |
7561a7e4 | 5766 | |
0530736e | 5767 | atomic_inc(&ctrl_info->sync_cmds_outstanding); |
4fd22c13 | 5768 | rc = pqi_device_reset(ctrl_info, device); |
0530736e | 5769 | atomic_dec(&ctrl_info->sync_cmds_outstanding); |
429fab70 | 5770 | |
7561a7e4 | 5771 | out: |
6c223761 KB |
5772 | dev_err(&ctrl_info->pci_dev->dev, |
5773 | "reset of scsi %d:%d:%d:%d: %s\n", | |
7561a7e4 | 5774 | shost->host_no, device->bus, device->target, device->lun, |
6c223761 KB |
5775 | rc == SUCCESS ? "SUCCESS" : "FAILED"); |
5776 | ||
5777 | return rc; | |
5778 | } | |
5779 | ||
5780 | static int pqi_slave_alloc(struct scsi_device *sdev) | |
5781 | { | |
5782 | struct pqi_scsi_dev *device; | |
5783 | unsigned long flags; | |
5784 | struct pqi_ctrl_info *ctrl_info; | |
5785 | struct scsi_target *starget; | |
5786 | struct sas_rphy *rphy; | |
5787 | ||
5788 | ctrl_info = shost_to_hba(sdev->host); | |
5789 | ||
5790 | spin_lock_irqsave(&ctrl_info->scsi_device_list_lock, flags); | |
5791 | ||
5792 | if (sdev_channel(sdev) == PQI_PHYSICAL_DEVICE_BUS) { | |
5793 | starget = scsi_target(sdev); | |
5794 | rphy = target_to_rphy(starget); | |
5795 | device = pqi_find_device_by_sas_rphy(ctrl_info, rphy); | |
5796 | if (device) { | |
5797 | device->target = sdev_id(sdev); | |
5798 | device->lun = sdev->lun; | |
5799 | device->target_lun_valid = true; | |
5800 | } | |
5801 | } else { | |
5802 | device = pqi_find_scsi_dev(ctrl_info, sdev_channel(sdev), | |
5803 | sdev_id(sdev), sdev->lun); | |
5804 | } | |
5805 | ||
94086f5b | 5806 | if (device) { |
6c223761 KB |
5807 | sdev->hostdata = device; |
5808 | device->sdev = sdev; | |
5809 | if (device->queue_depth) { | |
5810 | device->advertised_queue_depth = device->queue_depth; | |
5811 | scsi_change_queue_depth(sdev, | |
5812 | device->advertised_queue_depth); | |
5813 | } | |
b6e2ef67 DC |
5814 | if (pqi_is_logical_device(device)) |
5815 | pqi_disable_write_same(sdev); | |
2b447f81 DC |
5816 | else |
5817 | sdev->allow_restart = 1; | |
6c223761 KB |
5818 | } |
5819 | ||
5820 | spin_unlock_irqrestore(&ctrl_info->scsi_device_list_lock, flags); | |
5821 | ||
5822 | return 0; | |
5823 | } | |
5824 | ||
52198226 CH |
5825 | static int pqi_map_queues(struct Scsi_Host *shost) |
5826 | { | |
5827 | struct pqi_ctrl_info *ctrl_info = shost_to_hba(shost); | |
5828 | ||
79d3fa9e | 5829 | return blk_mq_pci_map_queues(&shost->tag_set.map[HCTX_TYPE_DEFAULT], |
ed76e329 | 5830 | ctrl_info->pci_dev, 0); |
52198226 CH |
5831 | } |
5832 | ||
ce143793 KB |
5833 | static int pqi_slave_configure(struct scsi_device *sdev) |
5834 | { | |
5835 | struct pqi_scsi_dev *device; | |
5836 | ||
5837 | device = sdev->hostdata; | |
5838 | device->devtype = sdev->type; | |
5839 | ||
5840 | return 0; | |
5841 | } | |
5842 | ||
6c223761 KB |
5843 | static int pqi_getpciinfo_ioctl(struct pqi_ctrl_info *ctrl_info, |
5844 | void __user *arg) | |
5845 | { | |
5846 | struct pci_dev *pci_dev; | |
5847 | u32 subsystem_vendor; | |
5848 | u32 subsystem_device; | |
5849 | cciss_pci_info_struct pciinfo; | |
5850 | ||
5851 | if (!arg) | |
5852 | return -EINVAL; | |
5853 | ||
5854 | pci_dev = ctrl_info->pci_dev; | |
5855 | ||
5856 | pciinfo.domain = pci_domain_nr(pci_dev->bus); | |
5857 | pciinfo.bus = pci_dev->bus->number; | |
5858 | pciinfo.dev_fn = pci_dev->devfn; | |
5859 | subsystem_vendor = pci_dev->subsystem_vendor; | |
5860 | subsystem_device = pci_dev->subsystem_device; | |
5861 | pciinfo.board_id = ((subsystem_device << 16) & 0xffff0000) | | |
5862 | subsystem_vendor; | |
5863 | ||
5864 | if (copy_to_user(arg, &pciinfo, sizeof(pciinfo))) | |
5865 | return -EFAULT; | |
5866 | ||
5867 | return 0; | |
5868 | } | |
5869 | ||
5870 | static int pqi_getdrivver_ioctl(void __user *arg) | |
5871 | { | |
5872 | u32 version; | |
5873 | ||
5874 | if (!arg) | |
5875 | return -EINVAL; | |
5876 | ||
5877 | version = (DRIVER_MAJOR << 28) | (DRIVER_MINOR << 24) | | |
5878 | (DRIVER_RELEASE << 16) | DRIVER_REVISION; | |
5879 | ||
5880 | if (copy_to_user(arg, &version, sizeof(version))) | |
5881 | return -EFAULT; | |
5882 | ||
5883 | return 0; | |
5884 | } | |
5885 | ||
5886 | struct ciss_error_info { | |
5887 | u8 scsi_status; | |
5888 | int command_status; | |
5889 | size_t sense_data_length; | |
5890 | }; | |
5891 | ||
5892 | static void pqi_error_info_to_ciss(struct pqi_raid_error_info *pqi_error_info, | |
5893 | struct ciss_error_info *ciss_error_info) | |
5894 | { | |
5895 | int ciss_cmd_status; | |
5896 | size_t sense_data_length; | |
5897 | ||
5898 | switch (pqi_error_info->data_out_result) { | |
5899 | case PQI_DATA_IN_OUT_GOOD: | |
5900 | ciss_cmd_status = CISS_CMD_STATUS_SUCCESS; | |
5901 | break; | |
5902 | case PQI_DATA_IN_OUT_UNDERFLOW: | |
5903 | ciss_cmd_status = CISS_CMD_STATUS_DATA_UNDERRUN; | |
5904 | break; | |
5905 | case PQI_DATA_IN_OUT_BUFFER_OVERFLOW: | |
5906 | ciss_cmd_status = CISS_CMD_STATUS_DATA_OVERRUN; | |
5907 | break; | |
5908 | case PQI_DATA_IN_OUT_PROTOCOL_ERROR: | |
5909 | case PQI_DATA_IN_OUT_BUFFER_ERROR: | |
5910 | case PQI_DATA_IN_OUT_BUFFER_OVERFLOW_DESCRIPTOR_AREA: | |
5911 | case PQI_DATA_IN_OUT_BUFFER_OVERFLOW_BRIDGE: | |
5912 | case PQI_DATA_IN_OUT_ERROR: | |
5913 | ciss_cmd_status = CISS_CMD_STATUS_PROTOCOL_ERROR; | |
5914 | break; | |
5915 | case PQI_DATA_IN_OUT_HARDWARE_ERROR: | |
5916 | case PQI_DATA_IN_OUT_PCIE_FABRIC_ERROR: | |
5917 | case PQI_DATA_IN_OUT_PCIE_COMPLETION_TIMEOUT: | |
5918 | case PQI_DATA_IN_OUT_PCIE_COMPLETER_ABORT_RECEIVED: | |
5919 | case PQI_DATA_IN_OUT_PCIE_UNSUPPORTED_REQUEST_RECEIVED: | |
5920 | case PQI_DATA_IN_OUT_PCIE_ECRC_CHECK_FAILED: | |
5921 | case PQI_DATA_IN_OUT_PCIE_UNSUPPORTED_REQUEST: | |
5922 | case PQI_DATA_IN_OUT_PCIE_ACS_VIOLATION: | |
5923 | case PQI_DATA_IN_OUT_PCIE_TLP_PREFIX_BLOCKED: | |
5924 | case PQI_DATA_IN_OUT_PCIE_POISONED_MEMORY_READ: | |
5925 | ciss_cmd_status = CISS_CMD_STATUS_HARDWARE_ERROR; | |
5926 | break; | |
5927 | case PQI_DATA_IN_OUT_UNSOLICITED_ABORT: | |
5928 | ciss_cmd_status = CISS_CMD_STATUS_UNSOLICITED_ABORT; | |
5929 | break; | |
5930 | case PQI_DATA_IN_OUT_ABORTED: | |
5931 | ciss_cmd_status = CISS_CMD_STATUS_ABORTED; | |
5932 | break; | |
5933 | case PQI_DATA_IN_OUT_TIMEOUT: | |
5934 | ciss_cmd_status = CISS_CMD_STATUS_TIMEOUT; | |
5935 | break; | |
5936 | default: | |
5937 | ciss_cmd_status = CISS_CMD_STATUS_TARGET_STATUS; | |
5938 | break; | |
5939 | } | |
5940 | ||
5941 | sense_data_length = | |
5942 | get_unaligned_le16(&pqi_error_info->sense_data_length); | |
5943 | if (sense_data_length == 0) | |
5944 | sense_data_length = | |
5945 | get_unaligned_le16(&pqi_error_info->response_data_length); | |
5946 | if (sense_data_length) | |
5947 | if (sense_data_length > sizeof(pqi_error_info->data)) | |
5948 | sense_data_length = sizeof(pqi_error_info->data); | |
5949 | ||
5950 | ciss_error_info->scsi_status = pqi_error_info->status; | |
5951 | ciss_error_info->command_status = ciss_cmd_status; | |
5952 | ciss_error_info->sense_data_length = sense_data_length; | |
5953 | } | |
5954 | ||
5955 | static int pqi_passthru_ioctl(struct pqi_ctrl_info *ctrl_info, void __user *arg) | |
5956 | { | |
5957 | int rc; | |
5958 | char *kernel_buffer = NULL; | |
5959 | u16 iu_length; | |
5960 | size_t sense_data_length; | |
5961 | IOCTL_Command_struct iocommand; | |
5962 | struct pqi_raid_path_request request; | |
5963 | struct pqi_raid_error_info pqi_error_info; | |
5964 | struct ciss_error_info ciss_error_info; | |
5965 | ||
5966 | if (pqi_ctrl_offline(ctrl_info)) | |
5967 | return -ENXIO; | |
5968 | if (!arg) | |
5969 | return -EINVAL; | |
5970 | if (!capable(CAP_SYS_RAWIO)) | |
5971 | return -EPERM; | |
5972 | if (copy_from_user(&iocommand, arg, sizeof(iocommand))) | |
5973 | return -EFAULT; | |
5974 | if (iocommand.buf_size < 1 && | |
5975 | iocommand.Request.Type.Direction != XFER_NONE) | |
5976 | return -EINVAL; | |
5977 | if (iocommand.Request.CDBLen > sizeof(request.cdb)) | |
5978 | return -EINVAL; | |
5979 | if (iocommand.Request.Type.Type != TYPE_CMD) | |
5980 | return -EINVAL; | |
5981 | ||
5982 | switch (iocommand.Request.Type.Direction) { | |
5983 | case XFER_NONE: | |
5984 | case XFER_WRITE: | |
5985 | case XFER_READ: | |
41555d54 | 5986 | case XFER_READ | XFER_WRITE: |
6c223761 KB |
5987 | break; |
5988 | default: | |
5989 | return -EINVAL; | |
5990 | } | |
5991 | ||
5992 | if (iocommand.buf_size > 0) { | |
5993 | kernel_buffer = kmalloc(iocommand.buf_size, GFP_KERNEL); | |
5994 | if (!kernel_buffer) | |
5995 | return -ENOMEM; | |
5996 | if (iocommand.Request.Type.Direction & XFER_WRITE) { | |
5997 | if (copy_from_user(kernel_buffer, iocommand.buf, | |
5998 | iocommand.buf_size)) { | |
5999 | rc = -EFAULT; | |
6000 | goto out; | |
6001 | } | |
6002 | } else { | |
6003 | memset(kernel_buffer, 0, iocommand.buf_size); | |
6004 | } | |
6005 | } | |
6006 | ||
6007 | memset(&request, 0, sizeof(request)); | |
6008 | ||
6009 | request.header.iu_type = PQI_REQUEST_IU_RAID_PATH_IO; | |
6010 | iu_length = offsetof(struct pqi_raid_path_request, sg_descriptors) - | |
6011 | PQI_REQUEST_HEADER_LENGTH; | |
6012 | memcpy(request.lun_number, iocommand.LUN_info.LunAddrBytes, | |
6013 | sizeof(request.lun_number)); | |
6014 | memcpy(request.cdb, iocommand.Request.CDB, iocommand.Request.CDBLen); | |
6015 | request.additional_cdb_bytes_usage = SOP_ADDITIONAL_CDB_BYTES_0; | |
6016 | ||
6017 | switch (iocommand.Request.Type.Direction) { | |
6018 | case XFER_NONE: | |
6019 | request.data_direction = SOP_NO_DIRECTION_FLAG; | |
6020 | break; | |
6021 | case XFER_WRITE: | |
6022 | request.data_direction = SOP_WRITE_FLAG; | |
6023 | break; | |
6024 | case XFER_READ: | |
6025 | request.data_direction = SOP_READ_FLAG; | |
6026 | break; | |
41555d54 KB |
6027 | case XFER_READ | XFER_WRITE: |
6028 | request.data_direction = SOP_BIDIRECTIONAL; | |
6029 | break; | |
6c223761 KB |
6030 | } |
6031 | ||
6032 | request.task_attribute = SOP_TASK_ATTRIBUTE_SIMPLE; | |
6033 | ||
6034 | if (iocommand.buf_size > 0) { | |
6035 | put_unaligned_le32(iocommand.buf_size, &request.buffer_length); | |
6036 | ||
6037 | rc = pqi_map_single(ctrl_info->pci_dev, | |
6038 | &request.sg_descriptors[0], kernel_buffer, | |
6917a9cc | 6039 | iocommand.buf_size, DMA_BIDIRECTIONAL); |
6c223761 KB |
6040 | if (rc) |
6041 | goto out; | |
6042 | ||
6043 | iu_length += sizeof(request.sg_descriptors[0]); | |
6044 | } | |
6045 | ||
6046 | put_unaligned_le16(iu_length, &request.header.iu_length); | |
6047 | ||
21432010 | 6048 | if (ctrl_info->raid_iu_timeout_supported) |
6049 | put_unaligned_le32(iocommand.Request.Timeout, &request.timeout); | |
6050 | ||
6c223761 KB |
6051 | rc = pqi_submit_raid_request_synchronous(ctrl_info, &request.header, |
6052 | PQI_SYNC_FLAGS_INTERRUPTABLE, &pqi_error_info, NO_TIMEOUT); | |
6053 | ||
6054 | if (iocommand.buf_size > 0) | |
6055 | pqi_pci_unmap(ctrl_info->pci_dev, request.sg_descriptors, 1, | |
6917a9cc | 6056 | DMA_BIDIRECTIONAL); |
6c223761 KB |
6057 | |
6058 | memset(&iocommand.error_info, 0, sizeof(iocommand.error_info)); | |
6059 | ||
6060 | if (rc == 0) { | |
6061 | pqi_error_info_to_ciss(&pqi_error_info, &ciss_error_info); | |
6062 | iocommand.error_info.ScsiStatus = ciss_error_info.scsi_status; | |
6063 | iocommand.error_info.CommandStatus = | |
6064 | ciss_error_info.command_status; | |
6065 | sense_data_length = ciss_error_info.sense_data_length; | |
6066 | if (sense_data_length) { | |
6067 | if (sense_data_length > | |
6068 | sizeof(iocommand.error_info.SenseInfo)) | |
6069 | sense_data_length = | |
6070 | sizeof(iocommand.error_info.SenseInfo); | |
6071 | memcpy(iocommand.error_info.SenseInfo, | |
6072 | pqi_error_info.data, sense_data_length); | |
6073 | iocommand.error_info.SenseLen = sense_data_length; | |
6074 | } | |
6075 | } | |
6076 | ||
6077 | if (copy_to_user(arg, &iocommand, sizeof(iocommand))) { | |
6078 | rc = -EFAULT; | |
6079 | goto out; | |
6080 | } | |
6081 | ||
6082 | if (rc == 0 && iocommand.buf_size > 0 && | |
6083 | (iocommand.Request.Type.Direction & XFER_READ)) { | |
6084 | if (copy_to_user(iocommand.buf, kernel_buffer, | |
6085 | iocommand.buf_size)) { | |
6086 | rc = -EFAULT; | |
6087 | } | |
6088 | } | |
6089 | ||
6090 | out: | |
6091 | kfree(kernel_buffer); | |
6092 | ||
6093 | return rc; | |
6094 | } | |
6095 | ||
6f4e626f NC |
6096 | static int pqi_ioctl(struct scsi_device *sdev, unsigned int cmd, |
6097 | void __user *arg) | |
6c223761 KB |
6098 | { |
6099 | int rc; | |
6100 | struct pqi_ctrl_info *ctrl_info; | |
6101 | ||
6102 | ctrl_info = shost_to_hba(sdev->host); | |
6103 | ||
694c5d5b | 6104 | if (pqi_ctrl_in_ofa(ctrl_info) || pqi_ctrl_in_shutdown(ctrl_info)) |
4fd22c13 MR |
6105 | return -EBUSY; |
6106 | ||
6c223761 KB |
6107 | switch (cmd) { |
6108 | case CCISS_DEREGDISK: | |
6109 | case CCISS_REGNEWDISK: | |
6110 | case CCISS_REGNEWD: | |
6111 | rc = pqi_scan_scsi_devices(ctrl_info); | |
6112 | break; | |
6113 | case CCISS_GETPCIINFO: | |
6114 | rc = pqi_getpciinfo_ioctl(ctrl_info, arg); | |
6115 | break; | |
6116 | case CCISS_GETDRIVVER: | |
6117 | rc = pqi_getdrivver_ioctl(arg); | |
6118 | break; | |
6119 | case CCISS_PASSTHRU: | |
6120 | rc = pqi_passthru_ioctl(ctrl_info, arg); | |
6121 | break; | |
6122 | default: | |
6123 | rc = -EINVAL; | |
6124 | break; | |
6125 | } | |
6126 | ||
6127 | return rc; | |
6128 | } | |
6129 | ||
6d90615f | 6130 | static ssize_t pqi_firmware_version_show(struct device *dev, |
6c223761 KB |
6131 | struct device_attribute *attr, char *buffer) |
6132 | { | |
6c223761 KB |
6133 | struct Scsi_Host *shost; |
6134 | struct pqi_ctrl_info *ctrl_info; | |
6135 | ||
6136 | shost = class_to_shost(dev); | |
6137 | ctrl_info = shost_to_hba(shost); | |
6138 | ||
6d90615f MB |
6139 | return snprintf(buffer, PAGE_SIZE, "%s\n", ctrl_info->firmware_version); |
6140 | } | |
6141 | ||
6142 | static ssize_t pqi_driver_version_show(struct device *dev, | |
6143 | struct device_attribute *attr, char *buffer) | |
6144 | { | |
694c5d5b KB |
6145 | return snprintf(buffer, PAGE_SIZE, "%s\n", |
6146 | DRIVER_VERSION BUILD_TIMESTAMP); | |
6d90615f | 6147 | } |
6c223761 | 6148 | |
6d90615f MB |
6149 | static ssize_t pqi_serial_number_show(struct device *dev, |
6150 | struct device_attribute *attr, char *buffer) | |
6151 | { | |
6152 | struct Scsi_Host *shost; | |
6153 | struct pqi_ctrl_info *ctrl_info; | |
6154 | ||
6155 | shost = class_to_shost(dev); | |
6156 | ctrl_info = shost_to_hba(shost); | |
6157 | ||
6158 | return snprintf(buffer, PAGE_SIZE, "%s\n", ctrl_info->serial_number); | |
6159 | } | |
6160 | ||
6161 | static ssize_t pqi_model_show(struct device *dev, | |
6162 | struct device_attribute *attr, char *buffer) | |
6163 | { | |
6164 | struct Scsi_Host *shost; | |
6165 | struct pqi_ctrl_info *ctrl_info; | |
6166 | ||
6167 | shost = class_to_shost(dev); | |
6168 | ctrl_info = shost_to_hba(shost); | |
6169 | ||
6170 | return snprintf(buffer, PAGE_SIZE, "%s\n", ctrl_info->model); | |
6171 | } | |
6172 | ||
6173 | static ssize_t pqi_vendor_show(struct device *dev, | |
6174 | struct device_attribute *attr, char *buffer) | |
6175 | { | |
6176 | struct Scsi_Host *shost; | |
6177 | struct pqi_ctrl_info *ctrl_info; | |
6178 | ||
6179 | shost = class_to_shost(dev); | |
6180 | ctrl_info = shost_to_hba(shost); | |
6181 | ||
6182 | return snprintf(buffer, PAGE_SIZE, "%s\n", ctrl_info->vendor); | |
6c223761 KB |
6183 | } |
6184 | ||
6185 | static ssize_t pqi_host_rescan_store(struct device *dev, | |
6186 | struct device_attribute *attr, const char *buffer, size_t count) | |
6187 | { | |
6188 | struct Scsi_Host *shost = class_to_shost(dev); | |
6189 | ||
6190 | pqi_scan_start(shost); | |
6191 | ||
6192 | return count; | |
6193 | } | |
6194 | ||
3c50976f KB |
6195 | static ssize_t pqi_lockup_action_show(struct device *dev, |
6196 | struct device_attribute *attr, char *buffer) | |
6197 | { | |
6198 | int count = 0; | |
6199 | unsigned int i; | |
6200 | ||
6201 | for (i = 0; i < ARRAY_SIZE(pqi_lockup_actions); i++) { | |
6202 | if (pqi_lockup_actions[i].action == pqi_lockup_action) | |
181aea89 | 6203 | count += scnprintf(buffer + count, PAGE_SIZE - count, |
3c50976f KB |
6204 | "[%s] ", pqi_lockup_actions[i].name); |
6205 | else | |
181aea89 | 6206 | count += scnprintf(buffer + count, PAGE_SIZE - count, |
3c50976f KB |
6207 | "%s ", pqi_lockup_actions[i].name); |
6208 | } | |
6209 | ||
181aea89 | 6210 | count += scnprintf(buffer + count, PAGE_SIZE - count, "\n"); |
3c50976f KB |
6211 | |
6212 | return count; | |
6213 | } | |
6214 | ||
6215 | static ssize_t pqi_lockup_action_store(struct device *dev, | |
6216 | struct device_attribute *attr, const char *buffer, size_t count) | |
6217 | { | |
6218 | unsigned int i; | |
6219 | char *action_name; | |
6220 | char action_name_buffer[32]; | |
6221 | ||
6222 | strlcpy(action_name_buffer, buffer, sizeof(action_name_buffer)); | |
6223 | action_name = strstrip(action_name_buffer); | |
6224 | ||
6225 | for (i = 0; i < ARRAY_SIZE(pqi_lockup_actions); i++) { | |
6226 | if (strcmp(action_name, pqi_lockup_actions[i].name) == 0) { | |
6227 | pqi_lockup_action = pqi_lockup_actions[i].action; | |
6228 | return count; | |
6229 | } | |
6230 | } | |
6231 | ||
6232 | return -EINVAL; | |
6233 | } | |
6234 | ||
6d90615f MB |
6235 | static DEVICE_ATTR(driver_version, 0444, pqi_driver_version_show, NULL); |
6236 | static DEVICE_ATTR(firmware_version, 0444, pqi_firmware_version_show, NULL); | |
6237 | static DEVICE_ATTR(model, 0444, pqi_model_show, NULL); | |
6238 | static DEVICE_ATTR(serial_number, 0444, pqi_serial_number_show, NULL); | |
6239 | static DEVICE_ATTR(vendor, 0444, pqi_vendor_show, NULL); | |
cbe0c7b1 | 6240 | static DEVICE_ATTR(rescan, 0200, NULL, pqi_host_rescan_store); |
3c50976f KB |
6241 | static DEVICE_ATTR(lockup_action, 0644, |
6242 | pqi_lockup_action_show, pqi_lockup_action_store); | |
6c223761 KB |
6243 | |
6244 | static struct device_attribute *pqi_shost_attrs[] = { | |
6d90615f MB |
6245 | &dev_attr_driver_version, |
6246 | &dev_attr_firmware_version, | |
6247 | &dev_attr_model, | |
6248 | &dev_attr_serial_number, | |
6249 | &dev_attr_vendor, | |
6c223761 | 6250 | &dev_attr_rescan, |
3c50976f | 6251 | &dev_attr_lockup_action, |
6c223761 KB |
6252 | NULL |
6253 | }; | |
6254 | ||
cd128244 DC |
6255 | static ssize_t pqi_unique_id_show(struct device *dev, |
6256 | struct device_attribute *attr, char *buffer) | |
6257 | { | |
6258 | struct pqi_ctrl_info *ctrl_info; | |
6259 | struct scsi_device *sdev; | |
6260 | struct pqi_scsi_dev *device; | |
6261 | unsigned long flags; | |
5b083b30 | 6262 | u8 unique_id[16]; |
cd128244 DC |
6263 | |
6264 | sdev = to_scsi_device(dev); | |
6265 | ctrl_info = shost_to_hba(sdev->host); | |
6266 | ||
6267 | spin_lock_irqsave(&ctrl_info->scsi_device_list_lock, flags); | |
6268 | ||
6269 | device = sdev->hostdata; | |
6270 | if (!device) { | |
6271 | spin_unlock_irqrestore(&ctrl_info->scsi_device_list_lock, | |
6272 | flags); | |
6273 | return -ENODEV; | |
6274 | } | |
5b083b30 KB |
6275 | |
6276 | if (device->is_physical_device) { | |
6277 | memset(unique_id, 0, 8); | |
6278 | memcpy(unique_id + 8, &device->wwid, sizeof(device->wwid)); | |
6279 | } else { | |
6280 | memcpy(unique_id, device->volume_id, sizeof(device->volume_id)); | |
6281 | } | |
cd128244 DC |
6282 | |
6283 | spin_unlock_irqrestore(&ctrl_info->scsi_device_list_lock, flags); | |
6284 | ||
5995b236 MB |
6285 | return snprintf(buffer, PAGE_SIZE, |
6286 | "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n", | |
5b083b30 KB |
6287 | unique_id[0], unique_id[1], unique_id[2], unique_id[3], |
6288 | unique_id[4], unique_id[5], unique_id[6], unique_id[7], | |
6289 | unique_id[8], unique_id[9], unique_id[10], unique_id[11], | |
6290 | unique_id[12], unique_id[13], unique_id[14], unique_id[15]); | |
cd128244 DC |
6291 | } |
6292 | ||
6293 | static ssize_t pqi_lunid_show(struct device *dev, | |
6294 | struct device_attribute *attr, char *buffer) | |
6295 | { | |
6296 | struct pqi_ctrl_info *ctrl_info; | |
6297 | struct scsi_device *sdev; | |
6298 | struct pqi_scsi_dev *device; | |
6299 | unsigned long flags; | |
6300 | u8 lunid[8]; | |
6301 | ||
6302 | sdev = to_scsi_device(dev); | |
6303 | ctrl_info = shost_to_hba(sdev->host); | |
6304 | ||
6305 | spin_lock_irqsave(&ctrl_info->scsi_device_list_lock, flags); | |
6306 | ||
6307 | device = sdev->hostdata; | |
6308 | if (!device) { | |
6309 | spin_unlock_irqrestore(&ctrl_info->scsi_device_list_lock, | |
6310 | flags); | |
6311 | return -ENODEV; | |
6312 | } | |
694c5d5b | 6313 | |
cd128244 DC |
6314 | memcpy(lunid, device->scsi3addr, sizeof(lunid)); |
6315 | ||
6316 | spin_unlock_irqrestore(&ctrl_info->scsi_device_list_lock, flags); | |
6317 | ||
6318 | return snprintf(buffer, PAGE_SIZE, "0x%8phN\n", lunid); | |
6319 | } | |
6320 | ||
694c5d5b KB |
6321 | #define MAX_PATHS 8 |
6322 | ||
cd128244 DC |
6323 | static ssize_t pqi_path_info_show(struct device *dev, |
6324 | struct device_attribute *attr, char *buf) | |
6325 | { | |
6326 | struct pqi_ctrl_info *ctrl_info; | |
6327 | struct scsi_device *sdev; | |
6328 | struct pqi_scsi_dev *device; | |
6329 | unsigned long flags; | |
6330 | int i; | |
6331 | int output_len = 0; | |
6332 | u8 box; | |
6333 | u8 bay; | |
694c5d5b | 6334 | u8 path_map_index; |
cd128244 | 6335 | char *active; |
694c5d5b | 6336 | u8 phys_connector[2]; |
cd128244 DC |
6337 | |
6338 | sdev = to_scsi_device(dev); | |
6339 | ctrl_info = shost_to_hba(sdev->host); | |
6340 | ||
6341 | spin_lock_irqsave(&ctrl_info->scsi_device_list_lock, flags); | |
6342 | ||
6343 | device = sdev->hostdata; | |
6344 | if (!device) { | |
6345 | spin_unlock_irqrestore(&ctrl_info->scsi_device_list_lock, | |
6346 | flags); | |
6347 | return -ENODEV; | |
6348 | } | |
6349 | ||
6350 | bay = device->bay; | |
6351 | for (i = 0; i < MAX_PATHS; i++) { | |
694c5d5b | 6352 | path_map_index = 1 << i; |
cd128244 DC |
6353 | if (i == device->active_path_index) |
6354 | active = "Active"; | |
6355 | else if (device->path_map & path_map_index) | |
6356 | active = "Inactive"; | |
6357 | else | |
6358 | continue; | |
6359 | ||
6360 | output_len += scnprintf(buf + output_len, | |
6361 | PAGE_SIZE - output_len, | |
6362 | "[%d:%d:%d:%d] %20.20s ", | |
6363 | ctrl_info->scsi_host->host_no, | |
6364 | device->bus, device->target, | |
6365 | device->lun, | |
6366 | scsi_device_type(device->devtype)); | |
6367 | ||
6368 | if (device->devtype == TYPE_RAID || | |
6369 | pqi_is_logical_device(device)) | |
6370 | goto end_buffer; | |
6371 | ||
6372 | memcpy(&phys_connector, &device->phys_connector[i], | |
6373 | sizeof(phys_connector)); | |
6374 | if (phys_connector[0] < '0') | |
6375 | phys_connector[0] = '0'; | |
6376 | if (phys_connector[1] < '0') | |
6377 | phys_connector[1] = '0'; | |
6378 | ||
6379 | output_len += scnprintf(buf + output_len, | |
6380 | PAGE_SIZE - output_len, | |
6381 | "PORT: %.2s ", phys_connector); | |
6382 | ||
6383 | box = device->box[i]; | |
6384 | if (box != 0 && box != 0xFF) | |
6385 | output_len += scnprintf(buf + output_len, | |
6386 | PAGE_SIZE - output_len, | |
6387 | "BOX: %hhu ", box); | |
6388 | ||
6389 | if ((device->devtype == TYPE_DISK || | |
6390 | device->devtype == TYPE_ZBC) && | |
6391 | pqi_expose_device(device)) | |
6392 | output_len += scnprintf(buf + output_len, | |
6393 | PAGE_SIZE - output_len, | |
6394 | "BAY: %hhu ", bay); | |
6395 | ||
6396 | end_buffer: | |
6397 | output_len += scnprintf(buf + output_len, | |
6398 | PAGE_SIZE - output_len, | |
6399 | "%s\n", active); | |
6400 | } | |
6401 | ||
6402 | spin_unlock_irqrestore(&ctrl_info->scsi_device_list_lock, flags); | |
694c5d5b | 6403 | |
cd128244 DC |
6404 | return output_len; |
6405 | } | |
6406 | ||
6c223761 KB |
6407 | static ssize_t pqi_sas_address_show(struct device *dev, |
6408 | struct device_attribute *attr, char *buffer) | |
6409 | { | |
6410 | struct pqi_ctrl_info *ctrl_info; | |
6411 | struct scsi_device *sdev; | |
6412 | struct pqi_scsi_dev *device; | |
6413 | unsigned long flags; | |
6414 | u64 sas_address; | |
6415 | ||
6416 | sdev = to_scsi_device(dev); | |
6417 | ctrl_info = shost_to_hba(sdev->host); | |
6418 | ||
6419 | spin_lock_irqsave(&ctrl_info->scsi_device_list_lock, flags); | |
6420 | ||
6421 | device = sdev->hostdata; | |
6422 | if (pqi_is_logical_device(device)) { | |
6423 | spin_unlock_irqrestore(&ctrl_info->scsi_device_list_lock, | |
6424 | flags); | |
6425 | return -ENODEV; | |
6426 | } | |
694c5d5b | 6427 | |
6c223761 KB |
6428 | sas_address = device->sas_address; |
6429 | ||
6430 | spin_unlock_irqrestore(&ctrl_info->scsi_device_list_lock, flags); | |
6431 | ||
6432 | return snprintf(buffer, PAGE_SIZE, "0x%016llx\n", sas_address); | |
6433 | } | |
6434 | ||
6435 | static ssize_t pqi_ssd_smart_path_enabled_show(struct device *dev, | |
6436 | struct device_attribute *attr, char *buffer) | |
6437 | { | |
6438 | struct pqi_ctrl_info *ctrl_info; | |
6439 | struct scsi_device *sdev; | |
6440 | struct pqi_scsi_dev *device; | |
6441 | unsigned long flags; | |
6442 | ||
6443 | sdev = to_scsi_device(dev); | |
6444 | ctrl_info = shost_to_hba(sdev->host); | |
6445 | ||
6446 | spin_lock_irqsave(&ctrl_info->scsi_device_list_lock, flags); | |
6447 | ||
6448 | device = sdev->hostdata; | |
588a63fe | 6449 | buffer[0] = device->raid_bypass_enabled ? '1' : '0'; |
6c223761 KB |
6450 | buffer[1] = '\n'; |
6451 | buffer[2] = '\0'; | |
6452 | ||
6453 | spin_unlock_irqrestore(&ctrl_info->scsi_device_list_lock, flags); | |
6454 | ||
6455 | return 2; | |
6456 | } | |
6457 | ||
a9f93392 KB |
6458 | static ssize_t pqi_raid_level_show(struct device *dev, |
6459 | struct device_attribute *attr, char *buffer) | |
6460 | { | |
6461 | struct pqi_ctrl_info *ctrl_info; | |
6462 | struct scsi_device *sdev; | |
6463 | struct pqi_scsi_dev *device; | |
6464 | unsigned long flags; | |
6465 | char *raid_level; | |
6466 | ||
6467 | sdev = to_scsi_device(dev); | |
6468 | ctrl_info = shost_to_hba(sdev->host); | |
6469 | ||
6470 | spin_lock_irqsave(&ctrl_info->scsi_device_list_lock, flags); | |
6471 | ||
6472 | device = sdev->hostdata; | |
6473 | ||
6474 | if (pqi_is_logical_device(device)) | |
6475 | raid_level = pqi_raid_level_to_string(device->raid_level); | |
6476 | else | |
6477 | raid_level = "N/A"; | |
6478 | ||
6479 | spin_unlock_irqrestore(&ctrl_info->scsi_device_list_lock, flags); | |
6480 | ||
6481 | return snprintf(buffer, PAGE_SIZE, "%s\n", raid_level); | |
6482 | } | |
6483 | ||
cd128244 DC |
6484 | static DEVICE_ATTR(lunid, 0444, pqi_lunid_show, NULL); |
6485 | static DEVICE_ATTR(unique_id, 0444, pqi_unique_id_show, NULL); | |
6486 | static DEVICE_ATTR(path_info, 0444, pqi_path_info_show, NULL); | |
cbe0c7b1 KB |
6487 | static DEVICE_ATTR(sas_address, 0444, pqi_sas_address_show, NULL); |
6488 | static DEVICE_ATTR(ssd_smart_path_enabled, 0444, | |
6c223761 | 6489 | pqi_ssd_smart_path_enabled_show, NULL); |
a9f93392 | 6490 | static DEVICE_ATTR(raid_level, 0444, pqi_raid_level_show, NULL); |
6c223761 KB |
6491 | |
6492 | static struct device_attribute *pqi_sdev_attrs[] = { | |
cd128244 DC |
6493 | &dev_attr_lunid, |
6494 | &dev_attr_unique_id, | |
6495 | &dev_attr_path_info, | |
6c223761 KB |
6496 | &dev_attr_sas_address, |
6497 | &dev_attr_ssd_smart_path_enabled, | |
a9f93392 | 6498 | &dev_attr_raid_level, |
6c223761 KB |
6499 | NULL |
6500 | }; | |
6501 | ||
6502 | static struct scsi_host_template pqi_driver_template = { | |
6503 | .module = THIS_MODULE, | |
6504 | .name = DRIVER_NAME_SHORT, | |
6505 | .proc_name = DRIVER_NAME_SHORT, | |
6506 | .queuecommand = pqi_scsi_queue_command, | |
6507 | .scan_start = pqi_scan_start, | |
6508 | .scan_finished = pqi_scan_finished, | |
6509 | .this_id = -1, | |
6c223761 KB |
6510 | .eh_device_reset_handler = pqi_eh_device_reset_handler, |
6511 | .ioctl = pqi_ioctl, | |
6512 | .slave_alloc = pqi_slave_alloc, | |
ce143793 | 6513 | .slave_configure = pqi_slave_configure, |
52198226 | 6514 | .map_queues = pqi_map_queues, |
6c223761 KB |
6515 | .sdev_attrs = pqi_sdev_attrs, |
6516 | .shost_attrs = pqi_shost_attrs, | |
6517 | }; | |
6518 | ||
6519 | static int pqi_register_scsi(struct pqi_ctrl_info *ctrl_info) | |
6520 | { | |
6521 | int rc; | |
6522 | struct Scsi_Host *shost; | |
6523 | ||
6524 | shost = scsi_host_alloc(&pqi_driver_template, sizeof(ctrl_info)); | |
6525 | if (!shost) { | |
6526 | dev_err(&ctrl_info->pci_dev->dev, | |
6527 | "scsi_host_alloc failed for controller %u\n", | |
6528 | ctrl_info->ctrl_id); | |
6529 | return -ENOMEM; | |
6530 | } | |
6531 | ||
6532 | shost->io_port = 0; | |
6533 | shost->n_io_port = 0; | |
6534 | shost->this_id = -1; | |
6535 | shost->max_channel = PQI_MAX_BUS; | |
6536 | shost->max_cmd_len = MAX_COMMAND_SIZE; | |
6537 | shost->max_lun = ~0; | |
6538 | shost->max_id = ~0; | |
6539 | shost->max_sectors = ctrl_info->max_sectors; | |
6540 | shost->can_queue = ctrl_info->scsi_ml_can_queue; | |
6541 | shost->cmd_per_lun = shost->can_queue; | |
6542 | shost->sg_tablesize = ctrl_info->sg_tablesize; | |
6543 | shost->transportt = pqi_sas_transport_template; | |
52198226 | 6544 | shost->irq = pci_irq_vector(ctrl_info->pci_dev, 0); |
6c223761 KB |
6545 | shost->unique_id = shost->irq; |
6546 | shost->nr_hw_queues = ctrl_info->num_queue_groups; | |
6547 | shost->hostdata[0] = (unsigned long)ctrl_info; | |
6548 | ||
6549 | rc = scsi_add_host(shost, &ctrl_info->pci_dev->dev); | |
6550 | if (rc) { | |
6551 | dev_err(&ctrl_info->pci_dev->dev, | |
6552 | "scsi_add_host failed for controller %u\n", | |
6553 | ctrl_info->ctrl_id); | |
6554 | goto free_host; | |
6555 | } | |
6556 | ||
6557 | rc = pqi_add_sas_host(shost, ctrl_info); | |
6558 | if (rc) { | |
6559 | dev_err(&ctrl_info->pci_dev->dev, | |
6560 | "add SAS host failed for controller %u\n", | |
6561 | ctrl_info->ctrl_id); | |
6562 | goto remove_host; | |
6563 | } | |
6564 | ||
6565 | ctrl_info->scsi_host = shost; | |
6566 | ||
6567 | return 0; | |
6568 | ||
6569 | remove_host: | |
6570 | scsi_remove_host(shost); | |
6571 | free_host: | |
6572 | scsi_host_put(shost); | |
6573 | ||
6574 | return rc; | |
6575 | } | |
6576 | ||
6577 | static void pqi_unregister_scsi(struct pqi_ctrl_info *ctrl_info) | |
6578 | { | |
6579 | struct Scsi_Host *shost; | |
6580 | ||
6581 | pqi_delete_sas_host(ctrl_info); | |
6582 | ||
6583 | shost = ctrl_info->scsi_host; | |
6584 | if (!shost) | |
6585 | return; | |
6586 | ||
6587 | scsi_remove_host(shost); | |
6588 | scsi_host_put(shost); | |
6589 | } | |
6590 | ||
336b6819 KB |
6591 | static int pqi_wait_for_pqi_reset_completion(struct pqi_ctrl_info *ctrl_info) |
6592 | { | |
6593 | int rc = 0; | |
6594 | struct pqi_device_registers __iomem *pqi_registers; | |
6595 | unsigned long timeout; | |
6596 | unsigned int timeout_msecs; | |
6597 | union pqi_reset_register reset_reg; | |
6c223761 | 6598 | |
336b6819 KB |
6599 | pqi_registers = ctrl_info->pqi_registers; |
6600 | timeout_msecs = readw(&pqi_registers->max_reset_timeout) * 100; | |
6601 | timeout = msecs_to_jiffies(timeout_msecs) + jiffies; | |
6602 | ||
6603 | while (1) { | |
6604 | msleep(PQI_RESET_POLL_INTERVAL_MSECS); | |
6605 | reset_reg.all_bits = readl(&pqi_registers->device_reset); | |
6606 | if (reset_reg.bits.reset_action == PQI_RESET_ACTION_COMPLETED) | |
6607 | break; | |
6608 | pqi_check_ctrl_health(ctrl_info); | |
6609 | if (pqi_ctrl_offline(ctrl_info)) { | |
6610 | rc = -ENXIO; | |
6611 | break; | |
6612 | } | |
6613 | if (time_after(jiffies, timeout)) { | |
6614 | rc = -ETIMEDOUT; | |
6615 | break; | |
6616 | } | |
6617 | } | |
6618 | ||
6619 | return rc; | |
6620 | } | |
6c223761 KB |
6621 | |
6622 | static int pqi_reset(struct pqi_ctrl_info *ctrl_info) | |
6623 | { | |
6624 | int rc; | |
336b6819 KB |
6625 | union pqi_reset_register reset_reg; |
6626 | ||
6627 | if (ctrl_info->pqi_reset_quiesce_supported) { | |
6628 | rc = sis_pqi_reset_quiesce(ctrl_info); | |
6629 | if (rc) { | |
6630 | dev_err(&ctrl_info->pci_dev->dev, | |
6631 | "PQI reset failed during quiesce with error %d\n", | |
6632 | rc); | |
6633 | return rc; | |
6634 | } | |
6635 | } | |
6c223761 | 6636 | |
336b6819 KB |
6637 | reset_reg.all_bits = 0; |
6638 | reset_reg.bits.reset_type = PQI_RESET_TYPE_HARD_RESET; | |
6639 | reset_reg.bits.reset_action = PQI_RESET_ACTION_RESET; | |
6c223761 | 6640 | |
336b6819 | 6641 | writel(reset_reg.all_bits, &ctrl_info->pqi_registers->device_reset); |
6c223761 | 6642 | |
336b6819 | 6643 | rc = pqi_wait_for_pqi_reset_completion(ctrl_info); |
6c223761 KB |
6644 | if (rc) |
6645 | dev_err(&ctrl_info->pci_dev->dev, | |
336b6819 | 6646 | "PQI reset failed with error %d\n", rc); |
6c223761 KB |
6647 | |
6648 | return rc; | |
6649 | } | |
6650 | ||
6d90615f MB |
6651 | static int pqi_get_ctrl_serial_number(struct pqi_ctrl_info *ctrl_info) |
6652 | { | |
6653 | int rc; | |
6654 | struct bmic_sense_subsystem_info *sense_info; | |
6655 | ||
6656 | sense_info = kzalloc(sizeof(*sense_info), GFP_KERNEL); | |
6657 | if (!sense_info) | |
6658 | return -ENOMEM; | |
6659 | ||
6660 | rc = pqi_sense_subsystem_info(ctrl_info, sense_info); | |
6661 | if (rc) | |
6662 | goto out; | |
6663 | ||
6664 | memcpy(ctrl_info->serial_number, sense_info->ctrl_serial_number, | |
6665 | sizeof(sense_info->ctrl_serial_number)); | |
6666 | ctrl_info->serial_number[sizeof(sense_info->ctrl_serial_number)] = '\0'; | |
6667 | ||
6668 | out: | |
6669 | kfree(sense_info); | |
6670 | ||
6671 | return rc; | |
6672 | } | |
6673 | ||
6674 | static int pqi_get_ctrl_product_details(struct pqi_ctrl_info *ctrl_info) | |
6c223761 KB |
6675 | { |
6676 | int rc; | |
6677 | struct bmic_identify_controller *identify; | |
6678 | ||
6679 | identify = kmalloc(sizeof(*identify), GFP_KERNEL); | |
6680 | if (!identify) | |
6681 | return -ENOMEM; | |
6682 | ||
6683 | rc = pqi_identify_controller(ctrl_info, identify); | |
6684 | if (rc) | |
6685 | goto out; | |
6686 | ||
6687 | memcpy(ctrl_info->firmware_version, identify->firmware_version, | |
6688 | sizeof(identify->firmware_version)); | |
6689 | ctrl_info->firmware_version[sizeof(identify->firmware_version)] = '\0'; | |
6690 | snprintf(ctrl_info->firmware_version + | |
6691 | strlen(ctrl_info->firmware_version), | |
6692 | sizeof(ctrl_info->firmware_version), | |
6693 | "-%u", get_unaligned_le16(&identify->firmware_build_number)); | |
6694 | ||
6d90615f MB |
6695 | memcpy(ctrl_info->model, identify->product_id, |
6696 | sizeof(identify->product_id)); | |
6697 | ctrl_info->model[sizeof(identify->product_id)] = '\0'; | |
6698 | ||
6699 | memcpy(ctrl_info->vendor, identify->vendor_id, | |
6700 | sizeof(identify->vendor_id)); | |
6701 | ctrl_info->vendor[sizeof(identify->vendor_id)] = '\0'; | |
6702 | ||
6c223761 KB |
6703 | out: |
6704 | kfree(identify); | |
6705 | ||
6706 | return rc; | |
6707 | } | |
6708 | ||
b212c251 KB |
6709 | struct pqi_config_table_section_info { |
6710 | struct pqi_ctrl_info *ctrl_info; | |
6711 | void *section; | |
6712 | u32 section_offset; | |
6713 | void __iomem *section_iomem_addr; | |
6714 | }; | |
6715 | ||
6716 | static inline bool pqi_is_firmware_feature_supported( | |
6717 | struct pqi_config_table_firmware_features *firmware_features, | |
6718 | unsigned int bit_position) | |
98f87667 | 6719 | { |
b212c251 | 6720 | unsigned int byte_index; |
98f87667 | 6721 | |
b212c251 | 6722 | byte_index = bit_position / BITS_PER_BYTE; |
98f87667 | 6723 | |
b212c251 KB |
6724 | if (byte_index >= le16_to_cpu(firmware_features->num_elements)) |
6725 | return false; | |
98f87667 | 6726 | |
b212c251 KB |
6727 | return firmware_features->features_supported[byte_index] & |
6728 | (1 << (bit_position % BITS_PER_BYTE)) ? true : false; | |
6729 | } | |
6730 | ||
6731 | static inline bool pqi_is_firmware_feature_enabled( | |
6732 | struct pqi_config_table_firmware_features *firmware_features, | |
6733 | void __iomem *firmware_features_iomem_addr, | |
6734 | unsigned int bit_position) | |
6735 | { | |
6736 | unsigned int byte_index; | |
6737 | u8 __iomem *features_enabled_iomem_addr; | |
6738 | ||
6739 | byte_index = (bit_position / BITS_PER_BYTE) + | |
6740 | (le16_to_cpu(firmware_features->num_elements) * 2); | |
6741 | ||
6742 | features_enabled_iomem_addr = firmware_features_iomem_addr + | |
6743 | offsetof(struct pqi_config_table_firmware_features, | |
6744 | features_supported) + byte_index; | |
6745 | ||
6746 | return *((__force u8 *)features_enabled_iomem_addr) & | |
6747 | (1 << (bit_position % BITS_PER_BYTE)) ? true : false; | |
6748 | } | |
6749 | ||
6750 | static inline void pqi_request_firmware_feature( | |
6751 | struct pqi_config_table_firmware_features *firmware_features, | |
6752 | unsigned int bit_position) | |
6753 | { | |
6754 | unsigned int byte_index; | |
6755 | ||
6756 | byte_index = (bit_position / BITS_PER_BYTE) + | |
6757 | le16_to_cpu(firmware_features->num_elements); | |
6758 | ||
6759 | firmware_features->features_supported[byte_index] |= | |
6760 | (1 << (bit_position % BITS_PER_BYTE)); | |
6761 | } | |
6762 | ||
6763 | static int pqi_config_table_update(struct pqi_ctrl_info *ctrl_info, | |
6764 | u16 first_section, u16 last_section) | |
6765 | { | |
6766 | struct pqi_vendor_general_request request; | |
6767 | ||
6768 | memset(&request, 0, sizeof(request)); | |
6769 | ||
6770 | request.header.iu_type = PQI_REQUEST_IU_VENDOR_GENERAL; | |
6771 | put_unaligned_le16(sizeof(request) - PQI_REQUEST_HEADER_LENGTH, | |
6772 | &request.header.iu_length); | |
6773 | put_unaligned_le16(PQI_VENDOR_GENERAL_CONFIG_TABLE_UPDATE, | |
6774 | &request.function_code); | |
6775 | put_unaligned_le16(first_section, | |
6776 | &request.data.config_table_update.first_section); | |
6777 | put_unaligned_le16(last_section, | |
6778 | &request.data.config_table_update.last_section); | |
6779 | ||
6780 | return pqi_submit_raid_request_synchronous(ctrl_info, &request.header, | |
6781 | 0, NULL, NO_TIMEOUT); | |
6782 | } | |
6783 | ||
6784 | static int pqi_enable_firmware_features(struct pqi_ctrl_info *ctrl_info, | |
6785 | struct pqi_config_table_firmware_features *firmware_features, | |
6786 | void __iomem *firmware_features_iomem_addr) | |
6787 | { | |
6788 | void *features_requested; | |
6789 | void __iomem *features_requested_iomem_addr; | |
6790 | ||
6791 | features_requested = firmware_features->features_supported + | |
6792 | le16_to_cpu(firmware_features->num_elements); | |
6793 | ||
6794 | features_requested_iomem_addr = firmware_features_iomem_addr + | |
6795 | (features_requested - (void *)firmware_features); | |
6796 | ||
6797 | memcpy_toio(features_requested_iomem_addr, features_requested, | |
6798 | le16_to_cpu(firmware_features->num_elements)); | |
6799 | ||
6800 | return pqi_config_table_update(ctrl_info, | |
6801 | PQI_CONFIG_TABLE_SECTION_FIRMWARE_FEATURES, | |
6802 | PQI_CONFIG_TABLE_SECTION_FIRMWARE_FEATURES); | |
6803 | } | |
6804 | ||
6805 | struct pqi_firmware_feature { | |
6806 | char *feature_name; | |
6807 | unsigned int feature_bit; | |
6808 | bool supported; | |
6809 | bool enabled; | |
6810 | void (*feature_status)(struct pqi_ctrl_info *ctrl_info, | |
6811 | struct pqi_firmware_feature *firmware_feature); | |
6812 | }; | |
6813 | ||
6814 | static void pqi_firmware_feature_status(struct pqi_ctrl_info *ctrl_info, | |
6815 | struct pqi_firmware_feature *firmware_feature) | |
6816 | { | |
6817 | if (!firmware_feature->supported) { | |
6818 | dev_info(&ctrl_info->pci_dev->dev, "%s not supported by controller\n", | |
6819 | firmware_feature->feature_name); | |
6820 | return; | |
6821 | } | |
6822 | ||
6823 | if (firmware_feature->enabled) { | |
6824 | dev_info(&ctrl_info->pci_dev->dev, | |
6825 | "%s enabled\n", firmware_feature->feature_name); | |
6826 | return; | |
6827 | } | |
6828 | ||
6829 | dev_err(&ctrl_info->pci_dev->dev, "failed to enable %s\n", | |
6830 | firmware_feature->feature_name); | |
6831 | } | |
6832 | ||
21432010 | 6833 | static void pqi_ctrl_update_feature_flags(struct pqi_ctrl_info *ctrl_info, |
6834 | struct pqi_firmware_feature *firmware_feature) | |
6835 | { | |
6836 | switch (firmware_feature->feature_bit) { | |
6837 | case PQI_FIRMWARE_FEATURE_SOFT_RESET_HANDSHAKE: | |
6838 | ctrl_info->soft_reset_handshake_supported = | |
6839 | firmware_feature->enabled; | |
6840 | break; | |
6841 | case PQI_FIRMWARE_FEATURE_RAID_IU_TIMEOUT: | |
6842 | ctrl_info->raid_iu_timeout_supported = | |
6843 | firmware_feature->enabled; | |
6844 | break; | |
c2922f17 MB |
6845 | case PQI_FIRMWARE_FEATURE_TMF_IU_TIMEOUT: |
6846 | ctrl_info->tmf_iu_timeout_supported = | |
6847 | firmware_feature->enabled; | |
6848 | break; | |
21432010 | 6849 | } |
6850 | ||
6851 | pqi_firmware_feature_status(ctrl_info, firmware_feature); | |
6852 | } | |
6853 | ||
b212c251 KB |
6854 | static inline void pqi_firmware_feature_update(struct pqi_ctrl_info *ctrl_info, |
6855 | struct pqi_firmware_feature *firmware_feature) | |
6856 | { | |
6857 | if (firmware_feature->feature_status) | |
6858 | firmware_feature->feature_status(ctrl_info, firmware_feature); | |
6859 | } | |
6860 | ||
6861 | static DEFINE_MUTEX(pqi_firmware_features_mutex); | |
6862 | ||
6863 | static struct pqi_firmware_feature pqi_firmware_features[] = { | |
6864 | { | |
6865 | .feature_name = "Online Firmware Activation", | |
6866 | .feature_bit = PQI_FIRMWARE_FEATURE_OFA, | |
6867 | .feature_status = pqi_firmware_feature_status, | |
6868 | }, | |
6869 | { | |
6870 | .feature_name = "Serial Management Protocol", | |
6871 | .feature_bit = PQI_FIRMWARE_FEATURE_SMP, | |
6872 | .feature_status = pqi_firmware_feature_status, | |
6873 | }, | |
4fd22c13 MR |
6874 | { |
6875 | .feature_name = "New Soft Reset Handshake", | |
6876 | .feature_bit = PQI_FIRMWARE_FEATURE_SOFT_RESET_HANDSHAKE, | |
21432010 | 6877 | .feature_status = pqi_ctrl_update_feature_flags, |
6878 | }, | |
6879 | { | |
6880 | .feature_name = "RAID IU Timeout", | |
6881 | .feature_bit = PQI_FIRMWARE_FEATURE_RAID_IU_TIMEOUT, | |
6882 | .feature_status = pqi_ctrl_update_feature_flags, | |
4fd22c13 | 6883 | }, |
c2922f17 MB |
6884 | { |
6885 | .feature_name = "TMF IU Timeout", | |
6886 | .feature_bit = PQI_FIRMWARE_FEATURE_TMF_IU_TIMEOUT, | |
6887 | .feature_status = pqi_ctrl_update_feature_flags, | |
6888 | }, | |
b212c251 KB |
6889 | }; |
6890 | ||
6891 | static void pqi_process_firmware_features( | |
6892 | struct pqi_config_table_section_info *section_info) | |
6893 | { | |
6894 | int rc; | |
6895 | struct pqi_ctrl_info *ctrl_info; | |
6896 | struct pqi_config_table_firmware_features *firmware_features; | |
6897 | void __iomem *firmware_features_iomem_addr; | |
6898 | unsigned int i; | |
6899 | unsigned int num_features_supported; | |
6900 | ||
6901 | ctrl_info = section_info->ctrl_info; | |
6902 | firmware_features = section_info->section; | |
6903 | firmware_features_iomem_addr = section_info->section_iomem_addr; | |
6904 | ||
6905 | for (i = 0, num_features_supported = 0; | |
6906 | i < ARRAY_SIZE(pqi_firmware_features); i++) { | |
6907 | if (pqi_is_firmware_feature_supported(firmware_features, | |
6908 | pqi_firmware_features[i].feature_bit)) { | |
6909 | pqi_firmware_features[i].supported = true; | |
6910 | num_features_supported++; | |
6911 | } else { | |
6912 | pqi_firmware_feature_update(ctrl_info, | |
6913 | &pqi_firmware_features[i]); | |
6914 | } | |
6915 | } | |
6916 | ||
6917 | if (num_features_supported == 0) | |
6918 | return; | |
6919 | ||
6920 | for (i = 0; i < ARRAY_SIZE(pqi_firmware_features); i++) { | |
6921 | if (!pqi_firmware_features[i].supported) | |
6922 | continue; | |
6923 | pqi_request_firmware_feature(firmware_features, | |
6924 | pqi_firmware_features[i].feature_bit); | |
6925 | } | |
6926 | ||
6927 | rc = pqi_enable_firmware_features(ctrl_info, firmware_features, | |
6928 | firmware_features_iomem_addr); | |
6929 | if (rc) { | |
6930 | dev_err(&ctrl_info->pci_dev->dev, | |
6931 | "failed to enable firmware features in PQI configuration table\n"); | |
6932 | for (i = 0; i < ARRAY_SIZE(pqi_firmware_features); i++) { | |
6933 | if (!pqi_firmware_features[i].supported) | |
6934 | continue; | |
6935 | pqi_firmware_feature_update(ctrl_info, | |
6936 | &pqi_firmware_features[i]); | |
6937 | } | |
6938 | return; | |
6939 | } | |
6940 | ||
6941 | for (i = 0; i < ARRAY_SIZE(pqi_firmware_features); i++) { | |
6942 | if (!pqi_firmware_features[i].supported) | |
6943 | continue; | |
6944 | if (pqi_is_firmware_feature_enabled(firmware_features, | |
6945 | firmware_features_iomem_addr, | |
4fd22c13 | 6946 | pqi_firmware_features[i].feature_bit)) { |
b212c251 | 6947 | pqi_firmware_features[i].enabled = true; |
4fd22c13 | 6948 | } |
b212c251 KB |
6949 | pqi_firmware_feature_update(ctrl_info, |
6950 | &pqi_firmware_features[i]); | |
6951 | } | |
6952 | } | |
6953 | ||
6954 | static void pqi_init_firmware_features(void) | |
6955 | { | |
6956 | unsigned int i; | |
6957 | ||
6958 | for (i = 0; i < ARRAY_SIZE(pqi_firmware_features); i++) { | |
6959 | pqi_firmware_features[i].supported = false; | |
6960 | pqi_firmware_features[i].enabled = false; | |
6961 | } | |
6962 | } | |
6963 | ||
6964 | static void pqi_process_firmware_features_section( | |
6965 | struct pqi_config_table_section_info *section_info) | |
6966 | { | |
6967 | mutex_lock(&pqi_firmware_features_mutex); | |
6968 | pqi_init_firmware_features(); | |
6969 | pqi_process_firmware_features(section_info); | |
6970 | mutex_unlock(&pqi_firmware_features_mutex); | |
6971 | } | |
6972 | ||
98f87667 KB |
6973 | static int pqi_process_config_table(struct pqi_ctrl_info *ctrl_info) |
6974 | { | |
6975 | u32 table_length; | |
6976 | u32 section_offset; | |
6977 | void __iomem *table_iomem_addr; | |
6978 | struct pqi_config_table *config_table; | |
6979 | struct pqi_config_table_section_header *section; | |
b212c251 | 6980 | struct pqi_config_table_section_info section_info; |
98f87667 KB |
6981 | |
6982 | table_length = ctrl_info->config_table_length; | |
b212c251 KB |
6983 | if (table_length == 0) |
6984 | return 0; | |
98f87667 KB |
6985 | |
6986 | config_table = kmalloc(table_length, GFP_KERNEL); | |
6987 | if (!config_table) { | |
6988 | dev_err(&ctrl_info->pci_dev->dev, | |
d87d5474 | 6989 | "failed to allocate memory for PQI configuration table\n"); |
98f87667 KB |
6990 | return -ENOMEM; |
6991 | } | |
6992 | ||
6993 | /* | |
6994 | * Copy the config table contents from I/O memory space into the | |
6995 | * temporary buffer. | |
6996 | */ | |
6997 | table_iomem_addr = ctrl_info->iomem_base + | |
6998 | ctrl_info->config_table_offset; | |
6999 | memcpy_fromio(config_table, table_iomem_addr, table_length); | |
7000 | ||
b212c251 | 7001 | section_info.ctrl_info = ctrl_info; |
98f87667 KB |
7002 | section_offset = |
7003 | get_unaligned_le32(&config_table->first_section_offset); | |
7004 | ||
7005 | while (section_offset) { | |
7006 | section = (void *)config_table + section_offset; | |
7007 | ||
b212c251 KB |
7008 | section_info.section = section; |
7009 | section_info.section_offset = section_offset; | |
7010 | section_info.section_iomem_addr = | |
7011 | table_iomem_addr + section_offset; | |
7012 | ||
98f87667 | 7013 | switch (get_unaligned_le16(§ion->section_id)) { |
b212c251 KB |
7014 | case PQI_CONFIG_TABLE_SECTION_FIRMWARE_FEATURES: |
7015 | pqi_process_firmware_features_section(§ion_info); | |
7016 | break; | |
98f87667 | 7017 | case PQI_CONFIG_TABLE_SECTION_HEARTBEAT: |
5a259e32 KB |
7018 | if (pqi_disable_heartbeat) |
7019 | dev_warn(&ctrl_info->pci_dev->dev, | |
7020 | "heartbeat disabled by module parameter\n"); | |
7021 | else | |
7022 | ctrl_info->heartbeat_counter = | |
7023 | table_iomem_addr + | |
7024 | section_offset + | |
7025 | offsetof( | |
7026 | struct pqi_config_table_heartbeat, | |
7027 | heartbeat_counter); | |
98f87667 | 7028 | break; |
4fd22c13 MR |
7029 | case PQI_CONFIG_TABLE_SECTION_SOFT_RESET: |
7030 | ctrl_info->soft_reset_status = | |
7031 | table_iomem_addr + | |
7032 | section_offset + | |
7033 | offsetof(struct pqi_config_table_soft_reset, | |
7034 | soft_reset_status); | |
7035 | break; | |
98f87667 KB |
7036 | } |
7037 | ||
7038 | section_offset = | |
7039 | get_unaligned_le16(§ion->next_section_offset); | |
7040 | } | |
7041 | ||
7042 | kfree(config_table); | |
7043 | ||
7044 | return 0; | |
7045 | } | |
7046 | ||
162d7753 KB |
7047 | /* Switches the controller from PQI mode back into SIS mode. */ |
7048 | ||
7049 | static int pqi_revert_to_sis_mode(struct pqi_ctrl_info *ctrl_info) | |
7050 | { | |
7051 | int rc; | |
7052 | ||
061ef06a | 7053 | pqi_change_irq_mode(ctrl_info, IRQ_MODE_NONE); |
162d7753 KB |
7054 | rc = pqi_reset(ctrl_info); |
7055 | if (rc) | |
7056 | return rc; | |
4f078e24 KB |
7057 | rc = sis_reenable_sis_mode(ctrl_info); |
7058 | if (rc) { | |
7059 | dev_err(&ctrl_info->pci_dev->dev, | |
7060 | "re-enabling SIS mode failed with error %d\n", rc); | |
7061 | return rc; | |
7062 | } | |
162d7753 KB |
7063 | pqi_save_ctrl_mode(ctrl_info, SIS_MODE); |
7064 | ||
7065 | return 0; | |
7066 | } | |
7067 | ||
7068 | /* | |
7069 | * If the controller isn't already in SIS mode, this function forces it into | |
7070 | * SIS mode. | |
7071 | */ | |
7072 | ||
7073 | static int pqi_force_sis_mode(struct pqi_ctrl_info *ctrl_info) | |
ff6abb73 KB |
7074 | { |
7075 | if (!sis_is_firmware_running(ctrl_info)) | |
7076 | return -ENXIO; | |
7077 | ||
162d7753 KB |
7078 | if (pqi_get_ctrl_mode(ctrl_info) == SIS_MODE) |
7079 | return 0; | |
7080 | ||
7081 | if (sis_is_kernel_up(ctrl_info)) { | |
7082 | pqi_save_ctrl_mode(ctrl_info, SIS_MODE); | |
7083 | return 0; | |
ff6abb73 KB |
7084 | } |
7085 | ||
162d7753 | 7086 | return pqi_revert_to_sis_mode(ctrl_info); |
ff6abb73 KB |
7087 | } |
7088 | ||
0530736e KB |
7089 | #define PQI_POST_RESET_DELAY_B4_MSGU_READY 5000 |
7090 | ||
6c223761 KB |
7091 | static int pqi_ctrl_init(struct pqi_ctrl_info *ctrl_info) |
7092 | { | |
7093 | int rc; | |
7094 | ||
0530736e KB |
7095 | if (reset_devices) { |
7096 | sis_soft_reset(ctrl_info); | |
7097 | msleep(PQI_POST_RESET_DELAY_B4_MSGU_READY); | |
7098 | } else { | |
7099 | rc = pqi_force_sis_mode(ctrl_info); | |
7100 | if (rc) | |
7101 | return rc; | |
7102 | } | |
6c223761 KB |
7103 | |
7104 | /* | |
7105 | * Wait until the controller is ready to start accepting SIS | |
7106 | * commands. | |
7107 | */ | |
7108 | rc = sis_wait_for_ctrl_ready(ctrl_info); | |
8845fdfa | 7109 | if (rc) |
6c223761 | 7110 | return rc; |
6c223761 KB |
7111 | |
7112 | /* | |
7113 | * Get the controller properties. This allows us to determine | |
7114 | * whether or not it supports PQI mode. | |
7115 | */ | |
7116 | rc = sis_get_ctrl_properties(ctrl_info); | |
7117 | if (rc) { | |
7118 | dev_err(&ctrl_info->pci_dev->dev, | |
7119 | "error obtaining controller properties\n"); | |
7120 | return rc; | |
7121 | } | |
7122 | ||
7123 | rc = sis_get_pqi_capabilities(ctrl_info); | |
7124 | if (rc) { | |
7125 | dev_err(&ctrl_info->pci_dev->dev, | |
7126 | "error obtaining controller capabilities\n"); | |
7127 | return rc; | |
7128 | } | |
7129 | ||
d727a776 KB |
7130 | if (reset_devices) { |
7131 | if (ctrl_info->max_outstanding_requests > | |
7132 | PQI_MAX_OUTSTANDING_REQUESTS_KDUMP) | |
7133 | ctrl_info->max_outstanding_requests = | |
7134 | PQI_MAX_OUTSTANDING_REQUESTS_KDUMP; | |
7135 | } else { | |
7136 | if (ctrl_info->max_outstanding_requests > | |
7137 | PQI_MAX_OUTSTANDING_REQUESTS) | |
7138 | ctrl_info->max_outstanding_requests = | |
7139 | PQI_MAX_OUTSTANDING_REQUESTS; | |
7140 | } | |
6c223761 KB |
7141 | |
7142 | pqi_calculate_io_resources(ctrl_info); | |
7143 | ||
7144 | rc = pqi_alloc_error_buffer(ctrl_info); | |
7145 | if (rc) { | |
7146 | dev_err(&ctrl_info->pci_dev->dev, | |
7147 | "failed to allocate PQI error buffer\n"); | |
7148 | return rc; | |
7149 | } | |
7150 | ||
7151 | /* | |
7152 | * If the function we are about to call succeeds, the | |
7153 | * controller will transition from legacy SIS mode | |
7154 | * into PQI mode. | |
7155 | */ | |
7156 | rc = sis_init_base_struct_addr(ctrl_info); | |
7157 | if (rc) { | |
7158 | dev_err(&ctrl_info->pci_dev->dev, | |
7159 | "error initializing PQI mode\n"); | |
7160 | return rc; | |
7161 | } | |
7162 | ||
7163 | /* Wait for the controller to complete the SIS -> PQI transition. */ | |
7164 | rc = pqi_wait_for_pqi_mode_ready(ctrl_info); | |
7165 | if (rc) { | |
7166 | dev_err(&ctrl_info->pci_dev->dev, | |
7167 | "transition to PQI mode failed\n"); | |
7168 | return rc; | |
7169 | } | |
7170 | ||
7171 | /* From here on, we are running in PQI mode. */ | |
7172 | ctrl_info->pqi_mode_enabled = true; | |
ff6abb73 | 7173 | pqi_save_ctrl_mode(ctrl_info, PQI_MODE); |
6c223761 KB |
7174 | |
7175 | rc = pqi_alloc_admin_queues(ctrl_info); | |
7176 | if (rc) { | |
7177 | dev_err(&ctrl_info->pci_dev->dev, | |
d87d5474 | 7178 | "failed to allocate admin queues\n"); |
6c223761 KB |
7179 | return rc; |
7180 | } | |
7181 | ||
7182 | rc = pqi_create_admin_queues(ctrl_info); | |
7183 | if (rc) { | |
7184 | dev_err(&ctrl_info->pci_dev->dev, | |
7185 | "error creating admin queues\n"); | |
7186 | return rc; | |
7187 | } | |
7188 | ||
7189 | rc = pqi_report_device_capability(ctrl_info); | |
7190 | if (rc) { | |
7191 | dev_err(&ctrl_info->pci_dev->dev, | |
7192 | "obtaining device capability failed\n"); | |
7193 | return rc; | |
7194 | } | |
7195 | ||
7196 | rc = pqi_validate_device_capability(ctrl_info); | |
7197 | if (rc) | |
7198 | return rc; | |
7199 | ||
7200 | pqi_calculate_queue_resources(ctrl_info); | |
7201 | ||
7202 | rc = pqi_enable_msix_interrupts(ctrl_info); | |
7203 | if (rc) | |
7204 | return rc; | |
7205 | ||
7206 | if (ctrl_info->num_msix_vectors_enabled < ctrl_info->num_queue_groups) { | |
7207 | ctrl_info->max_msix_vectors = | |
7208 | ctrl_info->num_msix_vectors_enabled; | |
7209 | pqi_calculate_queue_resources(ctrl_info); | |
7210 | } | |
7211 | ||
7212 | rc = pqi_alloc_io_resources(ctrl_info); | |
7213 | if (rc) | |
7214 | return rc; | |
7215 | ||
7216 | rc = pqi_alloc_operational_queues(ctrl_info); | |
d87d5474 KB |
7217 | if (rc) { |
7218 | dev_err(&ctrl_info->pci_dev->dev, | |
7219 | "failed to allocate operational queues\n"); | |
6c223761 | 7220 | return rc; |
d87d5474 | 7221 | } |
6c223761 KB |
7222 | |
7223 | pqi_init_operational_queues(ctrl_info); | |
7224 | ||
7225 | rc = pqi_request_irqs(ctrl_info); | |
7226 | if (rc) | |
7227 | return rc; | |
7228 | ||
6c223761 KB |
7229 | rc = pqi_create_queues(ctrl_info); |
7230 | if (rc) | |
7231 | return rc; | |
7232 | ||
061ef06a KB |
7233 | pqi_change_irq_mode(ctrl_info, IRQ_MODE_MSIX); |
7234 | ||
7235 | ctrl_info->controller_online = true; | |
b212c251 KB |
7236 | |
7237 | rc = pqi_process_config_table(ctrl_info); | |
7238 | if (rc) | |
7239 | return rc; | |
7240 | ||
061ef06a | 7241 | pqi_start_heartbeat_timer(ctrl_info); |
6c223761 | 7242 | |
6a50d6ad | 7243 | rc = pqi_enable_events(ctrl_info); |
6c223761 KB |
7244 | if (rc) { |
7245 | dev_err(&ctrl_info->pci_dev->dev, | |
6a50d6ad | 7246 | "error enabling events\n"); |
6c223761 KB |
7247 | return rc; |
7248 | } | |
7249 | ||
6c223761 KB |
7250 | /* Register with the SCSI subsystem. */ |
7251 | rc = pqi_register_scsi(ctrl_info); | |
7252 | if (rc) | |
7253 | return rc; | |
7254 | ||
6d90615f MB |
7255 | rc = pqi_get_ctrl_product_details(ctrl_info); |
7256 | if (rc) { | |
7257 | dev_err(&ctrl_info->pci_dev->dev, | |
7258 | "error obtaining product details\n"); | |
7259 | return rc; | |
7260 | } | |
7261 | ||
7262 | rc = pqi_get_ctrl_serial_number(ctrl_info); | |
6c223761 KB |
7263 | if (rc) { |
7264 | dev_err(&ctrl_info->pci_dev->dev, | |
6d90615f | 7265 | "error obtaining ctrl serial number\n"); |
6c223761 KB |
7266 | return rc; |
7267 | } | |
7268 | ||
171c2865 DC |
7269 | rc = pqi_set_diag_rescan(ctrl_info); |
7270 | if (rc) { | |
7271 | dev_err(&ctrl_info->pci_dev->dev, | |
7272 | "error enabling multi-lun rescan\n"); | |
7273 | return rc; | |
7274 | } | |
7275 | ||
6c223761 KB |
7276 | rc = pqi_write_driver_version_to_host_wellness(ctrl_info); |
7277 | if (rc) { | |
7278 | dev_err(&ctrl_info->pci_dev->dev, | |
7279 | "error updating host wellness\n"); | |
7280 | return rc; | |
7281 | } | |
7282 | ||
7283 | pqi_schedule_update_time_worker(ctrl_info); | |
7284 | ||
7285 | pqi_scan_scsi_devices(ctrl_info); | |
7286 | ||
7287 | return 0; | |
7288 | } | |
7289 | ||
061ef06a KB |
7290 | static void pqi_reinit_queues(struct pqi_ctrl_info *ctrl_info) |
7291 | { | |
7292 | unsigned int i; | |
7293 | struct pqi_admin_queues *admin_queues; | |
7294 | struct pqi_event_queue *event_queue; | |
7295 | ||
7296 | admin_queues = &ctrl_info->admin_queues; | |
7297 | admin_queues->iq_pi_copy = 0; | |
7298 | admin_queues->oq_ci_copy = 0; | |
dac12fbc | 7299 | writel(0, admin_queues->oq_pi); |
061ef06a KB |
7300 | |
7301 | for (i = 0; i < ctrl_info->num_queue_groups; i++) { | |
7302 | ctrl_info->queue_groups[i].iq_pi_copy[RAID_PATH] = 0; | |
7303 | ctrl_info->queue_groups[i].iq_pi_copy[AIO_PATH] = 0; | |
7304 | ctrl_info->queue_groups[i].oq_ci_copy = 0; | |
7305 | ||
dac12fbc KB |
7306 | writel(0, ctrl_info->queue_groups[i].iq_ci[RAID_PATH]); |
7307 | writel(0, ctrl_info->queue_groups[i].iq_ci[AIO_PATH]); | |
7308 | writel(0, ctrl_info->queue_groups[i].oq_pi); | |
061ef06a KB |
7309 | } |
7310 | ||
7311 | event_queue = &ctrl_info->event_queue; | |
dac12fbc | 7312 | writel(0, event_queue->oq_pi); |
061ef06a KB |
7313 | event_queue->oq_ci_copy = 0; |
7314 | } | |
7315 | ||
7316 | static int pqi_ctrl_init_resume(struct pqi_ctrl_info *ctrl_info) | |
7317 | { | |
7318 | int rc; | |
7319 | ||
7320 | rc = pqi_force_sis_mode(ctrl_info); | |
7321 | if (rc) | |
7322 | return rc; | |
7323 | ||
7324 | /* | |
7325 | * Wait until the controller is ready to start accepting SIS | |
7326 | * commands. | |
7327 | */ | |
7328 | rc = sis_wait_for_ctrl_ready_resume(ctrl_info); | |
7329 | if (rc) | |
7330 | return rc; | |
7331 | ||
4fd22c13 MR |
7332 | /* |
7333 | * Get the controller properties. This allows us to determine | |
7334 | * whether or not it supports PQI mode. | |
7335 | */ | |
7336 | rc = sis_get_ctrl_properties(ctrl_info); | |
7337 | if (rc) { | |
7338 | dev_err(&ctrl_info->pci_dev->dev, | |
7339 | "error obtaining controller properties\n"); | |
7340 | return rc; | |
7341 | } | |
7342 | ||
7343 | rc = sis_get_pqi_capabilities(ctrl_info); | |
7344 | if (rc) { | |
7345 | dev_err(&ctrl_info->pci_dev->dev, | |
7346 | "error obtaining controller capabilities\n"); | |
7347 | return rc; | |
7348 | } | |
7349 | ||
061ef06a KB |
7350 | /* |
7351 | * If the function we are about to call succeeds, the | |
7352 | * controller will transition from legacy SIS mode | |
7353 | * into PQI mode. | |
7354 | */ | |
7355 | rc = sis_init_base_struct_addr(ctrl_info); | |
7356 | if (rc) { | |
7357 | dev_err(&ctrl_info->pci_dev->dev, | |
7358 | "error initializing PQI mode\n"); | |
7359 | return rc; | |
7360 | } | |
7361 | ||
7362 | /* Wait for the controller to complete the SIS -> PQI transition. */ | |
7363 | rc = pqi_wait_for_pqi_mode_ready(ctrl_info); | |
7364 | if (rc) { | |
7365 | dev_err(&ctrl_info->pci_dev->dev, | |
7366 | "transition to PQI mode failed\n"); | |
7367 | return rc; | |
7368 | } | |
7369 | ||
7370 | /* From here on, we are running in PQI mode. */ | |
7371 | ctrl_info->pqi_mode_enabled = true; | |
7372 | pqi_save_ctrl_mode(ctrl_info, PQI_MODE); | |
7373 | ||
7374 | pqi_reinit_queues(ctrl_info); | |
7375 | ||
7376 | rc = pqi_create_admin_queues(ctrl_info); | |
7377 | if (rc) { | |
7378 | dev_err(&ctrl_info->pci_dev->dev, | |
7379 | "error creating admin queues\n"); | |
7380 | return rc; | |
7381 | } | |
7382 | ||
7383 | rc = pqi_create_queues(ctrl_info); | |
7384 | if (rc) | |
7385 | return rc; | |
7386 | ||
7387 | pqi_change_irq_mode(ctrl_info, IRQ_MODE_MSIX); | |
7388 | ||
7389 | ctrl_info->controller_online = true; | |
061ef06a KB |
7390 | pqi_ctrl_unblock_requests(ctrl_info); |
7391 | ||
4fd22c13 MR |
7392 | rc = pqi_process_config_table(ctrl_info); |
7393 | if (rc) | |
7394 | return rc; | |
7395 | ||
7396 | pqi_start_heartbeat_timer(ctrl_info); | |
7397 | ||
061ef06a KB |
7398 | rc = pqi_enable_events(ctrl_info); |
7399 | if (rc) { | |
7400 | dev_err(&ctrl_info->pci_dev->dev, | |
d87d5474 | 7401 | "error enabling events\n"); |
061ef06a KB |
7402 | return rc; |
7403 | } | |
7404 | ||
6d90615f | 7405 | rc = pqi_get_ctrl_product_details(ctrl_info); |
4fd22c13 MR |
7406 | if (rc) { |
7407 | dev_err(&ctrl_info->pci_dev->dev, | |
694c5d5b | 7408 | "error obtaining product details\n"); |
4fd22c13 MR |
7409 | return rc; |
7410 | } | |
7411 | ||
171c2865 DC |
7412 | rc = pqi_set_diag_rescan(ctrl_info); |
7413 | if (rc) { | |
7414 | dev_err(&ctrl_info->pci_dev->dev, | |
7415 | "error enabling multi-lun rescan\n"); | |
7416 | return rc; | |
7417 | } | |
7418 | ||
061ef06a KB |
7419 | rc = pqi_write_driver_version_to_host_wellness(ctrl_info); |
7420 | if (rc) { | |
7421 | dev_err(&ctrl_info->pci_dev->dev, | |
7422 | "error updating host wellness\n"); | |
7423 | return rc; | |
7424 | } | |
7425 | ||
7426 | pqi_schedule_update_time_worker(ctrl_info); | |
7427 | ||
7428 | pqi_scan_scsi_devices(ctrl_info); | |
7429 | ||
7430 | return 0; | |
7431 | } | |
7432 | ||
a81ed5f3 KB |
7433 | static inline int pqi_set_pcie_completion_timeout(struct pci_dev *pci_dev, |
7434 | u16 timeout) | |
7435 | { | |
d20df83b BOS |
7436 | int rc; |
7437 | ||
7438 | rc = pcie_capability_clear_and_set_word(pci_dev, PCI_EXP_DEVCTL2, | |
a81ed5f3 | 7439 | PCI_EXP_DEVCTL2_COMP_TIMEOUT, timeout); |
d20df83b BOS |
7440 | |
7441 | return pcibios_err_to_errno(rc); | |
a81ed5f3 KB |
7442 | } |
7443 | ||
6c223761 KB |
7444 | static int pqi_pci_init(struct pqi_ctrl_info *ctrl_info) |
7445 | { | |
7446 | int rc; | |
7447 | u64 mask; | |
7448 | ||
7449 | rc = pci_enable_device(ctrl_info->pci_dev); | |
7450 | if (rc) { | |
7451 | dev_err(&ctrl_info->pci_dev->dev, | |
7452 | "failed to enable PCI device\n"); | |
7453 | return rc; | |
7454 | } | |
7455 | ||
7456 | if (sizeof(dma_addr_t) > 4) | |
7457 | mask = DMA_BIT_MASK(64); | |
7458 | else | |
7459 | mask = DMA_BIT_MASK(32); | |
7460 | ||
1d94f06e | 7461 | rc = dma_set_mask_and_coherent(&ctrl_info->pci_dev->dev, mask); |
6c223761 KB |
7462 | if (rc) { |
7463 | dev_err(&ctrl_info->pci_dev->dev, "failed to set DMA mask\n"); | |
7464 | goto disable_device; | |
7465 | } | |
7466 | ||
7467 | rc = pci_request_regions(ctrl_info->pci_dev, DRIVER_NAME_SHORT); | |
7468 | if (rc) { | |
7469 | dev_err(&ctrl_info->pci_dev->dev, | |
7470 | "failed to obtain PCI resources\n"); | |
7471 | goto disable_device; | |
7472 | } | |
7473 | ||
4bdc0d67 | 7474 | ctrl_info->iomem_base = ioremap(pci_resource_start( |
6c223761 KB |
7475 | ctrl_info->pci_dev, 0), |
7476 | sizeof(struct pqi_ctrl_registers)); | |
7477 | if (!ctrl_info->iomem_base) { | |
7478 | dev_err(&ctrl_info->pci_dev->dev, | |
7479 | "failed to map memory for controller registers\n"); | |
7480 | rc = -ENOMEM; | |
7481 | goto release_regions; | |
7482 | } | |
7483 | ||
a81ed5f3 KB |
7484 | #define PCI_EXP_COMP_TIMEOUT_65_TO_210_MS 0x6 |
7485 | ||
7486 | /* Increase the PCIe completion timeout. */ | |
7487 | rc = pqi_set_pcie_completion_timeout(ctrl_info->pci_dev, | |
7488 | PCI_EXP_COMP_TIMEOUT_65_TO_210_MS); | |
7489 | if (rc) { | |
7490 | dev_err(&ctrl_info->pci_dev->dev, | |
7491 | "failed to set PCIe completion timeout\n"); | |
7492 | goto release_regions; | |
7493 | } | |
7494 | ||
6c223761 KB |
7495 | /* Enable bus mastering. */ |
7496 | pci_set_master(ctrl_info->pci_dev); | |
7497 | ||
cbe0c7b1 KB |
7498 | ctrl_info->registers = ctrl_info->iomem_base; |
7499 | ctrl_info->pqi_registers = &ctrl_info->registers->pqi_registers; | |
7500 | ||
6c223761 KB |
7501 | pci_set_drvdata(ctrl_info->pci_dev, ctrl_info); |
7502 | ||
7503 | return 0; | |
7504 | ||
7505 | release_regions: | |
7506 | pci_release_regions(ctrl_info->pci_dev); | |
7507 | disable_device: | |
7508 | pci_disable_device(ctrl_info->pci_dev); | |
7509 | ||
7510 | return rc; | |
7511 | } | |
7512 | ||
7513 | static void pqi_cleanup_pci_init(struct pqi_ctrl_info *ctrl_info) | |
7514 | { | |
7515 | iounmap(ctrl_info->iomem_base); | |
7516 | pci_release_regions(ctrl_info->pci_dev); | |
cbe0c7b1 KB |
7517 | if (pci_is_enabled(ctrl_info->pci_dev)) |
7518 | pci_disable_device(ctrl_info->pci_dev); | |
6c223761 KB |
7519 | pci_set_drvdata(ctrl_info->pci_dev, NULL); |
7520 | } | |
7521 | ||
7522 | static struct pqi_ctrl_info *pqi_alloc_ctrl_info(int numa_node) | |
7523 | { | |
7524 | struct pqi_ctrl_info *ctrl_info; | |
7525 | ||
7526 | ctrl_info = kzalloc_node(sizeof(struct pqi_ctrl_info), | |
7527 | GFP_KERNEL, numa_node); | |
7528 | if (!ctrl_info) | |
7529 | return NULL; | |
7530 | ||
7531 | mutex_init(&ctrl_info->scan_mutex); | |
7561a7e4 | 7532 | mutex_init(&ctrl_info->lun_reset_mutex); |
4fd22c13 | 7533 | mutex_init(&ctrl_info->ofa_mutex); |
6c223761 KB |
7534 | |
7535 | INIT_LIST_HEAD(&ctrl_info->scsi_device_list); | |
7536 | spin_lock_init(&ctrl_info->scsi_device_list_lock); | |
7537 | ||
7538 | INIT_WORK(&ctrl_info->event_work, pqi_event_worker); | |
7539 | atomic_set(&ctrl_info->num_interrupts, 0); | |
0530736e | 7540 | atomic_set(&ctrl_info->sync_cmds_outstanding, 0); |
6c223761 KB |
7541 | |
7542 | INIT_DELAYED_WORK(&ctrl_info->rescan_work, pqi_rescan_worker); | |
7543 | INIT_DELAYED_WORK(&ctrl_info->update_time_work, pqi_update_time_worker); | |
7544 | ||
74a0f573 | 7545 | timer_setup(&ctrl_info->heartbeat_timer, pqi_heartbeat_timer_handler, 0); |
5f310425 | 7546 | INIT_WORK(&ctrl_info->ctrl_offline_work, pqi_ctrl_offline_worker); |
98f87667 | 7547 | |
6c223761 KB |
7548 | sema_init(&ctrl_info->sync_request_sem, |
7549 | PQI_RESERVED_IO_SLOTS_SYNCHRONOUS_REQUESTS); | |
7561a7e4 | 7550 | init_waitqueue_head(&ctrl_info->block_requests_wait); |
6c223761 | 7551 | |
376fb880 KB |
7552 | INIT_LIST_HEAD(&ctrl_info->raid_bypass_retry_list); |
7553 | spin_lock_init(&ctrl_info->raid_bypass_retry_list_lock); | |
7554 | INIT_WORK(&ctrl_info->raid_bypass_retry_work, | |
7555 | pqi_raid_bypass_retry_worker); | |
7556 | ||
6c223761 | 7557 | ctrl_info->ctrl_id = atomic_inc_return(&pqi_controller_count) - 1; |
061ef06a | 7558 | ctrl_info->irq_mode = IRQ_MODE_NONE; |
6c223761 KB |
7559 | ctrl_info->max_msix_vectors = PQI_MAX_MSIX_VECTORS; |
7560 | ||
7561 | return ctrl_info; | |
7562 | } | |
7563 | ||
7564 | static inline void pqi_free_ctrl_info(struct pqi_ctrl_info *ctrl_info) | |
7565 | { | |
7566 | kfree(ctrl_info); | |
7567 | } | |
7568 | ||
7569 | static void pqi_free_interrupts(struct pqi_ctrl_info *ctrl_info) | |
7570 | { | |
98bf061b KB |
7571 | pqi_free_irqs(ctrl_info); |
7572 | pqi_disable_msix_interrupts(ctrl_info); | |
6c223761 KB |
7573 | } |
7574 | ||
7575 | static void pqi_free_ctrl_resources(struct pqi_ctrl_info *ctrl_info) | |
7576 | { | |
7577 | pqi_stop_heartbeat_timer(ctrl_info); | |
7578 | pqi_free_interrupts(ctrl_info); | |
7579 | if (ctrl_info->queue_memory_base) | |
7580 | dma_free_coherent(&ctrl_info->pci_dev->dev, | |
7581 | ctrl_info->queue_memory_length, | |
7582 | ctrl_info->queue_memory_base, | |
7583 | ctrl_info->queue_memory_base_dma_handle); | |
7584 | if (ctrl_info->admin_queue_memory_base) | |
7585 | dma_free_coherent(&ctrl_info->pci_dev->dev, | |
7586 | ctrl_info->admin_queue_memory_length, | |
7587 | ctrl_info->admin_queue_memory_base, | |
7588 | ctrl_info->admin_queue_memory_base_dma_handle); | |
7589 | pqi_free_all_io_requests(ctrl_info); | |
7590 | if (ctrl_info->error_buffer) | |
7591 | dma_free_coherent(&ctrl_info->pci_dev->dev, | |
7592 | ctrl_info->error_buffer_length, | |
7593 | ctrl_info->error_buffer, | |
7594 | ctrl_info->error_buffer_dma_handle); | |
7595 | if (ctrl_info->iomem_base) | |
7596 | pqi_cleanup_pci_init(ctrl_info); | |
7597 | pqi_free_ctrl_info(ctrl_info); | |
7598 | } | |
7599 | ||
7600 | static void pqi_remove_ctrl(struct pqi_ctrl_info *ctrl_info) | |
7601 | { | |
061ef06a KB |
7602 | pqi_cancel_rescan_worker(ctrl_info); |
7603 | pqi_cancel_update_time_worker(ctrl_info); | |
e57a1f9b KB |
7604 | pqi_remove_all_scsi_devices(ctrl_info); |
7605 | pqi_unregister_scsi(ctrl_info); | |
162d7753 KB |
7606 | if (ctrl_info->pqi_mode_enabled) |
7607 | pqi_revert_to_sis_mode(ctrl_info); | |
6c223761 KB |
7608 | pqi_free_ctrl_resources(ctrl_info); |
7609 | } | |
7610 | ||
4fd22c13 MR |
7611 | static void pqi_ofa_ctrl_quiesce(struct pqi_ctrl_info *ctrl_info) |
7612 | { | |
7613 | pqi_cancel_update_time_worker(ctrl_info); | |
7614 | pqi_cancel_rescan_worker(ctrl_info); | |
7615 | pqi_wait_until_lun_reset_finished(ctrl_info); | |
7616 | pqi_wait_until_scan_finished(ctrl_info); | |
7617 | pqi_ctrl_ofa_start(ctrl_info); | |
7618 | pqi_ctrl_block_requests(ctrl_info); | |
7619 | pqi_ctrl_wait_until_quiesced(ctrl_info); | |
7620 | pqi_ctrl_wait_for_pending_io(ctrl_info, PQI_PENDING_IO_TIMEOUT_SECS); | |
7621 | pqi_fail_io_queued_for_all_devices(ctrl_info); | |
7622 | pqi_wait_until_inbound_queues_empty(ctrl_info); | |
7623 | pqi_stop_heartbeat_timer(ctrl_info); | |
7624 | ctrl_info->pqi_mode_enabled = false; | |
7625 | pqi_save_ctrl_mode(ctrl_info, SIS_MODE); | |
7626 | } | |
7627 | ||
7628 | static void pqi_ofa_ctrl_unquiesce(struct pqi_ctrl_info *ctrl_info) | |
7629 | { | |
7630 | pqi_ofa_free_host_buffer(ctrl_info); | |
7631 | ctrl_info->pqi_mode_enabled = true; | |
7632 | pqi_save_ctrl_mode(ctrl_info, PQI_MODE); | |
7633 | ctrl_info->controller_online = true; | |
7634 | pqi_ctrl_unblock_requests(ctrl_info); | |
7635 | pqi_start_heartbeat_timer(ctrl_info); | |
7636 | pqi_schedule_update_time_worker(ctrl_info); | |
7637 | pqi_clear_soft_reset_status(ctrl_info, | |
7638 | PQI_SOFT_RESET_ABORT); | |
7639 | pqi_scan_scsi_devices(ctrl_info); | |
7640 | } | |
7641 | ||
7642 | static int pqi_ofa_alloc_mem(struct pqi_ctrl_info *ctrl_info, | |
7643 | u32 total_size, u32 chunk_size) | |
7644 | { | |
7645 | u32 sg_count; | |
7646 | u32 size; | |
7647 | int i; | |
7648 | struct pqi_sg_descriptor *mem_descriptor = NULL; | |
7649 | struct device *dev; | |
7650 | struct pqi_ofa_memory *ofap; | |
7651 | ||
7652 | dev = &ctrl_info->pci_dev->dev; | |
7653 | ||
7654 | sg_count = (total_size + chunk_size - 1); | |
e52c9e07 | 7655 | sg_count /= chunk_size; |
4fd22c13 MR |
7656 | |
7657 | ofap = ctrl_info->pqi_ofa_mem_virt_addr; | |
7658 | ||
7659 | if (sg_count*chunk_size < total_size) | |
7660 | goto out; | |
7661 | ||
7662 | ctrl_info->pqi_ofa_chunk_virt_addr = | |
7663 | kcalloc(sg_count, sizeof(void *), GFP_KERNEL); | |
7664 | if (!ctrl_info->pqi_ofa_chunk_virt_addr) | |
7665 | goto out; | |
7666 | ||
7667 | for (size = 0, i = 0; size < total_size; size += chunk_size, i++) { | |
7668 | dma_addr_t dma_handle; | |
7669 | ||
7670 | ctrl_info->pqi_ofa_chunk_virt_addr[i] = | |
750afb08 LC |
7671 | dma_alloc_coherent(dev, chunk_size, &dma_handle, |
7672 | GFP_KERNEL); | |
4fd22c13 MR |
7673 | |
7674 | if (!ctrl_info->pqi_ofa_chunk_virt_addr[i]) | |
7675 | break; | |
7676 | ||
7677 | mem_descriptor = &ofap->sg_descriptor[i]; | |
7678 | put_unaligned_le64 ((u64) dma_handle, &mem_descriptor->address); | |
7679 | put_unaligned_le32 (chunk_size, &mem_descriptor->length); | |
7680 | } | |
7681 | ||
7682 | if (!size || size < total_size) | |
7683 | goto out_free_chunks; | |
7684 | ||
7685 | put_unaligned_le32(CISS_SG_LAST, &mem_descriptor->flags); | |
7686 | put_unaligned_le16(sg_count, &ofap->num_memory_descriptors); | |
7687 | put_unaligned_le32(size, &ofap->bytes_allocated); | |
7688 | ||
7689 | return 0; | |
7690 | ||
7691 | out_free_chunks: | |
7692 | while (--i >= 0) { | |
7693 | mem_descriptor = &ofap->sg_descriptor[i]; | |
7694 | dma_free_coherent(dev, chunk_size, | |
7695 | ctrl_info->pqi_ofa_chunk_virt_addr[i], | |
7696 | get_unaligned_le64(&mem_descriptor->address)); | |
7697 | } | |
7698 | kfree(ctrl_info->pqi_ofa_chunk_virt_addr); | |
7699 | ||
7700 | out: | |
7701 | put_unaligned_le32 (0, &ofap->bytes_allocated); | |
7702 | return -ENOMEM; | |
7703 | } | |
7704 | ||
7705 | static int pqi_ofa_alloc_host_buffer(struct pqi_ctrl_info *ctrl_info) | |
7706 | { | |
7707 | u32 total_size; | |
7708 | u32 min_chunk_size; | |
7709 | u32 chunk_sz; | |
7710 | ||
7711 | total_size = le32_to_cpu( | |
7712 | ctrl_info->pqi_ofa_mem_virt_addr->bytes_allocated); | |
7713 | min_chunk_size = total_size / PQI_OFA_MAX_SG_DESCRIPTORS; | |
7714 | ||
7715 | for (chunk_sz = total_size; chunk_sz >= min_chunk_size; chunk_sz /= 2) | |
7716 | if (!pqi_ofa_alloc_mem(ctrl_info, total_size, chunk_sz)) | |
7717 | return 0; | |
7718 | ||
7719 | return -ENOMEM; | |
7720 | } | |
7721 | ||
7722 | static void pqi_ofa_setup_host_buffer(struct pqi_ctrl_info *ctrl_info, | |
7723 | u32 bytes_requested) | |
7724 | { | |
7725 | struct pqi_ofa_memory *pqi_ofa_memory; | |
7726 | struct device *dev; | |
7727 | ||
7728 | dev = &ctrl_info->pci_dev->dev; | |
750afb08 LC |
7729 | pqi_ofa_memory = dma_alloc_coherent(dev, |
7730 | PQI_OFA_MEMORY_DESCRIPTOR_LENGTH, | |
7731 | &ctrl_info->pqi_ofa_mem_dma_handle, | |
7732 | GFP_KERNEL); | |
4fd22c13 MR |
7733 | |
7734 | if (!pqi_ofa_memory) | |
7735 | return; | |
7736 | ||
7737 | put_unaligned_le16(PQI_OFA_VERSION, &pqi_ofa_memory->version); | |
7738 | memcpy(&pqi_ofa_memory->signature, PQI_OFA_SIGNATURE, | |
7739 | sizeof(pqi_ofa_memory->signature)); | |
7740 | pqi_ofa_memory->bytes_allocated = cpu_to_le32(bytes_requested); | |
7741 | ||
7742 | ctrl_info->pqi_ofa_mem_virt_addr = pqi_ofa_memory; | |
7743 | ||
7744 | if (pqi_ofa_alloc_host_buffer(ctrl_info) < 0) { | |
7745 | dev_err(dev, "Failed to allocate host buffer of size = %u", | |
7746 | bytes_requested); | |
7747 | } | |
694c5d5b KB |
7748 | |
7749 | return; | |
4fd22c13 MR |
7750 | } |
7751 | ||
7752 | static void pqi_ofa_free_host_buffer(struct pqi_ctrl_info *ctrl_info) | |
7753 | { | |
7754 | int i; | |
7755 | struct pqi_sg_descriptor *mem_descriptor; | |
7756 | struct pqi_ofa_memory *ofap; | |
7757 | ||
7758 | ofap = ctrl_info->pqi_ofa_mem_virt_addr; | |
7759 | ||
7760 | if (!ofap) | |
7761 | return; | |
7762 | ||
7763 | if (!ofap->bytes_allocated) | |
7764 | goto out; | |
7765 | ||
7766 | mem_descriptor = ofap->sg_descriptor; | |
7767 | ||
7768 | for (i = 0; i < get_unaligned_le16(&ofap->num_memory_descriptors); | |
7769 | i++) { | |
7770 | dma_free_coherent(&ctrl_info->pci_dev->dev, | |
7771 | get_unaligned_le32(&mem_descriptor[i].length), | |
7772 | ctrl_info->pqi_ofa_chunk_virt_addr[i], | |
7773 | get_unaligned_le64(&mem_descriptor[i].address)); | |
7774 | } | |
7775 | kfree(ctrl_info->pqi_ofa_chunk_virt_addr); | |
7776 | ||
7777 | out: | |
7778 | dma_free_coherent(&ctrl_info->pci_dev->dev, | |
7779 | PQI_OFA_MEMORY_DESCRIPTOR_LENGTH, ofap, | |
7780 | ctrl_info->pqi_ofa_mem_dma_handle); | |
7781 | ctrl_info->pqi_ofa_mem_virt_addr = NULL; | |
7782 | } | |
7783 | ||
7784 | static int pqi_ofa_host_memory_update(struct pqi_ctrl_info *ctrl_info) | |
7785 | { | |
7786 | struct pqi_vendor_general_request request; | |
7787 | size_t size; | |
7788 | struct pqi_ofa_memory *ofap; | |
7789 | ||
7790 | memset(&request, 0, sizeof(request)); | |
7791 | ||
7792 | ofap = ctrl_info->pqi_ofa_mem_virt_addr; | |
7793 | ||
7794 | request.header.iu_type = PQI_REQUEST_IU_VENDOR_GENERAL; | |
7795 | put_unaligned_le16(sizeof(request) - PQI_REQUEST_HEADER_LENGTH, | |
7796 | &request.header.iu_length); | |
7797 | put_unaligned_le16(PQI_VENDOR_GENERAL_HOST_MEMORY_UPDATE, | |
7798 | &request.function_code); | |
7799 | ||
7800 | if (ofap) { | |
7801 | size = offsetof(struct pqi_ofa_memory, sg_descriptor) + | |
7802 | get_unaligned_le16(&ofap->num_memory_descriptors) * | |
7803 | sizeof(struct pqi_sg_descriptor); | |
7804 | ||
7805 | put_unaligned_le64((u64)ctrl_info->pqi_ofa_mem_dma_handle, | |
7806 | &request.data.ofa_memory_allocation.buffer_address); | |
7807 | put_unaligned_le32(size, | |
7808 | &request.data.ofa_memory_allocation.buffer_length); | |
7809 | ||
7810 | } | |
7811 | ||
7812 | return pqi_submit_raid_request_synchronous(ctrl_info, &request.header, | |
7813 | 0, NULL, NO_TIMEOUT); | |
7814 | } | |
7815 | ||
4fd22c13 MR |
7816 | static int pqi_ofa_ctrl_restart(struct pqi_ctrl_info *ctrl_info) |
7817 | { | |
7818 | msleep(PQI_POST_RESET_DELAY_B4_MSGU_READY); | |
7819 | return pqi_ctrl_init_resume(ctrl_info); | |
7820 | } | |
7821 | ||
3c50976f KB |
7822 | static void pqi_perform_lockup_action(void) |
7823 | { | |
7824 | switch (pqi_lockup_action) { | |
7825 | case PANIC: | |
7826 | panic("FATAL: Smart Family Controller lockup detected"); | |
7827 | break; | |
7828 | case REBOOT: | |
7829 | emergency_restart(); | |
7830 | break; | |
7831 | case NONE: | |
7832 | default: | |
7833 | break; | |
7834 | } | |
7835 | } | |
7836 | ||
5f310425 KB |
7837 | static struct pqi_raid_error_info pqi_ctrl_offline_raid_error_info = { |
7838 | .data_out_result = PQI_DATA_IN_OUT_HARDWARE_ERROR, | |
7839 | .status = SAM_STAT_CHECK_CONDITION, | |
7840 | }; | |
7841 | ||
7842 | static void pqi_fail_all_outstanding_requests(struct pqi_ctrl_info *ctrl_info) | |
376fb880 KB |
7843 | { |
7844 | unsigned int i; | |
376fb880 | 7845 | struct pqi_io_request *io_request; |
376fb880 KB |
7846 | struct scsi_cmnd *scmd; |
7847 | ||
5f310425 KB |
7848 | for (i = 0; i < ctrl_info->max_io_slots; i++) { |
7849 | io_request = &ctrl_info->io_request_pool[i]; | |
7850 | if (atomic_read(&io_request->refcount) == 0) | |
7851 | continue; | |
376fb880 | 7852 | |
5f310425 KB |
7853 | scmd = io_request->scmd; |
7854 | if (scmd) { | |
7855 | set_host_byte(scmd, DID_NO_CONNECT); | |
7856 | } else { | |
7857 | io_request->status = -ENXIO; | |
7858 | io_request->error_info = | |
7859 | &pqi_ctrl_offline_raid_error_info; | |
376fb880 | 7860 | } |
5f310425 KB |
7861 | |
7862 | io_request->io_complete_callback(io_request, | |
7863 | io_request->context); | |
376fb880 KB |
7864 | } |
7865 | } | |
7866 | ||
5f310425 | 7867 | static void pqi_take_ctrl_offline_deferred(struct pqi_ctrl_info *ctrl_info) |
376fb880 | 7868 | { |
5f310425 KB |
7869 | pqi_perform_lockup_action(); |
7870 | pqi_stop_heartbeat_timer(ctrl_info); | |
7871 | pqi_free_interrupts(ctrl_info); | |
7872 | pqi_cancel_rescan_worker(ctrl_info); | |
7873 | pqi_cancel_update_time_worker(ctrl_info); | |
7874 | pqi_ctrl_wait_until_quiesced(ctrl_info); | |
7875 | pqi_fail_all_outstanding_requests(ctrl_info); | |
7876 | pqi_clear_all_queued_raid_bypass_retries(ctrl_info); | |
7877 | pqi_ctrl_unblock_requests(ctrl_info); | |
7878 | } | |
7879 | ||
7880 | static void pqi_ctrl_offline_worker(struct work_struct *work) | |
7881 | { | |
7882 | struct pqi_ctrl_info *ctrl_info; | |
7883 | ||
7884 | ctrl_info = container_of(work, struct pqi_ctrl_info, ctrl_offline_work); | |
7885 | pqi_take_ctrl_offline_deferred(ctrl_info); | |
376fb880 KB |
7886 | } |
7887 | ||
7888 | static void pqi_take_ctrl_offline(struct pqi_ctrl_info *ctrl_info) | |
7889 | { | |
5f310425 KB |
7890 | if (!ctrl_info->controller_online) |
7891 | return; | |
7892 | ||
376fb880 | 7893 | ctrl_info->controller_online = false; |
5f310425 KB |
7894 | ctrl_info->pqi_mode_enabled = false; |
7895 | pqi_ctrl_block_requests(ctrl_info); | |
5a259e32 KB |
7896 | if (!pqi_disable_ctrl_shutdown) |
7897 | sis_shutdown_ctrl(ctrl_info); | |
376fb880 KB |
7898 | pci_disable_device(ctrl_info->pci_dev); |
7899 | dev_err(&ctrl_info->pci_dev->dev, "controller offline\n"); | |
5f310425 | 7900 | schedule_work(&ctrl_info->ctrl_offline_work); |
376fb880 KB |
7901 | } |
7902 | ||
d91d7820 | 7903 | static void pqi_print_ctrl_info(struct pci_dev *pci_dev, |
6c223761 KB |
7904 | const struct pci_device_id *id) |
7905 | { | |
7906 | char *ctrl_description; | |
7907 | ||
37b36847 | 7908 | if (id->driver_data) |
6c223761 | 7909 | ctrl_description = (char *)id->driver_data; |
37b36847 KB |
7910 | else |
7911 | ctrl_description = "Microsemi Smart Family Controller"; | |
6c223761 | 7912 | |
d91d7820 | 7913 | dev_info(&pci_dev->dev, "%s found\n", ctrl_description); |
6c223761 KB |
7914 | } |
7915 | ||
d91d7820 KB |
7916 | static int pqi_pci_probe(struct pci_dev *pci_dev, |
7917 | const struct pci_device_id *id) | |
6c223761 KB |
7918 | { |
7919 | int rc; | |
62dc51fb | 7920 | int node, cp_node; |
6c223761 KB |
7921 | struct pqi_ctrl_info *ctrl_info; |
7922 | ||
d91d7820 | 7923 | pqi_print_ctrl_info(pci_dev, id); |
6c223761 KB |
7924 | |
7925 | if (pqi_disable_device_id_wildcards && | |
7926 | id->subvendor == PCI_ANY_ID && | |
7927 | id->subdevice == PCI_ANY_ID) { | |
d91d7820 | 7928 | dev_warn(&pci_dev->dev, |
6c223761 KB |
7929 | "controller not probed because device ID wildcards are disabled\n"); |
7930 | return -ENODEV; | |
7931 | } | |
7932 | ||
7933 | if (id->subvendor == PCI_ANY_ID || id->subdevice == PCI_ANY_ID) | |
d91d7820 | 7934 | dev_warn(&pci_dev->dev, |
6c223761 KB |
7935 | "controller device ID matched using wildcards\n"); |
7936 | ||
d91d7820 | 7937 | node = dev_to_node(&pci_dev->dev); |
62dc51fb SB |
7938 | if (node == NUMA_NO_NODE) { |
7939 | cp_node = cpu_to_node(0); | |
7940 | if (cp_node == NUMA_NO_NODE) | |
7941 | cp_node = 0; | |
7942 | set_dev_node(&pci_dev->dev, cp_node); | |
7943 | } | |
6c223761 KB |
7944 | |
7945 | ctrl_info = pqi_alloc_ctrl_info(node); | |
7946 | if (!ctrl_info) { | |
d91d7820 | 7947 | dev_err(&pci_dev->dev, |
6c223761 KB |
7948 | "failed to allocate controller info block\n"); |
7949 | return -ENOMEM; | |
7950 | } | |
7951 | ||
d91d7820 | 7952 | ctrl_info->pci_dev = pci_dev; |
6c223761 KB |
7953 | |
7954 | rc = pqi_pci_init(ctrl_info); | |
7955 | if (rc) | |
7956 | goto error; | |
7957 | ||
7958 | rc = pqi_ctrl_init(ctrl_info); | |
7959 | if (rc) | |
7960 | goto error; | |
7961 | ||
7962 | return 0; | |
7963 | ||
7964 | error: | |
7965 | pqi_remove_ctrl(ctrl_info); | |
7966 | ||
7967 | return rc; | |
7968 | } | |
7969 | ||
d91d7820 | 7970 | static void pqi_pci_remove(struct pci_dev *pci_dev) |
6c223761 KB |
7971 | { |
7972 | struct pqi_ctrl_info *ctrl_info; | |
7973 | ||
d91d7820 | 7974 | ctrl_info = pci_get_drvdata(pci_dev); |
6c223761 KB |
7975 | if (!ctrl_info) |
7976 | return; | |
7977 | ||
1e46731e MR |
7978 | ctrl_info->in_shutdown = true; |
7979 | ||
6c223761 KB |
7980 | pqi_remove_ctrl(ctrl_info); |
7981 | } | |
7982 | ||
0530736e KB |
7983 | static void pqi_crash_if_pending_command(struct pqi_ctrl_info *ctrl_info) |
7984 | { | |
7985 | unsigned int i; | |
7986 | struct pqi_io_request *io_request; | |
7987 | struct scsi_cmnd *scmd; | |
7988 | ||
7989 | for (i = 0; i < ctrl_info->max_io_slots; i++) { | |
7990 | io_request = &ctrl_info->io_request_pool[i]; | |
7991 | if (atomic_read(&io_request->refcount) == 0) | |
7992 | continue; | |
7993 | scmd = io_request->scmd; | |
7994 | WARN_ON(scmd != NULL); /* IO command from SML */ | |
7995 | WARN_ON(scmd == NULL); /* Non-IO cmd or driver initiated*/ | |
7996 | } | |
7997 | } | |
7998 | ||
d91d7820 | 7999 | static void pqi_shutdown(struct pci_dev *pci_dev) |
6c223761 KB |
8000 | { |
8001 | int rc; | |
8002 | struct pqi_ctrl_info *ctrl_info; | |
8003 | ||
d91d7820 | 8004 | ctrl_info = pci_get_drvdata(pci_dev); |
0530736e KB |
8005 | if (!ctrl_info) { |
8006 | dev_err(&pci_dev->dev, | |
8007 | "cache could not be flushed\n"); | |
8008 | return; | |
8009 | } | |
8010 | ||
8011 | pqi_disable_events(ctrl_info); | |
8012 | pqi_wait_until_ofa_finished(ctrl_info); | |
8013 | pqi_cancel_update_time_worker(ctrl_info); | |
8014 | pqi_cancel_rescan_worker(ctrl_info); | |
8015 | pqi_cancel_event_worker(ctrl_info); | |
8016 | ||
8017 | pqi_ctrl_shutdown_start(ctrl_info); | |
8018 | pqi_ctrl_wait_until_quiesced(ctrl_info); | |
8019 | ||
8020 | rc = pqi_ctrl_wait_for_pending_io(ctrl_info, NO_TIMEOUT); | |
8021 | if (rc) { | |
8022 | dev_err(&pci_dev->dev, | |
8023 | "wait for pending I/O failed\n"); | |
8024 | return; | |
8025 | } | |
8026 | ||
8027 | pqi_ctrl_block_device_reset(ctrl_info); | |
8028 | pqi_wait_until_lun_reset_finished(ctrl_info); | |
6c223761 KB |
8029 | |
8030 | /* | |
8031 | * Write all data in the controller's battery-backed cache to | |
8032 | * storage. | |
8033 | */ | |
58322fe0 | 8034 | rc = pqi_flush_cache(ctrl_info, SHUTDOWN); |
0530736e KB |
8035 | if (rc) |
8036 | dev_err(&pci_dev->dev, | |
8037 | "unable to flush controller cache\n"); | |
8038 | ||
8039 | pqi_ctrl_block_requests(ctrl_info); | |
8040 | ||
8041 | rc = pqi_ctrl_wait_for_pending_sync_cmds(ctrl_info); | |
8042 | if (rc) { | |
8043 | dev_err(&pci_dev->dev, | |
8044 | "wait for pending sync cmds failed\n"); | |
6c223761 | 8045 | return; |
0530736e KB |
8046 | } |
8047 | ||
8048 | pqi_crash_if_pending_command(ctrl_info); | |
8049 | pqi_reset(ctrl_info); | |
6c223761 KB |
8050 | } |
8051 | ||
3c50976f KB |
8052 | static void pqi_process_lockup_action_param(void) |
8053 | { | |
8054 | unsigned int i; | |
8055 | ||
8056 | if (!pqi_lockup_action_param) | |
8057 | return; | |
8058 | ||
8059 | for (i = 0; i < ARRAY_SIZE(pqi_lockup_actions); i++) { | |
8060 | if (strcmp(pqi_lockup_action_param, | |
8061 | pqi_lockup_actions[i].name) == 0) { | |
8062 | pqi_lockup_action = pqi_lockup_actions[i].action; | |
8063 | return; | |
8064 | } | |
8065 | } | |
8066 | ||
8067 | pr_warn("%s: invalid lockup action setting \"%s\" - supported settings: none, reboot, panic\n", | |
8068 | DRIVER_NAME_SHORT, pqi_lockup_action_param); | |
8069 | } | |
8070 | ||
8071 | static void pqi_process_module_params(void) | |
8072 | { | |
8073 | pqi_process_lockup_action_param(); | |
8074 | } | |
8075 | ||
5c146686 | 8076 | static __maybe_unused int pqi_suspend(struct pci_dev *pci_dev, pm_message_t state) |
061ef06a KB |
8077 | { |
8078 | struct pqi_ctrl_info *ctrl_info; | |
8079 | ||
8080 | ctrl_info = pci_get_drvdata(pci_dev); | |
8081 | ||
8082 | pqi_disable_events(ctrl_info); | |
8083 | pqi_cancel_update_time_worker(ctrl_info); | |
8084 | pqi_cancel_rescan_worker(ctrl_info); | |
8085 | pqi_wait_until_scan_finished(ctrl_info); | |
8086 | pqi_wait_until_lun_reset_finished(ctrl_info); | |
4fd22c13 | 8087 | pqi_wait_until_ofa_finished(ctrl_info); |
58322fe0 | 8088 | pqi_flush_cache(ctrl_info, SUSPEND); |
061ef06a KB |
8089 | pqi_ctrl_block_requests(ctrl_info); |
8090 | pqi_ctrl_wait_until_quiesced(ctrl_info); | |
8091 | pqi_wait_until_inbound_queues_empty(ctrl_info); | |
4fd22c13 | 8092 | pqi_ctrl_wait_for_pending_io(ctrl_info, NO_TIMEOUT); |
061ef06a KB |
8093 | pqi_stop_heartbeat_timer(ctrl_info); |
8094 | ||
8095 | if (state.event == PM_EVENT_FREEZE) | |
8096 | return 0; | |
8097 | ||
8098 | pci_save_state(pci_dev); | |
8099 | pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state)); | |
8100 | ||
8101 | ctrl_info->controller_online = false; | |
8102 | ctrl_info->pqi_mode_enabled = false; | |
8103 | ||
8104 | return 0; | |
8105 | } | |
8106 | ||
5c146686 | 8107 | static __maybe_unused int pqi_resume(struct pci_dev *pci_dev) |
061ef06a KB |
8108 | { |
8109 | int rc; | |
8110 | struct pqi_ctrl_info *ctrl_info; | |
8111 | ||
8112 | ctrl_info = pci_get_drvdata(pci_dev); | |
8113 | ||
8114 | if (pci_dev->current_state != PCI_D0) { | |
8115 | ctrl_info->max_hw_queue_index = 0; | |
8116 | pqi_free_interrupts(ctrl_info); | |
8117 | pqi_change_irq_mode(ctrl_info, IRQ_MODE_INTX); | |
8118 | rc = request_irq(pci_irq_vector(pci_dev, 0), pqi_irq_handler, | |
8119 | IRQF_SHARED, DRIVER_NAME_SHORT, | |
8120 | &ctrl_info->queue_groups[0]); | |
8121 | if (rc) { | |
8122 | dev_err(&ctrl_info->pci_dev->dev, | |
8123 | "irq %u init failed with error %d\n", | |
8124 | pci_dev->irq, rc); | |
8125 | return rc; | |
8126 | } | |
8127 | pqi_start_heartbeat_timer(ctrl_info); | |
8128 | pqi_ctrl_unblock_requests(ctrl_info); | |
8129 | return 0; | |
8130 | } | |
8131 | ||
8132 | pci_set_power_state(pci_dev, PCI_D0); | |
8133 | pci_restore_state(pci_dev); | |
8134 | ||
8135 | return pqi_ctrl_init_resume(ctrl_info); | |
8136 | } | |
8137 | ||
6c223761 KB |
8138 | /* Define the PCI IDs for the controllers that we support. */ |
8139 | static const struct pci_device_id pqi_pci_id_table[] = { | |
b0f9408b KB |
8140 | { |
8141 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8142 | 0x105b, 0x1211) | |
8143 | }, | |
8144 | { | |
8145 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8146 | 0x105b, 0x1321) | |
8147 | }, | |
7eddabff KB |
8148 | { |
8149 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8150 | 0x152d, 0x8a22) | |
8151 | }, | |
8152 | { | |
8153 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8154 | 0x152d, 0x8a23) | |
8155 | }, | |
8156 | { | |
8157 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8158 | 0x152d, 0x8a24) | |
8159 | }, | |
8160 | { | |
8161 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8162 | 0x152d, 0x8a36) | |
8163 | }, | |
8164 | { | |
8165 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8166 | 0x152d, 0x8a37) | |
8167 | }, | |
0595a0b4 AK |
8168 | { |
8169 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8170 | 0x193d, 0x1104) | |
8171 | }, | |
8172 | { | |
8173 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8174 | 0x193d, 0x1105) | |
8175 | }, | |
8176 | { | |
8177 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8178 | 0x193d, 0x1106) | |
8179 | }, | |
8180 | { | |
8181 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8182 | 0x193d, 0x1107) | |
8183 | }, | |
b0f9408b KB |
8184 | { |
8185 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8186 | 0x193d, 0x8460) | |
8187 | }, | |
8188 | { | |
8189 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8190 | 0x193d, 0x8461) | |
8191 | }, | |
84a77fef MB |
8192 | { |
8193 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8194 | 0x193d, 0xc460) | |
8195 | }, | |
8196 | { | |
8197 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8198 | 0x193d, 0xc461) | |
8199 | }, | |
b0f9408b KB |
8200 | { |
8201 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8202 | 0x193d, 0xf460) | |
8203 | }, | |
8204 | { | |
8205 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8206 | 0x193d, 0xf461) | |
8207 | }, | |
8208 | { | |
8209 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8210 | 0x1bd4, 0x0045) | |
8211 | }, | |
8212 | { | |
8213 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8214 | 0x1bd4, 0x0046) | |
8215 | }, | |
8216 | { | |
8217 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8218 | 0x1bd4, 0x0047) | |
8219 | }, | |
8220 | { | |
8221 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8222 | 0x1bd4, 0x0048) | |
8223 | }, | |
9f8d05fa KB |
8224 | { |
8225 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8226 | 0x1bd4, 0x004a) | |
8227 | }, | |
8228 | { | |
8229 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8230 | 0x1bd4, 0x004b) | |
8231 | }, | |
8232 | { | |
8233 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8234 | 0x1bd4, 0x004c) | |
8235 | }, | |
63a7956a GW |
8236 | { |
8237 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8238 | 0x1bd4, 0x004f) | |
8239 | }, | |
c1b10475 AK |
8240 | { |
8241 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8242 | 0x19e5, 0xd227) | |
8243 | }, | |
8244 | { | |
8245 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8246 | 0x19e5, 0xd228) | |
8247 | }, | |
8248 | { | |
8249 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8250 | 0x19e5, 0xd229) | |
8251 | }, | |
8252 | { | |
8253 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8254 | 0x19e5, 0xd22a) | |
8255 | }, | |
8256 | { | |
8257 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8258 | 0x19e5, 0xd22b) | |
8259 | }, | |
8260 | { | |
8261 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8262 | 0x19e5, 0xd22c) | |
8263 | }, | |
6c223761 KB |
8264 | { |
8265 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8266 | PCI_VENDOR_ID_ADAPTEC2, 0x0110) | |
8267 | }, | |
8268 | { | |
8269 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
55790064 | 8270 | PCI_VENDOR_ID_ADAPTEC2, 0x0608) |
6c223761 KB |
8271 | }, |
8272 | { | |
8273 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
7eddabff | 8274 | PCI_VENDOR_ID_ADAPTEC2, 0x0800) |
6c223761 KB |
8275 | }, |
8276 | { | |
8277 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
7eddabff | 8278 | PCI_VENDOR_ID_ADAPTEC2, 0x0801) |
6c223761 KB |
8279 | }, |
8280 | { | |
8281 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
7eddabff | 8282 | PCI_VENDOR_ID_ADAPTEC2, 0x0802) |
6c223761 KB |
8283 | }, |
8284 | { | |
8285 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
7eddabff | 8286 | PCI_VENDOR_ID_ADAPTEC2, 0x0803) |
6c223761 KB |
8287 | }, |
8288 | { | |
8289 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
7eddabff | 8290 | PCI_VENDOR_ID_ADAPTEC2, 0x0804) |
6c223761 KB |
8291 | }, |
8292 | { | |
8293 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
7eddabff | 8294 | PCI_VENDOR_ID_ADAPTEC2, 0x0805) |
6c223761 KB |
8295 | }, |
8296 | { | |
8297 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
7eddabff | 8298 | PCI_VENDOR_ID_ADAPTEC2, 0x0806) |
6c223761 | 8299 | }, |
55790064 KB |
8300 | { |
8301 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8302 | PCI_VENDOR_ID_ADAPTEC2, 0x0807) | |
8303 | }, | |
63a7956a GW |
8304 | { |
8305 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8306 | PCI_VENDOR_ID_ADAPTEC2, 0x0808) | |
8307 | }, | |
8308 | { | |
8309 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8310 | PCI_VENDOR_ID_ADAPTEC2, 0x0809) | |
8311 | }, | |
3af06083 MR |
8312 | { |
8313 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8314 | PCI_VENDOR_ID_ADAPTEC2, 0x080a) | |
8315 | }, | |
6c223761 KB |
8316 | { |
8317 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
7eddabff | 8318 | PCI_VENDOR_ID_ADAPTEC2, 0x0900) |
6c223761 KB |
8319 | }, |
8320 | { | |
8321 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
7eddabff | 8322 | PCI_VENDOR_ID_ADAPTEC2, 0x0901) |
6c223761 KB |
8323 | }, |
8324 | { | |
8325 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
7eddabff | 8326 | PCI_VENDOR_ID_ADAPTEC2, 0x0902) |
6c223761 KB |
8327 | }, |
8328 | { | |
8329 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
7eddabff | 8330 | PCI_VENDOR_ID_ADAPTEC2, 0x0903) |
6c223761 KB |
8331 | }, |
8332 | { | |
8333 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
7eddabff | 8334 | PCI_VENDOR_ID_ADAPTEC2, 0x0904) |
6c223761 KB |
8335 | }, |
8336 | { | |
8337 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
7eddabff | 8338 | PCI_VENDOR_ID_ADAPTEC2, 0x0905) |
6c223761 KB |
8339 | }, |
8340 | { | |
8341 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
7eddabff | 8342 | PCI_VENDOR_ID_ADAPTEC2, 0x0906) |
6c223761 KB |
8343 | }, |
8344 | { | |
8345 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
7eddabff | 8346 | PCI_VENDOR_ID_ADAPTEC2, 0x0907) |
6c223761 KB |
8347 | }, |
8348 | { | |
8349 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
7eddabff | 8350 | PCI_VENDOR_ID_ADAPTEC2, 0x0908) |
6c223761 | 8351 | }, |
55790064 KB |
8352 | { |
8353 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8354 | PCI_VENDOR_ID_ADAPTEC2, 0x090a) | |
8355 | }, | |
6c223761 KB |
8356 | { |
8357 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
7eddabff | 8358 | PCI_VENDOR_ID_ADAPTEC2, 0x1200) |
6c223761 KB |
8359 | }, |
8360 | { | |
8361 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
7eddabff | 8362 | PCI_VENDOR_ID_ADAPTEC2, 0x1201) |
6c223761 KB |
8363 | }, |
8364 | { | |
8365 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
7eddabff | 8366 | PCI_VENDOR_ID_ADAPTEC2, 0x1202) |
6c223761 KB |
8367 | }, |
8368 | { | |
8369 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
7eddabff | 8370 | PCI_VENDOR_ID_ADAPTEC2, 0x1280) |
6c223761 KB |
8371 | }, |
8372 | { | |
8373 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
7eddabff | 8374 | PCI_VENDOR_ID_ADAPTEC2, 0x1281) |
6c223761 | 8375 | }, |
b0f9408b KB |
8376 | { |
8377 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8378 | PCI_VENDOR_ID_ADAPTEC2, 0x1282) | |
8379 | }, | |
6c223761 KB |
8380 | { |
8381 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
7eddabff | 8382 | PCI_VENDOR_ID_ADAPTEC2, 0x1300) |
6c223761 KB |
8383 | }, |
8384 | { | |
8385 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
7eddabff | 8386 | PCI_VENDOR_ID_ADAPTEC2, 0x1301) |
6c223761 | 8387 | }, |
bd809e8d KB |
8388 | { |
8389 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8390 | PCI_VENDOR_ID_ADAPTEC2, 0x1302) | |
8391 | }, | |
8392 | { | |
8393 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8394 | PCI_VENDOR_ID_ADAPTEC2, 0x1303) | |
8395 | }, | |
6c223761 KB |
8396 | { |
8397 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
7eddabff KB |
8398 | PCI_VENDOR_ID_ADAPTEC2, 0x1380) |
8399 | }, | |
9f8d05fa KB |
8400 | { |
8401 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8402 | PCI_VENDOR_ID_ADVANTECH, 0x8312) | |
8403 | }, | |
55790064 KB |
8404 | { |
8405 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8406 | PCI_VENDOR_ID_DELL, 0x1fe0) | |
8407 | }, | |
7eddabff KB |
8408 | { |
8409 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8410 | PCI_VENDOR_ID_HP, 0x0600) | |
8411 | }, | |
8412 | { | |
8413 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8414 | PCI_VENDOR_ID_HP, 0x0601) | |
8415 | }, | |
8416 | { | |
8417 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8418 | PCI_VENDOR_ID_HP, 0x0602) | |
8419 | }, | |
8420 | { | |
8421 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8422 | PCI_VENDOR_ID_HP, 0x0603) | |
8423 | }, | |
8424 | { | |
8425 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
55790064 | 8426 | PCI_VENDOR_ID_HP, 0x0609) |
7eddabff KB |
8427 | }, |
8428 | { | |
8429 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8430 | PCI_VENDOR_ID_HP, 0x0650) | |
8431 | }, | |
8432 | { | |
8433 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8434 | PCI_VENDOR_ID_HP, 0x0651) | |
8435 | }, | |
8436 | { | |
8437 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8438 | PCI_VENDOR_ID_HP, 0x0652) | |
8439 | }, | |
8440 | { | |
8441 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8442 | PCI_VENDOR_ID_HP, 0x0653) | |
8443 | }, | |
8444 | { | |
8445 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8446 | PCI_VENDOR_ID_HP, 0x0654) | |
8447 | }, | |
8448 | { | |
8449 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8450 | PCI_VENDOR_ID_HP, 0x0655) | |
8451 | }, | |
7eddabff KB |
8452 | { |
8453 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8454 | PCI_VENDOR_ID_HP, 0x0700) | |
8455 | }, | |
8456 | { | |
8457 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8458 | PCI_VENDOR_ID_HP, 0x0701) | |
6c223761 KB |
8459 | }, |
8460 | { | |
8461 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8462 | PCI_VENDOR_ID_HP, 0x1001) | |
8463 | }, | |
8464 | { | |
8465 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8466 | PCI_VENDOR_ID_HP, 0x1100) | |
8467 | }, | |
8468 | { | |
8469 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8470 | PCI_VENDOR_ID_HP, 0x1101) | |
8471 | }, | |
8bdb3b9c GW |
8472 | { |
8473 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8474 | 0x1d8d, 0x0800) | |
8475 | }, | |
8476 | { | |
8477 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8478 | 0x1d8d, 0x0908) | |
8479 | }, | |
8480 | { | |
8481 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8482 | 0x1d8d, 0x0806) | |
8483 | }, | |
8484 | { | |
8485 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8486 | 0x1d8d, 0x0916) | |
8487 | }, | |
71ecc60d GW |
8488 | { |
8489 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8490 | PCI_VENDOR_ID_GIGABYTE, 0x1000) | |
8491 | }, | |
6c223761 KB |
8492 | { |
8493 | PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, | |
8494 | PCI_ANY_ID, PCI_ANY_ID) | |
8495 | }, | |
8496 | { 0 } | |
8497 | }; | |
8498 | ||
8499 | MODULE_DEVICE_TABLE(pci, pqi_pci_id_table); | |
8500 | ||
8501 | static struct pci_driver pqi_pci_driver = { | |
8502 | .name = DRIVER_NAME_SHORT, | |
8503 | .id_table = pqi_pci_id_table, | |
8504 | .probe = pqi_pci_probe, | |
8505 | .remove = pqi_pci_remove, | |
8506 | .shutdown = pqi_shutdown, | |
061ef06a KB |
8507 | #if defined(CONFIG_PM) |
8508 | .suspend = pqi_suspend, | |
8509 | .resume = pqi_resume, | |
8510 | #endif | |
6c223761 KB |
8511 | }; |
8512 | ||
8513 | static int __init pqi_init(void) | |
8514 | { | |
8515 | int rc; | |
8516 | ||
8517 | pr_info(DRIVER_NAME "\n"); | |
8518 | ||
8519 | pqi_sas_transport_template = | |
8520 | sas_attach_transport(&pqi_sas_transport_functions); | |
8521 | if (!pqi_sas_transport_template) | |
8522 | return -ENODEV; | |
8523 | ||
3c50976f KB |
8524 | pqi_process_module_params(); |
8525 | ||
6c223761 KB |
8526 | rc = pci_register_driver(&pqi_pci_driver); |
8527 | if (rc) | |
8528 | sas_release_transport(pqi_sas_transport_template); | |
8529 | ||
8530 | return rc; | |
8531 | } | |
8532 | ||
8533 | static void __exit pqi_cleanup(void) | |
8534 | { | |
8535 | pci_unregister_driver(&pqi_pci_driver); | |
8536 | sas_release_transport(pqi_sas_transport_template); | |
8537 | } | |
8538 | ||
8539 | module_init(pqi_init); | |
8540 | module_exit(pqi_cleanup); | |
8541 | ||
8542 | static void __attribute__((unused)) verify_structures(void) | |
8543 | { | |
8544 | BUILD_BUG_ON(offsetof(struct pqi_ctrl_registers, | |
8545 | sis_host_to_ctrl_doorbell) != 0x20); | |
8546 | BUILD_BUG_ON(offsetof(struct pqi_ctrl_registers, | |
8547 | sis_interrupt_mask) != 0x34); | |
8548 | BUILD_BUG_ON(offsetof(struct pqi_ctrl_registers, | |
8549 | sis_ctrl_to_host_doorbell) != 0x9c); | |
8550 | BUILD_BUG_ON(offsetof(struct pqi_ctrl_registers, | |
8551 | sis_ctrl_to_host_doorbell_clear) != 0xa0); | |
ff6abb73 KB |
8552 | BUILD_BUG_ON(offsetof(struct pqi_ctrl_registers, |
8553 | sis_driver_scratch) != 0xb0); | |
6c223761 KB |
8554 | BUILD_BUG_ON(offsetof(struct pqi_ctrl_registers, |
8555 | sis_firmware_status) != 0xbc); | |
8556 | BUILD_BUG_ON(offsetof(struct pqi_ctrl_registers, | |
8557 | sis_mailbox) != 0x1000); | |
8558 | BUILD_BUG_ON(offsetof(struct pqi_ctrl_registers, | |
8559 | pqi_registers) != 0x4000); | |
8560 | ||
8561 | BUILD_BUG_ON(offsetof(struct pqi_iu_header, | |
8562 | iu_type) != 0x0); | |
8563 | BUILD_BUG_ON(offsetof(struct pqi_iu_header, | |
8564 | iu_length) != 0x2); | |
8565 | BUILD_BUG_ON(offsetof(struct pqi_iu_header, | |
8566 | response_queue_id) != 0x4); | |
8567 | BUILD_BUG_ON(offsetof(struct pqi_iu_header, | |
8568 | work_area) != 0x6); | |
8569 | BUILD_BUG_ON(sizeof(struct pqi_iu_header) != 0x8); | |
8570 | ||
8571 | BUILD_BUG_ON(offsetof(struct pqi_aio_error_info, | |
8572 | status) != 0x0); | |
8573 | BUILD_BUG_ON(offsetof(struct pqi_aio_error_info, | |
8574 | service_response) != 0x1); | |
8575 | BUILD_BUG_ON(offsetof(struct pqi_aio_error_info, | |
8576 | data_present) != 0x2); | |
8577 | BUILD_BUG_ON(offsetof(struct pqi_aio_error_info, | |
8578 | reserved) != 0x3); | |
8579 | BUILD_BUG_ON(offsetof(struct pqi_aio_error_info, | |
8580 | residual_count) != 0x4); | |
8581 | BUILD_BUG_ON(offsetof(struct pqi_aio_error_info, | |
8582 | data_length) != 0x8); | |
8583 | BUILD_BUG_ON(offsetof(struct pqi_aio_error_info, | |
8584 | reserved1) != 0xa); | |
8585 | BUILD_BUG_ON(offsetof(struct pqi_aio_error_info, | |
8586 | data) != 0xc); | |
8587 | BUILD_BUG_ON(sizeof(struct pqi_aio_error_info) != 0x10c); | |
8588 | ||
8589 | BUILD_BUG_ON(offsetof(struct pqi_raid_error_info, | |
8590 | data_in_result) != 0x0); | |
8591 | BUILD_BUG_ON(offsetof(struct pqi_raid_error_info, | |
8592 | data_out_result) != 0x1); | |
8593 | BUILD_BUG_ON(offsetof(struct pqi_raid_error_info, | |
8594 | reserved) != 0x2); | |
8595 | BUILD_BUG_ON(offsetof(struct pqi_raid_error_info, | |
8596 | status) != 0x5); | |
8597 | BUILD_BUG_ON(offsetof(struct pqi_raid_error_info, | |
8598 | status_qualifier) != 0x6); | |
8599 | BUILD_BUG_ON(offsetof(struct pqi_raid_error_info, | |
8600 | sense_data_length) != 0x8); | |
8601 | BUILD_BUG_ON(offsetof(struct pqi_raid_error_info, | |
8602 | response_data_length) != 0xa); | |
8603 | BUILD_BUG_ON(offsetof(struct pqi_raid_error_info, | |
8604 | data_in_transferred) != 0xc); | |
8605 | BUILD_BUG_ON(offsetof(struct pqi_raid_error_info, | |
8606 | data_out_transferred) != 0x10); | |
8607 | BUILD_BUG_ON(offsetof(struct pqi_raid_error_info, | |
8608 | data) != 0x14); | |
8609 | BUILD_BUG_ON(sizeof(struct pqi_raid_error_info) != 0x114); | |
8610 | ||
8611 | BUILD_BUG_ON(offsetof(struct pqi_device_registers, | |
8612 | signature) != 0x0); | |
8613 | BUILD_BUG_ON(offsetof(struct pqi_device_registers, | |
8614 | function_and_status_code) != 0x8); | |
8615 | BUILD_BUG_ON(offsetof(struct pqi_device_registers, | |
8616 | max_admin_iq_elements) != 0x10); | |
8617 | BUILD_BUG_ON(offsetof(struct pqi_device_registers, | |
8618 | max_admin_oq_elements) != 0x11); | |
8619 | BUILD_BUG_ON(offsetof(struct pqi_device_registers, | |
8620 | admin_iq_element_length) != 0x12); | |
8621 | BUILD_BUG_ON(offsetof(struct pqi_device_registers, | |
8622 | admin_oq_element_length) != 0x13); | |
8623 | BUILD_BUG_ON(offsetof(struct pqi_device_registers, | |
8624 | max_reset_timeout) != 0x14); | |
8625 | BUILD_BUG_ON(offsetof(struct pqi_device_registers, | |
8626 | legacy_intx_status) != 0x18); | |
8627 | BUILD_BUG_ON(offsetof(struct pqi_device_registers, | |
8628 | legacy_intx_mask_set) != 0x1c); | |
8629 | BUILD_BUG_ON(offsetof(struct pqi_device_registers, | |
8630 | legacy_intx_mask_clear) != 0x20); | |
8631 | BUILD_BUG_ON(offsetof(struct pqi_device_registers, | |
8632 | device_status) != 0x40); | |
8633 | BUILD_BUG_ON(offsetof(struct pqi_device_registers, | |
8634 | admin_iq_pi_offset) != 0x48); | |
8635 | BUILD_BUG_ON(offsetof(struct pqi_device_registers, | |
8636 | admin_oq_ci_offset) != 0x50); | |
8637 | BUILD_BUG_ON(offsetof(struct pqi_device_registers, | |
8638 | admin_iq_element_array_addr) != 0x58); | |
8639 | BUILD_BUG_ON(offsetof(struct pqi_device_registers, | |
8640 | admin_oq_element_array_addr) != 0x60); | |
8641 | BUILD_BUG_ON(offsetof(struct pqi_device_registers, | |
8642 | admin_iq_ci_addr) != 0x68); | |
8643 | BUILD_BUG_ON(offsetof(struct pqi_device_registers, | |
8644 | admin_oq_pi_addr) != 0x70); | |
8645 | BUILD_BUG_ON(offsetof(struct pqi_device_registers, | |
8646 | admin_iq_num_elements) != 0x78); | |
8647 | BUILD_BUG_ON(offsetof(struct pqi_device_registers, | |
8648 | admin_oq_num_elements) != 0x79); | |
8649 | BUILD_BUG_ON(offsetof(struct pqi_device_registers, | |
8650 | admin_queue_int_msg_num) != 0x7a); | |
8651 | BUILD_BUG_ON(offsetof(struct pqi_device_registers, | |
8652 | device_error) != 0x80); | |
8653 | BUILD_BUG_ON(offsetof(struct pqi_device_registers, | |
8654 | error_details) != 0x88); | |
8655 | BUILD_BUG_ON(offsetof(struct pqi_device_registers, | |
8656 | device_reset) != 0x90); | |
8657 | BUILD_BUG_ON(offsetof(struct pqi_device_registers, | |
8658 | power_action) != 0x94); | |
8659 | BUILD_BUG_ON(sizeof(struct pqi_device_registers) != 0x100); | |
8660 | ||
8661 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_request, | |
8662 | header.iu_type) != 0); | |
8663 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_request, | |
8664 | header.iu_length) != 2); | |
8665 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_request, | |
8666 | header.work_area) != 6); | |
8667 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_request, | |
8668 | request_id) != 8); | |
8669 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_request, | |
8670 | function_code) != 10); | |
8671 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_request, | |
8672 | data.report_device_capability.buffer_length) != 44); | |
8673 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_request, | |
8674 | data.report_device_capability.sg_descriptor) != 48); | |
8675 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_request, | |
8676 | data.create_operational_iq.queue_id) != 12); | |
8677 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_request, | |
8678 | data.create_operational_iq.element_array_addr) != 16); | |
8679 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_request, | |
8680 | data.create_operational_iq.ci_addr) != 24); | |
8681 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_request, | |
8682 | data.create_operational_iq.num_elements) != 32); | |
8683 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_request, | |
8684 | data.create_operational_iq.element_length) != 34); | |
8685 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_request, | |
8686 | data.create_operational_iq.queue_protocol) != 36); | |
8687 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_request, | |
8688 | data.create_operational_oq.queue_id) != 12); | |
8689 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_request, | |
8690 | data.create_operational_oq.element_array_addr) != 16); | |
8691 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_request, | |
8692 | data.create_operational_oq.pi_addr) != 24); | |
8693 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_request, | |
8694 | data.create_operational_oq.num_elements) != 32); | |
8695 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_request, | |
8696 | data.create_operational_oq.element_length) != 34); | |
8697 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_request, | |
8698 | data.create_operational_oq.queue_protocol) != 36); | |
8699 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_request, | |
8700 | data.create_operational_oq.int_msg_num) != 40); | |
8701 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_request, | |
8702 | data.create_operational_oq.coalescing_count) != 42); | |
8703 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_request, | |
8704 | data.create_operational_oq.min_coalescing_time) != 44); | |
8705 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_request, | |
8706 | data.create_operational_oq.max_coalescing_time) != 48); | |
8707 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_request, | |
8708 | data.delete_operational_queue.queue_id) != 12); | |
8709 | BUILD_BUG_ON(sizeof(struct pqi_general_admin_request) != 64); | |
c593642c | 8710 | BUILD_BUG_ON(sizeof_field(struct pqi_general_admin_request, |
6c223761 | 8711 | data.create_operational_iq) != 64 - 11); |
c593642c | 8712 | BUILD_BUG_ON(sizeof_field(struct pqi_general_admin_request, |
6c223761 | 8713 | data.create_operational_oq) != 64 - 11); |
c593642c | 8714 | BUILD_BUG_ON(sizeof_field(struct pqi_general_admin_request, |
6c223761 KB |
8715 | data.delete_operational_queue) != 64 - 11); |
8716 | ||
8717 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_response, | |
8718 | header.iu_type) != 0); | |
8719 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_response, | |
8720 | header.iu_length) != 2); | |
8721 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_response, | |
8722 | header.work_area) != 6); | |
8723 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_response, | |
8724 | request_id) != 8); | |
8725 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_response, | |
8726 | function_code) != 10); | |
8727 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_response, | |
8728 | status) != 11); | |
8729 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_response, | |
8730 | data.create_operational_iq.status_descriptor) != 12); | |
8731 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_response, | |
8732 | data.create_operational_iq.iq_pi_offset) != 16); | |
8733 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_response, | |
8734 | data.create_operational_oq.status_descriptor) != 12); | |
8735 | BUILD_BUG_ON(offsetof(struct pqi_general_admin_response, | |
8736 | data.create_operational_oq.oq_ci_offset) != 16); | |
8737 | BUILD_BUG_ON(sizeof(struct pqi_general_admin_response) != 64); | |
8738 | ||
8739 | BUILD_BUG_ON(offsetof(struct pqi_raid_path_request, | |
8740 | header.iu_type) != 0); | |
8741 | BUILD_BUG_ON(offsetof(struct pqi_raid_path_request, | |
8742 | header.iu_length) != 2); | |
8743 | BUILD_BUG_ON(offsetof(struct pqi_raid_path_request, | |
8744 | header.response_queue_id) != 4); | |
8745 | BUILD_BUG_ON(offsetof(struct pqi_raid_path_request, | |
8746 | header.work_area) != 6); | |
8747 | BUILD_BUG_ON(offsetof(struct pqi_raid_path_request, | |
8748 | request_id) != 8); | |
8749 | BUILD_BUG_ON(offsetof(struct pqi_raid_path_request, | |
8750 | nexus_id) != 10); | |
8751 | BUILD_BUG_ON(offsetof(struct pqi_raid_path_request, | |
8752 | buffer_length) != 12); | |
8753 | BUILD_BUG_ON(offsetof(struct pqi_raid_path_request, | |
8754 | lun_number) != 16); | |
8755 | BUILD_BUG_ON(offsetof(struct pqi_raid_path_request, | |
8756 | protocol_specific) != 24); | |
8757 | BUILD_BUG_ON(offsetof(struct pqi_raid_path_request, | |
8758 | error_index) != 27); | |
8759 | BUILD_BUG_ON(offsetof(struct pqi_raid_path_request, | |
8760 | cdb) != 32); | |
21432010 | 8761 | BUILD_BUG_ON(offsetof(struct pqi_raid_path_request, |
8762 | timeout) != 60); | |
6c223761 KB |
8763 | BUILD_BUG_ON(offsetof(struct pqi_raid_path_request, |
8764 | sg_descriptors) != 64); | |
8765 | BUILD_BUG_ON(sizeof(struct pqi_raid_path_request) != | |
8766 | PQI_OPERATIONAL_IQ_ELEMENT_LENGTH); | |
8767 | ||
8768 | BUILD_BUG_ON(offsetof(struct pqi_aio_path_request, | |
8769 | header.iu_type) != 0); | |
8770 | BUILD_BUG_ON(offsetof(struct pqi_aio_path_request, | |
8771 | header.iu_length) != 2); | |
8772 | BUILD_BUG_ON(offsetof(struct pqi_aio_path_request, | |
8773 | header.response_queue_id) != 4); | |
8774 | BUILD_BUG_ON(offsetof(struct pqi_aio_path_request, | |
8775 | header.work_area) != 6); | |
8776 | BUILD_BUG_ON(offsetof(struct pqi_aio_path_request, | |
8777 | request_id) != 8); | |
8778 | BUILD_BUG_ON(offsetof(struct pqi_aio_path_request, | |
8779 | nexus_id) != 12); | |
8780 | BUILD_BUG_ON(offsetof(struct pqi_aio_path_request, | |
8781 | buffer_length) != 16); | |
8782 | BUILD_BUG_ON(offsetof(struct pqi_aio_path_request, | |
8783 | data_encryption_key_index) != 22); | |
8784 | BUILD_BUG_ON(offsetof(struct pqi_aio_path_request, | |
8785 | encrypt_tweak_lower) != 24); | |
8786 | BUILD_BUG_ON(offsetof(struct pqi_aio_path_request, | |
8787 | encrypt_tweak_upper) != 28); | |
8788 | BUILD_BUG_ON(offsetof(struct pqi_aio_path_request, | |
8789 | cdb) != 32); | |
8790 | BUILD_BUG_ON(offsetof(struct pqi_aio_path_request, | |
8791 | error_index) != 48); | |
8792 | BUILD_BUG_ON(offsetof(struct pqi_aio_path_request, | |
8793 | num_sg_descriptors) != 50); | |
8794 | BUILD_BUG_ON(offsetof(struct pqi_aio_path_request, | |
8795 | cdb_length) != 51); | |
8796 | BUILD_BUG_ON(offsetof(struct pqi_aio_path_request, | |
8797 | lun_number) != 52); | |
8798 | BUILD_BUG_ON(offsetof(struct pqi_aio_path_request, | |
8799 | sg_descriptors) != 64); | |
8800 | BUILD_BUG_ON(sizeof(struct pqi_aio_path_request) != | |
8801 | PQI_OPERATIONAL_IQ_ELEMENT_LENGTH); | |
8802 | ||
8803 | BUILD_BUG_ON(offsetof(struct pqi_io_response, | |
8804 | header.iu_type) != 0); | |
8805 | BUILD_BUG_ON(offsetof(struct pqi_io_response, | |
8806 | header.iu_length) != 2); | |
8807 | BUILD_BUG_ON(offsetof(struct pqi_io_response, | |
8808 | request_id) != 8); | |
8809 | BUILD_BUG_ON(offsetof(struct pqi_io_response, | |
8810 | error_index) != 10); | |
8811 | ||
8812 | BUILD_BUG_ON(offsetof(struct pqi_general_management_request, | |
8813 | header.iu_type) != 0); | |
8814 | BUILD_BUG_ON(offsetof(struct pqi_general_management_request, | |
8815 | header.iu_length) != 2); | |
8816 | BUILD_BUG_ON(offsetof(struct pqi_general_management_request, | |
8817 | header.response_queue_id) != 4); | |
8818 | BUILD_BUG_ON(offsetof(struct pqi_general_management_request, | |
8819 | request_id) != 8); | |
8820 | BUILD_BUG_ON(offsetof(struct pqi_general_management_request, | |
8821 | data.report_event_configuration.buffer_length) != 12); | |
8822 | BUILD_BUG_ON(offsetof(struct pqi_general_management_request, | |
8823 | data.report_event_configuration.sg_descriptors) != 16); | |
8824 | BUILD_BUG_ON(offsetof(struct pqi_general_management_request, | |
8825 | data.set_event_configuration.global_event_oq_id) != 10); | |
8826 | BUILD_BUG_ON(offsetof(struct pqi_general_management_request, | |
8827 | data.set_event_configuration.buffer_length) != 12); | |
8828 | BUILD_BUG_ON(offsetof(struct pqi_general_management_request, | |
8829 | data.set_event_configuration.sg_descriptors) != 16); | |
8830 | ||
8831 | BUILD_BUG_ON(offsetof(struct pqi_iu_layer_descriptor, | |
8832 | max_inbound_iu_length) != 6); | |
8833 | BUILD_BUG_ON(offsetof(struct pqi_iu_layer_descriptor, | |
8834 | max_outbound_iu_length) != 14); | |
8835 | BUILD_BUG_ON(sizeof(struct pqi_iu_layer_descriptor) != 16); | |
8836 | ||
8837 | BUILD_BUG_ON(offsetof(struct pqi_device_capability, | |
8838 | data_length) != 0); | |
8839 | BUILD_BUG_ON(offsetof(struct pqi_device_capability, | |
8840 | iq_arbitration_priority_support_bitmask) != 8); | |
8841 | BUILD_BUG_ON(offsetof(struct pqi_device_capability, | |
8842 | maximum_aw_a) != 9); | |
8843 | BUILD_BUG_ON(offsetof(struct pqi_device_capability, | |
8844 | maximum_aw_b) != 10); | |
8845 | BUILD_BUG_ON(offsetof(struct pqi_device_capability, | |
8846 | maximum_aw_c) != 11); | |
8847 | BUILD_BUG_ON(offsetof(struct pqi_device_capability, | |
8848 | max_inbound_queues) != 16); | |
8849 | BUILD_BUG_ON(offsetof(struct pqi_device_capability, | |
8850 | max_elements_per_iq) != 18); | |
8851 | BUILD_BUG_ON(offsetof(struct pqi_device_capability, | |
8852 | max_iq_element_length) != 24); | |
8853 | BUILD_BUG_ON(offsetof(struct pqi_device_capability, | |
8854 | min_iq_element_length) != 26); | |
8855 | BUILD_BUG_ON(offsetof(struct pqi_device_capability, | |
8856 | max_outbound_queues) != 30); | |
8857 | BUILD_BUG_ON(offsetof(struct pqi_device_capability, | |
8858 | max_elements_per_oq) != 32); | |
8859 | BUILD_BUG_ON(offsetof(struct pqi_device_capability, | |
8860 | intr_coalescing_time_granularity) != 34); | |
8861 | BUILD_BUG_ON(offsetof(struct pqi_device_capability, | |
8862 | max_oq_element_length) != 36); | |
8863 | BUILD_BUG_ON(offsetof(struct pqi_device_capability, | |
8864 | min_oq_element_length) != 38); | |
8865 | BUILD_BUG_ON(offsetof(struct pqi_device_capability, | |
8866 | iu_layer_descriptors) != 64); | |
8867 | BUILD_BUG_ON(sizeof(struct pqi_device_capability) != 576); | |
8868 | ||
8869 | BUILD_BUG_ON(offsetof(struct pqi_event_descriptor, | |
8870 | event_type) != 0); | |
8871 | BUILD_BUG_ON(offsetof(struct pqi_event_descriptor, | |
8872 | oq_id) != 2); | |
8873 | BUILD_BUG_ON(sizeof(struct pqi_event_descriptor) != 4); | |
8874 | ||
8875 | BUILD_BUG_ON(offsetof(struct pqi_event_config, | |
8876 | num_event_descriptors) != 2); | |
8877 | BUILD_BUG_ON(offsetof(struct pqi_event_config, | |
8878 | descriptors) != 4); | |
8879 | ||
061ef06a KB |
8880 | BUILD_BUG_ON(PQI_NUM_SUPPORTED_EVENTS != |
8881 | ARRAY_SIZE(pqi_supported_event_types)); | |
8882 | ||
6c223761 KB |
8883 | BUILD_BUG_ON(offsetof(struct pqi_event_response, |
8884 | header.iu_type) != 0); | |
8885 | BUILD_BUG_ON(offsetof(struct pqi_event_response, | |
8886 | header.iu_length) != 2); | |
8887 | BUILD_BUG_ON(offsetof(struct pqi_event_response, | |
8888 | event_type) != 8); | |
8889 | BUILD_BUG_ON(offsetof(struct pqi_event_response, | |
8890 | event_id) != 10); | |
8891 | BUILD_BUG_ON(offsetof(struct pqi_event_response, | |
8892 | additional_event_id) != 12); | |
8893 | BUILD_BUG_ON(offsetof(struct pqi_event_response, | |
8894 | data) != 16); | |
8895 | BUILD_BUG_ON(sizeof(struct pqi_event_response) != 32); | |
8896 | ||
8897 | BUILD_BUG_ON(offsetof(struct pqi_event_acknowledge_request, | |
8898 | header.iu_type) != 0); | |
8899 | BUILD_BUG_ON(offsetof(struct pqi_event_acknowledge_request, | |
8900 | header.iu_length) != 2); | |
8901 | BUILD_BUG_ON(offsetof(struct pqi_event_acknowledge_request, | |
8902 | event_type) != 8); | |
8903 | BUILD_BUG_ON(offsetof(struct pqi_event_acknowledge_request, | |
8904 | event_id) != 10); | |
8905 | BUILD_BUG_ON(offsetof(struct pqi_event_acknowledge_request, | |
8906 | additional_event_id) != 12); | |
8907 | BUILD_BUG_ON(sizeof(struct pqi_event_acknowledge_request) != 16); | |
8908 | ||
8909 | BUILD_BUG_ON(offsetof(struct pqi_task_management_request, | |
8910 | header.iu_type) != 0); | |
8911 | BUILD_BUG_ON(offsetof(struct pqi_task_management_request, | |
8912 | header.iu_length) != 2); | |
8913 | BUILD_BUG_ON(offsetof(struct pqi_task_management_request, | |
8914 | request_id) != 8); | |
8915 | BUILD_BUG_ON(offsetof(struct pqi_task_management_request, | |
8916 | nexus_id) != 10); | |
8917 | BUILD_BUG_ON(offsetof(struct pqi_task_management_request, | |
c2922f17 MB |
8918 | timeout) != 14); |
8919 | BUILD_BUG_ON(offsetof(struct pqi_task_management_request, | |
6c223761 KB |
8920 | lun_number) != 16); |
8921 | BUILD_BUG_ON(offsetof(struct pqi_task_management_request, | |
8922 | protocol_specific) != 24); | |
8923 | BUILD_BUG_ON(offsetof(struct pqi_task_management_request, | |
8924 | outbound_queue_id_to_manage) != 26); | |
8925 | BUILD_BUG_ON(offsetof(struct pqi_task_management_request, | |
8926 | request_id_to_manage) != 28); | |
8927 | BUILD_BUG_ON(offsetof(struct pqi_task_management_request, | |
8928 | task_management_function) != 30); | |
8929 | BUILD_BUG_ON(sizeof(struct pqi_task_management_request) != 32); | |
8930 | ||
8931 | BUILD_BUG_ON(offsetof(struct pqi_task_management_response, | |
8932 | header.iu_type) != 0); | |
8933 | BUILD_BUG_ON(offsetof(struct pqi_task_management_response, | |
8934 | header.iu_length) != 2); | |
8935 | BUILD_BUG_ON(offsetof(struct pqi_task_management_response, | |
8936 | request_id) != 8); | |
8937 | BUILD_BUG_ON(offsetof(struct pqi_task_management_response, | |
8938 | nexus_id) != 10); | |
8939 | BUILD_BUG_ON(offsetof(struct pqi_task_management_response, | |
8940 | additional_response_info) != 12); | |
8941 | BUILD_BUG_ON(offsetof(struct pqi_task_management_response, | |
8942 | response_code) != 15); | |
8943 | BUILD_BUG_ON(sizeof(struct pqi_task_management_response) != 16); | |
8944 | ||
8945 | BUILD_BUG_ON(offsetof(struct bmic_identify_controller, | |
8946 | configured_logical_drive_count) != 0); | |
8947 | BUILD_BUG_ON(offsetof(struct bmic_identify_controller, | |
8948 | configuration_signature) != 1); | |
8949 | BUILD_BUG_ON(offsetof(struct bmic_identify_controller, | |
8950 | firmware_version) != 5); | |
8951 | BUILD_BUG_ON(offsetof(struct bmic_identify_controller, | |
8952 | extended_logical_unit_count) != 154); | |
8953 | BUILD_BUG_ON(offsetof(struct bmic_identify_controller, | |
8954 | firmware_build_number) != 190); | |
8955 | BUILD_BUG_ON(offsetof(struct bmic_identify_controller, | |
8956 | controller_mode) != 292); | |
8957 | ||
1be42f46 KB |
8958 | BUILD_BUG_ON(offsetof(struct bmic_identify_physical_device, |
8959 | phys_bay_in_box) != 115); | |
8960 | BUILD_BUG_ON(offsetof(struct bmic_identify_physical_device, | |
8961 | device_type) != 120); | |
8962 | BUILD_BUG_ON(offsetof(struct bmic_identify_physical_device, | |
8963 | redundant_path_present_map) != 1736); | |
8964 | BUILD_BUG_ON(offsetof(struct bmic_identify_physical_device, | |
8965 | active_path_number) != 1738); | |
8966 | BUILD_BUG_ON(offsetof(struct bmic_identify_physical_device, | |
8967 | alternate_paths_phys_connector) != 1739); | |
8968 | BUILD_BUG_ON(offsetof(struct bmic_identify_physical_device, | |
8969 | alternate_paths_phys_box_on_port) != 1755); | |
8970 | BUILD_BUG_ON(offsetof(struct bmic_identify_physical_device, | |
8971 | current_queue_depth_limit) != 1796); | |
8972 | BUILD_BUG_ON(sizeof(struct bmic_identify_physical_device) != 2560); | |
8973 | ||
6c223761 KB |
8974 | BUILD_BUG_ON(PQI_ADMIN_IQ_NUM_ELEMENTS > 255); |
8975 | BUILD_BUG_ON(PQI_ADMIN_OQ_NUM_ELEMENTS > 255); | |
8976 | BUILD_BUG_ON(PQI_ADMIN_IQ_ELEMENT_LENGTH % | |
8977 | PQI_QUEUE_ELEMENT_LENGTH_ALIGNMENT != 0); | |
8978 | BUILD_BUG_ON(PQI_ADMIN_OQ_ELEMENT_LENGTH % | |
8979 | PQI_QUEUE_ELEMENT_LENGTH_ALIGNMENT != 0); | |
8980 | BUILD_BUG_ON(PQI_OPERATIONAL_IQ_ELEMENT_LENGTH > 1048560); | |
8981 | BUILD_BUG_ON(PQI_OPERATIONAL_IQ_ELEMENT_LENGTH % | |
8982 | PQI_QUEUE_ELEMENT_LENGTH_ALIGNMENT != 0); | |
8983 | BUILD_BUG_ON(PQI_OPERATIONAL_OQ_ELEMENT_LENGTH > 1048560); | |
8984 | BUILD_BUG_ON(PQI_OPERATIONAL_OQ_ELEMENT_LENGTH % | |
8985 | PQI_QUEUE_ELEMENT_LENGTH_ALIGNMENT != 0); | |
8986 | ||
8987 | BUILD_BUG_ON(PQI_RESERVED_IO_SLOTS >= PQI_MAX_OUTSTANDING_REQUESTS); | |
d727a776 KB |
8988 | BUILD_BUG_ON(PQI_RESERVED_IO_SLOTS >= |
8989 | PQI_MAX_OUTSTANDING_REQUESTS_KDUMP); | |
6c223761 | 8990 | } |