]>
Commit | Line | Data |
---|---|---|
f92363d1 SR |
1 | /* |
2 | * Scsi Host Layer for MPT (Message Passing Technology) based controllers | |
3 | * | |
4 | * This code is based on drivers/scsi/mpt3sas/mpt3sas_scsih.c | |
a4ffce0d | 5 | * Copyright (C) 2012-2014 LSI Corporation |
a03bd153 SR |
6 | * Copyright (C) 2013-2014 Avago Technologies |
7 | * (mailto: MPT-FusionLinux.pdl@avagotech.com) | |
f92363d1 SR |
8 | * |
9 | * This program is free software; you can redistribute it and/or | |
10 | * modify it under the terms of the GNU General Public License | |
11 | * as published by the Free Software Foundation; either version 2 | |
12 | * of the License, or (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * NO WARRANTY | |
20 | * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR | |
21 | * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT | |
22 | * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, | |
23 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is | |
24 | * solely responsible for determining the appropriateness of using and | |
25 | * distributing the Program and assumes all risks associated with its | |
26 | * exercise of rights under this Agreement, including but not limited to | |
27 | * the risks and costs of program errors, damage to or loss of data, | |
28 | * programs or equipment, and unavailability or interruption of operations. | |
29 | ||
30 | * DISCLAIMER OF LIABILITY | |
31 | * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY | |
32 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
33 | * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND | |
34 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | |
35 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
36 | * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED | |
37 | * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES | |
38 | ||
39 | * You should have received a copy of the GNU General Public License | |
40 | * along with this program; if not, write to the Free Software | |
41 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | |
42 | * USA. | |
43 | */ | |
44 | ||
f92363d1 SR |
45 | #include <linux/module.h> |
46 | #include <linux/kernel.h> | |
47 | #include <linux/init.h> | |
48 | #include <linux/errno.h> | |
49 | #include <linux/blkdev.h> | |
50 | #include <linux/sched.h> | |
51 | #include <linux/workqueue.h> | |
52 | #include <linux/delay.h> | |
53 | #include <linux/pci.h> | |
ffdadd68 | 54 | #include <linux/pci-aspm.h> |
f92363d1 SR |
55 | #include <linux/interrupt.h> |
56 | #include <linux/aer.h> | |
57 | #include <linux/raid_class.h> | |
7786ab6a | 58 | #include <asm/unaligned.h> |
f92363d1 SR |
59 | |
60 | #include "mpt3sas_base.h" | |
61 | ||
f92363d1 | 62 | #define RAID_CHANNEL 1 |
d88e1eab SPS |
63 | |
64 | #define PCIE_CHANNEL 2 | |
65 | ||
f92363d1 SR |
66 | /* forward proto's */ |
67 | static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc, | |
68 | struct _sas_node *sas_expander); | |
69 | static void _firmware_event_work(struct work_struct *work); | |
70 | ||
71 | static void _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc, | |
72 | struct _sas_device *sas_device); | |
73 | static int _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, | |
74 | u8 retry_count, u8 is_pd); | |
c102e00c | 75 | static int _scsih_pcie_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle); |
3075ac49 SPS |
76 | static void _scsih_pcie_device_remove_from_sml(struct MPT3SAS_ADAPTER *ioc, |
77 | struct _pcie_device *pcie_device); | |
4318c734 SPS |
78 | static void |
79 | _scsih_pcie_check_device(struct MPT3SAS_ADAPTER *ioc, u16 handle); | |
f92363d1 SR |
80 | static u8 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid); |
81 | ||
f92363d1 SR |
82 | /* global parameters */ |
83 | LIST_HEAD(mpt3sas_ioc_list); | |
08c4d550 SR |
84 | /* global ioc lock for list operations */ |
85 | DEFINE_SPINLOCK(gioc_lock); | |
f92363d1 | 86 | |
c84b06a4 SR |
87 | MODULE_AUTHOR(MPT3SAS_AUTHOR); |
88 | MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION); | |
89 | MODULE_LICENSE("GPL"); | |
90 | MODULE_VERSION(MPT3SAS_DRIVER_VERSION); | |
91 | MODULE_ALIAS("mpt2sas"); | |
92 | ||
f92363d1 SR |
93 | /* local parameters */ |
94 | static u8 scsi_io_cb_idx = -1; | |
95 | static u8 tm_cb_idx = -1; | |
96 | static u8 ctl_cb_idx = -1; | |
97 | static u8 base_cb_idx = -1; | |
98 | static u8 port_enable_cb_idx = -1; | |
99 | static u8 transport_cb_idx = -1; | |
100 | static u8 scsih_cb_idx = -1; | |
101 | static u8 config_cb_idx = -1; | |
c84b06a4 SR |
102 | static int mpt2_ids; |
103 | static int mpt3_ids; | |
f92363d1 SR |
104 | |
105 | static u8 tm_tr_cb_idx = -1 ; | |
106 | static u8 tm_tr_volume_cb_idx = -1 ; | |
107 | static u8 tm_sas_control_cb_idx = -1; | |
108 | ||
109 | /* command line options */ | |
110 | static u32 logging_level; | |
111 | MODULE_PARM_DESC(logging_level, | |
112 | " bits for enabling additional logging info (default=0)"); | |
113 | ||
114 | ||
115 | static ushort max_sectors = 0xFFFF; | |
116 | module_param(max_sectors, ushort, 0); | |
117 | MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767"); | |
118 | ||
119 | ||
120 | static int missing_delay[2] = {-1, -1}; | |
121 | module_param_array(missing_delay, int, NULL, 0); | |
122 | MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay"); | |
123 | ||
124 | /* scsi-mid layer global parmeter is max_report_luns, which is 511 */ | |
125 | #define MPT3SAS_MAX_LUN (16895) | |
1abf635d HR |
126 | static u64 max_lun = MPT3SAS_MAX_LUN; |
127 | module_param(max_lun, ullong, 0); | |
f92363d1 SR |
128 | MODULE_PARM_DESC(max_lun, " max lun, default=16895 "); |
129 | ||
c84b06a4 SR |
130 | static ushort hbas_to_enumerate; |
131 | module_param(hbas_to_enumerate, ushort, 0); | |
132 | MODULE_PARM_DESC(hbas_to_enumerate, | |
133 | " 0 - enumerates both SAS 2.0 & SAS 3.0 generation HBAs\n \ | |
134 | 1 - enumerates only SAS 2.0 generation HBAs\n \ | |
135 | 2 - enumerates only SAS 3.0 generation HBAs (default=0)"); | |
f92363d1 SR |
136 | |
137 | /* diag_buffer_enable is bitwise | |
138 | * bit 0 set = TRACE | |
139 | * bit 1 set = SNAPSHOT | |
140 | * bit 2 set = EXTENDED | |
141 | * | |
142 | * Either bit can be set, or both | |
143 | */ | |
144 | static int diag_buffer_enable = -1; | |
145 | module_param(diag_buffer_enable, int, 0); | |
146 | MODULE_PARM_DESC(diag_buffer_enable, | |
147 | " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)"); | |
148 | static int disable_discovery = -1; | |
149 | module_param(disable_discovery, int, 0); | |
150 | MODULE_PARM_DESC(disable_discovery, " disable discovery "); | |
151 | ||
152 | ||
153 | /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */ | |
154 | static int prot_mask = -1; | |
155 | module_param(prot_mask, int, 0); | |
156 | MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 "); | |
157 | ||
158 | ||
159 | /* raid transport support */ | |
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. | |
287 | * | |
288 | * Note: The logging levels are defined in mpt3sas_debug.h. | |
289 | */ | |
290 | static int | |
e4dca7b7 | 291 | _scsih_set_debug_level(const char *val, const struct kernel_param *kp) |
f92363d1 SR |
292 | { |
293 | int ret = param_set_int(val, kp); | |
294 | struct MPT3SAS_ADAPTER *ioc; | |
295 | ||
296 | if (ret) | |
297 | return ret; | |
298 | ||
299 | pr_info("setting logging_level(0x%08x)\n", logging_level); | |
08c4d550 | 300 | spin_lock(&gioc_lock); |
f92363d1 SR |
301 | list_for_each_entry(ioc, &mpt3sas_ioc_list, list) |
302 | ioc->logging_level = logging_level; | |
08c4d550 | 303 | spin_unlock(&gioc_lock); |
f92363d1 SR |
304 | return 0; |
305 | } | |
306 | module_param_call(logging_level, _scsih_set_debug_level, param_get_int, | |
307 | &logging_level, 0644); | |
308 | ||
309 | /** | |
310 | * _scsih_srch_boot_sas_address - search based on sas_address | |
311 | * @sas_address: sas address | |
312 | * @boot_device: boot device object from bios page 2 | |
313 | * | |
314 | * Returns 1 when there's a match, 0 means no match. | |
315 | */ | |
316 | static inline int | |
317 | _scsih_srch_boot_sas_address(u64 sas_address, | |
318 | Mpi2BootDeviceSasWwid_t *boot_device) | |
319 | { | |
320 | return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0; | |
321 | } | |
322 | ||
323 | /** | |
324 | * _scsih_srch_boot_device_name - search based on device name | |
325 | * @device_name: device name specified in INDENTIFY fram | |
326 | * @boot_device: boot device object from bios page 2 | |
327 | * | |
328 | * Returns 1 when there's a match, 0 means no match. | |
329 | */ | |
330 | static inline int | |
331 | _scsih_srch_boot_device_name(u64 device_name, | |
332 | Mpi2BootDeviceDeviceName_t *boot_device) | |
333 | { | |
334 | return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0; | |
335 | } | |
336 | ||
337 | /** | |
338 | * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot | |
339 | * @enclosure_logical_id: enclosure logical id | |
340 | * @slot_number: slot number | |
341 | * @boot_device: boot device object from bios page 2 | |
342 | * | |
343 | * Returns 1 when there's a match, 0 means no match. | |
344 | */ | |
345 | static inline int | |
346 | _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number, | |
347 | Mpi2BootDeviceEnclosureSlot_t *boot_device) | |
348 | { | |
349 | return (enclosure_logical_id == le64_to_cpu(boot_device-> | |
350 | EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device-> | |
351 | SlotNumber)) ? 1 : 0; | |
352 | } | |
353 | ||
354 | /** | |
355 | * _scsih_is_boot_device - search for matching boot device. | |
356 | * @sas_address: sas address | |
357 | * @device_name: device name specified in INDENTIFY fram | |
358 | * @enclosure_logical_id: enclosure logical id | |
359 | * @slot_number: slot number | |
360 | * @form: specifies boot device form | |
361 | * @boot_device: boot device object from bios page 2 | |
362 | * | |
363 | * Returns 1 when there's a match, 0 means no match. | |
364 | */ | |
365 | static int | |
366 | _scsih_is_boot_device(u64 sas_address, u64 device_name, | |
367 | u64 enclosure_logical_id, u16 slot, u8 form, | |
368 | Mpi2BiosPage2BootDevice_t *boot_device) | |
369 | { | |
370 | int rc = 0; | |
371 | ||
372 | switch (form) { | |
373 | case MPI2_BIOSPAGE2_FORM_SAS_WWID: | |
374 | if (!sas_address) | |
375 | break; | |
376 | rc = _scsih_srch_boot_sas_address( | |
377 | sas_address, &boot_device->SasWwid); | |
378 | break; | |
379 | case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT: | |
380 | if (!enclosure_logical_id) | |
381 | break; | |
382 | rc = _scsih_srch_boot_encl_slot( | |
383 | enclosure_logical_id, | |
384 | slot, &boot_device->EnclosureSlot); | |
385 | break; | |
386 | case MPI2_BIOSPAGE2_FORM_DEVICE_NAME: | |
387 | if (!device_name) | |
388 | break; | |
389 | rc = _scsih_srch_boot_device_name( | |
390 | device_name, &boot_device->DeviceName); | |
391 | break; | |
392 | case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED: | |
393 | break; | |
394 | } | |
395 | ||
396 | return rc; | |
397 | } | |
398 | ||
399 | /** | |
400 | * _scsih_get_sas_address - set the sas_address for given device handle | |
401 | * @handle: device handle | |
402 | * @sas_address: sas address | |
403 | * | |
404 | * Returns 0 success, non-zero when failure | |
405 | */ | |
406 | static int | |
407 | _scsih_get_sas_address(struct MPT3SAS_ADAPTER *ioc, u16 handle, | |
408 | u64 *sas_address) | |
409 | { | |
410 | Mpi2SasDevicePage0_t sas_device_pg0; | |
411 | Mpi2ConfigReply_t mpi_reply; | |
412 | u32 ioc_status; | |
413 | ||
414 | *sas_address = 0; | |
415 | ||
f92363d1 SR |
416 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
417 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
418 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name, | |
419 | __FILE__, __LINE__, __func__); | |
420 | return -ENXIO; | |
421 | } | |
422 | ||
423 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
424 | if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { | |
758f8139 SR |
425 | /* For HBA, vSES doesn't return HBA SAS address. Instead return |
426 | * vSES's sas address. | |
427 | */ | |
428 | if ((handle <= ioc->sas_hba.num_phys) && | |
429 | (!(le32_to_cpu(sas_device_pg0.DeviceInfo) & | |
430 | MPI2_SAS_DEVICE_INFO_SEP))) | |
431 | *sas_address = ioc->sas_hba.sas_address; | |
432 | else | |
433 | *sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | |
f92363d1 SR |
434 | return 0; |
435 | } | |
436 | ||
6c7abffc | 437 | /* we hit this because the given parent handle doesn't exist */ |
f92363d1 SR |
438 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
439 | return -ENXIO; | |
440 | ||
441 | /* else error case */ | |
442 | pr_err(MPT3SAS_FMT | |
443 | "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n", | |
444 | ioc->name, handle, ioc_status, | |
445 | __FILE__, __LINE__, __func__); | |
446 | return -EIO; | |
447 | } | |
448 | ||
449 | /** | |
450 | * _scsih_determine_boot_device - determine boot device. | |
451 | * @ioc: per adapter object | |
d88e1eab SPS |
452 | * @device: sas_device or pcie_device object |
453 | * @channel: SAS or PCIe channel | |
f92363d1 SR |
454 | * |
455 | * Determines whether this device should be first reported device to | |
456 | * to scsi-ml or sas transport, this purpose is for persistent boot device. | |
457 | * There are primary, alternate, and current entries in bios page 2. The order | |
458 | * priority is primary, alternate, then current. This routine saves | |
d88e1eab | 459 | * the corresponding device object. |
f92363d1 SR |
460 | * The saved data to be used later in _scsih_probe_boot_devices(). |
461 | */ | |
462 | static void | |
d88e1eab SPS |
463 | _scsih_determine_boot_device(struct MPT3SAS_ADAPTER *ioc, void *device, |
464 | u32 channel) | |
f92363d1 SR |
465 | { |
466 | struct _sas_device *sas_device; | |
d88e1eab | 467 | struct _pcie_device *pcie_device; |
f92363d1 SR |
468 | struct _raid_device *raid_device; |
469 | u64 sas_address; | |
470 | u64 device_name; | |
471 | u64 enclosure_logical_id; | |
472 | u16 slot; | |
473 | ||
474 | /* only process this function when driver loads */ | |
475 | if (!ioc->is_driver_loading) | |
476 | return; | |
477 | ||
478 | /* no Bios, return immediately */ | |
479 | if (!ioc->bios_pg3.BiosVersion) | |
480 | return; | |
481 | ||
d88e1eab | 482 | if (channel == RAID_CHANNEL) { |
f92363d1 SR |
483 | raid_device = device; |
484 | sas_address = raid_device->wwid; | |
485 | device_name = 0; | |
486 | enclosure_logical_id = 0; | |
487 | slot = 0; | |
d88e1eab SPS |
488 | } else if (channel == PCIE_CHANNEL) { |
489 | pcie_device = device; | |
490 | sas_address = pcie_device->wwid; | |
491 | device_name = 0; | |
492 | enclosure_logical_id = 0; | |
493 | slot = 0; | |
494 | } else { | |
495 | sas_device = device; | |
496 | sas_address = sas_device->sas_address; | |
497 | device_name = sas_device->device_name; | |
498 | enclosure_logical_id = sas_device->enclosure_logical_id; | |
499 | slot = sas_device->slot; | |
f92363d1 SR |
500 | } |
501 | ||
502 | if (!ioc->req_boot_device.device) { | |
503 | if (_scsih_is_boot_device(sas_address, device_name, | |
504 | enclosure_logical_id, slot, | |
505 | (ioc->bios_pg2.ReqBootDeviceForm & | |
506 | MPI2_BIOSPAGE2_FORM_MASK), | |
507 | &ioc->bios_pg2.RequestedBootDevice)) { | |
508 | dinitprintk(ioc, pr_info(MPT3SAS_FMT | |
509 | "%s: req_boot_device(0x%016llx)\n", | |
510 | ioc->name, __func__, | |
511 | (unsigned long long)sas_address)); | |
512 | ioc->req_boot_device.device = device; | |
d88e1eab | 513 | ioc->req_boot_device.channel = channel; |
f92363d1 SR |
514 | } |
515 | } | |
516 | ||
517 | if (!ioc->req_alt_boot_device.device) { | |
518 | if (_scsih_is_boot_device(sas_address, device_name, | |
519 | enclosure_logical_id, slot, | |
520 | (ioc->bios_pg2.ReqAltBootDeviceForm & | |
521 | MPI2_BIOSPAGE2_FORM_MASK), | |
522 | &ioc->bios_pg2.RequestedAltBootDevice)) { | |
523 | dinitprintk(ioc, pr_info(MPT3SAS_FMT | |
524 | "%s: req_alt_boot_device(0x%016llx)\n", | |
525 | ioc->name, __func__, | |
526 | (unsigned long long)sas_address)); | |
527 | ioc->req_alt_boot_device.device = device; | |
d88e1eab | 528 | ioc->req_alt_boot_device.channel = channel; |
f92363d1 SR |
529 | } |
530 | } | |
531 | ||
532 | if (!ioc->current_boot_device.device) { | |
533 | if (_scsih_is_boot_device(sas_address, device_name, | |
534 | enclosure_logical_id, slot, | |
535 | (ioc->bios_pg2.CurrentBootDeviceForm & | |
536 | MPI2_BIOSPAGE2_FORM_MASK), | |
537 | &ioc->bios_pg2.CurrentBootDevice)) { | |
538 | dinitprintk(ioc, pr_info(MPT3SAS_FMT | |
539 | "%s: current_boot_device(0x%016llx)\n", | |
540 | ioc->name, __func__, | |
541 | (unsigned long long)sas_address)); | |
542 | ioc->current_boot_device.device = device; | |
d88e1eab | 543 | ioc->current_boot_device.channel = channel; |
f92363d1 SR |
544 | } |
545 | } | |
546 | } | |
547 | ||
d1cb5e49 SR |
548 | static struct _sas_device * |
549 | __mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc, | |
550 | struct MPT3SAS_TARGET *tgt_priv) | |
551 | { | |
552 | struct _sas_device *ret; | |
553 | ||
554 | assert_spin_locked(&ioc->sas_device_lock); | |
555 | ||
d88e1eab | 556 | ret = tgt_priv->sas_dev; |
d1cb5e49 SR |
557 | if (ret) |
558 | sas_device_get(ret); | |
559 | ||
560 | return ret; | |
561 | } | |
562 | ||
563 | static struct _sas_device * | |
564 | mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc, | |
565 | struct MPT3SAS_TARGET *tgt_priv) | |
566 | { | |
567 | struct _sas_device *ret; | |
568 | unsigned long flags; | |
569 | ||
570 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
571 | ret = __mpt3sas_get_sdev_from_target(ioc, tgt_priv); | |
572 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
573 | ||
574 | return ret; | |
575 | } | |
576 | ||
d88e1eab SPS |
577 | static struct _pcie_device * |
578 | __mpt3sas_get_pdev_from_target(struct MPT3SAS_ADAPTER *ioc, | |
579 | struct MPT3SAS_TARGET *tgt_priv) | |
580 | { | |
581 | struct _pcie_device *ret; | |
582 | ||
583 | assert_spin_locked(&ioc->pcie_device_lock); | |
584 | ||
585 | ret = tgt_priv->pcie_dev; | |
586 | if (ret) | |
587 | pcie_device_get(ret); | |
588 | ||
589 | return ret; | |
590 | } | |
591 | ||
592 | /** | |
593 | * mpt3sas_get_pdev_from_target - pcie device search | |
594 | * @ioc: per adapter object | |
595 | * @tgt_priv: starget private object | |
596 | * | |
597 | * Context: This function will acquire ioc->pcie_device_lock and will release | |
598 | * before returning the pcie_device object. | |
599 | * | |
600 | * This searches for pcie_device from target, then return pcie_device object. | |
601 | */ | |
494f401b | 602 | static struct _pcie_device * |
d88e1eab SPS |
603 | mpt3sas_get_pdev_from_target(struct MPT3SAS_ADAPTER *ioc, |
604 | struct MPT3SAS_TARGET *tgt_priv) | |
605 | { | |
606 | struct _pcie_device *ret; | |
607 | unsigned long flags; | |
608 | ||
609 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
610 | ret = __mpt3sas_get_pdev_from_target(ioc, tgt_priv); | |
611 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
612 | ||
613 | return ret; | |
614 | } | |
d1cb5e49 SR |
615 | |
616 | struct _sas_device * | |
617 | __mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc, | |
618 | u64 sas_address) | |
619 | { | |
620 | struct _sas_device *sas_device; | |
621 | ||
622 | assert_spin_locked(&ioc->sas_device_lock); | |
623 | ||
624 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) | |
625 | if (sas_device->sas_address == sas_address) | |
626 | goto found_device; | |
627 | ||
628 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) | |
629 | if (sas_device->sas_address == sas_address) | |
630 | goto found_device; | |
631 | ||
632 | return NULL; | |
633 | ||
634 | found_device: | |
635 | sas_device_get(sas_device); | |
636 | return sas_device; | |
637 | } | |
638 | ||
f92363d1 | 639 | /** |
d1cb5e49 | 640 | * mpt3sas_get_sdev_by_addr - sas device search |
f92363d1 SR |
641 | * @ioc: per adapter object |
642 | * @sas_address: sas address | |
643 | * Context: Calling function should acquire ioc->sas_device_lock | |
644 | * | |
645 | * This searches for sas_device based on sas_address, then return sas_device | |
646 | * object. | |
647 | */ | |
648 | struct _sas_device * | |
d1cb5e49 | 649 | mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc, |
f92363d1 SR |
650 | u64 sas_address) |
651 | { | |
652 | struct _sas_device *sas_device; | |
d1cb5e49 SR |
653 | unsigned long flags; |
654 | ||
655 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
656 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, | |
657 | sas_address); | |
658 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
659 | ||
660 | return sas_device; | |
661 | } | |
662 | ||
663 | static struct _sas_device * | |
664 | __mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
665 | { | |
666 | struct _sas_device *sas_device; | |
667 | ||
668 | assert_spin_locked(&ioc->sas_device_lock); | |
f92363d1 SR |
669 | |
670 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) | |
d1cb5e49 SR |
671 | if (sas_device->handle == handle) |
672 | goto found_device; | |
f92363d1 SR |
673 | |
674 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) | |
d1cb5e49 SR |
675 | if (sas_device->handle == handle) |
676 | goto found_device; | |
f92363d1 SR |
677 | |
678 | return NULL; | |
d1cb5e49 SR |
679 | |
680 | found_device: | |
681 | sas_device_get(sas_device); | |
682 | return sas_device; | |
f92363d1 SR |
683 | } |
684 | ||
685 | /** | |
d1cb5e49 | 686 | * mpt3sas_get_sdev_by_handle - sas device search |
f92363d1 SR |
687 | * @ioc: per adapter object |
688 | * @handle: sas device handle (assigned by firmware) | |
689 | * Context: Calling function should acquire ioc->sas_device_lock | |
690 | * | |
691 | * This searches for sas_device based on sas_address, then return sas_device | |
692 | * object. | |
693 | */ | |
c102e00c | 694 | struct _sas_device * |
d1cb5e49 | 695 | mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
f92363d1 SR |
696 | { |
697 | struct _sas_device *sas_device; | |
d1cb5e49 | 698 | unsigned long flags; |
f92363d1 | 699 | |
d1cb5e49 SR |
700 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
701 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); | |
702 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
f92363d1 | 703 | |
d1cb5e49 | 704 | return sas_device; |
f92363d1 SR |
705 | } |
706 | ||
75888956 SR |
707 | /** |
708 | * _scsih_display_enclosure_chassis_info - display device location info | |
709 | * @ioc: per adapter object | |
710 | * @sas_device: per sas device object | |
711 | * @sdev: scsi device struct | |
712 | * @starget: scsi target struct | |
713 | * | |
714 | * Returns nothing. | |
715 | */ | |
716 | static void | |
717 | _scsih_display_enclosure_chassis_info(struct MPT3SAS_ADAPTER *ioc, | |
718 | struct _sas_device *sas_device, struct scsi_device *sdev, | |
719 | struct scsi_target *starget) | |
720 | { | |
721 | if (sdev) { | |
722 | if (sas_device->enclosure_handle != 0) | |
723 | sdev_printk(KERN_INFO, sdev, | |
724 | "enclosure logical id (0x%016llx), slot(%d) \n", | |
725 | (unsigned long long) | |
726 | sas_device->enclosure_logical_id, | |
727 | sas_device->slot); | |
728 | if (sas_device->connector_name[0] != '\0') | |
729 | sdev_printk(KERN_INFO, sdev, | |
730 | "enclosure level(0x%04x), connector name( %s)\n", | |
731 | sas_device->enclosure_level, | |
732 | sas_device->connector_name); | |
733 | if (sas_device->is_chassis_slot_valid) | |
734 | sdev_printk(KERN_INFO, sdev, "chassis slot(0x%04x)\n", | |
735 | sas_device->chassis_slot); | |
736 | } else if (starget) { | |
737 | if (sas_device->enclosure_handle != 0) | |
738 | starget_printk(KERN_INFO, starget, | |
739 | "enclosure logical id(0x%016llx), slot(%d) \n", | |
740 | (unsigned long long) | |
741 | sas_device->enclosure_logical_id, | |
742 | sas_device->slot); | |
743 | if (sas_device->connector_name[0] != '\0') | |
744 | starget_printk(KERN_INFO, starget, | |
745 | "enclosure level(0x%04x), connector name( %s)\n", | |
746 | sas_device->enclosure_level, | |
747 | sas_device->connector_name); | |
748 | if (sas_device->is_chassis_slot_valid) | |
749 | starget_printk(KERN_INFO, starget, | |
750 | "chassis slot(0x%04x)\n", | |
751 | sas_device->chassis_slot); | |
752 | } else { | |
753 | if (sas_device->enclosure_handle != 0) | |
754 | pr_info(MPT3SAS_FMT | |
755 | "enclosure logical id(0x%016llx), slot(%d) \n", | |
756 | ioc->name, (unsigned long long) | |
757 | sas_device->enclosure_logical_id, | |
758 | sas_device->slot); | |
759 | if (sas_device->connector_name[0] != '\0') | |
760 | pr_info(MPT3SAS_FMT | |
761 | "enclosure level(0x%04x), connector name( %s)\n", | |
762 | ioc->name, sas_device->enclosure_level, | |
763 | sas_device->connector_name); | |
764 | if (sas_device->is_chassis_slot_valid) | |
765 | pr_info(MPT3SAS_FMT "chassis slot(0x%04x)\n", | |
766 | ioc->name, sas_device->chassis_slot); | |
767 | } | |
768 | } | |
769 | ||
f92363d1 SR |
770 | /** |
771 | * _scsih_sas_device_remove - remove sas_device from list. | |
772 | * @ioc: per adapter object | |
773 | * @sas_device: the sas_device object | |
774 | * Context: This function will acquire ioc->sas_device_lock. | |
775 | * | |
d1cb5e49 | 776 | * If sas_device is on the list, remove it and decrement its reference count. |
f92363d1 SR |
777 | */ |
778 | static void | |
779 | _scsih_sas_device_remove(struct MPT3SAS_ADAPTER *ioc, | |
780 | struct _sas_device *sas_device) | |
781 | { | |
782 | unsigned long flags; | |
783 | ||
784 | if (!sas_device) | |
785 | return; | |
e6d45e3e SR |
786 | pr_info(MPT3SAS_FMT |
787 | "removing handle(0x%04x), sas_addr(0x%016llx)\n", | |
788 | ioc->name, sas_device->handle, | |
789 | (unsigned long long) sas_device->sas_address); | |
790 | ||
75888956 | 791 | _scsih_display_enclosure_chassis_info(ioc, sas_device, NULL, NULL); |
f92363d1 | 792 | |
d1cb5e49 SR |
793 | /* |
794 | * The lock serializes access to the list, but we still need to verify | |
795 | * that nobody removed the entry while we were waiting on the lock. | |
796 | */ | |
f92363d1 | 797 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 SR |
798 | if (!list_empty(&sas_device->list)) { |
799 | list_del_init(&sas_device->list); | |
800 | sas_device_put(sas_device); | |
801 | } | |
f92363d1 SR |
802 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
803 | } | |
804 | ||
805 | /** | |
806 | * _scsih_device_remove_by_handle - removing device object by handle | |
807 | * @ioc: per adapter object | |
808 | * @handle: device handle | |
809 | * | |
810 | * Return nothing. | |
811 | */ | |
812 | static void | |
813 | _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
814 | { | |
815 | struct _sas_device *sas_device; | |
816 | unsigned long flags; | |
817 | ||
818 | if (ioc->shost_recovery) | |
819 | return; | |
820 | ||
821 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 SR |
822 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
823 | if (sas_device) { | |
824 | list_del_init(&sas_device->list); | |
825 | sas_device_put(sas_device); | |
826 | } | |
f92363d1 | 827 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
d1cb5e49 | 828 | if (sas_device) { |
f92363d1 | 829 | _scsih_remove_device(ioc, sas_device); |
d1cb5e49 SR |
830 | sas_device_put(sas_device); |
831 | } | |
f92363d1 SR |
832 | } |
833 | ||
834 | /** | |
835 | * mpt3sas_device_remove_by_sas_address - removing device object by sas address | |
836 | * @ioc: per adapter object | |
837 | * @sas_address: device sas_address | |
838 | * | |
839 | * Return nothing. | |
840 | */ | |
841 | void | |
842 | mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER *ioc, | |
843 | u64 sas_address) | |
844 | { | |
845 | struct _sas_device *sas_device; | |
846 | unsigned long flags; | |
847 | ||
848 | if (ioc->shost_recovery) | |
849 | return; | |
850 | ||
851 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 SR |
852 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, sas_address); |
853 | if (sas_device) { | |
854 | list_del_init(&sas_device->list); | |
855 | sas_device_put(sas_device); | |
856 | } | |
f92363d1 | 857 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
d1cb5e49 | 858 | if (sas_device) { |
f92363d1 | 859 | _scsih_remove_device(ioc, sas_device); |
d1cb5e49 SR |
860 | sas_device_put(sas_device); |
861 | } | |
f92363d1 SR |
862 | } |
863 | ||
864 | /** | |
865 | * _scsih_sas_device_add - insert sas_device to the list. | |
866 | * @ioc: per adapter object | |
867 | * @sas_device: the sas_device object | |
868 | * Context: This function will acquire ioc->sas_device_lock. | |
869 | * | |
870 | * Adding new object to the ioc->sas_device_list. | |
871 | */ | |
872 | static void | |
873 | _scsih_sas_device_add(struct MPT3SAS_ADAPTER *ioc, | |
874 | struct _sas_device *sas_device) | |
875 | { | |
876 | unsigned long flags; | |
877 | ||
878 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
879 | "%s: handle(0x%04x), sas_addr(0x%016llx)\n", | |
880 | ioc->name, __func__, sas_device->handle, | |
881 | (unsigned long long)sas_device->sas_address)); | |
882 | ||
75888956 SR |
883 | dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device, |
884 | NULL, NULL)); | |
e6d45e3e | 885 | |
f92363d1 | 886 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 887 | sas_device_get(sas_device); |
f92363d1 SR |
888 | list_add_tail(&sas_device->list, &ioc->sas_device_list); |
889 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
890 | ||
c696f7b8 SPS |
891 | if (ioc->hide_drives) { |
892 | clear_bit(sas_device->handle, ioc->pend_os_device_add); | |
893 | return; | |
894 | } | |
895 | ||
f92363d1 SR |
896 | if (!mpt3sas_transport_port_add(ioc, sas_device->handle, |
897 | sas_device->sas_address_parent)) { | |
898 | _scsih_sas_device_remove(ioc, sas_device); | |
899 | } else if (!sas_device->starget) { | |
900 | /* | |
901 | * When asyn scanning is enabled, its not possible to remove | |
902 | * devices while scanning is turned on due to an oops in | |
903 | * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start() | |
904 | */ | |
f5edbe77 | 905 | if (!ioc->is_driver_loading) { |
f92363d1 SR |
906 | mpt3sas_transport_port_remove(ioc, |
907 | sas_device->sas_address, | |
908 | sas_device->sas_address_parent); | |
f5edbe77 SR |
909 | _scsih_sas_device_remove(ioc, sas_device); |
910 | } | |
c696f7b8 SPS |
911 | } else |
912 | clear_bit(sas_device->handle, ioc->pend_os_device_add); | |
f92363d1 SR |
913 | } |
914 | ||
915 | /** | |
916 | * _scsih_sas_device_init_add - insert sas_device to the list. | |
917 | * @ioc: per adapter object | |
918 | * @sas_device: the sas_device object | |
919 | * Context: This function will acquire ioc->sas_device_lock. | |
920 | * | |
921 | * Adding new object at driver load time to the ioc->sas_device_init_list. | |
922 | */ | |
923 | static void | |
924 | _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER *ioc, | |
925 | struct _sas_device *sas_device) | |
926 | { | |
927 | unsigned long flags; | |
928 | ||
929 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
930 | "%s: handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
931 | __func__, sas_device->handle, | |
932 | (unsigned long long)sas_device->sas_address)); | |
933 | ||
75888956 SR |
934 | dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device, |
935 | NULL, NULL)); | |
e6d45e3e | 936 | |
f92363d1 | 937 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 938 | sas_device_get(sas_device); |
f92363d1 SR |
939 | list_add_tail(&sas_device->list, &ioc->sas_device_init_list); |
940 | _scsih_determine_boot_device(ioc, sas_device, 0); | |
941 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
942 | } | |
943 | ||
d88e1eab | 944 | |
494f401b | 945 | static struct _pcie_device * |
d88e1eab SPS |
946 | __mpt3sas_get_pdev_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid) |
947 | { | |
948 | struct _pcie_device *pcie_device; | |
949 | ||
950 | assert_spin_locked(&ioc->pcie_device_lock); | |
951 | ||
952 | list_for_each_entry(pcie_device, &ioc->pcie_device_list, list) | |
953 | if (pcie_device->wwid == wwid) | |
954 | goto found_device; | |
955 | ||
956 | list_for_each_entry(pcie_device, &ioc->pcie_device_init_list, list) | |
957 | if (pcie_device->wwid == wwid) | |
958 | goto found_device; | |
959 | ||
960 | return NULL; | |
961 | ||
962 | found_device: | |
963 | pcie_device_get(pcie_device); | |
964 | return pcie_device; | |
965 | } | |
966 | ||
967 | ||
968 | /** | |
969 | * mpt3sas_get_pdev_by_wwid - pcie device search | |
970 | * @ioc: per adapter object | |
971 | * @wwid: wwid | |
972 | * | |
973 | * Context: This function will acquire ioc->pcie_device_lock and will release | |
974 | * before returning the pcie_device object. | |
975 | * | |
976 | * This searches for pcie_device based on wwid, then return pcie_device object. | |
977 | */ | |
494f401b | 978 | static struct _pcie_device * |
d88e1eab SPS |
979 | mpt3sas_get_pdev_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid) |
980 | { | |
981 | struct _pcie_device *pcie_device; | |
982 | unsigned long flags; | |
983 | ||
984 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
985 | pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid); | |
986 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
987 | ||
988 | return pcie_device; | |
989 | } | |
990 | ||
991 | ||
494f401b | 992 | static struct _pcie_device * |
d88e1eab SPS |
993 | __mpt3sas_get_pdev_by_idchannel(struct MPT3SAS_ADAPTER *ioc, int id, |
994 | int channel) | |
995 | { | |
996 | struct _pcie_device *pcie_device; | |
997 | ||
998 | assert_spin_locked(&ioc->pcie_device_lock); | |
999 | ||
1000 | list_for_each_entry(pcie_device, &ioc->pcie_device_list, list) | |
1001 | if (pcie_device->id == id && pcie_device->channel == channel) | |
1002 | goto found_device; | |
1003 | ||
1004 | list_for_each_entry(pcie_device, &ioc->pcie_device_init_list, list) | |
1005 | if (pcie_device->id == id && pcie_device->channel == channel) | |
1006 | goto found_device; | |
1007 | ||
1008 | return NULL; | |
1009 | ||
1010 | found_device: | |
1011 | pcie_device_get(pcie_device); | |
1012 | return pcie_device; | |
1013 | } | |
1014 | ||
494f401b | 1015 | static struct _pcie_device * |
c102e00c SPS |
1016 | __mpt3sas_get_pdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
1017 | { | |
1018 | struct _pcie_device *pcie_device; | |
1019 | ||
1020 | assert_spin_locked(&ioc->pcie_device_lock); | |
1021 | ||
1022 | list_for_each_entry(pcie_device, &ioc->pcie_device_list, list) | |
1023 | if (pcie_device->handle == handle) | |
1024 | goto found_device; | |
1025 | ||
1026 | list_for_each_entry(pcie_device, &ioc->pcie_device_init_list, list) | |
1027 | if (pcie_device->handle == handle) | |
1028 | goto found_device; | |
1029 | ||
1030 | return NULL; | |
1031 | ||
1032 | found_device: | |
1033 | pcie_device_get(pcie_device); | |
1034 | return pcie_device; | |
1035 | } | |
1036 | ||
1037 | ||
1038 | /** | |
1039 | * mpt3sas_get_pdev_by_handle - pcie device search | |
1040 | * @ioc: per adapter object | |
1041 | * @handle: Firmware device handle | |
1042 | * | |
1043 | * Context: This function will acquire ioc->pcie_device_lock and will release | |
1044 | * before returning the pcie_device object. | |
1045 | * | |
1046 | * This searches for pcie_device based on handle, then return pcie_device | |
1047 | * object. | |
1048 | */ | |
1049 | struct _pcie_device * | |
1050 | mpt3sas_get_pdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
1051 | { | |
1052 | struct _pcie_device *pcie_device; | |
1053 | unsigned long flags; | |
1054 | ||
1055 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1056 | pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle); | |
1057 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1058 | ||
1059 | return pcie_device; | |
1060 | } | |
1061 | ||
d88e1eab SPS |
1062 | /** |
1063 | * _scsih_pcie_device_remove - remove pcie_device from list. | |
1064 | * @ioc: per adapter object | |
1065 | * @pcie_device: the pcie_device object | |
1066 | * Context: This function will acquire ioc->pcie_device_lock. | |
1067 | * | |
1068 | * If pcie_device is on the list, remove it and decrement its reference count. | |
1069 | */ | |
1070 | static void | |
1071 | _scsih_pcie_device_remove(struct MPT3SAS_ADAPTER *ioc, | |
1072 | struct _pcie_device *pcie_device) | |
1073 | { | |
1074 | unsigned long flags; | |
1075 | int was_on_pcie_device_list = 0; | |
1076 | ||
1077 | if (!pcie_device) | |
1078 | return; | |
1079 | pr_info(MPT3SAS_FMT | |
1080 | "removing handle(0x%04x), wwid(0x%016llx)\n", | |
1081 | ioc->name, pcie_device->handle, | |
1082 | (unsigned long long) pcie_device->wwid); | |
1083 | if (pcie_device->enclosure_handle != 0) | |
1084 | pr_info(MPT3SAS_FMT | |
1085 | "removing enclosure logical id(0x%016llx), slot(%d)\n", | |
1086 | ioc->name, | |
1087 | (unsigned long long)pcie_device->enclosure_logical_id, | |
1088 | pcie_device->slot); | |
1089 | if (pcie_device->connector_name[0] != '\0') | |
1090 | pr_info(MPT3SAS_FMT | |
c1a6c5ac | 1091 | "removing enclosure level(0x%04x), connector name( %s)\n", |
d88e1eab SPS |
1092 | ioc->name, pcie_device->enclosure_level, |
1093 | pcie_device->connector_name); | |
1094 | ||
1095 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1096 | if (!list_empty(&pcie_device->list)) { | |
1097 | list_del_init(&pcie_device->list); | |
1098 | was_on_pcie_device_list = 1; | |
1099 | } | |
1100 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1101 | if (was_on_pcie_device_list) { | |
1102 | kfree(pcie_device->serial_number); | |
1103 | pcie_device_put(pcie_device); | |
1104 | } | |
1105 | } | |
3075ac49 SPS |
1106 | |
1107 | ||
1108 | /** | |
1109 | * _scsih_pcie_device_remove_by_handle - removing pcie device object by handle | |
1110 | * @ioc: per adapter object | |
1111 | * @handle: device handle | |
1112 | * | |
1113 | * Return nothing. | |
1114 | */ | |
1115 | static void | |
1116 | _scsih_pcie_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
1117 | { | |
1118 | struct _pcie_device *pcie_device; | |
1119 | unsigned long flags; | |
1120 | int was_on_pcie_device_list = 0; | |
1121 | ||
1122 | if (ioc->shost_recovery) | |
1123 | return; | |
1124 | ||
1125 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1126 | pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle); | |
1127 | if (pcie_device) { | |
1128 | if (!list_empty(&pcie_device->list)) { | |
1129 | list_del_init(&pcie_device->list); | |
1130 | was_on_pcie_device_list = 1; | |
1131 | pcie_device_put(pcie_device); | |
1132 | } | |
1133 | } | |
1134 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1135 | if (was_on_pcie_device_list) { | |
1136 | _scsih_pcie_device_remove_from_sml(ioc, pcie_device); | |
1137 | pcie_device_put(pcie_device); | |
1138 | } | |
1139 | } | |
1140 | ||
c102e00c SPS |
1141 | /** |
1142 | * _scsih_pcie_device_add - add pcie_device object | |
1143 | * @ioc: per adapter object | |
1144 | * @pcie_device: pcie_device object | |
1145 | * | |
1146 | * This is added to the pcie_device_list link list. | |
1147 | */ | |
1148 | static void | |
1149 | _scsih_pcie_device_add(struct MPT3SAS_ADAPTER *ioc, | |
1150 | struct _pcie_device *pcie_device) | |
1151 | { | |
1152 | unsigned long flags; | |
1153 | ||
1154 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
1155 | "%s: handle (0x%04x), wwid(0x%016llx)\n", ioc->name, __func__, | |
1156 | pcie_device->handle, (unsigned long long)pcie_device->wwid)); | |
1157 | if (pcie_device->enclosure_handle != 0) | |
1158 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
1159 | "%s: enclosure logical id(0x%016llx), slot( %d)\n", | |
1160 | ioc->name, __func__, | |
1161 | (unsigned long long)pcie_device->enclosure_logical_id, | |
1162 | pcie_device->slot)); | |
1163 | if (pcie_device->connector_name[0] != '\0') | |
1164 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
1165 | "%s: enclosure level(0x%04x), connector name( %s)\n", | |
1166 | ioc->name, __func__, pcie_device->enclosure_level, | |
1167 | pcie_device->connector_name)); | |
1168 | ||
1169 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1170 | pcie_device_get(pcie_device); | |
1171 | list_add_tail(&pcie_device->list, &ioc->pcie_device_list); | |
1172 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1173 | ||
1174 | if (scsi_add_device(ioc->shost, PCIE_CHANNEL, pcie_device->id, 0)) { | |
1175 | _scsih_pcie_device_remove(ioc, pcie_device); | |
1176 | } else if (!pcie_device->starget) { | |
1177 | if (!ioc->is_driver_loading) { | |
1178 | /*TODO-- Need to find out whether this condition will occur or not*/ | |
1179 | clear_bit(pcie_device->handle, ioc->pend_os_device_add); | |
1180 | } | |
1181 | } else | |
1182 | clear_bit(pcie_device->handle, ioc->pend_os_device_add); | |
1183 | } | |
1184 | ||
1185 | /* | |
1186 | * _scsih_pcie_device_init_add - insert pcie_device to the init list. | |
1187 | * @ioc: per adapter object | |
1188 | * @pcie_device: the pcie_device object | |
1189 | * Context: This function will acquire ioc->pcie_device_lock. | |
1190 | * | |
1191 | * Adding new object at driver load time to the ioc->pcie_device_init_list. | |
1192 | */ | |
1193 | static void | |
1194 | _scsih_pcie_device_init_add(struct MPT3SAS_ADAPTER *ioc, | |
1195 | struct _pcie_device *pcie_device) | |
1196 | { | |
1197 | unsigned long flags; | |
1198 | ||
1199 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
1200 | "%s: handle (0x%04x), wwid(0x%016llx)\n", ioc->name, __func__, | |
1201 | pcie_device->handle, (unsigned long long)pcie_device->wwid)); | |
1202 | if (pcie_device->enclosure_handle != 0) | |
1203 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
1204 | "%s: enclosure logical id(0x%016llx), slot( %d)\n", | |
1205 | ioc->name, __func__, | |
1206 | (unsigned long long)pcie_device->enclosure_logical_id, | |
1207 | pcie_device->slot)); | |
1208 | if (pcie_device->connector_name[0] != '\0') | |
1209 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
1210 | "%s: enclosure level(0x%04x), connector name( %s)\n", | |
1211 | ioc->name, __func__, pcie_device->enclosure_level, | |
1212 | pcie_device->connector_name)); | |
1213 | ||
1214 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1215 | pcie_device_get(pcie_device); | |
1216 | list_add_tail(&pcie_device->list, &ioc->pcie_device_init_list); | |
1217 | _scsih_determine_boot_device(ioc, pcie_device, PCIE_CHANNEL); | |
1218 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1219 | } | |
f92363d1 SR |
1220 | /** |
1221 | * _scsih_raid_device_find_by_id - raid device search | |
1222 | * @ioc: per adapter object | |
1223 | * @id: sas device target id | |
1224 | * @channel: sas device channel | |
1225 | * Context: Calling function should acquire ioc->raid_device_lock | |
1226 | * | |
1227 | * This searches for raid_device based on target id, then return raid_device | |
1228 | * object. | |
1229 | */ | |
1230 | static struct _raid_device * | |
1231 | _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER *ioc, int id, int channel) | |
1232 | { | |
1233 | struct _raid_device *raid_device, *r; | |
1234 | ||
1235 | r = NULL; | |
1236 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
1237 | if (raid_device->id == id && raid_device->channel == channel) { | |
1238 | r = raid_device; | |
1239 | goto out; | |
1240 | } | |
1241 | } | |
1242 | ||
1243 | out: | |
1244 | return r; | |
1245 | } | |
1246 | ||
1247 | /** | |
c84b06a4 | 1248 | * mpt3sas_raid_device_find_by_handle - raid device search |
f92363d1 SR |
1249 | * @ioc: per adapter object |
1250 | * @handle: sas device handle (assigned by firmware) | |
1251 | * Context: Calling function should acquire ioc->raid_device_lock | |
1252 | * | |
1253 | * This searches for raid_device based on handle, then return raid_device | |
1254 | * object. | |
1255 | */ | |
c84b06a4 SR |
1256 | struct _raid_device * |
1257 | mpt3sas_raid_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
f92363d1 SR |
1258 | { |
1259 | struct _raid_device *raid_device, *r; | |
1260 | ||
1261 | r = NULL; | |
1262 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
1263 | if (raid_device->handle != handle) | |
1264 | continue; | |
1265 | r = raid_device; | |
1266 | goto out; | |
1267 | } | |
1268 | ||
1269 | out: | |
1270 | return r; | |
1271 | } | |
1272 | ||
1273 | /** | |
1274 | * _scsih_raid_device_find_by_wwid - raid device search | |
1275 | * @ioc: per adapter object | |
1276 | * @handle: sas device handle (assigned by firmware) | |
1277 | * Context: Calling function should acquire ioc->raid_device_lock | |
1278 | * | |
1279 | * This searches for raid_device based on wwid, then return raid_device | |
1280 | * object. | |
1281 | */ | |
1282 | static struct _raid_device * | |
1283 | _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid) | |
1284 | { | |
1285 | struct _raid_device *raid_device, *r; | |
1286 | ||
1287 | r = NULL; | |
1288 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
1289 | if (raid_device->wwid != wwid) | |
1290 | continue; | |
1291 | r = raid_device; | |
1292 | goto out; | |
1293 | } | |
1294 | ||
1295 | out: | |
1296 | return r; | |
1297 | } | |
1298 | ||
1299 | /** | |
1300 | * _scsih_raid_device_add - add raid_device object | |
1301 | * @ioc: per adapter object | |
1302 | * @raid_device: raid_device object | |
1303 | * | |
1304 | * This is added to the raid_device_list link list. | |
1305 | */ | |
1306 | static void | |
1307 | _scsih_raid_device_add(struct MPT3SAS_ADAPTER *ioc, | |
1308 | struct _raid_device *raid_device) | |
1309 | { | |
1310 | unsigned long flags; | |
1311 | ||
1312 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
1313 | "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__, | |
1314 | raid_device->handle, (unsigned long long)raid_device->wwid)); | |
1315 | ||
1316 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1317 | list_add_tail(&raid_device->list, &ioc->raid_device_list); | |
1318 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1319 | } | |
1320 | ||
1321 | /** | |
1322 | * _scsih_raid_device_remove - delete raid_device object | |
1323 | * @ioc: per adapter object | |
1324 | * @raid_device: raid_device object | |
1325 | * | |
1326 | */ | |
1327 | static void | |
1328 | _scsih_raid_device_remove(struct MPT3SAS_ADAPTER *ioc, | |
1329 | struct _raid_device *raid_device) | |
1330 | { | |
1331 | unsigned long flags; | |
1332 | ||
1333 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1334 | list_del(&raid_device->list); | |
1335 | kfree(raid_device); | |
1336 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1337 | } | |
1338 | ||
1339 | /** | |
1340 | * mpt3sas_scsih_expander_find_by_handle - expander device search | |
1341 | * @ioc: per adapter object | |
1342 | * @handle: expander handle (assigned by firmware) | |
1343 | * Context: Calling function should acquire ioc->sas_device_lock | |
1344 | * | |
1345 | * This searches for expander device based on handle, then returns the | |
1346 | * sas_node object. | |
1347 | */ | |
1348 | struct _sas_node * | |
1349 | mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
1350 | { | |
1351 | struct _sas_node *sas_expander, *r; | |
1352 | ||
1353 | r = NULL; | |
1354 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { | |
1355 | if (sas_expander->handle != handle) | |
1356 | continue; | |
1357 | r = sas_expander; | |
1358 | goto out; | |
1359 | } | |
1360 | out: | |
1361 | return r; | |
1362 | } | |
1363 | ||
22a923c3 C |
1364 | /** |
1365 | * mpt3sas_scsih_enclosure_find_by_handle - exclosure device search | |
1366 | * @ioc: per adapter object | |
1367 | * @handle: enclosure handle (assigned by firmware) | |
1368 | * Context: Calling function should acquire ioc->sas_device_lock | |
1369 | * | |
1370 | * This searches for enclosure device based on handle, then returns the | |
1371 | * enclosure object. | |
1372 | */ | |
1373 | static struct _enclosure_node * | |
1374 | mpt3sas_scsih_enclosure_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
1375 | { | |
1376 | struct _enclosure_node *enclosure_dev, *r; | |
1377 | ||
1378 | r = NULL; | |
1379 | list_for_each_entry(enclosure_dev, &ioc->enclosure_list, list) { | |
1380 | if (le16_to_cpu(enclosure_dev->pg0.EnclosureHandle) != handle) | |
1381 | continue; | |
1382 | r = enclosure_dev; | |
1383 | goto out; | |
1384 | } | |
1385 | out: | |
1386 | return r; | |
1387 | } | |
f92363d1 SR |
1388 | /** |
1389 | * mpt3sas_scsih_expander_find_by_sas_address - expander device search | |
1390 | * @ioc: per adapter object | |
1391 | * @sas_address: sas address | |
1392 | * Context: Calling function should acquire ioc->sas_node_lock. | |
1393 | * | |
1394 | * This searches for expander device based on sas_address, then returns the | |
1395 | * sas_node object. | |
1396 | */ | |
1397 | struct _sas_node * | |
1398 | mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc, | |
1399 | u64 sas_address) | |
1400 | { | |
1401 | struct _sas_node *sas_expander, *r; | |
1402 | ||
1403 | r = NULL; | |
1404 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { | |
1405 | if (sas_expander->sas_address != sas_address) | |
1406 | continue; | |
1407 | r = sas_expander; | |
1408 | goto out; | |
1409 | } | |
1410 | out: | |
1411 | return r; | |
1412 | } | |
1413 | ||
1414 | /** | |
1415 | * _scsih_expander_node_add - insert expander device to the list. | |
1416 | * @ioc: per adapter object | |
1417 | * @sas_expander: the sas_device object | |
1418 | * Context: This function will acquire ioc->sas_node_lock. | |
1419 | * | |
1420 | * Adding new object to the ioc->sas_expander_list. | |
1421 | * | |
1422 | * Return nothing. | |
1423 | */ | |
1424 | static void | |
1425 | _scsih_expander_node_add(struct MPT3SAS_ADAPTER *ioc, | |
1426 | struct _sas_node *sas_expander) | |
1427 | { | |
1428 | unsigned long flags; | |
1429 | ||
1430 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
1431 | list_add_tail(&sas_expander->list, &ioc->sas_expander_list); | |
1432 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
1433 | } | |
1434 | ||
1435 | /** | |
1436 | * _scsih_is_end_device - determines if device is an end device | |
1437 | * @device_info: bitfield providing information about the device. | |
1438 | * Context: none | |
1439 | * | |
1440 | * Returns 1 if end device. | |
1441 | */ | |
1442 | static int | |
1443 | _scsih_is_end_device(u32 device_info) | |
1444 | { | |
1445 | if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE && | |
1446 | ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) | | |
1447 | (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) | | |
1448 | (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE))) | |
1449 | return 1; | |
1450 | else | |
1451 | return 0; | |
1452 | } | |
1453 | ||
c102e00c SPS |
1454 | /** |
1455 | * _scsih_is_nvme_device - determines if device is an nvme device | |
1456 | * @device_info: bitfield providing information about the device. | |
1457 | * Context: none | |
1458 | * | |
1459 | * Returns 1 if nvme device. | |
1460 | */ | |
1461 | static int | |
1462 | _scsih_is_nvme_device(u32 device_info) | |
1463 | { | |
1464 | if ((device_info & MPI26_PCIE_DEVINFO_MASK_DEVICE_TYPE) | |
1465 | == MPI26_PCIE_DEVINFO_NVME) | |
1466 | return 1; | |
1467 | else | |
1468 | return 0; | |
1469 | } | |
1470 | ||
459325c4 | 1471 | /** |
dbec4c90 | 1472 | * mpt3sas_scsih_scsi_lookup_get - returns scmd entry |
459325c4 C |
1473 | * @ioc: per adapter object |
1474 | * @smid: system request message index | |
1475 | * | |
1476 | * Returns the smid stored scmd pointer. | |
1477 | * Then will dereference the stored scmd pointer. | |
1478 | */ | |
dbec4c90 SPS |
1479 | struct scsi_cmnd * |
1480 | mpt3sas_scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid) | |
459325c4 C |
1481 | { |
1482 | struct scsi_cmnd *scmd = NULL; | |
dbec4c90 | 1483 | struct scsiio_tracker *st; |
459325c4 | 1484 | |
dbec4c90 SPS |
1485 | if (smid > 0 && |
1486 | smid <= ioc->scsiio_depth - INTERNAL_SCSIIO_CMDS_COUNT) { | |
1487 | u32 unique_tag = smid - 1; | |
f92363d1 | 1488 | |
dbec4c90 SPS |
1489 | scmd = scsi_host_find_tag(ioc->shost, unique_tag); |
1490 | if (scmd) { | |
1491 | st = scsi_cmd_priv(scmd); | |
1492 | if (st->cb_idx == 0xFF) | |
1493 | scmd = NULL; | |
f92363d1 SR |
1494 | } |
1495 | } | |
dbec4c90 | 1496 | return scmd; |
f92363d1 SR |
1497 | } |
1498 | ||
cf75d5d6 | 1499 | /** |
8a7e4c24 | 1500 | * scsih_change_queue_depth - setting device queue depth |
cf75d5d6 CH |
1501 | * @sdev: scsi device struct |
1502 | * @qdepth: requested queue depth | |
1503 | * | |
1504 | * Returns queue depth. | |
1505 | */ | |
8bbb1cf6 | 1506 | static int |
8a7e4c24 | 1507 | scsih_change_queue_depth(struct scsi_device *sdev, int qdepth) |
f92363d1 SR |
1508 | { |
1509 | struct Scsi_Host *shost = sdev->host; | |
1510 | int max_depth; | |
1511 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
1512 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
1513 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1514 | struct _sas_device *sas_device; | |
1515 | unsigned long flags; | |
1516 | ||
1517 | max_depth = shost->can_queue; | |
1518 | ||
1519 | /* limit max device queue for SATA to 32 */ | |
1520 | sas_device_priv_data = sdev->hostdata; | |
1521 | if (!sas_device_priv_data) | |
1522 | goto not_sata; | |
1523 | sas_target_priv_data = sas_device_priv_data->sas_target; | |
1524 | if (!sas_target_priv_data) | |
1525 | goto not_sata; | |
1526 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) | |
1527 | goto not_sata; | |
d1cb5e49 | 1528 | |
f92363d1 | 1529 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 SR |
1530 | sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data); |
1531 | if (sas_device) { | |
1532 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE) | |
1533 | max_depth = MPT3SAS_SATA_QUEUE_DEPTH; | |
1534 | ||
1535 | sas_device_put(sas_device); | |
1536 | } | |
f92363d1 SR |
1537 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
1538 | ||
1539 | not_sata: | |
1540 | ||
1541 | if (!sdev->tagged_supported) | |
1542 | max_depth = 1; | |
1543 | if (qdepth > max_depth) | |
1544 | qdepth = max_depth; | |
cf75d5d6 | 1545 | return scsi_change_queue_depth(sdev, qdepth); |
f92363d1 SR |
1546 | } |
1547 | ||
f92363d1 | 1548 | /** |
8a7e4c24 | 1549 | * scsih_target_alloc - target add routine |
f92363d1 SR |
1550 | * @starget: scsi target struct |
1551 | * | |
1552 | * Returns 0 if ok. Any other return is assumed to be an error and | |
1553 | * the device is ignored. | |
1554 | */ | |
8bbb1cf6 | 1555 | static int |
8a7e4c24 | 1556 | scsih_target_alloc(struct scsi_target *starget) |
f92363d1 SR |
1557 | { |
1558 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); | |
1559 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
1560 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1561 | struct _sas_device *sas_device; | |
1562 | struct _raid_device *raid_device; | |
d88e1eab | 1563 | struct _pcie_device *pcie_device; |
f92363d1 SR |
1564 | unsigned long flags; |
1565 | struct sas_rphy *rphy; | |
1566 | ||
62c4da44 JL |
1567 | sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data), |
1568 | GFP_KERNEL); | |
f92363d1 SR |
1569 | if (!sas_target_priv_data) |
1570 | return -ENOMEM; | |
1571 | ||
1572 | starget->hostdata = sas_target_priv_data; | |
1573 | sas_target_priv_data->starget = starget; | |
1574 | sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE; | |
1575 | ||
1576 | /* RAID volumes */ | |
1577 | if (starget->channel == RAID_CHANNEL) { | |
1578 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1579 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, | |
1580 | starget->channel); | |
1581 | if (raid_device) { | |
1582 | sas_target_priv_data->handle = raid_device->handle; | |
1583 | sas_target_priv_data->sas_address = raid_device->wwid; | |
1584 | sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME; | |
7786ab6a | 1585 | if (ioc->is_warpdrive) |
6d3a56ed SR |
1586 | sas_target_priv_data->raid_device = raid_device; |
1587 | raid_device->starget = starget; | |
f92363d1 SR |
1588 | } |
1589 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1590 | return 0; | |
1591 | } | |
1592 | ||
d88e1eab SPS |
1593 | /* PCIe devices */ |
1594 | if (starget->channel == PCIE_CHANNEL) { | |
1595 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1596 | pcie_device = __mpt3sas_get_pdev_by_idchannel(ioc, starget->id, | |
1597 | starget->channel); | |
1598 | if (pcie_device) { | |
1599 | sas_target_priv_data->handle = pcie_device->handle; | |
1600 | sas_target_priv_data->sas_address = pcie_device->wwid; | |
1601 | sas_target_priv_data->pcie_dev = pcie_device; | |
1602 | pcie_device->starget = starget; | |
1603 | pcie_device->id = starget->id; | |
1604 | pcie_device->channel = starget->channel; | |
1605 | sas_target_priv_data->flags |= | |
1606 | MPT_TARGET_FLAGS_PCIE_DEVICE; | |
1607 | if (pcie_device->fast_path) | |
1608 | sas_target_priv_data->flags |= | |
1609 | MPT_TARGET_FASTPATH_IO; | |
1610 | } | |
1611 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1612 | return 0; | |
1613 | } | |
1614 | ||
f92363d1 SR |
1615 | /* sas/sata devices */ |
1616 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
1617 | rphy = dev_to_rphy(starget->dev.parent); | |
d1cb5e49 | 1618 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 SR |
1619 | rphy->identify.sas_address); |
1620 | ||
1621 | if (sas_device) { | |
1622 | sas_target_priv_data->handle = sas_device->handle; | |
1623 | sas_target_priv_data->sas_address = sas_device->sas_address; | |
d88e1eab | 1624 | sas_target_priv_data->sas_dev = sas_device; |
f92363d1 SR |
1625 | sas_device->starget = starget; |
1626 | sas_device->id = starget->id; | |
1627 | sas_device->channel = starget->channel; | |
1628 | if (test_bit(sas_device->handle, ioc->pd_handles)) | |
1629 | sas_target_priv_data->flags |= | |
1630 | MPT_TARGET_FLAGS_RAID_COMPONENT; | |
1631 | if (sas_device->fast_path) | |
d88e1eab SPS |
1632 | sas_target_priv_data->flags |= |
1633 | MPT_TARGET_FASTPATH_IO; | |
f92363d1 SR |
1634 | } |
1635 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
1636 | ||
1637 | return 0; | |
1638 | } | |
1639 | ||
1640 | /** | |
8a7e4c24 | 1641 | * scsih_target_destroy - target destroy routine |
f92363d1 SR |
1642 | * @starget: scsi target struct |
1643 | * | |
1644 | * Returns nothing. | |
1645 | */ | |
8bbb1cf6 | 1646 | static void |
8a7e4c24 | 1647 | scsih_target_destroy(struct scsi_target *starget) |
f92363d1 SR |
1648 | { |
1649 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); | |
1650 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
1651 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1652 | struct _sas_device *sas_device; | |
1653 | struct _raid_device *raid_device; | |
d88e1eab | 1654 | struct _pcie_device *pcie_device; |
f92363d1 | 1655 | unsigned long flags; |
f92363d1 SR |
1656 | |
1657 | sas_target_priv_data = starget->hostdata; | |
1658 | if (!sas_target_priv_data) | |
1659 | return; | |
1660 | ||
1661 | if (starget->channel == RAID_CHANNEL) { | |
1662 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1663 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, | |
1664 | starget->channel); | |
1665 | if (raid_device) { | |
1666 | raid_device->starget = NULL; | |
1667 | raid_device->sdev = NULL; | |
1668 | } | |
1669 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1670 | goto out; | |
1671 | } | |
1672 | ||
d88e1eab SPS |
1673 | if (starget->channel == PCIE_CHANNEL) { |
1674 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1675 | pcie_device = __mpt3sas_get_pdev_from_target(ioc, | |
1676 | sas_target_priv_data); | |
1677 | if (pcie_device && (pcie_device->starget == starget) && | |
1678 | (pcie_device->id == starget->id) && | |
1679 | (pcie_device->channel == starget->channel)) | |
1680 | pcie_device->starget = NULL; | |
1681 | ||
1682 | if (pcie_device) { | |
1683 | /* | |
1684 | * Corresponding get() is in _scsih_target_alloc() | |
1685 | */ | |
1686 | sas_target_priv_data->pcie_dev = NULL; | |
1687 | pcie_device_put(pcie_device); | |
1688 | pcie_device_put(pcie_device); | |
1689 | } | |
1690 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1691 | goto out; | |
1692 | } | |
1693 | ||
f92363d1 | 1694 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 1695 | sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data); |
f92363d1 SR |
1696 | if (sas_device && (sas_device->starget == starget) && |
1697 | (sas_device->id == starget->id) && | |
1698 | (sas_device->channel == starget->channel)) | |
1699 | sas_device->starget = NULL; | |
1700 | ||
d1cb5e49 SR |
1701 | if (sas_device) { |
1702 | /* | |
1703 | * Corresponding get() is in _scsih_target_alloc() | |
1704 | */ | |
d88e1eab | 1705 | sas_target_priv_data->sas_dev = NULL; |
d1cb5e49 SR |
1706 | sas_device_put(sas_device); |
1707 | ||
1708 | sas_device_put(sas_device); | |
1709 | } | |
f92363d1 SR |
1710 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
1711 | ||
1712 | out: | |
1713 | kfree(sas_target_priv_data); | |
1714 | starget->hostdata = NULL; | |
1715 | } | |
1716 | ||
1717 | /** | |
8a7e4c24 | 1718 | * scsih_slave_alloc - device add routine |
f92363d1 SR |
1719 | * @sdev: scsi device struct |
1720 | * | |
1721 | * Returns 0 if ok. Any other return is assumed to be an error and | |
1722 | * the device is ignored. | |
1723 | */ | |
8bbb1cf6 | 1724 | static int |
8a7e4c24 | 1725 | scsih_slave_alloc(struct scsi_device *sdev) |
f92363d1 SR |
1726 | { |
1727 | struct Scsi_Host *shost; | |
1728 | struct MPT3SAS_ADAPTER *ioc; | |
1729 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1730 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
1731 | struct scsi_target *starget; | |
1732 | struct _raid_device *raid_device; | |
b65cfedf | 1733 | struct _sas_device *sas_device; |
d88e1eab | 1734 | struct _pcie_device *pcie_device; |
f92363d1 SR |
1735 | unsigned long flags; |
1736 | ||
62c4da44 JL |
1737 | sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data), |
1738 | GFP_KERNEL); | |
f92363d1 SR |
1739 | if (!sas_device_priv_data) |
1740 | return -ENOMEM; | |
1741 | ||
1742 | sas_device_priv_data->lun = sdev->lun; | |
1743 | sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT; | |
1744 | ||
1745 | starget = scsi_target(sdev); | |
1746 | sas_target_priv_data = starget->hostdata; | |
1747 | sas_target_priv_data->num_luns++; | |
1748 | sas_device_priv_data->sas_target = sas_target_priv_data; | |
1749 | sdev->hostdata = sas_device_priv_data; | |
1750 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT)) | |
1751 | sdev->no_uld_attach = 1; | |
1752 | ||
1753 | shost = dev_to_shost(&starget->dev); | |
1754 | ioc = shost_priv(shost); | |
1755 | if (starget->channel == RAID_CHANNEL) { | |
1756 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1757 | raid_device = _scsih_raid_device_find_by_id(ioc, | |
1758 | starget->id, starget->channel); | |
1759 | if (raid_device) | |
1760 | raid_device->sdev = sdev; /* raid is single lun */ | |
1761 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1762 | } | |
d88e1eab SPS |
1763 | if (starget->channel == PCIE_CHANNEL) { |
1764 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1765 | pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, | |
1766 | sas_target_priv_data->sas_address); | |
1767 | if (pcie_device && (pcie_device->starget == NULL)) { | |
1768 | sdev_printk(KERN_INFO, sdev, | |
1769 | "%s : pcie_device->starget set to starget @ %d\n", | |
1770 | __func__, __LINE__); | |
1771 | pcie_device->starget = starget; | |
1772 | } | |
1773 | ||
1774 | if (pcie_device) | |
1775 | pcie_device_put(pcie_device); | |
1776 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
f92363d1 | 1777 | |
d88e1eab | 1778 | } else if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { |
b65cfedf | 1779 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 1780 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
b65cfedf SR |
1781 | sas_target_priv_data->sas_address); |
1782 | if (sas_device && (sas_device->starget == NULL)) { | |
1783 | sdev_printk(KERN_INFO, sdev, | |
1784 | "%s : sas_device->starget set to starget @ %d\n", | |
d1cb5e49 | 1785 | __func__, __LINE__); |
b65cfedf SR |
1786 | sas_device->starget = starget; |
1787 | } | |
d1cb5e49 SR |
1788 | |
1789 | if (sas_device) | |
1790 | sas_device_put(sas_device); | |
1791 | ||
b65cfedf SR |
1792 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
1793 | } | |
1794 | ||
f92363d1 SR |
1795 | return 0; |
1796 | } | |
1797 | ||
1798 | /** | |
8a7e4c24 | 1799 | * scsih_slave_destroy - device destroy routine |
f92363d1 SR |
1800 | * @sdev: scsi device struct |
1801 | * | |
1802 | * Returns nothing. | |
1803 | */ | |
8bbb1cf6 | 1804 | static void |
8a7e4c24 | 1805 | scsih_slave_destroy(struct scsi_device *sdev) |
f92363d1 SR |
1806 | { |
1807 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1808 | struct scsi_target *starget; | |
1809 | struct Scsi_Host *shost; | |
1810 | struct MPT3SAS_ADAPTER *ioc; | |
1811 | struct _sas_device *sas_device; | |
d88e1eab | 1812 | struct _pcie_device *pcie_device; |
f92363d1 SR |
1813 | unsigned long flags; |
1814 | ||
1815 | if (!sdev->hostdata) | |
1816 | return; | |
1817 | ||
1818 | starget = scsi_target(sdev); | |
1819 | sas_target_priv_data = starget->hostdata; | |
1820 | sas_target_priv_data->num_luns--; | |
1821 | ||
1822 | shost = dev_to_shost(&starget->dev); | |
1823 | ioc = shost_priv(shost); | |
1824 | ||
d88e1eab SPS |
1825 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) { |
1826 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1827 | pcie_device = __mpt3sas_get_pdev_from_target(ioc, | |
1828 | sas_target_priv_data); | |
1829 | if (pcie_device && !sas_target_priv_data->num_luns) | |
1830 | pcie_device->starget = NULL; | |
1831 | ||
1832 | if (pcie_device) | |
1833 | pcie_device_put(pcie_device); | |
1834 | ||
1835 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1836 | ||
1837 | } else if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { | |
f92363d1 | 1838 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 SR |
1839 | sas_device = __mpt3sas_get_sdev_from_target(ioc, |
1840 | sas_target_priv_data); | |
f92363d1 SR |
1841 | if (sas_device && !sas_target_priv_data->num_luns) |
1842 | sas_device->starget = NULL; | |
d1cb5e49 SR |
1843 | |
1844 | if (sas_device) | |
1845 | sas_device_put(sas_device); | |
f92363d1 SR |
1846 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
1847 | } | |
1848 | ||
1849 | kfree(sdev->hostdata); | |
1850 | sdev->hostdata = NULL; | |
1851 | } | |
1852 | ||
1853 | /** | |
1854 | * _scsih_display_sata_capabilities - sata capabilities | |
1855 | * @ioc: per adapter object | |
1856 | * @handle: device handle | |
1857 | * @sdev: scsi device struct | |
1858 | */ | |
1859 | static void | |
1860 | _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc, | |
1861 | u16 handle, struct scsi_device *sdev) | |
1862 | { | |
1863 | Mpi2ConfigReply_t mpi_reply; | |
1864 | Mpi2SasDevicePage0_t sas_device_pg0; | |
1865 | u32 ioc_status; | |
1866 | u16 flags; | |
1867 | u32 device_info; | |
1868 | ||
1869 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
1870 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
1871 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
1872 | ioc->name, __FILE__, __LINE__, __func__); | |
1873 | return; | |
1874 | } | |
1875 | ||
1876 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
1877 | MPI2_IOCSTATUS_MASK; | |
1878 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
1879 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
1880 | ioc->name, __FILE__, __LINE__, __func__); | |
1881 | return; | |
1882 | } | |
1883 | ||
1884 | flags = le16_to_cpu(sas_device_pg0.Flags); | |
1885 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | |
1886 | ||
1887 | sdev_printk(KERN_INFO, sdev, | |
1888 | "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), " | |
1889 | "sw_preserve(%s)\n", | |
1890 | (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n", | |
1891 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n", | |
1892 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" : | |
1893 | "n", | |
1894 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n", | |
1895 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n", | |
1896 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n"); | |
1897 | } | |
1898 | ||
1899 | /* | |
1900 | * raid transport support - | |
1901 | * Enabled for SLES11 and newer, in older kernels the driver will panic when | |
6c7abffc | 1902 | * unloading the driver followed by a load - I believe that the subroutine |
f92363d1 SR |
1903 | * raid_class_release() is not cleaning up properly. |
1904 | */ | |
1905 | ||
1906 | /** | |
8a7e4c24 | 1907 | * scsih_is_raid - return boolean indicating device is raid volume |
f92363d1 SR |
1908 | * @dev the device struct object |
1909 | */ | |
8bbb1cf6 | 1910 | static int |
8a7e4c24 | 1911 | scsih_is_raid(struct device *dev) |
f92363d1 SR |
1912 | { |
1913 | struct scsi_device *sdev = to_scsi_device(dev); | |
7786ab6a | 1914 | struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host); |
f92363d1 | 1915 | |
7786ab6a SR |
1916 | if (ioc->is_warpdrive) |
1917 | return 0; | |
f92363d1 SR |
1918 | return (sdev->channel == RAID_CHANNEL) ? 1 : 0; |
1919 | } | |
1920 | ||
cd5897ed SPS |
1921 | static int |
1922 | scsih_is_nvme(struct device *dev) | |
1923 | { | |
1924 | struct scsi_device *sdev = to_scsi_device(dev); | |
1925 | ||
1926 | return (sdev->channel == PCIE_CHANNEL) ? 1 : 0; | |
1927 | } | |
1928 | ||
f92363d1 | 1929 | /** |
8a7e4c24 | 1930 | * scsih_get_resync - get raid volume resync percent complete |
f92363d1 SR |
1931 | * @dev the device struct object |
1932 | */ | |
8bbb1cf6 | 1933 | static void |
8a7e4c24 | 1934 | scsih_get_resync(struct device *dev) |
f92363d1 SR |
1935 | { |
1936 | struct scsi_device *sdev = to_scsi_device(dev); | |
1937 | struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host); | |
1938 | static struct _raid_device *raid_device; | |
1939 | unsigned long flags; | |
1940 | Mpi2RaidVolPage0_t vol_pg0; | |
1941 | Mpi2ConfigReply_t mpi_reply; | |
1942 | u32 volume_status_flags; | |
1943 | u8 percent_complete; | |
1944 | u16 handle; | |
1945 | ||
1946 | percent_complete = 0; | |
1947 | handle = 0; | |
7786ab6a SR |
1948 | if (ioc->is_warpdrive) |
1949 | goto out; | |
1950 | ||
f92363d1 SR |
1951 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
1952 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, | |
1953 | sdev->channel); | |
1954 | if (raid_device) { | |
1955 | handle = raid_device->handle; | |
1956 | percent_complete = raid_device->percent_complete; | |
1957 | } | |
1958 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1959 | ||
1960 | if (!handle) | |
1961 | goto out; | |
1962 | ||
1963 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0, | |
1964 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
1965 | sizeof(Mpi2RaidVolPage0_t))) { | |
1966 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
1967 | ioc->name, __FILE__, __LINE__, __func__); | |
1968 | percent_complete = 0; | |
1969 | goto out; | |
1970 | } | |
1971 | ||
1972 | volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags); | |
1973 | if (!(volume_status_flags & | |
1974 | MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)) | |
1975 | percent_complete = 0; | |
1976 | ||
1977 | out: | |
b130b0d5 SS |
1978 | |
1979 | switch (ioc->hba_mpi_version_belonged) { | |
1980 | case MPI2_VERSION: | |
c84b06a4 | 1981 | raid_set_resync(mpt2sas_raid_template, dev, percent_complete); |
b130b0d5 SS |
1982 | break; |
1983 | case MPI25_VERSION: | |
1984 | case MPI26_VERSION: | |
c84b06a4 | 1985 | raid_set_resync(mpt3sas_raid_template, dev, percent_complete); |
b130b0d5 SS |
1986 | break; |
1987 | } | |
f92363d1 SR |
1988 | } |
1989 | ||
1990 | /** | |
8a7e4c24 | 1991 | * scsih_get_state - get raid volume level |
f92363d1 SR |
1992 | * @dev the device struct object |
1993 | */ | |
8bbb1cf6 | 1994 | static void |
8a7e4c24 | 1995 | scsih_get_state(struct device *dev) |
f92363d1 SR |
1996 | { |
1997 | struct scsi_device *sdev = to_scsi_device(dev); | |
1998 | struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host); | |
1999 | static struct _raid_device *raid_device; | |
2000 | unsigned long flags; | |
2001 | Mpi2RaidVolPage0_t vol_pg0; | |
2002 | Mpi2ConfigReply_t mpi_reply; | |
2003 | u32 volstate; | |
2004 | enum raid_state state = RAID_STATE_UNKNOWN; | |
2005 | u16 handle = 0; | |
2006 | ||
2007 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
2008 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, | |
2009 | sdev->channel); | |
2010 | if (raid_device) | |
2011 | handle = raid_device->handle; | |
2012 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
2013 | ||
2014 | if (!raid_device) | |
2015 | goto out; | |
2016 | ||
2017 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0, | |
2018 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
2019 | sizeof(Mpi2RaidVolPage0_t))) { | |
2020 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
2021 | ioc->name, __FILE__, __LINE__, __func__); | |
2022 | goto out; | |
2023 | } | |
2024 | ||
2025 | volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags); | |
2026 | if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) { | |
2027 | state = RAID_STATE_RESYNCING; | |
2028 | goto out; | |
2029 | } | |
2030 | ||
2031 | switch (vol_pg0.VolumeState) { | |
2032 | case MPI2_RAID_VOL_STATE_OPTIMAL: | |
2033 | case MPI2_RAID_VOL_STATE_ONLINE: | |
2034 | state = RAID_STATE_ACTIVE; | |
2035 | break; | |
2036 | case MPI2_RAID_VOL_STATE_DEGRADED: | |
2037 | state = RAID_STATE_DEGRADED; | |
2038 | break; | |
2039 | case MPI2_RAID_VOL_STATE_FAILED: | |
2040 | case MPI2_RAID_VOL_STATE_MISSING: | |
2041 | state = RAID_STATE_OFFLINE; | |
2042 | break; | |
2043 | } | |
2044 | out: | |
b130b0d5 SS |
2045 | switch (ioc->hba_mpi_version_belonged) { |
2046 | case MPI2_VERSION: | |
c84b06a4 | 2047 | raid_set_state(mpt2sas_raid_template, dev, state); |
b130b0d5 SS |
2048 | break; |
2049 | case MPI25_VERSION: | |
2050 | case MPI26_VERSION: | |
c84b06a4 | 2051 | raid_set_state(mpt3sas_raid_template, dev, state); |
b130b0d5 SS |
2052 | break; |
2053 | } | |
f92363d1 SR |
2054 | } |
2055 | ||
2056 | /** | |
2057 | * _scsih_set_level - set raid level | |
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 | |
2099 | * @sas_device: the raid_device object | |
2100 | * | |
2101 | * Returns 0 for success, else 1 | |
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) { | |
2116 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2117 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | |
2118 | __func__)); | |
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) { | |
2127 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2128 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | |
2129 | __func__)); | |
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))) { | |
2135 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2136 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | |
2137 | __func__)); | |
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 | * | |
2193 | * Returns 0 if ok. Any other return is assumed to be an error and | |
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) { | |
2228 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2229 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, | |
2230 | __LINE__, __func__)); | |
2231 | return 1; | |
2232 | } | |
2233 | ||
2234 | if (_scsih_get_volume_capabilities(ioc, raid_device)) { | |
2235 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2236 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, | |
2237 | __LINE__, __func__)); | |
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)) { | |
2321 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2322 | "failure at %s:%d/%s()!\n", ioc->name, | |
2323 | __FILE__, __LINE__, __func__)); | |
2324 | return 1; | |
2325 | } | |
2326 | if (volume_handle && mpt3sas_config_get_volume_wwid(ioc, | |
2327 | volume_handle, &volume_wwid)) { | |
2328 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2329 | "failure at %s:%d/%s()!\n", ioc->name, | |
2330 | __FILE__, __LINE__, __func__)); | |
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); | |
2342 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2343 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, | |
2344 | __LINE__, __func__)); | |
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); | |
2390 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2391 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | |
2392 | __func__)); | |
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 | |
2452 | * | |
2453 | * Return nothing. | |
2454 | */ | |
8bbb1cf6 | 2455 | static int |
8a7e4c24 | 2456 | scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev, |
f92363d1 SR |
2457 | sector_t capacity, int params[]) |
2458 | { | |
2459 | int heads; | |
2460 | int sectors; | |
2461 | sector_t cylinders; | |
2462 | ulong dummy; | |
2463 | ||
2464 | heads = 64; | |
2465 | sectors = 32; | |
2466 | ||
2467 | dummy = heads * sectors; | |
2468 | cylinders = capacity; | |
2469 | sector_div(cylinders, dummy); | |
2470 | ||
2471 | /* | |
2472 | * Handle extended translation size for logical drives | |
2473 | * > 1Gb | |
2474 | */ | |
2475 | if ((ulong)capacity >= 0x200000) { | |
2476 | heads = 255; | |
2477 | sectors = 63; | |
2478 | dummy = heads * sectors; | |
2479 | cylinders = capacity; | |
2480 | sector_div(cylinders, dummy); | |
2481 | } | |
2482 | ||
2483 | /* return result */ | |
2484 | params[0] = heads; | |
2485 | params[1] = sectors; | |
2486 | params[2] = cylinders; | |
2487 | ||
2488 | return 0; | |
2489 | } | |
2490 | ||
2491 | /** | |
2492 | * _scsih_response_code - translation of device response code | |
2493 | * @ioc: per adapter object | |
2494 | * @response_code: response code returned by the device | |
2495 | * | |
2496 | * Return nothing. | |
2497 | */ | |
2498 | static void | |
2499 | _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code) | |
2500 | { | |
2501 | char *desc; | |
2502 | ||
2503 | switch (response_code) { | |
2504 | case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE: | |
2505 | desc = "task management request completed"; | |
2506 | break; | |
2507 | case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME: | |
2508 | desc = "invalid frame"; | |
2509 | break; | |
2510 | case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED: | |
2511 | desc = "task management request not supported"; | |
2512 | break; | |
2513 | case MPI2_SCSITASKMGMT_RSP_TM_FAILED: | |
2514 | desc = "task management request failed"; | |
2515 | break; | |
2516 | case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED: | |
2517 | desc = "task management request succeeded"; | |
2518 | break; | |
2519 | case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN: | |
2520 | desc = "invalid lun"; | |
2521 | break; | |
2522 | case 0xA: | |
2523 | desc = "overlapped tag attempted"; | |
2524 | break; | |
2525 | case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC: | |
2526 | desc = "task queued, however not sent to target"; | |
2527 | break; | |
2528 | default: | |
2529 | desc = "unknown"; | |
2530 | break; | |
2531 | } | |
2532 | pr_warn(MPT3SAS_FMT "response_code(0x%01x): %s\n", | |
2533 | ioc->name, response_code, desc); | |
2534 | } | |
2535 | ||
2536 | /** | |
2537 | * _scsih_tm_done - tm completion routine | |
2538 | * @ioc: per adapter object | |
2539 | * @smid: system request message index | |
2540 | * @msix_index: MSIX table index supplied by the OS | |
2541 | * @reply: reply message frame(lower 32bit addr) | |
2542 | * Context: none. | |
2543 | * | |
2544 | * The callback handler when using scsih_issue_tm. | |
2545 | * | |
2546 | * Return 1 meaning mf should be freed from _base_interrupt | |
2547 | * 0 means the mf is freed from this function. | |
2548 | */ | |
2549 | static u8 | |
2550 | _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | |
2551 | { | |
2552 | MPI2DefaultReply_t *mpi_reply; | |
2553 | ||
2554 | if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED) | |
2555 | return 1; | |
2556 | if (ioc->tm_cmds.smid != smid) | |
2557 | return 1; | |
f92363d1 SR |
2558 | ioc->tm_cmds.status |= MPT3_CMD_COMPLETE; |
2559 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
2560 | if (mpi_reply) { | |
2561 | memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); | |
2562 | ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID; | |
2563 | } | |
2564 | ioc->tm_cmds.status &= ~MPT3_CMD_PENDING; | |
2565 | complete(&ioc->tm_cmds.done); | |
2566 | return 1; | |
2567 | } | |
2568 | ||
2569 | /** | |
2570 | * mpt3sas_scsih_set_tm_flag - set per target tm_busy | |
2571 | * @ioc: per adapter object | |
2572 | * @handle: device handle | |
2573 | * | |
2574 | * During taskmangement request, we need to freeze the device queue. | |
2575 | */ | |
2576 | void | |
2577 | mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
2578 | { | |
2579 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2580 | struct scsi_device *sdev; | |
2581 | u8 skip = 0; | |
2582 | ||
2583 | shost_for_each_device(sdev, ioc->shost) { | |
2584 | if (skip) | |
2585 | continue; | |
2586 | sas_device_priv_data = sdev->hostdata; | |
2587 | if (!sas_device_priv_data) | |
2588 | continue; | |
2589 | if (sas_device_priv_data->sas_target->handle == handle) { | |
2590 | sas_device_priv_data->sas_target->tm_busy = 1; | |
2591 | skip = 1; | |
2592 | ioc->ignore_loginfos = 1; | |
2593 | } | |
2594 | } | |
2595 | } | |
2596 | ||
2597 | /** | |
2598 | * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy | |
2599 | * @ioc: per adapter object | |
2600 | * @handle: device handle | |
2601 | * | |
2602 | * During taskmangement request, we need to freeze the device queue. | |
2603 | */ | |
2604 | void | |
2605 | mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
2606 | { | |
2607 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2608 | struct scsi_device *sdev; | |
2609 | u8 skip = 0; | |
2610 | ||
2611 | shost_for_each_device(sdev, ioc->shost) { | |
2612 | if (skip) | |
2613 | continue; | |
2614 | sas_device_priv_data = sdev->hostdata; | |
2615 | if (!sas_device_priv_data) | |
2616 | continue; | |
2617 | if (sas_device_priv_data->sas_target->handle == handle) { | |
2618 | sas_device_priv_data->sas_target->tm_busy = 0; | |
2619 | skip = 1; | |
2620 | ioc->ignore_loginfos = 0; | |
2621 | } | |
2622 | } | |
2623 | } | |
2624 | ||
2625 | /** | |
2626 | * mpt3sas_scsih_issue_tm - main routine for sending tm requests | |
2627 | * @ioc: per adapter struct | |
6da999fe | 2628 | * @handle: device handle |
f92363d1 SR |
2629 | * @lun: lun number |
2630 | * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h) | |
2631 | * @smid_task: smid assigned to the task | |
6da999fe | 2632 | * @msix_task: MSIX table index supplied by the OS |
f92363d1 | 2633 | * @timeout: timeout in seconds |
c1a6c5ac | 2634 | * @tr_method: Target Reset Method |
f92363d1 SR |
2635 | * Context: user |
2636 | * | |
2637 | * A generic API for sending task management requests to firmware. | |
2638 | * | |
2639 | * The callback index is set inside `ioc->tm_cb_idx`. | |
6da999fe | 2640 | * The caller is responsible to check for outstanding commands. |
f92363d1 SR |
2641 | * |
2642 | * Return SUCCESS or FAILED. | |
2643 | */ | |
2644 | int | |
c1a6c5ac C |
2645 | mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, u64 lun, |
2646 | u8 type, u16 smid_task, u16 msix_task, u8 timeout, u8 tr_method) | |
f92363d1 SR |
2647 | { |
2648 | Mpi2SCSITaskManagementRequest_t *mpi_request; | |
2649 | Mpi2SCSITaskManagementReply_t *mpi_reply; | |
2650 | u16 smid = 0; | |
2651 | u32 ioc_state; | |
f92363d1 SR |
2652 | int rc; |
2653 | ||
96902835 CO |
2654 | lockdep_assert_held(&ioc->tm_cmds.mutex); |
2655 | ||
f92363d1 SR |
2656 | if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) { |
2657 | pr_info(MPT3SAS_FMT "%s: tm_cmd busy!!!\n", | |
2658 | __func__, ioc->name); | |
96902835 | 2659 | return FAILED; |
f92363d1 SR |
2660 | } |
2661 | ||
2662 | if (ioc->shost_recovery || ioc->remove_host || | |
2663 | ioc->pci_error_recovery) { | |
2664 | pr_info(MPT3SAS_FMT "%s: host reset in progress!\n", | |
2665 | __func__, ioc->name); | |
96902835 | 2666 | return FAILED; |
f92363d1 SR |
2667 | } |
2668 | ||
2669 | ioc_state = mpt3sas_base_get_iocstate(ioc, 0); | |
2670 | if (ioc_state & MPI2_DOORBELL_USED) { | |
2671 | dhsprintk(ioc, pr_info(MPT3SAS_FMT | |
2672 | "unexpected doorbell active!\n", ioc->name)); | |
98c56ad3 | 2673 | rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
96902835 | 2674 | return (!rc) ? SUCCESS : FAILED; |
f92363d1 SR |
2675 | } |
2676 | ||
2677 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { | |
2678 | mpt3sas_base_fault_info(ioc, ioc_state & | |
2679 | MPI2_DOORBELL_DATA_MASK); | |
98c56ad3 | 2680 | rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
96902835 | 2681 | return (!rc) ? SUCCESS : FAILED; |
f92363d1 SR |
2682 | } |
2683 | ||
2684 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx); | |
2685 | if (!smid) { | |
2686 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
2687 | ioc->name, __func__); | |
96902835 | 2688 | return FAILED; |
f92363d1 SR |
2689 | } |
2690 | ||
f92363d1 | 2691 | dtmprintk(ioc, pr_info(MPT3SAS_FMT |
c1a6c5ac C |
2692 | "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d), timeout(%d), tr_method(0x%x)\n", |
2693 | ioc->name, handle, type, smid_task, timeout, tr_method)); | |
f92363d1 SR |
2694 | ioc->tm_cmds.status = MPT3_CMD_PENDING; |
2695 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
2696 | ioc->tm_cmds.smid = smid; | |
2697 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | |
2698 | memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t)); | |
2699 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | |
2700 | mpi_request->DevHandle = cpu_to_le16(handle); | |
2701 | mpi_request->TaskType = type; | |
c1a6c5ac | 2702 | mpi_request->MsgFlags = tr_method; |
f92363d1 SR |
2703 | mpi_request->TaskMID = cpu_to_le16(smid_task); |
2704 | int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN); | |
2705 | mpt3sas_scsih_set_tm_flag(ioc, handle); | |
2706 | init_completion(&ioc->tm_cmds.done); | |
40114bde | 2707 | mpt3sas_base_put_smid_hi_priority(ioc, smid, msix_task); |
8bbb1cf6 | 2708 | wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ); |
f92363d1 | 2709 | if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) { |
d37306ca C |
2710 | if (mpt3sas_base_check_cmd_timeout(ioc, |
2711 | ioc->tm_cmds.status, mpi_request, | |
2712 | sizeof(Mpi2SCSITaskManagementRequest_t)/4)) { | |
98c56ad3 CO |
2713 | rc = mpt3sas_base_hard_reset_handler(ioc, |
2714 | FORCE_BIG_HAMMER); | |
f92363d1 | 2715 | rc = (!rc) ? SUCCESS : FAILED; |
96902835 | 2716 | goto out; |
f92363d1 SR |
2717 | } |
2718 | } | |
2719 | ||
5f0dfb7a C |
2720 | /* sync IRQs in case those were busy during flush. */ |
2721 | mpt3sas_base_sync_reply_irqs(ioc); | |
2722 | ||
f92363d1 SR |
2723 | if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) { |
2724 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT); | |
2725 | mpi_reply = ioc->tm_cmds.reply; | |
2726 | dtmprintk(ioc, pr_info(MPT3SAS_FMT "complete tm: " \ | |
2727 | "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n", | |
2728 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), | |
2729 | le32_to_cpu(mpi_reply->IOCLogInfo), | |
2730 | le32_to_cpu(mpi_reply->TerminationCount))); | |
2731 | if (ioc->logging_level & MPT_DEBUG_TM) { | |
2732 | _scsih_response_code(ioc, mpi_reply->ResponseCode); | |
2733 | if (mpi_reply->IOCStatus) | |
2734 | _debug_dump_mf(mpi_request, | |
2735 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); | |
2736 | } | |
2737 | } | |
6da999fe | 2738 | rc = SUCCESS; |
f92363d1 | 2739 | |
96902835 | 2740 | out: |
f92363d1 SR |
2741 | mpt3sas_scsih_clear_tm_flag(ioc, handle); |
2742 | ioc->tm_cmds.status = MPT3_CMD_NOT_USED; | |
f92363d1 | 2743 | return rc; |
96902835 | 2744 | } |
f92363d1 | 2745 | |
96902835 | 2746 | int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, |
c1a6c5ac C |
2747 | u64 lun, u8 type, u16 smid_task, u16 msix_task, |
2748 | u8 timeout, u8 tr_method) | |
96902835 CO |
2749 | { |
2750 | int ret; | |
2751 | ||
2752 | mutex_lock(&ioc->tm_cmds.mutex); | |
6da999fe | 2753 | ret = mpt3sas_scsih_issue_tm(ioc, handle, lun, type, smid_task, |
c1a6c5ac | 2754 | msix_task, timeout, tr_method); |
96902835 CO |
2755 | mutex_unlock(&ioc->tm_cmds.mutex); |
2756 | ||
2757 | return ret; | |
f92363d1 SR |
2758 | } |
2759 | ||
2760 | /** | |
2761 | * _scsih_tm_display_info - displays info about the device | |
2762 | * @ioc: per adapter struct | |
2763 | * @scmd: pointer to scsi command object | |
2764 | * | |
2765 | * Called by task management callback handlers. | |
2766 | */ | |
2767 | static void | |
2768 | _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd) | |
2769 | { | |
2770 | struct scsi_target *starget = scmd->device->sdev_target; | |
2771 | struct MPT3SAS_TARGET *priv_target = starget->hostdata; | |
2772 | struct _sas_device *sas_device = NULL; | |
6ce2f1d1 | 2773 | struct _pcie_device *pcie_device = NULL; |
f92363d1 SR |
2774 | unsigned long flags; |
2775 | char *device_str = NULL; | |
2776 | ||
2777 | if (!priv_target) | |
2778 | return; | |
7786ab6a SR |
2779 | if (ioc->hide_ir_msg) |
2780 | device_str = "WarpDrive"; | |
2781 | else | |
2782 | device_str = "volume"; | |
f92363d1 SR |
2783 | |
2784 | scsi_print_command(scmd); | |
2785 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { | |
2786 | starget_printk(KERN_INFO, starget, | |
2787 | "%s handle(0x%04x), %s wwid(0x%016llx)\n", | |
2788 | device_str, priv_target->handle, | |
2789 | device_str, (unsigned long long)priv_target->sas_address); | |
6ce2f1d1 SPS |
2790 | |
2791 | } else if (priv_target->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) { | |
2792 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
2793 | pcie_device = __mpt3sas_get_pdev_from_target(ioc, priv_target); | |
2794 | if (pcie_device) { | |
2795 | starget_printk(KERN_INFO, starget, | |
2796 | "handle(0x%04x), wwid(0x%016llx), port(%d)\n", | |
2797 | pcie_device->handle, | |
2798 | (unsigned long long)pcie_device->wwid, | |
2799 | pcie_device->port_num); | |
2800 | if (pcie_device->enclosure_handle != 0) | |
2801 | starget_printk(KERN_INFO, starget, | |
2802 | "enclosure logical id(0x%016llx), slot(%d)\n", | |
2803 | (unsigned long long) | |
2804 | pcie_device->enclosure_logical_id, | |
2805 | pcie_device->slot); | |
2806 | if (pcie_device->connector_name[0] != '\0') | |
2807 | starget_printk(KERN_INFO, starget, | |
2808 | "enclosure level(0x%04x), connector name( %s)\n", | |
2809 | pcie_device->enclosure_level, | |
2810 | pcie_device->connector_name); | |
2811 | pcie_device_put(pcie_device); | |
2812 | } | |
2813 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
2814 | ||
f92363d1 SR |
2815 | } else { |
2816 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 | 2817 | sas_device = __mpt3sas_get_sdev_from_target(ioc, priv_target); |
f92363d1 SR |
2818 | if (sas_device) { |
2819 | if (priv_target->flags & | |
2820 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
2821 | starget_printk(KERN_INFO, starget, | |
2822 | "volume handle(0x%04x), " | |
2823 | "volume wwid(0x%016llx)\n", | |
2824 | sas_device->volume_handle, | |
2825 | (unsigned long long)sas_device->volume_wwid); | |
2826 | } | |
2827 | starget_printk(KERN_INFO, starget, | |
2828 | "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n", | |
2829 | sas_device->handle, | |
2830 | (unsigned long long)sas_device->sas_address, | |
2831 | sas_device->phy); | |
75888956 SR |
2832 | |
2833 | _scsih_display_enclosure_chassis_info(NULL, sas_device, | |
2834 | NULL, starget); | |
d1cb5e49 SR |
2835 | |
2836 | sas_device_put(sas_device); | |
f92363d1 SR |
2837 | } |
2838 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
2839 | } | |
2840 | } | |
2841 | ||
2842 | /** | |
8a7e4c24 | 2843 | * scsih_abort - eh threads main abort routine |
f92363d1 SR |
2844 | * @scmd: pointer to scsi command object |
2845 | * | |
2846 | * Returns SUCCESS if command aborted else FAILED | |
2847 | */ | |
8bbb1cf6 | 2848 | static int |
8a7e4c24 | 2849 | scsih_abort(struct scsi_cmnd *scmd) |
f92363d1 SR |
2850 | { |
2851 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
2852 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
dbec4c90 | 2853 | struct scsiio_tracker *st = scsi_cmd_priv(scmd); |
f92363d1 SR |
2854 | u16 handle; |
2855 | int r; | |
2856 | ||
c1a6c5ac C |
2857 | u8 timeout = 30; |
2858 | struct _pcie_device *pcie_device = NULL; | |
f92363d1 SR |
2859 | sdev_printk(KERN_INFO, scmd->device, |
2860 | "attempting task abort! scmd(%p)\n", scmd); | |
2861 | _scsih_tm_display_info(ioc, scmd); | |
2862 | ||
2863 | sas_device_priv_data = scmd->device->hostdata; | |
9ff549ff MFO |
2864 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target || |
2865 | ioc->remove_host) { | |
f92363d1 SR |
2866 | sdev_printk(KERN_INFO, scmd->device, |
2867 | "device been deleted! scmd(%p)\n", scmd); | |
2868 | scmd->result = DID_NO_CONNECT << 16; | |
2869 | scmd->scsi_done(scmd); | |
2870 | r = SUCCESS; | |
2871 | goto out; | |
2872 | } | |
2873 | ||
dbec4c90 SPS |
2874 | /* check for completed command */ |
2875 | if (st == NULL || st->cb_idx == 0xFF) { | |
f92363d1 SR |
2876 | scmd->result = DID_RESET << 16; |
2877 | r = SUCCESS; | |
2878 | goto out; | |
2879 | } | |
2880 | ||
2881 | /* for hidden raid components and volumes this is not supported */ | |
2882 | if (sas_device_priv_data->sas_target->flags & | |
2883 | MPT_TARGET_FLAGS_RAID_COMPONENT || | |
2884 | sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) { | |
2885 | scmd->result = DID_RESET << 16; | |
2886 | r = FAILED; | |
2887 | goto out; | |
2888 | } | |
2889 | ||
2890 | mpt3sas_halt_firmware(ioc); | |
2891 | ||
2892 | handle = sas_device_priv_data->sas_target->handle; | |
c1a6c5ac C |
2893 | pcie_device = mpt3sas_get_pdev_by_handle(ioc, handle); |
2894 | if (pcie_device && (!ioc->tm_custom_handling)) | |
2895 | timeout = ioc->nvme_abort_timeout; | |
6da999fe HR |
2896 | r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->lun, |
2897 | MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, | |
c1a6c5ac | 2898 | st->smid, st->msix_io, timeout, 0); |
6da999fe | 2899 | /* Command must be cleared after abort */ |
dbec4c90 | 2900 | if (r == SUCCESS && st->cb_idx != 0xFF) |
6da999fe | 2901 | r = FAILED; |
f92363d1 SR |
2902 | out: |
2903 | sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n", | |
2904 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
c1a6c5ac C |
2905 | if (pcie_device) |
2906 | pcie_device_put(pcie_device); | |
f92363d1 SR |
2907 | return r; |
2908 | } | |
2909 | ||
2910 | /** | |
8a7e4c24 | 2911 | * scsih_dev_reset - eh threads main device reset routine |
f92363d1 SR |
2912 | * @scmd: pointer to scsi command object |
2913 | * | |
2914 | * Returns SUCCESS if command aborted else FAILED | |
2915 | */ | |
8bbb1cf6 | 2916 | static int |
8a7e4c24 | 2917 | scsih_dev_reset(struct scsi_cmnd *scmd) |
f92363d1 SR |
2918 | { |
2919 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
2920 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
d1cb5e49 | 2921 | struct _sas_device *sas_device = NULL; |
c1a6c5ac | 2922 | struct _pcie_device *pcie_device = NULL; |
f92363d1 | 2923 | u16 handle; |
c1a6c5ac C |
2924 | u8 tr_method = 0; |
2925 | u8 tr_timeout = 30; | |
f92363d1 SR |
2926 | int r; |
2927 | ||
d1cb5e49 SR |
2928 | struct scsi_target *starget = scmd->device->sdev_target; |
2929 | struct MPT3SAS_TARGET *target_priv_data = starget->hostdata; | |
2930 | ||
f92363d1 SR |
2931 | sdev_printk(KERN_INFO, scmd->device, |
2932 | "attempting device reset! scmd(%p)\n", scmd); | |
2933 | _scsih_tm_display_info(ioc, scmd); | |
2934 | ||
2935 | sas_device_priv_data = scmd->device->hostdata; | |
9ff549ff MFO |
2936 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target || |
2937 | ioc->remove_host) { | |
f92363d1 SR |
2938 | sdev_printk(KERN_INFO, scmd->device, |
2939 | "device been deleted! scmd(%p)\n", scmd); | |
2940 | scmd->result = DID_NO_CONNECT << 16; | |
2941 | scmd->scsi_done(scmd); | |
2942 | r = SUCCESS; | |
2943 | goto out; | |
2944 | } | |
2945 | ||
2946 | /* for hidden raid components obtain the volume_handle */ | |
2947 | handle = 0; | |
2948 | if (sas_device_priv_data->sas_target->flags & | |
2949 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
d1cb5e49 SR |
2950 | sas_device = mpt3sas_get_sdev_from_target(ioc, |
2951 | target_priv_data); | |
f92363d1 SR |
2952 | if (sas_device) |
2953 | handle = sas_device->volume_handle; | |
f92363d1 SR |
2954 | } else |
2955 | handle = sas_device_priv_data->sas_target->handle; | |
2956 | ||
2957 | if (!handle) { | |
2958 | scmd->result = DID_RESET << 16; | |
2959 | r = FAILED; | |
2960 | goto out; | |
2961 | } | |
2962 | ||
c1a6c5ac C |
2963 | pcie_device = mpt3sas_get_pdev_by_handle(ioc, handle); |
2964 | ||
2965 | if (pcie_device && (!ioc->tm_custom_handling)) { | |
2966 | tr_timeout = pcie_device->reset_timeout; | |
2967 | tr_method = MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE; | |
2968 | } else | |
2969 | tr_method = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET; | |
6da999fe | 2970 | r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->lun, |
c1a6c5ac C |
2971 | MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 0, |
2972 | tr_timeout, tr_method); | |
74fcfa53 HR |
2973 | /* Check for busy commands after reset */ |
2974 | if (r == SUCCESS && atomic_read(&scmd->device->device_busy)) | |
2975 | r = FAILED; | |
f92363d1 SR |
2976 | out: |
2977 | sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n", | |
2978 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
d1cb5e49 SR |
2979 | |
2980 | if (sas_device) | |
2981 | sas_device_put(sas_device); | |
c1a6c5ac C |
2982 | if (pcie_device) |
2983 | pcie_device_put(pcie_device); | |
d1cb5e49 | 2984 | |
f92363d1 SR |
2985 | return r; |
2986 | } | |
2987 | ||
2988 | /** | |
8a7e4c24 | 2989 | * scsih_target_reset - eh threads main target reset routine |
f92363d1 SR |
2990 | * @scmd: pointer to scsi command object |
2991 | * | |
2992 | * Returns SUCCESS if command aborted else FAILED | |
2993 | */ | |
8bbb1cf6 | 2994 | static int |
8a7e4c24 | 2995 | scsih_target_reset(struct scsi_cmnd *scmd) |
f92363d1 SR |
2996 | { |
2997 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
2998 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
d1cb5e49 | 2999 | struct _sas_device *sas_device = NULL; |
c1a6c5ac | 3000 | struct _pcie_device *pcie_device = NULL; |
f92363d1 | 3001 | u16 handle; |
c1a6c5ac C |
3002 | u8 tr_method = 0; |
3003 | u8 tr_timeout = 30; | |
f92363d1 SR |
3004 | int r; |
3005 | struct scsi_target *starget = scmd->device->sdev_target; | |
d1cb5e49 | 3006 | struct MPT3SAS_TARGET *target_priv_data = starget->hostdata; |
f92363d1 SR |
3007 | |
3008 | starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n", | |
3009 | scmd); | |
3010 | _scsih_tm_display_info(ioc, scmd); | |
3011 | ||
3012 | sas_device_priv_data = scmd->device->hostdata; | |
9ff549ff MFO |
3013 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target || |
3014 | ioc->remove_host) { | |
f92363d1 SR |
3015 | starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n", |
3016 | scmd); | |
3017 | scmd->result = DID_NO_CONNECT << 16; | |
3018 | scmd->scsi_done(scmd); | |
3019 | r = SUCCESS; | |
3020 | goto out; | |
3021 | } | |
3022 | ||
3023 | /* for hidden raid components obtain the volume_handle */ | |
3024 | handle = 0; | |
3025 | if (sas_device_priv_data->sas_target->flags & | |
3026 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
d1cb5e49 SR |
3027 | sas_device = mpt3sas_get_sdev_from_target(ioc, |
3028 | target_priv_data); | |
f92363d1 SR |
3029 | if (sas_device) |
3030 | handle = sas_device->volume_handle; | |
f92363d1 SR |
3031 | } else |
3032 | handle = sas_device_priv_data->sas_target->handle; | |
3033 | ||
3034 | if (!handle) { | |
3035 | scmd->result = DID_RESET << 16; | |
3036 | r = FAILED; | |
3037 | goto out; | |
3038 | } | |
3039 | ||
c1a6c5ac C |
3040 | pcie_device = mpt3sas_get_pdev_by_handle(ioc, handle); |
3041 | ||
3042 | if (pcie_device && (!ioc->tm_custom_handling)) { | |
3043 | tr_timeout = pcie_device->reset_timeout; | |
3044 | tr_method = MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE; | |
3045 | } else | |
3046 | tr_method = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET; | |
6da999fe | 3047 | r = mpt3sas_scsih_issue_locked_tm(ioc, handle, 0, |
c1a6c5ac C |
3048 | MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 0, |
3049 | tr_timeout, tr_method); | |
74fcfa53 HR |
3050 | /* Check for busy commands after reset */ |
3051 | if (r == SUCCESS && atomic_read(&starget->target_busy)) | |
3052 | r = FAILED; | |
f92363d1 SR |
3053 | out: |
3054 | starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n", | |
3055 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
d1cb5e49 SR |
3056 | |
3057 | if (sas_device) | |
3058 | sas_device_put(sas_device); | |
c1a6c5ac C |
3059 | if (pcie_device) |
3060 | pcie_device_put(pcie_device); | |
f92363d1 SR |
3061 | return r; |
3062 | } | |
3063 | ||
3064 | ||
3065 | /** | |
8a7e4c24 | 3066 | * scsih_host_reset - eh threads main host reset routine |
f92363d1 SR |
3067 | * @scmd: pointer to scsi command object |
3068 | * | |
3069 | * Returns SUCCESS if command aborted else FAILED | |
3070 | */ | |
8bbb1cf6 | 3071 | static int |
8a7e4c24 | 3072 | scsih_host_reset(struct scsi_cmnd *scmd) |
f92363d1 SR |
3073 | { |
3074 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
3075 | int r, retval; | |
3076 | ||
3077 | pr_info(MPT3SAS_FMT "attempting host reset! scmd(%p)\n", | |
3078 | ioc->name, scmd); | |
3079 | scsi_print_command(scmd); | |
3080 | ||
9ff549ff | 3081 | if (ioc->is_driver_loading || ioc->remove_host) { |
ddb588be SR |
3082 | pr_info(MPT3SAS_FMT "Blocking the host reset\n", |
3083 | ioc->name); | |
3084 | r = FAILED; | |
3085 | goto out; | |
3086 | } | |
3087 | ||
98c56ad3 | 3088 | retval = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
f92363d1 | 3089 | r = (retval < 0) ? FAILED : SUCCESS; |
ddb588be | 3090 | out: |
f92363d1 SR |
3091 | pr_info(MPT3SAS_FMT "host reset: %s scmd(%p)\n", |
3092 | ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
3093 | ||
3094 | return r; | |
3095 | } | |
3096 | ||
3097 | /** | |
3098 | * _scsih_fw_event_add - insert and queue up fw_event | |
3099 | * @ioc: per adapter object | |
3100 | * @fw_event: object describing the event | |
3101 | * Context: This function will acquire ioc->fw_event_lock. | |
3102 | * | |
3103 | * This adds the firmware event object into link list, then queues it up to | |
3104 | * be processed from user context. | |
3105 | * | |
3106 | * Return nothing. | |
3107 | */ | |
3108 | static void | |
3109 | _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event) | |
3110 | { | |
3111 | unsigned long flags; | |
3112 | ||
3113 | if (ioc->firmware_event_thread == NULL) | |
3114 | return; | |
3115 | ||
3116 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
146b16c8 | 3117 | fw_event_work_get(fw_event); |
f92363d1 SR |
3118 | INIT_LIST_HEAD(&fw_event->list); |
3119 | list_add_tail(&fw_event->list, &ioc->fw_event_list); | |
3120 | INIT_WORK(&fw_event->work, _firmware_event_work); | |
146b16c8 | 3121 | fw_event_work_get(fw_event); |
f92363d1 SR |
3122 | queue_work(ioc->firmware_event_thread, &fw_event->work); |
3123 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
3124 | } | |
3125 | ||
3126 | /** | |
146b16c8 | 3127 | * _scsih_fw_event_del_from_list - delete fw_event from the list |
f92363d1 SR |
3128 | * @ioc: per adapter object |
3129 | * @fw_event: object describing the event | |
3130 | * Context: This function will acquire ioc->fw_event_lock. | |
3131 | * | |
146b16c8 | 3132 | * If the fw_event is on the fw_event_list, remove it and do a put. |
f92363d1 SR |
3133 | * |
3134 | * Return nothing. | |
3135 | */ | |
3136 | static void | |
146b16c8 | 3137 | _scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work |
f92363d1 SR |
3138 | *fw_event) |
3139 | { | |
3140 | unsigned long flags; | |
3141 | ||
3142 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
146b16c8 SR |
3143 | if (!list_empty(&fw_event->list)) { |
3144 | list_del_init(&fw_event->list); | |
3145 | fw_event_work_put(fw_event); | |
3146 | } | |
f92363d1 SR |
3147 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
3148 | } | |
3149 | ||
3150 | ||
3151 | /** | |
3152 | * mpt3sas_send_trigger_data_event - send event for processing trigger data | |
3153 | * @ioc: per adapter object | |
3154 | * @event_data: trigger event data | |
3155 | * | |
3156 | * Return nothing. | |
3157 | */ | |
3158 | void | |
3159 | mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc, | |
3160 | struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data) | |
3161 | { | |
3162 | struct fw_event_work *fw_event; | |
146b16c8 | 3163 | u16 sz; |
f92363d1 SR |
3164 | |
3165 | if (ioc->is_driver_loading) | |
3166 | return; | |
146b16c8 SR |
3167 | sz = sizeof(*event_data); |
3168 | fw_event = alloc_fw_event_work(sz); | |
f92363d1 SR |
3169 | if (!fw_event) |
3170 | return; | |
f92363d1 SR |
3171 | fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG; |
3172 | fw_event->ioc = ioc; | |
3173 | memcpy(fw_event->event_data, event_data, sizeof(*event_data)); | |
3174 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 | 3175 | fw_event_work_put(fw_event); |
f92363d1 SR |
3176 | } |
3177 | ||
3178 | /** | |
3179 | * _scsih_error_recovery_delete_devices - remove devices not responding | |
3180 | * @ioc: per adapter object | |
3181 | * | |
3182 | * Return nothing. | |
3183 | */ | |
3184 | static void | |
3185 | _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc) | |
3186 | { | |
3187 | struct fw_event_work *fw_event; | |
3188 | ||
3189 | if (ioc->is_driver_loading) | |
3190 | return; | |
146b16c8 | 3191 | fw_event = alloc_fw_event_work(0); |
f92363d1 SR |
3192 | if (!fw_event) |
3193 | return; | |
3194 | fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES; | |
3195 | fw_event->ioc = ioc; | |
3196 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 | 3197 | fw_event_work_put(fw_event); |
f92363d1 SR |
3198 | } |
3199 | ||
3200 | /** | |
3201 | * mpt3sas_port_enable_complete - port enable completed (fake event) | |
3202 | * @ioc: per adapter object | |
3203 | * | |
3204 | * Return nothing. | |
3205 | */ | |
3206 | void | |
3207 | mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc) | |
3208 | { | |
3209 | struct fw_event_work *fw_event; | |
3210 | ||
146b16c8 | 3211 | fw_event = alloc_fw_event_work(0); |
f92363d1 SR |
3212 | if (!fw_event) |
3213 | return; | |
3214 | fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE; | |
3215 | fw_event->ioc = ioc; | |
3216 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 SR |
3217 | fw_event_work_put(fw_event); |
3218 | } | |
3219 | ||
3220 | static struct fw_event_work *dequeue_next_fw_event(struct MPT3SAS_ADAPTER *ioc) | |
3221 | { | |
3222 | unsigned long flags; | |
3223 | struct fw_event_work *fw_event = NULL; | |
3224 | ||
3225 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
3226 | if (!list_empty(&ioc->fw_event_list)) { | |
3227 | fw_event = list_first_entry(&ioc->fw_event_list, | |
3228 | struct fw_event_work, list); | |
3229 | list_del_init(&fw_event->list); | |
3230 | } | |
3231 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
3232 | ||
3233 | return fw_event; | |
f92363d1 SR |
3234 | } |
3235 | ||
3236 | /** | |
3237 | * _scsih_fw_event_cleanup_queue - cleanup event queue | |
3238 | * @ioc: per adapter object | |
3239 | * | |
3240 | * Walk the firmware event queue, either killing timers, or waiting | |
3241 | * for outstanding events to complete | |
3242 | * | |
3243 | * Return nothing. | |
3244 | */ | |
3245 | static void | |
3246 | _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc) | |
3247 | { | |
146b16c8 | 3248 | struct fw_event_work *fw_event; |
f92363d1 SR |
3249 | |
3250 | if (list_empty(&ioc->fw_event_list) || | |
3251 | !ioc->firmware_event_thread || in_interrupt()) | |
3252 | return; | |
3253 | ||
146b16c8 SR |
3254 | while ((fw_event = dequeue_next_fw_event(ioc))) { |
3255 | /* | |
3256 | * Wait on the fw_event to complete. If this returns 1, then | |
3257 | * the event was never executed, and we need a put for the | |
b8ac0cc7 | 3258 | * reference the work had on the fw_event. |
146b16c8 SR |
3259 | * |
3260 | * If it did execute, we wait for it to finish, and the put will | |
3261 | * happen from _firmware_event_work() | |
3262 | */ | |
b8ac0cc7 | 3263 | if (cancel_work_sync(&fw_event->work)) |
146b16c8 SR |
3264 | fw_event_work_put(fw_event); |
3265 | ||
3266 | fw_event_work_put(fw_event); | |
f92363d1 SR |
3267 | } |
3268 | } | |
3269 | ||
df838f92 SR |
3270 | /** |
3271 | * _scsih_internal_device_block - block the sdev device | |
3272 | * @sdev: per device object | |
3273 | * @sas_device_priv_data : per device driver private data | |
3274 | * | |
3275 | * make sure device is blocked without error, if not | |
3276 | * print an error | |
3277 | */ | |
3278 | static void | |
3279 | _scsih_internal_device_block(struct scsi_device *sdev, | |
3280 | struct MPT3SAS_DEVICE *sas_device_priv_data) | |
3281 | { | |
3282 | int r = 0; | |
3283 | ||
3284 | sdev_printk(KERN_INFO, sdev, "device_block, handle(0x%04x)\n", | |
3285 | sas_device_priv_data->sas_target->handle); | |
3286 | sas_device_priv_data->block = 1; | |
3287 | ||
551eb598 | 3288 | r = scsi_internal_device_block_nowait(sdev); |
df838f92 SR |
3289 | if (r == -EINVAL) |
3290 | sdev_printk(KERN_WARNING, sdev, | |
3291 | "device_block failed with return(%d) for handle(0x%04x)\n", | |
b2fe6be7 | 3292 | r, sas_device_priv_data->sas_target->handle); |
df838f92 SR |
3293 | } |
3294 | ||
3295 | /** | |
3296 | * _scsih_internal_device_unblock - unblock the sdev device | |
3297 | * @sdev: per device object | |
3298 | * @sas_device_priv_data : per device driver private data | |
3299 | * make sure device is unblocked without error, if not retry | |
3300 | * by blocking and then unblocking | |
3301 | */ | |
3302 | ||
3303 | static void | |
3304 | _scsih_internal_device_unblock(struct scsi_device *sdev, | |
3305 | struct MPT3SAS_DEVICE *sas_device_priv_data) | |
3306 | { | |
3307 | int r = 0; | |
3308 | ||
3309 | sdev_printk(KERN_WARNING, sdev, "device_unblock and setting to running, " | |
3310 | "handle(0x%04x)\n", sas_device_priv_data->sas_target->handle); | |
3311 | sas_device_priv_data->block = 0; | |
43f7571b | 3312 | r = scsi_internal_device_unblock_nowait(sdev, SDEV_RUNNING); |
df838f92 SR |
3313 | if (r == -EINVAL) { |
3314 | /* The device has been set to SDEV_RUNNING by SD layer during | |
3315 | * device addition but the request queue is still stopped by | |
3316 | * our earlier block call. We need to perform a block again | |
3317 | * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */ | |
3318 | ||
3319 | sdev_printk(KERN_WARNING, sdev, | |
3320 | "device_unblock failed with return(%d) for handle(0x%04x) " | |
3321 | "performing a block followed by an unblock\n", | |
b2fe6be7 | 3322 | r, sas_device_priv_data->sas_target->handle); |
df838f92 | 3323 | sas_device_priv_data->block = 1; |
551eb598 | 3324 | r = scsi_internal_device_block_nowait(sdev); |
df838f92 SR |
3325 | if (r) |
3326 | sdev_printk(KERN_WARNING, sdev, "retried device_block " | |
3327 | "failed with return(%d) for handle(0x%04x)\n", | |
b2fe6be7 | 3328 | r, sas_device_priv_data->sas_target->handle); |
df838f92 SR |
3329 | |
3330 | sas_device_priv_data->block = 0; | |
43f7571b | 3331 | r = scsi_internal_device_unblock_nowait(sdev, SDEV_RUNNING); |
df838f92 SR |
3332 | if (r) |
3333 | sdev_printk(KERN_WARNING, sdev, "retried device_unblock" | |
3334 | " failed with return(%d) for handle(0x%04x)\n", | |
b2fe6be7 | 3335 | r, sas_device_priv_data->sas_target->handle); |
df838f92 SR |
3336 | } |
3337 | } | |
3338 | ||
f92363d1 SR |
3339 | /** |
3340 | * _scsih_ublock_io_all_device - unblock every device | |
3341 | * @ioc: per adapter object | |
3342 | * | |
3343 | * change the device state from block to running | |
3344 | */ | |
3345 | static void | |
3346 | _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc) | |
3347 | { | |
3348 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
3349 | struct scsi_device *sdev; | |
3350 | ||
3351 | shost_for_each_device(sdev, ioc->shost) { | |
3352 | sas_device_priv_data = sdev->hostdata; | |
3353 | if (!sas_device_priv_data) | |
3354 | continue; | |
3355 | if (!sas_device_priv_data->block) | |
3356 | continue; | |
3357 | ||
f92363d1 SR |
3358 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, |
3359 | "device_running, handle(0x%04x)\n", | |
3360 | sas_device_priv_data->sas_target->handle)); | |
df838f92 | 3361 | _scsih_internal_device_unblock(sdev, sas_device_priv_data); |
f92363d1 SR |
3362 | } |
3363 | } | |
3364 | ||
3365 | ||
3366 | /** | |
3367 | * _scsih_ublock_io_device - prepare device to be deleted | |
3368 | * @ioc: per adapter object | |
3369 | * @sas_addr: sas address | |
3370 | * | |
3371 | * unblock then put device in offline state | |
3372 | */ | |
3373 | static void | |
3374 | _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address) | |
3375 | { | |
3376 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
3377 | struct scsi_device *sdev; | |
3378 | ||
3379 | shost_for_each_device(sdev, ioc->shost) { | |
3380 | sas_device_priv_data = sdev->hostdata; | |
3381 | if (!sas_device_priv_data) | |
3382 | continue; | |
3383 | if (sas_device_priv_data->sas_target->sas_address | |
3384 | != sas_address) | |
3385 | continue; | |
df838f92 SR |
3386 | if (sas_device_priv_data->block) |
3387 | _scsih_internal_device_unblock(sdev, | |
3388 | sas_device_priv_data); | |
f92363d1 SR |
3389 | } |
3390 | } | |
3391 | ||
3392 | /** | |
3393 | * _scsih_block_io_all_device - set the device state to SDEV_BLOCK | |
3394 | * @ioc: per adapter object | |
3395 | * @handle: device handle | |
3396 | * | |
6c7abffc | 3397 | * During device pull we need to appropriately set the sdev state. |
f92363d1 SR |
3398 | */ |
3399 | static void | |
3400 | _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc) | |
3401 | { | |
3402 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
3403 | struct scsi_device *sdev; | |
3404 | ||
3405 | shost_for_each_device(sdev, ioc->shost) { | |
3406 | sas_device_priv_data = sdev->hostdata; | |
3407 | if (!sas_device_priv_data) | |
3408 | continue; | |
3409 | if (sas_device_priv_data->block) | |
3410 | continue; | |
30158dc9 SS |
3411 | if (sas_device_priv_data->ignore_delay_remove) { |
3412 | sdev_printk(KERN_INFO, sdev, | |
3413 | "%s skip device_block for SES handle(0x%04x)\n", | |
3414 | __func__, sas_device_priv_data->sas_target->handle); | |
3415 | continue; | |
3416 | } | |
df838f92 | 3417 | _scsih_internal_device_block(sdev, sas_device_priv_data); |
f92363d1 SR |
3418 | } |
3419 | } | |
3420 | ||
3421 | /** | |
3422 | * _scsih_block_io_device - set the device state to SDEV_BLOCK | |
3423 | * @ioc: per adapter object | |
3424 | * @handle: device handle | |
3425 | * | |
6c7abffc | 3426 | * During device pull we need to appropriately set the sdev state. |
f92363d1 SR |
3427 | */ |
3428 | static void | |
3429 | _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
3430 | { | |
3431 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
3432 | struct scsi_device *sdev; | |
e4bc7f5c SR |
3433 | struct _sas_device *sas_device; |
3434 | ||
d1cb5e49 | 3435 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
3436 | |
3437 | shost_for_each_device(sdev, ioc->shost) { | |
3438 | sas_device_priv_data = sdev->hostdata; | |
3439 | if (!sas_device_priv_data) | |
3440 | continue; | |
3441 | if (sas_device_priv_data->sas_target->handle != handle) | |
3442 | continue; | |
3443 | if (sas_device_priv_data->block) | |
3444 | continue; | |
4318c734 | 3445 | if (sas_device && sas_device->pend_sas_rphy_add) |
e4bc7f5c | 3446 | continue; |
30158dc9 SS |
3447 | if (sas_device_priv_data->ignore_delay_remove) { |
3448 | sdev_printk(KERN_INFO, sdev, | |
3449 | "%s skip device_block for SES handle(0x%04x)\n", | |
3450 | __func__, sas_device_priv_data->sas_target->handle); | |
3451 | continue; | |
3452 | } | |
df838f92 | 3453 | _scsih_internal_device_block(sdev, sas_device_priv_data); |
f92363d1 | 3454 | } |
d1cb5e49 | 3455 | |
4318c734 SPS |
3456 | if (sas_device) |
3457 | sas_device_put(sas_device); | |
f92363d1 SR |
3458 | } |
3459 | ||
3460 | /** | |
3461 | * _scsih_block_io_to_children_attached_to_ex | |
3462 | * @ioc: per adapter object | |
3463 | * @sas_expander: the sas_device object | |
3464 | * | |
3465 | * This routine set sdev state to SDEV_BLOCK for all devices | |
3466 | * attached to this expander. This function called when expander is | |
3467 | * pulled. | |
3468 | */ | |
3469 | static void | |
3470 | _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc, | |
3471 | struct _sas_node *sas_expander) | |
3472 | { | |
3473 | struct _sas_port *mpt3sas_port; | |
3474 | struct _sas_device *sas_device; | |
3475 | struct _sas_node *expander_sibling; | |
3476 | unsigned long flags; | |
3477 | ||
3478 | if (!sas_expander) | |
3479 | return; | |
3480 | ||
3481 | list_for_each_entry(mpt3sas_port, | |
3482 | &sas_expander->sas_port_list, port_list) { | |
3483 | if (mpt3sas_port->remote_identify.device_type == | |
3484 | SAS_END_DEVICE) { | |
3485 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 SR |
3486 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
3487 | mpt3sas_port->remote_identify.sas_address); | |
3488 | if (sas_device) { | |
f92363d1 | 3489 | set_bit(sas_device->handle, |
d1cb5e49 SR |
3490 | ioc->blocking_handles); |
3491 | sas_device_put(sas_device); | |
3492 | } | |
f92363d1 SR |
3493 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
3494 | } | |
3495 | } | |
3496 | ||
3497 | list_for_each_entry(mpt3sas_port, | |
3498 | &sas_expander->sas_port_list, port_list) { | |
3499 | ||
3500 | if (mpt3sas_port->remote_identify.device_type == | |
3501 | SAS_EDGE_EXPANDER_DEVICE || | |
3502 | mpt3sas_port->remote_identify.device_type == | |
3503 | SAS_FANOUT_EXPANDER_DEVICE) { | |
3504 | expander_sibling = | |
3505 | mpt3sas_scsih_expander_find_by_sas_address( | |
3506 | ioc, mpt3sas_port->remote_identify.sas_address); | |
3507 | _scsih_block_io_to_children_attached_to_ex(ioc, | |
3508 | expander_sibling); | |
3509 | } | |
3510 | } | |
3511 | } | |
3512 | ||
3513 | /** | |
3514 | * _scsih_block_io_to_children_attached_directly | |
3515 | * @ioc: per adapter object | |
3516 | * @event_data: topology change event data | |
3517 | * | |
3518 | * This routine set sdev state to SDEV_BLOCK for all devices | |
3519 | * direct attached during device pull. | |
3520 | */ | |
3521 | static void | |
3522 | _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc, | |
3523 | Mpi2EventDataSasTopologyChangeList_t *event_data) | |
3524 | { | |
3525 | int i; | |
3526 | u16 handle; | |
3527 | u16 reason_code; | |
f92363d1 SR |
3528 | |
3529 | for (i = 0; i < event_data->NumEntries; i++) { | |
3530 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
3531 | if (!handle) | |
3532 | continue; | |
f92363d1 SR |
3533 | reason_code = event_data->PHY[i].PhyStatus & |
3534 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
3535 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING) | |
3536 | _scsih_block_io_device(ioc, handle); | |
3537 | } | |
3538 | } | |
3539 | ||
4318c734 SPS |
3540 | /** |
3541 | * _scsih_block_io_to_pcie_children_attached_directly | |
3542 | * @ioc: per adapter object | |
3543 | * @event_data: topology change event data | |
3544 | * | |
3545 | * This routine set sdev state to SDEV_BLOCK for all devices | |
3546 | * direct attached during device pull/reconnect. | |
3547 | */ | |
3548 | static void | |
3549 | _scsih_block_io_to_pcie_children_attached_directly(struct MPT3SAS_ADAPTER *ioc, | |
3550 | Mpi26EventDataPCIeTopologyChangeList_t *event_data) | |
3551 | { | |
3552 | int i; | |
3553 | u16 handle; | |
3554 | u16 reason_code; | |
3555 | ||
3556 | for (i = 0; i < event_data->NumEntries; i++) { | |
3557 | handle = | |
3558 | le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle); | |
3559 | if (!handle) | |
3560 | continue; | |
3561 | reason_code = event_data->PortEntry[i].PortStatus; | |
3562 | if (reason_code == | |
3563 | MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING) | |
3564 | _scsih_block_io_device(ioc, handle); | |
3565 | } | |
3566 | } | |
f92363d1 SR |
3567 | /** |
3568 | * _scsih_tm_tr_send - send task management request | |
3569 | * @ioc: per adapter object | |
3570 | * @handle: device handle | |
3571 | * Context: interrupt time. | |
3572 | * | |
3573 | * This code is to initiate the device removal handshake protocol | |
3574 | * with controller firmware. This function will issue target reset | |
3575 | * using high priority request queue. It will send a sas iounit | |
3576 | * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion. | |
3577 | * | |
3578 | * This is designed to send muliple task management request at the same | |
3579 | * time to the fifo. If the fifo is full, we will append the request, | |
3580 | * and process it in a future completion. | |
3581 | */ | |
3582 | static void | |
3583 | _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
3584 | { | |
3585 | Mpi2SCSITaskManagementRequest_t *mpi_request; | |
3586 | u16 smid; | |
d1cb5e49 | 3587 | struct _sas_device *sas_device = NULL; |
6ce2f1d1 | 3588 | struct _pcie_device *pcie_device = NULL; |
f92363d1 SR |
3589 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; |
3590 | u64 sas_address = 0; | |
3591 | unsigned long flags; | |
3592 | struct _tr_list *delayed_tr; | |
3593 | u32 ioc_state; | |
c1a6c5ac | 3594 | u8 tr_method = 0; |
f92363d1 | 3595 | |
6ce2f1d1 | 3596 | if (ioc->pci_error_recovery) { |
f92363d1 SR |
3597 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
3598 | "%s: host in pci error recovery: handle(0x%04x)\n", | |
3599 | __func__, ioc->name, | |
3600 | handle)); | |
3601 | return; | |
3602 | } | |
3603 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); | |
3604 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | |
3605 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3606 | "%s: host is not operational: handle(0x%04x)\n", | |
3607 | __func__, ioc->name, | |
3608 | handle)); | |
3609 | return; | |
3610 | } | |
3611 | ||
3612 | /* if PD, then return */ | |
3613 | if (test_bit(handle, ioc->pd_handles)) | |
3614 | return; | |
3615 | ||
c696f7b8 SPS |
3616 | clear_bit(handle, ioc->pend_os_device_add); |
3617 | ||
f92363d1 | 3618 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 3619 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
3620 | if (sas_device && sas_device->starget && |
3621 | sas_device->starget->hostdata) { | |
3622 | sas_target_priv_data = sas_device->starget->hostdata; | |
3623 | sas_target_priv_data->deleted = 1; | |
3624 | sas_address = sas_device->sas_address; | |
3625 | } | |
3626 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
6ce2f1d1 SPS |
3627 | if (!sas_device) { |
3628 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
3629 | pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle); | |
3630 | if (pcie_device && pcie_device->starget && | |
3631 | pcie_device->starget->hostdata) { | |
3632 | sas_target_priv_data = pcie_device->starget->hostdata; | |
3633 | sas_target_priv_data->deleted = 1; | |
3634 | sas_address = pcie_device->wwid; | |
3635 | } | |
3636 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
c1a6c5ac C |
3637 | if (pcie_device && (!ioc->tm_custom_handling)) |
3638 | tr_method = | |
3639 | MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE; | |
3640 | else | |
3641 | tr_method = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET; | |
6ce2f1d1 | 3642 | } |
f92363d1 SR |
3643 | if (sas_target_priv_data) { |
3644 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3645 | "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n", | |
3646 | ioc->name, handle, | |
3647 | (unsigned long long)sas_address)); | |
6ce2f1d1 SPS |
3648 | if (sas_device) { |
3649 | if (sas_device->enclosure_handle != 0) | |
3650 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3651 | "setting delete flag:enclosure logical " | |
3652 | "id(0x%016llx), slot(%d)\n", ioc->name, | |
3653 | (unsigned long long) | |
3654 | sas_device->enclosure_logical_id, | |
3655 | sas_device->slot)); | |
3656 | if (sas_device->connector_name[0] != '\0') | |
3657 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3658 | "setting delete flag: enclosure " | |
3659 | "level(0x%04x), connector name( %s)\n", | |
3660 | ioc->name, sas_device->enclosure_level, | |
3661 | sas_device->connector_name)); | |
3662 | } else if (pcie_device) { | |
3663 | if (pcie_device->enclosure_handle != 0) | |
3664 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3665 | "setting delete flag: logical " | |
3666 | "id(0x%016llx), slot(%d)\n", ioc->name, | |
3667 | (unsigned long long) | |
3668 | pcie_device->enclosure_logical_id, | |
3669 | pcie_device->slot)); | |
3670 | if (pcie_device->connector_name[0] != '\0') | |
3671 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3672 | "setting delete flag:, enclosure " | |
3673 | "level(0x%04x), " | |
3674 | "connector name( %s)\n", ioc->name, | |
3675 | pcie_device->enclosure_level, | |
3676 | pcie_device->connector_name)); | |
3677 | } | |
f92363d1 SR |
3678 | _scsih_ublock_io_device(ioc, sas_address); |
3679 | sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE; | |
3680 | } | |
3681 | ||
3682 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx); | |
3683 | if (!smid) { | |
3684 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | |
3685 | if (!delayed_tr) | |
d1cb5e49 | 3686 | goto out; |
f92363d1 SR |
3687 | INIT_LIST_HEAD(&delayed_tr->list); |
3688 | delayed_tr->handle = handle; | |
3689 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); | |
3690 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3691 | "DELAYED:tr:handle(0x%04x), (open)\n", | |
3692 | ioc->name, handle)); | |
d1cb5e49 | 3693 | goto out; |
f92363d1 SR |
3694 | } |
3695 | ||
3696 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3697 | "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
3698 | ioc->name, handle, smid, | |
3699 | ioc->tm_tr_cb_idx)); | |
3700 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
3701 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | |
3702 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | |
3703 | mpi_request->DevHandle = cpu_to_le16(handle); | |
3704 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; | |
c1a6c5ac | 3705 | mpi_request->MsgFlags = tr_method; |
c696f7b8 | 3706 | set_bit(handle, ioc->device_remove_in_progress); |
40114bde | 3707 | mpt3sas_base_put_smid_hi_priority(ioc, smid, 0); |
f92363d1 | 3708 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL); |
d1cb5e49 SR |
3709 | |
3710 | out: | |
3711 | if (sas_device) | |
3712 | sas_device_put(sas_device); | |
6ce2f1d1 SPS |
3713 | if (pcie_device) |
3714 | pcie_device_put(pcie_device); | |
f92363d1 SR |
3715 | } |
3716 | ||
3717 | /** | |
3718 | * _scsih_tm_tr_complete - | |
3719 | * @ioc: per adapter object | |
3720 | * @smid: system request message index | |
3721 | * @msix_index: MSIX table index supplied by the OS | |
3722 | * @reply: reply message frame(lower 32bit addr) | |
3723 | * Context: interrupt time. | |
3724 | * | |
3725 | * This is the target reset completion routine. | |
3726 | * This code is part of the code to initiate the device removal | |
3727 | * handshake protocol with controller firmware. | |
3728 | * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE) | |
3729 | * | |
3730 | * Return 1 meaning mf should be freed from _base_interrupt | |
3731 | * 0 means the mf is freed from this function. | |
3732 | */ | |
3733 | static u8 | |
3734 | _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, | |
3735 | u32 reply) | |
3736 | { | |
3737 | u16 handle; | |
3738 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; | |
3739 | Mpi2SCSITaskManagementReply_t *mpi_reply = | |
3740 | mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
3741 | Mpi2SasIoUnitControlRequest_t *mpi_request; | |
3742 | u16 smid_sas_ctrl; | |
3743 | u32 ioc_state; | |
fd0331b3 | 3744 | struct _sc_list *delayed_sc; |
f92363d1 | 3745 | |
79eb96d6 | 3746 | if (ioc->pci_error_recovery) { |
f92363d1 SR |
3747 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
3748 | "%s: host in pci error recovery\n", __func__, | |
3749 | ioc->name)); | |
3750 | return 1; | |
3751 | } | |
3752 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); | |
3753 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | |
3754 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3755 | "%s: host is not operational\n", __func__, ioc->name)); | |
3756 | return 1; | |
3757 | } | |
3758 | if (unlikely(!mpi_reply)) { | |
3759 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", | |
3760 | ioc->name, __FILE__, __LINE__, __func__); | |
3761 | return 1; | |
3762 | } | |
3763 | mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid); | |
3764 | handle = le16_to_cpu(mpi_request_tm->DevHandle); | |
3765 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { | |
3766 | dewtprintk(ioc, pr_err(MPT3SAS_FMT | |
3767 | "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n", | |
3768 | ioc->name, handle, | |
3769 | le16_to_cpu(mpi_reply->DevHandle), smid)); | |
3770 | return 0; | |
3771 | } | |
3772 | ||
3773 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT); | |
3774 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3775 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " | |
3776 | "loginfo(0x%08x), completed(%d)\n", ioc->name, | |
3777 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), | |
3778 | le32_to_cpu(mpi_reply->IOCLogInfo), | |
3779 | le32_to_cpu(mpi_reply->TerminationCount))); | |
3780 | ||
3781 | smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx); | |
3782 | if (!smid_sas_ctrl) { | |
fd0331b3 SS |
3783 | delayed_sc = kzalloc(sizeof(*delayed_sc), GFP_ATOMIC); |
3784 | if (!delayed_sc) | |
3785 | return _scsih_check_for_pending_tm(ioc, smid); | |
3786 | INIT_LIST_HEAD(&delayed_sc->list); | |
cf6bf971 | 3787 | delayed_sc->handle = le16_to_cpu(mpi_request_tm->DevHandle); |
fd0331b3 SS |
3788 | list_add_tail(&delayed_sc->list, &ioc->delayed_sc_list); |
3789 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3790 | "DELAYED:sc:handle(0x%04x), (open)\n", | |
3791 | ioc->name, handle)); | |
3792 | return _scsih_check_for_pending_tm(ioc, smid); | |
f92363d1 SR |
3793 | } |
3794 | ||
3795 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3796 | "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
3797 | ioc->name, handle, smid_sas_ctrl, | |
3798 | ioc->tm_sas_control_cb_idx)); | |
3799 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl); | |
3800 | memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t)); | |
3801 | mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; | |
3802 | mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE; | |
3803 | mpi_request->DevHandle = mpi_request_tm->DevHandle; | |
40114bde | 3804 | mpt3sas_base_put_smid_default(ioc, smid_sas_ctrl); |
f92363d1 SR |
3805 | |
3806 | return _scsih_check_for_pending_tm(ioc, smid); | |
3807 | } | |
3808 | ||
3809 | ||
3810 | /** | |
3811 | * _scsih_sas_control_complete - completion routine | |
3812 | * @ioc: per adapter object | |
3813 | * @smid: system request message index | |
3814 | * @msix_index: MSIX table index supplied by the OS | |
3815 | * @reply: reply message frame(lower 32bit addr) | |
3816 | * Context: interrupt time. | |
3817 | * | |
3818 | * This is the sas iounit control completion routine. | |
3819 | * This code is part of the code to initiate the device removal | |
3820 | * handshake protocol with controller firmware. | |
3821 | * | |
3822 | * Return 1 meaning mf should be freed from _base_interrupt | |
3823 | * 0 means the mf is freed from this function. | |
3824 | */ | |
3825 | static u8 | |
3826 | _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, | |
3827 | u8 msix_index, u32 reply) | |
3828 | { | |
3829 | Mpi2SasIoUnitControlReply_t *mpi_reply = | |
3830 | mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
3831 | ||
3832 | if (likely(mpi_reply)) { | |
3833 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3834 | "sc_complete:handle(0x%04x), (open) " | |
3835 | "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n", | |
3836 | ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid, | |
3837 | le16_to_cpu(mpi_reply->IOCStatus), | |
3838 | le32_to_cpu(mpi_reply->IOCLogInfo))); | |
c696f7b8 SPS |
3839 | if (le16_to_cpu(mpi_reply->IOCStatus) == |
3840 | MPI2_IOCSTATUS_SUCCESS) { | |
3841 | clear_bit(le16_to_cpu(mpi_reply->DevHandle), | |
3842 | ioc->device_remove_in_progress); | |
3843 | } | |
f92363d1 SR |
3844 | } else { |
3845 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", | |
3846 | ioc->name, __FILE__, __LINE__, __func__); | |
3847 | } | |
fd0331b3 | 3848 | return mpt3sas_check_for_pending_internal_cmds(ioc, smid); |
f92363d1 SR |
3849 | } |
3850 | ||
3851 | /** | |
3852 | * _scsih_tm_tr_volume_send - send target reset request for volumes | |
3853 | * @ioc: per adapter object | |
3854 | * @handle: device handle | |
3855 | * Context: interrupt time. | |
3856 | * | |
3857 | * This is designed to send muliple task management request at the same | |
3858 | * time to the fifo. If the fifo is full, we will append the request, | |
3859 | * and process it in a future completion. | |
3860 | */ | |
3861 | static void | |
3862 | _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
3863 | { | |
3864 | Mpi2SCSITaskManagementRequest_t *mpi_request; | |
3865 | u16 smid; | |
3866 | struct _tr_list *delayed_tr; | |
3867 | ||
79eb96d6 | 3868 | if (ioc->pci_error_recovery) { |
f92363d1 SR |
3869 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
3870 | "%s: host reset in progress!\n", | |
3871 | __func__, ioc->name)); | |
3872 | return; | |
3873 | } | |
3874 | ||
3875 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx); | |
3876 | if (!smid) { | |
3877 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | |
3878 | if (!delayed_tr) | |
3879 | return; | |
3880 | INIT_LIST_HEAD(&delayed_tr->list); | |
3881 | delayed_tr->handle = handle; | |
3882 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list); | |
3883 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3884 | "DELAYED:tr:handle(0x%04x), (open)\n", | |
3885 | ioc->name, handle)); | |
3886 | return; | |
3887 | } | |
3888 | ||
3889 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3890 | "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
3891 | ioc->name, handle, smid, | |
3892 | ioc->tm_tr_volume_cb_idx)); | |
3893 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
3894 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | |
3895 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | |
3896 | mpi_request->DevHandle = cpu_to_le16(handle); | |
3897 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; | |
40114bde | 3898 | mpt3sas_base_put_smid_hi_priority(ioc, smid, 0); |
f92363d1 SR |
3899 | } |
3900 | ||
3901 | /** | |
3902 | * _scsih_tm_volume_tr_complete - target reset completion | |
3903 | * @ioc: per adapter object | |
3904 | * @smid: system request message index | |
3905 | * @msix_index: MSIX table index supplied by the OS | |
3906 | * @reply: reply message frame(lower 32bit addr) | |
3907 | * Context: interrupt time. | |
3908 | * | |
3909 | * Return 1 meaning mf should be freed from _base_interrupt | |
3910 | * 0 means the mf is freed from this function. | |
3911 | */ | |
3912 | static u8 | |
3913 | _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, | |
3914 | u8 msix_index, u32 reply) | |
3915 | { | |
3916 | u16 handle; | |
3917 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; | |
3918 | Mpi2SCSITaskManagementReply_t *mpi_reply = | |
3919 | mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
3920 | ||
79eb96d6 | 3921 | if (ioc->shost_recovery || ioc->pci_error_recovery) { |
f92363d1 SR |
3922 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
3923 | "%s: host reset in progress!\n", | |
3924 | __func__, ioc->name)); | |
3925 | return 1; | |
3926 | } | |
3927 | if (unlikely(!mpi_reply)) { | |
3928 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", | |
3929 | ioc->name, __FILE__, __LINE__, __func__); | |
3930 | return 1; | |
3931 | } | |
3932 | ||
3933 | mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid); | |
3934 | handle = le16_to_cpu(mpi_request_tm->DevHandle); | |
3935 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { | |
3936 | dewtprintk(ioc, pr_err(MPT3SAS_FMT | |
3937 | "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n", | |
3938 | ioc->name, handle, | |
3939 | le16_to_cpu(mpi_reply->DevHandle), smid)); | |
3940 | return 0; | |
3941 | } | |
3942 | ||
3943 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3944 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " | |
3945 | "loginfo(0x%08x), completed(%d)\n", ioc->name, | |
3946 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), | |
3947 | le32_to_cpu(mpi_reply->IOCLogInfo), | |
3948 | le32_to_cpu(mpi_reply->TerminationCount))); | |
3949 | ||
3950 | return _scsih_check_for_pending_tm(ioc, smid); | |
3951 | } | |
3952 | ||
fd0331b3 SS |
3953 | /** |
3954 | * _scsih_issue_delayed_event_ack - issue delayed Event ACK messages | |
3955 | * @ioc: per adapter object | |
3956 | * @smid: system request message index | |
3957 | * @event: Event ID | |
3958 | * @event_context: used to track events uniquely | |
3959 | * | |
3960 | * Context - processed in interrupt context. | |
3961 | */ | |
8bbb1cf6 | 3962 | static void |
cf6bf971 C |
3963 | _scsih_issue_delayed_event_ack(struct MPT3SAS_ADAPTER *ioc, u16 smid, U16 event, |
3964 | U32 event_context) | |
fd0331b3 SS |
3965 | { |
3966 | Mpi2EventAckRequest_t *ack_request; | |
3967 | int i = smid - ioc->internal_smid; | |
3968 | unsigned long flags; | |
3969 | ||
3970 | /* Without releasing the smid just update the | |
3971 | * call back index and reuse the same smid for | |
3972 | * processing this delayed request | |
3973 | */ | |
3974 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
3975 | ioc->internal_lookup[i].cb_idx = ioc->base_cb_idx; | |
3976 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
3977 | ||
3978 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3979 | "EVENT ACK: event(0x%04x), smid(%d), cb(%d)\n", | |
3980 | ioc->name, le16_to_cpu(event), smid, | |
3981 | ioc->base_cb_idx)); | |
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; | |
40114bde | 3989 | mpt3sas_base_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 BVA |
4010 | if (ioc->remove_host) { |
4011 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
fd0331b3 SS |
4012 | "%s: host has been removed\n", |
4013 | __func__, ioc->name)); | |
199fd79a BVA |
4014 | return; |
4015 | } else if (ioc->pci_error_recovery) { | |
4016 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
fd0331b3 SS |
4017 | "%s: host in pci error recovery\n", |
4018 | __func__, ioc->name)); | |
4019 | return; | |
4020 | } | |
4021 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); | |
4022 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | |
4023 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4024 | "%s: host is not operational\n", | |
4025 | __func__, ioc->name)); | |
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 | ||
4037 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4038 | "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
cf6bf971 | 4039 | ioc->name, handle, smid, |
fd0331b3 SS |
4040 | ioc->tm_sas_control_cb_idx)); |
4041 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
4042 | memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t)); | |
4043 | mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; | |
4044 | mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE; | |
cf6bf971 | 4045 | mpi_request->DevHandle = cpu_to_le16(handle); |
40114bde | 4046 | mpt3sas_base_put_smid_default(ioc, smid); |
fd0331b3 SS |
4047 | } |
4048 | ||
4049 | /** | |
4050 | * _scsih_check_for_pending_internal_cmds - check for pending internal messages | |
4051 | * @ioc: per adapter object | |
4052 | * @smid: system request message index | |
4053 | * | |
4054 | * Context: Executed in interrupt context | |
4055 | * | |
4056 | * This will check delayed internal messages list, and process the | |
4057 | * next request. | |
4058 | * | |
4059 | * Return 1 meaning mf should be freed from _base_interrupt | |
4060 | * 0 means the mf is freed from this function. | |
4061 | */ | |
4062 | u8 | |
4063 | mpt3sas_check_for_pending_internal_cmds(struct MPT3SAS_ADAPTER *ioc, u16 smid) | |
4064 | { | |
4065 | struct _sc_list *delayed_sc; | |
4066 | struct _event_ack_list *delayed_event_ack; | |
4067 | ||
4068 | if (!list_empty(&ioc->delayed_event_ack_list)) { | |
4069 | delayed_event_ack = list_entry(ioc->delayed_event_ack_list.next, | |
4070 | struct _event_ack_list, list); | |
4071 | _scsih_issue_delayed_event_ack(ioc, smid, | |
4072 | delayed_event_ack->Event, delayed_event_ack->EventContext); | |
4073 | list_del(&delayed_event_ack->list); | |
4074 | kfree(delayed_event_ack); | |
4075 | return 0; | |
4076 | } | |
4077 | ||
4078 | if (!list_empty(&ioc->delayed_sc_list)) { | |
4079 | delayed_sc = list_entry(ioc->delayed_sc_list.next, | |
4080 | struct _sc_list, list); | |
4081 | _scsih_issue_delayed_sas_io_unit_ctrl(ioc, smid, | |
4082 | delayed_sc->handle); | |
4083 | list_del(&delayed_sc->list); | |
4084 | kfree(delayed_sc); | |
4085 | return 0; | |
4086 | } | |
4087 | return 1; | |
4088 | } | |
f92363d1 SR |
4089 | |
4090 | /** | |
4091 | * _scsih_check_for_pending_tm - check for pending task management | |
4092 | * @ioc: per adapter object | |
4093 | * @smid: system request message index | |
4094 | * | |
4095 | * This will check delayed target reset list, and feed the | |
4096 | * next reqeust. | |
4097 | * | |
4098 | * Return 1 meaning mf should be freed from _base_interrupt | |
4099 | * 0 means the mf is freed from this function. | |
4100 | */ | |
4101 | static u8 | |
4102 | _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid) | |
4103 | { | |
4104 | struct _tr_list *delayed_tr; | |
4105 | ||
4106 | if (!list_empty(&ioc->delayed_tr_volume_list)) { | |
4107 | delayed_tr = list_entry(ioc->delayed_tr_volume_list.next, | |
4108 | struct _tr_list, list); | |
4109 | mpt3sas_base_free_smid(ioc, smid); | |
4110 | _scsih_tm_tr_volume_send(ioc, delayed_tr->handle); | |
4111 | list_del(&delayed_tr->list); | |
4112 | kfree(delayed_tr); | |
4113 | return 0; | |
4114 | } | |
4115 | ||
4116 | if (!list_empty(&ioc->delayed_tr_list)) { | |
4117 | delayed_tr = list_entry(ioc->delayed_tr_list.next, | |
4118 | struct _tr_list, list); | |
4119 | mpt3sas_base_free_smid(ioc, smid); | |
4120 | _scsih_tm_tr_send(ioc, delayed_tr->handle); | |
4121 | list_del(&delayed_tr->list); | |
4122 | kfree(delayed_tr); | |
4123 | return 0; | |
4124 | } | |
4125 | ||
4126 | return 1; | |
4127 | } | |
4128 | ||
4129 | /** | |
4130 | * _scsih_check_topo_delete_events - sanity check on topo events | |
4131 | * @ioc: per adapter object | |
4132 | * @event_data: the event data payload | |
4133 | * | |
4134 | * This routine added to better handle cable breaker. | |
4135 | * | |
4136 | * This handles the case where driver receives multiple expander | |
4137 | * add and delete events in a single shot. When there is a delete event | |
4138 | * the routine will void any pending add events waiting in the event queue. | |
4139 | * | |
4140 | * Return nothing. | |
4141 | */ | |
4142 | static void | |
4143 | _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc, | |
4144 | Mpi2EventDataSasTopologyChangeList_t *event_data) | |
4145 | { | |
4146 | struct fw_event_work *fw_event; | |
4147 | Mpi2EventDataSasTopologyChangeList_t *local_event_data; | |
4148 | u16 expander_handle; | |
4149 | struct _sas_node *sas_expander; | |
4150 | unsigned long flags; | |
4151 | int i, reason_code; | |
4152 | u16 handle; | |
4153 | ||
4154 | for (i = 0 ; i < event_data->NumEntries; i++) { | |
4155 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
4156 | if (!handle) | |
4157 | continue; | |
4158 | reason_code = event_data->PHY[i].PhyStatus & | |
4159 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
4160 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING) | |
4161 | _scsih_tm_tr_send(ioc, handle); | |
4162 | } | |
4163 | ||
4164 | expander_handle = le16_to_cpu(event_data->ExpanderDevHandle); | |
4165 | if (expander_handle < ioc->sas_hba.num_phys) { | |
4166 | _scsih_block_io_to_children_attached_directly(ioc, event_data); | |
4167 | return; | |
4168 | } | |
4169 | if (event_data->ExpStatus == | |
4170 | MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) { | |
4171 | /* put expander attached devices into blocking state */ | |
4172 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
4173 | sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc, | |
4174 | expander_handle); | |
4175 | _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander); | |
4176 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
4177 | do { | |
4178 | handle = find_first_bit(ioc->blocking_handles, | |
4179 | ioc->facts.MaxDevHandle); | |
4180 | if (handle < ioc->facts.MaxDevHandle) | |
4181 | _scsih_block_io_device(ioc, handle); | |
4182 | } while (test_and_clear_bit(handle, ioc->blocking_handles)); | |
4183 | } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING) | |
4184 | _scsih_block_io_to_children_attached_directly(ioc, event_data); | |
4185 | ||
4186 | if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) | |
4187 | return; | |
4188 | ||
4189 | /* mark ignore flag for pending events */ | |
4190 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
4191 | list_for_each_entry(fw_event, &ioc->fw_event_list, list) { | |
4192 | if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST || | |
4193 | fw_event->ignore) | |
4194 | continue; | |
35b62362 JL |
4195 | local_event_data = (Mpi2EventDataSasTopologyChangeList_t *) |
4196 | fw_event->event_data; | |
f92363d1 SR |
4197 | if (local_event_data->ExpStatus == |
4198 | MPI2_EVENT_SAS_TOPO_ES_ADDED || | |
4199 | local_event_data->ExpStatus == | |
4200 | MPI2_EVENT_SAS_TOPO_ES_RESPONDING) { | |
4201 | if (le16_to_cpu(local_event_data->ExpanderDevHandle) == | |
4202 | expander_handle) { | |
4203 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4204 | "setting ignoring flag\n", ioc->name)); | |
4205 | fw_event->ignore = 1; | |
4206 | } | |
4207 | } | |
4208 | } | |
4209 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
4210 | } | |
4211 | ||
4318c734 SPS |
4212 | /** |
4213 | * _scsih_check_pcie_topo_remove_events - sanity check on topo | |
4214 | * events | |
4215 | * @ioc: per adapter object | |
4216 | * @event_data: the event data payload | |
4217 | * | |
4218 | * This handles the case where driver receives multiple switch | |
4219 | * or device add and delete events in a single shot. When there | |
4220 | * is a delete event the routine will void any pending add | |
4221 | * events waiting in the event queue. | |
4222 | * | |
4223 | * Return nothing. | |
4224 | */ | |
4225 | static void | |
4226 | _scsih_check_pcie_topo_remove_events(struct MPT3SAS_ADAPTER *ioc, | |
4227 | Mpi26EventDataPCIeTopologyChangeList_t *event_data) | |
4228 | { | |
4229 | struct fw_event_work *fw_event; | |
4230 | Mpi26EventDataPCIeTopologyChangeList_t *local_event_data; | |
4231 | unsigned long flags; | |
4232 | int i, reason_code; | |
4233 | u16 handle, switch_handle; | |
4234 | ||
4235 | for (i = 0; i < event_data->NumEntries; i++) { | |
4236 | handle = | |
4237 | le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle); | |
4238 | if (!handle) | |
4239 | continue; | |
4240 | reason_code = event_data->PortEntry[i].PortStatus; | |
4241 | if (reason_code == MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING) | |
4242 | _scsih_tm_tr_send(ioc, handle); | |
4243 | } | |
4244 | ||
4245 | switch_handle = le16_to_cpu(event_data->SwitchDevHandle); | |
4246 | if (!switch_handle) { | |
4247 | _scsih_block_io_to_pcie_children_attached_directly( | |
4248 | ioc, event_data); | |
4249 | return; | |
4250 | } | |
4251 | /* TODO We are not supporting cascaded PCIe Switch removal yet*/ | |
4252 | if ((event_data->SwitchStatus | |
4253 | == MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING) || | |
4254 | (event_data->SwitchStatus == | |
4255 | MPI26_EVENT_PCIE_TOPO_SS_RESPONDING)) | |
4256 | _scsih_block_io_to_pcie_children_attached_directly( | |
4257 | ioc, event_data); | |
4258 | ||
4259 | if (event_data->SwitchStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) | |
4260 | return; | |
4261 | ||
4262 | /* mark ignore flag for pending events */ | |
4263 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
4264 | list_for_each_entry(fw_event, &ioc->fw_event_list, list) { | |
4265 | if (fw_event->event != MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST || | |
4266 | fw_event->ignore) | |
4267 | continue; | |
4268 | local_event_data = | |
4269 | (Mpi26EventDataPCIeTopologyChangeList_t *) | |
4270 | fw_event->event_data; | |
4271 | if (local_event_data->SwitchStatus == | |
4272 | MPI2_EVENT_SAS_TOPO_ES_ADDED || | |
4273 | local_event_data->SwitchStatus == | |
4274 | MPI2_EVENT_SAS_TOPO_ES_RESPONDING) { | |
4275 | if (le16_to_cpu(local_event_data->SwitchDevHandle) == | |
4276 | switch_handle) { | |
4277 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4278 | "setting ignoring flag for switch event\n", | |
4279 | ioc->name)); | |
4280 | fw_event->ignore = 1; | |
4281 | } | |
4282 | } | |
4283 | } | |
4284 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
4285 | } | |
4286 | ||
f92363d1 SR |
4287 | /** |
4288 | * _scsih_set_volume_delete_flag - setting volume delete flag | |
4289 | * @ioc: per adapter object | |
4290 | * @handle: device handle | |
4291 | * | |
4292 | * This returns nothing. | |
4293 | */ | |
4294 | static void | |
4295 | _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
4296 | { | |
4297 | struct _raid_device *raid_device; | |
4298 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
4299 | unsigned long flags; | |
4300 | ||
4301 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
c84b06a4 | 4302 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
4303 | if (raid_device && raid_device->starget && |
4304 | raid_device->starget->hostdata) { | |
4305 | sas_target_priv_data = | |
4306 | raid_device->starget->hostdata; | |
4307 | sas_target_priv_data->deleted = 1; | |
4308 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4309 | "setting delete flag: handle(0x%04x), " | |
4310 | "wwid(0x%016llx)\n", ioc->name, handle, | |
4311 | (unsigned long long) raid_device->wwid)); | |
4312 | } | |
4313 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
4314 | } | |
4315 | ||
4316 | /** | |
4317 | * _scsih_set_volume_handle_for_tr - set handle for target reset to volume | |
4318 | * @handle: input handle | |
4319 | * @a: handle for volume a | |
4320 | * @b: handle for volume b | |
4321 | * | |
4322 | * IR firmware only supports two raid volumes. The purpose of this | |
4323 | * routine is to set the volume handle in either a or b. When the given | |
4324 | * input handle is non-zero, or when a and b have not been set before. | |
4325 | */ | |
4326 | static void | |
4327 | _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b) | |
4328 | { | |
4329 | if (!handle || handle == *a || handle == *b) | |
4330 | return; | |
4331 | if (!*a) | |
4332 | *a = handle; | |
4333 | else if (!*b) | |
4334 | *b = handle; | |
4335 | } | |
4336 | ||
4337 | /** | |
4338 | * _scsih_check_ir_config_unhide_events - check for UNHIDE events | |
4339 | * @ioc: per adapter object | |
4340 | * @event_data: the event data payload | |
4341 | * Context: interrupt time. | |
4342 | * | |
4343 | * This routine will send target reset to volume, followed by target | |
4344 | * resets to the PDs. This is called when a PD has been removed, or | |
4345 | * volume has been deleted or removed. When the target reset is sent | |
4346 | * to volume, the PD target resets need to be queued to start upon | |
4347 | * completion of the volume target reset. | |
4348 | * | |
4349 | * Return nothing. | |
4350 | */ | |
4351 | static void | |
4352 | _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc, | |
4353 | Mpi2EventDataIrConfigChangeList_t *event_data) | |
4354 | { | |
4355 | Mpi2EventIrConfigElement_t *element; | |
4356 | int i; | |
4357 | u16 handle, volume_handle, a, b; | |
4358 | struct _tr_list *delayed_tr; | |
4359 | ||
4360 | a = 0; | |
4361 | b = 0; | |
4362 | ||
7786ab6a SR |
4363 | if (ioc->is_warpdrive) |
4364 | return; | |
4365 | ||
f92363d1 SR |
4366 | /* Volume Resets for Deleted or Removed */ |
4367 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
4368 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
4369 | if (le32_to_cpu(event_data->Flags) & | |
4370 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) | |
4371 | continue; | |
4372 | if (element->ReasonCode == | |
4373 | MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED || | |
4374 | element->ReasonCode == | |
4375 | MPI2_EVENT_IR_CHANGE_RC_REMOVED) { | |
4376 | volume_handle = le16_to_cpu(element->VolDevHandle); | |
4377 | _scsih_set_volume_delete_flag(ioc, volume_handle); | |
4378 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); | |
4379 | } | |
4380 | } | |
4381 | ||
4382 | /* Volume Resets for UNHIDE events */ | |
4383 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
4384 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
4385 | if (le32_to_cpu(event_data->Flags) & | |
4386 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) | |
4387 | continue; | |
4388 | if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) { | |
4389 | volume_handle = le16_to_cpu(element->VolDevHandle); | |
4390 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); | |
4391 | } | |
4392 | } | |
4393 | ||
4394 | if (a) | |
4395 | _scsih_tm_tr_volume_send(ioc, a); | |
4396 | if (b) | |
4397 | _scsih_tm_tr_volume_send(ioc, b); | |
4398 | ||
4399 | /* PD target resets */ | |
4400 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
4401 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
4402 | if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE) | |
4403 | continue; | |
4404 | handle = le16_to_cpu(element->PhysDiskDevHandle); | |
4405 | volume_handle = le16_to_cpu(element->VolDevHandle); | |
4406 | clear_bit(handle, ioc->pd_handles); | |
4407 | if (!volume_handle) | |
4408 | _scsih_tm_tr_send(ioc, handle); | |
4409 | else if (volume_handle == a || volume_handle == b) { | |
4410 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | |
4411 | BUG_ON(!delayed_tr); | |
4412 | INIT_LIST_HEAD(&delayed_tr->list); | |
4413 | delayed_tr->handle = handle; | |
4414 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); | |
4415 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4416 | "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name, | |
4417 | handle)); | |
4418 | } else | |
4419 | _scsih_tm_tr_send(ioc, handle); | |
4420 | } | |
4421 | } | |
4422 | ||
4423 | ||
4424 | /** | |
4425 | * _scsih_check_volume_delete_events - set delete flag for volumes | |
4426 | * @ioc: per adapter object | |
4427 | * @event_data: the event data payload | |
4428 | * Context: interrupt time. | |
4429 | * | |
4430 | * This will handle the case when the cable connected to entire volume is | |
4431 | * pulled. We will take care of setting the deleted flag so normal IO will | |
4432 | * not be sent. | |
4433 | * | |
4434 | * Return nothing. | |
4435 | */ | |
4436 | static void | |
4437 | _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc, | |
4438 | Mpi2EventDataIrVolume_t *event_data) | |
4439 | { | |
4440 | u32 state; | |
4441 | ||
4442 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) | |
4443 | return; | |
4444 | state = le32_to_cpu(event_data->NewValue); | |
4445 | if (state == MPI2_RAID_VOL_STATE_MISSING || state == | |
4446 | MPI2_RAID_VOL_STATE_FAILED) | |
4447 | _scsih_set_volume_delete_flag(ioc, | |
4448 | le16_to_cpu(event_data->VolDevHandle)); | |
4449 | } | |
4450 | ||
2d8ce8c9 SR |
4451 | /** |
4452 | * _scsih_temp_threshold_events - display temperature threshold exceeded events | |
4453 | * @ioc: per adapter object | |
4454 | * @event_data: the temp threshold event data | |
4455 | * Context: interrupt time. | |
4456 | * | |
4457 | * Return nothing. | |
4458 | */ | |
4459 | static void | |
4460 | _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER *ioc, | |
4461 | Mpi2EventDataTemperature_t *event_data) | |
4462 | { | |
4463 | if (ioc->temp_sensors_count >= event_data->SensorNum) { | |
4464 | pr_err(MPT3SAS_FMT "Temperature Threshold flags %s%s%s%s" | |
4465 | " exceeded for Sensor: %d !!!\n", ioc->name, | |
4466 | ((le16_to_cpu(event_data->Status) & 0x1) == 1) ? "0 " : " ", | |
4467 | ((le16_to_cpu(event_data->Status) & 0x2) == 2) ? "1 " : " ", | |
4468 | ((le16_to_cpu(event_data->Status) & 0x4) == 4) ? "2 " : " ", | |
4469 | ((le16_to_cpu(event_data->Status) & 0x8) == 8) ? "3 " : " ", | |
4470 | event_data->SensorNum); | |
4471 | pr_err(MPT3SAS_FMT "Current Temp In Celsius: %d\n", | |
4472 | ioc->name, event_data->CurrentTemperature); | |
4473 | } | |
4474 | } | |
4475 | ||
ffb58456 | 4476 | static int _scsih_set_satl_pending(struct scsi_cmnd *scmd, bool pending) |
7ff723ad | 4477 | { |
ffb58456 JB |
4478 | struct MPT3SAS_DEVICE *priv = scmd->device->hostdata; |
4479 | ||
4480 | if (scmd->cmnd[0] != ATA_12 && scmd->cmnd[0] != ATA_16) | |
4481 | return 0; | |
4482 | ||
4483 | if (pending) | |
4484 | return test_and_set_bit(0, &priv->ata_command_pending); | |
4485 | ||
4486 | clear_bit(0, &priv->ata_command_pending); | |
4487 | return 0; | |
7ff723ad SP |
4488 | } |
4489 | ||
f92363d1 SR |
4490 | /** |
4491 | * _scsih_flush_running_cmds - completing outstanding commands. | |
4492 | * @ioc: per adapter object | |
4493 | * | |
4494 | * The flushing out of all pending scmd commands following host reset, | |
4495 | * where all IO is dropped to the floor. | |
4496 | * | |
4497 | * Return nothing. | |
4498 | */ | |
4499 | static void | |
4500 | _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc) | |
4501 | { | |
4502 | struct scsi_cmnd *scmd; | |
dbec4c90 | 4503 | struct scsiio_tracker *st; |
f92363d1 | 4504 | u16 smid; |
dbec4c90 | 4505 | int count = 0; |
f92363d1 SR |
4506 | |
4507 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { | |
dbec4c90 | 4508 | scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid); |
f92363d1 SR |
4509 | if (!scmd) |
4510 | continue; | |
4511 | count++; | |
ffb58456 | 4512 | _scsih_set_satl_pending(scmd, false); |
dbec4c90 SPS |
4513 | st = scsi_cmd_priv(scmd); |
4514 | mpt3sas_base_clear_st(ioc, st); | |
f92363d1 | 4515 | scsi_dma_unmap(scmd); |
c666d3be | 4516 | if (ioc->pci_error_recovery || ioc->remove_host) |
f92363d1 SR |
4517 | scmd->result = DID_NO_CONNECT << 16; |
4518 | else | |
4519 | scmd->result = DID_RESET << 16; | |
4520 | scmd->scsi_done(scmd); | |
4521 | } | |
4522 | dtmprintk(ioc, pr_info(MPT3SAS_FMT "completing %d cmds\n", | |
4523 | ioc->name, count)); | |
4524 | } | |
4525 | ||
4526 | /** | |
4527 | * _scsih_setup_eedp - setup MPI request for EEDP transfer | |
4528 | * @ioc: per adapter object | |
4529 | * @scmd: pointer to scsi command object | |
6c7abffc | 4530 | * @mpi_request: pointer to the SCSI_IO request message frame |
f92363d1 SR |
4531 | * |
4532 | * Supporting protection 1 and 3. | |
4533 | * | |
4534 | * Returns nothing | |
4535 | */ | |
4536 | static void | |
4537 | _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, | |
016d5c35 | 4538 | Mpi25SCSIIORequest_t *mpi_request) |
f92363d1 SR |
4539 | { |
4540 | u16 eedp_flags; | |
4541 | unsigned char prot_op = scsi_get_prot_op(scmd); | |
4542 | unsigned char prot_type = scsi_get_prot_type(scmd); | |
4543 | Mpi25SCSIIORequest_t *mpi_request_3v = | |
4544 | (Mpi25SCSIIORequest_t *)mpi_request; | |
4545 | ||
4546 | if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL) | |
4547 | return; | |
4548 | ||
4549 | if (prot_op == SCSI_PROT_READ_STRIP) | |
4550 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP; | |
4551 | else if (prot_op == SCSI_PROT_WRITE_INSERT) | |
4552 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP; | |
4553 | else | |
4554 | return; | |
4555 | ||
4556 | switch (prot_type) { | |
4557 | case SCSI_PROT_DIF_TYPE1: | |
4558 | case SCSI_PROT_DIF_TYPE2: | |
4559 | ||
4560 | /* | |
4561 | * enable ref/guard checking | |
4562 | * auto increment ref tag | |
4563 | */ | |
4564 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG | | |
4565 | MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG | | |
4566 | MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; | |
4567 | mpi_request->CDB.EEDP32.PrimaryReferenceTag = | |
648512cc | 4568 | cpu_to_be32(scsi_prot_ref_tag(scmd)); |
f92363d1 SR |
4569 | break; |
4570 | ||
4571 | case SCSI_PROT_DIF_TYPE3: | |
4572 | ||
4573 | /* | |
4574 | * enable guard checking | |
4575 | */ | |
4576 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; | |
4577 | ||
4578 | break; | |
4579 | } | |
4580 | ||
4581 | mpi_request_3v->EEDPBlockSize = | |
4582 | cpu_to_le16(scmd->device->sector_size); | |
186a18e5 SPS |
4583 | |
4584 | if (ioc->is_gen35_ioc) | |
4585 | eedp_flags |= MPI25_SCSIIO_EEDPFLAGS_APPTAG_DISABLE_MODE; | |
f92363d1 SR |
4586 | mpi_request->EEDPFlags = cpu_to_le16(eedp_flags); |
4587 | } | |
4588 | ||
4589 | /** | |
4590 | * _scsih_eedp_error_handling - return sense code for EEDP errors | |
4591 | * @scmd: pointer to scsi command object | |
4592 | * @ioc_status: ioc status | |
4593 | * | |
4594 | * Returns nothing | |
4595 | */ | |
4596 | static void | |
4597 | _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status) | |
4598 | { | |
4599 | u8 ascq; | |
4600 | ||
4601 | switch (ioc_status) { | |
4602 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | |
4603 | ascq = 0x01; | |
4604 | break; | |
4605 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | |
4606 | ascq = 0x02; | |
4607 | break; | |
4608 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | |
4609 | ascq = 0x03; | |
4610 | break; | |
4611 | default: | |
4612 | ascq = 0x00; | |
4613 | break; | |
4614 | } | |
4615 | scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10, | |
4616 | ascq); | |
4617 | scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) | | |
4618 | SAM_STAT_CHECK_CONDITION; | |
4619 | } | |
4620 | ||
f92363d1 | 4621 | /** |
8a7e4c24 | 4622 | * scsih_qcmd - main scsi request entry point |
f92363d1 SR |
4623 | * @scmd: pointer to scsi command object |
4624 | * @done: function pointer to be invoked on completion | |
4625 | * | |
4626 | * The callback index is set inside `ioc->scsi_io_cb_idx`. | |
4627 | * | |
4628 | * Returns 0 on success. If there's a failure, return either: | |
4629 | * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or | |
4630 | * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full | |
4631 | */ | |
8bbb1cf6 | 4632 | static int |
8a7e4c24 | 4633 | scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd) |
f92363d1 | 4634 | { |
d8bfbd8d | 4635 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
f92363d1 SR |
4636 | struct MPT3SAS_DEVICE *sas_device_priv_data; |
4637 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
7786ab6a | 4638 | struct _raid_device *raid_device; |
307d9075 AM |
4639 | struct request *rq = scmd->request; |
4640 | int class; | |
016d5c35 SPS |
4641 | Mpi25SCSIIORequest_t *mpi_request; |
4642 | struct _pcie_device *pcie_device = NULL; | |
f92363d1 SR |
4643 | u32 mpi_control; |
4644 | u16 smid; | |
4645 | u16 handle; | |
4646 | ||
f92363d1 SR |
4647 | if (ioc->logging_level & MPT_DEBUG_SCSI) |
4648 | scsi_print_command(scmd); | |
f92363d1 | 4649 | |
f92363d1 SR |
4650 | sas_device_priv_data = scmd->device->hostdata; |
4651 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | |
4652 | scmd->result = DID_NO_CONNECT << 16; | |
4653 | scmd->scsi_done(scmd); | |
4654 | return 0; | |
4655 | } | |
4656 | ||
4657 | if (ioc->pci_error_recovery || ioc->remove_host) { | |
4658 | scmd->result = DID_NO_CONNECT << 16; | |
4659 | scmd->scsi_done(scmd); | |
4660 | return 0; | |
4661 | } | |
4662 | ||
4663 | sas_target_priv_data = sas_device_priv_data->sas_target; | |
4664 | ||
4665 | /* invalid device handle */ | |
4666 | handle = sas_target_priv_data->handle; | |
4667 | if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) { | |
4668 | scmd->result = DID_NO_CONNECT << 16; | |
4669 | scmd->scsi_done(scmd); | |
4670 | return 0; | |
4671 | } | |
4672 | ||
4673 | ||
199fd79a BVA |
4674 | if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress) { |
4675 | /* host recovery or link resets sent via IOCTLs */ | |
f92363d1 | 4676 | return SCSI_MLQUEUE_HOST_BUSY; |
199fd79a BVA |
4677 | } else if (sas_target_priv_data->deleted) { |
4678 | /* device has been deleted */ | |
f92363d1 SR |
4679 | scmd->result = DID_NO_CONNECT << 16; |
4680 | scmd->scsi_done(scmd); | |
4681 | return 0; | |
f92363d1 | 4682 | } else if (sas_target_priv_data->tm_busy || |
199fd79a BVA |
4683 | sas_device_priv_data->block) { |
4684 | /* device busy with task management */ | |
f92363d1 | 4685 | return SCSI_MLQUEUE_DEVICE_BUSY; |
199fd79a | 4686 | } |
f92363d1 | 4687 | |
f49d4aed C |
4688 | /* |
4689 | * Bug work around for firmware SATL handling. The loop | |
4690 | * is based on atomic operations and ensures consistency | |
4691 | * since we're lockless at this point | |
4692 | */ | |
4693 | do { | |
4694 | if (test_bit(0, &sas_device_priv_data->ata_command_pending)) { | |
4695 | scmd->result = SAM_STAT_BUSY; | |
4696 | scmd->scsi_done(scmd); | |
4697 | return 0; | |
4698 | } | |
4699 | } while (_scsih_set_satl_pending(scmd, true)); | |
4700 | ||
f92363d1 SR |
4701 | if (scmd->sc_data_direction == DMA_FROM_DEVICE) |
4702 | mpi_control = MPI2_SCSIIO_CONTROL_READ; | |
4703 | else if (scmd->sc_data_direction == DMA_TO_DEVICE) | |
4704 | mpi_control = MPI2_SCSIIO_CONTROL_WRITE; | |
4705 | else | |
4706 | mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER; | |
4707 | ||
4708 | /* set tags */ | |
609aa22f | 4709 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; |
307d9075 AM |
4710 | /* NCQ Prio supported, make sure control indicated high priority */ |
4711 | if (sas_device_priv_data->ncq_prio_enable) { | |
4712 | class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq)); | |
4713 | if (class == IOPRIO_CLASS_RT) | |
4714 | mpi_control |= 1 << MPI2_SCSIIO_CONTROL_CMDPRI_SHIFT; | |
4715 | } | |
7786ab6a SR |
4716 | /* Make sure Device is not raid volume. |
4717 | * We do not expose raid functionality to upper layer for warpdrive. | |
4718 | */ | |
cd5897ed SPS |
4719 | if (((!ioc->is_warpdrive && !scsih_is_raid(&scmd->device->sdev_gendev)) |
4720 | && !scsih_is_nvme(&scmd->device->sdev_gendev)) | |
4721 | && sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32) | |
f92363d1 SR |
4722 | mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON; |
4723 | ||
4724 | smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd); | |
4725 | if (!smid) { | |
4726 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
4727 | ioc->name, __func__); | |
f49d4aed | 4728 | _scsih_set_satl_pending(scmd, false); |
f92363d1 SR |
4729 | goto out; |
4730 | } | |
4731 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
016d5c35 | 4732 | memset(mpi_request, 0, ioc->request_sz); |
f92363d1 SR |
4733 | _scsih_setup_eedp(ioc, scmd, mpi_request); |
4734 | ||
4735 | if (scmd->cmd_len == 32) | |
4736 | mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT; | |
4737 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; | |
4738 | if (sas_device_priv_data->sas_target->flags & | |
4739 | MPT_TARGET_FLAGS_RAID_COMPONENT) | |
4740 | mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH; | |
4741 | else | |
4742 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; | |
4743 | mpi_request->DevHandle = cpu_to_le16(handle); | |
4744 | mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd)); | |
4745 | mpi_request->Control = cpu_to_le32(mpi_control); | |
4746 | mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len); | |
4747 | mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR; | |
4748 | mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE; | |
4749 | mpi_request->SenseBufferLowAddress = | |
4750 | mpt3sas_base_get_sense_buffer_dma(ioc, smid); | |
016d5c35 | 4751 | mpi_request->SGLOffset0 = offsetof(Mpi25SCSIIORequest_t, SGL) / 4; |
f92363d1 SR |
4752 | int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *) |
4753 | mpi_request->LUN); | |
4754 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); | |
4755 | ||
4756 | if (mpi_request->DataLength) { | |
016d5c35 SPS |
4757 | pcie_device = sas_target_priv_data->pcie_dev; |
4758 | if (ioc->build_sg_scmd(ioc, scmd, smid, pcie_device)) { | |
f92363d1 | 4759 | mpt3sas_base_free_smid(ioc, smid); |
f49d4aed | 4760 | _scsih_set_satl_pending(scmd, false); |
f92363d1 SR |
4761 | goto out; |
4762 | } | |
4763 | } else | |
4764 | ioc->build_zero_len_sge(ioc, &mpi_request->SGL); | |
4765 | ||
7786ab6a SR |
4766 | raid_device = sas_target_priv_data->raid_device; |
4767 | if (raid_device && raid_device->direct_io_enabled) | |
cd5897ed | 4768 | mpt3sas_setup_direct_io(ioc, scmd, |
dbec4c90 | 4769 | raid_device, mpi_request); |
7786ab6a | 4770 | |
f92363d1 SR |
4771 | if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) { |
4772 | if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) { | |
4773 | mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len | | |
4774 | MPI25_SCSIIO_IOFLAGS_FAST_PATH); | |
40114bde | 4775 | mpt3sas_base_put_smid_fast_path(ioc, smid, handle); |
f92363d1 | 4776 | } else |
81c16f83 | 4777 | ioc->put_smid_scsi_io(ioc, smid, |
7786ab6a | 4778 | le16_to_cpu(mpi_request->DevHandle)); |
f92363d1 | 4779 | } else |
40114bde | 4780 | mpt3sas_base_put_smid_default(ioc, smid); |
f92363d1 SR |
4781 | return 0; |
4782 | ||
4783 | out: | |
4784 | return SCSI_MLQUEUE_HOST_BUSY; | |
4785 | } | |
f92363d1 SR |
4786 | |
4787 | /** | |
4788 | * _scsih_normalize_sense - normalize descriptor and fixed format sense data | |
4789 | * @sense_buffer: sense data returned by target | |
4790 | * @data: normalized skey/asc/ascq | |
4791 | * | |
4792 | * Return nothing. | |
4793 | */ | |
4794 | static void | |
4795 | _scsih_normalize_sense(char *sense_buffer, struct sense_info *data) | |
4796 | { | |
4797 | if ((sense_buffer[0] & 0x7F) >= 0x72) { | |
4798 | /* descriptor format */ | |
4799 | data->skey = sense_buffer[1] & 0x0F; | |
4800 | data->asc = sense_buffer[2]; | |
4801 | data->ascq = sense_buffer[3]; | |
4802 | } else { | |
4803 | /* fixed format */ | |
4804 | data->skey = sense_buffer[2] & 0x0F; | |
4805 | data->asc = sense_buffer[12]; | |
4806 | data->ascq = sense_buffer[13]; | |
4807 | } | |
4808 | } | |
4809 | ||
f92363d1 SR |
4810 | /** |
4811 | * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request | |
4812 | * @ioc: per adapter object | |
4813 | * @scmd: pointer to scsi command object | |
4814 | * @mpi_reply: reply mf payload returned from firmware | |
4815 | * | |
4816 | * scsi_status - SCSI Status code returned from target device | |
4817 | * scsi_state - state info associated with SCSI_IO determined by ioc | |
4818 | * ioc_status - ioc supplied status info | |
4819 | * | |
4820 | * Return nothing. | |
4821 | */ | |
4822 | static void | |
4823 | _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, | |
4824 | Mpi2SCSIIOReply_t *mpi_reply, u16 smid) | |
4825 | { | |
4826 | u32 response_info; | |
4827 | u8 *response_bytes; | |
4828 | u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & | |
4829 | MPI2_IOCSTATUS_MASK; | |
4830 | u8 scsi_state = mpi_reply->SCSIState; | |
4831 | u8 scsi_status = mpi_reply->SCSIStatus; | |
4832 | char *desc_ioc_state = NULL; | |
4833 | char *desc_scsi_status = NULL; | |
4834 | char *desc_scsi_state = ioc->tmp_string; | |
4835 | u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo); | |
4836 | struct _sas_device *sas_device = NULL; | |
ec051e5a | 4837 | struct _pcie_device *pcie_device = NULL; |
f92363d1 SR |
4838 | struct scsi_target *starget = scmd->device->sdev_target; |
4839 | struct MPT3SAS_TARGET *priv_target = starget->hostdata; | |
4840 | char *device_str = NULL; | |
4841 | ||
4842 | if (!priv_target) | |
4843 | return; | |
7786ab6a SR |
4844 | if (ioc->hide_ir_msg) |
4845 | device_str = "WarpDrive"; | |
4846 | else | |
4847 | device_str = "volume"; | |
f92363d1 SR |
4848 | |
4849 | if (log_info == 0x31170000) | |
4850 | return; | |
4851 | ||
4852 | switch (ioc_status) { | |
4853 | case MPI2_IOCSTATUS_SUCCESS: | |
4854 | desc_ioc_state = "success"; | |
4855 | break; | |
4856 | case MPI2_IOCSTATUS_INVALID_FUNCTION: | |
4857 | desc_ioc_state = "invalid function"; | |
4858 | break; | |
4859 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: | |
4860 | desc_ioc_state = "scsi recovered error"; | |
4861 | break; | |
4862 | case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE: | |
4863 | desc_ioc_state = "scsi invalid dev handle"; | |
4864 | break; | |
4865 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: | |
4866 | desc_ioc_state = "scsi device not there"; | |
4867 | break; | |
4868 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: | |
4869 | desc_ioc_state = "scsi data overrun"; | |
4870 | break; | |
4871 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: | |
4872 | desc_ioc_state = "scsi data underrun"; | |
4873 | break; | |
4874 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: | |
4875 | desc_ioc_state = "scsi io data error"; | |
4876 | break; | |
4877 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: | |
4878 | desc_ioc_state = "scsi protocol error"; | |
4879 | break; | |
4880 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: | |
4881 | desc_ioc_state = "scsi task terminated"; | |
4882 | break; | |
4883 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: | |
4884 | desc_ioc_state = "scsi residual mismatch"; | |
4885 | break; | |
4886 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: | |
4887 | desc_ioc_state = "scsi task mgmt failed"; | |
4888 | break; | |
4889 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: | |
4890 | desc_ioc_state = "scsi ioc terminated"; | |
4891 | break; | |
4892 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: | |
4893 | desc_ioc_state = "scsi ext terminated"; | |
4894 | break; | |
4895 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | |
4896 | desc_ioc_state = "eedp guard error"; | |
4897 | break; | |
4898 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | |
4899 | desc_ioc_state = "eedp ref tag error"; | |
4900 | break; | |
4901 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | |
4902 | desc_ioc_state = "eedp app tag error"; | |
4903 | break; | |
b130b0d5 SS |
4904 | case MPI2_IOCSTATUS_INSUFFICIENT_POWER: |
4905 | desc_ioc_state = "insufficient power"; | |
4906 | break; | |
f92363d1 SR |
4907 | default: |
4908 | desc_ioc_state = "unknown"; | |
4909 | break; | |
4910 | } | |
4911 | ||
4912 | switch (scsi_status) { | |
4913 | case MPI2_SCSI_STATUS_GOOD: | |
4914 | desc_scsi_status = "good"; | |
4915 | break; | |
4916 | case MPI2_SCSI_STATUS_CHECK_CONDITION: | |
4917 | desc_scsi_status = "check condition"; | |
4918 | break; | |
4919 | case MPI2_SCSI_STATUS_CONDITION_MET: | |
4920 | desc_scsi_status = "condition met"; | |
4921 | break; | |
4922 | case MPI2_SCSI_STATUS_BUSY: | |
4923 | desc_scsi_status = "busy"; | |
4924 | break; | |
4925 | case MPI2_SCSI_STATUS_INTERMEDIATE: | |
4926 | desc_scsi_status = "intermediate"; | |
4927 | break; | |
4928 | case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET: | |
4929 | desc_scsi_status = "intermediate condmet"; | |
4930 | break; | |
4931 | case MPI2_SCSI_STATUS_RESERVATION_CONFLICT: | |
4932 | desc_scsi_status = "reservation conflict"; | |
4933 | break; | |
4934 | case MPI2_SCSI_STATUS_COMMAND_TERMINATED: | |
4935 | desc_scsi_status = "command terminated"; | |
4936 | break; | |
4937 | case MPI2_SCSI_STATUS_TASK_SET_FULL: | |
4938 | desc_scsi_status = "task set full"; | |
4939 | break; | |
4940 | case MPI2_SCSI_STATUS_ACA_ACTIVE: | |
4941 | desc_scsi_status = "aca active"; | |
4942 | break; | |
4943 | case MPI2_SCSI_STATUS_TASK_ABORTED: | |
4944 | desc_scsi_status = "task aborted"; | |
4945 | break; | |
4946 | default: | |
4947 | desc_scsi_status = "unknown"; | |
4948 | break; | |
4949 | } | |
4950 | ||
4951 | desc_scsi_state[0] = '\0'; | |
4952 | if (!scsi_state) | |
4953 | desc_scsi_state = " "; | |
4954 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) | |
4955 | strcat(desc_scsi_state, "response info "); | |
4956 | if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | |
4957 | strcat(desc_scsi_state, "state terminated "); | |
4958 | if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS) | |
4959 | strcat(desc_scsi_state, "no status "); | |
4960 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED) | |
4961 | strcat(desc_scsi_state, "autosense failed "); | |
4962 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) | |
4963 | strcat(desc_scsi_state, "autosense valid "); | |
4964 | ||
4965 | scsi_print_command(scmd); | |
4966 | ||
4967 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { | |
4968 | pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name, | |
4969 | device_str, (unsigned long long)priv_target->sas_address); | |
ec051e5a SPS |
4970 | } else if (priv_target->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) { |
4971 | pcie_device = mpt3sas_get_pdev_from_target(ioc, priv_target); | |
4972 | if (pcie_device) { | |
4973 | pr_info(MPT3SAS_FMT "\twwid(0x%016llx), port(%d)\n", | |
4974 | ioc->name, | |
4975 | (unsigned long long)pcie_device->wwid, | |
4976 | pcie_device->port_num); | |
4977 | if (pcie_device->enclosure_handle != 0) | |
4978 | pr_info(MPT3SAS_FMT | |
4979 | "\tenclosure logical id(0x%016llx), " | |
4980 | "slot(%d)\n", ioc->name, | |
4981 | (unsigned long long) | |
4982 | pcie_device->enclosure_logical_id, | |
4983 | pcie_device->slot); | |
4984 | if (pcie_device->connector_name[0]) | |
4985 | pr_info(MPT3SAS_FMT | |
4986 | "\tenclosure level(0x%04x)," | |
4987 | "connector name( %s)\n", | |
4988 | ioc->name, pcie_device->enclosure_level, | |
4989 | pcie_device->connector_name); | |
4990 | pcie_device_put(pcie_device); | |
4991 | } | |
f92363d1 | 4992 | } else { |
d1cb5e49 | 4993 | sas_device = mpt3sas_get_sdev_from_target(ioc, priv_target); |
f92363d1 SR |
4994 | if (sas_device) { |
4995 | pr_warn(MPT3SAS_FMT | |
4996 | "\tsas_address(0x%016llx), phy(%d)\n", | |
4997 | ioc->name, (unsigned long long) | |
4998 | sas_device->sas_address, sas_device->phy); | |
75888956 SR |
4999 | |
5000 | _scsih_display_enclosure_chassis_info(ioc, sas_device, | |
5001 | NULL, NULL); | |
d1cb5e49 SR |
5002 | |
5003 | sas_device_put(sas_device); | |
f92363d1 | 5004 | } |
f92363d1 SR |
5005 | } |
5006 | ||
5007 | pr_warn(MPT3SAS_FMT | |
5008 | "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n", | |
5009 | ioc->name, le16_to_cpu(mpi_reply->DevHandle), | |
5010 | desc_ioc_state, ioc_status, smid); | |
5011 | pr_warn(MPT3SAS_FMT | |
5012 | "\trequest_len(%d), underflow(%d), resid(%d)\n", | |
5013 | ioc->name, scsi_bufflen(scmd), scmd->underflow, | |
5014 | scsi_get_resid(scmd)); | |
5015 | pr_warn(MPT3SAS_FMT | |
5016 | "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n", | |
5017 | ioc->name, le16_to_cpu(mpi_reply->TaskTag), | |
5018 | le32_to_cpu(mpi_reply->TransferCount), scmd->result); | |
5019 | pr_warn(MPT3SAS_FMT | |
5020 | "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n", | |
5021 | ioc->name, desc_scsi_status, | |
5022 | scsi_status, desc_scsi_state, scsi_state); | |
5023 | ||
5024 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { | |
5025 | struct sense_info data; | |
5026 | _scsih_normalize_sense(scmd->sense_buffer, &data); | |
5027 | pr_warn(MPT3SAS_FMT | |
ec051e5a SPS |
5028 | "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n", |
5029 | ioc->name, data.skey, | |
5030 | data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount)); | |
f92363d1 | 5031 | } |
f92363d1 SR |
5032 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) { |
5033 | response_info = le32_to_cpu(mpi_reply->ResponseInfo); | |
5034 | response_bytes = (u8 *)&response_info; | |
5035 | _scsih_response_code(ioc, response_bytes[0]); | |
5036 | } | |
5037 | } | |
f92363d1 SR |
5038 | |
5039 | /** | |
0f624c39 | 5040 | * _scsih_turn_on_pfa_led - illuminate PFA LED |
f92363d1 SR |
5041 | * @ioc: per adapter object |
5042 | * @handle: device handle | |
5043 | * Context: process | |
5044 | * | |
5045 | * Return nothing. | |
5046 | */ | |
5047 | static void | |
0f624c39 | 5048 | _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
f92363d1 SR |
5049 | { |
5050 | Mpi2SepReply_t mpi_reply; | |
5051 | Mpi2SepRequest_t mpi_request; | |
0f624c39 SR |
5052 | struct _sas_device *sas_device; |
5053 | ||
d1cb5e49 | 5054 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
0f624c39 SR |
5055 | if (!sas_device) |
5056 | return; | |
f92363d1 SR |
5057 | |
5058 | memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t)); | |
5059 | mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; | |
5060 | mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; | |
5061 | mpi_request.SlotStatus = | |
5062 | cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT); | |
5063 | mpi_request.DevHandle = cpu_to_le16(handle); | |
5064 | mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS; | |
5065 | if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply, | |
5066 | &mpi_request)) != 0) { | |
5067 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name, | |
5068 | __FILE__, __LINE__, __func__); | |
d1cb5e49 | 5069 | goto out; |
f92363d1 | 5070 | } |
0f624c39 | 5071 | sas_device->pfa_led_on = 1; |
f92363d1 SR |
5072 | |
5073 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) { | |
5074 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
5075 | "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n", | |
5076 | ioc->name, le16_to_cpu(mpi_reply.IOCStatus), | |
5077 | le32_to_cpu(mpi_reply.IOCLogInfo))); | |
d1cb5e49 | 5078 | goto out; |
f92363d1 | 5079 | } |
d1cb5e49 SR |
5080 | out: |
5081 | sas_device_put(sas_device); | |
f92363d1 | 5082 | } |
d1cb5e49 | 5083 | |
0f624c39 SR |
5084 | /** |
5085 | * _scsih_turn_off_pfa_led - turn off Fault LED | |
5086 | * @ioc: per adapter object | |
5087 | * @sas_device: sas device whose PFA LED has to turned off | |
5088 | * Context: process | |
5089 | * | |
5090 | * Return nothing. | |
5091 | */ | |
5092 | static void | |
5093 | _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc, | |
5094 | struct _sas_device *sas_device) | |
5095 | { | |
5096 | Mpi2SepReply_t mpi_reply; | |
5097 | Mpi2SepRequest_t mpi_request; | |
f92363d1 | 5098 | |
0f624c39 SR |
5099 | memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t)); |
5100 | mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; | |
5101 | mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; | |
5102 | mpi_request.SlotStatus = 0; | |
5103 | mpi_request.Slot = cpu_to_le16(sas_device->slot); | |
5104 | mpi_request.DevHandle = 0; | |
5105 | mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle); | |
5106 | mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS; | |
5107 | if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply, | |
5108 | &mpi_request)) != 0) { | |
5109 | printk(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name, | |
5110 | __FILE__, __LINE__, __func__); | |
5111 | return; | |
5112 | } | |
5113 | ||
5114 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) { | |
5115 | dewtprintk(ioc, printk(MPT3SAS_FMT | |
5116 | "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n", | |
5117 | ioc->name, le16_to_cpu(mpi_reply.IOCStatus), | |
5118 | le32_to_cpu(mpi_reply.IOCLogInfo))); | |
5119 | return; | |
5120 | } | |
5121 | } | |
d1cb5e49 | 5122 | |
f92363d1 | 5123 | /** |
0f624c39 | 5124 | * _scsih_send_event_to_turn_on_pfa_led - fire delayed event |
f92363d1 SR |
5125 | * @ioc: per adapter object |
5126 | * @handle: device handle | |
5127 | * Context: interrupt. | |
5128 | * | |
5129 | * Return nothing. | |
5130 | */ | |
5131 | static void | |
0f624c39 | 5132 | _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
f92363d1 SR |
5133 | { |
5134 | struct fw_event_work *fw_event; | |
5135 | ||
146b16c8 | 5136 | fw_event = alloc_fw_event_work(0); |
f92363d1 SR |
5137 | if (!fw_event) |
5138 | return; | |
0f624c39 | 5139 | fw_event->event = MPT3SAS_TURN_ON_PFA_LED; |
f92363d1 SR |
5140 | fw_event->device_handle = handle; |
5141 | fw_event->ioc = ioc; | |
5142 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 | 5143 | fw_event_work_put(fw_event); |
f92363d1 SR |
5144 | } |
5145 | ||
5146 | /** | |
5147 | * _scsih_smart_predicted_fault - process smart errors | |
5148 | * @ioc: per adapter object | |
5149 | * @handle: device handle | |
5150 | * Context: interrupt. | |
5151 | * | |
5152 | * Return nothing. | |
5153 | */ | |
5154 | static void | |
5155 | _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
5156 | { | |
5157 | struct scsi_target *starget; | |
5158 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
5159 | Mpi2EventNotificationReply_t *event_reply; | |
5160 | Mpi2EventDataSasDeviceStatusChange_t *event_data; | |
5161 | struct _sas_device *sas_device; | |
5162 | ssize_t sz; | |
5163 | unsigned long flags; | |
5164 | ||
5165 | /* only handle non-raid devices */ | |
5166 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 SR |
5167 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
5168 | if (!sas_device) | |
5169 | goto out_unlock; | |
5170 | ||
f92363d1 SR |
5171 | starget = sas_device->starget; |
5172 | sas_target_priv_data = starget->hostdata; | |
5173 | ||
5174 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) || | |
d1cb5e49 SR |
5175 | ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) |
5176 | goto out_unlock; | |
5177 | ||
75888956 SR |
5178 | _scsih_display_enclosure_chassis_info(NULL, sas_device, NULL, starget); |
5179 | ||
f92363d1 SR |
5180 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
5181 | ||
5182 | if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) | |
0f624c39 | 5183 | _scsih_send_event_to_turn_on_pfa_led(ioc, handle); |
f92363d1 SR |
5184 | |
5185 | /* insert into event log */ | |
5186 | sz = offsetof(Mpi2EventNotificationReply_t, EventData) + | |
5187 | sizeof(Mpi2EventDataSasDeviceStatusChange_t); | |
5188 | event_reply = kzalloc(sz, GFP_KERNEL); | |
5189 | if (!event_reply) { | |
5190 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5191 | ioc->name, __FILE__, __LINE__, __func__); | |
d1cb5e49 | 5192 | goto out; |
f92363d1 SR |
5193 | } |
5194 | ||
5195 | event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION; | |
5196 | event_reply->Event = | |
5197 | cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE); | |
5198 | event_reply->MsgLength = sz/4; | |
5199 | event_reply->EventDataLength = | |
5200 | cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4); | |
5201 | event_data = (Mpi2EventDataSasDeviceStatusChange_t *) | |
5202 | event_reply->EventData; | |
5203 | event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA; | |
5204 | event_data->ASC = 0x5D; | |
5205 | event_data->DevHandle = cpu_to_le16(handle); | |
5206 | event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address); | |
5207 | mpt3sas_ctl_add_to_event_log(ioc, event_reply); | |
5208 | kfree(event_reply); | |
d1cb5e49 SR |
5209 | out: |
5210 | if (sas_device) | |
5211 | sas_device_put(sas_device); | |
5212 | return; | |
5213 | ||
5214 | out_unlock: | |
5215 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
5216 | goto out; | |
f92363d1 SR |
5217 | } |
5218 | ||
5219 | /** | |
5220 | * _scsih_io_done - scsi request callback | |
5221 | * @ioc: per adapter object | |
5222 | * @smid: system request message index | |
5223 | * @msix_index: MSIX table index supplied by the OS | |
5224 | * @reply: reply message frame(lower 32bit addr) | |
5225 | * | |
5226 | * Callback handler when using _scsih_qcmd. | |
5227 | * | |
5228 | * Return 1 meaning mf should be freed from _base_interrupt | |
5229 | * 0 means the mf is freed from this function. | |
5230 | */ | |
5231 | static u8 | |
5232 | _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | |
5233 | { | |
016d5c35 | 5234 | Mpi25SCSIIORequest_t *mpi_request; |
f92363d1 SR |
5235 | Mpi2SCSIIOReply_t *mpi_reply; |
5236 | struct scsi_cmnd *scmd; | |
dbec4c90 | 5237 | struct scsiio_tracker *st; |
f92363d1 SR |
5238 | u16 ioc_status; |
5239 | u32 xfer_cnt; | |
5240 | u8 scsi_state; | |
5241 | u8 scsi_status; | |
5242 | u32 log_info; | |
5243 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
5244 | u32 response_code = 0; | |
5245 | ||
5246 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
459325c4 | 5247 | |
dbec4c90 | 5248 | scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid); |
f92363d1 SR |
5249 | if (scmd == NULL) |
5250 | return 1; | |
5251 | ||
ffb58456 | 5252 | _scsih_set_satl_pending(scmd, false); |
18f6084a | 5253 | |
f92363d1 SR |
5254 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
5255 | ||
5256 | if (mpi_reply == NULL) { | |
5257 | scmd->result = DID_OK << 16; | |
5258 | goto out; | |
5259 | } | |
5260 | ||
5261 | sas_device_priv_data = scmd->device->hostdata; | |
5262 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target || | |
5263 | sas_device_priv_data->sas_target->deleted) { | |
5264 | scmd->result = DID_NO_CONNECT << 16; | |
5265 | goto out; | |
5266 | } | |
5267 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); | |
5268 | ||
7786ab6a SR |
5269 | /* |
5270 | * WARPDRIVE: If direct_io is set then it is directIO, | |
5271 | * the failed direct I/O should be redirected to volume | |
5272 | */ | |
dbec4c90 SPS |
5273 | st = scsi_cmd_priv(scmd); |
5274 | if (st->direct_io && | |
7786ab6a SR |
5275 | ((ioc_status & MPI2_IOCSTATUS_MASK) |
5276 | != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) { | |
dbec4c90 | 5277 | st->direct_io = 0; |
7786ab6a SR |
5278 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); |
5279 | mpi_request->DevHandle = | |
5280 | cpu_to_le16(sas_device_priv_data->sas_target->handle); | |
81c16f83 | 5281 | ioc->put_smid_scsi_io(ioc, smid, |
7786ab6a SR |
5282 | sas_device_priv_data->sas_target->handle); |
5283 | return 0; | |
5284 | } | |
f92363d1 SR |
5285 | /* turning off TLR */ |
5286 | scsi_state = mpi_reply->SCSIState; | |
5287 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) | |
5288 | response_code = | |
5289 | le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF; | |
5290 | if (!sas_device_priv_data->tlr_snoop_check) { | |
5291 | sas_device_priv_data->tlr_snoop_check++; | |
cd5897ed | 5292 | if ((!ioc->is_warpdrive && |
7786ab6a | 5293 | !scsih_is_raid(&scmd->device->sdev_gendev) && |
cd5897ed SPS |
5294 | !scsih_is_nvme(&scmd->device->sdev_gendev)) |
5295 | && sas_is_tlr_enabled(scmd->device) && | |
c84b06a4 SR |
5296 | response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) { |
5297 | sas_disable_tlr(scmd->device); | |
5298 | sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n"); | |
5299 | } | |
f92363d1 SR |
5300 | } |
5301 | ||
5302 | xfer_cnt = le32_to_cpu(mpi_reply->TransferCount); | |
5303 | scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt); | |
5304 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) | |
5305 | log_info = le32_to_cpu(mpi_reply->IOCLogInfo); | |
5306 | else | |
5307 | log_info = 0; | |
5308 | ioc_status &= MPI2_IOCSTATUS_MASK; | |
5309 | scsi_status = mpi_reply->SCSIStatus; | |
5310 | ||
5311 | if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 && | |
5312 | (scsi_status == MPI2_SCSI_STATUS_BUSY || | |
5313 | scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT || | |
5314 | scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) { | |
5315 | ioc_status = MPI2_IOCSTATUS_SUCCESS; | |
5316 | } | |
5317 | ||
5318 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { | |
5319 | struct sense_info data; | |
5320 | const void *sense_data = mpt3sas_base_get_sense_buffer(ioc, | |
5321 | smid); | |
5322 | u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE, | |
5323 | le32_to_cpu(mpi_reply->SenseCount)); | |
5324 | memcpy(scmd->sense_buffer, sense_data, sz); | |
5325 | _scsih_normalize_sense(scmd->sense_buffer, &data); | |
5326 | /* failure prediction threshold exceeded */ | |
5327 | if (data.asc == 0x5D) | |
5328 | _scsih_smart_predicted_fault(ioc, | |
5329 | le16_to_cpu(mpi_reply->DevHandle)); | |
5330 | mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq); | |
f92363d1 | 5331 | |
0d667f72 | 5332 | if ((ioc->logging_level & MPT_DEBUG_REPLY) && |
e6d45e3e SR |
5333 | ((scmd->sense_buffer[2] == UNIT_ATTENTION) || |
5334 | (scmd->sense_buffer[2] == MEDIUM_ERROR) || | |
5335 | (scmd->sense_buffer[2] == HARDWARE_ERROR))) | |
5336 | _scsih_scsi_ioc_info(ioc, scmd, mpi_reply, smid); | |
e6d45e3e | 5337 | } |
f92363d1 SR |
5338 | switch (ioc_status) { |
5339 | case MPI2_IOCSTATUS_BUSY: | |
5340 | case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES: | |
5341 | scmd->result = SAM_STAT_BUSY; | |
5342 | break; | |
5343 | ||
5344 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: | |
5345 | scmd->result = DID_NO_CONNECT << 16; | |
5346 | break; | |
5347 | ||
5348 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: | |
5349 | if (sas_device_priv_data->block) { | |
5350 | scmd->result = DID_TRANSPORT_DISRUPTED << 16; | |
5351 | goto out; | |
5352 | } | |
5353 | if (log_info == 0x31110630) { | |
5354 | if (scmd->retries > 2) { | |
5355 | scmd->result = DID_NO_CONNECT << 16; | |
5356 | scsi_device_set_state(scmd->device, | |
5357 | SDEV_OFFLINE); | |
5358 | } else { | |
5359 | scmd->result = DID_SOFT_ERROR << 16; | |
5360 | scmd->device->expecting_cc_ua = 1; | |
5361 | } | |
5362 | break; | |
3898f08e SR |
5363 | } else if (log_info == VIRTUAL_IO_FAILED_RETRY) { |
5364 | scmd->result = DID_RESET << 16; | |
5365 | break; | |
2ce9a364 SR |
5366 | } else if ((scmd->device->channel == RAID_CHANNEL) && |
5367 | (scsi_state == (MPI2_SCSI_STATE_TERMINATED | | |
5368 | MPI2_SCSI_STATE_NO_SCSI_STATUS))) { | |
5369 | scmd->result = DID_RESET << 16; | |
5370 | break; | |
f92363d1 SR |
5371 | } |
5372 | scmd->result = DID_SOFT_ERROR << 16; | |
5373 | break; | |
5374 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: | |
5375 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: | |
5376 | scmd->result = DID_RESET << 16; | |
5377 | break; | |
5378 | ||
5379 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: | |
5380 | if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt)) | |
5381 | scmd->result = DID_SOFT_ERROR << 16; | |
5382 | else | |
5383 | scmd->result = (DID_OK << 16) | scsi_status; | |
5384 | break; | |
5385 | ||
5386 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: | |
5387 | scmd->result = (DID_OK << 16) | scsi_status; | |
5388 | ||
5389 | if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)) | |
5390 | break; | |
5391 | ||
5392 | if (xfer_cnt < scmd->underflow) { | |
5393 | if (scsi_status == SAM_STAT_BUSY) | |
5394 | scmd->result = SAM_STAT_BUSY; | |
5395 | else | |
5396 | scmd->result = DID_SOFT_ERROR << 16; | |
5397 | } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | | |
5398 | MPI2_SCSI_STATE_NO_SCSI_STATUS)) | |
5399 | scmd->result = DID_SOFT_ERROR << 16; | |
5400 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | |
5401 | scmd->result = DID_RESET << 16; | |
5402 | else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) { | |
5403 | mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID; | |
5404 | mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION; | |
5405 | scmd->result = (DRIVER_SENSE << 24) | | |
5406 | SAM_STAT_CHECK_CONDITION; | |
5407 | scmd->sense_buffer[0] = 0x70; | |
5408 | scmd->sense_buffer[2] = ILLEGAL_REQUEST; | |
5409 | scmd->sense_buffer[12] = 0x20; | |
5410 | scmd->sense_buffer[13] = 0; | |
5411 | } | |
5412 | break; | |
5413 | ||
5414 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: | |
5415 | scsi_set_resid(scmd, 0); | |
5416 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: | |
5417 | case MPI2_IOCSTATUS_SUCCESS: | |
5418 | scmd->result = (DID_OK << 16) | scsi_status; | |
5419 | if (response_code == | |
5420 | MPI2_SCSITASKMGMT_RSP_INVALID_FRAME || | |
5421 | (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | | |
5422 | MPI2_SCSI_STATE_NO_SCSI_STATUS))) | |
5423 | scmd->result = DID_SOFT_ERROR << 16; | |
5424 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | |
5425 | scmd->result = DID_RESET << 16; | |
5426 | break; | |
5427 | ||
5428 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | |
5429 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | |
5430 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | |
5431 | _scsih_eedp_error_handling(scmd, ioc_status); | |
5432 | break; | |
5433 | ||
5434 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: | |
5435 | case MPI2_IOCSTATUS_INVALID_FUNCTION: | |
5436 | case MPI2_IOCSTATUS_INVALID_SGL: | |
5437 | case MPI2_IOCSTATUS_INTERNAL_ERROR: | |
5438 | case MPI2_IOCSTATUS_INVALID_FIELD: | |
5439 | case MPI2_IOCSTATUS_INVALID_STATE: | |
5440 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: | |
5441 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: | |
b130b0d5 | 5442 | case MPI2_IOCSTATUS_INSUFFICIENT_POWER: |
f92363d1 SR |
5443 | default: |
5444 | scmd->result = DID_SOFT_ERROR << 16; | |
5445 | break; | |
5446 | ||
5447 | } | |
5448 | ||
f92363d1 SR |
5449 | if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY)) |
5450 | _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid); | |
f92363d1 SR |
5451 | |
5452 | out: | |
5453 | ||
5454 | scsi_dma_unmap(scmd); | |
dbec4c90 | 5455 | mpt3sas_base_free_smid(ioc, smid); |
f92363d1 | 5456 | scmd->scsi_done(scmd); |
dbec4c90 | 5457 | return 0; |
f92363d1 SR |
5458 | } |
5459 | ||
5460 | /** | |
5461 | * _scsih_sas_host_refresh - refreshing sas host object contents | |
5462 | * @ioc: per adapter object | |
5463 | * Context: user | |
5464 | * | |
5465 | * During port enable, fw will send topology events for every device. Its | |
5466 | * possible that the handles may change from the previous setting, so this | |
5467 | * code keeping handles updating if changed. | |
5468 | * | |
5469 | * Return nothing. | |
5470 | */ | |
5471 | static void | |
5472 | _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc) | |
5473 | { | |
5474 | u16 sz; | |
5475 | u16 ioc_status; | |
5476 | int i; | |
5477 | Mpi2ConfigReply_t mpi_reply; | |
5478 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; | |
5479 | u16 attached_handle; | |
5480 | u8 link_rate; | |
5481 | ||
5482 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
5483 | "updating handles for sas_host(0x%016llx)\n", | |
5484 | ioc->name, (unsigned long long)ioc->sas_hba.sas_address)); | |
5485 | ||
5486 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys | |
5487 | * sizeof(Mpi2SasIOUnit0PhyData_t)); | |
5488 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); | |
5489 | if (!sas_iounit_pg0) { | |
5490 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5491 | ioc->name, __FILE__, __LINE__, __func__); | |
5492 | return; | |
5493 | } | |
5494 | ||
5495 | if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, | |
5496 | sas_iounit_pg0, sz)) != 0) | |
5497 | goto out; | |
5498 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
5499 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | |
5500 | goto out; | |
5501 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { | |
5502 | link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4; | |
5503 | if (i == 0) | |
5504 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> | |
5505 | PhyData[0].ControllerDevHandle); | |
5506 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; | |
5507 | attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i]. | |
5508 | AttachedDevHandle); | |
5509 | if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) | |
5510 | link_rate = MPI2_SAS_NEG_LINK_RATE_1_5; | |
5511 | mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address, | |
5512 | attached_handle, i, link_rate); | |
5513 | } | |
5514 | out: | |
5515 | kfree(sas_iounit_pg0); | |
5516 | } | |
5517 | ||
5518 | /** | |
5519 | * _scsih_sas_host_add - create sas host object | |
5520 | * @ioc: per adapter object | |
5521 | * | |
5522 | * Creating host side data object, stored in ioc->sas_hba | |
5523 | * | |
5524 | * Return nothing. | |
5525 | */ | |
5526 | static void | |
5527 | _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc) | |
5528 | { | |
5529 | int i; | |
5530 | Mpi2ConfigReply_t mpi_reply; | |
5531 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; | |
5532 | Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; | |
5533 | Mpi2SasPhyPage0_t phy_pg0; | |
5534 | Mpi2SasDevicePage0_t sas_device_pg0; | |
5535 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
5536 | u16 ioc_status; | |
5537 | u16 sz; | |
5538 | u8 device_missing_delay; | |
87aa95d4 | 5539 | u8 num_phys; |
f92363d1 | 5540 | |
87aa95d4 JL |
5541 | mpt3sas_config_get_number_hba_phys(ioc, &num_phys); |
5542 | if (!num_phys) { | |
f92363d1 SR |
5543 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
5544 | ioc->name, __FILE__, __LINE__, __func__); | |
5545 | return; | |
5546 | } | |
87aa95d4 JL |
5547 | ioc->sas_hba.phy = kcalloc(num_phys, |
5548 | sizeof(struct _sas_phy), GFP_KERNEL); | |
5549 | if (!ioc->sas_hba.phy) { | |
5550 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5551 | ioc->name, __FILE__, __LINE__, __func__); | |
5552 | goto out; | |
5553 | } | |
5554 | ioc->sas_hba.num_phys = num_phys; | |
f92363d1 SR |
5555 | |
5556 | /* sas_iounit page 0 */ | |
5557 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys * | |
5558 | sizeof(Mpi2SasIOUnit0PhyData_t)); | |
5559 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); | |
5560 | if (!sas_iounit_pg0) { | |
5561 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5562 | ioc->name, __FILE__, __LINE__, __func__); | |
5563 | return; | |
5564 | } | |
5565 | if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, | |
5566 | sas_iounit_pg0, sz))) { | |
5567 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5568 | ioc->name, __FILE__, __LINE__, __func__); | |
5569 | goto out; | |
5570 | } | |
5571 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5572 | MPI2_IOCSTATUS_MASK; | |
5573 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
5574 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5575 | ioc->name, __FILE__, __LINE__, __func__); | |
5576 | goto out; | |
5577 | } | |
5578 | ||
5579 | /* sas_iounit page 1 */ | |
5580 | sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys * | |
5581 | sizeof(Mpi2SasIOUnit1PhyData_t)); | |
5582 | sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL); | |
5583 | if (!sas_iounit_pg1) { | |
5584 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5585 | ioc->name, __FILE__, __LINE__, __func__); | |
5586 | goto out; | |
5587 | } | |
5588 | if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply, | |
5589 | sas_iounit_pg1, sz))) { | |
5590 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5591 | ioc->name, __FILE__, __LINE__, __func__); | |
5592 | goto out; | |
5593 | } | |
5594 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5595 | MPI2_IOCSTATUS_MASK; | |
5596 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
5597 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5598 | ioc->name, __FILE__, __LINE__, __func__); | |
5599 | goto out; | |
5600 | } | |
5601 | ||
5602 | ioc->io_missing_delay = | |
5603 | sas_iounit_pg1->IODeviceMissingDelay; | |
5604 | device_missing_delay = | |
5605 | sas_iounit_pg1->ReportDeviceMissingDelay; | |
5606 | if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16) | |
5607 | ioc->device_missing_delay = (device_missing_delay & | |
5608 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16; | |
5609 | else | |
5610 | ioc->device_missing_delay = device_missing_delay & | |
5611 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK; | |
5612 | ||
5613 | ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev; | |
f92363d1 SR |
5614 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { |
5615 | if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0, | |
5616 | i))) { | |
5617 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5618 | ioc->name, __FILE__, __LINE__, __func__); | |
5619 | goto out; | |
5620 | } | |
5621 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5622 | MPI2_IOCSTATUS_MASK; | |
5623 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
5624 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5625 | ioc->name, __FILE__, __LINE__, __func__); | |
5626 | goto out; | |
5627 | } | |
5628 | ||
5629 | if (i == 0) | |
5630 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> | |
5631 | PhyData[0].ControllerDevHandle); | |
5632 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; | |
5633 | ioc->sas_hba.phy[i].phy_id = i; | |
5634 | mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i], | |
5635 | phy_pg0, ioc->sas_hba.parent_dev); | |
5636 | } | |
5637 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
5638 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) { | |
5639 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5640 | ioc->name, __FILE__, __LINE__, __func__); | |
5641 | goto out; | |
5642 | } | |
5643 | ioc->sas_hba.enclosure_handle = | |
5644 | le16_to_cpu(sas_device_pg0.EnclosureHandle); | |
5645 | ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | |
5646 | pr_info(MPT3SAS_FMT | |
5647 | "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n", | |
5648 | ioc->name, ioc->sas_hba.handle, | |
5649 | (unsigned long long) ioc->sas_hba.sas_address, | |
5650 | ioc->sas_hba.num_phys) ; | |
5651 | ||
5652 | if (ioc->sas_hba.enclosure_handle) { | |
5653 | if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
5654 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
5655 | ioc->sas_hba.enclosure_handle))) | |
5656 | ioc->sas_hba.enclosure_logical_id = | |
5657 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
5658 | } | |
5659 | ||
5660 | out: | |
5661 | kfree(sas_iounit_pg1); | |
5662 | kfree(sas_iounit_pg0); | |
5663 | } | |
5664 | ||
5665 | /** | |
5666 | * _scsih_expander_add - creating expander object | |
5667 | * @ioc: per adapter object | |
5668 | * @handle: expander handle | |
5669 | * | |
5670 | * Creating expander object, stored in ioc->sas_expander_list. | |
5671 | * | |
5672 | * Return 0 for success, else error. | |
5673 | */ | |
5674 | static int | |
5675 | _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
5676 | { | |
5677 | struct _sas_node *sas_expander; | |
22a923c3 | 5678 | struct _enclosure_node *enclosure_dev; |
f92363d1 SR |
5679 | Mpi2ConfigReply_t mpi_reply; |
5680 | Mpi2ExpanderPage0_t expander_pg0; | |
5681 | Mpi2ExpanderPage1_t expander_pg1; | |
f92363d1 SR |
5682 | u32 ioc_status; |
5683 | u16 parent_handle; | |
5684 | u64 sas_address, sas_address_parent = 0; | |
5685 | int i; | |
5686 | unsigned long flags; | |
5687 | struct _sas_port *mpt3sas_port = NULL; | |
5688 | ||
5689 | int rc = 0; | |
5690 | ||
5691 | if (!handle) | |
5692 | return -1; | |
5693 | ||
5694 | if (ioc->shost_recovery || ioc->pci_error_recovery) | |
5695 | return -1; | |
5696 | ||
5697 | if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | |
5698 | MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) { | |
5699 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5700 | ioc->name, __FILE__, __LINE__, __func__); | |
5701 | return -1; | |
5702 | } | |
5703 | ||
5704 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5705 | MPI2_IOCSTATUS_MASK; | |
5706 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
5707 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5708 | ioc->name, __FILE__, __LINE__, __func__); | |
5709 | return -1; | |
5710 | } | |
5711 | ||
5712 | /* handle out of order topology events */ | |
5713 | parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle); | |
5714 | if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent) | |
5715 | != 0) { | |
5716 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5717 | ioc->name, __FILE__, __LINE__, __func__); | |
5718 | return -1; | |
5719 | } | |
5720 | if (sas_address_parent != ioc->sas_hba.sas_address) { | |
5721 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
5722 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, | |
5723 | sas_address_parent); | |
5724 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
5725 | if (!sas_expander) { | |
5726 | rc = _scsih_expander_add(ioc, parent_handle); | |
5727 | if (rc != 0) | |
5728 | return rc; | |
5729 | } | |
5730 | } | |
5731 | ||
5732 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
5733 | sas_address = le64_to_cpu(expander_pg0.SASAddress); | |
5734 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, | |
5735 | sas_address); | |
5736 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
5737 | ||
5738 | if (sas_expander) | |
5739 | return 0; | |
5740 | ||
5741 | sas_expander = kzalloc(sizeof(struct _sas_node), | |
5742 | GFP_KERNEL); | |
5743 | if (!sas_expander) { | |
5744 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5745 | ioc->name, __FILE__, __LINE__, __func__); | |
5746 | return -1; | |
5747 | } | |
5748 | ||
5749 | sas_expander->handle = handle; | |
5750 | sas_expander->num_phys = expander_pg0.NumPhys; | |
5751 | sas_expander->sas_address_parent = sas_address_parent; | |
5752 | sas_expander->sas_address = sas_address; | |
5753 | ||
5754 | pr_info(MPT3SAS_FMT "expander_add: handle(0x%04x)," \ | |
5755 | " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name, | |
5756 | handle, parent_handle, (unsigned long long) | |
5757 | sas_expander->sas_address, sas_expander->num_phys); | |
5758 | ||
5759 | if (!sas_expander->num_phys) | |
5760 | goto out_fail; | |
5761 | sas_expander->phy = kcalloc(sas_expander->num_phys, | |
5762 | sizeof(struct _sas_phy), GFP_KERNEL); | |
5763 | if (!sas_expander->phy) { | |
5764 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5765 | ioc->name, __FILE__, __LINE__, __func__); | |
5766 | rc = -1; | |
5767 | goto out_fail; | |
5768 | } | |
5769 | ||
5770 | INIT_LIST_HEAD(&sas_expander->sas_port_list); | |
5771 | mpt3sas_port = mpt3sas_transport_port_add(ioc, handle, | |
5772 | sas_address_parent); | |
5773 | if (!mpt3sas_port) { | |
5774 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5775 | ioc->name, __FILE__, __LINE__, __func__); | |
5776 | rc = -1; | |
5777 | goto out_fail; | |
5778 | } | |
5779 | sas_expander->parent_dev = &mpt3sas_port->rphy->dev; | |
5780 | ||
5781 | for (i = 0 ; i < sas_expander->num_phys ; i++) { | |
5782 | if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply, | |
5783 | &expander_pg1, i, handle))) { | |
5784 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5785 | ioc->name, __FILE__, __LINE__, __func__); | |
5786 | rc = -1; | |
5787 | goto out_fail; | |
5788 | } | |
5789 | sas_expander->phy[i].handle = handle; | |
5790 | sas_expander->phy[i].phy_id = i; | |
5791 | ||
5792 | if ((mpt3sas_transport_add_expander_phy(ioc, | |
5793 | &sas_expander->phy[i], expander_pg1, | |
5794 | sas_expander->parent_dev))) { | |
5795 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5796 | ioc->name, __FILE__, __LINE__, __func__); | |
5797 | rc = -1; | |
5798 | goto out_fail; | |
5799 | } | |
5800 | } | |
5801 | ||
5802 | if (sas_expander->enclosure_handle) { | |
22a923c3 C |
5803 | enclosure_dev = |
5804 | mpt3sas_scsih_enclosure_find_by_handle(ioc, | |
5805 | sas_expander->enclosure_handle); | |
5806 | if (enclosure_dev) | |
f92363d1 | 5807 | sas_expander->enclosure_logical_id = |
22a923c3 | 5808 | le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID); |
f92363d1 SR |
5809 | } |
5810 | ||
5811 | _scsih_expander_node_add(ioc, sas_expander); | |
199fd79a | 5812 | return 0; |
f92363d1 SR |
5813 | |
5814 | out_fail: | |
5815 | ||
5816 | if (mpt3sas_port) | |
5817 | mpt3sas_transport_port_remove(ioc, sas_expander->sas_address, | |
5818 | sas_address_parent); | |
5819 | kfree(sas_expander); | |
5820 | return rc; | |
5821 | } | |
5822 | ||
5823 | /** | |
5824 | * mpt3sas_expander_remove - removing expander object | |
5825 | * @ioc: per adapter object | |
5826 | * @sas_address: expander sas_address | |
5827 | * | |
5828 | * Return nothing. | |
5829 | */ | |
5830 | void | |
5831 | mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address) | |
5832 | { | |
5833 | struct _sas_node *sas_expander; | |
5834 | unsigned long flags; | |
5835 | ||
5836 | if (ioc->shost_recovery) | |
5837 | return; | |
5838 | ||
5839 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
5840 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, | |
5841 | sas_address); | |
f92363d1 SR |
5842 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
5843 | if (sas_expander) | |
5844 | _scsih_expander_node_remove(ioc, sas_expander); | |
5845 | } | |
5846 | ||
5847 | /** | |
5848 | * _scsih_done - internal SCSI_IO callback handler. | |
5849 | * @ioc: per adapter object | |
5850 | * @smid: system request message index | |
5851 | * @msix_index: MSIX table index supplied by the OS | |
5852 | * @reply: reply message frame(lower 32bit addr) | |
5853 | * | |
5854 | * Callback handler when sending internal generated SCSI_IO. | |
5855 | * The callback index passed is `ioc->scsih_cb_idx` | |
5856 | * | |
5857 | * Return 1 meaning mf should be freed from _base_interrupt | |
5858 | * 0 means the mf is freed from this function. | |
5859 | */ | |
5860 | static u8 | |
5861 | _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | |
5862 | { | |
5863 | MPI2DefaultReply_t *mpi_reply; | |
5864 | ||
5865 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
5866 | if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED) | |
5867 | return 1; | |
5868 | if (ioc->scsih_cmds.smid != smid) | |
5869 | return 1; | |
5870 | ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE; | |
5871 | if (mpi_reply) { | |
5872 | memcpy(ioc->scsih_cmds.reply, mpi_reply, | |
5873 | mpi_reply->MsgLength*4); | |
5874 | ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID; | |
5875 | } | |
5876 | ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING; | |
5877 | complete(&ioc->scsih_cmds.done); | |
5878 | return 1; | |
5879 | } | |
5880 | ||
5881 | ||
5882 | ||
5883 | ||
5884 | #define MPT3_MAX_LUNS (255) | |
5885 | ||
5886 | ||
5887 | /** | |
5888 | * _scsih_check_access_status - check access flags | |
5889 | * @ioc: per adapter object | |
5890 | * @sas_address: sas address | |
5891 | * @handle: sas device handle | |
5892 | * @access_flags: errors returned during discovery of the device | |
5893 | * | |
5894 | * Return 0 for success, else failure | |
5895 | */ | |
5896 | static u8 | |
5897 | _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address, | |
5898 | u16 handle, u8 access_status) | |
5899 | { | |
5900 | u8 rc = 1; | |
5901 | char *desc = NULL; | |
5902 | ||
5903 | switch (access_status) { | |
5904 | case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS: | |
5905 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION: | |
5906 | rc = 0; | |
5907 | break; | |
5908 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED: | |
5909 | desc = "sata capability failed"; | |
5910 | break; | |
5911 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT: | |
5912 | desc = "sata affiliation conflict"; | |
5913 | break; | |
5914 | case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE: | |
5915 | desc = "route not addressable"; | |
5916 | break; | |
5917 | case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE: | |
5918 | desc = "smp error not addressable"; | |
5919 | break; | |
5920 | case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED: | |
5921 | desc = "device blocked"; | |
5922 | break; | |
5923 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED: | |
5924 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN: | |
5925 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT: | |
5926 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG: | |
5927 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION: | |
5928 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER: | |
5929 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN: | |
5930 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN: | |
5931 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN: | |
5932 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION: | |
5933 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE: | |
5934 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX: | |
5935 | desc = "sata initialization failed"; | |
5936 | break; | |
5937 | default: | |
5938 | desc = "unknown"; | |
5939 | break; | |
5940 | } | |
5941 | ||
5942 | if (!rc) | |
5943 | return 0; | |
5944 | ||
5945 | pr_err(MPT3SAS_FMT | |
5946 | "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n", | |
5947 | ioc->name, desc, (unsigned long long)sas_address, handle); | |
5948 | return rc; | |
5949 | } | |
5950 | ||
5951 | /** | |
5952 | * _scsih_check_device - checking device responsiveness | |
5953 | * @ioc: per adapter object | |
5954 | * @parent_sas_address: sas address of parent expander or sas host | |
5955 | * @handle: attached device handle | |
5956 | * @phy_numberv: phy number | |
5957 | * @link_rate: new link rate | |
5958 | * | |
5959 | * Returns nothing. | |
5960 | */ | |
5961 | static void | |
5962 | _scsih_check_device(struct MPT3SAS_ADAPTER *ioc, | |
5963 | u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate) | |
5964 | { | |
5965 | Mpi2ConfigReply_t mpi_reply; | |
5966 | Mpi2SasDevicePage0_t sas_device_pg0; | |
5967 | struct _sas_device *sas_device; | |
22a923c3 | 5968 | struct _enclosure_node *enclosure_dev = NULL; |
f92363d1 SR |
5969 | u32 ioc_status; |
5970 | unsigned long flags; | |
5971 | u64 sas_address; | |
5972 | struct scsi_target *starget; | |
5973 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
5974 | u32 device_info; | |
5975 | ||
f92363d1 SR |
5976 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
5977 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) | |
5978 | return; | |
5979 | ||
5980 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
5981 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | |
5982 | return; | |
5983 | ||
5984 | /* wide port handling ~ we need only handle device once for the phy that | |
5985 | * is matched in sas device page zero | |
5986 | */ | |
5987 | if (phy_number != sas_device_pg0.PhyNum) | |
5988 | return; | |
5989 | ||
5990 | /* check if this is end device */ | |
5991 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | |
5992 | if (!(_scsih_is_end_device(device_info))) | |
5993 | return; | |
5994 | ||
5995 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
5996 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | |
d1cb5e49 | 5997 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 SR |
5998 | sas_address); |
5999 | ||
d1cb5e49 SR |
6000 | if (!sas_device) |
6001 | goto out_unlock; | |
f92363d1 SR |
6002 | |
6003 | if (unlikely(sas_device->handle != handle)) { | |
6004 | starget = sas_device->starget; | |
6005 | sas_target_priv_data = starget->hostdata; | |
6006 | starget_printk(KERN_INFO, starget, | |
6007 | "handle changed from(0x%04x) to (0x%04x)!!!\n", | |
6008 | sas_device->handle, handle); | |
6009 | sas_target_priv_data->handle = handle; | |
6010 | sas_device->handle = handle; | |
aa53bb89 | 6011 | if (le16_to_cpu(sas_device_pg0.Flags) & |
e6d45e3e SR |
6012 | MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) { |
6013 | sas_device->enclosure_level = | |
aa53bb89 | 6014 | sas_device_pg0.EnclosureLevel; |
310c8e40 CO |
6015 | memcpy(sas_device->connector_name, |
6016 | sas_device_pg0.ConnectorName, 4); | |
6017 | sas_device->connector_name[4] = '\0'; | |
e6d45e3e SR |
6018 | } else { |
6019 | sas_device->enclosure_level = 0; | |
6020 | sas_device->connector_name[0] = '\0'; | |
6021 | } | |
aba5a85c | 6022 | |
22a923c3 C |
6023 | sas_device->enclosure_handle = |
6024 | le16_to_cpu(sas_device_pg0.EnclosureHandle); | |
6025 | sas_device->is_chassis_slot_valid = 0; | |
6026 | enclosure_dev = mpt3sas_scsih_enclosure_find_by_handle(ioc, | |
6027 | sas_device->enclosure_handle); | |
6028 | if (enclosure_dev) { | |
6029 | sas_device->enclosure_logical_id = | |
6030 | le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID); | |
6031 | if (le16_to_cpu(enclosure_dev->pg0.Flags) & | |
6032 | MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) { | |
6033 | sas_device->is_chassis_slot_valid = 1; | |
6034 | sas_device->chassis_slot = | |
6035 | enclosure_dev->pg0.ChassisSlot; | |
6036 | } | |
6037 | } | |
f92363d1 SR |
6038 | } |
6039 | ||
6040 | /* check if device is present */ | |
6041 | if (!(le16_to_cpu(sas_device_pg0.Flags) & | |
6042 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { | |
6043 | pr_err(MPT3SAS_FMT | |
6044 | "device is not present handle(0x%04x), flags!!!\n", | |
6045 | ioc->name, handle); | |
d1cb5e49 | 6046 | goto out_unlock; |
f92363d1 SR |
6047 | } |
6048 | ||
6049 | /* check if there were any issues with discovery */ | |
6050 | if (_scsih_check_access_status(ioc, sas_address, handle, | |
d1cb5e49 SR |
6051 | sas_device_pg0.AccessStatus)) |
6052 | goto out_unlock; | |
f92363d1 SR |
6053 | |
6054 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
6055 | _scsih_ublock_io_device(ioc, sas_address); | |
6056 | ||
d1cb5e49 SR |
6057 | if (sas_device) |
6058 | sas_device_put(sas_device); | |
6059 | return; | |
6060 | ||
6061 | out_unlock: | |
6062 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
6063 | if (sas_device) | |
6064 | sas_device_put(sas_device); | |
f92363d1 SR |
6065 | } |
6066 | ||
6067 | /** | |
6068 | * _scsih_add_device - creating sas device object | |
6069 | * @ioc: per adapter object | |
6070 | * @handle: sas device handle | |
6071 | * @phy_num: phy number end device attached to | |
6072 | * @is_pd: is this hidden raid component | |
6073 | * | |
6074 | * Creating end device object, stored in ioc->sas_device_list. | |
6075 | * | |
6076 | * Returns 0 for success, non-zero for failure. | |
6077 | */ | |
6078 | static int | |
6079 | _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num, | |
6080 | u8 is_pd) | |
6081 | { | |
6082 | Mpi2ConfigReply_t mpi_reply; | |
6083 | Mpi2SasDevicePage0_t sas_device_pg0; | |
f92363d1 | 6084 | struct _sas_device *sas_device; |
22a923c3 | 6085 | struct _enclosure_node *enclosure_dev = NULL; |
f92363d1 SR |
6086 | u32 ioc_status; |
6087 | u64 sas_address; | |
6088 | u32 device_info; | |
f92363d1 SR |
6089 | |
6090 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
6091 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
6092 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6093 | ioc->name, __FILE__, __LINE__, __func__); | |
6094 | return -1; | |
6095 | } | |
6096 | ||
6097 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6098 | MPI2_IOCSTATUS_MASK; | |
6099 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
6100 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6101 | ioc->name, __FILE__, __LINE__, __func__); | |
6102 | return -1; | |
6103 | } | |
6104 | ||
6105 | /* check if this is end device */ | |
6106 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | |
6107 | if (!(_scsih_is_end_device(device_info))) | |
6108 | return -1; | |
c696f7b8 | 6109 | set_bit(handle, ioc->pend_os_device_add); |
f92363d1 SR |
6110 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
6111 | ||
6112 | /* check if device is present */ | |
6113 | if (!(le16_to_cpu(sas_device_pg0.Flags) & | |
6114 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { | |
6115 | pr_err(MPT3SAS_FMT "device is not present handle(0x04%x)!!!\n", | |
6116 | ioc->name, handle); | |
6117 | return -1; | |
6118 | } | |
6119 | ||
6120 | /* check if there were any issues with discovery */ | |
6121 | if (_scsih_check_access_status(ioc, sas_address, handle, | |
6122 | sas_device_pg0.AccessStatus)) | |
6123 | return -1; | |
6124 | ||
d1cb5e49 SR |
6125 | sas_device = mpt3sas_get_sdev_by_addr(ioc, |
6126 | sas_address); | |
6127 | if (sas_device) { | |
c696f7b8 | 6128 | clear_bit(handle, ioc->pend_os_device_add); |
d1cb5e49 | 6129 | sas_device_put(sas_device); |
f92363d1 | 6130 | return -1; |
d1cb5e49 | 6131 | } |
f92363d1 | 6132 | |
75888956 | 6133 | if (sas_device_pg0.EnclosureHandle) { |
22a923c3 C |
6134 | enclosure_dev = |
6135 | mpt3sas_scsih_enclosure_find_by_handle(ioc, | |
6136 | le16_to_cpu(sas_device_pg0.EnclosureHandle)); | |
6137 | if (enclosure_dev == NULL) | |
6138 | pr_info(MPT3SAS_FMT "Enclosure handle(0x%04x)" | |
6139 | "doesn't match with enclosure device!\n", | |
75888956 SR |
6140 | ioc->name, sas_device_pg0.EnclosureHandle); |
6141 | } | |
6142 | ||
f92363d1 SR |
6143 | sas_device = kzalloc(sizeof(struct _sas_device), |
6144 | GFP_KERNEL); | |
6145 | if (!sas_device) { | |
6146 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6147 | ioc->name, __FILE__, __LINE__, __func__); | |
6148 | return 0; | |
6149 | } | |
6150 | ||
d1cb5e49 | 6151 | kref_init(&sas_device->refcount); |
f92363d1 SR |
6152 | sas_device->handle = handle; |
6153 | if (_scsih_get_sas_address(ioc, | |
6154 | le16_to_cpu(sas_device_pg0.ParentDevHandle), | |
6155 | &sas_device->sas_address_parent) != 0) | |
6156 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6157 | ioc->name, __FILE__, __LINE__, __func__); | |
6158 | sas_device->enclosure_handle = | |
6159 | le16_to_cpu(sas_device_pg0.EnclosureHandle); | |
e6d45e3e SR |
6160 | if (sas_device->enclosure_handle != 0) |
6161 | sas_device->slot = | |
6162 | le16_to_cpu(sas_device_pg0.Slot); | |
f92363d1 SR |
6163 | sas_device->device_info = device_info; |
6164 | sas_device->sas_address = sas_address; | |
6165 | sas_device->phy = sas_device_pg0.PhyNum; | |
6166 | sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) & | |
6167 | MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0; | |
6168 | ||
aa53bb89 SPS |
6169 | if (le16_to_cpu(sas_device_pg0.Flags) |
6170 | & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) { | |
e6d45e3e | 6171 | sas_device->enclosure_level = |
aa53bb89 | 6172 | sas_device_pg0.EnclosureLevel; |
310c8e40 CO |
6173 | memcpy(sas_device->connector_name, |
6174 | sas_device_pg0.ConnectorName, 4); | |
6175 | sas_device->connector_name[4] = '\0'; | |
e6d45e3e SR |
6176 | } else { |
6177 | sas_device->enclosure_level = 0; | |
6178 | sas_device->connector_name[0] = '\0'; | |
6179 | } | |
22a923c3 | 6180 | /* get enclosure_logical_id & chassis_slot*/ |
75888956 | 6181 | sas_device->is_chassis_slot_valid = 0; |
22a923c3 | 6182 | if (enclosure_dev) { |
f92363d1 | 6183 | sas_device->enclosure_logical_id = |
22a923c3 C |
6184 | le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID); |
6185 | if (le16_to_cpu(enclosure_dev->pg0.Flags) & | |
75888956 SR |
6186 | MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) { |
6187 | sas_device->is_chassis_slot_valid = 1; | |
6188 | sas_device->chassis_slot = | |
22a923c3 | 6189 | enclosure_dev->pg0.ChassisSlot; |
75888956 SR |
6190 | } |
6191 | } | |
6192 | ||
f92363d1 SR |
6193 | /* get device name */ |
6194 | sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName); | |
6195 | ||
6196 | if (ioc->wait_for_discovery_to_complete) | |
6197 | _scsih_sas_device_init_add(ioc, sas_device); | |
6198 | else | |
6199 | _scsih_sas_device_add(ioc, sas_device); | |
6200 | ||
d1cb5e49 | 6201 | sas_device_put(sas_device); |
f92363d1 SR |
6202 | return 0; |
6203 | } | |
6204 | ||
6205 | /** | |
6206 | * _scsih_remove_device - removing sas device object | |
6207 | * @ioc: per adapter object | |
6208 | * @sas_device_delete: the sas_device object | |
6209 | * | |
6210 | * Return nothing. | |
6211 | */ | |
6212 | static void | |
6213 | _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc, | |
6214 | struct _sas_device *sas_device) | |
6215 | { | |
6216 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
6217 | ||
0f624c39 SR |
6218 | if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) && |
6219 | (sas_device->pfa_led_on)) { | |
6220 | _scsih_turn_off_pfa_led(ioc, sas_device); | |
6221 | sas_device->pfa_led_on = 0; | |
6222 | } | |
75888956 | 6223 | |
f92363d1 SR |
6224 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
6225 | "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n", | |
6226 | ioc->name, __func__, | |
6227 | sas_device->handle, (unsigned long long) | |
6228 | sas_device->sas_address)); | |
75888956 SR |
6229 | |
6230 | dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device, | |
6231 | NULL, NULL)); | |
f92363d1 SR |
6232 | |
6233 | if (sas_device->starget && sas_device->starget->hostdata) { | |
6234 | sas_target_priv_data = sas_device->starget->hostdata; | |
6235 | sas_target_priv_data->deleted = 1; | |
6236 | _scsih_ublock_io_device(ioc, sas_device->sas_address); | |
6237 | sas_target_priv_data->handle = | |
6238 | MPT3SAS_INVALID_DEVICE_HANDLE; | |
6239 | } | |
7786ab6a SR |
6240 | |
6241 | if (!ioc->hide_drives) | |
6242 | mpt3sas_transport_port_remove(ioc, | |
f92363d1 SR |
6243 | sas_device->sas_address, |
6244 | sas_device->sas_address_parent); | |
6245 | ||
6246 | pr_info(MPT3SAS_FMT | |
6247 | "removing handle(0x%04x), sas_addr(0x%016llx)\n", | |
6248 | ioc->name, sas_device->handle, | |
6249 | (unsigned long long) sas_device->sas_address); | |
75888956 SR |
6250 | |
6251 | _scsih_display_enclosure_chassis_info(ioc, sas_device, NULL, NULL); | |
f92363d1 SR |
6252 | |
6253 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6254 | "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n", | |
6255 | ioc->name, __func__, | |
e6d45e3e SR |
6256 | sas_device->handle, (unsigned long long) |
6257 | sas_device->sas_address)); | |
75888956 SR |
6258 | dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device, |
6259 | NULL, NULL)); | |
f92363d1 SR |
6260 | } |
6261 | ||
f92363d1 SR |
6262 | /** |
6263 | * _scsih_sas_topology_change_event_debug - debug for topology event | |
6264 | * @ioc: per adapter object | |
6265 | * @event_data: event data payload | |
6266 | * Context: user. | |
6267 | */ | |
6268 | static void | |
6269 | _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
6270 | Mpi2EventDataSasTopologyChangeList_t *event_data) | |
6271 | { | |
6272 | int i; | |
6273 | u16 handle; | |
6274 | u16 reason_code; | |
6275 | u8 phy_number; | |
6276 | char *status_str = NULL; | |
6277 | u8 link_rate, prev_link_rate; | |
6278 | ||
6279 | switch (event_data->ExpStatus) { | |
6280 | case MPI2_EVENT_SAS_TOPO_ES_ADDED: | |
6281 | status_str = "add"; | |
6282 | break; | |
6283 | case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING: | |
6284 | status_str = "remove"; | |
6285 | break; | |
6286 | case MPI2_EVENT_SAS_TOPO_ES_RESPONDING: | |
6287 | case 0: | |
6288 | status_str = "responding"; | |
6289 | break; | |
6290 | case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING: | |
6291 | status_str = "remove delay"; | |
6292 | break; | |
6293 | default: | |
6294 | status_str = "unknown status"; | |
6295 | break; | |
6296 | } | |
6297 | pr_info(MPT3SAS_FMT "sas topology change: (%s)\n", | |
6298 | ioc->name, status_str); | |
6299 | pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \ | |
6300 | "start_phy(%02d), count(%d)\n", | |
6301 | le16_to_cpu(event_data->ExpanderDevHandle), | |
6302 | le16_to_cpu(event_data->EnclosureHandle), | |
6303 | event_data->StartPhyNum, event_data->NumEntries); | |
6304 | for (i = 0; i < event_data->NumEntries; i++) { | |
6305 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
6306 | if (!handle) | |
6307 | continue; | |
6308 | phy_number = event_data->StartPhyNum + i; | |
6309 | reason_code = event_data->PHY[i].PhyStatus & | |
6310 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
6311 | switch (reason_code) { | |
6312 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: | |
6313 | status_str = "target add"; | |
6314 | break; | |
6315 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: | |
6316 | status_str = "target remove"; | |
6317 | break; | |
6318 | case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING: | |
6319 | status_str = "delay target remove"; | |
6320 | break; | |
6321 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: | |
6322 | status_str = "link rate change"; | |
6323 | break; | |
6324 | case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE: | |
6325 | status_str = "target responding"; | |
6326 | break; | |
6327 | default: | |
6328 | status_str = "unknown"; | |
6329 | break; | |
6330 | } | |
6331 | link_rate = event_data->PHY[i].LinkRate >> 4; | |
6332 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; | |
6333 | pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \ | |
6334 | " link rate: new(0x%02x), old(0x%02x)\n", phy_number, | |
6335 | handle, status_str, link_rate, prev_link_rate); | |
6336 | ||
6337 | } | |
6338 | } | |
f92363d1 SR |
6339 | |
6340 | /** | |
6341 | * _scsih_sas_topology_change_event - handle topology changes | |
6342 | * @ioc: per adapter object | |
6343 | * @fw_event: The fw_event_work object | |
6344 | * Context: user. | |
6345 | * | |
6346 | */ | |
6347 | static int | |
6348 | _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc, | |
6349 | struct fw_event_work *fw_event) | |
6350 | { | |
6351 | int i; | |
6352 | u16 parent_handle, handle; | |
6353 | u16 reason_code; | |
6354 | u8 phy_number, max_phys; | |
6355 | struct _sas_node *sas_expander; | |
6356 | u64 sas_address; | |
6357 | unsigned long flags; | |
6358 | u8 link_rate, prev_link_rate; | |
35b62362 JL |
6359 | Mpi2EventDataSasTopologyChangeList_t *event_data = |
6360 | (Mpi2EventDataSasTopologyChangeList_t *) | |
6361 | fw_event->event_data; | |
f92363d1 | 6362 | |
f92363d1 SR |
6363 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
6364 | _scsih_sas_topology_change_event_debug(ioc, event_data); | |
f92363d1 SR |
6365 | |
6366 | if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery) | |
6367 | return 0; | |
6368 | ||
6369 | if (!ioc->sas_hba.num_phys) | |
6370 | _scsih_sas_host_add(ioc); | |
6371 | else | |
6372 | _scsih_sas_host_refresh(ioc); | |
6373 | ||
6374 | if (fw_event->ignore) { | |
6375 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6376 | "ignoring expander event\n", ioc->name)); | |
6377 | return 0; | |
6378 | } | |
6379 | ||
6380 | parent_handle = le16_to_cpu(event_data->ExpanderDevHandle); | |
6381 | ||
6382 | /* handle expander add */ | |
6383 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED) | |
6384 | if (_scsih_expander_add(ioc, parent_handle) != 0) | |
6385 | return 0; | |
6386 | ||
6387 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
6388 | sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc, | |
6389 | parent_handle); | |
6390 | if (sas_expander) { | |
6391 | sas_address = sas_expander->sas_address; | |
6392 | max_phys = sas_expander->num_phys; | |
6393 | } else if (parent_handle < ioc->sas_hba.num_phys) { | |
6394 | sas_address = ioc->sas_hba.sas_address; | |
6395 | max_phys = ioc->sas_hba.num_phys; | |
6396 | } else { | |
6397 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
6398 | return 0; | |
6399 | } | |
6400 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
6401 | ||
6402 | /* handle siblings events */ | |
6403 | for (i = 0; i < event_data->NumEntries; i++) { | |
6404 | if (fw_event->ignore) { | |
6405 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6406 | "ignoring expander event\n", ioc->name)); | |
6407 | return 0; | |
6408 | } | |
6409 | if (ioc->remove_host || ioc->pci_error_recovery) | |
6410 | return 0; | |
6411 | phy_number = event_data->StartPhyNum + i; | |
6412 | if (phy_number >= max_phys) | |
6413 | continue; | |
6414 | reason_code = event_data->PHY[i].PhyStatus & | |
6415 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
6416 | if ((event_data->PHY[i].PhyStatus & | |
6417 | MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code != | |
6418 | MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)) | |
6419 | continue; | |
6420 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
6421 | if (!handle) | |
6422 | continue; | |
6423 | link_rate = event_data->PHY[i].LinkRate >> 4; | |
6424 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; | |
6425 | switch (reason_code) { | |
6426 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: | |
6427 | ||
6428 | if (ioc->shost_recovery) | |
6429 | break; | |
6430 | ||
6431 | if (link_rate == prev_link_rate) | |
6432 | break; | |
6433 | ||
6434 | mpt3sas_transport_update_links(ioc, sas_address, | |
6435 | handle, phy_number, link_rate); | |
6436 | ||
6437 | if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) | |
6438 | break; | |
6439 | ||
6440 | _scsih_check_device(ioc, sas_address, handle, | |
6441 | phy_number, link_rate); | |
6442 | ||
c696f7b8 SPS |
6443 | if (!test_bit(handle, ioc->pend_os_device_add)) |
6444 | break; | |
6445 | ||
f92363d1 SR |
6446 | |
6447 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: | |
6448 | ||
6449 | if (ioc->shost_recovery) | |
6450 | break; | |
6451 | ||
6452 | mpt3sas_transport_update_links(ioc, sas_address, | |
6453 | handle, phy_number, link_rate); | |
6454 | ||
6455 | _scsih_add_device(ioc, handle, phy_number, 0); | |
6456 | ||
6457 | break; | |
6458 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: | |
6459 | ||
6460 | _scsih_device_remove_by_handle(ioc, handle); | |
6461 | break; | |
6462 | } | |
6463 | } | |
6464 | ||
6465 | /* handle expander removal */ | |
6466 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING && | |
6467 | sas_expander) | |
6468 | mpt3sas_expander_remove(ioc, sas_address); | |
6469 | ||
6470 | return 0; | |
6471 | } | |
6472 | ||
f92363d1 SR |
6473 | /** |
6474 | * _scsih_sas_device_status_change_event_debug - debug for device event | |
6475 | * @event_data: event data payload | |
6476 | * Context: user. | |
6477 | * | |
6478 | * Return nothing. | |
6479 | */ | |
6480 | static void | |
6481 | _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
6482 | Mpi2EventDataSasDeviceStatusChange_t *event_data) | |
6483 | { | |
6484 | char *reason_str = NULL; | |
6485 | ||
6486 | switch (event_data->ReasonCode) { | |
6487 | case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA: | |
6488 | reason_str = "smart data"; | |
6489 | break; | |
6490 | case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED: | |
6491 | reason_str = "unsupported device discovered"; | |
6492 | break; | |
6493 | case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET: | |
6494 | reason_str = "internal device reset"; | |
6495 | break; | |
6496 | case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL: | |
6497 | reason_str = "internal task abort"; | |
6498 | break; | |
6499 | case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL: | |
6500 | reason_str = "internal task abort set"; | |
6501 | break; | |
6502 | case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL: | |
6503 | reason_str = "internal clear task set"; | |
6504 | break; | |
6505 | case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL: | |
6506 | reason_str = "internal query task"; | |
6507 | break; | |
6508 | case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE: | |
6509 | reason_str = "sata init failure"; | |
6510 | break; | |
6511 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET: | |
6512 | reason_str = "internal device reset complete"; | |
6513 | break; | |
6514 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL: | |
6515 | reason_str = "internal task abort complete"; | |
6516 | break; | |
6517 | case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION: | |
6518 | reason_str = "internal async notification"; | |
6519 | break; | |
6520 | case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY: | |
6521 | reason_str = "expander reduced functionality"; | |
6522 | break; | |
6523 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY: | |
6524 | reason_str = "expander reduced functionality complete"; | |
6525 | break; | |
6526 | default: | |
6527 | reason_str = "unknown reason"; | |
6528 | break; | |
6529 | } | |
6530 | pr_info(MPT3SAS_FMT "device status change: (%s)\n" | |
6531 | "\thandle(0x%04x), sas address(0x%016llx), tag(%d)", | |
6532 | ioc->name, reason_str, le16_to_cpu(event_data->DevHandle), | |
6533 | (unsigned long long)le64_to_cpu(event_data->SASAddress), | |
6534 | le16_to_cpu(event_data->TaskTag)); | |
6535 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA) | |
6536 | pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name, | |
6537 | event_data->ASC, event_data->ASCQ); | |
6538 | pr_info("\n"); | |
6539 | } | |
f92363d1 SR |
6540 | |
6541 | /** | |
6542 | * _scsih_sas_device_status_change_event - handle device status change | |
6543 | * @ioc: per adapter object | |
6544 | * @fw_event: The fw_event_work object | |
6545 | * Context: user. | |
6546 | * | |
6547 | * Return nothing. | |
6548 | */ | |
6549 | static void | |
6550 | _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc, | |
6551 | struct fw_event_work *fw_event) | |
6552 | { | |
6553 | struct MPT3SAS_TARGET *target_priv_data; | |
6554 | struct _sas_device *sas_device; | |
6555 | u64 sas_address; | |
6556 | unsigned long flags; | |
6557 | Mpi2EventDataSasDeviceStatusChange_t *event_data = | |
35b62362 JL |
6558 | (Mpi2EventDataSasDeviceStatusChange_t *) |
6559 | fw_event->event_data; | |
f92363d1 | 6560 | |
f92363d1 SR |
6561 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
6562 | _scsih_sas_device_status_change_event_debug(ioc, | |
6563 | event_data); | |
f92363d1 SR |
6564 | |
6565 | /* In MPI Revision K (0xC), the internal device reset complete was | |
6566 | * implemented, so avoid setting tm_busy flag for older firmware. | |
6567 | */ | |
6568 | if ((ioc->facts.HeaderVersion >> 8) < 0xC) | |
6569 | return; | |
6570 | ||
6571 | if (event_data->ReasonCode != | |
6572 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET && | |
6573 | event_data->ReasonCode != | |
6574 | MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET) | |
6575 | return; | |
6576 | ||
6577 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
6578 | sas_address = le64_to_cpu(event_data->SASAddress); | |
d1cb5e49 | 6579 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 SR |
6580 | sas_address); |
6581 | ||
d1cb5e49 SR |
6582 | if (!sas_device || !sas_device->starget) |
6583 | goto out; | |
f92363d1 SR |
6584 | |
6585 | target_priv_data = sas_device->starget->hostdata; | |
d1cb5e49 SR |
6586 | if (!target_priv_data) |
6587 | goto out; | |
f92363d1 SR |
6588 | |
6589 | if (event_data->ReasonCode == | |
6590 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET) | |
6591 | target_priv_data->tm_busy = 1; | |
6592 | else | |
6593 | target_priv_data->tm_busy = 0; | |
d1cb5e49 SR |
6594 | |
6595 | out: | |
6596 | if (sas_device) | |
6597 | sas_device_put(sas_device); | |
6598 | ||
f92363d1 SR |
6599 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
6600 | } | |
6601 | ||
4318c734 | 6602 | |
c102e00c SPS |
6603 | /** |
6604 | * _scsih_check_pcie_access_status - check access flags | |
6605 | * @ioc: per adapter object | |
6606 | * @wwid: wwid | |
6607 | * @handle: sas device handle | |
6608 | * @access_flags: errors returned during discovery of the device | |
6609 | * | |
6610 | * Return 0 for success, else failure | |
6611 | */ | |
6612 | static u8 | |
6613 | _scsih_check_pcie_access_status(struct MPT3SAS_ADAPTER *ioc, u64 wwid, | |
6614 | u16 handle, u8 access_status) | |
6615 | { | |
6616 | u8 rc = 1; | |
6617 | char *desc = NULL; | |
6618 | ||
6619 | switch (access_status) { | |
6620 | case MPI26_PCIEDEV0_ASTATUS_NO_ERRORS: | |
6621 | case MPI26_PCIEDEV0_ASTATUS_NEEDS_INITIALIZATION: | |
6622 | rc = 0; | |
6623 | break; | |
6624 | case MPI26_PCIEDEV0_ASTATUS_CAPABILITY_FAILED: | |
6625 | desc = "PCIe device capability failed"; | |
6626 | break; | |
6627 | case MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED: | |
6628 | desc = "PCIe device blocked"; | |
6629 | break; | |
6630 | case MPI26_PCIEDEV0_ASTATUS_MEMORY_SPACE_ACCESS_FAILED: | |
6631 | desc = "PCIe device mem space access failed"; | |
6632 | break; | |
6633 | case MPI26_PCIEDEV0_ASTATUS_UNSUPPORTED_DEVICE: | |
6634 | desc = "PCIe device unsupported"; | |
6635 | break; | |
6636 | case MPI26_PCIEDEV0_ASTATUS_MSIX_REQUIRED: | |
6637 | desc = "PCIe device MSIx Required"; | |
6638 | break; | |
6639 | case MPI26_PCIEDEV0_ASTATUS_INIT_FAIL_MAX: | |
6640 | desc = "PCIe device init fail max"; | |
6641 | break; | |
6642 | case MPI26_PCIEDEV0_ASTATUS_UNKNOWN: | |
6643 | desc = "PCIe device status unknown"; | |
6644 | break; | |
6645 | case MPI26_PCIEDEV0_ASTATUS_NVME_READY_TIMEOUT: | |
6646 | desc = "nvme ready timeout"; | |
6647 | break; | |
6648 | case MPI26_PCIEDEV0_ASTATUS_NVME_DEVCFG_UNSUPPORTED: | |
6649 | desc = "nvme device configuration unsupported"; | |
6650 | break; | |
6651 | case MPI26_PCIEDEV0_ASTATUS_NVME_IDENTIFY_FAILED: | |
6652 | desc = "nvme identify failed"; | |
6653 | break; | |
6654 | case MPI26_PCIEDEV0_ASTATUS_NVME_QCONFIG_FAILED: | |
6655 | desc = "nvme qconfig failed"; | |
6656 | break; | |
6657 | case MPI26_PCIEDEV0_ASTATUS_NVME_QCREATION_FAILED: | |
6658 | desc = "nvme qcreation failed"; | |
6659 | break; | |
6660 | case MPI26_PCIEDEV0_ASTATUS_NVME_EVENTCFG_FAILED: | |
6661 | desc = "nvme eventcfg failed"; | |
6662 | break; | |
6663 | case MPI26_PCIEDEV0_ASTATUS_NVME_GET_FEATURE_STAT_FAILED: | |
6664 | desc = "nvme get feature stat failed"; | |
6665 | break; | |
6666 | case MPI26_PCIEDEV0_ASTATUS_NVME_IDLE_TIMEOUT: | |
6667 | desc = "nvme idle timeout"; | |
6668 | break; | |
6669 | case MPI26_PCIEDEV0_ASTATUS_NVME_FAILURE_STATUS: | |
6670 | desc = "nvme failure status"; | |
6671 | break; | |
6672 | default: | |
6673 | pr_err(MPT3SAS_FMT | |
6674 | " NVMe discovery error(0x%02x): wwid(0x%016llx)," | |
6675 | "handle(0x%04x)\n", ioc->name, access_status, | |
6676 | (unsigned long long)wwid, handle); | |
6677 | return rc; | |
6678 | } | |
6679 | ||
6680 | if (!rc) | |
6681 | return rc; | |
6682 | ||
6683 | pr_info(MPT3SAS_FMT | |
6684 | "NVMe discovery error(%s): wwid(0x%016llx), handle(0x%04x)\n", | |
6685 | ioc->name, desc, | |
6686 | (unsigned long long)wwid, handle); | |
6687 | return rc; | |
6688 | } | |
3075ac49 SPS |
6689 | |
6690 | /** | |
6691 | * _scsih_pcie_device_remove_from_sml - removing pcie device | |
6692 | * from SML and free up associated memory | |
6693 | * @ioc: per adapter object | |
6694 | * @pcie_device: the pcie_device object | |
6695 | * | |
6696 | * Return nothing. | |
6697 | */ | |
6698 | static void | |
6699 | _scsih_pcie_device_remove_from_sml(struct MPT3SAS_ADAPTER *ioc, | |
6700 | struct _pcie_device *pcie_device) | |
6701 | { | |
6702 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
6703 | ||
6704 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6705 | "%s: enter: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__, | |
6706 | pcie_device->handle, (unsigned long long) | |
6707 | pcie_device->wwid)); | |
6708 | if (pcie_device->enclosure_handle != 0) | |
6709 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6710 | "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n", | |
6711 | ioc->name, __func__, | |
6712 | (unsigned long long)pcie_device->enclosure_logical_id, | |
6713 | pcie_device->slot)); | |
6714 | if (pcie_device->connector_name[0] != '\0') | |
6715 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6716 | "%s: enter: enclosure level(0x%04x), connector name( %s)\n", | |
6717 | ioc->name, __func__, | |
6718 | pcie_device->enclosure_level, | |
6719 | pcie_device->connector_name)); | |
6720 | ||
6721 | if (pcie_device->starget && pcie_device->starget->hostdata) { | |
6722 | sas_target_priv_data = pcie_device->starget->hostdata; | |
6723 | sas_target_priv_data->deleted = 1; | |
6724 | _scsih_ublock_io_device(ioc, pcie_device->wwid); | |
6725 | sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE; | |
6726 | } | |
6727 | ||
6728 | pr_info(MPT3SAS_FMT | |
6729 | "removing handle(0x%04x), wwid (0x%016llx)\n", | |
6730 | ioc->name, pcie_device->handle, | |
6731 | (unsigned long long) pcie_device->wwid); | |
6732 | if (pcie_device->enclosure_handle != 0) | |
6733 | pr_info(MPT3SAS_FMT | |
6734 | "removing : enclosure logical id(0x%016llx), slot(%d)\n", | |
6735 | ioc->name, | |
6736 | (unsigned long long)pcie_device->enclosure_logical_id, | |
6737 | pcie_device->slot); | |
6738 | if (pcie_device->connector_name[0] != '\0') | |
6739 | pr_info(MPT3SAS_FMT | |
6740 | "removing: enclosure level(0x%04x), connector name( %s)\n", | |
6741 | ioc->name, pcie_device->enclosure_level, | |
6742 | pcie_device->connector_name); | |
6743 | ||
6744 | if (pcie_device->starget) | |
6745 | scsi_remove_target(&pcie_device->starget->dev); | |
6746 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6747 | "%s: exit: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__, | |
6748 | pcie_device->handle, (unsigned long long) | |
6749 | pcie_device->wwid)); | |
6750 | if (pcie_device->enclosure_handle != 0) | |
6751 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6752 | "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n", | |
6753 | ioc->name, __func__, | |
6754 | (unsigned long long)pcie_device->enclosure_logical_id, | |
6755 | pcie_device->slot)); | |
6756 | if (pcie_device->connector_name[0] != '\0') | |
6757 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6758 | "%s: exit: enclosure level(0x%04x), connector name( %s)\n", | |
6759 | ioc->name, __func__, pcie_device->enclosure_level, | |
6760 | pcie_device->connector_name)); | |
6761 | ||
6762 | kfree(pcie_device->serial_number); | |
6763 | } | |
6764 | ||
6765 | ||
c102e00c SPS |
6766 | /** |
6767 | * _scsih_pcie_check_device - checking device responsiveness | |
6768 | * @ioc: per adapter object | |
6769 | * @handle: attached device handle | |
6770 | * | |
6771 | * Returns nothing. | |
6772 | */ | |
6773 | static void | |
6774 | _scsih_pcie_check_device(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
6775 | { | |
6776 | Mpi2ConfigReply_t mpi_reply; | |
6777 | Mpi26PCIeDevicePage0_t pcie_device_pg0; | |
6778 | u32 ioc_status; | |
6779 | struct _pcie_device *pcie_device; | |
6780 | u64 wwid; | |
6781 | unsigned long flags; | |
6782 | struct scsi_target *starget; | |
6783 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
6784 | u32 device_info; | |
6785 | ||
6786 | if ((mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply, | |
6787 | &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE, handle))) | |
6788 | return; | |
6789 | ||
6790 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
6791 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | |
6792 | return; | |
6793 | ||
6794 | /* check if this is end device */ | |
6795 | device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo); | |
6796 | if (!(_scsih_is_nvme_device(device_info))) | |
6797 | return; | |
6798 | ||
6799 | wwid = le64_to_cpu(pcie_device_pg0.WWID); | |
6800 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
6801 | pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid); | |
6802 | ||
6803 | if (!pcie_device) { | |
6804 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
6805 | return; | |
6806 | } | |
6807 | ||
6808 | if (unlikely(pcie_device->handle != handle)) { | |
6809 | starget = pcie_device->starget; | |
6810 | sas_target_priv_data = starget->hostdata; | |
6811 | starget_printk(KERN_INFO, starget, | |
6812 | "handle changed from(0x%04x) to (0x%04x)!!!\n", | |
6813 | pcie_device->handle, handle); | |
6814 | sas_target_priv_data->handle = handle; | |
6815 | pcie_device->handle = handle; | |
6816 | ||
6817 | if (le32_to_cpu(pcie_device_pg0.Flags) & | |
6818 | MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) { | |
6819 | pcie_device->enclosure_level = | |
6820 | pcie_device_pg0.EnclosureLevel; | |
6821 | memcpy(&pcie_device->connector_name[0], | |
6822 | &pcie_device_pg0.ConnectorName[0], 4); | |
6823 | } else { | |
6824 | pcie_device->enclosure_level = 0; | |
6825 | pcie_device->connector_name[0] = '\0'; | |
6826 | } | |
6827 | } | |
6828 | ||
6829 | /* check if device is present */ | |
6830 | if (!(le32_to_cpu(pcie_device_pg0.Flags) & | |
6831 | MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT)) { | |
6832 | pr_info(MPT3SAS_FMT | |
6833 | "device is not present handle(0x%04x), flags!!!\n", | |
6834 | ioc->name, handle); | |
6835 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
6836 | pcie_device_put(pcie_device); | |
6837 | return; | |
6838 | } | |
6839 | ||
6840 | /* check if there were any issues with discovery */ | |
6841 | if (_scsih_check_pcie_access_status(ioc, wwid, handle, | |
6842 | pcie_device_pg0.AccessStatus)) { | |
6843 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
6844 | pcie_device_put(pcie_device); | |
6845 | return; | |
6846 | } | |
6847 | ||
6848 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
6849 | pcie_device_put(pcie_device); | |
6850 | ||
6851 | _scsih_ublock_io_device(ioc, wwid); | |
6852 | ||
6853 | return; | |
6854 | } | |
6855 | ||
6856 | /** | |
6857 | * _scsih_pcie_add_device - creating pcie device object | |
6858 | * @ioc: per adapter object | |
6859 | * @handle: pcie device handle | |
6860 | * | |
6861 | * Creating end device object, stored in ioc->pcie_device_list. | |
6862 | * | |
6863 | * Return 1 means queue the event later, 0 means complete the event | |
6864 | */ | |
6865 | static int | |
6866 | _scsih_pcie_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
6867 | { | |
6868 | Mpi26PCIeDevicePage0_t pcie_device_pg0; | |
6869 | Mpi26PCIeDevicePage2_t pcie_device_pg2; | |
6870 | Mpi2ConfigReply_t mpi_reply; | |
c102e00c | 6871 | struct _pcie_device *pcie_device; |
22a923c3 | 6872 | struct _enclosure_node *enclosure_dev; |
c102e00c SPS |
6873 | u32 ioc_status; |
6874 | u64 wwid; | |
6875 | ||
6876 | if ((mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply, | |
6877 | &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
6878 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6879 | ioc->name, __FILE__, __LINE__, __func__); | |
6880 | return 0; | |
6881 | } | |
6882 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6883 | MPI2_IOCSTATUS_MASK; | |
6884 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
6885 | pr_err(MPT3SAS_FMT | |
6886 | "failure at %s:%d/%s()!\n", | |
6887 | ioc->name, __FILE__, __LINE__, __func__); | |
6888 | return 0; | |
6889 | } | |
6890 | ||
6891 | set_bit(handle, ioc->pend_os_device_add); | |
6892 | wwid = le64_to_cpu(pcie_device_pg0.WWID); | |
6893 | ||
6894 | /* check if device is present */ | |
6895 | if (!(le32_to_cpu(pcie_device_pg0.Flags) & | |
6896 | MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT)) { | |
6897 | pr_err(MPT3SAS_FMT | |
6898 | "device is not present handle(0x04%x)!!!\n", | |
6899 | ioc->name, handle); | |
6900 | return 0; | |
6901 | } | |
6902 | ||
6903 | /* check if there were any issues with discovery */ | |
6904 | if (_scsih_check_pcie_access_status(ioc, wwid, handle, | |
6905 | pcie_device_pg0.AccessStatus)) | |
6906 | return 0; | |
6907 | ||
6908 | if (!(_scsih_is_nvme_device(le32_to_cpu(pcie_device_pg0.DeviceInfo)))) | |
6909 | return 0; | |
6910 | ||
6911 | pcie_device = mpt3sas_get_pdev_by_wwid(ioc, wwid); | |
6912 | if (pcie_device) { | |
6913 | clear_bit(handle, ioc->pend_os_device_add); | |
6914 | pcie_device_put(pcie_device); | |
6915 | return 0; | |
6916 | } | |
6917 | ||
6918 | pcie_device = kzalloc(sizeof(struct _pcie_device), GFP_KERNEL); | |
6919 | if (!pcie_device) { | |
6920 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6921 | ioc->name, __FILE__, __LINE__, __func__); | |
6922 | return 0; | |
6923 | } | |
6924 | ||
6925 | kref_init(&pcie_device->refcount); | |
6926 | pcie_device->id = ioc->pcie_target_id++; | |
6927 | pcie_device->channel = PCIE_CHANNEL; | |
6928 | pcie_device->handle = handle; | |
6929 | pcie_device->device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo); | |
6930 | pcie_device->wwid = wwid; | |
6931 | pcie_device->port_num = pcie_device_pg0.PortNum; | |
6932 | pcie_device->fast_path = (le32_to_cpu(pcie_device_pg0.Flags) & | |
6933 | MPI26_PCIEDEV0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0; | |
c102e00c SPS |
6934 | |
6935 | pcie_device->enclosure_handle = | |
6936 | le16_to_cpu(pcie_device_pg0.EnclosureHandle); | |
6937 | if (pcie_device->enclosure_handle != 0) | |
6938 | pcie_device->slot = le16_to_cpu(pcie_device_pg0.Slot); | |
6939 | ||
cf6bf971 | 6940 | if (le32_to_cpu(pcie_device_pg0.Flags) & |
c102e00c SPS |
6941 | MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) { |
6942 | pcie_device->enclosure_level = pcie_device_pg0.EnclosureLevel; | |
6943 | memcpy(&pcie_device->connector_name[0], | |
6944 | &pcie_device_pg0.ConnectorName[0], 4); | |
6945 | } else { | |
6946 | pcie_device->enclosure_level = 0; | |
6947 | pcie_device->connector_name[0] = '\0'; | |
6948 | } | |
6949 | ||
6950 | /* get enclosure_logical_id */ | |
22a923c3 C |
6951 | if (pcie_device->enclosure_handle) { |
6952 | enclosure_dev = | |
6953 | mpt3sas_scsih_enclosure_find_by_handle(ioc, | |
6954 | pcie_device->enclosure_handle); | |
6955 | if (enclosure_dev) | |
6956 | pcie_device->enclosure_logical_id = | |
6957 | le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID); | |
6958 | } | |
c102e00c SPS |
6959 | /* TODO -- Add device name once FW supports it */ |
6960 | if (mpt3sas_config_get_pcie_device_pg2(ioc, &mpi_reply, | |
6961 | &pcie_device_pg2, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)) { | |
6962 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6963 | ioc->name, __FILE__, __LINE__, __func__); | |
6964 | kfree(pcie_device); | |
6965 | return 0; | |
6966 | } | |
6967 | ||
6968 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
6969 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
6970 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6971 | ioc->name, __FILE__, __LINE__, __func__); | |
6972 | kfree(pcie_device); | |
6973 | return 0; | |
6974 | } | |
6975 | pcie_device->nvme_mdts = | |
6976 | le32_to_cpu(pcie_device_pg2.MaximumDataTransferSize); | |
c1a6c5ac C |
6977 | if (pcie_device_pg2.ControllerResetTO) |
6978 | pcie_device->reset_timeout = | |
6979 | pcie_device_pg2.ControllerResetTO; | |
6980 | else | |
6981 | pcie_device->reset_timeout = 30; | |
c102e00c SPS |
6982 | |
6983 | if (ioc->wait_for_discovery_to_complete) | |
6984 | _scsih_pcie_device_init_add(ioc, pcie_device); | |
6985 | else | |
6986 | _scsih_pcie_device_add(ioc, pcie_device); | |
6987 | ||
6988 | pcie_device_put(pcie_device); | |
6989 | return 0; | |
6990 | } | |
4318c734 SPS |
6991 | |
6992 | /** | |
6993 | * _scsih_pcie_topology_change_event_debug - debug for topology | |
6994 | * event | |
6995 | * @ioc: per adapter object | |
6996 | * @event_data: event data payload | |
6997 | * Context: user. | |
6998 | */ | |
6999 | static void | |
7000 | _scsih_pcie_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
7001 | Mpi26EventDataPCIeTopologyChangeList_t *event_data) | |
7002 | { | |
7003 | int i; | |
7004 | u16 handle; | |
7005 | u16 reason_code; | |
7006 | u8 port_number; | |
7007 | char *status_str = NULL; | |
7008 | u8 link_rate, prev_link_rate; | |
7009 | ||
7010 | switch (event_data->SwitchStatus) { | |
7011 | case MPI26_EVENT_PCIE_TOPO_SS_ADDED: | |
7012 | status_str = "add"; | |
7013 | break; | |
7014 | case MPI26_EVENT_PCIE_TOPO_SS_NOT_RESPONDING: | |
7015 | status_str = "remove"; | |
7016 | break; | |
7017 | case MPI26_EVENT_PCIE_TOPO_SS_RESPONDING: | |
7018 | case 0: | |
7019 | status_str = "responding"; | |
7020 | break; | |
7021 | case MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING: | |
7022 | status_str = "remove delay"; | |
7023 | break; | |
7024 | default: | |
7025 | status_str = "unknown status"; | |
7026 | break; | |
7027 | } | |
7028 | pr_info(MPT3SAS_FMT "pcie topology change: (%s)\n", | |
7029 | ioc->name, status_str); | |
7030 | pr_info("\tswitch_handle(0x%04x), enclosure_handle(0x%04x)" | |
7031 | "start_port(%02d), count(%d)\n", | |
7032 | le16_to_cpu(event_data->SwitchDevHandle), | |
7033 | le16_to_cpu(event_data->EnclosureHandle), | |
7034 | event_data->StartPortNum, event_data->NumEntries); | |
7035 | for (i = 0; i < event_data->NumEntries; i++) { | |
7036 | handle = | |
7037 | le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle); | |
7038 | if (!handle) | |
7039 | continue; | |
7040 | port_number = event_data->StartPortNum + i; | |
7041 | reason_code = event_data->PortEntry[i].PortStatus; | |
7042 | switch (reason_code) { | |
7043 | case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED: | |
7044 | status_str = "target add"; | |
7045 | break; | |
7046 | case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING: | |
7047 | status_str = "target remove"; | |
7048 | break; | |
7049 | case MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING: | |
7050 | status_str = "delay target remove"; | |
7051 | break; | |
7052 | case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED: | |
7053 | status_str = "link rate change"; | |
7054 | break; | |
7055 | case MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE: | |
7056 | status_str = "target responding"; | |
7057 | break; | |
7058 | default: | |
7059 | status_str = "unknown"; | |
7060 | break; | |
7061 | } | |
7062 | link_rate = event_data->PortEntry[i].CurrentPortInfo & | |
7063 | MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK; | |
7064 | prev_link_rate = event_data->PortEntry[i].PreviousPortInfo & | |
7065 | MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK; | |
7066 | pr_info("\tport(%02d), attached_handle(0x%04x): %s:" | |
7067 | " link rate: new(0x%02x), old(0x%02x)\n", port_number, | |
7068 | handle, status_str, link_rate, prev_link_rate); | |
7069 | } | |
7070 | } | |
7071 | ||
7072 | /** | |
7073 | * _scsih_pcie_topology_change_event - handle PCIe topology | |
7074 | * changes | |
7075 | * @ioc: per adapter object | |
7076 | * @fw_event: The fw_event_work object | |
7077 | * Context: user. | |
7078 | * | |
7079 | */ | |
45b7aef7 | 7080 | static void |
4318c734 SPS |
7081 | _scsih_pcie_topology_change_event(struct MPT3SAS_ADAPTER *ioc, |
7082 | struct fw_event_work *fw_event) | |
7083 | { | |
7084 | int i; | |
7085 | u16 handle; | |
7086 | u16 reason_code; | |
7087 | u8 link_rate, prev_link_rate; | |
7088 | unsigned long flags; | |
7089 | int rc; | |
4318c734 SPS |
7090 | Mpi26EventDataPCIeTopologyChangeList_t *event_data = |
7091 | (Mpi26EventDataPCIeTopologyChangeList_t *) fw_event->event_data; | |
7092 | struct _pcie_device *pcie_device; | |
7093 | ||
7094 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) | |
7095 | _scsih_pcie_topology_change_event_debug(ioc, event_data); | |
7096 | ||
7097 | if (ioc->shost_recovery || ioc->remove_host || | |
7098 | ioc->pci_error_recovery) | |
45b7aef7 | 7099 | return; |
4318c734 SPS |
7100 | |
7101 | if (fw_event->ignore) { | |
7102 | dewtprintk(ioc, pr_info(MPT3SAS_FMT "ignoring switch event\n", | |
7103 | ioc->name)); | |
45b7aef7 | 7104 | return; |
4318c734 SPS |
7105 | } |
7106 | ||
7107 | /* handle siblings events */ | |
7108 | for (i = 0; i < event_data->NumEntries; i++) { | |
7109 | if (fw_event->ignore) { | |
7110 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7111 | "ignoring switch event\n", ioc->name)); | |
45b7aef7 | 7112 | return; |
4318c734 SPS |
7113 | } |
7114 | if (ioc->remove_host || ioc->pci_error_recovery) | |
45b7aef7 | 7115 | return; |
4318c734 SPS |
7116 | reason_code = event_data->PortEntry[i].PortStatus; |
7117 | handle = | |
7118 | le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle); | |
7119 | if (!handle) | |
7120 | continue; | |
7121 | ||
7122 | link_rate = event_data->PortEntry[i].CurrentPortInfo | |
7123 | & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK; | |
7124 | prev_link_rate = event_data->PortEntry[i].PreviousPortInfo | |
7125 | & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK; | |
7126 | ||
7127 | switch (reason_code) { | |
7128 | case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED: | |
7129 | if (ioc->shost_recovery) | |
7130 | break; | |
7131 | if (link_rate == prev_link_rate) | |
7132 | break; | |
7133 | if (link_rate < MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5) | |
7134 | break; | |
7135 | ||
7136 | _scsih_pcie_check_device(ioc, handle); | |
7137 | ||
7138 | /* This code after this point handles the test case | |
7139 | * where a device has been added, however its returning | |
7140 | * BUSY for sometime. Then before the Device Missing | |
7141 | * Delay expires and the device becomes READY, the | |
7142 | * device is removed and added back. | |
7143 | */ | |
7144 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
7145 | pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle); | |
7146 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
7147 | ||
7148 | if (pcie_device) { | |
7149 | pcie_device_put(pcie_device); | |
7150 | break; | |
7151 | } | |
7152 | ||
7153 | if (!test_bit(handle, ioc->pend_os_device_add)) | |
7154 | break; | |
7155 | ||
7156 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7157 | "handle(0x%04x) device not found: convert " | |
7158 | "event to a device add\n", ioc->name, handle)); | |
7159 | event_data->PortEntry[i].PortStatus &= 0xF0; | |
7160 | event_data->PortEntry[i].PortStatus |= | |
7161 | MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED; | |
7162 | case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED: | |
7163 | if (ioc->shost_recovery) | |
7164 | break; | |
7165 | if (link_rate < MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5) | |
7166 | break; | |
7167 | ||
7168 | rc = _scsih_pcie_add_device(ioc, handle); | |
7169 | if (!rc) { | |
7170 | /* mark entry vacant */ | |
7171 | /* TODO This needs to be reviewed and fixed, | |
7172 | * we dont have an entry | |
7173 | * to make an event void like vacant | |
7174 | */ | |
7175 | event_data->PortEntry[i].PortStatus |= | |
7176 | MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE; | |
7177 | } | |
7178 | break; | |
7179 | case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING: | |
7180 | _scsih_pcie_device_remove_by_handle(ioc, handle); | |
7181 | break; | |
7182 | } | |
7183 | } | |
4318c734 SPS |
7184 | } |
7185 | ||
7186 | /** | |
7187 | * _scsih_pcie_device_status_change_event_debug - debug for | |
7188 | * device event | |
7189 | * @event_data: event data payload | |
7190 | * Context: user. | |
7191 | * | |
7192 | * Return nothing. | |
7193 | */ | |
7194 | static void | |
7195 | _scsih_pcie_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
7196 | Mpi26EventDataPCIeDeviceStatusChange_t *event_data) | |
7197 | { | |
7198 | char *reason_str = NULL; | |
7199 | ||
7200 | switch (event_data->ReasonCode) { | |
7201 | case MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA: | |
7202 | reason_str = "smart data"; | |
7203 | break; | |
7204 | case MPI26_EVENT_PCIDEV_STAT_RC_UNSUPPORTED: | |
7205 | reason_str = "unsupported device discovered"; | |
7206 | break; | |
7207 | case MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET: | |
7208 | reason_str = "internal device reset"; | |
7209 | break; | |
7210 | case MPI26_EVENT_PCIDEV_STAT_RC_TASK_ABORT_INTERNAL: | |
7211 | reason_str = "internal task abort"; | |
7212 | break; | |
7213 | case MPI26_EVENT_PCIDEV_STAT_RC_ABORT_TASK_SET_INTERNAL: | |
7214 | reason_str = "internal task abort set"; | |
7215 | break; | |
7216 | case MPI26_EVENT_PCIDEV_STAT_RC_CLEAR_TASK_SET_INTERNAL: | |
7217 | reason_str = "internal clear task set"; | |
7218 | break; | |
7219 | case MPI26_EVENT_PCIDEV_STAT_RC_QUERY_TASK_INTERNAL: | |
7220 | reason_str = "internal query task"; | |
7221 | break; | |
7222 | case MPI26_EVENT_PCIDEV_STAT_RC_DEV_INIT_FAILURE: | |
7223 | reason_str = "device init failure"; | |
7224 | break; | |
7225 | case MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET: | |
7226 | reason_str = "internal device reset complete"; | |
7227 | break; | |
7228 | case MPI26_EVENT_PCIDEV_STAT_RC_CMP_TASK_ABORT_INTERNAL: | |
7229 | reason_str = "internal task abort complete"; | |
7230 | break; | |
7231 | case MPI26_EVENT_PCIDEV_STAT_RC_ASYNC_NOTIFICATION: | |
7232 | reason_str = "internal async notification"; | |
7233 | break; | |
c1a6c5ac C |
7234 | case MPI26_EVENT_PCIDEV_STAT_RC_PCIE_HOT_RESET_FAILED: |
7235 | reason_str = "pcie hot reset failed"; | |
7236 | break; | |
4318c734 SPS |
7237 | default: |
7238 | reason_str = "unknown reason"; | |
7239 | break; | |
7240 | } | |
7241 | ||
7242 | pr_info(MPT3SAS_FMT "PCIE device status change: (%s)\n" | |
7243 | "\thandle(0x%04x), WWID(0x%016llx), tag(%d)", | |
7244 | ioc->name, reason_str, le16_to_cpu(event_data->DevHandle), | |
7245 | (unsigned long long)le64_to_cpu(event_data->WWID), | |
7246 | le16_to_cpu(event_data->TaskTag)); | |
7247 | if (event_data->ReasonCode == MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA) | |
7248 | pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name, | |
7249 | event_data->ASC, event_data->ASCQ); | |
7250 | pr_info("\n"); | |
7251 | } | |
7252 | ||
7253 | /** | |
7254 | * _scsih_pcie_device_status_change_event - handle device status | |
7255 | * change | |
7256 | * @ioc: per adapter object | |
7257 | * @fw_event: The fw_event_work object | |
7258 | * Context: user. | |
7259 | * | |
7260 | * Return nothing. | |
7261 | */ | |
7262 | static void | |
7263 | _scsih_pcie_device_status_change_event(struct MPT3SAS_ADAPTER *ioc, | |
7264 | struct fw_event_work *fw_event) | |
7265 | { | |
7266 | struct MPT3SAS_TARGET *target_priv_data; | |
7267 | struct _pcie_device *pcie_device; | |
7268 | u64 wwid; | |
7269 | unsigned long flags; | |
7270 | Mpi26EventDataPCIeDeviceStatusChange_t *event_data = | |
7271 | (Mpi26EventDataPCIeDeviceStatusChange_t *)fw_event->event_data; | |
7272 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) | |
7273 | _scsih_pcie_device_status_change_event_debug(ioc, | |
7274 | event_data); | |
7275 | ||
7276 | if (event_data->ReasonCode != | |
7277 | MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET && | |
7278 | event_data->ReasonCode != | |
7279 | MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET) | |
7280 | return; | |
7281 | ||
7282 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
7283 | wwid = le64_to_cpu(event_data->WWID); | |
7284 | pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid); | |
7285 | ||
7286 | if (!pcie_device || !pcie_device->starget) | |
7287 | goto out; | |
7288 | ||
7289 | target_priv_data = pcie_device->starget->hostdata; | |
7290 | if (!target_priv_data) | |
7291 | goto out; | |
7292 | ||
7293 | if (event_data->ReasonCode == | |
7294 | MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET) | |
7295 | target_priv_data->tm_busy = 1; | |
7296 | else | |
7297 | target_priv_data->tm_busy = 0; | |
7298 | out: | |
7299 | if (pcie_device) | |
7300 | pcie_device_put(pcie_device); | |
7301 | ||
7302 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
7303 | } | |
7304 | ||
f92363d1 SR |
7305 | /** |
7306 | * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure | |
7307 | * event | |
7308 | * @ioc: per adapter object | |
7309 | * @event_data: event data payload | |
7310 | * Context: user. | |
7311 | * | |
7312 | * Return nothing. | |
7313 | */ | |
7314 | static void | |
7315 | _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
7316 | Mpi2EventDataSasEnclDevStatusChange_t *event_data) | |
7317 | { | |
7318 | char *reason_str = NULL; | |
7319 | ||
7320 | switch (event_data->ReasonCode) { | |
7321 | case MPI2_EVENT_SAS_ENCL_RC_ADDED: | |
7322 | reason_str = "enclosure add"; | |
7323 | break; | |
7324 | case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING: | |
7325 | reason_str = "enclosure remove"; | |
7326 | break; | |
7327 | default: | |
7328 | reason_str = "unknown reason"; | |
7329 | break; | |
7330 | } | |
7331 | ||
7332 | pr_info(MPT3SAS_FMT "enclosure status change: (%s)\n" | |
7333 | "\thandle(0x%04x), enclosure logical id(0x%016llx)" | |
7334 | " number slots(%d)\n", ioc->name, reason_str, | |
7335 | le16_to_cpu(event_data->EnclosureHandle), | |
7336 | (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID), | |
7337 | le16_to_cpu(event_data->StartSlot)); | |
7338 | } | |
f92363d1 SR |
7339 | |
7340 | /** | |
7341 | * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events | |
7342 | * @ioc: per adapter object | |
7343 | * @fw_event: The fw_event_work object | |
7344 | * Context: user. | |
7345 | * | |
7346 | * Return nothing. | |
7347 | */ | |
7348 | static void | |
7349 | _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc, | |
7350 | struct fw_event_work *fw_event) | |
7351 | { | |
22a923c3 C |
7352 | Mpi2ConfigReply_t mpi_reply; |
7353 | struct _enclosure_node *enclosure_dev = NULL; | |
7354 | Mpi2EventDataSasEnclDevStatusChange_t *event_data = | |
7355 | (Mpi2EventDataSasEnclDevStatusChange_t *)fw_event->event_data; | |
7356 | int rc; | |
7357 | u16 enclosure_handle = le16_to_cpu(event_data->EnclosureHandle); | |
7358 | ||
f92363d1 SR |
7359 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
7360 | _scsih_sas_enclosure_dev_status_change_event_debug(ioc, | |
35b62362 | 7361 | (Mpi2EventDataSasEnclDevStatusChange_t *) |
f92363d1 | 7362 | fw_event->event_data); |
22a923c3 C |
7363 | if (ioc->shost_recovery) |
7364 | return; | |
7365 | ||
7366 | if (enclosure_handle) | |
7367 | enclosure_dev = | |
7368 | mpt3sas_scsih_enclosure_find_by_handle(ioc, | |
7369 | enclosure_handle); | |
7370 | switch (event_data->ReasonCode) { | |
7371 | case MPI2_EVENT_SAS_ENCL_RC_ADDED: | |
7372 | if (!enclosure_dev) { | |
7373 | enclosure_dev = | |
7374 | kzalloc(sizeof(struct _enclosure_node), | |
7375 | GFP_KERNEL); | |
7376 | if (!enclosure_dev) { | |
7377 | pr_info(MPT3SAS_FMT | |
7378 | "failure at %s:%d/%s()!\n", ioc->name, | |
7379 | __FILE__, __LINE__, __func__); | |
7380 | return; | |
7381 | } | |
7382 | rc = mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
7383 | &enclosure_dev->pg0, | |
7384 | MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
7385 | enclosure_handle); | |
7386 | ||
7387 | if (rc || (le16_to_cpu(mpi_reply.IOCStatus) & | |
7388 | MPI2_IOCSTATUS_MASK)) { | |
7389 | kfree(enclosure_dev); | |
7390 | return; | |
7391 | } | |
7392 | ||
7393 | list_add_tail(&enclosure_dev->list, | |
7394 | &ioc->enclosure_list); | |
7395 | } | |
7396 | break; | |
7397 | case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING: | |
7398 | if (enclosure_dev) { | |
7399 | list_del(&enclosure_dev->list); | |
7400 | kfree(enclosure_dev); | |
7401 | } | |
7402 | break; | |
7403 | default: | |
7404 | break; | |
7405 | } | |
f92363d1 SR |
7406 | } |
7407 | ||
7408 | /** | |
7409 | * _scsih_sas_broadcast_primitive_event - handle broadcast events | |
7410 | * @ioc: per adapter object | |
7411 | * @fw_event: The fw_event_work object | |
7412 | * Context: user. | |
7413 | * | |
7414 | * Return nothing. | |
7415 | */ | |
7416 | static void | |
7417 | _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc, | |
7418 | struct fw_event_work *fw_event) | |
7419 | { | |
7420 | struct scsi_cmnd *scmd; | |
7421 | struct scsi_device *sdev; | |
6da999fe | 7422 | struct scsiio_tracker *st; |
f92363d1 SR |
7423 | u16 smid, handle; |
7424 | u32 lun; | |
7425 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
7426 | u32 termination_count; | |
7427 | u32 query_count; | |
7428 | Mpi2SCSITaskManagementReply_t *mpi_reply; | |
35b62362 JL |
7429 | Mpi2EventDataSasBroadcastPrimitive_t *event_data = |
7430 | (Mpi2EventDataSasBroadcastPrimitive_t *) | |
7431 | fw_event->event_data; | |
f92363d1 SR |
7432 | u16 ioc_status; |
7433 | unsigned long flags; | |
7434 | int r; | |
7435 | u8 max_retries = 0; | |
7436 | u8 task_abort_retries; | |
7437 | ||
7438 | mutex_lock(&ioc->tm_cmds.mutex); | |
7439 | pr_info(MPT3SAS_FMT | |
7440 | "%s: enter: phy number(%d), width(%d)\n", | |
7441 | ioc->name, __func__, event_data->PhyNum, | |
7442 | event_data->PortWidth); | |
7443 | ||
7444 | _scsih_block_io_all_device(ioc); | |
7445 | ||
7446 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7447 | mpi_reply = ioc->tm_cmds.reply; | |
7448 | broadcast_aen_retry: | |
7449 | ||
7450 | /* sanity checks for retrying this loop */ | |
7451 | if (max_retries++ == 5) { | |
7452 | dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: giving up\n", | |
7453 | ioc->name, __func__)); | |
7454 | goto out; | |
7455 | } else if (max_retries > 1) | |
7456 | dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: %d retry\n", | |
7457 | ioc->name, __func__, max_retries - 1)); | |
7458 | ||
7459 | termination_count = 0; | |
7460 | query_count = 0; | |
7461 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { | |
7462 | if (ioc->shost_recovery) | |
7463 | goto out; | |
dbec4c90 | 7464 | scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid); |
f92363d1 SR |
7465 | if (!scmd) |
7466 | continue; | |
dbec4c90 | 7467 | st = scsi_cmd_priv(scmd); |
f92363d1 SR |
7468 | sdev = scmd->device; |
7469 | sas_device_priv_data = sdev->hostdata; | |
7470 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) | |
7471 | continue; | |
7472 | /* skip hidden raid components */ | |
7473 | if (sas_device_priv_data->sas_target->flags & | |
7474 | MPT_TARGET_FLAGS_RAID_COMPONENT) | |
7475 | continue; | |
7476 | /* skip volumes */ | |
7477 | if (sas_device_priv_data->sas_target->flags & | |
7478 | MPT_TARGET_FLAGS_VOLUME) | |
7479 | continue; | |
999c8513 C |
7480 | /* skip PCIe devices */ |
7481 | if (sas_device_priv_data->sas_target->flags & | |
7482 | MPT_TARGET_FLAGS_PCIE_DEVICE) | |
7483 | continue; | |
f92363d1 SR |
7484 | |
7485 | handle = sas_device_priv_data->sas_target->handle; | |
7486 | lun = sas_device_priv_data->lun; | |
7487 | query_count++; | |
7488 | ||
7489 | if (ioc->shost_recovery) | |
7490 | goto out; | |
7491 | ||
7492 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
6da999fe | 7493 | r = mpt3sas_scsih_issue_tm(ioc, handle, lun, |
dbec4c90 | 7494 | MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, st->smid, |
c1a6c5ac | 7495 | st->msix_io, 30, 0); |
f92363d1 SR |
7496 | if (r == FAILED) { |
7497 | sdev_printk(KERN_WARNING, sdev, | |
7498 | "mpt3sas_scsih_issue_tm: FAILED when sending " | |
7499 | "QUERY_TASK: scmd(%p)\n", scmd); | |
7500 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7501 | goto broadcast_aen_retry; | |
7502 | } | |
7503 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) | |
7504 | & MPI2_IOCSTATUS_MASK; | |
7505 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
7506 | sdev_printk(KERN_WARNING, sdev, | |
7507 | "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n", | |
7508 | ioc_status, scmd); | |
7509 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7510 | goto broadcast_aen_retry; | |
7511 | } | |
7512 | ||
7513 | /* see if IO is still owned by IOC and target */ | |
7514 | if (mpi_reply->ResponseCode == | |
7515 | MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED || | |
7516 | mpi_reply->ResponseCode == | |
7517 | MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) { | |
7518 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7519 | continue; | |
7520 | } | |
7521 | task_abort_retries = 0; | |
7522 | tm_retry: | |
7523 | if (task_abort_retries++ == 60) { | |
7524 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7525 | "%s: ABORT_TASK: giving up\n", ioc->name, | |
7526 | __func__)); | |
7527 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7528 | goto broadcast_aen_retry; | |
7529 | } | |
7530 | ||
7531 | if (ioc->shost_recovery) | |
7532 | goto out_no_lock; | |
7533 | ||
6da999fe | 7534 | r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->lun, |
dbec4c90 | 7535 | MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, st->smid, |
c1a6c5ac | 7536 | st->msix_io, 30, 0); |
dbec4c90 | 7537 | if (r == FAILED || st->cb_idx != 0xFF) { |
f92363d1 SR |
7538 | sdev_printk(KERN_WARNING, sdev, |
7539 | "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : " | |
7540 | "scmd(%p)\n", scmd); | |
7541 | goto tm_retry; | |
7542 | } | |
7543 | ||
7544 | if (task_abort_retries > 1) | |
7545 | sdev_printk(KERN_WARNING, sdev, | |
7546 | "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):" | |
7547 | " scmd(%p)\n", | |
7548 | task_abort_retries - 1, scmd); | |
7549 | ||
7550 | termination_count += le32_to_cpu(mpi_reply->TerminationCount); | |
7551 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7552 | } | |
7553 | ||
7554 | if (ioc->broadcast_aen_pending) { | |
7555 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7556 | "%s: loop back due to pending AEN\n", | |
7557 | ioc->name, __func__)); | |
7558 | ioc->broadcast_aen_pending = 0; | |
7559 | goto broadcast_aen_retry; | |
7560 | } | |
7561 | ||
7562 | out: | |
7563 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
7564 | out_no_lock: | |
7565 | ||
7566 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7567 | "%s - exit, query_count = %d termination_count = %d\n", | |
7568 | ioc->name, __func__, query_count, termination_count)); | |
7569 | ||
7570 | ioc->broadcast_aen_busy = 0; | |
7571 | if (!ioc->shost_recovery) | |
7572 | _scsih_ublock_io_all_device(ioc); | |
7573 | mutex_unlock(&ioc->tm_cmds.mutex); | |
7574 | } | |
7575 | ||
7576 | /** | |
7577 | * _scsih_sas_discovery_event - handle discovery events | |
7578 | * @ioc: per adapter object | |
7579 | * @fw_event: The fw_event_work object | |
7580 | * Context: user. | |
7581 | * | |
7582 | * Return nothing. | |
7583 | */ | |
7584 | static void | |
7585 | _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc, | |
7586 | struct fw_event_work *fw_event) | |
7587 | { | |
35b62362 JL |
7588 | Mpi2EventDataSasDiscovery_t *event_data = |
7589 | (Mpi2EventDataSasDiscovery_t *) fw_event->event_data; | |
f92363d1 | 7590 | |
f92363d1 SR |
7591 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) { |
7592 | pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name, | |
7593 | (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ? | |
7594 | "start" : "stop"); | |
af009411 SR |
7595 | if (event_data->DiscoveryStatus) |
7596 | pr_info("discovery_status(0x%08x)", | |
7597 | le32_to_cpu(event_data->DiscoveryStatus)); | |
7598 | pr_info("\n"); | |
f92363d1 | 7599 | } |
f92363d1 SR |
7600 | |
7601 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED && | |
7602 | !ioc->sas_hba.num_phys) { | |
7603 | if (disable_discovery > 0 && ioc->shost_recovery) { | |
7604 | /* Wait for the reset to complete */ | |
7605 | while (ioc->shost_recovery) | |
7606 | ssleep(1); | |
7607 | } | |
7608 | _scsih_sas_host_add(ioc); | |
7609 | } | |
7610 | } | |
7611 | ||
95540b8e C |
7612 | /** |
7613 | * _scsih_sas_device_discovery_error_event - display SAS device discovery error | |
7614 | * events | |
7615 | * @ioc: per adapter object | |
7616 | * @fw_event: The fw_event_work object | |
7617 | * Context: user. | |
7618 | * | |
7619 | * Return nothing. | |
7620 | */ | |
7621 | static void | |
7622 | _scsih_sas_device_discovery_error_event(struct MPT3SAS_ADAPTER *ioc, | |
7623 | struct fw_event_work *fw_event) | |
7624 | { | |
7625 | Mpi25EventDataSasDeviceDiscoveryError_t *event_data = | |
7626 | (Mpi25EventDataSasDeviceDiscoveryError_t *)fw_event->event_data; | |
7627 | ||
7628 | switch (event_data->ReasonCode) { | |
7629 | case MPI25_EVENT_SAS_DISC_ERR_SMP_FAILED: | |
7630 | pr_warn(MPT3SAS_FMT "SMP command sent to the expander" | |
7631 | "(handle:0x%04x, sas_address:0x%016llx," | |
7632 | "physical_port:0x%02x) has failed", | |
7633 | ioc->name, le16_to_cpu(event_data->DevHandle), | |
7634 | (unsigned long long)le64_to_cpu(event_data->SASAddress), | |
7635 | event_data->PhysicalPort); | |
7636 | break; | |
7637 | case MPI25_EVENT_SAS_DISC_ERR_SMP_TIMEOUT: | |
7638 | pr_warn(MPT3SAS_FMT "SMP command sent to the expander" | |
7639 | "(handle:0x%04x, sas_address:0x%016llx," | |
7640 | "physical_port:0x%02x) has timed out", | |
7641 | ioc->name, le16_to_cpu(event_data->DevHandle), | |
7642 | (unsigned long long)le64_to_cpu(event_data->SASAddress), | |
7643 | event_data->PhysicalPort); | |
7644 | break; | |
7645 | default: | |
7646 | break; | |
7647 | } | |
7648 | } | |
7649 | ||
4318c734 SPS |
7650 | /** |
7651 | * _scsih_pcie_enumeration_event - handle enumeration events | |
7652 | * @ioc: per adapter object | |
7653 | * @fw_event: The fw_event_work object | |
7654 | * Context: user. | |
7655 | * | |
7656 | * Return nothing. | |
7657 | */ | |
7658 | static void | |
7659 | _scsih_pcie_enumeration_event(struct MPT3SAS_ADAPTER *ioc, | |
7660 | struct fw_event_work *fw_event) | |
7661 | { | |
7662 | Mpi26EventDataPCIeEnumeration_t *event_data = | |
7663 | (Mpi26EventDataPCIeEnumeration_t *)fw_event->event_data; | |
7664 | ||
6767aced DC |
7665 | if (!(ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)) |
7666 | return; | |
7667 | ||
7668 | pr_info(MPT3SAS_FMT "pcie enumeration event: (%s) Flag 0x%02x", | |
7669 | ioc->name, | |
7670 | (event_data->ReasonCode == MPI26_EVENT_PCIE_ENUM_RC_STARTED) ? | |
7671 | "started" : "completed", | |
7672 | event_data->Flags); | |
4318c734 | 7673 | if (event_data->EnumerationStatus) |
6767aced DC |
7674 | pr_cont("enumeration_status(0x%08x)", |
7675 | le32_to_cpu(event_data->EnumerationStatus)); | |
7676 | pr_cont("\n"); | |
4318c734 SPS |
7677 | } |
7678 | ||
f92363d1 SR |
7679 | /** |
7680 | * _scsih_ir_fastpath - turn on fastpath for IR physdisk | |
7681 | * @ioc: per adapter object | |
7682 | * @handle: device handle for physical disk | |
7683 | * @phys_disk_num: physical disk number | |
7684 | * | |
7685 | * Return 0 for success, else failure. | |
7686 | */ | |
7687 | static int | |
7688 | _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num) | |
7689 | { | |
7690 | Mpi2RaidActionRequest_t *mpi_request; | |
7691 | Mpi2RaidActionReply_t *mpi_reply; | |
7692 | u16 smid; | |
7693 | u8 issue_reset = 0; | |
7694 | int rc = 0; | |
7695 | u16 ioc_status; | |
7696 | u32 log_info; | |
7697 | ||
c84b06a4 SR |
7698 | if (ioc->hba_mpi_version_belonged == MPI2_VERSION) |
7699 | return rc; | |
7700 | ||
f92363d1 SR |
7701 | mutex_lock(&ioc->scsih_cmds.mutex); |
7702 | ||
7703 | if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) { | |
7704 | pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n", | |
7705 | ioc->name, __func__); | |
7706 | rc = -EAGAIN; | |
7707 | goto out; | |
7708 | } | |
7709 | ioc->scsih_cmds.status = MPT3_CMD_PENDING; | |
7710 | ||
7711 | smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx); | |
7712 | if (!smid) { | |
7713 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
7714 | ioc->name, __func__); | |
7715 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
7716 | rc = -EAGAIN; | |
7717 | goto out; | |
7718 | } | |
7719 | ||
7720 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
7721 | ioc->scsih_cmds.smid = smid; | |
7722 | memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t)); | |
7723 | ||
7724 | mpi_request->Function = MPI2_FUNCTION_RAID_ACTION; | |
7725 | mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN; | |
7726 | mpi_request->PhysDiskNum = phys_disk_num; | |
7727 | ||
7728 | dewtprintk(ioc, pr_info(MPT3SAS_FMT "IR RAID_ACTION: turning fast "\ | |
7729 | "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc->name, | |
7730 | handle, phys_disk_num)); | |
7731 | ||
7732 | init_completion(&ioc->scsih_cmds.done); | |
40114bde | 7733 | mpt3sas_base_put_smid_default(ioc, smid); |
f92363d1 SR |
7734 | wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ); |
7735 | ||
7736 | if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) { | |
d37306ca C |
7737 | issue_reset = |
7738 | mpt3sas_base_check_cmd_timeout(ioc, | |
7739 | ioc->scsih_cmds.status, mpi_request, | |
7740 | sizeof(Mpi2RaidActionRequest_t)/4); | |
f92363d1 SR |
7741 | rc = -EFAULT; |
7742 | goto out; | |
7743 | } | |
7744 | ||
7745 | if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) { | |
7746 | ||
7747 | mpi_reply = ioc->scsih_cmds.reply; | |
7748 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); | |
7749 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) | |
7750 | log_info = le32_to_cpu(mpi_reply->IOCLogInfo); | |
7751 | else | |
7752 | log_info = 0; | |
7753 | ioc_status &= MPI2_IOCSTATUS_MASK; | |
7754 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
7755 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7756 | "IR RAID_ACTION: failed: ioc_status(0x%04x), " | |
7757 | "loginfo(0x%08x)!!!\n", ioc->name, ioc_status, | |
7758 | log_info)); | |
7759 | rc = -EFAULT; | |
7760 | } else | |
7761 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7762 | "IR RAID_ACTION: completed successfully\n", | |
7763 | ioc->name)); | |
7764 | } | |
7765 | ||
7766 | out: | |
7767 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
7768 | mutex_unlock(&ioc->scsih_cmds.mutex); | |
7769 | ||
7770 | if (issue_reset) | |
98c56ad3 | 7771 | mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
f92363d1 SR |
7772 | return rc; |
7773 | } | |
7774 | ||
7775 | /** | |
7776 | * _scsih_reprobe_lun - reprobing lun | |
7777 | * @sdev: scsi device struct | |
7778 | * @no_uld_attach: sdev->no_uld_attach flag setting | |
7779 | * | |
7780 | **/ | |
7781 | static void | |
7782 | _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach) | |
7783 | { | |
f92363d1 SR |
7784 | sdev->no_uld_attach = no_uld_attach ? 1 : 0; |
7785 | sdev_printk(KERN_INFO, sdev, "%s raid component\n", | |
6c7abffc | 7786 | sdev->no_uld_attach ? "hiding" : "exposing"); |
8bbb1cf6 | 7787 | WARN_ON(scsi_device_reprobe(sdev)); |
f92363d1 SR |
7788 | } |
7789 | ||
7790 | /** | |
7791 | * _scsih_sas_volume_add - add new volume | |
7792 | * @ioc: per adapter object | |
7793 | * @element: IR config element data | |
7794 | * Context: user. | |
7795 | * | |
7796 | * Return nothing. | |
7797 | */ | |
7798 | static void | |
7799 | _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc, | |
7800 | Mpi2EventIrConfigElement_t *element) | |
7801 | { | |
7802 | struct _raid_device *raid_device; | |
7803 | unsigned long flags; | |
7804 | u64 wwid; | |
7805 | u16 handle = le16_to_cpu(element->VolDevHandle); | |
7806 | int rc; | |
7807 | ||
7808 | mpt3sas_config_get_volume_wwid(ioc, handle, &wwid); | |
7809 | if (!wwid) { | |
7810 | pr_err(MPT3SAS_FMT | |
7811 | "failure at %s:%d/%s()!\n", ioc->name, | |
7812 | __FILE__, __LINE__, __func__); | |
7813 | return; | |
7814 | } | |
7815 | ||
7816 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
7817 | raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid); | |
7818 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
7819 | ||
7820 | if (raid_device) | |
7821 | return; | |
7822 | ||
7823 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); | |
7824 | if (!raid_device) { | |
7825 | pr_err(MPT3SAS_FMT | |
7826 | "failure at %s:%d/%s()!\n", ioc->name, | |
7827 | __FILE__, __LINE__, __func__); | |
7828 | return; | |
7829 | } | |
7830 | ||
7831 | raid_device->id = ioc->sas_id++; | |
7832 | raid_device->channel = RAID_CHANNEL; | |
7833 | raid_device->handle = handle; | |
7834 | raid_device->wwid = wwid; | |
7835 | _scsih_raid_device_add(ioc, raid_device); | |
7836 | if (!ioc->wait_for_discovery_to_complete) { | |
7837 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
7838 | raid_device->id, 0); | |
7839 | if (rc) | |
7840 | _scsih_raid_device_remove(ioc, raid_device); | |
7841 | } else { | |
7842 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
7843 | _scsih_determine_boot_device(ioc, raid_device, 1); | |
7844 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
7845 | } | |
7846 | } | |
7847 | ||
7848 | /** | |
7849 | * _scsih_sas_volume_delete - delete volume | |
7850 | * @ioc: per adapter object | |
7851 | * @handle: volume device handle | |
7852 | * Context: user. | |
7853 | * | |
7854 | * Return nothing. | |
7855 | */ | |
7856 | static void | |
7857 | _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
7858 | { | |
7859 | struct _raid_device *raid_device; | |
7860 | unsigned long flags; | |
7861 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
7862 | struct scsi_target *starget = NULL; | |
7863 | ||
7864 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
c84b06a4 | 7865 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
7866 | if (raid_device) { |
7867 | if (raid_device->starget) { | |
7868 | starget = raid_device->starget; | |
7869 | sas_target_priv_data = starget->hostdata; | |
7870 | sas_target_priv_data->deleted = 1; | |
7871 | } | |
7872 | pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n", | |
7873 | ioc->name, raid_device->handle, | |
7874 | (unsigned long long) raid_device->wwid); | |
7875 | list_del(&raid_device->list); | |
7876 | kfree(raid_device); | |
7877 | } | |
7878 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
7879 | if (starget) | |
7880 | scsi_remove_target(&starget->dev); | |
7881 | } | |
7882 | ||
7883 | /** | |
7884 | * _scsih_sas_pd_expose - expose pd component to /dev/sdX | |
7885 | * @ioc: per adapter object | |
7886 | * @element: IR config element data | |
7887 | * Context: user. | |
7888 | * | |
7889 | * Return nothing. | |
7890 | */ | |
7891 | static void | |
7892 | _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc, | |
7893 | Mpi2EventIrConfigElement_t *element) | |
7894 | { | |
7895 | struct _sas_device *sas_device; | |
7896 | struct scsi_target *starget = NULL; | |
7897 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
7898 | unsigned long flags; | |
7899 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | |
7900 | ||
7901 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 | 7902 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
7903 | if (sas_device) { |
7904 | sas_device->volume_handle = 0; | |
7905 | sas_device->volume_wwid = 0; | |
7906 | clear_bit(handle, ioc->pd_handles); | |
7907 | if (sas_device->starget && sas_device->starget->hostdata) { | |
7908 | starget = sas_device->starget; | |
7909 | sas_target_priv_data = starget->hostdata; | |
7910 | sas_target_priv_data->flags &= | |
7911 | ~MPT_TARGET_FLAGS_RAID_COMPONENT; | |
7912 | } | |
7913 | } | |
7914 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
7915 | if (!sas_device) | |
7916 | return; | |
7917 | ||
7918 | /* exposing raid component */ | |
7919 | if (starget) | |
7920 | starget_for_each_device(starget, NULL, _scsih_reprobe_lun); | |
d1cb5e49 SR |
7921 | |
7922 | sas_device_put(sas_device); | |
f92363d1 SR |
7923 | } |
7924 | ||
7925 | /** | |
7926 | * _scsih_sas_pd_hide - hide pd component from /dev/sdX | |
7927 | * @ioc: per adapter object | |
7928 | * @element: IR config element data | |
7929 | * Context: user. | |
7930 | * | |
7931 | * Return nothing. | |
7932 | */ | |
7933 | static void | |
7934 | _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc, | |
7935 | Mpi2EventIrConfigElement_t *element) | |
7936 | { | |
7937 | struct _sas_device *sas_device; | |
7938 | struct scsi_target *starget = NULL; | |
7939 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
7940 | unsigned long flags; | |
7941 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | |
7942 | u16 volume_handle = 0; | |
7943 | u64 volume_wwid = 0; | |
7944 | ||
7945 | mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle); | |
7946 | if (volume_handle) | |
7947 | mpt3sas_config_get_volume_wwid(ioc, volume_handle, | |
7948 | &volume_wwid); | |
7949 | ||
7950 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 | 7951 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
7952 | if (sas_device) { |
7953 | set_bit(handle, ioc->pd_handles); | |
7954 | if (sas_device->starget && sas_device->starget->hostdata) { | |
7955 | starget = sas_device->starget; | |
7956 | sas_target_priv_data = starget->hostdata; | |
7957 | sas_target_priv_data->flags |= | |
7958 | MPT_TARGET_FLAGS_RAID_COMPONENT; | |
7959 | sas_device->volume_handle = volume_handle; | |
7960 | sas_device->volume_wwid = volume_wwid; | |
7961 | } | |
7962 | } | |
7963 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
7964 | if (!sas_device) | |
7965 | return; | |
7966 | ||
7967 | /* hiding raid component */ | |
7968 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); | |
c84b06a4 | 7969 | |
f92363d1 SR |
7970 | if (starget) |
7971 | starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun); | |
d1cb5e49 SR |
7972 | |
7973 | sas_device_put(sas_device); | |
f92363d1 SR |
7974 | } |
7975 | ||
7976 | /** | |
7977 | * _scsih_sas_pd_delete - delete pd component | |
7978 | * @ioc: per adapter object | |
7979 | * @element: IR config element data | |
7980 | * Context: user. | |
7981 | * | |
7982 | * Return nothing. | |
7983 | */ | |
7984 | static void | |
7985 | _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc, | |
7986 | Mpi2EventIrConfigElement_t *element) | |
7987 | { | |
7988 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | |
7989 | ||
7990 | _scsih_device_remove_by_handle(ioc, handle); | |
7991 | } | |
7992 | ||
7993 | /** | |
7994 | * _scsih_sas_pd_add - remove pd component | |
7995 | * @ioc: per adapter object | |
7996 | * @element: IR config element data | |
7997 | * Context: user. | |
7998 | * | |
7999 | * Return nothing. | |
8000 | */ | |
8001 | static void | |
8002 | _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc, | |
8003 | Mpi2EventIrConfigElement_t *element) | |
8004 | { | |
8005 | struct _sas_device *sas_device; | |
f92363d1 SR |
8006 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
8007 | Mpi2ConfigReply_t mpi_reply; | |
8008 | Mpi2SasDevicePage0_t sas_device_pg0; | |
8009 | u32 ioc_status; | |
8010 | u64 sas_address; | |
8011 | u16 parent_handle; | |
8012 | ||
8013 | set_bit(handle, ioc->pd_handles); | |
8014 | ||
d1cb5e49 | 8015 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
8016 | if (sas_device) { |
8017 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); | |
d1cb5e49 | 8018 | sas_device_put(sas_device); |
f92363d1 SR |
8019 | return; |
8020 | } | |
8021 | ||
8022 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
8023 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
8024 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
8025 | ioc->name, __FILE__, __LINE__, __func__); | |
8026 | return; | |
8027 | } | |
8028 | ||
8029 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8030 | MPI2_IOCSTATUS_MASK; | |
8031 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
8032 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
8033 | ioc->name, __FILE__, __LINE__, __func__); | |
8034 | return; | |
8035 | } | |
8036 | ||
8037 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | |
8038 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) | |
8039 | mpt3sas_transport_update_links(ioc, sas_address, handle, | |
8040 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | |
8041 | ||
8042 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); | |
8043 | _scsih_add_device(ioc, handle, 0, 1); | |
8044 | } | |
8045 | ||
f92363d1 SR |
8046 | /** |
8047 | * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events | |
8048 | * @ioc: per adapter object | |
8049 | * @event_data: event data payload | |
8050 | * Context: user. | |
8051 | * | |
8052 | * Return nothing. | |
8053 | */ | |
8054 | static void | |
8055 | _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
8056 | Mpi2EventDataIrConfigChangeList_t *event_data) | |
8057 | { | |
8058 | Mpi2EventIrConfigElement_t *element; | |
8059 | u8 element_type; | |
8060 | int i; | |
8061 | char *reason_str = NULL, *element_str = NULL; | |
8062 | ||
8063 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
8064 | ||
8065 | pr_info(MPT3SAS_FMT "raid config change: (%s), elements(%d)\n", | |
8066 | ioc->name, (le32_to_cpu(event_data->Flags) & | |
8067 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? | |
8068 | "foreign" : "native", event_data->NumElements); | |
8069 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
8070 | switch (element->ReasonCode) { | |
8071 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: | |
8072 | reason_str = "add"; | |
8073 | break; | |
8074 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: | |
8075 | reason_str = "remove"; | |
8076 | break; | |
8077 | case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE: | |
8078 | reason_str = "no change"; | |
8079 | break; | |
8080 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: | |
8081 | reason_str = "hide"; | |
8082 | break; | |
8083 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: | |
8084 | reason_str = "unhide"; | |
8085 | break; | |
8086 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: | |
8087 | reason_str = "volume_created"; | |
8088 | break; | |
8089 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: | |
8090 | reason_str = "volume_deleted"; | |
8091 | break; | |
8092 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: | |
8093 | reason_str = "pd_created"; | |
8094 | break; | |
8095 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: | |
8096 | reason_str = "pd_deleted"; | |
8097 | break; | |
8098 | default: | |
8099 | reason_str = "unknown reason"; | |
8100 | break; | |
8101 | } | |
8102 | element_type = le16_to_cpu(element->ElementFlags) & | |
8103 | MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK; | |
8104 | switch (element_type) { | |
8105 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT: | |
8106 | element_str = "volume"; | |
8107 | break; | |
8108 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT: | |
8109 | element_str = "phys disk"; | |
8110 | break; | |
8111 | case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT: | |
8112 | element_str = "hot spare"; | |
8113 | break; | |
8114 | default: | |
8115 | element_str = "unknown element"; | |
8116 | break; | |
8117 | } | |
8118 | pr_info("\t(%s:%s), vol handle(0x%04x), " \ | |
8119 | "pd handle(0x%04x), pd num(0x%02x)\n", element_str, | |
8120 | reason_str, le16_to_cpu(element->VolDevHandle), | |
8121 | le16_to_cpu(element->PhysDiskDevHandle), | |
8122 | element->PhysDiskNum); | |
8123 | } | |
8124 | } | |
f92363d1 SR |
8125 | |
8126 | /** | |
8127 | * _scsih_sas_ir_config_change_event - handle ir configuration change events | |
8128 | * @ioc: per adapter object | |
8129 | * @fw_event: The fw_event_work object | |
8130 | * Context: user. | |
8131 | * | |
8132 | * Return nothing. | |
8133 | */ | |
8134 | static void | |
8135 | _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc, | |
8136 | struct fw_event_work *fw_event) | |
8137 | { | |
8138 | Mpi2EventIrConfigElement_t *element; | |
8139 | int i; | |
8140 | u8 foreign_config; | |
35b62362 JL |
8141 | Mpi2EventDataIrConfigChangeList_t *event_data = |
8142 | (Mpi2EventDataIrConfigChangeList_t *) | |
8143 | fw_event->event_data; | |
f92363d1 | 8144 | |
7786ab6a SR |
8145 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) && |
8146 | (!ioc->hide_ir_msg)) | |
f92363d1 SR |
8147 | _scsih_sas_ir_config_change_event_debug(ioc, event_data); |
8148 | ||
f92363d1 SR |
8149 | foreign_config = (le32_to_cpu(event_data->Flags) & |
8150 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0; | |
8151 | ||
8152 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
c84b06a4 SR |
8153 | if (ioc->shost_recovery && |
8154 | ioc->hba_mpi_version_belonged != MPI2_VERSION) { | |
f92363d1 SR |
8155 | for (i = 0; i < event_data->NumElements; i++, element++) { |
8156 | if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE) | |
8157 | _scsih_ir_fastpath(ioc, | |
8158 | le16_to_cpu(element->PhysDiskDevHandle), | |
8159 | element->PhysDiskNum); | |
8160 | } | |
8161 | return; | |
8162 | } | |
7786ab6a | 8163 | |
f92363d1 SR |
8164 | for (i = 0; i < event_data->NumElements; i++, element++) { |
8165 | ||
8166 | switch (element->ReasonCode) { | |
8167 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: | |
8168 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: | |
8169 | if (!foreign_config) | |
8170 | _scsih_sas_volume_add(ioc, element); | |
8171 | break; | |
8172 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: | |
8173 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: | |
8174 | if (!foreign_config) | |
8175 | _scsih_sas_volume_delete(ioc, | |
8176 | le16_to_cpu(element->VolDevHandle)); | |
8177 | break; | |
8178 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: | |
7786ab6a SR |
8179 | if (!ioc->is_warpdrive) |
8180 | _scsih_sas_pd_hide(ioc, element); | |
f92363d1 SR |
8181 | break; |
8182 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: | |
7786ab6a SR |
8183 | if (!ioc->is_warpdrive) |
8184 | _scsih_sas_pd_expose(ioc, element); | |
f92363d1 SR |
8185 | break; |
8186 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: | |
7786ab6a SR |
8187 | if (!ioc->is_warpdrive) |
8188 | _scsih_sas_pd_add(ioc, element); | |
f92363d1 SR |
8189 | break; |
8190 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: | |
7786ab6a SR |
8191 | if (!ioc->is_warpdrive) |
8192 | _scsih_sas_pd_delete(ioc, element); | |
f92363d1 SR |
8193 | break; |
8194 | } | |
8195 | } | |
8196 | } | |
8197 | ||
8198 | /** | |
8199 | * _scsih_sas_ir_volume_event - IR volume event | |
8200 | * @ioc: per adapter object | |
8201 | * @fw_event: The fw_event_work object | |
8202 | * Context: user. | |
8203 | * | |
8204 | * Return nothing. | |
8205 | */ | |
8206 | static void | |
8207 | _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc, | |
8208 | struct fw_event_work *fw_event) | |
8209 | { | |
8210 | u64 wwid; | |
8211 | unsigned long flags; | |
8212 | struct _raid_device *raid_device; | |
8213 | u16 handle; | |
8214 | u32 state; | |
8215 | int rc; | |
35b62362 JL |
8216 | Mpi2EventDataIrVolume_t *event_data = |
8217 | (Mpi2EventDataIrVolume_t *) fw_event->event_data; | |
f92363d1 SR |
8218 | |
8219 | if (ioc->shost_recovery) | |
8220 | return; | |
8221 | ||
8222 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) | |
8223 | return; | |
8224 | ||
8225 | handle = le16_to_cpu(event_data->VolDevHandle); | |
8226 | state = le32_to_cpu(event_data->NewValue); | |
7786ab6a SR |
8227 | if (!ioc->hide_ir_msg) |
8228 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
8229 | "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n", | |
8230 | ioc->name, __func__, handle, | |
8231 | le32_to_cpu(event_data->PreviousValue), state)); | |
f92363d1 SR |
8232 | switch (state) { |
8233 | case MPI2_RAID_VOL_STATE_MISSING: | |
8234 | case MPI2_RAID_VOL_STATE_FAILED: | |
8235 | _scsih_sas_volume_delete(ioc, handle); | |
8236 | break; | |
8237 | ||
8238 | case MPI2_RAID_VOL_STATE_ONLINE: | |
8239 | case MPI2_RAID_VOL_STATE_DEGRADED: | |
8240 | case MPI2_RAID_VOL_STATE_OPTIMAL: | |
8241 | ||
8242 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
c84b06a4 | 8243 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
8244 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
8245 | ||
8246 | if (raid_device) | |
8247 | break; | |
8248 | ||
8249 | mpt3sas_config_get_volume_wwid(ioc, handle, &wwid); | |
8250 | if (!wwid) { | |
8251 | pr_err(MPT3SAS_FMT | |
8252 | "failure at %s:%d/%s()!\n", ioc->name, | |
8253 | __FILE__, __LINE__, __func__); | |
8254 | break; | |
8255 | } | |
8256 | ||
8257 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); | |
8258 | if (!raid_device) { | |
8259 | pr_err(MPT3SAS_FMT | |
8260 | "failure at %s:%d/%s()!\n", ioc->name, | |
8261 | __FILE__, __LINE__, __func__); | |
8262 | break; | |
8263 | } | |
8264 | ||
8265 | raid_device->id = ioc->sas_id++; | |
8266 | raid_device->channel = RAID_CHANNEL; | |
8267 | raid_device->handle = handle; | |
8268 | raid_device->wwid = wwid; | |
8269 | _scsih_raid_device_add(ioc, raid_device); | |
8270 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
8271 | raid_device->id, 0); | |
8272 | if (rc) | |
8273 | _scsih_raid_device_remove(ioc, raid_device); | |
8274 | break; | |
8275 | ||
8276 | case MPI2_RAID_VOL_STATE_INITIALIZING: | |
8277 | default: | |
8278 | break; | |
8279 | } | |
8280 | } | |
8281 | ||
8282 | /** | |
8283 | * _scsih_sas_ir_physical_disk_event - PD event | |
8284 | * @ioc: per adapter object | |
8285 | * @fw_event: The fw_event_work object | |
8286 | * Context: user. | |
8287 | * | |
8288 | * Return nothing. | |
8289 | */ | |
8290 | static void | |
8291 | _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc, | |
8292 | struct fw_event_work *fw_event) | |
8293 | { | |
8294 | u16 handle, parent_handle; | |
8295 | u32 state; | |
8296 | struct _sas_device *sas_device; | |
f92363d1 SR |
8297 | Mpi2ConfigReply_t mpi_reply; |
8298 | Mpi2SasDevicePage0_t sas_device_pg0; | |
8299 | u32 ioc_status; | |
35b62362 JL |
8300 | Mpi2EventDataIrPhysicalDisk_t *event_data = |
8301 | (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data; | |
f92363d1 SR |
8302 | u64 sas_address; |
8303 | ||
8304 | if (ioc->shost_recovery) | |
8305 | return; | |
8306 | ||
8307 | if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED) | |
8308 | return; | |
8309 | ||
8310 | handle = le16_to_cpu(event_data->PhysDiskDevHandle); | |
8311 | state = le32_to_cpu(event_data->NewValue); | |
8312 | ||
7786ab6a SR |
8313 | if (!ioc->hide_ir_msg) |
8314 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
8315 | "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n", | |
8316 | ioc->name, __func__, handle, | |
f92363d1 | 8317 | le32_to_cpu(event_data->PreviousValue), state)); |
7786ab6a | 8318 | |
f92363d1 SR |
8319 | switch (state) { |
8320 | case MPI2_RAID_PD_STATE_ONLINE: | |
8321 | case MPI2_RAID_PD_STATE_DEGRADED: | |
8322 | case MPI2_RAID_PD_STATE_REBUILDING: | |
8323 | case MPI2_RAID_PD_STATE_OPTIMAL: | |
8324 | case MPI2_RAID_PD_STATE_HOT_SPARE: | |
8325 | ||
7786ab6a SR |
8326 | if (!ioc->is_warpdrive) |
8327 | set_bit(handle, ioc->pd_handles); | |
f92363d1 | 8328 | |
d1cb5e49 SR |
8329 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
8330 | if (sas_device) { | |
8331 | sas_device_put(sas_device); | |
f92363d1 | 8332 | return; |
d1cb5e49 | 8333 | } |
f92363d1 SR |
8334 | |
8335 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
8336 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | |
8337 | handle))) { | |
8338 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
8339 | ioc->name, __FILE__, __LINE__, __func__); | |
8340 | return; | |
8341 | } | |
8342 | ||
8343 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8344 | MPI2_IOCSTATUS_MASK; | |
8345 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
8346 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
8347 | ioc->name, __FILE__, __LINE__, __func__); | |
8348 | return; | |
8349 | } | |
8350 | ||
8351 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | |
8352 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) | |
8353 | mpt3sas_transport_update_links(ioc, sas_address, handle, | |
8354 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | |
8355 | ||
8356 | _scsih_add_device(ioc, handle, 0, 1); | |
8357 | ||
8358 | break; | |
8359 | ||
8360 | case MPI2_RAID_PD_STATE_OFFLINE: | |
8361 | case MPI2_RAID_PD_STATE_NOT_CONFIGURED: | |
8362 | case MPI2_RAID_PD_STATE_NOT_COMPATIBLE: | |
8363 | default: | |
8364 | break; | |
8365 | } | |
8366 | } | |
8367 | ||
f92363d1 SR |
8368 | /** |
8369 | * _scsih_sas_ir_operation_status_event_debug - debug for IR op event | |
8370 | * @ioc: per adapter object | |
8371 | * @event_data: event data payload | |
8372 | * Context: user. | |
8373 | * | |
8374 | * Return nothing. | |
8375 | */ | |
8376 | static void | |
8377 | _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
8378 | Mpi2EventDataIrOperationStatus_t *event_data) | |
8379 | { | |
8380 | char *reason_str = NULL; | |
8381 | ||
8382 | switch (event_data->RAIDOperation) { | |
8383 | case MPI2_EVENT_IR_RAIDOP_RESYNC: | |
8384 | reason_str = "resync"; | |
8385 | break; | |
8386 | case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION: | |
8387 | reason_str = "online capacity expansion"; | |
8388 | break; | |
8389 | case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK: | |
8390 | reason_str = "consistency check"; | |
8391 | break; | |
8392 | case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT: | |
8393 | reason_str = "background init"; | |
8394 | break; | |
8395 | case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT: | |
8396 | reason_str = "make data consistent"; | |
8397 | break; | |
8398 | } | |
8399 | ||
8400 | if (!reason_str) | |
8401 | return; | |
8402 | ||
8403 | pr_info(MPT3SAS_FMT "raid operational status: (%s)" \ | |
8404 | "\thandle(0x%04x), percent complete(%d)\n", | |
8405 | ioc->name, reason_str, | |
8406 | le16_to_cpu(event_data->VolDevHandle), | |
8407 | event_data->PercentComplete); | |
8408 | } | |
f92363d1 SR |
8409 | |
8410 | /** | |
8411 | * _scsih_sas_ir_operation_status_event - handle RAID operation events | |
8412 | * @ioc: per adapter object | |
8413 | * @fw_event: The fw_event_work object | |
8414 | * Context: user. | |
8415 | * | |
8416 | * Return nothing. | |
8417 | */ | |
8418 | static void | |
8419 | _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc, | |
8420 | struct fw_event_work *fw_event) | |
8421 | { | |
35b62362 JL |
8422 | Mpi2EventDataIrOperationStatus_t *event_data = |
8423 | (Mpi2EventDataIrOperationStatus_t *) | |
8424 | fw_event->event_data; | |
f92363d1 SR |
8425 | static struct _raid_device *raid_device; |
8426 | unsigned long flags; | |
8427 | u16 handle; | |
8428 | ||
7786ab6a SR |
8429 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) && |
8430 | (!ioc->hide_ir_msg)) | |
f92363d1 SR |
8431 | _scsih_sas_ir_operation_status_event_debug(ioc, |
8432 | event_data); | |
f92363d1 SR |
8433 | |
8434 | /* code added for raid transport support */ | |
8435 | if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) { | |
8436 | ||
8437 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
8438 | handle = le16_to_cpu(event_data->VolDevHandle); | |
c84b06a4 | 8439 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
8440 | if (raid_device) |
8441 | raid_device->percent_complete = | |
8442 | event_data->PercentComplete; | |
8443 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
8444 | } | |
8445 | } | |
8446 | ||
8447 | /** | |
8448 | * _scsih_prep_device_scan - initialize parameters prior to device scan | |
8449 | * @ioc: per adapter object | |
8450 | * | |
8451 | * Set the deleted flag prior to device scan. If the device is found during | |
8452 | * the scan, then we clear the deleted flag. | |
8453 | */ | |
8454 | static void | |
8455 | _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc) | |
8456 | { | |
8457 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
8458 | struct scsi_device *sdev; | |
8459 | ||
8460 | shost_for_each_device(sdev, ioc->shost) { | |
8461 | sas_device_priv_data = sdev->hostdata; | |
8462 | if (sas_device_priv_data && sas_device_priv_data->sas_target) | |
8463 | sas_device_priv_data->sas_target->deleted = 1; | |
8464 | } | |
8465 | } | |
8466 | ||
8467 | /** | |
8468 | * _scsih_mark_responding_sas_device - mark a sas_devices as responding | |
8469 | * @ioc: per adapter object | |
e6d45e3e | 8470 | * @sas_device_pg0: SAS Device page 0 |
f92363d1 SR |
8471 | * |
8472 | * After host reset, find out whether devices are still responding. | |
8473 | * Used in _scsih_remove_unresponsive_sas_devices. | |
8474 | * | |
8475 | * Return nothing. | |
8476 | */ | |
8477 | static void | |
e6d45e3e SR |
8478 | _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc, |
8479 | Mpi2SasDevicePage0_t *sas_device_pg0) | |
f92363d1 SR |
8480 | { |
8481 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; | |
8482 | struct scsi_target *starget; | |
aba5a85c | 8483 | struct _sas_device *sas_device = NULL; |
22a923c3 | 8484 | struct _enclosure_node *enclosure_dev = NULL; |
f92363d1 SR |
8485 | unsigned long flags; |
8486 | ||
22a923c3 C |
8487 | if (sas_device_pg0->EnclosureHandle) { |
8488 | enclosure_dev = | |
8489 | mpt3sas_scsih_enclosure_find_by_handle(ioc, | |
8490 | le16_to_cpu(sas_device_pg0->EnclosureHandle)); | |
8491 | if (enclosure_dev == NULL) | |
8492 | pr_info(MPT3SAS_FMT "Enclosure handle(0x%04x)" | |
8493 | "doesn't match with enclosure device!\n", | |
8494 | ioc->name, sas_device_pg0->EnclosureHandle); | |
8495 | } | |
f92363d1 SR |
8496 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
8497 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) { | |
cf6bf971 C |
8498 | if ((sas_device->sas_address == le64_to_cpu( |
8499 | sas_device_pg0->SASAddress)) && (sas_device->slot == | |
8500 | le16_to_cpu(sas_device_pg0->Slot))) { | |
f92363d1 SR |
8501 | sas_device->responding = 1; |
8502 | starget = sas_device->starget; | |
8503 | if (starget && starget->hostdata) { | |
8504 | sas_target_priv_data = starget->hostdata; | |
8505 | sas_target_priv_data->tm_busy = 0; | |
8506 | sas_target_priv_data->deleted = 0; | |
8507 | } else | |
8508 | sas_target_priv_data = NULL; | |
e6d45e3e | 8509 | if (starget) { |
f92363d1 | 8510 | starget_printk(KERN_INFO, starget, |
e6d45e3e | 8511 | "handle(0x%04x), sas_addr(0x%016llx)\n", |
cf6bf971 | 8512 | le16_to_cpu(sas_device_pg0->DevHandle), |
f92363d1 | 8513 | (unsigned long long) |
e6d45e3e SR |
8514 | sas_device->sas_address); |
8515 | ||
8516 | if (sas_device->enclosure_handle != 0) | |
8517 | starget_printk(KERN_INFO, starget, | |
8518 | "enclosure logical id(0x%016llx)," | |
8519 | " slot(%d)\n", | |
8520 | (unsigned long long) | |
8521 | sas_device->enclosure_logical_id, | |
8522 | sas_device->slot); | |
8523 | } | |
cf6bf971 | 8524 | if (le16_to_cpu(sas_device_pg0->Flags) & |
e6d45e3e SR |
8525 | MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) { |
8526 | sas_device->enclosure_level = | |
aa53bb89 | 8527 | sas_device_pg0->EnclosureLevel; |
e6d45e3e SR |
8528 | memcpy(&sas_device->connector_name[0], |
8529 | &sas_device_pg0->ConnectorName[0], 4); | |
8530 | } else { | |
8531 | sas_device->enclosure_level = 0; | |
8532 | sas_device->connector_name[0] = '\0'; | |
8533 | } | |
8534 | ||
22a923c3 C |
8535 | sas_device->enclosure_handle = |
8536 | le16_to_cpu(sas_device_pg0->EnclosureHandle); | |
8537 | sas_device->is_chassis_slot_valid = 0; | |
8538 | if (enclosure_dev) { | |
8539 | sas_device->enclosure_logical_id = le64_to_cpu( | |
8540 | enclosure_dev->pg0.EnclosureLogicalID); | |
8541 | if (le16_to_cpu(enclosure_dev->pg0.Flags) & | |
8542 | MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) { | |
8543 | sas_device->is_chassis_slot_valid = 1; | |
8544 | sas_device->chassis_slot = | |
8545 | enclosure_dev->pg0.ChassisSlot; | |
8546 | } | |
8547 | } | |
75888956 | 8548 | |
cf6bf971 C |
8549 | if (sas_device->handle == le16_to_cpu( |
8550 | sas_device_pg0->DevHandle)) | |
f92363d1 SR |
8551 | goto out; |
8552 | pr_info("\thandle changed from(0x%04x)!!!\n", | |
8553 | sas_device->handle); | |
cf6bf971 C |
8554 | sas_device->handle = le16_to_cpu( |
8555 | sas_device_pg0->DevHandle); | |
f92363d1 | 8556 | if (sas_target_priv_data) |
e6d45e3e | 8557 | sas_target_priv_data->handle = |
cf6bf971 | 8558 | le16_to_cpu(sas_device_pg0->DevHandle); |
f92363d1 SR |
8559 | goto out; |
8560 | } | |
8561 | } | |
8562 | out: | |
8563 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
8564 | } | |
8565 | ||
22a923c3 C |
8566 | /** |
8567 | * _scsih_create_enclosure_list_after_reset - Free Existing list, | |
8568 | * And create enclosure list by scanning all Enclosure Page(0)s | |
8569 | * @ioc: per adapter object | |
8570 | * | |
8571 | * Return nothing. | |
8572 | */ | |
8573 | static void | |
8574 | _scsih_create_enclosure_list_after_reset(struct MPT3SAS_ADAPTER *ioc) | |
8575 | { | |
8576 | struct _enclosure_node *enclosure_dev; | |
8577 | Mpi2ConfigReply_t mpi_reply; | |
8578 | u16 enclosure_handle; | |
8579 | int rc; | |
8580 | ||
8581 | /* Free existing enclosure list */ | |
8582 | mpt3sas_free_enclosure_list(ioc); | |
8583 | ||
8584 | /* Re constructing enclosure list after reset*/ | |
8585 | enclosure_handle = 0xFFFF; | |
8586 | do { | |
8587 | enclosure_dev = | |
8588 | kzalloc(sizeof(struct _enclosure_node), GFP_KERNEL); | |
8589 | if (!enclosure_dev) { | |
8590 | pr_err(MPT3SAS_FMT | |
8591 | "failure at %s:%d/%s()!\n", ioc->name, | |
8592 | __FILE__, __LINE__, __func__); | |
8593 | return; | |
8594 | } | |
8595 | rc = mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
8596 | &enclosure_dev->pg0, | |
8597 | MPI2_SAS_ENCLOS_PGAD_FORM_GET_NEXT_HANDLE, | |
8598 | enclosure_handle); | |
8599 | ||
8600 | if (rc || (le16_to_cpu(mpi_reply.IOCStatus) & | |
8601 | MPI2_IOCSTATUS_MASK)) { | |
8602 | kfree(enclosure_dev); | |
8603 | return; | |
8604 | } | |
8605 | list_add_tail(&enclosure_dev->list, | |
8606 | &ioc->enclosure_list); | |
8607 | enclosure_handle = | |
8608 | le16_to_cpu(enclosure_dev->pg0.EnclosureHandle); | |
8609 | } while (1); | |
8610 | } | |
8611 | ||
f92363d1 SR |
8612 | /** |
8613 | * _scsih_search_responding_sas_devices - | |
8614 | * @ioc: per adapter object | |
8615 | * | |
8616 | * After host reset, find out whether devices are still responding. | |
8617 | * If not remove. | |
8618 | * | |
8619 | * Return nothing. | |
8620 | */ | |
8621 | static void | |
8622 | _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc) | |
8623 | { | |
8624 | Mpi2SasDevicePage0_t sas_device_pg0; | |
8625 | Mpi2ConfigReply_t mpi_reply; | |
8626 | u16 ioc_status; | |
8627 | u16 handle; | |
8628 | u32 device_info; | |
8629 | ||
8630 | pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name); | |
8631 | ||
8632 | if (list_empty(&ioc->sas_device_list)) | |
8633 | goto out; | |
8634 | ||
8635 | handle = 0xFFFF; | |
8636 | while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
8637 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | |
8638 | handle))) { | |
8639 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8640 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 8641 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 | 8642 | break; |
cf6bf971 | 8643 | handle = le16_to_cpu(sas_device_pg0.DevHandle); |
f92363d1 SR |
8644 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
8645 | if (!(_scsih_is_end_device(device_info))) | |
8646 | continue; | |
e6d45e3e | 8647 | _scsih_mark_responding_sas_device(ioc, &sas_device_pg0); |
f92363d1 SR |
8648 | } |
8649 | ||
8650 | out: | |
8651 | pr_info(MPT3SAS_FMT "search for end-devices: complete\n", | |
8652 | ioc->name); | |
8653 | } | |
8654 | ||
ec051e5a SPS |
8655 | /** |
8656 | * _scsih_mark_responding_pcie_device - mark a pcie_device as responding | |
8657 | * @ioc: per adapter object | |
8658 | * @pcie_device_pg0: PCIe Device page 0 | |
8659 | * | |
8660 | * After host reset, find out whether devices are still responding. | |
8661 | * Used in _scsih_remove_unresponding_devices. | |
8662 | * | |
8663 | * Return nothing. | |
8664 | */ | |
8665 | static void | |
8666 | _scsih_mark_responding_pcie_device(struct MPT3SAS_ADAPTER *ioc, | |
8667 | Mpi26PCIeDevicePage0_t *pcie_device_pg0) | |
8668 | { | |
8669 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; | |
8670 | struct scsi_target *starget; | |
8671 | struct _pcie_device *pcie_device; | |
8672 | unsigned long flags; | |
8673 | ||
8674 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
8675 | list_for_each_entry(pcie_device, &ioc->pcie_device_list, list) { | |
cf6bf971 C |
8676 | if ((pcie_device->wwid == le64_to_cpu(pcie_device_pg0->WWID)) |
8677 | && (pcie_device->slot == le16_to_cpu( | |
8678 | pcie_device_pg0->Slot))) { | |
ec051e5a SPS |
8679 | pcie_device->responding = 1; |
8680 | starget = pcie_device->starget; | |
8681 | if (starget && starget->hostdata) { | |
8682 | sas_target_priv_data = starget->hostdata; | |
8683 | sas_target_priv_data->tm_busy = 0; | |
8684 | sas_target_priv_data->deleted = 0; | |
8685 | } else | |
8686 | sas_target_priv_data = NULL; | |
8687 | if (starget) { | |
8688 | starget_printk(KERN_INFO, starget, | |
8689 | "handle(0x%04x), wwid(0x%016llx) ", | |
8690 | pcie_device->handle, | |
8691 | (unsigned long long)pcie_device->wwid); | |
8692 | if (pcie_device->enclosure_handle != 0) | |
8693 | starget_printk(KERN_INFO, starget, | |
8694 | "enclosure logical id(0x%016llx), " | |
8695 | "slot(%d)\n", | |
8696 | (unsigned long long) | |
8697 | pcie_device->enclosure_logical_id, | |
8698 | pcie_device->slot); | |
8699 | } | |
8700 | ||
8701 | if (((le32_to_cpu(pcie_device_pg0->Flags)) & | |
8702 | MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) && | |
8703 | (ioc->hba_mpi_version_belonged != MPI2_VERSION)) { | |
8704 | pcie_device->enclosure_level = | |
8705 | pcie_device_pg0->EnclosureLevel; | |
8706 | memcpy(&pcie_device->connector_name[0], | |
8707 | &pcie_device_pg0->ConnectorName[0], 4); | |
8708 | } else { | |
8709 | pcie_device->enclosure_level = 0; | |
8710 | pcie_device->connector_name[0] = '\0'; | |
8711 | } | |
8712 | ||
cf6bf971 C |
8713 | if (pcie_device->handle == le16_to_cpu( |
8714 | pcie_device_pg0->DevHandle)) | |
ec051e5a | 8715 | goto out; |
268eb498 | 8716 | pr_info("\thandle changed from(0x%04x)!!!\n", |
ec051e5a | 8717 | pcie_device->handle); |
cf6bf971 C |
8718 | pcie_device->handle = le16_to_cpu( |
8719 | pcie_device_pg0->DevHandle); | |
ec051e5a SPS |
8720 | if (sas_target_priv_data) |
8721 | sas_target_priv_data->handle = | |
cf6bf971 | 8722 | le16_to_cpu(pcie_device_pg0->DevHandle); |
ec051e5a SPS |
8723 | goto out; |
8724 | } | |
8725 | } | |
8726 | ||
8727 | out: | |
8728 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
8729 | } | |
8730 | ||
8731 | /** | |
8732 | * _scsih_search_responding_pcie_devices - | |
8733 | * @ioc: per adapter object | |
8734 | * | |
8735 | * After host reset, find out whether devices are still responding. | |
8736 | * If not remove. | |
8737 | * | |
8738 | * Return nothing. | |
8739 | */ | |
8740 | static void | |
8741 | _scsih_search_responding_pcie_devices(struct MPT3SAS_ADAPTER *ioc) | |
8742 | { | |
8743 | Mpi26PCIeDevicePage0_t pcie_device_pg0; | |
8744 | Mpi2ConfigReply_t mpi_reply; | |
8745 | u16 ioc_status; | |
8746 | u16 handle; | |
8747 | u32 device_info; | |
8748 | ||
8749 | pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name); | |
8750 | ||
8751 | if (list_empty(&ioc->pcie_device_list)) | |
8752 | goto out; | |
8753 | ||
8754 | handle = 0xFFFF; | |
8755 | while (!(mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply, | |
8756 | &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | |
8757 | handle))) { | |
8758 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8759 | MPI2_IOCSTATUS_MASK; | |
8760 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
8761 | pr_info(MPT3SAS_FMT "\tbreak from %s: " | |
8762 | "ioc_status(0x%04x), loginfo(0x%08x)\n", ioc->name, | |
8763 | __func__, ioc_status, | |
8764 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
8765 | break; | |
8766 | } | |
8767 | handle = le16_to_cpu(pcie_device_pg0.DevHandle); | |
8768 | device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo); | |
8769 | if (!(_scsih_is_nvme_device(device_info))) | |
8770 | continue; | |
ec051e5a SPS |
8771 | _scsih_mark_responding_pcie_device(ioc, &pcie_device_pg0); |
8772 | } | |
8773 | out: | |
8774 | pr_info(MPT3SAS_FMT "search for PCIe end-devices: complete\n", | |
8775 | ioc->name); | |
8776 | } | |
8777 | ||
f92363d1 SR |
8778 | /** |
8779 | * _scsih_mark_responding_raid_device - mark a raid_device as responding | |
8780 | * @ioc: per adapter object | |
8781 | * @wwid: world wide identifier for raid volume | |
8782 | * @handle: device handle | |
8783 | * | |
8784 | * After host reset, find out whether devices are still responding. | |
8785 | * Used in _scsih_remove_unresponsive_raid_devices. | |
8786 | * | |
8787 | * Return nothing. | |
8788 | */ | |
8789 | static void | |
8790 | _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid, | |
8791 | u16 handle) | |
8792 | { | |
7786ab6a | 8793 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; |
f92363d1 SR |
8794 | struct scsi_target *starget; |
8795 | struct _raid_device *raid_device; | |
8796 | unsigned long flags; | |
8797 | ||
8798 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
8799 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
8800 | if (raid_device->wwid == wwid && raid_device->starget) { | |
8801 | starget = raid_device->starget; | |
8802 | if (starget && starget->hostdata) { | |
8803 | sas_target_priv_data = starget->hostdata; | |
8804 | sas_target_priv_data->deleted = 0; | |
8805 | } else | |
8806 | sas_target_priv_data = NULL; | |
8807 | raid_device->responding = 1; | |
8808 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
8809 | starget_printk(KERN_INFO, raid_device->starget, | |
8810 | "handle(0x%04x), wwid(0x%016llx)\n", handle, | |
8811 | (unsigned long long)raid_device->wwid); | |
7786ab6a | 8812 | |
7786ab6a SR |
8813 | /* |
8814 | * WARPDRIVE: The handles of the PDs might have changed | |
8815 | * across the host reset so re-initialize the | |
8816 | * required data for Direct IO | |
8817 | */ | |
c84b06a4 | 8818 | mpt3sas_init_warpdrive_properties(ioc, raid_device); |
f92363d1 SR |
8819 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
8820 | if (raid_device->handle == handle) { | |
8821 | spin_unlock_irqrestore(&ioc->raid_device_lock, | |
8822 | flags); | |
8823 | return; | |
8824 | } | |
8825 | pr_info("\thandle changed from(0x%04x)!!!\n", | |
8826 | raid_device->handle); | |
8827 | raid_device->handle = handle; | |
8828 | if (sas_target_priv_data) | |
8829 | sas_target_priv_data->handle = handle; | |
8830 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
8831 | return; | |
8832 | } | |
8833 | } | |
8834 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
8835 | } | |
8836 | ||
8837 | /** | |
8838 | * _scsih_search_responding_raid_devices - | |
8839 | * @ioc: per adapter object | |
8840 | * | |
8841 | * After host reset, find out whether devices are still responding. | |
8842 | * If not remove. | |
8843 | * | |
8844 | * Return nothing. | |
8845 | */ | |
8846 | static void | |
8847 | _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc) | |
8848 | { | |
8849 | Mpi2RaidVolPage1_t volume_pg1; | |
8850 | Mpi2RaidVolPage0_t volume_pg0; | |
8851 | Mpi2RaidPhysDiskPage0_t pd_pg0; | |
8852 | Mpi2ConfigReply_t mpi_reply; | |
8853 | u16 ioc_status; | |
8854 | u16 handle; | |
8855 | u8 phys_disk_num; | |
8856 | ||
8857 | if (!ioc->ir_firmware) | |
8858 | return; | |
8859 | ||
8860 | pr_info(MPT3SAS_FMT "search for raid volumes: start\n", | |
8861 | ioc->name); | |
8862 | ||
8863 | if (list_empty(&ioc->raid_device_list)) | |
8864 | goto out; | |
8865 | ||
8866 | handle = 0xFFFF; | |
8867 | while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply, | |
8868 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { | |
8869 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8870 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 8871 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 SR |
8872 | break; |
8873 | handle = le16_to_cpu(volume_pg1.DevHandle); | |
8874 | ||
8875 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, | |
8876 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
8877 | sizeof(Mpi2RaidVolPage0_t))) | |
8878 | continue; | |
8879 | ||
8880 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || | |
8881 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || | |
8882 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) | |
8883 | _scsih_mark_responding_raid_device(ioc, | |
8884 | le64_to_cpu(volume_pg1.WWID), handle); | |
8885 | } | |
8886 | ||
8887 | /* refresh the pd_handles */ | |
7786ab6a | 8888 | if (!ioc->is_warpdrive) { |
f92363d1 SR |
8889 | phys_disk_num = 0xFF; |
8890 | memset(ioc->pd_handles, 0, ioc->pd_handles_sz); | |
8891 | while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | |
8892 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, | |
8893 | phys_disk_num))) { | |
8894 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8895 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 8896 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 SR |
8897 | break; |
8898 | phys_disk_num = pd_pg0.PhysDiskNum; | |
8899 | handle = le16_to_cpu(pd_pg0.DevHandle); | |
8900 | set_bit(handle, ioc->pd_handles); | |
8901 | } | |
7786ab6a | 8902 | } |
f92363d1 SR |
8903 | out: |
8904 | pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n", | |
8905 | ioc->name); | |
8906 | } | |
8907 | ||
8908 | /** | |
8909 | * _scsih_mark_responding_expander - mark a expander as responding | |
8910 | * @ioc: per adapter object | |
aba5a85c | 8911 | * @expander_pg0:SAS Expander Config Page0 |
f92363d1 SR |
8912 | * |
8913 | * After host reset, find out whether devices are still responding. | |
8914 | * Used in _scsih_remove_unresponsive_expanders. | |
8915 | * | |
8916 | * Return nothing. | |
8917 | */ | |
8918 | static void | |
aba5a85c SR |
8919 | _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc, |
8920 | Mpi2ExpanderPage0_t *expander_pg0) | |
f92363d1 | 8921 | { |
aba5a85c | 8922 | struct _sas_node *sas_expander = NULL; |
f92363d1 | 8923 | unsigned long flags; |
22a923c3 C |
8924 | int i; |
8925 | struct _enclosure_node *enclosure_dev = NULL; | |
aba5a85c | 8926 | u16 handle = le16_to_cpu(expander_pg0->DevHandle); |
22a923c3 | 8927 | u16 enclosure_handle = le16_to_cpu(expander_pg0->EnclosureHandle); |
aba5a85c SR |
8928 | u64 sas_address = le64_to_cpu(expander_pg0->SASAddress); |
8929 | ||
22a923c3 C |
8930 | if (enclosure_handle) |
8931 | enclosure_dev = | |
8932 | mpt3sas_scsih_enclosure_find_by_handle(ioc, | |
8933 | enclosure_handle); | |
f92363d1 SR |
8934 | |
8935 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
8936 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { | |
8937 | if (sas_expander->sas_address != sas_address) | |
8938 | continue; | |
8939 | sas_expander->responding = 1; | |
aba5a85c | 8940 | |
22a923c3 | 8941 | if (enclosure_dev) { |
aba5a85c | 8942 | sas_expander->enclosure_logical_id = |
22a923c3 C |
8943 | le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID); |
8944 | sas_expander->enclosure_handle = | |
8945 | le16_to_cpu(expander_pg0->EnclosureHandle); | |
8946 | } | |
aba5a85c | 8947 | |
f92363d1 SR |
8948 | if (sas_expander->handle == handle) |
8949 | goto out; | |
8950 | pr_info("\texpander(0x%016llx): handle changed" \ | |
8951 | " from(0x%04x) to (0x%04x)!!!\n", | |
8952 | (unsigned long long)sas_expander->sas_address, | |
8953 | sas_expander->handle, handle); | |
8954 | sas_expander->handle = handle; | |
8955 | for (i = 0 ; i < sas_expander->num_phys ; i++) | |
8956 | sas_expander->phy[i].handle = handle; | |
8957 | goto out; | |
8958 | } | |
8959 | out: | |
8960 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
8961 | } | |
8962 | ||
8963 | /** | |
8964 | * _scsih_search_responding_expanders - | |
8965 | * @ioc: per adapter object | |
8966 | * | |
8967 | * After host reset, find out whether devices are still responding. | |
8968 | * If not remove. | |
8969 | * | |
8970 | * Return nothing. | |
8971 | */ | |
8972 | static void | |
8973 | _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc) | |
8974 | { | |
8975 | Mpi2ExpanderPage0_t expander_pg0; | |
8976 | Mpi2ConfigReply_t mpi_reply; | |
8977 | u16 ioc_status; | |
8978 | u64 sas_address; | |
8979 | u16 handle; | |
8980 | ||
8981 | pr_info(MPT3SAS_FMT "search for expanders: start\n", ioc->name); | |
8982 | ||
8983 | if (list_empty(&ioc->sas_expander_list)) | |
8984 | goto out; | |
8985 | ||
8986 | handle = 0xFFFF; | |
8987 | while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | |
8988 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { | |
8989 | ||
8990 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8991 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 8992 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 SR |
8993 | break; |
8994 | ||
8995 | handle = le16_to_cpu(expander_pg0.DevHandle); | |
8996 | sas_address = le64_to_cpu(expander_pg0.SASAddress); | |
8997 | pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n", | |
8998 | handle, | |
8999 | (unsigned long long)sas_address); | |
aba5a85c | 9000 | _scsih_mark_responding_expander(ioc, &expander_pg0); |
f92363d1 SR |
9001 | } |
9002 | ||
9003 | out: | |
9004 | pr_info(MPT3SAS_FMT "search for expanders: complete\n", ioc->name); | |
9005 | } | |
9006 | ||
9007 | /** | |
3075ac49 | 9008 | * _scsih_remove_unresponding_devices - removing unresponding devices |
f92363d1 SR |
9009 | * @ioc: per adapter object |
9010 | * | |
9011 | * Return nothing. | |
9012 | */ | |
9013 | static void | |
3075ac49 | 9014 | _scsih_remove_unresponding_devices(struct MPT3SAS_ADAPTER *ioc) |
f92363d1 SR |
9015 | { |
9016 | struct _sas_device *sas_device, *sas_device_next; | |
9017 | struct _sas_node *sas_expander, *sas_expander_next; | |
9018 | struct _raid_device *raid_device, *raid_device_next; | |
3075ac49 | 9019 | struct _pcie_device *pcie_device, *pcie_device_next; |
f92363d1 SR |
9020 | struct list_head tmp_list; |
9021 | unsigned long flags; | |
d1cb5e49 | 9022 | LIST_HEAD(head); |
f92363d1 SR |
9023 | |
9024 | pr_info(MPT3SAS_FMT "removing unresponding devices: start\n", | |
9025 | ioc->name); | |
9026 | ||
9027 | /* removing unresponding end devices */ | |
9028 | pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n", | |
9029 | ioc->name); | |
d1cb5e49 SR |
9030 | /* |
9031 | * Iterate, pulling off devices marked as non-responding. We become the | |
9032 | * owner for the reference the list had on any object we prune. | |
9033 | */ | |
9034 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
f92363d1 SR |
9035 | list_for_each_entry_safe(sas_device, sas_device_next, |
9036 | &ioc->sas_device_list, list) { | |
9037 | if (!sas_device->responding) | |
d1cb5e49 | 9038 | list_move_tail(&sas_device->list, &head); |
f92363d1 SR |
9039 | else |
9040 | sas_device->responding = 0; | |
9041 | } | |
d1cb5e49 SR |
9042 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
9043 | ||
9044 | /* | |
9045 | * Now, uninitialize and remove the unresponding devices we pruned. | |
9046 | */ | |
9047 | list_for_each_entry_safe(sas_device, sas_device_next, &head, list) { | |
9048 | _scsih_remove_device(ioc, sas_device); | |
9049 | list_del_init(&sas_device->list); | |
9050 | sas_device_put(sas_device); | |
9051 | } | |
f92363d1 | 9052 | |
3075ac49 SPS |
9053 | pr_info(MPT3SAS_FMT |
9054 | " Removing unresponding devices: pcie end-devices\n" | |
9055 | , ioc->name); | |
9056 | INIT_LIST_HEAD(&head); | |
9057 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
9058 | list_for_each_entry_safe(pcie_device, pcie_device_next, | |
9059 | &ioc->pcie_device_list, list) { | |
9060 | if (!pcie_device->responding) | |
9061 | list_move_tail(&pcie_device->list, &head); | |
9062 | else | |
9063 | pcie_device->responding = 0; | |
9064 | } | |
9065 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
9066 | ||
9067 | list_for_each_entry_safe(pcie_device, pcie_device_next, &head, list) { | |
9068 | _scsih_pcie_device_remove_from_sml(ioc, pcie_device); | |
9069 | list_del_init(&pcie_device->list); | |
9070 | pcie_device_put(pcie_device); | |
9071 | } | |
9072 | ||
f92363d1 SR |
9073 | /* removing unresponding volumes */ |
9074 | if (ioc->ir_firmware) { | |
9075 | pr_info(MPT3SAS_FMT "removing unresponding devices: volumes\n", | |
9076 | ioc->name); | |
9077 | list_for_each_entry_safe(raid_device, raid_device_next, | |
9078 | &ioc->raid_device_list, list) { | |
9079 | if (!raid_device->responding) | |
9080 | _scsih_sas_volume_delete(ioc, | |
9081 | raid_device->handle); | |
9082 | else | |
9083 | raid_device->responding = 0; | |
9084 | } | |
9085 | } | |
9086 | ||
9087 | /* removing unresponding expanders */ | |
9088 | pr_info(MPT3SAS_FMT "removing unresponding devices: expanders\n", | |
9089 | ioc->name); | |
9090 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
9091 | INIT_LIST_HEAD(&tmp_list); | |
9092 | list_for_each_entry_safe(sas_expander, sas_expander_next, | |
9093 | &ioc->sas_expander_list, list) { | |
9094 | if (!sas_expander->responding) | |
9095 | list_move_tail(&sas_expander->list, &tmp_list); | |
9096 | else | |
9097 | sas_expander->responding = 0; | |
9098 | } | |
9099 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
9100 | list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list, | |
9101 | list) { | |
f92363d1 SR |
9102 | _scsih_expander_node_remove(ioc, sas_expander); |
9103 | } | |
9104 | ||
9105 | pr_info(MPT3SAS_FMT "removing unresponding devices: complete\n", | |
9106 | ioc->name); | |
9107 | ||
9108 | /* unblock devices */ | |
9109 | _scsih_ublock_io_all_device(ioc); | |
9110 | } | |
9111 | ||
9112 | static void | |
9113 | _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc, | |
9114 | struct _sas_node *sas_expander, u16 handle) | |
9115 | { | |
9116 | Mpi2ExpanderPage1_t expander_pg1; | |
9117 | Mpi2ConfigReply_t mpi_reply; | |
9118 | int i; | |
9119 | ||
9120 | for (i = 0 ; i < sas_expander->num_phys ; i++) { | |
9121 | if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply, | |
9122 | &expander_pg1, i, handle))) { | |
9123 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
9124 | ioc->name, __FILE__, __LINE__, __func__); | |
9125 | return; | |
9126 | } | |
9127 | ||
9128 | mpt3sas_transport_update_links(ioc, sas_expander->sas_address, | |
9129 | le16_to_cpu(expander_pg1.AttachedDevHandle), i, | |
9130 | expander_pg1.NegotiatedLinkRate >> 4); | |
9131 | } | |
9132 | } | |
9133 | ||
9134 | /** | |
9135 | * _scsih_scan_for_devices_after_reset - scan for devices after host reset | |
9136 | * @ioc: per adapter object | |
9137 | * | |
9138 | * Return nothing. | |
9139 | */ | |
9140 | static void | |
9141 | _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc) | |
9142 | { | |
9143 | Mpi2ExpanderPage0_t expander_pg0; | |
9144 | Mpi2SasDevicePage0_t sas_device_pg0; | |
ec051e5a | 9145 | Mpi26PCIeDevicePage0_t pcie_device_pg0; |
f92363d1 SR |
9146 | Mpi2RaidVolPage1_t volume_pg1; |
9147 | Mpi2RaidVolPage0_t volume_pg0; | |
9148 | Mpi2RaidPhysDiskPage0_t pd_pg0; | |
9149 | Mpi2EventIrConfigElement_t element; | |
9150 | Mpi2ConfigReply_t mpi_reply; | |
9151 | u8 phys_disk_num; | |
9152 | u16 ioc_status; | |
9153 | u16 handle, parent_handle; | |
9154 | u64 sas_address; | |
9155 | struct _sas_device *sas_device; | |
ec051e5a | 9156 | struct _pcie_device *pcie_device; |
f92363d1 SR |
9157 | struct _sas_node *expander_device; |
9158 | static struct _raid_device *raid_device; | |
9159 | u8 retry_count; | |
9160 | unsigned long flags; | |
9161 | ||
9162 | pr_info(MPT3SAS_FMT "scan devices: start\n", ioc->name); | |
9163 | ||
9164 | _scsih_sas_host_refresh(ioc); | |
9165 | ||
9166 | pr_info(MPT3SAS_FMT "\tscan devices: expanders start\n", ioc->name); | |
9167 | ||
9168 | /* expanders */ | |
9169 | handle = 0xFFFF; | |
9170 | while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | |
9171 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { | |
9172 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9173 | MPI2_IOCSTATUS_MASK; | |
f92363d1 SR |
9174 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
9175 | pr_info(MPT3SAS_FMT "\tbreak from expander scan: " \ | |
9176 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9177 | ioc->name, ioc_status, | |
9178 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
9179 | break; | |
9180 | } | |
9181 | handle = le16_to_cpu(expander_pg0.DevHandle); | |
9182 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
9183 | expander_device = mpt3sas_scsih_expander_find_by_sas_address( | |
9184 | ioc, le64_to_cpu(expander_pg0.SASAddress)); | |
9185 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
9186 | if (expander_device) | |
9187 | _scsih_refresh_expander_links(ioc, expander_device, | |
9188 | handle); | |
9189 | else { | |
9190 | pr_info(MPT3SAS_FMT "\tBEFORE adding expander: " \ | |
9191 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
9192 | handle, (unsigned long long) | |
9193 | le64_to_cpu(expander_pg0.SASAddress)); | |
9194 | _scsih_expander_add(ioc, handle); | |
9195 | pr_info(MPT3SAS_FMT "\tAFTER adding expander: " \ | |
9196 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
9197 | handle, (unsigned long long) | |
9198 | le64_to_cpu(expander_pg0.SASAddress)); | |
9199 | } | |
9200 | } | |
9201 | ||
9202 | pr_info(MPT3SAS_FMT "\tscan devices: expanders complete\n", | |
9203 | ioc->name); | |
9204 | ||
9205 | if (!ioc->ir_firmware) | |
9206 | goto skip_to_sas; | |
9207 | ||
9208 | pr_info(MPT3SAS_FMT "\tscan devices: phys disk start\n", ioc->name); | |
9209 | ||
9210 | /* phys disk */ | |
9211 | phys_disk_num = 0xFF; | |
9212 | while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | |
9213 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, | |
9214 | phys_disk_num))) { | |
9215 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9216 | MPI2_IOCSTATUS_MASK; | |
f92363d1 SR |
9217 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
9218 | pr_info(MPT3SAS_FMT "\tbreak from phys disk scan: "\ | |
9219 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9220 | ioc->name, ioc_status, | |
9221 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
9222 | break; | |
9223 | } | |
9224 | phys_disk_num = pd_pg0.PhysDiskNum; | |
9225 | handle = le16_to_cpu(pd_pg0.DevHandle); | |
d1cb5e49 SR |
9226 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
9227 | if (sas_device) { | |
9228 | sas_device_put(sas_device); | |
f92363d1 | 9229 | continue; |
d1cb5e49 | 9230 | } |
f92363d1 SR |
9231 | if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
9232 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | |
9233 | handle) != 0) | |
9234 | continue; | |
9235 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9236 | MPI2_IOCSTATUS_MASK; | |
9237 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
9238 | pr_info(MPT3SAS_FMT "\tbreak from phys disk scan " \ | |
9239 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9240 | ioc->name, ioc_status, | |
9241 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
9242 | break; | |
9243 | } | |
9244 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | |
9245 | if (!_scsih_get_sas_address(ioc, parent_handle, | |
9246 | &sas_address)) { | |
9247 | pr_info(MPT3SAS_FMT "\tBEFORE adding phys disk: " \ | |
9248 | " handle (0x%04x), sas_addr(0x%016llx)\n", | |
9249 | ioc->name, handle, (unsigned long long) | |
9250 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
9251 | mpt3sas_transport_update_links(ioc, sas_address, | |
9252 | handle, sas_device_pg0.PhyNum, | |
9253 | MPI2_SAS_NEG_LINK_RATE_1_5); | |
9254 | set_bit(handle, ioc->pd_handles); | |
9255 | retry_count = 0; | |
9256 | /* This will retry adding the end device. | |
9257 | * _scsih_add_device() will decide on retries and | |
9258 | * return "1" when it should be retried | |
9259 | */ | |
9260 | while (_scsih_add_device(ioc, handle, retry_count++, | |
9261 | 1)) { | |
9262 | ssleep(1); | |
9263 | } | |
9264 | pr_info(MPT3SAS_FMT "\tAFTER adding phys disk: " \ | |
9265 | " handle (0x%04x), sas_addr(0x%016llx)\n", | |
9266 | ioc->name, handle, (unsigned long long) | |
9267 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
9268 | } | |
9269 | } | |
9270 | ||
9271 | pr_info(MPT3SAS_FMT "\tscan devices: phys disk complete\n", | |
9272 | ioc->name); | |
9273 | ||
9274 | pr_info(MPT3SAS_FMT "\tscan devices: volumes start\n", ioc->name); | |
9275 | ||
9276 | /* volumes */ | |
9277 | handle = 0xFFFF; | |
9278 | while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply, | |
9279 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { | |
9280 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9281 | MPI2_IOCSTATUS_MASK; | |
f92363d1 SR |
9282 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
9283 | pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \ | |
9284 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9285 | ioc->name, ioc_status, | |
9286 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
9287 | break; | |
9288 | } | |
9289 | handle = le16_to_cpu(volume_pg1.DevHandle); | |
9290 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
9291 | raid_device = _scsih_raid_device_find_by_wwid(ioc, | |
9292 | le64_to_cpu(volume_pg1.WWID)); | |
9293 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
9294 | if (raid_device) | |
9295 | continue; | |
9296 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, | |
9297 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
9298 | sizeof(Mpi2RaidVolPage0_t))) | |
9299 | continue; | |
9300 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9301 | MPI2_IOCSTATUS_MASK; | |
9302 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
9303 | pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \ | |
9304 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9305 | ioc->name, ioc_status, | |
9306 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
9307 | break; | |
9308 | } | |
9309 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || | |
9310 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || | |
9311 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) { | |
9312 | memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t)); | |
9313 | element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED; | |
9314 | element.VolDevHandle = volume_pg1.DevHandle; | |
9315 | pr_info(MPT3SAS_FMT | |
9316 | "\tBEFORE adding volume: handle (0x%04x)\n", | |
9317 | ioc->name, volume_pg1.DevHandle); | |
9318 | _scsih_sas_volume_add(ioc, &element); | |
9319 | pr_info(MPT3SAS_FMT | |
9320 | "\tAFTER adding volume: handle (0x%04x)\n", | |
9321 | ioc->name, volume_pg1.DevHandle); | |
9322 | } | |
9323 | } | |
9324 | ||
9325 | pr_info(MPT3SAS_FMT "\tscan devices: volumes complete\n", | |
9326 | ioc->name); | |
9327 | ||
9328 | skip_to_sas: | |
9329 | ||
9330 | pr_info(MPT3SAS_FMT "\tscan devices: end devices start\n", | |
9331 | ioc->name); | |
9332 | ||
9333 | /* sas devices */ | |
9334 | handle = 0xFFFF; | |
9335 | while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
9336 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | |
9337 | handle))) { | |
9338 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9339 | MPI2_IOCSTATUS_MASK; | |
f92363d1 SR |
9340 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
9341 | pr_info(MPT3SAS_FMT "\tbreak from end device scan:"\ | |
9342 | " ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9343 | ioc->name, ioc_status, | |
9344 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
9345 | break; | |
9346 | } | |
9347 | handle = le16_to_cpu(sas_device_pg0.DevHandle); | |
9348 | if (!(_scsih_is_end_device( | |
9349 | le32_to_cpu(sas_device_pg0.DeviceInfo)))) | |
9350 | continue; | |
d1cb5e49 | 9351 | sas_device = mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 | 9352 | le64_to_cpu(sas_device_pg0.SASAddress)); |
d1cb5e49 SR |
9353 | if (sas_device) { |
9354 | sas_device_put(sas_device); | |
f92363d1 | 9355 | continue; |
d1cb5e49 | 9356 | } |
f92363d1 SR |
9357 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
9358 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) { | |
9359 | pr_info(MPT3SAS_FMT "\tBEFORE adding end device: " \ | |
9360 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
9361 | handle, (unsigned long long) | |
9362 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
9363 | mpt3sas_transport_update_links(ioc, sas_address, handle, | |
9364 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | |
9365 | retry_count = 0; | |
9366 | /* This will retry adding the end device. | |
9367 | * _scsih_add_device() will decide on retries and | |
9368 | * return "1" when it should be retried | |
9369 | */ | |
9370 | while (_scsih_add_device(ioc, handle, retry_count++, | |
9371 | 0)) { | |
9372 | ssleep(1); | |
9373 | } | |
9374 | pr_info(MPT3SAS_FMT "\tAFTER adding end device: " \ | |
9375 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
9376 | handle, (unsigned long long) | |
9377 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
9378 | } | |
9379 | } | |
9380 | pr_info(MPT3SAS_FMT "\tscan devices: end devices complete\n", | |
9381 | ioc->name); | |
ec051e5a SPS |
9382 | pr_info(MPT3SAS_FMT "\tscan devices: pcie end devices start\n", |
9383 | ioc->name); | |
9384 | ||
9385 | /* pcie devices */ | |
9386 | handle = 0xFFFF; | |
9387 | while (!(mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply, | |
9388 | &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | |
9389 | handle))) { | |
9390 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) | |
9391 | & MPI2_IOCSTATUS_MASK; | |
9392 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
9393 | pr_info(MPT3SAS_FMT "\tbreak from pcie end device" | |
9394 | " scan: ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9395 | ioc->name, ioc_status, | |
9396 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
9397 | break; | |
9398 | } | |
9399 | handle = le16_to_cpu(pcie_device_pg0.DevHandle); | |
9400 | if (!(_scsih_is_nvme_device( | |
9401 | le32_to_cpu(pcie_device_pg0.DeviceInfo)))) | |
9402 | continue; | |
9403 | pcie_device = mpt3sas_get_pdev_by_wwid(ioc, | |
9404 | le64_to_cpu(pcie_device_pg0.WWID)); | |
9405 | if (pcie_device) { | |
9406 | pcie_device_put(pcie_device); | |
9407 | continue; | |
9408 | } | |
9409 | retry_count = 0; | |
9410 | parent_handle = le16_to_cpu(pcie_device_pg0.ParentDevHandle); | |
9411 | _scsih_pcie_add_device(ioc, handle); | |
f92363d1 | 9412 | |
ec051e5a SPS |
9413 | pr_info(MPT3SAS_FMT "\tAFTER adding pcie end device: " |
9414 | "handle (0x%04x), wwid(0x%016llx)\n", ioc->name, | |
9415 | handle, | |
9416 | (unsigned long long) le64_to_cpu(pcie_device_pg0.WWID)); | |
9417 | } | |
9418 | pr_info(MPT3SAS_FMT "\tpcie devices: pcie end devices complete\n", | |
9419 | ioc->name); | |
f92363d1 SR |
9420 | pr_info(MPT3SAS_FMT "scan devices: complete\n", ioc->name); |
9421 | } | |
9422 | /** | |
9423 | * mpt3sas_scsih_reset_handler - reset callback handler (for scsih) | |
9424 | * @ioc: per adapter object | |
9425 | * @reset_phase: phase | |
9426 | * | |
9427 | * The handler for doing any required cleanup or initialization. | |
9428 | * | |
9429 | * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET, | |
9430 | * MPT3_IOC_DONE_RESET | |
9431 | * | |
9432 | * Return nothing. | |
9433 | */ | |
9434 | void | |
9435 | mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase) | |
9436 | { | |
9437 | switch (reset_phase) { | |
9438 | case MPT3_IOC_PRE_RESET: | |
9439 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
9440 | "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__)); | |
9441 | break; | |
9442 | case MPT3_IOC_AFTER_RESET: | |
9443 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
9444 | "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__)); | |
9445 | if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) { | |
9446 | ioc->scsih_cmds.status |= MPT3_CMD_RESET; | |
9447 | mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid); | |
9448 | complete(&ioc->scsih_cmds.done); | |
9449 | } | |
9450 | if (ioc->tm_cmds.status & MPT3_CMD_PENDING) { | |
9451 | ioc->tm_cmds.status |= MPT3_CMD_RESET; | |
9452 | mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid); | |
9453 | complete(&ioc->tm_cmds.done); | |
9454 | } | |
9455 | ||
c696f7b8 SPS |
9456 | memset(ioc->pend_os_device_add, 0, ioc->pend_os_device_add_sz); |
9457 | memset(ioc->device_remove_in_progress, 0, | |
9458 | ioc->device_remove_in_progress_sz); | |
f92363d1 SR |
9459 | _scsih_fw_event_cleanup_queue(ioc); |
9460 | _scsih_flush_running_cmds(ioc); | |
9461 | break; | |
9462 | case MPT3_IOC_DONE_RESET: | |
9463 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
9464 | "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__)); | |
9465 | if ((!ioc->is_driver_loading) && !(disable_discovery > 0 && | |
9466 | !ioc->sas_hba.num_phys)) { | |
9467 | _scsih_prep_device_scan(ioc); | |
22a923c3 | 9468 | _scsih_create_enclosure_list_after_reset(ioc); |
f92363d1 | 9469 | _scsih_search_responding_sas_devices(ioc); |
ec051e5a | 9470 | _scsih_search_responding_pcie_devices(ioc); |
f92363d1 SR |
9471 | _scsih_search_responding_raid_devices(ioc); |
9472 | _scsih_search_responding_expanders(ioc); | |
9473 | _scsih_error_recovery_delete_devices(ioc); | |
9474 | } | |
9475 | break; | |
9476 | } | |
9477 | } | |
9478 | ||
9479 | /** | |
9480 | * _mpt3sas_fw_work - delayed task for processing firmware events | |
9481 | * @ioc: per adapter object | |
9482 | * @fw_event: The fw_event_work object | |
9483 | * Context: user. | |
9484 | * | |
9485 | * Return nothing. | |
9486 | */ | |
9487 | static void | |
9488 | _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event) | |
9489 | { | |
146b16c8 SR |
9490 | _scsih_fw_event_del_from_list(ioc, fw_event); |
9491 | ||
f92363d1 | 9492 | /* the queue is being flushed so ignore this event */ |
146b16c8 SR |
9493 | if (ioc->remove_host || ioc->pci_error_recovery) { |
9494 | fw_event_work_put(fw_event); | |
f92363d1 SR |
9495 | return; |
9496 | } | |
9497 | ||
9498 | switch (fw_event->event) { | |
9499 | case MPT3SAS_PROCESS_TRIGGER_DIAG: | |
35b62362 JL |
9500 | mpt3sas_process_trigger_data(ioc, |
9501 | (struct SL_WH_TRIGGERS_EVENT_DATA_T *) | |
9502 | fw_event->event_data); | |
f92363d1 SR |
9503 | break; |
9504 | case MPT3SAS_REMOVE_UNRESPONDING_DEVICES: | |
146b16c8 SR |
9505 | while (scsi_host_in_recovery(ioc->shost) || |
9506 | ioc->shost_recovery) { | |
9507 | /* | |
9508 | * If we're unloading, bail. Otherwise, this can become | |
9509 | * an infinite loop. | |
9510 | */ | |
9511 | if (ioc->remove_host) | |
9512 | goto out; | |
f92363d1 | 9513 | ssleep(1); |
146b16c8 | 9514 | } |
3075ac49 | 9515 | _scsih_remove_unresponding_devices(ioc); |
f92363d1 SR |
9516 | _scsih_scan_for_devices_after_reset(ioc); |
9517 | break; | |
9518 | case MPT3SAS_PORT_ENABLE_COMPLETE: | |
9519 | ioc->start_scan = 0; | |
199fd79a | 9520 | if (missing_delay[0] != -1 && missing_delay[1] != -1) |
f92363d1 SR |
9521 | mpt3sas_base_update_missing_delay(ioc, missing_delay[0], |
9522 | missing_delay[1]); | |
9523 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
9524 | "port enable: complete from worker thread\n", | |
9525 | ioc->name)); | |
9526 | break; | |
0f624c39 SR |
9527 | case MPT3SAS_TURN_ON_PFA_LED: |
9528 | _scsih_turn_on_pfa_led(ioc, fw_event->device_handle); | |
f92363d1 SR |
9529 | break; |
9530 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: | |
9531 | _scsih_sas_topology_change_event(ioc, fw_event); | |
9532 | break; | |
9533 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: | |
9534 | _scsih_sas_device_status_change_event(ioc, fw_event); | |
9535 | break; | |
9536 | case MPI2_EVENT_SAS_DISCOVERY: | |
9537 | _scsih_sas_discovery_event(ioc, fw_event); | |
9538 | break; | |
95540b8e C |
9539 | case MPI2_EVENT_SAS_DEVICE_DISCOVERY_ERROR: |
9540 | _scsih_sas_device_discovery_error_event(ioc, fw_event); | |
9541 | break; | |
f92363d1 SR |
9542 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: |
9543 | _scsih_sas_broadcast_primitive_event(ioc, fw_event); | |
9544 | break; | |
9545 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: | |
9546 | _scsih_sas_enclosure_dev_status_change_event(ioc, | |
9547 | fw_event); | |
9548 | break; | |
9549 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: | |
9550 | _scsih_sas_ir_config_change_event(ioc, fw_event); | |
9551 | break; | |
9552 | case MPI2_EVENT_IR_VOLUME: | |
9553 | _scsih_sas_ir_volume_event(ioc, fw_event); | |
9554 | break; | |
9555 | case MPI2_EVENT_IR_PHYSICAL_DISK: | |
9556 | _scsih_sas_ir_physical_disk_event(ioc, fw_event); | |
9557 | break; | |
9558 | case MPI2_EVENT_IR_OPERATION_STATUS: | |
9559 | _scsih_sas_ir_operation_status_event(ioc, fw_event); | |
9560 | break; | |
4318c734 SPS |
9561 | case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE: |
9562 | _scsih_pcie_device_status_change_event(ioc, fw_event); | |
9563 | break; | |
9564 | case MPI2_EVENT_PCIE_ENUMERATION: | |
9565 | _scsih_pcie_enumeration_event(ioc, fw_event); | |
9566 | break; | |
9567 | case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST: | |
9568 | _scsih_pcie_topology_change_event(ioc, fw_event); | |
9569 | return; | |
9570 | break; | |
f92363d1 | 9571 | } |
146b16c8 SR |
9572 | out: |
9573 | fw_event_work_put(fw_event); | |
f92363d1 SR |
9574 | } |
9575 | ||
9576 | /** | |
9577 | * _firmware_event_work | |
9578 | * @ioc: per adapter object | |
9579 | * @work: The fw_event_work object | |
9580 | * Context: user. | |
9581 | * | |
9582 | * wrappers for the work thread handling firmware events | |
9583 | * | |
9584 | * Return nothing. | |
9585 | */ | |
9586 | ||
9587 | static void | |
9588 | _firmware_event_work(struct work_struct *work) | |
9589 | { | |
9590 | struct fw_event_work *fw_event = container_of(work, | |
9591 | struct fw_event_work, work); | |
9592 | ||
9593 | _mpt3sas_fw_work(fw_event->ioc, fw_event); | |
9594 | } | |
9595 | ||
9596 | /** | |
9597 | * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time) | |
9598 | * @ioc: per adapter object | |
9599 | * @msix_index: MSIX table index supplied by the OS | |
9600 | * @reply: reply message frame(lower 32bit addr) | |
9601 | * Context: interrupt. | |
9602 | * | |
9603 | * This function merely adds a new work task into ioc->firmware_event_thread. | |
9604 | * The tasks are worked from _firmware_event_work in user context. | |
9605 | * | |
9606 | * Return 1 meaning mf should be freed from _base_interrupt | |
9607 | * 0 means the mf is freed from this function. | |
9608 | */ | |
9609 | u8 | |
9610 | mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index, | |
9611 | u32 reply) | |
9612 | { | |
9613 | struct fw_event_work *fw_event; | |
9614 | Mpi2EventNotificationReply_t *mpi_reply; | |
9615 | u16 event; | |
9616 | u16 sz; | |
a470a51c | 9617 | Mpi26EventDataActiveCableExcept_t *ActiveCableEventData; |
f92363d1 | 9618 | |
79eb96d6 C |
9619 | /* events turned off due to host reset */ |
9620 | if (ioc->pci_error_recovery) | |
f92363d1 SR |
9621 | return 1; |
9622 | ||
9623 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
9624 | ||
9625 | if (unlikely(!mpi_reply)) { | |
9626 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", | |
9627 | ioc->name, __FILE__, __LINE__, __func__); | |
9628 | return 1; | |
9629 | } | |
9630 | ||
9631 | event = le16_to_cpu(mpi_reply->Event); | |
9632 | ||
9633 | if (event != MPI2_EVENT_LOG_ENTRY_ADDED) | |
9634 | mpt3sas_trigger_event(ioc, event, 0); | |
9635 | ||
9636 | switch (event) { | |
9637 | /* handle these */ | |
9638 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: | |
9639 | { | |
9640 | Mpi2EventDataSasBroadcastPrimitive_t *baen_data = | |
9641 | (Mpi2EventDataSasBroadcastPrimitive_t *) | |
9642 | mpi_reply->EventData; | |
9643 | ||
9644 | if (baen_data->Primitive != | |
9645 | MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT) | |
9646 | return 1; | |
9647 | ||
9648 | if (ioc->broadcast_aen_busy) { | |
9649 | ioc->broadcast_aen_pending++; | |
9650 | return 1; | |
9651 | } else | |
9652 | ioc->broadcast_aen_busy = 1; | |
9653 | break; | |
9654 | } | |
9655 | ||
9656 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: | |
9657 | _scsih_check_topo_delete_events(ioc, | |
9658 | (Mpi2EventDataSasTopologyChangeList_t *) | |
9659 | mpi_reply->EventData); | |
9660 | break; | |
4318c734 SPS |
9661 | case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST: |
9662 | _scsih_check_pcie_topo_remove_events(ioc, | |
9663 | (Mpi26EventDataPCIeTopologyChangeList_t *) | |
9664 | mpi_reply->EventData); | |
9665 | break; | |
f92363d1 SR |
9666 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: |
9667 | _scsih_check_ir_config_unhide_events(ioc, | |
9668 | (Mpi2EventDataIrConfigChangeList_t *) | |
9669 | mpi_reply->EventData); | |
9670 | break; | |
9671 | case MPI2_EVENT_IR_VOLUME: | |
9672 | _scsih_check_volume_delete_events(ioc, | |
9673 | (Mpi2EventDataIrVolume_t *) | |
9674 | mpi_reply->EventData); | |
9675 | break; | |
7786ab6a SR |
9676 | case MPI2_EVENT_LOG_ENTRY_ADDED: |
9677 | { | |
9678 | Mpi2EventDataLogEntryAdded_t *log_entry; | |
9679 | u32 *log_code; | |
9680 | ||
9681 | if (!ioc->is_warpdrive) | |
9682 | break; | |
9683 | ||
9684 | log_entry = (Mpi2EventDataLogEntryAdded_t *) | |
9685 | mpi_reply->EventData; | |
9686 | log_code = (u32 *)log_entry->LogData; | |
f92363d1 | 9687 | |
7786ab6a SR |
9688 | if (le16_to_cpu(log_entry->LogEntryQualifier) |
9689 | != MPT2_WARPDRIVE_LOGENTRY) | |
9690 | break; | |
9691 | ||
9692 | switch (le32_to_cpu(*log_code)) { | |
9693 | case MPT2_WARPDRIVE_LC_SSDT: | |
9694 | pr_warn(MPT3SAS_FMT "WarpDrive Warning: " | |
9695 | "IO Throttling has occurred in the WarpDrive " | |
9696 | "subsystem. Check WarpDrive documentation for " | |
9697 | "additional details.\n", ioc->name); | |
9698 | break; | |
9699 | case MPT2_WARPDRIVE_LC_SSDLW: | |
9700 | pr_warn(MPT3SAS_FMT "WarpDrive Warning: " | |
9701 | "Program/Erase Cycles for the WarpDrive subsystem " | |
9702 | "in degraded range. Check WarpDrive documentation " | |
9703 | "for additional details.\n", ioc->name); | |
9704 | break; | |
9705 | case MPT2_WARPDRIVE_LC_SSDLF: | |
9706 | pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: " | |
9707 | "There are no Program/Erase Cycles for the " | |
9708 | "WarpDrive subsystem. The storage device will be " | |
9709 | "in read-only mode. Check WarpDrive documentation " | |
9710 | "for additional details.\n", ioc->name); | |
9711 | break; | |
9712 | case MPT2_WARPDRIVE_LC_BRMF: | |
9713 | pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: " | |
9714 | "The Backup Rail Monitor has failed on the " | |
9715 | "WarpDrive subsystem. Check WarpDrive " | |
9716 | "documentation for additional details.\n", | |
9717 | ioc->name); | |
9718 | break; | |
9719 | } | |
9720 | ||
9721 | break; | |
9722 | } | |
f92363d1 SR |
9723 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: |
9724 | case MPI2_EVENT_IR_OPERATION_STATUS: | |
9725 | case MPI2_EVENT_SAS_DISCOVERY: | |
95540b8e | 9726 | case MPI2_EVENT_SAS_DEVICE_DISCOVERY_ERROR: |
f92363d1 SR |
9727 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: |
9728 | case MPI2_EVENT_IR_PHYSICAL_DISK: | |
4318c734 SPS |
9729 | case MPI2_EVENT_PCIE_ENUMERATION: |
9730 | case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE: | |
f92363d1 SR |
9731 | break; |
9732 | ||
2d8ce8c9 SR |
9733 | case MPI2_EVENT_TEMP_THRESHOLD: |
9734 | _scsih_temp_threshold_events(ioc, | |
9735 | (Mpi2EventDataTemperature_t *) | |
9736 | mpi_reply->EventData); | |
9737 | break; | |
a470a51c C |
9738 | case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION: |
9739 | ActiveCableEventData = | |
9740 | (Mpi26EventDataActiveCableExcept_t *) mpi_reply->EventData; | |
6c44c0fe C |
9741 | switch (ActiveCableEventData->ReasonCode) { |
9742 | case MPI26_EVENT_ACTIVE_CABLE_INSUFFICIENT_POWER: | |
b99b1993 SR |
9743 | pr_notice(MPT3SAS_FMT |
9744 | "Currently an active cable with ReceptacleID %d\n", | |
9745 | ioc->name, ActiveCableEventData->ReceptacleID); | |
9746 | pr_notice("cannot be powered and devices connected\n"); | |
9747 | pr_notice("to this active cable will not be seen\n"); | |
9748 | pr_notice("This active cable requires %d mW of power\n", | |
6c44c0fe | 9749 | ActiveCableEventData->ActiveCablePowerRequirement); |
6c44c0fe C |
9750 | break; |
9751 | ||
9752 | case MPI26_EVENT_ACTIVE_CABLE_DEGRADED: | |
b99b1993 SR |
9753 | pr_notice(MPT3SAS_FMT |
9754 | "Currently a cable with ReceptacleID %d\n", | |
9755 | ioc->name, ActiveCableEventData->ReceptacleID); | |
9756 | pr_notice( | |
9757 | "is not running at optimal speed(12 Gb/s rate)\n"); | |
6c44c0fe | 9758 | break; |
7ebd67e0 | 9759 | } |
6c44c0fe | 9760 | |
a470a51c | 9761 | break; |
2d8ce8c9 | 9762 | |
f92363d1 SR |
9763 | default: /* ignore the rest */ |
9764 | return 1; | |
9765 | } | |
9766 | ||
f92363d1 | 9767 | sz = le16_to_cpu(mpi_reply->EventDataLength) * 4; |
146b16c8 | 9768 | fw_event = alloc_fw_event_work(sz); |
35b62362 | 9769 | if (!fw_event) { |
f92363d1 SR |
9770 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
9771 | ioc->name, __FILE__, __LINE__, __func__); | |
f92363d1 SR |
9772 | return 1; |
9773 | } | |
9774 | ||
9775 | memcpy(fw_event->event_data, mpi_reply->EventData, sz); | |
9776 | fw_event->ioc = ioc; | |
9777 | fw_event->VF_ID = mpi_reply->VF_ID; | |
9778 | fw_event->VP_ID = mpi_reply->VP_ID; | |
9779 | fw_event->event = event; | |
9780 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 | 9781 | fw_event_work_put(fw_event); |
f92363d1 SR |
9782 | return 1; |
9783 | } | |
9784 | ||
f92363d1 SR |
9785 | /** |
9786 | * _scsih_expander_node_remove - removing expander device from list. | |
9787 | * @ioc: per adapter object | |
9788 | * @sas_expander: the sas_device object | |
f92363d1 SR |
9789 | * |
9790 | * Removing object and freeing associated memory from the | |
9791 | * ioc->sas_expander_list. | |
9792 | * | |
9793 | * Return nothing. | |
9794 | */ | |
9795 | static void | |
9796 | _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc, | |
9797 | struct _sas_node *sas_expander) | |
9798 | { | |
9799 | struct _sas_port *mpt3sas_port, *next; | |
bbe3def3 | 9800 | unsigned long flags; |
f92363d1 SR |
9801 | |
9802 | /* remove sibling ports attached to this expander */ | |
9803 | list_for_each_entry_safe(mpt3sas_port, next, | |
9804 | &sas_expander->sas_port_list, port_list) { | |
9805 | if (ioc->shost_recovery) | |
9806 | return; | |
9807 | if (mpt3sas_port->remote_identify.device_type == | |
9808 | SAS_END_DEVICE) | |
9809 | mpt3sas_device_remove_by_sas_address(ioc, | |
9810 | mpt3sas_port->remote_identify.sas_address); | |
9811 | else if (mpt3sas_port->remote_identify.device_type == | |
9812 | SAS_EDGE_EXPANDER_DEVICE || | |
9813 | mpt3sas_port->remote_identify.device_type == | |
9814 | SAS_FANOUT_EXPANDER_DEVICE) | |
9815 | mpt3sas_expander_remove(ioc, | |
9816 | mpt3sas_port->remote_identify.sas_address); | |
9817 | } | |
9818 | ||
9819 | mpt3sas_transport_port_remove(ioc, sas_expander->sas_address, | |
9820 | sas_expander->sas_address_parent); | |
9821 | ||
9822 | pr_info(MPT3SAS_FMT | |
9823 | "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n", | |
9824 | ioc->name, | |
9825 | sas_expander->handle, (unsigned long long) | |
9826 | sas_expander->sas_address); | |
9827 | ||
bbe3def3 SR |
9828 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
9829 | list_del(&sas_expander->list); | |
9830 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
9831 | ||
f92363d1 SR |
9832 | kfree(sas_expander->phy); |
9833 | kfree(sas_expander); | |
9834 | } | |
9835 | ||
9836 | /** | |
9837 | * _scsih_ir_shutdown - IR shutdown notification | |
9838 | * @ioc: per adapter object | |
9839 | * | |
9840 | * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that | |
9841 | * the host system is shutting down. | |
9842 | * | |
9843 | * Return nothing. | |
9844 | */ | |
9845 | static void | |
9846 | _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc) | |
9847 | { | |
9848 | Mpi2RaidActionRequest_t *mpi_request; | |
9849 | Mpi2RaidActionReply_t *mpi_reply; | |
9850 | u16 smid; | |
9851 | ||
9852 | /* is IR firmware build loaded ? */ | |
9853 | if (!ioc->ir_firmware) | |
9854 | return; | |
9855 | ||
9856 | /* are there any volumes ? */ | |
9857 | if (list_empty(&ioc->raid_device_list)) | |
9858 | return; | |
9859 | ||
9860 | mutex_lock(&ioc->scsih_cmds.mutex); | |
9861 | ||
9862 | if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) { | |
9863 | pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n", | |
9864 | ioc->name, __func__); | |
9865 | goto out; | |
9866 | } | |
9867 | ioc->scsih_cmds.status = MPT3_CMD_PENDING; | |
9868 | ||
9869 | smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx); | |
9870 | if (!smid) { | |
9871 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
9872 | ioc->name, __func__); | |
9873 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
9874 | goto out; | |
9875 | } | |
9876 | ||
9877 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
9878 | ioc->scsih_cmds.smid = smid; | |
9879 | memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t)); | |
9880 | ||
9881 | mpi_request->Function = MPI2_FUNCTION_RAID_ACTION; | |
9882 | mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED; | |
9883 | ||
7786ab6a SR |
9884 | if (!ioc->hide_ir_msg) |
9885 | pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name); | |
f92363d1 | 9886 | init_completion(&ioc->scsih_cmds.done); |
40114bde | 9887 | mpt3sas_base_put_smid_default(ioc, smid); |
f92363d1 SR |
9888 | wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ); |
9889 | ||
9890 | if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) { | |
9891 | pr_err(MPT3SAS_FMT "%s: timeout\n", | |
9892 | ioc->name, __func__); | |
9893 | goto out; | |
9894 | } | |
9895 | ||
9896 | if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) { | |
9897 | mpi_reply = ioc->scsih_cmds.reply; | |
7786ab6a SR |
9898 | if (!ioc->hide_ir_msg) |
9899 | pr_info(MPT3SAS_FMT "IR shutdown " | |
9900 | "(complete): ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9901 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), | |
9902 | le32_to_cpu(mpi_reply->IOCLogInfo)); | |
f92363d1 SR |
9903 | } |
9904 | ||
9905 | out: | |
9906 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
9907 | mutex_unlock(&ioc->scsih_cmds.mutex); | |
9908 | } | |
9909 | ||
9910 | /** | |
8a7e4c24 | 9911 | * scsih_remove - detach and remove add host |
f92363d1 SR |
9912 | * @pdev: PCI device struct |
9913 | * | |
9914 | * Routine called when unloading the driver. | |
9915 | * Return nothing. | |
9916 | */ | |
8bbb1cf6 | 9917 | static void scsih_remove(struct pci_dev *pdev) |
f92363d1 SR |
9918 | { |
9919 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9920 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
9921 | struct _sas_port *mpt3sas_port, *next_port; | |
9922 | struct _raid_device *raid_device, *next; | |
9923 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
3075ac49 | 9924 | struct _pcie_device *pcie_device, *pcienext; |
f92363d1 SR |
9925 | struct workqueue_struct *wq; |
9926 | unsigned long flags; | |
9927 | ||
9928 | ioc->remove_host = 1; | |
c666d3be SR |
9929 | |
9930 | mpt3sas_wait_for_commands_to_complete(ioc); | |
9931 | _scsih_flush_running_cmds(ioc); | |
9932 | ||
f92363d1 SR |
9933 | _scsih_fw_event_cleanup_queue(ioc); |
9934 | ||
9935 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
9936 | wq = ioc->firmware_event_thread; | |
9937 | ioc->firmware_event_thread = NULL; | |
9938 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
9939 | if (wq) | |
9940 | destroy_workqueue(wq); | |
9941 | ||
9942 | /* release all the volumes */ | |
9943 | _scsih_ir_shutdown(ioc); | |
9944 | list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list, | |
9945 | list) { | |
9946 | if (raid_device->starget) { | |
9947 | sas_target_priv_data = | |
9948 | raid_device->starget->hostdata; | |
9949 | sas_target_priv_data->deleted = 1; | |
9950 | scsi_remove_target(&raid_device->starget->dev); | |
9951 | } | |
9952 | pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n", | |
9953 | ioc->name, raid_device->handle, | |
9954 | (unsigned long long) raid_device->wwid); | |
9955 | _scsih_raid_device_remove(ioc, raid_device); | |
9956 | } | |
3075ac49 SPS |
9957 | list_for_each_entry_safe(pcie_device, pcienext, &ioc->pcie_device_list, |
9958 | list) { | |
9959 | _scsih_pcie_device_remove_from_sml(ioc, pcie_device); | |
9960 | list_del_init(&pcie_device->list); | |
9961 | pcie_device_put(pcie_device); | |
9962 | } | |
f92363d1 SR |
9963 | |
9964 | /* free ports attached to the sas_host */ | |
9965 | list_for_each_entry_safe(mpt3sas_port, next_port, | |
9966 | &ioc->sas_hba.sas_port_list, port_list) { | |
9967 | if (mpt3sas_port->remote_identify.device_type == | |
9968 | SAS_END_DEVICE) | |
9969 | mpt3sas_device_remove_by_sas_address(ioc, | |
9970 | mpt3sas_port->remote_identify.sas_address); | |
9971 | else if (mpt3sas_port->remote_identify.device_type == | |
9972 | SAS_EDGE_EXPANDER_DEVICE || | |
9973 | mpt3sas_port->remote_identify.device_type == | |
9974 | SAS_FANOUT_EXPANDER_DEVICE) | |
9975 | mpt3sas_expander_remove(ioc, | |
9976 | mpt3sas_port->remote_identify.sas_address); | |
9977 | } | |
9978 | ||
9979 | /* free phys attached to the sas_host */ | |
9980 | if (ioc->sas_hba.num_phys) { | |
9981 | kfree(ioc->sas_hba.phy); | |
9982 | ioc->sas_hba.phy = NULL; | |
9983 | ioc->sas_hba.num_phys = 0; | |
9984 | } | |
9985 | ||
9986 | sas_remove_host(shost); | |
9987 | mpt3sas_base_detach(ioc); | |
08c4d550 | 9988 | spin_lock(&gioc_lock); |
f92363d1 | 9989 | list_del(&ioc->list); |
08c4d550 | 9990 | spin_unlock(&gioc_lock); |
f92363d1 SR |
9991 | scsi_host_put(shost); |
9992 | } | |
9993 | ||
9994 | /** | |
8a7e4c24 | 9995 | * scsih_shutdown - routine call during system shutdown |
f92363d1 SR |
9996 | * @pdev: PCI device struct |
9997 | * | |
9998 | * Return nothing. | |
9999 | */ | |
8bbb1cf6 | 10000 | static void |
8a7e4c24 | 10001 | scsih_shutdown(struct pci_dev *pdev) |
f92363d1 SR |
10002 | { |
10003 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10004 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10005 | struct workqueue_struct *wq; | |
10006 | unsigned long flags; | |
10007 | ||
10008 | ioc->remove_host = 1; | |
c666d3be SR |
10009 | |
10010 | mpt3sas_wait_for_commands_to_complete(ioc); | |
10011 | _scsih_flush_running_cmds(ioc); | |
10012 | ||
f92363d1 SR |
10013 | _scsih_fw_event_cleanup_queue(ioc); |
10014 | ||
10015 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
10016 | wq = ioc->firmware_event_thread; | |
10017 | ioc->firmware_event_thread = NULL; | |
10018 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
10019 | if (wq) | |
10020 | destroy_workqueue(wq); | |
10021 | ||
10022 | _scsih_ir_shutdown(ioc); | |
10023 | mpt3sas_base_detach(ioc); | |
10024 | } | |
10025 | ||
10026 | ||
10027 | /** | |
10028 | * _scsih_probe_boot_devices - reports 1st device | |
10029 | * @ioc: per adapter object | |
10030 | * | |
10031 | * If specified in bios page 2, this routine reports the 1st | |
10032 | * device scsi-ml or sas transport for persistent boot device | |
10033 | * purposes. Please refer to function _scsih_determine_boot_device() | |
10034 | */ | |
10035 | static void | |
10036 | _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc) | |
10037 | { | |
d88e1eab | 10038 | u32 channel; |
f92363d1 SR |
10039 | void *device; |
10040 | struct _sas_device *sas_device; | |
10041 | struct _raid_device *raid_device; | |
d88e1eab | 10042 | struct _pcie_device *pcie_device; |
f92363d1 SR |
10043 | u16 handle; |
10044 | u64 sas_address_parent; | |
10045 | u64 sas_address; | |
10046 | unsigned long flags; | |
10047 | int rc; | |
d88e1eab | 10048 | int tid; |
f92363d1 SR |
10049 | |
10050 | /* no Bios, return immediately */ | |
10051 | if (!ioc->bios_pg3.BiosVersion) | |
10052 | return; | |
10053 | ||
10054 | device = NULL; | |
f92363d1 SR |
10055 | if (ioc->req_boot_device.device) { |
10056 | device = ioc->req_boot_device.device; | |
d88e1eab | 10057 | channel = ioc->req_boot_device.channel; |
f92363d1 SR |
10058 | } else if (ioc->req_alt_boot_device.device) { |
10059 | device = ioc->req_alt_boot_device.device; | |
d88e1eab | 10060 | channel = ioc->req_alt_boot_device.channel; |
f92363d1 SR |
10061 | } else if (ioc->current_boot_device.device) { |
10062 | device = ioc->current_boot_device.device; | |
d88e1eab | 10063 | channel = ioc->current_boot_device.channel; |
f92363d1 SR |
10064 | } |
10065 | ||
10066 | if (!device) | |
10067 | return; | |
10068 | ||
d88e1eab | 10069 | if (channel == RAID_CHANNEL) { |
f92363d1 SR |
10070 | raid_device = device; |
10071 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
10072 | raid_device->id, 0); | |
10073 | if (rc) | |
10074 | _scsih_raid_device_remove(ioc, raid_device); | |
d88e1eab SPS |
10075 | } else if (channel == PCIE_CHANNEL) { |
10076 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
10077 | pcie_device = device; | |
10078 | tid = pcie_device->id; | |
10079 | list_move_tail(&pcie_device->list, &ioc->pcie_device_list); | |
10080 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
10081 | rc = scsi_add_device(ioc->shost, PCIE_CHANNEL, tid, 0); | |
10082 | if (rc) | |
10083 | _scsih_pcie_device_remove(ioc, pcie_device); | |
f92363d1 SR |
10084 | } else { |
10085 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
10086 | sas_device = device; | |
10087 | handle = sas_device->handle; | |
10088 | sas_address_parent = sas_device->sas_address_parent; | |
10089 | sas_address = sas_device->sas_address; | |
10090 | list_move_tail(&sas_device->list, &ioc->sas_device_list); | |
10091 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
10092 | ||
7786ab6a SR |
10093 | if (ioc->hide_drives) |
10094 | return; | |
f92363d1 SR |
10095 | if (!mpt3sas_transport_port_add(ioc, handle, |
10096 | sas_address_parent)) { | |
10097 | _scsih_sas_device_remove(ioc, sas_device); | |
10098 | } else if (!sas_device->starget) { | |
f5edbe77 SR |
10099 | if (!ioc->is_driver_loading) { |
10100 | mpt3sas_transport_port_remove(ioc, | |
10101 | sas_address, | |
f92363d1 | 10102 | sas_address_parent); |
f5edbe77 SR |
10103 | _scsih_sas_device_remove(ioc, sas_device); |
10104 | } | |
f92363d1 SR |
10105 | } |
10106 | } | |
10107 | } | |
10108 | ||
10109 | /** | |
10110 | * _scsih_probe_raid - reporting raid volumes to scsi-ml | |
10111 | * @ioc: per adapter object | |
10112 | * | |
10113 | * Called during initial loading of the driver. | |
10114 | */ | |
10115 | static void | |
10116 | _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc) | |
10117 | { | |
10118 | struct _raid_device *raid_device, *raid_next; | |
10119 | int rc; | |
10120 | ||
10121 | list_for_each_entry_safe(raid_device, raid_next, | |
10122 | &ioc->raid_device_list, list) { | |
10123 | if (raid_device->starget) | |
10124 | continue; | |
10125 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
10126 | raid_device->id, 0); | |
10127 | if (rc) | |
10128 | _scsih_raid_device_remove(ioc, raid_device); | |
10129 | } | |
10130 | } | |
10131 | ||
d1cb5e49 SR |
10132 | static struct _sas_device *get_next_sas_device(struct MPT3SAS_ADAPTER *ioc) |
10133 | { | |
10134 | struct _sas_device *sas_device = NULL; | |
10135 | unsigned long flags; | |
10136 | ||
10137 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
10138 | if (!list_empty(&ioc->sas_device_init_list)) { | |
10139 | sas_device = list_first_entry(&ioc->sas_device_init_list, | |
10140 | struct _sas_device, list); | |
10141 | sas_device_get(sas_device); | |
10142 | } | |
10143 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
10144 | ||
10145 | return sas_device; | |
10146 | } | |
10147 | ||
10148 | static void sas_device_make_active(struct MPT3SAS_ADAPTER *ioc, | |
10149 | struct _sas_device *sas_device) | |
10150 | { | |
10151 | unsigned long flags; | |
10152 | ||
10153 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
10154 | ||
10155 | /* | |
10156 | * Since we dropped the lock during the call to port_add(), we need to | |
10157 | * be careful here that somebody else didn't move or delete this item | |
10158 | * while we were busy with other things. | |
10159 | * | |
10160 | * If it was on the list, we need a put() for the reference the list | |
10161 | * had. Either way, we need a get() for the destination list. | |
10162 | */ | |
10163 | if (!list_empty(&sas_device->list)) { | |
10164 | list_del_init(&sas_device->list); | |
10165 | sas_device_put(sas_device); | |
10166 | } | |
10167 | ||
10168 | sas_device_get(sas_device); | |
10169 | list_add_tail(&sas_device->list, &ioc->sas_device_list); | |
10170 | ||
10171 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
10172 | } | |
10173 | ||
f92363d1 SR |
10174 | /** |
10175 | * _scsih_probe_sas - reporting sas devices to sas transport | |
10176 | * @ioc: per adapter object | |
10177 | * | |
10178 | * Called during initial loading of the driver. | |
10179 | */ | |
10180 | static void | |
10181 | _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc) | |
10182 | { | |
d1cb5e49 | 10183 | struct _sas_device *sas_device; |
f92363d1 | 10184 | |
d1cb5e49 SR |
10185 | if (ioc->hide_drives) |
10186 | return; | |
7786ab6a | 10187 | |
d1cb5e49 | 10188 | while ((sas_device = get_next_sas_device(ioc))) { |
f92363d1 SR |
10189 | if (!mpt3sas_transport_port_add(ioc, sas_device->handle, |
10190 | sas_device->sas_address_parent)) { | |
d1cb5e49 SR |
10191 | _scsih_sas_device_remove(ioc, sas_device); |
10192 | sas_device_put(sas_device); | |
f92363d1 SR |
10193 | continue; |
10194 | } else if (!sas_device->starget) { | |
10195 | /* | |
10196 | * When asyn scanning is enabled, its not possible to | |
10197 | * remove devices while scanning is turned on due to an | |
10198 | * oops in scsi_sysfs_add_sdev()->add_device()-> | |
10199 | * sysfs_addrm_start() | |
10200 | */ | |
f5edbe77 | 10201 | if (!ioc->is_driver_loading) { |
f92363d1 SR |
10202 | mpt3sas_transport_port_remove(ioc, |
10203 | sas_device->sas_address, | |
10204 | sas_device->sas_address_parent); | |
d1cb5e49 SR |
10205 | _scsih_sas_device_remove(ioc, sas_device); |
10206 | sas_device_put(sas_device); | |
f5edbe77 SR |
10207 | continue; |
10208 | } | |
f92363d1 | 10209 | } |
d1cb5e49 SR |
10210 | sas_device_make_active(ioc, sas_device); |
10211 | sas_device_put(sas_device); | |
f92363d1 SR |
10212 | } |
10213 | } | |
10214 | ||
d88e1eab SPS |
10215 | /** |
10216 | * get_next_pcie_device - Get the next pcie device | |
10217 | * @ioc: per adapter object | |
10218 | * | |
10219 | * Get the next pcie device from pcie_device_init_list list. | |
10220 | * | |
10221 | * Returns pcie device structure if pcie_device_init_list list is not empty | |
10222 | * otherwise returns NULL | |
10223 | */ | |
10224 | static struct _pcie_device *get_next_pcie_device(struct MPT3SAS_ADAPTER *ioc) | |
10225 | { | |
10226 | struct _pcie_device *pcie_device = NULL; | |
10227 | unsigned long flags; | |
10228 | ||
10229 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
10230 | if (!list_empty(&ioc->pcie_device_init_list)) { | |
10231 | pcie_device = list_first_entry(&ioc->pcie_device_init_list, | |
10232 | struct _pcie_device, list); | |
10233 | pcie_device_get(pcie_device); | |
10234 | } | |
10235 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
10236 | ||
10237 | return pcie_device; | |
10238 | } | |
10239 | ||
10240 | /** | |
10241 | * pcie_device_make_active - Add pcie device to pcie_device_list list | |
10242 | * @ioc: per adapter object | |
10243 | * @pcie_device: pcie device object | |
10244 | * | |
10245 | * Add the pcie device which has registered with SCSI Transport Later to | |
10246 | * pcie_device_list list | |
10247 | */ | |
10248 | static void pcie_device_make_active(struct MPT3SAS_ADAPTER *ioc, | |
10249 | struct _pcie_device *pcie_device) | |
10250 | { | |
10251 | unsigned long flags; | |
10252 | ||
10253 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
10254 | ||
10255 | if (!list_empty(&pcie_device->list)) { | |
10256 | list_del_init(&pcie_device->list); | |
10257 | pcie_device_put(pcie_device); | |
10258 | } | |
10259 | pcie_device_get(pcie_device); | |
10260 | list_add_tail(&pcie_device->list, &ioc->pcie_device_list); | |
10261 | ||
10262 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
10263 | } | |
10264 | ||
10265 | /** | |
10266 | * _scsih_probe_pcie - reporting PCIe devices to scsi-ml | |
10267 | * @ioc: per adapter object | |
10268 | * | |
10269 | * Called during initial loading of the driver. | |
10270 | */ | |
10271 | static void | |
10272 | _scsih_probe_pcie(struct MPT3SAS_ADAPTER *ioc) | |
10273 | { | |
10274 | struct _pcie_device *pcie_device; | |
10275 | int rc; | |
10276 | ||
10277 | /* PCIe Device List */ | |
10278 | while ((pcie_device = get_next_pcie_device(ioc))) { | |
10279 | if (pcie_device->starget) { | |
10280 | pcie_device_put(pcie_device); | |
10281 | continue; | |
10282 | } | |
10283 | rc = scsi_add_device(ioc->shost, PCIE_CHANNEL, | |
10284 | pcie_device->id, 0); | |
10285 | if (rc) { | |
10286 | _scsih_pcie_device_remove(ioc, pcie_device); | |
10287 | pcie_device_put(pcie_device); | |
10288 | continue; | |
10289 | } else if (!pcie_device->starget) { | |
10290 | /* | |
10291 | * When async scanning is enabled, its not possible to | |
10292 | * remove devices while scanning is turned on due to an | |
10293 | * oops in scsi_sysfs_add_sdev()->add_device()-> | |
10294 | * sysfs_addrm_start() | |
10295 | */ | |
10296 | if (!ioc->is_driver_loading) { | |
10297 | /* TODO-- Need to find out whether this condition will | |
10298 | * occur or not | |
10299 | */ | |
10300 | _scsih_pcie_device_remove(ioc, pcie_device); | |
10301 | pcie_device_put(pcie_device); | |
10302 | continue; | |
10303 | } | |
10304 | } | |
10305 | pcie_device_make_active(ioc, pcie_device); | |
10306 | pcie_device_put(pcie_device); | |
10307 | } | |
10308 | } | |
10309 | ||
f92363d1 SR |
10310 | /** |
10311 | * _scsih_probe_devices - probing for devices | |
10312 | * @ioc: per adapter object | |
10313 | * | |
10314 | * Called during initial loading of the driver. | |
10315 | */ | |
10316 | static void | |
10317 | _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc) | |
10318 | { | |
10319 | u16 volume_mapping_flags; | |
10320 | ||
10321 | if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR)) | |
10322 | return; /* return when IOC doesn't support initiator mode */ | |
10323 | ||
10324 | _scsih_probe_boot_devices(ioc); | |
10325 | ||
10326 | if (ioc->ir_firmware) { | |
10327 | volume_mapping_flags = | |
10328 | le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) & | |
10329 | MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE; | |
10330 | if (volume_mapping_flags == | |
10331 | MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) { | |
10332 | _scsih_probe_raid(ioc); | |
10333 | _scsih_probe_sas(ioc); | |
10334 | } else { | |
10335 | _scsih_probe_sas(ioc); | |
10336 | _scsih_probe_raid(ioc); | |
10337 | } | |
d88e1eab | 10338 | } else { |
f92363d1 | 10339 | _scsih_probe_sas(ioc); |
d88e1eab SPS |
10340 | _scsih_probe_pcie(ioc); |
10341 | } | |
f92363d1 SR |
10342 | } |
10343 | ||
10344 | /** | |
8a7e4c24 | 10345 | * scsih_scan_start - scsi lld callback for .scan_start |
f92363d1 SR |
10346 | * @shost: SCSI host pointer |
10347 | * | |
10348 | * The shost has the ability to discover targets on its own instead | |
10349 | * of scanning the entire bus. In our implemention, we will kick off | |
10350 | * firmware discovery. | |
10351 | */ | |
8bbb1cf6 | 10352 | static void |
8a7e4c24 | 10353 | scsih_scan_start(struct Scsi_Host *shost) |
f92363d1 SR |
10354 | { |
10355 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10356 | int rc; | |
10357 | if (diag_buffer_enable != -1 && diag_buffer_enable != 0) | |
10358 | mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable); | |
10359 | ||
10360 | if (disable_discovery > 0) | |
10361 | return; | |
10362 | ||
10363 | ioc->start_scan = 1; | |
10364 | rc = mpt3sas_port_enable(ioc); | |
10365 | ||
10366 | if (rc != 0) | |
10367 | pr_info(MPT3SAS_FMT "port enable: FAILED\n", ioc->name); | |
10368 | } | |
10369 | ||
10370 | /** | |
8a7e4c24 | 10371 | * scsih_scan_finished - scsi lld callback for .scan_finished |
f92363d1 SR |
10372 | * @shost: SCSI host pointer |
10373 | * @time: elapsed time of the scan in jiffies | |
10374 | * | |
10375 | * This function will be called periodicallyn until it returns 1 with the | |
10376 | * scsi_host and the elapsed time of the scan in jiffies. In our implemention, | |
10377 | * we wait for firmware discovery to complete, then return 1. | |
10378 | */ | |
8bbb1cf6 | 10379 | static int |
8a7e4c24 | 10380 | scsih_scan_finished(struct Scsi_Host *shost, unsigned long time) |
f92363d1 SR |
10381 | { |
10382 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10383 | ||
10384 | if (disable_discovery > 0) { | |
10385 | ioc->is_driver_loading = 0; | |
10386 | ioc->wait_for_discovery_to_complete = 0; | |
10387 | return 1; | |
10388 | } | |
10389 | ||
10390 | if (time >= (300 * HZ)) { | |
e3586147 | 10391 | ioc->port_enable_cmds.status = MPT3_CMD_NOT_USED; |
f92363d1 SR |
10392 | pr_info(MPT3SAS_FMT |
10393 | "port enable: FAILED with timeout (timeout=300s)\n", | |
10394 | ioc->name); | |
10395 | ioc->is_driver_loading = 0; | |
10396 | return 1; | |
10397 | } | |
10398 | ||
10399 | if (ioc->start_scan) | |
10400 | return 0; | |
10401 | ||
10402 | if (ioc->start_scan_failed) { | |
10403 | pr_info(MPT3SAS_FMT | |
10404 | "port enable: FAILED with (ioc_status=0x%08x)\n", | |
10405 | ioc->name, ioc->start_scan_failed); | |
10406 | ioc->is_driver_loading = 0; | |
10407 | ioc->wait_for_discovery_to_complete = 0; | |
10408 | ioc->remove_host = 1; | |
10409 | return 1; | |
10410 | } | |
10411 | ||
10412 | pr_info(MPT3SAS_FMT "port enable: SUCCESS\n", ioc->name); | |
e3586147 | 10413 | ioc->port_enable_cmds.status = MPT3_CMD_NOT_USED; |
f92363d1 SR |
10414 | |
10415 | if (ioc->wait_for_discovery_to_complete) { | |
10416 | ioc->wait_for_discovery_to_complete = 0; | |
10417 | _scsih_probe_devices(ioc); | |
10418 | } | |
10419 | mpt3sas_base_start_watchdog(ioc); | |
10420 | ioc->is_driver_loading = 0; | |
10421 | return 1; | |
10422 | } | |
10423 | ||
c84b06a4 SR |
10424 | /* shost template for SAS 2.0 HBA devices */ |
10425 | static struct scsi_host_template mpt2sas_driver_template = { | |
10426 | .module = THIS_MODULE, | |
10427 | .name = "Fusion MPT SAS Host", | |
10428 | .proc_name = MPT2SAS_DRIVER_NAME, | |
10429 | .queuecommand = scsih_qcmd, | |
10430 | .target_alloc = scsih_target_alloc, | |
10431 | .slave_alloc = scsih_slave_alloc, | |
10432 | .slave_configure = scsih_slave_configure, | |
10433 | .target_destroy = scsih_target_destroy, | |
10434 | .slave_destroy = scsih_slave_destroy, | |
10435 | .scan_finished = scsih_scan_finished, | |
10436 | .scan_start = scsih_scan_start, | |
10437 | .change_queue_depth = scsih_change_queue_depth, | |
10438 | .eh_abort_handler = scsih_abort, | |
10439 | .eh_device_reset_handler = scsih_dev_reset, | |
10440 | .eh_target_reset_handler = scsih_target_reset, | |
10441 | .eh_host_reset_handler = scsih_host_reset, | |
10442 | .bios_param = scsih_bios_param, | |
10443 | .can_queue = 1, | |
10444 | .this_id = -1, | |
10445 | .sg_tablesize = MPT2SAS_SG_DEPTH, | |
10446 | .max_sectors = 32767, | |
10447 | .cmd_per_lun = 7, | |
10448 | .use_clustering = ENABLE_CLUSTERING, | |
10449 | .shost_attrs = mpt3sas_host_attrs, | |
10450 | .sdev_attrs = mpt3sas_dev_attrs, | |
10451 | .track_queue_depth = 1, | |
dbec4c90 | 10452 | .cmd_size = sizeof(struct scsiio_tracker), |
c84b06a4 SR |
10453 | }; |
10454 | ||
10455 | /* raid transport support for SAS 2.0 HBA devices */ | |
10456 | static struct raid_function_template mpt2sas_raid_functions = { | |
10457 | .cookie = &mpt2sas_driver_template, | |
10458 | .is_raid = scsih_is_raid, | |
10459 | .get_resync = scsih_get_resync, | |
10460 | .get_state = scsih_get_state, | |
10461 | }; | |
d357e84d | 10462 | |
c84b06a4 SR |
10463 | /* shost template for SAS 3.0 HBA devices */ |
10464 | static struct scsi_host_template mpt3sas_driver_template = { | |
10465 | .module = THIS_MODULE, | |
10466 | .name = "Fusion MPT SAS Host", | |
10467 | .proc_name = MPT3SAS_DRIVER_NAME, | |
10468 | .queuecommand = scsih_qcmd, | |
10469 | .target_alloc = scsih_target_alloc, | |
10470 | .slave_alloc = scsih_slave_alloc, | |
10471 | .slave_configure = scsih_slave_configure, | |
10472 | .target_destroy = scsih_target_destroy, | |
10473 | .slave_destroy = scsih_slave_destroy, | |
10474 | .scan_finished = scsih_scan_finished, | |
10475 | .scan_start = scsih_scan_start, | |
10476 | .change_queue_depth = scsih_change_queue_depth, | |
10477 | .eh_abort_handler = scsih_abort, | |
10478 | .eh_device_reset_handler = scsih_dev_reset, | |
10479 | .eh_target_reset_handler = scsih_target_reset, | |
10480 | .eh_host_reset_handler = scsih_host_reset, | |
10481 | .bios_param = scsih_bios_param, | |
10482 | .can_queue = 1, | |
10483 | .this_id = -1, | |
10484 | .sg_tablesize = MPT3SAS_SG_DEPTH, | |
10485 | .max_sectors = 32767, | |
10486 | .cmd_per_lun = 7, | |
10487 | .use_clustering = ENABLE_CLUSTERING, | |
10488 | .shost_attrs = mpt3sas_host_attrs, | |
10489 | .sdev_attrs = mpt3sas_dev_attrs, | |
10490 | .track_queue_depth = 1, | |
dbec4c90 | 10491 | .cmd_size = sizeof(struct scsiio_tracker), |
c84b06a4 SR |
10492 | }; |
10493 | ||
10494 | /* raid transport support for SAS 3.0 HBA devices */ | |
10495 | static struct raid_function_template mpt3sas_raid_functions = { | |
10496 | .cookie = &mpt3sas_driver_template, | |
10497 | .is_raid = scsih_is_raid, | |
10498 | .get_resync = scsih_get_resync, | |
10499 | .get_state = scsih_get_state, | |
10500 | }; | |
10501 | ||
10502 | /** | |
10503 | * _scsih_determine_hba_mpi_version - determine in which MPI version class | |
10504 | * this device belongs to. | |
10505 | * @pdev: PCI device struct | |
10506 | * | |
10507 | * return MPI2_VERSION for SAS 2.0 HBA devices, | |
b130b0d5 SS |
10508 | * MPI25_VERSION for SAS 3.0 HBA devices, and |
10509 | * MPI26 VERSION for Cutlass & Invader SAS 3.0 HBA devices | |
c84b06a4 | 10510 | */ |
8bbb1cf6 | 10511 | static u16 |
c84b06a4 SR |
10512 | _scsih_determine_hba_mpi_version(struct pci_dev *pdev) |
10513 | { | |
10514 | ||
10515 | switch (pdev->device) { | |
7786ab6a | 10516 | case MPI2_MFGPAGE_DEVID_SSS6200: |
d357e84d SR |
10517 | case MPI2_MFGPAGE_DEVID_SAS2004: |
10518 | case MPI2_MFGPAGE_DEVID_SAS2008: | |
10519 | case MPI2_MFGPAGE_DEVID_SAS2108_1: | |
10520 | case MPI2_MFGPAGE_DEVID_SAS2108_2: | |
10521 | case MPI2_MFGPAGE_DEVID_SAS2108_3: | |
10522 | case MPI2_MFGPAGE_DEVID_SAS2116_1: | |
10523 | case MPI2_MFGPAGE_DEVID_SAS2116_2: | |
10524 | case MPI2_MFGPAGE_DEVID_SAS2208_1: | |
10525 | case MPI2_MFGPAGE_DEVID_SAS2208_2: | |
10526 | case MPI2_MFGPAGE_DEVID_SAS2208_3: | |
10527 | case MPI2_MFGPAGE_DEVID_SAS2208_4: | |
10528 | case MPI2_MFGPAGE_DEVID_SAS2208_5: | |
10529 | case MPI2_MFGPAGE_DEVID_SAS2208_6: | |
10530 | case MPI2_MFGPAGE_DEVID_SAS2308_1: | |
10531 | case MPI2_MFGPAGE_DEVID_SAS2308_2: | |
10532 | case MPI2_MFGPAGE_DEVID_SAS2308_3: | |
c520691b | 10533 | case MPI2_MFGPAGE_DEVID_SAS2308_MPI_EP: |
c84b06a4 | 10534 | return MPI2_VERSION; |
d357e84d SR |
10535 | case MPI25_MFGPAGE_DEVID_SAS3004: |
10536 | case MPI25_MFGPAGE_DEVID_SAS3008: | |
10537 | case MPI25_MFGPAGE_DEVID_SAS3108_1: | |
10538 | case MPI25_MFGPAGE_DEVID_SAS3108_2: | |
10539 | case MPI25_MFGPAGE_DEVID_SAS3108_5: | |
10540 | case MPI25_MFGPAGE_DEVID_SAS3108_6: | |
c84b06a4 | 10541 | return MPI25_VERSION; |
b130b0d5 SS |
10542 | case MPI26_MFGPAGE_DEVID_SAS3216: |
10543 | case MPI26_MFGPAGE_DEVID_SAS3224: | |
10544 | case MPI26_MFGPAGE_DEVID_SAS3316_1: | |
10545 | case MPI26_MFGPAGE_DEVID_SAS3316_2: | |
10546 | case MPI26_MFGPAGE_DEVID_SAS3316_3: | |
10547 | case MPI26_MFGPAGE_DEVID_SAS3316_4: | |
10548 | case MPI26_MFGPAGE_DEVID_SAS3324_1: | |
10549 | case MPI26_MFGPAGE_DEVID_SAS3324_2: | |
10550 | case MPI26_MFGPAGE_DEVID_SAS3324_3: | |
10551 | case MPI26_MFGPAGE_DEVID_SAS3324_4: | |
998f26ae SPS |
10552 | case MPI26_MFGPAGE_DEVID_SAS3508: |
10553 | case MPI26_MFGPAGE_DEVID_SAS3508_1: | |
10554 | case MPI26_MFGPAGE_DEVID_SAS3408: | |
10555 | case MPI26_MFGPAGE_DEVID_SAS3516: | |
10556 | case MPI26_MFGPAGE_DEVID_SAS3516_1: | |
10557 | case MPI26_MFGPAGE_DEVID_SAS3416: | |
15fd7c74 | 10558 | case MPI26_MFGPAGE_DEVID_SAS3616: |
b130b0d5 | 10559 | return MPI26_VERSION; |
d357e84d | 10560 | } |
c84b06a4 | 10561 | return 0; |
d357e84d SR |
10562 | } |
10563 | ||
f92363d1 | 10564 | /** |
c84b06a4 | 10565 | * _scsih_probe - attach and add scsi host |
f92363d1 SR |
10566 | * @pdev: PCI device struct |
10567 | * @id: pci device id | |
10568 | * | |
10569 | * Returns 0 success, anything else error. | |
10570 | */ | |
8bbb1cf6 | 10571 | static int |
c84b06a4 | 10572 | _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
f92363d1 SR |
10573 | { |
10574 | struct MPT3SAS_ADAPTER *ioc; | |
c84b06a4 | 10575 | struct Scsi_Host *shost = NULL; |
b65f1d4d | 10576 | int rv; |
c84b06a4 SR |
10577 | u16 hba_mpi_version; |
10578 | ||
10579 | /* Determine in which MPI version class this pci device belongs */ | |
10580 | hba_mpi_version = _scsih_determine_hba_mpi_version(pdev); | |
10581 | if (hba_mpi_version == 0) | |
10582 | return -ENODEV; | |
10583 | ||
10584 | /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one, | |
10585 | * for other generation HBA's return with -ENODEV | |
10586 | */ | |
10587 | if ((hbas_to_enumerate == 1) && (hba_mpi_version != MPI2_VERSION)) | |
10588 | return -ENODEV; | |
10589 | ||
10590 | /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two, | |
10591 | * for other generation HBA's return with -ENODEV | |
10592 | */ | |
b130b0d5 SS |
10593 | if ((hbas_to_enumerate == 2) && (!(hba_mpi_version == MPI25_VERSION |
10594 | || hba_mpi_version == MPI26_VERSION))) | |
c84b06a4 SR |
10595 | return -ENODEV; |
10596 | ||
10597 | switch (hba_mpi_version) { | |
10598 | case MPI2_VERSION: | |
ffdadd68 | 10599 | pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | |
10600 | PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM); | |
c84b06a4 SR |
10601 | /* Use mpt2sas driver host template for SAS 2.0 HBA's */ |
10602 | shost = scsi_host_alloc(&mpt2sas_driver_template, | |
10603 | sizeof(struct MPT3SAS_ADAPTER)); | |
10604 | if (!shost) | |
10605 | return -ENODEV; | |
10606 | ioc = shost_priv(shost); | |
10607 | memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER)); | |
10608 | ioc->hba_mpi_version_belonged = hba_mpi_version; | |
10609 | ioc->id = mpt2_ids++; | |
10610 | sprintf(ioc->driver_name, "%s", MPT2SAS_DRIVER_NAME); | |
c520691b SPS |
10611 | switch (pdev->device) { |
10612 | case MPI2_MFGPAGE_DEVID_SSS6200: | |
c84b06a4 SR |
10613 | ioc->is_warpdrive = 1; |
10614 | ioc->hide_ir_msg = 1; | |
c520691b SPS |
10615 | break; |
10616 | case MPI2_MFGPAGE_DEVID_SAS2308_MPI_EP: | |
10617 | ioc->is_mcpu_endpoint = 1; | |
10618 | break; | |
10619 | default: | |
c84b06a4 | 10620 | ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS; |
c520691b SPS |
10621 | break; |
10622 | } | |
c84b06a4 SR |
10623 | break; |
10624 | case MPI25_VERSION: | |
b130b0d5 | 10625 | case MPI26_VERSION: |
c84b06a4 SR |
10626 | /* Use mpt3sas driver host template for SAS 3.0 HBA's */ |
10627 | shost = scsi_host_alloc(&mpt3sas_driver_template, | |
10628 | sizeof(struct MPT3SAS_ADAPTER)); | |
10629 | if (!shost) | |
10630 | return -ENODEV; | |
10631 | ioc = shost_priv(shost); | |
10632 | memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER)); | |
10633 | ioc->hba_mpi_version_belonged = hba_mpi_version; | |
10634 | ioc->id = mpt3_ids++; | |
10635 | sprintf(ioc->driver_name, "%s", MPT3SAS_DRIVER_NAME); | |
998f26ae SPS |
10636 | switch (pdev->device) { |
10637 | case MPI26_MFGPAGE_DEVID_SAS3508: | |
10638 | case MPI26_MFGPAGE_DEVID_SAS3508_1: | |
10639 | case MPI26_MFGPAGE_DEVID_SAS3408: | |
10640 | case MPI26_MFGPAGE_DEVID_SAS3516: | |
10641 | case MPI26_MFGPAGE_DEVID_SAS3516_1: | |
10642 | case MPI26_MFGPAGE_DEVID_SAS3416: | |
15fd7c74 | 10643 | case MPI26_MFGPAGE_DEVID_SAS3616: |
998f26ae SPS |
10644 | ioc->is_gen35_ioc = 1; |
10645 | break; | |
10646 | default: | |
10647 | ioc->is_gen35_ioc = 0; | |
10648 | } | |
b130b0d5 SS |
10649 | if ((ioc->hba_mpi_version_belonged == MPI25_VERSION && |
10650 | pdev->revision >= SAS3_PCI_DEVICE_C0_REVISION) || | |
0bb337c9 SPS |
10651 | (ioc->hba_mpi_version_belonged == MPI26_VERSION)) { |
10652 | ioc->combined_reply_queue = 1; | |
10653 | if (ioc->is_gen35_ioc) | |
10654 | ioc->combined_reply_index_count = | |
10655 | MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G35; | |
10656 | else | |
10657 | ioc->combined_reply_index_count = | |
10658 | MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G3; | |
10659 | } | |
c84b06a4 SR |
10660 | break; |
10661 | default: | |
10662 | return -ENODEV; | |
10663 | } | |
f92363d1 | 10664 | |
f92363d1 | 10665 | INIT_LIST_HEAD(&ioc->list); |
08c4d550 | 10666 | spin_lock(&gioc_lock); |
f92363d1 | 10667 | list_add_tail(&ioc->list, &mpt3sas_ioc_list); |
08c4d550 | 10668 | spin_unlock(&gioc_lock); |
f92363d1 | 10669 | ioc->shost = shost; |
f92363d1 SR |
10670 | ioc->pdev = pdev; |
10671 | ioc->scsi_io_cb_idx = scsi_io_cb_idx; | |
10672 | ioc->tm_cb_idx = tm_cb_idx; | |
10673 | ioc->ctl_cb_idx = ctl_cb_idx; | |
10674 | ioc->base_cb_idx = base_cb_idx; | |
10675 | ioc->port_enable_cb_idx = port_enable_cb_idx; | |
10676 | ioc->transport_cb_idx = transport_cb_idx; | |
10677 | ioc->scsih_cb_idx = scsih_cb_idx; | |
10678 | ioc->config_cb_idx = config_cb_idx; | |
10679 | ioc->tm_tr_cb_idx = tm_tr_cb_idx; | |
10680 | ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx; | |
10681 | ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx; | |
10682 | ioc->logging_level = logging_level; | |
10683 | ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds; | |
10684 | /* misc semaphores and spin locks */ | |
10685 | mutex_init(&ioc->reset_in_progress_mutex); | |
08c4d550 SR |
10686 | /* initializing pci_access_mutex lock */ |
10687 | mutex_init(&ioc->pci_access_mutex); | |
f92363d1 SR |
10688 | spin_lock_init(&ioc->ioc_reset_in_progress_lock); |
10689 | spin_lock_init(&ioc->scsi_lookup_lock); | |
10690 | spin_lock_init(&ioc->sas_device_lock); | |
10691 | spin_lock_init(&ioc->sas_node_lock); | |
10692 | spin_lock_init(&ioc->fw_event_lock); | |
10693 | spin_lock_init(&ioc->raid_device_lock); | |
d88e1eab | 10694 | spin_lock_init(&ioc->pcie_device_lock); |
f92363d1 SR |
10695 | spin_lock_init(&ioc->diag_trigger_lock); |
10696 | ||
10697 | INIT_LIST_HEAD(&ioc->sas_device_list); | |
10698 | INIT_LIST_HEAD(&ioc->sas_device_init_list); | |
10699 | INIT_LIST_HEAD(&ioc->sas_expander_list); | |
22a923c3 | 10700 | INIT_LIST_HEAD(&ioc->enclosure_list); |
d88e1eab SPS |
10701 | INIT_LIST_HEAD(&ioc->pcie_device_list); |
10702 | INIT_LIST_HEAD(&ioc->pcie_device_init_list); | |
f92363d1 SR |
10703 | INIT_LIST_HEAD(&ioc->fw_event_list); |
10704 | INIT_LIST_HEAD(&ioc->raid_device_list); | |
10705 | INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list); | |
10706 | INIT_LIST_HEAD(&ioc->delayed_tr_list); | |
fd0331b3 SS |
10707 | INIT_LIST_HEAD(&ioc->delayed_sc_list); |
10708 | INIT_LIST_HEAD(&ioc->delayed_event_ack_list); | |
f92363d1 | 10709 | INIT_LIST_HEAD(&ioc->delayed_tr_volume_list); |
cf9bd21a | 10710 | INIT_LIST_HEAD(&ioc->reply_queue_list); |
f92363d1 | 10711 | |
c84b06a4 | 10712 | sprintf(ioc->name, "%s_cm%d", ioc->driver_name, ioc->id); |
d357e84d | 10713 | |
f92363d1 SR |
10714 | /* init shost parameters */ |
10715 | shost->max_cmd_len = 32; | |
10716 | shost->max_lun = max_lun; | |
10717 | shost->transportt = mpt3sas_transport_template; | |
10718 | shost->unique_id = ioc->id; | |
10719 | ||
0448f019 SPS |
10720 | if (ioc->is_mcpu_endpoint) { |
10721 | /* mCPU MPI support 64K max IO */ | |
10722 | shost->max_sectors = 128; | |
10723 | pr_info(MPT3SAS_FMT | |
f92363d1 SR |
10724 | "The max_sectors value is set to %d\n", |
10725 | ioc->name, shost->max_sectors); | |
0448f019 SPS |
10726 | } else { |
10727 | if (max_sectors != 0xFFFF) { | |
10728 | if (max_sectors < 64) { | |
10729 | shost->max_sectors = 64; | |
10730 | pr_warn(MPT3SAS_FMT "Invalid value %d passed " \ | |
10731 | "for max_sectors, range is 64 to 32767. " \ | |
10732 | "Assigning value of 64.\n", \ | |
10733 | ioc->name, max_sectors); | |
10734 | } else if (max_sectors > 32767) { | |
10735 | shost->max_sectors = 32767; | |
10736 | pr_warn(MPT3SAS_FMT "Invalid value %d passed " \ | |
10737 | "for max_sectors, range is 64 to 32767." \ | |
10738 | "Assigning default value of 32767.\n", \ | |
10739 | ioc->name, max_sectors); | |
10740 | } else { | |
10741 | shost->max_sectors = max_sectors & 0xFFFE; | |
10742 | pr_info(MPT3SAS_FMT | |
10743 | "The max_sectors value is set to %d\n", | |
10744 | ioc->name, shost->max_sectors); | |
10745 | } | |
f92363d1 SR |
10746 | } |
10747 | } | |
f92363d1 SR |
10748 | /* register EEDP capabilities with SCSI layer */ |
10749 | if (prot_mask > 0) | |
10750 | scsi_host_set_prot(shost, prot_mask); | |
10751 | else | |
10752 | scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION | |
10753 | | SHOST_DIF_TYPE2_PROTECTION | |
10754 | | SHOST_DIF_TYPE3_PROTECTION); | |
10755 | ||
10756 | scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC); | |
10757 | ||
10758 | /* event thread */ | |
10759 | snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name), | |
c84b06a4 | 10760 | "fw_event_%s%d", ioc->driver_name, ioc->id); |
bdff785e | 10761 | ioc->firmware_event_thread = alloc_ordered_workqueue( |
864449ee | 10762 | ioc->firmware_event_name, 0); |
f92363d1 SR |
10763 | if (!ioc->firmware_event_thread) { |
10764 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
10765 | ioc->name, __FILE__, __LINE__, __func__); | |
b65f1d4d | 10766 | rv = -ENODEV; |
f92363d1 SR |
10767 | goto out_thread_fail; |
10768 | } | |
10769 | ||
10770 | ioc->is_driver_loading = 1; | |
10771 | if ((mpt3sas_base_attach(ioc))) { | |
10772 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
10773 | ioc->name, __FILE__, __LINE__, __func__); | |
b65f1d4d | 10774 | rv = -ENODEV; |
f92363d1 SR |
10775 | goto out_attach_fail; |
10776 | } | |
7786ab6a | 10777 | |
7786ab6a SR |
10778 | if (ioc->is_warpdrive) { |
10779 | if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) | |
10780 | ioc->hide_drives = 0; | |
10781 | else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS) | |
10782 | ioc->hide_drives = 1; | |
10783 | else { | |
c84b06a4 | 10784 | if (mpt3sas_get_num_volumes(ioc)) |
7786ab6a SR |
10785 | ioc->hide_drives = 1; |
10786 | else | |
10787 | ioc->hide_drives = 0; | |
10788 | } | |
10789 | } else | |
10790 | ioc->hide_drives = 0; | |
7786ab6a | 10791 | |
b65f1d4d SR |
10792 | rv = scsi_add_host(shost, &pdev->dev); |
10793 | if (rv) { | |
4dc06fd8 RS |
10794 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
10795 | ioc->name, __FILE__, __LINE__, __func__); | |
4dc06fd8 RS |
10796 | goto out_add_shost_fail; |
10797 | } | |
10798 | ||
f92363d1 SR |
10799 | scsi_scan_host(shost); |
10800 | return 0; | |
4dc06fd8 RS |
10801 | out_add_shost_fail: |
10802 | mpt3sas_base_detach(ioc); | |
f92363d1 SR |
10803 | out_attach_fail: |
10804 | destroy_workqueue(ioc->firmware_event_thread); | |
10805 | out_thread_fail: | |
08c4d550 | 10806 | spin_lock(&gioc_lock); |
f92363d1 | 10807 | list_del(&ioc->list); |
08c4d550 | 10808 | spin_unlock(&gioc_lock); |
f92363d1 | 10809 | scsi_host_put(shost); |
b65f1d4d | 10810 | return rv; |
f92363d1 SR |
10811 | } |
10812 | ||
10813 | #ifdef CONFIG_PM | |
10814 | /** | |
8a7e4c24 | 10815 | * scsih_suspend - power management suspend main entry point |
f92363d1 SR |
10816 | * @pdev: PCI device struct |
10817 | * @state: PM state change to (usually PCI_D3) | |
10818 | * | |
10819 | * Returns 0 success, anything else error. | |
10820 | */ | |
8bbb1cf6 | 10821 | static int |
8a7e4c24 | 10822 | scsih_suspend(struct pci_dev *pdev, pm_message_t state) |
f92363d1 SR |
10823 | { |
10824 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10825 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10826 | pci_power_t device_state; | |
10827 | ||
10828 | mpt3sas_base_stop_watchdog(ioc); | |
10829 | flush_scheduled_work(); | |
10830 | scsi_block_requests(shost); | |
10831 | device_state = pci_choose_state(pdev, state); | |
10832 | pr_info(MPT3SAS_FMT | |
10833 | "pdev=0x%p, slot=%s, entering operating state [D%d]\n", | |
10834 | ioc->name, pdev, pci_name(pdev), device_state); | |
10835 | ||
10836 | pci_save_state(pdev); | |
10837 | mpt3sas_base_free_resources(ioc); | |
10838 | pci_set_power_state(pdev, device_state); | |
10839 | return 0; | |
10840 | } | |
10841 | ||
10842 | /** | |
8a7e4c24 | 10843 | * scsih_resume - power management resume main entry point |
f92363d1 SR |
10844 | * @pdev: PCI device struct |
10845 | * | |
10846 | * Returns 0 success, anything else error. | |
10847 | */ | |
8bbb1cf6 | 10848 | static int |
8a7e4c24 | 10849 | scsih_resume(struct pci_dev *pdev) |
f92363d1 SR |
10850 | { |
10851 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10852 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10853 | pci_power_t device_state = pdev->current_state; | |
10854 | int r; | |
10855 | ||
10856 | pr_info(MPT3SAS_FMT | |
10857 | "pdev=0x%p, slot=%s, previous operating state [D%d]\n", | |
10858 | ioc->name, pdev, pci_name(pdev), device_state); | |
10859 | ||
10860 | pci_set_power_state(pdev, PCI_D0); | |
10861 | pci_enable_wake(pdev, PCI_D0, 0); | |
10862 | pci_restore_state(pdev); | |
10863 | ioc->pdev = pdev; | |
10864 | r = mpt3sas_base_map_resources(ioc); | |
10865 | if (r) | |
10866 | return r; | |
10867 | ||
98c56ad3 | 10868 | mpt3sas_base_hard_reset_handler(ioc, SOFT_RESET); |
f92363d1 SR |
10869 | scsi_unblock_requests(shost); |
10870 | mpt3sas_base_start_watchdog(ioc); | |
10871 | return 0; | |
10872 | } | |
10873 | #endif /* CONFIG_PM */ | |
10874 | ||
10875 | /** | |
8a7e4c24 | 10876 | * scsih_pci_error_detected - Called when a PCI error is detected. |
f92363d1 SR |
10877 | * @pdev: PCI device struct |
10878 | * @state: PCI channel state | |
10879 | * | |
10880 | * Description: Called when a PCI error is detected. | |
10881 | * | |
10882 | * Return value: | |
10883 | * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT | |
10884 | */ | |
8bbb1cf6 | 10885 | static pci_ers_result_t |
8a7e4c24 | 10886 | scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
f92363d1 SR |
10887 | { |
10888 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10889 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10890 | ||
10891 | pr_info(MPT3SAS_FMT "PCI error: detected callback, state(%d)!!\n", | |
10892 | ioc->name, state); | |
10893 | ||
10894 | switch (state) { | |
10895 | case pci_channel_io_normal: | |
10896 | return PCI_ERS_RESULT_CAN_RECOVER; | |
10897 | case pci_channel_io_frozen: | |
10898 | /* Fatal error, prepare for slot reset */ | |
10899 | ioc->pci_error_recovery = 1; | |
10900 | scsi_block_requests(ioc->shost); | |
10901 | mpt3sas_base_stop_watchdog(ioc); | |
10902 | mpt3sas_base_free_resources(ioc); | |
10903 | return PCI_ERS_RESULT_NEED_RESET; | |
10904 | case pci_channel_io_perm_failure: | |
10905 | /* Permanent error, prepare for device removal */ | |
10906 | ioc->pci_error_recovery = 1; | |
10907 | mpt3sas_base_stop_watchdog(ioc); | |
10908 | _scsih_flush_running_cmds(ioc); | |
10909 | return PCI_ERS_RESULT_DISCONNECT; | |
10910 | } | |
10911 | return PCI_ERS_RESULT_NEED_RESET; | |
10912 | } | |
10913 | ||
10914 | /** | |
8a7e4c24 | 10915 | * scsih_pci_slot_reset - Called when PCI slot has been reset. |
f92363d1 SR |
10916 | * @pdev: PCI device struct |
10917 | * | |
10918 | * Description: This routine is called by the pci error recovery | |
10919 | * code after the PCI slot has been reset, just before we | |
10920 | * should resume normal operations. | |
10921 | */ | |
8bbb1cf6 | 10922 | static pci_ers_result_t |
8a7e4c24 | 10923 | scsih_pci_slot_reset(struct pci_dev *pdev) |
f92363d1 SR |
10924 | { |
10925 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10926 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10927 | int rc; | |
10928 | ||
10929 | pr_info(MPT3SAS_FMT "PCI error: slot reset callback!!\n", | |
10930 | ioc->name); | |
10931 | ||
10932 | ioc->pci_error_recovery = 0; | |
10933 | ioc->pdev = pdev; | |
10934 | pci_restore_state(pdev); | |
10935 | rc = mpt3sas_base_map_resources(ioc); | |
10936 | if (rc) | |
10937 | return PCI_ERS_RESULT_DISCONNECT; | |
10938 | ||
98c56ad3 | 10939 | rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
f92363d1 SR |
10940 | |
10941 | pr_warn(MPT3SAS_FMT "hard reset: %s\n", ioc->name, | |
10942 | (rc == 0) ? "success" : "failed"); | |
10943 | ||
10944 | if (!rc) | |
10945 | return PCI_ERS_RESULT_RECOVERED; | |
10946 | else | |
10947 | return PCI_ERS_RESULT_DISCONNECT; | |
10948 | } | |
10949 | ||
10950 | /** | |
8a7e4c24 | 10951 | * scsih_pci_resume() - resume normal ops after PCI reset |
f92363d1 SR |
10952 | * @pdev: pointer to PCI device |
10953 | * | |
10954 | * Called when the error recovery driver tells us that its | |
10955 | * OK to resume normal operation. Use completion to allow | |
10956 | * halted scsi ops to resume. | |
10957 | */ | |
8bbb1cf6 | 10958 | static void |
8a7e4c24 | 10959 | scsih_pci_resume(struct pci_dev *pdev) |
f92363d1 SR |
10960 | { |
10961 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10962 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10963 | ||
10964 | pr_info(MPT3SAS_FMT "PCI error: resume callback!!\n", ioc->name); | |
10965 | ||
10966 | pci_cleanup_aer_uncorrect_error_status(pdev); | |
10967 | mpt3sas_base_start_watchdog(ioc); | |
10968 | scsi_unblock_requests(ioc->shost); | |
10969 | } | |
10970 | ||
10971 | /** | |
8a7e4c24 | 10972 | * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers |
f92363d1 SR |
10973 | * @pdev: pointer to PCI device |
10974 | */ | |
8bbb1cf6 | 10975 | static pci_ers_result_t |
8a7e4c24 | 10976 | scsih_pci_mmio_enabled(struct pci_dev *pdev) |
f92363d1 SR |
10977 | { |
10978 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10979 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10980 | ||
10981 | pr_info(MPT3SAS_FMT "PCI error: mmio enabled callback!!\n", | |
10982 | ioc->name); | |
10983 | ||
10984 | /* TODO - dump whatever for debugging purposes */ | |
10985 | ||
83c3d340 KW |
10986 | /* This called only if scsih_pci_error_detected returns |
10987 | * PCI_ERS_RESULT_CAN_RECOVER. Read/write to the device still | |
10988 | * works, no need to reset slot. | |
10989 | */ | |
10990 | return PCI_ERS_RESULT_RECOVERED; | |
f92363d1 SR |
10991 | } |
10992 | ||
307d9075 AM |
10993 | /** |
10994 | * scsih__ncq_prio_supp - Check for NCQ command priority support | |
10995 | * @sdev: scsi device struct | |
10996 | * | |
10997 | * This is called when a user indicates they would like to enable | |
10998 | * ncq command priorities. This works only on SATA devices. | |
10999 | */ | |
11000 | bool scsih_ncq_prio_supp(struct scsi_device *sdev) | |
11001 | { | |
11002 | unsigned char *buf; | |
11003 | bool ncq_prio_supp = false; | |
11004 | ||
11005 | if (!scsi_device_supports_vpd(sdev)) | |
11006 | return ncq_prio_supp; | |
11007 | ||
11008 | buf = kmalloc(SCSI_VPD_PG_LEN, GFP_KERNEL); | |
11009 | if (!buf) | |
11010 | return ncq_prio_supp; | |
11011 | ||
11012 | if (!scsi_get_vpd_page(sdev, 0x89, buf, SCSI_VPD_PG_LEN)) | |
11013 | ncq_prio_supp = (buf[213] >> 4) & 1; | |
11014 | ||
11015 | kfree(buf); | |
11016 | return ncq_prio_supp; | |
11017 | } | |
c84b06a4 SR |
11018 | /* |
11019 | * The pci device ids are defined in mpi/mpi2_cnfg.h. | |
11020 | */ | |
11021 | static const struct pci_device_id mpt3sas_pci_table[] = { | |
11022 | /* Spitfire ~ 2004 */ | |
11023 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004, | |
11024 | PCI_ANY_ID, PCI_ANY_ID }, | |
11025 | /* Falcon ~ 2008 */ | |
11026 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008, | |
11027 | PCI_ANY_ID, PCI_ANY_ID }, | |
11028 | /* Liberator ~ 2108 */ | |
11029 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1, | |
11030 | PCI_ANY_ID, PCI_ANY_ID }, | |
11031 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2, | |
11032 | PCI_ANY_ID, PCI_ANY_ID }, | |
11033 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3, | |
11034 | PCI_ANY_ID, PCI_ANY_ID }, | |
11035 | /* Meteor ~ 2116 */ | |
11036 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1, | |
11037 | PCI_ANY_ID, PCI_ANY_ID }, | |
11038 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2, | |
11039 | PCI_ANY_ID, PCI_ANY_ID }, | |
11040 | /* Thunderbolt ~ 2208 */ | |
11041 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1, | |
11042 | PCI_ANY_ID, PCI_ANY_ID }, | |
11043 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2, | |
11044 | PCI_ANY_ID, PCI_ANY_ID }, | |
11045 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3, | |
11046 | PCI_ANY_ID, PCI_ANY_ID }, | |
11047 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4, | |
11048 | PCI_ANY_ID, PCI_ANY_ID }, | |
11049 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5, | |
11050 | PCI_ANY_ID, PCI_ANY_ID }, | |
11051 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6, | |
11052 | PCI_ANY_ID, PCI_ANY_ID }, | |
11053 | /* Mustang ~ 2308 */ | |
11054 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1, | |
11055 | PCI_ANY_ID, PCI_ANY_ID }, | |
11056 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2, | |
11057 | PCI_ANY_ID, PCI_ANY_ID }, | |
11058 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3, | |
11059 | PCI_ANY_ID, PCI_ANY_ID }, | |
c520691b SPS |
11060 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_MPI_EP, |
11061 | PCI_ANY_ID, PCI_ANY_ID }, | |
c84b06a4 SR |
11062 | /* SSS6200 */ |
11063 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200, | |
11064 | PCI_ANY_ID, PCI_ANY_ID }, | |
11065 | /* Fury ~ 3004 and 3008 */ | |
11066 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3004, | |
11067 | PCI_ANY_ID, PCI_ANY_ID }, | |
11068 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3008, | |
11069 | PCI_ANY_ID, PCI_ANY_ID }, | |
11070 | /* Invader ~ 3108 */ | |
11071 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_1, | |
11072 | PCI_ANY_ID, PCI_ANY_ID }, | |
11073 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_2, | |
11074 | PCI_ANY_ID, PCI_ANY_ID }, | |
11075 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_5, | |
11076 | PCI_ANY_ID, PCI_ANY_ID }, | |
11077 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_6, | |
11078 | PCI_ANY_ID, PCI_ANY_ID }, | |
b130b0d5 SS |
11079 | /* Cutlass ~ 3216 and 3224 */ |
11080 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3216, | |
11081 | PCI_ANY_ID, PCI_ANY_ID }, | |
11082 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3224, | |
11083 | PCI_ANY_ID, PCI_ANY_ID }, | |
11084 | /* Intruder ~ 3316 and 3324 */ | |
11085 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_1, | |
11086 | PCI_ANY_ID, PCI_ANY_ID }, | |
11087 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_2, | |
11088 | PCI_ANY_ID, PCI_ANY_ID }, | |
11089 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_3, | |
11090 | PCI_ANY_ID, PCI_ANY_ID }, | |
11091 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_4, | |
11092 | PCI_ANY_ID, PCI_ANY_ID }, | |
11093 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_1, | |
11094 | PCI_ANY_ID, PCI_ANY_ID }, | |
11095 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_2, | |
11096 | PCI_ANY_ID, PCI_ANY_ID }, | |
11097 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_3, | |
11098 | PCI_ANY_ID, PCI_ANY_ID }, | |
11099 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_4, | |
11100 | PCI_ANY_ID, PCI_ANY_ID }, | |
998f26ae SPS |
11101 | /* Ventura, Crusader, Harpoon & Tomcat ~ 3516, 3416, 3508 & 3408*/ |
11102 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3508, | |
11103 | PCI_ANY_ID, PCI_ANY_ID }, | |
11104 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3508_1, | |
11105 | PCI_ANY_ID, PCI_ANY_ID }, | |
11106 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3408, | |
11107 | PCI_ANY_ID, PCI_ANY_ID }, | |
11108 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3516, | |
11109 | PCI_ANY_ID, PCI_ANY_ID }, | |
11110 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3516_1, | |
11111 | PCI_ANY_ID, PCI_ANY_ID }, | |
11112 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3416, | |
11113 | PCI_ANY_ID, PCI_ANY_ID }, | |
15fd7c74 SR |
11114 | /* Mercator ~ 3616*/ |
11115 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3616, | |
11116 | PCI_ANY_ID, PCI_ANY_ID }, | |
c84b06a4 SR |
11117 | {0} /* Terminating entry */ |
11118 | }; | |
11119 | MODULE_DEVICE_TABLE(pci, mpt3sas_pci_table); | |
11120 | ||
11121 | static struct pci_error_handlers _mpt3sas_err_handler = { | |
11122 | .error_detected = scsih_pci_error_detected, | |
11123 | .mmio_enabled = scsih_pci_mmio_enabled, | |
11124 | .slot_reset = scsih_pci_slot_reset, | |
11125 | .resume = scsih_pci_resume, | |
11126 | }; | |
11127 | ||
11128 | static struct pci_driver mpt3sas_driver = { | |
11129 | .name = MPT3SAS_DRIVER_NAME, | |
11130 | .id_table = mpt3sas_pci_table, | |
11131 | .probe = _scsih_probe, | |
11132 | .remove = scsih_remove, | |
11133 | .shutdown = scsih_shutdown, | |
11134 | .err_handler = &_mpt3sas_err_handler, | |
11135 | #ifdef CONFIG_PM | |
11136 | .suspend = scsih_suspend, | |
11137 | .resume = scsih_resume, | |
11138 | #endif | |
11139 | }; | |
11140 | ||
f92363d1 | 11141 | /** |
8a7e4c24 | 11142 | * scsih_init - main entry point for this driver. |
f92363d1 SR |
11143 | * |
11144 | * Returns 0 success, anything else error. | |
11145 | */ | |
8bbb1cf6 | 11146 | static int |
8a7e4c24 | 11147 | scsih_init(void) |
f92363d1 | 11148 | { |
c84b06a4 SR |
11149 | mpt2_ids = 0; |
11150 | mpt3_ids = 0; | |
f92363d1 | 11151 | |
f92363d1 SR |
11152 | mpt3sas_base_initialize_callback_handler(); |
11153 | ||
11154 | /* queuecommand callback hander */ | |
11155 | scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done); | |
11156 | ||
6c7abffc | 11157 | /* task management callback handler */ |
f92363d1 SR |
11158 | tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done); |
11159 | ||
11160 | /* base internal commands callback handler */ | |
11161 | base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done); | |
11162 | port_enable_cb_idx = mpt3sas_base_register_callback_handler( | |
11163 | mpt3sas_port_enable_done); | |
11164 | ||
11165 | /* transport internal commands callback handler */ | |
11166 | transport_cb_idx = mpt3sas_base_register_callback_handler( | |
11167 | mpt3sas_transport_done); | |
11168 | ||
11169 | /* scsih internal commands callback handler */ | |
11170 | scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done); | |
11171 | ||
11172 | /* configuration page API internal commands callback handler */ | |
11173 | config_cb_idx = mpt3sas_base_register_callback_handler( | |
11174 | mpt3sas_config_done); | |
11175 | ||
11176 | /* ctl module callback handler */ | |
11177 | ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done); | |
11178 | ||
11179 | tm_tr_cb_idx = mpt3sas_base_register_callback_handler( | |
11180 | _scsih_tm_tr_complete); | |
11181 | ||
11182 | tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler( | |
11183 | _scsih_tm_volume_tr_complete); | |
11184 | ||
11185 | tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler( | |
11186 | _scsih_sas_control_complete); | |
11187 | ||
7497392a | 11188 | return 0; |
f92363d1 SR |
11189 | } |
11190 | ||
11191 | /** | |
7497392a | 11192 | * scsih_exit - exit point for this driver (when it is a module). |
f92363d1 SR |
11193 | * |
11194 | * Returns 0 success, anything else error. | |
11195 | */ | |
8bbb1cf6 | 11196 | static void |
8a7e4c24 | 11197 | scsih_exit(void) |
f92363d1 | 11198 | { |
f92363d1 SR |
11199 | |
11200 | mpt3sas_base_release_callback_handler(scsi_io_cb_idx); | |
11201 | mpt3sas_base_release_callback_handler(tm_cb_idx); | |
11202 | mpt3sas_base_release_callback_handler(base_cb_idx); | |
11203 | mpt3sas_base_release_callback_handler(port_enable_cb_idx); | |
11204 | mpt3sas_base_release_callback_handler(transport_cb_idx); | |
11205 | mpt3sas_base_release_callback_handler(scsih_cb_idx); | |
11206 | mpt3sas_base_release_callback_handler(config_cb_idx); | |
11207 | mpt3sas_base_release_callback_handler(ctl_cb_idx); | |
11208 | ||
11209 | mpt3sas_base_release_callback_handler(tm_tr_cb_idx); | |
11210 | mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx); | |
11211 | mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx); | |
11212 | ||
11213 | /* raid transport support */ | |
c84b06a4 SR |
11214 | if (hbas_to_enumerate != 1) |
11215 | raid_class_release(mpt3sas_raid_template); | |
11216 | if (hbas_to_enumerate != 2) | |
11217 | raid_class_release(mpt2sas_raid_template); | |
f92363d1 SR |
11218 | sas_release_transport(mpt3sas_transport_template); |
11219 | } | |
7786ab6a | 11220 | |
c84b06a4 SR |
11221 | /** |
11222 | * _mpt3sas_init - main entry point for this driver. | |
11223 | * | |
11224 | * Returns 0 success, anything else error. | |
11225 | */ | |
11226 | static int __init | |
11227 | _mpt3sas_init(void) | |
11228 | { | |
11229 | int error; | |
11230 | ||
11231 | pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME, | |
11232 | MPT3SAS_DRIVER_VERSION); | |
11233 | ||
11234 | mpt3sas_transport_template = | |
11235 | sas_attach_transport(&mpt3sas_transport_functions); | |
11236 | if (!mpt3sas_transport_template) | |
11237 | return -ENODEV; | |
11238 | ||
11239 | /* No need attach mpt3sas raid functions template | |
11240 | * if hbas_to_enumarate value is one. | |
11241 | */ | |
11242 | if (hbas_to_enumerate != 1) { | |
11243 | mpt3sas_raid_template = | |
11244 | raid_class_attach(&mpt3sas_raid_functions); | |
11245 | if (!mpt3sas_raid_template) { | |
11246 | sas_release_transport(mpt3sas_transport_template); | |
11247 | return -ENODEV; | |
11248 | } | |
11249 | } | |
11250 | ||
11251 | /* No need to attach mpt2sas raid functions template | |
11252 | * if hbas_to_enumarate value is two | |
11253 | */ | |
11254 | if (hbas_to_enumerate != 2) { | |
11255 | mpt2sas_raid_template = | |
11256 | raid_class_attach(&mpt2sas_raid_functions); | |
11257 | if (!mpt2sas_raid_template) { | |
11258 | sas_release_transport(mpt3sas_transport_template); | |
11259 | return -ENODEV; | |
11260 | } | |
11261 | } | |
11262 | ||
11263 | error = scsih_init(); | |
11264 | if (error) { | |
11265 | scsih_exit(); | |
11266 | return error; | |
11267 | } | |
11268 | ||
11269 | mpt3sas_ctl_init(hbas_to_enumerate); | |
11270 | ||
11271 | error = pci_register_driver(&mpt3sas_driver); | |
11272 | if (error) | |
11273 | scsih_exit(); | |
11274 | ||
11275 | return error; | |
11276 | } | |
11277 | ||
11278 | /** | |
11279 | * _mpt3sas_exit - exit point for this driver (when it is a module). | |
11280 | * | |
11281 | */ | |
11282 | static void __exit | |
11283 | _mpt3sas_exit(void) | |
11284 | { | |
11285 | pr_info("mpt3sas version %s unloading\n", | |
11286 | MPT3SAS_DRIVER_VERSION); | |
11287 | ||
c84b06a4 SR |
11288 | mpt3sas_ctl_exit(hbas_to_enumerate); |
11289 | ||
87b3576e C |
11290 | pci_unregister_driver(&mpt3sas_driver); |
11291 | ||
c84b06a4 SR |
11292 | scsih_exit(); |
11293 | } | |
11294 | ||
11295 | module_init(_mpt3sas_init); | |
11296 | module_exit(_mpt3sas_exit); |