]>
Commit | Line | Data |
---|---|---|
f92363d1 SR |
1 | /* |
2 | * Scsi Host Layer for MPT (Message Passing Technology) based controllers | |
3 | * | |
4 | * This code is based on drivers/scsi/mpt3sas/mpt3sas_scsih.c | |
a4ffce0d | 5 | * Copyright (C) 2012-2014 LSI Corporation |
a03bd153 SR |
6 | * Copyright (C) 2013-2014 Avago Technologies |
7 | * (mailto: MPT-FusionLinux.pdl@avagotech.com) | |
f92363d1 SR |
8 | * |
9 | * This program is free software; you can redistribute it and/or | |
10 | * modify it under the terms of the GNU General Public License | |
11 | * as published by the Free Software Foundation; either version 2 | |
12 | * of the License, or (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * NO WARRANTY | |
20 | * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR | |
21 | * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT | |
22 | * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, | |
23 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is | |
24 | * solely responsible for determining the appropriateness of using and | |
25 | * distributing the Program and assumes all risks associated with its | |
26 | * exercise of rights under this Agreement, including but not limited to | |
27 | * the risks and costs of program errors, damage to or loss of data, | |
28 | * programs or equipment, and unavailability or interruption of operations. | |
29 | ||
30 | * DISCLAIMER OF LIABILITY | |
31 | * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY | |
32 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
33 | * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND | |
34 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | |
35 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
36 | * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED | |
37 | * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES | |
38 | ||
39 | * You should have received a copy of the GNU General Public License | |
40 | * along with this program; if not, write to the Free Software | |
41 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | |
42 | * USA. | |
43 | */ | |
44 | ||
f92363d1 SR |
45 | #include <linux/module.h> |
46 | #include <linux/kernel.h> | |
47 | #include <linux/init.h> | |
48 | #include <linux/errno.h> | |
49 | #include <linux/blkdev.h> | |
50 | #include <linux/sched.h> | |
51 | #include <linux/workqueue.h> | |
52 | #include <linux/delay.h> | |
53 | #include <linux/pci.h> | |
54 | #include <linux/interrupt.h> | |
55 | #include <linux/aer.h> | |
56 | #include <linux/raid_class.h> | |
7786ab6a | 57 | #include <asm/unaligned.h> |
f92363d1 SR |
58 | |
59 | #include "mpt3sas_base.h" | |
60 | ||
f92363d1 | 61 | #define RAID_CHANNEL 1 |
d88e1eab SPS |
62 | |
63 | #define PCIE_CHANNEL 2 | |
64 | ||
f92363d1 SR |
65 | /* forward proto's */ |
66 | static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc, | |
67 | struct _sas_node *sas_expander); | |
68 | static void _firmware_event_work(struct work_struct *work); | |
69 | ||
70 | static void _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc, | |
71 | struct _sas_device *sas_device); | |
72 | static int _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, | |
73 | u8 retry_count, u8 is_pd); | |
c102e00c | 74 | static int _scsih_pcie_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle); |
3075ac49 SPS |
75 | static void _scsih_pcie_device_remove_from_sml(struct MPT3SAS_ADAPTER *ioc, |
76 | struct _pcie_device *pcie_device); | |
4318c734 SPS |
77 | static void |
78 | _scsih_pcie_check_device(struct MPT3SAS_ADAPTER *ioc, u16 handle); | |
f92363d1 SR |
79 | static u8 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid); |
80 | ||
f92363d1 SR |
81 | /* global parameters */ |
82 | LIST_HEAD(mpt3sas_ioc_list); | |
08c4d550 SR |
83 | /* global ioc lock for list operations */ |
84 | DEFINE_SPINLOCK(gioc_lock); | |
f92363d1 | 85 | |
c84b06a4 SR |
86 | MODULE_AUTHOR(MPT3SAS_AUTHOR); |
87 | MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION); | |
88 | MODULE_LICENSE("GPL"); | |
89 | MODULE_VERSION(MPT3SAS_DRIVER_VERSION); | |
90 | MODULE_ALIAS("mpt2sas"); | |
91 | ||
f92363d1 SR |
92 | /* local parameters */ |
93 | static u8 scsi_io_cb_idx = -1; | |
94 | static u8 tm_cb_idx = -1; | |
95 | static u8 ctl_cb_idx = -1; | |
96 | static u8 base_cb_idx = -1; | |
97 | static u8 port_enable_cb_idx = -1; | |
98 | static u8 transport_cb_idx = -1; | |
99 | static u8 scsih_cb_idx = -1; | |
100 | static u8 config_cb_idx = -1; | |
c84b06a4 SR |
101 | static int mpt2_ids; |
102 | static int mpt3_ids; | |
f92363d1 SR |
103 | |
104 | static u8 tm_tr_cb_idx = -1 ; | |
105 | static u8 tm_tr_volume_cb_idx = -1 ; | |
106 | static u8 tm_sas_control_cb_idx = -1; | |
107 | ||
108 | /* command line options */ | |
109 | static u32 logging_level; | |
110 | MODULE_PARM_DESC(logging_level, | |
111 | " bits for enabling additional logging info (default=0)"); | |
112 | ||
113 | ||
114 | static ushort max_sectors = 0xFFFF; | |
ab9f5adb | 115 | module_param(max_sectors, ushort, 0444); |
f92363d1 SR |
116 | MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767"); |
117 | ||
118 | ||
119 | static int missing_delay[2] = {-1, -1}; | |
ab9f5adb | 120 | module_param_array(missing_delay, int, NULL, 0444); |
f92363d1 SR |
121 | MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay"); |
122 | ||
123 | /* scsi-mid layer global parmeter is max_report_luns, which is 511 */ | |
124 | #define MPT3SAS_MAX_LUN (16895) | |
1abf635d | 125 | static u64 max_lun = MPT3SAS_MAX_LUN; |
ab9f5adb | 126 | module_param(max_lun, ullong, 0444); |
f92363d1 SR |
127 | MODULE_PARM_DESC(max_lun, " max lun, default=16895 "); |
128 | ||
c84b06a4 | 129 | static ushort hbas_to_enumerate; |
ab9f5adb | 130 | module_param(hbas_to_enumerate, ushort, 0444); |
c84b06a4 SR |
131 | MODULE_PARM_DESC(hbas_to_enumerate, |
132 | " 0 - enumerates both SAS 2.0 & SAS 3.0 generation HBAs\n \ | |
133 | 1 - enumerates only SAS 2.0 generation HBAs\n \ | |
134 | 2 - enumerates only SAS 3.0 generation HBAs (default=0)"); | |
f92363d1 SR |
135 | |
136 | /* diag_buffer_enable is bitwise | |
137 | * bit 0 set = TRACE | |
138 | * bit 1 set = SNAPSHOT | |
139 | * bit 2 set = EXTENDED | |
140 | * | |
141 | * Either bit can be set, or both | |
142 | */ | |
143 | static int diag_buffer_enable = -1; | |
ab9f5adb | 144 | module_param(diag_buffer_enable, int, 0444); |
f92363d1 SR |
145 | MODULE_PARM_DESC(diag_buffer_enable, |
146 | " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)"); | |
147 | static int disable_discovery = -1; | |
ab9f5adb | 148 | module_param(disable_discovery, int, 0444); |
f92363d1 SR |
149 | MODULE_PARM_DESC(disable_discovery, " disable discovery "); |
150 | ||
151 | ||
152 | /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */ | |
153 | static int prot_mask = -1; | |
ab9f5adb | 154 | module_param(prot_mask, int, 0444); |
f92363d1 SR |
155 | MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 "); |
156 | ||
8dc8d29a SR |
157 | static bool enable_sdev_max_qd; |
158 | module_param(enable_sdev_max_qd, bool, 0444); | |
159 | MODULE_PARM_DESC(enable_sdev_max_qd, | |
160 | "Enable sdev max qd as can_queue, def=disabled(0)"); | |
f92363d1 SR |
161 | |
162 | /* raid transport support */ | |
cf6bf971 C |
163 | static struct raid_template *mpt3sas_raid_template; |
164 | static struct raid_template *mpt2sas_raid_template; | |
f92363d1 SR |
165 | |
166 | ||
167 | /** | |
168 | * struct sense_info - common structure for obtaining sense keys | |
169 | * @skey: sense key | |
170 | * @asc: additional sense code | |
171 | * @ascq: additional sense code qualifier | |
172 | */ | |
173 | struct sense_info { | |
174 | u8 skey; | |
175 | u8 asc; | |
176 | u8 ascq; | |
177 | }; | |
178 | ||
179 | #define MPT3SAS_PROCESS_TRIGGER_DIAG (0xFFFB) | |
0f624c39 | 180 | #define MPT3SAS_TURN_ON_PFA_LED (0xFFFC) |
f92363d1 SR |
181 | #define MPT3SAS_PORT_ENABLE_COMPLETE (0xFFFD) |
182 | #define MPT3SAS_ABRT_TASK_SET (0xFFFE) | |
183 | #define MPT3SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF) | |
184 | /** | |
185 | * struct fw_event_work - firmware event struct | |
186 | * @list: link list framework | |
187 | * @work: work object (ioc->fault_reset_work_q) | |
f92363d1 SR |
188 | * @ioc: per adapter object |
189 | * @device_handle: device handle | |
190 | * @VF_ID: virtual function id | |
191 | * @VP_ID: virtual port id | |
192 | * @ignore: flag meaning this event has been marked to ignore | |
b8ac0cc7 JL |
193 | * @event: firmware event MPI2_EVENT_XXX defined in mpi2_ioc.h |
194 | * @refcount: kref for this event | |
f92363d1 SR |
195 | * @event_data: reply event data payload follows |
196 | * | |
197 | * This object stored on ioc->fw_event_list. | |
198 | */ | |
199 | struct fw_event_work { | |
200 | struct list_head list; | |
201 | struct work_struct work; | |
f92363d1 SR |
202 | |
203 | struct MPT3SAS_ADAPTER *ioc; | |
204 | u16 device_handle; | |
205 | u8 VF_ID; | |
206 | u8 VP_ID; | |
207 | u8 ignore; | |
208 | u16 event; | |
146b16c8 | 209 | struct kref refcount; |
35b62362 | 210 | char event_data[0] __aligned(4); |
f92363d1 SR |
211 | }; |
212 | ||
146b16c8 SR |
213 | static void fw_event_work_free(struct kref *r) |
214 | { | |
215 | kfree(container_of(r, struct fw_event_work, refcount)); | |
216 | } | |
217 | ||
218 | static void fw_event_work_get(struct fw_event_work *fw_work) | |
219 | { | |
220 | kref_get(&fw_work->refcount); | |
221 | } | |
222 | ||
223 | static void fw_event_work_put(struct fw_event_work *fw_work) | |
224 | { | |
225 | kref_put(&fw_work->refcount, fw_event_work_free); | |
226 | } | |
227 | ||
228 | static struct fw_event_work *alloc_fw_event_work(int len) | |
229 | { | |
230 | struct fw_event_work *fw_event; | |
231 | ||
232 | fw_event = kzalloc(sizeof(*fw_event) + len, GFP_ATOMIC); | |
233 | if (!fw_event) | |
234 | return NULL; | |
235 | ||
236 | kref_init(&fw_event->refcount); | |
237 | return fw_event; | |
238 | } | |
239 | ||
f92363d1 SR |
240 | /** |
241 | * struct _scsi_io_transfer - scsi io transfer | |
242 | * @handle: sas device handle (assigned by firmware) | |
243 | * @is_raid: flag set for hidden raid components | |
244 | * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE, | |
245 | * @data_length: data transfer length | |
246 | * @data_dma: dma pointer to data | |
247 | * @sense: sense data | |
248 | * @lun: lun number | |
249 | * @cdb_length: cdb length | |
250 | * @cdb: cdb contents | |
251 | * @timeout: timeout for this command | |
252 | * @VF_ID: virtual function id | |
253 | * @VP_ID: virtual port id | |
254 | * @valid_reply: flag set for reply message | |
255 | * @sense_length: sense length | |
256 | * @ioc_status: ioc status | |
257 | * @scsi_state: scsi state | |
258 | * @scsi_status: scsi staus | |
259 | * @log_info: log information | |
260 | * @transfer_length: data length transfer when there is a reply message | |
261 | * | |
262 | * Used for sending internal scsi commands to devices within this module. | |
263 | * Refer to _scsi_send_scsi_io(). | |
264 | */ | |
265 | struct _scsi_io_transfer { | |
266 | u16 handle; | |
267 | u8 is_raid; | |
268 | enum dma_data_direction dir; | |
269 | u32 data_length; | |
270 | dma_addr_t data_dma; | |
271 | u8 sense[SCSI_SENSE_BUFFERSIZE]; | |
272 | u32 lun; | |
273 | u8 cdb_length; | |
274 | u8 cdb[32]; | |
275 | u8 timeout; | |
276 | u8 VF_ID; | |
277 | u8 VP_ID; | |
278 | u8 valid_reply; | |
279 | /* the following bits are only valid when 'valid_reply = 1' */ | |
280 | u32 sense_length; | |
281 | u16 ioc_status; | |
282 | u8 scsi_state; | |
283 | u8 scsi_status; | |
284 | u32 log_info; | |
285 | u32 transfer_length; | |
286 | }; | |
287 | ||
f92363d1 SR |
288 | /** |
289 | * _scsih_set_debug_level - global setting of ioc->logging_level. | |
4beb4867 BVA |
290 | * @val: ? |
291 | * @kp: ? | |
f92363d1 SR |
292 | * |
293 | * Note: The logging levels are defined in mpt3sas_debug.h. | |
294 | */ | |
295 | static int | |
e4dca7b7 | 296 | _scsih_set_debug_level(const char *val, const struct kernel_param *kp) |
f92363d1 SR |
297 | { |
298 | int ret = param_set_int(val, kp); | |
299 | struct MPT3SAS_ADAPTER *ioc; | |
300 | ||
301 | if (ret) | |
302 | return ret; | |
303 | ||
304 | pr_info("setting logging_level(0x%08x)\n", logging_level); | |
08c4d550 | 305 | spin_lock(&gioc_lock); |
f92363d1 SR |
306 | list_for_each_entry(ioc, &mpt3sas_ioc_list, list) |
307 | ioc->logging_level = logging_level; | |
08c4d550 | 308 | spin_unlock(&gioc_lock); |
f92363d1 SR |
309 | return 0; |
310 | } | |
311 | module_param_call(logging_level, _scsih_set_debug_level, param_get_int, | |
312 | &logging_level, 0644); | |
313 | ||
314 | /** | |
315 | * _scsih_srch_boot_sas_address - search based on sas_address | |
316 | * @sas_address: sas address | |
317 | * @boot_device: boot device object from bios page 2 | |
318 | * | |
4beb4867 | 319 | * Return: 1 when there's a match, 0 means no match. |
f92363d1 SR |
320 | */ |
321 | static inline int | |
322 | _scsih_srch_boot_sas_address(u64 sas_address, | |
323 | Mpi2BootDeviceSasWwid_t *boot_device) | |
324 | { | |
325 | return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0; | |
326 | } | |
327 | ||
328 | /** | |
329 | * _scsih_srch_boot_device_name - search based on device name | |
330 | * @device_name: device name specified in INDENTIFY fram | |
331 | * @boot_device: boot device object from bios page 2 | |
332 | * | |
4beb4867 | 333 | * Return: 1 when there's a match, 0 means no match. |
f92363d1 SR |
334 | */ |
335 | static inline int | |
336 | _scsih_srch_boot_device_name(u64 device_name, | |
337 | Mpi2BootDeviceDeviceName_t *boot_device) | |
338 | { | |
339 | return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0; | |
340 | } | |
341 | ||
342 | /** | |
343 | * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot | |
344 | * @enclosure_logical_id: enclosure logical id | |
345 | * @slot_number: slot number | |
346 | * @boot_device: boot device object from bios page 2 | |
347 | * | |
4beb4867 | 348 | * Return: 1 when there's a match, 0 means no match. |
f92363d1 SR |
349 | */ |
350 | static inline int | |
351 | _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number, | |
352 | Mpi2BootDeviceEnclosureSlot_t *boot_device) | |
353 | { | |
354 | return (enclosure_logical_id == le64_to_cpu(boot_device-> | |
355 | EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device-> | |
356 | SlotNumber)) ? 1 : 0; | |
357 | } | |
358 | ||
b326db46 SR |
359 | /** |
360 | * mpt3sas_get_port_by_id - get hba port entry corresponding to provided | |
361 | * port number from port list | |
362 | * @ioc: per adapter object | |
363 | * @port_id: port number | |
364 | * | |
365 | * Search for hba port entry corresponding to provided port number, | |
366 | * if available return port object otherwise return NULL. | |
367 | */ | |
368 | struct hba_port * | |
369 | mpt3sas_get_port_by_id(struct MPT3SAS_ADAPTER *ioc, u8 port_id) | |
370 | { | |
371 | struct hba_port *port, *port_next; | |
372 | ||
373 | list_for_each_entry_safe(port, port_next, | |
374 | &ioc->port_table_list, list) { | |
375 | if (port->port_id == port_id && | |
376 | !(port->flags & HBA_PORT_FLAG_DIRTY_PORT)) | |
377 | return port; | |
378 | } | |
379 | ||
380 | return NULL; | |
381 | } | |
382 | ||
f92363d1 SR |
383 | /** |
384 | * _scsih_is_boot_device - search for matching boot device. | |
385 | * @sas_address: sas address | |
386 | * @device_name: device name specified in INDENTIFY fram | |
387 | * @enclosure_logical_id: enclosure logical id | |
4beb4867 | 388 | * @slot: slot number |
f92363d1 SR |
389 | * @form: specifies boot device form |
390 | * @boot_device: boot device object from bios page 2 | |
391 | * | |
4beb4867 | 392 | * Return: 1 when there's a match, 0 means no match. |
f92363d1 SR |
393 | */ |
394 | static int | |
395 | _scsih_is_boot_device(u64 sas_address, u64 device_name, | |
396 | u64 enclosure_logical_id, u16 slot, u8 form, | |
397 | Mpi2BiosPage2BootDevice_t *boot_device) | |
398 | { | |
399 | int rc = 0; | |
400 | ||
401 | switch (form) { | |
402 | case MPI2_BIOSPAGE2_FORM_SAS_WWID: | |
403 | if (!sas_address) | |
404 | break; | |
405 | rc = _scsih_srch_boot_sas_address( | |
406 | sas_address, &boot_device->SasWwid); | |
407 | break; | |
408 | case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT: | |
409 | if (!enclosure_logical_id) | |
410 | break; | |
411 | rc = _scsih_srch_boot_encl_slot( | |
412 | enclosure_logical_id, | |
413 | slot, &boot_device->EnclosureSlot); | |
414 | break; | |
415 | case MPI2_BIOSPAGE2_FORM_DEVICE_NAME: | |
416 | if (!device_name) | |
417 | break; | |
418 | rc = _scsih_srch_boot_device_name( | |
419 | device_name, &boot_device->DeviceName); | |
420 | break; | |
421 | case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED: | |
422 | break; | |
423 | } | |
424 | ||
425 | return rc; | |
426 | } | |
427 | ||
428 | /** | |
429 | * _scsih_get_sas_address - set the sas_address for given device handle | |
4beb4867 | 430 | * @ioc: ? |
f92363d1 SR |
431 | * @handle: device handle |
432 | * @sas_address: sas address | |
433 | * | |
4beb4867 | 434 | * Return: 0 success, non-zero when failure |
f92363d1 SR |
435 | */ |
436 | static int | |
437 | _scsih_get_sas_address(struct MPT3SAS_ADAPTER *ioc, u16 handle, | |
438 | u64 *sas_address) | |
439 | { | |
440 | Mpi2SasDevicePage0_t sas_device_pg0; | |
441 | Mpi2ConfigReply_t mpi_reply; | |
442 | u32 ioc_status; | |
443 | ||
444 | *sas_address = 0; | |
445 | ||
f92363d1 SR |
446 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
447 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
919d8a3f JP |
448 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
449 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
450 | return -ENXIO; |
451 | } | |
452 | ||
453 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
454 | if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { | |
758f8139 SR |
455 | /* For HBA, vSES doesn't return HBA SAS address. Instead return |
456 | * vSES's sas address. | |
457 | */ | |
458 | if ((handle <= ioc->sas_hba.num_phys) && | |
459 | (!(le32_to_cpu(sas_device_pg0.DeviceInfo) & | |
460 | MPI2_SAS_DEVICE_INFO_SEP))) | |
461 | *sas_address = ioc->sas_hba.sas_address; | |
462 | else | |
463 | *sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | |
f92363d1 SR |
464 | return 0; |
465 | } | |
466 | ||
6c7abffc | 467 | /* we hit this because the given parent handle doesn't exist */ |
f92363d1 SR |
468 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
469 | return -ENXIO; | |
470 | ||
471 | /* else error case */ | |
919d8a3f JP |
472 | ioc_err(ioc, "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n", |
473 | handle, ioc_status, __FILE__, __LINE__, __func__); | |
f92363d1 SR |
474 | return -EIO; |
475 | } | |
476 | ||
477 | /** | |
478 | * _scsih_determine_boot_device - determine boot device. | |
479 | * @ioc: per adapter object | |
d88e1eab SPS |
480 | * @device: sas_device or pcie_device object |
481 | * @channel: SAS or PCIe channel | |
f92363d1 SR |
482 | * |
483 | * Determines whether this device should be first reported device to | |
484 | * to scsi-ml or sas transport, this purpose is for persistent boot device. | |
485 | * There are primary, alternate, and current entries in bios page 2. The order | |
486 | * priority is primary, alternate, then current. This routine saves | |
d88e1eab | 487 | * the corresponding device object. |
f92363d1 SR |
488 | * The saved data to be used later in _scsih_probe_boot_devices(). |
489 | */ | |
490 | static void | |
d88e1eab SPS |
491 | _scsih_determine_boot_device(struct MPT3SAS_ADAPTER *ioc, void *device, |
492 | u32 channel) | |
f92363d1 SR |
493 | { |
494 | struct _sas_device *sas_device; | |
d88e1eab | 495 | struct _pcie_device *pcie_device; |
f92363d1 SR |
496 | struct _raid_device *raid_device; |
497 | u64 sas_address; | |
498 | u64 device_name; | |
499 | u64 enclosure_logical_id; | |
500 | u16 slot; | |
501 | ||
502 | /* only process this function when driver loads */ | |
503 | if (!ioc->is_driver_loading) | |
504 | return; | |
505 | ||
506 | /* no Bios, return immediately */ | |
507 | if (!ioc->bios_pg3.BiosVersion) | |
508 | return; | |
509 | ||
d88e1eab | 510 | if (channel == RAID_CHANNEL) { |
f92363d1 SR |
511 | raid_device = device; |
512 | sas_address = raid_device->wwid; | |
513 | device_name = 0; | |
514 | enclosure_logical_id = 0; | |
515 | slot = 0; | |
d88e1eab SPS |
516 | } else if (channel == PCIE_CHANNEL) { |
517 | pcie_device = device; | |
518 | sas_address = pcie_device->wwid; | |
519 | device_name = 0; | |
520 | enclosure_logical_id = 0; | |
521 | slot = 0; | |
522 | } else { | |
523 | sas_device = device; | |
524 | sas_address = sas_device->sas_address; | |
525 | device_name = sas_device->device_name; | |
526 | enclosure_logical_id = sas_device->enclosure_logical_id; | |
527 | slot = sas_device->slot; | |
f92363d1 SR |
528 | } |
529 | ||
530 | if (!ioc->req_boot_device.device) { | |
531 | if (_scsih_is_boot_device(sas_address, device_name, | |
532 | enclosure_logical_id, slot, | |
533 | (ioc->bios_pg2.ReqBootDeviceForm & | |
534 | MPI2_BIOSPAGE2_FORM_MASK), | |
535 | &ioc->bios_pg2.RequestedBootDevice)) { | |
919d8a3f JP |
536 | dinitprintk(ioc, |
537 | ioc_info(ioc, "%s: req_boot_device(0x%016llx)\n", | |
538 | __func__, (u64)sas_address)); | |
f92363d1 | 539 | ioc->req_boot_device.device = device; |
d88e1eab | 540 | ioc->req_boot_device.channel = channel; |
f92363d1 SR |
541 | } |
542 | } | |
543 | ||
544 | if (!ioc->req_alt_boot_device.device) { | |
545 | if (_scsih_is_boot_device(sas_address, device_name, | |
546 | enclosure_logical_id, slot, | |
547 | (ioc->bios_pg2.ReqAltBootDeviceForm & | |
548 | MPI2_BIOSPAGE2_FORM_MASK), | |
549 | &ioc->bios_pg2.RequestedAltBootDevice)) { | |
919d8a3f JP |
550 | dinitprintk(ioc, |
551 | ioc_info(ioc, "%s: req_alt_boot_device(0x%016llx)\n", | |
552 | __func__, (u64)sas_address)); | |
f92363d1 | 553 | ioc->req_alt_boot_device.device = device; |
d88e1eab | 554 | ioc->req_alt_boot_device.channel = channel; |
f92363d1 SR |
555 | } |
556 | } | |
557 | ||
558 | if (!ioc->current_boot_device.device) { | |
559 | if (_scsih_is_boot_device(sas_address, device_name, | |
560 | enclosure_logical_id, slot, | |
561 | (ioc->bios_pg2.CurrentBootDeviceForm & | |
562 | MPI2_BIOSPAGE2_FORM_MASK), | |
563 | &ioc->bios_pg2.CurrentBootDevice)) { | |
919d8a3f JP |
564 | dinitprintk(ioc, |
565 | ioc_info(ioc, "%s: current_boot_device(0x%016llx)\n", | |
566 | __func__, (u64)sas_address)); | |
f92363d1 | 567 | ioc->current_boot_device.device = device; |
d88e1eab | 568 | ioc->current_boot_device.channel = channel; |
f92363d1 SR |
569 | } |
570 | } | |
571 | } | |
572 | ||
d1cb5e49 SR |
573 | static struct _sas_device * |
574 | __mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc, | |
575 | struct MPT3SAS_TARGET *tgt_priv) | |
576 | { | |
577 | struct _sas_device *ret; | |
578 | ||
579 | assert_spin_locked(&ioc->sas_device_lock); | |
580 | ||
d88e1eab | 581 | ret = tgt_priv->sas_dev; |
d1cb5e49 SR |
582 | if (ret) |
583 | sas_device_get(ret); | |
584 | ||
585 | return ret; | |
586 | } | |
587 | ||
588 | static struct _sas_device * | |
589 | mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc, | |
590 | struct MPT3SAS_TARGET *tgt_priv) | |
591 | { | |
592 | struct _sas_device *ret; | |
593 | unsigned long flags; | |
594 | ||
595 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
596 | ret = __mpt3sas_get_sdev_from_target(ioc, tgt_priv); | |
597 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
598 | ||
599 | return ret; | |
600 | } | |
601 | ||
d88e1eab SPS |
602 | static struct _pcie_device * |
603 | __mpt3sas_get_pdev_from_target(struct MPT3SAS_ADAPTER *ioc, | |
604 | struct MPT3SAS_TARGET *tgt_priv) | |
605 | { | |
606 | struct _pcie_device *ret; | |
607 | ||
608 | assert_spin_locked(&ioc->pcie_device_lock); | |
609 | ||
610 | ret = tgt_priv->pcie_dev; | |
611 | if (ret) | |
612 | pcie_device_get(ret); | |
613 | ||
614 | return ret; | |
615 | } | |
616 | ||
617 | /** | |
618 | * mpt3sas_get_pdev_from_target - pcie device search | |
619 | * @ioc: per adapter object | |
620 | * @tgt_priv: starget private object | |
621 | * | |
622 | * Context: This function will acquire ioc->pcie_device_lock and will release | |
623 | * before returning the pcie_device object. | |
624 | * | |
625 | * This searches for pcie_device from target, then return pcie_device object. | |
626 | */ | |
494f401b | 627 | static struct _pcie_device * |
d88e1eab SPS |
628 | mpt3sas_get_pdev_from_target(struct MPT3SAS_ADAPTER *ioc, |
629 | struct MPT3SAS_TARGET *tgt_priv) | |
630 | { | |
631 | struct _pcie_device *ret; | |
632 | unsigned long flags; | |
633 | ||
634 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
635 | ret = __mpt3sas_get_pdev_from_target(ioc, tgt_priv); | |
636 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
637 | ||
638 | return ret; | |
639 | } | |
d1cb5e49 SR |
640 | |
641 | struct _sas_device * | |
642 | __mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc, | |
643 | u64 sas_address) | |
644 | { | |
645 | struct _sas_device *sas_device; | |
646 | ||
647 | assert_spin_locked(&ioc->sas_device_lock); | |
648 | ||
649 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) | |
650 | if (sas_device->sas_address == sas_address) | |
651 | goto found_device; | |
652 | ||
653 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) | |
654 | if (sas_device->sas_address == sas_address) | |
655 | goto found_device; | |
656 | ||
657 | return NULL; | |
658 | ||
659 | found_device: | |
660 | sas_device_get(sas_device); | |
661 | return sas_device; | |
662 | } | |
663 | ||
f92363d1 | 664 | /** |
d1cb5e49 | 665 | * mpt3sas_get_sdev_by_addr - sas device search |
f92363d1 SR |
666 | * @ioc: per adapter object |
667 | * @sas_address: sas address | |
668 | * Context: Calling function should acquire ioc->sas_device_lock | |
669 | * | |
670 | * This searches for sas_device based on sas_address, then return sas_device | |
671 | * object. | |
672 | */ | |
673 | struct _sas_device * | |
d1cb5e49 | 674 | mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc, |
f92363d1 SR |
675 | u64 sas_address) |
676 | { | |
677 | struct _sas_device *sas_device; | |
d1cb5e49 SR |
678 | unsigned long flags; |
679 | ||
680 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
681 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, | |
682 | sas_address); | |
683 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
684 | ||
685 | return sas_device; | |
686 | } | |
687 | ||
688 | static struct _sas_device * | |
689 | __mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
690 | { | |
691 | struct _sas_device *sas_device; | |
692 | ||
693 | assert_spin_locked(&ioc->sas_device_lock); | |
f92363d1 SR |
694 | |
695 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) | |
d1cb5e49 SR |
696 | if (sas_device->handle == handle) |
697 | goto found_device; | |
f92363d1 SR |
698 | |
699 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) | |
d1cb5e49 SR |
700 | if (sas_device->handle == handle) |
701 | goto found_device; | |
f92363d1 SR |
702 | |
703 | return NULL; | |
d1cb5e49 SR |
704 | |
705 | found_device: | |
706 | sas_device_get(sas_device); | |
707 | return sas_device; | |
f92363d1 SR |
708 | } |
709 | ||
710 | /** | |
d1cb5e49 | 711 | * mpt3sas_get_sdev_by_handle - sas device search |
f92363d1 SR |
712 | * @ioc: per adapter object |
713 | * @handle: sas device handle (assigned by firmware) | |
714 | * Context: Calling function should acquire ioc->sas_device_lock | |
715 | * | |
716 | * This searches for sas_device based on sas_address, then return sas_device | |
717 | * object. | |
718 | */ | |
c102e00c | 719 | struct _sas_device * |
d1cb5e49 | 720 | mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
f92363d1 SR |
721 | { |
722 | struct _sas_device *sas_device; | |
d1cb5e49 | 723 | unsigned long flags; |
f92363d1 | 724 | |
d1cb5e49 SR |
725 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
726 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); | |
727 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
f92363d1 | 728 | |
d1cb5e49 | 729 | return sas_device; |
f92363d1 SR |
730 | } |
731 | ||
75888956 SR |
732 | /** |
733 | * _scsih_display_enclosure_chassis_info - display device location info | |
734 | * @ioc: per adapter object | |
735 | * @sas_device: per sas device object | |
736 | * @sdev: scsi device struct | |
737 | * @starget: scsi target struct | |
75888956 SR |
738 | */ |
739 | static void | |
740 | _scsih_display_enclosure_chassis_info(struct MPT3SAS_ADAPTER *ioc, | |
741 | struct _sas_device *sas_device, struct scsi_device *sdev, | |
742 | struct scsi_target *starget) | |
743 | { | |
744 | if (sdev) { | |
745 | if (sas_device->enclosure_handle != 0) | |
746 | sdev_printk(KERN_INFO, sdev, | |
747 | "enclosure logical id (0x%016llx), slot(%d) \n", | |
748 | (unsigned long long) | |
749 | sas_device->enclosure_logical_id, | |
750 | sas_device->slot); | |
751 | if (sas_device->connector_name[0] != '\0') | |
752 | sdev_printk(KERN_INFO, sdev, | |
753 | "enclosure level(0x%04x), connector name( %s)\n", | |
754 | sas_device->enclosure_level, | |
755 | sas_device->connector_name); | |
756 | if (sas_device->is_chassis_slot_valid) | |
757 | sdev_printk(KERN_INFO, sdev, "chassis slot(0x%04x)\n", | |
758 | sas_device->chassis_slot); | |
759 | } else if (starget) { | |
760 | if (sas_device->enclosure_handle != 0) | |
761 | starget_printk(KERN_INFO, starget, | |
762 | "enclosure logical id(0x%016llx), slot(%d) \n", | |
763 | (unsigned long long) | |
764 | sas_device->enclosure_logical_id, | |
765 | sas_device->slot); | |
766 | if (sas_device->connector_name[0] != '\0') | |
767 | starget_printk(KERN_INFO, starget, | |
768 | "enclosure level(0x%04x), connector name( %s)\n", | |
769 | sas_device->enclosure_level, | |
770 | sas_device->connector_name); | |
771 | if (sas_device->is_chassis_slot_valid) | |
772 | starget_printk(KERN_INFO, starget, | |
773 | "chassis slot(0x%04x)\n", | |
774 | sas_device->chassis_slot); | |
775 | } else { | |
776 | if (sas_device->enclosure_handle != 0) | |
919d8a3f JP |
777 | ioc_info(ioc, "enclosure logical id(0x%016llx), slot(%d)\n", |
778 | (u64)sas_device->enclosure_logical_id, | |
779 | sas_device->slot); | |
75888956 | 780 | if (sas_device->connector_name[0] != '\0') |
919d8a3f JP |
781 | ioc_info(ioc, "enclosure level(0x%04x), connector name( %s)\n", |
782 | sas_device->enclosure_level, | |
783 | sas_device->connector_name); | |
75888956 | 784 | if (sas_device->is_chassis_slot_valid) |
919d8a3f JP |
785 | ioc_info(ioc, "chassis slot(0x%04x)\n", |
786 | sas_device->chassis_slot); | |
75888956 SR |
787 | } |
788 | } | |
789 | ||
f92363d1 SR |
790 | /** |
791 | * _scsih_sas_device_remove - remove sas_device from list. | |
792 | * @ioc: per adapter object | |
793 | * @sas_device: the sas_device object | |
794 | * Context: This function will acquire ioc->sas_device_lock. | |
795 | * | |
d1cb5e49 | 796 | * If sas_device is on the list, remove it and decrement its reference count. |
f92363d1 SR |
797 | */ |
798 | static void | |
799 | _scsih_sas_device_remove(struct MPT3SAS_ADAPTER *ioc, | |
800 | struct _sas_device *sas_device) | |
801 | { | |
802 | unsigned long flags; | |
803 | ||
804 | if (!sas_device) | |
805 | return; | |
919d8a3f JP |
806 | ioc_info(ioc, "removing handle(0x%04x), sas_addr(0x%016llx)\n", |
807 | sas_device->handle, (u64)sas_device->sas_address); | |
e6d45e3e | 808 | |
75888956 | 809 | _scsih_display_enclosure_chassis_info(ioc, sas_device, NULL, NULL); |
f92363d1 | 810 | |
d1cb5e49 SR |
811 | /* |
812 | * The lock serializes access to the list, but we still need to verify | |
813 | * that nobody removed the entry while we were waiting on the lock. | |
814 | */ | |
f92363d1 | 815 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 SR |
816 | if (!list_empty(&sas_device->list)) { |
817 | list_del_init(&sas_device->list); | |
818 | sas_device_put(sas_device); | |
819 | } | |
f92363d1 SR |
820 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
821 | } | |
822 | ||
823 | /** | |
824 | * _scsih_device_remove_by_handle - removing device object by handle | |
825 | * @ioc: per adapter object | |
826 | * @handle: device handle | |
f92363d1 SR |
827 | */ |
828 | static void | |
829 | _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
830 | { | |
831 | struct _sas_device *sas_device; | |
832 | unsigned long flags; | |
833 | ||
834 | if (ioc->shost_recovery) | |
835 | return; | |
836 | ||
837 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 SR |
838 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
839 | if (sas_device) { | |
840 | list_del_init(&sas_device->list); | |
841 | sas_device_put(sas_device); | |
842 | } | |
f92363d1 | 843 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
d1cb5e49 | 844 | if (sas_device) { |
f92363d1 | 845 | _scsih_remove_device(ioc, sas_device); |
d1cb5e49 SR |
846 | sas_device_put(sas_device); |
847 | } | |
f92363d1 SR |
848 | } |
849 | ||
850 | /** | |
851 | * mpt3sas_device_remove_by_sas_address - removing device object by sas address | |
852 | * @ioc: per adapter object | |
853 | * @sas_address: device sas_address | |
f92363d1 SR |
854 | */ |
855 | void | |
856 | mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER *ioc, | |
857 | u64 sas_address) | |
858 | { | |
859 | struct _sas_device *sas_device; | |
860 | unsigned long flags; | |
861 | ||
862 | if (ioc->shost_recovery) | |
863 | return; | |
864 | ||
865 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 SR |
866 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, sas_address); |
867 | if (sas_device) { | |
868 | list_del_init(&sas_device->list); | |
869 | sas_device_put(sas_device); | |
870 | } | |
f92363d1 | 871 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
d1cb5e49 | 872 | if (sas_device) { |
f92363d1 | 873 | _scsih_remove_device(ioc, sas_device); |
d1cb5e49 SR |
874 | sas_device_put(sas_device); |
875 | } | |
f92363d1 SR |
876 | } |
877 | ||
878 | /** | |
879 | * _scsih_sas_device_add - insert sas_device to the list. | |
880 | * @ioc: per adapter object | |
881 | * @sas_device: the sas_device object | |
882 | * Context: This function will acquire ioc->sas_device_lock. | |
883 | * | |
884 | * Adding new object to the ioc->sas_device_list. | |
885 | */ | |
886 | static void | |
887 | _scsih_sas_device_add(struct MPT3SAS_ADAPTER *ioc, | |
888 | struct _sas_device *sas_device) | |
889 | { | |
890 | unsigned long flags; | |
891 | ||
919d8a3f JP |
892 | dewtprintk(ioc, |
893 | ioc_info(ioc, "%s: handle(0x%04x), sas_addr(0x%016llx)\n", | |
894 | __func__, sas_device->handle, | |
895 | (u64)sas_device->sas_address)); | |
f92363d1 | 896 | |
75888956 SR |
897 | dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device, |
898 | NULL, NULL)); | |
e6d45e3e | 899 | |
f92363d1 | 900 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 901 | sas_device_get(sas_device); |
f92363d1 SR |
902 | list_add_tail(&sas_device->list, &ioc->sas_device_list); |
903 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
904 | ||
c696f7b8 SPS |
905 | if (ioc->hide_drives) { |
906 | clear_bit(sas_device->handle, ioc->pend_os_device_add); | |
907 | return; | |
908 | } | |
909 | ||
f92363d1 SR |
910 | if (!mpt3sas_transport_port_add(ioc, sas_device->handle, |
911 | sas_device->sas_address_parent)) { | |
912 | _scsih_sas_device_remove(ioc, sas_device); | |
913 | } else if (!sas_device->starget) { | |
914 | /* | |
915 | * When asyn scanning is enabled, its not possible to remove | |
916 | * devices while scanning is turned on due to an oops in | |
917 | * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start() | |
918 | */ | |
f5edbe77 | 919 | if (!ioc->is_driver_loading) { |
f92363d1 SR |
920 | mpt3sas_transport_port_remove(ioc, |
921 | sas_device->sas_address, | |
922 | sas_device->sas_address_parent); | |
f5edbe77 SR |
923 | _scsih_sas_device_remove(ioc, sas_device); |
924 | } | |
c696f7b8 SPS |
925 | } else |
926 | clear_bit(sas_device->handle, ioc->pend_os_device_add); | |
f92363d1 SR |
927 | } |
928 | ||
929 | /** | |
930 | * _scsih_sas_device_init_add - insert sas_device to the list. | |
931 | * @ioc: per adapter object | |
932 | * @sas_device: the sas_device object | |
933 | * Context: This function will acquire ioc->sas_device_lock. | |
934 | * | |
935 | * Adding new object at driver load time to the ioc->sas_device_init_list. | |
936 | */ | |
937 | static void | |
938 | _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER *ioc, | |
939 | struct _sas_device *sas_device) | |
940 | { | |
941 | unsigned long flags; | |
942 | ||
919d8a3f JP |
943 | dewtprintk(ioc, |
944 | ioc_info(ioc, "%s: handle(0x%04x), sas_addr(0x%016llx)\n", | |
945 | __func__, sas_device->handle, | |
946 | (u64)sas_device->sas_address)); | |
f92363d1 | 947 | |
75888956 SR |
948 | dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device, |
949 | NULL, NULL)); | |
e6d45e3e | 950 | |
f92363d1 | 951 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 952 | sas_device_get(sas_device); |
f92363d1 SR |
953 | list_add_tail(&sas_device->list, &ioc->sas_device_init_list); |
954 | _scsih_determine_boot_device(ioc, sas_device, 0); | |
955 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
956 | } | |
957 | ||
d88e1eab | 958 | |
494f401b | 959 | static struct _pcie_device * |
d88e1eab SPS |
960 | __mpt3sas_get_pdev_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid) |
961 | { | |
962 | struct _pcie_device *pcie_device; | |
963 | ||
964 | assert_spin_locked(&ioc->pcie_device_lock); | |
965 | ||
966 | list_for_each_entry(pcie_device, &ioc->pcie_device_list, list) | |
967 | if (pcie_device->wwid == wwid) | |
968 | goto found_device; | |
969 | ||
970 | list_for_each_entry(pcie_device, &ioc->pcie_device_init_list, list) | |
971 | if (pcie_device->wwid == wwid) | |
972 | goto found_device; | |
973 | ||
974 | return NULL; | |
975 | ||
976 | found_device: | |
977 | pcie_device_get(pcie_device); | |
978 | return pcie_device; | |
979 | } | |
980 | ||
981 | ||
982 | /** | |
983 | * mpt3sas_get_pdev_by_wwid - pcie device search | |
984 | * @ioc: per adapter object | |
985 | * @wwid: wwid | |
986 | * | |
987 | * Context: This function will acquire ioc->pcie_device_lock and will release | |
988 | * before returning the pcie_device object. | |
989 | * | |
990 | * This searches for pcie_device based on wwid, then return pcie_device object. | |
991 | */ | |
494f401b | 992 | static struct _pcie_device * |
d88e1eab SPS |
993 | mpt3sas_get_pdev_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid) |
994 | { | |
995 | struct _pcie_device *pcie_device; | |
996 | unsigned long flags; | |
997 | ||
998 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
999 | pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid); | |
1000 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1001 | ||
1002 | return pcie_device; | |
1003 | } | |
1004 | ||
1005 | ||
494f401b | 1006 | static struct _pcie_device * |
d88e1eab SPS |
1007 | __mpt3sas_get_pdev_by_idchannel(struct MPT3SAS_ADAPTER *ioc, int id, |
1008 | int channel) | |
1009 | { | |
1010 | struct _pcie_device *pcie_device; | |
1011 | ||
1012 | assert_spin_locked(&ioc->pcie_device_lock); | |
1013 | ||
1014 | list_for_each_entry(pcie_device, &ioc->pcie_device_list, list) | |
1015 | if (pcie_device->id == id && pcie_device->channel == channel) | |
1016 | goto found_device; | |
1017 | ||
1018 | list_for_each_entry(pcie_device, &ioc->pcie_device_init_list, list) | |
1019 | if (pcie_device->id == id && pcie_device->channel == channel) | |
1020 | goto found_device; | |
1021 | ||
1022 | return NULL; | |
1023 | ||
1024 | found_device: | |
1025 | pcie_device_get(pcie_device); | |
1026 | return pcie_device; | |
1027 | } | |
1028 | ||
494f401b | 1029 | static struct _pcie_device * |
c102e00c SPS |
1030 | __mpt3sas_get_pdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
1031 | { | |
1032 | struct _pcie_device *pcie_device; | |
1033 | ||
1034 | assert_spin_locked(&ioc->pcie_device_lock); | |
1035 | ||
1036 | list_for_each_entry(pcie_device, &ioc->pcie_device_list, list) | |
1037 | if (pcie_device->handle == handle) | |
1038 | goto found_device; | |
1039 | ||
1040 | list_for_each_entry(pcie_device, &ioc->pcie_device_init_list, list) | |
1041 | if (pcie_device->handle == handle) | |
1042 | goto found_device; | |
1043 | ||
1044 | return NULL; | |
1045 | ||
1046 | found_device: | |
1047 | pcie_device_get(pcie_device); | |
1048 | return pcie_device; | |
1049 | } | |
1050 | ||
1051 | ||
1052 | /** | |
1053 | * mpt3sas_get_pdev_by_handle - pcie device search | |
1054 | * @ioc: per adapter object | |
1055 | * @handle: Firmware device handle | |
1056 | * | |
1057 | * Context: This function will acquire ioc->pcie_device_lock and will release | |
1058 | * before returning the pcie_device object. | |
1059 | * | |
1060 | * This searches for pcie_device based on handle, then return pcie_device | |
1061 | * object. | |
1062 | */ | |
1063 | struct _pcie_device * | |
1064 | mpt3sas_get_pdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
1065 | { | |
1066 | struct _pcie_device *pcie_device; | |
1067 | unsigned long flags; | |
1068 | ||
1069 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1070 | pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle); | |
1071 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1072 | ||
1073 | return pcie_device; | |
1074 | } | |
1075 | ||
43fb7c95 SR |
1076 | /** |
1077 | * _scsih_set_nvme_max_shutdown_latency - Update max_shutdown_latency. | |
1078 | * @ioc: per adapter object | |
1079 | * Context: This function will acquire ioc->pcie_device_lock | |
1080 | * | |
1081 | * Update ioc->max_shutdown_latency to that NVMe drives RTD3 Entry Latency | |
1082 | * which has reported maximum among all available NVMe drives. | |
1083 | * Minimum max_shutdown_latency will be six seconds. | |
1084 | */ | |
1085 | static void | |
1086 | _scsih_set_nvme_max_shutdown_latency(struct MPT3SAS_ADAPTER *ioc) | |
1087 | { | |
1088 | struct _pcie_device *pcie_device; | |
1089 | unsigned long flags; | |
1090 | u16 shutdown_latency = IO_UNIT_CONTROL_SHUTDOWN_TIMEOUT; | |
1091 | ||
1092 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1093 | list_for_each_entry(pcie_device, &ioc->pcie_device_list, list) { | |
1094 | if (pcie_device->shutdown_latency) { | |
1095 | if (shutdown_latency < pcie_device->shutdown_latency) | |
1096 | shutdown_latency = | |
1097 | pcie_device->shutdown_latency; | |
1098 | } | |
1099 | } | |
1100 | ioc->max_shutdown_latency = shutdown_latency; | |
1101 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1102 | } | |
1103 | ||
d88e1eab SPS |
1104 | /** |
1105 | * _scsih_pcie_device_remove - remove pcie_device from list. | |
1106 | * @ioc: per adapter object | |
1107 | * @pcie_device: the pcie_device object | |
1108 | * Context: This function will acquire ioc->pcie_device_lock. | |
1109 | * | |
1110 | * If pcie_device is on the list, remove it and decrement its reference count. | |
1111 | */ | |
1112 | static void | |
1113 | _scsih_pcie_device_remove(struct MPT3SAS_ADAPTER *ioc, | |
1114 | struct _pcie_device *pcie_device) | |
1115 | { | |
1116 | unsigned long flags; | |
1117 | int was_on_pcie_device_list = 0; | |
43fb7c95 | 1118 | u8 update_latency = 0; |
d88e1eab SPS |
1119 | |
1120 | if (!pcie_device) | |
1121 | return; | |
919d8a3f JP |
1122 | ioc_info(ioc, "removing handle(0x%04x), wwid(0x%016llx)\n", |
1123 | pcie_device->handle, (u64)pcie_device->wwid); | |
d88e1eab | 1124 | if (pcie_device->enclosure_handle != 0) |
919d8a3f JP |
1125 | ioc_info(ioc, "removing enclosure logical id(0x%016llx), slot(%d)\n", |
1126 | (u64)pcie_device->enclosure_logical_id, | |
1127 | pcie_device->slot); | |
d88e1eab | 1128 | if (pcie_device->connector_name[0] != '\0') |
919d8a3f JP |
1129 | ioc_info(ioc, "removing enclosure level(0x%04x), connector name( %s)\n", |
1130 | pcie_device->enclosure_level, | |
1131 | pcie_device->connector_name); | |
d88e1eab SPS |
1132 | |
1133 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1134 | if (!list_empty(&pcie_device->list)) { | |
1135 | list_del_init(&pcie_device->list); | |
1136 | was_on_pcie_device_list = 1; | |
1137 | } | |
43fb7c95 SR |
1138 | if (pcie_device->shutdown_latency == ioc->max_shutdown_latency) |
1139 | update_latency = 1; | |
d88e1eab SPS |
1140 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); |
1141 | if (was_on_pcie_device_list) { | |
1142 | kfree(pcie_device->serial_number); | |
1143 | pcie_device_put(pcie_device); | |
1144 | } | |
43fb7c95 SR |
1145 | |
1146 | /* | |
1147 | * This device's RTD3 Entry Latency matches IOC's | |
1148 | * max_shutdown_latency. Recalculate IOC's max_shutdown_latency | |
1149 | * from the available drives as current drive is getting removed. | |
1150 | */ | |
1151 | if (update_latency) | |
1152 | _scsih_set_nvme_max_shutdown_latency(ioc); | |
d88e1eab | 1153 | } |
3075ac49 SPS |
1154 | |
1155 | ||
1156 | /** | |
1157 | * _scsih_pcie_device_remove_by_handle - removing pcie device object by handle | |
1158 | * @ioc: per adapter object | |
1159 | * @handle: device handle | |
3075ac49 SPS |
1160 | */ |
1161 | static void | |
1162 | _scsih_pcie_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
1163 | { | |
1164 | struct _pcie_device *pcie_device; | |
1165 | unsigned long flags; | |
1166 | int was_on_pcie_device_list = 0; | |
43fb7c95 | 1167 | u8 update_latency = 0; |
3075ac49 SPS |
1168 | |
1169 | if (ioc->shost_recovery) | |
1170 | return; | |
1171 | ||
1172 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1173 | pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle); | |
1174 | if (pcie_device) { | |
1175 | if (!list_empty(&pcie_device->list)) { | |
1176 | list_del_init(&pcie_device->list); | |
1177 | was_on_pcie_device_list = 1; | |
1178 | pcie_device_put(pcie_device); | |
1179 | } | |
43fb7c95 SR |
1180 | if (pcie_device->shutdown_latency == ioc->max_shutdown_latency) |
1181 | update_latency = 1; | |
3075ac49 SPS |
1182 | } |
1183 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1184 | if (was_on_pcie_device_list) { | |
1185 | _scsih_pcie_device_remove_from_sml(ioc, pcie_device); | |
1186 | pcie_device_put(pcie_device); | |
1187 | } | |
43fb7c95 SR |
1188 | |
1189 | /* | |
1190 | * This device's RTD3 Entry Latency matches IOC's | |
1191 | * max_shutdown_latency. Recalculate IOC's max_shutdown_latency | |
1192 | * from the available drives as current drive is getting removed. | |
1193 | */ | |
1194 | if (update_latency) | |
1195 | _scsih_set_nvme_max_shutdown_latency(ioc); | |
3075ac49 SPS |
1196 | } |
1197 | ||
c102e00c SPS |
1198 | /** |
1199 | * _scsih_pcie_device_add - add pcie_device object | |
1200 | * @ioc: per adapter object | |
1201 | * @pcie_device: pcie_device object | |
1202 | * | |
1203 | * This is added to the pcie_device_list link list. | |
1204 | */ | |
1205 | static void | |
1206 | _scsih_pcie_device_add(struct MPT3SAS_ADAPTER *ioc, | |
1207 | struct _pcie_device *pcie_device) | |
1208 | { | |
1209 | unsigned long flags; | |
1210 | ||
919d8a3f JP |
1211 | dewtprintk(ioc, |
1212 | ioc_info(ioc, "%s: handle (0x%04x), wwid(0x%016llx)\n", | |
1213 | __func__, | |
1214 | pcie_device->handle, (u64)pcie_device->wwid)); | |
c102e00c | 1215 | if (pcie_device->enclosure_handle != 0) |
919d8a3f JP |
1216 | dewtprintk(ioc, |
1217 | ioc_info(ioc, "%s: enclosure logical id(0x%016llx), slot( %d)\n", | |
1218 | __func__, | |
1219 | (u64)pcie_device->enclosure_logical_id, | |
1220 | pcie_device->slot)); | |
c102e00c | 1221 | if (pcie_device->connector_name[0] != '\0') |
919d8a3f JP |
1222 | dewtprintk(ioc, |
1223 | ioc_info(ioc, "%s: enclosure level(0x%04x), connector name( %s)\n", | |
1224 | __func__, pcie_device->enclosure_level, | |
1225 | pcie_device->connector_name)); | |
c102e00c SPS |
1226 | |
1227 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1228 | pcie_device_get(pcie_device); | |
1229 | list_add_tail(&pcie_device->list, &ioc->pcie_device_list); | |
1230 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1231 | ||
3c090ce3 SP |
1232 | if (pcie_device->access_status == |
1233 | MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED) { | |
1234 | clear_bit(pcie_device->handle, ioc->pend_os_device_add); | |
1235 | return; | |
1236 | } | |
c102e00c SPS |
1237 | if (scsi_add_device(ioc->shost, PCIE_CHANNEL, pcie_device->id, 0)) { |
1238 | _scsih_pcie_device_remove(ioc, pcie_device); | |
1239 | } else if (!pcie_device->starget) { | |
1240 | if (!ioc->is_driver_loading) { | |
1241 | /*TODO-- Need to find out whether this condition will occur or not*/ | |
1242 | clear_bit(pcie_device->handle, ioc->pend_os_device_add); | |
1243 | } | |
1244 | } else | |
1245 | clear_bit(pcie_device->handle, ioc->pend_os_device_add); | |
1246 | } | |
1247 | ||
1248 | /* | |
1249 | * _scsih_pcie_device_init_add - insert pcie_device to the init list. | |
1250 | * @ioc: per adapter object | |
1251 | * @pcie_device: the pcie_device object | |
1252 | * Context: This function will acquire ioc->pcie_device_lock. | |
1253 | * | |
1254 | * Adding new object at driver load time to the ioc->pcie_device_init_list. | |
1255 | */ | |
1256 | static void | |
1257 | _scsih_pcie_device_init_add(struct MPT3SAS_ADAPTER *ioc, | |
1258 | struct _pcie_device *pcie_device) | |
1259 | { | |
1260 | unsigned long flags; | |
1261 | ||
919d8a3f JP |
1262 | dewtprintk(ioc, |
1263 | ioc_info(ioc, "%s: handle (0x%04x), wwid(0x%016llx)\n", | |
1264 | __func__, | |
1265 | pcie_device->handle, (u64)pcie_device->wwid)); | |
c102e00c | 1266 | if (pcie_device->enclosure_handle != 0) |
919d8a3f JP |
1267 | dewtprintk(ioc, |
1268 | ioc_info(ioc, "%s: enclosure logical id(0x%016llx), slot( %d)\n", | |
1269 | __func__, | |
1270 | (u64)pcie_device->enclosure_logical_id, | |
1271 | pcie_device->slot)); | |
c102e00c | 1272 | if (pcie_device->connector_name[0] != '\0') |
919d8a3f JP |
1273 | dewtprintk(ioc, |
1274 | ioc_info(ioc, "%s: enclosure level(0x%04x), connector name( %s)\n", | |
1275 | __func__, pcie_device->enclosure_level, | |
1276 | pcie_device->connector_name)); | |
c102e00c SPS |
1277 | |
1278 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1279 | pcie_device_get(pcie_device); | |
1280 | list_add_tail(&pcie_device->list, &ioc->pcie_device_init_list); | |
3c090ce3 SP |
1281 | if (pcie_device->access_status != |
1282 | MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED) | |
1283 | _scsih_determine_boot_device(ioc, pcie_device, PCIE_CHANNEL); | |
c102e00c SPS |
1284 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); |
1285 | } | |
f92363d1 SR |
1286 | /** |
1287 | * _scsih_raid_device_find_by_id - raid device search | |
1288 | * @ioc: per adapter object | |
1289 | * @id: sas device target id | |
1290 | * @channel: sas device channel | |
1291 | * Context: Calling function should acquire ioc->raid_device_lock | |
1292 | * | |
1293 | * This searches for raid_device based on target id, then return raid_device | |
1294 | * object. | |
1295 | */ | |
1296 | static struct _raid_device * | |
1297 | _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER *ioc, int id, int channel) | |
1298 | { | |
1299 | struct _raid_device *raid_device, *r; | |
1300 | ||
1301 | r = NULL; | |
1302 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
1303 | if (raid_device->id == id && raid_device->channel == channel) { | |
1304 | r = raid_device; | |
1305 | goto out; | |
1306 | } | |
1307 | } | |
1308 | ||
1309 | out: | |
1310 | return r; | |
1311 | } | |
1312 | ||
1313 | /** | |
c84b06a4 | 1314 | * mpt3sas_raid_device_find_by_handle - raid device search |
f92363d1 SR |
1315 | * @ioc: per adapter object |
1316 | * @handle: sas device handle (assigned by firmware) | |
1317 | * Context: Calling function should acquire ioc->raid_device_lock | |
1318 | * | |
1319 | * This searches for raid_device based on handle, then return raid_device | |
1320 | * object. | |
1321 | */ | |
c84b06a4 SR |
1322 | struct _raid_device * |
1323 | mpt3sas_raid_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
f92363d1 SR |
1324 | { |
1325 | struct _raid_device *raid_device, *r; | |
1326 | ||
1327 | r = NULL; | |
1328 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
1329 | if (raid_device->handle != handle) | |
1330 | continue; | |
1331 | r = raid_device; | |
1332 | goto out; | |
1333 | } | |
1334 | ||
1335 | out: | |
1336 | return r; | |
1337 | } | |
1338 | ||
1339 | /** | |
1340 | * _scsih_raid_device_find_by_wwid - raid device search | |
1341 | * @ioc: per adapter object | |
4beb4867 | 1342 | * @wwid: ? |
f92363d1 SR |
1343 | * Context: Calling function should acquire ioc->raid_device_lock |
1344 | * | |
1345 | * This searches for raid_device based on wwid, then return raid_device | |
1346 | * object. | |
1347 | */ | |
1348 | static struct _raid_device * | |
1349 | _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid) | |
1350 | { | |
1351 | struct _raid_device *raid_device, *r; | |
1352 | ||
1353 | r = NULL; | |
1354 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
1355 | if (raid_device->wwid != wwid) | |
1356 | continue; | |
1357 | r = raid_device; | |
1358 | goto out; | |
1359 | } | |
1360 | ||
1361 | out: | |
1362 | return r; | |
1363 | } | |
1364 | ||
1365 | /** | |
1366 | * _scsih_raid_device_add - add raid_device object | |
1367 | * @ioc: per adapter object | |
1368 | * @raid_device: raid_device object | |
1369 | * | |
1370 | * This is added to the raid_device_list link list. | |
1371 | */ | |
1372 | static void | |
1373 | _scsih_raid_device_add(struct MPT3SAS_ADAPTER *ioc, | |
1374 | struct _raid_device *raid_device) | |
1375 | { | |
1376 | unsigned long flags; | |
1377 | ||
919d8a3f JP |
1378 | dewtprintk(ioc, |
1379 | ioc_info(ioc, "%s: handle(0x%04x), wwid(0x%016llx)\n", | |
1380 | __func__, | |
1381 | raid_device->handle, (u64)raid_device->wwid)); | |
f92363d1 SR |
1382 | |
1383 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1384 | list_add_tail(&raid_device->list, &ioc->raid_device_list); | |
1385 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1386 | } | |
1387 | ||
1388 | /** | |
1389 | * _scsih_raid_device_remove - delete raid_device object | |
1390 | * @ioc: per adapter object | |
1391 | * @raid_device: raid_device object | |
1392 | * | |
1393 | */ | |
1394 | static void | |
1395 | _scsih_raid_device_remove(struct MPT3SAS_ADAPTER *ioc, | |
1396 | struct _raid_device *raid_device) | |
1397 | { | |
1398 | unsigned long flags; | |
1399 | ||
1400 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1401 | list_del(&raid_device->list); | |
1402 | kfree(raid_device); | |
1403 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1404 | } | |
1405 | ||
1406 | /** | |
1407 | * mpt3sas_scsih_expander_find_by_handle - expander device search | |
1408 | * @ioc: per adapter object | |
1409 | * @handle: expander handle (assigned by firmware) | |
1410 | * Context: Calling function should acquire ioc->sas_device_lock | |
1411 | * | |
1412 | * This searches for expander device based on handle, then returns the | |
1413 | * sas_node object. | |
1414 | */ | |
1415 | struct _sas_node * | |
1416 | mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
1417 | { | |
1418 | struct _sas_node *sas_expander, *r; | |
1419 | ||
1420 | r = NULL; | |
1421 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { | |
1422 | if (sas_expander->handle != handle) | |
1423 | continue; | |
1424 | r = sas_expander; | |
1425 | goto out; | |
1426 | } | |
1427 | out: | |
1428 | return r; | |
1429 | } | |
1430 | ||
22a923c3 C |
1431 | /** |
1432 | * mpt3sas_scsih_enclosure_find_by_handle - exclosure device search | |
1433 | * @ioc: per adapter object | |
1434 | * @handle: enclosure handle (assigned by firmware) | |
1435 | * Context: Calling function should acquire ioc->sas_device_lock | |
1436 | * | |
1437 | * This searches for enclosure device based on handle, then returns the | |
1438 | * enclosure object. | |
1439 | */ | |
1440 | static struct _enclosure_node * | |
1441 | mpt3sas_scsih_enclosure_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
1442 | { | |
1443 | struct _enclosure_node *enclosure_dev, *r; | |
1444 | ||
1445 | r = NULL; | |
1446 | list_for_each_entry(enclosure_dev, &ioc->enclosure_list, list) { | |
1447 | if (le16_to_cpu(enclosure_dev->pg0.EnclosureHandle) != handle) | |
1448 | continue; | |
1449 | r = enclosure_dev; | |
1450 | goto out; | |
1451 | } | |
1452 | out: | |
1453 | return r; | |
1454 | } | |
f92363d1 SR |
1455 | /** |
1456 | * mpt3sas_scsih_expander_find_by_sas_address - expander device search | |
1457 | * @ioc: per adapter object | |
1458 | * @sas_address: sas address | |
1459 | * Context: Calling function should acquire ioc->sas_node_lock. | |
1460 | * | |
1461 | * This searches for expander device based on sas_address, then returns the | |
1462 | * sas_node object. | |
1463 | */ | |
1464 | struct _sas_node * | |
1465 | mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc, | |
1466 | u64 sas_address) | |
1467 | { | |
1468 | struct _sas_node *sas_expander, *r; | |
1469 | ||
1470 | r = NULL; | |
1471 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { | |
1472 | if (sas_expander->sas_address != sas_address) | |
1473 | continue; | |
1474 | r = sas_expander; | |
1475 | goto out; | |
1476 | } | |
1477 | out: | |
1478 | return r; | |
1479 | } | |
1480 | ||
1481 | /** | |
1482 | * _scsih_expander_node_add - insert expander device to the list. | |
1483 | * @ioc: per adapter object | |
1484 | * @sas_expander: the sas_device object | |
1485 | * Context: This function will acquire ioc->sas_node_lock. | |
1486 | * | |
1487 | * Adding new object to the ioc->sas_expander_list. | |
f92363d1 SR |
1488 | */ |
1489 | static void | |
1490 | _scsih_expander_node_add(struct MPT3SAS_ADAPTER *ioc, | |
1491 | struct _sas_node *sas_expander) | |
1492 | { | |
1493 | unsigned long flags; | |
1494 | ||
1495 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
1496 | list_add_tail(&sas_expander->list, &ioc->sas_expander_list); | |
1497 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
1498 | } | |
1499 | ||
1500 | /** | |
1501 | * _scsih_is_end_device - determines if device is an end device | |
1502 | * @device_info: bitfield providing information about the device. | |
1503 | * Context: none | |
1504 | * | |
4beb4867 | 1505 | * Return: 1 if end device. |
f92363d1 SR |
1506 | */ |
1507 | static int | |
1508 | _scsih_is_end_device(u32 device_info) | |
1509 | { | |
1510 | if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE && | |
1511 | ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) | | |
1512 | (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) | | |
1513 | (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE))) | |
1514 | return 1; | |
1515 | else | |
1516 | return 0; | |
1517 | } | |
1518 | ||
c102e00c | 1519 | /** |
5bb309db SP |
1520 | * _scsih_is_nvme_pciescsi_device - determines if |
1521 | * device is an pcie nvme/scsi device | |
c102e00c SPS |
1522 | * @device_info: bitfield providing information about the device. |
1523 | * Context: none | |
1524 | * | |
5bb309db | 1525 | * Returns 1 if device is pcie device type nvme/scsi. |
c102e00c SPS |
1526 | */ |
1527 | static int | |
5bb309db | 1528 | _scsih_is_nvme_pciescsi_device(u32 device_info) |
c102e00c | 1529 | { |
5bb309db SP |
1530 | if (((device_info & MPI26_PCIE_DEVINFO_MASK_DEVICE_TYPE) |
1531 | == MPI26_PCIE_DEVINFO_NVME) || | |
1532 | ((device_info & MPI26_PCIE_DEVINFO_MASK_DEVICE_TYPE) | |
1533 | == MPI26_PCIE_DEVINFO_SCSI)) | |
c102e00c SPS |
1534 | return 1; |
1535 | else | |
1536 | return 0; | |
1537 | } | |
1538 | ||
459325c4 | 1539 | /** |
dbec4c90 | 1540 | * mpt3sas_scsih_scsi_lookup_get - returns scmd entry |
459325c4 C |
1541 | * @ioc: per adapter object |
1542 | * @smid: system request message index | |
1543 | * | |
4beb4867 | 1544 | * Return: the smid stored scmd pointer. |
459325c4 C |
1545 | * Then will dereference the stored scmd pointer. |
1546 | */ | |
dbec4c90 SPS |
1547 | struct scsi_cmnd * |
1548 | mpt3sas_scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid) | |
459325c4 C |
1549 | { |
1550 | struct scsi_cmnd *scmd = NULL; | |
dbec4c90 | 1551 | struct scsiio_tracker *st; |
c2fe742f | 1552 | Mpi25SCSIIORequest_t *mpi_request; |
459325c4 | 1553 | |
dbec4c90 SPS |
1554 | if (smid > 0 && |
1555 | smid <= ioc->scsiio_depth - INTERNAL_SCSIIO_CMDS_COUNT) { | |
1556 | u32 unique_tag = smid - 1; | |
f92363d1 | 1557 | |
c2fe742f SR |
1558 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
1559 | ||
1560 | /* | |
1561 | * If SCSI IO request is outstanding at driver level then | |
1562 | * DevHandle filed must be non-zero. If DevHandle is zero | |
1563 | * then it means that this smid is free at driver level, | |
1564 | * so return NULL. | |
1565 | */ | |
1566 | if (!mpi_request->DevHandle) | |
1567 | return scmd; | |
1568 | ||
dbec4c90 SPS |
1569 | scmd = scsi_host_find_tag(ioc->shost, unique_tag); |
1570 | if (scmd) { | |
1571 | st = scsi_cmd_priv(scmd); | |
e7018314 | 1572 | if (st->cb_idx == 0xFF || st->smid == 0) |
dbec4c90 | 1573 | scmd = NULL; |
f92363d1 SR |
1574 | } |
1575 | } | |
dbec4c90 | 1576 | return scmd; |
f92363d1 SR |
1577 | } |
1578 | ||
cf75d5d6 | 1579 | /** |
8a7e4c24 | 1580 | * scsih_change_queue_depth - setting device queue depth |
cf75d5d6 CH |
1581 | * @sdev: scsi device struct |
1582 | * @qdepth: requested queue depth | |
1583 | * | |
4beb4867 | 1584 | * Return: queue depth. |
cf75d5d6 | 1585 | */ |
8bbb1cf6 | 1586 | static int |
8a7e4c24 | 1587 | scsih_change_queue_depth(struct scsi_device *sdev, int qdepth) |
f92363d1 SR |
1588 | { |
1589 | struct Scsi_Host *shost = sdev->host; | |
1590 | int max_depth; | |
1591 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
1592 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
1593 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1594 | struct _sas_device *sas_device; | |
1595 | unsigned long flags; | |
1596 | ||
1597 | max_depth = shost->can_queue; | |
1598 | ||
8dc8d29a SR |
1599 | /* |
1600 | * limit max device queue for SATA to 32 if enable_sdev_max_qd | |
1601 | * is disabled. | |
1602 | */ | |
1603 | if (ioc->enable_sdev_max_qd) | |
1604 | goto not_sata; | |
1605 | ||
f92363d1 SR |
1606 | sas_device_priv_data = sdev->hostdata; |
1607 | if (!sas_device_priv_data) | |
1608 | goto not_sata; | |
1609 | sas_target_priv_data = sas_device_priv_data->sas_target; | |
1610 | if (!sas_target_priv_data) | |
1611 | goto not_sata; | |
1612 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) | |
1613 | goto not_sata; | |
d1cb5e49 | 1614 | |
f92363d1 | 1615 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 SR |
1616 | sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data); |
1617 | if (sas_device) { | |
1618 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE) | |
1619 | max_depth = MPT3SAS_SATA_QUEUE_DEPTH; | |
1620 | ||
1621 | sas_device_put(sas_device); | |
1622 | } | |
f92363d1 SR |
1623 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
1624 | ||
1625 | not_sata: | |
1626 | ||
1627 | if (!sdev->tagged_supported) | |
1628 | max_depth = 1; | |
1629 | if (qdepth > max_depth) | |
1630 | qdepth = max_depth; | |
13d01df5 SR |
1631 | scsi_change_queue_depth(sdev, qdepth); |
1632 | sdev_printk(KERN_INFO, sdev, | |
1633 | "qdepth(%d), tagged(%d), scsi_level(%d), cmd_que(%d)\n", | |
1634 | sdev->queue_depth, sdev->tagged_supported, | |
1635 | sdev->scsi_level, ((sdev->inquiry[7] & 2) >> 1)); | |
1636 | return sdev->queue_depth; | |
f92363d1 SR |
1637 | } |
1638 | ||
8dc8d29a SR |
1639 | /** |
1640 | * mpt3sas_scsih_change_queue_depth - setting device queue depth | |
1641 | * @sdev: scsi device struct | |
1642 | * @qdepth: requested queue depth | |
1643 | * | |
1644 | * Returns nothing. | |
1645 | */ | |
1646 | void | |
1647 | mpt3sas_scsih_change_queue_depth(struct scsi_device *sdev, int qdepth) | |
1648 | { | |
1649 | struct Scsi_Host *shost = sdev->host; | |
1650 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
1651 | ||
1652 | if (ioc->enable_sdev_max_qd) | |
1653 | qdepth = shost->can_queue; | |
1654 | ||
1655 | scsih_change_queue_depth(sdev, qdepth); | |
1656 | } | |
1657 | ||
f92363d1 | 1658 | /** |
8a7e4c24 | 1659 | * scsih_target_alloc - target add routine |
f92363d1 SR |
1660 | * @starget: scsi target struct |
1661 | * | |
4beb4867 | 1662 | * Return: 0 if ok. Any other return is assumed to be an error and |
f92363d1 SR |
1663 | * the device is ignored. |
1664 | */ | |
8bbb1cf6 | 1665 | static int |
8a7e4c24 | 1666 | scsih_target_alloc(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 SR |
1674 | unsigned long flags; |
1675 | struct sas_rphy *rphy; | |
1676 | ||
62c4da44 JL |
1677 | sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data), |
1678 | GFP_KERNEL); | |
f92363d1 SR |
1679 | if (!sas_target_priv_data) |
1680 | return -ENOMEM; | |
1681 | ||
1682 | starget->hostdata = sas_target_priv_data; | |
1683 | sas_target_priv_data->starget = starget; | |
1684 | sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE; | |
1685 | ||
1686 | /* RAID volumes */ | |
1687 | if (starget->channel == RAID_CHANNEL) { | |
1688 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1689 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, | |
1690 | starget->channel); | |
1691 | if (raid_device) { | |
1692 | sas_target_priv_data->handle = raid_device->handle; | |
1693 | sas_target_priv_data->sas_address = raid_device->wwid; | |
1694 | sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME; | |
7786ab6a | 1695 | if (ioc->is_warpdrive) |
6d3a56ed SR |
1696 | sas_target_priv_data->raid_device = raid_device; |
1697 | raid_device->starget = starget; | |
f92363d1 SR |
1698 | } |
1699 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1700 | return 0; | |
1701 | } | |
1702 | ||
d88e1eab SPS |
1703 | /* PCIe devices */ |
1704 | if (starget->channel == PCIE_CHANNEL) { | |
1705 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1706 | pcie_device = __mpt3sas_get_pdev_by_idchannel(ioc, starget->id, | |
1707 | starget->channel); | |
1708 | if (pcie_device) { | |
1709 | sas_target_priv_data->handle = pcie_device->handle; | |
1710 | sas_target_priv_data->sas_address = pcie_device->wwid; | |
1711 | sas_target_priv_data->pcie_dev = pcie_device; | |
1712 | pcie_device->starget = starget; | |
1713 | pcie_device->id = starget->id; | |
1714 | pcie_device->channel = starget->channel; | |
1715 | sas_target_priv_data->flags |= | |
1716 | MPT_TARGET_FLAGS_PCIE_DEVICE; | |
1717 | if (pcie_device->fast_path) | |
1718 | sas_target_priv_data->flags |= | |
1719 | MPT_TARGET_FASTPATH_IO; | |
1720 | } | |
1721 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1722 | return 0; | |
1723 | } | |
1724 | ||
f92363d1 SR |
1725 | /* sas/sata devices */ |
1726 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
1727 | rphy = dev_to_rphy(starget->dev.parent); | |
d1cb5e49 | 1728 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 SR |
1729 | rphy->identify.sas_address); |
1730 | ||
1731 | if (sas_device) { | |
1732 | sas_target_priv_data->handle = sas_device->handle; | |
1733 | sas_target_priv_data->sas_address = sas_device->sas_address; | |
d88e1eab | 1734 | sas_target_priv_data->sas_dev = sas_device; |
f92363d1 SR |
1735 | sas_device->starget = starget; |
1736 | sas_device->id = starget->id; | |
1737 | sas_device->channel = starget->channel; | |
1738 | if (test_bit(sas_device->handle, ioc->pd_handles)) | |
1739 | sas_target_priv_data->flags |= | |
1740 | MPT_TARGET_FLAGS_RAID_COMPONENT; | |
1741 | if (sas_device->fast_path) | |
d88e1eab SPS |
1742 | sas_target_priv_data->flags |= |
1743 | MPT_TARGET_FASTPATH_IO; | |
f92363d1 SR |
1744 | } |
1745 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
1746 | ||
1747 | return 0; | |
1748 | } | |
1749 | ||
1750 | /** | |
8a7e4c24 | 1751 | * scsih_target_destroy - target destroy routine |
f92363d1 | 1752 | * @starget: scsi target struct |
f92363d1 | 1753 | */ |
8bbb1cf6 | 1754 | static void |
8a7e4c24 | 1755 | scsih_target_destroy(struct scsi_target *starget) |
f92363d1 SR |
1756 | { |
1757 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); | |
1758 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
1759 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1760 | struct _sas_device *sas_device; | |
1761 | struct _raid_device *raid_device; | |
d88e1eab | 1762 | struct _pcie_device *pcie_device; |
f92363d1 | 1763 | unsigned long flags; |
f92363d1 SR |
1764 | |
1765 | sas_target_priv_data = starget->hostdata; | |
1766 | if (!sas_target_priv_data) | |
1767 | return; | |
1768 | ||
1769 | if (starget->channel == RAID_CHANNEL) { | |
1770 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1771 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, | |
1772 | starget->channel); | |
1773 | if (raid_device) { | |
1774 | raid_device->starget = NULL; | |
1775 | raid_device->sdev = NULL; | |
1776 | } | |
1777 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1778 | goto out; | |
1779 | } | |
1780 | ||
d88e1eab SPS |
1781 | if (starget->channel == PCIE_CHANNEL) { |
1782 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1783 | pcie_device = __mpt3sas_get_pdev_from_target(ioc, | |
1784 | sas_target_priv_data); | |
1785 | if (pcie_device && (pcie_device->starget == starget) && | |
1786 | (pcie_device->id == starget->id) && | |
1787 | (pcie_device->channel == starget->channel)) | |
1788 | pcie_device->starget = NULL; | |
1789 | ||
1790 | if (pcie_device) { | |
1791 | /* | |
1792 | * Corresponding get() is in _scsih_target_alloc() | |
1793 | */ | |
1794 | sas_target_priv_data->pcie_dev = NULL; | |
1795 | pcie_device_put(pcie_device); | |
1796 | pcie_device_put(pcie_device); | |
1797 | } | |
1798 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1799 | goto out; | |
1800 | } | |
1801 | ||
f92363d1 | 1802 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 1803 | sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data); |
f92363d1 SR |
1804 | if (sas_device && (sas_device->starget == starget) && |
1805 | (sas_device->id == starget->id) && | |
1806 | (sas_device->channel == starget->channel)) | |
1807 | sas_device->starget = NULL; | |
1808 | ||
d1cb5e49 SR |
1809 | if (sas_device) { |
1810 | /* | |
1811 | * Corresponding get() is in _scsih_target_alloc() | |
1812 | */ | |
d88e1eab | 1813 | sas_target_priv_data->sas_dev = NULL; |
d1cb5e49 SR |
1814 | sas_device_put(sas_device); |
1815 | ||
1816 | sas_device_put(sas_device); | |
1817 | } | |
f92363d1 SR |
1818 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
1819 | ||
1820 | out: | |
1821 | kfree(sas_target_priv_data); | |
1822 | starget->hostdata = NULL; | |
1823 | } | |
1824 | ||
1825 | /** | |
8a7e4c24 | 1826 | * scsih_slave_alloc - device add routine |
f92363d1 SR |
1827 | * @sdev: scsi device struct |
1828 | * | |
4beb4867 | 1829 | * Return: 0 if ok. Any other return is assumed to be an error and |
f92363d1 SR |
1830 | * the device is ignored. |
1831 | */ | |
8bbb1cf6 | 1832 | static int |
8a7e4c24 | 1833 | scsih_slave_alloc(struct scsi_device *sdev) |
f92363d1 SR |
1834 | { |
1835 | struct Scsi_Host *shost; | |
1836 | struct MPT3SAS_ADAPTER *ioc; | |
1837 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1838 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
1839 | struct scsi_target *starget; | |
1840 | struct _raid_device *raid_device; | |
b65cfedf | 1841 | struct _sas_device *sas_device; |
d88e1eab | 1842 | struct _pcie_device *pcie_device; |
f92363d1 SR |
1843 | unsigned long flags; |
1844 | ||
62c4da44 JL |
1845 | sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data), |
1846 | GFP_KERNEL); | |
f92363d1 SR |
1847 | if (!sas_device_priv_data) |
1848 | return -ENOMEM; | |
1849 | ||
1850 | sas_device_priv_data->lun = sdev->lun; | |
1851 | sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT; | |
1852 | ||
1853 | starget = scsi_target(sdev); | |
1854 | sas_target_priv_data = starget->hostdata; | |
1855 | sas_target_priv_data->num_luns++; | |
1856 | sas_device_priv_data->sas_target = sas_target_priv_data; | |
1857 | sdev->hostdata = sas_device_priv_data; | |
1858 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT)) | |
1859 | sdev->no_uld_attach = 1; | |
1860 | ||
1861 | shost = dev_to_shost(&starget->dev); | |
1862 | ioc = shost_priv(shost); | |
1863 | if (starget->channel == RAID_CHANNEL) { | |
1864 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1865 | raid_device = _scsih_raid_device_find_by_id(ioc, | |
1866 | starget->id, starget->channel); | |
1867 | if (raid_device) | |
1868 | raid_device->sdev = sdev; /* raid is single lun */ | |
1869 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1870 | } | |
d88e1eab SPS |
1871 | if (starget->channel == PCIE_CHANNEL) { |
1872 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1873 | pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, | |
1874 | sas_target_priv_data->sas_address); | |
1875 | if (pcie_device && (pcie_device->starget == NULL)) { | |
1876 | sdev_printk(KERN_INFO, sdev, | |
1877 | "%s : pcie_device->starget set to starget @ %d\n", | |
1878 | __func__, __LINE__); | |
1879 | pcie_device->starget = starget; | |
1880 | } | |
1881 | ||
1882 | if (pcie_device) | |
1883 | pcie_device_put(pcie_device); | |
1884 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
f92363d1 | 1885 | |
d88e1eab | 1886 | } else if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { |
b65cfedf | 1887 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 1888 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
b65cfedf SR |
1889 | sas_target_priv_data->sas_address); |
1890 | if (sas_device && (sas_device->starget == NULL)) { | |
1891 | sdev_printk(KERN_INFO, sdev, | |
1892 | "%s : sas_device->starget set to starget @ %d\n", | |
d1cb5e49 | 1893 | __func__, __LINE__); |
b65cfedf SR |
1894 | sas_device->starget = starget; |
1895 | } | |
d1cb5e49 SR |
1896 | |
1897 | if (sas_device) | |
1898 | sas_device_put(sas_device); | |
1899 | ||
b65cfedf SR |
1900 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
1901 | } | |
1902 | ||
f92363d1 SR |
1903 | return 0; |
1904 | } | |
1905 | ||
1906 | /** | |
8a7e4c24 | 1907 | * scsih_slave_destroy - device destroy routine |
f92363d1 | 1908 | * @sdev: scsi device struct |
f92363d1 | 1909 | */ |
8bbb1cf6 | 1910 | static void |
8a7e4c24 | 1911 | scsih_slave_destroy(struct scsi_device *sdev) |
f92363d1 SR |
1912 | { |
1913 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1914 | struct scsi_target *starget; | |
1915 | struct Scsi_Host *shost; | |
1916 | struct MPT3SAS_ADAPTER *ioc; | |
1917 | struct _sas_device *sas_device; | |
d88e1eab | 1918 | struct _pcie_device *pcie_device; |
f92363d1 SR |
1919 | unsigned long flags; |
1920 | ||
1921 | if (!sdev->hostdata) | |
1922 | return; | |
1923 | ||
1924 | starget = scsi_target(sdev); | |
1925 | sas_target_priv_data = starget->hostdata; | |
1926 | sas_target_priv_data->num_luns--; | |
1927 | ||
1928 | shost = dev_to_shost(&starget->dev); | |
1929 | ioc = shost_priv(shost); | |
1930 | ||
d88e1eab SPS |
1931 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) { |
1932 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1933 | pcie_device = __mpt3sas_get_pdev_from_target(ioc, | |
1934 | sas_target_priv_data); | |
1935 | if (pcie_device && !sas_target_priv_data->num_luns) | |
1936 | pcie_device->starget = NULL; | |
1937 | ||
1938 | if (pcie_device) | |
1939 | pcie_device_put(pcie_device); | |
1940 | ||
1941 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1942 | ||
1943 | } else if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { | |
f92363d1 | 1944 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 SR |
1945 | sas_device = __mpt3sas_get_sdev_from_target(ioc, |
1946 | sas_target_priv_data); | |
f92363d1 SR |
1947 | if (sas_device && !sas_target_priv_data->num_luns) |
1948 | sas_device->starget = NULL; | |
d1cb5e49 SR |
1949 | |
1950 | if (sas_device) | |
1951 | sas_device_put(sas_device); | |
f92363d1 SR |
1952 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
1953 | } | |
1954 | ||
1955 | kfree(sdev->hostdata); | |
1956 | sdev->hostdata = NULL; | |
1957 | } | |
1958 | ||
1959 | /** | |
1960 | * _scsih_display_sata_capabilities - sata capabilities | |
1961 | * @ioc: per adapter object | |
1962 | * @handle: device handle | |
1963 | * @sdev: scsi device struct | |
1964 | */ | |
1965 | static void | |
1966 | _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc, | |
1967 | u16 handle, struct scsi_device *sdev) | |
1968 | { | |
1969 | Mpi2ConfigReply_t mpi_reply; | |
1970 | Mpi2SasDevicePage0_t sas_device_pg0; | |
1971 | u32 ioc_status; | |
1972 | u16 flags; | |
1973 | u32 device_info; | |
1974 | ||
1975 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
1976 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
919d8a3f JP |
1977 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
1978 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
1979 | return; |
1980 | } | |
1981 | ||
1982 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
1983 | MPI2_IOCSTATUS_MASK; | |
1984 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
919d8a3f JP |
1985 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
1986 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
1987 | return; |
1988 | } | |
1989 | ||
1990 | flags = le16_to_cpu(sas_device_pg0.Flags); | |
1991 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | |
1992 | ||
1993 | sdev_printk(KERN_INFO, sdev, | |
1994 | "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), " | |
1995 | "sw_preserve(%s)\n", | |
1996 | (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n", | |
1997 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n", | |
1998 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" : | |
1999 | "n", | |
2000 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n", | |
2001 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n", | |
2002 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n"); | |
2003 | } | |
2004 | ||
2005 | /* | |
2006 | * raid transport support - | |
2007 | * Enabled for SLES11 and newer, in older kernels the driver will panic when | |
6c7abffc | 2008 | * unloading the driver followed by a load - I believe that the subroutine |
f92363d1 SR |
2009 | * raid_class_release() is not cleaning up properly. |
2010 | */ | |
2011 | ||
2012 | /** | |
8a7e4c24 | 2013 | * scsih_is_raid - return boolean indicating device is raid volume |
4beb4867 | 2014 | * @dev: the device struct object |
f92363d1 | 2015 | */ |
8bbb1cf6 | 2016 | static int |
8a7e4c24 | 2017 | scsih_is_raid(struct device *dev) |
f92363d1 SR |
2018 | { |
2019 | struct scsi_device *sdev = to_scsi_device(dev); | |
7786ab6a | 2020 | struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host); |
f92363d1 | 2021 | |
7786ab6a SR |
2022 | if (ioc->is_warpdrive) |
2023 | return 0; | |
f92363d1 SR |
2024 | return (sdev->channel == RAID_CHANNEL) ? 1 : 0; |
2025 | } | |
2026 | ||
cd5897ed SPS |
2027 | static int |
2028 | scsih_is_nvme(struct device *dev) | |
2029 | { | |
2030 | struct scsi_device *sdev = to_scsi_device(dev); | |
2031 | ||
2032 | return (sdev->channel == PCIE_CHANNEL) ? 1 : 0; | |
2033 | } | |
2034 | ||
f92363d1 | 2035 | /** |
8a7e4c24 | 2036 | * scsih_get_resync - get raid volume resync percent complete |
4beb4867 | 2037 | * @dev: the device struct object |
f92363d1 | 2038 | */ |
8bbb1cf6 | 2039 | static void |
8a7e4c24 | 2040 | scsih_get_resync(struct device *dev) |
f92363d1 SR |
2041 | { |
2042 | struct scsi_device *sdev = to_scsi_device(dev); | |
2043 | struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host); | |
2044 | static struct _raid_device *raid_device; | |
2045 | unsigned long flags; | |
2046 | Mpi2RaidVolPage0_t vol_pg0; | |
2047 | Mpi2ConfigReply_t mpi_reply; | |
2048 | u32 volume_status_flags; | |
2049 | u8 percent_complete; | |
2050 | u16 handle; | |
2051 | ||
2052 | percent_complete = 0; | |
2053 | handle = 0; | |
7786ab6a SR |
2054 | if (ioc->is_warpdrive) |
2055 | goto out; | |
2056 | ||
f92363d1 SR |
2057 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
2058 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, | |
2059 | sdev->channel); | |
2060 | if (raid_device) { | |
2061 | handle = raid_device->handle; | |
2062 | percent_complete = raid_device->percent_complete; | |
2063 | } | |
2064 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
2065 | ||
2066 | if (!handle) | |
2067 | goto out; | |
2068 | ||
2069 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0, | |
2070 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
2071 | sizeof(Mpi2RaidVolPage0_t))) { | |
919d8a3f JP |
2072 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
2073 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
2074 | percent_complete = 0; |
2075 | goto out; | |
2076 | } | |
2077 | ||
2078 | volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags); | |
2079 | if (!(volume_status_flags & | |
2080 | MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)) | |
2081 | percent_complete = 0; | |
2082 | ||
2083 | out: | |
b130b0d5 SS |
2084 | |
2085 | switch (ioc->hba_mpi_version_belonged) { | |
2086 | case MPI2_VERSION: | |
c84b06a4 | 2087 | raid_set_resync(mpt2sas_raid_template, dev, percent_complete); |
b130b0d5 SS |
2088 | break; |
2089 | case MPI25_VERSION: | |
2090 | case MPI26_VERSION: | |
c84b06a4 | 2091 | raid_set_resync(mpt3sas_raid_template, dev, percent_complete); |
b130b0d5 SS |
2092 | break; |
2093 | } | |
f92363d1 SR |
2094 | } |
2095 | ||
2096 | /** | |
8a7e4c24 | 2097 | * scsih_get_state - get raid volume level |
4beb4867 | 2098 | * @dev: the device struct object |
f92363d1 | 2099 | */ |
8bbb1cf6 | 2100 | static void |
8a7e4c24 | 2101 | scsih_get_state(struct device *dev) |
f92363d1 SR |
2102 | { |
2103 | struct scsi_device *sdev = to_scsi_device(dev); | |
2104 | struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host); | |
2105 | static struct _raid_device *raid_device; | |
2106 | unsigned long flags; | |
2107 | Mpi2RaidVolPage0_t vol_pg0; | |
2108 | Mpi2ConfigReply_t mpi_reply; | |
2109 | u32 volstate; | |
2110 | enum raid_state state = RAID_STATE_UNKNOWN; | |
2111 | u16 handle = 0; | |
2112 | ||
2113 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
2114 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, | |
2115 | sdev->channel); | |
2116 | if (raid_device) | |
2117 | handle = raid_device->handle; | |
2118 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
2119 | ||
2120 | if (!raid_device) | |
2121 | goto out; | |
2122 | ||
2123 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0, | |
2124 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
2125 | sizeof(Mpi2RaidVolPage0_t))) { | |
919d8a3f JP |
2126 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
2127 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
2128 | goto out; |
2129 | } | |
2130 | ||
2131 | volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags); | |
2132 | if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) { | |
2133 | state = RAID_STATE_RESYNCING; | |
2134 | goto out; | |
2135 | } | |
2136 | ||
2137 | switch (vol_pg0.VolumeState) { | |
2138 | case MPI2_RAID_VOL_STATE_OPTIMAL: | |
2139 | case MPI2_RAID_VOL_STATE_ONLINE: | |
2140 | state = RAID_STATE_ACTIVE; | |
2141 | break; | |
2142 | case MPI2_RAID_VOL_STATE_DEGRADED: | |
2143 | state = RAID_STATE_DEGRADED; | |
2144 | break; | |
2145 | case MPI2_RAID_VOL_STATE_FAILED: | |
2146 | case MPI2_RAID_VOL_STATE_MISSING: | |
2147 | state = RAID_STATE_OFFLINE; | |
2148 | break; | |
2149 | } | |
2150 | out: | |
b130b0d5 SS |
2151 | switch (ioc->hba_mpi_version_belonged) { |
2152 | case MPI2_VERSION: | |
c84b06a4 | 2153 | raid_set_state(mpt2sas_raid_template, dev, state); |
b130b0d5 SS |
2154 | break; |
2155 | case MPI25_VERSION: | |
2156 | case MPI26_VERSION: | |
c84b06a4 | 2157 | raid_set_state(mpt3sas_raid_template, dev, state); |
b130b0d5 SS |
2158 | break; |
2159 | } | |
f92363d1 SR |
2160 | } |
2161 | ||
2162 | /** | |
2163 | * _scsih_set_level - set raid level | |
4beb4867 | 2164 | * @ioc: ? |
f92363d1 SR |
2165 | * @sdev: scsi device struct |
2166 | * @volume_type: volume type | |
2167 | */ | |
2168 | static void | |
c84b06a4 SR |
2169 | _scsih_set_level(struct MPT3SAS_ADAPTER *ioc, |
2170 | struct scsi_device *sdev, u8 volume_type) | |
f92363d1 SR |
2171 | { |
2172 | enum raid_level level = RAID_LEVEL_UNKNOWN; | |
2173 | ||
2174 | switch (volume_type) { | |
2175 | case MPI2_RAID_VOL_TYPE_RAID0: | |
2176 | level = RAID_LEVEL_0; | |
2177 | break; | |
2178 | case MPI2_RAID_VOL_TYPE_RAID10: | |
2179 | level = RAID_LEVEL_10; | |
2180 | break; | |
2181 | case MPI2_RAID_VOL_TYPE_RAID1E: | |
2182 | level = RAID_LEVEL_1E; | |
2183 | break; | |
2184 | case MPI2_RAID_VOL_TYPE_RAID1: | |
2185 | level = RAID_LEVEL_1; | |
2186 | break; | |
2187 | } | |
2188 | ||
b130b0d5 SS |
2189 | switch (ioc->hba_mpi_version_belonged) { |
2190 | case MPI2_VERSION: | |
c84b06a4 | 2191 | raid_set_level(mpt2sas_raid_template, |
b130b0d5 SS |
2192 | &sdev->sdev_gendev, level); |
2193 | break; | |
2194 | case MPI25_VERSION: | |
2195 | case MPI26_VERSION: | |
c84b06a4 | 2196 | raid_set_level(mpt3sas_raid_template, |
b130b0d5 SS |
2197 | &sdev->sdev_gendev, level); |
2198 | break; | |
2199 | } | |
f92363d1 SR |
2200 | } |
2201 | ||
2202 | ||
2203 | /** | |
2204 | * _scsih_get_volume_capabilities - volume capabilities | |
2205 | * @ioc: per adapter object | |
4beb4867 | 2206 | * @raid_device: the raid_device object |
f92363d1 | 2207 | * |
4beb4867 | 2208 | * Return: 0 for success, else 1 |
f92363d1 SR |
2209 | */ |
2210 | static int | |
2211 | _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc, | |
2212 | struct _raid_device *raid_device) | |
2213 | { | |
2214 | Mpi2RaidVolPage0_t *vol_pg0; | |
2215 | Mpi2RaidPhysDiskPage0_t pd_pg0; | |
2216 | Mpi2SasDevicePage0_t sas_device_pg0; | |
2217 | Mpi2ConfigReply_t mpi_reply; | |
2218 | u16 sz; | |
2219 | u8 num_pds; | |
2220 | ||
2221 | if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle, | |
2222 | &num_pds)) || !num_pds) { | |
919d8a3f JP |
2223 | dfailprintk(ioc, |
2224 | ioc_warn(ioc, "failure at %s:%d/%s()!\n", | |
2225 | __FILE__, __LINE__, __func__)); | |
f92363d1 SR |
2226 | return 1; |
2227 | } | |
2228 | ||
2229 | raid_device->num_pds = num_pds; | |
2230 | sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds * | |
2231 | sizeof(Mpi2RaidVol0PhysDisk_t)); | |
2232 | vol_pg0 = kzalloc(sz, GFP_KERNEL); | |
2233 | if (!vol_pg0) { | |
919d8a3f JP |
2234 | dfailprintk(ioc, |
2235 | ioc_warn(ioc, "failure at %s:%d/%s()!\n", | |
2236 | __FILE__, __LINE__, __func__)); | |
f92363d1 SR |
2237 | return 1; |
2238 | } | |
2239 | ||
2240 | if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0, | |
2241 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) { | |
919d8a3f JP |
2242 | dfailprintk(ioc, |
2243 | ioc_warn(ioc, "failure at %s:%d/%s()!\n", | |
2244 | __FILE__, __LINE__, __func__)); | |
f92363d1 SR |
2245 | kfree(vol_pg0); |
2246 | return 1; | |
2247 | } | |
2248 | ||
2249 | raid_device->volume_type = vol_pg0->VolumeType; | |
2250 | ||
2251 | /* figure out what the underlying devices are by | |
2252 | * obtaining the device_info bits for the 1st device | |
2253 | */ | |
2254 | if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | |
2255 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM, | |
2256 | vol_pg0->PhysDisk[0].PhysDiskNum))) { | |
2257 | if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
2258 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | |
2259 | le16_to_cpu(pd_pg0.DevHandle)))) { | |
2260 | raid_device->device_info = | |
2261 | le32_to_cpu(sas_device_pg0.DeviceInfo); | |
2262 | } | |
2263 | } | |
2264 | ||
2265 | kfree(vol_pg0); | |
2266 | return 0; | |
2267 | } | |
2268 | ||
f92363d1 SR |
2269 | /** |
2270 | * _scsih_enable_tlr - setting TLR flags | |
2271 | * @ioc: per adapter object | |
2272 | * @sdev: scsi device struct | |
2273 | * | |
2274 | * Enabling Transaction Layer Retries for tape devices when | |
2275 | * vpd page 0x90 is present | |
2276 | * | |
2277 | */ | |
2278 | static void | |
2279 | _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev) | |
2280 | { | |
2281 | ||
2282 | /* only for TAPE */ | |
2283 | if (sdev->type != TYPE_TAPE) | |
2284 | return; | |
2285 | ||
2286 | if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR)) | |
2287 | return; | |
2288 | ||
2289 | sas_enable_tlr(sdev); | |
2290 | sdev_printk(KERN_INFO, sdev, "TLR %s\n", | |
2291 | sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled"); | |
2292 | return; | |
2293 | ||
2294 | } | |
2295 | ||
2296 | /** | |
8a7e4c24 | 2297 | * scsih_slave_configure - device configure routine. |
f92363d1 SR |
2298 | * @sdev: scsi device struct |
2299 | * | |
4beb4867 | 2300 | * Return: 0 if ok. Any other return is assumed to be an error and |
f92363d1 SR |
2301 | * the device is ignored. |
2302 | */ | |
8bbb1cf6 | 2303 | static int |
8a7e4c24 | 2304 | scsih_slave_configure(struct scsi_device *sdev) |
f92363d1 SR |
2305 | { |
2306 | struct Scsi_Host *shost = sdev->host; | |
2307 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
2308 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2309 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
2310 | struct _sas_device *sas_device; | |
d1b01d14 | 2311 | struct _pcie_device *pcie_device; |
f92363d1 SR |
2312 | struct _raid_device *raid_device; |
2313 | unsigned long flags; | |
2314 | int qdepth; | |
2315 | u8 ssp_target = 0; | |
2316 | char *ds = ""; | |
2317 | char *r_level = ""; | |
2318 | u16 handle, volume_handle = 0; | |
2319 | u64 volume_wwid = 0; | |
2320 | ||
2321 | qdepth = 1; | |
2322 | sas_device_priv_data = sdev->hostdata; | |
2323 | sas_device_priv_data->configured_lun = 1; | |
2324 | sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT; | |
2325 | sas_target_priv_data = sas_device_priv_data->sas_target; | |
2326 | handle = sas_target_priv_data->handle; | |
2327 | ||
2328 | /* raid volume handling */ | |
2329 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) { | |
2330 | ||
2331 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
c84b06a4 | 2332 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
2333 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
2334 | if (!raid_device) { | |
919d8a3f JP |
2335 | dfailprintk(ioc, |
2336 | ioc_warn(ioc, "failure at %s:%d/%s()!\n", | |
2337 | __FILE__, __LINE__, __func__)); | |
f92363d1 SR |
2338 | return 1; |
2339 | } | |
2340 | ||
2341 | if (_scsih_get_volume_capabilities(ioc, raid_device)) { | |
919d8a3f JP |
2342 | dfailprintk(ioc, |
2343 | ioc_warn(ioc, "failure at %s:%d/%s()!\n", | |
2344 | __FILE__, __LINE__, __func__)); | |
f92363d1 SR |
2345 | return 1; |
2346 | } | |
2347 | ||
7786ab6a SR |
2348 | /* |
2349 | * WARPDRIVE: Initialize the required data for Direct IO | |
2350 | */ | |
c84b06a4 | 2351 | mpt3sas_init_warpdrive_properties(ioc, raid_device); |
f92363d1 SR |
2352 | |
2353 | /* RAID Queue Depth Support | |
2354 | * IS volume = underlying qdepth of drive type, either | |
2355 | * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH | |
2356 | * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH) | |
2357 | */ | |
2358 | if (raid_device->device_info & | |
2359 | MPI2_SAS_DEVICE_INFO_SSP_TARGET) { | |
2360 | qdepth = MPT3SAS_SAS_QUEUE_DEPTH; | |
2361 | ds = "SSP"; | |
2362 | } else { | |
2363 | qdepth = MPT3SAS_SATA_QUEUE_DEPTH; | |
199fd79a | 2364 | if (raid_device->device_info & |
f92363d1 SR |
2365 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) |
2366 | ds = "SATA"; | |
2367 | else | |
2368 | ds = "STP"; | |
2369 | } | |
2370 | ||
2371 | switch (raid_device->volume_type) { | |
2372 | case MPI2_RAID_VOL_TYPE_RAID0: | |
2373 | r_level = "RAID0"; | |
2374 | break; | |
2375 | case MPI2_RAID_VOL_TYPE_RAID1E: | |
2376 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
2377 | if (ioc->manu_pg10.OEMIdentifier && | |
2378 | (le32_to_cpu(ioc->manu_pg10.GenericFlags0) & | |
2379 | MFG10_GF0_R10_DISPLAY) && | |
2380 | !(raid_device->num_pds % 2)) | |
2381 | r_level = "RAID10"; | |
2382 | else | |
2383 | r_level = "RAID1E"; | |
2384 | break; | |
2385 | case MPI2_RAID_VOL_TYPE_RAID1: | |
2386 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
2387 | r_level = "RAID1"; | |
2388 | break; | |
2389 | case MPI2_RAID_VOL_TYPE_RAID10: | |
2390 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
2391 | r_level = "RAID10"; | |
2392 | break; | |
2393 | case MPI2_RAID_VOL_TYPE_UNKNOWN: | |
2394 | default: | |
2395 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
2396 | r_level = "RAIDX"; | |
2397 | break; | |
2398 | } | |
2399 | ||
7786ab6a SR |
2400 | if (!ioc->hide_ir_msg) |
2401 | sdev_printk(KERN_INFO, sdev, | |
2402 | "%s: handle(0x%04x), wwid(0x%016llx)," | |
2403 | " pd_count(%d), type(%s)\n", | |
2404 | r_level, raid_device->handle, | |
2405 | (unsigned long long)raid_device->wwid, | |
2406 | raid_device->num_pds, ds); | |
f92363d1 | 2407 | |
6c197093 C |
2408 | if (shost->max_sectors > MPT3SAS_RAID_MAX_SECTORS) { |
2409 | blk_queue_max_hw_sectors(sdev->request_queue, | |
2410 | MPT3SAS_RAID_MAX_SECTORS); | |
2411 | sdev_printk(KERN_INFO, sdev, | |
2412 | "Set queue's max_sector to: %u\n", | |
2413 | MPT3SAS_RAID_MAX_SECTORS); | |
2414 | } | |
2415 | ||
8dc8d29a | 2416 | mpt3sas_scsih_change_queue_depth(sdev, qdepth); |
f92363d1 | 2417 | |
7786ab6a SR |
2418 | /* raid transport support */ |
2419 | if (!ioc->is_warpdrive) | |
c84b06a4 | 2420 | _scsih_set_level(ioc, sdev, raid_device->volume_type); |
f92363d1 SR |
2421 | return 0; |
2422 | } | |
2423 | ||
2424 | /* non-raid handling */ | |
2425 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
2426 | if (mpt3sas_config_get_volume_handle(ioc, handle, | |
2427 | &volume_handle)) { | |
919d8a3f JP |
2428 | dfailprintk(ioc, |
2429 | ioc_warn(ioc, "failure at %s:%d/%s()!\n", | |
2430 | __FILE__, __LINE__, __func__)); | |
f92363d1 SR |
2431 | return 1; |
2432 | } | |
2433 | if (volume_handle && mpt3sas_config_get_volume_wwid(ioc, | |
2434 | volume_handle, &volume_wwid)) { | |
919d8a3f JP |
2435 | dfailprintk(ioc, |
2436 | ioc_warn(ioc, "failure at %s:%d/%s()!\n", | |
2437 | __FILE__, __LINE__, __func__)); | |
f92363d1 SR |
2438 | return 1; |
2439 | } | |
2440 | } | |
2441 | ||
d1b01d14 SPS |
2442 | /* PCIe handling */ |
2443 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) { | |
2444 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
2445 | pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, | |
2446 | sas_device_priv_data->sas_target->sas_address); | |
2447 | if (!pcie_device) { | |
2448 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
919d8a3f JP |
2449 | dfailprintk(ioc, |
2450 | ioc_warn(ioc, "failure at %s:%d/%s()!\n", | |
2451 | __FILE__, __LINE__, __func__)); | |
d1b01d14 SPS |
2452 | return 1; |
2453 | } | |
2454 | ||
2455 | qdepth = MPT3SAS_NVME_QUEUE_DEPTH; | |
2456 | ds = "NVMe"; | |
2457 | sdev_printk(KERN_INFO, sdev, | |
2458 | "%s: handle(0x%04x), wwid(0x%016llx), port(%d)\n", | |
2459 | ds, handle, (unsigned long long)pcie_device->wwid, | |
2460 | pcie_device->port_num); | |
2461 | if (pcie_device->enclosure_handle != 0) | |
2462 | sdev_printk(KERN_INFO, sdev, | |
2463 | "%s: enclosure logical id(0x%016llx), slot(%d)\n", | |
2464 | ds, | |
2465 | (unsigned long long)pcie_device->enclosure_logical_id, | |
2466 | pcie_device->slot); | |
2467 | if (pcie_device->connector_name[0] != '\0') | |
2468 | sdev_printk(KERN_INFO, sdev, | |
2469 | "%s: enclosure level(0x%04x)," | |
2470 | "connector name( %s)\n", ds, | |
2471 | pcie_device->enclosure_level, | |
2472 | pcie_device->connector_name); | |
d1b01d14 SPS |
2473 | |
2474 | if (pcie_device->nvme_mdts) | |
2475 | blk_queue_max_hw_sectors(sdev->request_queue, | |
2476 | pcie_device->nvme_mdts/512); | |
20a04433 C |
2477 | |
2478 | pcie_device_put(pcie_device); | |
2479 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
8dc8d29a | 2480 | mpt3sas_scsih_change_queue_depth(sdev, qdepth); |
d1b01d14 SPS |
2481 | /* Enable QUEUE_FLAG_NOMERGES flag, so that IOs won't be |
2482 | ** merged and can eliminate holes created during merging | |
2483 | ** operation. | |
2484 | **/ | |
8b904b5b | 2485 | blk_queue_flag_set(QUEUE_FLAG_NOMERGES, |
d1b01d14 SPS |
2486 | sdev->request_queue); |
2487 | blk_queue_virt_boundary(sdev->request_queue, | |
2488 | ioc->page_size - 1); | |
2489 | return 0; | |
2490 | } | |
2491 | ||
f92363d1 | 2492 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 2493 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 SR |
2494 | sas_device_priv_data->sas_target->sas_address); |
2495 | if (!sas_device) { | |
2496 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
919d8a3f JP |
2497 | dfailprintk(ioc, |
2498 | ioc_warn(ioc, "failure at %s:%d/%s()!\n", | |
2499 | __FILE__, __LINE__, __func__)); | |
f92363d1 SR |
2500 | return 1; |
2501 | } | |
2502 | ||
2503 | sas_device->volume_handle = volume_handle; | |
2504 | sas_device->volume_wwid = volume_wwid; | |
2505 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) { | |
2506 | qdepth = MPT3SAS_SAS_QUEUE_DEPTH; | |
2507 | ssp_target = 1; | |
30158dc9 SS |
2508 | if (sas_device->device_info & |
2509 | MPI2_SAS_DEVICE_INFO_SEP) { | |
2510 | sdev_printk(KERN_WARNING, sdev, | |
2511 | "set ignore_delay_remove for handle(0x%04x)\n", | |
2512 | sas_device_priv_data->sas_target->handle); | |
2513 | sas_device_priv_data->ignore_delay_remove = 1; | |
2514 | ds = "SES"; | |
2515 | } else | |
2516 | ds = "SSP"; | |
f92363d1 SR |
2517 | } else { |
2518 | qdepth = MPT3SAS_SATA_QUEUE_DEPTH; | |
2519 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) | |
2520 | ds = "STP"; | |
2521 | else if (sas_device->device_info & | |
2522 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) | |
2523 | ds = "SATA"; | |
2524 | } | |
2525 | ||
2526 | sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \ | |
2527 | "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n", | |
2528 | ds, handle, (unsigned long long)sas_device->sas_address, | |
2529 | sas_device->phy, (unsigned long long)sas_device->device_name); | |
75888956 SR |
2530 | |
2531 | _scsih_display_enclosure_chassis_info(NULL, sas_device, sdev, NULL); | |
f92363d1 | 2532 | |
d1cb5e49 | 2533 | sas_device_put(sas_device); |
f92363d1 SR |
2534 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
2535 | ||
2536 | if (!ssp_target) | |
2537 | _scsih_display_sata_capabilities(ioc, handle, sdev); | |
2538 | ||
2539 | ||
8dc8d29a | 2540 | mpt3sas_scsih_change_queue_depth(sdev, qdepth); |
f92363d1 SR |
2541 | |
2542 | if (ssp_target) { | |
2543 | sas_read_port_mode_page(sdev); | |
2544 | _scsih_enable_tlr(ioc, sdev); | |
2545 | } | |
2546 | ||
2547 | return 0; | |
2548 | } | |
2549 | ||
2550 | /** | |
8a7e4c24 | 2551 | * scsih_bios_param - fetch head, sector, cylinder info for a disk |
f92363d1 SR |
2552 | * @sdev: scsi device struct |
2553 | * @bdev: pointer to block device context | |
2554 | * @capacity: device size (in 512 byte sectors) | |
2555 | * @params: three element array to place output: | |
2556 | * params[0] number of heads (max 255) | |
2557 | * params[1] number of sectors (max 63) | |
2558 | * params[2] number of cylinders | |
f92363d1 | 2559 | */ |
8bbb1cf6 | 2560 | static int |
8a7e4c24 | 2561 | scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev, |
f92363d1 SR |
2562 | sector_t capacity, int params[]) |
2563 | { | |
2564 | int heads; | |
2565 | int sectors; | |
2566 | sector_t cylinders; | |
2567 | ulong dummy; | |
2568 | ||
2569 | heads = 64; | |
2570 | sectors = 32; | |
2571 | ||
2572 | dummy = heads * sectors; | |
2573 | cylinders = capacity; | |
2574 | sector_div(cylinders, dummy); | |
2575 | ||
2576 | /* | |
2577 | * Handle extended translation size for logical drives | |
2578 | * > 1Gb | |
2579 | */ | |
2580 | if ((ulong)capacity >= 0x200000) { | |
2581 | heads = 255; | |
2582 | sectors = 63; | |
2583 | dummy = heads * sectors; | |
2584 | cylinders = capacity; | |
2585 | sector_div(cylinders, dummy); | |
2586 | } | |
2587 | ||
2588 | /* return result */ | |
2589 | params[0] = heads; | |
2590 | params[1] = sectors; | |
2591 | params[2] = cylinders; | |
2592 | ||
2593 | return 0; | |
2594 | } | |
2595 | ||
2596 | /** | |
2597 | * _scsih_response_code - translation of device response code | |
2598 | * @ioc: per adapter object | |
2599 | * @response_code: response code returned by the device | |
f92363d1 SR |
2600 | */ |
2601 | static void | |
2602 | _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code) | |
2603 | { | |
2604 | char *desc; | |
2605 | ||
2606 | switch (response_code) { | |
2607 | case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE: | |
2608 | desc = "task management request completed"; | |
2609 | break; | |
2610 | case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME: | |
2611 | desc = "invalid frame"; | |
2612 | break; | |
2613 | case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED: | |
2614 | desc = "task management request not supported"; | |
2615 | break; | |
2616 | case MPI2_SCSITASKMGMT_RSP_TM_FAILED: | |
2617 | desc = "task management request failed"; | |
2618 | break; | |
2619 | case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED: | |
2620 | desc = "task management request succeeded"; | |
2621 | break; | |
2622 | case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN: | |
2623 | desc = "invalid lun"; | |
2624 | break; | |
2625 | case 0xA: | |
2626 | desc = "overlapped tag attempted"; | |
2627 | break; | |
2628 | case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC: | |
2629 | desc = "task queued, however not sent to target"; | |
2630 | break; | |
2631 | default: | |
2632 | desc = "unknown"; | |
2633 | break; | |
2634 | } | |
919d8a3f | 2635 | ioc_warn(ioc, "response_code(0x%01x): %s\n", response_code, desc); |
f92363d1 SR |
2636 | } |
2637 | ||
2638 | /** | |
2639 | * _scsih_tm_done - tm completion routine | |
2640 | * @ioc: per adapter object | |
2641 | * @smid: system request message index | |
2642 | * @msix_index: MSIX table index supplied by the OS | |
2643 | * @reply: reply message frame(lower 32bit addr) | |
2644 | * Context: none. | |
2645 | * | |
2646 | * The callback handler when using scsih_issue_tm. | |
2647 | * | |
4beb4867 BVA |
2648 | * Return: 1 meaning mf should be freed from _base_interrupt |
2649 | * 0 means the mf is freed from this function. | |
f92363d1 SR |
2650 | */ |
2651 | static u8 | |
2652 | _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | |
2653 | { | |
2654 | MPI2DefaultReply_t *mpi_reply; | |
2655 | ||
2656 | if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED) | |
2657 | return 1; | |
2658 | if (ioc->tm_cmds.smid != smid) | |
2659 | return 1; | |
f92363d1 SR |
2660 | ioc->tm_cmds.status |= MPT3_CMD_COMPLETE; |
2661 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
2662 | if (mpi_reply) { | |
2663 | memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); | |
2664 | ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID; | |
2665 | } | |
2666 | ioc->tm_cmds.status &= ~MPT3_CMD_PENDING; | |
2667 | complete(&ioc->tm_cmds.done); | |
2668 | return 1; | |
2669 | } | |
2670 | ||
2671 | /** | |
2672 | * mpt3sas_scsih_set_tm_flag - set per target tm_busy | |
2673 | * @ioc: per adapter object | |
2674 | * @handle: device handle | |
2675 | * | |
2676 | * During taskmangement request, we need to freeze the device queue. | |
2677 | */ | |
2678 | void | |
2679 | mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
2680 | { | |
2681 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2682 | struct scsi_device *sdev; | |
2683 | u8 skip = 0; | |
2684 | ||
2685 | shost_for_each_device(sdev, ioc->shost) { | |
2686 | if (skip) | |
2687 | continue; | |
2688 | sas_device_priv_data = sdev->hostdata; | |
2689 | if (!sas_device_priv_data) | |
2690 | continue; | |
2691 | if (sas_device_priv_data->sas_target->handle == handle) { | |
2692 | sas_device_priv_data->sas_target->tm_busy = 1; | |
2693 | skip = 1; | |
2694 | ioc->ignore_loginfos = 1; | |
2695 | } | |
2696 | } | |
2697 | } | |
2698 | ||
2699 | /** | |
2700 | * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy | |
2701 | * @ioc: per adapter object | |
2702 | * @handle: device handle | |
2703 | * | |
2704 | * During taskmangement request, we need to freeze the device queue. | |
2705 | */ | |
2706 | void | |
2707 | mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
2708 | { | |
2709 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2710 | struct scsi_device *sdev; | |
2711 | u8 skip = 0; | |
2712 | ||
2713 | shost_for_each_device(sdev, ioc->shost) { | |
2714 | if (skip) | |
2715 | continue; | |
2716 | sas_device_priv_data = sdev->hostdata; | |
2717 | if (!sas_device_priv_data) | |
2718 | continue; | |
2719 | if (sas_device_priv_data->sas_target->handle == handle) { | |
2720 | sas_device_priv_data->sas_target->tm_busy = 0; | |
2721 | skip = 1; | |
2722 | ioc->ignore_loginfos = 0; | |
2723 | } | |
2724 | } | |
2725 | } | |
2726 | ||
2727 | /** | |
2728 | * mpt3sas_scsih_issue_tm - main routine for sending tm requests | |
2729 | * @ioc: per adapter struct | |
6da999fe | 2730 | * @handle: device handle |
f92363d1 SR |
2731 | * @lun: lun number |
2732 | * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h) | |
2733 | * @smid_task: smid assigned to the task | |
6da999fe | 2734 | * @msix_task: MSIX table index supplied by the OS |
f92363d1 | 2735 | * @timeout: timeout in seconds |
c1a6c5ac | 2736 | * @tr_method: Target Reset Method |
f92363d1 SR |
2737 | * Context: user |
2738 | * | |
2739 | * A generic API for sending task management requests to firmware. | |
2740 | * | |
2741 | * The callback index is set inside `ioc->tm_cb_idx`. | |
6da999fe | 2742 | * The caller is responsible to check for outstanding commands. |
f92363d1 | 2743 | * |
4beb4867 | 2744 | * Return: SUCCESS or FAILED. |
f92363d1 SR |
2745 | */ |
2746 | int | |
c1a6c5ac C |
2747 | mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, u64 lun, |
2748 | u8 type, u16 smid_task, u16 msix_task, u8 timeout, u8 tr_method) | |
f92363d1 SR |
2749 | { |
2750 | Mpi2SCSITaskManagementRequest_t *mpi_request; | |
2751 | Mpi2SCSITaskManagementReply_t *mpi_reply; | |
2752 | u16 smid = 0; | |
2753 | u32 ioc_state; | |
f92363d1 | 2754 | int rc; |
b3fe7efd | 2755 | u8 issue_reset = 0; |
f92363d1 | 2756 | |
96902835 CO |
2757 | lockdep_assert_held(&ioc->tm_cmds.mutex); |
2758 | ||
f92363d1 | 2759 | if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) { |
4dc74b2e | 2760 | ioc_info(ioc, "%s: tm_cmd busy!!!\n", __func__); |
96902835 | 2761 | return FAILED; |
f92363d1 SR |
2762 | } |
2763 | ||
2764 | if (ioc->shost_recovery || ioc->remove_host || | |
2765 | ioc->pci_error_recovery) { | |
4dc74b2e | 2766 | ioc_info(ioc, "%s: host reset in progress!\n", __func__); |
96902835 | 2767 | return FAILED; |
f92363d1 SR |
2768 | } |
2769 | ||
2770 | ioc_state = mpt3sas_base_get_iocstate(ioc, 0); | |
2771 | if (ioc_state & MPI2_DOORBELL_USED) { | |
919d8a3f | 2772 | dhsprintk(ioc, ioc_info(ioc, "unexpected doorbell active!\n")); |
98c56ad3 | 2773 | rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
96902835 | 2774 | return (!rc) ? SUCCESS : FAILED; |
f92363d1 SR |
2775 | } |
2776 | ||
2777 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { | |
e0a035be | 2778 | mpt3sas_print_fault_code(ioc, ioc_state & |
f92363d1 | 2779 | MPI2_DOORBELL_DATA_MASK); |
98c56ad3 | 2780 | rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
96902835 | 2781 | return (!rc) ? SUCCESS : FAILED; |
1de2bf7c SR |
2782 | } else if ((ioc_state & MPI2_IOC_STATE_MASK) == |
2783 | MPI2_IOC_STATE_COREDUMP) { | |
e0a035be | 2784 | mpt3sas_print_coredump_info(ioc, ioc_state & |
1de2bf7c SR |
2785 | MPI2_DOORBELL_DATA_MASK); |
2786 | rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); | |
2787 | return (!rc) ? SUCCESS : FAILED; | |
f92363d1 SR |
2788 | } |
2789 | ||
2790 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx); | |
2791 | if (!smid) { | |
919d8a3f | 2792 | ioc_err(ioc, "%s: failed obtaining a smid\n", __func__); |
96902835 | 2793 | return FAILED; |
f92363d1 SR |
2794 | } |
2795 | ||
919d8a3f JP |
2796 | dtmprintk(ioc, |
2797 | ioc_info(ioc, "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d), timeout(%d), tr_method(0x%x)\n", | |
2798 | handle, type, smid_task, timeout, tr_method)); | |
f92363d1 SR |
2799 | ioc->tm_cmds.status = MPT3_CMD_PENDING; |
2800 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
2801 | ioc->tm_cmds.smid = smid; | |
2802 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | |
2803 | memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t)); | |
2804 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | |
2805 | mpi_request->DevHandle = cpu_to_le16(handle); | |
2806 | mpi_request->TaskType = type; | |
c1a6c5ac | 2807 | mpi_request->MsgFlags = tr_method; |
f92363d1 SR |
2808 | mpi_request->TaskMID = cpu_to_le16(smid_task); |
2809 | int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN); | |
2810 | mpt3sas_scsih_set_tm_flag(ioc, handle); | |
2811 | init_completion(&ioc->tm_cmds.done); | |
078a4cc1 | 2812 | ioc->put_smid_hi_priority(ioc, smid, msix_task); |
8bbb1cf6 | 2813 | wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ); |
f92363d1 | 2814 | if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) { |
b3fe7efd SR |
2815 | mpt3sas_check_cmd_timeout(ioc, |
2816 | ioc->tm_cmds.status, mpi_request, | |
2817 | sizeof(Mpi2SCSITaskManagementRequest_t)/4, issue_reset); | |
2818 | if (issue_reset) { | |
98c56ad3 CO |
2819 | rc = mpt3sas_base_hard_reset_handler(ioc, |
2820 | FORCE_BIG_HAMMER); | |
f92363d1 | 2821 | rc = (!rc) ? SUCCESS : FAILED; |
96902835 | 2822 | goto out; |
f92363d1 SR |
2823 | } |
2824 | } | |
2825 | ||
5f0dfb7a C |
2826 | /* sync IRQs in case those were busy during flush. */ |
2827 | mpt3sas_base_sync_reply_irqs(ioc); | |
2828 | ||
f92363d1 SR |
2829 | if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) { |
2830 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT); | |
2831 | mpi_reply = ioc->tm_cmds.reply; | |
919d8a3f JP |
2832 | dtmprintk(ioc, |
2833 | ioc_info(ioc, "complete tm: ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n", | |
2834 | le16_to_cpu(mpi_reply->IOCStatus), | |
2835 | le32_to_cpu(mpi_reply->IOCLogInfo), | |
2836 | le32_to_cpu(mpi_reply->TerminationCount))); | |
f92363d1 SR |
2837 | if (ioc->logging_level & MPT_DEBUG_TM) { |
2838 | _scsih_response_code(ioc, mpi_reply->ResponseCode); | |
2839 | if (mpi_reply->IOCStatus) | |
2840 | _debug_dump_mf(mpi_request, | |
2841 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); | |
2842 | } | |
2843 | } | |
6da999fe | 2844 | rc = SUCCESS; |
f92363d1 | 2845 | |
96902835 | 2846 | out: |
f92363d1 SR |
2847 | mpt3sas_scsih_clear_tm_flag(ioc, handle); |
2848 | ioc->tm_cmds.status = MPT3_CMD_NOT_USED; | |
f92363d1 | 2849 | return rc; |
96902835 | 2850 | } |
f92363d1 | 2851 | |
96902835 | 2852 | int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, |
c1a6c5ac C |
2853 | u64 lun, u8 type, u16 smid_task, u16 msix_task, |
2854 | u8 timeout, u8 tr_method) | |
96902835 CO |
2855 | { |
2856 | int ret; | |
2857 | ||
2858 | mutex_lock(&ioc->tm_cmds.mutex); | |
6da999fe | 2859 | ret = mpt3sas_scsih_issue_tm(ioc, handle, lun, type, smid_task, |
c1a6c5ac | 2860 | msix_task, timeout, tr_method); |
96902835 CO |
2861 | mutex_unlock(&ioc->tm_cmds.mutex); |
2862 | ||
2863 | return ret; | |
f92363d1 SR |
2864 | } |
2865 | ||
2866 | /** | |
2867 | * _scsih_tm_display_info - displays info about the device | |
2868 | * @ioc: per adapter struct | |
2869 | * @scmd: pointer to scsi command object | |
2870 | * | |
2871 | * Called by task management callback handlers. | |
2872 | */ | |
2873 | static void | |
2874 | _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd) | |
2875 | { | |
2876 | struct scsi_target *starget = scmd->device->sdev_target; | |
2877 | struct MPT3SAS_TARGET *priv_target = starget->hostdata; | |
2878 | struct _sas_device *sas_device = NULL; | |
6ce2f1d1 | 2879 | struct _pcie_device *pcie_device = NULL; |
f92363d1 SR |
2880 | unsigned long flags; |
2881 | char *device_str = NULL; | |
2882 | ||
2883 | if (!priv_target) | |
2884 | return; | |
7786ab6a SR |
2885 | if (ioc->hide_ir_msg) |
2886 | device_str = "WarpDrive"; | |
2887 | else | |
2888 | device_str = "volume"; | |
f92363d1 SR |
2889 | |
2890 | scsi_print_command(scmd); | |
2891 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { | |
2892 | starget_printk(KERN_INFO, starget, | |
2893 | "%s handle(0x%04x), %s wwid(0x%016llx)\n", | |
2894 | device_str, priv_target->handle, | |
2895 | device_str, (unsigned long long)priv_target->sas_address); | |
6ce2f1d1 SPS |
2896 | |
2897 | } else if (priv_target->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) { | |
2898 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
2899 | pcie_device = __mpt3sas_get_pdev_from_target(ioc, priv_target); | |
2900 | if (pcie_device) { | |
2901 | starget_printk(KERN_INFO, starget, | |
2902 | "handle(0x%04x), wwid(0x%016llx), port(%d)\n", | |
2903 | pcie_device->handle, | |
2904 | (unsigned long long)pcie_device->wwid, | |
2905 | pcie_device->port_num); | |
2906 | if (pcie_device->enclosure_handle != 0) | |
2907 | starget_printk(KERN_INFO, starget, | |
2908 | "enclosure logical id(0x%016llx), slot(%d)\n", | |
2909 | (unsigned long long) | |
2910 | pcie_device->enclosure_logical_id, | |
2911 | pcie_device->slot); | |
2912 | if (pcie_device->connector_name[0] != '\0') | |
2913 | starget_printk(KERN_INFO, starget, | |
2914 | "enclosure level(0x%04x), connector name( %s)\n", | |
2915 | pcie_device->enclosure_level, | |
2916 | pcie_device->connector_name); | |
2917 | pcie_device_put(pcie_device); | |
2918 | } | |
2919 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
2920 | ||
f92363d1 SR |
2921 | } else { |
2922 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 | 2923 | sas_device = __mpt3sas_get_sdev_from_target(ioc, priv_target); |
f92363d1 SR |
2924 | if (sas_device) { |
2925 | if (priv_target->flags & | |
2926 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
2927 | starget_printk(KERN_INFO, starget, | |
2928 | "volume handle(0x%04x), " | |
2929 | "volume wwid(0x%016llx)\n", | |
2930 | sas_device->volume_handle, | |
2931 | (unsigned long long)sas_device->volume_wwid); | |
2932 | } | |
2933 | starget_printk(KERN_INFO, starget, | |
2934 | "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n", | |
2935 | sas_device->handle, | |
2936 | (unsigned long long)sas_device->sas_address, | |
2937 | sas_device->phy); | |
75888956 SR |
2938 | |
2939 | _scsih_display_enclosure_chassis_info(NULL, sas_device, | |
2940 | NULL, starget); | |
d1cb5e49 SR |
2941 | |
2942 | sas_device_put(sas_device); | |
f92363d1 SR |
2943 | } |
2944 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
2945 | } | |
2946 | } | |
2947 | ||
2948 | /** | |
8a7e4c24 | 2949 | * scsih_abort - eh threads main abort routine |
f92363d1 SR |
2950 | * @scmd: pointer to scsi command object |
2951 | * | |
4beb4867 | 2952 | * Return: SUCCESS if command aborted else FAILED |
f92363d1 | 2953 | */ |
8bbb1cf6 | 2954 | static int |
8a7e4c24 | 2955 | scsih_abort(struct scsi_cmnd *scmd) |
f92363d1 SR |
2956 | { |
2957 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
2958 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
dbec4c90 | 2959 | struct scsiio_tracker *st = scsi_cmd_priv(scmd); |
f92363d1 SR |
2960 | u16 handle; |
2961 | int r; | |
2962 | ||
c1a6c5ac C |
2963 | u8 timeout = 30; |
2964 | struct _pcie_device *pcie_device = NULL; | |
13d01df5 SR |
2965 | sdev_printk(KERN_INFO, scmd->device, "attempting task abort!" |
2966 | "scmd(0x%p), outstanding for %u ms & timeout %u ms\n", | |
2967 | scmd, jiffies_to_msecs(jiffies - scmd->jiffies_at_alloc), | |
2968 | (scmd->request->timeout / HZ) * 1000); | |
f92363d1 SR |
2969 | _scsih_tm_display_info(ioc, scmd); |
2970 | ||
2971 | sas_device_priv_data = scmd->device->hostdata; | |
9ff549ff MFO |
2972 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target || |
2973 | ioc->remove_host) { | |
f92363d1 | 2974 | sdev_printk(KERN_INFO, scmd->device, |
13d01df5 | 2975 | "device been deleted! scmd(0x%p)\n", scmd); |
f92363d1 SR |
2976 | scmd->result = DID_NO_CONNECT << 16; |
2977 | scmd->scsi_done(scmd); | |
2978 | r = SUCCESS; | |
2979 | goto out; | |
2980 | } | |
2981 | ||
dbec4c90 SPS |
2982 | /* check for completed command */ |
2983 | if (st == NULL || st->cb_idx == 0xFF) { | |
13d01df5 SR |
2984 | sdev_printk(KERN_INFO, scmd->device, "No reference found at " |
2985 | "driver, assuming scmd(0x%p) might have completed\n", scmd); | |
f92363d1 SR |
2986 | scmd->result = DID_RESET << 16; |
2987 | r = SUCCESS; | |
2988 | goto out; | |
2989 | } | |
2990 | ||
2991 | /* for hidden raid components and volumes this is not supported */ | |
2992 | if (sas_device_priv_data->sas_target->flags & | |
2993 | MPT_TARGET_FLAGS_RAID_COMPONENT || | |
2994 | sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) { | |
2995 | scmd->result = DID_RESET << 16; | |
2996 | r = FAILED; | |
2997 | goto out; | |
2998 | } | |
2999 | ||
3000 | mpt3sas_halt_firmware(ioc); | |
3001 | ||
3002 | handle = sas_device_priv_data->sas_target->handle; | |
c1a6c5ac | 3003 | pcie_device = mpt3sas_get_pdev_by_handle(ioc, handle); |
5bb309db SP |
3004 | if (pcie_device && (!ioc->tm_custom_handling) && |
3005 | (!(mpt3sas_scsih_is_pcie_scsi_device(pcie_device->device_info)))) | |
c1a6c5ac | 3006 | timeout = ioc->nvme_abort_timeout; |
6da999fe HR |
3007 | r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->lun, |
3008 | MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, | |
c1a6c5ac | 3009 | st->smid, st->msix_io, timeout, 0); |
6da999fe | 3010 | /* Command must be cleared after abort */ |
dbec4c90 | 3011 | if (r == SUCCESS && st->cb_idx != 0xFF) |
6da999fe | 3012 | r = FAILED; |
f92363d1 | 3013 | out: |
13d01df5 | 3014 | sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(0x%p)\n", |
f92363d1 | 3015 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
c1a6c5ac C |
3016 | if (pcie_device) |
3017 | pcie_device_put(pcie_device); | |
f92363d1 SR |
3018 | return r; |
3019 | } | |
3020 | ||
3021 | /** | |
8a7e4c24 | 3022 | * scsih_dev_reset - eh threads main device reset routine |
f92363d1 SR |
3023 | * @scmd: pointer to scsi command object |
3024 | * | |
4beb4867 | 3025 | * Return: SUCCESS if command aborted else FAILED |
f92363d1 | 3026 | */ |
8bbb1cf6 | 3027 | static int |
8a7e4c24 | 3028 | scsih_dev_reset(struct scsi_cmnd *scmd) |
f92363d1 SR |
3029 | { |
3030 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
3031 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
d1cb5e49 | 3032 | struct _sas_device *sas_device = NULL; |
c1a6c5ac | 3033 | struct _pcie_device *pcie_device = NULL; |
f92363d1 | 3034 | u16 handle; |
c1a6c5ac C |
3035 | u8 tr_method = 0; |
3036 | u8 tr_timeout = 30; | |
f92363d1 SR |
3037 | int r; |
3038 | ||
d1cb5e49 SR |
3039 | struct scsi_target *starget = scmd->device->sdev_target; |
3040 | struct MPT3SAS_TARGET *target_priv_data = starget->hostdata; | |
3041 | ||
f92363d1 | 3042 | sdev_printk(KERN_INFO, scmd->device, |
13d01df5 | 3043 | "attempting device reset! scmd(0x%p)\n", scmd); |
f92363d1 SR |
3044 | _scsih_tm_display_info(ioc, scmd); |
3045 | ||
3046 | sas_device_priv_data = scmd->device->hostdata; | |
9ff549ff MFO |
3047 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target || |
3048 | ioc->remove_host) { | |
f92363d1 | 3049 | sdev_printk(KERN_INFO, scmd->device, |
13d01df5 | 3050 | "device been deleted! scmd(0x%p)\n", scmd); |
f92363d1 SR |
3051 | scmd->result = DID_NO_CONNECT << 16; |
3052 | scmd->scsi_done(scmd); | |
3053 | r = SUCCESS; | |
3054 | goto out; | |
3055 | } | |
3056 | ||
3057 | /* for hidden raid components obtain the volume_handle */ | |
3058 | handle = 0; | |
3059 | if (sas_device_priv_data->sas_target->flags & | |
3060 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
d1cb5e49 SR |
3061 | sas_device = mpt3sas_get_sdev_from_target(ioc, |
3062 | target_priv_data); | |
f92363d1 SR |
3063 | if (sas_device) |
3064 | handle = sas_device->volume_handle; | |
f92363d1 SR |
3065 | } else |
3066 | handle = sas_device_priv_data->sas_target->handle; | |
3067 | ||
3068 | if (!handle) { | |
3069 | scmd->result = DID_RESET << 16; | |
3070 | r = FAILED; | |
3071 | goto out; | |
3072 | } | |
3073 | ||
c1a6c5ac C |
3074 | pcie_device = mpt3sas_get_pdev_by_handle(ioc, handle); |
3075 | ||
5bb309db SP |
3076 | if (pcie_device && (!ioc->tm_custom_handling) && |
3077 | (!(mpt3sas_scsih_is_pcie_scsi_device(pcie_device->device_info)))) { | |
c1a6c5ac C |
3078 | tr_timeout = pcie_device->reset_timeout; |
3079 | tr_method = MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE; | |
3080 | } else | |
3081 | tr_method = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET; | |
5bb309db | 3082 | |
6da999fe | 3083 | r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->lun, |
c1a6c5ac C |
3084 | MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 0, |
3085 | tr_timeout, tr_method); | |
74fcfa53 HR |
3086 | /* Check for busy commands after reset */ |
3087 | if (r == SUCCESS && atomic_read(&scmd->device->device_busy)) | |
3088 | r = FAILED; | |
f92363d1 | 3089 | out: |
13d01df5 | 3090 | sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(0x%p)\n", |
f92363d1 | 3091 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
d1cb5e49 SR |
3092 | |
3093 | if (sas_device) | |
3094 | sas_device_put(sas_device); | |
c1a6c5ac C |
3095 | if (pcie_device) |
3096 | pcie_device_put(pcie_device); | |
d1cb5e49 | 3097 | |
f92363d1 SR |
3098 | return r; |
3099 | } | |
3100 | ||
3101 | /** | |
8a7e4c24 | 3102 | * scsih_target_reset - eh threads main target reset routine |
f92363d1 SR |
3103 | * @scmd: pointer to scsi command object |
3104 | * | |
4beb4867 | 3105 | * Return: SUCCESS if command aborted else FAILED |
f92363d1 | 3106 | */ |
8bbb1cf6 | 3107 | static int |
8a7e4c24 | 3108 | scsih_target_reset(struct scsi_cmnd *scmd) |
f92363d1 SR |
3109 | { |
3110 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
3111 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
d1cb5e49 | 3112 | struct _sas_device *sas_device = NULL; |
c1a6c5ac | 3113 | struct _pcie_device *pcie_device = NULL; |
f92363d1 | 3114 | u16 handle; |
c1a6c5ac C |
3115 | u8 tr_method = 0; |
3116 | u8 tr_timeout = 30; | |
f92363d1 SR |
3117 | int r; |
3118 | struct scsi_target *starget = scmd->device->sdev_target; | |
d1cb5e49 | 3119 | struct MPT3SAS_TARGET *target_priv_data = starget->hostdata; |
f92363d1 | 3120 | |
13d01df5 SR |
3121 | starget_printk(KERN_INFO, starget, |
3122 | "attempting target reset! scmd(0x%p)\n", scmd); | |
f92363d1 SR |
3123 | _scsih_tm_display_info(ioc, scmd); |
3124 | ||
3125 | sas_device_priv_data = scmd->device->hostdata; | |
9ff549ff MFO |
3126 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target || |
3127 | ioc->remove_host) { | |
13d01df5 SR |
3128 | starget_printk(KERN_INFO, starget, |
3129 | "target been deleted! scmd(0x%p)\n", scmd); | |
f92363d1 SR |
3130 | scmd->result = DID_NO_CONNECT << 16; |
3131 | scmd->scsi_done(scmd); | |
3132 | r = SUCCESS; | |
3133 | goto out; | |
3134 | } | |
3135 | ||
3136 | /* for hidden raid components obtain the volume_handle */ | |
3137 | handle = 0; | |
3138 | if (sas_device_priv_data->sas_target->flags & | |
3139 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
d1cb5e49 SR |
3140 | sas_device = mpt3sas_get_sdev_from_target(ioc, |
3141 | target_priv_data); | |
f92363d1 SR |
3142 | if (sas_device) |
3143 | handle = sas_device->volume_handle; | |
f92363d1 SR |
3144 | } else |
3145 | handle = sas_device_priv_data->sas_target->handle; | |
3146 | ||
3147 | if (!handle) { | |
3148 | scmd->result = DID_RESET << 16; | |
3149 | r = FAILED; | |
3150 | goto out; | |
3151 | } | |
3152 | ||
c1a6c5ac C |
3153 | pcie_device = mpt3sas_get_pdev_by_handle(ioc, handle); |
3154 | ||
5bb309db SP |
3155 | if (pcie_device && (!ioc->tm_custom_handling) && |
3156 | (!(mpt3sas_scsih_is_pcie_scsi_device(pcie_device->device_info)))) { | |
c1a6c5ac C |
3157 | tr_timeout = pcie_device->reset_timeout; |
3158 | tr_method = MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE; | |
3159 | } else | |
3160 | tr_method = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET; | |
6da999fe | 3161 | r = mpt3sas_scsih_issue_locked_tm(ioc, handle, 0, |
c1a6c5ac C |
3162 | MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 0, |
3163 | tr_timeout, tr_method); | |
74fcfa53 HR |
3164 | /* Check for busy commands after reset */ |
3165 | if (r == SUCCESS && atomic_read(&starget->target_busy)) | |
3166 | r = FAILED; | |
f92363d1 | 3167 | out: |
13d01df5 | 3168 | starget_printk(KERN_INFO, starget, "target reset: %s scmd(0x%p)\n", |
f92363d1 | 3169 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
d1cb5e49 SR |
3170 | |
3171 | if (sas_device) | |
3172 | sas_device_put(sas_device); | |
c1a6c5ac C |
3173 | if (pcie_device) |
3174 | pcie_device_put(pcie_device); | |
f92363d1 SR |
3175 | return r; |
3176 | } | |
3177 | ||
3178 | ||
3179 | /** | |
8a7e4c24 | 3180 | * scsih_host_reset - eh threads main host reset routine |
f92363d1 SR |
3181 | * @scmd: pointer to scsi command object |
3182 | * | |
4beb4867 | 3183 | * Return: SUCCESS if command aborted else FAILED |
f92363d1 | 3184 | */ |
8bbb1cf6 | 3185 | static int |
8a7e4c24 | 3186 | scsih_host_reset(struct scsi_cmnd *scmd) |
f92363d1 SR |
3187 | { |
3188 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
3189 | int r, retval; | |
3190 | ||
13d01df5 | 3191 | ioc_info(ioc, "attempting host reset! scmd(0x%p)\n", scmd); |
f92363d1 SR |
3192 | scsi_print_command(scmd); |
3193 | ||
9ff549ff | 3194 | if (ioc->is_driver_loading || ioc->remove_host) { |
919d8a3f | 3195 | ioc_info(ioc, "Blocking the host reset\n"); |
ddb588be SR |
3196 | r = FAILED; |
3197 | goto out; | |
3198 | } | |
3199 | ||
98c56ad3 | 3200 | retval = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
f92363d1 | 3201 | r = (retval < 0) ? FAILED : SUCCESS; |
ddb588be | 3202 | out: |
13d01df5 | 3203 | ioc_info(ioc, "host reset: %s scmd(0x%p)\n", |
919d8a3f | 3204 | r == SUCCESS ? "SUCCESS" : "FAILED", scmd); |
f92363d1 SR |
3205 | |
3206 | return r; | |
3207 | } | |
3208 | ||
3209 | /** | |
3210 | * _scsih_fw_event_add - insert and queue up fw_event | |
3211 | * @ioc: per adapter object | |
3212 | * @fw_event: object describing the event | |
3213 | * Context: This function will acquire ioc->fw_event_lock. | |
3214 | * | |
3215 | * This adds the firmware event object into link list, then queues it up to | |
3216 | * be processed from user context. | |
f92363d1 SR |
3217 | */ |
3218 | static void | |
3219 | _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event) | |
3220 | { | |
3221 | unsigned long flags; | |
3222 | ||
3223 | if (ioc->firmware_event_thread == NULL) | |
3224 | return; | |
3225 | ||
3226 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
146b16c8 | 3227 | fw_event_work_get(fw_event); |
f92363d1 SR |
3228 | INIT_LIST_HEAD(&fw_event->list); |
3229 | list_add_tail(&fw_event->list, &ioc->fw_event_list); | |
3230 | INIT_WORK(&fw_event->work, _firmware_event_work); | |
146b16c8 | 3231 | fw_event_work_get(fw_event); |
f92363d1 SR |
3232 | queue_work(ioc->firmware_event_thread, &fw_event->work); |
3233 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
3234 | } | |
3235 | ||
3236 | /** | |
146b16c8 | 3237 | * _scsih_fw_event_del_from_list - delete fw_event from the list |
f92363d1 SR |
3238 | * @ioc: per adapter object |
3239 | * @fw_event: object describing the event | |
3240 | * Context: This function will acquire ioc->fw_event_lock. | |
3241 | * | |
146b16c8 | 3242 | * If the fw_event is on the fw_event_list, remove it and do a put. |
f92363d1 SR |
3243 | */ |
3244 | static void | |
146b16c8 | 3245 | _scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work |
f92363d1 SR |
3246 | *fw_event) |
3247 | { | |
3248 | unsigned long flags; | |
3249 | ||
3250 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
146b16c8 SR |
3251 | if (!list_empty(&fw_event->list)) { |
3252 | list_del_init(&fw_event->list); | |
3253 | fw_event_work_put(fw_event); | |
3254 | } | |
f92363d1 SR |
3255 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
3256 | } | |
3257 | ||
3258 | ||
3259 | /** | |
3260 | * mpt3sas_send_trigger_data_event - send event for processing trigger data | |
3261 | * @ioc: per adapter object | |
3262 | * @event_data: trigger event data | |
f92363d1 SR |
3263 | */ |
3264 | void | |
3265 | mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc, | |
3266 | struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data) | |
3267 | { | |
3268 | struct fw_event_work *fw_event; | |
146b16c8 | 3269 | u16 sz; |
f92363d1 SR |
3270 | |
3271 | if (ioc->is_driver_loading) | |
3272 | return; | |
146b16c8 SR |
3273 | sz = sizeof(*event_data); |
3274 | fw_event = alloc_fw_event_work(sz); | |
f92363d1 SR |
3275 | if (!fw_event) |
3276 | return; | |
f92363d1 SR |
3277 | fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG; |
3278 | fw_event->ioc = ioc; | |
3279 | memcpy(fw_event->event_data, event_data, sizeof(*event_data)); | |
3280 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 | 3281 | fw_event_work_put(fw_event); |
f92363d1 SR |
3282 | } |
3283 | ||
3284 | /** | |
3285 | * _scsih_error_recovery_delete_devices - remove devices not responding | |
3286 | * @ioc: per adapter object | |
f92363d1 SR |
3287 | */ |
3288 | static void | |
3289 | _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc) | |
3290 | { | |
3291 | struct fw_event_work *fw_event; | |
3292 | ||
3293 | if (ioc->is_driver_loading) | |
3294 | return; | |
146b16c8 | 3295 | fw_event = alloc_fw_event_work(0); |
f92363d1 SR |
3296 | if (!fw_event) |
3297 | return; | |
3298 | fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES; | |
3299 | fw_event->ioc = ioc; | |
3300 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 | 3301 | fw_event_work_put(fw_event); |
f92363d1 SR |
3302 | } |
3303 | ||
3304 | /** | |
3305 | * mpt3sas_port_enable_complete - port enable completed (fake event) | |
3306 | * @ioc: per adapter object | |
f92363d1 SR |
3307 | */ |
3308 | void | |
3309 | mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc) | |
3310 | { | |
3311 | struct fw_event_work *fw_event; | |
3312 | ||
146b16c8 | 3313 | fw_event = alloc_fw_event_work(0); |
f92363d1 SR |
3314 | if (!fw_event) |
3315 | return; | |
3316 | fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE; | |
3317 | fw_event->ioc = ioc; | |
3318 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 SR |
3319 | fw_event_work_put(fw_event); |
3320 | } | |
3321 | ||
3322 | static struct fw_event_work *dequeue_next_fw_event(struct MPT3SAS_ADAPTER *ioc) | |
3323 | { | |
3324 | unsigned long flags; | |
3325 | struct fw_event_work *fw_event = NULL; | |
3326 | ||
3327 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
3328 | if (!list_empty(&ioc->fw_event_list)) { | |
3329 | fw_event = list_first_entry(&ioc->fw_event_list, | |
3330 | struct fw_event_work, list); | |
3331 | list_del_init(&fw_event->list); | |
3332 | } | |
3333 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
3334 | ||
3335 | return fw_event; | |
f92363d1 SR |
3336 | } |
3337 | ||
3338 | /** | |
3339 | * _scsih_fw_event_cleanup_queue - cleanup event queue | |
3340 | * @ioc: per adapter object | |
3341 | * | |
3342 | * Walk the firmware event queue, either killing timers, or waiting | |
3343 | * for outstanding events to complete | |
f92363d1 SR |
3344 | */ |
3345 | static void | |
3346 | _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc) | |
3347 | { | |
146b16c8 | 3348 | struct fw_event_work *fw_event; |
f92363d1 SR |
3349 | |
3350 | if (list_empty(&ioc->fw_event_list) || | |
3351 | !ioc->firmware_event_thread || in_interrupt()) | |
3352 | return; | |
3353 | ||
146b16c8 SR |
3354 | while ((fw_event = dequeue_next_fw_event(ioc))) { |
3355 | /* | |
3356 | * Wait on the fw_event to complete. If this returns 1, then | |
3357 | * the event was never executed, and we need a put for the | |
b8ac0cc7 | 3358 | * reference the work had on the fw_event. |
146b16c8 SR |
3359 | * |
3360 | * If it did execute, we wait for it to finish, and the put will | |
3361 | * happen from _firmware_event_work() | |
3362 | */ | |
b8ac0cc7 | 3363 | if (cancel_work_sync(&fw_event->work)) |
146b16c8 SR |
3364 | fw_event_work_put(fw_event); |
3365 | ||
3366 | fw_event_work_put(fw_event); | |
f92363d1 SR |
3367 | } |
3368 | } | |
3369 | ||
df838f92 SR |
3370 | /** |
3371 | * _scsih_internal_device_block - block the sdev device | |
3372 | * @sdev: per device object | |
3373 | * @sas_device_priv_data : per device driver private data | |
3374 | * | |
3375 | * make sure device is blocked without error, if not | |
3376 | * print an error | |
3377 | */ | |
3378 | static void | |
3379 | _scsih_internal_device_block(struct scsi_device *sdev, | |
3380 | struct MPT3SAS_DEVICE *sas_device_priv_data) | |
3381 | { | |
3382 | int r = 0; | |
3383 | ||
3384 | sdev_printk(KERN_INFO, sdev, "device_block, handle(0x%04x)\n", | |
3385 | sas_device_priv_data->sas_target->handle); | |
3386 | sas_device_priv_data->block = 1; | |
3387 | ||
551eb598 | 3388 | r = scsi_internal_device_block_nowait(sdev); |
df838f92 SR |
3389 | if (r == -EINVAL) |
3390 | sdev_printk(KERN_WARNING, sdev, | |
3391 | "device_block failed with return(%d) for handle(0x%04x)\n", | |
b2fe6be7 | 3392 | r, sas_device_priv_data->sas_target->handle); |
df838f92 SR |
3393 | } |
3394 | ||
3395 | /** | |
3396 | * _scsih_internal_device_unblock - unblock the sdev device | |
3397 | * @sdev: per device object | |
3398 | * @sas_device_priv_data : per device driver private data | |
3399 | * make sure device is unblocked without error, if not retry | |
3400 | * by blocking and then unblocking | |
3401 | */ | |
3402 | ||
3403 | static void | |
3404 | _scsih_internal_device_unblock(struct scsi_device *sdev, | |
3405 | struct MPT3SAS_DEVICE *sas_device_priv_data) | |
3406 | { | |
3407 | int r = 0; | |
3408 | ||
3409 | sdev_printk(KERN_WARNING, sdev, "device_unblock and setting to running, " | |
3410 | "handle(0x%04x)\n", sas_device_priv_data->sas_target->handle); | |
3411 | sas_device_priv_data->block = 0; | |
43f7571b | 3412 | r = scsi_internal_device_unblock_nowait(sdev, SDEV_RUNNING); |
df838f92 SR |
3413 | if (r == -EINVAL) { |
3414 | /* The device has been set to SDEV_RUNNING by SD layer during | |
3415 | * device addition but the request queue is still stopped by | |
3416 | * our earlier block call. We need to perform a block again | |
3417 | * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */ | |
3418 | ||
3419 | sdev_printk(KERN_WARNING, sdev, | |
3420 | "device_unblock failed with return(%d) for handle(0x%04x) " | |
3421 | "performing a block followed by an unblock\n", | |
b2fe6be7 | 3422 | r, sas_device_priv_data->sas_target->handle); |
df838f92 | 3423 | sas_device_priv_data->block = 1; |
551eb598 | 3424 | r = scsi_internal_device_block_nowait(sdev); |
df838f92 SR |
3425 | if (r) |
3426 | sdev_printk(KERN_WARNING, sdev, "retried device_block " | |
3427 | "failed with return(%d) for handle(0x%04x)\n", | |
b2fe6be7 | 3428 | r, sas_device_priv_data->sas_target->handle); |
df838f92 SR |
3429 | |
3430 | sas_device_priv_data->block = 0; | |
43f7571b | 3431 | r = scsi_internal_device_unblock_nowait(sdev, SDEV_RUNNING); |
df838f92 SR |
3432 | if (r) |
3433 | sdev_printk(KERN_WARNING, sdev, "retried device_unblock" | |
3434 | " failed with return(%d) for handle(0x%04x)\n", | |
b2fe6be7 | 3435 | r, sas_device_priv_data->sas_target->handle); |
df838f92 SR |
3436 | } |
3437 | } | |
3438 | ||
f92363d1 SR |
3439 | /** |
3440 | * _scsih_ublock_io_all_device - unblock every device | |
3441 | * @ioc: per adapter object | |
3442 | * | |
3443 | * change the device state from block to running | |
3444 | */ | |
3445 | static void | |
3446 | _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc) | |
3447 | { | |
3448 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
3449 | struct scsi_device *sdev; | |
3450 | ||
3451 | shost_for_each_device(sdev, ioc->shost) { | |
3452 | sas_device_priv_data = sdev->hostdata; | |
3453 | if (!sas_device_priv_data) | |
3454 | continue; | |
3455 | if (!sas_device_priv_data->block) | |
3456 | continue; | |
3457 | ||
f92363d1 SR |
3458 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, |
3459 | "device_running, handle(0x%04x)\n", | |
3460 | sas_device_priv_data->sas_target->handle)); | |
df838f92 | 3461 | _scsih_internal_device_unblock(sdev, sas_device_priv_data); |
f92363d1 SR |
3462 | } |
3463 | } | |
3464 | ||
3465 | ||
3466 | /** | |
3467 | * _scsih_ublock_io_device - prepare device to be deleted | |
3468 | * @ioc: per adapter object | |
4beb4867 | 3469 | * @sas_address: sas address |
f92363d1 SR |
3470 | * |
3471 | * unblock then put device in offline state | |
3472 | */ | |
3473 | static void | |
3474 | _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address) | |
3475 | { | |
3476 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
3477 | struct scsi_device *sdev; | |
3478 | ||
3479 | shost_for_each_device(sdev, ioc->shost) { | |
3480 | sas_device_priv_data = sdev->hostdata; | |
3481 | if (!sas_device_priv_data) | |
3482 | continue; | |
3483 | if (sas_device_priv_data->sas_target->sas_address | |
3484 | != sas_address) | |
3485 | continue; | |
df838f92 SR |
3486 | if (sas_device_priv_data->block) |
3487 | _scsih_internal_device_unblock(sdev, | |
3488 | sas_device_priv_data); | |
f92363d1 SR |
3489 | } |
3490 | } | |
3491 | ||
3492 | /** | |
3493 | * _scsih_block_io_all_device - set the device state to SDEV_BLOCK | |
3494 | * @ioc: per adapter object | |
f92363d1 | 3495 | * |
6c7abffc | 3496 | * During device pull we need to appropriately set the sdev state. |
f92363d1 SR |
3497 | */ |
3498 | static void | |
3499 | _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc) | |
3500 | { | |
3501 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
3502 | struct scsi_device *sdev; | |
3503 | ||
3504 | shost_for_each_device(sdev, ioc->shost) { | |
3505 | sas_device_priv_data = sdev->hostdata; | |
3506 | if (!sas_device_priv_data) | |
3507 | continue; | |
3508 | if (sas_device_priv_data->block) | |
3509 | continue; | |
30158dc9 SS |
3510 | if (sas_device_priv_data->ignore_delay_remove) { |
3511 | sdev_printk(KERN_INFO, sdev, | |
3512 | "%s skip device_block for SES handle(0x%04x)\n", | |
3513 | __func__, sas_device_priv_data->sas_target->handle); | |
3514 | continue; | |
3515 | } | |
df838f92 | 3516 | _scsih_internal_device_block(sdev, sas_device_priv_data); |
f92363d1 SR |
3517 | } |
3518 | } | |
3519 | ||
3520 | /** | |
3521 | * _scsih_block_io_device - set the device state to SDEV_BLOCK | |
3522 | * @ioc: per adapter object | |
3523 | * @handle: device handle | |
3524 | * | |
6c7abffc | 3525 | * During device pull we need to appropriately set the sdev state. |
f92363d1 SR |
3526 | */ |
3527 | static void | |
3528 | _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
3529 | { | |
3530 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
3531 | struct scsi_device *sdev; | |
e4bc7f5c SR |
3532 | struct _sas_device *sas_device; |
3533 | ||
d1cb5e49 | 3534 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
3535 | |
3536 | shost_for_each_device(sdev, ioc->shost) { | |
3537 | sas_device_priv_data = sdev->hostdata; | |
3538 | if (!sas_device_priv_data) | |
3539 | continue; | |
3540 | if (sas_device_priv_data->sas_target->handle != handle) | |
3541 | continue; | |
3542 | if (sas_device_priv_data->block) | |
3543 | continue; | |
4318c734 | 3544 | if (sas_device && sas_device->pend_sas_rphy_add) |
e4bc7f5c | 3545 | continue; |
30158dc9 SS |
3546 | if (sas_device_priv_data->ignore_delay_remove) { |
3547 | sdev_printk(KERN_INFO, sdev, | |
3548 | "%s skip device_block for SES handle(0x%04x)\n", | |
3549 | __func__, sas_device_priv_data->sas_target->handle); | |
3550 | continue; | |
3551 | } | |
df838f92 | 3552 | _scsih_internal_device_block(sdev, sas_device_priv_data); |
f92363d1 | 3553 | } |
d1cb5e49 | 3554 | |
4318c734 SPS |
3555 | if (sas_device) |
3556 | sas_device_put(sas_device); | |
f92363d1 SR |
3557 | } |
3558 | ||
3559 | /** | |
3560 | * _scsih_block_io_to_children_attached_to_ex | |
3561 | * @ioc: per adapter object | |
3562 | * @sas_expander: the sas_device object | |
3563 | * | |
3564 | * This routine set sdev state to SDEV_BLOCK for all devices | |
3565 | * attached to this expander. This function called when expander is | |
3566 | * pulled. | |
3567 | */ | |
3568 | static void | |
3569 | _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc, | |
3570 | struct _sas_node *sas_expander) | |
3571 | { | |
3572 | struct _sas_port *mpt3sas_port; | |
3573 | struct _sas_device *sas_device; | |
3574 | struct _sas_node *expander_sibling; | |
3575 | unsigned long flags; | |
3576 | ||
3577 | if (!sas_expander) | |
3578 | return; | |
3579 | ||
3580 | list_for_each_entry(mpt3sas_port, | |
3581 | &sas_expander->sas_port_list, port_list) { | |
3582 | if (mpt3sas_port->remote_identify.device_type == | |
3583 | SAS_END_DEVICE) { | |
3584 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 SR |
3585 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
3586 | mpt3sas_port->remote_identify.sas_address); | |
3587 | if (sas_device) { | |
f92363d1 | 3588 | set_bit(sas_device->handle, |
d1cb5e49 SR |
3589 | ioc->blocking_handles); |
3590 | sas_device_put(sas_device); | |
3591 | } | |
f92363d1 SR |
3592 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
3593 | } | |
3594 | } | |
3595 | ||
3596 | list_for_each_entry(mpt3sas_port, | |
3597 | &sas_expander->sas_port_list, port_list) { | |
3598 | ||
3599 | if (mpt3sas_port->remote_identify.device_type == | |
3600 | SAS_EDGE_EXPANDER_DEVICE || | |
3601 | mpt3sas_port->remote_identify.device_type == | |
3602 | SAS_FANOUT_EXPANDER_DEVICE) { | |
3603 | expander_sibling = | |
3604 | mpt3sas_scsih_expander_find_by_sas_address( | |
3605 | ioc, mpt3sas_port->remote_identify.sas_address); | |
3606 | _scsih_block_io_to_children_attached_to_ex(ioc, | |
3607 | expander_sibling); | |
3608 | } | |
3609 | } | |
3610 | } | |
3611 | ||
3612 | /** | |
3613 | * _scsih_block_io_to_children_attached_directly | |
3614 | * @ioc: per adapter object | |
3615 | * @event_data: topology change event data | |
3616 | * | |
3617 | * This routine set sdev state to SDEV_BLOCK for all devices | |
3618 | * direct attached during device pull. | |
3619 | */ | |
3620 | static void | |
3621 | _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc, | |
3622 | Mpi2EventDataSasTopologyChangeList_t *event_data) | |
3623 | { | |
3624 | int i; | |
3625 | u16 handle; | |
3626 | u16 reason_code; | |
f92363d1 SR |
3627 | |
3628 | for (i = 0; i < event_data->NumEntries; i++) { | |
3629 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
3630 | if (!handle) | |
3631 | continue; | |
f92363d1 SR |
3632 | reason_code = event_data->PHY[i].PhyStatus & |
3633 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
3634 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING) | |
3635 | _scsih_block_io_device(ioc, handle); | |
3636 | } | |
3637 | } | |
3638 | ||
4318c734 SPS |
3639 | /** |
3640 | * _scsih_block_io_to_pcie_children_attached_directly | |
3641 | * @ioc: per adapter object | |
3642 | * @event_data: topology change event data | |
3643 | * | |
3644 | * This routine set sdev state to SDEV_BLOCK for all devices | |
3645 | * direct attached during device pull/reconnect. | |
3646 | */ | |
3647 | static void | |
3648 | _scsih_block_io_to_pcie_children_attached_directly(struct MPT3SAS_ADAPTER *ioc, | |
3649 | Mpi26EventDataPCIeTopologyChangeList_t *event_data) | |
3650 | { | |
3651 | int i; | |
3652 | u16 handle; | |
3653 | u16 reason_code; | |
3654 | ||
3655 | for (i = 0; i < event_data->NumEntries; i++) { | |
3656 | handle = | |
3657 | le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle); | |
3658 | if (!handle) | |
3659 | continue; | |
3660 | reason_code = event_data->PortEntry[i].PortStatus; | |
3661 | if (reason_code == | |
3662 | MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING) | |
3663 | _scsih_block_io_device(ioc, handle); | |
3664 | } | |
3665 | } | |
f92363d1 SR |
3666 | /** |
3667 | * _scsih_tm_tr_send - send task management request | |
3668 | * @ioc: per adapter object | |
3669 | * @handle: device handle | |
3670 | * Context: interrupt time. | |
3671 | * | |
3672 | * This code is to initiate the device removal handshake protocol | |
3673 | * with controller firmware. This function will issue target reset | |
3674 | * using high priority request queue. It will send a sas iounit | |
3675 | * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion. | |
3676 | * | |
3677 | * This is designed to send muliple task management request at the same | |
3678 | * time to the fifo. If the fifo is full, we will append the request, | |
3679 | * and process it in a future completion. | |
3680 | */ | |
3681 | static void | |
3682 | _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
3683 | { | |
3684 | Mpi2SCSITaskManagementRequest_t *mpi_request; | |
3685 | u16 smid; | |
d1cb5e49 | 3686 | struct _sas_device *sas_device = NULL; |
6ce2f1d1 | 3687 | struct _pcie_device *pcie_device = NULL; |
f92363d1 SR |
3688 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; |
3689 | u64 sas_address = 0; | |
3690 | unsigned long flags; | |
3691 | struct _tr_list *delayed_tr; | |
3692 | u32 ioc_state; | |
c1a6c5ac | 3693 | u8 tr_method = 0; |
f92363d1 | 3694 | |
6ce2f1d1 | 3695 | if (ioc->pci_error_recovery) { |
4dc74b2e JP |
3696 | dewtprintk(ioc, |
3697 | ioc_info(ioc, "%s: host in pci error recovery: handle(0x%04x)\n", | |
3698 | __func__, handle)); | |
f92363d1 SR |
3699 | return; |
3700 | } | |
3701 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); | |
3702 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | |
4dc74b2e JP |
3703 | dewtprintk(ioc, |
3704 | ioc_info(ioc, "%s: host is not operational: handle(0x%04x)\n", | |
3705 | __func__, handle)); | |
f92363d1 SR |
3706 | return; |
3707 | } | |
3708 | ||
3709 | /* if PD, then return */ | |
3710 | if (test_bit(handle, ioc->pd_handles)) | |
3711 | return; | |
3712 | ||
c696f7b8 SPS |
3713 | clear_bit(handle, ioc->pend_os_device_add); |
3714 | ||
f92363d1 | 3715 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 3716 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
3717 | if (sas_device && sas_device->starget && |
3718 | sas_device->starget->hostdata) { | |
3719 | sas_target_priv_data = sas_device->starget->hostdata; | |
3720 | sas_target_priv_data->deleted = 1; | |
3721 | sas_address = sas_device->sas_address; | |
3722 | } | |
3723 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
6ce2f1d1 SPS |
3724 | if (!sas_device) { |
3725 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
3726 | pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle); | |
3727 | if (pcie_device && pcie_device->starget && | |
3728 | pcie_device->starget->hostdata) { | |
3729 | sas_target_priv_data = pcie_device->starget->hostdata; | |
3730 | sas_target_priv_data->deleted = 1; | |
3731 | sas_address = pcie_device->wwid; | |
3732 | } | |
3733 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
5bb309db SP |
3734 | if (pcie_device && (!ioc->tm_custom_handling) && |
3735 | (!(mpt3sas_scsih_is_pcie_scsi_device( | |
3736 | pcie_device->device_info)))) | |
c1a6c5ac C |
3737 | tr_method = |
3738 | MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE; | |
3739 | else | |
3740 | tr_method = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET; | |
6ce2f1d1 | 3741 | } |
f92363d1 | 3742 | if (sas_target_priv_data) { |
919d8a3f JP |
3743 | dewtprintk(ioc, |
3744 | ioc_info(ioc, "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n", | |
3745 | handle, (u64)sas_address)); | |
6ce2f1d1 SPS |
3746 | if (sas_device) { |
3747 | if (sas_device->enclosure_handle != 0) | |
919d8a3f JP |
3748 | dewtprintk(ioc, |
3749 | ioc_info(ioc, "setting delete flag:enclosure logical id(0x%016llx), slot(%d)\n", | |
3750 | (u64)sas_device->enclosure_logical_id, | |
3751 | sas_device->slot)); | |
6ce2f1d1 | 3752 | if (sas_device->connector_name[0] != '\0') |
919d8a3f JP |
3753 | dewtprintk(ioc, |
3754 | ioc_info(ioc, "setting delete flag: enclosure level(0x%04x), connector name( %s)\n", | |
3755 | sas_device->enclosure_level, | |
3756 | sas_device->connector_name)); | |
6ce2f1d1 SPS |
3757 | } else if (pcie_device) { |
3758 | if (pcie_device->enclosure_handle != 0) | |
919d8a3f JP |
3759 | dewtprintk(ioc, |
3760 | ioc_info(ioc, "setting delete flag: logical id(0x%016llx), slot(%d)\n", | |
3761 | (u64)pcie_device->enclosure_logical_id, | |
3762 | pcie_device->slot)); | |
6ce2f1d1 | 3763 | if (pcie_device->connector_name[0] != '\0') |
919d8a3f JP |
3764 | dewtprintk(ioc, |
3765 | ioc_info(ioc, "setting delete flag:, enclosure level(0x%04x), connector name( %s)\n", | |
3766 | pcie_device->enclosure_level, | |
3767 | pcie_device->connector_name)); | |
6ce2f1d1 | 3768 | } |
f92363d1 SR |
3769 | _scsih_ublock_io_device(ioc, sas_address); |
3770 | sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE; | |
3771 | } | |
3772 | ||
3773 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx); | |
3774 | if (!smid) { | |
3775 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | |
3776 | if (!delayed_tr) | |
d1cb5e49 | 3777 | goto out; |
f92363d1 SR |
3778 | INIT_LIST_HEAD(&delayed_tr->list); |
3779 | delayed_tr->handle = handle; | |
3780 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); | |
919d8a3f JP |
3781 | dewtprintk(ioc, |
3782 | ioc_info(ioc, "DELAYED:tr:handle(0x%04x), (open)\n", | |
3783 | handle)); | |
d1cb5e49 | 3784 | goto out; |
f92363d1 SR |
3785 | } |
3786 | ||
919d8a3f JP |
3787 | dewtprintk(ioc, |
3788 | ioc_info(ioc, "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
3789 | handle, smid, ioc->tm_tr_cb_idx)); | |
f92363d1 SR |
3790 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
3791 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | |
3792 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | |
3793 | mpi_request->DevHandle = cpu_to_le16(handle); | |
3794 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; | |
c1a6c5ac | 3795 | mpi_request->MsgFlags = tr_method; |
c696f7b8 | 3796 | set_bit(handle, ioc->device_remove_in_progress); |
078a4cc1 | 3797 | ioc->put_smid_hi_priority(ioc, smid, 0); |
f92363d1 | 3798 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL); |
d1cb5e49 SR |
3799 | |
3800 | out: | |
3801 | if (sas_device) | |
3802 | sas_device_put(sas_device); | |
6ce2f1d1 SPS |
3803 | if (pcie_device) |
3804 | pcie_device_put(pcie_device); | |
f92363d1 SR |
3805 | } |
3806 | ||
3807 | /** | |
3808 | * _scsih_tm_tr_complete - | |
3809 | * @ioc: per adapter object | |
3810 | * @smid: system request message index | |
3811 | * @msix_index: MSIX table index supplied by the OS | |
3812 | * @reply: reply message frame(lower 32bit addr) | |
3813 | * Context: interrupt time. | |
3814 | * | |
3815 | * This is the target reset completion routine. | |
3816 | * This code is part of the code to initiate the device removal | |
3817 | * handshake protocol with controller firmware. | |
3818 | * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE) | |
3819 | * | |
4beb4867 BVA |
3820 | * Return: 1 meaning mf should be freed from _base_interrupt |
3821 | * 0 means the mf is freed from this function. | |
f92363d1 SR |
3822 | */ |
3823 | static u8 | |
3824 | _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, | |
3825 | u32 reply) | |
3826 | { | |
3827 | u16 handle; | |
3828 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; | |
3829 | Mpi2SCSITaskManagementReply_t *mpi_reply = | |
3830 | mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
3831 | Mpi2SasIoUnitControlRequest_t *mpi_request; | |
3832 | u16 smid_sas_ctrl; | |
3833 | u32 ioc_state; | |
fd0331b3 | 3834 | struct _sc_list *delayed_sc; |
f92363d1 | 3835 | |
79eb96d6 | 3836 | if (ioc->pci_error_recovery) { |
919d8a3f JP |
3837 | dewtprintk(ioc, |
3838 | ioc_info(ioc, "%s: host in pci error recovery\n", | |
3839 | __func__)); | |
f92363d1 SR |
3840 | return 1; |
3841 | } | |
3842 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); | |
3843 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | |
919d8a3f JP |
3844 | dewtprintk(ioc, |
3845 | ioc_info(ioc, "%s: host is not operational\n", | |
3846 | __func__)); | |
f92363d1 SR |
3847 | return 1; |
3848 | } | |
3849 | if (unlikely(!mpi_reply)) { | |
919d8a3f JP |
3850 | ioc_err(ioc, "mpi_reply not valid at %s:%d/%s()!\n", |
3851 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
3852 | return 1; |
3853 | } | |
3854 | mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid); | |
3855 | handle = le16_to_cpu(mpi_request_tm->DevHandle); | |
3856 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { | |
919d8a3f JP |
3857 | dewtprintk(ioc, |
3858 | ioc_err(ioc, "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n", | |
3859 | handle, | |
3860 | le16_to_cpu(mpi_reply->DevHandle), smid)); | |
f92363d1 SR |
3861 | return 0; |
3862 | } | |
3863 | ||
3864 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT); | |
919d8a3f JP |
3865 | dewtprintk(ioc, |
3866 | ioc_info(ioc, "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), loginfo(0x%08x), completed(%d)\n", | |
3867 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), | |
3868 | le32_to_cpu(mpi_reply->IOCLogInfo), | |
3869 | le32_to_cpu(mpi_reply->TerminationCount))); | |
f92363d1 SR |
3870 | |
3871 | smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx); | |
3872 | if (!smid_sas_ctrl) { | |
fd0331b3 SS |
3873 | delayed_sc = kzalloc(sizeof(*delayed_sc), GFP_ATOMIC); |
3874 | if (!delayed_sc) | |
3875 | return _scsih_check_for_pending_tm(ioc, smid); | |
3876 | INIT_LIST_HEAD(&delayed_sc->list); | |
cf6bf971 | 3877 | delayed_sc->handle = le16_to_cpu(mpi_request_tm->DevHandle); |
fd0331b3 | 3878 | list_add_tail(&delayed_sc->list, &ioc->delayed_sc_list); |
919d8a3f JP |
3879 | dewtprintk(ioc, |
3880 | ioc_info(ioc, "DELAYED:sc:handle(0x%04x), (open)\n", | |
3881 | handle)); | |
fd0331b3 | 3882 | return _scsih_check_for_pending_tm(ioc, smid); |
f92363d1 SR |
3883 | } |
3884 | ||
919d8a3f JP |
3885 | dewtprintk(ioc, |
3886 | ioc_info(ioc, "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
3887 | handle, smid_sas_ctrl, ioc->tm_sas_control_cb_idx)); | |
f92363d1 SR |
3888 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl); |
3889 | memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t)); | |
3890 | mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; | |
3891 | mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE; | |
3892 | mpi_request->DevHandle = mpi_request_tm->DevHandle; | |
078a4cc1 | 3893 | ioc->put_smid_default(ioc, smid_sas_ctrl); |
f92363d1 SR |
3894 | |
3895 | return _scsih_check_for_pending_tm(ioc, smid); | |
3896 | } | |
3897 | ||
9029a725 SP |
3898 | /** _scsih_allow_scmd_to_device - check whether scmd needs to |
3899 | * issue to IOC or not. | |
3900 | * @ioc: per adapter object | |
3901 | * @scmd: pointer to scsi command object | |
3902 | * | |
3903 | * Returns true if scmd can be issued to IOC otherwise returns false. | |
3904 | */ | |
3905 | inline bool _scsih_allow_scmd_to_device(struct MPT3SAS_ADAPTER *ioc, | |
3906 | struct scsi_cmnd *scmd) | |
3907 | { | |
3908 | ||
3909 | if (ioc->pci_error_recovery) | |
3910 | return false; | |
3911 | ||
3912 | if (ioc->hba_mpi_version_belonged == MPI2_VERSION) { | |
3913 | if (ioc->remove_host) | |
3914 | return false; | |
3915 | ||
3916 | return true; | |
3917 | } | |
3918 | ||
3919 | if (ioc->remove_host) { | |
3920 | ||
3921 | switch (scmd->cmnd[0]) { | |
3922 | case SYNCHRONIZE_CACHE: | |
3923 | case START_STOP: | |
3924 | return true; | |
3925 | default: | |
3926 | return false; | |
3927 | } | |
3928 | } | |
3929 | ||
3930 | return true; | |
3931 | } | |
f92363d1 SR |
3932 | |
3933 | /** | |
3934 | * _scsih_sas_control_complete - completion routine | |
3935 | * @ioc: per adapter object | |
3936 | * @smid: system request message index | |
3937 | * @msix_index: MSIX table index supplied by the OS | |
3938 | * @reply: reply message frame(lower 32bit addr) | |
3939 | * Context: interrupt time. | |
3940 | * | |
3941 | * This is the sas iounit control completion routine. | |
3942 | * This code is part of the code to initiate the device removal | |
3943 | * handshake protocol with controller firmware. | |
3944 | * | |
4beb4867 BVA |
3945 | * Return: 1 meaning mf should be freed from _base_interrupt |
3946 | * 0 means the mf is freed from this function. | |
f92363d1 SR |
3947 | */ |
3948 | static u8 | |
3949 | _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, | |
3950 | u8 msix_index, u32 reply) | |
3951 | { | |
3952 | Mpi2SasIoUnitControlReply_t *mpi_reply = | |
3953 | mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
3954 | ||
3955 | if (likely(mpi_reply)) { | |
919d8a3f JP |
3956 | dewtprintk(ioc, |
3957 | ioc_info(ioc, "sc_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n", | |
3958 | le16_to_cpu(mpi_reply->DevHandle), smid, | |
3959 | le16_to_cpu(mpi_reply->IOCStatus), | |
3960 | le32_to_cpu(mpi_reply->IOCLogInfo))); | |
c696f7b8 SPS |
3961 | if (le16_to_cpu(mpi_reply->IOCStatus) == |
3962 | MPI2_IOCSTATUS_SUCCESS) { | |
3963 | clear_bit(le16_to_cpu(mpi_reply->DevHandle), | |
3964 | ioc->device_remove_in_progress); | |
3965 | } | |
f92363d1 | 3966 | } else { |
919d8a3f JP |
3967 | ioc_err(ioc, "mpi_reply not valid at %s:%d/%s()!\n", |
3968 | __FILE__, __LINE__, __func__); | |
f92363d1 | 3969 | } |
fd0331b3 | 3970 | return mpt3sas_check_for_pending_internal_cmds(ioc, smid); |
f92363d1 SR |
3971 | } |
3972 | ||
3973 | /** | |
3974 | * _scsih_tm_tr_volume_send - send target reset request for volumes | |
3975 | * @ioc: per adapter object | |
3976 | * @handle: device handle | |
3977 | * Context: interrupt time. | |
3978 | * | |
3979 | * This is designed to send muliple task management request at the same | |
3980 | * time to the fifo. If the fifo is full, we will append the request, | |
3981 | * and process it in a future completion. | |
3982 | */ | |
3983 | static void | |
3984 | _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
3985 | { | |
3986 | Mpi2SCSITaskManagementRequest_t *mpi_request; | |
3987 | u16 smid; | |
3988 | struct _tr_list *delayed_tr; | |
3989 | ||
79eb96d6 | 3990 | if (ioc->pci_error_recovery) { |
4dc74b2e JP |
3991 | dewtprintk(ioc, |
3992 | ioc_info(ioc, "%s: host reset in progress!\n", | |
3993 | __func__)); | |
f92363d1 SR |
3994 | return; |
3995 | } | |
3996 | ||
3997 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx); | |
3998 | if (!smid) { | |
3999 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | |
4000 | if (!delayed_tr) | |
4001 | return; | |
4002 | INIT_LIST_HEAD(&delayed_tr->list); | |
4003 | delayed_tr->handle = handle; | |
4004 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list); | |
919d8a3f JP |
4005 | dewtprintk(ioc, |
4006 | ioc_info(ioc, "DELAYED:tr:handle(0x%04x), (open)\n", | |
4007 | handle)); | |
f92363d1 SR |
4008 | return; |
4009 | } | |
4010 | ||
919d8a3f JP |
4011 | dewtprintk(ioc, |
4012 | ioc_info(ioc, "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
4013 | handle, smid, ioc->tm_tr_volume_cb_idx)); | |
f92363d1 SR |
4014 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
4015 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | |
4016 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | |
4017 | mpi_request->DevHandle = cpu_to_le16(handle); | |
4018 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; | |
078a4cc1 | 4019 | ioc->put_smid_hi_priority(ioc, smid, 0); |
f92363d1 SR |
4020 | } |
4021 | ||
4022 | /** | |
4023 | * _scsih_tm_volume_tr_complete - target reset completion | |
4024 | * @ioc: per adapter object | |
4025 | * @smid: system request message index | |
4026 | * @msix_index: MSIX table index supplied by the OS | |
4027 | * @reply: reply message frame(lower 32bit addr) | |
4028 | * Context: interrupt time. | |
4029 | * | |
4beb4867 BVA |
4030 | * Return: 1 meaning mf should be freed from _base_interrupt |
4031 | * 0 means the mf is freed from this function. | |
f92363d1 SR |
4032 | */ |
4033 | static u8 | |
4034 | _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, | |
4035 | u8 msix_index, u32 reply) | |
4036 | { | |
4037 | u16 handle; | |
4038 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; | |
4039 | Mpi2SCSITaskManagementReply_t *mpi_reply = | |
4040 | mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
4041 | ||
79eb96d6 | 4042 | if (ioc->shost_recovery || ioc->pci_error_recovery) { |
4dc74b2e JP |
4043 | dewtprintk(ioc, |
4044 | ioc_info(ioc, "%s: host reset in progress!\n", | |
4045 | __func__)); | |
f92363d1 SR |
4046 | return 1; |
4047 | } | |
4048 | if (unlikely(!mpi_reply)) { | |
919d8a3f JP |
4049 | ioc_err(ioc, "mpi_reply not valid at %s:%d/%s()!\n", |
4050 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
4051 | return 1; |
4052 | } | |
4053 | ||
4054 | mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid); | |
4055 | handle = le16_to_cpu(mpi_request_tm->DevHandle); | |
4056 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { | |
919d8a3f JP |
4057 | dewtprintk(ioc, |
4058 | ioc_err(ioc, "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n", | |
4059 | handle, le16_to_cpu(mpi_reply->DevHandle), | |
4060 | smid)); | |
f92363d1 SR |
4061 | return 0; |
4062 | } | |
4063 | ||
919d8a3f JP |
4064 | dewtprintk(ioc, |
4065 | ioc_info(ioc, "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), loginfo(0x%08x), completed(%d)\n", | |
4066 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), | |
4067 | le32_to_cpu(mpi_reply->IOCLogInfo), | |
4068 | le32_to_cpu(mpi_reply->TerminationCount))); | |
f92363d1 SR |
4069 | |
4070 | return _scsih_check_for_pending_tm(ioc, smid); | |
4071 | } | |
4072 | ||
fd0331b3 SS |
4073 | /** |
4074 | * _scsih_issue_delayed_event_ack - issue delayed Event ACK messages | |
4075 | * @ioc: per adapter object | |
4076 | * @smid: system request message index | |
4077 | * @event: Event ID | |
4078 | * @event_context: used to track events uniquely | |
4079 | * | |
4080 | * Context - processed in interrupt context. | |
4081 | */ | |
8bbb1cf6 | 4082 | static void |
cf6bf971 C |
4083 | _scsih_issue_delayed_event_ack(struct MPT3SAS_ADAPTER *ioc, u16 smid, U16 event, |
4084 | U32 event_context) | |
fd0331b3 SS |
4085 | { |
4086 | Mpi2EventAckRequest_t *ack_request; | |
4087 | int i = smid - ioc->internal_smid; | |
4088 | unsigned long flags; | |
4089 | ||
4090 | /* Without releasing the smid just update the | |
4091 | * call back index and reuse the same smid for | |
4092 | * processing this delayed request | |
4093 | */ | |
4094 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
4095 | ioc->internal_lookup[i].cb_idx = ioc->base_cb_idx; | |
4096 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
4097 | ||
919d8a3f JP |
4098 | dewtprintk(ioc, |
4099 | ioc_info(ioc, "EVENT ACK: event(0x%04x), smid(%d), cb(%d)\n", | |
4100 | le16_to_cpu(event), smid, ioc->base_cb_idx)); | |
fd0331b3 SS |
4101 | ack_request = mpt3sas_base_get_msg_frame(ioc, smid); |
4102 | memset(ack_request, 0, sizeof(Mpi2EventAckRequest_t)); | |
4103 | ack_request->Function = MPI2_FUNCTION_EVENT_ACK; | |
4104 | ack_request->Event = event; | |
4105 | ack_request->EventContext = event_context; | |
4106 | ack_request->VF_ID = 0; /* TODO */ | |
4107 | ack_request->VP_ID = 0; | |
078a4cc1 | 4108 | ioc->put_smid_default(ioc, smid); |
fd0331b3 SS |
4109 | } |
4110 | ||
4111 | /** | |
4112 | * _scsih_issue_delayed_sas_io_unit_ctrl - issue delayed | |
4113 | * sas_io_unit_ctrl messages | |
4114 | * @ioc: per adapter object | |
4115 | * @smid: system request message index | |
4116 | * @handle: device handle | |
4117 | * | |
4118 | * Context - processed in interrupt context. | |
4119 | */ | |
8bbb1cf6 | 4120 | static void |
fd0331b3 SS |
4121 | _scsih_issue_delayed_sas_io_unit_ctrl(struct MPT3SAS_ADAPTER *ioc, |
4122 | u16 smid, u16 handle) | |
199fd79a BVA |
4123 | { |
4124 | Mpi2SasIoUnitControlRequest_t *mpi_request; | |
4125 | u32 ioc_state; | |
4126 | int i = smid - ioc->internal_smid; | |
4127 | unsigned long flags; | |
fd0331b3 | 4128 | |
199fd79a | 4129 | if (ioc->remove_host) { |
4dc74b2e JP |
4130 | dewtprintk(ioc, |
4131 | ioc_info(ioc, "%s: host has been removed\n", | |
4132 | __func__)); | |
199fd79a BVA |
4133 | return; |
4134 | } else if (ioc->pci_error_recovery) { | |
4dc74b2e JP |
4135 | dewtprintk(ioc, |
4136 | ioc_info(ioc, "%s: host in pci error recovery\n", | |
4137 | __func__)); | |
fd0331b3 SS |
4138 | return; |
4139 | } | |
4140 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); | |
4141 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | |
4dc74b2e JP |
4142 | dewtprintk(ioc, |
4143 | ioc_info(ioc, "%s: host is not operational\n", | |
4144 | __func__)); | |
fd0331b3 SS |
4145 | return; |
4146 | } | |
4147 | ||
4148 | /* Without releasing the smid just update the | |
4149 | * call back index and reuse the same smid for | |
4150 | * processing this delayed request | |
4151 | */ | |
4152 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
4153 | ioc->internal_lookup[i].cb_idx = ioc->tm_sas_control_cb_idx; | |
4154 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
4155 | ||
919d8a3f JP |
4156 | dewtprintk(ioc, |
4157 | ioc_info(ioc, "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
4158 | handle, smid, ioc->tm_sas_control_cb_idx)); | |
fd0331b3 SS |
4159 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
4160 | memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t)); | |
4161 | mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; | |
4162 | mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE; | |
cf6bf971 | 4163 | mpi_request->DevHandle = cpu_to_le16(handle); |
078a4cc1 | 4164 | ioc->put_smid_default(ioc, smid); |
fd0331b3 SS |
4165 | } |
4166 | ||
4167 | /** | |
4168 | * _scsih_check_for_pending_internal_cmds - check for pending internal messages | |
4169 | * @ioc: per adapter object | |
4170 | * @smid: system request message index | |
4171 | * | |
4172 | * Context: Executed in interrupt context | |
4173 | * | |
4174 | * This will check delayed internal messages list, and process the | |
4175 | * next request. | |
4176 | * | |
4beb4867 BVA |
4177 | * Return: 1 meaning mf should be freed from _base_interrupt |
4178 | * 0 means the mf is freed from this function. | |
fd0331b3 SS |
4179 | */ |
4180 | u8 | |
4181 | mpt3sas_check_for_pending_internal_cmds(struct MPT3SAS_ADAPTER *ioc, u16 smid) | |
4182 | { | |
4183 | struct _sc_list *delayed_sc; | |
4184 | struct _event_ack_list *delayed_event_ack; | |
4185 | ||
4186 | if (!list_empty(&ioc->delayed_event_ack_list)) { | |
4187 | delayed_event_ack = list_entry(ioc->delayed_event_ack_list.next, | |
4188 | struct _event_ack_list, list); | |
4189 | _scsih_issue_delayed_event_ack(ioc, smid, | |
4190 | delayed_event_ack->Event, delayed_event_ack->EventContext); | |
4191 | list_del(&delayed_event_ack->list); | |
4192 | kfree(delayed_event_ack); | |
4193 | return 0; | |
4194 | } | |
4195 | ||
4196 | if (!list_empty(&ioc->delayed_sc_list)) { | |
4197 | delayed_sc = list_entry(ioc->delayed_sc_list.next, | |
4198 | struct _sc_list, list); | |
4199 | _scsih_issue_delayed_sas_io_unit_ctrl(ioc, smid, | |
4200 | delayed_sc->handle); | |
4201 | list_del(&delayed_sc->list); | |
4202 | kfree(delayed_sc); | |
4203 | return 0; | |
4204 | } | |
4205 | return 1; | |
4206 | } | |
f92363d1 SR |
4207 | |
4208 | /** | |
4209 | * _scsih_check_for_pending_tm - check for pending task management | |
4210 | * @ioc: per adapter object | |
4211 | * @smid: system request message index | |
4212 | * | |
4213 | * This will check delayed target reset list, and feed the | |
4214 | * next reqeust. | |
4215 | * | |
4beb4867 BVA |
4216 | * Return: 1 meaning mf should be freed from _base_interrupt |
4217 | * 0 means the mf is freed from this function. | |
f92363d1 SR |
4218 | */ |
4219 | static u8 | |
4220 | _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid) | |
4221 | { | |
4222 | struct _tr_list *delayed_tr; | |
4223 | ||
4224 | if (!list_empty(&ioc->delayed_tr_volume_list)) { | |
4225 | delayed_tr = list_entry(ioc->delayed_tr_volume_list.next, | |
4226 | struct _tr_list, list); | |
4227 | mpt3sas_base_free_smid(ioc, smid); | |
4228 | _scsih_tm_tr_volume_send(ioc, delayed_tr->handle); | |
4229 | list_del(&delayed_tr->list); | |
4230 | kfree(delayed_tr); | |
4231 | return 0; | |
4232 | } | |
4233 | ||
4234 | if (!list_empty(&ioc->delayed_tr_list)) { | |
4235 | delayed_tr = list_entry(ioc->delayed_tr_list.next, | |
4236 | struct _tr_list, list); | |
4237 | mpt3sas_base_free_smid(ioc, smid); | |
4238 | _scsih_tm_tr_send(ioc, delayed_tr->handle); | |
4239 | list_del(&delayed_tr->list); | |
4240 | kfree(delayed_tr); | |
4241 | return 0; | |
4242 | } | |
4243 | ||
4244 | return 1; | |
4245 | } | |
4246 | ||
4247 | /** | |
4248 | * _scsih_check_topo_delete_events - sanity check on topo events | |
4249 | * @ioc: per adapter object | |
4250 | * @event_data: the event data payload | |
4251 | * | |
4252 | * This routine added to better handle cable breaker. | |
4253 | * | |
4254 | * This handles the case where driver receives multiple expander | |
4255 | * add and delete events in a single shot. When there is a delete event | |
4256 | * the routine will void any pending add events waiting in the event queue. | |
f92363d1 SR |
4257 | */ |
4258 | static void | |
4259 | _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc, | |
4260 | Mpi2EventDataSasTopologyChangeList_t *event_data) | |
4261 | { | |
4262 | struct fw_event_work *fw_event; | |
4263 | Mpi2EventDataSasTopologyChangeList_t *local_event_data; | |
4264 | u16 expander_handle; | |
4265 | struct _sas_node *sas_expander; | |
4266 | unsigned long flags; | |
4267 | int i, reason_code; | |
4268 | u16 handle; | |
4269 | ||
4270 | for (i = 0 ; i < event_data->NumEntries; i++) { | |
4271 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
4272 | if (!handle) | |
4273 | continue; | |
4274 | reason_code = event_data->PHY[i].PhyStatus & | |
4275 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
4276 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING) | |
4277 | _scsih_tm_tr_send(ioc, handle); | |
4278 | } | |
4279 | ||
4280 | expander_handle = le16_to_cpu(event_data->ExpanderDevHandle); | |
4281 | if (expander_handle < ioc->sas_hba.num_phys) { | |
4282 | _scsih_block_io_to_children_attached_directly(ioc, event_data); | |
4283 | return; | |
4284 | } | |
4285 | if (event_data->ExpStatus == | |
4286 | MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) { | |
4287 | /* put expander attached devices into blocking state */ | |
4288 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
4289 | sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc, | |
4290 | expander_handle); | |
4291 | _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander); | |
4292 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
4293 | do { | |
4294 | handle = find_first_bit(ioc->blocking_handles, | |
4295 | ioc->facts.MaxDevHandle); | |
4296 | if (handle < ioc->facts.MaxDevHandle) | |
4297 | _scsih_block_io_device(ioc, handle); | |
4298 | } while (test_and_clear_bit(handle, ioc->blocking_handles)); | |
4299 | } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING) | |
4300 | _scsih_block_io_to_children_attached_directly(ioc, event_data); | |
4301 | ||
4302 | if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) | |
4303 | return; | |
4304 | ||
4305 | /* mark ignore flag for pending events */ | |
4306 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
4307 | list_for_each_entry(fw_event, &ioc->fw_event_list, list) { | |
4308 | if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST || | |
4309 | fw_event->ignore) | |
4310 | continue; | |
35b62362 JL |
4311 | local_event_data = (Mpi2EventDataSasTopologyChangeList_t *) |
4312 | fw_event->event_data; | |
f92363d1 SR |
4313 | if (local_event_data->ExpStatus == |
4314 | MPI2_EVENT_SAS_TOPO_ES_ADDED || | |
4315 | local_event_data->ExpStatus == | |
4316 | MPI2_EVENT_SAS_TOPO_ES_RESPONDING) { | |
4317 | if (le16_to_cpu(local_event_data->ExpanderDevHandle) == | |
4318 | expander_handle) { | |
919d8a3f JP |
4319 | dewtprintk(ioc, |
4320 | ioc_info(ioc, "setting ignoring flag\n")); | |
f92363d1 SR |
4321 | fw_event->ignore = 1; |
4322 | } | |
4323 | } | |
4324 | } | |
4325 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
4326 | } | |
4327 | ||
4318c734 SPS |
4328 | /** |
4329 | * _scsih_check_pcie_topo_remove_events - sanity check on topo | |
4330 | * events | |
4331 | * @ioc: per adapter object | |
4332 | * @event_data: the event data payload | |
4333 | * | |
4334 | * This handles the case where driver receives multiple switch | |
4335 | * or device add and delete events in a single shot. When there | |
4336 | * is a delete event the routine will void any pending add | |
4337 | * events waiting in the event queue. | |
4318c734 SPS |
4338 | */ |
4339 | static void | |
4340 | _scsih_check_pcie_topo_remove_events(struct MPT3SAS_ADAPTER *ioc, | |
4341 | Mpi26EventDataPCIeTopologyChangeList_t *event_data) | |
4342 | { | |
4343 | struct fw_event_work *fw_event; | |
4344 | Mpi26EventDataPCIeTopologyChangeList_t *local_event_data; | |
4345 | unsigned long flags; | |
4346 | int i, reason_code; | |
4347 | u16 handle, switch_handle; | |
4348 | ||
4349 | for (i = 0; i < event_data->NumEntries; i++) { | |
4350 | handle = | |
4351 | le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle); | |
4352 | if (!handle) | |
4353 | continue; | |
4354 | reason_code = event_data->PortEntry[i].PortStatus; | |
4355 | if (reason_code == MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING) | |
4356 | _scsih_tm_tr_send(ioc, handle); | |
4357 | } | |
4358 | ||
4359 | switch_handle = le16_to_cpu(event_data->SwitchDevHandle); | |
4360 | if (!switch_handle) { | |
4361 | _scsih_block_io_to_pcie_children_attached_directly( | |
4362 | ioc, event_data); | |
4363 | return; | |
4364 | } | |
4365 | /* TODO We are not supporting cascaded PCIe Switch removal yet*/ | |
4366 | if ((event_data->SwitchStatus | |
4367 | == MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING) || | |
4368 | (event_data->SwitchStatus == | |
4369 | MPI26_EVENT_PCIE_TOPO_SS_RESPONDING)) | |
4370 | _scsih_block_io_to_pcie_children_attached_directly( | |
4371 | ioc, event_data); | |
4372 | ||
4373 | if (event_data->SwitchStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) | |
4374 | return; | |
4375 | ||
4376 | /* mark ignore flag for pending events */ | |
4377 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
4378 | list_for_each_entry(fw_event, &ioc->fw_event_list, list) { | |
4379 | if (fw_event->event != MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST || | |
4380 | fw_event->ignore) | |
4381 | continue; | |
4382 | local_event_data = | |
4383 | (Mpi26EventDataPCIeTopologyChangeList_t *) | |
4384 | fw_event->event_data; | |
4385 | if (local_event_data->SwitchStatus == | |
4386 | MPI2_EVENT_SAS_TOPO_ES_ADDED || | |
4387 | local_event_data->SwitchStatus == | |
4388 | MPI2_EVENT_SAS_TOPO_ES_RESPONDING) { | |
4389 | if (le16_to_cpu(local_event_data->SwitchDevHandle) == | |
4390 | switch_handle) { | |
919d8a3f JP |
4391 | dewtprintk(ioc, |
4392 | ioc_info(ioc, "setting ignoring flag for switch event\n")); | |
4318c734 SPS |
4393 | fw_event->ignore = 1; |
4394 | } | |
4395 | } | |
4396 | } | |
4397 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
4398 | } | |
4399 | ||
f92363d1 SR |
4400 | /** |
4401 | * _scsih_set_volume_delete_flag - setting volume delete flag | |
4402 | * @ioc: per adapter object | |
4403 | * @handle: device handle | |
4404 | * | |
4405 | * This returns nothing. | |
4406 | */ | |
4407 | static void | |
4408 | _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
4409 | { | |
4410 | struct _raid_device *raid_device; | |
4411 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
4412 | unsigned long flags; | |
4413 | ||
4414 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
c84b06a4 | 4415 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
4416 | if (raid_device && raid_device->starget && |
4417 | raid_device->starget->hostdata) { | |
4418 | sas_target_priv_data = | |
4419 | raid_device->starget->hostdata; | |
4420 | sas_target_priv_data->deleted = 1; | |
919d8a3f JP |
4421 | dewtprintk(ioc, |
4422 | ioc_info(ioc, "setting delete flag: handle(0x%04x), wwid(0x%016llx)\n", | |
4423 | handle, (u64)raid_device->wwid)); | |
f92363d1 SR |
4424 | } |
4425 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
4426 | } | |
4427 | ||
4428 | /** | |
4429 | * _scsih_set_volume_handle_for_tr - set handle for target reset to volume | |
4430 | * @handle: input handle | |
4431 | * @a: handle for volume a | |
4432 | * @b: handle for volume b | |
4433 | * | |
4434 | * IR firmware only supports two raid volumes. The purpose of this | |
4435 | * routine is to set the volume handle in either a or b. When the given | |
4436 | * input handle is non-zero, or when a and b have not been set before. | |
4437 | */ | |
4438 | static void | |
4439 | _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b) | |
4440 | { | |
4441 | if (!handle || handle == *a || handle == *b) | |
4442 | return; | |
4443 | if (!*a) | |
4444 | *a = handle; | |
4445 | else if (!*b) | |
4446 | *b = handle; | |
4447 | } | |
4448 | ||
4449 | /** | |
4450 | * _scsih_check_ir_config_unhide_events - check for UNHIDE events | |
4451 | * @ioc: per adapter object | |
4452 | * @event_data: the event data payload | |
4453 | * Context: interrupt time. | |
4454 | * | |
4455 | * This routine will send target reset to volume, followed by target | |
4456 | * resets to the PDs. This is called when a PD has been removed, or | |
4457 | * volume has been deleted or removed. When the target reset is sent | |
4458 | * to volume, the PD target resets need to be queued to start upon | |
4459 | * completion of the volume target reset. | |
f92363d1 SR |
4460 | */ |
4461 | static void | |
4462 | _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc, | |
4463 | Mpi2EventDataIrConfigChangeList_t *event_data) | |
4464 | { | |
4465 | Mpi2EventIrConfigElement_t *element; | |
4466 | int i; | |
4467 | u16 handle, volume_handle, a, b; | |
4468 | struct _tr_list *delayed_tr; | |
4469 | ||
4470 | a = 0; | |
4471 | b = 0; | |
4472 | ||
7786ab6a SR |
4473 | if (ioc->is_warpdrive) |
4474 | return; | |
4475 | ||
f92363d1 SR |
4476 | /* Volume Resets for Deleted or Removed */ |
4477 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
4478 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
4479 | if (le32_to_cpu(event_data->Flags) & | |
4480 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) | |
4481 | continue; | |
4482 | if (element->ReasonCode == | |
4483 | MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED || | |
4484 | element->ReasonCode == | |
4485 | MPI2_EVENT_IR_CHANGE_RC_REMOVED) { | |
4486 | volume_handle = le16_to_cpu(element->VolDevHandle); | |
4487 | _scsih_set_volume_delete_flag(ioc, volume_handle); | |
4488 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); | |
4489 | } | |
4490 | } | |
4491 | ||
4492 | /* Volume Resets for UNHIDE events */ | |
4493 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
4494 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
4495 | if (le32_to_cpu(event_data->Flags) & | |
4496 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) | |
4497 | continue; | |
4498 | if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) { | |
4499 | volume_handle = le16_to_cpu(element->VolDevHandle); | |
4500 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); | |
4501 | } | |
4502 | } | |
4503 | ||
4504 | if (a) | |
4505 | _scsih_tm_tr_volume_send(ioc, a); | |
4506 | if (b) | |
4507 | _scsih_tm_tr_volume_send(ioc, b); | |
4508 | ||
4509 | /* PD target resets */ | |
4510 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
4511 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
4512 | if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE) | |
4513 | continue; | |
4514 | handle = le16_to_cpu(element->PhysDiskDevHandle); | |
4515 | volume_handle = le16_to_cpu(element->VolDevHandle); | |
4516 | clear_bit(handle, ioc->pd_handles); | |
4517 | if (!volume_handle) | |
4518 | _scsih_tm_tr_send(ioc, handle); | |
4519 | else if (volume_handle == a || volume_handle == b) { | |
4520 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | |
4521 | BUG_ON(!delayed_tr); | |
4522 | INIT_LIST_HEAD(&delayed_tr->list); | |
4523 | delayed_tr->handle = handle; | |
4524 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); | |
919d8a3f JP |
4525 | dewtprintk(ioc, |
4526 | ioc_info(ioc, "DELAYED:tr:handle(0x%04x), (open)\n", | |
4527 | handle)); | |
f92363d1 SR |
4528 | } else |
4529 | _scsih_tm_tr_send(ioc, handle); | |
4530 | } | |
4531 | } | |
4532 | ||
4533 | ||
4534 | /** | |
4535 | * _scsih_check_volume_delete_events - set delete flag for volumes | |
4536 | * @ioc: per adapter object | |
4537 | * @event_data: the event data payload | |
4538 | * Context: interrupt time. | |
4539 | * | |
4540 | * This will handle the case when the cable connected to entire volume is | |
4541 | * pulled. We will take care of setting the deleted flag so normal IO will | |
4542 | * not be sent. | |
f92363d1 SR |
4543 | */ |
4544 | static void | |
4545 | _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc, | |
4546 | Mpi2EventDataIrVolume_t *event_data) | |
4547 | { | |
4548 | u32 state; | |
4549 | ||
4550 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) | |
4551 | return; | |
4552 | state = le32_to_cpu(event_data->NewValue); | |
4553 | if (state == MPI2_RAID_VOL_STATE_MISSING || state == | |
4554 | MPI2_RAID_VOL_STATE_FAILED) | |
4555 | _scsih_set_volume_delete_flag(ioc, | |
4556 | le16_to_cpu(event_data->VolDevHandle)); | |
4557 | } | |
4558 | ||
2d8ce8c9 SR |
4559 | /** |
4560 | * _scsih_temp_threshold_events - display temperature threshold exceeded events | |
4561 | * @ioc: per adapter object | |
4562 | * @event_data: the temp threshold event data | |
4563 | * Context: interrupt time. | |
2d8ce8c9 SR |
4564 | */ |
4565 | static void | |
4566 | _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER *ioc, | |
4567 | Mpi2EventDataTemperature_t *event_data) | |
4568 | { | |
1de2bf7c | 4569 | u32 doorbell; |
2d8ce8c9 | 4570 | if (ioc->temp_sensors_count >= event_data->SensorNum) { |
919d8a3f JP |
4571 | ioc_err(ioc, "Temperature Threshold flags %s%s%s%s exceeded for Sensor: %d !!!\n", |
4572 | le16_to_cpu(event_data->Status) & 0x1 ? "0 " : " ", | |
4573 | le16_to_cpu(event_data->Status) & 0x2 ? "1 " : " ", | |
4574 | le16_to_cpu(event_data->Status) & 0x4 ? "2 " : " ", | |
4575 | le16_to_cpu(event_data->Status) & 0x8 ? "3 " : " ", | |
4576 | event_data->SensorNum); | |
4577 | ioc_err(ioc, "Current Temp In Celsius: %d\n", | |
4578 | event_data->CurrentTemperature); | |
1de2bf7c SR |
4579 | if (ioc->hba_mpi_version_belonged != MPI2_VERSION) { |
4580 | doorbell = mpt3sas_base_get_iocstate(ioc, 0); | |
4581 | if ((doorbell & MPI2_IOC_STATE_MASK) == | |
4582 | MPI2_IOC_STATE_FAULT) { | |
e0a035be | 4583 | mpt3sas_print_fault_code(ioc, |
1de2bf7c SR |
4584 | doorbell & MPI2_DOORBELL_DATA_MASK); |
4585 | } else if ((doorbell & MPI2_IOC_STATE_MASK) == | |
4586 | MPI2_IOC_STATE_COREDUMP) { | |
e0a035be | 4587 | mpt3sas_print_coredump_info(ioc, |
1de2bf7c SR |
4588 | doorbell & MPI2_DOORBELL_DATA_MASK); |
4589 | } | |
4590 | } | |
2d8ce8c9 SR |
4591 | } |
4592 | } | |
4593 | ||
ffb58456 | 4594 | static int _scsih_set_satl_pending(struct scsi_cmnd *scmd, bool pending) |
7ff723ad | 4595 | { |
ffb58456 JB |
4596 | struct MPT3SAS_DEVICE *priv = scmd->device->hostdata; |
4597 | ||
4598 | if (scmd->cmnd[0] != ATA_12 && scmd->cmnd[0] != ATA_16) | |
4599 | return 0; | |
4600 | ||
4601 | if (pending) | |
4602 | return test_and_set_bit(0, &priv->ata_command_pending); | |
4603 | ||
4604 | clear_bit(0, &priv->ata_command_pending); | |
4605 | return 0; | |
7ff723ad SP |
4606 | } |
4607 | ||
f92363d1 SR |
4608 | /** |
4609 | * _scsih_flush_running_cmds - completing outstanding commands. | |
4610 | * @ioc: per adapter object | |
4611 | * | |
4612 | * The flushing out of all pending scmd commands following host reset, | |
4613 | * where all IO is dropped to the floor. | |
f92363d1 SR |
4614 | */ |
4615 | static void | |
4616 | _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc) | |
4617 | { | |
4618 | struct scsi_cmnd *scmd; | |
dbec4c90 | 4619 | struct scsiio_tracker *st; |
f92363d1 | 4620 | u16 smid; |
dbec4c90 | 4621 | int count = 0; |
f92363d1 SR |
4622 | |
4623 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { | |
dbec4c90 | 4624 | scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid); |
f92363d1 SR |
4625 | if (!scmd) |
4626 | continue; | |
4627 | count++; | |
ffb58456 | 4628 | _scsih_set_satl_pending(scmd, false); |
dbec4c90 SPS |
4629 | st = scsi_cmd_priv(scmd); |
4630 | mpt3sas_base_clear_st(ioc, st); | |
f92363d1 | 4631 | scsi_dma_unmap(scmd); |
c666d3be | 4632 | if (ioc->pci_error_recovery || ioc->remove_host) |
f92363d1 SR |
4633 | scmd->result = DID_NO_CONNECT << 16; |
4634 | else | |
4635 | scmd->result = DID_RESET << 16; | |
4636 | scmd->scsi_done(scmd); | |
4637 | } | |
919d8a3f | 4638 | dtmprintk(ioc, ioc_info(ioc, "completing %d cmds\n", count)); |
f92363d1 SR |
4639 | } |
4640 | ||
4641 | /** | |
4642 | * _scsih_setup_eedp - setup MPI request for EEDP transfer | |
4643 | * @ioc: per adapter object | |
4644 | * @scmd: pointer to scsi command object | |
6c7abffc | 4645 | * @mpi_request: pointer to the SCSI_IO request message frame |
f92363d1 SR |
4646 | * |
4647 | * Supporting protection 1 and 3. | |
f92363d1 SR |
4648 | */ |
4649 | static void | |
4650 | _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, | |
016d5c35 | 4651 | Mpi25SCSIIORequest_t *mpi_request) |
f92363d1 SR |
4652 | { |
4653 | u16 eedp_flags; | |
4654 | unsigned char prot_op = scsi_get_prot_op(scmd); | |
4655 | unsigned char prot_type = scsi_get_prot_type(scmd); | |
4656 | Mpi25SCSIIORequest_t *mpi_request_3v = | |
4657 | (Mpi25SCSIIORequest_t *)mpi_request; | |
4658 | ||
4659 | if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL) | |
4660 | return; | |
4661 | ||
4662 | if (prot_op == SCSI_PROT_READ_STRIP) | |
4663 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP; | |
4664 | else if (prot_op == SCSI_PROT_WRITE_INSERT) | |
4665 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP; | |
4666 | else | |
4667 | return; | |
4668 | ||
4669 | switch (prot_type) { | |
4670 | case SCSI_PROT_DIF_TYPE1: | |
4671 | case SCSI_PROT_DIF_TYPE2: | |
4672 | ||
4673 | /* | |
4674 | * enable ref/guard checking | |
4675 | * auto increment ref tag | |
4676 | */ | |
4677 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG | | |
4678 | MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG | | |
4679 | MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; | |
4680 | mpi_request->CDB.EEDP32.PrimaryReferenceTag = | |
ddd0bc75 | 4681 | cpu_to_be32(t10_pi_ref_tag(scmd->request)); |
f92363d1 SR |
4682 | break; |
4683 | ||
4684 | case SCSI_PROT_DIF_TYPE3: | |
4685 | ||
4686 | /* | |
4687 | * enable guard checking | |
4688 | */ | |
4689 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; | |
4690 | ||
4691 | break; | |
4692 | } | |
4693 | ||
4694 | mpi_request_3v->EEDPBlockSize = | |
4695 | cpu_to_le16(scmd->device->sector_size); | |
186a18e5 SPS |
4696 | |
4697 | if (ioc->is_gen35_ioc) | |
4698 | eedp_flags |= MPI25_SCSIIO_EEDPFLAGS_APPTAG_DISABLE_MODE; | |
f92363d1 SR |
4699 | mpi_request->EEDPFlags = cpu_to_le16(eedp_flags); |
4700 | } | |
4701 | ||
4702 | /** | |
4703 | * _scsih_eedp_error_handling - return sense code for EEDP errors | |
4704 | * @scmd: pointer to scsi command object | |
4705 | * @ioc_status: ioc status | |
f92363d1 SR |
4706 | */ |
4707 | static void | |
4708 | _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status) | |
4709 | { | |
4710 | u8 ascq; | |
4711 | ||
4712 | switch (ioc_status) { | |
4713 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | |
4714 | ascq = 0x01; | |
4715 | break; | |
4716 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | |
4717 | ascq = 0x02; | |
4718 | break; | |
4719 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | |
4720 | ascq = 0x03; | |
4721 | break; | |
4722 | default: | |
4723 | ascq = 0x00; | |
4724 | break; | |
4725 | } | |
4726 | scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10, | |
4727 | ascq); | |
4728 | scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) | | |
4729 | SAM_STAT_CHECK_CONDITION; | |
4730 | } | |
4731 | ||
f92363d1 | 4732 | /** |
8a7e4c24 | 4733 | * scsih_qcmd - main scsi request entry point |
4beb4867 | 4734 | * @shost: SCSI host pointer |
f92363d1 | 4735 | * @scmd: pointer to scsi command object |
f92363d1 SR |
4736 | * |
4737 | * The callback index is set inside `ioc->scsi_io_cb_idx`. | |
4738 | * | |
4beb4867 | 4739 | * Return: 0 on success. If there's a failure, return either: |
f92363d1 SR |
4740 | * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or |
4741 | * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full | |
4742 | */ | |
8bbb1cf6 | 4743 | static int |
8a7e4c24 | 4744 | scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd) |
f92363d1 | 4745 | { |
d8bfbd8d | 4746 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
f92363d1 SR |
4747 | struct MPT3SAS_DEVICE *sas_device_priv_data; |
4748 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
7786ab6a | 4749 | struct _raid_device *raid_device; |
307d9075 AM |
4750 | struct request *rq = scmd->request; |
4751 | int class; | |
016d5c35 SPS |
4752 | Mpi25SCSIIORequest_t *mpi_request; |
4753 | struct _pcie_device *pcie_device = NULL; | |
f92363d1 SR |
4754 | u32 mpi_control; |
4755 | u16 smid; | |
4756 | u16 handle; | |
4757 | ||
f92363d1 SR |
4758 | if (ioc->logging_level & MPT_DEBUG_SCSI) |
4759 | scsi_print_command(scmd); | |
f92363d1 | 4760 | |
f92363d1 SR |
4761 | sas_device_priv_data = scmd->device->hostdata; |
4762 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | |
4763 | scmd->result = DID_NO_CONNECT << 16; | |
4764 | scmd->scsi_done(scmd); | |
4765 | return 0; | |
4766 | } | |
4767 | ||
9029a725 | 4768 | if (!(_scsih_allow_scmd_to_device(ioc, scmd))) { |
f92363d1 SR |
4769 | scmd->result = DID_NO_CONNECT << 16; |
4770 | scmd->scsi_done(scmd); | |
4771 | return 0; | |
4772 | } | |
4773 | ||
4774 | sas_target_priv_data = sas_device_priv_data->sas_target; | |
4775 | ||
4776 | /* invalid device handle */ | |
4777 | handle = sas_target_priv_data->handle; | |
4778 | if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) { | |
4779 | scmd->result = DID_NO_CONNECT << 16; | |
4780 | scmd->scsi_done(scmd); | |
4781 | return 0; | |
4782 | } | |
4783 | ||
4784 | ||
199fd79a BVA |
4785 | if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress) { |
4786 | /* host recovery or link resets sent via IOCTLs */ | |
f92363d1 | 4787 | return SCSI_MLQUEUE_HOST_BUSY; |
199fd79a BVA |
4788 | } else if (sas_target_priv_data->deleted) { |
4789 | /* device has been deleted */ | |
f92363d1 SR |
4790 | scmd->result = DID_NO_CONNECT << 16; |
4791 | scmd->scsi_done(scmd); | |
4792 | return 0; | |
f92363d1 | 4793 | } else if (sas_target_priv_data->tm_busy || |
199fd79a BVA |
4794 | sas_device_priv_data->block) { |
4795 | /* device busy with task management */ | |
f92363d1 | 4796 | return SCSI_MLQUEUE_DEVICE_BUSY; |
199fd79a | 4797 | } |
f92363d1 | 4798 | |
f49d4aed C |
4799 | /* |
4800 | * Bug work around for firmware SATL handling. The loop | |
4801 | * is based on atomic operations and ensures consistency | |
4802 | * since we're lockless at this point | |
4803 | */ | |
4804 | do { | |
1edc6770 SP |
4805 | if (test_bit(0, &sas_device_priv_data->ata_command_pending)) |
4806 | return SCSI_MLQUEUE_DEVICE_BUSY; | |
f49d4aed C |
4807 | } while (_scsih_set_satl_pending(scmd, true)); |
4808 | ||
f92363d1 SR |
4809 | if (scmd->sc_data_direction == DMA_FROM_DEVICE) |
4810 | mpi_control = MPI2_SCSIIO_CONTROL_READ; | |
4811 | else if (scmd->sc_data_direction == DMA_TO_DEVICE) | |
4812 | mpi_control = MPI2_SCSIIO_CONTROL_WRITE; | |
4813 | else | |
4814 | mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER; | |
4815 | ||
4816 | /* set tags */ | |
609aa22f | 4817 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; |
307d9075 AM |
4818 | /* NCQ Prio supported, make sure control indicated high priority */ |
4819 | if (sas_device_priv_data->ncq_prio_enable) { | |
4820 | class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq)); | |
4821 | if (class == IOPRIO_CLASS_RT) | |
4822 | mpi_control |= 1 << MPI2_SCSIIO_CONTROL_CMDPRI_SHIFT; | |
4823 | } | |
7786ab6a SR |
4824 | /* Make sure Device is not raid volume. |
4825 | * We do not expose raid functionality to upper layer for warpdrive. | |
4826 | */ | |
cd5897ed SPS |
4827 | if (((!ioc->is_warpdrive && !scsih_is_raid(&scmd->device->sdev_gendev)) |
4828 | && !scsih_is_nvme(&scmd->device->sdev_gendev)) | |
4829 | && sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32) | |
f92363d1 SR |
4830 | mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON; |
4831 | ||
4832 | smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd); | |
4833 | if (!smid) { | |
919d8a3f | 4834 | ioc_err(ioc, "%s: failed obtaining a smid\n", __func__); |
f49d4aed | 4835 | _scsih_set_satl_pending(scmd, false); |
f92363d1 SR |
4836 | goto out; |
4837 | } | |
4838 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
016d5c35 | 4839 | memset(mpi_request, 0, ioc->request_sz); |
f92363d1 SR |
4840 | _scsih_setup_eedp(ioc, scmd, mpi_request); |
4841 | ||
4842 | if (scmd->cmd_len == 32) | |
4843 | mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT; | |
4844 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; | |
4845 | if (sas_device_priv_data->sas_target->flags & | |
4846 | MPT_TARGET_FLAGS_RAID_COMPONENT) | |
4847 | mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH; | |
4848 | else | |
4849 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; | |
4850 | mpi_request->DevHandle = cpu_to_le16(handle); | |
4851 | mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd)); | |
4852 | mpi_request->Control = cpu_to_le32(mpi_control); | |
4853 | mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len); | |
4854 | mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR; | |
4855 | mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE; | |
4856 | mpi_request->SenseBufferLowAddress = | |
4857 | mpt3sas_base_get_sense_buffer_dma(ioc, smid); | |
016d5c35 | 4858 | mpi_request->SGLOffset0 = offsetof(Mpi25SCSIIORequest_t, SGL) / 4; |
f92363d1 SR |
4859 | int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *) |
4860 | mpi_request->LUN); | |
4861 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); | |
4862 | ||
4863 | if (mpi_request->DataLength) { | |
016d5c35 SPS |
4864 | pcie_device = sas_target_priv_data->pcie_dev; |
4865 | if (ioc->build_sg_scmd(ioc, scmd, smid, pcie_device)) { | |
f92363d1 | 4866 | mpt3sas_base_free_smid(ioc, smid); |
f49d4aed | 4867 | _scsih_set_satl_pending(scmd, false); |
f92363d1 SR |
4868 | goto out; |
4869 | } | |
4870 | } else | |
4871 | ioc->build_zero_len_sge(ioc, &mpi_request->SGL); | |
4872 | ||
7786ab6a SR |
4873 | raid_device = sas_target_priv_data->raid_device; |
4874 | if (raid_device && raid_device->direct_io_enabled) | |
cd5897ed | 4875 | mpt3sas_setup_direct_io(ioc, scmd, |
dbec4c90 | 4876 | raid_device, mpi_request); |
7786ab6a | 4877 | |
f92363d1 SR |
4878 | if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) { |
4879 | if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) { | |
4880 | mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len | | |
4881 | MPI25_SCSIIO_IOFLAGS_FAST_PATH); | |
078a4cc1 | 4882 | ioc->put_smid_fast_path(ioc, smid, handle); |
f92363d1 | 4883 | } else |
81c16f83 | 4884 | ioc->put_smid_scsi_io(ioc, smid, |
7786ab6a | 4885 | le16_to_cpu(mpi_request->DevHandle)); |
f92363d1 | 4886 | } else |
078a4cc1 | 4887 | ioc->put_smid_default(ioc, smid); |
f92363d1 SR |
4888 | return 0; |
4889 | ||
4890 | out: | |
4891 | return SCSI_MLQUEUE_HOST_BUSY; | |
4892 | } | |
f92363d1 SR |
4893 | |
4894 | /** | |
4895 | * _scsih_normalize_sense - normalize descriptor and fixed format sense data | |
4896 | * @sense_buffer: sense data returned by target | |
4897 | * @data: normalized skey/asc/ascq | |
f92363d1 SR |
4898 | */ |
4899 | static void | |
4900 | _scsih_normalize_sense(char *sense_buffer, struct sense_info *data) | |
4901 | { | |
4902 | if ((sense_buffer[0] & 0x7F) >= 0x72) { | |
4903 | /* descriptor format */ | |
4904 | data->skey = sense_buffer[1] & 0x0F; | |
4905 | data->asc = sense_buffer[2]; | |
4906 | data->ascq = sense_buffer[3]; | |
4907 | } else { | |
4908 | /* fixed format */ | |
4909 | data->skey = sense_buffer[2] & 0x0F; | |
4910 | data->asc = sense_buffer[12]; | |
4911 | data->ascq = sense_buffer[13]; | |
4912 | } | |
4913 | } | |
4914 | ||
f92363d1 SR |
4915 | /** |
4916 | * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request | |
4917 | * @ioc: per adapter object | |
4918 | * @scmd: pointer to scsi command object | |
4919 | * @mpi_reply: reply mf payload returned from firmware | |
4beb4867 | 4920 | * @smid: ? |
f92363d1 SR |
4921 | * |
4922 | * scsi_status - SCSI Status code returned from target device | |
4923 | * scsi_state - state info associated with SCSI_IO determined by ioc | |
4924 | * ioc_status - ioc supplied status info | |
f92363d1 SR |
4925 | */ |
4926 | static void | |
4927 | _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, | |
4928 | Mpi2SCSIIOReply_t *mpi_reply, u16 smid) | |
4929 | { | |
4930 | u32 response_info; | |
4931 | u8 *response_bytes; | |
4932 | u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & | |
4933 | MPI2_IOCSTATUS_MASK; | |
4934 | u8 scsi_state = mpi_reply->SCSIState; | |
4935 | u8 scsi_status = mpi_reply->SCSIStatus; | |
4936 | char *desc_ioc_state = NULL; | |
4937 | char *desc_scsi_status = NULL; | |
4938 | char *desc_scsi_state = ioc->tmp_string; | |
4939 | u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo); | |
4940 | struct _sas_device *sas_device = NULL; | |
ec051e5a | 4941 | struct _pcie_device *pcie_device = NULL; |
f92363d1 SR |
4942 | struct scsi_target *starget = scmd->device->sdev_target; |
4943 | struct MPT3SAS_TARGET *priv_target = starget->hostdata; | |
4944 | char *device_str = NULL; | |
4945 | ||
4946 | if (!priv_target) | |
4947 | return; | |
7786ab6a SR |
4948 | if (ioc->hide_ir_msg) |
4949 | device_str = "WarpDrive"; | |
4950 | else | |
4951 | device_str = "volume"; | |
f92363d1 SR |
4952 | |
4953 | if (log_info == 0x31170000) | |
4954 | return; | |
4955 | ||
4956 | switch (ioc_status) { | |
4957 | case MPI2_IOCSTATUS_SUCCESS: | |
4958 | desc_ioc_state = "success"; | |
4959 | break; | |
4960 | case MPI2_IOCSTATUS_INVALID_FUNCTION: | |
4961 | desc_ioc_state = "invalid function"; | |
4962 | break; | |
4963 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: | |
4964 | desc_ioc_state = "scsi recovered error"; | |
4965 | break; | |
4966 | case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE: | |
4967 | desc_ioc_state = "scsi invalid dev handle"; | |
4968 | break; | |
4969 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: | |
4970 | desc_ioc_state = "scsi device not there"; | |
4971 | break; | |
4972 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: | |
4973 | desc_ioc_state = "scsi data overrun"; | |
4974 | break; | |
4975 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: | |
4976 | desc_ioc_state = "scsi data underrun"; | |
4977 | break; | |
4978 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: | |
4979 | desc_ioc_state = "scsi io data error"; | |
4980 | break; | |
4981 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: | |
4982 | desc_ioc_state = "scsi protocol error"; | |
4983 | break; | |
4984 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: | |
4985 | desc_ioc_state = "scsi task terminated"; | |
4986 | break; | |
4987 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: | |
4988 | desc_ioc_state = "scsi residual mismatch"; | |
4989 | break; | |
4990 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: | |
4991 | desc_ioc_state = "scsi task mgmt failed"; | |
4992 | break; | |
4993 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: | |
4994 | desc_ioc_state = "scsi ioc terminated"; | |
4995 | break; | |
4996 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: | |
4997 | desc_ioc_state = "scsi ext terminated"; | |
4998 | break; | |
4999 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | |
5000 | desc_ioc_state = "eedp guard error"; | |
5001 | break; | |
5002 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | |
5003 | desc_ioc_state = "eedp ref tag error"; | |
5004 | break; | |
5005 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | |
5006 | desc_ioc_state = "eedp app tag error"; | |
5007 | break; | |
b130b0d5 SS |
5008 | case MPI2_IOCSTATUS_INSUFFICIENT_POWER: |
5009 | desc_ioc_state = "insufficient power"; | |
5010 | break; | |
f92363d1 SR |
5011 | default: |
5012 | desc_ioc_state = "unknown"; | |
5013 | break; | |
5014 | } | |
5015 | ||
5016 | switch (scsi_status) { | |
5017 | case MPI2_SCSI_STATUS_GOOD: | |
5018 | desc_scsi_status = "good"; | |
5019 | break; | |
5020 | case MPI2_SCSI_STATUS_CHECK_CONDITION: | |
5021 | desc_scsi_status = "check condition"; | |
5022 | break; | |
5023 | case MPI2_SCSI_STATUS_CONDITION_MET: | |
5024 | desc_scsi_status = "condition met"; | |
5025 | break; | |
5026 | case MPI2_SCSI_STATUS_BUSY: | |
5027 | desc_scsi_status = "busy"; | |
5028 | break; | |
5029 | case MPI2_SCSI_STATUS_INTERMEDIATE: | |
5030 | desc_scsi_status = "intermediate"; | |
5031 | break; | |
5032 | case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET: | |
5033 | desc_scsi_status = "intermediate condmet"; | |
5034 | break; | |
5035 | case MPI2_SCSI_STATUS_RESERVATION_CONFLICT: | |
5036 | desc_scsi_status = "reservation conflict"; | |
5037 | break; | |
5038 | case MPI2_SCSI_STATUS_COMMAND_TERMINATED: | |
5039 | desc_scsi_status = "command terminated"; | |
5040 | break; | |
5041 | case MPI2_SCSI_STATUS_TASK_SET_FULL: | |
5042 | desc_scsi_status = "task set full"; | |
5043 | break; | |
5044 | case MPI2_SCSI_STATUS_ACA_ACTIVE: | |
5045 | desc_scsi_status = "aca active"; | |
5046 | break; | |
5047 | case MPI2_SCSI_STATUS_TASK_ABORTED: | |
5048 | desc_scsi_status = "task aborted"; | |
5049 | break; | |
5050 | default: | |
5051 | desc_scsi_status = "unknown"; | |
5052 | break; | |
5053 | } | |
5054 | ||
5055 | desc_scsi_state[0] = '\0'; | |
5056 | if (!scsi_state) | |
5057 | desc_scsi_state = " "; | |
5058 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) | |
5059 | strcat(desc_scsi_state, "response info "); | |
5060 | if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | |
5061 | strcat(desc_scsi_state, "state terminated "); | |
5062 | if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS) | |
5063 | strcat(desc_scsi_state, "no status "); | |
5064 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED) | |
5065 | strcat(desc_scsi_state, "autosense failed "); | |
5066 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) | |
5067 | strcat(desc_scsi_state, "autosense valid "); | |
5068 | ||
5069 | scsi_print_command(scmd); | |
5070 | ||
5071 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { | |
919d8a3f JP |
5072 | ioc_warn(ioc, "\t%s wwid(0x%016llx)\n", |
5073 | device_str, (u64)priv_target->sas_address); | |
ec051e5a SPS |
5074 | } else if (priv_target->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) { |
5075 | pcie_device = mpt3sas_get_pdev_from_target(ioc, priv_target); | |
5076 | if (pcie_device) { | |
919d8a3f JP |
5077 | ioc_info(ioc, "\twwid(0x%016llx), port(%d)\n", |
5078 | (u64)pcie_device->wwid, pcie_device->port_num); | |
ec051e5a | 5079 | if (pcie_device->enclosure_handle != 0) |
919d8a3f JP |
5080 | ioc_info(ioc, "\tenclosure logical id(0x%016llx), slot(%d)\n", |
5081 | (u64)pcie_device->enclosure_logical_id, | |
5082 | pcie_device->slot); | |
ec051e5a | 5083 | if (pcie_device->connector_name[0]) |
919d8a3f JP |
5084 | ioc_info(ioc, "\tenclosure level(0x%04x), connector name( %s)\n", |
5085 | pcie_device->enclosure_level, | |
5086 | pcie_device->connector_name); | |
ec051e5a SPS |
5087 | pcie_device_put(pcie_device); |
5088 | } | |
f92363d1 | 5089 | } else { |
d1cb5e49 | 5090 | sas_device = mpt3sas_get_sdev_from_target(ioc, priv_target); |
f92363d1 | 5091 | if (sas_device) { |
919d8a3f JP |
5092 | ioc_warn(ioc, "\tsas_address(0x%016llx), phy(%d)\n", |
5093 | (u64)sas_device->sas_address, sas_device->phy); | |
75888956 SR |
5094 | |
5095 | _scsih_display_enclosure_chassis_info(ioc, sas_device, | |
5096 | NULL, NULL); | |
d1cb5e49 SR |
5097 | |
5098 | sas_device_put(sas_device); | |
f92363d1 | 5099 | } |
f92363d1 SR |
5100 | } |
5101 | ||
919d8a3f JP |
5102 | ioc_warn(ioc, "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n", |
5103 | le16_to_cpu(mpi_reply->DevHandle), | |
5104 | desc_ioc_state, ioc_status, smid); | |
5105 | ioc_warn(ioc, "\trequest_len(%d), underflow(%d), resid(%d)\n", | |
5106 | scsi_bufflen(scmd), scmd->underflow, scsi_get_resid(scmd)); | |
5107 | ioc_warn(ioc, "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n", | |
5108 | le16_to_cpu(mpi_reply->TaskTag), | |
5109 | le32_to_cpu(mpi_reply->TransferCount), scmd->result); | |
5110 | ioc_warn(ioc, "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n", | |
5111 | desc_scsi_status, scsi_status, desc_scsi_state, scsi_state); | |
f92363d1 SR |
5112 | |
5113 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { | |
5114 | struct sense_info data; | |
5115 | _scsih_normalize_sense(scmd->sense_buffer, &data); | |
919d8a3f JP |
5116 | ioc_warn(ioc, "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n", |
5117 | data.skey, data.asc, data.ascq, | |
5118 | le32_to_cpu(mpi_reply->SenseCount)); | |
f92363d1 | 5119 | } |
f92363d1 SR |
5120 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) { |
5121 | response_info = le32_to_cpu(mpi_reply->ResponseInfo); | |
5122 | response_bytes = (u8 *)&response_info; | |
5123 | _scsih_response_code(ioc, response_bytes[0]); | |
5124 | } | |
5125 | } | |
f92363d1 SR |
5126 | |
5127 | /** | |
0f624c39 | 5128 | * _scsih_turn_on_pfa_led - illuminate PFA LED |
f92363d1 SR |
5129 | * @ioc: per adapter object |
5130 | * @handle: device handle | |
5131 | * Context: process | |
f92363d1 SR |
5132 | */ |
5133 | static void | |
0f624c39 | 5134 | _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
f92363d1 SR |
5135 | { |
5136 | Mpi2SepReply_t mpi_reply; | |
5137 | Mpi2SepRequest_t mpi_request; | |
0f624c39 SR |
5138 | struct _sas_device *sas_device; |
5139 | ||
d1cb5e49 | 5140 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
0f624c39 SR |
5141 | if (!sas_device) |
5142 | return; | |
f92363d1 SR |
5143 | |
5144 | memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t)); | |
5145 | mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; | |
5146 | mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; | |
5147 | mpi_request.SlotStatus = | |
5148 | cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT); | |
5149 | mpi_request.DevHandle = cpu_to_le16(handle); | |
5150 | mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS; | |
5151 | if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply, | |
5152 | &mpi_request)) != 0) { | |
919d8a3f JP |
5153 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5154 | __FILE__, __LINE__, __func__); | |
d1cb5e49 | 5155 | goto out; |
f92363d1 | 5156 | } |
0f624c39 | 5157 | sas_device->pfa_led_on = 1; |
f92363d1 SR |
5158 | |
5159 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) { | |
919d8a3f JP |
5160 | dewtprintk(ioc, |
5161 | ioc_info(ioc, "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n", | |
5162 | le16_to_cpu(mpi_reply.IOCStatus), | |
5163 | le32_to_cpu(mpi_reply.IOCLogInfo))); | |
d1cb5e49 | 5164 | goto out; |
f92363d1 | 5165 | } |
d1cb5e49 SR |
5166 | out: |
5167 | sas_device_put(sas_device); | |
f92363d1 | 5168 | } |
d1cb5e49 | 5169 | |
0f624c39 SR |
5170 | /** |
5171 | * _scsih_turn_off_pfa_led - turn off Fault LED | |
5172 | * @ioc: per adapter object | |
5173 | * @sas_device: sas device whose PFA LED has to turned off | |
5174 | * Context: process | |
0f624c39 SR |
5175 | */ |
5176 | static void | |
5177 | _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc, | |
5178 | struct _sas_device *sas_device) | |
5179 | { | |
5180 | Mpi2SepReply_t mpi_reply; | |
5181 | Mpi2SepRequest_t mpi_request; | |
f92363d1 | 5182 | |
0f624c39 SR |
5183 | memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t)); |
5184 | mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; | |
5185 | mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; | |
5186 | mpi_request.SlotStatus = 0; | |
5187 | mpi_request.Slot = cpu_to_le16(sas_device->slot); | |
5188 | mpi_request.DevHandle = 0; | |
5189 | mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle); | |
5190 | mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS; | |
5191 | if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply, | |
5192 | &mpi_request)) != 0) { | |
1f95a47e JP |
5193 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5194 | __FILE__, __LINE__, __func__); | |
0f624c39 SR |
5195 | return; |
5196 | } | |
5197 | ||
5198 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) { | |
1f95a47e JP |
5199 | dewtprintk(ioc, |
5200 | ioc_info(ioc, "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n", | |
5201 | le16_to_cpu(mpi_reply.IOCStatus), | |
5202 | le32_to_cpu(mpi_reply.IOCLogInfo))); | |
0f624c39 SR |
5203 | return; |
5204 | } | |
5205 | } | |
d1cb5e49 | 5206 | |
f92363d1 | 5207 | /** |
0f624c39 | 5208 | * _scsih_send_event_to_turn_on_pfa_led - fire delayed event |
f92363d1 SR |
5209 | * @ioc: per adapter object |
5210 | * @handle: device handle | |
5211 | * Context: interrupt. | |
f92363d1 SR |
5212 | */ |
5213 | static void | |
0f624c39 | 5214 | _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
f92363d1 SR |
5215 | { |
5216 | struct fw_event_work *fw_event; | |
5217 | ||
146b16c8 | 5218 | fw_event = alloc_fw_event_work(0); |
f92363d1 SR |
5219 | if (!fw_event) |
5220 | return; | |
0f624c39 | 5221 | fw_event->event = MPT3SAS_TURN_ON_PFA_LED; |
f92363d1 SR |
5222 | fw_event->device_handle = handle; |
5223 | fw_event->ioc = ioc; | |
5224 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 | 5225 | fw_event_work_put(fw_event); |
f92363d1 SR |
5226 | } |
5227 | ||
5228 | /** | |
5229 | * _scsih_smart_predicted_fault - process smart errors | |
5230 | * @ioc: per adapter object | |
5231 | * @handle: device handle | |
5232 | * Context: interrupt. | |
f92363d1 SR |
5233 | */ |
5234 | static void | |
5235 | _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
5236 | { | |
5237 | struct scsi_target *starget; | |
5238 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
5239 | Mpi2EventNotificationReply_t *event_reply; | |
5240 | Mpi2EventDataSasDeviceStatusChange_t *event_data; | |
5241 | struct _sas_device *sas_device; | |
5242 | ssize_t sz; | |
5243 | unsigned long flags; | |
5244 | ||
5245 | /* only handle non-raid devices */ | |
5246 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 SR |
5247 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
5248 | if (!sas_device) | |
5249 | goto out_unlock; | |
5250 | ||
f92363d1 SR |
5251 | starget = sas_device->starget; |
5252 | sas_target_priv_data = starget->hostdata; | |
5253 | ||
5254 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) || | |
d1cb5e49 SR |
5255 | ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) |
5256 | goto out_unlock; | |
5257 | ||
75888956 SR |
5258 | _scsih_display_enclosure_chassis_info(NULL, sas_device, NULL, starget); |
5259 | ||
f92363d1 SR |
5260 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
5261 | ||
5262 | if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) | |
0f624c39 | 5263 | _scsih_send_event_to_turn_on_pfa_led(ioc, handle); |
f92363d1 SR |
5264 | |
5265 | /* insert into event log */ | |
5266 | sz = offsetof(Mpi2EventNotificationReply_t, EventData) + | |
5267 | sizeof(Mpi2EventDataSasDeviceStatusChange_t); | |
ec491554 | 5268 | event_reply = kzalloc(sz, GFP_ATOMIC); |
f92363d1 | 5269 | if (!event_reply) { |
919d8a3f JP |
5270 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5271 | __FILE__, __LINE__, __func__); | |
d1cb5e49 | 5272 | goto out; |
f92363d1 SR |
5273 | } |
5274 | ||
5275 | event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION; | |
5276 | event_reply->Event = | |
5277 | cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE); | |
5278 | event_reply->MsgLength = sz/4; | |
5279 | event_reply->EventDataLength = | |
5280 | cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4); | |
5281 | event_data = (Mpi2EventDataSasDeviceStatusChange_t *) | |
5282 | event_reply->EventData; | |
5283 | event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA; | |
5284 | event_data->ASC = 0x5D; | |
5285 | event_data->DevHandle = cpu_to_le16(handle); | |
5286 | event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address); | |
5287 | mpt3sas_ctl_add_to_event_log(ioc, event_reply); | |
5288 | kfree(event_reply); | |
d1cb5e49 SR |
5289 | out: |
5290 | if (sas_device) | |
5291 | sas_device_put(sas_device); | |
5292 | return; | |
5293 | ||
5294 | out_unlock: | |
5295 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
5296 | goto out; | |
f92363d1 SR |
5297 | } |
5298 | ||
5299 | /** | |
5300 | * _scsih_io_done - scsi request callback | |
5301 | * @ioc: per adapter object | |
5302 | * @smid: system request message index | |
5303 | * @msix_index: MSIX table index supplied by the OS | |
5304 | * @reply: reply message frame(lower 32bit addr) | |
5305 | * | |
5306 | * Callback handler when using _scsih_qcmd. | |
5307 | * | |
4beb4867 BVA |
5308 | * Return: 1 meaning mf should be freed from _base_interrupt |
5309 | * 0 means the mf is freed from this function. | |
f92363d1 SR |
5310 | */ |
5311 | static u8 | |
5312 | _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | |
5313 | { | |
016d5c35 | 5314 | Mpi25SCSIIORequest_t *mpi_request; |
f92363d1 SR |
5315 | Mpi2SCSIIOReply_t *mpi_reply; |
5316 | struct scsi_cmnd *scmd; | |
dbec4c90 | 5317 | struct scsiio_tracker *st; |
f92363d1 SR |
5318 | u16 ioc_status; |
5319 | u32 xfer_cnt; | |
5320 | u8 scsi_state; | |
5321 | u8 scsi_status; | |
5322 | u32 log_info; | |
5323 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
5324 | u32 response_code = 0; | |
5325 | ||
5326 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
459325c4 | 5327 | |
dbec4c90 | 5328 | scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid); |
f92363d1 SR |
5329 | if (scmd == NULL) |
5330 | return 1; | |
5331 | ||
ffb58456 | 5332 | _scsih_set_satl_pending(scmd, false); |
18f6084a | 5333 | |
f92363d1 SR |
5334 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
5335 | ||
5336 | if (mpi_reply == NULL) { | |
5337 | scmd->result = DID_OK << 16; | |
5338 | goto out; | |
5339 | } | |
5340 | ||
5341 | sas_device_priv_data = scmd->device->hostdata; | |
5342 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target || | |
5343 | sas_device_priv_data->sas_target->deleted) { | |
5344 | scmd->result = DID_NO_CONNECT << 16; | |
5345 | goto out; | |
5346 | } | |
5347 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); | |
5348 | ||
7786ab6a SR |
5349 | /* |
5350 | * WARPDRIVE: If direct_io is set then it is directIO, | |
5351 | * the failed direct I/O should be redirected to volume | |
5352 | */ | |
dbec4c90 SPS |
5353 | st = scsi_cmd_priv(scmd); |
5354 | if (st->direct_io && | |
7786ab6a SR |
5355 | ((ioc_status & MPI2_IOCSTATUS_MASK) |
5356 | != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) { | |
dbec4c90 | 5357 | st->direct_io = 0; |
998c3001 | 5358 | st->scmd = scmd; |
7786ab6a SR |
5359 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); |
5360 | mpi_request->DevHandle = | |
5361 | cpu_to_le16(sas_device_priv_data->sas_target->handle); | |
81c16f83 | 5362 | ioc->put_smid_scsi_io(ioc, smid, |
7786ab6a SR |
5363 | sas_device_priv_data->sas_target->handle); |
5364 | return 0; | |
5365 | } | |
f92363d1 SR |
5366 | /* turning off TLR */ |
5367 | scsi_state = mpi_reply->SCSIState; | |
5368 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) | |
5369 | response_code = | |
5370 | le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF; | |
5371 | if (!sas_device_priv_data->tlr_snoop_check) { | |
5372 | sas_device_priv_data->tlr_snoop_check++; | |
cd5897ed | 5373 | if ((!ioc->is_warpdrive && |
7786ab6a | 5374 | !scsih_is_raid(&scmd->device->sdev_gendev) && |
cd5897ed SPS |
5375 | !scsih_is_nvme(&scmd->device->sdev_gendev)) |
5376 | && sas_is_tlr_enabled(scmd->device) && | |
c84b06a4 SR |
5377 | response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) { |
5378 | sas_disable_tlr(scmd->device); | |
5379 | sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n"); | |
5380 | } | |
f92363d1 SR |
5381 | } |
5382 | ||
5383 | xfer_cnt = le32_to_cpu(mpi_reply->TransferCount); | |
5384 | scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt); | |
5385 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) | |
5386 | log_info = le32_to_cpu(mpi_reply->IOCLogInfo); | |
5387 | else | |
5388 | log_info = 0; | |
5389 | ioc_status &= MPI2_IOCSTATUS_MASK; | |
5390 | scsi_status = mpi_reply->SCSIStatus; | |
5391 | ||
5392 | if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 && | |
5393 | (scsi_status == MPI2_SCSI_STATUS_BUSY || | |
5394 | scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT || | |
5395 | scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) { | |
5396 | ioc_status = MPI2_IOCSTATUS_SUCCESS; | |
5397 | } | |
5398 | ||
5399 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { | |
5400 | struct sense_info data; | |
5401 | const void *sense_data = mpt3sas_base_get_sense_buffer(ioc, | |
5402 | smid); | |
5403 | u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE, | |
5404 | le32_to_cpu(mpi_reply->SenseCount)); | |
5405 | memcpy(scmd->sense_buffer, sense_data, sz); | |
5406 | _scsih_normalize_sense(scmd->sense_buffer, &data); | |
5407 | /* failure prediction threshold exceeded */ | |
5408 | if (data.asc == 0x5D) | |
5409 | _scsih_smart_predicted_fault(ioc, | |
5410 | le16_to_cpu(mpi_reply->DevHandle)); | |
5411 | mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq); | |
f92363d1 | 5412 | |
0d667f72 | 5413 | if ((ioc->logging_level & MPT_DEBUG_REPLY) && |
e6d45e3e SR |
5414 | ((scmd->sense_buffer[2] == UNIT_ATTENTION) || |
5415 | (scmd->sense_buffer[2] == MEDIUM_ERROR) || | |
5416 | (scmd->sense_buffer[2] == HARDWARE_ERROR))) | |
5417 | _scsih_scsi_ioc_info(ioc, scmd, mpi_reply, smid); | |
e6d45e3e | 5418 | } |
f92363d1 SR |
5419 | switch (ioc_status) { |
5420 | case MPI2_IOCSTATUS_BUSY: | |
5421 | case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES: | |
5422 | scmd->result = SAM_STAT_BUSY; | |
5423 | break; | |
5424 | ||
5425 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: | |
5426 | scmd->result = DID_NO_CONNECT << 16; | |
5427 | break; | |
5428 | ||
5429 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: | |
5430 | if (sas_device_priv_data->block) { | |
5431 | scmd->result = DID_TRANSPORT_DISRUPTED << 16; | |
5432 | goto out; | |
5433 | } | |
5434 | if (log_info == 0x31110630) { | |
5435 | if (scmd->retries > 2) { | |
5436 | scmd->result = DID_NO_CONNECT << 16; | |
5437 | scsi_device_set_state(scmd->device, | |
5438 | SDEV_OFFLINE); | |
5439 | } else { | |
5440 | scmd->result = DID_SOFT_ERROR << 16; | |
5441 | scmd->device->expecting_cc_ua = 1; | |
5442 | } | |
5443 | break; | |
3898f08e SR |
5444 | } else if (log_info == VIRTUAL_IO_FAILED_RETRY) { |
5445 | scmd->result = DID_RESET << 16; | |
5446 | break; | |
2ce9a364 SR |
5447 | } else if ((scmd->device->channel == RAID_CHANNEL) && |
5448 | (scsi_state == (MPI2_SCSI_STATE_TERMINATED | | |
5449 | MPI2_SCSI_STATE_NO_SCSI_STATUS))) { | |
5450 | scmd->result = DID_RESET << 16; | |
5451 | break; | |
f92363d1 SR |
5452 | } |
5453 | scmd->result = DID_SOFT_ERROR << 16; | |
5454 | break; | |
5455 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: | |
5456 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: | |
5457 | scmd->result = DID_RESET << 16; | |
5458 | break; | |
5459 | ||
5460 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: | |
5461 | if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt)) | |
5462 | scmd->result = DID_SOFT_ERROR << 16; | |
5463 | else | |
5464 | scmd->result = (DID_OK << 16) | scsi_status; | |
5465 | break; | |
5466 | ||
5467 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: | |
5468 | scmd->result = (DID_OK << 16) | scsi_status; | |
5469 | ||
5470 | if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)) | |
5471 | break; | |
5472 | ||
5473 | if (xfer_cnt < scmd->underflow) { | |
5474 | if (scsi_status == SAM_STAT_BUSY) | |
5475 | scmd->result = SAM_STAT_BUSY; | |
5476 | else | |
5477 | scmd->result = DID_SOFT_ERROR << 16; | |
5478 | } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | | |
5479 | MPI2_SCSI_STATE_NO_SCSI_STATUS)) | |
5480 | scmd->result = DID_SOFT_ERROR << 16; | |
5481 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | |
5482 | scmd->result = DID_RESET << 16; | |
5483 | else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) { | |
5484 | mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID; | |
5485 | mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION; | |
5486 | scmd->result = (DRIVER_SENSE << 24) | | |
5487 | SAM_STAT_CHECK_CONDITION; | |
5488 | scmd->sense_buffer[0] = 0x70; | |
5489 | scmd->sense_buffer[2] = ILLEGAL_REQUEST; | |
5490 | scmd->sense_buffer[12] = 0x20; | |
5491 | scmd->sense_buffer[13] = 0; | |
5492 | } | |
5493 | break; | |
5494 | ||
5495 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: | |
5496 | scsi_set_resid(scmd, 0); | |
eb0c7af2 | 5497 | /* fall through */ |
f92363d1 SR |
5498 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: |
5499 | case MPI2_IOCSTATUS_SUCCESS: | |
5500 | scmd->result = (DID_OK << 16) | scsi_status; | |
5501 | if (response_code == | |
5502 | MPI2_SCSITASKMGMT_RSP_INVALID_FRAME || | |
5503 | (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | | |
5504 | MPI2_SCSI_STATE_NO_SCSI_STATUS))) | |
5505 | scmd->result = DID_SOFT_ERROR << 16; | |
5506 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | |
5507 | scmd->result = DID_RESET << 16; | |
5508 | break; | |
5509 | ||
5510 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | |
5511 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | |
5512 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | |
5513 | _scsih_eedp_error_handling(scmd, ioc_status); | |
5514 | break; | |
5515 | ||
5516 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: | |
5517 | case MPI2_IOCSTATUS_INVALID_FUNCTION: | |
5518 | case MPI2_IOCSTATUS_INVALID_SGL: | |
5519 | case MPI2_IOCSTATUS_INTERNAL_ERROR: | |
5520 | case MPI2_IOCSTATUS_INVALID_FIELD: | |
5521 | case MPI2_IOCSTATUS_INVALID_STATE: | |
5522 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: | |
5523 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: | |
b130b0d5 | 5524 | case MPI2_IOCSTATUS_INSUFFICIENT_POWER: |
f92363d1 SR |
5525 | default: |
5526 | scmd->result = DID_SOFT_ERROR << 16; | |
5527 | break; | |
5528 | ||
5529 | } | |
5530 | ||
f92363d1 SR |
5531 | if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY)) |
5532 | _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid); | |
f92363d1 SR |
5533 | |
5534 | out: | |
5535 | ||
5536 | scsi_dma_unmap(scmd); | |
dbec4c90 | 5537 | mpt3sas_base_free_smid(ioc, smid); |
f92363d1 | 5538 | scmd->scsi_done(scmd); |
dbec4c90 | 5539 | return 0; |
f92363d1 SR |
5540 | } |
5541 | ||
5542 | /** | |
5543 | * _scsih_sas_host_refresh - refreshing sas host object contents | |
5544 | * @ioc: per adapter object | |
5545 | * Context: user | |
5546 | * | |
5547 | * During port enable, fw will send topology events for every device. Its | |
5548 | * possible that the handles may change from the previous setting, so this | |
5549 | * code keeping handles updating if changed. | |
f92363d1 SR |
5550 | */ |
5551 | static void | |
5552 | _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc) | |
5553 | { | |
5554 | u16 sz; | |
5555 | u16 ioc_status; | |
5556 | int i; | |
5557 | Mpi2ConfigReply_t mpi_reply; | |
5558 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; | |
5559 | u16 attached_handle; | |
b326db46 SR |
5560 | u8 link_rate, port_id; |
5561 | struct hba_port *port; | |
f92363d1 | 5562 | |
919d8a3f JP |
5563 | dtmprintk(ioc, |
5564 | ioc_info(ioc, "updating handles for sas_host(0x%016llx)\n", | |
5565 | (u64)ioc->sas_hba.sas_address)); | |
f92363d1 SR |
5566 | |
5567 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys | |
5568 | * sizeof(Mpi2SasIOUnit0PhyData_t)); | |
5569 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); | |
5570 | if (!sas_iounit_pg0) { | |
919d8a3f JP |
5571 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5572 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5573 | return; |
5574 | } | |
5575 | ||
5576 | if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, | |
5577 | sas_iounit_pg0, sz)) != 0) | |
5578 | goto out; | |
5579 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
5580 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | |
5581 | goto out; | |
5582 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { | |
5583 | link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4; | |
5584 | if (i == 0) | |
b326db46 SR |
5585 | ioc->sas_hba.handle = le16_to_cpu( |
5586 | sas_iounit_pg0->PhyData[0].ControllerDevHandle); | |
5587 | port_id = sas_iounit_pg0->PhyData[i].Port; | |
5588 | if (!(mpt3sas_get_port_by_id(ioc, port_id))) { | |
5589 | port = kzalloc(sizeof(struct hba_port), GFP_KERNEL); | |
5590 | if (!port) | |
5591 | goto out; | |
5592 | ||
5593 | port->port_id = port_id; | |
5594 | ioc_info(ioc, | |
5595 | "hba_port entry: %p, port: %d is added to hba_port list\n", | |
5596 | port, port->port_id); | |
5597 | if (ioc->shost_recovery) | |
5598 | port->flags = HBA_PORT_FLAG_NEW_PORT; | |
5599 | list_add_tail(&port->list, &ioc->port_table_list); | |
5600 | } | |
f92363d1 SR |
5601 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; |
5602 | attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i]. | |
5603 | AttachedDevHandle); | |
5604 | if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) | |
5605 | link_rate = MPI2_SAS_NEG_LINK_RATE_1_5; | |
b326db46 | 5606 | ioc->sas_hba.phy[i].port = mpt3sas_get_port_by_id(ioc, port_id); |
f92363d1 SR |
5607 | mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address, |
5608 | attached_handle, i, link_rate); | |
5609 | } | |
5610 | out: | |
5611 | kfree(sas_iounit_pg0); | |
5612 | } | |
5613 | ||
5614 | /** | |
5615 | * _scsih_sas_host_add - create sas host object | |
5616 | * @ioc: per adapter object | |
5617 | * | |
5618 | * Creating host side data object, stored in ioc->sas_hba | |
f92363d1 SR |
5619 | */ |
5620 | static void | |
5621 | _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc) | |
5622 | { | |
5623 | int i; | |
5624 | Mpi2ConfigReply_t mpi_reply; | |
5625 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; | |
5626 | Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; | |
5627 | Mpi2SasPhyPage0_t phy_pg0; | |
5628 | Mpi2SasDevicePage0_t sas_device_pg0; | |
5629 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
5630 | u16 ioc_status; | |
5631 | u16 sz; | |
5632 | u8 device_missing_delay; | |
b326db46 SR |
5633 | u8 num_phys, port_id; |
5634 | struct hba_port *port; | |
f92363d1 | 5635 | |
87aa95d4 JL |
5636 | mpt3sas_config_get_number_hba_phys(ioc, &num_phys); |
5637 | if (!num_phys) { | |
919d8a3f JP |
5638 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5639 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5640 | return; |
5641 | } | |
87aa95d4 JL |
5642 | ioc->sas_hba.phy = kcalloc(num_phys, |
5643 | sizeof(struct _sas_phy), GFP_KERNEL); | |
5644 | if (!ioc->sas_hba.phy) { | |
919d8a3f JP |
5645 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5646 | __FILE__, __LINE__, __func__); | |
87aa95d4 JL |
5647 | goto out; |
5648 | } | |
5649 | ioc->sas_hba.num_phys = num_phys; | |
f92363d1 SR |
5650 | |
5651 | /* sas_iounit page 0 */ | |
5652 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys * | |
5653 | sizeof(Mpi2SasIOUnit0PhyData_t)); | |
5654 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); | |
5655 | if (!sas_iounit_pg0) { | |
919d8a3f JP |
5656 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5657 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5658 | return; |
5659 | } | |
5660 | if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, | |
5661 | sas_iounit_pg0, sz))) { | |
919d8a3f JP |
5662 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5663 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5664 | goto out; |
5665 | } | |
5666 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5667 | MPI2_IOCSTATUS_MASK; | |
5668 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
919d8a3f JP |
5669 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5670 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5671 | goto out; |
5672 | } | |
5673 | ||
5674 | /* sas_iounit page 1 */ | |
5675 | sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys * | |
5676 | sizeof(Mpi2SasIOUnit1PhyData_t)); | |
5677 | sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL); | |
5678 | if (!sas_iounit_pg1) { | |
919d8a3f JP |
5679 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5680 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5681 | goto out; |
5682 | } | |
5683 | if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply, | |
5684 | sas_iounit_pg1, sz))) { | |
919d8a3f JP |
5685 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5686 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5687 | goto out; |
5688 | } | |
5689 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5690 | MPI2_IOCSTATUS_MASK; | |
5691 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
919d8a3f JP |
5692 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5693 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5694 | goto out; |
5695 | } | |
5696 | ||
5697 | ioc->io_missing_delay = | |
5698 | sas_iounit_pg1->IODeviceMissingDelay; | |
5699 | device_missing_delay = | |
5700 | sas_iounit_pg1->ReportDeviceMissingDelay; | |
5701 | if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16) | |
5702 | ioc->device_missing_delay = (device_missing_delay & | |
5703 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16; | |
5704 | else | |
5705 | ioc->device_missing_delay = device_missing_delay & | |
5706 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK; | |
5707 | ||
5708 | ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev; | |
f92363d1 SR |
5709 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { |
5710 | if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0, | |
5711 | i))) { | |
919d8a3f JP |
5712 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5713 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5714 | goto out; |
5715 | } | |
5716 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5717 | MPI2_IOCSTATUS_MASK; | |
5718 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
919d8a3f JP |
5719 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5720 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5721 | goto out; |
5722 | } | |
5723 | ||
5724 | if (i == 0) | |
5725 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> | |
5726 | PhyData[0].ControllerDevHandle); | |
b326db46 SR |
5727 | |
5728 | port_id = sas_iounit_pg0->PhyData[i].Port; | |
5729 | if (!(mpt3sas_get_port_by_id(ioc, port_id))) { | |
5730 | port = kzalloc(sizeof(struct hba_port), GFP_KERNEL); | |
5731 | if (!port) | |
5732 | goto out; | |
5733 | ||
5734 | port->port_id = port_id; | |
5735 | ioc_info(ioc, | |
5736 | "hba_port entry: %p, port: %d is added to hba_port list\n", | |
5737 | port, port->port_id); | |
5738 | list_add_tail(&port->list, | |
5739 | &ioc->port_table_list); | |
5740 | } | |
5741 | ||
f92363d1 SR |
5742 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; |
5743 | ioc->sas_hba.phy[i].phy_id = i; | |
b326db46 | 5744 | ioc->sas_hba.phy[i].port = mpt3sas_get_port_by_id(ioc, port_id); |
f92363d1 SR |
5745 | mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i], |
5746 | phy_pg0, ioc->sas_hba.parent_dev); | |
5747 | } | |
5748 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
5749 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) { | |
919d8a3f JP |
5750 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5751 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5752 | goto out; |
5753 | } | |
5754 | ioc->sas_hba.enclosure_handle = | |
5755 | le16_to_cpu(sas_device_pg0.EnclosureHandle); | |
5756 | ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | |
919d8a3f JP |
5757 | ioc_info(ioc, "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n", |
5758 | ioc->sas_hba.handle, | |
5759 | (u64)ioc->sas_hba.sas_address, | |
5760 | ioc->sas_hba.num_phys); | |
f92363d1 SR |
5761 | |
5762 | if (ioc->sas_hba.enclosure_handle) { | |
5763 | if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
5764 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
5765 | ioc->sas_hba.enclosure_handle))) | |
5766 | ioc->sas_hba.enclosure_logical_id = | |
5767 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
5768 | } | |
5769 | ||
5770 | out: | |
5771 | kfree(sas_iounit_pg1); | |
5772 | kfree(sas_iounit_pg0); | |
5773 | } | |
5774 | ||
5775 | /** | |
5776 | * _scsih_expander_add - creating expander object | |
5777 | * @ioc: per adapter object | |
5778 | * @handle: expander handle | |
5779 | * | |
5780 | * Creating expander object, stored in ioc->sas_expander_list. | |
5781 | * | |
4beb4867 | 5782 | * Return: 0 for success, else error. |
f92363d1 SR |
5783 | */ |
5784 | static int | |
5785 | _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
5786 | { | |
5787 | struct _sas_node *sas_expander; | |
22a923c3 | 5788 | struct _enclosure_node *enclosure_dev; |
f92363d1 SR |
5789 | Mpi2ConfigReply_t mpi_reply; |
5790 | Mpi2ExpanderPage0_t expander_pg0; | |
5791 | Mpi2ExpanderPage1_t expander_pg1; | |
f92363d1 SR |
5792 | u32 ioc_status; |
5793 | u16 parent_handle; | |
5794 | u64 sas_address, sas_address_parent = 0; | |
5795 | int i; | |
5796 | unsigned long flags; | |
5797 | struct _sas_port *mpt3sas_port = NULL; | |
5798 | ||
5799 | int rc = 0; | |
5800 | ||
5801 | if (!handle) | |
5802 | return -1; | |
5803 | ||
5804 | if (ioc->shost_recovery || ioc->pci_error_recovery) | |
5805 | return -1; | |
5806 | ||
5807 | if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | |
5808 | MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) { | |
919d8a3f JP |
5809 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5810 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5811 | return -1; |
5812 | } | |
5813 | ||
5814 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5815 | MPI2_IOCSTATUS_MASK; | |
5816 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
919d8a3f JP |
5817 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5818 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5819 | return -1; |
5820 | } | |
5821 | ||
5822 | /* handle out of order topology events */ | |
5823 | parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle); | |
5824 | if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent) | |
5825 | != 0) { | |
919d8a3f JP |
5826 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5827 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5828 | return -1; |
5829 | } | |
5830 | if (sas_address_parent != ioc->sas_hba.sas_address) { | |
5831 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
5832 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, | |
5833 | sas_address_parent); | |
5834 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
5835 | if (!sas_expander) { | |
5836 | rc = _scsih_expander_add(ioc, parent_handle); | |
5837 | if (rc != 0) | |
5838 | return rc; | |
5839 | } | |
5840 | } | |
5841 | ||
5842 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
5843 | sas_address = le64_to_cpu(expander_pg0.SASAddress); | |
5844 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, | |
5845 | sas_address); | |
5846 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
5847 | ||
5848 | if (sas_expander) | |
5849 | return 0; | |
5850 | ||
5851 | sas_expander = kzalloc(sizeof(struct _sas_node), | |
5852 | GFP_KERNEL); | |
5853 | if (!sas_expander) { | |
919d8a3f JP |
5854 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5855 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5856 | return -1; |
5857 | } | |
5858 | ||
5859 | sas_expander->handle = handle; | |
5860 | sas_expander->num_phys = expander_pg0.NumPhys; | |
5861 | sas_expander->sas_address_parent = sas_address_parent; | |
5862 | sas_expander->sas_address = sas_address; | |
5863 | ||
919d8a3f JP |
5864 | ioc_info(ioc, "expander_add: handle(0x%04x), parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", |
5865 | handle, parent_handle, | |
5866 | (u64)sas_expander->sas_address, sas_expander->num_phys); | |
f92363d1 SR |
5867 | |
5868 | if (!sas_expander->num_phys) | |
5869 | goto out_fail; | |
5870 | sas_expander->phy = kcalloc(sas_expander->num_phys, | |
5871 | sizeof(struct _sas_phy), GFP_KERNEL); | |
5872 | if (!sas_expander->phy) { | |
919d8a3f JP |
5873 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5874 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5875 | rc = -1; |
5876 | goto out_fail; | |
5877 | } | |
5878 | ||
5879 | INIT_LIST_HEAD(&sas_expander->sas_port_list); | |
5880 | mpt3sas_port = mpt3sas_transport_port_add(ioc, handle, | |
5881 | sas_address_parent); | |
5882 | if (!mpt3sas_port) { | |
919d8a3f JP |
5883 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5884 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5885 | rc = -1; |
5886 | goto out_fail; | |
5887 | } | |
5888 | sas_expander->parent_dev = &mpt3sas_port->rphy->dev; | |
5889 | ||
5890 | for (i = 0 ; i < sas_expander->num_phys ; i++) { | |
5891 | if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply, | |
5892 | &expander_pg1, i, handle))) { | |
919d8a3f JP |
5893 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5894 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5895 | rc = -1; |
5896 | goto out_fail; | |
5897 | } | |
5898 | sas_expander->phy[i].handle = handle; | |
5899 | sas_expander->phy[i].phy_id = i; | |
5900 | ||
5901 | if ((mpt3sas_transport_add_expander_phy(ioc, | |
5902 | &sas_expander->phy[i], expander_pg1, | |
5903 | sas_expander->parent_dev))) { | |
919d8a3f JP |
5904 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5905 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5906 | rc = -1; |
5907 | goto out_fail; | |
5908 | } | |
5909 | } | |
5910 | ||
5911 | if (sas_expander->enclosure_handle) { | |
22a923c3 C |
5912 | enclosure_dev = |
5913 | mpt3sas_scsih_enclosure_find_by_handle(ioc, | |
5914 | sas_expander->enclosure_handle); | |
5915 | if (enclosure_dev) | |
f92363d1 | 5916 | sas_expander->enclosure_logical_id = |
22a923c3 | 5917 | le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID); |
f92363d1 SR |
5918 | } |
5919 | ||
5920 | _scsih_expander_node_add(ioc, sas_expander); | |
199fd79a | 5921 | return 0; |
f92363d1 SR |
5922 | |
5923 | out_fail: | |
5924 | ||
5925 | if (mpt3sas_port) | |
5926 | mpt3sas_transport_port_remove(ioc, sas_expander->sas_address, | |
5927 | sas_address_parent); | |
5928 | kfree(sas_expander); | |
5929 | return rc; | |
5930 | } | |
5931 | ||
5932 | /** | |
5933 | * mpt3sas_expander_remove - removing expander object | |
5934 | * @ioc: per adapter object | |
5935 | * @sas_address: expander sas_address | |
f92363d1 SR |
5936 | */ |
5937 | void | |
5938 | mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address) | |
5939 | { | |
5940 | struct _sas_node *sas_expander; | |
5941 | unsigned long flags; | |
5942 | ||
5943 | if (ioc->shost_recovery) | |
5944 | return; | |
5945 | ||
5946 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
5947 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, | |
5948 | sas_address); | |
f92363d1 SR |
5949 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
5950 | if (sas_expander) | |
5951 | _scsih_expander_node_remove(ioc, sas_expander); | |
5952 | } | |
5953 | ||
5954 | /** | |
5955 | * _scsih_done - internal SCSI_IO callback handler. | |
5956 | * @ioc: per adapter object | |
5957 | * @smid: system request message index | |
5958 | * @msix_index: MSIX table index supplied by the OS | |
5959 | * @reply: reply message frame(lower 32bit addr) | |
5960 | * | |
5961 | * Callback handler when sending internal generated SCSI_IO. | |
5962 | * The callback index passed is `ioc->scsih_cb_idx` | |
5963 | * | |
4beb4867 BVA |
5964 | * Return: 1 meaning mf should be freed from _base_interrupt |
5965 | * 0 means the mf is freed from this function. | |
f92363d1 SR |
5966 | */ |
5967 | static u8 | |
5968 | _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | |
5969 | { | |
5970 | MPI2DefaultReply_t *mpi_reply; | |
5971 | ||
5972 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
5973 | if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED) | |
5974 | return 1; | |
5975 | if (ioc->scsih_cmds.smid != smid) | |
5976 | return 1; | |
5977 | ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE; | |
5978 | if (mpi_reply) { | |
5979 | memcpy(ioc->scsih_cmds.reply, mpi_reply, | |
5980 | mpi_reply->MsgLength*4); | |
5981 | ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID; | |
5982 | } | |
5983 | ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING; | |
5984 | complete(&ioc->scsih_cmds.done); | |
5985 | return 1; | |
5986 | } | |
5987 | ||
5988 | ||
5989 | ||
5990 | ||
5991 | #define MPT3_MAX_LUNS (255) | |
5992 | ||
5993 | ||
5994 | /** | |
5995 | * _scsih_check_access_status - check access flags | |
5996 | * @ioc: per adapter object | |
5997 | * @sas_address: sas address | |
5998 | * @handle: sas device handle | |
4beb4867 | 5999 | * @access_status: errors returned during discovery of the device |
f92363d1 | 6000 | * |
4beb4867 | 6001 | * Return: 0 for success, else failure |
f92363d1 SR |
6002 | */ |
6003 | static u8 | |
6004 | _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address, | |
6005 | u16 handle, u8 access_status) | |
6006 | { | |
6007 | u8 rc = 1; | |
6008 | char *desc = NULL; | |
6009 | ||
6010 | switch (access_status) { | |
6011 | case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS: | |
6012 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION: | |
6013 | rc = 0; | |
6014 | break; | |
6015 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED: | |
6016 | desc = "sata capability failed"; | |
6017 | break; | |
6018 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT: | |
6019 | desc = "sata affiliation conflict"; | |
6020 | break; | |
6021 | case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE: | |
6022 | desc = "route not addressable"; | |
6023 | break; | |
6024 | case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE: | |
6025 | desc = "smp error not addressable"; | |
6026 | break; | |
6027 | case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED: | |
6028 | desc = "device blocked"; | |
6029 | break; | |
6030 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED: | |
6031 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN: | |
6032 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT: | |
6033 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG: | |
6034 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION: | |
6035 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER: | |
6036 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN: | |
6037 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN: | |
6038 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN: | |
6039 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION: | |
6040 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE: | |
6041 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX: | |
6042 | desc = "sata initialization failed"; | |
6043 | break; | |
6044 | default: | |
6045 | desc = "unknown"; | |
6046 | break; | |
6047 | } | |
6048 | ||
6049 | if (!rc) | |
6050 | return 0; | |
6051 | ||
919d8a3f JP |
6052 | ioc_err(ioc, "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n", |
6053 | desc, (u64)sas_address, handle); | |
f92363d1 SR |
6054 | return rc; |
6055 | } | |
6056 | ||
6057 | /** | |
6058 | * _scsih_check_device - checking device responsiveness | |
6059 | * @ioc: per adapter object | |
6060 | * @parent_sas_address: sas address of parent expander or sas host | |
6061 | * @handle: attached device handle | |
4beb4867 | 6062 | * @phy_number: phy number |
f92363d1 | 6063 | * @link_rate: new link rate |
f92363d1 SR |
6064 | */ |
6065 | static void | |
6066 | _scsih_check_device(struct MPT3SAS_ADAPTER *ioc, | |
6067 | u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate) | |
6068 | { | |
6069 | Mpi2ConfigReply_t mpi_reply; | |
6070 | Mpi2SasDevicePage0_t sas_device_pg0; | |
6071 | struct _sas_device *sas_device; | |
22a923c3 | 6072 | struct _enclosure_node *enclosure_dev = NULL; |
f92363d1 SR |
6073 | u32 ioc_status; |
6074 | unsigned long flags; | |
6075 | u64 sas_address; | |
6076 | struct scsi_target *starget; | |
6077 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
6078 | u32 device_info; | |
6079 | ||
f92363d1 SR |
6080 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
6081 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) | |
6082 | return; | |
6083 | ||
6084 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
6085 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | |
6086 | return; | |
6087 | ||
6088 | /* wide port handling ~ we need only handle device once for the phy that | |
6089 | * is matched in sas device page zero | |
6090 | */ | |
6091 | if (phy_number != sas_device_pg0.PhyNum) | |
6092 | return; | |
6093 | ||
6094 | /* check if this is end device */ | |
6095 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | |
6096 | if (!(_scsih_is_end_device(device_info))) | |
6097 | return; | |
6098 | ||
6099 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
6100 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | |
d1cb5e49 | 6101 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 SR |
6102 | sas_address); |
6103 | ||
d1cb5e49 SR |
6104 | if (!sas_device) |
6105 | goto out_unlock; | |
f92363d1 SR |
6106 | |
6107 | if (unlikely(sas_device->handle != handle)) { | |
6108 | starget = sas_device->starget; | |
6109 | sas_target_priv_data = starget->hostdata; | |
6110 | starget_printk(KERN_INFO, starget, | |
6111 | "handle changed from(0x%04x) to (0x%04x)!!!\n", | |
6112 | sas_device->handle, handle); | |
6113 | sas_target_priv_data->handle = handle; | |
6114 | sas_device->handle = handle; | |
aa53bb89 | 6115 | if (le16_to_cpu(sas_device_pg0.Flags) & |
e6d45e3e SR |
6116 | MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) { |
6117 | sas_device->enclosure_level = | |
aa53bb89 | 6118 | sas_device_pg0.EnclosureLevel; |
310c8e40 CO |
6119 | memcpy(sas_device->connector_name, |
6120 | sas_device_pg0.ConnectorName, 4); | |
6121 | sas_device->connector_name[4] = '\0'; | |
e6d45e3e SR |
6122 | } else { |
6123 | sas_device->enclosure_level = 0; | |
6124 | sas_device->connector_name[0] = '\0'; | |
6125 | } | |
aba5a85c | 6126 | |
22a923c3 C |
6127 | sas_device->enclosure_handle = |
6128 | le16_to_cpu(sas_device_pg0.EnclosureHandle); | |
6129 | sas_device->is_chassis_slot_valid = 0; | |
6130 | enclosure_dev = mpt3sas_scsih_enclosure_find_by_handle(ioc, | |
6131 | sas_device->enclosure_handle); | |
6132 | if (enclosure_dev) { | |
6133 | sas_device->enclosure_logical_id = | |
6134 | le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID); | |
6135 | if (le16_to_cpu(enclosure_dev->pg0.Flags) & | |
6136 | MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) { | |
6137 | sas_device->is_chassis_slot_valid = 1; | |
6138 | sas_device->chassis_slot = | |
6139 | enclosure_dev->pg0.ChassisSlot; | |
6140 | } | |
6141 | } | |
f92363d1 SR |
6142 | } |
6143 | ||
6144 | /* check if device is present */ | |
6145 | if (!(le16_to_cpu(sas_device_pg0.Flags) & | |
6146 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { | |
919d8a3f JP |
6147 | ioc_err(ioc, "device is not present handle(0x%04x), flags!!!\n", |
6148 | handle); | |
d1cb5e49 | 6149 | goto out_unlock; |
f92363d1 SR |
6150 | } |
6151 | ||
6152 | /* check if there were any issues with discovery */ | |
6153 | if (_scsih_check_access_status(ioc, sas_address, handle, | |
d1cb5e49 SR |
6154 | sas_device_pg0.AccessStatus)) |
6155 | goto out_unlock; | |
f92363d1 SR |
6156 | |
6157 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
6158 | _scsih_ublock_io_device(ioc, sas_address); | |
6159 | ||
d1cb5e49 SR |
6160 | if (sas_device) |
6161 | sas_device_put(sas_device); | |
6162 | return; | |
6163 | ||
6164 | out_unlock: | |
6165 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
6166 | if (sas_device) | |
6167 | sas_device_put(sas_device); | |
f92363d1 SR |
6168 | } |
6169 | ||
6170 | /** | |
6171 | * _scsih_add_device - creating sas device object | |
6172 | * @ioc: per adapter object | |
6173 | * @handle: sas device handle | |
6174 | * @phy_num: phy number end device attached to | |
6175 | * @is_pd: is this hidden raid component | |
6176 | * | |
6177 | * Creating end device object, stored in ioc->sas_device_list. | |
6178 | * | |
4beb4867 | 6179 | * Return: 0 for success, non-zero for failure. |
f92363d1 SR |
6180 | */ |
6181 | static int | |
6182 | _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num, | |
6183 | u8 is_pd) | |
6184 | { | |
6185 | Mpi2ConfigReply_t mpi_reply; | |
6186 | Mpi2SasDevicePage0_t sas_device_pg0; | |
f92363d1 | 6187 | struct _sas_device *sas_device; |
22a923c3 | 6188 | struct _enclosure_node *enclosure_dev = NULL; |
f92363d1 SR |
6189 | u32 ioc_status; |
6190 | u64 sas_address; | |
6191 | u32 device_info; | |
f92363d1 SR |
6192 | |
6193 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
6194 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
919d8a3f JP |
6195 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
6196 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
6197 | return -1; |
6198 | } | |
6199 | ||
6200 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6201 | MPI2_IOCSTATUS_MASK; | |
6202 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
919d8a3f JP |
6203 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
6204 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
6205 | return -1; |
6206 | } | |
6207 | ||
6208 | /* check if this is end device */ | |
6209 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | |
6210 | if (!(_scsih_is_end_device(device_info))) | |
6211 | return -1; | |
c696f7b8 | 6212 | set_bit(handle, ioc->pend_os_device_add); |
f92363d1 SR |
6213 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
6214 | ||
6215 | /* check if device is present */ | |
6216 | if (!(le16_to_cpu(sas_device_pg0.Flags) & | |
6217 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { | |
919d8a3f JP |
6218 | ioc_err(ioc, "device is not present handle(0x04%x)!!!\n", |
6219 | handle); | |
f92363d1 SR |
6220 | return -1; |
6221 | } | |
6222 | ||
6223 | /* check if there were any issues with discovery */ | |
6224 | if (_scsih_check_access_status(ioc, sas_address, handle, | |
6225 | sas_device_pg0.AccessStatus)) | |
6226 | return -1; | |
6227 | ||
d1cb5e49 SR |
6228 | sas_device = mpt3sas_get_sdev_by_addr(ioc, |
6229 | sas_address); | |
6230 | if (sas_device) { | |
c696f7b8 | 6231 | clear_bit(handle, ioc->pend_os_device_add); |
d1cb5e49 | 6232 | sas_device_put(sas_device); |
f92363d1 | 6233 | return -1; |
d1cb5e49 | 6234 | } |
f92363d1 | 6235 | |
75888956 | 6236 | if (sas_device_pg0.EnclosureHandle) { |
22a923c3 C |
6237 | enclosure_dev = |
6238 | mpt3sas_scsih_enclosure_find_by_handle(ioc, | |
6239 | le16_to_cpu(sas_device_pg0.EnclosureHandle)); | |
6240 | if (enclosure_dev == NULL) | |
919d8a3f JP |
6241 | ioc_info(ioc, "Enclosure handle(0x%04x) doesn't match with enclosure device!\n", |
6242 | sas_device_pg0.EnclosureHandle); | |
75888956 SR |
6243 | } |
6244 | ||
f92363d1 SR |
6245 | sas_device = kzalloc(sizeof(struct _sas_device), |
6246 | GFP_KERNEL); | |
6247 | if (!sas_device) { | |
919d8a3f JP |
6248 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
6249 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
6250 | return 0; |
6251 | } | |
6252 | ||
d1cb5e49 | 6253 | kref_init(&sas_device->refcount); |
f92363d1 SR |
6254 | sas_device->handle = handle; |
6255 | if (_scsih_get_sas_address(ioc, | |
6256 | le16_to_cpu(sas_device_pg0.ParentDevHandle), | |
6257 | &sas_device->sas_address_parent) != 0) | |
919d8a3f JP |
6258 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
6259 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
6260 | sas_device->enclosure_handle = |
6261 | le16_to_cpu(sas_device_pg0.EnclosureHandle); | |
e6d45e3e SR |
6262 | if (sas_device->enclosure_handle != 0) |
6263 | sas_device->slot = | |
6264 | le16_to_cpu(sas_device_pg0.Slot); | |
f92363d1 SR |
6265 | sas_device->device_info = device_info; |
6266 | sas_device->sas_address = sas_address; | |
6267 | sas_device->phy = sas_device_pg0.PhyNum; | |
6268 | sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) & | |
6269 | MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0; | |
6270 | ||
aa53bb89 SPS |
6271 | if (le16_to_cpu(sas_device_pg0.Flags) |
6272 | & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) { | |
e6d45e3e | 6273 | sas_device->enclosure_level = |
aa53bb89 | 6274 | sas_device_pg0.EnclosureLevel; |
310c8e40 CO |
6275 | memcpy(sas_device->connector_name, |
6276 | sas_device_pg0.ConnectorName, 4); | |
6277 | sas_device->connector_name[4] = '\0'; | |
e6d45e3e SR |
6278 | } else { |
6279 | sas_device->enclosure_level = 0; | |
6280 | sas_device->connector_name[0] = '\0'; | |
6281 | } | |
22a923c3 | 6282 | /* get enclosure_logical_id & chassis_slot*/ |
75888956 | 6283 | sas_device->is_chassis_slot_valid = 0; |
22a923c3 | 6284 | if (enclosure_dev) { |
f92363d1 | 6285 | sas_device->enclosure_logical_id = |
22a923c3 C |
6286 | le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID); |
6287 | if (le16_to_cpu(enclosure_dev->pg0.Flags) & | |
75888956 SR |
6288 | MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) { |
6289 | sas_device->is_chassis_slot_valid = 1; | |
6290 | sas_device->chassis_slot = | |
22a923c3 | 6291 | enclosure_dev->pg0.ChassisSlot; |
75888956 SR |
6292 | } |
6293 | } | |
6294 | ||
f92363d1 SR |
6295 | /* get device name */ |
6296 | sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName); | |
6297 | ||
6298 | if (ioc->wait_for_discovery_to_complete) | |
6299 | _scsih_sas_device_init_add(ioc, sas_device); | |
6300 | else | |
6301 | _scsih_sas_device_add(ioc, sas_device); | |
6302 | ||
d1cb5e49 | 6303 | sas_device_put(sas_device); |
f92363d1 SR |
6304 | return 0; |
6305 | } | |
6306 | ||
6307 | /** | |
6308 | * _scsih_remove_device - removing sas device object | |
6309 | * @ioc: per adapter object | |
4beb4867 | 6310 | * @sas_device: the sas_device object |
f92363d1 SR |
6311 | */ |
6312 | static void | |
6313 | _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc, | |
6314 | struct _sas_device *sas_device) | |
6315 | { | |
6316 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
6317 | ||
0f624c39 SR |
6318 | if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) && |
6319 | (sas_device->pfa_led_on)) { | |
6320 | _scsih_turn_off_pfa_led(ioc, sas_device); | |
6321 | sas_device->pfa_led_on = 0; | |
6322 | } | |
75888956 | 6323 | |
919d8a3f JP |
6324 | dewtprintk(ioc, |
6325 | ioc_info(ioc, "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n", | |
6326 | __func__, | |
6327 | sas_device->handle, (u64)sas_device->sas_address)); | |
75888956 SR |
6328 | |
6329 | dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device, | |
6330 | NULL, NULL)); | |
f92363d1 SR |
6331 | |
6332 | if (sas_device->starget && sas_device->starget->hostdata) { | |
6333 | sas_target_priv_data = sas_device->starget->hostdata; | |
6334 | sas_target_priv_data->deleted = 1; | |
6335 | _scsih_ublock_io_device(ioc, sas_device->sas_address); | |
6336 | sas_target_priv_data->handle = | |
6337 | MPT3SAS_INVALID_DEVICE_HANDLE; | |
6338 | } | |
7786ab6a SR |
6339 | |
6340 | if (!ioc->hide_drives) | |
6341 | mpt3sas_transport_port_remove(ioc, | |
f92363d1 SR |
6342 | sas_device->sas_address, |
6343 | sas_device->sas_address_parent); | |
6344 | ||
919d8a3f JP |
6345 | ioc_info(ioc, "removing handle(0x%04x), sas_addr(0x%016llx)\n", |
6346 | sas_device->handle, (u64)sas_device->sas_address); | |
75888956 SR |
6347 | |
6348 | _scsih_display_enclosure_chassis_info(ioc, sas_device, NULL, NULL); | |
f92363d1 | 6349 | |
919d8a3f JP |
6350 | dewtprintk(ioc, |
6351 | ioc_info(ioc, "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n", | |
6352 | __func__, | |
6353 | sas_device->handle, (u64)sas_device->sas_address)); | |
75888956 SR |
6354 | dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device, |
6355 | NULL, NULL)); | |
f92363d1 SR |
6356 | } |
6357 | ||
f92363d1 SR |
6358 | /** |
6359 | * _scsih_sas_topology_change_event_debug - debug for topology event | |
6360 | * @ioc: per adapter object | |
6361 | * @event_data: event data payload | |
6362 | * Context: user. | |
6363 | */ | |
6364 | static void | |
6365 | _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
6366 | Mpi2EventDataSasTopologyChangeList_t *event_data) | |
6367 | { | |
6368 | int i; | |
6369 | u16 handle; | |
6370 | u16 reason_code; | |
6371 | u8 phy_number; | |
6372 | char *status_str = NULL; | |
6373 | u8 link_rate, prev_link_rate; | |
6374 | ||
6375 | switch (event_data->ExpStatus) { | |
6376 | case MPI2_EVENT_SAS_TOPO_ES_ADDED: | |
6377 | status_str = "add"; | |
6378 | break; | |
6379 | case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING: | |
6380 | status_str = "remove"; | |
6381 | break; | |
6382 | case MPI2_EVENT_SAS_TOPO_ES_RESPONDING: | |
6383 | case 0: | |
6384 | status_str = "responding"; | |
6385 | break; | |
6386 | case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING: | |
6387 | status_str = "remove delay"; | |
6388 | break; | |
6389 | default: | |
6390 | status_str = "unknown status"; | |
6391 | break; | |
6392 | } | |
919d8a3f | 6393 | ioc_info(ioc, "sas topology change: (%s)\n", status_str); |
f92363d1 SR |
6394 | pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \ |
6395 | "start_phy(%02d), count(%d)\n", | |
6396 | le16_to_cpu(event_data->ExpanderDevHandle), | |
6397 | le16_to_cpu(event_data->EnclosureHandle), | |
6398 | event_data->StartPhyNum, event_data->NumEntries); | |
6399 | for (i = 0; i < event_data->NumEntries; i++) { | |
6400 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
6401 | if (!handle) | |
6402 | continue; | |
6403 | phy_number = event_data->StartPhyNum + i; | |
6404 | reason_code = event_data->PHY[i].PhyStatus & | |
6405 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
6406 | switch (reason_code) { | |
6407 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: | |
6408 | status_str = "target add"; | |
6409 | break; | |
6410 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: | |
6411 | status_str = "target remove"; | |
6412 | break; | |
6413 | case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING: | |
6414 | status_str = "delay target remove"; | |
6415 | break; | |
6416 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: | |
6417 | status_str = "link rate change"; | |
6418 | break; | |
6419 | case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE: | |
6420 | status_str = "target responding"; | |
6421 | break; | |
6422 | default: | |
6423 | status_str = "unknown"; | |
6424 | break; | |
6425 | } | |
6426 | link_rate = event_data->PHY[i].LinkRate >> 4; | |
6427 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; | |
6428 | pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \ | |
6429 | " link rate: new(0x%02x), old(0x%02x)\n", phy_number, | |
6430 | handle, status_str, link_rate, prev_link_rate); | |
6431 | ||
6432 | } | |
6433 | } | |
f92363d1 SR |
6434 | |
6435 | /** | |
6436 | * _scsih_sas_topology_change_event - handle topology changes | |
6437 | * @ioc: per adapter object | |
6438 | * @fw_event: The fw_event_work object | |
6439 | * Context: user. | |
6440 | * | |
6441 | */ | |
6442 | static int | |
6443 | _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc, | |
6444 | struct fw_event_work *fw_event) | |
6445 | { | |
6446 | int i; | |
6447 | u16 parent_handle, handle; | |
6448 | u16 reason_code; | |
6449 | u8 phy_number, max_phys; | |
6450 | struct _sas_node *sas_expander; | |
6451 | u64 sas_address; | |
6452 | unsigned long flags; | |
6453 | u8 link_rate, prev_link_rate; | |
35b62362 JL |
6454 | Mpi2EventDataSasTopologyChangeList_t *event_data = |
6455 | (Mpi2EventDataSasTopologyChangeList_t *) | |
6456 | fw_event->event_data; | |
f92363d1 | 6457 | |
f92363d1 SR |
6458 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
6459 | _scsih_sas_topology_change_event_debug(ioc, event_data); | |
f92363d1 SR |
6460 | |
6461 | if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery) | |
6462 | return 0; | |
6463 | ||
6464 | if (!ioc->sas_hba.num_phys) | |
6465 | _scsih_sas_host_add(ioc); | |
6466 | else | |
6467 | _scsih_sas_host_refresh(ioc); | |
6468 | ||
6469 | if (fw_event->ignore) { | |
919d8a3f | 6470 | dewtprintk(ioc, ioc_info(ioc, "ignoring expander event\n")); |
f92363d1 SR |
6471 | return 0; |
6472 | } | |
6473 | ||
6474 | parent_handle = le16_to_cpu(event_data->ExpanderDevHandle); | |
6475 | ||
6476 | /* handle expander add */ | |
6477 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED) | |
6478 | if (_scsih_expander_add(ioc, parent_handle) != 0) | |
6479 | return 0; | |
6480 | ||
6481 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
6482 | sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc, | |
6483 | parent_handle); | |
6484 | if (sas_expander) { | |
6485 | sas_address = sas_expander->sas_address; | |
6486 | max_phys = sas_expander->num_phys; | |
6487 | } else if (parent_handle < ioc->sas_hba.num_phys) { | |
6488 | sas_address = ioc->sas_hba.sas_address; | |
6489 | max_phys = ioc->sas_hba.num_phys; | |
6490 | } else { | |
6491 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
6492 | return 0; | |
6493 | } | |
6494 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
6495 | ||
6496 | /* handle siblings events */ | |
6497 | for (i = 0; i < event_data->NumEntries; i++) { | |
6498 | if (fw_event->ignore) { | |
919d8a3f JP |
6499 | dewtprintk(ioc, |
6500 | ioc_info(ioc, "ignoring expander event\n")); | |
f92363d1 SR |
6501 | return 0; |
6502 | } | |
6503 | if (ioc->remove_host || ioc->pci_error_recovery) | |
6504 | return 0; | |
6505 | phy_number = event_data->StartPhyNum + i; | |
6506 | if (phy_number >= max_phys) | |
6507 | continue; | |
6508 | reason_code = event_data->PHY[i].PhyStatus & | |
6509 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
6510 | if ((event_data->PHY[i].PhyStatus & | |
6511 | MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code != | |
6512 | MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)) | |
6513 | continue; | |
6514 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
6515 | if (!handle) | |
6516 | continue; | |
6517 | link_rate = event_data->PHY[i].LinkRate >> 4; | |
6518 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; | |
6519 | switch (reason_code) { | |
6520 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: | |
6521 | ||
6522 | if (ioc->shost_recovery) | |
6523 | break; | |
6524 | ||
6525 | if (link_rate == prev_link_rate) | |
6526 | break; | |
6527 | ||
6528 | mpt3sas_transport_update_links(ioc, sas_address, | |
6529 | handle, phy_number, link_rate); | |
6530 | ||
6531 | if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) | |
6532 | break; | |
6533 | ||
6534 | _scsih_check_device(ioc, sas_address, handle, | |
6535 | phy_number, link_rate); | |
6536 | ||
c696f7b8 SPS |
6537 | if (!test_bit(handle, ioc->pend_os_device_add)) |
6538 | break; | |
6539 | ||
eb0c7af2 | 6540 | /* fall through */ |
f92363d1 SR |
6541 | |
6542 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: | |
6543 | ||
6544 | if (ioc->shost_recovery) | |
6545 | break; | |
6546 | ||
6547 | mpt3sas_transport_update_links(ioc, sas_address, | |
6548 | handle, phy_number, link_rate); | |
6549 | ||
6550 | _scsih_add_device(ioc, handle, phy_number, 0); | |
6551 | ||
6552 | break; | |
6553 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: | |
6554 | ||
6555 | _scsih_device_remove_by_handle(ioc, handle); | |
6556 | break; | |
6557 | } | |
6558 | } | |
6559 | ||
6560 | /* handle expander removal */ | |
6561 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING && | |
6562 | sas_expander) | |
6563 | mpt3sas_expander_remove(ioc, sas_address); | |
6564 | ||
6565 | return 0; | |
6566 | } | |
6567 | ||
f92363d1 SR |
6568 | /** |
6569 | * _scsih_sas_device_status_change_event_debug - debug for device event | |
4beb4867 | 6570 | * @ioc: ? |
f92363d1 SR |
6571 | * @event_data: event data payload |
6572 | * Context: user. | |
f92363d1 SR |
6573 | */ |
6574 | static void | |
6575 | _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
6576 | Mpi2EventDataSasDeviceStatusChange_t *event_data) | |
6577 | { | |
6578 | char *reason_str = NULL; | |
6579 | ||
6580 | switch (event_data->ReasonCode) { | |
6581 | case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA: | |
6582 | reason_str = "smart data"; | |
6583 | break; | |
6584 | case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED: | |
6585 | reason_str = "unsupported device discovered"; | |
6586 | break; | |
6587 | case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET: | |
6588 | reason_str = "internal device reset"; | |
6589 | break; | |
6590 | case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL: | |
6591 | reason_str = "internal task abort"; | |
6592 | break; | |
6593 | case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL: | |
6594 | reason_str = "internal task abort set"; | |
6595 | break; | |
6596 | case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL: | |
6597 | reason_str = "internal clear task set"; | |
6598 | break; | |
6599 | case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL: | |
6600 | reason_str = "internal query task"; | |
6601 | break; | |
6602 | case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE: | |
6603 | reason_str = "sata init failure"; | |
6604 | break; | |
6605 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET: | |
6606 | reason_str = "internal device reset complete"; | |
6607 | break; | |
6608 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL: | |
6609 | reason_str = "internal task abort complete"; | |
6610 | break; | |
6611 | case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION: | |
6612 | reason_str = "internal async notification"; | |
6613 | break; | |
6614 | case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY: | |
6615 | reason_str = "expander reduced functionality"; | |
6616 | break; | |
6617 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY: | |
6618 | reason_str = "expander reduced functionality complete"; | |
6619 | break; | |
6620 | default: | |
6621 | reason_str = "unknown reason"; | |
6622 | break; | |
6623 | } | |
919d8a3f JP |
6624 | ioc_info(ioc, "device status change: (%s)\thandle(0x%04x), sas address(0x%016llx), tag(%d)", |
6625 | reason_str, le16_to_cpu(event_data->DevHandle), | |
6626 | (u64)le64_to_cpu(event_data->SASAddress), | |
6627 | le16_to_cpu(event_data->TaskTag)); | |
f92363d1 | 6628 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA) |
919d8a3f JP |
6629 | pr_cont(", ASC(0x%x), ASCQ(0x%x)\n", |
6630 | event_data->ASC, event_data->ASCQ); | |
6631 | pr_cont("\n"); | |
f92363d1 | 6632 | } |
f92363d1 SR |
6633 | |
6634 | /** | |
6635 | * _scsih_sas_device_status_change_event - handle device status change | |
6636 | * @ioc: per adapter object | |
54d74e6b | 6637 | * @event_data: The fw event |
f92363d1 | 6638 | * Context: user. |
f92363d1 SR |
6639 | */ |
6640 | static void | |
6641 | _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc, | |
54d74e6b | 6642 | Mpi2EventDataSasDeviceStatusChange_t *event_data) |
f92363d1 SR |
6643 | { |
6644 | struct MPT3SAS_TARGET *target_priv_data; | |
6645 | struct _sas_device *sas_device; | |
6646 | u64 sas_address; | |
6647 | unsigned long flags; | |
f92363d1 SR |
6648 | |
6649 | /* In MPI Revision K (0xC), the internal device reset complete was | |
6650 | * implemented, so avoid setting tm_busy flag for older firmware. | |
6651 | */ | |
6652 | if ((ioc->facts.HeaderVersion >> 8) < 0xC) | |
6653 | return; | |
6654 | ||
6655 | if (event_data->ReasonCode != | |
6656 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET && | |
6657 | event_data->ReasonCode != | |
6658 | MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET) | |
6659 | return; | |
6660 | ||
6661 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
6662 | sas_address = le64_to_cpu(event_data->SASAddress); | |
d1cb5e49 | 6663 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 SR |
6664 | sas_address); |
6665 | ||
d1cb5e49 SR |
6666 | if (!sas_device || !sas_device->starget) |
6667 | goto out; | |
f92363d1 SR |
6668 | |
6669 | target_priv_data = sas_device->starget->hostdata; | |
d1cb5e49 SR |
6670 | if (!target_priv_data) |
6671 | goto out; | |
f92363d1 SR |
6672 | |
6673 | if (event_data->ReasonCode == | |
6674 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET) | |
6675 | target_priv_data->tm_busy = 1; | |
6676 | else | |
6677 | target_priv_data->tm_busy = 0; | |
d1cb5e49 | 6678 | |
54d74e6b SP |
6679 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
6680 | ioc_info(ioc, | |
6681 | "%s tm_busy flag for handle(0x%04x)\n", | |
6682 | (target_priv_data->tm_busy == 1) ? "Enable" : "Disable", | |
6683 | target_priv_data->handle); | |
6684 | ||
d1cb5e49 SR |
6685 | out: |
6686 | if (sas_device) | |
6687 | sas_device_put(sas_device); | |
6688 | ||
f92363d1 SR |
6689 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
6690 | } | |
6691 | ||
4318c734 | 6692 | |
c102e00c SPS |
6693 | /** |
6694 | * _scsih_check_pcie_access_status - check access flags | |
6695 | * @ioc: per adapter object | |
6696 | * @wwid: wwid | |
6697 | * @handle: sas device handle | |
4beb4867 | 6698 | * @access_status: errors returned during discovery of the device |
c102e00c | 6699 | * |
4beb4867 | 6700 | * Return: 0 for success, else failure |
c102e00c SPS |
6701 | */ |
6702 | static u8 | |
6703 | _scsih_check_pcie_access_status(struct MPT3SAS_ADAPTER *ioc, u64 wwid, | |
6704 | u16 handle, u8 access_status) | |
6705 | { | |
6706 | u8 rc = 1; | |
6707 | char *desc = NULL; | |
6708 | ||
6709 | switch (access_status) { | |
6710 | case MPI26_PCIEDEV0_ASTATUS_NO_ERRORS: | |
6711 | case MPI26_PCIEDEV0_ASTATUS_NEEDS_INITIALIZATION: | |
6712 | rc = 0; | |
6713 | break; | |
6714 | case MPI26_PCIEDEV0_ASTATUS_CAPABILITY_FAILED: | |
6715 | desc = "PCIe device capability failed"; | |
6716 | break; | |
6717 | case MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED: | |
6718 | desc = "PCIe device blocked"; | |
3c090ce3 SP |
6719 | ioc_info(ioc, |
6720 | "Device with Access Status (%s): wwid(0x%016llx), " | |
6721 | "handle(0x%04x)\n ll only be added to the internal list", | |
6722 | desc, (u64)wwid, handle); | |
6723 | rc = 0; | |
c102e00c SPS |
6724 | break; |
6725 | case MPI26_PCIEDEV0_ASTATUS_MEMORY_SPACE_ACCESS_FAILED: | |
6726 | desc = "PCIe device mem space access failed"; | |
6727 | break; | |
6728 | case MPI26_PCIEDEV0_ASTATUS_UNSUPPORTED_DEVICE: | |
6729 | desc = "PCIe device unsupported"; | |
6730 | break; | |
6731 | case MPI26_PCIEDEV0_ASTATUS_MSIX_REQUIRED: | |
6732 | desc = "PCIe device MSIx Required"; | |
6733 | break; | |
6734 | case MPI26_PCIEDEV0_ASTATUS_INIT_FAIL_MAX: | |
6735 | desc = "PCIe device init fail max"; | |
6736 | break; | |
6737 | case MPI26_PCIEDEV0_ASTATUS_UNKNOWN: | |
6738 | desc = "PCIe device status unknown"; | |
6739 | break; | |
6740 | case MPI26_PCIEDEV0_ASTATUS_NVME_READY_TIMEOUT: | |
6741 | desc = "nvme ready timeout"; | |
6742 | break; | |
6743 | case MPI26_PCIEDEV0_ASTATUS_NVME_DEVCFG_UNSUPPORTED: | |
6744 | desc = "nvme device configuration unsupported"; | |
6745 | break; | |
6746 | case MPI26_PCIEDEV0_ASTATUS_NVME_IDENTIFY_FAILED: | |
6747 | desc = "nvme identify failed"; | |
6748 | break; | |
6749 | case MPI26_PCIEDEV0_ASTATUS_NVME_QCONFIG_FAILED: | |
6750 | desc = "nvme qconfig failed"; | |
6751 | break; | |
6752 | case MPI26_PCIEDEV0_ASTATUS_NVME_QCREATION_FAILED: | |
6753 | desc = "nvme qcreation failed"; | |
6754 | break; | |
6755 | case MPI26_PCIEDEV0_ASTATUS_NVME_EVENTCFG_FAILED: | |
6756 | desc = "nvme eventcfg failed"; | |
6757 | break; | |
6758 | case MPI26_PCIEDEV0_ASTATUS_NVME_GET_FEATURE_STAT_FAILED: | |
6759 | desc = "nvme get feature stat failed"; | |
6760 | break; | |
6761 | case MPI26_PCIEDEV0_ASTATUS_NVME_IDLE_TIMEOUT: | |
6762 | desc = "nvme idle timeout"; | |
6763 | break; | |
6764 | case MPI26_PCIEDEV0_ASTATUS_NVME_FAILURE_STATUS: | |
6765 | desc = "nvme failure status"; | |
6766 | break; | |
6767 | default: | |
919d8a3f JP |
6768 | ioc_err(ioc, "NVMe discovery error(0x%02x): wwid(0x%016llx), handle(0x%04x)\n", |
6769 | access_status, (u64)wwid, handle); | |
c102e00c SPS |
6770 | return rc; |
6771 | } | |
6772 | ||
6773 | if (!rc) | |
6774 | return rc; | |
6775 | ||
919d8a3f JP |
6776 | ioc_info(ioc, "NVMe discovery error(%s): wwid(0x%016llx), handle(0x%04x)\n", |
6777 | desc, (u64)wwid, handle); | |
c102e00c SPS |
6778 | return rc; |
6779 | } | |
3075ac49 SPS |
6780 | |
6781 | /** | |
6782 | * _scsih_pcie_device_remove_from_sml - removing pcie device | |
6783 | * from SML and free up associated memory | |
6784 | * @ioc: per adapter object | |
6785 | * @pcie_device: the pcie_device object | |
3075ac49 SPS |
6786 | */ |
6787 | static void | |
6788 | _scsih_pcie_device_remove_from_sml(struct MPT3SAS_ADAPTER *ioc, | |
6789 | struct _pcie_device *pcie_device) | |
6790 | { | |
6791 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
6792 | ||
919d8a3f JP |
6793 | dewtprintk(ioc, |
6794 | ioc_info(ioc, "%s: enter: handle(0x%04x), wwid(0x%016llx)\n", | |
6795 | __func__, | |
6796 | pcie_device->handle, (u64)pcie_device->wwid)); | |
3075ac49 | 6797 | if (pcie_device->enclosure_handle != 0) |
919d8a3f JP |
6798 | dewtprintk(ioc, |
6799 | ioc_info(ioc, "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n", | |
6800 | __func__, | |
6801 | (u64)pcie_device->enclosure_logical_id, | |
6802 | pcie_device->slot)); | |
3075ac49 | 6803 | if (pcie_device->connector_name[0] != '\0') |
919d8a3f JP |
6804 | dewtprintk(ioc, |
6805 | ioc_info(ioc, "%s: enter: enclosure level(0x%04x), connector name(%s)\n", | |
6806 | __func__, | |
6807 | pcie_device->enclosure_level, | |
6808 | pcie_device->connector_name)); | |
3075ac49 SPS |
6809 | |
6810 | if (pcie_device->starget && pcie_device->starget->hostdata) { | |
6811 | sas_target_priv_data = pcie_device->starget->hostdata; | |
6812 | sas_target_priv_data->deleted = 1; | |
6813 | _scsih_ublock_io_device(ioc, pcie_device->wwid); | |
6814 | sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE; | |
6815 | } | |
6816 | ||
919d8a3f JP |
6817 | ioc_info(ioc, "removing handle(0x%04x), wwid(0x%016llx)\n", |
6818 | pcie_device->handle, (u64)pcie_device->wwid); | |
3075ac49 | 6819 | if (pcie_device->enclosure_handle != 0) |
919d8a3f JP |
6820 | ioc_info(ioc, "removing : enclosure logical id(0x%016llx), slot(%d)\n", |
6821 | (u64)pcie_device->enclosure_logical_id, | |
6822 | pcie_device->slot); | |
3075ac49 | 6823 | if (pcie_device->connector_name[0] != '\0') |
919d8a3f JP |
6824 | ioc_info(ioc, "removing: enclosure level(0x%04x), connector name( %s)\n", |
6825 | pcie_device->enclosure_level, | |
6826 | pcie_device->connector_name); | |
3075ac49 | 6827 | |
3c090ce3 SP |
6828 | if (pcie_device->starget && (pcie_device->access_status != |
6829 | MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED)) | |
3075ac49 | 6830 | scsi_remove_target(&pcie_device->starget->dev); |
919d8a3f JP |
6831 | dewtprintk(ioc, |
6832 | ioc_info(ioc, "%s: exit: handle(0x%04x), wwid(0x%016llx)\n", | |
6833 | __func__, | |
6834 | pcie_device->handle, (u64)pcie_device->wwid)); | |
3075ac49 | 6835 | if (pcie_device->enclosure_handle != 0) |
919d8a3f JP |
6836 | dewtprintk(ioc, |
6837 | ioc_info(ioc, "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n", | |
6838 | __func__, | |
6839 | (u64)pcie_device->enclosure_logical_id, | |
6840 | pcie_device->slot)); | |
3075ac49 | 6841 | if (pcie_device->connector_name[0] != '\0') |
919d8a3f JP |
6842 | dewtprintk(ioc, |
6843 | ioc_info(ioc, "%s: exit: enclosure level(0x%04x), connector name( %s)\n", | |
6844 | __func__, | |
6845 | pcie_device->enclosure_level, | |
6846 | pcie_device->connector_name)); | |
3075ac49 SPS |
6847 | |
6848 | kfree(pcie_device->serial_number); | |
6849 | } | |
6850 | ||
6851 | ||
c102e00c SPS |
6852 | /** |
6853 | * _scsih_pcie_check_device - checking device responsiveness | |
6854 | * @ioc: per adapter object | |
6855 | * @handle: attached device handle | |
c102e00c SPS |
6856 | */ |
6857 | static void | |
6858 | _scsih_pcie_check_device(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
6859 | { | |
6860 | Mpi2ConfigReply_t mpi_reply; | |
6861 | Mpi26PCIeDevicePage0_t pcie_device_pg0; | |
6862 | u32 ioc_status; | |
6863 | struct _pcie_device *pcie_device; | |
6864 | u64 wwid; | |
6865 | unsigned long flags; | |
6866 | struct scsi_target *starget; | |
6867 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
6868 | u32 device_info; | |
6869 | ||
6870 | if ((mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply, | |
6871 | &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE, handle))) | |
6872 | return; | |
6873 | ||
6874 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
6875 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | |
6876 | return; | |
6877 | ||
6878 | /* check if this is end device */ | |
6879 | device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo); | |
5bb309db | 6880 | if (!(_scsih_is_nvme_pciescsi_device(device_info))) |
c102e00c SPS |
6881 | return; |
6882 | ||
6883 | wwid = le64_to_cpu(pcie_device_pg0.WWID); | |
6884 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
6885 | pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid); | |
6886 | ||
6887 | if (!pcie_device) { | |
6888 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
6889 | return; | |
6890 | } | |
6891 | ||
6892 | if (unlikely(pcie_device->handle != handle)) { | |
6893 | starget = pcie_device->starget; | |
6894 | sas_target_priv_data = starget->hostdata; | |
3c090ce3 | 6895 | pcie_device->access_status = pcie_device_pg0.AccessStatus; |
c102e00c SPS |
6896 | starget_printk(KERN_INFO, starget, |
6897 | "handle changed from(0x%04x) to (0x%04x)!!!\n", | |
6898 | pcie_device->handle, handle); | |
6899 | sas_target_priv_data->handle = handle; | |
6900 | pcie_device->handle = handle; | |
6901 | ||
6902 | if (le32_to_cpu(pcie_device_pg0.Flags) & | |
6903 | MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) { | |
6904 | pcie_device->enclosure_level = | |
6905 | pcie_device_pg0.EnclosureLevel; | |
6906 | memcpy(&pcie_device->connector_name[0], | |
6907 | &pcie_device_pg0.ConnectorName[0], 4); | |
6908 | } else { | |
6909 | pcie_device->enclosure_level = 0; | |
6910 | pcie_device->connector_name[0] = '\0'; | |
6911 | } | |
6912 | } | |
6913 | ||
6914 | /* check if device is present */ | |
6915 | if (!(le32_to_cpu(pcie_device_pg0.Flags) & | |
6916 | MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT)) { | |
919d8a3f JP |
6917 | ioc_info(ioc, "device is not present handle(0x%04x), flags!!!\n", |
6918 | handle); | |
c102e00c SPS |
6919 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); |
6920 | pcie_device_put(pcie_device); | |
6921 | return; | |
6922 | } | |
6923 | ||
6924 | /* check if there were any issues with discovery */ | |
6925 | if (_scsih_check_pcie_access_status(ioc, wwid, handle, | |
6926 | pcie_device_pg0.AccessStatus)) { | |
6927 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
6928 | pcie_device_put(pcie_device); | |
6929 | return; | |
6930 | } | |
6931 | ||
6932 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
6933 | pcie_device_put(pcie_device); | |
6934 | ||
6935 | _scsih_ublock_io_device(ioc, wwid); | |
6936 | ||
6937 | return; | |
6938 | } | |
6939 | ||
6940 | /** | |
6941 | * _scsih_pcie_add_device - creating pcie device object | |
6942 | * @ioc: per adapter object | |
6943 | * @handle: pcie device handle | |
6944 | * | |
6945 | * Creating end device object, stored in ioc->pcie_device_list. | |
6946 | * | |
4beb4867 | 6947 | * Return: 1 means queue the event later, 0 means complete the event |
c102e00c SPS |
6948 | */ |
6949 | static int | |
6950 | _scsih_pcie_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
6951 | { | |
6952 | Mpi26PCIeDevicePage0_t pcie_device_pg0; | |
6953 | Mpi26PCIeDevicePage2_t pcie_device_pg2; | |
6954 | Mpi2ConfigReply_t mpi_reply; | |
c102e00c | 6955 | struct _pcie_device *pcie_device; |
22a923c3 | 6956 | struct _enclosure_node *enclosure_dev; |
c102e00c SPS |
6957 | u32 ioc_status; |
6958 | u64 wwid; | |
6959 | ||
6960 | if ((mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply, | |
6961 | &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
919d8a3f JP |
6962 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
6963 | __FILE__, __LINE__, __func__); | |
c102e00c SPS |
6964 | return 0; |
6965 | } | |
6966 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6967 | MPI2_IOCSTATUS_MASK; | |
6968 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
919d8a3f JP |
6969 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
6970 | __FILE__, __LINE__, __func__); | |
c102e00c SPS |
6971 | return 0; |
6972 | } | |
6973 | ||
6974 | set_bit(handle, ioc->pend_os_device_add); | |
6975 | wwid = le64_to_cpu(pcie_device_pg0.WWID); | |
6976 | ||
6977 | /* check if device is present */ | |
6978 | if (!(le32_to_cpu(pcie_device_pg0.Flags) & | |
6979 | MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT)) { | |
919d8a3f JP |
6980 | ioc_err(ioc, "device is not present handle(0x04%x)!!!\n", |
6981 | handle); | |
c102e00c SPS |
6982 | return 0; |
6983 | } | |
6984 | ||
6985 | /* check if there were any issues with discovery */ | |
6986 | if (_scsih_check_pcie_access_status(ioc, wwid, handle, | |
6987 | pcie_device_pg0.AccessStatus)) | |
6988 | return 0; | |
6989 | ||
5bb309db SP |
6990 | if (!(_scsih_is_nvme_pciescsi_device(le32_to_cpu |
6991 | (pcie_device_pg0.DeviceInfo)))) | |
c102e00c SPS |
6992 | return 0; |
6993 | ||
6994 | pcie_device = mpt3sas_get_pdev_by_wwid(ioc, wwid); | |
6995 | if (pcie_device) { | |
6996 | clear_bit(handle, ioc->pend_os_device_add); | |
6997 | pcie_device_put(pcie_device); | |
6998 | return 0; | |
6999 | } | |
7000 | ||
5bb309db SP |
7001 | /* PCIe Device Page 2 contains read-only information about a |
7002 | * specific NVMe device; therefore, this page is only | |
7003 | * valid for NVMe devices and skip for pcie devices of type scsi. | |
7004 | */ | |
7005 | if (!(mpt3sas_scsih_is_pcie_scsi_device( | |
7006 | le32_to_cpu(pcie_device_pg0.DeviceInfo)))) { | |
7007 | if (mpt3sas_config_get_pcie_device_pg2(ioc, &mpi_reply, | |
7008 | &pcie_device_pg2, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | |
7009 | handle)) { | |
7010 | ioc_err(ioc, | |
7011 | "failure at %s:%d/%s()!\n", __FILE__, | |
7012 | __LINE__, __func__); | |
7013 | return 0; | |
7014 | } | |
7015 | ||
7016 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
7017 | MPI2_IOCSTATUS_MASK; | |
7018 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
7019 | ioc_err(ioc, | |
7020 | "failure at %s:%d/%s()!\n", __FILE__, | |
7021 | __LINE__, __func__); | |
7022 | return 0; | |
7023 | } | |
7024 | } | |
7025 | ||
c102e00c SPS |
7026 | pcie_device = kzalloc(sizeof(struct _pcie_device), GFP_KERNEL); |
7027 | if (!pcie_device) { | |
919d8a3f JP |
7028 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
7029 | __FILE__, __LINE__, __func__); | |
c102e00c SPS |
7030 | return 0; |
7031 | } | |
7032 | ||
7033 | kref_init(&pcie_device->refcount); | |
7034 | pcie_device->id = ioc->pcie_target_id++; | |
7035 | pcie_device->channel = PCIE_CHANNEL; | |
7036 | pcie_device->handle = handle; | |
3c090ce3 | 7037 | pcie_device->access_status = pcie_device_pg0.AccessStatus; |
c102e00c SPS |
7038 | pcie_device->device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo); |
7039 | pcie_device->wwid = wwid; | |
7040 | pcie_device->port_num = pcie_device_pg0.PortNum; | |
7041 | pcie_device->fast_path = (le32_to_cpu(pcie_device_pg0.Flags) & | |
7042 | MPI26_PCIEDEV0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0; | |
c102e00c SPS |
7043 | |
7044 | pcie_device->enclosure_handle = | |
7045 | le16_to_cpu(pcie_device_pg0.EnclosureHandle); | |
7046 | if (pcie_device->enclosure_handle != 0) | |
7047 | pcie_device->slot = le16_to_cpu(pcie_device_pg0.Slot); | |
7048 | ||
cf6bf971 | 7049 | if (le32_to_cpu(pcie_device_pg0.Flags) & |
c102e00c SPS |
7050 | MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) { |
7051 | pcie_device->enclosure_level = pcie_device_pg0.EnclosureLevel; | |
7052 | memcpy(&pcie_device->connector_name[0], | |
7053 | &pcie_device_pg0.ConnectorName[0], 4); | |
7054 | } else { | |
7055 | pcie_device->enclosure_level = 0; | |
7056 | pcie_device->connector_name[0] = '\0'; | |
7057 | } | |
7058 | ||
7059 | /* get enclosure_logical_id */ | |
22a923c3 C |
7060 | if (pcie_device->enclosure_handle) { |
7061 | enclosure_dev = | |
7062 | mpt3sas_scsih_enclosure_find_by_handle(ioc, | |
7063 | pcie_device->enclosure_handle); | |
7064 | if (enclosure_dev) | |
7065 | pcie_device->enclosure_logical_id = | |
7066 | le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID); | |
7067 | } | |
c102e00c | 7068 | /* TODO -- Add device name once FW supports it */ |
5bb309db SP |
7069 | if (!(mpt3sas_scsih_is_pcie_scsi_device( |
7070 | le32_to_cpu(pcie_device_pg0.DeviceInfo)))) { | |
7071 | pcie_device->nvme_mdts = | |
7072 | le32_to_cpu(pcie_device_pg2.MaximumDataTransferSize); | |
43fb7c95 SR |
7073 | pcie_device->shutdown_latency = |
7074 | le16_to_cpu(pcie_device_pg2.ShutdownLatency); | |
7075 | /* | |
7076 | * Set IOC's max_shutdown_latency to drive's RTD3 Entry Latency | |
7077 | * if drive's RTD3 Entry Latency is greater then IOC's | |
7078 | * max_shutdown_latency. | |
7079 | */ | |
7080 | if (pcie_device->shutdown_latency > ioc->max_shutdown_latency) | |
7081 | ioc->max_shutdown_latency = | |
7082 | pcie_device->shutdown_latency; | |
5bb309db SP |
7083 | if (pcie_device_pg2.ControllerResetTO) |
7084 | pcie_device->reset_timeout = | |
7085 | pcie_device_pg2.ControllerResetTO; | |
7086 | else | |
7087 | pcie_device->reset_timeout = 30; | |
7088 | } else | |
c1a6c5ac | 7089 | pcie_device->reset_timeout = 30; |
c102e00c SPS |
7090 | |
7091 | if (ioc->wait_for_discovery_to_complete) | |
7092 | _scsih_pcie_device_init_add(ioc, pcie_device); | |
7093 | else | |
7094 | _scsih_pcie_device_add(ioc, pcie_device); | |
7095 | ||
7096 | pcie_device_put(pcie_device); | |
7097 | return 0; | |
7098 | } | |
4318c734 SPS |
7099 | |
7100 | /** | |
7101 | * _scsih_pcie_topology_change_event_debug - debug for topology | |
7102 | * event | |
7103 | * @ioc: per adapter object | |
7104 | * @event_data: event data payload | |
7105 | * Context: user. | |
7106 | */ | |
7107 | static void | |
7108 | _scsih_pcie_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
7109 | Mpi26EventDataPCIeTopologyChangeList_t *event_data) | |
7110 | { | |
7111 | int i; | |
7112 | u16 handle; | |
7113 | u16 reason_code; | |
7114 | u8 port_number; | |
7115 | char *status_str = NULL; | |
7116 | u8 link_rate, prev_link_rate; | |
7117 | ||
7118 | switch (event_data->SwitchStatus) { | |
7119 | case MPI26_EVENT_PCIE_TOPO_SS_ADDED: | |
7120 | status_str = "add"; | |
7121 | break; | |
7122 | case MPI26_EVENT_PCIE_TOPO_SS_NOT_RESPONDING: | |
7123 | status_str = "remove"; | |
7124 | break; | |
7125 | case MPI26_EVENT_PCIE_TOPO_SS_RESPONDING: | |
7126 | case 0: | |
7127 | status_str = "responding"; | |
7128 | break; | |
7129 | case MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING: | |
7130 | status_str = "remove delay"; | |
7131 | break; | |
7132 | default: | |
7133 | status_str = "unknown status"; | |
7134 | break; | |
7135 | } | |
919d8a3f | 7136 | ioc_info(ioc, "pcie topology change: (%s)\n", status_str); |
4318c734 SPS |
7137 | pr_info("\tswitch_handle(0x%04x), enclosure_handle(0x%04x)" |
7138 | "start_port(%02d), count(%d)\n", | |
7139 | le16_to_cpu(event_data->SwitchDevHandle), | |
7140 | le16_to_cpu(event_data->EnclosureHandle), | |
7141 | event_data->StartPortNum, event_data->NumEntries); | |
7142 | for (i = 0; i < event_data->NumEntries; i++) { | |
7143 | handle = | |
7144 | le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle); | |
7145 | if (!handle) | |
7146 | continue; | |
7147 | port_number = event_data->StartPortNum + i; | |
7148 | reason_code = event_data->PortEntry[i].PortStatus; | |
7149 | switch (reason_code) { | |
7150 | case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED: | |
7151 | status_str = "target add"; | |
7152 | break; | |
7153 | case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING: | |
7154 | status_str = "target remove"; | |
7155 | break; | |
7156 | case MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING: | |
7157 | status_str = "delay target remove"; | |
7158 | break; | |
7159 | case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED: | |
7160 | status_str = "link rate change"; | |
7161 | break; | |
7162 | case MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE: | |
7163 | status_str = "target responding"; | |
7164 | break; | |
7165 | default: | |
7166 | status_str = "unknown"; | |
7167 | break; | |
7168 | } | |
7169 | link_rate = event_data->PortEntry[i].CurrentPortInfo & | |
7170 | MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK; | |
7171 | prev_link_rate = event_data->PortEntry[i].PreviousPortInfo & | |
7172 | MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK; | |
7173 | pr_info("\tport(%02d), attached_handle(0x%04x): %s:" | |
7174 | " link rate: new(0x%02x), old(0x%02x)\n", port_number, | |
7175 | handle, status_str, link_rate, prev_link_rate); | |
7176 | } | |
7177 | } | |
7178 | ||
7179 | /** | |
7180 | * _scsih_pcie_topology_change_event - handle PCIe topology | |
7181 | * changes | |
7182 | * @ioc: per adapter object | |
7183 | * @fw_event: The fw_event_work object | |
7184 | * Context: user. | |
7185 | * | |
7186 | */ | |
45b7aef7 | 7187 | static void |
4318c734 SPS |
7188 | _scsih_pcie_topology_change_event(struct MPT3SAS_ADAPTER *ioc, |
7189 | struct fw_event_work *fw_event) | |
7190 | { | |
7191 | int i; | |
7192 | u16 handle; | |
7193 | u16 reason_code; | |
7194 | u8 link_rate, prev_link_rate; | |
7195 | unsigned long flags; | |
7196 | int rc; | |
4318c734 SPS |
7197 | Mpi26EventDataPCIeTopologyChangeList_t *event_data = |
7198 | (Mpi26EventDataPCIeTopologyChangeList_t *) fw_event->event_data; | |
7199 | struct _pcie_device *pcie_device; | |
7200 | ||
7201 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) | |
7202 | _scsih_pcie_topology_change_event_debug(ioc, event_data); | |
7203 | ||
7204 | if (ioc->shost_recovery || ioc->remove_host || | |
7205 | ioc->pci_error_recovery) | |
45b7aef7 | 7206 | return; |
4318c734 SPS |
7207 | |
7208 | if (fw_event->ignore) { | |
919d8a3f | 7209 | dewtprintk(ioc, ioc_info(ioc, "ignoring switch event\n")); |
45b7aef7 | 7210 | return; |
4318c734 SPS |
7211 | } |
7212 | ||
7213 | /* handle siblings events */ | |
7214 | for (i = 0; i < event_data->NumEntries; i++) { | |
7215 | if (fw_event->ignore) { | |
919d8a3f JP |
7216 | dewtprintk(ioc, |
7217 | ioc_info(ioc, "ignoring switch event\n")); | |
45b7aef7 | 7218 | return; |
4318c734 SPS |
7219 | } |
7220 | if (ioc->remove_host || ioc->pci_error_recovery) | |
45b7aef7 | 7221 | return; |
4318c734 SPS |
7222 | reason_code = event_data->PortEntry[i].PortStatus; |
7223 | handle = | |
7224 | le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle); | |
7225 | if (!handle) | |
7226 | continue; | |
7227 | ||
7228 | link_rate = event_data->PortEntry[i].CurrentPortInfo | |
7229 | & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK; | |
7230 | prev_link_rate = event_data->PortEntry[i].PreviousPortInfo | |
7231 | & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK; | |
7232 | ||
7233 | switch (reason_code) { | |
7234 | case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED: | |
7235 | if (ioc->shost_recovery) | |
7236 | break; | |
7237 | if (link_rate == prev_link_rate) | |
7238 | break; | |
7239 | if (link_rate < MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5) | |
7240 | break; | |
7241 | ||
7242 | _scsih_pcie_check_device(ioc, handle); | |
7243 | ||
7244 | /* This code after this point handles the test case | |
7245 | * where a device has been added, however its returning | |
7246 | * BUSY for sometime. Then before the Device Missing | |
7247 | * Delay expires and the device becomes READY, the | |
7248 | * device is removed and added back. | |
7249 | */ | |
7250 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
7251 | pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle); | |
7252 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
7253 | ||
7254 | if (pcie_device) { | |
7255 | pcie_device_put(pcie_device); | |
7256 | break; | |
7257 | } | |
7258 | ||
7259 | if (!test_bit(handle, ioc->pend_os_device_add)) | |
7260 | break; | |
7261 | ||
919d8a3f JP |
7262 | dewtprintk(ioc, |
7263 | ioc_info(ioc, "handle(0x%04x) device not found: convert event to a device add\n", | |
7264 | handle)); | |
4318c734 SPS |
7265 | event_data->PortEntry[i].PortStatus &= 0xF0; |
7266 | event_data->PortEntry[i].PortStatus |= | |
7267 | MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED; | |
eb0c7af2 | 7268 | /* fall through */ |
4318c734 SPS |
7269 | case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED: |
7270 | if (ioc->shost_recovery) | |
7271 | break; | |
7272 | if (link_rate < MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5) | |
7273 | break; | |
7274 | ||
7275 | rc = _scsih_pcie_add_device(ioc, handle); | |
7276 | if (!rc) { | |
7277 | /* mark entry vacant */ | |
7278 | /* TODO This needs to be reviewed and fixed, | |
7279 | * we dont have an entry | |
7280 | * to make an event void like vacant | |
7281 | */ | |
7282 | event_data->PortEntry[i].PortStatus |= | |
7283 | MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE; | |
7284 | } | |
7285 | break; | |
7286 | case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING: | |
7287 | _scsih_pcie_device_remove_by_handle(ioc, handle); | |
7288 | break; | |
7289 | } | |
7290 | } | |
4318c734 SPS |
7291 | } |
7292 | ||
7293 | /** | |
4beb4867 BVA |
7294 | * _scsih_pcie_device_status_change_event_debug - debug for device event |
7295 | * @ioc: ? | |
4318c734 SPS |
7296 | * @event_data: event data payload |
7297 | * Context: user. | |
4318c734 SPS |
7298 | */ |
7299 | static void | |
7300 | _scsih_pcie_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
7301 | Mpi26EventDataPCIeDeviceStatusChange_t *event_data) | |
7302 | { | |
7303 | char *reason_str = NULL; | |
7304 | ||
7305 | switch (event_data->ReasonCode) { | |
7306 | case MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA: | |
7307 | reason_str = "smart data"; | |
7308 | break; | |
7309 | case MPI26_EVENT_PCIDEV_STAT_RC_UNSUPPORTED: | |
7310 | reason_str = "unsupported device discovered"; | |
7311 | break; | |
7312 | case MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET: | |
7313 | reason_str = "internal device reset"; | |
7314 | break; | |
7315 | case MPI26_EVENT_PCIDEV_STAT_RC_TASK_ABORT_INTERNAL: | |
7316 | reason_str = "internal task abort"; | |
7317 | break; | |
7318 | case MPI26_EVENT_PCIDEV_STAT_RC_ABORT_TASK_SET_INTERNAL: | |
7319 | reason_str = "internal task abort set"; | |
7320 | break; | |
7321 | case MPI26_EVENT_PCIDEV_STAT_RC_CLEAR_TASK_SET_INTERNAL: | |
7322 | reason_str = "internal clear task set"; | |
7323 | break; | |
7324 | case MPI26_EVENT_PCIDEV_STAT_RC_QUERY_TASK_INTERNAL: | |
7325 | reason_str = "internal query task"; | |
7326 | break; | |
7327 | case MPI26_EVENT_PCIDEV_STAT_RC_DEV_INIT_FAILURE: | |
7328 | reason_str = "device init failure"; | |
7329 | break; | |
7330 | case MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET: | |
7331 | reason_str = "internal device reset complete"; | |
7332 | break; | |
7333 | case MPI26_EVENT_PCIDEV_STAT_RC_CMP_TASK_ABORT_INTERNAL: | |
7334 | reason_str = "internal task abort complete"; | |
7335 | break; | |
7336 | case MPI26_EVENT_PCIDEV_STAT_RC_ASYNC_NOTIFICATION: | |
7337 | reason_str = "internal async notification"; | |
7338 | break; | |
c1a6c5ac C |
7339 | case MPI26_EVENT_PCIDEV_STAT_RC_PCIE_HOT_RESET_FAILED: |
7340 | reason_str = "pcie hot reset failed"; | |
7341 | break; | |
4318c734 SPS |
7342 | default: |
7343 | reason_str = "unknown reason"; | |
7344 | break; | |
7345 | } | |
7346 | ||
919d8a3f JP |
7347 | ioc_info(ioc, "PCIE device status change: (%s)\n" |
7348 | "\thandle(0x%04x), WWID(0x%016llx), tag(%d)", | |
7349 | reason_str, le16_to_cpu(event_data->DevHandle), | |
7350 | (u64)le64_to_cpu(event_data->WWID), | |
7351 | le16_to_cpu(event_data->TaskTag)); | |
4318c734 | 7352 | if (event_data->ReasonCode == MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA) |
919d8a3f | 7353 | pr_cont(", ASC(0x%x), ASCQ(0x%x)\n", |
4318c734 | 7354 | event_data->ASC, event_data->ASCQ); |
919d8a3f | 7355 | pr_cont("\n"); |
4318c734 SPS |
7356 | } |
7357 | ||
7358 | /** | |
7359 | * _scsih_pcie_device_status_change_event - handle device status | |
7360 | * change | |
7361 | * @ioc: per adapter object | |
7362 | * @fw_event: The fw_event_work object | |
7363 | * Context: user. | |
4318c734 SPS |
7364 | */ |
7365 | static void | |
7366 | _scsih_pcie_device_status_change_event(struct MPT3SAS_ADAPTER *ioc, | |
7367 | struct fw_event_work *fw_event) | |
7368 | { | |
7369 | struct MPT3SAS_TARGET *target_priv_data; | |
7370 | struct _pcie_device *pcie_device; | |
7371 | u64 wwid; | |
7372 | unsigned long flags; | |
7373 | Mpi26EventDataPCIeDeviceStatusChange_t *event_data = | |
7374 | (Mpi26EventDataPCIeDeviceStatusChange_t *)fw_event->event_data; | |
7375 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) | |
7376 | _scsih_pcie_device_status_change_event_debug(ioc, | |
7377 | event_data); | |
7378 | ||
7379 | if (event_data->ReasonCode != | |
7380 | MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET && | |
7381 | event_data->ReasonCode != | |
7382 | MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET) | |
7383 | return; | |
7384 | ||
7385 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
7386 | wwid = le64_to_cpu(event_data->WWID); | |
7387 | pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid); | |
7388 | ||
7389 | if (!pcie_device || !pcie_device->starget) | |
7390 | goto out; | |
7391 | ||
7392 | target_priv_data = pcie_device->starget->hostdata; | |
7393 | if (!target_priv_data) | |
7394 | goto out; | |
7395 | ||
7396 | if (event_data->ReasonCode == | |
7397 | MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET) | |
7398 | target_priv_data->tm_busy = 1; | |
7399 | else | |
7400 | target_priv_data->tm_busy = 0; | |
7401 | out: | |
7402 | if (pcie_device) | |
7403 | pcie_device_put(pcie_device); | |
7404 | ||
7405 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
7406 | } | |
7407 | ||
f92363d1 SR |
7408 | /** |
7409 | * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure | |
7410 | * event | |
7411 | * @ioc: per adapter object | |
7412 | * @event_data: event data payload | |
7413 | * Context: user. | |
f92363d1 SR |
7414 | */ |
7415 | static void | |
7416 | _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
7417 | Mpi2EventDataSasEnclDevStatusChange_t *event_data) | |
7418 | { | |
7419 | char *reason_str = NULL; | |
7420 | ||
7421 | switch (event_data->ReasonCode) { | |
7422 | case MPI2_EVENT_SAS_ENCL_RC_ADDED: | |
7423 | reason_str = "enclosure add"; | |
7424 | break; | |
7425 | case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING: | |
7426 | reason_str = "enclosure remove"; | |
7427 | break; | |
7428 | default: | |
7429 | reason_str = "unknown reason"; | |
7430 | break; | |
7431 | } | |
7432 | ||
919d8a3f JP |
7433 | ioc_info(ioc, "enclosure status change: (%s)\n" |
7434 | "\thandle(0x%04x), enclosure logical id(0x%016llx) number slots(%d)\n", | |
7435 | reason_str, | |
7436 | le16_to_cpu(event_data->EnclosureHandle), | |
7437 | (u64)le64_to_cpu(event_data->EnclosureLogicalID), | |
7438 | le16_to_cpu(event_data->StartSlot)); | |
f92363d1 | 7439 | } |
f92363d1 SR |
7440 | |
7441 | /** | |
7442 | * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events | |
7443 | * @ioc: per adapter object | |
7444 | * @fw_event: The fw_event_work object | |
7445 | * Context: user. | |
f92363d1 SR |
7446 | */ |
7447 | static void | |
7448 | _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc, | |
7449 | struct fw_event_work *fw_event) | |
7450 | { | |
22a923c3 C |
7451 | Mpi2ConfigReply_t mpi_reply; |
7452 | struct _enclosure_node *enclosure_dev = NULL; | |
7453 | Mpi2EventDataSasEnclDevStatusChange_t *event_data = | |
7454 | (Mpi2EventDataSasEnclDevStatusChange_t *)fw_event->event_data; | |
7455 | int rc; | |
7456 | u16 enclosure_handle = le16_to_cpu(event_data->EnclosureHandle); | |
7457 | ||
f92363d1 SR |
7458 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
7459 | _scsih_sas_enclosure_dev_status_change_event_debug(ioc, | |
35b62362 | 7460 | (Mpi2EventDataSasEnclDevStatusChange_t *) |
f92363d1 | 7461 | fw_event->event_data); |
22a923c3 C |
7462 | if (ioc->shost_recovery) |
7463 | return; | |
7464 | ||
7465 | if (enclosure_handle) | |
7466 | enclosure_dev = | |
7467 | mpt3sas_scsih_enclosure_find_by_handle(ioc, | |
7468 | enclosure_handle); | |
7469 | switch (event_data->ReasonCode) { | |
7470 | case MPI2_EVENT_SAS_ENCL_RC_ADDED: | |
7471 | if (!enclosure_dev) { | |
7472 | enclosure_dev = | |
7473 | kzalloc(sizeof(struct _enclosure_node), | |
7474 | GFP_KERNEL); | |
7475 | if (!enclosure_dev) { | |
919d8a3f JP |
7476 | ioc_info(ioc, "failure at %s:%d/%s()!\n", |
7477 | __FILE__, __LINE__, __func__); | |
22a923c3 C |
7478 | return; |
7479 | } | |
7480 | rc = mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
7481 | &enclosure_dev->pg0, | |
7482 | MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
7483 | enclosure_handle); | |
7484 | ||
7485 | if (rc || (le16_to_cpu(mpi_reply.IOCStatus) & | |
7486 | MPI2_IOCSTATUS_MASK)) { | |
7487 | kfree(enclosure_dev); | |
7488 | return; | |
7489 | } | |
7490 | ||
7491 | list_add_tail(&enclosure_dev->list, | |
7492 | &ioc->enclosure_list); | |
7493 | } | |
7494 | break; | |
7495 | case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING: | |
7496 | if (enclosure_dev) { | |
7497 | list_del(&enclosure_dev->list); | |
7498 | kfree(enclosure_dev); | |
7499 | } | |
7500 | break; | |
7501 | default: | |
7502 | break; | |
7503 | } | |
f92363d1 SR |
7504 | } |
7505 | ||
7506 | /** | |
7507 | * _scsih_sas_broadcast_primitive_event - handle broadcast events | |
7508 | * @ioc: per adapter object | |
7509 | * @fw_event: The fw_event_work object | |
7510 | * Context: user. | |
f92363d1 SR |
7511 | */ |
7512 | static void | |
7513 | _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc, | |
7514 | struct fw_event_work *fw_event) | |
7515 | { | |
7516 | struct scsi_cmnd *scmd; | |
7517 | struct scsi_device *sdev; | |
6da999fe | 7518 | struct scsiio_tracker *st; |
f92363d1 SR |
7519 | u16 smid, handle; |
7520 | u32 lun; | |
7521 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
7522 | u32 termination_count; | |
7523 | u32 query_count; | |
7524 | Mpi2SCSITaskManagementReply_t *mpi_reply; | |
35b62362 JL |
7525 | Mpi2EventDataSasBroadcastPrimitive_t *event_data = |
7526 | (Mpi2EventDataSasBroadcastPrimitive_t *) | |
7527 | fw_event->event_data; | |
f92363d1 SR |
7528 | u16 ioc_status; |
7529 | unsigned long flags; | |
7530 | int r; | |
7531 | u8 max_retries = 0; | |
7532 | u8 task_abort_retries; | |
7533 | ||
7534 | mutex_lock(&ioc->tm_cmds.mutex); | |
919d8a3f JP |
7535 | ioc_info(ioc, "%s: enter: phy number(%d), width(%d)\n", |
7536 | __func__, event_data->PhyNum, event_data->PortWidth); | |
f92363d1 SR |
7537 | |
7538 | _scsih_block_io_all_device(ioc); | |
7539 | ||
7540 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7541 | mpi_reply = ioc->tm_cmds.reply; | |
7542 | broadcast_aen_retry: | |
7543 | ||
7544 | /* sanity checks for retrying this loop */ | |
7545 | if (max_retries++ == 5) { | |
919d8a3f | 7546 | dewtprintk(ioc, ioc_info(ioc, "%s: giving up\n", __func__)); |
f92363d1 SR |
7547 | goto out; |
7548 | } else if (max_retries > 1) | |
919d8a3f JP |
7549 | dewtprintk(ioc, |
7550 | ioc_info(ioc, "%s: %d retry\n", | |
7551 | __func__, max_retries - 1)); | |
f92363d1 SR |
7552 | |
7553 | termination_count = 0; | |
7554 | query_count = 0; | |
7555 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { | |
7556 | if (ioc->shost_recovery) | |
7557 | goto out; | |
dbec4c90 | 7558 | scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid); |
f92363d1 SR |
7559 | if (!scmd) |
7560 | continue; | |
dbec4c90 | 7561 | st = scsi_cmd_priv(scmd); |
f92363d1 SR |
7562 | sdev = scmd->device; |
7563 | sas_device_priv_data = sdev->hostdata; | |
7564 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) | |
7565 | continue; | |
7566 | /* skip hidden raid components */ | |
7567 | if (sas_device_priv_data->sas_target->flags & | |
7568 | MPT_TARGET_FLAGS_RAID_COMPONENT) | |
7569 | continue; | |
7570 | /* skip volumes */ | |
7571 | if (sas_device_priv_data->sas_target->flags & | |
7572 | MPT_TARGET_FLAGS_VOLUME) | |
7573 | continue; | |
999c8513 C |
7574 | /* skip PCIe devices */ |
7575 | if (sas_device_priv_data->sas_target->flags & | |
7576 | MPT_TARGET_FLAGS_PCIE_DEVICE) | |
7577 | continue; | |
f92363d1 SR |
7578 | |
7579 | handle = sas_device_priv_data->sas_target->handle; | |
7580 | lun = sas_device_priv_data->lun; | |
7581 | query_count++; | |
7582 | ||
7583 | if (ioc->shost_recovery) | |
7584 | goto out; | |
7585 | ||
7586 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
6da999fe | 7587 | r = mpt3sas_scsih_issue_tm(ioc, handle, lun, |
dbec4c90 | 7588 | MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, st->smid, |
c1a6c5ac | 7589 | st->msix_io, 30, 0); |
f92363d1 SR |
7590 | if (r == FAILED) { |
7591 | sdev_printk(KERN_WARNING, sdev, | |
7592 | "mpt3sas_scsih_issue_tm: FAILED when sending " | |
7593 | "QUERY_TASK: scmd(%p)\n", scmd); | |
7594 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7595 | goto broadcast_aen_retry; | |
7596 | } | |
7597 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) | |
7598 | & MPI2_IOCSTATUS_MASK; | |
7599 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
7600 | sdev_printk(KERN_WARNING, sdev, | |
7601 | "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n", | |
7602 | ioc_status, scmd); | |
7603 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7604 | goto broadcast_aen_retry; | |
7605 | } | |
7606 | ||
7607 | /* see if IO is still owned by IOC and target */ | |
7608 | if (mpi_reply->ResponseCode == | |
7609 | MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED || | |
7610 | mpi_reply->ResponseCode == | |
7611 | MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) { | |
7612 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7613 | continue; | |
7614 | } | |
7615 | task_abort_retries = 0; | |
7616 | tm_retry: | |
7617 | if (task_abort_retries++ == 60) { | |
919d8a3f JP |
7618 | dewtprintk(ioc, |
7619 | ioc_info(ioc, "%s: ABORT_TASK: giving up\n", | |
7620 | __func__)); | |
f92363d1 SR |
7621 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
7622 | goto broadcast_aen_retry; | |
7623 | } | |
7624 | ||
7625 | if (ioc->shost_recovery) | |
7626 | goto out_no_lock; | |
7627 | ||
6da999fe | 7628 | r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->lun, |
dbec4c90 | 7629 | MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, st->smid, |
c1a6c5ac | 7630 | st->msix_io, 30, 0); |
dbec4c90 | 7631 | if (r == FAILED || st->cb_idx != 0xFF) { |
f92363d1 SR |
7632 | sdev_printk(KERN_WARNING, sdev, |
7633 | "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : " | |
7634 | "scmd(%p)\n", scmd); | |
7635 | goto tm_retry; | |
7636 | } | |
7637 | ||
7638 | if (task_abort_retries > 1) | |
7639 | sdev_printk(KERN_WARNING, sdev, | |
7640 | "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):" | |
7641 | " scmd(%p)\n", | |
7642 | task_abort_retries - 1, scmd); | |
7643 | ||
7644 | termination_count += le32_to_cpu(mpi_reply->TerminationCount); | |
7645 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7646 | } | |
7647 | ||
7648 | if (ioc->broadcast_aen_pending) { | |
919d8a3f JP |
7649 | dewtprintk(ioc, |
7650 | ioc_info(ioc, | |
7651 | "%s: loop back due to pending AEN\n", | |
7652 | __func__)); | |
f92363d1 SR |
7653 | ioc->broadcast_aen_pending = 0; |
7654 | goto broadcast_aen_retry; | |
7655 | } | |
7656 | ||
7657 | out: | |
7658 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
7659 | out_no_lock: | |
7660 | ||
919d8a3f JP |
7661 | dewtprintk(ioc, |
7662 | ioc_info(ioc, "%s - exit, query_count = %d termination_count = %d\n", | |
7663 | __func__, query_count, termination_count)); | |
f92363d1 SR |
7664 | |
7665 | ioc->broadcast_aen_busy = 0; | |
7666 | if (!ioc->shost_recovery) | |
7667 | _scsih_ublock_io_all_device(ioc); | |
7668 | mutex_unlock(&ioc->tm_cmds.mutex); | |
7669 | } | |
7670 | ||
7671 | /** | |
7672 | * _scsih_sas_discovery_event - handle discovery events | |
7673 | * @ioc: per adapter object | |
7674 | * @fw_event: The fw_event_work object | |
7675 | * Context: user. | |
f92363d1 SR |
7676 | */ |
7677 | static void | |
7678 | _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc, | |
7679 | struct fw_event_work *fw_event) | |
7680 | { | |
35b62362 JL |
7681 | Mpi2EventDataSasDiscovery_t *event_data = |
7682 | (Mpi2EventDataSasDiscovery_t *) fw_event->event_data; | |
f92363d1 | 7683 | |
f92363d1 | 7684 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) { |
919d8a3f JP |
7685 | ioc_info(ioc, "discovery event: (%s)", |
7686 | event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED ? | |
7687 | "start" : "stop"); | |
af009411 | 7688 | if (event_data->DiscoveryStatus) |
919d8a3f JP |
7689 | pr_cont("discovery_status(0x%08x)", |
7690 | le32_to_cpu(event_data->DiscoveryStatus)); | |
7691 | pr_cont("\n"); | |
f92363d1 | 7692 | } |
f92363d1 SR |
7693 | |
7694 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED && | |
7695 | !ioc->sas_hba.num_phys) { | |
7696 | if (disable_discovery > 0 && ioc->shost_recovery) { | |
7697 | /* Wait for the reset to complete */ | |
7698 | while (ioc->shost_recovery) | |
7699 | ssleep(1); | |
7700 | } | |
7701 | _scsih_sas_host_add(ioc); | |
7702 | } | |
7703 | } | |
7704 | ||
95540b8e C |
7705 | /** |
7706 | * _scsih_sas_device_discovery_error_event - display SAS device discovery error | |
7707 | * events | |
7708 | * @ioc: per adapter object | |
7709 | * @fw_event: The fw_event_work object | |
7710 | * Context: user. | |
95540b8e C |
7711 | */ |
7712 | static void | |
7713 | _scsih_sas_device_discovery_error_event(struct MPT3SAS_ADAPTER *ioc, | |
7714 | struct fw_event_work *fw_event) | |
7715 | { | |
7716 | Mpi25EventDataSasDeviceDiscoveryError_t *event_data = | |
7717 | (Mpi25EventDataSasDeviceDiscoveryError_t *)fw_event->event_data; | |
7718 | ||
7719 | switch (event_data->ReasonCode) { | |
7720 | case MPI25_EVENT_SAS_DISC_ERR_SMP_FAILED: | |
919d8a3f JP |
7721 | ioc_warn(ioc, "SMP command sent to the expander (handle:0x%04x, sas_address:0x%016llx, physical_port:0x%02x) has failed\n", |
7722 | le16_to_cpu(event_data->DevHandle), | |
7723 | (u64)le64_to_cpu(event_data->SASAddress), | |
7724 | event_data->PhysicalPort); | |
95540b8e C |
7725 | break; |
7726 | case MPI25_EVENT_SAS_DISC_ERR_SMP_TIMEOUT: | |
919d8a3f JP |
7727 | ioc_warn(ioc, "SMP command sent to the expander (handle:0x%04x, sas_address:0x%016llx, physical_port:0x%02x) has timed out\n", |
7728 | le16_to_cpu(event_data->DevHandle), | |
7729 | (u64)le64_to_cpu(event_data->SASAddress), | |
7730 | event_data->PhysicalPort); | |
95540b8e C |
7731 | break; |
7732 | default: | |
7733 | break; | |
7734 | } | |
7735 | } | |
7736 | ||
4318c734 SPS |
7737 | /** |
7738 | * _scsih_pcie_enumeration_event - handle enumeration events | |
7739 | * @ioc: per adapter object | |
7740 | * @fw_event: The fw_event_work object | |
7741 | * Context: user. | |
4318c734 SPS |
7742 | */ |
7743 | static void | |
7744 | _scsih_pcie_enumeration_event(struct MPT3SAS_ADAPTER *ioc, | |
7745 | struct fw_event_work *fw_event) | |
7746 | { | |
7747 | Mpi26EventDataPCIeEnumeration_t *event_data = | |
7748 | (Mpi26EventDataPCIeEnumeration_t *)fw_event->event_data; | |
7749 | ||
6767aced DC |
7750 | if (!(ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)) |
7751 | return; | |
7752 | ||
919d8a3f JP |
7753 | ioc_info(ioc, "pcie enumeration event: (%s) Flag 0x%02x", |
7754 | (event_data->ReasonCode == MPI26_EVENT_PCIE_ENUM_RC_STARTED) ? | |
7755 | "started" : "completed", | |
7756 | event_data->Flags); | |
4318c734 | 7757 | if (event_data->EnumerationStatus) |
6767aced DC |
7758 | pr_cont("enumeration_status(0x%08x)", |
7759 | le32_to_cpu(event_data->EnumerationStatus)); | |
7760 | pr_cont("\n"); | |
4318c734 SPS |
7761 | } |
7762 | ||
f92363d1 SR |
7763 | /** |
7764 | * _scsih_ir_fastpath - turn on fastpath for IR physdisk | |
7765 | * @ioc: per adapter object | |
7766 | * @handle: device handle for physical disk | |
7767 | * @phys_disk_num: physical disk number | |
7768 | * | |
4beb4867 | 7769 | * Return: 0 for success, else failure. |
f92363d1 SR |
7770 | */ |
7771 | static int | |
7772 | _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num) | |
7773 | { | |
7774 | Mpi2RaidActionRequest_t *mpi_request; | |
7775 | Mpi2RaidActionReply_t *mpi_reply; | |
7776 | u16 smid; | |
7777 | u8 issue_reset = 0; | |
7778 | int rc = 0; | |
7779 | u16 ioc_status; | |
7780 | u32 log_info; | |
7781 | ||
c84b06a4 SR |
7782 | if (ioc->hba_mpi_version_belonged == MPI2_VERSION) |
7783 | return rc; | |
7784 | ||
f92363d1 SR |
7785 | mutex_lock(&ioc->scsih_cmds.mutex); |
7786 | ||
7787 | if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) { | |
919d8a3f | 7788 | ioc_err(ioc, "%s: scsih_cmd in use\n", __func__); |
f92363d1 SR |
7789 | rc = -EAGAIN; |
7790 | goto out; | |
7791 | } | |
7792 | ioc->scsih_cmds.status = MPT3_CMD_PENDING; | |
7793 | ||
7794 | smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx); | |
7795 | if (!smid) { | |
919d8a3f | 7796 | ioc_err(ioc, "%s: failed obtaining a smid\n", __func__); |
f92363d1 SR |
7797 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; |
7798 | rc = -EAGAIN; | |
7799 | goto out; | |
7800 | } | |
7801 | ||
7802 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
7803 | ioc->scsih_cmds.smid = smid; | |
7804 | memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t)); | |
7805 | ||
7806 | mpi_request->Function = MPI2_FUNCTION_RAID_ACTION; | |
7807 | mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN; | |
7808 | mpi_request->PhysDiskNum = phys_disk_num; | |
7809 | ||
919d8a3f JP |
7810 | dewtprintk(ioc, |
7811 | ioc_info(ioc, "IR RAID_ACTION: turning fast path on for handle(0x%04x), phys_disk_num (0x%02x)\n", | |
7812 | handle, phys_disk_num)); | |
f92363d1 SR |
7813 | |
7814 | init_completion(&ioc->scsih_cmds.done); | |
078a4cc1 | 7815 | ioc->put_smid_default(ioc, smid); |
f92363d1 SR |
7816 | wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ); |
7817 | ||
7818 | if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) { | |
b3fe7efd SR |
7819 | mpt3sas_check_cmd_timeout(ioc, |
7820 | ioc->scsih_cmds.status, mpi_request, | |
7821 | sizeof(Mpi2RaidActionRequest_t)/4, issue_reset); | |
f92363d1 SR |
7822 | rc = -EFAULT; |
7823 | goto out; | |
7824 | } | |
7825 | ||
7826 | if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) { | |
7827 | ||
7828 | mpi_reply = ioc->scsih_cmds.reply; | |
7829 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); | |
7830 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) | |
7831 | log_info = le32_to_cpu(mpi_reply->IOCLogInfo); | |
7832 | else | |
7833 | log_info = 0; | |
7834 | ioc_status &= MPI2_IOCSTATUS_MASK; | |
7835 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
919d8a3f JP |
7836 | dewtprintk(ioc, |
7837 | ioc_info(ioc, "IR RAID_ACTION: failed: ioc_status(0x%04x), loginfo(0x%08x)!!!\n", | |
7838 | ioc_status, log_info)); | |
f92363d1 SR |
7839 | rc = -EFAULT; |
7840 | } else | |
919d8a3f JP |
7841 | dewtprintk(ioc, |
7842 | ioc_info(ioc, "IR RAID_ACTION: completed successfully\n")); | |
f92363d1 SR |
7843 | } |
7844 | ||
7845 | out: | |
7846 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
7847 | mutex_unlock(&ioc->scsih_cmds.mutex); | |
7848 | ||
7849 | if (issue_reset) | |
98c56ad3 | 7850 | mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
f92363d1 SR |
7851 | return rc; |
7852 | } | |
7853 | ||
7854 | /** | |
7855 | * _scsih_reprobe_lun - reprobing lun | |
7856 | * @sdev: scsi device struct | |
7857 | * @no_uld_attach: sdev->no_uld_attach flag setting | |
7858 | * | |
7859 | **/ | |
7860 | static void | |
7861 | _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach) | |
7862 | { | |
f92363d1 SR |
7863 | sdev->no_uld_attach = no_uld_attach ? 1 : 0; |
7864 | sdev_printk(KERN_INFO, sdev, "%s raid component\n", | |
6c7abffc | 7865 | sdev->no_uld_attach ? "hiding" : "exposing"); |
8bbb1cf6 | 7866 | WARN_ON(scsi_device_reprobe(sdev)); |
f92363d1 SR |
7867 | } |
7868 | ||
7869 | /** | |
7870 | * _scsih_sas_volume_add - add new volume | |
7871 | * @ioc: per adapter object | |
7872 | * @element: IR config element data | |
7873 | * Context: user. | |
f92363d1 SR |
7874 | */ |
7875 | static void | |
7876 | _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc, | |
7877 | Mpi2EventIrConfigElement_t *element) | |
7878 | { | |
7879 | struct _raid_device *raid_device; | |
7880 | unsigned long flags; | |
7881 | u64 wwid; | |
7882 | u16 handle = le16_to_cpu(element->VolDevHandle); | |
7883 | int rc; | |
7884 | ||
7885 | mpt3sas_config_get_volume_wwid(ioc, handle, &wwid); | |
7886 | if (!wwid) { | |
919d8a3f JP |
7887 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
7888 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
7889 | return; |
7890 | } | |
7891 | ||
7892 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
7893 | raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid); | |
7894 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
7895 | ||
7896 | if (raid_device) | |
7897 | return; | |
7898 | ||
7899 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); | |
7900 | if (!raid_device) { | |
919d8a3f JP |
7901 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
7902 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
7903 | return; |
7904 | } | |
7905 | ||
7906 | raid_device->id = ioc->sas_id++; | |
7907 | raid_device->channel = RAID_CHANNEL; | |
7908 | raid_device->handle = handle; | |
7909 | raid_device->wwid = wwid; | |
7910 | _scsih_raid_device_add(ioc, raid_device); | |
7911 | if (!ioc->wait_for_discovery_to_complete) { | |
7912 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
7913 | raid_device->id, 0); | |
7914 | if (rc) | |
7915 | _scsih_raid_device_remove(ioc, raid_device); | |
7916 | } else { | |
7917 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
7918 | _scsih_determine_boot_device(ioc, raid_device, 1); | |
7919 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
7920 | } | |
7921 | } | |
7922 | ||
7923 | /** | |
7924 | * _scsih_sas_volume_delete - delete volume | |
7925 | * @ioc: per adapter object | |
7926 | * @handle: volume device handle | |
7927 | * Context: user. | |
f92363d1 SR |
7928 | */ |
7929 | static void | |
7930 | _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
7931 | { | |
7932 | struct _raid_device *raid_device; | |
7933 | unsigned long flags; | |
7934 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
7935 | struct scsi_target *starget = NULL; | |
7936 | ||
7937 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
c84b06a4 | 7938 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
7939 | if (raid_device) { |
7940 | if (raid_device->starget) { | |
7941 | starget = raid_device->starget; | |
7942 | sas_target_priv_data = starget->hostdata; | |
7943 | sas_target_priv_data->deleted = 1; | |
7944 | } | |
919d8a3f JP |
7945 | ioc_info(ioc, "removing handle(0x%04x), wwid(0x%016llx)\n", |
7946 | raid_device->handle, (u64)raid_device->wwid); | |
f92363d1 SR |
7947 | list_del(&raid_device->list); |
7948 | kfree(raid_device); | |
7949 | } | |
7950 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
7951 | if (starget) | |
7952 | scsi_remove_target(&starget->dev); | |
7953 | } | |
7954 | ||
7955 | /** | |
7956 | * _scsih_sas_pd_expose - expose pd component to /dev/sdX | |
7957 | * @ioc: per adapter object | |
7958 | * @element: IR config element data | |
7959 | * Context: user. | |
f92363d1 SR |
7960 | */ |
7961 | static void | |
7962 | _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc, | |
7963 | Mpi2EventIrConfigElement_t *element) | |
7964 | { | |
7965 | struct _sas_device *sas_device; | |
7966 | struct scsi_target *starget = NULL; | |
7967 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
7968 | unsigned long flags; | |
7969 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | |
7970 | ||
7971 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 | 7972 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
7973 | if (sas_device) { |
7974 | sas_device->volume_handle = 0; | |
7975 | sas_device->volume_wwid = 0; | |
7976 | clear_bit(handle, ioc->pd_handles); | |
7977 | if (sas_device->starget && sas_device->starget->hostdata) { | |
7978 | starget = sas_device->starget; | |
7979 | sas_target_priv_data = starget->hostdata; | |
7980 | sas_target_priv_data->flags &= | |
7981 | ~MPT_TARGET_FLAGS_RAID_COMPONENT; | |
7982 | } | |
7983 | } | |
7984 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
7985 | if (!sas_device) | |
7986 | return; | |
7987 | ||
7988 | /* exposing raid component */ | |
7989 | if (starget) | |
7990 | starget_for_each_device(starget, NULL, _scsih_reprobe_lun); | |
d1cb5e49 SR |
7991 | |
7992 | sas_device_put(sas_device); | |
f92363d1 SR |
7993 | } |
7994 | ||
7995 | /** | |
7996 | * _scsih_sas_pd_hide - hide pd component from /dev/sdX | |
7997 | * @ioc: per adapter object | |
7998 | * @element: IR config element data | |
7999 | * Context: user. | |
f92363d1 SR |
8000 | */ |
8001 | static void | |
8002 | _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc, | |
8003 | Mpi2EventIrConfigElement_t *element) | |
8004 | { | |
8005 | struct _sas_device *sas_device; | |
8006 | struct scsi_target *starget = NULL; | |
8007 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
8008 | unsigned long flags; | |
8009 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | |
8010 | u16 volume_handle = 0; | |
8011 | u64 volume_wwid = 0; | |
8012 | ||
8013 | mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle); | |
8014 | if (volume_handle) | |
8015 | mpt3sas_config_get_volume_wwid(ioc, volume_handle, | |
8016 | &volume_wwid); | |
8017 | ||
8018 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 | 8019 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
8020 | if (sas_device) { |
8021 | set_bit(handle, ioc->pd_handles); | |
8022 | if (sas_device->starget && sas_device->starget->hostdata) { | |
8023 | starget = sas_device->starget; | |
8024 | sas_target_priv_data = starget->hostdata; | |
8025 | sas_target_priv_data->flags |= | |
8026 | MPT_TARGET_FLAGS_RAID_COMPONENT; | |
8027 | sas_device->volume_handle = volume_handle; | |
8028 | sas_device->volume_wwid = volume_wwid; | |
8029 | } | |
8030 | } | |
8031 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
8032 | if (!sas_device) | |
8033 | return; | |
8034 | ||
8035 | /* hiding raid component */ | |
8036 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); | |
c84b06a4 | 8037 | |
f92363d1 SR |
8038 | if (starget) |
8039 | starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun); | |
d1cb5e49 SR |
8040 | |
8041 | sas_device_put(sas_device); | |
f92363d1 SR |
8042 | } |
8043 | ||
8044 | /** | |
8045 | * _scsih_sas_pd_delete - delete pd component | |
8046 | * @ioc: per adapter object | |
8047 | * @element: IR config element data | |
8048 | * Context: user. | |
f92363d1 SR |
8049 | */ |
8050 | static void | |
8051 | _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc, | |
8052 | Mpi2EventIrConfigElement_t *element) | |
8053 | { | |
8054 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | |
8055 | ||
8056 | _scsih_device_remove_by_handle(ioc, handle); | |
8057 | } | |
8058 | ||
8059 | /** | |
8060 | * _scsih_sas_pd_add - remove pd component | |
8061 | * @ioc: per adapter object | |
8062 | * @element: IR config element data | |
8063 | * Context: user. | |
f92363d1 SR |
8064 | */ |
8065 | static void | |
8066 | _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc, | |
8067 | Mpi2EventIrConfigElement_t *element) | |
8068 | { | |
8069 | struct _sas_device *sas_device; | |
f92363d1 SR |
8070 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
8071 | Mpi2ConfigReply_t mpi_reply; | |
8072 | Mpi2SasDevicePage0_t sas_device_pg0; | |
8073 | u32 ioc_status; | |
8074 | u64 sas_address; | |
8075 | u16 parent_handle; | |
8076 | ||
8077 | set_bit(handle, ioc->pd_handles); | |
8078 | ||
d1cb5e49 | 8079 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
8080 | if (sas_device) { |
8081 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); | |
d1cb5e49 | 8082 | sas_device_put(sas_device); |
f92363d1 SR |
8083 | return; |
8084 | } | |
8085 | ||
8086 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
8087 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
919d8a3f JP |
8088 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
8089 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
8090 | return; |
8091 | } | |
8092 | ||
8093 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8094 | MPI2_IOCSTATUS_MASK; | |
8095 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
919d8a3f JP |
8096 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
8097 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
8098 | return; |
8099 | } | |
8100 | ||
8101 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | |
8102 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) | |
8103 | mpt3sas_transport_update_links(ioc, sas_address, handle, | |
8104 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | |
8105 | ||
8106 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); | |
8107 | _scsih_add_device(ioc, handle, 0, 1); | |
8108 | } | |
8109 | ||
f92363d1 SR |
8110 | /** |
8111 | * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events | |
8112 | * @ioc: per adapter object | |
8113 | * @event_data: event data payload | |
8114 | * Context: user. | |
f92363d1 SR |
8115 | */ |
8116 | static void | |
8117 | _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
8118 | Mpi2EventDataIrConfigChangeList_t *event_data) | |
8119 | { | |
8120 | Mpi2EventIrConfigElement_t *element; | |
8121 | u8 element_type; | |
8122 | int i; | |
8123 | char *reason_str = NULL, *element_str = NULL; | |
8124 | ||
8125 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
8126 | ||
919d8a3f JP |
8127 | ioc_info(ioc, "raid config change: (%s), elements(%d)\n", |
8128 | le32_to_cpu(event_data->Flags) & MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG ? | |
8129 | "foreign" : "native", | |
8130 | event_data->NumElements); | |
f92363d1 SR |
8131 | for (i = 0; i < event_data->NumElements; i++, element++) { |
8132 | switch (element->ReasonCode) { | |
8133 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: | |
8134 | reason_str = "add"; | |
8135 | break; | |
8136 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: | |
8137 | reason_str = "remove"; | |
8138 | break; | |
8139 | case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE: | |
8140 | reason_str = "no change"; | |
8141 | break; | |
8142 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: | |
8143 | reason_str = "hide"; | |
8144 | break; | |
8145 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: | |
8146 | reason_str = "unhide"; | |
8147 | break; | |
8148 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: | |
8149 | reason_str = "volume_created"; | |
8150 | break; | |
8151 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: | |
8152 | reason_str = "volume_deleted"; | |
8153 | break; | |
8154 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: | |
8155 | reason_str = "pd_created"; | |
8156 | break; | |
8157 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: | |
8158 | reason_str = "pd_deleted"; | |
8159 | break; | |
8160 | default: | |
8161 | reason_str = "unknown reason"; | |
8162 | break; | |
8163 | } | |
8164 | element_type = le16_to_cpu(element->ElementFlags) & | |
8165 | MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK; | |
8166 | switch (element_type) { | |
8167 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT: | |
8168 | element_str = "volume"; | |
8169 | break; | |
8170 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT: | |
8171 | element_str = "phys disk"; | |
8172 | break; | |
8173 | case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT: | |
8174 | element_str = "hot spare"; | |
8175 | break; | |
8176 | default: | |
8177 | element_str = "unknown element"; | |
8178 | break; | |
8179 | } | |
8180 | pr_info("\t(%s:%s), vol handle(0x%04x), " \ | |
8181 | "pd handle(0x%04x), pd num(0x%02x)\n", element_str, | |
8182 | reason_str, le16_to_cpu(element->VolDevHandle), | |
8183 | le16_to_cpu(element->PhysDiskDevHandle), | |
8184 | element->PhysDiskNum); | |
8185 | } | |
8186 | } | |
f92363d1 SR |
8187 | |
8188 | /** | |
8189 | * _scsih_sas_ir_config_change_event - handle ir configuration change events | |
8190 | * @ioc: per adapter object | |
8191 | * @fw_event: The fw_event_work object | |
8192 | * Context: user. | |
f92363d1 SR |
8193 | */ |
8194 | static void | |
8195 | _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc, | |
8196 | struct fw_event_work *fw_event) | |
8197 | { | |
8198 | Mpi2EventIrConfigElement_t *element; | |
8199 | int i; | |
8200 | u8 foreign_config; | |
35b62362 JL |
8201 | Mpi2EventDataIrConfigChangeList_t *event_data = |
8202 | (Mpi2EventDataIrConfigChangeList_t *) | |
8203 | fw_event->event_data; | |
f92363d1 | 8204 | |
7786ab6a SR |
8205 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) && |
8206 | (!ioc->hide_ir_msg)) | |
f92363d1 SR |
8207 | _scsih_sas_ir_config_change_event_debug(ioc, event_data); |
8208 | ||
f92363d1 SR |
8209 | foreign_config = (le32_to_cpu(event_data->Flags) & |
8210 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0; | |
8211 | ||
8212 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
c84b06a4 SR |
8213 | if (ioc->shost_recovery && |
8214 | ioc->hba_mpi_version_belonged != MPI2_VERSION) { | |
f92363d1 SR |
8215 | for (i = 0; i < event_data->NumElements; i++, element++) { |
8216 | if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE) | |
8217 | _scsih_ir_fastpath(ioc, | |
8218 | le16_to_cpu(element->PhysDiskDevHandle), | |
8219 | element->PhysDiskNum); | |
8220 | } | |
8221 | return; | |
8222 | } | |
7786ab6a | 8223 | |
f92363d1 SR |
8224 | for (i = 0; i < event_data->NumElements; i++, element++) { |
8225 | ||
8226 | switch (element->ReasonCode) { | |
8227 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: | |
8228 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: | |
8229 | if (!foreign_config) | |
8230 | _scsih_sas_volume_add(ioc, element); | |
8231 | break; | |
8232 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: | |
8233 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: | |
8234 | if (!foreign_config) | |
8235 | _scsih_sas_volume_delete(ioc, | |
8236 | le16_to_cpu(element->VolDevHandle)); | |
8237 | break; | |
8238 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: | |
7786ab6a SR |
8239 | if (!ioc->is_warpdrive) |
8240 | _scsih_sas_pd_hide(ioc, element); | |
f92363d1 SR |
8241 | break; |
8242 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: | |
7786ab6a SR |
8243 | if (!ioc->is_warpdrive) |
8244 | _scsih_sas_pd_expose(ioc, element); | |
f92363d1 SR |
8245 | break; |
8246 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: | |
7786ab6a SR |
8247 | if (!ioc->is_warpdrive) |
8248 | _scsih_sas_pd_add(ioc, element); | |
f92363d1 SR |
8249 | break; |
8250 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: | |
7786ab6a SR |
8251 | if (!ioc->is_warpdrive) |
8252 | _scsih_sas_pd_delete(ioc, element); | |
f92363d1 SR |
8253 | break; |
8254 | } | |
8255 | } | |
8256 | } | |
8257 | ||
8258 | /** | |
8259 | * _scsih_sas_ir_volume_event - IR volume event | |
8260 | * @ioc: per adapter object | |
8261 | * @fw_event: The fw_event_work object | |
8262 | * Context: user. | |
f92363d1 SR |
8263 | */ |
8264 | static void | |
8265 | _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc, | |
8266 | struct fw_event_work *fw_event) | |
8267 | { | |
8268 | u64 wwid; | |
8269 | unsigned long flags; | |
8270 | struct _raid_device *raid_device; | |
8271 | u16 handle; | |
8272 | u32 state; | |
8273 | int rc; | |
35b62362 JL |
8274 | Mpi2EventDataIrVolume_t *event_data = |
8275 | (Mpi2EventDataIrVolume_t *) fw_event->event_data; | |
f92363d1 SR |
8276 | |
8277 | if (ioc->shost_recovery) | |
8278 | return; | |
8279 | ||
8280 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) | |
8281 | return; | |
8282 | ||
8283 | handle = le16_to_cpu(event_data->VolDevHandle); | |
8284 | state = le32_to_cpu(event_data->NewValue); | |
7786ab6a | 8285 | if (!ioc->hide_ir_msg) |
919d8a3f JP |
8286 | dewtprintk(ioc, |
8287 | ioc_info(ioc, "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n", | |
8288 | __func__, handle, | |
8289 | le32_to_cpu(event_data->PreviousValue), | |
8290 | state)); | |
f92363d1 SR |
8291 | switch (state) { |
8292 | case MPI2_RAID_VOL_STATE_MISSING: | |
8293 | case MPI2_RAID_VOL_STATE_FAILED: | |
8294 | _scsih_sas_volume_delete(ioc, handle); | |
8295 | break; | |
8296 | ||
8297 | case MPI2_RAID_VOL_STATE_ONLINE: | |
8298 | case MPI2_RAID_VOL_STATE_DEGRADED: | |
8299 | case MPI2_RAID_VOL_STATE_OPTIMAL: | |
8300 | ||
8301 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
c84b06a4 | 8302 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
8303 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
8304 | ||
8305 | if (raid_device) | |
8306 | break; | |
8307 | ||
8308 | mpt3sas_config_get_volume_wwid(ioc, handle, &wwid); | |
8309 | if (!wwid) { | |
919d8a3f JP |
8310 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
8311 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
8312 | break; |
8313 | } | |
8314 | ||
8315 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); | |
8316 | if (!raid_device) { | |
919d8a3f JP |
8317 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
8318 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
8319 | break; |
8320 | } | |
8321 | ||
8322 | raid_device->id = ioc->sas_id++; | |
8323 | raid_device->channel = RAID_CHANNEL; | |
8324 | raid_device->handle = handle; | |
8325 | raid_device->wwid = wwid; | |
8326 | _scsih_raid_device_add(ioc, raid_device); | |
8327 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
8328 | raid_device->id, 0); | |
8329 | if (rc) | |
8330 | _scsih_raid_device_remove(ioc, raid_device); | |
8331 | break; | |
8332 | ||
8333 | case MPI2_RAID_VOL_STATE_INITIALIZING: | |
8334 | default: | |
8335 | break; | |
8336 | } | |
8337 | } | |
8338 | ||
8339 | /** | |
8340 | * _scsih_sas_ir_physical_disk_event - PD event | |
8341 | * @ioc: per adapter object | |
8342 | * @fw_event: The fw_event_work object | |
8343 | * Context: user. | |
f92363d1 SR |
8344 | */ |
8345 | static void | |
8346 | _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc, | |
8347 | struct fw_event_work *fw_event) | |
8348 | { | |
8349 | u16 handle, parent_handle; | |
8350 | u32 state; | |
8351 | struct _sas_device *sas_device; | |
f92363d1 SR |
8352 | Mpi2ConfigReply_t mpi_reply; |
8353 | Mpi2SasDevicePage0_t sas_device_pg0; | |
8354 | u32 ioc_status; | |
35b62362 JL |
8355 | Mpi2EventDataIrPhysicalDisk_t *event_data = |
8356 | (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data; | |
f92363d1 SR |
8357 | u64 sas_address; |
8358 | ||
8359 | if (ioc->shost_recovery) | |
8360 | return; | |
8361 | ||
8362 | if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED) | |
8363 | return; | |
8364 | ||
8365 | handle = le16_to_cpu(event_data->PhysDiskDevHandle); | |
8366 | state = le32_to_cpu(event_data->NewValue); | |
8367 | ||
7786ab6a | 8368 | if (!ioc->hide_ir_msg) |
919d8a3f JP |
8369 | dewtprintk(ioc, |
8370 | ioc_info(ioc, "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n", | |
8371 | __func__, handle, | |
8372 | le32_to_cpu(event_data->PreviousValue), | |
8373 | state)); | |
7786ab6a | 8374 | |
f92363d1 SR |
8375 | switch (state) { |
8376 | case MPI2_RAID_PD_STATE_ONLINE: | |
8377 | case MPI2_RAID_PD_STATE_DEGRADED: | |
8378 | case MPI2_RAID_PD_STATE_REBUILDING: | |
8379 | case MPI2_RAID_PD_STATE_OPTIMAL: | |
8380 | case MPI2_RAID_PD_STATE_HOT_SPARE: | |
8381 | ||
7786ab6a SR |
8382 | if (!ioc->is_warpdrive) |
8383 | set_bit(handle, ioc->pd_handles); | |
f92363d1 | 8384 | |
d1cb5e49 SR |
8385 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
8386 | if (sas_device) { | |
8387 | sas_device_put(sas_device); | |
f92363d1 | 8388 | return; |
d1cb5e49 | 8389 | } |
f92363d1 SR |
8390 | |
8391 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
8392 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | |
8393 | handle))) { | |
919d8a3f JP |
8394 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
8395 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
8396 | return; |
8397 | } | |
8398 | ||
8399 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8400 | MPI2_IOCSTATUS_MASK; | |
8401 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
919d8a3f JP |
8402 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
8403 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
8404 | return; |
8405 | } | |
8406 | ||
8407 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | |
8408 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) | |
8409 | mpt3sas_transport_update_links(ioc, sas_address, handle, | |
8410 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | |
8411 | ||
8412 | _scsih_add_device(ioc, handle, 0, 1); | |
8413 | ||
8414 | break; | |
8415 | ||
8416 | case MPI2_RAID_PD_STATE_OFFLINE: | |
8417 | case MPI2_RAID_PD_STATE_NOT_CONFIGURED: | |
8418 | case MPI2_RAID_PD_STATE_NOT_COMPATIBLE: | |
8419 | default: | |
8420 | break; | |
8421 | } | |
8422 | } | |
8423 | ||
f92363d1 SR |
8424 | /** |
8425 | * _scsih_sas_ir_operation_status_event_debug - debug for IR op event | |
8426 | * @ioc: per adapter object | |
8427 | * @event_data: event data payload | |
8428 | * Context: user. | |
f92363d1 SR |
8429 | */ |
8430 | static void | |
8431 | _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
8432 | Mpi2EventDataIrOperationStatus_t *event_data) | |
8433 | { | |
8434 | char *reason_str = NULL; | |
8435 | ||
8436 | switch (event_data->RAIDOperation) { | |
8437 | case MPI2_EVENT_IR_RAIDOP_RESYNC: | |
8438 | reason_str = "resync"; | |
8439 | break; | |
8440 | case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION: | |
8441 | reason_str = "online capacity expansion"; | |
8442 | break; | |
8443 | case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK: | |
8444 | reason_str = "consistency check"; | |
8445 | break; | |
8446 | case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT: | |
8447 | reason_str = "background init"; | |
8448 | break; | |
8449 | case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT: | |
8450 | reason_str = "make data consistent"; | |
8451 | break; | |
8452 | } | |
8453 | ||
8454 | if (!reason_str) | |
8455 | return; | |
8456 | ||
919d8a3f JP |
8457 | ioc_info(ioc, "raid operational status: (%s)\thandle(0x%04x), percent complete(%d)\n", |
8458 | reason_str, | |
8459 | le16_to_cpu(event_data->VolDevHandle), | |
8460 | event_data->PercentComplete); | |
f92363d1 | 8461 | } |
f92363d1 SR |
8462 | |
8463 | /** | |
8464 | * _scsih_sas_ir_operation_status_event - handle RAID operation events | |
8465 | * @ioc: per adapter object | |
8466 | * @fw_event: The fw_event_work object | |
8467 | * Context: user. | |
f92363d1 SR |
8468 | */ |
8469 | static void | |
8470 | _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc, | |
8471 | struct fw_event_work *fw_event) | |
8472 | { | |
35b62362 JL |
8473 | Mpi2EventDataIrOperationStatus_t *event_data = |
8474 | (Mpi2EventDataIrOperationStatus_t *) | |
8475 | fw_event->event_data; | |
f92363d1 SR |
8476 | static struct _raid_device *raid_device; |
8477 | unsigned long flags; | |
8478 | u16 handle; | |
8479 | ||
7786ab6a SR |
8480 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) && |
8481 | (!ioc->hide_ir_msg)) | |
f92363d1 SR |
8482 | _scsih_sas_ir_operation_status_event_debug(ioc, |
8483 | event_data); | |
f92363d1 SR |
8484 | |
8485 | /* code added for raid transport support */ | |
8486 | if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) { | |
8487 | ||
8488 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
8489 | handle = le16_to_cpu(event_data->VolDevHandle); | |
c84b06a4 | 8490 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
8491 | if (raid_device) |
8492 | raid_device->percent_complete = | |
8493 | event_data->PercentComplete; | |
8494 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
8495 | } | |
8496 | } | |
8497 | ||
8498 | /** | |
8499 | * _scsih_prep_device_scan - initialize parameters prior to device scan | |
8500 | * @ioc: per adapter object | |
8501 | * | |
8502 | * Set the deleted flag prior to device scan. If the device is found during | |
8503 | * the scan, then we clear the deleted flag. | |
8504 | */ | |
8505 | static void | |
8506 | _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc) | |
8507 | { | |
8508 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
8509 | struct scsi_device *sdev; | |
8510 | ||
8511 | shost_for_each_device(sdev, ioc->shost) { | |
8512 | sas_device_priv_data = sdev->hostdata; | |
8513 | if (sas_device_priv_data && sas_device_priv_data->sas_target) | |
8514 | sas_device_priv_data->sas_target->deleted = 1; | |
8515 | } | |
8516 | } | |
8517 | ||
8518 | /** | |
8519 | * _scsih_mark_responding_sas_device - mark a sas_devices as responding | |
8520 | * @ioc: per adapter object | |
e6d45e3e | 8521 | * @sas_device_pg0: SAS Device page 0 |
f92363d1 SR |
8522 | * |
8523 | * After host reset, find out whether devices are still responding. | |
8524 | * Used in _scsih_remove_unresponsive_sas_devices. | |
f92363d1 SR |
8525 | */ |
8526 | static void | |
e6d45e3e SR |
8527 | _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc, |
8528 | Mpi2SasDevicePage0_t *sas_device_pg0) | |
f92363d1 SR |
8529 | { |
8530 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; | |
8531 | struct scsi_target *starget; | |
aba5a85c | 8532 | struct _sas_device *sas_device = NULL; |
22a923c3 | 8533 | struct _enclosure_node *enclosure_dev = NULL; |
f92363d1 SR |
8534 | unsigned long flags; |
8535 | ||
22a923c3 C |
8536 | if (sas_device_pg0->EnclosureHandle) { |
8537 | enclosure_dev = | |
8538 | mpt3sas_scsih_enclosure_find_by_handle(ioc, | |
8539 | le16_to_cpu(sas_device_pg0->EnclosureHandle)); | |
8540 | if (enclosure_dev == NULL) | |
919d8a3f JP |
8541 | ioc_info(ioc, "Enclosure handle(0x%04x) doesn't match with enclosure device!\n", |
8542 | sas_device_pg0->EnclosureHandle); | |
22a923c3 | 8543 | } |
f92363d1 SR |
8544 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
8545 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) { | |
cf6bf971 C |
8546 | if ((sas_device->sas_address == le64_to_cpu( |
8547 | sas_device_pg0->SASAddress)) && (sas_device->slot == | |
8548 | le16_to_cpu(sas_device_pg0->Slot))) { | |
f92363d1 SR |
8549 | sas_device->responding = 1; |
8550 | starget = sas_device->starget; | |
8551 | if (starget && starget->hostdata) { | |
8552 | sas_target_priv_data = starget->hostdata; | |
8553 | sas_target_priv_data->tm_busy = 0; | |
8554 | sas_target_priv_data->deleted = 0; | |
8555 | } else | |
8556 | sas_target_priv_data = NULL; | |
e6d45e3e | 8557 | if (starget) { |
f92363d1 | 8558 | starget_printk(KERN_INFO, starget, |
e6d45e3e | 8559 | "handle(0x%04x), sas_addr(0x%016llx)\n", |
cf6bf971 | 8560 | le16_to_cpu(sas_device_pg0->DevHandle), |
f92363d1 | 8561 | (unsigned long long) |
e6d45e3e SR |
8562 | sas_device->sas_address); |
8563 | ||
8564 | if (sas_device->enclosure_handle != 0) | |
8565 | starget_printk(KERN_INFO, starget, | |
8566 | "enclosure logical id(0x%016llx)," | |
8567 | " slot(%d)\n", | |
8568 | (unsigned long long) | |
8569 | sas_device->enclosure_logical_id, | |
8570 | sas_device->slot); | |
8571 | } | |
cf6bf971 | 8572 | if (le16_to_cpu(sas_device_pg0->Flags) & |
e6d45e3e SR |
8573 | MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) { |
8574 | sas_device->enclosure_level = | |
aa53bb89 | 8575 | sas_device_pg0->EnclosureLevel; |
e6d45e3e SR |
8576 | memcpy(&sas_device->connector_name[0], |
8577 | &sas_device_pg0->ConnectorName[0], 4); | |
8578 | } else { | |
8579 | sas_device->enclosure_level = 0; | |
8580 | sas_device->connector_name[0] = '\0'; | |
8581 | } | |
8582 | ||
22a923c3 C |
8583 | sas_device->enclosure_handle = |
8584 | le16_to_cpu(sas_device_pg0->EnclosureHandle); | |
8585 | sas_device->is_chassis_slot_valid = 0; | |
8586 | if (enclosure_dev) { | |
8587 | sas_device->enclosure_logical_id = le64_to_cpu( | |
8588 | enclosure_dev->pg0.EnclosureLogicalID); | |
8589 | if (le16_to_cpu(enclosure_dev->pg0.Flags) & | |
8590 | MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) { | |
8591 | sas_device->is_chassis_slot_valid = 1; | |
8592 | sas_device->chassis_slot = | |
8593 | enclosure_dev->pg0.ChassisSlot; | |
8594 | } | |
8595 | } | |
75888956 | 8596 | |
cf6bf971 C |
8597 | if (sas_device->handle == le16_to_cpu( |
8598 | sas_device_pg0->DevHandle)) | |
f92363d1 SR |
8599 | goto out; |
8600 | pr_info("\thandle changed from(0x%04x)!!!\n", | |
8601 | sas_device->handle); | |
cf6bf971 C |
8602 | sas_device->handle = le16_to_cpu( |
8603 | sas_device_pg0->DevHandle); | |
f92363d1 | 8604 | if (sas_target_priv_data) |
e6d45e3e | 8605 | sas_target_priv_data->handle = |
cf6bf971 | 8606 | le16_to_cpu(sas_device_pg0->DevHandle); |
f92363d1 SR |
8607 | goto out; |
8608 | } | |
8609 | } | |
8610 | out: | |
8611 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
8612 | } | |
8613 | ||
22a923c3 C |
8614 | /** |
8615 | * _scsih_create_enclosure_list_after_reset - Free Existing list, | |
8616 | * And create enclosure list by scanning all Enclosure Page(0)s | |
8617 | * @ioc: per adapter object | |
22a923c3 C |
8618 | */ |
8619 | static void | |
8620 | _scsih_create_enclosure_list_after_reset(struct MPT3SAS_ADAPTER *ioc) | |
8621 | { | |
8622 | struct _enclosure_node *enclosure_dev; | |
8623 | Mpi2ConfigReply_t mpi_reply; | |
8624 | u16 enclosure_handle; | |
8625 | int rc; | |
8626 | ||
8627 | /* Free existing enclosure list */ | |
8628 | mpt3sas_free_enclosure_list(ioc); | |
8629 | ||
8630 | /* Re constructing enclosure list after reset*/ | |
8631 | enclosure_handle = 0xFFFF; | |
8632 | do { | |
8633 | enclosure_dev = | |
8634 | kzalloc(sizeof(struct _enclosure_node), GFP_KERNEL); | |
8635 | if (!enclosure_dev) { | |
919d8a3f | 8636 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
22a923c3 C |
8637 | __FILE__, __LINE__, __func__); |
8638 | return; | |
8639 | } | |
8640 | rc = mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
8641 | &enclosure_dev->pg0, | |
8642 | MPI2_SAS_ENCLOS_PGAD_FORM_GET_NEXT_HANDLE, | |
8643 | enclosure_handle); | |
8644 | ||
8645 | if (rc || (le16_to_cpu(mpi_reply.IOCStatus) & | |
8646 | MPI2_IOCSTATUS_MASK)) { | |
8647 | kfree(enclosure_dev); | |
8648 | return; | |
8649 | } | |
8650 | list_add_tail(&enclosure_dev->list, | |
8651 | &ioc->enclosure_list); | |
8652 | enclosure_handle = | |
8653 | le16_to_cpu(enclosure_dev->pg0.EnclosureHandle); | |
8654 | } while (1); | |
8655 | } | |
8656 | ||
f92363d1 SR |
8657 | /** |
8658 | * _scsih_search_responding_sas_devices - | |
8659 | * @ioc: per adapter object | |
8660 | * | |
8661 | * After host reset, find out whether devices are still responding. | |
8662 | * If not remove. | |
f92363d1 SR |
8663 | */ |
8664 | static void | |
8665 | _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc) | |
8666 | { | |
8667 | Mpi2SasDevicePage0_t sas_device_pg0; | |
8668 | Mpi2ConfigReply_t mpi_reply; | |
8669 | u16 ioc_status; | |
8670 | u16 handle; | |
8671 | u32 device_info; | |
8672 | ||
919d8a3f | 8673 | ioc_info(ioc, "search for end-devices: start\n"); |
f92363d1 SR |
8674 | |
8675 | if (list_empty(&ioc->sas_device_list)) | |
8676 | goto out; | |
8677 | ||
8678 | handle = 0xFFFF; | |
8679 | while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
8680 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | |
8681 | handle))) { | |
8682 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8683 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 8684 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 | 8685 | break; |
cf6bf971 | 8686 | handle = le16_to_cpu(sas_device_pg0.DevHandle); |
f92363d1 SR |
8687 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
8688 | if (!(_scsih_is_end_device(device_info))) | |
8689 | continue; | |
e6d45e3e | 8690 | _scsih_mark_responding_sas_device(ioc, &sas_device_pg0); |
f92363d1 SR |
8691 | } |
8692 | ||
8693 | out: | |
919d8a3f | 8694 | ioc_info(ioc, "search for end-devices: complete\n"); |
f92363d1 SR |
8695 | } |
8696 | ||
ec051e5a SPS |
8697 | /** |
8698 | * _scsih_mark_responding_pcie_device - mark a pcie_device as responding | |
8699 | * @ioc: per adapter object | |
8700 | * @pcie_device_pg0: PCIe Device page 0 | |
8701 | * | |
8702 | * After host reset, find out whether devices are still responding. | |
8703 | * Used in _scsih_remove_unresponding_devices. | |
ec051e5a SPS |
8704 | */ |
8705 | static void | |
8706 | _scsih_mark_responding_pcie_device(struct MPT3SAS_ADAPTER *ioc, | |
8707 | Mpi26PCIeDevicePage0_t *pcie_device_pg0) | |
8708 | { | |
8709 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; | |
8710 | struct scsi_target *starget; | |
8711 | struct _pcie_device *pcie_device; | |
8712 | unsigned long flags; | |
8713 | ||
8714 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
8715 | list_for_each_entry(pcie_device, &ioc->pcie_device_list, list) { | |
cf6bf971 C |
8716 | if ((pcie_device->wwid == le64_to_cpu(pcie_device_pg0->WWID)) |
8717 | && (pcie_device->slot == le16_to_cpu( | |
8718 | pcie_device_pg0->Slot))) { | |
3c090ce3 SP |
8719 | pcie_device->access_status = |
8720 | pcie_device_pg0->AccessStatus; | |
ec051e5a SPS |
8721 | pcie_device->responding = 1; |
8722 | starget = pcie_device->starget; | |
8723 | if (starget && starget->hostdata) { | |
8724 | sas_target_priv_data = starget->hostdata; | |
8725 | sas_target_priv_data->tm_busy = 0; | |
8726 | sas_target_priv_data->deleted = 0; | |
8727 | } else | |
8728 | sas_target_priv_data = NULL; | |
8729 | if (starget) { | |
8730 | starget_printk(KERN_INFO, starget, | |
8731 | "handle(0x%04x), wwid(0x%016llx) ", | |
8732 | pcie_device->handle, | |
8733 | (unsigned long long)pcie_device->wwid); | |
8734 | if (pcie_device->enclosure_handle != 0) | |
8735 | starget_printk(KERN_INFO, starget, | |
8736 | "enclosure logical id(0x%016llx), " | |
8737 | "slot(%d)\n", | |
8738 | (unsigned long long) | |
8739 | pcie_device->enclosure_logical_id, | |
8740 | pcie_device->slot); | |
8741 | } | |
8742 | ||
8743 | if (((le32_to_cpu(pcie_device_pg0->Flags)) & | |
8744 | MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) && | |
8745 | (ioc->hba_mpi_version_belonged != MPI2_VERSION)) { | |
8746 | pcie_device->enclosure_level = | |
8747 | pcie_device_pg0->EnclosureLevel; | |
8748 | memcpy(&pcie_device->connector_name[0], | |
8749 | &pcie_device_pg0->ConnectorName[0], 4); | |
8750 | } else { | |
8751 | pcie_device->enclosure_level = 0; | |
8752 | pcie_device->connector_name[0] = '\0'; | |
8753 | } | |
8754 | ||
cf6bf971 C |
8755 | if (pcie_device->handle == le16_to_cpu( |
8756 | pcie_device_pg0->DevHandle)) | |
ec051e5a | 8757 | goto out; |
268eb498 | 8758 | pr_info("\thandle changed from(0x%04x)!!!\n", |
ec051e5a | 8759 | pcie_device->handle); |
cf6bf971 C |
8760 | pcie_device->handle = le16_to_cpu( |
8761 | pcie_device_pg0->DevHandle); | |
ec051e5a SPS |
8762 | if (sas_target_priv_data) |
8763 | sas_target_priv_data->handle = | |
cf6bf971 | 8764 | le16_to_cpu(pcie_device_pg0->DevHandle); |
ec051e5a SPS |
8765 | goto out; |
8766 | } | |
8767 | } | |
8768 | ||
8769 | out: | |
8770 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
8771 | } | |
8772 | ||
8773 | /** | |
8774 | * _scsih_search_responding_pcie_devices - | |
8775 | * @ioc: per adapter object | |
8776 | * | |
8777 | * After host reset, find out whether devices are still responding. | |
8778 | * If not remove. | |
ec051e5a SPS |
8779 | */ |
8780 | static void | |
8781 | _scsih_search_responding_pcie_devices(struct MPT3SAS_ADAPTER *ioc) | |
8782 | { | |
8783 | Mpi26PCIeDevicePage0_t pcie_device_pg0; | |
8784 | Mpi2ConfigReply_t mpi_reply; | |
8785 | u16 ioc_status; | |
8786 | u16 handle; | |
8787 | u32 device_info; | |
8788 | ||
919d8a3f | 8789 | ioc_info(ioc, "search for end-devices: start\n"); |
ec051e5a SPS |
8790 | |
8791 | if (list_empty(&ioc->pcie_device_list)) | |
8792 | goto out; | |
8793 | ||
8794 | handle = 0xFFFF; | |
8795 | while (!(mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply, | |
8796 | &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | |
8797 | handle))) { | |
8798 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8799 | MPI2_IOCSTATUS_MASK; | |
8800 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
919d8a3f JP |
8801 | ioc_info(ioc, "\tbreak from %s: ioc_status(0x%04x), loginfo(0x%08x)\n", |
8802 | __func__, ioc_status, | |
8803 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
ec051e5a SPS |
8804 | break; |
8805 | } | |
8806 | handle = le16_to_cpu(pcie_device_pg0.DevHandle); | |
8807 | device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo); | |
5bb309db | 8808 | if (!(_scsih_is_nvme_pciescsi_device(device_info))) |
ec051e5a | 8809 | continue; |
ec051e5a SPS |
8810 | _scsih_mark_responding_pcie_device(ioc, &pcie_device_pg0); |
8811 | } | |
8812 | out: | |
919d8a3f | 8813 | ioc_info(ioc, "search for PCIe end-devices: complete\n"); |
ec051e5a SPS |
8814 | } |
8815 | ||
f92363d1 SR |
8816 | /** |
8817 | * _scsih_mark_responding_raid_device - mark a raid_device as responding | |
8818 | * @ioc: per adapter object | |
8819 | * @wwid: world wide identifier for raid volume | |
8820 | * @handle: device handle | |
8821 | * | |
8822 | * After host reset, find out whether devices are still responding. | |
8823 | * Used in _scsih_remove_unresponsive_raid_devices. | |
f92363d1 SR |
8824 | */ |
8825 | static void | |
8826 | _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid, | |
8827 | u16 handle) | |
8828 | { | |
7786ab6a | 8829 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; |
f92363d1 SR |
8830 | struct scsi_target *starget; |
8831 | struct _raid_device *raid_device; | |
8832 | unsigned long flags; | |
8833 | ||
8834 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
8835 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
8836 | if (raid_device->wwid == wwid && raid_device->starget) { | |
8837 | starget = raid_device->starget; | |
8838 | if (starget && starget->hostdata) { | |
8839 | sas_target_priv_data = starget->hostdata; | |
8840 | sas_target_priv_data->deleted = 0; | |
8841 | } else | |
8842 | sas_target_priv_data = NULL; | |
8843 | raid_device->responding = 1; | |
8844 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
8845 | starget_printk(KERN_INFO, raid_device->starget, | |
8846 | "handle(0x%04x), wwid(0x%016llx)\n", handle, | |
8847 | (unsigned long long)raid_device->wwid); | |
7786ab6a | 8848 | |
7786ab6a SR |
8849 | /* |
8850 | * WARPDRIVE: The handles of the PDs might have changed | |
8851 | * across the host reset so re-initialize the | |
8852 | * required data for Direct IO | |
8853 | */ | |
c84b06a4 | 8854 | mpt3sas_init_warpdrive_properties(ioc, raid_device); |
f92363d1 SR |
8855 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
8856 | if (raid_device->handle == handle) { | |
8857 | spin_unlock_irqrestore(&ioc->raid_device_lock, | |
8858 | flags); | |
8859 | return; | |
8860 | } | |
8861 | pr_info("\thandle changed from(0x%04x)!!!\n", | |
8862 | raid_device->handle); | |
8863 | raid_device->handle = handle; | |
8864 | if (sas_target_priv_data) | |
8865 | sas_target_priv_data->handle = handle; | |
8866 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
8867 | return; | |
8868 | } | |
8869 | } | |
8870 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
8871 | } | |
8872 | ||
8873 | /** | |
8874 | * _scsih_search_responding_raid_devices - | |
8875 | * @ioc: per adapter object | |
8876 | * | |
8877 | * After host reset, find out whether devices are still responding. | |
8878 | * If not remove. | |
f92363d1 SR |
8879 | */ |
8880 | static void | |
8881 | _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc) | |
8882 | { | |
8883 | Mpi2RaidVolPage1_t volume_pg1; | |
8884 | Mpi2RaidVolPage0_t volume_pg0; | |
8885 | Mpi2RaidPhysDiskPage0_t pd_pg0; | |
8886 | Mpi2ConfigReply_t mpi_reply; | |
8887 | u16 ioc_status; | |
8888 | u16 handle; | |
8889 | u8 phys_disk_num; | |
8890 | ||
8891 | if (!ioc->ir_firmware) | |
8892 | return; | |
8893 | ||
919d8a3f | 8894 | ioc_info(ioc, "search for raid volumes: start\n"); |
f92363d1 SR |
8895 | |
8896 | if (list_empty(&ioc->raid_device_list)) | |
8897 | goto out; | |
8898 | ||
8899 | handle = 0xFFFF; | |
8900 | while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply, | |
8901 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { | |
8902 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8903 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 8904 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 SR |
8905 | break; |
8906 | handle = le16_to_cpu(volume_pg1.DevHandle); | |
8907 | ||
8908 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, | |
8909 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
8910 | sizeof(Mpi2RaidVolPage0_t))) | |
8911 | continue; | |
8912 | ||
8913 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || | |
8914 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || | |
8915 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) | |
8916 | _scsih_mark_responding_raid_device(ioc, | |
8917 | le64_to_cpu(volume_pg1.WWID), handle); | |
8918 | } | |
8919 | ||
8920 | /* refresh the pd_handles */ | |
7786ab6a | 8921 | if (!ioc->is_warpdrive) { |
f92363d1 SR |
8922 | phys_disk_num = 0xFF; |
8923 | memset(ioc->pd_handles, 0, ioc->pd_handles_sz); | |
8924 | while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | |
8925 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, | |
8926 | phys_disk_num))) { | |
8927 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8928 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 8929 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 SR |
8930 | break; |
8931 | phys_disk_num = pd_pg0.PhysDiskNum; | |
8932 | handle = le16_to_cpu(pd_pg0.DevHandle); | |
8933 | set_bit(handle, ioc->pd_handles); | |
8934 | } | |
7786ab6a | 8935 | } |
f92363d1 | 8936 | out: |
919d8a3f | 8937 | ioc_info(ioc, "search for responding raid volumes: complete\n"); |
f92363d1 SR |
8938 | } |
8939 | ||
8940 | /** | |
8941 | * _scsih_mark_responding_expander - mark a expander as responding | |
8942 | * @ioc: per adapter object | |
aba5a85c | 8943 | * @expander_pg0:SAS Expander Config Page0 |
f92363d1 SR |
8944 | * |
8945 | * After host reset, find out whether devices are still responding. | |
8946 | * Used in _scsih_remove_unresponsive_expanders. | |
f92363d1 SR |
8947 | */ |
8948 | static void | |
aba5a85c SR |
8949 | _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc, |
8950 | Mpi2ExpanderPage0_t *expander_pg0) | |
f92363d1 | 8951 | { |
aba5a85c | 8952 | struct _sas_node *sas_expander = NULL; |
f92363d1 | 8953 | unsigned long flags; |
22a923c3 C |
8954 | int i; |
8955 | struct _enclosure_node *enclosure_dev = NULL; | |
aba5a85c | 8956 | u16 handle = le16_to_cpu(expander_pg0->DevHandle); |
22a923c3 | 8957 | u16 enclosure_handle = le16_to_cpu(expander_pg0->EnclosureHandle); |
aba5a85c SR |
8958 | u64 sas_address = le64_to_cpu(expander_pg0->SASAddress); |
8959 | ||
22a923c3 C |
8960 | if (enclosure_handle) |
8961 | enclosure_dev = | |
8962 | mpt3sas_scsih_enclosure_find_by_handle(ioc, | |
8963 | enclosure_handle); | |
f92363d1 SR |
8964 | |
8965 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
8966 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { | |
8967 | if (sas_expander->sas_address != sas_address) | |
8968 | continue; | |
8969 | sas_expander->responding = 1; | |
aba5a85c | 8970 | |
22a923c3 | 8971 | if (enclosure_dev) { |
aba5a85c | 8972 | sas_expander->enclosure_logical_id = |
22a923c3 C |
8973 | le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID); |
8974 | sas_expander->enclosure_handle = | |
8975 | le16_to_cpu(expander_pg0->EnclosureHandle); | |
8976 | } | |
aba5a85c | 8977 | |
f92363d1 SR |
8978 | if (sas_expander->handle == handle) |
8979 | goto out; | |
8980 | pr_info("\texpander(0x%016llx): handle changed" \ | |
8981 | " from(0x%04x) to (0x%04x)!!!\n", | |
8982 | (unsigned long long)sas_expander->sas_address, | |
8983 | sas_expander->handle, handle); | |
8984 | sas_expander->handle = handle; | |
8985 | for (i = 0 ; i < sas_expander->num_phys ; i++) | |
8986 | sas_expander->phy[i].handle = handle; | |
8987 | goto out; | |
8988 | } | |
8989 | out: | |
8990 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
8991 | } | |
8992 | ||
8993 | /** | |
8994 | * _scsih_search_responding_expanders - | |
8995 | * @ioc: per adapter object | |
8996 | * | |
8997 | * After host reset, find out whether devices are still responding. | |
8998 | * If not remove. | |
f92363d1 SR |
8999 | */ |
9000 | static void | |
9001 | _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc) | |
9002 | { | |
9003 | Mpi2ExpanderPage0_t expander_pg0; | |
9004 | Mpi2ConfigReply_t mpi_reply; | |
9005 | u16 ioc_status; | |
9006 | u64 sas_address; | |
9007 | u16 handle; | |
9008 | ||
919d8a3f | 9009 | ioc_info(ioc, "search for expanders: start\n"); |
f92363d1 SR |
9010 | |
9011 | if (list_empty(&ioc->sas_expander_list)) | |
9012 | goto out; | |
9013 | ||
9014 | handle = 0xFFFF; | |
9015 | while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | |
9016 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { | |
9017 | ||
9018 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9019 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 9020 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 SR |
9021 | break; |
9022 | ||
9023 | handle = le16_to_cpu(expander_pg0.DevHandle); | |
9024 | sas_address = le64_to_cpu(expander_pg0.SASAddress); | |
9025 | pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n", | |
9026 | handle, | |
9027 | (unsigned long long)sas_address); | |
aba5a85c | 9028 | _scsih_mark_responding_expander(ioc, &expander_pg0); |
f92363d1 SR |
9029 | } |
9030 | ||
9031 | out: | |
919d8a3f | 9032 | ioc_info(ioc, "search for expanders: complete\n"); |
f92363d1 SR |
9033 | } |
9034 | ||
9035 | /** | |
3075ac49 | 9036 | * _scsih_remove_unresponding_devices - removing unresponding devices |
f92363d1 | 9037 | * @ioc: per adapter object |
f92363d1 SR |
9038 | */ |
9039 | static void | |
3075ac49 | 9040 | _scsih_remove_unresponding_devices(struct MPT3SAS_ADAPTER *ioc) |
f92363d1 SR |
9041 | { |
9042 | struct _sas_device *sas_device, *sas_device_next; | |
9043 | struct _sas_node *sas_expander, *sas_expander_next; | |
9044 | struct _raid_device *raid_device, *raid_device_next; | |
3075ac49 | 9045 | struct _pcie_device *pcie_device, *pcie_device_next; |
f92363d1 SR |
9046 | struct list_head tmp_list; |
9047 | unsigned long flags; | |
d1cb5e49 | 9048 | LIST_HEAD(head); |
f92363d1 | 9049 | |
919d8a3f | 9050 | ioc_info(ioc, "removing unresponding devices: start\n"); |
f92363d1 SR |
9051 | |
9052 | /* removing unresponding end devices */ | |
919d8a3f | 9053 | ioc_info(ioc, "removing unresponding devices: end-devices\n"); |
d1cb5e49 SR |
9054 | /* |
9055 | * Iterate, pulling off devices marked as non-responding. We become the | |
9056 | * owner for the reference the list had on any object we prune. | |
9057 | */ | |
9058 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
f92363d1 SR |
9059 | list_for_each_entry_safe(sas_device, sas_device_next, |
9060 | &ioc->sas_device_list, list) { | |
9061 | if (!sas_device->responding) | |
d1cb5e49 | 9062 | list_move_tail(&sas_device->list, &head); |
f92363d1 SR |
9063 | else |
9064 | sas_device->responding = 0; | |
9065 | } | |
d1cb5e49 SR |
9066 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
9067 | ||
9068 | /* | |
9069 | * Now, uninitialize and remove the unresponding devices we pruned. | |
9070 | */ | |
9071 | list_for_each_entry_safe(sas_device, sas_device_next, &head, list) { | |
9072 | _scsih_remove_device(ioc, sas_device); | |
9073 | list_del_init(&sas_device->list); | |
9074 | sas_device_put(sas_device); | |
9075 | } | |
f92363d1 | 9076 | |
919d8a3f | 9077 | ioc_info(ioc, "Removing unresponding devices: pcie end-devices\n"); |
3075ac49 SPS |
9078 | INIT_LIST_HEAD(&head); |
9079 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
9080 | list_for_each_entry_safe(pcie_device, pcie_device_next, | |
9081 | &ioc->pcie_device_list, list) { | |
9082 | if (!pcie_device->responding) | |
9083 | list_move_tail(&pcie_device->list, &head); | |
9084 | else | |
9085 | pcie_device->responding = 0; | |
9086 | } | |
9087 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
9088 | ||
9089 | list_for_each_entry_safe(pcie_device, pcie_device_next, &head, list) { | |
9090 | _scsih_pcie_device_remove_from_sml(ioc, pcie_device); | |
9091 | list_del_init(&pcie_device->list); | |
9092 | pcie_device_put(pcie_device); | |
9093 | } | |
9094 | ||
f92363d1 SR |
9095 | /* removing unresponding volumes */ |
9096 | if (ioc->ir_firmware) { | |
919d8a3f | 9097 | ioc_info(ioc, "removing unresponding devices: volumes\n"); |
f92363d1 SR |
9098 | list_for_each_entry_safe(raid_device, raid_device_next, |
9099 | &ioc->raid_device_list, list) { | |
9100 | if (!raid_device->responding) | |
9101 | _scsih_sas_volume_delete(ioc, | |
9102 | raid_device->handle); | |
9103 | else | |
9104 | raid_device->responding = 0; | |
9105 | } | |
9106 | } | |
9107 | ||
9108 | /* removing unresponding expanders */ | |
919d8a3f | 9109 | ioc_info(ioc, "removing unresponding devices: expanders\n"); |
f92363d1 SR |
9110 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
9111 | INIT_LIST_HEAD(&tmp_list); | |
9112 | list_for_each_entry_safe(sas_expander, sas_expander_next, | |
9113 | &ioc->sas_expander_list, list) { | |
9114 | if (!sas_expander->responding) | |
9115 | list_move_tail(&sas_expander->list, &tmp_list); | |
9116 | else | |
9117 | sas_expander->responding = 0; | |
9118 | } | |
9119 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
9120 | list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list, | |
9121 | list) { | |
f92363d1 SR |
9122 | _scsih_expander_node_remove(ioc, sas_expander); |
9123 | } | |
9124 | ||
919d8a3f | 9125 | ioc_info(ioc, "removing unresponding devices: complete\n"); |
f92363d1 SR |
9126 | |
9127 | /* unblock devices */ | |
9128 | _scsih_ublock_io_all_device(ioc); | |
9129 | } | |
9130 | ||
9131 | static void | |
9132 | _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc, | |
9133 | struct _sas_node *sas_expander, u16 handle) | |
9134 | { | |
9135 | Mpi2ExpanderPage1_t expander_pg1; | |
9136 | Mpi2ConfigReply_t mpi_reply; | |
9137 | int i; | |
9138 | ||
9139 | for (i = 0 ; i < sas_expander->num_phys ; i++) { | |
9140 | if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply, | |
9141 | &expander_pg1, i, handle))) { | |
919d8a3f JP |
9142 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
9143 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
9144 | return; |
9145 | } | |
9146 | ||
9147 | mpt3sas_transport_update_links(ioc, sas_expander->sas_address, | |
9148 | le16_to_cpu(expander_pg1.AttachedDevHandle), i, | |
9149 | expander_pg1.NegotiatedLinkRate >> 4); | |
9150 | } | |
9151 | } | |
9152 | ||
9153 | /** | |
9154 | * _scsih_scan_for_devices_after_reset - scan for devices after host reset | |
9155 | * @ioc: per adapter object | |
f92363d1 SR |
9156 | */ |
9157 | static void | |
9158 | _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc) | |
9159 | { | |
9160 | Mpi2ExpanderPage0_t expander_pg0; | |
9161 | Mpi2SasDevicePage0_t sas_device_pg0; | |
ec051e5a | 9162 | Mpi26PCIeDevicePage0_t pcie_device_pg0; |
f92363d1 SR |
9163 | Mpi2RaidVolPage1_t volume_pg1; |
9164 | Mpi2RaidVolPage0_t volume_pg0; | |
9165 | Mpi2RaidPhysDiskPage0_t pd_pg0; | |
9166 | Mpi2EventIrConfigElement_t element; | |
9167 | Mpi2ConfigReply_t mpi_reply; | |
9168 | u8 phys_disk_num; | |
9169 | u16 ioc_status; | |
9170 | u16 handle, parent_handle; | |
9171 | u64 sas_address; | |
9172 | struct _sas_device *sas_device; | |
ec051e5a | 9173 | struct _pcie_device *pcie_device; |
f92363d1 SR |
9174 | struct _sas_node *expander_device; |
9175 | static struct _raid_device *raid_device; | |
9176 | u8 retry_count; | |
9177 | unsigned long flags; | |
9178 | ||
919d8a3f | 9179 | ioc_info(ioc, "scan devices: start\n"); |
f92363d1 SR |
9180 | |
9181 | _scsih_sas_host_refresh(ioc); | |
9182 | ||
919d8a3f | 9183 | ioc_info(ioc, "\tscan devices: expanders start\n"); |
f92363d1 SR |
9184 | |
9185 | /* expanders */ | |
9186 | handle = 0xFFFF; | |
9187 | while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | |
9188 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { | |
9189 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9190 | MPI2_IOCSTATUS_MASK; | |
f92363d1 | 9191 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
919d8a3f JP |
9192 | ioc_info(ioc, "\tbreak from expander scan: ioc_status(0x%04x), loginfo(0x%08x)\n", |
9193 | ioc_status, le32_to_cpu(mpi_reply.IOCLogInfo)); | |
f92363d1 SR |
9194 | break; |
9195 | } | |
9196 | handle = le16_to_cpu(expander_pg0.DevHandle); | |
9197 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
9198 | expander_device = mpt3sas_scsih_expander_find_by_sas_address( | |
9199 | ioc, le64_to_cpu(expander_pg0.SASAddress)); | |
9200 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
9201 | if (expander_device) | |
9202 | _scsih_refresh_expander_links(ioc, expander_device, | |
9203 | handle); | |
9204 | else { | |
919d8a3f JP |
9205 | ioc_info(ioc, "\tBEFORE adding expander: handle (0x%04x), sas_addr(0x%016llx)\n", |
9206 | handle, | |
9207 | (u64)le64_to_cpu(expander_pg0.SASAddress)); | |
f92363d1 | 9208 | _scsih_expander_add(ioc, handle); |
919d8a3f JP |
9209 | ioc_info(ioc, "\tAFTER adding expander: handle (0x%04x), sas_addr(0x%016llx)\n", |
9210 | handle, | |
9211 | (u64)le64_to_cpu(expander_pg0.SASAddress)); | |
f92363d1 SR |
9212 | } |
9213 | } | |
9214 | ||
919d8a3f | 9215 | ioc_info(ioc, "\tscan devices: expanders complete\n"); |
f92363d1 SR |
9216 | |
9217 | if (!ioc->ir_firmware) | |
9218 | goto skip_to_sas; | |
9219 | ||
919d8a3f | 9220 | ioc_info(ioc, "\tscan devices: phys disk start\n"); |
f92363d1 SR |
9221 | |
9222 | /* phys disk */ | |
9223 | phys_disk_num = 0xFF; | |
9224 | while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | |
9225 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, | |
9226 | phys_disk_num))) { | |
9227 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9228 | MPI2_IOCSTATUS_MASK; | |
f92363d1 | 9229 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
919d8a3f JP |
9230 | ioc_info(ioc, "\tbreak from phys disk scan: ioc_status(0x%04x), loginfo(0x%08x)\n", |
9231 | ioc_status, le32_to_cpu(mpi_reply.IOCLogInfo)); | |
f92363d1 SR |
9232 | break; |
9233 | } | |
9234 | phys_disk_num = pd_pg0.PhysDiskNum; | |
9235 | handle = le16_to_cpu(pd_pg0.DevHandle); | |
d1cb5e49 SR |
9236 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
9237 | if (sas_device) { | |
9238 | sas_device_put(sas_device); | |
f92363d1 | 9239 | continue; |
d1cb5e49 | 9240 | } |
f92363d1 SR |
9241 | if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
9242 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | |
9243 | handle) != 0) | |
9244 | continue; | |
9245 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9246 | MPI2_IOCSTATUS_MASK; | |
9247 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
919d8a3f JP |
9248 | ioc_info(ioc, "\tbreak from phys disk scan ioc_status(0x%04x), loginfo(0x%08x)\n", |
9249 | ioc_status, le32_to_cpu(mpi_reply.IOCLogInfo)); | |
f92363d1 SR |
9250 | break; |
9251 | } | |
9252 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | |
9253 | if (!_scsih_get_sas_address(ioc, parent_handle, | |
9254 | &sas_address)) { | |
919d8a3f JP |
9255 | ioc_info(ioc, "\tBEFORE adding phys disk: handle (0x%04x), sas_addr(0x%016llx)\n", |
9256 | handle, | |
9257 | (u64)le64_to_cpu(sas_device_pg0.SASAddress)); | |
f92363d1 SR |
9258 | mpt3sas_transport_update_links(ioc, sas_address, |
9259 | handle, sas_device_pg0.PhyNum, | |
9260 | MPI2_SAS_NEG_LINK_RATE_1_5); | |
9261 | set_bit(handle, ioc->pd_handles); | |
9262 | retry_count = 0; | |
9263 | /* This will retry adding the end device. | |
9264 | * _scsih_add_device() will decide on retries and | |
9265 | * return "1" when it should be retried | |
9266 | */ | |
9267 | while (_scsih_add_device(ioc, handle, retry_count++, | |
9268 | 1)) { | |
9269 | ssleep(1); | |
9270 | } | |
919d8a3f JP |
9271 | ioc_info(ioc, "\tAFTER adding phys disk: handle (0x%04x), sas_addr(0x%016llx)\n", |
9272 | handle, | |
9273 | (u64)le64_to_cpu(sas_device_pg0.SASAddress)); | |
f92363d1 SR |
9274 | } |
9275 | } | |
9276 | ||
919d8a3f | 9277 | ioc_info(ioc, "\tscan devices: phys disk complete\n"); |
f92363d1 | 9278 | |
919d8a3f | 9279 | ioc_info(ioc, "\tscan devices: volumes start\n"); |
f92363d1 SR |
9280 | |
9281 | /* volumes */ | |
9282 | handle = 0xFFFF; | |
9283 | while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply, | |
9284 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { | |
9285 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9286 | MPI2_IOCSTATUS_MASK; | |
f92363d1 | 9287 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
919d8a3f JP |
9288 | ioc_info(ioc, "\tbreak from volume scan: ioc_status(0x%04x), loginfo(0x%08x)\n", |
9289 | ioc_status, le32_to_cpu(mpi_reply.IOCLogInfo)); | |
f92363d1 SR |
9290 | break; |
9291 | } | |
9292 | handle = le16_to_cpu(volume_pg1.DevHandle); | |
9293 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
9294 | raid_device = _scsih_raid_device_find_by_wwid(ioc, | |
9295 | le64_to_cpu(volume_pg1.WWID)); | |
9296 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
9297 | if (raid_device) | |
9298 | continue; | |
9299 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, | |
9300 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
9301 | sizeof(Mpi2RaidVolPage0_t))) | |
9302 | continue; | |
9303 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9304 | MPI2_IOCSTATUS_MASK; | |
9305 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
919d8a3f JP |
9306 | ioc_info(ioc, "\tbreak from volume scan: ioc_status(0x%04x), loginfo(0x%08x)\n", |
9307 | ioc_status, le32_to_cpu(mpi_reply.IOCLogInfo)); | |
f92363d1 SR |
9308 | break; |
9309 | } | |
9310 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || | |
9311 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || | |
9312 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) { | |
9313 | memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t)); | |
9314 | element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED; | |
9315 | element.VolDevHandle = volume_pg1.DevHandle; | |
919d8a3f JP |
9316 | ioc_info(ioc, "\tBEFORE adding volume: handle (0x%04x)\n", |
9317 | volume_pg1.DevHandle); | |
f92363d1 | 9318 | _scsih_sas_volume_add(ioc, &element); |
919d8a3f JP |
9319 | ioc_info(ioc, "\tAFTER adding volume: handle (0x%04x)\n", |
9320 | volume_pg1.DevHandle); | |
f92363d1 SR |
9321 | } |
9322 | } | |
9323 | ||
919d8a3f | 9324 | ioc_info(ioc, "\tscan devices: volumes complete\n"); |
f92363d1 SR |
9325 | |
9326 | skip_to_sas: | |
9327 | ||
919d8a3f | 9328 | ioc_info(ioc, "\tscan devices: end devices start\n"); |
f92363d1 SR |
9329 | |
9330 | /* sas devices */ | |
9331 | handle = 0xFFFF; | |
9332 | while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
9333 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | |
9334 | handle))) { | |
9335 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9336 | MPI2_IOCSTATUS_MASK; | |
f92363d1 | 9337 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
919d8a3f JP |
9338 | ioc_info(ioc, "\tbreak from end device scan: ioc_status(0x%04x), loginfo(0x%08x)\n", |
9339 | ioc_status, le32_to_cpu(mpi_reply.IOCLogInfo)); | |
f92363d1 SR |
9340 | break; |
9341 | } | |
9342 | handle = le16_to_cpu(sas_device_pg0.DevHandle); | |
9343 | if (!(_scsih_is_end_device( | |
9344 | le32_to_cpu(sas_device_pg0.DeviceInfo)))) | |
9345 | continue; | |
d1cb5e49 | 9346 | sas_device = mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 | 9347 | le64_to_cpu(sas_device_pg0.SASAddress)); |
d1cb5e49 SR |
9348 | if (sas_device) { |
9349 | sas_device_put(sas_device); | |
f92363d1 | 9350 | continue; |
d1cb5e49 | 9351 | } |
f92363d1 SR |
9352 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
9353 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) { | |
919d8a3f JP |
9354 | ioc_info(ioc, "\tBEFORE adding end device: handle (0x%04x), sas_addr(0x%016llx)\n", |
9355 | handle, | |
9356 | (u64)le64_to_cpu(sas_device_pg0.SASAddress)); | |
f92363d1 SR |
9357 | mpt3sas_transport_update_links(ioc, sas_address, handle, |
9358 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | |
9359 | retry_count = 0; | |
9360 | /* This will retry adding the end device. | |
9361 | * _scsih_add_device() will decide on retries and | |
9362 | * return "1" when it should be retried | |
9363 | */ | |
9364 | while (_scsih_add_device(ioc, handle, retry_count++, | |
9365 | 0)) { | |
9366 | ssleep(1); | |
9367 | } | |
919d8a3f JP |
9368 | ioc_info(ioc, "\tAFTER adding end device: handle (0x%04x), sas_addr(0x%016llx)\n", |
9369 | handle, | |
9370 | (u64)le64_to_cpu(sas_device_pg0.SASAddress)); | |
f92363d1 SR |
9371 | } |
9372 | } | |
919d8a3f JP |
9373 | ioc_info(ioc, "\tscan devices: end devices complete\n"); |
9374 | ioc_info(ioc, "\tscan devices: pcie end devices start\n"); | |
ec051e5a SPS |
9375 | |
9376 | /* pcie devices */ | |
9377 | handle = 0xFFFF; | |
9378 | while (!(mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply, | |
9379 | &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | |
9380 | handle))) { | |
9381 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) | |
9382 | & MPI2_IOCSTATUS_MASK; | |
9383 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
919d8a3f JP |
9384 | ioc_info(ioc, "\tbreak from pcie end device scan: ioc_status(0x%04x), loginfo(0x%08x)\n", |
9385 | ioc_status, le32_to_cpu(mpi_reply.IOCLogInfo)); | |
ec051e5a SPS |
9386 | break; |
9387 | } | |
9388 | handle = le16_to_cpu(pcie_device_pg0.DevHandle); | |
5bb309db | 9389 | if (!(_scsih_is_nvme_pciescsi_device( |
ec051e5a SPS |
9390 | le32_to_cpu(pcie_device_pg0.DeviceInfo)))) |
9391 | continue; | |
9392 | pcie_device = mpt3sas_get_pdev_by_wwid(ioc, | |
9393 | le64_to_cpu(pcie_device_pg0.WWID)); | |
9394 | if (pcie_device) { | |
9395 | pcie_device_put(pcie_device); | |
9396 | continue; | |
9397 | } | |
9398 | retry_count = 0; | |
9399 | parent_handle = le16_to_cpu(pcie_device_pg0.ParentDevHandle); | |
9400 | _scsih_pcie_add_device(ioc, handle); | |
f92363d1 | 9401 | |
919d8a3f JP |
9402 | ioc_info(ioc, "\tAFTER adding pcie end device: handle (0x%04x), wwid(0x%016llx)\n", |
9403 | handle, (u64)le64_to_cpu(pcie_device_pg0.WWID)); | |
ec051e5a | 9404 | } |
919d8a3f JP |
9405 | ioc_info(ioc, "\tpcie devices: pcie end devices complete\n"); |
9406 | ioc_info(ioc, "scan devices: complete\n"); | |
f92363d1 | 9407 | } |
c7a35705 | 9408 | |
f92363d1 SR |
9409 | /** |
9410 | * mpt3sas_scsih_reset_handler - reset callback handler (for scsih) | |
9411 | * @ioc: per adapter object | |
f92363d1 SR |
9412 | * |
9413 | * The handler for doing any required cleanup or initialization. | |
c7a35705 BVA |
9414 | */ |
9415 | void mpt3sas_scsih_pre_reset_handler(struct MPT3SAS_ADAPTER *ioc) | |
9416 | { | |
919d8a3f | 9417 | dtmprintk(ioc, ioc_info(ioc, "%s: MPT3_IOC_PRE_RESET\n", __func__)); |
c7a35705 BVA |
9418 | } |
9419 | ||
9420 | /** | |
c3a2ce88 SR |
9421 | * mpt3sas_scsih_clear_outstanding_scsi_tm_commands - clears outstanding |
9422 | * scsi & tm cmds. | |
c7a35705 | 9423 | * @ioc: per adapter object |
f92363d1 | 9424 | * |
c7a35705 | 9425 | * The handler for doing any required cleanup or initialization. |
f92363d1 SR |
9426 | */ |
9427 | void | |
c3a2ce88 | 9428 | mpt3sas_scsih_clear_outstanding_scsi_tm_commands(struct MPT3SAS_ADAPTER *ioc) |
f92363d1 | 9429 | { |
c3a2ce88 SR |
9430 | dtmprintk(ioc, |
9431 | ioc_info(ioc, "%s: clear outstanding scsi & tm cmds\n", __func__)); | |
c7a35705 BVA |
9432 | if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) { |
9433 | ioc->scsih_cmds.status |= MPT3_CMD_RESET; | |
9434 | mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid); | |
9435 | complete(&ioc->scsih_cmds.done); | |
9436 | } | |
9437 | if (ioc->tm_cmds.status & MPT3_CMD_PENDING) { | |
9438 | ioc->tm_cmds.status |= MPT3_CMD_RESET; | |
9439 | mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid); | |
9440 | complete(&ioc->tm_cmds.done); | |
9441 | } | |
f92363d1 | 9442 | |
c7a35705 BVA |
9443 | memset(ioc->pend_os_device_add, 0, ioc->pend_os_device_add_sz); |
9444 | memset(ioc->device_remove_in_progress, 0, | |
9445 | ioc->device_remove_in_progress_sz); | |
9446 | _scsih_fw_event_cleanup_queue(ioc); | |
9447 | _scsih_flush_running_cmds(ioc); | |
9448 | } | |
9449 | ||
9450 | /** | |
9451 | * mpt3sas_scsih_reset_handler - reset callback handler (for scsih) | |
9452 | * @ioc: per adapter object | |
9453 | * | |
9454 | * The handler for doing any required cleanup or initialization. | |
9455 | */ | |
9456 | void | |
9457 | mpt3sas_scsih_reset_done_handler(struct MPT3SAS_ADAPTER *ioc) | |
9458 | { | |
919d8a3f | 9459 | dtmprintk(ioc, ioc_info(ioc, "%s: MPT3_IOC_DONE_RESET\n", __func__)); |
c7a35705 BVA |
9460 | if ((!ioc->is_driver_loading) && !(disable_discovery > 0 && |
9461 | !ioc->sas_hba.num_phys)) { | |
9462 | _scsih_prep_device_scan(ioc); | |
9463 | _scsih_create_enclosure_list_after_reset(ioc); | |
9464 | _scsih_search_responding_sas_devices(ioc); | |
9465 | _scsih_search_responding_pcie_devices(ioc); | |
9466 | _scsih_search_responding_raid_devices(ioc); | |
9467 | _scsih_search_responding_expanders(ioc); | |
9468 | _scsih_error_recovery_delete_devices(ioc); | |
f92363d1 SR |
9469 | } |
9470 | } | |
9471 | ||
9472 | /** | |
9473 | * _mpt3sas_fw_work - delayed task for processing firmware events | |
9474 | * @ioc: per adapter object | |
9475 | * @fw_event: The fw_event_work object | |
9476 | * Context: user. | |
f92363d1 SR |
9477 | */ |
9478 | static void | |
9479 | _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event) | |
9480 | { | |
146b16c8 SR |
9481 | _scsih_fw_event_del_from_list(ioc, fw_event); |
9482 | ||
f92363d1 | 9483 | /* the queue is being flushed so ignore this event */ |
146b16c8 SR |
9484 | if (ioc->remove_host || ioc->pci_error_recovery) { |
9485 | fw_event_work_put(fw_event); | |
f92363d1 SR |
9486 | return; |
9487 | } | |
9488 | ||
9489 | switch (fw_event->event) { | |
9490 | case MPT3SAS_PROCESS_TRIGGER_DIAG: | |
35b62362 JL |
9491 | mpt3sas_process_trigger_data(ioc, |
9492 | (struct SL_WH_TRIGGERS_EVENT_DATA_T *) | |
9493 | fw_event->event_data); | |
f92363d1 SR |
9494 | break; |
9495 | case MPT3SAS_REMOVE_UNRESPONDING_DEVICES: | |
146b16c8 SR |
9496 | while (scsi_host_in_recovery(ioc->shost) || |
9497 | ioc->shost_recovery) { | |
9498 | /* | |
9499 | * If we're unloading, bail. Otherwise, this can become | |
9500 | * an infinite loop. | |
9501 | */ | |
9502 | if (ioc->remove_host) | |
9503 | goto out; | |
f92363d1 | 9504 | ssleep(1); |
146b16c8 | 9505 | } |
3075ac49 | 9506 | _scsih_remove_unresponding_devices(ioc); |
f92363d1 | 9507 | _scsih_scan_for_devices_after_reset(ioc); |
43fb7c95 | 9508 | _scsih_set_nvme_max_shutdown_latency(ioc); |
f92363d1 SR |
9509 | break; |
9510 | case MPT3SAS_PORT_ENABLE_COMPLETE: | |
9511 | ioc->start_scan = 0; | |
199fd79a | 9512 | if (missing_delay[0] != -1 && missing_delay[1] != -1) |
f92363d1 SR |
9513 | mpt3sas_base_update_missing_delay(ioc, missing_delay[0], |
9514 | missing_delay[1]); | |
919d8a3f JP |
9515 | dewtprintk(ioc, |
9516 | ioc_info(ioc, "port enable: complete from worker thread\n")); | |
f92363d1 | 9517 | break; |
0f624c39 SR |
9518 | case MPT3SAS_TURN_ON_PFA_LED: |
9519 | _scsih_turn_on_pfa_led(ioc, fw_event->device_handle); | |
f92363d1 SR |
9520 | break; |
9521 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: | |
9522 | _scsih_sas_topology_change_event(ioc, fw_event); | |
9523 | break; | |
9524 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: | |
54d74e6b SP |
9525 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
9526 | _scsih_sas_device_status_change_event_debug(ioc, | |
9527 | (Mpi2EventDataSasDeviceStatusChange_t *) | |
9528 | fw_event->event_data); | |
f92363d1 SR |
9529 | break; |
9530 | case MPI2_EVENT_SAS_DISCOVERY: | |
9531 | _scsih_sas_discovery_event(ioc, fw_event); | |
9532 | break; | |
95540b8e C |
9533 | case MPI2_EVENT_SAS_DEVICE_DISCOVERY_ERROR: |
9534 | _scsih_sas_device_discovery_error_event(ioc, fw_event); | |
9535 | break; | |
f92363d1 SR |
9536 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: |
9537 | _scsih_sas_broadcast_primitive_event(ioc, fw_event); | |
9538 | break; | |
9539 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: | |
9540 | _scsih_sas_enclosure_dev_status_change_event(ioc, | |
9541 | fw_event); | |
9542 | break; | |
9543 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: | |
9544 | _scsih_sas_ir_config_change_event(ioc, fw_event); | |
9545 | break; | |
9546 | case MPI2_EVENT_IR_VOLUME: | |
9547 | _scsih_sas_ir_volume_event(ioc, fw_event); | |
9548 | break; | |
9549 | case MPI2_EVENT_IR_PHYSICAL_DISK: | |
9550 | _scsih_sas_ir_physical_disk_event(ioc, fw_event); | |
9551 | break; | |
9552 | case MPI2_EVENT_IR_OPERATION_STATUS: | |
9553 | _scsih_sas_ir_operation_status_event(ioc, fw_event); | |
9554 | break; | |
4318c734 SPS |
9555 | case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE: |
9556 | _scsih_pcie_device_status_change_event(ioc, fw_event); | |
9557 | break; | |
9558 | case MPI2_EVENT_PCIE_ENUMERATION: | |
9559 | _scsih_pcie_enumeration_event(ioc, fw_event); | |
9560 | break; | |
9561 | case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST: | |
9562 | _scsih_pcie_topology_change_event(ioc, fw_event); | |
9563 | return; | |
9564 | break; | |
f92363d1 | 9565 | } |
146b16c8 SR |
9566 | out: |
9567 | fw_event_work_put(fw_event); | |
f92363d1 SR |
9568 | } |
9569 | ||
9570 | /** | |
9571 | * _firmware_event_work | |
f92363d1 SR |
9572 | * @work: The fw_event_work object |
9573 | * Context: user. | |
9574 | * | |
9575 | * wrappers for the work thread handling firmware events | |
f92363d1 SR |
9576 | */ |
9577 | ||
9578 | static void | |
9579 | _firmware_event_work(struct work_struct *work) | |
9580 | { | |
9581 | struct fw_event_work *fw_event = container_of(work, | |
9582 | struct fw_event_work, work); | |
9583 | ||
9584 | _mpt3sas_fw_work(fw_event->ioc, fw_event); | |
9585 | } | |
9586 | ||
9587 | /** | |
9588 | * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time) | |
9589 | * @ioc: per adapter object | |
9590 | * @msix_index: MSIX table index supplied by the OS | |
9591 | * @reply: reply message frame(lower 32bit addr) | |
9592 | * Context: interrupt. | |
9593 | * | |
9594 | * This function merely adds a new work task into ioc->firmware_event_thread. | |
9595 | * The tasks are worked from _firmware_event_work in user context. | |
9596 | * | |
4beb4867 BVA |
9597 | * Return: 1 meaning mf should be freed from _base_interrupt |
9598 | * 0 means the mf is freed from this function. | |
f92363d1 SR |
9599 | */ |
9600 | u8 | |
9601 | mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index, | |
9602 | u32 reply) | |
9603 | { | |
9604 | struct fw_event_work *fw_event; | |
9605 | Mpi2EventNotificationReply_t *mpi_reply; | |
9606 | u16 event; | |
9607 | u16 sz; | |
a470a51c | 9608 | Mpi26EventDataActiveCableExcept_t *ActiveCableEventData; |
f92363d1 | 9609 | |
79eb96d6 C |
9610 | /* events turned off due to host reset */ |
9611 | if (ioc->pci_error_recovery) | |
f92363d1 SR |
9612 | return 1; |
9613 | ||
9614 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
9615 | ||
9616 | if (unlikely(!mpi_reply)) { | |
919d8a3f JP |
9617 | ioc_err(ioc, "mpi_reply not valid at %s:%d/%s()!\n", |
9618 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
9619 | return 1; |
9620 | } | |
9621 | ||
9622 | event = le16_to_cpu(mpi_reply->Event); | |
9623 | ||
9624 | if (event != MPI2_EVENT_LOG_ENTRY_ADDED) | |
9625 | mpt3sas_trigger_event(ioc, event, 0); | |
9626 | ||
9627 | switch (event) { | |
9628 | /* handle these */ | |
9629 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: | |
9630 | { | |
9631 | Mpi2EventDataSasBroadcastPrimitive_t *baen_data = | |
9632 | (Mpi2EventDataSasBroadcastPrimitive_t *) | |
9633 | mpi_reply->EventData; | |
9634 | ||
9635 | if (baen_data->Primitive != | |
9636 | MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT) | |
9637 | return 1; | |
9638 | ||
9639 | if (ioc->broadcast_aen_busy) { | |
9640 | ioc->broadcast_aen_pending++; | |
9641 | return 1; | |
9642 | } else | |
9643 | ioc->broadcast_aen_busy = 1; | |
9644 | break; | |
9645 | } | |
9646 | ||
9647 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: | |
9648 | _scsih_check_topo_delete_events(ioc, | |
9649 | (Mpi2EventDataSasTopologyChangeList_t *) | |
9650 | mpi_reply->EventData); | |
9651 | break; | |
4318c734 SPS |
9652 | case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST: |
9653 | _scsih_check_pcie_topo_remove_events(ioc, | |
9654 | (Mpi26EventDataPCIeTopologyChangeList_t *) | |
9655 | mpi_reply->EventData); | |
9656 | break; | |
f92363d1 SR |
9657 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: |
9658 | _scsih_check_ir_config_unhide_events(ioc, | |
9659 | (Mpi2EventDataIrConfigChangeList_t *) | |
9660 | mpi_reply->EventData); | |
9661 | break; | |
9662 | case MPI2_EVENT_IR_VOLUME: | |
9663 | _scsih_check_volume_delete_events(ioc, | |
9664 | (Mpi2EventDataIrVolume_t *) | |
9665 | mpi_reply->EventData); | |
9666 | break; | |
7786ab6a SR |
9667 | case MPI2_EVENT_LOG_ENTRY_ADDED: |
9668 | { | |
9669 | Mpi2EventDataLogEntryAdded_t *log_entry; | |
9670 | u32 *log_code; | |
9671 | ||
9672 | if (!ioc->is_warpdrive) | |
9673 | break; | |
9674 | ||
9675 | log_entry = (Mpi2EventDataLogEntryAdded_t *) | |
9676 | mpi_reply->EventData; | |
9677 | log_code = (u32 *)log_entry->LogData; | |
f92363d1 | 9678 | |
7786ab6a SR |
9679 | if (le16_to_cpu(log_entry->LogEntryQualifier) |
9680 | != MPT2_WARPDRIVE_LOGENTRY) | |
9681 | break; | |
9682 | ||
9683 | switch (le32_to_cpu(*log_code)) { | |
9684 | case MPT2_WARPDRIVE_LC_SSDT: | |
919d8a3f | 9685 | ioc_warn(ioc, "WarpDrive Warning: IO Throttling has occurred in the WarpDrive subsystem. Check WarpDrive documentation for additional details.\n"); |
7786ab6a SR |
9686 | break; |
9687 | case MPT2_WARPDRIVE_LC_SSDLW: | |
919d8a3f | 9688 | ioc_warn(ioc, "WarpDrive Warning: Program/Erase Cycles for the WarpDrive subsystem in degraded range. Check WarpDrive documentation for additional details.\n"); |
7786ab6a SR |
9689 | break; |
9690 | case MPT2_WARPDRIVE_LC_SSDLF: | |
919d8a3f | 9691 | ioc_err(ioc, "WarpDrive Fatal Error: There are no Program/Erase Cycles for the WarpDrive subsystem. The storage device will be in read-only mode. Check WarpDrive documentation for additional details.\n"); |
7786ab6a SR |
9692 | break; |
9693 | case MPT2_WARPDRIVE_LC_BRMF: | |
919d8a3f | 9694 | ioc_err(ioc, "WarpDrive Fatal Error: The Backup Rail Monitor has failed on the WarpDrive subsystem. Check WarpDrive documentation for additional details.\n"); |
7786ab6a SR |
9695 | break; |
9696 | } | |
9697 | ||
9698 | break; | |
9699 | } | |
f92363d1 | 9700 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: |
54d74e6b SP |
9701 | _scsih_sas_device_status_change_event(ioc, |
9702 | (Mpi2EventDataSasDeviceStatusChange_t *) | |
9703 | mpi_reply->EventData); | |
9704 | break; | |
f92363d1 SR |
9705 | case MPI2_EVENT_IR_OPERATION_STATUS: |
9706 | case MPI2_EVENT_SAS_DISCOVERY: | |
95540b8e | 9707 | case MPI2_EVENT_SAS_DEVICE_DISCOVERY_ERROR: |
f92363d1 SR |
9708 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: |
9709 | case MPI2_EVENT_IR_PHYSICAL_DISK: | |
4318c734 SPS |
9710 | case MPI2_EVENT_PCIE_ENUMERATION: |
9711 | case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE: | |
f92363d1 SR |
9712 | break; |
9713 | ||
2d8ce8c9 SR |
9714 | case MPI2_EVENT_TEMP_THRESHOLD: |
9715 | _scsih_temp_threshold_events(ioc, | |
9716 | (Mpi2EventDataTemperature_t *) | |
9717 | mpi_reply->EventData); | |
9718 | break; | |
a470a51c C |
9719 | case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION: |
9720 | ActiveCableEventData = | |
9721 | (Mpi26EventDataActiveCableExcept_t *) mpi_reply->EventData; | |
6c44c0fe C |
9722 | switch (ActiveCableEventData->ReasonCode) { |
9723 | case MPI26_EVENT_ACTIVE_CABLE_INSUFFICIENT_POWER: | |
919d8a3f JP |
9724 | ioc_notice(ioc, "Currently an active cable with ReceptacleID %d\n", |
9725 | ActiveCableEventData->ReceptacleID); | |
b99b1993 SR |
9726 | pr_notice("cannot be powered and devices connected\n"); |
9727 | pr_notice("to this active cable will not be seen\n"); | |
9728 | pr_notice("This active cable requires %d mW of power\n", | |
6c44c0fe | 9729 | ActiveCableEventData->ActiveCablePowerRequirement); |
6c44c0fe C |
9730 | break; |
9731 | ||
9732 | case MPI26_EVENT_ACTIVE_CABLE_DEGRADED: | |
919d8a3f JP |
9733 | ioc_notice(ioc, "Currently a cable with ReceptacleID %d\n", |
9734 | ActiveCableEventData->ReceptacleID); | |
b99b1993 SR |
9735 | pr_notice( |
9736 | "is not running at optimal speed(12 Gb/s rate)\n"); | |
6c44c0fe | 9737 | break; |
7ebd67e0 | 9738 | } |
6c44c0fe | 9739 | |
a470a51c | 9740 | break; |
2d8ce8c9 | 9741 | |
f92363d1 SR |
9742 | default: /* ignore the rest */ |
9743 | return 1; | |
9744 | } | |
9745 | ||
f92363d1 | 9746 | sz = le16_to_cpu(mpi_reply->EventDataLength) * 4; |
146b16c8 | 9747 | fw_event = alloc_fw_event_work(sz); |
35b62362 | 9748 | if (!fw_event) { |
919d8a3f JP |
9749 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
9750 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
9751 | return 1; |
9752 | } | |
9753 | ||
9754 | memcpy(fw_event->event_data, mpi_reply->EventData, sz); | |
9755 | fw_event->ioc = ioc; | |
9756 | fw_event->VF_ID = mpi_reply->VF_ID; | |
9757 | fw_event->VP_ID = mpi_reply->VP_ID; | |
9758 | fw_event->event = event; | |
9759 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 | 9760 | fw_event_work_put(fw_event); |
f92363d1 SR |
9761 | return 1; |
9762 | } | |
9763 | ||
f92363d1 SR |
9764 | /** |
9765 | * _scsih_expander_node_remove - removing expander device from list. | |
9766 | * @ioc: per adapter object | |
9767 | * @sas_expander: the sas_device object | |
f92363d1 SR |
9768 | * |
9769 | * Removing object and freeing associated memory from the | |
9770 | * ioc->sas_expander_list. | |
f92363d1 SR |
9771 | */ |
9772 | static void | |
9773 | _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc, | |
9774 | struct _sas_node *sas_expander) | |
9775 | { | |
9776 | struct _sas_port *mpt3sas_port, *next; | |
bbe3def3 | 9777 | unsigned long flags; |
f92363d1 SR |
9778 | |
9779 | /* remove sibling ports attached to this expander */ | |
9780 | list_for_each_entry_safe(mpt3sas_port, next, | |
9781 | &sas_expander->sas_port_list, port_list) { | |
9782 | if (ioc->shost_recovery) | |
9783 | return; | |
9784 | if (mpt3sas_port->remote_identify.device_type == | |
9785 | SAS_END_DEVICE) | |
9786 | mpt3sas_device_remove_by_sas_address(ioc, | |
9787 | mpt3sas_port->remote_identify.sas_address); | |
9788 | else if (mpt3sas_port->remote_identify.device_type == | |
9789 | SAS_EDGE_EXPANDER_DEVICE || | |
9790 | mpt3sas_port->remote_identify.device_type == | |
9791 | SAS_FANOUT_EXPANDER_DEVICE) | |
9792 | mpt3sas_expander_remove(ioc, | |
9793 | mpt3sas_port->remote_identify.sas_address); | |
9794 | } | |
9795 | ||
9796 | mpt3sas_transport_port_remove(ioc, sas_expander->sas_address, | |
9797 | sas_expander->sas_address_parent); | |
9798 | ||
919d8a3f JP |
9799 | ioc_info(ioc, "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n", |
9800 | sas_expander->handle, (unsigned long long) | |
9801 | sas_expander->sas_address); | |
f92363d1 | 9802 | |
bbe3def3 SR |
9803 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
9804 | list_del(&sas_expander->list); | |
9805 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
9806 | ||
f92363d1 SR |
9807 | kfree(sas_expander->phy); |
9808 | kfree(sas_expander); | |
9809 | } | |
9810 | ||
43fb7c95 SR |
9811 | /** |
9812 | * _scsih_nvme_shutdown - NVMe shutdown notification | |
9813 | * @ioc: per adapter object | |
9814 | * | |
9815 | * Sending IoUnitControl request with shutdown operation code to alert IOC that | |
9816 | * the host system is shutting down so that IOC can issue NVMe shutdown to | |
9817 | * NVMe drives attached to it. | |
9818 | */ | |
9819 | static void | |
9820 | _scsih_nvme_shutdown(struct MPT3SAS_ADAPTER *ioc) | |
9821 | { | |
9822 | Mpi26IoUnitControlRequest_t *mpi_request; | |
9823 | Mpi26IoUnitControlReply_t *mpi_reply; | |
9824 | u16 smid; | |
9825 | ||
9826 | /* are there any NVMe devices ? */ | |
9827 | if (list_empty(&ioc->pcie_device_list)) | |
9828 | return; | |
9829 | ||
9830 | mutex_lock(&ioc->scsih_cmds.mutex); | |
9831 | ||
9832 | if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) { | |
9833 | ioc_err(ioc, "%s: scsih_cmd in use\n", __func__); | |
9834 | goto out; | |
9835 | } | |
9836 | ||
9837 | ioc->scsih_cmds.status = MPT3_CMD_PENDING; | |
9838 | ||
9839 | smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx); | |
9840 | if (!smid) { | |
9841 | ioc_err(ioc, | |
9842 | "%s: failed obtaining a smid\n", __func__); | |
9843 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
9844 | goto out; | |
9845 | } | |
9846 | ||
9847 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
9848 | ioc->scsih_cmds.smid = smid; | |
9849 | memset(mpi_request, 0, sizeof(Mpi26IoUnitControlRequest_t)); | |
9850 | mpi_request->Function = MPI2_FUNCTION_IO_UNIT_CONTROL; | |
9851 | mpi_request->Operation = MPI26_CTRL_OP_SHUTDOWN; | |
9852 | ||
9853 | init_completion(&ioc->scsih_cmds.done); | |
9854 | ioc->put_smid_default(ioc, smid); | |
9855 | /* Wait for max_shutdown_latency seconds */ | |
9856 | ioc_info(ioc, | |
9857 | "Io Unit Control shutdown (sending), Shutdown latency %d sec\n", | |
9858 | ioc->max_shutdown_latency); | |
9859 | wait_for_completion_timeout(&ioc->scsih_cmds.done, | |
9860 | ioc->max_shutdown_latency*HZ); | |
9861 | ||
9862 | if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) { | |
9863 | ioc_err(ioc, "%s: timeout\n", __func__); | |
9864 | goto out; | |
9865 | } | |
9866 | ||
9867 | if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) { | |
9868 | mpi_reply = ioc->scsih_cmds.reply; | |
9869 | ioc_info(ioc, "Io Unit Control shutdown (complete):" | |
9870 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9871 | le16_to_cpu(mpi_reply->IOCStatus), | |
9872 | le32_to_cpu(mpi_reply->IOCLogInfo)); | |
9873 | } | |
9874 | out: | |
9875 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
9876 | mutex_unlock(&ioc->scsih_cmds.mutex); | |
9877 | } | |
9878 | ||
9879 | ||
f92363d1 SR |
9880 | /** |
9881 | * _scsih_ir_shutdown - IR shutdown notification | |
9882 | * @ioc: per adapter object | |
9883 | * | |
9884 | * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that | |
9885 | * the host system is shutting down. | |
f92363d1 SR |
9886 | */ |
9887 | static void | |
9888 | _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc) | |
9889 | { | |
9890 | Mpi2RaidActionRequest_t *mpi_request; | |
9891 | Mpi2RaidActionReply_t *mpi_reply; | |
9892 | u16 smid; | |
9893 | ||
9894 | /* is IR firmware build loaded ? */ | |
9895 | if (!ioc->ir_firmware) | |
9896 | return; | |
9897 | ||
9898 | /* are there any volumes ? */ | |
9899 | if (list_empty(&ioc->raid_device_list)) | |
9900 | return; | |
9901 | ||
9902 | mutex_lock(&ioc->scsih_cmds.mutex); | |
9903 | ||
9904 | if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) { | |
919d8a3f | 9905 | ioc_err(ioc, "%s: scsih_cmd in use\n", __func__); |
f92363d1 SR |
9906 | goto out; |
9907 | } | |
9908 | ioc->scsih_cmds.status = MPT3_CMD_PENDING; | |
9909 | ||
9910 | smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx); | |
9911 | if (!smid) { | |
919d8a3f | 9912 | ioc_err(ioc, "%s: failed obtaining a smid\n", __func__); |
f92363d1 SR |
9913 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; |
9914 | goto out; | |
9915 | } | |
9916 | ||
9917 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
9918 | ioc->scsih_cmds.smid = smid; | |
9919 | memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t)); | |
9920 | ||
9921 | mpi_request->Function = MPI2_FUNCTION_RAID_ACTION; | |
9922 | mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED; | |
9923 | ||
7786ab6a | 9924 | if (!ioc->hide_ir_msg) |
919d8a3f | 9925 | ioc_info(ioc, "IR shutdown (sending)\n"); |
f92363d1 | 9926 | init_completion(&ioc->scsih_cmds.done); |
078a4cc1 | 9927 | ioc->put_smid_default(ioc, smid); |
f92363d1 SR |
9928 | wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ); |
9929 | ||
9930 | if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) { | |
919d8a3f | 9931 | ioc_err(ioc, "%s: timeout\n", __func__); |
f92363d1 SR |
9932 | goto out; |
9933 | } | |
9934 | ||
9935 | if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) { | |
9936 | mpi_reply = ioc->scsih_cmds.reply; | |
7786ab6a | 9937 | if (!ioc->hide_ir_msg) |
919d8a3f JP |
9938 | ioc_info(ioc, "IR shutdown (complete): ioc_status(0x%04x), loginfo(0x%08x)\n", |
9939 | le16_to_cpu(mpi_reply->IOCStatus), | |
9940 | le32_to_cpu(mpi_reply->IOCLogInfo)); | |
f92363d1 SR |
9941 | } |
9942 | ||
9943 | out: | |
9944 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
9945 | mutex_unlock(&ioc->scsih_cmds.mutex); | |
9946 | } | |
9947 | ||
9948 | /** | |
8a7e4c24 | 9949 | * scsih_remove - detach and remove add host |
f92363d1 SR |
9950 | * @pdev: PCI device struct |
9951 | * | |
9952 | * Routine called when unloading the driver. | |
f92363d1 | 9953 | */ |
8bbb1cf6 | 9954 | static void scsih_remove(struct pci_dev *pdev) |
f92363d1 SR |
9955 | { |
9956 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9957 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
9958 | struct _sas_port *mpt3sas_port, *next_port; | |
9959 | struct _raid_device *raid_device, *next; | |
9960 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
3075ac49 | 9961 | struct _pcie_device *pcie_device, *pcienext; |
f92363d1 SR |
9962 | struct workqueue_struct *wq; |
9963 | unsigned long flags; | |
2426f209 | 9964 | Mpi2ConfigReply_t mpi_reply; |
b326db46 | 9965 | struct hba_port *port, *port_next; |
f92363d1 SR |
9966 | |
9967 | ioc->remove_host = 1; | |
c666d3be | 9968 | |
349e16ca SR |
9969 | if (!pci_device_is_present(pdev)) |
9970 | _scsih_flush_running_cmds(ioc); | |
c666d3be | 9971 | |
f92363d1 SR |
9972 | _scsih_fw_event_cleanup_queue(ioc); |
9973 | ||
9974 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
9975 | wq = ioc->firmware_event_thread; | |
9976 | ioc->firmware_event_thread = NULL; | |
9977 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
9978 | if (wq) | |
9979 | destroy_workqueue(wq); | |
2426f209 SP |
9980 | /* |
9981 | * Copy back the unmodified ioc page1. so that on next driver load, | |
9982 | * current modified changes on ioc page1 won't take effect. | |
9983 | */ | |
9984 | if (ioc->is_aero_ioc) | |
9985 | mpt3sas_config_set_ioc_pg1(ioc, &mpi_reply, | |
9986 | &ioc->ioc_pg1_copy); | |
f92363d1 SR |
9987 | /* release all the volumes */ |
9988 | _scsih_ir_shutdown(ioc); | |
dc730212 | 9989 | sas_remove_host(shost); |
f92363d1 SR |
9990 | list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list, |
9991 | list) { | |
9992 | if (raid_device->starget) { | |
9993 | sas_target_priv_data = | |
9994 | raid_device->starget->hostdata; | |
9995 | sas_target_priv_data->deleted = 1; | |
9996 | scsi_remove_target(&raid_device->starget->dev); | |
9997 | } | |
919d8a3f JP |
9998 | ioc_info(ioc, "removing handle(0x%04x), wwid(0x%016llx)\n", |
9999 | raid_device->handle, (u64)raid_device->wwid); | |
f92363d1 SR |
10000 | _scsih_raid_device_remove(ioc, raid_device); |
10001 | } | |
3075ac49 SPS |
10002 | list_for_each_entry_safe(pcie_device, pcienext, &ioc->pcie_device_list, |
10003 | list) { | |
10004 | _scsih_pcie_device_remove_from_sml(ioc, pcie_device); | |
10005 | list_del_init(&pcie_device->list); | |
10006 | pcie_device_put(pcie_device); | |
10007 | } | |
f92363d1 SR |
10008 | |
10009 | /* free ports attached to the sas_host */ | |
10010 | list_for_each_entry_safe(mpt3sas_port, next_port, | |
10011 | &ioc->sas_hba.sas_port_list, port_list) { | |
10012 | if (mpt3sas_port->remote_identify.device_type == | |
10013 | SAS_END_DEVICE) | |
10014 | mpt3sas_device_remove_by_sas_address(ioc, | |
10015 | mpt3sas_port->remote_identify.sas_address); | |
10016 | else if (mpt3sas_port->remote_identify.device_type == | |
10017 | SAS_EDGE_EXPANDER_DEVICE || | |
10018 | mpt3sas_port->remote_identify.device_type == | |
10019 | SAS_FANOUT_EXPANDER_DEVICE) | |
10020 | mpt3sas_expander_remove(ioc, | |
10021 | mpt3sas_port->remote_identify.sas_address); | |
10022 | } | |
10023 | ||
b326db46 SR |
10024 | list_for_each_entry_safe(port, port_next, |
10025 | &ioc->port_table_list, list) { | |
10026 | list_del(&port->list); | |
10027 | kfree(port); | |
10028 | } | |
10029 | ||
f92363d1 SR |
10030 | /* free phys attached to the sas_host */ |
10031 | if (ioc->sas_hba.num_phys) { | |
10032 | kfree(ioc->sas_hba.phy); | |
10033 | ioc->sas_hba.phy = NULL; | |
10034 | ioc->sas_hba.num_phys = 0; | |
10035 | } | |
10036 | ||
f92363d1 | 10037 | mpt3sas_base_detach(ioc); |
08c4d550 | 10038 | spin_lock(&gioc_lock); |
f92363d1 | 10039 | list_del(&ioc->list); |
08c4d550 | 10040 | spin_unlock(&gioc_lock); |
f92363d1 SR |
10041 | scsi_host_put(shost); |
10042 | } | |
10043 | ||
10044 | /** | |
8a7e4c24 | 10045 | * scsih_shutdown - routine call during system shutdown |
f92363d1 | 10046 | * @pdev: PCI device struct |
f92363d1 | 10047 | */ |
8bbb1cf6 | 10048 | static void |
8a7e4c24 | 10049 | scsih_shutdown(struct pci_dev *pdev) |
f92363d1 SR |
10050 | { |
10051 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10052 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10053 | struct workqueue_struct *wq; | |
10054 | unsigned long flags; | |
2426f209 | 10055 | Mpi2ConfigReply_t mpi_reply; |
f92363d1 SR |
10056 | |
10057 | ioc->remove_host = 1; | |
c666d3be | 10058 | |
349e16ca SR |
10059 | if (!pci_device_is_present(pdev)) |
10060 | _scsih_flush_running_cmds(ioc); | |
c666d3be | 10061 | |
f92363d1 SR |
10062 | _scsih_fw_event_cleanup_queue(ioc); |
10063 | ||
10064 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
10065 | wq = ioc->firmware_event_thread; | |
10066 | ioc->firmware_event_thread = NULL; | |
10067 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
10068 | if (wq) | |
10069 | destroy_workqueue(wq); | |
2426f209 SP |
10070 | /* |
10071 | * Copy back the unmodified ioc page1 so that on next driver load, | |
10072 | * current modified changes on ioc page1 won't take effect. | |
10073 | */ | |
10074 | if (ioc->is_aero_ioc) | |
10075 | mpt3sas_config_set_ioc_pg1(ioc, &mpi_reply, | |
10076 | &ioc->ioc_pg1_copy); | |
f92363d1 SR |
10077 | |
10078 | _scsih_ir_shutdown(ioc); | |
43fb7c95 | 10079 | _scsih_nvme_shutdown(ioc); |
f92363d1 SR |
10080 | mpt3sas_base_detach(ioc); |
10081 | } | |
10082 | ||
10083 | ||
10084 | /** | |
10085 | * _scsih_probe_boot_devices - reports 1st device | |
10086 | * @ioc: per adapter object | |
10087 | * | |
10088 | * If specified in bios page 2, this routine reports the 1st | |
10089 | * device scsi-ml or sas transport for persistent boot device | |
10090 | * purposes. Please refer to function _scsih_determine_boot_device() | |
10091 | */ | |
10092 | static void | |
10093 | _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc) | |
10094 | { | |
d88e1eab | 10095 | u32 channel; |
f92363d1 SR |
10096 | void *device; |
10097 | struct _sas_device *sas_device; | |
10098 | struct _raid_device *raid_device; | |
d88e1eab | 10099 | struct _pcie_device *pcie_device; |
f92363d1 SR |
10100 | u16 handle; |
10101 | u64 sas_address_parent; | |
10102 | u64 sas_address; | |
10103 | unsigned long flags; | |
10104 | int rc; | |
d88e1eab | 10105 | int tid; |
f92363d1 SR |
10106 | |
10107 | /* no Bios, return immediately */ | |
10108 | if (!ioc->bios_pg3.BiosVersion) | |
10109 | return; | |
10110 | ||
10111 | device = NULL; | |
f92363d1 SR |
10112 | if (ioc->req_boot_device.device) { |
10113 | device = ioc->req_boot_device.device; | |
d88e1eab | 10114 | channel = ioc->req_boot_device.channel; |
f92363d1 SR |
10115 | } else if (ioc->req_alt_boot_device.device) { |
10116 | device = ioc->req_alt_boot_device.device; | |
d88e1eab | 10117 | channel = ioc->req_alt_boot_device.channel; |
f92363d1 SR |
10118 | } else if (ioc->current_boot_device.device) { |
10119 | device = ioc->current_boot_device.device; | |
d88e1eab | 10120 | channel = ioc->current_boot_device.channel; |
f92363d1 SR |
10121 | } |
10122 | ||
10123 | if (!device) | |
10124 | return; | |
10125 | ||
d88e1eab | 10126 | if (channel == RAID_CHANNEL) { |
f92363d1 SR |
10127 | raid_device = device; |
10128 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
10129 | raid_device->id, 0); | |
10130 | if (rc) | |
10131 | _scsih_raid_device_remove(ioc, raid_device); | |
d88e1eab SPS |
10132 | } else if (channel == PCIE_CHANNEL) { |
10133 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
10134 | pcie_device = device; | |
10135 | tid = pcie_device->id; | |
10136 | list_move_tail(&pcie_device->list, &ioc->pcie_device_list); | |
10137 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
10138 | rc = scsi_add_device(ioc->shost, PCIE_CHANNEL, tid, 0); | |
10139 | if (rc) | |
10140 | _scsih_pcie_device_remove(ioc, pcie_device); | |
f92363d1 SR |
10141 | } else { |
10142 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
10143 | sas_device = device; | |
10144 | handle = sas_device->handle; | |
10145 | sas_address_parent = sas_device->sas_address_parent; | |
10146 | sas_address = sas_device->sas_address; | |
10147 | list_move_tail(&sas_device->list, &ioc->sas_device_list); | |
10148 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
10149 | ||
7786ab6a SR |
10150 | if (ioc->hide_drives) |
10151 | return; | |
f92363d1 SR |
10152 | if (!mpt3sas_transport_port_add(ioc, handle, |
10153 | sas_address_parent)) { | |
10154 | _scsih_sas_device_remove(ioc, sas_device); | |
10155 | } else if (!sas_device->starget) { | |
f5edbe77 SR |
10156 | if (!ioc->is_driver_loading) { |
10157 | mpt3sas_transport_port_remove(ioc, | |
10158 | sas_address, | |
f92363d1 | 10159 | sas_address_parent); |
f5edbe77 SR |
10160 | _scsih_sas_device_remove(ioc, sas_device); |
10161 | } | |
f92363d1 SR |
10162 | } |
10163 | } | |
10164 | } | |
10165 | ||
10166 | /** | |
10167 | * _scsih_probe_raid - reporting raid volumes to scsi-ml | |
10168 | * @ioc: per adapter object | |
10169 | * | |
10170 | * Called during initial loading of the driver. | |
10171 | */ | |
10172 | static void | |
10173 | _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc) | |
10174 | { | |
10175 | struct _raid_device *raid_device, *raid_next; | |
10176 | int rc; | |
10177 | ||
10178 | list_for_each_entry_safe(raid_device, raid_next, | |
10179 | &ioc->raid_device_list, list) { | |
10180 | if (raid_device->starget) | |
10181 | continue; | |
10182 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
10183 | raid_device->id, 0); | |
10184 | if (rc) | |
10185 | _scsih_raid_device_remove(ioc, raid_device); | |
10186 | } | |
10187 | } | |
10188 | ||
d1cb5e49 SR |
10189 | static struct _sas_device *get_next_sas_device(struct MPT3SAS_ADAPTER *ioc) |
10190 | { | |
10191 | struct _sas_device *sas_device = NULL; | |
10192 | unsigned long flags; | |
10193 | ||
10194 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
10195 | if (!list_empty(&ioc->sas_device_init_list)) { | |
10196 | sas_device = list_first_entry(&ioc->sas_device_init_list, | |
10197 | struct _sas_device, list); | |
10198 | sas_device_get(sas_device); | |
10199 | } | |
10200 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
10201 | ||
10202 | return sas_device; | |
10203 | } | |
10204 | ||
10205 | static void sas_device_make_active(struct MPT3SAS_ADAPTER *ioc, | |
10206 | struct _sas_device *sas_device) | |
10207 | { | |
10208 | unsigned long flags; | |
10209 | ||
10210 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
10211 | ||
10212 | /* | |
10213 | * Since we dropped the lock during the call to port_add(), we need to | |
10214 | * be careful here that somebody else didn't move or delete this item | |
10215 | * while we were busy with other things. | |
10216 | * | |
10217 | * If it was on the list, we need a put() for the reference the list | |
10218 | * had. Either way, we need a get() for the destination list. | |
10219 | */ | |
10220 | if (!list_empty(&sas_device->list)) { | |
10221 | list_del_init(&sas_device->list); | |
10222 | sas_device_put(sas_device); | |
10223 | } | |
10224 | ||
10225 | sas_device_get(sas_device); | |
10226 | list_add_tail(&sas_device->list, &ioc->sas_device_list); | |
10227 | ||
10228 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
10229 | } | |
10230 | ||
f92363d1 SR |
10231 | /** |
10232 | * _scsih_probe_sas - reporting sas devices to sas transport | |
10233 | * @ioc: per adapter object | |
10234 | * | |
10235 | * Called during initial loading of the driver. | |
10236 | */ | |
10237 | static void | |
10238 | _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc) | |
10239 | { | |
d1cb5e49 | 10240 | struct _sas_device *sas_device; |
f92363d1 | 10241 | |
d1cb5e49 SR |
10242 | if (ioc->hide_drives) |
10243 | return; | |
7786ab6a | 10244 | |
d1cb5e49 | 10245 | while ((sas_device = get_next_sas_device(ioc))) { |
f92363d1 SR |
10246 | if (!mpt3sas_transport_port_add(ioc, sas_device->handle, |
10247 | sas_device->sas_address_parent)) { | |
d1cb5e49 SR |
10248 | _scsih_sas_device_remove(ioc, sas_device); |
10249 | sas_device_put(sas_device); | |
f92363d1 SR |
10250 | continue; |
10251 | } else if (!sas_device->starget) { | |
10252 | /* | |
10253 | * When asyn scanning is enabled, its not possible to | |
10254 | * remove devices while scanning is turned on due to an | |
10255 | * oops in scsi_sysfs_add_sdev()->add_device()-> | |
10256 | * sysfs_addrm_start() | |
10257 | */ | |
f5edbe77 | 10258 | if (!ioc->is_driver_loading) { |
f92363d1 SR |
10259 | mpt3sas_transport_port_remove(ioc, |
10260 | sas_device->sas_address, | |
10261 | sas_device->sas_address_parent); | |
d1cb5e49 SR |
10262 | _scsih_sas_device_remove(ioc, sas_device); |
10263 | sas_device_put(sas_device); | |
f5edbe77 SR |
10264 | continue; |
10265 | } | |
f92363d1 | 10266 | } |
d1cb5e49 SR |
10267 | sas_device_make_active(ioc, sas_device); |
10268 | sas_device_put(sas_device); | |
f92363d1 SR |
10269 | } |
10270 | } | |
10271 | ||
d88e1eab SPS |
10272 | /** |
10273 | * get_next_pcie_device - Get the next pcie device | |
10274 | * @ioc: per adapter object | |
10275 | * | |
10276 | * Get the next pcie device from pcie_device_init_list list. | |
10277 | * | |
4beb4867 | 10278 | * Return: pcie device structure if pcie_device_init_list list is not empty |
d88e1eab SPS |
10279 | * otherwise returns NULL |
10280 | */ | |
10281 | static struct _pcie_device *get_next_pcie_device(struct MPT3SAS_ADAPTER *ioc) | |
10282 | { | |
10283 | struct _pcie_device *pcie_device = NULL; | |
10284 | unsigned long flags; | |
10285 | ||
10286 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
10287 | if (!list_empty(&ioc->pcie_device_init_list)) { | |
10288 | pcie_device = list_first_entry(&ioc->pcie_device_init_list, | |
10289 | struct _pcie_device, list); | |
10290 | pcie_device_get(pcie_device); | |
10291 | } | |
10292 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
10293 | ||
10294 | return pcie_device; | |
10295 | } | |
10296 | ||
10297 | /** | |
10298 | * pcie_device_make_active - Add pcie device to pcie_device_list list | |
10299 | * @ioc: per adapter object | |
10300 | * @pcie_device: pcie device object | |
10301 | * | |
10302 | * Add the pcie device which has registered with SCSI Transport Later to | |
10303 | * pcie_device_list list | |
10304 | */ | |
10305 | static void pcie_device_make_active(struct MPT3SAS_ADAPTER *ioc, | |
10306 | struct _pcie_device *pcie_device) | |
10307 | { | |
10308 | unsigned long flags; | |
10309 | ||
10310 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
10311 | ||
10312 | if (!list_empty(&pcie_device->list)) { | |
10313 | list_del_init(&pcie_device->list); | |
10314 | pcie_device_put(pcie_device); | |
10315 | } | |
10316 | pcie_device_get(pcie_device); | |
10317 | list_add_tail(&pcie_device->list, &ioc->pcie_device_list); | |
10318 | ||
10319 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
10320 | } | |
10321 | ||
10322 | /** | |
10323 | * _scsih_probe_pcie - reporting PCIe devices to scsi-ml | |
10324 | * @ioc: per adapter object | |
10325 | * | |
10326 | * Called during initial loading of the driver. | |
10327 | */ | |
10328 | static void | |
10329 | _scsih_probe_pcie(struct MPT3SAS_ADAPTER *ioc) | |
10330 | { | |
10331 | struct _pcie_device *pcie_device; | |
10332 | int rc; | |
10333 | ||
10334 | /* PCIe Device List */ | |
10335 | while ((pcie_device = get_next_pcie_device(ioc))) { | |
10336 | if (pcie_device->starget) { | |
10337 | pcie_device_put(pcie_device); | |
10338 | continue; | |
10339 | } | |
3c090ce3 SP |
10340 | if (pcie_device->access_status == |
10341 | MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED) { | |
10342 | pcie_device_make_active(ioc, pcie_device); | |
10343 | pcie_device_put(pcie_device); | |
10344 | continue; | |
10345 | } | |
d88e1eab SPS |
10346 | rc = scsi_add_device(ioc->shost, PCIE_CHANNEL, |
10347 | pcie_device->id, 0); | |
10348 | if (rc) { | |
10349 | _scsih_pcie_device_remove(ioc, pcie_device); | |
10350 | pcie_device_put(pcie_device); | |
10351 | continue; | |
10352 | } else if (!pcie_device->starget) { | |
10353 | /* | |
10354 | * When async scanning is enabled, its not possible to | |
10355 | * remove devices while scanning is turned on due to an | |
10356 | * oops in scsi_sysfs_add_sdev()->add_device()-> | |
10357 | * sysfs_addrm_start() | |
10358 | */ | |
10359 | if (!ioc->is_driver_loading) { | |
10360 | /* TODO-- Need to find out whether this condition will | |
10361 | * occur or not | |
10362 | */ | |
10363 | _scsih_pcie_device_remove(ioc, pcie_device); | |
10364 | pcie_device_put(pcie_device); | |
10365 | continue; | |
10366 | } | |
10367 | } | |
10368 | pcie_device_make_active(ioc, pcie_device); | |
10369 | pcie_device_put(pcie_device); | |
10370 | } | |
10371 | } | |
10372 | ||
f92363d1 SR |
10373 | /** |
10374 | * _scsih_probe_devices - probing for devices | |
10375 | * @ioc: per adapter object | |
10376 | * | |
10377 | * Called during initial loading of the driver. | |
10378 | */ | |
10379 | static void | |
10380 | _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc) | |
10381 | { | |
10382 | u16 volume_mapping_flags; | |
10383 | ||
10384 | if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR)) | |
10385 | return; /* return when IOC doesn't support initiator mode */ | |
10386 | ||
10387 | _scsih_probe_boot_devices(ioc); | |
10388 | ||
10389 | if (ioc->ir_firmware) { | |
10390 | volume_mapping_flags = | |
10391 | le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) & | |
10392 | MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE; | |
10393 | if (volume_mapping_flags == | |
10394 | MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) { | |
10395 | _scsih_probe_raid(ioc); | |
10396 | _scsih_probe_sas(ioc); | |
10397 | } else { | |
10398 | _scsih_probe_sas(ioc); | |
10399 | _scsih_probe_raid(ioc); | |
10400 | } | |
d88e1eab | 10401 | } else { |
f92363d1 | 10402 | _scsih_probe_sas(ioc); |
d88e1eab SPS |
10403 | _scsih_probe_pcie(ioc); |
10404 | } | |
f92363d1 SR |
10405 | } |
10406 | ||
10407 | /** | |
8a7e4c24 | 10408 | * scsih_scan_start - scsi lld callback for .scan_start |
f92363d1 SR |
10409 | * @shost: SCSI host pointer |
10410 | * | |
10411 | * The shost has the ability to discover targets on its own instead | |
10412 | * of scanning the entire bus. In our implemention, we will kick off | |
10413 | * firmware discovery. | |
10414 | */ | |
8bbb1cf6 | 10415 | static void |
8a7e4c24 | 10416 | scsih_scan_start(struct Scsi_Host *shost) |
f92363d1 SR |
10417 | { |
10418 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10419 | int rc; | |
10420 | if (diag_buffer_enable != -1 && diag_buffer_enable != 0) | |
10421 | mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable); | |
d67072de SR |
10422 | else if (ioc->manu_pg11.HostTraceBufferMaxSizeKB != 0) |
10423 | mpt3sas_enable_diag_buffer(ioc, 1); | |
f92363d1 SR |
10424 | |
10425 | if (disable_discovery > 0) | |
10426 | return; | |
10427 | ||
10428 | ioc->start_scan = 1; | |
10429 | rc = mpt3sas_port_enable(ioc); | |
10430 | ||
10431 | if (rc != 0) | |
919d8a3f | 10432 | ioc_info(ioc, "port enable: FAILED\n"); |
f92363d1 SR |
10433 | } |
10434 | ||
10435 | /** | |
8a7e4c24 | 10436 | * scsih_scan_finished - scsi lld callback for .scan_finished |
f92363d1 SR |
10437 | * @shost: SCSI host pointer |
10438 | * @time: elapsed time of the scan in jiffies | |
10439 | * | |
10440 | * This function will be called periodicallyn until it returns 1 with the | |
10441 | * scsi_host and the elapsed time of the scan in jiffies. In our implemention, | |
10442 | * we wait for firmware discovery to complete, then return 1. | |
10443 | */ | |
8bbb1cf6 | 10444 | static int |
8a7e4c24 | 10445 | scsih_scan_finished(struct Scsi_Host *shost, unsigned long time) |
f92363d1 SR |
10446 | { |
10447 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10448 | ||
10449 | if (disable_discovery > 0) { | |
10450 | ioc->is_driver_loading = 0; | |
10451 | ioc->wait_for_discovery_to_complete = 0; | |
10452 | return 1; | |
10453 | } | |
10454 | ||
10455 | if (time >= (300 * HZ)) { | |
e3586147 | 10456 | ioc->port_enable_cmds.status = MPT3_CMD_NOT_USED; |
919d8a3f | 10457 | ioc_info(ioc, "port enable: FAILED with timeout (timeout=300s)\n"); |
f92363d1 SR |
10458 | ioc->is_driver_loading = 0; |
10459 | return 1; | |
10460 | } | |
10461 | ||
10462 | if (ioc->start_scan) | |
10463 | return 0; | |
10464 | ||
10465 | if (ioc->start_scan_failed) { | |
919d8a3f JP |
10466 | ioc_info(ioc, "port enable: FAILED with (ioc_status=0x%08x)\n", |
10467 | ioc->start_scan_failed); | |
f92363d1 SR |
10468 | ioc->is_driver_loading = 0; |
10469 | ioc->wait_for_discovery_to_complete = 0; | |
10470 | ioc->remove_host = 1; | |
10471 | return 1; | |
10472 | } | |
10473 | ||
919d8a3f | 10474 | ioc_info(ioc, "port enable: SUCCESS\n"); |
e3586147 | 10475 | ioc->port_enable_cmds.status = MPT3_CMD_NOT_USED; |
f92363d1 SR |
10476 | |
10477 | if (ioc->wait_for_discovery_to_complete) { | |
10478 | ioc->wait_for_discovery_to_complete = 0; | |
10479 | _scsih_probe_devices(ioc); | |
10480 | } | |
10481 | mpt3sas_base_start_watchdog(ioc); | |
10482 | ioc->is_driver_loading = 0; | |
10483 | return 1; | |
10484 | } | |
10485 | ||
c84b06a4 SR |
10486 | /* shost template for SAS 2.0 HBA devices */ |
10487 | static struct scsi_host_template mpt2sas_driver_template = { | |
10488 | .module = THIS_MODULE, | |
10489 | .name = "Fusion MPT SAS Host", | |
10490 | .proc_name = MPT2SAS_DRIVER_NAME, | |
10491 | .queuecommand = scsih_qcmd, | |
10492 | .target_alloc = scsih_target_alloc, | |
10493 | .slave_alloc = scsih_slave_alloc, | |
10494 | .slave_configure = scsih_slave_configure, | |
10495 | .target_destroy = scsih_target_destroy, | |
10496 | .slave_destroy = scsih_slave_destroy, | |
10497 | .scan_finished = scsih_scan_finished, | |
10498 | .scan_start = scsih_scan_start, | |
10499 | .change_queue_depth = scsih_change_queue_depth, | |
10500 | .eh_abort_handler = scsih_abort, | |
10501 | .eh_device_reset_handler = scsih_dev_reset, | |
10502 | .eh_target_reset_handler = scsih_target_reset, | |
10503 | .eh_host_reset_handler = scsih_host_reset, | |
10504 | .bios_param = scsih_bios_param, | |
10505 | .can_queue = 1, | |
10506 | .this_id = -1, | |
10507 | .sg_tablesize = MPT2SAS_SG_DEPTH, | |
10508 | .max_sectors = 32767, | |
10509 | .cmd_per_lun = 7, | |
c84b06a4 SR |
10510 | .shost_attrs = mpt3sas_host_attrs, |
10511 | .sdev_attrs = mpt3sas_dev_attrs, | |
10512 | .track_queue_depth = 1, | |
dbec4c90 | 10513 | .cmd_size = sizeof(struct scsiio_tracker), |
c84b06a4 SR |
10514 | }; |
10515 | ||
10516 | /* raid transport support for SAS 2.0 HBA devices */ | |
10517 | static struct raid_function_template mpt2sas_raid_functions = { | |
10518 | .cookie = &mpt2sas_driver_template, | |
10519 | .is_raid = scsih_is_raid, | |
10520 | .get_resync = scsih_get_resync, | |
10521 | .get_state = scsih_get_state, | |
10522 | }; | |
d357e84d | 10523 | |
c84b06a4 SR |
10524 | /* shost template for SAS 3.0 HBA devices */ |
10525 | static struct scsi_host_template mpt3sas_driver_template = { | |
10526 | .module = THIS_MODULE, | |
10527 | .name = "Fusion MPT SAS Host", | |
10528 | .proc_name = MPT3SAS_DRIVER_NAME, | |
10529 | .queuecommand = scsih_qcmd, | |
10530 | .target_alloc = scsih_target_alloc, | |
10531 | .slave_alloc = scsih_slave_alloc, | |
10532 | .slave_configure = scsih_slave_configure, | |
10533 | .target_destroy = scsih_target_destroy, | |
10534 | .slave_destroy = scsih_slave_destroy, | |
10535 | .scan_finished = scsih_scan_finished, | |
10536 | .scan_start = scsih_scan_start, | |
10537 | .change_queue_depth = scsih_change_queue_depth, | |
10538 | .eh_abort_handler = scsih_abort, | |
10539 | .eh_device_reset_handler = scsih_dev_reset, | |
10540 | .eh_target_reset_handler = scsih_target_reset, | |
10541 | .eh_host_reset_handler = scsih_host_reset, | |
10542 | .bios_param = scsih_bios_param, | |
10543 | .can_queue = 1, | |
10544 | .this_id = -1, | |
10545 | .sg_tablesize = MPT3SAS_SG_DEPTH, | |
10546 | .max_sectors = 32767, | |
ce0ad853 | 10547 | .max_segment_size = 0xffffffff, |
c84b06a4 | 10548 | .cmd_per_lun = 7, |
c84b06a4 SR |
10549 | .shost_attrs = mpt3sas_host_attrs, |
10550 | .sdev_attrs = mpt3sas_dev_attrs, | |
10551 | .track_queue_depth = 1, | |
dbec4c90 | 10552 | .cmd_size = sizeof(struct scsiio_tracker), |
c84b06a4 SR |
10553 | }; |
10554 | ||
10555 | /* raid transport support for SAS 3.0 HBA devices */ | |
10556 | static struct raid_function_template mpt3sas_raid_functions = { | |
10557 | .cookie = &mpt3sas_driver_template, | |
10558 | .is_raid = scsih_is_raid, | |
10559 | .get_resync = scsih_get_resync, | |
10560 | .get_state = scsih_get_state, | |
10561 | }; | |
10562 | ||
10563 | /** | |
10564 | * _scsih_determine_hba_mpi_version - determine in which MPI version class | |
10565 | * this device belongs to. | |
10566 | * @pdev: PCI device struct | |
10567 | * | |
10568 | * return MPI2_VERSION for SAS 2.0 HBA devices, | |
b130b0d5 SS |
10569 | * MPI25_VERSION for SAS 3.0 HBA devices, and |
10570 | * MPI26 VERSION for Cutlass & Invader SAS 3.0 HBA devices | |
c84b06a4 | 10571 | */ |
8bbb1cf6 | 10572 | static u16 |
c84b06a4 SR |
10573 | _scsih_determine_hba_mpi_version(struct pci_dev *pdev) |
10574 | { | |
10575 | ||
10576 | switch (pdev->device) { | |
7786ab6a | 10577 | case MPI2_MFGPAGE_DEVID_SSS6200: |
d357e84d SR |
10578 | case MPI2_MFGPAGE_DEVID_SAS2004: |
10579 | case MPI2_MFGPAGE_DEVID_SAS2008: | |
10580 | case MPI2_MFGPAGE_DEVID_SAS2108_1: | |
10581 | case MPI2_MFGPAGE_DEVID_SAS2108_2: | |
10582 | case MPI2_MFGPAGE_DEVID_SAS2108_3: | |
10583 | case MPI2_MFGPAGE_DEVID_SAS2116_1: | |
10584 | case MPI2_MFGPAGE_DEVID_SAS2116_2: | |
10585 | case MPI2_MFGPAGE_DEVID_SAS2208_1: | |
10586 | case MPI2_MFGPAGE_DEVID_SAS2208_2: | |
10587 | case MPI2_MFGPAGE_DEVID_SAS2208_3: | |
10588 | case MPI2_MFGPAGE_DEVID_SAS2208_4: | |
10589 | case MPI2_MFGPAGE_DEVID_SAS2208_5: | |
10590 | case MPI2_MFGPAGE_DEVID_SAS2208_6: | |
10591 | case MPI2_MFGPAGE_DEVID_SAS2308_1: | |
10592 | case MPI2_MFGPAGE_DEVID_SAS2308_2: | |
10593 | case MPI2_MFGPAGE_DEVID_SAS2308_3: | |
1244790d | 10594 | case MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP: |
8f838450 | 10595 | case MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP_1: |
c84b06a4 | 10596 | return MPI2_VERSION; |
d357e84d SR |
10597 | case MPI25_MFGPAGE_DEVID_SAS3004: |
10598 | case MPI25_MFGPAGE_DEVID_SAS3008: | |
10599 | case MPI25_MFGPAGE_DEVID_SAS3108_1: | |
10600 | case MPI25_MFGPAGE_DEVID_SAS3108_2: | |
10601 | case MPI25_MFGPAGE_DEVID_SAS3108_5: | |
10602 | case MPI25_MFGPAGE_DEVID_SAS3108_6: | |
c84b06a4 | 10603 | return MPI25_VERSION; |
b130b0d5 SS |
10604 | case MPI26_MFGPAGE_DEVID_SAS3216: |
10605 | case MPI26_MFGPAGE_DEVID_SAS3224: | |
10606 | case MPI26_MFGPAGE_DEVID_SAS3316_1: | |
10607 | case MPI26_MFGPAGE_DEVID_SAS3316_2: | |
10608 | case MPI26_MFGPAGE_DEVID_SAS3316_3: | |
10609 | case MPI26_MFGPAGE_DEVID_SAS3316_4: | |
10610 | case MPI26_MFGPAGE_DEVID_SAS3324_1: | |
10611 | case MPI26_MFGPAGE_DEVID_SAS3324_2: | |
10612 | case MPI26_MFGPAGE_DEVID_SAS3324_3: | |
10613 | case MPI26_MFGPAGE_DEVID_SAS3324_4: | |
998f26ae SPS |
10614 | case MPI26_MFGPAGE_DEVID_SAS3508: |
10615 | case MPI26_MFGPAGE_DEVID_SAS3508_1: | |
10616 | case MPI26_MFGPAGE_DEVID_SAS3408: | |
10617 | case MPI26_MFGPAGE_DEVID_SAS3516: | |
10618 | case MPI26_MFGPAGE_DEVID_SAS3516_1: | |
10619 | case MPI26_MFGPAGE_DEVID_SAS3416: | |
15fd7c74 | 10620 | case MPI26_MFGPAGE_DEVID_SAS3616: |
eb9c7ce5 | 10621 | case MPI26_ATLAS_PCIe_SWITCH_DEVID: |
6c2938f7 SP |
10622 | case MPI26_MFGPAGE_DEVID_CFG_SEC_3916: |
10623 | case MPI26_MFGPAGE_DEVID_HARD_SEC_3916: | |
10624 | case MPI26_MFGPAGE_DEVID_CFG_SEC_3816: | |
10625 | case MPI26_MFGPAGE_DEVID_HARD_SEC_3816: | |
b130b0d5 | 10626 | return MPI26_VERSION; |
d357e84d | 10627 | } |
c84b06a4 | 10628 | return 0; |
d357e84d SR |
10629 | } |
10630 | ||
f92363d1 | 10631 | /** |
c84b06a4 | 10632 | * _scsih_probe - attach and add scsi host |
f92363d1 SR |
10633 | * @pdev: PCI device struct |
10634 | * @id: pci device id | |
10635 | * | |
4beb4867 | 10636 | * Return: 0 success, anything else error. |
f92363d1 | 10637 | */ |
8bbb1cf6 | 10638 | static int |
c84b06a4 | 10639 | _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
f92363d1 SR |
10640 | { |
10641 | struct MPT3SAS_ADAPTER *ioc; | |
c84b06a4 | 10642 | struct Scsi_Host *shost = NULL; |
b65f1d4d | 10643 | int rv; |
c84b06a4 SR |
10644 | u16 hba_mpi_version; |
10645 | ||
10646 | /* Determine in which MPI version class this pci device belongs */ | |
10647 | hba_mpi_version = _scsih_determine_hba_mpi_version(pdev); | |
10648 | if (hba_mpi_version == 0) | |
10649 | return -ENODEV; | |
10650 | ||
10651 | /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one, | |
10652 | * for other generation HBA's return with -ENODEV | |
10653 | */ | |
10654 | if ((hbas_to_enumerate == 1) && (hba_mpi_version != MPI2_VERSION)) | |
10655 | return -ENODEV; | |
10656 | ||
10657 | /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two, | |
10658 | * for other generation HBA's return with -ENODEV | |
10659 | */ | |
b130b0d5 SS |
10660 | if ((hbas_to_enumerate == 2) && (!(hba_mpi_version == MPI25_VERSION |
10661 | || hba_mpi_version == MPI26_VERSION))) | |
c84b06a4 SR |
10662 | return -ENODEV; |
10663 | ||
10664 | switch (hba_mpi_version) { | |
10665 | case MPI2_VERSION: | |
ffdadd68 | 10666 | pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | |
10667 | PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM); | |
c84b06a4 SR |
10668 | /* Use mpt2sas driver host template for SAS 2.0 HBA's */ |
10669 | shost = scsi_host_alloc(&mpt2sas_driver_template, | |
10670 | sizeof(struct MPT3SAS_ADAPTER)); | |
10671 | if (!shost) | |
10672 | return -ENODEV; | |
10673 | ioc = shost_priv(shost); | |
10674 | memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER)); | |
10675 | ioc->hba_mpi_version_belonged = hba_mpi_version; | |
10676 | ioc->id = mpt2_ids++; | |
10677 | sprintf(ioc->driver_name, "%s", MPT2SAS_DRIVER_NAME); | |
c520691b SPS |
10678 | switch (pdev->device) { |
10679 | case MPI2_MFGPAGE_DEVID_SSS6200: | |
c84b06a4 SR |
10680 | ioc->is_warpdrive = 1; |
10681 | ioc->hide_ir_msg = 1; | |
c520691b | 10682 | break; |
1244790d | 10683 | case MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP: |
8f838450 | 10684 | case MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP_1: |
c520691b SPS |
10685 | ioc->is_mcpu_endpoint = 1; |
10686 | break; | |
10687 | default: | |
c84b06a4 | 10688 | ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS; |
c520691b SPS |
10689 | break; |
10690 | } | |
c84b06a4 SR |
10691 | break; |
10692 | case MPI25_VERSION: | |
b130b0d5 | 10693 | case MPI26_VERSION: |
c84b06a4 SR |
10694 | /* Use mpt3sas driver host template for SAS 3.0 HBA's */ |
10695 | shost = scsi_host_alloc(&mpt3sas_driver_template, | |
10696 | sizeof(struct MPT3SAS_ADAPTER)); | |
10697 | if (!shost) | |
10698 | return -ENODEV; | |
10699 | ioc = shost_priv(shost); | |
10700 | memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER)); | |
10701 | ioc->hba_mpi_version_belonged = hba_mpi_version; | |
10702 | ioc->id = mpt3_ids++; | |
10703 | sprintf(ioc->driver_name, "%s", MPT3SAS_DRIVER_NAME); | |
998f26ae SPS |
10704 | switch (pdev->device) { |
10705 | case MPI26_MFGPAGE_DEVID_SAS3508: | |
10706 | case MPI26_MFGPAGE_DEVID_SAS3508_1: | |
10707 | case MPI26_MFGPAGE_DEVID_SAS3408: | |
10708 | case MPI26_MFGPAGE_DEVID_SAS3516: | |
10709 | case MPI26_MFGPAGE_DEVID_SAS3516_1: | |
10710 | case MPI26_MFGPAGE_DEVID_SAS3416: | |
15fd7c74 | 10711 | case MPI26_MFGPAGE_DEVID_SAS3616: |
eb9c7ce5 | 10712 | case MPI26_ATLAS_PCIe_SWITCH_DEVID: |
cc68e607 SP |
10713 | ioc->is_gen35_ioc = 1; |
10714 | break; | |
10715 | case MPI26_MFGPAGE_DEVID_CFG_SEC_3816: | |
10716 | case MPI26_MFGPAGE_DEVID_CFG_SEC_3916: | |
10717 | dev_info(&pdev->dev, | |
10718 | "HBA is in Configurable Secure mode\n"); | |
a8cc10e2 | 10719 | /* fall through */ |
6c2938f7 SP |
10720 | case MPI26_MFGPAGE_DEVID_HARD_SEC_3816: |
10721 | case MPI26_MFGPAGE_DEVID_HARD_SEC_3916: | |
cc68e607 | 10722 | ioc->is_aero_ioc = ioc->is_gen35_ioc = 1; |
998f26ae SPS |
10723 | break; |
10724 | default: | |
cc68e607 | 10725 | ioc->is_gen35_ioc = ioc->is_aero_ioc = 0; |
998f26ae | 10726 | } |
b130b0d5 SS |
10727 | if ((ioc->hba_mpi_version_belonged == MPI25_VERSION && |
10728 | pdev->revision >= SAS3_PCI_DEVICE_C0_REVISION) || | |
0bb337c9 SPS |
10729 | (ioc->hba_mpi_version_belonged == MPI26_VERSION)) { |
10730 | ioc->combined_reply_queue = 1; | |
10731 | if (ioc->is_gen35_ioc) | |
10732 | ioc->combined_reply_index_count = | |
10733 | MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G35; | |
10734 | else | |
10735 | ioc->combined_reply_index_count = | |
10736 | MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G3; | |
10737 | } | |
c84b06a4 SR |
10738 | break; |
10739 | default: | |
10740 | return -ENODEV; | |
10741 | } | |
f92363d1 | 10742 | |
f92363d1 | 10743 | INIT_LIST_HEAD(&ioc->list); |
08c4d550 | 10744 | spin_lock(&gioc_lock); |
f92363d1 | 10745 | list_add_tail(&ioc->list, &mpt3sas_ioc_list); |
08c4d550 | 10746 | spin_unlock(&gioc_lock); |
f92363d1 | 10747 | ioc->shost = shost; |
f92363d1 SR |
10748 | ioc->pdev = pdev; |
10749 | ioc->scsi_io_cb_idx = scsi_io_cb_idx; | |
10750 | ioc->tm_cb_idx = tm_cb_idx; | |
10751 | ioc->ctl_cb_idx = ctl_cb_idx; | |
10752 | ioc->base_cb_idx = base_cb_idx; | |
10753 | ioc->port_enable_cb_idx = port_enable_cb_idx; | |
10754 | ioc->transport_cb_idx = transport_cb_idx; | |
10755 | ioc->scsih_cb_idx = scsih_cb_idx; | |
10756 | ioc->config_cb_idx = config_cb_idx; | |
10757 | ioc->tm_tr_cb_idx = tm_tr_cb_idx; | |
10758 | ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx; | |
10759 | ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx; | |
10760 | ioc->logging_level = logging_level; | |
10761 | ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds; | |
43fb7c95 SR |
10762 | /* Host waits for minimum of six seconds */ |
10763 | ioc->max_shutdown_latency = IO_UNIT_CONTROL_SHUTDOWN_TIMEOUT; | |
3ac8e47b SP |
10764 | /* |
10765 | * Enable MEMORY MOVE support flag. | |
10766 | */ | |
10767 | ioc->drv_support_bitmap |= MPT_DRV_SUPPORT_BITMAP_MEMMOVE; | |
8dc8d29a SR |
10768 | |
10769 | ioc->enable_sdev_max_qd = enable_sdev_max_qd; | |
10770 | ||
f92363d1 SR |
10771 | /* misc semaphores and spin locks */ |
10772 | mutex_init(&ioc->reset_in_progress_mutex); | |
08c4d550 SR |
10773 | /* initializing pci_access_mutex lock */ |
10774 | mutex_init(&ioc->pci_access_mutex); | |
f92363d1 SR |
10775 | spin_lock_init(&ioc->ioc_reset_in_progress_lock); |
10776 | spin_lock_init(&ioc->scsi_lookup_lock); | |
10777 | spin_lock_init(&ioc->sas_device_lock); | |
10778 | spin_lock_init(&ioc->sas_node_lock); | |
10779 | spin_lock_init(&ioc->fw_event_lock); | |
10780 | spin_lock_init(&ioc->raid_device_lock); | |
d88e1eab | 10781 | spin_lock_init(&ioc->pcie_device_lock); |
f92363d1 SR |
10782 | spin_lock_init(&ioc->diag_trigger_lock); |
10783 | ||
10784 | INIT_LIST_HEAD(&ioc->sas_device_list); | |
10785 | INIT_LIST_HEAD(&ioc->sas_device_init_list); | |
10786 | INIT_LIST_HEAD(&ioc->sas_expander_list); | |
22a923c3 | 10787 | INIT_LIST_HEAD(&ioc->enclosure_list); |
d88e1eab SPS |
10788 | INIT_LIST_HEAD(&ioc->pcie_device_list); |
10789 | INIT_LIST_HEAD(&ioc->pcie_device_init_list); | |
f92363d1 SR |
10790 | INIT_LIST_HEAD(&ioc->fw_event_list); |
10791 | INIT_LIST_HEAD(&ioc->raid_device_list); | |
10792 | INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list); | |
10793 | INIT_LIST_HEAD(&ioc->delayed_tr_list); | |
fd0331b3 SS |
10794 | INIT_LIST_HEAD(&ioc->delayed_sc_list); |
10795 | INIT_LIST_HEAD(&ioc->delayed_event_ack_list); | |
f92363d1 | 10796 | INIT_LIST_HEAD(&ioc->delayed_tr_volume_list); |
cf9bd21a | 10797 | INIT_LIST_HEAD(&ioc->reply_queue_list); |
b326db46 | 10798 | INIT_LIST_HEAD(&ioc->port_table_list); |
f92363d1 | 10799 | |
c84b06a4 | 10800 | sprintf(ioc->name, "%s_cm%d", ioc->driver_name, ioc->id); |
d357e84d | 10801 | |
f92363d1 SR |
10802 | /* init shost parameters */ |
10803 | shost->max_cmd_len = 32; | |
10804 | shost->max_lun = max_lun; | |
10805 | shost->transportt = mpt3sas_transport_template; | |
10806 | shost->unique_id = ioc->id; | |
10807 | ||
0448f019 SPS |
10808 | if (ioc->is_mcpu_endpoint) { |
10809 | /* mCPU MPI support 64K max IO */ | |
10810 | shost->max_sectors = 128; | |
919d8a3f JP |
10811 | ioc_info(ioc, "The max_sectors value is set to %d\n", |
10812 | shost->max_sectors); | |
0448f019 SPS |
10813 | } else { |
10814 | if (max_sectors != 0xFFFF) { | |
10815 | if (max_sectors < 64) { | |
10816 | shost->max_sectors = 64; | |
919d8a3f JP |
10817 | ioc_warn(ioc, "Invalid value %d passed for max_sectors, range is 64 to 32767. Assigning value of 64.\n", |
10818 | max_sectors); | |
0448f019 SPS |
10819 | } else if (max_sectors > 32767) { |
10820 | shost->max_sectors = 32767; | |
919d8a3f JP |
10821 | ioc_warn(ioc, "Invalid value %d passed for max_sectors, range is 64 to 32767.Assigning default value of 32767.\n", |
10822 | max_sectors); | |
0448f019 SPS |
10823 | } else { |
10824 | shost->max_sectors = max_sectors & 0xFFFE; | |
919d8a3f JP |
10825 | ioc_info(ioc, "The max_sectors value is set to %d\n", |
10826 | shost->max_sectors); | |
0448f019 | 10827 | } |
f92363d1 SR |
10828 | } |
10829 | } | |
f92363d1 SR |
10830 | /* register EEDP capabilities with SCSI layer */ |
10831 | if (prot_mask > 0) | |
10832 | scsi_host_set_prot(shost, prot_mask); | |
10833 | else | |
10834 | scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION | |
10835 | | SHOST_DIF_TYPE2_PROTECTION | |
10836 | | SHOST_DIF_TYPE3_PROTECTION); | |
10837 | ||
10838 | scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC); | |
10839 | ||
10840 | /* event thread */ | |
10841 | snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name), | |
c84b06a4 | 10842 | "fw_event_%s%d", ioc->driver_name, ioc->id); |
bdff785e | 10843 | ioc->firmware_event_thread = alloc_ordered_workqueue( |
864449ee | 10844 | ioc->firmware_event_name, 0); |
f92363d1 | 10845 | if (!ioc->firmware_event_thread) { |
919d8a3f JP |
10846 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
10847 | __FILE__, __LINE__, __func__); | |
b65f1d4d | 10848 | rv = -ENODEV; |
f92363d1 SR |
10849 | goto out_thread_fail; |
10850 | } | |
10851 | ||
10852 | ioc->is_driver_loading = 1; | |
10853 | if ((mpt3sas_base_attach(ioc))) { | |
919d8a3f JP |
10854 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
10855 | __FILE__, __LINE__, __func__); | |
b65f1d4d | 10856 | rv = -ENODEV; |
f92363d1 SR |
10857 | goto out_attach_fail; |
10858 | } | |
7786ab6a | 10859 | |
7786ab6a SR |
10860 | if (ioc->is_warpdrive) { |
10861 | if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) | |
10862 | ioc->hide_drives = 0; | |
10863 | else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS) | |
10864 | ioc->hide_drives = 1; | |
10865 | else { | |
c84b06a4 | 10866 | if (mpt3sas_get_num_volumes(ioc)) |
7786ab6a SR |
10867 | ioc->hide_drives = 1; |
10868 | else | |
10869 | ioc->hide_drives = 0; | |
10870 | } | |
10871 | } else | |
10872 | ioc->hide_drives = 0; | |
7786ab6a | 10873 | |
b65f1d4d SR |
10874 | rv = scsi_add_host(shost, &pdev->dev); |
10875 | if (rv) { | |
919d8a3f JP |
10876 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
10877 | __FILE__, __LINE__, __func__); | |
4dc06fd8 RS |
10878 | goto out_add_shost_fail; |
10879 | } | |
10880 | ||
f92363d1 SR |
10881 | scsi_scan_host(shost); |
10882 | return 0; | |
4dc06fd8 RS |
10883 | out_add_shost_fail: |
10884 | mpt3sas_base_detach(ioc); | |
f92363d1 SR |
10885 | out_attach_fail: |
10886 | destroy_workqueue(ioc->firmware_event_thread); | |
10887 | out_thread_fail: | |
08c4d550 | 10888 | spin_lock(&gioc_lock); |
f92363d1 | 10889 | list_del(&ioc->list); |
08c4d550 | 10890 | spin_unlock(&gioc_lock); |
f92363d1 | 10891 | scsi_host_put(shost); |
b65f1d4d | 10892 | return rv; |
f92363d1 SR |
10893 | } |
10894 | ||
10895 | #ifdef CONFIG_PM | |
10896 | /** | |
8a7e4c24 | 10897 | * scsih_suspend - power management suspend main entry point |
f92363d1 SR |
10898 | * @pdev: PCI device struct |
10899 | * @state: PM state change to (usually PCI_D3) | |
10900 | * | |
4beb4867 | 10901 | * Return: 0 success, anything else error. |
f92363d1 | 10902 | */ |
8bbb1cf6 | 10903 | static int |
8a7e4c24 | 10904 | scsih_suspend(struct pci_dev *pdev, pm_message_t state) |
f92363d1 SR |
10905 | { |
10906 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10907 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10908 | pci_power_t device_state; | |
10909 | ||
10910 | mpt3sas_base_stop_watchdog(ioc); | |
10911 | flush_scheduled_work(); | |
10912 | scsi_block_requests(shost); | |
43fb7c95 | 10913 | _scsih_nvme_shutdown(ioc); |
f92363d1 | 10914 | device_state = pci_choose_state(pdev, state); |
919d8a3f JP |
10915 | ioc_info(ioc, "pdev=0x%p, slot=%s, entering operating state [D%d]\n", |
10916 | pdev, pci_name(pdev), device_state); | |
f92363d1 SR |
10917 | |
10918 | pci_save_state(pdev); | |
10919 | mpt3sas_base_free_resources(ioc); | |
10920 | pci_set_power_state(pdev, device_state); | |
10921 | return 0; | |
10922 | } | |
10923 | ||
10924 | /** | |
8a7e4c24 | 10925 | * scsih_resume - power management resume main entry point |
f92363d1 SR |
10926 | * @pdev: PCI device struct |
10927 | * | |
4beb4867 | 10928 | * Return: 0 success, anything else error. |
f92363d1 | 10929 | */ |
8bbb1cf6 | 10930 | static int |
8a7e4c24 | 10931 | scsih_resume(struct pci_dev *pdev) |
f92363d1 SR |
10932 | { |
10933 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10934 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10935 | pci_power_t device_state = pdev->current_state; | |
10936 | int r; | |
10937 | ||
919d8a3f JP |
10938 | ioc_info(ioc, "pdev=0x%p, slot=%s, previous operating state [D%d]\n", |
10939 | pdev, pci_name(pdev), device_state); | |
f92363d1 SR |
10940 | |
10941 | pci_set_power_state(pdev, PCI_D0); | |
10942 | pci_enable_wake(pdev, PCI_D0, 0); | |
10943 | pci_restore_state(pdev); | |
10944 | ioc->pdev = pdev; | |
10945 | r = mpt3sas_base_map_resources(ioc); | |
10946 | if (r) | |
10947 | return r; | |
13d01df5 | 10948 | ioc_info(ioc, "Issuing Hard Reset as part of OS Resume\n"); |
98c56ad3 | 10949 | mpt3sas_base_hard_reset_handler(ioc, SOFT_RESET); |
f92363d1 SR |
10950 | scsi_unblock_requests(shost); |
10951 | mpt3sas_base_start_watchdog(ioc); | |
10952 | return 0; | |
10953 | } | |
10954 | #endif /* CONFIG_PM */ | |
10955 | ||
10956 | /** | |
8a7e4c24 | 10957 | * scsih_pci_error_detected - Called when a PCI error is detected. |
f92363d1 SR |
10958 | * @pdev: PCI device struct |
10959 | * @state: PCI channel state | |
10960 | * | |
10961 | * Description: Called when a PCI error is detected. | |
10962 | * | |
4beb4867 | 10963 | * Return: PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT. |
f92363d1 | 10964 | */ |
8bbb1cf6 | 10965 | static pci_ers_result_t |
8a7e4c24 | 10966 | scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
f92363d1 SR |
10967 | { |
10968 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10969 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10970 | ||
919d8a3f | 10971 | ioc_info(ioc, "PCI error: detected callback, state(%d)!!\n", state); |
f92363d1 SR |
10972 | |
10973 | switch (state) { | |
10974 | case pci_channel_io_normal: | |
10975 | return PCI_ERS_RESULT_CAN_RECOVER; | |
10976 | case pci_channel_io_frozen: | |
10977 | /* Fatal error, prepare for slot reset */ | |
10978 | ioc->pci_error_recovery = 1; | |
10979 | scsi_block_requests(ioc->shost); | |
10980 | mpt3sas_base_stop_watchdog(ioc); | |
10981 | mpt3sas_base_free_resources(ioc); | |
10982 | return PCI_ERS_RESULT_NEED_RESET; | |
10983 | case pci_channel_io_perm_failure: | |
10984 | /* Permanent error, prepare for device removal */ | |
10985 | ioc->pci_error_recovery = 1; | |
10986 | mpt3sas_base_stop_watchdog(ioc); | |
10987 | _scsih_flush_running_cmds(ioc); | |
10988 | return PCI_ERS_RESULT_DISCONNECT; | |
10989 | } | |
10990 | return PCI_ERS_RESULT_NEED_RESET; | |
10991 | } | |
10992 | ||
10993 | /** | |
8a7e4c24 | 10994 | * scsih_pci_slot_reset - Called when PCI slot has been reset. |
f92363d1 SR |
10995 | * @pdev: PCI device struct |
10996 | * | |
10997 | * Description: This routine is called by the pci error recovery | |
10998 | * code after the PCI slot has been reset, just before we | |
10999 | * should resume normal operations. | |
11000 | */ | |
8bbb1cf6 | 11001 | static pci_ers_result_t |
8a7e4c24 | 11002 | scsih_pci_slot_reset(struct pci_dev *pdev) |
f92363d1 SR |
11003 | { |
11004 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
11005 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
11006 | int rc; | |
11007 | ||
919d8a3f | 11008 | ioc_info(ioc, "PCI error: slot reset callback!!\n"); |
f92363d1 SR |
11009 | |
11010 | ioc->pci_error_recovery = 0; | |
11011 | ioc->pdev = pdev; | |
11012 | pci_restore_state(pdev); | |
11013 | rc = mpt3sas_base_map_resources(ioc); | |
11014 | if (rc) | |
11015 | return PCI_ERS_RESULT_DISCONNECT; | |
11016 | ||
13d01df5 | 11017 | ioc_info(ioc, "Issuing Hard Reset as part of PCI Slot Reset\n"); |
98c56ad3 | 11018 | rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
f92363d1 | 11019 | |
919d8a3f JP |
11020 | ioc_warn(ioc, "hard reset: %s\n", |
11021 | (rc == 0) ? "success" : "failed"); | |
f92363d1 SR |
11022 | |
11023 | if (!rc) | |
11024 | return PCI_ERS_RESULT_RECOVERED; | |
11025 | else | |
11026 | return PCI_ERS_RESULT_DISCONNECT; | |
11027 | } | |
11028 | ||
11029 | /** | |
8a7e4c24 | 11030 | * scsih_pci_resume() - resume normal ops after PCI reset |
f92363d1 SR |
11031 | * @pdev: pointer to PCI device |
11032 | * | |
11033 | * Called when the error recovery driver tells us that its | |
11034 | * OK to resume normal operation. Use completion to allow | |
11035 | * halted scsi ops to resume. | |
11036 | */ | |
8bbb1cf6 | 11037 | static void |
8a7e4c24 | 11038 | scsih_pci_resume(struct pci_dev *pdev) |
f92363d1 SR |
11039 | { |
11040 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
11041 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
11042 | ||
919d8a3f | 11043 | ioc_info(ioc, "PCI error: resume callback!!\n"); |
f92363d1 | 11044 | |
f92363d1 SR |
11045 | mpt3sas_base_start_watchdog(ioc); |
11046 | scsi_unblock_requests(ioc->shost); | |
11047 | } | |
11048 | ||
11049 | /** | |
8a7e4c24 | 11050 | * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers |
f92363d1 SR |
11051 | * @pdev: pointer to PCI device |
11052 | */ | |
8bbb1cf6 | 11053 | static pci_ers_result_t |
8a7e4c24 | 11054 | scsih_pci_mmio_enabled(struct pci_dev *pdev) |
f92363d1 SR |
11055 | { |
11056 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
11057 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
11058 | ||
919d8a3f | 11059 | ioc_info(ioc, "PCI error: mmio enabled callback!!\n"); |
f92363d1 SR |
11060 | |
11061 | /* TODO - dump whatever for debugging purposes */ | |
11062 | ||
83c3d340 KW |
11063 | /* This called only if scsih_pci_error_detected returns |
11064 | * PCI_ERS_RESULT_CAN_RECOVER. Read/write to the device still | |
11065 | * works, no need to reset slot. | |
11066 | */ | |
11067 | return PCI_ERS_RESULT_RECOVERED; | |
f92363d1 SR |
11068 | } |
11069 | ||
307d9075 AM |
11070 | /** |
11071 | * scsih__ncq_prio_supp - Check for NCQ command priority support | |
11072 | * @sdev: scsi device struct | |
11073 | * | |
11074 | * This is called when a user indicates they would like to enable | |
11075 | * ncq command priorities. This works only on SATA devices. | |
11076 | */ | |
11077 | bool scsih_ncq_prio_supp(struct scsi_device *sdev) | |
11078 | { | |
11079 | unsigned char *buf; | |
11080 | bool ncq_prio_supp = false; | |
11081 | ||
11082 | if (!scsi_device_supports_vpd(sdev)) | |
11083 | return ncq_prio_supp; | |
11084 | ||
11085 | buf = kmalloc(SCSI_VPD_PG_LEN, GFP_KERNEL); | |
11086 | if (!buf) | |
11087 | return ncq_prio_supp; | |
11088 | ||
11089 | if (!scsi_get_vpd_page(sdev, 0x89, buf, SCSI_VPD_PG_LEN)) | |
11090 | ncq_prio_supp = (buf[213] >> 4) & 1; | |
11091 | ||
11092 | kfree(buf); | |
11093 | return ncq_prio_supp; | |
11094 | } | |
c84b06a4 SR |
11095 | /* |
11096 | * The pci device ids are defined in mpi/mpi2_cnfg.h. | |
11097 | */ | |
11098 | static const struct pci_device_id mpt3sas_pci_table[] = { | |
11099 | /* Spitfire ~ 2004 */ | |
11100 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004, | |
11101 | PCI_ANY_ID, PCI_ANY_ID }, | |
11102 | /* Falcon ~ 2008 */ | |
11103 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008, | |
11104 | PCI_ANY_ID, PCI_ANY_ID }, | |
11105 | /* Liberator ~ 2108 */ | |
11106 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1, | |
11107 | PCI_ANY_ID, PCI_ANY_ID }, | |
11108 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2, | |
11109 | PCI_ANY_ID, PCI_ANY_ID }, | |
11110 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3, | |
11111 | PCI_ANY_ID, PCI_ANY_ID }, | |
11112 | /* Meteor ~ 2116 */ | |
11113 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1, | |
11114 | PCI_ANY_ID, PCI_ANY_ID }, | |
11115 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2, | |
11116 | PCI_ANY_ID, PCI_ANY_ID }, | |
11117 | /* Thunderbolt ~ 2208 */ | |
11118 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1, | |
11119 | PCI_ANY_ID, PCI_ANY_ID }, | |
11120 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2, | |
11121 | PCI_ANY_ID, PCI_ANY_ID }, | |
11122 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3, | |
11123 | PCI_ANY_ID, PCI_ANY_ID }, | |
11124 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4, | |
11125 | PCI_ANY_ID, PCI_ANY_ID }, | |
11126 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5, | |
11127 | PCI_ANY_ID, PCI_ANY_ID }, | |
11128 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6, | |
11129 | PCI_ANY_ID, PCI_ANY_ID }, | |
11130 | /* Mustang ~ 2308 */ | |
11131 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1, | |
11132 | PCI_ANY_ID, PCI_ANY_ID }, | |
11133 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2, | |
11134 | PCI_ANY_ID, PCI_ANY_ID }, | |
11135 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3, | |
11136 | PCI_ANY_ID, PCI_ANY_ID }, | |
1244790d | 11137 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP, |
c520691b | 11138 | PCI_ANY_ID, PCI_ANY_ID }, |
8f838450 SP |
11139 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP_1, |
11140 | PCI_ANY_ID, PCI_ANY_ID }, | |
c84b06a4 SR |
11141 | /* SSS6200 */ |
11142 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200, | |
11143 | PCI_ANY_ID, PCI_ANY_ID }, | |
11144 | /* Fury ~ 3004 and 3008 */ | |
11145 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3004, | |
11146 | PCI_ANY_ID, PCI_ANY_ID }, | |
11147 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3008, | |
11148 | PCI_ANY_ID, PCI_ANY_ID }, | |
11149 | /* Invader ~ 3108 */ | |
11150 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_1, | |
11151 | PCI_ANY_ID, PCI_ANY_ID }, | |
11152 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_2, | |
11153 | PCI_ANY_ID, PCI_ANY_ID }, | |
11154 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_5, | |
11155 | PCI_ANY_ID, PCI_ANY_ID }, | |
11156 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_6, | |
11157 | PCI_ANY_ID, PCI_ANY_ID }, | |
b130b0d5 SS |
11158 | /* Cutlass ~ 3216 and 3224 */ |
11159 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3216, | |
11160 | PCI_ANY_ID, PCI_ANY_ID }, | |
11161 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3224, | |
11162 | PCI_ANY_ID, PCI_ANY_ID }, | |
11163 | /* Intruder ~ 3316 and 3324 */ | |
11164 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_1, | |
11165 | PCI_ANY_ID, PCI_ANY_ID }, | |
11166 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_2, | |
11167 | PCI_ANY_ID, PCI_ANY_ID }, | |
11168 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_3, | |
11169 | PCI_ANY_ID, PCI_ANY_ID }, | |
11170 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_4, | |
11171 | PCI_ANY_ID, PCI_ANY_ID }, | |
11172 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_1, | |
11173 | PCI_ANY_ID, PCI_ANY_ID }, | |
11174 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_2, | |
11175 | PCI_ANY_ID, PCI_ANY_ID }, | |
11176 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_3, | |
11177 | PCI_ANY_ID, PCI_ANY_ID }, | |
11178 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_4, | |
11179 | PCI_ANY_ID, PCI_ANY_ID }, | |
998f26ae SPS |
11180 | /* Ventura, Crusader, Harpoon & Tomcat ~ 3516, 3416, 3508 & 3408*/ |
11181 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3508, | |
11182 | PCI_ANY_ID, PCI_ANY_ID }, | |
11183 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3508_1, | |
11184 | PCI_ANY_ID, PCI_ANY_ID }, | |
11185 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3408, | |
11186 | PCI_ANY_ID, PCI_ANY_ID }, | |
11187 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3516, | |
11188 | PCI_ANY_ID, PCI_ANY_ID }, | |
11189 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3516_1, | |
11190 | PCI_ANY_ID, PCI_ANY_ID }, | |
11191 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3416, | |
11192 | PCI_ANY_ID, PCI_ANY_ID }, | |
15fd7c74 SR |
11193 | /* Mercator ~ 3616*/ |
11194 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3616, | |
11195 | PCI_ANY_ID, PCI_ANY_ID }, | |
6c2938f7 SP |
11196 | |
11197 | /* Aero SI 0x00E1 Configurable Secure | |
11198 | * 0x00E2 Hard Secure | |
11199 | */ | |
11200 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_CFG_SEC_3916, | |
11201 | PCI_ANY_ID, PCI_ANY_ID }, | |
11202 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_HARD_SEC_3916, | |
11203 | PCI_ANY_ID, PCI_ANY_ID }, | |
11204 | ||
eb9c7ce5 SP |
11205 | /* Atlas PCIe Switch Management Port */ |
11206 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_ATLAS_PCIe_SWITCH_DEVID, | |
11207 | PCI_ANY_ID, PCI_ANY_ID }, | |
11208 | ||
6c2938f7 SP |
11209 | /* Sea SI 0x00E5 Configurable Secure |
11210 | * 0x00E6 Hard Secure | |
11211 | */ | |
11212 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_CFG_SEC_3816, | |
11213 | PCI_ANY_ID, PCI_ANY_ID }, | |
11214 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_HARD_SEC_3816, | |
11215 | PCI_ANY_ID, PCI_ANY_ID }, | |
11216 | ||
c84b06a4 SR |
11217 | {0} /* Terminating entry */ |
11218 | }; | |
11219 | MODULE_DEVICE_TABLE(pci, mpt3sas_pci_table); | |
11220 | ||
11221 | static struct pci_error_handlers _mpt3sas_err_handler = { | |
11222 | .error_detected = scsih_pci_error_detected, | |
11223 | .mmio_enabled = scsih_pci_mmio_enabled, | |
11224 | .slot_reset = scsih_pci_slot_reset, | |
11225 | .resume = scsih_pci_resume, | |
11226 | }; | |
11227 | ||
11228 | static struct pci_driver mpt3sas_driver = { | |
11229 | .name = MPT3SAS_DRIVER_NAME, | |
11230 | .id_table = mpt3sas_pci_table, | |
11231 | .probe = _scsih_probe, | |
11232 | .remove = scsih_remove, | |
11233 | .shutdown = scsih_shutdown, | |
11234 | .err_handler = &_mpt3sas_err_handler, | |
11235 | #ifdef CONFIG_PM | |
11236 | .suspend = scsih_suspend, | |
11237 | .resume = scsih_resume, | |
11238 | #endif | |
11239 | }; | |
11240 | ||
f92363d1 | 11241 | /** |
8a7e4c24 | 11242 | * scsih_init - main entry point for this driver. |
f92363d1 | 11243 | * |
4beb4867 | 11244 | * Return: 0 success, anything else error. |
f92363d1 | 11245 | */ |
8bbb1cf6 | 11246 | static int |
8a7e4c24 | 11247 | scsih_init(void) |
f92363d1 | 11248 | { |
c84b06a4 SR |
11249 | mpt2_ids = 0; |
11250 | mpt3_ids = 0; | |
f92363d1 | 11251 | |
f92363d1 SR |
11252 | mpt3sas_base_initialize_callback_handler(); |
11253 | ||
11254 | /* queuecommand callback hander */ | |
11255 | scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done); | |
11256 | ||
6c7abffc | 11257 | /* task management callback handler */ |
f92363d1 SR |
11258 | tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done); |
11259 | ||
11260 | /* base internal commands callback handler */ | |
11261 | base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done); | |
11262 | port_enable_cb_idx = mpt3sas_base_register_callback_handler( | |
11263 | mpt3sas_port_enable_done); | |
11264 | ||
11265 | /* transport internal commands callback handler */ | |
11266 | transport_cb_idx = mpt3sas_base_register_callback_handler( | |
11267 | mpt3sas_transport_done); | |
11268 | ||
11269 | /* scsih internal commands callback handler */ | |
11270 | scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done); | |
11271 | ||
11272 | /* configuration page API internal commands callback handler */ | |
11273 | config_cb_idx = mpt3sas_base_register_callback_handler( | |
11274 | mpt3sas_config_done); | |
11275 | ||
11276 | /* ctl module callback handler */ | |
11277 | ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done); | |
11278 | ||
11279 | tm_tr_cb_idx = mpt3sas_base_register_callback_handler( | |
11280 | _scsih_tm_tr_complete); | |
11281 | ||
11282 | tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler( | |
11283 | _scsih_tm_volume_tr_complete); | |
11284 | ||
11285 | tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler( | |
11286 | _scsih_sas_control_complete); | |
11287 | ||
7497392a | 11288 | return 0; |
f92363d1 SR |
11289 | } |
11290 | ||
11291 | /** | |
7497392a | 11292 | * scsih_exit - exit point for this driver (when it is a module). |
f92363d1 | 11293 | * |
4beb4867 | 11294 | * Return: 0 success, anything else error. |
f92363d1 | 11295 | */ |
8bbb1cf6 | 11296 | static void |
8a7e4c24 | 11297 | scsih_exit(void) |
f92363d1 | 11298 | { |
f92363d1 SR |
11299 | |
11300 | mpt3sas_base_release_callback_handler(scsi_io_cb_idx); | |
11301 | mpt3sas_base_release_callback_handler(tm_cb_idx); | |
11302 | mpt3sas_base_release_callback_handler(base_cb_idx); | |
11303 | mpt3sas_base_release_callback_handler(port_enable_cb_idx); | |
11304 | mpt3sas_base_release_callback_handler(transport_cb_idx); | |
11305 | mpt3sas_base_release_callback_handler(scsih_cb_idx); | |
11306 | mpt3sas_base_release_callback_handler(config_cb_idx); | |
11307 | mpt3sas_base_release_callback_handler(ctl_cb_idx); | |
11308 | ||
11309 | mpt3sas_base_release_callback_handler(tm_tr_cb_idx); | |
11310 | mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx); | |
11311 | mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx); | |
11312 | ||
11313 | /* raid transport support */ | |
c84b06a4 SR |
11314 | if (hbas_to_enumerate != 1) |
11315 | raid_class_release(mpt3sas_raid_template); | |
11316 | if (hbas_to_enumerate != 2) | |
11317 | raid_class_release(mpt2sas_raid_template); | |
f92363d1 SR |
11318 | sas_release_transport(mpt3sas_transport_template); |
11319 | } | |
7786ab6a | 11320 | |
c84b06a4 SR |
11321 | /** |
11322 | * _mpt3sas_init - main entry point for this driver. | |
11323 | * | |
4beb4867 | 11324 | * Return: 0 success, anything else error. |
c84b06a4 SR |
11325 | */ |
11326 | static int __init | |
11327 | _mpt3sas_init(void) | |
11328 | { | |
11329 | int error; | |
11330 | ||
11331 | pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME, | |
11332 | MPT3SAS_DRIVER_VERSION); | |
11333 | ||
11334 | mpt3sas_transport_template = | |
11335 | sas_attach_transport(&mpt3sas_transport_functions); | |
11336 | if (!mpt3sas_transport_template) | |
11337 | return -ENODEV; | |
11338 | ||
11339 | /* No need attach mpt3sas raid functions template | |
11340 | * if hbas_to_enumarate value is one. | |
11341 | */ | |
11342 | if (hbas_to_enumerate != 1) { | |
11343 | mpt3sas_raid_template = | |
11344 | raid_class_attach(&mpt3sas_raid_functions); | |
11345 | if (!mpt3sas_raid_template) { | |
11346 | sas_release_transport(mpt3sas_transport_template); | |
11347 | return -ENODEV; | |
11348 | } | |
11349 | } | |
11350 | ||
11351 | /* No need to attach mpt2sas raid functions template | |
11352 | * if hbas_to_enumarate value is two | |
11353 | */ | |
11354 | if (hbas_to_enumerate != 2) { | |
11355 | mpt2sas_raid_template = | |
11356 | raid_class_attach(&mpt2sas_raid_functions); | |
11357 | if (!mpt2sas_raid_template) { | |
11358 | sas_release_transport(mpt3sas_transport_template); | |
11359 | return -ENODEV; | |
11360 | } | |
11361 | } | |
11362 | ||
11363 | error = scsih_init(); | |
11364 | if (error) { | |
11365 | scsih_exit(); | |
11366 | return error; | |
11367 | } | |
11368 | ||
11369 | mpt3sas_ctl_init(hbas_to_enumerate); | |
11370 | ||
11371 | error = pci_register_driver(&mpt3sas_driver); | |
11372 | if (error) | |
11373 | scsih_exit(); | |
11374 | ||
11375 | return error; | |
11376 | } | |
11377 | ||
11378 | /** | |
11379 | * _mpt3sas_exit - exit point for this driver (when it is a module). | |
11380 | * | |
11381 | */ | |
11382 | static void __exit | |
11383 | _mpt3sas_exit(void) | |
11384 | { | |
11385 | pr_info("mpt3sas version %s unloading\n", | |
11386 | MPT3SAS_DRIVER_VERSION); | |
11387 | ||
c84b06a4 SR |
11388 | mpt3sas_ctl_exit(hbas_to_enumerate); |
11389 | ||
87b3576e C |
11390 | pci_unregister_driver(&mpt3sas_driver); |
11391 | ||
c84b06a4 SR |
11392 | scsih_exit(); |
11393 | } | |
11394 | ||
11395 | module_init(_mpt3sas_init); | |
11396 | module_exit(_mpt3sas_exit); |