Commit | Line | Data |
---|---|---|
f92363d1 SR |
1 | /* |
2 | * Scsi Host Layer for MPT (Message Passing Technology) based controllers | |
3 | * | |
4 | * This code is based on drivers/scsi/mpt3sas/mpt3sas_scsih.c | |
a4ffce0d | 5 | * Copyright (C) 2012-2014 LSI Corporation |
a03bd153 SR |
6 | * Copyright (C) 2013-2014 Avago Technologies |
7 | * (mailto: MPT-FusionLinux.pdl@avagotech.com) | |
f92363d1 SR |
8 | * |
9 | * This program is free software; you can redistribute it and/or | |
10 | * modify it under the terms of the GNU General Public License | |
11 | * as published by the Free Software Foundation; either version 2 | |
12 | * of the License, or (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * NO WARRANTY | |
20 | * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR | |
21 | * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT | |
22 | * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, | |
23 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is | |
24 | * solely responsible for determining the appropriateness of using and | |
25 | * distributing the Program and assumes all risks associated with its | |
26 | * exercise of rights under this Agreement, including but not limited to | |
27 | * the risks and costs of program errors, damage to or loss of data, | |
28 | * programs or equipment, and unavailability or interruption of operations. | |
29 | ||
30 | * DISCLAIMER OF LIABILITY | |
31 | * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY | |
32 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
33 | * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND | |
34 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | |
35 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
36 | * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED | |
37 | * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES | |
38 | ||
39 | * You should have received a copy of the GNU General Public License | |
40 | * along with this program; if not, write to the Free Software | |
41 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | |
42 | * USA. | |
43 | */ | |
44 | ||
f92363d1 SR |
45 | #include <linux/module.h> |
46 | #include <linux/kernel.h> | |
47 | #include <linux/init.h> | |
48 | #include <linux/errno.h> | |
49 | #include <linux/blkdev.h> | |
50 | #include <linux/sched.h> | |
51 | #include <linux/workqueue.h> | |
52 | #include <linux/delay.h> | |
53 | #include <linux/pci.h> | |
54 | #include <linux/interrupt.h> | |
55 | #include <linux/aer.h> | |
56 | #include <linux/raid_class.h> | |
7786ab6a | 57 | #include <asm/unaligned.h> |
f92363d1 SR |
58 | |
59 | #include "mpt3sas_base.h" | |
60 | ||
f92363d1 SR |
61 | #define RAID_CHANNEL 1 |
62 | /* forward proto's */ | |
63 | static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc, | |
64 | struct _sas_node *sas_expander); | |
65 | static void _firmware_event_work(struct work_struct *work); | |
66 | ||
67 | static void _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc, | |
68 | struct _sas_device *sas_device); | |
69 | static int _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, | |
70 | u8 retry_count, u8 is_pd); | |
71 | ||
72 | static u8 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid); | |
73 | ||
7786ab6a SR |
74 | #ifdef SCSI_MPT2SAS |
75 | static void _scsih_disable_ddio(struct MPT3SAS_ADAPTER *ioc); | |
76 | static u8 _scsih_get_num_volumes(struct MPT3SAS_ADAPTER *ioc); | |
77 | static void | |
78 | _scsih_init_warpdrive_properties(struct MPT3SAS_ADAPTER *ioc, | |
79 | struct _raid_device *raid_device); | |
80 | static inline u8 | |
81 | _scsih_scsi_direct_io_get(struct MPT3SAS_ADAPTER *ioc, u16 smid); | |
82 | static inline void | |
83 | _scsih_scsi_direct_io_set(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 direct_io); | |
84 | static void | |
85 | _scsih_setup_direct_io(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, | |
86 | struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request, | |
87 | u16 smid); | |
88 | #endif | |
f92363d1 SR |
89 | |
90 | /* global parameters */ | |
91 | LIST_HEAD(mpt3sas_ioc_list); | |
d357e84d | 92 | char driver_name[MPT_NAME_LENGTH]; |
f92363d1 SR |
93 | |
94 | /* local parameters */ | |
95 | static u8 scsi_io_cb_idx = -1; | |
96 | static u8 tm_cb_idx = -1; | |
97 | static u8 ctl_cb_idx = -1; | |
98 | static u8 base_cb_idx = -1; | |
99 | static u8 port_enable_cb_idx = -1; | |
100 | static u8 transport_cb_idx = -1; | |
101 | static u8 scsih_cb_idx = -1; | |
102 | static u8 config_cb_idx = -1; | |
103 | static int mpt_ids; | |
104 | ||
105 | static u8 tm_tr_cb_idx = -1 ; | |
106 | static u8 tm_tr_volume_cb_idx = -1 ; | |
107 | static u8 tm_sas_control_cb_idx = -1; | |
108 | ||
109 | /* command line options */ | |
110 | static u32 logging_level; | |
111 | MODULE_PARM_DESC(logging_level, | |
112 | " bits for enabling additional logging info (default=0)"); | |
113 | ||
114 | ||
115 | static ushort max_sectors = 0xFFFF; | |
116 | module_param(max_sectors, ushort, 0); | |
117 | MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767"); | |
118 | ||
119 | ||
120 | static int missing_delay[2] = {-1, -1}; | |
121 | module_param_array(missing_delay, int, NULL, 0); | |
122 | MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay"); | |
123 | ||
124 | /* scsi-mid layer global parmeter is max_report_luns, which is 511 */ | |
125 | #define MPT3SAS_MAX_LUN (16895) | |
1abf635d HR |
126 | static u64 max_lun = MPT3SAS_MAX_LUN; |
127 | module_param(max_lun, ullong, 0); | |
f92363d1 SR |
128 | MODULE_PARM_DESC(max_lun, " max lun, default=16895 "); |
129 | ||
130 | ||
131 | ||
132 | ||
133 | /* diag_buffer_enable is bitwise | |
134 | * bit 0 set = TRACE | |
135 | * bit 1 set = SNAPSHOT | |
136 | * bit 2 set = EXTENDED | |
137 | * | |
138 | * Either bit can be set, or both | |
139 | */ | |
140 | static int diag_buffer_enable = -1; | |
141 | module_param(diag_buffer_enable, int, 0); | |
142 | MODULE_PARM_DESC(diag_buffer_enable, | |
143 | " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)"); | |
144 | static int disable_discovery = -1; | |
145 | module_param(disable_discovery, int, 0); | |
146 | MODULE_PARM_DESC(disable_discovery, " disable discovery "); | |
147 | ||
148 | ||
149 | /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */ | |
150 | static int prot_mask = -1; | |
151 | module_param(prot_mask, int, 0); | |
152 | MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 "); | |
153 | ||
154 | ||
155 | /* raid transport support */ | |
7497392a | 156 | struct raid_template *mpt3sas_raid_template; |
f92363d1 SR |
157 | |
158 | ||
159 | /** | |
160 | * struct sense_info - common structure for obtaining sense keys | |
161 | * @skey: sense key | |
162 | * @asc: additional sense code | |
163 | * @ascq: additional sense code qualifier | |
164 | */ | |
165 | struct sense_info { | |
166 | u8 skey; | |
167 | u8 asc; | |
168 | u8 ascq; | |
169 | }; | |
170 | ||
171 | #define MPT3SAS_PROCESS_TRIGGER_DIAG (0xFFFB) | |
0f624c39 | 172 | #define MPT3SAS_TURN_ON_PFA_LED (0xFFFC) |
f92363d1 SR |
173 | #define MPT3SAS_PORT_ENABLE_COMPLETE (0xFFFD) |
174 | #define MPT3SAS_ABRT_TASK_SET (0xFFFE) | |
175 | #define MPT3SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF) | |
176 | /** | |
177 | * struct fw_event_work - firmware event struct | |
178 | * @list: link list framework | |
179 | * @work: work object (ioc->fault_reset_work_q) | |
180 | * @cancel_pending_work: flag set during reset handling | |
181 | * @ioc: per adapter object | |
182 | * @device_handle: device handle | |
183 | * @VF_ID: virtual function id | |
184 | * @VP_ID: virtual port id | |
185 | * @ignore: flag meaning this event has been marked to ignore | |
186 | * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h | |
187 | * @event_data: reply event data payload follows | |
188 | * | |
189 | * This object stored on ioc->fw_event_list. | |
190 | */ | |
191 | struct fw_event_work { | |
192 | struct list_head list; | |
193 | struct work_struct work; | |
194 | u8 cancel_pending_work; | |
195 | struct delayed_work delayed_work; | |
196 | ||
197 | struct MPT3SAS_ADAPTER *ioc; | |
198 | u16 device_handle; | |
199 | u8 VF_ID; | |
200 | u8 VP_ID; | |
201 | u8 ignore; | |
202 | u16 event; | |
35b62362 | 203 | char event_data[0] __aligned(4); |
f92363d1 SR |
204 | }; |
205 | ||
f92363d1 SR |
206 | /** |
207 | * struct _scsi_io_transfer - scsi io transfer | |
208 | * @handle: sas device handle (assigned by firmware) | |
209 | * @is_raid: flag set for hidden raid components | |
210 | * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE, | |
211 | * @data_length: data transfer length | |
212 | * @data_dma: dma pointer to data | |
213 | * @sense: sense data | |
214 | * @lun: lun number | |
215 | * @cdb_length: cdb length | |
216 | * @cdb: cdb contents | |
217 | * @timeout: timeout for this command | |
218 | * @VF_ID: virtual function id | |
219 | * @VP_ID: virtual port id | |
220 | * @valid_reply: flag set for reply message | |
221 | * @sense_length: sense length | |
222 | * @ioc_status: ioc status | |
223 | * @scsi_state: scsi state | |
224 | * @scsi_status: scsi staus | |
225 | * @log_info: log information | |
226 | * @transfer_length: data length transfer when there is a reply message | |
227 | * | |
228 | * Used for sending internal scsi commands to devices within this module. | |
229 | * Refer to _scsi_send_scsi_io(). | |
230 | */ | |
231 | struct _scsi_io_transfer { | |
232 | u16 handle; | |
233 | u8 is_raid; | |
234 | enum dma_data_direction dir; | |
235 | u32 data_length; | |
236 | dma_addr_t data_dma; | |
237 | u8 sense[SCSI_SENSE_BUFFERSIZE]; | |
238 | u32 lun; | |
239 | u8 cdb_length; | |
240 | u8 cdb[32]; | |
241 | u8 timeout; | |
242 | u8 VF_ID; | |
243 | u8 VP_ID; | |
244 | u8 valid_reply; | |
245 | /* the following bits are only valid when 'valid_reply = 1' */ | |
246 | u32 sense_length; | |
247 | u16 ioc_status; | |
248 | u8 scsi_state; | |
249 | u8 scsi_status; | |
250 | u32 log_info; | |
251 | u32 transfer_length; | |
252 | }; | |
253 | ||
f92363d1 SR |
254 | /** |
255 | * _scsih_set_debug_level - global setting of ioc->logging_level. | |
256 | * | |
257 | * Note: The logging levels are defined in mpt3sas_debug.h. | |
258 | */ | |
259 | static int | |
260 | _scsih_set_debug_level(const char *val, struct kernel_param *kp) | |
261 | { | |
262 | int ret = param_set_int(val, kp); | |
263 | struct MPT3SAS_ADAPTER *ioc; | |
264 | ||
265 | if (ret) | |
266 | return ret; | |
267 | ||
268 | pr_info("setting logging_level(0x%08x)\n", logging_level); | |
269 | list_for_each_entry(ioc, &mpt3sas_ioc_list, list) | |
270 | ioc->logging_level = logging_level; | |
271 | return 0; | |
272 | } | |
273 | module_param_call(logging_level, _scsih_set_debug_level, param_get_int, | |
274 | &logging_level, 0644); | |
275 | ||
276 | /** | |
277 | * _scsih_srch_boot_sas_address - search based on sas_address | |
278 | * @sas_address: sas address | |
279 | * @boot_device: boot device object from bios page 2 | |
280 | * | |
281 | * Returns 1 when there's a match, 0 means no match. | |
282 | */ | |
283 | static inline int | |
284 | _scsih_srch_boot_sas_address(u64 sas_address, | |
285 | Mpi2BootDeviceSasWwid_t *boot_device) | |
286 | { | |
287 | return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0; | |
288 | } | |
289 | ||
290 | /** | |
291 | * _scsih_srch_boot_device_name - search based on device name | |
292 | * @device_name: device name specified in INDENTIFY fram | |
293 | * @boot_device: boot device object from bios page 2 | |
294 | * | |
295 | * Returns 1 when there's a match, 0 means no match. | |
296 | */ | |
297 | static inline int | |
298 | _scsih_srch_boot_device_name(u64 device_name, | |
299 | Mpi2BootDeviceDeviceName_t *boot_device) | |
300 | { | |
301 | return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0; | |
302 | } | |
303 | ||
304 | /** | |
305 | * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot | |
306 | * @enclosure_logical_id: enclosure logical id | |
307 | * @slot_number: slot number | |
308 | * @boot_device: boot device object from bios page 2 | |
309 | * | |
310 | * Returns 1 when there's a match, 0 means no match. | |
311 | */ | |
312 | static inline int | |
313 | _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number, | |
314 | Mpi2BootDeviceEnclosureSlot_t *boot_device) | |
315 | { | |
316 | return (enclosure_logical_id == le64_to_cpu(boot_device-> | |
317 | EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device-> | |
318 | SlotNumber)) ? 1 : 0; | |
319 | } | |
320 | ||
321 | /** | |
322 | * _scsih_is_boot_device - search for matching boot device. | |
323 | * @sas_address: sas address | |
324 | * @device_name: device name specified in INDENTIFY fram | |
325 | * @enclosure_logical_id: enclosure logical id | |
326 | * @slot_number: slot number | |
327 | * @form: specifies boot device form | |
328 | * @boot_device: boot device object from bios page 2 | |
329 | * | |
330 | * Returns 1 when there's a match, 0 means no match. | |
331 | */ | |
332 | static int | |
333 | _scsih_is_boot_device(u64 sas_address, u64 device_name, | |
334 | u64 enclosure_logical_id, u16 slot, u8 form, | |
335 | Mpi2BiosPage2BootDevice_t *boot_device) | |
336 | { | |
337 | int rc = 0; | |
338 | ||
339 | switch (form) { | |
340 | case MPI2_BIOSPAGE2_FORM_SAS_WWID: | |
341 | if (!sas_address) | |
342 | break; | |
343 | rc = _scsih_srch_boot_sas_address( | |
344 | sas_address, &boot_device->SasWwid); | |
345 | break; | |
346 | case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT: | |
347 | if (!enclosure_logical_id) | |
348 | break; | |
349 | rc = _scsih_srch_boot_encl_slot( | |
350 | enclosure_logical_id, | |
351 | slot, &boot_device->EnclosureSlot); | |
352 | break; | |
353 | case MPI2_BIOSPAGE2_FORM_DEVICE_NAME: | |
354 | if (!device_name) | |
355 | break; | |
356 | rc = _scsih_srch_boot_device_name( | |
357 | device_name, &boot_device->DeviceName); | |
358 | break; | |
359 | case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED: | |
360 | break; | |
361 | } | |
362 | ||
363 | return rc; | |
364 | } | |
365 | ||
366 | /** | |
367 | * _scsih_get_sas_address - set the sas_address for given device handle | |
368 | * @handle: device handle | |
369 | * @sas_address: sas address | |
370 | * | |
371 | * Returns 0 success, non-zero when failure | |
372 | */ | |
373 | static int | |
374 | _scsih_get_sas_address(struct MPT3SAS_ADAPTER *ioc, u16 handle, | |
375 | u64 *sas_address) | |
376 | { | |
377 | Mpi2SasDevicePage0_t sas_device_pg0; | |
378 | Mpi2ConfigReply_t mpi_reply; | |
379 | u32 ioc_status; | |
380 | ||
381 | *sas_address = 0; | |
382 | ||
383 | if (handle <= ioc->sas_hba.num_phys) { | |
384 | *sas_address = ioc->sas_hba.sas_address; | |
385 | return 0; | |
386 | } | |
387 | ||
388 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
389 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
390 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name, | |
391 | __FILE__, __LINE__, __func__); | |
392 | return -ENXIO; | |
393 | } | |
394 | ||
395 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
396 | if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { | |
397 | *sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | |
398 | return 0; | |
399 | } | |
400 | ||
401 | /* we hit this becuase the given parent handle doesn't exist */ | |
402 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) | |
403 | return -ENXIO; | |
404 | ||
405 | /* else error case */ | |
406 | pr_err(MPT3SAS_FMT | |
407 | "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n", | |
408 | ioc->name, handle, ioc_status, | |
409 | __FILE__, __LINE__, __func__); | |
410 | return -EIO; | |
411 | } | |
412 | ||
413 | /** | |
414 | * _scsih_determine_boot_device - determine boot device. | |
415 | * @ioc: per adapter object | |
416 | * @device: either sas_device or raid_device object | |
417 | * @is_raid: [flag] 1 = raid object, 0 = sas object | |
418 | * | |
419 | * Determines whether this device should be first reported device to | |
420 | * to scsi-ml or sas transport, this purpose is for persistent boot device. | |
421 | * There are primary, alternate, and current entries in bios page 2. The order | |
422 | * priority is primary, alternate, then current. This routine saves | |
423 | * the corresponding device object and is_raid flag in the ioc object. | |
424 | * The saved data to be used later in _scsih_probe_boot_devices(). | |
425 | */ | |
426 | static void | |
427 | _scsih_determine_boot_device(struct MPT3SAS_ADAPTER *ioc, | |
428 | void *device, u8 is_raid) | |
429 | { | |
430 | struct _sas_device *sas_device; | |
431 | struct _raid_device *raid_device; | |
432 | u64 sas_address; | |
433 | u64 device_name; | |
434 | u64 enclosure_logical_id; | |
435 | u16 slot; | |
436 | ||
437 | /* only process this function when driver loads */ | |
438 | if (!ioc->is_driver_loading) | |
439 | return; | |
440 | ||
441 | /* no Bios, return immediately */ | |
442 | if (!ioc->bios_pg3.BiosVersion) | |
443 | return; | |
444 | ||
445 | if (!is_raid) { | |
446 | sas_device = device; | |
447 | sas_address = sas_device->sas_address; | |
448 | device_name = sas_device->device_name; | |
449 | enclosure_logical_id = sas_device->enclosure_logical_id; | |
450 | slot = sas_device->slot; | |
451 | } else { | |
452 | raid_device = device; | |
453 | sas_address = raid_device->wwid; | |
454 | device_name = 0; | |
455 | enclosure_logical_id = 0; | |
456 | slot = 0; | |
457 | } | |
458 | ||
459 | if (!ioc->req_boot_device.device) { | |
460 | if (_scsih_is_boot_device(sas_address, device_name, | |
461 | enclosure_logical_id, slot, | |
462 | (ioc->bios_pg2.ReqBootDeviceForm & | |
463 | MPI2_BIOSPAGE2_FORM_MASK), | |
464 | &ioc->bios_pg2.RequestedBootDevice)) { | |
465 | dinitprintk(ioc, pr_info(MPT3SAS_FMT | |
466 | "%s: req_boot_device(0x%016llx)\n", | |
467 | ioc->name, __func__, | |
468 | (unsigned long long)sas_address)); | |
469 | ioc->req_boot_device.device = device; | |
470 | ioc->req_boot_device.is_raid = is_raid; | |
471 | } | |
472 | } | |
473 | ||
474 | if (!ioc->req_alt_boot_device.device) { | |
475 | if (_scsih_is_boot_device(sas_address, device_name, | |
476 | enclosure_logical_id, slot, | |
477 | (ioc->bios_pg2.ReqAltBootDeviceForm & | |
478 | MPI2_BIOSPAGE2_FORM_MASK), | |
479 | &ioc->bios_pg2.RequestedAltBootDevice)) { | |
480 | dinitprintk(ioc, pr_info(MPT3SAS_FMT | |
481 | "%s: req_alt_boot_device(0x%016llx)\n", | |
482 | ioc->name, __func__, | |
483 | (unsigned long long)sas_address)); | |
484 | ioc->req_alt_boot_device.device = device; | |
485 | ioc->req_alt_boot_device.is_raid = is_raid; | |
486 | } | |
487 | } | |
488 | ||
489 | if (!ioc->current_boot_device.device) { | |
490 | if (_scsih_is_boot_device(sas_address, device_name, | |
491 | enclosure_logical_id, slot, | |
492 | (ioc->bios_pg2.CurrentBootDeviceForm & | |
493 | MPI2_BIOSPAGE2_FORM_MASK), | |
494 | &ioc->bios_pg2.CurrentBootDevice)) { | |
495 | dinitprintk(ioc, pr_info(MPT3SAS_FMT | |
496 | "%s: current_boot_device(0x%016llx)\n", | |
497 | ioc->name, __func__, | |
498 | (unsigned long long)sas_address)); | |
499 | ioc->current_boot_device.device = device; | |
500 | ioc->current_boot_device.is_raid = is_raid; | |
501 | } | |
502 | } | |
503 | } | |
504 | ||
505 | /** | |
506 | * mpt3sas_scsih_sas_device_find_by_sas_address - sas device search | |
507 | * @ioc: per adapter object | |
508 | * @sas_address: sas address | |
509 | * Context: Calling function should acquire ioc->sas_device_lock | |
510 | * | |
511 | * This searches for sas_device based on sas_address, then return sas_device | |
512 | * object. | |
513 | */ | |
514 | struct _sas_device * | |
515 | mpt3sas_scsih_sas_device_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc, | |
516 | u64 sas_address) | |
517 | { | |
518 | struct _sas_device *sas_device; | |
519 | ||
520 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) | |
521 | if (sas_device->sas_address == sas_address) | |
522 | return sas_device; | |
523 | ||
524 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) | |
525 | if (sas_device->sas_address == sas_address) | |
526 | return sas_device; | |
527 | ||
528 | return NULL; | |
529 | } | |
530 | ||
531 | /** | |
532 | * _scsih_sas_device_find_by_handle - sas device search | |
533 | * @ioc: per adapter object | |
534 | * @handle: sas device handle (assigned by firmware) | |
535 | * Context: Calling function should acquire ioc->sas_device_lock | |
536 | * | |
537 | * This searches for sas_device based on sas_address, then return sas_device | |
538 | * object. | |
539 | */ | |
540 | static struct _sas_device * | |
541 | _scsih_sas_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
542 | { | |
543 | struct _sas_device *sas_device; | |
544 | ||
545 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) | |
546 | if (sas_device->handle == handle) | |
547 | return sas_device; | |
548 | ||
549 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) | |
550 | if (sas_device->handle == handle) | |
551 | return sas_device; | |
552 | ||
553 | return NULL; | |
554 | } | |
555 | ||
556 | /** | |
557 | * _scsih_sas_device_remove - remove sas_device from list. | |
558 | * @ioc: per adapter object | |
559 | * @sas_device: the sas_device object | |
560 | * Context: This function will acquire ioc->sas_device_lock. | |
561 | * | |
562 | * Removing object and freeing associated memory from the ioc->sas_device_list. | |
563 | */ | |
564 | static void | |
565 | _scsih_sas_device_remove(struct MPT3SAS_ADAPTER *ioc, | |
566 | struct _sas_device *sas_device) | |
567 | { | |
568 | unsigned long flags; | |
569 | ||
570 | if (!sas_device) | |
571 | return; | |
e6d45e3e SR |
572 | pr_info(MPT3SAS_FMT |
573 | "removing handle(0x%04x), sas_addr(0x%016llx)\n", | |
574 | ioc->name, sas_device->handle, | |
575 | (unsigned long long) sas_device->sas_address); | |
576 | ||
577 | if (sas_device->enclosure_handle != 0) | |
578 | pr_info(MPT3SAS_FMT | |
579 | "removing enclosure logical id(0x%016llx), slot(%d)\n", | |
580 | ioc->name, (unsigned long long) | |
581 | sas_device->enclosure_logical_id, sas_device->slot); | |
582 | ||
583 | if (sas_device->connector_name[0] != '\0') | |
584 | pr_info(MPT3SAS_FMT | |
585 | "removing enclosure level(0x%04x), connector name( %s)\n", | |
586 | ioc->name, sas_device->enclosure_level, | |
587 | sas_device->connector_name); | |
f92363d1 SR |
588 | |
589 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
590 | list_del(&sas_device->list); | |
591 | kfree(sas_device); | |
592 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
593 | } | |
594 | ||
595 | /** | |
596 | * _scsih_device_remove_by_handle - removing device object by handle | |
597 | * @ioc: per adapter object | |
598 | * @handle: device handle | |
599 | * | |
600 | * Return nothing. | |
601 | */ | |
602 | static void | |
603 | _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
604 | { | |
605 | struct _sas_device *sas_device; | |
606 | unsigned long flags; | |
607 | ||
608 | if (ioc->shost_recovery) | |
609 | return; | |
610 | ||
611 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
612 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); | |
613 | if (sas_device) | |
614 | list_del(&sas_device->list); | |
615 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
616 | if (sas_device) | |
617 | _scsih_remove_device(ioc, sas_device); | |
618 | } | |
619 | ||
620 | /** | |
621 | * mpt3sas_device_remove_by_sas_address - removing device object by sas address | |
622 | * @ioc: per adapter object | |
623 | * @sas_address: device sas_address | |
624 | * | |
625 | * Return nothing. | |
626 | */ | |
627 | void | |
628 | mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER *ioc, | |
629 | u64 sas_address) | |
630 | { | |
631 | struct _sas_device *sas_device; | |
632 | unsigned long flags; | |
633 | ||
634 | if (ioc->shost_recovery) | |
635 | return; | |
636 | ||
637 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
638 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, | |
639 | sas_address); | |
640 | if (sas_device) | |
641 | list_del(&sas_device->list); | |
642 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
643 | if (sas_device) | |
644 | _scsih_remove_device(ioc, sas_device); | |
645 | } | |
646 | ||
647 | /** | |
648 | * _scsih_sas_device_add - insert sas_device to the list. | |
649 | * @ioc: per adapter object | |
650 | * @sas_device: the sas_device object | |
651 | * Context: This function will acquire ioc->sas_device_lock. | |
652 | * | |
653 | * Adding new object to the ioc->sas_device_list. | |
654 | */ | |
655 | static void | |
656 | _scsih_sas_device_add(struct MPT3SAS_ADAPTER *ioc, | |
657 | struct _sas_device *sas_device) | |
658 | { | |
659 | unsigned long flags; | |
660 | ||
661 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
662 | "%s: handle(0x%04x), sas_addr(0x%016llx)\n", | |
663 | ioc->name, __func__, sas_device->handle, | |
664 | (unsigned long long)sas_device->sas_address)); | |
665 | ||
e6d45e3e SR |
666 | if (sas_device->enclosure_handle != 0) |
667 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
668 | "%s: enclosure logical id(0x%016llx), slot( %d)\n", | |
669 | ioc->name, __func__, (unsigned long long) | |
670 | sas_device->enclosure_logical_id, sas_device->slot)); | |
671 | ||
672 | if (sas_device->connector_name[0] != '\0') | |
673 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
674 | "%s: enclosure level(0x%04x), connector name( %s)\n", | |
675 | ioc->name, __func__, | |
676 | sas_device->enclosure_level, sas_device->connector_name)); | |
677 | ||
f92363d1 SR |
678 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
679 | list_add_tail(&sas_device->list, &ioc->sas_device_list); | |
680 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
681 | ||
682 | if (!mpt3sas_transport_port_add(ioc, sas_device->handle, | |
683 | sas_device->sas_address_parent)) { | |
684 | _scsih_sas_device_remove(ioc, sas_device); | |
685 | } else if (!sas_device->starget) { | |
686 | /* | |
687 | * When asyn scanning is enabled, its not possible to remove | |
688 | * devices while scanning is turned on due to an oops in | |
689 | * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start() | |
690 | */ | |
f5edbe77 | 691 | if (!ioc->is_driver_loading) { |
f92363d1 SR |
692 | mpt3sas_transport_port_remove(ioc, |
693 | sas_device->sas_address, | |
694 | sas_device->sas_address_parent); | |
f5edbe77 SR |
695 | _scsih_sas_device_remove(ioc, sas_device); |
696 | } | |
f92363d1 SR |
697 | } |
698 | } | |
699 | ||
700 | /** | |
701 | * _scsih_sas_device_init_add - insert sas_device to the list. | |
702 | * @ioc: per adapter object | |
703 | * @sas_device: the sas_device object | |
704 | * Context: This function will acquire ioc->sas_device_lock. | |
705 | * | |
706 | * Adding new object at driver load time to the ioc->sas_device_init_list. | |
707 | */ | |
708 | static void | |
709 | _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER *ioc, | |
710 | struct _sas_device *sas_device) | |
711 | { | |
712 | unsigned long flags; | |
713 | ||
714 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
715 | "%s: handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
716 | __func__, sas_device->handle, | |
717 | (unsigned long long)sas_device->sas_address)); | |
718 | ||
e6d45e3e SR |
719 | if (sas_device->enclosure_handle != 0) |
720 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
721 | "%s: enclosure logical id(0x%016llx), slot( %d)\n", | |
722 | ioc->name, __func__, (unsigned long long) | |
723 | sas_device->enclosure_logical_id, sas_device->slot)); | |
724 | ||
725 | if (sas_device->connector_name[0] != '\0') | |
726 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
727 | "%s: enclosure level(0x%04x), connector name( %s)\n", | |
728 | ioc->name, __func__, sas_device->enclosure_level, | |
729 | sas_device->connector_name)); | |
730 | ||
f92363d1 SR |
731 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
732 | list_add_tail(&sas_device->list, &ioc->sas_device_init_list); | |
733 | _scsih_determine_boot_device(ioc, sas_device, 0); | |
734 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
735 | } | |
736 | ||
737 | /** | |
738 | * _scsih_raid_device_find_by_id - raid device search | |
739 | * @ioc: per adapter object | |
740 | * @id: sas device target id | |
741 | * @channel: sas device channel | |
742 | * Context: Calling function should acquire ioc->raid_device_lock | |
743 | * | |
744 | * This searches for raid_device based on target id, then return raid_device | |
745 | * object. | |
746 | */ | |
747 | static struct _raid_device * | |
748 | _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER *ioc, int id, int channel) | |
749 | { | |
750 | struct _raid_device *raid_device, *r; | |
751 | ||
752 | r = NULL; | |
753 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
754 | if (raid_device->id == id && raid_device->channel == channel) { | |
755 | r = raid_device; | |
756 | goto out; | |
757 | } | |
758 | } | |
759 | ||
760 | out: | |
761 | return r; | |
762 | } | |
763 | ||
764 | /** | |
765 | * _scsih_raid_device_find_by_handle - raid device search | |
766 | * @ioc: per adapter object | |
767 | * @handle: sas device handle (assigned by firmware) | |
768 | * Context: Calling function should acquire ioc->raid_device_lock | |
769 | * | |
770 | * This searches for raid_device based on handle, then return raid_device | |
771 | * object. | |
772 | */ | |
773 | static struct _raid_device * | |
774 | _scsih_raid_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
775 | { | |
776 | struct _raid_device *raid_device, *r; | |
777 | ||
778 | r = NULL; | |
779 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
780 | if (raid_device->handle != handle) | |
781 | continue; | |
782 | r = raid_device; | |
783 | goto out; | |
784 | } | |
785 | ||
786 | out: | |
787 | return r; | |
788 | } | |
789 | ||
790 | /** | |
791 | * _scsih_raid_device_find_by_wwid - raid device search | |
792 | * @ioc: per adapter object | |
793 | * @handle: sas device handle (assigned by firmware) | |
794 | * Context: Calling function should acquire ioc->raid_device_lock | |
795 | * | |
796 | * This searches for raid_device based on wwid, then return raid_device | |
797 | * object. | |
798 | */ | |
799 | static struct _raid_device * | |
800 | _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid) | |
801 | { | |
802 | struct _raid_device *raid_device, *r; | |
803 | ||
804 | r = NULL; | |
805 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
806 | if (raid_device->wwid != wwid) | |
807 | continue; | |
808 | r = raid_device; | |
809 | goto out; | |
810 | } | |
811 | ||
812 | out: | |
813 | return r; | |
814 | } | |
815 | ||
816 | /** | |
817 | * _scsih_raid_device_add - add raid_device object | |
818 | * @ioc: per adapter object | |
819 | * @raid_device: raid_device object | |
820 | * | |
821 | * This is added to the raid_device_list link list. | |
822 | */ | |
823 | static void | |
824 | _scsih_raid_device_add(struct MPT3SAS_ADAPTER *ioc, | |
825 | struct _raid_device *raid_device) | |
826 | { | |
827 | unsigned long flags; | |
828 | ||
829 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
830 | "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__, | |
831 | raid_device->handle, (unsigned long long)raid_device->wwid)); | |
832 | ||
833 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
834 | list_add_tail(&raid_device->list, &ioc->raid_device_list); | |
835 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
836 | } | |
837 | ||
838 | /** | |
839 | * _scsih_raid_device_remove - delete raid_device object | |
840 | * @ioc: per adapter object | |
841 | * @raid_device: raid_device object | |
842 | * | |
843 | */ | |
844 | static void | |
845 | _scsih_raid_device_remove(struct MPT3SAS_ADAPTER *ioc, | |
846 | struct _raid_device *raid_device) | |
847 | { | |
848 | unsigned long flags; | |
849 | ||
850 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
851 | list_del(&raid_device->list); | |
852 | kfree(raid_device); | |
853 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
854 | } | |
855 | ||
856 | /** | |
857 | * mpt3sas_scsih_expander_find_by_handle - expander device search | |
858 | * @ioc: per adapter object | |
859 | * @handle: expander handle (assigned by firmware) | |
860 | * Context: Calling function should acquire ioc->sas_device_lock | |
861 | * | |
862 | * This searches for expander device based on handle, then returns the | |
863 | * sas_node object. | |
864 | */ | |
865 | struct _sas_node * | |
866 | mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
867 | { | |
868 | struct _sas_node *sas_expander, *r; | |
869 | ||
870 | r = NULL; | |
871 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { | |
872 | if (sas_expander->handle != handle) | |
873 | continue; | |
874 | r = sas_expander; | |
875 | goto out; | |
876 | } | |
877 | out: | |
878 | return r; | |
879 | } | |
880 | ||
881 | /** | |
882 | * mpt3sas_scsih_expander_find_by_sas_address - expander device search | |
883 | * @ioc: per adapter object | |
884 | * @sas_address: sas address | |
885 | * Context: Calling function should acquire ioc->sas_node_lock. | |
886 | * | |
887 | * This searches for expander device based on sas_address, then returns the | |
888 | * sas_node object. | |
889 | */ | |
890 | struct _sas_node * | |
891 | mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc, | |
892 | u64 sas_address) | |
893 | { | |
894 | struct _sas_node *sas_expander, *r; | |
895 | ||
896 | r = NULL; | |
897 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { | |
898 | if (sas_expander->sas_address != sas_address) | |
899 | continue; | |
900 | r = sas_expander; | |
901 | goto out; | |
902 | } | |
903 | out: | |
904 | return r; | |
905 | } | |
906 | ||
907 | /** | |
908 | * _scsih_expander_node_add - insert expander device to the list. | |
909 | * @ioc: per adapter object | |
910 | * @sas_expander: the sas_device object | |
911 | * Context: This function will acquire ioc->sas_node_lock. | |
912 | * | |
913 | * Adding new object to the ioc->sas_expander_list. | |
914 | * | |
915 | * Return nothing. | |
916 | */ | |
917 | static void | |
918 | _scsih_expander_node_add(struct MPT3SAS_ADAPTER *ioc, | |
919 | struct _sas_node *sas_expander) | |
920 | { | |
921 | unsigned long flags; | |
922 | ||
923 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
924 | list_add_tail(&sas_expander->list, &ioc->sas_expander_list); | |
925 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
926 | } | |
927 | ||
928 | /** | |
929 | * _scsih_is_end_device - determines if device is an end device | |
930 | * @device_info: bitfield providing information about the device. | |
931 | * Context: none | |
932 | * | |
933 | * Returns 1 if end device. | |
934 | */ | |
935 | static int | |
936 | _scsih_is_end_device(u32 device_info) | |
937 | { | |
938 | if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE && | |
939 | ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) | | |
940 | (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) | | |
941 | (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE))) | |
942 | return 1; | |
943 | else | |
944 | return 0; | |
945 | } | |
946 | ||
947 | /** | |
948 | * _scsih_scsi_lookup_get - returns scmd entry | |
949 | * @ioc: per adapter object | |
950 | * @smid: system request message index | |
951 | * | |
952 | * Returns the smid stored scmd pointer. | |
953 | */ | |
954 | static struct scsi_cmnd * | |
955 | _scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid) | |
956 | { | |
957 | return ioc->scsi_lookup[smid - 1].scmd; | |
958 | } | |
959 | ||
960 | /** | |
961 | * _scsih_scsi_lookup_get_clear - returns scmd entry | |
962 | * @ioc: per adapter object | |
963 | * @smid: system request message index | |
964 | * | |
965 | * Returns the smid stored scmd pointer. | |
966 | * Then will derefrence the stored scmd pointer. | |
967 | */ | |
968 | static inline struct scsi_cmnd * | |
969 | _scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER *ioc, u16 smid) | |
970 | { | |
971 | unsigned long flags; | |
972 | struct scsi_cmnd *scmd; | |
973 | ||
974 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
975 | scmd = ioc->scsi_lookup[smid - 1].scmd; | |
976 | ioc->scsi_lookup[smid - 1].scmd = NULL; | |
977 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
978 | ||
979 | return scmd; | |
980 | } | |
981 | ||
982 | /** | |
983 | * _scsih_scsi_lookup_find_by_scmd - scmd lookup | |
984 | * @ioc: per adapter object | |
985 | * @smid: system request message index | |
986 | * @scmd: pointer to scsi command object | |
987 | * Context: This function will acquire ioc->scsi_lookup_lock. | |
988 | * | |
989 | * This will search for a scmd pointer in the scsi_lookup array, | |
990 | * returning the revelent smid. A returned value of zero means invalid. | |
991 | */ | |
992 | static u16 | |
993 | _scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd | |
994 | *scmd) | |
995 | { | |
996 | u16 smid; | |
997 | unsigned long flags; | |
998 | int i; | |
999 | ||
1000 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
1001 | smid = 0; | |
1002 | for (i = 0; i < ioc->scsiio_depth; i++) { | |
1003 | if (ioc->scsi_lookup[i].scmd == scmd) { | |
1004 | smid = ioc->scsi_lookup[i].smid; | |
1005 | goto out; | |
1006 | } | |
1007 | } | |
1008 | out: | |
1009 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
1010 | return smid; | |
1011 | } | |
1012 | ||
1013 | /** | |
1014 | * _scsih_scsi_lookup_find_by_target - search for matching channel:id | |
1015 | * @ioc: per adapter object | |
1016 | * @id: target id | |
1017 | * @channel: channel | |
1018 | * Context: This function will acquire ioc->scsi_lookup_lock. | |
1019 | * | |
1020 | * This will search for a matching channel:id in the scsi_lookup array, | |
1021 | * returning 1 if found. | |
1022 | */ | |
1023 | static u8 | |
1024 | _scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER *ioc, int id, | |
1025 | int channel) | |
1026 | { | |
1027 | u8 found; | |
1028 | unsigned long flags; | |
1029 | int i; | |
1030 | ||
1031 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
1032 | found = 0; | |
1033 | for (i = 0 ; i < ioc->scsiio_depth; i++) { | |
1034 | if (ioc->scsi_lookup[i].scmd && | |
1035 | (ioc->scsi_lookup[i].scmd->device->id == id && | |
1036 | ioc->scsi_lookup[i].scmd->device->channel == channel)) { | |
1037 | found = 1; | |
1038 | goto out; | |
1039 | } | |
1040 | } | |
1041 | out: | |
1042 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
1043 | return found; | |
1044 | } | |
1045 | ||
1046 | /** | |
1047 | * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun | |
1048 | * @ioc: per adapter object | |
1049 | * @id: target id | |
1050 | * @lun: lun number | |
1051 | * @channel: channel | |
1052 | * Context: This function will acquire ioc->scsi_lookup_lock. | |
1053 | * | |
1054 | * This will search for a matching channel:id:lun in the scsi_lookup array, | |
1055 | * returning 1 if found. | |
1056 | */ | |
1057 | static u8 | |
1058 | _scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER *ioc, int id, | |
1059 | unsigned int lun, int channel) | |
1060 | { | |
1061 | u8 found; | |
1062 | unsigned long flags; | |
1063 | int i; | |
1064 | ||
1065 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
1066 | found = 0; | |
1067 | for (i = 0 ; i < ioc->scsiio_depth; i++) { | |
1068 | if (ioc->scsi_lookup[i].scmd && | |
1069 | (ioc->scsi_lookup[i].scmd->device->id == id && | |
1070 | ioc->scsi_lookup[i].scmd->device->channel == channel && | |
1071 | ioc->scsi_lookup[i].scmd->device->lun == lun)) { | |
1072 | found = 1; | |
1073 | goto out; | |
1074 | } | |
1075 | } | |
1076 | out: | |
1077 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
1078 | return found; | |
1079 | } | |
1080 | ||
cf75d5d6 | 1081 | /** |
8a7e4c24 | 1082 | * scsih_change_queue_depth - setting device queue depth |
cf75d5d6 CH |
1083 | * @sdev: scsi device struct |
1084 | * @qdepth: requested queue depth | |
1085 | * | |
1086 | * Returns queue depth. | |
1087 | */ | |
8a7e4c24 SR |
1088 | int |
1089 | scsih_change_queue_depth(struct scsi_device *sdev, int qdepth) | |
f92363d1 SR |
1090 | { |
1091 | struct Scsi_Host *shost = sdev->host; | |
1092 | int max_depth; | |
1093 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
1094 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
1095 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1096 | struct _sas_device *sas_device; | |
1097 | unsigned long flags; | |
1098 | ||
1099 | max_depth = shost->can_queue; | |
1100 | ||
1101 | /* limit max device queue for SATA to 32 */ | |
1102 | sas_device_priv_data = sdev->hostdata; | |
1103 | if (!sas_device_priv_data) | |
1104 | goto not_sata; | |
1105 | sas_target_priv_data = sas_device_priv_data->sas_target; | |
1106 | if (!sas_target_priv_data) | |
1107 | goto not_sata; | |
1108 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) | |
1109 | goto not_sata; | |
1110 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
1111 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, | |
1112 | sas_device_priv_data->sas_target->sas_address); | |
1113 | if (sas_device && sas_device->device_info & | |
1114 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) | |
1115 | max_depth = MPT3SAS_SATA_QUEUE_DEPTH; | |
1116 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
1117 | ||
1118 | not_sata: | |
1119 | ||
1120 | if (!sdev->tagged_supported) | |
1121 | max_depth = 1; | |
1122 | if (qdepth > max_depth) | |
1123 | qdepth = max_depth; | |
cf75d5d6 | 1124 | return scsi_change_queue_depth(sdev, qdepth); |
f92363d1 SR |
1125 | } |
1126 | ||
f92363d1 | 1127 | /** |
8a7e4c24 | 1128 | * scsih_target_alloc - target add routine |
f92363d1 SR |
1129 | * @starget: scsi target struct |
1130 | * | |
1131 | * Returns 0 if ok. Any other return is assumed to be an error and | |
1132 | * the device is ignored. | |
1133 | */ | |
8a7e4c24 SR |
1134 | int |
1135 | scsih_target_alloc(struct scsi_target *starget) | |
f92363d1 SR |
1136 | { |
1137 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); | |
1138 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
1139 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1140 | struct _sas_device *sas_device; | |
1141 | struct _raid_device *raid_device; | |
1142 | unsigned long flags; | |
1143 | struct sas_rphy *rphy; | |
1144 | ||
62c4da44 JL |
1145 | sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data), |
1146 | GFP_KERNEL); | |
f92363d1 SR |
1147 | if (!sas_target_priv_data) |
1148 | return -ENOMEM; | |
1149 | ||
1150 | starget->hostdata = sas_target_priv_data; | |
1151 | sas_target_priv_data->starget = starget; | |
1152 | sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE; | |
1153 | ||
1154 | /* RAID volumes */ | |
1155 | if (starget->channel == RAID_CHANNEL) { | |
1156 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1157 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, | |
1158 | starget->channel); | |
1159 | if (raid_device) { | |
1160 | sas_target_priv_data->handle = raid_device->handle; | |
1161 | sas_target_priv_data->sas_address = raid_device->wwid; | |
1162 | sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME; | |
7786ab6a SR |
1163 | sas_target_priv_data->raid_device = raid_device; |
1164 | if (ioc->is_warpdrive) | |
1165 | raid_device->starget = starget; | |
f92363d1 SR |
1166 | } |
1167 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1168 | return 0; | |
1169 | } | |
1170 | ||
1171 | /* sas/sata devices */ | |
1172 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
1173 | rphy = dev_to_rphy(starget->dev.parent); | |
1174 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, | |
1175 | rphy->identify.sas_address); | |
1176 | ||
1177 | if (sas_device) { | |
1178 | sas_target_priv_data->handle = sas_device->handle; | |
1179 | sas_target_priv_data->sas_address = sas_device->sas_address; | |
1180 | sas_device->starget = starget; | |
1181 | sas_device->id = starget->id; | |
1182 | sas_device->channel = starget->channel; | |
1183 | if (test_bit(sas_device->handle, ioc->pd_handles)) | |
1184 | sas_target_priv_data->flags |= | |
1185 | MPT_TARGET_FLAGS_RAID_COMPONENT; | |
45506049 | 1186 | #ifndef SCSI_MPT2SAS |
f92363d1 SR |
1187 | if (sas_device->fast_path) |
1188 | sas_target_priv_data->flags |= MPT_TARGET_FASTPATH_IO; | |
45506049 | 1189 | #endif |
f92363d1 SR |
1190 | } |
1191 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
1192 | ||
1193 | return 0; | |
1194 | } | |
1195 | ||
1196 | /** | |
8a7e4c24 | 1197 | * scsih_target_destroy - target destroy routine |
f92363d1 SR |
1198 | * @starget: scsi target struct |
1199 | * | |
1200 | * Returns nothing. | |
1201 | */ | |
8a7e4c24 SR |
1202 | void |
1203 | scsih_target_destroy(struct scsi_target *starget) | |
f92363d1 SR |
1204 | { |
1205 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); | |
1206 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
1207 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1208 | struct _sas_device *sas_device; | |
1209 | struct _raid_device *raid_device; | |
1210 | unsigned long flags; | |
1211 | struct sas_rphy *rphy; | |
1212 | ||
1213 | sas_target_priv_data = starget->hostdata; | |
1214 | if (!sas_target_priv_data) | |
1215 | return; | |
1216 | ||
1217 | if (starget->channel == RAID_CHANNEL) { | |
1218 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1219 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, | |
1220 | starget->channel); | |
1221 | if (raid_device) { | |
1222 | raid_device->starget = NULL; | |
1223 | raid_device->sdev = NULL; | |
1224 | } | |
1225 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1226 | goto out; | |
1227 | } | |
1228 | ||
1229 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
1230 | rphy = dev_to_rphy(starget->dev.parent); | |
1231 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, | |
1232 | rphy->identify.sas_address); | |
1233 | if (sas_device && (sas_device->starget == starget) && | |
1234 | (sas_device->id == starget->id) && | |
1235 | (sas_device->channel == starget->channel)) | |
1236 | sas_device->starget = NULL; | |
1237 | ||
1238 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
1239 | ||
1240 | out: | |
1241 | kfree(sas_target_priv_data); | |
1242 | starget->hostdata = NULL; | |
1243 | } | |
1244 | ||
1245 | /** | |
8a7e4c24 | 1246 | * scsih_slave_alloc - device add routine |
f92363d1 SR |
1247 | * @sdev: scsi device struct |
1248 | * | |
1249 | * Returns 0 if ok. Any other return is assumed to be an error and | |
1250 | * the device is ignored. | |
1251 | */ | |
8a7e4c24 SR |
1252 | int |
1253 | scsih_slave_alloc(struct scsi_device *sdev) | |
f92363d1 SR |
1254 | { |
1255 | struct Scsi_Host *shost; | |
1256 | struct MPT3SAS_ADAPTER *ioc; | |
1257 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1258 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
1259 | struct scsi_target *starget; | |
1260 | struct _raid_device *raid_device; | |
b65cfedf | 1261 | struct _sas_device *sas_device; |
f92363d1 SR |
1262 | unsigned long flags; |
1263 | ||
62c4da44 JL |
1264 | sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data), |
1265 | GFP_KERNEL); | |
f92363d1 SR |
1266 | if (!sas_device_priv_data) |
1267 | return -ENOMEM; | |
1268 | ||
1269 | sas_device_priv_data->lun = sdev->lun; | |
1270 | sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT; | |
1271 | ||
1272 | starget = scsi_target(sdev); | |
1273 | sas_target_priv_data = starget->hostdata; | |
1274 | sas_target_priv_data->num_luns++; | |
1275 | sas_device_priv_data->sas_target = sas_target_priv_data; | |
1276 | sdev->hostdata = sas_device_priv_data; | |
1277 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT)) | |
1278 | sdev->no_uld_attach = 1; | |
1279 | ||
1280 | shost = dev_to_shost(&starget->dev); | |
1281 | ioc = shost_priv(shost); | |
1282 | if (starget->channel == RAID_CHANNEL) { | |
1283 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1284 | raid_device = _scsih_raid_device_find_by_id(ioc, | |
1285 | starget->id, starget->channel); | |
1286 | if (raid_device) | |
1287 | raid_device->sdev = sdev; /* raid is single lun */ | |
1288 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1289 | } | |
1290 | ||
b65cfedf SR |
1291 | if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { |
1292 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
1293 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, | |
1294 | sas_target_priv_data->sas_address); | |
1295 | if (sas_device && (sas_device->starget == NULL)) { | |
1296 | sdev_printk(KERN_INFO, sdev, | |
1297 | "%s : sas_device->starget set to starget @ %d\n", | |
1298 | __func__, __LINE__); | |
1299 | sas_device->starget = starget; | |
1300 | } | |
1301 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
1302 | } | |
1303 | ||
f92363d1 SR |
1304 | return 0; |
1305 | } | |
1306 | ||
1307 | /** | |
8a7e4c24 | 1308 | * scsih_slave_destroy - device destroy routine |
f92363d1 SR |
1309 | * @sdev: scsi device struct |
1310 | * | |
1311 | * Returns nothing. | |
1312 | */ | |
8a7e4c24 SR |
1313 | void |
1314 | scsih_slave_destroy(struct scsi_device *sdev) | |
f92363d1 SR |
1315 | { |
1316 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1317 | struct scsi_target *starget; | |
1318 | struct Scsi_Host *shost; | |
1319 | struct MPT3SAS_ADAPTER *ioc; | |
1320 | struct _sas_device *sas_device; | |
1321 | unsigned long flags; | |
1322 | ||
1323 | if (!sdev->hostdata) | |
1324 | return; | |
1325 | ||
1326 | starget = scsi_target(sdev); | |
1327 | sas_target_priv_data = starget->hostdata; | |
1328 | sas_target_priv_data->num_luns--; | |
1329 | ||
1330 | shost = dev_to_shost(&starget->dev); | |
1331 | ioc = shost_priv(shost); | |
1332 | ||
1333 | if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { | |
1334 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
1335 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, | |
1336 | sas_target_priv_data->sas_address); | |
1337 | if (sas_device && !sas_target_priv_data->num_luns) | |
1338 | sas_device->starget = NULL; | |
1339 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
1340 | } | |
1341 | ||
1342 | kfree(sdev->hostdata); | |
1343 | sdev->hostdata = NULL; | |
1344 | } | |
1345 | ||
1346 | /** | |
1347 | * _scsih_display_sata_capabilities - sata capabilities | |
1348 | * @ioc: per adapter object | |
1349 | * @handle: device handle | |
1350 | * @sdev: scsi device struct | |
1351 | */ | |
1352 | static void | |
1353 | _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc, | |
1354 | u16 handle, struct scsi_device *sdev) | |
1355 | { | |
1356 | Mpi2ConfigReply_t mpi_reply; | |
1357 | Mpi2SasDevicePage0_t sas_device_pg0; | |
1358 | u32 ioc_status; | |
1359 | u16 flags; | |
1360 | u32 device_info; | |
1361 | ||
1362 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
1363 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
1364 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
1365 | ioc->name, __FILE__, __LINE__, __func__); | |
1366 | return; | |
1367 | } | |
1368 | ||
1369 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
1370 | MPI2_IOCSTATUS_MASK; | |
1371 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
1372 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
1373 | ioc->name, __FILE__, __LINE__, __func__); | |
1374 | return; | |
1375 | } | |
1376 | ||
1377 | flags = le16_to_cpu(sas_device_pg0.Flags); | |
1378 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | |
1379 | ||
1380 | sdev_printk(KERN_INFO, sdev, | |
1381 | "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), " | |
1382 | "sw_preserve(%s)\n", | |
1383 | (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n", | |
1384 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n", | |
1385 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" : | |
1386 | "n", | |
1387 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n", | |
1388 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n", | |
1389 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n"); | |
1390 | } | |
1391 | ||
1392 | /* | |
1393 | * raid transport support - | |
1394 | * Enabled for SLES11 and newer, in older kernels the driver will panic when | |
1395 | * unloading the driver followed by a load - I beleive that the subroutine | |
1396 | * raid_class_release() is not cleaning up properly. | |
1397 | */ | |
1398 | ||
1399 | /** | |
8a7e4c24 | 1400 | * scsih_is_raid - return boolean indicating device is raid volume |
f92363d1 SR |
1401 | * @dev the device struct object |
1402 | */ | |
8a7e4c24 SR |
1403 | int |
1404 | scsih_is_raid(struct device *dev) | |
f92363d1 SR |
1405 | { |
1406 | struct scsi_device *sdev = to_scsi_device(dev); | |
7786ab6a | 1407 | struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host); |
f92363d1 | 1408 | |
7786ab6a SR |
1409 | if (ioc->is_warpdrive) |
1410 | return 0; | |
f92363d1 SR |
1411 | return (sdev->channel == RAID_CHANNEL) ? 1 : 0; |
1412 | } | |
1413 | ||
1414 | /** | |
8a7e4c24 | 1415 | * scsih_get_resync - get raid volume resync percent complete |
f92363d1 SR |
1416 | * @dev the device struct object |
1417 | */ | |
8a7e4c24 SR |
1418 | void |
1419 | scsih_get_resync(struct device *dev) | |
f92363d1 SR |
1420 | { |
1421 | struct scsi_device *sdev = to_scsi_device(dev); | |
1422 | struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host); | |
1423 | static struct _raid_device *raid_device; | |
1424 | unsigned long flags; | |
1425 | Mpi2RaidVolPage0_t vol_pg0; | |
1426 | Mpi2ConfigReply_t mpi_reply; | |
1427 | u32 volume_status_flags; | |
1428 | u8 percent_complete; | |
1429 | u16 handle; | |
1430 | ||
1431 | percent_complete = 0; | |
1432 | handle = 0; | |
7786ab6a SR |
1433 | if (ioc->is_warpdrive) |
1434 | goto out; | |
1435 | ||
f92363d1 SR |
1436 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
1437 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, | |
1438 | sdev->channel); | |
1439 | if (raid_device) { | |
1440 | handle = raid_device->handle; | |
1441 | percent_complete = raid_device->percent_complete; | |
1442 | } | |
1443 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1444 | ||
1445 | if (!handle) | |
1446 | goto out; | |
1447 | ||
1448 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0, | |
1449 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
1450 | sizeof(Mpi2RaidVolPage0_t))) { | |
1451 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
1452 | ioc->name, __FILE__, __LINE__, __func__); | |
1453 | percent_complete = 0; | |
1454 | goto out; | |
1455 | } | |
1456 | ||
1457 | volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags); | |
1458 | if (!(volume_status_flags & | |
1459 | MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)) | |
1460 | percent_complete = 0; | |
1461 | ||
1462 | out: | |
1463 | raid_set_resync(mpt3sas_raid_template, dev, percent_complete); | |
1464 | } | |
1465 | ||
1466 | /** | |
8a7e4c24 | 1467 | * scsih_get_state - get raid volume level |
f92363d1 SR |
1468 | * @dev the device struct object |
1469 | */ | |
8a7e4c24 SR |
1470 | void |
1471 | scsih_get_state(struct device *dev) | |
f92363d1 SR |
1472 | { |
1473 | struct scsi_device *sdev = to_scsi_device(dev); | |
1474 | struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host); | |
1475 | static struct _raid_device *raid_device; | |
1476 | unsigned long flags; | |
1477 | Mpi2RaidVolPage0_t vol_pg0; | |
1478 | Mpi2ConfigReply_t mpi_reply; | |
1479 | u32 volstate; | |
1480 | enum raid_state state = RAID_STATE_UNKNOWN; | |
1481 | u16 handle = 0; | |
1482 | ||
1483 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1484 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, | |
1485 | sdev->channel); | |
1486 | if (raid_device) | |
1487 | handle = raid_device->handle; | |
1488 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1489 | ||
1490 | if (!raid_device) | |
1491 | goto out; | |
1492 | ||
1493 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0, | |
1494 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
1495 | sizeof(Mpi2RaidVolPage0_t))) { | |
1496 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
1497 | ioc->name, __FILE__, __LINE__, __func__); | |
1498 | goto out; | |
1499 | } | |
1500 | ||
1501 | volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags); | |
1502 | if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) { | |
1503 | state = RAID_STATE_RESYNCING; | |
1504 | goto out; | |
1505 | } | |
1506 | ||
1507 | switch (vol_pg0.VolumeState) { | |
1508 | case MPI2_RAID_VOL_STATE_OPTIMAL: | |
1509 | case MPI2_RAID_VOL_STATE_ONLINE: | |
1510 | state = RAID_STATE_ACTIVE; | |
1511 | break; | |
1512 | case MPI2_RAID_VOL_STATE_DEGRADED: | |
1513 | state = RAID_STATE_DEGRADED; | |
1514 | break; | |
1515 | case MPI2_RAID_VOL_STATE_FAILED: | |
1516 | case MPI2_RAID_VOL_STATE_MISSING: | |
1517 | state = RAID_STATE_OFFLINE; | |
1518 | break; | |
1519 | } | |
1520 | out: | |
1521 | raid_set_state(mpt3sas_raid_template, dev, state); | |
1522 | } | |
1523 | ||
1524 | /** | |
1525 | * _scsih_set_level - set raid level | |
1526 | * @sdev: scsi device struct | |
1527 | * @volume_type: volume type | |
1528 | */ | |
1529 | static void | |
1530 | _scsih_set_level(struct scsi_device *sdev, u8 volume_type) | |
1531 | { | |
1532 | enum raid_level level = RAID_LEVEL_UNKNOWN; | |
1533 | ||
1534 | switch (volume_type) { | |
1535 | case MPI2_RAID_VOL_TYPE_RAID0: | |
1536 | level = RAID_LEVEL_0; | |
1537 | break; | |
1538 | case MPI2_RAID_VOL_TYPE_RAID10: | |
1539 | level = RAID_LEVEL_10; | |
1540 | break; | |
1541 | case MPI2_RAID_VOL_TYPE_RAID1E: | |
1542 | level = RAID_LEVEL_1E; | |
1543 | break; | |
1544 | case MPI2_RAID_VOL_TYPE_RAID1: | |
1545 | level = RAID_LEVEL_1; | |
1546 | break; | |
1547 | } | |
1548 | ||
1549 | raid_set_level(mpt3sas_raid_template, &sdev->sdev_gendev, level); | |
1550 | } | |
1551 | ||
1552 | ||
1553 | /** | |
1554 | * _scsih_get_volume_capabilities - volume capabilities | |
1555 | * @ioc: per adapter object | |
1556 | * @sas_device: the raid_device object | |
1557 | * | |
1558 | * Returns 0 for success, else 1 | |
1559 | */ | |
1560 | static int | |
1561 | _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc, | |
1562 | struct _raid_device *raid_device) | |
1563 | { | |
1564 | Mpi2RaidVolPage0_t *vol_pg0; | |
1565 | Mpi2RaidPhysDiskPage0_t pd_pg0; | |
1566 | Mpi2SasDevicePage0_t sas_device_pg0; | |
1567 | Mpi2ConfigReply_t mpi_reply; | |
1568 | u16 sz; | |
1569 | u8 num_pds; | |
1570 | ||
1571 | if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle, | |
1572 | &num_pds)) || !num_pds) { | |
1573 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
1574 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | |
1575 | __func__)); | |
1576 | return 1; | |
1577 | } | |
1578 | ||
1579 | raid_device->num_pds = num_pds; | |
1580 | sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds * | |
1581 | sizeof(Mpi2RaidVol0PhysDisk_t)); | |
1582 | vol_pg0 = kzalloc(sz, GFP_KERNEL); | |
1583 | if (!vol_pg0) { | |
1584 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
1585 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | |
1586 | __func__)); | |
1587 | return 1; | |
1588 | } | |
1589 | ||
1590 | if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0, | |
1591 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) { | |
1592 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
1593 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | |
1594 | __func__)); | |
1595 | kfree(vol_pg0); | |
1596 | return 1; | |
1597 | } | |
1598 | ||
1599 | raid_device->volume_type = vol_pg0->VolumeType; | |
1600 | ||
1601 | /* figure out what the underlying devices are by | |
1602 | * obtaining the device_info bits for the 1st device | |
1603 | */ | |
1604 | if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | |
1605 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM, | |
1606 | vol_pg0->PhysDisk[0].PhysDiskNum))) { | |
1607 | if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
1608 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | |
1609 | le16_to_cpu(pd_pg0.DevHandle)))) { | |
1610 | raid_device->device_info = | |
1611 | le32_to_cpu(sas_device_pg0.DeviceInfo); | |
1612 | } | |
1613 | } | |
1614 | ||
1615 | kfree(vol_pg0); | |
1616 | return 0; | |
1617 | } | |
1618 | ||
f92363d1 SR |
1619 | /** |
1620 | * _scsih_enable_tlr - setting TLR flags | |
1621 | * @ioc: per adapter object | |
1622 | * @sdev: scsi device struct | |
1623 | * | |
1624 | * Enabling Transaction Layer Retries for tape devices when | |
1625 | * vpd page 0x90 is present | |
1626 | * | |
1627 | */ | |
1628 | static void | |
1629 | _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev) | |
1630 | { | |
1631 | ||
1632 | /* only for TAPE */ | |
1633 | if (sdev->type != TYPE_TAPE) | |
1634 | return; | |
1635 | ||
1636 | if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR)) | |
1637 | return; | |
1638 | ||
1639 | sas_enable_tlr(sdev); | |
1640 | sdev_printk(KERN_INFO, sdev, "TLR %s\n", | |
1641 | sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled"); | |
1642 | return; | |
1643 | ||
1644 | } | |
1645 | ||
1646 | /** | |
8a7e4c24 | 1647 | * scsih_slave_configure - device configure routine. |
f92363d1 SR |
1648 | * @sdev: scsi device struct |
1649 | * | |
1650 | * Returns 0 if ok. Any other return is assumed to be an error and | |
1651 | * the device is ignored. | |
1652 | */ | |
8a7e4c24 SR |
1653 | int |
1654 | scsih_slave_configure(struct scsi_device *sdev) | |
f92363d1 SR |
1655 | { |
1656 | struct Scsi_Host *shost = sdev->host; | |
1657 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
1658 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
1659 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1660 | struct _sas_device *sas_device; | |
1661 | struct _raid_device *raid_device; | |
1662 | unsigned long flags; | |
1663 | int qdepth; | |
1664 | u8 ssp_target = 0; | |
1665 | char *ds = ""; | |
1666 | char *r_level = ""; | |
1667 | u16 handle, volume_handle = 0; | |
1668 | u64 volume_wwid = 0; | |
1669 | ||
1670 | qdepth = 1; | |
1671 | sas_device_priv_data = sdev->hostdata; | |
1672 | sas_device_priv_data->configured_lun = 1; | |
1673 | sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT; | |
1674 | sas_target_priv_data = sas_device_priv_data->sas_target; | |
1675 | handle = sas_target_priv_data->handle; | |
1676 | ||
1677 | /* raid volume handling */ | |
1678 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) { | |
1679 | ||
1680 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1681 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); | |
1682 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1683 | if (!raid_device) { | |
1684 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
1685 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, | |
1686 | __LINE__, __func__)); | |
1687 | return 1; | |
1688 | } | |
1689 | ||
1690 | if (_scsih_get_volume_capabilities(ioc, raid_device)) { | |
1691 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
1692 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, | |
1693 | __LINE__, __func__)); | |
1694 | return 1; | |
1695 | } | |
1696 | ||
7786ab6a SR |
1697 | #ifdef SCSI_MPT2SAS |
1698 | /* | |
1699 | * WARPDRIVE: Initialize the required data for Direct IO | |
1700 | */ | |
1701 | _scsih_init_warpdrive_properties(ioc, raid_device); | |
1702 | #endif | |
f92363d1 SR |
1703 | |
1704 | /* RAID Queue Depth Support | |
1705 | * IS volume = underlying qdepth of drive type, either | |
1706 | * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH | |
1707 | * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH) | |
1708 | */ | |
1709 | if (raid_device->device_info & | |
1710 | MPI2_SAS_DEVICE_INFO_SSP_TARGET) { | |
1711 | qdepth = MPT3SAS_SAS_QUEUE_DEPTH; | |
1712 | ds = "SSP"; | |
1713 | } else { | |
1714 | qdepth = MPT3SAS_SATA_QUEUE_DEPTH; | |
1715 | if (raid_device->device_info & | |
1716 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) | |
1717 | ds = "SATA"; | |
1718 | else | |
1719 | ds = "STP"; | |
1720 | } | |
1721 | ||
1722 | switch (raid_device->volume_type) { | |
1723 | case MPI2_RAID_VOL_TYPE_RAID0: | |
1724 | r_level = "RAID0"; | |
1725 | break; | |
1726 | case MPI2_RAID_VOL_TYPE_RAID1E: | |
1727 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
1728 | if (ioc->manu_pg10.OEMIdentifier && | |
1729 | (le32_to_cpu(ioc->manu_pg10.GenericFlags0) & | |
1730 | MFG10_GF0_R10_DISPLAY) && | |
1731 | !(raid_device->num_pds % 2)) | |
1732 | r_level = "RAID10"; | |
1733 | else | |
1734 | r_level = "RAID1E"; | |
1735 | break; | |
1736 | case MPI2_RAID_VOL_TYPE_RAID1: | |
1737 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
1738 | r_level = "RAID1"; | |
1739 | break; | |
1740 | case MPI2_RAID_VOL_TYPE_RAID10: | |
1741 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
1742 | r_level = "RAID10"; | |
1743 | break; | |
1744 | case MPI2_RAID_VOL_TYPE_UNKNOWN: | |
1745 | default: | |
1746 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
1747 | r_level = "RAIDX"; | |
1748 | break; | |
1749 | } | |
1750 | ||
7786ab6a SR |
1751 | if (!ioc->hide_ir_msg) |
1752 | sdev_printk(KERN_INFO, sdev, | |
1753 | "%s: handle(0x%04x), wwid(0x%016llx)," | |
1754 | " pd_count(%d), type(%s)\n", | |
1755 | r_level, raid_device->handle, | |
1756 | (unsigned long long)raid_device->wwid, | |
1757 | raid_device->num_pds, ds); | |
f92363d1 | 1758 | |
8a7e4c24 | 1759 | scsih_change_queue_depth(sdev, qdepth); |
f92363d1 | 1760 | |
7786ab6a SR |
1761 | /* raid transport support */ |
1762 | if (!ioc->is_warpdrive) | |
1763 | _scsih_set_level(sdev, raid_device->volume_type); | |
f92363d1 SR |
1764 | return 0; |
1765 | } | |
1766 | ||
1767 | /* non-raid handling */ | |
1768 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
1769 | if (mpt3sas_config_get_volume_handle(ioc, handle, | |
1770 | &volume_handle)) { | |
1771 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
1772 | "failure at %s:%d/%s()!\n", ioc->name, | |
1773 | __FILE__, __LINE__, __func__)); | |
1774 | return 1; | |
1775 | } | |
1776 | if (volume_handle && mpt3sas_config_get_volume_wwid(ioc, | |
1777 | volume_handle, &volume_wwid)) { | |
1778 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
1779 | "failure at %s:%d/%s()!\n", ioc->name, | |
1780 | __FILE__, __LINE__, __func__)); | |
1781 | return 1; | |
1782 | } | |
1783 | } | |
1784 | ||
1785 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
1786 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, | |
1787 | sas_device_priv_data->sas_target->sas_address); | |
1788 | if (!sas_device) { | |
1789 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
1790 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
1791 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | |
1792 | __func__)); | |
1793 | return 1; | |
1794 | } | |
1795 | ||
1796 | sas_device->volume_handle = volume_handle; | |
1797 | sas_device->volume_wwid = volume_wwid; | |
1798 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) { | |
1799 | qdepth = MPT3SAS_SAS_QUEUE_DEPTH; | |
1800 | ssp_target = 1; | |
1801 | ds = "SSP"; | |
1802 | } else { | |
1803 | qdepth = MPT3SAS_SATA_QUEUE_DEPTH; | |
1804 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) | |
1805 | ds = "STP"; | |
1806 | else if (sas_device->device_info & | |
1807 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) | |
1808 | ds = "SATA"; | |
1809 | } | |
1810 | ||
1811 | sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \ | |
1812 | "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n", | |
1813 | ds, handle, (unsigned long long)sas_device->sas_address, | |
1814 | sas_device->phy, (unsigned long long)sas_device->device_name); | |
e6d45e3e SR |
1815 | if (sas_device->enclosure_handle != 0) |
1816 | sdev_printk(KERN_INFO, sdev, | |
1817 | "%s: enclosure_logical_id(0x%016llx), slot(%d)\n", | |
1818 | ds, (unsigned long long) | |
1819 | sas_device->enclosure_logical_id, sas_device->slot); | |
1820 | if (sas_device->connector_name[0] != '\0') | |
1821 | sdev_printk(KERN_INFO, sdev, | |
1822 | "%s: enclosure level(0x%04x), connector name( %s)\n", | |
1823 | ds, sas_device->enclosure_level, | |
1824 | sas_device->connector_name); | |
f92363d1 SR |
1825 | |
1826 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
1827 | ||
1828 | if (!ssp_target) | |
1829 | _scsih_display_sata_capabilities(ioc, handle, sdev); | |
1830 | ||
1831 | ||
8a7e4c24 | 1832 | scsih_change_queue_depth(sdev, qdepth); |
f92363d1 SR |
1833 | |
1834 | if (ssp_target) { | |
1835 | sas_read_port_mode_page(sdev); | |
1836 | _scsih_enable_tlr(ioc, sdev); | |
1837 | } | |
1838 | ||
1839 | return 0; | |
1840 | } | |
1841 | ||
1842 | /** | |
8a7e4c24 | 1843 | * scsih_bios_param - fetch head, sector, cylinder info for a disk |
f92363d1 SR |
1844 | * @sdev: scsi device struct |
1845 | * @bdev: pointer to block device context | |
1846 | * @capacity: device size (in 512 byte sectors) | |
1847 | * @params: three element array to place output: | |
1848 | * params[0] number of heads (max 255) | |
1849 | * params[1] number of sectors (max 63) | |
1850 | * params[2] number of cylinders | |
1851 | * | |
1852 | * Return nothing. | |
1853 | */ | |
8a7e4c24 SR |
1854 | int |
1855 | scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev, | |
f92363d1 SR |
1856 | sector_t capacity, int params[]) |
1857 | { | |
1858 | int heads; | |
1859 | int sectors; | |
1860 | sector_t cylinders; | |
1861 | ulong dummy; | |
1862 | ||
1863 | heads = 64; | |
1864 | sectors = 32; | |
1865 | ||
1866 | dummy = heads * sectors; | |
1867 | cylinders = capacity; | |
1868 | sector_div(cylinders, dummy); | |
1869 | ||
1870 | /* | |
1871 | * Handle extended translation size for logical drives | |
1872 | * > 1Gb | |
1873 | */ | |
1874 | if ((ulong)capacity >= 0x200000) { | |
1875 | heads = 255; | |
1876 | sectors = 63; | |
1877 | dummy = heads * sectors; | |
1878 | cylinders = capacity; | |
1879 | sector_div(cylinders, dummy); | |
1880 | } | |
1881 | ||
1882 | /* return result */ | |
1883 | params[0] = heads; | |
1884 | params[1] = sectors; | |
1885 | params[2] = cylinders; | |
1886 | ||
1887 | return 0; | |
1888 | } | |
1889 | ||
1890 | /** | |
1891 | * _scsih_response_code - translation of device response code | |
1892 | * @ioc: per adapter object | |
1893 | * @response_code: response code returned by the device | |
1894 | * | |
1895 | * Return nothing. | |
1896 | */ | |
1897 | static void | |
1898 | _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code) | |
1899 | { | |
1900 | char *desc; | |
1901 | ||
1902 | switch (response_code) { | |
1903 | case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE: | |
1904 | desc = "task management request completed"; | |
1905 | break; | |
1906 | case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME: | |
1907 | desc = "invalid frame"; | |
1908 | break; | |
1909 | case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED: | |
1910 | desc = "task management request not supported"; | |
1911 | break; | |
1912 | case MPI2_SCSITASKMGMT_RSP_TM_FAILED: | |
1913 | desc = "task management request failed"; | |
1914 | break; | |
1915 | case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED: | |
1916 | desc = "task management request succeeded"; | |
1917 | break; | |
1918 | case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN: | |
1919 | desc = "invalid lun"; | |
1920 | break; | |
1921 | case 0xA: | |
1922 | desc = "overlapped tag attempted"; | |
1923 | break; | |
1924 | case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC: | |
1925 | desc = "task queued, however not sent to target"; | |
1926 | break; | |
1927 | default: | |
1928 | desc = "unknown"; | |
1929 | break; | |
1930 | } | |
1931 | pr_warn(MPT3SAS_FMT "response_code(0x%01x): %s\n", | |
1932 | ioc->name, response_code, desc); | |
1933 | } | |
1934 | ||
1935 | /** | |
1936 | * _scsih_tm_done - tm completion routine | |
1937 | * @ioc: per adapter object | |
1938 | * @smid: system request message index | |
1939 | * @msix_index: MSIX table index supplied by the OS | |
1940 | * @reply: reply message frame(lower 32bit addr) | |
1941 | * Context: none. | |
1942 | * | |
1943 | * The callback handler when using scsih_issue_tm. | |
1944 | * | |
1945 | * Return 1 meaning mf should be freed from _base_interrupt | |
1946 | * 0 means the mf is freed from this function. | |
1947 | */ | |
1948 | static u8 | |
1949 | _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | |
1950 | { | |
1951 | MPI2DefaultReply_t *mpi_reply; | |
1952 | ||
1953 | if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED) | |
1954 | return 1; | |
1955 | if (ioc->tm_cmds.smid != smid) | |
1956 | return 1; | |
1957 | mpt3sas_base_flush_reply_queues(ioc); | |
1958 | ioc->tm_cmds.status |= MPT3_CMD_COMPLETE; | |
1959 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
1960 | if (mpi_reply) { | |
1961 | memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); | |
1962 | ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID; | |
1963 | } | |
1964 | ioc->tm_cmds.status &= ~MPT3_CMD_PENDING; | |
1965 | complete(&ioc->tm_cmds.done); | |
1966 | return 1; | |
1967 | } | |
1968 | ||
1969 | /** | |
1970 | * mpt3sas_scsih_set_tm_flag - set per target tm_busy | |
1971 | * @ioc: per adapter object | |
1972 | * @handle: device handle | |
1973 | * | |
1974 | * During taskmangement request, we need to freeze the device queue. | |
1975 | */ | |
1976 | void | |
1977 | mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
1978 | { | |
1979 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
1980 | struct scsi_device *sdev; | |
1981 | u8 skip = 0; | |
1982 | ||
1983 | shost_for_each_device(sdev, ioc->shost) { | |
1984 | if (skip) | |
1985 | continue; | |
1986 | sas_device_priv_data = sdev->hostdata; | |
1987 | if (!sas_device_priv_data) | |
1988 | continue; | |
1989 | if (sas_device_priv_data->sas_target->handle == handle) { | |
1990 | sas_device_priv_data->sas_target->tm_busy = 1; | |
1991 | skip = 1; | |
1992 | ioc->ignore_loginfos = 1; | |
1993 | } | |
1994 | } | |
1995 | } | |
1996 | ||
1997 | /** | |
1998 | * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy | |
1999 | * @ioc: per adapter object | |
2000 | * @handle: device handle | |
2001 | * | |
2002 | * During taskmangement request, we need to freeze the device queue. | |
2003 | */ | |
2004 | void | |
2005 | mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
2006 | { | |
2007 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2008 | struct scsi_device *sdev; | |
2009 | u8 skip = 0; | |
2010 | ||
2011 | shost_for_each_device(sdev, ioc->shost) { | |
2012 | if (skip) | |
2013 | continue; | |
2014 | sas_device_priv_data = sdev->hostdata; | |
2015 | if (!sas_device_priv_data) | |
2016 | continue; | |
2017 | if (sas_device_priv_data->sas_target->handle == handle) { | |
2018 | sas_device_priv_data->sas_target->tm_busy = 0; | |
2019 | skip = 1; | |
2020 | ioc->ignore_loginfos = 0; | |
2021 | } | |
2022 | } | |
2023 | } | |
2024 | ||
2025 | /** | |
2026 | * mpt3sas_scsih_issue_tm - main routine for sending tm requests | |
2027 | * @ioc: per adapter struct | |
2028 | * @device_handle: device handle | |
2029 | * @channel: the channel assigned by the OS | |
2030 | * @id: the id assigned by the OS | |
2031 | * @lun: lun number | |
2032 | * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h) | |
2033 | * @smid_task: smid assigned to the task | |
2034 | * @timeout: timeout in seconds | |
f92363d1 SR |
2035 | * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF |
2036 | * Context: user | |
2037 | * | |
2038 | * A generic API for sending task management requests to firmware. | |
2039 | * | |
2040 | * The callback index is set inside `ioc->tm_cb_idx`. | |
2041 | * | |
2042 | * Return SUCCESS or FAILED. | |
2043 | */ | |
2044 | int | |
2045 | mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, uint channel, | |
2046 | uint id, uint lun, u8 type, u16 smid_task, ulong timeout, | |
c62e46de | 2047 | enum mutex_type m_type) |
f92363d1 SR |
2048 | { |
2049 | Mpi2SCSITaskManagementRequest_t *mpi_request; | |
2050 | Mpi2SCSITaskManagementReply_t *mpi_reply; | |
2051 | u16 smid = 0; | |
2052 | u32 ioc_state; | |
2053 | unsigned long timeleft; | |
2054 | struct scsiio_tracker *scsi_lookup = NULL; | |
2055 | int rc; | |
2056 | ||
2057 | if (m_type == TM_MUTEX_ON) | |
2058 | mutex_lock(&ioc->tm_cmds.mutex); | |
2059 | if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) { | |
2060 | pr_info(MPT3SAS_FMT "%s: tm_cmd busy!!!\n", | |
2061 | __func__, ioc->name); | |
2062 | rc = FAILED; | |
2063 | goto err_out; | |
2064 | } | |
2065 | ||
2066 | if (ioc->shost_recovery || ioc->remove_host || | |
2067 | ioc->pci_error_recovery) { | |
2068 | pr_info(MPT3SAS_FMT "%s: host reset in progress!\n", | |
2069 | __func__, ioc->name); | |
2070 | rc = FAILED; | |
2071 | goto err_out; | |
2072 | } | |
2073 | ||
2074 | ioc_state = mpt3sas_base_get_iocstate(ioc, 0); | |
2075 | if (ioc_state & MPI2_DOORBELL_USED) { | |
2076 | dhsprintk(ioc, pr_info(MPT3SAS_FMT | |
2077 | "unexpected doorbell active!\n", ioc->name)); | |
2078 | rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, | |
2079 | FORCE_BIG_HAMMER); | |
2080 | rc = (!rc) ? SUCCESS : FAILED; | |
2081 | goto err_out; | |
2082 | } | |
2083 | ||
2084 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { | |
2085 | mpt3sas_base_fault_info(ioc, ioc_state & | |
2086 | MPI2_DOORBELL_DATA_MASK); | |
2087 | rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, | |
2088 | FORCE_BIG_HAMMER); | |
2089 | rc = (!rc) ? SUCCESS : FAILED; | |
2090 | goto err_out; | |
2091 | } | |
2092 | ||
2093 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx); | |
2094 | if (!smid) { | |
2095 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
2096 | ioc->name, __func__); | |
2097 | rc = FAILED; | |
2098 | goto err_out; | |
2099 | } | |
2100 | ||
2101 | if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) | |
2102 | scsi_lookup = &ioc->scsi_lookup[smid_task - 1]; | |
2103 | ||
2104 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
2105 | "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n", | |
2106 | ioc->name, handle, type, smid_task)); | |
2107 | ioc->tm_cmds.status = MPT3_CMD_PENDING; | |
2108 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
2109 | ioc->tm_cmds.smid = smid; | |
2110 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | |
2111 | memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t)); | |
2112 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | |
2113 | mpi_request->DevHandle = cpu_to_le16(handle); | |
2114 | mpi_request->TaskType = type; | |
2115 | mpi_request->TaskMID = cpu_to_le16(smid_task); | |
2116 | int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN); | |
2117 | mpt3sas_scsih_set_tm_flag(ioc, handle); | |
2118 | init_completion(&ioc->tm_cmds.done); | |
2119 | mpt3sas_base_put_smid_hi_priority(ioc, smid); | |
2120 | timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ); | |
2121 | if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) { | |
2122 | pr_err(MPT3SAS_FMT "%s: timeout\n", | |
2123 | ioc->name, __func__); | |
2124 | _debug_dump_mf(mpi_request, | |
2125 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); | |
2126 | if (!(ioc->tm_cmds.status & MPT3_CMD_RESET)) { | |
2127 | rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, | |
2128 | FORCE_BIG_HAMMER); | |
2129 | rc = (!rc) ? SUCCESS : FAILED; | |
2130 | ioc->tm_cmds.status = MPT3_CMD_NOT_USED; | |
2131 | mpt3sas_scsih_clear_tm_flag(ioc, handle); | |
2132 | goto err_out; | |
2133 | } | |
2134 | } | |
2135 | ||
2136 | if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) { | |
2137 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT); | |
2138 | mpi_reply = ioc->tm_cmds.reply; | |
2139 | dtmprintk(ioc, pr_info(MPT3SAS_FMT "complete tm: " \ | |
2140 | "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n", | |
2141 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), | |
2142 | le32_to_cpu(mpi_reply->IOCLogInfo), | |
2143 | le32_to_cpu(mpi_reply->TerminationCount))); | |
2144 | if (ioc->logging_level & MPT_DEBUG_TM) { | |
2145 | _scsih_response_code(ioc, mpi_reply->ResponseCode); | |
2146 | if (mpi_reply->IOCStatus) | |
2147 | _debug_dump_mf(mpi_request, | |
2148 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); | |
2149 | } | |
2150 | } | |
2151 | ||
2152 | switch (type) { | |
2153 | case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK: | |
2154 | rc = SUCCESS; | |
2155 | if (scsi_lookup->scmd == NULL) | |
2156 | break; | |
2157 | rc = FAILED; | |
2158 | break; | |
2159 | ||
2160 | case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET: | |
2161 | if (_scsih_scsi_lookup_find_by_target(ioc, id, channel)) | |
2162 | rc = FAILED; | |
2163 | else | |
2164 | rc = SUCCESS; | |
2165 | break; | |
2166 | case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET: | |
2167 | case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET: | |
2168 | if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel)) | |
2169 | rc = FAILED; | |
2170 | else | |
2171 | rc = SUCCESS; | |
2172 | break; | |
2173 | case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK: | |
2174 | rc = SUCCESS; | |
2175 | break; | |
2176 | default: | |
2177 | rc = FAILED; | |
2178 | break; | |
2179 | } | |
2180 | ||
2181 | mpt3sas_scsih_clear_tm_flag(ioc, handle); | |
2182 | ioc->tm_cmds.status = MPT3_CMD_NOT_USED; | |
2183 | if (m_type == TM_MUTEX_ON) | |
2184 | mutex_unlock(&ioc->tm_cmds.mutex); | |
2185 | ||
2186 | return rc; | |
2187 | ||
2188 | err_out: | |
2189 | if (m_type == TM_MUTEX_ON) | |
2190 | mutex_unlock(&ioc->tm_cmds.mutex); | |
2191 | return rc; | |
2192 | } | |
2193 | ||
2194 | /** | |
2195 | * _scsih_tm_display_info - displays info about the device | |
2196 | * @ioc: per adapter struct | |
2197 | * @scmd: pointer to scsi command object | |
2198 | * | |
2199 | * Called by task management callback handlers. | |
2200 | */ | |
2201 | static void | |
2202 | _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd) | |
2203 | { | |
2204 | struct scsi_target *starget = scmd->device->sdev_target; | |
2205 | struct MPT3SAS_TARGET *priv_target = starget->hostdata; | |
2206 | struct _sas_device *sas_device = NULL; | |
2207 | unsigned long flags; | |
2208 | char *device_str = NULL; | |
2209 | ||
2210 | if (!priv_target) | |
2211 | return; | |
7786ab6a SR |
2212 | if (ioc->hide_ir_msg) |
2213 | device_str = "WarpDrive"; | |
2214 | else | |
2215 | device_str = "volume"; | |
f92363d1 SR |
2216 | |
2217 | scsi_print_command(scmd); | |
2218 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { | |
2219 | starget_printk(KERN_INFO, starget, | |
2220 | "%s handle(0x%04x), %s wwid(0x%016llx)\n", | |
2221 | device_str, priv_target->handle, | |
2222 | device_str, (unsigned long long)priv_target->sas_address); | |
2223 | } else { | |
2224 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
2225 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, | |
2226 | priv_target->sas_address); | |
2227 | if (sas_device) { | |
2228 | if (priv_target->flags & | |
2229 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
2230 | starget_printk(KERN_INFO, starget, | |
2231 | "volume handle(0x%04x), " | |
2232 | "volume wwid(0x%016llx)\n", | |
2233 | sas_device->volume_handle, | |
2234 | (unsigned long long)sas_device->volume_wwid); | |
2235 | } | |
2236 | starget_printk(KERN_INFO, starget, | |
2237 | "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n", | |
2238 | sas_device->handle, | |
2239 | (unsigned long long)sas_device->sas_address, | |
2240 | sas_device->phy); | |
e6d45e3e SR |
2241 | if (sas_device->enclosure_handle != 0) |
2242 | starget_printk(KERN_INFO, starget, | |
2243 | "enclosure_logical_id(0x%016llx), slot(%d)\n", | |
2244 | (unsigned long long) | |
2245 | sas_device->enclosure_logical_id, | |
2246 | sas_device->slot); | |
2247 | if (sas_device->connector_name) | |
2248 | starget_printk(KERN_INFO, starget, | |
2249 | "enclosure level(0x%04x),connector name(%s)\n", | |
2250 | sas_device->enclosure_level, | |
2251 | sas_device->connector_name); | |
f92363d1 SR |
2252 | } |
2253 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
2254 | } | |
2255 | } | |
2256 | ||
2257 | /** | |
8a7e4c24 | 2258 | * scsih_abort - eh threads main abort routine |
f92363d1 SR |
2259 | * @scmd: pointer to scsi command object |
2260 | * | |
2261 | * Returns SUCCESS if command aborted else FAILED | |
2262 | */ | |
8a7e4c24 SR |
2263 | int |
2264 | scsih_abort(struct scsi_cmnd *scmd) | |
f92363d1 SR |
2265 | { |
2266 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
2267 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2268 | u16 smid; | |
2269 | u16 handle; | |
2270 | int r; | |
2271 | ||
2272 | sdev_printk(KERN_INFO, scmd->device, | |
2273 | "attempting task abort! scmd(%p)\n", scmd); | |
2274 | _scsih_tm_display_info(ioc, scmd); | |
2275 | ||
2276 | sas_device_priv_data = scmd->device->hostdata; | |
2277 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | |
2278 | sdev_printk(KERN_INFO, scmd->device, | |
2279 | "device been deleted! scmd(%p)\n", scmd); | |
2280 | scmd->result = DID_NO_CONNECT << 16; | |
2281 | scmd->scsi_done(scmd); | |
2282 | r = SUCCESS; | |
2283 | goto out; | |
2284 | } | |
2285 | ||
2286 | /* search for the command */ | |
2287 | smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd); | |
2288 | if (!smid) { | |
2289 | scmd->result = DID_RESET << 16; | |
2290 | r = SUCCESS; | |
2291 | goto out; | |
2292 | } | |
2293 | ||
2294 | /* for hidden raid components and volumes this is not supported */ | |
2295 | if (sas_device_priv_data->sas_target->flags & | |
2296 | MPT_TARGET_FLAGS_RAID_COMPONENT || | |
2297 | sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) { | |
2298 | scmd->result = DID_RESET << 16; | |
2299 | r = FAILED; | |
2300 | goto out; | |
2301 | } | |
2302 | ||
2303 | mpt3sas_halt_firmware(ioc); | |
2304 | ||
2305 | handle = sas_device_priv_data->sas_target->handle; | |
2306 | r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel, | |
2307 | scmd->device->id, scmd->device->lun, | |
c62e46de | 2308 | MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, TM_MUTEX_ON); |
f92363d1 SR |
2309 | |
2310 | out: | |
2311 | sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n", | |
2312 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
2313 | return r; | |
2314 | } | |
2315 | ||
2316 | /** | |
8a7e4c24 | 2317 | * scsih_dev_reset - eh threads main device reset routine |
f92363d1 SR |
2318 | * @scmd: pointer to scsi command object |
2319 | * | |
2320 | * Returns SUCCESS if command aborted else FAILED | |
2321 | */ | |
8a7e4c24 SR |
2322 | int |
2323 | scsih_dev_reset(struct scsi_cmnd *scmd) | |
f92363d1 SR |
2324 | { |
2325 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
2326 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2327 | struct _sas_device *sas_device; | |
2328 | unsigned long flags; | |
2329 | u16 handle; | |
2330 | int r; | |
2331 | ||
2332 | sdev_printk(KERN_INFO, scmd->device, | |
2333 | "attempting device reset! scmd(%p)\n", scmd); | |
2334 | _scsih_tm_display_info(ioc, scmd); | |
2335 | ||
2336 | sas_device_priv_data = scmd->device->hostdata; | |
2337 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | |
2338 | sdev_printk(KERN_INFO, scmd->device, | |
2339 | "device been deleted! scmd(%p)\n", scmd); | |
2340 | scmd->result = DID_NO_CONNECT << 16; | |
2341 | scmd->scsi_done(scmd); | |
2342 | r = SUCCESS; | |
2343 | goto out; | |
2344 | } | |
2345 | ||
2346 | /* for hidden raid components obtain the volume_handle */ | |
2347 | handle = 0; | |
2348 | if (sas_device_priv_data->sas_target->flags & | |
2349 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
2350 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
2351 | sas_device = _scsih_sas_device_find_by_handle(ioc, | |
2352 | sas_device_priv_data->sas_target->handle); | |
2353 | if (sas_device) | |
2354 | handle = sas_device->volume_handle; | |
2355 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
2356 | } else | |
2357 | handle = sas_device_priv_data->sas_target->handle; | |
2358 | ||
2359 | if (!handle) { | |
2360 | scmd->result = DID_RESET << 16; | |
2361 | r = FAILED; | |
2362 | goto out; | |
2363 | } | |
2364 | ||
2365 | r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel, | |
2366 | scmd->device->id, scmd->device->lun, | |
c62e46de | 2367 | MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, TM_MUTEX_ON); |
f92363d1 SR |
2368 | |
2369 | out: | |
2370 | sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n", | |
2371 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
2372 | return r; | |
2373 | } | |
2374 | ||
2375 | /** | |
8a7e4c24 | 2376 | * scsih_target_reset - eh threads main target reset routine |
f92363d1 SR |
2377 | * @scmd: pointer to scsi command object |
2378 | * | |
2379 | * Returns SUCCESS if command aborted else FAILED | |
2380 | */ | |
8a7e4c24 SR |
2381 | int |
2382 | scsih_target_reset(struct scsi_cmnd *scmd) | |
f92363d1 SR |
2383 | { |
2384 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
2385 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2386 | struct _sas_device *sas_device; | |
2387 | unsigned long flags; | |
2388 | u16 handle; | |
2389 | int r; | |
2390 | struct scsi_target *starget = scmd->device->sdev_target; | |
2391 | ||
2392 | starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n", | |
2393 | scmd); | |
2394 | _scsih_tm_display_info(ioc, scmd); | |
2395 | ||
2396 | sas_device_priv_data = scmd->device->hostdata; | |
2397 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | |
2398 | starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n", | |
2399 | scmd); | |
2400 | scmd->result = DID_NO_CONNECT << 16; | |
2401 | scmd->scsi_done(scmd); | |
2402 | r = SUCCESS; | |
2403 | goto out; | |
2404 | } | |
2405 | ||
2406 | /* for hidden raid components obtain the volume_handle */ | |
2407 | handle = 0; | |
2408 | if (sas_device_priv_data->sas_target->flags & | |
2409 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
2410 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
2411 | sas_device = _scsih_sas_device_find_by_handle(ioc, | |
2412 | sas_device_priv_data->sas_target->handle); | |
2413 | if (sas_device) | |
2414 | handle = sas_device->volume_handle; | |
2415 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
2416 | } else | |
2417 | handle = sas_device_priv_data->sas_target->handle; | |
2418 | ||
2419 | if (!handle) { | |
2420 | scmd->result = DID_RESET << 16; | |
2421 | r = FAILED; | |
2422 | goto out; | |
2423 | } | |
2424 | ||
2425 | r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel, | |
2426 | scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, | |
c62e46de | 2427 | 30, TM_MUTEX_ON); |
f92363d1 SR |
2428 | |
2429 | out: | |
2430 | starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n", | |
2431 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
2432 | return r; | |
2433 | } | |
2434 | ||
2435 | ||
2436 | /** | |
8a7e4c24 | 2437 | * scsih_host_reset - eh threads main host reset routine |
f92363d1 SR |
2438 | * @scmd: pointer to scsi command object |
2439 | * | |
2440 | * Returns SUCCESS if command aborted else FAILED | |
2441 | */ | |
8a7e4c24 SR |
2442 | int |
2443 | scsih_host_reset(struct scsi_cmnd *scmd) | |
f92363d1 SR |
2444 | { |
2445 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
2446 | int r, retval; | |
2447 | ||
2448 | pr_info(MPT3SAS_FMT "attempting host reset! scmd(%p)\n", | |
2449 | ioc->name, scmd); | |
2450 | scsi_print_command(scmd); | |
2451 | ||
ddb588be SR |
2452 | if (ioc->is_driver_loading) { |
2453 | pr_info(MPT3SAS_FMT "Blocking the host reset\n", | |
2454 | ioc->name); | |
2455 | r = FAILED; | |
2456 | goto out; | |
2457 | } | |
2458 | ||
f92363d1 SR |
2459 | retval = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
2460 | FORCE_BIG_HAMMER); | |
2461 | r = (retval < 0) ? FAILED : SUCCESS; | |
ddb588be | 2462 | out: |
f92363d1 SR |
2463 | pr_info(MPT3SAS_FMT "host reset: %s scmd(%p)\n", |
2464 | ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
2465 | ||
2466 | return r; | |
2467 | } | |
2468 | ||
2469 | /** | |
2470 | * _scsih_fw_event_add - insert and queue up fw_event | |
2471 | * @ioc: per adapter object | |
2472 | * @fw_event: object describing the event | |
2473 | * Context: This function will acquire ioc->fw_event_lock. | |
2474 | * | |
2475 | * This adds the firmware event object into link list, then queues it up to | |
2476 | * be processed from user context. | |
2477 | * | |
2478 | * Return nothing. | |
2479 | */ | |
2480 | static void | |
2481 | _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event) | |
2482 | { | |
2483 | unsigned long flags; | |
2484 | ||
2485 | if (ioc->firmware_event_thread == NULL) | |
2486 | return; | |
2487 | ||
2488 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
2489 | INIT_LIST_HEAD(&fw_event->list); | |
2490 | list_add_tail(&fw_event->list, &ioc->fw_event_list); | |
2491 | INIT_WORK(&fw_event->work, _firmware_event_work); | |
2492 | queue_work(ioc->firmware_event_thread, &fw_event->work); | |
2493 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
2494 | } | |
2495 | ||
2496 | /** | |
2497 | * _scsih_fw_event_free - delete fw_event | |
2498 | * @ioc: per adapter object | |
2499 | * @fw_event: object describing the event | |
2500 | * Context: This function will acquire ioc->fw_event_lock. | |
2501 | * | |
2502 | * This removes firmware event object from link list, frees associated memory. | |
2503 | * | |
2504 | * Return nothing. | |
2505 | */ | |
2506 | static void | |
2507 | _scsih_fw_event_free(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work | |
2508 | *fw_event) | |
2509 | { | |
2510 | unsigned long flags; | |
2511 | ||
2512 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
2513 | list_del(&fw_event->list); | |
f92363d1 SR |
2514 | kfree(fw_event); |
2515 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
2516 | } | |
2517 | ||
2518 | ||
2519 | /** | |
2520 | * mpt3sas_send_trigger_data_event - send event for processing trigger data | |
2521 | * @ioc: per adapter object | |
2522 | * @event_data: trigger event data | |
2523 | * | |
2524 | * Return nothing. | |
2525 | */ | |
2526 | void | |
2527 | mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc, | |
2528 | struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data) | |
2529 | { | |
2530 | struct fw_event_work *fw_event; | |
2531 | ||
2532 | if (ioc->is_driver_loading) | |
2533 | return; | |
35b62362 JL |
2534 | fw_event = kzalloc(sizeof(*fw_event) + sizeof(*event_data), |
2535 | GFP_ATOMIC); | |
f92363d1 SR |
2536 | if (!fw_event) |
2537 | return; | |
f92363d1 SR |
2538 | fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG; |
2539 | fw_event->ioc = ioc; | |
2540 | memcpy(fw_event->event_data, event_data, sizeof(*event_data)); | |
2541 | _scsih_fw_event_add(ioc, fw_event); | |
2542 | } | |
2543 | ||
2544 | /** | |
2545 | * _scsih_error_recovery_delete_devices - remove devices not responding | |
2546 | * @ioc: per adapter object | |
2547 | * | |
2548 | * Return nothing. | |
2549 | */ | |
2550 | static void | |
2551 | _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc) | |
2552 | { | |
2553 | struct fw_event_work *fw_event; | |
2554 | ||
2555 | if (ioc->is_driver_loading) | |
2556 | return; | |
2557 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); | |
2558 | if (!fw_event) | |
2559 | return; | |
2560 | fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES; | |
2561 | fw_event->ioc = ioc; | |
2562 | _scsih_fw_event_add(ioc, fw_event); | |
2563 | } | |
2564 | ||
2565 | /** | |
2566 | * mpt3sas_port_enable_complete - port enable completed (fake event) | |
2567 | * @ioc: per adapter object | |
2568 | * | |
2569 | * Return nothing. | |
2570 | */ | |
2571 | void | |
2572 | mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc) | |
2573 | { | |
2574 | struct fw_event_work *fw_event; | |
2575 | ||
2576 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); | |
2577 | if (!fw_event) | |
2578 | return; | |
2579 | fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE; | |
2580 | fw_event->ioc = ioc; | |
2581 | _scsih_fw_event_add(ioc, fw_event); | |
2582 | } | |
2583 | ||
2584 | /** | |
2585 | * _scsih_fw_event_cleanup_queue - cleanup event queue | |
2586 | * @ioc: per adapter object | |
2587 | * | |
2588 | * Walk the firmware event queue, either killing timers, or waiting | |
2589 | * for outstanding events to complete | |
2590 | * | |
2591 | * Return nothing. | |
2592 | */ | |
2593 | static void | |
2594 | _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc) | |
2595 | { | |
2596 | struct fw_event_work *fw_event, *next; | |
2597 | ||
2598 | if (list_empty(&ioc->fw_event_list) || | |
2599 | !ioc->firmware_event_thread || in_interrupt()) | |
2600 | return; | |
2601 | ||
2602 | list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) { | |
4dc06fd8 | 2603 | if (cancel_delayed_work_sync(&fw_event->delayed_work)) { |
f92363d1 SR |
2604 | _scsih_fw_event_free(ioc, fw_event); |
2605 | continue; | |
2606 | } | |
f92363d1 SR |
2607 | } |
2608 | } | |
2609 | ||
df838f92 SR |
2610 | /** |
2611 | * _scsih_internal_device_block - block the sdev device | |
2612 | * @sdev: per device object | |
2613 | * @sas_device_priv_data : per device driver private data | |
2614 | * | |
2615 | * make sure device is blocked without error, if not | |
2616 | * print an error | |
2617 | */ | |
2618 | static void | |
2619 | _scsih_internal_device_block(struct scsi_device *sdev, | |
2620 | struct MPT3SAS_DEVICE *sas_device_priv_data) | |
2621 | { | |
2622 | int r = 0; | |
2623 | ||
2624 | sdev_printk(KERN_INFO, sdev, "device_block, handle(0x%04x)\n", | |
2625 | sas_device_priv_data->sas_target->handle); | |
2626 | sas_device_priv_data->block = 1; | |
2627 | ||
2628 | r = scsi_internal_device_block(sdev); | |
2629 | if (r == -EINVAL) | |
2630 | sdev_printk(KERN_WARNING, sdev, | |
2631 | "device_block failed with return(%d) for handle(0x%04x)\n", | |
2632 | sas_device_priv_data->sas_target->handle, r); | |
2633 | } | |
2634 | ||
2635 | /** | |
2636 | * _scsih_internal_device_unblock - unblock the sdev device | |
2637 | * @sdev: per device object | |
2638 | * @sas_device_priv_data : per device driver private data | |
2639 | * make sure device is unblocked without error, if not retry | |
2640 | * by blocking and then unblocking | |
2641 | */ | |
2642 | ||
2643 | static void | |
2644 | _scsih_internal_device_unblock(struct scsi_device *sdev, | |
2645 | struct MPT3SAS_DEVICE *sas_device_priv_data) | |
2646 | { | |
2647 | int r = 0; | |
2648 | ||
2649 | sdev_printk(KERN_WARNING, sdev, "device_unblock and setting to running, " | |
2650 | "handle(0x%04x)\n", sas_device_priv_data->sas_target->handle); | |
2651 | sas_device_priv_data->block = 0; | |
2652 | r = scsi_internal_device_unblock(sdev, SDEV_RUNNING); | |
2653 | if (r == -EINVAL) { | |
2654 | /* The device has been set to SDEV_RUNNING by SD layer during | |
2655 | * device addition but the request queue is still stopped by | |
2656 | * our earlier block call. We need to perform a block again | |
2657 | * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */ | |
2658 | ||
2659 | sdev_printk(KERN_WARNING, sdev, | |
2660 | "device_unblock failed with return(%d) for handle(0x%04x) " | |
2661 | "performing a block followed by an unblock\n", | |
2662 | sas_device_priv_data->sas_target->handle, r); | |
2663 | sas_device_priv_data->block = 1; | |
2664 | r = scsi_internal_device_block(sdev); | |
2665 | if (r) | |
2666 | sdev_printk(KERN_WARNING, sdev, "retried device_block " | |
2667 | "failed with return(%d) for handle(0x%04x)\n", | |
2668 | sas_device_priv_data->sas_target->handle, r); | |
2669 | ||
2670 | sas_device_priv_data->block = 0; | |
2671 | r = scsi_internal_device_unblock(sdev, SDEV_RUNNING); | |
2672 | if (r) | |
2673 | sdev_printk(KERN_WARNING, sdev, "retried device_unblock" | |
2674 | " failed with return(%d) for handle(0x%04x)\n", | |
2675 | sas_device_priv_data->sas_target->handle, r); | |
2676 | } | |
2677 | } | |
2678 | ||
f92363d1 SR |
2679 | /** |
2680 | * _scsih_ublock_io_all_device - unblock every device | |
2681 | * @ioc: per adapter object | |
2682 | * | |
2683 | * change the device state from block to running | |
2684 | */ | |
2685 | static void | |
2686 | _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc) | |
2687 | { | |
2688 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2689 | struct scsi_device *sdev; | |
2690 | ||
2691 | shost_for_each_device(sdev, ioc->shost) { | |
2692 | sas_device_priv_data = sdev->hostdata; | |
2693 | if (!sas_device_priv_data) | |
2694 | continue; | |
2695 | if (!sas_device_priv_data->block) | |
2696 | continue; | |
2697 | ||
f92363d1 SR |
2698 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, |
2699 | "device_running, handle(0x%04x)\n", | |
2700 | sas_device_priv_data->sas_target->handle)); | |
df838f92 | 2701 | _scsih_internal_device_unblock(sdev, sas_device_priv_data); |
f92363d1 SR |
2702 | } |
2703 | } | |
2704 | ||
2705 | ||
2706 | /** | |
2707 | * _scsih_ublock_io_device - prepare device to be deleted | |
2708 | * @ioc: per adapter object | |
2709 | * @sas_addr: sas address | |
2710 | * | |
2711 | * unblock then put device in offline state | |
2712 | */ | |
2713 | static void | |
2714 | _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address) | |
2715 | { | |
2716 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2717 | struct scsi_device *sdev; | |
2718 | ||
2719 | shost_for_each_device(sdev, ioc->shost) { | |
2720 | sas_device_priv_data = sdev->hostdata; | |
2721 | if (!sas_device_priv_data) | |
2722 | continue; | |
2723 | if (sas_device_priv_data->sas_target->sas_address | |
2724 | != sas_address) | |
2725 | continue; | |
df838f92 SR |
2726 | if (sas_device_priv_data->block) |
2727 | _scsih_internal_device_unblock(sdev, | |
2728 | sas_device_priv_data); | |
f92363d1 SR |
2729 | } |
2730 | } | |
2731 | ||
2732 | /** | |
2733 | * _scsih_block_io_all_device - set the device state to SDEV_BLOCK | |
2734 | * @ioc: per adapter object | |
2735 | * @handle: device handle | |
2736 | * | |
2737 | * During device pull we need to appropiately set the sdev state. | |
2738 | */ | |
2739 | static void | |
2740 | _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc) | |
2741 | { | |
2742 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2743 | struct scsi_device *sdev; | |
2744 | ||
2745 | shost_for_each_device(sdev, ioc->shost) { | |
2746 | sas_device_priv_data = sdev->hostdata; | |
2747 | if (!sas_device_priv_data) | |
2748 | continue; | |
2749 | if (sas_device_priv_data->block) | |
2750 | continue; | |
df838f92 | 2751 | _scsih_internal_device_block(sdev, sas_device_priv_data); |
f92363d1 SR |
2752 | } |
2753 | } | |
2754 | ||
2755 | /** | |
2756 | * _scsih_block_io_device - set the device state to SDEV_BLOCK | |
2757 | * @ioc: per adapter object | |
2758 | * @handle: device handle | |
2759 | * | |
2760 | * During device pull we need to appropiately set the sdev state. | |
2761 | */ | |
2762 | static void | |
2763 | _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
2764 | { | |
2765 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2766 | struct scsi_device *sdev; | |
e4bc7f5c SR |
2767 | struct _sas_device *sas_device; |
2768 | ||
2769 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); | |
2770 | if (!sas_device) | |
2771 | return; | |
f92363d1 SR |
2772 | |
2773 | shost_for_each_device(sdev, ioc->shost) { | |
2774 | sas_device_priv_data = sdev->hostdata; | |
2775 | if (!sas_device_priv_data) | |
2776 | continue; | |
2777 | if (sas_device_priv_data->sas_target->handle != handle) | |
2778 | continue; | |
2779 | if (sas_device_priv_data->block) | |
2780 | continue; | |
e4bc7f5c SR |
2781 | if (sas_device->pend_sas_rphy_add) |
2782 | continue; | |
df838f92 | 2783 | _scsih_internal_device_block(sdev, sas_device_priv_data); |
f92363d1 SR |
2784 | } |
2785 | } | |
2786 | ||
2787 | /** | |
2788 | * _scsih_block_io_to_children_attached_to_ex | |
2789 | * @ioc: per adapter object | |
2790 | * @sas_expander: the sas_device object | |
2791 | * | |
2792 | * This routine set sdev state to SDEV_BLOCK for all devices | |
2793 | * attached to this expander. This function called when expander is | |
2794 | * pulled. | |
2795 | */ | |
2796 | static void | |
2797 | _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc, | |
2798 | struct _sas_node *sas_expander) | |
2799 | { | |
2800 | struct _sas_port *mpt3sas_port; | |
2801 | struct _sas_device *sas_device; | |
2802 | struct _sas_node *expander_sibling; | |
2803 | unsigned long flags; | |
2804 | ||
2805 | if (!sas_expander) | |
2806 | return; | |
2807 | ||
2808 | list_for_each_entry(mpt3sas_port, | |
2809 | &sas_expander->sas_port_list, port_list) { | |
2810 | if (mpt3sas_port->remote_identify.device_type == | |
2811 | SAS_END_DEVICE) { | |
2812 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
2813 | sas_device = | |
2814 | mpt3sas_scsih_sas_device_find_by_sas_address(ioc, | |
2815 | mpt3sas_port->remote_identify.sas_address); | |
2816 | if (sas_device) | |
2817 | set_bit(sas_device->handle, | |
2818 | ioc->blocking_handles); | |
2819 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
2820 | } | |
2821 | } | |
2822 | ||
2823 | list_for_each_entry(mpt3sas_port, | |
2824 | &sas_expander->sas_port_list, port_list) { | |
2825 | ||
2826 | if (mpt3sas_port->remote_identify.device_type == | |
2827 | SAS_EDGE_EXPANDER_DEVICE || | |
2828 | mpt3sas_port->remote_identify.device_type == | |
2829 | SAS_FANOUT_EXPANDER_DEVICE) { | |
2830 | expander_sibling = | |
2831 | mpt3sas_scsih_expander_find_by_sas_address( | |
2832 | ioc, mpt3sas_port->remote_identify.sas_address); | |
2833 | _scsih_block_io_to_children_attached_to_ex(ioc, | |
2834 | expander_sibling); | |
2835 | } | |
2836 | } | |
2837 | } | |
2838 | ||
2839 | /** | |
2840 | * _scsih_block_io_to_children_attached_directly | |
2841 | * @ioc: per adapter object | |
2842 | * @event_data: topology change event data | |
2843 | * | |
2844 | * This routine set sdev state to SDEV_BLOCK for all devices | |
2845 | * direct attached during device pull. | |
2846 | */ | |
2847 | static void | |
2848 | _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc, | |
2849 | Mpi2EventDataSasTopologyChangeList_t *event_data) | |
2850 | { | |
2851 | int i; | |
2852 | u16 handle; | |
2853 | u16 reason_code; | |
f92363d1 SR |
2854 | |
2855 | for (i = 0; i < event_data->NumEntries; i++) { | |
2856 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
2857 | if (!handle) | |
2858 | continue; | |
f92363d1 SR |
2859 | reason_code = event_data->PHY[i].PhyStatus & |
2860 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
2861 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING) | |
2862 | _scsih_block_io_device(ioc, handle); | |
2863 | } | |
2864 | } | |
2865 | ||
2866 | /** | |
2867 | * _scsih_tm_tr_send - send task management request | |
2868 | * @ioc: per adapter object | |
2869 | * @handle: device handle | |
2870 | * Context: interrupt time. | |
2871 | * | |
2872 | * This code is to initiate the device removal handshake protocol | |
2873 | * with controller firmware. This function will issue target reset | |
2874 | * using high priority request queue. It will send a sas iounit | |
2875 | * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion. | |
2876 | * | |
2877 | * This is designed to send muliple task management request at the same | |
2878 | * time to the fifo. If the fifo is full, we will append the request, | |
2879 | * and process it in a future completion. | |
2880 | */ | |
2881 | static void | |
2882 | _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
2883 | { | |
2884 | Mpi2SCSITaskManagementRequest_t *mpi_request; | |
2885 | u16 smid; | |
2886 | struct _sas_device *sas_device; | |
2887 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; | |
2888 | u64 sas_address = 0; | |
2889 | unsigned long flags; | |
2890 | struct _tr_list *delayed_tr; | |
2891 | u32 ioc_state; | |
2892 | ||
2893 | if (ioc->remove_host) { | |
2894 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
2895 | "%s: host has been removed: handle(0x%04x)\n", | |
2896 | __func__, ioc->name, handle)); | |
2897 | return; | |
2898 | } else if (ioc->pci_error_recovery) { | |
2899 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
2900 | "%s: host in pci error recovery: handle(0x%04x)\n", | |
2901 | __func__, ioc->name, | |
2902 | handle)); | |
2903 | return; | |
2904 | } | |
2905 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); | |
2906 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | |
2907 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
2908 | "%s: host is not operational: handle(0x%04x)\n", | |
2909 | __func__, ioc->name, | |
2910 | handle)); | |
2911 | return; | |
2912 | } | |
2913 | ||
2914 | /* if PD, then return */ | |
2915 | if (test_bit(handle, ioc->pd_handles)) | |
2916 | return; | |
2917 | ||
2918 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
2919 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); | |
2920 | if (sas_device && sas_device->starget && | |
2921 | sas_device->starget->hostdata) { | |
2922 | sas_target_priv_data = sas_device->starget->hostdata; | |
2923 | sas_target_priv_data->deleted = 1; | |
2924 | sas_address = sas_device->sas_address; | |
2925 | } | |
2926 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
2927 | ||
2928 | if (sas_target_priv_data) { | |
2929 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
2930 | "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n", | |
2931 | ioc->name, handle, | |
2932 | (unsigned long long)sas_address)); | |
e6d45e3e SR |
2933 | if (sas_device->enclosure_handle != 0) |
2934 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
2935 | "setting delete flag:enclosure logical id(0x%016llx)," | |
2936 | " slot(%d)\n", ioc->name, (unsigned long long) | |
2937 | sas_device->enclosure_logical_id, | |
2938 | sas_device->slot)); | |
2939 | if (sas_device->connector_name) | |
2940 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
2941 | "setting delete flag: enclosure level(0x%04x)," | |
2942 | " connector name( %s)\n", ioc->name, | |
2943 | sas_device->enclosure_level, | |
2944 | sas_device->connector_name)); | |
f92363d1 SR |
2945 | _scsih_ublock_io_device(ioc, sas_address); |
2946 | sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE; | |
2947 | } | |
2948 | ||
2949 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx); | |
2950 | if (!smid) { | |
2951 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | |
2952 | if (!delayed_tr) | |
2953 | return; | |
2954 | INIT_LIST_HEAD(&delayed_tr->list); | |
2955 | delayed_tr->handle = handle; | |
2956 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); | |
2957 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
2958 | "DELAYED:tr:handle(0x%04x), (open)\n", | |
2959 | ioc->name, handle)); | |
2960 | return; | |
2961 | } | |
2962 | ||
2963 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
2964 | "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
2965 | ioc->name, handle, smid, | |
2966 | ioc->tm_tr_cb_idx)); | |
2967 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
2968 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | |
2969 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | |
2970 | mpi_request->DevHandle = cpu_to_le16(handle); | |
2971 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; | |
2972 | mpt3sas_base_put_smid_hi_priority(ioc, smid); | |
2973 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL); | |
2974 | } | |
2975 | ||
2976 | /** | |
2977 | * _scsih_tm_tr_complete - | |
2978 | * @ioc: per adapter object | |
2979 | * @smid: system request message index | |
2980 | * @msix_index: MSIX table index supplied by the OS | |
2981 | * @reply: reply message frame(lower 32bit addr) | |
2982 | * Context: interrupt time. | |
2983 | * | |
2984 | * This is the target reset completion routine. | |
2985 | * This code is part of the code to initiate the device removal | |
2986 | * handshake protocol with controller firmware. | |
2987 | * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE) | |
2988 | * | |
2989 | * Return 1 meaning mf should be freed from _base_interrupt | |
2990 | * 0 means the mf is freed from this function. | |
2991 | */ | |
2992 | static u8 | |
2993 | _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, | |
2994 | u32 reply) | |
2995 | { | |
2996 | u16 handle; | |
2997 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; | |
2998 | Mpi2SCSITaskManagementReply_t *mpi_reply = | |
2999 | mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
3000 | Mpi2SasIoUnitControlRequest_t *mpi_request; | |
3001 | u16 smid_sas_ctrl; | |
3002 | u32 ioc_state; | |
3003 | ||
3004 | if (ioc->remove_host) { | |
3005 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3006 | "%s: host has been removed\n", __func__, ioc->name)); | |
3007 | return 1; | |
3008 | } else if (ioc->pci_error_recovery) { | |
3009 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3010 | "%s: host in pci error recovery\n", __func__, | |
3011 | ioc->name)); | |
3012 | return 1; | |
3013 | } | |
3014 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); | |
3015 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | |
3016 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3017 | "%s: host is not operational\n", __func__, ioc->name)); | |
3018 | return 1; | |
3019 | } | |
3020 | if (unlikely(!mpi_reply)) { | |
3021 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", | |
3022 | ioc->name, __FILE__, __LINE__, __func__); | |
3023 | return 1; | |
3024 | } | |
3025 | mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid); | |
3026 | handle = le16_to_cpu(mpi_request_tm->DevHandle); | |
3027 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { | |
3028 | dewtprintk(ioc, pr_err(MPT3SAS_FMT | |
3029 | "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n", | |
3030 | ioc->name, handle, | |
3031 | le16_to_cpu(mpi_reply->DevHandle), smid)); | |
3032 | return 0; | |
3033 | } | |
3034 | ||
3035 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT); | |
3036 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3037 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " | |
3038 | "loginfo(0x%08x), completed(%d)\n", ioc->name, | |
3039 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), | |
3040 | le32_to_cpu(mpi_reply->IOCLogInfo), | |
3041 | le32_to_cpu(mpi_reply->TerminationCount))); | |
3042 | ||
3043 | smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx); | |
3044 | if (!smid_sas_ctrl) { | |
3045 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
3046 | ioc->name, __func__); | |
3047 | return 1; | |
3048 | } | |
3049 | ||
3050 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3051 | "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
3052 | ioc->name, handle, smid_sas_ctrl, | |
3053 | ioc->tm_sas_control_cb_idx)); | |
3054 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl); | |
3055 | memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t)); | |
3056 | mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; | |
3057 | mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE; | |
3058 | mpi_request->DevHandle = mpi_request_tm->DevHandle; | |
3059 | mpt3sas_base_put_smid_default(ioc, smid_sas_ctrl); | |
3060 | ||
3061 | return _scsih_check_for_pending_tm(ioc, smid); | |
3062 | } | |
3063 | ||
3064 | ||
3065 | /** | |
3066 | * _scsih_sas_control_complete - completion routine | |
3067 | * @ioc: per adapter object | |
3068 | * @smid: system request message index | |
3069 | * @msix_index: MSIX table index supplied by the OS | |
3070 | * @reply: reply message frame(lower 32bit addr) | |
3071 | * Context: interrupt time. | |
3072 | * | |
3073 | * This is the sas iounit control completion routine. | |
3074 | * This code is part of the code to initiate the device removal | |
3075 | * handshake protocol with controller firmware. | |
3076 | * | |
3077 | * Return 1 meaning mf should be freed from _base_interrupt | |
3078 | * 0 means the mf is freed from this function. | |
3079 | */ | |
3080 | static u8 | |
3081 | _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, | |
3082 | u8 msix_index, u32 reply) | |
3083 | { | |
3084 | Mpi2SasIoUnitControlReply_t *mpi_reply = | |
3085 | mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
3086 | ||
3087 | if (likely(mpi_reply)) { | |
3088 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3089 | "sc_complete:handle(0x%04x), (open) " | |
3090 | "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n", | |
3091 | ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid, | |
3092 | le16_to_cpu(mpi_reply->IOCStatus), | |
3093 | le32_to_cpu(mpi_reply->IOCLogInfo))); | |
3094 | } else { | |
3095 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", | |
3096 | ioc->name, __FILE__, __LINE__, __func__); | |
3097 | } | |
3098 | return 1; | |
3099 | } | |
3100 | ||
3101 | /** | |
3102 | * _scsih_tm_tr_volume_send - send target reset request for volumes | |
3103 | * @ioc: per adapter object | |
3104 | * @handle: device handle | |
3105 | * Context: interrupt time. | |
3106 | * | |
3107 | * This is designed to send muliple task management request at the same | |
3108 | * time to the fifo. If the fifo is full, we will append the request, | |
3109 | * and process it in a future completion. | |
3110 | */ | |
3111 | static void | |
3112 | _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
3113 | { | |
3114 | Mpi2SCSITaskManagementRequest_t *mpi_request; | |
3115 | u16 smid; | |
3116 | struct _tr_list *delayed_tr; | |
3117 | ||
3118 | if (ioc->shost_recovery || ioc->remove_host || | |
3119 | ioc->pci_error_recovery) { | |
3120 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3121 | "%s: host reset in progress!\n", | |
3122 | __func__, ioc->name)); | |
3123 | return; | |
3124 | } | |
3125 | ||
3126 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx); | |
3127 | if (!smid) { | |
3128 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | |
3129 | if (!delayed_tr) | |
3130 | return; | |
3131 | INIT_LIST_HEAD(&delayed_tr->list); | |
3132 | delayed_tr->handle = handle; | |
3133 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list); | |
3134 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3135 | "DELAYED:tr:handle(0x%04x), (open)\n", | |
3136 | ioc->name, handle)); | |
3137 | return; | |
3138 | } | |
3139 | ||
3140 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3141 | "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
3142 | ioc->name, handle, smid, | |
3143 | ioc->tm_tr_volume_cb_idx)); | |
3144 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
3145 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | |
3146 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | |
3147 | mpi_request->DevHandle = cpu_to_le16(handle); | |
3148 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; | |
3149 | mpt3sas_base_put_smid_hi_priority(ioc, smid); | |
3150 | } | |
3151 | ||
3152 | /** | |
3153 | * _scsih_tm_volume_tr_complete - target reset completion | |
3154 | * @ioc: per adapter object | |
3155 | * @smid: system request message index | |
3156 | * @msix_index: MSIX table index supplied by the OS | |
3157 | * @reply: reply message frame(lower 32bit addr) | |
3158 | * Context: interrupt time. | |
3159 | * | |
3160 | * Return 1 meaning mf should be freed from _base_interrupt | |
3161 | * 0 means the mf is freed from this function. | |
3162 | */ | |
3163 | static u8 | |
3164 | _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, | |
3165 | u8 msix_index, u32 reply) | |
3166 | { | |
3167 | u16 handle; | |
3168 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; | |
3169 | Mpi2SCSITaskManagementReply_t *mpi_reply = | |
3170 | mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
3171 | ||
3172 | if (ioc->shost_recovery || ioc->remove_host || | |
3173 | ioc->pci_error_recovery) { | |
3174 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3175 | "%s: host reset in progress!\n", | |
3176 | __func__, ioc->name)); | |
3177 | return 1; | |
3178 | } | |
3179 | if (unlikely(!mpi_reply)) { | |
3180 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", | |
3181 | ioc->name, __FILE__, __LINE__, __func__); | |
3182 | return 1; | |
3183 | } | |
3184 | ||
3185 | mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid); | |
3186 | handle = le16_to_cpu(mpi_request_tm->DevHandle); | |
3187 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { | |
3188 | dewtprintk(ioc, pr_err(MPT3SAS_FMT | |
3189 | "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n", | |
3190 | ioc->name, handle, | |
3191 | le16_to_cpu(mpi_reply->DevHandle), smid)); | |
3192 | return 0; | |
3193 | } | |
3194 | ||
3195 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3196 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " | |
3197 | "loginfo(0x%08x), completed(%d)\n", ioc->name, | |
3198 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), | |
3199 | le32_to_cpu(mpi_reply->IOCLogInfo), | |
3200 | le32_to_cpu(mpi_reply->TerminationCount))); | |
3201 | ||
3202 | return _scsih_check_for_pending_tm(ioc, smid); | |
3203 | } | |
3204 | ||
3205 | ||
3206 | /** | |
3207 | * _scsih_check_for_pending_tm - check for pending task management | |
3208 | * @ioc: per adapter object | |
3209 | * @smid: system request message index | |
3210 | * | |
3211 | * This will check delayed target reset list, and feed the | |
3212 | * next reqeust. | |
3213 | * | |
3214 | * Return 1 meaning mf should be freed from _base_interrupt | |
3215 | * 0 means the mf is freed from this function. | |
3216 | */ | |
3217 | static u8 | |
3218 | _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid) | |
3219 | { | |
3220 | struct _tr_list *delayed_tr; | |
3221 | ||
3222 | if (!list_empty(&ioc->delayed_tr_volume_list)) { | |
3223 | delayed_tr = list_entry(ioc->delayed_tr_volume_list.next, | |
3224 | struct _tr_list, list); | |
3225 | mpt3sas_base_free_smid(ioc, smid); | |
3226 | _scsih_tm_tr_volume_send(ioc, delayed_tr->handle); | |
3227 | list_del(&delayed_tr->list); | |
3228 | kfree(delayed_tr); | |
3229 | return 0; | |
3230 | } | |
3231 | ||
3232 | if (!list_empty(&ioc->delayed_tr_list)) { | |
3233 | delayed_tr = list_entry(ioc->delayed_tr_list.next, | |
3234 | struct _tr_list, list); | |
3235 | mpt3sas_base_free_smid(ioc, smid); | |
3236 | _scsih_tm_tr_send(ioc, delayed_tr->handle); | |
3237 | list_del(&delayed_tr->list); | |
3238 | kfree(delayed_tr); | |
3239 | return 0; | |
3240 | } | |
3241 | ||
3242 | return 1; | |
3243 | } | |
3244 | ||
3245 | /** | |
3246 | * _scsih_check_topo_delete_events - sanity check on topo events | |
3247 | * @ioc: per adapter object | |
3248 | * @event_data: the event data payload | |
3249 | * | |
3250 | * This routine added to better handle cable breaker. | |
3251 | * | |
3252 | * This handles the case where driver receives multiple expander | |
3253 | * add and delete events in a single shot. When there is a delete event | |
3254 | * the routine will void any pending add events waiting in the event queue. | |
3255 | * | |
3256 | * Return nothing. | |
3257 | */ | |
3258 | static void | |
3259 | _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc, | |
3260 | Mpi2EventDataSasTopologyChangeList_t *event_data) | |
3261 | { | |
3262 | struct fw_event_work *fw_event; | |
3263 | Mpi2EventDataSasTopologyChangeList_t *local_event_data; | |
3264 | u16 expander_handle; | |
3265 | struct _sas_node *sas_expander; | |
3266 | unsigned long flags; | |
3267 | int i, reason_code; | |
3268 | u16 handle; | |
3269 | ||
3270 | for (i = 0 ; i < event_data->NumEntries; i++) { | |
3271 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
3272 | if (!handle) | |
3273 | continue; | |
3274 | reason_code = event_data->PHY[i].PhyStatus & | |
3275 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
3276 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING) | |
3277 | _scsih_tm_tr_send(ioc, handle); | |
3278 | } | |
3279 | ||
3280 | expander_handle = le16_to_cpu(event_data->ExpanderDevHandle); | |
3281 | if (expander_handle < ioc->sas_hba.num_phys) { | |
3282 | _scsih_block_io_to_children_attached_directly(ioc, event_data); | |
3283 | return; | |
3284 | } | |
3285 | if (event_data->ExpStatus == | |
3286 | MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) { | |
3287 | /* put expander attached devices into blocking state */ | |
3288 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
3289 | sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc, | |
3290 | expander_handle); | |
3291 | _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander); | |
3292 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
3293 | do { | |
3294 | handle = find_first_bit(ioc->blocking_handles, | |
3295 | ioc->facts.MaxDevHandle); | |
3296 | if (handle < ioc->facts.MaxDevHandle) | |
3297 | _scsih_block_io_device(ioc, handle); | |
3298 | } while (test_and_clear_bit(handle, ioc->blocking_handles)); | |
3299 | } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING) | |
3300 | _scsih_block_io_to_children_attached_directly(ioc, event_data); | |
3301 | ||
3302 | if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) | |
3303 | return; | |
3304 | ||
3305 | /* mark ignore flag for pending events */ | |
3306 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
3307 | list_for_each_entry(fw_event, &ioc->fw_event_list, list) { | |
3308 | if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST || | |
3309 | fw_event->ignore) | |
3310 | continue; | |
35b62362 JL |
3311 | local_event_data = (Mpi2EventDataSasTopologyChangeList_t *) |
3312 | fw_event->event_data; | |
f92363d1 SR |
3313 | if (local_event_data->ExpStatus == |
3314 | MPI2_EVENT_SAS_TOPO_ES_ADDED || | |
3315 | local_event_data->ExpStatus == | |
3316 | MPI2_EVENT_SAS_TOPO_ES_RESPONDING) { | |
3317 | if (le16_to_cpu(local_event_data->ExpanderDevHandle) == | |
3318 | expander_handle) { | |
3319 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3320 | "setting ignoring flag\n", ioc->name)); | |
3321 | fw_event->ignore = 1; | |
3322 | } | |
3323 | } | |
3324 | } | |
3325 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
3326 | } | |
3327 | ||
3328 | /** | |
3329 | * _scsih_set_volume_delete_flag - setting volume delete flag | |
3330 | * @ioc: per adapter object | |
3331 | * @handle: device handle | |
3332 | * | |
3333 | * This returns nothing. | |
3334 | */ | |
3335 | static void | |
3336 | _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
3337 | { | |
3338 | struct _raid_device *raid_device; | |
3339 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
3340 | unsigned long flags; | |
3341 | ||
3342 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
3343 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); | |
3344 | if (raid_device && raid_device->starget && | |
3345 | raid_device->starget->hostdata) { | |
3346 | sas_target_priv_data = | |
3347 | raid_device->starget->hostdata; | |
3348 | sas_target_priv_data->deleted = 1; | |
3349 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3350 | "setting delete flag: handle(0x%04x), " | |
3351 | "wwid(0x%016llx)\n", ioc->name, handle, | |
3352 | (unsigned long long) raid_device->wwid)); | |
3353 | } | |
3354 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
3355 | } | |
3356 | ||
3357 | /** | |
3358 | * _scsih_set_volume_handle_for_tr - set handle for target reset to volume | |
3359 | * @handle: input handle | |
3360 | * @a: handle for volume a | |
3361 | * @b: handle for volume b | |
3362 | * | |
3363 | * IR firmware only supports two raid volumes. The purpose of this | |
3364 | * routine is to set the volume handle in either a or b. When the given | |
3365 | * input handle is non-zero, or when a and b have not been set before. | |
3366 | */ | |
3367 | static void | |
3368 | _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b) | |
3369 | { | |
3370 | if (!handle || handle == *a || handle == *b) | |
3371 | return; | |
3372 | if (!*a) | |
3373 | *a = handle; | |
3374 | else if (!*b) | |
3375 | *b = handle; | |
3376 | } | |
3377 | ||
3378 | /** | |
3379 | * _scsih_check_ir_config_unhide_events - check for UNHIDE events | |
3380 | * @ioc: per adapter object | |
3381 | * @event_data: the event data payload | |
3382 | * Context: interrupt time. | |
3383 | * | |
3384 | * This routine will send target reset to volume, followed by target | |
3385 | * resets to the PDs. This is called when a PD has been removed, or | |
3386 | * volume has been deleted or removed. When the target reset is sent | |
3387 | * to volume, the PD target resets need to be queued to start upon | |
3388 | * completion of the volume target reset. | |
3389 | * | |
3390 | * Return nothing. | |
3391 | */ | |
3392 | static void | |
3393 | _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc, | |
3394 | Mpi2EventDataIrConfigChangeList_t *event_data) | |
3395 | { | |
3396 | Mpi2EventIrConfigElement_t *element; | |
3397 | int i; | |
3398 | u16 handle, volume_handle, a, b; | |
3399 | struct _tr_list *delayed_tr; | |
3400 | ||
3401 | a = 0; | |
3402 | b = 0; | |
3403 | ||
7786ab6a SR |
3404 | if (ioc->is_warpdrive) |
3405 | return; | |
3406 | ||
f92363d1 SR |
3407 | /* Volume Resets for Deleted or Removed */ |
3408 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
3409 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
3410 | if (le32_to_cpu(event_data->Flags) & | |
3411 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) | |
3412 | continue; | |
3413 | if (element->ReasonCode == | |
3414 | MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED || | |
3415 | element->ReasonCode == | |
3416 | MPI2_EVENT_IR_CHANGE_RC_REMOVED) { | |
3417 | volume_handle = le16_to_cpu(element->VolDevHandle); | |
3418 | _scsih_set_volume_delete_flag(ioc, volume_handle); | |
3419 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); | |
3420 | } | |
3421 | } | |
3422 | ||
3423 | /* Volume Resets for UNHIDE events */ | |
3424 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
3425 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
3426 | if (le32_to_cpu(event_data->Flags) & | |
3427 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) | |
3428 | continue; | |
3429 | if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) { | |
3430 | volume_handle = le16_to_cpu(element->VolDevHandle); | |
3431 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); | |
3432 | } | |
3433 | } | |
3434 | ||
3435 | if (a) | |
3436 | _scsih_tm_tr_volume_send(ioc, a); | |
3437 | if (b) | |
3438 | _scsih_tm_tr_volume_send(ioc, b); | |
3439 | ||
3440 | /* PD target resets */ | |
3441 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
3442 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
3443 | if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE) | |
3444 | continue; | |
3445 | handle = le16_to_cpu(element->PhysDiskDevHandle); | |
3446 | volume_handle = le16_to_cpu(element->VolDevHandle); | |
3447 | clear_bit(handle, ioc->pd_handles); | |
3448 | if (!volume_handle) | |
3449 | _scsih_tm_tr_send(ioc, handle); | |
3450 | else if (volume_handle == a || volume_handle == b) { | |
3451 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | |
3452 | BUG_ON(!delayed_tr); | |
3453 | INIT_LIST_HEAD(&delayed_tr->list); | |
3454 | delayed_tr->handle = handle; | |
3455 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); | |
3456 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3457 | "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name, | |
3458 | handle)); | |
3459 | } else | |
3460 | _scsih_tm_tr_send(ioc, handle); | |
3461 | } | |
3462 | } | |
3463 | ||
3464 | ||
3465 | /** | |
3466 | * _scsih_check_volume_delete_events - set delete flag for volumes | |
3467 | * @ioc: per adapter object | |
3468 | * @event_data: the event data payload | |
3469 | * Context: interrupt time. | |
3470 | * | |
3471 | * This will handle the case when the cable connected to entire volume is | |
3472 | * pulled. We will take care of setting the deleted flag so normal IO will | |
3473 | * not be sent. | |
3474 | * | |
3475 | * Return nothing. | |
3476 | */ | |
3477 | static void | |
3478 | _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc, | |
3479 | Mpi2EventDataIrVolume_t *event_data) | |
3480 | { | |
3481 | u32 state; | |
3482 | ||
3483 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) | |
3484 | return; | |
3485 | state = le32_to_cpu(event_data->NewValue); | |
3486 | if (state == MPI2_RAID_VOL_STATE_MISSING || state == | |
3487 | MPI2_RAID_VOL_STATE_FAILED) | |
3488 | _scsih_set_volume_delete_flag(ioc, | |
3489 | le16_to_cpu(event_data->VolDevHandle)); | |
3490 | } | |
3491 | ||
2d8ce8c9 SR |
3492 | /** |
3493 | * _scsih_temp_threshold_events - display temperature threshold exceeded events | |
3494 | * @ioc: per adapter object | |
3495 | * @event_data: the temp threshold event data | |
3496 | * Context: interrupt time. | |
3497 | * | |
3498 | * Return nothing. | |
3499 | */ | |
3500 | static void | |
3501 | _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER *ioc, | |
3502 | Mpi2EventDataTemperature_t *event_data) | |
3503 | { | |
3504 | if (ioc->temp_sensors_count >= event_data->SensorNum) { | |
3505 | pr_err(MPT3SAS_FMT "Temperature Threshold flags %s%s%s%s" | |
3506 | " exceeded for Sensor: %d !!!\n", ioc->name, | |
3507 | ((le16_to_cpu(event_data->Status) & 0x1) == 1) ? "0 " : " ", | |
3508 | ((le16_to_cpu(event_data->Status) & 0x2) == 2) ? "1 " : " ", | |
3509 | ((le16_to_cpu(event_data->Status) & 0x4) == 4) ? "2 " : " ", | |
3510 | ((le16_to_cpu(event_data->Status) & 0x8) == 8) ? "3 " : " ", | |
3511 | event_data->SensorNum); | |
3512 | pr_err(MPT3SAS_FMT "Current Temp In Celsius: %d\n", | |
3513 | ioc->name, event_data->CurrentTemperature); | |
3514 | } | |
3515 | } | |
3516 | ||
f92363d1 SR |
3517 | /** |
3518 | * _scsih_flush_running_cmds - completing outstanding commands. | |
3519 | * @ioc: per adapter object | |
3520 | * | |
3521 | * The flushing out of all pending scmd commands following host reset, | |
3522 | * where all IO is dropped to the floor. | |
3523 | * | |
3524 | * Return nothing. | |
3525 | */ | |
3526 | static void | |
3527 | _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc) | |
3528 | { | |
3529 | struct scsi_cmnd *scmd; | |
3530 | u16 smid; | |
3531 | u16 count = 0; | |
3532 | ||
3533 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { | |
3534 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); | |
3535 | if (!scmd) | |
3536 | continue; | |
3537 | count++; | |
3538 | mpt3sas_base_free_smid(ioc, smid); | |
3539 | scsi_dma_unmap(scmd); | |
3540 | if (ioc->pci_error_recovery) | |
3541 | scmd->result = DID_NO_CONNECT << 16; | |
3542 | else | |
3543 | scmd->result = DID_RESET << 16; | |
3544 | scmd->scsi_done(scmd); | |
3545 | } | |
3546 | dtmprintk(ioc, pr_info(MPT3SAS_FMT "completing %d cmds\n", | |
3547 | ioc->name, count)); | |
3548 | } | |
3549 | ||
3550 | /** | |
3551 | * _scsih_setup_eedp - setup MPI request for EEDP transfer | |
3552 | * @ioc: per adapter object | |
3553 | * @scmd: pointer to scsi command object | |
3554 | * @mpi_request: pointer to the SCSI_IO reqest message frame | |
3555 | * | |
3556 | * Supporting protection 1 and 3. | |
3557 | * | |
3558 | * Returns nothing | |
3559 | */ | |
3560 | static void | |
3561 | _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, | |
3562 | Mpi2SCSIIORequest_t *mpi_request) | |
3563 | { | |
3564 | u16 eedp_flags; | |
3565 | unsigned char prot_op = scsi_get_prot_op(scmd); | |
3566 | unsigned char prot_type = scsi_get_prot_type(scmd); | |
3567 | Mpi25SCSIIORequest_t *mpi_request_3v = | |
3568 | (Mpi25SCSIIORequest_t *)mpi_request; | |
3569 | ||
3570 | if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL) | |
3571 | return; | |
3572 | ||
3573 | if (prot_op == SCSI_PROT_READ_STRIP) | |
3574 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP; | |
3575 | else if (prot_op == SCSI_PROT_WRITE_INSERT) | |
3576 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP; | |
3577 | else | |
3578 | return; | |
3579 | ||
3580 | switch (prot_type) { | |
3581 | case SCSI_PROT_DIF_TYPE1: | |
3582 | case SCSI_PROT_DIF_TYPE2: | |
3583 | ||
3584 | /* | |
3585 | * enable ref/guard checking | |
3586 | * auto increment ref tag | |
3587 | */ | |
3588 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG | | |
3589 | MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG | | |
3590 | MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; | |
3591 | mpi_request->CDB.EEDP32.PrimaryReferenceTag = | |
3592 | cpu_to_be32(scsi_get_lba(scmd)); | |
3593 | break; | |
3594 | ||
3595 | case SCSI_PROT_DIF_TYPE3: | |
3596 | ||
3597 | /* | |
3598 | * enable guard checking | |
3599 | */ | |
3600 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; | |
3601 | ||
3602 | break; | |
3603 | } | |
3604 | ||
3605 | mpi_request_3v->EEDPBlockSize = | |
3606 | cpu_to_le16(scmd->device->sector_size); | |
3607 | mpi_request->EEDPFlags = cpu_to_le16(eedp_flags); | |
3608 | } | |
3609 | ||
3610 | /** | |
3611 | * _scsih_eedp_error_handling - return sense code for EEDP errors | |
3612 | * @scmd: pointer to scsi command object | |
3613 | * @ioc_status: ioc status | |
3614 | * | |
3615 | * Returns nothing | |
3616 | */ | |
3617 | static void | |
3618 | _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status) | |
3619 | { | |
3620 | u8 ascq; | |
3621 | ||
3622 | switch (ioc_status) { | |
3623 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | |
3624 | ascq = 0x01; | |
3625 | break; | |
3626 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | |
3627 | ascq = 0x02; | |
3628 | break; | |
3629 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | |
3630 | ascq = 0x03; | |
3631 | break; | |
3632 | default: | |
3633 | ascq = 0x00; | |
3634 | break; | |
3635 | } | |
3636 | scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10, | |
3637 | ascq); | |
3638 | scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) | | |
3639 | SAM_STAT_CHECK_CONDITION; | |
3640 | } | |
3641 | ||
3642 | ||
7786ab6a | 3643 | |
f92363d1 | 3644 | /** |
8a7e4c24 | 3645 | * scsih_qcmd - main scsi request entry point |
f92363d1 SR |
3646 | * @scmd: pointer to scsi command object |
3647 | * @done: function pointer to be invoked on completion | |
3648 | * | |
3649 | * The callback index is set inside `ioc->scsi_io_cb_idx`. | |
3650 | * | |
3651 | * Returns 0 on success. If there's a failure, return either: | |
3652 | * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or | |
3653 | * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full | |
3654 | */ | |
8a7e4c24 SR |
3655 | int |
3656 | scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd) | |
f92363d1 | 3657 | { |
d8bfbd8d | 3658 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
f92363d1 SR |
3659 | struct MPT3SAS_DEVICE *sas_device_priv_data; |
3660 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
7786ab6a SR |
3661 | #ifdef SCSI_MPT2SAS |
3662 | struct _raid_device *raid_device; | |
3663 | #endif | |
f92363d1 SR |
3664 | Mpi2SCSIIORequest_t *mpi_request; |
3665 | u32 mpi_control; | |
3666 | u16 smid; | |
3667 | u16 handle; | |
3668 | ||
f92363d1 SR |
3669 | if (ioc->logging_level & MPT_DEBUG_SCSI) |
3670 | scsi_print_command(scmd); | |
f92363d1 | 3671 | |
f92363d1 SR |
3672 | sas_device_priv_data = scmd->device->hostdata; |
3673 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | |
3674 | scmd->result = DID_NO_CONNECT << 16; | |
3675 | scmd->scsi_done(scmd); | |
3676 | return 0; | |
3677 | } | |
3678 | ||
3679 | if (ioc->pci_error_recovery || ioc->remove_host) { | |
3680 | scmd->result = DID_NO_CONNECT << 16; | |
3681 | scmd->scsi_done(scmd); | |
3682 | return 0; | |
3683 | } | |
3684 | ||
3685 | sas_target_priv_data = sas_device_priv_data->sas_target; | |
3686 | ||
3687 | /* invalid device handle */ | |
3688 | handle = sas_target_priv_data->handle; | |
3689 | if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) { | |
3690 | scmd->result = DID_NO_CONNECT << 16; | |
3691 | scmd->scsi_done(scmd); | |
3692 | return 0; | |
3693 | } | |
3694 | ||
3695 | ||
3696 | /* host recovery or link resets sent via IOCTLs */ | |
3697 | if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress) | |
3698 | return SCSI_MLQUEUE_HOST_BUSY; | |
3699 | ||
3700 | /* device has been deleted */ | |
3701 | else if (sas_target_priv_data->deleted) { | |
3702 | scmd->result = DID_NO_CONNECT << 16; | |
3703 | scmd->scsi_done(scmd); | |
3704 | return 0; | |
3705 | /* device busy with task managment */ | |
3706 | } else if (sas_target_priv_data->tm_busy || | |
3707 | sas_device_priv_data->block) | |
3708 | return SCSI_MLQUEUE_DEVICE_BUSY; | |
3709 | ||
3710 | if (scmd->sc_data_direction == DMA_FROM_DEVICE) | |
3711 | mpi_control = MPI2_SCSIIO_CONTROL_READ; | |
3712 | else if (scmd->sc_data_direction == DMA_TO_DEVICE) | |
3713 | mpi_control = MPI2_SCSIIO_CONTROL_WRITE; | |
3714 | else | |
3715 | mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER; | |
3716 | ||
3717 | /* set tags */ | |
609aa22f | 3718 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; |
f92363d1 | 3719 | |
7786ab6a SR |
3720 | /* Make sure Device is not raid volume. |
3721 | * We do not expose raid functionality to upper layer for warpdrive. | |
3722 | */ | |
3723 | if (!ioc->is_warpdrive && !scsih_is_raid(&scmd->device->sdev_gendev) | |
3724 | && (sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) && | |
f92363d1 SR |
3725 | scmd->cmd_len != 32) |
3726 | mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON; | |
3727 | ||
3728 | smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd); | |
3729 | if (!smid) { | |
3730 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
3731 | ioc->name, __func__); | |
3732 | goto out; | |
3733 | } | |
3734 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
3735 | memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t)); | |
3736 | _scsih_setup_eedp(ioc, scmd, mpi_request); | |
3737 | ||
3738 | if (scmd->cmd_len == 32) | |
3739 | mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT; | |
3740 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; | |
3741 | if (sas_device_priv_data->sas_target->flags & | |
3742 | MPT_TARGET_FLAGS_RAID_COMPONENT) | |
3743 | mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH; | |
3744 | else | |
3745 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; | |
3746 | mpi_request->DevHandle = cpu_to_le16(handle); | |
3747 | mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd)); | |
3748 | mpi_request->Control = cpu_to_le32(mpi_control); | |
3749 | mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len); | |
3750 | mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR; | |
3751 | mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE; | |
3752 | mpi_request->SenseBufferLowAddress = | |
3753 | mpt3sas_base_get_sense_buffer_dma(ioc, smid); | |
3754 | mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4; | |
3755 | int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *) | |
3756 | mpi_request->LUN); | |
3757 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); | |
3758 | ||
3759 | if (mpi_request->DataLength) { | |
3760 | if (ioc->build_sg_scmd(ioc, scmd, smid)) { | |
3761 | mpt3sas_base_free_smid(ioc, smid); | |
3762 | goto out; | |
3763 | } | |
3764 | } else | |
3765 | ioc->build_zero_len_sge(ioc, &mpi_request->SGL); | |
3766 | ||
7786ab6a SR |
3767 | #ifdef SCSI_MPT2SAS |
3768 | raid_device = sas_target_priv_data->raid_device; | |
3769 | if (raid_device && raid_device->direct_io_enabled) | |
3770 | _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request, | |
3771 | smid); | |
3772 | #endif | |
3773 | ||
f92363d1 | 3774 | if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) { |
45506049 | 3775 | #ifndef SCSI_MPT2SAS |
f92363d1 SR |
3776 | if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) { |
3777 | mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len | | |
3778 | MPI25_SCSIIO_IOFLAGS_FAST_PATH); | |
3779 | mpt3sas_base_put_smid_fast_path(ioc, smid, handle); | |
3780 | } else | |
45506049 | 3781 | #endif |
7786ab6a SR |
3782 | mpt3sas_base_put_smid_scsi_io(ioc, smid, |
3783 | le16_to_cpu(mpi_request->DevHandle)); | |
f92363d1 SR |
3784 | } else |
3785 | mpt3sas_base_put_smid_default(ioc, smid); | |
3786 | return 0; | |
3787 | ||
3788 | out: | |
3789 | return SCSI_MLQUEUE_HOST_BUSY; | |
3790 | } | |
f92363d1 SR |
3791 | |
3792 | /** | |
3793 | * _scsih_normalize_sense - normalize descriptor and fixed format sense data | |
3794 | * @sense_buffer: sense data returned by target | |
3795 | * @data: normalized skey/asc/ascq | |
3796 | * | |
3797 | * Return nothing. | |
3798 | */ | |
3799 | static void | |
3800 | _scsih_normalize_sense(char *sense_buffer, struct sense_info *data) | |
3801 | { | |
3802 | if ((sense_buffer[0] & 0x7F) >= 0x72) { | |
3803 | /* descriptor format */ | |
3804 | data->skey = sense_buffer[1] & 0x0F; | |
3805 | data->asc = sense_buffer[2]; | |
3806 | data->ascq = sense_buffer[3]; | |
3807 | } else { | |
3808 | /* fixed format */ | |
3809 | data->skey = sense_buffer[2] & 0x0F; | |
3810 | data->asc = sense_buffer[12]; | |
3811 | data->ascq = sense_buffer[13]; | |
3812 | } | |
3813 | } | |
3814 | ||
f92363d1 SR |
3815 | /** |
3816 | * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request | |
3817 | * @ioc: per adapter object | |
3818 | * @scmd: pointer to scsi command object | |
3819 | * @mpi_reply: reply mf payload returned from firmware | |
3820 | * | |
3821 | * scsi_status - SCSI Status code returned from target device | |
3822 | * scsi_state - state info associated with SCSI_IO determined by ioc | |
3823 | * ioc_status - ioc supplied status info | |
3824 | * | |
3825 | * Return nothing. | |
3826 | */ | |
3827 | static void | |
3828 | _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, | |
3829 | Mpi2SCSIIOReply_t *mpi_reply, u16 smid) | |
3830 | { | |
3831 | u32 response_info; | |
3832 | u8 *response_bytes; | |
3833 | u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & | |
3834 | MPI2_IOCSTATUS_MASK; | |
3835 | u8 scsi_state = mpi_reply->SCSIState; | |
3836 | u8 scsi_status = mpi_reply->SCSIStatus; | |
3837 | char *desc_ioc_state = NULL; | |
3838 | char *desc_scsi_status = NULL; | |
3839 | char *desc_scsi_state = ioc->tmp_string; | |
3840 | u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo); | |
3841 | struct _sas_device *sas_device = NULL; | |
3842 | unsigned long flags; | |
3843 | struct scsi_target *starget = scmd->device->sdev_target; | |
3844 | struct MPT3SAS_TARGET *priv_target = starget->hostdata; | |
3845 | char *device_str = NULL; | |
3846 | ||
3847 | if (!priv_target) | |
3848 | return; | |
7786ab6a SR |
3849 | if (ioc->hide_ir_msg) |
3850 | device_str = "WarpDrive"; | |
3851 | else | |
3852 | device_str = "volume"; | |
f92363d1 SR |
3853 | |
3854 | if (log_info == 0x31170000) | |
3855 | return; | |
3856 | ||
3857 | switch (ioc_status) { | |
3858 | case MPI2_IOCSTATUS_SUCCESS: | |
3859 | desc_ioc_state = "success"; | |
3860 | break; | |
3861 | case MPI2_IOCSTATUS_INVALID_FUNCTION: | |
3862 | desc_ioc_state = "invalid function"; | |
3863 | break; | |
3864 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: | |
3865 | desc_ioc_state = "scsi recovered error"; | |
3866 | break; | |
3867 | case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE: | |
3868 | desc_ioc_state = "scsi invalid dev handle"; | |
3869 | break; | |
3870 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: | |
3871 | desc_ioc_state = "scsi device not there"; | |
3872 | break; | |
3873 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: | |
3874 | desc_ioc_state = "scsi data overrun"; | |
3875 | break; | |
3876 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: | |
3877 | desc_ioc_state = "scsi data underrun"; | |
3878 | break; | |
3879 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: | |
3880 | desc_ioc_state = "scsi io data error"; | |
3881 | break; | |
3882 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: | |
3883 | desc_ioc_state = "scsi protocol error"; | |
3884 | break; | |
3885 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: | |
3886 | desc_ioc_state = "scsi task terminated"; | |
3887 | break; | |
3888 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: | |
3889 | desc_ioc_state = "scsi residual mismatch"; | |
3890 | break; | |
3891 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: | |
3892 | desc_ioc_state = "scsi task mgmt failed"; | |
3893 | break; | |
3894 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: | |
3895 | desc_ioc_state = "scsi ioc terminated"; | |
3896 | break; | |
3897 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: | |
3898 | desc_ioc_state = "scsi ext terminated"; | |
3899 | break; | |
3900 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | |
3901 | desc_ioc_state = "eedp guard error"; | |
3902 | break; | |
3903 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | |
3904 | desc_ioc_state = "eedp ref tag error"; | |
3905 | break; | |
3906 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | |
3907 | desc_ioc_state = "eedp app tag error"; | |
3908 | break; | |
3909 | default: | |
3910 | desc_ioc_state = "unknown"; | |
3911 | break; | |
3912 | } | |
3913 | ||
3914 | switch (scsi_status) { | |
3915 | case MPI2_SCSI_STATUS_GOOD: | |
3916 | desc_scsi_status = "good"; | |
3917 | break; | |
3918 | case MPI2_SCSI_STATUS_CHECK_CONDITION: | |
3919 | desc_scsi_status = "check condition"; | |
3920 | break; | |
3921 | case MPI2_SCSI_STATUS_CONDITION_MET: | |
3922 | desc_scsi_status = "condition met"; | |
3923 | break; | |
3924 | case MPI2_SCSI_STATUS_BUSY: | |
3925 | desc_scsi_status = "busy"; | |
3926 | break; | |
3927 | case MPI2_SCSI_STATUS_INTERMEDIATE: | |
3928 | desc_scsi_status = "intermediate"; | |
3929 | break; | |
3930 | case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET: | |
3931 | desc_scsi_status = "intermediate condmet"; | |
3932 | break; | |
3933 | case MPI2_SCSI_STATUS_RESERVATION_CONFLICT: | |
3934 | desc_scsi_status = "reservation conflict"; | |
3935 | break; | |
3936 | case MPI2_SCSI_STATUS_COMMAND_TERMINATED: | |
3937 | desc_scsi_status = "command terminated"; | |
3938 | break; | |
3939 | case MPI2_SCSI_STATUS_TASK_SET_FULL: | |
3940 | desc_scsi_status = "task set full"; | |
3941 | break; | |
3942 | case MPI2_SCSI_STATUS_ACA_ACTIVE: | |
3943 | desc_scsi_status = "aca active"; | |
3944 | break; | |
3945 | case MPI2_SCSI_STATUS_TASK_ABORTED: | |
3946 | desc_scsi_status = "task aborted"; | |
3947 | break; | |
3948 | default: | |
3949 | desc_scsi_status = "unknown"; | |
3950 | break; | |
3951 | } | |
3952 | ||
3953 | desc_scsi_state[0] = '\0'; | |
3954 | if (!scsi_state) | |
3955 | desc_scsi_state = " "; | |
3956 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) | |
3957 | strcat(desc_scsi_state, "response info "); | |
3958 | if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | |
3959 | strcat(desc_scsi_state, "state terminated "); | |
3960 | if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS) | |
3961 | strcat(desc_scsi_state, "no status "); | |
3962 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED) | |
3963 | strcat(desc_scsi_state, "autosense failed "); | |
3964 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) | |
3965 | strcat(desc_scsi_state, "autosense valid "); | |
3966 | ||
3967 | scsi_print_command(scmd); | |
3968 | ||
3969 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { | |
3970 | pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name, | |
3971 | device_str, (unsigned long long)priv_target->sas_address); | |
3972 | } else { | |
3973 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
3974 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, | |
3975 | priv_target->sas_address); | |
3976 | if (sas_device) { | |
3977 | pr_warn(MPT3SAS_FMT | |
3978 | "\tsas_address(0x%016llx), phy(%d)\n", | |
3979 | ioc->name, (unsigned long long) | |
3980 | sas_device->sas_address, sas_device->phy); | |
e6d45e3e SR |
3981 | if (sas_device->enclosure_handle != 0) |
3982 | pr_warn(MPT3SAS_FMT | |
3983 | "\tenclosure_logical_id(0x%016llx)," | |
3984 | "slot(%d)\n", ioc->name, | |
3985 | (unsigned long long) | |
3986 | sas_device->enclosure_logical_id, | |
3987 | sas_device->slot); | |
3988 | if (sas_device->connector_name[0]) | |
3989 | pr_warn(MPT3SAS_FMT | |
3990 | "\tenclosure level(0x%04x)," | |
3991 | " connector name( %s)\n", ioc->name, | |
3992 | sas_device->enclosure_level, | |
3993 | sas_device->connector_name); | |
f92363d1 SR |
3994 | } |
3995 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
3996 | } | |
3997 | ||
3998 | pr_warn(MPT3SAS_FMT | |
3999 | "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n", | |
4000 | ioc->name, le16_to_cpu(mpi_reply->DevHandle), | |
4001 | desc_ioc_state, ioc_status, smid); | |
4002 | pr_warn(MPT3SAS_FMT | |
4003 | "\trequest_len(%d), underflow(%d), resid(%d)\n", | |
4004 | ioc->name, scsi_bufflen(scmd), scmd->underflow, | |
4005 | scsi_get_resid(scmd)); | |
4006 | pr_warn(MPT3SAS_FMT | |
4007 | "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n", | |
4008 | ioc->name, le16_to_cpu(mpi_reply->TaskTag), | |
4009 | le32_to_cpu(mpi_reply->TransferCount), scmd->result); | |
4010 | pr_warn(MPT3SAS_FMT | |
4011 | "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n", | |
4012 | ioc->name, desc_scsi_status, | |
4013 | scsi_status, desc_scsi_state, scsi_state); | |
4014 | ||
4015 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { | |
4016 | struct sense_info data; | |
4017 | _scsih_normalize_sense(scmd->sense_buffer, &data); | |
4018 | pr_warn(MPT3SAS_FMT | |
4019 | "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n", | |
4020 | ioc->name, data.skey, | |
4021 | data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount)); | |
4022 | } | |
4023 | ||
4024 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) { | |
4025 | response_info = le32_to_cpu(mpi_reply->ResponseInfo); | |
4026 | response_bytes = (u8 *)&response_info; | |
4027 | _scsih_response_code(ioc, response_bytes[0]); | |
4028 | } | |
4029 | } | |
f92363d1 SR |
4030 | |
4031 | /** | |
0f624c39 | 4032 | * _scsih_turn_on_pfa_led - illuminate PFA LED |
f92363d1 SR |
4033 | * @ioc: per adapter object |
4034 | * @handle: device handle | |
4035 | * Context: process | |
4036 | * | |
4037 | * Return nothing. | |
4038 | */ | |
4039 | static void | |
0f624c39 | 4040 | _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
f92363d1 SR |
4041 | { |
4042 | Mpi2SepReply_t mpi_reply; | |
4043 | Mpi2SepRequest_t mpi_request; | |
0f624c39 SR |
4044 | struct _sas_device *sas_device; |
4045 | ||
4046 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); | |
4047 | if (!sas_device) | |
4048 | return; | |
f92363d1 SR |
4049 | |
4050 | memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t)); | |
4051 | mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; | |
4052 | mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; | |
4053 | mpi_request.SlotStatus = | |
4054 | cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT); | |
4055 | mpi_request.DevHandle = cpu_to_le16(handle); | |
4056 | mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS; | |
4057 | if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply, | |
4058 | &mpi_request)) != 0) { | |
4059 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name, | |
4060 | __FILE__, __LINE__, __func__); | |
4061 | return; | |
4062 | } | |
0f624c39 | 4063 | sas_device->pfa_led_on = 1; |
f92363d1 SR |
4064 | |
4065 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) { | |
4066 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4067 | "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n", | |
4068 | ioc->name, le16_to_cpu(mpi_reply.IOCStatus), | |
4069 | le32_to_cpu(mpi_reply.IOCLogInfo))); | |
4070 | return; | |
4071 | } | |
4072 | } | |
0f624c39 SR |
4073 | /** |
4074 | * _scsih_turn_off_pfa_led - turn off Fault LED | |
4075 | * @ioc: per adapter object | |
4076 | * @sas_device: sas device whose PFA LED has to turned off | |
4077 | * Context: process | |
4078 | * | |
4079 | * Return nothing. | |
4080 | */ | |
4081 | static void | |
4082 | _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc, | |
4083 | struct _sas_device *sas_device) | |
4084 | { | |
4085 | Mpi2SepReply_t mpi_reply; | |
4086 | Mpi2SepRequest_t mpi_request; | |
f92363d1 | 4087 | |
0f624c39 SR |
4088 | memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t)); |
4089 | mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; | |
4090 | mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; | |
4091 | mpi_request.SlotStatus = 0; | |
4092 | mpi_request.Slot = cpu_to_le16(sas_device->slot); | |
4093 | mpi_request.DevHandle = 0; | |
4094 | mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle); | |
4095 | mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS; | |
4096 | if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply, | |
4097 | &mpi_request)) != 0) { | |
4098 | printk(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name, | |
4099 | __FILE__, __LINE__, __func__); | |
4100 | return; | |
4101 | } | |
4102 | ||
4103 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) { | |
4104 | dewtprintk(ioc, printk(MPT3SAS_FMT | |
4105 | "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n", | |
4106 | ioc->name, le16_to_cpu(mpi_reply.IOCStatus), | |
4107 | le32_to_cpu(mpi_reply.IOCLogInfo))); | |
4108 | return; | |
4109 | } | |
4110 | } | |
f92363d1 | 4111 | /** |
0f624c39 | 4112 | * _scsih_send_event_to_turn_on_pfa_led - fire delayed event |
f92363d1 SR |
4113 | * @ioc: per adapter object |
4114 | * @handle: device handle | |
4115 | * Context: interrupt. | |
4116 | * | |
4117 | * Return nothing. | |
4118 | */ | |
4119 | static void | |
0f624c39 | 4120 | _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
f92363d1 SR |
4121 | { |
4122 | struct fw_event_work *fw_event; | |
4123 | ||
4124 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); | |
4125 | if (!fw_event) | |
4126 | return; | |
0f624c39 | 4127 | fw_event->event = MPT3SAS_TURN_ON_PFA_LED; |
f92363d1 SR |
4128 | fw_event->device_handle = handle; |
4129 | fw_event->ioc = ioc; | |
4130 | _scsih_fw_event_add(ioc, fw_event); | |
4131 | } | |
4132 | ||
4133 | /** | |
4134 | * _scsih_smart_predicted_fault - process smart errors | |
4135 | * @ioc: per adapter object | |
4136 | * @handle: device handle | |
4137 | * Context: interrupt. | |
4138 | * | |
4139 | * Return nothing. | |
4140 | */ | |
4141 | static void | |
4142 | _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
4143 | { | |
4144 | struct scsi_target *starget; | |
4145 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
4146 | Mpi2EventNotificationReply_t *event_reply; | |
4147 | Mpi2EventDataSasDeviceStatusChange_t *event_data; | |
4148 | struct _sas_device *sas_device; | |
4149 | ssize_t sz; | |
4150 | unsigned long flags; | |
4151 | ||
4152 | /* only handle non-raid devices */ | |
4153 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
4154 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); | |
4155 | if (!sas_device) { | |
4156 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
4157 | return; | |
4158 | } | |
4159 | starget = sas_device->starget; | |
4160 | sas_target_priv_data = starget->hostdata; | |
4161 | ||
4162 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) || | |
4163 | ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) { | |
4164 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
4165 | return; | |
4166 | } | |
e6d45e3e SR |
4167 | if (sas_device->enclosure_handle != 0) |
4168 | starget_printk(KERN_INFO, starget, "predicted fault, " | |
4169 | "enclosure logical id(0x%016llx), slot(%d)\n", | |
4170 | (unsigned long long)sas_device->enclosure_logical_id, | |
4171 | sas_device->slot); | |
4172 | if (sas_device->connector_name[0] != '\0') | |
4173 | starget_printk(KERN_WARNING, starget, "predicted fault, " | |
4174 | "enclosure level(0x%04x), connector name( %s)\n", | |
4175 | sas_device->enclosure_level, | |
4176 | sas_device->connector_name); | |
f92363d1 SR |
4177 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
4178 | ||
4179 | if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) | |
0f624c39 | 4180 | _scsih_send_event_to_turn_on_pfa_led(ioc, handle); |
f92363d1 SR |
4181 | |
4182 | /* insert into event log */ | |
4183 | sz = offsetof(Mpi2EventNotificationReply_t, EventData) + | |
4184 | sizeof(Mpi2EventDataSasDeviceStatusChange_t); | |
4185 | event_reply = kzalloc(sz, GFP_KERNEL); | |
4186 | if (!event_reply) { | |
4187 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4188 | ioc->name, __FILE__, __LINE__, __func__); | |
4189 | return; | |
4190 | } | |
4191 | ||
4192 | event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION; | |
4193 | event_reply->Event = | |
4194 | cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE); | |
4195 | event_reply->MsgLength = sz/4; | |
4196 | event_reply->EventDataLength = | |
4197 | cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4); | |
4198 | event_data = (Mpi2EventDataSasDeviceStatusChange_t *) | |
4199 | event_reply->EventData; | |
4200 | event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA; | |
4201 | event_data->ASC = 0x5D; | |
4202 | event_data->DevHandle = cpu_to_le16(handle); | |
4203 | event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address); | |
4204 | mpt3sas_ctl_add_to_event_log(ioc, event_reply); | |
4205 | kfree(event_reply); | |
4206 | } | |
4207 | ||
4208 | /** | |
4209 | * _scsih_io_done - scsi request callback | |
4210 | * @ioc: per adapter object | |
4211 | * @smid: system request message index | |
4212 | * @msix_index: MSIX table index supplied by the OS | |
4213 | * @reply: reply message frame(lower 32bit addr) | |
4214 | * | |
4215 | * Callback handler when using _scsih_qcmd. | |
4216 | * | |
4217 | * Return 1 meaning mf should be freed from _base_interrupt | |
4218 | * 0 means the mf is freed from this function. | |
4219 | */ | |
4220 | static u8 | |
4221 | _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | |
4222 | { | |
4223 | Mpi2SCSIIORequest_t *mpi_request; | |
4224 | Mpi2SCSIIOReply_t *mpi_reply; | |
4225 | struct scsi_cmnd *scmd; | |
4226 | u16 ioc_status; | |
4227 | u32 xfer_cnt; | |
4228 | u8 scsi_state; | |
4229 | u8 scsi_status; | |
4230 | u32 log_info; | |
4231 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
4232 | u32 response_code = 0; | |
7786ab6a SR |
4233 | #ifdef SCSI_MPT2SAS |
4234 | unsigned long flags; | |
4235 | #endif | |
f92363d1 SR |
4236 | |
4237 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
4238 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); | |
4239 | if (scmd == NULL) | |
4240 | return 1; | |
4241 | ||
4242 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
4243 | ||
4244 | if (mpi_reply == NULL) { | |
4245 | scmd->result = DID_OK << 16; | |
4246 | goto out; | |
4247 | } | |
4248 | ||
4249 | sas_device_priv_data = scmd->device->hostdata; | |
4250 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target || | |
4251 | sas_device_priv_data->sas_target->deleted) { | |
4252 | scmd->result = DID_NO_CONNECT << 16; | |
4253 | goto out; | |
4254 | } | |
4255 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); | |
4256 | ||
7786ab6a SR |
4257 | #ifdef SCSI_MPT2SAS |
4258 | /* | |
4259 | * WARPDRIVE: If direct_io is set then it is directIO, | |
4260 | * the failed direct I/O should be redirected to volume | |
4261 | */ | |
4262 | if (_scsih_scsi_direct_io_get(ioc, smid) && | |
4263 | ((ioc_status & MPI2_IOCSTATUS_MASK) | |
4264 | != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) { | |
4265 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
4266 | ioc->scsi_lookup[smid - 1].scmd = scmd; | |
4267 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
4268 | _scsih_scsi_direct_io_set(ioc, smid, 0); | |
4269 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); | |
4270 | mpi_request->DevHandle = | |
4271 | cpu_to_le16(sas_device_priv_data->sas_target->handle); | |
4272 | mpt3sas_base_put_smid_scsi_io(ioc, smid, | |
4273 | sas_device_priv_data->sas_target->handle); | |
4274 | return 0; | |
4275 | } | |
4276 | #endif | |
f92363d1 SR |
4277 | /* turning off TLR */ |
4278 | scsi_state = mpi_reply->SCSIState; | |
4279 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) | |
4280 | response_code = | |
4281 | le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF; | |
4282 | if (!sas_device_priv_data->tlr_snoop_check) { | |
4283 | sas_device_priv_data->tlr_snoop_check++; | |
7786ab6a SR |
4284 | if (!ioc->is_warpdrive && |
4285 | !scsih_is_raid(&scmd->device->sdev_gendev) && | |
4286 | (sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) && | |
f92363d1 SR |
4287 | response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) |
4288 | sas_device_priv_data->flags &= | |
4289 | ~MPT_DEVICE_TLR_ON; | |
4290 | } | |
4291 | ||
4292 | xfer_cnt = le32_to_cpu(mpi_reply->TransferCount); | |
4293 | scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt); | |
4294 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) | |
4295 | log_info = le32_to_cpu(mpi_reply->IOCLogInfo); | |
4296 | else | |
4297 | log_info = 0; | |
4298 | ioc_status &= MPI2_IOCSTATUS_MASK; | |
4299 | scsi_status = mpi_reply->SCSIStatus; | |
4300 | ||
4301 | if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 && | |
4302 | (scsi_status == MPI2_SCSI_STATUS_BUSY || | |
4303 | scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT || | |
4304 | scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) { | |
4305 | ioc_status = MPI2_IOCSTATUS_SUCCESS; | |
4306 | } | |
4307 | ||
4308 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { | |
4309 | struct sense_info data; | |
4310 | const void *sense_data = mpt3sas_base_get_sense_buffer(ioc, | |
4311 | smid); | |
4312 | u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE, | |
4313 | le32_to_cpu(mpi_reply->SenseCount)); | |
4314 | memcpy(scmd->sense_buffer, sense_data, sz); | |
4315 | _scsih_normalize_sense(scmd->sense_buffer, &data); | |
4316 | /* failure prediction threshold exceeded */ | |
4317 | if (data.asc == 0x5D) | |
4318 | _scsih_smart_predicted_fault(ioc, | |
4319 | le16_to_cpu(mpi_reply->DevHandle)); | |
4320 | mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq); | |
f92363d1 | 4321 | |
e6d45e3e SR |
4322 | if (!(ioc->logging_level & MPT_DEBUG_REPLY) && |
4323 | ((scmd->sense_buffer[2] == UNIT_ATTENTION) || | |
4324 | (scmd->sense_buffer[2] == MEDIUM_ERROR) || | |
4325 | (scmd->sense_buffer[2] == HARDWARE_ERROR))) | |
4326 | _scsih_scsi_ioc_info(ioc, scmd, mpi_reply, smid); | |
e6d45e3e | 4327 | } |
f92363d1 SR |
4328 | switch (ioc_status) { |
4329 | case MPI2_IOCSTATUS_BUSY: | |
4330 | case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES: | |
4331 | scmd->result = SAM_STAT_BUSY; | |
4332 | break; | |
4333 | ||
4334 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: | |
4335 | scmd->result = DID_NO_CONNECT << 16; | |
4336 | break; | |
4337 | ||
4338 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: | |
4339 | if (sas_device_priv_data->block) { | |
4340 | scmd->result = DID_TRANSPORT_DISRUPTED << 16; | |
4341 | goto out; | |
4342 | } | |
4343 | if (log_info == 0x31110630) { | |
4344 | if (scmd->retries > 2) { | |
4345 | scmd->result = DID_NO_CONNECT << 16; | |
4346 | scsi_device_set_state(scmd->device, | |
4347 | SDEV_OFFLINE); | |
4348 | } else { | |
4349 | scmd->result = DID_SOFT_ERROR << 16; | |
4350 | scmd->device->expecting_cc_ua = 1; | |
4351 | } | |
4352 | break; | |
3898f08e SR |
4353 | } else if (log_info == VIRTUAL_IO_FAILED_RETRY) { |
4354 | scmd->result = DID_RESET << 16; | |
4355 | break; | |
f92363d1 SR |
4356 | } |
4357 | scmd->result = DID_SOFT_ERROR << 16; | |
4358 | break; | |
4359 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: | |
4360 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: | |
4361 | scmd->result = DID_RESET << 16; | |
4362 | break; | |
4363 | ||
4364 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: | |
4365 | if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt)) | |
4366 | scmd->result = DID_SOFT_ERROR << 16; | |
4367 | else | |
4368 | scmd->result = (DID_OK << 16) | scsi_status; | |
4369 | break; | |
4370 | ||
4371 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: | |
4372 | scmd->result = (DID_OK << 16) | scsi_status; | |
4373 | ||
4374 | if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)) | |
4375 | break; | |
4376 | ||
4377 | if (xfer_cnt < scmd->underflow) { | |
4378 | if (scsi_status == SAM_STAT_BUSY) | |
4379 | scmd->result = SAM_STAT_BUSY; | |
4380 | else | |
4381 | scmd->result = DID_SOFT_ERROR << 16; | |
4382 | } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | | |
4383 | MPI2_SCSI_STATE_NO_SCSI_STATUS)) | |
4384 | scmd->result = DID_SOFT_ERROR << 16; | |
4385 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | |
4386 | scmd->result = DID_RESET << 16; | |
4387 | else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) { | |
4388 | mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID; | |
4389 | mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION; | |
4390 | scmd->result = (DRIVER_SENSE << 24) | | |
4391 | SAM_STAT_CHECK_CONDITION; | |
4392 | scmd->sense_buffer[0] = 0x70; | |
4393 | scmd->sense_buffer[2] = ILLEGAL_REQUEST; | |
4394 | scmd->sense_buffer[12] = 0x20; | |
4395 | scmd->sense_buffer[13] = 0; | |
4396 | } | |
4397 | break; | |
4398 | ||
4399 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: | |
4400 | scsi_set_resid(scmd, 0); | |
4401 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: | |
4402 | case MPI2_IOCSTATUS_SUCCESS: | |
4403 | scmd->result = (DID_OK << 16) | scsi_status; | |
4404 | if (response_code == | |
4405 | MPI2_SCSITASKMGMT_RSP_INVALID_FRAME || | |
4406 | (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | | |
4407 | MPI2_SCSI_STATE_NO_SCSI_STATUS))) | |
4408 | scmd->result = DID_SOFT_ERROR << 16; | |
4409 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | |
4410 | scmd->result = DID_RESET << 16; | |
4411 | break; | |
4412 | ||
4413 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | |
4414 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | |
4415 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | |
4416 | _scsih_eedp_error_handling(scmd, ioc_status); | |
4417 | break; | |
4418 | ||
4419 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: | |
4420 | case MPI2_IOCSTATUS_INVALID_FUNCTION: | |
4421 | case MPI2_IOCSTATUS_INVALID_SGL: | |
4422 | case MPI2_IOCSTATUS_INTERNAL_ERROR: | |
4423 | case MPI2_IOCSTATUS_INVALID_FIELD: | |
4424 | case MPI2_IOCSTATUS_INVALID_STATE: | |
4425 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: | |
4426 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: | |
4427 | default: | |
4428 | scmd->result = DID_SOFT_ERROR << 16; | |
4429 | break; | |
4430 | ||
4431 | } | |
4432 | ||
f92363d1 SR |
4433 | if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY)) |
4434 | _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid); | |
f92363d1 SR |
4435 | |
4436 | out: | |
4437 | ||
4438 | scsi_dma_unmap(scmd); | |
4439 | ||
4440 | scmd->scsi_done(scmd); | |
4441 | return 1; | |
4442 | } | |
4443 | ||
4444 | /** | |
4445 | * _scsih_sas_host_refresh - refreshing sas host object contents | |
4446 | * @ioc: per adapter object | |
4447 | * Context: user | |
4448 | * | |
4449 | * During port enable, fw will send topology events for every device. Its | |
4450 | * possible that the handles may change from the previous setting, so this | |
4451 | * code keeping handles updating if changed. | |
4452 | * | |
4453 | * Return nothing. | |
4454 | */ | |
4455 | static void | |
4456 | _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc) | |
4457 | { | |
4458 | u16 sz; | |
4459 | u16 ioc_status; | |
4460 | int i; | |
4461 | Mpi2ConfigReply_t mpi_reply; | |
4462 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; | |
4463 | u16 attached_handle; | |
4464 | u8 link_rate; | |
4465 | ||
4466 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
4467 | "updating handles for sas_host(0x%016llx)\n", | |
4468 | ioc->name, (unsigned long long)ioc->sas_hba.sas_address)); | |
4469 | ||
4470 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys | |
4471 | * sizeof(Mpi2SasIOUnit0PhyData_t)); | |
4472 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); | |
4473 | if (!sas_iounit_pg0) { | |
4474 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4475 | ioc->name, __FILE__, __LINE__, __func__); | |
4476 | return; | |
4477 | } | |
4478 | ||
4479 | if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, | |
4480 | sas_iounit_pg0, sz)) != 0) | |
4481 | goto out; | |
4482 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
4483 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | |
4484 | goto out; | |
4485 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { | |
4486 | link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4; | |
4487 | if (i == 0) | |
4488 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> | |
4489 | PhyData[0].ControllerDevHandle); | |
4490 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; | |
4491 | attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i]. | |
4492 | AttachedDevHandle); | |
4493 | if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) | |
4494 | link_rate = MPI2_SAS_NEG_LINK_RATE_1_5; | |
4495 | mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address, | |
4496 | attached_handle, i, link_rate); | |
4497 | } | |
4498 | out: | |
4499 | kfree(sas_iounit_pg0); | |
4500 | } | |
4501 | ||
4502 | /** | |
4503 | * _scsih_sas_host_add - create sas host object | |
4504 | * @ioc: per adapter object | |
4505 | * | |
4506 | * Creating host side data object, stored in ioc->sas_hba | |
4507 | * | |
4508 | * Return nothing. | |
4509 | */ | |
4510 | static void | |
4511 | _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc) | |
4512 | { | |
4513 | int i; | |
4514 | Mpi2ConfigReply_t mpi_reply; | |
4515 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; | |
4516 | Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; | |
4517 | Mpi2SasPhyPage0_t phy_pg0; | |
4518 | Mpi2SasDevicePage0_t sas_device_pg0; | |
4519 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
4520 | u16 ioc_status; | |
4521 | u16 sz; | |
4522 | u8 device_missing_delay; | |
4523 | ||
4524 | mpt3sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys); | |
4525 | if (!ioc->sas_hba.num_phys) { | |
4526 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4527 | ioc->name, __FILE__, __LINE__, __func__); | |
4528 | return; | |
4529 | } | |
4530 | ||
4531 | /* sas_iounit page 0 */ | |
4532 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys * | |
4533 | sizeof(Mpi2SasIOUnit0PhyData_t)); | |
4534 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); | |
4535 | if (!sas_iounit_pg0) { | |
4536 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4537 | ioc->name, __FILE__, __LINE__, __func__); | |
4538 | return; | |
4539 | } | |
4540 | if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, | |
4541 | sas_iounit_pg0, sz))) { | |
4542 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4543 | ioc->name, __FILE__, __LINE__, __func__); | |
4544 | goto out; | |
4545 | } | |
4546 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
4547 | MPI2_IOCSTATUS_MASK; | |
4548 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
4549 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4550 | ioc->name, __FILE__, __LINE__, __func__); | |
4551 | goto out; | |
4552 | } | |
4553 | ||
4554 | /* sas_iounit page 1 */ | |
4555 | sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys * | |
4556 | sizeof(Mpi2SasIOUnit1PhyData_t)); | |
4557 | sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL); | |
4558 | if (!sas_iounit_pg1) { | |
4559 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4560 | ioc->name, __FILE__, __LINE__, __func__); | |
4561 | goto out; | |
4562 | } | |
4563 | if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply, | |
4564 | sas_iounit_pg1, sz))) { | |
4565 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4566 | ioc->name, __FILE__, __LINE__, __func__); | |
4567 | goto out; | |
4568 | } | |
4569 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
4570 | MPI2_IOCSTATUS_MASK; | |
4571 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
4572 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4573 | ioc->name, __FILE__, __LINE__, __func__); | |
4574 | goto out; | |
4575 | } | |
4576 | ||
4577 | ioc->io_missing_delay = | |
4578 | sas_iounit_pg1->IODeviceMissingDelay; | |
4579 | device_missing_delay = | |
4580 | sas_iounit_pg1->ReportDeviceMissingDelay; | |
4581 | if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16) | |
4582 | ioc->device_missing_delay = (device_missing_delay & | |
4583 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16; | |
4584 | else | |
4585 | ioc->device_missing_delay = device_missing_delay & | |
4586 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK; | |
4587 | ||
4588 | ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev; | |
4589 | ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys, | |
4590 | sizeof(struct _sas_phy), GFP_KERNEL); | |
4591 | if (!ioc->sas_hba.phy) { | |
4592 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4593 | ioc->name, __FILE__, __LINE__, __func__); | |
4594 | goto out; | |
4595 | } | |
4596 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { | |
4597 | if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0, | |
4598 | i))) { | |
4599 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4600 | ioc->name, __FILE__, __LINE__, __func__); | |
4601 | goto out; | |
4602 | } | |
4603 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
4604 | MPI2_IOCSTATUS_MASK; | |
4605 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
4606 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4607 | ioc->name, __FILE__, __LINE__, __func__); | |
4608 | goto out; | |
4609 | } | |
4610 | ||
4611 | if (i == 0) | |
4612 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> | |
4613 | PhyData[0].ControllerDevHandle); | |
4614 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; | |
4615 | ioc->sas_hba.phy[i].phy_id = i; | |
4616 | mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i], | |
4617 | phy_pg0, ioc->sas_hba.parent_dev); | |
4618 | } | |
4619 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
4620 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) { | |
4621 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4622 | ioc->name, __FILE__, __LINE__, __func__); | |
4623 | goto out; | |
4624 | } | |
4625 | ioc->sas_hba.enclosure_handle = | |
4626 | le16_to_cpu(sas_device_pg0.EnclosureHandle); | |
4627 | ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | |
4628 | pr_info(MPT3SAS_FMT | |
4629 | "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n", | |
4630 | ioc->name, ioc->sas_hba.handle, | |
4631 | (unsigned long long) ioc->sas_hba.sas_address, | |
4632 | ioc->sas_hba.num_phys) ; | |
4633 | ||
4634 | if (ioc->sas_hba.enclosure_handle) { | |
4635 | if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
4636 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
4637 | ioc->sas_hba.enclosure_handle))) | |
4638 | ioc->sas_hba.enclosure_logical_id = | |
4639 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
4640 | } | |
4641 | ||
4642 | out: | |
4643 | kfree(sas_iounit_pg1); | |
4644 | kfree(sas_iounit_pg0); | |
4645 | } | |
4646 | ||
4647 | /** | |
4648 | * _scsih_expander_add - creating expander object | |
4649 | * @ioc: per adapter object | |
4650 | * @handle: expander handle | |
4651 | * | |
4652 | * Creating expander object, stored in ioc->sas_expander_list. | |
4653 | * | |
4654 | * Return 0 for success, else error. | |
4655 | */ | |
4656 | static int | |
4657 | _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
4658 | { | |
4659 | struct _sas_node *sas_expander; | |
4660 | Mpi2ConfigReply_t mpi_reply; | |
4661 | Mpi2ExpanderPage0_t expander_pg0; | |
4662 | Mpi2ExpanderPage1_t expander_pg1; | |
4663 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
4664 | u32 ioc_status; | |
4665 | u16 parent_handle; | |
4666 | u64 sas_address, sas_address_parent = 0; | |
4667 | int i; | |
4668 | unsigned long flags; | |
4669 | struct _sas_port *mpt3sas_port = NULL; | |
4670 | ||
4671 | int rc = 0; | |
4672 | ||
4673 | if (!handle) | |
4674 | return -1; | |
4675 | ||
4676 | if (ioc->shost_recovery || ioc->pci_error_recovery) | |
4677 | return -1; | |
4678 | ||
4679 | if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | |
4680 | MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) { | |
4681 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4682 | ioc->name, __FILE__, __LINE__, __func__); | |
4683 | return -1; | |
4684 | } | |
4685 | ||
4686 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
4687 | MPI2_IOCSTATUS_MASK; | |
4688 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
4689 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4690 | ioc->name, __FILE__, __LINE__, __func__); | |
4691 | return -1; | |
4692 | } | |
4693 | ||
4694 | /* handle out of order topology events */ | |
4695 | parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle); | |
4696 | if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent) | |
4697 | != 0) { | |
4698 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4699 | ioc->name, __FILE__, __LINE__, __func__); | |
4700 | return -1; | |
4701 | } | |
4702 | if (sas_address_parent != ioc->sas_hba.sas_address) { | |
4703 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
4704 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, | |
4705 | sas_address_parent); | |
4706 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
4707 | if (!sas_expander) { | |
4708 | rc = _scsih_expander_add(ioc, parent_handle); | |
4709 | if (rc != 0) | |
4710 | return rc; | |
4711 | } | |
4712 | } | |
4713 | ||
4714 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
4715 | sas_address = le64_to_cpu(expander_pg0.SASAddress); | |
4716 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, | |
4717 | sas_address); | |
4718 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
4719 | ||
4720 | if (sas_expander) | |
4721 | return 0; | |
4722 | ||
4723 | sas_expander = kzalloc(sizeof(struct _sas_node), | |
4724 | GFP_KERNEL); | |
4725 | if (!sas_expander) { | |
4726 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4727 | ioc->name, __FILE__, __LINE__, __func__); | |
4728 | return -1; | |
4729 | } | |
4730 | ||
4731 | sas_expander->handle = handle; | |
4732 | sas_expander->num_phys = expander_pg0.NumPhys; | |
4733 | sas_expander->sas_address_parent = sas_address_parent; | |
4734 | sas_expander->sas_address = sas_address; | |
4735 | ||
4736 | pr_info(MPT3SAS_FMT "expander_add: handle(0x%04x)," \ | |
4737 | " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name, | |
4738 | handle, parent_handle, (unsigned long long) | |
4739 | sas_expander->sas_address, sas_expander->num_phys); | |
4740 | ||
4741 | if (!sas_expander->num_phys) | |
4742 | goto out_fail; | |
4743 | sas_expander->phy = kcalloc(sas_expander->num_phys, | |
4744 | sizeof(struct _sas_phy), GFP_KERNEL); | |
4745 | if (!sas_expander->phy) { | |
4746 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4747 | ioc->name, __FILE__, __LINE__, __func__); | |
4748 | rc = -1; | |
4749 | goto out_fail; | |
4750 | } | |
4751 | ||
4752 | INIT_LIST_HEAD(&sas_expander->sas_port_list); | |
4753 | mpt3sas_port = mpt3sas_transport_port_add(ioc, handle, | |
4754 | sas_address_parent); | |
4755 | if (!mpt3sas_port) { | |
4756 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4757 | ioc->name, __FILE__, __LINE__, __func__); | |
4758 | rc = -1; | |
4759 | goto out_fail; | |
4760 | } | |
4761 | sas_expander->parent_dev = &mpt3sas_port->rphy->dev; | |
4762 | ||
4763 | for (i = 0 ; i < sas_expander->num_phys ; i++) { | |
4764 | if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply, | |
4765 | &expander_pg1, i, handle))) { | |
4766 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4767 | ioc->name, __FILE__, __LINE__, __func__); | |
4768 | rc = -1; | |
4769 | goto out_fail; | |
4770 | } | |
4771 | sas_expander->phy[i].handle = handle; | |
4772 | sas_expander->phy[i].phy_id = i; | |
4773 | ||
4774 | if ((mpt3sas_transport_add_expander_phy(ioc, | |
4775 | &sas_expander->phy[i], expander_pg1, | |
4776 | sas_expander->parent_dev))) { | |
4777 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4778 | ioc->name, __FILE__, __LINE__, __func__); | |
4779 | rc = -1; | |
4780 | goto out_fail; | |
4781 | } | |
4782 | } | |
4783 | ||
4784 | if (sas_expander->enclosure_handle) { | |
4785 | if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
4786 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
4787 | sas_expander->enclosure_handle))) | |
4788 | sas_expander->enclosure_logical_id = | |
4789 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
4790 | } | |
4791 | ||
4792 | _scsih_expander_node_add(ioc, sas_expander); | |
4793 | return 0; | |
4794 | ||
4795 | out_fail: | |
4796 | ||
4797 | if (mpt3sas_port) | |
4798 | mpt3sas_transport_port_remove(ioc, sas_expander->sas_address, | |
4799 | sas_address_parent); | |
4800 | kfree(sas_expander); | |
4801 | return rc; | |
4802 | } | |
4803 | ||
4804 | /** | |
4805 | * mpt3sas_expander_remove - removing expander object | |
4806 | * @ioc: per adapter object | |
4807 | * @sas_address: expander sas_address | |
4808 | * | |
4809 | * Return nothing. | |
4810 | */ | |
4811 | void | |
4812 | mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address) | |
4813 | { | |
4814 | struct _sas_node *sas_expander; | |
4815 | unsigned long flags; | |
4816 | ||
4817 | if (ioc->shost_recovery) | |
4818 | return; | |
4819 | ||
4820 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
4821 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, | |
4822 | sas_address); | |
4823 | if (sas_expander) | |
4824 | list_del(&sas_expander->list); | |
4825 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
4826 | if (sas_expander) | |
4827 | _scsih_expander_node_remove(ioc, sas_expander); | |
4828 | } | |
4829 | ||
4830 | /** | |
4831 | * _scsih_done - internal SCSI_IO callback handler. | |
4832 | * @ioc: per adapter object | |
4833 | * @smid: system request message index | |
4834 | * @msix_index: MSIX table index supplied by the OS | |
4835 | * @reply: reply message frame(lower 32bit addr) | |
4836 | * | |
4837 | * Callback handler when sending internal generated SCSI_IO. | |
4838 | * The callback index passed is `ioc->scsih_cb_idx` | |
4839 | * | |
4840 | * Return 1 meaning mf should be freed from _base_interrupt | |
4841 | * 0 means the mf is freed from this function. | |
4842 | */ | |
4843 | static u8 | |
4844 | _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | |
4845 | { | |
4846 | MPI2DefaultReply_t *mpi_reply; | |
4847 | ||
4848 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
4849 | if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED) | |
4850 | return 1; | |
4851 | if (ioc->scsih_cmds.smid != smid) | |
4852 | return 1; | |
4853 | ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE; | |
4854 | if (mpi_reply) { | |
4855 | memcpy(ioc->scsih_cmds.reply, mpi_reply, | |
4856 | mpi_reply->MsgLength*4); | |
4857 | ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID; | |
4858 | } | |
4859 | ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING; | |
4860 | complete(&ioc->scsih_cmds.done); | |
4861 | return 1; | |
4862 | } | |
4863 | ||
4864 | ||
4865 | ||
4866 | ||
4867 | #define MPT3_MAX_LUNS (255) | |
4868 | ||
4869 | ||
4870 | /** | |
4871 | * _scsih_check_access_status - check access flags | |
4872 | * @ioc: per adapter object | |
4873 | * @sas_address: sas address | |
4874 | * @handle: sas device handle | |
4875 | * @access_flags: errors returned during discovery of the device | |
4876 | * | |
4877 | * Return 0 for success, else failure | |
4878 | */ | |
4879 | static u8 | |
4880 | _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address, | |
4881 | u16 handle, u8 access_status) | |
4882 | { | |
4883 | u8 rc = 1; | |
4884 | char *desc = NULL; | |
4885 | ||
4886 | switch (access_status) { | |
4887 | case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS: | |
4888 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION: | |
4889 | rc = 0; | |
4890 | break; | |
4891 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED: | |
4892 | desc = "sata capability failed"; | |
4893 | break; | |
4894 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT: | |
4895 | desc = "sata affiliation conflict"; | |
4896 | break; | |
4897 | case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE: | |
4898 | desc = "route not addressable"; | |
4899 | break; | |
4900 | case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE: | |
4901 | desc = "smp error not addressable"; | |
4902 | break; | |
4903 | case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED: | |
4904 | desc = "device blocked"; | |
4905 | break; | |
4906 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED: | |
4907 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN: | |
4908 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT: | |
4909 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG: | |
4910 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION: | |
4911 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER: | |
4912 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN: | |
4913 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN: | |
4914 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN: | |
4915 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION: | |
4916 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE: | |
4917 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX: | |
4918 | desc = "sata initialization failed"; | |
4919 | break; | |
4920 | default: | |
4921 | desc = "unknown"; | |
4922 | break; | |
4923 | } | |
4924 | ||
4925 | if (!rc) | |
4926 | return 0; | |
4927 | ||
4928 | pr_err(MPT3SAS_FMT | |
4929 | "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n", | |
4930 | ioc->name, desc, (unsigned long long)sas_address, handle); | |
4931 | return rc; | |
4932 | } | |
4933 | ||
4934 | /** | |
4935 | * _scsih_check_device - checking device responsiveness | |
4936 | * @ioc: per adapter object | |
4937 | * @parent_sas_address: sas address of parent expander or sas host | |
4938 | * @handle: attached device handle | |
4939 | * @phy_numberv: phy number | |
4940 | * @link_rate: new link rate | |
4941 | * | |
4942 | * Returns nothing. | |
4943 | */ | |
4944 | static void | |
4945 | _scsih_check_device(struct MPT3SAS_ADAPTER *ioc, | |
4946 | u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate) | |
4947 | { | |
4948 | Mpi2ConfigReply_t mpi_reply; | |
4949 | Mpi2SasDevicePage0_t sas_device_pg0; | |
4950 | struct _sas_device *sas_device; | |
4951 | u32 ioc_status; | |
4952 | unsigned long flags; | |
4953 | u64 sas_address; | |
4954 | struct scsi_target *starget; | |
4955 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
4956 | u32 device_info; | |
4957 | ||
4958 | ||
4959 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
4960 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) | |
4961 | return; | |
4962 | ||
4963 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
4964 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | |
4965 | return; | |
4966 | ||
4967 | /* wide port handling ~ we need only handle device once for the phy that | |
4968 | * is matched in sas device page zero | |
4969 | */ | |
4970 | if (phy_number != sas_device_pg0.PhyNum) | |
4971 | return; | |
4972 | ||
4973 | /* check if this is end device */ | |
4974 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | |
4975 | if (!(_scsih_is_end_device(device_info))) | |
4976 | return; | |
4977 | ||
4978 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
4979 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | |
4980 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, | |
4981 | sas_address); | |
4982 | ||
4983 | if (!sas_device) { | |
4984 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
4985 | return; | |
4986 | } | |
4987 | ||
4988 | if (unlikely(sas_device->handle != handle)) { | |
4989 | starget = sas_device->starget; | |
4990 | sas_target_priv_data = starget->hostdata; | |
4991 | starget_printk(KERN_INFO, starget, | |
4992 | "handle changed from(0x%04x) to (0x%04x)!!!\n", | |
4993 | sas_device->handle, handle); | |
4994 | sas_target_priv_data->handle = handle; | |
4995 | sas_device->handle = handle; | |
e6d45e3e SR |
4996 | if (sas_device_pg0.Flags & |
4997 | MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) { | |
4998 | sas_device->enclosure_level = | |
4999 | le16_to_cpu(sas_device_pg0.EnclosureLevel); | |
5000 | memcpy(&sas_device->connector_name[0], | |
5001 | &sas_device_pg0.ConnectorName[0], 4); | |
5002 | } else { | |
5003 | sas_device->enclosure_level = 0; | |
5004 | sas_device->connector_name[0] = '\0'; | |
5005 | } | |
f92363d1 SR |
5006 | } |
5007 | ||
5008 | /* check if device is present */ | |
5009 | if (!(le16_to_cpu(sas_device_pg0.Flags) & | |
5010 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { | |
5011 | pr_err(MPT3SAS_FMT | |
5012 | "device is not present handle(0x%04x), flags!!!\n", | |
5013 | ioc->name, handle); | |
5014 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
5015 | return; | |
5016 | } | |
5017 | ||
5018 | /* check if there were any issues with discovery */ | |
5019 | if (_scsih_check_access_status(ioc, sas_address, handle, | |
5020 | sas_device_pg0.AccessStatus)) { | |
5021 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
5022 | return; | |
5023 | } | |
5024 | ||
5025 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
5026 | _scsih_ublock_io_device(ioc, sas_address); | |
5027 | ||
5028 | } | |
5029 | ||
5030 | /** | |
5031 | * _scsih_add_device - creating sas device object | |
5032 | * @ioc: per adapter object | |
5033 | * @handle: sas device handle | |
5034 | * @phy_num: phy number end device attached to | |
5035 | * @is_pd: is this hidden raid component | |
5036 | * | |
5037 | * Creating end device object, stored in ioc->sas_device_list. | |
5038 | * | |
5039 | * Returns 0 for success, non-zero for failure. | |
5040 | */ | |
5041 | static int | |
5042 | _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num, | |
5043 | u8 is_pd) | |
5044 | { | |
5045 | Mpi2ConfigReply_t mpi_reply; | |
5046 | Mpi2SasDevicePage0_t sas_device_pg0; | |
5047 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
5048 | struct _sas_device *sas_device; | |
5049 | u32 ioc_status; | |
5050 | u64 sas_address; | |
5051 | u32 device_info; | |
5052 | unsigned long flags; | |
5053 | ||
5054 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
5055 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
5056 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5057 | ioc->name, __FILE__, __LINE__, __func__); | |
5058 | return -1; | |
5059 | } | |
5060 | ||
5061 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5062 | MPI2_IOCSTATUS_MASK; | |
5063 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
5064 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5065 | ioc->name, __FILE__, __LINE__, __func__); | |
5066 | return -1; | |
5067 | } | |
5068 | ||
5069 | /* check if this is end device */ | |
5070 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | |
5071 | if (!(_scsih_is_end_device(device_info))) | |
5072 | return -1; | |
5073 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | |
5074 | ||
5075 | /* check if device is present */ | |
5076 | if (!(le16_to_cpu(sas_device_pg0.Flags) & | |
5077 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { | |
5078 | pr_err(MPT3SAS_FMT "device is not present handle(0x04%x)!!!\n", | |
5079 | ioc->name, handle); | |
5080 | return -1; | |
5081 | } | |
5082 | ||
5083 | /* check if there were any issues with discovery */ | |
5084 | if (_scsih_check_access_status(ioc, sas_address, handle, | |
5085 | sas_device_pg0.AccessStatus)) | |
5086 | return -1; | |
5087 | ||
5088 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
5089 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, | |
5090 | sas_address); | |
5091 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
5092 | ||
5093 | if (sas_device) | |
5094 | return -1; | |
5095 | ||
5096 | sas_device = kzalloc(sizeof(struct _sas_device), | |
5097 | GFP_KERNEL); | |
5098 | if (!sas_device) { | |
5099 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5100 | ioc->name, __FILE__, __LINE__, __func__); | |
5101 | return 0; | |
5102 | } | |
5103 | ||
5104 | sas_device->handle = handle; | |
5105 | if (_scsih_get_sas_address(ioc, | |
5106 | le16_to_cpu(sas_device_pg0.ParentDevHandle), | |
5107 | &sas_device->sas_address_parent) != 0) | |
5108 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5109 | ioc->name, __FILE__, __LINE__, __func__); | |
5110 | sas_device->enclosure_handle = | |
5111 | le16_to_cpu(sas_device_pg0.EnclosureHandle); | |
e6d45e3e SR |
5112 | if (sas_device->enclosure_handle != 0) |
5113 | sas_device->slot = | |
5114 | le16_to_cpu(sas_device_pg0.Slot); | |
f92363d1 SR |
5115 | sas_device->device_info = device_info; |
5116 | sas_device->sas_address = sas_address; | |
5117 | sas_device->phy = sas_device_pg0.PhyNum; | |
45506049 | 5118 | #ifndef SCSI_MPT2SAS |
f92363d1 SR |
5119 | sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) & |
5120 | MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0; | |
45506049 | 5121 | #endif |
f92363d1 | 5122 | |
e6d45e3e SR |
5123 | if (sas_device_pg0.Flags & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) { |
5124 | sas_device->enclosure_level = | |
5125 | le16_to_cpu(sas_device_pg0.EnclosureLevel); | |
5126 | memcpy(&sas_device->connector_name[0], | |
5127 | &sas_device_pg0.ConnectorName[0], 4); | |
5128 | } else { | |
5129 | sas_device->enclosure_level = 0; | |
5130 | sas_device->connector_name[0] = '\0'; | |
5131 | } | |
f92363d1 SR |
5132 | /* get enclosure_logical_id */ |
5133 | if (sas_device->enclosure_handle && !(mpt3sas_config_get_enclosure_pg0( | |
5134 | ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
5135 | sas_device->enclosure_handle))) | |
5136 | sas_device->enclosure_logical_id = | |
5137 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
5138 | ||
5139 | /* get device name */ | |
5140 | sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName); | |
5141 | ||
5142 | if (ioc->wait_for_discovery_to_complete) | |
5143 | _scsih_sas_device_init_add(ioc, sas_device); | |
5144 | else | |
5145 | _scsih_sas_device_add(ioc, sas_device); | |
5146 | ||
5147 | return 0; | |
5148 | } | |
5149 | ||
5150 | /** | |
5151 | * _scsih_remove_device - removing sas device object | |
5152 | * @ioc: per adapter object | |
5153 | * @sas_device_delete: the sas_device object | |
5154 | * | |
5155 | * Return nothing. | |
5156 | */ | |
5157 | static void | |
5158 | _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc, | |
5159 | struct _sas_device *sas_device) | |
5160 | { | |
5161 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
5162 | ||
0f624c39 SR |
5163 | if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) && |
5164 | (sas_device->pfa_led_on)) { | |
5165 | _scsih_turn_off_pfa_led(ioc, sas_device); | |
5166 | sas_device->pfa_led_on = 0; | |
5167 | } | |
f92363d1 SR |
5168 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
5169 | "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n", | |
5170 | ioc->name, __func__, | |
5171 | sas_device->handle, (unsigned long long) | |
5172 | sas_device->sas_address)); | |
e6d45e3e SR |
5173 | if (sas_device->enclosure_handle != 0) |
5174 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
5175 | "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n", | |
5176 | ioc->name, __func__, | |
5177 | (unsigned long long)sas_device->enclosure_logical_id, | |
5178 | sas_device->slot)); | |
5179 | if (sas_device->connector_name[0] != '\0') | |
5180 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
5181 | "%s: enter: enclosure level(0x%04x), connector name( %s)\n", | |
5182 | ioc->name, __func__, | |
5183 | sas_device->enclosure_level, | |
5184 | sas_device->connector_name)); | |
f92363d1 SR |
5185 | |
5186 | if (sas_device->starget && sas_device->starget->hostdata) { | |
5187 | sas_target_priv_data = sas_device->starget->hostdata; | |
5188 | sas_target_priv_data->deleted = 1; | |
5189 | _scsih_ublock_io_device(ioc, sas_device->sas_address); | |
5190 | sas_target_priv_data->handle = | |
5191 | MPT3SAS_INVALID_DEVICE_HANDLE; | |
5192 | } | |
7786ab6a SR |
5193 | |
5194 | if (!ioc->hide_drives) | |
5195 | mpt3sas_transport_port_remove(ioc, | |
f92363d1 SR |
5196 | sas_device->sas_address, |
5197 | sas_device->sas_address_parent); | |
5198 | ||
5199 | pr_info(MPT3SAS_FMT | |
5200 | "removing handle(0x%04x), sas_addr(0x%016llx)\n", | |
5201 | ioc->name, sas_device->handle, | |
5202 | (unsigned long long) sas_device->sas_address); | |
e6d45e3e SR |
5203 | if (sas_device->enclosure_handle != 0) |
5204 | pr_info(MPT3SAS_FMT | |
5205 | "removing : enclosure logical id(0x%016llx), slot(%d)\n", | |
5206 | ioc->name, | |
5207 | (unsigned long long)sas_device->enclosure_logical_id, | |
5208 | sas_device->slot); | |
5209 | if (sas_device->connector_name[0] != '\0') | |
5210 | pr_info(MPT3SAS_FMT | |
5211 | "removing enclosure level(0x%04x), connector name( %s)\n", | |
5212 | ioc->name, sas_device->enclosure_level, | |
5213 | sas_device->connector_name); | |
f92363d1 SR |
5214 | |
5215 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
5216 | "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n", | |
5217 | ioc->name, __func__, | |
e6d45e3e SR |
5218 | sas_device->handle, (unsigned long long) |
5219 | sas_device->sas_address)); | |
5220 | if (sas_device->enclosure_handle != 0) | |
5221 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
5222 | "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n", | |
5223 | ioc->name, __func__, | |
5224 | (unsigned long long)sas_device->enclosure_logical_id, | |
5225 | sas_device->slot)); | |
5226 | if (sas_device->connector_name[0] != '\0') | |
5227 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
5228 | "%s: exit: enclosure level(0x%04x), connector name(%s)\n", | |
5229 | ioc->name, __func__, sas_device->enclosure_level, | |
5230 | sas_device->connector_name)); | |
f92363d1 SR |
5231 | |
5232 | kfree(sas_device); | |
5233 | } | |
5234 | ||
f92363d1 SR |
5235 | /** |
5236 | * _scsih_sas_topology_change_event_debug - debug for topology event | |
5237 | * @ioc: per adapter object | |
5238 | * @event_data: event data payload | |
5239 | * Context: user. | |
5240 | */ | |
5241 | static void | |
5242 | _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
5243 | Mpi2EventDataSasTopologyChangeList_t *event_data) | |
5244 | { | |
5245 | int i; | |
5246 | u16 handle; | |
5247 | u16 reason_code; | |
5248 | u8 phy_number; | |
5249 | char *status_str = NULL; | |
5250 | u8 link_rate, prev_link_rate; | |
5251 | ||
5252 | switch (event_data->ExpStatus) { | |
5253 | case MPI2_EVENT_SAS_TOPO_ES_ADDED: | |
5254 | status_str = "add"; | |
5255 | break; | |
5256 | case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING: | |
5257 | status_str = "remove"; | |
5258 | break; | |
5259 | case MPI2_EVENT_SAS_TOPO_ES_RESPONDING: | |
5260 | case 0: | |
5261 | status_str = "responding"; | |
5262 | break; | |
5263 | case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING: | |
5264 | status_str = "remove delay"; | |
5265 | break; | |
5266 | default: | |
5267 | status_str = "unknown status"; | |
5268 | break; | |
5269 | } | |
5270 | pr_info(MPT3SAS_FMT "sas topology change: (%s)\n", | |
5271 | ioc->name, status_str); | |
5272 | pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \ | |
5273 | "start_phy(%02d), count(%d)\n", | |
5274 | le16_to_cpu(event_data->ExpanderDevHandle), | |
5275 | le16_to_cpu(event_data->EnclosureHandle), | |
5276 | event_data->StartPhyNum, event_data->NumEntries); | |
5277 | for (i = 0; i < event_data->NumEntries; i++) { | |
5278 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
5279 | if (!handle) | |
5280 | continue; | |
5281 | phy_number = event_data->StartPhyNum + i; | |
5282 | reason_code = event_data->PHY[i].PhyStatus & | |
5283 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
5284 | switch (reason_code) { | |
5285 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: | |
5286 | status_str = "target add"; | |
5287 | break; | |
5288 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: | |
5289 | status_str = "target remove"; | |
5290 | break; | |
5291 | case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING: | |
5292 | status_str = "delay target remove"; | |
5293 | break; | |
5294 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: | |
5295 | status_str = "link rate change"; | |
5296 | break; | |
5297 | case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE: | |
5298 | status_str = "target responding"; | |
5299 | break; | |
5300 | default: | |
5301 | status_str = "unknown"; | |
5302 | break; | |
5303 | } | |
5304 | link_rate = event_data->PHY[i].LinkRate >> 4; | |
5305 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; | |
5306 | pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \ | |
5307 | " link rate: new(0x%02x), old(0x%02x)\n", phy_number, | |
5308 | handle, status_str, link_rate, prev_link_rate); | |
5309 | ||
5310 | } | |
5311 | } | |
f92363d1 SR |
5312 | |
5313 | /** | |
5314 | * _scsih_sas_topology_change_event - handle topology changes | |
5315 | * @ioc: per adapter object | |
5316 | * @fw_event: The fw_event_work object | |
5317 | * Context: user. | |
5318 | * | |
5319 | */ | |
5320 | static int | |
5321 | _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc, | |
5322 | struct fw_event_work *fw_event) | |
5323 | { | |
5324 | int i; | |
5325 | u16 parent_handle, handle; | |
5326 | u16 reason_code; | |
5327 | u8 phy_number, max_phys; | |
5328 | struct _sas_node *sas_expander; | |
5329 | u64 sas_address; | |
5330 | unsigned long flags; | |
5331 | u8 link_rate, prev_link_rate; | |
35b62362 JL |
5332 | Mpi2EventDataSasTopologyChangeList_t *event_data = |
5333 | (Mpi2EventDataSasTopologyChangeList_t *) | |
5334 | fw_event->event_data; | |
f92363d1 | 5335 | |
f92363d1 SR |
5336 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
5337 | _scsih_sas_topology_change_event_debug(ioc, event_data); | |
f92363d1 SR |
5338 | |
5339 | if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery) | |
5340 | return 0; | |
5341 | ||
5342 | if (!ioc->sas_hba.num_phys) | |
5343 | _scsih_sas_host_add(ioc); | |
5344 | else | |
5345 | _scsih_sas_host_refresh(ioc); | |
5346 | ||
5347 | if (fw_event->ignore) { | |
5348 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
5349 | "ignoring expander event\n", ioc->name)); | |
5350 | return 0; | |
5351 | } | |
5352 | ||
5353 | parent_handle = le16_to_cpu(event_data->ExpanderDevHandle); | |
5354 | ||
5355 | /* handle expander add */ | |
5356 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED) | |
5357 | if (_scsih_expander_add(ioc, parent_handle) != 0) | |
5358 | return 0; | |
5359 | ||
5360 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
5361 | sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc, | |
5362 | parent_handle); | |
5363 | if (sas_expander) { | |
5364 | sas_address = sas_expander->sas_address; | |
5365 | max_phys = sas_expander->num_phys; | |
5366 | } else if (parent_handle < ioc->sas_hba.num_phys) { | |
5367 | sas_address = ioc->sas_hba.sas_address; | |
5368 | max_phys = ioc->sas_hba.num_phys; | |
5369 | } else { | |
5370 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
5371 | return 0; | |
5372 | } | |
5373 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
5374 | ||
5375 | /* handle siblings events */ | |
5376 | for (i = 0; i < event_data->NumEntries; i++) { | |
5377 | if (fw_event->ignore) { | |
5378 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
5379 | "ignoring expander event\n", ioc->name)); | |
5380 | return 0; | |
5381 | } | |
5382 | if (ioc->remove_host || ioc->pci_error_recovery) | |
5383 | return 0; | |
5384 | phy_number = event_data->StartPhyNum + i; | |
5385 | if (phy_number >= max_phys) | |
5386 | continue; | |
5387 | reason_code = event_data->PHY[i].PhyStatus & | |
5388 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
5389 | if ((event_data->PHY[i].PhyStatus & | |
5390 | MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code != | |
5391 | MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)) | |
5392 | continue; | |
5393 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
5394 | if (!handle) | |
5395 | continue; | |
5396 | link_rate = event_data->PHY[i].LinkRate >> 4; | |
5397 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; | |
5398 | switch (reason_code) { | |
5399 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: | |
5400 | ||
5401 | if (ioc->shost_recovery) | |
5402 | break; | |
5403 | ||
5404 | if (link_rate == prev_link_rate) | |
5405 | break; | |
5406 | ||
5407 | mpt3sas_transport_update_links(ioc, sas_address, | |
5408 | handle, phy_number, link_rate); | |
5409 | ||
5410 | if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) | |
5411 | break; | |
5412 | ||
5413 | _scsih_check_device(ioc, sas_address, handle, | |
5414 | phy_number, link_rate); | |
5415 | ||
5416 | ||
5417 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: | |
5418 | ||
5419 | if (ioc->shost_recovery) | |
5420 | break; | |
5421 | ||
5422 | mpt3sas_transport_update_links(ioc, sas_address, | |
5423 | handle, phy_number, link_rate); | |
5424 | ||
5425 | _scsih_add_device(ioc, handle, phy_number, 0); | |
5426 | ||
5427 | break; | |
5428 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: | |
5429 | ||
5430 | _scsih_device_remove_by_handle(ioc, handle); | |
5431 | break; | |
5432 | } | |
5433 | } | |
5434 | ||
5435 | /* handle expander removal */ | |
5436 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING && | |
5437 | sas_expander) | |
5438 | mpt3sas_expander_remove(ioc, sas_address); | |
5439 | ||
5440 | return 0; | |
5441 | } | |
5442 | ||
f92363d1 SR |
5443 | /** |
5444 | * _scsih_sas_device_status_change_event_debug - debug for device event | |
5445 | * @event_data: event data payload | |
5446 | * Context: user. | |
5447 | * | |
5448 | * Return nothing. | |
5449 | */ | |
5450 | static void | |
5451 | _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
5452 | Mpi2EventDataSasDeviceStatusChange_t *event_data) | |
5453 | { | |
5454 | char *reason_str = NULL; | |
5455 | ||
5456 | switch (event_data->ReasonCode) { | |
5457 | case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA: | |
5458 | reason_str = "smart data"; | |
5459 | break; | |
5460 | case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED: | |
5461 | reason_str = "unsupported device discovered"; | |
5462 | break; | |
5463 | case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET: | |
5464 | reason_str = "internal device reset"; | |
5465 | break; | |
5466 | case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL: | |
5467 | reason_str = "internal task abort"; | |
5468 | break; | |
5469 | case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL: | |
5470 | reason_str = "internal task abort set"; | |
5471 | break; | |
5472 | case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL: | |
5473 | reason_str = "internal clear task set"; | |
5474 | break; | |
5475 | case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL: | |
5476 | reason_str = "internal query task"; | |
5477 | break; | |
5478 | case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE: | |
5479 | reason_str = "sata init failure"; | |
5480 | break; | |
5481 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET: | |
5482 | reason_str = "internal device reset complete"; | |
5483 | break; | |
5484 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL: | |
5485 | reason_str = "internal task abort complete"; | |
5486 | break; | |
5487 | case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION: | |
5488 | reason_str = "internal async notification"; | |
5489 | break; | |
5490 | case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY: | |
5491 | reason_str = "expander reduced functionality"; | |
5492 | break; | |
5493 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY: | |
5494 | reason_str = "expander reduced functionality complete"; | |
5495 | break; | |
5496 | default: | |
5497 | reason_str = "unknown reason"; | |
5498 | break; | |
5499 | } | |
5500 | pr_info(MPT3SAS_FMT "device status change: (%s)\n" | |
5501 | "\thandle(0x%04x), sas address(0x%016llx), tag(%d)", | |
5502 | ioc->name, reason_str, le16_to_cpu(event_data->DevHandle), | |
5503 | (unsigned long long)le64_to_cpu(event_data->SASAddress), | |
5504 | le16_to_cpu(event_data->TaskTag)); | |
5505 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA) | |
5506 | pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name, | |
5507 | event_data->ASC, event_data->ASCQ); | |
5508 | pr_info("\n"); | |
5509 | } | |
f92363d1 SR |
5510 | |
5511 | /** | |
5512 | * _scsih_sas_device_status_change_event - handle device status change | |
5513 | * @ioc: per adapter object | |
5514 | * @fw_event: The fw_event_work object | |
5515 | * Context: user. | |
5516 | * | |
5517 | * Return nothing. | |
5518 | */ | |
5519 | static void | |
5520 | _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc, | |
5521 | struct fw_event_work *fw_event) | |
5522 | { | |
5523 | struct MPT3SAS_TARGET *target_priv_data; | |
5524 | struct _sas_device *sas_device; | |
5525 | u64 sas_address; | |
5526 | unsigned long flags; | |
5527 | Mpi2EventDataSasDeviceStatusChange_t *event_data = | |
35b62362 JL |
5528 | (Mpi2EventDataSasDeviceStatusChange_t *) |
5529 | fw_event->event_data; | |
f92363d1 | 5530 | |
f92363d1 SR |
5531 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
5532 | _scsih_sas_device_status_change_event_debug(ioc, | |
5533 | event_data); | |
f92363d1 SR |
5534 | |
5535 | /* In MPI Revision K (0xC), the internal device reset complete was | |
5536 | * implemented, so avoid setting tm_busy flag for older firmware. | |
5537 | */ | |
5538 | if ((ioc->facts.HeaderVersion >> 8) < 0xC) | |
5539 | return; | |
5540 | ||
5541 | if (event_data->ReasonCode != | |
5542 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET && | |
5543 | event_data->ReasonCode != | |
5544 | MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET) | |
5545 | return; | |
5546 | ||
5547 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
5548 | sas_address = le64_to_cpu(event_data->SASAddress); | |
5549 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, | |
5550 | sas_address); | |
5551 | ||
5552 | if (!sas_device || !sas_device->starget) { | |
5553 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
5554 | return; | |
5555 | } | |
5556 | ||
5557 | target_priv_data = sas_device->starget->hostdata; | |
5558 | if (!target_priv_data) { | |
5559 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
5560 | return; | |
5561 | } | |
5562 | ||
5563 | if (event_data->ReasonCode == | |
5564 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET) | |
5565 | target_priv_data->tm_busy = 1; | |
5566 | else | |
5567 | target_priv_data->tm_busy = 0; | |
5568 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
5569 | } | |
5570 | ||
f92363d1 SR |
5571 | /** |
5572 | * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure | |
5573 | * event | |
5574 | * @ioc: per adapter object | |
5575 | * @event_data: event data payload | |
5576 | * Context: user. | |
5577 | * | |
5578 | * Return nothing. | |
5579 | */ | |
5580 | static void | |
5581 | _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
5582 | Mpi2EventDataSasEnclDevStatusChange_t *event_data) | |
5583 | { | |
5584 | char *reason_str = NULL; | |
5585 | ||
5586 | switch (event_data->ReasonCode) { | |
5587 | case MPI2_EVENT_SAS_ENCL_RC_ADDED: | |
5588 | reason_str = "enclosure add"; | |
5589 | break; | |
5590 | case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING: | |
5591 | reason_str = "enclosure remove"; | |
5592 | break; | |
5593 | default: | |
5594 | reason_str = "unknown reason"; | |
5595 | break; | |
5596 | } | |
5597 | ||
5598 | pr_info(MPT3SAS_FMT "enclosure status change: (%s)\n" | |
5599 | "\thandle(0x%04x), enclosure logical id(0x%016llx)" | |
5600 | " number slots(%d)\n", ioc->name, reason_str, | |
5601 | le16_to_cpu(event_data->EnclosureHandle), | |
5602 | (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID), | |
5603 | le16_to_cpu(event_data->StartSlot)); | |
5604 | } | |
f92363d1 SR |
5605 | |
5606 | /** | |
5607 | * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events | |
5608 | * @ioc: per adapter object | |
5609 | * @fw_event: The fw_event_work object | |
5610 | * Context: user. | |
5611 | * | |
5612 | * Return nothing. | |
5613 | */ | |
5614 | static void | |
5615 | _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc, | |
5616 | struct fw_event_work *fw_event) | |
5617 | { | |
f92363d1 SR |
5618 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
5619 | _scsih_sas_enclosure_dev_status_change_event_debug(ioc, | |
35b62362 | 5620 | (Mpi2EventDataSasEnclDevStatusChange_t *) |
f92363d1 | 5621 | fw_event->event_data); |
f92363d1 SR |
5622 | } |
5623 | ||
5624 | /** | |
5625 | * _scsih_sas_broadcast_primitive_event - handle broadcast events | |
5626 | * @ioc: per adapter object | |
5627 | * @fw_event: The fw_event_work object | |
5628 | * Context: user. | |
5629 | * | |
5630 | * Return nothing. | |
5631 | */ | |
5632 | static void | |
5633 | _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc, | |
5634 | struct fw_event_work *fw_event) | |
5635 | { | |
5636 | struct scsi_cmnd *scmd; | |
5637 | struct scsi_device *sdev; | |
5638 | u16 smid, handle; | |
5639 | u32 lun; | |
5640 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
5641 | u32 termination_count; | |
5642 | u32 query_count; | |
5643 | Mpi2SCSITaskManagementReply_t *mpi_reply; | |
35b62362 JL |
5644 | Mpi2EventDataSasBroadcastPrimitive_t *event_data = |
5645 | (Mpi2EventDataSasBroadcastPrimitive_t *) | |
5646 | fw_event->event_data; | |
f92363d1 SR |
5647 | u16 ioc_status; |
5648 | unsigned long flags; | |
5649 | int r; | |
5650 | u8 max_retries = 0; | |
5651 | u8 task_abort_retries; | |
5652 | ||
5653 | mutex_lock(&ioc->tm_cmds.mutex); | |
5654 | pr_info(MPT3SAS_FMT | |
5655 | "%s: enter: phy number(%d), width(%d)\n", | |
5656 | ioc->name, __func__, event_data->PhyNum, | |
5657 | event_data->PortWidth); | |
5658 | ||
5659 | _scsih_block_io_all_device(ioc); | |
5660 | ||
5661 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
5662 | mpi_reply = ioc->tm_cmds.reply; | |
5663 | broadcast_aen_retry: | |
5664 | ||
5665 | /* sanity checks for retrying this loop */ | |
5666 | if (max_retries++ == 5) { | |
5667 | dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: giving up\n", | |
5668 | ioc->name, __func__)); | |
5669 | goto out; | |
5670 | } else if (max_retries > 1) | |
5671 | dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: %d retry\n", | |
5672 | ioc->name, __func__, max_retries - 1)); | |
5673 | ||
5674 | termination_count = 0; | |
5675 | query_count = 0; | |
5676 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { | |
5677 | if (ioc->shost_recovery) | |
5678 | goto out; | |
5679 | scmd = _scsih_scsi_lookup_get(ioc, smid); | |
5680 | if (!scmd) | |
5681 | continue; | |
5682 | sdev = scmd->device; | |
5683 | sas_device_priv_data = sdev->hostdata; | |
5684 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) | |
5685 | continue; | |
5686 | /* skip hidden raid components */ | |
5687 | if (sas_device_priv_data->sas_target->flags & | |
5688 | MPT_TARGET_FLAGS_RAID_COMPONENT) | |
5689 | continue; | |
5690 | /* skip volumes */ | |
5691 | if (sas_device_priv_data->sas_target->flags & | |
5692 | MPT_TARGET_FLAGS_VOLUME) | |
5693 | continue; | |
5694 | ||
5695 | handle = sas_device_priv_data->sas_target->handle; | |
5696 | lun = sas_device_priv_data->lun; | |
5697 | query_count++; | |
5698 | ||
5699 | if (ioc->shost_recovery) | |
5700 | goto out; | |
5701 | ||
5702 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
5703 | r = mpt3sas_scsih_issue_tm(ioc, handle, 0, 0, lun, | |
c62e46de | 5704 | MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30, |
f92363d1 SR |
5705 | TM_MUTEX_OFF); |
5706 | if (r == FAILED) { | |
5707 | sdev_printk(KERN_WARNING, sdev, | |
5708 | "mpt3sas_scsih_issue_tm: FAILED when sending " | |
5709 | "QUERY_TASK: scmd(%p)\n", scmd); | |
5710 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
5711 | goto broadcast_aen_retry; | |
5712 | } | |
5713 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) | |
5714 | & MPI2_IOCSTATUS_MASK; | |
5715 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
5716 | sdev_printk(KERN_WARNING, sdev, | |
5717 | "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n", | |
5718 | ioc_status, scmd); | |
5719 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
5720 | goto broadcast_aen_retry; | |
5721 | } | |
5722 | ||
5723 | /* see if IO is still owned by IOC and target */ | |
5724 | if (mpi_reply->ResponseCode == | |
5725 | MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED || | |
5726 | mpi_reply->ResponseCode == | |
5727 | MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) { | |
5728 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
5729 | continue; | |
5730 | } | |
5731 | task_abort_retries = 0; | |
5732 | tm_retry: | |
5733 | if (task_abort_retries++ == 60) { | |
5734 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
5735 | "%s: ABORT_TASK: giving up\n", ioc->name, | |
5736 | __func__)); | |
5737 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
5738 | goto broadcast_aen_retry; | |
5739 | } | |
5740 | ||
5741 | if (ioc->shost_recovery) | |
5742 | goto out_no_lock; | |
5743 | ||
5744 | r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id, | |
5745 | sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, | |
c62e46de | 5746 | TM_MUTEX_OFF); |
f92363d1 SR |
5747 | if (r == FAILED) { |
5748 | sdev_printk(KERN_WARNING, sdev, | |
5749 | "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : " | |
5750 | "scmd(%p)\n", scmd); | |
5751 | goto tm_retry; | |
5752 | } | |
5753 | ||
5754 | if (task_abort_retries > 1) | |
5755 | sdev_printk(KERN_WARNING, sdev, | |
5756 | "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):" | |
5757 | " scmd(%p)\n", | |
5758 | task_abort_retries - 1, scmd); | |
5759 | ||
5760 | termination_count += le32_to_cpu(mpi_reply->TerminationCount); | |
5761 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
5762 | } | |
5763 | ||
5764 | if (ioc->broadcast_aen_pending) { | |
5765 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
5766 | "%s: loop back due to pending AEN\n", | |
5767 | ioc->name, __func__)); | |
5768 | ioc->broadcast_aen_pending = 0; | |
5769 | goto broadcast_aen_retry; | |
5770 | } | |
5771 | ||
5772 | out: | |
5773 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
5774 | out_no_lock: | |
5775 | ||
5776 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
5777 | "%s - exit, query_count = %d termination_count = %d\n", | |
5778 | ioc->name, __func__, query_count, termination_count)); | |
5779 | ||
5780 | ioc->broadcast_aen_busy = 0; | |
5781 | if (!ioc->shost_recovery) | |
5782 | _scsih_ublock_io_all_device(ioc); | |
5783 | mutex_unlock(&ioc->tm_cmds.mutex); | |
5784 | } | |
5785 | ||
5786 | /** | |
5787 | * _scsih_sas_discovery_event - handle discovery events | |
5788 | * @ioc: per adapter object | |
5789 | * @fw_event: The fw_event_work object | |
5790 | * Context: user. | |
5791 | * | |
5792 | * Return nothing. | |
5793 | */ | |
5794 | static void | |
5795 | _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc, | |
5796 | struct fw_event_work *fw_event) | |
5797 | { | |
35b62362 JL |
5798 | Mpi2EventDataSasDiscovery_t *event_data = |
5799 | (Mpi2EventDataSasDiscovery_t *) fw_event->event_data; | |
f92363d1 | 5800 | |
f92363d1 SR |
5801 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) { |
5802 | pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name, | |
5803 | (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ? | |
5804 | "start" : "stop"); | |
af009411 SR |
5805 | if (event_data->DiscoveryStatus) |
5806 | pr_info("discovery_status(0x%08x)", | |
5807 | le32_to_cpu(event_data->DiscoveryStatus)); | |
5808 | pr_info("\n"); | |
f92363d1 | 5809 | } |
f92363d1 SR |
5810 | |
5811 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED && | |
5812 | !ioc->sas_hba.num_phys) { | |
5813 | if (disable_discovery > 0 && ioc->shost_recovery) { | |
5814 | /* Wait for the reset to complete */ | |
5815 | while (ioc->shost_recovery) | |
5816 | ssleep(1); | |
5817 | } | |
5818 | _scsih_sas_host_add(ioc); | |
5819 | } | |
5820 | } | |
5821 | ||
45506049 | 5822 | #ifndef SCSI_MPT2SAS |
f92363d1 SR |
5823 | /** |
5824 | * _scsih_ir_fastpath - turn on fastpath for IR physdisk | |
5825 | * @ioc: per adapter object | |
5826 | * @handle: device handle for physical disk | |
5827 | * @phys_disk_num: physical disk number | |
5828 | * | |
5829 | * Return 0 for success, else failure. | |
5830 | */ | |
5831 | static int | |
5832 | _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num) | |
5833 | { | |
5834 | Mpi2RaidActionRequest_t *mpi_request; | |
5835 | Mpi2RaidActionReply_t *mpi_reply; | |
5836 | u16 smid; | |
5837 | u8 issue_reset = 0; | |
5838 | int rc = 0; | |
5839 | u16 ioc_status; | |
5840 | u32 log_info; | |
5841 | ||
f92363d1 SR |
5842 | mutex_lock(&ioc->scsih_cmds.mutex); |
5843 | ||
5844 | if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) { | |
5845 | pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n", | |
5846 | ioc->name, __func__); | |
5847 | rc = -EAGAIN; | |
5848 | goto out; | |
5849 | } | |
5850 | ioc->scsih_cmds.status = MPT3_CMD_PENDING; | |
5851 | ||
5852 | smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx); | |
5853 | if (!smid) { | |
5854 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
5855 | ioc->name, __func__); | |
5856 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
5857 | rc = -EAGAIN; | |
5858 | goto out; | |
5859 | } | |
5860 | ||
5861 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
5862 | ioc->scsih_cmds.smid = smid; | |
5863 | memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t)); | |
5864 | ||
5865 | mpi_request->Function = MPI2_FUNCTION_RAID_ACTION; | |
5866 | mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN; | |
5867 | mpi_request->PhysDiskNum = phys_disk_num; | |
5868 | ||
5869 | dewtprintk(ioc, pr_info(MPT3SAS_FMT "IR RAID_ACTION: turning fast "\ | |
5870 | "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc->name, | |
5871 | handle, phys_disk_num)); | |
5872 | ||
5873 | init_completion(&ioc->scsih_cmds.done); | |
5874 | mpt3sas_base_put_smid_default(ioc, smid); | |
5875 | wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ); | |
5876 | ||
5877 | if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) { | |
5878 | pr_err(MPT3SAS_FMT "%s: timeout\n", | |
5879 | ioc->name, __func__); | |
5880 | if (!(ioc->scsih_cmds.status & MPT3_CMD_RESET)) | |
5881 | issue_reset = 1; | |
5882 | rc = -EFAULT; | |
5883 | goto out; | |
5884 | } | |
5885 | ||
5886 | if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) { | |
5887 | ||
5888 | mpi_reply = ioc->scsih_cmds.reply; | |
5889 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); | |
5890 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) | |
5891 | log_info = le32_to_cpu(mpi_reply->IOCLogInfo); | |
5892 | else | |
5893 | log_info = 0; | |
5894 | ioc_status &= MPI2_IOCSTATUS_MASK; | |
5895 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
5896 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
5897 | "IR RAID_ACTION: failed: ioc_status(0x%04x), " | |
5898 | "loginfo(0x%08x)!!!\n", ioc->name, ioc_status, | |
5899 | log_info)); | |
5900 | rc = -EFAULT; | |
5901 | } else | |
5902 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
5903 | "IR RAID_ACTION: completed successfully\n", | |
5904 | ioc->name)); | |
5905 | } | |
5906 | ||
5907 | out: | |
5908 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
5909 | mutex_unlock(&ioc->scsih_cmds.mutex); | |
5910 | ||
5911 | if (issue_reset) | |
5912 | mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, | |
5913 | FORCE_BIG_HAMMER); | |
5914 | return rc; | |
5915 | } | |
45506049 SR |
5916 | /* End of not defined SCSI_MPT2SAS */ |
5917 | #endif | |
f92363d1 SR |
5918 | |
5919 | /** | |
5920 | * _scsih_reprobe_lun - reprobing lun | |
5921 | * @sdev: scsi device struct | |
5922 | * @no_uld_attach: sdev->no_uld_attach flag setting | |
5923 | * | |
5924 | **/ | |
5925 | static void | |
5926 | _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach) | |
5927 | { | |
5928 | int rc; | |
5929 | sdev->no_uld_attach = no_uld_attach ? 1 : 0; | |
5930 | sdev_printk(KERN_INFO, sdev, "%s raid component\n", | |
5931 | sdev->no_uld_attach ? "hidding" : "exposing"); | |
5932 | rc = scsi_device_reprobe(sdev); | |
5933 | } | |
5934 | ||
5935 | /** | |
5936 | * _scsih_sas_volume_add - add new volume | |
5937 | * @ioc: per adapter object | |
5938 | * @element: IR config element data | |
5939 | * Context: user. | |
5940 | * | |
5941 | * Return nothing. | |
5942 | */ | |
5943 | static void | |
5944 | _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc, | |
5945 | Mpi2EventIrConfigElement_t *element) | |
5946 | { | |
5947 | struct _raid_device *raid_device; | |
5948 | unsigned long flags; | |
5949 | u64 wwid; | |
5950 | u16 handle = le16_to_cpu(element->VolDevHandle); | |
5951 | int rc; | |
5952 | ||
5953 | mpt3sas_config_get_volume_wwid(ioc, handle, &wwid); | |
5954 | if (!wwid) { | |
5955 | pr_err(MPT3SAS_FMT | |
5956 | "failure at %s:%d/%s()!\n", ioc->name, | |
5957 | __FILE__, __LINE__, __func__); | |
5958 | return; | |
5959 | } | |
5960 | ||
5961 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
5962 | raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid); | |
5963 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
5964 | ||
5965 | if (raid_device) | |
5966 | return; | |
5967 | ||
5968 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); | |
5969 | if (!raid_device) { | |
5970 | pr_err(MPT3SAS_FMT | |
5971 | "failure at %s:%d/%s()!\n", ioc->name, | |
5972 | __FILE__, __LINE__, __func__); | |
5973 | return; | |
5974 | } | |
5975 | ||
5976 | raid_device->id = ioc->sas_id++; | |
5977 | raid_device->channel = RAID_CHANNEL; | |
5978 | raid_device->handle = handle; | |
5979 | raid_device->wwid = wwid; | |
5980 | _scsih_raid_device_add(ioc, raid_device); | |
5981 | if (!ioc->wait_for_discovery_to_complete) { | |
5982 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
5983 | raid_device->id, 0); | |
5984 | if (rc) | |
5985 | _scsih_raid_device_remove(ioc, raid_device); | |
5986 | } else { | |
5987 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
5988 | _scsih_determine_boot_device(ioc, raid_device, 1); | |
5989 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
5990 | } | |
5991 | } | |
5992 | ||
5993 | /** | |
5994 | * _scsih_sas_volume_delete - delete volume | |
5995 | * @ioc: per adapter object | |
5996 | * @handle: volume device handle | |
5997 | * Context: user. | |
5998 | * | |
5999 | * Return nothing. | |
6000 | */ | |
6001 | static void | |
6002 | _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
6003 | { | |
6004 | struct _raid_device *raid_device; | |
6005 | unsigned long flags; | |
6006 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
6007 | struct scsi_target *starget = NULL; | |
6008 | ||
6009 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
6010 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); | |
6011 | if (raid_device) { | |
6012 | if (raid_device->starget) { | |
6013 | starget = raid_device->starget; | |
6014 | sas_target_priv_data = starget->hostdata; | |
6015 | sas_target_priv_data->deleted = 1; | |
6016 | } | |
6017 | pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n", | |
6018 | ioc->name, raid_device->handle, | |
6019 | (unsigned long long) raid_device->wwid); | |
6020 | list_del(&raid_device->list); | |
6021 | kfree(raid_device); | |
6022 | } | |
6023 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
6024 | if (starget) | |
6025 | scsi_remove_target(&starget->dev); | |
6026 | } | |
6027 | ||
6028 | /** | |
6029 | * _scsih_sas_pd_expose - expose pd component to /dev/sdX | |
6030 | * @ioc: per adapter object | |
6031 | * @element: IR config element data | |
6032 | * Context: user. | |
6033 | * | |
6034 | * Return nothing. | |
6035 | */ | |
6036 | static void | |
6037 | _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc, | |
6038 | Mpi2EventIrConfigElement_t *element) | |
6039 | { | |
6040 | struct _sas_device *sas_device; | |
6041 | struct scsi_target *starget = NULL; | |
6042 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
6043 | unsigned long flags; | |
6044 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | |
6045 | ||
6046 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
6047 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); | |
6048 | if (sas_device) { | |
6049 | sas_device->volume_handle = 0; | |
6050 | sas_device->volume_wwid = 0; | |
6051 | clear_bit(handle, ioc->pd_handles); | |
6052 | if (sas_device->starget && sas_device->starget->hostdata) { | |
6053 | starget = sas_device->starget; | |
6054 | sas_target_priv_data = starget->hostdata; | |
6055 | sas_target_priv_data->flags &= | |
6056 | ~MPT_TARGET_FLAGS_RAID_COMPONENT; | |
6057 | } | |
6058 | } | |
6059 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
6060 | if (!sas_device) | |
6061 | return; | |
6062 | ||
6063 | /* exposing raid component */ | |
6064 | if (starget) | |
6065 | starget_for_each_device(starget, NULL, _scsih_reprobe_lun); | |
6066 | } | |
6067 | ||
6068 | /** | |
6069 | * _scsih_sas_pd_hide - hide pd component from /dev/sdX | |
6070 | * @ioc: per adapter object | |
6071 | * @element: IR config element data | |
6072 | * Context: user. | |
6073 | * | |
6074 | * Return nothing. | |
6075 | */ | |
6076 | static void | |
6077 | _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc, | |
6078 | Mpi2EventIrConfigElement_t *element) | |
6079 | { | |
6080 | struct _sas_device *sas_device; | |
6081 | struct scsi_target *starget = NULL; | |
6082 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
6083 | unsigned long flags; | |
6084 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | |
6085 | u16 volume_handle = 0; | |
6086 | u64 volume_wwid = 0; | |
6087 | ||
6088 | mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle); | |
6089 | if (volume_handle) | |
6090 | mpt3sas_config_get_volume_wwid(ioc, volume_handle, | |
6091 | &volume_wwid); | |
6092 | ||
6093 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
6094 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); | |
6095 | if (sas_device) { | |
6096 | set_bit(handle, ioc->pd_handles); | |
6097 | if (sas_device->starget && sas_device->starget->hostdata) { | |
6098 | starget = sas_device->starget; | |
6099 | sas_target_priv_data = starget->hostdata; | |
6100 | sas_target_priv_data->flags |= | |
6101 | MPT_TARGET_FLAGS_RAID_COMPONENT; | |
6102 | sas_device->volume_handle = volume_handle; | |
6103 | sas_device->volume_wwid = volume_wwid; | |
6104 | } | |
6105 | } | |
6106 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
6107 | if (!sas_device) | |
6108 | return; | |
6109 | ||
45506049 | 6110 | #ifndef SCSI_MPT2SAS |
f92363d1 SR |
6111 | /* hiding raid component */ |
6112 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); | |
45506049 | 6113 | #endif |
f92363d1 SR |
6114 | if (starget) |
6115 | starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun); | |
6116 | } | |
6117 | ||
6118 | /** | |
6119 | * _scsih_sas_pd_delete - delete pd component | |
6120 | * @ioc: per adapter object | |
6121 | * @element: IR config element data | |
6122 | * Context: user. | |
6123 | * | |
6124 | * Return nothing. | |
6125 | */ | |
6126 | static void | |
6127 | _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc, | |
6128 | Mpi2EventIrConfigElement_t *element) | |
6129 | { | |
6130 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | |
6131 | ||
6132 | _scsih_device_remove_by_handle(ioc, handle); | |
6133 | } | |
6134 | ||
6135 | /** | |
6136 | * _scsih_sas_pd_add - remove pd component | |
6137 | * @ioc: per adapter object | |
6138 | * @element: IR config element data | |
6139 | * Context: user. | |
6140 | * | |
6141 | * Return nothing. | |
6142 | */ | |
6143 | static void | |
6144 | _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc, | |
6145 | Mpi2EventIrConfigElement_t *element) | |
6146 | { | |
6147 | struct _sas_device *sas_device; | |
6148 | unsigned long flags; | |
6149 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | |
6150 | Mpi2ConfigReply_t mpi_reply; | |
6151 | Mpi2SasDevicePage0_t sas_device_pg0; | |
6152 | u32 ioc_status; | |
6153 | u64 sas_address; | |
6154 | u16 parent_handle; | |
6155 | ||
6156 | set_bit(handle, ioc->pd_handles); | |
6157 | ||
6158 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
6159 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); | |
6160 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
6161 | if (sas_device) { | |
45506049 | 6162 | #ifndef SCSI_MPT2SAS |
f92363d1 | 6163 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); |
45506049 | 6164 | #endif |
f92363d1 SR |
6165 | return; |
6166 | } | |
6167 | ||
6168 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
6169 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
6170 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6171 | ioc->name, __FILE__, __LINE__, __func__); | |
6172 | return; | |
6173 | } | |
6174 | ||
6175 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6176 | MPI2_IOCSTATUS_MASK; | |
6177 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
6178 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6179 | ioc->name, __FILE__, __LINE__, __func__); | |
6180 | return; | |
6181 | } | |
6182 | ||
6183 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | |
6184 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) | |
6185 | mpt3sas_transport_update_links(ioc, sas_address, handle, | |
6186 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | |
6187 | ||
45506049 | 6188 | #ifndef SCSI_MPT2SAS |
f92363d1 | 6189 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); |
45506049 | 6190 | #endif |
f92363d1 SR |
6191 | _scsih_add_device(ioc, handle, 0, 1); |
6192 | } | |
6193 | ||
f92363d1 SR |
6194 | /** |
6195 | * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events | |
6196 | * @ioc: per adapter object | |
6197 | * @event_data: event data payload | |
6198 | * Context: user. | |
6199 | * | |
6200 | * Return nothing. | |
6201 | */ | |
6202 | static void | |
6203 | _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
6204 | Mpi2EventDataIrConfigChangeList_t *event_data) | |
6205 | { | |
6206 | Mpi2EventIrConfigElement_t *element; | |
6207 | u8 element_type; | |
6208 | int i; | |
6209 | char *reason_str = NULL, *element_str = NULL; | |
6210 | ||
6211 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
6212 | ||
6213 | pr_info(MPT3SAS_FMT "raid config change: (%s), elements(%d)\n", | |
6214 | ioc->name, (le32_to_cpu(event_data->Flags) & | |
6215 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? | |
6216 | "foreign" : "native", event_data->NumElements); | |
6217 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
6218 | switch (element->ReasonCode) { | |
6219 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: | |
6220 | reason_str = "add"; | |
6221 | break; | |
6222 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: | |
6223 | reason_str = "remove"; | |
6224 | break; | |
6225 | case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE: | |
6226 | reason_str = "no change"; | |
6227 | break; | |
6228 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: | |
6229 | reason_str = "hide"; | |
6230 | break; | |
6231 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: | |
6232 | reason_str = "unhide"; | |
6233 | break; | |
6234 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: | |
6235 | reason_str = "volume_created"; | |
6236 | break; | |
6237 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: | |
6238 | reason_str = "volume_deleted"; | |
6239 | break; | |
6240 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: | |
6241 | reason_str = "pd_created"; | |
6242 | break; | |
6243 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: | |
6244 | reason_str = "pd_deleted"; | |
6245 | break; | |
6246 | default: | |
6247 | reason_str = "unknown reason"; | |
6248 | break; | |
6249 | } | |
6250 | element_type = le16_to_cpu(element->ElementFlags) & | |
6251 | MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK; | |
6252 | switch (element_type) { | |
6253 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT: | |
6254 | element_str = "volume"; | |
6255 | break; | |
6256 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT: | |
6257 | element_str = "phys disk"; | |
6258 | break; | |
6259 | case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT: | |
6260 | element_str = "hot spare"; | |
6261 | break; | |
6262 | default: | |
6263 | element_str = "unknown element"; | |
6264 | break; | |
6265 | } | |
6266 | pr_info("\t(%s:%s), vol handle(0x%04x), " \ | |
6267 | "pd handle(0x%04x), pd num(0x%02x)\n", element_str, | |
6268 | reason_str, le16_to_cpu(element->VolDevHandle), | |
6269 | le16_to_cpu(element->PhysDiskDevHandle), | |
6270 | element->PhysDiskNum); | |
6271 | } | |
6272 | } | |
f92363d1 SR |
6273 | |
6274 | /** | |
6275 | * _scsih_sas_ir_config_change_event - handle ir configuration change events | |
6276 | * @ioc: per adapter object | |
6277 | * @fw_event: The fw_event_work object | |
6278 | * Context: user. | |
6279 | * | |
6280 | * Return nothing. | |
6281 | */ | |
6282 | static void | |
6283 | _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc, | |
6284 | struct fw_event_work *fw_event) | |
6285 | { | |
6286 | Mpi2EventIrConfigElement_t *element; | |
6287 | int i; | |
6288 | u8 foreign_config; | |
35b62362 JL |
6289 | Mpi2EventDataIrConfigChangeList_t *event_data = |
6290 | (Mpi2EventDataIrConfigChangeList_t *) | |
6291 | fw_event->event_data; | |
f92363d1 | 6292 | |
7786ab6a SR |
6293 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) && |
6294 | (!ioc->hide_ir_msg)) | |
f92363d1 SR |
6295 | _scsih_sas_ir_config_change_event_debug(ioc, event_data); |
6296 | ||
f92363d1 SR |
6297 | foreign_config = (le32_to_cpu(event_data->Flags) & |
6298 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0; | |
6299 | ||
6300 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
6301 | if (ioc->shost_recovery) { | |
45506049 | 6302 | #ifndef SCSI_MPT2SAS |
f92363d1 SR |
6303 | for (i = 0; i < event_data->NumElements; i++, element++) { |
6304 | if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE) | |
6305 | _scsih_ir_fastpath(ioc, | |
6306 | le16_to_cpu(element->PhysDiskDevHandle), | |
6307 | element->PhysDiskNum); | |
6308 | } | |
45506049 | 6309 | #endif |
f92363d1 SR |
6310 | return; |
6311 | } | |
7786ab6a | 6312 | |
f92363d1 SR |
6313 | for (i = 0; i < event_data->NumElements; i++, element++) { |
6314 | ||
6315 | switch (element->ReasonCode) { | |
6316 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: | |
6317 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: | |
6318 | if (!foreign_config) | |
6319 | _scsih_sas_volume_add(ioc, element); | |
6320 | break; | |
6321 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: | |
6322 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: | |
6323 | if (!foreign_config) | |
6324 | _scsih_sas_volume_delete(ioc, | |
6325 | le16_to_cpu(element->VolDevHandle)); | |
6326 | break; | |
6327 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: | |
7786ab6a SR |
6328 | if (!ioc->is_warpdrive) |
6329 | _scsih_sas_pd_hide(ioc, element); | |
f92363d1 SR |
6330 | break; |
6331 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: | |
7786ab6a SR |
6332 | if (!ioc->is_warpdrive) |
6333 | _scsih_sas_pd_expose(ioc, element); | |
f92363d1 SR |
6334 | break; |
6335 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: | |
7786ab6a SR |
6336 | if (!ioc->is_warpdrive) |
6337 | _scsih_sas_pd_add(ioc, element); | |
f92363d1 SR |
6338 | break; |
6339 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: | |
7786ab6a SR |
6340 | if (!ioc->is_warpdrive) |
6341 | _scsih_sas_pd_delete(ioc, element); | |
f92363d1 SR |
6342 | break; |
6343 | } | |
6344 | } | |
6345 | } | |
6346 | ||
6347 | /** | |
6348 | * _scsih_sas_ir_volume_event - IR volume event | |
6349 | * @ioc: per adapter object | |
6350 | * @fw_event: The fw_event_work object | |
6351 | * Context: user. | |
6352 | * | |
6353 | * Return nothing. | |
6354 | */ | |
6355 | static void | |
6356 | _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc, | |
6357 | struct fw_event_work *fw_event) | |
6358 | { | |
6359 | u64 wwid; | |
6360 | unsigned long flags; | |
6361 | struct _raid_device *raid_device; | |
6362 | u16 handle; | |
6363 | u32 state; | |
6364 | int rc; | |
35b62362 JL |
6365 | Mpi2EventDataIrVolume_t *event_data = |
6366 | (Mpi2EventDataIrVolume_t *) fw_event->event_data; | |
f92363d1 SR |
6367 | |
6368 | if (ioc->shost_recovery) | |
6369 | return; | |
6370 | ||
6371 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) | |
6372 | return; | |
6373 | ||
6374 | handle = le16_to_cpu(event_data->VolDevHandle); | |
6375 | state = le32_to_cpu(event_data->NewValue); | |
7786ab6a SR |
6376 | if (!ioc->hide_ir_msg) |
6377 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6378 | "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n", | |
6379 | ioc->name, __func__, handle, | |
6380 | le32_to_cpu(event_data->PreviousValue), state)); | |
f92363d1 SR |
6381 | switch (state) { |
6382 | case MPI2_RAID_VOL_STATE_MISSING: | |
6383 | case MPI2_RAID_VOL_STATE_FAILED: | |
6384 | _scsih_sas_volume_delete(ioc, handle); | |
6385 | break; | |
6386 | ||
6387 | case MPI2_RAID_VOL_STATE_ONLINE: | |
6388 | case MPI2_RAID_VOL_STATE_DEGRADED: | |
6389 | case MPI2_RAID_VOL_STATE_OPTIMAL: | |
6390 | ||
6391 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
6392 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); | |
6393 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
6394 | ||
6395 | if (raid_device) | |
6396 | break; | |
6397 | ||
6398 | mpt3sas_config_get_volume_wwid(ioc, handle, &wwid); | |
6399 | if (!wwid) { | |
6400 | pr_err(MPT3SAS_FMT | |
6401 | "failure at %s:%d/%s()!\n", ioc->name, | |
6402 | __FILE__, __LINE__, __func__); | |
6403 | break; | |
6404 | } | |
6405 | ||
6406 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); | |
6407 | if (!raid_device) { | |
6408 | pr_err(MPT3SAS_FMT | |
6409 | "failure at %s:%d/%s()!\n", ioc->name, | |
6410 | __FILE__, __LINE__, __func__); | |
6411 | break; | |
6412 | } | |
6413 | ||
6414 | raid_device->id = ioc->sas_id++; | |
6415 | raid_device->channel = RAID_CHANNEL; | |
6416 | raid_device->handle = handle; | |
6417 | raid_device->wwid = wwid; | |
6418 | _scsih_raid_device_add(ioc, raid_device); | |
6419 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
6420 | raid_device->id, 0); | |
6421 | if (rc) | |
6422 | _scsih_raid_device_remove(ioc, raid_device); | |
6423 | break; | |
6424 | ||
6425 | case MPI2_RAID_VOL_STATE_INITIALIZING: | |
6426 | default: | |
6427 | break; | |
6428 | } | |
6429 | } | |
6430 | ||
6431 | /** | |
6432 | * _scsih_sas_ir_physical_disk_event - PD event | |
6433 | * @ioc: per adapter object | |
6434 | * @fw_event: The fw_event_work object | |
6435 | * Context: user. | |
6436 | * | |
6437 | * Return nothing. | |
6438 | */ | |
6439 | static void | |
6440 | _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc, | |
6441 | struct fw_event_work *fw_event) | |
6442 | { | |
6443 | u16 handle, parent_handle; | |
6444 | u32 state; | |
6445 | struct _sas_device *sas_device; | |
6446 | unsigned long flags; | |
6447 | Mpi2ConfigReply_t mpi_reply; | |
6448 | Mpi2SasDevicePage0_t sas_device_pg0; | |
6449 | u32 ioc_status; | |
35b62362 JL |
6450 | Mpi2EventDataIrPhysicalDisk_t *event_data = |
6451 | (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data; | |
f92363d1 SR |
6452 | u64 sas_address; |
6453 | ||
6454 | if (ioc->shost_recovery) | |
6455 | return; | |
6456 | ||
6457 | if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED) | |
6458 | return; | |
6459 | ||
6460 | handle = le16_to_cpu(event_data->PhysDiskDevHandle); | |
6461 | state = le32_to_cpu(event_data->NewValue); | |
6462 | ||
7786ab6a SR |
6463 | if (!ioc->hide_ir_msg) |
6464 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6465 | "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n", | |
6466 | ioc->name, __func__, handle, | |
f92363d1 | 6467 | le32_to_cpu(event_data->PreviousValue), state)); |
7786ab6a | 6468 | |
f92363d1 SR |
6469 | switch (state) { |
6470 | case MPI2_RAID_PD_STATE_ONLINE: | |
6471 | case MPI2_RAID_PD_STATE_DEGRADED: | |
6472 | case MPI2_RAID_PD_STATE_REBUILDING: | |
6473 | case MPI2_RAID_PD_STATE_OPTIMAL: | |
6474 | case MPI2_RAID_PD_STATE_HOT_SPARE: | |
6475 | ||
7786ab6a SR |
6476 | if (!ioc->is_warpdrive) |
6477 | set_bit(handle, ioc->pd_handles); | |
f92363d1 SR |
6478 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
6479 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); | |
6480 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
6481 | ||
6482 | if (sas_device) | |
6483 | return; | |
6484 | ||
6485 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
6486 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | |
6487 | handle))) { | |
6488 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6489 | ioc->name, __FILE__, __LINE__, __func__); | |
6490 | return; | |
6491 | } | |
6492 | ||
6493 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6494 | MPI2_IOCSTATUS_MASK; | |
6495 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
6496 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6497 | ioc->name, __FILE__, __LINE__, __func__); | |
6498 | return; | |
6499 | } | |
6500 | ||
6501 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | |
6502 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) | |
6503 | mpt3sas_transport_update_links(ioc, sas_address, handle, | |
6504 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | |
6505 | ||
6506 | _scsih_add_device(ioc, handle, 0, 1); | |
6507 | ||
6508 | break; | |
6509 | ||
6510 | case MPI2_RAID_PD_STATE_OFFLINE: | |
6511 | case MPI2_RAID_PD_STATE_NOT_CONFIGURED: | |
6512 | case MPI2_RAID_PD_STATE_NOT_COMPATIBLE: | |
6513 | default: | |
6514 | break; | |
6515 | } | |
6516 | } | |
6517 | ||
f92363d1 SR |
6518 | /** |
6519 | * _scsih_sas_ir_operation_status_event_debug - debug for IR op event | |
6520 | * @ioc: per adapter object | |
6521 | * @event_data: event data payload | |
6522 | * Context: user. | |
6523 | * | |
6524 | * Return nothing. | |
6525 | */ | |
6526 | static void | |
6527 | _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
6528 | Mpi2EventDataIrOperationStatus_t *event_data) | |
6529 | { | |
6530 | char *reason_str = NULL; | |
6531 | ||
6532 | switch (event_data->RAIDOperation) { | |
6533 | case MPI2_EVENT_IR_RAIDOP_RESYNC: | |
6534 | reason_str = "resync"; | |
6535 | break; | |
6536 | case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION: | |
6537 | reason_str = "online capacity expansion"; | |
6538 | break; | |
6539 | case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK: | |
6540 | reason_str = "consistency check"; | |
6541 | break; | |
6542 | case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT: | |
6543 | reason_str = "background init"; | |
6544 | break; | |
6545 | case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT: | |
6546 | reason_str = "make data consistent"; | |
6547 | break; | |
6548 | } | |
6549 | ||
6550 | if (!reason_str) | |
6551 | return; | |
6552 | ||
6553 | pr_info(MPT3SAS_FMT "raid operational status: (%s)" \ | |
6554 | "\thandle(0x%04x), percent complete(%d)\n", | |
6555 | ioc->name, reason_str, | |
6556 | le16_to_cpu(event_data->VolDevHandle), | |
6557 | event_data->PercentComplete); | |
6558 | } | |
f92363d1 SR |
6559 | |
6560 | /** | |
6561 | * _scsih_sas_ir_operation_status_event - handle RAID operation events | |
6562 | * @ioc: per adapter object | |
6563 | * @fw_event: The fw_event_work object | |
6564 | * Context: user. | |
6565 | * | |
6566 | * Return nothing. | |
6567 | */ | |
6568 | static void | |
6569 | _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc, | |
6570 | struct fw_event_work *fw_event) | |
6571 | { | |
35b62362 JL |
6572 | Mpi2EventDataIrOperationStatus_t *event_data = |
6573 | (Mpi2EventDataIrOperationStatus_t *) | |
6574 | fw_event->event_data; | |
f92363d1 SR |
6575 | static struct _raid_device *raid_device; |
6576 | unsigned long flags; | |
6577 | u16 handle; | |
6578 | ||
7786ab6a SR |
6579 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) && |
6580 | (!ioc->hide_ir_msg)) | |
f92363d1 SR |
6581 | _scsih_sas_ir_operation_status_event_debug(ioc, |
6582 | event_data); | |
f92363d1 SR |
6583 | |
6584 | /* code added for raid transport support */ | |
6585 | if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) { | |
6586 | ||
6587 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
6588 | handle = le16_to_cpu(event_data->VolDevHandle); | |
6589 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); | |
6590 | if (raid_device) | |
6591 | raid_device->percent_complete = | |
6592 | event_data->PercentComplete; | |
6593 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
6594 | } | |
6595 | } | |
6596 | ||
6597 | /** | |
6598 | * _scsih_prep_device_scan - initialize parameters prior to device scan | |
6599 | * @ioc: per adapter object | |
6600 | * | |
6601 | * Set the deleted flag prior to device scan. If the device is found during | |
6602 | * the scan, then we clear the deleted flag. | |
6603 | */ | |
6604 | static void | |
6605 | _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc) | |
6606 | { | |
6607 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
6608 | struct scsi_device *sdev; | |
6609 | ||
6610 | shost_for_each_device(sdev, ioc->shost) { | |
6611 | sas_device_priv_data = sdev->hostdata; | |
6612 | if (sas_device_priv_data && sas_device_priv_data->sas_target) | |
6613 | sas_device_priv_data->sas_target->deleted = 1; | |
6614 | } | |
6615 | } | |
6616 | ||
6617 | /** | |
6618 | * _scsih_mark_responding_sas_device - mark a sas_devices as responding | |
6619 | * @ioc: per adapter object | |
e6d45e3e | 6620 | * @sas_device_pg0: SAS Device page 0 |
f92363d1 SR |
6621 | * |
6622 | * After host reset, find out whether devices are still responding. | |
6623 | * Used in _scsih_remove_unresponsive_sas_devices. | |
6624 | * | |
6625 | * Return nothing. | |
6626 | */ | |
6627 | static void | |
e6d45e3e SR |
6628 | _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc, |
6629 | Mpi2SasDevicePage0_t *sas_device_pg0) | |
f92363d1 SR |
6630 | { |
6631 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; | |
6632 | struct scsi_target *starget; | |
6633 | struct _sas_device *sas_device; | |
6634 | unsigned long flags; | |
6635 | ||
6636 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
6637 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) { | |
e6d45e3e SR |
6638 | if ((sas_device->sas_address == sas_device_pg0->SASAddress) && |
6639 | (sas_device->slot == sas_device_pg0->Slot)) { | |
f92363d1 SR |
6640 | sas_device->responding = 1; |
6641 | starget = sas_device->starget; | |
6642 | if (starget && starget->hostdata) { | |
6643 | sas_target_priv_data = starget->hostdata; | |
6644 | sas_target_priv_data->tm_busy = 0; | |
6645 | sas_target_priv_data->deleted = 0; | |
6646 | } else | |
6647 | sas_target_priv_data = NULL; | |
e6d45e3e | 6648 | if (starget) { |
f92363d1 | 6649 | starget_printk(KERN_INFO, starget, |
e6d45e3e SR |
6650 | "handle(0x%04x), sas_addr(0x%016llx)\n", |
6651 | sas_device_pg0->DevHandle, | |
f92363d1 | 6652 | (unsigned long long) |
e6d45e3e SR |
6653 | sas_device->sas_address); |
6654 | ||
6655 | if (sas_device->enclosure_handle != 0) | |
6656 | starget_printk(KERN_INFO, starget, | |
6657 | "enclosure logical id(0x%016llx)," | |
6658 | " slot(%d)\n", | |
6659 | (unsigned long long) | |
6660 | sas_device->enclosure_logical_id, | |
6661 | sas_device->slot); | |
6662 | } | |
6663 | if (sas_device_pg0->Flags & | |
6664 | MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) { | |
6665 | sas_device->enclosure_level = | |
6666 | le16_to_cpu(sas_device_pg0->EnclosureLevel); | |
6667 | memcpy(&sas_device->connector_name[0], | |
6668 | &sas_device_pg0->ConnectorName[0], 4); | |
6669 | } else { | |
6670 | sas_device->enclosure_level = 0; | |
6671 | sas_device->connector_name[0] = '\0'; | |
6672 | } | |
6673 | ||
6674 | if (sas_device->handle == sas_device_pg0->DevHandle) | |
f92363d1 SR |
6675 | goto out; |
6676 | pr_info("\thandle changed from(0x%04x)!!!\n", | |
6677 | sas_device->handle); | |
e6d45e3e | 6678 | sas_device->handle = sas_device_pg0->DevHandle; |
f92363d1 | 6679 | if (sas_target_priv_data) |
e6d45e3e SR |
6680 | sas_target_priv_data->handle = |
6681 | sas_device_pg0->DevHandle; | |
f92363d1 SR |
6682 | goto out; |
6683 | } | |
6684 | } | |
6685 | out: | |
6686 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
6687 | } | |
6688 | ||
6689 | /** | |
6690 | * _scsih_search_responding_sas_devices - | |
6691 | * @ioc: per adapter object | |
6692 | * | |
6693 | * After host reset, find out whether devices are still responding. | |
6694 | * If not remove. | |
6695 | * | |
6696 | * Return nothing. | |
6697 | */ | |
6698 | static void | |
6699 | _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc) | |
6700 | { | |
6701 | Mpi2SasDevicePage0_t sas_device_pg0; | |
6702 | Mpi2ConfigReply_t mpi_reply; | |
6703 | u16 ioc_status; | |
6704 | u16 handle; | |
6705 | u32 device_info; | |
6706 | ||
6707 | pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name); | |
6708 | ||
6709 | if (list_empty(&ioc->sas_device_list)) | |
6710 | goto out; | |
6711 | ||
6712 | handle = 0xFFFF; | |
6713 | while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
6714 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | |
6715 | handle))) { | |
6716 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6717 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 6718 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 | 6719 | break; |
e6d45e3e SR |
6720 | handle = sas_device_pg0.DevHandle = |
6721 | le16_to_cpu(sas_device_pg0.DevHandle); | |
f92363d1 SR |
6722 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
6723 | if (!(_scsih_is_end_device(device_info))) | |
6724 | continue; | |
e6d45e3e SR |
6725 | sas_device_pg0.SASAddress = |
6726 | le64_to_cpu(sas_device_pg0.SASAddress); | |
6727 | sas_device_pg0.Slot = le16_to_cpu(sas_device_pg0.Slot); | |
6728 | _scsih_mark_responding_sas_device(ioc, &sas_device_pg0); | |
f92363d1 SR |
6729 | } |
6730 | ||
6731 | out: | |
6732 | pr_info(MPT3SAS_FMT "search for end-devices: complete\n", | |
6733 | ioc->name); | |
6734 | } | |
6735 | ||
6736 | /** | |
6737 | * _scsih_mark_responding_raid_device - mark a raid_device as responding | |
6738 | * @ioc: per adapter object | |
6739 | * @wwid: world wide identifier for raid volume | |
6740 | * @handle: device handle | |
6741 | * | |
6742 | * After host reset, find out whether devices are still responding. | |
6743 | * Used in _scsih_remove_unresponsive_raid_devices. | |
6744 | * | |
6745 | * Return nothing. | |
6746 | */ | |
6747 | static void | |
6748 | _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid, | |
6749 | u16 handle) | |
6750 | { | |
7786ab6a | 6751 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; |
f92363d1 SR |
6752 | struct scsi_target *starget; |
6753 | struct _raid_device *raid_device; | |
6754 | unsigned long flags; | |
6755 | ||
6756 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
6757 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
6758 | if (raid_device->wwid == wwid && raid_device->starget) { | |
6759 | starget = raid_device->starget; | |
6760 | if (starget && starget->hostdata) { | |
6761 | sas_target_priv_data = starget->hostdata; | |
6762 | sas_target_priv_data->deleted = 0; | |
6763 | } else | |
6764 | sas_target_priv_data = NULL; | |
6765 | raid_device->responding = 1; | |
6766 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
6767 | starget_printk(KERN_INFO, raid_device->starget, | |
6768 | "handle(0x%04x), wwid(0x%016llx)\n", handle, | |
6769 | (unsigned long long)raid_device->wwid); | |
7786ab6a SR |
6770 | |
6771 | #ifdef SCSI_MPT2SAS | |
6772 | /* | |
6773 | * WARPDRIVE: The handles of the PDs might have changed | |
6774 | * across the host reset so re-initialize the | |
6775 | * required data for Direct IO | |
6776 | */ | |
6777 | _scsih_init_warpdrive_properties(ioc, raid_device); | |
6778 | #endif | |
f92363d1 SR |
6779 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
6780 | if (raid_device->handle == handle) { | |
6781 | spin_unlock_irqrestore(&ioc->raid_device_lock, | |
6782 | flags); | |
6783 | return; | |
6784 | } | |
6785 | pr_info("\thandle changed from(0x%04x)!!!\n", | |
6786 | raid_device->handle); | |
6787 | raid_device->handle = handle; | |
6788 | if (sas_target_priv_data) | |
6789 | sas_target_priv_data->handle = handle; | |
6790 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
6791 | return; | |
6792 | } | |
6793 | } | |
6794 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
6795 | } | |
6796 | ||
6797 | /** | |
6798 | * _scsih_search_responding_raid_devices - | |
6799 | * @ioc: per adapter object | |
6800 | * | |
6801 | * After host reset, find out whether devices are still responding. | |
6802 | * If not remove. | |
6803 | * | |
6804 | * Return nothing. | |
6805 | */ | |
6806 | static void | |
6807 | _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc) | |
6808 | { | |
6809 | Mpi2RaidVolPage1_t volume_pg1; | |
6810 | Mpi2RaidVolPage0_t volume_pg0; | |
6811 | Mpi2RaidPhysDiskPage0_t pd_pg0; | |
6812 | Mpi2ConfigReply_t mpi_reply; | |
6813 | u16 ioc_status; | |
6814 | u16 handle; | |
6815 | u8 phys_disk_num; | |
6816 | ||
6817 | if (!ioc->ir_firmware) | |
6818 | return; | |
6819 | ||
6820 | pr_info(MPT3SAS_FMT "search for raid volumes: start\n", | |
6821 | ioc->name); | |
6822 | ||
6823 | if (list_empty(&ioc->raid_device_list)) | |
6824 | goto out; | |
6825 | ||
6826 | handle = 0xFFFF; | |
6827 | while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply, | |
6828 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { | |
6829 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6830 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 6831 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 SR |
6832 | break; |
6833 | handle = le16_to_cpu(volume_pg1.DevHandle); | |
6834 | ||
6835 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, | |
6836 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
6837 | sizeof(Mpi2RaidVolPage0_t))) | |
6838 | continue; | |
6839 | ||
6840 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || | |
6841 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || | |
6842 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) | |
6843 | _scsih_mark_responding_raid_device(ioc, | |
6844 | le64_to_cpu(volume_pg1.WWID), handle); | |
6845 | } | |
6846 | ||
6847 | /* refresh the pd_handles */ | |
7786ab6a | 6848 | if (!ioc->is_warpdrive) { |
f92363d1 SR |
6849 | phys_disk_num = 0xFF; |
6850 | memset(ioc->pd_handles, 0, ioc->pd_handles_sz); | |
6851 | while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | |
6852 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, | |
6853 | phys_disk_num))) { | |
6854 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6855 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 6856 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 SR |
6857 | break; |
6858 | phys_disk_num = pd_pg0.PhysDiskNum; | |
6859 | handle = le16_to_cpu(pd_pg0.DevHandle); | |
6860 | set_bit(handle, ioc->pd_handles); | |
6861 | } | |
7786ab6a | 6862 | } |
f92363d1 SR |
6863 | out: |
6864 | pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n", | |
6865 | ioc->name); | |
6866 | } | |
6867 | ||
6868 | /** | |
6869 | * _scsih_mark_responding_expander - mark a expander as responding | |
6870 | * @ioc: per adapter object | |
6871 | * @sas_address: sas address | |
6872 | * @handle: | |
6873 | * | |
6874 | * After host reset, find out whether devices are still responding. | |
6875 | * Used in _scsih_remove_unresponsive_expanders. | |
6876 | * | |
6877 | * Return nothing. | |
6878 | */ | |
6879 | static void | |
6880 | _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc, u64 sas_address, | |
6881 | u16 handle) | |
6882 | { | |
6883 | struct _sas_node *sas_expander; | |
6884 | unsigned long flags; | |
6885 | int i; | |
6886 | ||
6887 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
6888 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { | |
6889 | if (sas_expander->sas_address != sas_address) | |
6890 | continue; | |
6891 | sas_expander->responding = 1; | |
6892 | if (sas_expander->handle == handle) | |
6893 | goto out; | |
6894 | pr_info("\texpander(0x%016llx): handle changed" \ | |
6895 | " from(0x%04x) to (0x%04x)!!!\n", | |
6896 | (unsigned long long)sas_expander->sas_address, | |
6897 | sas_expander->handle, handle); | |
6898 | sas_expander->handle = handle; | |
6899 | for (i = 0 ; i < sas_expander->num_phys ; i++) | |
6900 | sas_expander->phy[i].handle = handle; | |
6901 | goto out; | |
6902 | } | |
6903 | out: | |
6904 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
6905 | } | |
6906 | ||
6907 | /** | |
6908 | * _scsih_search_responding_expanders - | |
6909 | * @ioc: per adapter object | |
6910 | * | |
6911 | * After host reset, find out whether devices are still responding. | |
6912 | * If not remove. | |
6913 | * | |
6914 | * Return nothing. | |
6915 | */ | |
6916 | static void | |
6917 | _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc) | |
6918 | { | |
6919 | Mpi2ExpanderPage0_t expander_pg0; | |
6920 | Mpi2ConfigReply_t mpi_reply; | |
6921 | u16 ioc_status; | |
6922 | u64 sas_address; | |
6923 | u16 handle; | |
6924 | ||
6925 | pr_info(MPT3SAS_FMT "search for expanders: start\n", ioc->name); | |
6926 | ||
6927 | if (list_empty(&ioc->sas_expander_list)) | |
6928 | goto out; | |
6929 | ||
6930 | handle = 0xFFFF; | |
6931 | while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | |
6932 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { | |
6933 | ||
6934 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6935 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 6936 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 SR |
6937 | break; |
6938 | ||
6939 | handle = le16_to_cpu(expander_pg0.DevHandle); | |
6940 | sas_address = le64_to_cpu(expander_pg0.SASAddress); | |
6941 | pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n", | |
6942 | handle, | |
6943 | (unsigned long long)sas_address); | |
6944 | _scsih_mark_responding_expander(ioc, sas_address, handle); | |
6945 | } | |
6946 | ||
6947 | out: | |
6948 | pr_info(MPT3SAS_FMT "search for expanders: complete\n", ioc->name); | |
6949 | } | |
6950 | ||
6951 | /** | |
6952 | * _scsih_remove_unresponding_sas_devices - removing unresponding devices | |
6953 | * @ioc: per adapter object | |
6954 | * | |
6955 | * Return nothing. | |
6956 | */ | |
6957 | static void | |
6958 | _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER *ioc) | |
6959 | { | |
6960 | struct _sas_device *sas_device, *sas_device_next; | |
6961 | struct _sas_node *sas_expander, *sas_expander_next; | |
6962 | struct _raid_device *raid_device, *raid_device_next; | |
6963 | struct list_head tmp_list; | |
6964 | unsigned long flags; | |
6965 | ||
6966 | pr_info(MPT3SAS_FMT "removing unresponding devices: start\n", | |
6967 | ioc->name); | |
6968 | ||
6969 | /* removing unresponding end devices */ | |
6970 | pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n", | |
6971 | ioc->name); | |
6972 | list_for_each_entry_safe(sas_device, sas_device_next, | |
6973 | &ioc->sas_device_list, list) { | |
6974 | if (!sas_device->responding) | |
6975 | mpt3sas_device_remove_by_sas_address(ioc, | |
6976 | sas_device->sas_address); | |
6977 | else | |
6978 | sas_device->responding = 0; | |
6979 | } | |
6980 | ||
6981 | /* removing unresponding volumes */ | |
6982 | if (ioc->ir_firmware) { | |
6983 | pr_info(MPT3SAS_FMT "removing unresponding devices: volumes\n", | |
6984 | ioc->name); | |
6985 | list_for_each_entry_safe(raid_device, raid_device_next, | |
6986 | &ioc->raid_device_list, list) { | |
6987 | if (!raid_device->responding) | |
6988 | _scsih_sas_volume_delete(ioc, | |
6989 | raid_device->handle); | |
6990 | else | |
6991 | raid_device->responding = 0; | |
6992 | } | |
6993 | } | |
6994 | ||
6995 | /* removing unresponding expanders */ | |
6996 | pr_info(MPT3SAS_FMT "removing unresponding devices: expanders\n", | |
6997 | ioc->name); | |
6998 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
6999 | INIT_LIST_HEAD(&tmp_list); | |
7000 | list_for_each_entry_safe(sas_expander, sas_expander_next, | |
7001 | &ioc->sas_expander_list, list) { | |
7002 | if (!sas_expander->responding) | |
7003 | list_move_tail(&sas_expander->list, &tmp_list); | |
7004 | else | |
7005 | sas_expander->responding = 0; | |
7006 | } | |
7007 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
7008 | list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list, | |
7009 | list) { | |
7010 | list_del(&sas_expander->list); | |
7011 | _scsih_expander_node_remove(ioc, sas_expander); | |
7012 | } | |
7013 | ||
7014 | pr_info(MPT3SAS_FMT "removing unresponding devices: complete\n", | |
7015 | ioc->name); | |
7016 | ||
7017 | /* unblock devices */ | |
7018 | _scsih_ublock_io_all_device(ioc); | |
7019 | } | |
7020 | ||
7021 | static void | |
7022 | _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc, | |
7023 | struct _sas_node *sas_expander, u16 handle) | |
7024 | { | |
7025 | Mpi2ExpanderPage1_t expander_pg1; | |
7026 | Mpi2ConfigReply_t mpi_reply; | |
7027 | int i; | |
7028 | ||
7029 | for (i = 0 ; i < sas_expander->num_phys ; i++) { | |
7030 | if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply, | |
7031 | &expander_pg1, i, handle))) { | |
7032 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
7033 | ioc->name, __FILE__, __LINE__, __func__); | |
7034 | return; | |
7035 | } | |
7036 | ||
7037 | mpt3sas_transport_update_links(ioc, sas_expander->sas_address, | |
7038 | le16_to_cpu(expander_pg1.AttachedDevHandle), i, | |
7039 | expander_pg1.NegotiatedLinkRate >> 4); | |
7040 | } | |
7041 | } | |
7042 | ||
7043 | /** | |
7044 | * _scsih_scan_for_devices_after_reset - scan for devices after host reset | |
7045 | * @ioc: per adapter object | |
7046 | * | |
7047 | * Return nothing. | |
7048 | */ | |
7049 | static void | |
7050 | _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc) | |
7051 | { | |
7052 | Mpi2ExpanderPage0_t expander_pg0; | |
7053 | Mpi2SasDevicePage0_t sas_device_pg0; | |
7054 | Mpi2RaidVolPage1_t volume_pg1; | |
7055 | Mpi2RaidVolPage0_t volume_pg0; | |
7056 | Mpi2RaidPhysDiskPage0_t pd_pg0; | |
7057 | Mpi2EventIrConfigElement_t element; | |
7058 | Mpi2ConfigReply_t mpi_reply; | |
7059 | u8 phys_disk_num; | |
7060 | u16 ioc_status; | |
7061 | u16 handle, parent_handle; | |
7062 | u64 sas_address; | |
7063 | struct _sas_device *sas_device; | |
7064 | struct _sas_node *expander_device; | |
7065 | static struct _raid_device *raid_device; | |
7066 | u8 retry_count; | |
7067 | unsigned long flags; | |
7068 | ||
7069 | pr_info(MPT3SAS_FMT "scan devices: start\n", ioc->name); | |
7070 | ||
7071 | _scsih_sas_host_refresh(ioc); | |
7072 | ||
7073 | pr_info(MPT3SAS_FMT "\tscan devices: expanders start\n", ioc->name); | |
7074 | ||
7075 | /* expanders */ | |
7076 | handle = 0xFFFF; | |
7077 | while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | |
7078 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { | |
7079 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
7080 | MPI2_IOCSTATUS_MASK; | |
f92363d1 SR |
7081 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
7082 | pr_info(MPT3SAS_FMT "\tbreak from expander scan: " \ | |
7083 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
7084 | ioc->name, ioc_status, | |
7085 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
7086 | break; | |
7087 | } | |
7088 | handle = le16_to_cpu(expander_pg0.DevHandle); | |
7089 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
7090 | expander_device = mpt3sas_scsih_expander_find_by_sas_address( | |
7091 | ioc, le64_to_cpu(expander_pg0.SASAddress)); | |
7092 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
7093 | if (expander_device) | |
7094 | _scsih_refresh_expander_links(ioc, expander_device, | |
7095 | handle); | |
7096 | else { | |
7097 | pr_info(MPT3SAS_FMT "\tBEFORE adding expander: " \ | |
7098 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
7099 | handle, (unsigned long long) | |
7100 | le64_to_cpu(expander_pg0.SASAddress)); | |
7101 | _scsih_expander_add(ioc, handle); | |
7102 | pr_info(MPT3SAS_FMT "\tAFTER adding expander: " \ | |
7103 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
7104 | handle, (unsigned long long) | |
7105 | le64_to_cpu(expander_pg0.SASAddress)); | |
7106 | } | |
7107 | } | |
7108 | ||
7109 | pr_info(MPT3SAS_FMT "\tscan devices: expanders complete\n", | |
7110 | ioc->name); | |
7111 | ||
7112 | if (!ioc->ir_firmware) | |
7113 | goto skip_to_sas; | |
7114 | ||
7115 | pr_info(MPT3SAS_FMT "\tscan devices: phys disk start\n", ioc->name); | |
7116 | ||
7117 | /* phys disk */ | |
7118 | phys_disk_num = 0xFF; | |
7119 | while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | |
7120 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, | |
7121 | phys_disk_num))) { | |
7122 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
7123 | MPI2_IOCSTATUS_MASK; | |
f92363d1 SR |
7124 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
7125 | pr_info(MPT3SAS_FMT "\tbreak from phys disk scan: "\ | |
7126 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
7127 | ioc->name, ioc_status, | |
7128 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
7129 | break; | |
7130 | } | |
7131 | phys_disk_num = pd_pg0.PhysDiskNum; | |
7132 | handle = le16_to_cpu(pd_pg0.DevHandle); | |
7133 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
7134 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); | |
7135 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
7136 | if (sas_device) | |
7137 | continue; | |
7138 | if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
7139 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | |
7140 | handle) != 0) | |
7141 | continue; | |
7142 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
7143 | MPI2_IOCSTATUS_MASK; | |
7144 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
7145 | pr_info(MPT3SAS_FMT "\tbreak from phys disk scan " \ | |
7146 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
7147 | ioc->name, ioc_status, | |
7148 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
7149 | break; | |
7150 | } | |
7151 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | |
7152 | if (!_scsih_get_sas_address(ioc, parent_handle, | |
7153 | &sas_address)) { | |
7154 | pr_info(MPT3SAS_FMT "\tBEFORE adding phys disk: " \ | |
7155 | " handle (0x%04x), sas_addr(0x%016llx)\n", | |
7156 | ioc->name, handle, (unsigned long long) | |
7157 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
7158 | mpt3sas_transport_update_links(ioc, sas_address, | |
7159 | handle, sas_device_pg0.PhyNum, | |
7160 | MPI2_SAS_NEG_LINK_RATE_1_5); | |
7161 | set_bit(handle, ioc->pd_handles); | |
7162 | retry_count = 0; | |
7163 | /* This will retry adding the end device. | |
7164 | * _scsih_add_device() will decide on retries and | |
7165 | * return "1" when it should be retried | |
7166 | */ | |
7167 | while (_scsih_add_device(ioc, handle, retry_count++, | |
7168 | 1)) { | |
7169 | ssleep(1); | |
7170 | } | |
7171 | pr_info(MPT3SAS_FMT "\tAFTER adding phys disk: " \ | |
7172 | " handle (0x%04x), sas_addr(0x%016llx)\n", | |
7173 | ioc->name, handle, (unsigned long long) | |
7174 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
7175 | } | |
7176 | } | |
7177 | ||
7178 | pr_info(MPT3SAS_FMT "\tscan devices: phys disk complete\n", | |
7179 | ioc->name); | |
7180 | ||
7181 | pr_info(MPT3SAS_FMT "\tscan devices: volumes start\n", ioc->name); | |
7182 | ||
7183 | /* volumes */ | |
7184 | handle = 0xFFFF; | |
7185 | while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply, | |
7186 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { | |
7187 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
7188 | MPI2_IOCSTATUS_MASK; | |
f92363d1 SR |
7189 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
7190 | pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \ | |
7191 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
7192 | ioc->name, ioc_status, | |
7193 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
7194 | break; | |
7195 | } | |
7196 | handle = le16_to_cpu(volume_pg1.DevHandle); | |
7197 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
7198 | raid_device = _scsih_raid_device_find_by_wwid(ioc, | |
7199 | le64_to_cpu(volume_pg1.WWID)); | |
7200 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
7201 | if (raid_device) | |
7202 | continue; | |
7203 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, | |
7204 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
7205 | sizeof(Mpi2RaidVolPage0_t))) | |
7206 | continue; | |
7207 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
7208 | MPI2_IOCSTATUS_MASK; | |
7209 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
7210 | pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \ | |
7211 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
7212 | ioc->name, ioc_status, | |
7213 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
7214 | break; | |
7215 | } | |
7216 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || | |
7217 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || | |
7218 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) { | |
7219 | memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t)); | |
7220 | element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED; | |
7221 | element.VolDevHandle = volume_pg1.DevHandle; | |
7222 | pr_info(MPT3SAS_FMT | |
7223 | "\tBEFORE adding volume: handle (0x%04x)\n", | |
7224 | ioc->name, volume_pg1.DevHandle); | |
7225 | _scsih_sas_volume_add(ioc, &element); | |
7226 | pr_info(MPT3SAS_FMT | |
7227 | "\tAFTER adding volume: handle (0x%04x)\n", | |
7228 | ioc->name, volume_pg1.DevHandle); | |
7229 | } | |
7230 | } | |
7231 | ||
7232 | pr_info(MPT3SAS_FMT "\tscan devices: volumes complete\n", | |
7233 | ioc->name); | |
7234 | ||
7235 | skip_to_sas: | |
7236 | ||
7237 | pr_info(MPT3SAS_FMT "\tscan devices: end devices start\n", | |
7238 | ioc->name); | |
7239 | ||
7240 | /* sas devices */ | |
7241 | handle = 0xFFFF; | |
7242 | while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
7243 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | |
7244 | handle))) { | |
7245 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
7246 | MPI2_IOCSTATUS_MASK; | |
f92363d1 SR |
7247 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
7248 | pr_info(MPT3SAS_FMT "\tbreak from end device scan:"\ | |
7249 | " ioc_status(0x%04x), loginfo(0x%08x)\n", | |
7250 | ioc->name, ioc_status, | |
7251 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
7252 | break; | |
7253 | } | |
7254 | handle = le16_to_cpu(sas_device_pg0.DevHandle); | |
7255 | if (!(_scsih_is_end_device( | |
7256 | le32_to_cpu(sas_device_pg0.DeviceInfo)))) | |
7257 | continue; | |
7258 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
7259 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, | |
7260 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
7261 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
7262 | if (sas_device) | |
7263 | continue; | |
7264 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | |
7265 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) { | |
7266 | pr_info(MPT3SAS_FMT "\tBEFORE adding end device: " \ | |
7267 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
7268 | handle, (unsigned long long) | |
7269 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
7270 | mpt3sas_transport_update_links(ioc, sas_address, handle, | |
7271 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | |
7272 | retry_count = 0; | |
7273 | /* This will retry adding the end device. | |
7274 | * _scsih_add_device() will decide on retries and | |
7275 | * return "1" when it should be retried | |
7276 | */ | |
7277 | while (_scsih_add_device(ioc, handle, retry_count++, | |
7278 | 0)) { | |
7279 | ssleep(1); | |
7280 | } | |
7281 | pr_info(MPT3SAS_FMT "\tAFTER adding end device: " \ | |
7282 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
7283 | handle, (unsigned long long) | |
7284 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
7285 | } | |
7286 | } | |
7287 | pr_info(MPT3SAS_FMT "\tscan devices: end devices complete\n", | |
7288 | ioc->name); | |
7289 | ||
7290 | pr_info(MPT3SAS_FMT "scan devices: complete\n", ioc->name); | |
7291 | } | |
7292 | /** | |
7293 | * mpt3sas_scsih_reset_handler - reset callback handler (for scsih) | |
7294 | * @ioc: per adapter object | |
7295 | * @reset_phase: phase | |
7296 | * | |
7297 | * The handler for doing any required cleanup or initialization. | |
7298 | * | |
7299 | * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET, | |
7300 | * MPT3_IOC_DONE_RESET | |
7301 | * | |
7302 | * Return nothing. | |
7303 | */ | |
7304 | void | |
7305 | mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase) | |
7306 | { | |
7307 | switch (reset_phase) { | |
7308 | case MPT3_IOC_PRE_RESET: | |
7309 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
7310 | "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__)); | |
7311 | break; | |
7312 | case MPT3_IOC_AFTER_RESET: | |
7313 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
7314 | "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__)); | |
7315 | if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) { | |
7316 | ioc->scsih_cmds.status |= MPT3_CMD_RESET; | |
7317 | mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid); | |
7318 | complete(&ioc->scsih_cmds.done); | |
7319 | } | |
7320 | if (ioc->tm_cmds.status & MPT3_CMD_PENDING) { | |
7321 | ioc->tm_cmds.status |= MPT3_CMD_RESET; | |
7322 | mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid); | |
7323 | complete(&ioc->tm_cmds.done); | |
7324 | } | |
7325 | ||
7326 | _scsih_fw_event_cleanup_queue(ioc); | |
7327 | _scsih_flush_running_cmds(ioc); | |
7328 | break; | |
7329 | case MPT3_IOC_DONE_RESET: | |
7330 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
7331 | "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__)); | |
7332 | if ((!ioc->is_driver_loading) && !(disable_discovery > 0 && | |
7333 | !ioc->sas_hba.num_phys)) { | |
7334 | _scsih_prep_device_scan(ioc); | |
7335 | _scsih_search_responding_sas_devices(ioc); | |
7336 | _scsih_search_responding_raid_devices(ioc); | |
7337 | _scsih_search_responding_expanders(ioc); | |
7338 | _scsih_error_recovery_delete_devices(ioc); | |
7339 | } | |
7340 | break; | |
7341 | } | |
7342 | } | |
7343 | ||
7344 | /** | |
7345 | * _mpt3sas_fw_work - delayed task for processing firmware events | |
7346 | * @ioc: per adapter object | |
7347 | * @fw_event: The fw_event_work object | |
7348 | * Context: user. | |
7349 | * | |
7350 | * Return nothing. | |
7351 | */ | |
7352 | static void | |
7353 | _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event) | |
7354 | { | |
7355 | /* the queue is being flushed so ignore this event */ | |
4dc06fd8 | 7356 | if (ioc->remove_host || |
f92363d1 SR |
7357 | ioc->pci_error_recovery) { |
7358 | _scsih_fw_event_free(ioc, fw_event); | |
7359 | return; | |
7360 | } | |
7361 | ||
7362 | switch (fw_event->event) { | |
7363 | case MPT3SAS_PROCESS_TRIGGER_DIAG: | |
35b62362 JL |
7364 | mpt3sas_process_trigger_data(ioc, |
7365 | (struct SL_WH_TRIGGERS_EVENT_DATA_T *) | |
7366 | fw_event->event_data); | |
f92363d1 SR |
7367 | break; |
7368 | case MPT3SAS_REMOVE_UNRESPONDING_DEVICES: | |
7369 | while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery) | |
7370 | ssleep(1); | |
7371 | _scsih_remove_unresponding_sas_devices(ioc); | |
7372 | _scsih_scan_for_devices_after_reset(ioc); | |
7373 | break; | |
7374 | case MPT3SAS_PORT_ENABLE_COMPLETE: | |
7375 | ioc->start_scan = 0; | |
7376 | if (missing_delay[0] != -1 && missing_delay[1] != -1) | |
7377 | mpt3sas_base_update_missing_delay(ioc, missing_delay[0], | |
7378 | missing_delay[1]); | |
7379 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7380 | "port enable: complete from worker thread\n", | |
7381 | ioc->name)); | |
7382 | break; | |
0f624c39 SR |
7383 | case MPT3SAS_TURN_ON_PFA_LED: |
7384 | _scsih_turn_on_pfa_led(ioc, fw_event->device_handle); | |
f92363d1 SR |
7385 | break; |
7386 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: | |
7387 | _scsih_sas_topology_change_event(ioc, fw_event); | |
7388 | break; | |
7389 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: | |
7390 | _scsih_sas_device_status_change_event(ioc, fw_event); | |
7391 | break; | |
7392 | case MPI2_EVENT_SAS_DISCOVERY: | |
7393 | _scsih_sas_discovery_event(ioc, fw_event); | |
7394 | break; | |
7395 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: | |
7396 | _scsih_sas_broadcast_primitive_event(ioc, fw_event); | |
7397 | break; | |
7398 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: | |
7399 | _scsih_sas_enclosure_dev_status_change_event(ioc, | |
7400 | fw_event); | |
7401 | break; | |
7402 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: | |
7403 | _scsih_sas_ir_config_change_event(ioc, fw_event); | |
7404 | break; | |
7405 | case MPI2_EVENT_IR_VOLUME: | |
7406 | _scsih_sas_ir_volume_event(ioc, fw_event); | |
7407 | break; | |
7408 | case MPI2_EVENT_IR_PHYSICAL_DISK: | |
7409 | _scsih_sas_ir_physical_disk_event(ioc, fw_event); | |
7410 | break; | |
7411 | case MPI2_EVENT_IR_OPERATION_STATUS: | |
7412 | _scsih_sas_ir_operation_status_event(ioc, fw_event); | |
7413 | break; | |
7414 | } | |
7415 | _scsih_fw_event_free(ioc, fw_event); | |
7416 | } | |
7417 | ||
7418 | /** | |
7419 | * _firmware_event_work | |
7420 | * @ioc: per adapter object | |
7421 | * @work: The fw_event_work object | |
7422 | * Context: user. | |
7423 | * | |
7424 | * wrappers for the work thread handling firmware events | |
7425 | * | |
7426 | * Return nothing. | |
7427 | */ | |
7428 | ||
7429 | static void | |
7430 | _firmware_event_work(struct work_struct *work) | |
7431 | { | |
7432 | struct fw_event_work *fw_event = container_of(work, | |
7433 | struct fw_event_work, work); | |
7434 | ||
7435 | _mpt3sas_fw_work(fw_event->ioc, fw_event); | |
7436 | } | |
7437 | ||
7438 | /** | |
7439 | * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time) | |
7440 | * @ioc: per adapter object | |
7441 | * @msix_index: MSIX table index supplied by the OS | |
7442 | * @reply: reply message frame(lower 32bit addr) | |
7443 | * Context: interrupt. | |
7444 | * | |
7445 | * This function merely adds a new work task into ioc->firmware_event_thread. | |
7446 | * The tasks are worked from _firmware_event_work in user context. | |
7447 | * | |
7448 | * Return 1 meaning mf should be freed from _base_interrupt | |
7449 | * 0 means the mf is freed from this function. | |
7450 | */ | |
7451 | u8 | |
7452 | mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index, | |
7453 | u32 reply) | |
7454 | { | |
7455 | struct fw_event_work *fw_event; | |
7456 | Mpi2EventNotificationReply_t *mpi_reply; | |
7457 | u16 event; | |
7458 | u16 sz; | |
7459 | ||
7460 | /* events turned off due to host reset or driver unloading */ | |
7461 | if (ioc->remove_host || ioc->pci_error_recovery) | |
7462 | return 1; | |
7463 | ||
7464 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
7465 | ||
7466 | if (unlikely(!mpi_reply)) { | |
7467 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", | |
7468 | ioc->name, __FILE__, __LINE__, __func__); | |
7469 | return 1; | |
7470 | } | |
7471 | ||
7472 | event = le16_to_cpu(mpi_reply->Event); | |
7473 | ||
7474 | if (event != MPI2_EVENT_LOG_ENTRY_ADDED) | |
7475 | mpt3sas_trigger_event(ioc, event, 0); | |
7476 | ||
7477 | switch (event) { | |
7478 | /* handle these */ | |
7479 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: | |
7480 | { | |
7481 | Mpi2EventDataSasBroadcastPrimitive_t *baen_data = | |
7482 | (Mpi2EventDataSasBroadcastPrimitive_t *) | |
7483 | mpi_reply->EventData; | |
7484 | ||
7485 | if (baen_data->Primitive != | |
7486 | MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT) | |
7487 | return 1; | |
7488 | ||
7489 | if (ioc->broadcast_aen_busy) { | |
7490 | ioc->broadcast_aen_pending++; | |
7491 | return 1; | |
7492 | } else | |
7493 | ioc->broadcast_aen_busy = 1; | |
7494 | break; | |
7495 | } | |
7496 | ||
7497 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: | |
7498 | _scsih_check_topo_delete_events(ioc, | |
7499 | (Mpi2EventDataSasTopologyChangeList_t *) | |
7500 | mpi_reply->EventData); | |
7501 | break; | |
7502 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: | |
7503 | _scsih_check_ir_config_unhide_events(ioc, | |
7504 | (Mpi2EventDataIrConfigChangeList_t *) | |
7505 | mpi_reply->EventData); | |
7506 | break; | |
7507 | case MPI2_EVENT_IR_VOLUME: | |
7508 | _scsih_check_volume_delete_events(ioc, | |
7509 | (Mpi2EventDataIrVolume_t *) | |
7510 | mpi_reply->EventData); | |
7511 | break; | |
7786ab6a SR |
7512 | case MPI2_EVENT_LOG_ENTRY_ADDED: |
7513 | { | |
7514 | Mpi2EventDataLogEntryAdded_t *log_entry; | |
7515 | u32 *log_code; | |
7516 | ||
7517 | if (!ioc->is_warpdrive) | |
7518 | break; | |
7519 | ||
7520 | log_entry = (Mpi2EventDataLogEntryAdded_t *) | |
7521 | mpi_reply->EventData; | |
7522 | log_code = (u32 *)log_entry->LogData; | |
f92363d1 | 7523 | |
7786ab6a SR |
7524 | if (le16_to_cpu(log_entry->LogEntryQualifier) |
7525 | != MPT2_WARPDRIVE_LOGENTRY) | |
7526 | break; | |
7527 | ||
7528 | switch (le32_to_cpu(*log_code)) { | |
7529 | case MPT2_WARPDRIVE_LC_SSDT: | |
7530 | pr_warn(MPT3SAS_FMT "WarpDrive Warning: " | |
7531 | "IO Throttling has occurred in the WarpDrive " | |
7532 | "subsystem. Check WarpDrive documentation for " | |
7533 | "additional details.\n", ioc->name); | |
7534 | break; | |
7535 | case MPT2_WARPDRIVE_LC_SSDLW: | |
7536 | pr_warn(MPT3SAS_FMT "WarpDrive Warning: " | |
7537 | "Program/Erase Cycles for the WarpDrive subsystem " | |
7538 | "in degraded range. Check WarpDrive documentation " | |
7539 | "for additional details.\n", ioc->name); | |
7540 | break; | |
7541 | case MPT2_WARPDRIVE_LC_SSDLF: | |
7542 | pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: " | |
7543 | "There are no Program/Erase Cycles for the " | |
7544 | "WarpDrive subsystem. The storage device will be " | |
7545 | "in read-only mode. Check WarpDrive documentation " | |
7546 | "for additional details.\n", ioc->name); | |
7547 | break; | |
7548 | case MPT2_WARPDRIVE_LC_BRMF: | |
7549 | pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: " | |
7550 | "The Backup Rail Monitor has failed on the " | |
7551 | "WarpDrive subsystem. Check WarpDrive " | |
7552 | "documentation for additional details.\n", | |
7553 | ioc->name); | |
7554 | break; | |
7555 | } | |
7556 | ||
7557 | break; | |
7558 | } | |
f92363d1 SR |
7559 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: |
7560 | case MPI2_EVENT_IR_OPERATION_STATUS: | |
7561 | case MPI2_EVENT_SAS_DISCOVERY: | |
7562 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: | |
7563 | case MPI2_EVENT_IR_PHYSICAL_DISK: | |
7564 | break; | |
7565 | ||
2d8ce8c9 SR |
7566 | case MPI2_EVENT_TEMP_THRESHOLD: |
7567 | _scsih_temp_threshold_events(ioc, | |
7568 | (Mpi2EventDataTemperature_t *) | |
7569 | mpi_reply->EventData); | |
7570 | break; | |
7571 | ||
f92363d1 SR |
7572 | default: /* ignore the rest */ |
7573 | return 1; | |
7574 | } | |
7575 | ||
f92363d1 | 7576 | sz = le16_to_cpu(mpi_reply->EventDataLength) * 4; |
35b62362 JL |
7577 | fw_event = kzalloc(sizeof(*fw_event) + sz, GFP_ATOMIC); |
7578 | if (!fw_event) { | |
f92363d1 SR |
7579 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
7580 | ioc->name, __FILE__, __LINE__, __func__); | |
f92363d1 SR |
7581 | return 1; |
7582 | } | |
7583 | ||
7584 | memcpy(fw_event->event_data, mpi_reply->EventData, sz); | |
7585 | fw_event->ioc = ioc; | |
7586 | fw_event->VF_ID = mpi_reply->VF_ID; | |
7587 | fw_event->VP_ID = mpi_reply->VP_ID; | |
7588 | fw_event->event = event; | |
7589 | _scsih_fw_event_add(ioc, fw_event); | |
7590 | return 1; | |
7591 | } | |
7592 | ||
f92363d1 SR |
7593 | /** |
7594 | * _scsih_expander_node_remove - removing expander device from list. | |
7595 | * @ioc: per adapter object | |
7596 | * @sas_expander: the sas_device object | |
7597 | * Context: Calling function should acquire ioc->sas_node_lock. | |
7598 | * | |
7599 | * Removing object and freeing associated memory from the | |
7600 | * ioc->sas_expander_list. | |
7601 | * | |
7602 | * Return nothing. | |
7603 | */ | |
7604 | static void | |
7605 | _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc, | |
7606 | struct _sas_node *sas_expander) | |
7607 | { | |
7608 | struct _sas_port *mpt3sas_port, *next; | |
7609 | ||
7610 | /* remove sibling ports attached to this expander */ | |
7611 | list_for_each_entry_safe(mpt3sas_port, next, | |
7612 | &sas_expander->sas_port_list, port_list) { | |
7613 | if (ioc->shost_recovery) | |
7614 | return; | |
7615 | if (mpt3sas_port->remote_identify.device_type == | |
7616 | SAS_END_DEVICE) | |
7617 | mpt3sas_device_remove_by_sas_address(ioc, | |
7618 | mpt3sas_port->remote_identify.sas_address); | |
7619 | else if (mpt3sas_port->remote_identify.device_type == | |
7620 | SAS_EDGE_EXPANDER_DEVICE || | |
7621 | mpt3sas_port->remote_identify.device_type == | |
7622 | SAS_FANOUT_EXPANDER_DEVICE) | |
7623 | mpt3sas_expander_remove(ioc, | |
7624 | mpt3sas_port->remote_identify.sas_address); | |
7625 | } | |
7626 | ||
7627 | mpt3sas_transport_port_remove(ioc, sas_expander->sas_address, | |
7628 | sas_expander->sas_address_parent); | |
7629 | ||
7630 | pr_info(MPT3SAS_FMT | |
7631 | "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n", | |
7632 | ioc->name, | |
7633 | sas_expander->handle, (unsigned long long) | |
7634 | sas_expander->sas_address); | |
7635 | ||
7636 | kfree(sas_expander->phy); | |
7637 | kfree(sas_expander); | |
7638 | } | |
7639 | ||
7640 | /** | |
7641 | * _scsih_ir_shutdown - IR shutdown notification | |
7642 | * @ioc: per adapter object | |
7643 | * | |
7644 | * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that | |
7645 | * the host system is shutting down. | |
7646 | * | |
7647 | * Return nothing. | |
7648 | */ | |
7649 | static void | |
7650 | _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc) | |
7651 | { | |
7652 | Mpi2RaidActionRequest_t *mpi_request; | |
7653 | Mpi2RaidActionReply_t *mpi_reply; | |
7654 | u16 smid; | |
7655 | ||
7656 | /* is IR firmware build loaded ? */ | |
7657 | if (!ioc->ir_firmware) | |
7658 | return; | |
7659 | ||
7660 | /* are there any volumes ? */ | |
7661 | if (list_empty(&ioc->raid_device_list)) | |
7662 | return; | |
7663 | ||
7664 | mutex_lock(&ioc->scsih_cmds.mutex); | |
7665 | ||
7666 | if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) { | |
7667 | pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n", | |
7668 | ioc->name, __func__); | |
7669 | goto out; | |
7670 | } | |
7671 | ioc->scsih_cmds.status = MPT3_CMD_PENDING; | |
7672 | ||
7673 | smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx); | |
7674 | if (!smid) { | |
7675 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
7676 | ioc->name, __func__); | |
7677 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
7678 | goto out; | |
7679 | } | |
7680 | ||
7681 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
7682 | ioc->scsih_cmds.smid = smid; | |
7683 | memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t)); | |
7684 | ||
7685 | mpi_request->Function = MPI2_FUNCTION_RAID_ACTION; | |
7686 | mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED; | |
7687 | ||
7786ab6a SR |
7688 | if (!ioc->hide_ir_msg) |
7689 | pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name); | |
f92363d1 SR |
7690 | init_completion(&ioc->scsih_cmds.done); |
7691 | mpt3sas_base_put_smid_default(ioc, smid); | |
7692 | wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ); | |
7693 | ||
7694 | if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) { | |
7695 | pr_err(MPT3SAS_FMT "%s: timeout\n", | |
7696 | ioc->name, __func__); | |
7697 | goto out; | |
7698 | } | |
7699 | ||
7700 | if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) { | |
7701 | mpi_reply = ioc->scsih_cmds.reply; | |
7786ab6a SR |
7702 | if (!ioc->hide_ir_msg) |
7703 | pr_info(MPT3SAS_FMT "IR shutdown " | |
7704 | "(complete): ioc_status(0x%04x), loginfo(0x%08x)\n", | |
7705 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), | |
7706 | le32_to_cpu(mpi_reply->IOCLogInfo)); | |
f92363d1 SR |
7707 | } |
7708 | ||
7709 | out: | |
7710 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
7711 | mutex_unlock(&ioc->scsih_cmds.mutex); | |
7712 | } | |
7713 | ||
7714 | /** | |
8a7e4c24 | 7715 | * scsih_remove - detach and remove add host |
f92363d1 SR |
7716 | * @pdev: PCI device struct |
7717 | * | |
7718 | * Routine called when unloading the driver. | |
7719 | * Return nothing. | |
7720 | */ | |
8a7e4c24 | 7721 | void scsih_remove(struct pci_dev *pdev) |
f92363d1 SR |
7722 | { |
7723 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
7724 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
7725 | struct _sas_port *mpt3sas_port, *next_port; | |
7726 | struct _raid_device *raid_device, *next; | |
7727 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
7728 | struct workqueue_struct *wq; | |
7729 | unsigned long flags; | |
7730 | ||
7731 | ioc->remove_host = 1; | |
7732 | _scsih_fw_event_cleanup_queue(ioc); | |
7733 | ||
7734 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
7735 | wq = ioc->firmware_event_thread; | |
7736 | ioc->firmware_event_thread = NULL; | |
7737 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
7738 | if (wq) | |
7739 | destroy_workqueue(wq); | |
7740 | ||
7741 | /* release all the volumes */ | |
7742 | _scsih_ir_shutdown(ioc); | |
7743 | list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list, | |
7744 | list) { | |
7745 | if (raid_device->starget) { | |
7746 | sas_target_priv_data = | |
7747 | raid_device->starget->hostdata; | |
7748 | sas_target_priv_data->deleted = 1; | |
7749 | scsi_remove_target(&raid_device->starget->dev); | |
7750 | } | |
7751 | pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n", | |
7752 | ioc->name, raid_device->handle, | |
7753 | (unsigned long long) raid_device->wwid); | |
7754 | _scsih_raid_device_remove(ioc, raid_device); | |
7755 | } | |
7756 | ||
7757 | /* free ports attached to the sas_host */ | |
7758 | list_for_each_entry_safe(mpt3sas_port, next_port, | |
7759 | &ioc->sas_hba.sas_port_list, port_list) { | |
7760 | if (mpt3sas_port->remote_identify.device_type == | |
7761 | SAS_END_DEVICE) | |
7762 | mpt3sas_device_remove_by_sas_address(ioc, | |
7763 | mpt3sas_port->remote_identify.sas_address); | |
7764 | else if (mpt3sas_port->remote_identify.device_type == | |
7765 | SAS_EDGE_EXPANDER_DEVICE || | |
7766 | mpt3sas_port->remote_identify.device_type == | |
7767 | SAS_FANOUT_EXPANDER_DEVICE) | |
7768 | mpt3sas_expander_remove(ioc, | |
7769 | mpt3sas_port->remote_identify.sas_address); | |
7770 | } | |
7771 | ||
7772 | /* free phys attached to the sas_host */ | |
7773 | if (ioc->sas_hba.num_phys) { | |
7774 | kfree(ioc->sas_hba.phy); | |
7775 | ioc->sas_hba.phy = NULL; | |
7776 | ioc->sas_hba.num_phys = 0; | |
7777 | } | |
7778 | ||
7779 | sas_remove_host(shost); | |
4dc06fd8 | 7780 | scsi_remove_host(shost); |
f92363d1 SR |
7781 | mpt3sas_base_detach(ioc); |
7782 | list_del(&ioc->list); | |
f92363d1 SR |
7783 | scsi_host_put(shost); |
7784 | } | |
7785 | ||
7786 | /** | |
8a7e4c24 | 7787 | * scsih_shutdown - routine call during system shutdown |
f92363d1 SR |
7788 | * @pdev: PCI device struct |
7789 | * | |
7790 | * Return nothing. | |
7791 | */ | |
8a7e4c24 SR |
7792 | void |
7793 | scsih_shutdown(struct pci_dev *pdev) | |
f92363d1 SR |
7794 | { |
7795 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
7796 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
7797 | struct workqueue_struct *wq; | |
7798 | unsigned long flags; | |
7799 | ||
7800 | ioc->remove_host = 1; | |
7801 | _scsih_fw_event_cleanup_queue(ioc); | |
7802 | ||
7803 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
7804 | wq = ioc->firmware_event_thread; | |
7805 | ioc->firmware_event_thread = NULL; | |
7806 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
7807 | if (wq) | |
7808 | destroy_workqueue(wq); | |
7809 | ||
7810 | _scsih_ir_shutdown(ioc); | |
7811 | mpt3sas_base_detach(ioc); | |
7812 | } | |
7813 | ||
7814 | ||
7815 | /** | |
7816 | * _scsih_probe_boot_devices - reports 1st device | |
7817 | * @ioc: per adapter object | |
7818 | * | |
7819 | * If specified in bios page 2, this routine reports the 1st | |
7820 | * device scsi-ml or sas transport for persistent boot device | |
7821 | * purposes. Please refer to function _scsih_determine_boot_device() | |
7822 | */ | |
7823 | static void | |
7824 | _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc) | |
7825 | { | |
7826 | u8 is_raid; | |
7827 | void *device; | |
7828 | struct _sas_device *sas_device; | |
7829 | struct _raid_device *raid_device; | |
7830 | u16 handle; | |
7831 | u64 sas_address_parent; | |
7832 | u64 sas_address; | |
7833 | unsigned long flags; | |
7834 | int rc; | |
7835 | ||
7836 | /* no Bios, return immediately */ | |
7837 | if (!ioc->bios_pg3.BiosVersion) | |
7838 | return; | |
7839 | ||
7840 | device = NULL; | |
7841 | is_raid = 0; | |
7842 | if (ioc->req_boot_device.device) { | |
7843 | device = ioc->req_boot_device.device; | |
7844 | is_raid = ioc->req_boot_device.is_raid; | |
7845 | } else if (ioc->req_alt_boot_device.device) { | |
7846 | device = ioc->req_alt_boot_device.device; | |
7847 | is_raid = ioc->req_alt_boot_device.is_raid; | |
7848 | } else if (ioc->current_boot_device.device) { | |
7849 | device = ioc->current_boot_device.device; | |
7850 | is_raid = ioc->current_boot_device.is_raid; | |
7851 | } | |
7852 | ||
7853 | if (!device) | |
7854 | return; | |
7855 | ||
7856 | if (is_raid) { | |
7857 | raid_device = device; | |
7858 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
7859 | raid_device->id, 0); | |
7860 | if (rc) | |
7861 | _scsih_raid_device_remove(ioc, raid_device); | |
7862 | } else { | |
7863 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
7864 | sas_device = device; | |
7865 | handle = sas_device->handle; | |
7866 | sas_address_parent = sas_device->sas_address_parent; | |
7867 | sas_address = sas_device->sas_address; | |
7868 | list_move_tail(&sas_device->list, &ioc->sas_device_list); | |
7869 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
7870 | ||
7786ab6a SR |
7871 | if (ioc->hide_drives) |
7872 | return; | |
f92363d1 SR |
7873 | if (!mpt3sas_transport_port_add(ioc, handle, |
7874 | sas_address_parent)) { | |
7875 | _scsih_sas_device_remove(ioc, sas_device); | |
7876 | } else if (!sas_device->starget) { | |
f5edbe77 SR |
7877 | if (!ioc->is_driver_loading) { |
7878 | mpt3sas_transport_port_remove(ioc, | |
7879 | sas_address, | |
f92363d1 | 7880 | sas_address_parent); |
f5edbe77 SR |
7881 | _scsih_sas_device_remove(ioc, sas_device); |
7882 | } | |
f92363d1 SR |
7883 | } |
7884 | } | |
7885 | } | |
7886 | ||
7887 | /** | |
7888 | * _scsih_probe_raid - reporting raid volumes to scsi-ml | |
7889 | * @ioc: per adapter object | |
7890 | * | |
7891 | * Called during initial loading of the driver. | |
7892 | */ | |
7893 | static void | |
7894 | _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc) | |
7895 | { | |
7896 | struct _raid_device *raid_device, *raid_next; | |
7897 | int rc; | |
7898 | ||
7899 | list_for_each_entry_safe(raid_device, raid_next, | |
7900 | &ioc->raid_device_list, list) { | |
7901 | if (raid_device->starget) | |
7902 | continue; | |
7903 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
7904 | raid_device->id, 0); | |
7905 | if (rc) | |
7906 | _scsih_raid_device_remove(ioc, raid_device); | |
7907 | } | |
7908 | } | |
7909 | ||
7910 | /** | |
7911 | * _scsih_probe_sas - reporting sas devices to sas transport | |
7912 | * @ioc: per adapter object | |
7913 | * | |
7914 | * Called during initial loading of the driver. | |
7915 | */ | |
7916 | static void | |
7917 | _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc) | |
7918 | { | |
7919 | struct _sas_device *sas_device, *next; | |
7920 | unsigned long flags; | |
7921 | ||
7922 | /* SAS Device List */ | |
7923 | list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list, | |
7924 | list) { | |
7925 | ||
7786ab6a SR |
7926 | if (ioc->hide_drives) |
7927 | return; | |
7928 | ||
f92363d1 SR |
7929 | if (!mpt3sas_transport_port_add(ioc, sas_device->handle, |
7930 | sas_device->sas_address_parent)) { | |
7931 | list_del(&sas_device->list); | |
7932 | kfree(sas_device); | |
7933 | continue; | |
7934 | } else if (!sas_device->starget) { | |
7935 | /* | |
7936 | * When asyn scanning is enabled, its not possible to | |
7937 | * remove devices while scanning is turned on due to an | |
7938 | * oops in scsi_sysfs_add_sdev()->add_device()-> | |
7939 | * sysfs_addrm_start() | |
7940 | */ | |
f5edbe77 | 7941 | if (!ioc->is_driver_loading) { |
f92363d1 SR |
7942 | mpt3sas_transport_port_remove(ioc, |
7943 | sas_device->sas_address, | |
7944 | sas_device->sas_address_parent); | |
f5edbe77 SR |
7945 | list_del(&sas_device->list); |
7946 | kfree(sas_device); | |
7947 | continue; | |
7948 | } | |
f92363d1 SR |
7949 | } |
7950 | ||
7951 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
7952 | list_move_tail(&sas_device->list, &ioc->sas_device_list); | |
7953 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
7954 | } | |
7955 | } | |
7956 | ||
7957 | /** | |
7958 | * _scsih_probe_devices - probing for devices | |
7959 | * @ioc: per adapter object | |
7960 | * | |
7961 | * Called during initial loading of the driver. | |
7962 | */ | |
7963 | static void | |
7964 | _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc) | |
7965 | { | |
7966 | u16 volume_mapping_flags; | |
7967 | ||
7968 | if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR)) | |
7969 | return; /* return when IOC doesn't support initiator mode */ | |
7970 | ||
7971 | _scsih_probe_boot_devices(ioc); | |
7972 | ||
7973 | if (ioc->ir_firmware) { | |
7974 | volume_mapping_flags = | |
7975 | le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) & | |
7976 | MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE; | |
7977 | if (volume_mapping_flags == | |
7978 | MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) { | |
7979 | _scsih_probe_raid(ioc); | |
7980 | _scsih_probe_sas(ioc); | |
7981 | } else { | |
7982 | _scsih_probe_sas(ioc); | |
7983 | _scsih_probe_raid(ioc); | |
7984 | } | |
7985 | } else | |
7986 | _scsih_probe_sas(ioc); | |
7987 | } | |
7988 | ||
7989 | /** | |
8a7e4c24 | 7990 | * scsih_scan_start - scsi lld callback for .scan_start |
f92363d1 SR |
7991 | * @shost: SCSI host pointer |
7992 | * | |
7993 | * The shost has the ability to discover targets on its own instead | |
7994 | * of scanning the entire bus. In our implemention, we will kick off | |
7995 | * firmware discovery. | |
7996 | */ | |
8a7e4c24 SR |
7997 | void |
7998 | scsih_scan_start(struct Scsi_Host *shost) | |
f92363d1 SR |
7999 | { |
8000 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
8001 | int rc; | |
8002 | if (diag_buffer_enable != -1 && diag_buffer_enable != 0) | |
8003 | mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable); | |
8004 | ||
8005 | if (disable_discovery > 0) | |
8006 | return; | |
8007 | ||
8008 | ioc->start_scan = 1; | |
8009 | rc = mpt3sas_port_enable(ioc); | |
8010 | ||
8011 | if (rc != 0) | |
8012 | pr_info(MPT3SAS_FMT "port enable: FAILED\n", ioc->name); | |
8013 | } | |
8014 | ||
8015 | /** | |
8a7e4c24 | 8016 | * scsih_scan_finished - scsi lld callback for .scan_finished |
f92363d1 SR |
8017 | * @shost: SCSI host pointer |
8018 | * @time: elapsed time of the scan in jiffies | |
8019 | * | |
8020 | * This function will be called periodicallyn until it returns 1 with the | |
8021 | * scsi_host and the elapsed time of the scan in jiffies. In our implemention, | |
8022 | * we wait for firmware discovery to complete, then return 1. | |
8023 | */ | |
8a7e4c24 SR |
8024 | int |
8025 | scsih_scan_finished(struct Scsi_Host *shost, unsigned long time) | |
f92363d1 SR |
8026 | { |
8027 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
8028 | ||
8029 | if (disable_discovery > 0) { | |
8030 | ioc->is_driver_loading = 0; | |
8031 | ioc->wait_for_discovery_to_complete = 0; | |
8032 | return 1; | |
8033 | } | |
8034 | ||
8035 | if (time >= (300 * HZ)) { | |
8036 | ioc->base_cmds.status = MPT3_CMD_NOT_USED; | |
8037 | pr_info(MPT3SAS_FMT | |
8038 | "port enable: FAILED with timeout (timeout=300s)\n", | |
8039 | ioc->name); | |
8040 | ioc->is_driver_loading = 0; | |
8041 | return 1; | |
8042 | } | |
8043 | ||
8044 | if (ioc->start_scan) | |
8045 | return 0; | |
8046 | ||
8047 | if (ioc->start_scan_failed) { | |
8048 | pr_info(MPT3SAS_FMT | |
8049 | "port enable: FAILED with (ioc_status=0x%08x)\n", | |
8050 | ioc->name, ioc->start_scan_failed); | |
8051 | ioc->is_driver_loading = 0; | |
8052 | ioc->wait_for_discovery_to_complete = 0; | |
8053 | ioc->remove_host = 1; | |
8054 | return 1; | |
8055 | } | |
8056 | ||
8057 | pr_info(MPT3SAS_FMT "port enable: SUCCESS\n", ioc->name); | |
8058 | ioc->base_cmds.status = MPT3_CMD_NOT_USED; | |
8059 | ||
8060 | if (ioc->wait_for_discovery_to_complete) { | |
8061 | ioc->wait_for_discovery_to_complete = 0; | |
8062 | _scsih_probe_devices(ioc); | |
8063 | } | |
8064 | mpt3sas_base_start_watchdog(ioc); | |
8065 | ioc->is_driver_loading = 0; | |
8066 | return 1; | |
8067 | } | |
8068 | ||
d357e84d SR |
8069 | void |
8070 | _scsih_determine_hba_mpi_version(struct MPT3SAS_ADAPTER *ioc) { | |
8071 | ||
8072 | switch (ioc->pdev->device) { | |
7786ab6a SR |
8073 | case MPI2_MFGPAGE_DEVID_SSS6200: |
8074 | ioc->is_warpdrive = 1; | |
8075 | ioc->hide_ir_msg = 1; | |
d357e84d SR |
8076 | case MPI2_MFGPAGE_DEVID_SAS2004: |
8077 | case MPI2_MFGPAGE_DEVID_SAS2008: | |
8078 | case MPI2_MFGPAGE_DEVID_SAS2108_1: | |
8079 | case MPI2_MFGPAGE_DEVID_SAS2108_2: | |
8080 | case MPI2_MFGPAGE_DEVID_SAS2108_3: | |
8081 | case MPI2_MFGPAGE_DEVID_SAS2116_1: | |
8082 | case MPI2_MFGPAGE_DEVID_SAS2116_2: | |
8083 | case MPI2_MFGPAGE_DEVID_SAS2208_1: | |
8084 | case MPI2_MFGPAGE_DEVID_SAS2208_2: | |
8085 | case MPI2_MFGPAGE_DEVID_SAS2208_3: | |
8086 | case MPI2_MFGPAGE_DEVID_SAS2208_4: | |
8087 | case MPI2_MFGPAGE_DEVID_SAS2208_5: | |
8088 | case MPI2_MFGPAGE_DEVID_SAS2208_6: | |
8089 | case MPI2_MFGPAGE_DEVID_SAS2308_1: | |
8090 | case MPI2_MFGPAGE_DEVID_SAS2308_2: | |
8091 | case MPI2_MFGPAGE_DEVID_SAS2308_3: | |
8092 | ioc->hba_mpi_version_belonged = MPI2_VERSION; | |
8093 | break; | |
8094 | case MPI25_MFGPAGE_DEVID_SAS3004: | |
8095 | case MPI25_MFGPAGE_DEVID_SAS3008: | |
8096 | case MPI25_MFGPAGE_DEVID_SAS3108_1: | |
8097 | case MPI25_MFGPAGE_DEVID_SAS3108_2: | |
8098 | case MPI25_MFGPAGE_DEVID_SAS3108_5: | |
8099 | case MPI25_MFGPAGE_DEVID_SAS3108_6: | |
8100 | ioc->hba_mpi_version_belonged = MPI25_VERSION; | |
42081173 SR |
8101 | |
8102 | /* Check whether the controller revision is C0 or above. | |
8103 | * only C0 and above revision controllers support 96 MSI-X | |
8104 | * vectors. | |
8105 | */ | |
8106 | if (ioc->pdev->revision >= SAS3_PCI_DEVICE_C0_REVISION) | |
8107 | ioc->msix96_vector = 1; | |
d357e84d SR |
8108 | break; |
8109 | } | |
7786ab6a SR |
8110 | |
8111 | if ((ioc->pdev->device != MPI2_MFGPAGE_DEVID_SSS6200) && | |
8112 | (ioc->hba_mpi_version_belonged == MPI2_VERSION)) | |
8113 | ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS; | |
d357e84d SR |
8114 | } |
8115 | ||
f92363d1 | 8116 | /** |
8a7e4c24 | 8117 | * scsih_probe - attach and add scsi host |
f92363d1 SR |
8118 | * @pdev: PCI device struct |
8119 | * @id: pci device id | |
8120 | * | |
8121 | * Returns 0 success, anything else error. | |
8122 | */ | |
8a7e4c24 | 8123 | int |
7497392a | 8124 | scsih_probe(struct pci_dev *pdev, struct Scsi_Host *shost) |
f92363d1 SR |
8125 | { |
8126 | struct MPT3SAS_ADAPTER *ioc; | |
b65f1d4d | 8127 | int rv; |
f92363d1 | 8128 | |
f92363d1 SR |
8129 | /* init local params */ |
8130 | ioc = shost_priv(shost); | |
8131 | memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER)); | |
8132 | INIT_LIST_HEAD(&ioc->list); | |
8133 | list_add_tail(&ioc->list, &mpt3sas_ioc_list); | |
8134 | ioc->shost = shost; | |
8135 | ioc->id = mpt_ids++; | |
f92363d1 SR |
8136 | ioc->pdev = pdev; |
8137 | ioc->scsi_io_cb_idx = scsi_io_cb_idx; | |
8138 | ioc->tm_cb_idx = tm_cb_idx; | |
8139 | ioc->ctl_cb_idx = ctl_cb_idx; | |
8140 | ioc->base_cb_idx = base_cb_idx; | |
8141 | ioc->port_enable_cb_idx = port_enable_cb_idx; | |
8142 | ioc->transport_cb_idx = transport_cb_idx; | |
8143 | ioc->scsih_cb_idx = scsih_cb_idx; | |
8144 | ioc->config_cb_idx = config_cb_idx; | |
8145 | ioc->tm_tr_cb_idx = tm_tr_cb_idx; | |
8146 | ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx; | |
8147 | ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx; | |
8148 | ioc->logging_level = logging_level; | |
8149 | ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds; | |
8150 | /* misc semaphores and spin locks */ | |
8151 | mutex_init(&ioc->reset_in_progress_mutex); | |
8152 | spin_lock_init(&ioc->ioc_reset_in_progress_lock); | |
8153 | spin_lock_init(&ioc->scsi_lookup_lock); | |
8154 | spin_lock_init(&ioc->sas_device_lock); | |
8155 | spin_lock_init(&ioc->sas_node_lock); | |
8156 | spin_lock_init(&ioc->fw_event_lock); | |
8157 | spin_lock_init(&ioc->raid_device_lock); | |
8158 | spin_lock_init(&ioc->diag_trigger_lock); | |
8159 | ||
8160 | INIT_LIST_HEAD(&ioc->sas_device_list); | |
8161 | INIT_LIST_HEAD(&ioc->sas_device_init_list); | |
8162 | INIT_LIST_HEAD(&ioc->sas_expander_list); | |
8163 | INIT_LIST_HEAD(&ioc->fw_event_list); | |
8164 | INIT_LIST_HEAD(&ioc->raid_device_list); | |
8165 | INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list); | |
8166 | INIT_LIST_HEAD(&ioc->delayed_tr_list); | |
8167 | INIT_LIST_HEAD(&ioc->delayed_tr_volume_list); | |
cf9bd21a | 8168 | INIT_LIST_HEAD(&ioc->reply_queue_list); |
f92363d1 | 8169 | |
d357e84d SR |
8170 | _scsih_determine_hba_mpi_version(ioc); |
8171 | sprintf(ioc->name, "%s_cm%d", driver_name, ioc->id); | |
8172 | ||
f92363d1 SR |
8173 | /* init shost parameters */ |
8174 | shost->max_cmd_len = 32; | |
8175 | shost->max_lun = max_lun; | |
8176 | shost->transportt = mpt3sas_transport_template; | |
8177 | shost->unique_id = ioc->id; | |
8178 | ||
8179 | if (max_sectors != 0xFFFF) { | |
8180 | if (max_sectors < 64) { | |
8181 | shost->max_sectors = 64; | |
8182 | pr_warn(MPT3SAS_FMT "Invalid value %d passed " \ | |
8183 | "for max_sectors, range is 64 to 32767. Assigning " | |
8184 | "value of 64.\n", ioc->name, max_sectors); | |
8185 | } else if (max_sectors > 32767) { | |
8186 | shost->max_sectors = 32767; | |
8187 | pr_warn(MPT3SAS_FMT "Invalid value %d passed " \ | |
8188 | "for max_sectors, range is 64 to 32767. Assigning " | |
8189 | "default value of 32767.\n", ioc->name, | |
8190 | max_sectors); | |
8191 | } else { | |
8192 | shost->max_sectors = max_sectors & 0xFFFE; | |
8193 | pr_info(MPT3SAS_FMT | |
8194 | "The max_sectors value is set to %d\n", | |
8195 | ioc->name, shost->max_sectors); | |
8196 | } | |
8197 | } | |
8198 | ||
f92363d1 SR |
8199 | /* register EEDP capabilities with SCSI layer */ |
8200 | if (prot_mask > 0) | |
8201 | scsi_host_set_prot(shost, prot_mask); | |
8202 | else | |
8203 | scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION | |
8204 | | SHOST_DIF_TYPE2_PROTECTION | |
8205 | | SHOST_DIF_TYPE3_PROTECTION); | |
8206 | ||
8207 | scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC); | |
8208 | ||
8209 | /* event thread */ | |
8210 | snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name), | |
8211 | "fw_event%d", ioc->id); | |
bdff785e SR |
8212 | ioc->firmware_event_thread = alloc_ordered_workqueue( |
8213 | ioc->firmware_event_name, WQ_MEM_RECLAIM); | |
f92363d1 SR |
8214 | if (!ioc->firmware_event_thread) { |
8215 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
8216 | ioc->name, __FILE__, __LINE__, __func__); | |
b65f1d4d | 8217 | rv = -ENODEV; |
f92363d1 SR |
8218 | goto out_thread_fail; |
8219 | } | |
8220 | ||
8221 | ioc->is_driver_loading = 1; | |
8222 | if ((mpt3sas_base_attach(ioc))) { | |
8223 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
8224 | ioc->name, __FILE__, __LINE__, __func__); | |
b65f1d4d | 8225 | rv = -ENODEV; |
f92363d1 SR |
8226 | goto out_attach_fail; |
8227 | } | |
7786ab6a SR |
8228 | |
8229 | #ifdef SCSI_MPT2SAS | |
8230 | if (ioc->is_warpdrive) { | |
8231 | if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) | |
8232 | ioc->hide_drives = 0; | |
8233 | else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS) | |
8234 | ioc->hide_drives = 1; | |
8235 | else { | |
8236 | if (_scsih_get_num_volumes(ioc)) | |
8237 | ioc->hide_drives = 1; | |
8238 | else | |
8239 | ioc->hide_drives = 0; | |
8240 | } | |
8241 | } else | |
8242 | ioc->hide_drives = 0; | |
8243 | #endif | |
8244 | ||
b65f1d4d SR |
8245 | rv = scsi_add_host(shost, &pdev->dev); |
8246 | if (rv) { | |
4dc06fd8 RS |
8247 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
8248 | ioc->name, __FILE__, __LINE__, __func__); | |
4dc06fd8 RS |
8249 | goto out_add_shost_fail; |
8250 | } | |
8251 | ||
f92363d1 SR |
8252 | scsi_scan_host(shost); |
8253 | return 0; | |
4dc06fd8 RS |
8254 | out_add_shost_fail: |
8255 | mpt3sas_base_detach(ioc); | |
f92363d1 SR |
8256 | out_attach_fail: |
8257 | destroy_workqueue(ioc->firmware_event_thread); | |
8258 | out_thread_fail: | |
8259 | list_del(&ioc->list); | |
f92363d1 | 8260 | scsi_host_put(shost); |
b65f1d4d | 8261 | return rv; |
f92363d1 SR |
8262 | } |
8263 | ||
8264 | #ifdef CONFIG_PM | |
8265 | /** | |
8a7e4c24 | 8266 | * scsih_suspend - power management suspend main entry point |
f92363d1 SR |
8267 | * @pdev: PCI device struct |
8268 | * @state: PM state change to (usually PCI_D3) | |
8269 | * | |
8270 | * Returns 0 success, anything else error. | |
8271 | */ | |
8a7e4c24 SR |
8272 | int |
8273 | scsih_suspend(struct pci_dev *pdev, pm_message_t state) | |
f92363d1 SR |
8274 | { |
8275 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8276 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
8277 | pci_power_t device_state; | |
8278 | ||
8279 | mpt3sas_base_stop_watchdog(ioc); | |
8280 | flush_scheduled_work(); | |
8281 | scsi_block_requests(shost); | |
8282 | device_state = pci_choose_state(pdev, state); | |
8283 | pr_info(MPT3SAS_FMT | |
8284 | "pdev=0x%p, slot=%s, entering operating state [D%d]\n", | |
8285 | ioc->name, pdev, pci_name(pdev), device_state); | |
8286 | ||
8287 | pci_save_state(pdev); | |
8288 | mpt3sas_base_free_resources(ioc); | |
8289 | pci_set_power_state(pdev, device_state); | |
8290 | return 0; | |
8291 | } | |
8292 | ||
8293 | /** | |
8a7e4c24 | 8294 | * scsih_resume - power management resume main entry point |
f92363d1 SR |
8295 | * @pdev: PCI device struct |
8296 | * | |
8297 | * Returns 0 success, anything else error. | |
8298 | */ | |
8a7e4c24 SR |
8299 | int |
8300 | scsih_resume(struct pci_dev *pdev) | |
f92363d1 SR |
8301 | { |
8302 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8303 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
8304 | pci_power_t device_state = pdev->current_state; | |
8305 | int r; | |
8306 | ||
8307 | pr_info(MPT3SAS_FMT | |
8308 | "pdev=0x%p, slot=%s, previous operating state [D%d]\n", | |
8309 | ioc->name, pdev, pci_name(pdev), device_state); | |
8310 | ||
8311 | pci_set_power_state(pdev, PCI_D0); | |
8312 | pci_enable_wake(pdev, PCI_D0, 0); | |
8313 | pci_restore_state(pdev); | |
8314 | ioc->pdev = pdev; | |
8315 | r = mpt3sas_base_map_resources(ioc); | |
8316 | if (r) | |
8317 | return r; | |
8318 | ||
8319 | mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET); | |
8320 | scsi_unblock_requests(shost); | |
8321 | mpt3sas_base_start_watchdog(ioc); | |
8322 | return 0; | |
8323 | } | |
8324 | #endif /* CONFIG_PM */ | |
8325 | ||
8326 | /** | |
8a7e4c24 | 8327 | * scsih_pci_error_detected - Called when a PCI error is detected. |
f92363d1 SR |
8328 | * @pdev: PCI device struct |
8329 | * @state: PCI channel state | |
8330 | * | |
8331 | * Description: Called when a PCI error is detected. | |
8332 | * | |
8333 | * Return value: | |
8334 | * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT | |
8335 | */ | |
8a7e4c24 SR |
8336 | pci_ers_result_t |
8337 | scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) | |
f92363d1 SR |
8338 | { |
8339 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8340 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
8341 | ||
8342 | pr_info(MPT3SAS_FMT "PCI error: detected callback, state(%d)!!\n", | |
8343 | ioc->name, state); | |
8344 | ||
8345 | switch (state) { | |
8346 | case pci_channel_io_normal: | |
8347 | return PCI_ERS_RESULT_CAN_RECOVER; | |
8348 | case pci_channel_io_frozen: | |
8349 | /* Fatal error, prepare for slot reset */ | |
8350 | ioc->pci_error_recovery = 1; | |
8351 | scsi_block_requests(ioc->shost); | |
8352 | mpt3sas_base_stop_watchdog(ioc); | |
8353 | mpt3sas_base_free_resources(ioc); | |
8354 | return PCI_ERS_RESULT_NEED_RESET; | |
8355 | case pci_channel_io_perm_failure: | |
8356 | /* Permanent error, prepare for device removal */ | |
8357 | ioc->pci_error_recovery = 1; | |
8358 | mpt3sas_base_stop_watchdog(ioc); | |
8359 | _scsih_flush_running_cmds(ioc); | |
8360 | return PCI_ERS_RESULT_DISCONNECT; | |
8361 | } | |
8362 | return PCI_ERS_RESULT_NEED_RESET; | |
8363 | } | |
8364 | ||
8365 | /** | |
8a7e4c24 | 8366 | * scsih_pci_slot_reset - Called when PCI slot has been reset. |
f92363d1 SR |
8367 | * @pdev: PCI device struct |
8368 | * | |
8369 | * Description: This routine is called by the pci error recovery | |
8370 | * code after the PCI slot has been reset, just before we | |
8371 | * should resume normal operations. | |
8372 | */ | |
8a7e4c24 SR |
8373 | pci_ers_result_t |
8374 | scsih_pci_slot_reset(struct pci_dev *pdev) | |
f92363d1 SR |
8375 | { |
8376 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8377 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
8378 | int rc; | |
8379 | ||
8380 | pr_info(MPT3SAS_FMT "PCI error: slot reset callback!!\n", | |
8381 | ioc->name); | |
8382 | ||
8383 | ioc->pci_error_recovery = 0; | |
8384 | ioc->pdev = pdev; | |
8385 | pci_restore_state(pdev); | |
8386 | rc = mpt3sas_base_map_resources(ioc); | |
8387 | if (rc) | |
8388 | return PCI_ERS_RESULT_DISCONNECT; | |
8389 | ||
8390 | rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, | |
8391 | FORCE_BIG_HAMMER); | |
8392 | ||
8393 | pr_warn(MPT3SAS_FMT "hard reset: %s\n", ioc->name, | |
8394 | (rc == 0) ? "success" : "failed"); | |
8395 | ||
8396 | if (!rc) | |
8397 | return PCI_ERS_RESULT_RECOVERED; | |
8398 | else | |
8399 | return PCI_ERS_RESULT_DISCONNECT; | |
8400 | } | |
8401 | ||
8402 | /** | |
8a7e4c24 | 8403 | * scsih_pci_resume() - resume normal ops after PCI reset |
f92363d1 SR |
8404 | * @pdev: pointer to PCI device |
8405 | * | |
8406 | * Called when the error recovery driver tells us that its | |
8407 | * OK to resume normal operation. Use completion to allow | |
8408 | * halted scsi ops to resume. | |
8409 | */ | |
8a7e4c24 SR |
8410 | void |
8411 | scsih_pci_resume(struct pci_dev *pdev) | |
f92363d1 SR |
8412 | { |
8413 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8414 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
8415 | ||
8416 | pr_info(MPT3SAS_FMT "PCI error: resume callback!!\n", ioc->name); | |
8417 | ||
8418 | pci_cleanup_aer_uncorrect_error_status(pdev); | |
8419 | mpt3sas_base_start_watchdog(ioc); | |
8420 | scsi_unblock_requests(ioc->shost); | |
8421 | } | |
8422 | ||
8423 | /** | |
8a7e4c24 | 8424 | * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers |
f92363d1 SR |
8425 | * @pdev: pointer to PCI device |
8426 | */ | |
8a7e4c24 SR |
8427 | pci_ers_result_t |
8428 | scsih_pci_mmio_enabled(struct pci_dev *pdev) | |
f92363d1 SR |
8429 | { |
8430 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8431 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
8432 | ||
8433 | pr_info(MPT3SAS_FMT "PCI error: mmio enabled callback!!\n", | |
8434 | ioc->name); | |
8435 | ||
8436 | /* TODO - dump whatever for debugging purposes */ | |
8437 | ||
8438 | /* Request a slot reset. */ | |
8439 | return PCI_ERS_RESULT_NEED_RESET; | |
8440 | } | |
8441 | ||
f92363d1 | 8442 | /** |
8a7e4c24 | 8443 | * scsih_init - main entry point for this driver. |
f92363d1 SR |
8444 | * |
8445 | * Returns 0 success, anything else error. | |
8446 | */ | |
8a7e4c24 SR |
8447 | int |
8448 | scsih_init(void) | |
f92363d1 | 8449 | { |
f92363d1 SR |
8450 | mpt_ids = 0; |
8451 | ||
f92363d1 SR |
8452 | mpt3sas_base_initialize_callback_handler(); |
8453 | ||
8454 | /* queuecommand callback hander */ | |
8455 | scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done); | |
8456 | ||
8457 | /* task managment callback handler */ | |
8458 | tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done); | |
8459 | ||
8460 | /* base internal commands callback handler */ | |
8461 | base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done); | |
8462 | port_enable_cb_idx = mpt3sas_base_register_callback_handler( | |
8463 | mpt3sas_port_enable_done); | |
8464 | ||
8465 | /* transport internal commands callback handler */ | |
8466 | transport_cb_idx = mpt3sas_base_register_callback_handler( | |
8467 | mpt3sas_transport_done); | |
8468 | ||
8469 | /* scsih internal commands callback handler */ | |
8470 | scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done); | |
8471 | ||
8472 | /* configuration page API internal commands callback handler */ | |
8473 | config_cb_idx = mpt3sas_base_register_callback_handler( | |
8474 | mpt3sas_config_done); | |
8475 | ||
8476 | /* ctl module callback handler */ | |
8477 | ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done); | |
8478 | ||
8479 | tm_tr_cb_idx = mpt3sas_base_register_callback_handler( | |
8480 | _scsih_tm_tr_complete); | |
8481 | ||
8482 | tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler( | |
8483 | _scsih_tm_volume_tr_complete); | |
8484 | ||
8485 | tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler( | |
8486 | _scsih_sas_control_complete); | |
8487 | ||
7497392a | 8488 | return 0; |
f92363d1 SR |
8489 | } |
8490 | ||
8491 | /** | |
7497392a | 8492 | * scsih_exit - exit point for this driver (when it is a module). |
f92363d1 SR |
8493 | * |
8494 | * Returns 0 success, anything else error. | |
8495 | */ | |
8a7e4c24 SR |
8496 | void |
8497 | scsih_exit(void) | |
f92363d1 | 8498 | { |
f92363d1 SR |
8499 | |
8500 | mpt3sas_base_release_callback_handler(scsi_io_cb_idx); | |
8501 | mpt3sas_base_release_callback_handler(tm_cb_idx); | |
8502 | mpt3sas_base_release_callback_handler(base_cb_idx); | |
8503 | mpt3sas_base_release_callback_handler(port_enable_cb_idx); | |
8504 | mpt3sas_base_release_callback_handler(transport_cb_idx); | |
8505 | mpt3sas_base_release_callback_handler(scsih_cb_idx); | |
8506 | mpt3sas_base_release_callback_handler(config_cb_idx); | |
8507 | mpt3sas_base_release_callback_handler(ctl_cb_idx); | |
8508 | ||
8509 | mpt3sas_base_release_callback_handler(tm_tr_cb_idx); | |
8510 | mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx); | |
8511 | mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx); | |
8512 | ||
8513 | /* raid transport support */ | |
8514 | raid_class_release(mpt3sas_raid_template); | |
8515 | sas_release_transport(mpt3sas_transport_template); | |
8516 | } | |
7786ab6a SR |
8517 | |
8518 | #ifdef SCSI_MPT2SAS | |
8519 | #include "../mpt2sas/mpt2sas_warpdrive.c" | |
8520 | #endif |