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