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