Commit | Line | Data |
---|---|---|
f92363d1 SR |
1 | /* |
2 | * Scsi Host Layer for MPT (Message Passing Technology) based controllers | |
3 | * | |
4 | * This code is based on drivers/scsi/mpt3sas/mpt3sas_scsih.c | |
a4ffce0d | 5 | * Copyright (C) 2012-2014 LSI Corporation |
a03bd153 SR |
6 | * Copyright (C) 2013-2014 Avago Technologies |
7 | * (mailto: MPT-FusionLinux.pdl@avagotech.com) | |
f92363d1 SR |
8 | * |
9 | * This program is free software; you can redistribute it and/or | |
10 | * modify it under the terms of the GNU General Public License | |
11 | * as published by the Free Software Foundation; either version 2 | |
12 | * of the License, or (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * NO WARRANTY | |
20 | * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR | |
21 | * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT | |
22 | * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, | |
23 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is | |
24 | * solely responsible for determining the appropriateness of using and | |
25 | * distributing the Program and assumes all risks associated with its | |
26 | * exercise of rights under this Agreement, including but not limited to | |
27 | * the risks and costs of program errors, damage to or loss of data, | |
28 | * programs or equipment, and unavailability or interruption of operations. | |
29 | ||
30 | * DISCLAIMER OF LIABILITY | |
31 | * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY | |
32 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
33 | * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND | |
34 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | |
35 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
36 | * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED | |
37 | * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES | |
38 | ||
39 | * You should have received a copy of the GNU General Public License | |
40 | * along with this program; if not, write to the Free Software | |
41 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | |
42 | * USA. | |
43 | */ | |
44 | ||
f92363d1 SR |
45 | #include <linux/module.h> |
46 | #include <linux/kernel.h> | |
47 | #include <linux/init.h> | |
48 | #include <linux/errno.h> | |
49 | #include <linux/blkdev.h> | |
50 | #include <linux/sched.h> | |
51 | #include <linux/workqueue.h> | |
52 | #include <linux/delay.h> | |
53 | #include <linux/pci.h> | |
ffdadd68 | 54 | #include <linux/pci-aspm.h> |
f92363d1 SR |
55 | #include <linux/interrupt.h> |
56 | #include <linux/aer.h> | |
57 | #include <linux/raid_class.h> | |
7786ab6a | 58 | #include <asm/unaligned.h> |
f92363d1 SR |
59 | |
60 | #include "mpt3sas_base.h" | |
61 | ||
f92363d1 | 62 | #define RAID_CHANNEL 1 |
d88e1eab SPS |
63 | |
64 | #define PCIE_CHANNEL 2 | |
65 | ||
f92363d1 SR |
66 | /* forward proto's */ |
67 | static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc, | |
68 | struct _sas_node *sas_expander); | |
69 | static void _firmware_event_work(struct work_struct *work); | |
70 | ||
71 | static void _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc, | |
72 | struct _sas_device *sas_device); | |
73 | static int _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, | |
74 | u8 retry_count, u8 is_pd); | |
c102e00c | 75 | static int _scsih_pcie_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle); |
3075ac49 SPS |
76 | static void _scsih_pcie_device_remove_from_sml(struct MPT3SAS_ADAPTER *ioc, |
77 | struct _pcie_device *pcie_device); | |
4318c734 SPS |
78 | static void |
79 | _scsih_pcie_check_device(struct MPT3SAS_ADAPTER *ioc, u16 handle); | |
f92363d1 SR |
80 | static u8 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid); |
81 | ||
f92363d1 SR |
82 | /* global parameters */ |
83 | LIST_HEAD(mpt3sas_ioc_list); | |
08c4d550 SR |
84 | /* global ioc lock for list operations */ |
85 | DEFINE_SPINLOCK(gioc_lock); | |
f92363d1 | 86 | |
c84b06a4 SR |
87 | MODULE_AUTHOR(MPT3SAS_AUTHOR); |
88 | MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION); | |
89 | MODULE_LICENSE("GPL"); | |
90 | MODULE_VERSION(MPT3SAS_DRIVER_VERSION); | |
91 | MODULE_ALIAS("mpt2sas"); | |
92 | ||
f92363d1 SR |
93 | /* local parameters */ |
94 | static u8 scsi_io_cb_idx = -1; | |
95 | static u8 tm_cb_idx = -1; | |
96 | static u8 ctl_cb_idx = -1; | |
97 | static u8 base_cb_idx = -1; | |
98 | static u8 port_enable_cb_idx = -1; | |
99 | static u8 transport_cb_idx = -1; | |
100 | static u8 scsih_cb_idx = -1; | |
101 | static u8 config_cb_idx = -1; | |
c84b06a4 SR |
102 | static int mpt2_ids; |
103 | static int mpt3_ids; | |
f92363d1 SR |
104 | |
105 | static u8 tm_tr_cb_idx = -1 ; | |
106 | static u8 tm_tr_volume_cb_idx = -1 ; | |
107 | static u8 tm_sas_control_cb_idx = -1; | |
108 | ||
109 | /* command line options */ | |
110 | static u32 logging_level; | |
111 | MODULE_PARM_DESC(logging_level, | |
112 | " bits for enabling additional logging info (default=0)"); | |
113 | ||
114 | ||
115 | static ushort max_sectors = 0xFFFF; | |
ab9f5adb | 116 | module_param(max_sectors, ushort, 0444); |
f92363d1 SR |
117 | MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767"); |
118 | ||
119 | ||
120 | static int missing_delay[2] = {-1, -1}; | |
ab9f5adb | 121 | module_param_array(missing_delay, int, NULL, 0444); |
f92363d1 SR |
122 | MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay"); |
123 | ||
124 | /* scsi-mid layer global parmeter is max_report_luns, which is 511 */ | |
125 | #define MPT3SAS_MAX_LUN (16895) | |
1abf635d | 126 | static u64 max_lun = MPT3SAS_MAX_LUN; |
ab9f5adb | 127 | module_param(max_lun, ullong, 0444); |
f92363d1 SR |
128 | MODULE_PARM_DESC(max_lun, " max lun, default=16895 "); |
129 | ||
c84b06a4 | 130 | static ushort hbas_to_enumerate; |
ab9f5adb | 131 | module_param(hbas_to_enumerate, ushort, 0444); |
c84b06a4 SR |
132 | MODULE_PARM_DESC(hbas_to_enumerate, |
133 | " 0 - enumerates both SAS 2.0 & SAS 3.0 generation HBAs\n \ | |
134 | 1 - enumerates only SAS 2.0 generation HBAs\n \ | |
135 | 2 - enumerates only SAS 3.0 generation HBAs (default=0)"); | |
f92363d1 SR |
136 | |
137 | /* diag_buffer_enable is bitwise | |
138 | * bit 0 set = TRACE | |
139 | * bit 1 set = SNAPSHOT | |
140 | * bit 2 set = EXTENDED | |
141 | * | |
142 | * Either bit can be set, or both | |
143 | */ | |
144 | static int diag_buffer_enable = -1; | |
ab9f5adb | 145 | module_param(diag_buffer_enable, int, 0444); |
f92363d1 SR |
146 | MODULE_PARM_DESC(diag_buffer_enable, |
147 | " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)"); | |
148 | static int disable_discovery = -1; | |
ab9f5adb | 149 | module_param(disable_discovery, int, 0444); |
f92363d1 SR |
150 | MODULE_PARM_DESC(disable_discovery, " disable discovery "); |
151 | ||
152 | ||
153 | /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */ | |
154 | static int prot_mask = -1; | |
ab9f5adb | 155 | module_param(prot_mask, int, 0444); |
f92363d1 SR |
156 | MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 "); |
157 | ||
158 | ||
159 | /* raid transport support */ | |
cf6bf971 C |
160 | static struct raid_template *mpt3sas_raid_template; |
161 | static struct raid_template *mpt2sas_raid_template; | |
f92363d1 SR |
162 | |
163 | ||
164 | /** | |
165 | * struct sense_info - common structure for obtaining sense keys | |
166 | * @skey: sense key | |
167 | * @asc: additional sense code | |
168 | * @ascq: additional sense code qualifier | |
169 | */ | |
170 | struct sense_info { | |
171 | u8 skey; | |
172 | u8 asc; | |
173 | u8 ascq; | |
174 | }; | |
175 | ||
176 | #define MPT3SAS_PROCESS_TRIGGER_DIAG (0xFFFB) | |
0f624c39 | 177 | #define MPT3SAS_TURN_ON_PFA_LED (0xFFFC) |
f92363d1 SR |
178 | #define MPT3SAS_PORT_ENABLE_COMPLETE (0xFFFD) |
179 | #define MPT3SAS_ABRT_TASK_SET (0xFFFE) | |
180 | #define MPT3SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF) | |
181 | /** | |
182 | * struct fw_event_work - firmware event struct | |
183 | * @list: link list framework | |
184 | * @work: work object (ioc->fault_reset_work_q) | |
f92363d1 SR |
185 | * @ioc: per adapter object |
186 | * @device_handle: device handle | |
187 | * @VF_ID: virtual function id | |
188 | * @VP_ID: virtual port id | |
189 | * @ignore: flag meaning this event has been marked to ignore | |
b8ac0cc7 JL |
190 | * @event: firmware event MPI2_EVENT_XXX defined in mpi2_ioc.h |
191 | * @refcount: kref for this event | |
f92363d1 SR |
192 | * @event_data: reply event data payload follows |
193 | * | |
194 | * This object stored on ioc->fw_event_list. | |
195 | */ | |
196 | struct fw_event_work { | |
197 | struct list_head list; | |
198 | struct work_struct work; | |
f92363d1 SR |
199 | |
200 | struct MPT3SAS_ADAPTER *ioc; | |
201 | u16 device_handle; | |
202 | u8 VF_ID; | |
203 | u8 VP_ID; | |
204 | u8 ignore; | |
205 | u16 event; | |
146b16c8 | 206 | struct kref refcount; |
35b62362 | 207 | char event_data[0] __aligned(4); |
f92363d1 SR |
208 | }; |
209 | ||
146b16c8 SR |
210 | static void fw_event_work_free(struct kref *r) |
211 | { | |
212 | kfree(container_of(r, struct fw_event_work, refcount)); | |
213 | } | |
214 | ||
215 | static void fw_event_work_get(struct fw_event_work *fw_work) | |
216 | { | |
217 | kref_get(&fw_work->refcount); | |
218 | } | |
219 | ||
220 | static void fw_event_work_put(struct fw_event_work *fw_work) | |
221 | { | |
222 | kref_put(&fw_work->refcount, fw_event_work_free); | |
223 | } | |
224 | ||
225 | static struct fw_event_work *alloc_fw_event_work(int len) | |
226 | { | |
227 | struct fw_event_work *fw_event; | |
228 | ||
229 | fw_event = kzalloc(sizeof(*fw_event) + len, GFP_ATOMIC); | |
230 | if (!fw_event) | |
231 | return NULL; | |
232 | ||
233 | kref_init(&fw_event->refcount); | |
234 | return fw_event; | |
235 | } | |
236 | ||
f92363d1 SR |
237 | /** |
238 | * struct _scsi_io_transfer - scsi io transfer | |
239 | * @handle: sas device handle (assigned by firmware) | |
240 | * @is_raid: flag set for hidden raid components | |
241 | * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE, | |
242 | * @data_length: data transfer length | |
243 | * @data_dma: dma pointer to data | |
244 | * @sense: sense data | |
245 | * @lun: lun number | |
246 | * @cdb_length: cdb length | |
247 | * @cdb: cdb contents | |
248 | * @timeout: timeout for this command | |
249 | * @VF_ID: virtual function id | |
250 | * @VP_ID: virtual port id | |
251 | * @valid_reply: flag set for reply message | |
252 | * @sense_length: sense length | |
253 | * @ioc_status: ioc status | |
254 | * @scsi_state: scsi state | |
255 | * @scsi_status: scsi staus | |
256 | * @log_info: log information | |
257 | * @transfer_length: data length transfer when there is a reply message | |
258 | * | |
259 | * Used for sending internal scsi commands to devices within this module. | |
260 | * Refer to _scsi_send_scsi_io(). | |
261 | */ | |
262 | struct _scsi_io_transfer { | |
263 | u16 handle; | |
264 | u8 is_raid; | |
265 | enum dma_data_direction dir; | |
266 | u32 data_length; | |
267 | dma_addr_t data_dma; | |
268 | u8 sense[SCSI_SENSE_BUFFERSIZE]; | |
269 | u32 lun; | |
270 | u8 cdb_length; | |
271 | u8 cdb[32]; | |
272 | u8 timeout; | |
273 | u8 VF_ID; | |
274 | u8 VP_ID; | |
275 | u8 valid_reply; | |
276 | /* the following bits are only valid when 'valid_reply = 1' */ | |
277 | u32 sense_length; | |
278 | u16 ioc_status; | |
279 | u8 scsi_state; | |
280 | u8 scsi_status; | |
281 | u32 log_info; | |
282 | u32 transfer_length; | |
283 | }; | |
284 | ||
f92363d1 SR |
285 | /** |
286 | * _scsih_set_debug_level - global setting of ioc->logging_level. | |
4beb4867 BVA |
287 | * @val: ? |
288 | * @kp: ? | |
f92363d1 SR |
289 | * |
290 | * Note: The logging levels are defined in mpt3sas_debug.h. | |
291 | */ | |
292 | static int | |
e4dca7b7 | 293 | _scsih_set_debug_level(const char *val, const struct kernel_param *kp) |
f92363d1 SR |
294 | { |
295 | int ret = param_set_int(val, kp); | |
296 | struct MPT3SAS_ADAPTER *ioc; | |
297 | ||
298 | if (ret) | |
299 | return ret; | |
300 | ||
301 | pr_info("setting logging_level(0x%08x)\n", logging_level); | |
08c4d550 | 302 | spin_lock(&gioc_lock); |
f92363d1 SR |
303 | list_for_each_entry(ioc, &mpt3sas_ioc_list, list) |
304 | ioc->logging_level = logging_level; | |
08c4d550 | 305 | spin_unlock(&gioc_lock); |
f92363d1 SR |
306 | return 0; |
307 | } | |
308 | module_param_call(logging_level, _scsih_set_debug_level, param_get_int, | |
309 | &logging_level, 0644); | |
310 | ||
311 | /** | |
312 | * _scsih_srch_boot_sas_address - search based on sas_address | |
313 | * @sas_address: sas address | |
314 | * @boot_device: boot device object from bios page 2 | |
315 | * | |
4beb4867 | 316 | * Return: 1 when there's a match, 0 means no match. |
f92363d1 SR |
317 | */ |
318 | static inline int | |
319 | _scsih_srch_boot_sas_address(u64 sas_address, | |
320 | Mpi2BootDeviceSasWwid_t *boot_device) | |
321 | { | |
322 | return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0; | |
323 | } | |
324 | ||
325 | /** | |
326 | * _scsih_srch_boot_device_name - search based on device name | |
327 | * @device_name: device name specified in INDENTIFY fram | |
328 | * @boot_device: boot device object from bios page 2 | |
329 | * | |
4beb4867 | 330 | * Return: 1 when there's a match, 0 means no match. |
f92363d1 SR |
331 | */ |
332 | static inline int | |
333 | _scsih_srch_boot_device_name(u64 device_name, | |
334 | Mpi2BootDeviceDeviceName_t *boot_device) | |
335 | { | |
336 | return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0; | |
337 | } | |
338 | ||
339 | /** | |
340 | * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot | |
341 | * @enclosure_logical_id: enclosure logical id | |
342 | * @slot_number: slot number | |
343 | * @boot_device: boot device object from bios page 2 | |
344 | * | |
4beb4867 | 345 | * Return: 1 when there's a match, 0 means no match. |
f92363d1 SR |
346 | */ |
347 | static inline int | |
348 | _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number, | |
349 | Mpi2BootDeviceEnclosureSlot_t *boot_device) | |
350 | { | |
351 | return (enclosure_logical_id == le64_to_cpu(boot_device-> | |
352 | EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device-> | |
353 | SlotNumber)) ? 1 : 0; | |
354 | } | |
355 | ||
356 | /** | |
357 | * _scsih_is_boot_device - search for matching boot device. | |
358 | * @sas_address: sas address | |
359 | * @device_name: device name specified in INDENTIFY fram | |
360 | * @enclosure_logical_id: enclosure logical id | |
4beb4867 | 361 | * @slot: slot number |
f92363d1 SR |
362 | * @form: specifies boot device form |
363 | * @boot_device: boot device object from bios page 2 | |
364 | * | |
4beb4867 | 365 | * Return: 1 when there's a match, 0 means no match. |
f92363d1 SR |
366 | */ |
367 | static int | |
368 | _scsih_is_boot_device(u64 sas_address, u64 device_name, | |
369 | u64 enclosure_logical_id, u16 slot, u8 form, | |
370 | Mpi2BiosPage2BootDevice_t *boot_device) | |
371 | { | |
372 | int rc = 0; | |
373 | ||
374 | switch (form) { | |
375 | case MPI2_BIOSPAGE2_FORM_SAS_WWID: | |
376 | if (!sas_address) | |
377 | break; | |
378 | rc = _scsih_srch_boot_sas_address( | |
379 | sas_address, &boot_device->SasWwid); | |
380 | break; | |
381 | case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT: | |
382 | if (!enclosure_logical_id) | |
383 | break; | |
384 | rc = _scsih_srch_boot_encl_slot( | |
385 | enclosure_logical_id, | |
386 | slot, &boot_device->EnclosureSlot); | |
387 | break; | |
388 | case MPI2_BIOSPAGE2_FORM_DEVICE_NAME: | |
389 | if (!device_name) | |
390 | break; | |
391 | rc = _scsih_srch_boot_device_name( | |
392 | device_name, &boot_device->DeviceName); | |
393 | break; | |
394 | case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED: | |
395 | break; | |
396 | } | |
397 | ||
398 | return rc; | |
399 | } | |
400 | ||
401 | /** | |
402 | * _scsih_get_sas_address - set the sas_address for given device handle | |
4beb4867 | 403 | * @ioc: ? |
f92363d1 SR |
404 | * @handle: device handle |
405 | * @sas_address: sas address | |
406 | * | |
4beb4867 | 407 | * Return: 0 success, non-zero when failure |
f92363d1 SR |
408 | */ |
409 | static int | |
410 | _scsih_get_sas_address(struct MPT3SAS_ADAPTER *ioc, u16 handle, | |
411 | u64 *sas_address) | |
412 | { | |
413 | Mpi2SasDevicePage0_t sas_device_pg0; | |
414 | Mpi2ConfigReply_t mpi_reply; | |
415 | u32 ioc_status; | |
416 | ||
417 | *sas_address = 0; | |
418 | ||
f92363d1 SR |
419 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
420 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
919d8a3f JP |
421 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
422 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
423 | return -ENXIO; |
424 | } | |
425 | ||
426 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
427 | if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { | |
758f8139 SR |
428 | /* For HBA, vSES doesn't return HBA SAS address. Instead return |
429 | * vSES's sas address. | |
430 | */ | |
431 | if ((handle <= ioc->sas_hba.num_phys) && | |
432 | (!(le32_to_cpu(sas_device_pg0.DeviceInfo) & | |
433 | MPI2_SAS_DEVICE_INFO_SEP))) | |
434 | *sas_address = ioc->sas_hba.sas_address; | |
435 | else | |
436 | *sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | |
f92363d1 SR |
437 | return 0; |
438 | } | |
439 | ||
6c7abffc | 440 | /* we hit this because the given parent handle doesn't exist */ |
f92363d1 SR |
441 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
442 | return -ENXIO; | |
443 | ||
444 | /* else error case */ | |
919d8a3f JP |
445 | ioc_err(ioc, "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n", |
446 | handle, ioc_status, __FILE__, __LINE__, __func__); | |
f92363d1 SR |
447 | return -EIO; |
448 | } | |
449 | ||
450 | /** | |
451 | * _scsih_determine_boot_device - determine boot device. | |
452 | * @ioc: per adapter object | |
d88e1eab SPS |
453 | * @device: sas_device or pcie_device object |
454 | * @channel: SAS or PCIe channel | |
f92363d1 SR |
455 | * |
456 | * Determines whether this device should be first reported device to | |
457 | * to scsi-ml or sas transport, this purpose is for persistent boot device. | |
458 | * There are primary, alternate, and current entries in bios page 2. The order | |
459 | * priority is primary, alternate, then current. This routine saves | |
d88e1eab | 460 | * the corresponding device object. |
f92363d1 SR |
461 | * The saved data to be used later in _scsih_probe_boot_devices(). |
462 | */ | |
463 | static void | |
d88e1eab SPS |
464 | _scsih_determine_boot_device(struct MPT3SAS_ADAPTER *ioc, void *device, |
465 | u32 channel) | |
f92363d1 SR |
466 | { |
467 | struct _sas_device *sas_device; | |
d88e1eab | 468 | struct _pcie_device *pcie_device; |
f92363d1 SR |
469 | struct _raid_device *raid_device; |
470 | u64 sas_address; | |
471 | u64 device_name; | |
472 | u64 enclosure_logical_id; | |
473 | u16 slot; | |
474 | ||
475 | /* only process this function when driver loads */ | |
476 | if (!ioc->is_driver_loading) | |
477 | return; | |
478 | ||
479 | /* no Bios, return immediately */ | |
480 | if (!ioc->bios_pg3.BiosVersion) | |
481 | return; | |
482 | ||
d88e1eab | 483 | if (channel == RAID_CHANNEL) { |
f92363d1 SR |
484 | raid_device = device; |
485 | sas_address = raid_device->wwid; | |
486 | device_name = 0; | |
487 | enclosure_logical_id = 0; | |
488 | slot = 0; | |
d88e1eab SPS |
489 | } else if (channel == PCIE_CHANNEL) { |
490 | pcie_device = device; | |
491 | sas_address = pcie_device->wwid; | |
492 | device_name = 0; | |
493 | enclosure_logical_id = 0; | |
494 | slot = 0; | |
495 | } else { | |
496 | sas_device = device; | |
497 | sas_address = sas_device->sas_address; | |
498 | device_name = sas_device->device_name; | |
499 | enclosure_logical_id = sas_device->enclosure_logical_id; | |
500 | slot = sas_device->slot; | |
f92363d1 SR |
501 | } |
502 | ||
503 | if (!ioc->req_boot_device.device) { | |
504 | if (_scsih_is_boot_device(sas_address, device_name, | |
505 | enclosure_logical_id, slot, | |
506 | (ioc->bios_pg2.ReqBootDeviceForm & | |
507 | MPI2_BIOSPAGE2_FORM_MASK), | |
508 | &ioc->bios_pg2.RequestedBootDevice)) { | |
919d8a3f JP |
509 | dinitprintk(ioc, |
510 | ioc_info(ioc, "%s: req_boot_device(0x%016llx)\n", | |
511 | __func__, (u64)sas_address)); | |
f92363d1 | 512 | ioc->req_boot_device.device = device; |
d88e1eab | 513 | ioc->req_boot_device.channel = channel; |
f92363d1 SR |
514 | } |
515 | } | |
516 | ||
517 | if (!ioc->req_alt_boot_device.device) { | |
518 | if (_scsih_is_boot_device(sas_address, device_name, | |
519 | enclosure_logical_id, slot, | |
520 | (ioc->bios_pg2.ReqAltBootDeviceForm & | |
521 | MPI2_BIOSPAGE2_FORM_MASK), | |
522 | &ioc->bios_pg2.RequestedAltBootDevice)) { | |
919d8a3f JP |
523 | dinitprintk(ioc, |
524 | ioc_info(ioc, "%s: req_alt_boot_device(0x%016llx)\n", | |
525 | __func__, (u64)sas_address)); | |
f92363d1 | 526 | ioc->req_alt_boot_device.device = device; |
d88e1eab | 527 | ioc->req_alt_boot_device.channel = channel; |
f92363d1 SR |
528 | } |
529 | } | |
530 | ||
531 | if (!ioc->current_boot_device.device) { | |
532 | if (_scsih_is_boot_device(sas_address, device_name, | |
533 | enclosure_logical_id, slot, | |
534 | (ioc->bios_pg2.CurrentBootDeviceForm & | |
535 | MPI2_BIOSPAGE2_FORM_MASK), | |
536 | &ioc->bios_pg2.CurrentBootDevice)) { | |
919d8a3f JP |
537 | dinitprintk(ioc, |
538 | ioc_info(ioc, "%s: current_boot_device(0x%016llx)\n", | |
539 | __func__, (u64)sas_address)); | |
f92363d1 | 540 | ioc->current_boot_device.device = device; |
d88e1eab | 541 | ioc->current_boot_device.channel = channel; |
f92363d1 SR |
542 | } |
543 | } | |
544 | } | |
545 | ||
d1cb5e49 SR |
546 | static struct _sas_device * |
547 | __mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc, | |
548 | struct MPT3SAS_TARGET *tgt_priv) | |
549 | { | |
550 | struct _sas_device *ret; | |
551 | ||
552 | assert_spin_locked(&ioc->sas_device_lock); | |
553 | ||
d88e1eab | 554 | ret = tgt_priv->sas_dev; |
d1cb5e49 SR |
555 | if (ret) |
556 | sas_device_get(ret); | |
557 | ||
558 | return ret; | |
559 | } | |
560 | ||
561 | static struct _sas_device * | |
562 | mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc, | |
563 | struct MPT3SAS_TARGET *tgt_priv) | |
564 | { | |
565 | struct _sas_device *ret; | |
566 | unsigned long flags; | |
567 | ||
568 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
569 | ret = __mpt3sas_get_sdev_from_target(ioc, tgt_priv); | |
570 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
571 | ||
572 | return ret; | |
573 | } | |
574 | ||
d88e1eab SPS |
575 | static struct _pcie_device * |
576 | __mpt3sas_get_pdev_from_target(struct MPT3SAS_ADAPTER *ioc, | |
577 | struct MPT3SAS_TARGET *tgt_priv) | |
578 | { | |
579 | struct _pcie_device *ret; | |
580 | ||
581 | assert_spin_locked(&ioc->pcie_device_lock); | |
582 | ||
583 | ret = tgt_priv->pcie_dev; | |
584 | if (ret) | |
585 | pcie_device_get(ret); | |
586 | ||
587 | return ret; | |
588 | } | |
589 | ||
590 | /** | |
591 | * mpt3sas_get_pdev_from_target - pcie device search | |
592 | * @ioc: per adapter object | |
593 | * @tgt_priv: starget private object | |
594 | * | |
595 | * Context: This function will acquire ioc->pcie_device_lock and will release | |
596 | * before returning the pcie_device object. | |
597 | * | |
598 | * This searches for pcie_device from target, then return pcie_device object. | |
599 | */ | |
494f401b | 600 | static struct _pcie_device * |
d88e1eab SPS |
601 | mpt3sas_get_pdev_from_target(struct MPT3SAS_ADAPTER *ioc, |
602 | struct MPT3SAS_TARGET *tgt_priv) | |
603 | { | |
604 | struct _pcie_device *ret; | |
605 | unsigned long flags; | |
606 | ||
607 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
608 | ret = __mpt3sas_get_pdev_from_target(ioc, tgt_priv); | |
609 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
610 | ||
611 | return ret; | |
612 | } | |
d1cb5e49 SR |
613 | |
614 | struct _sas_device * | |
615 | __mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc, | |
616 | u64 sas_address) | |
617 | { | |
618 | struct _sas_device *sas_device; | |
619 | ||
620 | assert_spin_locked(&ioc->sas_device_lock); | |
621 | ||
622 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) | |
623 | if (sas_device->sas_address == sas_address) | |
624 | goto found_device; | |
625 | ||
626 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) | |
627 | if (sas_device->sas_address == sas_address) | |
628 | goto found_device; | |
629 | ||
630 | return NULL; | |
631 | ||
632 | found_device: | |
633 | sas_device_get(sas_device); | |
634 | return sas_device; | |
635 | } | |
636 | ||
f92363d1 | 637 | /** |
d1cb5e49 | 638 | * mpt3sas_get_sdev_by_addr - sas device search |
f92363d1 SR |
639 | * @ioc: per adapter object |
640 | * @sas_address: sas address | |
641 | * Context: Calling function should acquire ioc->sas_device_lock | |
642 | * | |
643 | * This searches for sas_device based on sas_address, then return sas_device | |
644 | * object. | |
645 | */ | |
646 | struct _sas_device * | |
d1cb5e49 | 647 | mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc, |
f92363d1 SR |
648 | u64 sas_address) |
649 | { | |
650 | struct _sas_device *sas_device; | |
d1cb5e49 SR |
651 | unsigned long flags; |
652 | ||
653 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
654 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, | |
655 | sas_address); | |
656 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
657 | ||
658 | return sas_device; | |
659 | } | |
660 | ||
661 | static struct _sas_device * | |
662 | __mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
663 | { | |
664 | struct _sas_device *sas_device; | |
665 | ||
666 | assert_spin_locked(&ioc->sas_device_lock); | |
f92363d1 SR |
667 | |
668 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) | |
d1cb5e49 SR |
669 | if (sas_device->handle == handle) |
670 | goto found_device; | |
f92363d1 SR |
671 | |
672 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) | |
d1cb5e49 SR |
673 | if (sas_device->handle == handle) |
674 | goto found_device; | |
f92363d1 SR |
675 | |
676 | return NULL; | |
d1cb5e49 SR |
677 | |
678 | found_device: | |
679 | sas_device_get(sas_device); | |
680 | return sas_device; | |
f92363d1 SR |
681 | } |
682 | ||
683 | /** | |
d1cb5e49 | 684 | * mpt3sas_get_sdev_by_handle - sas device search |
f92363d1 SR |
685 | * @ioc: per adapter object |
686 | * @handle: sas device handle (assigned by firmware) | |
687 | * Context: Calling function should acquire ioc->sas_device_lock | |
688 | * | |
689 | * This searches for sas_device based on sas_address, then return sas_device | |
690 | * object. | |
691 | */ | |
c102e00c | 692 | struct _sas_device * |
d1cb5e49 | 693 | mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
f92363d1 SR |
694 | { |
695 | struct _sas_device *sas_device; | |
d1cb5e49 | 696 | unsigned long flags; |
f92363d1 | 697 | |
d1cb5e49 SR |
698 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
699 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); | |
700 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
f92363d1 | 701 | |
d1cb5e49 | 702 | return sas_device; |
f92363d1 SR |
703 | } |
704 | ||
75888956 SR |
705 | /** |
706 | * _scsih_display_enclosure_chassis_info - display device location info | |
707 | * @ioc: per adapter object | |
708 | * @sas_device: per sas device object | |
709 | * @sdev: scsi device struct | |
710 | * @starget: scsi target struct | |
75888956 SR |
711 | */ |
712 | static void | |
713 | _scsih_display_enclosure_chassis_info(struct MPT3SAS_ADAPTER *ioc, | |
714 | struct _sas_device *sas_device, struct scsi_device *sdev, | |
715 | struct scsi_target *starget) | |
716 | { | |
717 | if (sdev) { | |
718 | if (sas_device->enclosure_handle != 0) | |
719 | sdev_printk(KERN_INFO, sdev, | |
720 | "enclosure logical id (0x%016llx), slot(%d) \n", | |
721 | (unsigned long long) | |
722 | sas_device->enclosure_logical_id, | |
723 | sas_device->slot); | |
724 | if (sas_device->connector_name[0] != '\0') | |
725 | sdev_printk(KERN_INFO, sdev, | |
726 | "enclosure level(0x%04x), connector name( %s)\n", | |
727 | sas_device->enclosure_level, | |
728 | sas_device->connector_name); | |
729 | if (sas_device->is_chassis_slot_valid) | |
730 | sdev_printk(KERN_INFO, sdev, "chassis slot(0x%04x)\n", | |
731 | sas_device->chassis_slot); | |
732 | } else if (starget) { | |
733 | if (sas_device->enclosure_handle != 0) | |
734 | starget_printk(KERN_INFO, starget, | |
735 | "enclosure logical id(0x%016llx), slot(%d) \n", | |
736 | (unsigned long long) | |
737 | sas_device->enclosure_logical_id, | |
738 | sas_device->slot); | |
739 | if (sas_device->connector_name[0] != '\0') | |
740 | starget_printk(KERN_INFO, starget, | |
741 | "enclosure level(0x%04x), connector name( %s)\n", | |
742 | sas_device->enclosure_level, | |
743 | sas_device->connector_name); | |
744 | if (sas_device->is_chassis_slot_valid) | |
745 | starget_printk(KERN_INFO, starget, | |
746 | "chassis slot(0x%04x)\n", | |
747 | sas_device->chassis_slot); | |
748 | } else { | |
749 | if (sas_device->enclosure_handle != 0) | |
919d8a3f JP |
750 | ioc_info(ioc, "enclosure logical id(0x%016llx), slot(%d)\n", |
751 | (u64)sas_device->enclosure_logical_id, | |
752 | sas_device->slot); | |
75888956 | 753 | if (sas_device->connector_name[0] != '\0') |
919d8a3f JP |
754 | ioc_info(ioc, "enclosure level(0x%04x), connector name( %s)\n", |
755 | sas_device->enclosure_level, | |
756 | sas_device->connector_name); | |
75888956 | 757 | if (sas_device->is_chassis_slot_valid) |
919d8a3f JP |
758 | ioc_info(ioc, "chassis slot(0x%04x)\n", |
759 | sas_device->chassis_slot); | |
75888956 SR |
760 | } |
761 | } | |
762 | ||
f92363d1 SR |
763 | /** |
764 | * _scsih_sas_device_remove - remove sas_device from list. | |
765 | * @ioc: per adapter object | |
766 | * @sas_device: the sas_device object | |
767 | * Context: This function will acquire ioc->sas_device_lock. | |
768 | * | |
d1cb5e49 | 769 | * If sas_device is on the list, remove it and decrement its reference count. |
f92363d1 SR |
770 | */ |
771 | static void | |
772 | _scsih_sas_device_remove(struct MPT3SAS_ADAPTER *ioc, | |
773 | struct _sas_device *sas_device) | |
774 | { | |
775 | unsigned long flags; | |
776 | ||
777 | if (!sas_device) | |
778 | return; | |
919d8a3f JP |
779 | ioc_info(ioc, "removing handle(0x%04x), sas_addr(0x%016llx)\n", |
780 | sas_device->handle, (u64)sas_device->sas_address); | |
e6d45e3e | 781 | |
75888956 | 782 | _scsih_display_enclosure_chassis_info(ioc, sas_device, NULL, NULL); |
f92363d1 | 783 | |
d1cb5e49 SR |
784 | /* |
785 | * The lock serializes access to the list, but we still need to verify | |
786 | * that nobody removed the entry while we were waiting on the lock. | |
787 | */ | |
f92363d1 | 788 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 SR |
789 | if (!list_empty(&sas_device->list)) { |
790 | list_del_init(&sas_device->list); | |
791 | sas_device_put(sas_device); | |
792 | } | |
f92363d1 SR |
793 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
794 | } | |
795 | ||
796 | /** | |
797 | * _scsih_device_remove_by_handle - removing device object by handle | |
798 | * @ioc: per adapter object | |
799 | * @handle: device handle | |
f92363d1 SR |
800 | */ |
801 | static void | |
802 | _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
803 | { | |
804 | struct _sas_device *sas_device; | |
805 | unsigned long flags; | |
806 | ||
807 | if (ioc->shost_recovery) | |
808 | return; | |
809 | ||
810 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 SR |
811 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
812 | if (sas_device) { | |
813 | list_del_init(&sas_device->list); | |
814 | sas_device_put(sas_device); | |
815 | } | |
f92363d1 | 816 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
d1cb5e49 | 817 | if (sas_device) { |
f92363d1 | 818 | _scsih_remove_device(ioc, sas_device); |
d1cb5e49 SR |
819 | sas_device_put(sas_device); |
820 | } | |
f92363d1 SR |
821 | } |
822 | ||
823 | /** | |
824 | * mpt3sas_device_remove_by_sas_address - removing device object by sas address | |
825 | * @ioc: per adapter object | |
826 | * @sas_address: device sas_address | |
f92363d1 SR |
827 | */ |
828 | void | |
829 | mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER *ioc, | |
830 | u64 sas_address) | |
831 | { | |
832 | struct _sas_device *sas_device; | |
833 | unsigned long flags; | |
834 | ||
835 | if (ioc->shost_recovery) | |
836 | return; | |
837 | ||
838 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 SR |
839 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, sas_address); |
840 | if (sas_device) { | |
841 | list_del_init(&sas_device->list); | |
842 | sas_device_put(sas_device); | |
843 | } | |
f92363d1 | 844 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
d1cb5e49 | 845 | if (sas_device) { |
f92363d1 | 846 | _scsih_remove_device(ioc, sas_device); |
d1cb5e49 SR |
847 | sas_device_put(sas_device); |
848 | } | |
f92363d1 SR |
849 | } |
850 | ||
851 | /** | |
852 | * _scsih_sas_device_add - insert sas_device to the list. | |
853 | * @ioc: per adapter object | |
854 | * @sas_device: the sas_device object | |
855 | * Context: This function will acquire ioc->sas_device_lock. | |
856 | * | |
857 | * Adding new object to the ioc->sas_device_list. | |
858 | */ | |
859 | static void | |
860 | _scsih_sas_device_add(struct MPT3SAS_ADAPTER *ioc, | |
861 | struct _sas_device *sas_device) | |
862 | { | |
863 | unsigned long flags; | |
864 | ||
919d8a3f JP |
865 | dewtprintk(ioc, |
866 | ioc_info(ioc, "%s: handle(0x%04x), sas_addr(0x%016llx)\n", | |
867 | __func__, sas_device->handle, | |
868 | (u64)sas_device->sas_address)); | |
f92363d1 | 869 | |
75888956 SR |
870 | dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device, |
871 | NULL, NULL)); | |
e6d45e3e | 872 | |
f92363d1 | 873 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 874 | sas_device_get(sas_device); |
f92363d1 SR |
875 | list_add_tail(&sas_device->list, &ioc->sas_device_list); |
876 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
877 | ||
c696f7b8 SPS |
878 | if (ioc->hide_drives) { |
879 | clear_bit(sas_device->handle, ioc->pend_os_device_add); | |
880 | return; | |
881 | } | |
882 | ||
f92363d1 SR |
883 | if (!mpt3sas_transport_port_add(ioc, sas_device->handle, |
884 | sas_device->sas_address_parent)) { | |
885 | _scsih_sas_device_remove(ioc, sas_device); | |
886 | } else if (!sas_device->starget) { | |
887 | /* | |
888 | * When asyn scanning is enabled, its not possible to remove | |
889 | * devices while scanning is turned on due to an oops in | |
890 | * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start() | |
891 | */ | |
f5edbe77 | 892 | if (!ioc->is_driver_loading) { |
f92363d1 SR |
893 | mpt3sas_transport_port_remove(ioc, |
894 | sas_device->sas_address, | |
895 | sas_device->sas_address_parent); | |
f5edbe77 SR |
896 | _scsih_sas_device_remove(ioc, sas_device); |
897 | } | |
c696f7b8 SPS |
898 | } else |
899 | clear_bit(sas_device->handle, ioc->pend_os_device_add); | |
f92363d1 SR |
900 | } |
901 | ||
902 | /** | |
903 | * _scsih_sas_device_init_add - insert sas_device to the list. | |
904 | * @ioc: per adapter object | |
905 | * @sas_device: the sas_device object | |
906 | * Context: This function will acquire ioc->sas_device_lock. | |
907 | * | |
908 | * Adding new object at driver load time to the ioc->sas_device_init_list. | |
909 | */ | |
910 | static void | |
911 | _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER *ioc, | |
912 | struct _sas_device *sas_device) | |
913 | { | |
914 | unsigned long flags; | |
915 | ||
919d8a3f JP |
916 | dewtprintk(ioc, |
917 | ioc_info(ioc, "%s: handle(0x%04x), sas_addr(0x%016llx)\n", | |
918 | __func__, sas_device->handle, | |
919 | (u64)sas_device->sas_address)); | |
f92363d1 | 920 | |
75888956 SR |
921 | dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device, |
922 | NULL, NULL)); | |
e6d45e3e | 923 | |
f92363d1 | 924 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 925 | sas_device_get(sas_device); |
f92363d1 SR |
926 | list_add_tail(&sas_device->list, &ioc->sas_device_init_list); |
927 | _scsih_determine_boot_device(ioc, sas_device, 0); | |
928 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
929 | } | |
930 | ||
d88e1eab | 931 | |
494f401b | 932 | static struct _pcie_device * |
d88e1eab SPS |
933 | __mpt3sas_get_pdev_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid) |
934 | { | |
935 | struct _pcie_device *pcie_device; | |
936 | ||
937 | assert_spin_locked(&ioc->pcie_device_lock); | |
938 | ||
939 | list_for_each_entry(pcie_device, &ioc->pcie_device_list, list) | |
940 | if (pcie_device->wwid == wwid) | |
941 | goto found_device; | |
942 | ||
943 | list_for_each_entry(pcie_device, &ioc->pcie_device_init_list, list) | |
944 | if (pcie_device->wwid == wwid) | |
945 | goto found_device; | |
946 | ||
947 | return NULL; | |
948 | ||
949 | found_device: | |
950 | pcie_device_get(pcie_device); | |
951 | return pcie_device; | |
952 | } | |
953 | ||
954 | ||
955 | /** | |
956 | * mpt3sas_get_pdev_by_wwid - pcie device search | |
957 | * @ioc: per adapter object | |
958 | * @wwid: wwid | |
959 | * | |
960 | * Context: This function will acquire ioc->pcie_device_lock and will release | |
961 | * before returning the pcie_device object. | |
962 | * | |
963 | * This searches for pcie_device based on wwid, then return pcie_device object. | |
964 | */ | |
494f401b | 965 | static struct _pcie_device * |
d88e1eab SPS |
966 | mpt3sas_get_pdev_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid) |
967 | { | |
968 | struct _pcie_device *pcie_device; | |
969 | unsigned long flags; | |
970 | ||
971 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
972 | pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid); | |
973 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
974 | ||
975 | return pcie_device; | |
976 | } | |
977 | ||
978 | ||
494f401b | 979 | static struct _pcie_device * |
d88e1eab SPS |
980 | __mpt3sas_get_pdev_by_idchannel(struct MPT3SAS_ADAPTER *ioc, int id, |
981 | int channel) | |
982 | { | |
983 | struct _pcie_device *pcie_device; | |
984 | ||
985 | assert_spin_locked(&ioc->pcie_device_lock); | |
986 | ||
987 | list_for_each_entry(pcie_device, &ioc->pcie_device_list, list) | |
988 | if (pcie_device->id == id && pcie_device->channel == channel) | |
989 | goto found_device; | |
990 | ||
991 | list_for_each_entry(pcie_device, &ioc->pcie_device_init_list, list) | |
992 | if (pcie_device->id == id && pcie_device->channel == channel) | |
993 | goto found_device; | |
994 | ||
995 | return NULL; | |
996 | ||
997 | found_device: | |
998 | pcie_device_get(pcie_device); | |
999 | return pcie_device; | |
1000 | } | |
1001 | ||
494f401b | 1002 | static struct _pcie_device * |
c102e00c SPS |
1003 | __mpt3sas_get_pdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
1004 | { | |
1005 | struct _pcie_device *pcie_device; | |
1006 | ||
1007 | assert_spin_locked(&ioc->pcie_device_lock); | |
1008 | ||
1009 | list_for_each_entry(pcie_device, &ioc->pcie_device_list, list) | |
1010 | if (pcie_device->handle == handle) | |
1011 | goto found_device; | |
1012 | ||
1013 | list_for_each_entry(pcie_device, &ioc->pcie_device_init_list, list) | |
1014 | if (pcie_device->handle == handle) | |
1015 | goto found_device; | |
1016 | ||
1017 | return NULL; | |
1018 | ||
1019 | found_device: | |
1020 | pcie_device_get(pcie_device); | |
1021 | return pcie_device; | |
1022 | } | |
1023 | ||
1024 | ||
1025 | /** | |
1026 | * mpt3sas_get_pdev_by_handle - pcie device search | |
1027 | * @ioc: per adapter object | |
1028 | * @handle: Firmware device handle | |
1029 | * | |
1030 | * Context: This function will acquire ioc->pcie_device_lock and will release | |
1031 | * before returning the pcie_device object. | |
1032 | * | |
1033 | * This searches for pcie_device based on handle, then return pcie_device | |
1034 | * object. | |
1035 | */ | |
1036 | struct _pcie_device * | |
1037 | mpt3sas_get_pdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
1038 | { | |
1039 | struct _pcie_device *pcie_device; | |
1040 | unsigned long flags; | |
1041 | ||
1042 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1043 | pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle); | |
1044 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1045 | ||
1046 | return pcie_device; | |
1047 | } | |
1048 | ||
d88e1eab SPS |
1049 | /** |
1050 | * _scsih_pcie_device_remove - remove pcie_device from list. | |
1051 | * @ioc: per adapter object | |
1052 | * @pcie_device: the pcie_device object | |
1053 | * Context: This function will acquire ioc->pcie_device_lock. | |
1054 | * | |
1055 | * If pcie_device is on the list, remove it and decrement its reference count. | |
1056 | */ | |
1057 | static void | |
1058 | _scsih_pcie_device_remove(struct MPT3SAS_ADAPTER *ioc, | |
1059 | struct _pcie_device *pcie_device) | |
1060 | { | |
1061 | unsigned long flags; | |
1062 | int was_on_pcie_device_list = 0; | |
1063 | ||
1064 | if (!pcie_device) | |
1065 | return; | |
919d8a3f JP |
1066 | ioc_info(ioc, "removing handle(0x%04x), wwid(0x%016llx)\n", |
1067 | pcie_device->handle, (u64)pcie_device->wwid); | |
d88e1eab | 1068 | if (pcie_device->enclosure_handle != 0) |
919d8a3f JP |
1069 | ioc_info(ioc, "removing enclosure logical id(0x%016llx), slot(%d)\n", |
1070 | (u64)pcie_device->enclosure_logical_id, | |
1071 | pcie_device->slot); | |
d88e1eab | 1072 | if (pcie_device->connector_name[0] != '\0') |
919d8a3f JP |
1073 | ioc_info(ioc, "removing enclosure level(0x%04x), connector name( %s)\n", |
1074 | pcie_device->enclosure_level, | |
1075 | pcie_device->connector_name); | |
d88e1eab SPS |
1076 | |
1077 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1078 | if (!list_empty(&pcie_device->list)) { | |
1079 | list_del_init(&pcie_device->list); | |
1080 | was_on_pcie_device_list = 1; | |
1081 | } | |
1082 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1083 | if (was_on_pcie_device_list) { | |
1084 | kfree(pcie_device->serial_number); | |
1085 | pcie_device_put(pcie_device); | |
1086 | } | |
1087 | } | |
3075ac49 SPS |
1088 | |
1089 | ||
1090 | /** | |
1091 | * _scsih_pcie_device_remove_by_handle - removing pcie device object by handle | |
1092 | * @ioc: per adapter object | |
1093 | * @handle: device handle | |
3075ac49 SPS |
1094 | */ |
1095 | static void | |
1096 | _scsih_pcie_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
1097 | { | |
1098 | struct _pcie_device *pcie_device; | |
1099 | unsigned long flags; | |
1100 | int was_on_pcie_device_list = 0; | |
1101 | ||
1102 | if (ioc->shost_recovery) | |
1103 | return; | |
1104 | ||
1105 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1106 | pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle); | |
1107 | if (pcie_device) { | |
1108 | if (!list_empty(&pcie_device->list)) { | |
1109 | list_del_init(&pcie_device->list); | |
1110 | was_on_pcie_device_list = 1; | |
1111 | pcie_device_put(pcie_device); | |
1112 | } | |
1113 | } | |
1114 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1115 | if (was_on_pcie_device_list) { | |
1116 | _scsih_pcie_device_remove_from_sml(ioc, pcie_device); | |
1117 | pcie_device_put(pcie_device); | |
1118 | } | |
1119 | } | |
1120 | ||
c102e00c SPS |
1121 | /** |
1122 | * _scsih_pcie_device_add - add pcie_device object | |
1123 | * @ioc: per adapter object | |
1124 | * @pcie_device: pcie_device object | |
1125 | * | |
1126 | * This is added to the pcie_device_list link list. | |
1127 | */ | |
1128 | static void | |
1129 | _scsih_pcie_device_add(struct MPT3SAS_ADAPTER *ioc, | |
1130 | struct _pcie_device *pcie_device) | |
1131 | { | |
1132 | unsigned long flags; | |
1133 | ||
919d8a3f JP |
1134 | dewtprintk(ioc, |
1135 | ioc_info(ioc, "%s: handle (0x%04x), wwid(0x%016llx)\n", | |
1136 | __func__, | |
1137 | pcie_device->handle, (u64)pcie_device->wwid)); | |
c102e00c | 1138 | if (pcie_device->enclosure_handle != 0) |
919d8a3f JP |
1139 | dewtprintk(ioc, |
1140 | ioc_info(ioc, "%s: enclosure logical id(0x%016llx), slot( %d)\n", | |
1141 | __func__, | |
1142 | (u64)pcie_device->enclosure_logical_id, | |
1143 | pcie_device->slot)); | |
c102e00c | 1144 | if (pcie_device->connector_name[0] != '\0') |
919d8a3f JP |
1145 | dewtprintk(ioc, |
1146 | ioc_info(ioc, "%s: enclosure level(0x%04x), connector name( %s)\n", | |
1147 | __func__, pcie_device->enclosure_level, | |
1148 | pcie_device->connector_name)); | |
c102e00c SPS |
1149 | |
1150 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1151 | pcie_device_get(pcie_device); | |
1152 | list_add_tail(&pcie_device->list, &ioc->pcie_device_list); | |
1153 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1154 | ||
3c090ce3 SP |
1155 | if (pcie_device->access_status == |
1156 | MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED) { | |
1157 | clear_bit(pcie_device->handle, ioc->pend_os_device_add); | |
1158 | return; | |
1159 | } | |
c102e00c SPS |
1160 | if (scsi_add_device(ioc->shost, PCIE_CHANNEL, pcie_device->id, 0)) { |
1161 | _scsih_pcie_device_remove(ioc, pcie_device); | |
1162 | } else if (!pcie_device->starget) { | |
1163 | if (!ioc->is_driver_loading) { | |
1164 | /*TODO-- Need to find out whether this condition will occur or not*/ | |
1165 | clear_bit(pcie_device->handle, ioc->pend_os_device_add); | |
1166 | } | |
1167 | } else | |
1168 | clear_bit(pcie_device->handle, ioc->pend_os_device_add); | |
1169 | } | |
1170 | ||
1171 | /* | |
1172 | * _scsih_pcie_device_init_add - insert pcie_device to the init list. | |
1173 | * @ioc: per adapter object | |
1174 | * @pcie_device: the pcie_device object | |
1175 | * Context: This function will acquire ioc->pcie_device_lock. | |
1176 | * | |
1177 | * Adding new object at driver load time to the ioc->pcie_device_init_list. | |
1178 | */ | |
1179 | static void | |
1180 | _scsih_pcie_device_init_add(struct MPT3SAS_ADAPTER *ioc, | |
1181 | struct _pcie_device *pcie_device) | |
1182 | { | |
1183 | unsigned long flags; | |
1184 | ||
919d8a3f JP |
1185 | dewtprintk(ioc, |
1186 | ioc_info(ioc, "%s: handle (0x%04x), wwid(0x%016llx)\n", | |
1187 | __func__, | |
1188 | pcie_device->handle, (u64)pcie_device->wwid)); | |
c102e00c | 1189 | if (pcie_device->enclosure_handle != 0) |
919d8a3f JP |
1190 | dewtprintk(ioc, |
1191 | ioc_info(ioc, "%s: enclosure logical id(0x%016llx), slot( %d)\n", | |
1192 | __func__, | |
1193 | (u64)pcie_device->enclosure_logical_id, | |
1194 | pcie_device->slot)); | |
c102e00c | 1195 | if (pcie_device->connector_name[0] != '\0') |
919d8a3f JP |
1196 | dewtprintk(ioc, |
1197 | ioc_info(ioc, "%s: enclosure level(0x%04x), connector name( %s)\n", | |
1198 | __func__, pcie_device->enclosure_level, | |
1199 | pcie_device->connector_name)); | |
c102e00c SPS |
1200 | |
1201 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1202 | pcie_device_get(pcie_device); | |
1203 | list_add_tail(&pcie_device->list, &ioc->pcie_device_init_list); | |
3c090ce3 SP |
1204 | if (pcie_device->access_status != |
1205 | MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED) | |
1206 | _scsih_determine_boot_device(ioc, pcie_device, PCIE_CHANNEL); | |
c102e00c SPS |
1207 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); |
1208 | } | |
f92363d1 SR |
1209 | /** |
1210 | * _scsih_raid_device_find_by_id - raid device search | |
1211 | * @ioc: per adapter object | |
1212 | * @id: sas device target id | |
1213 | * @channel: sas device channel | |
1214 | * Context: Calling function should acquire ioc->raid_device_lock | |
1215 | * | |
1216 | * This searches for raid_device based on target id, then return raid_device | |
1217 | * object. | |
1218 | */ | |
1219 | static struct _raid_device * | |
1220 | _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER *ioc, int id, int channel) | |
1221 | { | |
1222 | struct _raid_device *raid_device, *r; | |
1223 | ||
1224 | r = NULL; | |
1225 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
1226 | if (raid_device->id == id && raid_device->channel == channel) { | |
1227 | r = raid_device; | |
1228 | goto out; | |
1229 | } | |
1230 | } | |
1231 | ||
1232 | out: | |
1233 | return r; | |
1234 | } | |
1235 | ||
1236 | /** | |
c84b06a4 | 1237 | * mpt3sas_raid_device_find_by_handle - raid device search |
f92363d1 SR |
1238 | * @ioc: per adapter object |
1239 | * @handle: sas device handle (assigned by firmware) | |
1240 | * Context: Calling function should acquire ioc->raid_device_lock | |
1241 | * | |
1242 | * This searches for raid_device based on handle, then return raid_device | |
1243 | * object. | |
1244 | */ | |
c84b06a4 SR |
1245 | struct _raid_device * |
1246 | mpt3sas_raid_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
f92363d1 SR |
1247 | { |
1248 | struct _raid_device *raid_device, *r; | |
1249 | ||
1250 | r = NULL; | |
1251 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
1252 | if (raid_device->handle != handle) | |
1253 | continue; | |
1254 | r = raid_device; | |
1255 | goto out; | |
1256 | } | |
1257 | ||
1258 | out: | |
1259 | return r; | |
1260 | } | |
1261 | ||
1262 | /** | |
1263 | * _scsih_raid_device_find_by_wwid - raid device search | |
1264 | * @ioc: per adapter object | |
4beb4867 | 1265 | * @wwid: ? |
f92363d1 SR |
1266 | * Context: Calling function should acquire ioc->raid_device_lock |
1267 | * | |
1268 | * This searches for raid_device based on wwid, then return raid_device | |
1269 | * object. | |
1270 | */ | |
1271 | static struct _raid_device * | |
1272 | _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid) | |
1273 | { | |
1274 | struct _raid_device *raid_device, *r; | |
1275 | ||
1276 | r = NULL; | |
1277 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
1278 | if (raid_device->wwid != wwid) | |
1279 | continue; | |
1280 | r = raid_device; | |
1281 | goto out; | |
1282 | } | |
1283 | ||
1284 | out: | |
1285 | return r; | |
1286 | } | |
1287 | ||
1288 | /** | |
1289 | * _scsih_raid_device_add - add raid_device object | |
1290 | * @ioc: per adapter object | |
1291 | * @raid_device: raid_device object | |
1292 | * | |
1293 | * This is added to the raid_device_list link list. | |
1294 | */ | |
1295 | static void | |
1296 | _scsih_raid_device_add(struct MPT3SAS_ADAPTER *ioc, | |
1297 | struct _raid_device *raid_device) | |
1298 | { | |
1299 | unsigned long flags; | |
1300 | ||
919d8a3f JP |
1301 | dewtprintk(ioc, |
1302 | ioc_info(ioc, "%s: handle(0x%04x), wwid(0x%016llx)\n", | |
1303 | __func__, | |
1304 | raid_device->handle, (u64)raid_device->wwid)); | |
f92363d1 SR |
1305 | |
1306 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1307 | list_add_tail(&raid_device->list, &ioc->raid_device_list); | |
1308 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1309 | } | |
1310 | ||
1311 | /** | |
1312 | * _scsih_raid_device_remove - delete raid_device object | |
1313 | * @ioc: per adapter object | |
1314 | * @raid_device: raid_device object | |
1315 | * | |
1316 | */ | |
1317 | static void | |
1318 | _scsih_raid_device_remove(struct MPT3SAS_ADAPTER *ioc, | |
1319 | struct _raid_device *raid_device) | |
1320 | { | |
1321 | unsigned long flags; | |
1322 | ||
1323 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1324 | list_del(&raid_device->list); | |
1325 | kfree(raid_device); | |
1326 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1327 | } | |
1328 | ||
1329 | /** | |
1330 | * mpt3sas_scsih_expander_find_by_handle - expander device search | |
1331 | * @ioc: per adapter object | |
1332 | * @handle: expander handle (assigned by firmware) | |
1333 | * Context: Calling function should acquire ioc->sas_device_lock | |
1334 | * | |
1335 | * This searches for expander device based on handle, then returns the | |
1336 | * sas_node object. | |
1337 | */ | |
1338 | struct _sas_node * | |
1339 | mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
1340 | { | |
1341 | struct _sas_node *sas_expander, *r; | |
1342 | ||
1343 | r = NULL; | |
1344 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { | |
1345 | if (sas_expander->handle != handle) | |
1346 | continue; | |
1347 | r = sas_expander; | |
1348 | goto out; | |
1349 | } | |
1350 | out: | |
1351 | return r; | |
1352 | } | |
1353 | ||
22a923c3 C |
1354 | /** |
1355 | * mpt3sas_scsih_enclosure_find_by_handle - exclosure device search | |
1356 | * @ioc: per adapter object | |
1357 | * @handle: enclosure handle (assigned by firmware) | |
1358 | * Context: Calling function should acquire ioc->sas_device_lock | |
1359 | * | |
1360 | * This searches for enclosure device based on handle, then returns the | |
1361 | * enclosure object. | |
1362 | */ | |
1363 | static struct _enclosure_node * | |
1364 | mpt3sas_scsih_enclosure_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
1365 | { | |
1366 | struct _enclosure_node *enclosure_dev, *r; | |
1367 | ||
1368 | r = NULL; | |
1369 | list_for_each_entry(enclosure_dev, &ioc->enclosure_list, list) { | |
1370 | if (le16_to_cpu(enclosure_dev->pg0.EnclosureHandle) != handle) | |
1371 | continue; | |
1372 | r = enclosure_dev; | |
1373 | goto out; | |
1374 | } | |
1375 | out: | |
1376 | return r; | |
1377 | } | |
f92363d1 SR |
1378 | /** |
1379 | * mpt3sas_scsih_expander_find_by_sas_address - expander device search | |
1380 | * @ioc: per adapter object | |
1381 | * @sas_address: sas address | |
1382 | * Context: Calling function should acquire ioc->sas_node_lock. | |
1383 | * | |
1384 | * This searches for expander device based on sas_address, then returns the | |
1385 | * sas_node object. | |
1386 | */ | |
1387 | struct _sas_node * | |
1388 | mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc, | |
1389 | u64 sas_address) | |
1390 | { | |
1391 | struct _sas_node *sas_expander, *r; | |
1392 | ||
1393 | r = NULL; | |
1394 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { | |
1395 | if (sas_expander->sas_address != sas_address) | |
1396 | continue; | |
1397 | r = sas_expander; | |
1398 | goto out; | |
1399 | } | |
1400 | out: | |
1401 | return r; | |
1402 | } | |
1403 | ||
1404 | /** | |
1405 | * _scsih_expander_node_add - insert expander device to the list. | |
1406 | * @ioc: per adapter object | |
1407 | * @sas_expander: the sas_device object | |
1408 | * Context: This function will acquire ioc->sas_node_lock. | |
1409 | * | |
1410 | * Adding new object to the ioc->sas_expander_list. | |
f92363d1 SR |
1411 | */ |
1412 | static void | |
1413 | _scsih_expander_node_add(struct MPT3SAS_ADAPTER *ioc, | |
1414 | struct _sas_node *sas_expander) | |
1415 | { | |
1416 | unsigned long flags; | |
1417 | ||
1418 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
1419 | list_add_tail(&sas_expander->list, &ioc->sas_expander_list); | |
1420 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
1421 | } | |
1422 | ||
1423 | /** | |
1424 | * _scsih_is_end_device - determines if device is an end device | |
1425 | * @device_info: bitfield providing information about the device. | |
1426 | * Context: none | |
1427 | * | |
4beb4867 | 1428 | * Return: 1 if end device. |
f92363d1 SR |
1429 | */ |
1430 | static int | |
1431 | _scsih_is_end_device(u32 device_info) | |
1432 | { | |
1433 | if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE && | |
1434 | ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) | | |
1435 | (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) | | |
1436 | (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE))) | |
1437 | return 1; | |
1438 | else | |
1439 | return 0; | |
1440 | } | |
1441 | ||
c102e00c | 1442 | /** |
5bb309db SP |
1443 | * _scsih_is_nvme_pciescsi_device - determines if |
1444 | * device is an pcie nvme/scsi device | |
c102e00c SPS |
1445 | * @device_info: bitfield providing information about the device. |
1446 | * Context: none | |
1447 | * | |
5bb309db | 1448 | * Returns 1 if device is pcie device type nvme/scsi. |
c102e00c SPS |
1449 | */ |
1450 | static int | |
5bb309db | 1451 | _scsih_is_nvme_pciescsi_device(u32 device_info) |
c102e00c | 1452 | { |
5bb309db SP |
1453 | if (((device_info & MPI26_PCIE_DEVINFO_MASK_DEVICE_TYPE) |
1454 | == MPI26_PCIE_DEVINFO_NVME) || | |
1455 | ((device_info & MPI26_PCIE_DEVINFO_MASK_DEVICE_TYPE) | |
1456 | == MPI26_PCIE_DEVINFO_SCSI)) | |
c102e00c SPS |
1457 | return 1; |
1458 | else | |
1459 | return 0; | |
1460 | } | |
1461 | ||
459325c4 | 1462 | /** |
dbec4c90 | 1463 | * mpt3sas_scsih_scsi_lookup_get - returns scmd entry |
459325c4 C |
1464 | * @ioc: per adapter object |
1465 | * @smid: system request message index | |
1466 | * | |
4beb4867 | 1467 | * Return: the smid stored scmd pointer. |
459325c4 C |
1468 | * Then will dereference the stored scmd pointer. |
1469 | */ | |
dbec4c90 SPS |
1470 | struct scsi_cmnd * |
1471 | mpt3sas_scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid) | |
459325c4 C |
1472 | { |
1473 | struct scsi_cmnd *scmd = NULL; | |
dbec4c90 | 1474 | struct scsiio_tracker *st; |
c2fe742f | 1475 | Mpi25SCSIIORequest_t *mpi_request; |
459325c4 | 1476 | |
dbec4c90 SPS |
1477 | if (smid > 0 && |
1478 | smid <= ioc->scsiio_depth - INTERNAL_SCSIIO_CMDS_COUNT) { | |
1479 | u32 unique_tag = smid - 1; | |
f92363d1 | 1480 | |
c2fe742f SR |
1481 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
1482 | ||
1483 | /* | |
1484 | * If SCSI IO request is outstanding at driver level then | |
1485 | * DevHandle filed must be non-zero. If DevHandle is zero | |
1486 | * then it means that this smid is free at driver level, | |
1487 | * so return NULL. | |
1488 | */ | |
1489 | if (!mpi_request->DevHandle) | |
1490 | return scmd; | |
1491 | ||
dbec4c90 SPS |
1492 | scmd = scsi_host_find_tag(ioc->shost, unique_tag); |
1493 | if (scmd) { | |
1494 | st = scsi_cmd_priv(scmd); | |
e7018314 | 1495 | if (st->cb_idx == 0xFF || st->smid == 0) |
dbec4c90 | 1496 | scmd = NULL; |
f92363d1 SR |
1497 | } |
1498 | } | |
dbec4c90 | 1499 | return scmd; |
f92363d1 SR |
1500 | } |
1501 | ||
cf75d5d6 | 1502 | /** |
8a7e4c24 | 1503 | * scsih_change_queue_depth - setting device queue depth |
cf75d5d6 CH |
1504 | * @sdev: scsi device struct |
1505 | * @qdepth: requested queue depth | |
1506 | * | |
4beb4867 | 1507 | * Return: queue depth. |
cf75d5d6 | 1508 | */ |
8bbb1cf6 | 1509 | static int |
8a7e4c24 | 1510 | scsih_change_queue_depth(struct scsi_device *sdev, int qdepth) |
f92363d1 SR |
1511 | { |
1512 | struct Scsi_Host *shost = sdev->host; | |
1513 | int max_depth; | |
1514 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
1515 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
1516 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1517 | struct _sas_device *sas_device; | |
1518 | unsigned long flags; | |
1519 | ||
1520 | max_depth = shost->can_queue; | |
1521 | ||
1522 | /* limit max device queue for SATA to 32 */ | |
1523 | sas_device_priv_data = sdev->hostdata; | |
1524 | if (!sas_device_priv_data) | |
1525 | goto not_sata; | |
1526 | sas_target_priv_data = sas_device_priv_data->sas_target; | |
1527 | if (!sas_target_priv_data) | |
1528 | goto not_sata; | |
1529 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) | |
1530 | goto not_sata; | |
d1cb5e49 | 1531 | |
f92363d1 | 1532 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 SR |
1533 | sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data); |
1534 | if (sas_device) { | |
1535 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE) | |
1536 | max_depth = MPT3SAS_SATA_QUEUE_DEPTH; | |
1537 | ||
1538 | sas_device_put(sas_device); | |
1539 | } | |
f92363d1 SR |
1540 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
1541 | ||
1542 | not_sata: | |
1543 | ||
1544 | if (!sdev->tagged_supported) | |
1545 | max_depth = 1; | |
1546 | if (qdepth > max_depth) | |
1547 | qdepth = max_depth; | |
cf75d5d6 | 1548 | return scsi_change_queue_depth(sdev, qdepth); |
f92363d1 SR |
1549 | } |
1550 | ||
f92363d1 | 1551 | /** |
8a7e4c24 | 1552 | * scsih_target_alloc - target add routine |
f92363d1 SR |
1553 | * @starget: scsi target struct |
1554 | * | |
4beb4867 | 1555 | * Return: 0 if ok. Any other return is assumed to be an error and |
f92363d1 SR |
1556 | * the device is ignored. |
1557 | */ | |
8bbb1cf6 | 1558 | static int |
8a7e4c24 | 1559 | scsih_target_alloc(struct scsi_target *starget) |
f92363d1 SR |
1560 | { |
1561 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); | |
1562 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
1563 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1564 | struct _sas_device *sas_device; | |
1565 | struct _raid_device *raid_device; | |
d88e1eab | 1566 | struct _pcie_device *pcie_device; |
f92363d1 SR |
1567 | unsigned long flags; |
1568 | struct sas_rphy *rphy; | |
1569 | ||
62c4da44 JL |
1570 | sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data), |
1571 | GFP_KERNEL); | |
f92363d1 SR |
1572 | if (!sas_target_priv_data) |
1573 | return -ENOMEM; | |
1574 | ||
1575 | starget->hostdata = sas_target_priv_data; | |
1576 | sas_target_priv_data->starget = starget; | |
1577 | sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE; | |
1578 | ||
1579 | /* RAID volumes */ | |
1580 | if (starget->channel == RAID_CHANNEL) { | |
1581 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1582 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, | |
1583 | starget->channel); | |
1584 | if (raid_device) { | |
1585 | sas_target_priv_data->handle = raid_device->handle; | |
1586 | sas_target_priv_data->sas_address = raid_device->wwid; | |
1587 | sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME; | |
7786ab6a | 1588 | if (ioc->is_warpdrive) |
6d3a56ed SR |
1589 | sas_target_priv_data->raid_device = raid_device; |
1590 | raid_device->starget = starget; | |
f92363d1 SR |
1591 | } |
1592 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1593 | return 0; | |
1594 | } | |
1595 | ||
d88e1eab SPS |
1596 | /* PCIe devices */ |
1597 | if (starget->channel == PCIE_CHANNEL) { | |
1598 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1599 | pcie_device = __mpt3sas_get_pdev_by_idchannel(ioc, starget->id, | |
1600 | starget->channel); | |
1601 | if (pcie_device) { | |
1602 | sas_target_priv_data->handle = pcie_device->handle; | |
1603 | sas_target_priv_data->sas_address = pcie_device->wwid; | |
1604 | sas_target_priv_data->pcie_dev = pcie_device; | |
1605 | pcie_device->starget = starget; | |
1606 | pcie_device->id = starget->id; | |
1607 | pcie_device->channel = starget->channel; | |
1608 | sas_target_priv_data->flags |= | |
1609 | MPT_TARGET_FLAGS_PCIE_DEVICE; | |
1610 | if (pcie_device->fast_path) | |
1611 | sas_target_priv_data->flags |= | |
1612 | MPT_TARGET_FASTPATH_IO; | |
1613 | } | |
1614 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1615 | return 0; | |
1616 | } | |
1617 | ||
f92363d1 SR |
1618 | /* sas/sata devices */ |
1619 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
1620 | rphy = dev_to_rphy(starget->dev.parent); | |
d1cb5e49 | 1621 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 SR |
1622 | rphy->identify.sas_address); |
1623 | ||
1624 | if (sas_device) { | |
1625 | sas_target_priv_data->handle = sas_device->handle; | |
1626 | sas_target_priv_data->sas_address = sas_device->sas_address; | |
d88e1eab | 1627 | sas_target_priv_data->sas_dev = sas_device; |
f92363d1 SR |
1628 | sas_device->starget = starget; |
1629 | sas_device->id = starget->id; | |
1630 | sas_device->channel = starget->channel; | |
1631 | if (test_bit(sas_device->handle, ioc->pd_handles)) | |
1632 | sas_target_priv_data->flags |= | |
1633 | MPT_TARGET_FLAGS_RAID_COMPONENT; | |
1634 | if (sas_device->fast_path) | |
d88e1eab SPS |
1635 | sas_target_priv_data->flags |= |
1636 | MPT_TARGET_FASTPATH_IO; | |
f92363d1 SR |
1637 | } |
1638 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
1639 | ||
1640 | return 0; | |
1641 | } | |
1642 | ||
1643 | /** | |
8a7e4c24 | 1644 | * scsih_target_destroy - target destroy routine |
f92363d1 | 1645 | * @starget: scsi target struct |
f92363d1 | 1646 | */ |
8bbb1cf6 | 1647 | static void |
8a7e4c24 | 1648 | scsih_target_destroy(struct scsi_target *starget) |
f92363d1 SR |
1649 | { |
1650 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); | |
1651 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
1652 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1653 | struct _sas_device *sas_device; | |
1654 | struct _raid_device *raid_device; | |
d88e1eab | 1655 | struct _pcie_device *pcie_device; |
f92363d1 | 1656 | unsigned long flags; |
f92363d1 SR |
1657 | |
1658 | sas_target_priv_data = starget->hostdata; | |
1659 | if (!sas_target_priv_data) | |
1660 | return; | |
1661 | ||
1662 | if (starget->channel == RAID_CHANNEL) { | |
1663 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1664 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, | |
1665 | starget->channel); | |
1666 | if (raid_device) { | |
1667 | raid_device->starget = NULL; | |
1668 | raid_device->sdev = NULL; | |
1669 | } | |
1670 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1671 | goto out; | |
1672 | } | |
1673 | ||
d88e1eab SPS |
1674 | if (starget->channel == PCIE_CHANNEL) { |
1675 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1676 | pcie_device = __mpt3sas_get_pdev_from_target(ioc, | |
1677 | sas_target_priv_data); | |
1678 | if (pcie_device && (pcie_device->starget == starget) && | |
1679 | (pcie_device->id == starget->id) && | |
1680 | (pcie_device->channel == starget->channel)) | |
1681 | pcie_device->starget = NULL; | |
1682 | ||
1683 | if (pcie_device) { | |
1684 | /* | |
1685 | * Corresponding get() is in _scsih_target_alloc() | |
1686 | */ | |
1687 | sas_target_priv_data->pcie_dev = NULL; | |
1688 | pcie_device_put(pcie_device); | |
1689 | pcie_device_put(pcie_device); | |
1690 | } | |
1691 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1692 | goto out; | |
1693 | } | |
1694 | ||
f92363d1 | 1695 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 1696 | sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data); |
f92363d1 SR |
1697 | if (sas_device && (sas_device->starget == starget) && |
1698 | (sas_device->id == starget->id) && | |
1699 | (sas_device->channel == starget->channel)) | |
1700 | sas_device->starget = NULL; | |
1701 | ||
d1cb5e49 SR |
1702 | if (sas_device) { |
1703 | /* | |
1704 | * Corresponding get() is in _scsih_target_alloc() | |
1705 | */ | |
d88e1eab | 1706 | sas_target_priv_data->sas_dev = NULL; |
d1cb5e49 SR |
1707 | sas_device_put(sas_device); |
1708 | ||
1709 | sas_device_put(sas_device); | |
1710 | } | |
f92363d1 SR |
1711 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
1712 | ||
1713 | out: | |
1714 | kfree(sas_target_priv_data); | |
1715 | starget->hostdata = NULL; | |
1716 | } | |
1717 | ||
1718 | /** | |
8a7e4c24 | 1719 | * scsih_slave_alloc - device add routine |
f92363d1 SR |
1720 | * @sdev: scsi device struct |
1721 | * | |
4beb4867 | 1722 | * Return: 0 if ok. Any other return is assumed to be an error and |
f92363d1 SR |
1723 | * the device is ignored. |
1724 | */ | |
8bbb1cf6 | 1725 | static int |
8a7e4c24 | 1726 | scsih_slave_alloc(struct scsi_device *sdev) |
f92363d1 SR |
1727 | { |
1728 | struct Scsi_Host *shost; | |
1729 | struct MPT3SAS_ADAPTER *ioc; | |
1730 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1731 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
1732 | struct scsi_target *starget; | |
1733 | struct _raid_device *raid_device; | |
b65cfedf | 1734 | struct _sas_device *sas_device; |
d88e1eab | 1735 | struct _pcie_device *pcie_device; |
f92363d1 SR |
1736 | unsigned long flags; |
1737 | ||
62c4da44 JL |
1738 | sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data), |
1739 | GFP_KERNEL); | |
f92363d1 SR |
1740 | if (!sas_device_priv_data) |
1741 | return -ENOMEM; | |
1742 | ||
1743 | sas_device_priv_data->lun = sdev->lun; | |
1744 | sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT; | |
1745 | ||
1746 | starget = scsi_target(sdev); | |
1747 | sas_target_priv_data = starget->hostdata; | |
1748 | sas_target_priv_data->num_luns++; | |
1749 | sas_device_priv_data->sas_target = sas_target_priv_data; | |
1750 | sdev->hostdata = sas_device_priv_data; | |
1751 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT)) | |
1752 | sdev->no_uld_attach = 1; | |
1753 | ||
1754 | shost = dev_to_shost(&starget->dev); | |
1755 | ioc = shost_priv(shost); | |
1756 | if (starget->channel == RAID_CHANNEL) { | |
1757 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1758 | raid_device = _scsih_raid_device_find_by_id(ioc, | |
1759 | starget->id, starget->channel); | |
1760 | if (raid_device) | |
1761 | raid_device->sdev = sdev; /* raid is single lun */ | |
1762 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1763 | } | |
d88e1eab SPS |
1764 | if (starget->channel == PCIE_CHANNEL) { |
1765 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1766 | pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, | |
1767 | sas_target_priv_data->sas_address); | |
1768 | if (pcie_device && (pcie_device->starget == NULL)) { | |
1769 | sdev_printk(KERN_INFO, sdev, | |
1770 | "%s : pcie_device->starget set to starget @ %d\n", | |
1771 | __func__, __LINE__); | |
1772 | pcie_device->starget = starget; | |
1773 | } | |
1774 | ||
1775 | if (pcie_device) | |
1776 | pcie_device_put(pcie_device); | |
1777 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
f92363d1 | 1778 | |
d88e1eab | 1779 | } else if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { |
b65cfedf | 1780 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 1781 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
b65cfedf SR |
1782 | sas_target_priv_data->sas_address); |
1783 | if (sas_device && (sas_device->starget == NULL)) { | |
1784 | sdev_printk(KERN_INFO, sdev, | |
1785 | "%s : sas_device->starget set to starget @ %d\n", | |
d1cb5e49 | 1786 | __func__, __LINE__); |
b65cfedf SR |
1787 | sas_device->starget = starget; |
1788 | } | |
d1cb5e49 SR |
1789 | |
1790 | if (sas_device) | |
1791 | sas_device_put(sas_device); | |
1792 | ||
b65cfedf SR |
1793 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
1794 | } | |
1795 | ||
f92363d1 SR |
1796 | return 0; |
1797 | } | |
1798 | ||
1799 | /** | |
8a7e4c24 | 1800 | * scsih_slave_destroy - device destroy routine |
f92363d1 | 1801 | * @sdev: scsi device struct |
f92363d1 | 1802 | */ |
8bbb1cf6 | 1803 | static void |
8a7e4c24 | 1804 | scsih_slave_destroy(struct scsi_device *sdev) |
f92363d1 SR |
1805 | { |
1806 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1807 | struct scsi_target *starget; | |
1808 | struct Scsi_Host *shost; | |
1809 | struct MPT3SAS_ADAPTER *ioc; | |
1810 | struct _sas_device *sas_device; | |
d88e1eab | 1811 | struct _pcie_device *pcie_device; |
f92363d1 SR |
1812 | unsigned long flags; |
1813 | ||
1814 | if (!sdev->hostdata) | |
1815 | return; | |
1816 | ||
1817 | starget = scsi_target(sdev); | |
1818 | sas_target_priv_data = starget->hostdata; | |
1819 | sas_target_priv_data->num_luns--; | |
1820 | ||
1821 | shost = dev_to_shost(&starget->dev); | |
1822 | ioc = shost_priv(shost); | |
1823 | ||
d88e1eab SPS |
1824 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) { |
1825 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1826 | pcie_device = __mpt3sas_get_pdev_from_target(ioc, | |
1827 | sas_target_priv_data); | |
1828 | if (pcie_device && !sas_target_priv_data->num_luns) | |
1829 | pcie_device->starget = NULL; | |
1830 | ||
1831 | if (pcie_device) | |
1832 | pcie_device_put(pcie_device); | |
1833 | ||
1834 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1835 | ||
1836 | } else if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { | |
f92363d1 | 1837 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 SR |
1838 | sas_device = __mpt3sas_get_sdev_from_target(ioc, |
1839 | sas_target_priv_data); | |
f92363d1 SR |
1840 | if (sas_device && !sas_target_priv_data->num_luns) |
1841 | sas_device->starget = NULL; | |
d1cb5e49 SR |
1842 | |
1843 | if (sas_device) | |
1844 | sas_device_put(sas_device); | |
f92363d1 SR |
1845 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
1846 | } | |
1847 | ||
1848 | kfree(sdev->hostdata); | |
1849 | sdev->hostdata = NULL; | |
1850 | } | |
1851 | ||
1852 | /** | |
1853 | * _scsih_display_sata_capabilities - sata capabilities | |
1854 | * @ioc: per adapter object | |
1855 | * @handle: device handle | |
1856 | * @sdev: scsi device struct | |
1857 | */ | |
1858 | static void | |
1859 | _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc, | |
1860 | u16 handle, struct scsi_device *sdev) | |
1861 | { | |
1862 | Mpi2ConfigReply_t mpi_reply; | |
1863 | Mpi2SasDevicePage0_t sas_device_pg0; | |
1864 | u32 ioc_status; | |
1865 | u16 flags; | |
1866 | u32 device_info; | |
1867 | ||
1868 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
1869 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
919d8a3f JP |
1870 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
1871 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
1872 | return; |
1873 | } | |
1874 | ||
1875 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
1876 | MPI2_IOCSTATUS_MASK; | |
1877 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
919d8a3f JP |
1878 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
1879 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
1880 | return; |
1881 | } | |
1882 | ||
1883 | flags = le16_to_cpu(sas_device_pg0.Flags); | |
1884 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | |
1885 | ||
1886 | sdev_printk(KERN_INFO, sdev, | |
1887 | "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), " | |
1888 | "sw_preserve(%s)\n", | |
1889 | (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n", | |
1890 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n", | |
1891 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" : | |
1892 | "n", | |
1893 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n", | |
1894 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n", | |
1895 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n"); | |
1896 | } | |
1897 | ||
1898 | /* | |
1899 | * raid transport support - | |
1900 | * Enabled for SLES11 and newer, in older kernels the driver will panic when | |
6c7abffc | 1901 | * unloading the driver followed by a load - I believe that the subroutine |
f92363d1 SR |
1902 | * raid_class_release() is not cleaning up properly. |
1903 | */ | |
1904 | ||
1905 | /** | |
8a7e4c24 | 1906 | * scsih_is_raid - return boolean indicating device is raid volume |
4beb4867 | 1907 | * @dev: the device struct object |
f92363d1 | 1908 | */ |
8bbb1cf6 | 1909 | static int |
8a7e4c24 | 1910 | scsih_is_raid(struct device *dev) |
f92363d1 SR |
1911 | { |
1912 | struct scsi_device *sdev = to_scsi_device(dev); | |
7786ab6a | 1913 | struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host); |
f92363d1 | 1914 | |
7786ab6a SR |
1915 | if (ioc->is_warpdrive) |
1916 | return 0; | |
f92363d1 SR |
1917 | return (sdev->channel == RAID_CHANNEL) ? 1 : 0; |
1918 | } | |
1919 | ||
cd5897ed SPS |
1920 | static int |
1921 | scsih_is_nvme(struct device *dev) | |
1922 | { | |
1923 | struct scsi_device *sdev = to_scsi_device(dev); | |
1924 | ||
1925 | return (sdev->channel == PCIE_CHANNEL) ? 1 : 0; | |
1926 | } | |
1927 | ||
f92363d1 | 1928 | /** |
8a7e4c24 | 1929 | * scsih_get_resync - get raid volume resync percent complete |
4beb4867 | 1930 | * @dev: the device struct object |
f92363d1 | 1931 | */ |
8bbb1cf6 | 1932 | static void |
8a7e4c24 | 1933 | scsih_get_resync(struct device *dev) |
f92363d1 SR |
1934 | { |
1935 | struct scsi_device *sdev = to_scsi_device(dev); | |
1936 | struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host); | |
1937 | static struct _raid_device *raid_device; | |
1938 | unsigned long flags; | |
1939 | Mpi2RaidVolPage0_t vol_pg0; | |
1940 | Mpi2ConfigReply_t mpi_reply; | |
1941 | u32 volume_status_flags; | |
1942 | u8 percent_complete; | |
1943 | u16 handle; | |
1944 | ||
1945 | percent_complete = 0; | |
1946 | handle = 0; | |
7786ab6a SR |
1947 | if (ioc->is_warpdrive) |
1948 | goto out; | |
1949 | ||
f92363d1 SR |
1950 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
1951 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, | |
1952 | sdev->channel); | |
1953 | if (raid_device) { | |
1954 | handle = raid_device->handle; | |
1955 | percent_complete = raid_device->percent_complete; | |
1956 | } | |
1957 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1958 | ||
1959 | if (!handle) | |
1960 | goto out; | |
1961 | ||
1962 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0, | |
1963 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
1964 | sizeof(Mpi2RaidVolPage0_t))) { | |
919d8a3f JP |
1965 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
1966 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
1967 | percent_complete = 0; |
1968 | goto out; | |
1969 | } | |
1970 | ||
1971 | volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags); | |
1972 | if (!(volume_status_flags & | |
1973 | MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)) | |
1974 | percent_complete = 0; | |
1975 | ||
1976 | out: | |
b130b0d5 SS |
1977 | |
1978 | switch (ioc->hba_mpi_version_belonged) { | |
1979 | case MPI2_VERSION: | |
c84b06a4 | 1980 | raid_set_resync(mpt2sas_raid_template, dev, percent_complete); |
b130b0d5 SS |
1981 | break; |
1982 | case MPI25_VERSION: | |
1983 | case MPI26_VERSION: | |
c84b06a4 | 1984 | raid_set_resync(mpt3sas_raid_template, dev, percent_complete); |
b130b0d5 SS |
1985 | break; |
1986 | } | |
f92363d1 SR |
1987 | } |
1988 | ||
1989 | /** | |
8a7e4c24 | 1990 | * scsih_get_state - get raid volume level |
4beb4867 | 1991 | * @dev: the device struct object |
f92363d1 | 1992 | */ |
8bbb1cf6 | 1993 | static void |
8a7e4c24 | 1994 | scsih_get_state(struct device *dev) |
f92363d1 SR |
1995 | { |
1996 | struct scsi_device *sdev = to_scsi_device(dev); | |
1997 | struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host); | |
1998 | static struct _raid_device *raid_device; | |
1999 | unsigned long flags; | |
2000 | Mpi2RaidVolPage0_t vol_pg0; | |
2001 | Mpi2ConfigReply_t mpi_reply; | |
2002 | u32 volstate; | |
2003 | enum raid_state state = RAID_STATE_UNKNOWN; | |
2004 | u16 handle = 0; | |
2005 | ||
2006 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
2007 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, | |
2008 | sdev->channel); | |
2009 | if (raid_device) | |
2010 | handle = raid_device->handle; | |
2011 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
2012 | ||
2013 | if (!raid_device) | |
2014 | goto out; | |
2015 | ||
2016 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0, | |
2017 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
2018 | sizeof(Mpi2RaidVolPage0_t))) { | |
919d8a3f JP |
2019 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
2020 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
2021 | goto out; |
2022 | } | |
2023 | ||
2024 | volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags); | |
2025 | if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) { | |
2026 | state = RAID_STATE_RESYNCING; | |
2027 | goto out; | |
2028 | } | |
2029 | ||
2030 | switch (vol_pg0.VolumeState) { | |
2031 | case MPI2_RAID_VOL_STATE_OPTIMAL: | |
2032 | case MPI2_RAID_VOL_STATE_ONLINE: | |
2033 | state = RAID_STATE_ACTIVE; | |
2034 | break; | |
2035 | case MPI2_RAID_VOL_STATE_DEGRADED: | |
2036 | state = RAID_STATE_DEGRADED; | |
2037 | break; | |
2038 | case MPI2_RAID_VOL_STATE_FAILED: | |
2039 | case MPI2_RAID_VOL_STATE_MISSING: | |
2040 | state = RAID_STATE_OFFLINE; | |
2041 | break; | |
2042 | } | |
2043 | out: | |
b130b0d5 SS |
2044 | switch (ioc->hba_mpi_version_belonged) { |
2045 | case MPI2_VERSION: | |
c84b06a4 | 2046 | raid_set_state(mpt2sas_raid_template, dev, state); |
b130b0d5 SS |
2047 | break; |
2048 | case MPI25_VERSION: | |
2049 | case MPI26_VERSION: | |
c84b06a4 | 2050 | raid_set_state(mpt3sas_raid_template, dev, state); |
b130b0d5 SS |
2051 | break; |
2052 | } | |
f92363d1 SR |
2053 | } |
2054 | ||
2055 | /** | |
2056 | * _scsih_set_level - set raid level | |
4beb4867 | 2057 | * @ioc: ? |
f92363d1 SR |
2058 | * @sdev: scsi device struct |
2059 | * @volume_type: volume type | |
2060 | */ | |
2061 | static void | |
c84b06a4 SR |
2062 | _scsih_set_level(struct MPT3SAS_ADAPTER *ioc, |
2063 | struct scsi_device *sdev, u8 volume_type) | |
f92363d1 SR |
2064 | { |
2065 | enum raid_level level = RAID_LEVEL_UNKNOWN; | |
2066 | ||
2067 | switch (volume_type) { | |
2068 | case MPI2_RAID_VOL_TYPE_RAID0: | |
2069 | level = RAID_LEVEL_0; | |
2070 | break; | |
2071 | case MPI2_RAID_VOL_TYPE_RAID10: | |
2072 | level = RAID_LEVEL_10; | |
2073 | break; | |
2074 | case MPI2_RAID_VOL_TYPE_RAID1E: | |
2075 | level = RAID_LEVEL_1E; | |
2076 | break; | |
2077 | case MPI2_RAID_VOL_TYPE_RAID1: | |
2078 | level = RAID_LEVEL_1; | |
2079 | break; | |
2080 | } | |
2081 | ||
b130b0d5 SS |
2082 | switch (ioc->hba_mpi_version_belonged) { |
2083 | case MPI2_VERSION: | |
c84b06a4 | 2084 | raid_set_level(mpt2sas_raid_template, |
b130b0d5 SS |
2085 | &sdev->sdev_gendev, level); |
2086 | break; | |
2087 | case MPI25_VERSION: | |
2088 | case MPI26_VERSION: | |
c84b06a4 | 2089 | raid_set_level(mpt3sas_raid_template, |
b130b0d5 SS |
2090 | &sdev->sdev_gendev, level); |
2091 | break; | |
2092 | } | |
f92363d1 SR |
2093 | } |
2094 | ||
2095 | ||
2096 | /** | |
2097 | * _scsih_get_volume_capabilities - volume capabilities | |
2098 | * @ioc: per adapter object | |
4beb4867 | 2099 | * @raid_device: the raid_device object |
f92363d1 | 2100 | * |
4beb4867 | 2101 | * Return: 0 for success, else 1 |
f92363d1 SR |
2102 | */ |
2103 | static int | |
2104 | _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc, | |
2105 | struct _raid_device *raid_device) | |
2106 | { | |
2107 | Mpi2RaidVolPage0_t *vol_pg0; | |
2108 | Mpi2RaidPhysDiskPage0_t pd_pg0; | |
2109 | Mpi2SasDevicePage0_t sas_device_pg0; | |
2110 | Mpi2ConfigReply_t mpi_reply; | |
2111 | u16 sz; | |
2112 | u8 num_pds; | |
2113 | ||
2114 | if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle, | |
2115 | &num_pds)) || !num_pds) { | |
919d8a3f JP |
2116 | dfailprintk(ioc, |
2117 | ioc_warn(ioc, "failure at %s:%d/%s()!\n", | |
2118 | __FILE__, __LINE__, __func__)); | |
f92363d1 SR |
2119 | return 1; |
2120 | } | |
2121 | ||
2122 | raid_device->num_pds = num_pds; | |
2123 | sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds * | |
2124 | sizeof(Mpi2RaidVol0PhysDisk_t)); | |
2125 | vol_pg0 = kzalloc(sz, GFP_KERNEL); | |
2126 | if (!vol_pg0) { | |
919d8a3f JP |
2127 | dfailprintk(ioc, |
2128 | ioc_warn(ioc, "failure at %s:%d/%s()!\n", | |
2129 | __FILE__, __LINE__, __func__)); | |
f92363d1 SR |
2130 | return 1; |
2131 | } | |
2132 | ||
2133 | if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0, | |
2134 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) { | |
919d8a3f JP |
2135 | dfailprintk(ioc, |
2136 | ioc_warn(ioc, "failure at %s:%d/%s()!\n", | |
2137 | __FILE__, __LINE__, __func__)); | |
f92363d1 SR |
2138 | kfree(vol_pg0); |
2139 | return 1; | |
2140 | } | |
2141 | ||
2142 | raid_device->volume_type = vol_pg0->VolumeType; | |
2143 | ||
2144 | /* figure out what the underlying devices are by | |
2145 | * obtaining the device_info bits for the 1st device | |
2146 | */ | |
2147 | if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | |
2148 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM, | |
2149 | vol_pg0->PhysDisk[0].PhysDiskNum))) { | |
2150 | if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
2151 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | |
2152 | le16_to_cpu(pd_pg0.DevHandle)))) { | |
2153 | raid_device->device_info = | |
2154 | le32_to_cpu(sas_device_pg0.DeviceInfo); | |
2155 | } | |
2156 | } | |
2157 | ||
2158 | kfree(vol_pg0); | |
2159 | return 0; | |
2160 | } | |
2161 | ||
f92363d1 SR |
2162 | /** |
2163 | * _scsih_enable_tlr - setting TLR flags | |
2164 | * @ioc: per adapter object | |
2165 | * @sdev: scsi device struct | |
2166 | * | |
2167 | * Enabling Transaction Layer Retries for tape devices when | |
2168 | * vpd page 0x90 is present | |
2169 | * | |
2170 | */ | |
2171 | static void | |
2172 | _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev) | |
2173 | { | |
2174 | ||
2175 | /* only for TAPE */ | |
2176 | if (sdev->type != TYPE_TAPE) | |
2177 | return; | |
2178 | ||
2179 | if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR)) | |
2180 | return; | |
2181 | ||
2182 | sas_enable_tlr(sdev); | |
2183 | sdev_printk(KERN_INFO, sdev, "TLR %s\n", | |
2184 | sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled"); | |
2185 | return; | |
2186 | ||
2187 | } | |
2188 | ||
2189 | /** | |
8a7e4c24 | 2190 | * scsih_slave_configure - device configure routine. |
f92363d1 SR |
2191 | * @sdev: scsi device struct |
2192 | * | |
4beb4867 | 2193 | * Return: 0 if ok. Any other return is assumed to be an error and |
f92363d1 SR |
2194 | * the device is ignored. |
2195 | */ | |
8bbb1cf6 | 2196 | static int |
8a7e4c24 | 2197 | scsih_slave_configure(struct scsi_device *sdev) |
f92363d1 SR |
2198 | { |
2199 | struct Scsi_Host *shost = sdev->host; | |
2200 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
2201 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2202 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
2203 | struct _sas_device *sas_device; | |
d1b01d14 | 2204 | struct _pcie_device *pcie_device; |
f92363d1 SR |
2205 | struct _raid_device *raid_device; |
2206 | unsigned long flags; | |
2207 | int qdepth; | |
2208 | u8 ssp_target = 0; | |
2209 | char *ds = ""; | |
2210 | char *r_level = ""; | |
2211 | u16 handle, volume_handle = 0; | |
2212 | u64 volume_wwid = 0; | |
2213 | ||
2214 | qdepth = 1; | |
2215 | sas_device_priv_data = sdev->hostdata; | |
2216 | sas_device_priv_data->configured_lun = 1; | |
2217 | sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT; | |
2218 | sas_target_priv_data = sas_device_priv_data->sas_target; | |
2219 | handle = sas_target_priv_data->handle; | |
2220 | ||
2221 | /* raid volume handling */ | |
2222 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) { | |
2223 | ||
2224 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
c84b06a4 | 2225 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
2226 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
2227 | if (!raid_device) { | |
919d8a3f JP |
2228 | dfailprintk(ioc, |
2229 | ioc_warn(ioc, "failure at %s:%d/%s()!\n", | |
2230 | __FILE__, __LINE__, __func__)); | |
f92363d1 SR |
2231 | return 1; |
2232 | } | |
2233 | ||
2234 | if (_scsih_get_volume_capabilities(ioc, raid_device)) { | |
919d8a3f JP |
2235 | dfailprintk(ioc, |
2236 | ioc_warn(ioc, "failure at %s:%d/%s()!\n", | |
2237 | __FILE__, __LINE__, __func__)); | |
f92363d1 SR |
2238 | return 1; |
2239 | } | |
2240 | ||
7786ab6a SR |
2241 | /* |
2242 | * WARPDRIVE: Initialize the required data for Direct IO | |
2243 | */ | |
c84b06a4 | 2244 | mpt3sas_init_warpdrive_properties(ioc, raid_device); |
f92363d1 SR |
2245 | |
2246 | /* RAID Queue Depth Support | |
2247 | * IS volume = underlying qdepth of drive type, either | |
2248 | * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH | |
2249 | * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH) | |
2250 | */ | |
2251 | if (raid_device->device_info & | |
2252 | MPI2_SAS_DEVICE_INFO_SSP_TARGET) { | |
2253 | qdepth = MPT3SAS_SAS_QUEUE_DEPTH; | |
2254 | ds = "SSP"; | |
2255 | } else { | |
2256 | qdepth = MPT3SAS_SATA_QUEUE_DEPTH; | |
199fd79a | 2257 | if (raid_device->device_info & |
f92363d1 SR |
2258 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) |
2259 | ds = "SATA"; | |
2260 | else | |
2261 | ds = "STP"; | |
2262 | } | |
2263 | ||
2264 | switch (raid_device->volume_type) { | |
2265 | case MPI2_RAID_VOL_TYPE_RAID0: | |
2266 | r_level = "RAID0"; | |
2267 | break; | |
2268 | case MPI2_RAID_VOL_TYPE_RAID1E: | |
2269 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
2270 | if (ioc->manu_pg10.OEMIdentifier && | |
2271 | (le32_to_cpu(ioc->manu_pg10.GenericFlags0) & | |
2272 | MFG10_GF0_R10_DISPLAY) && | |
2273 | !(raid_device->num_pds % 2)) | |
2274 | r_level = "RAID10"; | |
2275 | else | |
2276 | r_level = "RAID1E"; | |
2277 | break; | |
2278 | case MPI2_RAID_VOL_TYPE_RAID1: | |
2279 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
2280 | r_level = "RAID1"; | |
2281 | break; | |
2282 | case MPI2_RAID_VOL_TYPE_RAID10: | |
2283 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
2284 | r_level = "RAID10"; | |
2285 | break; | |
2286 | case MPI2_RAID_VOL_TYPE_UNKNOWN: | |
2287 | default: | |
2288 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
2289 | r_level = "RAIDX"; | |
2290 | break; | |
2291 | } | |
2292 | ||
7786ab6a SR |
2293 | if (!ioc->hide_ir_msg) |
2294 | sdev_printk(KERN_INFO, sdev, | |
2295 | "%s: handle(0x%04x), wwid(0x%016llx)," | |
2296 | " pd_count(%d), type(%s)\n", | |
2297 | r_level, raid_device->handle, | |
2298 | (unsigned long long)raid_device->wwid, | |
2299 | raid_device->num_pds, ds); | |
f92363d1 | 2300 | |
6c197093 C |
2301 | if (shost->max_sectors > MPT3SAS_RAID_MAX_SECTORS) { |
2302 | blk_queue_max_hw_sectors(sdev->request_queue, | |
2303 | MPT3SAS_RAID_MAX_SECTORS); | |
2304 | sdev_printk(KERN_INFO, sdev, | |
2305 | "Set queue's max_sector to: %u\n", | |
2306 | MPT3SAS_RAID_MAX_SECTORS); | |
2307 | } | |
2308 | ||
8a7e4c24 | 2309 | scsih_change_queue_depth(sdev, qdepth); |
f92363d1 | 2310 | |
7786ab6a SR |
2311 | /* raid transport support */ |
2312 | if (!ioc->is_warpdrive) | |
c84b06a4 | 2313 | _scsih_set_level(ioc, sdev, raid_device->volume_type); |
f92363d1 SR |
2314 | return 0; |
2315 | } | |
2316 | ||
2317 | /* non-raid handling */ | |
2318 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
2319 | if (mpt3sas_config_get_volume_handle(ioc, handle, | |
2320 | &volume_handle)) { | |
919d8a3f JP |
2321 | dfailprintk(ioc, |
2322 | ioc_warn(ioc, "failure at %s:%d/%s()!\n", | |
2323 | __FILE__, __LINE__, __func__)); | |
f92363d1 SR |
2324 | return 1; |
2325 | } | |
2326 | if (volume_handle && mpt3sas_config_get_volume_wwid(ioc, | |
2327 | volume_handle, &volume_wwid)) { | |
919d8a3f JP |
2328 | dfailprintk(ioc, |
2329 | ioc_warn(ioc, "failure at %s:%d/%s()!\n", | |
2330 | __FILE__, __LINE__, __func__)); | |
f92363d1 SR |
2331 | return 1; |
2332 | } | |
2333 | } | |
2334 | ||
d1b01d14 SPS |
2335 | /* PCIe handling */ |
2336 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) { | |
2337 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
2338 | pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, | |
2339 | sas_device_priv_data->sas_target->sas_address); | |
2340 | if (!pcie_device) { | |
2341 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
919d8a3f JP |
2342 | dfailprintk(ioc, |
2343 | ioc_warn(ioc, "failure at %s:%d/%s()!\n", | |
2344 | __FILE__, __LINE__, __func__)); | |
d1b01d14 SPS |
2345 | return 1; |
2346 | } | |
2347 | ||
2348 | qdepth = MPT3SAS_NVME_QUEUE_DEPTH; | |
2349 | ds = "NVMe"; | |
2350 | sdev_printk(KERN_INFO, sdev, | |
2351 | "%s: handle(0x%04x), wwid(0x%016llx), port(%d)\n", | |
2352 | ds, handle, (unsigned long long)pcie_device->wwid, | |
2353 | pcie_device->port_num); | |
2354 | if (pcie_device->enclosure_handle != 0) | |
2355 | sdev_printk(KERN_INFO, sdev, | |
2356 | "%s: enclosure logical id(0x%016llx), slot(%d)\n", | |
2357 | ds, | |
2358 | (unsigned long long)pcie_device->enclosure_logical_id, | |
2359 | pcie_device->slot); | |
2360 | if (pcie_device->connector_name[0] != '\0') | |
2361 | sdev_printk(KERN_INFO, sdev, | |
2362 | "%s: enclosure level(0x%04x)," | |
2363 | "connector name( %s)\n", ds, | |
2364 | pcie_device->enclosure_level, | |
2365 | pcie_device->connector_name); | |
d1b01d14 SPS |
2366 | |
2367 | if (pcie_device->nvme_mdts) | |
2368 | blk_queue_max_hw_sectors(sdev->request_queue, | |
2369 | pcie_device->nvme_mdts/512); | |
20a04433 C |
2370 | |
2371 | pcie_device_put(pcie_device); | |
2372 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
2373 | scsih_change_queue_depth(sdev, qdepth); | |
d1b01d14 SPS |
2374 | /* Enable QUEUE_FLAG_NOMERGES flag, so that IOs won't be |
2375 | ** merged and can eliminate holes created during merging | |
2376 | ** operation. | |
2377 | **/ | |
8b904b5b | 2378 | blk_queue_flag_set(QUEUE_FLAG_NOMERGES, |
d1b01d14 SPS |
2379 | sdev->request_queue); |
2380 | blk_queue_virt_boundary(sdev->request_queue, | |
2381 | ioc->page_size - 1); | |
2382 | return 0; | |
2383 | } | |
2384 | ||
f92363d1 | 2385 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 2386 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 SR |
2387 | sas_device_priv_data->sas_target->sas_address); |
2388 | if (!sas_device) { | |
2389 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
919d8a3f JP |
2390 | dfailprintk(ioc, |
2391 | ioc_warn(ioc, "failure at %s:%d/%s()!\n", | |
2392 | __FILE__, __LINE__, __func__)); | |
f92363d1 SR |
2393 | return 1; |
2394 | } | |
2395 | ||
2396 | sas_device->volume_handle = volume_handle; | |
2397 | sas_device->volume_wwid = volume_wwid; | |
2398 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) { | |
2399 | qdepth = MPT3SAS_SAS_QUEUE_DEPTH; | |
2400 | ssp_target = 1; | |
30158dc9 SS |
2401 | if (sas_device->device_info & |
2402 | MPI2_SAS_DEVICE_INFO_SEP) { | |
2403 | sdev_printk(KERN_WARNING, sdev, | |
2404 | "set ignore_delay_remove for handle(0x%04x)\n", | |
2405 | sas_device_priv_data->sas_target->handle); | |
2406 | sas_device_priv_data->ignore_delay_remove = 1; | |
2407 | ds = "SES"; | |
2408 | } else | |
2409 | ds = "SSP"; | |
f92363d1 SR |
2410 | } else { |
2411 | qdepth = MPT3SAS_SATA_QUEUE_DEPTH; | |
2412 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) | |
2413 | ds = "STP"; | |
2414 | else if (sas_device->device_info & | |
2415 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) | |
2416 | ds = "SATA"; | |
2417 | } | |
2418 | ||
2419 | sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \ | |
2420 | "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n", | |
2421 | ds, handle, (unsigned long long)sas_device->sas_address, | |
2422 | sas_device->phy, (unsigned long long)sas_device->device_name); | |
75888956 SR |
2423 | |
2424 | _scsih_display_enclosure_chassis_info(NULL, sas_device, sdev, NULL); | |
f92363d1 | 2425 | |
d1cb5e49 | 2426 | sas_device_put(sas_device); |
f92363d1 SR |
2427 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
2428 | ||
2429 | if (!ssp_target) | |
2430 | _scsih_display_sata_capabilities(ioc, handle, sdev); | |
2431 | ||
2432 | ||
8a7e4c24 | 2433 | scsih_change_queue_depth(sdev, qdepth); |
f92363d1 SR |
2434 | |
2435 | if (ssp_target) { | |
2436 | sas_read_port_mode_page(sdev); | |
2437 | _scsih_enable_tlr(ioc, sdev); | |
2438 | } | |
2439 | ||
2440 | return 0; | |
2441 | } | |
2442 | ||
2443 | /** | |
8a7e4c24 | 2444 | * scsih_bios_param - fetch head, sector, cylinder info for a disk |
f92363d1 SR |
2445 | * @sdev: scsi device struct |
2446 | * @bdev: pointer to block device context | |
2447 | * @capacity: device size (in 512 byte sectors) | |
2448 | * @params: three element array to place output: | |
2449 | * params[0] number of heads (max 255) | |
2450 | * params[1] number of sectors (max 63) | |
2451 | * params[2] number of cylinders | |
f92363d1 | 2452 | */ |
8bbb1cf6 | 2453 | static int |
8a7e4c24 | 2454 | scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev, |
f92363d1 SR |
2455 | sector_t capacity, int params[]) |
2456 | { | |
2457 | int heads; | |
2458 | int sectors; | |
2459 | sector_t cylinders; | |
2460 | ulong dummy; | |
2461 | ||
2462 | heads = 64; | |
2463 | sectors = 32; | |
2464 | ||
2465 | dummy = heads * sectors; | |
2466 | cylinders = capacity; | |
2467 | sector_div(cylinders, dummy); | |
2468 | ||
2469 | /* | |
2470 | * Handle extended translation size for logical drives | |
2471 | * > 1Gb | |
2472 | */ | |
2473 | if ((ulong)capacity >= 0x200000) { | |
2474 | heads = 255; | |
2475 | sectors = 63; | |
2476 | dummy = heads * sectors; | |
2477 | cylinders = capacity; | |
2478 | sector_div(cylinders, dummy); | |
2479 | } | |
2480 | ||
2481 | /* return result */ | |
2482 | params[0] = heads; | |
2483 | params[1] = sectors; | |
2484 | params[2] = cylinders; | |
2485 | ||
2486 | return 0; | |
2487 | } | |
2488 | ||
2489 | /** | |
2490 | * _scsih_response_code - translation of device response code | |
2491 | * @ioc: per adapter object | |
2492 | * @response_code: response code returned by the device | |
f92363d1 SR |
2493 | */ |
2494 | static void | |
2495 | _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code) | |
2496 | { | |
2497 | char *desc; | |
2498 | ||
2499 | switch (response_code) { | |
2500 | case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE: | |
2501 | desc = "task management request completed"; | |
2502 | break; | |
2503 | case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME: | |
2504 | desc = "invalid frame"; | |
2505 | break; | |
2506 | case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED: | |
2507 | desc = "task management request not supported"; | |
2508 | break; | |
2509 | case MPI2_SCSITASKMGMT_RSP_TM_FAILED: | |
2510 | desc = "task management request failed"; | |
2511 | break; | |
2512 | case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED: | |
2513 | desc = "task management request succeeded"; | |
2514 | break; | |
2515 | case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN: | |
2516 | desc = "invalid lun"; | |
2517 | break; | |
2518 | case 0xA: | |
2519 | desc = "overlapped tag attempted"; | |
2520 | break; | |
2521 | case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC: | |
2522 | desc = "task queued, however not sent to target"; | |
2523 | break; | |
2524 | default: | |
2525 | desc = "unknown"; | |
2526 | break; | |
2527 | } | |
919d8a3f | 2528 | ioc_warn(ioc, "response_code(0x%01x): %s\n", response_code, desc); |
f92363d1 SR |
2529 | } |
2530 | ||
2531 | /** | |
2532 | * _scsih_tm_done - tm completion routine | |
2533 | * @ioc: per adapter object | |
2534 | * @smid: system request message index | |
2535 | * @msix_index: MSIX table index supplied by the OS | |
2536 | * @reply: reply message frame(lower 32bit addr) | |
2537 | * Context: none. | |
2538 | * | |
2539 | * The callback handler when using scsih_issue_tm. | |
2540 | * | |
4beb4867 BVA |
2541 | * Return: 1 meaning mf should be freed from _base_interrupt |
2542 | * 0 means the mf is freed from this function. | |
f92363d1 SR |
2543 | */ |
2544 | static u8 | |
2545 | _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | |
2546 | { | |
2547 | MPI2DefaultReply_t *mpi_reply; | |
2548 | ||
2549 | if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED) | |
2550 | return 1; | |
2551 | if (ioc->tm_cmds.smid != smid) | |
2552 | return 1; | |
f92363d1 SR |
2553 | ioc->tm_cmds.status |= MPT3_CMD_COMPLETE; |
2554 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
2555 | if (mpi_reply) { | |
2556 | memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); | |
2557 | ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID; | |
2558 | } | |
2559 | ioc->tm_cmds.status &= ~MPT3_CMD_PENDING; | |
2560 | complete(&ioc->tm_cmds.done); | |
2561 | return 1; | |
2562 | } | |
2563 | ||
2564 | /** | |
2565 | * mpt3sas_scsih_set_tm_flag - set per target tm_busy | |
2566 | * @ioc: per adapter object | |
2567 | * @handle: device handle | |
2568 | * | |
2569 | * During taskmangement request, we need to freeze the device queue. | |
2570 | */ | |
2571 | void | |
2572 | mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
2573 | { | |
2574 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2575 | struct scsi_device *sdev; | |
2576 | u8 skip = 0; | |
2577 | ||
2578 | shost_for_each_device(sdev, ioc->shost) { | |
2579 | if (skip) | |
2580 | continue; | |
2581 | sas_device_priv_data = sdev->hostdata; | |
2582 | if (!sas_device_priv_data) | |
2583 | continue; | |
2584 | if (sas_device_priv_data->sas_target->handle == handle) { | |
2585 | sas_device_priv_data->sas_target->tm_busy = 1; | |
2586 | skip = 1; | |
2587 | ioc->ignore_loginfos = 1; | |
2588 | } | |
2589 | } | |
2590 | } | |
2591 | ||
2592 | /** | |
2593 | * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy | |
2594 | * @ioc: per adapter object | |
2595 | * @handle: device handle | |
2596 | * | |
2597 | * During taskmangement request, we need to freeze the device queue. | |
2598 | */ | |
2599 | void | |
2600 | mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
2601 | { | |
2602 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2603 | struct scsi_device *sdev; | |
2604 | u8 skip = 0; | |
2605 | ||
2606 | shost_for_each_device(sdev, ioc->shost) { | |
2607 | if (skip) | |
2608 | continue; | |
2609 | sas_device_priv_data = sdev->hostdata; | |
2610 | if (!sas_device_priv_data) | |
2611 | continue; | |
2612 | if (sas_device_priv_data->sas_target->handle == handle) { | |
2613 | sas_device_priv_data->sas_target->tm_busy = 0; | |
2614 | skip = 1; | |
2615 | ioc->ignore_loginfos = 0; | |
2616 | } | |
2617 | } | |
2618 | } | |
2619 | ||
2620 | /** | |
2621 | * mpt3sas_scsih_issue_tm - main routine for sending tm requests | |
2622 | * @ioc: per adapter struct | |
6da999fe | 2623 | * @handle: device handle |
f92363d1 SR |
2624 | * @lun: lun number |
2625 | * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h) | |
2626 | * @smid_task: smid assigned to the task | |
6da999fe | 2627 | * @msix_task: MSIX table index supplied by the OS |
f92363d1 | 2628 | * @timeout: timeout in seconds |
c1a6c5ac | 2629 | * @tr_method: Target Reset Method |
f92363d1 SR |
2630 | * Context: user |
2631 | * | |
2632 | * A generic API for sending task management requests to firmware. | |
2633 | * | |
2634 | * The callback index is set inside `ioc->tm_cb_idx`. | |
6da999fe | 2635 | * The caller is responsible to check for outstanding commands. |
f92363d1 | 2636 | * |
4beb4867 | 2637 | * Return: SUCCESS or FAILED. |
f92363d1 SR |
2638 | */ |
2639 | int | |
c1a6c5ac C |
2640 | mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, u64 lun, |
2641 | u8 type, u16 smid_task, u16 msix_task, u8 timeout, u8 tr_method) | |
f92363d1 SR |
2642 | { |
2643 | Mpi2SCSITaskManagementRequest_t *mpi_request; | |
2644 | Mpi2SCSITaskManagementReply_t *mpi_reply; | |
2645 | u16 smid = 0; | |
2646 | u32 ioc_state; | |
f92363d1 SR |
2647 | int rc; |
2648 | ||
96902835 CO |
2649 | lockdep_assert_held(&ioc->tm_cmds.mutex); |
2650 | ||
f92363d1 | 2651 | if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) { |
4dc74b2e | 2652 | ioc_info(ioc, "%s: tm_cmd busy!!!\n", __func__); |
96902835 | 2653 | return FAILED; |
f92363d1 SR |
2654 | } |
2655 | ||
2656 | if (ioc->shost_recovery || ioc->remove_host || | |
2657 | ioc->pci_error_recovery) { | |
4dc74b2e | 2658 | ioc_info(ioc, "%s: host reset in progress!\n", __func__); |
96902835 | 2659 | return FAILED; |
f92363d1 SR |
2660 | } |
2661 | ||
2662 | ioc_state = mpt3sas_base_get_iocstate(ioc, 0); | |
2663 | if (ioc_state & MPI2_DOORBELL_USED) { | |
919d8a3f | 2664 | dhsprintk(ioc, ioc_info(ioc, "unexpected doorbell active!\n")); |
98c56ad3 | 2665 | rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
96902835 | 2666 | return (!rc) ? SUCCESS : FAILED; |
f92363d1 SR |
2667 | } |
2668 | ||
2669 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { | |
2670 | mpt3sas_base_fault_info(ioc, ioc_state & | |
2671 | MPI2_DOORBELL_DATA_MASK); | |
98c56ad3 | 2672 | rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
96902835 | 2673 | return (!rc) ? SUCCESS : FAILED; |
f92363d1 SR |
2674 | } |
2675 | ||
2676 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx); | |
2677 | if (!smid) { | |
919d8a3f | 2678 | ioc_err(ioc, "%s: failed obtaining a smid\n", __func__); |
96902835 | 2679 | return FAILED; |
f92363d1 SR |
2680 | } |
2681 | ||
919d8a3f JP |
2682 | dtmprintk(ioc, |
2683 | ioc_info(ioc, "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d), timeout(%d), tr_method(0x%x)\n", | |
2684 | handle, type, smid_task, timeout, tr_method)); | |
f92363d1 SR |
2685 | ioc->tm_cmds.status = MPT3_CMD_PENDING; |
2686 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
2687 | ioc->tm_cmds.smid = smid; | |
2688 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | |
2689 | memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t)); | |
2690 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | |
2691 | mpi_request->DevHandle = cpu_to_le16(handle); | |
2692 | mpi_request->TaskType = type; | |
c1a6c5ac | 2693 | mpi_request->MsgFlags = tr_method; |
f92363d1 SR |
2694 | mpi_request->TaskMID = cpu_to_le16(smid_task); |
2695 | int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN); | |
2696 | mpt3sas_scsih_set_tm_flag(ioc, handle); | |
2697 | init_completion(&ioc->tm_cmds.done); | |
078a4cc1 | 2698 | ioc->put_smid_hi_priority(ioc, smid, msix_task); |
8bbb1cf6 | 2699 | wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ); |
f92363d1 | 2700 | if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) { |
d37306ca C |
2701 | if (mpt3sas_base_check_cmd_timeout(ioc, |
2702 | ioc->tm_cmds.status, mpi_request, | |
2703 | sizeof(Mpi2SCSITaskManagementRequest_t)/4)) { | |
98c56ad3 CO |
2704 | rc = mpt3sas_base_hard_reset_handler(ioc, |
2705 | FORCE_BIG_HAMMER); | |
f92363d1 | 2706 | rc = (!rc) ? SUCCESS : FAILED; |
96902835 | 2707 | goto out; |
f92363d1 SR |
2708 | } |
2709 | } | |
2710 | ||
5f0dfb7a C |
2711 | /* sync IRQs in case those were busy during flush. */ |
2712 | mpt3sas_base_sync_reply_irqs(ioc); | |
2713 | ||
f92363d1 SR |
2714 | if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) { |
2715 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT); | |
2716 | mpi_reply = ioc->tm_cmds.reply; | |
919d8a3f JP |
2717 | dtmprintk(ioc, |
2718 | ioc_info(ioc, "complete tm: ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n", | |
2719 | le16_to_cpu(mpi_reply->IOCStatus), | |
2720 | le32_to_cpu(mpi_reply->IOCLogInfo), | |
2721 | le32_to_cpu(mpi_reply->TerminationCount))); | |
f92363d1 SR |
2722 | if (ioc->logging_level & MPT_DEBUG_TM) { |
2723 | _scsih_response_code(ioc, mpi_reply->ResponseCode); | |
2724 | if (mpi_reply->IOCStatus) | |
2725 | _debug_dump_mf(mpi_request, | |
2726 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); | |
2727 | } | |
2728 | } | |
6da999fe | 2729 | rc = SUCCESS; |
f92363d1 | 2730 | |
96902835 | 2731 | out: |
f92363d1 SR |
2732 | mpt3sas_scsih_clear_tm_flag(ioc, handle); |
2733 | ioc->tm_cmds.status = MPT3_CMD_NOT_USED; | |
f92363d1 | 2734 | return rc; |
96902835 | 2735 | } |
f92363d1 | 2736 | |
96902835 | 2737 | int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, |
c1a6c5ac C |
2738 | u64 lun, u8 type, u16 smid_task, u16 msix_task, |
2739 | u8 timeout, u8 tr_method) | |
96902835 CO |
2740 | { |
2741 | int ret; | |
2742 | ||
2743 | mutex_lock(&ioc->tm_cmds.mutex); | |
6da999fe | 2744 | ret = mpt3sas_scsih_issue_tm(ioc, handle, lun, type, smid_task, |
c1a6c5ac | 2745 | msix_task, timeout, tr_method); |
96902835 CO |
2746 | mutex_unlock(&ioc->tm_cmds.mutex); |
2747 | ||
2748 | return ret; | |
f92363d1 SR |
2749 | } |
2750 | ||
2751 | /** | |
2752 | * _scsih_tm_display_info - displays info about the device | |
2753 | * @ioc: per adapter struct | |
2754 | * @scmd: pointer to scsi command object | |
2755 | * | |
2756 | * Called by task management callback handlers. | |
2757 | */ | |
2758 | static void | |
2759 | _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd) | |
2760 | { | |
2761 | struct scsi_target *starget = scmd->device->sdev_target; | |
2762 | struct MPT3SAS_TARGET *priv_target = starget->hostdata; | |
2763 | struct _sas_device *sas_device = NULL; | |
6ce2f1d1 | 2764 | struct _pcie_device *pcie_device = NULL; |
f92363d1 SR |
2765 | unsigned long flags; |
2766 | char *device_str = NULL; | |
2767 | ||
2768 | if (!priv_target) | |
2769 | return; | |
7786ab6a SR |
2770 | if (ioc->hide_ir_msg) |
2771 | device_str = "WarpDrive"; | |
2772 | else | |
2773 | device_str = "volume"; | |
f92363d1 SR |
2774 | |
2775 | scsi_print_command(scmd); | |
2776 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { | |
2777 | starget_printk(KERN_INFO, starget, | |
2778 | "%s handle(0x%04x), %s wwid(0x%016llx)\n", | |
2779 | device_str, priv_target->handle, | |
2780 | device_str, (unsigned long long)priv_target->sas_address); | |
6ce2f1d1 SPS |
2781 | |
2782 | } else if (priv_target->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) { | |
2783 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
2784 | pcie_device = __mpt3sas_get_pdev_from_target(ioc, priv_target); | |
2785 | if (pcie_device) { | |
2786 | starget_printk(KERN_INFO, starget, | |
2787 | "handle(0x%04x), wwid(0x%016llx), port(%d)\n", | |
2788 | pcie_device->handle, | |
2789 | (unsigned long long)pcie_device->wwid, | |
2790 | pcie_device->port_num); | |
2791 | if (pcie_device->enclosure_handle != 0) | |
2792 | starget_printk(KERN_INFO, starget, | |
2793 | "enclosure logical id(0x%016llx), slot(%d)\n", | |
2794 | (unsigned long long) | |
2795 | pcie_device->enclosure_logical_id, | |
2796 | pcie_device->slot); | |
2797 | if (pcie_device->connector_name[0] != '\0') | |
2798 | starget_printk(KERN_INFO, starget, | |
2799 | "enclosure level(0x%04x), connector name( %s)\n", | |
2800 | pcie_device->enclosure_level, | |
2801 | pcie_device->connector_name); | |
2802 | pcie_device_put(pcie_device); | |
2803 | } | |
2804 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
2805 | ||
f92363d1 SR |
2806 | } else { |
2807 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 | 2808 | sas_device = __mpt3sas_get_sdev_from_target(ioc, priv_target); |
f92363d1 SR |
2809 | if (sas_device) { |
2810 | if (priv_target->flags & | |
2811 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
2812 | starget_printk(KERN_INFO, starget, | |
2813 | "volume handle(0x%04x), " | |
2814 | "volume wwid(0x%016llx)\n", | |
2815 | sas_device->volume_handle, | |
2816 | (unsigned long long)sas_device->volume_wwid); | |
2817 | } | |
2818 | starget_printk(KERN_INFO, starget, | |
2819 | "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n", | |
2820 | sas_device->handle, | |
2821 | (unsigned long long)sas_device->sas_address, | |
2822 | sas_device->phy); | |
75888956 SR |
2823 | |
2824 | _scsih_display_enclosure_chassis_info(NULL, sas_device, | |
2825 | NULL, starget); | |
d1cb5e49 SR |
2826 | |
2827 | sas_device_put(sas_device); | |
f92363d1 SR |
2828 | } |
2829 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
2830 | } | |
2831 | } | |
2832 | ||
2833 | /** | |
8a7e4c24 | 2834 | * scsih_abort - eh threads main abort routine |
f92363d1 SR |
2835 | * @scmd: pointer to scsi command object |
2836 | * | |
4beb4867 | 2837 | * Return: SUCCESS if command aborted else FAILED |
f92363d1 | 2838 | */ |
8bbb1cf6 | 2839 | static int |
8a7e4c24 | 2840 | scsih_abort(struct scsi_cmnd *scmd) |
f92363d1 SR |
2841 | { |
2842 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
2843 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
dbec4c90 | 2844 | struct scsiio_tracker *st = scsi_cmd_priv(scmd); |
f92363d1 SR |
2845 | u16 handle; |
2846 | int r; | |
2847 | ||
c1a6c5ac C |
2848 | u8 timeout = 30; |
2849 | struct _pcie_device *pcie_device = NULL; | |
f92363d1 SR |
2850 | sdev_printk(KERN_INFO, scmd->device, |
2851 | "attempting task abort! scmd(%p)\n", scmd); | |
2852 | _scsih_tm_display_info(ioc, scmd); | |
2853 | ||
2854 | sas_device_priv_data = scmd->device->hostdata; | |
9ff549ff MFO |
2855 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target || |
2856 | ioc->remove_host) { | |
f92363d1 SR |
2857 | sdev_printk(KERN_INFO, scmd->device, |
2858 | "device been deleted! scmd(%p)\n", scmd); | |
2859 | scmd->result = DID_NO_CONNECT << 16; | |
2860 | scmd->scsi_done(scmd); | |
2861 | r = SUCCESS; | |
2862 | goto out; | |
2863 | } | |
2864 | ||
dbec4c90 SPS |
2865 | /* check for completed command */ |
2866 | if (st == NULL || st->cb_idx == 0xFF) { | |
f92363d1 SR |
2867 | scmd->result = DID_RESET << 16; |
2868 | r = SUCCESS; | |
2869 | goto out; | |
2870 | } | |
2871 | ||
2872 | /* for hidden raid components and volumes this is not supported */ | |
2873 | if (sas_device_priv_data->sas_target->flags & | |
2874 | MPT_TARGET_FLAGS_RAID_COMPONENT || | |
2875 | sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) { | |
2876 | scmd->result = DID_RESET << 16; | |
2877 | r = FAILED; | |
2878 | goto out; | |
2879 | } | |
2880 | ||
2881 | mpt3sas_halt_firmware(ioc); | |
2882 | ||
2883 | handle = sas_device_priv_data->sas_target->handle; | |
c1a6c5ac | 2884 | pcie_device = mpt3sas_get_pdev_by_handle(ioc, handle); |
5bb309db SP |
2885 | if (pcie_device && (!ioc->tm_custom_handling) && |
2886 | (!(mpt3sas_scsih_is_pcie_scsi_device(pcie_device->device_info)))) | |
c1a6c5ac | 2887 | timeout = ioc->nvme_abort_timeout; |
6da999fe HR |
2888 | r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->lun, |
2889 | MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, | |
c1a6c5ac | 2890 | st->smid, st->msix_io, timeout, 0); |
6da999fe | 2891 | /* Command must be cleared after abort */ |
dbec4c90 | 2892 | if (r == SUCCESS && st->cb_idx != 0xFF) |
6da999fe | 2893 | r = FAILED; |
f92363d1 SR |
2894 | out: |
2895 | sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n", | |
2896 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
c1a6c5ac C |
2897 | if (pcie_device) |
2898 | pcie_device_put(pcie_device); | |
f92363d1 SR |
2899 | return r; |
2900 | } | |
2901 | ||
2902 | /** | |
8a7e4c24 | 2903 | * scsih_dev_reset - eh threads main device reset routine |
f92363d1 SR |
2904 | * @scmd: pointer to scsi command object |
2905 | * | |
4beb4867 | 2906 | * Return: SUCCESS if command aborted else FAILED |
f92363d1 | 2907 | */ |
8bbb1cf6 | 2908 | static int |
8a7e4c24 | 2909 | scsih_dev_reset(struct scsi_cmnd *scmd) |
f92363d1 SR |
2910 | { |
2911 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
2912 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
d1cb5e49 | 2913 | struct _sas_device *sas_device = NULL; |
c1a6c5ac | 2914 | struct _pcie_device *pcie_device = NULL; |
f92363d1 | 2915 | u16 handle; |
c1a6c5ac C |
2916 | u8 tr_method = 0; |
2917 | u8 tr_timeout = 30; | |
f92363d1 SR |
2918 | int r; |
2919 | ||
d1cb5e49 SR |
2920 | struct scsi_target *starget = scmd->device->sdev_target; |
2921 | struct MPT3SAS_TARGET *target_priv_data = starget->hostdata; | |
2922 | ||
f92363d1 SR |
2923 | sdev_printk(KERN_INFO, scmd->device, |
2924 | "attempting device reset! scmd(%p)\n", scmd); | |
2925 | _scsih_tm_display_info(ioc, scmd); | |
2926 | ||
2927 | sas_device_priv_data = scmd->device->hostdata; | |
9ff549ff MFO |
2928 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target || |
2929 | ioc->remove_host) { | |
f92363d1 SR |
2930 | sdev_printk(KERN_INFO, scmd->device, |
2931 | "device been deleted! scmd(%p)\n", scmd); | |
2932 | scmd->result = DID_NO_CONNECT << 16; | |
2933 | scmd->scsi_done(scmd); | |
2934 | r = SUCCESS; | |
2935 | goto out; | |
2936 | } | |
2937 | ||
2938 | /* for hidden raid components obtain the volume_handle */ | |
2939 | handle = 0; | |
2940 | if (sas_device_priv_data->sas_target->flags & | |
2941 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
d1cb5e49 SR |
2942 | sas_device = mpt3sas_get_sdev_from_target(ioc, |
2943 | target_priv_data); | |
f92363d1 SR |
2944 | if (sas_device) |
2945 | handle = sas_device->volume_handle; | |
f92363d1 SR |
2946 | } else |
2947 | handle = sas_device_priv_data->sas_target->handle; | |
2948 | ||
2949 | if (!handle) { | |
2950 | scmd->result = DID_RESET << 16; | |
2951 | r = FAILED; | |
2952 | goto out; | |
2953 | } | |
2954 | ||
c1a6c5ac C |
2955 | pcie_device = mpt3sas_get_pdev_by_handle(ioc, handle); |
2956 | ||
5bb309db SP |
2957 | if (pcie_device && (!ioc->tm_custom_handling) && |
2958 | (!(mpt3sas_scsih_is_pcie_scsi_device(pcie_device->device_info)))) { | |
c1a6c5ac C |
2959 | tr_timeout = pcie_device->reset_timeout; |
2960 | tr_method = MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE; | |
2961 | } else | |
2962 | tr_method = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET; | |
5bb309db | 2963 | |
6da999fe | 2964 | r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->lun, |
c1a6c5ac C |
2965 | MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 0, |
2966 | tr_timeout, tr_method); | |
74fcfa53 HR |
2967 | /* Check for busy commands after reset */ |
2968 | if (r == SUCCESS && atomic_read(&scmd->device->device_busy)) | |
2969 | r = FAILED; | |
f92363d1 SR |
2970 | out: |
2971 | sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n", | |
2972 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
d1cb5e49 SR |
2973 | |
2974 | if (sas_device) | |
2975 | sas_device_put(sas_device); | |
c1a6c5ac C |
2976 | if (pcie_device) |
2977 | pcie_device_put(pcie_device); | |
d1cb5e49 | 2978 | |
f92363d1 SR |
2979 | return r; |
2980 | } | |
2981 | ||
2982 | /** | |
8a7e4c24 | 2983 | * scsih_target_reset - eh threads main target reset routine |
f92363d1 SR |
2984 | * @scmd: pointer to scsi command object |
2985 | * | |
4beb4867 | 2986 | * Return: SUCCESS if command aborted else FAILED |
f92363d1 | 2987 | */ |
8bbb1cf6 | 2988 | static int |
8a7e4c24 | 2989 | scsih_target_reset(struct scsi_cmnd *scmd) |
f92363d1 SR |
2990 | { |
2991 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
2992 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
d1cb5e49 | 2993 | struct _sas_device *sas_device = NULL; |
c1a6c5ac | 2994 | struct _pcie_device *pcie_device = NULL; |
f92363d1 | 2995 | u16 handle; |
c1a6c5ac C |
2996 | u8 tr_method = 0; |
2997 | u8 tr_timeout = 30; | |
f92363d1 SR |
2998 | int r; |
2999 | struct scsi_target *starget = scmd->device->sdev_target; | |
d1cb5e49 | 3000 | struct MPT3SAS_TARGET *target_priv_data = starget->hostdata; |
f92363d1 SR |
3001 | |
3002 | starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n", | |
3003 | scmd); | |
3004 | _scsih_tm_display_info(ioc, scmd); | |
3005 | ||
3006 | sas_device_priv_data = scmd->device->hostdata; | |
9ff549ff MFO |
3007 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target || |
3008 | ioc->remove_host) { | |
f92363d1 SR |
3009 | starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n", |
3010 | scmd); | |
3011 | scmd->result = DID_NO_CONNECT << 16; | |
3012 | scmd->scsi_done(scmd); | |
3013 | r = SUCCESS; | |
3014 | goto out; | |
3015 | } | |
3016 | ||
3017 | /* for hidden raid components obtain the volume_handle */ | |
3018 | handle = 0; | |
3019 | if (sas_device_priv_data->sas_target->flags & | |
3020 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
d1cb5e49 SR |
3021 | sas_device = mpt3sas_get_sdev_from_target(ioc, |
3022 | target_priv_data); | |
f92363d1 SR |
3023 | if (sas_device) |
3024 | handle = sas_device->volume_handle; | |
f92363d1 SR |
3025 | } else |
3026 | handle = sas_device_priv_data->sas_target->handle; | |
3027 | ||
3028 | if (!handle) { | |
3029 | scmd->result = DID_RESET << 16; | |
3030 | r = FAILED; | |
3031 | goto out; | |
3032 | } | |
3033 | ||
c1a6c5ac C |
3034 | pcie_device = mpt3sas_get_pdev_by_handle(ioc, handle); |
3035 | ||
5bb309db SP |
3036 | if (pcie_device && (!ioc->tm_custom_handling) && |
3037 | (!(mpt3sas_scsih_is_pcie_scsi_device(pcie_device->device_info)))) { | |
c1a6c5ac C |
3038 | tr_timeout = pcie_device->reset_timeout; |
3039 | tr_method = MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE; | |
3040 | } else | |
3041 | tr_method = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET; | |
6da999fe | 3042 | r = mpt3sas_scsih_issue_locked_tm(ioc, handle, 0, |
c1a6c5ac C |
3043 | MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 0, |
3044 | tr_timeout, tr_method); | |
74fcfa53 HR |
3045 | /* Check for busy commands after reset */ |
3046 | if (r == SUCCESS && atomic_read(&starget->target_busy)) | |
3047 | r = FAILED; | |
f92363d1 SR |
3048 | out: |
3049 | starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n", | |
3050 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
d1cb5e49 SR |
3051 | |
3052 | if (sas_device) | |
3053 | sas_device_put(sas_device); | |
c1a6c5ac C |
3054 | if (pcie_device) |
3055 | pcie_device_put(pcie_device); | |
f92363d1 SR |
3056 | return r; |
3057 | } | |
3058 | ||
3059 | ||
3060 | /** | |
8a7e4c24 | 3061 | * scsih_host_reset - eh threads main host reset routine |
f92363d1 SR |
3062 | * @scmd: pointer to scsi command object |
3063 | * | |
4beb4867 | 3064 | * Return: SUCCESS if command aborted else FAILED |
f92363d1 | 3065 | */ |
8bbb1cf6 | 3066 | static int |
8a7e4c24 | 3067 | scsih_host_reset(struct scsi_cmnd *scmd) |
f92363d1 SR |
3068 | { |
3069 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
3070 | int r, retval; | |
3071 | ||
919d8a3f | 3072 | ioc_info(ioc, "attempting host reset! scmd(%p)\n", scmd); |
f92363d1 SR |
3073 | scsi_print_command(scmd); |
3074 | ||
9ff549ff | 3075 | if (ioc->is_driver_loading || ioc->remove_host) { |
919d8a3f | 3076 | ioc_info(ioc, "Blocking the host reset\n"); |
ddb588be SR |
3077 | r = FAILED; |
3078 | goto out; | |
3079 | } | |
3080 | ||
98c56ad3 | 3081 | retval = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
f92363d1 | 3082 | r = (retval < 0) ? FAILED : SUCCESS; |
ddb588be | 3083 | out: |
919d8a3f JP |
3084 | ioc_info(ioc, "host reset: %s scmd(%p)\n", |
3085 | r == SUCCESS ? "SUCCESS" : "FAILED", scmd); | |
f92363d1 SR |
3086 | |
3087 | return r; | |
3088 | } | |
3089 | ||
3090 | /** | |
3091 | * _scsih_fw_event_add - insert and queue up fw_event | |
3092 | * @ioc: per adapter object | |
3093 | * @fw_event: object describing the event | |
3094 | * Context: This function will acquire ioc->fw_event_lock. | |
3095 | * | |
3096 | * This adds the firmware event object into link list, then queues it up to | |
3097 | * be processed from user context. | |
f92363d1 SR |
3098 | */ |
3099 | static void | |
3100 | _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event) | |
3101 | { | |
3102 | unsigned long flags; | |
3103 | ||
3104 | if (ioc->firmware_event_thread == NULL) | |
3105 | return; | |
3106 | ||
3107 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
146b16c8 | 3108 | fw_event_work_get(fw_event); |
f92363d1 SR |
3109 | INIT_LIST_HEAD(&fw_event->list); |
3110 | list_add_tail(&fw_event->list, &ioc->fw_event_list); | |
3111 | INIT_WORK(&fw_event->work, _firmware_event_work); | |
146b16c8 | 3112 | fw_event_work_get(fw_event); |
f92363d1 SR |
3113 | queue_work(ioc->firmware_event_thread, &fw_event->work); |
3114 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
3115 | } | |
3116 | ||
3117 | /** | |
146b16c8 | 3118 | * _scsih_fw_event_del_from_list - delete fw_event from the list |
f92363d1 SR |
3119 | * @ioc: per adapter object |
3120 | * @fw_event: object describing the event | |
3121 | * Context: This function will acquire ioc->fw_event_lock. | |
3122 | * | |
146b16c8 | 3123 | * If the fw_event is on the fw_event_list, remove it and do a put. |
f92363d1 SR |
3124 | */ |
3125 | static void | |
146b16c8 | 3126 | _scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work |
f92363d1 SR |
3127 | *fw_event) |
3128 | { | |
3129 | unsigned long flags; | |
3130 | ||
3131 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
146b16c8 SR |
3132 | if (!list_empty(&fw_event->list)) { |
3133 | list_del_init(&fw_event->list); | |
3134 | fw_event_work_put(fw_event); | |
3135 | } | |
f92363d1 SR |
3136 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
3137 | } | |
3138 | ||
3139 | ||
3140 | /** | |
3141 | * mpt3sas_send_trigger_data_event - send event for processing trigger data | |
3142 | * @ioc: per adapter object | |
3143 | * @event_data: trigger event data | |
f92363d1 SR |
3144 | */ |
3145 | void | |
3146 | mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc, | |
3147 | struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data) | |
3148 | { | |
3149 | struct fw_event_work *fw_event; | |
146b16c8 | 3150 | u16 sz; |
f92363d1 SR |
3151 | |
3152 | if (ioc->is_driver_loading) | |
3153 | return; | |
146b16c8 SR |
3154 | sz = sizeof(*event_data); |
3155 | fw_event = alloc_fw_event_work(sz); | |
f92363d1 SR |
3156 | if (!fw_event) |
3157 | return; | |
f92363d1 SR |
3158 | fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG; |
3159 | fw_event->ioc = ioc; | |
3160 | memcpy(fw_event->event_data, event_data, sizeof(*event_data)); | |
3161 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 | 3162 | fw_event_work_put(fw_event); |
f92363d1 SR |
3163 | } |
3164 | ||
3165 | /** | |
3166 | * _scsih_error_recovery_delete_devices - remove devices not responding | |
3167 | * @ioc: per adapter object | |
f92363d1 SR |
3168 | */ |
3169 | static void | |
3170 | _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc) | |
3171 | { | |
3172 | struct fw_event_work *fw_event; | |
3173 | ||
3174 | if (ioc->is_driver_loading) | |
3175 | return; | |
146b16c8 | 3176 | fw_event = alloc_fw_event_work(0); |
f92363d1 SR |
3177 | if (!fw_event) |
3178 | return; | |
3179 | fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES; | |
3180 | fw_event->ioc = ioc; | |
3181 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 | 3182 | fw_event_work_put(fw_event); |
f92363d1 SR |
3183 | } |
3184 | ||
3185 | /** | |
3186 | * mpt3sas_port_enable_complete - port enable completed (fake event) | |
3187 | * @ioc: per adapter object | |
f92363d1 SR |
3188 | */ |
3189 | void | |
3190 | mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc) | |
3191 | { | |
3192 | struct fw_event_work *fw_event; | |
3193 | ||
146b16c8 | 3194 | fw_event = alloc_fw_event_work(0); |
f92363d1 SR |
3195 | if (!fw_event) |
3196 | return; | |
3197 | fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE; | |
3198 | fw_event->ioc = ioc; | |
3199 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 SR |
3200 | fw_event_work_put(fw_event); |
3201 | } | |
3202 | ||
3203 | static struct fw_event_work *dequeue_next_fw_event(struct MPT3SAS_ADAPTER *ioc) | |
3204 | { | |
3205 | unsigned long flags; | |
3206 | struct fw_event_work *fw_event = NULL; | |
3207 | ||
3208 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
3209 | if (!list_empty(&ioc->fw_event_list)) { | |
3210 | fw_event = list_first_entry(&ioc->fw_event_list, | |
3211 | struct fw_event_work, list); | |
3212 | list_del_init(&fw_event->list); | |
3213 | } | |
3214 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
3215 | ||
3216 | return fw_event; | |
f92363d1 SR |
3217 | } |
3218 | ||
3219 | /** | |
3220 | * _scsih_fw_event_cleanup_queue - cleanup event queue | |
3221 | * @ioc: per adapter object | |
3222 | * | |
3223 | * Walk the firmware event queue, either killing timers, or waiting | |
3224 | * for outstanding events to complete | |
f92363d1 SR |
3225 | */ |
3226 | static void | |
3227 | _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc) | |
3228 | { | |
146b16c8 | 3229 | struct fw_event_work *fw_event; |
f92363d1 SR |
3230 | |
3231 | if (list_empty(&ioc->fw_event_list) || | |
3232 | !ioc->firmware_event_thread || in_interrupt()) | |
3233 | return; | |
3234 | ||
146b16c8 SR |
3235 | while ((fw_event = dequeue_next_fw_event(ioc))) { |
3236 | /* | |
3237 | * Wait on the fw_event to complete. If this returns 1, then | |
3238 | * the event was never executed, and we need a put for the | |
b8ac0cc7 | 3239 | * reference the work had on the fw_event. |
146b16c8 SR |
3240 | * |
3241 | * If it did execute, we wait for it to finish, and the put will | |
3242 | * happen from _firmware_event_work() | |
3243 | */ | |
b8ac0cc7 | 3244 | if (cancel_work_sync(&fw_event->work)) |
146b16c8 SR |
3245 | fw_event_work_put(fw_event); |
3246 | ||
3247 | fw_event_work_put(fw_event); | |
f92363d1 SR |
3248 | } |
3249 | } | |
3250 | ||
df838f92 SR |
3251 | /** |
3252 | * _scsih_internal_device_block - block the sdev device | |
3253 | * @sdev: per device object | |
3254 | * @sas_device_priv_data : per device driver private data | |
3255 | * | |
3256 | * make sure device is blocked without error, if not | |
3257 | * print an error | |
3258 | */ | |
3259 | static void | |
3260 | _scsih_internal_device_block(struct scsi_device *sdev, | |
3261 | struct MPT3SAS_DEVICE *sas_device_priv_data) | |
3262 | { | |
3263 | int r = 0; | |
3264 | ||
3265 | sdev_printk(KERN_INFO, sdev, "device_block, handle(0x%04x)\n", | |
3266 | sas_device_priv_data->sas_target->handle); | |
3267 | sas_device_priv_data->block = 1; | |
3268 | ||
551eb598 | 3269 | r = scsi_internal_device_block_nowait(sdev); |
df838f92 SR |
3270 | if (r == -EINVAL) |
3271 | sdev_printk(KERN_WARNING, sdev, | |
3272 | "device_block failed with return(%d) for handle(0x%04x)\n", | |
b2fe6be7 | 3273 | r, sas_device_priv_data->sas_target->handle); |
df838f92 SR |
3274 | } |
3275 | ||
3276 | /** | |
3277 | * _scsih_internal_device_unblock - unblock the sdev device | |
3278 | * @sdev: per device object | |
3279 | * @sas_device_priv_data : per device driver private data | |
3280 | * make sure device is unblocked without error, if not retry | |
3281 | * by blocking and then unblocking | |
3282 | */ | |
3283 | ||
3284 | static void | |
3285 | _scsih_internal_device_unblock(struct scsi_device *sdev, | |
3286 | struct MPT3SAS_DEVICE *sas_device_priv_data) | |
3287 | { | |
3288 | int r = 0; | |
3289 | ||
3290 | sdev_printk(KERN_WARNING, sdev, "device_unblock and setting to running, " | |
3291 | "handle(0x%04x)\n", sas_device_priv_data->sas_target->handle); | |
3292 | sas_device_priv_data->block = 0; | |
43f7571b | 3293 | r = scsi_internal_device_unblock_nowait(sdev, SDEV_RUNNING); |
df838f92 SR |
3294 | if (r == -EINVAL) { |
3295 | /* The device has been set to SDEV_RUNNING by SD layer during | |
3296 | * device addition but the request queue is still stopped by | |
3297 | * our earlier block call. We need to perform a block again | |
3298 | * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */ | |
3299 | ||
3300 | sdev_printk(KERN_WARNING, sdev, | |
3301 | "device_unblock failed with return(%d) for handle(0x%04x) " | |
3302 | "performing a block followed by an unblock\n", | |
b2fe6be7 | 3303 | r, sas_device_priv_data->sas_target->handle); |
df838f92 | 3304 | sas_device_priv_data->block = 1; |
551eb598 | 3305 | r = scsi_internal_device_block_nowait(sdev); |
df838f92 SR |
3306 | if (r) |
3307 | sdev_printk(KERN_WARNING, sdev, "retried device_block " | |
3308 | "failed with return(%d) for handle(0x%04x)\n", | |
b2fe6be7 | 3309 | r, sas_device_priv_data->sas_target->handle); |
df838f92 SR |
3310 | |
3311 | sas_device_priv_data->block = 0; | |
43f7571b | 3312 | r = scsi_internal_device_unblock_nowait(sdev, SDEV_RUNNING); |
df838f92 SR |
3313 | if (r) |
3314 | sdev_printk(KERN_WARNING, sdev, "retried device_unblock" | |
3315 | " failed with return(%d) for handle(0x%04x)\n", | |
b2fe6be7 | 3316 | r, sas_device_priv_data->sas_target->handle); |
df838f92 SR |
3317 | } |
3318 | } | |
3319 | ||
f92363d1 SR |
3320 | /** |
3321 | * _scsih_ublock_io_all_device - unblock every device | |
3322 | * @ioc: per adapter object | |
3323 | * | |
3324 | * change the device state from block to running | |
3325 | */ | |
3326 | static void | |
3327 | _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc) | |
3328 | { | |
3329 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
3330 | struct scsi_device *sdev; | |
3331 | ||
3332 | shost_for_each_device(sdev, ioc->shost) { | |
3333 | sas_device_priv_data = sdev->hostdata; | |
3334 | if (!sas_device_priv_data) | |
3335 | continue; | |
3336 | if (!sas_device_priv_data->block) | |
3337 | continue; | |
3338 | ||
f92363d1 SR |
3339 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, |
3340 | "device_running, handle(0x%04x)\n", | |
3341 | sas_device_priv_data->sas_target->handle)); | |
df838f92 | 3342 | _scsih_internal_device_unblock(sdev, sas_device_priv_data); |
f92363d1 SR |
3343 | } |
3344 | } | |
3345 | ||
3346 | ||
3347 | /** | |
3348 | * _scsih_ublock_io_device - prepare device to be deleted | |
3349 | * @ioc: per adapter object | |
4beb4867 | 3350 | * @sas_address: sas address |
f92363d1 SR |
3351 | * |
3352 | * unblock then put device in offline state | |
3353 | */ | |
3354 | static void | |
3355 | _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address) | |
3356 | { | |
3357 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
3358 | struct scsi_device *sdev; | |
3359 | ||
3360 | shost_for_each_device(sdev, ioc->shost) { | |
3361 | sas_device_priv_data = sdev->hostdata; | |
3362 | if (!sas_device_priv_data) | |
3363 | continue; | |
3364 | if (sas_device_priv_data->sas_target->sas_address | |
3365 | != sas_address) | |
3366 | continue; | |
df838f92 SR |
3367 | if (sas_device_priv_data->block) |
3368 | _scsih_internal_device_unblock(sdev, | |
3369 | sas_device_priv_data); | |
f92363d1 SR |
3370 | } |
3371 | } | |
3372 | ||
3373 | /** | |
3374 | * _scsih_block_io_all_device - set the device state to SDEV_BLOCK | |
3375 | * @ioc: per adapter object | |
f92363d1 | 3376 | * |
6c7abffc | 3377 | * During device pull we need to appropriately set the sdev state. |
f92363d1 SR |
3378 | */ |
3379 | static void | |
3380 | _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc) | |
3381 | { | |
3382 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
3383 | struct scsi_device *sdev; | |
3384 | ||
3385 | shost_for_each_device(sdev, ioc->shost) { | |
3386 | sas_device_priv_data = sdev->hostdata; | |
3387 | if (!sas_device_priv_data) | |
3388 | continue; | |
3389 | if (sas_device_priv_data->block) | |
3390 | continue; | |
30158dc9 SS |
3391 | if (sas_device_priv_data->ignore_delay_remove) { |
3392 | sdev_printk(KERN_INFO, sdev, | |
3393 | "%s skip device_block for SES handle(0x%04x)\n", | |
3394 | __func__, sas_device_priv_data->sas_target->handle); | |
3395 | continue; | |
3396 | } | |
df838f92 | 3397 | _scsih_internal_device_block(sdev, sas_device_priv_data); |
f92363d1 SR |
3398 | } |
3399 | } | |
3400 | ||
3401 | /** | |
3402 | * _scsih_block_io_device - set the device state to SDEV_BLOCK | |
3403 | * @ioc: per adapter object | |
3404 | * @handle: device handle | |
3405 | * | |
6c7abffc | 3406 | * During device pull we need to appropriately set the sdev state. |
f92363d1 SR |
3407 | */ |
3408 | static void | |
3409 | _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
3410 | { | |
3411 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
3412 | struct scsi_device *sdev; | |
e4bc7f5c SR |
3413 | struct _sas_device *sas_device; |
3414 | ||
d1cb5e49 | 3415 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
3416 | |
3417 | shost_for_each_device(sdev, ioc->shost) { | |
3418 | sas_device_priv_data = sdev->hostdata; | |
3419 | if (!sas_device_priv_data) | |
3420 | continue; | |
3421 | if (sas_device_priv_data->sas_target->handle != handle) | |
3422 | continue; | |
3423 | if (sas_device_priv_data->block) | |
3424 | continue; | |
4318c734 | 3425 | if (sas_device && sas_device->pend_sas_rphy_add) |
e4bc7f5c | 3426 | continue; |
30158dc9 SS |
3427 | if (sas_device_priv_data->ignore_delay_remove) { |
3428 | sdev_printk(KERN_INFO, sdev, | |
3429 | "%s skip device_block for SES handle(0x%04x)\n", | |
3430 | __func__, sas_device_priv_data->sas_target->handle); | |
3431 | continue; | |
3432 | } | |
df838f92 | 3433 | _scsih_internal_device_block(sdev, sas_device_priv_data); |
f92363d1 | 3434 | } |
d1cb5e49 | 3435 | |
4318c734 SPS |
3436 | if (sas_device) |
3437 | sas_device_put(sas_device); | |
f92363d1 SR |
3438 | } |
3439 | ||
3440 | /** | |
3441 | * _scsih_block_io_to_children_attached_to_ex | |
3442 | * @ioc: per adapter object | |
3443 | * @sas_expander: the sas_device object | |
3444 | * | |
3445 | * This routine set sdev state to SDEV_BLOCK for all devices | |
3446 | * attached to this expander. This function called when expander is | |
3447 | * pulled. | |
3448 | */ | |
3449 | static void | |
3450 | _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc, | |
3451 | struct _sas_node *sas_expander) | |
3452 | { | |
3453 | struct _sas_port *mpt3sas_port; | |
3454 | struct _sas_device *sas_device; | |
3455 | struct _sas_node *expander_sibling; | |
3456 | unsigned long flags; | |
3457 | ||
3458 | if (!sas_expander) | |
3459 | return; | |
3460 | ||
3461 | list_for_each_entry(mpt3sas_port, | |
3462 | &sas_expander->sas_port_list, port_list) { | |
3463 | if (mpt3sas_port->remote_identify.device_type == | |
3464 | SAS_END_DEVICE) { | |
3465 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 SR |
3466 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
3467 | mpt3sas_port->remote_identify.sas_address); | |
3468 | if (sas_device) { | |
f92363d1 | 3469 | set_bit(sas_device->handle, |
d1cb5e49 SR |
3470 | ioc->blocking_handles); |
3471 | sas_device_put(sas_device); | |
3472 | } | |
f92363d1 SR |
3473 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
3474 | } | |
3475 | } | |
3476 | ||
3477 | list_for_each_entry(mpt3sas_port, | |
3478 | &sas_expander->sas_port_list, port_list) { | |
3479 | ||
3480 | if (mpt3sas_port->remote_identify.device_type == | |
3481 | SAS_EDGE_EXPANDER_DEVICE || | |
3482 | mpt3sas_port->remote_identify.device_type == | |
3483 | SAS_FANOUT_EXPANDER_DEVICE) { | |
3484 | expander_sibling = | |
3485 | mpt3sas_scsih_expander_find_by_sas_address( | |
3486 | ioc, mpt3sas_port->remote_identify.sas_address); | |
3487 | _scsih_block_io_to_children_attached_to_ex(ioc, | |
3488 | expander_sibling); | |
3489 | } | |
3490 | } | |
3491 | } | |
3492 | ||
3493 | /** | |
3494 | * _scsih_block_io_to_children_attached_directly | |
3495 | * @ioc: per adapter object | |
3496 | * @event_data: topology change event data | |
3497 | * | |
3498 | * This routine set sdev state to SDEV_BLOCK for all devices | |
3499 | * direct attached during device pull. | |
3500 | */ | |
3501 | static void | |
3502 | _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc, | |
3503 | Mpi2EventDataSasTopologyChangeList_t *event_data) | |
3504 | { | |
3505 | int i; | |
3506 | u16 handle; | |
3507 | u16 reason_code; | |
f92363d1 SR |
3508 | |
3509 | for (i = 0; i < event_data->NumEntries; i++) { | |
3510 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
3511 | if (!handle) | |
3512 | continue; | |
f92363d1 SR |
3513 | reason_code = event_data->PHY[i].PhyStatus & |
3514 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
3515 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING) | |
3516 | _scsih_block_io_device(ioc, handle); | |
3517 | } | |
3518 | } | |
3519 | ||
4318c734 SPS |
3520 | /** |
3521 | * _scsih_block_io_to_pcie_children_attached_directly | |
3522 | * @ioc: per adapter object | |
3523 | * @event_data: topology change event data | |
3524 | * | |
3525 | * This routine set sdev state to SDEV_BLOCK for all devices | |
3526 | * direct attached during device pull/reconnect. | |
3527 | */ | |
3528 | static void | |
3529 | _scsih_block_io_to_pcie_children_attached_directly(struct MPT3SAS_ADAPTER *ioc, | |
3530 | Mpi26EventDataPCIeTopologyChangeList_t *event_data) | |
3531 | { | |
3532 | int i; | |
3533 | u16 handle; | |
3534 | u16 reason_code; | |
3535 | ||
3536 | for (i = 0; i < event_data->NumEntries; i++) { | |
3537 | handle = | |
3538 | le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle); | |
3539 | if (!handle) | |
3540 | continue; | |
3541 | reason_code = event_data->PortEntry[i].PortStatus; | |
3542 | if (reason_code == | |
3543 | MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING) | |
3544 | _scsih_block_io_device(ioc, handle); | |
3545 | } | |
3546 | } | |
f92363d1 SR |
3547 | /** |
3548 | * _scsih_tm_tr_send - send task management request | |
3549 | * @ioc: per adapter object | |
3550 | * @handle: device handle | |
3551 | * Context: interrupt time. | |
3552 | * | |
3553 | * This code is to initiate the device removal handshake protocol | |
3554 | * with controller firmware. This function will issue target reset | |
3555 | * using high priority request queue. It will send a sas iounit | |
3556 | * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion. | |
3557 | * | |
3558 | * This is designed to send muliple task management request at the same | |
3559 | * time to the fifo. If the fifo is full, we will append the request, | |
3560 | * and process it in a future completion. | |
3561 | */ | |
3562 | static void | |
3563 | _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
3564 | { | |
3565 | Mpi2SCSITaskManagementRequest_t *mpi_request; | |
3566 | u16 smid; | |
d1cb5e49 | 3567 | struct _sas_device *sas_device = NULL; |
6ce2f1d1 | 3568 | struct _pcie_device *pcie_device = NULL; |
f92363d1 SR |
3569 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; |
3570 | u64 sas_address = 0; | |
3571 | unsigned long flags; | |
3572 | struct _tr_list *delayed_tr; | |
3573 | u32 ioc_state; | |
c1a6c5ac | 3574 | u8 tr_method = 0; |
f92363d1 | 3575 | |
6ce2f1d1 | 3576 | if (ioc->pci_error_recovery) { |
4dc74b2e JP |
3577 | dewtprintk(ioc, |
3578 | ioc_info(ioc, "%s: host in pci error recovery: handle(0x%04x)\n", | |
3579 | __func__, handle)); | |
f92363d1 SR |
3580 | return; |
3581 | } | |
3582 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); | |
3583 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | |
4dc74b2e JP |
3584 | dewtprintk(ioc, |
3585 | ioc_info(ioc, "%s: host is not operational: handle(0x%04x)\n", | |
3586 | __func__, handle)); | |
f92363d1 SR |
3587 | return; |
3588 | } | |
3589 | ||
3590 | /* if PD, then return */ | |
3591 | if (test_bit(handle, ioc->pd_handles)) | |
3592 | return; | |
3593 | ||
c696f7b8 SPS |
3594 | clear_bit(handle, ioc->pend_os_device_add); |
3595 | ||
f92363d1 | 3596 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 3597 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
3598 | if (sas_device && sas_device->starget && |
3599 | sas_device->starget->hostdata) { | |
3600 | sas_target_priv_data = sas_device->starget->hostdata; | |
3601 | sas_target_priv_data->deleted = 1; | |
3602 | sas_address = sas_device->sas_address; | |
3603 | } | |
3604 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
6ce2f1d1 SPS |
3605 | if (!sas_device) { |
3606 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
3607 | pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle); | |
3608 | if (pcie_device && pcie_device->starget && | |
3609 | pcie_device->starget->hostdata) { | |
3610 | sas_target_priv_data = pcie_device->starget->hostdata; | |
3611 | sas_target_priv_data->deleted = 1; | |
3612 | sas_address = pcie_device->wwid; | |
3613 | } | |
3614 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
5bb309db SP |
3615 | if (pcie_device && (!ioc->tm_custom_handling) && |
3616 | (!(mpt3sas_scsih_is_pcie_scsi_device( | |
3617 | pcie_device->device_info)))) | |
c1a6c5ac C |
3618 | tr_method = |
3619 | MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE; | |
3620 | else | |
3621 | tr_method = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET; | |
6ce2f1d1 | 3622 | } |
f92363d1 | 3623 | if (sas_target_priv_data) { |
919d8a3f JP |
3624 | dewtprintk(ioc, |
3625 | ioc_info(ioc, "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n", | |
3626 | handle, (u64)sas_address)); | |
6ce2f1d1 SPS |
3627 | if (sas_device) { |
3628 | if (sas_device->enclosure_handle != 0) | |
919d8a3f JP |
3629 | dewtprintk(ioc, |
3630 | ioc_info(ioc, "setting delete flag:enclosure logical id(0x%016llx), slot(%d)\n", | |
3631 | (u64)sas_device->enclosure_logical_id, | |
3632 | sas_device->slot)); | |
6ce2f1d1 | 3633 | if (sas_device->connector_name[0] != '\0') |
919d8a3f JP |
3634 | dewtprintk(ioc, |
3635 | ioc_info(ioc, "setting delete flag: enclosure level(0x%04x), connector name( %s)\n", | |
3636 | sas_device->enclosure_level, | |
3637 | sas_device->connector_name)); | |
6ce2f1d1 SPS |
3638 | } else if (pcie_device) { |
3639 | if (pcie_device->enclosure_handle != 0) | |
919d8a3f JP |
3640 | dewtprintk(ioc, |
3641 | ioc_info(ioc, "setting delete flag: logical id(0x%016llx), slot(%d)\n", | |
3642 | (u64)pcie_device->enclosure_logical_id, | |
3643 | pcie_device->slot)); | |
6ce2f1d1 | 3644 | if (pcie_device->connector_name[0] != '\0') |
919d8a3f JP |
3645 | dewtprintk(ioc, |
3646 | ioc_info(ioc, "setting delete flag:, enclosure level(0x%04x), connector name( %s)\n", | |
3647 | pcie_device->enclosure_level, | |
3648 | pcie_device->connector_name)); | |
6ce2f1d1 | 3649 | } |
f92363d1 SR |
3650 | _scsih_ublock_io_device(ioc, sas_address); |
3651 | sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE; | |
3652 | } | |
3653 | ||
3654 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx); | |
3655 | if (!smid) { | |
3656 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | |
3657 | if (!delayed_tr) | |
d1cb5e49 | 3658 | goto out; |
f92363d1 SR |
3659 | INIT_LIST_HEAD(&delayed_tr->list); |
3660 | delayed_tr->handle = handle; | |
3661 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); | |
919d8a3f JP |
3662 | dewtprintk(ioc, |
3663 | ioc_info(ioc, "DELAYED:tr:handle(0x%04x), (open)\n", | |
3664 | handle)); | |
d1cb5e49 | 3665 | goto out; |
f92363d1 SR |
3666 | } |
3667 | ||
919d8a3f JP |
3668 | dewtprintk(ioc, |
3669 | ioc_info(ioc, "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
3670 | handle, smid, ioc->tm_tr_cb_idx)); | |
f92363d1 SR |
3671 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
3672 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | |
3673 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | |
3674 | mpi_request->DevHandle = cpu_to_le16(handle); | |
3675 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; | |
c1a6c5ac | 3676 | mpi_request->MsgFlags = tr_method; |
c696f7b8 | 3677 | set_bit(handle, ioc->device_remove_in_progress); |
078a4cc1 | 3678 | ioc->put_smid_hi_priority(ioc, smid, 0); |
f92363d1 | 3679 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL); |
d1cb5e49 SR |
3680 | |
3681 | out: | |
3682 | if (sas_device) | |
3683 | sas_device_put(sas_device); | |
6ce2f1d1 SPS |
3684 | if (pcie_device) |
3685 | pcie_device_put(pcie_device); | |
f92363d1 SR |
3686 | } |
3687 | ||
3688 | /** | |
3689 | * _scsih_tm_tr_complete - | |
3690 | * @ioc: per adapter object | |
3691 | * @smid: system request message index | |
3692 | * @msix_index: MSIX table index supplied by the OS | |
3693 | * @reply: reply message frame(lower 32bit addr) | |
3694 | * Context: interrupt time. | |
3695 | * | |
3696 | * This is the target reset completion routine. | |
3697 | * This code is part of the code to initiate the device removal | |
3698 | * handshake protocol with controller firmware. | |
3699 | * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE) | |
3700 | * | |
4beb4867 BVA |
3701 | * Return: 1 meaning mf should be freed from _base_interrupt |
3702 | * 0 means the mf is freed from this function. | |
f92363d1 SR |
3703 | */ |
3704 | static u8 | |
3705 | _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, | |
3706 | u32 reply) | |
3707 | { | |
3708 | u16 handle; | |
3709 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; | |
3710 | Mpi2SCSITaskManagementReply_t *mpi_reply = | |
3711 | mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
3712 | Mpi2SasIoUnitControlRequest_t *mpi_request; | |
3713 | u16 smid_sas_ctrl; | |
3714 | u32 ioc_state; | |
fd0331b3 | 3715 | struct _sc_list *delayed_sc; |
f92363d1 | 3716 | |
79eb96d6 | 3717 | if (ioc->pci_error_recovery) { |
919d8a3f JP |
3718 | dewtprintk(ioc, |
3719 | ioc_info(ioc, "%s: host in pci error recovery\n", | |
3720 | __func__)); | |
f92363d1 SR |
3721 | return 1; |
3722 | } | |
3723 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); | |
3724 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | |
919d8a3f JP |
3725 | dewtprintk(ioc, |
3726 | ioc_info(ioc, "%s: host is not operational\n", | |
3727 | __func__)); | |
f92363d1 SR |
3728 | return 1; |
3729 | } | |
3730 | if (unlikely(!mpi_reply)) { | |
919d8a3f JP |
3731 | ioc_err(ioc, "mpi_reply not valid at %s:%d/%s()!\n", |
3732 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
3733 | return 1; |
3734 | } | |
3735 | mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid); | |
3736 | handle = le16_to_cpu(mpi_request_tm->DevHandle); | |
3737 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { | |
919d8a3f JP |
3738 | dewtprintk(ioc, |
3739 | ioc_err(ioc, "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n", | |
3740 | handle, | |
3741 | le16_to_cpu(mpi_reply->DevHandle), smid)); | |
f92363d1 SR |
3742 | return 0; |
3743 | } | |
3744 | ||
3745 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT); | |
919d8a3f JP |
3746 | dewtprintk(ioc, |
3747 | ioc_info(ioc, "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), loginfo(0x%08x), completed(%d)\n", | |
3748 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), | |
3749 | le32_to_cpu(mpi_reply->IOCLogInfo), | |
3750 | le32_to_cpu(mpi_reply->TerminationCount))); | |
f92363d1 SR |
3751 | |
3752 | smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx); | |
3753 | if (!smid_sas_ctrl) { | |
fd0331b3 SS |
3754 | delayed_sc = kzalloc(sizeof(*delayed_sc), GFP_ATOMIC); |
3755 | if (!delayed_sc) | |
3756 | return _scsih_check_for_pending_tm(ioc, smid); | |
3757 | INIT_LIST_HEAD(&delayed_sc->list); | |
cf6bf971 | 3758 | delayed_sc->handle = le16_to_cpu(mpi_request_tm->DevHandle); |
fd0331b3 | 3759 | list_add_tail(&delayed_sc->list, &ioc->delayed_sc_list); |
919d8a3f JP |
3760 | dewtprintk(ioc, |
3761 | ioc_info(ioc, "DELAYED:sc:handle(0x%04x), (open)\n", | |
3762 | handle)); | |
fd0331b3 | 3763 | return _scsih_check_for_pending_tm(ioc, smid); |
f92363d1 SR |
3764 | } |
3765 | ||
919d8a3f JP |
3766 | dewtprintk(ioc, |
3767 | ioc_info(ioc, "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
3768 | handle, smid_sas_ctrl, ioc->tm_sas_control_cb_idx)); | |
f92363d1 SR |
3769 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl); |
3770 | memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t)); | |
3771 | mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; | |
3772 | mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE; | |
3773 | mpi_request->DevHandle = mpi_request_tm->DevHandle; | |
078a4cc1 | 3774 | ioc->put_smid_default(ioc, smid_sas_ctrl); |
f92363d1 SR |
3775 | |
3776 | return _scsih_check_for_pending_tm(ioc, smid); | |
3777 | } | |
3778 | ||
9029a725 SP |
3779 | /** _scsih_allow_scmd_to_device - check whether scmd needs to |
3780 | * issue to IOC or not. | |
3781 | * @ioc: per adapter object | |
3782 | * @scmd: pointer to scsi command object | |
3783 | * | |
3784 | * Returns true if scmd can be issued to IOC otherwise returns false. | |
3785 | */ | |
3786 | inline bool _scsih_allow_scmd_to_device(struct MPT3SAS_ADAPTER *ioc, | |
3787 | struct scsi_cmnd *scmd) | |
3788 | { | |
3789 | ||
3790 | if (ioc->pci_error_recovery) | |
3791 | return false; | |
3792 | ||
3793 | if (ioc->hba_mpi_version_belonged == MPI2_VERSION) { | |
3794 | if (ioc->remove_host) | |
3795 | return false; | |
3796 | ||
3797 | return true; | |
3798 | } | |
3799 | ||
3800 | if (ioc->remove_host) { | |
3801 | ||
3802 | switch (scmd->cmnd[0]) { | |
3803 | case SYNCHRONIZE_CACHE: | |
3804 | case START_STOP: | |
3805 | return true; | |
3806 | default: | |
3807 | return false; | |
3808 | } | |
3809 | } | |
3810 | ||
3811 | return true; | |
3812 | } | |
f92363d1 SR |
3813 | |
3814 | /** | |
3815 | * _scsih_sas_control_complete - completion routine | |
3816 | * @ioc: per adapter object | |
3817 | * @smid: system request message index | |
3818 | * @msix_index: MSIX table index supplied by the OS | |
3819 | * @reply: reply message frame(lower 32bit addr) | |
3820 | * Context: interrupt time. | |
3821 | * | |
3822 | * This is the sas iounit control completion routine. | |
3823 | * This code is part of the code to initiate the device removal | |
3824 | * handshake protocol with controller firmware. | |
3825 | * | |
4beb4867 BVA |
3826 | * Return: 1 meaning mf should be freed from _base_interrupt |
3827 | * 0 means the mf is freed from this function. | |
f92363d1 SR |
3828 | */ |
3829 | static u8 | |
3830 | _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, | |
3831 | u8 msix_index, u32 reply) | |
3832 | { | |
3833 | Mpi2SasIoUnitControlReply_t *mpi_reply = | |
3834 | mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
3835 | ||
3836 | if (likely(mpi_reply)) { | |
919d8a3f JP |
3837 | dewtprintk(ioc, |
3838 | ioc_info(ioc, "sc_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n", | |
3839 | le16_to_cpu(mpi_reply->DevHandle), smid, | |
3840 | le16_to_cpu(mpi_reply->IOCStatus), | |
3841 | le32_to_cpu(mpi_reply->IOCLogInfo))); | |
c696f7b8 SPS |
3842 | if (le16_to_cpu(mpi_reply->IOCStatus) == |
3843 | MPI2_IOCSTATUS_SUCCESS) { | |
3844 | clear_bit(le16_to_cpu(mpi_reply->DevHandle), | |
3845 | ioc->device_remove_in_progress); | |
3846 | } | |
f92363d1 | 3847 | } else { |
919d8a3f JP |
3848 | ioc_err(ioc, "mpi_reply not valid at %s:%d/%s()!\n", |
3849 | __FILE__, __LINE__, __func__); | |
f92363d1 | 3850 | } |
fd0331b3 | 3851 | return mpt3sas_check_for_pending_internal_cmds(ioc, smid); |
f92363d1 SR |
3852 | } |
3853 | ||
3854 | /** | |
3855 | * _scsih_tm_tr_volume_send - send target reset request for volumes | |
3856 | * @ioc: per adapter object | |
3857 | * @handle: device handle | |
3858 | * Context: interrupt time. | |
3859 | * | |
3860 | * This is designed to send muliple task management request at the same | |
3861 | * time to the fifo. If the fifo is full, we will append the request, | |
3862 | * and process it in a future completion. | |
3863 | */ | |
3864 | static void | |
3865 | _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
3866 | { | |
3867 | Mpi2SCSITaskManagementRequest_t *mpi_request; | |
3868 | u16 smid; | |
3869 | struct _tr_list *delayed_tr; | |
3870 | ||
79eb96d6 | 3871 | if (ioc->pci_error_recovery) { |
4dc74b2e JP |
3872 | dewtprintk(ioc, |
3873 | ioc_info(ioc, "%s: host reset in progress!\n", | |
3874 | __func__)); | |
f92363d1 SR |
3875 | return; |
3876 | } | |
3877 | ||
3878 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx); | |
3879 | if (!smid) { | |
3880 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | |
3881 | if (!delayed_tr) | |
3882 | return; | |
3883 | INIT_LIST_HEAD(&delayed_tr->list); | |
3884 | delayed_tr->handle = handle; | |
3885 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list); | |
919d8a3f JP |
3886 | dewtprintk(ioc, |
3887 | ioc_info(ioc, "DELAYED:tr:handle(0x%04x), (open)\n", | |
3888 | handle)); | |
f92363d1 SR |
3889 | return; |
3890 | } | |
3891 | ||
919d8a3f JP |
3892 | dewtprintk(ioc, |
3893 | ioc_info(ioc, "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
3894 | handle, smid, ioc->tm_tr_volume_cb_idx)); | |
f92363d1 SR |
3895 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
3896 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | |
3897 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | |
3898 | mpi_request->DevHandle = cpu_to_le16(handle); | |
3899 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; | |
078a4cc1 | 3900 | ioc->put_smid_hi_priority(ioc, smid, 0); |
f92363d1 SR |
3901 | } |
3902 | ||
3903 | /** | |
3904 | * _scsih_tm_volume_tr_complete - target reset completion | |
3905 | * @ioc: per adapter object | |
3906 | * @smid: system request message index | |
3907 | * @msix_index: MSIX table index supplied by the OS | |
3908 | * @reply: reply message frame(lower 32bit addr) | |
3909 | * Context: interrupt time. | |
3910 | * | |
4beb4867 BVA |
3911 | * Return: 1 meaning mf should be freed from _base_interrupt |
3912 | * 0 means the mf is freed from this function. | |
f92363d1 SR |
3913 | */ |
3914 | static u8 | |
3915 | _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, | |
3916 | u8 msix_index, u32 reply) | |
3917 | { | |
3918 | u16 handle; | |
3919 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; | |
3920 | Mpi2SCSITaskManagementReply_t *mpi_reply = | |
3921 | mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
3922 | ||
79eb96d6 | 3923 | if (ioc->shost_recovery || ioc->pci_error_recovery) { |
4dc74b2e JP |
3924 | dewtprintk(ioc, |
3925 | ioc_info(ioc, "%s: host reset in progress!\n", | |
3926 | __func__)); | |
f92363d1 SR |
3927 | return 1; |
3928 | } | |
3929 | if (unlikely(!mpi_reply)) { | |
919d8a3f JP |
3930 | ioc_err(ioc, "mpi_reply not valid at %s:%d/%s()!\n", |
3931 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
3932 | return 1; |
3933 | } | |
3934 | ||
3935 | mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid); | |
3936 | handle = le16_to_cpu(mpi_request_tm->DevHandle); | |
3937 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { | |
919d8a3f JP |
3938 | dewtprintk(ioc, |
3939 | ioc_err(ioc, "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n", | |
3940 | handle, le16_to_cpu(mpi_reply->DevHandle), | |
3941 | smid)); | |
f92363d1 SR |
3942 | return 0; |
3943 | } | |
3944 | ||
919d8a3f JP |
3945 | dewtprintk(ioc, |
3946 | ioc_info(ioc, "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), loginfo(0x%08x), completed(%d)\n", | |
3947 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), | |
3948 | le32_to_cpu(mpi_reply->IOCLogInfo), | |
3949 | le32_to_cpu(mpi_reply->TerminationCount))); | |
f92363d1 SR |
3950 | |
3951 | return _scsih_check_for_pending_tm(ioc, smid); | |
3952 | } | |
3953 | ||
fd0331b3 SS |
3954 | /** |
3955 | * _scsih_issue_delayed_event_ack - issue delayed Event ACK messages | |
3956 | * @ioc: per adapter object | |
3957 | * @smid: system request message index | |
3958 | * @event: Event ID | |
3959 | * @event_context: used to track events uniquely | |
3960 | * | |
3961 | * Context - processed in interrupt context. | |
3962 | */ | |
8bbb1cf6 | 3963 | static void |
cf6bf971 C |
3964 | _scsih_issue_delayed_event_ack(struct MPT3SAS_ADAPTER *ioc, u16 smid, U16 event, |
3965 | U32 event_context) | |
fd0331b3 SS |
3966 | { |
3967 | Mpi2EventAckRequest_t *ack_request; | |
3968 | int i = smid - ioc->internal_smid; | |
3969 | unsigned long flags; | |
3970 | ||
3971 | /* Without releasing the smid just update the | |
3972 | * call back index and reuse the same smid for | |
3973 | * processing this delayed request | |
3974 | */ | |
3975 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
3976 | ioc->internal_lookup[i].cb_idx = ioc->base_cb_idx; | |
3977 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
3978 | ||
919d8a3f JP |
3979 | dewtprintk(ioc, |
3980 | ioc_info(ioc, "EVENT ACK: event(0x%04x), smid(%d), cb(%d)\n", | |
3981 | le16_to_cpu(event), smid, ioc->base_cb_idx)); | |
fd0331b3 SS |
3982 | ack_request = mpt3sas_base_get_msg_frame(ioc, smid); |
3983 | memset(ack_request, 0, sizeof(Mpi2EventAckRequest_t)); | |
3984 | ack_request->Function = MPI2_FUNCTION_EVENT_ACK; | |
3985 | ack_request->Event = event; | |
3986 | ack_request->EventContext = event_context; | |
3987 | ack_request->VF_ID = 0; /* TODO */ | |
3988 | ack_request->VP_ID = 0; | |
078a4cc1 | 3989 | ioc->put_smid_default(ioc, smid); |
fd0331b3 SS |
3990 | } |
3991 | ||
3992 | /** | |
3993 | * _scsih_issue_delayed_sas_io_unit_ctrl - issue delayed | |
3994 | * sas_io_unit_ctrl messages | |
3995 | * @ioc: per adapter object | |
3996 | * @smid: system request message index | |
3997 | * @handle: device handle | |
3998 | * | |
3999 | * Context - processed in interrupt context. | |
4000 | */ | |
8bbb1cf6 | 4001 | static void |
fd0331b3 SS |
4002 | _scsih_issue_delayed_sas_io_unit_ctrl(struct MPT3SAS_ADAPTER *ioc, |
4003 | u16 smid, u16 handle) | |
199fd79a BVA |
4004 | { |
4005 | Mpi2SasIoUnitControlRequest_t *mpi_request; | |
4006 | u32 ioc_state; | |
4007 | int i = smid - ioc->internal_smid; | |
4008 | unsigned long flags; | |
fd0331b3 | 4009 | |
199fd79a | 4010 | if (ioc->remove_host) { |
4dc74b2e JP |
4011 | dewtprintk(ioc, |
4012 | ioc_info(ioc, "%s: host has been removed\n", | |
4013 | __func__)); | |
199fd79a BVA |
4014 | return; |
4015 | } else if (ioc->pci_error_recovery) { | |
4dc74b2e JP |
4016 | dewtprintk(ioc, |
4017 | ioc_info(ioc, "%s: host in pci error recovery\n", | |
4018 | __func__)); | |
fd0331b3 SS |
4019 | return; |
4020 | } | |
4021 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); | |
4022 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | |
4dc74b2e JP |
4023 | dewtprintk(ioc, |
4024 | ioc_info(ioc, "%s: host is not operational\n", | |
4025 | __func__)); | |
fd0331b3 SS |
4026 | return; |
4027 | } | |
4028 | ||
4029 | /* Without releasing the smid just update the | |
4030 | * call back index and reuse the same smid for | |
4031 | * processing this delayed request | |
4032 | */ | |
4033 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
4034 | ioc->internal_lookup[i].cb_idx = ioc->tm_sas_control_cb_idx; | |
4035 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
4036 | ||
919d8a3f JP |
4037 | dewtprintk(ioc, |
4038 | ioc_info(ioc, "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
4039 | handle, smid, ioc->tm_sas_control_cb_idx)); | |
fd0331b3 SS |
4040 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
4041 | memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t)); | |
4042 | mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; | |
4043 | mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE; | |
cf6bf971 | 4044 | mpi_request->DevHandle = cpu_to_le16(handle); |
078a4cc1 | 4045 | ioc->put_smid_default(ioc, smid); |
fd0331b3 SS |
4046 | } |
4047 | ||
4048 | /** | |
4049 | * _scsih_check_for_pending_internal_cmds - check for pending internal messages | |
4050 | * @ioc: per adapter object | |
4051 | * @smid: system request message index | |
4052 | * | |
4053 | * Context: Executed in interrupt context | |
4054 | * | |
4055 | * This will check delayed internal messages list, and process the | |
4056 | * next request. | |
4057 | * | |
4beb4867 BVA |
4058 | * Return: 1 meaning mf should be freed from _base_interrupt |
4059 | * 0 means the mf is freed from this function. | |
fd0331b3 SS |
4060 | */ |
4061 | u8 | |
4062 | mpt3sas_check_for_pending_internal_cmds(struct MPT3SAS_ADAPTER *ioc, u16 smid) | |
4063 | { | |
4064 | struct _sc_list *delayed_sc; | |
4065 | struct _event_ack_list *delayed_event_ack; | |
4066 | ||
4067 | if (!list_empty(&ioc->delayed_event_ack_list)) { | |
4068 | delayed_event_ack = list_entry(ioc->delayed_event_ack_list.next, | |
4069 | struct _event_ack_list, list); | |
4070 | _scsih_issue_delayed_event_ack(ioc, smid, | |
4071 | delayed_event_ack->Event, delayed_event_ack->EventContext); | |
4072 | list_del(&delayed_event_ack->list); | |
4073 | kfree(delayed_event_ack); | |
4074 | return 0; | |
4075 | } | |
4076 | ||
4077 | if (!list_empty(&ioc->delayed_sc_list)) { | |
4078 | delayed_sc = list_entry(ioc->delayed_sc_list.next, | |
4079 | struct _sc_list, list); | |
4080 | _scsih_issue_delayed_sas_io_unit_ctrl(ioc, smid, | |
4081 | delayed_sc->handle); | |
4082 | list_del(&delayed_sc->list); | |
4083 | kfree(delayed_sc); | |
4084 | return 0; | |
4085 | } | |
4086 | return 1; | |
4087 | } | |
f92363d1 SR |
4088 | |
4089 | /** | |
4090 | * _scsih_check_for_pending_tm - check for pending task management | |
4091 | * @ioc: per adapter object | |
4092 | * @smid: system request message index | |
4093 | * | |
4094 | * This will check delayed target reset list, and feed the | |
4095 | * next reqeust. | |
4096 | * | |
4beb4867 BVA |
4097 | * Return: 1 meaning mf should be freed from _base_interrupt |
4098 | * 0 means the mf is freed from this function. | |
f92363d1 SR |
4099 | */ |
4100 | static u8 | |
4101 | _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid) | |
4102 | { | |
4103 | struct _tr_list *delayed_tr; | |
4104 | ||
4105 | if (!list_empty(&ioc->delayed_tr_volume_list)) { | |
4106 | delayed_tr = list_entry(ioc->delayed_tr_volume_list.next, | |
4107 | struct _tr_list, list); | |
4108 | mpt3sas_base_free_smid(ioc, smid); | |
4109 | _scsih_tm_tr_volume_send(ioc, delayed_tr->handle); | |
4110 | list_del(&delayed_tr->list); | |
4111 | kfree(delayed_tr); | |
4112 | return 0; | |
4113 | } | |
4114 | ||
4115 | if (!list_empty(&ioc->delayed_tr_list)) { | |
4116 | delayed_tr = list_entry(ioc->delayed_tr_list.next, | |
4117 | struct _tr_list, list); | |
4118 | mpt3sas_base_free_smid(ioc, smid); | |
4119 | _scsih_tm_tr_send(ioc, delayed_tr->handle); | |
4120 | list_del(&delayed_tr->list); | |
4121 | kfree(delayed_tr); | |
4122 | return 0; | |
4123 | } | |
4124 | ||
4125 | return 1; | |
4126 | } | |
4127 | ||
4128 | /** | |
4129 | * _scsih_check_topo_delete_events - sanity check on topo events | |
4130 | * @ioc: per adapter object | |
4131 | * @event_data: the event data payload | |
4132 | * | |
4133 | * This routine added to better handle cable breaker. | |
4134 | * | |
4135 | * This handles the case where driver receives multiple expander | |
4136 | * add and delete events in a single shot. When there is a delete event | |
4137 | * the routine will void any pending add events waiting in the event queue. | |
f92363d1 SR |
4138 | */ |
4139 | static void | |
4140 | _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc, | |
4141 | Mpi2EventDataSasTopologyChangeList_t *event_data) | |
4142 | { | |
4143 | struct fw_event_work *fw_event; | |
4144 | Mpi2EventDataSasTopologyChangeList_t *local_event_data; | |
4145 | u16 expander_handle; | |
4146 | struct _sas_node *sas_expander; | |
4147 | unsigned long flags; | |
4148 | int i, reason_code; | |
4149 | u16 handle; | |
4150 | ||
4151 | for (i = 0 ; i < event_data->NumEntries; i++) { | |
4152 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
4153 | if (!handle) | |
4154 | continue; | |
4155 | reason_code = event_data->PHY[i].PhyStatus & | |
4156 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
4157 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING) | |
4158 | _scsih_tm_tr_send(ioc, handle); | |
4159 | } | |
4160 | ||
4161 | expander_handle = le16_to_cpu(event_data->ExpanderDevHandle); | |
4162 | if (expander_handle < ioc->sas_hba.num_phys) { | |
4163 | _scsih_block_io_to_children_attached_directly(ioc, event_data); | |
4164 | return; | |
4165 | } | |
4166 | if (event_data->ExpStatus == | |
4167 | MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) { | |
4168 | /* put expander attached devices into blocking state */ | |
4169 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
4170 | sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc, | |
4171 | expander_handle); | |
4172 | _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander); | |
4173 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
4174 | do { | |
4175 | handle = find_first_bit(ioc->blocking_handles, | |
4176 | ioc->facts.MaxDevHandle); | |
4177 | if (handle < ioc->facts.MaxDevHandle) | |
4178 | _scsih_block_io_device(ioc, handle); | |
4179 | } while (test_and_clear_bit(handle, ioc->blocking_handles)); | |
4180 | } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING) | |
4181 | _scsih_block_io_to_children_attached_directly(ioc, event_data); | |
4182 | ||
4183 | if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) | |
4184 | return; | |
4185 | ||
4186 | /* mark ignore flag for pending events */ | |
4187 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
4188 | list_for_each_entry(fw_event, &ioc->fw_event_list, list) { | |
4189 | if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST || | |
4190 | fw_event->ignore) | |
4191 | continue; | |
35b62362 JL |
4192 | local_event_data = (Mpi2EventDataSasTopologyChangeList_t *) |
4193 | fw_event->event_data; | |
f92363d1 SR |
4194 | if (local_event_data->ExpStatus == |
4195 | MPI2_EVENT_SAS_TOPO_ES_ADDED || | |
4196 | local_event_data->ExpStatus == | |
4197 | MPI2_EVENT_SAS_TOPO_ES_RESPONDING) { | |
4198 | if (le16_to_cpu(local_event_data->ExpanderDevHandle) == | |
4199 | expander_handle) { | |
919d8a3f JP |
4200 | dewtprintk(ioc, |
4201 | ioc_info(ioc, "setting ignoring flag\n")); | |
f92363d1 SR |
4202 | fw_event->ignore = 1; |
4203 | } | |
4204 | } | |
4205 | } | |
4206 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
4207 | } | |
4208 | ||
4318c734 SPS |
4209 | /** |
4210 | * _scsih_check_pcie_topo_remove_events - sanity check on topo | |
4211 | * events | |
4212 | * @ioc: per adapter object | |
4213 | * @event_data: the event data payload | |
4214 | * | |
4215 | * This handles the case where driver receives multiple switch | |
4216 | * or device add and delete events in a single shot. When there | |
4217 | * is a delete event the routine will void any pending add | |
4218 | * events waiting in the event queue. | |
4318c734 SPS |
4219 | */ |
4220 | static void | |
4221 | _scsih_check_pcie_topo_remove_events(struct MPT3SAS_ADAPTER *ioc, | |
4222 | Mpi26EventDataPCIeTopologyChangeList_t *event_data) | |
4223 | { | |
4224 | struct fw_event_work *fw_event; | |
4225 | Mpi26EventDataPCIeTopologyChangeList_t *local_event_data; | |
4226 | unsigned long flags; | |
4227 | int i, reason_code; | |
4228 | u16 handle, switch_handle; | |
4229 | ||
4230 | for (i = 0; i < event_data->NumEntries; i++) { | |
4231 | handle = | |
4232 | le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle); | |
4233 | if (!handle) | |
4234 | continue; | |
4235 | reason_code = event_data->PortEntry[i].PortStatus; | |
4236 | if (reason_code == MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING) | |
4237 | _scsih_tm_tr_send(ioc, handle); | |
4238 | } | |
4239 | ||
4240 | switch_handle = le16_to_cpu(event_data->SwitchDevHandle); | |
4241 | if (!switch_handle) { | |
4242 | _scsih_block_io_to_pcie_children_attached_directly( | |
4243 | ioc, event_data); | |
4244 | return; | |
4245 | } | |
4246 | /* TODO We are not supporting cascaded PCIe Switch removal yet*/ | |
4247 | if ((event_data->SwitchStatus | |
4248 | == MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING) || | |
4249 | (event_data->SwitchStatus == | |
4250 | MPI26_EVENT_PCIE_TOPO_SS_RESPONDING)) | |
4251 | _scsih_block_io_to_pcie_children_attached_directly( | |
4252 | ioc, event_data); | |
4253 | ||
4254 | if (event_data->SwitchStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) | |
4255 | return; | |
4256 | ||
4257 | /* mark ignore flag for pending events */ | |
4258 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
4259 | list_for_each_entry(fw_event, &ioc->fw_event_list, list) { | |
4260 | if (fw_event->event != MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST || | |
4261 | fw_event->ignore) | |
4262 | continue; | |
4263 | local_event_data = | |
4264 | (Mpi26EventDataPCIeTopologyChangeList_t *) | |
4265 | fw_event->event_data; | |
4266 | if (local_event_data->SwitchStatus == | |
4267 | MPI2_EVENT_SAS_TOPO_ES_ADDED || | |
4268 | local_event_data->SwitchStatus == | |
4269 | MPI2_EVENT_SAS_TOPO_ES_RESPONDING) { | |
4270 | if (le16_to_cpu(local_event_data->SwitchDevHandle) == | |
4271 | switch_handle) { | |
919d8a3f JP |
4272 | dewtprintk(ioc, |
4273 | ioc_info(ioc, "setting ignoring flag for switch event\n")); | |
4318c734 SPS |
4274 | fw_event->ignore = 1; |
4275 | } | |
4276 | } | |
4277 | } | |
4278 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
4279 | } | |
4280 | ||
f92363d1 SR |
4281 | /** |
4282 | * _scsih_set_volume_delete_flag - setting volume delete flag | |
4283 | * @ioc: per adapter object | |
4284 | * @handle: device handle | |
4285 | * | |
4286 | * This returns nothing. | |
4287 | */ | |
4288 | static void | |
4289 | _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
4290 | { | |
4291 | struct _raid_device *raid_device; | |
4292 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
4293 | unsigned long flags; | |
4294 | ||
4295 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
c84b06a4 | 4296 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
4297 | if (raid_device && raid_device->starget && |
4298 | raid_device->starget->hostdata) { | |
4299 | sas_target_priv_data = | |
4300 | raid_device->starget->hostdata; | |
4301 | sas_target_priv_data->deleted = 1; | |
919d8a3f JP |
4302 | dewtprintk(ioc, |
4303 | ioc_info(ioc, "setting delete flag: handle(0x%04x), wwid(0x%016llx)\n", | |
4304 | handle, (u64)raid_device->wwid)); | |
f92363d1 SR |
4305 | } |
4306 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
4307 | } | |
4308 | ||
4309 | /** | |
4310 | * _scsih_set_volume_handle_for_tr - set handle for target reset to volume | |
4311 | * @handle: input handle | |
4312 | * @a: handle for volume a | |
4313 | * @b: handle for volume b | |
4314 | * | |
4315 | * IR firmware only supports two raid volumes. The purpose of this | |
4316 | * routine is to set the volume handle in either a or b. When the given | |
4317 | * input handle is non-zero, or when a and b have not been set before. | |
4318 | */ | |
4319 | static void | |
4320 | _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b) | |
4321 | { | |
4322 | if (!handle || handle == *a || handle == *b) | |
4323 | return; | |
4324 | if (!*a) | |
4325 | *a = handle; | |
4326 | else if (!*b) | |
4327 | *b = handle; | |
4328 | } | |
4329 | ||
4330 | /** | |
4331 | * _scsih_check_ir_config_unhide_events - check for UNHIDE events | |
4332 | * @ioc: per adapter object | |
4333 | * @event_data: the event data payload | |
4334 | * Context: interrupt time. | |
4335 | * | |
4336 | * This routine will send target reset to volume, followed by target | |
4337 | * resets to the PDs. This is called when a PD has been removed, or | |
4338 | * volume has been deleted or removed. When the target reset is sent | |
4339 | * to volume, the PD target resets need to be queued to start upon | |
4340 | * completion of the volume target reset. | |
f92363d1 SR |
4341 | */ |
4342 | static void | |
4343 | _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc, | |
4344 | Mpi2EventDataIrConfigChangeList_t *event_data) | |
4345 | { | |
4346 | Mpi2EventIrConfigElement_t *element; | |
4347 | int i; | |
4348 | u16 handle, volume_handle, a, b; | |
4349 | struct _tr_list *delayed_tr; | |
4350 | ||
4351 | a = 0; | |
4352 | b = 0; | |
4353 | ||
7786ab6a SR |
4354 | if (ioc->is_warpdrive) |
4355 | return; | |
4356 | ||
f92363d1 SR |
4357 | /* Volume Resets for Deleted or Removed */ |
4358 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
4359 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
4360 | if (le32_to_cpu(event_data->Flags) & | |
4361 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) | |
4362 | continue; | |
4363 | if (element->ReasonCode == | |
4364 | MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED || | |
4365 | element->ReasonCode == | |
4366 | MPI2_EVENT_IR_CHANGE_RC_REMOVED) { | |
4367 | volume_handle = le16_to_cpu(element->VolDevHandle); | |
4368 | _scsih_set_volume_delete_flag(ioc, volume_handle); | |
4369 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); | |
4370 | } | |
4371 | } | |
4372 | ||
4373 | /* Volume Resets for UNHIDE events */ | |
4374 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
4375 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
4376 | if (le32_to_cpu(event_data->Flags) & | |
4377 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) | |
4378 | continue; | |
4379 | if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) { | |
4380 | volume_handle = le16_to_cpu(element->VolDevHandle); | |
4381 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); | |
4382 | } | |
4383 | } | |
4384 | ||
4385 | if (a) | |
4386 | _scsih_tm_tr_volume_send(ioc, a); | |
4387 | if (b) | |
4388 | _scsih_tm_tr_volume_send(ioc, b); | |
4389 | ||
4390 | /* PD target resets */ | |
4391 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
4392 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
4393 | if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE) | |
4394 | continue; | |
4395 | handle = le16_to_cpu(element->PhysDiskDevHandle); | |
4396 | volume_handle = le16_to_cpu(element->VolDevHandle); | |
4397 | clear_bit(handle, ioc->pd_handles); | |
4398 | if (!volume_handle) | |
4399 | _scsih_tm_tr_send(ioc, handle); | |
4400 | else if (volume_handle == a || volume_handle == b) { | |
4401 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | |
4402 | BUG_ON(!delayed_tr); | |
4403 | INIT_LIST_HEAD(&delayed_tr->list); | |
4404 | delayed_tr->handle = handle; | |
4405 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); | |
919d8a3f JP |
4406 | dewtprintk(ioc, |
4407 | ioc_info(ioc, "DELAYED:tr:handle(0x%04x), (open)\n", | |
4408 | handle)); | |
f92363d1 SR |
4409 | } else |
4410 | _scsih_tm_tr_send(ioc, handle); | |
4411 | } | |
4412 | } | |
4413 | ||
4414 | ||
4415 | /** | |
4416 | * _scsih_check_volume_delete_events - set delete flag for volumes | |
4417 | * @ioc: per adapter object | |
4418 | * @event_data: the event data payload | |
4419 | * Context: interrupt time. | |
4420 | * | |
4421 | * This will handle the case when the cable connected to entire volume is | |
4422 | * pulled. We will take care of setting the deleted flag so normal IO will | |
4423 | * not be sent. | |
f92363d1 SR |
4424 | */ |
4425 | static void | |
4426 | _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc, | |
4427 | Mpi2EventDataIrVolume_t *event_data) | |
4428 | { | |
4429 | u32 state; | |
4430 | ||
4431 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) | |
4432 | return; | |
4433 | state = le32_to_cpu(event_data->NewValue); | |
4434 | if (state == MPI2_RAID_VOL_STATE_MISSING || state == | |
4435 | MPI2_RAID_VOL_STATE_FAILED) | |
4436 | _scsih_set_volume_delete_flag(ioc, | |
4437 | le16_to_cpu(event_data->VolDevHandle)); | |
4438 | } | |
4439 | ||
2d8ce8c9 SR |
4440 | /** |
4441 | * _scsih_temp_threshold_events - display temperature threshold exceeded events | |
4442 | * @ioc: per adapter object | |
4443 | * @event_data: the temp threshold event data | |
4444 | * Context: interrupt time. | |
2d8ce8c9 SR |
4445 | */ |
4446 | static void | |
4447 | _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER *ioc, | |
4448 | Mpi2EventDataTemperature_t *event_data) | |
4449 | { | |
4450 | if (ioc->temp_sensors_count >= event_data->SensorNum) { | |
919d8a3f JP |
4451 | ioc_err(ioc, "Temperature Threshold flags %s%s%s%s exceeded for Sensor: %d !!!\n", |
4452 | le16_to_cpu(event_data->Status) & 0x1 ? "0 " : " ", | |
4453 | le16_to_cpu(event_data->Status) & 0x2 ? "1 " : " ", | |
4454 | le16_to_cpu(event_data->Status) & 0x4 ? "2 " : " ", | |
4455 | le16_to_cpu(event_data->Status) & 0x8 ? "3 " : " ", | |
4456 | event_data->SensorNum); | |
4457 | ioc_err(ioc, "Current Temp In Celsius: %d\n", | |
4458 | event_data->CurrentTemperature); | |
2d8ce8c9 SR |
4459 | } |
4460 | } | |
4461 | ||
ffb58456 | 4462 | static int _scsih_set_satl_pending(struct scsi_cmnd *scmd, bool pending) |
7ff723ad | 4463 | { |
ffb58456 JB |
4464 | struct MPT3SAS_DEVICE *priv = scmd->device->hostdata; |
4465 | ||
4466 | if (scmd->cmnd[0] != ATA_12 && scmd->cmnd[0] != ATA_16) | |
4467 | return 0; | |
4468 | ||
4469 | if (pending) | |
4470 | return test_and_set_bit(0, &priv->ata_command_pending); | |
4471 | ||
4472 | clear_bit(0, &priv->ata_command_pending); | |
4473 | return 0; | |
7ff723ad SP |
4474 | } |
4475 | ||
f92363d1 SR |
4476 | /** |
4477 | * _scsih_flush_running_cmds - completing outstanding commands. | |
4478 | * @ioc: per adapter object | |
4479 | * | |
4480 | * The flushing out of all pending scmd commands following host reset, | |
4481 | * where all IO is dropped to the floor. | |
f92363d1 SR |
4482 | */ |
4483 | static void | |
4484 | _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc) | |
4485 | { | |
4486 | struct scsi_cmnd *scmd; | |
dbec4c90 | 4487 | struct scsiio_tracker *st; |
f92363d1 | 4488 | u16 smid; |
dbec4c90 | 4489 | int count = 0; |
f92363d1 SR |
4490 | |
4491 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { | |
dbec4c90 | 4492 | scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid); |
f92363d1 SR |
4493 | if (!scmd) |
4494 | continue; | |
4495 | count++; | |
ffb58456 | 4496 | _scsih_set_satl_pending(scmd, false); |
dbec4c90 SPS |
4497 | st = scsi_cmd_priv(scmd); |
4498 | mpt3sas_base_clear_st(ioc, st); | |
f92363d1 | 4499 | scsi_dma_unmap(scmd); |
c666d3be | 4500 | if (ioc->pci_error_recovery || ioc->remove_host) |
f92363d1 SR |
4501 | scmd->result = DID_NO_CONNECT << 16; |
4502 | else | |
4503 | scmd->result = DID_RESET << 16; | |
4504 | scmd->scsi_done(scmd); | |
4505 | } | |
919d8a3f | 4506 | dtmprintk(ioc, ioc_info(ioc, "completing %d cmds\n", count)); |
f92363d1 SR |
4507 | } |
4508 | ||
4509 | /** | |
4510 | * _scsih_setup_eedp - setup MPI request for EEDP transfer | |
4511 | * @ioc: per adapter object | |
4512 | * @scmd: pointer to scsi command object | |
6c7abffc | 4513 | * @mpi_request: pointer to the SCSI_IO request message frame |
f92363d1 SR |
4514 | * |
4515 | * Supporting protection 1 and 3. | |
f92363d1 SR |
4516 | */ |
4517 | static void | |
4518 | _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, | |
016d5c35 | 4519 | Mpi25SCSIIORequest_t *mpi_request) |
f92363d1 SR |
4520 | { |
4521 | u16 eedp_flags; | |
4522 | unsigned char prot_op = scsi_get_prot_op(scmd); | |
4523 | unsigned char prot_type = scsi_get_prot_type(scmd); | |
4524 | Mpi25SCSIIORequest_t *mpi_request_3v = | |
4525 | (Mpi25SCSIIORequest_t *)mpi_request; | |
4526 | ||
4527 | if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL) | |
4528 | return; | |
4529 | ||
4530 | if (prot_op == SCSI_PROT_READ_STRIP) | |
4531 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP; | |
4532 | else if (prot_op == SCSI_PROT_WRITE_INSERT) | |
4533 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP; | |
4534 | else | |
4535 | return; | |
4536 | ||
4537 | switch (prot_type) { | |
4538 | case SCSI_PROT_DIF_TYPE1: | |
4539 | case SCSI_PROT_DIF_TYPE2: | |
4540 | ||
4541 | /* | |
4542 | * enable ref/guard checking | |
4543 | * auto increment ref tag | |
4544 | */ | |
4545 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG | | |
4546 | MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG | | |
4547 | MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; | |
4548 | mpi_request->CDB.EEDP32.PrimaryReferenceTag = | |
ddd0bc75 | 4549 | cpu_to_be32(t10_pi_ref_tag(scmd->request)); |
f92363d1 SR |
4550 | break; |
4551 | ||
4552 | case SCSI_PROT_DIF_TYPE3: | |
4553 | ||
4554 | /* | |
4555 | * enable guard checking | |
4556 | */ | |
4557 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; | |
4558 | ||
4559 | break; | |
4560 | } | |
4561 | ||
4562 | mpi_request_3v->EEDPBlockSize = | |
4563 | cpu_to_le16(scmd->device->sector_size); | |
186a18e5 SPS |
4564 | |
4565 | if (ioc->is_gen35_ioc) | |
4566 | eedp_flags |= MPI25_SCSIIO_EEDPFLAGS_APPTAG_DISABLE_MODE; | |
f92363d1 SR |
4567 | mpi_request->EEDPFlags = cpu_to_le16(eedp_flags); |
4568 | } | |
4569 | ||
4570 | /** | |
4571 | * _scsih_eedp_error_handling - return sense code for EEDP errors | |
4572 | * @scmd: pointer to scsi command object | |
4573 | * @ioc_status: ioc status | |
f92363d1 SR |
4574 | */ |
4575 | static void | |
4576 | _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status) | |
4577 | { | |
4578 | u8 ascq; | |
4579 | ||
4580 | switch (ioc_status) { | |
4581 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | |
4582 | ascq = 0x01; | |
4583 | break; | |
4584 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | |
4585 | ascq = 0x02; | |
4586 | break; | |
4587 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | |
4588 | ascq = 0x03; | |
4589 | break; | |
4590 | default: | |
4591 | ascq = 0x00; | |
4592 | break; | |
4593 | } | |
4594 | scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10, | |
4595 | ascq); | |
4596 | scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) | | |
4597 | SAM_STAT_CHECK_CONDITION; | |
4598 | } | |
4599 | ||
f92363d1 | 4600 | /** |
8a7e4c24 | 4601 | * scsih_qcmd - main scsi request entry point |
4beb4867 | 4602 | * @shost: SCSI host pointer |
f92363d1 | 4603 | * @scmd: pointer to scsi command object |
f92363d1 SR |
4604 | * |
4605 | * The callback index is set inside `ioc->scsi_io_cb_idx`. | |
4606 | * | |
4beb4867 | 4607 | * Return: 0 on success. If there's a failure, return either: |
f92363d1 SR |
4608 | * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or |
4609 | * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full | |
4610 | */ | |
8bbb1cf6 | 4611 | static int |
8a7e4c24 | 4612 | scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd) |
f92363d1 | 4613 | { |
d8bfbd8d | 4614 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
f92363d1 SR |
4615 | struct MPT3SAS_DEVICE *sas_device_priv_data; |
4616 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
7786ab6a | 4617 | struct _raid_device *raid_device; |
307d9075 AM |
4618 | struct request *rq = scmd->request; |
4619 | int class; | |
016d5c35 SPS |
4620 | Mpi25SCSIIORequest_t *mpi_request; |
4621 | struct _pcie_device *pcie_device = NULL; | |
f92363d1 SR |
4622 | u32 mpi_control; |
4623 | u16 smid; | |
4624 | u16 handle; | |
4625 | ||
f92363d1 SR |
4626 | if (ioc->logging_level & MPT_DEBUG_SCSI) |
4627 | scsi_print_command(scmd); | |
f92363d1 | 4628 | |
f92363d1 SR |
4629 | sas_device_priv_data = scmd->device->hostdata; |
4630 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | |
4631 | scmd->result = DID_NO_CONNECT << 16; | |
4632 | scmd->scsi_done(scmd); | |
4633 | return 0; | |
4634 | } | |
4635 | ||
9029a725 | 4636 | if (!(_scsih_allow_scmd_to_device(ioc, scmd))) { |
f92363d1 SR |
4637 | scmd->result = DID_NO_CONNECT << 16; |
4638 | scmd->scsi_done(scmd); | |
4639 | return 0; | |
4640 | } | |
4641 | ||
4642 | sas_target_priv_data = sas_device_priv_data->sas_target; | |
4643 | ||
4644 | /* invalid device handle */ | |
4645 | handle = sas_target_priv_data->handle; | |
4646 | if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) { | |
4647 | scmd->result = DID_NO_CONNECT << 16; | |
4648 | scmd->scsi_done(scmd); | |
4649 | return 0; | |
4650 | } | |
4651 | ||
4652 | ||
199fd79a BVA |
4653 | if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress) { |
4654 | /* host recovery or link resets sent via IOCTLs */ | |
f92363d1 | 4655 | return SCSI_MLQUEUE_HOST_BUSY; |
199fd79a BVA |
4656 | } else if (sas_target_priv_data->deleted) { |
4657 | /* device has been deleted */ | |
f92363d1 SR |
4658 | scmd->result = DID_NO_CONNECT << 16; |
4659 | scmd->scsi_done(scmd); | |
4660 | return 0; | |
f92363d1 | 4661 | } else if (sas_target_priv_data->tm_busy || |
199fd79a BVA |
4662 | sas_device_priv_data->block) { |
4663 | /* device busy with task management */ | |
f92363d1 | 4664 | return SCSI_MLQUEUE_DEVICE_BUSY; |
199fd79a | 4665 | } |
f92363d1 | 4666 | |
f49d4aed C |
4667 | /* |
4668 | * Bug work around for firmware SATL handling. The loop | |
4669 | * is based on atomic operations and ensures consistency | |
4670 | * since we're lockless at this point | |
4671 | */ | |
4672 | do { | |
4673 | if (test_bit(0, &sas_device_priv_data->ata_command_pending)) { | |
4674 | scmd->result = SAM_STAT_BUSY; | |
4675 | scmd->scsi_done(scmd); | |
4676 | return 0; | |
4677 | } | |
4678 | } while (_scsih_set_satl_pending(scmd, true)); | |
4679 | ||
f92363d1 SR |
4680 | if (scmd->sc_data_direction == DMA_FROM_DEVICE) |
4681 | mpi_control = MPI2_SCSIIO_CONTROL_READ; | |
4682 | else if (scmd->sc_data_direction == DMA_TO_DEVICE) | |
4683 | mpi_control = MPI2_SCSIIO_CONTROL_WRITE; | |
4684 | else | |
4685 | mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER; | |
4686 | ||
4687 | /* set tags */ | |
609aa22f | 4688 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; |
307d9075 AM |
4689 | /* NCQ Prio supported, make sure control indicated high priority */ |
4690 | if (sas_device_priv_data->ncq_prio_enable) { | |
4691 | class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq)); | |
4692 | if (class == IOPRIO_CLASS_RT) | |
4693 | mpi_control |= 1 << MPI2_SCSIIO_CONTROL_CMDPRI_SHIFT; | |
4694 | } | |
7786ab6a SR |
4695 | /* Make sure Device is not raid volume. |
4696 | * We do not expose raid functionality to upper layer for warpdrive. | |
4697 | */ | |
cd5897ed SPS |
4698 | if (((!ioc->is_warpdrive && !scsih_is_raid(&scmd->device->sdev_gendev)) |
4699 | && !scsih_is_nvme(&scmd->device->sdev_gendev)) | |
4700 | && sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32) | |
f92363d1 SR |
4701 | mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON; |
4702 | ||
4703 | smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd); | |
4704 | if (!smid) { | |
919d8a3f | 4705 | ioc_err(ioc, "%s: failed obtaining a smid\n", __func__); |
f49d4aed | 4706 | _scsih_set_satl_pending(scmd, false); |
f92363d1 SR |
4707 | goto out; |
4708 | } | |
4709 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
016d5c35 | 4710 | memset(mpi_request, 0, ioc->request_sz); |
f92363d1 SR |
4711 | _scsih_setup_eedp(ioc, scmd, mpi_request); |
4712 | ||
4713 | if (scmd->cmd_len == 32) | |
4714 | mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT; | |
4715 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; | |
4716 | if (sas_device_priv_data->sas_target->flags & | |
4717 | MPT_TARGET_FLAGS_RAID_COMPONENT) | |
4718 | mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH; | |
4719 | else | |
4720 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; | |
4721 | mpi_request->DevHandle = cpu_to_le16(handle); | |
4722 | mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd)); | |
4723 | mpi_request->Control = cpu_to_le32(mpi_control); | |
4724 | mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len); | |
4725 | mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR; | |
4726 | mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE; | |
4727 | mpi_request->SenseBufferLowAddress = | |
4728 | mpt3sas_base_get_sense_buffer_dma(ioc, smid); | |
016d5c35 | 4729 | mpi_request->SGLOffset0 = offsetof(Mpi25SCSIIORequest_t, SGL) / 4; |
f92363d1 SR |
4730 | int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *) |
4731 | mpi_request->LUN); | |
4732 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); | |
4733 | ||
4734 | if (mpi_request->DataLength) { | |
016d5c35 SPS |
4735 | pcie_device = sas_target_priv_data->pcie_dev; |
4736 | if (ioc->build_sg_scmd(ioc, scmd, smid, pcie_device)) { | |
f92363d1 | 4737 | mpt3sas_base_free_smid(ioc, smid); |
f49d4aed | 4738 | _scsih_set_satl_pending(scmd, false); |
f92363d1 SR |
4739 | goto out; |
4740 | } | |
4741 | } else | |
4742 | ioc->build_zero_len_sge(ioc, &mpi_request->SGL); | |
4743 | ||
7786ab6a SR |
4744 | raid_device = sas_target_priv_data->raid_device; |
4745 | if (raid_device && raid_device->direct_io_enabled) | |
cd5897ed | 4746 | mpt3sas_setup_direct_io(ioc, scmd, |
dbec4c90 | 4747 | raid_device, mpi_request); |
7786ab6a | 4748 | |
f92363d1 SR |
4749 | if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) { |
4750 | if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) { | |
4751 | mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len | | |
4752 | MPI25_SCSIIO_IOFLAGS_FAST_PATH); | |
078a4cc1 | 4753 | ioc->put_smid_fast_path(ioc, smid, handle); |
f92363d1 | 4754 | } else |
81c16f83 | 4755 | ioc->put_smid_scsi_io(ioc, smid, |
7786ab6a | 4756 | le16_to_cpu(mpi_request->DevHandle)); |
f92363d1 | 4757 | } else |
078a4cc1 | 4758 | ioc->put_smid_default(ioc, smid); |
f92363d1 SR |
4759 | return 0; |
4760 | ||
4761 | out: | |
4762 | return SCSI_MLQUEUE_HOST_BUSY; | |
4763 | } | |
f92363d1 SR |
4764 | |
4765 | /** | |
4766 | * _scsih_normalize_sense - normalize descriptor and fixed format sense data | |
4767 | * @sense_buffer: sense data returned by target | |
4768 | * @data: normalized skey/asc/ascq | |
f92363d1 SR |
4769 | */ |
4770 | static void | |
4771 | _scsih_normalize_sense(char *sense_buffer, struct sense_info *data) | |
4772 | { | |
4773 | if ((sense_buffer[0] & 0x7F) >= 0x72) { | |
4774 | /* descriptor format */ | |
4775 | data->skey = sense_buffer[1] & 0x0F; | |
4776 | data->asc = sense_buffer[2]; | |
4777 | data->ascq = sense_buffer[3]; | |
4778 | } else { | |
4779 | /* fixed format */ | |
4780 | data->skey = sense_buffer[2] & 0x0F; | |
4781 | data->asc = sense_buffer[12]; | |
4782 | data->ascq = sense_buffer[13]; | |
4783 | } | |
4784 | } | |
4785 | ||
f92363d1 SR |
4786 | /** |
4787 | * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request | |
4788 | * @ioc: per adapter object | |
4789 | * @scmd: pointer to scsi command object | |
4790 | * @mpi_reply: reply mf payload returned from firmware | |
4beb4867 | 4791 | * @smid: ? |
f92363d1 SR |
4792 | * |
4793 | * scsi_status - SCSI Status code returned from target device | |
4794 | * scsi_state - state info associated with SCSI_IO determined by ioc | |
4795 | * ioc_status - ioc supplied status info | |
f92363d1 SR |
4796 | */ |
4797 | static void | |
4798 | _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, | |
4799 | Mpi2SCSIIOReply_t *mpi_reply, u16 smid) | |
4800 | { | |
4801 | u32 response_info; | |
4802 | u8 *response_bytes; | |
4803 | u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & | |
4804 | MPI2_IOCSTATUS_MASK; | |
4805 | u8 scsi_state = mpi_reply->SCSIState; | |
4806 | u8 scsi_status = mpi_reply->SCSIStatus; | |
4807 | char *desc_ioc_state = NULL; | |
4808 | char *desc_scsi_status = NULL; | |
4809 | char *desc_scsi_state = ioc->tmp_string; | |
4810 | u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo); | |
4811 | struct _sas_device *sas_device = NULL; | |
ec051e5a | 4812 | struct _pcie_device *pcie_device = NULL; |
f92363d1 SR |
4813 | struct scsi_target *starget = scmd->device->sdev_target; |
4814 | struct MPT3SAS_TARGET *priv_target = starget->hostdata; | |
4815 | char *device_str = NULL; | |
4816 | ||
4817 | if (!priv_target) | |
4818 | return; | |
7786ab6a SR |
4819 | if (ioc->hide_ir_msg) |
4820 | device_str = "WarpDrive"; | |
4821 | else | |
4822 | device_str = "volume"; | |
f92363d1 SR |
4823 | |
4824 | if (log_info == 0x31170000) | |
4825 | return; | |
4826 | ||
4827 | switch (ioc_status) { | |
4828 | case MPI2_IOCSTATUS_SUCCESS: | |
4829 | desc_ioc_state = "success"; | |
4830 | break; | |
4831 | case MPI2_IOCSTATUS_INVALID_FUNCTION: | |
4832 | desc_ioc_state = "invalid function"; | |
4833 | break; | |
4834 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: | |
4835 | desc_ioc_state = "scsi recovered error"; | |
4836 | break; | |
4837 | case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE: | |
4838 | desc_ioc_state = "scsi invalid dev handle"; | |
4839 | break; | |
4840 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: | |
4841 | desc_ioc_state = "scsi device not there"; | |
4842 | break; | |
4843 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: | |
4844 | desc_ioc_state = "scsi data overrun"; | |
4845 | break; | |
4846 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: | |
4847 | desc_ioc_state = "scsi data underrun"; | |
4848 | break; | |
4849 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: | |
4850 | desc_ioc_state = "scsi io data error"; | |
4851 | break; | |
4852 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: | |
4853 | desc_ioc_state = "scsi protocol error"; | |
4854 | break; | |
4855 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: | |
4856 | desc_ioc_state = "scsi task terminated"; | |
4857 | break; | |
4858 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: | |
4859 | desc_ioc_state = "scsi residual mismatch"; | |
4860 | break; | |
4861 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: | |
4862 | desc_ioc_state = "scsi task mgmt failed"; | |
4863 | break; | |
4864 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: | |
4865 | desc_ioc_state = "scsi ioc terminated"; | |
4866 | break; | |
4867 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: | |
4868 | desc_ioc_state = "scsi ext terminated"; | |
4869 | break; | |
4870 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | |
4871 | desc_ioc_state = "eedp guard error"; | |
4872 | break; | |
4873 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | |
4874 | desc_ioc_state = "eedp ref tag error"; | |
4875 | break; | |
4876 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | |
4877 | desc_ioc_state = "eedp app tag error"; | |
4878 | break; | |
b130b0d5 SS |
4879 | case MPI2_IOCSTATUS_INSUFFICIENT_POWER: |
4880 | desc_ioc_state = "insufficient power"; | |
4881 | break; | |
f92363d1 SR |
4882 | default: |
4883 | desc_ioc_state = "unknown"; | |
4884 | break; | |
4885 | } | |
4886 | ||
4887 | switch (scsi_status) { | |
4888 | case MPI2_SCSI_STATUS_GOOD: | |
4889 | desc_scsi_status = "good"; | |
4890 | break; | |
4891 | case MPI2_SCSI_STATUS_CHECK_CONDITION: | |
4892 | desc_scsi_status = "check condition"; | |
4893 | break; | |
4894 | case MPI2_SCSI_STATUS_CONDITION_MET: | |
4895 | desc_scsi_status = "condition met"; | |
4896 | break; | |
4897 | case MPI2_SCSI_STATUS_BUSY: | |
4898 | desc_scsi_status = "busy"; | |
4899 | break; | |
4900 | case MPI2_SCSI_STATUS_INTERMEDIATE: | |
4901 | desc_scsi_status = "intermediate"; | |
4902 | break; | |
4903 | case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET: | |
4904 | desc_scsi_status = "intermediate condmet"; | |
4905 | break; | |
4906 | case MPI2_SCSI_STATUS_RESERVATION_CONFLICT: | |
4907 | desc_scsi_status = "reservation conflict"; | |
4908 | break; | |
4909 | case MPI2_SCSI_STATUS_COMMAND_TERMINATED: | |
4910 | desc_scsi_status = "command terminated"; | |
4911 | break; | |
4912 | case MPI2_SCSI_STATUS_TASK_SET_FULL: | |
4913 | desc_scsi_status = "task set full"; | |
4914 | break; | |
4915 | case MPI2_SCSI_STATUS_ACA_ACTIVE: | |
4916 | desc_scsi_status = "aca active"; | |
4917 | break; | |
4918 | case MPI2_SCSI_STATUS_TASK_ABORTED: | |
4919 | desc_scsi_status = "task aborted"; | |
4920 | break; | |
4921 | default: | |
4922 | desc_scsi_status = "unknown"; | |
4923 | break; | |
4924 | } | |
4925 | ||
4926 | desc_scsi_state[0] = '\0'; | |
4927 | if (!scsi_state) | |
4928 | desc_scsi_state = " "; | |
4929 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) | |
4930 | strcat(desc_scsi_state, "response info "); | |
4931 | if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | |
4932 | strcat(desc_scsi_state, "state terminated "); | |
4933 | if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS) | |
4934 | strcat(desc_scsi_state, "no status "); | |
4935 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED) | |
4936 | strcat(desc_scsi_state, "autosense failed "); | |
4937 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) | |
4938 | strcat(desc_scsi_state, "autosense valid "); | |
4939 | ||
4940 | scsi_print_command(scmd); | |
4941 | ||
4942 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { | |
919d8a3f JP |
4943 | ioc_warn(ioc, "\t%s wwid(0x%016llx)\n", |
4944 | device_str, (u64)priv_target->sas_address); | |
ec051e5a SPS |
4945 | } else if (priv_target->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) { |
4946 | pcie_device = mpt3sas_get_pdev_from_target(ioc, priv_target); | |
4947 | if (pcie_device) { | |
919d8a3f JP |
4948 | ioc_info(ioc, "\twwid(0x%016llx), port(%d)\n", |
4949 | (u64)pcie_device->wwid, pcie_device->port_num); | |
ec051e5a | 4950 | if (pcie_device->enclosure_handle != 0) |
919d8a3f JP |
4951 | ioc_info(ioc, "\tenclosure logical id(0x%016llx), slot(%d)\n", |
4952 | (u64)pcie_device->enclosure_logical_id, | |
4953 | pcie_device->slot); | |
ec051e5a | 4954 | if (pcie_device->connector_name[0]) |
919d8a3f JP |
4955 | ioc_info(ioc, "\tenclosure level(0x%04x), connector name( %s)\n", |
4956 | pcie_device->enclosure_level, | |
4957 | pcie_device->connector_name); | |
ec051e5a SPS |
4958 | pcie_device_put(pcie_device); |
4959 | } | |
f92363d1 | 4960 | } else { |
d1cb5e49 | 4961 | sas_device = mpt3sas_get_sdev_from_target(ioc, priv_target); |
f92363d1 | 4962 | if (sas_device) { |
919d8a3f JP |
4963 | ioc_warn(ioc, "\tsas_address(0x%016llx), phy(%d)\n", |
4964 | (u64)sas_device->sas_address, sas_device->phy); | |
75888956 SR |
4965 | |
4966 | _scsih_display_enclosure_chassis_info(ioc, sas_device, | |
4967 | NULL, NULL); | |
d1cb5e49 SR |
4968 | |
4969 | sas_device_put(sas_device); | |
f92363d1 | 4970 | } |
f92363d1 SR |
4971 | } |
4972 | ||
919d8a3f JP |
4973 | ioc_warn(ioc, "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n", |
4974 | le16_to_cpu(mpi_reply->DevHandle), | |
4975 | desc_ioc_state, ioc_status, smid); | |
4976 | ioc_warn(ioc, "\trequest_len(%d), underflow(%d), resid(%d)\n", | |
4977 | scsi_bufflen(scmd), scmd->underflow, scsi_get_resid(scmd)); | |
4978 | ioc_warn(ioc, "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n", | |
4979 | le16_to_cpu(mpi_reply->TaskTag), | |
4980 | le32_to_cpu(mpi_reply->TransferCount), scmd->result); | |
4981 | ioc_warn(ioc, "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n", | |
4982 | desc_scsi_status, scsi_status, desc_scsi_state, scsi_state); | |
f92363d1 SR |
4983 | |
4984 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { | |
4985 | struct sense_info data; | |
4986 | _scsih_normalize_sense(scmd->sense_buffer, &data); | |
919d8a3f JP |
4987 | ioc_warn(ioc, "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n", |
4988 | data.skey, data.asc, data.ascq, | |
4989 | le32_to_cpu(mpi_reply->SenseCount)); | |
f92363d1 | 4990 | } |
f92363d1 SR |
4991 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) { |
4992 | response_info = le32_to_cpu(mpi_reply->ResponseInfo); | |
4993 | response_bytes = (u8 *)&response_info; | |
4994 | _scsih_response_code(ioc, response_bytes[0]); | |
4995 | } | |
4996 | } | |
f92363d1 SR |
4997 | |
4998 | /** | |
0f624c39 | 4999 | * _scsih_turn_on_pfa_led - illuminate PFA LED |
f92363d1 SR |
5000 | * @ioc: per adapter object |
5001 | * @handle: device handle | |
5002 | * Context: process | |
f92363d1 SR |
5003 | */ |
5004 | static void | |
0f624c39 | 5005 | _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
f92363d1 SR |
5006 | { |
5007 | Mpi2SepReply_t mpi_reply; | |
5008 | Mpi2SepRequest_t mpi_request; | |
0f624c39 SR |
5009 | struct _sas_device *sas_device; |
5010 | ||
d1cb5e49 | 5011 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
0f624c39 SR |
5012 | if (!sas_device) |
5013 | return; | |
f92363d1 SR |
5014 | |
5015 | memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t)); | |
5016 | mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; | |
5017 | mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; | |
5018 | mpi_request.SlotStatus = | |
5019 | cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT); | |
5020 | mpi_request.DevHandle = cpu_to_le16(handle); | |
5021 | mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS; | |
5022 | if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply, | |
5023 | &mpi_request)) != 0) { | |
919d8a3f JP |
5024 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5025 | __FILE__, __LINE__, __func__); | |
d1cb5e49 | 5026 | goto out; |
f92363d1 | 5027 | } |
0f624c39 | 5028 | sas_device->pfa_led_on = 1; |
f92363d1 SR |
5029 | |
5030 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) { | |
919d8a3f JP |
5031 | dewtprintk(ioc, |
5032 | ioc_info(ioc, "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n", | |
5033 | le16_to_cpu(mpi_reply.IOCStatus), | |
5034 | le32_to_cpu(mpi_reply.IOCLogInfo))); | |
d1cb5e49 | 5035 | goto out; |
f92363d1 | 5036 | } |
d1cb5e49 SR |
5037 | out: |
5038 | sas_device_put(sas_device); | |
f92363d1 | 5039 | } |
d1cb5e49 | 5040 | |
0f624c39 SR |
5041 | /** |
5042 | * _scsih_turn_off_pfa_led - turn off Fault LED | |
5043 | * @ioc: per adapter object | |
5044 | * @sas_device: sas device whose PFA LED has to turned off | |
5045 | * Context: process | |
0f624c39 SR |
5046 | */ |
5047 | static void | |
5048 | _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc, | |
5049 | struct _sas_device *sas_device) | |
5050 | { | |
5051 | Mpi2SepReply_t mpi_reply; | |
5052 | Mpi2SepRequest_t mpi_request; | |
f92363d1 | 5053 | |
0f624c39 SR |
5054 | memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t)); |
5055 | mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; | |
5056 | mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; | |
5057 | mpi_request.SlotStatus = 0; | |
5058 | mpi_request.Slot = cpu_to_le16(sas_device->slot); | |
5059 | mpi_request.DevHandle = 0; | |
5060 | mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle); | |
5061 | mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS; | |
5062 | if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply, | |
5063 | &mpi_request)) != 0) { | |
1f95a47e JP |
5064 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5065 | __FILE__, __LINE__, __func__); | |
0f624c39 SR |
5066 | return; |
5067 | } | |
5068 | ||
5069 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) { | |
1f95a47e JP |
5070 | dewtprintk(ioc, |
5071 | ioc_info(ioc, "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n", | |
5072 | le16_to_cpu(mpi_reply.IOCStatus), | |
5073 | le32_to_cpu(mpi_reply.IOCLogInfo))); | |
0f624c39 SR |
5074 | return; |
5075 | } | |
5076 | } | |
d1cb5e49 | 5077 | |
f92363d1 | 5078 | /** |
0f624c39 | 5079 | * _scsih_send_event_to_turn_on_pfa_led - fire delayed event |
f92363d1 SR |
5080 | * @ioc: per adapter object |
5081 | * @handle: device handle | |
5082 | * Context: interrupt. | |
f92363d1 SR |
5083 | */ |
5084 | static void | |
0f624c39 | 5085 | _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
f92363d1 SR |
5086 | { |
5087 | struct fw_event_work *fw_event; | |
5088 | ||
146b16c8 | 5089 | fw_event = alloc_fw_event_work(0); |
f92363d1 SR |
5090 | if (!fw_event) |
5091 | return; | |
0f624c39 | 5092 | fw_event->event = MPT3SAS_TURN_ON_PFA_LED; |
f92363d1 SR |
5093 | fw_event->device_handle = handle; |
5094 | fw_event->ioc = ioc; | |
5095 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 | 5096 | fw_event_work_put(fw_event); |
f92363d1 SR |
5097 | } |
5098 | ||
5099 | /** | |
5100 | * _scsih_smart_predicted_fault - process smart errors | |
5101 | * @ioc: per adapter object | |
5102 | * @handle: device handle | |
5103 | * Context: interrupt. | |
f92363d1 SR |
5104 | */ |
5105 | static void | |
5106 | _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
5107 | { | |
5108 | struct scsi_target *starget; | |
5109 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
5110 | Mpi2EventNotificationReply_t *event_reply; | |
5111 | Mpi2EventDataSasDeviceStatusChange_t *event_data; | |
5112 | struct _sas_device *sas_device; | |
5113 | ssize_t sz; | |
5114 | unsigned long flags; | |
5115 | ||
5116 | /* only handle non-raid devices */ | |
5117 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 SR |
5118 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
5119 | if (!sas_device) | |
5120 | goto out_unlock; | |
5121 | ||
f92363d1 SR |
5122 | starget = sas_device->starget; |
5123 | sas_target_priv_data = starget->hostdata; | |
5124 | ||
5125 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) || | |
d1cb5e49 SR |
5126 | ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) |
5127 | goto out_unlock; | |
5128 | ||
75888956 SR |
5129 | _scsih_display_enclosure_chassis_info(NULL, sas_device, NULL, starget); |
5130 | ||
f92363d1 SR |
5131 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
5132 | ||
5133 | if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) | |
0f624c39 | 5134 | _scsih_send_event_to_turn_on_pfa_led(ioc, handle); |
f92363d1 SR |
5135 | |
5136 | /* insert into event log */ | |
5137 | sz = offsetof(Mpi2EventNotificationReply_t, EventData) + | |
5138 | sizeof(Mpi2EventDataSasDeviceStatusChange_t); | |
5139 | event_reply = kzalloc(sz, GFP_KERNEL); | |
5140 | if (!event_reply) { | |
919d8a3f JP |
5141 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5142 | __FILE__, __LINE__, __func__); | |
d1cb5e49 | 5143 | goto out; |
f92363d1 SR |
5144 | } |
5145 | ||
5146 | event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION; | |
5147 | event_reply->Event = | |
5148 | cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE); | |
5149 | event_reply->MsgLength = sz/4; | |
5150 | event_reply->EventDataLength = | |
5151 | cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4); | |
5152 | event_data = (Mpi2EventDataSasDeviceStatusChange_t *) | |
5153 | event_reply->EventData; | |
5154 | event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA; | |
5155 | event_data->ASC = 0x5D; | |
5156 | event_data->DevHandle = cpu_to_le16(handle); | |
5157 | event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address); | |
5158 | mpt3sas_ctl_add_to_event_log(ioc, event_reply); | |
5159 | kfree(event_reply); | |
d1cb5e49 SR |
5160 | out: |
5161 | if (sas_device) | |
5162 | sas_device_put(sas_device); | |
5163 | return; | |
5164 | ||
5165 | out_unlock: | |
5166 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
5167 | goto out; | |
f92363d1 SR |
5168 | } |
5169 | ||
5170 | /** | |
5171 | * _scsih_io_done - scsi request callback | |
5172 | * @ioc: per adapter object | |
5173 | * @smid: system request message index | |
5174 | * @msix_index: MSIX table index supplied by the OS | |
5175 | * @reply: reply message frame(lower 32bit addr) | |
5176 | * | |
5177 | * Callback handler when using _scsih_qcmd. | |
5178 | * | |
4beb4867 BVA |
5179 | * Return: 1 meaning mf should be freed from _base_interrupt |
5180 | * 0 means the mf is freed from this function. | |
f92363d1 SR |
5181 | */ |
5182 | static u8 | |
5183 | _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | |
5184 | { | |
016d5c35 | 5185 | Mpi25SCSIIORequest_t *mpi_request; |
f92363d1 SR |
5186 | Mpi2SCSIIOReply_t *mpi_reply; |
5187 | struct scsi_cmnd *scmd; | |
dbec4c90 | 5188 | struct scsiio_tracker *st; |
f92363d1 SR |
5189 | u16 ioc_status; |
5190 | u32 xfer_cnt; | |
5191 | u8 scsi_state; | |
5192 | u8 scsi_status; | |
5193 | u32 log_info; | |
5194 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
5195 | u32 response_code = 0; | |
5196 | ||
5197 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
459325c4 | 5198 | |
dbec4c90 | 5199 | scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid); |
f92363d1 SR |
5200 | if (scmd == NULL) |
5201 | return 1; | |
5202 | ||
ffb58456 | 5203 | _scsih_set_satl_pending(scmd, false); |
18f6084a | 5204 | |
f92363d1 SR |
5205 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
5206 | ||
5207 | if (mpi_reply == NULL) { | |
5208 | scmd->result = DID_OK << 16; | |
5209 | goto out; | |
5210 | } | |
5211 | ||
5212 | sas_device_priv_data = scmd->device->hostdata; | |
5213 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target || | |
5214 | sas_device_priv_data->sas_target->deleted) { | |
5215 | scmd->result = DID_NO_CONNECT << 16; | |
5216 | goto out; | |
5217 | } | |
5218 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); | |
5219 | ||
7786ab6a SR |
5220 | /* |
5221 | * WARPDRIVE: If direct_io is set then it is directIO, | |
5222 | * the failed direct I/O should be redirected to volume | |
5223 | */ | |
dbec4c90 SPS |
5224 | st = scsi_cmd_priv(scmd); |
5225 | if (st->direct_io && | |
7786ab6a SR |
5226 | ((ioc_status & MPI2_IOCSTATUS_MASK) |
5227 | != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) { | |
dbec4c90 | 5228 | st->direct_io = 0; |
998c3001 | 5229 | st->scmd = scmd; |
7786ab6a SR |
5230 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); |
5231 | mpi_request->DevHandle = | |
5232 | cpu_to_le16(sas_device_priv_data->sas_target->handle); | |
81c16f83 | 5233 | ioc->put_smid_scsi_io(ioc, smid, |
7786ab6a SR |
5234 | sas_device_priv_data->sas_target->handle); |
5235 | return 0; | |
5236 | } | |
f92363d1 SR |
5237 | /* turning off TLR */ |
5238 | scsi_state = mpi_reply->SCSIState; | |
5239 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) | |
5240 | response_code = | |
5241 | le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF; | |
5242 | if (!sas_device_priv_data->tlr_snoop_check) { | |
5243 | sas_device_priv_data->tlr_snoop_check++; | |
cd5897ed | 5244 | if ((!ioc->is_warpdrive && |
7786ab6a | 5245 | !scsih_is_raid(&scmd->device->sdev_gendev) && |
cd5897ed SPS |
5246 | !scsih_is_nvme(&scmd->device->sdev_gendev)) |
5247 | && sas_is_tlr_enabled(scmd->device) && | |
c84b06a4 SR |
5248 | response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) { |
5249 | sas_disable_tlr(scmd->device); | |
5250 | sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n"); | |
5251 | } | |
f92363d1 SR |
5252 | } |
5253 | ||
5254 | xfer_cnt = le32_to_cpu(mpi_reply->TransferCount); | |
5255 | scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt); | |
5256 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) | |
5257 | log_info = le32_to_cpu(mpi_reply->IOCLogInfo); | |
5258 | else | |
5259 | log_info = 0; | |
5260 | ioc_status &= MPI2_IOCSTATUS_MASK; | |
5261 | scsi_status = mpi_reply->SCSIStatus; | |
5262 | ||
5263 | if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 && | |
5264 | (scsi_status == MPI2_SCSI_STATUS_BUSY || | |
5265 | scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT || | |
5266 | scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) { | |
5267 | ioc_status = MPI2_IOCSTATUS_SUCCESS; | |
5268 | } | |
5269 | ||
5270 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { | |
5271 | struct sense_info data; | |
5272 | const void *sense_data = mpt3sas_base_get_sense_buffer(ioc, | |
5273 | smid); | |
5274 | u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE, | |
5275 | le32_to_cpu(mpi_reply->SenseCount)); | |
5276 | memcpy(scmd->sense_buffer, sense_data, sz); | |
5277 | _scsih_normalize_sense(scmd->sense_buffer, &data); | |
5278 | /* failure prediction threshold exceeded */ | |
5279 | if (data.asc == 0x5D) | |
5280 | _scsih_smart_predicted_fault(ioc, | |
5281 | le16_to_cpu(mpi_reply->DevHandle)); | |
5282 | mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq); | |
f92363d1 | 5283 | |
0d667f72 | 5284 | if ((ioc->logging_level & MPT_DEBUG_REPLY) && |
e6d45e3e SR |
5285 | ((scmd->sense_buffer[2] == UNIT_ATTENTION) || |
5286 | (scmd->sense_buffer[2] == MEDIUM_ERROR) || | |
5287 | (scmd->sense_buffer[2] == HARDWARE_ERROR))) | |
5288 | _scsih_scsi_ioc_info(ioc, scmd, mpi_reply, smid); | |
e6d45e3e | 5289 | } |
f92363d1 SR |
5290 | switch (ioc_status) { |
5291 | case MPI2_IOCSTATUS_BUSY: | |
5292 | case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES: | |
5293 | scmd->result = SAM_STAT_BUSY; | |
5294 | break; | |
5295 | ||
5296 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: | |
5297 | scmd->result = DID_NO_CONNECT << 16; | |
5298 | break; | |
5299 | ||
5300 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: | |
5301 | if (sas_device_priv_data->block) { | |
5302 | scmd->result = DID_TRANSPORT_DISRUPTED << 16; | |
5303 | goto out; | |
5304 | } | |
5305 | if (log_info == 0x31110630) { | |
5306 | if (scmd->retries > 2) { | |
5307 | scmd->result = DID_NO_CONNECT << 16; | |
5308 | scsi_device_set_state(scmd->device, | |
5309 | SDEV_OFFLINE); | |
5310 | } else { | |
5311 | scmd->result = DID_SOFT_ERROR << 16; | |
5312 | scmd->device->expecting_cc_ua = 1; | |
5313 | } | |
5314 | break; | |
3898f08e SR |
5315 | } else if (log_info == VIRTUAL_IO_FAILED_RETRY) { |
5316 | scmd->result = DID_RESET << 16; | |
5317 | break; | |
2ce9a364 SR |
5318 | } else if ((scmd->device->channel == RAID_CHANNEL) && |
5319 | (scsi_state == (MPI2_SCSI_STATE_TERMINATED | | |
5320 | MPI2_SCSI_STATE_NO_SCSI_STATUS))) { | |
5321 | scmd->result = DID_RESET << 16; | |
5322 | break; | |
f92363d1 SR |
5323 | } |
5324 | scmd->result = DID_SOFT_ERROR << 16; | |
5325 | break; | |
5326 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: | |
5327 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: | |
5328 | scmd->result = DID_RESET << 16; | |
5329 | break; | |
5330 | ||
5331 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: | |
5332 | if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt)) | |
5333 | scmd->result = DID_SOFT_ERROR << 16; | |
5334 | else | |
5335 | scmd->result = (DID_OK << 16) | scsi_status; | |
5336 | break; | |
5337 | ||
5338 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: | |
5339 | scmd->result = (DID_OK << 16) | scsi_status; | |
5340 | ||
5341 | if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)) | |
5342 | break; | |
5343 | ||
5344 | if (xfer_cnt < scmd->underflow) { | |
5345 | if (scsi_status == SAM_STAT_BUSY) | |
5346 | scmd->result = SAM_STAT_BUSY; | |
5347 | else | |
5348 | scmd->result = DID_SOFT_ERROR << 16; | |
5349 | } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | | |
5350 | MPI2_SCSI_STATE_NO_SCSI_STATUS)) | |
5351 | scmd->result = DID_SOFT_ERROR << 16; | |
5352 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | |
5353 | scmd->result = DID_RESET << 16; | |
5354 | else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) { | |
5355 | mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID; | |
5356 | mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION; | |
5357 | scmd->result = (DRIVER_SENSE << 24) | | |
5358 | SAM_STAT_CHECK_CONDITION; | |
5359 | scmd->sense_buffer[0] = 0x70; | |
5360 | scmd->sense_buffer[2] = ILLEGAL_REQUEST; | |
5361 | scmd->sense_buffer[12] = 0x20; | |
5362 | scmd->sense_buffer[13] = 0; | |
5363 | } | |
5364 | break; | |
5365 | ||
5366 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: | |
5367 | scsi_set_resid(scmd, 0); | |
eb0c7af2 | 5368 | /* fall through */ |
f92363d1 SR |
5369 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: |
5370 | case MPI2_IOCSTATUS_SUCCESS: | |
5371 | scmd->result = (DID_OK << 16) | scsi_status; | |
5372 | if (response_code == | |
5373 | MPI2_SCSITASKMGMT_RSP_INVALID_FRAME || | |
5374 | (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | | |
5375 | MPI2_SCSI_STATE_NO_SCSI_STATUS))) | |
5376 | scmd->result = DID_SOFT_ERROR << 16; | |
5377 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | |
5378 | scmd->result = DID_RESET << 16; | |
5379 | break; | |
5380 | ||
5381 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | |
5382 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | |
5383 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | |
5384 | _scsih_eedp_error_handling(scmd, ioc_status); | |
5385 | break; | |
5386 | ||
5387 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: | |
5388 | case MPI2_IOCSTATUS_INVALID_FUNCTION: | |
5389 | case MPI2_IOCSTATUS_INVALID_SGL: | |
5390 | case MPI2_IOCSTATUS_INTERNAL_ERROR: | |
5391 | case MPI2_IOCSTATUS_INVALID_FIELD: | |
5392 | case MPI2_IOCSTATUS_INVALID_STATE: | |
5393 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: | |
5394 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: | |
b130b0d5 | 5395 | case MPI2_IOCSTATUS_INSUFFICIENT_POWER: |
f92363d1 SR |
5396 | default: |
5397 | scmd->result = DID_SOFT_ERROR << 16; | |
5398 | break; | |
5399 | ||
5400 | } | |
5401 | ||
f92363d1 SR |
5402 | if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY)) |
5403 | _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid); | |
f92363d1 SR |
5404 | |
5405 | out: | |
5406 | ||
5407 | scsi_dma_unmap(scmd); | |
dbec4c90 | 5408 | mpt3sas_base_free_smid(ioc, smid); |
f92363d1 | 5409 | scmd->scsi_done(scmd); |
dbec4c90 | 5410 | return 0; |
f92363d1 SR |
5411 | } |
5412 | ||
5413 | /** | |
5414 | * _scsih_sas_host_refresh - refreshing sas host object contents | |
5415 | * @ioc: per adapter object | |
5416 | * Context: user | |
5417 | * | |
5418 | * During port enable, fw will send topology events for every device. Its | |
5419 | * possible that the handles may change from the previous setting, so this | |
5420 | * code keeping handles updating if changed. | |
f92363d1 SR |
5421 | */ |
5422 | static void | |
5423 | _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc) | |
5424 | { | |
5425 | u16 sz; | |
5426 | u16 ioc_status; | |
5427 | int i; | |
5428 | Mpi2ConfigReply_t mpi_reply; | |
5429 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; | |
5430 | u16 attached_handle; | |
5431 | u8 link_rate; | |
5432 | ||
919d8a3f JP |
5433 | dtmprintk(ioc, |
5434 | ioc_info(ioc, "updating handles for sas_host(0x%016llx)\n", | |
5435 | (u64)ioc->sas_hba.sas_address)); | |
f92363d1 SR |
5436 | |
5437 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys | |
5438 | * sizeof(Mpi2SasIOUnit0PhyData_t)); | |
5439 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); | |
5440 | if (!sas_iounit_pg0) { | |
919d8a3f JP |
5441 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5442 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5443 | return; |
5444 | } | |
5445 | ||
5446 | if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, | |
5447 | sas_iounit_pg0, sz)) != 0) | |
5448 | goto out; | |
5449 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
5450 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | |
5451 | goto out; | |
5452 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { | |
5453 | link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4; | |
5454 | if (i == 0) | |
5455 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> | |
5456 | PhyData[0].ControllerDevHandle); | |
5457 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; | |
5458 | attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i]. | |
5459 | AttachedDevHandle); | |
5460 | if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) | |
5461 | link_rate = MPI2_SAS_NEG_LINK_RATE_1_5; | |
5462 | mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address, | |
5463 | attached_handle, i, link_rate); | |
5464 | } | |
5465 | out: | |
5466 | kfree(sas_iounit_pg0); | |
5467 | } | |
5468 | ||
5469 | /** | |
5470 | * _scsih_sas_host_add - create sas host object | |
5471 | * @ioc: per adapter object | |
5472 | * | |
5473 | * Creating host side data object, stored in ioc->sas_hba | |
f92363d1 SR |
5474 | */ |
5475 | static void | |
5476 | _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc) | |
5477 | { | |
5478 | int i; | |
5479 | Mpi2ConfigReply_t mpi_reply; | |
5480 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; | |
5481 | Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; | |
5482 | Mpi2SasPhyPage0_t phy_pg0; | |
5483 | Mpi2SasDevicePage0_t sas_device_pg0; | |
5484 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
5485 | u16 ioc_status; | |
5486 | u16 sz; | |
5487 | u8 device_missing_delay; | |
87aa95d4 | 5488 | u8 num_phys; |
f92363d1 | 5489 | |
87aa95d4 JL |
5490 | mpt3sas_config_get_number_hba_phys(ioc, &num_phys); |
5491 | if (!num_phys) { | |
919d8a3f JP |
5492 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5493 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5494 | return; |
5495 | } | |
87aa95d4 JL |
5496 | ioc->sas_hba.phy = kcalloc(num_phys, |
5497 | sizeof(struct _sas_phy), GFP_KERNEL); | |
5498 | if (!ioc->sas_hba.phy) { | |
919d8a3f JP |
5499 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5500 | __FILE__, __LINE__, __func__); | |
87aa95d4 JL |
5501 | goto out; |
5502 | } | |
5503 | ioc->sas_hba.num_phys = num_phys; | |
f92363d1 SR |
5504 | |
5505 | /* sas_iounit page 0 */ | |
5506 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys * | |
5507 | sizeof(Mpi2SasIOUnit0PhyData_t)); | |
5508 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); | |
5509 | if (!sas_iounit_pg0) { | |
919d8a3f JP |
5510 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5511 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5512 | return; |
5513 | } | |
5514 | if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, | |
5515 | sas_iounit_pg0, sz))) { | |
919d8a3f JP |
5516 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5517 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5518 | goto out; |
5519 | } | |
5520 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5521 | MPI2_IOCSTATUS_MASK; | |
5522 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
919d8a3f JP |
5523 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5524 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5525 | goto out; |
5526 | } | |
5527 | ||
5528 | /* sas_iounit page 1 */ | |
5529 | sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys * | |
5530 | sizeof(Mpi2SasIOUnit1PhyData_t)); | |
5531 | sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL); | |
5532 | if (!sas_iounit_pg1) { | |
919d8a3f JP |
5533 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5534 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5535 | goto out; |
5536 | } | |
5537 | if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply, | |
5538 | sas_iounit_pg1, sz))) { | |
919d8a3f JP |
5539 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5540 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5541 | goto out; |
5542 | } | |
5543 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5544 | MPI2_IOCSTATUS_MASK; | |
5545 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
919d8a3f JP |
5546 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5547 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5548 | goto out; |
5549 | } | |
5550 | ||
5551 | ioc->io_missing_delay = | |
5552 | sas_iounit_pg1->IODeviceMissingDelay; | |
5553 | device_missing_delay = | |
5554 | sas_iounit_pg1->ReportDeviceMissingDelay; | |
5555 | if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16) | |
5556 | ioc->device_missing_delay = (device_missing_delay & | |
5557 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16; | |
5558 | else | |
5559 | ioc->device_missing_delay = device_missing_delay & | |
5560 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK; | |
5561 | ||
5562 | ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev; | |
f92363d1 SR |
5563 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { |
5564 | if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0, | |
5565 | i))) { | |
919d8a3f JP |
5566 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5567 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5568 | goto out; |
5569 | } | |
5570 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5571 | MPI2_IOCSTATUS_MASK; | |
5572 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
919d8a3f JP |
5573 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5574 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5575 | goto out; |
5576 | } | |
5577 | ||
5578 | if (i == 0) | |
5579 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> | |
5580 | PhyData[0].ControllerDevHandle); | |
5581 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; | |
5582 | ioc->sas_hba.phy[i].phy_id = i; | |
5583 | mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i], | |
5584 | phy_pg0, ioc->sas_hba.parent_dev); | |
5585 | } | |
5586 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
5587 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) { | |
919d8a3f JP |
5588 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5589 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5590 | goto out; |
5591 | } | |
5592 | ioc->sas_hba.enclosure_handle = | |
5593 | le16_to_cpu(sas_device_pg0.EnclosureHandle); | |
5594 | ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | |
919d8a3f JP |
5595 | ioc_info(ioc, "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n", |
5596 | ioc->sas_hba.handle, | |
5597 | (u64)ioc->sas_hba.sas_address, | |
5598 | ioc->sas_hba.num_phys); | |
f92363d1 SR |
5599 | |
5600 | if (ioc->sas_hba.enclosure_handle) { | |
5601 | if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
5602 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
5603 | ioc->sas_hba.enclosure_handle))) | |
5604 | ioc->sas_hba.enclosure_logical_id = | |
5605 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
5606 | } | |
5607 | ||
5608 | out: | |
5609 | kfree(sas_iounit_pg1); | |
5610 | kfree(sas_iounit_pg0); | |
5611 | } | |
5612 | ||
5613 | /** | |
5614 | * _scsih_expander_add - creating expander object | |
5615 | * @ioc: per adapter object | |
5616 | * @handle: expander handle | |
5617 | * | |
5618 | * Creating expander object, stored in ioc->sas_expander_list. | |
5619 | * | |
4beb4867 | 5620 | * Return: 0 for success, else error. |
f92363d1 SR |
5621 | */ |
5622 | static int | |
5623 | _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
5624 | { | |
5625 | struct _sas_node *sas_expander; | |
22a923c3 | 5626 | struct _enclosure_node *enclosure_dev; |
f92363d1 SR |
5627 | Mpi2ConfigReply_t mpi_reply; |
5628 | Mpi2ExpanderPage0_t expander_pg0; | |
5629 | Mpi2ExpanderPage1_t expander_pg1; | |
f92363d1 SR |
5630 | u32 ioc_status; |
5631 | u16 parent_handle; | |
5632 | u64 sas_address, sas_address_parent = 0; | |
5633 | int i; | |
5634 | unsigned long flags; | |
5635 | struct _sas_port *mpt3sas_port = NULL; | |
5636 | ||
5637 | int rc = 0; | |
5638 | ||
5639 | if (!handle) | |
5640 | return -1; | |
5641 | ||
5642 | if (ioc->shost_recovery || ioc->pci_error_recovery) | |
5643 | return -1; | |
5644 | ||
5645 | if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | |
5646 | MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) { | |
919d8a3f JP |
5647 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5648 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5649 | return -1; |
5650 | } | |
5651 | ||
5652 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5653 | MPI2_IOCSTATUS_MASK; | |
5654 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
919d8a3f JP |
5655 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5656 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5657 | return -1; |
5658 | } | |
5659 | ||
5660 | /* handle out of order topology events */ | |
5661 | parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle); | |
5662 | if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent) | |
5663 | != 0) { | |
919d8a3f JP |
5664 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5665 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5666 | return -1; |
5667 | } | |
5668 | if (sas_address_parent != ioc->sas_hba.sas_address) { | |
5669 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
5670 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, | |
5671 | sas_address_parent); | |
5672 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
5673 | if (!sas_expander) { | |
5674 | rc = _scsih_expander_add(ioc, parent_handle); | |
5675 | if (rc != 0) | |
5676 | return rc; | |
5677 | } | |
5678 | } | |
5679 | ||
5680 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
5681 | sas_address = le64_to_cpu(expander_pg0.SASAddress); | |
5682 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, | |
5683 | sas_address); | |
5684 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
5685 | ||
5686 | if (sas_expander) | |
5687 | return 0; | |
5688 | ||
5689 | sas_expander = kzalloc(sizeof(struct _sas_node), | |
5690 | GFP_KERNEL); | |
5691 | if (!sas_expander) { | |
919d8a3f JP |
5692 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5693 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5694 | return -1; |
5695 | } | |
5696 | ||
5697 | sas_expander->handle = handle; | |
5698 | sas_expander->num_phys = expander_pg0.NumPhys; | |
5699 | sas_expander->sas_address_parent = sas_address_parent; | |
5700 | sas_expander->sas_address = sas_address; | |
5701 | ||
919d8a3f JP |
5702 | ioc_info(ioc, "expander_add: handle(0x%04x), parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", |
5703 | handle, parent_handle, | |
5704 | (u64)sas_expander->sas_address, sas_expander->num_phys); | |
f92363d1 SR |
5705 | |
5706 | if (!sas_expander->num_phys) | |
5707 | goto out_fail; | |
5708 | sas_expander->phy = kcalloc(sas_expander->num_phys, | |
5709 | sizeof(struct _sas_phy), GFP_KERNEL); | |
5710 | if (!sas_expander->phy) { | |
919d8a3f JP |
5711 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5712 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5713 | rc = -1; |
5714 | goto out_fail; | |
5715 | } | |
5716 | ||
5717 | INIT_LIST_HEAD(&sas_expander->sas_port_list); | |
5718 | mpt3sas_port = mpt3sas_transport_port_add(ioc, handle, | |
5719 | sas_address_parent); | |
5720 | if (!mpt3sas_port) { | |
919d8a3f JP |
5721 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5722 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5723 | rc = -1; |
5724 | goto out_fail; | |
5725 | } | |
5726 | sas_expander->parent_dev = &mpt3sas_port->rphy->dev; | |
5727 | ||
5728 | for (i = 0 ; i < sas_expander->num_phys ; i++) { | |
5729 | if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply, | |
5730 | &expander_pg1, i, handle))) { | |
919d8a3f JP |
5731 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5732 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5733 | rc = -1; |
5734 | goto out_fail; | |
5735 | } | |
5736 | sas_expander->phy[i].handle = handle; | |
5737 | sas_expander->phy[i].phy_id = i; | |
5738 | ||
5739 | if ((mpt3sas_transport_add_expander_phy(ioc, | |
5740 | &sas_expander->phy[i], expander_pg1, | |
5741 | sas_expander->parent_dev))) { | |
919d8a3f JP |
5742 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
5743 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
5744 | rc = -1; |
5745 | goto out_fail; | |
5746 | } | |
5747 | } | |
5748 | ||
5749 | if (sas_expander->enclosure_handle) { | |
22a923c3 C |
5750 | enclosure_dev = |
5751 | mpt3sas_scsih_enclosure_find_by_handle(ioc, | |
5752 | sas_expander->enclosure_handle); | |
5753 | if (enclosure_dev) | |
f92363d1 | 5754 | sas_expander->enclosure_logical_id = |
22a923c3 | 5755 | le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID); |
f92363d1 SR |
5756 | } |
5757 | ||
5758 | _scsih_expander_node_add(ioc, sas_expander); | |
199fd79a | 5759 | return 0; |
f92363d1 SR |
5760 | |
5761 | out_fail: | |
5762 | ||
5763 | if (mpt3sas_port) | |
5764 | mpt3sas_transport_port_remove(ioc, sas_expander->sas_address, | |
5765 | sas_address_parent); | |
5766 | kfree(sas_expander); | |
5767 | return rc; | |
5768 | } | |
5769 | ||
5770 | /** | |
5771 | * mpt3sas_expander_remove - removing expander object | |
5772 | * @ioc: per adapter object | |
5773 | * @sas_address: expander sas_address | |
f92363d1 SR |
5774 | */ |
5775 | void | |
5776 | mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address) | |
5777 | { | |
5778 | struct _sas_node *sas_expander; | |
5779 | unsigned long flags; | |
5780 | ||
5781 | if (ioc->shost_recovery) | |
5782 | return; | |
5783 | ||
5784 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
5785 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, | |
5786 | sas_address); | |
f92363d1 SR |
5787 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
5788 | if (sas_expander) | |
5789 | _scsih_expander_node_remove(ioc, sas_expander); | |
5790 | } | |
5791 | ||
5792 | /** | |
5793 | * _scsih_done - internal SCSI_IO callback handler. | |
5794 | * @ioc: per adapter object | |
5795 | * @smid: system request message index | |
5796 | * @msix_index: MSIX table index supplied by the OS | |
5797 | * @reply: reply message frame(lower 32bit addr) | |
5798 | * | |
5799 | * Callback handler when sending internal generated SCSI_IO. | |
5800 | * The callback index passed is `ioc->scsih_cb_idx` | |
5801 | * | |
4beb4867 BVA |
5802 | * Return: 1 meaning mf should be freed from _base_interrupt |
5803 | * 0 means the mf is freed from this function. | |
f92363d1 SR |
5804 | */ |
5805 | static u8 | |
5806 | _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | |
5807 | { | |
5808 | MPI2DefaultReply_t *mpi_reply; | |
5809 | ||
5810 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
5811 | if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED) | |
5812 | return 1; | |
5813 | if (ioc->scsih_cmds.smid != smid) | |
5814 | return 1; | |
5815 | ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE; | |
5816 | if (mpi_reply) { | |
5817 | memcpy(ioc->scsih_cmds.reply, mpi_reply, | |
5818 | mpi_reply->MsgLength*4); | |
5819 | ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID; | |
5820 | } | |
5821 | ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING; | |
5822 | complete(&ioc->scsih_cmds.done); | |
5823 | return 1; | |
5824 | } | |
5825 | ||
5826 | ||
5827 | ||
5828 | ||
5829 | #define MPT3_MAX_LUNS (255) | |
5830 | ||
5831 | ||
5832 | /** | |
5833 | * _scsih_check_access_status - check access flags | |
5834 | * @ioc: per adapter object | |
5835 | * @sas_address: sas address | |
5836 | * @handle: sas device handle | |
4beb4867 | 5837 | * @access_status: errors returned during discovery of the device |
f92363d1 | 5838 | * |
4beb4867 | 5839 | * Return: 0 for success, else failure |
f92363d1 SR |
5840 | */ |
5841 | static u8 | |
5842 | _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address, | |
5843 | u16 handle, u8 access_status) | |
5844 | { | |
5845 | u8 rc = 1; | |
5846 | char *desc = NULL; | |
5847 | ||
5848 | switch (access_status) { | |
5849 | case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS: | |
5850 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION: | |
5851 | rc = 0; | |
5852 | break; | |
5853 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED: | |
5854 | desc = "sata capability failed"; | |
5855 | break; | |
5856 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT: | |
5857 | desc = "sata affiliation conflict"; | |
5858 | break; | |
5859 | case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE: | |
5860 | desc = "route not addressable"; | |
5861 | break; | |
5862 | case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE: | |
5863 | desc = "smp error not addressable"; | |
5864 | break; | |
5865 | case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED: | |
5866 | desc = "device blocked"; | |
5867 | break; | |
5868 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED: | |
5869 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN: | |
5870 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT: | |
5871 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG: | |
5872 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION: | |
5873 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER: | |
5874 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN: | |
5875 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN: | |
5876 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN: | |
5877 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION: | |
5878 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE: | |
5879 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX: | |
5880 | desc = "sata initialization failed"; | |
5881 | break; | |
5882 | default: | |
5883 | desc = "unknown"; | |
5884 | break; | |
5885 | } | |
5886 | ||
5887 | if (!rc) | |
5888 | return 0; | |
5889 | ||
919d8a3f JP |
5890 | ioc_err(ioc, "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n", |
5891 | desc, (u64)sas_address, handle); | |
f92363d1 SR |
5892 | return rc; |
5893 | } | |
5894 | ||
5895 | /** | |
5896 | * _scsih_check_device - checking device responsiveness | |
5897 | * @ioc: per adapter object | |
5898 | * @parent_sas_address: sas address of parent expander or sas host | |
5899 | * @handle: attached device handle | |
4beb4867 | 5900 | * @phy_number: phy number |
f92363d1 | 5901 | * @link_rate: new link rate |
f92363d1 SR |
5902 | */ |
5903 | static void | |
5904 | _scsih_check_device(struct MPT3SAS_ADAPTER *ioc, | |
5905 | u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate) | |
5906 | { | |
5907 | Mpi2ConfigReply_t mpi_reply; | |
5908 | Mpi2SasDevicePage0_t sas_device_pg0; | |
5909 | struct _sas_device *sas_device; | |
22a923c3 | 5910 | struct _enclosure_node *enclosure_dev = NULL; |
f92363d1 SR |
5911 | u32 ioc_status; |
5912 | unsigned long flags; | |
5913 | u64 sas_address; | |
5914 | struct scsi_target *starget; | |
5915 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
5916 | u32 device_info; | |
5917 | ||
f92363d1 SR |
5918 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
5919 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) | |
5920 | return; | |
5921 | ||
5922 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
5923 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | |
5924 | return; | |
5925 | ||
5926 | /* wide port handling ~ we need only handle device once for the phy that | |
5927 | * is matched in sas device page zero | |
5928 | */ | |
5929 | if (phy_number != sas_device_pg0.PhyNum) | |
5930 | return; | |
5931 | ||
5932 | /* check if this is end device */ | |
5933 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | |
5934 | if (!(_scsih_is_end_device(device_info))) | |
5935 | return; | |
5936 | ||
5937 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
5938 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | |
d1cb5e49 | 5939 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 SR |
5940 | sas_address); |
5941 | ||
d1cb5e49 SR |
5942 | if (!sas_device) |
5943 | goto out_unlock; | |
f92363d1 SR |
5944 | |
5945 | if (unlikely(sas_device->handle != handle)) { | |
5946 | starget = sas_device->starget; | |
5947 | sas_target_priv_data = starget->hostdata; | |
5948 | starget_printk(KERN_INFO, starget, | |
5949 | "handle changed from(0x%04x) to (0x%04x)!!!\n", | |
5950 | sas_device->handle, handle); | |
5951 | sas_target_priv_data->handle = handle; | |
5952 | sas_device->handle = handle; | |
aa53bb89 | 5953 | if (le16_to_cpu(sas_device_pg0.Flags) & |
e6d45e3e SR |
5954 | MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) { |
5955 | sas_device->enclosure_level = | |
aa53bb89 | 5956 | sas_device_pg0.EnclosureLevel; |
310c8e40 CO |
5957 | memcpy(sas_device->connector_name, |
5958 | sas_device_pg0.ConnectorName, 4); | |
5959 | sas_device->connector_name[4] = '\0'; | |
e6d45e3e SR |
5960 | } else { |
5961 | sas_device->enclosure_level = 0; | |
5962 | sas_device->connector_name[0] = '\0'; | |
5963 | } | |
aba5a85c | 5964 | |
22a923c3 C |
5965 | sas_device->enclosure_handle = |
5966 | le16_to_cpu(sas_device_pg0.EnclosureHandle); | |
5967 | sas_device->is_chassis_slot_valid = 0; | |
5968 | enclosure_dev = mpt3sas_scsih_enclosure_find_by_handle(ioc, | |
5969 | sas_device->enclosure_handle); | |
5970 | if (enclosure_dev) { | |
5971 | sas_device->enclosure_logical_id = | |
5972 | le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID); | |
5973 | if (le16_to_cpu(enclosure_dev->pg0.Flags) & | |
5974 | MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) { | |
5975 | sas_device->is_chassis_slot_valid = 1; | |
5976 | sas_device->chassis_slot = | |
5977 | enclosure_dev->pg0.ChassisSlot; | |
5978 | } | |
5979 | } | |
f92363d1 SR |
5980 | } |
5981 | ||
5982 | /* check if device is present */ | |
5983 | if (!(le16_to_cpu(sas_device_pg0.Flags) & | |
5984 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { | |
919d8a3f JP |
5985 | ioc_err(ioc, "device is not present handle(0x%04x), flags!!!\n", |
5986 | handle); | |
d1cb5e49 | 5987 | goto out_unlock; |
f92363d1 SR |
5988 | } |
5989 | ||
5990 | /* check if there were any issues with discovery */ | |
5991 | if (_scsih_check_access_status(ioc, sas_address, handle, | |
d1cb5e49 SR |
5992 | sas_device_pg0.AccessStatus)) |
5993 | goto out_unlock; | |
f92363d1 SR |
5994 | |
5995 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
5996 | _scsih_ublock_io_device(ioc, sas_address); | |
5997 | ||
d1cb5e49 SR |
5998 | if (sas_device) |
5999 | sas_device_put(sas_device); | |
6000 | return; | |
6001 | ||
6002 | out_unlock: | |
6003 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
6004 | if (sas_device) | |
6005 | sas_device_put(sas_device); | |
f92363d1 SR |
6006 | } |
6007 | ||
6008 | /** | |
6009 | * _scsih_add_device - creating sas device object | |
6010 | * @ioc: per adapter object | |
6011 | * @handle: sas device handle | |
6012 | * @phy_num: phy number end device attached to | |
6013 | * @is_pd: is this hidden raid component | |
6014 | * | |
6015 | * Creating end device object, stored in ioc->sas_device_list. | |
6016 | * | |
4beb4867 | 6017 | * Return: 0 for success, non-zero for failure. |
f92363d1 SR |
6018 | */ |
6019 | static int | |
6020 | _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num, | |
6021 | u8 is_pd) | |
6022 | { | |
6023 | Mpi2ConfigReply_t mpi_reply; | |
6024 | Mpi2SasDevicePage0_t sas_device_pg0; | |
f92363d1 | 6025 | struct _sas_device *sas_device; |
22a923c3 | 6026 | struct _enclosure_node *enclosure_dev = NULL; |
f92363d1 SR |
6027 | u32 ioc_status; |
6028 | u64 sas_address; | |
6029 | u32 device_info; | |
f92363d1 SR |
6030 | |
6031 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
6032 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
919d8a3f JP |
6033 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
6034 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
6035 | return -1; |
6036 | } | |
6037 | ||
6038 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6039 | MPI2_IOCSTATUS_MASK; | |
6040 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
919d8a3f JP |
6041 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
6042 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
6043 | return -1; |
6044 | } | |
6045 | ||
6046 | /* check if this is end device */ | |
6047 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | |
6048 | if (!(_scsih_is_end_device(device_info))) | |
6049 | return -1; | |
c696f7b8 | 6050 | set_bit(handle, ioc->pend_os_device_add); |
f92363d1 SR |
6051 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
6052 | ||
6053 | /* check if device is present */ | |
6054 | if (!(le16_to_cpu(sas_device_pg0.Flags) & | |
6055 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { | |
919d8a3f JP |
6056 | ioc_err(ioc, "device is not present handle(0x04%x)!!!\n", |
6057 | handle); | |
f92363d1 SR |
6058 | return -1; |
6059 | } | |
6060 | ||
6061 | /* check if there were any issues with discovery */ | |
6062 | if (_scsih_check_access_status(ioc, sas_address, handle, | |
6063 | sas_device_pg0.AccessStatus)) | |
6064 | return -1; | |
6065 | ||
d1cb5e49 SR |
6066 | sas_device = mpt3sas_get_sdev_by_addr(ioc, |
6067 | sas_address); | |
6068 | if (sas_device) { | |
c696f7b8 | 6069 | clear_bit(handle, ioc->pend_os_device_add); |
d1cb5e49 | 6070 | sas_device_put(sas_device); |
f92363d1 | 6071 | return -1; |
d1cb5e49 | 6072 | } |
f92363d1 | 6073 | |
75888956 | 6074 | if (sas_device_pg0.EnclosureHandle) { |
22a923c3 C |
6075 | enclosure_dev = |
6076 | mpt3sas_scsih_enclosure_find_by_handle(ioc, | |
6077 | le16_to_cpu(sas_device_pg0.EnclosureHandle)); | |
6078 | if (enclosure_dev == NULL) | |
919d8a3f JP |
6079 | ioc_info(ioc, "Enclosure handle(0x%04x) doesn't match with enclosure device!\n", |
6080 | sas_device_pg0.EnclosureHandle); | |
75888956 SR |
6081 | } |
6082 | ||
f92363d1 SR |
6083 | sas_device = kzalloc(sizeof(struct _sas_device), |
6084 | GFP_KERNEL); | |
6085 | if (!sas_device) { | |
919d8a3f JP |
6086 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
6087 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
6088 | return 0; |
6089 | } | |
6090 | ||
d1cb5e49 | 6091 | kref_init(&sas_device->refcount); |
f92363d1 SR |
6092 | sas_device->handle = handle; |
6093 | if (_scsih_get_sas_address(ioc, | |
6094 | le16_to_cpu(sas_device_pg0.ParentDevHandle), | |
6095 | &sas_device->sas_address_parent) != 0) | |
919d8a3f JP |
6096 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
6097 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
6098 | sas_device->enclosure_handle = |
6099 | le16_to_cpu(sas_device_pg0.EnclosureHandle); | |
e6d45e3e SR |
6100 | if (sas_device->enclosure_handle != 0) |
6101 | sas_device->slot = | |
6102 | le16_to_cpu(sas_device_pg0.Slot); | |
f92363d1 SR |
6103 | sas_device->device_info = device_info; |
6104 | sas_device->sas_address = sas_address; | |
6105 | sas_device->phy = sas_device_pg0.PhyNum; | |
6106 | sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) & | |
6107 | MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0; | |
6108 | ||
aa53bb89 SPS |
6109 | if (le16_to_cpu(sas_device_pg0.Flags) |
6110 | & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) { | |
e6d45e3e | 6111 | sas_device->enclosure_level = |
aa53bb89 | 6112 | sas_device_pg0.EnclosureLevel; |
310c8e40 CO |
6113 | memcpy(sas_device->connector_name, |
6114 | sas_device_pg0.ConnectorName, 4); | |
6115 | sas_device->connector_name[4] = '\0'; | |
e6d45e3e SR |
6116 | } else { |
6117 | sas_device->enclosure_level = 0; | |
6118 | sas_device->connector_name[0] = '\0'; | |
6119 | } | |
22a923c3 | 6120 | /* get enclosure_logical_id & chassis_slot*/ |
75888956 | 6121 | sas_device->is_chassis_slot_valid = 0; |
22a923c3 | 6122 | if (enclosure_dev) { |
f92363d1 | 6123 | sas_device->enclosure_logical_id = |
22a923c3 C |
6124 | le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID); |
6125 | if (le16_to_cpu(enclosure_dev->pg0.Flags) & | |
75888956 SR |
6126 | MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) { |
6127 | sas_device->is_chassis_slot_valid = 1; | |
6128 | sas_device->chassis_slot = | |
22a923c3 | 6129 | enclosure_dev->pg0.ChassisSlot; |
75888956 SR |
6130 | } |
6131 | } | |
6132 | ||
f92363d1 SR |
6133 | /* get device name */ |
6134 | sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName); | |
6135 | ||
6136 | if (ioc->wait_for_discovery_to_complete) | |
6137 | _scsih_sas_device_init_add(ioc, sas_device); | |
6138 | else | |
6139 | _scsih_sas_device_add(ioc, sas_device); | |
6140 | ||
d1cb5e49 | 6141 | sas_device_put(sas_device); |
f92363d1 SR |
6142 | return 0; |
6143 | } | |
6144 | ||
6145 | /** | |
6146 | * _scsih_remove_device - removing sas device object | |
6147 | * @ioc: per adapter object | |
4beb4867 | 6148 | * @sas_device: the sas_device object |
f92363d1 SR |
6149 | */ |
6150 | static void | |
6151 | _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc, | |
6152 | struct _sas_device *sas_device) | |
6153 | { | |
6154 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
6155 | ||
0f624c39 SR |
6156 | if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) && |
6157 | (sas_device->pfa_led_on)) { | |
6158 | _scsih_turn_off_pfa_led(ioc, sas_device); | |
6159 | sas_device->pfa_led_on = 0; | |
6160 | } | |
75888956 | 6161 | |
919d8a3f JP |
6162 | dewtprintk(ioc, |
6163 | ioc_info(ioc, "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n", | |
6164 | __func__, | |
6165 | sas_device->handle, (u64)sas_device->sas_address)); | |
75888956 SR |
6166 | |
6167 | dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device, | |
6168 | NULL, NULL)); | |
f92363d1 SR |
6169 | |
6170 | if (sas_device->starget && sas_device->starget->hostdata) { | |
6171 | sas_target_priv_data = sas_device->starget->hostdata; | |
6172 | sas_target_priv_data->deleted = 1; | |
6173 | _scsih_ublock_io_device(ioc, sas_device->sas_address); | |
6174 | sas_target_priv_data->handle = | |
6175 | MPT3SAS_INVALID_DEVICE_HANDLE; | |
6176 | } | |
7786ab6a SR |
6177 | |
6178 | if (!ioc->hide_drives) | |
6179 | mpt3sas_transport_port_remove(ioc, | |
f92363d1 SR |
6180 | sas_device->sas_address, |
6181 | sas_device->sas_address_parent); | |
6182 | ||
919d8a3f JP |
6183 | ioc_info(ioc, "removing handle(0x%04x), sas_addr(0x%016llx)\n", |
6184 | sas_device->handle, (u64)sas_device->sas_address); | |
75888956 SR |
6185 | |
6186 | _scsih_display_enclosure_chassis_info(ioc, sas_device, NULL, NULL); | |
f92363d1 | 6187 | |
919d8a3f JP |
6188 | dewtprintk(ioc, |
6189 | ioc_info(ioc, "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n", | |
6190 | __func__, | |
6191 | sas_device->handle, (u64)sas_device->sas_address)); | |
75888956 SR |
6192 | dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device, |
6193 | NULL, NULL)); | |
f92363d1 SR |
6194 | } |
6195 | ||
f92363d1 SR |
6196 | /** |
6197 | * _scsih_sas_topology_change_event_debug - debug for topology event | |
6198 | * @ioc: per adapter object | |
6199 | * @event_data: event data payload | |
6200 | * Context: user. | |
6201 | */ | |
6202 | static void | |
6203 | _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
6204 | Mpi2EventDataSasTopologyChangeList_t *event_data) | |
6205 | { | |
6206 | int i; | |
6207 | u16 handle; | |
6208 | u16 reason_code; | |
6209 | u8 phy_number; | |
6210 | char *status_str = NULL; | |
6211 | u8 link_rate, prev_link_rate; | |
6212 | ||
6213 | switch (event_data->ExpStatus) { | |
6214 | case MPI2_EVENT_SAS_TOPO_ES_ADDED: | |
6215 | status_str = "add"; | |
6216 | break; | |
6217 | case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING: | |
6218 | status_str = "remove"; | |
6219 | break; | |
6220 | case MPI2_EVENT_SAS_TOPO_ES_RESPONDING: | |
6221 | case 0: | |
6222 | status_str = "responding"; | |
6223 | break; | |
6224 | case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING: | |
6225 | status_str = "remove delay"; | |
6226 | break; | |
6227 | default: | |
6228 | status_str = "unknown status"; | |
6229 | break; | |
6230 | } | |
919d8a3f | 6231 | ioc_info(ioc, "sas topology change: (%s)\n", status_str); |
f92363d1 SR |
6232 | pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \ |
6233 | "start_phy(%02d), count(%d)\n", | |
6234 | le16_to_cpu(event_data->ExpanderDevHandle), | |
6235 | le16_to_cpu(event_data->EnclosureHandle), | |
6236 | event_data->StartPhyNum, event_data->NumEntries); | |
6237 | for (i = 0; i < event_data->NumEntries; i++) { | |
6238 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
6239 | if (!handle) | |
6240 | continue; | |
6241 | phy_number = event_data->StartPhyNum + i; | |
6242 | reason_code = event_data->PHY[i].PhyStatus & | |
6243 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
6244 | switch (reason_code) { | |
6245 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: | |
6246 | status_str = "target add"; | |
6247 | break; | |
6248 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: | |
6249 | status_str = "target remove"; | |
6250 | break; | |
6251 | case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING: | |
6252 | status_str = "delay target remove"; | |
6253 | break; | |
6254 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: | |
6255 | status_str = "link rate change"; | |
6256 | break; | |
6257 | case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE: | |
6258 | status_str = "target responding"; | |
6259 | break; | |
6260 | default: | |
6261 | status_str = "unknown"; | |
6262 | break; | |
6263 | } | |
6264 | link_rate = event_data->PHY[i].LinkRate >> 4; | |
6265 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; | |
6266 | pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \ | |
6267 | " link rate: new(0x%02x), old(0x%02x)\n", phy_number, | |
6268 | handle, status_str, link_rate, prev_link_rate); | |
6269 | ||
6270 | } | |
6271 | } | |
f92363d1 SR |
6272 | |
6273 | /** | |
6274 | * _scsih_sas_topology_change_event - handle topology changes | |
6275 | * @ioc: per adapter object | |
6276 | * @fw_event: The fw_event_work object | |
6277 | * Context: user. | |
6278 | * | |
6279 | */ | |
6280 | static int | |
6281 | _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc, | |
6282 | struct fw_event_work *fw_event) | |
6283 | { | |
6284 | int i; | |
6285 | u16 parent_handle, handle; | |
6286 | u16 reason_code; | |
6287 | u8 phy_number, max_phys; | |
6288 | struct _sas_node *sas_expander; | |
6289 | u64 sas_address; | |
6290 | unsigned long flags; | |
6291 | u8 link_rate, prev_link_rate; | |
35b62362 JL |
6292 | Mpi2EventDataSasTopologyChangeList_t *event_data = |
6293 | (Mpi2EventDataSasTopologyChangeList_t *) | |
6294 | fw_event->event_data; | |
f92363d1 | 6295 | |
f92363d1 SR |
6296 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
6297 | _scsih_sas_topology_change_event_debug(ioc, event_data); | |
f92363d1 SR |
6298 | |
6299 | if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery) | |
6300 | return 0; | |
6301 | ||
6302 | if (!ioc->sas_hba.num_phys) | |
6303 | _scsih_sas_host_add(ioc); | |
6304 | else | |
6305 | _scsih_sas_host_refresh(ioc); | |
6306 | ||
6307 | if (fw_event->ignore) { | |
919d8a3f | 6308 | dewtprintk(ioc, ioc_info(ioc, "ignoring expander event\n")); |
f92363d1 SR |
6309 | return 0; |
6310 | } | |
6311 | ||
6312 | parent_handle = le16_to_cpu(event_data->ExpanderDevHandle); | |
6313 | ||
6314 | /* handle expander add */ | |
6315 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED) | |
6316 | if (_scsih_expander_add(ioc, parent_handle) != 0) | |
6317 | return 0; | |
6318 | ||
6319 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
6320 | sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc, | |
6321 | parent_handle); | |
6322 | if (sas_expander) { | |
6323 | sas_address = sas_expander->sas_address; | |
6324 | max_phys = sas_expander->num_phys; | |
6325 | } else if (parent_handle < ioc->sas_hba.num_phys) { | |
6326 | sas_address = ioc->sas_hba.sas_address; | |
6327 | max_phys = ioc->sas_hba.num_phys; | |
6328 | } else { | |
6329 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
6330 | return 0; | |
6331 | } | |
6332 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
6333 | ||
6334 | /* handle siblings events */ | |
6335 | for (i = 0; i < event_data->NumEntries; i++) { | |
6336 | if (fw_event->ignore) { | |
919d8a3f JP |
6337 | dewtprintk(ioc, |
6338 | ioc_info(ioc, "ignoring expander event\n")); | |
f92363d1 SR |
6339 | return 0; |
6340 | } | |
6341 | if (ioc->remove_host || ioc->pci_error_recovery) | |
6342 | return 0; | |
6343 | phy_number = event_data->StartPhyNum + i; | |
6344 | if (phy_number >= max_phys) | |
6345 | continue; | |
6346 | reason_code = event_data->PHY[i].PhyStatus & | |
6347 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
6348 | if ((event_data->PHY[i].PhyStatus & | |
6349 | MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code != | |
6350 | MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)) | |
6351 | continue; | |
6352 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
6353 | if (!handle) | |
6354 | continue; | |
6355 | link_rate = event_data->PHY[i].LinkRate >> 4; | |
6356 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; | |
6357 | switch (reason_code) { | |
6358 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: | |
6359 | ||
6360 | if (ioc->shost_recovery) | |
6361 | break; | |
6362 | ||
6363 | if (link_rate == prev_link_rate) | |
6364 | break; | |
6365 | ||
6366 | mpt3sas_transport_update_links(ioc, sas_address, | |
6367 | handle, phy_number, link_rate); | |
6368 | ||
6369 | if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) | |
6370 | break; | |
6371 | ||
6372 | _scsih_check_device(ioc, sas_address, handle, | |
6373 | phy_number, link_rate); | |
6374 | ||
c696f7b8 SPS |
6375 | if (!test_bit(handle, ioc->pend_os_device_add)) |
6376 | break; | |
6377 | ||
eb0c7af2 | 6378 | /* fall through */ |
f92363d1 SR |
6379 | |
6380 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: | |
6381 | ||
6382 | if (ioc->shost_recovery) | |
6383 | break; | |
6384 | ||
6385 | mpt3sas_transport_update_links(ioc, sas_address, | |
6386 | handle, phy_number, link_rate); | |
6387 | ||
6388 | _scsih_add_device(ioc, handle, phy_number, 0); | |
6389 | ||
6390 | break; | |
6391 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: | |
6392 | ||
6393 | _scsih_device_remove_by_handle(ioc, handle); | |
6394 | break; | |
6395 | } | |
6396 | } | |
6397 | ||
6398 | /* handle expander removal */ | |
6399 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING && | |
6400 | sas_expander) | |
6401 | mpt3sas_expander_remove(ioc, sas_address); | |
6402 | ||
6403 | return 0; | |
6404 | } | |
6405 | ||
f92363d1 SR |
6406 | /** |
6407 | * _scsih_sas_device_status_change_event_debug - debug for device event | |
4beb4867 | 6408 | * @ioc: ? |
f92363d1 SR |
6409 | * @event_data: event data payload |
6410 | * Context: user. | |
f92363d1 SR |
6411 | */ |
6412 | static void | |
6413 | _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
6414 | Mpi2EventDataSasDeviceStatusChange_t *event_data) | |
6415 | { | |
6416 | char *reason_str = NULL; | |
6417 | ||
6418 | switch (event_data->ReasonCode) { | |
6419 | case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA: | |
6420 | reason_str = "smart data"; | |
6421 | break; | |
6422 | case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED: | |
6423 | reason_str = "unsupported device discovered"; | |
6424 | break; | |
6425 | case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET: | |
6426 | reason_str = "internal device reset"; | |
6427 | break; | |
6428 | case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL: | |
6429 | reason_str = "internal task abort"; | |
6430 | break; | |
6431 | case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL: | |
6432 | reason_str = "internal task abort set"; | |
6433 | break; | |
6434 | case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL: | |
6435 | reason_str = "internal clear task set"; | |
6436 | break; | |
6437 | case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL: | |
6438 | reason_str = "internal query task"; | |
6439 | break; | |
6440 | case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE: | |
6441 | reason_str = "sata init failure"; | |
6442 | break; | |
6443 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET: | |
6444 | reason_str = "internal device reset complete"; | |
6445 | break; | |
6446 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL: | |
6447 | reason_str = "internal task abort complete"; | |
6448 | break; | |
6449 | case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION: | |
6450 | reason_str = "internal async notification"; | |
6451 | break; | |
6452 | case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY: | |
6453 | reason_str = "expander reduced functionality"; | |
6454 | break; | |
6455 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY: | |
6456 | reason_str = "expander reduced functionality complete"; | |
6457 | break; | |
6458 | default: | |
6459 | reason_str = "unknown reason"; | |
6460 | break; | |
6461 | } | |
919d8a3f JP |
6462 | ioc_info(ioc, "device status change: (%s)\thandle(0x%04x), sas address(0x%016llx), tag(%d)", |
6463 | reason_str, le16_to_cpu(event_data->DevHandle), | |
6464 | (u64)le64_to_cpu(event_data->SASAddress), | |
6465 | le16_to_cpu(event_data->TaskTag)); | |
f92363d1 | 6466 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA) |
919d8a3f JP |
6467 | pr_cont(", ASC(0x%x), ASCQ(0x%x)\n", |
6468 | event_data->ASC, event_data->ASCQ); | |
6469 | pr_cont("\n"); | |
f92363d1 | 6470 | } |
f92363d1 SR |
6471 | |
6472 | /** | |
6473 | * _scsih_sas_device_status_change_event - handle device status change | |
6474 | * @ioc: per adapter object | |
6475 | * @fw_event: The fw_event_work object | |
6476 | * Context: user. | |
f92363d1 SR |
6477 | */ |
6478 | static void | |
6479 | _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc, | |
6480 | struct fw_event_work *fw_event) | |
6481 | { | |
6482 | struct MPT3SAS_TARGET *target_priv_data; | |
6483 | struct _sas_device *sas_device; | |
6484 | u64 sas_address; | |
6485 | unsigned long flags; | |
6486 | Mpi2EventDataSasDeviceStatusChange_t *event_data = | |
35b62362 JL |
6487 | (Mpi2EventDataSasDeviceStatusChange_t *) |
6488 | fw_event->event_data; | |
f92363d1 | 6489 | |
f92363d1 SR |
6490 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
6491 | _scsih_sas_device_status_change_event_debug(ioc, | |
6492 | event_data); | |
f92363d1 SR |
6493 | |
6494 | /* In MPI Revision K (0xC), the internal device reset complete was | |
6495 | * implemented, so avoid setting tm_busy flag for older firmware. | |
6496 | */ | |
6497 | if ((ioc->facts.HeaderVersion >> 8) < 0xC) | |
6498 | return; | |
6499 | ||
6500 | if (event_data->ReasonCode != | |
6501 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET && | |
6502 | event_data->ReasonCode != | |
6503 | MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET) | |
6504 | return; | |
6505 | ||
6506 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
6507 | sas_address = le64_to_cpu(event_data->SASAddress); | |
d1cb5e49 | 6508 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 SR |
6509 | sas_address); |
6510 | ||
d1cb5e49 SR |
6511 | if (!sas_device || !sas_device->starget) |
6512 | goto out; | |
f92363d1 SR |
6513 | |
6514 | target_priv_data = sas_device->starget->hostdata; | |
d1cb5e49 SR |
6515 | if (!target_priv_data) |
6516 | goto out; | |
f92363d1 SR |
6517 | |
6518 | if (event_data->ReasonCode == | |
6519 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET) | |
6520 | target_priv_data->tm_busy = 1; | |
6521 | else | |
6522 | target_priv_data->tm_busy = 0; | |
d1cb5e49 SR |
6523 | |
6524 | out: | |
6525 | if (sas_device) | |
6526 | sas_device_put(sas_device); | |
6527 | ||
f92363d1 SR |
6528 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
6529 | } | |
6530 | ||
4318c734 | 6531 | |
c102e00c SPS |
6532 | /** |
6533 | * _scsih_check_pcie_access_status - check access flags | |
6534 | * @ioc: per adapter object | |
6535 | * @wwid: wwid | |
6536 | * @handle: sas device handle | |
4beb4867 | 6537 | * @access_status: errors returned during discovery of the device |
c102e00c | 6538 | * |
4beb4867 | 6539 | * Return: 0 for success, else failure |
c102e00c SPS |
6540 | */ |
6541 | static u8 | |
6542 | _scsih_check_pcie_access_status(struct MPT3SAS_ADAPTER *ioc, u64 wwid, | |
6543 | u16 handle, u8 access_status) | |
6544 | { | |
6545 | u8 rc = 1; | |
6546 | char *desc = NULL; | |
6547 | ||
6548 | switch (access_status) { | |
6549 | case MPI26_PCIEDEV0_ASTATUS_NO_ERRORS: | |
6550 | case MPI26_PCIEDEV0_ASTATUS_NEEDS_INITIALIZATION: | |
6551 | rc = 0; | |
6552 | break; | |
6553 | case MPI26_PCIEDEV0_ASTATUS_CAPABILITY_FAILED: | |
6554 | desc = "PCIe device capability failed"; | |
6555 | break; | |
6556 | case MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED: | |
6557 | desc = "PCIe device blocked"; | |
3c090ce3 SP |
6558 | ioc_info(ioc, |
6559 | "Device with Access Status (%s): wwid(0x%016llx), " | |
6560 | "handle(0x%04x)\n ll only be added to the internal list", | |
6561 | desc, (u64)wwid, handle); | |
6562 | rc = 0; | |
c102e00c SPS |
6563 | break; |
6564 | case MPI26_PCIEDEV0_ASTATUS_MEMORY_SPACE_ACCESS_FAILED: | |
6565 | desc = "PCIe device mem space access failed"; | |
6566 | break; | |
6567 | case MPI26_PCIEDEV0_ASTATUS_UNSUPPORTED_DEVICE: | |
6568 | desc = "PCIe device unsupported"; | |
6569 | break; | |
6570 | case MPI26_PCIEDEV0_ASTATUS_MSIX_REQUIRED: | |
6571 | desc = "PCIe device MSIx Required"; | |
6572 | break; | |
6573 | case MPI26_PCIEDEV0_ASTATUS_INIT_FAIL_MAX: | |
6574 | desc = "PCIe device init fail max"; | |
6575 | break; | |
6576 | case MPI26_PCIEDEV0_ASTATUS_UNKNOWN: | |
6577 | desc = "PCIe device status unknown"; | |
6578 | break; | |
6579 | case MPI26_PCIEDEV0_ASTATUS_NVME_READY_TIMEOUT: | |
6580 | desc = "nvme ready timeout"; | |
6581 | break; | |
6582 | case MPI26_PCIEDEV0_ASTATUS_NVME_DEVCFG_UNSUPPORTED: | |
6583 | desc = "nvme device configuration unsupported"; | |
6584 | break; | |
6585 | case MPI26_PCIEDEV0_ASTATUS_NVME_IDENTIFY_FAILED: | |
6586 | desc = "nvme identify failed"; | |
6587 | break; | |
6588 | case MPI26_PCIEDEV0_ASTATUS_NVME_QCONFIG_FAILED: | |
6589 | desc = "nvme qconfig failed"; | |
6590 | break; | |
6591 | case MPI26_PCIEDEV0_ASTATUS_NVME_QCREATION_FAILED: | |
6592 | desc = "nvme qcreation failed"; | |
6593 | break; | |
6594 | case MPI26_PCIEDEV0_ASTATUS_NVME_EVENTCFG_FAILED: | |
6595 | desc = "nvme eventcfg failed"; | |
6596 | break; | |
6597 | case MPI26_PCIEDEV0_ASTATUS_NVME_GET_FEATURE_STAT_FAILED: | |
6598 | desc = "nvme get feature stat failed"; | |
6599 | break; | |
6600 | case MPI26_PCIEDEV0_ASTATUS_NVME_IDLE_TIMEOUT: | |
6601 | desc = "nvme idle timeout"; | |
6602 | break; | |
6603 | case MPI26_PCIEDEV0_ASTATUS_NVME_FAILURE_STATUS: | |
6604 | desc = "nvme failure status"; | |
6605 | break; | |
6606 | default: | |
919d8a3f JP |
6607 | ioc_err(ioc, "NVMe discovery error(0x%02x): wwid(0x%016llx), handle(0x%04x)\n", |
6608 | access_status, (u64)wwid, handle); | |
c102e00c SPS |
6609 | return rc; |
6610 | } | |
6611 | ||
6612 | if (!rc) | |
6613 | return rc; | |
6614 | ||
919d8a3f JP |
6615 | ioc_info(ioc, "NVMe discovery error(%s): wwid(0x%016llx), handle(0x%04x)\n", |
6616 | desc, (u64)wwid, handle); | |
c102e00c SPS |
6617 | return rc; |
6618 | } | |
3075ac49 SPS |
6619 | |
6620 | /** | |
6621 | * _scsih_pcie_device_remove_from_sml - removing pcie device | |
6622 | * from SML and free up associated memory | |
6623 | * @ioc: per adapter object | |
6624 | * @pcie_device: the pcie_device object | |
3075ac49 SPS |
6625 | */ |
6626 | static void | |
6627 | _scsih_pcie_device_remove_from_sml(struct MPT3SAS_ADAPTER *ioc, | |
6628 | struct _pcie_device *pcie_device) | |
6629 | { | |
6630 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
6631 | ||
919d8a3f JP |
6632 | dewtprintk(ioc, |
6633 | ioc_info(ioc, "%s: enter: handle(0x%04x), wwid(0x%016llx)\n", | |
6634 | __func__, | |
6635 | pcie_device->handle, (u64)pcie_device->wwid)); | |
3075ac49 | 6636 | if (pcie_device->enclosure_handle != 0) |
919d8a3f JP |
6637 | dewtprintk(ioc, |
6638 | ioc_info(ioc, "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n", | |
6639 | __func__, | |
6640 | (u64)pcie_device->enclosure_logical_id, | |
6641 | pcie_device->slot)); | |
3075ac49 | 6642 | if (pcie_device->connector_name[0] != '\0') |
919d8a3f JP |
6643 | dewtprintk(ioc, |
6644 | ioc_info(ioc, "%s: enter: enclosure level(0x%04x), connector name(%s)\n", | |
6645 | __func__, | |
6646 | pcie_device->enclosure_level, | |
6647 | pcie_device->connector_name)); | |
3075ac49 SPS |
6648 | |
6649 | if (pcie_device->starget && pcie_device->starget->hostdata) { | |
6650 | sas_target_priv_data = pcie_device->starget->hostdata; | |
6651 | sas_target_priv_data->deleted = 1; | |
6652 | _scsih_ublock_io_device(ioc, pcie_device->wwid); | |
6653 | sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE; | |
6654 | } | |
6655 | ||
919d8a3f JP |
6656 | ioc_info(ioc, "removing handle(0x%04x), wwid(0x%016llx)\n", |
6657 | pcie_device->handle, (u64)pcie_device->wwid); | |
3075ac49 | 6658 | if (pcie_device->enclosure_handle != 0) |
919d8a3f JP |
6659 | ioc_info(ioc, "removing : enclosure logical id(0x%016llx), slot(%d)\n", |
6660 | (u64)pcie_device->enclosure_logical_id, | |
6661 | pcie_device->slot); | |
3075ac49 | 6662 | if (pcie_device->connector_name[0] != '\0') |
919d8a3f JP |
6663 | ioc_info(ioc, "removing: enclosure level(0x%04x), connector name( %s)\n", |
6664 | pcie_device->enclosure_level, | |
6665 | pcie_device->connector_name); | |
3075ac49 | 6666 | |
3c090ce3 SP |
6667 | if (pcie_device->starget && (pcie_device->access_status != |
6668 | MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED)) | |
3075ac49 | 6669 | scsi_remove_target(&pcie_device->starget->dev); |
919d8a3f JP |
6670 | dewtprintk(ioc, |
6671 | ioc_info(ioc, "%s: exit: handle(0x%04x), wwid(0x%016llx)\n", | |
6672 | __func__, | |
6673 | pcie_device->handle, (u64)pcie_device->wwid)); | |
3075ac49 | 6674 | if (pcie_device->enclosure_handle != 0) |
919d8a3f JP |
6675 | dewtprintk(ioc, |
6676 | ioc_info(ioc, "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n", | |
6677 | __func__, | |
6678 | (u64)pcie_device->enclosure_logical_id, | |
6679 | pcie_device->slot)); | |
3075ac49 | 6680 | if (pcie_device->connector_name[0] != '\0') |
919d8a3f JP |
6681 | dewtprintk(ioc, |
6682 | ioc_info(ioc, "%s: exit: enclosure level(0x%04x), connector name( %s)\n", | |
6683 | __func__, | |
6684 | pcie_device->enclosure_level, | |
6685 | pcie_device->connector_name)); | |
3075ac49 SPS |
6686 | |
6687 | kfree(pcie_device->serial_number); | |
6688 | } | |
6689 | ||
6690 | ||
c102e00c SPS |
6691 | /** |
6692 | * _scsih_pcie_check_device - checking device responsiveness | |
6693 | * @ioc: per adapter object | |
6694 | * @handle: attached device handle | |
c102e00c SPS |
6695 | */ |
6696 | static void | |
6697 | _scsih_pcie_check_device(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
6698 | { | |
6699 | Mpi2ConfigReply_t mpi_reply; | |
6700 | Mpi26PCIeDevicePage0_t pcie_device_pg0; | |
6701 | u32 ioc_status; | |
6702 | struct _pcie_device *pcie_device; | |
6703 | u64 wwid; | |
6704 | unsigned long flags; | |
6705 | struct scsi_target *starget; | |
6706 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
6707 | u32 device_info; | |
6708 | ||
6709 | if ((mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply, | |
6710 | &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE, handle))) | |
6711 | return; | |
6712 | ||
6713 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
6714 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | |
6715 | return; | |
6716 | ||
6717 | /* check if this is end device */ | |
6718 | device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo); | |
5bb309db | 6719 | if (!(_scsih_is_nvme_pciescsi_device(device_info))) |
c102e00c SPS |
6720 | return; |
6721 | ||
6722 | wwid = le64_to_cpu(pcie_device_pg0.WWID); | |
6723 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
6724 | pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid); | |
6725 | ||
6726 | if (!pcie_device) { | |
6727 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
6728 | return; | |
6729 | } | |
6730 | ||
6731 | if (unlikely(pcie_device->handle != handle)) { | |
6732 | starget = pcie_device->starget; | |
6733 | sas_target_priv_data = starget->hostdata; | |
3c090ce3 | 6734 | pcie_device->access_status = pcie_device_pg0.AccessStatus; |
c102e00c SPS |
6735 | starget_printk(KERN_INFO, starget, |
6736 | "handle changed from(0x%04x) to (0x%04x)!!!\n", | |
6737 | pcie_device->handle, handle); | |
6738 | sas_target_priv_data->handle = handle; | |
6739 | pcie_device->handle = handle; | |
6740 | ||
6741 | if (le32_to_cpu(pcie_device_pg0.Flags) & | |
6742 | MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) { | |
6743 | pcie_device->enclosure_level = | |
6744 | pcie_device_pg0.EnclosureLevel; | |
6745 | memcpy(&pcie_device->connector_name[0], | |
6746 | &pcie_device_pg0.ConnectorName[0], 4); | |
6747 | } else { | |
6748 | pcie_device->enclosure_level = 0; | |
6749 | pcie_device->connector_name[0] = '\0'; | |
6750 | } | |
6751 | } | |
6752 | ||
6753 | /* check if device is present */ | |
6754 | if (!(le32_to_cpu(pcie_device_pg0.Flags) & | |
6755 | MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT)) { | |
919d8a3f JP |
6756 | ioc_info(ioc, "device is not present handle(0x%04x), flags!!!\n", |
6757 | handle); | |
c102e00c SPS |
6758 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); |
6759 | pcie_device_put(pcie_device); | |
6760 | return; | |
6761 | } | |
6762 | ||
6763 | /* check if there were any issues with discovery */ | |
6764 | if (_scsih_check_pcie_access_status(ioc, wwid, handle, | |
6765 | pcie_device_pg0.AccessStatus)) { | |
6766 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
6767 | pcie_device_put(pcie_device); | |
6768 | return; | |
6769 | } | |
6770 | ||
6771 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
6772 | pcie_device_put(pcie_device); | |
6773 | ||
6774 | _scsih_ublock_io_device(ioc, wwid); | |
6775 | ||
6776 | return; | |
6777 | } | |
6778 | ||
6779 | /** | |
6780 | * _scsih_pcie_add_device - creating pcie device object | |
6781 | * @ioc: per adapter object | |
6782 | * @handle: pcie device handle | |
6783 | * | |
6784 | * Creating end device object, stored in ioc->pcie_device_list. | |
6785 | * | |
4beb4867 | 6786 | * Return: 1 means queue the event later, 0 means complete the event |
c102e00c SPS |
6787 | */ |
6788 | static int | |
6789 | _scsih_pcie_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
6790 | { | |
6791 | Mpi26PCIeDevicePage0_t pcie_device_pg0; | |
6792 | Mpi26PCIeDevicePage2_t pcie_device_pg2; | |
6793 | Mpi2ConfigReply_t mpi_reply; | |
c102e00c | 6794 | struct _pcie_device *pcie_device; |
22a923c3 | 6795 | struct _enclosure_node *enclosure_dev; |
c102e00c SPS |
6796 | u32 ioc_status; |
6797 | u64 wwid; | |
6798 | ||
6799 | if ((mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply, | |
6800 | &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
919d8a3f JP |
6801 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
6802 | __FILE__, __LINE__, __func__); | |
c102e00c SPS |
6803 | return 0; |
6804 | } | |
6805 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6806 | MPI2_IOCSTATUS_MASK; | |
6807 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
919d8a3f JP |
6808 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
6809 | __FILE__, __LINE__, __func__); | |
c102e00c SPS |
6810 | return 0; |
6811 | } | |
6812 | ||
6813 | set_bit(handle, ioc->pend_os_device_add); | |
6814 | wwid = le64_to_cpu(pcie_device_pg0.WWID); | |
6815 | ||
6816 | /* check if device is present */ | |
6817 | if (!(le32_to_cpu(pcie_device_pg0.Flags) & | |
6818 | MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT)) { | |
919d8a3f JP |
6819 | ioc_err(ioc, "device is not present handle(0x04%x)!!!\n", |
6820 | handle); | |
c102e00c SPS |
6821 | return 0; |
6822 | } | |
6823 | ||
6824 | /* check if there were any issues with discovery */ | |
6825 | if (_scsih_check_pcie_access_status(ioc, wwid, handle, | |
6826 | pcie_device_pg0.AccessStatus)) | |
6827 | return 0; | |
6828 | ||
5bb309db SP |
6829 | if (!(_scsih_is_nvme_pciescsi_device(le32_to_cpu |
6830 | (pcie_device_pg0.DeviceInfo)))) | |
c102e00c SPS |
6831 | return 0; |
6832 | ||
6833 | pcie_device = mpt3sas_get_pdev_by_wwid(ioc, wwid); | |
6834 | if (pcie_device) { | |
6835 | clear_bit(handle, ioc->pend_os_device_add); | |
6836 | pcie_device_put(pcie_device); | |
6837 | return 0; | |
6838 | } | |
6839 | ||
5bb309db SP |
6840 | /* PCIe Device Page 2 contains read-only information about a |
6841 | * specific NVMe device; therefore, this page is only | |
6842 | * valid for NVMe devices and skip for pcie devices of type scsi. | |
6843 | */ | |
6844 | if (!(mpt3sas_scsih_is_pcie_scsi_device( | |
6845 | le32_to_cpu(pcie_device_pg0.DeviceInfo)))) { | |
6846 | if (mpt3sas_config_get_pcie_device_pg2(ioc, &mpi_reply, | |
6847 | &pcie_device_pg2, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | |
6848 | handle)) { | |
6849 | ioc_err(ioc, | |
6850 | "failure at %s:%d/%s()!\n", __FILE__, | |
6851 | __LINE__, __func__); | |
6852 | return 0; | |
6853 | } | |
6854 | ||
6855 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6856 | MPI2_IOCSTATUS_MASK; | |
6857 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
6858 | ioc_err(ioc, | |
6859 | "failure at %s:%d/%s()!\n", __FILE__, | |
6860 | __LINE__, __func__); | |
6861 | return 0; | |
6862 | } | |
6863 | } | |
6864 | ||
c102e00c SPS |
6865 | pcie_device = kzalloc(sizeof(struct _pcie_device), GFP_KERNEL); |
6866 | if (!pcie_device) { | |
919d8a3f JP |
6867 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
6868 | __FILE__, __LINE__, __func__); | |
c102e00c SPS |
6869 | return 0; |
6870 | } | |
6871 | ||
6872 | kref_init(&pcie_device->refcount); | |
6873 | pcie_device->id = ioc->pcie_target_id++; | |
6874 | pcie_device->channel = PCIE_CHANNEL; | |
6875 | pcie_device->handle = handle; | |
3c090ce3 | 6876 | pcie_device->access_status = pcie_device_pg0.AccessStatus; |
c102e00c SPS |
6877 | pcie_device->device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo); |
6878 | pcie_device->wwid = wwid; | |
6879 | pcie_device->port_num = pcie_device_pg0.PortNum; | |
6880 | pcie_device->fast_path = (le32_to_cpu(pcie_device_pg0.Flags) & | |
6881 | MPI26_PCIEDEV0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0; | |
c102e00c SPS |
6882 | |
6883 | pcie_device->enclosure_handle = | |
6884 | le16_to_cpu(pcie_device_pg0.EnclosureHandle); | |
6885 | if (pcie_device->enclosure_handle != 0) | |
6886 | pcie_device->slot = le16_to_cpu(pcie_device_pg0.Slot); | |
6887 | ||
cf6bf971 | 6888 | if (le32_to_cpu(pcie_device_pg0.Flags) & |
c102e00c SPS |
6889 | MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) { |
6890 | pcie_device->enclosure_level = pcie_device_pg0.EnclosureLevel; | |
6891 | memcpy(&pcie_device->connector_name[0], | |
6892 | &pcie_device_pg0.ConnectorName[0], 4); | |
6893 | } else { | |
6894 | pcie_device->enclosure_level = 0; | |
6895 | pcie_device->connector_name[0] = '\0'; | |
6896 | } | |
6897 | ||
6898 | /* get enclosure_logical_id */ | |
22a923c3 C |
6899 | if (pcie_device->enclosure_handle) { |
6900 | enclosure_dev = | |
6901 | mpt3sas_scsih_enclosure_find_by_handle(ioc, | |
6902 | pcie_device->enclosure_handle); | |
6903 | if (enclosure_dev) | |
6904 | pcie_device->enclosure_logical_id = | |
6905 | le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID); | |
6906 | } | |
c102e00c | 6907 | /* TODO -- Add device name once FW supports it */ |
5bb309db SP |
6908 | if (!(mpt3sas_scsih_is_pcie_scsi_device( |
6909 | le32_to_cpu(pcie_device_pg0.DeviceInfo)))) { | |
6910 | pcie_device->nvme_mdts = | |
6911 | le32_to_cpu(pcie_device_pg2.MaximumDataTransferSize); | |
6912 | if (pcie_device_pg2.ControllerResetTO) | |
6913 | pcie_device->reset_timeout = | |
6914 | pcie_device_pg2.ControllerResetTO; | |
6915 | else | |
6916 | pcie_device->reset_timeout = 30; | |
6917 | } else | |
c1a6c5ac | 6918 | pcie_device->reset_timeout = 30; |
c102e00c SPS |
6919 | |
6920 | if (ioc->wait_for_discovery_to_complete) | |
6921 | _scsih_pcie_device_init_add(ioc, pcie_device); | |
6922 | else | |
6923 | _scsih_pcie_device_add(ioc, pcie_device); | |
6924 | ||
6925 | pcie_device_put(pcie_device); | |
6926 | return 0; | |
6927 | } | |
4318c734 SPS |
6928 | |
6929 | /** | |
6930 | * _scsih_pcie_topology_change_event_debug - debug for topology | |
6931 | * event | |
6932 | * @ioc: per adapter object | |
6933 | * @event_data: event data payload | |
6934 | * Context: user. | |
6935 | */ | |
6936 | static void | |
6937 | _scsih_pcie_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
6938 | Mpi26EventDataPCIeTopologyChangeList_t *event_data) | |
6939 | { | |
6940 | int i; | |
6941 | u16 handle; | |
6942 | u16 reason_code; | |
6943 | u8 port_number; | |
6944 | char *status_str = NULL; | |
6945 | u8 link_rate, prev_link_rate; | |
6946 | ||
6947 | switch (event_data->SwitchStatus) { | |
6948 | case MPI26_EVENT_PCIE_TOPO_SS_ADDED: | |
6949 | status_str = "add"; | |
6950 | break; | |
6951 | case MPI26_EVENT_PCIE_TOPO_SS_NOT_RESPONDING: | |
6952 | status_str = "remove"; | |
6953 | break; | |
6954 | case MPI26_EVENT_PCIE_TOPO_SS_RESPONDING: | |
6955 | case 0: | |
6956 | status_str = "responding"; | |
6957 | break; | |
6958 | case MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING: | |
6959 | status_str = "remove delay"; | |
6960 | break; | |
6961 | default: | |
6962 | status_str = "unknown status"; | |
6963 | break; | |
6964 | } | |
919d8a3f | 6965 | ioc_info(ioc, "pcie topology change: (%s)\n", status_str); |
4318c734 SPS |
6966 | pr_info("\tswitch_handle(0x%04x), enclosure_handle(0x%04x)" |
6967 | "start_port(%02d), count(%d)\n", | |
6968 | le16_to_cpu(event_data->SwitchDevHandle), | |
6969 | le16_to_cpu(event_data->EnclosureHandle), | |
6970 | event_data->StartPortNum, event_data->NumEntries); | |
6971 | for (i = 0; i < event_data->NumEntries; i++) { | |
6972 | handle = | |
6973 | le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle); | |
6974 | if (!handle) | |
6975 | continue; | |
6976 | port_number = event_data->StartPortNum + i; | |
6977 | reason_code = event_data->PortEntry[i].PortStatus; | |
6978 | switch (reason_code) { | |
6979 | case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED: | |
6980 | status_str = "target add"; | |
6981 | break; | |
6982 | case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING: | |
6983 | status_str = "target remove"; | |
6984 | break; | |
6985 | case MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING: | |
6986 | status_str = "delay target remove"; | |
6987 | break; | |
6988 | case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED: | |
6989 | status_str = "link rate change"; | |
6990 | break; | |
6991 | case MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE: | |
6992 | status_str = "target responding"; | |
6993 | break; | |
6994 | default: | |
6995 | status_str = "unknown"; | |
6996 | break; | |
6997 | } | |
6998 | link_rate = event_data->PortEntry[i].CurrentPortInfo & | |
6999 | MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK; | |
7000 | prev_link_rate = event_data->PortEntry[i].PreviousPortInfo & | |
7001 | MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK; | |
7002 | pr_info("\tport(%02d), attached_handle(0x%04x): %s:" | |
7003 | " link rate: new(0x%02x), old(0x%02x)\n", port_number, | |
7004 | handle, status_str, link_rate, prev_link_rate); | |
7005 | } | |
7006 | } | |
7007 | ||
7008 | /** | |
7009 | * _scsih_pcie_topology_change_event - handle PCIe topology | |
7010 | * changes | |
7011 | * @ioc: per adapter object | |
7012 | * @fw_event: The fw_event_work object | |
7013 | * Context: user. | |
7014 | * | |
7015 | */ | |
45b7aef7 | 7016 | static void |
4318c734 SPS |
7017 | _scsih_pcie_topology_change_event(struct MPT3SAS_ADAPTER *ioc, |
7018 | struct fw_event_work *fw_event) | |
7019 | { | |
7020 | int i; | |
7021 | u16 handle; | |
7022 | u16 reason_code; | |
7023 | u8 link_rate, prev_link_rate; | |
7024 | unsigned long flags; | |
7025 | int rc; | |
4318c734 SPS |
7026 | Mpi26EventDataPCIeTopologyChangeList_t *event_data = |
7027 | (Mpi26EventDataPCIeTopologyChangeList_t *) fw_event->event_data; | |
7028 | struct _pcie_device *pcie_device; | |
7029 | ||
7030 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) | |
7031 | _scsih_pcie_topology_change_event_debug(ioc, event_data); | |
7032 | ||
7033 | if (ioc->shost_recovery || ioc->remove_host || | |
7034 | ioc->pci_error_recovery) | |
45b7aef7 | 7035 | return; |
4318c734 SPS |
7036 | |
7037 | if (fw_event->ignore) { | |
919d8a3f | 7038 | dewtprintk(ioc, ioc_info(ioc, "ignoring switch event\n")); |
45b7aef7 | 7039 | return; |
4318c734 SPS |
7040 | } |
7041 | ||
7042 | /* handle siblings events */ | |
7043 | for (i = 0; i < event_data->NumEntries; i++) { | |
7044 | if (fw_event->ignore) { | |
919d8a3f JP |
7045 | dewtprintk(ioc, |
7046 | ioc_info(ioc, "ignoring switch event\n")); | |
45b7aef7 | 7047 | return; |
4318c734 SPS |
7048 | } |
7049 | if (ioc->remove_host || ioc->pci_error_recovery) | |
45b7aef7 | 7050 | return; |
4318c734 SPS |
7051 | reason_code = event_data->PortEntry[i].PortStatus; |
7052 | handle = | |
7053 | le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle); | |
7054 | if (!handle) | |
7055 | continue; | |
7056 | ||
7057 | link_rate = event_data->PortEntry[i].CurrentPortInfo | |
7058 | & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK; | |
7059 | prev_link_rate = event_data->PortEntry[i].PreviousPortInfo | |
7060 | & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK; | |
7061 | ||
7062 | switch (reason_code) { | |
7063 | case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED: | |
7064 | if (ioc->shost_recovery) | |
7065 | break; | |
7066 | if (link_rate == prev_link_rate) | |
7067 | break; | |
7068 | if (link_rate < MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5) | |
7069 | break; | |
7070 | ||
7071 | _scsih_pcie_check_device(ioc, handle); | |
7072 | ||
7073 | /* This code after this point handles the test case | |
7074 | * where a device has been added, however its returning | |
7075 | * BUSY for sometime. Then before the Device Missing | |
7076 | * Delay expires and the device becomes READY, the | |
7077 | * device is removed and added back. | |
7078 | */ | |
7079 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
7080 | pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle); | |
7081 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
7082 | ||
7083 | if (pcie_device) { | |
7084 | pcie_device_put(pcie_device); | |
7085 | break; | |
7086 | } | |
7087 | ||
7088 | if (!test_bit(handle, ioc->pend_os_device_add)) | |
7089 | break; | |
7090 | ||
919d8a3f JP |
7091 | dewtprintk(ioc, |
7092 | ioc_info(ioc, "handle(0x%04x) device not found: convert event to a device add\n", | |
7093 | handle)); | |
4318c734 SPS |
7094 | event_data->PortEntry[i].PortStatus &= 0xF0; |
7095 | event_data->PortEntry[i].PortStatus |= | |
7096 | MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED; | |
eb0c7af2 | 7097 | /* fall through */ |
4318c734 SPS |
7098 | case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED: |
7099 | if (ioc->shost_recovery) | |
7100 | break; | |
7101 | if (link_rate < MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5) | |
7102 | break; | |
7103 | ||
7104 | rc = _scsih_pcie_add_device(ioc, handle); | |
7105 | if (!rc) { | |
7106 | /* mark entry vacant */ | |
7107 | /* TODO This needs to be reviewed and fixed, | |
7108 | * we dont have an entry | |
7109 | * to make an event void like vacant | |
7110 | */ | |
7111 | event_data->PortEntry[i].PortStatus |= | |
7112 | MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE; | |
7113 | } | |
7114 | break; | |
7115 | case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING: | |
7116 | _scsih_pcie_device_remove_by_handle(ioc, handle); | |
7117 | break; | |
7118 | } | |
7119 | } | |
4318c734 SPS |
7120 | } |
7121 | ||
7122 | /** | |
4beb4867 BVA |
7123 | * _scsih_pcie_device_status_change_event_debug - debug for device event |
7124 | * @ioc: ? | |
4318c734 SPS |
7125 | * @event_data: event data payload |
7126 | * Context: user. | |
4318c734 SPS |
7127 | */ |
7128 | static void | |
7129 | _scsih_pcie_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
7130 | Mpi26EventDataPCIeDeviceStatusChange_t *event_data) | |
7131 | { | |
7132 | char *reason_str = NULL; | |
7133 | ||
7134 | switch (event_data->ReasonCode) { | |
7135 | case MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA: | |
7136 | reason_str = "smart data"; | |
7137 | break; | |
7138 | case MPI26_EVENT_PCIDEV_STAT_RC_UNSUPPORTED: | |
7139 | reason_str = "unsupported device discovered"; | |
7140 | break; | |
7141 | case MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET: | |
7142 | reason_str = "internal device reset"; | |
7143 | break; | |
7144 | case MPI26_EVENT_PCIDEV_STAT_RC_TASK_ABORT_INTERNAL: | |
7145 | reason_str = "internal task abort"; | |
7146 | break; | |
7147 | case MPI26_EVENT_PCIDEV_STAT_RC_ABORT_TASK_SET_INTERNAL: | |
7148 | reason_str = "internal task abort set"; | |
7149 | break; | |
7150 | case MPI26_EVENT_PCIDEV_STAT_RC_CLEAR_TASK_SET_INTERNAL: | |
7151 | reason_str = "internal clear task set"; | |
7152 | break; | |
7153 | case MPI26_EVENT_PCIDEV_STAT_RC_QUERY_TASK_INTERNAL: | |
7154 | reason_str = "internal query task"; | |
7155 | break; | |
7156 | case MPI26_EVENT_PCIDEV_STAT_RC_DEV_INIT_FAILURE: | |
7157 | reason_str = "device init failure"; | |
7158 | break; | |
7159 | case MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET: | |
7160 | reason_str = "internal device reset complete"; | |
7161 | break; | |
7162 | case MPI26_EVENT_PCIDEV_STAT_RC_CMP_TASK_ABORT_INTERNAL: | |
7163 | reason_str = "internal task abort complete"; | |
7164 | break; | |
7165 | case MPI26_EVENT_PCIDEV_STAT_RC_ASYNC_NOTIFICATION: | |
7166 | reason_str = "internal async notification"; | |
7167 | break; | |
c1a6c5ac C |
7168 | case MPI26_EVENT_PCIDEV_STAT_RC_PCIE_HOT_RESET_FAILED: |
7169 | reason_str = "pcie hot reset failed"; | |
7170 | break; | |
4318c734 SPS |
7171 | default: |
7172 | reason_str = "unknown reason"; | |
7173 | break; | |
7174 | } | |
7175 | ||
919d8a3f JP |
7176 | ioc_info(ioc, "PCIE device status change: (%s)\n" |
7177 | "\thandle(0x%04x), WWID(0x%016llx), tag(%d)", | |
7178 | reason_str, le16_to_cpu(event_data->DevHandle), | |
7179 | (u64)le64_to_cpu(event_data->WWID), | |
7180 | le16_to_cpu(event_data->TaskTag)); | |
4318c734 | 7181 | if (event_data->ReasonCode == MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA) |
919d8a3f | 7182 | pr_cont(", ASC(0x%x), ASCQ(0x%x)\n", |
4318c734 | 7183 | event_data->ASC, event_data->ASCQ); |
919d8a3f | 7184 | pr_cont("\n"); |
4318c734 SPS |
7185 | } |
7186 | ||
7187 | /** | |
7188 | * _scsih_pcie_device_status_change_event - handle device status | |
7189 | * change | |
7190 | * @ioc: per adapter object | |
7191 | * @fw_event: The fw_event_work object | |
7192 | * Context: user. | |
4318c734 SPS |
7193 | */ |
7194 | static void | |
7195 | _scsih_pcie_device_status_change_event(struct MPT3SAS_ADAPTER *ioc, | |
7196 | struct fw_event_work *fw_event) | |
7197 | { | |
7198 | struct MPT3SAS_TARGET *target_priv_data; | |
7199 | struct _pcie_device *pcie_device; | |
7200 | u64 wwid; | |
7201 | unsigned long flags; | |
7202 | Mpi26EventDataPCIeDeviceStatusChange_t *event_data = | |
7203 | (Mpi26EventDataPCIeDeviceStatusChange_t *)fw_event->event_data; | |
7204 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) | |
7205 | _scsih_pcie_device_status_change_event_debug(ioc, | |
7206 | event_data); | |
7207 | ||
7208 | if (event_data->ReasonCode != | |
7209 | MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET && | |
7210 | event_data->ReasonCode != | |
7211 | MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET) | |
7212 | return; | |
7213 | ||
7214 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
7215 | wwid = le64_to_cpu(event_data->WWID); | |
7216 | pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid); | |
7217 | ||
7218 | if (!pcie_device || !pcie_device->starget) | |
7219 | goto out; | |
7220 | ||
7221 | target_priv_data = pcie_device->starget->hostdata; | |
7222 | if (!target_priv_data) | |
7223 | goto out; | |
7224 | ||
7225 | if (event_data->ReasonCode == | |
7226 | MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET) | |
7227 | target_priv_data->tm_busy = 1; | |
7228 | else | |
7229 | target_priv_data->tm_busy = 0; | |
7230 | out: | |
7231 | if (pcie_device) | |
7232 | pcie_device_put(pcie_device); | |
7233 | ||
7234 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
7235 | } | |
7236 | ||
f92363d1 SR |
7237 | /** |
7238 | * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure | |
7239 | * event | |
7240 | * @ioc: per adapter object | |
7241 | * @event_data: event data payload | |
7242 | * Context: user. | |
f92363d1 SR |
7243 | */ |
7244 | static void | |
7245 | _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
7246 | Mpi2EventDataSasEnclDevStatusChange_t *event_data) | |
7247 | { | |
7248 | char *reason_str = NULL; | |
7249 | ||
7250 | switch (event_data->ReasonCode) { | |
7251 | case MPI2_EVENT_SAS_ENCL_RC_ADDED: | |
7252 | reason_str = "enclosure add"; | |
7253 | break; | |
7254 | case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING: | |
7255 | reason_str = "enclosure remove"; | |
7256 | break; | |
7257 | default: | |
7258 | reason_str = "unknown reason"; | |
7259 | break; | |
7260 | } | |
7261 | ||
919d8a3f JP |
7262 | ioc_info(ioc, "enclosure status change: (%s)\n" |
7263 | "\thandle(0x%04x), enclosure logical id(0x%016llx) number slots(%d)\n", | |
7264 | reason_str, | |
7265 | le16_to_cpu(event_data->EnclosureHandle), | |
7266 | (u64)le64_to_cpu(event_data->EnclosureLogicalID), | |
7267 | le16_to_cpu(event_data->StartSlot)); | |
f92363d1 | 7268 | } |
f92363d1 SR |
7269 | |
7270 | /** | |
7271 | * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events | |
7272 | * @ioc: per adapter object | |
7273 | * @fw_event: The fw_event_work object | |
7274 | * Context: user. | |
f92363d1 SR |
7275 | */ |
7276 | static void | |
7277 | _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc, | |
7278 | struct fw_event_work *fw_event) | |
7279 | { | |
22a923c3 C |
7280 | Mpi2ConfigReply_t mpi_reply; |
7281 | struct _enclosure_node *enclosure_dev = NULL; | |
7282 | Mpi2EventDataSasEnclDevStatusChange_t *event_data = | |
7283 | (Mpi2EventDataSasEnclDevStatusChange_t *)fw_event->event_data; | |
7284 | int rc; | |
7285 | u16 enclosure_handle = le16_to_cpu(event_data->EnclosureHandle); | |
7286 | ||
f92363d1 SR |
7287 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
7288 | _scsih_sas_enclosure_dev_status_change_event_debug(ioc, | |
35b62362 | 7289 | (Mpi2EventDataSasEnclDevStatusChange_t *) |
f92363d1 | 7290 | fw_event->event_data); |
22a923c3 C |
7291 | if (ioc->shost_recovery) |
7292 | return; | |
7293 | ||
7294 | if (enclosure_handle) | |
7295 | enclosure_dev = | |
7296 | mpt3sas_scsih_enclosure_find_by_handle(ioc, | |
7297 | enclosure_handle); | |
7298 | switch (event_data->ReasonCode) { | |
7299 | case MPI2_EVENT_SAS_ENCL_RC_ADDED: | |
7300 | if (!enclosure_dev) { | |
7301 | enclosure_dev = | |
7302 | kzalloc(sizeof(struct _enclosure_node), | |
7303 | GFP_KERNEL); | |
7304 | if (!enclosure_dev) { | |
919d8a3f JP |
7305 | ioc_info(ioc, "failure at %s:%d/%s()!\n", |
7306 | __FILE__, __LINE__, __func__); | |
22a923c3 C |
7307 | return; |
7308 | } | |
7309 | rc = mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
7310 | &enclosure_dev->pg0, | |
7311 | MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
7312 | enclosure_handle); | |
7313 | ||
7314 | if (rc || (le16_to_cpu(mpi_reply.IOCStatus) & | |
7315 | MPI2_IOCSTATUS_MASK)) { | |
7316 | kfree(enclosure_dev); | |
7317 | return; | |
7318 | } | |
7319 | ||
7320 | list_add_tail(&enclosure_dev->list, | |
7321 | &ioc->enclosure_list); | |
7322 | } | |
7323 | break; | |
7324 | case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING: | |
7325 | if (enclosure_dev) { | |
7326 | list_del(&enclosure_dev->list); | |
7327 | kfree(enclosure_dev); | |
7328 | } | |
7329 | break; | |
7330 | default: | |
7331 | break; | |
7332 | } | |
f92363d1 SR |
7333 | } |
7334 | ||
7335 | /** | |
7336 | * _scsih_sas_broadcast_primitive_event - handle broadcast events | |
7337 | * @ioc: per adapter object | |
7338 | * @fw_event: The fw_event_work object | |
7339 | * Context: user. | |
f92363d1 SR |
7340 | */ |
7341 | static void | |
7342 | _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc, | |
7343 | struct fw_event_work *fw_event) | |
7344 | { | |
7345 | struct scsi_cmnd *scmd; | |
7346 | struct scsi_device *sdev; | |
6da999fe | 7347 | struct scsiio_tracker *st; |
f92363d1 SR |
7348 | u16 smid, handle; |
7349 | u32 lun; | |
7350 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
7351 | u32 termination_count; | |
7352 | u32 query_count; | |
7353 | Mpi2SCSITaskManagementReply_t *mpi_reply; | |
35b62362 JL |
7354 | Mpi2EventDataSasBroadcastPrimitive_t *event_data = |
7355 | (Mpi2EventDataSasBroadcastPrimitive_t *) | |
7356 | fw_event->event_data; | |
f92363d1 SR |
7357 | u16 ioc_status; |
7358 | unsigned long flags; | |
7359 | int r; | |
7360 | u8 max_retries = 0; | |
7361 | u8 task_abort_retries; | |
7362 | ||
7363 | mutex_lock(&ioc->tm_cmds.mutex); | |
919d8a3f JP |
7364 | ioc_info(ioc, "%s: enter: phy number(%d), width(%d)\n", |
7365 | __func__, event_data->PhyNum, event_data->PortWidth); | |
f92363d1 SR |
7366 | |
7367 | _scsih_block_io_all_device(ioc); | |
7368 | ||
7369 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7370 | mpi_reply = ioc->tm_cmds.reply; | |
7371 | broadcast_aen_retry: | |
7372 | ||
7373 | /* sanity checks for retrying this loop */ | |
7374 | if (max_retries++ == 5) { | |
919d8a3f | 7375 | dewtprintk(ioc, ioc_info(ioc, "%s: giving up\n", __func__)); |
f92363d1 SR |
7376 | goto out; |
7377 | } else if (max_retries > 1) | |
919d8a3f JP |
7378 | dewtprintk(ioc, |
7379 | ioc_info(ioc, "%s: %d retry\n", | |
7380 | __func__, max_retries - 1)); | |
f92363d1 SR |
7381 | |
7382 | termination_count = 0; | |
7383 | query_count = 0; | |
7384 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { | |
7385 | if (ioc->shost_recovery) | |
7386 | goto out; | |
dbec4c90 | 7387 | scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid); |
f92363d1 SR |
7388 | if (!scmd) |
7389 | continue; | |
dbec4c90 | 7390 | st = scsi_cmd_priv(scmd); |
f92363d1 SR |
7391 | sdev = scmd->device; |
7392 | sas_device_priv_data = sdev->hostdata; | |
7393 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) | |
7394 | continue; | |
7395 | /* skip hidden raid components */ | |
7396 | if (sas_device_priv_data->sas_target->flags & | |
7397 | MPT_TARGET_FLAGS_RAID_COMPONENT) | |
7398 | continue; | |
7399 | /* skip volumes */ | |
7400 | if (sas_device_priv_data->sas_target->flags & | |
7401 | MPT_TARGET_FLAGS_VOLUME) | |
7402 | continue; | |
999c8513 C |
7403 | /* skip PCIe devices */ |
7404 | if (sas_device_priv_data->sas_target->flags & | |
7405 | MPT_TARGET_FLAGS_PCIE_DEVICE) | |
7406 | continue; | |
f92363d1 SR |
7407 | |
7408 | handle = sas_device_priv_data->sas_target->handle; | |
7409 | lun = sas_device_priv_data->lun; | |
7410 | query_count++; | |
7411 | ||
7412 | if (ioc->shost_recovery) | |
7413 | goto out; | |
7414 | ||
7415 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
6da999fe | 7416 | r = mpt3sas_scsih_issue_tm(ioc, handle, lun, |
dbec4c90 | 7417 | MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, st->smid, |
c1a6c5ac | 7418 | st->msix_io, 30, 0); |
f92363d1 SR |
7419 | if (r == FAILED) { |
7420 | sdev_printk(KERN_WARNING, sdev, | |
7421 | "mpt3sas_scsih_issue_tm: FAILED when sending " | |
7422 | "QUERY_TASK: scmd(%p)\n", scmd); | |
7423 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7424 | goto broadcast_aen_retry; | |
7425 | } | |
7426 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) | |
7427 | & MPI2_IOCSTATUS_MASK; | |
7428 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
7429 | sdev_printk(KERN_WARNING, sdev, | |
7430 | "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n", | |
7431 | ioc_status, scmd); | |
7432 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7433 | goto broadcast_aen_retry; | |
7434 | } | |
7435 | ||
7436 | /* see if IO is still owned by IOC and target */ | |
7437 | if (mpi_reply->ResponseCode == | |
7438 | MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED || | |
7439 | mpi_reply->ResponseCode == | |
7440 | MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) { | |
7441 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7442 | continue; | |
7443 | } | |
7444 | task_abort_retries = 0; | |
7445 | tm_retry: | |
7446 | if (task_abort_retries++ == 60) { | |
919d8a3f JP |
7447 | dewtprintk(ioc, |
7448 | ioc_info(ioc, "%s: ABORT_TASK: giving up\n", | |
7449 | __func__)); | |
f92363d1 SR |
7450 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
7451 | goto broadcast_aen_retry; | |
7452 | } | |
7453 | ||
7454 | if (ioc->shost_recovery) | |
7455 | goto out_no_lock; | |
7456 | ||
6da999fe | 7457 | r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->lun, |
dbec4c90 | 7458 | MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, st->smid, |
c1a6c5ac | 7459 | st->msix_io, 30, 0); |
dbec4c90 | 7460 | if (r == FAILED || st->cb_idx != 0xFF) { |
f92363d1 SR |
7461 | sdev_printk(KERN_WARNING, sdev, |
7462 | "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : " | |
7463 | "scmd(%p)\n", scmd); | |
7464 | goto tm_retry; | |
7465 | } | |
7466 | ||
7467 | if (task_abort_retries > 1) | |
7468 | sdev_printk(KERN_WARNING, sdev, | |
7469 | "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):" | |
7470 | " scmd(%p)\n", | |
7471 | task_abort_retries - 1, scmd); | |
7472 | ||
7473 | termination_count += le32_to_cpu(mpi_reply->TerminationCount); | |
7474 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7475 | } | |
7476 | ||
7477 | if (ioc->broadcast_aen_pending) { | |
919d8a3f JP |
7478 | dewtprintk(ioc, |
7479 | ioc_info(ioc, | |
7480 | "%s: loop back due to pending AEN\n", | |
7481 | __func__)); | |
f92363d1 SR |
7482 | ioc->broadcast_aen_pending = 0; |
7483 | goto broadcast_aen_retry; | |
7484 | } | |
7485 | ||
7486 | out: | |
7487 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
7488 | out_no_lock: | |
7489 | ||
919d8a3f JP |
7490 | dewtprintk(ioc, |
7491 | ioc_info(ioc, "%s - exit, query_count = %d termination_count = %d\n", | |
7492 | __func__, query_count, termination_count)); | |
f92363d1 SR |
7493 | |
7494 | ioc->broadcast_aen_busy = 0; | |
7495 | if (!ioc->shost_recovery) | |
7496 | _scsih_ublock_io_all_device(ioc); | |
7497 | mutex_unlock(&ioc->tm_cmds.mutex); | |
7498 | } | |
7499 | ||
7500 | /** | |
7501 | * _scsih_sas_discovery_event - handle discovery events | |
7502 | * @ioc: per adapter object | |
7503 | * @fw_event: The fw_event_work object | |
7504 | * Context: user. | |
f92363d1 SR |
7505 | */ |
7506 | static void | |
7507 | _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc, | |
7508 | struct fw_event_work *fw_event) | |
7509 | { | |
35b62362 JL |
7510 | Mpi2EventDataSasDiscovery_t *event_data = |
7511 | (Mpi2EventDataSasDiscovery_t *) fw_event->event_data; | |
f92363d1 | 7512 | |
f92363d1 | 7513 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) { |
919d8a3f JP |
7514 | ioc_info(ioc, "discovery event: (%s)", |
7515 | event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED ? | |
7516 | "start" : "stop"); | |
af009411 | 7517 | if (event_data->DiscoveryStatus) |
919d8a3f JP |
7518 | pr_cont("discovery_status(0x%08x)", |
7519 | le32_to_cpu(event_data->DiscoveryStatus)); | |
7520 | pr_cont("\n"); | |
f92363d1 | 7521 | } |
f92363d1 SR |
7522 | |
7523 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED && | |
7524 | !ioc->sas_hba.num_phys) { | |
7525 | if (disable_discovery > 0 && ioc->shost_recovery) { | |
7526 | /* Wait for the reset to complete */ | |
7527 | while (ioc->shost_recovery) | |
7528 | ssleep(1); | |
7529 | } | |
7530 | _scsih_sas_host_add(ioc); | |
7531 | } | |
7532 | } | |
7533 | ||
95540b8e C |
7534 | /** |
7535 | * _scsih_sas_device_discovery_error_event - display SAS device discovery error | |
7536 | * events | |
7537 | * @ioc: per adapter object | |
7538 | * @fw_event: The fw_event_work object | |
7539 | * Context: user. | |
95540b8e C |
7540 | */ |
7541 | static void | |
7542 | _scsih_sas_device_discovery_error_event(struct MPT3SAS_ADAPTER *ioc, | |
7543 | struct fw_event_work *fw_event) | |
7544 | { | |
7545 | Mpi25EventDataSasDeviceDiscoveryError_t *event_data = | |
7546 | (Mpi25EventDataSasDeviceDiscoveryError_t *)fw_event->event_data; | |
7547 | ||
7548 | switch (event_data->ReasonCode) { | |
7549 | case MPI25_EVENT_SAS_DISC_ERR_SMP_FAILED: | |
919d8a3f JP |
7550 | ioc_warn(ioc, "SMP command sent to the expander (handle:0x%04x, sas_address:0x%016llx, physical_port:0x%02x) has failed\n", |
7551 | le16_to_cpu(event_data->DevHandle), | |
7552 | (u64)le64_to_cpu(event_data->SASAddress), | |
7553 | event_data->PhysicalPort); | |
95540b8e C |
7554 | break; |
7555 | case MPI25_EVENT_SAS_DISC_ERR_SMP_TIMEOUT: | |
919d8a3f JP |
7556 | ioc_warn(ioc, "SMP command sent to the expander (handle:0x%04x, sas_address:0x%016llx, physical_port:0x%02x) has timed out\n", |
7557 | le16_to_cpu(event_data->DevHandle), | |
7558 | (u64)le64_to_cpu(event_data->SASAddress), | |
7559 | event_data->PhysicalPort); | |
95540b8e C |
7560 | break; |
7561 | default: | |
7562 | break; | |
7563 | } | |
7564 | } | |
7565 | ||
4318c734 SPS |
7566 | /** |
7567 | * _scsih_pcie_enumeration_event - handle enumeration events | |
7568 | * @ioc: per adapter object | |
7569 | * @fw_event: The fw_event_work object | |
7570 | * Context: user. | |
4318c734 SPS |
7571 | */ |
7572 | static void | |
7573 | _scsih_pcie_enumeration_event(struct MPT3SAS_ADAPTER *ioc, | |
7574 | struct fw_event_work *fw_event) | |
7575 | { | |
7576 | Mpi26EventDataPCIeEnumeration_t *event_data = | |
7577 | (Mpi26EventDataPCIeEnumeration_t *)fw_event->event_data; | |
7578 | ||
6767aced DC |
7579 | if (!(ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)) |
7580 | return; | |
7581 | ||
919d8a3f JP |
7582 | ioc_info(ioc, "pcie enumeration event: (%s) Flag 0x%02x", |
7583 | (event_data->ReasonCode == MPI26_EVENT_PCIE_ENUM_RC_STARTED) ? | |
7584 | "started" : "completed", | |
7585 | event_data->Flags); | |
4318c734 | 7586 | if (event_data->EnumerationStatus) |
6767aced DC |
7587 | pr_cont("enumeration_status(0x%08x)", |
7588 | le32_to_cpu(event_data->EnumerationStatus)); | |
7589 | pr_cont("\n"); | |
4318c734 SPS |
7590 | } |
7591 | ||
f92363d1 SR |
7592 | /** |
7593 | * _scsih_ir_fastpath - turn on fastpath for IR physdisk | |
7594 | * @ioc: per adapter object | |
7595 | * @handle: device handle for physical disk | |
7596 | * @phys_disk_num: physical disk number | |
7597 | * | |
4beb4867 | 7598 | * Return: 0 for success, else failure. |
f92363d1 SR |
7599 | */ |
7600 | static int | |
7601 | _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num) | |
7602 | { | |
7603 | Mpi2RaidActionRequest_t *mpi_request; | |
7604 | Mpi2RaidActionReply_t *mpi_reply; | |
7605 | u16 smid; | |
7606 | u8 issue_reset = 0; | |
7607 | int rc = 0; | |
7608 | u16 ioc_status; | |
7609 | u32 log_info; | |
7610 | ||
c84b06a4 SR |
7611 | if (ioc->hba_mpi_version_belonged == MPI2_VERSION) |
7612 | return rc; | |
7613 | ||
f92363d1 SR |
7614 | mutex_lock(&ioc->scsih_cmds.mutex); |
7615 | ||
7616 | if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) { | |
919d8a3f | 7617 | ioc_err(ioc, "%s: scsih_cmd in use\n", __func__); |
f92363d1 SR |
7618 | rc = -EAGAIN; |
7619 | goto out; | |
7620 | } | |
7621 | ioc->scsih_cmds.status = MPT3_CMD_PENDING; | |
7622 | ||
7623 | smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx); | |
7624 | if (!smid) { | |
919d8a3f | 7625 | ioc_err(ioc, "%s: failed obtaining a smid\n", __func__); |
f92363d1 SR |
7626 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; |
7627 | rc = -EAGAIN; | |
7628 | goto out; | |
7629 | } | |
7630 | ||
7631 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
7632 | ioc->scsih_cmds.smid = smid; | |
7633 | memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t)); | |
7634 | ||
7635 | mpi_request->Function = MPI2_FUNCTION_RAID_ACTION; | |
7636 | mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN; | |
7637 | mpi_request->PhysDiskNum = phys_disk_num; | |
7638 | ||
919d8a3f JP |
7639 | dewtprintk(ioc, |
7640 | ioc_info(ioc, "IR RAID_ACTION: turning fast path on for handle(0x%04x), phys_disk_num (0x%02x)\n", | |
7641 | handle, phys_disk_num)); | |
f92363d1 SR |
7642 | |
7643 | init_completion(&ioc->scsih_cmds.done); | |
078a4cc1 | 7644 | ioc->put_smid_default(ioc, smid); |
f92363d1 SR |
7645 | wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ); |
7646 | ||
7647 | if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) { | |
d37306ca C |
7648 | issue_reset = |
7649 | mpt3sas_base_check_cmd_timeout(ioc, | |
7650 | ioc->scsih_cmds.status, mpi_request, | |
7651 | sizeof(Mpi2RaidActionRequest_t)/4); | |
f92363d1 SR |
7652 | rc = -EFAULT; |
7653 | goto out; | |
7654 | } | |
7655 | ||
7656 | if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) { | |
7657 | ||
7658 | mpi_reply = ioc->scsih_cmds.reply; | |
7659 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); | |
7660 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) | |
7661 | log_info = le32_to_cpu(mpi_reply->IOCLogInfo); | |
7662 | else | |
7663 | log_info = 0; | |
7664 | ioc_status &= MPI2_IOCSTATUS_MASK; | |
7665 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
919d8a3f JP |
7666 | dewtprintk(ioc, |
7667 | ioc_info(ioc, "IR RAID_ACTION: failed: ioc_status(0x%04x), loginfo(0x%08x)!!!\n", | |
7668 | ioc_status, log_info)); | |
f92363d1 SR |
7669 | rc = -EFAULT; |
7670 | } else | |
919d8a3f JP |
7671 | dewtprintk(ioc, |
7672 | ioc_info(ioc, "IR RAID_ACTION: completed successfully\n")); | |
f92363d1 SR |
7673 | } |
7674 | ||
7675 | out: | |
7676 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
7677 | mutex_unlock(&ioc->scsih_cmds.mutex); | |
7678 | ||
7679 | if (issue_reset) | |
98c56ad3 | 7680 | mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
f92363d1 SR |
7681 | return rc; |
7682 | } | |
7683 | ||
7684 | /** | |
7685 | * _scsih_reprobe_lun - reprobing lun | |
7686 | * @sdev: scsi device struct | |
7687 | * @no_uld_attach: sdev->no_uld_attach flag setting | |
7688 | * | |
7689 | **/ | |
7690 | static void | |
7691 | _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach) | |
7692 | { | |
f92363d1 SR |
7693 | sdev->no_uld_attach = no_uld_attach ? 1 : 0; |
7694 | sdev_printk(KERN_INFO, sdev, "%s raid component\n", | |
6c7abffc | 7695 | sdev->no_uld_attach ? "hiding" : "exposing"); |
8bbb1cf6 | 7696 | WARN_ON(scsi_device_reprobe(sdev)); |
f92363d1 SR |
7697 | } |
7698 | ||
7699 | /** | |
7700 | * _scsih_sas_volume_add - add new volume | |
7701 | * @ioc: per adapter object | |
7702 | * @element: IR config element data | |
7703 | * Context: user. | |
f92363d1 SR |
7704 | */ |
7705 | static void | |
7706 | _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc, | |
7707 | Mpi2EventIrConfigElement_t *element) | |
7708 | { | |
7709 | struct _raid_device *raid_device; | |
7710 | unsigned long flags; | |
7711 | u64 wwid; | |
7712 | u16 handle = le16_to_cpu(element->VolDevHandle); | |
7713 | int rc; | |
7714 | ||
7715 | mpt3sas_config_get_volume_wwid(ioc, handle, &wwid); | |
7716 | if (!wwid) { | |
919d8a3f JP |
7717 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
7718 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
7719 | return; |
7720 | } | |
7721 | ||
7722 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
7723 | raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid); | |
7724 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
7725 | ||
7726 | if (raid_device) | |
7727 | return; | |
7728 | ||
7729 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); | |
7730 | if (!raid_device) { | |
919d8a3f JP |
7731 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
7732 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
7733 | return; |
7734 | } | |
7735 | ||
7736 | raid_device->id = ioc->sas_id++; | |
7737 | raid_device->channel = RAID_CHANNEL; | |
7738 | raid_device->handle = handle; | |
7739 | raid_device->wwid = wwid; | |
7740 | _scsih_raid_device_add(ioc, raid_device); | |
7741 | if (!ioc->wait_for_discovery_to_complete) { | |
7742 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
7743 | raid_device->id, 0); | |
7744 | if (rc) | |
7745 | _scsih_raid_device_remove(ioc, raid_device); | |
7746 | } else { | |
7747 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
7748 | _scsih_determine_boot_device(ioc, raid_device, 1); | |
7749 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
7750 | } | |
7751 | } | |
7752 | ||
7753 | /** | |
7754 | * _scsih_sas_volume_delete - delete volume | |
7755 | * @ioc: per adapter object | |
7756 | * @handle: volume device handle | |
7757 | * Context: user. | |
f92363d1 SR |
7758 | */ |
7759 | static void | |
7760 | _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
7761 | { | |
7762 | struct _raid_device *raid_device; | |
7763 | unsigned long flags; | |
7764 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
7765 | struct scsi_target *starget = NULL; | |
7766 | ||
7767 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
c84b06a4 | 7768 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
7769 | if (raid_device) { |
7770 | if (raid_device->starget) { | |
7771 | starget = raid_device->starget; | |
7772 | sas_target_priv_data = starget->hostdata; | |
7773 | sas_target_priv_data->deleted = 1; | |
7774 | } | |
919d8a3f JP |
7775 | ioc_info(ioc, "removing handle(0x%04x), wwid(0x%016llx)\n", |
7776 | raid_device->handle, (u64)raid_device->wwid); | |
f92363d1 SR |
7777 | list_del(&raid_device->list); |
7778 | kfree(raid_device); | |
7779 | } | |
7780 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
7781 | if (starget) | |
7782 | scsi_remove_target(&starget->dev); | |
7783 | } | |
7784 | ||
7785 | /** | |
7786 | * _scsih_sas_pd_expose - expose pd component to /dev/sdX | |
7787 | * @ioc: per adapter object | |
7788 | * @element: IR config element data | |
7789 | * Context: user. | |
f92363d1 SR |
7790 | */ |
7791 | static void | |
7792 | _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc, | |
7793 | Mpi2EventIrConfigElement_t *element) | |
7794 | { | |
7795 | struct _sas_device *sas_device; | |
7796 | struct scsi_target *starget = NULL; | |
7797 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
7798 | unsigned long flags; | |
7799 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | |
7800 | ||
7801 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 | 7802 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
7803 | if (sas_device) { |
7804 | sas_device->volume_handle = 0; | |
7805 | sas_device->volume_wwid = 0; | |
7806 | clear_bit(handle, ioc->pd_handles); | |
7807 | if (sas_device->starget && sas_device->starget->hostdata) { | |
7808 | starget = sas_device->starget; | |
7809 | sas_target_priv_data = starget->hostdata; | |
7810 | sas_target_priv_data->flags &= | |
7811 | ~MPT_TARGET_FLAGS_RAID_COMPONENT; | |
7812 | } | |
7813 | } | |
7814 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
7815 | if (!sas_device) | |
7816 | return; | |
7817 | ||
7818 | /* exposing raid component */ | |
7819 | if (starget) | |
7820 | starget_for_each_device(starget, NULL, _scsih_reprobe_lun); | |
d1cb5e49 SR |
7821 | |
7822 | sas_device_put(sas_device); | |
f92363d1 SR |
7823 | } |
7824 | ||
7825 | /** | |
7826 | * _scsih_sas_pd_hide - hide pd component from /dev/sdX | |
7827 | * @ioc: per adapter object | |
7828 | * @element: IR config element data | |
7829 | * Context: user. | |
f92363d1 SR |
7830 | */ |
7831 | static void | |
7832 | _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc, | |
7833 | Mpi2EventIrConfigElement_t *element) | |
7834 | { | |
7835 | struct _sas_device *sas_device; | |
7836 | struct scsi_target *starget = NULL; | |
7837 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
7838 | unsigned long flags; | |
7839 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | |
7840 | u16 volume_handle = 0; | |
7841 | u64 volume_wwid = 0; | |
7842 | ||
7843 | mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle); | |
7844 | if (volume_handle) | |
7845 | mpt3sas_config_get_volume_wwid(ioc, volume_handle, | |
7846 | &volume_wwid); | |
7847 | ||
7848 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 | 7849 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
7850 | if (sas_device) { |
7851 | set_bit(handle, ioc->pd_handles); | |
7852 | if (sas_device->starget && sas_device->starget->hostdata) { | |
7853 | starget = sas_device->starget; | |
7854 | sas_target_priv_data = starget->hostdata; | |
7855 | sas_target_priv_data->flags |= | |
7856 | MPT_TARGET_FLAGS_RAID_COMPONENT; | |
7857 | sas_device->volume_handle = volume_handle; | |
7858 | sas_device->volume_wwid = volume_wwid; | |
7859 | } | |
7860 | } | |
7861 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
7862 | if (!sas_device) | |
7863 | return; | |
7864 | ||
7865 | /* hiding raid component */ | |
7866 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); | |
c84b06a4 | 7867 | |
f92363d1 SR |
7868 | if (starget) |
7869 | starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun); | |
d1cb5e49 SR |
7870 | |
7871 | sas_device_put(sas_device); | |
f92363d1 SR |
7872 | } |
7873 | ||
7874 | /** | |
7875 | * _scsih_sas_pd_delete - delete pd component | |
7876 | * @ioc: per adapter object | |
7877 | * @element: IR config element data | |
7878 | * Context: user. | |
f92363d1 SR |
7879 | */ |
7880 | static void | |
7881 | _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc, | |
7882 | Mpi2EventIrConfigElement_t *element) | |
7883 | { | |
7884 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | |
7885 | ||
7886 | _scsih_device_remove_by_handle(ioc, handle); | |
7887 | } | |
7888 | ||
7889 | /** | |
7890 | * _scsih_sas_pd_add - remove pd component | |
7891 | * @ioc: per adapter object | |
7892 | * @element: IR config element data | |
7893 | * Context: user. | |
f92363d1 SR |
7894 | */ |
7895 | static void | |
7896 | _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc, | |
7897 | Mpi2EventIrConfigElement_t *element) | |
7898 | { | |
7899 | struct _sas_device *sas_device; | |
f92363d1 SR |
7900 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
7901 | Mpi2ConfigReply_t mpi_reply; | |
7902 | Mpi2SasDevicePage0_t sas_device_pg0; | |
7903 | u32 ioc_status; | |
7904 | u64 sas_address; | |
7905 | u16 parent_handle; | |
7906 | ||
7907 | set_bit(handle, ioc->pd_handles); | |
7908 | ||
d1cb5e49 | 7909 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
7910 | if (sas_device) { |
7911 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); | |
d1cb5e49 | 7912 | sas_device_put(sas_device); |
f92363d1 SR |
7913 | return; |
7914 | } | |
7915 | ||
7916 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
7917 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
919d8a3f JP |
7918 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
7919 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
7920 | return; |
7921 | } | |
7922 | ||
7923 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
7924 | MPI2_IOCSTATUS_MASK; | |
7925 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
919d8a3f JP |
7926 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
7927 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
7928 | return; |
7929 | } | |
7930 | ||
7931 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | |
7932 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) | |
7933 | mpt3sas_transport_update_links(ioc, sas_address, handle, | |
7934 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | |
7935 | ||
7936 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); | |
7937 | _scsih_add_device(ioc, handle, 0, 1); | |
7938 | } | |
7939 | ||
f92363d1 SR |
7940 | /** |
7941 | * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events | |
7942 | * @ioc: per adapter object | |
7943 | * @event_data: event data payload | |
7944 | * Context: user. | |
f92363d1 SR |
7945 | */ |
7946 | static void | |
7947 | _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
7948 | Mpi2EventDataIrConfigChangeList_t *event_data) | |
7949 | { | |
7950 | Mpi2EventIrConfigElement_t *element; | |
7951 | u8 element_type; | |
7952 | int i; | |
7953 | char *reason_str = NULL, *element_str = NULL; | |
7954 | ||
7955 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
7956 | ||
919d8a3f JP |
7957 | ioc_info(ioc, "raid config change: (%s), elements(%d)\n", |
7958 | le32_to_cpu(event_data->Flags) & MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG ? | |
7959 | "foreign" : "native", | |
7960 | event_data->NumElements); | |
f92363d1 SR |
7961 | for (i = 0; i < event_data->NumElements; i++, element++) { |
7962 | switch (element->ReasonCode) { | |
7963 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: | |
7964 | reason_str = "add"; | |
7965 | break; | |
7966 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: | |
7967 | reason_str = "remove"; | |
7968 | break; | |
7969 | case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE: | |
7970 | reason_str = "no change"; | |
7971 | break; | |
7972 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: | |
7973 | reason_str = "hide"; | |
7974 | break; | |
7975 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: | |
7976 | reason_str = "unhide"; | |
7977 | break; | |
7978 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: | |
7979 | reason_str = "volume_created"; | |
7980 | break; | |
7981 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: | |
7982 | reason_str = "volume_deleted"; | |
7983 | break; | |
7984 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: | |
7985 | reason_str = "pd_created"; | |
7986 | break; | |
7987 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: | |
7988 | reason_str = "pd_deleted"; | |
7989 | break; | |
7990 | default: | |
7991 | reason_str = "unknown reason"; | |
7992 | break; | |
7993 | } | |
7994 | element_type = le16_to_cpu(element->ElementFlags) & | |
7995 | MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK; | |
7996 | switch (element_type) { | |
7997 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT: | |
7998 | element_str = "volume"; | |
7999 | break; | |
8000 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT: | |
8001 | element_str = "phys disk"; | |
8002 | break; | |
8003 | case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT: | |
8004 | element_str = "hot spare"; | |
8005 | break; | |
8006 | default: | |
8007 | element_str = "unknown element"; | |
8008 | break; | |
8009 | } | |
8010 | pr_info("\t(%s:%s), vol handle(0x%04x), " \ | |
8011 | "pd handle(0x%04x), pd num(0x%02x)\n", element_str, | |
8012 | reason_str, le16_to_cpu(element->VolDevHandle), | |
8013 | le16_to_cpu(element->PhysDiskDevHandle), | |
8014 | element->PhysDiskNum); | |
8015 | } | |
8016 | } | |
f92363d1 SR |
8017 | |
8018 | /** | |
8019 | * _scsih_sas_ir_config_change_event - handle ir configuration change events | |
8020 | * @ioc: per adapter object | |
8021 | * @fw_event: The fw_event_work object | |
8022 | * Context: user. | |
f92363d1 SR |
8023 | */ |
8024 | static void | |
8025 | _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc, | |
8026 | struct fw_event_work *fw_event) | |
8027 | { | |
8028 | Mpi2EventIrConfigElement_t *element; | |
8029 | int i; | |
8030 | u8 foreign_config; | |
35b62362 JL |
8031 | Mpi2EventDataIrConfigChangeList_t *event_data = |
8032 | (Mpi2EventDataIrConfigChangeList_t *) | |
8033 | fw_event->event_data; | |
f92363d1 | 8034 | |
7786ab6a SR |
8035 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) && |
8036 | (!ioc->hide_ir_msg)) | |
f92363d1 SR |
8037 | _scsih_sas_ir_config_change_event_debug(ioc, event_data); |
8038 | ||
f92363d1 SR |
8039 | foreign_config = (le32_to_cpu(event_data->Flags) & |
8040 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0; | |
8041 | ||
8042 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
c84b06a4 SR |
8043 | if (ioc->shost_recovery && |
8044 | ioc->hba_mpi_version_belonged != MPI2_VERSION) { | |
f92363d1 SR |
8045 | for (i = 0; i < event_data->NumElements; i++, element++) { |
8046 | if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE) | |
8047 | _scsih_ir_fastpath(ioc, | |
8048 | le16_to_cpu(element->PhysDiskDevHandle), | |
8049 | element->PhysDiskNum); | |
8050 | } | |
8051 | return; | |
8052 | } | |
7786ab6a | 8053 | |
f92363d1 SR |
8054 | for (i = 0; i < event_data->NumElements; i++, element++) { |
8055 | ||
8056 | switch (element->ReasonCode) { | |
8057 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: | |
8058 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: | |
8059 | if (!foreign_config) | |
8060 | _scsih_sas_volume_add(ioc, element); | |
8061 | break; | |
8062 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: | |
8063 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: | |
8064 | if (!foreign_config) | |
8065 | _scsih_sas_volume_delete(ioc, | |
8066 | le16_to_cpu(element->VolDevHandle)); | |
8067 | break; | |
8068 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: | |
7786ab6a SR |
8069 | if (!ioc->is_warpdrive) |
8070 | _scsih_sas_pd_hide(ioc, element); | |
f92363d1 SR |
8071 | break; |
8072 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: | |
7786ab6a SR |
8073 | if (!ioc->is_warpdrive) |
8074 | _scsih_sas_pd_expose(ioc, element); | |
f92363d1 SR |
8075 | break; |
8076 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: | |
7786ab6a SR |
8077 | if (!ioc->is_warpdrive) |
8078 | _scsih_sas_pd_add(ioc, element); | |
f92363d1 SR |
8079 | break; |
8080 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: | |
7786ab6a SR |
8081 | if (!ioc->is_warpdrive) |
8082 | _scsih_sas_pd_delete(ioc, element); | |
f92363d1 SR |
8083 | break; |
8084 | } | |
8085 | } | |
8086 | } | |
8087 | ||
8088 | /** | |
8089 | * _scsih_sas_ir_volume_event - IR volume event | |
8090 | * @ioc: per adapter object | |
8091 | * @fw_event: The fw_event_work object | |
8092 | * Context: user. | |
f92363d1 SR |
8093 | */ |
8094 | static void | |
8095 | _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc, | |
8096 | struct fw_event_work *fw_event) | |
8097 | { | |
8098 | u64 wwid; | |
8099 | unsigned long flags; | |
8100 | struct _raid_device *raid_device; | |
8101 | u16 handle; | |
8102 | u32 state; | |
8103 | int rc; | |
35b62362 JL |
8104 | Mpi2EventDataIrVolume_t *event_data = |
8105 | (Mpi2EventDataIrVolume_t *) fw_event->event_data; | |
f92363d1 SR |
8106 | |
8107 | if (ioc->shost_recovery) | |
8108 | return; | |
8109 | ||
8110 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) | |
8111 | return; | |
8112 | ||
8113 | handle = le16_to_cpu(event_data->VolDevHandle); | |
8114 | state = le32_to_cpu(event_data->NewValue); | |
7786ab6a | 8115 | if (!ioc->hide_ir_msg) |
919d8a3f JP |
8116 | dewtprintk(ioc, |
8117 | ioc_info(ioc, "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n", | |
8118 | __func__, handle, | |
8119 | le32_to_cpu(event_data->PreviousValue), | |
8120 | state)); | |
f92363d1 SR |
8121 | switch (state) { |
8122 | case MPI2_RAID_VOL_STATE_MISSING: | |
8123 | case MPI2_RAID_VOL_STATE_FAILED: | |
8124 | _scsih_sas_volume_delete(ioc, handle); | |
8125 | break; | |
8126 | ||
8127 | case MPI2_RAID_VOL_STATE_ONLINE: | |
8128 | case MPI2_RAID_VOL_STATE_DEGRADED: | |
8129 | case MPI2_RAID_VOL_STATE_OPTIMAL: | |
8130 | ||
8131 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
c84b06a4 | 8132 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
8133 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
8134 | ||
8135 | if (raid_device) | |
8136 | break; | |
8137 | ||
8138 | mpt3sas_config_get_volume_wwid(ioc, handle, &wwid); | |
8139 | if (!wwid) { | |
919d8a3f JP |
8140 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
8141 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
8142 | break; |
8143 | } | |
8144 | ||
8145 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); | |
8146 | if (!raid_device) { | |
919d8a3f JP |
8147 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
8148 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
8149 | break; |
8150 | } | |
8151 | ||
8152 | raid_device->id = ioc->sas_id++; | |
8153 | raid_device->channel = RAID_CHANNEL; | |
8154 | raid_device->handle = handle; | |
8155 | raid_device->wwid = wwid; | |
8156 | _scsih_raid_device_add(ioc, raid_device); | |
8157 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
8158 | raid_device->id, 0); | |
8159 | if (rc) | |
8160 | _scsih_raid_device_remove(ioc, raid_device); | |
8161 | break; | |
8162 | ||
8163 | case MPI2_RAID_VOL_STATE_INITIALIZING: | |
8164 | default: | |
8165 | break; | |
8166 | } | |
8167 | } | |
8168 | ||
8169 | /** | |
8170 | * _scsih_sas_ir_physical_disk_event - PD event | |
8171 | * @ioc: per adapter object | |
8172 | * @fw_event: The fw_event_work object | |
8173 | * Context: user. | |
f92363d1 SR |
8174 | */ |
8175 | static void | |
8176 | _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc, | |
8177 | struct fw_event_work *fw_event) | |
8178 | { | |
8179 | u16 handle, parent_handle; | |
8180 | u32 state; | |
8181 | struct _sas_device *sas_device; | |
f92363d1 SR |
8182 | Mpi2ConfigReply_t mpi_reply; |
8183 | Mpi2SasDevicePage0_t sas_device_pg0; | |
8184 | u32 ioc_status; | |
35b62362 JL |
8185 | Mpi2EventDataIrPhysicalDisk_t *event_data = |
8186 | (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data; | |
f92363d1 SR |
8187 | u64 sas_address; |
8188 | ||
8189 | if (ioc->shost_recovery) | |
8190 | return; | |
8191 | ||
8192 | if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED) | |
8193 | return; | |
8194 | ||
8195 | handle = le16_to_cpu(event_data->PhysDiskDevHandle); | |
8196 | state = le32_to_cpu(event_data->NewValue); | |
8197 | ||
7786ab6a | 8198 | if (!ioc->hide_ir_msg) |
919d8a3f JP |
8199 | dewtprintk(ioc, |
8200 | ioc_info(ioc, "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n", | |
8201 | __func__, handle, | |
8202 | le32_to_cpu(event_data->PreviousValue), | |
8203 | state)); | |
7786ab6a | 8204 | |
f92363d1 SR |
8205 | switch (state) { |
8206 | case MPI2_RAID_PD_STATE_ONLINE: | |
8207 | case MPI2_RAID_PD_STATE_DEGRADED: | |
8208 | case MPI2_RAID_PD_STATE_REBUILDING: | |
8209 | case MPI2_RAID_PD_STATE_OPTIMAL: | |
8210 | case MPI2_RAID_PD_STATE_HOT_SPARE: | |
8211 | ||
7786ab6a SR |
8212 | if (!ioc->is_warpdrive) |
8213 | set_bit(handle, ioc->pd_handles); | |
f92363d1 | 8214 | |
d1cb5e49 SR |
8215 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
8216 | if (sas_device) { | |
8217 | sas_device_put(sas_device); | |
f92363d1 | 8218 | return; |
d1cb5e49 | 8219 | } |
f92363d1 SR |
8220 | |
8221 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
8222 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | |
8223 | handle))) { | |
919d8a3f JP |
8224 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
8225 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
8226 | return; |
8227 | } | |
8228 | ||
8229 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8230 | MPI2_IOCSTATUS_MASK; | |
8231 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
919d8a3f JP |
8232 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
8233 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
8234 | return; |
8235 | } | |
8236 | ||
8237 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | |
8238 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) | |
8239 | mpt3sas_transport_update_links(ioc, sas_address, handle, | |
8240 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | |
8241 | ||
8242 | _scsih_add_device(ioc, handle, 0, 1); | |
8243 | ||
8244 | break; | |
8245 | ||
8246 | case MPI2_RAID_PD_STATE_OFFLINE: | |
8247 | case MPI2_RAID_PD_STATE_NOT_CONFIGURED: | |
8248 | case MPI2_RAID_PD_STATE_NOT_COMPATIBLE: | |
8249 | default: | |
8250 | break; | |
8251 | } | |
8252 | } | |
8253 | ||
f92363d1 SR |
8254 | /** |
8255 | * _scsih_sas_ir_operation_status_event_debug - debug for IR op event | |
8256 | * @ioc: per adapter object | |
8257 | * @event_data: event data payload | |
8258 | * Context: user. | |
f92363d1 SR |
8259 | */ |
8260 | static void | |
8261 | _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
8262 | Mpi2EventDataIrOperationStatus_t *event_data) | |
8263 | { | |
8264 | char *reason_str = NULL; | |
8265 | ||
8266 | switch (event_data->RAIDOperation) { | |
8267 | case MPI2_EVENT_IR_RAIDOP_RESYNC: | |
8268 | reason_str = "resync"; | |
8269 | break; | |
8270 | case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION: | |
8271 | reason_str = "online capacity expansion"; | |
8272 | break; | |
8273 | case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK: | |
8274 | reason_str = "consistency check"; | |
8275 | break; | |
8276 | case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT: | |
8277 | reason_str = "background init"; | |
8278 | break; | |
8279 | case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT: | |
8280 | reason_str = "make data consistent"; | |
8281 | break; | |
8282 | } | |
8283 | ||
8284 | if (!reason_str) | |
8285 | return; | |
8286 | ||
919d8a3f JP |
8287 | ioc_info(ioc, "raid operational status: (%s)\thandle(0x%04x), percent complete(%d)\n", |
8288 | reason_str, | |
8289 | le16_to_cpu(event_data->VolDevHandle), | |
8290 | event_data->PercentComplete); | |
f92363d1 | 8291 | } |
f92363d1 SR |
8292 | |
8293 | /** | |
8294 | * _scsih_sas_ir_operation_status_event - handle RAID operation events | |
8295 | * @ioc: per adapter object | |
8296 | * @fw_event: The fw_event_work object | |
8297 | * Context: user. | |
f92363d1 SR |
8298 | */ |
8299 | static void | |
8300 | _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc, | |
8301 | struct fw_event_work *fw_event) | |
8302 | { | |
35b62362 JL |
8303 | Mpi2EventDataIrOperationStatus_t *event_data = |
8304 | (Mpi2EventDataIrOperationStatus_t *) | |
8305 | fw_event->event_data; | |
f92363d1 SR |
8306 | static struct _raid_device *raid_device; |
8307 | unsigned long flags; | |
8308 | u16 handle; | |
8309 | ||
7786ab6a SR |
8310 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) && |
8311 | (!ioc->hide_ir_msg)) | |
f92363d1 SR |
8312 | _scsih_sas_ir_operation_status_event_debug(ioc, |
8313 | event_data); | |
f92363d1 SR |
8314 | |
8315 | /* code added for raid transport support */ | |
8316 | if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) { | |
8317 | ||
8318 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
8319 | handle = le16_to_cpu(event_data->VolDevHandle); | |
c84b06a4 | 8320 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
8321 | if (raid_device) |
8322 | raid_device->percent_complete = | |
8323 | event_data->PercentComplete; | |
8324 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
8325 | } | |
8326 | } | |
8327 | ||
8328 | /** | |
8329 | * _scsih_prep_device_scan - initialize parameters prior to device scan | |
8330 | * @ioc: per adapter object | |
8331 | * | |
8332 | * Set the deleted flag prior to device scan. If the device is found during | |
8333 | * the scan, then we clear the deleted flag. | |
8334 | */ | |
8335 | static void | |
8336 | _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc) | |
8337 | { | |
8338 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
8339 | struct scsi_device *sdev; | |
8340 | ||
8341 | shost_for_each_device(sdev, ioc->shost) { | |
8342 | sas_device_priv_data = sdev->hostdata; | |
8343 | if (sas_device_priv_data && sas_device_priv_data->sas_target) | |
8344 | sas_device_priv_data->sas_target->deleted = 1; | |
8345 | } | |
8346 | } | |
8347 | ||
8348 | /** | |
8349 | * _scsih_mark_responding_sas_device - mark a sas_devices as responding | |
8350 | * @ioc: per adapter object | |
e6d45e3e | 8351 | * @sas_device_pg0: SAS Device page 0 |
f92363d1 SR |
8352 | * |
8353 | * After host reset, find out whether devices are still responding. | |
8354 | * Used in _scsih_remove_unresponsive_sas_devices. | |
f92363d1 SR |
8355 | */ |
8356 | static void | |
e6d45e3e SR |
8357 | _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc, |
8358 | Mpi2SasDevicePage0_t *sas_device_pg0) | |
f92363d1 SR |
8359 | { |
8360 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; | |
8361 | struct scsi_target *starget; | |
aba5a85c | 8362 | struct _sas_device *sas_device = NULL; |
22a923c3 | 8363 | struct _enclosure_node *enclosure_dev = NULL; |
f92363d1 SR |
8364 | unsigned long flags; |
8365 | ||
22a923c3 C |
8366 | if (sas_device_pg0->EnclosureHandle) { |
8367 | enclosure_dev = | |
8368 | mpt3sas_scsih_enclosure_find_by_handle(ioc, | |
8369 | le16_to_cpu(sas_device_pg0->EnclosureHandle)); | |
8370 | if (enclosure_dev == NULL) | |
919d8a3f JP |
8371 | ioc_info(ioc, "Enclosure handle(0x%04x) doesn't match with enclosure device!\n", |
8372 | sas_device_pg0->EnclosureHandle); | |
22a923c3 | 8373 | } |
f92363d1 SR |
8374 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
8375 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) { | |
cf6bf971 C |
8376 | if ((sas_device->sas_address == le64_to_cpu( |
8377 | sas_device_pg0->SASAddress)) && (sas_device->slot == | |
8378 | le16_to_cpu(sas_device_pg0->Slot))) { | |
f92363d1 SR |
8379 | sas_device->responding = 1; |
8380 | starget = sas_device->starget; | |
8381 | if (starget && starget->hostdata) { | |
8382 | sas_target_priv_data = starget->hostdata; | |
8383 | sas_target_priv_data->tm_busy = 0; | |
8384 | sas_target_priv_data->deleted = 0; | |
8385 | } else | |
8386 | sas_target_priv_data = NULL; | |
e6d45e3e | 8387 | if (starget) { |
f92363d1 | 8388 | starget_printk(KERN_INFO, starget, |
e6d45e3e | 8389 | "handle(0x%04x), sas_addr(0x%016llx)\n", |
cf6bf971 | 8390 | le16_to_cpu(sas_device_pg0->DevHandle), |
f92363d1 | 8391 | (unsigned long long) |
e6d45e3e SR |
8392 | sas_device->sas_address); |
8393 | ||
8394 | if (sas_device->enclosure_handle != 0) | |
8395 | starget_printk(KERN_INFO, starget, | |
8396 | "enclosure logical id(0x%016llx)," | |
8397 | " slot(%d)\n", | |
8398 | (unsigned long long) | |
8399 | sas_device->enclosure_logical_id, | |
8400 | sas_device->slot); | |
8401 | } | |
cf6bf971 | 8402 | if (le16_to_cpu(sas_device_pg0->Flags) & |
e6d45e3e SR |
8403 | MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) { |
8404 | sas_device->enclosure_level = | |
aa53bb89 | 8405 | sas_device_pg0->EnclosureLevel; |
e6d45e3e SR |
8406 | memcpy(&sas_device->connector_name[0], |
8407 | &sas_device_pg0->ConnectorName[0], 4); | |
8408 | } else { | |
8409 | sas_device->enclosure_level = 0; | |
8410 | sas_device->connector_name[0] = '\0'; | |
8411 | } | |
8412 | ||
22a923c3 C |
8413 | sas_device->enclosure_handle = |
8414 | le16_to_cpu(sas_device_pg0->EnclosureHandle); | |
8415 | sas_device->is_chassis_slot_valid = 0; | |
8416 | if (enclosure_dev) { | |
8417 | sas_device->enclosure_logical_id = le64_to_cpu( | |
8418 | enclosure_dev->pg0.EnclosureLogicalID); | |
8419 | if (le16_to_cpu(enclosure_dev->pg0.Flags) & | |
8420 | MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) { | |
8421 | sas_device->is_chassis_slot_valid = 1; | |
8422 | sas_device->chassis_slot = | |
8423 | enclosure_dev->pg0.ChassisSlot; | |
8424 | } | |
8425 | } | |
75888956 | 8426 | |
cf6bf971 C |
8427 | if (sas_device->handle == le16_to_cpu( |
8428 | sas_device_pg0->DevHandle)) | |
f92363d1 SR |
8429 | goto out; |
8430 | pr_info("\thandle changed from(0x%04x)!!!\n", | |
8431 | sas_device->handle); | |
cf6bf971 C |
8432 | sas_device->handle = le16_to_cpu( |
8433 | sas_device_pg0->DevHandle); | |
f92363d1 | 8434 | if (sas_target_priv_data) |
e6d45e3e | 8435 | sas_target_priv_data->handle = |
cf6bf971 | 8436 | le16_to_cpu(sas_device_pg0->DevHandle); |
f92363d1 SR |
8437 | goto out; |
8438 | } | |
8439 | } | |
8440 | out: | |
8441 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
8442 | } | |
8443 | ||
22a923c3 C |
8444 | /** |
8445 | * _scsih_create_enclosure_list_after_reset - Free Existing list, | |
8446 | * And create enclosure list by scanning all Enclosure Page(0)s | |
8447 | * @ioc: per adapter object | |
22a923c3 C |
8448 | */ |
8449 | static void | |
8450 | _scsih_create_enclosure_list_after_reset(struct MPT3SAS_ADAPTER *ioc) | |
8451 | { | |
8452 | struct _enclosure_node *enclosure_dev; | |
8453 | Mpi2ConfigReply_t mpi_reply; | |
8454 | u16 enclosure_handle; | |
8455 | int rc; | |
8456 | ||
8457 | /* Free existing enclosure list */ | |
8458 | mpt3sas_free_enclosure_list(ioc); | |
8459 | ||
8460 | /* Re constructing enclosure list after reset*/ | |
8461 | enclosure_handle = 0xFFFF; | |
8462 | do { | |
8463 | enclosure_dev = | |
8464 | kzalloc(sizeof(struct _enclosure_node), GFP_KERNEL); | |
8465 | if (!enclosure_dev) { | |
919d8a3f | 8466 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
22a923c3 C |
8467 | __FILE__, __LINE__, __func__); |
8468 | return; | |
8469 | } | |
8470 | rc = mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
8471 | &enclosure_dev->pg0, | |
8472 | MPI2_SAS_ENCLOS_PGAD_FORM_GET_NEXT_HANDLE, | |
8473 | enclosure_handle); | |
8474 | ||
8475 | if (rc || (le16_to_cpu(mpi_reply.IOCStatus) & | |
8476 | MPI2_IOCSTATUS_MASK)) { | |
8477 | kfree(enclosure_dev); | |
8478 | return; | |
8479 | } | |
8480 | list_add_tail(&enclosure_dev->list, | |
8481 | &ioc->enclosure_list); | |
8482 | enclosure_handle = | |
8483 | le16_to_cpu(enclosure_dev->pg0.EnclosureHandle); | |
8484 | } while (1); | |
8485 | } | |
8486 | ||
f92363d1 SR |
8487 | /** |
8488 | * _scsih_search_responding_sas_devices - | |
8489 | * @ioc: per adapter object | |
8490 | * | |
8491 | * After host reset, find out whether devices are still responding. | |
8492 | * If not remove. | |
f92363d1 SR |
8493 | */ |
8494 | static void | |
8495 | _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc) | |
8496 | { | |
8497 | Mpi2SasDevicePage0_t sas_device_pg0; | |
8498 | Mpi2ConfigReply_t mpi_reply; | |
8499 | u16 ioc_status; | |
8500 | u16 handle; | |
8501 | u32 device_info; | |
8502 | ||
919d8a3f | 8503 | ioc_info(ioc, "search for end-devices: start\n"); |
f92363d1 SR |
8504 | |
8505 | if (list_empty(&ioc->sas_device_list)) | |
8506 | goto out; | |
8507 | ||
8508 | handle = 0xFFFF; | |
8509 | while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
8510 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | |
8511 | handle))) { | |
8512 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8513 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 8514 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 | 8515 | break; |
cf6bf971 | 8516 | handle = le16_to_cpu(sas_device_pg0.DevHandle); |
f92363d1 SR |
8517 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
8518 | if (!(_scsih_is_end_device(device_info))) | |
8519 | continue; | |
e6d45e3e | 8520 | _scsih_mark_responding_sas_device(ioc, &sas_device_pg0); |
f92363d1 SR |
8521 | } |
8522 | ||
8523 | out: | |
919d8a3f | 8524 | ioc_info(ioc, "search for end-devices: complete\n"); |
f92363d1 SR |
8525 | } |
8526 | ||
ec051e5a SPS |
8527 | /** |
8528 | * _scsih_mark_responding_pcie_device - mark a pcie_device as responding | |
8529 | * @ioc: per adapter object | |
8530 | * @pcie_device_pg0: PCIe Device page 0 | |
8531 | * | |
8532 | * After host reset, find out whether devices are still responding. | |
8533 | * Used in _scsih_remove_unresponding_devices. | |
ec051e5a SPS |
8534 | */ |
8535 | static void | |
8536 | _scsih_mark_responding_pcie_device(struct MPT3SAS_ADAPTER *ioc, | |
8537 | Mpi26PCIeDevicePage0_t *pcie_device_pg0) | |
8538 | { | |
8539 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; | |
8540 | struct scsi_target *starget; | |
8541 | struct _pcie_device *pcie_device; | |
8542 | unsigned long flags; | |
8543 | ||
8544 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
8545 | list_for_each_entry(pcie_device, &ioc->pcie_device_list, list) { | |
cf6bf971 C |
8546 | if ((pcie_device->wwid == le64_to_cpu(pcie_device_pg0->WWID)) |
8547 | && (pcie_device->slot == le16_to_cpu( | |
8548 | pcie_device_pg0->Slot))) { | |
3c090ce3 SP |
8549 | pcie_device->access_status = |
8550 | pcie_device_pg0->AccessStatus; | |
ec051e5a SPS |
8551 | pcie_device->responding = 1; |
8552 | starget = pcie_device->starget; | |
8553 | if (starget && starget->hostdata) { | |
8554 | sas_target_priv_data = starget->hostdata; | |
8555 | sas_target_priv_data->tm_busy = 0; | |
8556 | sas_target_priv_data->deleted = 0; | |
8557 | } else | |
8558 | sas_target_priv_data = NULL; | |
8559 | if (starget) { | |
8560 | starget_printk(KERN_INFO, starget, | |
8561 | "handle(0x%04x), wwid(0x%016llx) ", | |
8562 | pcie_device->handle, | |
8563 | (unsigned long long)pcie_device->wwid); | |
8564 | if (pcie_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 | pcie_device->enclosure_logical_id, | |
8570 | pcie_device->slot); | |
8571 | } | |
8572 | ||
8573 | if (((le32_to_cpu(pcie_device_pg0->Flags)) & | |
8574 | MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) && | |
8575 | (ioc->hba_mpi_version_belonged != MPI2_VERSION)) { | |
8576 | pcie_device->enclosure_level = | |
8577 | pcie_device_pg0->EnclosureLevel; | |
8578 | memcpy(&pcie_device->connector_name[0], | |
8579 | &pcie_device_pg0->ConnectorName[0], 4); | |
8580 | } else { | |
8581 | pcie_device->enclosure_level = 0; | |
8582 | pcie_device->connector_name[0] = '\0'; | |
8583 | } | |
8584 | ||
cf6bf971 C |
8585 | if (pcie_device->handle == le16_to_cpu( |
8586 | pcie_device_pg0->DevHandle)) | |
ec051e5a | 8587 | goto out; |
268eb498 | 8588 | pr_info("\thandle changed from(0x%04x)!!!\n", |
ec051e5a | 8589 | pcie_device->handle); |
cf6bf971 C |
8590 | pcie_device->handle = le16_to_cpu( |
8591 | pcie_device_pg0->DevHandle); | |
ec051e5a SPS |
8592 | if (sas_target_priv_data) |
8593 | sas_target_priv_data->handle = | |
cf6bf971 | 8594 | le16_to_cpu(pcie_device_pg0->DevHandle); |
ec051e5a SPS |
8595 | goto out; |
8596 | } | |
8597 | } | |
8598 | ||
8599 | out: | |
8600 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
8601 | } | |
8602 | ||
8603 | /** | |
8604 | * _scsih_search_responding_pcie_devices - | |
8605 | * @ioc: per adapter object | |
8606 | * | |
8607 | * After host reset, find out whether devices are still responding. | |
8608 | * If not remove. | |
ec051e5a SPS |
8609 | */ |
8610 | static void | |
8611 | _scsih_search_responding_pcie_devices(struct MPT3SAS_ADAPTER *ioc) | |
8612 | { | |
8613 | Mpi26PCIeDevicePage0_t pcie_device_pg0; | |
8614 | Mpi2ConfigReply_t mpi_reply; | |
8615 | u16 ioc_status; | |
8616 | u16 handle; | |
8617 | u32 device_info; | |
8618 | ||
919d8a3f | 8619 | ioc_info(ioc, "search for end-devices: start\n"); |
ec051e5a SPS |
8620 | |
8621 | if (list_empty(&ioc->pcie_device_list)) | |
8622 | goto out; | |
8623 | ||
8624 | handle = 0xFFFF; | |
8625 | while (!(mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply, | |
8626 | &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | |
8627 | handle))) { | |
8628 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8629 | MPI2_IOCSTATUS_MASK; | |
8630 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
919d8a3f JP |
8631 | ioc_info(ioc, "\tbreak from %s: ioc_status(0x%04x), loginfo(0x%08x)\n", |
8632 | __func__, ioc_status, | |
8633 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
ec051e5a SPS |
8634 | break; |
8635 | } | |
8636 | handle = le16_to_cpu(pcie_device_pg0.DevHandle); | |
8637 | device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo); | |
5bb309db | 8638 | if (!(_scsih_is_nvme_pciescsi_device(device_info))) |
ec051e5a | 8639 | continue; |
ec051e5a SPS |
8640 | _scsih_mark_responding_pcie_device(ioc, &pcie_device_pg0); |
8641 | } | |
8642 | out: | |
919d8a3f | 8643 | ioc_info(ioc, "search for PCIe end-devices: complete\n"); |
ec051e5a SPS |
8644 | } |
8645 | ||
f92363d1 SR |
8646 | /** |
8647 | * _scsih_mark_responding_raid_device - mark a raid_device as responding | |
8648 | * @ioc: per adapter object | |
8649 | * @wwid: world wide identifier for raid volume | |
8650 | * @handle: device handle | |
8651 | * | |
8652 | * After host reset, find out whether devices are still responding. | |
8653 | * Used in _scsih_remove_unresponsive_raid_devices. | |
f92363d1 SR |
8654 | */ |
8655 | static void | |
8656 | _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid, | |
8657 | u16 handle) | |
8658 | { | |
7786ab6a | 8659 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; |
f92363d1 SR |
8660 | struct scsi_target *starget; |
8661 | struct _raid_device *raid_device; | |
8662 | unsigned long flags; | |
8663 | ||
8664 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
8665 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
8666 | if (raid_device->wwid == wwid && raid_device->starget) { | |
8667 | starget = raid_device->starget; | |
8668 | if (starget && starget->hostdata) { | |
8669 | sas_target_priv_data = starget->hostdata; | |
8670 | sas_target_priv_data->deleted = 0; | |
8671 | } else | |
8672 | sas_target_priv_data = NULL; | |
8673 | raid_device->responding = 1; | |
8674 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
8675 | starget_printk(KERN_INFO, raid_device->starget, | |
8676 | "handle(0x%04x), wwid(0x%016llx)\n", handle, | |
8677 | (unsigned long long)raid_device->wwid); | |
7786ab6a | 8678 | |
7786ab6a SR |
8679 | /* |
8680 | * WARPDRIVE: The handles of the PDs might have changed | |
8681 | * across the host reset so re-initialize the | |
8682 | * required data for Direct IO | |
8683 | */ | |
c84b06a4 | 8684 | mpt3sas_init_warpdrive_properties(ioc, raid_device); |
f92363d1 SR |
8685 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
8686 | if (raid_device->handle == handle) { | |
8687 | spin_unlock_irqrestore(&ioc->raid_device_lock, | |
8688 | flags); | |
8689 | return; | |
8690 | } | |
8691 | pr_info("\thandle changed from(0x%04x)!!!\n", | |
8692 | raid_device->handle); | |
8693 | raid_device->handle = handle; | |
8694 | if (sas_target_priv_data) | |
8695 | sas_target_priv_data->handle = handle; | |
8696 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
8697 | return; | |
8698 | } | |
8699 | } | |
8700 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
8701 | } | |
8702 | ||
8703 | /** | |
8704 | * _scsih_search_responding_raid_devices - | |
8705 | * @ioc: per adapter object | |
8706 | * | |
8707 | * After host reset, find out whether devices are still responding. | |
8708 | * If not remove. | |
f92363d1 SR |
8709 | */ |
8710 | static void | |
8711 | _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc) | |
8712 | { | |
8713 | Mpi2RaidVolPage1_t volume_pg1; | |
8714 | Mpi2RaidVolPage0_t volume_pg0; | |
8715 | Mpi2RaidPhysDiskPage0_t pd_pg0; | |
8716 | Mpi2ConfigReply_t mpi_reply; | |
8717 | u16 ioc_status; | |
8718 | u16 handle; | |
8719 | u8 phys_disk_num; | |
8720 | ||
8721 | if (!ioc->ir_firmware) | |
8722 | return; | |
8723 | ||
919d8a3f | 8724 | ioc_info(ioc, "search for raid volumes: start\n"); |
f92363d1 SR |
8725 | |
8726 | if (list_empty(&ioc->raid_device_list)) | |
8727 | goto out; | |
8728 | ||
8729 | handle = 0xFFFF; | |
8730 | while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply, | |
8731 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { | |
8732 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8733 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 8734 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 SR |
8735 | break; |
8736 | handle = le16_to_cpu(volume_pg1.DevHandle); | |
8737 | ||
8738 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, | |
8739 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
8740 | sizeof(Mpi2RaidVolPage0_t))) | |
8741 | continue; | |
8742 | ||
8743 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || | |
8744 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || | |
8745 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) | |
8746 | _scsih_mark_responding_raid_device(ioc, | |
8747 | le64_to_cpu(volume_pg1.WWID), handle); | |
8748 | } | |
8749 | ||
8750 | /* refresh the pd_handles */ | |
7786ab6a | 8751 | if (!ioc->is_warpdrive) { |
f92363d1 SR |
8752 | phys_disk_num = 0xFF; |
8753 | memset(ioc->pd_handles, 0, ioc->pd_handles_sz); | |
8754 | while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | |
8755 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, | |
8756 | phys_disk_num))) { | |
8757 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8758 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 8759 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 SR |
8760 | break; |
8761 | phys_disk_num = pd_pg0.PhysDiskNum; | |
8762 | handle = le16_to_cpu(pd_pg0.DevHandle); | |
8763 | set_bit(handle, ioc->pd_handles); | |
8764 | } | |
7786ab6a | 8765 | } |
f92363d1 | 8766 | out: |
919d8a3f | 8767 | ioc_info(ioc, "search for responding raid volumes: complete\n"); |
f92363d1 SR |
8768 | } |
8769 | ||
8770 | /** | |
8771 | * _scsih_mark_responding_expander - mark a expander as responding | |
8772 | * @ioc: per adapter object | |
aba5a85c | 8773 | * @expander_pg0:SAS Expander Config Page0 |
f92363d1 SR |
8774 | * |
8775 | * After host reset, find out whether devices are still responding. | |
8776 | * Used in _scsih_remove_unresponsive_expanders. | |
f92363d1 SR |
8777 | */ |
8778 | static void | |
aba5a85c SR |
8779 | _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc, |
8780 | Mpi2ExpanderPage0_t *expander_pg0) | |
f92363d1 | 8781 | { |
aba5a85c | 8782 | struct _sas_node *sas_expander = NULL; |
f92363d1 | 8783 | unsigned long flags; |
22a923c3 C |
8784 | int i; |
8785 | struct _enclosure_node *enclosure_dev = NULL; | |
aba5a85c | 8786 | u16 handle = le16_to_cpu(expander_pg0->DevHandle); |
22a923c3 | 8787 | u16 enclosure_handle = le16_to_cpu(expander_pg0->EnclosureHandle); |
aba5a85c SR |
8788 | u64 sas_address = le64_to_cpu(expander_pg0->SASAddress); |
8789 | ||
22a923c3 C |
8790 | if (enclosure_handle) |
8791 | enclosure_dev = | |
8792 | mpt3sas_scsih_enclosure_find_by_handle(ioc, | |
8793 | enclosure_handle); | |
f92363d1 SR |
8794 | |
8795 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
8796 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { | |
8797 | if (sas_expander->sas_address != sas_address) | |
8798 | continue; | |
8799 | sas_expander->responding = 1; | |
aba5a85c | 8800 | |
22a923c3 | 8801 | if (enclosure_dev) { |
aba5a85c | 8802 | sas_expander->enclosure_logical_id = |
22a923c3 C |
8803 | le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID); |
8804 | sas_expander->enclosure_handle = | |
8805 | le16_to_cpu(expander_pg0->EnclosureHandle); | |
8806 | } | |
aba5a85c | 8807 | |
f92363d1 SR |
8808 | if (sas_expander->handle == handle) |
8809 | goto out; | |
8810 | pr_info("\texpander(0x%016llx): handle changed" \ | |
8811 | " from(0x%04x) to (0x%04x)!!!\n", | |
8812 | (unsigned long long)sas_expander->sas_address, | |
8813 | sas_expander->handle, handle); | |
8814 | sas_expander->handle = handle; | |
8815 | for (i = 0 ; i < sas_expander->num_phys ; i++) | |
8816 | sas_expander->phy[i].handle = handle; | |
8817 | goto out; | |
8818 | } | |
8819 | out: | |
8820 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
8821 | } | |
8822 | ||
8823 | /** | |
8824 | * _scsih_search_responding_expanders - | |
8825 | * @ioc: per adapter object | |
8826 | * | |
8827 | * After host reset, find out whether devices are still responding. | |
8828 | * If not remove. | |
f92363d1 SR |
8829 | */ |
8830 | static void | |
8831 | _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc) | |
8832 | { | |
8833 | Mpi2ExpanderPage0_t expander_pg0; | |
8834 | Mpi2ConfigReply_t mpi_reply; | |
8835 | u16 ioc_status; | |
8836 | u64 sas_address; | |
8837 | u16 handle; | |
8838 | ||
919d8a3f | 8839 | ioc_info(ioc, "search for expanders: start\n"); |
f92363d1 SR |
8840 | |
8841 | if (list_empty(&ioc->sas_expander_list)) | |
8842 | goto out; | |
8843 | ||
8844 | handle = 0xFFFF; | |
8845 | while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | |
8846 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { | |
8847 | ||
8848 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8849 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 8850 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 SR |
8851 | break; |
8852 | ||
8853 | handle = le16_to_cpu(expander_pg0.DevHandle); | |
8854 | sas_address = le64_to_cpu(expander_pg0.SASAddress); | |
8855 | pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n", | |
8856 | handle, | |
8857 | (unsigned long long)sas_address); | |
aba5a85c | 8858 | _scsih_mark_responding_expander(ioc, &expander_pg0); |
f92363d1 SR |
8859 | } |
8860 | ||
8861 | out: | |
919d8a3f | 8862 | ioc_info(ioc, "search for expanders: complete\n"); |
f92363d1 SR |
8863 | } |
8864 | ||
8865 | /** | |
3075ac49 | 8866 | * _scsih_remove_unresponding_devices - removing unresponding devices |
f92363d1 | 8867 | * @ioc: per adapter object |
f92363d1 SR |
8868 | */ |
8869 | static void | |
3075ac49 | 8870 | _scsih_remove_unresponding_devices(struct MPT3SAS_ADAPTER *ioc) |
f92363d1 SR |
8871 | { |
8872 | struct _sas_device *sas_device, *sas_device_next; | |
8873 | struct _sas_node *sas_expander, *sas_expander_next; | |
8874 | struct _raid_device *raid_device, *raid_device_next; | |
3075ac49 | 8875 | struct _pcie_device *pcie_device, *pcie_device_next; |
f92363d1 SR |
8876 | struct list_head tmp_list; |
8877 | unsigned long flags; | |
d1cb5e49 | 8878 | LIST_HEAD(head); |
f92363d1 | 8879 | |
919d8a3f | 8880 | ioc_info(ioc, "removing unresponding devices: start\n"); |
f92363d1 SR |
8881 | |
8882 | /* removing unresponding end devices */ | |
919d8a3f | 8883 | ioc_info(ioc, "removing unresponding devices: end-devices\n"); |
d1cb5e49 SR |
8884 | /* |
8885 | * Iterate, pulling off devices marked as non-responding. We become the | |
8886 | * owner for the reference the list had on any object we prune. | |
8887 | */ | |
8888 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
f92363d1 SR |
8889 | list_for_each_entry_safe(sas_device, sas_device_next, |
8890 | &ioc->sas_device_list, list) { | |
8891 | if (!sas_device->responding) | |
d1cb5e49 | 8892 | list_move_tail(&sas_device->list, &head); |
f92363d1 SR |
8893 | else |
8894 | sas_device->responding = 0; | |
8895 | } | |
d1cb5e49 SR |
8896 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
8897 | ||
8898 | /* | |
8899 | * Now, uninitialize and remove the unresponding devices we pruned. | |
8900 | */ | |
8901 | list_for_each_entry_safe(sas_device, sas_device_next, &head, list) { | |
8902 | _scsih_remove_device(ioc, sas_device); | |
8903 | list_del_init(&sas_device->list); | |
8904 | sas_device_put(sas_device); | |
8905 | } | |
f92363d1 | 8906 | |
919d8a3f | 8907 | ioc_info(ioc, "Removing unresponding devices: pcie end-devices\n"); |
3075ac49 SPS |
8908 | INIT_LIST_HEAD(&head); |
8909 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
8910 | list_for_each_entry_safe(pcie_device, pcie_device_next, | |
8911 | &ioc->pcie_device_list, list) { | |
8912 | if (!pcie_device->responding) | |
8913 | list_move_tail(&pcie_device->list, &head); | |
8914 | else | |
8915 | pcie_device->responding = 0; | |
8916 | } | |
8917 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
8918 | ||
8919 | list_for_each_entry_safe(pcie_device, pcie_device_next, &head, list) { | |
8920 | _scsih_pcie_device_remove_from_sml(ioc, pcie_device); | |
8921 | list_del_init(&pcie_device->list); | |
8922 | pcie_device_put(pcie_device); | |
8923 | } | |
8924 | ||
f92363d1 SR |
8925 | /* removing unresponding volumes */ |
8926 | if (ioc->ir_firmware) { | |
919d8a3f | 8927 | ioc_info(ioc, "removing unresponding devices: volumes\n"); |
f92363d1 SR |
8928 | list_for_each_entry_safe(raid_device, raid_device_next, |
8929 | &ioc->raid_device_list, list) { | |
8930 | if (!raid_device->responding) | |
8931 | _scsih_sas_volume_delete(ioc, | |
8932 | raid_device->handle); | |
8933 | else | |
8934 | raid_device->responding = 0; | |
8935 | } | |
8936 | } | |
8937 | ||
8938 | /* removing unresponding expanders */ | |
919d8a3f | 8939 | ioc_info(ioc, "removing unresponding devices: expanders\n"); |
f92363d1 SR |
8940 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
8941 | INIT_LIST_HEAD(&tmp_list); | |
8942 | list_for_each_entry_safe(sas_expander, sas_expander_next, | |
8943 | &ioc->sas_expander_list, list) { | |
8944 | if (!sas_expander->responding) | |
8945 | list_move_tail(&sas_expander->list, &tmp_list); | |
8946 | else | |
8947 | sas_expander->responding = 0; | |
8948 | } | |
8949 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
8950 | list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list, | |
8951 | list) { | |
f92363d1 SR |
8952 | _scsih_expander_node_remove(ioc, sas_expander); |
8953 | } | |
8954 | ||
919d8a3f | 8955 | ioc_info(ioc, "removing unresponding devices: complete\n"); |
f92363d1 SR |
8956 | |
8957 | /* unblock devices */ | |
8958 | _scsih_ublock_io_all_device(ioc); | |
8959 | } | |
8960 | ||
8961 | static void | |
8962 | _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc, | |
8963 | struct _sas_node *sas_expander, u16 handle) | |
8964 | { | |
8965 | Mpi2ExpanderPage1_t expander_pg1; | |
8966 | Mpi2ConfigReply_t mpi_reply; | |
8967 | int i; | |
8968 | ||
8969 | for (i = 0 ; i < sas_expander->num_phys ; i++) { | |
8970 | if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply, | |
8971 | &expander_pg1, i, handle))) { | |
919d8a3f JP |
8972 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
8973 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
8974 | return; |
8975 | } | |
8976 | ||
8977 | mpt3sas_transport_update_links(ioc, sas_expander->sas_address, | |
8978 | le16_to_cpu(expander_pg1.AttachedDevHandle), i, | |
8979 | expander_pg1.NegotiatedLinkRate >> 4); | |
8980 | } | |
8981 | } | |
8982 | ||
8983 | /** | |
8984 | * _scsih_scan_for_devices_after_reset - scan for devices after host reset | |
8985 | * @ioc: per adapter object | |
f92363d1 SR |
8986 | */ |
8987 | static void | |
8988 | _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc) | |
8989 | { | |
8990 | Mpi2ExpanderPage0_t expander_pg0; | |
8991 | Mpi2SasDevicePage0_t sas_device_pg0; | |
ec051e5a | 8992 | Mpi26PCIeDevicePage0_t pcie_device_pg0; |
f92363d1 SR |
8993 | Mpi2RaidVolPage1_t volume_pg1; |
8994 | Mpi2RaidVolPage0_t volume_pg0; | |
8995 | Mpi2RaidPhysDiskPage0_t pd_pg0; | |
8996 | Mpi2EventIrConfigElement_t element; | |
8997 | Mpi2ConfigReply_t mpi_reply; | |
8998 | u8 phys_disk_num; | |
8999 | u16 ioc_status; | |
9000 | u16 handle, parent_handle; | |
9001 | u64 sas_address; | |
9002 | struct _sas_device *sas_device; | |
ec051e5a | 9003 | struct _pcie_device *pcie_device; |
f92363d1 SR |
9004 | struct _sas_node *expander_device; |
9005 | static struct _raid_device *raid_device; | |
9006 | u8 retry_count; | |
9007 | unsigned long flags; | |
9008 | ||
919d8a3f | 9009 | ioc_info(ioc, "scan devices: start\n"); |
f92363d1 SR |
9010 | |
9011 | _scsih_sas_host_refresh(ioc); | |
9012 | ||
919d8a3f | 9013 | ioc_info(ioc, "\tscan devices: expanders start\n"); |
f92363d1 SR |
9014 | |
9015 | /* expanders */ | |
9016 | handle = 0xFFFF; | |
9017 | while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | |
9018 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { | |
9019 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9020 | MPI2_IOCSTATUS_MASK; | |
f92363d1 | 9021 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
919d8a3f JP |
9022 | ioc_info(ioc, "\tbreak from expander scan: ioc_status(0x%04x), loginfo(0x%08x)\n", |
9023 | ioc_status, le32_to_cpu(mpi_reply.IOCLogInfo)); | |
f92363d1 SR |
9024 | break; |
9025 | } | |
9026 | handle = le16_to_cpu(expander_pg0.DevHandle); | |
9027 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
9028 | expander_device = mpt3sas_scsih_expander_find_by_sas_address( | |
9029 | ioc, le64_to_cpu(expander_pg0.SASAddress)); | |
9030 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
9031 | if (expander_device) | |
9032 | _scsih_refresh_expander_links(ioc, expander_device, | |
9033 | handle); | |
9034 | else { | |
919d8a3f JP |
9035 | ioc_info(ioc, "\tBEFORE adding expander: handle (0x%04x), sas_addr(0x%016llx)\n", |
9036 | handle, | |
9037 | (u64)le64_to_cpu(expander_pg0.SASAddress)); | |
f92363d1 | 9038 | _scsih_expander_add(ioc, handle); |
919d8a3f JP |
9039 | ioc_info(ioc, "\tAFTER adding expander: handle (0x%04x), sas_addr(0x%016llx)\n", |
9040 | handle, | |
9041 | (u64)le64_to_cpu(expander_pg0.SASAddress)); | |
f92363d1 SR |
9042 | } |
9043 | } | |
9044 | ||
919d8a3f | 9045 | ioc_info(ioc, "\tscan devices: expanders complete\n"); |
f92363d1 SR |
9046 | |
9047 | if (!ioc->ir_firmware) | |
9048 | goto skip_to_sas; | |
9049 | ||
919d8a3f | 9050 | ioc_info(ioc, "\tscan devices: phys disk start\n"); |
f92363d1 SR |
9051 | |
9052 | /* phys disk */ | |
9053 | phys_disk_num = 0xFF; | |
9054 | while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | |
9055 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, | |
9056 | phys_disk_num))) { | |
9057 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9058 | MPI2_IOCSTATUS_MASK; | |
f92363d1 | 9059 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
919d8a3f JP |
9060 | ioc_info(ioc, "\tbreak from phys disk scan: ioc_status(0x%04x), loginfo(0x%08x)\n", |
9061 | ioc_status, le32_to_cpu(mpi_reply.IOCLogInfo)); | |
f92363d1 SR |
9062 | break; |
9063 | } | |
9064 | phys_disk_num = pd_pg0.PhysDiskNum; | |
9065 | handle = le16_to_cpu(pd_pg0.DevHandle); | |
d1cb5e49 SR |
9066 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
9067 | if (sas_device) { | |
9068 | sas_device_put(sas_device); | |
f92363d1 | 9069 | continue; |
d1cb5e49 | 9070 | } |
f92363d1 SR |
9071 | if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
9072 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | |
9073 | handle) != 0) | |
9074 | continue; | |
9075 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9076 | MPI2_IOCSTATUS_MASK; | |
9077 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
919d8a3f JP |
9078 | ioc_info(ioc, "\tbreak from phys disk scan ioc_status(0x%04x), loginfo(0x%08x)\n", |
9079 | ioc_status, le32_to_cpu(mpi_reply.IOCLogInfo)); | |
f92363d1 SR |
9080 | break; |
9081 | } | |
9082 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | |
9083 | if (!_scsih_get_sas_address(ioc, parent_handle, | |
9084 | &sas_address)) { | |
919d8a3f JP |
9085 | ioc_info(ioc, "\tBEFORE adding phys disk: handle (0x%04x), sas_addr(0x%016llx)\n", |
9086 | handle, | |
9087 | (u64)le64_to_cpu(sas_device_pg0.SASAddress)); | |
f92363d1 SR |
9088 | mpt3sas_transport_update_links(ioc, sas_address, |
9089 | handle, sas_device_pg0.PhyNum, | |
9090 | MPI2_SAS_NEG_LINK_RATE_1_5); | |
9091 | set_bit(handle, ioc->pd_handles); | |
9092 | retry_count = 0; | |
9093 | /* This will retry adding the end device. | |
9094 | * _scsih_add_device() will decide on retries and | |
9095 | * return "1" when it should be retried | |
9096 | */ | |
9097 | while (_scsih_add_device(ioc, handle, retry_count++, | |
9098 | 1)) { | |
9099 | ssleep(1); | |
9100 | } | |
919d8a3f JP |
9101 | ioc_info(ioc, "\tAFTER adding phys disk: handle (0x%04x), sas_addr(0x%016llx)\n", |
9102 | handle, | |
9103 | (u64)le64_to_cpu(sas_device_pg0.SASAddress)); | |
f92363d1 SR |
9104 | } |
9105 | } | |
9106 | ||
919d8a3f | 9107 | ioc_info(ioc, "\tscan devices: phys disk complete\n"); |
f92363d1 | 9108 | |
919d8a3f | 9109 | ioc_info(ioc, "\tscan devices: volumes start\n"); |
f92363d1 SR |
9110 | |
9111 | /* volumes */ | |
9112 | handle = 0xFFFF; | |
9113 | while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply, | |
9114 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { | |
9115 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9116 | MPI2_IOCSTATUS_MASK; | |
f92363d1 | 9117 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
919d8a3f JP |
9118 | ioc_info(ioc, "\tbreak from volume scan: ioc_status(0x%04x), loginfo(0x%08x)\n", |
9119 | ioc_status, le32_to_cpu(mpi_reply.IOCLogInfo)); | |
f92363d1 SR |
9120 | break; |
9121 | } | |
9122 | handle = le16_to_cpu(volume_pg1.DevHandle); | |
9123 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
9124 | raid_device = _scsih_raid_device_find_by_wwid(ioc, | |
9125 | le64_to_cpu(volume_pg1.WWID)); | |
9126 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
9127 | if (raid_device) | |
9128 | continue; | |
9129 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, | |
9130 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
9131 | sizeof(Mpi2RaidVolPage0_t))) | |
9132 | continue; | |
9133 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9134 | MPI2_IOCSTATUS_MASK; | |
9135 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
919d8a3f JP |
9136 | ioc_info(ioc, "\tbreak from volume scan: ioc_status(0x%04x), loginfo(0x%08x)\n", |
9137 | ioc_status, le32_to_cpu(mpi_reply.IOCLogInfo)); | |
f92363d1 SR |
9138 | break; |
9139 | } | |
9140 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || | |
9141 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || | |
9142 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) { | |
9143 | memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t)); | |
9144 | element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED; | |
9145 | element.VolDevHandle = volume_pg1.DevHandle; | |
919d8a3f JP |
9146 | ioc_info(ioc, "\tBEFORE adding volume: handle (0x%04x)\n", |
9147 | volume_pg1.DevHandle); | |
f92363d1 | 9148 | _scsih_sas_volume_add(ioc, &element); |
919d8a3f JP |
9149 | ioc_info(ioc, "\tAFTER adding volume: handle (0x%04x)\n", |
9150 | volume_pg1.DevHandle); | |
f92363d1 SR |
9151 | } |
9152 | } | |
9153 | ||
919d8a3f | 9154 | ioc_info(ioc, "\tscan devices: volumes complete\n"); |
f92363d1 SR |
9155 | |
9156 | skip_to_sas: | |
9157 | ||
919d8a3f | 9158 | ioc_info(ioc, "\tscan devices: end devices start\n"); |
f92363d1 SR |
9159 | |
9160 | /* sas devices */ | |
9161 | handle = 0xFFFF; | |
9162 | while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
9163 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | |
9164 | handle))) { | |
9165 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9166 | MPI2_IOCSTATUS_MASK; | |
f92363d1 | 9167 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
919d8a3f JP |
9168 | ioc_info(ioc, "\tbreak from end device scan: ioc_status(0x%04x), loginfo(0x%08x)\n", |
9169 | ioc_status, le32_to_cpu(mpi_reply.IOCLogInfo)); | |
f92363d1 SR |
9170 | break; |
9171 | } | |
9172 | handle = le16_to_cpu(sas_device_pg0.DevHandle); | |
9173 | if (!(_scsih_is_end_device( | |
9174 | le32_to_cpu(sas_device_pg0.DeviceInfo)))) | |
9175 | continue; | |
d1cb5e49 | 9176 | sas_device = mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 | 9177 | le64_to_cpu(sas_device_pg0.SASAddress)); |
d1cb5e49 SR |
9178 | if (sas_device) { |
9179 | sas_device_put(sas_device); | |
f92363d1 | 9180 | continue; |
d1cb5e49 | 9181 | } |
f92363d1 SR |
9182 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
9183 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) { | |
919d8a3f JP |
9184 | ioc_info(ioc, "\tBEFORE adding end device: handle (0x%04x), sas_addr(0x%016llx)\n", |
9185 | handle, | |
9186 | (u64)le64_to_cpu(sas_device_pg0.SASAddress)); | |
f92363d1 SR |
9187 | mpt3sas_transport_update_links(ioc, sas_address, handle, |
9188 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | |
9189 | retry_count = 0; | |
9190 | /* This will retry adding the end device. | |
9191 | * _scsih_add_device() will decide on retries and | |
9192 | * return "1" when it should be retried | |
9193 | */ | |
9194 | while (_scsih_add_device(ioc, handle, retry_count++, | |
9195 | 0)) { | |
9196 | ssleep(1); | |
9197 | } | |
919d8a3f JP |
9198 | ioc_info(ioc, "\tAFTER adding end device: handle (0x%04x), sas_addr(0x%016llx)\n", |
9199 | handle, | |
9200 | (u64)le64_to_cpu(sas_device_pg0.SASAddress)); | |
f92363d1 SR |
9201 | } |
9202 | } | |
919d8a3f JP |
9203 | ioc_info(ioc, "\tscan devices: end devices complete\n"); |
9204 | ioc_info(ioc, "\tscan devices: pcie end devices start\n"); | |
ec051e5a SPS |
9205 | |
9206 | /* pcie devices */ | |
9207 | handle = 0xFFFF; | |
9208 | while (!(mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply, | |
9209 | &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | |
9210 | handle))) { | |
9211 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) | |
9212 | & MPI2_IOCSTATUS_MASK; | |
9213 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
919d8a3f JP |
9214 | ioc_info(ioc, "\tbreak from pcie end device scan: ioc_status(0x%04x), loginfo(0x%08x)\n", |
9215 | ioc_status, le32_to_cpu(mpi_reply.IOCLogInfo)); | |
ec051e5a SPS |
9216 | break; |
9217 | } | |
9218 | handle = le16_to_cpu(pcie_device_pg0.DevHandle); | |
5bb309db | 9219 | if (!(_scsih_is_nvme_pciescsi_device( |
ec051e5a SPS |
9220 | le32_to_cpu(pcie_device_pg0.DeviceInfo)))) |
9221 | continue; | |
9222 | pcie_device = mpt3sas_get_pdev_by_wwid(ioc, | |
9223 | le64_to_cpu(pcie_device_pg0.WWID)); | |
9224 | if (pcie_device) { | |
9225 | pcie_device_put(pcie_device); | |
9226 | continue; | |
9227 | } | |
9228 | retry_count = 0; | |
9229 | parent_handle = le16_to_cpu(pcie_device_pg0.ParentDevHandle); | |
9230 | _scsih_pcie_add_device(ioc, handle); | |
f92363d1 | 9231 | |
919d8a3f JP |
9232 | ioc_info(ioc, "\tAFTER adding pcie end device: handle (0x%04x), wwid(0x%016llx)\n", |
9233 | handle, (u64)le64_to_cpu(pcie_device_pg0.WWID)); | |
ec051e5a | 9234 | } |
919d8a3f JP |
9235 | ioc_info(ioc, "\tpcie devices: pcie end devices complete\n"); |
9236 | ioc_info(ioc, "scan devices: complete\n"); | |
f92363d1 | 9237 | } |
c7a35705 | 9238 | |
f92363d1 SR |
9239 | /** |
9240 | * mpt3sas_scsih_reset_handler - reset callback handler (for scsih) | |
9241 | * @ioc: per adapter object | |
f92363d1 SR |
9242 | * |
9243 | * The handler for doing any required cleanup or initialization. | |
c7a35705 BVA |
9244 | */ |
9245 | void mpt3sas_scsih_pre_reset_handler(struct MPT3SAS_ADAPTER *ioc) | |
9246 | { | |
919d8a3f | 9247 | dtmprintk(ioc, ioc_info(ioc, "%s: MPT3_IOC_PRE_RESET\n", __func__)); |
c7a35705 BVA |
9248 | } |
9249 | ||
9250 | /** | |
9251 | * mpt3sas_scsih_after_reset_handler - reset callback handler (for scsih) | |
9252 | * @ioc: per adapter object | |
f92363d1 | 9253 | * |
c7a35705 | 9254 | * The handler for doing any required cleanup or initialization. |
f92363d1 SR |
9255 | */ |
9256 | void | |
c7a35705 | 9257 | mpt3sas_scsih_after_reset_handler(struct MPT3SAS_ADAPTER *ioc) |
f92363d1 | 9258 | { |
919d8a3f | 9259 | dtmprintk(ioc, ioc_info(ioc, "%s: MPT3_IOC_AFTER_RESET\n", __func__)); |
c7a35705 BVA |
9260 | if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) { |
9261 | ioc->scsih_cmds.status |= MPT3_CMD_RESET; | |
9262 | mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid); | |
9263 | complete(&ioc->scsih_cmds.done); | |
9264 | } | |
9265 | if (ioc->tm_cmds.status & MPT3_CMD_PENDING) { | |
9266 | ioc->tm_cmds.status |= MPT3_CMD_RESET; | |
9267 | mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid); | |
9268 | complete(&ioc->tm_cmds.done); | |
9269 | } | |
f92363d1 | 9270 | |
c7a35705 BVA |
9271 | memset(ioc->pend_os_device_add, 0, ioc->pend_os_device_add_sz); |
9272 | memset(ioc->device_remove_in_progress, 0, | |
9273 | ioc->device_remove_in_progress_sz); | |
9274 | _scsih_fw_event_cleanup_queue(ioc); | |
9275 | _scsih_flush_running_cmds(ioc); | |
9276 | } | |
9277 | ||
9278 | /** | |
9279 | * mpt3sas_scsih_reset_handler - reset callback handler (for scsih) | |
9280 | * @ioc: per adapter object | |
9281 | * | |
9282 | * The handler for doing any required cleanup or initialization. | |
9283 | */ | |
9284 | void | |
9285 | mpt3sas_scsih_reset_done_handler(struct MPT3SAS_ADAPTER *ioc) | |
9286 | { | |
919d8a3f | 9287 | dtmprintk(ioc, ioc_info(ioc, "%s: MPT3_IOC_DONE_RESET\n", __func__)); |
c7a35705 BVA |
9288 | if ((!ioc->is_driver_loading) && !(disable_discovery > 0 && |
9289 | !ioc->sas_hba.num_phys)) { | |
9290 | _scsih_prep_device_scan(ioc); | |
9291 | _scsih_create_enclosure_list_after_reset(ioc); | |
9292 | _scsih_search_responding_sas_devices(ioc); | |
9293 | _scsih_search_responding_pcie_devices(ioc); | |
9294 | _scsih_search_responding_raid_devices(ioc); | |
9295 | _scsih_search_responding_expanders(ioc); | |
9296 | _scsih_error_recovery_delete_devices(ioc); | |
f92363d1 SR |
9297 | } |
9298 | } | |
9299 | ||
9300 | /** | |
9301 | * _mpt3sas_fw_work - delayed task for processing firmware events | |
9302 | * @ioc: per adapter object | |
9303 | * @fw_event: The fw_event_work object | |
9304 | * Context: user. | |
f92363d1 SR |
9305 | */ |
9306 | static void | |
9307 | _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event) | |
9308 | { | |
146b16c8 SR |
9309 | _scsih_fw_event_del_from_list(ioc, fw_event); |
9310 | ||
f92363d1 | 9311 | /* the queue is being flushed so ignore this event */ |
146b16c8 SR |
9312 | if (ioc->remove_host || ioc->pci_error_recovery) { |
9313 | fw_event_work_put(fw_event); | |
f92363d1 SR |
9314 | return; |
9315 | } | |
9316 | ||
9317 | switch (fw_event->event) { | |
9318 | case MPT3SAS_PROCESS_TRIGGER_DIAG: | |
35b62362 JL |
9319 | mpt3sas_process_trigger_data(ioc, |
9320 | (struct SL_WH_TRIGGERS_EVENT_DATA_T *) | |
9321 | fw_event->event_data); | |
f92363d1 SR |
9322 | break; |
9323 | case MPT3SAS_REMOVE_UNRESPONDING_DEVICES: | |
146b16c8 SR |
9324 | while (scsi_host_in_recovery(ioc->shost) || |
9325 | ioc->shost_recovery) { | |
9326 | /* | |
9327 | * If we're unloading, bail. Otherwise, this can become | |
9328 | * an infinite loop. | |
9329 | */ | |
9330 | if (ioc->remove_host) | |
9331 | goto out; | |
f92363d1 | 9332 | ssleep(1); |
146b16c8 | 9333 | } |
3075ac49 | 9334 | _scsih_remove_unresponding_devices(ioc); |
f92363d1 SR |
9335 | _scsih_scan_for_devices_after_reset(ioc); |
9336 | break; | |
9337 | case MPT3SAS_PORT_ENABLE_COMPLETE: | |
9338 | ioc->start_scan = 0; | |
199fd79a | 9339 | if (missing_delay[0] != -1 && missing_delay[1] != -1) |
f92363d1 SR |
9340 | mpt3sas_base_update_missing_delay(ioc, missing_delay[0], |
9341 | missing_delay[1]); | |
919d8a3f JP |
9342 | dewtprintk(ioc, |
9343 | ioc_info(ioc, "port enable: complete from worker thread\n")); | |
f92363d1 | 9344 | break; |
0f624c39 SR |
9345 | case MPT3SAS_TURN_ON_PFA_LED: |
9346 | _scsih_turn_on_pfa_led(ioc, fw_event->device_handle); | |
f92363d1 SR |
9347 | break; |
9348 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: | |
9349 | _scsih_sas_topology_change_event(ioc, fw_event); | |
9350 | break; | |
9351 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: | |
9352 | _scsih_sas_device_status_change_event(ioc, fw_event); | |
9353 | break; | |
9354 | case MPI2_EVENT_SAS_DISCOVERY: | |
9355 | _scsih_sas_discovery_event(ioc, fw_event); | |
9356 | break; | |
95540b8e C |
9357 | case MPI2_EVENT_SAS_DEVICE_DISCOVERY_ERROR: |
9358 | _scsih_sas_device_discovery_error_event(ioc, fw_event); | |
9359 | break; | |
f92363d1 SR |
9360 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: |
9361 | _scsih_sas_broadcast_primitive_event(ioc, fw_event); | |
9362 | break; | |
9363 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: | |
9364 | _scsih_sas_enclosure_dev_status_change_event(ioc, | |
9365 | fw_event); | |
9366 | break; | |
9367 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: | |
9368 | _scsih_sas_ir_config_change_event(ioc, fw_event); | |
9369 | break; | |
9370 | case MPI2_EVENT_IR_VOLUME: | |
9371 | _scsih_sas_ir_volume_event(ioc, fw_event); | |
9372 | break; | |
9373 | case MPI2_EVENT_IR_PHYSICAL_DISK: | |
9374 | _scsih_sas_ir_physical_disk_event(ioc, fw_event); | |
9375 | break; | |
9376 | case MPI2_EVENT_IR_OPERATION_STATUS: | |
9377 | _scsih_sas_ir_operation_status_event(ioc, fw_event); | |
9378 | break; | |
4318c734 SPS |
9379 | case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE: |
9380 | _scsih_pcie_device_status_change_event(ioc, fw_event); | |
9381 | break; | |
9382 | case MPI2_EVENT_PCIE_ENUMERATION: | |
9383 | _scsih_pcie_enumeration_event(ioc, fw_event); | |
9384 | break; | |
9385 | case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST: | |
9386 | _scsih_pcie_topology_change_event(ioc, fw_event); | |
9387 | return; | |
9388 | break; | |
f92363d1 | 9389 | } |
146b16c8 SR |
9390 | out: |
9391 | fw_event_work_put(fw_event); | |
f92363d1 SR |
9392 | } |
9393 | ||
9394 | /** | |
9395 | * _firmware_event_work | |
f92363d1 SR |
9396 | * @work: The fw_event_work object |
9397 | * Context: user. | |
9398 | * | |
9399 | * wrappers for the work thread handling firmware events | |
f92363d1 SR |
9400 | */ |
9401 | ||
9402 | static void | |
9403 | _firmware_event_work(struct work_struct *work) | |
9404 | { | |
9405 | struct fw_event_work *fw_event = container_of(work, | |
9406 | struct fw_event_work, work); | |
9407 | ||
9408 | _mpt3sas_fw_work(fw_event->ioc, fw_event); | |
9409 | } | |
9410 | ||
9411 | /** | |
9412 | * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time) | |
9413 | * @ioc: per adapter object | |
9414 | * @msix_index: MSIX table index supplied by the OS | |
9415 | * @reply: reply message frame(lower 32bit addr) | |
9416 | * Context: interrupt. | |
9417 | * | |
9418 | * This function merely adds a new work task into ioc->firmware_event_thread. | |
9419 | * The tasks are worked from _firmware_event_work in user context. | |
9420 | * | |
4beb4867 BVA |
9421 | * Return: 1 meaning mf should be freed from _base_interrupt |
9422 | * 0 means the mf is freed from this function. | |
f92363d1 SR |
9423 | */ |
9424 | u8 | |
9425 | mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index, | |
9426 | u32 reply) | |
9427 | { | |
9428 | struct fw_event_work *fw_event; | |
9429 | Mpi2EventNotificationReply_t *mpi_reply; | |
9430 | u16 event; | |
9431 | u16 sz; | |
a470a51c | 9432 | Mpi26EventDataActiveCableExcept_t *ActiveCableEventData; |
f92363d1 | 9433 | |
79eb96d6 C |
9434 | /* events turned off due to host reset */ |
9435 | if (ioc->pci_error_recovery) | |
f92363d1 SR |
9436 | return 1; |
9437 | ||
9438 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
9439 | ||
9440 | if (unlikely(!mpi_reply)) { | |
919d8a3f JP |
9441 | ioc_err(ioc, "mpi_reply not valid at %s:%d/%s()!\n", |
9442 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
9443 | return 1; |
9444 | } | |
9445 | ||
9446 | event = le16_to_cpu(mpi_reply->Event); | |
9447 | ||
9448 | if (event != MPI2_EVENT_LOG_ENTRY_ADDED) | |
9449 | mpt3sas_trigger_event(ioc, event, 0); | |
9450 | ||
9451 | switch (event) { | |
9452 | /* handle these */ | |
9453 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: | |
9454 | { | |
9455 | Mpi2EventDataSasBroadcastPrimitive_t *baen_data = | |
9456 | (Mpi2EventDataSasBroadcastPrimitive_t *) | |
9457 | mpi_reply->EventData; | |
9458 | ||
9459 | if (baen_data->Primitive != | |
9460 | MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT) | |
9461 | return 1; | |
9462 | ||
9463 | if (ioc->broadcast_aen_busy) { | |
9464 | ioc->broadcast_aen_pending++; | |
9465 | return 1; | |
9466 | } else | |
9467 | ioc->broadcast_aen_busy = 1; | |
9468 | break; | |
9469 | } | |
9470 | ||
9471 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: | |
9472 | _scsih_check_topo_delete_events(ioc, | |
9473 | (Mpi2EventDataSasTopologyChangeList_t *) | |
9474 | mpi_reply->EventData); | |
9475 | break; | |
4318c734 SPS |
9476 | case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST: |
9477 | _scsih_check_pcie_topo_remove_events(ioc, | |
9478 | (Mpi26EventDataPCIeTopologyChangeList_t *) | |
9479 | mpi_reply->EventData); | |
9480 | break; | |
f92363d1 SR |
9481 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: |
9482 | _scsih_check_ir_config_unhide_events(ioc, | |
9483 | (Mpi2EventDataIrConfigChangeList_t *) | |
9484 | mpi_reply->EventData); | |
9485 | break; | |
9486 | case MPI2_EVENT_IR_VOLUME: | |
9487 | _scsih_check_volume_delete_events(ioc, | |
9488 | (Mpi2EventDataIrVolume_t *) | |
9489 | mpi_reply->EventData); | |
9490 | break; | |
7786ab6a SR |
9491 | case MPI2_EVENT_LOG_ENTRY_ADDED: |
9492 | { | |
9493 | Mpi2EventDataLogEntryAdded_t *log_entry; | |
9494 | u32 *log_code; | |
9495 | ||
9496 | if (!ioc->is_warpdrive) | |
9497 | break; | |
9498 | ||
9499 | log_entry = (Mpi2EventDataLogEntryAdded_t *) | |
9500 | mpi_reply->EventData; | |
9501 | log_code = (u32 *)log_entry->LogData; | |
f92363d1 | 9502 | |
7786ab6a SR |
9503 | if (le16_to_cpu(log_entry->LogEntryQualifier) |
9504 | != MPT2_WARPDRIVE_LOGENTRY) | |
9505 | break; | |
9506 | ||
9507 | switch (le32_to_cpu(*log_code)) { | |
9508 | case MPT2_WARPDRIVE_LC_SSDT: | |
919d8a3f | 9509 | ioc_warn(ioc, "WarpDrive Warning: IO Throttling has occurred in the WarpDrive subsystem. Check WarpDrive documentation for additional details.\n"); |
7786ab6a SR |
9510 | break; |
9511 | case MPT2_WARPDRIVE_LC_SSDLW: | |
919d8a3f | 9512 | ioc_warn(ioc, "WarpDrive Warning: Program/Erase Cycles for the WarpDrive subsystem in degraded range. Check WarpDrive documentation for additional details.\n"); |
7786ab6a SR |
9513 | break; |
9514 | case MPT2_WARPDRIVE_LC_SSDLF: | |
919d8a3f | 9515 | 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 |
9516 | break; |
9517 | case MPT2_WARPDRIVE_LC_BRMF: | |
919d8a3f | 9518 | 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 |
9519 | break; |
9520 | } | |
9521 | ||
9522 | break; | |
9523 | } | |
f92363d1 SR |
9524 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: |
9525 | case MPI2_EVENT_IR_OPERATION_STATUS: | |
9526 | case MPI2_EVENT_SAS_DISCOVERY: | |
95540b8e | 9527 | case MPI2_EVENT_SAS_DEVICE_DISCOVERY_ERROR: |
f92363d1 SR |
9528 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: |
9529 | case MPI2_EVENT_IR_PHYSICAL_DISK: | |
4318c734 SPS |
9530 | case MPI2_EVENT_PCIE_ENUMERATION: |
9531 | case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE: | |
f92363d1 SR |
9532 | break; |
9533 | ||
2d8ce8c9 SR |
9534 | case MPI2_EVENT_TEMP_THRESHOLD: |
9535 | _scsih_temp_threshold_events(ioc, | |
9536 | (Mpi2EventDataTemperature_t *) | |
9537 | mpi_reply->EventData); | |
9538 | break; | |
a470a51c C |
9539 | case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION: |
9540 | ActiveCableEventData = | |
9541 | (Mpi26EventDataActiveCableExcept_t *) mpi_reply->EventData; | |
6c44c0fe C |
9542 | switch (ActiveCableEventData->ReasonCode) { |
9543 | case MPI26_EVENT_ACTIVE_CABLE_INSUFFICIENT_POWER: | |
919d8a3f JP |
9544 | ioc_notice(ioc, "Currently an active cable with ReceptacleID %d\n", |
9545 | ActiveCableEventData->ReceptacleID); | |
b99b1993 SR |
9546 | pr_notice("cannot be powered and devices connected\n"); |
9547 | pr_notice("to this active cable will not be seen\n"); | |
9548 | pr_notice("This active cable requires %d mW of power\n", | |
6c44c0fe | 9549 | ActiveCableEventData->ActiveCablePowerRequirement); |
6c44c0fe C |
9550 | break; |
9551 | ||
9552 | case MPI26_EVENT_ACTIVE_CABLE_DEGRADED: | |
919d8a3f JP |
9553 | ioc_notice(ioc, "Currently a cable with ReceptacleID %d\n", |
9554 | ActiveCableEventData->ReceptacleID); | |
b99b1993 SR |
9555 | pr_notice( |
9556 | "is not running at optimal speed(12 Gb/s rate)\n"); | |
6c44c0fe | 9557 | break; |
7ebd67e0 | 9558 | } |
6c44c0fe | 9559 | |
a470a51c | 9560 | break; |
2d8ce8c9 | 9561 | |
f92363d1 SR |
9562 | default: /* ignore the rest */ |
9563 | return 1; | |
9564 | } | |
9565 | ||
f92363d1 | 9566 | sz = le16_to_cpu(mpi_reply->EventDataLength) * 4; |
146b16c8 | 9567 | fw_event = alloc_fw_event_work(sz); |
35b62362 | 9568 | if (!fw_event) { |
919d8a3f JP |
9569 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
9570 | __FILE__, __LINE__, __func__); | |
f92363d1 SR |
9571 | return 1; |
9572 | } | |
9573 | ||
9574 | memcpy(fw_event->event_data, mpi_reply->EventData, sz); | |
9575 | fw_event->ioc = ioc; | |
9576 | fw_event->VF_ID = mpi_reply->VF_ID; | |
9577 | fw_event->VP_ID = mpi_reply->VP_ID; | |
9578 | fw_event->event = event; | |
9579 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 | 9580 | fw_event_work_put(fw_event); |
f92363d1 SR |
9581 | return 1; |
9582 | } | |
9583 | ||
f92363d1 SR |
9584 | /** |
9585 | * _scsih_expander_node_remove - removing expander device from list. | |
9586 | * @ioc: per adapter object | |
9587 | * @sas_expander: the sas_device object | |
f92363d1 SR |
9588 | * |
9589 | * Removing object and freeing associated memory from the | |
9590 | * ioc->sas_expander_list. | |
f92363d1 SR |
9591 | */ |
9592 | static void | |
9593 | _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc, | |
9594 | struct _sas_node *sas_expander) | |
9595 | { | |
9596 | struct _sas_port *mpt3sas_port, *next; | |
bbe3def3 | 9597 | unsigned long flags; |
f92363d1 SR |
9598 | |
9599 | /* remove sibling ports attached to this expander */ | |
9600 | list_for_each_entry_safe(mpt3sas_port, next, | |
9601 | &sas_expander->sas_port_list, port_list) { | |
9602 | if (ioc->shost_recovery) | |
9603 | return; | |
9604 | if (mpt3sas_port->remote_identify.device_type == | |
9605 | SAS_END_DEVICE) | |
9606 | mpt3sas_device_remove_by_sas_address(ioc, | |
9607 | mpt3sas_port->remote_identify.sas_address); | |
9608 | else if (mpt3sas_port->remote_identify.device_type == | |
9609 | SAS_EDGE_EXPANDER_DEVICE || | |
9610 | mpt3sas_port->remote_identify.device_type == | |
9611 | SAS_FANOUT_EXPANDER_DEVICE) | |
9612 | mpt3sas_expander_remove(ioc, | |
9613 | mpt3sas_port->remote_identify.sas_address); | |
9614 | } | |
9615 | ||
9616 | mpt3sas_transport_port_remove(ioc, sas_expander->sas_address, | |
9617 | sas_expander->sas_address_parent); | |
9618 | ||
919d8a3f JP |
9619 | ioc_info(ioc, "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n", |
9620 | sas_expander->handle, (unsigned long long) | |
9621 | sas_expander->sas_address); | |
f92363d1 | 9622 | |
bbe3def3 SR |
9623 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
9624 | list_del(&sas_expander->list); | |
9625 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
9626 | ||
f92363d1 SR |
9627 | kfree(sas_expander->phy); |
9628 | kfree(sas_expander); | |
9629 | } | |
9630 | ||
9631 | /** | |
9632 | * _scsih_ir_shutdown - IR shutdown notification | |
9633 | * @ioc: per adapter object | |
9634 | * | |
9635 | * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that | |
9636 | * the host system is shutting down. | |
f92363d1 SR |
9637 | */ |
9638 | static void | |
9639 | _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc) | |
9640 | { | |
9641 | Mpi2RaidActionRequest_t *mpi_request; | |
9642 | Mpi2RaidActionReply_t *mpi_reply; | |
9643 | u16 smid; | |
9644 | ||
9645 | /* is IR firmware build loaded ? */ | |
9646 | if (!ioc->ir_firmware) | |
9647 | return; | |
9648 | ||
9649 | /* are there any volumes ? */ | |
9650 | if (list_empty(&ioc->raid_device_list)) | |
9651 | return; | |
9652 | ||
9653 | mutex_lock(&ioc->scsih_cmds.mutex); | |
9654 | ||
9655 | if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) { | |
919d8a3f | 9656 | ioc_err(ioc, "%s: scsih_cmd in use\n", __func__); |
f92363d1 SR |
9657 | goto out; |
9658 | } | |
9659 | ioc->scsih_cmds.status = MPT3_CMD_PENDING; | |
9660 | ||
9661 | smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx); | |
9662 | if (!smid) { | |
919d8a3f | 9663 | ioc_err(ioc, "%s: failed obtaining a smid\n", __func__); |
f92363d1 SR |
9664 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; |
9665 | goto out; | |
9666 | } | |
9667 | ||
9668 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
9669 | ioc->scsih_cmds.smid = smid; | |
9670 | memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t)); | |
9671 | ||
9672 | mpi_request->Function = MPI2_FUNCTION_RAID_ACTION; | |
9673 | mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED; | |
9674 | ||
7786ab6a | 9675 | if (!ioc->hide_ir_msg) |
919d8a3f | 9676 | ioc_info(ioc, "IR shutdown (sending)\n"); |
f92363d1 | 9677 | init_completion(&ioc->scsih_cmds.done); |
078a4cc1 | 9678 | ioc->put_smid_default(ioc, smid); |
f92363d1 SR |
9679 | wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ); |
9680 | ||
9681 | if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) { | |
919d8a3f | 9682 | ioc_err(ioc, "%s: timeout\n", __func__); |
f92363d1 SR |
9683 | goto out; |
9684 | } | |
9685 | ||
9686 | if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) { | |
9687 | mpi_reply = ioc->scsih_cmds.reply; | |
7786ab6a | 9688 | if (!ioc->hide_ir_msg) |
919d8a3f JP |
9689 | ioc_info(ioc, "IR shutdown (complete): ioc_status(0x%04x), loginfo(0x%08x)\n", |
9690 | le16_to_cpu(mpi_reply->IOCStatus), | |
9691 | le32_to_cpu(mpi_reply->IOCLogInfo)); | |
f92363d1 SR |
9692 | } |
9693 | ||
9694 | out: | |
9695 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
9696 | mutex_unlock(&ioc->scsih_cmds.mutex); | |
9697 | } | |
9698 | ||
9699 | /** | |
8a7e4c24 | 9700 | * scsih_remove - detach and remove add host |
f92363d1 SR |
9701 | * @pdev: PCI device struct |
9702 | * | |
9703 | * Routine called when unloading the driver. | |
f92363d1 | 9704 | */ |
8bbb1cf6 | 9705 | static void scsih_remove(struct pci_dev *pdev) |
f92363d1 SR |
9706 | { |
9707 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9708 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
9709 | struct _sas_port *mpt3sas_port, *next_port; | |
9710 | struct _raid_device *raid_device, *next; | |
9711 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
3075ac49 | 9712 | struct _pcie_device *pcie_device, *pcienext; |
f92363d1 SR |
9713 | struct workqueue_struct *wq; |
9714 | unsigned long flags; | |
2426f209 | 9715 | Mpi2ConfigReply_t mpi_reply; |
f92363d1 SR |
9716 | |
9717 | ioc->remove_host = 1; | |
c666d3be SR |
9718 | |
9719 | mpt3sas_wait_for_commands_to_complete(ioc); | |
9720 | _scsih_flush_running_cmds(ioc); | |
9721 | ||
f92363d1 SR |
9722 | _scsih_fw_event_cleanup_queue(ioc); |
9723 | ||
9724 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
9725 | wq = ioc->firmware_event_thread; | |
9726 | ioc->firmware_event_thread = NULL; | |
9727 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
9728 | if (wq) | |
9729 | destroy_workqueue(wq); | |
2426f209 SP |
9730 | /* |
9731 | * Copy back the unmodified ioc page1. so that on next driver load, | |
9732 | * current modified changes on ioc page1 won't take effect. | |
9733 | */ | |
9734 | if (ioc->is_aero_ioc) | |
9735 | mpt3sas_config_set_ioc_pg1(ioc, &mpi_reply, | |
9736 | &ioc->ioc_pg1_copy); | |
f92363d1 SR |
9737 | /* release all the volumes */ |
9738 | _scsih_ir_shutdown(ioc); | |
dc730212 | 9739 | sas_remove_host(shost); |
f92363d1 SR |
9740 | list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list, |
9741 | list) { | |
9742 | if (raid_device->starget) { | |
9743 | sas_target_priv_data = | |
9744 | raid_device->starget->hostdata; | |
9745 | sas_target_priv_data->deleted = 1; | |
9746 | scsi_remove_target(&raid_device->starget->dev); | |
9747 | } | |
919d8a3f JP |
9748 | ioc_info(ioc, "removing handle(0x%04x), wwid(0x%016llx)\n", |
9749 | raid_device->handle, (u64)raid_device->wwid); | |
f92363d1 SR |
9750 | _scsih_raid_device_remove(ioc, raid_device); |
9751 | } | |
3075ac49 SPS |
9752 | list_for_each_entry_safe(pcie_device, pcienext, &ioc->pcie_device_list, |
9753 | list) { | |
9754 | _scsih_pcie_device_remove_from_sml(ioc, pcie_device); | |
9755 | list_del_init(&pcie_device->list); | |
9756 | pcie_device_put(pcie_device); | |
9757 | } | |
f92363d1 SR |
9758 | |
9759 | /* free ports attached to the sas_host */ | |
9760 | list_for_each_entry_safe(mpt3sas_port, next_port, | |
9761 | &ioc->sas_hba.sas_port_list, port_list) { | |
9762 | if (mpt3sas_port->remote_identify.device_type == | |
9763 | SAS_END_DEVICE) | |
9764 | mpt3sas_device_remove_by_sas_address(ioc, | |
9765 | mpt3sas_port->remote_identify.sas_address); | |
9766 | else if (mpt3sas_port->remote_identify.device_type == | |
9767 | SAS_EDGE_EXPANDER_DEVICE || | |
9768 | mpt3sas_port->remote_identify.device_type == | |
9769 | SAS_FANOUT_EXPANDER_DEVICE) | |
9770 | mpt3sas_expander_remove(ioc, | |
9771 | mpt3sas_port->remote_identify.sas_address); | |
9772 | } | |
9773 | ||
9774 | /* free phys attached to the sas_host */ | |
9775 | if (ioc->sas_hba.num_phys) { | |
9776 | kfree(ioc->sas_hba.phy); | |
9777 | ioc->sas_hba.phy = NULL; | |
9778 | ioc->sas_hba.num_phys = 0; | |
9779 | } | |
9780 | ||
f92363d1 | 9781 | mpt3sas_base_detach(ioc); |
08c4d550 | 9782 | spin_lock(&gioc_lock); |
f92363d1 | 9783 | list_del(&ioc->list); |
08c4d550 | 9784 | spin_unlock(&gioc_lock); |
f92363d1 SR |
9785 | scsi_host_put(shost); |
9786 | } | |
9787 | ||
9788 | /** | |
8a7e4c24 | 9789 | * scsih_shutdown - routine call during system shutdown |
f92363d1 | 9790 | * @pdev: PCI device struct |
f92363d1 | 9791 | */ |
8bbb1cf6 | 9792 | static void |
8a7e4c24 | 9793 | scsih_shutdown(struct pci_dev *pdev) |
f92363d1 SR |
9794 | { |
9795 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9796 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
9797 | struct workqueue_struct *wq; | |
9798 | unsigned long flags; | |
2426f209 | 9799 | Mpi2ConfigReply_t mpi_reply; |
f92363d1 SR |
9800 | |
9801 | ioc->remove_host = 1; | |
c666d3be SR |
9802 | |
9803 | mpt3sas_wait_for_commands_to_complete(ioc); | |
9804 | _scsih_flush_running_cmds(ioc); | |
9805 | ||
f92363d1 SR |
9806 | _scsih_fw_event_cleanup_queue(ioc); |
9807 | ||
9808 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
9809 | wq = ioc->firmware_event_thread; | |
9810 | ioc->firmware_event_thread = NULL; | |
9811 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
9812 | if (wq) | |
9813 | destroy_workqueue(wq); | |
2426f209 SP |
9814 | /* |
9815 | * Copy back the unmodified ioc page1 so that on next driver load, | |
9816 | * current modified changes on ioc page1 won't take effect. | |
9817 | */ | |
9818 | if (ioc->is_aero_ioc) | |
9819 | mpt3sas_config_set_ioc_pg1(ioc, &mpi_reply, | |
9820 | &ioc->ioc_pg1_copy); | |
f92363d1 SR |
9821 | |
9822 | _scsih_ir_shutdown(ioc); | |
9823 | mpt3sas_base_detach(ioc); | |
9824 | } | |
9825 | ||
9826 | ||
9827 | /** | |
9828 | * _scsih_probe_boot_devices - reports 1st device | |
9829 | * @ioc: per adapter object | |
9830 | * | |
9831 | * If specified in bios page 2, this routine reports the 1st | |
9832 | * device scsi-ml or sas transport for persistent boot device | |
9833 | * purposes. Please refer to function _scsih_determine_boot_device() | |
9834 | */ | |
9835 | static void | |
9836 | _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc) | |
9837 | { | |
d88e1eab | 9838 | u32 channel; |
f92363d1 SR |
9839 | void *device; |
9840 | struct _sas_device *sas_device; | |
9841 | struct _raid_device *raid_device; | |
d88e1eab | 9842 | struct _pcie_device *pcie_device; |
f92363d1 SR |
9843 | u16 handle; |
9844 | u64 sas_address_parent; | |
9845 | u64 sas_address; | |
9846 | unsigned long flags; | |
9847 | int rc; | |
d88e1eab | 9848 | int tid; |
f92363d1 SR |
9849 | |
9850 | /* no Bios, return immediately */ | |
9851 | if (!ioc->bios_pg3.BiosVersion) | |
9852 | return; | |
9853 | ||
9854 | device = NULL; | |
f92363d1 SR |
9855 | if (ioc->req_boot_device.device) { |
9856 | device = ioc->req_boot_device.device; | |
d88e1eab | 9857 | channel = ioc->req_boot_device.channel; |
f92363d1 SR |
9858 | } else if (ioc->req_alt_boot_device.device) { |
9859 | device = ioc->req_alt_boot_device.device; | |
d88e1eab | 9860 | channel = ioc->req_alt_boot_device.channel; |
f92363d1 SR |
9861 | } else if (ioc->current_boot_device.device) { |
9862 | device = ioc->current_boot_device.device; | |
d88e1eab | 9863 | channel = ioc->current_boot_device.channel; |
f92363d1 SR |
9864 | } |
9865 | ||
9866 | if (!device) | |
9867 | return; | |
9868 | ||
d88e1eab | 9869 | if (channel == RAID_CHANNEL) { |
f92363d1 SR |
9870 | raid_device = device; |
9871 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
9872 | raid_device->id, 0); | |
9873 | if (rc) | |
9874 | _scsih_raid_device_remove(ioc, raid_device); | |
d88e1eab SPS |
9875 | } else if (channel == PCIE_CHANNEL) { |
9876 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
9877 | pcie_device = device; | |
9878 | tid = pcie_device->id; | |
9879 | list_move_tail(&pcie_device->list, &ioc->pcie_device_list); | |
9880 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
9881 | rc = scsi_add_device(ioc->shost, PCIE_CHANNEL, tid, 0); | |
9882 | if (rc) | |
9883 | _scsih_pcie_device_remove(ioc, pcie_device); | |
f92363d1 SR |
9884 | } else { |
9885 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
9886 | sas_device = device; | |
9887 | handle = sas_device->handle; | |
9888 | sas_address_parent = sas_device->sas_address_parent; | |
9889 | sas_address = sas_device->sas_address; | |
9890 | list_move_tail(&sas_device->list, &ioc->sas_device_list); | |
9891 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
9892 | ||
7786ab6a SR |
9893 | if (ioc->hide_drives) |
9894 | return; | |
f92363d1 SR |
9895 | if (!mpt3sas_transport_port_add(ioc, handle, |
9896 | sas_address_parent)) { | |
9897 | _scsih_sas_device_remove(ioc, sas_device); | |
9898 | } else if (!sas_device->starget) { | |
f5edbe77 SR |
9899 | if (!ioc->is_driver_loading) { |
9900 | mpt3sas_transport_port_remove(ioc, | |
9901 | sas_address, | |
f92363d1 | 9902 | sas_address_parent); |
f5edbe77 SR |
9903 | _scsih_sas_device_remove(ioc, sas_device); |
9904 | } | |
f92363d1 SR |
9905 | } |
9906 | } | |
9907 | } | |
9908 | ||
9909 | /** | |
9910 | * _scsih_probe_raid - reporting raid volumes to scsi-ml | |
9911 | * @ioc: per adapter object | |
9912 | * | |
9913 | * Called during initial loading of the driver. | |
9914 | */ | |
9915 | static void | |
9916 | _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc) | |
9917 | { | |
9918 | struct _raid_device *raid_device, *raid_next; | |
9919 | int rc; | |
9920 | ||
9921 | list_for_each_entry_safe(raid_device, raid_next, | |
9922 | &ioc->raid_device_list, list) { | |
9923 | if (raid_device->starget) | |
9924 | continue; | |
9925 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
9926 | raid_device->id, 0); | |
9927 | if (rc) | |
9928 | _scsih_raid_device_remove(ioc, raid_device); | |
9929 | } | |
9930 | } | |
9931 | ||
d1cb5e49 SR |
9932 | static struct _sas_device *get_next_sas_device(struct MPT3SAS_ADAPTER *ioc) |
9933 | { | |
9934 | struct _sas_device *sas_device = NULL; | |
9935 | unsigned long flags; | |
9936 | ||
9937 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
9938 | if (!list_empty(&ioc->sas_device_init_list)) { | |
9939 | sas_device = list_first_entry(&ioc->sas_device_init_list, | |
9940 | struct _sas_device, list); | |
9941 | sas_device_get(sas_device); | |
9942 | } | |
9943 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
9944 | ||
9945 | return sas_device; | |
9946 | } | |
9947 | ||
9948 | static void sas_device_make_active(struct MPT3SAS_ADAPTER *ioc, | |
9949 | struct _sas_device *sas_device) | |
9950 | { | |
9951 | unsigned long flags; | |
9952 | ||
9953 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
9954 | ||
9955 | /* | |
9956 | * Since we dropped the lock during the call to port_add(), we need to | |
9957 | * be careful here that somebody else didn't move or delete this item | |
9958 | * while we were busy with other things. | |
9959 | * | |
9960 | * If it was on the list, we need a put() for the reference the list | |
9961 | * had. Either way, we need a get() for the destination list. | |
9962 | */ | |
9963 | if (!list_empty(&sas_device->list)) { | |
9964 | list_del_init(&sas_device->list); | |
9965 | sas_device_put(sas_device); | |
9966 | } | |
9967 | ||
9968 | sas_device_get(sas_device); | |
9969 | list_add_tail(&sas_device->list, &ioc->sas_device_list); | |
9970 | ||
9971 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
9972 | } | |
9973 | ||
f92363d1 SR |
9974 | /** |
9975 | * _scsih_probe_sas - reporting sas devices to sas transport | |
9976 | * @ioc: per adapter object | |
9977 | * | |
9978 | * Called during initial loading of the driver. | |
9979 | */ | |
9980 | static void | |
9981 | _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc) | |
9982 | { | |
d1cb5e49 | 9983 | struct _sas_device *sas_device; |
f92363d1 | 9984 | |
d1cb5e49 SR |
9985 | if (ioc->hide_drives) |
9986 | return; | |
7786ab6a | 9987 | |
d1cb5e49 | 9988 | while ((sas_device = get_next_sas_device(ioc))) { |
f92363d1 SR |
9989 | if (!mpt3sas_transport_port_add(ioc, sas_device->handle, |
9990 | sas_device->sas_address_parent)) { | |
d1cb5e49 SR |
9991 | _scsih_sas_device_remove(ioc, sas_device); |
9992 | sas_device_put(sas_device); | |
f92363d1 SR |
9993 | continue; |
9994 | } else if (!sas_device->starget) { | |
9995 | /* | |
9996 | * When asyn scanning is enabled, its not possible to | |
9997 | * remove devices while scanning is turned on due to an | |
9998 | * oops in scsi_sysfs_add_sdev()->add_device()-> | |
9999 | * sysfs_addrm_start() | |
10000 | */ | |
f5edbe77 | 10001 | if (!ioc->is_driver_loading) { |
f92363d1 SR |
10002 | mpt3sas_transport_port_remove(ioc, |
10003 | sas_device->sas_address, | |
10004 | sas_device->sas_address_parent); | |
d1cb5e49 SR |
10005 | _scsih_sas_device_remove(ioc, sas_device); |
10006 | sas_device_put(sas_device); | |
f5edbe77 SR |
10007 | continue; |
10008 | } | |
f92363d1 | 10009 | } |
d1cb5e49 SR |
10010 | sas_device_make_active(ioc, sas_device); |
10011 | sas_device_put(sas_device); | |
f92363d1 SR |
10012 | } |
10013 | } | |
10014 | ||
d88e1eab SPS |
10015 | /** |
10016 | * get_next_pcie_device - Get the next pcie device | |
10017 | * @ioc: per adapter object | |
10018 | * | |
10019 | * Get the next pcie device from pcie_device_init_list list. | |
10020 | * | |
4beb4867 | 10021 | * Return: pcie device structure if pcie_device_init_list list is not empty |
d88e1eab SPS |
10022 | * otherwise returns NULL |
10023 | */ | |
10024 | static struct _pcie_device *get_next_pcie_device(struct MPT3SAS_ADAPTER *ioc) | |
10025 | { | |
10026 | struct _pcie_device *pcie_device = NULL; | |
10027 | unsigned long flags; | |
10028 | ||
10029 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
10030 | if (!list_empty(&ioc->pcie_device_init_list)) { | |
10031 | pcie_device = list_first_entry(&ioc->pcie_device_init_list, | |
10032 | struct _pcie_device, list); | |
10033 | pcie_device_get(pcie_device); | |
10034 | } | |
10035 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
10036 | ||
10037 | return pcie_device; | |
10038 | } | |
10039 | ||
10040 | /** | |
10041 | * pcie_device_make_active - Add pcie device to pcie_device_list list | |
10042 | * @ioc: per adapter object | |
10043 | * @pcie_device: pcie device object | |
10044 | * | |
10045 | * Add the pcie device which has registered with SCSI Transport Later to | |
10046 | * pcie_device_list list | |
10047 | */ | |
10048 | static void pcie_device_make_active(struct MPT3SAS_ADAPTER *ioc, | |
10049 | struct _pcie_device *pcie_device) | |
10050 | { | |
10051 | unsigned long flags; | |
10052 | ||
10053 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
10054 | ||
10055 | if (!list_empty(&pcie_device->list)) { | |
10056 | list_del_init(&pcie_device->list); | |
10057 | pcie_device_put(pcie_device); | |
10058 | } | |
10059 | pcie_device_get(pcie_device); | |
10060 | list_add_tail(&pcie_device->list, &ioc->pcie_device_list); | |
10061 | ||
10062 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
10063 | } | |
10064 | ||
10065 | /** | |
10066 | * _scsih_probe_pcie - reporting PCIe devices to scsi-ml | |
10067 | * @ioc: per adapter object | |
10068 | * | |
10069 | * Called during initial loading of the driver. | |
10070 | */ | |
10071 | static void | |
10072 | _scsih_probe_pcie(struct MPT3SAS_ADAPTER *ioc) | |
10073 | { | |
10074 | struct _pcie_device *pcie_device; | |
10075 | int rc; | |
10076 | ||
10077 | /* PCIe Device List */ | |
10078 | while ((pcie_device = get_next_pcie_device(ioc))) { | |
10079 | if (pcie_device->starget) { | |
10080 | pcie_device_put(pcie_device); | |
10081 | continue; | |
10082 | } | |
3c090ce3 SP |
10083 | if (pcie_device->access_status == |
10084 | MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED) { | |
10085 | pcie_device_make_active(ioc, pcie_device); | |
10086 | pcie_device_put(pcie_device); | |
10087 | continue; | |
10088 | } | |
d88e1eab SPS |
10089 | rc = scsi_add_device(ioc->shost, PCIE_CHANNEL, |
10090 | pcie_device->id, 0); | |
10091 | if (rc) { | |
10092 | _scsih_pcie_device_remove(ioc, pcie_device); | |
10093 | pcie_device_put(pcie_device); | |
10094 | continue; | |
10095 | } else if (!pcie_device->starget) { | |
10096 | /* | |
10097 | * When async scanning is enabled, its not possible to | |
10098 | * remove devices while scanning is turned on due to an | |
10099 | * oops in scsi_sysfs_add_sdev()->add_device()-> | |
10100 | * sysfs_addrm_start() | |
10101 | */ | |
10102 | if (!ioc->is_driver_loading) { | |
10103 | /* TODO-- Need to find out whether this condition will | |
10104 | * occur or not | |
10105 | */ | |
10106 | _scsih_pcie_device_remove(ioc, pcie_device); | |
10107 | pcie_device_put(pcie_device); | |
10108 | continue; | |
10109 | } | |
10110 | } | |
10111 | pcie_device_make_active(ioc, pcie_device); | |
10112 | pcie_device_put(pcie_device); | |
10113 | } | |
10114 | } | |
10115 | ||
f92363d1 SR |
10116 | /** |
10117 | * _scsih_probe_devices - probing for devices | |
10118 | * @ioc: per adapter object | |
10119 | * | |
10120 | * Called during initial loading of the driver. | |
10121 | */ | |
10122 | static void | |
10123 | _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc) | |
10124 | { | |
10125 | u16 volume_mapping_flags; | |
10126 | ||
10127 | if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR)) | |
10128 | return; /* return when IOC doesn't support initiator mode */ | |
10129 | ||
10130 | _scsih_probe_boot_devices(ioc); | |
10131 | ||
10132 | if (ioc->ir_firmware) { | |
10133 | volume_mapping_flags = | |
10134 | le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) & | |
10135 | MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE; | |
10136 | if (volume_mapping_flags == | |
10137 | MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) { | |
10138 | _scsih_probe_raid(ioc); | |
10139 | _scsih_probe_sas(ioc); | |
10140 | } else { | |
10141 | _scsih_probe_sas(ioc); | |
10142 | _scsih_probe_raid(ioc); | |
10143 | } | |
d88e1eab | 10144 | } else { |
f92363d1 | 10145 | _scsih_probe_sas(ioc); |
d88e1eab SPS |
10146 | _scsih_probe_pcie(ioc); |
10147 | } | |
f92363d1 SR |
10148 | } |
10149 | ||
10150 | /** | |
8a7e4c24 | 10151 | * scsih_scan_start - scsi lld callback for .scan_start |
f92363d1 SR |
10152 | * @shost: SCSI host pointer |
10153 | * | |
10154 | * The shost has the ability to discover targets on its own instead | |
10155 | * of scanning the entire bus. In our implemention, we will kick off | |
10156 | * firmware discovery. | |
10157 | */ | |
8bbb1cf6 | 10158 | static void |
8a7e4c24 | 10159 | scsih_scan_start(struct Scsi_Host *shost) |
f92363d1 SR |
10160 | { |
10161 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10162 | int rc; | |
10163 | if (diag_buffer_enable != -1 && diag_buffer_enable != 0) | |
10164 | mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable); | |
10165 | ||
10166 | if (disable_discovery > 0) | |
10167 | return; | |
10168 | ||
10169 | ioc->start_scan = 1; | |
10170 | rc = mpt3sas_port_enable(ioc); | |
10171 | ||
10172 | if (rc != 0) | |
919d8a3f | 10173 | ioc_info(ioc, "port enable: FAILED\n"); |
f92363d1 SR |
10174 | } |
10175 | ||
10176 | /** | |
8a7e4c24 | 10177 | * scsih_scan_finished - scsi lld callback for .scan_finished |
f92363d1 SR |
10178 | * @shost: SCSI host pointer |
10179 | * @time: elapsed time of the scan in jiffies | |
10180 | * | |
10181 | * This function will be called periodicallyn until it returns 1 with the | |
10182 | * scsi_host and the elapsed time of the scan in jiffies. In our implemention, | |
10183 | * we wait for firmware discovery to complete, then return 1. | |
10184 | */ | |
8bbb1cf6 | 10185 | static int |
8a7e4c24 | 10186 | scsih_scan_finished(struct Scsi_Host *shost, unsigned long time) |
f92363d1 SR |
10187 | { |
10188 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10189 | ||
10190 | if (disable_discovery > 0) { | |
10191 | ioc->is_driver_loading = 0; | |
10192 | ioc->wait_for_discovery_to_complete = 0; | |
10193 | return 1; | |
10194 | } | |
10195 | ||
10196 | if (time >= (300 * HZ)) { | |
e3586147 | 10197 | ioc->port_enable_cmds.status = MPT3_CMD_NOT_USED; |
919d8a3f | 10198 | ioc_info(ioc, "port enable: FAILED with timeout (timeout=300s)\n"); |
f92363d1 SR |
10199 | ioc->is_driver_loading = 0; |
10200 | return 1; | |
10201 | } | |
10202 | ||
10203 | if (ioc->start_scan) | |
10204 | return 0; | |
10205 | ||
10206 | if (ioc->start_scan_failed) { | |
919d8a3f JP |
10207 | ioc_info(ioc, "port enable: FAILED with (ioc_status=0x%08x)\n", |
10208 | ioc->start_scan_failed); | |
f92363d1 SR |
10209 | ioc->is_driver_loading = 0; |
10210 | ioc->wait_for_discovery_to_complete = 0; | |
10211 | ioc->remove_host = 1; | |
10212 | return 1; | |
10213 | } | |
10214 | ||
919d8a3f | 10215 | ioc_info(ioc, "port enable: SUCCESS\n"); |
e3586147 | 10216 | ioc->port_enable_cmds.status = MPT3_CMD_NOT_USED; |
f92363d1 SR |
10217 | |
10218 | if (ioc->wait_for_discovery_to_complete) { | |
10219 | ioc->wait_for_discovery_to_complete = 0; | |
10220 | _scsih_probe_devices(ioc); | |
10221 | } | |
10222 | mpt3sas_base_start_watchdog(ioc); | |
10223 | ioc->is_driver_loading = 0; | |
10224 | return 1; | |
10225 | } | |
10226 | ||
c84b06a4 SR |
10227 | /* shost template for SAS 2.0 HBA devices */ |
10228 | static struct scsi_host_template mpt2sas_driver_template = { | |
10229 | .module = THIS_MODULE, | |
10230 | .name = "Fusion MPT SAS Host", | |
10231 | .proc_name = MPT2SAS_DRIVER_NAME, | |
10232 | .queuecommand = scsih_qcmd, | |
10233 | .target_alloc = scsih_target_alloc, | |
10234 | .slave_alloc = scsih_slave_alloc, | |
10235 | .slave_configure = scsih_slave_configure, | |
10236 | .target_destroy = scsih_target_destroy, | |
10237 | .slave_destroy = scsih_slave_destroy, | |
10238 | .scan_finished = scsih_scan_finished, | |
10239 | .scan_start = scsih_scan_start, | |
10240 | .change_queue_depth = scsih_change_queue_depth, | |
10241 | .eh_abort_handler = scsih_abort, | |
10242 | .eh_device_reset_handler = scsih_dev_reset, | |
10243 | .eh_target_reset_handler = scsih_target_reset, | |
10244 | .eh_host_reset_handler = scsih_host_reset, | |
10245 | .bios_param = scsih_bios_param, | |
10246 | .can_queue = 1, | |
10247 | .this_id = -1, | |
10248 | .sg_tablesize = MPT2SAS_SG_DEPTH, | |
10249 | .max_sectors = 32767, | |
10250 | .cmd_per_lun = 7, | |
c84b06a4 SR |
10251 | .shost_attrs = mpt3sas_host_attrs, |
10252 | .sdev_attrs = mpt3sas_dev_attrs, | |
10253 | .track_queue_depth = 1, | |
dbec4c90 | 10254 | .cmd_size = sizeof(struct scsiio_tracker), |
c84b06a4 SR |
10255 | }; |
10256 | ||
10257 | /* raid transport support for SAS 2.0 HBA devices */ | |
10258 | static struct raid_function_template mpt2sas_raid_functions = { | |
10259 | .cookie = &mpt2sas_driver_template, | |
10260 | .is_raid = scsih_is_raid, | |
10261 | .get_resync = scsih_get_resync, | |
10262 | .get_state = scsih_get_state, | |
10263 | }; | |
d357e84d | 10264 | |
c84b06a4 SR |
10265 | /* shost template for SAS 3.0 HBA devices */ |
10266 | static struct scsi_host_template mpt3sas_driver_template = { | |
10267 | .module = THIS_MODULE, | |
10268 | .name = "Fusion MPT SAS Host", | |
10269 | .proc_name = MPT3SAS_DRIVER_NAME, | |
10270 | .queuecommand = scsih_qcmd, | |
10271 | .target_alloc = scsih_target_alloc, | |
10272 | .slave_alloc = scsih_slave_alloc, | |
10273 | .slave_configure = scsih_slave_configure, | |
10274 | .target_destroy = scsih_target_destroy, | |
10275 | .slave_destroy = scsih_slave_destroy, | |
10276 | .scan_finished = scsih_scan_finished, | |
10277 | .scan_start = scsih_scan_start, | |
10278 | .change_queue_depth = scsih_change_queue_depth, | |
10279 | .eh_abort_handler = scsih_abort, | |
10280 | .eh_device_reset_handler = scsih_dev_reset, | |
10281 | .eh_target_reset_handler = scsih_target_reset, | |
10282 | .eh_host_reset_handler = scsih_host_reset, | |
10283 | .bios_param = scsih_bios_param, | |
10284 | .can_queue = 1, | |
10285 | .this_id = -1, | |
10286 | .sg_tablesize = MPT3SAS_SG_DEPTH, | |
10287 | .max_sectors = 32767, | |
ce0ad853 | 10288 | .max_segment_size = 0xffffffff, |
c84b06a4 | 10289 | .cmd_per_lun = 7, |
c84b06a4 SR |
10290 | .shost_attrs = mpt3sas_host_attrs, |
10291 | .sdev_attrs = mpt3sas_dev_attrs, | |
10292 | .track_queue_depth = 1, | |
dbec4c90 | 10293 | .cmd_size = sizeof(struct scsiio_tracker), |
c84b06a4 SR |
10294 | }; |
10295 | ||
10296 | /* raid transport support for SAS 3.0 HBA devices */ | |
10297 | static struct raid_function_template mpt3sas_raid_functions = { | |
10298 | .cookie = &mpt3sas_driver_template, | |
10299 | .is_raid = scsih_is_raid, | |
10300 | .get_resync = scsih_get_resync, | |
10301 | .get_state = scsih_get_state, | |
10302 | }; | |
10303 | ||
10304 | /** | |
10305 | * _scsih_determine_hba_mpi_version - determine in which MPI version class | |
10306 | * this device belongs to. | |
10307 | * @pdev: PCI device struct | |
10308 | * | |
10309 | * return MPI2_VERSION for SAS 2.0 HBA devices, | |
b130b0d5 SS |
10310 | * MPI25_VERSION for SAS 3.0 HBA devices, and |
10311 | * MPI26 VERSION for Cutlass & Invader SAS 3.0 HBA devices | |
c84b06a4 | 10312 | */ |
8bbb1cf6 | 10313 | static u16 |
c84b06a4 SR |
10314 | _scsih_determine_hba_mpi_version(struct pci_dev *pdev) |
10315 | { | |
10316 | ||
10317 | switch (pdev->device) { | |
7786ab6a | 10318 | case MPI2_MFGPAGE_DEVID_SSS6200: |
d357e84d SR |
10319 | case MPI2_MFGPAGE_DEVID_SAS2004: |
10320 | case MPI2_MFGPAGE_DEVID_SAS2008: | |
10321 | case MPI2_MFGPAGE_DEVID_SAS2108_1: | |
10322 | case MPI2_MFGPAGE_DEVID_SAS2108_2: | |
10323 | case MPI2_MFGPAGE_DEVID_SAS2108_3: | |
10324 | case MPI2_MFGPAGE_DEVID_SAS2116_1: | |
10325 | case MPI2_MFGPAGE_DEVID_SAS2116_2: | |
10326 | case MPI2_MFGPAGE_DEVID_SAS2208_1: | |
10327 | case MPI2_MFGPAGE_DEVID_SAS2208_2: | |
10328 | case MPI2_MFGPAGE_DEVID_SAS2208_3: | |
10329 | case MPI2_MFGPAGE_DEVID_SAS2208_4: | |
10330 | case MPI2_MFGPAGE_DEVID_SAS2208_5: | |
10331 | case MPI2_MFGPAGE_DEVID_SAS2208_6: | |
10332 | case MPI2_MFGPAGE_DEVID_SAS2308_1: | |
10333 | case MPI2_MFGPAGE_DEVID_SAS2308_2: | |
10334 | case MPI2_MFGPAGE_DEVID_SAS2308_3: | |
1244790d | 10335 | case MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP: |
8f838450 | 10336 | case MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP_1: |
c84b06a4 | 10337 | return MPI2_VERSION; |
d357e84d SR |
10338 | case MPI25_MFGPAGE_DEVID_SAS3004: |
10339 | case MPI25_MFGPAGE_DEVID_SAS3008: | |
10340 | case MPI25_MFGPAGE_DEVID_SAS3108_1: | |
10341 | case MPI25_MFGPAGE_DEVID_SAS3108_2: | |
10342 | case MPI25_MFGPAGE_DEVID_SAS3108_5: | |
10343 | case MPI25_MFGPAGE_DEVID_SAS3108_6: | |
c84b06a4 | 10344 | return MPI25_VERSION; |
b130b0d5 SS |
10345 | case MPI26_MFGPAGE_DEVID_SAS3216: |
10346 | case MPI26_MFGPAGE_DEVID_SAS3224: | |
10347 | case MPI26_MFGPAGE_DEVID_SAS3316_1: | |
10348 | case MPI26_MFGPAGE_DEVID_SAS3316_2: | |
10349 | case MPI26_MFGPAGE_DEVID_SAS3316_3: | |
10350 | case MPI26_MFGPAGE_DEVID_SAS3316_4: | |
10351 | case MPI26_MFGPAGE_DEVID_SAS3324_1: | |
10352 | case MPI26_MFGPAGE_DEVID_SAS3324_2: | |
10353 | case MPI26_MFGPAGE_DEVID_SAS3324_3: | |
10354 | case MPI26_MFGPAGE_DEVID_SAS3324_4: | |
998f26ae SPS |
10355 | case MPI26_MFGPAGE_DEVID_SAS3508: |
10356 | case MPI26_MFGPAGE_DEVID_SAS3508_1: | |
10357 | case MPI26_MFGPAGE_DEVID_SAS3408: | |
10358 | case MPI26_MFGPAGE_DEVID_SAS3516: | |
10359 | case MPI26_MFGPAGE_DEVID_SAS3516_1: | |
10360 | case MPI26_MFGPAGE_DEVID_SAS3416: | |
15fd7c74 | 10361 | case MPI26_MFGPAGE_DEVID_SAS3616: |
eb9c7ce5 | 10362 | case MPI26_ATLAS_PCIe_SWITCH_DEVID: |
6c2938f7 SP |
10363 | case MPI26_MFGPAGE_DEVID_CFG_SEC_3916: |
10364 | case MPI26_MFGPAGE_DEVID_HARD_SEC_3916: | |
10365 | case MPI26_MFGPAGE_DEVID_CFG_SEC_3816: | |
10366 | case MPI26_MFGPAGE_DEVID_HARD_SEC_3816: | |
b130b0d5 | 10367 | return MPI26_VERSION; |
d357e84d | 10368 | } |
c84b06a4 | 10369 | return 0; |
d357e84d SR |
10370 | } |
10371 | ||
f92363d1 | 10372 | /** |
c84b06a4 | 10373 | * _scsih_probe - attach and add scsi host |
f92363d1 SR |
10374 | * @pdev: PCI device struct |
10375 | * @id: pci device id | |
10376 | * | |
4beb4867 | 10377 | * Return: 0 success, anything else error. |
f92363d1 | 10378 | */ |
8bbb1cf6 | 10379 | static int |
c84b06a4 | 10380 | _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
f92363d1 SR |
10381 | { |
10382 | struct MPT3SAS_ADAPTER *ioc; | |
c84b06a4 | 10383 | struct Scsi_Host *shost = NULL; |
b65f1d4d | 10384 | int rv; |
c84b06a4 SR |
10385 | u16 hba_mpi_version; |
10386 | ||
10387 | /* Determine in which MPI version class this pci device belongs */ | |
10388 | hba_mpi_version = _scsih_determine_hba_mpi_version(pdev); | |
10389 | if (hba_mpi_version == 0) | |
10390 | return -ENODEV; | |
10391 | ||
10392 | /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one, | |
10393 | * for other generation HBA's return with -ENODEV | |
10394 | */ | |
10395 | if ((hbas_to_enumerate == 1) && (hba_mpi_version != MPI2_VERSION)) | |
10396 | return -ENODEV; | |
10397 | ||
10398 | /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two, | |
10399 | * for other generation HBA's return with -ENODEV | |
10400 | */ | |
b130b0d5 SS |
10401 | if ((hbas_to_enumerate == 2) && (!(hba_mpi_version == MPI25_VERSION |
10402 | || hba_mpi_version == MPI26_VERSION))) | |
c84b06a4 SR |
10403 | return -ENODEV; |
10404 | ||
10405 | switch (hba_mpi_version) { | |
10406 | case MPI2_VERSION: | |
ffdadd68 | 10407 | pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | |
10408 | PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM); | |
c84b06a4 SR |
10409 | /* Use mpt2sas driver host template for SAS 2.0 HBA's */ |
10410 | shost = scsi_host_alloc(&mpt2sas_driver_template, | |
10411 | sizeof(struct MPT3SAS_ADAPTER)); | |
10412 | if (!shost) | |
10413 | return -ENODEV; | |
10414 | ioc = shost_priv(shost); | |
10415 | memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER)); | |
10416 | ioc->hba_mpi_version_belonged = hba_mpi_version; | |
10417 | ioc->id = mpt2_ids++; | |
10418 | sprintf(ioc->driver_name, "%s", MPT2SAS_DRIVER_NAME); | |
c520691b SPS |
10419 | switch (pdev->device) { |
10420 | case MPI2_MFGPAGE_DEVID_SSS6200: | |
c84b06a4 SR |
10421 | ioc->is_warpdrive = 1; |
10422 | ioc->hide_ir_msg = 1; | |
c520691b | 10423 | break; |
1244790d | 10424 | case MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP: |
8f838450 | 10425 | case MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP_1: |
c520691b SPS |
10426 | ioc->is_mcpu_endpoint = 1; |
10427 | break; | |
10428 | default: | |
c84b06a4 | 10429 | ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS; |
c520691b SPS |
10430 | break; |
10431 | } | |
c84b06a4 SR |
10432 | break; |
10433 | case MPI25_VERSION: | |
b130b0d5 | 10434 | case MPI26_VERSION: |
c84b06a4 SR |
10435 | /* Use mpt3sas driver host template for SAS 3.0 HBA's */ |
10436 | shost = scsi_host_alloc(&mpt3sas_driver_template, | |
10437 | sizeof(struct MPT3SAS_ADAPTER)); | |
10438 | if (!shost) | |
10439 | return -ENODEV; | |
10440 | ioc = shost_priv(shost); | |
10441 | memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER)); | |
10442 | ioc->hba_mpi_version_belonged = hba_mpi_version; | |
10443 | ioc->id = mpt3_ids++; | |
10444 | sprintf(ioc->driver_name, "%s", MPT3SAS_DRIVER_NAME); | |
998f26ae SPS |
10445 | switch (pdev->device) { |
10446 | case MPI26_MFGPAGE_DEVID_SAS3508: | |
10447 | case MPI26_MFGPAGE_DEVID_SAS3508_1: | |
10448 | case MPI26_MFGPAGE_DEVID_SAS3408: | |
10449 | case MPI26_MFGPAGE_DEVID_SAS3516: | |
10450 | case MPI26_MFGPAGE_DEVID_SAS3516_1: | |
10451 | case MPI26_MFGPAGE_DEVID_SAS3416: | |
15fd7c74 | 10452 | case MPI26_MFGPAGE_DEVID_SAS3616: |
eb9c7ce5 | 10453 | case MPI26_ATLAS_PCIe_SWITCH_DEVID: |
cc68e607 SP |
10454 | ioc->is_gen35_ioc = 1; |
10455 | break; | |
10456 | case MPI26_MFGPAGE_DEVID_CFG_SEC_3816: | |
10457 | case MPI26_MFGPAGE_DEVID_CFG_SEC_3916: | |
10458 | dev_info(&pdev->dev, | |
10459 | "HBA is in Configurable Secure mode\n"); | |
a8cc10e2 | 10460 | /* fall through */ |
6c2938f7 SP |
10461 | case MPI26_MFGPAGE_DEVID_HARD_SEC_3816: |
10462 | case MPI26_MFGPAGE_DEVID_HARD_SEC_3916: | |
cc68e607 | 10463 | ioc->is_aero_ioc = ioc->is_gen35_ioc = 1; |
998f26ae SPS |
10464 | break; |
10465 | default: | |
cc68e607 | 10466 | ioc->is_gen35_ioc = ioc->is_aero_ioc = 0; |
998f26ae | 10467 | } |
b130b0d5 SS |
10468 | if ((ioc->hba_mpi_version_belonged == MPI25_VERSION && |
10469 | pdev->revision >= SAS3_PCI_DEVICE_C0_REVISION) || | |
0bb337c9 SPS |
10470 | (ioc->hba_mpi_version_belonged == MPI26_VERSION)) { |
10471 | ioc->combined_reply_queue = 1; | |
10472 | if (ioc->is_gen35_ioc) | |
10473 | ioc->combined_reply_index_count = | |
10474 | MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G35; | |
10475 | else | |
10476 | ioc->combined_reply_index_count = | |
10477 | MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G3; | |
10478 | } | |
c84b06a4 SR |
10479 | break; |
10480 | default: | |
10481 | return -ENODEV; | |
10482 | } | |
f92363d1 | 10483 | |
f92363d1 | 10484 | INIT_LIST_HEAD(&ioc->list); |
08c4d550 | 10485 | spin_lock(&gioc_lock); |
f92363d1 | 10486 | list_add_tail(&ioc->list, &mpt3sas_ioc_list); |
08c4d550 | 10487 | spin_unlock(&gioc_lock); |
f92363d1 | 10488 | ioc->shost = shost; |
f92363d1 SR |
10489 | ioc->pdev = pdev; |
10490 | ioc->scsi_io_cb_idx = scsi_io_cb_idx; | |
10491 | ioc->tm_cb_idx = tm_cb_idx; | |
10492 | ioc->ctl_cb_idx = ctl_cb_idx; | |
10493 | ioc->base_cb_idx = base_cb_idx; | |
10494 | ioc->port_enable_cb_idx = port_enable_cb_idx; | |
10495 | ioc->transport_cb_idx = transport_cb_idx; | |
10496 | ioc->scsih_cb_idx = scsih_cb_idx; | |
10497 | ioc->config_cb_idx = config_cb_idx; | |
10498 | ioc->tm_tr_cb_idx = tm_tr_cb_idx; | |
10499 | ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx; | |
10500 | ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx; | |
10501 | ioc->logging_level = logging_level; | |
10502 | ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds; | |
3ac8e47b SP |
10503 | /* |
10504 | * Enable MEMORY MOVE support flag. | |
10505 | */ | |
10506 | ioc->drv_support_bitmap |= MPT_DRV_SUPPORT_BITMAP_MEMMOVE; | |
f92363d1 SR |
10507 | /* misc semaphores and spin locks */ |
10508 | mutex_init(&ioc->reset_in_progress_mutex); | |
08c4d550 SR |
10509 | /* initializing pci_access_mutex lock */ |
10510 | mutex_init(&ioc->pci_access_mutex); | |
f92363d1 SR |
10511 | spin_lock_init(&ioc->ioc_reset_in_progress_lock); |
10512 | spin_lock_init(&ioc->scsi_lookup_lock); | |
10513 | spin_lock_init(&ioc->sas_device_lock); | |
10514 | spin_lock_init(&ioc->sas_node_lock); | |
10515 | spin_lock_init(&ioc->fw_event_lock); | |
10516 | spin_lock_init(&ioc->raid_device_lock); | |
d88e1eab | 10517 | spin_lock_init(&ioc->pcie_device_lock); |
f92363d1 SR |
10518 | spin_lock_init(&ioc->diag_trigger_lock); |
10519 | ||
10520 | INIT_LIST_HEAD(&ioc->sas_device_list); | |
10521 | INIT_LIST_HEAD(&ioc->sas_device_init_list); | |
10522 | INIT_LIST_HEAD(&ioc->sas_expander_list); | |
22a923c3 | 10523 | INIT_LIST_HEAD(&ioc->enclosure_list); |
d88e1eab SPS |
10524 | INIT_LIST_HEAD(&ioc->pcie_device_list); |
10525 | INIT_LIST_HEAD(&ioc->pcie_device_init_list); | |
f92363d1 SR |
10526 | INIT_LIST_HEAD(&ioc->fw_event_list); |
10527 | INIT_LIST_HEAD(&ioc->raid_device_list); | |
10528 | INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list); | |
10529 | INIT_LIST_HEAD(&ioc->delayed_tr_list); | |
fd0331b3 SS |
10530 | INIT_LIST_HEAD(&ioc->delayed_sc_list); |
10531 | INIT_LIST_HEAD(&ioc->delayed_event_ack_list); | |
f92363d1 | 10532 | INIT_LIST_HEAD(&ioc->delayed_tr_volume_list); |
cf9bd21a | 10533 | INIT_LIST_HEAD(&ioc->reply_queue_list); |
f92363d1 | 10534 | |
c84b06a4 | 10535 | sprintf(ioc->name, "%s_cm%d", ioc->driver_name, ioc->id); |
d357e84d | 10536 | |
f92363d1 SR |
10537 | /* init shost parameters */ |
10538 | shost->max_cmd_len = 32; | |
10539 | shost->max_lun = max_lun; | |
10540 | shost->transportt = mpt3sas_transport_template; | |
10541 | shost->unique_id = ioc->id; | |
10542 | ||
0448f019 SPS |
10543 | if (ioc->is_mcpu_endpoint) { |
10544 | /* mCPU MPI support 64K max IO */ | |
10545 | shost->max_sectors = 128; | |
919d8a3f JP |
10546 | ioc_info(ioc, "The max_sectors value is set to %d\n", |
10547 | shost->max_sectors); | |
0448f019 SPS |
10548 | } else { |
10549 | if (max_sectors != 0xFFFF) { | |
10550 | if (max_sectors < 64) { | |
10551 | shost->max_sectors = 64; | |
919d8a3f JP |
10552 | ioc_warn(ioc, "Invalid value %d passed for max_sectors, range is 64 to 32767. Assigning value of 64.\n", |
10553 | max_sectors); | |
0448f019 SPS |
10554 | } else if (max_sectors > 32767) { |
10555 | shost->max_sectors = 32767; | |
919d8a3f JP |
10556 | ioc_warn(ioc, "Invalid value %d passed for max_sectors, range is 64 to 32767.Assigning default value of 32767.\n", |
10557 | max_sectors); | |
0448f019 SPS |
10558 | } else { |
10559 | shost->max_sectors = max_sectors & 0xFFFE; | |
919d8a3f JP |
10560 | ioc_info(ioc, "The max_sectors value is set to %d\n", |
10561 | shost->max_sectors); | |
0448f019 | 10562 | } |
f92363d1 SR |
10563 | } |
10564 | } | |
f92363d1 SR |
10565 | /* register EEDP capabilities with SCSI layer */ |
10566 | if (prot_mask > 0) | |
10567 | scsi_host_set_prot(shost, prot_mask); | |
10568 | else | |
10569 | scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION | |
10570 | | SHOST_DIF_TYPE2_PROTECTION | |
10571 | | SHOST_DIF_TYPE3_PROTECTION); | |
10572 | ||
10573 | scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC); | |
10574 | ||
10575 | /* event thread */ | |
10576 | snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name), | |
c84b06a4 | 10577 | "fw_event_%s%d", ioc->driver_name, ioc->id); |
bdff785e | 10578 | ioc->firmware_event_thread = alloc_ordered_workqueue( |
864449ee | 10579 | ioc->firmware_event_name, 0); |
f92363d1 | 10580 | if (!ioc->firmware_event_thread) { |
919d8a3f JP |
10581 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
10582 | __FILE__, __LINE__, __func__); | |
b65f1d4d | 10583 | rv = -ENODEV; |
f92363d1 SR |
10584 | goto out_thread_fail; |
10585 | } | |
10586 | ||
10587 | ioc->is_driver_loading = 1; | |
10588 | if ((mpt3sas_base_attach(ioc))) { | |
919d8a3f JP |
10589 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
10590 | __FILE__, __LINE__, __func__); | |
b65f1d4d | 10591 | rv = -ENODEV; |
f92363d1 SR |
10592 | goto out_attach_fail; |
10593 | } | |
7786ab6a | 10594 | |
7786ab6a SR |
10595 | if (ioc->is_warpdrive) { |
10596 | if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) | |
10597 | ioc->hide_drives = 0; | |
10598 | else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS) | |
10599 | ioc->hide_drives = 1; | |
10600 | else { | |
c84b06a4 | 10601 | if (mpt3sas_get_num_volumes(ioc)) |
7786ab6a SR |
10602 | ioc->hide_drives = 1; |
10603 | else | |
10604 | ioc->hide_drives = 0; | |
10605 | } | |
10606 | } else | |
10607 | ioc->hide_drives = 0; | |
7786ab6a | 10608 | |
b65f1d4d SR |
10609 | rv = scsi_add_host(shost, &pdev->dev); |
10610 | if (rv) { | |
919d8a3f JP |
10611 | ioc_err(ioc, "failure at %s:%d/%s()!\n", |
10612 | __FILE__, __LINE__, __func__); | |
4dc06fd8 RS |
10613 | goto out_add_shost_fail; |
10614 | } | |
10615 | ||
f92363d1 SR |
10616 | scsi_scan_host(shost); |
10617 | return 0; | |
4dc06fd8 RS |
10618 | out_add_shost_fail: |
10619 | mpt3sas_base_detach(ioc); | |
f92363d1 SR |
10620 | out_attach_fail: |
10621 | destroy_workqueue(ioc->firmware_event_thread); | |
10622 | out_thread_fail: | |
08c4d550 | 10623 | spin_lock(&gioc_lock); |
f92363d1 | 10624 | list_del(&ioc->list); |
08c4d550 | 10625 | spin_unlock(&gioc_lock); |
f92363d1 | 10626 | scsi_host_put(shost); |
b65f1d4d | 10627 | return rv; |
f92363d1 SR |
10628 | } |
10629 | ||
10630 | #ifdef CONFIG_PM | |
10631 | /** | |
8a7e4c24 | 10632 | * scsih_suspend - power management suspend main entry point |
f92363d1 SR |
10633 | * @pdev: PCI device struct |
10634 | * @state: PM state change to (usually PCI_D3) | |
10635 | * | |
4beb4867 | 10636 | * Return: 0 success, anything else error. |
f92363d1 | 10637 | */ |
8bbb1cf6 | 10638 | static int |
8a7e4c24 | 10639 | scsih_suspend(struct pci_dev *pdev, pm_message_t state) |
f92363d1 SR |
10640 | { |
10641 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10642 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10643 | pci_power_t device_state; | |
10644 | ||
10645 | mpt3sas_base_stop_watchdog(ioc); | |
10646 | flush_scheduled_work(); | |
10647 | scsi_block_requests(shost); | |
10648 | device_state = pci_choose_state(pdev, state); | |
919d8a3f JP |
10649 | ioc_info(ioc, "pdev=0x%p, slot=%s, entering operating state [D%d]\n", |
10650 | pdev, pci_name(pdev), device_state); | |
f92363d1 SR |
10651 | |
10652 | pci_save_state(pdev); | |
10653 | mpt3sas_base_free_resources(ioc); | |
10654 | pci_set_power_state(pdev, device_state); | |
10655 | return 0; | |
10656 | } | |
10657 | ||
10658 | /** | |
8a7e4c24 | 10659 | * scsih_resume - power management resume main entry point |
f92363d1 SR |
10660 | * @pdev: PCI device struct |
10661 | * | |
4beb4867 | 10662 | * Return: 0 success, anything else error. |
f92363d1 | 10663 | */ |
8bbb1cf6 | 10664 | static int |
8a7e4c24 | 10665 | scsih_resume(struct pci_dev *pdev) |
f92363d1 SR |
10666 | { |
10667 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10668 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10669 | pci_power_t device_state = pdev->current_state; | |
10670 | int r; | |
10671 | ||
919d8a3f JP |
10672 | ioc_info(ioc, "pdev=0x%p, slot=%s, previous operating state [D%d]\n", |
10673 | pdev, pci_name(pdev), device_state); | |
f92363d1 SR |
10674 | |
10675 | pci_set_power_state(pdev, PCI_D0); | |
10676 | pci_enable_wake(pdev, PCI_D0, 0); | |
10677 | pci_restore_state(pdev); | |
10678 | ioc->pdev = pdev; | |
10679 | r = mpt3sas_base_map_resources(ioc); | |
10680 | if (r) | |
10681 | return r; | |
10682 | ||
98c56ad3 | 10683 | mpt3sas_base_hard_reset_handler(ioc, SOFT_RESET); |
f92363d1 SR |
10684 | scsi_unblock_requests(shost); |
10685 | mpt3sas_base_start_watchdog(ioc); | |
10686 | return 0; | |
10687 | } | |
10688 | #endif /* CONFIG_PM */ | |
10689 | ||
10690 | /** | |
8a7e4c24 | 10691 | * scsih_pci_error_detected - Called when a PCI error is detected. |
f92363d1 SR |
10692 | * @pdev: PCI device struct |
10693 | * @state: PCI channel state | |
10694 | * | |
10695 | * Description: Called when a PCI error is detected. | |
10696 | * | |
4beb4867 | 10697 | * Return: PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT. |
f92363d1 | 10698 | */ |
8bbb1cf6 | 10699 | static pci_ers_result_t |
8a7e4c24 | 10700 | scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
f92363d1 SR |
10701 | { |
10702 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10703 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10704 | ||
919d8a3f | 10705 | ioc_info(ioc, "PCI error: detected callback, state(%d)!!\n", state); |
f92363d1 SR |
10706 | |
10707 | switch (state) { | |
10708 | case pci_channel_io_normal: | |
10709 | return PCI_ERS_RESULT_CAN_RECOVER; | |
10710 | case pci_channel_io_frozen: | |
10711 | /* Fatal error, prepare for slot reset */ | |
10712 | ioc->pci_error_recovery = 1; | |
10713 | scsi_block_requests(ioc->shost); | |
10714 | mpt3sas_base_stop_watchdog(ioc); | |
10715 | mpt3sas_base_free_resources(ioc); | |
10716 | return PCI_ERS_RESULT_NEED_RESET; | |
10717 | case pci_channel_io_perm_failure: | |
10718 | /* Permanent error, prepare for device removal */ | |
10719 | ioc->pci_error_recovery = 1; | |
10720 | mpt3sas_base_stop_watchdog(ioc); | |
10721 | _scsih_flush_running_cmds(ioc); | |
10722 | return PCI_ERS_RESULT_DISCONNECT; | |
10723 | } | |
10724 | return PCI_ERS_RESULT_NEED_RESET; | |
10725 | } | |
10726 | ||
10727 | /** | |
8a7e4c24 | 10728 | * scsih_pci_slot_reset - Called when PCI slot has been reset. |
f92363d1 SR |
10729 | * @pdev: PCI device struct |
10730 | * | |
10731 | * Description: This routine is called by the pci error recovery | |
10732 | * code after the PCI slot has been reset, just before we | |
10733 | * should resume normal operations. | |
10734 | */ | |
8bbb1cf6 | 10735 | static pci_ers_result_t |
8a7e4c24 | 10736 | scsih_pci_slot_reset(struct pci_dev *pdev) |
f92363d1 SR |
10737 | { |
10738 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10739 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10740 | int rc; | |
10741 | ||
919d8a3f | 10742 | ioc_info(ioc, "PCI error: slot reset callback!!\n"); |
f92363d1 SR |
10743 | |
10744 | ioc->pci_error_recovery = 0; | |
10745 | ioc->pdev = pdev; | |
10746 | pci_restore_state(pdev); | |
10747 | rc = mpt3sas_base_map_resources(ioc); | |
10748 | if (rc) | |
10749 | return PCI_ERS_RESULT_DISCONNECT; | |
10750 | ||
98c56ad3 | 10751 | rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
f92363d1 | 10752 | |
919d8a3f JP |
10753 | ioc_warn(ioc, "hard reset: %s\n", |
10754 | (rc == 0) ? "success" : "failed"); | |
f92363d1 SR |
10755 | |
10756 | if (!rc) | |
10757 | return PCI_ERS_RESULT_RECOVERED; | |
10758 | else | |
10759 | return PCI_ERS_RESULT_DISCONNECT; | |
10760 | } | |
10761 | ||
10762 | /** | |
8a7e4c24 | 10763 | * scsih_pci_resume() - resume normal ops after PCI reset |
f92363d1 SR |
10764 | * @pdev: pointer to PCI device |
10765 | * | |
10766 | * Called when the error recovery driver tells us that its | |
10767 | * OK to resume normal operation. Use completion to allow | |
10768 | * halted scsi ops to resume. | |
10769 | */ | |
8bbb1cf6 | 10770 | static void |
8a7e4c24 | 10771 | scsih_pci_resume(struct pci_dev *pdev) |
f92363d1 SR |
10772 | { |
10773 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10774 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10775 | ||
919d8a3f | 10776 | ioc_info(ioc, "PCI error: resume callback!!\n"); |
f92363d1 | 10777 | |
f92363d1 SR |
10778 | mpt3sas_base_start_watchdog(ioc); |
10779 | scsi_unblock_requests(ioc->shost); | |
10780 | } | |
10781 | ||
10782 | /** | |
8a7e4c24 | 10783 | * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers |
f92363d1 SR |
10784 | * @pdev: pointer to PCI device |
10785 | */ | |
8bbb1cf6 | 10786 | static pci_ers_result_t |
8a7e4c24 | 10787 | scsih_pci_mmio_enabled(struct pci_dev *pdev) |
f92363d1 SR |
10788 | { |
10789 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10790 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10791 | ||
919d8a3f | 10792 | ioc_info(ioc, "PCI error: mmio enabled callback!!\n"); |
f92363d1 SR |
10793 | |
10794 | /* TODO - dump whatever for debugging purposes */ | |
10795 | ||
83c3d340 KW |
10796 | /* This called only if scsih_pci_error_detected returns |
10797 | * PCI_ERS_RESULT_CAN_RECOVER. Read/write to the device still | |
10798 | * works, no need to reset slot. | |
10799 | */ | |
10800 | return PCI_ERS_RESULT_RECOVERED; | |
f92363d1 SR |
10801 | } |
10802 | ||
307d9075 AM |
10803 | /** |
10804 | * scsih__ncq_prio_supp - Check for NCQ command priority support | |
10805 | * @sdev: scsi device struct | |
10806 | * | |
10807 | * This is called when a user indicates they would like to enable | |
10808 | * ncq command priorities. This works only on SATA devices. | |
10809 | */ | |
10810 | bool scsih_ncq_prio_supp(struct scsi_device *sdev) | |
10811 | { | |
10812 | unsigned char *buf; | |
10813 | bool ncq_prio_supp = false; | |
10814 | ||
10815 | if (!scsi_device_supports_vpd(sdev)) | |
10816 | return ncq_prio_supp; | |
10817 | ||
10818 | buf = kmalloc(SCSI_VPD_PG_LEN, GFP_KERNEL); | |
10819 | if (!buf) | |
10820 | return ncq_prio_supp; | |
10821 | ||
10822 | if (!scsi_get_vpd_page(sdev, 0x89, buf, SCSI_VPD_PG_LEN)) | |
10823 | ncq_prio_supp = (buf[213] >> 4) & 1; | |
10824 | ||
10825 | kfree(buf); | |
10826 | return ncq_prio_supp; | |
10827 | } | |
c84b06a4 SR |
10828 | /* |
10829 | * The pci device ids are defined in mpi/mpi2_cnfg.h. | |
10830 | */ | |
10831 | static const struct pci_device_id mpt3sas_pci_table[] = { | |
10832 | /* Spitfire ~ 2004 */ | |
10833 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004, | |
10834 | PCI_ANY_ID, PCI_ANY_ID }, | |
10835 | /* Falcon ~ 2008 */ | |
10836 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008, | |
10837 | PCI_ANY_ID, PCI_ANY_ID }, | |
10838 | /* Liberator ~ 2108 */ | |
10839 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1, | |
10840 | PCI_ANY_ID, PCI_ANY_ID }, | |
10841 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2, | |
10842 | PCI_ANY_ID, PCI_ANY_ID }, | |
10843 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3, | |
10844 | PCI_ANY_ID, PCI_ANY_ID }, | |
10845 | /* Meteor ~ 2116 */ | |
10846 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1, | |
10847 | PCI_ANY_ID, PCI_ANY_ID }, | |
10848 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2, | |
10849 | PCI_ANY_ID, PCI_ANY_ID }, | |
10850 | /* Thunderbolt ~ 2208 */ | |
10851 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1, | |
10852 | PCI_ANY_ID, PCI_ANY_ID }, | |
10853 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2, | |
10854 | PCI_ANY_ID, PCI_ANY_ID }, | |
10855 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3, | |
10856 | PCI_ANY_ID, PCI_ANY_ID }, | |
10857 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4, | |
10858 | PCI_ANY_ID, PCI_ANY_ID }, | |
10859 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5, | |
10860 | PCI_ANY_ID, PCI_ANY_ID }, | |
10861 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6, | |
10862 | PCI_ANY_ID, PCI_ANY_ID }, | |
10863 | /* Mustang ~ 2308 */ | |
10864 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1, | |
10865 | PCI_ANY_ID, PCI_ANY_ID }, | |
10866 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2, | |
10867 | PCI_ANY_ID, PCI_ANY_ID }, | |
10868 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3, | |
10869 | PCI_ANY_ID, PCI_ANY_ID }, | |
1244790d | 10870 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP, |
c520691b | 10871 | PCI_ANY_ID, PCI_ANY_ID }, |
8f838450 SP |
10872 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP_1, |
10873 | PCI_ANY_ID, PCI_ANY_ID }, | |
c84b06a4 SR |
10874 | /* SSS6200 */ |
10875 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200, | |
10876 | PCI_ANY_ID, PCI_ANY_ID }, | |
10877 | /* Fury ~ 3004 and 3008 */ | |
10878 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3004, | |
10879 | PCI_ANY_ID, PCI_ANY_ID }, | |
10880 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3008, | |
10881 | PCI_ANY_ID, PCI_ANY_ID }, | |
10882 | /* Invader ~ 3108 */ | |
10883 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_1, | |
10884 | PCI_ANY_ID, PCI_ANY_ID }, | |
10885 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_2, | |
10886 | PCI_ANY_ID, PCI_ANY_ID }, | |
10887 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_5, | |
10888 | PCI_ANY_ID, PCI_ANY_ID }, | |
10889 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_6, | |
10890 | PCI_ANY_ID, PCI_ANY_ID }, | |
b130b0d5 SS |
10891 | /* Cutlass ~ 3216 and 3224 */ |
10892 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3216, | |
10893 | PCI_ANY_ID, PCI_ANY_ID }, | |
10894 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3224, | |
10895 | PCI_ANY_ID, PCI_ANY_ID }, | |
10896 | /* Intruder ~ 3316 and 3324 */ | |
10897 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_1, | |
10898 | PCI_ANY_ID, PCI_ANY_ID }, | |
10899 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_2, | |
10900 | PCI_ANY_ID, PCI_ANY_ID }, | |
10901 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_3, | |
10902 | PCI_ANY_ID, PCI_ANY_ID }, | |
10903 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_4, | |
10904 | PCI_ANY_ID, PCI_ANY_ID }, | |
10905 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_1, | |
10906 | PCI_ANY_ID, PCI_ANY_ID }, | |
10907 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_2, | |
10908 | PCI_ANY_ID, PCI_ANY_ID }, | |
10909 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_3, | |
10910 | PCI_ANY_ID, PCI_ANY_ID }, | |
10911 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_4, | |
10912 | PCI_ANY_ID, PCI_ANY_ID }, | |
998f26ae SPS |
10913 | /* Ventura, Crusader, Harpoon & Tomcat ~ 3516, 3416, 3508 & 3408*/ |
10914 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3508, | |
10915 | PCI_ANY_ID, PCI_ANY_ID }, | |
10916 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3508_1, | |
10917 | PCI_ANY_ID, PCI_ANY_ID }, | |
10918 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3408, | |
10919 | PCI_ANY_ID, PCI_ANY_ID }, | |
10920 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3516, | |
10921 | PCI_ANY_ID, PCI_ANY_ID }, | |
10922 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3516_1, | |
10923 | PCI_ANY_ID, PCI_ANY_ID }, | |
10924 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3416, | |
10925 | PCI_ANY_ID, PCI_ANY_ID }, | |
15fd7c74 SR |
10926 | /* Mercator ~ 3616*/ |
10927 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3616, | |
10928 | PCI_ANY_ID, PCI_ANY_ID }, | |
6c2938f7 SP |
10929 | |
10930 | /* Aero SI 0x00E1 Configurable Secure | |
10931 | * 0x00E2 Hard Secure | |
10932 | */ | |
10933 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_CFG_SEC_3916, | |
10934 | PCI_ANY_ID, PCI_ANY_ID }, | |
10935 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_HARD_SEC_3916, | |
10936 | PCI_ANY_ID, PCI_ANY_ID }, | |
10937 | ||
eb9c7ce5 SP |
10938 | /* Atlas PCIe Switch Management Port */ |
10939 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_ATLAS_PCIe_SWITCH_DEVID, | |
10940 | PCI_ANY_ID, PCI_ANY_ID }, | |
10941 | ||
6c2938f7 SP |
10942 | /* Sea SI 0x00E5 Configurable Secure |
10943 | * 0x00E6 Hard Secure | |
10944 | */ | |
10945 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_CFG_SEC_3816, | |
10946 | PCI_ANY_ID, PCI_ANY_ID }, | |
10947 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_HARD_SEC_3816, | |
10948 | PCI_ANY_ID, PCI_ANY_ID }, | |
10949 | ||
c84b06a4 SR |
10950 | {0} /* Terminating entry */ |
10951 | }; | |
10952 | MODULE_DEVICE_TABLE(pci, mpt3sas_pci_table); | |
10953 | ||
10954 | static struct pci_error_handlers _mpt3sas_err_handler = { | |
10955 | .error_detected = scsih_pci_error_detected, | |
10956 | .mmio_enabled = scsih_pci_mmio_enabled, | |
10957 | .slot_reset = scsih_pci_slot_reset, | |
10958 | .resume = scsih_pci_resume, | |
10959 | }; | |
10960 | ||
10961 | static struct pci_driver mpt3sas_driver = { | |
10962 | .name = MPT3SAS_DRIVER_NAME, | |
10963 | .id_table = mpt3sas_pci_table, | |
10964 | .probe = _scsih_probe, | |
10965 | .remove = scsih_remove, | |
10966 | .shutdown = scsih_shutdown, | |
10967 | .err_handler = &_mpt3sas_err_handler, | |
10968 | #ifdef CONFIG_PM | |
10969 | .suspend = scsih_suspend, | |
10970 | .resume = scsih_resume, | |
10971 | #endif | |
10972 | }; | |
10973 | ||
f92363d1 | 10974 | /** |
8a7e4c24 | 10975 | * scsih_init - main entry point for this driver. |
f92363d1 | 10976 | * |
4beb4867 | 10977 | * Return: 0 success, anything else error. |
f92363d1 | 10978 | */ |
8bbb1cf6 | 10979 | static int |
8a7e4c24 | 10980 | scsih_init(void) |
f92363d1 | 10981 | { |
c84b06a4 SR |
10982 | mpt2_ids = 0; |
10983 | mpt3_ids = 0; | |
f92363d1 | 10984 | |
f92363d1 SR |
10985 | mpt3sas_base_initialize_callback_handler(); |
10986 | ||
10987 | /* queuecommand callback hander */ | |
10988 | scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done); | |
10989 | ||
6c7abffc | 10990 | /* task management callback handler */ |
f92363d1 SR |
10991 | tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done); |
10992 | ||
10993 | /* base internal commands callback handler */ | |
10994 | base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done); | |
10995 | port_enable_cb_idx = mpt3sas_base_register_callback_handler( | |
10996 | mpt3sas_port_enable_done); | |
10997 | ||
10998 | /* transport internal commands callback handler */ | |
10999 | transport_cb_idx = mpt3sas_base_register_callback_handler( | |
11000 | mpt3sas_transport_done); | |
11001 | ||
11002 | /* scsih internal commands callback handler */ | |
11003 | scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done); | |
11004 | ||
11005 | /* configuration page API internal commands callback handler */ | |
11006 | config_cb_idx = mpt3sas_base_register_callback_handler( | |
11007 | mpt3sas_config_done); | |
11008 | ||
11009 | /* ctl module callback handler */ | |
11010 | ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done); | |
11011 | ||
11012 | tm_tr_cb_idx = mpt3sas_base_register_callback_handler( | |
11013 | _scsih_tm_tr_complete); | |
11014 | ||
11015 | tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler( | |
11016 | _scsih_tm_volume_tr_complete); | |
11017 | ||
11018 | tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler( | |
11019 | _scsih_sas_control_complete); | |
11020 | ||
7497392a | 11021 | return 0; |
f92363d1 SR |
11022 | } |
11023 | ||
11024 | /** | |
7497392a | 11025 | * scsih_exit - exit point for this driver (when it is a module). |
f92363d1 | 11026 | * |
4beb4867 | 11027 | * Return: 0 success, anything else error. |
f92363d1 | 11028 | */ |
8bbb1cf6 | 11029 | static void |
8a7e4c24 | 11030 | scsih_exit(void) |
f92363d1 | 11031 | { |
f92363d1 SR |
11032 | |
11033 | mpt3sas_base_release_callback_handler(scsi_io_cb_idx); | |
11034 | mpt3sas_base_release_callback_handler(tm_cb_idx); | |
11035 | mpt3sas_base_release_callback_handler(base_cb_idx); | |
11036 | mpt3sas_base_release_callback_handler(port_enable_cb_idx); | |
11037 | mpt3sas_base_release_callback_handler(transport_cb_idx); | |
11038 | mpt3sas_base_release_callback_handler(scsih_cb_idx); | |
11039 | mpt3sas_base_release_callback_handler(config_cb_idx); | |
11040 | mpt3sas_base_release_callback_handler(ctl_cb_idx); | |
11041 | ||
11042 | mpt3sas_base_release_callback_handler(tm_tr_cb_idx); | |
11043 | mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx); | |
11044 | mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx); | |
11045 | ||
11046 | /* raid transport support */ | |
c84b06a4 SR |
11047 | if (hbas_to_enumerate != 1) |
11048 | raid_class_release(mpt3sas_raid_template); | |
11049 | if (hbas_to_enumerate != 2) | |
11050 | raid_class_release(mpt2sas_raid_template); | |
f92363d1 SR |
11051 | sas_release_transport(mpt3sas_transport_template); |
11052 | } | |
7786ab6a | 11053 | |
c84b06a4 SR |
11054 | /** |
11055 | * _mpt3sas_init - main entry point for this driver. | |
11056 | * | |
4beb4867 | 11057 | * Return: 0 success, anything else error. |
c84b06a4 SR |
11058 | */ |
11059 | static int __init | |
11060 | _mpt3sas_init(void) | |
11061 | { | |
11062 | int error; | |
11063 | ||
11064 | pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME, | |
11065 | MPT3SAS_DRIVER_VERSION); | |
11066 | ||
11067 | mpt3sas_transport_template = | |
11068 | sas_attach_transport(&mpt3sas_transport_functions); | |
11069 | if (!mpt3sas_transport_template) | |
11070 | return -ENODEV; | |
11071 | ||
11072 | /* No need attach mpt3sas raid functions template | |
11073 | * if hbas_to_enumarate value is one. | |
11074 | */ | |
11075 | if (hbas_to_enumerate != 1) { | |
11076 | mpt3sas_raid_template = | |
11077 | raid_class_attach(&mpt3sas_raid_functions); | |
11078 | if (!mpt3sas_raid_template) { | |
11079 | sas_release_transport(mpt3sas_transport_template); | |
11080 | return -ENODEV; | |
11081 | } | |
11082 | } | |
11083 | ||
11084 | /* No need to attach mpt2sas raid functions template | |
11085 | * if hbas_to_enumarate value is two | |
11086 | */ | |
11087 | if (hbas_to_enumerate != 2) { | |
11088 | mpt2sas_raid_template = | |
11089 | raid_class_attach(&mpt2sas_raid_functions); | |
11090 | if (!mpt2sas_raid_template) { | |
11091 | sas_release_transport(mpt3sas_transport_template); | |
11092 | return -ENODEV; | |
11093 | } | |
11094 | } | |
11095 | ||
11096 | error = scsih_init(); | |
11097 | if (error) { | |
11098 | scsih_exit(); | |
11099 | return error; | |
11100 | } | |
11101 | ||
11102 | mpt3sas_ctl_init(hbas_to_enumerate); | |
11103 | ||
11104 | error = pci_register_driver(&mpt3sas_driver); | |
11105 | if (error) | |
11106 | scsih_exit(); | |
11107 | ||
11108 | return error; | |
11109 | } | |
11110 | ||
11111 | /** | |
11112 | * _mpt3sas_exit - exit point for this driver (when it is a module). | |
11113 | * | |
11114 | */ | |
11115 | static void __exit | |
11116 | _mpt3sas_exit(void) | |
11117 | { | |
11118 | pr_info("mpt3sas version %s unloading\n", | |
11119 | MPT3SAS_DRIVER_VERSION); | |
11120 | ||
c84b06a4 SR |
11121 | mpt3sas_ctl_exit(hbas_to_enumerate); |
11122 | ||
87b3576e C |
11123 | pci_unregister_driver(&mpt3sas_driver); |
11124 | ||
c84b06a4 SR |
11125 | scsih_exit(); |
11126 | } | |
11127 | ||
11128 | module_init(_mpt3sas_init); | |
11129 | module_exit(_mpt3sas_exit); |