]>
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 | 62 | #define RAID_CHANNEL 1 |
d88e1eab SPS |
63 | |
64 | #define PCIE_CHANNEL 2 | |
65 | ||
f92363d1 SR |
66 | /* forward proto's */ |
67 | static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc, | |
68 | struct _sas_node *sas_expander); | |
69 | static void _firmware_event_work(struct work_struct *work); | |
70 | ||
71 | static void _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc, | |
72 | struct _sas_device *sas_device); | |
73 | static int _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, | |
74 | u8 retry_count, u8 is_pd); | |
c102e00c | 75 | static int _scsih_pcie_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle); |
3075ac49 SPS |
76 | static void _scsih_pcie_device_remove_from_sml(struct MPT3SAS_ADAPTER *ioc, |
77 | struct _pcie_device *pcie_device); | |
4318c734 SPS |
78 | static void |
79 | _scsih_pcie_check_device(struct MPT3SAS_ADAPTER *ioc, u16 handle); | |
f92363d1 SR |
80 | static u8 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid); |
81 | ||
f92363d1 SR |
82 | /* global parameters */ |
83 | LIST_HEAD(mpt3sas_ioc_list); | |
08c4d550 SR |
84 | /* global ioc lock for list operations */ |
85 | DEFINE_SPINLOCK(gioc_lock); | |
f92363d1 | 86 | |
c84b06a4 SR |
87 | MODULE_AUTHOR(MPT3SAS_AUTHOR); |
88 | MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION); | |
89 | MODULE_LICENSE("GPL"); | |
90 | MODULE_VERSION(MPT3SAS_DRIVER_VERSION); | |
91 | MODULE_ALIAS("mpt2sas"); | |
92 | ||
f92363d1 SR |
93 | /* local parameters */ |
94 | static u8 scsi_io_cb_idx = -1; | |
95 | static u8 tm_cb_idx = -1; | |
96 | static u8 ctl_cb_idx = -1; | |
97 | static u8 base_cb_idx = -1; | |
98 | static u8 port_enable_cb_idx = -1; | |
99 | static u8 transport_cb_idx = -1; | |
100 | static u8 scsih_cb_idx = -1; | |
101 | static u8 config_cb_idx = -1; | |
c84b06a4 SR |
102 | static int mpt2_ids; |
103 | static int mpt3_ids; | |
f92363d1 SR |
104 | |
105 | static u8 tm_tr_cb_idx = -1 ; | |
106 | static u8 tm_tr_volume_cb_idx = -1 ; | |
107 | static u8 tm_sas_control_cb_idx = -1; | |
108 | ||
109 | /* command line options */ | |
110 | static u32 logging_level; | |
111 | MODULE_PARM_DESC(logging_level, | |
112 | " bits for enabling additional logging info (default=0)"); | |
113 | ||
114 | ||
115 | static ushort max_sectors = 0xFFFF; | |
116 | module_param(max_sectors, ushort, 0); | |
117 | MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767"); | |
118 | ||
119 | ||
120 | static int missing_delay[2] = {-1, -1}; | |
121 | module_param_array(missing_delay, int, NULL, 0); | |
122 | MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay"); | |
123 | ||
124 | /* scsi-mid layer global parmeter is max_report_luns, which is 511 */ | |
125 | #define MPT3SAS_MAX_LUN (16895) | |
1abf635d HR |
126 | static u64 max_lun = MPT3SAS_MAX_LUN; |
127 | module_param(max_lun, ullong, 0); | |
f92363d1 SR |
128 | MODULE_PARM_DESC(max_lun, " max lun, default=16895 "); |
129 | ||
c84b06a4 SR |
130 | static ushort hbas_to_enumerate; |
131 | module_param(hbas_to_enumerate, ushort, 0); | |
132 | MODULE_PARM_DESC(hbas_to_enumerate, | |
133 | " 0 - enumerates both SAS 2.0 & SAS 3.0 generation HBAs\n \ | |
134 | 1 - enumerates only SAS 2.0 generation HBAs\n \ | |
135 | 2 - enumerates only SAS 3.0 generation HBAs (default=0)"); | |
f92363d1 SR |
136 | |
137 | /* diag_buffer_enable is bitwise | |
138 | * bit 0 set = TRACE | |
139 | * bit 1 set = SNAPSHOT | |
140 | * bit 2 set = EXTENDED | |
141 | * | |
142 | * Either bit can be set, or both | |
143 | */ | |
144 | static int diag_buffer_enable = -1; | |
145 | module_param(diag_buffer_enable, int, 0); | |
146 | MODULE_PARM_DESC(diag_buffer_enable, | |
147 | " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)"); | |
148 | static int disable_discovery = -1; | |
149 | module_param(disable_discovery, int, 0); | |
150 | MODULE_PARM_DESC(disable_discovery, " disable discovery "); | |
151 | ||
152 | ||
153 | /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */ | |
154 | static int prot_mask = -1; | |
155 | module_param(prot_mask, int, 0); | |
156 | MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 "); | |
157 | ||
158 | ||
159 | /* raid transport support */ | |
7497392a | 160 | struct raid_template *mpt3sas_raid_template; |
c84b06a4 | 161 | struct raid_template *mpt2sas_raid_template; |
f92363d1 SR |
162 | |
163 | ||
164 | /** | |
165 | * struct sense_info - common structure for obtaining sense keys | |
166 | * @skey: sense key | |
167 | * @asc: additional sense code | |
168 | * @ascq: additional sense code qualifier | |
169 | */ | |
170 | struct sense_info { | |
171 | u8 skey; | |
172 | u8 asc; | |
173 | u8 ascq; | |
174 | }; | |
175 | ||
176 | #define MPT3SAS_PROCESS_TRIGGER_DIAG (0xFFFB) | |
0f624c39 | 177 | #define MPT3SAS_TURN_ON_PFA_LED (0xFFFC) |
f92363d1 SR |
178 | #define MPT3SAS_PORT_ENABLE_COMPLETE (0xFFFD) |
179 | #define MPT3SAS_ABRT_TASK_SET (0xFFFE) | |
180 | #define MPT3SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF) | |
181 | /** | |
182 | * struct fw_event_work - firmware event struct | |
183 | * @list: link list framework | |
184 | * @work: work object (ioc->fault_reset_work_q) | |
f92363d1 SR |
185 | * @ioc: per adapter object |
186 | * @device_handle: device handle | |
187 | * @VF_ID: virtual function id | |
188 | * @VP_ID: virtual port id | |
189 | * @ignore: flag meaning this event has been marked to ignore | |
b8ac0cc7 JL |
190 | * @event: firmware event MPI2_EVENT_XXX defined in mpi2_ioc.h |
191 | * @refcount: kref for this event | |
f92363d1 SR |
192 | * @event_data: reply event data payload follows |
193 | * | |
194 | * This object stored on ioc->fw_event_list. | |
195 | */ | |
196 | struct fw_event_work { | |
197 | struct list_head list; | |
198 | struct work_struct work; | |
f92363d1 SR |
199 | |
200 | struct MPT3SAS_ADAPTER *ioc; | |
201 | u16 device_handle; | |
202 | u8 VF_ID; | |
203 | u8 VP_ID; | |
204 | u8 ignore; | |
205 | u16 event; | |
146b16c8 | 206 | struct kref refcount; |
35b62362 | 207 | char event_data[0] __aligned(4); |
f92363d1 SR |
208 | }; |
209 | ||
146b16c8 SR |
210 | static void fw_event_work_free(struct kref *r) |
211 | { | |
212 | kfree(container_of(r, struct fw_event_work, refcount)); | |
213 | } | |
214 | ||
215 | static void fw_event_work_get(struct fw_event_work *fw_work) | |
216 | { | |
217 | kref_get(&fw_work->refcount); | |
218 | } | |
219 | ||
220 | static void fw_event_work_put(struct fw_event_work *fw_work) | |
221 | { | |
222 | kref_put(&fw_work->refcount, fw_event_work_free); | |
223 | } | |
224 | ||
225 | static struct fw_event_work *alloc_fw_event_work(int len) | |
226 | { | |
227 | struct fw_event_work *fw_event; | |
228 | ||
229 | fw_event = kzalloc(sizeof(*fw_event) + len, GFP_ATOMIC); | |
230 | if (!fw_event) | |
231 | return NULL; | |
232 | ||
233 | kref_init(&fw_event->refcount); | |
234 | return fw_event; | |
235 | } | |
236 | ||
f92363d1 SR |
237 | /** |
238 | * struct _scsi_io_transfer - scsi io transfer | |
239 | * @handle: sas device handle (assigned by firmware) | |
240 | * @is_raid: flag set for hidden raid components | |
241 | * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE, | |
242 | * @data_length: data transfer length | |
243 | * @data_dma: dma pointer to data | |
244 | * @sense: sense data | |
245 | * @lun: lun number | |
246 | * @cdb_length: cdb length | |
247 | * @cdb: cdb contents | |
248 | * @timeout: timeout for this command | |
249 | * @VF_ID: virtual function id | |
250 | * @VP_ID: virtual port id | |
251 | * @valid_reply: flag set for reply message | |
252 | * @sense_length: sense length | |
253 | * @ioc_status: ioc status | |
254 | * @scsi_state: scsi state | |
255 | * @scsi_status: scsi staus | |
256 | * @log_info: log information | |
257 | * @transfer_length: data length transfer when there is a reply message | |
258 | * | |
259 | * Used for sending internal scsi commands to devices within this module. | |
260 | * Refer to _scsi_send_scsi_io(). | |
261 | */ | |
262 | struct _scsi_io_transfer { | |
263 | u16 handle; | |
264 | u8 is_raid; | |
265 | enum dma_data_direction dir; | |
266 | u32 data_length; | |
267 | dma_addr_t data_dma; | |
268 | u8 sense[SCSI_SENSE_BUFFERSIZE]; | |
269 | u32 lun; | |
270 | u8 cdb_length; | |
271 | u8 cdb[32]; | |
272 | u8 timeout; | |
273 | u8 VF_ID; | |
274 | u8 VP_ID; | |
275 | u8 valid_reply; | |
276 | /* the following bits are only valid when 'valid_reply = 1' */ | |
277 | u32 sense_length; | |
278 | u16 ioc_status; | |
279 | u8 scsi_state; | |
280 | u8 scsi_status; | |
281 | u32 log_info; | |
282 | u32 transfer_length; | |
283 | }; | |
284 | ||
f92363d1 SR |
285 | /** |
286 | * _scsih_set_debug_level - global setting of ioc->logging_level. | |
287 | * | |
288 | * Note: The logging levels are defined in mpt3sas_debug.h. | |
289 | */ | |
290 | static int | |
e4dca7b7 | 291 | _scsih_set_debug_level(const char *val, const struct kernel_param *kp) |
f92363d1 SR |
292 | { |
293 | int ret = param_set_int(val, kp); | |
294 | struct MPT3SAS_ADAPTER *ioc; | |
295 | ||
296 | if (ret) | |
297 | return ret; | |
298 | ||
299 | pr_info("setting logging_level(0x%08x)\n", logging_level); | |
08c4d550 | 300 | spin_lock(&gioc_lock); |
f92363d1 SR |
301 | list_for_each_entry(ioc, &mpt3sas_ioc_list, list) |
302 | ioc->logging_level = logging_level; | |
08c4d550 | 303 | spin_unlock(&gioc_lock); |
f92363d1 SR |
304 | return 0; |
305 | } | |
306 | module_param_call(logging_level, _scsih_set_debug_level, param_get_int, | |
307 | &logging_level, 0644); | |
308 | ||
309 | /** | |
310 | * _scsih_srch_boot_sas_address - search based on sas_address | |
311 | * @sas_address: sas address | |
312 | * @boot_device: boot device object from bios page 2 | |
313 | * | |
314 | * Returns 1 when there's a match, 0 means no match. | |
315 | */ | |
316 | static inline int | |
317 | _scsih_srch_boot_sas_address(u64 sas_address, | |
318 | Mpi2BootDeviceSasWwid_t *boot_device) | |
319 | { | |
320 | return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0; | |
321 | } | |
322 | ||
323 | /** | |
324 | * _scsih_srch_boot_device_name - search based on device name | |
325 | * @device_name: device name specified in INDENTIFY fram | |
326 | * @boot_device: boot device object from bios page 2 | |
327 | * | |
328 | * Returns 1 when there's a match, 0 means no match. | |
329 | */ | |
330 | static inline int | |
331 | _scsih_srch_boot_device_name(u64 device_name, | |
332 | Mpi2BootDeviceDeviceName_t *boot_device) | |
333 | { | |
334 | return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0; | |
335 | } | |
336 | ||
337 | /** | |
338 | * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot | |
339 | * @enclosure_logical_id: enclosure logical id | |
340 | * @slot_number: slot number | |
341 | * @boot_device: boot device object from bios page 2 | |
342 | * | |
343 | * Returns 1 when there's a match, 0 means no match. | |
344 | */ | |
345 | static inline int | |
346 | _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number, | |
347 | Mpi2BootDeviceEnclosureSlot_t *boot_device) | |
348 | { | |
349 | return (enclosure_logical_id == le64_to_cpu(boot_device-> | |
350 | EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device-> | |
351 | SlotNumber)) ? 1 : 0; | |
352 | } | |
353 | ||
354 | /** | |
355 | * _scsih_is_boot_device - search for matching boot device. | |
356 | * @sas_address: sas address | |
357 | * @device_name: device name specified in INDENTIFY fram | |
358 | * @enclosure_logical_id: enclosure logical id | |
359 | * @slot_number: slot number | |
360 | * @form: specifies boot device form | |
361 | * @boot_device: boot device object from bios page 2 | |
362 | * | |
363 | * Returns 1 when there's a match, 0 means no match. | |
364 | */ | |
365 | static int | |
366 | _scsih_is_boot_device(u64 sas_address, u64 device_name, | |
367 | u64 enclosure_logical_id, u16 slot, u8 form, | |
368 | Mpi2BiosPage2BootDevice_t *boot_device) | |
369 | { | |
370 | int rc = 0; | |
371 | ||
372 | switch (form) { | |
373 | case MPI2_BIOSPAGE2_FORM_SAS_WWID: | |
374 | if (!sas_address) | |
375 | break; | |
376 | rc = _scsih_srch_boot_sas_address( | |
377 | sas_address, &boot_device->SasWwid); | |
378 | break; | |
379 | case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT: | |
380 | if (!enclosure_logical_id) | |
381 | break; | |
382 | rc = _scsih_srch_boot_encl_slot( | |
383 | enclosure_logical_id, | |
384 | slot, &boot_device->EnclosureSlot); | |
385 | break; | |
386 | case MPI2_BIOSPAGE2_FORM_DEVICE_NAME: | |
387 | if (!device_name) | |
388 | break; | |
389 | rc = _scsih_srch_boot_device_name( | |
390 | device_name, &boot_device->DeviceName); | |
391 | break; | |
392 | case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED: | |
393 | break; | |
394 | } | |
395 | ||
396 | return rc; | |
397 | } | |
398 | ||
399 | /** | |
400 | * _scsih_get_sas_address - set the sas_address for given device handle | |
401 | * @handle: device handle | |
402 | * @sas_address: sas address | |
403 | * | |
404 | * Returns 0 success, non-zero when failure | |
405 | */ | |
406 | static int | |
407 | _scsih_get_sas_address(struct MPT3SAS_ADAPTER *ioc, u16 handle, | |
408 | u64 *sas_address) | |
409 | { | |
410 | Mpi2SasDevicePage0_t sas_device_pg0; | |
411 | Mpi2ConfigReply_t mpi_reply; | |
412 | u32 ioc_status; | |
413 | ||
414 | *sas_address = 0; | |
415 | ||
f92363d1 SR |
416 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
417 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
418 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name, | |
419 | __FILE__, __LINE__, __func__); | |
420 | return -ENXIO; | |
421 | } | |
422 | ||
423 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
424 | if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { | |
758f8139 SR |
425 | /* For HBA, vSES doesn't return HBA SAS address. Instead return |
426 | * vSES's sas address. | |
427 | */ | |
428 | if ((handle <= ioc->sas_hba.num_phys) && | |
429 | (!(le32_to_cpu(sas_device_pg0.DeviceInfo) & | |
430 | MPI2_SAS_DEVICE_INFO_SEP))) | |
431 | *sas_address = ioc->sas_hba.sas_address; | |
432 | else | |
433 | *sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | |
f92363d1 SR |
434 | return 0; |
435 | } | |
436 | ||
6c7abffc | 437 | /* we hit this because the given parent handle doesn't exist */ |
f92363d1 SR |
438 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
439 | return -ENXIO; | |
440 | ||
441 | /* else error case */ | |
442 | pr_err(MPT3SAS_FMT | |
443 | "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n", | |
444 | ioc->name, handle, ioc_status, | |
445 | __FILE__, __LINE__, __func__); | |
446 | return -EIO; | |
447 | } | |
448 | ||
449 | /** | |
450 | * _scsih_determine_boot_device - determine boot device. | |
451 | * @ioc: per adapter object | |
d88e1eab SPS |
452 | * @device: sas_device or pcie_device object |
453 | * @channel: SAS or PCIe channel | |
f92363d1 SR |
454 | * |
455 | * Determines whether this device should be first reported device to | |
456 | * to scsi-ml or sas transport, this purpose is for persistent boot device. | |
457 | * There are primary, alternate, and current entries in bios page 2. The order | |
458 | * priority is primary, alternate, then current. This routine saves | |
d88e1eab | 459 | * the corresponding device object. |
f92363d1 SR |
460 | * The saved data to be used later in _scsih_probe_boot_devices(). |
461 | */ | |
462 | static void | |
d88e1eab SPS |
463 | _scsih_determine_boot_device(struct MPT3SAS_ADAPTER *ioc, void *device, |
464 | u32 channel) | |
f92363d1 SR |
465 | { |
466 | struct _sas_device *sas_device; | |
d88e1eab | 467 | struct _pcie_device *pcie_device; |
f92363d1 SR |
468 | struct _raid_device *raid_device; |
469 | u64 sas_address; | |
470 | u64 device_name; | |
471 | u64 enclosure_logical_id; | |
472 | u16 slot; | |
473 | ||
474 | /* only process this function when driver loads */ | |
475 | if (!ioc->is_driver_loading) | |
476 | return; | |
477 | ||
478 | /* no Bios, return immediately */ | |
479 | if (!ioc->bios_pg3.BiosVersion) | |
480 | return; | |
481 | ||
d88e1eab | 482 | if (channel == RAID_CHANNEL) { |
f92363d1 SR |
483 | raid_device = device; |
484 | sas_address = raid_device->wwid; | |
485 | device_name = 0; | |
486 | enclosure_logical_id = 0; | |
487 | slot = 0; | |
d88e1eab SPS |
488 | } else if (channel == PCIE_CHANNEL) { |
489 | pcie_device = device; | |
490 | sas_address = pcie_device->wwid; | |
491 | device_name = 0; | |
492 | enclosure_logical_id = 0; | |
493 | slot = 0; | |
494 | } else { | |
495 | sas_device = device; | |
496 | sas_address = sas_device->sas_address; | |
497 | device_name = sas_device->device_name; | |
498 | enclosure_logical_id = sas_device->enclosure_logical_id; | |
499 | slot = sas_device->slot; | |
f92363d1 SR |
500 | } |
501 | ||
502 | if (!ioc->req_boot_device.device) { | |
503 | if (_scsih_is_boot_device(sas_address, device_name, | |
504 | enclosure_logical_id, slot, | |
505 | (ioc->bios_pg2.ReqBootDeviceForm & | |
506 | MPI2_BIOSPAGE2_FORM_MASK), | |
507 | &ioc->bios_pg2.RequestedBootDevice)) { | |
508 | dinitprintk(ioc, pr_info(MPT3SAS_FMT | |
509 | "%s: req_boot_device(0x%016llx)\n", | |
510 | ioc->name, __func__, | |
511 | (unsigned long long)sas_address)); | |
512 | ioc->req_boot_device.device = device; | |
d88e1eab | 513 | ioc->req_boot_device.channel = channel; |
f92363d1 SR |
514 | } |
515 | } | |
516 | ||
517 | if (!ioc->req_alt_boot_device.device) { | |
518 | if (_scsih_is_boot_device(sas_address, device_name, | |
519 | enclosure_logical_id, slot, | |
520 | (ioc->bios_pg2.ReqAltBootDeviceForm & | |
521 | MPI2_BIOSPAGE2_FORM_MASK), | |
522 | &ioc->bios_pg2.RequestedAltBootDevice)) { | |
523 | dinitprintk(ioc, pr_info(MPT3SAS_FMT | |
524 | "%s: req_alt_boot_device(0x%016llx)\n", | |
525 | ioc->name, __func__, | |
526 | (unsigned long long)sas_address)); | |
527 | ioc->req_alt_boot_device.device = device; | |
d88e1eab | 528 | ioc->req_alt_boot_device.channel = channel; |
f92363d1 SR |
529 | } |
530 | } | |
531 | ||
532 | if (!ioc->current_boot_device.device) { | |
533 | if (_scsih_is_boot_device(sas_address, device_name, | |
534 | enclosure_logical_id, slot, | |
535 | (ioc->bios_pg2.CurrentBootDeviceForm & | |
536 | MPI2_BIOSPAGE2_FORM_MASK), | |
537 | &ioc->bios_pg2.CurrentBootDevice)) { | |
538 | dinitprintk(ioc, pr_info(MPT3SAS_FMT | |
539 | "%s: current_boot_device(0x%016llx)\n", | |
540 | ioc->name, __func__, | |
541 | (unsigned long long)sas_address)); | |
542 | ioc->current_boot_device.device = device; | |
d88e1eab | 543 | ioc->current_boot_device.channel = channel; |
f92363d1 SR |
544 | } |
545 | } | |
546 | } | |
547 | ||
d1cb5e49 SR |
548 | static struct _sas_device * |
549 | __mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc, | |
550 | struct MPT3SAS_TARGET *tgt_priv) | |
551 | { | |
552 | struct _sas_device *ret; | |
553 | ||
554 | assert_spin_locked(&ioc->sas_device_lock); | |
555 | ||
d88e1eab | 556 | ret = tgt_priv->sas_dev; |
d1cb5e49 SR |
557 | if (ret) |
558 | sas_device_get(ret); | |
559 | ||
560 | return ret; | |
561 | } | |
562 | ||
563 | static struct _sas_device * | |
564 | mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc, | |
565 | struct MPT3SAS_TARGET *tgt_priv) | |
566 | { | |
567 | struct _sas_device *ret; | |
568 | unsigned long flags; | |
569 | ||
570 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
571 | ret = __mpt3sas_get_sdev_from_target(ioc, tgt_priv); | |
572 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
573 | ||
574 | return ret; | |
575 | } | |
576 | ||
d88e1eab SPS |
577 | static struct _pcie_device * |
578 | __mpt3sas_get_pdev_from_target(struct MPT3SAS_ADAPTER *ioc, | |
579 | struct MPT3SAS_TARGET *tgt_priv) | |
580 | { | |
581 | struct _pcie_device *ret; | |
582 | ||
583 | assert_spin_locked(&ioc->pcie_device_lock); | |
584 | ||
585 | ret = tgt_priv->pcie_dev; | |
586 | if (ret) | |
587 | pcie_device_get(ret); | |
588 | ||
589 | return ret; | |
590 | } | |
591 | ||
592 | /** | |
593 | * mpt3sas_get_pdev_from_target - pcie device search | |
594 | * @ioc: per adapter object | |
595 | * @tgt_priv: starget private object | |
596 | * | |
597 | * Context: This function will acquire ioc->pcie_device_lock and will release | |
598 | * before returning the pcie_device object. | |
599 | * | |
600 | * This searches for pcie_device from target, then return pcie_device object. | |
601 | */ | |
494f401b | 602 | static struct _pcie_device * |
d88e1eab SPS |
603 | mpt3sas_get_pdev_from_target(struct MPT3SAS_ADAPTER *ioc, |
604 | struct MPT3SAS_TARGET *tgt_priv) | |
605 | { | |
606 | struct _pcie_device *ret; | |
607 | unsigned long flags; | |
608 | ||
609 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
610 | ret = __mpt3sas_get_pdev_from_target(ioc, tgt_priv); | |
611 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
612 | ||
613 | return ret; | |
614 | } | |
d1cb5e49 SR |
615 | |
616 | struct _sas_device * | |
617 | __mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc, | |
618 | u64 sas_address) | |
619 | { | |
620 | struct _sas_device *sas_device; | |
621 | ||
622 | assert_spin_locked(&ioc->sas_device_lock); | |
623 | ||
624 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) | |
625 | if (sas_device->sas_address == sas_address) | |
626 | goto found_device; | |
627 | ||
628 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) | |
629 | if (sas_device->sas_address == sas_address) | |
630 | goto found_device; | |
631 | ||
632 | return NULL; | |
633 | ||
634 | found_device: | |
635 | sas_device_get(sas_device); | |
636 | return sas_device; | |
637 | } | |
638 | ||
f92363d1 | 639 | /** |
d1cb5e49 | 640 | * mpt3sas_get_sdev_by_addr - sas device search |
f92363d1 SR |
641 | * @ioc: per adapter object |
642 | * @sas_address: sas address | |
643 | * Context: Calling function should acquire ioc->sas_device_lock | |
644 | * | |
645 | * This searches for sas_device based on sas_address, then return sas_device | |
646 | * object. | |
647 | */ | |
648 | struct _sas_device * | |
d1cb5e49 | 649 | mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc, |
f92363d1 SR |
650 | u64 sas_address) |
651 | { | |
652 | struct _sas_device *sas_device; | |
d1cb5e49 SR |
653 | unsigned long flags; |
654 | ||
655 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
656 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, | |
657 | sas_address); | |
658 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
659 | ||
660 | return sas_device; | |
661 | } | |
662 | ||
663 | static struct _sas_device * | |
664 | __mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
665 | { | |
666 | struct _sas_device *sas_device; | |
667 | ||
668 | assert_spin_locked(&ioc->sas_device_lock); | |
f92363d1 SR |
669 | |
670 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) | |
d1cb5e49 SR |
671 | if (sas_device->handle == handle) |
672 | goto found_device; | |
f92363d1 SR |
673 | |
674 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) | |
d1cb5e49 SR |
675 | if (sas_device->handle == handle) |
676 | goto found_device; | |
f92363d1 SR |
677 | |
678 | return NULL; | |
d1cb5e49 SR |
679 | |
680 | found_device: | |
681 | sas_device_get(sas_device); | |
682 | return sas_device; | |
f92363d1 SR |
683 | } |
684 | ||
685 | /** | |
d1cb5e49 | 686 | * mpt3sas_get_sdev_by_handle - sas device search |
f92363d1 SR |
687 | * @ioc: per adapter object |
688 | * @handle: sas device handle (assigned by firmware) | |
689 | * Context: Calling function should acquire ioc->sas_device_lock | |
690 | * | |
691 | * This searches for sas_device based on sas_address, then return sas_device | |
692 | * object. | |
693 | */ | |
c102e00c | 694 | struct _sas_device * |
d1cb5e49 | 695 | mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
f92363d1 SR |
696 | { |
697 | struct _sas_device *sas_device; | |
d1cb5e49 | 698 | unsigned long flags; |
f92363d1 | 699 | |
d1cb5e49 SR |
700 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
701 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); | |
702 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
f92363d1 | 703 | |
d1cb5e49 | 704 | return sas_device; |
f92363d1 SR |
705 | } |
706 | ||
75888956 SR |
707 | /** |
708 | * _scsih_display_enclosure_chassis_info - display device location info | |
709 | * @ioc: per adapter object | |
710 | * @sas_device: per sas device object | |
711 | * @sdev: scsi device struct | |
712 | * @starget: scsi target struct | |
713 | * | |
714 | * Returns nothing. | |
715 | */ | |
716 | static void | |
717 | _scsih_display_enclosure_chassis_info(struct MPT3SAS_ADAPTER *ioc, | |
718 | struct _sas_device *sas_device, struct scsi_device *sdev, | |
719 | struct scsi_target *starget) | |
720 | { | |
721 | if (sdev) { | |
722 | if (sas_device->enclosure_handle != 0) | |
723 | sdev_printk(KERN_INFO, sdev, | |
724 | "enclosure logical id (0x%016llx), slot(%d) \n", | |
725 | (unsigned long long) | |
726 | sas_device->enclosure_logical_id, | |
727 | sas_device->slot); | |
728 | if (sas_device->connector_name[0] != '\0') | |
729 | sdev_printk(KERN_INFO, sdev, | |
730 | "enclosure level(0x%04x), connector name( %s)\n", | |
731 | sas_device->enclosure_level, | |
732 | sas_device->connector_name); | |
733 | if (sas_device->is_chassis_slot_valid) | |
734 | sdev_printk(KERN_INFO, sdev, "chassis slot(0x%04x)\n", | |
735 | sas_device->chassis_slot); | |
736 | } else if (starget) { | |
737 | if (sas_device->enclosure_handle != 0) | |
738 | starget_printk(KERN_INFO, starget, | |
739 | "enclosure logical id(0x%016llx), slot(%d) \n", | |
740 | (unsigned long long) | |
741 | sas_device->enclosure_logical_id, | |
742 | sas_device->slot); | |
743 | if (sas_device->connector_name[0] != '\0') | |
744 | starget_printk(KERN_INFO, starget, | |
745 | "enclosure level(0x%04x), connector name( %s)\n", | |
746 | sas_device->enclosure_level, | |
747 | sas_device->connector_name); | |
748 | if (sas_device->is_chassis_slot_valid) | |
749 | starget_printk(KERN_INFO, starget, | |
750 | "chassis slot(0x%04x)\n", | |
751 | sas_device->chassis_slot); | |
752 | } else { | |
753 | if (sas_device->enclosure_handle != 0) | |
754 | pr_info(MPT3SAS_FMT | |
755 | "enclosure logical id(0x%016llx), slot(%d) \n", | |
756 | ioc->name, (unsigned long long) | |
757 | sas_device->enclosure_logical_id, | |
758 | sas_device->slot); | |
759 | if (sas_device->connector_name[0] != '\0') | |
760 | pr_info(MPT3SAS_FMT | |
761 | "enclosure level(0x%04x), connector name( %s)\n", | |
762 | ioc->name, sas_device->enclosure_level, | |
763 | sas_device->connector_name); | |
764 | if (sas_device->is_chassis_slot_valid) | |
765 | pr_info(MPT3SAS_FMT "chassis slot(0x%04x)\n", | |
766 | ioc->name, sas_device->chassis_slot); | |
767 | } | |
768 | } | |
769 | ||
f92363d1 SR |
770 | /** |
771 | * _scsih_sas_device_remove - remove sas_device from list. | |
772 | * @ioc: per adapter object | |
773 | * @sas_device: the sas_device object | |
774 | * Context: This function will acquire ioc->sas_device_lock. | |
775 | * | |
d1cb5e49 | 776 | * If sas_device is on the list, remove it and decrement its reference count. |
f92363d1 SR |
777 | */ |
778 | static void | |
779 | _scsih_sas_device_remove(struct MPT3SAS_ADAPTER *ioc, | |
780 | struct _sas_device *sas_device) | |
781 | { | |
782 | unsigned long flags; | |
783 | ||
784 | if (!sas_device) | |
785 | return; | |
e6d45e3e SR |
786 | pr_info(MPT3SAS_FMT |
787 | "removing handle(0x%04x), sas_addr(0x%016llx)\n", | |
788 | ioc->name, sas_device->handle, | |
789 | (unsigned long long) sas_device->sas_address); | |
790 | ||
75888956 | 791 | _scsih_display_enclosure_chassis_info(ioc, sas_device, NULL, NULL); |
f92363d1 | 792 | |
d1cb5e49 SR |
793 | /* |
794 | * The lock serializes access to the list, but we still need to verify | |
795 | * that nobody removed the entry while we were waiting on the lock. | |
796 | */ | |
f92363d1 | 797 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 SR |
798 | if (!list_empty(&sas_device->list)) { |
799 | list_del_init(&sas_device->list); | |
800 | sas_device_put(sas_device); | |
801 | } | |
f92363d1 SR |
802 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
803 | } | |
804 | ||
805 | /** | |
806 | * _scsih_device_remove_by_handle - removing device object by handle | |
807 | * @ioc: per adapter object | |
808 | * @handle: device handle | |
809 | * | |
810 | * Return nothing. | |
811 | */ | |
812 | static void | |
813 | _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
814 | { | |
815 | struct _sas_device *sas_device; | |
816 | unsigned long flags; | |
817 | ||
818 | if (ioc->shost_recovery) | |
819 | return; | |
820 | ||
821 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 SR |
822 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
823 | if (sas_device) { | |
824 | list_del_init(&sas_device->list); | |
825 | sas_device_put(sas_device); | |
826 | } | |
f92363d1 | 827 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
d1cb5e49 | 828 | if (sas_device) { |
f92363d1 | 829 | _scsih_remove_device(ioc, sas_device); |
d1cb5e49 SR |
830 | sas_device_put(sas_device); |
831 | } | |
f92363d1 SR |
832 | } |
833 | ||
834 | /** | |
835 | * mpt3sas_device_remove_by_sas_address - removing device object by sas address | |
836 | * @ioc: per adapter object | |
837 | * @sas_address: device sas_address | |
838 | * | |
839 | * Return nothing. | |
840 | */ | |
841 | void | |
842 | mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER *ioc, | |
843 | u64 sas_address) | |
844 | { | |
845 | struct _sas_device *sas_device; | |
846 | unsigned long flags; | |
847 | ||
848 | if (ioc->shost_recovery) | |
849 | return; | |
850 | ||
851 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 SR |
852 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, sas_address); |
853 | if (sas_device) { | |
854 | list_del_init(&sas_device->list); | |
855 | sas_device_put(sas_device); | |
856 | } | |
f92363d1 | 857 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
d1cb5e49 | 858 | if (sas_device) { |
f92363d1 | 859 | _scsih_remove_device(ioc, sas_device); |
d1cb5e49 SR |
860 | sas_device_put(sas_device); |
861 | } | |
f92363d1 SR |
862 | } |
863 | ||
864 | /** | |
865 | * _scsih_sas_device_add - insert sas_device to the list. | |
866 | * @ioc: per adapter object | |
867 | * @sas_device: the sas_device object | |
868 | * Context: This function will acquire ioc->sas_device_lock. | |
869 | * | |
870 | * Adding new object to the ioc->sas_device_list. | |
871 | */ | |
872 | static void | |
873 | _scsih_sas_device_add(struct MPT3SAS_ADAPTER *ioc, | |
874 | struct _sas_device *sas_device) | |
875 | { | |
876 | unsigned long flags; | |
877 | ||
878 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
879 | "%s: handle(0x%04x), sas_addr(0x%016llx)\n", | |
880 | ioc->name, __func__, sas_device->handle, | |
881 | (unsigned long long)sas_device->sas_address)); | |
882 | ||
75888956 SR |
883 | dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device, |
884 | NULL, NULL)); | |
e6d45e3e | 885 | |
f92363d1 | 886 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 887 | sas_device_get(sas_device); |
f92363d1 SR |
888 | list_add_tail(&sas_device->list, &ioc->sas_device_list); |
889 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
890 | ||
c696f7b8 SPS |
891 | if (ioc->hide_drives) { |
892 | clear_bit(sas_device->handle, ioc->pend_os_device_add); | |
893 | return; | |
894 | } | |
895 | ||
f92363d1 SR |
896 | if (!mpt3sas_transport_port_add(ioc, sas_device->handle, |
897 | sas_device->sas_address_parent)) { | |
898 | _scsih_sas_device_remove(ioc, sas_device); | |
899 | } else if (!sas_device->starget) { | |
900 | /* | |
901 | * When asyn scanning is enabled, its not possible to remove | |
902 | * devices while scanning is turned on due to an oops in | |
903 | * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start() | |
904 | */ | |
f5edbe77 | 905 | if (!ioc->is_driver_loading) { |
f92363d1 SR |
906 | mpt3sas_transport_port_remove(ioc, |
907 | sas_device->sas_address, | |
908 | sas_device->sas_address_parent); | |
f5edbe77 SR |
909 | _scsih_sas_device_remove(ioc, sas_device); |
910 | } | |
c696f7b8 SPS |
911 | } else |
912 | clear_bit(sas_device->handle, ioc->pend_os_device_add); | |
f92363d1 SR |
913 | } |
914 | ||
915 | /** | |
916 | * _scsih_sas_device_init_add - insert sas_device to the list. | |
917 | * @ioc: per adapter object | |
918 | * @sas_device: the sas_device object | |
919 | * Context: This function will acquire ioc->sas_device_lock. | |
920 | * | |
921 | * Adding new object at driver load time to the ioc->sas_device_init_list. | |
922 | */ | |
923 | static void | |
924 | _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER *ioc, | |
925 | struct _sas_device *sas_device) | |
926 | { | |
927 | unsigned long flags; | |
928 | ||
929 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
930 | "%s: handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
931 | __func__, sas_device->handle, | |
932 | (unsigned long long)sas_device->sas_address)); | |
933 | ||
75888956 SR |
934 | dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device, |
935 | NULL, NULL)); | |
e6d45e3e | 936 | |
f92363d1 | 937 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 938 | sas_device_get(sas_device); |
f92363d1 SR |
939 | list_add_tail(&sas_device->list, &ioc->sas_device_init_list); |
940 | _scsih_determine_boot_device(ioc, sas_device, 0); | |
941 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
942 | } | |
943 | ||
d88e1eab | 944 | |
494f401b | 945 | static struct _pcie_device * |
d88e1eab SPS |
946 | __mpt3sas_get_pdev_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid) |
947 | { | |
948 | struct _pcie_device *pcie_device; | |
949 | ||
950 | assert_spin_locked(&ioc->pcie_device_lock); | |
951 | ||
952 | list_for_each_entry(pcie_device, &ioc->pcie_device_list, list) | |
953 | if (pcie_device->wwid == wwid) | |
954 | goto found_device; | |
955 | ||
956 | list_for_each_entry(pcie_device, &ioc->pcie_device_init_list, list) | |
957 | if (pcie_device->wwid == wwid) | |
958 | goto found_device; | |
959 | ||
960 | return NULL; | |
961 | ||
962 | found_device: | |
963 | pcie_device_get(pcie_device); | |
964 | return pcie_device; | |
965 | } | |
966 | ||
967 | ||
968 | /** | |
969 | * mpt3sas_get_pdev_by_wwid - pcie device search | |
970 | * @ioc: per adapter object | |
971 | * @wwid: wwid | |
972 | * | |
973 | * Context: This function will acquire ioc->pcie_device_lock and will release | |
974 | * before returning the pcie_device object. | |
975 | * | |
976 | * This searches for pcie_device based on wwid, then return pcie_device object. | |
977 | */ | |
494f401b | 978 | static struct _pcie_device * |
d88e1eab SPS |
979 | mpt3sas_get_pdev_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid) |
980 | { | |
981 | struct _pcie_device *pcie_device; | |
982 | unsigned long flags; | |
983 | ||
984 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
985 | pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid); | |
986 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
987 | ||
988 | return pcie_device; | |
989 | } | |
990 | ||
991 | ||
494f401b | 992 | static struct _pcie_device * |
d88e1eab SPS |
993 | __mpt3sas_get_pdev_by_idchannel(struct MPT3SAS_ADAPTER *ioc, int id, |
994 | int channel) | |
995 | { | |
996 | struct _pcie_device *pcie_device; | |
997 | ||
998 | assert_spin_locked(&ioc->pcie_device_lock); | |
999 | ||
1000 | list_for_each_entry(pcie_device, &ioc->pcie_device_list, list) | |
1001 | if (pcie_device->id == id && pcie_device->channel == channel) | |
1002 | goto found_device; | |
1003 | ||
1004 | list_for_each_entry(pcie_device, &ioc->pcie_device_init_list, list) | |
1005 | if (pcie_device->id == id && pcie_device->channel == channel) | |
1006 | goto found_device; | |
1007 | ||
1008 | return NULL; | |
1009 | ||
1010 | found_device: | |
1011 | pcie_device_get(pcie_device); | |
1012 | return pcie_device; | |
1013 | } | |
1014 | ||
494f401b | 1015 | static struct _pcie_device * |
c102e00c SPS |
1016 | __mpt3sas_get_pdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
1017 | { | |
1018 | struct _pcie_device *pcie_device; | |
1019 | ||
1020 | assert_spin_locked(&ioc->pcie_device_lock); | |
1021 | ||
1022 | list_for_each_entry(pcie_device, &ioc->pcie_device_list, list) | |
1023 | if (pcie_device->handle == handle) | |
1024 | goto found_device; | |
1025 | ||
1026 | list_for_each_entry(pcie_device, &ioc->pcie_device_init_list, list) | |
1027 | if (pcie_device->handle == handle) | |
1028 | goto found_device; | |
1029 | ||
1030 | return NULL; | |
1031 | ||
1032 | found_device: | |
1033 | pcie_device_get(pcie_device); | |
1034 | return pcie_device; | |
1035 | } | |
1036 | ||
1037 | ||
1038 | /** | |
1039 | * mpt3sas_get_pdev_by_handle - pcie device search | |
1040 | * @ioc: per adapter object | |
1041 | * @handle: Firmware device handle | |
1042 | * | |
1043 | * Context: This function will acquire ioc->pcie_device_lock and will release | |
1044 | * before returning the pcie_device object. | |
1045 | * | |
1046 | * This searches for pcie_device based on handle, then return pcie_device | |
1047 | * object. | |
1048 | */ | |
1049 | struct _pcie_device * | |
1050 | mpt3sas_get_pdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
1051 | { | |
1052 | struct _pcie_device *pcie_device; | |
1053 | unsigned long flags; | |
1054 | ||
1055 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1056 | pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle); | |
1057 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1058 | ||
1059 | return pcie_device; | |
1060 | } | |
1061 | ||
d88e1eab SPS |
1062 | /** |
1063 | * _scsih_pcie_device_remove - remove pcie_device from list. | |
1064 | * @ioc: per adapter object | |
1065 | * @pcie_device: the pcie_device object | |
1066 | * Context: This function will acquire ioc->pcie_device_lock. | |
1067 | * | |
1068 | * If pcie_device is on the list, remove it and decrement its reference count. | |
1069 | */ | |
1070 | static void | |
1071 | _scsih_pcie_device_remove(struct MPT3SAS_ADAPTER *ioc, | |
1072 | struct _pcie_device *pcie_device) | |
1073 | { | |
1074 | unsigned long flags; | |
1075 | int was_on_pcie_device_list = 0; | |
1076 | ||
1077 | if (!pcie_device) | |
1078 | return; | |
1079 | pr_info(MPT3SAS_FMT | |
1080 | "removing handle(0x%04x), wwid(0x%016llx)\n", | |
1081 | ioc->name, pcie_device->handle, | |
1082 | (unsigned long long) pcie_device->wwid); | |
1083 | if (pcie_device->enclosure_handle != 0) | |
1084 | pr_info(MPT3SAS_FMT | |
1085 | "removing enclosure logical id(0x%016llx), slot(%d)\n", | |
1086 | ioc->name, | |
1087 | (unsigned long long)pcie_device->enclosure_logical_id, | |
1088 | pcie_device->slot); | |
1089 | if (pcie_device->connector_name[0] != '\0') | |
1090 | pr_info(MPT3SAS_FMT | |
1091 | "removing enclosure level(0x%04x), connector name( %s)\n", | |
1092 | ioc->name, pcie_device->enclosure_level, | |
1093 | pcie_device->connector_name); | |
1094 | ||
1095 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1096 | if (!list_empty(&pcie_device->list)) { | |
1097 | list_del_init(&pcie_device->list); | |
1098 | was_on_pcie_device_list = 1; | |
1099 | } | |
1100 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1101 | if (was_on_pcie_device_list) { | |
1102 | kfree(pcie_device->serial_number); | |
1103 | pcie_device_put(pcie_device); | |
1104 | } | |
1105 | } | |
3075ac49 SPS |
1106 | |
1107 | ||
1108 | /** | |
1109 | * _scsih_pcie_device_remove_by_handle - removing pcie device object by handle | |
1110 | * @ioc: per adapter object | |
1111 | * @handle: device handle | |
1112 | * | |
1113 | * Return nothing. | |
1114 | */ | |
1115 | static void | |
1116 | _scsih_pcie_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
1117 | { | |
1118 | struct _pcie_device *pcie_device; | |
1119 | unsigned long flags; | |
1120 | int was_on_pcie_device_list = 0; | |
1121 | ||
1122 | if (ioc->shost_recovery) | |
1123 | return; | |
1124 | ||
1125 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1126 | pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle); | |
1127 | if (pcie_device) { | |
1128 | if (!list_empty(&pcie_device->list)) { | |
1129 | list_del_init(&pcie_device->list); | |
1130 | was_on_pcie_device_list = 1; | |
1131 | pcie_device_put(pcie_device); | |
1132 | } | |
1133 | } | |
1134 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1135 | if (was_on_pcie_device_list) { | |
1136 | _scsih_pcie_device_remove_from_sml(ioc, pcie_device); | |
1137 | pcie_device_put(pcie_device); | |
1138 | } | |
1139 | } | |
1140 | ||
c102e00c SPS |
1141 | /** |
1142 | * _scsih_pcie_device_add - add pcie_device object | |
1143 | * @ioc: per adapter object | |
1144 | * @pcie_device: pcie_device object | |
1145 | * | |
1146 | * This is added to the pcie_device_list link list. | |
1147 | */ | |
1148 | static void | |
1149 | _scsih_pcie_device_add(struct MPT3SAS_ADAPTER *ioc, | |
1150 | struct _pcie_device *pcie_device) | |
1151 | { | |
1152 | unsigned long flags; | |
1153 | ||
1154 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
1155 | "%s: handle (0x%04x), wwid(0x%016llx)\n", ioc->name, __func__, | |
1156 | pcie_device->handle, (unsigned long long)pcie_device->wwid)); | |
1157 | if (pcie_device->enclosure_handle != 0) | |
1158 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
1159 | "%s: enclosure logical id(0x%016llx), slot( %d)\n", | |
1160 | ioc->name, __func__, | |
1161 | (unsigned long long)pcie_device->enclosure_logical_id, | |
1162 | pcie_device->slot)); | |
1163 | if (pcie_device->connector_name[0] != '\0') | |
1164 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
1165 | "%s: enclosure level(0x%04x), connector name( %s)\n", | |
1166 | ioc->name, __func__, pcie_device->enclosure_level, | |
1167 | pcie_device->connector_name)); | |
1168 | ||
1169 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1170 | pcie_device_get(pcie_device); | |
1171 | list_add_tail(&pcie_device->list, &ioc->pcie_device_list); | |
1172 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1173 | ||
1174 | if (scsi_add_device(ioc->shost, PCIE_CHANNEL, pcie_device->id, 0)) { | |
1175 | _scsih_pcie_device_remove(ioc, pcie_device); | |
1176 | } else if (!pcie_device->starget) { | |
1177 | if (!ioc->is_driver_loading) { | |
1178 | /*TODO-- Need to find out whether this condition will occur or not*/ | |
1179 | clear_bit(pcie_device->handle, ioc->pend_os_device_add); | |
1180 | } | |
1181 | } else | |
1182 | clear_bit(pcie_device->handle, ioc->pend_os_device_add); | |
1183 | } | |
1184 | ||
1185 | /* | |
1186 | * _scsih_pcie_device_init_add - insert pcie_device to the init list. | |
1187 | * @ioc: per adapter object | |
1188 | * @pcie_device: the pcie_device object | |
1189 | * Context: This function will acquire ioc->pcie_device_lock. | |
1190 | * | |
1191 | * Adding new object at driver load time to the ioc->pcie_device_init_list. | |
1192 | */ | |
1193 | static void | |
1194 | _scsih_pcie_device_init_add(struct MPT3SAS_ADAPTER *ioc, | |
1195 | struct _pcie_device *pcie_device) | |
1196 | { | |
1197 | unsigned long flags; | |
1198 | ||
1199 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
1200 | "%s: handle (0x%04x), wwid(0x%016llx)\n", ioc->name, __func__, | |
1201 | pcie_device->handle, (unsigned long long)pcie_device->wwid)); | |
1202 | if (pcie_device->enclosure_handle != 0) | |
1203 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
1204 | "%s: enclosure logical id(0x%016llx), slot( %d)\n", | |
1205 | ioc->name, __func__, | |
1206 | (unsigned long long)pcie_device->enclosure_logical_id, | |
1207 | pcie_device->slot)); | |
1208 | if (pcie_device->connector_name[0] != '\0') | |
1209 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
1210 | "%s: enclosure level(0x%04x), connector name( %s)\n", | |
1211 | ioc->name, __func__, pcie_device->enclosure_level, | |
1212 | pcie_device->connector_name)); | |
1213 | ||
1214 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1215 | pcie_device_get(pcie_device); | |
1216 | list_add_tail(&pcie_device->list, &ioc->pcie_device_init_list); | |
1217 | _scsih_determine_boot_device(ioc, pcie_device, PCIE_CHANNEL); | |
1218 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1219 | } | |
f92363d1 SR |
1220 | /** |
1221 | * _scsih_raid_device_find_by_id - raid device search | |
1222 | * @ioc: per adapter object | |
1223 | * @id: sas device target id | |
1224 | * @channel: sas device channel | |
1225 | * Context: Calling function should acquire ioc->raid_device_lock | |
1226 | * | |
1227 | * This searches for raid_device based on target id, then return raid_device | |
1228 | * object. | |
1229 | */ | |
1230 | static struct _raid_device * | |
1231 | _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER *ioc, int id, int channel) | |
1232 | { | |
1233 | struct _raid_device *raid_device, *r; | |
1234 | ||
1235 | r = NULL; | |
1236 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
1237 | if (raid_device->id == id && raid_device->channel == channel) { | |
1238 | r = raid_device; | |
1239 | goto out; | |
1240 | } | |
1241 | } | |
1242 | ||
1243 | out: | |
1244 | return r; | |
1245 | } | |
1246 | ||
1247 | /** | |
c84b06a4 | 1248 | * mpt3sas_raid_device_find_by_handle - raid device search |
f92363d1 SR |
1249 | * @ioc: per adapter object |
1250 | * @handle: sas device handle (assigned by firmware) | |
1251 | * Context: Calling function should acquire ioc->raid_device_lock | |
1252 | * | |
1253 | * This searches for raid_device based on handle, then return raid_device | |
1254 | * object. | |
1255 | */ | |
c84b06a4 SR |
1256 | struct _raid_device * |
1257 | mpt3sas_raid_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
f92363d1 SR |
1258 | { |
1259 | struct _raid_device *raid_device, *r; | |
1260 | ||
1261 | r = NULL; | |
1262 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
1263 | if (raid_device->handle != handle) | |
1264 | continue; | |
1265 | r = raid_device; | |
1266 | goto out; | |
1267 | } | |
1268 | ||
1269 | out: | |
1270 | return r; | |
1271 | } | |
1272 | ||
1273 | /** | |
1274 | * _scsih_raid_device_find_by_wwid - raid device search | |
1275 | * @ioc: per adapter object | |
1276 | * @handle: sas device handle (assigned by firmware) | |
1277 | * Context: Calling function should acquire ioc->raid_device_lock | |
1278 | * | |
1279 | * This searches for raid_device based on wwid, then return raid_device | |
1280 | * object. | |
1281 | */ | |
1282 | static struct _raid_device * | |
1283 | _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid) | |
1284 | { | |
1285 | struct _raid_device *raid_device, *r; | |
1286 | ||
1287 | r = NULL; | |
1288 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
1289 | if (raid_device->wwid != wwid) | |
1290 | continue; | |
1291 | r = raid_device; | |
1292 | goto out; | |
1293 | } | |
1294 | ||
1295 | out: | |
1296 | return r; | |
1297 | } | |
1298 | ||
1299 | /** | |
1300 | * _scsih_raid_device_add - add raid_device object | |
1301 | * @ioc: per adapter object | |
1302 | * @raid_device: raid_device object | |
1303 | * | |
1304 | * This is added to the raid_device_list link list. | |
1305 | */ | |
1306 | static void | |
1307 | _scsih_raid_device_add(struct MPT3SAS_ADAPTER *ioc, | |
1308 | struct _raid_device *raid_device) | |
1309 | { | |
1310 | unsigned long flags; | |
1311 | ||
1312 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
1313 | "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__, | |
1314 | raid_device->handle, (unsigned long long)raid_device->wwid)); | |
1315 | ||
1316 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1317 | list_add_tail(&raid_device->list, &ioc->raid_device_list); | |
1318 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1319 | } | |
1320 | ||
1321 | /** | |
1322 | * _scsih_raid_device_remove - delete raid_device object | |
1323 | * @ioc: per adapter object | |
1324 | * @raid_device: raid_device object | |
1325 | * | |
1326 | */ | |
1327 | static void | |
1328 | _scsih_raid_device_remove(struct MPT3SAS_ADAPTER *ioc, | |
1329 | struct _raid_device *raid_device) | |
1330 | { | |
1331 | unsigned long flags; | |
1332 | ||
1333 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1334 | list_del(&raid_device->list); | |
1335 | kfree(raid_device); | |
1336 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1337 | } | |
1338 | ||
1339 | /** | |
1340 | * mpt3sas_scsih_expander_find_by_handle - expander device search | |
1341 | * @ioc: per adapter object | |
1342 | * @handle: expander handle (assigned by firmware) | |
1343 | * Context: Calling function should acquire ioc->sas_device_lock | |
1344 | * | |
1345 | * This searches for expander device based on handle, then returns the | |
1346 | * sas_node object. | |
1347 | */ | |
1348 | struct _sas_node * | |
1349 | mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
1350 | { | |
1351 | struct _sas_node *sas_expander, *r; | |
1352 | ||
1353 | r = NULL; | |
1354 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { | |
1355 | if (sas_expander->handle != handle) | |
1356 | continue; | |
1357 | r = sas_expander; | |
1358 | goto out; | |
1359 | } | |
1360 | out: | |
1361 | return r; | |
1362 | } | |
1363 | ||
1364 | /** | |
1365 | * mpt3sas_scsih_expander_find_by_sas_address - expander device search | |
1366 | * @ioc: per adapter object | |
1367 | * @sas_address: sas address | |
1368 | * Context: Calling function should acquire ioc->sas_node_lock. | |
1369 | * | |
1370 | * This searches for expander device based on sas_address, then returns the | |
1371 | * sas_node object. | |
1372 | */ | |
1373 | struct _sas_node * | |
1374 | mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc, | |
1375 | u64 sas_address) | |
1376 | { | |
1377 | struct _sas_node *sas_expander, *r; | |
1378 | ||
1379 | r = NULL; | |
1380 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { | |
1381 | if (sas_expander->sas_address != sas_address) | |
1382 | continue; | |
1383 | r = sas_expander; | |
1384 | goto out; | |
1385 | } | |
1386 | out: | |
1387 | return r; | |
1388 | } | |
1389 | ||
1390 | /** | |
1391 | * _scsih_expander_node_add - insert expander device to the list. | |
1392 | * @ioc: per adapter object | |
1393 | * @sas_expander: the sas_device object | |
1394 | * Context: This function will acquire ioc->sas_node_lock. | |
1395 | * | |
1396 | * Adding new object to the ioc->sas_expander_list. | |
1397 | * | |
1398 | * Return nothing. | |
1399 | */ | |
1400 | static void | |
1401 | _scsih_expander_node_add(struct MPT3SAS_ADAPTER *ioc, | |
1402 | struct _sas_node *sas_expander) | |
1403 | { | |
1404 | unsigned long flags; | |
1405 | ||
1406 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
1407 | list_add_tail(&sas_expander->list, &ioc->sas_expander_list); | |
1408 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
1409 | } | |
1410 | ||
1411 | /** | |
1412 | * _scsih_is_end_device - determines if device is an end device | |
1413 | * @device_info: bitfield providing information about the device. | |
1414 | * Context: none | |
1415 | * | |
1416 | * Returns 1 if end device. | |
1417 | */ | |
1418 | static int | |
1419 | _scsih_is_end_device(u32 device_info) | |
1420 | { | |
1421 | if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE && | |
1422 | ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) | | |
1423 | (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) | | |
1424 | (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE))) | |
1425 | return 1; | |
1426 | else | |
1427 | return 0; | |
1428 | } | |
1429 | ||
c102e00c SPS |
1430 | /** |
1431 | * _scsih_is_nvme_device - determines if device is an nvme device | |
1432 | * @device_info: bitfield providing information about the device. | |
1433 | * Context: none | |
1434 | * | |
1435 | * Returns 1 if nvme device. | |
1436 | */ | |
1437 | static int | |
1438 | _scsih_is_nvme_device(u32 device_info) | |
1439 | { | |
1440 | if ((device_info & MPI26_PCIE_DEVINFO_MASK_DEVICE_TYPE) | |
1441 | == MPI26_PCIE_DEVINFO_NVME) | |
1442 | return 1; | |
1443 | else | |
1444 | return 0; | |
1445 | } | |
1446 | ||
459325c4 C |
1447 | /** |
1448 | * __scsih_scsi_lookup_get_clear - returns scmd entry without | |
1449 | * holding any lock. | |
1450 | * @ioc: per adapter object | |
1451 | * @smid: system request message index | |
1452 | * | |
1453 | * Returns the smid stored scmd pointer. | |
1454 | * Then will dereference the stored scmd pointer. | |
1455 | */ | |
1456 | static inline struct scsi_cmnd * | |
1457 | __scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER *ioc, | |
1458 | u16 smid) | |
1459 | { | |
1460 | struct scsi_cmnd *scmd = NULL; | |
1461 | ||
1462 | swap(scmd, ioc->scsi_lookup[smid - 1].scmd); | |
1463 | ||
1464 | return scmd; | |
1465 | } | |
1466 | ||
f92363d1 SR |
1467 | /** |
1468 | * _scsih_scsi_lookup_get_clear - returns scmd entry | |
1469 | * @ioc: per adapter object | |
1470 | * @smid: system request message index | |
1471 | * | |
1472 | * Returns the smid stored scmd pointer. | |
1473 | * Then will derefrence the stored scmd pointer. | |
1474 | */ | |
1475 | static inline struct scsi_cmnd * | |
1476 | _scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER *ioc, u16 smid) | |
1477 | { | |
1478 | unsigned long flags; | |
1479 | struct scsi_cmnd *scmd; | |
1480 | ||
1481 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
459325c4 | 1482 | scmd = __scsih_scsi_lookup_get_clear(ioc, smid); |
f92363d1 SR |
1483 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
1484 | ||
1485 | return scmd; | |
1486 | } | |
1487 | ||
1488 | /** | |
1489 | * _scsih_scsi_lookup_find_by_scmd - scmd lookup | |
1490 | * @ioc: per adapter object | |
1491 | * @smid: system request message index | |
1492 | * @scmd: pointer to scsi command object | |
1493 | * Context: This function will acquire ioc->scsi_lookup_lock. | |
1494 | * | |
1495 | * This will search for a scmd pointer in the scsi_lookup array, | |
1496 | * returning the revelent smid. A returned value of zero means invalid. | |
1497 | */ | |
6da999fe | 1498 | struct scsiio_tracker * |
f92363d1 SR |
1499 | _scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd |
1500 | *scmd) | |
1501 | { | |
6da999fe HR |
1502 | struct scsiio_tracker *st = NULL; |
1503 | unsigned long flags; | |
f92363d1 SR |
1504 | int i; |
1505 | ||
1506 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
f92363d1 SR |
1507 | for (i = 0; i < ioc->scsiio_depth; i++) { |
1508 | if (ioc->scsi_lookup[i].scmd == scmd) { | |
6da999fe | 1509 | st = &ioc->scsi_lookup[i]; |
f92363d1 SR |
1510 | goto out; |
1511 | } | |
1512 | } | |
1513 | out: | |
1514 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
6da999fe | 1515 | return st; |
f92363d1 SR |
1516 | } |
1517 | ||
cf75d5d6 | 1518 | /** |
8a7e4c24 | 1519 | * scsih_change_queue_depth - setting device queue depth |
cf75d5d6 CH |
1520 | * @sdev: scsi device struct |
1521 | * @qdepth: requested queue depth | |
1522 | * | |
1523 | * Returns queue depth. | |
1524 | */ | |
8bbb1cf6 | 1525 | static int |
8a7e4c24 | 1526 | scsih_change_queue_depth(struct scsi_device *sdev, int qdepth) |
f92363d1 SR |
1527 | { |
1528 | struct Scsi_Host *shost = sdev->host; | |
1529 | int max_depth; | |
1530 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
1531 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
1532 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1533 | struct _sas_device *sas_device; | |
1534 | unsigned long flags; | |
1535 | ||
1536 | max_depth = shost->can_queue; | |
1537 | ||
1538 | /* limit max device queue for SATA to 32 */ | |
1539 | sas_device_priv_data = sdev->hostdata; | |
1540 | if (!sas_device_priv_data) | |
1541 | goto not_sata; | |
1542 | sas_target_priv_data = sas_device_priv_data->sas_target; | |
1543 | if (!sas_target_priv_data) | |
1544 | goto not_sata; | |
1545 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) | |
1546 | goto not_sata; | |
d1cb5e49 | 1547 | |
f92363d1 | 1548 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 SR |
1549 | sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data); |
1550 | if (sas_device) { | |
1551 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE) | |
1552 | max_depth = MPT3SAS_SATA_QUEUE_DEPTH; | |
1553 | ||
1554 | sas_device_put(sas_device); | |
1555 | } | |
f92363d1 SR |
1556 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
1557 | ||
1558 | not_sata: | |
1559 | ||
1560 | if (!sdev->tagged_supported) | |
1561 | max_depth = 1; | |
1562 | if (qdepth > max_depth) | |
1563 | qdepth = max_depth; | |
cf75d5d6 | 1564 | return scsi_change_queue_depth(sdev, qdepth); |
f92363d1 SR |
1565 | } |
1566 | ||
f92363d1 | 1567 | /** |
8a7e4c24 | 1568 | * scsih_target_alloc - target add routine |
f92363d1 SR |
1569 | * @starget: scsi target struct |
1570 | * | |
1571 | * Returns 0 if ok. Any other return is assumed to be an error and | |
1572 | * the device is ignored. | |
1573 | */ | |
8bbb1cf6 | 1574 | static int |
8a7e4c24 | 1575 | scsih_target_alloc(struct scsi_target *starget) |
f92363d1 SR |
1576 | { |
1577 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); | |
1578 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
1579 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1580 | struct _sas_device *sas_device; | |
1581 | struct _raid_device *raid_device; | |
d88e1eab | 1582 | struct _pcie_device *pcie_device; |
f92363d1 SR |
1583 | unsigned long flags; |
1584 | struct sas_rphy *rphy; | |
1585 | ||
62c4da44 JL |
1586 | sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data), |
1587 | GFP_KERNEL); | |
f92363d1 SR |
1588 | if (!sas_target_priv_data) |
1589 | return -ENOMEM; | |
1590 | ||
1591 | starget->hostdata = sas_target_priv_data; | |
1592 | sas_target_priv_data->starget = starget; | |
1593 | sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE; | |
1594 | ||
1595 | /* RAID volumes */ | |
1596 | if (starget->channel == RAID_CHANNEL) { | |
1597 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1598 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, | |
1599 | starget->channel); | |
1600 | if (raid_device) { | |
1601 | sas_target_priv_data->handle = raid_device->handle; | |
1602 | sas_target_priv_data->sas_address = raid_device->wwid; | |
1603 | sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME; | |
7786ab6a | 1604 | if (ioc->is_warpdrive) |
6d3a56ed SR |
1605 | sas_target_priv_data->raid_device = raid_device; |
1606 | raid_device->starget = starget; | |
f92363d1 SR |
1607 | } |
1608 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1609 | return 0; | |
1610 | } | |
1611 | ||
d88e1eab SPS |
1612 | /* PCIe devices */ |
1613 | if (starget->channel == PCIE_CHANNEL) { | |
1614 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1615 | pcie_device = __mpt3sas_get_pdev_by_idchannel(ioc, starget->id, | |
1616 | starget->channel); | |
1617 | if (pcie_device) { | |
1618 | sas_target_priv_data->handle = pcie_device->handle; | |
1619 | sas_target_priv_data->sas_address = pcie_device->wwid; | |
1620 | sas_target_priv_data->pcie_dev = pcie_device; | |
1621 | pcie_device->starget = starget; | |
1622 | pcie_device->id = starget->id; | |
1623 | pcie_device->channel = starget->channel; | |
1624 | sas_target_priv_data->flags |= | |
1625 | MPT_TARGET_FLAGS_PCIE_DEVICE; | |
1626 | if (pcie_device->fast_path) | |
1627 | sas_target_priv_data->flags |= | |
1628 | MPT_TARGET_FASTPATH_IO; | |
1629 | } | |
1630 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1631 | return 0; | |
1632 | } | |
1633 | ||
f92363d1 SR |
1634 | /* sas/sata devices */ |
1635 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
1636 | rphy = dev_to_rphy(starget->dev.parent); | |
d1cb5e49 | 1637 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 SR |
1638 | rphy->identify.sas_address); |
1639 | ||
1640 | if (sas_device) { | |
1641 | sas_target_priv_data->handle = sas_device->handle; | |
1642 | sas_target_priv_data->sas_address = sas_device->sas_address; | |
d88e1eab | 1643 | sas_target_priv_data->sas_dev = sas_device; |
f92363d1 SR |
1644 | sas_device->starget = starget; |
1645 | sas_device->id = starget->id; | |
1646 | sas_device->channel = starget->channel; | |
1647 | if (test_bit(sas_device->handle, ioc->pd_handles)) | |
1648 | sas_target_priv_data->flags |= | |
1649 | MPT_TARGET_FLAGS_RAID_COMPONENT; | |
1650 | if (sas_device->fast_path) | |
d88e1eab SPS |
1651 | sas_target_priv_data->flags |= |
1652 | MPT_TARGET_FASTPATH_IO; | |
f92363d1 SR |
1653 | } |
1654 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
1655 | ||
1656 | return 0; | |
1657 | } | |
1658 | ||
1659 | /** | |
8a7e4c24 | 1660 | * scsih_target_destroy - target destroy routine |
f92363d1 SR |
1661 | * @starget: scsi target struct |
1662 | * | |
1663 | * Returns nothing. | |
1664 | */ | |
8bbb1cf6 | 1665 | static void |
8a7e4c24 | 1666 | scsih_target_destroy(struct scsi_target *starget) |
f92363d1 SR |
1667 | { |
1668 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); | |
1669 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
1670 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1671 | struct _sas_device *sas_device; | |
1672 | struct _raid_device *raid_device; | |
d88e1eab | 1673 | struct _pcie_device *pcie_device; |
f92363d1 | 1674 | unsigned long flags; |
d88e1eab | 1675 | struct sas_rphy *rphy; |
f92363d1 SR |
1676 | |
1677 | sas_target_priv_data = starget->hostdata; | |
1678 | if (!sas_target_priv_data) | |
1679 | return; | |
1680 | ||
1681 | if (starget->channel == RAID_CHANNEL) { | |
1682 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1683 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, | |
1684 | starget->channel); | |
1685 | if (raid_device) { | |
1686 | raid_device->starget = NULL; | |
1687 | raid_device->sdev = NULL; | |
1688 | } | |
1689 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1690 | goto out; | |
1691 | } | |
1692 | ||
d88e1eab SPS |
1693 | if (starget->channel == PCIE_CHANNEL) { |
1694 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1695 | pcie_device = __mpt3sas_get_pdev_from_target(ioc, | |
1696 | sas_target_priv_data); | |
1697 | if (pcie_device && (pcie_device->starget == starget) && | |
1698 | (pcie_device->id == starget->id) && | |
1699 | (pcie_device->channel == starget->channel)) | |
1700 | pcie_device->starget = NULL; | |
1701 | ||
1702 | if (pcie_device) { | |
1703 | /* | |
1704 | * Corresponding get() is in _scsih_target_alloc() | |
1705 | */ | |
1706 | sas_target_priv_data->pcie_dev = NULL; | |
1707 | pcie_device_put(pcie_device); | |
1708 | pcie_device_put(pcie_device); | |
1709 | } | |
1710 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1711 | goto out; | |
1712 | } | |
1713 | ||
f92363d1 | 1714 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d88e1eab | 1715 | rphy = dev_to_rphy(starget->dev.parent); |
d1cb5e49 | 1716 | sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data); |
f92363d1 SR |
1717 | if (sas_device && (sas_device->starget == starget) && |
1718 | (sas_device->id == starget->id) && | |
1719 | (sas_device->channel == starget->channel)) | |
1720 | sas_device->starget = NULL; | |
1721 | ||
d1cb5e49 SR |
1722 | if (sas_device) { |
1723 | /* | |
1724 | * Corresponding get() is in _scsih_target_alloc() | |
1725 | */ | |
d88e1eab | 1726 | sas_target_priv_data->sas_dev = NULL; |
d1cb5e49 SR |
1727 | sas_device_put(sas_device); |
1728 | ||
1729 | sas_device_put(sas_device); | |
1730 | } | |
f92363d1 SR |
1731 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
1732 | ||
1733 | out: | |
1734 | kfree(sas_target_priv_data); | |
1735 | starget->hostdata = NULL; | |
1736 | } | |
1737 | ||
1738 | /** | |
8a7e4c24 | 1739 | * scsih_slave_alloc - device add routine |
f92363d1 SR |
1740 | * @sdev: scsi device struct |
1741 | * | |
1742 | * Returns 0 if ok. Any other return is assumed to be an error and | |
1743 | * the device is ignored. | |
1744 | */ | |
8bbb1cf6 | 1745 | static int |
8a7e4c24 | 1746 | scsih_slave_alloc(struct scsi_device *sdev) |
f92363d1 SR |
1747 | { |
1748 | struct Scsi_Host *shost; | |
1749 | struct MPT3SAS_ADAPTER *ioc; | |
1750 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1751 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
1752 | struct scsi_target *starget; | |
1753 | struct _raid_device *raid_device; | |
b65cfedf | 1754 | struct _sas_device *sas_device; |
d88e1eab | 1755 | struct _pcie_device *pcie_device; |
f92363d1 SR |
1756 | unsigned long flags; |
1757 | ||
62c4da44 JL |
1758 | sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data), |
1759 | GFP_KERNEL); | |
f92363d1 SR |
1760 | if (!sas_device_priv_data) |
1761 | return -ENOMEM; | |
1762 | ||
1763 | sas_device_priv_data->lun = sdev->lun; | |
1764 | sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT; | |
1765 | ||
1766 | starget = scsi_target(sdev); | |
1767 | sas_target_priv_data = starget->hostdata; | |
1768 | sas_target_priv_data->num_luns++; | |
1769 | sas_device_priv_data->sas_target = sas_target_priv_data; | |
1770 | sdev->hostdata = sas_device_priv_data; | |
1771 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT)) | |
1772 | sdev->no_uld_attach = 1; | |
1773 | ||
1774 | shost = dev_to_shost(&starget->dev); | |
1775 | ioc = shost_priv(shost); | |
1776 | if (starget->channel == RAID_CHANNEL) { | |
1777 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1778 | raid_device = _scsih_raid_device_find_by_id(ioc, | |
1779 | starget->id, starget->channel); | |
1780 | if (raid_device) | |
1781 | raid_device->sdev = sdev; /* raid is single lun */ | |
1782 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1783 | } | |
d88e1eab SPS |
1784 | if (starget->channel == PCIE_CHANNEL) { |
1785 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1786 | pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, | |
1787 | sas_target_priv_data->sas_address); | |
1788 | if (pcie_device && (pcie_device->starget == NULL)) { | |
1789 | sdev_printk(KERN_INFO, sdev, | |
1790 | "%s : pcie_device->starget set to starget @ %d\n", | |
1791 | __func__, __LINE__); | |
1792 | pcie_device->starget = starget; | |
1793 | } | |
1794 | ||
1795 | if (pcie_device) | |
1796 | pcie_device_put(pcie_device); | |
1797 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
f92363d1 | 1798 | |
d88e1eab | 1799 | } else if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { |
b65cfedf | 1800 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 1801 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
b65cfedf SR |
1802 | sas_target_priv_data->sas_address); |
1803 | if (sas_device && (sas_device->starget == NULL)) { | |
1804 | sdev_printk(KERN_INFO, sdev, | |
1805 | "%s : sas_device->starget set to starget @ %d\n", | |
d1cb5e49 | 1806 | __func__, __LINE__); |
b65cfedf SR |
1807 | sas_device->starget = starget; |
1808 | } | |
d1cb5e49 SR |
1809 | |
1810 | if (sas_device) | |
1811 | sas_device_put(sas_device); | |
1812 | ||
b65cfedf SR |
1813 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
1814 | } | |
1815 | ||
f92363d1 SR |
1816 | return 0; |
1817 | } | |
1818 | ||
1819 | /** | |
8a7e4c24 | 1820 | * scsih_slave_destroy - device destroy routine |
f92363d1 SR |
1821 | * @sdev: scsi device struct |
1822 | * | |
1823 | * Returns nothing. | |
1824 | */ | |
8bbb1cf6 | 1825 | static void |
8a7e4c24 | 1826 | scsih_slave_destroy(struct scsi_device *sdev) |
f92363d1 SR |
1827 | { |
1828 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1829 | struct scsi_target *starget; | |
1830 | struct Scsi_Host *shost; | |
1831 | struct MPT3SAS_ADAPTER *ioc; | |
1832 | struct _sas_device *sas_device; | |
d88e1eab | 1833 | struct _pcie_device *pcie_device; |
f92363d1 SR |
1834 | unsigned long flags; |
1835 | ||
1836 | if (!sdev->hostdata) | |
1837 | return; | |
1838 | ||
1839 | starget = scsi_target(sdev); | |
1840 | sas_target_priv_data = starget->hostdata; | |
1841 | sas_target_priv_data->num_luns--; | |
1842 | ||
1843 | shost = dev_to_shost(&starget->dev); | |
1844 | ioc = shost_priv(shost); | |
1845 | ||
d88e1eab SPS |
1846 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) { |
1847 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1848 | pcie_device = __mpt3sas_get_pdev_from_target(ioc, | |
1849 | sas_target_priv_data); | |
1850 | if (pcie_device && !sas_target_priv_data->num_luns) | |
1851 | pcie_device->starget = NULL; | |
1852 | ||
1853 | if (pcie_device) | |
1854 | pcie_device_put(pcie_device); | |
1855 | ||
1856 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1857 | ||
1858 | } else if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { | |
f92363d1 | 1859 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 SR |
1860 | sas_device = __mpt3sas_get_sdev_from_target(ioc, |
1861 | sas_target_priv_data); | |
f92363d1 SR |
1862 | if (sas_device && !sas_target_priv_data->num_luns) |
1863 | sas_device->starget = NULL; | |
d1cb5e49 SR |
1864 | |
1865 | if (sas_device) | |
1866 | sas_device_put(sas_device); | |
f92363d1 SR |
1867 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
1868 | } | |
1869 | ||
1870 | kfree(sdev->hostdata); | |
1871 | sdev->hostdata = NULL; | |
1872 | } | |
1873 | ||
1874 | /** | |
1875 | * _scsih_display_sata_capabilities - sata capabilities | |
1876 | * @ioc: per adapter object | |
1877 | * @handle: device handle | |
1878 | * @sdev: scsi device struct | |
1879 | */ | |
1880 | static void | |
1881 | _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc, | |
1882 | u16 handle, struct scsi_device *sdev) | |
1883 | { | |
1884 | Mpi2ConfigReply_t mpi_reply; | |
1885 | Mpi2SasDevicePage0_t sas_device_pg0; | |
1886 | u32 ioc_status; | |
1887 | u16 flags; | |
1888 | u32 device_info; | |
1889 | ||
1890 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
1891 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
1892 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
1893 | ioc->name, __FILE__, __LINE__, __func__); | |
1894 | return; | |
1895 | } | |
1896 | ||
1897 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
1898 | MPI2_IOCSTATUS_MASK; | |
1899 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
1900 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
1901 | ioc->name, __FILE__, __LINE__, __func__); | |
1902 | return; | |
1903 | } | |
1904 | ||
1905 | flags = le16_to_cpu(sas_device_pg0.Flags); | |
1906 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | |
1907 | ||
1908 | sdev_printk(KERN_INFO, sdev, | |
1909 | "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), " | |
1910 | "sw_preserve(%s)\n", | |
1911 | (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n", | |
1912 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n", | |
1913 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" : | |
1914 | "n", | |
1915 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n", | |
1916 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n", | |
1917 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n"); | |
1918 | } | |
1919 | ||
1920 | /* | |
1921 | * raid transport support - | |
1922 | * Enabled for SLES11 and newer, in older kernels the driver will panic when | |
6c7abffc | 1923 | * unloading the driver followed by a load - I believe that the subroutine |
f92363d1 SR |
1924 | * raid_class_release() is not cleaning up properly. |
1925 | */ | |
1926 | ||
1927 | /** | |
8a7e4c24 | 1928 | * scsih_is_raid - return boolean indicating device is raid volume |
f92363d1 SR |
1929 | * @dev the device struct object |
1930 | */ | |
8bbb1cf6 | 1931 | static int |
8a7e4c24 | 1932 | scsih_is_raid(struct device *dev) |
f92363d1 SR |
1933 | { |
1934 | struct scsi_device *sdev = to_scsi_device(dev); | |
7786ab6a | 1935 | struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host); |
f92363d1 | 1936 | |
7786ab6a SR |
1937 | if (ioc->is_warpdrive) |
1938 | return 0; | |
f92363d1 SR |
1939 | return (sdev->channel == RAID_CHANNEL) ? 1 : 0; |
1940 | } | |
1941 | ||
cd5897ed SPS |
1942 | static int |
1943 | scsih_is_nvme(struct device *dev) | |
1944 | { | |
1945 | struct scsi_device *sdev = to_scsi_device(dev); | |
1946 | ||
1947 | return (sdev->channel == PCIE_CHANNEL) ? 1 : 0; | |
1948 | } | |
1949 | ||
f92363d1 | 1950 | /** |
8a7e4c24 | 1951 | * scsih_get_resync - get raid volume resync percent complete |
f92363d1 SR |
1952 | * @dev the device struct object |
1953 | */ | |
8bbb1cf6 | 1954 | static void |
8a7e4c24 | 1955 | scsih_get_resync(struct device *dev) |
f92363d1 SR |
1956 | { |
1957 | struct scsi_device *sdev = to_scsi_device(dev); | |
1958 | struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host); | |
1959 | static struct _raid_device *raid_device; | |
1960 | unsigned long flags; | |
1961 | Mpi2RaidVolPage0_t vol_pg0; | |
1962 | Mpi2ConfigReply_t mpi_reply; | |
1963 | u32 volume_status_flags; | |
1964 | u8 percent_complete; | |
1965 | u16 handle; | |
1966 | ||
1967 | percent_complete = 0; | |
1968 | handle = 0; | |
7786ab6a SR |
1969 | if (ioc->is_warpdrive) |
1970 | goto out; | |
1971 | ||
f92363d1 SR |
1972 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
1973 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, | |
1974 | sdev->channel); | |
1975 | if (raid_device) { | |
1976 | handle = raid_device->handle; | |
1977 | percent_complete = raid_device->percent_complete; | |
1978 | } | |
1979 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1980 | ||
1981 | if (!handle) | |
1982 | goto out; | |
1983 | ||
1984 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0, | |
1985 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
1986 | sizeof(Mpi2RaidVolPage0_t))) { | |
1987 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
1988 | ioc->name, __FILE__, __LINE__, __func__); | |
1989 | percent_complete = 0; | |
1990 | goto out; | |
1991 | } | |
1992 | ||
1993 | volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags); | |
1994 | if (!(volume_status_flags & | |
1995 | MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)) | |
1996 | percent_complete = 0; | |
1997 | ||
1998 | out: | |
b130b0d5 SS |
1999 | |
2000 | switch (ioc->hba_mpi_version_belonged) { | |
2001 | case MPI2_VERSION: | |
c84b06a4 | 2002 | raid_set_resync(mpt2sas_raid_template, dev, percent_complete); |
b130b0d5 SS |
2003 | break; |
2004 | case MPI25_VERSION: | |
2005 | case MPI26_VERSION: | |
c84b06a4 | 2006 | raid_set_resync(mpt3sas_raid_template, dev, percent_complete); |
b130b0d5 SS |
2007 | break; |
2008 | } | |
f92363d1 SR |
2009 | } |
2010 | ||
2011 | /** | |
8a7e4c24 | 2012 | * scsih_get_state - get raid volume level |
f92363d1 SR |
2013 | * @dev the device struct object |
2014 | */ | |
8bbb1cf6 | 2015 | static void |
8a7e4c24 | 2016 | scsih_get_state(struct device *dev) |
f92363d1 SR |
2017 | { |
2018 | struct scsi_device *sdev = to_scsi_device(dev); | |
2019 | struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host); | |
2020 | static struct _raid_device *raid_device; | |
2021 | unsigned long flags; | |
2022 | Mpi2RaidVolPage0_t vol_pg0; | |
2023 | Mpi2ConfigReply_t mpi_reply; | |
2024 | u32 volstate; | |
2025 | enum raid_state state = RAID_STATE_UNKNOWN; | |
2026 | u16 handle = 0; | |
2027 | ||
2028 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
2029 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, | |
2030 | sdev->channel); | |
2031 | if (raid_device) | |
2032 | handle = raid_device->handle; | |
2033 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
2034 | ||
2035 | if (!raid_device) | |
2036 | goto out; | |
2037 | ||
2038 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0, | |
2039 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
2040 | sizeof(Mpi2RaidVolPage0_t))) { | |
2041 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
2042 | ioc->name, __FILE__, __LINE__, __func__); | |
2043 | goto out; | |
2044 | } | |
2045 | ||
2046 | volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags); | |
2047 | if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) { | |
2048 | state = RAID_STATE_RESYNCING; | |
2049 | goto out; | |
2050 | } | |
2051 | ||
2052 | switch (vol_pg0.VolumeState) { | |
2053 | case MPI2_RAID_VOL_STATE_OPTIMAL: | |
2054 | case MPI2_RAID_VOL_STATE_ONLINE: | |
2055 | state = RAID_STATE_ACTIVE; | |
2056 | break; | |
2057 | case MPI2_RAID_VOL_STATE_DEGRADED: | |
2058 | state = RAID_STATE_DEGRADED; | |
2059 | break; | |
2060 | case MPI2_RAID_VOL_STATE_FAILED: | |
2061 | case MPI2_RAID_VOL_STATE_MISSING: | |
2062 | state = RAID_STATE_OFFLINE; | |
2063 | break; | |
2064 | } | |
2065 | out: | |
b130b0d5 SS |
2066 | switch (ioc->hba_mpi_version_belonged) { |
2067 | case MPI2_VERSION: | |
c84b06a4 | 2068 | raid_set_state(mpt2sas_raid_template, dev, state); |
b130b0d5 SS |
2069 | break; |
2070 | case MPI25_VERSION: | |
2071 | case MPI26_VERSION: | |
c84b06a4 | 2072 | raid_set_state(mpt3sas_raid_template, dev, state); |
b130b0d5 SS |
2073 | break; |
2074 | } | |
f92363d1 SR |
2075 | } |
2076 | ||
2077 | /** | |
2078 | * _scsih_set_level - set raid level | |
2079 | * @sdev: scsi device struct | |
2080 | * @volume_type: volume type | |
2081 | */ | |
2082 | static void | |
c84b06a4 SR |
2083 | _scsih_set_level(struct MPT3SAS_ADAPTER *ioc, |
2084 | struct scsi_device *sdev, u8 volume_type) | |
f92363d1 SR |
2085 | { |
2086 | enum raid_level level = RAID_LEVEL_UNKNOWN; | |
2087 | ||
2088 | switch (volume_type) { | |
2089 | case MPI2_RAID_VOL_TYPE_RAID0: | |
2090 | level = RAID_LEVEL_0; | |
2091 | break; | |
2092 | case MPI2_RAID_VOL_TYPE_RAID10: | |
2093 | level = RAID_LEVEL_10; | |
2094 | break; | |
2095 | case MPI2_RAID_VOL_TYPE_RAID1E: | |
2096 | level = RAID_LEVEL_1E; | |
2097 | break; | |
2098 | case MPI2_RAID_VOL_TYPE_RAID1: | |
2099 | level = RAID_LEVEL_1; | |
2100 | break; | |
2101 | } | |
2102 | ||
b130b0d5 SS |
2103 | switch (ioc->hba_mpi_version_belonged) { |
2104 | case MPI2_VERSION: | |
c84b06a4 | 2105 | raid_set_level(mpt2sas_raid_template, |
b130b0d5 SS |
2106 | &sdev->sdev_gendev, level); |
2107 | break; | |
2108 | case MPI25_VERSION: | |
2109 | case MPI26_VERSION: | |
c84b06a4 | 2110 | raid_set_level(mpt3sas_raid_template, |
b130b0d5 SS |
2111 | &sdev->sdev_gendev, level); |
2112 | break; | |
2113 | } | |
f92363d1 SR |
2114 | } |
2115 | ||
2116 | ||
2117 | /** | |
2118 | * _scsih_get_volume_capabilities - volume capabilities | |
2119 | * @ioc: per adapter object | |
2120 | * @sas_device: the raid_device object | |
2121 | * | |
2122 | * Returns 0 for success, else 1 | |
2123 | */ | |
2124 | static int | |
2125 | _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc, | |
2126 | struct _raid_device *raid_device) | |
2127 | { | |
2128 | Mpi2RaidVolPage0_t *vol_pg0; | |
2129 | Mpi2RaidPhysDiskPage0_t pd_pg0; | |
2130 | Mpi2SasDevicePage0_t sas_device_pg0; | |
2131 | Mpi2ConfigReply_t mpi_reply; | |
2132 | u16 sz; | |
2133 | u8 num_pds; | |
2134 | ||
2135 | if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle, | |
2136 | &num_pds)) || !num_pds) { | |
2137 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2138 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | |
2139 | __func__)); | |
2140 | return 1; | |
2141 | } | |
2142 | ||
2143 | raid_device->num_pds = num_pds; | |
2144 | sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds * | |
2145 | sizeof(Mpi2RaidVol0PhysDisk_t)); | |
2146 | vol_pg0 = kzalloc(sz, GFP_KERNEL); | |
2147 | if (!vol_pg0) { | |
2148 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2149 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | |
2150 | __func__)); | |
2151 | return 1; | |
2152 | } | |
2153 | ||
2154 | if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0, | |
2155 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) { | |
2156 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2157 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | |
2158 | __func__)); | |
2159 | kfree(vol_pg0); | |
2160 | return 1; | |
2161 | } | |
2162 | ||
2163 | raid_device->volume_type = vol_pg0->VolumeType; | |
2164 | ||
2165 | /* figure out what the underlying devices are by | |
2166 | * obtaining the device_info bits for the 1st device | |
2167 | */ | |
2168 | if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | |
2169 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM, | |
2170 | vol_pg0->PhysDisk[0].PhysDiskNum))) { | |
2171 | if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
2172 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | |
2173 | le16_to_cpu(pd_pg0.DevHandle)))) { | |
2174 | raid_device->device_info = | |
2175 | le32_to_cpu(sas_device_pg0.DeviceInfo); | |
2176 | } | |
2177 | } | |
2178 | ||
2179 | kfree(vol_pg0); | |
2180 | return 0; | |
2181 | } | |
2182 | ||
f92363d1 SR |
2183 | /** |
2184 | * _scsih_enable_tlr - setting TLR flags | |
2185 | * @ioc: per adapter object | |
2186 | * @sdev: scsi device struct | |
2187 | * | |
2188 | * Enabling Transaction Layer Retries for tape devices when | |
2189 | * vpd page 0x90 is present | |
2190 | * | |
2191 | */ | |
2192 | static void | |
2193 | _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev) | |
2194 | { | |
2195 | ||
2196 | /* only for TAPE */ | |
2197 | if (sdev->type != TYPE_TAPE) | |
2198 | return; | |
2199 | ||
2200 | if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR)) | |
2201 | return; | |
2202 | ||
2203 | sas_enable_tlr(sdev); | |
2204 | sdev_printk(KERN_INFO, sdev, "TLR %s\n", | |
2205 | sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled"); | |
2206 | return; | |
2207 | ||
2208 | } | |
2209 | ||
2210 | /** | |
8a7e4c24 | 2211 | * scsih_slave_configure - device configure routine. |
f92363d1 SR |
2212 | * @sdev: scsi device struct |
2213 | * | |
2214 | * Returns 0 if ok. Any other return is assumed to be an error and | |
2215 | * the device is ignored. | |
2216 | */ | |
8bbb1cf6 | 2217 | static int |
8a7e4c24 | 2218 | scsih_slave_configure(struct scsi_device *sdev) |
f92363d1 SR |
2219 | { |
2220 | struct Scsi_Host *shost = sdev->host; | |
2221 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
2222 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2223 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
2224 | struct _sas_device *sas_device; | |
d1b01d14 | 2225 | struct _pcie_device *pcie_device; |
f92363d1 SR |
2226 | struct _raid_device *raid_device; |
2227 | unsigned long flags; | |
2228 | int qdepth; | |
2229 | u8 ssp_target = 0; | |
2230 | char *ds = ""; | |
2231 | char *r_level = ""; | |
2232 | u16 handle, volume_handle = 0; | |
2233 | u64 volume_wwid = 0; | |
2234 | ||
2235 | qdepth = 1; | |
2236 | sas_device_priv_data = sdev->hostdata; | |
2237 | sas_device_priv_data->configured_lun = 1; | |
2238 | sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT; | |
2239 | sas_target_priv_data = sas_device_priv_data->sas_target; | |
2240 | handle = sas_target_priv_data->handle; | |
2241 | ||
2242 | /* raid volume handling */ | |
2243 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) { | |
2244 | ||
2245 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
c84b06a4 | 2246 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
2247 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
2248 | if (!raid_device) { | |
2249 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2250 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, | |
2251 | __LINE__, __func__)); | |
2252 | return 1; | |
2253 | } | |
2254 | ||
2255 | if (_scsih_get_volume_capabilities(ioc, raid_device)) { | |
2256 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2257 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, | |
2258 | __LINE__, __func__)); | |
2259 | return 1; | |
2260 | } | |
2261 | ||
7786ab6a SR |
2262 | /* |
2263 | * WARPDRIVE: Initialize the required data for Direct IO | |
2264 | */ | |
c84b06a4 | 2265 | mpt3sas_init_warpdrive_properties(ioc, raid_device); |
f92363d1 SR |
2266 | |
2267 | /* RAID Queue Depth Support | |
2268 | * IS volume = underlying qdepth of drive type, either | |
2269 | * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH | |
2270 | * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH) | |
2271 | */ | |
2272 | if (raid_device->device_info & | |
2273 | MPI2_SAS_DEVICE_INFO_SSP_TARGET) { | |
2274 | qdepth = MPT3SAS_SAS_QUEUE_DEPTH; | |
2275 | ds = "SSP"; | |
2276 | } else { | |
2277 | qdepth = MPT3SAS_SATA_QUEUE_DEPTH; | |
2278 | if (raid_device->device_info & | |
2279 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) | |
2280 | ds = "SATA"; | |
2281 | else | |
2282 | ds = "STP"; | |
2283 | } | |
2284 | ||
2285 | switch (raid_device->volume_type) { | |
2286 | case MPI2_RAID_VOL_TYPE_RAID0: | |
2287 | r_level = "RAID0"; | |
2288 | break; | |
2289 | case MPI2_RAID_VOL_TYPE_RAID1E: | |
2290 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
2291 | if (ioc->manu_pg10.OEMIdentifier && | |
2292 | (le32_to_cpu(ioc->manu_pg10.GenericFlags0) & | |
2293 | MFG10_GF0_R10_DISPLAY) && | |
2294 | !(raid_device->num_pds % 2)) | |
2295 | r_level = "RAID10"; | |
2296 | else | |
2297 | r_level = "RAID1E"; | |
2298 | break; | |
2299 | case MPI2_RAID_VOL_TYPE_RAID1: | |
2300 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
2301 | r_level = "RAID1"; | |
2302 | break; | |
2303 | case MPI2_RAID_VOL_TYPE_RAID10: | |
2304 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
2305 | r_level = "RAID10"; | |
2306 | break; | |
2307 | case MPI2_RAID_VOL_TYPE_UNKNOWN: | |
2308 | default: | |
2309 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
2310 | r_level = "RAIDX"; | |
2311 | break; | |
2312 | } | |
2313 | ||
7786ab6a SR |
2314 | if (!ioc->hide_ir_msg) |
2315 | sdev_printk(KERN_INFO, sdev, | |
2316 | "%s: handle(0x%04x), wwid(0x%016llx)," | |
2317 | " pd_count(%d), type(%s)\n", | |
2318 | r_level, raid_device->handle, | |
2319 | (unsigned long long)raid_device->wwid, | |
2320 | raid_device->num_pds, ds); | |
f92363d1 | 2321 | |
6c197093 C |
2322 | if (shost->max_sectors > MPT3SAS_RAID_MAX_SECTORS) { |
2323 | blk_queue_max_hw_sectors(sdev->request_queue, | |
2324 | MPT3SAS_RAID_MAX_SECTORS); | |
2325 | sdev_printk(KERN_INFO, sdev, | |
2326 | "Set queue's max_sector to: %u\n", | |
2327 | MPT3SAS_RAID_MAX_SECTORS); | |
2328 | } | |
2329 | ||
8a7e4c24 | 2330 | scsih_change_queue_depth(sdev, qdepth); |
f92363d1 | 2331 | |
7786ab6a SR |
2332 | /* raid transport support */ |
2333 | if (!ioc->is_warpdrive) | |
c84b06a4 | 2334 | _scsih_set_level(ioc, sdev, raid_device->volume_type); |
f92363d1 SR |
2335 | return 0; |
2336 | } | |
2337 | ||
2338 | /* non-raid handling */ | |
2339 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
2340 | if (mpt3sas_config_get_volume_handle(ioc, handle, | |
2341 | &volume_handle)) { | |
2342 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2343 | "failure at %s:%d/%s()!\n", ioc->name, | |
2344 | __FILE__, __LINE__, __func__)); | |
2345 | return 1; | |
2346 | } | |
2347 | if (volume_handle && mpt3sas_config_get_volume_wwid(ioc, | |
2348 | volume_handle, &volume_wwid)) { | |
2349 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2350 | "failure at %s:%d/%s()!\n", ioc->name, | |
2351 | __FILE__, __LINE__, __func__)); | |
2352 | return 1; | |
2353 | } | |
2354 | } | |
2355 | ||
d1b01d14 SPS |
2356 | /* PCIe handling */ |
2357 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) { | |
2358 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
2359 | pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, | |
2360 | sas_device_priv_data->sas_target->sas_address); | |
2361 | if (!pcie_device) { | |
2362 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
2363 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2364 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, | |
2365 | __LINE__, __func__)); | |
2366 | return 1; | |
2367 | } | |
2368 | ||
2369 | qdepth = MPT3SAS_NVME_QUEUE_DEPTH; | |
2370 | ds = "NVMe"; | |
2371 | sdev_printk(KERN_INFO, sdev, | |
2372 | "%s: handle(0x%04x), wwid(0x%016llx), port(%d)\n", | |
2373 | ds, handle, (unsigned long long)pcie_device->wwid, | |
2374 | pcie_device->port_num); | |
2375 | if (pcie_device->enclosure_handle != 0) | |
2376 | sdev_printk(KERN_INFO, sdev, | |
2377 | "%s: enclosure logical id(0x%016llx), slot(%d)\n", | |
2378 | ds, | |
2379 | (unsigned long long)pcie_device->enclosure_logical_id, | |
2380 | pcie_device->slot); | |
2381 | if (pcie_device->connector_name[0] != '\0') | |
2382 | sdev_printk(KERN_INFO, sdev, | |
2383 | "%s: enclosure level(0x%04x)," | |
2384 | "connector name( %s)\n", ds, | |
2385 | pcie_device->enclosure_level, | |
2386 | pcie_device->connector_name); | |
2387 | pcie_device_put(pcie_device); | |
2388 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
2389 | scsih_change_queue_depth(sdev, qdepth); | |
2390 | ||
2391 | if (pcie_device->nvme_mdts) | |
2392 | blk_queue_max_hw_sectors(sdev->request_queue, | |
2393 | pcie_device->nvme_mdts/512); | |
2394 | /* Enable QUEUE_FLAG_NOMERGES flag, so that IOs won't be | |
2395 | ** merged and can eliminate holes created during merging | |
2396 | ** operation. | |
2397 | **/ | |
2398 | queue_flag_set_unlocked(QUEUE_FLAG_NOMERGES, | |
2399 | sdev->request_queue); | |
2400 | blk_queue_virt_boundary(sdev->request_queue, | |
2401 | ioc->page_size - 1); | |
2402 | return 0; | |
2403 | } | |
2404 | ||
f92363d1 | 2405 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 2406 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 SR |
2407 | sas_device_priv_data->sas_target->sas_address); |
2408 | if (!sas_device) { | |
2409 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
2410 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2411 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | |
2412 | __func__)); | |
2413 | return 1; | |
2414 | } | |
2415 | ||
2416 | sas_device->volume_handle = volume_handle; | |
2417 | sas_device->volume_wwid = volume_wwid; | |
2418 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) { | |
2419 | qdepth = MPT3SAS_SAS_QUEUE_DEPTH; | |
2420 | ssp_target = 1; | |
30158dc9 SS |
2421 | if (sas_device->device_info & |
2422 | MPI2_SAS_DEVICE_INFO_SEP) { | |
2423 | sdev_printk(KERN_WARNING, sdev, | |
2424 | "set ignore_delay_remove for handle(0x%04x)\n", | |
2425 | sas_device_priv_data->sas_target->handle); | |
2426 | sas_device_priv_data->ignore_delay_remove = 1; | |
2427 | ds = "SES"; | |
2428 | } else | |
2429 | ds = "SSP"; | |
f92363d1 SR |
2430 | } else { |
2431 | qdepth = MPT3SAS_SATA_QUEUE_DEPTH; | |
2432 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) | |
2433 | ds = "STP"; | |
2434 | else if (sas_device->device_info & | |
2435 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) | |
2436 | ds = "SATA"; | |
2437 | } | |
2438 | ||
2439 | sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \ | |
2440 | "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n", | |
2441 | ds, handle, (unsigned long long)sas_device->sas_address, | |
2442 | sas_device->phy, (unsigned long long)sas_device->device_name); | |
75888956 SR |
2443 | |
2444 | _scsih_display_enclosure_chassis_info(NULL, sas_device, sdev, NULL); | |
f92363d1 | 2445 | |
d1cb5e49 | 2446 | sas_device_put(sas_device); |
f92363d1 SR |
2447 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
2448 | ||
2449 | if (!ssp_target) | |
2450 | _scsih_display_sata_capabilities(ioc, handle, sdev); | |
2451 | ||
2452 | ||
8a7e4c24 | 2453 | scsih_change_queue_depth(sdev, qdepth); |
f92363d1 SR |
2454 | |
2455 | if (ssp_target) { | |
2456 | sas_read_port_mode_page(sdev); | |
2457 | _scsih_enable_tlr(ioc, sdev); | |
2458 | } | |
2459 | ||
2460 | return 0; | |
2461 | } | |
2462 | ||
2463 | /** | |
8a7e4c24 | 2464 | * scsih_bios_param - fetch head, sector, cylinder info for a disk |
f92363d1 SR |
2465 | * @sdev: scsi device struct |
2466 | * @bdev: pointer to block device context | |
2467 | * @capacity: device size (in 512 byte sectors) | |
2468 | * @params: three element array to place output: | |
2469 | * params[0] number of heads (max 255) | |
2470 | * params[1] number of sectors (max 63) | |
2471 | * params[2] number of cylinders | |
2472 | * | |
2473 | * Return nothing. | |
2474 | */ | |
8bbb1cf6 | 2475 | static int |
8a7e4c24 | 2476 | scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev, |
f92363d1 SR |
2477 | sector_t capacity, int params[]) |
2478 | { | |
2479 | int heads; | |
2480 | int sectors; | |
2481 | sector_t cylinders; | |
2482 | ulong dummy; | |
2483 | ||
2484 | heads = 64; | |
2485 | sectors = 32; | |
2486 | ||
2487 | dummy = heads * sectors; | |
2488 | cylinders = capacity; | |
2489 | sector_div(cylinders, dummy); | |
2490 | ||
2491 | /* | |
2492 | * Handle extended translation size for logical drives | |
2493 | * > 1Gb | |
2494 | */ | |
2495 | if ((ulong)capacity >= 0x200000) { | |
2496 | heads = 255; | |
2497 | sectors = 63; | |
2498 | dummy = heads * sectors; | |
2499 | cylinders = capacity; | |
2500 | sector_div(cylinders, dummy); | |
2501 | } | |
2502 | ||
2503 | /* return result */ | |
2504 | params[0] = heads; | |
2505 | params[1] = sectors; | |
2506 | params[2] = cylinders; | |
2507 | ||
2508 | return 0; | |
2509 | } | |
2510 | ||
2511 | /** | |
2512 | * _scsih_response_code - translation of device response code | |
2513 | * @ioc: per adapter object | |
2514 | * @response_code: response code returned by the device | |
2515 | * | |
2516 | * Return nothing. | |
2517 | */ | |
2518 | static void | |
2519 | _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code) | |
2520 | { | |
2521 | char *desc; | |
2522 | ||
2523 | switch (response_code) { | |
2524 | case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE: | |
2525 | desc = "task management request completed"; | |
2526 | break; | |
2527 | case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME: | |
2528 | desc = "invalid frame"; | |
2529 | break; | |
2530 | case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED: | |
2531 | desc = "task management request not supported"; | |
2532 | break; | |
2533 | case MPI2_SCSITASKMGMT_RSP_TM_FAILED: | |
2534 | desc = "task management request failed"; | |
2535 | break; | |
2536 | case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED: | |
2537 | desc = "task management request succeeded"; | |
2538 | break; | |
2539 | case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN: | |
2540 | desc = "invalid lun"; | |
2541 | break; | |
2542 | case 0xA: | |
2543 | desc = "overlapped tag attempted"; | |
2544 | break; | |
2545 | case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC: | |
2546 | desc = "task queued, however not sent to target"; | |
2547 | break; | |
2548 | default: | |
2549 | desc = "unknown"; | |
2550 | break; | |
2551 | } | |
2552 | pr_warn(MPT3SAS_FMT "response_code(0x%01x): %s\n", | |
2553 | ioc->name, response_code, desc); | |
2554 | } | |
2555 | ||
2556 | /** | |
2557 | * _scsih_tm_done - tm completion routine | |
2558 | * @ioc: per adapter object | |
2559 | * @smid: system request message index | |
2560 | * @msix_index: MSIX table index supplied by the OS | |
2561 | * @reply: reply message frame(lower 32bit addr) | |
2562 | * Context: none. | |
2563 | * | |
2564 | * The callback handler when using scsih_issue_tm. | |
2565 | * | |
2566 | * Return 1 meaning mf should be freed from _base_interrupt | |
2567 | * 0 means the mf is freed from this function. | |
2568 | */ | |
2569 | static u8 | |
2570 | _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | |
2571 | { | |
2572 | MPI2DefaultReply_t *mpi_reply; | |
2573 | ||
2574 | if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED) | |
2575 | return 1; | |
2576 | if (ioc->tm_cmds.smid != smid) | |
2577 | return 1; | |
f92363d1 SR |
2578 | ioc->tm_cmds.status |= MPT3_CMD_COMPLETE; |
2579 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
2580 | if (mpi_reply) { | |
2581 | memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); | |
2582 | ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID; | |
2583 | } | |
2584 | ioc->tm_cmds.status &= ~MPT3_CMD_PENDING; | |
2585 | complete(&ioc->tm_cmds.done); | |
2586 | return 1; | |
2587 | } | |
2588 | ||
2589 | /** | |
2590 | * mpt3sas_scsih_set_tm_flag - set per target tm_busy | |
2591 | * @ioc: per adapter object | |
2592 | * @handle: device handle | |
2593 | * | |
2594 | * During taskmangement request, we need to freeze the device queue. | |
2595 | */ | |
2596 | void | |
2597 | mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
2598 | { | |
2599 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2600 | struct scsi_device *sdev; | |
2601 | u8 skip = 0; | |
2602 | ||
2603 | shost_for_each_device(sdev, ioc->shost) { | |
2604 | if (skip) | |
2605 | continue; | |
2606 | sas_device_priv_data = sdev->hostdata; | |
2607 | if (!sas_device_priv_data) | |
2608 | continue; | |
2609 | if (sas_device_priv_data->sas_target->handle == handle) { | |
2610 | sas_device_priv_data->sas_target->tm_busy = 1; | |
2611 | skip = 1; | |
2612 | ioc->ignore_loginfos = 1; | |
2613 | } | |
2614 | } | |
2615 | } | |
2616 | ||
2617 | /** | |
2618 | * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy | |
2619 | * @ioc: per adapter object | |
2620 | * @handle: device handle | |
2621 | * | |
2622 | * During taskmangement request, we need to freeze the device queue. | |
2623 | */ | |
2624 | void | |
2625 | mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
2626 | { | |
2627 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2628 | struct scsi_device *sdev; | |
2629 | u8 skip = 0; | |
2630 | ||
2631 | shost_for_each_device(sdev, ioc->shost) { | |
2632 | if (skip) | |
2633 | continue; | |
2634 | sas_device_priv_data = sdev->hostdata; | |
2635 | if (!sas_device_priv_data) | |
2636 | continue; | |
2637 | if (sas_device_priv_data->sas_target->handle == handle) { | |
2638 | sas_device_priv_data->sas_target->tm_busy = 0; | |
2639 | skip = 1; | |
2640 | ioc->ignore_loginfos = 0; | |
2641 | } | |
2642 | } | |
2643 | } | |
2644 | ||
2645 | /** | |
2646 | * mpt3sas_scsih_issue_tm - main routine for sending tm requests | |
2647 | * @ioc: per adapter struct | |
6da999fe | 2648 | * @handle: device handle |
f92363d1 SR |
2649 | * @lun: lun number |
2650 | * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h) | |
2651 | * @smid_task: smid assigned to the task | |
6da999fe | 2652 | * @msix_task: MSIX table index supplied by the OS |
f92363d1 | 2653 | * @timeout: timeout in seconds |
f92363d1 SR |
2654 | * Context: user |
2655 | * | |
2656 | * A generic API for sending task management requests to firmware. | |
2657 | * | |
2658 | * The callback index is set inside `ioc->tm_cb_idx`. | |
6da999fe | 2659 | * The caller is responsible to check for outstanding commands. |
f92363d1 SR |
2660 | * |
2661 | * Return SUCCESS or FAILED. | |
2662 | */ | |
2663 | int | |
6da999fe HR |
2664 | mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, |
2665 | u64 lun, u8 type, u16 smid_task, u16 msix_task, ulong timeout) | |
f92363d1 SR |
2666 | { |
2667 | Mpi2SCSITaskManagementRequest_t *mpi_request; | |
2668 | Mpi2SCSITaskManagementReply_t *mpi_reply; | |
2669 | u16 smid = 0; | |
2670 | u32 ioc_state; | |
f92363d1 SR |
2671 | int rc; |
2672 | ||
96902835 CO |
2673 | lockdep_assert_held(&ioc->tm_cmds.mutex); |
2674 | ||
f92363d1 SR |
2675 | if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) { |
2676 | pr_info(MPT3SAS_FMT "%s: tm_cmd busy!!!\n", | |
2677 | __func__, ioc->name); | |
96902835 | 2678 | return FAILED; |
f92363d1 SR |
2679 | } |
2680 | ||
2681 | if (ioc->shost_recovery || ioc->remove_host || | |
2682 | ioc->pci_error_recovery) { | |
2683 | pr_info(MPT3SAS_FMT "%s: host reset in progress!\n", | |
2684 | __func__, ioc->name); | |
96902835 | 2685 | return FAILED; |
f92363d1 SR |
2686 | } |
2687 | ||
2688 | ioc_state = mpt3sas_base_get_iocstate(ioc, 0); | |
2689 | if (ioc_state & MPI2_DOORBELL_USED) { | |
2690 | dhsprintk(ioc, pr_info(MPT3SAS_FMT | |
2691 | "unexpected doorbell active!\n", ioc->name)); | |
98c56ad3 | 2692 | rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
96902835 | 2693 | return (!rc) ? SUCCESS : FAILED; |
f92363d1 SR |
2694 | } |
2695 | ||
2696 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { | |
2697 | mpt3sas_base_fault_info(ioc, ioc_state & | |
2698 | MPI2_DOORBELL_DATA_MASK); | |
98c56ad3 | 2699 | rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
96902835 | 2700 | return (!rc) ? SUCCESS : FAILED; |
f92363d1 SR |
2701 | } |
2702 | ||
2703 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx); | |
2704 | if (!smid) { | |
2705 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
2706 | ioc->name, __func__); | |
96902835 | 2707 | return FAILED; |
f92363d1 SR |
2708 | } |
2709 | ||
f92363d1 SR |
2710 | dtmprintk(ioc, pr_info(MPT3SAS_FMT |
2711 | "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n", | |
2712 | ioc->name, handle, type, smid_task)); | |
2713 | ioc->tm_cmds.status = MPT3_CMD_PENDING; | |
2714 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
2715 | ioc->tm_cmds.smid = smid; | |
2716 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | |
2717 | memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t)); | |
2718 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | |
2719 | mpi_request->DevHandle = cpu_to_le16(handle); | |
2720 | mpi_request->TaskType = type; | |
2721 | mpi_request->TaskMID = cpu_to_le16(smid_task); | |
2722 | int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN); | |
2723 | mpt3sas_scsih_set_tm_flag(ioc, handle); | |
2724 | init_completion(&ioc->tm_cmds.done); | |
81c16f83 | 2725 | ioc->put_smid_hi_priority(ioc, smid, msix_task); |
8bbb1cf6 | 2726 | wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ); |
f92363d1 SR |
2727 | if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) { |
2728 | pr_err(MPT3SAS_FMT "%s: timeout\n", | |
2729 | ioc->name, __func__); | |
2730 | _debug_dump_mf(mpi_request, | |
2731 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); | |
2732 | if (!(ioc->tm_cmds.status & MPT3_CMD_RESET)) { | |
98c56ad3 CO |
2733 | rc = mpt3sas_base_hard_reset_handler(ioc, |
2734 | FORCE_BIG_HAMMER); | |
f92363d1 | 2735 | rc = (!rc) ? SUCCESS : FAILED; |
96902835 | 2736 | goto out; |
f92363d1 SR |
2737 | } |
2738 | } | |
2739 | ||
5f0dfb7a C |
2740 | /* sync IRQs in case those were busy during flush. */ |
2741 | mpt3sas_base_sync_reply_irqs(ioc); | |
2742 | ||
f92363d1 SR |
2743 | if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) { |
2744 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT); | |
2745 | mpi_reply = ioc->tm_cmds.reply; | |
2746 | dtmprintk(ioc, pr_info(MPT3SAS_FMT "complete tm: " \ | |
2747 | "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n", | |
2748 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), | |
2749 | le32_to_cpu(mpi_reply->IOCLogInfo), | |
2750 | le32_to_cpu(mpi_reply->TerminationCount))); | |
2751 | if (ioc->logging_level & MPT_DEBUG_TM) { | |
2752 | _scsih_response_code(ioc, mpi_reply->ResponseCode); | |
2753 | if (mpi_reply->IOCStatus) | |
2754 | _debug_dump_mf(mpi_request, | |
2755 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); | |
2756 | } | |
2757 | } | |
6da999fe | 2758 | rc = SUCCESS; |
f92363d1 | 2759 | |
96902835 | 2760 | out: |
f92363d1 SR |
2761 | mpt3sas_scsih_clear_tm_flag(ioc, handle); |
2762 | ioc->tm_cmds.status = MPT3_CMD_NOT_USED; | |
f92363d1 | 2763 | return rc; |
96902835 | 2764 | } |
f92363d1 | 2765 | |
96902835 | 2766 | int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, |
6da999fe | 2767 | u64 lun, u8 type, u16 smid_task, u16 msix_task, ulong timeout) |
96902835 CO |
2768 | { |
2769 | int ret; | |
2770 | ||
2771 | mutex_lock(&ioc->tm_cmds.mutex); | |
6da999fe HR |
2772 | ret = mpt3sas_scsih_issue_tm(ioc, handle, lun, type, smid_task, |
2773 | msix_task, timeout); | |
96902835 CO |
2774 | mutex_unlock(&ioc->tm_cmds.mutex); |
2775 | ||
2776 | return ret; | |
f92363d1 SR |
2777 | } |
2778 | ||
2779 | /** | |
2780 | * _scsih_tm_display_info - displays info about the device | |
2781 | * @ioc: per adapter struct | |
2782 | * @scmd: pointer to scsi command object | |
2783 | * | |
2784 | * Called by task management callback handlers. | |
2785 | */ | |
2786 | static void | |
2787 | _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd) | |
2788 | { | |
2789 | struct scsi_target *starget = scmd->device->sdev_target; | |
2790 | struct MPT3SAS_TARGET *priv_target = starget->hostdata; | |
2791 | struct _sas_device *sas_device = NULL; | |
6ce2f1d1 | 2792 | struct _pcie_device *pcie_device = NULL; |
f92363d1 SR |
2793 | unsigned long flags; |
2794 | char *device_str = NULL; | |
2795 | ||
2796 | if (!priv_target) | |
2797 | return; | |
7786ab6a SR |
2798 | if (ioc->hide_ir_msg) |
2799 | device_str = "WarpDrive"; | |
2800 | else | |
2801 | device_str = "volume"; | |
f92363d1 SR |
2802 | |
2803 | scsi_print_command(scmd); | |
2804 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { | |
2805 | starget_printk(KERN_INFO, starget, | |
2806 | "%s handle(0x%04x), %s wwid(0x%016llx)\n", | |
2807 | device_str, priv_target->handle, | |
2808 | device_str, (unsigned long long)priv_target->sas_address); | |
6ce2f1d1 SPS |
2809 | |
2810 | } else if (priv_target->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) { | |
2811 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
2812 | pcie_device = __mpt3sas_get_pdev_from_target(ioc, priv_target); | |
2813 | if (pcie_device) { | |
2814 | starget_printk(KERN_INFO, starget, | |
2815 | "handle(0x%04x), wwid(0x%016llx), port(%d)\n", | |
2816 | pcie_device->handle, | |
2817 | (unsigned long long)pcie_device->wwid, | |
2818 | pcie_device->port_num); | |
2819 | if (pcie_device->enclosure_handle != 0) | |
2820 | starget_printk(KERN_INFO, starget, | |
2821 | "enclosure logical id(0x%016llx), slot(%d)\n", | |
2822 | (unsigned long long) | |
2823 | pcie_device->enclosure_logical_id, | |
2824 | pcie_device->slot); | |
2825 | if (pcie_device->connector_name[0] != '\0') | |
2826 | starget_printk(KERN_INFO, starget, | |
2827 | "enclosure level(0x%04x), connector name( %s)\n", | |
2828 | pcie_device->enclosure_level, | |
2829 | pcie_device->connector_name); | |
2830 | pcie_device_put(pcie_device); | |
2831 | } | |
2832 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
2833 | ||
f92363d1 SR |
2834 | } else { |
2835 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 | 2836 | sas_device = __mpt3sas_get_sdev_from_target(ioc, priv_target); |
f92363d1 SR |
2837 | if (sas_device) { |
2838 | if (priv_target->flags & | |
2839 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
2840 | starget_printk(KERN_INFO, starget, | |
2841 | "volume handle(0x%04x), " | |
2842 | "volume wwid(0x%016llx)\n", | |
2843 | sas_device->volume_handle, | |
2844 | (unsigned long long)sas_device->volume_wwid); | |
2845 | } | |
2846 | starget_printk(KERN_INFO, starget, | |
2847 | "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n", | |
2848 | sas_device->handle, | |
2849 | (unsigned long long)sas_device->sas_address, | |
2850 | sas_device->phy); | |
75888956 SR |
2851 | |
2852 | _scsih_display_enclosure_chassis_info(NULL, sas_device, | |
2853 | NULL, starget); | |
d1cb5e49 SR |
2854 | |
2855 | sas_device_put(sas_device); | |
f92363d1 SR |
2856 | } |
2857 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
2858 | } | |
2859 | } | |
2860 | ||
2861 | /** | |
8a7e4c24 | 2862 | * scsih_abort - eh threads main abort routine |
f92363d1 SR |
2863 | * @scmd: pointer to scsi command object |
2864 | * | |
2865 | * Returns SUCCESS if command aborted else FAILED | |
2866 | */ | |
8bbb1cf6 | 2867 | static int |
8a7e4c24 | 2868 | scsih_abort(struct scsi_cmnd *scmd) |
f92363d1 SR |
2869 | { |
2870 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
2871 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
6da999fe | 2872 | struct scsiio_tracker *st = NULL; |
f92363d1 SR |
2873 | u16 handle; |
2874 | int r; | |
2875 | ||
2876 | sdev_printk(KERN_INFO, scmd->device, | |
2877 | "attempting task abort! scmd(%p)\n", scmd); | |
2878 | _scsih_tm_display_info(ioc, scmd); | |
2879 | ||
2880 | sas_device_priv_data = scmd->device->hostdata; | |
2881 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | |
2882 | sdev_printk(KERN_INFO, scmd->device, | |
2883 | "device been deleted! scmd(%p)\n", scmd); | |
2884 | scmd->result = DID_NO_CONNECT << 16; | |
2885 | scmd->scsi_done(scmd); | |
2886 | r = SUCCESS; | |
2887 | goto out; | |
2888 | } | |
2889 | ||
2890 | /* search for the command */ | |
6da999fe HR |
2891 | st = _scsih_scsi_lookup_find_by_scmd(ioc, scmd); |
2892 | if (!st) { | |
f92363d1 SR |
2893 | scmd->result = DID_RESET << 16; |
2894 | r = SUCCESS; | |
2895 | goto out; | |
2896 | } | |
2897 | ||
2898 | /* for hidden raid components and volumes this is not supported */ | |
2899 | if (sas_device_priv_data->sas_target->flags & | |
2900 | MPT_TARGET_FLAGS_RAID_COMPONENT || | |
2901 | sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) { | |
2902 | scmd->result = DID_RESET << 16; | |
2903 | r = FAILED; | |
2904 | goto out; | |
2905 | } | |
2906 | ||
2907 | mpt3sas_halt_firmware(ioc); | |
2908 | ||
2909 | handle = sas_device_priv_data->sas_target->handle; | |
6da999fe HR |
2910 | r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->lun, |
2911 | MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, | |
2912 | st->smid, st->msix_io, 30); | |
2913 | /* Command must be cleared after abort */ | |
2914 | if (r == SUCCESS && st->scmd) | |
2915 | r = FAILED; | |
f92363d1 SR |
2916 | out: |
2917 | sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n", | |
2918 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
2919 | return r; | |
2920 | } | |
2921 | ||
2922 | /** | |
8a7e4c24 | 2923 | * scsih_dev_reset - eh threads main device reset routine |
f92363d1 SR |
2924 | * @scmd: pointer to scsi command object |
2925 | * | |
2926 | * Returns SUCCESS if command aborted else FAILED | |
2927 | */ | |
8bbb1cf6 | 2928 | static int |
8a7e4c24 | 2929 | scsih_dev_reset(struct scsi_cmnd *scmd) |
f92363d1 SR |
2930 | { |
2931 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
2932 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
d1cb5e49 | 2933 | struct _sas_device *sas_device = NULL; |
f92363d1 SR |
2934 | u16 handle; |
2935 | int r; | |
2936 | ||
d1cb5e49 SR |
2937 | struct scsi_target *starget = scmd->device->sdev_target; |
2938 | struct MPT3SAS_TARGET *target_priv_data = starget->hostdata; | |
2939 | ||
f92363d1 SR |
2940 | sdev_printk(KERN_INFO, scmd->device, |
2941 | "attempting device reset! scmd(%p)\n", scmd); | |
2942 | _scsih_tm_display_info(ioc, scmd); | |
2943 | ||
2944 | sas_device_priv_data = scmd->device->hostdata; | |
2945 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | |
2946 | sdev_printk(KERN_INFO, scmd->device, | |
2947 | "device been deleted! scmd(%p)\n", scmd); | |
2948 | scmd->result = DID_NO_CONNECT << 16; | |
2949 | scmd->scsi_done(scmd); | |
2950 | r = SUCCESS; | |
2951 | goto out; | |
2952 | } | |
2953 | ||
2954 | /* for hidden raid components obtain the volume_handle */ | |
2955 | handle = 0; | |
2956 | if (sas_device_priv_data->sas_target->flags & | |
2957 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
d1cb5e49 SR |
2958 | sas_device = mpt3sas_get_sdev_from_target(ioc, |
2959 | target_priv_data); | |
f92363d1 SR |
2960 | if (sas_device) |
2961 | handle = sas_device->volume_handle; | |
f92363d1 SR |
2962 | } else |
2963 | handle = sas_device_priv_data->sas_target->handle; | |
2964 | ||
2965 | if (!handle) { | |
2966 | scmd->result = DID_RESET << 16; | |
2967 | r = FAILED; | |
2968 | goto out; | |
2969 | } | |
2970 | ||
6da999fe HR |
2971 | r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->lun, |
2972 | MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 0, 30); | |
74fcfa53 HR |
2973 | /* Check for busy commands after reset */ |
2974 | if (r == SUCCESS && atomic_read(&scmd->device->device_busy)) | |
2975 | r = FAILED; | |
f92363d1 SR |
2976 | out: |
2977 | sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n", | |
2978 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
d1cb5e49 SR |
2979 | |
2980 | if (sas_device) | |
2981 | sas_device_put(sas_device); | |
2982 | ||
f92363d1 SR |
2983 | return r; |
2984 | } | |
2985 | ||
2986 | /** | |
8a7e4c24 | 2987 | * scsih_target_reset - eh threads main target reset routine |
f92363d1 SR |
2988 | * @scmd: pointer to scsi command object |
2989 | * | |
2990 | * Returns SUCCESS if command aborted else FAILED | |
2991 | */ | |
8bbb1cf6 | 2992 | static int |
8a7e4c24 | 2993 | scsih_target_reset(struct scsi_cmnd *scmd) |
f92363d1 SR |
2994 | { |
2995 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
2996 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
d1cb5e49 | 2997 | struct _sas_device *sas_device = NULL; |
f92363d1 SR |
2998 | u16 handle; |
2999 | int r; | |
3000 | struct scsi_target *starget = scmd->device->sdev_target; | |
d1cb5e49 | 3001 | struct MPT3SAS_TARGET *target_priv_data = starget->hostdata; |
f92363d1 SR |
3002 | |
3003 | starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n", | |
3004 | scmd); | |
3005 | _scsih_tm_display_info(ioc, scmd); | |
3006 | ||
3007 | sas_device_priv_data = scmd->device->hostdata; | |
3008 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | |
3009 | starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n", | |
3010 | scmd); | |
3011 | scmd->result = DID_NO_CONNECT << 16; | |
3012 | scmd->scsi_done(scmd); | |
3013 | r = SUCCESS; | |
3014 | goto out; | |
3015 | } | |
3016 | ||
3017 | /* for hidden raid components obtain the volume_handle */ | |
3018 | handle = 0; | |
3019 | if (sas_device_priv_data->sas_target->flags & | |
3020 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
d1cb5e49 SR |
3021 | sas_device = mpt3sas_get_sdev_from_target(ioc, |
3022 | target_priv_data); | |
f92363d1 SR |
3023 | if (sas_device) |
3024 | handle = sas_device->volume_handle; | |
f92363d1 SR |
3025 | } else |
3026 | handle = sas_device_priv_data->sas_target->handle; | |
3027 | ||
3028 | if (!handle) { | |
3029 | scmd->result = DID_RESET << 16; | |
3030 | r = FAILED; | |
3031 | goto out; | |
3032 | } | |
3033 | ||
6da999fe HR |
3034 | r = mpt3sas_scsih_issue_locked_tm(ioc, handle, 0, |
3035 | MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 0, 30); | |
74fcfa53 HR |
3036 | /* Check for busy commands after reset */ |
3037 | if (r == SUCCESS && atomic_read(&starget->target_busy)) | |
3038 | r = FAILED; | |
f92363d1 SR |
3039 | out: |
3040 | starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n", | |
3041 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
d1cb5e49 SR |
3042 | |
3043 | if (sas_device) | |
3044 | sas_device_put(sas_device); | |
3045 | ||
f92363d1 SR |
3046 | return r; |
3047 | } | |
3048 | ||
3049 | ||
3050 | /** | |
8a7e4c24 | 3051 | * scsih_host_reset - eh threads main host reset routine |
f92363d1 SR |
3052 | * @scmd: pointer to scsi command object |
3053 | * | |
3054 | * Returns SUCCESS if command aborted else FAILED | |
3055 | */ | |
8bbb1cf6 | 3056 | static int |
8a7e4c24 | 3057 | scsih_host_reset(struct scsi_cmnd *scmd) |
f92363d1 SR |
3058 | { |
3059 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
3060 | int r, retval; | |
3061 | ||
3062 | pr_info(MPT3SAS_FMT "attempting host reset! scmd(%p)\n", | |
3063 | ioc->name, scmd); | |
3064 | scsi_print_command(scmd); | |
3065 | ||
ddb588be SR |
3066 | if (ioc->is_driver_loading) { |
3067 | pr_info(MPT3SAS_FMT "Blocking the host reset\n", | |
3068 | ioc->name); | |
3069 | r = FAILED; | |
3070 | goto out; | |
3071 | } | |
3072 | ||
98c56ad3 | 3073 | retval = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
f92363d1 | 3074 | r = (retval < 0) ? FAILED : SUCCESS; |
ddb588be | 3075 | out: |
f92363d1 SR |
3076 | pr_info(MPT3SAS_FMT "host reset: %s scmd(%p)\n", |
3077 | ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
3078 | ||
3079 | return r; | |
3080 | } | |
3081 | ||
3082 | /** | |
3083 | * _scsih_fw_event_add - insert and queue up fw_event | |
3084 | * @ioc: per adapter object | |
3085 | * @fw_event: object describing the event | |
3086 | * Context: This function will acquire ioc->fw_event_lock. | |
3087 | * | |
3088 | * This adds the firmware event object into link list, then queues it up to | |
3089 | * be processed from user context. | |
3090 | * | |
3091 | * Return nothing. | |
3092 | */ | |
3093 | static void | |
3094 | _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event) | |
3095 | { | |
3096 | unsigned long flags; | |
3097 | ||
3098 | if (ioc->firmware_event_thread == NULL) | |
3099 | return; | |
3100 | ||
3101 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
146b16c8 | 3102 | fw_event_work_get(fw_event); |
f92363d1 SR |
3103 | INIT_LIST_HEAD(&fw_event->list); |
3104 | list_add_tail(&fw_event->list, &ioc->fw_event_list); | |
3105 | INIT_WORK(&fw_event->work, _firmware_event_work); | |
146b16c8 | 3106 | fw_event_work_get(fw_event); |
f92363d1 SR |
3107 | queue_work(ioc->firmware_event_thread, &fw_event->work); |
3108 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
3109 | } | |
3110 | ||
3111 | /** | |
146b16c8 | 3112 | * _scsih_fw_event_del_from_list - delete fw_event from the list |
f92363d1 SR |
3113 | * @ioc: per adapter object |
3114 | * @fw_event: object describing the event | |
3115 | * Context: This function will acquire ioc->fw_event_lock. | |
3116 | * | |
146b16c8 | 3117 | * If the fw_event is on the fw_event_list, remove it and do a put. |
f92363d1 SR |
3118 | * |
3119 | * Return nothing. | |
3120 | */ | |
3121 | static void | |
146b16c8 | 3122 | _scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work |
f92363d1 SR |
3123 | *fw_event) |
3124 | { | |
3125 | unsigned long flags; | |
3126 | ||
3127 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
146b16c8 SR |
3128 | if (!list_empty(&fw_event->list)) { |
3129 | list_del_init(&fw_event->list); | |
3130 | fw_event_work_put(fw_event); | |
3131 | } | |
f92363d1 SR |
3132 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
3133 | } | |
3134 | ||
3135 | ||
3136 | /** | |
3137 | * mpt3sas_send_trigger_data_event - send event for processing trigger data | |
3138 | * @ioc: per adapter object | |
3139 | * @event_data: trigger event data | |
3140 | * | |
3141 | * Return nothing. | |
3142 | */ | |
3143 | void | |
3144 | mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc, | |
3145 | struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data) | |
3146 | { | |
3147 | struct fw_event_work *fw_event; | |
146b16c8 | 3148 | u16 sz; |
f92363d1 SR |
3149 | |
3150 | if (ioc->is_driver_loading) | |
3151 | return; | |
146b16c8 SR |
3152 | sz = sizeof(*event_data); |
3153 | fw_event = alloc_fw_event_work(sz); | |
f92363d1 SR |
3154 | if (!fw_event) |
3155 | return; | |
f92363d1 SR |
3156 | fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG; |
3157 | fw_event->ioc = ioc; | |
3158 | memcpy(fw_event->event_data, event_data, sizeof(*event_data)); | |
3159 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 | 3160 | fw_event_work_put(fw_event); |
f92363d1 SR |
3161 | } |
3162 | ||
3163 | /** | |
3164 | * _scsih_error_recovery_delete_devices - remove devices not responding | |
3165 | * @ioc: per adapter object | |
3166 | * | |
3167 | * Return nothing. | |
3168 | */ | |
3169 | static void | |
3170 | _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc) | |
3171 | { | |
3172 | struct fw_event_work *fw_event; | |
3173 | ||
3174 | if (ioc->is_driver_loading) | |
3175 | return; | |
146b16c8 | 3176 | fw_event = alloc_fw_event_work(0); |
f92363d1 SR |
3177 | if (!fw_event) |
3178 | return; | |
3179 | fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES; | |
3180 | fw_event->ioc = ioc; | |
3181 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 | 3182 | fw_event_work_put(fw_event); |
f92363d1 SR |
3183 | } |
3184 | ||
3185 | /** | |
3186 | * mpt3sas_port_enable_complete - port enable completed (fake event) | |
3187 | * @ioc: per adapter object | |
3188 | * | |
3189 | * Return nothing. | |
3190 | */ | |
3191 | void | |
3192 | mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc) | |
3193 | { | |
3194 | struct fw_event_work *fw_event; | |
3195 | ||
146b16c8 | 3196 | fw_event = alloc_fw_event_work(0); |
f92363d1 SR |
3197 | if (!fw_event) |
3198 | return; | |
3199 | fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE; | |
3200 | fw_event->ioc = ioc; | |
3201 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 SR |
3202 | fw_event_work_put(fw_event); |
3203 | } | |
3204 | ||
3205 | static struct fw_event_work *dequeue_next_fw_event(struct MPT3SAS_ADAPTER *ioc) | |
3206 | { | |
3207 | unsigned long flags; | |
3208 | struct fw_event_work *fw_event = NULL; | |
3209 | ||
3210 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
3211 | if (!list_empty(&ioc->fw_event_list)) { | |
3212 | fw_event = list_first_entry(&ioc->fw_event_list, | |
3213 | struct fw_event_work, list); | |
3214 | list_del_init(&fw_event->list); | |
3215 | } | |
3216 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
3217 | ||
3218 | return fw_event; | |
f92363d1 SR |
3219 | } |
3220 | ||
3221 | /** | |
3222 | * _scsih_fw_event_cleanup_queue - cleanup event queue | |
3223 | * @ioc: per adapter object | |
3224 | * | |
3225 | * Walk the firmware event queue, either killing timers, or waiting | |
3226 | * for outstanding events to complete | |
3227 | * | |
3228 | * Return nothing. | |
3229 | */ | |
3230 | static void | |
3231 | _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc) | |
3232 | { | |
146b16c8 | 3233 | struct fw_event_work *fw_event; |
f92363d1 SR |
3234 | |
3235 | if (list_empty(&ioc->fw_event_list) || | |
3236 | !ioc->firmware_event_thread || in_interrupt()) | |
3237 | return; | |
3238 | ||
146b16c8 SR |
3239 | while ((fw_event = dequeue_next_fw_event(ioc))) { |
3240 | /* | |
3241 | * Wait on the fw_event to complete. If this returns 1, then | |
3242 | * the event was never executed, and we need a put for the | |
b8ac0cc7 | 3243 | * reference the work had on the fw_event. |
146b16c8 SR |
3244 | * |
3245 | * If it did execute, we wait for it to finish, and the put will | |
3246 | * happen from _firmware_event_work() | |
3247 | */ | |
b8ac0cc7 | 3248 | if (cancel_work_sync(&fw_event->work)) |
146b16c8 SR |
3249 | fw_event_work_put(fw_event); |
3250 | ||
3251 | fw_event_work_put(fw_event); | |
f92363d1 SR |
3252 | } |
3253 | } | |
3254 | ||
df838f92 SR |
3255 | /** |
3256 | * _scsih_internal_device_block - block the sdev device | |
3257 | * @sdev: per device object | |
3258 | * @sas_device_priv_data : per device driver private data | |
3259 | * | |
3260 | * make sure device is blocked without error, if not | |
3261 | * print an error | |
3262 | */ | |
3263 | static void | |
3264 | _scsih_internal_device_block(struct scsi_device *sdev, | |
3265 | struct MPT3SAS_DEVICE *sas_device_priv_data) | |
3266 | { | |
3267 | int r = 0; | |
3268 | ||
3269 | sdev_printk(KERN_INFO, sdev, "device_block, handle(0x%04x)\n", | |
3270 | sas_device_priv_data->sas_target->handle); | |
3271 | sas_device_priv_data->block = 1; | |
3272 | ||
551eb598 | 3273 | r = scsi_internal_device_block_nowait(sdev); |
df838f92 SR |
3274 | if (r == -EINVAL) |
3275 | sdev_printk(KERN_WARNING, sdev, | |
3276 | "device_block failed with return(%d) for handle(0x%04x)\n", | |
b2fe6be7 | 3277 | r, sas_device_priv_data->sas_target->handle); |
df838f92 SR |
3278 | } |
3279 | ||
3280 | /** | |
3281 | * _scsih_internal_device_unblock - unblock the sdev device | |
3282 | * @sdev: per device object | |
3283 | * @sas_device_priv_data : per device driver private data | |
3284 | * make sure device is unblocked without error, if not retry | |
3285 | * by blocking and then unblocking | |
3286 | */ | |
3287 | ||
3288 | static void | |
3289 | _scsih_internal_device_unblock(struct scsi_device *sdev, | |
3290 | struct MPT3SAS_DEVICE *sas_device_priv_data) | |
3291 | { | |
3292 | int r = 0; | |
3293 | ||
3294 | sdev_printk(KERN_WARNING, sdev, "device_unblock and setting to running, " | |
3295 | "handle(0x%04x)\n", sas_device_priv_data->sas_target->handle); | |
3296 | sas_device_priv_data->block = 0; | |
43f7571b | 3297 | r = scsi_internal_device_unblock_nowait(sdev, SDEV_RUNNING); |
df838f92 SR |
3298 | if (r == -EINVAL) { |
3299 | /* The device has been set to SDEV_RUNNING by SD layer during | |
3300 | * device addition but the request queue is still stopped by | |
3301 | * our earlier block call. We need to perform a block again | |
3302 | * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */ | |
3303 | ||
3304 | sdev_printk(KERN_WARNING, sdev, | |
3305 | "device_unblock failed with return(%d) for handle(0x%04x) " | |
3306 | "performing a block followed by an unblock\n", | |
b2fe6be7 | 3307 | r, sas_device_priv_data->sas_target->handle); |
df838f92 | 3308 | sas_device_priv_data->block = 1; |
551eb598 | 3309 | r = scsi_internal_device_block_nowait(sdev); |
df838f92 SR |
3310 | if (r) |
3311 | sdev_printk(KERN_WARNING, sdev, "retried device_block " | |
3312 | "failed with return(%d) for handle(0x%04x)\n", | |
b2fe6be7 | 3313 | r, sas_device_priv_data->sas_target->handle); |
df838f92 SR |
3314 | |
3315 | sas_device_priv_data->block = 0; | |
43f7571b | 3316 | r = scsi_internal_device_unblock_nowait(sdev, SDEV_RUNNING); |
df838f92 SR |
3317 | if (r) |
3318 | sdev_printk(KERN_WARNING, sdev, "retried device_unblock" | |
3319 | " failed with return(%d) for handle(0x%04x)\n", | |
b2fe6be7 | 3320 | r, sas_device_priv_data->sas_target->handle); |
df838f92 SR |
3321 | } |
3322 | } | |
3323 | ||
f92363d1 SR |
3324 | /** |
3325 | * _scsih_ublock_io_all_device - unblock every device | |
3326 | * @ioc: per adapter object | |
3327 | * | |
3328 | * change the device state from block to running | |
3329 | */ | |
3330 | static void | |
3331 | _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc) | |
3332 | { | |
3333 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
3334 | struct scsi_device *sdev; | |
3335 | ||
3336 | shost_for_each_device(sdev, ioc->shost) { | |
3337 | sas_device_priv_data = sdev->hostdata; | |
3338 | if (!sas_device_priv_data) | |
3339 | continue; | |
3340 | if (!sas_device_priv_data->block) | |
3341 | continue; | |
3342 | ||
f92363d1 SR |
3343 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, |
3344 | "device_running, handle(0x%04x)\n", | |
3345 | sas_device_priv_data->sas_target->handle)); | |
df838f92 | 3346 | _scsih_internal_device_unblock(sdev, sas_device_priv_data); |
f92363d1 SR |
3347 | } |
3348 | } | |
3349 | ||
3350 | ||
3351 | /** | |
3352 | * _scsih_ublock_io_device - prepare device to be deleted | |
3353 | * @ioc: per adapter object | |
3354 | * @sas_addr: sas address | |
3355 | * | |
3356 | * unblock then put device in offline state | |
3357 | */ | |
3358 | static void | |
3359 | _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address) | |
3360 | { | |
3361 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
3362 | struct scsi_device *sdev; | |
3363 | ||
3364 | shost_for_each_device(sdev, ioc->shost) { | |
3365 | sas_device_priv_data = sdev->hostdata; | |
3366 | if (!sas_device_priv_data) | |
3367 | continue; | |
3368 | if (sas_device_priv_data->sas_target->sas_address | |
3369 | != sas_address) | |
3370 | continue; | |
df838f92 SR |
3371 | if (sas_device_priv_data->block) |
3372 | _scsih_internal_device_unblock(sdev, | |
3373 | sas_device_priv_data); | |
f92363d1 SR |
3374 | } |
3375 | } | |
3376 | ||
3377 | /** | |
3378 | * _scsih_block_io_all_device - set the device state to SDEV_BLOCK | |
3379 | * @ioc: per adapter object | |
3380 | * @handle: device handle | |
3381 | * | |
6c7abffc | 3382 | * During device pull we need to appropriately set the sdev state. |
f92363d1 SR |
3383 | */ |
3384 | static void | |
3385 | _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc) | |
3386 | { | |
3387 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
3388 | struct scsi_device *sdev; | |
3389 | ||
3390 | shost_for_each_device(sdev, ioc->shost) { | |
3391 | sas_device_priv_data = sdev->hostdata; | |
3392 | if (!sas_device_priv_data) | |
3393 | continue; | |
3394 | if (sas_device_priv_data->block) | |
3395 | continue; | |
30158dc9 SS |
3396 | if (sas_device_priv_data->ignore_delay_remove) { |
3397 | sdev_printk(KERN_INFO, sdev, | |
3398 | "%s skip device_block for SES handle(0x%04x)\n", | |
3399 | __func__, sas_device_priv_data->sas_target->handle); | |
3400 | continue; | |
3401 | } | |
df838f92 | 3402 | _scsih_internal_device_block(sdev, sas_device_priv_data); |
f92363d1 SR |
3403 | } |
3404 | } | |
3405 | ||
3406 | /** | |
3407 | * _scsih_block_io_device - set the device state to SDEV_BLOCK | |
3408 | * @ioc: per adapter object | |
3409 | * @handle: device handle | |
3410 | * | |
6c7abffc | 3411 | * During device pull we need to appropriately set the sdev state. |
f92363d1 SR |
3412 | */ |
3413 | static void | |
3414 | _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
3415 | { | |
3416 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
3417 | struct scsi_device *sdev; | |
e4bc7f5c SR |
3418 | struct _sas_device *sas_device; |
3419 | ||
d1cb5e49 | 3420 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
3421 | |
3422 | shost_for_each_device(sdev, ioc->shost) { | |
3423 | sas_device_priv_data = sdev->hostdata; | |
3424 | if (!sas_device_priv_data) | |
3425 | continue; | |
3426 | if (sas_device_priv_data->sas_target->handle != handle) | |
3427 | continue; | |
3428 | if (sas_device_priv_data->block) | |
3429 | continue; | |
4318c734 | 3430 | if (sas_device && sas_device->pend_sas_rphy_add) |
e4bc7f5c | 3431 | continue; |
30158dc9 SS |
3432 | if (sas_device_priv_data->ignore_delay_remove) { |
3433 | sdev_printk(KERN_INFO, sdev, | |
3434 | "%s skip device_block for SES handle(0x%04x)\n", | |
3435 | __func__, sas_device_priv_data->sas_target->handle); | |
3436 | continue; | |
3437 | } | |
df838f92 | 3438 | _scsih_internal_device_block(sdev, sas_device_priv_data); |
f92363d1 | 3439 | } |
d1cb5e49 | 3440 | |
4318c734 SPS |
3441 | if (sas_device) |
3442 | sas_device_put(sas_device); | |
f92363d1 SR |
3443 | } |
3444 | ||
3445 | /** | |
3446 | * _scsih_block_io_to_children_attached_to_ex | |
3447 | * @ioc: per adapter object | |
3448 | * @sas_expander: the sas_device object | |
3449 | * | |
3450 | * This routine set sdev state to SDEV_BLOCK for all devices | |
3451 | * attached to this expander. This function called when expander is | |
3452 | * pulled. | |
3453 | */ | |
3454 | static void | |
3455 | _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc, | |
3456 | struct _sas_node *sas_expander) | |
3457 | { | |
3458 | struct _sas_port *mpt3sas_port; | |
3459 | struct _sas_device *sas_device; | |
3460 | struct _sas_node *expander_sibling; | |
3461 | unsigned long flags; | |
3462 | ||
3463 | if (!sas_expander) | |
3464 | return; | |
3465 | ||
3466 | list_for_each_entry(mpt3sas_port, | |
3467 | &sas_expander->sas_port_list, port_list) { | |
3468 | if (mpt3sas_port->remote_identify.device_type == | |
3469 | SAS_END_DEVICE) { | |
3470 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 SR |
3471 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
3472 | mpt3sas_port->remote_identify.sas_address); | |
3473 | if (sas_device) { | |
f92363d1 | 3474 | set_bit(sas_device->handle, |
d1cb5e49 SR |
3475 | ioc->blocking_handles); |
3476 | sas_device_put(sas_device); | |
3477 | } | |
f92363d1 SR |
3478 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
3479 | } | |
3480 | } | |
3481 | ||
3482 | list_for_each_entry(mpt3sas_port, | |
3483 | &sas_expander->sas_port_list, port_list) { | |
3484 | ||
3485 | if (mpt3sas_port->remote_identify.device_type == | |
3486 | SAS_EDGE_EXPANDER_DEVICE || | |
3487 | mpt3sas_port->remote_identify.device_type == | |
3488 | SAS_FANOUT_EXPANDER_DEVICE) { | |
3489 | expander_sibling = | |
3490 | mpt3sas_scsih_expander_find_by_sas_address( | |
3491 | ioc, mpt3sas_port->remote_identify.sas_address); | |
3492 | _scsih_block_io_to_children_attached_to_ex(ioc, | |
3493 | expander_sibling); | |
3494 | } | |
3495 | } | |
3496 | } | |
3497 | ||
3498 | /** | |
3499 | * _scsih_block_io_to_children_attached_directly | |
3500 | * @ioc: per adapter object | |
3501 | * @event_data: topology change event data | |
3502 | * | |
3503 | * This routine set sdev state to SDEV_BLOCK for all devices | |
3504 | * direct attached during device pull. | |
3505 | */ | |
3506 | static void | |
3507 | _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc, | |
3508 | Mpi2EventDataSasTopologyChangeList_t *event_data) | |
3509 | { | |
3510 | int i; | |
3511 | u16 handle; | |
3512 | u16 reason_code; | |
f92363d1 SR |
3513 | |
3514 | for (i = 0; i < event_data->NumEntries; i++) { | |
3515 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
3516 | if (!handle) | |
3517 | continue; | |
f92363d1 SR |
3518 | reason_code = event_data->PHY[i].PhyStatus & |
3519 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
3520 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING) | |
3521 | _scsih_block_io_device(ioc, handle); | |
3522 | } | |
3523 | } | |
3524 | ||
4318c734 SPS |
3525 | /** |
3526 | * _scsih_block_io_to_pcie_children_attached_directly | |
3527 | * @ioc: per adapter object | |
3528 | * @event_data: topology change event data | |
3529 | * | |
3530 | * This routine set sdev state to SDEV_BLOCK for all devices | |
3531 | * direct attached during device pull/reconnect. | |
3532 | */ | |
3533 | static void | |
3534 | _scsih_block_io_to_pcie_children_attached_directly(struct MPT3SAS_ADAPTER *ioc, | |
3535 | Mpi26EventDataPCIeTopologyChangeList_t *event_data) | |
3536 | { | |
3537 | int i; | |
3538 | u16 handle; | |
3539 | u16 reason_code; | |
3540 | ||
3541 | for (i = 0; i < event_data->NumEntries; i++) { | |
3542 | handle = | |
3543 | le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle); | |
3544 | if (!handle) | |
3545 | continue; | |
3546 | reason_code = event_data->PortEntry[i].PortStatus; | |
3547 | if (reason_code == | |
3548 | MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING) | |
3549 | _scsih_block_io_device(ioc, handle); | |
3550 | } | |
3551 | } | |
f92363d1 SR |
3552 | /** |
3553 | * _scsih_tm_tr_send - send task management request | |
3554 | * @ioc: per adapter object | |
3555 | * @handle: device handle | |
3556 | * Context: interrupt time. | |
3557 | * | |
3558 | * This code is to initiate the device removal handshake protocol | |
3559 | * with controller firmware. This function will issue target reset | |
3560 | * using high priority request queue. It will send a sas iounit | |
3561 | * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion. | |
3562 | * | |
3563 | * This is designed to send muliple task management request at the same | |
3564 | * time to the fifo. If the fifo is full, we will append the request, | |
3565 | * and process it in a future completion. | |
3566 | */ | |
3567 | static void | |
3568 | _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
3569 | { | |
3570 | Mpi2SCSITaskManagementRequest_t *mpi_request; | |
3571 | u16 smid; | |
d1cb5e49 | 3572 | struct _sas_device *sas_device = NULL; |
6ce2f1d1 | 3573 | struct _pcie_device *pcie_device = NULL; |
f92363d1 SR |
3574 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; |
3575 | u64 sas_address = 0; | |
3576 | unsigned long flags; | |
3577 | struct _tr_list *delayed_tr; | |
3578 | u32 ioc_state; | |
3579 | ||
6ce2f1d1 | 3580 | if (ioc->pci_error_recovery) { |
f92363d1 SR |
3581 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
3582 | "%s: host in pci error recovery: handle(0x%04x)\n", | |
3583 | __func__, ioc->name, | |
3584 | handle)); | |
3585 | return; | |
3586 | } | |
3587 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); | |
3588 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | |
3589 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3590 | "%s: host is not operational: handle(0x%04x)\n", | |
3591 | __func__, ioc->name, | |
3592 | handle)); | |
3593 | return; | |
3594 | } | |
3595 | ||
3596 | /* if PD, then return */ | |
3597 | if (test_bit(handle, ioc->pd_handles)) | |
3598 | return; | |
3599 | ||
c696f7b8 SPS |
3600 | clear_bit(handle, ioc->pend_os_device_add); |
3601 | ||
f92363d1 | 3602 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 3603 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
3604 | if (sas_device && sas_device->starget && |
3605 | sas_device->starget->hostdata) { | |
3606 | sas_target_priv_data = sas_device->starget->hostdata; | |
3607 | sas_target_priv_data->deleted = 1; | |
3608 | sas_address = sas_device->sas_address; | |
3609 | } | |
3610 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
6ce2f1d1 SPS |
3611 | if (!sas_device) { |
3612 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
3613 | pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle); | |
3614 | if (pcie_device && pcie_device->starget && | |
3615 | pcie_device->starget->hostdata) { | |
3616 | sas_target_priv_data = pcie_device->starget->hostdata; | |
3617 | sas_target_priv_data->deleted = 1; | |
3618 | sas_address = pcie_device->wwid; | |
3619 | } | |
3620 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
3621 | } | |
f92363d1 SR |
3622 | if (sas_target_priv_data) { |
3623 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3624 | "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n", | |
3625 | ioc->name, handle, | |
3626 | (unsigned long long)sas_address)); | |
6ce2f1d1 SPS |
3627 | if (sas_device) { |
3628 | if (sas_device->enclosure_handle != 0) | |
3629 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3630 | "setting delete flag:enclosure logical " | |
3631 | "id(0x%016llx), slot(%d)\n", ioc->name, | |
3632 | (unsigned long long) | |
3633 | sas_device->enclosure_logical_id, | |
3634 | sas_device->slot)); | |
3635 | if (sas_device->connector_name[0] != '\0') | |
3636 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3637 | "setting delete flag: enclosure " | |
3638 | "level(0x%04x), connector name( %s)\n", | |
3639 | ioc->name, sas_device->enclosure_level, | |
3640 | sas_device->connector_name)); | |
3641 | } else if (pcie_device) { | |
3642 | if (pcie_device->enclosure_handle != 0) | |
3643 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3644 | "setting delete flag: logical " | |
3645 | "id(0x%016llx), slot(%d)\n", ioc->name, | |
3646 | (unsigned long long) | |
3647 | pcie_device->enclosure_logical_id, | |
3648 | pcie_device->slot)); | |
3649 | if (pcie_device->connector_name[0] != '\0') | |
3650 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3651 | "setting delete flag:, enclosure " | |
3652 | "level(0x%04x), " | |
3653 | "connector name( %s)\n", ioc->name, | |
3654 | pcie_device->enclosure_level, | |
3655 | pcie_device->connector_name)); | |
3656 | } | |
f92363d1 SR |
3657 | _scsih_ublock_io_device(ioc, sas_address); |
3658 | sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE; | |
3659 | } | |
3660 | ||
3661 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx); | |
3662 | if (!smid) { | |
3663 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | |
3664 | if (!delayed_tr) | |
d1cb5e49 | 3665 | goto out; |
f92363d1 SR |
3666 | INIT_LIST_HEAD(&delayed_tr->list); |
3667 | delayed_tr->handle = handle; | |
3668 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); | |
3669 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3670 | "DELAYED:tr:handle(0x%04x), (open)\n", | |
3671 | ioc->name, handle)); | |
d1cb5e49 | 3672 | goto out; |
f92363d1 SR |
3673 | } |
3674 | ||
3675 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3676 | "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
3677 | ioc->name, handle, smid, | |
3678 | ioc->tm_tr_cb_idx)); | |
3679 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
3680 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | |
3681 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | |
3682 | mpi_request->DevHandle = cpu_to_le16(handle); | |
3683 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; | |
c696f7b8 | 3684 | set_bit(handle, ioc->device_remove_in_progress); |
81c16f83 | 3685 | ioc->put_smid_hi_priority(ioc, smid, 0); |
f92363d1 | 3686 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL); |
d1cb5e49 SR |
3687 | |
3688 | out: | |
3689 | if (sas_device) | |
3690 | sas_device_put(sas_device); | |
6ce2f1d1 SPS |
3691 | if (pcie_device) |
3692 | pcie_device_put(pcie_device); | |
f92363d1 SR |
3693 | } |
3694 | ||
3695 | /** | |
3696 | * _scsih_tm_tr_complete - | |
3697 | * @ioc: per adapter object | |
3698 | * @smid: system request message index | |
3699 | * @msix_index: MSIX table index supplied by the OS | |
3700 | * @reply: reply message frame(lower 32bit addr) | |
3701 | * Context: interrupt time. | |
3702 | * | |
3703 | * This is the target reset completion routine. | |
3704 | * This code is part of the code to initiate the device removal | |
3705 | * handshake protocol with controller firmware. | |
3706 | * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE) | |
3707 | * | |
3708 | * Return 1 meaning mf should be freed from _base_interrupt | |
3709 | * 0 means the mf is freed from this function. | |
3710 | */ | |
3711 | static u8 | |
3712 | _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, | |
3713 | u32 reply) | |
3714 | { | |
3715 | u16 handle; | |
3716 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; | |
3717 | Mpi2SCSITaskManagementReply_t *mpi_reply = | |
3718 | mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
3719 | Mpi2SasIoUnitControlRequest_t *mpi_request; | |
3720 | u16 smid_sas_ctrl; | |
3721 | u32 ioc_state; | |
fd0331b3 | 3722 | struct _sc_list *delayed_sc; |
f92363d1 SR |
3723 | |
3724 | if (ioc->remove_host) { | |
3725 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3726 | "%s: host has been removed\n", __func__, ioc->name)); | |
3727 | return 1; | |
3728 | } else if (ioc->pci_error_recovery) { | |
3729 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3730 | "%s: host in pci error recovery\n", __func__, | |
3731 | ioc->name)); | |
3732 | return 1; | |
3733 | } | |
3734 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); | |
3735 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | |
3736 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3737 | "%s: host is not operational\n", __func__, ioc->name)); | |
3738 | return 1; | |
3739 | } | |
3740 | if (unlikely(!mpi_reply)) { | |
3741 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", | |
3742 | ioc->name, __FILE__, __LINE__, __func__); | |
3743 | return 1; | |
3744 | } | |
3745 | mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid); | |
3746 | handle = le16_to_cpu(mpi_request_tm->DevHandle); | |
3747 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { | |
3748 | dewtprintk(ioc, pr_err(MPT3SAS_FMT | |
3749 | "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n", | |
3750 | ioc->name, handle, | |
3751 | le16_to_cpu(mpi_reply->DevHandle), smid)); | |
3752 | return 0; | |
3753 | } | |
3754 | ||
3755 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT); | |
3756 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3757 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " | |
3758 | "loginfo(0x%08x), completed(%d)\n", ioc->name, | |
3759 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), | |
3760 | le32_to_cpu(mpi_reply->IOCLogInfo), | |
3761 | le32_to_cpu(mpi_reply->TerminationCount))); | |
3762 | ||
3763 | smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx); | |
3764 | if (!smid_sas_ctrl) { | |
fd0331b3 SS |
3765 | delayed_sc = kzalloc(sizeof(*delayed_sc), GFP_ATOMIC); |
3766 | if (!delayed_sc) | |
3767 | return _scsih_check_for_pending_tm(ioc, smid); | |
3768 | INIT_LIST_HEAD(&delayed_sc->list); | |
3769 | delayed_sc->handle = mpi_request_tm->DevHandle; | |
3770 | list_add_tail(&delayed_sc->list, &ioc->delayed_sc_list); | |
3771 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3772 | "DELAYED:sc:handle(0x%04x), (open)\n", | |
3773 | ioc->name, handle)); | |
3774 | return _scsih_check_for_pending_tm(ioc, smid); | |
f92363d1 SR |
3775 | } |
3776 | ||
3777 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3778 | "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
3779 | ioc->name, handle, smid_sas_ctrl, | |
3780 | ioc->tm_sas_control_cb_idx)); | |
3781 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl); | |
3782 | memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t)); | |
3783 | mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; | |
3784 | mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE; | |
3785 | mpi_request->DevHandle = mpi_request_tm->DevHandle; | |
81c16f83 | 3786 | ioc->put_smid_default(ioc, smid_sas_ctrl); |
f92363d1 SR |
3787 | |
3788 | return _scsih_check_for_pending_tm(ioc, smid); | |
3789 | } | |
3790 | ||
3791 | ||
3792 | /** | |
3793 | * _scsih_sas_control_complete - completion routine | |
3794 | * @ioc: per adapter object | |
3795 | * @smid: system request message index | |
3796 | * @msix_index: MSIX table index supplied by the OS | |
3797 | * @reply: reply message frame(lower 32bit addr) | |
3798 | * Context: interrupt time. | |
3799 | * | |
3800 | * This is the sas iounit control completion routine. | |
3801 | * This code is part of the code to initiate the device removal | |
3802 | * handshake protocol with controller firmware. | |
3803 | * | |
3804 | * Return 1 meaning mf should be freed from _base_interrupt | |
3805 | * 0 means the mf is freed from this function. | |
3806 | */ | |
3807 | static u8 | |
3808 | _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, | |
3809 | u8 msix_index, u32 reply) | |
3810 | { | |
3811 | Mpi2SasIoUnitControlReply_t *mpi_reply = | |
3812 | mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
3813 | ||
3814 | if (likely(mpi_reply)) { | |
3815 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3816 | "sc_complete:handle(0x%04x), (open) " | |
3817 | "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n", | |
3818 | ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid, | |
3819 | le16_to_cpu(mpi_reply->IOCStatus), | |
3820 | le32_to_cpu(mpi_reply->IOCLogInfo))); | |
c696f7b8 SPS |
3821 | if (le16_to_cpu(mpi_reply->IOCStatus) == |
3822 | MPI2_IOCSTATUS_SUCCESS) { | |
3823 | clear_bit(le16_to_cpu(mpi_reply->DevHandle), | |
3824 | ioc->device_remove_in_progress); | |
3825 | } | |
f92363d1 SR |
3826 | } else { |
3827 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", | |
3828 | ioc->name, __FILE__, __LINE__, __func__); | |
3829 | } | |
fd0331b3 | 3830 | return mpt3sas_check_for_pending_internal_cmds(ioc, smid); |
f92363d1 SR |
3831 | } |
3832 | ||
3833 | /** | |
3834 | * _scsih_tm_tr_volume_send - send target reset request for volumes | |
3835 | * @ioc: per adapter object | |
3836 | * @handle: device handle | |
3837 | * Context: interrupt time. | |
3838 | * | |
3839 | * This is designed to send muliple task management request at the same | |
3840 | * time to the fifo. If the fifo is full, we will append the request, | |
3841 | * and process it in a future completion. | |
3842 | */ | |
3843 | static void | |
3844 | _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
3845 | { | |
3846 | Mpi2SCSITaskManagementRequest_t *mpi_request; | |
3847 | u16 smid; | |
3848 | struct _tr_list *delayed_tr; | |
3849 | ||
3850 | if (ioc->shost_recovery || ioc->remove_host || | |
3851 | ioc->pci_error_recovery) { | |
3852 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3853 | "%s: host reset in progress!\n", | |
3854 | __func__, ioc->name)); | |
3855 | return; | |
3856 | } | |
3857 | ||
3858 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx); | |
3859 | if (!smid) { | |
3860 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | |
3861 | if (!delayed_tr) | |
3862 | return; | |
3863 | INIT_LIST_HEAD(&delayed_tr->list); | |
3864 | delayed_tr->handle = handle; | |
3865 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list); | |
3866 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3867 | "DELAYED:tr:handle(0x%04x), (open)\n", | |
3868 | ioc->name, handle)); | |
3869 | return; | |
3870 | } | |
3871 | ||
3872 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3873 | "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
3874 | ioc->name, handle, smid, | |
3875 | ioc->tm_tr_volume_cb_idx)); | |
3876 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
3877 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | |
3878 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | |
3879 | mpi_request->DevHandle = cpu_to_le16(handle); | |
3880 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; | |
81c16f83 | 3881 | ioc->put_smid_hi_priority(ioc, smid, 0); |
f92363d1 SR |
3882 | } |
3883 | ||
3884 | /** | |
3885 | * _scsih_tm_volume_tr_complete - target reset completion | |
3886 | * @ioc: per adapter object | |
3887 | * @smid: system request message index | |
3888 | * @msix_index: MSIX table index supplied by the OS | |
3889 | * @reply: reply message frame(lower 32bit addr) | |
3890 | * Context: interrupt time. | |
3891 | * | |
3892 | * Return 1 meaning mf should be freed from _base_interrupt | |
3893 | * 0 means the mf is freed from this function. | |
3894 | */ | |
3895 | static u8 | |
3896 | _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, | |
3897 | u8 msix_index, u32 reply) | |
3898 | { | |
3899 | u16 handle; | |
3900 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; | |
3901 | Mpi2SCSITaskManagementReply_t *mpi_reply = | |
3902 | mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
3903 | ||
3904 | if (ioc->shost_recovery || ioc->remove_host || | |
3905 | ioc->pci_error_recovery) { | |
3906 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3907 | "%s: host reset in progress!\n", | |
3908 | __func__, ioc->name)); | |
3909 | return 1; | |
3910 | } | |
3911 | if (unlikely(!mpi_reply)) { | |
3912 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", | |
3913 | ioc->name, __FILE__, __LINE__, __func__); | |
3914 | return 1; | |
3915 | } | |
3916 | ||
3917 | mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid); | |
3918 | handle = le16_to_cpu(mpi_request_tm->DevHandle); | |
3919 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { | |
3920 | dewtprintk(ioc, pr_err(MPT3SAS_FMT | |
3921 | "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n", | |
3922 | ioc->name, handle, | |
3923 | le16_to_cpu(mpi_reply->DevHandle), smid)); | |
3924 | return 0; | |
3925 | } | |
3926 | ||
3927 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3928 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " | |
3929 | "loginfo(0x%08x), completed(%d)\n", ioc->name, | |
3930 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), | |
3931 | le32_to_cpu(mpi_reply->IOCLogInfo), | |
3932 | le32_to_cpu(mpi_reply->TerminationCount))); | |
3933 | ||
3934 | return _scsih_check_for_pending_tm(ioc, smid); | |
3935 | } | |
3936 | ||
fd0331b3 SS |
3937 | /** |
3938 | * _scsih_issue_delayed_event_ack - issue delayed Event ACK messages | |
3939 | * @ioc: per adapter object | |
3940 | * @smid: system request message index | |
3941 | * @event: Event ID | |
3942 | * @event_context: used to track events uniquely | |
3943 | * | |
3944 | * Context - processed in interrupt context. | |
3945 | */ | |
8bbb1cf6 | 3946 | static void |
fd0331b3 SS |
3947 | _scsih_issue_delayed_event_ack(struct MPT3SAS_ADAPTER *ioc, u16 smid, u16 event, |
3948 | u32 event_context) | |
3949 | { | |
3950 | Mpi2EventAckRequest_t *ack_request; | |
3951 | int i = smid - ioc->internal_smid; | |
3952 | unsigned long flags; | |
3953 | ||
3954 | /* Without releasing the smid just update the | |
3955 | * call back index and reuse the same smid for | |
3956 | * processing this delayed request | |
3957 | */ | |
3958 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
3959 | ioc->internal_lookup[i].cb_idx = ioc->base_cb_idx; | |
3960 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
3961 | ||
3962 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3963 | "EVENT ACK: event(0x%04x), smid(%d), cb(%d)\n", | |
3964 | ioc->name, le16_to_cpu(event), smid, | |
3965 | ioc->base_cb_idx)); | |
3966 | ack_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
3967 | memset(ack_request, 0, sizeof(Mpi2EventAckRequest_t)); | |
3968 | ack_request->Function = MPI2_FUNCTION_EVENT_ACK; | |
3969 | ack_request->Event = event; | |
3970 | ack_request->EventContext = event_context; | |
3971 | ack_request->VF_ID = 0; /* TODO */ | |
3972 | ack_request->VP_ID = 0; | |
81c16f83 | 3973 | ioc->put_smid_default(ioc, smid); |
fd0331b3 SS |
3974 | } |
3975 | ||
3976 | /** | |
3977 | * _scsih_issue_delayed_sas_io_unit_ctrl - issue delayed | |
3978 | * sas_io_unit_ctrl messages | |
3979 | * @ioc: per adapter object | |
3980 | * @smid: system request message index | |
3981 | * @handle: device handle | |
3982 | * | |
3983 | * Context - processed in interrupt context. | |
3984 | */ | |
8bbb1cf6 | 3985 | static void |
fd0331b3 SS |
3986 | _scsih_issue_delayed_sas_io_unit_ctrl(struct MPT3SAS_ADAPTER *ioc, |
3987 | u16 smid, u16 handle) | |
3988 | { | |
3989 | Mpi2SasIoUnitControlRequest_t *mpi_request; | |
3990 | u32 ioc_state; | |
3991 | int i = smid - ioc->internal_smid; | |
3992 | unsigned long flags; | |
3993 | ||
3994 | if (ioc->remove_host) { | |
3995 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3996 | "%s: host has been removed\n", | |
3997 | __func__, ioc->name)); | |
3998 | return; | |
3999 | } else if (ioc->pci_error_recovery) { | |
4000 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4001 | "%s: host in pci error recovery\n", | |
4002 | __func__, ioc->name)); | |
4003 | return; | |
4004 | } | |
4005 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); | |
4006 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | |
4007 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4008 | "%s: host is not operational\n", | |
4009 | __func__, ioc->name)); | |
4010 | return; | |
4011 | } | |
4012 | ||
4013 | /* Without releasing the smid just update the | |
4014 | * call back index and reuse the same smid for | |
4015 | * processing this delayed request | |
4016 | */ | |
4017 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
4018 | ioc->internal_lookup[i].cb_idx = ioc->tm_sas_control_cb_idx; | |
4019 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
4020 | ||
4021 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4022 | "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
4023 | ioc->name, le16_to_cpu(handle), smid, | |
4024 | ioc->tm_sas_control_cb_idx)); | |
4025 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
4026 | memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t)); | |
4027 | mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; | |
4028 | mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE; | |
4029 | mpi_request->DevHandle = handle; | |
81c16f83 | 4030 | ioc->put_smid_default(ioc, smid); |
fd0331b3 SS |
4031 | } |
4032 | ||
4033 | /** | |
4034 | * _scsih_check_for_pending_internal_cmds - check for pending internal messages | |
4035 | * @ioc: per adapter object | |
4036 | * @smid: system request message index | |
4037 | * | |
4038 | * Context: Executed in interrupt context | |
4039 | * | |
4040 | * This will check delayed internal messages list, and process the | |
4041 | * next request. | |
4042 | * | |
4043 | * Return 1 meaning mf should be freed from _base_interrupt | |
4044 | * 0 means the mf is freed from this function. | |
4045 | */ | |
4046 | u8 | |
4047 | mpt3sas_check_for_pending_internal_cmds(struct MPT3SAS_ADAPTER *ioc, u16 smid) | |
4048 | { | |
4049 | struct _sc_list *delayed_sc; | |
4050 | struct _event_ack_list *delayed_event_ack; | |
4051 | ||
4052 | if (!list_empty(&ioc->delayed_event_ack_list)) { | |
4053 | delayed_event_ack = list_entry(ioc->delayed_event_ack_list.next, | |
4054 | struct _event_ack_list, list); | |
4055 | _scsih_issue_delayed_event_ack(ioc, smid, | |
4056 | delayed_event_ack->Event, delayed_event_ack->EventContext); | |
4057 | list_del(&delayed_event_ack->list); | |
4058 | kfree(delayed_event_ack); | |
4059 | return 0; | |
4060 | } | |
4061 | ||
4062 | if (!list_empty(&ioc->delayed_sc_list)) { | |
4063 | delayed_sc = list_entry(ioc->delayed_sc_list.next, | |
4064 | struct _sc_list, list); | |
4065 | _scsih_issue_delayed_sas_io_unit_ctrl(ioc, smid, | |
4066 | delayed_sc->handle); | |
4067 | list_del(&delayed_sc->list); | |
4068 | kfree(delayed_sc); | |
4069 | return 0; | |
4070 | } | |
4071 | return 1; | |
4072 | } | |
f92363d1 SR |
4073 | |
4074 | /** | |
4075 | * _scsih_check_for_pending_tm - check for pending task management | |
4076 | * @ioc: per adapter object | |
4077 | * @smid: system request message index | |
4078 | * | |
4079 | * This will check delayed target reset list, and feed the | |
4080 | * next reqeust. | |
4081 | * | |
4082 | * Return 1 meaning mf should be freed from _base_interrupt | |
4083 | * 0 means the mf is freed from this function. | |
4084 | */ | |
4085 | static u8 | |
4086 | _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid) | |
4087 | { | |
4088 | struct _tr_list *delayed_tr; | |
4089 | ||
4090 | if (!list_empty(&ioc->delayed_tr_volume_list)) { | |
4091 | delayed_tr = list_entry(ioc->delayed_tr_volume_list.next, | |
4092 | struct _tr_list, list); | |
4093 | mpt3sas_base_free_smid(ioc, smid); | |
4094 | _scsih_tm_tr_volume_send(ioc, delayed_tr->handle); | |
4095 | list_del(&delayed_tr->list); | |
4096 | kfree(delayed_tr); | |
4097 | return 0; | |
4098 | } | |
4099 | ||
4100 | if (!list_empty(&ioc->delayed_tr_list)) { | |
4101 | delayed_tr = list_entry(ioc->delayed_tr_list.next, | |
4102 | struct _tr_list, list); | |
4103 | mpt3sas_base_free_smid(ioc, smid); | |
4104 | _scsih_tm_tr_send(ioc, delayed_tr->handle); | |
4105 | list_del(&delayed_tr->list); | |
4106 | kfree(delayed_tr); | |
4107 | return 0; | |
4108 | } | |
4109 | ||
4110 | return 1; | |
4111 | } | |
4112 | ||
4113 | /** | |
4114 | * _scsih_check_topo_delete_events - sanity check on topo events | |
4115 | * @ioc: per adapter object | |
4116 | * @event_data: the event data payload | |
4117 | * | |
4118 | * This routine added to better handle cable breaker. | |
4119 | * | |
4120 | * This handles the case where driver receives multiple expander | |
4121 | * add and delete events in a single shot. When there is a delete event | |
4122 | * the routine will void any pending add events waiting in the event queue. | |
4123 | * | |
4124 | * Return nothing. | |
4125 | */ | |
4126 | static void | |
4127 | _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc, | |
4128 | Mpi2EventDataSasTopologyChangeList_t *event_data) | |
4129 | { | |
4130 | struct fw_event_work *fw_event; | |
4131 | Mpi2EventDataSasTopologyChangeList_t *local_event_data; | |
4132 | u16 expander_handle; | |
4133 | struct _sas_node *sas_expander; | |
4134 | unsigned long flags; | |
4135 | int i, reason_code; | |
4136 | u16 handle; | |
4137 | ||
4138 | for (i = 0 ; i < event_data->NumEntries; i++) { | |
4139 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
4140 | if (!handle) | |
4141 | continue; | |
4142 | reason_code = event_data->PHY[i].PhyStatus & | |
4143 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
4144 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING) | |
4145 | _scsih_tm_tr_send(ioc, handle); | |
4146 | } | |
4147 | ||
4148 | expander_handle = le16_to_cpu(event_data->ExpanderDevHandle); | |
4149 | if (expander_handle < ioc->sas_hba.num_phys) { | |
4150 | _scsih_block_io_to_children_attached_directly(ioc, event_data); | |
4151 | return; | |
4152 | } | |
4153 | if (event_data->ExpStatus == | |
4154 | MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) { | |
4155 | /* put expander attached devices into blocking state */ | |
4156 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
4157 | sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc, | |
4158 | expander_handle); | |
4159 | _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander); | |
4160 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
4161 | do { | |
4162 | handle = find_first_bit(ioc->blocking_handles, | |
4163 | ioc->facts.MaxDevHandle); | |
4164 | if (handle < ioc->facts.MaxDevHandle) | |
4165 | _scsih_block_io_device(ioc, handle); | |
4166 | } while (test_and_clear_bit(handle, ioc->blocking_handles)); | |
4167 | } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING) | |
4168 | _scsih_block_io_to_children_attached_directly(ioc, event_data); | |
4169 | ||
4170 | if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) | |
4171 | return; | |
4172 | ||
4173 | /* mark ignore flag for pending events */ | |
4174 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
4175 | list_for_each_entry(fw_event, &ioc->fw_event_list, list) { | |
4176 | if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST || | |
4177 | fw_event->ignore) | |
4178 | continue; | |
35b62362 JL |
4179 | local_event_data = (Mpi2EventDataSasTopologyChangeList_t *) |
4180 | fw_event->event_data; | |
f92363d1 SR |
4181 | if (local_event_data->ExpStatus == |
4182 | MPI2_EVENT_SAS_TOPO_ES_ADDED || | |
4183 | local_event_data->ExpStatus == | |
4184 | MPI2_EVENT_SAS_TOPO_ES_RESPONDING) { | |
4185 | if (le16_to_cpu(local_event_data->ExpanderDevHandle) == | |
4186 | expander_handle) { | |
4187 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4188 | "setting ignoring flag\n", ioc->name)); | |
4189 | fw_event->ignore = 1; | |
4190 | } | |
4191 | } | |
4192 | } | |
4193 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
4194 | } | |
4195 | ||
4318c734 SPS |
4196 | /** |
4197 | * _scsih_check_pcie_topo_remove_events - sanity check on topo | |
4198 | * events | |
4199 | * @ioc: per adapter object | |
4200 | * @event_data: the event data payload | |
4201 | * | |
4202 | * This handles the case where driver receives multiple switch | |
4203 | * or device add and delete events in a single shot. When there | |
4204 | * is a delete event the routine will void any pending add | |
4205 | * events waiting in the event queue. | |
4206 | * | |
4207 | * Return nothing. | |
4208 | */ | |
4209 | static void | |
4210 | _scsih_check_pcie_topo_remove_events(struct MPT3SAS_ADAPTER *ioc, | |
4211 | Mpi26EventDataPCIeTopologyChangeList_t *event_data) | |
4212 | { | |
4213 | struct fw_event_work *fw_event; | |
4214 | Mpi26EventDataPCIeTopologyChangeList_t *local_event_data; | |
4215 | unsigned long flags; | |
4216 | int i, reason_code; | |
4217 | u16 handle, switch_handle; | |
4218 | ||
4219 | for (i = 0; i < event_data->NumEntries; i++) { | |
4220 | handle = | |
4221 | le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle); | |
4222 | if (!handle) | |
4223 | continue; | |
4224 | reason_code = event_data->PortEntry[i].PortStatus; | |
4225 | if (reason_code == MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING) | |
4226 | _scsih_tm_tr_send(ioc, handle); | |
4227 | } | |
4228 | ||
4229 | switch_handle = le16_to_cpu(event_data->SwitchDevHandle); | |
4230 | if (!switch_handle) { | |
4231 | _scsih_block_io_to_pcie_children_attached_directly( | |
4232 | ioc, event_data); | |
4233 | return; | |
4234 | } | |
4235 | /* TODO We are not supporting cascaded PCIe Switch removal yet*/ | |
4236 | if ((event_data->SwitchStatus | |
4237 | == MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING) || | |
4238 | (event_data->SwitchStatus == | |
4239 | MPI26_EVENT_PCIE_TOPO_SS_RESPONDING)) | |
4240 | _scsih_block_io_to_pcie_children_attached_directly( | |
4241 | ioc, event_data); | |
4242 | ||
4243 | if (event_data->SwitchStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) | |
4244 | return; | |
4245 | ||
4246 | /* mark ignore flag for pending events */ | |
4247 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
4248 | list_for_each_entry(fw_event, &ioc->fw_event_list, list) { | |
4249 | if (fw_event->event != MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST || | |
4250 | fw_event->ignore) | |
4251 | continue; | |
4252 | local_event_data = | |
4253 | (Mpi26EventDataPCIeTopologyChangeList_t *) | |
4254 | fw_event->event_data; | |
4255 | if (local_event_data->SwitchStatus == | |
4256 | MPI2_EVENT_SAS_TOPO_ES_ADDED || | |
4257 | local_event_data->SwitchStatus == | |
4258 | MPI2_EVENT_SAS_TOPO_ES_RESPONDING) { | |
4259 | if (le16_to_cpu(local_event_data->SwitchDevHandle) == | |
4260 | switch_handle) { | |
4261 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4262 | "setting ignoring flag for switch event\n", | |
4263 | ioc->name)); | |
4264 | fw_event->ignore = 1; | |
4265 | } | |
4266 | } | |
4267 | } | |
4268 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
4269 | } | |
4270 | ||
f92363d1 SR |
4271 | /** |
4272 | * _scsih_set_volume_delete_flag - setting volume delete flag | |
4273 | * @ioc: per adapter object | |
4274 | * @handle: device handle | |
4275 | * | |
4276 | * This returns nothing. | |
4277 | */ | |
4278 | static void | |
4279 | _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
4280 | { | |
4281 | struct _raid_device *raid_device; | |
4282 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
4283 | unsigned long flags; | |
4284 | ||
4285 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
c84b06a4 | 4286 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
4287 | if (raid_device && raid_device->starget && |
4288 | raid_device->starget->hostdata) { | |
4289 | sas_target_priv_data = | |
4290 | raid_device->starget->hostdata; | |
4291 | sas_target_priv_data->deleted = 1; | |
4292 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4293 | "setting delete flag: handle(0x%04x), " | |
4294 | "wwid(0x%016llx)\n", ioc->name, handle, | |
4295 | (unsigned long long) raid_device->wwid)); | |
4296 | } | |
4297 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
4298 | } | |
4299 | ||
4300 | /** | |
4301 | * _scsih_set_volume_handle_for_tr - set handle for target reset to volume | |
4302 | * @handle: input handle | |
4303 | * @a: handle for volume a | |
4304 | * @b: handle for volume b | |
4305 | * | |
4306 | * IR firmware only supports two raid volumes. The purpose of this | |
4307 | * routine is to set the volume handle in either a or b. When the given | |
4308 | * input handle is non-zero, or when a and b have not been set before. | |
4309 | */ | |
4310 | static void | |
4311 | _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b) | |
4312 | { | |
4313 | if (!handle || handle == *a || handle == *b) | |
4314 | return; | |
4315 | if (!*a) | |
4316 | *a = handle; | |
4317 | else if (!*b) | |
4318 | *b = handle; | |
4319 | } | |
4320 | ||
4321 | /** | |
4322 | * _scsih_check_ir_config_unhide_events - check for UNHIDE events | |
4323 | * @ioc: per adapter object | |
4324 | * @event_data: the event data payload | |
4325 | * Context: interrupt time. | |
4326 | * | |
4327 | * This routine will send target reset to volume, followed by target | |
4328 | * resets to the PDs. This is called when a PD has been removed, or | |
4329 | * volume has been deleted or removed. When the target reset is sent | |
4330 | * to volume, the PD target resets need to be queued to start upon | |
4331 | * completion of the volume target reset. | |
4332 | * | |
4333 | * Return nothing. | |
4334 | */ | |
4335 | static void | |
4336 | _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc, | |
4337 | Mpi2EventDataIrConfigChangeList_t *event_data) | |
4338 | { | |
4339 | Mpi2EventIrConfigElement_t *element; | |
4340 | int i; | |
4341 | u16 handle, volume_handle, a, b; | |
4342 | struct _tr_list *delayed_tr; | |
4343 | ||
4344 | a = 0; | |
4345 | b = 0; | |
4346 | ||
7786ab6a SR |
4347 | if (ioc->is_warpdrive) |
4348 | return; | |
4349 | ||
f92363d1 SR |
4350 | /* Volume Resets for Deleted or Removed */ |
4351 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
4352 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
4353 | if (le32_to_cpu(event_data->Flags) & | |
4354 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) | |
4355 | continue; | |
4356 | if (element->ReasonCode == | |
4357 | MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED || | |
4358 | element->ReasonCode == | |
4359 | MPI2_EVENT_IR_CHANGE_RC_REMOVED) { | |
4360 | volume_handle = le16_to_cpu(element->VolDevHandle); | |
4361 | _scsih_set_volume_delete_flag(ioc, volume_handle); | |
4362 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); | |
4363 | } | |
4364 | } | |
4365 | ||
4366 | /* Volume Resets for UNHIDE events */ | |
4367 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
4368 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
4369 | if (le32_to_cpu(event_data->Flags) & | |
4370 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) | |
4371 | continue; | |
4372 | if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) { | |
4373 | volume_handle = le16_to_cpu(element->VolDevHandle); | |
4374 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); | |
4375 | } | |
4376 | } | |
4377 | ||
4378 | if (a) | |
4379 | _scsih_tm_tr_volume_send(ioc, a); | |
4380 | if (b) | |
4381 | _scsih_tm_tr_volume_send(ioc, b); | |
4382 | ||
4383 | /* PD target resets */ | |
4384 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
4385 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
4386 | if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE) | |
4387 | continue; | |
4388 | handle = le16_to_cpu(element->PhysDiskDevHandle); | |
4389 | volume_handle = le16_to_cpu(element->VolDevHandle); | |
4390 | clear_bit(handle, ioc->pd_handles); | |
4391 | if (!volume_handle) | |
4392 | _scsih_tm_tr_send(ioc, handle); | |
4393 | else if (volume_handle == a || volume_handle == b) { | |
4394 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | |
4395 | BUG_ON(!delayed_tr); | |
4396 | INIT_LIST_HEAD(&delayed_tr->list); | |
4397 | delayed_tr->handle = handle; | |
4398 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); | |
4399 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4400 | "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name, | |
4401 | handle)); | |
4402 | } else | |
4403 | _scsih_tm_tr_send(ioc, handle); | |
4404 | } | |
4405 | } | |
4406 | ||
4407 | ||
4408 | /** | |
4409 | * _scsih_check_volume_delete_events - set delete flag for volumes | |
4410 | * @ioc: per adapter object | |
4411 | * @event_data: the event data payload | |
4412 | * Context: interrupt time. | |
4413 | * | |
4414 | * This will handle the case when the cable connected to entire volume is | |
4415 | * pulled. We will take care of setting the deleted flag so normal IO will | |
4416 | * not be sent. | |
4417 | * | |
4418 | * Return nothing. | |
4419 | */ | |
4420 | static void | |
4421 | _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc, | |
4422 | Mpi2EventDataIrVolume_t *event_data) | |
4423 | { | |
4424 | u32 state; | |
4425 | ||
4426 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) | |
4427 | return; | |
4428 | state = le32_to_cpu(event_data->NewValue); | |
4429 | if (state == MPI2_RAID_VOL_STATE_MISSING || state == | |
4430 | MPI2_RAID_VOL_STATE_FAILED) | |
4431 | _scsih_set_volume_delete_flag(ioc, | |
4432 | le16_to_cpu(event_data->VolDevHandle)); | |
4433 | } | |
4434 | ||
2d8ce8c9 SR |
4435 | /** |
4436 | * _scsih_temp_threshold_events - display temperature threshold exceeded events | |
4437 | * @ioc: per adapter object | |
4438 | * @event_data: the temp threshold event data | |
4439 | * Context: interrupt time. | |
4440 | * | |
4441 | * Return nothing. | |
4442 | */ | |
4443 | static void | |
4444 | _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER *ioc, | |
4445 | Mpi2EventDataTemperature_t *event_data) | |
4446 | { | |
4447 | if (ioc->temp_sensors_count >= event_data->SensorNum) { | |
4448 | pr_err(MPT3SAS_FMT "Temperature Threshold flags %s%s%s%s" | |
4449 | " exceeded for Sensor: %d !!!\n", ioc->name, | |
4450 | ((le16_to_cpu(event_data->Status) & 0x1) == 1) ? "0 " : " ", | |
4451 | ((le16_to_cpu(event_data->Status) & 0x2) == 2) ? "1 " : " ", | |
4452 | ((le16_to_cpu(event_data->Status) & 0x4) == 4) ? "2 " : " ", | |
4453 | ((le16_to_cpu(event_data->Status) & 0x8) == 8) ? "3 " : " ", | |
4454 | event_data->SensorNum); | |
4455 | pr_err(MPT3SAS_FMT "Current Temp In Celsius: %d\n", | |
4456 | ioc->name, event_data->CurrentTemperature); | |
4457 | } | |
4458 | } | |
4459 | ||
ffb58456 | 4460 | static int _scsih_set_satl_pending(struct scsi_cmnd *scmd, bool pending) |
7ff723ad | 4461 | { |
ffb58456 JB |
4462 | struct MPT3SAS_DEVICE *priv = scmd->device->hostdata; |
4463 | ||
4464 | if (scmd->cmnd[0] != ATA_12 && scmd->cmnd[0] != ATA_16) | |
4465 | return 0; | |
4466 | ||
4467 | if (pending) | |
4468 | return test_and_set_bit(0, &priv->ata_command_pending); | |
4469 | ||
4470 | clear_bit(0, &priv->ata_command_pending); | |
4471 | return 0; | |
7ff723ad SP |
4472 | } |
4473 | ||
f92363d1 SR |
4474 | /** |
4475 | * _scsih_flush_running_cmds - completing outstanding commands. | |
4476 | * @ioc: per adapter object | |
4477 | * | |
4478 | * The flushing out of all pending scmd commands following host reset, | |
4479 | * where all IO is dropped to the floor. | |
4480 | * | |
4481 | * Return nothing. | |
4482 | */ | |
4483 | static void | |
4484 | _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc) | |
4485 | { | |
4486 | struct scsi_cmnd *scmd; | |
4487 | u16 smid; | |
4488 | u16 count = 0; | |
4489 | ||
4490 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { | |
4491 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); | |
4492 | if (!scmd) | |
4493 | continue; | |
4494 | count++; | |
ffb58456 | 4495 | _scsih_set_satl_pending(scmd, false); |
f92363d1 SR |
4496 | mpt3sas_base_free_smid(ioc, smid); |
4497 | scsi_dma_unmap(scmd); | |
4498 | if (ioc->pci_error_recovery) | |
4499 | scmd->result = DID_NO_CONNECT << 16; | |
4500 | else | |
4501 | scmd->result = DID_RESET << 16; | |
4502 | scmd->scsi_done(scmd); | |
4503 | } | |
4504 | dtmprintk(ioc, pr_info(MPT3SAS_FMT "completing %d cmds\n", | |
4505 | ioc->name, count)); | |
4506 | } | |
4507 | ||
4508 | /** | |
4509 | * _scsih_setup_eedp - setup MPI request for EEDP transfer | |
4510 | * @ioc: per adapter object | |
4511 | * @scmd: pointer to scsi command object | |
6c7abffc | 4512 | * @mpi_request: pointer to the SCSI_IO request message frame |
f92363d1 SR |
4513 | * |
4514 | * Supporting protection 1 and 3. | |
4515 | * | |
4516 | * Returns nothing | |
4517 | */ | |
4518 | static void | |
4519 | _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, | |
016d5c35 | 4520 | Mpi25SCSIIORequest_t *mpi_request) |
f92363d1 SR |
4521 | { |
4522 | u16 eedp_flags; | |
4523 | unsigned char prot_op = scsi_get_prot_op(scmd); | |
4524 | unsigned char prot_type = scsi_get_prot_type(scmd); | |
4525 | Mpi25SCSIIORequest_t *mpi_request_3v = | |
4526 | (Mpi25SCSIIORequest_t *)mpi_request; | |
4527 | ||
4528 | if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL) | |
4529 | return; | |
4530 | ||
4531 | if (prot_op == SCSI_PROT_READ_STRIP) | |
4532 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP; | |
4533 | else if (prot_op == SCSI_PROT_WRITE_INSERT) | |
4534 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP; | |
4535 | else | |
4536 | return; | |
4537 | ||
4538 | switch (prot_type) { | |
4539 | case SCSI_PROT_DIF_TYPE1: | |
4540 | case SCSI_PROT_DIF_TYPE2: | |
4541 | ||
4542 | /* | |
4543 | * enable ref/guard checking | |
4544 | * auto increment ref tag | |
4545 | */ | |
4546 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG | | |
4547 | MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG | | |
4548 | MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; | |
4549 | mpi_request->CDB.EEDP32.PrimaryReferenceTag = | |
648512cc | 4550 | cpu_to_be32(scsi_prot_ref_tag(scmd)); |
f92363d1 SR |
4551 | break; |
4552 | ||
4553 | case SCSI_PROT_DIF_TYPE3: | |
4554 | ||
4555 | /* | |
4556 | * enable guard checking | |
4557 | */ | |
4558 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; | |
4559 | ||
4560 | break; | |
4561 | } | |
4562 | ||
4563 | mpi_request_3v->EEDPBlockSize = | |
4564 | cpu_to_le16(scmd->device->sector_size); | |
186a18e5 SPS |
4565 | |
4566 | if (ioc->is_gen35_ioc) | |
4567 | eedp_flags |= MPI25_SCSIIO_EEDPFLAGS_APPTAG_DISABLE_MODE; | |
f92363d1 SR |
4568 | mpi_request->EEDPFlags = cpu_to_le16(eedp_flags); |
4569 | } | |
4570 | ||
4571 | /** | |
4572 | * _scsih_eedp_error_handling - return sense code for EEDP errors | |
4573 | * @scmd: pointer to scsi command object | |
4574 | * @ioc_status: ioc status | |
4575 | * | |
4576 | * Returns nothing | |
4577 | */ | |
4578 | static void | |
4579 | _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status) | |
4580 | { | |
4581 | u8 ascq; | |
4582 | ||
4583 | switch (ioc_status) { | |
4584 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | |
4585 | ascq = 0x01; | |
4586 | break; | |
4587 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | |
4588 | ascq = 0x02; | |
4589 | break; | |
4590 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | |
4591 | ascq = 0x03; | |
4592 | break; | |
4593 | default: | |
4594 | ascq = 0x00; | |
4595 | break; | |
4596 | } | |
4597 | scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10, | |
4598 | ascq); | |
4599 | scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) | | |
4600 | SAM_STAT_CHECK_CONDITION; | |
4601 | } | |
4602 | ||
f92363d1 | 4603 | /** |
8a7e4c24 | 4604 | * scsih_qcmd - main scsi request entry point |
f92363d1 SR |
4605 | * @scmd: pointer to scsi command object |
4606 | * @done: function pointer to be invoked on completion | |
4607 | * | |
4608 | * The callback index is set inside `ioc->scsi_io_cb_idx`. | |
4609 | * | |
4610 | * Returns 0 on success. If there's a failure, return either: | |
4611 | * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or | |
4612 | * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full | |
4613 | */ | |
8bbb1cf6 | 4614 | static int |
8a7e4c24 | 4615 | scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd) |
f92363d1 | 4616 | { |
d8bfbd8d | 4617 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
f92363d1 SR |
4618 | struct MPT3SAS_DEVICE *sas_device_priv_data; |
4619 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
7786ab6a | 4620 | struct _raid_device *raid_device; |
307d9075 AM |
4621 | struct request *rq = scmd->request; |
4622 | int class; | |
016d5c35 SPS |
4623 | Mpi25SCSIIORequest_t *mpi_request; |
4624 | struct _pcie_device *pcie_device = NULL; | |
f92363d1 SR |
4625 | u32 mpi_control; |
4626 | u16 smid; | |
4627 | u16 handle; | |
4628 | ||
f92363d1 SR |
4629 | if (ioc->logging_level & MPT_DEBUG_SCSI) |
4630 | scsi_print_command(scmd); | |
f92363d1 | 4631 | |
f92363d1 SR |
4632 | sas_device_priv_data = scmd->device->hostdata; |
4633 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | |
4634 | scmd->result = DID_NO_CONNECT << 16; | |
4635 | scmd->scsi_done(scmd); | |
4636 | return 0; | |
4637 | } | |
4638 | ||
4639 | if (ioc->pci_error_recovery || ioc->remove_host) { | |
4640 | scmd->result = DID_NO_CONNECT << 16; | |
4641 | scmd->scsi_done(scmd); | |
4642 | return 0; | |
4643 | } | |
4644 | ||
4645 | sas_target_priv_data = sas_device_priv_data->sas_target; | |
4646 | ||
4647 | /* invalid device handle */ | |
4648 | handle = sas_target_priv_data->handle; | |
4649 | if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) { | |
4650 | scmd->result = DID_NO_CONNECT << 16; | |
4651 | scmd->scsi_done(scmd); | |
4652 | return 0; | |
4653 | } | |
4654 | ||
4655 | ||
4656 | /* host recovery or link resets sent via IOCTLs */ | |
4657 | if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress) | |
4658 | return SCSI_MLQUEUE_HOST_BUSY; | |
4659 | ||
4660 | /* device has been deleted */ | |
4661 | else if (sas_target_priv_data->deleted) { | |
4662 | scmd->result = DID_NO_CONNECT << 16; | |
4663 | scmd->scsi_done(scmd); | |
4664 | return 0; | |
6c7abffc | 4665 | /* device busy with task management */ |
f92363d1 SR |
4666 | } else if (sas_target_priv_data->tm_busy || |
4667 | sas_device_priv_data->block) | |
4668 | return SCSI_MLQUEUE_DEVICE_BUSY; | |
4669 | ||
f49d4aed C |
4670 | /* |
4671 | * Bug work around for firmware SATL handling. The loop | |
4672 | * is based on atomic operations and ensures consistency | |
4673 | * since we're lockless at this point | |
4674 | */ | |
4675 | do { | |
4676 | if (test_bit(0, &sas_device_priv_data->ata_command_pending)) { | |
4677 | scmd->result = SAM_STAT_BUSY; | |
4678 | scmd->scsi_done(scmd); | |
4679 | return 0; | |
4680 | } | |
4681 | } while (_scsih_set_satl_pending(scmd, true)); | |
4682 | ||
f92363d1 SR |
4683 | if (scmd->sc_data_direction == DMA_FROM_DEVICE) |
4684 | mpi_control = MPI2_SCSIIO_CONTROL_READ; | |
4685 | else if (scmd->sc_data_direction == DMA_TO_DEVICE) | |
4686 | mpi_control = MPI2_SCSIIO_CONTROL_WRITE; | |
4687 | else | |
4688 | mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER; | |
4689 | ||
4690 | /* set tags */ | |
609aa22f | 4691 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; |
307d9075 AM |
4692 | /* NCQ Prio supported, make sure control indicated high priority */ |
4693 | if (sas_device_priv_data->ncq_prio_enable) { | |
4694 | class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq)); | |
4695 | if (class == IOPRIO_CLASS_RT) | |
4696 | mpi_control |= 1 << MPI2_SCSIIO_CONTROL_CMDPRI_SHIFT; | |
4697 | } | |
7786ab6a SR |
4698 | /* Make sure Device is not raid volume. |
4699 | * We do not expose raid functionality to upper layer for warpdrive. | |
4700 | */ | |
cd5897ed SPS |
4701 | if (((!ioc->is_warpdrive && !scsih_is_raid(&scmd->device->sdev_gendev)) |
4702 | && !scsih_is_nvme(&scmd->device->sdev_gendev)) | |
4703 | && sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32) | |
f92363d1 SR |
4704 | mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON; |
4705 | ||
4706 | smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd); | |
4707 | if (!smid) { | |
4708 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
4709 | ioc->name, __func__); | |
f49d4aed | 4710 | _scsih_set_satl_pending(scmd, false); |
f92363d1 SR |
4711 | goto out; |
4712 | } | |
4713 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
016d5c35 | 4714 | memset(mpi_request, 0, ioc->request_sz); |
f92363d1 SR |
4715 | _scsih_setup_eedp(ioc, scmd, mpi_request); |
4716 | ||
4717 | if (scmd->cmd_len == 32) | |
4718 | mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT; | |
4719 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; | |
4720 | if (sas_device_priv_data->sas_target->flags & | |
4721 | MPT_TARGET_FLAGS_RAID_COMPONENT) | |
4722 | mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH; | |
4723 | else | |
4724 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; | |
4725 | mpi_request->DevHandle = cpu_to_le16(handle); | |
4726 | mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd)); | |
4727 | mpi_request->Control = cpu_to_le32(mpi_control); | |
4728 | mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len); | |
4729 | mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR; | |
4730 | mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE; | |
4731 | mpi_request->SenseBufferLowAddress = | |
4732 | mpt3sas_base_get_sense_buffer_dma(ioc, smid); | |
016d5c35 | 4733 | mpi_request->SGLOffset0 = offsetof(Mpi25SCSIIORequest_t, SGL) / 4; |
f92363d1 SR |
4734 | int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *) |
4735 | mpi_request->LUN); | |
4736 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); | |
4737 | ||
4738 | if (mpi_request->DataLength) { | |
016d5c35 SPS |
4739 | pcie_device = sas_target_priv_data->pcie_dev; |
4740 | if (ioc->build_sg_scmd(ioc, scmd, smid, pcie_device)) { | |
f92363d1 | 4741 | mpt3sas_base_free_smid(ioc, smid); |
f49d4aed | 4742 | _scsih_set_satl_pending(scmd, false); |
f92363d1 SR |
4743 | goto out; |
4744 | } | |
4745 | } else | |
4746 | ioc->build_zero_len_sge(ioc, &mpi_request->SGL); | |
4747 | ||
7786ab6a SR |
4748 | raid_device = sas_target_priv_data->raid_device; |
4749 | if (raid_device && raid_device->direct_io_enabled) | |
cd5897ed SPS |
4750 | mpt3sas_setup_direct_io(ioc, scmd, |
4751 | raid_device, mpi_request, smid); | |
7786ab6a | 4752 | |
f92363d1 SR |
4753 | if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) { |
4754 | if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) { | |
4755 | mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len | | |
4756 | MPI25_SCSIIO_IOFLAGS_FAST_PATH); | |
81c16f83 | 4757 | ioc->put_smid_fast_path(ioc, smid, handle); |
f92363d1 | 4758 | } else |
81c16f83 | 4759 | ioc->put_smid_scsi_io(ioc, smid, |
7786ab6a | 4760 | le16_to_cpu(mpi_request->DevHandle)); |
f92363d1 | 4761 | } else |
81c16f83 | 4762 | ioc->put_smid_default(ioc, smid); |
f92363d1 SR |
4763 | return 0; |
4764 | ||
4765 | out: | |
4766 | return SCSI_MLQUEUE_HOST_BUSY; | |
4767 | } | |
f92363d1 SR |
4768 | |
4769 | /** | |
4770 | * _scsih_normalize_sense - normalize descriptor and fixed format sense data | |
4771 | * @sense_buffer: sense data returned by target | |
4772 | * @data: normalized skey/asc/ascq | |
4773 | * | |
4774 | * Return nothing. | |
4775 | */ | |
4776 | static void | |
4777 | _scsih_normalize_sense(char *sense_buffer, struct sense_info *data) | |
4778 | { | |
4779 | if ((sense_buffer[0] & 0x7F) >= 0x72) { | |
4780 | /* descriptor format */ | |
4781 | data->skey = sense_buffer[1] & 0x0F; | |
4782 | data->asc = sense_buffer[2]; | |
4783 | data->ascq = sense_buffer[3]; | |
4784 | } else { | |
4785 | /* fixed format */ | |
4786 | data->skey = sense_buffer[2] & 0x0F; | |
4787 | data->asc = sense_buffer[12]; | |
4788 | data->ascq = sense_buffer[13]; | |
4789 | } | |
4790 | } | |
4791 | ||
f92363d1 SR |
4792 | /** |
4793 | * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request | |
4794 | * @ioc: per adapter object | |
4795 | * @scmd: pointer to scsi command object | |
4796 | * @mpi_reply: reply mf payload returned from firmware | |
4797 | * | |
4798 | * scsi_status - SCSI Status code returned from target device | |
4799 | * scsi_state - state info associated with SCSI_IO determined by ioc | |
4800 | * ioc_status - ioc supplied status info | |
4801 | * | |
4802 | * Return nothing. | |
4803 | */ | |
4804 | static void | |
4805 | _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, | |
4806 | Mpi2SCSIIOReply_t *mpi_reply, u16 smid) | |
4807 | { | |
4808 | u32 response_info; | |
4809 | u8 *response_bytes; | |
4810 | u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & | |
4811 | MPI2_IOCSTATUS_MASK; | |
4812 | u8 scsi_state = mpi_reply->SCSIState; | |
4813 | u8 scsi_status = mpi_reply->SCSIStatus; | |
4814 | char *desc_ioc_state = NULL; | |
4815 | char *desc_scsi_status = NULL; | |
4816 | char *desc_scsi_state = ioc->tmp_string; | |
4817 | u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo); | |
4818 | struct _sas_device *sas_device = NULL; | |
ec051e5a | 4819 | struct _pcie_device *pcie_device = NULL; |
f92363d1 SR |
4820 | struct scsi_target *starget = scmd->device->sdev_target; |
4821 | struct MPT3SAS_TARGET *priv_target = starget->hostdata; | |
4822 | char *device_str = NULL; | |
4823 | ||
4824 | if (!priv_target) | |
4825 | return; | |
7786ab6a SR |
4826 | if (ioc->hide_ir_msg) |
4827 | device_str = "WarpDrive"; | |
4828 | else | |
4829 | device_str = "volume"; | |
f92363d1 SR |
4830 | |
4831 | if (log_info == 0x31170000) | |
4832 | return; | |
4833 | ||
4834 | switch (ioc_status) { | |
4835 | case MPI2_IOCSTATUS_SUCCESS: | |
4836 | desc_ioc_state = "success"; | |
4837 | break; | |
4838 | case MPI2_IOCSTATUS_INVALID_FUNCTION: | |
4839 | desc_ioc_state = "invalid function"; | |
4840 | break; | |
4841 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: | |
4842 | desc_ioc_state = "scsi recovered error"; | |
4843 | break; | |
4844 | case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE: | |
4845 | desc_ioc_state = "scsi invalid dev handle"; | |
4846 | break; | |
4847 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: | |
4848 | desc_ioc_state = "scsi device not there"; | |
4849 | break; | |
4850 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: | |
4851 | desc_ioc_state = "scsi data overrun"; | |
4852 | break; | |
4853 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: | |
4854 | desc_ioc_state = "scsi data underrun"; | |
4855 | break; | |
4856 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: | |
4857 | desc_ioc_state = "scsi io data error"; | |
4858 | break; | |
4859 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: | |
4860 | desc_ioc_state = "scsi protocol error"; | |
4861 | break; | |
4862 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: | |
4863 | desc_ioc_state = "scsi task terminated"; | |
4864 | break; | |
4865 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: | |
4866 | desc_ioc_state = "scsi residual mismatch"; | |
4867 | break; | |
4868 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: | |
4869 | desc_ioc_state = "scsi task mgmt failed"; | |
4870 | break; | |
4871 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: | |
4872 | desc_ioc_state = "scsi ioc terminated"; | |
4873 | break; | |
4874 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: | |
4875 | desc_ioc_state = "scsi ext terminated"; | |
4876 | break; | |
4877 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | |
4878 | desc_ioc_state = "eedp guard error"; | |
4879 | break; | |
4880 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | |
4881 | desc_ioc_state = "eedp ref tag error"; | |
4882 | break; | |
4883 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | |
4884 | desc_ioc_state = "eedp app tag error"; | |
4885 | break; | |
b130b0d5 SS |
4886 | case MPI2_IOCSTATUS_INSUFFICIENT_POWER: |
4887 | desc_ioc_state = "insufficient power"; | |
4888 | break; | |
f92363d1 SR |
4889 | default: |
4890 | desc_ioc_state = "unknown"; | |
4891 | break; | |
4892 | } | |
4893 | ||
4894 | switch (scsi_status) { | |
4895 | case MPI2_SCSI_STATUS_GOOD: | |
4896 | desc_scsi_status = "good"; | |
4897 | break; | |
4898 | case MPI2_SCSI_STATUS_CHECK_CONDITION: | |
4899 | desc_scsi_status = "check condition"; | |
4900 | break; | |
4901 | case MPI2_SCSI_STATUS_CONDITION_MET: | |
4902 | desc_scsi_status = "condition met"; | |
4903 | break; | |
4904 | case MPI2_SCSI_STATUS_BUSY: | |
4905 | desc_scsi_status = "busy"; | |
4906 | break; | |
4907 | case MPI2_SCSI_STATUS_INTERMEDIATE: | |
4908 | desc_scsi_status = "intermediate"; | |
4909 | break; | |
4910 | case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET: | |
4911 | desc_scsi_status = "intermediate condmet"; | |
4912 | break; | |
4913 | case MPI2_SCSI_STATUS_RESERVATION_CONFLICT: | |
4914 | desc_scsi_status = "reservation conflict"; | |
4915 | break; | |
4916 | case MPI2_SCSI_STATUS_COMMAND_TERMINATED: | |
4917 | desc_scsi_status = "command terminated"; | |
4918 | break; | |
4919 | case MPI2_SCSI_STATUS_TASK_SET_FULL: | |
4920 | desc_scsi_status = "task set full"; | |
4921 | break; | |
4922 | case MPI2_SCSI_STATUS_ACA_ACTIVE: | |
4923 | desc_scsi_status = "aca active"; | |
4924 | break; | |
4925 | case MPI2_SCSI_STATUS_TASK_ABORTED: | |
4926 | desc_scsi_status = "task aborted"; | |
4927 | break; | |
4928 | default: | |
4929 | desc_scsi_status = "unknown"; | |
4930 | break; | |
4931 | } | |
4932 | ||
4933 | desc_scsi_state[0] = '\0'; | |
4934 | if (!scsi_state) | |
4935 | desc_scsi_state = " "; | |
4936 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) | |
4937 | strcat(desc_scsi_state, "response info "); | |
4938 | if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | |
4939 | strcat(desc_scsi_state, "state terminated "); | |
4940 | if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS) | |
4941 | strcat(desc_scsi_state, "no status "); | |
4942 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED) | |
4943 | strcat(desc_scsi_state, "autosense failed "); | |
4944 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) | |
4945 | strcat(desc_scsi_state, "autosense valid "); | |
4946 | ||
4947 | scsi_print_command(scmd); | |
4948 | ||
4949 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { | |
4950 | pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name, | |
4951 | device_str, (unsigned long long)priv_target->sas_address); | |
ec051e5a SPS |
4952 | } else if (priv_target->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) { |
4953 | pcie_device = mpt3sas_get_pdev_from_target(ioc, priv_target); | |
4954 | if (pcie_device) { | |
4955 | pr_info(MPT3SAS_FMT "\twwid(0x%016llx), port(%d)\n", | |
4956 | ioc->name, | |
4957 | (unsigned long long)pcie_device->wwid, | |
4958 | pcie_device->port_num); | |
4959 | if (pcie_device->enclosure_handle != 0) | |
4960 | pr_info(MPT3SAS_FMT | |
4961 | "\tenclosure logical id(0x%016llx), " | |
4962 | "slot(%d)\n", ioc->name, | |
4963 | (unsigned long long) | |
4964 | pcie_device->enclosure_logical_id, | |
4965 | pcie_device->slot); | |
4966 | if (pcie_device->connector_name[0]) | |
4967 | pr_info(MPT3SAS_FMT | |
4968 | "\tenclosure level(0x%04x)," | |
4969 | "connector name( %s)\n", | |
4970 | ioc->name, pcie_device->enclosure_level, | |
4971 | pcie_device->connector_name); | |
4972 | pcie_device_put(pcie_device); | |
4973 | } | |
f92363d1 | 4974 | } else { |
d1cb5e49 | 4975 | sas_device = mpt3sas_get_sdev_from_target(ioc, priv_target); |
f92363d1 SR |
4976 | if (sas_device) { |
4977 | pr_warn(MPT3SAS_FMT | |
4978 | "\tsas_address(0x%016llx), phy(%d)\n", | |
4979 | ioc->name, (unsigned long long) | |
4980 | sas_device->sas_address, sas_device->phy); | |
75888956 SR |
4981 | |
4982 | _scsih_display_enclosure_chassis_info(ioc, sas_device, | |
4983 | NULL, NULL); | |
d1cb5e49 SR |
4984 | |
4985 | sas_device_put(sas_device); | |
f92363d1 | 4986 | } |
f92363d1 SR |
4987 | } |
4988 | ||
4989 | pr_warn(MPT3SAS_FMT | |
4990 | "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n", | |
4991 | ioc->name, le16_to_cpu(mpi_reply->DevHandle), | |
4992 | desc_ioc_state, ioc_status, smid); | |
4993 | pr_warn(MPT3SAS_FMT | |
4994 | "\trequest_len(%d), underflow(%d), resid(%d)\n", | |
4995 | ioc->name, scsi_bufflen(scmd), scmd->underflow, | |
4996 | scsi_get_resid(scmd)); | |
4997 | pr_warn(MPT3SAS_FMT | |
4998 | "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n", | |
4999 | ioc->name, le16_to_cpu(mpi_reply->TaskTag), | |
5000 | le32_to_cpu(mpi_reply->TransferCount), scmd->result); | |
5001 | pr_warn(MPT3SAS_FMT | |
5002 | "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n", | |
5003 | ioc->name, desc_scsi_status, | |
5004 | scsi_status, desc_scsi_state, scsi_state); | |
5005 | ||
5006 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { | |
5007 | struct sense_info data; | |
5008 | _scsih_normalize_sense(scmd->sense_buffer, &data); | |
5009 | pr_warn(MPT3SAS_FMT | |
ec051e5a SPS |
5010 | "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n", |
5011 | ioc->name, data.skey, | |
5012 | data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount)); | |
f92363d1 | 5013 | } |
f92363d1 SR |
5014 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) { |
5015 | response_info = le32_to_cpu(mpi_reply->ResponseInfo); | |
5016 | response_bytes = (u8 *)&response_info; | |
5017 | _scsih_response_code(ioc, response_bytes[0]); | |
5018 | } | |
5019 | } | |
f92363d1 SR |
5020 | |
5021 | /** | |
0f624c39 | 5022 | * _scsih_turn_on_pfa_led - illuminate PFA LED |
f92363d1 SR |
5023 | * @ioc: per adapter object |
5024 | * @handle: device handle | |
5025 | * Context: process | |
5026 | * | |
5027 | * Return nothing. | |
5028 | */ | |
5029 | static void | |
0f624c39 | 5030 | _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
f92363d1 SR |
5031 | { |
5032 | Mpi2SepReply_t mpi_reply; | |
5033 | Mpi2SepRequest_t mpi_request; | |
0f624c39 SR |
5034 | struct _sas_device *sas_device; |
5035 | ||
d1cb5e49 | 5036 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
0f624c39 SR |
5037 | if (!sas_device) |
5038 | return; | |
f92363d1 SR |
5039 | |
5040 | memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t)); | |
5041 | mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; | |
5042 | mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; | |
5043 | mpi_request.SlotStatus = | |
5044 | cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT); | |
5045 | mpi_request.DevHandle = cpu_to_le16(handle); | |
5046 | mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS; | |
5047 | if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply, | |
5048 | &mpi_request)) != 0) { | |
5049 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name, | |
5050 | __FILE__, __LINE__, __func__); | |
d1cb5e49 | 5051 | goto out; |
f92363d1 | 5052 | } |
0f624c39 | 5053 | sas_device->pfa_led_on = 1; |
f92363d1 SR |
5054 | |
5055 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) { | |
5056 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
5057 | "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n", | |
5058 | ioc->name, le16_to_cpu(mpi_reply.IOCStatus), | |
5059 | le32_to_cpu(mpi_reply.IOCLogInfo))); | |
d1cb5e49 | 5060 | goto out; |
f92363d1 | 5061 | } |
d1cb5e49 SR |
5062 | out: |
5063 | sas_device_put(sas_device); | |
f92363d1 | 5064 | } |
d1cb5e49 | 5065 | |
0f624c39 SR |
5066 | /** |
5067 | * _scsih_turn_off_pfa_led - turn off Fault LED | |
5068 | * @ioc: per adapter object | |
5069 | * @sas_device: sas device whose PFA LED has to turned off | |
5070 | * Context: process | |
5071 | * | |
5072 | * Return nothing. | |
5073 | */ | |
5074 | static void | |
5075 | _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc, | |
5076 | struct _sas_device *sas_device) | |
5077 | { | |
5078 | Mpi2SepReply_t mpi_reply; | |
5079 | Mpi2SepRequest_t mpi_request; | |
f92363d1 | 5080 | |
0f624c39 SR |
5081 | memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t)); |
5082 | mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; | |
5083 | mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; | |
5084 | mpi_request.SlotStatus = 0; | |
5085 | mpi_request.Slot = cpu_to_le16(sas_device->slot); | |
5086 | mpi_request.DevHandle = 0; | |
5087 | mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle); | |
5088 | mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS; | |
5089 | if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply, | |
5090 | &mpi_request)) != 0) { | |
5091 | printk(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name, | |
5092 | __FILE__, __LINE__, __func__); | |
5093 | return; | |
5094 | } | |
5095 | ||
5096 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) { | |
5097 | dewtprintk(ioc, printk(MPT3SAS_FMT | |
5098 | "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n", | |
5099 | ioc->name, le16_to_cpu(mpi_reply.IOCStatus), | |
5100 | le32_to_cpu(mpi_reply.IOCLogInfo))); | |
5101 | return; | |
5102 | } | |
5103 | } | |
d1cb5e49 | 5104 | |
f92363d1 | 5105 | /** |
0f624c39 | 5106 | * _scsih_send_event_to_turn_on_pfa_led - fire delayed event |
f92363d1 SR |
5107 | * @ioc: per adapter object |
5108 | * @handle: device handle | |
5109 | * Context: interrupt. | |
5110 | * | |
5111 | * Return nothing. | |
5112 | */ | |
5113 | static void | |
0f624c39 | 5114 | _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
f92363d1 SR |
5115 | { |
5116 | struct fw_event_work *fw_event; | |
5117 | ||
146b16c8 | 5118 | fw_event = alloc_fw_event_work(0); |
f92363d1 SR |
5119 | if (!fw_event) |
5120 | return; | |
0f624c39 | 5121 | fw_event->event = MPT3SAS_TURN_ON_PFA_LED; |
f92363d1 SR |
5122 | fw_event->device_handle = handle; |
5123 | fw_event->ioc = ioc; | |
5124 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 | 5125 | fw_event_work_put(fw_event); |
f92363d1 SR |
5126 | } |
5127 | ||
5128 | /** | |
5129 | * _scsih_smart_predicted_fault - process smart errors | |
5130 | * @ioc: per adapter object | |
5131 | * @handle: device handle | |
5132 | * Context: interrupt. | |
5133 | * | |
5134 | * Return nothing. | |
5135 | */ | |
5136 | static void | |
5137 | _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
5138 | { | |
5139 | struct scsi_target *starget; | |
5140 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
5141 | Mpi2EventNotificationReply_t *event_reply; | |
5142 | Mpi2EventDataSasDeviceStatusChange_t *event_data; | |
5143 | struct _sas_device *sas_device; | |
5144 | ssize_t sz; | |
5145 | unsigned long flags; | |
5146 | ||
5147 | /* only handle non-raid devices */ | |
5148 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 SR |
5149 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
5150 | if (!sas_device) | |
5151 | goto out_unlock; | |
5152 | ||
f92363d1 SR |
5153 | starget = sas_device->starget; |
5154 | sas_target_priv_data = starget->hostdata; | |
5155 | ||
5156 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) || | |
d1cb5e49 SR |
5157 | ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) |
5158 | goto out_unlock; | |
5159 | ||
75888956 SR |
5160 | _scsih_display_enclosure_chassis_info(NULL, sas_device, NULL, starget); |
5161 | ||
f92363d1 SR |
5162 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
5163 | ||
5164 | if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) | |
0f624c39 | 5165 | _scsih_send_event_to_turn_on_pfa_led(ioc, handle); |
f92363d1 SR |
5166 | |
5167 | /* insert into event log */ | |
5168 | sz = offsetof(Mpi2EventNotificationReply_t, EventData) + | |
5169 | sizeof(Mpi2EventDataSasDeviceStatusChange_t); | |
5170 | event_reply = kzalloc(sz, GFP_KERNEL); | |
5171 | if (!event_reply) { | |
5172 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5173 | ioc->name, __FILE__, __LINE__, __func__); | |
d1cb5e49 | 5174 | goto out; |
f92363d1 SR |
5175 | } |
5176 | ||
5177 | event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION; | |
5178 | event_reply->Event = | |
5179 | cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE); | |
5180 | event_reply->MsgLength = sz/4; | |
5181 | event_reply->EventDataLength = | |
5182 | cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4); | |
5183 | event_data = (Mpi2EventDataSasDeviceStatusChange_t *) | |
5184 | event_reply->EventData; | |
5185 | event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA; | |
5186 | event_data->ASC = 0x5D; | |
5187 | event_data->DevHandle = cpu_to_le16(handle); | |
5188 | event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address); | |
5189 | mpt3sas_ctl_add_to_event_log(ioc, event_reply); | |
5190 | kfree(event_reply); | |
d1cb5e49 SR |
5191 | out: |
5192 | if (sas_device) | |
5193 | sas_device_put(sas_device); | |
5194 | return; | |
5195 | ||
5196 | out_unlock: | |
5197 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
5198 | goto out; | |
f92363d1 SR |
5199 | } |
5200 | ||
5201 | /** | |
5202 | * _scsih_io_done - scsi request callback | |
5203 | * @ioc: per adapter object | |
5204 | * @smid: system request message index | |
5205 | * @msix_index: MSIX table index supplied by the OS | |
5206 | * @reply: reply message frame(lower 32bit addr) | |
5207 | * | |
5208 | * Callback handler when using _scsih_qcmd. | |
5209 | * | |
5210 | * Return 1 meaning mf should be freed from _base_interrupt | |
5211 | * 0 means the mf is freed from this function. | |
5212 | */ | |
5213 | static u8 | |
5214 | _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | |
5215 | { | |
016d5c35 | 5216 | Mpi25SCSIIORequest_t *mpi_request; |
f92363d1 SR |
5217 | Mpi2SCSIIOReply_t *mpi_reply; |
5218 | struct scsi_cmnd *scmd; | |
5219 | u16 ioc_status; | |
5220 | u32 xfer_cnt; | |
5221 | u8 scsi_state; | |
5222 | u8 scsi_status; | |
5223 | u32 log_info; | |
5224 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
5225 | u32 response_code = 0; | |
7786ab6a | 5226 | unsigned long flags; |
f92363d1 SR |
5227 | |
5228 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
459325c4 C |
5229 | |
5230 | if (ioc->broadcast_aen_busy || ioc->pci_error_recovery || | |
5231 | ioc->got_task_abort_from_ioctl) | |
5232 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); | |
5233 | else | |
5234 | scmd = __scsih_scsi_lookup_get_clear(ioc, smid); | |
5235 | ||
f92363d1 SR |
5236 | if (scmd == NULL) |
5237 | return 1; | |
5238 | ||
ffb58456 | 5239 | _scsih_set_satl_pending(scmd, false); |
18f6084a | 5240 | |
f92363d1 SR |
5241 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
5242 | ||
5243 | if (mpi_reply == NULL) { | |
5244 | scmd->result = DID_OK << 16; | |
5245 | goto out; | |
5246 | } | |
5247 | ||
5248 | sas_device_priv_data = scmd->device->hostdata; | |
5249 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target || | |
5250 | sas_device_priv_data->sas_target->deleted) { | |
5251 | scmd->result = DID_NO_CONNECT << 16; | |
5252 | goto out; | |
5253 | } | |
5254 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); | |
5255 | ||
7786ab6a SR |
5256 | /* |
5257 | * WARPDRIVE: If direct_io is set then it is directIO, | |
5258 | * the failed direct I/O should be redirected to volume | |
5259 | */ | |
c84b06a4 | 5260 | if (mpt3sas_scsi_direct_io_get(ioc, smid) && |
7786ab6a SR |
5261 | ((ioc_status & MPI2_IOCSTATUS_MASK) |
5262 | != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) { | |
5263 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
5264 | ioc->scsi_lookup[smid - 1].scmd = scmd; | |
5265 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
c84b06a4 | 5266 | mpt3sas_scsi_direct_io_set(ioc, smid, 0); |
7786ab6a SR |
5267 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); |
5268 | mpi_request->DevHandle = | |
5269 | cpu_to_le16(sas_device_priv_data->sas_target->handle); | |
81c16f83 | 5270 | ioc->put_smid_scsi_io(ioc, smid, |
7786ab6a SR |
5271 | sas_device_priv_data->sas_target->handle); |
5272 | return 0; | |
5273 | } | |
f92363d1 SR |
5274 | /* turning off TLR */ |
5275 | scsi_state = mpi_reply->SCSIState; | |
5276 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) | |
5277 | response_code = | |
5278 | le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF; | |
5279 | if (!sas_device_priv_data->tlr_snoop_check) { | |
5280 | sas_device_priv_data->tlr_snoop_check++; | |
cd5897ed | 5281 | if ((!ioc->is_warpdrive && |
7786ab6a | 5282 | !scsih_is_raid(&scmd->device->sdev_gendev) && |
cd5897ed SPS |
5283 | !scsih_is_nvme(&scmd->device->sdev_gendev)) |
5284 | && sas_is_tlr_enabled(scmd->device) && | |
c84b06a4 SR |
5285 | response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) { |
5286 | sas_disable_tlr(scmd->device); | |
5287 | sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n"); | |
5288 | } | |
f92363d1 SR |
5289 | } |
5290 | ||
5291 | xfer_cnt = le32_to_cpu(mpi_reply->TransferCount); | |
5292 | scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt); | |
5293 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) | |
5294 | log_info = le32_to_cpu(mpi_reply->IOCLogInfo); | |
5295 | else | |
5296 | log_info = 0; | |
5297 | ioc_status &= MPI2_IOCSTATUS_MASK; | |
5298 | scsi_status = mpi_reply->SCSIStatus; | |
5299 | ||
5300 | if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 && | |
5301 | (scsi_status == MPI2_SCSI_STATUS_BUSY || | |
5302 | scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT || | |
5303 | scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) { | |
5304 | ioc_status = MPI2_IOCSTATUS_SUCCESS; | |
5305 | } | |
5306 | ||
5307 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { | |
5308 | struct sense_info data; | |
5309 | const void *sense_data = mpt3sas_base_get_sense_buffer(ioc, | |
5310 | smid); | |
5311 | u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE, | |
5312 | le32_to_cpu(mpi_reply->SenseCount)); | |
5313 | memcpy(scmd->sense_buffer, sense_data, sz); | |
5314 | _scsih_normalize_sense(scmd->sense_buffer, &data); | |
5315 | /* failure prediction threshold exceeded */ | |
5316 | if (data.asc == 0x5D) | |
5317 | _scsih_smart_predicted_fault(ioc, | |
5318 | le16_to_cpu(mpi_reply->DevHandle)); | |
5319 | mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq); | |
f92363d1 | 5320 | |
0d667f72 | 5321 | if ((ioc->logging_level & MPT_DEBUG_REPLY) && |
e6d45e3e SR |
5322 | ((scmd->sense_buffer[2] == UNIT_ATTENTION) || |
5323 | (scmd->sense_buffer[2] == MEDIUM_ERROR) || | |
5324 | (scmd->sense_buffer[2] == HARDWARE_ERROR))) | |
5325 | _scsih_scsi_ioc_info(ioc, scmd, mpi_reply, smid); | |
e6d45e3e | 5326 | } |
f92363d1 SR |
5327 | switch (ioc_status) { |
5328 | case MPI2_IOCSTATUS_BUSY: | |
5329 | case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES: | |
5330 | scmd->result = SAM_STAT_BUSY; | |
5331 | break; | |
5332 | ||
5333 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: | |
5334 | scmd->result = DID_NO_CONNECT << 16; | |
5335 | break; | |
5336 | ||
5337 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: | |
5338 | if (sas_device_priv_data->block) { | |
5339 | scmd->result = DID_TRANSPORT_DISRUPTED << 16; | |
5340 | goto out; | |
5341 | } | |
5342 | if (log_info == 0x31110630) { | |
5343 | if (scmd->retries > 2) { | |
5344 | scmd->result = DID_NO_CONNECT << 16; | |
5345 | scsi_device_set_state(scmd->device, | |
5346 | SDEV_OFFLINE); | |
5347 | } else { | |
5348 | scmd->result = DID_SOFT_ERROR << 16; | |
5349 | scmd->device->expecting_cc_ua = 1; | |
5350 | } | |
5351 | break; | |
3898f08e SR |
5352 | } else if (log_info == VIRTUAL_IO_FAILED_RETRY) { |
5353 | scmd->result = DID_RESET << 16; | |
5354 | break; | |
2ce9a364 SR |
5355 | } else if ((scmd->device->channel == RAID_CHANNEL) && |
5356 | (scsi_state == (MPI2_SCSI_STATE_TERMINATED | | |
5357 | MPI2_SCSI_STATE_NO_SCSI_STATUS))) { | |
5358 | scmd->result = DID_RESET << 16; | |
5359 | break; | |
f92363d1 SR |
5360 | } |
5361 | scmd->result = DID_SOFT_ERROR << 16; | |
5362 | break; | |
5363 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: | |
5364 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: | |
5365 | scmd->result = DID_RESET << 16; | |
5366 | break; | |
5367 | ||
5368 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: | |
5369 | if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt)) | |
5370 | scmd->result = DID_SOFT_ERROR << 16; | |
5371 | else | |
5372 | scmd->result = (DID_OK << 16) | scsi_status; | |
5373 | break; | |
5374 | ||
5375 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: | |
5376 | scmd->result = (DID_OK << 16) | scsi_status; | |
5377 | ||
5378 | if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)) | |
5379 | break; | |
5380 | ||
5381 | if (xfer_cnt < scmd->underflow) { | |
5382 | if (scsi_status == SAM_STAT_BUSY) | |
5383 | scmd->result = SAM_STAT_BUSY; | |
5384 | else | |
5385 | scmd->result = DID_SOFT_ERROR << 16; | |
5386 | } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | | |
5387 | MPI2_SCSI_STATE_NO_SCSI_STATUS)) | |
5388 | scmd->result = DID_SOFT_ERROR << 16; | |
5389 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | |
5390 | scmd->result = DID_RESET << 16; | |
5391 | else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) { | |
5392 | mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID; | |
5393 | mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION; | |
5394 | scmd->result = (DRIVER_SENSE << 24) | | |
5395 | SAM_STAT_CHECK_CONDITION; | |
5396 | scmd->sense_buffer[0] = 0x70; | |
5397 | scmd->sense_buffer[2] = ILLEGAL_REQUEST; | |
5398 | scmd->sense_buffer[12] = 0x20; | |
5399 | scmd->sense_buffer[13] = 0; | |
5400 | } | |
5401 | break; | |
5402 | ||
5403 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: | |
5404 | scsi_set_resid(scmd, 0); | |
5405 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: | |
5406 | case MPI2_IOCSTATUS_SUCCESS: | |
5407 | scmd->result = (DID_OK << 16) | scsi_status; | |
5408 | if (response_code == | |
5409 | MPI2_SCSITASKMGMT_RSP_INVALID_FRAME || | |
5410 | (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | | |
5411 | MPI2_SCSI_STATE_NO_SCSI_STATUS))) | |
5412 | scmd->result = DID_SOFT_ERROR << 16; | |
5413 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | |
5414 | scmd->result = DID_RESET << 16; | |
5415 | break; | |
5416 | ||
5417 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | |
5418 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | |
5419 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | |
5420 | _scsih_eedp_error_handling(scmd, ioc_status); | |
5421 | break; | |
5422 | ||
5423 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: | |
5424 | case MPI2_IOCSTATUS_INVALID_FUNCTION: | |
5425 | case MPI2_IOCSTATUS_INVALID_SGL: | |
5426 | case MPI2_IOCSTATUS_INTERNAL_ERROR: | |
5427 | case MPI2_IOCSTATUS_INVALID_FIELD: | |
5428 | case MPI2_IOCSTATUS_INVALID_STATE: | |
5429 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: | |
5430 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: | |
b130b0d5 | 5431 | case MPI2_IOCSTATUS_INSUFFICIENT_POWER: |
f92363d1 SR |
5432 | default: |
5433 | scmd->result = DID_SOFT_ERROR << 16; | |
5434 | break; | |
5435 | ||
5436 | } | |
5437 | ||
f92363d1 SR |
5438 | if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY)) |
5439 | _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid); | |
f92363d1 SR |
5440 | |
5441 | out: | |
5442 | ||
5443 | scsi_dma_unmap(scmd); | |
5444 | ||
5445 | scmd->scsi_done(scmd); | |
5446 | return 1; | |
5447 | } | |
5448 | ||
5449 | /** | |
5450 | * _scsih_sas_host_refresh - refreshing sas host object contents | |
5451 | * @ioc: per adapter object | |
5452 | * Context: user | |
5453 | * | |
5454 | * During port enable, fw will send topology events for every device. Its | |
5455 | * possible that the handles may change from the previous setting, so this | |
5456 | * code keeping handles updating if changed. | |
5457 | * | |
5458 | * Return nothing. | |
5459 | */ | |
5460 | static void | |
5461 | _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc) | |
5462 | { | |
5463 | u16 sz; | |
5464 | u16 ioc_status; | |
5465 | int i; | |
5466 | Mpi2ConfigReply_t mpi_reply; | |
5467 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; | |
5468 | u16 attached_handle; | |
5469 | u8 link_rate; | |
5470 | ||
5471 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
5472 | "updating handles for sas_host(0x%016llx)\n", | |
5473 | ioc->name, (unsigned long long)ioc->sas_hba.sas_address)); | |
5474 | ||
5475 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys | |
5476 | * sizeof(Mpi2SasIOUnit0PhyData_t)); | |
5477 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); | |
5478 | if (!sas_iounit_pg0) { | |
5479 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5480 | ioc->name, __FILE__, __LINE__, __func__); | |
5481 | return; | |
5482 | } | |
5483 | ||
5484 | if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, | |
5485 | sas_iounit_pg0, sz)) != 0) | |
5486 | goto out; | |
5487 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
5488 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | |
5489 | goto out; | |
5490 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { | |
5491 | link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4; | |
5492 | if (i == 0) | |
5493 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> | |
5494 | PhyData[0].ControllerDevHandle); | |
5495 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; | |
5496 | attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i]. | |
5497 | AttachedDevHandle); | |
5498 | if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) | |
5499 | link_rate = MPI2_SAS_NEG_LINK_RATE_1_5; | |
5500 | mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address, | |
5501 | attached_handle, i, link_rate); | |
5502 | } | |
5503 | out: | |
5504 | kfree(sas_iounit_pg0); | |
5505 | } | |
5506 | ||
5507 | /** | |
5508 | * _scsih_sas_host_add - create sas host object | |
5509 | * @ioc: per adapter object | |
5510 | * | |
5511 | * Creating host side data object, stored in ioc->sas_hba | |
5512 | * | |
5513 | * Return nothing. | |
5514 | */ | |
5515 | static void | |
5516 | _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc) | |
5517 | { | |
5518 | int i; | |
5519 | Mpi2ConfigReply_t mpi_reply; | |
5520 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; | |
5521 | Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; | |
5522 | Mpi2SasPhyPage0_t phy_pg0; | |
5523 | Mpi2SasDevicePage0_t sas_device_pg0; | |
5524 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
5525 | u16 ioc_status; | |
5526 | u16 sz; | |
5527 | u8 device_missing_delay; | |
87aa95d4 | 5528 | u8 num_phys; |
f92363d1 | 5529 | |
87aa95d4 JL |
5530 | mpt3sas_config_get_number_hba_phys(ioc, &num_phys); |
5531 | if (!num_phys) { | |
f92363d1 SR |
5532 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
5533 | ioc->name, __FILE__, __LINE__, __func__); | |
5534 | return; | |
5535 | } | |
87aa95d4 JL |
5536 | ioc->sas_hba.phy = kcalloc(num_phys, |
5537 | sizeof(struct _sas_phy), GFP_KERNEL); | |
5538 | if (!ioc->sas_hba.phy) { | |
5539 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5540 | ioc->name, __FILE__, __LINE__, __func__); | |
5541 | goto out; | |
5542 | } | |
5543 | ioc->sas_hba.num_phys = num_phys; | |
f92363d1 SR |
5544 | |
5545 | /* sas_iounit page 0 */ | |
5546 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys * | |
5547 | sizeof(Mpi2SasIOUnit0PhyData_t)); | |
5548 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); | |
5549 | if (!sas_iounit_pg0) { | |
5550 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5551 | ioc->name, __FILE__, __LINE__, __func__); | |
5552 | return; | |
5553 | } | |
5554 | if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, | |
5555 | sas_iounit_pg0, sz))) { | |
5556 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5557 | ioc->name, __FILE__, __LINE__, __func__); | |
5558 | goto out; | |
5559 | } | |
5560 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5561 | MPI2_IOCSTATUS_MASK; | |
5562 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
5563 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5564 | ioc->name, __FILE__, __LINE__, __func__); | |
5565 | goto out; | |
5566 | } | |
5567 | ||
5568 | /* sas_iounit page 1 */ | |
5569 | sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys * | |
5570 | sizeof(Mpi2SasIOUnit1PhyData_t)); | |
5571 | sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL); | |
5572 | if (!sas_iounit_pg1) { | |
5573 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5574 | ioc->name, __FILE__, __LINE__, __func__); | |
5575 | goto out; | |
5576 | } | |
5577 | if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply, | |
5578 | sas_iounit_pg1, sz))) { | |
5579 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5580 | ioc->name, __FILE__, __LINE__, __func__); | |
5581 | goto out; | |
5582 | } | |
5583 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5584 | MPI2_IOCSTATUS_MASK; | |
5585 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
5586 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5587 | ioc->name, __FILE__, __LINE__, __func__); | |
5588 | goto out; | |
5589 | } | |
5590 | ||
5591 | ioc->io_missing_delay = | |
5592 | sas_iounit_pg1->IODeviceMissingDelay; | |
5593 | device_missing_delay = | |
5594 | sas_iounit_pg1->ReportDeviceMissingDelay; | |
5595 | if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16) | |
5596 | ioc->device_missing_delay = (device_missing_delay & | |
5597 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16; | |
5598 | else | |
5599 | ioc->device_missing_delay = device_missing_delay & | |
5600 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK; | |
5601 | ||
5602 | ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev; | |
f92363d1 SR |
5603 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { |
5604 | if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0, | |
5605 | i))) { | |
5606 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5607 | ioc->name, __FILE__, __LINE__, __func__); | |
5608 | goto out; | |
5609 | } | |
5610 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5611 | MPI2_IOCSTATUS_MASK; | |
5612 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
5613 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5614 | ioc->name, __FILE__, __LINE__, __func__); | |
5615 | goto out; | |
5616 | } | |
5617 | ||
5618 | if (i == 0) | |
5619 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> | |
5620 | PhyData[0].ControllerDevHandle); | |
5621 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; | |
5622 | ioc->sas_hba.phy[i].phy_id = i; | |
5623 | mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i], | |
5624 | phy_pg0, ioc->sas_hba.parent_dev); | |
5625 | } | |
5626 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
5627 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) { | |
5628 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5629 | ioc->name, __FILE__, __LINE__, __func__); | |
5630 | goto out; | |
5631 | } | |
5632 | ioc->sas_hba.enclosure_handle = | |
5633 | le16_to_cpu(sas_device_pg0.EnclosureHandle); | |
5634 | ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | |
5635 | pr_info(MPT3SAS_FMT | |
5636 | "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n", | |
5637 | ioc->name, ioc->sas_hba.handle, | |
5638 | (unsigned long long) ioc->sas_hba.sas_address, | |
5639 | ioc->sas_hba.num_phys) ; | |
5640 | ||
5641 | if (ioc->sas_hba.enclosure_handle) { | |
5642 | if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
5643 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
5644 | ioc->sas_hba.enclosure_handle))) | |
5645 | ioc->sas_hba.enclosure_logical_id = | |
5646 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
5647 | } | |
5648 | ||
5649 | out: | |
5650 | kfree(sas_iounit_pg1); | |
5651 | kfree(sas_iounit_pg0); | |
5652 | } | |
5653 | ||
5654 | /** | |
5655 | * _scsih_expander_add - creating expander object | |
5656 | * @ioc: per adapter object | |
5657 | * @handle: expander handle | |
5658 | * | |
5659 | * Creating expander object, stored in ioc->sas_expander_list. | |
5660 | * | |
5661 | * Return 0 for success, else error. | |
5662 | */ | |
5663 | static int | |
5664 | _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
5665 | { | |
5666 | struct _sas_node *sas_expander; | |
5667 | Mpi2ConfigReply_t mpi_reply; | |
5668 | Mpi2ExpanderPage0_t expander_pg0; | |
5669 | Mpi2ExpanderPage1_t expander_pg1; | |
5670 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
5671 | u32 ioc_status; | |
5672 | u16 parent_handle; | |
5673 | u64 sas_address, sas_address_parent = 0; | |
5674 | int i; | |
5675 | unsigned long flags; | |
5676 | struct _sas_port *mpt3sas_port = NULL; | |
5677 | ||
5678 | int rc = 0; | |
5679 | ||
5680 | if (!handle) | |
5681 | return -1; | |
5682 | ||
5683 | if (ioc->shost_recovery || ioc->pci_error_recovery) | |
5684 | return -1; | |
5685 | ||
5686 | if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | |
5687 | MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) { | |
5688 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5689 | ioc->name, __FILE__, __LINE__, __func__); | |
5690 | return -1; | |
5691 | } | |
5692 | ||
5693 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5694 | MPI2_IOCSTATUS_MASK; | |
5695 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
5696 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5697 | ioc->name, __FILE__, __LINE__, __func__); | |
5698 | return -1; | |
5699 | } | |
5700 | ||
5701 | /* handle out of order topology events */ | |
5702 | parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle); | |
5703 | if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent) | |
5704 | != 0) { | |
5705 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5706 | ioc->name, __FILE__, __LINE__, __func__); | |
5707 | return -1; | |
5708 | } | |
5709 | if (sas_address_parent != ioc->sas_hba.sas_address) { | |
5710 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
5711 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, | |
5712 | sas_address_parent); | |
5713 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
5714 | if (!sas_expander) { | |
5715 | rc = _scsih_expander_add(ioc, parent_handle); | |
5716 | if (rc != 0) | |
5717 | return rc; | |
5718 | } | |
5719 | } | |
5720 | ||
5721 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
5722 | sas_address = le64_to_cpu(expander_pg0.SASAddress); | |
5723 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, | |
5724 | sas_address); | |
5725 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
5726 | ||
5727 | if (sas_expander) | |
5728 | return 0; | |
5729 | ||
5730 | sas_expander = kzalloc(sizeof(struct _sas_node), | |
5731 | GFP_KERNEL); | |
5732 | if (!sas_expander) { | |
5733 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5734 | ioc->name, __FILE__, __LINE__, __func__); | |
5735 | return -1; | |
5736 | } | |
5737 | ||
5738 | sas_expander->handle = handle; | |
5739 | sas_expander->num_phys = expander_pg0.NumPhys; | |
5740 | sas_expander->sas_address_parent = sas_address_parent; | |
5741 | sas_expander->sas_address = sas_address; | |
5742 | ||
5743 | pr_info(MPT3SAS_FMT "expander_add: handle(0x%04x)," \ | |
5744 | " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name, | |
5745 | handle, parent_handle, (unsigned long long) | |
5746 | sas_expander->sas_address, sas_expander->num_phys); | |
5747 | ||
5748 | if (!sas_expander->num_phys) | |
5749 | goto out_fail; | |
5750 | sas_expander->phy = kcalloc(sas_expander->num_phys, | |
5751 | sizeof(struct _sas_phy), GFP_KERNEL); | |
5752 | if (!sas_expander->phy) { | |
5753 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5754 | ioc->name, __FILE__, __LINE__, __func__); | |
5755 | rc = -1; | |
5756 | goto out_fail; | |
5757 | } | |
5758 | ||
5759 | INIT_LIST_HEAD(&sas_expander->sas_port_list); | |
5760 | mpt3sas_port = mpt3sas_transport_port_add(ioc, handle, | |
5761 | sas_address_parent); | |
5762 | if (!mpt3sas_port) { | |
5763 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5764 | ioc->name, __FILE__, __LINE__, __func__); | |
5765 | rc = -1; | |
5766 | goto out_fail; | |
5767 | } | |
5768 | sas_expander->parent_dev = &mpt3sas_port->rphy->dev; | |
5769 | ||
5770 | for (i = 0 ; i < sas_expander->num_phys ; i++) { | |
5771 | if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply, | |
5772 | &expander_pg1, i, handle))) { | |
5773 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5774 | ioc->name, __FILE__, __LINE__, __func__); | |
5775 | rc = -1; | |
5776 | goto out_fail; | |
5777 | } | |
5778 | sas_expander->phy[i].handle = handle; | |
5779 | sas_expander->phy[i].phy_id = i; | |
5780 | ||
5781 | if ((mpt3sas_transport_add_expander_phy(ioc, | |
5782 | &sas_expander->phy[i], expander_pg1, | |
5783 | sas_expander->parent_dev))) { | |
5784 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5785 | ioc->name, __FILE__, __LINE__, __func__); | |
5786 | rc = -1; | |
5787 | goto out_fail; | |
5788 | } | |
5789 | } | |
5790 | ||
5791 | if (sas_expander->enclosure_handle) { | |
5792 | if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
5793 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
5794 | sas_expander->enclosure_handle))) | |
5795 | sas_expander->enclosure_logical_id = | |
5796 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
5797 | } | |
5798 | ||
5799 | _scsih_expander_node_add(ioc, sas_expander); | |
5800 | return 0; | |
5801 | ||
5802 | out_fail: | |
5803 | ||
5804 | if (mpt3sas_port) | |
5805 | mpt3sas_transport_port_remove(ioc, sas_expander->sas_address, | |
5806 | sas_address_parent); | |
5807 | kfree(sas_expander); | |
5808 | return rc; | |
5809 | } | |
5810 | ||
5811 | /** | |
5812 | * mpt3sas_expander_remove - removing expander object | |
5813 | * @ioc: per adapter object | |
5814 | * @sas_address: expander sas_address | |
5815 | * | |
5816 | * Return nothing. | |
5817 | */ | |
5818 | void | |
5819 | mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address) | |
5820 | { | |
5821 | struct _sas_node *sas_expander; | |
5822 | unsigned long flags; | |
5823 | ||
5824 | if (ioc->shost_recovery) | |
5825 | return; | |
5826 | ||
5827 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
5828 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, | |
5829 | sas_address); | |
f92363d1 SR |
5830 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
5831 | if (sas_expander) | |
5832 | _scsih_expander_node_remove(ioc, sas_expander); | |
5833 | } | |
5834 | ||
5835 | /** | |
5836 | * _scsih_done - internal SCSI_IO callback handler. | |
5837 | * @ioc: per adapter object | |
5838 | * @smid: system request message index | |
5839 | * @msix_index: MSIX table index supplied by the OS | |
5840 | * @reply: reply message frame(lower 32bit addr) | |
5841 | * | |
5842 | * Callback handler when sending internal generated SCSI_IO. | |
5843 | * The callback index passed is `ioc->scsih_cb_idx` | |
5844 | * | |
5845 | * Return 1 meaning mf should be freed from _base_interrupt | |
5846 | * 0 means the mf is freed from this function. | |
5847 | */ | |
5848 | static u8 | |
5849 | _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | |
5850 | { | |
5851 | MPI2DefaultReply_t *mpi_reply; | |
5852 | ||
5853 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
5854 | if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED) | |
5855 | return 1; | |
5856 | if (ioc->scsih_cmds.smid != smid) | |
5857 | return 1; | |
5858 | ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE; | |
5859 | if (mpi_reply) { | |
5860 | memcpy(ioc->scsih_cmds.reply, mpi_reply, | |
5861 | mpi_reply->MsgLength*4); | |
5862 | ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID; | |
5863 | } | |
5864 | ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING; | |
5865 | complete(&ioc->scsih_cmds.done); | |
5866 | return 1; | |
5867 | } | |
5868 | ||
5869 | ||
5870 | ||
5871 | ||
5872 | #define MPT3_MAX_LUNS (255) | |
5873 | ||
5874 | ||
5875 | /** | |
5876 | * _scsih_check_access_status - check access flags | |
5877 | * @ioc: per adapter object | |
5878 | * @sas_address: sas address | |
5879 | * @handle: sas device handle | |
5880 | * @access_flags: errors returned during discovery of the device | |
5881 | * | |
5882 | * Return 0 for success, else failure | |
5883 | */ | |
5884 | static u8 | |
5885 | _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address, | |
5886 | u16 handle, u8 access_status) | |
5887 | { | |
5888 | u8 rc = 1; | |
5889 | char *desc = NULL; | |
5890 | ||
5891 | switch (access_status) { | |
5892 | case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS: | |
5893 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION: | |
5894 | rc = 0; | |
5895 | break; | |
5896 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED: | |
5897 | desc = "sata capability failed"; | |
5898 | break; | |
5899 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT: | |
5900 | desc = "sata affiliation conflict"; | |
5901 | break; | |
5902 | case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE: | |
5903 | desc = "route not addressable"; | |
5904 | break; | |
5905 | case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE: | |
5906 | desc = "smp error not addressable"; | |
5907 | break; | |
5908 | case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED: | |
5909 | desc = "device blocked"; | |
5910 | break; | |
5911 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED: | |
5912 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN: | |
5913 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT: | |
5914 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG: | |
5915 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION: | |
5916 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER: | |
5917 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN: | |
5918 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN: | |
5919 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN: | |
5920 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION: | |
5921 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE: | |
5922 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX: | |
5923 | desc = "sata initialization failed"; | |
5924 | break; | |
5925 | default: | |
5926 | desc = "unknown"; | |
5927 | break; | |
5928 | } | |
5929 | ||
5930 | if (!rc) | |
5931 | return 0; | |
5932 | ||
5933 | pr_err(MPT3SAS_FMT | |
5934 | "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n", | |
5935 | ioc->name, desc, (unsigned long long)sas_address, handle); | |
5936 | return rc; | |
5937 | } | |
5938 | ||
aba5a85c SR |
5939 | /** |
5940 | * _scsih_get_enclosure_logicalid_chassis_slot - get device's | |
5941 | * EnclosureLogicalID and ChassisSlot information. | |
5942 | * @ioc: per adapter object | |
5943 | * @sas_device_pg0: SAS device page0 | |
5944 | * @sas_device: per sas device object | |
5945 | * | |
5946 | * Returns nothing. | |
5947 | */ | |
5948 | static void | |
5949 | _scsih_get_enclosure_logicalid_chassis_slot(struct MPT3SAS_ADAPTER *ioc, | |
5950 | Mpi2SasDevicePage0_t *sas_device_pg0, struct _sas_device *sas_device) | |
5951 | { | |
5952 | Mpi2ConfigReply_t mpi_reply; | |
5953 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
5954 | ||
5955 | if (!sas_device_pg0 || !sas_device) | |
5956 | return; | |
5957 | ||
5958 | sas_device->enclosure_handle = | |
5959 | le16_to_cpu(sas_device_pg0->EnclosureHandle); | |
5960 | sas_device->is_chassis_slot_valid = 0; | |
5961 | ||
5962 | if (!le16_to_cpu(sas_device_pg0->EnclosureHandle)) | |
5963 | return; | |
5964 | ||
5965 | if (mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
5966 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
5967 | le16_to_cpu(sas_device_pg0->EnclosureHandle))) { | |
5968 | pr_err(MPT3SAS_FMT | |
5969 | "Enclosure Pg0 read failed for handle(0x%04x)\n", | |
5970 | ioc->name, le16_to_cpu(sas_device_pg0->EnclosureHandle)); | |
5971 | return; | |
5972 | } | |
5973 | ||
5974 | sas_device->enclosure_logical_id = | |
5975 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
5976 | ||
5977 | if (le16_to_cpu(enclosure_pg0.Flags) & | |
5978 | MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) { | |
5979 | sas_device->is_chassis_slot_valid = 1; | |
5980 | sas_device->chassis_slot = enclosure_pg0.ChassisSlot; | |
5981 | } | |
5982 | } | |
5983 | ||
5984 | ||
f92363d1 SR |
5985 | /** |
5986 | * _scsih_check_device - checking device responsiveness | |
5987 | * @ioc: per adapter object | |
5988 | * @parent_sas_address: sas address of parent expander or sas host | |
5989 | * @handle: attached device handle | |
5990 | * @phy_numberv: phy number | |
5991 | * @link_rate: new link rate | |
5992 | * | |
5993 | * Returns nothing. | |
5994 | */ | |
5995 | static void | |
5996 | _scsih_check_device(struct MPT3SAS_ADAPTER *ioc, | |
5997 | u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate) | |
5998 | { | |
5999 | Mpi2ConfigReply_t mpi_reply; | |
6000 | Mpi2SasDevicePage0_t sas_device_pg0; | |
6001 | struct _sas_device *sas_device; | |
6002 | u32 ioc_status; | |
6003 | unsigned long flags; | |
6004 | u64 sas_address; | |
6005 | struct scsi_target *starget; | |
6006 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
6007 | u32 device_info; | |
6008 | ||
f92363d1 SR |
6009 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
6010 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) | |
6011 | return; | |
6012 | ||
6013 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
6014 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | |
6015 | return; | |
6016 | ||
6017 | /* wide port handling ~ we need only handle device once for the phy that | |
6018 | * is matched in sas device page zero | |
6019 | */ | |
6020 | if (phy_number != sas_device_pg0.PhyNum) | |
6021 | return; | |
6022 | ||
6023 | /* check if this is end device */ | |
6024 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | |
6025 | if (!(_scsih_is_end_device(device_info))) | |
6026 | return; | |
6027 | ||
6028 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
6029 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | |
d1cb5e49 | 6030 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 SR |
6031 | sas_address); |
6032 | ||
d1cb5e49 SR |
6033 | if (!sas_device) |
6034 | goto out_unlock; | |
f92363d1 SR |
6035 | |
6036 | if (unlikely(sas_device->handle != handle)) { | |
6037 | starget = sas_device->starget; | |
6038 | sas_target_priv_data = starget->hostdata; | |
6039 | starget_printk(KERN_INFO, starget, | |
6040 | "handle changed from(0x%04x) to (0x%04x)!!!\n", | |
6041 | sas_device->handle, handle); | |
6042 | sas_target_priv_data->handle = handle; | |
6043 | sas_device->handle = handle; | |
aa53bb89 | 6044 | if (le16_to_cpu(sas_device_pg0.Flags) & |
e6d45e3e SR |
6045 | MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) { |
6046 | sas_device->enclosure_level = | |
aa53bb89 | 6047 | sas_device_pg0.EnclosureLevel; |
310c8e40 CO |
6048 | memcpy(sas_device->connector_name, |
6049 | sas_device_pg0.ConnectorName, 4); | |
6050 | sas_device->connector_name[4] = '\0'; | |
e6d45e3e SR |
6051 | } else { |
6052 | sas_device->enclosure_level = 0; | |
6053 | sas_device->connector_name[0] = '\0'; | |
6054 | } | |
aba5a85c SR |
6055 | |
6056 | _scsih_get_enclosure_logicalid_chassis_slot(ioc, | |
6057 | &sas_device_pg0, sas_device); | |
f92363d1 SR |
6058 | } |
6059 | ||
6060 | /* check if device is present */ | |
6061 | if (!(le16_to_cpu(sas_device_pg0.Flags) & | |
6062 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { | |
6063 | pr_err(MPT3SAS_FMT | |
6064 | "device is not present handle(0x%04x), flags!!!\n", | |
6065 | ioc->name, handle); | |
d1cb5e49 | 6066 | goto out_unlock; |
f92363d1 SR |
6067 | } |
6068 | ||
6069 | /* check if there were any issues with discovery */ | |
6070 | if (_scsih_check_access_status(ioc, sas_address, handle, | |
d1cb5e49 SR |
6071 | sas_device_pg0.AccessStatus)) |
6072 | goto out_unlock; | |
f92363d1 SR |
6073 | |
6074 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
6075 | _scsih_ublock_io_device(ioc, sas_address); | |
6076 | ||
d1cb5e49 SR |
6077 | if (sas_device) |
6078 | sas_device_put(sas_device); | |
6079 | return; | |
6080 | ||
6081 | out_unlock: | |
6082 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
6083 | if (sas_device) | |
6084 | sas_device_put(sas_device); | |
f92363d1 SR |
6085 | } |
6086 | ||
6087 | /** | |
6088 | * _scsih_add_device - creating sas device object | |
6089 | * @ioc: per adapter object | |
6090 | * @handle: sas device handle | |
6091 | * @phy_num: phy number end device attached to | |
6092 | * @is_pd: is this hidden raid component | |
6093 | * | |
6094 | * Creating end device object, stored in ioc->sas_device_list. | |
6095 | * | |
6096 | * Returns 0 for success, non-zero for failure. | |
6097 | */ | |
6098 | static int | |
6099 | _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num, | |
6100 | u8 is_pd) | |
6101 | { | |
6102 | Mpi2ConfigReply_t mpi_reply; | |
6103 | Mpi2SasDevicePage0_t sas_device_pg0; | |
6104 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
6105 | struct _sas_device *sas_device; | |
6106 | u32 ioc_status; | |
6107 | u64 sas_address; | |
6108 | u32 device_info; | |
75888956 | 6109 | int encl_pg0_rc = -1; |
f92363d1 SR |
6110 | |
6111 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
6112 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
6113 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6114 | ioc->name, __FILE__, __LINE__, __func__); | |
6115 | return -1; | |
6116 | } | |
6117 | ||
6118 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6119 | MPI2_IOCSTATUS_MASK; | |
6120 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
6121 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6122 | ioc->name, __FILE__, __LINE__, __func__); | |
6123 | return -1; | |
6124 | } | |
6125 | ||
6126 | /* check if this is end device */ | |
6127 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | |
6128 | if (!(_scsih_is_end_device(device_info))) | |
6129 | return -1; | |
c696f7b8 | 6130 | set_bit(handle, ioc->pend_os_device_add); |
f92363d1 SR |
6131 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
6132 | ||
6133 | /* check if device is present */ | |
6134 | if (!(le16_to_cpu(sas_device_pg0.Flags) & | |
6135 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { | |
6136 | pr_err(MPT3SAS_FMT "device is not present handle(0x04%x)!!!\n", | |
6137 | ioc->name, handle); | |
6138 | return -1; | |
6139 | } | |
6140 | ||
6141 | /* check if there were any issues with discovery */ | |
6142 | if (_scsih_check_access_status(ioc, sas_address, handle, | |
6143 | sas_device_pg0.AccessStatus)) | |
6144 | return -1; | |
6145 | ||
d1cb5e49 SR |
6146 | sas_device = mpt3sas_get_sdev_by_addr(ioc, |
6147 | sas_address); | |
6148 | if (sas_device) { | |
c696f7b8 | 6149 | clear_bit(handle, ioc->pend_os_device_add); |
d1cb5e49 | 6150 | sas_device_put(sas_device); |
f92363d1 | 6151 | return -1; |
d1cb5e49 | 6152 | } |
f92363d1 | 6153 | |
75888956 SR |
6154 | if (sas_device_pg0.EnclosureHandle) { |
6155 | encl_pg0_rc = mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
6156 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
6157 | sas_device_pg0.EnclosureHandle); | |
6158 | if (encl_pg0_rc) | |
6159 | pr_info(MPT3SAS_FMT | |
6160 | "Enclosure Pg0 read failed for handle(0x%04x)\n", | |
6161 | ioc->name, sas_device_pg0.EnclosureHandle); | |
6162 | } | |
6163 | ||
f92363d1 SR |
6164 | sas_device = kzalloc(sizeof(struct _sas_device), |
6165 | GFP_KERNEL); | |
6166 | if (!sas_device) { | |
6167 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6168 | ioc->name, __FILE__, __LINE__, __func__); | |
6169 | return 0; | |
6170 | } | |
6171 | ||
d1cb5e49 | 6172 | kref_init(&sas_device->refcount); |
f92363d1 SR |
6173 | sas_device->handle = handle; |
6174 | if (_scsih_get_sas_address(ioc, | |
6175 | le16_to_cpu(sas_device_pg0.ParentDevHandle), | |
6176 | &sas_device->sas_address_parent) != 0) | |
6177 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6178 | ioc->name, __FILE__, __LINE__, __func__); | |
6179 | sas_device->enclosure_handle = | |
6180 | le16_to_cpu(sas_device_pg0.EnclosureHandle); | |
e6d45e3e SR |
6181 | if (sas_device->enclosure_handle != 0) |
6182 | sas_device->slot = | |
6183 | le16_to_cpu(sas_device_pg0.Slot); | |
f92363d1 SR |
6184 | sas_device->device_info = device_info; |
6185 | sas_device->sas_address = sas_address; | |
6186 | sas_device->phy = sas_device_pg0.PhyNum; | |
6187 | sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) & | |
6188 | MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0; | |
6189 | ||
aa53bb89 SPS |
6190 | if (le16_to_cpu(sas_device_pg0.Flags) |
6191 | & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) { | |
e6d45e3e | 6192 | sas_device->enclosure_level = |
aa53bb89 | 6193 | sas_device_pg0.EnclosureLevel; |
310c8e40 CO |
6194 | memcpy(sas_device->connector_name, |
6195 | sas_device_pg0.ConnectorName, 4); | |
6196 | sas_device->connector_name[4] = '\0'; | |
e6d45e3e SR |
6197 | } else { |
6198 | sas_device->enclosure_level = 0; | |
6199 | sas_device->connector_name[0] = '\0'; | |
6200 | } | |
75888956 SR |
6201 | |
6202 | /* get enclosure_logical_id & chassis_slot */ | |
6203 | sas_device->is_chassis_slot_valid = 0; | |
6204 | if (encl_pg0_rc == 0) { | |
f92363d1 SR |
6205 | sas_device->enclosure_logical_id = |
6206 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
6207 | ||
75888956 SR |
6208 | if (le16_to_cpu(enclosure_pg0.Flags) & |
6209 | MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) { | |
6210 | sas_device->is_chassis_slot_valid = 1; | |
6211 | sas_device->chassis_slot = | |
6212 | enclosure_pg0.ChassisSlot; | |
6213 | } | |
6214 | } | |
6215 | ||
f92363d1 SR |
6216 | /* get device name */ |
6217 | sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName); | |
6218 | ||
6219 | if (ioc->wait_for_discovery_to_complete) | |
6220 | _scsih_sas_device_init_add(ioc, sas_device); | |
6221 | else | |
6222 | _scsih_sas_device_add(ioc, sas_device); | |
6223 | ||
d1cb5e49 | 6224 | sas_device_put(sas_device); |
f92363d1 SR |
6225 | return 0; |
6226 | } | |
6227 | ||
6228 | /** | |
6229 | * _scsih_remove_device - removing sas device object | |
6230 | * @ioc: per adapter object | |
6231 | * @sas_device_delete: the sas_device object | |
6232 | * | |
6233 | * Return nothing. | |
6234 | */ | |
6235 | static void | |
6236 | _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc, | |
6237 | struct _sas_device *sas_device) | |
6238 | { | |
6239 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
6240 | ||
0f624c39 SR |
6241 | if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) && |
6242 | (sas_device->pfa_led_on)) { | |
6243 | _scsih_turn_off_pfa_led(ioc, sas_device); | |
6244 | sas_device->pfa_led_on = 0; | |
6245 | } | |
75888956 | 6246 | |
f92363d1 SR |
6247 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
6248 | "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n", | |
6249 | ioc->name, __func__, | |
6250 | sas_device->handle, (unsigned long long) | |
6251 | sas_device->sas_address)); | |
75888956 SR |
6252 | |
6253 | dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device, | |
6254 | NULL, NULL)); | |
f92363d1 SR |
6255 | |
6256 | if (sas_device->starget && sas_device->starget->hostdata) { | |
6257 | sas_target_priv_data = sas_device->starget->hostdata; | |
6258 | sas_target_priv_data->deleted = 1; | |
6259 | _scsih_ublock_io_device(ioc, sas_device->sas_address); | |
6260 | sas_target_priv_data->handle = | |
6261 | MPT3SAS_INVALID_DEVICE_HANDLE; | |
6262 | } | |
7786ab6a SR |
6263 | |
6264 | if (!ioc->hide_drives) | |
6265 | mpt3sas_transport_port_remove(ioc, | |
f92363d1 SR |
6266 | sas_device->sas_address, |
6267 | sas_device->sas_address_parent); | |
6268 | ||
6269 | pr_info(MPT3SAS_FMT | |
6270 | "removing handle(0x%04x), sas_addr(0x%016llx)\n", | |
6271 | ioc->name, sas_device->handle, | |
6272 | (unsigned long long) sas_device->sas_address); | |
75888956 SR |
6273 | |
6274 | _scsih_display_enclosure_chassis_info(ioc, sas_device, NULL, NULL); | |
f92363d1 SR |
6275 | |
6276 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6277 | "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n", | |
6278 | ioc->name, __func__, | |
e6d45e3e SR |
6279 | sas_device->handle, (unsigned long long) |
6280 | sas_device->sas_address)); | |
75888956 SR |
6281 | dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device, |
6282 | NULL, NULL)); | |
f92363d1 SR |
6283 | } |
6284 | ||
f92363d1 SR |
6285 | /** |
6286 | * _scsih_sas_topology_change_event_debug - debug for topology event | |
6287 | * @ioc: per adapter object | |
6288 | * @event_data: event data payload | |
6289 | * Context: user. | |
6290 | */ | |
6291 | static void | |
6292 | _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
6293 | Mpi2EventDataSasTopologyChangeList_t *event_data) | |
6294 | { | |
6295 | int i; | |
6296 | u16 handle; | |
6297 | u16 reason_code; | |
6298 | u8 phy_number; | |
6299 | char *status_str = NULL; | |
6300 | u8 link_rate, prev_link_rate; | |
6301 | ||
6302 | switch (event_data->ExpStatus) { | |
6303 | case MPI2_EVENT_SAS_TOPO_ES_ADDED: | |
6304 | status_str = "add"; | |
6305 | break; | |
6306 | case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING: | |
6307 | status_str = "remove"; | |
6308 | break; | |
6309 | case MPI2_EVENT_SAS_TOPO_ES_RESPONDING: | |
6310 | case 0: | |
6311 | status_str = "responding"; | |
6312 | break; | |
6313 | case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING: | |
6314 | status_str = "remove delay"; | |
6315 | break; | |
6316 | default: | |
6317 | status_str = "unknown status"; | |
6318 | break; | |
6319 | } | |
6320 | pr_info(MPT3SAS_FMT "sas topology change: (%s)\n", | |
6321 | ioc->name, status_str); | |
6322 | pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \ | |
6323 | "start_phy(%02d), count(%d)\n", | |
6324 | le16_to_cpu(event_data->ExpanderDevHandle), | |
6325 | le16_to_cpu(event_data->EnclosureHandle), | |
6326 | event_data->StartPhyNum, event_data->NumEntries); | |
6327 | for (i = 0; i < event_data->NumEntries; i++) { | |
6328 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
6329 | if (!handle) | |
6330 | continue; | |
6331 | phy_number = event_data->StartPhyNum + i; | |
6332 | reason_code = event_data->PHY[i].PhyStatus & | |
6333 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
6334 | switch (reason_code) { | |
6335 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: | |
6336 | status_str = "target add"; | |
6337 | break; | |
6338 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: | |
6339 | status_str = "target remove"; | |
6340 | break; | |
6341 | case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING: | |
6342 | status_str = "delay target remove"; | |
6343 | break; | |
6344 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: | |
6345 | status_str = "link rate change"; | |
6346 | break; | |
6347 | case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE: | |
6348 | status_str = "target responding"; | |
6349 | break; | |
6350 | default: | |
6351 | status_str = "unknown"; | |
6352 | break; | |
6353 | } | |
6354 | link_rate = event_data->PHY[i].LinkRate >> 4; | |
6355 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; | |
6356 | pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \ | |
6357 | " link rate: new(0x%02x), old(0x%02x)\n", phy_number, | |
6358 | handle, status_str, link_rate, prev_link_rate); | |
6359 | ||
6360 | } | |
6361 | } | |
f92363d1 SR |
6362 | |
6363 | /** | |
6364 | * _scsih_sas_topology_change_event - handle topology changes | |
6365 | * @ioc: per adapter object | |
6366 | * @fw_event: The fw_event_work object | |
6367 | * Context: user. | |
6368 | * | |
6369 | */ | |
6370 | static int | |
6371 | _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc, | |
6372 | struct fw_event_work *fw_event) | |
6373 | { | |
6374 | int i; | |
6375 | u16 parent_handle, handle; | |
6376 | u16 reason_code; | |
6377 | u8 phy_number, max_phys; | |
6378 | struct _sas_node *sas_expander; | |
6379 | u64 sas_address; | |
6380 | unsigned long flags; | |
6381 | u8 link_rate, prev_link_rate; | |
35b62362 JL |
6382 | Mpi2EventDataSasTopologyChangeList_t *event_data = |
6383 | (Mpi2EventDataSasTopologyChangeList_t *) | |
6384 | fw_event->event_data; | |
f92363d1 | 6385 | |
f92363d1 SR |
6386 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
6387 | _scsih_sas_topology_change_event_debug(ioc, event_data); | |
f92363d1 SR |
6388 | |
6389 | if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery) | |
6390 | return 0; | |
6391 | ||
6392 | if (!ioc->sas_hba.num_phys) | |
6393 | _scsih_sas_host_add(ioc); | |
6394 | else | |
6395 | _scsih_sas_host_refresh(ioc); | |
6396 | ||
6397 | if (fw_event->ignore) { | |
6398 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6399 | "ignoring expander event\n", ioc->name)); | |
6400 | return 0; | |
6401 | } | |
6402 | ||
6403 | parent_handle = le16_to_cpu(event_data->ExpanderDevHandle); | |
6404 | ||
6405 | /* handle expander add */ | |
6406 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED) | |
6407 | if (_scsih_expander_add(ioc, parent_handle) != 0) | |
6408 | return 0; | |
6409 | ||
6410 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
6411 | sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc, | |
6412 | parent_handle); | |
6413 | if (sas_expander) { | |
6414 | sas_address = sas_expander->sas_address; | |
6415 | max_phys = sas_expander->num_phys; | |
6416 | } else if (parent_handle < ioc->sas_hba.num_phys) { | |
6417 | sas_address = ioc->sas_hba.sas_address; | |
6418 | max_phys = ioc->sas_hba.num_phys; | |
6419 | } else { | |
6420 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
6421 | return 0; | |
6422 | } | |
6423 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
6424 | ||
6425 | /* handle siblings events */ | |
6426 | for (i = 0; i < event_data->NumEntries; i++) { | |
6427 | if (fw_event->ignore) { | |
6428 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6429 | "ignoring expander event\n", ioc->name)); | |
6430 | return 0; | |
6431 | } | |
6432 | if (ioc->remove_host || ioc->pci_error_recovery) | |
6433 | return 0; | |
6434 | phy_number = event_data->StartPhyNum + i; | |
6435 | if (phy_number >= max_phys) | |
6436 | continue; | |
6437 | reason_code = event_data->PHY[i].PhyStatus & | |
6438 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
6439 | if ((event_data->PHY[i].PhyStatus & | |
6440 | MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code != | |
6441 | MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)) | |
6442 | continue; | |
6443 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
6444 | if (!handle) | |
6445 | continue; | |
6446 | link_rate = event_data->PHY[i].LinkRate >> 4; | |
6447 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; | |
6448 | switch (reason_code) { | |
6449 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: | |
6450 | ||
6451 | if (ioc->shost_recovery) | |
6452 | break; | |
6453 | ||
6454 | if (link_rate == prev_link_rate) | |
6455 | break; | |
6456 | ||
6457 | mpt3sas_transport_update_links(ioc, sas_address, | |
6458 | handle, phy_number, link_rate); | |
6459 | ||
6460 | if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) | |
6461 | break; | |
6462 | ||
6463 | _scsih_check_device(ioc, sas_address, handle, | |
6464 | phy_number, link_rate); | |
6465 | ||
c696f7b8 SPS |
6466 | if (!test_bit(handle, ioc->pend_os_device_add)) |
6467 | break; | |
6468 | ||
f92363d1 SR |
6469 | |
6470 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: | |
6471 | ||
6472 | if (ioc->shost_recovery) | |
6473 | break; | |
6474 | ||
6475 | mpt3sas_transport_update_links(ioc, sas_address, | |
6476 | handle, phy_number, link_rate); | |
6477 | ||
6478 | _scsih_add_device(ioc, handle, phy_number, 0); | |
6479 | ||
6480 | break; | |
6481 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: | |
6482 | ||
6483 | _scsih_device_remove_by_handle(ioc, handle); | |
6484 | break; | |
6485 | } | |
6486 | } | |
6487 | ||
6488 | /* handle expander removal */ | |
6489 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING && | |
6490 | sas_expander) | |
6491 | mpt3sas_expander_remove(ioc, sas_address); | |
6492 | ||
6493 | return 0; | |
6494 | } | |
6495 | ||
f92363d1 SR |
6496 | /** |
6497 | * _scsih_sas_device_status_change_event_debug - debug for device event | |
6498 | * @event_data: event data payload | |
6499 | * Context: user. | |
6500 | * | |
6501 | * Return nothing. | |
6502 | */ | |
6503 | static void | |
6504 | _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
6505 | Mpi2EventDataSasDeviceStatusChange_t *event_data) | |
6506 | { | |
6507 | char *reason_str = NULL; | |
6508 | ||
6509 | switch (event_data->ReasonCode) { | |
6510 | case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA: | |
6511 | reason_str = "smart data"; | |
6512 | break; | |
6513 | case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED: | |
6514 | reason_str = "unsupported device discovered"; | |
6515 | break; | |
6516 | case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET: | |
6517 | reason_str = "internal device reset"; | |
6518 | break; | |
6519 | case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL: | |
6520 | reason_str = "internal task abort"; | |
6521 | break; | |
6522 | case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL: | |
6523 | reason_str = "internal task abort set"; | |
6524 | break; | |
6525 | case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL: | |
6526 | reason_str = "internal clear task set"; | |
6527 | break; | |
6528 | case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL: | |
6529 | reason_str = "internal query task"; | |
6530 | break; | |
6531 | case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE: | |
6532 | reason_str = "sata init failure"; | |
6533 | break; | |
6534 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET: | |
6535 | reason_str = "internal device reset complete"; | |
6536 | break; | |
6537 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL: | |
6538 | reason_str = "internal task abort complete"; | |
6539 | break; | |
6540 | case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION: | |
6541 | reason_str = "internal async notification"; | |
6542 | break; | |
6543 | case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY: | |
6544 | reason_str = "expander reduced functionality"; | |
6545 | break; | |
6546 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY: | |
6547 | reason_str = "expander reduced functionality complete"; | |
6548 | break; | |
6549 | default: | |
6550 | reason_str = "unknown reason"; | |
6551 | break; | |
6552 | } | |
6553 | pr_info(MPT3SAS_FMT "device status change: (%s)\n" | |
6554 | "\thandle(0x%04x), sas address(0x%016llx), tag(%d)", | |
6555 | ioc->name, reason_str, le16_to_cpu(event_data->DevHandle), | |
6556 | (unsigned long long)le64_to_cpu(event_data->SASAddress), | |
6557 | le16_to_cpu(event_data->TaskTag)); | |
6558 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA) | |
6559 | pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name, | |
6560 | event_data->ASC, event_data->ASCQ); | |
6561 | pr_info("\n"); | |
6562 | } | |
f92363d1 SR |
6563 | |
6564 | /** | |
6565 | * _scsih_sas_device_status_change_event - handle device status change | |
6566 | * @ioc: per adapter object | |
6567 | * @fw_event: The fw_event_work object | |
6568 | * Context: user. | |
6569 | * | |
6570 | * Return nothing. | |
6571 | */ | |
6572 | static void | |
6573 | _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc, | |
6574 | struct fw_event_work *fw_event) | |
6575 | { | |
6576 | struct MPT3SAS_TARGET *target_priv_data; | |
6577 | struct _sas_device *sas_device; | |
6578 | u64 sas_address; | |
6579 | unsigned long flags; | |
6580 | Mpi2EventDataSasDeviceStatusChange_t *event_data = | |
35b62362 JL |
6581 | (Mpi2EventDataSasDeviceStatusChange_t *) |
6582 | fw_event->event_data; | |
f92363d1 | 6583 | |
f92363d1 SR |
6584 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
6585 | _scsih_sas_device_status_change_event_debug(ioc, | |
6586 | event_data); | |
f92363d1 SR |
6587 | |
6588 | /* In MPI Revision K (0xC), the internal device reset complete was | |
6589 | * implemented, so avoid setting tm_busy flag for older firmware. | |
6590 | */ | |
6591 | if ((ioc->facts.HeaderVersion >> 8) < 0xC) | |
6592 | return; | |
6593 | ||
6594 | if (event_data->ReasonCode != | |
6595 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET && | |
6596 | event_data->ReasonCode != | |
6597 | MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET) | |
6598 | return; | |
6599 | ||
6600 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
6601 | sas_address = le64_to_cpu(event_data->SASAddress); | |
d1cb5e49 | 6602 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 SR |
6603 | sas_address); |
6604 | ||
d1cb5e49 SR |
6605 | if (!sas_device || !sas_device->starget) |
6606 | goto out; | |
f92363d1 SR |
6607 | |
6608 | target_priv_data = sas_device->starget->hostdata; | |
d1cb5e49 SR |
6609 | if (!target_priv_data) |
6610 | goto out; | |
f92363d1 SR |
6611 | |
6612 | if (event_data->ReasonCode == | |
6613 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET) | |
6614 | target_priv_data->tm_busy = 1; | |
6615 | else | |
6616 | target_priv_data->tm_busy = 0; | |
d1cb5e49 SR |
6617 | |
6618 | out: | |
6619 | if (sas_device) | |
6620 | sas_device_put(sas_device); | |
6621 | ||
f92363d1 SR |
6622 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
6623 | } | |
6624 | ||
4318c734 | 6625 | |
c102e00c SPS |
6626 | /** |
6627 | * _scsih_check_pcie_access_status - check access flags | |
6628 | * @ioc: per adapter object | |
6629 | * @wwid: wwid | |
6630 | * @handle: sas device handle | |
6631 | * @access_flags: errors returned during discovery of the device | |
6632 | * | |
6633 | * Return 0 for success, else failure | |
6634 | */ | |
6635 | static u8 | |
6636 | _scsih_check_pcie_access_status(struct MPT3SAS_ADAPTER *ioc, u64 wwid, | |
6637 | u16 handle, u8 access_status) | |
6638 | { | |
6639 | u8 rc = 1; | |
6640 | char *desc = NULL; | |
6641 | ||
6642 | switch (access_status) { | |
6643 | case MPI26_PCIEDEV0_ASTATUS_NO_ERRORS: | |
6644 | case MPI26_PCIEDEV0_ASTATUS_NEEDS_INITIALIZATION: | |
6645 | rc = 0; | |
6646 | break; | |
6647 | case MPI26_PCIEDEV0_ASTATUS_CAPABILITY_FAILED: | |
6648 | desc = "PCIe device capability failed"; | |
6649 | break; | |
6650 | case MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED: | |
6651 | desc = "PCIe device blocked"; | |
6652 | break; | |
6653 | case MPI26_PCIEDEV0_ASTATUS_MEMORY_SPACE_ACCESS_FAILED: | |
6654 | desc = "PCIe device mem space access failed"; | |
6655 | break; | |
6656 | case MPI26_PCIEDEV0_ASTATUS_UNSUPPORTED_DEVICE: | |
6657 | desc = "PCIe device unsupported"; | |
6658 | break; | |
6659 | case MPI26_PCIEDEV0_ASTATUS_MSIX_REQUIRED: | |
6660 | desc = "PCIe device MSIx Required"; | |
6661 | break; | |
6662 | case MPI26_PCIEDEV0_ASTATUS_INIT_FAIL_MAX: | |
6663 | desc = "PCIe device init fail max"; | |
6664 | break; | |
6665 | case MPI26_PCIEDEV0_ASTATUS_UNKNOWN: | |
6666 | desc = "PCIe device status unknown"; | |
6667 | break; | |
6668 | case MPI26_PCIEDEV0_ASTATUS_NVME_READY_TIMEOUT: | |
6669 | desc = "nvme ready timeout"; | |
6670 | break; | |
6671 | case MPI26_PCIEDEV0_ASTATUS_NVME_DEVCFG_UNSUPPORTED: | |
6672 | desc = "nvme device configuration unsupported"; | |
6673 | break; | |
6674 | case MPI26_PCIEDEV0_ASTATUS_NVME_IDENTIFY_FAILED: | |
6675 | desc = "nvme identify failed"; | |
6676 | break; | |
6677 | case MPI26_PCIEDEV0_ASTATUS_NVME_QCONFIG_FAILED: | |
6678 | desc = "nvme qconfig failed"; | |
6679 | break; | |
6680 | case MPI26_PCIEDEV0_ASTATUS_NVME_QCREATION_FAILED: | |
6681 | desc = "nvme qcreation failed"; | |
6682 | break; | |
6683 | case MPI26_PCIEDEV0_ASTATUS_NVME_EVENTCFG_FAILED: | |
6684 | desc = "nvme eventcfg failed"; | |
6685 | break; | |
6686 | case MPI26_PCIEDEV0_ASTATUS_NVME_GET_FEATURE_STAT_FAILED: | |
6687 | desc = "nvme get feature stat failed"; | |
6688 | break; | |
6689 | case MPI26_PCIEDEV0_ASTATUS_NVME_IDLE_TIMEOUT: | |
6690 | desc = "nvme idle timeout"; | |
6691 | break; | |
6692 | case MPI26_PCIEDEV0_ASTATUS_NVME_FAILURE_STATUS: | |
6693 | desc = "nvme failure status"; | |
6694 | break; | |
6695 | default: | |
6696 | pr_err(MPT3SAS_FMT | |
6697 | " NVMe discovery error(0x%02x): wwid(0x%016llx)," | |
6698 | "handle(0x%04x)\n", ioc->name, access_status, | |
6699 | (unsigned long long)wwid, handle); | |
6700 | return rc; | |
6701 | } | |
6702 | ||
6703 | if (!rc) | |
6704 | return rc; | |
6705 | ||
6706 | pr_info(MPT3SAS_FMT | |
6707 | "NVMe discovery error(%s): wwid(0x%016llx), handle(0x%04x)\n", | |
6708 | ioc->name, desc, | |
6709 | (unsigned long long)wwid, handle); | |
6710 | return rc; | |
6711 | } | |
3075ac49 SPS |
6712 | |
6713 | /** | |
6714 | * _scsih_pcie_device_remove_from_sml - removing pcie device | |
6715 | * from SML and free up associated memory | |
6716 | * @ioc: per adapter object | |
6717 | * @pcie_device: the pcie_device object | |
6718 | * | |
6719 | * Return nothing. | |
6720 | */ | |
6721 | static void | |
6722 | _scsih_pcie_device_remove_from_sml(struct MPT3SAS_ADAPTER *ioc, | |
6723 | struct _pcie_device *pcie_device) | |
6724 | { | |
6725 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
6726 | ||
6727 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6728 | "%s: enter: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__, | |
6729 | pcie_device->handle, (unsigned long long) | |
6730 | pcie_device->wwid)); | |
6731 | if (pcie_device->enclosure_handle != 0) | |
6732 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6733 | "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n", | |
6734 | ioc->name, __func__, | |
6735 | (unsigned long long)pcie_device->enclosure_logical_id, | |
6736 | pcie_device->slot)); | |
6737 | if (pcie_device->connector_name[0] != '\0') | |
6738 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6739 | "%s: enter: enclosure level(0x%04x), connector name( %s)\n", | |
6740 | ioc->name, __func__, | |
6741 | pcie_device->enclosure_level, | |
6742 | pcie_device->connector_name)); | |
6743 | ||
6744 | if (pcie_device->starget && pcie_device->starget->hostdata) { | |
6745 | sas_target_priv_data = pcie_device->starget->hostdata; | |
6746 | sas_target_priv_data->deleted = 1; | |
6747 | _scsih_ublock_io_device(ioc, pcie_device->wwid); | |
6748 | sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE; | |
6749 | } | |
6750 | ||
6751 | pr_info(MPT3SAS_FMT | |
6752 | "removing handle(0x%04x), wwid (0x%016llx)\n", | |
6753 | ioc->name, pcie_device->handle, | |
6754 | (unsigned long long) pcie_device->wwid); | |
6755 | if (pcie_device->enclosure_handle != 0) | |
6756 | pr_info(MPT3SAS_FMT | |
6757 | "removing : enclosure logical id(0x%016llx), slot(%d)\n", | |
6758 | ioc->name, | |
6759 | (unsigned long long)pcie_device->enclosure_logical_id, | |
6760 | pcie_device->slot); | |
6761 | if (pcie_device->connector_name[0] != '\0') | |
6762 | pr_info(MPT3SAS_FMT | |
6763 | "removing: enclosure level(0x%04x), connector name( %s)\n", | |
6764 | ioc->name, pcie_device->enclosure_level, | |
6765 | pcie_device->connector_name); | |
6766 | ||
6767 | if (pcie_device->starget) | |
6768 | scsi_remove_target(&pcie_device->starget->dev); | |
6769 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6770 | "%s: exit: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__, | |
6771 | pcie_device->handle, (unsigned long long) | |
6772 | pcie_device->wwid)); | |
6773 | if (pcie_device->enclosure_handle != 0) | |
6774 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6775 | "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n", | |
6776 | ioc->name, __func__, | |
6777 | (unsigned long long)pcie_device->enclosure_logical_id, | |
6778 | pcie_device->slot)); | |
6779 | if (pcie_device->connector_name[0] != '\0') | |
6780 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6781 | "%s: exit: enclosure level(0x%04x), connector name( %s)\n", | |
6782 | ioc->name, __func__, pcie_device->enclosure_level, | |
6783 | pcie_device->connector_name)); | |
6784 | ||
6785 | kfree(pcie_device->serial_number); | |
6786 | } | |
6787 | ||
6788 | ||
c102e00c SPS |
6789 | /** |
6790 | * _scsih_pcie_check_device - checking device responsiveness | |
6791 | * @ioc: per adapter object | |
6792 | * @handle: attached device handle | |
6793 | * | |
6794 | * Returns nothing. | |
6795 | */ | |
6796 | static void | |
6797 | _scsih_pcie_check_device(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
6798 | { | |
6799 | Mpi2ConfigReply_t mpi_reply; | |
6800 | Mpi26PCIeDevicePage0_t pcie_device_pg0; | |
6801 | u32 ioc_status; | |
6802 | struct _pcie_device *pcie_device; | |
6803 | u64 wwid; | |
6804 | unsigned long flags; | |
6805 | struct scsi_target *starget; | |
6806 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
6807 | u32 device_info; | |
6808 | ||
6809 | if ((mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply, | |
6810 | &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE, handle))) | |
6811 | return; | |
6812 | ||
6813 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
6814 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | |
6815 | return; | |
6816 | ||
6817 | /* check if this is end device */ | |
6818 | device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo); | |
6819 | if (!(_scsih_is_nvme_device(device_info))) | |
6820 | return; | |
6821 | ||
6822 | wwid = le64_to_cpu(pcie_device_pg0.WWID); | |
6823 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
6824 | pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid); | |
6825 | ||
6826 | if (!pcie_device) { | |
6827 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
6828 | return; | |
6829 | } | |
6830 | ||
6831 | if (unlikely(pcie_device->handle != handle)) { | |
6832 | starget = pcie_device->starget; | |
6833 | sas_target_priv_data = starget->hostdata; | |
6834 | starget_printk(KERN_INFO, starget, | |
6835 | "handle changed from(0x%04x) to (0x%04x)!!!\n", | |
6836 | pcie_device->handle, handle); | |
6837 | sas_target_priv_data->handle = handle; | |
6838 | pcie_device->handle = handle; | |
6839 | ||
6840 | if (le32_to_cpu(pcie_device_pg0.Flags) & | |
6841 | MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) { | |
6842 | pcie_device->enclosure_level = | |
6843 | pcie_device_pg0.EnclosureLevel; | |
6844 | memcpy(&pcie_device->connector_name[0], | |
6845 | &pcie_device_pg0.ConnectorName[0], 4); | |
6846 | } else { | |
6847 | pcie_device->enclosure_level = 0; | |
6848 | pcie_device->connector_name[0] = '\0'; | |
6849 | } | |
6850 | } | |
6851 | ||
6852 | /* check if device is present */ | |
6853 | if (!(le32_to_cpu(pcie_device_pg0.Flags) & | |
6854 | MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT)) { | |
6855 | pr_info(MPT3SAS_FMT | |
6856 | "device is not present handle(0x%04x), flags!!!\n", | |
6857 | ioc->name, handle); | |
6858 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
6859 | pcie_device_put(pcie_device); | |
6860 | return; | |
6861 | } | |
6862 | ||
6863 | /* check if there were any issues with discovery */ | |
6864 | if (_scsih_check_pcie_access_status(ioc, wwid, handle, | |
6865 | pcie_device_pg0.AccessStatus)) { | |
6866 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
6867 | pcie_device_put(pcie_device); | |
6868 | return; | |
6869 | } | |
6870 | ||
6871 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
6872 | pcie_device_put(pcie_device); | |
6873 | ||
6874 | _scsih_ublock_io_device(ioc, wwid); | |
6875 | ||
6876 | return; | |
6877 | } | |
6878 | ||
6879 | /** | |
6880 | * _scsih_pcie_add_device - creating pcie device object | |
6881 | * @ioc: per adapter object | |
6882 | * @handle: pcie device handle | |
6883 | * | |
6884 | * Creating end device object, stored in ioc->pcie_device_list. | |
6885 | * | |
6886 | * Return 1 means queue the event later, 0 means complete the event | |
6887 | */ | |
6888 | static int | |
6889 | _scsih_pcie_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
6890 | { | |
6891 | Mpi26PCIeDevicePage0_t pcie_device_pg0; | |
6892 | Mpi26PCIeDevicePage2_t pcie_device_pg2; | |
6893 | Mpi2ConfigReply_t mpi_reply; | |
6894 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
6895 | struct _pcie_device *pcie_device; | |
6896 | u32 pcie_device_type; | |
6897 | u32 ioc_status; | |
6898 | u64 wwid; | |
6899 | ||
6900 | if ((mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply, | |
6901 | &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
6902 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6903 | ioc->name, __FILE__, __LINE__, __func__); | |
6904 | return 0; | |
6905 | } | |
6906 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6907 | MPI2_IOCSTATUS_MASK; | |
6908 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
6909 | pr_err(MPT3SAS_FMT | |
6910 | "failure at %s:%d/%s()!\n", | |
6911 | ioc->name, __FILE__, __LINE__, __func__); | |
6912 | return 0; | |
6913 | } | |
6914 | ||
6915 | set_bit(handle, ioc->pend_os_device_add); | |
6916 | wwid = le64_to_cpu(pcie_device_pg0.WWID); | |
6917 | ||
6918 | /* check if device is present */ | |
6919 | if (!(le32_to_cpu(pcie_device_pg0.Flags) & | |
6920 | MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT)) { | |
6921 | pr_err(MPT3SAS_FMT | |
6922 | "device is not present handle(0x04%x)!!!\n", | |
6923 | ioc->name, handle); | |
6924 | return 0; | |
6925 | } | |
6926 | ||
6927 | /* check if there were any issues with discovery */ | |
6928 | if (_scsih_check_pcie_access_status(ioc, wwid, handle, | |
6929 | pcie_device_pg0.AccessStatus)) | |
6930 | return 0; | |
6931 | ||
6932 | if (!(_scsih_is_nvme_device(le32_to_cpu(pcie_device_pg0.DeviceInfo)))) | |
6933 | return 0; | |
6934 | ||
6935 | pcie_device = mpt3sas_get_pdev_by_wwid(ioc, wwid); | |
6936 | if (pcie_device) { | |
6937 | clear_bit(handle, ioc->pend_os_device_add); | |
6938 | pcie_device_put(pcie_device); | |
6939 | return 0; | |
6940 | } | |
6941 | ||
6942 | pcie_device = kzalloc(sizeof(struct _pcie_device), GFP_KERNEL); | |
6943 | if (!pcie_device) { | |
6944 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6945 | ioc->name, __FILE__, __LINE__, __func__); | |
6946 | return 0; | |
6947 | } | |
6948 | ||
6949 | kref_init(&pcie_device->refcount); | |
6950 | pcie_device->id = ioc->pcie_target_id++; | |
6951 | pcie_device->channel = PCIE_CHANNEL; | |
6952 | pcie_device->handle = handle; | |
6953 | pcie_device->device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo); | |
6954 | pcie_device->wwid = wwid; | |
6955 | pcie_device->port_num = pcie_device_pg0.PortNum; | |
6956 | pcie_device->fast_path = (le32_to_cpu(pcie_device_pg0.Flags) & | |
6957 | MPI26_PCIEDEV0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0; | |
6958 | pcie_device_type = pcie_device->device_info & | |
6959 | MPI26_PCIE_DEVINFO_MASK_DEVICE_TYPE; | |
6960 | ||
6961 | pcie_device->enclosure_handle = | |
6962 | le16_to_cpu(pcie_device_pg0.EnclosureHandle); | |
6963 | if (pcie_device->enclosure_handle != 0) | |
6964 | pcie_device->slot = le16_to_cpu(pcie_device_pg0.Slot); | |
6965 | ||
6966 | if (le16_to_cpu(pcie_device_pg0.Flags) & | |
6967 | MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) { | |
6968 | pcie_device->enclosure_level = pcie_device_pg0.EnclosureLevel; | |
6969 | memcpy(&pcie_device->connector_name[0], | |
6970 | &pcie_device_pg0.ConnectorName[0], 4); | |
6971 | } else { | |
6972 | pcie_device->enclosure_level = 0; | |
6973 | pcie_device->connector_name[0] = '\0'; | |
6974 | } | |
6975 | ||
6976 | /* get enclosure_logical_id */ | |
6977 | if (pcie_device->enclosure_handle && | |
6978 | !(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
6979 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
6980 | pcie_device->enclosure_handle))) | |
6981 | pcie_device->enclosure_logical_id = | |
6982 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
6983 | ||
6984 | /* TODO -- Add device name once FW supports it */ | |
6985 | if (mpt3sas_config_get_pcie_device_pg2(ioc, &mpi_reply, | |
6986 | &pcie_device_pg2, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)) { | |
6987 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6988 | ioc->name, __FILE__, __LINE__, __func__); | |
6989 | kfree(pcie_device); | |
6990 | return 0; | |
6991 | } | |
6992 | ||
6993 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
6994 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
6995 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6996 | ioc->name, __FILE__, __LINE__, __func__); | |
6997 | kfree(pcie_device); | |
6998 | return 0; | |
6999 | } | |
7000 | pcie_device->nvme_mdts = | |
7001 | le32_to_cpu(pcie_device_pg2.MaximumDataTransferSize); | |
7002 | ||
7003 | if (ioc->wait_for_discovery_to_complete) | |
7004 | _scsih_pcie_device_init_add(ioc, pcie_device); | |
7005 | else | |
7006 | _scsih_pcie_device_add(ioc, pcie_device); | |
7007 | ||
7008 | pcie_device_put(pcie_device); | |
7009 | return 0; | |
7010 | } | |
4318c734 SPS |
7011 | |
7012 | /** | |
7013 | * _scsih_pcie_topology_change_event_debug - debug for topology | |
7014 | * event | |
7015 | * @ioc: per adapter object | |
7016 | * @event_data: event data payload | |
7017 | * Context: user. | |
7018 | */ | |
7019 | static void | |
7020 | _scsih_pcie_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
7021 | Mpi26EventDataPCIeTopologyChangeList_t *event_data) | |
7022 | { | |
7023 | int i; | |
7024 | u16 handle; | |
7025 | u16 reason_code; | |
7026 | u8 port_number; | |
7027 | char *status_str = NULL; | |
7028 | u8 link_rate, prev_link_rate; | |
7029 | ||
7030 | switch (event_data->SwitchStatus) { | |
7031 | case MPI26_EVENT_PCIE_TOPO_SS_ADDED: | |
7032 | status_str = "add"; | |
7033 | break; | |
7034 | case MPI26_EVENT_PCIE_TOPO_SS_NOT_RESPONDING: | |
7035 | status_str = "remove"; | |
7036 | break; | |
7037 | case MPI26_EVENT_PCIE_TOPO_SS_RESPONDING: | |
7038 | case 0: | |
7039 | status_str = "responding"; | |
7040 | break; | |
7041 | case MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING: | |
7042 | status_str = "remove delay"; | |
7043 | break; | |
7044 | default: | |
7045 | status_str = "unknown status"; | |
7046 | break; | |
7047 | } | |
7048 | pr_info(MPT3SAS_FMT "pcie topology change: (%s)\n", | |
7049 | ioc->name, status_str); | |
7050 | pr_info("\tswitch_handle(0x%04x), enclosure_handle(0x%04x)" | |
7051 | "start_port(%02d), count(%d)\n", | |
7052 | le16_to_cpu(event_data->SwitchDevHandle), | |
7053 | le16_to_cpu(event_data->EnclosureHandle), | |
7054 | event_data->StartPortNum, event_data->NumEntries); | |
7055 | for (i = 0; i < event_data->NumEntries; i++) { | |
7056 | handle = | |
7057 | le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle); | |
7058 | if (!handle) | |
7059 | continue; | |
7060 | port_number = event_data->StartPortNum + i; | |
7061 | reason_code = event_data->PortEntry[i].PortStatus; | |
7062 | switch (reason_code) { | |
7063 | case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED: | |
7064 | status_str = "target add"; | |
7065 | break; | |
7066 | case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING: | |
7067 | status_str = "target remove"; | |
7068 | break; | |
7069 | case MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING: | |
7070 | status_str = "delay target remove"; | |
7071 | break; | |
7072 | case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED: | |
7073 | status_str = "link rate change"; | |
7074 | break; | |
7075 | case MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE: | |
7076 | status_str = "target responding"; | |
7077 | break; | |
7078 | default: | |
7079 | status_str = "unknown"; | |
7080 | break; | |
7081 | } | |
7082 | link_rate = event_data->PortEntry[i].CurrentPortInfo & | |
7083 | MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK; | |
7084 | prev_link_rate = event_data->PortEntry[i].PreviousPortInfo & | |
7085 | MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK; | |
7086 | pr_info("\tport(%02d), attached_handle(0x%04x): %s:" | |
7087 | " link rate: new(0x%02x), old(0x%02x)\n", port_number, | |
7088 | handle, status_str, link_rate, prev_link_rate); | |
7089 | } | |
7090 | } | |
7091 | ||
7092 | /** | |
7093 | * _scsih_pcie_topology_change_event - handle PCIe topology | |
7094 | * changes | |
7095 | * @ioc: per adapter object | |
7096 | * @fw_event: The fw_event_work object | |
7097 | * Context: user. | |
7098 | * | |
7099 | */ | |
45b7aef7 | 7100 | static void |
4318c734 SPS |
7101 | _scsih_pcie_topology_change_event(struct MPT3SAS_ADAPTER *ioc, |
7102 | struct fw_event_work *fw_event) | |
7103 | { | |
7104 | int i; | |
7105 | u16 handle; | |
7106 | u16 reason_code; | |
7107 | u8 link_rate, prev_link_rate; | |
7108 | unsigned long flags; | |
7109 | int rc; | |
4318c734 SPS |
7110 | Mpi26EventDataPCIeTopologyChangeList_t *event_data = |
7111 | (Mpi26EventDataPCIeTopologyChangeList_t *) fw_event->event_data; | |
7112 | struct _pcie_device *pcie_device; | |
7113 | ||
7114 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) | |
7115 | _scsih_pcie_topology_change_event_debug(ioc, event_data); | |
7116 | ||
7117 | if (ioc->shost_recovery || ioc->remove_host || | |
7118 | ioc->pci_error_recovery) | |
45b7aef7 | 7119 | return; |
4318c734 SPS |
7120 | |
7121 | if (fw_event->ignore) { | |
7122 | dewtprintk(ioc, pr_info(MPT3SAS_FMT "ignoring switch event\n", | |
7123 | ioc->name)); | |
45b7aef7 | 7124 | return; |
4318c734 SPS |
7125 | } |
7126 | ||
7127 | /* handle siblings events */ | |
7128 | for (i = 0; i < event_data->NumEntries; i++) { | |
7129 | if (fw_event->ignore) { | |
7130 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7131 | "ignoring switch event\n", ioc->name)); | |
45b7aef7 | 7132 | return; |
4318c734 SPS |
7133 | } |
7134 | if (ioc->remove_host || ioc->pci_error_recovery) | |
45b7aef7 | 7135 | return; |
4318c734 SPS |
7136 | reason_code = event_data->PortEntry[i].PortStatus; |
7137 | handle = | |
7138 | le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle); | |
7139 | if (!handle) | |
7140 | continue; | |
7141 | ||
7142 | link_rate = event_data->PortEntry[i].CurrentPortInfo | |
7143 | & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK; | |
7144 | prev_link_rate = event_data->PortEntry[i].PreviousPortInfo | |
7145 | & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK; | |
7146 | ||
7147 | switch (reason_code) { | |
7148 | case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED: | |
7149 | if (ioc->shost_recovery) | |
7150 | break; | |
7151 | if (link_rate == prev_link_rate) | |
7152 | break; | |
7153 | if (link_rate < MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5) | |
7154 | break; | |
7155 | ||
7156 | _scsih_pcie_check_device(ioc, handle); | |
7157 | ||
7158 | /* This code after this point handles the test case | |
7159 | * where a device has been added, however its returning | |
7160 | * BUSY for sometime. Then before the Device Missing | |
7161 | * Delay expires and the device becomes READY, the | |
7162 | * device is removed and added back. | |
7163 | */ | |
7164 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
7165 | pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle); | |
7166 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
7167 | ||
7168 | if (pcie_device) { | |
7169 | pcie_device_put(pcie_device); | |
7170 | break; | |
7171 | } | |
7172 | ||
7173 | if (!test_bit(handle, ioc->pend_os_device_add)) | |
7174 | break; | |
7175 | ||
7176 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7177 | "handle(0x%04x) device not found: convert " | |
7178 | "event to a device add\n", ioc->name, handle)); | |
7179 | event_data->PortEntry[i].PortStatus &= 0xF0; | |
7180 | event_data->PortEntry[i].PortStatus |= | |
7181 | MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED; | |
7182 | case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED: | |
7183 | if (ioc->shost_recovery) | |
7184 | break; | |
7185 | if (link_rate < MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5) | |
7186 | break; | |
7187 | ||
7188 | rc = _scsih_pcie_add_device(ioc, handle); | |
7189 | if (!rc) { | |
7190 | /* mark entry vacant */ | |
7191 | /* TODO This needs to be reviewed and fixed, | |
7192 | * we dont have an entry | |
7193 | * to make an event void like vacant | |
7194 | */ | |
7195 | event_data->PortEntry[i].PortStatus |= | |
7196 | MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE; | |
7197 | } | |
7198 | break; | |
7199 | case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING: | |
7200 | _scsih_pcie_device_remove_by_handle(ioc, handle); | |
7201 | break; | |
7202 | } | |
7203 | } | |
4318c734 SPS |
7204 | } |
7205 | ||
7206 | /** | |
7207 | * _scsih_pcie_device_status_change_event_debug - debug for | |
7208 | * device event | |
7209 | * @event_data: event data payload | |
7210 | * Context: user. | |
7211 | * | |
7212 | * Return nothing. | |
7213 | */ | |
7214 | static void | |
7215 | _scsih_pcie_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
7216 | Mpi26EventDataPCIeDeviceStatusChange_t *event_data) | |
7217 | { | |
7218 | char *reason_str = NULL; | |
7219 | ||
7220 | switch (event_data->ReasonCode) { | |
7221 | case MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA: | |
7222 | reason_str = "smart data"; | |
7223 | break; | |
7224 | case MPI26_EVENT_PCIDEV_STAT_RC_UNSUPPORTED: | |
7225 | reason_str = "unsupported device discovered"; | |
7226 | break; | |
7227 | case MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET: | |
7228 | reason_str = "internal device reset"; | |
7229 | break; | |
7230 | case MPI26_EVENT_PCIDEV_STAT_RC_TASK_ABORT_INTERNAL: | |
7231 | reason_str = "internal task abort"; | |
7232 | break; | |
7233 | case MPI26_EVENT_PCIDEV_STAT_RC_ABORT_TASK_SET_INTERNAL: | |
7234 | reason_str = "internal task abort set"; | |
7235 | break; | |
7236 | case MPI26_EVENT_PCIDEV_STAT_RC_CLEAR_TASK_SET_INTERNAL: | |
7237 | reason_str = "internal clear task set"; | |
7238 | break; | |
7239 | case MPI26_EVENT_PCIDEV_STAT_RC_QUERY_TASK_INTERNAL: | |
7240 | reason_str = "internal query task"; | |
7241 | break; | |
7242 | case MPI26_EVENT_PCIDEV_STAT_RC_DEV_INIT_FAILURE: | |
7243 | reason_str = "device init failure"; | |
7244 | break; | |
7245 | case MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET: | |
7246 | reason_str = "internal device reset complete"; | |
7247 | break; | |
7248 | case MPI26_EVENT_PCIDEV_STAT_RC_CMP_TASK_ABORT_INTERNAL: | |
7249 | reason_str = "internal task abort complete"; | |
7250 | break; | |
7251 | case MPI26_EVENT_PCIDEV_STAT_RC_ASYNC_NOTIFICATION: | |
7252 | reason_str = "internal async notification"; | |
7253 | break; | |
7254 | default: | |
7255 | reason_str = "unknown reason"; | |
7256 | break; | |
7257 | } | |
7258 | ||
7259 | pr_info(MPT3SAS_FMT "PCIE device status change: (%s)\n" | |
7260 | "\thandle(0x%04x), WWID(0x%016llx), tag(%d)", | |
7261 | ioc->name, reason_str, le16_to_cpu(event_data->DevHandle), | |
7262 | (unsigned long long)le64_to_cpu(event_data->WWID), | |
7263 | le16_to_cpu(event_data->TaskTag)); | |
7264 | if (event_data->ReasonCode == MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA) | |
7265 | pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name, | |
7266 | event_data->ASC, event_data->ASCQ); | |
7267 | pr_info("\n"); | |
7268 | } | |
7269 | ||
7270 | /** | |
7271 | * _scsih_pcie_device_status_change_event - handle device status | |
7272 | * change | |
7273 | * @ioc: per adapter object | |
7274 | * @fw_event: The fw_event_work object | |
7275 | * Context: user. | |
7276 | * | |
7277 | * Return nothing. | |
7278 | */ | |
7279 | static void | |
7280 | _scsih_pcie_device_status_change_event(struct MPT3SAS_ADAPTER *ioc, | |
7281 | struct fw_event_work *fw_event) | |
7282 | { | |
7283 | struct MPT3SAS_TARGET *target_priv_data; | |
7284 | struct _pcie_device *pcie_device; | |
7285 | u64 wwid; | |
7286 | unsigned long flags; | |
7287 | Mpi26EventDataPCIeDeviceStatusChange_t *event_data = | |
7288 | (Mpi26EventDataPCIeDeviceStatusChange_t *)fw_event->event_data; | |
7289 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) | |
7290 | _scsih_pcie_device_status_change_event_debug(ioc, | |
7291 | event_data); | |
7292 | ||
7293 | if (event_data->ReasonCode != | |
7294 | MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET && | |
7295 | event_data->ReasonCode != | |
7296 | MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET) | |
7297 | return; | |
7298 | ||
7299 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
7300 | wwid = le64_to_cpu(event_data->WWID); | |
7301 | pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid); | |
7302 | ||
7303 | if (!pcie_device || !pcie_device->starget) | |
7304 | goto out; | |
7305 | ||
7306 | target_priv_data = pcie_device->starget->hostdata; | |
7307 | if (!target_priv_data) | |
7308 | goto out; | |
7309 | ||
7310 | if (event_data->ReasonCode == | |
7311 | MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET) | |
7312 | target_priv_data->tm_busy = 1; | |
7313 | else | |
7314 | target_priv_data->tm_busy = 0; | |
7315 | out: | |
7316 | if (pcie_device) | |
7317 | pcie_device_put(pcie_device); | |
7318 | ||
7319 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
7320 | } | |
7321 | ||
f92363d1 SR |
7322 | /** |
7323 | * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure | |
7324 | * event | |
7325 | * @ioc: per adapter object | |
7326 | * @event_data: event data payload | |
7327 | * Context: user. | |
7328 | * | |
7329 | * Return nothing. | |
7330 | */ | |
7331 | static void | |
7332 | _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
7333 | Mpi2EventDataSasEnclDevStatusChange_t *event_data) | |
7334 | { | |
7335 | char *reason_str = NULL; | |
7336 | ||
7337 | switch (event_data->ReasonCode) { | |
7338 | case MPI2_EVENT_SAS_ENCL_RC_ADDED: | |
7339 | reason_str = "enclosure add"; | |
7340 | break; | |
7341 | case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING: | |
7342 | reason_str = "enclosure remove"; | |
7343 | break; | |
7344 | default: | |
7345 | reason_str = "unknown reason"; | |
7346 | break; | |
7347 | } | |
7348 | ||
7349 | pr_info(MPT3SAS_FMT "enclosure status change: (%s)\n" | |
7350 | "\thandle(0x%04x), enclosure logical id(0x%016llx)" | |
7351 | " number slots(%d)\n", ioc->name, reason_str, | |
7352 | le16_to_cpu(event_data->EnclosureHandle), | |
7353 | (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID), | |
7354 | le16_to_cpu(event_data->StartSlot)); | |
7355 | } | |
f92363d1 SR |
7356 | |
7357 | /** | |
7358 | * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events | |
7359 | * @ioc: per adapter object | |
7360 | * @fw_event: The fw_event_work object | |
7361 | * Context: user. | |
7362 | * | |
7363 | * Return nothing. | |
7364 | */ | |
7365 | static void | |
7366 | _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc, | |
7367 | struct fw_event_work *fw_event) | |
7368 | { | |
f92363d1 SR |
7369 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
7370 | _scsih_sas_enclosure_dev_status_change_event_debug(ioc, | |
35b62362 | 7371 | (Mpi2EventDataSasEnclDevStatusChange_t *) |
f92363d1 | 7372 | fw_event->event_data); |
f92363d1 SR |
7373 | } |
7374 | ||
7375 | /** | |
7376 | * _scsih_sas_broadcast_primitive_event - handle broadcast events | |
7377 | * @ioc: per adapter object | |
7378 | * @fw_event: The fw_event_work object | |
7379 | * Context: user. | |
7380 | * | |
7381 | * Return nothing. | |
7382 | */ | |
7383 | static void | |
7384 | _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc, | |
7385 | struct fw_event_work *fw_event) | |
7386 | { | |
7387 | struct scsi_cmnd *scmd; | |
7388 | struct scsi_device *sdev; | |
6da999fe | 7389 | struct scsiio_tracker *st; |
f92363d1 SR |
7390 | u16 smid, handle; |
7391 | u32 lun; | |
7392 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
7393 | u32 termination_count; | |
7394 | u32 query_count; | |
7395 | Mpi2SCSITaskManagementReply_t *mpi_reply; | |
35b62362 JL |
7396 | Mpi2EventDataSasBroadcastPrimitive_t *event_data = |
7397 | (Mpi2EventDataSasBroadcastPrimitive_t *) | |
7398 | fw_event->event_data; | |
f92363d1 SR |
7399 | u16 ioc_status; |
7400 | unsigned long flags; | |
7401 | int r; | |
7402 | u8 max_retries = 0; | |
7403 | u8 task_abort_retries; | |
7404 | ||
7405 | mutex_lock(&ioc->tm_cmds.mutex); | |
7406 | pr_info(MPT3SAS_FMT | |
7407 | "%s: enter: phy number(%d), width(%d)\n", | |
7408 | ioc->name, __func__, event_data->PhyNum, | |
7409 | event_data->PortWidth); | |
7410 | ||
7411 | _scsih_block_io_all_device(ioc); | |
7412 | ||
7413 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7414 | mpi_reply = ioc->tm_cmds.reply; | |
7415 | broadcast_aen_retry: | |
7416 | ||
7417 | /* sanity checks for retrying this loop */ | |
7418 | if (max_retries++ == 5) { | |
7419 | dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: giving up\n", | |
7420 | ioc->name, __func__)); | |
7421 | goto out; | |
7422 | } else if (max_retries > 1) | |
7423 | dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: %d retry\n", | |
7424 | ioc->name, __func__, max_retries - 1)); | |
7425 | ||
7426 | termination_count = 0; | |
7427 | query_count = 0; | |
7428 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { | |
7429 | if (ioc->shost_recovery) | |
7430 | goto out; | |
6da999fe HR |
7431 | st = &ioc->scsi_lookup[smid - 1]; |
7432 | scmd = st->scmd; | |
f92363d1 SR |
7433 | if (!scmd) |
7434 | continue; | |
7435 | sdev = scmd->device; | |
7436 | sas_device_priv_data = sdev->hostdata; | |
7437 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) | |
7438 | continue; | |
7439 | /* skip hidden raid components */ | |
7440 | if (sas_device_priv_data->sas_target->flags & | |
7441 | MPT_TARGET_FLAGS_RAID_COMPONENT) | |
7442 | continue; | |
7443 | /* skip volumes */ | |
7444 | if (sas_device_priv_data->sas_target->flags & | |
7445 | MPT_TARGET_FLAGS_VOLUME) | |
7446 | continue; | |
7447 | ||
7448 | handle = sas_device_priv_data->sas_target->handle; | |
7449 | lun = sas_device_priv_data->lun; | |
7450 | query_count++; | |
7451 | ||
7452 | if (ioc->shost_recovery) | |
7453 | goto out; | |
7454 | ||
7455 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
6da999fe HR |
7456 | r = mpt3sas_scsih_issue_tm(ioc, handle, lun, |
7457 | MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, | |
7458 | st->msix_io, 30); | |
f92363d1 SR |
7459 | if (r == FAILED) { |
7460 | sdev_printk(KERN_WARNING, sdev, | |
7461 | "mpt3sas_scsih_issue_tm: FAILED when sending " | |
7462 | "QUERY_TASK: scmd(%p)\n", scmd); | |
7463 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7464 | goto broadcast_aen_retry; | |
7465 | } | |
7466 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) | |
7467 | & MPI2_IOCSTATUS_MASK; | |
7468 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
7469 | sdev_printk(KERN_WARNING, sdev, | |
7470 | "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n", | |
7471 | ioc_status, scmd); | |
7472 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7473 | goto broadcast_aen_retry; | |
7474 | } | |
7475 | ||
7476 | /* see if IO is still owned by IOC and target */ | |
7477 | if (mpi_reply->ResponseCode == | |
7478 | MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED || | |
7479 | mpi_reply->ResponseCode == | |
7480 | MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) { | |
7481 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7482 | continue; | |
7483 | } | |
7484 | task_abort_retries = 0; | |
7485 | tm_retry: | |
7486 | if (task_abort_retries++ == 60) { | |
7487 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7488 | "%s: ABORT_TASK: giving up\n", ioc->name, | |
7489 | __func__)); | |
7490 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7491 | goto broadcast_aen_retry; | |
7492 | } | |
7493 | ||
7494 | if (ioc->shost_recovery) | |
7495 | goto out_no_lock; | |
7496 | ||
6da999fe HR |
7497 | r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->lun, |
7498 | MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, | |
7499 | st->msix_io, 30); | |
7500 | if (r == FAILED || st->scmd) { | |
f92363d1 SR |
7501 | sdev_printk(KERN_WARNING, sdev, |
7502 | "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : " | |
7503 | "scmd(%p)\n", scmd); | |
7504 | goto tm_retry; | |
7505 | } | |
7506 | ||
7507 | if (task_abort_retries > 1) | |
7508 | sdev_printk(KERN_WARNING, sdev, | |
7509 | "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):" | |
7510 | " scmd(%p)\n", | |
7511 | task_abort_retries - 1, scmd); | |
7512 | ||
7513 | termination_count += le32_to_cpu(mpi_reply->TerminationCount); | |
7514 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7515 | } | |
7516 | ||
7517 | if (ioc->broadcast_aen_pending) { | |
7518 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7519 | "%s: loop back due to pending AEN\n", | |
7520 | ioc->name, __func__)); | |
7521 | ioc->broadcast_aen_pending = 0; | |
7522 | goto broadcast_aen_retry; | |
7523 | } | |
7524 | ||
7525 | out: | |
7526 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
7527 | out_no_lock: | |
7528 | ||
7529 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7530 | "%s - exit, query_count = %d termination_count = %d\n", | |
7531 | ioc->name, __func__, query_count, termination_count)); | |
7532 | ||
7533 | ioc->broadcast_aen_busy = 0; | |
7534 | if (!ioc->shost_recovery) | |
7535 | _scsih_ublock_io_all_device(ioc); | |
7536 | mutex_unlock(&ioc->tm_cmds.mutex); | |
7537 | } | |
7538 | ||
7539 | /** | |
7540 | * _scsih_sas_discovery_event - handle discovery events | |
7541 | * @ioc: per adapter object | |
7542 | * @fw_event: The fw_event_work object | |
7543 | * Context: user. | |
7544 | * | |
7545 | * Return nothing. | |
7546 | */ | |
7547 | static void | |
7548 | _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc, | |
7549 | struct fw_event_work *fw_event) | |
7550 | { | |
35b62362 JL |
7551 | Mpi2EventDataSasDiscovery_t *event_data = |
7552 | (Mpi2EventDataSasDiscovery_t *) fw_event->event_data; | |
f92363d1 | 7553 | |
f92363d1 SR |
7554 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) { |
7555 | pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name, | |
7556 | (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ? | |
7557 | "start" : "stop"); | |
af009411 SR |
7558 | if (event_data->DiscoveryStatus) |
7559 | pr_info("discovery_status(0x%08x)", | |
7560 | le32_to_cpu(event_data->DiscoveryStatus)); | |
7561 | pr_info("\n"); | |
f92363d1 | 7562 | } |
f92363d1 SR |
7563 | |
7564 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED && | |
7565 | !ioc->sas_hba.num_phys) { | |
7566 | if (disable_discovery > 0 && ioc->shost_recovery) { | |
7567 | /* Wait for the reset to complete */ | |
7568 | while (ioc->shost_recovery) | |
7569 | ssleep(1); | |
7570 | } | |
7571 | _scsih_sas_host_add(ioc); | |
7572 | } | |
7573 | } | |
7574 | ||
4318c734 SPS |
7575 | /** |
7576 | * _scsih_pcie_enumeration_event - handle enumeration events | |
7577 | * @ioc: per adapter object | |
7578 | * @fw_event: The fw_event_work object | |
7579 | * Context: user. | |
7580 | * | |
7581 | * Return nothing. | |
7582 | */ | |
7583 | static void | |
7584 | _scsih_pcie_enumeration_event(struct MPT3SAS_ADAPTER *ioc, | |
7585 | struct fw_event_work *fw_event) | |
7586 | { | |
7587 | Mpi26EventDataPCIeEnumeration_t *event_data = | |
7588 | (Mpi26EventDataPCIeEnumeration_t *)fw_event->event_data; | |
7589 | ||
6767aced DC |
7590 | if (!(ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)) |
7591 | return; | |
7592 | ||
7593 | pr_info(MPT3SAS_FMT "pcie enumeration event: (%s) Flag 0x%02x", | |
7594 | ioc->name, | |
7595 | (event_data->ReasonCode == MPI26_EVENT_PCIE_ENUM_RC_STARTED) ? | |
7596 | "started" : "completed", | |
7597 | event_data->Flags); | |
4318c734 | 7598 | if (event_data->EnumerationStatus) |
6767aced DC |
7599 | pr_cont("enumeration_status(0x%08x)", |
7600 | le32_to_cpu(event_data->EnumerationStatus)); | |
7601 | pr_cont("\n"); | |
4318c734 SPS |
7602 | } |
7603 | ||
f92363d1 SR |
7604 | /** |
7605 | * _scsih_ir_fastpath - turn on fastpath for IR physdisk | |
7606 | * @ioc: per adapter object | |
7607 | * @handle: device handle for physical disk | |
7608 | * @phys_disk_num: physical disk number | |
7609 | * | |
7610 | * Return 0 for success, else failure. | |
7611 | */ | |
7612 | static int | |
7613 | _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num) | |
7614 | { | |
7615 | Mpi2RaidActionRequest_t *mpi_request; | |
7616 | Mpi2RaidActionReply_t *mpi_reply; | |
7617 | u16 smid; | |
7618 | u8 issue_reset = 0; | |
7619 | int rc = 0; | |
7620 | u16 ioc_status; | |
7621 | u32 log_info; | |
7622 | ||
c84b06a4 SR |
7623 | if (ioc->hba_mpi_version_belonged == MPI2_VERSION) |
7624 | return rc; | |
7625 | ||
f92363d1 SR |
7626 | mutex_lock(&ioc->scsih_cmds.mutex); |
7627 | ||
7628 | if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) { | |
7629 | pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n", | |
7630 | ioc->name, __func__); | |
7631 | rc = -EAGAIN; | |
7632 | goto out; | |
7633 | } | |
7634 | ioc->scsih_cmds.status = MPT3_CMD_PENDING; | |
7635 | ||
7636 | smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx); | |
7637 | if (!smid) { | |
7638 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
7639 | ioc->name, __func__); | |
7640 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
7641 | rc = -EAGAIN; | |
7642 | goto out; | |
7643 | } | |
7644 | ||
7645 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
7646 | ioc->scsih_cmds.smid = smid; | |
7647 | memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t)); | |
7648 | ||
7649 | mpi_request->Function = MPI2_FUNCTION_RAID_ACTION; | |
7650 | mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN; | |
7651 | mpi_request->PhysDiskNum = phys_disk_num; | |
7652 | ||
7653 | dewtprintk(ioc, pr_info(MPT3SAS_FMT "IR RAID_ACTION: turning fast "\ | |
7654 | "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc->name, | |
7655 | handle, phys_disk_num)); | |
7656 | ||
7657 | init_completion(&ioc->scsih_cmds.done); | |
81c16f83 | 7658 | ioc->put_smid_default(ioc, smid); |
f92363d1 SR |
7659 | wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ); |
7660 | ||
7661 | if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) { | |
7662 | pr_err(MPT3SAS_FMT "%s: timeout\n", | |
7663 | ioc->name, __func__); | |
7664 | if (!(ioc->scsih_cmds.status & MPT3_CMD_RESET)) | |
7665 | issue_reset = 1; | |
7666 | rc = -EFAULT; | |
7667 | goto out; | |
7668 | } | |
7669 | ||
7670 | if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) { | |
7671 | ||
7672 | mpi_reply = ioc->scsih_cmds.reply; | |
7673 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); | |
7674 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) | |
7675 | log_info = le32_to_cpu(mpi_reply->IOCLogInfo); | |
7676 | else | |
7677 | log_info = 0; | |
7678 | ioc_status &= MPI2_IOCSTATUS_MASK; | |
7679 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
7680 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7681 | "IR RAID_ACTION: failed: ioc_status(0x%04x), " | |
7682 | "loginfo(0x%08x)!!!\n", ioc->name, ioc_status, | |
7683 | log_info)); | |
7684 | rc = -EFAULT; | |
7685 | } else | |
7686 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7687 | "IR RAID_ACTION: completed successfully\n", | |
7688 | ioc->name)); | |
7689 | } | |
7690 | ||
7691 | out: | |
7692 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
7693 | mutex_unlock(&ioc->scsih_cmds.mutex); | |
7694 | ||
7695 | if (issue_reset) | |
98c56ad3 | 7696 | mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
f92363d1 SR |
7697 | return rc; |
7698 | } | |
7699 | ||
7700 | /** | |
7701 | * _scsih_reprobe_lun - reprobing lun | |
7702 | * @sdev: scsi device struct | |
7703 | * @no_uld_attach: sdev->no_uld_attach flag setting | |
7704 | * | |
7705 | **/ | |
7706 | static void | |
7707 | _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach) | |
7708 | { | |
f92363d1 SR |
7709 | sdev->no_uld_attach = no_uld_attach ? 1 : 0; |
7710 | sdev_printk(KERN_INFO, sdev, "%s raid component\n", | |
6c7abffc | 7711 | sdev->no_uld_attach ? "hiding" : "exposing"); |
8bbb1cf6 | 7712 | WARN_ON(scsi_device_reprobe(sdev)); |
f92363d1 SR |
7713 | } |
7714 | ||
7715 | /** | |
7716 | * _scsih_sas_volume_add - add new volume | |
7717 | * @ioc: per adapter object | |
7718 | * @element: IR config element data | |
7719 | * Context: user. | |
7720 | * | |
7721 | * Return nothing. | |
7722 | */ | |
7723 | static void | |
7724 | _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc, | |
7725 | Mpi2EventIrConfigElement_t *element) | |
7726 | { | |
7727 | struct _raid_device *raid_device; | |
7728 | unsigned long flags; | |
7729 | u64 wwid; | |
7730 | u16 handle = le16_to_cpu(element->VolDevHandle); | |
7731 | int rc; | |
7732 | ||
7733 | mpt3sas_config_get_volume_wwid(ioc, handle, &wwid); | |
7734 | if (!wwid) { | |
7735 | pr_err(MPT3SAS_FMT | |
7736 | "failure at %s:%d/%s()!\n", ioc->name, | |
7737 | __FILE__, __LINE__, __func__); | |
7738 | return; | |
7739 | } | |
7740 | ||
7741 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
7742 | raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid); | |
7743 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
7744 | ||
7745 | if (raid_device) | |
7746 | return; | |
7747 | ||
7748 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); | |
7749 | if (!raid_device) { | |
7750 | pr_err(MPT3SAS_FMT | |
7751 | "failure at %s:%d/%s()!\n", ioc->name, | |
7752 | __FILE__, __LINE__, __func__); | |
7753 | return; | |
7754 | } | |
7755 | ||
7756 | raid_device->id = ioc->sas_id++; | |
7757 | raid_device->channel = RAID_CHANNEL; | |
7758 | raid_device->handle = handle; | |
7759 | raid_device->wwid = wwid; | |
7760 | _scsih_raid_device_add(ioc, raid_device); | |
7761 | if (!ioc->wait_for_discovery_to_complete) { | |
7762 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
7763 | raid_device->id, 0); | |
7764 | if (rc) | |
7765 | _scsih_raid_device_remove(ioc, raid_device); | |
7766 | } else { | |
7767 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
7768 | _scsih_determine_boot_device(ioc, raid_device, 1); | |
7769 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
7770 | } | |
7771 | } | |
7772 | ||
7773 | /** | |
7774 | * _scsih_sas_volume_delete - delete volume | |
7775 | * @ioc: per adapter object | |
7776 | * @handle: volume device handle | |
7777 | * Context: user. | |
7778 | * | |
7779 | * Return nothing. | |
7780 | */ | |
7781 | static void | |
7782 | _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
7783 | { | |
7784 | struct _raid_device *raid_device; | |
7785 | unsigned long flags; | |
7786 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
7787 | struct scsi_target *starget = NULL; | |
7788 | ||
7789 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
c84b06a4 | 7790 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
7791 | if (raid_device) { |
7792 | if (raid_device->starget) { | |
7793 | starget = raid_device->starget; | |
7794 | sas_target_priv_data = starget->hostdata; | |
7795 | sas_target_priv_data->deleted = 1; | |
7796 | } | |
7797 | pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n", | |
7798 | ioc->name, raid_device->handle, | |
7799 | (unsigned long long) raid_device->wwid); | |
7800 | list_del(&raid_device->list); | |
7801 | kfree(raid_device); | |
7802 | } | |
7803 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
7804 | if (starget) | |
7805 | scsi_remove_target(&starget->dev); | |
7806 | } | |
7807 | ||
7808 | /** | |
7809 | * _scsih_sas_pd_expose - expose pd component to /dev/sdX | |
7810 | * @ioc: per adapter object | |
7811 | * @element: IR config element data | |
7812 | * Context: user. | |
7813 | * | |
7814 | * Return nothing. | |
7815 | */ | |
7816 | static void | |
7817 | _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc, | |
7818 | Mpi2EventIrConfigElement_t *element) | |
7819 | { | |
7820 | struct _sas_device *sas_device; | |
7821 | struct scsi_target *starget = NULL; | |
7822 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
7823 | unsigned long flags; | |
7824 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | |
7825 | ||
7826 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 | 7827 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
7828 | if (sas_device) { |
7829 | sas_device->volume_handle = 0; | |
7830 | sas_device->volume_wwid = 0; | |
7831 | clear_bit(handle, ioc->pd_handles); | |
7832 | if (sas_device->starget && sas_device->starget->hostdata) { | |
7833 | starget = sas_device->starget; | |
7834 | sas_target_priv_data = starget->hostdata; | |
7835 | sas_target_priv_data->flags &= | |
7836 | ~MPT_TARGET_FLAGS_RAID_COMPONENT; | |
7837 | } | |
7838 | } | |
7839 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
7840 | if (!sas_device) | |
7841 | return; | |
7842 | ||
7843 | /* exposing raid component */ | |
7844 | if (starget) | |
7845 | starget_for_each_device(starget, NULL, _scsih_reprobe_lun); | |
d1cb5e49 SR |
7846 | |
7847 | sas_device_put(sas_device); | |
f92363d1 SR |
7848 | } |
7849 | ||
7850 | /** | |
7851 | * _scsih_sas_pd_hide - hide pd component from /dev/sdX | |
7852 | * @ioc: per adapter object | |
7853 | * @element: IR config element data | |
7854 | * Context: user. | |
7855 | * | |
7856 | * Return nothing. | |
7857 | */ | |
7858 | static void | |
7859 | _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc, | |
7860 | Mpi2EventIrConfigElement_t *element) | |
7861 | { | |
7862 | struct _sas_device *sas_device; | |
7863 | struct scsi_target *starget = NULL; | |
7864 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
7865 | unsigned long flags; | |
7866 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | |
7867 | u16 volume_handle = 0; | |
7868 | u64 volume_wwid = 0; | |
7869 | ||
7870 | mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle); | |
7871 | if (volume_handle) | |
7872 | mpt3sas_config_get_volume_wwid(ioc, volume_handle, | |
7873 | &volume_wwid); | |
7874 | ||
7875 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 | 7876 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
7877 | if (sas_device) { |
7878 | set_bit(handle, ioc->pd_handles); | |
7879 | if (sas_device->starget && sas_device->starget->hostdata) { | |
7880 | starget = sas_device->starget; | |
7881 | sas_target_priv_data = starget->hostdata; | |
7882 | sas_target_priv_data->flags |= | |
7883 | MPT_TARGET_FLAGS_RAID_COMPONENT; | |
7884 | sas_device->volume_handle = volume_handle; | |
7885 | sas_device->volume_wwid = volume_wwid; | |
7886 | } | |
7887 | } | |
7888 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
7889 | if (!sas_device) | |
7890 | return; | |
7891 | ||
7892 | /* hiding raid component */ | |
7893 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); | |
c84b06a4 | 7894 | |
f92363d1 SR |
7895 | if (starget) |
7896 | starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun); | |
d1cb5e49 SR |
7897 | |
7898 | sas_device_put(sas_device); | |
f92363d1 SR |
7899 | } |
7900 | ||
7901 | /** | |
7902 | * _scsih_sas_pd_delete - delete pd component | |
7903 | * @ioc: per adapter object | |
7904 | * @element: IR config element data | |
7905 | * Context: user. | |
7906 | * | |
7907 | * Return nothing. | |
7908 | */ | |
7909 | static void | |
7910 | _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc, | |
7911 | Mpi2EventIrConfigElement_t *element) | |
7912 | { | |
7913 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | |
7914 | ||
7915 | _scsih_device_remove_by_handle(ioc, handle); | |
7916 | } | |
7917 | ||
7918 | /** | |
7919 | * _scsih_sas_pd_add - remove pd component | |
7920 | * @ioc: per adapter object | |
7921 | * @element: IR config element data | |
7922 | * Context: user. | |
7923 | * | |
7924 | * Return nothing. | |
7925 | */ | |
7926 | static void | |
7927 | _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc, | |
7928 | Mpi2EventIrConfigElement_t *element) | |
7929 | { | |
7930 | struct _sas_device *sas_device; | |
f92363d1 SR |
7931 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
7932 | Mpi2ConfigReply_t mpi_reply; | |
7933 | Mpi2SasDevicePage0_t sas_device_pg0; | |
7934 | u32 ioc_status; | |
7935 | u64 sas_address; | |
7936 | u16 parent_handle; | |
7937 | ||
7938 | set_bit(handle, ioc->pd_handles); | |
7939 | ||
d1cb5e49 | 7940 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
7941 | if (sas_device) { |
7942 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); | |
d1cb5e49 | 7943 | sas_device_put(sas_device); |
f92363d1 SR |
7944 | return; |
7945 | } | |
7946 | ||
7947 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
7948 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
7949 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
7950 | ioc->name, __FILE__, __LINE__, __func__); | |
7951 | return; | |
7952 | } | |
7953 | ||
7954 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
7955 | MPI2_IOCSTATUS_MASK; | |
7956 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
7957 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
7958 | ioc->name, __FILE__, __LINE__, __func__); | |
7959 | return; | |
7960 | } | |
7961 | ||
7962 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | |
7963 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) | |
7964 | mpt3sas_transport_update_links(ioc, sas_address, handle, | |
7965 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | |
7966 | ||
7967 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); | |
7968 | _scsih_add_device(ioc, handle, 0, 1); | |
7969 | } | |
7970 | ||
f92363d1 SR |
7971 | /** |
7972 | * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events | |
7973 | * @ioc: per adapter object | |
7974 | * @event_data: event data payload | |
7975 | * Context: user. | |
7976 | * | |
7977 | * Return nothing. | |
7978 | */ | |
7979 | static void | |
7980 | _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
7981 | Mpi2EventDataIrConfigChangeList_t *event_data) | |
7982 | { | |
7983 | Mpi2EventIrConfigElement_t *element; | |
7984 | u8 element_type; | |
7985 | int i; | |
7986 | char *reason_str = NULL, *element_str = NULL; | |
7987 | ||
7988 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
7989 | ||
7990 | pr_info(MPT3SAS_FMT "raid config change: (%s), elements(%d)\n", | |
7991 | ioc->name, (le32_to_cpu(event_data->Flags) & | |
7992 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? | |
7993 | "foreign" : "native", event_data->NumElements); | |
7994 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
7995 | switch (element->ReasonCode) { | |
7996 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: | |
7997 | reason_str = "add"; | |
7998 | break; | |
7999 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: | |
8000 | reason_str = "remove"; | |
8001 | break; | |
8002 | case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE: | |
8003 | reason_str = "no change"; | |
8004 | break; | |
8005 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: | |
8006 | reason_str = "hide"; | |
8007 | break; | |
8008 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: | |
8009 | reason_str = "unhide"; | |
8010 | break; | |
8011 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: | |
8012 | reason_str = "volume_created"; | |
8013 | break; | |
8014 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: | |
8015 | reason_str = "volume_deleted"; | |
8016 | break; | |
8017 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: | |
8018 | reason_str = "pd_created"; | |
8019 | break; | |
8020 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: | |
8021 | reason_str = "pd_deleted"; | |
8022 | break; | |
8023 | default: | |
8024 | reason_str = "unknown reason"; | |
8025 | break; | |
8026 | } | |
8027 | element_type = le16_to_cpu(element->ElementFlags) & | |
8028 | MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK; | |
8029 | switch (element_type) { | |
8030 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT: | |
8031 | element_str = "volume"; | |
8032 | break; | |
8033 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT: | |
8034 | element_str = "phys disk"; | |
8035 | break; | |
8036 | case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT: | |
8037 | element_str = "hot spare"; | |
8038 | break; | |
8039 | default: | |
8040 | element_str = "unknown element"; | |
8041 | break; | |
8042 | } | |
8043 | pr_info("\t(%s:%s), vol handle(0x%04x), " \ | |
8044 | "pd handle(0x%04x), pd num(0x%02x)\n", element_str, | |
8045 | reason_str, le16_to_cpu(element->VolDevHandle), | |
8046 | le16_to_cpu(element->PhysDiskDevHandle), | |
8047 | element->PhysDiskNum); | |
8048 | } | |
8049 | } | |
f92363d1 SR |
8050 | |
8051 | /** | |
8052 | * _scsih_sas_ir_config_change_event - handle ir configuration change events | |
8053 | * @ioc: per adapter object | |
8054 | * @fw_event: The fw_event_work object | |
8055 | * Context: user. | |
8056 | * | |
8057 | * Return nothing. | |
8058 | */ | |
8059 | static void | |
8060 | _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc, | |
8061 | struct fw_event_work *fw_event) | |
8062 | { | |
8063 | Mpi2EventIrConfigElement_t *element; | |
8064 | int i; | |
8065 | u8 foreign_config; | |
35b62362 JL |
8066 | Mpi2EventDataIrConfigChangeList_t *event_data = |
8067 | (Mpi2EventDataIrConfigChangeList_t *) | |
8068 | fw_event->event_data; | |
f92363d1 | 8069 | |
7786ab6a SR |
8070 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) && |
8071 | (!ioc->hide_ir_msg)) | |
f92363d1 SR |
8072 | _scsih_sas_ir_config_change_event_debug(ioc, event_data); |
8073 | ||
f92363d1 SR |
8074 | foreign_config = (le32_to_cpu(event_data->Flags) & |
8075 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0; | |
8076 | ||
8077 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
c84b06a4 SR |
8078 | if (ioc->shost_recovery && |
8079 | ioc->hba_mpi_version_belonged != MPI2_VERSION) { | |
f92363d1 SR |
8080 | for (i = 0; i < event_data->NumElements; i++, element++) { |
8081 | if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE) | |
8082 | _scsih_ir_fastpath(ioc, | |
8083 | le16_to_cpu(element->PhysDiskDevHandle), | |
8084 | element->PhysDiskNum); | |
8085 | } | |
8086 | return; | |
8087 | } | |
7786ab6a | 8088 | |
f92363d1 SR |
8089 | for (i = 0; i < event_data->NumElements; i++, element++) { |
8090 | ||
8091 | switch (element->ReasonCode) { | |
8092 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: | |
8093 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: | |
8094 | if (!foreign_config) | |
8095 | _scsih_sas_volume_add(ioc, element); | |
8096 | break; | |
8097 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: | |
8098 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: | |
8099 | if (!foreign_config) | |
8100 | _scsih_sas_volume_delete(ioc, | |
8101 | le16_to_cpu(element->VolDevHandle)); | |
8102 | break; | |
8103 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: | |
7786ab6a SR |
8104 | if (!ioc->is_warpdrive) |
8105 | _scsih_sas_pd_hide(ioc, element); | |
f92363d1 SR |
8106 | break; |
8107 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: | |
7786ab6a SR |
8108 | if (!ioc->is_warpdrive) |
8109 | _scsih_sas_pd_expose(ioc, element); | |
f92363d1 SR |
8110 | break; |
8111 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: | |
7786ab6a SR |
8112 | if (!ioc->is_warpdrive) |
8113 | _scsih_sas_pd_add(ioc, element); | |
f92363d1 SR |
8114 | break; |
8115 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: | |
7786ab6a SR |
8116 | if (!ioc->is_warpdrive) |
8117 | _scsih_sas_pd_delete(ioc, element); | |
f92363d1 SR |
8118 | break; |
8119 | } | |
8120 | } | |
8121 | } | |
8122 | ||
8123 | /** | |
8124 | * _scsih_sas_ir_volume_event - IR volume event | |
8125 | * @ioc: per adapter object | |
8126 | * @fw_event: The fw_event_work object | |
8127 | * Context: user. | |
8128 | * | |
8129 | * Return nothing. | |
8130 | */ | |
8131 | static void | |
8132 | _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc, | |
8133 | struct fw_event_work *fw_event) | |
8134 | { | |
8135 | u64 wwid; | |
8136 | unsigned long flags; | |
8137 | struct _raid_device *raid_device; | |
8138 | u16 handle; | |
8139 | u32 state; | |
8140 | int rc; | |
35b62362 JL |
8141 | Mpi2EventDataIrVolume_t *event_data = |
8142 | (Mpi2EventDataIrVolume_t *) fw_event->event_data; | |
f92363d1 SR |
8143 | |
8144 | if (ioc->shost_recovery) | |
8145 | return; | |
8146 | ||
8147 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) | |
8148 | return; | |
8149 | ||
8150 | handle = le16_to_cpu(event_data->VolDevHandle); | |
8151 | state = le32_to_cpu(event_data->NewValue); | |
7786ab6a SR |
8152 | if (!ioc->hide_ir_msg) |
8153 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
8154 | "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n", | |
8155 | ioc->name, __func__, handle, | |
8156 | le32_to_cpu(event_data->PreviousValue), state)); | |
f92363d1 SR |
8157 | switch (state) { |
8158 | case MPI2_RAID_VOL_STATE_MISSING: | |
8159 | case MPI2_RAID_VOL_STATE_FAILED: | |
8160 | _scsih_sas_volume_delete(ioc, handle); | |
8161 | break; | |
8162 | ||
8163 | case MPI2_RAID_VOL_STATE_ONLINE: | |
8164 | case MPI2_RAID_VOL_STATE_DEGRADED: | |
8165 | case MPI2_RAID_VOL_STATE_OPTIMAL: | |
8166 | ||
8167 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
c84b06a4 | 8168 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
8169 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
8170 | ||
8171 | if (raid_device) | |
8172 | break; | |
8173 | ||
8174 | mpt3sas_config_get_volume_wwid(ioc, handle, &wwid); | |
8175 | if (!wwid) { | |
8176 | pr_err(MPT3SAS_FMT | |
8177 | "failure at %s:%d/%s()!\n", ioc->name, | |
8178 | __FILE__, __LINE__, __func__); | |
8179 | break; | |
8180 | } | |
8181 | ||
8182 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); | |
8183 | if (!raid_device) { | |
8184 | pr_err(MPT3SAS_FMT | |
8185 | "failure at %s:%d/%s()!\n", ioc->name, | |
8186 | __FILE__, __LINE__, __func__); | |
8187 | break; | |
8188 | } | |
8189 | ||
8190 | raid_device->id = ioc->sas_id++; | |
8191 | raid_device->channel = RAID_CHANNEL; | |
8192 | raid_device->handle = handle; | |
8193 | raid_device->wwid = wwid; | |
8194 | _scsih_raid_device_add(ioc, raid_device); | |
8195 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
8196 | raid_device->id, 0); | |
8197 | if (rc) | |
8198 | _scsih_raid_device_remove(ioc, raid_device); | |
8199 | break; | |
8200 | ||
8201 | case MPI2_RAID_VOL_STATE_INITIALIZING: | |
8202 | default: | |
8203 | break; | |
8204 | } | |
8205 | } | |
8206 | ||
8207 | /** | |
8208 | * _scsih_sas_ir_physical_disk_event - PD event | |
8209 | * @ioc: per adapter object | |
8210 | * @fw_event: The fw_event_work object | |
8211 | * Context: user. | |
8212 | * | |
8213 | * Return nothing. | |
8214 | */ | |
8215 | static void | |
8216 | _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc, | |
8217 | struct fw_event_work *fw_event) | |
8218 | { | |
8219 | u16 handle, parent_handle; | |
8220 | u32 state; | |
8221 | struct _sas_device *sas_device; | |
f92363d1 SR |
8222 | Mpi2ConfigReply_t mpi_reply; |
8223 | Mpi2SasDevicePage0_t sas_device_pg0; | |
8224 | u32 ioc_status; | |
35b62362 JL |
8225 | Mpi2EventDataIrPhysicalDisk_t *event_data = |
8226 | (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data; | |
f92363d1 SR |
8227 | u64 sas_address; |
8228 | ||
8229 | if (ioc->shost_recovery) | |
8230 | return; | |
8231 | ||
8232 | if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED) | |
8233 | return; | |
8234 | ||
8235 | handle = le16_to_cpu(event_data->PhysDiskDevHandle); | |
8236 | state = le32_to_cpu(event_data->NewValue); | |
8237 | ||
7786ab6a SR |
8238 | if (!ioc->hide_ir_msg) |
8239 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
8240 | "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n", | |
8241 | ioc->name, __func__, handle, | |
f92363d1 | 8242 | le32_to_cpu(event_data->PreviousValue), state)); |
7786ab6a | 8243 | |
f92363d1 SR |
8244 | switch (state) { |
8245 | case MPI2_RAID_PD_STATE_ONLINE: | |
8246 | case MPI2_RAID_PD_STATE_DEGRADED: | |
8247 | case MPI2_RAID_PD_STATE_REBUILDING: | |
8248 | case MPI2_RAID_PD_STATE_OPTIMAL: | |
8249 | case MPI2_RAID_PD_STATE_HOT_SPARE: | |
8250 | ||
7786ab6a SR |
8251 | if (!ioc->is_warpdrive) |
8252 | set_bit(handle, ioc->pd_handles); | |
f92363d1 | 8253 | |
d1cb5e49 SR |
8254 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
8255 | if (sas_device) { | |
8256 | sas_device_put(sas_device); | |
f92363d1 | 8257 | return; |
d1cb5e49 | 8258 | } |
f92363d1 SR |
8259 | |
8260 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
8261 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | |
8262 | handle))) { | |
8263 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
8264 | ioc->name, __FILE__, __LINE__, __func__); | |
8265 | return; | |
8266 | } | |
8267 | ||
8268 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8269 | MPI2_IOCSTATUS_MASK; | |
8270 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
8271 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
8272 | ioc->name, __FILE__, __LINE__, __func__); | |
8273 | return; | |
8274 | } | |
8275 | ||
8276 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | |
8277 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) | |
8278 | mpt3sas_transport_update_links(ioc, sas_address, handle, | |
8279 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | |
8280 | ||
8281 | _scsih_add_device(ioc, handle, 0, 1); | |
8282 | ||
8283 | break; | |
8284 | ||
8285 | case MPI2_RAID_PD_STATE_OFFLINE: | |
8286 | case MPI2_RAID_PD_STATE_NOT_CONFIGURED: | |
8287 | case MPI2_RAID_PD_STATE_NOT_COMPATIBLE: | |
8288 | default: | |
8289 | break; | |
8290 | } | |
8291 | } | |
8292 | ||
f92363d1 SR |
8293 | /** |
8294 | * _scsih_sas_ir_operation_status_event_debug - debug for IR op event | |
8295 | * @ioc: per adapter object | |
8296 | * @event_data: event data payload | |
8297 | * Context: user. | |
8298 | * | |
8299 | * Return nothing. | |
8300 | */ | |
8301 | static void | |
8302 | _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
8303 | Mpi2EventDataIrOperationStatus_t *event_data) | |
8304 | { | |
8305 | char *reason_str = NULL; | |
8306 | ||
8307 | switch (event_data->RAIDOperation) { | |
8308 | case MPI2_EVENT_IR_RAIDOP_RESYNC: | |
8309 | reason_str = "resync"; | |
8310 | break; | |
8311 | case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION: | |
8312 | reason_str = "online capacity expansion"; | |
8313 | break; | |
8314 | case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK: | |
8315 | reason_str = "consistency check"; | |
8316 | break; | |
8317 | case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT: | |
8318 | reason_str = "background init"; | |
8319 | break; | |
8320 | case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT: | |
8321 | reason_str = "make data consistent"; | |
8322 | break; | |
8323 | } | |
8324 | ||
8325 | if (!reason_str) | |
8326 | return; | |
8327 | ||
8328 | pr_info(MPT3SAS_FMT "raid operational status: (%s)" \ | |
8329 | "\thandle(0x%04x), percent complete(%d)\n", | |
8330 | ioc->name, reason_str, | |
8331 | le16_to_cpu(event_data->VolDevHandle), | |
8332 | event_data->PercentComplete); | |
8333 | } | |
f92363d1 SR |
8334 | |
8335 | /** | |
8336 | * _scsih_sas_ir_operation_status_event - handle RAID operation events | |
8337 | * @ioc: per adapter object | |
8338 | * @fw_event: The fw_event_work object | |
8339 | * Context: user. | |
8340 | * | |
8341 | * Return nothing. | |
8342 | */ | |
8343 | static void | |
8344 | _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc, | |
8345 | struct fw_event_work *fw_event) | |
8346 | { | |
35b62362 JL |
8347 | Mpi2EventDataIrOperationStatus_t *event_data = |
8348 | (Mpi2EventDataIrOperationStatus_t *) | |
8349 | fw_event->event_data; | |
f92363d1 SR |
8350 | static struct _raid_device *raid_device; |
8351 | unsigned long flags; | |
8352 | u16 handle; | |
8353 | ||
7786ab6a SR |
8354 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) && |
8355 | (!ioc->hide_ir_msg)) | |
f92363d1 SR |
8356 | _scsih_sas_ir_operation_status_event_debug(ioc, |
8357 | event_data); | |
f92363d1 SR |
8358 | |
8359 | /* code added for raid transport support */ | |
8360 | if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) { | |
8361 | ||
8362 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
8363 | handle = le16_to_cpu(event_data->VolDevHandle); | |
c84b06a4 | 8364 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
8365 | if (raid_device) |
8366 | raid_device->percent_complete = | |
8367 | event_data->PercentComplete; | |
8368 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
8369 | } | |
8370 | } | |
8371 | ||
8372 | /** | |
8373 | * _scsih_prep_device_scan - initialize parameters prior to device scan | |
8374 | * @ioc: per adapter object | |
8375 | * | |
8376 | * Set the deleted flag prior to device scan. If the device is found during | |
8377 | * the scan, then we clear the deleted flag. | |
8378 | */ | |
8379 | static void | |
8380 | _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc) | |
8381 | { | |
8382 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
8383 | struct scsi_device *sdev; | |
8384 | ||
8385 | shost_for_each_device(sdev, ioc->shost) { | |
8386 | sas_device_priv_data = sdev->hostdata; | |
8387 | if (sas_device_priv_data && sas_device_priv_data->sas_target) | |
8388 | sas_device_priv_data->sas_target->deleted = 1; | |
8389 | } | |
8390 | } | |
8391 | ||
8392 | /** | |
8393 | * _scsih_mark_responding_sas_device - mark a sas_devices as responding | |
8394 | * @ioc: per adapter object | |
e6d45e3e | 8395 | * @sas_device_pg0: SAS Device page 0 |
f92363d1 SR |
8396 | * |
8397 | * After host reset, find out whether devices are still responding. | |
8398 | * Used in _scsih_remove_unresponsive_sas_devices. | |
8399 | * | |
8400 | * Return nothing. | |
8401 | */ | |
8402 | static void | |
e6d45e3e SR |
8403 | _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc, |
8404 | Mpi2SasDevicePage0_t *sas_device_pg0) | |
f92363d1 SR |
8405 | { |
8406 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; | |
8407 | struct scsi_target *starget; | |
aba5a85c | 8408 | struct _sas_device *sas_device = NULL; |
f92363d1 SR |
8409 | unsigned long flags; |
8410 | ||
8411 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
8412 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) { | |
e6d45e3e SR |
8413 | if ((sas_device->sas_address == sas_device_pg0->SASAddress) && |
8414 | (sas_device->slot == sas_device_pg0->Slot)) { | |
f92363d1 SR |
8415 | sas_device->responding = 1; |
8416 | starget = sas_device->starget; | |
8417 | if (starget && starget->hostdata) { | |
8418 | sas_target_priv_data = starget->hostdata; | |
8419 | sas_target_priv_data->tm_busy = 0; | |
8420 | sas_target_priv_data->deleted = 0; | |
8421 | } else | |
8422 | sas_target_priv_data = NULL; | |
e6d45e3e | 8423 | if (starget) { |
f92363d1 | 8424 | starget_printk(KERN_INFO, starget, |
e6d45e3e SR |
8425 | "handle(0x%04x), sas_addr(0x%016llx)\n", |
8426 | sas_device_pg0->DevHandle, | |
f92363d1 | 8427 | (unsigned long long) |
e6d45e3e SR |
8428 | sas_device->sas_address); |
8429 | ||
8430 | if (sas_device->enclosure_handle != 0) | |
8431 | starget_printk(KERN_INFO, starget, | |
8432 | "enclosure logical id(0x%016llx)," | |
8433 | " slot(%d)\n", | |
8434 | (unsigned long long) | |
8435 | sas_device->enclosure_logical_id, | |
8436 | sas_device->slot); | |
8437 | } | |
8438 | if (sas_device_pg0->Flags & | |
8439 | MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) { | |
8440 | sas_device->enclosure_level = | |
aa53bb89 | 8441 | sas_device_pg0->EnclosureLevel; |
e6d45e3e SR |
8442 | memcpy(&sas_device->connector_name[0], |
8443 | &sas_device_pg0->ConnectorName[0], 4); | |
8444 | } else { | |
8445 | sas_device->enclosure_level = 0; | |
8446 | sas_device->connector_name[0] = '\0'; | |
8447 | } | |
8448 | ||
aba5a85c SR |
8449 | _scsih_get_enclosure_logicalid_chassis_slot(ioc, |
8450 | sas_device_pg0, sas_device); | |
75888956 | 8451 | |
e6d45e3e | 8452 | if (sas_device->handle == sas_device_pg0->DevHandle) |
f92363d1 SR |
8453 | goto out; |
8454 | pr_info("\thandle changed from(0x%04x)!!!\n", | |
8455 | sas_device->handle); | |
e6d45e3e | 8456 | sas_device->handle = sas_device_pg0->DevHandle; |
f92363d1 | 8457 | if (sas_target_priv_data) |
e6d45e3e SR |
8458 | sas_target_priv_data->handle = |
8459 | sas_device_pg0->DevHandle; | |
f92363d1 SR |
8460 | goto out; |
8461 | } | |
8462 | } | |
8463 | out: | |
8464 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
8465 | } | |
8466 | ||
8467 | /** | |
8468 | * _scsih_search_responding_sas_devices - | |
8469 | * @ioc: per adapter object | |
8470 | * | |
8471 | * After host reset, find out whether devices are still responding. | |
8472 | * If not remove. | |
8473 | * | |
8474 | * Return nothing. | |
8475 | */ | |
8476 | static void | |
8477 | _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc) | |
8478 | { | |
8479 | Mpi2SasDevicePage0_t sas_device_pg0; | |
8480 | Mpi2ConfigReply_t mpi_reply; | |
8481 | u16 ioc_status; | |
8482 | u16 handle; | |
8483 | u32 device_info; | |
8484 | ||
8485 | pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name); | |
8486 | ||
8487 | if (list_empty(&ioc->sas_device_list)) | |
8488 | goto out; | |
8489 | ||
8490 | handle = 0xFFFF; | |
8491 | while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
8492 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | |
8493 | handle))) { | |
8494 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8495 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 8496 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 | 8497 | break; |
e6d45e3e SR |
8498 | handle = sas_device_pg0.DevHandle = |
8499 | le16_to_cpu(sas_device_pg0.DevHandle); | |
f92363d1 SR |
8500 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
8501 | if (!(_scsih_is_end_device(device_info))) | |
8502 | continue; | |
e6d45e3e SR |
8503 | sas_device_pg0.SASAddress = |
8504 | le64_to_cpu(sas_device_pg0.SASAddress); | |
8505 | sas_device_pg0.Slot = le16_to_cpu(sas_device_pg0.Slot); | |
aa53bb89 | 8506 | sas_device_pg0.Flags = le16_to_cpu(sas_device_pg0.Flags); |
e6d45e3e | 8507 | _scsih_mark_responding_sas_device(ioc, &sas_device_pg0); |
f92363d1 SR |
8508 | } |
8509 | ||
8510 | out: | |
8511 | pr_info(MPT3SAS_FMT "search for end-devices: complete\n", | |
8512 | ioc->name); | |
8513 | } | |
8514 | ||
ec051e5a SPS |
8515 | /** |
8516 | * _scsih_mark_responding_pcie_device - mark a pcie_device as responding | |
8517 | * @ioc: per adapter object | |
8518 | * @pcie_device_pg0: PCIe Device page 0 | |
8519 | * | |
8520 | * After host reset, find out whether devices are still responding. | |
8521 | * Used in _scsih_remove_unresponding_devices. | |
8522 | * | |
8523 | * Return nothing. | |
8524 | */ | |
8525 | static void | |
8526 | _scsih_mark_responding_pcie_device(struct MPT3SAS_ADAPTER *ioc, | |
8527 | Mpi26PCIeDevicePage0_t *pcie_device_pg0) | |
8528 | { | |
8529 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; | |
8530 | struct scsi_target *starget; | |
8531 | struct _pcie_device *pcie_device; | |
8532 | unsigned long flags; | |
8533 | ||
8534 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
8535 | list_for_each_entry(pcie_device, &ioc->pcie_device_list, list) { | |
8536 | if ((pcie_device->wwid == pcie_device_pg0->WWID) && | |
8537 | (pcie_device->slot == pcie_device_pg0->Slot)) { | |
8538 | pcie_device->responding = 1; | |
8539 | starget = pcie_device->starget; | |
8540 | if (starget && starget->hostdata) { | |
8541 | sas_target_priv_data = starget->hostdata; | |
8542 | sas_target_priv_data->tm_busy = 0; | |
8543 | sas_target_priv_data->deleted = 0; | |
8544 | } else | |
8545 | sas_target_priv_data = NULL; | |
8546 | if (starget) { | |
8547 | starget_printk(KERN_INFO, starget, | |
8548 | "handle(0x%04x), wwid(0x%016llx) ", | |
8549 | pcie_device->handle, | |
8550 | (unsigned long long)pcie_device->wwid); | |
8551 | if (pcie_device->enclosure_handle != 0) | |
8552 | starget_printk(KERN_INFO, starget, | |
8553 | "enclosure logical id(0x%016llx), " | |
8554 | "slot(%d)\n", | |
8555 | (unsigned long long) | |
8556 | pcie_device->enclosure_logical_id, | |
8557 | pcie_device->slot); | |
8558 | } | |
8559 | ||
8560 | if (((le32_to_cpu(pcie_device_pg0->Flags)) & | |
8561 | MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) && | |
8562 | (ioc->hba_mpi_version_belonged != MPI2_VERSION)) { | |
8563 | pcie_device->enclosure_level = | |
8564 | pcie_device_pg0->EnclosureLevel; | |
8565 | memcpy(&pcie_device->connector_name[0], | |
8566 | &pcie_device_pg0->ConnectorName[0], 4); | |
8567 | } else { | |
8568 | pcie_device->enclosure_level = 0; | |
8569 | pcie_device->connector_name[0] = '\0'; | |
8570 | } | |
8571 | ||
8572 | if (pcie_device->handle == pcie_device_pg0->DevHandle) | |
8573 | goto out; | |
268eb498 | 8574 | pr_info("\thandle changed from(0x%04x)!!!\n", |
ec051e5a SPS |
8575 | pcie_device->handle); |
8576 | pcie_device->handle = pcie_device_pg0->DevHandle; | |
8577 | if (sas_target_priv_data) | |
8578 | sas_target_priv_data->handle = | |
8579 | pcie_device_pg0->DevHandle; | |
8580 | goto out; | |
8581 | } | |
8582 | } | |
8583 | ||
8584 | out: | |
8585 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
8586 | } | |
8587 | ||
8588 | /** | |
8589 | * _scsih_search_responding_pcie_devices - | |
8590 | * @ioc: per adapter object | |
8591 | * | |
8592 | * After host reset, find out whether devices are still responding. | |
8593 | * If not remove. | |
8594 | * | |
8595 | * Return nothing. | |
8596 | */ | |
8597 | static void | |
8598 | _scsih_search_responding_pcie_devices(struct MPT3SAS_ADAPTER *ioc) | |
8599 | { | |
8600 | Mpi26PCIeDevicePage0_t pcie_device_pg0; | |
8601 | Mpi2ConfigReply_t mpi_reply; | |
8602 | u16 ioc_status; | |
8603 | u16 handle; | |
8604 | u32 device_info; | |
8605 | ||
8606 | pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name); | |
8607 | ||
8608 | if (list_empty(&ioc->pcie_device_list)) | |
8609 | goto out; | |
8610 | ||
8611 | handle = 0xFFFF; | |
8612 | while (!(mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply, | |
8613 | &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | |
8614 | handle))) { | |
8615 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8616 | MPI2_IOCSTATUS_MASK; | |
8617 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
8618 | pr_info(MPT3SAS_FMT "\tbreak from %s: " | |
8619 | "ioc_status(0x%04x), loginfo(0x%08x)\n", ioc->name, | |
8620 | __func__, ioc_status, | |
8621 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
8622 | break; | |
8623 | } | |
8624 | handle = le16_to_cpu(pcie_device_pg0.DevHandle); | |
8625 | device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo); | |
8626 | if (!(_scsih_is_nvme_device(device_info))) | |
8627 | continue; | |
8628 | pcie_device_pg0.WWID = le64_to_cpu(pcie_device_pg0.WWID), | |
8629 | pcie_device_pg0.Slot = le16_to_cpu(pcie_device_pg0.Slot); | |
8630 | pcie_device_pg0.Flags = le32_to_cpu(pcie_device_pg0.Flags); | |
8631 | pcie_device_pg0.DevHandle = handle; | |
8632 | _scsih_mark_responding_pcie_device(ioc, &pcie_device_pg0); | |
8633 | } | |
8634 | out: | |
8635 | pr_info(MPT3SAS_FMT "search for PCIe end-devices: complete\n", | |
8636 | ioc->name); | |
8637 | } | |
8638 | ||
f92363d1 SR |
8639 | /** |
8640 | * _scsih_mark_responding_raid_device - mark a raid_device as responding | |
8641 | * @ioc: per adapter object | |
8642 | * @wwid: world wide identifier for raid volume | |
8643 | * @handle: device handle | |
8644 | * | |
8645 | * After host reset, find out whether devices are still responding. | |
8646 | * Used in _scsih_remove_unresponsive_raid_devices. | |
8647 | * | |
8648 | * Return nothing. | |
8649 | */ | |
8650 | static void | |
8651 | _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid, | |
8652 | u16 handle) | |
8653 | { | |
7786ab6a | 8654 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; |
f92363d1 SR |
8655 | struct scsi_target *starget; |
8656 | struct _raid_device *raid_device; | |
8657 | unsigned long flags; | |
8658 | ||
8659 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
8660 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
8661 | if (raid_device->wwid == wwid && raid_device->starget) { | |
8662 | starget = raid_device->starget; | |
8663 | if (starget && starget->hostdata) { | |
8664 | sas_target_priv_data = starget->hostdata; | |
8665 | sas_target_priv_data->deleted = 0; | |
8666 | } else | |
8667 | sas_target_priv_data = NULL; | |
8668 | raid_device->responding = 1; | |
8669 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
8670 | starget_printk(KERN_INFO, raid_device->starget, | |
8671 | "handle(0x%04x), wwid(0x%016llx)\n", handle, | |
8672 | (unsigned long long)raid_device->wwid); | |
7786ab6a | 8673 | |
7786ab6a SR |
8674 | /* |
8675 | * WARPDRIVE: The handles of the PDs might have changed | |
8676 | * across the host reset so re-initialize the | |
8677 | * required data for Direct IO | |
8678 | */ | |
c84b06a4 | 8679 | mpt3sas_init_warpdrive_properties(ioc, raid_device); |
f92363d1 SR |
8680 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
8681 | if (raid_device->handle == handle) { | |
8682 | spin_unlock_irqrestore(&ioc->raid_device_lock, | |
8683 | flags); | |
8684 | return; | |
8685 | } | |
8686 | pr_info("\thandle changed from(0x%04x)!!!\n", | |
8687 | raid_device->handle); | |
8688 | raid_device->handle = handle; | |
8689 | if (sas_target_priv_data) | |
8690 | sas_target_priv_data->handle = handle; | |
8691 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
8692 | return; | |
8693 | } | |
8694 | } | |
8695 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
8696 | } | |
8697 | ||
8698 | /** | |
8699 | * _scsih_search_responding_raid_devices - | |
8700 | * @ioc: per adapter object | |
8701 | * | |
8702 | * After host reset, find out whether devices are still responding. | |
8703 | * If not remove. | |
8704 | * | |
8705 | * Return nothing. | |
8706 | */ | |
8707 | static void | |
8708 | _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc) | |
8709 | { | |
8710 | Mpi2RaidVolPage1_t volume_pg1; | |
8711 | Mpi2RaidVolPage0_t volume_pg0; | |
8712 | Mpi2RaidPhysDiskPage0_t pd_pg0; | |
8713 | Mpi2ConfigReply_t mpi_reply; | |
8714 | u16 ioc_status; | |
8715 | u16 handle; | |
8716 | u8 phys_disk_num; | |
8717 | ||
8718 | if (!ioc->ir_firmware) | |
8719 | return; | |
8720 | ||
8721 | pr_info(MPT3SAS_FMT "search for raid volumes: start\n", | |
8722 | ioc->name); | |
8723 | ||
8724 | if (list_empty(&ioc->raid_device_list)) | |
8725 | goto out; | |
8726 | ||
8727 | handle = 0xFFFF; | |
8728 | while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply, | |
8729 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { | |
8730 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8731 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 8732 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 SR |
8733 | break; |
8734 | handle = le16_to_cpu(volume_pg1.DevHandle); | |
8735 | ||
8736 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, | |
8737 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
8738 | sizeof(Mpi2RaidVolPage0_t))) | |
8739 | continue; | |
8740 | ||
8741 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || | |
8742 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || | |
8743 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) | |
8744 | _scsih_mark_responding_raid_device(ioc, | |
8745 | le64_to_cpu(volume_pg1.WWID), handle); | |
8746 | } | |
8747 | ||
8748 | /* refresh the pd_handles */ | |
7786ab6a | 8749 | if (!ioc->is_warpdrive) { |
f92363d1 SR |
8750 | phys_disk_num = 0xFF; |
8751 | memset(ioc->pd_handles, 0, ioc->pd_handles_sz); | |
8752 | while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | |
8753 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, | |
8754 | phys_disk_num))) { | |
8755 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8756 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 8757 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 SR |
8758 | break; |
8759 | phys_disk_num = pd_pg0.PhysDiskNum; | |
8760 | handle = le16_to_cpu(pd_pg0.DevHandle); | |
8761 | set_bit(handle, ioc->pd_handles); | |
8762 | } | |
7786ab6a | 8763 | } |
f92363d1 SR |
8764 | out: |
8765 | pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n", | |
8766 | ioc->name); | |
8767 | } | |
8768 | ||
8769 | /** | |
8770 | * _scsih_mark_responding_expander - mark a expander as responding | |
8771 | * @ioc: per adapter object | |
aba5a85c | 8772 | * @expander_pg0:SAS Expander Config Page0 |
f92363d1 SR |
8773 | * |
8774 | * After host reset, find out whether devices are still responding. | |
8775 | * Used in _scsih_remove_unresponsive_expanders. | |
8776 | * | |
8777 | * Return nothing. | |
8778 | */ | |
8779 | static void | |
aba5a85c SR |
8780 | _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc, |
8781 | Mpi2ExpanderPage0_t *expander_pg0) | |
f92363d1 | 8782 | { |
aba5a85c | 8783 | struct _sas_node *sas_expander = NULL; |
f92363d1 | 8784 | unsigned long flags; |
aba5a85c SR |
8785 | int i, encl_pg0_rc = -1; |
8786 | Mpi2ConfigReply_t mpi_reply; | |
8787 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
8788 | u16 handle = le16_to_cpu(expander_pg0->DevHandle); | |
8789 | u64 sas_address = le64_to_cpu(expander_pg0->SASAddress); | |
8790 | ||
8791 | if (le16_to_cpu(expander_pg0->EnclosureHandle)) { | |
8792 | encl_pg0_rc = mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
8793 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
8794 | le16_to_cpu(expander_pg0->EnclosureHandle)); | |
8795 | if (encl_pg0_rc) | |
8796 | pr_info(MPT3SAS_FMT | |
8797 | "Enclosure Pg0 read failed for handle(0x%04x)\n", | |
8798 | ioc->name, | |
8799 | le16_to_cpu(expander_pg0->EnclosureHandle)); | |
8800 | } | |
f92363d1 SR |
8801 | |
8802 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
8803 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { | |
8804 | if (sas_expander->sas_address != sas_address) | |
8805 | continue; | |
8806 | sas_expander->responding = 1; | |
aba5a85c SR |
8807 | |
8808 | if (!encl_pg0_rc) | |
8809 | sas_expander->enclosure_logical_id = | |
8810 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
8811 | ||
8812 | sas_expander->enclosure_handle = | |
8813 | le16_to_cpu(expander_pg0->EnclosureHandle); | |
8814 | ||
f92363d1 SR |
8815 | if (sas_expander->handle == handle) |
8816 | goto out; | |
8817 | pr_info("\texpander(0x%016llx): handle changed" \ | |
8818 | " from(0x%04x) to (0x%04x)!!!\n", | |
8819 | (unsigned long long)sas_expander->sas_address, | |
8820 | sas_expander->handle, handle); | |
8821 | sas_expander->handle = handle; | |
8822 | for (i = 0 ; i < sas_expander->num_phys ; i++) | |
8823 | sas_expander->phy[i].handle = handle; | |
8824 | goto out; | |
8825 | } | |
8826 | out: | |
8827 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
8828 | } | |
8829 | ||
8830 | /** | |
8831 | * _scsih_search_responding_expanders - | |
8832 | * @ioc: per adapter object | |
8833 | * | |
8834 | * After host reset, find out whether devices are still responding. | |
8835 | * If not remove. | |
8836 | * | |
8837 | * Return nothing. | |
8838 | */ | |
8839 | static void | |
8840 | _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc) | |
8841 | { | |
8842 | Mpi2ExpanderPage0_t expander_pg0; | |
8843 | Mpi2ConfigReply_t mpi_reply; | |
8844 | u16 ioc_status; | |
8845 | u64 sas_address; | |
8846 | u16 handle; | |
8847 | ||
8848 | pr_info(MPT3SAS_FMT "search for expanders: start\n", ioc->name); | |
8849 | ||
8850 | if (list_empty(&ioc->sas_expander_list)) | |
8851 | goto out; | |
8852 | ||
8853 | handle = 0xFFFF; | |
8854 | while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | |
8855 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { | |
8856 | ||
8857 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8858 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 8859 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 SR |
8860 | break; |
8861 | ||
8862 | handle = le16_to_cpu(expander_pg0.DevHandle); | |
8863 | sas_address = le64_to_cpu(expander_pg0.SASAddress); | |
8864 | pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n", | |
8865 | handle, | |
8866 | (unsigned long long)sas_address); | |
aba5a85c | 8867 | _scsih_mark_responding_expander(ioc, &expander_pg0); |
f92363d1 SR |
8868 | } |
8869 | ||
8870 | out: | |
8871 | pr_info(MPT3SAS_FMT "search for expanders: complete\n", ioc->name); | |
8872 | } | |
8873 | ||
8874 | /** | |
3075ac49 | 8875 | * _scsih_remove_unresponding_devices - removing unresponding devices |
f92363d1 SR |
8876 | * @ioc: per adapter object |
8877 | * | |
8878 | * Return nothing. | |
8879 | */ | |
8880 | static void | |
3075ac49 | 8881 | _scsih_remove_unresponding_devices(struct MPT3SAS_ADAPTER *ioc) |
f92363d1 SR |
8882 | { |
8883 | struct _sas_device *sas_device, *sas_device_next; | |
8884 | struct _sas_node *sas_expander, *sas_expander_next; | |
8885 | struct _raid_device *raid_device, *raid_device_next; | |
3075ac49 | 8886 | struct _pcie_device *pcie_device, *pcie_device_next; |
f92363d1 SR |
8887 | struct list_head tmp_list; |
8888 | unsigned long flags; | |
d1cb5e49 | 8889 | LIST_HEAD(head); |
f92363d1 SR |
8890 | |
8891 | pr_info(MPT3SAS_FMT "removing unresponding devices: start\n", | |
8892 | ioc->name); | |
8893 | ||
8894 | /* removing unresponding end devices */ | |
8895 | pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n", | |
8896 | ioc->name); | |
d1cb5e49 SR |
8897 | /* |
8898 | * Iterate, pulling off devices marked as non-responding. We become the | |
8899 | * owner for the reference the list had on any object we prune. | |
8900 | */ | |
8901 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
f92363d1 SR |
8902 | list_for_each_entry_safe(sas_device, sas_device_next, |
8903 | &ioc->sas_device_list, list) { | |
8904 | if (!sas_device->responding) | |
d1cb5e49 | 8905 | list_move_tail(&sas_device->list, &head); |
f92363d1 SR |
8906 | else |
8907 | sas_device->responding = 0; | |
8908 | } | |
d1cb5e49 SR |
8909 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
8910 | ||
8911 | /* | |
8912 | * Now, uninitialize and remove the unresponding devices we pruned. | |
8913 | */ | |
8914 | list_for_each_entry_safe(sas_device, sas_device_next, &head, list) { | |
8915 | _scsih_remove_device(ioc, sas_device); | |
8916 | list_del_init(&sas_device->list); | |
8917 | sas_device_put(sas_device); | |
8918 | } | |
f92363d1 | 8919 | |
3075ac49 SPS |
8920 | pr_info(MPT3SAS_FMT |
8921 | " Removing unresponding devices: pcie end-devices\n" | |
8922 | , ioc->name); | |
8923 | INIT_LIST_HEAD(&head); | |
8924 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
8925 | list_for_each_entry_safe(pcie_device, pcie_device_next, | |
8926 | &ioc->pcie_device_list, list) { | |
8927 | if (!pcie_device->responding) | |
8928 | list_move_tail(&pcie_device->list, &head); | |
8929 | else | |
8930 | pcie_device->responding = 0; | |
8931 | } | |
8932 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
8933 | ||
8934 | list_for_each_entry_safe(pcie_device, pcie_device_next, &head, list) { | |
8935 | _scsih_pcie_device_remove_from_sml(ioc, pcie_device); | |
8936 | list_del_init(&pcie_device->list); | |
8937 | pcie_device_put(pcie_device); | |
8938 | } | |
8939 | ||
f92363d1 SR |
8940 | /* removing unresponding volumes */ |
8941 | if (ioc->ir_firmware) { | |
8942 | pr_info(MPT3SAS_FMT "removing unresponding devices: volumes\n", | |
8943 | ioc->name); | |
8944 | list_for_each_entry_safe(raid_device, raid_device_next, | |
8945 | &ioc->raid_device_list, list) { | |
8946 | if (!raid_device->responding) | |
8947 | _scsih_sas_volume_delete(ioc, | |
8948 | raid_device->handle); | |
8949 | else | |
8950 | raid_device->responding = 0; | |
8951 | } | |
8952 | } | |
8953 | ||
8954 | /* removing unresponding expanders */ | |
8955 | pr_info(MPT3SAS_FMT "removing unresponding devices: expanders\n", | |
8956 | ioc->name); | |
8957 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
8958 | INIT_LIST_HEAD(&tmp_list); | |
8959 | list_for_each_entry_safe(sas_expander, sas_expander_next, | |
8960 | &ioc->sas_expander_list, list) { | |
8961 | if (!sas_expander->responding) | |
8962 | list_move_tail(&sas_expander->list, &tmp_list); | |
8963 | else | |
8964 | sas_expander->responding = 0; | |
8965 | } | |
8966 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
8967 | list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list, | |
8968 | list) { | |
f92363d1 SR |
8969 | _scsih_expander_node_remove(ioc, sas_expander); |
8970 | } | |
8971 | ||
8972 | pr_info(MPT3SAS_FMT "removing unresponding devices: complete\n", | |
8973 | ioc->name); | |
8974 | ||
8975 | /* unblock devices */ | |
8976 | _scsih_ublock_io_all_device(ioc); | |
8977 | } | |
8978 | ||
8979 | static void | |
8980 | _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc, | |
8981 | struct _sas_node *sas_expander, u16 handle) | |
8982 | { | |
8983 | Mpi2ExpanderPage1_t expander_pg1; | |
8984 | Mpi2ConfigReply_t mpi_reply; | |
8985 | int i; | |
8986 | ||
8987 | for (i = 0 ; i < sas_expander->num_phys ; i++) { | |
8988 | if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply, | |
8989 | &expander_pg1, i, handle))) { | |
8990 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
8991 | ioc->name, __FILE__, __LINE__, __func__); | |
8992 | return; | |
8993 | } | |
8994 | ||
8995 | mpt3sas_transport_update_links(ioc, sas_expander->sas_address, | |
8996 | le16_to_cpu(expander_pg1.AttachedDevHandle), i, | |
8997 | expander_pg1.NegotiatedLinkRate >> 4); | |
8998 | } | |
8999 | } | |
9000 | ||
9001 | /** | |
9002 | * _scsih_scan_for_devices_after_reset - scan for devices after host reset | |
9003 | * @ioc: per adapter object | |
9004 | * | |
9005 | * Return nothing. | |
9006 | */ | |
9007 | static void | |
9008 | _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc) | |
9009 | { | |
9010 | Mpi2ExpanderPage0_t expander_pg0; | |
9011 | Mpi2SasDevicePage0_t sas_device_pg0; | |
ec051e5a | 9012 | Mpi26PCIeDevicePage0_t pcie_device_pg0; |
f92363d1 SR |
9013 | Mpi2RaidVolPage1_t volume_pg1; |
9014 | Mpi2RaidVolPage0_t volume_pg0; | |
9015 | Mpi2RaidPhysDiskPage0_t pd_pg0; | |
9016 | Mpi2EventIrConfigElement_t element; | |
9017 | Mpi2ConfigReply_t mpi_reply; | |
9018 | u8 phys_disk_num; | |
9019 | u16 ioc_status; | |
9020 | u16 handle, parent_handle; | |
9021 | u64 sas_address; | |
9022 | struct _sas_device *sas_device; | |
ec051e5a | 9023 | struct _pcie_device *pcie_device; |
f92363d1 SR |
9024 | struct _sas_node *expander_device; |
9025 | static struct _raid_device *raid_device; | |
9026 | u8 retry_count; | |
9027 | unsigned long flags; | |
9028 | ||
9029 | pr_info(MPT3SAS_FMT "scan devices: start\n", ioc->name); | |
9030 | ||
9031 | _scsih_sas_host_refresh(ioc); | |
9032 | ||
9033 | pr_info(MPT3SAS_FMT "\tscan devices: expanders start\n", ioc->name); | |
9034 | ||
9035 | /* expanders */ | |
9036 | handle = 0xFFFF; | |
9037 | while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | |
9038 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { | |
9039 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9040 | MPI2_IOCSTATUS_MASK; | |
f92363d1 SR |
9041 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
9042 | pr_info(MPT3SAS_FMT "\tbreak from expander scan: " \ | |
9043 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9044 | ioc->name, ioc_status, | |
9045 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
9046 | break; | |
9047 | } | |
9048 | handle = le16_to_cpu(expander_pg0.DevHandle); | |
9049 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
9050 | expander_device = mpt3sas_scsih_expander_find_by_sas_address( | |
9051 | ioc, le64_to_cpu(expander_pg0.SASAddress)); | |
9052 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
9053 | if (expander_device) | |
9054 | _scsih_refresh_expander_links(ioc, expander_device, | |
9055 | handle); | |
9056 | else { | |
9057 | pr_info(MPT3SAS_FMT "\tBEFORE adding expander: " \ | |
9058 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
9059 | handle, (unsigned long long) | |
9060 | le64_to_cpu(expander_pg0.SASAddress)); | |
9061 | _scsih_expander_add(ioc, handle); | |
9062 | pr_info(MPT3SAS_FMT "\tAFTER adding expander: " \ | |
9063 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
9064 | handle, (unsigned long long) | |
9065 | le64_to_cpu(expander_pg0.SASAddress)); | |
9066 | } | |
9067 | } | |
9068 | ||
9069 | pr_info(MPT3SAS_FMT "\tscan devices: expanders complete\n", | |
9070 | ioc->name); | |
9071 | ||
9072 | if (!ioc->ir_firmware) | |
9073 | goto skip_to_sas; | |
9074 | ||
9075 | pr_info(MPT3SAS_FMT "\tscan devices: phys disk start\n", ioc->name); | |
9076 | ||
9077 | /* phys disk */ | |
9078 | phys_disk_num = 0xFF; | |
9079 | while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | |
9080 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, | |
9081 | phys_disk_num))) { | |
9082 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9083 | MPI2_IOCSTATUS_MASK; | |
f92363d1 SR |
9084 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
9085 | pr_info(MPT3SAS_FMT "\tbreak from phys disk scan: "\ | |
9086 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9087 | ioc->name, ioc_status, | |
9088 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
9089 | break; | |
9090 | } | |
9091 | phys_disk_num = pd_pg0.PhysDiskNum; | |
9092 | handle = le16_to_cpu(pd_pg0.DevHandle); | |
d1cb5e49 SR |
9093 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
9094 | if (sas_device) { | |
9095 | sas_device_put(sas_device); | |
f92363d1 | 9096 | continue; |
d1cb5e49 | 9097 | } |
f92363d1 SR |
9098 | if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
9099 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | |
9100 | handle) != 0) | |
9101 | continue; | |
9102 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9103 | MPI2_IOCSTATUS_MASK; | |
9104 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
9105 | pr_info(MPT3SAS_FMT "\tbreak from phys disk scan " \ | |
9106 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9107 | ioc->name, ioc_status, | |
9108 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
9109 | break; | |
9110 | } | |
9111 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | |
9112 | if (!_scsih_get_sas_address(ioc, parent_handle, | |
9113 | &sas_address)) { | |
9114 | pr_info(MPT3SAS_FMT "\tBEFORE adding phys disk: " \ | |
9115 | " handle (0x%04x), sas_addr(0x%016llx)\n", | |
9116 | ioc->name, handle, (unsigned long long) | |
9117 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
9118 | mpt3sas_transport_update_links(ioc, sas_address, | |
9119 | handle, sas_device_pg0.PhyNum, | |
9120 | MPI2_SAS_NEG_LINK_RATE_1_5); | |
9121 | set_bit(handle, ioc->pd_handles); | |
9122 | retry_count = 0; | |
9123 | /* This will retry adding the end device. | |
9124 | * _scsih_add_device() will decide on retries and | |
9125 | * return "1" when it should be retried | |
9126 | */ | |
9127 | while (_scsih_add_device(ioc, handle, retry_count++, | |
9128 | 1)) { | |
9129 | ssleep(1); | |
9130 | } | |
9131 | pr_info(MPT3SAS_FMT "\tAFTER adding phys disk: " \ | |
9132 | " handle (0x%04x), sas_addr(0x%016llx)\n", | |
9133 | ioc->name, handle, (unsigned long long) | |
9134 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
9135 | } | |
9136 | } | |
9137 | ||
9138 | pr_info(MPT3SAS_FMT "\tscan devices: phys disk complete\n", | |
9139 | ioc->name); | |
9140 | ||
9141 | pr_info(MPT3SAS_FMT "\tscan devices: volumes start\n", ioc->name); | |
9142 | ||
9143 | /* volumes */ | |
9144 | handle = 0xFFFF; | |
9145 | while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply, | |
9146 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { | |
9147 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9148 | MPI2_IOCSTATUS_MASK; | |
f92363d1 SR |
9149 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
9150 | pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \ | |
9151 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9152 | ioc->name, ioc_status, | |
9153 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
9154 | break; | |
9155 | } | |
9156 | handle = le16_to_cpu(volume_pg1.DevHandle); | |
9157 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
9158 | raid_device = _scsih_raid_device_find_by_wwid(ioc, | |
9159 | le64_to_cpu(volume_pg1.WWID)); | |
9160 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
9161 | if (raid_device) | |
9162 | continue; | |
9163 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, | |
9164 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
9165 | sizeof(Mpi2RaidVolPage0_t))) | |
9166 | continue; | |
9167 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9168 | MPI2_IOCSTATUS_MASK; | |
9169 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
9170 | pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \ | |
9171 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9172 | ioc->name, ioc_status, | |
9173 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
9174 | break; | |
9175 | } | |
9176 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || | |
9177 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || | |
9178 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) { | |
9179 | memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t)); | |
9180 | element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED; | |
9181 | element.VolDevHandle = volume_pg1.DevHandle; | |
9182 | pr_info(MPT3SAS_FMT | |
9183 | "\tBEFORE adding volume: handle (0x%04x)\n", | |
9184 | ioc->name, volume_pg1.DevHandle); | |
9185 | _scsih_sas_volume_add(ioc, &element); | |
9186 | pr_info(MPT3SAS_FMT | |
9187 | "\tAFTER adding volume: handle (0x%04x)\n", | |
9188 | ioc->name, volume_pg1.DevHandle); | |
9189 | } | |
9190 | } | |
9191 | ||
9192 | pr_info(MPT3SAS_FMT "\tscan devices: volumes complete\n", | |
9193 | ioc->name); | |
9194 | ||
9195 | skip_to_sas: | |
9196 | ||
9197 | pr_info(MPT3SAS_FMT "\tscan devices: end devices start\n", | |
9198 | ioc->name); | |
9199 | ||
9200 | /* sas devices */ | |
9201 | handle = 0xFFFF; | |
9202 | while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
9203 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | |
9204 | handle))) { | |
9205 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9206 | MPI2_IOCSTATUS_MASK; | |
f92363d1 SR |
9207 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
9208 | pr_info(MPT3SAS_FMT "\tbreak from end device scan:"\ | |
9209 | " ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9210 | ioc->name, ioc_status, | |
9211 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
9212 | break; | |
9213 | } | |
9214 | handle = le16_to_cpu(sas_device_pg0.DevHandle); | |
9215 | if (!(_scsih_is_end_device( | |
9216 | le32_to_cpu(sas_device_pg0.DeviceInfo)))) | |
9217 | continue; | |
d1cb5e49 | 9218 | sas_device = mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 | 9219 | le64_to_cpu(sas_device_pg0.SASAddress)); |
d1cb5e49 SR |
9220 | if (sas_device) { |
9221 | sas_device_put(sas_device); | |
f92363d1 | 9222 | continue; |
d1cb5e49 | 9223 | } |
f92363d1 SR |
9224 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
9225 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) { | |
9226 | pr_info(MPT3SAS_FMT "\tBEFORE adding end device: " \ | |
9227 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
9228 | handle, (unsigned long long) | |
9229 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
9230 | mpt3sas_transport_update_links(ioc, sas_address, handle, | |
9231 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | |
9232 | retry_count = 0; | |
9233 | /* This will retry adding the end device. | |
9234 | * _scsih_add_device() will decide on retries and | |
9235 | * return "1" when it should be retried | |
9236 | */ | |
9237 | while (_scsih_add_device(ioc, handle, retry_count++, | |
9238 | 0)) { | |
9239 | ssleep(1); | |
9240 | } | |
9241 | pr_info(MPT3SAS_FMT "\tAFTER adding end device: " \ | |
9242 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
9243 | handle, (unsigned long long) | |
9244 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
9245 | } | |
9246 | } | |
9247 | pr_info(MPT3SAS_FMT "\tscan devices: end devices complete\n", | |
9248 | ioc->name); | |
ec051e5a SPS |
9249 | pr_info(MPT3SAS_FMT "\tscan devices: pcie end devices start\n", |
9250 | ioc->name); | |
9251 | ||
9252 | /* pcie devices */ | |
9253 | handle = 0xFFFF; | |
9254 | while (!(mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply, | |
9255 | &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | |
9256 | handle))) { | |
9257 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) | |
9258 | & MPI2_IOCSTATUS_MASK; | |
9259 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
9260 | pr_info(MPT3SAS_FMT "\tbreak from pcie end device" | |
9261 | " scan: ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9262 | ioc->name, ioc_status, | |
9263 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
9264 | break; | |
9265 | } | |
9266 | handle = le16_to_cpu(pcie_device_pg0.DevHandle); | |
9267 | if (!(_scsih_is_nvme_device( | |
9268 | le32_to_cpu(pcie_device_pg0.DeviceInfo)))) | |
9269 | continue; | |
9270 | pcie_device = mpt3sas_get_pdev_by_wwid(ioc, | |
9271 | le64_to_cpu(pcie_device_pg0.WWID)); | |
9272 | if (pcie_device) { | |
9273 | pcie_device_put(pcie_device); | |
9274 | continue; | |
9275 | } | |
9276 | retry_count = 0; | |
9277 | parent_handle = le16_to_cpu(pcie_device_pg0.ParentDevHandle); | |
9278 | _scsih_pcie_add_device(ioc, handle); | |
f92363d1 | 9279 | |
ec051e5a SPS |
9280 | pr_info(MPT3SAS_FMT "\tAFTER adding pcie end device: " |
9281 | "handle (0x%04x), wwid(0x%016llx)\n", ioc->name, | |
9282 | handle, | |
9283 | (unsigned long long) le64_to_cpu(pcie_device_pg0.WWID)); | |
9284 | } | |
9285 | pr_info(MPT3SAS_FMT "\tpcie devices: pcie end devices complete\n", | |
9286 | ioc->name); | |
f92363d1 SR |
9287 | pr_info(MPT3SAS_FMT "scan devices: complete\n", ioc->name); |
9288 | } | |
9289 | /** | |
9290 | * mpt3sas_scsih_reset_handler - reset callback handler (for scsih) | |
9291 | * @ioc: per adapter object | |
9292 | * @reset_phase: phase | |
9293 | * | |
9294 | * The handler for doing any required cleanup or initialization. | |
9295 | * | |
9296 | * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET, | |
9297 | * MPT3_IOC_DONE_RESET | |
9298 | * | |
9299 | * Return nothing. | |
9300 | */ | |
9301 | void | |
9302 | mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase) | |
9303 | { | |
9304 | switch (reset_phase) { | |
9305 | case MPT3_IOC_PRE_RESET: | |
9306 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
9307 | "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__)); | |
9308 | break; | |
9309 | case MPT3_IOC_AFTER_RESET: | |
9310 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
9311 | "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__)); | |
9312 | if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) { | |
9313 | ioc->scsih_cmds.status |= MPT3_CMD_RESET; | |
9314 | mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid); | |
9315 | complete(&ioc->scsih_cmds.done); | |
9316 | } | |
9317 | if (ioc->tm_cmds.status & MPT3_CMD_PENDING) { | |
9318 | ioc->tm_cmds.status |= MPT3_CMD_RESET; | |
9319 | mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid); | |
9320 | complete(&ioc->tm_cmds.done); | |
9321 | } | |
9322 | ||
c696f7b8 SPS |
9323 | memset(ioc->pend_os_device_add, 0, ioc->pend_os_device_add_sz); |
9324 | memset(ioc->device_remove_in_progress, 0, | |
9325 | ioc->device_remove_in_progress_sz); | |
f92363d1 SR |
9326 | _scsih_fw_event_cleanup_queue(ioc); |
9327 | _scsih_flush_running_cmds(ioc); | |
9328 | break; | |
9329 | case MPT3_IOC_DONE_RESET: | |
9330 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
9331 | "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__)); | |
9332 | if ((!ioc->is_driver_loading) && !(disable_discovery > 0 && | |
9333 | !ioc->sas_hba.num_phys)) { | |
9334 | _scsih_prep_device_scan(ioc); | |
9335 | _scsih_search_responding_sas_devices(ioc); | |
ec051e5a | 9336 | _scsih_search_responding_pcie_devices(ioc); |
f92363d1 SR |
9337 | _scsih_search_responding_raid_devices(ioc); |
9338 | _scsih_search_responding_expanders(ioc); | |
9339 | _scsih_error_recovery_delete_devices(ioc); | |
9340 | } | |
9341 | break; | |
9342 | } | |
9343 | } | |
9344 | ||
9345 | /** | |
9346 | * _mpt3sas_fw_work - delayed task for processing firmware events | |
9347 | * @ioc: per adapter object | |
9348 | * @fw_event: The fw_event_work object | |
9349 | * Context: user. | |
9350 | * | |
9351 | * Return nothing. | |
9352 | */ | |
9353 | static void | |
9354 | _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event) | |
9355 | { | |
146b16c8 SR |
9356 | _scsih_fw_event_del_from_list(ioc, fw_event); |
9357 | ||
f92363d1 | 9358 | /* the queue is being flushed so ignore this event */ |
146b16c8 SR |
9359 | if (ioc->remove_host || ioc->pci_error_recovery) { |
9360 | fw_event_work_put(fw_event); | |
f92363d1 SR |
9361 | return; |
9362 | } | |
9363 | ||
9364 | switch (fw_event->event) { | |
9365 | case MPT3SAS_PROCESS_TRIGGER_DIAG: | |
35b62362 JL |
9366 | mpt3sas_process_trigger_data(ioc, |
9367 | (struct SL_WH_TRIGGERS_EVENT_DATA_T *) | |
9368 | fw_event->event_data); | |
f92363d1 SR |
9369 | break; |
9370 | case MPT3SAS_REMOVE_UNRESPONDING_DEVICES: | |
146b16c8 SR |
9371 | while (scsi_host_in_recovery(ioc->shost) || |
9372 | ioc->shost_recovery) { | |
9373 | /* | |
9374 | * If we're unloading, bail. Otherwise, this can become | |
9375 | * an infinite loop. | |
9376 | */ | |
9377 | if (ioc->remove_host) | |
9378 | goto out; | |
f92363d1 | 9379 | ssleep(1); |
146b16c8 | 9380 | } |
3075ac49 | 9381 | _scsih_remove_unresponding_devices(ioc); |
f92363d1 SR |
9382 | _scsih_scan_for_devices_after_reset(ioc); |
9383 | break; | |
9384 | case MPT3SAS_PORT_ENABLE_COMPLETE: | |
9385 | ioc->start_scan = 0; | |
9386 | if (missing_delay[0] != -1 && missing_delay[1] != -1) | |
9387 | mpt3sas_base_update_missing_delay(ioc, missing_delay[0], | |
9388 | missing_delay[1]); | |
9389 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
9390 | "port enable: complete from worker thread\n", | |
9391 | ioc->name)); | |
9392 | break; | |
0f624c39 SR |
9393 | case MPT3SAS_TURN_ON_PFA_LED: |
9394 | _scsih_turn_on_pfa_led(ioc, fw_event->device_handle); | |
f92363d1 SR |
9395 | break; |
9396 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: | |
9397 | _scsih_sas_topology_change_event(ioc, fw_event); | |
9398 | break; | |
9399 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: | |
9400 | _scsih_sas_device_status_change_event(ioc, fw_event); | |
9401 | break; | |
9402 | case MPI2_EVENT_SAS_DISCOVERY: | |
9403 | _scsih_sas_discovery_event(ioc, fw_event); | |
9404 | break; | |
9405 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: | |
9406 | _scsih_sas_broadcast_primitive_event(ioc, fw_event); | |
9407 | break; | |
9408 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: | |
9409 | _scsih_sas_enclosure_dev_status_change_event(ioc, | |
9410 | fw_event); | |
9411 | break; | |
9412 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: | |
9413 | _scsih_sas_ir_config_change_event(ioc, fw_event); | |
9414 | break; | |
9415 | case MPI2_EVENT_IR_VOLUME: | |
9416 | _scsih_sas_ir_volume_event(ioc, fw_event); | |
9417 | break; | |
9418 | case MPI2_EVENT_IR_PHYSICAL_DISK: | |
9419 | _scsih_sas_ir_physical_disk_event(ioc, fw_event); | |
9420 | break; | |
9421 | case MPI2_EVENT_IR_OPERATION_STATUS: | |
9422 | _scsih_sas_ir_operation_status_event(ioc, fw_event); | |
9423 | break; | |
4318c734 SPS |
9424 | case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE: |
9425 | _scsih_pcie_device_status_change_event(ioc, fw_event); | |
9426 | break; | |
9427 | case MPI2_EVENT_PCIE_ENUMERATION: | |
9428 | _scsih_pcie_enumeration_event(ioc, fw_event); | |
9429 | break; | |
9430 | case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST: | |
9431 | _scsih_pcie_topology_change_event(ioc, fw_event); | |
9432 | return; | |
9433 | break; | |
f92363d1 | 9434 | } |
146b16c8 SR |
9435 | out: |
9436 | fw_event_work_put(fw_event); | |
f92363d1 SR |
9437 | } |
9438 | ||
9439 | /** | |
9440 | * _firmware_event_work | |
9441 | * @ioc: per adapter object | |
9442 | * @work: The fw_event_work object | |
9443 | * Context: user. | |
9444 | * | |
9445 | * wrappers for the work thread handling firmware events | |
9446 | * | |
9447 | * Return nothing. | |
9448 | */ | |
9449 | ||
9450 | static void | |
9451 | _firmware_event_work(struct work_struct *work) | |
9452 | { | |
9453 | struct fw_event_work *fw_event = container_of(work, | |
9454 | struct fw_event_work, work); | |
9455 | ||
9456 | _mpt3sas_fw_work(fw_event->ioc, fw_event); | |
9457 | } | |
9458 | ||
9459 | /** | |
9460 | * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time) | |
9461 | * @ioc: per adapter object | |
9462 | * @msix_index: MSIX table index supplied by the OS | |
9463 | * @reply: reply message frame(lower 32bit addr) | |
9464 | * Context: interrupt. | |
9465 | * | |
9466 | * This function merely adds a new work task into ioc->firmware_event_thread. | |
9467 | * The tasks are worked from _firmware_event_work in user context. | |
9468 | * | |
9469 | * Return 1 meaning mf should be freed from _base_interrupt | |
9470 | * 0 means the mf is freed from this function. | |
9471 | */ | |
9472 | u8 | |
9473 | mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index, | |
9474 | u32 reply) | |
9475 | { | |
9476 | struct fw_event_work *fw_event; | |
9477 | Mpi2EventNotificationReply_t *mpi_reply; | |
9478 | u16 event; | |
9479 | u16 sz; | |
a470a51c | 9480 | Mpi26EventDataActiveCableExcept_t *ActiveCableEventData; |
f92363d1 SR |
9481 | |
9482 | /* events turned off due to host reset or driver unloading */ | |
9483 | if (ioc->remove_host || ioc->pci_error_recovery) | |
9484 | return 1; | |
9485 | ||
9486 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
9487 | ||
9488 | if (unlikely(!mpi_reply)) { | |
9489 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", | |
9490 | ioc->name, __FILE__, __LINE__, __func__); | |
9491 | return 1; | |
9492 | } | |
9493 | ||
9494 | event = le16_to_cpu(mpi_reply->Event); | |
9495 | ||
9496 | if (event != MPI2_EVENT_LOG_ENTRY_ADDED) | |
9497 | mpt3sas_trigger_event(ioc, event, 0); | |
9498 | ||
9499 | switch (event) { | |
9500 | /* handle these */ | |
9501 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: | |
9502 | { | |
9503 | Mpi2EventDataSasBroadcastPrimitive_t *baen_data = | |
9504 | (Mpi2EventDataSasBroadcastPrimitive_t *) | |
9505 | mpi_reply->EventData; | |
9506 | ||
9507 | if (baen_data->Primitive != | |
9508 | MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT) | |
9509 | return 1; | |
9510 | ||
9511 | if (ioc->broadcast_aen_busy) { | |
9512 | ioc->broadcast_aen_pending++; | |
9513 | return 1; | |
9514 | } else | |
9515 | ioc->broadcast_aen_busy = 1; | |
9516 | break; | |
9517 | } | |
9518 | ||
9519 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: | |
9520 | _scsih_check_topo_delete_events(ioc, | |
9521 | (Mpi2EventDataSasTopologyChangeList_t *) | |
9522 | mpi_reply->EventData); | |
9523 | break; | |
4318c734 SPS |
9524 | case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST: |
9525 | _scsih_check_pcie_topo_remove_events(ioc, | |
9526 | (Mpi26EventDataPCIeTopologyChangeList_t *) | |
9527 | mpi_reply->EventData); | |
9528 | break; | |
f92363d1 SR |
9529 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: |
9530 | _scsih_check_ir_config_unhide_events(ioc, | |
9531 | (Mpi2EventDataIrConfigChangeList_t *) | |
9532 | mpi_reply->EventData); | |
9533 | break; | |
9534 | case MPI2_EVENT_IR_VOLUME: | |
9535 | _scsih_check_volume_delete_events(ioc, | |
9536 | (Mpi2EventDataIrVolume_t *) | |
9537 | mpi_reply->EventData); | |
9538 | break; | |
7786ab6a SR |
9539 | case MPI2_EVENT_LOG_ENTRY_ADDED: |
9540 | { | |
9541 | Mpi2EventDataLogEntryAdded_t *log_entry; | |
9542 | u32 *log_code; | |
9543 | ||
9544 | if (!ioc->is_warpdrive) | |
9545 | break; | |
9546 | ||
9547 | log_entry = (Mpi2EventDataLogEntryAdded_t *) | |
9548 | mpi_reply->EventData; | |
9549 | log_code = (u32 *)log_entry->LogData; | |
f92363d1 | 9550 | |
7786ab6a SR |
9551 | if (le16_to_cpu(log_entry->LogEntryQualifier) |
9552 | != MPT2_WARPDRIVE_LOGENTRY) | |
9553 | break; | |
9554 | ||
9555 | switch (le32_to_cpu(*log_code)) { | |
9556 | case MPT2_WARPDRIVE_LC_SSDT: | |
9557 | pr_warn(MPT3SAS_FMT "WarpDrive Warning: " | |
9558 | "IO Throttling has occurred in the WarpDrive " | |
9559 | "subsystem. Check WarpDrive documentation for " | |
9560 | "additional details.\n", ioc->name); | |
9561 | break; | |
9562 | case MPT2_WARPDRIVE_LC_SSDLW: | |
9563 | pr_warn(MPT3SAS_FMT "WarpDrive Warning: " | |
9564 | "Program/Erase Cycles for the WarpDrive subsystem " | |
9565 | "in degraded range. Check WarpDrive documentation " | |
9566 | "for additional details.\n", ioc->name); | |
9567 | break; | |
9568 | case MPT2_WARPDRIVE_LC_SSDLF: | |
9569 | pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: " | |
9570 | "There are no Program/Erase Cycles for the " | |
9571 | "WarpDrive subsystem. The storage device will be " | |
9572 | "in read-only mode. Check WarpDrive documentation " | |
9573 | "for additional details.\n", ioc->name); | |
9574 | break; | |
9575 | case MPT2_WARPDRIVE_LC_BRMF: | |
9576 | pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: " | |
9577 | "The Backup Rail Monitor has failed on the " | |
9578 | "WarpDrive subsystem. Check WarpDrive " | |
9579 | "documentation for additional details.\n", | |
9580 | ioc->name); | |
9581 | break; | |
9582 | } | |
9583 | ||
9584 | break; | |
9585 | } | |
f92363d1 SR |
9586 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: |
9587 | case MPI2_EVENT_IR_OPERATION_STATUS: | |
9588 | case MPI2_EVENT_SAS_DISCOVERY: | |
9589 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: | |
9590 | case MPI2_EVENT_IR_PHYSICAL_DISK: | |
4318c734 SPS |
9591 | case MPI2_EVENT_PCIE_ENUMERATION: |
9592 | case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE: | |
f92363d1 SR |
9593 | break; |
9594 | ||
2d8ce8c9 SR |
9595 | case MPI2_EVENT_TEMP_THRESHOLD: |
9596 | _scsih_temp_threshold_events(ioc, | |
9597 | (Mpi2EventDataTemperature_t *) | |
9598 | mpi_reply->EventData); | |
9599 | break; | |
a470a51c C |
9600 | case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION: |
9601 | ActiveCableEventData = | |
9602 | (Mpi26EventDataActiveCableExcept_t *) mpi_reply->EventData; | |
6c44c0fe C |
9603 | switch (ActiveCableEventData->ReasonCode) { |
9604 | case MPI26_EVENT_ACTIVE_CABLE_INSUFFICIENT_POWER: | |
b99b1993 SR |
9605 | pr_notice(MPT3SAS_FMT |
9606 | "Currently an active cable with ReceptacleID %d\n", | |
9607 | ioc->name, ActiveCableEventData->ReceptacleID); | |
9608 | pr_notice("cannot be powered and devices connected\n"); | |
9609 | pr_notice("to this active cable will not be seen\n"); | |
9610 | pr_notice("This active cable requires %d mW of power\n", | |
6c44c0fe | 9611 | ActiveCableEventData->ActiveCablePowerRequirement); |
6c44c0fe C |
9612 | break; |
9613 | ||
9614 | case MPI26_EVENT_ACTIVE_CABLE_DEGRADED: | |
b99b1993 SR |
9615 | pr_notice(MPT3SAS_FMT |
9616 | "Currently a cable with ReceptacleID %d\n", | |
9617 | ioc->name, ActiveCableEventData->ReceptacleID); | |
9618 | pr_notice( | |
9619 | "is not running at optimal speed(12 Gb/s rate)\n"); | |
6c44c0fe | 9620 | break; |
7ebd67e0 | 9621 | } |
6c44c0fe | 9622 | |
a470a51c | 9623 | break; |
2d8ce8c9 | 9624 | |
f92363d1 SR |
9625 | default: /* ignore the rest */ |
9626 | return 1; | |
9627 | } | |
9628 | ||
f92363d1 | 9629 | sz = le16_to_cpu(mpi_reply->EventDataLength) * 4; |
146b16c8 | 9630 | fw_event = alloc_fw_event_work(sz); |
35b62362 | 9631 | if (!fw_event) { |
f92363d1 SR |
9632 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
9633 | ioc->name, __FILE__, __LINE__, __func__); | |
f92363d1 SR |
9634 | return 1; |
9635 | } | |
9636 | ||
9637 | memcpy(fw_event->event_data, mpi_reply->EventData, sz); | |
9638 | fw_event->ioc = ioc; | |
9639 | fw_event->VF_ID = mpi_reply->VF_ID; | |
9640 | fw_event->VP_ID = mpi_reply->VP_ID; | |
9641 | fw_event->event = event; | |
9642 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 | 9643 | fw_event_work_put(fw_event); |
f92363d1 SR |
9644 | return 1; |
9645 | } | |
9646 | ||
f92363d1 SR |
9647 | /** |
9648 | * _scsih_expander_node_remove - removing expander device from list. | |
9649 | * @ioc: per adapter object | |
9650 | * @sas_expander: the sas_device object | |
f92363d1 SR |
9651 | * |
9652 | * Removing object and freeing associated memory from the | |
9653 | * ioc->sas_expander_list. | |
9654 | * | |
9655 | * Return nothing. | |
9656 | */ | |
9657 | static void | |
9658 | _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc, | |
9659 | struct _sas_node *sas_expander) | |
9660 | { | |
9661 | struct _sas_port *mpt3sas_port, *next; | |
bbe3def3 | 9662 | unsigned long flags; |
f92363d1 SR |
9663 | |
9664 | /* remove sibling ports attached to this expander */ | |
9665 | list_for_each_entry_safe(mpt3sas_port, next, | |
9666 | &sas_expander->sas_port_list, port_list) { | |
9667 | if (ioc->shost_recovery) | |
9668 | return; | |
9669 | if (mpt3sas_port->remote_identify.device_type == | |
9670 | SAS_END_DEVICE) | |
9671 | mpt3sas_device_remove_by_sas_address(ioc, | |
9672 | mpt3sas_port->remote_identify.sas_address); | |
9673 | else if (mpt3sas_port->remote_identify.device_type == | |
9674 | SAS_EDGE_EXPANDER_DEVICE || | |
9675 | mpt3sas_port->remote_identify.device_type == | |
9676 | SAS_FANOUT_EXPANDER_DEVICE) | |
9677 | mpt3sas_expander_remove(ioc, | |
9678 | mpt3sas_port->remote_identify.sas_address); | |
9679 | } | |
9680 | ||
9681 | mpt3sas_transport_port_remove(ioc, sas_expander->sas_address, | |
9682 | sas_expander->sas_address_parent); | |
9683 | ||
9684 | pr_info(MPT3SAS_FMT | |
9685 | "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n", | |
9686 | ioc->name, | |
9687 | sas_expander->handle, (unsigned long long) | |
9688 | sas_expander->sas_address); | |
9689 | ||
bbe3def3 SR |
9690 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
9691 | list_del(&sas_expander->list); | |
9692 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
9693 | ||
f92363d1 SR |
9694 | kfree(sas_expander->phy); |
9695 | kfree(sas_expander); | |
9696 | } | |
9697 | ||
9698 | /** | |
9699 | * _scsih_ir_shutdown - IR shutdown notification | |
9700 | * @ioc: per adapter object | |
9701 | * | |
9702 | * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that | |
9703 | * the host system is shutting down. | |
9704 | * | |
9705 | * Return nothing. | |
9706 | */ | |
9707 | static void | |
9708 | _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc) | |
9709 | { | |
9710 | Mpi2RaidActionRequest_t *mpi_request; | |
9711 | Mpi2RaidActionReply_t *mpi_reply; | |
9712 | u16 smid; | |
9713 | ||
9714 | /* is IR firmware build loaded ? */ | |
9715 | if (!ioc->ir_firmware) | |
9716 | return; | |
9717 | ||
9718 | /* are there any volumes ? */ | |
9719 | if (list_empty(&ioc->raid_device_list)) | |
9720 | return; | |
9721 | ||
9722 | mutex_lock(&ioc->scsih_cmds.mutex); | |
9723 | ||
9724 | if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) { | |
9725 | pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n", | |
9726 | ioc->name, __func__); | |
9727 | goto out; | |
9728 | } | |
9729 | ioc->scsih_cmds.status = MPT3_CMD_PENDING; | |
9730 | ||
9731 | smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx); | |
9732 | if (!smid) { | |
9733 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
9734 | ioc->name, __func__); | |
9735 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
9736 | goto out; | |
9737 | } | |
9738 | ||
9739 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
9740 | ioc->scsih_cmds.smid = smid; | |
9741 | memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t)); | |
9742 | ||
9743 | mpi_request->Function = MPI2_FUNCTION_RAID_ACTION; | |
9744 | mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED; | |
9745 | ||
7786ab6a SR |
9746 | if (!ioc->hide_ir_msg) |
9747 | pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name); | |
f92363d1 | 9748 | init_completion(&ioc->scsih_cmds.done); |
81c16f83 | 9749 | ioc->put_smid_default(ioc, smid); |
f92363d1 SR |
9750 | wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ); |
9751 | ||
9752 | if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) { | |
9753 | pr_err(MPT3SAS_FMT "%s: timeout\n", | |
9754 | ioc->name, __func__); | |
9755 | goto out; | |
9756 | } | |
9757 | ||
9758 | if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) { | |
9759 | mpi_reply = ioc->scsih_cmds.reply; | |
7786ab6a SR |
9760 | if (!ioc->hide_ir_msg) |
9761 | pr_info(MPT3SAS_FMT "IR shutdown " | |
9762 | "(complete): ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9763 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), | |
9764 | le32_to_cpu(mpi_reply->IOCLogInfo)); | |
f92363d1 SR |
9765 | } |
9766 | ||
9767 | out: | |
9768 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
9769 | mutex_unlock(&ioc->scsih_cmds.mutex); | |
9770 | } | |
9771 | ||
9772 | /** | |
8a7e4c24 | 9773 | * scsih_remove - detach and remove add host |
f92363d1 SR |
9774 | * @pdev: PCI device struct |
9775 | * | |
9776 | * Routine called when unloading the driver. | |
9777 | * Return nothing. | |
9778 | */ | |
8bbb1cf6 | 9779 | static void scsih_remove(struct pci_dev *pdev) |
f92363d1 SR |
9780 | { |
9781 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9782 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
9783 | struct _sas_port *mpt3sas_port, *next_port; | |
9784 | struct _raid_device *raid_device, *next; | |
9785 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
3075ac49 | 9786 | struct _pcie_device *pcie_device, *pcienext; |
f92363d1 SR |
9787 | struct workqueue_struct *wq; |
9788 | unsigned long flags; | |
9789 | ||
9790 | ioc->remove_host = 1; | |
9791 | _scsih_fw_event_cleanup_queue(ioc); | |
9792 | ||
9793 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
9794 | wq = ioc->firmware_event_thread; | |
9795 | ioc->firmware_event_thread = NULL; | |
9796 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
9797 | if (wq) | |
9798 | destroy_workqueue(wq); | |
9799 | ||
9800 | /* release all the volumes */ | |
9801 | _scsih_ir_shutdown(ioc); | |
9802 | list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list, | |
9803 | list) { | |
9804 | if (raid_device->starget) { | |
9805 | sas_target_priv_data = | |
9806 | raid_device->starget->hostdata; | |
9807 | sas_target_priv_data->deleted = 1; | |
9808 | scsi_remove_target(&raid_device->starget->dev); | |
9809 | } | |
9810 | pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n", | |
9811 | ioc->name, raid_device->handle, | |
9812 | (unsigned long long) raid_device->wwid); | |
9813 | _scsih_raid_device_remove(ioc, raid_device); | |
9814 | } | |
3075ac49 SPS |
9815 | list_for_each_entry_safe(pcie_device, pcienext, &ioc->pcie_device_list, |
9816 | list) { | |
9817 | _scsih_pcie_device_remove_from_sml(ioc, pcie_device); | |
9818 | list_del_init(&pcie_device->list); | |
9819 | pcie_device_put(pcie_device); | |
9820 | } | |
f92363d1 SR |
9821 | |
9822 | /* free ports attached to the sas_host */ | |
9823 | list_for_each_entry_safe(mpt3sas_port, next_port, | |
9824 | &ioc->sas_hba.sas_port_list, port_list) { | |
9825 | if (mpt3sas_port->remote_identify.device_type == | |
9826 | SAS_END_DEVICE) | |
9827 | mpt3sas_device_remove_by_sas_address(ioc, | |
9828 | mpt3sas_port->remote_identify.sas_address); | |
9829 | else if (mpt3sas_port->remote_identify.device_type == | |
9830 | SAS_EDGE_EXPANDER_DEVICE || | |
9831 | mpt3sas_port->remote_identify.device_type == | |
9832 | SAS_FANOUT_EXPANDER_DEVICE) | |
9833 | mpt3sas_expander_remove(ioc, | |
9834 | mpt3sas_port->remote_identify.sas_address); | |
9835 | } | |
9836 | ||
9837 | /* free phys attached to the sas_host */ | |
9838 | if (ioc->sas_hba.num_phys) { | |
9839 | kfree(ioc->sas_hba.phy); | |
9840 | ioc->sas_hba.phy = NULL; | |
9841 | ioc->sas_hba.num_phys = 0; | |
9842 | } | |
9843 | ||
9844 | sas_remove_host(shost); | |
9845 | mpt3sas_base_detach(ioc); | |
08c4d550 | 9846 | spin_lock(&gioc_lock); |
f92363d1 | 9847 | list_del(&ioc->list); |
08c4d550 | 9848 | spin_unlock(&gioc_lock); |
f92363d1 SR |
9849 | scsi_host_put(shost); |
9850 | } | |
9851 | ||
9852 | /** | |
8a7e4c24 | 9853 | * scsih_shutdown - routine call during system shutdown |
f92363d1 SR |
9854 | * @pdev: PCI device struct |
9855 | * | |
9856 | * Return nothing. | |
9857 | */ | |
8bbb1cf6 | 9858 | static void |
8a7e4c24 | 9859 | scsih_shutdown(struct pci_dev *pdev) |
f92363d1 SR |
9860 | { |
9861 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9862 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
9863 | struct workqueue_struct *wq; | |
9864 | unsigned long flags; | |
9865 | ||
9866 | ioc->remove_host = 1; | |
9867 | _scsih_fw_event_cleanup_queue(ioc); | |
9868 | ||
9869 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
9870 | wq = ioc->firmware_event_thread; | |
9871 | ioc->firmware_event_thread = NULL; | |
9872 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
9873 | if (wq) | |
9874 | destroy_workqueue(wq); | |
9875 | ||
9876 | _scsih_ir_shutdown(ioc); | |
9877 | mpt3sas_base_detach(ioc); | |
9878 | } | |
9879 | ||
9880 | ||
9881 | /** | |
9882 | * _scsih_probe_boot_devices - reports 1st device | |
9883 | * @ioc: per adapter object | |
9884 | * | |
9885 | * If specified in bios page 2, this routine reports the 1st | |
9886 | * device scsi-ml or sas transport for persistent boot device | |
9887 | * purposes. Please refer to function _scsih_determine_boot_device() | |
9888 | */ | |
9889 | static void | |
9890 | _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc) | |
9891 | { | |
d88e1eab | 9892 | u32 channel; |
f92363d1 SR |
9893 | void *device; |
9894 | struct _sas_device *sas_device; | |
9895 | struct _raid_device *raid_device; | |
d88e1eab | 9896 | struct _pcie_device *pcie_device; |
f92363d1 SR |
9897 | u16 handle; |
9898 | u64 sas_address_parent; | |
9899 | u64 sas_address; | |
9900 | unsigned long flags; | |
9901 | int rc; | |
d88e1eab | 9902 | int tid; |
f92363d1 SR |
9903 | |
9904 | /* no Bios, return immediately */ | |
9905 | if (!ioc->bios_pg3.BiosVersion) | |
9906 | return; | |
9907 | ||
9908 | device = NULL; | |
f92363d1 SR |
9909 | if (ioc->req_boot_device.device) { |
9910 | device = ioc->req_boot_device.device; | |
d88e1eab | 9911 | channel = ioc->req_boot_device.channel; |
f92363d1 SR |
9912 | } else if (ioc->req_alt_boot_device.device) { |
9913 | device = ioc->req_alt_boot_device.device; | |
d88e1eab | 9914 | channel = ioc->req_alt_boot_device.channel; |
f92363d1 SR |
9915 | } else if (ioc->current_boot_device.device) { |
9916 | device = ioc->current_boot_device.device; | |
d88e1eab | 9917 | channel = ioc->current_boot_device.channel; |
f92363d1 SR |
9918 | } |
9919 | ||
9920 | if (!device) | |
9921 | return; | |
9922 | ||
d88e1eab | 9923 | if (channel == RAID_CHANNEL) { |
f92363d1 SR |
9924 | raid_device = device; |
9925 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
9926 | raid_device->id, 0); | |
9927 | if (rc) | |
9928 | _scsih_raid_device_remove(ioc, raid_device); | |
d88e1eab SPS |
9929 | } else if (channel == PCIE_CHANNEL) { |
9930 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
9931 | pcie_device = device; | |
9932 | tid = pcie_device->id; | |
9933 | list_move_tail(&pcie_device->list, &ioc->pcie_device_list); | |
9934 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
9935 | rc = scsi_add_device(ioc->shost, PCIE_CHANNEL, tid, 0); | |
9936 | if (rc) | |
9937 | _scsih_pcie_device_remove(ioc, pcie_device); | |
f92363d1 SR |
9938 | } else { |
9939 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
9940 | sas_device = device; | |
9941 | handle = sas_device->handle; | |
9942 | sas_address_parent = sas_device->sas_address_parent; | |
9943 | sas_address = sas_device->sas_address; | |
9944 | list_move_tail(&sas_device->list, &ioc->sas_device_list); | |
9945 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
9946 | ||
7786ab6a SR |
9947 | if (ioc->hide_drives) |
9948 | return; | |
f92363d1 SR |
9949 | if (!mpt3sas_transport_port_add(ioc, handle, |
9950 | sas_address_parent)) { | |
9951 | _scsih_sas_device_remove(ioc, sas_device); | |
9952 | } else if (!sas_device->starget) { | |
f5edbe77 SR |
9953 | if (!ioc->is_driver_loading) { |
9954 | mpt3sas_transport_port_remove(ioc, | |
9955 | sas_address, | |
f92363d1 | 9956 | sas_address_parent); |
f5edbe77 SR |
9957 | _scsih_sas_device_remove(ioc, sas_device); |
9958 | } | |
f92363d1 SR |
9959 | } |
9960 | } | |
9961 | } | |
9962 | ||
9963 | /** | |
9964 | * _scsih_probe_raid - reporting raid volumes to scsi-ml | |
9965 | * @ioc: per adapter object | |
9966 | * | |
9967 | * Called during initial loading of the driver. | |
9968 | */ | |
9969 | static void | |
9970 | _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc) | |
9971 | { | |
9972 | struct _raid_device *raid_device, *raid_next; | |
9973 | int rc; | |
9974 | ||
9975 | list_for_each_entry_safe(raid_device, raid_next, | |
9976 | &ioc->raid_device_list, list) { | |
9977 | if (raid_device->starget) | |
9978 | continue; | |
9979 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
9980 | raid_device->id, 0); | |
9981 | if (rc) | |
9982 | _scsih_raid_device_remove(ioc, raid_device); | |
9983 | } | |
9984 | } | |
9985 | ||
d1cb5e49 SR |
9986 | static struct _sas_device *get_next_sas_device(struct MPT3SAS_ADAPTER *ioc) |
9987 | { | |
9988 | struct _sas_device *sas_device = NULL; | |
9989 | unsigned long flags; | |
9990 | ||
9991 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
9992 | if (!list_empty(&ioc->sas_device_init_list)) { | |
9993 | sas_device = list_first_entry(&ioc->sas_device_init_list, | |
9994 | struct _sas_device, list); | |
9995 | sas_device_get(sas_device); | |
9996 | } | |
9997 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
9998 | ||
9999 | return sas_device; | |
10000 | } | |
10001 | ||
10002 | static void sas_device_make_active(struct MPT3SAS_ADAPTER *ioc, | |
10003 | struct _sas_device *sas_device) | |
10004 | { | |
10005 | unsigned long flags; | |
10006 | ||
10007 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
10008 | ||
10009 | /* | |
10010 | * Since we dropped the lock during the call to port_add(), we need to | |
10011 | * be careful here that somebody else didn't move or delete this item | |
10012 | * while we were busy with other things. | |
10013 | * | |
10014 | * If it was on the list, we need a put() for the reference the list | |
10015 | * had. Either way, we need a get() for the destination list. | |
10016 | */ | |
10017 | if (!list_empty(&sas_device->list)) { | |
10018 | list_del_init(&sas_device->list); | |
10019 | sas_device_put(sas_device); | |
10020 | } | |
10021 | ||
10022 | sas_device_get(sas_device); | |
10023 | list_add_tail(&sas_device->list, &ioc->sas_device_list); | |
10024 | ||
10025 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
10026 | } | |
10027 | ||
f92363d1 SR |
10028 | /** |
10029 | * _scsih_probe_sas - reporting sas devices to sas transport | |
10030 | * @ioc: per adapter object | |
10031 | * | |
10032 | * Called during initial loading of the driver. | |
10033 | */ | |
10034 | static void | |
10035 | _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc) | |
10036 | { | |
d1cb5e49 | 10037 | struct _sas_device *sas_device; |
f92363d1 | 10038 | |
d1cb5e49 SR |
10039 | if (ioc->hide_drives) |
10040 | return; | |
7786ab6a | 10041 | |
d1cb5e49 | 10042 | while ((sas_device = get_next_sas_device(ioc))) { |
f92363d1 SR |
10043 | if (!mpt3sas_transport_port_add(ioc, sas_device->handle, |
10044 | sas_device->sas_address_parent)) { | |
d1cb5e49 SR |
10045 | _scsih_sas_device_remove(ioc, sas_device); |
10046 | sas_device_put(sas_device); | |
f92363d1 SR |
10047 | continue; |
10048 | } else if (!sas_device->starget) { | |
10049 | /* | |
10050 | * When asyn scanning is enabled, its not possible to | |
10051 | * remove devices while scanning is turned on due to an | |
10052 | * oops in scsi_sysfs_add_sdev()->add_device()-> | |
10053 | * sysfs_addrm_start() | |
10054 | */ | |
f5edbe77 | 10055 | if (!ioc->is_driver_loading) { |
f92363d1 SR |
10056 | mpt3sas_transport_port_remove(ioc, |
10057 | sas_device->sas_address, | |
10058 | sas_device->sas_address_parent); | |
d1cb5e49 SR |
10059 | _scsih_sas_device_remove(ioc, sas_device); |
10060 | sas_device_put(sas_device); | |
f5edbe77 SR |
10061 | continue; |
10062 | } | |
f92363d1 | 10063 | } |
d1cb5e49 SR |
10064 | sas_device_make_active(ioc, sas_device); |
10065 | sas_device_put(sas_device); | |
f92363d1 SR |
10066 | } |
10067 | } | |
10068 | ||
d88e1eab SPS |
10069 | /** |
10070 | * get_next_pcie_device - Get the next pcie device | |
10071 | * @ioc: per adapter object | |
10072 | * | |
10073 | * Get the next pcie device from pcie_device_init_list list. | |
10074 | * | |
10075 | * Returns pcie device structure if pcie_device_init_list list is not empty | |
10076 | * otherwise returns NULL | |
10077 | */ | |
10078 | static struct _pcie_device *get_next_pcie_device(struct MPT3SAS_ADAPTER *ioc) | |
10079 | { | |
10080 | struct _pcie_device *pcie_device = NULL; | |
10081 | unsigned long flags; | |
10082 | ||
10083 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
10084 | if (!list_empty(&ioc->pcie_device_init_list)) { | |
10085 | pcie_device = list_first_entry(&ioc->pcie_device_init_list, | |
10086 | struct _pcie_device, list); | |
10087 | pcie_device_get(pcie_device); | |
10088 | } | |
10089 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
10090 | ||
10091 | return pcie_device; | |
10092 | } | |
10093 | ||
10094 | /** | |
10095 | * pcie_device_make_active - Add pcie device to pcie_device_list list | |
10096 | * @ioc: per adapter object | |
10097 | * @pcie_device: pcie device object | |
10098 | * | |
10099 | * Add the pcie device which has registered with SCSI Transport Later to | |
10100 | * pcie_device_list list | |
10101 | */ | |
10102 | static void pcie_device_make_active(struct MPT3SAS_ADAPTER *ioc, | |
10103 | struct _pcie_device *pcie_device) | |
10104 | { | |
10105 | unsigned long flags; | |
10106 | ||
10107 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
10108 | ||
10109 | if (!list_empty(&pcie_device->list)) { | |
10110 | list_del_init(&pcie_device->list); | |
10111 | pcie_device_put(pcie_device); | |
10112 | } | |
10113 | pcie_device_get(pcie_device); | |
10114 | list_add_tail(&pcie_device->list, &ioc->pcie_device_list); | |
10115 | ||
10116 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
10117 | } | |
10118 | ||
10119 | /** | |
10120 | * _scsih_probe_pcie - reporting PCIe devices to scsi-ml | |
10121 | * @ioc: per adapter object | |
10122 | * | |
10123 | * Called during initial loading of the driver. | |
10124 | */ | |
10125 | static void | |
10126 | _scsih_probe_pcie(struct MPT3SAS_ADAPTER *ioc) | |
10127 | { | |
10128 | struct _pcie_device *pcie_device; | |
10129 | int rc; | |
10130 | ||
10131 | /* PCIe Device List */ | |
10132 | while ((pcie_device = get_next_pcie_device(ioc))) { | |
10133 | if (pcie_device->starget) { | |
10134 | pcie_device_put(pcie_device); | |
10135 | continue; | |
10136 | } | |
10137 | rc = scsi_add_device(ioc->shost, PCIE_CHANNEL, | |
10138 | pcie_device->id, 0); | |
10139 | if (rc) { | |
10140 | _scsih_pcie_device_remove(ioc, pcie_device); | |
10141 | pcie_device_put(pcie_device); | |
10142 | continue; | |
10143 | } else if (!pcie_device->starget) { | |
10144 | /* | |
10145 | * When async scanning is enabled, its not possible to | |
10146 | * remove devices while scanning is turned on due to an | |
10147 | * oops in scsi_sysfs_add_sdev()->add_device()-> | |
10148 | * sysfs_addrm_start() | |
10149 | */ | |
10150 | if (!ioc->is_driver_loading) { | |
10151 | /* TODO-- Need to find out whether this condition will | |
10152 | * occur or not | |
10153 | */ | |
10154 | _scsih_pcie_device_remove(ioc, pcie_device); | |
10155 | pcie_device_put(pcie_device); | |
10156 | continue; | |
10157 | } | |
10158 | } | |
10159 | pcie_device_make_active(ioc, pcie_device); | |
10160 | pcie_device_put(pcie_device); | |
10161 | } | |
10162 | } | |
10163 | ||
f92363d1 SR |
10164 | /** |
10165 | * _scsih_probe_devices - probing for devices | |
10166 | * @ioc: per adapter object | |
10167 | * | |
10168 | * Called during initial loading of the driver. | |
10169 | */ | |
10170 | static void | |
10171 | _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc) | |
10172 | { | |
10173 | u16 volume_mapping_flags; | |
10174 | ||
10175 | if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR)) | |
10176 | return; /* return when IOC doesn't support initiator mode */ | |
10177 | ||
10178 | _scsih_probe_boot_devices(ioc); | |
10179 | ||
10180 | if (ioc->ir_firmware) { | |
10181 | volume_mapping_flags = | |
10182 | le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) & | |
10183 | MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE; | |
10184 | if (volume_mapping_flags == | |
10185 | MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) { | |
10186 | _scsih_probe_raid(ioc); | |
10187 | _scsih_probe_sas(ioc); | |
10188 | } else { | |
10189 | _scsih_probe_sas(ioc); | |
10190 | _scsih_probe_raid(ioc); | |
10191 | } | |
d88e1eab | 10192 | } else { |
f92363d1 | 10193 | _scsih_probe_sas(ioc); |
d88e1eab SPS |
10194 | _scsih_probe_pcie(ioc); |
10195 | } | |
f92363d1 SR |
10196 | } |
10197 | ||
10198 | /** | |
8a7e4c24 | 10199 | * scsih_scan_start - scsi lld callback for .scan_start |
f92363d1 SR |
10200 | * @shost: SCSI host pointer |
10201 | * | |
10202 | * The shost has the ability to discover targets on its own instead | |
10203 | * of scanning the entire bus. In our implemention, we will kick off | |
10204 | * firmware discovery. | |
10205 | */ | |
8bbb1cf6 | 10206 | static void |
8a7e4c24 | 10207 | scsih_scan_start(struct Scsi_Host *shost) |
f92363d1 SR |
10208 | { |
10209 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10210 | int rc; | |
10211 | if (diag_buffer_enable != -1 && diag_buffer_enable != 0) | |
10212 | mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable); | |
10213 | ||
10214 | if (disable_discovery > 0) | |
10215 | return; | |
10216 | ||
10217 | ioc->start_scan = 1; | |
10218 | rc = mpt3sas_port_enable(ioc); | |
10219 | ||
10220 | if (rc != 0) | |
10221 | pr_info(MPT3SAS_FMT "port enable: FAILED\n", ioc->name); | |
10222 | } | |
10223 | ||
10224 | /** | |
8a7e4c24 | 10225 | * scsih_scan_finished - scsi lld callback for .scan_finished |
f92363d1 SR |
10226 | * @shost: SCSI host pointer |
10227 | * @time: elapsed time of the scan in jiffies | |
10228 | * | |
10229 | * This function will be called periodicallyn until it returns 1 with the | |
10230 | * scsi_host and the elapsed time of the scan in jiffies. In our implemention, | |
10231 | * we wait for firmware discovery to complete, then return 1. | |
10232 | */ | |
8bbb1cf6 | 10233 | static int |
8a7e4c24 | 10234 | scsih_scan_finished(struct Scsi_Host *shost, unsigned long time) |
f92363d1 SR |
10235 | { |
10236 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10237 | ||
10238 | if (disable_discovery > 0) { | |
10239 | ioc->is_driver_loading = 0; | |
10240 | ioc->wait_for_discovery_to_complete = 0; | |
10241 | return 1; | |
10242 | } | |
10243 | ||
10244 | if (time >= (300 * HZ)) { | |
10245 | ioc->base_cmds.status = MPT3_CMD_NOT_USED; | |
10246 | pr_info(MPT3SAS_FMT | |
10247 | "port enable: FAILED with timeout (timeout=300s)\n", | |
10248 | ioc->name); | |
10249 | ioc->is_driver_loading = 0; | |
10250 | return 1; | |
10251 | } | |
10252 | ||
10253 | if (ioc->start_scan) | |
10254 | return 0; | |
10255 | ||
10256 | if (ioc->start_scan_failed) { | |
10257 | pr_info(MPT3SAS_FMT | |
10258 | "port enable: FAILED with (ioc_status=0x%08x)\n", | |
10259 | ioc->name, ioc->start_scan_failed); | |
10260 | ioc->is_driver_loading = 0; | |
10261 | ioc->wait_for_discovery_to_complete = 0; | |
10262 | ioc->remove_host = 1; | |
10263 | return 1; | |
10264 | } | |
10265 | ||
10266 | pr_info(MPT3SAS_FMT "port enable: SUCCESS\n", ioc->name); | |
10267 | ioc->base_cmds.status = MPT3_CMD_NOT_USED; | |
10268 | ||
10269 | if (ioc->wait_for_discovery_to_complete) { | |
10270 | ioc->wait_for_discovery_to_complete = 0; | |
10271 | _scsih_probe_devices(ioc); | |
10272 | } | |
10273 | mpt3sas_base_start_watchdog(ioc); | |
10274 | ioc->is_driver_loading = 0; | |
10275 | return 1; | |
10276 | } | |
10277 | ||
c84b06a4 SR |
10278 | /* shost template for SAS 2.0 HBA devices */ |
10279 | static struct scsi_host_template mpt2sas_driver_template = { | |
10280 | .module = THIS_MODULE, | |
10281 | .name = "Fusion MPT SAS Host", | |
10282 | .proc_name = MPT2SAS_DRIVER_NAME, | |
10283 | .queuecommand = scsih_qcmd, | |
10284 | .target_alloc = scsih_target_alloc, | |
10285 | .slave_alloc = scsih_slave_alloc, | |
10286 | .slave_configure = scsih_slave_configure, | |
10287 | .target_destroy = scsih_target_destroy, | |
10288 | .slave_destroy = scsih_slave_destroy, | |
10289 | .scan_finished = scsih_scan_finished, | |
10290 | .scan_start = scsih_scan_start, | |
10291 | .change_queue_depth = scsih_change_queue_depth, | |
10292 | .eh_abort_handler = scsih_abort, | |
10293 | .eh_device_reset_handler = scsih_dev_reset, | |
10294 | .eh_target_reset_handler = scsih_target_reset, | |
10295 | .eh_host_reset_handler = scsih_host_reset, | |
10296 | .bios_param = scsih_bios_param, | |
10297 | .can_queue = 1, | |
10298 | .this_id = -1, | |
10299 | .sg_tablesize = MPT2SAS_SG_DEPTH, | |
10300 | .max_sectors = 32767, | |
10301 | .cmd_per_lun = 7, | |
10302 | .use_clustering = ENABLE_CLUSTERING, | |
10303 | .shost_attrs = mpt3sas_host_attrs, | |
10304 | .sdev_attrs = mpt3sas_dev_attrs, | |
10305 | .track_queue_depth = 1, | |
10306 | }; | |
10307 | ||
10308 | /* raid transport support for SAS 2.0 HBA devices */ | |
10309 | static struct raid_function_template mpt2sas_raid_functions = { | |
10310 | .cookie = &mpt2sas_driver_template, | |
10311 | .is_raid = scsih_is_raid, | |
10312 | .get_resync = scsih_get_resync, | |
10313 | .get_state = scsih_get_state, | |
10314 | }; | |
d357e84d | 10315 | |
c84b06a4 SR |
10316 | /* shost template for SAS 3.0 HBA devices */ |
10317 | static struct scsi_host_template mpt3sas_driver_template = { | |
10318 | .module = THIS_MODULE, | |
10319 | .name = "Fusion MPT SAS Host", | |
10320 | .proc_name = MPT3SAS_DRIVER_NAME, | |
10321 | .queuecommand = scsih_qcmd, | |
10322 | .target_alloc = scsih_target_alloc, | |
10323 | .slave_alloc = scsih_slave_alloc, | |
10324 | .slave_configure = scsih_slave_configure, | |
10325 | .target_destroy = scsih_target_destroy, | |
10326 | .slave_destroy = scsih_slave_destroy, | |
10327 | .scan_finished = scsih_scan_finished, | |
10328 | .scan_start = scsih_scan_start, | |
10329 | .change_queue_depth = scsih_change_queue_depth, | |
10330 | .eh_abort_handler = scsih_abort, | |
10331 | .eh_device_reset_handler = scsih_dev_reset, | |
10332 | .eh_target_reset_handler = scsih_target_reset, | |
10333 | .eh_host_reset_handler = scsih_host_reset, | |
10334 | .bios_param = scsih_bios_param, | |
10335 | .can_queue = 1, | |
10336 | .this_id = -1, | |
10337 | .sg_tablesize = MPT3SAS_SG_DEPTH, | |
10338 | .max_sectors = 32767, | |
10339 | .cmd_per_lun = 7, | |
10340 | .use_clustering = ENABLE_CLUSTERING, | |
10341 | .shost_attrs = mpt3sas_host_attrs, | |
10342 | .sdev_attrs = mpt3sas_dev_attrs, | |
10343 | .track_queue_depth = 1, | |
10344 | }; | |
10345 | ||
10346 | /* raid transport support for SAS 3.0 HBA devices */ | |
10347 | static struct raid_function_template mpt3sas_raid_functions = { | |
10348 | .cookie = &mpt3sas_driver_template, | |
10349 | .is_raid = scsih_is_raid, | |
10350 | .get_resync = scsih_get_resync, | |
10351 | .get_state = scsih_get_state, | |
10352 | }; | |
10353 | ||
10354 | /** | |
10355 | * _scsih_determine_hba_mpi_version - determine in which MPI version class | |
10356 | * this device belongs to. | |
10357 | * @pdev: PCI device struct | |
10358 | * | |
10359 | * return MPI2_VERSION for SAS 2.0 HBA devices, | |
b130b0d5 SS |
10360 | * MPI25_VERSION for SAS 3.0 HBA devices, and |
10361 | * MPI26 VERSION for Cutlass & Invader SAS 3.0 HBA devices | |
c84b06a4 | 10362 | */ |
8bbb1cf6 | 10363 | static u16 |
c84b06a4 SR |
10364 | _scsih_determine_hba_mpi_version(struct pci_dev *pdev) |
10365 | { | |
10366 | ||
10367 | switch (pdev->device) { | |
7786ab6a | 10368 | case MPI2_MFGPAGE_DEVID_SSS6200: |
d357e84d SR |
10369 | case MPI2_MFGPAGE_DEVID_SAS2004: |
10370 | case MPI2_MFGPAGE_DEVID_SAS2008: | |
10371 | case MPI2_MFGPAGE_DEVID_SAS2108_1: | |
10372 | case MPI2_MFGPAGE_DEVID_SAS2108_2: | |
10373 | case MPI2_MFGPAGE_DEVID_SAS2108_3: | |
10374 | case MPI2_MFGPAGE_DEVID_SAS2116_1: | |
10375 | case MPI2_MFGPAGE_DEVID_SAS2116_2: | |
10376 | case MPI2_MFGPAGE_DEVID_SAS2208_1: | |
10377 | case MPI2_MFGPAGE_DEVID_SAS2208_2: | |
10378 | case MPI2_MFGPAGE_DEVID_SAS2208_3: | |
10379 | case MPI2_MFGPAGE_DEVID_SAS2208_4: | |
10380 | case MPI2_MFGPAGE_DEVID_SAS2208_5: | |
10381 | case MPI2_MFGPAGE_DEVID_SAS2208_6: | |
10382 | case MPI2_MFGPAGE_DEVID_SAS2308_1: | |
10383 | case MPI2_MFGPAGE_DEVID_SAS2308_2: | |
10384 | case MPI2_MFGPAGE_DEVID_SAS2308_3: | |
c84b06a4 | 10385 | return MPI2_VERSION; |
d357e84d SR |
10386 | case MPI25_MFGPAGE_DEVID_SAS3004: |
10387 | case MPI25_MFGPAGE_DEVID_SAS3008: | |
10388 | case MPI25_MFGPAGE_DEVID_SAS3108_1: | |
10389 | case MPI25_MFGPAGE_DEVID_SAS3108_2: | |
10390 | case MPI25_MFGPAGE_DEVID_SAS3108_5: | |
10391 | case MPI25_MFGPAGE_DEVID_SAS3108_6: | |
c84b06a4 | 10392 | return MPI25_VERSION; |
b130b0d5 SS |
10393 | case MPI26_MFGPAGE_DEVID_SAS3216: |
10394 | case MPI26_MFGPAGE_DEVID_SAS3224: | |
10395 | case MPI26_MFGPAGE_DEVID_SAS3316_1: | |
10396 | case MPI26_MFGPAGE_DEVID_SAS3316_2: | |
10397 | case MPI26_MFGPAGE_DEVID_SAS3316_3: | |
10398 | case MPI26_MFGPAGE_DEVID_SAS3316_4: | |
10399 | case MPI26_MFGPAGE_DEVID_SAS3324_1: | |
10400 | case MPI26_MFGPAGE_DEVID_SAS3324_2: | |
10401 | case MPI26_MFGPAGE_DEVID_SAS3324_3: | |
10402 | case MPI26_MFGPAGE_DEVID_SAS3324_4: | |
998f26ae SPS |
10403 | case MPI26_MFGPAGE_DEVID_SAS3508: |
10404 | case MPI26_MFGPAGE_DEVID_SAS3508_1: | |
10405 | case MPI26_MFGPAGE_DEVID_SAS3408: | |
10406 | case MPI26_MFGPAGE_DEVID_SAS3516: | |
10407 | case MPI26_MFGPAGE_DEVID_SAS3516_1: | |
10408 | case MPI26_MFGPAGE_DEVID_SAS3416: | |
15fd7c74 | 10409 | case MPI26_MFGPAGE_DEVID_SAS3616: |
b130b0d5 | 10410 | return MPI26_VERSION; |
d357e84d | 10411 | } |
c84b06a4 | 10412 | return 0; |
d357e84d SR |
10413 | } |
10414 | ||
f92363d1 | 10415 | /** |
c84b06a4 | 10416 | * _scsih_probe - attach and add scsi host |
f92363d1 SR |
10417 | * @pdev: PCI device struct |
10418 | * @id: pci device id | |
10419 | * | |
10420 | * Returns 0 success, anything else error. | |
10421 | */ | |
8bbb1cf6 | 10422 | static int |
c84b06a4 | 10423 | _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
f92363d1 SR |
10424 | { |
10425 | struct MPT3SAS_ADAPTER *ioc; | |
c84b06a4 | 10426 | struct Scsi_Host *shost = NULL; |
b65f1d4d | 10427 | int rv; |
c84b06a4 SR |
10428 | u16 hba_mpi_version; |
10429 | ||
10430 | /* Determine in which MPI version class this pci device belongs */ | |
10431 | hba_mpi_version = _scsih_determine_hba_mpi_version(pdev); | |
10432 | if (hba_mpi_version == 0) | |
10433 | return -ENODEV; | |
10434 | ||
10435 | /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one, | |
10436 | * for other generation HBA's return with -ENODEV | |
10437 | */ | |
10438 | if ((hbas_to_enumerate == 1) && (hba_mpi_version != MPI2_VERSION)) | |
10439 | return -ENODEV; | |
10440 | ||
10441 | /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two, | |
10442 | * for other generation HBA's return with -ENODEV | |
10443 | */ | |
b130b0d5 SS |
10444 | if ((hbas_to_enumerate == 2) && (!(hba_mpi_version == MPI25_VERSION |
10445 | || hba_mpi_version == MPI26_VERSION))) | |
c84b06a4 SR |
10446 | return -ENODEV; |
10447 | ||
10448 | switch (hba_mpi_version) { | |
10449 | case MPI2_VERSION: | |
ffdadd68 | 10450 | pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | |
10451 | PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM); | |
c84b06a4 SR |
10452 | /* Use mpt2sas driver host template for SAS 2.0 HBA's */ |
10453 | shost = scsi_host_alloc(&mpt2sas_driver_template, | |
10454 | sizeof(struct MPT3SAS_ADAPTER)); | |
10455 | if (!shost) | |
10456 | return -ENODEV; | |
10457 | ioc = shost_priv(shost); | |
10458 | memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER)); | |
10459 | ioc->hba_mpi_version_belonged = hba_mpi_version; | |
10460 | ioc->id = mpt2_ids++; | |
10461 | sprintf(ioc->driver_name, "%s", MPT2SAS_DRIVER_NAME); | |
10462 | if (pdev->device == MPI2_MFGPAGE_DEVID_SSS6200) { | |
10463 | ioc->is_warpdrive = 1; | |
10464 | ioc->hide_ir_msg = 1; | |
10465 | } else | |
10466 | ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS; | |
10467 | break; | |
10468 | case MPI25_VERSION: | |
b130b0d5 | 10469 | case MPI26_VERSION: |
c84b06a4 SR |
10470 | /* Use mpt3sas driver host template for SAS 3.0 HBA's */ |
10471 | shost = scsi_host_alloc(&mpt3sas_driver_template, | |
10472 | sizeof(struct MPT3SAS_ADAPTER)); | |
10473 | if (!shost) | |
10474 | return -ENODEV; | |
10475 | ioc = shost_priv(shost); | |
10476 | memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER)); | |
10477 | ioc->hba_mpi_version_belonged = hba_mpi_version; | |
10478 | ioc->id = mpt3_ids++; | |
10479 | sprintf(ioc->driver_name, "%s", MPT3SAS_DRIVER_NAME); | |
998f26ae SPS |
10480 | switch (pdev->device) { |
10481 | case MPI26_MFGPAGE_DEVID_SAS3508: | |
10482 | case MPI26_MFGPAGE_DEVID_SAS3508_1: | |
10483 | case MPI26_MFGPAGE_DEVID_SAS3408: | |
10484 | case MPI26_MFGPAGE_DEVID_SAS3516: | |
10485 | case MPI26_MFGPAGE_DEVID_SAS3516_1: | |
10486 | case MPI26_MFGPAGE_DEVID_SAS3416: | |
15fd7c74 | 10487 | case MPI26_MFGPAGE_DEVID_SAS3616: |
998f26ae SPS |
10488 | ioc->is_gen35_ioc = 1; |
10489 | break; | |
10490 | default: | |
10491 | ioc->is_gen35_ioc = 0; | |
10492 | } | |
b130b0d5 SS |
10493 | if ((ioc->hba_mpi_version_belonged == MPI25_VERSION && |
10494 | pdev->revision >= SAS3_PCI_DEVICE_C0_REVISION) || | |
0bb337c9 SPS |
10495 | (ioc->hba_mpi_version_belonged == MPI26_VERSION)) { |
10496 | ioc->combined_reply_queue = 1; | |
10497 | if (ioc->is_gen35_ioc) | |
10498 | ioc->combined_reply_index_count = | |
10499 | MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G35; | |
10500 | else | |
10501 | ioc->combined_reply_index_count = | |
10502 | MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G3; | |
10503 | } | |
c84b06a4 SR |
10504 | break; |
10505 | default: | |
10506 | return -ENODEV; | |
10507 | } | |
f92363d1 | 10508 | |
f92363d1 | 10509 | INIT_LIST_HEAD(&ioc->list); |
08c4d550 | 10510 | spin_lock(&gioc_lock); |
f92363d1 | 10511 | list_add_tail(&ioc->list, &mpt3sas_ioc_list); |
08c4d550 | 10512 | spin_unlock(&gioc_lock); |
f92363d1 | 10513 | ioc->shost = shost; |
f92363d1 SR |
10514 | ioc->pdev = pdev; |
10515 | ioc->scsi_io_cb_idx = scsi_io_cb_idx; | |
10516 | ioc->tm_cb_idx = tm_cb_idx; | |
10517 | ioc->ctl_cb_idx = ctl_cb_idx; | |
10518 | ioc->base_cb_idx = base_cb_idx; | |
10519 | ioc->port_enable_cb_idx = port_enable_cb_idx; | |
10520 | ioc->transport_cb_idx = transport_cb_idx; | |
10521 | ioc->scsih_cb_idx = scsih_cb_idx; | |
10522 | ioc->config_cb_idx = config_cb_idx; | |
10523 | ioc->tm_tr_cb_idx = tm_tr_cb_idx; | |
10524 | ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx; | |
10525 | ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx; | |
10526 | ioc->logging_level = logging_level; | |
10527 | ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds; | |
10528 | /* misc semaphores and spin locks */ | |
10529 | mutex_init(&ioc->reset_in_progress_mutex); | |
08c4d550 SR |
10530 | /* initializing pci_access_mutex lock */ |
10531 | mutex_init(&ioc->pci_access_mutex); | |
f92363d1 SR |
10532 | spin_lock_init(&ioc->ioc_reset_in_progress_lock); |
10533 | spin_lock_init(&ioc->scsi_lookup_lock); | |
10534 | spin_lock_init(&ioc->sas_device_lock); | |
10535 | spin_lock_init(&ioc->sas_node_lock); | |
10536 | spin_lock_init(&ioc->fw_event_lock); | |
10537 | spin_lock_init(&ioc->raid_device_lock); | |
d88e1eab | 10538 | spin_lock_init(&ioc->pcie_device_lock); |
f92363d1 SR |
10539 | spin_lock_init(&ioc->diag_trigger_lock); |
10540 | ||
10541 | INIT_LIST_HEAD(&ioc->sas_device_list); | |
10542 | INIT_LIST_HEAD(&ioc->sas_device_init_list); | |
10543 | INIT_LIST_HEAD(&ioc->sas_expander_list); | |
d88e1eab SPS |
10544 | INIT_LIST_HEAD(&ioc->pcie_device_list); |
10545 | INIT_LIST_HEAD(&ioc->pcie_device_init_list); | |
f92363d1 SR |
10546 | INIT_LIST_HEAD(&ioc->fw_event_list); |
10547 | INIT_LIST_HEAD(&ioc->raid_device_list); | |
10548 | INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list); | |
10549 | INIT_LIST_HEAD(&ioc->delayed_tr_list); | |
fd0331b3 SS |
10550 | INIT_LIST_HEAD(&ioc->delayed_sc_list); |
10551 | INIT_LIST_HEAD(&ioc->delayed_event_ack_list); | |
f92363d1 | 10552 | INIT_LIST_HEAD(&ioc->delayed_tr_volume_list); |
cf9bd21a | 10553 | INIT_LIST_HEAD(&ioc->reply_queue_list); |
f92363d1 | 10554 | |
c84b06a4 | 10555 | sprintf(ioc->name, "%s_cm%d", ioc->driver_name, ioc->id); |
d357e84d | 10556 | |
f92363d1 SR |
10557 | /* init shost parameters */ |
10558 | shost->max_cmd_len = 32; | |
10559 | shost->max_lun = max_lun; | |
10560 | shost->transportt = mpt3sas_transport_template; | |
10561 | shost->unique_id = ioc->id; | |
10562 | ||
10563 | if (max_sectors != 0xFFFF) { | |
10564 | if (max_sectors < 64) { | |
10565 | shost->max_sectors = 64; | |
10566 | pr_warn(MPT3SAS_FMT "Invalid value %d passed " \ | |
10567 | "for max_sectors, range is 64 to 32767. Assigning " | |
10568 | "value of 64.\n", ioc->name, max_sectors); | |
10569 | } else if (max_sectors > 32767) { | |
10570 | shost->max_sectors = 32767; | |
10571 | pr_warn(MPT3SAS_FMT "Invalid value %d passed " \ | |
10572 | "for max_sectors, range is 64 to 32767. Assigning " | |
10573 | "default value of 32767.\n", ioc->name, | |
10574 | max_sectors); | |
10575 | } else { | |
10576 | shost->max_sectors = max_sectors & 0xFFFE; | |
10577 | pr_info(MPT3SAS_FMT | |
10578 | "The max_sectors value is set to %d\n", | |
10579 | ioc->name, shost->max_sectors); | |
10580 | } | |
10581 | } | |
10582 | ||
f92363d1 SR |
10583 | /* register EEDP capabilities with SCSI layer */ |
10584 | if (prot_mask > 0) | |
10585 | scsi_host_set_prot(shost, prot_mask); | |
10586 | else | |
10587 | scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION | |
10588 | | SHOST_DIF_TYPE2_PROTECTION | |
10589 | | SHOST_DIF_TYPE3_PROTECTION); | |
10590 | ||
10591 | scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC); | |
10592 | ||
10593 | /* event thread */ | |
10594 | snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name), | |
c84b06a4 | 10595 | "fw_event_%s%d", ioc->driver_name, ioc->id); |
bdff785e SR |
10596 | ioc->firmware_event_thread = alloc_ordered_workqueue( |
10597 | ioc->firmware_event_name, WQ_MEM_RECLAIM); | |
f92363d1 SR |
10598 | if (!ioc->firmware_event_thread) { |
10599 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
10600 | ioc->name, __FILE__, __LINE__, __func__); | |
b65f1d4d | 10601 | rv = -ENODEV; |
f92363d1 SR |
10602 | goto out_thread_fail; |
10603 | } | |
10604 | ||
10605 | ioc->is_driver_loading = 1; | |
10606 | if ((mpt3sas_base_attach(ioc))) { | |
10607 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
10608 | ioc->name, __FILE__, __LINE__, __func__); | |
b65f1d4d | 10609 | rv = -ENODEV; |
f92363d1 SR |
10610 | goto out_attach_fail; |
10611 | } | |
7786ab6a | 10612 | |
7786ab6a SR |
10613 | if (ioc->is_warpdrive) { |
10614 | if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) | |
10615 | ioc->hide_drives = 0; | |
10616 | else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS) | |
10617 | ioc->hide_drives = 1; | |
10618 | else { | |
c84b06a4 | 10619 | if (mpt3sas_get_num_volumes(ioc)) |
7786ab6a SR |
10620 | ioc->hide_drives = 1; |
10621 | else | |
10622 | ioc->hide_drives = 0; | |
10623 | } | |
10624 | } else | |
10625 | ioc->hide_drives = 0; | |
7786ab6a | 10626 | |
b65f1d4d SR |
10627 | rv = scsi_add_host(shost, &pdev->dev); |
10628 | if (rv) { | |
4dc06fd8 RS |
10629 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
10630 | ioc->name, __FILE__, __LINE__, __func__); | |
4dc06fd8 RS |
10631 | goto out_add_shost_fail; |
10632 | } | |
10633 | ||
f92363d1 SR |
10634 | scsi_scan_host(shost); |
10635 | return 0; | |
4dc06fd8 RS |
10636 | out_add_shost_fail: |
10637 | mpt3sas_base_detach(ioc); | |
f92363d1 SR |
10638 | out_attach_fail: |
10639 | destroy_workqueue(ioc->firmware_event_thread); | |
10640 | out_thread_fail: | |
08c4d550 | 10641 | spin_lock(&gioc_lock); |
f92363d1 | 10642 | list_del(&ioc->list); |
08c4d550 | 10643 | spin_unlock(&gioc_lock); |
f92363d1 | 10644 | scsi_host_put(shost); |
b65f1d4d | 10645 | return rv; |
f92363d1 SR |
10646 | } |
10647 | ||
10648 | #ifdef CONFIG_PM | |
10649 | /** | |
8a7e4c24 | 10650 | * scsih_suspend - power management suspend main entry point |
f92363d1 SR |
10651 | * @pdev: PCI device struct |
10652 | * @state: PM state change to (usually PCI_D3) | |
10653 | * | |
10654 | * Returns 0 success, anything else error. | |
10655 | */ | |
8bbb1cf6 | 10656 | static int |
8a7e4c24 | 10657 | scsih_suspend(struct pci_dev *pdev, pm_message_t state) |
f92363d1 SR |
10658 | { |
10659 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10660 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10661 | pci_power_t device_state; | |
10662 | ||
10663 | mpt3sas_base_stop_watchdog(ioc); | |
10664 | flush_scheduled_work(); | |
10665 | scsi_block_requests(shost); | |
10666 | device_state = pci_choose_state(pdev, state); | |
10667 | pr_info(MPT3SAS_FMT | |
10668 | "pdev=0x%p, slot=%s, entering operating state [D%d]\n", | |
10669 | ioc->name, pdev, pci_name(pdev), device_state); | |
10670 | ||
10671 | pci_save_state(pdev); | |
10672 | mpt3sas_base_free_resources(ioc); | |
10673 | pci_set_power_state(pdev, device_state); | |
10674 | return 0; | |
10675 | } | |
10676 | ||
10677 | /** | |
8a7e4c24 | 10678 | * scsih_resume - power management resume main entry point |
f92363d1 SR |
10679 | * @pdev: PCI device struct |
10680 | * | |
10681 | * Returns 0 success, anything else error. | |
10682 | */ | |
8bbb1cf6 | 10683 | static int |
8a7e4c24 | 10684 | scsih_resume(struct pci_dev *pdev) |
f92363d1 SR |
10685 | { |
10686 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10687 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10688 | pci_power_t device_state = pdev->current_state; | |
10689 | int r; | |
10690 | ||
10691 | pr_info(MPT3SAS_FMT | |
10692 | "pdev=0x%p, slot=%s, previous operating state [D%d]\n", | |
10693 | ioc->name, pdev, pci_name(pdev), device_state); | |
10694 | ||
10695 | pci_set_power_state(pdev, PCI_D0); | |
10696 | pci_enable_wake(pdev, PCI_D0, 0); | |
10697 | pci_restore_state(pdev); | |
10698 | ioc->pdev = pdev; | |
10699 | r = mpt3sas_base_map_resources(ioc); | |
10700 | if (r) | |
10701 | return r; | |
10702 | ||
98c56ad3 | 10703 | mpt3sas_base_hard_reset_handler(ioc, SOFT_RESET); |
f92363d1 SR |
10704 | scsi_unblock_requests(shost); |
10705 | mpt3sas_base_start_watchdog(ioc); | |
10706 | return 0; | |
10707 | } | |
10708 | #endif /* CONFIG_PM */ | |
10709 | ||
10710 | /** | |
8a7e4c24 | 10711 | * scsih_pci_error_detected - Called when a PCI error is detected. |
f92363d1 SR |
10712 | * @pdev: PCI device struct |
10713 | * @state: PCI channel state | |
10714 | * | |
10715 | * Description: Called when a PCI error is detected. | |
10716 | * | |
10717 | * Return value: | |
10718 | * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT | |
10719 | */ | |
8bbb1cf6 | 10720 | static pci_ers_result_t |
8a7e4c24 | 10721 | scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
f92363d1 SR |
10722 | { |
10723 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10724 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10725 | ||
10726 | pr_info(MPT3SAS_FMT "PCI error: detected callback, state(%d)!!\n", | |
10727 | ioc->name, state); | |
10728 | ||
10729 | switch (state) { | |
10730 | case pci_channel_io_normal: | |
10731 | return PCI_ERS_RESULT_CAN_RECOVER; | |
10732 | case pci_channel_io_frozen: | |
10733 | /* Fatal error, prepare for slot reset */ | |
10734 | ioc->pci_error_recovery = 1; | |
10735 | scsi_block_requests(ioc->shost); | |
10736 | mpt3sas_base_stop_watchdog(ioc); | |
10737 | mpt3sas_base_free_resources(ioc); | |
10738 | return PCI_ERS_RESULT_NEED_RESET; | |
10739 | case pci_channel_io_perm_failure: | |
10740 | /* Permanent error, prepare for device removal */ | |
10741 | ioc->pci_error_recovery = 1; | |
10742 | mpt3sas_base_stop_watchdog(ioc); | |
10743 | _scsih_flush_running_cmds(ioc); | |
10744 | return PCI_ERS_RESULT_DISCONNECT; | |
10745 | } | |
10746 | return PCI_ERS_RESULT_NEED_RESET; | |
10747 | } | |
10748 | ||
10749 | /** | |
8a7e4c24 | 10750 | * scsih_pci_slot_reset - Called when PCI slot has been reset. |
f92363d1 SR |
10751 | * @pdev: PCI device struct |
10752 | * | |
10753 | * Description: This routine is called by the pci error recovery | |
10754 | * code after the PCI slot has been reset, just before we | |
10755 | * should resume normal operations. | |
10756 | */ | |
8bbb1cf6 | 10757 | static pci_ers_result_t |
8a7e4c24 | 10758 | scsih_pci_slot_reset(struct pci_dev *pdev) |
f92363d1 SR |
10759 | { |
10760 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10761 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10762 | int rc; | |
10763 | ||
10764 | pr_info(MPT3SAS_FMT "PCI error: slot reset callback!!\n", | |
10765 | ioc->name); | |
10766 | ||
10767 | ioc->pci_error_recovery = 0; | |
10768 | ioc->pdev = pdev; | |
10769 | pci_restore_state(pdev); | |
10770 | rc = mpt3sas_base_map_resources(ioc); | |
10771 | if (rc) | |
10772 | return PCI_ERS_RESULT_DISCONNECT; | |
10773 | ||
98c56ad3 | 10774 | rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
f92363d1 SR |
10775 | |
10776 | pr_warn(MPT3SAS_FMT "hard reset: %s\n", ioc->name, | |
10777 | (rc == 0) ? "success" : "failed"); | |
10778 | ||
10779 | if (!rc) | |
10780 | return PCI_ERS_RESULT_RECOVERED; | |
10781 | else | |
10782 | return PCI_ERS_RESULT_DISCONNECT; | |
10783 | } | |
10784 | ||
10785 | /** | |
8a7e4c24 | 10786 | * scsih_pci_resume() - resume normal ops after PCI reset |
f92363d1 SR |
10787 | * @pdev: pointer to PCI device |
10788 | * | |
10789 | * Called when the error recovery driver tells us that its | |
10790 | * OK to resume normal operation. Use completion to allow | |
10791 | * halted scsi ops to resume. | |
10792 | */ | |
8bbb1cf6 | 10793 | static void |
8a7e4c24 | 10794 | scsih_pci_resume(struct pci_dev *pdev) |
f92363d1 SR |
10795 | { |
10796 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10797 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10798 | ||
10799 | pr_info(MPT3SAS_FMT "PCI error: resume callback!!\n", ioc->name); | |
10800 | ||
10801 | pci_cleanup_aer_uncorrect_error_status(pdev); | |
10802 | mpt3sas_base_start_watchdog(ioc); | |
10803 | scsi_unblock_requests(ioc->shost); | |
10804 | } | |
10805 | ||
10806 | /** | |
8a7e4c24 | 10807 | * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers |
f92363d1 SR |
10808 | * @pdev: pointer to PCI device |
10809 | */ | |
8bbb1cf6 | 10810 | static pci_ers_result_t |
8a7e4c24 | 10811 | scsih_pci_mmio_enabled(struct pci_dev *pdev) |
f92363d1 SR |
10812 | { |
10813 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10814 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10815 | ||
10816 | pr_info(MPT3SAS_FMT "PCI error: mmio enabled callback!!\n", | |
10817 | ioc->name); | |
10818 | ||
10819 | /* TODO - dump whatever for debugging purposes */ | |
10820 | ||
83c3d340 KW |
10821 | /* This called only if scsih_pci_error_detected returns |
10822 | * PCI_ERS_RESULT_CAN_RECOVER. Read/write to the device still | |
10823 | * works, no need to reset slot. | |
10824 | */ | |
10825 | return PCI_ERS_RESULT_RECOVERED; | |
f92363d1 SR |
10826 | } |
10827 | ||
307d9075 AM |
10828 | /** |
10829 | * scsih__ncq_prio_supp - Check for NCQ command priority support | |
10830 | * @sdev: scsi device struct | |
10831 | * | |
10832 | * This is called when a user indicates they would like to enable | |
10833 | * ncq command priorities. This works only on SATA devices. | |
10834 | */ | |
10835 | bool scsih_ncq_prio_supp(struct scsi_device *sdev) | |
10836 | { | |
10837 | unsigned char *buf; | |
10838 | bool ncq_prio_supp = false; | |
10839 | ||
10840 | if (!scsi_device_supports_vpd(sdev)) | |
10841 | return ncq_prio_supp; | |
10842 | ||
10843 | buf = kmalloc(SCSI_VPD_PG_LEN, GFP_KERNEL); | |
10844 | if (!buf) | |
10845 | return ncq_prio_supp; | |
10846 | ||
10847 | if (!scsi_get_vpd_page(sdev, 0x89, buf, SCSI_VPD_PG_LEN)) | |
10848 | ncq_prio_supp = (buf[213] >> 4) & 1; | |
10849 | ||
10850 | kfree(buf); | |
10851 | return ncq_prio_supp; | |
10852 | } | |
c84b06a4 SR |
10853 | /* |
10854 | * The pci device ids are defined in mpi/mpi2_cnfg.h. | |
10855 | */ | |
10856 | static const struct pci_device_id mpt3sas_pci_table[] = { | |
10857 | /* Spitfire ~ 2004 */ | |
10858 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004, | |
10859 | PCI_ANY_ID, PCI_ANY_ID }, | |
10860 | /* Falcon ~ 2008 */ | |
10861 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008, | |
10862 | PCI_ANY_ID, PCI_ANY_ID }, | |
10863 | /* Liberator ~ 2108 */ | |
10864 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1, | |
10865 | PCI_ANY_ID, PCI_ANY_ID }, | |
10866 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2, | |
10867 | PCI_ANY_ID, PCI_ANY_ID }, | |
10868 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3, | |
10869 | PCI_ANY_ID, PCI_ANY_ID }, | |
10870 | /* Meteor ~ 2116 */ | |
10871 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1, | |
10872 | PCI_ANY_ID, PCI_ANY_ID }, | |
10873 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2, | |
10874 | PCI_ANY_ID, PCI_ANY_ID }, | |
10875 | /* Thunderbolt ~ 2208 */ | |
10876 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1, | |
10877 | PCI_ANY_ID, PCI_ANY_ID }, | |
10878 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2, | |
10879 | PCI_ANY_ID, PCI_ANY_ID }, | |
10880 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3, | |
10881 | PCI_ANY_ID, PCI_ANY_ID }, | |
10882 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4, | |
10883 | PCI_ANY_ID, PCI_ANY_ID }, | |
10884 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5, | |
10885 | PCI_ANY_ID, PCI_ANY_ID }, | |
10886 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6, | |
10887 | PCI_ANY_ID, PCI_ANY_ID }, | |
10888 | /* Mustang ~ 2308 */ | |
10889 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1, | |
10890 | PCI_ANY_ID, PCI_ANY_ID }, | |
10891 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2, | |
10892 | PCI_ANY_ID, PCI_ANY_ID }, | |
10893 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3, | |
10894 | PCI_ANY_ID, PCI_ANY_ID }, | |
10895 | /* SSS6200 */ | |
10896 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200, | |
10897 | PCI_ANY_ID, PCI_ANY_ID }, | |
10898 | /* Fury ~ 3004 and 3008 */ | |
10899 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3004, | |
10900 | PCI_ANY_ID, PCI_ANY_ID }, | |
10901 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3008, | |
10902 | PCI_ANY_ID, PCI_ANY_ID }, | |
10903 | /* Invader ~ 3108 */ | |
10904 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_1, | |
10905 | PCI_ANY_ID, PCI_ANY_ID }, | |
10906 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_2, | |
10907 | PCI_ANY_ID, PCI_ANY_ID }, | |
10908 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_5, | |
10909 | PCI_ANY_ID, PCI_ANY_ID }, | |
10910 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_6, | |
10911 | PCI_ANY_ID, PCI_ANY_ID }, | |
b130b0d5 SS |
10912 | /* Cutlass ~ 3216 and 3224 */ |
10913 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3216, | |
10914 | PCI_ANY_ID, PCI_ANY_ID }, | |
10915 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3224, | |
10916 | PCI_ANY_ID, PCI_ANY_ID }, | |
10917 | /* Intruder ~ 3316 and 3324 */ | |
10918 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_1, | |
10919 | PCI_ANY_ID, PCI_ANY_ID }, | |
10920 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_2, | |
10921 | PCI_ANY_ID, PCI_ANY_ID }, | |
10922 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_3, | |
10923 | PCI_ANY_ID, PCI_ANY_ID }, | |
10924 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_4, | |
10925 | PCI_ANY_ID, PCI_ANY_ID }, | |
10926 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_1, | |
10927 | PCI_ANY_ID, PCI_ANY_ID }, | |
10928 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_2, | |
10929 | PCI_ANY_ID, PCI_ANY_ID }, | |
10930 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_3, | |
10931 | PCI_ANY_ID, PCI_ANY_ID }, | |
10932 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_4, | |
10933 | PCI_ANY_ID, PCI_ANY_ID }, | |
998f26ae SPS |
10934 | /* Ventura, Crusader, Harpoon & Tomcat ~ 3516, 3416, 3508 & 3408*/ |
10935 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3508, | |
10936 | PCI_ANY_ID, PCI_ANY_ID }, | |
10937 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3508_1, | |
10938 | PCI_ANY_ID, PCI_ANY_ID }, | |
10939 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3408, | |
10940 | PCI_ANY_ID, PCI_ANY_ID }, | |
10941 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3516, | |
10942 | PCI_ANY_ID, PCI_ANY_ID }, | |
10943 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3516_1, | |
10944 | PCI_ANY_ID, PCI_ANY_ID }, | |
10945 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3416, | |
10946 | PCI_ANY_ID, PCI_ANY_ID }, | |
15fd7c74 SR |
10947 | /* Mercator ~ 3616*/ |
10948 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3616, | |
10949 | PCI_ANY_ID, PCI_ANY_ID }, | |
c84b06a4 SR |
10950 | {0} /* Terminating entry */ |
10951 | }; | |
10952 | MODULE_DEVICE_TABLE(pci, mpt3sas_pci_table); | |
10953 | ||
10954 | static struct pci_error_handlers _mpt3sas_err_handler = { | |
10955 | .error_detected = scsih_pci_error_detected, | |
10956 | .mmio_enabled = scsih_pci_mmio_enabled, | |
10957 | .slot_reset = scsih_pci_slot_reset, | |
10958 | .resume = scsih_pci_resume, | |
10959 | }; | |
10960 | ||
10961 | static struct pci_driver mpt3sas_driver = { | |
10962 | .name = MPT3SAS_DRIVER_NAME, | |
10963 | .id_table = mpt3sas_pci_table, | |
10964 | .probe = _scsih_probe, | |
10965 | .remove = scsih_remove, | |
10966 | .shutdown = scsih_shutdown, | |
10967 | .err_handler = &_mpt3sas_err_handler, | |
10968 | #ifdef CONFIG_PM | |
10969 | .suspend = scsih_suspend, | |
10970 | .resume = scsih_resume, | |
10971 | #endif | |
10972 | }; | |
10973 | ||
f92363d1 | 10974 | /** |
8a7e4c24 | 10975 | * scsih_init - main entry point for this driver. |
f92363d1 SR |
10976 | * |
10977 | * Returns 0 success, anything else error. | |
10978 | */ | |
8bbb1cf6 | 10979 | static int |
8a7e4c24 | 10980 | scsih_init(void) |
f92363d1 | 10981 | { |
c84b06a4 SR |
10982 | mpt2_ids = 0; |
10983 | mpt3_ids = 0; | |
f92363d1 | 10984 | |
f92363d1 SR |
10985 | mpt3sas_base_initialize_callback_handler(); |
10986 | ||
10987 | /* queuecommand callback hander */ | |
10988 | scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done); | |
10989 | ||
6c7abffc | 10990 | /* task management callback handler */ |
f92363d1 SR |
10991 | tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done); |
10992 | ||
10993 | /* base internal commands callback handler */ | |
10994 | base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done); | |
10995 | port_enable_cb_idx = mpt3sas_base_register_callback_handler( | |
10996 | mpt3sas_port_enable_done); | |
10997 | ||
10998 | /* transport internal commands callback handler */ | |
10999 | transport_cb_idx = mpt3sas_base_register_callback_handler( | |
11000 | mpt3sas_transport_done); | |
11001 | ||
11002 | /* scsih internal commands callback handler */ | |
11003 | scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done); | |
11004 | ||
11005 | /* configuration page API internal commands callback handler */ | |
11006 | config_cb_idx = mpt3sas_base_register_callback_handler( | |
11007 | mpt3sas_config_done); | |
11008 | ||
11009 | /* ctl module callback handler */ | |
11010 | ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done); | |
11011 | ||
11012 | tm_tr_cb_idx = mpt3sas_base_register_callback_handler( | |
11013 | _scsih_tm_tr_complete); | |
11014 | ||
11015 | tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler( | |
11016 | _scsih_tm_volume_tr_complete); | |
11017 | ||
11018 | tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler( | |
11019 | _scsih_sas_control_complete); | |
11020 | ||
7497392a | 11021 | return 0; |
f92363d1 SR |
11022 | } |
11023 | ||
11024 | /** | |
7497392a | 11025 | * scsih_exit - exit point for this driver (when it is a module). |
f92363d1 SR |
11026 | * |
11027 | * Returns 0 success, anything else error. | |
11028 | */ | |
8bbb1cf6 | 11029 | static void |
8a7e4c24 | 11030 | scsih_exit(void) |
f92363d1 | 11031 | { |
f92363d1 SR |
11032 | |
11033 | mpt3sas_base_release_callback_handler(scsi_io_cb_idx); | |
11034 | mpt3sas_base_release_callback_handler(tm_cb_idx); | |
11035 | mpt3sas_base_release_callback_handler(base_cb_idx); | |
11036 | mpt3sas_base_release_callback_handler(port_enable_cb_idx); | |
11037 | mpt3sas_base_release_callback_handler(transport_cb_idx); | |
11038 | mpt3sas_base_release_callback_handler(scsih_cb_idx); | |
11039 | mpt3sas_base_release_callback_handler(config_cb_idx); | |
11040 | mpt3sas_base_release_callback_handler(ctl_cb_idx); | |
11041 | ||
11042 | mpt3sas_base_release_callback_handler(tm_tr_cb_idx); | |
11043 | mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx); | |
11044 | mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx); | |
11045 | ||
11046 | /* raid transport support */ | |
c84b06a4 SR |
11047 | if (hbas_to_enumerate != 1) |
11048 | raid_class_release(mpt3sas_raid_template); | |
11049 | if (hbas_to_enumerate != 2) | |
11050 | raid_class_release(mpt2sas_raid_template); | |
f92363d1 SR |
11051 | sas_release_transport(mpt3sas_transport_template); |
11052 | } | |
7786ab6a | 11053 | |
c84b06a4 SR |
11054 | /** |
11055 | * _mpt3sas_init - main entry point for this driver. | |
11056 | * | |
11057 | * Returns 0 success, anything else error. | |
11058 | */ | |
11059 | static int __init | |
11060 | _mpt3sas_init(void) | |
11061 | { | |
11062 | int error; | |
11063 | ||
11064 | pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME, | |
11065 | MPT3SAS_DRIVER_VERSION); | |
11066 | ||
11067 | mpt3sas_transport_template = | |
11068 | sas_attach_transport(&mpt3sas_transport_functions); | |
11069 | if (!mpt3sas_transport_template) | |
11070 | return -ENODEV; | |
11071 | ||
11072 | /* No need attach mpt3sas raid functions template | |
11073 | * if hbas_to_enumarate value is one. | |
11074 | */ | |
11075 | if (hbas_to_enumerate != 1) { | |
11076 | mpt3sas_raid_template = | |
11077 | raid_class_attach(&mpt3sas_raid_functions); | |
11078 | if (!mpt3sas_raid_template) { | |
11079 | sas_release_transport(mpt3sas_transport_template); | |
11080 | return -ENODEV; | |
11081 | } | |
11082 | } | |
11083 | ||
11084 | /* No need to attach mpt2sas raid functions template | |
11085 | * if hbas_to_enumarate value is two | |
11086 | */ | |
11087 | if (hbas_to_enumerate != 2) { | |
11088 | mpt2sas_raid_template = | |
11089 | raid_class_attach(&mpt2sas_raid_functions); | |
11090 | if (!mpt2sas_raid_template) { | |
11091 | sas_release_transport(mpt3sas_transport_template); | |
11092 | return -ENODEV; | |
11093 | } | |
11094 | } | |
11095 | ||
11096 | error = scsih_init(); | |
11097 | if (error) { | |
11098 | scsih_exit(); | |
11099 | return error; | |
11100 | } | |
11101 | ||
11102 | mpt3sas_ctl_init(hbas_to_enumerate); | |
11103 | ||
11104 | error = pci_register_driver(&mpt3sas_driver); | |
11105 | if (error) | |
11106 | scsih_exit(); | |
11107 | ||
11108 | return error; | |
11109 | } | |
11110 | ||
11111 | /** | |
11112 | * _mpt3sas_exit - exit point for this driver (when it is a module). | |
11113 | * | |
11114 | */ | |
11115 | static void __exit | |
11116 | _mpt3sas_exit(void) | |
11117 | { | |
11118 | pr_info("mpt3sas version %s unloading\n", | |
11119 | MPT3SAS_DRIVER_VERSION); | |
11120 | ||
11121 | pci_unregister_driver(&mpt3sas_driver); | |
11122 | ||
11123 | mpt3sas_ctl_exit(hbas_to_enumerate); | |
11124 | ||
11125 | scsih_exit(); | |
11126 | } | |
11127 | ||
11128 | module_init(_mpt3sas_init); | |
11129 | module_exit(_mpt3sas_exit); |