]>
Commit | Line | Data |
---|---|---|
f92363d1 SR |
1 | /* |
2 | * Scsi Host Layer for MPT (Message Passing Technology) based controllers | |
3 | * | |
4 | * This code is based on drivers/scsi/mpt3sas/mpt3sas_scsih.c | |
a4ffce0d | 5 | * Copyright (C) 2012-2014 LSI Corporation |
a03bd153 SR |
6 | * Copyright (C) 2013-2014 Avago Technologies |
7 | * (mailto: MPT-FusionLinux.pdl@avagotech.com) | |
f92363d1 SR |
8 | * |
9 | * This program is free software; you can redistribute it and/or | |
10 | * modify it under the terms of the GNU General Public License | |
11 | * as published by the Free Software Foundation; either version 2 | |
12 | * of the License, or (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * NO WARRANTY | |
20 | * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR | |
21 | * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT | |
22 | * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, | |
23 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is | |
24 | * solely responsible for determining the appropriateness of using and | |
25 | * distributing the Program and assumes all risks associated with its | |
26 | * exercise of rights under this Agreement, including but not limited to | |
27 | * the risks and costs of program errors, damage to or loss of data, | |
28 | * programs or equipment, and unavailability or interruption of operations. | |
29 | ||
30 | * DISCLAIMER OF LIABILITY | |
31 | * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY | |
32 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
33 | * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND | |
34 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | |
35 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
36 | * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED | |
37 | * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES | |
38 | ||
39 | * You should have received a copy of the GNU General Public License | |
40 | * along with this program; if not, write to the Free Software | |
41 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | |
42 | * USA. | |
43 | */ | |
44 | ||
f92363d1 SR |
45 | #include <linux/module.h> |
46 | #include <linux/kernel.h> | |
47 | #include <linux/init.h> | |
48 | #include <linux/errno.h> | |
49 | #include <linux/blkdev.h> | |
50 | #include <linux/sched.h> | |
51 | #include <linux/workqueue.h> | |
52 | #include <linux/delay.h> | |
53 | #include <linux/pci.h> | |
ffdadd68 | 54 | #include <linux/pci-aspm.h> |
f92363d1 SR |
55 | #include <linux/interrupt.h> |
56 | #include <linux/aer.h> | |
57 | #include <linux/raid_class.h> | |
7786ab6a | 58 | #include <asm/unaligned.h> |
f92363d1 SR |
59 | |
60 | #include "mpt3sas_base.h" | |
61 | ||
f92363d1 | 62 | #define RAID_CHANNEL 1 |
d88e1eab SPS |
63 | |
64 | #define PCIE_CHANNEL 2 | |
65 | ||
f92363d1 SR |
66 | /* forward proto's */ |
67 | static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc, | |
68 | struct _sas_node *sas_expander); | |
69 | static void _firmware_event_work(struct work_struct *work); | |
70 | ||
71 | static void _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc, | |
72 | struct _sas_device *sas_device); | |
73 | static int _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, | |
74 | u8 retry_count, u8 is_pd); | |
c102e00c | 75 | static int _scsih_pcie_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle); |
3075ac49 SPS |
76 | static void _scsih_pcie_device_remove_from_sml(struct MPT3SAS_ADAPTER *ioc, |
77 | struct _pcie_device *pcie_device); | |
4318c734 SPS |
78 | static void |
79 | _scsih_pcie_check_device(struct MPT3SAS_ADAPTER *ioc, u16 handle); | |
f92363d1 SR |
80 | static u8 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid); |
81 | ||
f92363d1 SR |
82 | /* global parameters */ |
83 | LIST_HEAD(mpt3sas_ioc_list); | |
08c4d550 SR |
84 | /* global ioc lock for list operations */ |
85 | DEFINE_SPINLOCK(gioc_lock); | |
f92363d1 | 86 | |
c84b06a4 SR |
87 | MODULE_AUTHOR(MPT3SAS_AUTHOR); |
88 | MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION); | |
89 | MODULE_LICENSE("GPL"); | |
90 | MODULE_VERSION(MPT3SAS_DRIVER_VERSION); | |
91 | MODULE_ALIAS("mpt2sas"); | |
92 | ||
f92363d1 SR |
93 | /* local parameters */ |
94 | static u8 scsi_io_cb_idx = -1; | |
95 | static u8 tm_cb_idx = -1; | |
96 | static u8 ctl_cb_idx = -1; | |
97 | static u8 base_cb_idx = -1; | |
98 | static u8 port_enable_cb_idx = -1; | |
99 | static u8 transport_cb_idx = -1; | |
100 | static u8 scsih_cb_idx = -1; | |
101 | static u8 config_cb_idx = -1; | |
c84b06a4 SR |
102 | static int mpt2_ids; |
103 | static int mpt3_ids; | |
f92363d1 SR |
104 | |
105 | static u8 tm_tr_cb_idx = -1 ; | |
106 | static u8 tm_tr_volume_cb_idx = -1 ; | |
107 | static u8 tm_sas_control_cb_idx = -1; | |
108 | ||
109 | /* command line options */ | |
110 | static u32 logging_level; | |
111 | MODULE_PARM_DESC(logging_level, | |
112 | " bits for enabling additional logging info (default=0)"); | |
113 | ||
114 | ||
115 | static ushort max_sectors = 0xFFFF; | |
116 | module_param(max_sectors, ushort, 0); | |
117 | MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767"); | |
118 | ||
119 | ||
120 | static int missing_delay[2] = {-1, -1}; | |
121 | module_param_array(missing_delay, int, NULL, 0); | |
122 | MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay"); | |
123 | ||
124 | /* scsi-mid layer global parmeter is max_report_luns, which is 511 */ | |
125 | #define MPT3SAS_MAX_LUN (16895) | |
1abf635d HR |
126 | static u64 max_lun = MPT3SAS_MAX_LUN; |
127 | module_param(max_lun, ullong, 0); | |
f92363d1 SR |
128 | MODULE_PARM_DESC(max_lun, " max lun, default=16895 "); |
129 | ||
c84b06a4 SR |
130 | static ushort hbas_to_enumerate; |
131 | module_param(hbas_to_enumerate, ushort, 0); | |
132 | MODULE_PARM_DESC(hbas_to_enumerate, | |
133 | " 0 - enumerates both SAS 2.0 & SAS 3.0 generation HBAs\n \ | |
134 | 1 - enumerates only SAS 2.0 generation HBAs\n \ | |
135 | 2 - enumerates only SAS 3.0 generation HBAs (default=0)"); | |
f92363d1 SR |
136 | |
137 | /* diag_buffer_enable is bitwise | |
138 | * bit 0 set = TRACE | |
139 | * bit 1 set = SNAPSHOT | |
140 | * bit 2 set = EXTENDED | |
141 | * | |
142 | * Either bit can be set, or both | |
143 | */ | |
144 | static int diag_buffer_enable = -1; | |
145 | module_param(diag_buffer_enable, int, 0); | |
146 | MODULE_PARM_DESC(diag_buffer_enable, | |
147 | " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)"); | |
148 | static int disable_discovery = -1; | |
149 | module_param(disable_discovery, int, 0); | |
150 | MODULE_PARM_DESC(disable_discovery, " disable discovery "); | |
151 | ||
152 | ||
153 | /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */ | |
154 | static int prot_mask = -1; | |
155 | module_param(prot_mask, int, 0); | |
156 | MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 "); | |
157 | ||
158 | ||
159 | /* raid transport support */ | |
7497392a | 160 | struct raid_template *mpt3sas_raid_template; |
c84b06a4 | 161 | struct raid_template *mpt2sas_raid_template; |
f92363d1 SR |
162 | |
163 | ||
164 | /** | |
165 | * struct sense_info - common structure for obtaining sense keys | |
166 | * @skey: sense key | |
167 | * @asc: additional sense code | |
168 | * @ascq: additional sense code qualifier | |
169 | */ | |
170 | struct sense_info { | |
171 | u8 skey; | |
172 | u8 asc; | |
173 | u8 ascq; | |
174 | }; | |
175 | ||
176 | #define MPT3SAS_PROCESS_TRIGGER_DIAG (0xFFFB) | |
0f624c39 | 177 | #define MPT3SAS_TURN_ON_PFA_LED (0xFFFC) |
f92363d1 SR |
178 | #define MPT3SAS_PORT_ENABLE_COMPLETE (0xFFFD) |
179 | #define MPT3SAS_ABRT_TASK_SET (0xFFFE) | |
180 | #define MPT3SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF) | |
181 | /** | |
182 | * struct fw_event_work - firmware event struct | |
183 | * @list: link list framework | |
184 | * @work: work object (ioc->fault_reset_work_q) | |
f92363d1 SR |
185 | * @ioc: per adapter object |
186 | * @device_handle: device handle | |
187 | * @VF_ID: virtual function id | |
188 | * @VP_ID: virtual port id | |
189 | * @ignore: flag meaning this event has been marked to ignore | |
b8ac0cc7 JL |
190 | * @event: firmware event MPI2_EVENT_XXX defined in mpi2_ioc.h |
191 | * @refcount: kref for this event | |
f92363d1 SR |
192 | * @event_data: reply event data payload follows |
193 | * | |
194 | * This object stored on ioc->fw_event_list. | |
195 | */ | |
196 | struct fw_event_work { | |
197 | struct list_head list; | |
198 | struct work_struct work; | |
f92363d1 SR |
199 | |
200 | struct MPT3SAS_ADAPTER *ioc; | |
201 | u16 device_handle; | |
202 | u8 VF_ID; | |
203 | u8 VP_ID; | |
204 | u8 ignore; | |
205 | u16 event; | |
146b16c8 | 206 | struct kref refcount; |
35b62362 | 207 | char event_data[0] __aligned(4); |
f92363d1 SR |
208 | }; |
209 | ||
146b16c8 SR |
210 | static void fw_event_work_free(struct kref *r) |
211 | { | |
212 | kfree(container_of(r, struct fw_event_work, refcount)); | |
213 | } | |
214 | ||
215 | static void fw_event_work_get(struct fw_event_work *fw_work) | |
216 | { | |
217 | kref_get(&fw_work->refcount); | |
218 | } | |
219 | ||
220 | static void fw_event_work_put(struct fw_event_work *fw_work) | |
221 | { | |
222 | kref_put(&fw_work->refcount, fw_event_work_free); | |
223 | } | |
224 | ||
225 | static struct fw_event_work *alloc_fw_event_work(int len) | |
226 | { | |
227 | struct fw_event_work *fw_event; | |
228 | ||
229 | fw_event = kzalloc(sizeof(*fw_event) + len, GFP_ATOMIC); | |
230 | if (!fw_event) | |
231 | return NULL; | |
232 | ||
233 | kref_init(&fw_event->refcount); | |
234 | return fw_event; | |
235 | } | |
236 | ||
f92363d1 SR |
237 | /** |
238 | * struct _scsi_io_transfer - scsi io transfer | |
239 | * @handle: sas device handle (assigned by firmware) | |
240 | * @is_raid: flag set for hidden raid components | |
241 | * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE, | |
242 | * @data_length: data transfer length | |
243 | * @data_dma: dma pointer to data | |
244 | * @sense: sense data | |
245 | * @lun: lun number | |
246 | * @cdb_length: cdb length | |
247 | * @cdb: cdb contents | |
248 | * @timeout: timeout for this command | |
249 | * @VF_ID: virtual function id | |
250 | * @VP_ID: virtual port id | |
251 | * @valid_reply: flag set for reply message | |
252 | * @sense_length: sense length | |
253 | * @ioc_status: ioc status | |
254 | * @scsi_state: scsi state | |
255 | * @scsi_status: scsi staus | |
256 | * @log_info: log information | |
257 | * @transfer_length: data length transfer when there is a reply message | |
258 | * | |
259 | * Used for sending internal scsi commands to devices within this module. | |
260 | * Refer to _scsi_send_scsi_io(). | |
261 | */ | |
262 | struct _scsi_io_transfer { | |
263 | u16 handle; | |
264 | u8 is_raid; | |
265 | enum dma_data_direction dir; | |
266 | u32 data_length; | |
267 | dma_addr_t data_dma; | |
268 | u8 sense[SCSI_SENSE_BUFFERSIZE]; | |
269 | u32 lun; | |
270 | u8 cdb_length; | |
271 | u8 cdb[32]; | |
272 | u8 timeout; | |
273 | u8 VF_ID; | |
274 | u8 VP_ID; | |
275 | u8 valid_reply; | |
276 | /* the following bits are only valid when 'valid_reply = 1' */ | |
277 | u32 sense_length; | |
278 | u16 ioc_status; | |
279 | u8 scsi_state; | |
280 | u8 scsi_status; | |
281 | u32 log_info; | |
282 | u32 transfer_length; | |
283 | }; | |
284 | ||
f92363d1 SR |
285 | /** |
286 | * _scsih_set_debug_level - global setting of ioc->logging_level. | |
287 | * | |
288 | * Note: The logging levels are defined in mpt3sas_debug.h. | |
289 | */ | |
290 | static int | |
291 | _scsih_set_debug_level(const char *val, struct kernel_param *kp) | |
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 | */ | |
602 | struct _pcie_device * | |
603 | mpt3sas_get_pdev_from_target(struct MPT3SAS_ADAPTER *ioc, | |
604 | struct MPT3SAS_TARGET *tgt_priv) | |
605 | { | |
606 | struct _pcie_device *ret; | |
607 | 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 SPS |
944 | |
945 | struct _pcie_device * | |
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 | */ | |
978 | struct _pcie_device * | |
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 | ||
992 | struct _pcie_device * | |
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 | ||
1015 | ||
1016 | /** | |
1017 | * mpt3sas_get_pdev_by_idchannel - pcie device search | |
1018 | * @ioc: per adapter object | |
1019 | * @id: Target ID | |
1020 | * @channel: Channel ID | |
1021 | * | |
1022 | * Context: This function will acquire ioc->pcie_device_lock and will release | |
1023 | * before returning the pcie_device object. | |
1024 | * | |
1025 | * This searches for pcie_device based on id and channel, then return | |
1026 | * pcie_device object. | |
1027 | */ | |
1028 | struct _pcie_device * | |
1029 | mpt3sas_get_pdev_by_idchannel(struct MPT3SAS_ADAPTER *ioc, int id, int channel) | |
1030 | { | |
1031 | struct _pcie_device *pcie_device; | |
1032 | unsigned long flags; | |
1033 | ||
1034 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1035 | pcie_device = __mpt3sas_get_pdev_by_idchannel(ioc, id, channel); | |
1036 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1037 | ||
1038 | return pcie_device; | |
1039 | } | |
c102e00c SPS |
1040 | |
1041 | ||
1042 | struct _pcie_device * | |
1043 | __mpt3sas_get_pdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
1044 | { | |
1045 | struct _pcie_device *pcie_device; | |
1046 | ||
1047 | assert_spin_locked(&ioc->pcie_device_lock); | |
1048 | ||
1049 | list_for_each_entry(pcie_device, &ioc->pcie_device_list, list) | |
1050 | if (pcie_device->handle == handle) | |
1051 | goto found_device; | |
1052 | ||
1053 | list_for_each_entry(pcie_device, &ioc->pcie_device_init_list, list) | |
1054 | if (pcie_device->handle == handle) | |
1055 | goto found_device; | |
1056 | ||
1057 | return NULL; | |
1058 | ||
1059 | found_device: | |
1060 | pcie_device_get(pcie_device); | |
1061 | return pcie_device; | |
1062 | } | |
1063 | ||
1064 | ||
1065 | /** | |
1066 | * mpt3sas_get_pdev_by_handle - pcie device search | |
1067 | * @ioc: per adapter object | |
1068 | * @handle: Firmware device handle | |
1069 | * | |
1070 | * Context: This function will acquire ioc->pcie_device_lock and will release | |
1071 | * before returning the pcie_device object. | |
1072 | * | |
1073 | * This searches for pcie_device based on handle, then return pcie_device | |
1074 | * object. | |
1075 | */ | |
1076 | struct _pcie_device * | |
1077 | mpt3sas_get_pdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
1078 | { | |
1079 | struct _pcie_device *pcie_device; | |
1080 | unsigned long flags; | |
1081 | ||
1082 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1083 | pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle); | |
1084 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1085 | ||
1086 | return pcie_device; | |
1087 | } | |
1088 | ||
d88e1eab SPS |
1089 | /** |
1090 | * _scsih_pcie_device_remove - remove pcie_device from list. | |
1091 | * @ioc: per adapter object | |
1092 | * @pcie_device: the pcie_device object | |
1093 | * Context: This function will acquire ioc->pcie_device_lock. | |
1094 | * | |
1095 | * If pcie_device is on the list, remove it and decrement its reference count. | |
1096 | */ | |
1097 | static void | |
1098 | _scsih_pcie_device_remove(struct MPT3SAS_ADAPTER *ioc, | |
1099 | struct _pcie_device *pcie_device) | |
1100 | { | |
1101 | unsigned long flags; | |
1102 | int was_on_pcie_device_list = 0; | |
1103 | ||
1104 | if (!pcie_device) | |
1105 | return; | |
1106 | pr_info(MPT3SAS_FMT | |
1107 | "removing handle(0x%04x), wwid(0x%016llx)\n", | |
1108 | ioc->name, pcie_device->handle, | |
1109 | (unsigned long long) pcie_device->wwid); | |
1110 | if (pcie_device->enclosure_handle != 0) | |
1111 | pr_info(MPT3SAS_FMT | |
1112 | "removing enclosure logical id(0x%016llx), slot(%d)\n", | |
1113 | ioc->name, | |
1114 | (unsigned long long)pcie_device->enclosure_logical_id, | |
1115 | pcie_device->slot); | |
1116 | if (pcie_device->connector_name[0] != '\0') | |
1117 | pr_info(MPT3SAS_FMT | |
1118 | "removing enclosure level(0x%04x), connector name( %s)\n", | |
1119 | ioc->name, pcie_device->enclosure_level, | |
1120 | pcie_device->connector_name); | |
1121 | ||
1122 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1123 | if (!list_empty(&pcie_device->list)) { | |
1124 | list_del_init(&pcie_device->list); | |
1125 | was_on_pcie_device_list = 1; | |
1126 | } | |
1127 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1128 | if (was_on_pcie_device_list) { | |
1129 | kfree(pcie_device->serial_number); | |
1130 | pcie_device_put(pcie_device); | |
1131 | } | |
1132 | } | |
3075ac49 SPS |
1133 | |
1134 | ||
1135 | /** | |
1136 | * _scsih_pcie_device_remove_by_handle - removing pcie device object by handle | |
1137 | * @ioc: per adapter object | |
1138 | * @handle: device handle | |
1139 | * | |
1140 | * Return nothing. | |
1141 | */ | |
1142 | static void | |
1143 | _scsih_pcie_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
1144 | { | |
1145 | struct _pcie_device *pcie_device; | |
1146 | unsigned long flags; | |
1147 | int was_on_pcie_device_list = 0; | |
1148 | ||
1149 | if (ioc->shost_recovery) | |
1150 | return; | |
1151 | ||
1152 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1153 | pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle); | |
1154 | if (pcie_device) { | |
1155 | if (!list_empty(&pcie_device->list)) { | |
1156 | list_del_init(&pcie_device->list); | |
1157 | was_on_pcie_device_list = 1; | |
1158 | pcie_device_put(pcie_device); | |
1159 | } | |
1160 | } | |
1161 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1162 | if (was_on_pcie_device_list) { | |
1163 | _scsih_pcie_device_remove_from_sml(ioc, pcie_device); | |
1164 | pcie_device_put(pcie_device); | |
1165 | } | |
1166 | } | |
1167 | ||
c102e00c SPS |
1168 | /** |
1169 | * _scsih_pcie_device_add - add pcie_device object | |
1170 | * @ioc: per adapter object | |
1171 | * @pcie_device: pcie_device object | |
1172 | * | |
1173 | * This is added to the pcie_device_list link list. | |
1174 | */ | |
1175 | static void | |
1176 | _scsih_pcie_device_add(struct MPT3SAS_ADAPTER *ioc, | |
1177 | struct _pcie_device *pcie_device) | |
1178 | { | |
1179 | unsigned long flags; | |
1180 | ||
1181 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
1182 | "%s: handle (0x%04x), wwid(0x%016llx)\n", ioc->name, __func__, | |
1183 | pcie_device->handle, (unsigned long long)pcie_device->wwid)); | |
1184 | if (pcie_device->enclosure_handle != 0) | |
1185 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
1186 | "%s: enclosure logical id(0x%016llx), slot( %d)\n", | |
1187 | ioc->name, __func__, | |
1188 | (unsigned long long)pcie_device->enclosure_logical_id, | |
1189 | pcie_device->slot)); | |
1190 | if (pcie_device->connector_name[0] != '\0') | |
1191 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
1192 | "%s: enclosure level(0x%04x), connector name( %s)\n", | |
1193 | ioc->name, __func__, pcie_device->enclosure_level, | |
1194 | pcie_device->connector_name)); | |
1195 | ||
1196 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1197 | pcie_device_get(pcie_device); | |
1198 | list_add_tail(&pcie_device->list, &ioc->pcie_device_list); | |
1199 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1200 | ||
1201 | if (scsi_add_device(ioc->shost, PCIE_CHANNEL, pcie_device->id, 0)) { | |
1202 | _scsih_pcie_device_remove(ioc, pcie_device); | |
1203 | } else if (!pcie_device->starget) { | |
1204 | if (!ioc->is_driver_loading) { | |
1205 | /*TODO-- Need to find out whether this condition will occur or not*/ | |
1206 | clear_bit(pcie_device->handle, ioc->pend_os_device_add); | |
1207 | } | |
1208 | } else | |
1209 | clear_bit(pcie_device->handle, ioc->pend_os_device_add); | |
1210 | } | |
1211 | ||
1212 | /* | |
1213 | * _scsih_pcie_device_init_add - insert pcie_device to the init list. | |
1214 | * @ioc: per adapter object | |
1215 | * @pcie_device: the pcie_device object | |
1216 | * Context: This function will acquire ioc->pcie_device_lock. | |
1217 | * | |
1218 | * Adding new object at driver load time to the ioc->pcie_device_init_list. | |
1219 | */ | |
1220 | static void | |
1221 | _scsih_pcie_device_init_add(struct MPT3SAS_ADAPTER *ioc, | |
1222 | struct _pcie_device *pcie_device) | |
1223 | { | |
1224 | unsigned long flags; | |
1225 | ||
1226 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
1227 | "%s: handle (0x%04x), wwid(0x%016llx)\n", ioc->name, __func__, | |
1228 | pcie_device->handle, (unsigned long long)pcie_device->wwid)); | |
1229 | if (pcie_device->enclosure_handle != 0) | |
1230 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
1231 | "%s: enclosure logical id(0x%016llx), slot( %d)\n", | |
1232 | ioc->name, __func__, | |
1233 | (unsigned long long)pcie_device->enclosure_logical_id, | |
1234 | pcie_device->slot)); | |
1235 | if (pcie_device->connector_name[0] != '\0') | |
1236 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
1237 | "%s: enclosure level(0x%04x), connector name( %s)\n", | |
1238 | ioc->name, __func__, pcie_device->enclosure_level, | |
1239 | pcie_device->connector_name)); | |
1240 | ||
1241 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1242 | pcie_device_get(pcie_device); | |
1243 | list_add_tail(&pcie_device->list, &ioc->pcie_device_init_list); | |
1244 | _scsih_determine_boot_device(ioc, pcie_device, PCIE_CHANNEL); | |
1245 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1246 | } | |
f92363d1 SR |
1247 | /** |
1248 | * _scsih_raid_device_find_by_id - raid device search | |
1249 | * @ioc: per adapter object | |
1250 | * @id: sas device target id | |
1251 | * @channel: sas device channel | |
1252 | * Context: Calling function should acquire ioc->raid_device_lock | |
1253 | * | |
1254 | * This searches for raid_device based on target id, then return raid_device | |
1255 | * object. | |
1256 | */ | |
1257 | static struct _raid_device * | |
1258 | _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER *ioc, int id, int channel) | |
1259 | { | |
1260 | struct _raid_device *raid_device, *r; | |
1261 | ||
1262 | r = NULL; | |
1263 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
1264 | if (raid_device->id == id && raid_device->channel == channel) { | |
1265 | r = raid_device; | |
1266 | goto out; | |
1267 | } | |
1268 | } | |
1269 | ||
1270 | out: | |
1271 | return r; | |
1272 | } | |
1273 | ||
1274 | /** | |
c84b06a4 | 1275 | * mpt3sas_raid_device_find_by_handle - raid device search |
f92363d1 SR |
1276 | * @ioc: per adapter object |
1277 | * @handle: sas device handle (assigned by firmware) | |
1278 | * Context: Calling function should acquire ioc->raid_device_lock | |
1279 | * | |
1280 | * This searches for raid_device based on handle, then return raid_device | |
1281 | * object. | |
1282 | */ | |
c84b06a4 SR |
1283 | struct _raid_device * |
1284 | mpt3sas_raid_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
f92363d1 SR |
1285 | { |
1286 | struct _raid_device *raid_device, *r; | |
1287 | ||
1288 | r = NULL; | |
1289 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
1290 | if (raid_device->handle != handle) | |
1291 | continue; | |
1292 | r = raid_device; | |
1293 | goto out; | |
1294 | } | |
1295 | ||
1296 | out: | |
1297 | return r; | |
1298 | } | |
1299 | ||
1300 | /** | |
1301 | * _scsih_raid_device_find_by_wwid - raid device search | |
1302 | * @ioc: per adapter object | |
1303 | * @handle: sas device handle (assigned by firmware) | |
1304 | * Context: Calling function should acquire ioc->raid_device_lock | |
1305 | * | |
1306 | * This searches for raid_device based on wwid, then return raid_device | |
1307 | * object. | |
1308 | */ | |
1309 | static struct _raid_device * | |
1310 | _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid) | |
1311 | { | |
1312 | struct _raid_device *raid_device, *r; | |
1313 | ||
1314 | r = NULL; | |
1315 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
1316 | if (raid_device->wwid != wwid) | |
1317 | continue; | |
1318 | r = raid_device; | |
1319 | goto out; | |
1320 | } | |
1321 | ||
1322 | out: | |
1323 | return r; | |
1324 | } | |
1325 | ||
1326 | /** | |
1327 | * _scsih_raid_device_add - add raid_device object | |
1328 | * @ioc: per adapter object | |
1329 | * @raid_device: raid_device object | |
1330 | * | |
1331 | * This is added to the raid_device_list link list. | |
1332 | */ | |
1333 | static void | |
1334 | _scsih_raid_device_add(struct MPT3SAS_ADAPTER *ioc, | |
1335 | struct _raid_device *raid_device) | |
1336 | { | |
1337 | unsigned long flags; | |
1338 | ||
1339 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
1340 | "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__, | |
1341 | raid_device->handle, (unsigned long long)raid_device->wwid)); | |
1342 | ||
1343 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1344 | list_add_tail(&raid_device->list, &ioc->raid_device_list); | |
1345 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1346 | } | |
1347 | ||
1348 | /** | |
1349 | * _scsih_raid_device_remove - delete raid_device object | |
1350 | * @ioc: per adapter object | |
1351 | * @raid_device: raid_device object | |
1352 | * | |
1353 | */ | |
1354 | static void | |
1355 | _scsih_raid_device_remove(struct MPT3SAS_ADAPTER *ioc, | |
1356 | struct _raid_device *raid_device) | |
1357 | { | |
1358 | unsigned long flags; | |
1359 | ||
1360 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1361 | list_del(&raid_device->list); | |
1362 | kfree(raid_device); | |
1363 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1364 | } | |
1365 | ||
1366 | /** | |
1367 | * mpt3sas_scsih_expander_find_by_handle - expander device search | |
1368 | * @ioc: per adapter object | |
1369 | * @handle: expander handle (assigned by firmware) | |
1370 | * Context: Calling function should acquire ioc->sas_device_lock | |
1371 | * | |
1372 | * This searches for expander device based on handle, then returns the | |
1373 | * sas_node object. | |
1374 | */ | |
1375 | struct _sas_node * | |
1376 | mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
1377 | { | |
1378 | struct _sas_node *sas_expander, *r; | |
1379 | ||
1380 | r = NULL; | |
1381 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { | |
1382 | if (sas_expander->handle != handle) | |
1383 | continue; | |
1384 | r = sas_expander; | |
1385 | goto out; | |
1386 | } | |
1387 | out: | |
1388 | return r; | |
1389 | } | |
1390 | ||
1391 | /** | |
1392 | * mpt3sas_scsih_expander_find_by_sas_address - expander device search | |
1393 | * @ioc: per adapter object | |
1394 | * @sas_address: sas address | |
1395 | * Context: Calling function should acquire ioc->sas_node_lock. | |
1396 | * | |
1397 | * This searches for expander device based on sas_address, then returns the | |
1398 | * sas_node object. | |
1399 | */ | |
1400 | struct _sas_node * | |
1401 | mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc, | |
1402 | u64 sas_address) | |
1403 | { | |
1404 | struct _sas_node *sas_expander, *r; | |
1405 | ||
1406 | r = NULL; | |
1407 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { | |
1408 | if (sas_expander->sas_address != sas_address) | |
1409 | continue; | |
1410 | r = sas_expander; | |
1411 | goto out; | |
1412 | } | |
1413 | out: | |
1414 | return r; | |
1415 | } | |
1416 | ||
1417 | /** | |
1418 | * _scsih_expander_node_add - insert expander device to the list. | |
1419 | * @ioc: per adapter object | |
1420 | * @sas_expander: the sas_device object | |
1421 | * Context: This function will acquire ioc->sas_node_lock. | |
1422 | * | |
1423 | * Adding new object to the ioc->sas_expander_list. | |
1424 | * | |
1425 | * Return nothing. | |
1426 | */ | |
1427 | static void | |
1428 | _scsih_expander_node_add(struct MPT3SAS_ADAPTER *ioc, | |
1429 | struct _sas_node *sas_expander) | |
1430 | { | |
1431 | unsigned long flags; | |
1432 | ||
1433 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
1434 | list_add_tail(&sas_expander->list, &ioc->sas_expander_list); | |
1435 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
1436 | } | |
1437 | ||
1438 | /** | |
1439 | * _scsih_is_end_device - determines if device is an end device | |
1440 | * @device_info: bitfield providing information about the device. | |
1441 | * Context: none | |
1442 | * | |
1443 | * Returns 1 if end device. | |
1444 | */ | |
1445 | static int | |
1446 | _scsih_is_end_device(u32 device_info) | |
1447 | { | |
1448 | if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE && | |
1449 | ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) | | |
1450 | (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) | | |
1451 | (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE))) | |
1452 | return 1; | |
1453 | else | |
1454 | return 0; | |
1455 | } | |
1456 | ||
c102e00c SPS |
1457 | /** |
1458 | * _scsih_is_nvme_device - determines if device is an nvme device | |
1459 | * @device_info: bitfield providing information about the device. | |
1460 | * Context: none | |
1461 | * | |
1462 | * Returns 1 if nvme device. | |
1463 | */ | |
1464 | static int | |
1465 | _scsih_is_nvme_device(u32 device_info) | |
1466 | { | |
1467 | if ((device_info & MPI26_PCIE_DEVINFO_MASK_DEVICE_TYPE) | |
1468 | == MPI26_PCIE_DEVINFO_NVME) | |
1469 | return 1; | |
1470 | else | |
1471 | return 0; | |
1472 | } | |
1473 | ||
f92363d1 SR |
1474 | /** |
1475 | * _scsih_scsi_lookup_get - returns scmd entry | |
1476 | * @ioc: per adapter object | |
1477 | * @smid: system request message index | |
1478 | * | |
1479 | * Returns the smid stored scmd pointer. | |
1480 | */ | |
1481 | static struct scsi_cmnd * | |
1482 | _scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid) | |
1483 | { | |
1484 | return ioc->scsi_lookup[smid - 1].scmd; | |
1485 | } | |
1486 | ||
459325c4 C |
1487 | /** |
1488 | * __scsih_scsi_lookup_get_clear - returns scmd entry without | |
1489 | * holding any lock. | |
1490 | * @ioc: per adapter object | |
1491 | * @smid: system request message index | |
1492 | * | |
1493 | * Returns the smid stored scmd pointer. | |
1494 | * Then will dereference the stored scmd pointer. | |
1495 | */ | |
1496 | static inline struct scsi_cmnd * | |
1497 | __scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER *ioc, | |
1498 | u16 smid) | |
1499 | { | |
1500 | struct scsi_cmnd *scmd = NULL; | |
1501 | ||
1502 | swap(scmd, ioc->scsi_lookup[smid - 1].scmd); | |
1503 | ||
1504 | return scmd; | |
1505 | } | |
1506 | ||
f92363d1 SR |
1507 | /** |
1508 | * _scsih_scsi_lookup_get_clear - returns scmd entry | |
1509 | * @ioc: per adapter object | |
1510 | * @smid: system request message index | |
1511 | * | |
1512 | * Returns the smid stored scmd pointer. | |
1513 | * Then will derefrence the stored scmd pointer. | |
1514 | */ | |
1515 | static inline struct scsi_cmnd * | |
1516 | _scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER *ioc, u16 smid) | |
1517 | { | |
1518 | unsigned long flags; | |
1519 | struct scsi_cmnd *scmd; | |
1520 | ||
1521 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
459325c4 | 1522 | scmd = __scsih_scsi_lookup_get_clear(ioc, smid); |
f92363d1 SR |
1523 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
1524 | ||
1525 | return scmd; | |
1526 | } | |
1527 | ||
1528 | /** | |
1529 | * _scsih_scsi_lookup_find_by_scmd - scmd lookup | |
1530 | * @ioc: per adapter object | |
1531 | * @smid: system request message index | |
1532 | * @scmd: pointer to scsi command object | |
1533 | * Context: This function will acquire ioc->scsi_lookup_lock. | |
1534 | * | |
1535 | * This will search for a scmd pointer in the scsi_lookup array, | |
1536 | * returning the revelent smid. A returned value of zero means invalid. | |
1537 | */ | |
1538 | static u16 | |
1539 | _scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd | |
1540 | *scmd) | |
1541 | { | |
1542 | u16 smid; | |
1543 | unsigned long flags; | |
1544 | int i; | |
1545 | ||
1546 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
1547 | smid = 0; | |
1548 | for (i = 0; i < ioc->scsiio_depth; i++) { | |
1549 | if (ioc->scsi_lookup[i].scmd == scmd) { | |
1550 | smid = ioc->scsi_lookup[i].smid; | |
1551 | goto out; | |
1552 | } | |
1553 | } | |
1554 | out: | |
1555 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
1556 | return smid; | |
1557 | } | |
1558 | ||
1559 | /** | |
1560 | * _scsih_scsi_lookup_find_by_target - search for matching channel:id | |
1561 | * @ioc: per adapter object | |
1562 | * @id: target id | |
1563 | * @channel: channel | |
1564 | * Context: This function will acquire ioc->scsi_lookup_lock. | |
1565 | * | |
1566 | * This will search for a matching channel:id in the scsi_lookup array, | |
1567 | * returning 1 if found. | |
1568 | */ | |
1569 | static u8 | |
1570 | _scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER *ioc, int id, | |
1571 | int channel) | |
1572 | { | |
1573 | u8 found; | |
1574 | unsigned long flags; | |
1575 | int i; | |
1576 | ||
1577 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
1578 | found = 0; | |
1579 | for (i = 0 ; i < ioc->scsiio_depth; i++) { | |
1580 | if (ioc->scsi_lookup[i].scmd && | |
1581 | (ioc->scsi_lookup[i].scmd->device->id == id && | |
1582 | ioc->scsi_lookup[i].scmd->device->channel == channel)) { | |
1583 | found = 1; | |
1584 | goto out; | |
1585 | } | |
1586 | } | |
1587 | out: | |
1588 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
1589 | return found; | |
1590 | } | |
1591 | ||
1592 | /** | |
1593 | * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun | |
1594 | * @ioc: per adapter object | |
1595 | * @id: target id | |
1596 | * @lun: lun number | |
1597 | * @channel: channel | |
1598 | * Context: This function will acquire ioc->scsi_lookup_lock. | |
1599 | * | |
1600 | * This will search for a matching channel:id:lun in the scsi_lookup array, | |
1601 | * returning 1 if found. | |
1602 | */ | |
1603 | static u8 | |
1604 | _scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER *ioc, int id, | |
1605 | unsigned int lun, int channel) | |
1606 | { | |
1607 | u8 found; | |
1608 | unsigned long flags; | |
1609 | int i; | |
1610 | ||
1611 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
1612 | found = 0; | |
1613 | for (i = 0 ; i < ioc->scsiio_depth; i++) { | |
1614 | if (ioc->scsi_lookup[i].scmd && | |
1615 | (ioc->scsi_lookup[i].scmd->device->id == id && | |
1616 | ioc->scsi_lookup[i].scmd->device->channel == channel && | |
1617 | ioc->scsi_lookup[i].scmd->device->lun == lun)) { | |
1618 | found = 1; | |
1619 | goto out; | |
1620 | } | |
1621 | } | |
1622 | out: | |
1623 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
1624 | return found; | |
1625 | } | |
1626 | ||
cf75d5d6 | 1627 | /** |
8a7e4c24 | 1628 | * scsih_change_queue_depth - setting device queue depth |
cf75d5d6 CH |
1629 | * @sdev: scsi device struct |
1630 | * @qdepth: requested queue depth | |
1631 | * | |
1632 | * Returns queue depth. | |
1633 | */ | |
8bbb1cf6 | 1634 | static int |
8a7e4c24 | 1635 | scsih_change_queue_depth(struct scsi_device *sdev, int qdepth) |
f92363d1 SR |
1636 | { |
1637 | struct Scsi_Host *shost = sdev->host; | |
1638 | int max_depth; | |
1639 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
1640 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
1641 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1642 | struct _sas_device *sas_device; | |
1643 | unsigned long flags; | |
1644 | ||
1645 | max_depth = shost->can_queue; | |
1646 | ||
1647 | /* limit max device queue for SATA to 32 */ | |
1648 | sas_device_priv_data = sdev->hostdata; | |
1649 | if (!sas_device_priv_data) | |
1650 | goto not_sata; | |
1651 | sas_target_priv_data = sas_device_priv_data->sas_target; | |
1652 | if (!sas_target_priv_data) | |
1653 | goto not_sata; | |
1654 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) | |
1655 | goto not_sata; | |
d1cb5e49 | 1656 | |
f92363d1 | 1657 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 SR |
1658 | sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data); |
1659 | if (sas_device) { | |
1660 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE) | |
1661 | max_depth = MPT3SAS_SATA_QUEUE_DEPTH; | |
1662 | ||
1663 | sas_device_put(sas_device); | |
1664 | } | |
f92363d1 SR |
1665 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
1666 | ||
1667 | not_sata: | |
1668 | ||
1669 | if (!sdev->tagged_supported) | |
1670 | max_depth = 1; | |
1671 | if (qdepth > max_depth) | |
1672 | qdepth = max_depth; | |
cf75d5d6 | 1673 | return scsi_change_queue_depth(sdev, qdepth); |
f92363d1 SR |
1674 | } |
1675 | ||
f92363d1 | 1676 | /** |
8a7e4c24 | 1677 | * scsih_target_alloc - target add routine |
f92363d1 SR |
1678 | * @starget: scsi target struct |
1679 | * | |
1680 | * Returns 0 if ok. Any other return is assumed to be an error and | |
1681 | * the device is ignored. | |
1682 | */ | |
8bbb1cf6 | 1683 | static int |
8a7e4c24 | 1684 | scsih_target_alloc(struct scsi_target *starget) |
f92363d1 SR |
1685 | { |
1686 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); | |
1687 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
1688 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1689 | struct _sas_device *sas_device; | |
1690 | struct _raid_device *raid_device; | |
d88e1eab | 1691 | struct _pcie_device *pcie_device; |
f92363d1 SR |
1692 | unsigned long flags; |
1693 | struct sas_rphy *rphy; | |
1694 | ||
62c4da44 JL |
1695 | sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data), |
1696 | GFP_KERNEL); | |
f92363d1 SR |
1697 | if (!sas_target_priv_data) |
1698 | return -ENOMEM; | |
1699 | ||
1700 | starget->hostdata = sas_target_priv_data; | |
1701 | sas_target_priv_data->starget = starget; | |
1702 | sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE; | |
1703 | ||
1704 | /* RAID volumes */ | |
1705 | if (starget->channel == RAID_CHANNEL) { | |
1706 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1707 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, | |
1708 | starget->channel); | |
1709 | if (raid_device) { | |
1710 | sas_target_priv_data->handle = raid_device->handle; | |
1711 | sas_target_priv_data->sas_address = raid_device->wwid; | |
1712 | sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME; | |
7786ab6a | 1713 | if (ioc->is_warpdrive) |
6d3a56ed SR |
1714 | sas_target_priv_data->raid_device = raid_device; |
1715 | raid_device->starget = starget; | |
f92363d1 SR |
1716 | } |
1717 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1718 | return 0; | |
1719 | } | |
1720 | ||
d88e1eab SPS |
1721 | /* PCIe devices */ |
1722 | if (starget->channel == PCIE_CHANNEL) { | |
1723 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1724 | pcie_device = __mpt3sas_get_pdev_by_idchannel(ioc, starget->id, | |
1725 | starget->channel); | |
1726 | if (pcie_device) { | |
1727 | sas_target_priv_data->handle = pcie_device->handle; | |
1728 | sas_target_priv_data->sas_address = pcie_device->wwid; | |
1729 | sas_target_priv_data->pcie_dev = pcie_device; | |
1730 | pcie_device->starget = starget; | |
1731 | pcie_device->id = starget->id; | |
1732 | pcie_device->channel = starget->channel; | |
1733 | sas_target_priv_data->flags |= | |
1734 | MPT_TARGET_FLAGS_PCIE_DEVICE; | |
1735 | if (pcie_device->fast_path) | |
1736 | sas_target_priv_data->flags |= | |
1737 | MPT_TARGET_FASTPATH_IO; | |
1738 | } | |
1739 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1740 | return 0; | |
1741 | } | |
1742 | ||
f92363d1 SR |
1743 | /* sas/sata devices */ |
1744 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
1745 | rphy = dev_to_rphy(starget->dev.parent); | |
d1cb5e49 | 1746 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 SR |
1747 | rphy->identify.sas_address); |
1748 | ||
1749 | if (sas_device) { | |
1750 | sas_target_priv_data->handle = sas_device->handle; | |
1751 | sas_target_priv_data->sas_address = sas_device->sas_address; | |
d88e1eab | 1752 | sas_target_priv_data->sas_dev = sas_device; |
f92363d1 SR |
1753 | sas_device->starget = starget; |
1754 | sas_device->id = starget->id; | |
1755 | sas_device->channel = starget->channel; | |
1756 | if (test_bit(sas_device->handle, ioc->pd_handles)) | |
1757 | sas_target_priv_data->flags |= | |
1758 | MPT_TARGET_FLAGS_RAID_COMPONENT; | |
1759 | if (sas_device->fast_path) | |
d88e1eab SPS |
1760 | sas_target_priv_data->flags |= |
1761 | MPT_TARGET_FASTPATH_IO; | |
f92363d1 SR |
1762 | } |
1763 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
1764 | ||
1765 | return 0; | |
1766 | } | |
1767 | ||
1768 | /** | |
8a7e4c24 | 1769 | * scsih_target_destroy - target destroy routine |
f92363d1 SR |
1770 | * @starget: scsi target struct |
1771 | * | |
1772 | * Returns nothing. | |
1773 | */ | |
8bbb1cf6 | 1774 | static void |
8a7e4c24 | 1775 | scsih_target_destroy(struct scsi_target *starget) |
f92363d1 SR |
1776 | { |
1777 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); | |
1778 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
1779 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1780 | struct _sas_device *sas_device; | |
1781 | struct _raid_device *raid_device; | |
d88e1eab | 1782 | struct _pcie_device *pcie_device; |
f92363d1 | 1783 | unsigned long flags; |
d88e1eab | 1784 | struct sas_rphy *rphy; |
f92363d1 SR |
1785 | |
1786 | sas_target_priv_data = starget->hostdata; | |
1787 | if (!sas_target_priv_data) | |
1788 | return; | |
1789 | ||
1790 | if (starget->channel == RAID_CHANNEL) { | |
1791 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1792 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, | |
1793 | starget->channel); | |
1794 | if (raid_device) { | |
1795 | raid_device->starget = NULL; | |
1796 | raid_device->sdev = NULL; | |
1797 | } | |
1798 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1799 | goto out; | |
1800 | } | |
1801 | ||
d88e1eab SPS |
1802 | if (starget->channel == PCIE_CHANNEL) { |
1803 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1804 | pcie_device = __mpt3sas_get_pdev_from_target(ioc, | |
1805 | sas_target_priv_data); | |
1806 | if (pcie_device && (pcie_device->starget == starget) && | |
1807 | (pcie_device->id == starget->id) && | |
1808 | (pcie_device->channel == starget->channel)) | |
1809 | pcie_device->starget = NULL; | |
1810 | ||
1811 | if (pcie_device) { | |
1812 | /* | |
1813 | * Corresponding get() is in _scsih_target_alloc() | |
1814 | */ | |
1815 | sas_target_priv_data->pcie_dev = NULL; | |
1816 | pcie_device_put(pcie_device); | |
1817 | pcie_device_put(pcie_device); | |
1818 | } | |
1819 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1820 | goto out; | |
1821 | } | |
1822 | ||
f92363d1 | 1823 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d88e1eab | 1824 | rphy = dev_to_rphy(starget->dev.parent); |
d1cb5e49 | 1825 | sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data); |
f92363d1 SR |
1826 | if (sas_device && (sas_device->starget == starget) && |
1827 | (sas_device->id == starget->id) && | |
1828 | (sas_device->channel == starget->channel)) | |
1829 | sas_device->starget = NULL; | |
1830 | ||
d1cb5e49 SR |
1831 | if (sas_device) { |
1832 | /* | |
1833 | * Corresponding get() is in _scsih_target_alloc() | |
1834 | */ | |
d88e1eab | 1835 | sas_target_priv_data->sas_dev = NULL; |
d1cb5e49 SR |
1836 | sas_device_put(sas_device); |
1837 | ||
1838 | sas_device_put(sas_device); | |
1839 | } | |
f92363d1 SR |
1840 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
1841 | ||
1842 | out: | |
1843 | kfree(sas_target_priv_data); | |
1844 | starget->hostdata = NULL; | |
1845 | } | |
1846 | ||
1847 | /** | |
8a7e4c24 | 1848 | * scsih_slave_alloc - device add routine |
f92363d1 SR |
1849 | * @sdev: scsi device struct |
1850 | * | |
1851 | * Returns 0 if ok. Any other return is assumed to be an error and | |
1852 | * the device is ignored. | |
1853 | */ | |
8bbb1cf6 | 1854 | static int |
8a7e4c24 | 1855 | scsih_slave_alloc(struct scsi_device *sdev) |
f92363d1 SR |
1856 | { |
1857 | struct Scsi_Host *shost; | |
1858 | struct MPT3SAS_ADAPTER *ioc; | |
1859 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1860 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
1861 | struct scsi_target *starget; | |
1862 | struct _raid_device *raid_device; | |
b65cfedf | 1863 | struct _sas_device *sas_device; |
d88e1eab | 1864 | struct _pcie_device *pcie_device; |
f92363d1 SR |
1865 | unsigned long flags; |
1866 | ||
62c4da44 JL |
1867 | sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data), |
1868 | GFP_KERNEL); | |
f92363d1 SR |
1869 | if (!sas_device_priv_data) |
1870 | return -ENOMEM; | |
1871 | ||
1872 | sas_device_priv_data->lun = sdev->lun; | |
1873 | sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT; | |
1874 | ||
1875 | starget = scsi_target(sdev); | |
1876 | sas_target_priv_data = starget->hostdata; | |
1877 | sas_target_priv_data->num_luns++; | |
1878 | sas_device_priv_data->sas_target = sas_target_priv_data; | |
1879 | sdev->hostdata = sas_device_priv_data; | |
1880 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT)) | |
1881 | sdev->no_uld_attach = 1; | |
1882 | ||
1883 | shost = dev_to_shost(&starget->dev); | |
1884 | ioc = shost_priv(shost); | |
1885 | if (starget->channel == RAID_CHANNEL) { | |
1886 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1887 | raid_device = _scsih_raid_device_find_by_id(ioc, | |
1888 | starget->id, starget->channel); | |
1889 | if (raid_device) | |
1890 | raid_device->sdev = sdev; /* raid is single lun */ | |
1891 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1892 | } | |
d88e1eab SPS |
1893 | if (starget->channel == PCIE_CHANNEL) { |
1894 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1895 | pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, | |
1896 | sas_target_priv_data->sas_address); | |
1897 | if (pcie_device && (pcie_device->starget == NULL)) { | |
1898 | sdev_printk(KERN_INFO, sdev, | |
1899 | "%s : pcie_device->starget set to starget @ %d\n", | |
1900 | __func__, __LINE__); | |
1901 | pcie_device->starget = starget; | |
1902 | } | |
1903 | ||
1904 | if (pcie_device) | |
1905 | pcie_device_put(pcie_device); | |
1906 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
f92363d1 | 1907 | |
d88e1eab | 1908 | } else if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { |
b65cfedf | 1909 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 1910 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
b65cfedf SR |
1911 | sas_target_priv_data->sas_address); |
1912 | if (sas_device && (sas_device->starget == NULL)) { | |
1913 | sdev_printk(KERN_INFO, sdev, | |
1914 | "%s : sas_device->starget set to starget @ %d\n", | |
d1cb5e49 | 1915 | __func__, __LINE__); |
b65cfedf SR |
1916 | sas_device->starget = starget; |
1917 | } | |
d1cb5e49 SR |
1918 | |
1919 | if (sas_device) | |
1920 | sas_device_put(sas_device); | |
1921 | ||
b65cfedf SR |
1922 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
1923 | } | |
1924 | ||
f92363d1 SR |
1925 | return 0; |
1926 | } | |
1927 | ||
1928 | /** | |
8a7e4c24 | 1929 | * scsih_slave_destroy - device destroy routine |
f92363d1 SR |
1930 | * @sdev: scsi device struct |
1931 | * | |
1932 | * Returns nothing. | |
1933 | */ | |
8bbb1cf6 | 1934 | static void |
8a7e4c24 | 1935 | scsih_slave_destroy(struct scsi_device *sdev) |
f92363d1 SR |
1936 | { |
1937 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1938 | struct scsi_target *starget; | |
1939 | struct Scsi_Host *shost; | |
1940 | struct MPT3SAS_ADAPTER *ioc; | |
1941 | struct _sas_device *sas_device; | |
d88e1eab | 1942 | struct _pcie_device *pcie_device; |
f92363d1 SR |
1943 | unsigned long flags; |
1944 | ||
1945 | if (!sdev->hostdata) | |
1946 | return; | |
1947 | ||
1948 | starget = scsi_target(sdev); | |
1949 | sas_target_priv_data = starget->hostdata; | |
1950 | sas_target_priv_data->num_luns--; | |
1951 | ||
1952 | shost = dev_to_shost(&starget->dev); | |
1953 | ioc = shost_priv(shost); | |
1954 | ||
d88e1eab SPS |
1955 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) { |
1956 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1957 | pcie_device = __mpt3sas_get_pdev_from_target(ioc, | |
1958 | sas_target_priv_data); | |
1959 | if (pcie_device && !sas_target_priv_data->num_luns) | |
1960 | pcie_device->starget = NULL; | |
1961 | ||
1962 | if (pcie_device) | |
1963 | pcie_device_put(pcie_device); | |
1964 | ||
1965 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1966 | ||
1967 | } else if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { | |
f92363d1 | 1968 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 SR |
1969 | sas_device = __mpt3sas_get_sdev_from_target(ioc, |
1970 | sas_target_priv_data); | |
f92363d1 SR |
1971 | if (sas_device && !sas_target_priv_data->num_luns) |
1972 | sas_device->starget = NULL; | |
d1cb5e49 SR |
1973 | |
1974 | if (sas_device) | |
1975 | sas_device_put(sas_device); | |
f92363d1 SR |
1976 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
1977 | } | |
1978 | ||
1979 | kfree(sdev->hostdata); | |
1980 | sdev->hostdata = NULL; | |
1981 | } | |
1982 | ||
1983 | /** | |
1984 | * _scsih_display_sata_capabilities - sata capabilities | |
1985 | * @ioc: per adapter object | |
1986 | * @handle: device handle | |
1987 | * @sdev: scsi device struct | |
1988 | */ | |
1989 | static void | |
1990 | _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc, | |
1991 | u16 handle, struct scsi_device *sdev) | |
1992 | { | |
1993 | Mpi2ConfigReply_t mpi_reply; | |
1994 | Mpi2SasDevicePage0_t sas_device_pg0; | |
1995 | u32 ioc_status; | |
1996 | u16 flags; | |
1997 | u32 device_info; | |
1998 | ||
1999 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
2000 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
2001 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
2002 | ioc->name, __FILE__, __LINE__, __func__); | |
2003 | return; | |
2004 | } | |
2005 | ||
2006 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
2007 | MPI2_IOCSTATUS_MASK; | |
2008 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
2009 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
2010 | ioc->name, __FILE__, __LINE__, __func__); | |
2011 | return; | |
2012 | } | |
2013 | ||
2014 | flags = le16_to_cpu(sas_device_pg0.Flags); | |
2015 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | |
2016 | ||
2017 | sdev_printk(KERN_INFO, sdev, | |
2018 | "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), " | |
2019 | "sw_preserve(%s)\n", | |
2020 | (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n", | |
2021 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n", | |
2022 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" : | |
2023 | "n", | |
2024 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n", | |
2025 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n", | |
2026 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n"); | |
2027 | } | |
2028 | ||
2029 | /* | |
2030 | * raid transport support - | |
2031 | * Enabled for SLES11 and newer, in older kernels the driver will panic when | |
6c7abffc | 2032 | * unloading the driver followed by a load - I believe that the subroutine |
f92363d1 SR |
2033 | * raid_class_release() is not cleaning up properly. |
2034 | */ | |
2035 | ||
2036 | /** | |
8a7e4c24 | 2037 | * scsih_is_raid - return boolean indicating device is raid volume |
f92363d1 SR |
2038 | * @dev the device struct object |
2039 | */ | |
8bbb1cf6 | 2040 | static int |
8a7e4c24 | 2041 | scsih_is_raid(struct device *dev) |
f92363d1 SR |
2042 | { |
2043 | struct scsi_device *sdev = to_scsi_device(dev); | |
7786ab6a | 2044 | struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host); |
f92363d1 | 2045 | |
7786ab6a SR |
2046 | if (ioc->is_warpdrive) |
2047 | return 0; | |
f92363d1 SR |
2048 | return (sdev->channel == RAID_CHANNEL) ? 1 : 0; |
2049 | } | |
2050 | ||
2051 | /** | |
8a7e4c24 | 2052 | * scsih_get_resync - get raid volume resync percent complete |
f92363d1 SR |
2053 | * @dev the device struct object |
2054 | */ | |
8bbb1cf6 | 2055 | static void |
8a7e4c24 | 2056 | scsih_get_resync(struct device *dev) |
f92363d1 SR |
2057 | { |
2058 | struct scsi_device *sdev = to_scsi_device(dev); | |
2059 | struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host); | |
2060 | static struct _raid_device *raid_device; | |
2061 | unsigned long flags; | |
2062 | Mpi2RaidVolPage0_t vol_pg0; | |
2063 | Mpi2ConfigReply_t mpi_reply; | |
2064 | u32 volume_status_flags; | |
2065 | u8 percent_complete; | |
2066 | u16 handle; | |
2067 | ||
2068 | percent_complete = 0; | |
2069 | handle = 0; | |
7786ab6a SR |
2070 | if (ioc->is_warpdrive) |
2071 | goto out; | |
2072 | ||
f92363d1 SR |
2073 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
2074 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, | |
2075 | sdev->channel); | |
2076 | if (raid_device) { | |
2077 | handle = raid_device->handle; | |
2078 | percent_complete = raid_device->percent_complete; | |
2079 | } | |
2080 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
2081 | ||
2082 | if (!handle) | |
2083 | goto out; | |
2084 | ||
2085 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0, | |
2086 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
2087 | sizeof(Mpi2RaidVolPage0_t))) { | |
2088 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
2089 | ioc->name, __FILE__, __LINE__, __func__); | |
2090 | percent_complete = 0; | |
2091 | goto out; | |
2092 | } | |
2093 | ||
2094 | volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags); | |
2095 | if (!(volume_status_flags & | |
2096 | MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)) | |
2097 | percent_complete = 0; | |
2098 | ||
2099 | out: | |
b130b0d5 SS |
2100 | |
2101 | switch (ioc->hba_mpi_version_belonged) { | |
2102 | case MPI2_VERSION: | |
c84b06a4 | 2103 | raid_set_resync(mpt2sas_raid_template, dev, percent_complete); |
b130b0d5 SS |
2104 | break; |
2105 | case MPI25_VERSION: | |
2106 | case MPI26_VERSION: | |
c84b06a4 | 2107 | raid_set_resync(mpt3sas_raid_template, dev, percent_complete); |
b130b0d5 SS |
2108 | break; |
2109 | } | |
f92363d1 SR |
2110 | } |
2111 | ||
2112 | /** | |
8a7e4c24 | 2113 | * scsih_get_state - get raid volume level |
f92363d1 SR |
2114 | * @dev the device struct object |
2115 | */ | |
8bbb1cf6 | 2116 | static void |
8a7e4c24 | 2117 | scsih_get_state(struct device *dev) |
f92363d1 SR |
2118 | { |
2119 | struct scsi_device *sdev = to_scsi_device(dev); | |
2120 | struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host); | |
2121 | static struct _raid_device *raid_device; | |
2122 | unsigned long flags; | |
2123 | Mpi2RaidVolPage0_t vol_pg0; | |
2124 | Mpi2ConfigReply_t mpi_reply; | |
2125 | u32 volstate; | |
2126 | enum raid_state state = RAID_STATE_UNKNOWN; | |
2127 | u16 handle = 0; | |
2128 | ||
2129 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
2130 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, | |
2131 | sdev->channel); | |
2132 | if (raid_device) | |
2133 | handle = raid_device->handle; | |
2134 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
2135 | ||
2136 | if (!raid_device) | |
2137 | goto out; | |
2138 | ||
2139 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0, | |
2140 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
2141 | sizeof(Mpi2RaidVolPage0_t))) { | |
2142 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
2143 | ioc->name, __FILE__, __LINE__, __func__); | |
2144 | goto out; | |
2145 | } | |
2146 | ||
2147 | volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags); | |
2148 | if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) { | |
2149 | state = RAID_STATE_RESYNCING; | |
2150 | goto out; | |
2151 | } | |
2152 | ||
2153 | switch (vol_pg0.VolumeState) { | |
2154 | case MPI2_RAID_VOL_STATE_OPTIMAL: | |
2155 | case MPI2_RAID_VOL_STATE_ONLINE: | |
2156 | state = RAID_STATE_ACTIVE; | |
2157 | break; | |
2158 | case MPI2_RAID_VOL_STATE_DEGRADED: | |
2159 | state = RAID_STATE_DEGRADED; | |
2160 | break; | |
2161 | case MPI2_RAID_VOL_STATE_FAILED: | |
2162 | case MPI2_RAID_VOL_STATE_MISSING: | |
2163 | state = RAID_STATE_OFFLINE; | |
2164 | break; | |
2165 | } | |
2166 | out: | |
b130b0d5 SS |
2167 | switch (ioc->hba_mpi_version_belonged) { |
2168 | case MPI2_VERSION: | |
c84b06a4 | 2169 | raid_set_state(mpt2sas_raid_template, dev, state); |
b130b0d5 SS |
2170 | break; |
2171 | case MPI25_VERSION: | |
2172 | case MPI26_VERSION: | |
c84b06a4 | 2173 | raid_set_state(mpt3sas_raid_template, dev, state); |
b130b0d5 SS |
2174 | break; |
2175 | } | |
f92363d1 SR |
2176 | } |
2177 | ||
2178 | /** | |
2179 | * _scsih_set_level - set raid level | |
2180 | * @sdev: scsi device struct | |
2181 | * @volume_type: volume type | |
2182 | */ | |
2183 | static void | |
c84b06a4 SR |
2184 | _scsih_set_level(struct MPT3SAS_ADAPTER *ioc, |
2185 | struct scsi_device *sdev, u8 volume_type) | |
f92363d1 SR |
2186 | { |
2187 | enum raid_level level = RAID_LEVEL_UNKNOWN; | |
2188 | ||
2189 | switch (volume_type) { | |
2190 | case MPI2_RAID_VOL_TYPE_RAID0: | |
2191 | level = RAID_LEVEL_0; | |
2192 | break; | |
2193 | case MPI2_RAID_VOL_TYPE_RAID10: | |
2194 | level = RAID_LEVEL_10; | |
2195 | break; | |
2196 | case MPI2_RAID_VOL_TYPE_RAID1E: | |
2197 | level = RAID_LEVEL_1E; | |
2198 | break; | |
2199 | case MPI2_RAID_VOL_TYPE_RAID1: | |
2200 | level = RAID_LEVEL_1; | |
2201 | break; | |
2202 | } | |
2203 | ||
b130b0d5 SS |
2204 | switch (ioc->hba_mpi_version_belonged) { |
2205 | case MPI2_VERSION: | |
c84b06a4 | 2206 | raid_set_level(mpt2sas_raid_template, |
b130b0d5 SS |
2207 | &sdev->sdev_gendev, level); |
2208 | break; | |
2209 | case MPI25_VERSION: | |
2210 | case MPI26_VERSION: | |
c84b06a4 | 2211 | raid_set_level(mpt3sas_raid_template, |
b130b0d5 SS |
2212 | &sdev->sdev_gendev, level); |
2213 | break; | |
2214 | } | |
f92363d1 SR |
2215 | } |
2216 | ||
2217 | ||
2218 | /** | |
2219 | * _scsih_get_volume_capabilities - volume capabilities | |
2220 | * @ioc: per adapter object | |
2221 | * @sas_device: the raid_device object | |
2222 | * | |
2223 | * Returns 0 for success, else 1 | |
2224 | */ | |
2225 | static int | |
2226 | _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc, | |
2227 | struct _raid_device *raid_device) | |
2228 | { | |
2229 | Mpi2RaidVolPage0_t *vol_pg0; | |
2230 | Mpi2RaidPhysDiskPage0_t pd_pg0; | |
2231 | Mpi2SasDevicePage0_t sas_device_pg0; | |
2232 | Mpi2ConfigReply_t mpi_reply; | |
2233 | u16 sz; | |
2234 | u8 num_pds; | |
2235 | ||
2236 | if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle, | |
2237 | &num_pds)) || !num_pds) { | |
2238 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2239 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | |
2240 | __func__)); | |
2241 | return 1; | |
2242 | } | |
2243 | ||
2244 | raid_device->num_pds = num_pds; | |
2245 | sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds * | |
2246 | sizeof(Mpi2RaidVol0PhysDisk_t)); | |
2247 | vol_pg0 = kzalloc(sz, GFP_KERNEL); | |
2248 | if (!vol_pg0) { | |
2249 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2250 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | |
2251 | __func__)); | |
2252 | return 1; | |
2253 | } | |
2254 | ||
2255 | if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0, | |
2256 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) { | |
2257 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2258 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | |
2259 | __func__)); | |
2260 | kfree(vol_pg0); | |
2261 | return 1; | |
2262 | } | |
2263 | ||
2264 | raid_device->volume_type = vol_pg0->VolumeType; | |
2265 | ||
2266 | /* figure out what the underlying devices are by | |
2267 | * obtaining the device_info bits for the 1st device | |
2268 | */ | |
2269 | if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | |
2270 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM, | |
2271 | vol_pg0->PhysDisk[0].PhysDiskNum))) { | |
2272 | if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
2273 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | |
2274 | le16_to_cpu(pd_pg0.DevHandle)))) { | |
2275 | raid_device->device_info = | |
2276 | le32_to_cpu(sas_device_pg0.DeviceInfo); | |
2277 | } | |
2278 | } | |
2279 | ||
2280 | kfree(vol_pg0); | |
2281 | return 0; | |
2282 | } | |
2283 | ||
f92363d1 SR |
2284 | /** |
2285 | * _scsih_enable_tlr - setting TLR flags | |
2286 | * @ioc: per adapter object | |
2287 | * @sdev: scsi device struct | |
2288 | * | |
2289 | * Enabling Transaction Layer Retries for tape devices when | |
2290 | * vpd page 0x90 is present | |
2291 | * | |
2292 | */ | |
2293 | static void | |
2294 | _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev) | |
2295 | { | |
2296 | ||
2297 | /* only for TAPE */ | |
2298 | if (sdev->type != TYPE_TAPE) | |
2299 | return; | |
2300 | ||
2301 | if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR)) | |
2302 | return; | |
2303 | ||
2304 | sas_enable_tlr(sdev); | |
2305 | sdev_printk(KERN_INFO, sdev, "TLR %s\n", | |
2306 | sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled"); | |
2307 | return; | |
2308 | ||
2309 | } | |
2310 | ||
2311 | /** | |
8a7e4c24 | 2312 | * scsih_slave_configure - device configure routine. |
f92363d1 SR |
2313 | * @sdev: scsi device struct |
2314 | * | |
2315 | * Returns 0 if ok. Any other return is assumed to be an error and | |
2316 | * the device is ignored. | |
2317 | */ | |
8bbb1cf6 | 2318 | static int |
8a7e4c24 | 2319 | scsih_slave_configure(struct scsi_device *sdev) |
f92363d1 SR |
2320 | { |
2321 | struct Scsi_Host *shost = sdev->host; | |
2322 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
2323 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2324 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
2325 | struct _sas_device *sas_device; | |
d1b01d14 | 2326 | struct _pcie_device *pcie_device; |
f92363d1 SR |
2327 | struct _raid_device *raid_device; |
2328 | unsigned long flags; | |
2329 | int qdepth; | |
2330 | u8 ssp_target = 0; | |
2331 | char *ds = ""; | |
2332 | char *r_level = ""; | |
2333 | u16 handle, volume_handle = 0; | |
2334 | u64 volume_wwid = 0; | |
2335 | ||
2336 | qdepth = 1; | |
2337 | sas_device_priv_data = sdev->hostdata; | |
2338 | sas_device_priv_data->configured_lun = 1; | |
2339 | sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT; | |
2340 | sas_target_priv_data = sas_device_priv_data->sas_target; | |
2341 | handle = sas_target_priv_data->handle; | |
2342 | ||
2343 | /* raid volume handling */ | |
2344 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) { | |
2345 | ||
2346 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
c84b06a4 | 2347 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
2348 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
2349 | if (!raid_device) { | |
2350 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2351 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, | |
2352 | __LINE__, __func__)); | |
2353 | return 1; | |
2354 | } | |
2355 | ||
2356 | if (_scsih_get_volume_capabilities(ioc, raid_device)) { | |
2357 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2358 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, | |
2359 | __LINE__, __func__)); | |
2360 | return 1; | |
2361 | } | |
2362 | ||
7786ab6a SR |
2363 | /* |
2364 | * WARPDRIVE: Initialize the required data for Direct IO | |
2365 | */ | |
c84b06a4 | 2366 | mpt3sas_init_warpdrive_properties(ioc, raid_device); |
f92363d1 SR |
2367 | |
2368 | /* RAID Queue Depth Support | |
2369 | * IS volume = underlying qdepth of drive type, either | |
2370 | * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH | |
2371 | * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH) | |
2372 | */ | |
2373 | if (raid_device->device_info & | |
2374 | MPI2_SAS_DEVICE_INFO_SSP_TARGET) { | |
2375 | qdepth = MPT3SAS_SAS_QUEUE_DEPTH; | |
2376 | ds = "SSP"; | |
2377 | } else { | |
2378 | qdepth = MPT3SAS_SATA_QUEUE_DEPTH; | |
2379 | if (raid_device->device_info & | |
2380 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) | |
2381 | ds = "SATA"; | |
2382 | else | |
2383 | ds = "STP"; | |
2384 | } | |
2385 | ||
2386 | switch (raid_device->volume_type) { | |
2387 | case MPI2_RAID_VOL_TYPE_RAID0: | |
2388 | r_level = "RAID0"; | |
2389 | break; | |
2390 | case MPI2_RAID_VOL_TYPE_RAID1E: | |
2391 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
2392 | if (ioc->manu_pg10.OEMIdentifier && | |
2393 | (le32_to_cpu(ioc->manu_pg10.GenericFlags0) & | |
2394 | MFG10_GF0_R10_DISPLAY) && | |
2395 | !(raid_device->num_pds % 2)) | |
2396 | r_level = "RAID10"; | |
2397 | else | |
2398 | r_level = "RAID1E"; | |
2399 | break; | |
2400 | case MPI2_RAID_VOL_TYPE_RAID1: | |
2401 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
2402 | r_level = "RAID1"; | |
2403 | break; | |
2404 | case MPI2_RAID_VOL_TYPE_RAID10: | |
2405 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
2406 | r_level = "RAID10"; | |
2407 | break; | |
2408 | case MPI2_RAID_VOL_TYPE_UNKNOWN: | |
2409 | default: | |
2410 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
2411 | r_level = "RAIDX"; | |
2412 | break; | |
2413 | } | |
2414 | ||
7786ab6a SR |
2415 | if (!ioc->hide_ir_msg) |
2416 | sdev_printk(KERN_INFO, sdev, | |
2417 | "%s: handle(0x%04x), wwid(0x%016llx)," | |
2418 | " pd_count(%d), type(%s)\n", | |
2419 | r_level, raid_device->handle, | |
2420 | (unsigned long long)raid_device->wwid, | |
2421 | raid_device->num_pds, ds); | |
f92363d1 | 2422 | |
6c197093 C |
2423 | if (shost->max_sectors > MPT3SAS_RAID_MAX_SECTORS) { |
2424 | blk_queue_max_hw_sectors(sdev->request_queue, | |
2425 | MPT3SAS_RAID_MAX_SECTORS); | |
2426 | sdev_printk(KERN_INFO, sdev, | |
2427 | "Set queue's max_sector to: %u\n", | |
2428 | MPT3SAS_RAID_MAX_SECTORS); | |
2429 | } | |
2430 | ||
8a7e4c24 | 2431 | scsih_change_queue_depth(sdev, qdepth); |
f92363d1 | 2432 | |
7786ab6a SR |
2433 | /* raid transport support */ |
2434 | if (!ioc->is_warpdrive) | |
c84b06a4 | 2435 | _scsih_set_level(ioc, sdev, raid_device->volume_type); |
f92363d1 SR |
2436 | return 0; |
2437 | } | |
2438 | ||
2439 | /* non-raid handling */ | |
2440 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
2441 | if (mpt3sas_config_get_volume_handle(ioc, handle, | |
2442 | &volume_handle)) { | |
2443 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2444 | "failure at %s:%d/%s()!\n", ioc->name, | |
2445 | __FILE__, __LINE__, __func__)); | |
2446 | return 1; | |
2447 | } | |
2448 | if (volume_handle && mpt3sas_config_get_volume_wwid(ioc, | |
2449 | volume_handle, &volume_wwid)) { | |
2450 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2451 | "failure at %s:%d/%s()!\n", ioc->name, | |
2452 | __FILE__, __LINE__, __func__)); | |
2453 | return 1; | |
2454 | } | |
2455 | } | |
2456 | ||
d1b01d14 SPS |
2457 | /* PCIe handling */ |
2458 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) { | |
2459 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
2460 | pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, | |
2461 | sas_device_priv_data->sas_target->sas_address); | |
2462 | if (!pcie_device) { | |
2463 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
2464 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2465 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, | |
2466 | __LINE__, __func__)); | |
2467 | return 1; | |
2468 | } | |
2469 | ||
2470 | qdepth = MPT3SAS_NVME_QUEUE_DEPTH; | |
2471 | ds = "NVMe"; | |
2472 | sdev_printk(KERN_INFO, sdev, | |
2473 | "%s: handle(0x%04x), wwid(0x%016llx), port(%d)\n", | |
2474 | ds, handle, (unsigned long long)pcie_device->wwid, | |
2475 | pcie_device->port_num); | |
2476 | if (pcie_device->enclosure_handle != 0) | |
2477 | sdev_printk(KERN_INFO, sdev, | |
2478 | "%s: enclosure logical id(0x%016llx), slot(%d)\n", | |
2479 | ds, | |
2480 | (unsigned long long)pcie_device->enclosure_logical_id, | |
2481 | pcie_device->slot); | |
2482 | if (pcie_device->connector_name[0] != '\0') | |
2483 | sdev_printk(KERN_INFO, sdev, | |
2484 | "%s: enclosure level(0x%04x)," | |
2485 | "connector name( %s)\n", ds, | |
2486 | pcie_device->enclosure_level, | |
2487 | pcie_device->connector_name); | |
2488 | pcie_device_put(pcie_device); | |
2489 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
2490 | scsih_change_queue_depth(sdev, qdepth); | |
2491 | ||
2492 | if (pcie_device->nvme_mdts) | |
2493 | blk_queue_max_hw_sectors(sdev->request_queue, | |
2494 | pcie_device->nvme_mdts/512); | |
2495 | /* Enable QUEUE_FLAG_NOMERGES flag, so that IOs won't be | |
2496 | ** merged and can eliminate holes created during merging | |
2497 | ** operation. | |
2498 | **/ | |
2499 | queue_flag_set_unlocked(QUEUE_FLAG_NOMERGES, | |
2500 | sdev->request_queue); | |
2501 | blk_queue_virt_boundary(sdev->request_queue, | |
2502 | ioc->page_size - 1); | |
2503 | return 0; | |
2504 | } | |
2505 | ||
f92363d1 | 2506 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 2507 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 SR |
2508 | sas_device_priv_data->sas_target->sas_address); |
2509 | if (!sas_device) { | |
2510 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
2511 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2512 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | |
2513 | __func__)); | |
2514 | return 1; | |
2515 | } | |
2516 | ||
2517 | sas_device->volume_handle = volume_handle; | |
2518 | sas_device->volume_wwid = volume_wwid; | |
2519 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) { | |
2520 | qdepth = MPT3SAS_SAS_QUEUE_DEPTH; | |
2521 | ssp_target = 1; | |
30158dc9 SS |
2522 | if (sas_device->device_info & |
2523 | MPI2_SAS_DEVICE_INFO_SEP) { | |
2524 | sdev_printk(KERN_WARNING, sdev, | |
2525 | "set ignore_delay_remove for handle(0x%04x)\n", | |
2526 | sas_device_priv_data->sas_target->handle); | |
2527 | sas_device_priv_data->ignore_delay_remove = 1; | |
2528 | ds = "SES"; | |
2529 | } else | |
2530 | ds = "SSP"; | |
f92363d1 SR |
2531 | } else { |
2532 | qdepth = MPT3SAS_SATA_QUEUE_DEPTH; | |
2533 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) | |
2534 | ds = "STP"; | |
2535 | else if (sas_device->device_info & | |
2536 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) | |
2537 | ds = "SATA"; | |
2538 | } | |
2539 | ||
2540 | sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \ | |
2541 | "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n", | |
2542 | ds, handle, (unsigned long long)sas_device->sas_address, | |
2543 | sas_device->phy, (unsigned long long)sas_device->device_name); | |
75888956 SR |
2544 | |
2545 | _scsih_display_enclosure_chassis_info(NULL, sas_device, sdev, NULL); | |
f92363d1 | 2546 | |
d1cb5e49 | 2547 | sas_device_put(sas_device); |
f92363d1 SR |
2548 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
2549 | ||
2550 | if (!ssp_target) | |
2551 | _scsih_display_sata_capabilities(ioc, handle, sdev); | |
2552 | ||
2553 | ||
8a7e4c24 | 2554 | scsih_change_queue_depth(sdev, qdepth); |
f92363d1 SR |
2555 | |
2556 | if (ssp_target) { | |
2557 | sas_read_port_mode_page(sdev); | |
2558 | _scsih_enable_tlr(ioc, sdev); | |
2559 | } | |
2560 | ||
2561 | return 0; | |
2562 | } | |
2563 | ||
2564 | /** | |
8a7e4c24 | 2565 | * scsih_bios_param - fetch head, sector, cylinder info for a disk |
f92363d1 SR |
2566 | * @sdev: scsi device struct |
2567 | * @bdev: pointer to block device context | |
2568 | * @capacity: device size (in 512 byte sectors) | |
2569 | * @params: three element array to place output: | |
2570 | * params[0] number of heads (max 255) | |
2571 | * params[1] number of sectors (max 63) | |
2572 | * params[2] number of cylinders | |
2573 | * | |
2574 | * Return nothing. | |
2575 | */ | |
8bbb1cf6 | 2576 | static int |
8a7e4c24 | 2577 | scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev, |
f92363d1 SR |
2578 | sector_t capacity, int params[]) |
2579 | { | |
2580 | int heads; | |
2581 | int sectors; | |
2582 | sector_t cylinders; | |
2583 | ulong dummy; | |
2584 | ||
2585 | heads = 64; | |
2586 | sectors = 32; | |
2587 | ||
2588 | dummy = heads * sectors; | |
2589 | cylinders = capacity; | |
2590 | sector_div(cylinders, dummy); | |
2591 | ||
2592 | /* | |
2593 | * Handle extended translation size for logical drives | |
2594 | * > 1Gb | |
2595 | */ | |
2596 | if ((ulong)capacity >= 0x200000) { | |
2597 | heads = 255; | |
2598 | sectors = 63; | |
2599 | dummy = heads * sectors; | |
2600 | cylinders = capacity; | |
2601 | sector_div(cylinders, dummy); | |
2602 | } | |
2603 | ||
2604 | /* return result */ | |
2605 | params[0] = heads; | |
2606 | params[1] = sectors; | |
2607 | params[2] = cylinders; | |
2608 | ||
2609 | return 0; | |
2610 | } | |
2611 | ||
2612 | /** | |
2613 | * _scsih_response_code - translation of device response code | |
2614 | * @ioc: per adapter object | |
2615 | * @response_code: response code returned by the device | |
2616 | * | |
2617 | * Return nothing. | |
2618 | */ | |
2619 | static void | |
2620 | _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code) | |
2621 | { | |
2622 | char *desc; | |
2623 | ||
2624 | switch (response_code) { | |
2625 | case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE: | |
2626 | desc = "task management request completed"; | |
2627 | break; | |
2628 | case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME: | |
2629 | desc = "invalid frame"; | |
2630 | break; | |
2631 | case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED: | |
2632 | desc = "task management request not supported"; | |
2633 | break; | |
2634 | case MPI2_SCSITASKMGMT_RSP_TM_FAILED: | |
2635 | desc = "task management request failed"; | |
2636 | break; | |
2637 | case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED: | |
2638 | desc = "task management request succeeded"; | |
2639 | break; | |
2640 | case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN: | |
2641 | desc = "invalid lun"; | |
2642 | break; | |
2643 | case 0xA: | |
2644 | desc = "overlapped tag attempted"; | |
2645 | break; | |
2646 | case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC: | |
2647 | desc = "task queued, however not sent to target"; | |
2648 | break; | |
2649 | default: | |
2650 | desc = "unknown"; | |
2651 | break; | |
2652 | } | |
2653 | pr_warn(MPT3SAS_FMT "response_code(0x%01x): %s\n", | |
2654 | ioc->name, response_code, desc); | |
2655 | } | |
2656 | ||
2657 | /** | |
2658 | * _scsih_tm_done - tm completion routine | |
2659 | * @ioc: per adapter object | |
2660 | * @smid: system request message index | |
2661 | * @msix_index: MSIX table index supplied by the OS | |
2662 | * @reply: reply message frame(lower 32bit addr) | |
2663 | * Context: none. | |
2664 | * | |
2665 | * The callback handler when using scsih_issue_tm. | |
2666 | * | |
2667 | * Return 1 meaning mf should be freed from _base_interrupt | |
2668 | * 0 means the mf is freed from this function. | |
2669 | */ | |
2670 | static u8 | |
2671 | _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | |
2672 | { | |
2673 | MPI2DefaultReply_t *mpi_reply; | |
2674 | ||
2675 | if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED) | |
2676 | return 1; | |
2677 | if (ioc->tm_cmds.smid != smid) | |
2678 | return 1; | |
f92363d1 SR |
2679 | ioc->tm_cmds.status |= MPT3_CMD_COMPLETE; |
2680 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
2681 | if (mpi_reply) { | |
2682 | memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); | |
2683 | ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID; | |
2684 | } | |
2685 | ioc->tm_cmds.status &= ~MPT3_CMD_PENDING; | |
2686 | complete(&ioc->tm_cmds.done); | |
2687 | return 1; | |
2688 | } | |
2689 | ||
2690 | /** | |
2691 | * mpt3sas_scsih_set_tm_flag - set per target tm_busy | |
2692 | * @ioc: per adapter object | |
2693 | * @handle: device handle | |
2694 | * | |
2695 | * During taskmangement request, we need to freeze the device queue. | |
2696 | */ | |
2697 | void | |
2698 | mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
2699 | { | |
2700 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2701 | struct scsi_device *sdev; | |
2702 | u8 skip = 0; | |
2703 | ||
2704 | shost_for_each_device(sdev, ioc->shost) { | |
2705 | if (skip) | |
2706 | continue; | |
2707 | sas_device_priv_data = sdev->hostdata; | |
2708 | if (!sas_device_priv_data) | |
2709 | continue; | |
2710 | if (sas_device_priv_data->sas_target->handle == handle) { | |
2711 | sas_device_priv_data->sas_target->tm_busy = 1; | |
2712 | skip = 1; | |
2713 | ioc->ignore_loginfos = 1; | |
2714 | } | |
2715 | } | |
2716 | } | |
2717 | ||
2718 | /** | |
2719 | * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy | |
2720 | * @ioc: per adapter object | |
2721 | * @handle: device handle | |
2722 | * | |
2723 | * During taskmangement request, we need to freeze the device queue. | |
2724 | */ | |
2725 | void | |
2726 | mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
2727 | { | |
2728 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2729 | struct scsi_device *sdev; | |
2730 | u8 skip = 0; | |
2731 | ||
2732 | shost_for_each_device(sdev, ioc->shost) { | |
2733 | if (skip) | |
2734 | continue; | |
2735 | sas_device_priv_data = sdev->hostdata; | |
2736 | if (!sas_device_priv_data) | |
2737 | continue; | |
2738 | if (sas_device_priv_data->sas_target->handle == handle) { | |
2739 | sas_device_priv_data->sas_target->tm_busy = 0; | |
2740 | skip = 1; | |
2741 | ioc->ignore_loginfos = 0; | |
2742 | } | |
2743 | } | |
2744 | } | |
2745 | ||
2746 | /** | |
2747 | * mpt3sas_scsih_issue_tm - main routine for sending tm requests | |
2748 | * @ioc: per adapter struct | |
2749 | * @device_handle: device handle | |
2750 | * @channel: the channel assigned by the OS | |
2751 | * @id: the id assigned by the OS | |
2752 | * @lun: lun number | |
2753 | * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h) | |
2754 | * @smid_task: smid assigned to the task | |
2755 | * @timeout: timeout in seconds | |
f92363d1 SR |
2756 | * Context: user |
2757 | * | |
2758 | * A generic API for sending task management requests to firmware. | |
2759 | * | |
2760 | * The callback index is set inside `ioc->tm_cb_idx`. | |
2761 | * | |
2762 | * Return SUCCESS or FAILED. | |
2763 | */ | |
2764 | int | |
2765 | mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, uint channel, | |
96902835 | 2766 | uint id, uint lun, u8 type, u16 smid_task, ulong timeout) |
f92363d1 SR |
2767 | { |
2768 | Mpi2SCSITaskManagementRequest_t *mpi_request; | |
2769 | Mpi2SCSITaskManagementReply_t *mpi_reply; | |
2770 | u16 smid = 0; | |
2771 | u32 ioc_state; | |
f92363d1 SR |
2772 | struct scsiio_tracker *scsi_lookup = NULL; |
2773 | int rc; | |
03d1fb3a | 2774 | u16 msix_task = 0; |
f92363d1 | 2775 | |
96902835 CO |
2776 | lockdep_assert_held(&ioc->tm_cmds.mutex); |
2777 | ||
f92363d1 SR |
2778 | if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) { |
2779 | pr_info(MPT3SAS_FMT "%s: tm_cmd busy!!!\n", | |
2780 | __func__, ioc->name); | |
96902835 | 2781 | return FAILED; |
f92363d1 SR |
2782 | } |
2783 | ||
2784 | if (ioc->shost_recovery || ioc->remove_host || | |
2785 | ioc->pci_error_recovery) { | |
2786 | pr_info(MPT3SAS_FMT "%s: host reset in progress!\n", | |
2787 | __func__, ioc->name); | |
96902835 | 2788 | return FAILED; |
f92363d1 SR |
2789 | } |
2790 | ||
2791 | ioc_state = mpt3sas_base_get_iocstate(ioc, 0); | |
2792 | if (ioc_state & MPI2_DOORBELL_USED) { | |
2793 | dhsprintk(ioc, pr_info(MPT3SAS_FMT | |
2794 | "unexpected doorbell active!\n", ioc->name)); | |
98c56ad3 | 2795 | rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
96902835 | 2796 | return (!rc) ? SUCCESS : FAILED; |
f92363d1 SR |
2797 | } |
2798 | ||
2799 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { | |
2800 | mpt3sas_base_fault_info(ioc, ioc_state & | |
2801 | MPI2_DOORBELL_DATA_MASK); | |
98c56ad3 | 2802 | rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
96902835 | 2803 | return (!rc) ? SUCCESS : FAILED; |
f92363d1 SR |
2804 | } |
2805 | ||
2806 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx); | |
2807 | if (!smid) { | |
2808 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
2809 | ioc->name, __func__); | |
96902835 | 2810 | return FAILED; |
f92363d1 SR |
2811 | } |
2812 | ||
2813 | if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) | |
2814 | scsi_lookup = &ioc->scsi_lookup[smid_task - 1]; | |
2815 | ||
2816 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
2817 | "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n", | |
2818 | ioc->name, handle, type, smid_task)); | |
2819 | ioc->tm_cmds.status = MPT3_CMD_PENDING; | |
2820 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
2821 | ioc->tm_cmds.smid = smid; | |
2822 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | |
2823 | memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t)); | |
2824 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | |
2825 | mpi_request->DevHandle = cpu_to_le16(handle); | |
2826 | mpi_request->TaskType = type; | |
2827 | mpi_request->TaskMID = cpu_to_le16(smid_task); | |
2828 | int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN); | |
2829 | mpt3sas_scsih_set_tm_flag(ioc, handle); | |
2830 | init_completion(&ioc->tm_cmds.done); | |
03d1fb3a SS |
2831 | if ((type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) && |
2832 | (scsi_lookup->msix_io < ioc->reply_queue_count)) | |
2833 | msix_task = scsi_lookup->msix_io; | |
2834 | else | |
2835 | msix_task = 0; | |
81c16f83 | 2836 | ioc->put_smid_hi_priority(ioc, smid, msix_task); |
8bbb1cf6 | 2837 | wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ); |
f92363d1 SR |
2838 | if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) { |
2839 | pr_err(MPT3SAS_FMT "%s: timeout\n", | |
2840 | ioc->name, __func__); | |
2841 | _debug_dump_mf(mpi_request, | |
2842 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); | |
2843 | if (!(ioc->tm_cmds.status & MPT3_CMD_RESET)) { | |
98c56ad3 CO |
2844 | rc = mpt3sas_base_hard_reset_handler(ioc, |
2845 | FORCE_BIG_HAMMER); | |
f92363d1 | 2846 | rc = (!rc) ? SUCCESS : FAILED; |
96902835 | 2847 | goto out; |
f92363d1 SR |
2848 | } |
2849 | } | |
2850 | ||
5f0dfb7a C |
2851 | /* sync IRQs in case those were busy during flush. */ |
2852 | mpt3sas_base_sync_reply_irqs(ioc); | |
2853 | ||
f92363d1 SR |
2854 | if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) { |
2855 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT); | |
2856 | mpi_reply = ioc->tm_cmds.reply; | |
2857 | dtmprintk(ioc, pr_info(MPT3SAS_FMT "complete tm: " \ | |
2858 | "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n", | |
2859 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), | |
2860 | le32_to_cpu(mpi_reply->IOCLogInfo), | |
2861 | le32_to_cpu(mpi_reply->TerminationCount))); | |
2862 | if (ioc->logging_level & MPT_DEBUG_TM) { | |
2863 | _scsih_response_code(ioc, mpi_reply->ResponseCode); | |
2864 | if (mpi_reply->IOCStatus) | |
2865 | _debug_dump_mf(mpi_request, | |
2866 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); | |
2867 | } | |
2868 | } | |
2869 | ||
2870 | switch (type) { | |
2871 | case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK: | |
2872 | rc = SUCCESS; | |
2873 | if (scsi_lookup->scmd == NULL) | |
2874 | break; | |
2875 | rc = FAILED; | |
2876 | break; | |
2877 | ||
2878 | case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET: | |
2879 | if (_scsih_scsi_lookup_find_by_target(ioc, id, channel)) | |
2880 | rc = FAILED; | |
2881 | else | |
2882 | rc = SUCCESS; | |
2883 | break; | |
2884 | case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET: | |
2885 | case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET: | |
2886 | if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel)) | |
2887 | rc = FAILED; | |
2888 | else | |
2889 | rc = SUCCESS; | |
2890 | break; | |
2891 | case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK: | |
2892 | rc = SUCCESS; | |
2893 | break; | |
2894 | default: | |
2895 | rc = FAILED; | |
2896 | break; | |
2897 | } | |
2898 | ||
96902835 | 2899 | out: |
f92363d1 SR |
2900 | mpt3sas_scsih_clear_tm_flag(ioc, handle); |
2901 | ioc->tm_cmds.status = MPT3_CMD_NOT_USED; | |
f92363d1 | 2902 | return rc; |
96902835 | 2903 | } |
f92363d1 | 2904 | |
96902835 CO |
2905 | int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, |
2906 | uint channel, uint id, uint lun, u8 type, u16 smid_task, ulong timeout) | |
2907 | { | |
2908 | int ret; | |
2909 | ||
2910 | mutex_lock(&ioc->tm_cmds.mutex); | |
2911 | ret = mpt3sas_scsih_issue_tm(ioc, handle, channel, id, lun, type, | |
2912 | smid_task, timeout); | |
2913 | mutex_unlock(&ioc->tm_cmds.mutex); | |
2914 | ||
2915 | return ret; | |
f92363d1 SR |
2916 | } |
2917 | ||
2918 | /** | |
2919 | * _scsih_tm_display_info - displays info about the device | |
2920 | * @ioc: per adapter struct | |
2921 | * @scmd: pointer to scsi command object | |
2922 | * | |
2923 | * Called by task management callback handlers. | |
2924 | */ | |
2925 | static void | |
2926 | _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd) | |
2927 | { | |
2928 | struct scsi_target *starget = scmd->device->sdev_target; | |
2929 | struct MPT3SAS_TARGET *priv_target = starget->hostdata; | |
2930 | struct _sas_device *sas_device = NULL; | |
2931 | unsigned long flags; | |
2932 | char *device_str = NULL; | |
2933 | ||
2934 | if (!priv_target) | |
2935 | return; | |
7786ab6a SR |
2936 | if (ioc->hide_ir_msg) |
2937 | device_str = "WarpDrive"; | |
2938 | else | |
2939 | device_str = "volume"; | |
f92363d1 SR |
2940 | |
2941 | scsi_print_command(scmd); | |
2942 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { | |
2943 | starget_printk(KERN_INFO, starget, | |
2944 | "%s handle(0x%04x), %s wwid(0x%016llx)\n", | |
2945 | device_str, priv_target->handle, | |
2946 | device_str, (unsigned long long)priv_target->sas_address); | |
2947 | } else { | |
2948 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 | 2949 | sas_device = __mpt3sas_get_sdev_from_target(ioc, priv_target); |
f92363d1 SR |
2950 | if (sas_device) { |
2951 | if (priv_target->flags & | |
2952 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
2953 | starget_printk(KERN_INFO, starget, | |
2954 | "volume handle(0x%04x), " | |
2955 | "volume wwid(0x%016llx)\n", | |
2956 | sas_device->volume_handle, | |
2957 | (unsigned long long)sas_device->volume_wwid); | |
2958 | } | |
2959 | starget_printk(KERN_INFO, starget, | |
2960 | "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n", | |
2961 | sas_device->handle, | |
2962 | (unsigned long long)sas_device->sas_address, | |
2963 | sas_device->phy); | |
75888956 SR |
2964 | |
2965 | _scsih_display_enclosure_chassis_info(NULL, sas_device, | |
2966 | NULL, starget); | |
d1cb5e49 SR |
2967 | |
2968 | sas_device_put(sas_device); | |
f92363d1 SR |
2969 | } |
2970 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
2971 | } | |
2972 | } | |
2973 | ||
2974 | /** | |
8a7e4c24 | 2975 | * scsih_abort - eh threads main abort routine |
f92363d1 SR |
2976 | * @scmd: pointer to scsi command object |
2977 | * | |
2978 | * Returns SUCCESS if command aborted else FAILED | |
2979 | */ | |
8bbb1cf6 | 2980 | static int |
8a7e4c24 | 2981 | scsih_abort(struct scsi_cmnd *scmd) |
f92363d1 SR |
2982 | { |
2983 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
2984 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2985 | u16 smid; | |
2986 | u16 handle; | |
2987 | int r; | |
2988 | ||
2989 | sdev_printk(KERN_INFO, scmd->device, | |
2990 | "attempting task abort! scmd(%p)\n", scmd); | |
2991 | _scsih_tm_display_info(ioc, scmd); | |
2992 | ||
2993 | sas_device_priv_data = scmd->device->hostdata; | |
2994 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | |
2995 | sdev_printk(KERN_INFO, scmd->device, | |
2996 | "device been deleted! scmd(%p)\n", scmd); | |
2997 | scmd->result = DID_NO_CONNECT << 16; | |
2998 | scmd->scsi_done(scmd); | |
2999 | r = SUCCESS; | |
3000 | goto out; | |
3001 | } | |
3002 | ||
3003 | /* search for the command */ | |
3004 | smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd); | |
3005 | if (!smid) { | |
3006 | scmd->result = DID_RESET << 16; | |
3007 | r = SUCCESS; | |
3008 | goto out; | |
3009 | } | |
3010 | ||
3011 | /* for hidden raid components and volumes this is not supported */ | |
3012 | if (sas_device_priv_data->sas_target->flags & | |
3013 | MPT_TARGET_FLAGS_RAID_COMPONENT || | |
3014 | sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) { | |
3015 | scmd->result = DID_RESET << 16; | |
3016 | r = FAILED; | |
3017 | goto out; | |
3018 | } | |
3019 | ||
3020 | mpt3sas_halt_firmware(ioc); | |
3021 | ||
3022 | handle = sas_device_priv_data->sas_target->handle; | |
96902835 | 3023 | r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel, |
f92363d1 | 3024 | scmd->device->id, scmd->device->lun, |
96902835 | 3025 | MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30); |
f92363d1 SR |
3026 | |
3027 | out: | |
3028 | sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n", | |
3029 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
3030 | return r; | |
3031 | } | |
3032 | ||
3033 | /** | |
8a7e4c24 | 3034 | * scsih_dev_reset - eh threads main device reset routine |
f92363d1 SR |
3035 | * @scmd: pointer to scsi command object |
3036 | * | |
3037 | * Returns SUCCESS if command aborted else FAILED | |
3038 | */ | |
8bbb1cf6 | 3039 | static int |
8a7e4c24 | 3040 | scsih_dev_reset(struct scsi_cmnd *scmd) |
f92363d1 SR |
3041 | { |
3042 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
3043 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
d1cb5e49 | 3044 | struct _sas_device *sas_device = NULL; |
f92363d1 SR |
3045 | u16 handle; |
3046 | int r; | |
3047 | ||
d1cb5e49 SR |
3048 | struct scsi_target *starget = scmd->device->sdev_target; |
3049 | struct MPT3SAS_TARGET *target_priv_data = starget->hostdata; | |
3050 | ||
f92363d1 SR |
3051 | sdev_printk(KERN_INFO, scmd->device, |
3052 | "attempting device reset! scmd(%p)\n", scmd); | |
3053 | _scsih_tm_display_info(ioc, scmd); | |
3054 | ||
3055 | sas_device_priv_data = scmd->device->hostdata; | |
3056 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | |
3057 | sdev_printk(KERN_INFO, scmd->device, | |
3058 | "device been deleted! scmd(%p)\n", scmd); | |
3059 | scmd->result = DID_NO_CONNECT << 16; | |
3060 | scmd->scsi_done(scmd); | |
3061 | r = SUCCESS; | |
3062 | goto out; | |
3063 | } | |
3064 | ||
3065 | /* for hidden raid components obtain the volume_handle */ | |
3066 | handle = 0; | |
3067 | if (sas_device_priv_data->sas_target->flags & | |
3068 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
d1cb5e49 SR |
3069 | sas_device = mpt3sas_get_sdev_from_target(ioc, |
3070 | target_priv_data); | |
f92363d1 SR |
3071 | if (sas_device) |
3072 | handle = sas_device->volume_handle; | |
f92363d1 SR |
3073 | } else |
3074 | handle = sas_device_priv_data->sas_target->handle; | |
3075 | ||
3076 | if (!handle) { | |
3077 | scmd->result = DID_RESET << 16; | |
3078 | r = FAILED; | |
3079 | goto out; | |
3080 | } | |
3081 | ||
96902835 | 3082 | r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel, |
f92363d1 | 3083 | scmd->device->id, scmd->device->lun, |
96902835 | 3084 | MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30); |
f92363d1 SR |
3085 | |
3086 | out: | |
3087 | sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n", | |
3088 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
d1cb5e49 SR |
3089 | |
3090 | if (sas_device) | |
3091 | sas_device_put(sas_device); | |
3092 | ||
f92363d1 SR |
3093 | return r; |
3094 | } | |
3095 | ||
3096 | /** | |
8a7e4c24 | 3097 | * scsih_target_reset - eh threads main target reset routine |
f92363d1 SR |
3098 | * @scmd: pointer to scsi command object |
3099 | * | |
3100 | * Returns SUCCESS if command aborted else FAILED | |
3101 | */ | |
8bbb1cf6 | 3102 | static int |
8a7e4c24 | 3103 | scsih_target_reset(struct scsi_cmnd *scmd) |
f92363d1 SR |
3104 | { |
3105 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
3106 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
d1cb5e49 | 3107 | struct _sas_device *sas_device = NULL; |
f92363d1 SR |
3108 | u16 handle; |
3109 | int r; | |
3110 | struct scsi_target *starget = scmd->device->sdev_target; | |
d1cb5e49 | 3111 | struct MPT3SAS_TARGET *target_priv_data = starget->hostdata; |
f92363d1 SR |
3112 | |
3113 | starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n", | |
3114 | scmd); | |
3115 | _scsih_tm_display_info(ioc, scmd); | |
3116 | ||
3117 | sas_device_priv_data = scmd->device->hostdata; | |
3118 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | |
3119 | starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n", | |
3120 | scmd); | |
3121 | scmd->result = DID_NO_CONNECT << 16; | |
3122 | scmd->scsi_done(scmd); | |
3123 | r = SUCCESS; | |
3124 | goto out; | |
3125 | } | |
3126 | ||
3127 | /* for hidden raid components obtain the volume_handle */ | |
3128 | handle = 0; | |
3129 | if (sas_device_priv_data->sas_target->flags & | |
3130 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
d1cb5e49 SR |
3131 | sas_device = mpt3sas_get_sdev_from_target(ioc, |
3132 | target_priv_data); | |
f92363d1 SR |
3133 | if (sas_device) |
3134 | handle = sas_device->volume_handle; | |
f92363d1 SR |
3135 | } else |
3136 | handle = sas_device_priv_data->sas_target->handle; | |
3137 | ||
3138 | if (!handle) { | |
3139 | scmd->result = DID_RESET << 16; | |
3140 | r = FAILED; | |
3141 | goto out; | |
3142 | } | |
3143 | ||
96902835 | 3144 | r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel, |
f92363d1 | 3145 | scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, |
96902835 | 3146 | 30); |
f92363d1 SR |
3147 | |
3148 | out: | |
3149 | starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n", | |
3150 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
d1cb5e49 SR |
3151 | |
3152 | if (sas_device) | |
3153 | sas_device_put(sas_device); | |
3154 | ||
f92363d1 SR |
3155 | return r; |
3156 | } | |
3157 | ||
3158 | ||
3159 | /** | |
8a7e4c24 | 3160 | * scsih_host_reset - eh threads main host reset routine |
f92363d1 SR |
3161 | * @scmd: pointer to scsi command object |
3162 | * | |
3163 | * Returns SUCCESS if command aborted else FAILED | |
3164 | */ | |
8bbb1cf6 | 3165 | static int |
8a7e4c24 | 3166 | scsih_host_reset(struct scsi_cmnd *scmd) |
f92363d1 SR |
3167 | { |
3168 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
3169 | int r, retval; | |
3170 | ||
3171 | pr_info(MPT3SAS_FMT "attempting host reset! scmd(%p)\n", | |
3172 | ioc->name, scmd); | |
3173 | scsi_print_command(scmd); | |
3174 | ||
ddb588be SR |
3175 | if (ioc->is_driver_loading) { |
3176 | pr_info(MPT3SAS_FMT "Blocking the host reset\n", | |
3177 | ioc->name); | |
3178 | r = FAILED; | |
3179 | goto out; | |
3180 | } | |
3181 | ||
98c56ad3 | 3182 | retval = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
f92363d1 | 3183 | r = (retval < 0) ? FAILED : SUCCESS; |
ddb588be | 3184 | out: |
f92363d1 SR |
3185 | pr_info(MPT3SAS_FMT "host reset: %s scmd(%p)\n", |
3186 | ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
3187 | ||
3188 | return r; | |
3189 | } | |
3190 | ||
3191 | /** | |
3192 | * _scsih_fw_event_add - insert and queue up fw_event | |
3193 | * @ioc: per adapter object | |
3194 | * @fw_event: object describing the event | |
3195 | * Context: This function will acquire ioc->fw_event_lock. | |
3196 | * | |
3197 | * This adds the firmware event object into link list, then queues it up to | |
3198 | * be processed from user context. | |
3199 | * | |
3200 | * Return nothing. | |
3201 | */ | |
3202 | static void | |
3203 | _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event) | |
3204 | { | |
3205 | unsigned long flags; | |
3206 | ||
3207 | if (ioc->firmware_event_thread == NULL) | |
3208 | return; | |
3209 | ||
3210 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
146b16c8 | 3211 | fw_event_work_get(fw_event); |
f92363d1 SR |
3212 | INIT_LIST_HEAD(&fw_event->list); |
3213 | list_add_tail(&fw_event->list, &ioc->fw_event_list); | |
3214 | INIT_WORK(&fw_event->work, _firmware_event_work); | |
146b16c8 | 3215 | fw_event_work_get(fw_event); |
f92363d1 SR |
3216 | queue_work(ioc->firmware_event_thread, &fw_event->work); |
3217 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
3218 | } | |
3219 | ||
3220 | /** | |
146b16c8 | 3221 | * _scsih_fw_event_del_from_list - delete fw_event from the list |
f92363d1 SR |
3222 | * @ioc: per adapter object |
3223 | * @fw_event: object describing the event | |
3224 | * Context: This function will acquire ioc->fw_event_lock. | |
3225 | * | |
146b16c8 | 3226 | * If the fw_event is on the fw_event_list, remove it and do a put. |
f92363d1 SR |
3227 | * |
3228 | * Return nothing. | |
3229 | */ | |
3230 | static void | |
146b16c8 | 3231 | _scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work |
f92363d1 SR |
3232 | *fw_event) |
3233 | { | |
3234 | unsigned long flags; | |
3235 | ||
3236 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
146b16c8 SR |
3237 | if (!list_empty(&fw_event->list)) { |
3238 | list_del_init(&fw_event->list); | |
3239 | fw_event_work_put(fw_event); | |
3240 | } | |
f92363d1 SR |
3241 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
3242 | } | |
3243 | ||
3244 | ||
3245 | /** | |
3246 | * mpt3sas_send_trigger_data_event - send event for processing trigger data | |
3247 | * @ioc: per adapter object | |
3248 | * @event_data: trigger event data | |
3249 | * | |
3250 | * Return nothing. | |
3251 | */ | |
3252 | void | |
3253 | mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc, | |
3254 | struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data) | |
3255 | { | |
3256 | struct fw_event_work *fw_event; | |
146b16c8 | 3257 | u16 sz; |
f92363d1 SR |
3258 | |
3259 | if (ioc->is_driver_loading) | |
3260 | return; | |
146b16c8 SR |
3261 | sz = sizeof(*event_data); |
3262 | fw_event = alloc_fw_event_work(sz); | |
f92363d1 SR |
3263 | if (!fw_event) |
3264 | return; | |
f92363d1 SR |
3265 | fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG; |
3266 | fw_event->ioc = ioc; | |
3267 | memcpy(fw_event->event_data, event_data, sizeof(*event_data)); | |
3268 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 | 3269 | fw_event_work_put(fw_event); |
f92363d1 SR |
3270 | } |
3271 | ||
3272 | /** | |
3273 | * _scsih_error_recovery_delete_devices - remove devices not responding | |
3274 | * @ioc: per adapter object | |
3275 | * | |
3276 | * Return nothing. | |
3277 | */ | |
3278 | static void | |
3279 | _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc) | |
3280 | { | |
3281 | struct fw_event_work *fw_event; | |
3282 | ||
3283 | if (ioc->is_driver_loading) | |
3284 | return; | |
146b16c8 | 3285 | fw_event = alloc_fw_event_work(0); |
f92363d1 SR |
3286 | if (!fw_event) |
3287 | return; | |
3288 | fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES; | |
3289 | fw_event->ioc = ioc; | |
3290 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 | 3291 | fw_event_work_put(fw_event); |
f92363d1 SR |
3292 | } |
3293 | ||
3294 | /** | |
3295 | * mpt3sas_port_enable_complete - port enable completed (fake event) | |
3296 | * @ioc: per adapter object | |
3297 | * | |
3298 | * Return nothing. | |
3299 | */ | |
3300 | void | |
3301 | mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc) | |
3302 | { | |
3303 | struct fw_event_work *fw_event; | |
3304 | ||
146b16c8 | 3305 | fw_event = alloc_fw_event_work(0); |
f92363d1 SR |
3306 | if (!fw_event) |
3307 | return; | |
3308 | fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE; | |
3309 | fw_event->ioc = ioc; | |
3310 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 SR |
3311 | fw_event_work_put(fw_event); |
3312 | } | |
3313 | ||
3314 | static struct fw_event_work *dequeue_next_fw_event(struct MPT3SAS_ADAPTER *ioc) | |
3315 | { | |
3316 | unsigned long flags; | |
3317 | struct fw_event_work *fw_event = NULL; | |
3318 | ||
3319 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
3320 | if (!list_empty(&ioc->fw_event_list)) { | |
3321 | fw_event = list_first_entry(&ioc->fw_event_list, | |
3322 | struct fw_event_work, list); | |
3323 | list_del_init(&fw_event->list); | |
3324 | } | |
3325 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
3326 | ||
3327 | return fw_event; | |
f92363d1 SR |
3328 | } |
3329 | ||
3330 | /** | |
3331 | * _scsih_fw_event_cleanup_queue - cleanup event queue | |
3332 | * @ioc: per adapter object | |
3333 | * | |
3334 | * Walk the firmware event queue, either killing timers, or waiting | |
3335 | * for outstanding events to complete | |
3336 | * | |
3337 | * Return nothing. | |
3338 | */ | |
3339 | static void | |
3340 | _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc) | |
3341 | { | |
146b16c8 | 3342 | struct fw_event_work *fw_event; |
f92363d1 SR |
3343 | |
3344 | if (list_empty(&ioc->fw_event_list) || | |
3345 | !ioc->firmware_event_thread || in_interrupt()) | |
3346 | return; | |
3347 | ||
146b16c8 SR |
3348 | while ((fw_event = dequeue_next_fw_event(ioc))) { |
3349 | /* | |
3350 | * Wait on the fw_event to complete. If this returns 1, then | |
3351 | * the event was never executed, and we need a put for the | |
b8ac0cc7 | 3352 | * reference the work had on the fw_event. |
146b16c8 SR |
3353 | * |
3354 | * If it did execute, we wait for it to finish, and the put will | |
3355 | * happen from _firmware_event_work() | |
3356 | */ | |
b8ac0cc7 | 3357 | if (cancel_work_sync(&fw_event->work)) |
146b16c8 SR |
3358 | fw_event_work_put(fw_event); |
3359 | ||
3360 | fw_event_work_put(fw_event); | |
f92363d1 SR |
3361 | } |
3362 | } | |
3363 | ||
df838f92 SR |
3364 | /** |
3365 | * _scsih_internal_device_block - block the sdev device | |
3366 | * @sdev: per device object | |
3367 | * @sas_device_priv_data : per device driver private data | |
3368 | * | |
3369 | * make sure device is blocked without error, if not | |
3370 | * print an error | |
3371 | */ | |
3372 | static void | |
3373 | _scsih_internal_device_block(struct scsi_device *sdev, | |
3374 | struct MPT3SAS_DEVICE *sas_device_priv_data) | |
3375 | { | |
3376 | int r = 0; | |
3377 | ||
3378 | sdev_printk(KERN_INFO, sdev, "device_block, handle(0x%04x)\n", | |
3379 | sas_device_priv_data->sas_target->handle); | |
3380 | sas_device_priv_data->block = 1; | |
3381 | ||
551eb598 | 3382 | r = scsi_internal_device_block_nowait(sdev); |
df838f92 SR |
3383 | if (r == -EINVAL) |
3384 | sdev_printk(KERN_WARNING, sdev, | |
3385 | "device_block failed with return(%d) for handle(0x%04x)\n", | |
b2fe6be7 | 3386 | r, sas_device_priv_data->sas_target->handle); |
df838f92 SR |
3387 | } |
3388 | ||
3389 | /** | |
3390 | * _scsih_internal_device_unblock - unblock the sdev device | |
3391 | * @sdev: per device object | |
3392 | * @sas_device_priv_data : per device driver private data | |
3393 | * make sure device is unblocked without error, if not retry | |
3394 | * by blocking and then unblocking | |
3395 | */ | |
3396 | ||
3397 | static void | |
3398 | _scsih_internal_device_unblock(struct scsi_device *sdev, | |
3399 | struct MPT3SAS_DEVICE *sas_device_priv_data) | |
3400 | { | |
3401 | int r = 0; | |
3402 | ||
3403 | sdev_printk(KERN_WARNING, sdev, "device_unblock and setting to running, " | |
3404 | "handle(0x%04x)\n", sas_device_priv_data->sas_target->handle); | |
3405 | sas_device_priv_data->block = 0; | |
43f7571b | 3406 | r = scsi_internal_device_unblock_nowait(sdev, SDEV_RUNNING); |
df838f92 SR |
3407 | if (r == -EINVAL) { |
3408 | /* The device has been set to SDEV_RUNNING by SD layer during | |
3409 | * device addition but the request queue is still stopped by | |
3410 | * our earlier block call. We need to perform a block again | |
3411 | * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */ | |
3412 | ||
3413 | sdev_printk(KERN_WARNING, sdev, | |
3414 | "device_unblock failed with return(%d) for handle(0x%04x) " | |
3415 | "performing a block followed by an unblock\n", | |
b2fe6be7 | 3416 | r, sas_device_priv_data->sas_target->handle); |
df838f92 | 3417 | sas_device_priv_data->block = 1; |
551eb598 | 3418 | r = scsi_internal_device_block_nowait(sdev); |
df838f92 SR |
3419 | if (r) |
3420 | sdev_printk(KERN_WARNING, sdev, "retried device_block " | |
3421 | "failed with return(%d) for handle(0x%04x)\n", | |
b2fe6be7 | 3422 | r, sas_device_priv_data->sas_target->handle); |
df838f92 SR |
3423 | |
3424 | sas_device_priv_data->block = 0; | |
43f7571b | 3425 | r = scsi_internal_device_unblock_nowait(sdev, SDEV_RUNNING); |
df838f92 SR |
3426 | if (r) |
3427 | sdev_printk(KERN_WARNING, sdev, "retried device_unblock" | |
3428 | " failed with return(%d) for handle(0x%04x)\n", | |
b2fe6be7 | 3429 | r, sas_device_priv_data->sas_target->handle); |
df838f92 SR |
3430 | } |
3431 | } | |
3432 | ||
f92363d1 SR |
3433 | /** |
3434 | * _scsih_ublock_io_all_device - unblock every device | |
3435 | * @ioc: per adapter object | |
3436 | * | |
3437 | * change the device state from block to running | |
3438 | */ | |
3439 | static void | |
3440 | _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc) | |
3441 | { | |
3442 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
3443 | struct scsi_device *sdev; | |
3444 | ||
3445 | shost_for_each_device(sdev, ioc->shost) { | |
3446 | sas_device_priv_data = sdev->hostdata; | |
3447 | if (!sas_device_priv_data) | |
3448 | continue; | |
3449 | if (!sas_device_priv_data->block) | |
3450 | continue; | |
3451 | ||
f92363d1 SR |
3452 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, |
3453 | "device_running, handle(0x%04x)\n", | |
3454 | sas_device_priv_data->sas_target->handle)); | |
df838f92 | 3455 | _scsih_internal_device_unblock(sdev, sas_device_priv_data); |
f92363d1 SR |
3456 | } |
3457 | } | |
3458 | ||
3459 | ||
3460 | /** | |
3461 | * _scsih_ublock_io_device - prepare device to be deleted | |
3462 | * @ioc: per adapter object | |
3463 | * @sas_addr: sas address | |
3464 | * | |
3465 | * unblock then put device in offline state | |
3466 | */ | |
3467 | static void | |
3468 | _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address) | |
3469 | { | |
3470 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
3471 | struct scsi_device *sdev; | |
3472 | ||
3473 | shost_for_each_device(sdev, ioc->shost) { | |
3474 | sas_device_priv_data = sdev->hostdata; | |
3475 | if (!sas_device_priv_data) | |
3476 | continue; | |
3477 | if (sas_device_priv_data->sas_target->sas_address | |
3478 | != sas_address) | |
3479 | continue; | |
df838f92 SR |
3480 | if (sas_device_priv_data->block) |
3481 | _scsih_internal_device_unblock(sdev, | |
3482 | sas_device_priv_data); | |
f92363d1 SR |
3483 | } |
3484 | } | |
3485 | ||
3486 | /** | |
3487 | * _scsih_block_io_all_device - set the device state to SDEV_BLOCK | |
3488 | * @ioc: per adapter object | |
3489 | * @handle: device handle | |
3490 | * | |
6c7abffc | 3491 | * During device pull we need to appropriately set the sdev state. |
f92363d1 SR |
3492 | */ |
3493 | static void | |
3494 | _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc) | |
3495 | { | |
3496 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
3497 | struct scsi_device *sdev; | |
3498 | ||
3499 | shost_for_each_device(sdev, ioc->shost) { | |
3500 | sas_device_priv_data = sdev->hostdata; | |
3501 | if (!sas_device_priv_data) | |
3502 | continue; | |
3503 | if (sas_device_priv_data->block) | |
3504 | continue; | |
30158dc9 SS |
3505 | if (sas_device_priv_data->ignore_delay_remove) { |
3506 | sdev_printk(KERN_INFO, sdev, | |
3507 | "%s skip device_block for SES handle(0x%04x)\n", | |
3508 | __func__, sas_device_priv_data->sas_target->handle); | |
3509 | continue; | |
3510 | } | |
df838f92 | 3511 | _scsih_internal_device_block(sdev, sas_device_priv_data); |
f92363d1 SR |
3512 | } |
3513 | } | |
3514 | ||
3515 | /** | |
3516 | * _scsih_block_io_device - set the device state to SDEV_BLOCK | |
3517 | * @ioc: per adapter object | |
3518 | * @handle: device handle | |
3519 | * | |
6c7abffc | 3520 | * During device pull we need to appropriately set the sdev state. |
f92363d1 SR |
3521 | */ |
3522 | static void | |
3523 | _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
3524 | { | |
3525 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
3526 | struct scsi_device *sdev; | |
e4bc7f5c SR |
3527 | struct _sas_device *sas_device; |
3528 | ||
d1cb5e49 | 3529 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
3530 | |
3531 | shost_for_each_device(sdev, ioc->shost) { | |
3532 | sas_device_priv_data = sdev->hostdata; | |
3533 | if (!sas_device_priv_data) | |
3534 | continue; | |
3535 | if (sas_device_priv_data->sas_target->handle != handle) | |
3536 | continue; | |
3537 | if (sas_device_priv_data->block) | |
3538 | continue; | |
4318c734 | 3539 | if (sas_device && sas_device->pend_sas_rphy_add) |
e4bc7f5c | 3540 | continue; |
30158dc9 SS |
3541 | if (sas_device_priv_data->ignore_delay_remove) { |
3542 | sdev_printk(KERN_INFO, sdev, | |
3543 | "%s skip device_block for SES handle(0x%04x)\n", | |
3544 | __func__, sas_device_priv_data->sas_target->handle); | |
3545 | continue; | |
3546 | } | |
df838f92 | 3547 | _scsih_internal_device_block(sdev, sas_device_priv_data); |
f92363d1 | 3548 | } |
d1cb5e49 | 3549 | |
4318c734 SPS |
3550 | if (sas_device) |
3551 | sas_device_put(sas_device); | |
f92363d1 SR |
3552 | } |
3553 | ||
3554 | /** | |
3555 | * _scsih_block_io_to_children_attached_to_ex | |
3556 | * @ioc: per adapter object | |
3557 | * @sas_expander: the sas_device object | |
3558 | * | |
3559 | * This routine set sdev state to SDEV_BLOCK for all devices | |
3560 | * attached to this expander. This function called when expander is | |
3561 | * pulled. | |
3562 | */ | |
3563 | static void | |
3564 | _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc, | |
3565 | struct _sas_node *sas_expander) | |
3566 | { | |
3567 | struct _sas_port *mpt3sas_port; | |
3568 | struct _sas_device *sas_device; | |
3569 | struct _sas_node *expander_sibling; | |
3570 | unsigned long flags; | |
3571 | ||
3572 | if (!sas_expander) | |
3573 | return; | |
3574 | ||
3575 | list_for_each_entry(mpt3sas_port, | |
3576 | &sas_expander->sas_port_list, port_list) { | |
3577 | if (mpt3sas_port->remote_identify.device_type == | |
3578 | SAS_END_DEVICE) { | |
3579 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 SR |
3580 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
3581 | mpt3sas_port->remote_identify.sas_address); | |
3582 | if (sas_device) { | |
f92363d1 | 3583 | set_bit(sas_device->handle, |
d1cb5e49 SR |
3584 | ioc->blocking_handles); |
3585 | sas_device_put(sas_device); | |
3586 | } | |
f92363d1 SR |
3587 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
3588 | } | |
3589 | } | |
3590 | ||
3591 | list_for_each_entry(mpt3sas_port, | |
3592 | &sas_expander->sas_port_list, port_list) { | |
3593 | ||
3594 | if (mpt3sas_port->remote_identify.device_type == | |
3595 | SAS_EDGE_EXPANDER_DEVICE || | |
3596 | mpt3sas_port->remote_identify.device_type == | |
3597 | SAS_FANOUT_EXPANDER_DEVICE) { | |
3598 | expander_sibling = | |
3599 | mpt3sas_scsih_expander_find_by_sas_address( | |
3600 | ioc, mpt3sas_port->remote_identify.sas_address); | |
3601 | _scsih_block_io_to_children_attached_to_ex(ioc, | |
3602 | expander_sibling); | |
3603 | } | |
3604 | } | |
3605 | } | |
3606 | ||
3607 | /** | |
3608 | * _scsih_block_io_to_children_attached_directly | |
3609 | * @ioc: per adapter object | |
3610 | * @event_data: topology change event data | |
3611 | * | |
3612 | * This routine set sdev state to SDEV_BLOCK for all devices | |
3613 | * direct attached during device pull. | |
3614 | */ | |
3615 | static void | |
3616 | _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc, | |
3617 | Mpi2EventDataSasTopologyChangeList_t *event_data) | |
3618 | { | |
3619 | int i; | |
3620 | u16 handle; | |
3621 | u16 reason_code; | |
f92363d1 SR |
3622 | |
3623 | for (i = 0; i < event_data->NumEntries; i++) { | |
3624 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
3625 | if (!handle) | |
3626 | continue; | |
f92363d1 SR |
3627 | reason_code = event_data->PHY[i].PhyStatus & |
3628 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
3629 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING) | |
3630 | _scsih_block_io_device(ioc, handle); | |
3631 | } | |
3632 | } | |
3633 | ||
4318c734 SPS |
3634 | /** |
3635 | * _scsih_block_io_to_pcie_children_attached_directly | |
3636 | * @ioc: per adapter object | |
3637 | * @event_data: topology change event data | |
3638 | * | |
3639 | * This routine set sdev state to SDEV_BLOCK for all devices | |
3640 | * direct attached during device pull/reconnect. | |
3641 | */ | |
3642 | static void | |
3643 | _scsih_block_io_to_pcie_children_attached_directly(struct MPT3SAS_ADAPTER *ioc, | |
3644 | Mpi26EventDataPCIeTopologyChangeList_t *event_data) | |
3645 | { | |
3646 | int i; | |
3647 | u16 handle; | |
3648 | u16 reason_code; | |
3649 | ||
3650 | for (i = 0; i < event_data->NumEntries; i++) { | |
3651 | handle = | |
3652 | le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle); | |
3653 | if (!handle) | |
3654 | continue; | |
3655 | reason_code = event_data->PortEntry[i].PortStatus; | |
3656 | if (reason_code == | |
3657 | MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING) | |
3658 | _scsih_block_io_device(ioc, handle); | |
3659 | } | |
3660 | } | |
f92363d1 SR |
3661 | /** |
3662 | * _scsih_tm_tr_send - send task management request | |
3663 | * @ioc: per adapter object | |
3664 | * @handle: device handle | |
3665 | * Context: interrupt time. | |
3666 | * | |
3667 | * This code is to initiate the device removal handshake protocol | |
3668 | * with controller firmware. This function will issue target reset | |
3669 | * using high priority request queue. It will send a sas iounit | |
3670 | * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion. | |
3671 | * | |
3672 | * This is designed to send muliple task management request at the same | |
3673 | * time to the fifo. If the fifo is full, we will append the request, | |
3674 | * and process it in a future completion. | |
3675 | */ | |
3676 | static void | |
3677 | _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
3678 | { | |
3679 | Mpi2SCSITaskManagementRequest_t *mpi_request; | |
3680 | u16 smid; | |
d1cb5e49 | 3681 | struct _sas_device *sas_device = NULL; |
f92363d1 SR |
3682 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; |
3683 | u64 sas_address = 0; | |
3684 | unsigned long flags; | |
3685 | struct _tr_list *delayed_tr; | |
3686 | u32 ioc_state; | |
3687 | ||
3688 | if (ioc->remove_host) { | |
3689 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3690 | "%s: host has been removed: handle(0x%04x)\n", | |
3691 | __func__, ioc->name, handle)); | |
3692 | return; | |
3693 | } else if (ioc->pci_error_recovery) { | |
3694 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3695 | "%s: host in pci error recovery: handle(0x%04x)\n", | |
3696 | __func__, ioc->name, | |
3697 | handle)); | |
3698 | return; | |
3699 | } | |
3700 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); | |
3701 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | |
3702 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3703 | "%s: host is not operational: handle(0x%04x)\n", | |
3704 | __func__, ioc->name, | |
3705 | handle)); | |
3706 | return; | |
3707 | } | |
3708 | ||
3709 | /* if PD, then return */ | |
3710 | if (test_bit(handle, ioc->pd_handles)) | |
3711 | return; | |
3712 | ||
c696f7b8 SPS |
3713 | clear_bit(handle, ioc->pend_os_device_add); |
3714 | ||
f92363d1 | 3715 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 3716 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
3717 | if (sas_device && sas_device->starget && |
3718 | sas_device->starget->hostdata) { | |
3719 | sas_target_priv_data = sas_device->starget->hostdata; | |
3720 | sas_target_priv_data->deleted = 1; | |
3721 | sas_address = sas_device->sas_address; | |
3722 | } | |
3723 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
3724 | ||
3725 | if (sas_target_priv_data) { | |
3726 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3727 | "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n", | |
3728 | ioc->name, handle, | |
3729 | (unsigned long long)sas_address)); | |
75888956 SR |
3730 | dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, |
3731 | sas_device, NULL, NULL)); | |
f92363d1 SR |
3732 | _scsih_ublock_io_device(ioc, sas_address); |
3733 | sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE; | |
3734 | } | |
3735 | ||
3736 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx); | |
3737 | if (!smid) { | |
3738 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | |
3739 | if (!delayed_tr) | |
d1cb5e49 | 3740 | goto out; |
f92363d1 SR |
3741 | INIT_LIST_HEAD(&delayed_tr->list); |
3742 | delayed_tr->handle = handle; | |
3743 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); | |
3744 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3745 | "DELAYED:tr:handle(0x%04x), (open)\n", | |
3746 | ioc->name, handle)); | |
d1cb5e49 | 3747 | goto out; |
f92363d1 SR |
3748 | } |
3749 | ||
3750 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3751 | "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
3752 | ioc->name, handle, smid, | |
3753 | ioc->tm_tr_cb_idx)); | |
3754 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
3755 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | |
3756 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | |
3757 | mpi_request->DevHandle = cpu_to_le16(handle); | |
3758 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; | |
c696f7b8 | 3759 | set_bit(handle, ioc->device_remove_in_progress); |
81c16f83 | 3760 | ioc->put_smid_hi_priority(ioc, smid, 0); |
f92363d1 | 3761 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL); |
d1cb5e49 SR |
3762 | |
3763 | out: | |
3764 | if (sas_device) | |
3765 | sas_device_put(sas_device); | |
f92363d1 SR |
3766 | } |
3767 | ||
3768 | /** | |
3769 | * _scsih_tm_tr_complete - | |
3770 | * @ioc: per adapter object | |
3771 | * @smid: system request message index | |
3772 | * @msix_index: MSIX table index supplied by the OS | |
3773 | * @reply: reply message frame(lower 32bit addr) | |
3774 | * Context: interrupt time. | |
3775 | * | |
3776 | * This is the target reset completion routine. | |
3777 | * This code is part of the code to initiate the device removal | |
3778 | * handshake protocol with controller firmware. | |
3779 | * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE) | |
3780 | * | |
3781 | * Return 1 meaning mf should be freed from _base_interrupt | |
3782 | * 0 means the mf is freed from this function. | |
3783 | */ | |
3784 | static u8 | |
3785 | _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, | |
3786 | u32 reply) | |
3787 | { | |
3788 | u16 handle; | |
3789 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; | |
3790 | Mpi2SCSITaskManagementReply_t *mpi_reply = | |
3791 | mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
3792 | Mpi2SasIoUnitControlRequest_t *mpi_request; | |
3793 | u16 smid_sas_ctrl; | |
3794 | u32 ioc_state; | |
fd0331b3 | 3795 | struct _sc_list *delayed_sc; |
f92363d1 SR |
3796 | |
3797 | if (ioc->remove_host) { | |
3798 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3799 | "%s: host has been removed\n", __func__, ioc->name)); | |
3800 | return 1; | |
3801 | } else if (ioc->pci_error_recovery) { | |
3802 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3803 | "%s: host in pci error recovery\n", __func__, | |
3804 | ioc->name)); | |
3805 | return 1; | |
3806 | } | |
3807 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); | |
3808 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | |
3809 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3810 | "%s: host is not operational\n", __func__, ioc->name)); | |
3811 | return 1; | |
3812 | } | |
3813 | if (unlikely(!mpi_reply)) { | |
3814 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", | |
3815 | ioc->name, __FILE__, __LINE__, __func__); | |
3816 | return 1; | |
3817 | } | |
3818 | mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid); | |
3819 | handle = le16_to_cpu(mpi_request_tm->DevHandle); | |
3820 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { | |
3821 | dewtprintk(ioc, pr_err(MPT3SAS_FMT | |
3822 | "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n", | |
3823 | ioc->name, handle, | |
3824 | le16_to_cpu(mpi_reply->DevHandle), smid)); | |
3825 | return 0; | |
3826 | } | |
3827 | ||
3828 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT); | |
3829 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3830 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " | |
3831 | "loginfo(0x%08x), completed(%d)\n", ioc->name, | |
3832 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), | |
3833 | le32_to_cpu(mpi_reply->IOCLogInfo), | |
3834 | le32_to_cpu(mpi_reply->TerminationCount))); | |
3835 | ||
3836 | smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx); | |
3837 | if (!smid_sas_ctrl) { | |
fd0331b3 SS |
3838 | delayed_sc = kzalloc(sizeof(*delayed_sc), GFP_ATOMIC); |
3839 | if (!delayed_sc) | |
3840 | return _scsih_check_for_pending_tm(ioc, smid); | |
3841 | INIT_LIST_HEAD(&delayed_sc->list); | |
3842 | delayed_sc->handle = mpi_request_tm->DevHandle; | |
3843 | list_add_tail(&delayed_sc->list, &ioc->delayed_sc_list); | |
3844 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3845 | "DELAYED:sc:handle(0x%04x), (open)\n", | |
3846 | ioc->name, handle)); | |
3847 | return _scsih_check_for_pending_tm(ioc, smid); | |
f92363d1 SR |
3848 | } |
3849 | ||
3850 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3851 | "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
3852 | ioc->name, handle, smid_sas_ctrl, | |
3853 | ioc->tm_sas_control_cb_idx)); | |
3854 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl); | |
3855 | memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t)); | |
3856 | mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; | |
3857 | mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE; | |
3858 | mpi_request->DevHandle = mpi_request_tm->DevHandle; | |
81c16f83 | 3859 | ioc->put_smid_default(ioc, smid_sas_ctrl); |
f92363d1 SR |
3860 | |
3861 | return _scsih_check_for_pending_tm(ioc, smid); | |
3862 | } | |
3863 | ||
3864 | ||
3865 | /** | |
3866 | * _scsih_sas_control_complete - completion routine | |
3867 | * @ioc: per adapter object | |
3868 | * @smid: system request message index | |
3869 | * @msix_index: MSIX table index supplied by the OS | |
3870 | * @reply: reply message frame(lower 32bit addr) | |
3871 | * Context: interrupt time. | |
3872 | * | |
3873 | * This is the sas iounit control completion routine. | |
3874 | * This code is part of the code to initiate the device removal | |
3875 | * handshake protocol with controller firmware. | |
3876 | * | |
3877 | * Return 1 meaning mf should be freed from _base_interrupt | |
3878 | * 0 means the mf is freed from this function. | |
3879 | */ | |
3880 | static u8 | |
3881 | _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, | |
3882 | u8 msix_index, u32 reply) | |
3883 | { | |
3884 | Mpi2SasIoUnitControlReply_t *mpi_reply = | |
3885 | mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
3886 | ||
3887 | if (likely(mpi_reply)) { | |
3888 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3889 | "sc_complete:handle(0x%04x), (open) " | |
3890 | "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n", | |
3891 | ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid, | |
3892 | le16_to_cpu(mpi_reply->IOCStatus), | |
3893 | le32_to_cpu(mpi_reply->IOCLogInfo))); | |
c696f7b8 SPS |
3894 | if (le16_to_cpu(mpi_reply->IOCStatus) == |
3895 | MPI2_IOCSTATUS_SUCCESS) { | |
3896 | clear_bit(le16_to_cpu(mpi_reply->DevHandle), | |
3897 | ioc->device_remove_in_progress); | |
3898 | } | |
f92363d1 SR |
3899 | } else { |
3900 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", | |
3901 | ioc->name, __FILE__, __LINE__, __func__); | |
3902 | } | |
fd0331b3 | 3903 | return mpt3sas_check_for_pending_internal_cmds(ioc, smid); |
f92363d1 SR |
3904 | } |
3905 | ||
3906 | /** | |
3907 | * _scsih_tm_tr_volume_send - send target reset request for volumes | |
3908 | * @ioc: per adapter object | |
3909 | * @handle: device handle | |
3910 | * Context: interrupt time. | |
3911 | * | |
3912 | * This is designed to send muliple task management request at the same | |
3913 | * time to the fifo. If the fifo is full, we will append the request, | |
3914 | * and process it in a future completion. | |
3915 | */ | |
3916 | static void | |
3917 | _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
3918 | { | |
3919 | Mpi2SCSITaskManagementRequest_t *mpi_request; | |
3920 | u16 smid; | |
3921 | struct _tr_list *delayed_tr; | |
3922 | ||
3923 | if (ioc->shost_recovery || ioc->remove_host || | |
3924 | ioc->pci_error_recovery) { | |
3925 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3926 | "%s: host reset in progress!\n", | |
3927 | __func__, ioc->name)); | |
3928 | return; | |
3929 | } | |
3930 | ||
3931 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx); | |
3932 | if (!smid) { | |
3933 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | |
3934 | if (!delayed_tr) | |
3935 | return; | |
3936 | INIT_LIST_HEAD(&delayed_tr->list); | |
3937 | delayed_tr->handle = handle; | |
3938 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list); | |
3939 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3940 | "DELAYED:tr:handle(0x%04x), (open)\n", | |
3941 | ioc->name, handle)); | |
3942 | return; | |
3943 | } | |
3944 | ||
3945 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3946 | "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
3947 | ioc->name, handle, smid, | |
3948 | ioc->tm_tr_volume_cb_idx)); | |
3949 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
3950 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | |
3951 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | |
3952 | mpi_request->DevHandle = cpu_to_le16(handle); | |
3953 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; | |
81c16f83 | 3954 | ioc->put_smid_hi_priority(ioc, smid, 0); |
f92363d1 SR |
3955 | } |
3956 | ||
3957 | /** | |
3958 | * _scsih_tm_volume_tr_complete - target reset completion | |
3959 | * @ioc: per adapter object | |
3960 | * @smid: system request message index | |
3961 | * @msix_index: MSIX table index supplied by the OS | |
3962 | * @reply: reply message frame(lower 32bit addr) | |
3963 | * Context: interrupt time. | |
3964 | * | |
3965 | * Return 1 meaning mf should be freed from _base_interrupt | |
3966 | * 0 means the mf is freed from this function. | |
3967 | */ | |
3968 | static u8 | |
3969 | _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, | |
3970 | u8 msix_index, u32 reply) | |
3971 | { | |
3972 | u16 handle; | |
3973 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; | |
3974 | Mpi2SCSITaskManagementReply_t *mpi_reply = | |
3975 | mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
3976 | ||
3977 | if (ioc->shost_recovery || ioc->remove_host || | |
3978 | ioc->pci_error_recovery) { | |
3979 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3980 | "%s: host reset in progress!\n", | |
3981 | __func__, ioc->name)); | |
3982 | return 1; | |
3983 | } | |
3984 | if (unlikely(!mpi_reply)) { | |
3985 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", | |
3986 | ioc->name, __FILE__, __LINE__, __func__); | |
3987 | return 1; | |
3988 | } | |
3989 | ||
3990 | mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid); | |
3991 | handle = le16_to_cpu(mpi_request_tm->DevHandle); | |
3992 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { | |
3993 | dewtprintk(ioc, pr_err(MPT3SAS_FMT | |
3994 | "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n", | |
3995 | ioc->name, handle, | |
3996 | le16_to_cpu(mpi_reply->DevHandle), smid)); | |
3997 | return 0; | |
3998 | } | |
3999 | ||
4000 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4001 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " | |
4002 | "loginfo(0x%08x), completed(%d)\n", ioc->name, | |
4003 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), | |
4004 | le32_to_cpu(mpi_reply->IOCLogInfo), | |
4005 | le32_to_cpu(mpi_reply->TerminationCount))); | |
4006 | ||
4007 | return _scsih_check_for_pending_tm(ioc, smid); | |
4008 | } | |
4009 | ||
fd0331b3 SS |
4010 | /** |
4011 | * _scsih_issue_delayed_event_ack - issue delayed Event ACK messages | |
4012 | * @ioc: per adapter object | |
4013 | * @smid: system request message index | |
4014 | * @event: Event ID | |
4015 | * @event_context: used to track events uniquely | |
4016 | * | |
4017 | * Context - processed in interrupt context. | |
4018 | */ | |
8bbb1cf6 | 4019 | static void |
fd0331b3 SS |
4020 | _scsih_issue_delayed_event_ack(struct MPT3SAS_ADAPTER *ioc, u16 smid, u16 event, |
4021 | u32 event_context) | |
4022 | { | |
4023 | Mpi2EventAckRequest_t *ack_request; | |
4024 | int i = smid - ioc->internal_smid; | |
4025 | unsigned long flags; | |
4026 | ||
4027 | /* Without releasing the smid just update the | |
4028 | * call back index and reuse the same smid for | |
4029 | * processing this delayed request | |
4030 | */ | |
4031 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
4032 | ioc->internal_lookup[i].cb_idx = ioc->base_cb_idx; | |
4033 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
4034 | ||
4035 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4036 | "EVENT ACK: event(0x%04x), smid(%d), cb(%d)\n", | |
4037 | ioc->name, le16_to_cpu(event), smid, | |
4038 | ioc->base_cb_idx)); | |
4039 | ack_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
4040 | memset(ack_request, 0, sizeof(Mpi2EventAckRequest_t)); | |
4041 | ack_request->Function = MPI2_FUNCTION_EVENT_ACK; | |
4042 | ack_request->Event = event; | |
4043 | ack_request->EventContext = event_context; | |
4044 | ack_request->VF_ID = 0; /* TODO */ | |
4045 | ack_request->VP_ID = 0; | |
81c16f83 | 4046 | ioc->put_smid_default(ioc, smid); |
fd0331b3 SS |
4047 | } |
4048 | ||
4049 | /** | |
4050 | * _scsih_issue_delayed_sas_io_unit_ctrl - issue delayed | |
4051 | * sas_io_unit_ctrl messages | |
4052 | * @ioc: per adapter object | |
4053 | * @smid: system request message index | |
4054 | * @handle: device handle | |
4055 | * | |
4056 | * Context - processed in interrupt context. | |
4057 | */ | |
8bbb1cf6 | 4058 | static void |
fd0331b3 SS |
4059 | _scsih_issue_delayed_sas_io_unit_ctrl(struct MPT3SAS_ADAPTER *ioc, |
4060 | u16 smid, u16 handle) | |
4061 | { | |
4062 | Mpi2SasIoUnitControlRequest_t *mpi_request; | |
4063 | u32 ioc_state; | |
4064 | int i = smid - ioc->internal_smid; | |
4065 | unsigned long flags; | |
4066 | ||
4067 | if (ioc->remove_host) { | |
4068 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4069 | "%s: host has been removed\n", | |
4070 | __func__, ioc->name)); | |
4071 | return; | |
4072 | } else if (ioc->pci_error_recovery) { | |
4073 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4074 | "%s: host in pci error recovery\n", | |
4075 | __func__, ioc->name)); | |
4076 | return; | |
4077 | } | |
4078 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); | |
4079 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | |
4080 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4081 | "%s: host is not operational\n", | |
4082 | __func__, ioc->name)); | |
4083 | return; | |
4084 | } | |
4085 | ||
4086 | /* Without releasing the smid just update the | |
4087 | * call back index and reuse the same smid for | |
4088 | * processing this delayed request | |
4089 | */ | |
4090 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
4091 | ioc->internal_lookup[i].cb_idx = ioc->tm_sas_control_cb_idx; | |
4092 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
4093 | ||
4094 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4095 | "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
4096 | ioc->name, le16_to_cpu(handle), smid, | |
4097 | ioc->tm_sas_control_cb_idx)); | |
4098 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
4099 | memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t)); | |
4100 | mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; | |
4101 | mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE; | |
4102 | mpi_request->DevHandle = handle; | |
81c16f83 | 4103 | ioc->put_smid_default(ioc, smid); |
fd0331b3 SS |
4104 | } |
4105 | ||
4106 | /** | |
4107 | * _scsih_check_for_pending_internal_cmds - check for pending internal messages | |
4108 | * @ioc: per adapter object | |
4109 | * @smid: system request message index | |
4110 | * | |
4111 | * Context: Executed in interrupt context | |
4112 | * | |
4113 | * This will check delayed internal messages list, and process the | |
4114 | * next request. | |
4115 | * | |
4116 | * Return 1 meaning mf should be freed from _base_interrupt | |
4117 | * 0 means the mf is freed from this function. | |
4118 | */ | |
4119 | u8 | |
4120 | mpt3sas_check_for_pending_internal_cmds(struct MPT3SAS_ADAPTER *ioc, u16 smid) | |
4121 | { | |
4122 | struct _sc_list *delayed_sc; | |
4123 | struct _event_ack_list *delayed_event_ack; | |
4124 | ||
4125 | if (!list_empty(&ioc->delayed_event_ack_list)) { | |
4126 | delayed_event_ack = list_entry(ioc->delayed_event_ack_list.next, | |
4127 | struct _event_ack_list, list); | |
4128 | _scsih_issue_delayed_event_ack(ioc, smid, | |
4129 | delayed_event_ack->Event, delayed_event_ack->EventContext); | |
4130 | list_del(&delayed_event_ack->list); | |
4131 | kfree(delayed_event_ack); | |
4132 | return 0; | |
4133 | } | |
4134 | ||
4135 | if (!list_empty(&ioc->delayed_sc_list)) { | |
4136 | delayed_sc = list_entry(ioc->delayed_sc_list.next, | |
4137 | struct _sc_list, list); | |
4138 | _scsih_issue_delayed_sas_io_unit_ctrl(ioc, smid, | |
4139 | delayed_sc->handle); | |
4140 | list_del(&delayed_sc->list); | |
4141 | kfree(delayed_sc); | |
4142 | return 0; | |
4143 | } | |
4144 | return 1; | |
4145 | } | |
f92363d1 SR |
4146 | |
4147 | /** | |
4148 | * _scsih_check_for_pending_tm - check for pending task management | |
4149 | * @ioc: per adapter object | |
4150 | * @smid: system request message index | |
4151 | * | |
4152 | * This will check delayed target reset list, and feed the | |
4153 | * next reqeust. | |
4154 | * | |
4155 | * Return 1 meaning mf should be freed from _base_interrupt | |
4156 | * 0 means the mf is freed from this function. | |
4157 | */ | |
4158 | static u8 | |
4159 | _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid) | |
4160 | { | |
4161 | struct _tr_list *delayed_tr; | |
4162 | ||
4163 | if (!list_empty(&ioc->delayed_tr_volume_list)) { | |
4164 | delayed_tr = list_entry(ioc->delayed_tr_volume_list.next, | |
4165 | struct _tr_list, list); | |
4166 | mpt3sas_base_free_smid(ioc, smid); | |
4167 | _scsih_tm_tr_volume_send(ioc, delayed_tr->handle); | |
4168 | list_del(&delayed_tr->list); | |
4169 | kfree(delayed_tr); | |
4170 | return 0; | |
4171 | } | |
4172 | ||
4173 | if (!list_empty(&ioc->delayed_tr_list)) { | |
4174 | delayed_tr = list_entry(ioc->delayed_tr_list.next, | |
4175 | struct _tr_list, list); | |
4176 | mpt3sas_base_free_smid(ioc, smid); | |
4177 | _scsih_tm_tr_send(ioc, delayed_tr->handle); | |
4178 | list_del(&delayed_tr->list); | |
4179 | kfree(delayed_tr); | |
4180 | return 0; | |
4181 | } | |
4182 | ||
4183 | return 1; | |
4184 | } | |
4185 | ||
4186 | /** | |
4187 | * _scsih_check_topo_delete_events - sanity check on topo events | |
4188 | * @ioc: per adapter object | |
4189 | * @event_data: the event data payload | |
4190 | * | |
4191 | * This routine added to better handle cable breaker. | |
4192 | * | |
4193 | * This handles the case where driver receives multiple expander | |
4194 | * add and delete events in a single shot. When there is a delete event | |
4195 | * the routine will void any pending add events waiting in the event queue. | |
4196 | * | |
4197 | * Return nothing. | |
4198 | */ | |
4199 | static void | |
4200 | _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc, | |
4201 | Mpi2EventDataSasTopologyChangeList_t *event_data) | |
4202 | { | |
4203 | struct fw_event_work *fw_event; | |
4204 | Mpi2EventDataSasTopologyChangeList_t *local_event_data; | |
4205 | u16 expander_handle; | |
4206 | struct _sas_node *sas_expander; | |
4207 | unsigned long flags; | |
4208 | int i, reason_code; | |
4209 | u16 handle; | |
4210 | ||
4211 | for (i = 0 ; i < event_data->NumEntries; i++) { | |
4212 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
4213 | if (!handle) | |
4214 | continue; | |
4215 | reason_code = event_data->PHY[i].PhyStatus & | |
4216 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
4217 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING) | |
4218 | _scsih_tm_tr_send(ioc, handle); | |
4219 | } | |
4220 | ||
4221 | expander_handle = le16_to_cpu(event_data->ExpanderDevHandle); | |
4222 | if (expander_handle < ioc->sas_hba.num_phys) { | |
4223 | _scsih_block_io_to_children_attached_directly(ioc, event_data); | |
4224 | return; | |
4225 | } | |
4226 | if (event_data->ExpStatus == | |
4227 | MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) { | |
4228 | /* put expander attached devices into blocking state */ | |
4229 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
4230 | sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc, | |
4231 | expander_handle); | |
4232 | _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander); | |
4233 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
4234 | do { | |
4235 | handle = find_first_bit(ioc->blocking_handles, | |
4236 | ioc->facts.MaxDevHandle); | |
4237 | if (handle < ioc->facts.MaxDevHandle) | |
4238 | _scsih_block_io_device(ioc, handle); | |
4239 | } while (test_and_clear_bit(handle, ioc->blocking_handles)); | |
4240 | } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING) | |
4241 | _scsih_block_io_to_children_attached_directly(ioc, event_data); | |
4242 | ||
4243 | if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) | |
4244 | return; | |
4245 | ||
4246 | /* mark ignore flag for pending events */ | |
4247 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
4248 | list_for_each_entry(fw_event, &ioc->fw_event_list, list) { | |
4249 | if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST || | |
4250 | fw_event->ignore) | |
4251 | continue; | |
35b62362 JL |
4252 | local_event_data = (Mpi2EventDataSasTopologyChangeList_t *) |
4253 | fw_event->event_data; | |
f92363d1 SR |
4254 | if (local_event_data->ExpStatus == |
4255 | MPI2_EVENT_SAS_TOPO_ES_ADDED || | |
4256 | local_event_data->ExpStatus == | |
4257 | MPI2_EVENT_SAS_TOPO_ES_RESPONDING) { | |
4258 | if (le16_to_cpu(local_event_data->ExpanderDevHandle) == | |
4259 | expander_handle) { | |
4260 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4261 | "setting ignoring flag\n", ioc->name)); | |
4262 | fw_event->ignore = 1; | |
4263 | } | |
4264 | } | |
4265 | } | |
4266 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
4267 | } | |
4268 | ||
4318c734 SPS |
4269 | /** |
4270 | * _scsih_check_pcie_topo_remove_events - sanity check on topo | |
4271 | * events | |
4272 | * @ioc: per adapter object | |
4273 | * @event_data: the event data payload | |
4274 | * | |
4275 | * This handles the case where driver receives multiple switch | |
4276 | * or device add and delete events in a single shot. When there | |
4277 | * is a delete event the routine will void any pending add | |
4278 | * events waiting in the event queue. | |
4279 | * | |
4280 | * Return nothing. | |
4281 | */ | |
4282 | static void | |
4283 | _scsih_check_pcie_topo_remove_events(struct MPT3SAS_ADAPTER *ioc, | |
4284 | Mpi26EventDataPCIeTopologyChangeList_t *event_data) | |
4285 | { | |
4286 | struct fw_event_work *fw_event; | |
4287 | Mpi26EventDataPCIeTopologyChangeList_t *local_event_data; | |
4288 | unsigned long flags; | |
4289 | int i, reason_code; | |
4290 | u16 handle, switch_handle; | |
4291 | ||
4292 | for (i = 0; i < event_data->NumEntries; i++) { | |
4293 | handle = | |
4294 | le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle); | |
4295 | if (!handle) | |
4296 | continue; | |
4297 | reason_code = event_data->PortEntry[i].PortStatus; | |
4298 | if (reason_code == MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING) | |
4299 | _scsih_tm_tr_send(ioc, handle); | |
4300 | } | |
4301 | ||
4302 | switch_handle = le16_to_cpu(event_data->SwitchDevHandle); | |
4303 | if (!switch_handle) { | |
4304 | _scsih_block_io_to_pcie_children_attached_directly( | |
4305 | ioc, event_data); | |
4306 | return; | |
4307 | } | |
4308 | /* TODO We are not supporting cascaded PCIe Switch removal yet*/ | |
4309 | if ((event_data->SwitchStatus | |
4310 | == MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING) || | |
4311 | (event_data->SwitchStatus == | |
4312 | MPI26_EVENT_PCIE_TOPO_SS_RESPONDING)) | |
4313 | _scsih_block_io_to_pcie_children_attached_directly( | |
4314 | ioc, event_data); | |
4315 | ||
4316 | if (event_data->SwitchStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) | |
4317 | return; | |
4318 | ||
4319 | /* mark ignore flag for pending events */ | |
4320 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
4321 | list_for_each_entry(fw_event, &ioc->fw_event_list, list) { | |
4322 | if (fw_event->event != MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST || | |
4323 | fw_event->ignore) | |
4324 | continue; | |
4325 | local_event_data = | |
4326 | (Mpi26EventDataPCIeTopologyChangeList_t *) | |
4327 | fw_event->event_data; | |
4328 | if (local_event_data->SwitchStatus == | |
4329 | MPI2_EVENT_SAS_TOPO_ES_ADDED || | |
4330 | local_event_data->SwitchStatus == | |
4331 | MPI2_EVENT_SAS_TOPO_ES_RESPONDING) { | |
4332 | if (le16_to_cpu(local_event_data->SwitchDevHandle) == | |
4333 | switch_handle) { | |
4334 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4335 | "setting ignoring flag for switch event\n", | |
4336 | ioc->name)); | |
4337 | fw_event->ignore = 1; | |
4338 | } | |
4339 | } | |
4340 | } | |
4341 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
4342 | } | |
4343 | ||
f92363d1 SR |
4344 | /** |
4345 | * _scsih_set_volume_delete_flag - setting volume delete flag | |
4346 | * @ioc: per adapter object | |
4347 | * @handle: device handle | |
4348 | * | |
4349 | * This returns nothing. | |
4350 | */ | |
4351 | static void | |
4352 | _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
4353 | { | |
4354 | struct _raid_device *raid_device; | |
4355 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
4356 | unsigned long flags; | |
4357 | ||
4358 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
c84b06a4 | 4359 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
4360 | if (raid_device && raid_device->starget && |
4361 | raid_device->starget->hostdata) { | |
4362 | sas_target_priv_data = | |
4363 | raid_device->starget->hostdata; | |
4364 | sas_target_priv_data->deleted = 1; | |
4365 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4366 | "setting delete flag: handle(0x%04x), " | |
4367 | "wwid(0x%016llx)\n", ioc->name, handle, | |
4368 | (unsigned long long) raid_device->wwid)); | |
4369 | } | |
4370 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
4371 | } | |
4372 | ||
4373 | /** | |
4374 | * _scsih_set_volume_handle_for_tr - set handle for target reset to volume | |
4375 | * @handle: input handle | |
4376 | * @a: handle for volume a | |
4377 | * @b: handle for volume b | |
4378 | * | |
4379 | * IR firmware only supports two raid volumes. The purpose of this | |
4380 | * routine is to set the volume handle in either a or b. When the given | |
4381 | * input handle is non-zero, or when a and b have not been set before. | |
4382 | */ | |
4383 | static void | |
4384 | _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b) | |
4385 | { | |
4386 | if (!handle || handle == *a || handle == *b) | |
4387 | return; | |
4388 | if (!*a) | |
4389 | *a = handle; | |
4390 | else if (!*b) | |
4391 | *b = handle; | |
4392 | } | |
4393 | ||
4394 | /** | |
4395 | * _scsih_check_ir_config_unhide_events - check for UNHIDE events | |
4396 | * @ioc: per adapter object | |
4397 | * @event_data: the event data payload | |
4398 | * Context: interrupt time. | |
4399 | * | |
4400 | * This routine will send target reset to volume, followed by target | |
4401 | * resets to the PDs. This is called when a PD has been removed, or | |
4402 | * volume has been deleted or removed. When the target reset is sent | |
4403 | * to volume, the PD target resets need to be queued to start upon | |
4404 | * completion of the volume target reset. | |
4405 | * | |
4406 | * Return nothing. | |
4407 | */ | |
4408 | static void | |
4409 | _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc, | |
4410 | Mpi2EventDataIrConfigChangeList_t *event_data) | |
4411 | { | |
4412 | Mpi2EventIrConfigElement_t *element; | |
4413 | int i; | |
4414 | u16 handle, volume_handle, a, b; | |
4415 | struct _tr_list *delayed_tr; | |
4416 | ||
4417 | a = 0; | |
4418 | b = 0; | |
4419 | ||
7786ab6a SR |
4420 | if (ioc->is_warpdrive) |
4421 | return; | |
4422 | ||
f92363d1 SR |
4423 | /* Volume Resets for Deleted or Removed */ |
4424 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
4425 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
4426 | if (le32_to_cpu(event_data->Flags) & | |
4427 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) | |
4428 | continue; | |
4429 | if (element->ReasonCode == | |
4430 | MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED || | |
4431 | element->ReasonCode == | |
4432 | MPI2_EVENT_IR_CHANGE_RC_REMOVED) { | |
4433 | volume_handle = le16_to_cpu(element->VolDevHandle); | |
4434 | _scsih_set_volume_delete_flag(ioc, volume_handle); | |
4435 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); | |
4436 | } | |
4437 | } | |
4438 | ||
4439 | /* Volume Resets for UNHIDE events */ | |
4440 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
4441 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
4442 | if (le32_to_cpu(event_data->Flags) & | |
4443 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) | |
4444 | continue; | |
4445 | if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) { | |
4446 | volume_handle = le16_to_cpu(element->VolDevHandle); | |
4447 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); | |
4448 | } | |
4449 | } | |
4450 | ||
4451 | if (a) | |
4452 | _scsih_tm_tr_volume_send(ioc, a); | |
4453 | if (b) | |
4454 | _scsih_tm_tr_volume_send(ioc, b); | |
4455 | ||
4456 | /* PD target resets */ | |
4457 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
4458 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
4459 | if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE) | |
4460 | continue; | |
4461 | handle = le16_to_cpu(element->PhysDiskDevHandle); | |
4462 | volume_handle = le16_to_cpu(element->VolDevHandle); | |
4463 | clear_bit(handle, ioc->pd_handles); | |
4464 | if (!volume_handle) | |
4465 | _scsih_tm_tr_send(ioc, handle); | |
4466 | else if (volume_handle == a || volume_handle == b) { | |
4467 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | |
4468 | BUG_ON(!delayed_tr); | |
4469 | INIT_LIST_HEAD(&delayed_tr->list); | |
4470 | delayed_tr->handle = handle; | |
4471 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); | |
4472 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4473 | "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name, | |
4474 | handle)); | |
4475 | } else | |
4476 | _scsih_tm_tr_send(ioc, handle); | |
4477 | } | |
4478 | } | |
4479 | ||
4480 | ||
4481 | /** | |
4482 | * _scsih_check_volume_delete_events - set delete flag for volumes | |
4483 | * @ioc: per adapter object | |
4484 | * @event_data: the event data payload | |
4485 | * Context: interrupt time. | |
4486 | * | |
4487 | * This will handle the case when the cable connected to entire volume is | |
4488 | * pulled. We will take care of setting the deleted flag so normal IO will | |
4489 | * not be sent. | |
4490 | * | |
4491 | * Return nothing. | |
4492 | */ | |
4493 | static void | |
4494 | _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc, | |
4495 | Mpi2EventDataIrVolume_t *event_data) | |
4496 | { | |
4497 | u32 state; | |
4498 | ||
4499 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) | |
4500 | return; | |
4501 | state = le32_to_cpu(event_data->NewValue); | |
4502 | if (state == MPI2_RAID_VOL_STATE_MISSING || state == | |
4503 | MPI2_RAID_VOL_STATE_FAILED) | |
4504 | _scsih_set_volume_delete_flag(ioc, | |
4505 | le16_to_cpu(event_data->VolDevHandle)); | |
4506 | } | |
4507 | ||
2d8ce8c9 SR |
4508 | /** |
4509 | * _scsih_temp_threshold_events - display temperature threshold exceeded events | |
4510 | * @ioc: per adapter object | |
4511 | * @event_data: the temp threshold event data | |
4512 | * Context: interrupt time. | |
4513 | * | |
4514 | * Return nothing. | |
4515 | */ | |
4516 | static void | |
4517 | _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER *ioc, | |
4518 | Mpi2EventDataTemperature_t *event_data) | |
4519 | { | |
4520 | if (ioc->temp_sensors_count >= event_data->SensorNum) { | |
4521 | pr_err(MPT3SAS_FMT "Temperature Threshold flags %s%s%s%s" | |
4522 | " exceeded for Sensor: %d !!!\n", ioc->name, | |
4523 | ((le16_to_cpu(event_data->Status) & 0x1) == 1) ? "0 " : " ", | |
4524 | ((le16_to_cpu(event_data->Status) & 0x2) == 2) ? "1 " : " ", | |
4525 | ((le16_to_cpu(event_data->Status) & 0x4) == 4) ? "2 " : " ", | |
4526 | ((le16_to_cpu(event_data->Status) & 0x8) == 8) ? "3 " : " ", | |
4527 | event_data->SensorNum); | |
4528 | pr_err(MPT3SAS_FMT "Current Temp In Celsius: %d\n", | |
4529 | ioc->name, event_data->CurrentTemperature); | |
4530 | } | |
4531 | } | |
4532 | ||
ffb58456 | 4533 | static int _scsih_set_satl_pending(struct scsi_cmnd *scmd, bool pending) |
7ff723ad | 4534 | { |
ffb58456 JB |
4535 | struct MPT3SAS_DEVICE *priv = scmd->device->hostdata; |
4536 | ||
4537 | if (scmd->cmnd[0] != ATA_12 && scmd->cmnd[0] != ATA_16) | |
4538 | return 0; | |
4539 | ||
4540 | if (pending) | |
4541 | return test_and_set_bit(0, &priv->ata_command_pending); | |
4542 | ||
4543 | clear_bit(0, &priv->ata_command_pending); | |
4544 | return 0; | |
7ff723ad SP |
4545 | } |
4546 | ||
f92363d1 SR |
4547 | /** |
4548 | * _scsih_flush_running_cmds - completing outstanding commands. | |
4549 | * @ioc: per adapter object | |
4550 | * | |
4551 | * The flushing out of all pending scmd commands following host reset, | |
4552 | * where all IO is dropped to the floor. | |
4553 | * | |
4554 | * Return nothing. | |
4555 | */ | |
4556 | static void | |
4557 | _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc) | |
4558 | { | |
4559 | struct scsi_cmnd *scmd; | |
4560 | u16 smid; | |
4561 | u16 count = 0; | |
4562 | ||
4563 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { | |
4564 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); | |
4565 | if (!scmd) | |
4566 | continue; | |
4567 | count++; | |
ffb58456 | 4568 | _scsih_set_satl_pending(scmd, false); |
f92363d1 SR |
4569 | mpt3sas_base_free_smid(ioc, smid); |
4570 | scsi_dma_unmap(scmd); | |
4571 | if (ioc->pci_error_recovery) | |
4572 | scmd->result = DID_NO_CONNECT << 16; | |
4573 | else | |
4574 | scmd->result = DID_RESET << 16; | |
4575 | scmd->scsi_done(scmd); | |
4576 | } | |
4577 | dtmprintk(ioc, pr_info(MPT3SAS_FMT "completing %d cmds\n", | |
4578 | ioc->name, count)); | |
4579 | } | |
4580 | ||
4581 | /** | |
4582 | * _scsih_setup_eedp - setup MPI request for EEDP transfer | |
4583 | * @ioc: per adapter object | |
4584 | * @scmd: pointer to scsi command object | |
6c7abffc | 4585 | * @mpi_request: pointer to the SCSI_IO request message frame |
f92363d1 SR |
4586 | * |
4587 | * Supporting protection 1 and 3. | |
4588 | * | |
4589 | * Returns nothing | |
4590 | */ | |
4591 | static void | |
4592 | _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, | |
016d5c35 | 4593 | Mpi25SCSIIORequest_t *mpi_request) |
f92363d1 SR |
4594 | { |
4595 | u16 eedp_flags; | |
4596 | unsigned char prot_op = scsi_get_prot_op(scmd); | |
4597 | unsigned char prot_type = scsi_get_prot_type(scmd); | |
4598 | Mpi25SCSIIORequest_t *mpi_request_3v = | |
4599 | (Mpi25SCSIIORequest_t *)mpi_request; | |
4600 | ||
4601 | if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL) | |
4602 | return; | |
4603 | ||
4604 | if (prot_op == SCSI_PROT_READ_STRIP) | |
4605 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP; | |
4606 | else if (prot_op == SCSI_PROT_WRITE_INSERT) | |
4607 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP; | |
4608 | else | |
4609 | return; | |
4610 | ||
4611 | switch (prot_type) { | |
4612 | case SCSI_PROT_DIF_TYPE1: | |
4613 | case SCSI_PROT_DIF_TYPE2: | |
4614 | ||
4615 | /* | |
4616 | * enable ref/guard checking | |
4617 | * auto increment ref tag | |
4618 | */ | |
4619 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG | | |
4620 | MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG | | |
4621 | MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; | |
4622 | mpi_request->CDB.EEDP32.PrimaryReferenceTag = | |
648512cc | 4623 | cpu_to_be32(scsi_prot_ref_tag(scmd)); |
f92363d1 SR |
4624 | break; |
4625 | ||
4626 | case SCSI_PROT_DIF_TYPE3: | |
4627 | ||
4628 | /* | |
4629 | * enable guard checking | |
4630 | */ | |
4631 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; | |
4632 | ||
4633 | break; | |
4634 | } | |
4635 | ||
4636 | mpi_request_3v->EEDPBlockSize = | |
4637 | cpu_to_le16(scmd->device->sector_size); | |
186a18e5 SPS |
4638 | |
4639 | if (ioc->is_gen35_ioc) | |
4640 | eedp_flags |= MPI25_SCSIIO_EEDPFLAGS_APPTAG_DISABLE_MODE; | |
f92363d1 SR |
4641 | mpi_request->EEDPFlags = cpu_to_le16(eedp_flags); |
4642 | } | |
4643 | ||
4644 | /** | |
4645 | * _scsih_eedp_error_handling - return sense code for EEDP errors | |
4646 | * @scmd: pointer to scsi command object | |
4647 | * @ioc_status: ioc status | |
4648 | * | |
4649 | * Returns nothing | |
4650 | */ | |
4651 | static void | |
4652 | _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status) | |
4653 | { | |
4654 | u8 ascq; | |
4655 | ||
4656 | switch (ioc_status) { | |
4657 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | |
4658 | ascq = 0x01; | |
4659 | break; | |
4660 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | |
4661 | ascq = 0x02; | |
4662 | break; | |
4663 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | |
4664 | ascq = 0x03; | |
4665 | break; | |
4666 | default: | |
4667 | ascq = 0x00; | |
4668 | break; | |
4669 | } | |
4670 | scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10, | |
4671 | ascq); | |
4672 | scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) | | |
4673 | SAM_STAT_CHECK_CONDITION; | |
4674 | } | |
4675 | ||
f92363d1 | 4676 | /** |
8a7e4c24 | 4677 | * scsih_qcmd - main scsi request entry point |
f92363d1 SR |
4678 | * @scmd: pointer to scsi command object |
4679 | * @done: function pointer to be invoked on completion | |
4680 | * | |
4681 | * The callback index is set inside `ioc->scsi_io_cb_idx`. | |
4682 | * | |
4683 | * Returns 0 on success. If there's a failure, return either: | |
4684 | * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or | |
4685 | * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full | |
4686 | */ | |
8bbb1cf6 | 4687 | static int |
8a7e4c24 | 4688 | scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd) |
f92363d1 | 4689 | { |
d8bfbd8d | 4690 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
f92363d1 SR |
4691 | struct MPT3SAS_DEVICE *sas_device_priv_data; |
4692 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
7786ab6a | 4693 | struct _raid_device *raid_device; |
307d9075 AM |
4694 | struct request *rq = scmd->request; |
4695 | int class; | |
016d5c35 SPS |
4696 | Mpi25SCSIIORequest_t *mpi_request; |
4697 | struct _pcie_device *pcie_device = NULL; | |
f92363d1 SR |
4698 | u32 mpi_control; |
4699 | u16 smid; | |
4700 | u16 handle; | |
4701 | ||
f92363d1 SR |
4702 | if (ioc->logging_level & MPT_DEBUG_SCSI) |
4703 | scsi_print_command(scmd); | |
f92363d1 | 4704 | |
f92363d1 SR |
4705 | sas_device_priv_data = scmd->device->hostdata; |
4706 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | |
4707 | scmd->result = DID_NO_CONNECT << 16; | |
4708 | scmd->scsi_done(scmd); | |
4709 | return 0; | |
4710 | } | |
4711 | ||
4712 | if (ioc->pci_error_recovery || ioc->remove_host) { | |
4713 | scmd->result = DID_NO_CONNECT << 16; | |
4714 | scmd->scsi_done(scmd); | |
4715 | return 0; | |
4716 | } | |
4717 | ||
ffb58456 JB |
4718 | /* |
4719 | * Bug work around for firmware SATL handling. The loop | |
4720 | * is based on atomic operations and ensures consistency | |
4721 | * since we're lockless at this point | |
4722 | */ | |
4723 | do { | |
4724 | if (test_bit(0, &sas_device_priv_data->ata_command_pending)) { | |
4725 | scmd->result = SAM_STAT_BUSY; | |
4726 | scmd->scsi_done(scmd); | |
4727 | return 0; | |
4728 | } | |
4729 | } while (_scsih_set_satl_pending(scmd, true)); | |
4730 | ||
f92363d1 SR |
4731 | sas_target_priv_data = sas_device_priv_data->sas_target; |
4732 | ||
4733 | /* invalid device handle */ | |
4734 | handle = sas_target_priv_data->handle; | |
4735 | if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) { | |
4736 | scmd->result = DID_NO_CONNECT << 16; | |
4737 | scmd->scsi_done(scmd); | |
4738 | return 0; | |
4739 | } | |
4740 | ||
4741 | ||
4742 | /* host recovery or link resets sent via IOCTLs */ | |
4743 | if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress) | |
4744 | return SCSI_MLQUEUE_HOST_BUSY; | |
4745 | ||
4746 | /* device has been deleted */ | |
4747 | else if (sas_target_priv_data->deleted) { | |
4748 | scmd->result = DID_NO_CONNECT << 16; | |
4749 | scmd->scsi_done(scmd); | |
4750 | return 0; | |
6c7abffc | 4751 | /* device busy with task management */ |
f92363d1 SR |
4752 | } else if (sas_target_priv_data->tm_busy || |
4753 | sas_device_priv_data->block) | |
4754 | return SCSI_MLQUEUE_DEVICE_BUSY; | |
4755 | ||
4756 | if (scmd->sc_data_direction == DMA_FROM_DEVICE) | |
4757 | mpi_control = MPI2_SCSIIO_CONTROL_READ; | |
4758 | else if (scmd->sc_data_direction == DMA_TO_DEVICE) | |
4759 | mpi_control = MPI2_SCSIIO_CONTROL_WRITE; | |
4760 | else | |
4761 | mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER; | |
4762 | ||
4763 | /* set tags */ | |
609aa22f | 4764 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; |
307d9075 AM |
4765 | /* NCQ Prio supported, make sure control indicated high priority */ |
4766 | if (sas_device_priv_data->ncq_prio_enable) { | |
4767 | class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq)); | |
4768 | if (class == IOPRIO_CLASS_RT) | |
4769 | mpi_control |= 1 << MPI2_SCSIIO_CONTROL_CMDPRI_SHIFT; | |
4770 | } | |
7786ab6a SR |
4771 | /* Make sure Device is not raid volume. |
4772 | * We do not expose raid functionality to upper layer for warpdrive. | |
4773 | */ | |
4774 | if (!ioc->is_warpdrive && !scsih_is_raid(&scmd->device->sdev_gendev) | |
15de0de2 | 4775 | && sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32) |
f92363d1 SR |
4776 | mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON; |
4777 | ||
4778 | smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd); | |
4779 | if (!smid) { | |
4780 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
4781 | ioc->name, __func__); | |
4782 | goto out; | |
4783 | } | |
4784 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
016d5c35 | 4785 | memset(mpi_request, 0, ioc->request_sz); |
f92363d1 SR |
4786 | _scsih_setup_eedp(ioc, scmd, mpi_request); |
4787 | ||
4788 | if (scmd->cmd_len == 32) | |
4789 | mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT; | |
4790 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; | |
4791 | if (sas_device_priv_data->sas_target->flags & | |
4792 | MPT_TARGET_FLAGS_RAID_COMPONENT) | |
4793 | mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH; | |
4794 | else | |
4795 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; | |
4796 | mpi_request->DevHandle = cpu_to_le16(handle); | |
4797 | mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd)); | |
4798 | mpi_request->Control = cpu_to_le32(mpi_control); | |
4799 | mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len); | |
4800 | mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR; | |
4801 | mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE; | |
4802 | mpi_request->SenseBufferLowAddress = | |
4803 | mpt3sas_base_get_sense_buffer_dma(ioc, smid); | |
016d5c35 | 4804 | mpi_request->SGLOffset0 = offsetof(Mpi25SCSIIORequest_t, SGL) / 4; |
f92363d1 SR |
4805 | int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *) |
4806 | mpi_request->LUN); | |
4807 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); | |
4808 | ||
4809 | if (mpi_request->DataLength) { | |
016d5c35 SPS |
4810 | pcie_device = sas_target_priv_data->pcie_dev; |
4811 | if (ioc->build_sg_scmd(ioc, scmd, smid, pcie_device)) { | |
f92363d1 SR |
4812 | mpt3sas_base_free_smid(ioc, smid); |
4813 | goto out; | |
4814 | } | |
4815 | } else | |
4816 | ioc->build_zero_len_sge(ioc, &mpi_request->SGL); | |
4817 | ||
7786ab6a SR |
4818 | raid_device = sas_target_priv_data->raid_device; |
4819 | if (raid_device && raid_device->direct_io_enabled) | |
c84b06a4 | 4820 | mpt3sas_setup_direct_io(ioc, scmd, raid_device, mpi_request, |
7786ab6a | 4821 | smid); |
7786ab6a | 4822 | |
f92363d1 SR |
4823 | if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) { |
4824 | if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) { | |
4825 | mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len | | |
4826 | MPI25_SCSIIO_IOFLAGS_FAST_PATH); | |
81c16f83 | 4827 | ioc->put_smid_fast_path(ioc, smid, handle); |
f92363d1 | 4828 | } else |
81c16f83 | 4829 | ioc->put_smid_scsi_io(ioc, smid, |
7786ab6a | 4830 | le16_to_cpu(mpi_request->DevHandle)); |
f92363d1 | 4831 | } else |
81c16f83 | 4832 | ioc->put_smid_default(ioc, smid); |
f92363d1 SR |
4833 | return 0; |
4834 | ||
4835 | out: | |
4836 | return SCSI_MLQUEUE_HOST_BUSY; | |
4837 | } | |
f92363d1 SR |
4838 | |
4839 | /** | |
4840 | * _scsih_normalize_sense - normalize descriptor and fixed format sense data | |
4841 | * @sense_buffer: sense data returned by target | |
4842 | * @data: normalized skey/asc/ascq | |
4843 | * | |
4844 | * Return nothing. | |
4845 | */ | |
4846 | static void | |
4847 | _scsih_normalize_sense(char *sense_buffer, struct sense_info *data) | |
4848 | { | |
4849 | if ((sense_buffer[0] & 0x7F) >= 0x72) { | |
4850 | /* descriptor format */ | |
4851 | data->skey = sense_buffer[1] & 0x0F; | |
4852 | data->asc = sense_buffer[2]; | |
4853 | data->ascq = sense_buffer[3]; | |
4854 | } else { | |
4855 | /* fixed format */ | |
4856 | data->skey = sense_buffer[2] & 0x0F; | |
4857 | data->asc = sense_buffer[12]; | |
4858 | data->ascq = sense_buffer[13]; | |
4859 | } | |
4860 | } | |
4861 | ||
f92363d1 SR |
4862 | /** |
4863 | * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request | |
4864 | * @ioc: per adapter object | |
4865 | * @scmd: pointer to scsi command object | |
4866 | * @mpi_reply: reply mf payload returned from firmware | |
4867 | * | |
4868 | * scsi_status - SCSI Status code returned from target device | |
4869 | * scsi_state - state info associated with SCSI_IO determined by ioc | |
4870 | * ioc_status - ioc supplied status info | |
4871 | * | |
4872 | * Return nothing. | |
4873 | */ | |
4874 | static void | |
4875 | _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, | |
4876 | Mpi2SCSIIOReply_t *mpi_reply, u16 smid) | |
4877 | { | |
4878 | u32 response_info; | |
4879 | u8 *response_bytes; | |
4880 | u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & | |
4881 | MPI2_IOCSTATUS_MASK; | |
4882 | u8 scsi_state = mpi_reply->SCSIState; | |
4883 | u8 scsi_status = mpi_reply->SCSIStatus; | |
4884 | char *desc_ioc_state = NULL; | |
4885 | char *desc_scsi_status = NULL; | |
4886 | char *desc_scsi_state = ioc->tmp_string; | |
4887 | u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo); | |
4888 | struct _sas_device *sas_device = NULL; | |
f92363d1 SR |
4889 | struct scsi_target *starget = scmd->device->sdev_target; |
4890 | struct MPT3SAS_TARGET *priv_target = starget->hostdata; | |
4891 | char *device_str = NULL; | |
4892 | ||
4893 | if (!priv_target) | |
4894 | return; | |
7786ab6a SR |
4895 | if (ioc->hide_ir_msg) |
4896 | device_str = "WarpDrive"; | |
4897 | else | |
4898 | device_str = "volume"; | |
f92363d1 SR |
4899 | |
4900 | if (log_info == 0x31170000) | |
4901 | return; | |
4902 | ||
4903 | switch (ioc_status) { | |
4904 | case MPI2_IOCSTATUS_SUCCESS: | |
4905 | desc_ioc_state = "success"; | |
4906 | break; | |
4907 | case MPI2_IOCSTATUS_INVALID_FUNCTION: | |
4908 | desc_ioc_state = "invalid function"; | |
4909 | break; | |
4910 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: | |
4911 | desc_ioc_state = "scsi recovered error"; | |
4912 | break; | |
4913 | case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE: | |
4914 | desc_ioc_state = "scsi invalid dev handle"; | |
4915 | break; | |
4916 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: | |
4917 | desc_ioc_state = "scsi device not there"; | |
4918 | break; | |
4919 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: | |
4920 | desc_ioc_state = "scsi data overrun"; | |
4921 | break; | |
4922 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: | |
4923 | desc_ioc_state = "scsi data underrun"; | |
4924 | break; | |
4925 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: | |
4926 | desc_ioc_state = "scsi io data error"; | |
4927 | break; | |
4928 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: | |
4929 | desc_ioc_state = "scsi protocol error"; | |
4930 | break; | |
4931 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: | |
4932 | desc_ioc_state = "scsi task terminated"; | |
4933 | break; | |
4934 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: | |
4935 | desc_ioc_state = "scsi residual mismatch"; | |
4936 | break; | |
4937 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: | |
4938 | desc_ioc_state = "scsi task mgmt failed"; | |
4939 | break; | |
4940 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: | |
4941 | desc_ioc_state = "scsi ioc terminated"; | |
4942 | break; | |
4943 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: | |
4944 | desc_ioc_state = "scsi ext terminated"; | |
4945 | break; | |
4946 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | |
4947 | desc_ioc_state = "eedp guard error"; | |
4948 | break; | |
4949 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | |
4950 | desc_ioc_state = "eedp ref tag error"; | |
4951 | break; | |
4952 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | |
4953 | desc_ioc_state = "eedp app tag error"; | |
4954 | break; | |
b130b0d5 SS |
4955 | case MPI2_IOCSTATUS_INSUFFICIENT_POWER: |
4956 | desc_ioc_state = "insufficient power"; | |
4957 | break; | |
f92363d1 SR |
4958 | default: |
4959 | desc_ioc_state = "unknown"; | |
4960 | break; | |
4961 | } | |
4962 | ||
4963 | switch (scsi_status) { | |
4964 | case MPI2_SCSI_STATUS_GOOD: | |
4965 | desc_scsi_status = "good"; | |
4966 | break; | |
4967 | case MPI2_SCSI_STATUS_CHECK_CONDITION: | |
4968 | desc_scsi_status = "check condition"; | |
4969 | break; | |
4970 | case MPI2_SCSI_STATUS_CONDITION_MET: | |
4971 | desc_scsi_status = "condition met"; | |
4972 | break; | |
4973 | case MPI2_SCSI_STATUS_BUSY: | |
4974 | desc_scsi_status = "busy"; | |
4975 | break; | |
4976 | case MPI2_SCSI_STATUS_INTERMEDIATE: | |
4977 | desc_scsi_status = "intermediate"; | |
4978 | break; | |
4979 | case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET: | |
4980 | desc_scsi_status = "intermediate condmet"; | |
4981 | break; | |
4982 | case MPI2_SCSI_STATUS_RESERVATION_CONFLICT: | |
4983 | desc_scsi_status = "reservation conflict"; | |
4984 | break; | |
4985 | case MPI2_SCSI_STATUS_COMMAND_TERMINATED: | |
4986 | desc_scsi_status = "command terminated"; | |
4987 | break; | |
4988 | case MPI2_SCSI_STATUS_TASK_SET_FULL: | |
4989 | desc_scsi_status = "task set full"; | |
4990 | break; | |
4991 | case MPI2_SCSI_STATUS_ACA_ACTIVE: | |
4992 | desc_scsi_status = "aca active"; | |
4993 | break; | |
4994 | case MPI2_SCSI_STATUS_TASK_ABORTED: | |
4995 | desc_scsi_status = "task aborted"; | |
4996 | break; | |
4997 | default: | |
4998 | desc_scsi_status = "unknown"; | |
4999 | break; | |
5000 | } | |
5001 | ||
5002 | desc_scsi_state[0] = '\0'; | |
5003 | if (!scsi_state) | |
5004 | desc_scsi_state = " "; | |
5005 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) | |
5006 | strcat(desc_scsi_state, "response info "); | |
5007 | if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | |
5008 | strcat(desc_scsi_state, "state terminated "); | |
5009 | if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS) | |
5010 | strcat(desc_scsi_state, "no status "); | |
5011 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED) | |
5012 | strcat(desc_scsi_state, "autosense failed "); | |
5013 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) | |
5014 | strcat(desc_scsi_state, "autosense valid "); | |
5015 | ||
5016 | scsi_print_command(scmd); | |
5017 | ||
5018 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { | |
5019 | pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name, | |
5020 | device_str, (unsigned long long)priv_target->sas_address); | |
5021 | } else { | |
d1cb5e49 | 5022 | sas_device = mpt3sas_get_sdev_from_target(ioc, priv_target); |
f92363d1 SR |
5023 | if (sas_device) { |
5024 | pr_warn(MPT3SAS_FMT | |
5025 | "\tsas_address(0x%016llx), phy(%d)\n", | |
5026 | ioc->name, (unsigned long long) | |
5027 | sas_device->sas_address, sas_device->phy); | |
75888956 SR |
5028 | |
5029 | _scsih_display_enclosure_chassis_info(ioc, sas_device, | |
5030 | NULL, NULL); | |
d1cb5e49 SR |
5031 | |
5032 | sas_device_put(sas_device); | |
f92363d1 | 5033 | } |
f92363d1 SR |
5034 | } |
5035 | ||
5036 | pr_warn(MPT3SAS_FMT | |
5037 | "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n", | |
5038 | ioc->name, le16_to_cpu(mpi_reply->DevHandle), | |
5039 | desc_ioc_state, ioc_status, smid); | |
5040 | pr_warn(MPT3SAS_FMT | |
5041 | "\trequest_len(%d), underflow(%d), resid(%d)\n", | |
5042 | ioc->name, scsi_bufflen(scmd), scmd->underflow, | |
5043 | scsi_get_resid(scmd)); | |
5044 | pr_warn(MPT3SAS_FMT | |
5045 | "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n", | |
5046 | ioc->name, le16_to_cpu(mpi_reply->TaskTag), | |
5047 | le32_to_cpu(mpi_reply->TransferCount), scmd->result); | |
5048 | pr_warn(MPT3SAS_FMT | |
5049 | "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n", | |
5050 | ioc->name, desc_scsi_status, | |
5051 | scsi_status, desc_scsi_state, scsi_state); | |
5052 | ||
5053 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { | |
5054 | struct sense_info data; | |
5055 | _scsih_normalize_sense(scmd->sense_buffer, &data); | |
5056 | pr_warn(MPT3SAS_FMT | |
5057 | "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n", | |
5058 | ioc->name, data.skey, | |
5059 | data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount)); | |
5060 | } | |
5061 | ||
5062 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) { | |
5063 | response_info = le32_to_cpu(mpi_reply->ResponseInfo); | |
5064 | response_bytes = (u8 *)&response_info; | |
5065 | _scsih_response_code(ioc, response_bytes[0]); | |
5066 | } | |
5067 | } | |
f92363d1 SR |
5068 | |
5069 | /** | |
0f624c39 | 5070 | * _scsih_turn_on_pfa_led - illuminate PFA LED |
f92363d1 SR |
5071 | * @ioc: per adapter object |
5072 | * @handle: device handle | |
5073 | * Context: process | |
5074 | * | |
5075 | * Return nothing. | |
5076 | */ | |
5077 | static void | |
0f624c39 | 5078 | _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
f92363d1 SR |
5079 | { |
5080 | Mpi2SepReply_t mpi_reply; | |
5081 | Mpi2SepRequest_t mpi_request; | |
0f624c39 SR |
5082 | struct _sas_device *sas_device; |
5083 | ||
d1cb5e49 | 5084 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
0f624c39 SR |
5085 | if (!sas_device) |
5086 | return; | |
f92363d1 SR |
5087 | |
5088 | memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t)); | |
5089 | mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; | |
5090 | mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; | |
5091 | mpi_request.SlotStatus = | |
5092 | cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT); | |
5093 | mpi_request.DevHandle = cpu_to_le16(handle); | |
5094 | mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS; | |
5095 | if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply, | |
5096 | &mpi_request)) != 0) { | |
5097 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name, | |
5098 | __FILE__, __LINE__, __func__); | |
d1cb5e49 | 5099 | goto out; |
f92363d1 | 5100 | } |
0f624c39 | 5101 | sas_device->pfa_led_on = 1; |
f92363d1 SR |
5102 | |
5103 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) { | |
5104 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
5105 | "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n", | |
5106 | ioc->name, le16_to_cpu(mpi_reply.IOCStatus), | |
5107 | le32_to_cpu(mpi_reply.IOCLogInfo))); | |
d1cb5e49 | 5108 | goto out; |
f92363d1 | 5109 | } |
d1cb5e49 SR |
5110 | out: |
5111 | sas_device_put(sas_device); | |
f92363d1 | 5112 | } |
d1cb5e49 | 5113 | |
0f624c39 SR |
5114 | /** |
5115 | * _scsih_turn_off_pfa_led - turn off Fault LED | |
5116 | * @ioc: per adapter object | |
5117 | * @sas_device: sas device whose PFA LED has to turned off | |
5118 | * Context: process | |
5119 | * | |
5120 | * Return nothing. | |
5121 | */ | |
5122 | static void | |
5123 | _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc, | |
5124 | struct _sas_device *sas_device) | |
5125 | { | |
5126 | Mpi2SepReply_t mpi_reply; | |
5127 | Mpi2SepRequest_t mpi_request; | |
f92363d1 | 5128 | |
0f624c39 SR |
5129 | memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t)); |
5130 | mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; | |
5131 | mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; | |
5132 | mpi_request.SlotStatus = 0; | |
5133 | mpi_request.Slot = cpu_to_le16(sas_device->slot); | |
5134 | mpi_request.DevHandle = 0; | |
5135 | mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle); | |
5136 | mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS; | |
5137 | if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply, | |
5138 | &mpi_request)) != 0) { | |
5139 | printk(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name, | |
5140 | __FILE__, __LINE__, __func__); | |
5141 | return; | |
5142 | } | |
5143 | ||
5144 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) { | |
5145 | dewtprintk(ioc, printk(MPT3SAS_FMT | |
5146 | "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n", | |
5147 | ioc->name, le16_to_cpu(mpi_reply.IOCStatus), | |
5148 | le32_to_cpu(mpi_reply.IOCLogInfo))); | |
5149 | return; | |
5150 | } | |
5151 | } | |
d1cb5e49 | 5152 | |
f92363d1 | 5153 | /** |
0f624c39 | 5154 | * _scsih_send_event_to_turn_on_pfa_led - fire delayed event |
f92363d1 SR |
5155 | * @ioc: per adapter object |
5156 | * @handle: device handle | |
5157 | * Context: interrupt. | |
5158 | * | |
5159 | * Return nothing. | |
5160 | */ | |
5161 | static void | |
0f624c39 | 5162 | _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
f92363d1 SR |
5163 | { |
5164 | struct fw_event_work *fw_event; | |
5165 | ||
146b16c8 | 5166 | fw_event = alloc_fw_event_work(0); |
f92363d1 SR |
5167 | if (!fw_event) |
5168 | return; | |
0f624c39 | 5169 | fw_event->event = MPT3SAS_TURN_ON_PFA_LED; |
f92363d1 SR |
5170 | fw_event->device_handle = handle; |
5171 | fw_event->ioc = ioc; | |
5172 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 | 5173 | fw_event_work_put(fw_event); |
f92363d1 SR |
5174 | } |
5175 | ||
5176 | /** | |
5177 | * _scsih_smart_predicted_fault - process smart errors | |
5178 | * @ioc: per adapter object | |
5179 | * @handle: device handle | |
5180 | * Context: interrupt. | |
5181 | * | |
5182 | * Return nothing. | |
5183 | */ | |
5184 | static void | |
5185 | _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
5186 | { | |
5187 | struct scsi_target *starget; | |
5188 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
5189 | Mpi2EventNotificationReply_t *event_reply; | |
5190 | Mpi2EventDataSasDeviceStatusChange_t *event_data; | |
5191 | struct _sas_device *sas_device; | |
5192 | ssize_t sz; | |
5193 | unsigned long flags; | |
5194 | ||
5195 | /* only handle non-raid devices */ | |
5196 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 SR |
5197 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
5198 | if (!sas_device) | |
5199 | goto out_unlock; | |
5200 | ||
f92363d1 SR |
5201 | starget = sas_device->starget; |
5202 | sas_target_priv_data = starget->hostdata; | |
5203 | ||
5204 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) || | |
d1cb5e49 SR |
5205 | ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) |
5206 | goto out_unlock; | |
5207 | ||
75888956 SR |
5208 | _scsih_display_enclosure_chassis_info(NULL, sas_device, NULL, starget); |
5209 | ||
f92363d1 SR |
5210 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
5211 | ||
5212 | if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) | |
0f624c39 | 5213 | _scsih_send_event_to_turn_on_pfa_led(ioc, handle); |
f92363d1 SR |
5214 | |
5215 | /* insert into event log */ | |
5216 | sz = offsetof(Mpi2EventNotificationReply_t, EventData) + | |
5217 | sizeof(Mpi2EventDataSasDeviceStatusChange_t); | |
5218 | event_reply = kzalloc(sz, GFP_KERNEL); | |
5219 | if (!event_reply) { | |
5220 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5221 | ioc->name, __FILE__, __LINE__, __func__); | |
d1cb5e49 | 5222 | goto out; |
f92363d1 SR |
5223 | } |
5224 | ||
5225 | event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION; | |
5226 | event_reply->Event = | |
5227 | cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE); | |
5228 | event_reply->MsgLength = sz/4; | |
5229 | event_reply->EventDataLength = | |
5230 | cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4); | |
5231 | event_data = (Mpi2EventDataSasDeviceStatusChange_t *) | |
5232 | event_reply->EventData; | |
5233 | event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA; | |
5234 | event_data->ASC = 0x5D; | |
5235 | event_data->DevHandle = cpu_to_le16(handle); | |
5236 | event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address); | |
5237 | mpt3sas_ctl_add_to_event_log(ioc, event_reply); | |
5238 | kfree(event_reply); | |
d1cb5e49 SR |
5239 | out: |
5240 | if (sas_device) | |
5241 | sas_device_put(sas_device); | |
5242 | return; | |
5243 | ||
5244 | out_unlock: | |
5245 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
5246 | goto out; | |
f92363d1 SR |
5247 | } |
5248 | ||
5249 | /** | |
5250 | * _scsih_io_done - scsi request callback | |
5251 | * @ioc: per adapter object | |
5252 | * @smid: system request message index | |
5253 | * @msix_index: MSIX table index supplied by the OS | |
5254 | * @reply: reply message frame(lower 32bit addr) | |
5255 | * | |
5256 | * Callback handler when using _scsih_qcmd. | |
5257 | * | |
5258 | * Return 1 meaning mf should be freed from _base_interrupt | |
5259 | * 0 means the mf is freed from this function. | |
5260 | */ | |
5261 | static u8 | |
5262 | _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | |
5263 | { | |
016d5c35 | 5264 | Mpi25SCSIIORequest_t *mpi_request; |
f92363d1 SR |
5265 | Mpi2SCSIIOReply_t *mpi_reply; |
5266 | struct scsi_cmnd *scmd; | |
5267 | u16 ioc_status; | |
5268 | u32 xfer_cnt; | |
5269 | u8 scsi_state; | |
5270 | u8 scsi_status; | |
5271 | u32 log_info; | |
5272 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
5273 | u32 response_code = 0; | |
7786ab6a | 5274 | unsigned long flags; |
f92363d1 SR |
5275 | |
5276 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
459325c4 C |
5277 | |
5278 | if (ioc->broadcast_aen_busy || ioc->pci_error_recovery || | |
5279 | ioc->got_task_abort_from_ioctl) | |
5280 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); | |
5281 | else | |
5282 | scmd = __scsih_scsi_lookup_get_clear(ioc, smid); | |
5283 | ||
f92363d1 SR |
5284 | if (scmd == NULL) |
5285 | return 1; | |
5286 | ||
ffb58456 | 5287 | _scsih_set_satl_pending(scmd, false); |
18f6084a | 5288 | |
f92363d1 SR |
5289 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
5290 | ||
5291 | if (mpi_reply == NULL) { | |
5292 | scmd->result = DID_OK << 16; | |
5293 | goto out; | |
5294 | } | |
5295 | ||
5296 | sas_device_priv_data = scmd->device->hostdata; | |
5297 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target || | |
5298 | sas_device_priv_data->sas_target->deleted) { | |
5299 | scmd->result = DID_NO_CONNECT << 16; | |
5300 | goto out; | |
5301 | } | |
5302 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); | |
5303 | ||
7786ab6a SR |
5304 | /* |
5305 | * WARPDRIVE: If direct_io is set then it is directIO, | |
5306 | * the failed direct I/O should be redirected to volume | |
5307 | */ | |
c84b06a4 | 5308 | if (mpt3sas_scsi_direct_io_get(ioc, smid) && |
7786ab6a SR |
5309 | ((ioc_status & MPI2_IOCSTATUS_MASK) |
5310 | != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) { | |
5311 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
5312 | ioc->scsi_lookup[smid - 1].scmd = scmd; | |
5313 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
c84b06a4 | 5314 | mpt3sas_scsi_direct_io_set(ioc, smid, 0); |
7786ab6a SR |
5315 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); |
5316 | mpi_request->DevHandle = | |
5317 | cpu_to_le16(sas_device_priv_data->sas_target->handle); | |
81c16f83 | 5318 | ioc->put_smid_scsi_io(ioc, smid, |
7786ab6a SR |
5319 | sas_device_priv_data->sas_target->handle); |
5320 | return 0; | |
5321 | } | |
f92363d1 SR |
5322 | /* turning off TLR */ |
5323 | scsi_state = mpi_reply->SCSIState; | |
5324 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) | |
5325 | response_code = | |
5326 | le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF; | |
5327 | if (!sas_device_priv_data->tlr_snoop_check) { | |
5328 | sas_device_priv_data->tlr_snoop_check++; | |
7786ab6a SR |
5329 | if (!ioc->is_warpdrive && |
5330 | !scsih_is_raid(&scmd->device->sdev_gendev) && | |
c84b06a4 SR |
5331 | sas_is_tlr_enabled(scmd->device) && |
5332 | response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) { | |
5333 | sas_disable_tlr(scmd->device); | |
5334 | sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n"); | |
5335 | } | |
f92363d1 SR |
5336 | } |
5337 | ||
5338 | xfer_cnt = le32_to_cpu(mpi_reply->TransferCount); | |
5339 | scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt); | |
5340 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) | |
5341 | log_info = le32_to_cpu(mpi_reply->IOCLogInfo); | |
5342 | else | |
5343 | log_info = 0; | |
5344 | ioc_status &= MPI2_IOCSTATUS_MASK; | |
5345 | scsi_status = mpi_reply->SCSIStatus; | |
5346 | ||
5347 | if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 && | |
5348 | (scsi_status == MPI2_SCSI_STATUS_BUSY || | |
5349 | scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT || | |
5350 | scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) { | |
5351 | ioc_status = MPI2_IOCSTATUS_SUCCESS; | |
5352 | } | |
5353 | ||
5354 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { | |
5355 | struct sense_info data; | |
5356 | const void *sense_data = mpt3sas_base_get_sense_buffer(ioc, | |
5357 | smid); | |
5358 | u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE, | |
5359 | le32_to_cpu(mpi_reply->SenseCount)); | |
5360 | memcpy(scmd->sense_buffer, sense_data, sz); | |
5361 | _scsih_normalize_sense(scmd->sense_buffer, &data); | |
5362 | /* failure prediction threshold exceeded */ | |
5363 | if (data.asc == 0x5D) | |
5364 | _scsih_smart_predicted_fault(ioc, | |
5365 | le16_to_cpu(mpi_reply->DevHandle)); | |
5366 | mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq); | |
f92363d1 | 5367 | |
0d667f72 | 5368 | if ((ioc->logging_level & MPT_DEBUG_REPLY) && |
e6d45e3e SR |
5369 | ((scmd->sense_buffer[2] == UNIT_ATTENTION) || |
5370 | (scmd->sense_buffer[2] == MEDIUM_ERROR) || | |
5371 | (scmd->sense_buffer[2] == HARDWARE_ERROR))) | |
5372 | _scsih_scsi_ioc_info(ioc, scmd, mpi_reply, smid); | |
e6d45e3e | 5373 | } |
f92363d1 SR |
5374 | switch (ioc_status) { |
5375 | case MPI2_IOCSTATUS_BUSY: | |
5376 | case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES: | |
5377 | scmd->result = SAM_STAT_BUSY; | |
5378 | break; | |
5379 | ||
5380 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: | |
5381 | scmd->result = DID_NO_CONNECT << 16; | |
5382 | break; | |
5383 | ||
5384 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: | |
5385 | if (sas_device_priv_data->block) { | |
5386 | scmd->result = DID_TRANSPORT_DISRUPTED << 16; | |
5387 | goto out; | |
5388 | } | |
5389 | if (log_info == 0x31110630) { | |
5390 | if (scmd->retries > 2) { | |
5391 | scmd->result = DID_NO_CONNECT << 16; | |
5392 | scsi_device_set_state(scmd->device, | |
5393 | SDEV_OFFLINE); | |
5394 | } else { | |
5395 | scmd->result = DID_SOFT_ERROR << 16; | |
5396 | scmd->device->expecting_cc_ua = 1; | |
5397 | } | |
5398 | break; | |
3898f08e SR |
5399 | } else if (log_info == VIRTUAL_IO_FAILED_RETRY) { |
5400 | scmd->result = DID_RESET << 16; | |
5401 | break; | |
2ce9a364 SR |
5402 | } else if ((scmd->device->channel == RAID_CHANNEL) && |
5403 | (scsi_state == (MPI2_SCSI_STATE_TERMINATED | | |
5404 | MPI2_SCSI_STATE_NO_SCSI_STATUS))) { | |
5405 | scmd->result = DID_RESET << 16; | |
5406 | break; | |
f92363d1 SR |
5407 | } |
5408 | scmd->result = DID_SOFT_ERROR << 16; | |
5409 | break; | |
5410 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: | |
5411 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: | |
5412 | scmd->result = DID_RESET << 16; | |
5413 | break; | |
5414 | ||
5415 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: | |
5416 | if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt)) | |
5417 | scmd->result = DID_SOFT_ERROR << 16; | |
5418 | else | |
5419 | scmd->result = (DID_OK << 16) | scsi_status; | |
5420 | break; | |
5421 | ||
5422 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: | |
5423 | scmd->result = (DID_OK << 16) | scsi_status; | |
5424 | ||
5425 | if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)) | |
5426 | break; | |
5427 | ||
5428 | if (xfer_cnt < scmd->underflow) { | |
5429 | if (scsi_status == SAM_STAT_BUSY) | |
5430 | scmd->result = SAM_STAT_BUSY; | |
5431 | else | |
5432 | scmd->result = DID_SOFT_ERROR << 16; | |
5433 | } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | | |
5434 | MPI2_SCSI_STATE_NO_SCSI_STATUS)) | |
5435 | scmd->result = DID_SOFT_ERROR << 16; | |
5436 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | |
5437 | scmd->result = DID_RESET << 16; | |
5438 | else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) { | |
5439 | mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID; | |
5440 | mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION; | |
5441 | scmd->result = (DRIVER_SENSE << 24) | | |
5442 | SAM_STAT_CHECK_CONDITION; | |
5443 | scmd->sense_buffer[0] = 0x70; | |
5444 | scmd->sense_buffer[2] = ILLEGAL_REQUEST; | |
5445 | scmd->sense_buffer[12] = 0x20; | |
5446 | scmd->sense_buffer[13] = 0; | |
5447 | } | |
5448 | break; | |
5449 | ||
5450 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: | |
5451 | scsi_set_resid(scmd, 0); | |
5452 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: | |
5453 | case MPI2_IOCSTATUS_SUCCESS: | |
5454 | scmd->result = (DID_OK << 16) | scsi_status; | |
5455 | if (response_code == | |
5456 | MPI2_SCSITASKMGMT_RSP_INVALID_FRAME || | |
5457 | (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | | |
5458 | MPI2_SCSI_STATE_NO_SCSI_STATUS))) | |
5459 | scmd->result = DID_SOFT_ERROR << 16; | |
5460 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | |
5461 | scmd->result = DID_RESET << 16; | |
5462 | break; | |
5463 | ||
5464 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | |
5465 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | |
5466 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | |
5467 | _scsih_eedp_error_handling(scmd, ioc_status); | |
5468 | break; | |
5469 | ||
5470 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: | |
5471 | case MPI2_IOCSTATUS_INVALID_FUNCTION: | |
5472 | case MPI2_IOCSTATUS_INVALID_SGL: | |
5473 | case MPI2_IOCSTATUS_INTERNAL_ERROR: | |
5474 | case MPI2_IOCSTATUS_INVALID_FIELD: | |
5475 | case MPI2_IOCSTATUS_INVALID_STATE: | |
5476 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: | |
5477 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: | |
b130b0d5 | 5478 | case MPI2_IOCSTATUS_INSUFFICIENT_POWER: |
f92363d1 SR |
5479 | default: |
5480 | scmd->result = DID_SOFT_ERROR << 16; | |
5481 | break; | |
5482 | ||
5483 | } | |
5484 | ||
f92363d1 SR |
5485 | if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY)) |
5486 | _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid); | |
f92363d1 SR |
5487 | |
5488 | out: | |
5489 | ||
5490 | scsi_dma_unmap(scmd); | |
5491 | ||
5492 | scmd->scsi_done(scmd); | |
5493 | return 1; | |
5494 | } | |
5495 | ||
5496 | /** | |
5497 | * _scsih_sas_host_refresh - refreshing sas host object contents | |
5498 | * @ioc: per adapter object | |
5499 | * Context: user | |
5500 | * | |
5501 | * During port enable, fw will send topology events for every device. Its | |
5502 | * possible that the handles may change from the previous setting, so this | |
5503 | * code keeping handles updating if changed. | |
5504 | * | |
5505 | * Return nothing. | |
5506 | */ | |
5507 | static void | |
5508 | _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc) | |
5509 | { | |
5510 | u16 sz; | |
5511 | u16 ioc_status; | |
5512 | int i; | |
5513 | Mpi2ConfigReply_t mpi_reply; | |
5514 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; | |
5515 | u16 attached_handle; | |
5516 | u8 link_rate; | |
5517 | ||
5518 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
5519 | "updating handles for sas_host(0x%016llx)\n", | |
5520 | ioc->name, (unsigned long long)ioc->sas_hba.sas_address)); | |
5521 | ||
5522 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys | |
5523 | * sizeof(Mpi2SasIOUnit0PhyData_t)); | |
5524 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); | |
5525 | if (!sas_iounit_pg0) { | |
5526 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5527 | ioc->name, __FILE__, __LINE__, __func__); | |
5528 | return; | |
5529 | } | |
5530 | ||
5531 | if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, | |
5532 | sas_iounit_pg0, sz)) != 0) | |
5533 | goto out; | |
5534 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
5535 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | |
5536 | goto out; | |
5537 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { | |
5538 | link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4; | |
5539 | if (i == 0) | |
5540 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> | |
5541 | PhyData[0].ControllerDevHandle); | |
5542 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; | |
5543 | attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i]. | |
5544 | AttachedDevHandle); | |
5545 | if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) | |
5546 | link_rate = MPI2_SAS_NEG_LINK_RATE_1_5; | |
5547 | mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address, | |
5548 | attached_handle, i, link_rate); | |
5549 | } | |
5550 | out: | |
5551 | kfree(sas_iounit_pg0); | |
5552 | } | |
5553 | ||
5554 | /** | |
5555 | * _scsih_sas_host_add - create sas host object | |
5556 | * @ioc: per adapter object | |
5557 | * | |
5558 | * Creating host side data object, stored in ioc->sas_hba | |
5559 | * | |
5560 | * Return nothing. | |
5561 | */ | |
5562 | static void | |
5563 | _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc) | |
5564 | { | |
5565 | int i; | |
5566 | Mpi2ConfigReply_t mpi_reply; | |
5567 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; | |
5568 | Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; | |
5569 | Mpi2SasPhyPage0_t phy_pg0; | |
5570 | Mpi2SasDevicePage0_t sas_device_pg0; | |
5571 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
5572 | u16 ioc_status; | |
5573 | u16 sz; | |
5574 | u8 device_missing_delay; | |
87aa95d4 | 5575 | u8 num_phys; |
f92363d1 | 5576 | |
87aa95d4 JL |
5577 | mpt3sas_config_get_number_hba_phys(ioc, &num_phys); |
5578 | if (!num_phys) { | |
f92363d1 SR |
5579 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
5580 | ioc->name, __FILE__, __LINE__, __func__); | |
5581 | return; | |
5582 | } | |
87aa95d4 JL |
5583 | ioc->sas_hba.phy = kcalloc(num_phys, |
5584 | sizeof(struct _sas_phy), GFP_KERNEL); | |
5585 | if (!ioc->sas_hba.phy) { | |
5586 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5587 | ioc->name, __FILE__, __LINE__, __func__); | |
5588 | goto out; | |
5589 | } | |
5590 | ioc->sas_hba.num_phys = num_phys; | |
f92363d1 SR |
5591 | |
5592 | /* sas_iounit page 0 */ | |
5593 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys * | |
5594 | sizeof(Mpi2SasIOUnit0PhyData_t)); | |
5595 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); | |
5596 | if (!sas_iounit_pg0) { | |
5597 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5598 | ioc->name, __FILE__, __LINE__, __func__); | |
5599 | return; | |
5600 | } | |
5601 | if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, | |
5602 | sas_iounit_pg0, sz))) { | |
5603 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5604 | ioc->name, __FILE__, __LINE__, __func__); | |
5605 | goto out; | |
5606 | } | |
5607 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5608 | MPI2_IOCSTATUS_MASK; | |
5609 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
5610 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5611 | ioc->name, __FILE__, __LINE__, __func__); | |
5612 | goto out; | |
5613 | } | |
5614 | ||
5615 | /* sas_iounit page 1 */ | |
5616 | sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys * | |
5617 | sizeof(Mpi2SasIOUnit1PhyData_t)); | |
5618 | sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL); | |
5619 | if (!sas_iounit_pg1) { | |
5620 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5621 | ioc->name, __FILE__, __LINE__, __func__); | |
5622 | goto out; | |
5623 | } | |
5624 | if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply, | |
5625 | sas_iounit_pg1, sz))) { | |
5626 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5627 | ioc->name, __FILE__, __LINE__, __func__); | |
5628 | goto out; | |
5629 | } | |
5630 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5631 | MPI2_IOCSTATUS_MASK; | |
5632 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
5633 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5634 | ioc->name, __FILE__, __LINE__, __func__); | |
5635 | goto out; | |
5636 | } | |
5637 | ||
5638 | ioc->io_missing_delay = | |
5639 | sas_iounit_pg1->IODeviceMissingDelay; | |
5640 | device_missing_delay = | |
5641 | sas_iounit_pg1->ReportDeviceMissingDelay; | |
5642 | if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16) | |
5643 | ioc->device_missing_delay = (device_missing_delay & | |
5644 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16; | |
5645 | else | |
5646 | ioc->device_missing_delay = device_missing_delay & | |
5647 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK; | |
5648 | ||
5649 | ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev; | |
f92363d1 SR |
5650 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { |
5651 | if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0, | |
5652 | i))) { | |
5653 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5654 | ioc->name, __FILE__, __LINE__, __func__); | |
5655 | goto out; | |
5656 | } | |
5657 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5658 | MPI2_IOCSTATUS_MASK; | |
5659 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
5660 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5661 | ioc->name, __FILE__, __LINE__, __func__); | |
5662 | goto out; | |
5663 | } | |
5664 | ||
5665 | if (i == 0) | |
5666 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> | |
5667 | PhyData[0].ControllerDevHandle); | |
5668 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; | |
5669 | ioc->sas_hba.phy[i].phy_id = i; | |
5670 | mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i], | |
5671 | phy_pg0, ioc->sas_hba.parent_dev); | |
5672 | } | |
5673 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
5674 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) { | |
5675 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5676 | ioc->name, __FILE__, __LINE__, __func__); | |
5677 | goto out; | |
5678 | } | |
5679 | ioc->sas_hba.enclosure_handle = | |
5680 | le16_to_cpu(sas_device_pg0.EnclosureHandle); | |
5681 | ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | |
5682 | pr_info(MPT3SAS_FMT | |
5683 | "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n", | |
5684 | ioc->name, ioc->sas_hba.handle, | |
5685 | (unsigned long long) ioc->sas_hba.sas_address, | |
5686 | ioc->sas_hba.num_phys) ; | |
5687 | ||
5688 | if (ioc->sas_hba.enclosure_handle) { | |
5689 | if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
5690 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
5691 | ioc->sas_hba.enclosure_handle))) | |
5692 | ioc->sas_hba.enclosure_logical_id = | |
5693 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
5694 | } | |
5695 | ||
5696 | out: | |
5697 | kfree(sas_iounit_pg1); | |
5698 | kfree(sas_iounit_pg0); | |
5699 | } | |
5700 | ||
5701 | /** | |
5702 | * _scsih_expander_add - creating expander object | |
5703 | * @ioc: per adapter object | |
5704 | * @handle: expander handle | |
5705 | * | |
5706 | * Creating expander object, stored in ioc->sas_expander_list. | |
5707 | * | |
5708 | * Return 0 for success, else error. | |
5709 | */ | |
5710 | static int | |
5711 | _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
5712 | { | |
5713 | struct _sas_node *sas_expander; | |
5714 | Mpi2ConfigReply_t mpi_reply; | |
5715 | Mpi2ExpanderPage0_t expander_pg0; | |
5716 | Mpi2ExpanderPage1_t expander_pg1; | |
5717 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
5718 | u32 ioc_status; | |
5719 | u16 parent_handle; | |
5720 | u64 sas_address, sas_address_parent = 0; | |
5721 | int i; | |
5722 | unsigned long flags; | |
5723 | struct _sas_port *mpt3sas_port = NULL; | |
5724 | ||
5725 | int rc = 0; | |
5726 | ||
5727 | if (!handle) | |
5728 | return -1; | |
5729 | ||
5730 | if (ioc->shost_recovery || ioc->pci_error_recovery) | |
5731 | return -1; | |
5732 | ||
5733 | if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | |
5734 | MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) { | |
5735 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5736 | ioc->name, __FILE__, __LINE__, __func__); | |
5737 | return -1; | |
5738 | } | |
5739 | ||
5740 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5741 | MPI2_IOCSTATUS_MASK; | |
5742 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
5743 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5744 | ioc->name, __FILE__, __LINE__, __func__); | |
5745 | return -1; | |
5746 | } | |
5747 | ||
5748 | /* handle out of order topology events */ | |
5749 | parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle); | |
5750 | if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent) | |
5751 | != 0) { | |
5752 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5753 | ioc->name, __FILE__, __LINE__, __func__); | |
5754 | return -1; | |
5755 | } | |
5756 | if (sas_address_parent != ioc->sas_hba.sas_address) { | |
5757 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
5758 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, | |
5759 | sas_address_parent); | |
5760 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
5761 | if (!sas_expander) { | |
5762 | rc = _scsih_expander_add(ioc, parent_handle); | |
5763 | if (rc != 0) | |
5764 | return rc; | |
5765 | } | |
5766 | } | |
5767 | ||
5768 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
5769 | sas_address = le64_to_cpu(expander_pg0.SASAddress); | |
5770 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, | |
5771 | sas_address); | |
5772 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
5773 | ||
5774 | if (sas_expander) | |
5775 | return 0; | |
5776 | ||
5777 | sas_expander = kzalloc(sizeof(struct _sas_node), | |
5778 | GFP_KERNEL); | |
5779 | if (!sas_expander) { | |
5780 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5781 | ioc->name, __FILE__, __LINE__, __func__); | |
5782 | return -1; | |
5783 | } | |
5784 | ||
5785 | sas_expander->handle = handle; | |
5786 | sas_expander->num_phys = expander_pg0.NumPhys; | |
5787 | sas_expander->sas_address_parent = sas_address_parent; | |
5788 | sas_expander->sas_address = sas_address; | |
5789 | ||
5790 | pr_info(MPT3SAS_FMT "expander_add: handle(0x%04x)," \ | |
5791 | " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name, | |
5792 | handle, parent_handle, (unsigned long long) | |
5793 | sas_expander->sas_address, sas_expander->num_phys); | |
5794 | ||
5795 | if (!sas_expander->num_phys) | |
5796 | goto out_fail; | |
5797 | sas_expander->phy = kcalloc(sas_expander->num_phys, | |
5798 | sizeof(struct _sas_phy), GFP_KERNEL); | |
5799 | if (!sas_expander->phy) { | |
5800 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5801 | ioc->name, __FILE__, __LINE__, __func__); | |
5802 | rc = -1; | |
5803 | goto out_fail; | |
5804 | } | |
5805 | ||
5806 | INIT_LIST_HEAD(&sas_expander->sas_port_list); | |
5807 | mpt3sas_port = mpt3sas_transport_port_add(ioc, handle, | |
5808 | sas_address_parent); | |
5809 | if (!mpt3sas_port) { | |
5810 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5811 | ioc->name, __FILE__, __LINE__, __func__); | |
5812 | rc = -1; | |
5813 | goto out_fail; | |
5814 | } | |
5815 | sas_expander->parent_dev = &mpt3sas_port->rphy->dev; | |
5816 | ||
5817 | for (i = 0 ; i < sas_expander->num_phys ; i++) { | |
5818 | if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply, | |
5819 | &expander_pg1, i, handle))) { | |
5820 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5821 | ioc->name, __FILE__, __LINE__, __func__); | |
5822 | rc = -1; | |
5823 | goto out_fail; | |
5824 | } | |
5825 | sas_expander->phy[i].handle = handle; | |
5826 | sas_expander->phy[i].phy_id = i; | |
5827 | ||
5828 | if ((mpt3sas_transport_add_expander_phy(ioc, | |
5829 | &sas_expander->phy[i], expander_pg1, | |
5830 | sas_expander->parent_dev))) { | |
5831 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5832 | ioc->name, __FILE__, __LINE__, __func__); | |
5833 | rc = -1; | |
5834 | goto out_fail; | |
5835 | } | |
5836 | } | |
5837 | ||
5838 | if (sas_expander->enclosure_handle) { | |
5839 | if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
5840 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
5841 | sas_expander->enclosure_handle))) | |
5842 | sas_expander->enclosure_logical_id = | |
5843 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
5844 | } | |
5845 | ||
5846 | _scsih_expander_node_add(ioc, sas_expander); | |
5847 | return 0; | |
5848 | ||
5849 | out_fail: | |
5850 | ||
5851 | if (mpt3sas_port) | |
5852 | mpt3sas_transport_port_remove(ioc, sas_expander->sas_address, | |
5853 | sas_address_parent); | |
5854 | kfree(sas_expander); | |
5855 | return rc; | |
5856 | } | |
5857 | ||
5858 | /** | |
5859 | * mpt3sas_expander_remove - removing expander object | |
5860 | * @ioc: per adapter object | |
5861 | * @sas_address: expander sas_address | |
5862 | * | |
5863 | * Return nothing. | |
5864 | */ | |
5865 | void | |
5866 | mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address) | |
5867 | { | |
5868 | struct _sas_node *sas_expander; | |
5869 | unsigned long flags; | |
5870 | ||
5871 | if (ioc->shost_recovery) | |
5872 | return; | |
5873 | ||
5874 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
5875 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, | |
5876 | sas_address); | |
f92363d1 SR |
5877 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
5878 | if (sas_expander) | |
5879 | _scsih_expander_node_remove(ioc, sas_expander); | |
5880 | } | |
5881 | ||
5882 | /** | |
5883 | * _scsih_done - internal SCSI_IO callback handler. | |
5884 | * @ioc: per adapter object | |
5885 | * @smid: system request message index | |
5886 | * @msix_index: MSIX table index supplied by the OS | |
5887 | * @reply: reply message frame(lower 32bit addr) | |
5888 | * | |
5889 | * Callback handler when sending internal generated SCSI_IO. | |
5890 | * The callback index passed is `ioc->scsih_cb_idx` | |
5891 | * | |
5892 | * Return 1 meaning mf should be freed from _base_interrupt | |
5893 | * 0 means the mf is freed from this function. | |
5894 | */ | |
5895 | static u8 | |
5896 | _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | |
5897 | { | |
5898 | MPI2DefaultReply_t *mpi_reply; | |
5899 | ||
5900 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
5901 | if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED) | |
5902 | return 1; | |
5903 | if (ioc->scsih_cmds.smid != smid) | |
5904 | return 1; | |
5905 | ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE; | |
5906 | if (mpi_reply) { | |
5907 | memcpy(ioc->scsih_cmds.reply, mpi_reply, | |
5908 | mpi_reply->MsgLength*4); | |
5909 | ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID; | |
5910 | } | |
5911 | ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING; | |
5912 | complete(&ioc->scsih_cmds.done); | |
5913 | return 1; | |
5914 | } | |
5915 | ||
5916 | ||
5917 | ||
5918 | ||
5919 | #define MPT3_MAX_LUNS (255) | |
5920 | ||
5921 | ||
5922 | /** | |
5923 | * _scsih_check_access_status - check access flags | |
5924 | * @ioc: per adapter object | |
5925 | * @sas_address: sas address | |
5926 | * @handle: sas device handle | |
5927 | * @access_flags: errors returned during discovery of the device | |
5928 | * | |
5929 | * Return 0 for success, else failure | |
5930 | */ | |
5931 | static u8 | |
5932 | _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address, | |
5933 | u16 handle, u8 access_status) | |
5934 | { | |
5935 | u8 rc = 1; | |
5936 | char *desc = NULL; | |
5937 | ||
5938 | switch (access_status) { | |
5939 | case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS: | |
5940 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION: | |
5941 | rc = 0; | |
5942 | break; | |
5943 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED: | |
5944 | desc = "sata capability failed"; | |
5945 | break; | |
5946 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT: | |
5947 | desc = "sata affiliation conflict"; | |
5948 | break; | |
5949 | case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE: | |
5950 | desc = "route not addressable"; | |
5951 | break; | |
5952 | case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE: | |
5953 | desc = "smp error not addressable"; | |
5954 | break; | |
5955 | case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED: | |
5956 | desc = "device blocked"; | |
5957 | break; | |
5958 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED: | |
5959 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN: | |
5960 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT: | |
5961 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG: | |
5962 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION: | |
5963 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER: | |
5964 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN: | |
5965 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN: | |
5966 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN: | |
5967 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION: | |
5968 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE: | |
5969 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX: | |
5970 | desc = "sata initialization failed"; | |
5971 | break; | |
5972 | default: | |
5973 | desc = "unknown"; | |
5974 | break; | |
5975 | } | |
5976 | ||
5977 | if (!rc) | |
5978 | return 0; | |
5979 | ||
5980 | pr_err(MPT3SAS_FMT | |
5981 | "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n", | |
5982 | ioc->name, desc, (unsigned long long)sas_address, handle); | |
5983 | return rc; | |
5984 | } | |
5985 | ||
aba5a85c SR |
5986 | /** |
5987 | * _scsih_get_enclosure_logicalid_chassis_slot - get device's | |
5988 | * EnclosureLogicalID and ChassisSlot information. | |
5989 | * @ioc: per adapter object | |
5990 | * @sas_device_pg0: SAS device page0 | |
5991 | * @sas_device: per sas device object | |
5992 | * | |
5993 | * Returns nothing. | |
5994 | */ | |
5995 | static void | |
5996 | _scsih_get_enclosure_logicalid_chassis_slot(struct MPT3SAS_ADAPTER *ioc, | |
5997 | Mpi2SasDevicePage0_t *sas_device_pg0, struct _sas_device *sas_device) | |
5998 | { | |
5999 | Mpi2ConfigReply_t mpi_reply; | |
6000 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
6001 | ||
6002 | if (!sas_device_pg0 || !sas_device) | |
6003 | return; | |
6004 | ||
6005 | sas_device->enclosure_handle = | |
6006 | le16_to_cpu(sas_device_pg0->EnclosureHandle); | |
6007 | sas_device->is_chassis_slot_valid = 0; | |
6008 | ||
6009 | if (!le16_to_cpu(sas_device_pg0->EnclosureHandle)) | |
6010 | return; | |
6011 | ||
6012 | if (mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
6013 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
6014 | le16_to_cpu(sas_device_pg0->EnclosureHandle))) { | |
6015 | pr_err(MPT3SAS_FMT | |
6016 | "Enclosure Pg0 read failed for handle(0x%04x)\n", | |
6017 | ioc->name, le16_to_cpu(sas_device_pg0->EnclosureHandle)); | |
6018 | return; | |
6019 | } | |
6020 | ||
6021 | sas_device->enclosure_logical_id = | |
6022 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
6023 | ||
6024 | if (le16_to_cpu(enclosure_pg0.Flags) & | |
6025 | MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) { | |
6026 | sas_device->is_chassis_slot_valid = 1; | |
6027 | sas_device->chassis_slot = enclosure_pg0.ChassisSlot; | |
6028 | } | |
6029 | } | |
6030 | ||
6031 | ||
f92363d1 SR |
6032 | /** |
6033 | * _scsih_check_device - checking device responsiveness | |
6034 | * @ioc: per adapter object | |
6035 | * @parent_sas_address: sas address of parent expander or sas host | |
6036 | * @handle: attached device handle | |
6037 | * @phy_numberv: phy number | |
6038 | * @link_rate: new link rate | |
6039 | * | |
6040 | * Returns nothing. | |
6041 | */ | |
6042 | static void | |
6043 | _scsih_check_device(struct MPT3SAS_ADAPTER *ioc, | |
6044 | u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate) | |
6045 | { | |
6046 | Mpi2ConfigReply_t mpi_reply; | |
6047 | Mpi2SasDevicePage0_t sas_device_pg0; | |
6048 | struct _sas_device *sas_device; | |
6049 | u32 ioc_status; | |
6050 | unsigned long flags; | |
6051 | u64 sas_address; | |
6052 | struct scsi_target *starget; | |
6053 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
6054 | u32 device_info; | |
6055 | ||
f92363d1 SR |
6056 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
6057 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) | |
6058 | return; | |
6059 | ||
6060 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
6061 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | |
6062 | return; | |
6063 | ||
6064 | /* wide port handling ~ we need only handle device once for the phy that | |
6065 | * is matched in sas device page zero | |
6066 | */ | |
6067 | if (phy_number != sas_device_pg0.PhyNum) | |
6068 | return; | |
6069 | ||
6070 | /* check if this is end device */ | |
6071 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | |
6072 | if (!(_scsih_is_end_device(device_info))) | |
6073 | return; | |
6074 | ||
6075 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
6076 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | |
d1cb5e49 | 6077 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 SR |
6078 | sas_address); |
6079 | ||
d1cb5e49 SR |
6080 | if (!sas_device) |
6081 | goto out_unlock; | |
f92363d1 SR |
6082 | |
6083 | if (unlikely(sas_device->handle != handle)) { | |
6084 | starget = sas_device->starget; | |
6085 | sas_target_priv_data = starget->hostdata; | |
6086 | starget_printk(KERN_INFO, starget, | |
6087 | "handle changed from(0x%04x) to (0x%04x)!!!\n", | |
6088 | sas_device->handle, handle); | |
6089 | sas_target_priv_data->handle = handle; | |
6090 | sas_device->handle = handle; | |
aa53bb89 | 6091 | if (le16_to_cpu(sas_device_pg0.Flags) & |
e6d45e3e SR |
6092 | MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) { |
6093 | sas_device->enclosure_level = | |
aa53bb89 | 6094 | sas_device_pg0.EnclosureLevel; |
310c8e40 CO |
6095 | memcpy(sas_device->connector_name, |
6096 | sas_device_pg0.ConnectorName, 4); | |
6097 | sas_device->connector_name[4] = '\0'; | |
e6d45e3e SR |
6098 | } else { |
6099 | sas_device->enclosure_level = 0; | |
6100 | sas_device->connector_name[0] = '\0'; | |
6101 | } | |
aba5a85c SR |
6102 | |
6103 | _scsih_get_enclosure_logicalid_chassis_slot(ioc, | |
6104 | &sas_device_pg0, sas_device); | |
f92363d1 SR |
6105 | } |
6106 | ||
6107 | /* check if device is present */ | |
6108 | if (!(le16_to_cpu(sas_device_pg0.Flags) & | |
6109 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { | |
6110 | pr_err(MPT3SAS_FMT | |
6111 | "device is not present handle(0x%04x), flags!!!\n", | |
6112 | ioc->name, handle); | |
d1cb5e49 | 6113 | goto out_unlock; |
f92363d1 SR |
6114 | } |
6115 | ||
6116 | /* check if there were any issues with discovery */ | |
6117 | if (_scsih_check_access_status(ioc, sas_address, handle, | |
d1cb5e49 SR |
6118 | sas_device_pg0.AccessStatus)) |
6119 | goto out_unlock; | |
f92363d1 SR |
6120 | |
6121 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
6122 | _scsih_ublock_io_device(ioc, sas_address); | |
6123 | ||
d1cb5e49 SR |
6124 | if (sas_device) |
6125 | sas_device_put(sas_device); | |
6126 | return; | |
6127 | ||
6128 | out_unlock: | |
6129 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
6130 | if (sas_device) | |
6131 | sas_device_put(sas_device); | |
f92363d1 SR |
6132 | } |
6133 | ||
6134 | /** | |
6135 | * _scsih_add_device - creating sas device object | |
6136 | * @ioc: per adapter object | |
6137 | * @handle: sas device handle | |
6138 | * @phy_num: phy number end device attached to | |
6139 | * @is_pd: is this hidden raid component | |
6140 | * | |
6141 | * Creating end device object, stored in ioc->sas_device_list. | |
6142 | * | |
6143 | * Returns 0 for success, non-zero for failure. | |
6144 | */ | |
6145 | static int | |
6146 | _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num, | |
6147 | u8 is_pd) | |
6148 | { | |
6149 | Mpi2ConfigReply_t mpi_reply; | |
6150 | Mpi2SasDevicePage0_t sas_device_pg0; | |
6151 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
6152 | struct _sas_device *sas_device; | |
6153 | u32 ioc_status; | |
6154 | u64 sas_address; | |
6155 | u32 device_info; | |
75888956 | 6156 | int encl_pg0_rc = -1; |
f92363d1 SR |
6157 | |
6158 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
6159 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
6160 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6161 | ioc->name, __FILE__, __LINE__, __func__); | |
6162 | return -1; | |
6163 | } | |
6164 | ||
6165 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6166 | MPI2_IOCSTATUS_MASK; | |
6167 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
6168 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6169 | ioc->name, __FILE__, __LINE__, __func__); | |
6170 | return -1; | |
6171 | } | |
6172 | ||
6173 | /* check if this is end device */ | |
6174 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | |
6175 | if (!(_scsih_is_end_device(device_info))) | |
6176 | return -1; | |
c696f7b8 | 6177 | set_bit(handle, ioc->pend_os_device_add); |
f92363d1 SR |
6178 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
6179 | ||
6180 | /* check if device is present */ | |
6181 | if (!(le16_to_cpu(sas_device_pg0.Flags) & | |
6182 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { | |
6183 | pr_err(MPT3SAS_FMT "device is not present handle(0x04%x)!!!\n", | |
6184 | ioc->name, handle); | |
6185 | return -1; | |
6186 | } | |
6187 | ||
6188 | /* check if there were any issues with discovery */ | |
6189 | if (_scsih_check_access_status(ioc, sas_address, handle, | |
6190 | sas_device_pg0.AccessStatus)) | |
6191 | return -1; | |
6192 | ||
d1cb5e49 SR |
6193 | sas_device = mpt3sas_get_sdev_by_addr(ioc, |
6194 | sas_address); | |
6195 | if (sas_device) { | |
c696f7b8 | 6196 | clear_bit(handle, ioc->pend_os_device_add); |
d1cb5e49 | 6197 | sas_device_put(sas_device); |
f92363d1 | 6198 | return -1; |
d1cb5e49 | 6199 | } |
f92363d1 | 6200 | |
75888956 SR |
6201 | if (sas_device_pg0.EnclosureHandle) { |
6202 | encl_pg0_rc = mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
6203 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
6204 | sas_device_pg0.EnclosureHandle); | |
6205 | if (encl_pg0_rc) | |
6206 | pr_info(MPT3SAS_FMT | |
6207 | "Enclosure Pg0 read failed for handle(0x%04x)\n", | |
6208 | ioc->name, sas_device_pg0.EnclosureHandle); | |
6209 | } | |
6210 | ||
f92363d1 SR |
6211 | sas_device = kzalloc(sizeof(struct _sas_device), |
6212 | GFP_KERNEL); | |
6213 | if (!sas_device) { | |
6214 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6215 | ioc->name, __FILE__, __LINE__, __func__); | |
6216 | return 0; | |
6217 | } | |
6218 | ||
d1cb5e49 | 6219 | kref_init(&sas_device->refcount); |
f92363d1 SR |
6220 | sas_device->handle = handle; |
6221 | if (_scsih_get_sas_address(ioc, | |
6222 | le16_to_cpu(sas_device_pg0.ParentDevHandle), | |
6223 | &sas_device->sas_address_parent) != 0) | |
6224 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6225 | ioc->name, __FILE__, __LINE__, __func__); | |
6226 | sas_device->enclosure_handle = | |
6227 | le16_to_cpu(sas_device_pg0.EnclosureHandle); | |
e6d45e3e SR |
6228 | if (sas_device->enclosure_handle != 0) |
6229 | sas_device->slot = | |
6230 | le16_to_cpu(sas_device_pg0.Slot); | |
f92363d1 SR |
6231 | sas_device->device_info = device_info; |
6232 | sas_device->sas_address = sas_address; | |
6233 | sas_device->phy = sas_device_pg0.PhyNum; | |
6234 | sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) & | |
6235 | MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0; | |
6236 | ||
aa53bb89 SPS |
6237 | if (le16_to_cpu(sas_device_pg0.Flags) |
6238 | & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) { | |
e6d45e3e | 6239 | sas_device->enclosure_level = |
aa53bb89 | 6240 | sas_device_pg0.EnclosureLevel; |
310c8e40 CO |
6241 | memcpy(sas_device->connector_name, |
6242 | sas_device_pg0.ConnectorName, 4); | |
6243 | sas_device->connector_name[4] = '\0'; | |
e6d45e3e SR |
6244 | } else { |
6245 | sas_device->enclosure_level = 0; | |
6246 | sas_device->connector_name[0] = '\0'; | |
6247 | } | |
75888956 SR |
6248 | |
6249 | /* get enclosure_logical_id & chassis_slot */ | |
6250 | sas_device->is_chassis_slot_valid = 0; | |
6251 | if (encl_pg0_rc == 0) { | |
f92363d1 SR |
6252 | sas_device->enclosure_logical_id = |
6253 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
6254 | ||
75888956 SR |
6255 | if (le16_to_cpu(enclosure_pg0.Flags) & |
6256 | MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) { | |
6257 | sas_device->is_chassis_slot_valid = 1; | |
6258 | sas_device->chassis_slot = | |
6259 | enclosure_pg0.ChassisSlot; | |
6260 | } | |
6261 | } | |
6262 | ||
f92363d1 SR |
6263 | /* get device name */ |
6264 | sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName); | |
6265 | ||
6266 | if (ioc->wait_for_discovery_to_complete) | |
6267 | _scsih_sas_device_init_add(ioc, sas_device); | |
6268 | else | |
6269 | _scsih_sas_device_add(ioc, sas_device); | |
6270 | ||
d1cb5e49 | 6271 | sas_device_put(sas_device); |
f92363d1 SR |
6272 | return 0; |
6273 | } | |
6274 | ||
6275 | /** | |
6276 | * _scsih_remove_device - removing sas device object | |
6277 | * @ioc: per adapter object | |
6278 | * @sas_device_delete: the sas_device object | |
6279 | * | |
6280 | * Return nothing. | |
6281 | */ | |
6282 | static void | |
6283 | _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc, | |
6284 | struct _sas_device *sas_device) | |
6285 | { | |
6286 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
6287 | ||
0f624c39 SR |
6288 | if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) && |
6289 | (sas_device->pfa_led_on)) { | |
6290 | _scsih_turn_off_pfa_led(ioc, sas_device); | |
6291 | sas_device->pfa_led_on = 0; | |
6292 | } | |
75888956 | 6293 | |
f92363d1 SR |
6294 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
6295 | "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n", | |
6296 | ioc->name, __func__, | |
6297 | sas_device->handle, (unsigned long long) | |
6298 | sas_device->sas_address)); | |
75888956 SR |
6299 | |
6300 | dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device, | |
6301 | NULL, NULL)); | |
f92363d1 SR |
6302 | |
6303 | if (sas_device->starget && sas_device->starget->hostdata) { | |
6304 | sas_target_priv_data = sas_device->starget->hostdata; | |
6305 | sas_target_priv_data->deleted = 1; | |
6306 | _scsih_ublock_io_device(ioc, sas_device->sas_address); | |
6307 | sas_target_priv_data->handle = | |
6308 | MPT3SAS_INVALID_DEVICE_HANDLE; | |
6309 | } | |
7786ab6a SR |
6310 | |
6311 | if (!ioc->hide_drives) | |
6312 | mpt3sas_transport_port_remove(ioc, | |
f92363d1 SR |
6313 | sas_device->sas_address, |
6314 | sas_device->sas_address_parent); | |
6315 | ||
6316 | pr_info(MPT3SAS_FMT | |
6317 | "removing handle(0x%04x), sas_addr(0x%016llx)\n", | |
6318 | ioc->name, sas_device->handle, | |
6319 | (unsigned long long) sas_device->sas_address); | |
75888956 SR |
6320 | |
6321 | _scsih_display_enclosure_chassis_info(ioc, sas_device, NULL, NULL); | |
f92363d1 SR |
6322 | |
6323 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6324 | "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n", | |
6325 | ioc->name, __func__, | |
e6d45e3e SR |
6326 | sas_device->handle, (unsigned long long) |
6327 | sas_device->sas_address)); | |
75888956 SR |
6328 | dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device, |
6329 | NULL, NULL)); | |
f92363d1 SR |
6330 | } |
6331 | ||
f92363d1 SR |
6332 | /** |
6333 | * _scsih_sas_topology_change_event_debug - debug for topology event | |
6334 | * @ioc: per adapter object | |
6335 | * @event_data: event data payload | |
6336 | * Context: user. | |
6337 | */ | |
6338 | static void | |
6339 | _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
6340 | Mpi2EventDataSasTopologyChangeList_t *event_data) | |
6341 | { | |
6342 | int i; | |
6343 | u16 handle; | |
6344 | u16 reason_code; | |
6345 | u8 phy_number; | |
6346 | char *status_str = NULL; | |
6347 | u8 link_rate, prev_link_rate; | |
6348 | ||
6349 | switch (event_data->ExpStatus) { | |
6350 | case MPI2_EVENT_SAS_TOPO_ES_ADDED: | |
6351 | status_str = "add"; | |
6352 | break; | |
6353 | case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING: | |
6354 | status_str = "remove"; | |
6355 | break; | |
6356 | case MPI2_EVENT_SAS_TOPO_ES_RESPONDING: | |
6357 | case 0: | |
6358 | status_str = "responding"; | |
6359 | break; | |
6360 | case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING: | |
6361 | status_str = "remove delay"; | |
6362 | break; | |
6363 | default: | |
6364 | status_str = "unknown status"; | |
6365 | break; | |
6366 | } | |
6367 | pr_info(MPT3SAS_FMT "sas topology change: (%s)\n", | |
6368 | ioc->name, status_str); | |
6369 | pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \ | |
6370 | "start_phy(%02d), count(%d)\n", | |
6371 | le16_to_cpu(event_data->ExpanderDevHandle), | |
6372 | le16_to_cpu(event_data->EnclosureHandle), | |
6373 | event_data->StartPhyNum, event_data->NumEntries); | |
6374 | for (i = 0; i < event_data->NumEntries; i++) { | |
6375 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
6376 | if (!handle) | |
6377 | continue; | |
6378 | phy_number = event_data->StartPhyNum + i; | |
6379 | reason_code = event_data->PHY[i].PhyStatus & | |
6380 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
6381 | switch (reason_code) { | |
6382 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: | |
6383 | status_str = "target add"; | |
6384 | break; | |
6385 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: | |
6386 | status_str = "target remove"; | |
6387 | break; | |
6388 | case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING: | |
6389 | status_str = "delay target remove"; | |
6390 | break; | |
6391 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: | |
6392 | status_str = "link rate change"; | |
6393 | break; | |
6394 | case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE: | |
6395 | status_str = "target responding"; | |
6396 | break; | |
6397 | default: | |
6398 | status_str = "unknown"; | |
6399 | break; | |
6400 | } | |
6401 | link_rate = event_data->PHY[i].LinkRate >> 4; | |
6402 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; | |
6403 | pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \ | |
6404 | " link rate: new(0x%02x), old(0x%02x)\n", phy_number, | |
6405 | handle, status_str, link_rate, prev_link_rate); | |
6406 | ||
6407 | } | |
6408 | } | |
f92363d1 SR |
6409 | |
6410 | /** | |
6411 | * _scsih_sas_topology_change_event - handle topology changes | |
6412 | * @ioc: per adapter object | |
6413 | * @fw_event: The fw_event_work object | |
6414 | * Context: user. | |
6415 | * | |
6416 | */ | |
6417 | static int | |
6418 | _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc, | |
6419 | struct fw_event_work *fw_event) | |
6420 | { | |
6421 | int i; | |
6422 | u16 parent_handle, handle; | |
6423 | u16 reason_code; | |
6424 | u8 phy_number, max_phys; | |
6425 | struct _sas_node *sas_expander; | |
6426 | u64 sas_address; | |
6427 | unsigned long flags; | |
6428 | u8 link_rate, prev_link_rate; | |
35b62362 JL |
6429 | Mpi2EventDataSasTopologyChangeList_t *event_data = |
6430 | (Mpi2EventDataSasTopologyChangeList_t *) | |
6431 | fw_event->event_data; | |
f92363d1 | 6432 | |
f92363d1 SR |
6433 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
6434 | _scsih_sas_topology_change_event_debug(ioc, event_data); | |
f92363d1 SR |
6435 | |
6436 | if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery) | |
6437 | return 0; | |
6438 | ||
6439 | if (!ioc->sas_hba.num_phys) | |
6440 | _scsih_sas_host_add(ioc); | |
6441 | else | |
6442 | _scsih_sas_host_refresh(ioc); | |
6443 | ||
6444 | if (fw_event->ignore) { | |
6445 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6446 | "ignoring expander event\n", ioc->name)); | |
6447 | return 0; | |
6448 | } | |
6449 | ||
6450 | parent_handle = le16_to_cpu(event_data->ExpanderDevHandle); | |
6451 | ||
6452 | /* handle expander add */ | |
6453 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED) | |
6454 | if (_scsih_expander_add(ioc, parent_handle) != 0) | |
6455 | return 0; | |
6456 | ||
6457 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
6458 | sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc, | |
6459 | parent_handle); | |
6460 | if (sas_expander) { | |
6461 | sas_address = sas_expander->sas_address; | |
6462 | max_phys = sas_expander->num_phys; | |
6463 | } else if (parent_handle < ioc->sas_hba.num_phys) { | |
6464 | sas_address = ioc->sas_hba.sas_address; | |
6465 | max_phys = ioc->sas_hba.num_phys; | |
6466 | } else { | |
6467 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
6468 | return 0; | |
6469 | } | |
6470 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
6471 | ||
6472 | /* handle siblings events */ | |
6473 | for (i = 0; i < event_data->NumEntries; i++) { | |
6474 | if (fw_event->ignore) { | |
6475 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6476 | "ignoring expander event\n", ioc->name)); | |
6477 | return 0; | |
6478 | } | |
6479 | if (ioc->remove_host || ioc->pci_error_recovery) | |
6480 | return 0; | |
6481 | phy_number = event_data->StartPhyNum + i; | |
6482 | if (phy_number >= max_phys) | |
6483 | continue; | |
6484 | reason_code = event_data->PHY[i].PhyStatus & | |
6485 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
6486 | if ((event_data->PHY[i].PhyStatus & | |
6487 | MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code != | |
6488 | MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)) | |
6489 | continue; | |
6490 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
6491 | if (!handle) | |
6492 | continue; | |
6493 | link_rate = event_data->PHY[i].LinkRate >> 4; | |
6494 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; | |
6495 | switch (reason_code) { | |
6496 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: | |
6497 | ||
6498 | if (ioc->shost_recovery) | |
6499 | break; | |
6500 | ||
6501 | if (link_rate == prev_link_rate) | |
6502 | break; | |
6503 | ||
6504 | mpt3sas_transport_update_links(ioc, sas_address, | |
6505 | handle, phy_number, link_rate); | |
6506 | ||
6507 | if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) | |
6508 | break; | |
6509 | ||
6510 | _scsih_check_device(ioc, sas_address, handle, | |
6511 | phy_number, link_rate); | |
6512 | ||
c696f7b8 SPS |
6513 | if (!test_bit(handle, ioc->pend_os_device_add)) |
6514 | break; | |
6515 | ||
f92363d1 SR |
6516 | |
6517 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: | |
6518 | ||
6519 | if (ioc->shost_recovery) | |
6520 | break; | |
6521 | ||
6522 | mpt3sas_transport_update_links(ioc, sas_address, | |
6523 | handle, phy_number, link_rate); | |
6524 | ||
6525 | _scsih_add_device(ioc, handle, phy_number, 0); | |
6526 | ||
6527 | break; | |
6528 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: | |
6529 | ||
6530 | _scsih_device_remove_by_handle(ioc, handle); | |
6531 | break; | |
6532 | } | |
6533 | } | |
6534 | ||
6535 | /* handle expander removal */ | |
6536 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING && | |
6537 | sas_expander) | |
6538 | mpt3sas_expander_remove(ioc, sas_address); | |
6539 | ||
6540 | return 0; | |
6541 | } | |
6542 | ||
f92363d1 SR |
6543 | /** |
6544 | * _scsih_sas_device_status_change_event_debug - debug for device event | |
6545 | * @event_data: event data payload | |
6546 | * Context: user. | |
6547 | * | |
6548 | * Return nothing. | |
6549 | */ | |
6550 | static void | |
6551 | _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
6552 | Mpi2EventDataSasDeviceStatusChange_t *event_data) | |
6553 | { | |
6554 | char *reason_str = NULL; | |
6555 | ||
6556 | switch (event_data->ReasonCode) { | |
6557 | case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA: | |
6558 | reason_str = "smart data"; | |
6559 | break; | |
6560 | case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED: | |
6561 | reason_str = "unsupported device discovered"; | |
6562 | break; | |
6563 | case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET: | |
6564 | reason_str = "internal device reset"; | |
6565 | break; | |
6566 | case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL: | |
6567 | reason_str = "internal task abort"; | |
6568 | break; | |
6569 | case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL: | |
6570 | reason_str = "internal task abort set"; | |
6571 | break; | |
6572 | case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL: | |
6573 | reason_str = "internal clear task set"; | |
6574 | break; | |
6575 | case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL: | |
6576 | reason_str = "internal query task"; | |
6577 | break; | |
6578 | case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE: | |
6579 | reason_str = "sata init failure"; | |
6580 | break; | |
6581 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET: | |
6582 | reason_str = "internal device reset complete"; | |
6583 | break; | |
6584 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL: | |
6585 | reason_str = "internal task abort complete"; | |
6586 | break; | |
6587 | case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION: | |
6588 | reason_str = "internal async notification"; | |
6589 | break; | |
6590 | case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY: | |
6591 | reason_str = "expander reduced functionality"; | |
6592 | break; | |
6593 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY: | |
6594 | reason_str = "expander reduced functionality complete"; | |
6595 | break; | |
6596 | default: | |
6597 | reason_str = "unknown reason"; | |
6598 | break; | |
6599 | } | |
6600 | pr_info(MPT3SAS_FMT "device status change: (%s)\n" | |
6601 | "\thandle(0x%04x), sas address(0x%016llx), tag(%d)", | |
6602 | ioc->name, reason_str, le16_to_cpu(event_data->DevHandle), | |
6603 | (unsigned long long)le64_to_cpu(event_data->SASAddress), | |
6604 | le16_to_cpu(event_data->TaskTag)); | |
6605 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA) | |
6606 | pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name, | |
6607 | event_data->ASC, event_data->ASCQ); | |
6608 | pr_info("\n"); | |
6609 | } | |
f92363d1 SR |
6610 | |
6611 | /** | |
6612 | * _scsih_sas_device_status_change_event - handle device status change | |
6613 | * @ioc: per adapter object | |
6614 | * @fw_event: The fw_event_work object | |
6615 | * Context: user. | |
6616 | * | |
6617 | * Return nothing. | |
6618 | */ | |
6619 | static void | |
6620 | _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc, | |
6621 | struct fw_event_work *fw_event) | |
6622 | { | |
6623 | struct MPT3SAS_TARGET *target_priv_data; | |
6624 | struct _sas_device *sas_device; | |
6625 | u64 sas_address; | |
6626 | unsigned long flags; | |
6627 | Mpi2EventDataSasDeviceStatusChange_t *event_data = | |
35b62362 JL |
6628 | (Mpi2EventDataSasDeviceStatusChange_t *) |
6629 | fw_event->event_data; | |
f92363d1 | 6630 | |
f92363d1 SR |
6631 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
6632 | _scsih_sas_device_status_change_event_debug(ioc, | |
6633 | event_data); | |
f92363d1 SR |
6634 | |
6635 | /* In MPI Revision K (0xC), the internal device reset complete was | |
6636 | * implemented, so avoid setting tm_busy flag for older firmware. | |
6637 | */ | |
6638 | if ((ioc->facts.HeaderVersion >> 8) < 0xC) | |
6639 | return; | |
6640 | ||
6641 | if (event_data->ReasonCode != | |
6642 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET && | |
6643 | event_data->ReasonCode != | |
6644 | MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET) | |
6645 | return; | |
6646 | ||
6647 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
6648 | sas_address = le64_to_cpu(event_data->SASAddress); | |
d1cb5e49 | 6649 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 SR |
6650 | sas_address); |
6651 | ||
d1cb5e49 SR |
6652 | if (!sas_device || !sas_device->starget) |
6653 | goto out; | |
f92363d1 SR |
6654 | |
6655 | target_priv_data = sas_device->starget->hostdata; | |
d1cb5e49 SR |
6656 | if (!target_priv_data) |
6657 | goto out; | |
f92363d1 SR |
6658 | |
6659 | if (event_data->ReasonCode == | |
6660 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET) | |
6661 | target_priv_data->tm_busy = 1; | |
6662 | else | |
6663 | target_priv_data->tm_busy = 0; | |
d1cb5e49 SR |
6664 | |
6665 | out: | |
6666 | if (sas_device) | |
6667 | sas_device_put(sas_device); | |
6668 | ||
f92363d1 SR |
6669 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
6670 | } | |
6671 | ||
4318c734 | 6672 | |
c102e00c SPS |
6673 | /** |
6674 | * _scsih_check_pcie_access_status - check access flags | |
6675 | * @ioc: per adapter object | |
6676 | * @wwid: wwid | |
6677 | * @handle: sas device handle | |
6678 | * @access_flags: errors returned during discovery of the device | |
6679 | * | |
6680 | * Return 0 for success, else failure | |
6681 | */ | |
6682 | static u8 | |
6683 | _scsih_check_pcie_access_status(struct MPT3SAS_ADAPTER *ioc, u64 wwid, | |
6684 | u16 handle, u8 access_status) | |
6685 | { | |
6686 | u8 rc = 1; | |
6687 | char *desc = NULL; | |
6688 | ||
6689 | switch (access_status) { | |
6690 | case MPI26_PCIEDEV0_ASTATUS_NO_ERRORS: | |
6691 | case MPI26_PCIEDEV0_ASTATUS_NEEDS_INITIALIZATION: | |
6692 | rc = 0; | |
6693 | break; | |
6694 | case MPI26_PCIEDEV0_ASTATUS_CAPABILITY_FAILED: | |
6695 | desc = "PCIe device capability failed"; | |
6696 | break; | |
6697 | case MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED: | |
6698 | desc = "PCIe device blocked"; | |
6699 | break; | |
6700 | case MPI26_PCIEDEV0_ASTATUS_MEMORY_SPACE_ACCESS_FAILED: | |
6701 | desc = "PCIe device mem space access failed"; | |
6702 | break; | |
6703 | case MPI26_PCIEDEV0_ASTATUS_UNSUPPORTED_DEVICE: | |
6704 | desc = "PCIe device unsupported"; | |
6705 | break; | |
6706 | case MPI26_PCIEDEV0_ASTATUS_MSIX_REQUIRED: | |
6707 | desc = "PCIe device MSIx Required"; | |
6708 | break; | |
6709 | case MPI26_PCIEDEV0_ASTATUS_INIT_FAIL_MAX: | |
6710 | desc = "PCIe device init fail max"; | |
6711 | break; | |
6712 | case MPI26_PCIEDEV0_ASTATUS_UNKNOWN: | |
6713 | desc = "PCIe device status unknown"; | |
6714 | break; | |
6715 | case MPI26_PCIEDEV0_ASTATUS_NVME_READY_TIMEOUT: | |
6716 | desc = "nvme ready timeout"; | |
6717 | break; | |
6718 | case MPI26_PCIEDEV0_ASTATUS_NVME_DEVCFG_UNSUPPORTED: | |
6719 | desc = "nvme device configuration unsupported"; | |
6720 | break; | |
6721 | case MPI26_PCIEDEV0_ASTATUS_NVME_IDENTIFY_FAILED: | |
6722 | desc = "nvme identify failed"; | |
6723 | break; | |
6724 | case MPI26_PCIEDEV0_ASTATUS_NVME_QCONFIG_FAILED: | |
6725 | desc = "nvme qconfig failed"; | |
6726 | break; | |
6727 | case MPI26_PCIEDEV0_ASTATUS_NVME_QCREATION_FAILED: | |
6728 | desc = "nvme qcreation failed"; | |
6729 | break; | |
6730 | case MPI26_PCIEDEV0_ASTATUS_NVME_EVENTCFG_FAILED: | |
6731 | desc = "nvme eventcfg failed"; | |
6732 | break; | |
6733 | case MPI26_PCIEDEV0_ASTATUS_NVME_GET_FEATURE_STAT_FAILED: | |
6734 | desc = "nvme get feature stat failed"; | |
6735 | break; | |
6736 | case MPI26_PCIEDEV0_ASTATUS_NVME_IDLE_TIMEOUT: | |
6737 | desc = "nvme idle timeout"; | |
6738 | break; | |
6739 | case MPI26_PCIEDEV0_ASTATUS_NVME_FAILURE_STATUS: | |
6740 | desc = "nvme failure status"; | |
6741 | break; | |
6742 | default: | |
6743 | pr_err(MPT3SAS_FMT | |
6744 | " NVMe discovery error(0x%02x): wwid(0x%016llx)," | |
6745 | "handle(0x%04x)\n", ioc->name, access_status, | |
6746 | (unsigned long long)wwid, handle); | |
6747 | return rc; | |
6748 | } | |
6749 | ||
6750 | if (!rc) | |
6751 | return rc; | |
6752 | ||
6753 | pr_info(MPT3SAS_FMT | |
6754 | "NVMe discovery error(%s): wwid(0x%016llx), handle(0x%04x)\n", | |
6755 | ioc->name, desc, | |
6756 | (unsigned long long)wwid, handle); | |
6757 | return rc; | |
6758 | } | |
3075ac49 SPS |
6759 | |
6760 | /** | |
6761 | * _scsih_pcie_device_remove_from_sml - removing pcie device | |
6762 | * from SML and free up associated memory | |
6763 | * @ioc: per adapter object | |
6764 | * @pcie_device: the pcie_device object | |
6765 | * | |
6766 | * Return nothing. | |
6767 | */ | |
6768 | static void | |
6769 | _scsih_pcie_device_remove_from_sml(struct MPT3SAS_ADAPTER *ioc, | |
6770 | struct _pcie_device *pcie_device) | |
6771 | { | |
6772 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
6773 | ||
6774 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6775 | "%s: enter: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__, | |
6776 | pcie_device->handle, (unsigned long long) | |
6777 | pcie_device->wwid)); | |
6778 | if (pcie_device->enclosure_handle != 0) | |
6779 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6780 | "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n", | |
6781 | ioc->name, __func__, | |
6782 | (unsigned long long)pcie_device->enclosure_logical_id, | |
6783 | pcie_device->slot)); | |
6784 | if (pcie_device->connector_name[0] != '\0') | |
6785 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6786 | "%s: enter: enclosure level(0x%04x), connector name( %s)\n", | |
6787 | ioc->name, __func__, | |
6788 | pcie_device->enclosure_level, | |
6789 | pcie_device->connector_name)); | |
6790 | ||
6791 | if (pcie_device->starget && pcie_device->starget->hostdata) { | |
6792 | sas_target_priv_data = pcie_device->starget->hostdata; | |
6793 | sas_target_priv_data->deleted = 1; | |
6794 | _scsih_ublock_io_device(ioc, pcie_device->wwid); | |
6795 | sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE; | |
6796 | } | |
6797 | ||
6798 | pr_info(MPT3SAS_FMT | |
6799 | "removing handle(0x%04x), wwid (0x%016llx)\n", | |
6800 | ioc->name, pcie_device->handle, | |
6801 | (unsigned long long) pcie_device->wwid); | |
6802 | if (pcie_device->enclosure_handle != 0) | |
6803 | pr_info(MPT3SAS_FMT | |
6804 | "removing : enclosure logical id(0x%016llx), slot(%d)\n", | |
6805 | ioc->name, | |
6806 | (unsigned long long)pcie_device->enclosure_logical_id, | |
6807 | pcie_device->slot); | |
6808 | if (pcie_device->connector_name[0] != '\0') | |
6809 | pr_info(MPT3SAS_FMT | |
6810 | "removing: enclosure level(0x%04x), connector name( %s)\n", | |
6811 | ioc->name, pcie_device->enclosure_level, | |
6812 | pcie_device->connector_name); | |
6813 | ||
6814 | if (pcie_device->starget) | |
6815 | scsi_remove_target(&pcie_device->starget->dev); | |
6816 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6817 | "%s: exit: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__, | |
6818 | pcie_device->handle, (unsigned long long) | |
6819 | pcie_device->wwid)); | |
6820 | if (pcie_device->enclosure_handle != 0) | |
6821 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6822 | "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n", | |
6823 | ioc->name, __func__, | |
6824 | (unsigned long long)pcie_device->enclosure_logical_id, | |
6825 | pcie_device->slot)); | |
6826 | if (pcie_device->connector_name[0] != '\0') | |
6827 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6828 | "%s: exit: enclosure level(0x%04x), connector name( %s)\n", | |
6829 | ioc->name, __func__, pcie_device->enclosure_level, | |
6830 | pcie_device->connector_name)); | |
6831 | ||
6832 | kfree(pcie_device->serial_number); | |
6833 | } | |
6834 | ||
6835 | ||
c102e00c SPS |
6836 | /** |
6837 | * _scsih_pcie_check_device - checking device responsiveness | |
6838 | * @ioc: per adapter object | |
6839 | * @handle: attached device handle | |
6840 | * | |
6841 | * Returns nothing. | |
6842 | */ | |
6843 | static void | |
6844 | _scsih_pcie_check_device(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
6845 | { | |
6846 | Mpi2ConfigReply_t mpi_reply; | |
6847 | Mpi26PCIeDevicePage0_t pcie_device_pg0; | |
6848 | u32 ioc_status; | |
6849 | struct _pcie_device *pcie_device; | |
6850 | u64 wwid; | |
6851 | unsigned long flags; | |
6852 | struct scsi_target *starget; | |
6853 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
6854 | u32 device_info; | |
6855 | ||
6856 | if ((mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply, | |
6857 | &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE, handle))) | |
6858 | return; | |
6859 | ||
6860 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
6861 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | |
6862 | return; | |
6863 | ||
6864 | /* check if this is end device */ | |
6865 | device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo); | |
6866 | if (!(_scsih_is_nvme_device(device_info))) | |
6867 | return; | |
6868 | ||
6869 | wwid = le64_to_cpu(pcie_device_pg0.WWID); | |
6870 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
6871 | pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid); | |
6872 | ||
6873 | if (!pcie_device) { | |
6874 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
6875 | return; | |
6876 | } | |
6877 | ||
6878 | if (unlikely(pcie_device->handle != handle)) { | |
6879 | starget = pcie_device->starget; | |
6880 | sas_target_priv_data = starget->hostdata; | |
6881 | starget_printk(KERN_INFO, starget, | |
6882 | "handle changed from(0x%04x) to (0x%04x)!!!\n", | |
6883 | pcie_device->handle, handle); | |
6884 | sas_target_priv_data->handle = handle; | |
6885 | pcie_device->handle = handle; | |
6886 | ||
6887 | if (le32_to_cpu(pcie_device_pg0.Flags) & | |
6888 | MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) { | |
6889 | pcie_device->enclosure_level = | |
6890 | pcie_device_pg0.EnclosureLevel; | |
6891 | memcpy(&pcie_device->connector_name[0], | |
6892 | &pcie_device_pg0.ConnectorName[0], 4); | |
6893 | } else { | |
6894 | pcie_device->enclosure_level = 0; | |
6895 | pcie_device->connector_name[0] = '\0'; | |
6896 | } | |
6897 | } | |
6898 | ||
6899 | /* check if device is present */ | |
6900 | if (!(le32_to_cpu(pcie_device_pg0.Flags) & | |
6901 | MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT)) { | |
6902 | pr_info(MPT3SAS_FMT | |
6903 | "device is not present handle(0x%04x), flags!!!\n", | |
6904 | ioc->name, handle); | |
6905 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
6906 | pcie_device_put(pcie_device); | |
6907 | return; | |
6908 | } | |
6909 | ||
6910 | /* check if there were any issues with discovery */ | |
6911 | if (_scsih_check_pcie_access_status(ioc, wwid, handle, | |
6912 | pcie_device_pg0.AccessStatus)) { | |
6913 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
6914 | pcie_device_put(pcie_device); | |
6915 | return; | |
6916 | } | |
6917 | ||
6918 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
6919 | pcie_device_put(pcie_device); | |
6920 | ||
6921 | _scsih_ublock_io_device(ioc, wwid); | |
6922 | ||
6923 | return; | |
6924 | } | |
6925 | ||
6926 | /** | |
6927 | * _scsih_pcie_add_device - creating pcie device object | |
6928 | * @ioc: per adapter object | |
6929 | * @handle: pcie device handle | |
6930 | * | |
6931 | * Creating end device object, stored in ioc->pcie_device_list. | |
6932 | * | |
6933 | * Return 1 means queue the event later, 0 means complete the event | |
6934 | */ | |
6935 | static int | |
6936 | _scsih_pcie_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
6937 | { | |
6938 | Mpi26PCIeDevicePage0_t pcie_device_pg0; | |
6939 | Mpi26PCIeDevicePage2_t pcie_device_pg2; | |
6940 | Mpi2ConfigReply_t mpi_reply; | |
6941 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
6942 | struct _pcie_device *pcie_device; | |
6943 | u32 pcie_device_type; | |
6944 | u32 ioc_status; | |
6945 | u64 wwid; | |
6946 | ||
6947 | if ((mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply, | |
6948 | &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
6949 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6950 | ioc->name, __FILE__, __LINE__, __func__); | |
6951 | return 0; | |
6952 | } | |
6953 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6954 | MPI2_IOCSTATUS_MASK; | |
6955 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
6956 | pr_err(MPT3SAS_FMT | |
6957 | "failure at %s:%d/%s()!\n", | |
6958 | ioc->name, __FILE__, __LINE__, __func__); | |
6959 | return 0; | |
6960 | } | |
6961 | ||
6962 | set_bit(handle, ioc->pend_os_device_add); | |
6963 | wwid = le64_to_cpu(pcie_device_pg0.WWID); | |
6964 | ||
6965 | /* check if device is present */ | |
6966 | if (!(le32_to_cpu(pcie_device_pg0.Flags) & | |
6967 | MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT)) { | |
6968 | pr_err(MPT3SAS_FMT | |
6969 | "device is not present handle(0x04%x)!!!\n", | |
6970 | ioc->name, handle); | |
6971 | return 0; | |
6972 | } | |
6973 | ||
6974 | /* check if there were any issues with discovery */ | |
6975 | if (_scsih_check_pcie_access_status(ioc, wwid, handle, | |
6976 | pcie_device_pg0.AccessStatus)) | |
6977 | return 0; | |
6978 | ||
6979 | if (!(_scsih_is_nvme_device(le32_to_cpu(pcie_device_pg0.DeviceInfo)))) | |
6980 | return 0; | |
6981 | ||
6982 | pcie_device = mpt3sas_get_pdev_by_wwid(ioc, wwid); | |
6983 | if (pcie_device) { | |
6984 | clear_bit(handle, ioc->pend_os_device_add); | |
6985 | pcie_device_put(pcie_device); | |
6986 | return 0; | |
6987 | } | |
6988 | ||
6989 | pcie_device = kzalloc(sizeof(struct _pcie_device), GFP_KERNEL); | |
6990 | if (!pcie_device) { | |
6991 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6992 | ioc->name, __FILE__, __LINE__, __func__); | |
6993 | return 0; | |
6994 | } | |
6995 | ||
6996 | kref_init(&pcie_device->refcount); | |
6997 | pcie_device->id = ioc->pcie_target_id++; | |
6998 | pcie_device->channel = PCIE_CHANNEL; | |
6999 | pcie_device->handle = handle; | |
7000 | pcie_device->device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo); | |
7001 | pcie_device->wwid = wwid; | |
7002 | pcie_device->port_num = pcie_device_pg0.PortNum; | |
7003 | pcie_device->fast_path = (le32_to_cpu(pcie_device_pg0.Flags) & | |
7004 | MPI26_PCIEDEV0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0; | |
7005 | pcie_device_type = pcie_device->device_info & | |
7006 | MPI26_PCIE_DEVINFO_MASK_DEVICE_TYPE; | |
7007 | ||
7008 | pcie_device->enclosure_handle = | |
7009 | le16_to_cpu(pcie_device_pg0.EnclosureHandle); | |
7010 | if (pcie_device->enclosure_handle != 0) | |
7011 | pcie_device->slot = le16_to_cpu(pcie_device_pg0.Slot); | |
7012 | ||
7013 | if (le16_to_cpu(pcie_device_pg0.Flags) & | |
7014 | MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) { | |
7015 | pcie_device->enclosure_level = pcie_device_pg0.EnclosureLevel; | |
7016 | memcpy(&pcie_device->connector_name[0], | |
7017 | &pcie_device_pg0.ConnectorName[0], 4); | |
7018 | } else { | |
7019 | pcie_device->enclosure_level = 0; | |
7020 | pcie_device->connector_name[0] = '\0'; | |
7021 | } | |
7022 | ||
7023 | /* get enclosure_logical_id */ | |
7024 | if (pcie_device->enclosure_handle && | |
7025 | !(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
7026 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
7027 | pcie_device->enclosure_handle))) | |
7028 | pcie_device->enclosure_logical_id = | |
7029 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
7030 | ||
7031 | /* TODO -- Add device name once FW supports it */ | |
7032 | if (mpt3sas_config_get_pcie_device_pg2(ioc, &mpi_reply, | |
7033 | &pcie_device_pg2, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)) { | |
7034 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
7035 | ioc->name, __FILE__, __LINE__, __func__); | |
7036 | kfree(pcie_device); | |
7037 | return 0; | |
7038 | } | |
7039 | ||
7040 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
7041 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
7042 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
7043 | ioc->name, __FILE__, __LINE__, __func__); | |
7044 | kfree(pcie_device); | |
7045 | return 0; | |
7046 | } | |
7047 | pcie_device->nvme_mdts = | |
7048 | le32_to_cpu(pcie_device_pg2.MaximumDataTransferSize); | |
7049 | ||
7050 | if (ioc->wait_for_discovery_to_complete) | |
7051 | _scsih_pcie_device_init_add(ioc, pcie_device); | |
7052 | else | |
7053 | _scsih_pcie_device_add(ioc, pcie_device); | |
7054 | ||
7055 | pcie_device_put(pcie_device); | |
7056 | return 0; | |
7057 | } | |
4318c734 SPS |
7058 | |
7059 | /** | |
7060 | * _scsih_pcie_topology_change_event_debug - debug for topology | |
7061 | * event | |
7062 | * @ioc: per adapter object | |
7063 | * @event_data: event data payload | |
7064 | * Context: user. | |
7065 | */ | |
7066 | static void | |
7067 | _scsih_pcie_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
7068 | Mpi26EventDataPCIeTopologyChangeList_t *event_data) | |
7069 | { | |
7070 | int i; | |
7071 | u16 handle; | |
7072 | u16 reason_code; | |
7073 | u8 port_number; | |
7074 | char *status_str = NULL; | |
7075 | u8 link_rate, prev_link_rate; | |
7076 | ||
7077 | switch (event_data->SwitchStatus) { | |
7078 | case MPI26_EVENT_PCIE_TOPO_SS_ADDED: | |
7079 | status_str = "add"; | |
7080 | break; | |
7081 | case MPI26_EVENT_PCIE_TOPO_SS_NOT_RESPONDING: | |
7082 | status_str = "remove"; | |
7083 | break; | |
7084 | case MPI26_EVENT_PCIE_TOPO_SS_RESPONDING: | |
7085 | case 0: | |
7086 | status_str = "responding"; | |
7087 | break; | |
7088 | case MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING: | |
7089 | status_str = "remove delay"; | |
7090 | break; | |
7091 | default: | |
7092 | status_str = "unknown status"; | |
7093 | break; | |
7094 | } | |
7095 | pr_info(MPT3SAS_FMT "pcie topology change: (%s)\n", | |
7096 | ioc->name, status_str); | |
7097 | pr_info("\tswitch_handle(0x%04x), enclosure_handle(0x%04x)" | |
7098 | "start_port(%02d), count(%d)\n", | |
7099 | le16_to_cpu(event_data->SwitchDevHandle), | |
7100 | le16_to_cpu(event_data->EnclosureHandle), | |
7101 | event_data->StartPortNum, event_data->NumEntries); | |
7102 | for (i = 0; i < event_data->NumEntries; i++) { | |
7103 | handle = | |
7104 | le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle); | |
7105 | if (!handle) | |
7106 | continue; | |
7107 | port_number = event_data->StartPortNum + i; | |
7108 | reason_code = event_data->PortEntry[i].PortStatus; | |
7109 | switch (reason_code) { | |
7110 | case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED: | |
7111 | status_str = "target add"; | |
7112 | break; | |
7113 | case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING: | |
7114 | status_str = "target remove"; | |
7115 | break; | |
7116 | case MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING: | |
7117 | status_str = "delay target remove"; | |
7118 | break; | |
7119 | case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED: | |
7120 | status_str = "link rate change"; | |
7121 | break; | |
7122 | case MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE: | |
7123 | status_str = "target responding"; | |
7124 | break; | |
7125 | default: | |
7126 | status_str = "unknown"; | |
7127 | break; | |
7128 | } | |
7129 | link_rate = event_data->PortEntry[i].CurrentPortInfo & | |
7130 | MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK; | |
7131 | prev_link_rate = event_data->PortEntry[i].PreviousPortInfo & | |
7132 | MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK; | |
7133 | pr_info("\tport(%02d), attached_handle(0x%04x): %s:" | |
7134 | " link rate: new(0x%02x), old(0x%02x)\n", port_number, | |
7135 | handle, status_str, link_rate, prev_link_rate); | |
7136 | } | |
7137 | } | |
7138 | ||
7139 | /** | |
7140 | * _scsih_pcie_topology_change_event - handle PCIe topology | |
7141 | * changes | |
7142 | * @ioc: per adapter object | |
7143 | * @fw_event: The fw_event_work object | |
7144 | * Context: user. | |
7145 | * | |
7146 | */ | |
7147 | static int | |
7148 | _scsih_pcie_topology_change_event(struct MPT3SAS_ADAPTER *ioc, | |
7149 | struct fw_event_work *fw_event) | |
7150 | { | |
7151 | int i; | |
7152 | u16 handle; | |
7153 | u16 reason_code; | |
7154 | u8 link_rate, prev_link_rate; | |
7155 | unsigned long flags; | |
7156 | int rc; | |
7157 | int requeue_event; | |
7158 | Mpi26EventDataPCIeTopologyChangeList_t *event_data = | |
7159 | (Mpi26EventDataPCIeTopologyChangeList_t *) fw_event->event_data; | |
7160 | struct _pcie_device *pcie_device; | |
7161 | ||
7162 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) | |
7163 | _scsih_pcie_topology_change_event_debug(ioc, event_data); | |
7164 | ||
7165 | if (ioc->shost_recovery || ioc->remove_host || | |
7166 | ioc->pci_error_recovery) | |
7167 | return 0; | |
7168 | ||
7169 | if (fw_event->ignore) { | |
7170 | dewtprintk(ioc, pr_info(MPT3SAS_FMT "ignoring switch event\n", | |
7171 | ioc->name)); | |
7172 | return 0; | |
7173 | } | |
7174 | ||
7175 | /* handle siblings events */ | |
7176 | for (i = 0; i < event_data->NumEntries; i++) { | |
7177 | if (fw_event->ignore) { | |
7178 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7179 | "ignoring switch event\n", ioc->name)); | |
7180 | return 0; | |
7181 | } | |
7182 | if (ioc->remove_host || ioc->pci_error_recovery) | |
7183 | return 0; | |
7184 | reason_code = event_data->PortEntry[i].PortStatus; | |
7185 | handle = | |
7186 | le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle); | |
7187 | if (!handle) | |
7188 | continue; | |
7189 | ||
7190 | link_rate = event_data->PortEntry[i].CurrentPortInfo | |
7191 | & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK; | |
7192 | prev_link_rate = event_data->PortEntry[i].PreviousPortInfo | |
7193 | & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK; | |
7194 | ||
7195 | switch (reason_code) { | |
7196 | case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED: | |
7197 | if (ioc->shost_recovery) | |
7198 | break; | |
7199 | if (link_rate == prev_link_rate) | |
7200 | break; | |
7201 | if (link_rate < MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5) | |
7202 | break; | |
7203 | ||
7204 | _scsih_pcie_check_device(ioc, handle); | |
7205 | ||
7206 | /* This code after this point handles the test case | |
7207 | * where a device has been added, however its returning | |
7208 | * BUSY for sometime. Then before the Device Missing | |
7209 | * Delay expires and the device becomes READY, the | |
7210 | * device is removed and added back. | |
7211 | */ | |
7212 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
7213 | pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle); | |
7214 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
7215 | ||
7216 | if (pcie_device) { | |
7217 | pcie_device_put(pcie_device); | |
7218 | break; | |
7219 | } | |
7220 | ||
7221 | if (!test_bit(handle, ioc->pend_os_device_add)) | |
7222 | break; | |
7223 | ||
7224 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7225 | "handle(0x%04x) device not found: convert " | |
7226 | "event to a device add\n", ioc->name, handle)); | |
7227 | event_data->PortEntry[i].PortStatus &= 0xF0; | |
7228 | event_data->PortEntry[i].PortStatus |= | |
7229 | MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED; | |
7230 | case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED: | |
7231 | if (ioc->shost_recovery) | |
7232 | break; | |
7233 | if (link_rate < MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5) | |
7234 | break; | |
7235 | ||
7236 | rc = _scsih_pcie_add_device(ioc, handle); | |
7237 | if (!rc) { | |
7238 | /* mark entry vacant */ | |
7239 | /* TODO This needs to be reviewed and fixed, | |
7240 | * we dont have an entry | |
7241 | * to make an event void like vacant | |
7242 | */ | |
7243 | event_data->PortEntry[i].PortStatus |= | |
7244 | MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE; | |
7245 | } | |
7246 | break; | |
7247 | case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING: | |
7248 | _scsih_pcie_device_remove_by_handle(ioc, handle); | |
7249 | break; | |
7250 | } | |
7251 | } | |
7252 | return requeue_event; | |
7253 | } | |
7254 | ||
7255 | /** | |
7256 | * _scsih_pcie_device_status_change_event_debug - debug for | |
7257 | * device event | |
7258 | * @event_data: event data payload | |
7259 | * Context: user. | |
7260 | * | |
7261 | * Return nothing. | |
7262 | */ | |
7263 | static void | |
7264 | _scsih_pcie_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
7265 | Mpi26EventDataPCIeDeviceStatusChange_t *event_data) | |
7266 | { | |
7267 | char *reason_str = NULL; | |
7268 | ||
7269 | switch (event_data->ReasonCode) { | |
7270 | case MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA: | |
7271 | reason_str = "smart data"; | |
7272 | break; | |
7273 | case MPI26_EVENT_PCIDEV_STAT_RC_UNSUPPORTED: | |
7274 | reason_str = "unsupported device discovered"; | |
7275 | break; | |
7276 | case MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET: | |
7277 | reason_str = "internal device reset"; | |
7278 | break; | |
7279 | case MPI26_EVENT_PCIDEV_STAT_RC_TASK_ABORT_INTERNAL: | |
7280 | reason_str = "internal task abort"; | |
7281 | break; | |
7282 | case MPI26_EVENT_PCIDEV_STAT_RC_ABORT_TASK_SET_INTERNAL: | |
7283 | reason_str = "internal task abort set"; | |
7284 | break; | |
7285 | case MPI26_EVENT_PCIDEV_STAT_RC_CLEAR_TASK_SET_INTERNAL: | |
7286 | reason_str = "internal clear task set"; | |
7287 | break; | |
7288 | case MPI26_EVENT_PCIDEV_STAT_RC_QUERY_TASK_INTERNAL: | |
7289 | reason_str = "internal query task"; | |
7290 | break; | |
7291 | case MPI26_EVENT_PCIDEV_STAT_RC_DEV_INIT_FAILURE: | |
7292 | reason_str = "device init failure"; | |
7293 | break; | |
7294 | case MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET: | |
7295 | reason_str = "internal device reset complete"; | |
7296 | break; | |
7297 | case MPI26_EVENT_PCIDEV_STAT_RC_CMP_TASK_ABORT_INTERNAL: | |
7298 | reason_str = "internal task abort complete"; | |
7299 | break; | |
7300 | case MPI26_EVENT_PCIDEV_STAT_RC_ASYNC_NOTIFICATION: | |
7301 | reason_str = "internal async notification"; | |
7302 | break; | |
7303 | default: | |
7304 | reason_str = "unknown reason"; | |
7305 | break; | |
7306 | } | |
7307 | ||
7308 | pr_info(MPT3SAS_FMT "PCIE device status change: (%s)\n" | |
7309 | "\thandle(0x%04x), WWID(0x%016llx), tag(%d)", | |
7310 | ioc->name, reason_str, le16_to_cpu(event_data->DevHandle), | |
7311 | (unsigned long long)le64_to_cpu(event_data->WWID), | |
7312 | le16_to_cpu(event_data->TaskTag)); | |
7313 | if (event_data->ReasonCode == MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA) | |
7314 | pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name, | |
7315 | event_data->ASC, event_data->ASCQ); | |
7316 | pr_info("\n"); | |
7317 | } | |
7318 | ||
7319 | /** | |
7320 | * _scsih_pcie_device_status_change_event - handle device status | |
7321 | * change | |
7322 | * @ioc: per adapter object | |
7323 | * @fw_event: The fw_event_work object | |
7324 | * Context: user. | |
7325 | * | |
7326 | * Return nothing. | |
7327 | */ | |
7328 | static void | |
7329 | _scsih_pcie_device_status_change_event(struct MPT3SAS_ADAPTER *ioc, | |
7330 | struct fw_event_work *fw_event) | |
7331 | { | |
7332 | struct MPT3SAS_TARGET *target_priv_data; | |
7333 | struct _pcie_device *pcie_device; | |
7334 | u64 wwid; | |
7335 | unsigned long flags; | |
7336 | Mpi26EventDataPCIeDeviceStatusChange_t *event_data = | |
7337 | (Mpi26EventDataPCIeDeviceStatusChange_t *)fw_event->event_data; | |
7338 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) | |
7339 | _scsih_pcie_device_status_change_event_debug(ioc, | |
7340 | event_data); | |
7341 | ||
7342 | if (event_data->ReasonCode != | |
7343 | MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET && | |
7344 | event_data->ReasonCode != | |
7345 | MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET) | |
7346 | return; | |
7347 | ||
7348 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
7349 | wwid = le64_to_cpu(event_data->WWID); | |
7350 | pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid); | |
7351 | ||
7352 | if (!pcie_device || !pcie_device->starget) | |
7353 | goto out; | |
7354 | ||
7355 | target_priv_data = pcie_device->starget->hostdata; | |
7356 | if (!target_priv_data) | |
7357 | goto out; | |
7358 | ||
7359 | if (event_data->ReasonCode == | |
7360 | MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET) | |
7361 | target_priv_data->tm_busy = 1; | |
7362 | else | |
7363 | target_priv_data->tm_busy = 0; | |
7364 | out: | |
7365 | if (pcie_device) | |
7366 | pcie_device_put(pcie_device); | |
7367 | ||
7368 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
7369 | } | |
7370 | ||
f92363d1 SR |
7371 | /** |
7372 | * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure | |
7373 | * event | |
7374 | * @ioc: per adapter object | |
7375 | * @event_data: event data payload | |
7376 | * Context: user. | |
7377 | * | |
7378 | * Return nothing. | |
7379 | */ | |
7380 | static void | |
7381 | _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
7382 | Mpi2EventDataSasEnclDevStatusChange_t *event_data) | |
7383 | { | |
7384 | char *reason_str = NULL; | |
7385 | ||
7386 | switch (event_data->ReasonCode) { | |
7387 | case MPI2_EVENT_SAS_ENCL_RC_ADDED: | |
7388 | reason_str = "enclosure add"; | |
7389 | break; | |
7390 | case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING: | |
7391 | reason_str = "enclosure remove"; | |
7392 | break; | |
7393 | default: | |
7394 | reason_str = "unknown reason"; | |
7395 | break; | |
7396 | } | |
7397 | ||
7398 | pr_info(MPT3SAS_FMT "enclosure status change: (%s)\n" | |
7399 | "\thandle(0x%04x), enclosure logical id(0x%016llx)" | |
7400 | " number slots(%d)\n", ioc->name, reason_str, | |
7401 | le16_to_cpu(event_data->EnclosureHandle), | |
7402 | (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID), | |
7403 | le16_to_cpu(event_data->StartSlot)); | |
7404 | } | |
f92363d1 SR |
7405 | |
7406 | /** | |
7407 | * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events | |
7408 | * @ioc: per adapter object | |
7409 | * @fw_event: The fw_event_work object | |
7410 | * Context: user. | |
7411 | * | |
7412 | * Return nothing. | |
7413 | */ | |
7414 | static void | |
7415 | _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc, | |
7416 | struct fw_event_work *fw_event) | |
7417 | { | |
f92363d1 SR |
7418 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
7419 | _scsih_sas_enclosure_dev_status_change_event_debug(ioc, | |
35b62362 | 7420 | (Mpi2EventDataSasEnclDevStatusChange_t *) |
f92363d1 | 7421 | fw_event->event_data); |
f92363d1 SR |
7422 | } |
7423 | ||
7424 | /** | |
7425 | * _scsih_sas_broadcast_primitive_event - handle broadcast events | |
7426 | * @ioc: per adapter object | |
7427 | * @fw_event: The fw_event_work object | |
7428 | * Context: user. | |
7429 | * | |
7430 | * Return nothing. | |
7431 | */ | |
7432 | static void | |
7433 | _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc, | |
7434 | struct fw_event_work *fw_event) | |
7435 | { | |
7436 | struct scsi_cmnd *scmd; | |
7437 | struct scsi_device *sdev; | |
7438 | u16 smid, handle; | |
7439 | u32 lun; | |
7440 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
7441 | u32 termination_count; | |
7442 | u32 query_count; | |
7443 | Mpi2SCSITaskManagementReply_t *mpi_reply; | |
35b62362 JL |
7444 | Mpi2EventDataSasBroadcastPrimitive_t *event_data = |
7445 | (Mpi2EventDataSasBroadcastPrimitive_t *) | |
7446 | fw_event->event_data; | |
f92363d1 SR |
7447 | u16 ioc_status; |
7448 | unsigned long flags; | |
7449 | int r; | |
7450 | u8 max_retries = 0; | |
7451 | u8 task_abort_retries; | |
7452 | ||
7453 | mutex_lock(&ioc->tm_cmds.mutex); | |
7454 | pr_info(MPT3SAS_FMT | |
7455 | "%s: enter: phy number(%d), width(%d)\n", | |
7456 | ioc->name, __func__, event_data->PhyNum, | |
7457 | event_data->PortWidth); | |
7458 | ||
7459 | _scsih_block_io_all_device(ioc); | |
7460 | ||
7461 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7462 | mpi_reply = ioc->tm_cmds.reply; | |
7463 | broadcast_aen_retry: | |
7464 | ||
7465 | /* sanity checks for retrying this loop */ | |
7466 | if (max_retries++ == 5) { | |
7467 | dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: giving up\n", | |
7468 | ioc->name, __func__)); | |
7469 | goto out; | |
7470 | } else if (max_retries > 1) | |
7471 | dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: %d retry\n", | |
7472 | ioc->name, __func__, max_retries - 1)); | |
7473 | ||
7474 | termination_count = 0; | |
7475 | query_count = 0; | |
7476 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { | |
7477 | if (ioc->shost_recovery) | |
7478 | goto out; | |
7479 | scmd = _scsih_scsi_lookup_get(ioc, smid); | |
7480 | if (!scmd) | |
7481 | continue; | |
7482 | sdev = scmd->device; | |
7483 | sas_device_priv_data = sdev->hostdata; | |
7484 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) | |
7485 | continue; | |
7486 | /* skip hidden raid components */ | |
7487 | if (sas_device_priv_data->sas_target->flags & | |
7488 | MPT_TARGET_FLAGS_RAID_COMPONENT) | |
7489 | continue; | |
7490 | /* skip volumes */ | |
7491 | if (sas_device_priv_data->sas_target->flags & | |
7492 | MPT_TARGET_FLAGS_VOLUME) | |
7493 | continue; | |
7494 | ||
7495 | handle = sas_device_priv_data->sas_target->handle; | |
7496 | lun = sas_device_priv_data->lun; | |
7497 | query_count++; | |
7498 | ||
7499 | if (ioc->shost_recovery) | |
7500 | goto out; | |
7501 | ||
7502 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
7503 | r = mpt3sas_scsih_issue_tm(ioc, handle, 0, 0, lun, | |
96902835 | 7504 | MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30); |
f92363d1 SR |
7505 | if (r == FAILED) { |
7506 | sdev_printk(KERN_WARNING, sdev, | |
7507 | "mpt3sas_scsih_issue_tm: FAILED when sending " | |
7508 | "QUERY_TASK: scmd(%p)\n", scmd); | |
7509 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7510 | goto broadcast_aen_retry; | |
7511 | } | |
7512 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) | |
7513 | & MPI2_IOCSTATUS_MASK; | |
7514 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
7515 | sdev_printk(KERN_WARNING, sdev, | |
7516 | "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n", | |
7517 | ioc_status, scmd); | |
7518 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7519 | goto broadcast_aen_retry; | |
7520 | } | |
7521 | ||
7522 | /* see if IO is still owned by IOC and target */ | |
7523 | if (mpi_reply->ResponseCode == | |
7524 | MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED || | |
7525 | mpi_reply->ResponseCode == | |
7526 | MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) { | |
7527 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7528 | continue; | |
7529 | } | |
7530 | task_abort_retries = 0; | |
7531 | tm_retry: | |
7532 | if (task_abort_retries++ == 60) { | |
7533 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7534 | "%s: ABORT_TASK: giving up\n", ioc->name, | |
7535 | __func__)); | |
7536 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7537 | goto broadcast_aen_retry; | |
7538 | } | |
7539 | ||
7540 | if (ioc->shost_recovery) | |
7541 | goto out_no_lock; | |
7542 | ||
7543 | r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id, | |
96902835 CO |
7544 | sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, |
7545 | 30); | |
f92363d1 SR |
7546 | if (r == FAILED) { |
7547 | sdev_printk(KERN_WARNING, sdev, | |
7548 | "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : " | |
7549 | "scmd(%p)\n", scmd); | |
7550 | goto tm_retry; | |
7551 | } | |
7552 | ||
7553 | if (task_abort_retries > 1) | |
7554 | sdev_printk(KERN_WARNING, sdev, | |
7555 | "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):" | |
7556 | " scmd(%p)\n", | |
7557 | task_abort_retries - 1, scmd); | |
7558 | ||
7559 | termination_count += le32_to_cpu(mpi_reply->TerminationCount); | |
7560 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7561 | } | |
7562 | ||
7563 | if (ioc->broadcast_aen_pending) { | |
7564 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7565 | "%s: loop back due to pending AEN\n", | |
7566 | ioc->name, __func__)); | |
7567 | ioc->broadcast_aen_pending = 0; | |
7568 | goto broadcast_aen_retry; | |
7569 | } | |
7570 | ||
7571 | out: | |
7572 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
7573 | out_no_lock: | |
7574 | ||
7575 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7576 | "%s - exit, query_count = %d termination_count = %d\n", | |
7577 | ioc->name, __func__, query_count, termination_count)); | |
7578 | ||
7579 | ioc->broadcast_aen_busy = 0; | |
7580 | if (!ioc->shost_recovery) | |
7581 | _scsih_ublock_io_all_device(ioc); | |
7582 | mutex_unlock(&ioc->tm_cmds.mutex); | |
7583 | } | |
7584 | ||
7585 | /** | |
7586 | * _scsih_sas_discovery_event - handle discovery events | |
7587 | * @ioc: per adapter object | |
7588 | * @fw_event: The fw_event_work object | |
7589 | * Context: user. | |
7590 | * | |
7591 | * Return nothing. | |
7592 | */ | |
7593 | static void | |
7594 | _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc, | |
7595 | struct fw_event_work *fw_event) | |
7596 | { | |
35b62362 JL |
7597 | Mpi2EventDataSasDiscovery_t *event_data = |
7598 | (Mpi2EventDataSasDiscovery_t *) fw_event->event_data; | |
f92363d1 | 7599 | |
f92363d1 SR |
7600 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) { |
7601 | pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name, | |
7602 | (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ? | |
7603 | "start" : "stop"); | |
af009411 SR |
7604 | if (event_data->DiscoveryStatus) |
7605 | pr_info("discovery_status(0x%08x)", | |
7606 | le32_to_cpu(event_data->DiscoveryStatus)); | |
7607 | pr_info("\n"); | |
f92363d1 | 7608 | } |
f92363d1 SR |
7609 | |
7610 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED && | |
7611 | !ioc->sas_hba.num_phys) { | |
7612 | if (disable_discovery > 0 && ioc->shost_recovery) { | |
7613 | /* Wait for the reset to complete */ | |
7614 | while (ioc->shost_recovery) | |
7615 | ssleep(1); | |
7616 | } | |
7617 | _scsih_sas_host_add(ioc); | |
7618 | } | |
7619 | } | |
7620 | ||
4318c734 SPS |
7621 | /** |
7622 | * _scsih_pcie_enumeration_event - handle enumeration events | |
7623 | * @ioc: per adapter object | |
7624 | * @fw_event: The fw_event_work object | |
7625 | * Context: user. | |
7626 | * | |
7627 | * Return nothing. | |
7628 | */ | |
7629 | static void | |
7630 | _scsih_pcie_enumeration_event(struct MPT3SAS_ADAPTER *ioc, | |
7631 | struct fw_event_work *fw_event) | |
7632 | { | |
7633 | Mpi26EventDataPCIeEnumeration_t *event_data = | |
7634 | (Mpi26EventDataPCIeEnumeration_t *)fw_event->event_data; | |
7635 | ||
7636 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) { | |
7637 | pr_info(MPT3SAS_FMT "pcie enumeration event: (%s) Flag 0x%02x", | |
7638 | ioc->name, | |
7639 | ((event_data->ReasonCode == | |
7640 | MPI26_EVENT_PCIE_ENUM_RC_STARTED) ? | |
7641 | "started" : "completed"), event_data->Flags); | |
7642 | if (event_data->EnumerationStatus) | |
7643 | pr_info("enumeration_status(0x%08x)", | |
7644 | le32_to_cpu(event_data->EnumerationStatus)); | |
7645 | pr_info("\n"); | |
7646 | } | |
7647 | } | |
7648 | ||
f92363d1 SR |
7649 | /** |
7650 | * _scsih_ir_fastpath - turn on fastpath for IR physdisk | |
7651 | * @ioc: per adapter object | |
7652 | * @handle: device handle for physical disk | |
7653 | * @phys_disk_num: physical disk number | |
7654 | * | |
7655 | * Return 0 for success, else failure. | |
7656 | */ | |
7657 | static int | |
7658 | _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num) | |
7659 | { | |
7660 | Mpi2RaidActionRequest_t *mpi_request; | |
7661 | Mpi2RaidActionReply_t *mpi_reply; | |
7662 | u16 smid; | |
7663 | u8 issue_reset = 0; | |
7664 | int rc = 0; | |
7665 | u16 ioc_status; | |
7666 | u32 log_info; | |
7667 | ||
c84b06a4 SR |
7668 | if (ioc->hba_mpi_version_belonged == MPI2_VERSION) |
7669 | return rc; | |
7670 | ||
f92363d1 SR |
7671 | mutex_lock(&ioc->scsih_cmds.mutex); |
7672 | ||
7673 | if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) { | |
7674 | pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n", | |
7675 | ioc->name, __func__); | |
7676 | rc = -EAGAIN; | |
7677 | goto out; | |
7678 | } | |
7679 | ioc->scsih_cmds.status = MPT3_CMD_PENDING; | |
7680 | ||
7681 | smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx); | |
7682 | if (!smid) { | |
7683 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
7684 | ioc->name, __func__); | |
7685 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
7686 | rc = -EAGAIN; | |
7687 | goto out; | |
7688 | } | |
7689 | ||
7690 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
7691 | ioc->scsih_cmds.smid = smid; | |
7692 | memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t)); | |
7693 | ||
7694 | mpi_request->Function = MPI2_FUNCTION_RAID_ACTION; | |
7695 | mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN; | |
7696 | mpi_request->PhysDiskNum = phys_disk_num; | |
7697 | ||
7698 | dewtprintk(ioc, pr_info(MPT3SAS_FMT "IR RAID_ACTION: turning fast "\ | |
7699 | "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc->name, | |
7700 | handle, phys_disk_num)); | |
7701 | ||
7702 | init_completion(&ioc->scsih_cmds.done); | |
81c16f83 | 7703 | ioc->put_smid_default(ioc, smid); |
f92363d1 SR |
7704 | wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ); |
7705 | ||
7706 | if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) { | |
7707 | pr_err(MPT3SAS_FMT "%s: timeout\n", | |
7708 | ioc->name, __func__); | |
7709 | if (!(ioc->scsih_cmds.status & MPT3_CMD_RESET)) | |
7710 | issue_reset = 1; | |
7711 | rc = -EFAULT; | |
7712 | goto out; | |
7713 | } | |
7714 | ||
7715 | if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) { | |
7716 | ||
7717 | mpi_reply = ioc->scsih_cmds.reply; | |
7718 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); | |
7719 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) | |
7720 | log_info = le32_to_cpu(mpi_reply->IOCLogInfo); | |
7721 | else | |
7722 | log_info = 0; | |
7723 | ioc_status &= MPI2_IOCSTATUS_MASK; | |
7724 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
7725 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7726 | "IR RAID_ACTION: failed: ioc_status(0x%04x), " | |
7727 | "loginfo(0x%08x)!!!\n", ioc->name, ioc_status, | |
7728 | log_info)); | |
7729 | rc = -EFAULT; | |
7730 | } else | |
7731 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7732 | "IR RAID_ACTION: completed successfully\n", | |
7733 | ioc->name)); | |
7734 | } | |
7735 | ||
7736 | out: | |
7737 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
7738 | mutex_unlock(&ioc->scsih_cmds.mutex); | |
7739 | ||
7740 | if (issue_reset) | |
98c56ad3 | 7741 | mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
f92363d1 SR |
7742 | return rc; |
7743 | } | |
7744 | ||
7745 | /** | |
7746 | * _scsih_reprobe_lun - reprobing lun | |
7747 | * @sdev: scsi device struct | |
7748 | * @no_uld_attach: sdev->no_uld_attach flag setting | |
7749 | * | |
7750 | **/ | |
7751 | static void | |
7752 | _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach) | |
7753 | { | |
f92363d1 SR |
7754 | sdev->no_uld_attach = no_uld_attach ? 1 : 0; |
7755 | sdev_printk(KERN_INFO, sdev, "%s raid component\n", | |
6c7abffc | 7756 | sdev->no_uld_attach ? "hiding" : "exposing"); |
8bbb1cf6 | 7757 | WARN_ON(scsi_device_reprobe(sdev)); |
f92363d1 SR |
7758 | } |
7759 | ||
7760 | /** | |
7761 | * _scsih_sas_volume_add - add new volume | |
7762 | * @ioc: per adapter object | |
7763 | * @element: IR config element data | |
7764 | * Context: user. | |
7765 | * | |
7766 | * Return nothing. | |
7767 | */ | |
7768 | static void | |
7769 | _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc, | |
7770 | Mpi2EventIrConfigElement_t *element) | |
7771 | { | |
7772 | struct _raid_device *raid_device; | |
7773 | unsigned long flags; | |
7774 | u64 wwid; | |
7775 | u16 handle = le16_to_cpu(element->VolDevHandle); | |
7776 | int rc; | |
7777 | ||
7778 | mpt3sas_config_get_volume_wwid(ioc, handle, &wwid); | |
7779 | if (!wwid) { | |
7780 | pr_err(MPT3SAS_FMT | |
7781 | "failure at %s:%d/%s()!\n", ioc->name, | |
7782 | __FILE__, __LINE__, __func__); | |
7783 | return; | |
7784 | } | |
7785 | ||
7786 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
7787 | raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid); | |
7788 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
7789 | ||
7790 | if (raid_device) | |
7791 | return; | |
7792 | ||
7793 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); | |
7794 | if (!raid_device) { | |
7795 | pr_err(MPT3SAS_FMT | |
7796 | "failure at %s:%d/%s()!\n", ioc->name, | |
7797 | __FILE__, __LINE__, __func__); | |
7798 | return; | |
7799 | } | |
7800 | ||
7801 | raid_device->id = ioc->sas_id++; | |
7802 | raid_device->channel = RAID_CHANNEL; | |
7803 | raid_device->handle = handle; | |
7804 | raid_device->wwid = wwid; | |
7805 | _scsih_raid_device_add(ioc, raid_device); | |
7806 | if (!ioc->wait_for_discovery_to_complete) { | |
7807 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
7808 | raid_device->id, 0); | |
7809 | if (rc) | |
7810 | _scsih_raid_device_remove(ioc, raid_device); | |
7811 | } else { | |
7812 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
7813 | _scsih_determine_boot_device(ioc, raid_device, 1); | |
7814 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
7815 | } | |
7816 | } | |
7817 | ||
7818 | /** | |
7819 | * _scsih_sas_volume_delete - delete volume | |
7820 | * @ioc: per adapter object | |
7821 | * @handle: volume device handle | |
7822 | * Context: user. | |
7823 | * | |
7824 | * Return nothing. | |
7825 | */ | |
7826 | static void | |
7827 | _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
7828 | { | |
7829 | struct _raid_device *raid_device; | |
7830 | unsigned long flags; | |
7831 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
7832 | struct scsi_target *starget = NULL; | |
7833 | ||
7834 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
c84b06a4 | 7835 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
7836 | if (raid_device) { |
7837 | if (raid_device->starget) { | |
7838 | starget = raid_device->starget; | |
7839 | sas_target_priv_data = starget->hostdata; | |
7840 | sas_target_priv_data->deleted = 1; | |
7841 | } | |
7842 | pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n", | |
7843 | ioc->name, raid_device->handle, | |
7844 | (unsigned long long) raid_device->wwid); | |
7845 | list_del(&raid_device->list); | |
7846 | kfree(raid_device); | |
7847 | } | |
7848 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
7849 | if (starget) | |
7850 | scsi_remove_target(&starget->dev); | |
7851 | } | |
7852 | ||
7853 | /** | |
7854 | * _scsih_sas_pd_expose - expose pd component to /dev/sdX | |
7855 | * @ioc: per adapter object | |
7856 | * @element: IR config element data | |
7857 | * Context: user. | |
7858 | * | |
7859 | * Return nothing. | |
7860 | */ | |
7861 | static void | |
7862 | _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc, | |
7863 | Mpi2EventIrConfigElement_t *element) | |
7864 | { | |
7865 | struct _sas_device *sas_device; | |
7866 | struct scsi_target *starget = NULL; | |
7867 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
7868 | unsigned long flags; | |
7869 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | |
7870 | ||
7871 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 | 7872 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
7873 | if (sas_device) { |
7874 | sas_device->volume_handle = 0; | |
7875 | sas_device->volume_wwid = 0; | |
7876 | clear_bit(handle, ioc->pd_handles); | |
7877 | if (sas_device->starget && sas_device->starget->hostdata) { | |
7878 | starget = sas_device->starget; | |
7879 | sas_target_priv_data = starget->hostdata; | |
7880 | sas_target_priv_data->flags &= | |
7881 | ~MPT_TARGET_FLAGS_RAID_COMPONENT; | |
7882 | } | |
7883 | } | |
7884 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
7885 | if (!sas_device) | |
7886 | return; | |
7887 | ||
7888 | /* exposing raid component */ | |
7889 | if (starget) | |
7890 | starget_for_each_device(starget, NULL, _scsih_reprobe_lun); | |
d1cb5e49 SR |
7891 | |
7892 | sas_device_put(sas_device); | |
f92363d1 SR |
7893 | } |
7894 | ||
7895 | /** | |
7896 | * _scsih_sas_pd_hide - hide pd component from /dev/sdX | |
7897 | * @ioc: per adapter object | |
7898 | * @element: IR config element data | |
7899 | * Context: user. | |
7900 | * | |
7901 | * Return nothing. | |
7902 | */ | |
7903 | static void | |
7904 | _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc, | |
7905 | Mpi2EventIrConfigElement_t *element) | |
7906 | { | |
7907 | struct _sas_device *sas_device; | |
7908 | struct scsi_target *starget = NULL; | |
7909 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
7910 | unsigned long flags; | |
7911 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | |
7912 | u16 volume_handle = 0; | |
7913 | u64 volume_wwid = 0; | |
7914 | ||
7915 | mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle); | |
7916 | if (volume_handle) | |
7917 | mpt3sas_config_get_volume_wwid(ioc, volume_handle, | |
7918 | &volume_wwid); | |
7919 | ||
7920 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 | 7921 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
7922 | if (sas_device) { |
7923 | set_bit(handle, ioc->pd_handles); | |
7924 | if (sas_device->starget && sas_device->starget->hostdata) { | |
7925 | starget = sas_device->starget; | |
7926 | sas_target_priv_data = starget->hostdata; | |
7927 | sas_target_priv_data->flags |= | |
7928 | MPT_TARGET_FLAGS_RAID_COMPONENT; | |
7929 | sas_device->volume_handle = volume_handle; | |
7930 | sas_device->volume_wwid = volume_wwid; | |
7931 | } | |
7932 | } | |
7933 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
7934 | if (!sas_device) | |
7935 | return; | |
7936 | ||
7937 | /* hiding raid component */ | |
7938 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); | |
c84b06a4 | 7939 | |
f92363d1 SR |
7940 | if (starget) |
7941 | starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun); | |
d1cb5e49 SR |
7942 | |
7943 | sas_device_put(sas_device); | |
f92363d1 SR |
7944 | } |
7945 | ||
7946 | /** | |
7947 | * _scsih_sas_pd_delete - delete pd component | |
7948 | * @ioc: per adapter object | |
7949 | * @element: IR config element data | |
7950 | * Context: user. | |
7951 | * | |
7952 | * Return nothing. | |
7953 | */ | |
7954 | static void | |
7955 | _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc, | |
7956 | Mpi2EventIrConfigElement_t *element) | |
7957 | { | |
7958 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | |
7959 | ||
7960 | _scsih_device_remove_by_handle(ioc, handle); | |
7961 | } | |
7962 | ||
7963 | /** | |
7964 | * _scsih_sas_pd_add - remove pd component | |
7965 | * @ioc: per adapter object | |
7966 | * @element: IR config element data | |
7967 | * Context: user. | |
7968 | * | |
7969 | * Return nothing. | |
7970 | */ | |
7971 | static void | |
7972 | _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc, | |
7973 | Mpi2EventIrConfigElement_t *element) | |
7974 | { | |
7975 | struct _sas_device *sas_device; | |
f92363d1 SR |
7976 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
7977 | Mpi2ConfigReply_t mpi_reply; | |
7978 | Mpi2SasDevicePage0_t sas_device_pg0; | |
7979 | u32 ioc_status; | |
7980 | u64 sas_address; | |
7981 | u16 parent_handle; | |
7982 | ||
7983 | set_bit(handle, ioc->pd_handles); | |
7984 | ||
d1cb5e49 | 7985 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
7986 | if (sas_device) { |
7987 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); | |
d1cb5e49 | 7988 | sas_device_put(sas_device); |
f92363d1 SR |
7989 | return; |
7990 | } | |
7991 | ||
7992 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
7993 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
7994 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
7995 | ioc->name, __FILE__, __LINE__, __func__); | |
7996 | return; | |
7997 | } | |
7998 | ||
7999 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8000 | MPI2_IOCSTATUS_MASK; | |
8001 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
8002 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
8003 | ioc->name, __FILE__, __LINE__, __func__); | |
8004 | return; | |
8005 | } | |
8006 | ||
8007 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | |
8008 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) | |
8009 | mpt3sas_transport_update_links(ioc, sas_address, handle, | |
8010 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | |
8011 | ||
8012 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); | |
8013 | _scsih_add_device(ioc, handle, 0, 1); | |
8014 | } | |
8015 | ||
f92363d1 SR |
8016 | /** |
8017 | * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events | |
8018 | * @ioc: per adapter object | |
8019 | * @event_data: event data payload | |
8020 | * Context: user. | |
8021 | * | |
8022 | * Return nothing. | |
8023 | */ | |
8024 | static void | |
8025 | _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
8026 | Mpi2EventDataIrConfigChangeList_t *event_data) | |
8027 | { | |
8028 | Mpi2EventIrConfigElement_t *element; | |
8029 | u8 element_type; | |
8030 | int i; | |
8031 | char *reason_str = NULL, *element_str = NULL; | |
8032 | ||
8033 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
8034 | ||
8035 | pr_info(MPT3SAS_FMT "raid config change: (%s), elements(%d)\n", | |
8036 | ioc->name, (le32_to_cpu(event_data->Flags) & | |
8037 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? | |
8038 | "foreign" : "native", event_data->NumElements); | |
8039 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
8040 | switch (element->ReasonCode) { | |
8041 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: | |
8042 | reason_str = "add"; | |
8043 | break; | |
8044 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: | |
8045 | reason_str = "remove"; | |
8046 | break; | |
8047 | case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE: | |
8048 | reason_str = "no change"; | |
8049 | break; | |
8050 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: | |
8051 | reason_str = "hide"; | |
8052 | break; | |
8053 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: | |
8054 | reason_str = "unhide"; | |
8055 | break; | |
8056 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: | |
8057 | reason_str = "volume_created"; | |
8058 | break; | |
8059 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: | |
8060 | reason_str = "volume_deleted"; | |
8061 | break; | |
8062 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: | |
8063 | reason_str = "pd_created"; | |
8064 | break; | |
8065 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: | |
8066 | reason_str = "pd_deleted"; | |
8067 | break; | |
8068 | default: | |
8069 | reason_str = "unknown reason"; | |
8070 | break; | |
8071 | } | |
8072 | element_type = le16_to_cpu(element->ElementFlags) & | |
8073 | MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK; | |
8074 | switch (element_type) { | |
8075 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT: | |
8076 | element_str = "volume"; | |
8077 | break; | |
8078 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT: | |
8079 | element_str = "phys disk"; | |
8080 | break; | |
8081 | case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT: | |
8082 | element_str = "hot spare"; | |
8083 | break; | |
8084 | default: | |
8085 | element_str = "unknown element"; | |
8086 | break; | |
8087 | } | |
8088 | pr_info("\t(%s:%s), vol handle(0x%04x), " \ | |
8089 | "pd handle(0x%04x), pd num(0x%02x)\n", element_str, | |
8090 | reason_str, le16_to_cpu(element->VolDevHandle), | |
8091 | le16_to_cpu(element->PhysDiskDevHandle), | |
8092 | element->PhysDiskNum); | |
8093 | } | |
8094 | } | |
f92363d1 SR |
8095 | |
8096 | /** | |
8097 | * _scsih_sas_ir_config_change_event - handle ir configuration change events | |
8098 | * @ioc: per adapter object | |
8099 | * @fw_event: The fw_event_work object | |
8100 | * Context: user. | |
8101 | * | |
8102 | * Return nothing. | |
8103 | */ | |
8104 | static void | |
8105 | _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc, | |
8106 | struct fw_event_work *fw_event) | |
8107 | { | |
8108 | Mpi2EventIrConfigElement_t *element; | |
8109 | int i; | |
8110 | u8 foreign_config; | |
35b62362 JL |
8111 | Mpi2EventDataIrConfigChangeList_t *event_data = |
8112 | (Mpi2EventDataIrConfigChangeList_t *) | |
8113 | fw_event->event_data; | |
f92363d1 | 8114 | |
7786ab6a SR |
8115 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) && |
8116 | (!ioc->hide_ir_msg)) | |
f92363d1 SR |
8117 | _scsih_sas_ir_config_change_event_debug(ioc, event_data); |
8118 | ||
f92363d1 SR |
8119 | foreign_config = (le32_to_cpu(event_data->Flags) & |
8120 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0; | |
8121 | ||
8122 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
c84b06a4 SR |
8123 | if (ioc->shost_recovery && |
8124 | ioc->hba_mpi_version_belonged != MPI2_VERSION) { | |
f92363d1 SR |
8125 | for (i = 0; i < event_data->NumElements; i++, element++) { |
8126 | if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE) | |
8127 | _scsih_ir_fastpath(ioc, | |
8128 | le16_to_cpu(element->PhysDiskDevHandle), | |
8129 | element->PhysDiskNum); | |
8130 | } | |
8131 | return; | |
8132 | } | |
7786ab6a | 8133 | |
f92363d1 SR |
8134 | for (i = 0; i < event_data->NumElements; i++, element++) { |
8135 | ||
8136 | switch (element->ReasonCode) { | |
8137 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: | |
8138 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: | |
8139 | if (!foreign_config) | |
8140 | _scsih_sas_volume_add(ioc, element); | |
8141 | break; | |
8142 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: | |
8143 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: | |
8144 | if (!foreign_config) | |
8145 | _scsih_sas_volume_delete(ioc, | |
8146 | le16_to_cpu(element->VolDevHandle)); | |
8147 | break; | |
8148 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: | |
7786ab6a SR |
8149 | if (!ioc->is_warpdrive) |
8150 | _scsih_sas_pd_hide(ioc, element); | |
f92363d1 SR |
8151 | break; |
8152 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: | |
7786ab6a SR |
8153 | if (!ioc->is_warpdrive) |
8154 | _scsih_sas_pd_expose(ioc, element); | |
f92363d1 SR |
8155 | break; |
8156 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: | |
7786ab6a SR |
8157 | if (!ioc->is_warpdrive) |
8158 | _scsih_sas_pd_add(ioc, element); | |
f92363d1 SR |
8159 | break; |
8160 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: | |
7786ab6a SR |
8161 | if (!ioc->is_warpdrive) |
8162 | _scsih_sas_pd_delete(ioc, element); | |
f92363d1 SR |
8163 | break; |
8164 | } | |
8165 | } | |
8166 | } | |
8167 | ||
8168 | /** | |
8169 | * _scsih_sas_ir_volume_event - IR volume event | |
8170 | * @ioc: per adapter object | |
8171 | * @fw_event: The fw_event_work object | |
8172 | * Context: user. | |
8173 | * | |
8174 | * Return nothing. | |
8175 | */ | |
8176 | static void | |
8177 | _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc, | |
8178 | struct fw_event_work *fw_event) | |
8179 | { | |
8180 | u64 wwid; | |
8181 | unsigned long flags; | |
8182 | struct _raid_device *raid_device; | |
8183 | u16 handle; | |
8184 | u32 state; | |
8185 | int rc; | |
35b62362 JL |
8186 | Mpi2EventDataIrVolume_t *event_data = |
8187 | (Mpi2EventDataIrVolume_t *) fw_event->event_data; | |
f92363d1 SR |
8188 | |
8189 | if (ioc->shost_recovery) | |
8190 | return; | |
8191 | ||
8192 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) | |
8193 | return; | |
8194 | ||
8195 | handle = le16_to_cpu(event_data->VolDevHandle); | |
8196 | state = le32_to_cpu(event_data->NewValue); | |
7786ab6a SR |
8197 | if (!ioc->hide_ir_msg) |
8198 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
8199 | "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n", | |
8200 | ioc->name, __func__, handle, | |
8201 | le32_to_cpu(event_data->PreviousValue), state)); | |
f92363d1 SR |
8202 | switch (state) { |
8203 | case MPI2_RAID_VOL_STATE_MISSING: | |
8204 | case MPI2_RAID_VOL_STATE_FAILED: | |
8205 | _scsih_sas_volume_delete(ioc, handle); | |
8206 | break; | |
8207 | ||
8208 | case MPI2_RAID_VOL_STATE_ONLINE: | |
8209 | case MPI2_RAID_VOL_STATE_DEGRADED: | |
8210 | case MPI2_RAID_VOL_STATE_OPTIMAL: | |
8211 | ||
8212 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
c84b06a4 | 8213 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
8214 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
8215 | ||
8216 | if (raid_device) | |
8217 | break; | |
8218 | ||
8219 | mpt3sas_config_get_volume_wwid(ioc, handle, &wwid); | |
8220 | if (!wwid) { | |
8221 | pr_err(MPT3SAS_FMT | |
8222 | "failure at %s:%d/%s()!\n", ioc->name, | |
8223 | __FILE__, __LINE__, __func__); | |
8224 | break; | |
8225 | } | |
8226 | ||
8227 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); | |
8228 | if (!raid_device) { | |
8229 | pr_err(MPT3SAS_FMT | |
8230 | "failure at %s:%d/%s()!\n", ioc->name, | |
8231 | __FILE__, __LINE__, __func__); | |
8232 | break; | |
8233 | } | |
8234 | ||
8235 | raid_device->id = ioc->sas_id++; | |
8236 | raid_device->channel = RAID_CHANNEL; | |
8237 | raid_device->handle = handle; | |
8238 | raid_device->wwid = wwid; | |
8239 | _scsih_raid_device_add(ioc, raid_device); | |
8240 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
8241 | raid_device->id, 0); | |
8242 | if (rc) | |
8243 | _scsih_raid_device_remove(ioc, raid_device); | |
8244 | break; | |
8245 | ||
8246 | case MPI2_RAID_VOL_STATE_INITIALIZING: | |
8247 | default: | |
8248 | break; | |
8249 | } | |
8250 | } | |
8251 | ||
8252 | /** | |
8253 | * _scsih_sas_ir_physical_disk_event - PD event | |
8254 | * @ioc: per adapter object | |
8255 | * @fw_event: The fw_event_work object | |
8256 | * Context: user. | |
8257 | * | |
8258 | * Return nothing. | |
8259 | */ | |
8260 | static void | |
8261 | _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc, | |
8262 | struct fw_event_work *fw_event) | |
8263 | { | |
8264 | u16 handle, parent_handle; | |
8265 | u32 state; | |
8266 | struct _sas_device *sas_device; | |
f92363d1 SR |
8267 | Mpi2ConfigReply_t mpi_reply; |
8268 | Mpi2SasDevicePage0_t sas_device_pg0; | |
8269 | u32 ioc_status; | |
35b62362 JL |
8270 | Mpi2EventDataIrPhysicalDisk_t *event_data = |
8271 | (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data; | |
f92363d1 SR |
8272 | u64 sas_address; |
8273 | ||
8274 | if (ioc->shost_recovery) | |
8275 | return; | |
8276 | ||
8277 | if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED) | |
8278 | return; | |
8279 | ||
8280 | handle = le16_to_cpu(event_data->PhysDiskDevHandle); | |
8281 | state = le32_to_cpu(event_data->NewValue); | |
8282 | ||
7786ab6a SR |
8283 | if (!ioc->hide_ir_msg) |
8284 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
8285 | "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n", | |
8286 | ioc->name, __func__, handle, | |
f92363d1 | 8287 | le32_to_cpu(event_data->PreviousValue), state)); |
7786ab6a | 8288 | |
f92363d1 SR |
8289 | switch (state) { |
8290 | case MPI2_RAID_PD_STATE_ONLINE: | |
8291 | case MPI2_RAID_PD_STATE_DEGRADED: | |
8292 | case MPI2_RAID_PD_STATE_REBUILDING: | |
8293 | case MPI2_RAID_PD_STATE_OPTIMAL: | |
8294 | case MPI2_RAID_PD_STATE_HOT_SPARE: | |
8295 | ||
7786ab6a SR |
8296 | if (!ioc->is_warpdrive) |
8297 | set_bit(handle, ioc->pd_handles); | |
f92363d1 | 8298 | |
d1cb5e49 SR |
8299 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
8300 | if (sas_device) { | |
8301 | sas_device_put(sas_device); | |
f92363d1 | 8302 | return; |
d1cb5e49 | 8303 | } |
f92363d1 SR |
8304 | |
8305 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
8306 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | |
8307 | handle))) { | |
8308 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
8309 | ioc->name, __FILE__, __LINE__, __func__); | |
8310 | return; | |
8311 | } | |
8312 | ||
8313 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8314 | MPI2_IOCSTATUS_MASK; | |
8315 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
8316 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
8317 | ioc->name, __FILE__, __LINE__, __func__); | |
8318 | return; | |
8319 | } | |
8320 | ||
8321 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | |
8322 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) | |
8323 | mpt3sas_transport_update_links(ioc, sas_address, handle, | |
8324 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | |
8325 | ||
8326 | _scsih_add_device(ioc, handle, 0, 1); | |
8327 | ||
8328 | break; | |
8329 | ||
8330 | case MPI2_RAID_PD_STATE_OFFLINE: | |
8331 | case MPI2_RAID_PD_STATE_NOT_CONFIGURED: | |
8332 | case MPI2_RAID_PD_STATE_NOT_COMPATIBLE: | |
8333 | default: | |
8334 | break; | |
8335 | } | |
8336 | } | |
8337 | ||
f92363d1 SR |
8338 | /** |
8339 | * _scsih_sas_ir_operation_status_event_debug - debug for IR op event | |
8340 | * @ioc: per adapter object | |
8341 | * @event_data: event data payload | |
8342 | * Context: user. | |
8343 | * | |
8344 | * Return nothing. | |
8345 | */ | |
8346 | static void | |
8347 | _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
8348 | Mpi2EventDataIrOperationStatus_t *event_data) | |
8349 | { | |
8350 | char *reason_str = NULL; | |
8351 | ||
8352 | switch (event_data->RAIDOperation) { | |
8353 | case MPI2_EVENT_IR_RAIDOP_RESYNC: | |
8354 | reason_str = "resync"; | |
8355 | break; | |
8356 | case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION: | |
8357 | reason_str = "online capacity expansion"; | |
8358 | break; | |
8359 | case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK: | |
8360 | reason_str = "consistency check"; | |
8361 | break; | |
8362 | case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT: | |
8363 | reason_str = "background init"; | |
8364 | break; | |
8365 | case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT: | |
8366 | reason_str = "make data consistent"; | |
8367 | break; | |
8368 | } | |
8369 | ||
8370 | if (!reason_str) | |
8371 | return; | |
8372 | ||
8373 | pr_info(MPT3SAS_FMT "raid operational status: (%s)" \ | |
8374 | "\thandle(0x%04x), percent complete(%d)\n", | |
8375 | ioc->name, reason_str, | |
8376 | le16_to_cpu(event_data->VolDevHandle), | |
8377 | event_data->PercentComplete); | |
8378 | } | |
f92363d1 SR |
8379 | |
8380 | /** | |
8381 | * _scsih_sas_ir_operation_status_event - handle RAID operation events | |
8382 | * @ioc: per adapter object | |
8383 | * @fw_event: The fw_event_work object | |
8384 | * Context: user. | |
8385 | * | |
8386 | * Return nothing. | |
8387 | */ | |
8388 | static void | |
8389 | _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc, | |
8390 | struct fw_event_work *fw_event) | |
8391 | { | |
35b62362 JL |
8392 | Mpi2EventDataIrOperationStatus_t *event_data = |
8393 | (Mpi2EventDataIrOperationStatus_t *) | |
8394 | fw_event->event_data; | |
f92363d1 SR |
8395 | static struct _raid_device *raid_device; |
8396 | unsigned long flags; | |
8397 | u16 handle; | |
8398 | ||
7786ab6a SR |
8399 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) && |
8400 | (!ioc->hide_ir_msg)) | |
f92363d1 SR |
8401 | _scsih_sas_ir_operation_status_event_debug(ioc, |
8402 | event_data); | |
f92363d1 SR |
8403 | |
8404 | /* code added for raid transport support */ | |
8405 | if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) { | |
8406 | ||
8407 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
8408 | handle = le16_to_cpu(event_data->VolDevHandle); | |
c84b06a4 | 8409 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
8410 | if (raid_device) |
8411 | raid_device->percent_complete = | |
8412 | event_data->PercentComplete; | |
8413 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
8414 | } | |
8415 | } | |
8416 | ||
8417 | /** | |
8418 | * _scsih_prep_device_scan - initialize parameters prior to device scan | |
8419 | * @ioc: per adapter object | |
8420 | * | |
8421 | * Set the deleted flag prior to device scan. If the device is found during | |
8422 | * the scan, then we clear the deleted flag. | |
8423 | */ | |
8424 | static void | |
8425 | _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc) | |
8426 | { | |
8427 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
8428 | struct scsi_device *sdev; | |
8429 | ||
8430 | shost_for_each_device(sdev, ioc->shost) { | |
8431 | sas_device_priv_data = sdev->hostdata; | |
8432 | if (sas_device_priv_data && sas_device_priv_data->sas_target) | |
8433 | sas_device_priv_data->sas_target->deleted = 1; | |
8434 | } | |
8435 | } | |
8436 | ||
8437 | /** | |
8438 | * _scsih_mark_responding_sas_device - mark a sas_devices as responding | |
8439 | * @ioc: per adapter object | |
e6d45e3e | 8440 | * @sas_device_pg0: SAS Device page 0 |
f92363d1 SR |
8441 | * |
8442 | * After host reset, find out whether devices are still responding. | |
8443 | * Used in _scsih_remove_unresponsive_sas_devices. | |
8444 | * | |
8445 | * Return nothing. | |
8446 | */ | |
8447 | static void | |
e6d45e3e SR |
8448 | _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc, |
8449 | Mpi2SasDevicePage0_t *sas_device_pg0) | |
f92363d1 SR |
8450 | { |
8451 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; | |
8452 | struct scsi_target *starget; | |
aba5a85c | 8453 | struct _sas_device *sas_device = NULL; |
f92363d1 SR |
8454 | unsigned long flags; |
8455 | ||
8456 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
8457 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) { | |
e6d45e3e SR |
8458 | if ((sas_device->sas_address == sas_device_pg0->SASAddress) && |
8459 | (sas_device->slot == sas_device_pg0->Slot)) { | |
f92363d1 SR |
8460 | sas_device->responding = 1; |
8461 | starget = sas_device->starget; | |
8462 | if (starget && starget->hostdata) { | |
8463 | sas_target_priv_data = starget->hostdata; | |
8464 | sas_target_priv_data->tm_busy = 0; | |
8465 | sas_target_priv_data->deleted = 0; | |
8466 | } else | |
8467 | sas_target_priv_data = NULL; | |
e6d45e3e | 8468 | if (starget) { |
f92363d1 | 8469 | starget_printk(KERN_INFO, starget, |
e6d45e3e SR |
8470 | "handle(0x%04x), sas_addr(0x%016llx)\n", |
8471 | sas_device_pg0->DevHandle, | |
f92363d1 | 8472 | (unsigned long long) |
e6d45e3e SR |
8473 | sas_device->sas_address); |
8474 | ||
8475 | if (sas_device->enclosure_handle != 0) | |
8476 | starget_printk(KERN_INFO, starget, | |
8477 | "enclosure logical id(0x%016llx)," | |
8478 | " slot(%d)\n", | |
8479 | (unsigned long long) | |
8480 | sas_device->enclosure_logical_id, | |
8481 | sas_device->slot); | |
8482 | } | |
8483 | if (sas_device_pg0->Flags & | |
8484 | MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) { | |
8485 | sas_device->enclosure_level = | |
aa53bb89 | 8486 | sas_device_pg0->EnclosureLevel; |
e6d45e3e SR |
8487 | memcpy(&sas_device->connector_name[0], |
8488 | &sas_device_pg0->ConnectorName[0], 4); | |
8489 | } else { | |
8490 | sas_device->enclosure_level = 0; | |
8491 | sas_device->connector_name[0] = '\0'; | |
8492 | } | |
8493 | ||
aba5a85c SR |
8494 | _scsih_get_enclosure_logicalid_chassis_slot(ioc, |
8495 | sas_device_pg0, sas_device); | |
75888956 | 8496 | |
e6d45e3e | 8497 | if (sas_device->handle == sas_device_pg0->DevHandle) |
f92363d1 SR |
8498 | goto out; |
8499 | pr_info("\thandle changed from(0x%04x)!!!\n", | |
8500 | sas_device->handle); | |
e6d45e3e | 8501 | sas_device->handle = sas_device_pg0->DevHandle; |
f92363d1 | 8502 | if (sas_target_priv_data) |
e6d45e3e SR |
8503 | sas_target_priv_data->handle = |
8504 | sas_device_pg0->DevHandle; | |
f92363d1 SR |
8505 | goto out; |
8506 | } | |
8507 | } | |
8508 | out: | |
8509 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
8510 | } | |
8511 | ||
8512 | /** | |
8513 | * _scsih_search_responding_sas_devices - | |
8514 | * @ioc: per adapter object | |
8515 | * | |
8516 | * After host reset, find out whether devices are still responding. | |
8517 | * If not remove. | |
8518 | * | |
8519 | * Return nothing. | |
8520 | */ | |
8521 | static void | |
8522 | _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc) | |
8523 | { | |
8524 | Mpi2SasDevicePage0_t sas_device_pg0; | |
8525 | Mpi2ConfigReply_t mpi_reply; | |
8526 | u16 ioc_status; | |
8527 | u16 handle; | |
8528 | u32 device_info; | |
8529 | ||
8530 | pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name); | |
8531 | ||
8532 | if (list_empty(&ioc->sas_device_list)) | |
8533 | goto out; | |
8534 | ||
8535 | handle = 0xFFFF; | |
8536 | while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
8537 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | |
8538 | handle))) { | |
8539 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8540 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 8541 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 | 8542 | break; |
e6d45e3e SR |
8543 | handle = sas_device_pg0.DevHandle = |
8544 | le16_to_cpu(sas_device_pg0.DevHandle); | |
f92363d1 SR |
8545 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
8546 | if (!(_scsih_is_end_device(device_info))) | |
8547 | continue; | |
e6d45e3e SR |
8548 | sas_device_pg0.SASAddress = |
8549 | le64_to_cpu(sas_device_pg0.SASAddress); | |
8550 | sas_device_pg0.Slot = le16_to_cpu(sas_device_pg0.Slot); | |
aa53bb89 | 8551 | sas_device_pg0.Flags = le16_to_cpu(sas_device_pg0.Flags); |
e6d45e3e | 8552 | _scsih_mark_responding_sas_device(ioc, &sas_device_pg0); |
f92363d1 SR |
8553 | } |
8554 | ||
8555 | out: | |
8556 | pr_info(MPT3SAS_FMT "search for end-devices: complete\n", | |
8557 | ioc->name); | |
8558 | } | |
8559 | ||
8560 | /** | |
8561 | * _scsih_mark_responding_raid_device - mark a raid_device as responding | |
8562 | * @ioc: per adapter object | |
8563 | * @wwid: world wide identifier for raid volume | |
8564 | * @handle: device handle | |
8565 | * | |
8566 | * After host reset, find out whether devices are still responding. | |
8567 | * Used in _scsih_remove_unresponsive_raid_devices. | |
8568 | * | |
8569 | * Return nothing. | |
8570 | */ | |
8571 | static void | |
8572 | _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid, | |
8573 | u16 handle) | |
8574 | { | |
7786ab6a | 8575 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; |
f92363d1 SR |
8576 | struct scsi_target *starget; |
8577 | struct _raid_device *raid_device; | |
8578 | unsigned long flags; | |
8579 | ||
8580 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
8581 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
8582 | if (raid_device->wwid == wwid && raid_device->starget) { | |
8583 | starget = raid_device->starget; | |
8584 | if (starget && starget->hostdata) { | |
8585 | sas_target_priv_data = starget->hostdata; | |
8586 | sas_target_priv_data->deleted = 0; | |
8587 | } else | |
8588 | sas_target_priv_data = NULL; | |
8589 | raid_device->responding = 1; | |
8590 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
8591 | starget_printk(KERN_INFO, raid_device->starget, | |
8592 | "handle(0x%04x), wwid(0x%016llx)\n", handle, | |
8593 | (unsigned long long)raid_device->wwid); | |
7786ab6a | 8594 | |
7786ab6a SR |
8595 | /* |
8596 | * WARPDRIVE: The handles of the PDs might have changed | |
8597 | * across the host reset so re-initialize the | |
8598 | * required data for Direct IO | |
8599 | */ | |
c84b06a4 | 8600 | mpt3sas_init_warpdrive_properties(ioc, raid_device); |
f92363d1 SR |
8601 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
8602 | if (raid_device->handle == handle) { | |
8603 | spin_unlock_irqrestore(&ioc->raid_device_lock, | |
8604 | flags); | |
8605 | return; | |
8606 | } | |
8607 | pr_info("\thandle changed from(0x%04x)!!!\n", | |
8608 | raid_device->handle); | |
8609 | raid_device->handle = handle; | |
8610 | if (sas_target_priv_data) | |
8611 | sas_target_priv_data->handle = handle; | |
8612 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
8613 | return; | |
8614 | } | |
8615 | } | |
8616 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
8617 | } | |
8618 | ||
8619 | /** | |
8620 | * _scsih_search_responding_raid_devices - | |
8621 | * @ioc: per adapter object | |
8622 | * | |
8623 | * After host reset, find out whether devices are still responding. | |
8624 | * If not remove. | |
8625 | * | |
8626 | * Return nothing. | |
8627 | */ | |
8628 | static void | |
8629 | _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc) | |
8630 | { | |
8631 | Mpi2RaidVolPage1_t volume_pg1; | |
8632 | Mpi2RaidVolPage0_t volume_pg0; | |
8633 | Mpi2RaidPhysDiskPage0_t pd_pg0; | |
8634 | Mpi2ConfigReply_t mpi_reply; | |
8635 | u16 ioc_status; | |
8636 | u16 handle; | |
8637 | u8 phys_disk_num; | |
8638 | ||
8639 | if (!ioc->ir_firmware) | |
8640 | return; | |
8641 | ||
8642 | pr_info(MPT3SAS_FMT "search for raid volumes: start\n", | |
8643 | ioc->name); | |
8644 | ||
8645 | if (list_empty(&ioc->raid_device_list)) | |
8646 | goto out; | |
8647 | ||
8648 | handle = 0xFFFF; | |
8649 | while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply, | |
8650 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { | |
8651 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8652 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 8653 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 SR |
8654 | break; |
8655 | handle = le16_to_cpu(volume_pg1.DevHandle); | |
8656 | ||
8657 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, | |
8658 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
8659 | sizeof(Mpi2RaidVolPage0_t))) | |
8660 | continue; | |
8661 | ||
8662 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || | |
8663 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || | |
8664 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) | |
8665 | _scsih_mark_responding_raid_device(ioc, | |
8666 | le64_to_cpu(volume_pg1.WWID), handle); | |
8667 | } | |
8668 | ||
8669 | /* refresh the pd_handles */ | |
7786ab6a | 8670 | if (!ioc->is_warpdrive) { |
f92363d1 SR |
8671 | phys_disk_num = 0xFF; |
8672 | memset(ioc->pd_handles, 0, ioc->pd_handles_sz); | |
8673 | while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | |
8674 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, | |
8675 | phys_disk_num))) { | |
8676 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8677 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 8678 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 SR |
8679 | break; |
8680 | phys_disk_num = pd_pg0.PhysDiskNum; | |
8681 | handle = le16_to_cpu(pd_pg0.DevHandle); | |
8682 | set_bit(handle, ioc->pd_handles); | |
8683 | } | |
7786ab6a | 8684 | } |
f92363d1 SR |
8685 | out: |
8686 | pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n", | |
8687 | ioc->name); | |
8688 | } | |
8689 | ||
8690 | /** | |
8691 | * _scsih_mark_responding_expander - mark a expander as responding | |
8692 | * @ioc: per adapter object | |
aba5a85c | 8693 | * @expander_pg0:SAS Expander Config Page0 |
f92363d1 SR |
8694 | * |
8695 | * After host reset, find out whether devices are still responding. | |
8696 | * Used in _scsih_remove_unresponsive_expanders. | |
8697 | * | |
8698 | * Return nothing. | |
8699 | */ | |
8700 | static void | |
aba5a85c SR |
8701 | _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc, |
8702 | Mpi2ExpanderPage0_t *expander_pg0) | |
f92363d1 | 8703 | { |
aba5a85c | 8704 | struct _sas_node *sas_expander = NULL; |
f92363d1 | 8705 | unsigned long flags; |
aba5a85c SR |
8706 | int i, encl_pg0_rc = -1; |
8707 | Mpi2ConfigReply_t mpi_reply; | |
8708 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
8709 | u16 handle = le16_to_cpu(expander_pg0->DevHandle); | |
8710 | u64 sas_address = le64_to_cpu(expander_pg0->SASAddress); | |
8711 | ||
8712 | if (le16_to_cpu(expander_pg0->EnclosureHandle)) { | |
8713 | encl_pg0_rc = mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
8714 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
8715 | le16_to_cpu(expander_pg0->EnclosureHandle)); | |
8716 | if (encl_pg0_rc) | |
8717 | pr_info(MPT3SAS_FMT | |
8718 | "Enclosure Pg0 read failed for handle(0x%04x)\n", | |
8719 | ioc->name, | |
8720 | le16_to_cpu(expander_pg0->EnclosureHandle)); | |
8721 | } | |
f92363d1 SR |
8722 | |
8723 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
8724 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { | |
8725 | if (sas_expander->sas_address != sas_address) | |
8726 | continue; | |
8727 | sas_expander->responding = 1; | |
aba5a85c SR |
8728 | |
8729 | if (!encl_pg0_rc) | |
8730 | sas_expander->enclosure_logical_id = | |
8731 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
8732 | ||
8733 | sas_expander->enclosure_handle = | |
8734 | le16_to_cpu(expander_pg0->EnclosureHandle); | |
8735 | ||
f92363d1 SR |
8736 | if (sas_expander->handle == handle) |
8737 | goto out; | |
8738 | pr_info("\texpander(0x%016llx): handle changed" \ | |
8739 | " from(0x%04x) to (0x%04x)!!!\n", | |
8740 | (unsigned long long)sas_expander->sas_address, | |
8741 | sas_expander->handle, handle); | |
8742 | sas_expander->handle = handle; | |
8743 | for (i = 0 ; i < sas_expander->num_phys ; i++) | |
8744 | sas_expander->phy[i].handle = handle; | |
8745 | goto out; | |
8746 | } | |
8747 | out: | |
8748 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
8749 | } | |
8750 | ||
8751 | /** | |
8752 | * _scsih_search_responding_expanders - | |
8753 | * @ioc: per adapter object | |
8754 | * | |
8755 | * After host reset, find out whether devices are still responding. | |
8756 | * If not remove. | |
8757 | * | |
8758 | * Return nothing. | |
8759 | */ | |
8760 | static void | |
8761 | _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc) | |
8762 | { | |
8763 | Mpi2ExpanderPage0_t expander_pg0; | |
8764 | Mpi2ConfigReply_t mpi_reply; | |
8765 | u16 ioc_status; | |
8766 | u64 sas_address; | |
8767 | u16 handle; | |
8768 | ||
8769 | pr_info(MPT3SAS_FMT "search for expanders: start\n", ioc->name); | |
8770 | ||
8771 | if (list_empty(&ioc->sas_expander_list)) | |
8772 | goto out; | |
8773 | ||
8774 | handle = 0xFFFF; | |
8775 | while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | |
8776 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { | |
8777 | ||
8778 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8779 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 8780 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 SR |
8781 | break; |
8782 | ||
8783 | handle = le16_to_cpu(expander_pg0.DevHandle); | |
8784 | sas_address = le64_to_cpu(expander_pg0.SASAddress); | |
8785 | pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n", | |
8786 | handle, | |
8787 | (unsigned long long)sas_address); | |
aba5a85c | 8788 | _scsih_mark_responding_expander(ioc, &expander_pg0); |
f92363d1 SR |
8789 | } |
8790 | ||
8791 | out: | |
8792 | pr_info(MPT3SAS_FMT "search for expanders: complete\n", ioc->name); | |
8793 | } | |
8794 | ||
8795 | /** | |
3075ac49 | 8796 | * _scsih_remove_unresponding_devices - removing unresponding devices |
f92363d1 SR |
8797 | * @ioc: per adapter object |
8798 | * | |
8799 | * Return nothing. | |
8800 | */ | |
8801 | static void | |
3075ac49 | 8802 | _scsih_remove_unresponding_devices(struct MPT3SAS_ADAPTER *ioc) |
f92363d1 SR |
8803 | { |
8804 | struct _sas_device *sas_device, *sas_device_next; | |
8805 | struct _sas_node *sas_expander, *sas_expander_next; | |
8806 | struct _raid_device *raid_device, *raid_device_next; | |
3075ac49 | 8807 | struct _pcie_device *pcie_device, *pcie_device_next; |
f92363d1 SR |
8808 | struct list_head tmp_list; |
8809 | unsigned long flags; | |
d1cb5e49 | 8810 | LIST_HEAD(head); |
f92363d1 SR |
8811 | |
8812 | pr_info(MPT3SAS_FMT "removing unresponding devices: start\n", | |
8813 | ioc->name); | |
8814 | ||
8815 | /* removing unresponding end devices */ | |
8816 | pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n", | |
8817 | ioc->name); | |
d1cb5e49 SR |
8818 | /* |
8819 | * Iterate, pulling off devices marked as non-responding. We become the | |
8820 | * owner for the reference the list had on any object we prune. | |
8821 | */ | |
8822 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
f92363d1 SR |
8823 | list_for_each_entry_safe(sas_device, sas_device_next, |
8824 | &ioc->sas_device_list, list) { | |
8825 | if (!sas_device->responding) | |
d1cb5e49 | 8826 | list_move_tail(&sas_device->list, &head); |
f92363d1 SR |
8827 | else |
8828 | sas_device->responding = 0; | |
8829 | } | |
d1cb5e49 SR |
8830 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
8831 | ||
8832 | /* | |
8833 | * Now, uninitialize and remove the unresponding devices we pruned. | |
8834 | */ | |
8835 | list_for_each_entry_safe(sas_device, sas_device_next, &head, list) { | |
8836 | _scsih_remove_device(ioc, sas_device); | |
8837 | list_del_init(&sas_device->list); | |
8838 | sas_device_put(sas_device); | |
8839 | } | |
f92363d1 | 8840 | |
3075ac49 SPS |
8841 | pr_info(MPT3SAS_FMT |
8842 | " Removing unresponding devices: pcie end-devices\n" | |
8843 | , ioc->name); | |
8844 | INIT_LIST_HEAD(&head); | |
8845 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
8846 | list_for_each_entry_safe(pcie_device, pcie_device_next, | |
8847 | &ioc->pcie_device_list, list) { | |
8848 | if (!pcie_device->responding) | |
8849 | list_move_tail(&pcie_device->list, &head); | |
8850 | else | |
8851 | pcie_device->responding = 0; | |
8852 | } | |
8853 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
8854 | ||
8855 | list_for_each_entry_safe(pcie_device, pcie_device_next, &head, list) { | |
8856 | _scsih_pcie_device_remove_from_sml(ioc, pcie_device); | |
8857 | list_del_init(&pcie_device->list); | |
8858 | pcie_device_put(pcie_device); | |
8859 | } | |
8860 | ||
f92363d1 SR |
8861 | /* removing unresponding volumes */ |
8862 | if (ioc->ir_firmware) { | |
8863 | pr_info(MPT3SAS_FMT "removing unresponding devices: volumes\n", | |
8864 | ioc->name); | |
8865 | list_for_each_entry_safe(raid_device, raid_device_next, | |
8866 | &ioc->raid_device_list, list) { | |
8867 | if (!raid_device->responding) | |
8868 | _scsih_sas_volume_delete(ioc, | |
8869 | raid_device->handle); | |
8870 | else | |
8871 | raid_device->responding = 0; | |
8872 | } | |
8873 | } | |
8874 | ||
8875 | /* removing unresponding expanders */ | |
8876 | pr_info(MPT3SAS_FMT "removing unresponding devices: expanders\n", | |
8877 | ioc->name); | |
8878 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
8879 | INIT_LIST_HEAD(&tmp_list); | |
8880 | list_for_each_entry_safe(sas_expander, sas_expander_next, | |
8881 | &ioc->sas_expander_list, list) { | |
8882 | if (!sas_expander->responding) | |
8883 | list_move_tail(&sas_expander->list, &tmp_list); | |
8884 | else | |
8885 | sas_expander->responding = 0; | |
8886 | } | |
8887 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
8888 | list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list, | |
8889 | list) { | |
f92363d1 SR |
8890 | _scsih_expander_node_remove(ioc, sas_expander); |
8891 | } | |
8892 | ||
8893 | pr_info(MPT3SAS_FMT "removing unresponding devices: complete\n", | |
8894 | ioc->name); | |
8895 | ||
8896 | /* unblock devices */ | |
8897 | _scsih_ublock_io_all_device(ioc); | |
8898 | } | |
8899 | ||
8900 | static void | |
8901 | _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc, | |
8902 | struct _sas_node *sas_expander, u16 handle) | |
8903 | { | |
8904 | Mpi2ExpanderPage1_t expander_pg1; | |
8905 | Mpi2ConfigReply_t mpi_reply; | |
8906 | int i; | |
8907 | ||
8908 | for (i = 0 ; i < sas_expander->num_phys ; i++) { | |
8909 | if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply, | |
8910 | &expander_pg1, i, handle))) { | |
8911 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
8912 | ioc->name, __FILE__, __LINE__, __func__); | |
8913 | return; | |
8914 | } | |
8915 | ||
8916 | mpt3sas_transport_update_links(ioc, sas_expander->sas_address, | |
8917 | le16_to_cpu(expander_pg1.AttachedDevHandle), i, | |
8918 | expander_pg1.NegotiatedLinkRate >> 4); | |
8919 | } | |
8920 | } | |
8921 | ||
8922 | /** | |
8923 | * _scsih_scan_for_devices_after_reset - scan for devices after host reset | |
8924 | * @ioc: per adapter object | |
8925 | * | |
8926 | * Return nothing. | |
8927 | */ | |
8928 | static void | |
8929 | _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc) | |
8930 | { | |
8931 | Mpi2ExpanderPage0_t expander_pg0; | |
8932 | Mpi2SasDevicePage0_t sas_device_pg0; | |
8933 | Mpi2RaidVolPage1_t volume_pg1; | |
8934 | Mpi2RaidVolPage0_t volume_pg0; | |
8935 | Mpi2RaidPhysDiskPage0_t pd_pg0; | |
8936 | Mpi2EventIrConfigElement_t element; | |
8937 | Mpi2ConfigReply_t mpi_reply; | |
8938 | u8 phys_disk_num; | |
8939 | u16 ioc_status; | |
8940 | u16 handle, parent_handle; | |
8941 | u64 sas_address; | |
8942 | struct _sas_device *sas_device; | |
8943 | struct _sas_node *expander_device; | |
8944 | static struct _raid_device *raid_device; | |
8945 | u8 retry_count; | |
8946 | unsigned long flags; | |
8947 | ||
8948 | pr_info(MPT3SAS_FMT "scan devices: start\n", ioc->name); | |
8949 | ||
8950 | _scsih_sas_host_refresh(ioc); | |
8951 | ||
8952 | pr_info(MPT3SAS_FMT "\tscan devices: expanders start\n", ioc->name); | |
8953 | ||
8954 | /* expanders */ | |
8955 | handle = 0xFFFF; | |
8956 | while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | |
8957 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { | |
8958 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8959 | MPI2_IOCSTATUS_MASK; | |
f92363d1 SR |
8960 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
8961 | pr_info(MPT3SAS_FMT "\tbreak from expander scan: " \ | |
8962 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
8963 | ioc->name, ioc_status, | |
8964 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
8965 | break; | |
8966 | } | |
8967 | handle = le16_to_cpu(expander_pg0.DevHandle); | |
8968 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
8969 | expander_device = mpt3sas_scsih_expander_find_by_sas_address( | |
8970 | ioc, le64_to_cpu(expander_pg0.SASAddress)); | |
8971 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
8972 | if (expander_device) | |
8973 | _scsih_refresh_expander_links(ioc, expander_device, | |
8974 | handle); | |
8975 | else { | |
8976 | pr_info(MPT3SAS_FMT "\tBEFORE adding expander: " \ | |
8977 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
8978 | handle, (unsigned long long) | |
8979 | le64_to_cpu(expander_pg0.SASAddress)); | |
8980 | _scsih_expander_add(ioc, handle); | |
8981 | pr_info(MPT3SAS_FMT "\tAFTER adding expander: " \ | |
8982 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
8983 | handle, (unsigned long long) | |
8984 | le64_to_cpu(expander_pg0.SASAddress)); | |
8985 | } | |
8986 | } | |
8987 | ||
8988 | pr_info(MPT3SAS_FMT "\tscan devices: expanders complete\n", | |
8989 | ioc->name); | |
8990 | ||
8991 | if (!ioc->ir_firmware) | |
8992 | goto skip_to_sas; | |
8993 | ||
8994 | pr_info(MPT3SAS_FMT "\tscan devices: phys disk start\n", ioc->name); | |
8995 | ||
8996 | /* phys disk */ | |
8997 | phys_disk_num = 0xFF; | |
8998 | while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | |
8999 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, | |
9000 | phys_disk_num))) { | |
9001 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9002 | MPI2_IOCSTATUS_MASK; | |
f92363d1 SR |
9003 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
9004 | pr_info(MPT3SAS_FMT "\tbreak from phys disk scan: "\ | |
9005 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9006 | ioc->name, ioc_status, | |
9007 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
9008 | break; | |
9009 | } | |
9010 | phys_disk_num = pd_pg0.PhysDiskNum; | |
9011 | handle = le16_to_cpu(pd_pg0.DevHandle); | |
d1cb5e49 SR |
9012 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
9013 | if (sas_device) { | |
9014 | sas_device_put(sas_device); | |
f92363d1 | 9015 | continue; |
d1cb5e49 | 9016 | } |
f92363d1 SR |
9017 | if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
9018 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | |
9019 | handle) != 0) | |
9020 | continue; | |
9021 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9022 | MPI2_IOCSTATUS_MASK; | |
9023 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
9024 | pr_info(MPT3SAS_FMT "\tbreak from phys disk scan " \ | |
9025 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9026 | ioc->name, ioc_status, | |
9027 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
9028 | break; | |
9029 | } | |
9030 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | |
9031 | if (!_scsih_get_sas_address(ioc, parent_handle, | |
9032 | &sas_address)) { | |
9033 | pr_info(MPT3SAS_FMT "\tBEFORE adding phys disk: " \ | |
9034 | " handle (0x%04x), sas_addr(0x%016llx)\n", | |
9035 | ioc->name, handle, (unsigned long long) | |
9036 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
9037 | mpt3sas_transport_update_links(ioc, sas_address, | |
9038 | handle, sas_device_pg0.PhyNum, | |
9039 | MPI2_SAS_NEG_LINK_RATE_1_5); | |
9040 | set_bit(handle, ioc->pd_handles); | |
9041 | retry_count = 0; | |
9042 | /* This will retry adding the end device. | |
9043 | * _scsih_add_device() will decide on retries and | |
9044 | * return "1" when it should be retried | |
9045 | */ | |
9046 | while (_scsih_add_device(ioc, handle, retry_count++, | |
9047 | 1)) { | |
9048 | ssleep(1); | |
9049 | } | |
9050 | pr_info(MPT3SAS_FMT "\tAFTER adding phys disk: " \ | |
9051 | " handle (0x%04x), sas_addr(0x%016llx)\n", | |
9052 | ioc->name, handle, (unsigned long long) | |
9053 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
9054 | } | |
9055 | } | |
9056 | ||
9057 | pr_info(MPT3SAS_FMT "\tscan devices: phys disk complete\n", | |
9058 | ioc->name); | |
9059 | ||
9060 | pr_info(MPT3SAS_FMT "\tscan devices: volumes start\n", ioc->name); | |
9061 | ||
9062 | /* volumes */ | |
9063 | handle = 0xFFFF; | |
9064 | while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply, | |
9065 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { | |
9066 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9067 | MPI2_IOCSTATUS_MASK; | |
f92363d1 SR |
9068 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
9069 | pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \ | |
9070 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9071 | ioc->name, ioc_status, | |
9072 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
9073 | break; | |
9074 | } | |
9075 | handle = le16_to_cpu(volume_pg1.DevHandle); | |
9076 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
9077 | raid_device = _scsih_raid_device_find_by_wwid(ioc, | |
9078 | le64_to_cpu(volume_pg1.WWID)); | |
9079 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
9080 | if (raid_device) | |
9081 | continue; | |
9082 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, | |
9083 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
9084 | sizeof(Mpi2RaidVolPage0_t))) | |
9085 | continue; | |
9086 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9087 | MPI2_IOCSTATUS_MASK; | |
9088 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
9089 | pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \ | |
9090 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9091 | ioc->name, ioc_status, | |
9092 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
9093 | break; | |
9094 | } | |
9095 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || | |
9096 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || | |
9097 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) { | |
9098 | memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t)); | |
9099 | element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED; | |
9100 | element.VolDevHandle = volume_pg1.DevHandle; | |
9101 | pr_info(MPT3SAS_FMT | |
9102 | "\tBEFORE adding volume: handle (0x%04x)\n", | |
9103 | ioc->name, volume_pg1.DevHandle); | |
9104 | _scsih_sas_volume_add(ioc, &element); | |
9105 | pr_info(MPT3SAS_FMT | |
9106 | "\tAFTER adding volume: handle (0x%04x)\n", | |
9107 | ioc->name, volume_pg1.DevHandle); | |
9108 | } | |
9109 | } | |
9110 | ||
9111 | pr_info(MPT3SAS_FMT "\tscan devices: volumes complete\n", | |
9112 | ioc->name); | |
9113 | ||
9114 | skip_to_sas: | |
9115 | ||
9116 | pr_info(MPT3SAS_FMT "\tscan devices: end devices start\n", | |
9117 | ioc->name); | |
9118 | ||
9119 | /* sas devices */ | |
9120 | handle = 0xFFFF; | |
9121 | while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
9122 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | |
9123 | handle))) { | |
9124 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9125 | MPI2_IOCSTATUS_MASK; | |
f92363d1 SR |
9126 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
9127 | pr_info(MPT3SAS_FMT "\tbreak from end device scan:"\ | |
9128 | " ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9129 | ioc->name, ioc_status, | |
9130 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
9131 | break; | |
9132 | } | |
9133 | handle = le16_to_cpu(sas_device_pg0.DevHandle); | |
9134 | if (!(_scsih_is_end_device( | |
9135 | le32_to_cpu(sas_device_pg0.DeviceInfo)))) | |
9136 | continue; | |
d1cb5e49 | 9137 | sas_device = mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 | 9138 | le64_to_cpu(sas_device_pg0.SASAddress)); |
d1cb5e49 SR |
9139 | if (sas_device) { |
9140 | sas_device_put(sas_device); | |
f92363d1 | 9141 | continue; |
d1cb5e49 | 9142 | } |
f92363d1 SR |
9143 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
9144 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) { | |
9145 | pr_info(MPT3SAS_FMT "\tBEFORE adding end device: " \ | |
9146 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
9147 | handle, (unsigned long long) | |
9148 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
9149 | mpt3sas_transport_update_links(ioc, sas_address, handle, | |
9150 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | |
9151 | retry_count = 0; | |
9152 | /* This will retry adding the end device. | |
9153 | * _scsih_add_device() will decide on retries and | |
9154 | * return "1" when it should be retried | |
9155 | */ | |
9156 | while (_scsih_add_device(ioc, handle, retry_count++, | |
9157 | 0)) { | |
9158 | ssleep(1); | |
9159 | } | |
9160 | pr_info(MPT3SAS_FMT "\tAFTER adding end device: " \ | |
9161 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
9162 | handle, (unsigned long long) | |
9163 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
9164 | } | |
9165 | } | |
9166 | pr_info(MPT3SAS_FMT "\tscan devices: end devices complete\n", | |
9167 | ioc->name); | |
9168 | ||
9169 | pr_info(MPT3SAS_FMT "scan devices: complete\n", ioc->name); | |
9170 | } | |
9171 | /** | |
9172 | * mpt3sas_scsih_reset_handler - reset callback handler (for scsih) | |
9173 | * @ioc: per adapter object | |
9174 | * @reset_phase: phase | |
9175 | * | |
9176 | * The handler for doing any required cleanup or initialization. | |
9177 | * | |
9178 | * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET, | |
9179 | * MPT3_IOC_DONE_RESET | |
9180 | * | |
9181 | * Return nothing. | |
9182 | */ | |
9183 | void | |
9184 | mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase) | |
9185 | { | |
9186 | switch (reset_phase) { | |
9187 | case MPT3_IOC_PRE_RESET: | |
9188 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
9189 | "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__)); | |
9190 | break; | |
9191 | case MPT3_IOC_AFTER_RESET: | |
9192 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
9193 | "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__)); | |
9194 | if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) { | |
9195 | ioc->scsih_cmds.status |= MPT3_CMD_RESET; | |
9196 | mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid); | |
9197 | complete(&ioc->scsih_cmds.done); | |
9198 | } | |
9199 | if (ioc->tm_cmds.status & MPT3_CMD_PENDING) { | |
9200 | ioc->tm_cmds.status |= MPT3_CMD_RESET; | |
9201 | mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid); | |
9202 | complete(&ioc->tm_cmds.done); | |
9203 | } | |
9204 | ||
c696f7b8 SPS |
9205 | memset(ioc->pend_os_device_add, 0, ioc->pend_os_device_add_sz); |
9206 | memset(ioc->device_remove_in_progress, 0, | |
9207 | ioc->device_remove_in_progress_sz); | |
f92363d1 SR |
9208 | _scsih_fw_event_cleanup_queue(ioc); |
9209 | _scsih_flush_running_cmds(ioc); | |
9210 | break; | |
9211 | case MPT3_IOC_DONE_RESET: | |
9212 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
9213 | "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__)); | |
9214 | if ((!ioc->is_driver_loading) && !(disable_discovery > 0 && | |
9215 | !ioc->sas_hba.num_phys)) { | |
9216 | _scsih_prep_device_scan(ioc); | |
9217 | _scsih_search_responding_sas_devices(ioc); | |
9218 | _scsih_search_responding_raid_devices(ioc); | |
9219 | _scsih_search_responding_expanders(ioc); | |
9220 | _scsih_error_recovery_delete_devices(ioc); | |
9221 | } | |
9222 | break; | |
9223 | } | |
9224 | } | |
9225 | ||
9226 | /** | |
9227 | * _mpt3sas_fw_work - delayed task for processing firmware events | |
9228 | * @ioc: per adapter object | |
9229 | * @fw_event: The fw_event_work object | |
9230 | * Context: user. | |
9231 | * | |
9232 | * Return nothing. | |
9233 | */ | |
9234 | static void | |
9235 | _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event) | |
9236 | { | |
146b16c8 SR |
9237 | _scsih_fw_event_del_from_list(ioc, fw_event); |
9238 | ||
f92363d1 | 9239 | /* the queue is being flushed so ignore this event */ |
146b16c8 SR |
9240 | if (ioc->remove_host || ioc->pci_error_recovery) { |
9241 | fw_event_work_put(fw_event); | |
f92363d1 SR |
9242 | return; |
9243 | } | |
9244 | ||
9245 | switch (fw_event->event) { | |
9246 | case MPT3SAS_PROCESS_TRIGGER_DIAG: | |
35b62362 JL |
9247 | mpt3sas_process_trigger_data(ioc, |
9248 | (struct SL_WH_TRIGGERS_EVENT_DATA_T *) | |
9249 | fw_event->event_data); | |
f92363d1 SR |
9250 | break; |
9251 | case MPT3SAS_REMOVE_UNRESPONDING_DEVICES: | |
146b16c8 SR |
9252 | while (scsi_host_in_recovery(ioc->shost) || |
9253 | ioc->shost_recovery) { | |
9254 | /* | |
9255 | * If we're unloading, bail. Otherwise, this can become | |
9256 | * an infinite loop. | |
9257 | */ | |
9258 | if (ioc->remove_host) | |
9259 | goto out; | |
f92363d1 | 9260 | ssleep(1); |
146b16c8 | 9261 | } |
3075ac49 | 9262 | _scsih_remove_unresponding_devices(ioc); |
f92363d1 SR |
9263 | _scsih_scan_for_devices_after_reset(ioc); |
9264 | break; | |
9265 | case MPT3SAS_PORT_ENABLE_COMPLETE: | |
9266 | ioc->start_scan = 0; | |
9267 | if (missing_delay[0] != -1 && missing_delay[1] != -1) | |
9268 | mpt3sas_base_update_missing_delay(ioc, missing_delay[0], | |
9269 | missing_delay[1]); | |
9270 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
9271 | "port enable: complete from worker thread\n", | |
9272 | ioc->name)); | |
9273 | break; | |
0f624c39 SR |
9274 | case MPT3SAS_TURN_ON_PFA_LED: |
9275 | _scsih_turn_on_pfa_led(ioc, fw_event->device_handle); | |
f92363d1 SR |
9276 | break; |
9277 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: | |
9278 | _scsih_sas_topology_change_event(ioc, fw_event); | |
9279 | break; | |
9280 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: | |
9281 | _scsih_sas_device_status_change_event(ioc, fw_event); | |
9282 | break; | |
9283 | case MPI2_EVENT_SAS_DISCOVERY: | |
9284 | _scsih_sas_discovery_event(ioc, fw_event); | |
9285 | break; | |
9286 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: | |
9287 | _scsih_sas_broadcast_primitive_event(ioc, fw_event); | |
9288 | break; | |
9289 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: | |
9290 | _scsih_sas_enclosure_dev_status_change_event(ioc, | |
9291 | fw_event); | |
9292 | break; | |
9293 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: | |
9294 | _scsih_sas_ir_config_change_event(ioc, fw_event); | |
9295 | break; | |
9296 | case MPI2_EVENT_IR_VOLUME: | |
9297 | _scsih_sas_ir_volume_event(ioc, fw_event); | |
9298 | break; | |
9299 | case MPI2_EVENT_IR_PHYSICAL_DISK: | |
9300 | _scsih_sas_ir_physical_disk_event(ioc, fw_event); | |
9301 | break; | |
9302 | case MPI2_EVENT_IR_OPERATION_STATUS: | |
9303 | _scsih_sas_ir_operation_status_event(ioc, fw_event); | |
9304 | break; | |
4318c734 SPS |
9305 | case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE: |
9306 | _scsih_pcie_device_status_change_event(ioc, fw_event); | |
9307 | break; | |
9308 | case MPI2_EVENT_PCIE_ENUMERATION: | |
9309 | _scsih_pcie_enumeration_event(ioc, fw_event); | |
9310 | break; | |
9311 | case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST: | |
9312 | _scsih_pcie_topology_change_event(ioc, fw_event); | |
9313 | return; | |
9314 | break; | |
f92363d1 | 9315 | } |
146b16c8 SR |
9316 | out: |
9317 | fw_event_work_put(fw_event); | |
f92363d1 SR |
9318 | } |
9319 | ||
9320 | /** | |
9321 | * _firmware_event_work | |
9322 | * @ioc: per adapter object | |
9323 | * @work: The fw_event_work object | |
9324 | * Context: user. | |
9325 | * | |
9326 | * wrappers for the work thread handling firmware events | |
9327 | * | |
9328 | * Return nothing. | |
9329 | */ | |
9330 | ||
9331 | static void | |
9332 | _firmware_event_work(struct work_struct *work) | |
9333 | { | |
9334 | struct fw_event_work *fw_event = container_of(work, | |
9335 | struct fw_event_work, work); | |
9336 | ||
9337 | _mpt3sas_fw_work(fw_event->ioc, fw_event); | |
9338 | } | |
9339 | ||
9340 | /** | |
9341 | * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time) | |
9342 | * @ioc: per adapter object | |
9343 | * @msix_index: MSIX table index supplied by the OS | |
9344 | * @reply: reply message frame(lower 32bit addr) | |
9345 | * Context: interrupt. | |
9346 | * | |
9347 | * This function merely adds a new work task into ioc->firmware_event_thread. | |
9348 | * The tasks are worked from _firmware_event_work in user context. | |
9349 | * | |
9350 | * Return 1 meaning mf should be freed from _base_interrupt | |
9351 | * 0 means the mf is freed from this function. | |
9352 | */ | |
9353 | u8 | |
9354 | mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index, | |
9355 | u32 reply) | |
9356 | { | |
9357 | struct fw_event_work *fw_event; | |
9358 | Mpi2EventNotificationReply_t *mpi_reply; | |
9359 | u16 event; | |
9360 | u16 sz; | |
a470a51c | 9361 | Mpi26EventDataActiveCableExcept_t *ActiveCableEventData; |
f92363d1 SR |
9362 | |
9363 | /* events turned off due to host reset or driver unloading */ | |
9364 | if (ioc->remove_host || ioc->pci_error_recovery) | |
9365 | return 1; | |
9366 | ||
9367 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
9368 | ||
9369 | if (unlikely(!mpi_reply)) { | |
9370 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", | |
9371 | ioc->name, __FILE__, __LINE__, __func__); | |
9372 | return 1; | |
9373 | } | |
9374 | ||
9375 | event = le16_to_cpu(mpi_reply->Event); | |
9376 | ||
9377 | if (event != MPI2_EVENT_LOG_ENTRY_ADDED) | |
9378 | mpt3sas_trigger_event(ioc, event, 0); | |
9379 | ||
9380 | switch (event) { | |
9381 | /* handle these */ | |
9382 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: | |
9383 | { | |
9384 | Mpi2EventDataSasBroadcastPrimitive_t *baen_data = | |
9385 | (Mpi2EventDataSasBroadcastPrimitive_t *) | |
9386 | mpi_reply->EventData; | |
9387 | ||
9388 | if (baen_data->Primitive != | |
9389 | MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT) | |
9390 | return 1; | |
9391 | ||
9392 | if (ioc->broadcast_aen_busy) { | |
9393 | ioc->broadcast_aen_pending++; | |
9394 | return 1; | |
9395 | } else | |
9396 | ioc->broadcast_aen_busy = 1; | |
9397 | break; | |
9398 | } | |
9399 | ||
9400 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: | |
9401 | _scsih_check_topo_delete_events(ioc, | |
9402 | (Mpi2EventDataSasTopologyChangeList_t *) | |
9403 | mpi_reply->EventData); | |
9404 | break; | |
4318c734 SPS |
9405 | case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST: |
9406 | _scsih_check_pcie_topo_remove_events(ioc, | |
9407 | (Mpi26EventDataPCIeTopologyChangeList_t *) | |
9408 | mpi_reply->EventData); | |
9409 | break; | |
f92363d1 SR |
9410 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: |
9411 | _scsih_check_ir_config_unhide_events(ioc, | |
9412 | (Mpi2EventDataIrConfigChangeList_t *) | |
9413 | mpi_reply->EventData); | |
9414 | break; | |
9415 | case MPI2_EVENT_IR_VOLUME: | |
9416 | _scsih_check_volume_delete_events(ioc, | |
9417 | (Mpi2EventDataIrVolume_t *) | |
9418 | mpi_reply->EventData); | |
9419 | break; | |
7786ab6a SR |
9420 | case MPI2_EVENT_LOG_ENTRY_ADDED: |
9421 | { | |
9422 | Mpi2EventDataLogEntryAdded_t *log_entry; | |
9423 | u32 *log_code; | |
9424 | ||
9425 | if (!ioc->is_warpdrive) | |
9426 | break; | |
9427 | ||
9428 | log_entry = (Mpi2EventDataLogEntryAdded_t *) | |
9429 | mpi_reply->EventData; | |
9430 | log_code = (u32 *)log_entry->LogData; | |
f92363d1 | 9431 | |
7786ab6a SR |
9432 | if (le16_to_cpu(log_entry->LogEntryQualifier) |
9433 | != MPT2_WARPDRIVE_LOGENTRY) | |
9434 | break; | |
9435 | ||
9436 | switch (le32_to_cpu(*log_code)) { | |
9437 | case MPT2_WARPDRIVE_LC_SSDT: | |
9438 | pr_warn(MPT3SAS_FMT "WarpDrive Warning: " | |
9439 | "IO Throttling has occurred in the WarpDrive " | |
9440 | "subsystem. Check WarpDrive documentation for " | |
9441 | "additional details.\n", ioc->name); | |
9442 | break; | |
9443 | case MPT2_WARPDRIVE_LC_SSDLW: | |
9444 | pr_warn(MPT3SAS_FMT "WarpDrive Warning: " | |
9445 | "Program/Erase Cycles for the WarpDrive subsystem " | |
9446 | "in degraded range. Check WarpDrive documentation " | |
9447 | "for additional details.\n", ioc->name); | |
9448 | break; | |
9449 | case MPT2_WARPDRIVE_LC_SSDLF: | |
9450 | pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: " | |
9451 | "There are no Program/Erase Cycles for the " | |
9452 | "WarpDrive subsystem. The storage device will be " | |
9453 | "in read-only mode. Check WarpDrive documentation " | |
9454 | "for additional details.\n", ioc->name); | |
9455 | break; | |
9456 | case MPT2_WARPDRIVE_LC_BRMF: | |
9457 | pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: " | |
9458 | "The Backup Rail Monitor has failed on the " | |
9459 | "WarpDrive subsystem. Check WarpDrive " | |
9460 | "documentation for additional details.\n", | |
9461 | ioc->name); | |
9462 | break; | |
9463 | } | |
9464 | ||
9465 | break; | |
9466 | } | |
f92363d1 SR |
9467 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: |
9468 | case MPI2_EVENT_IR_OPERATION_STATUS: | |
9469 | case MPI2_EVENT_SAS_DISCOVERY: | |
9470 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: | |
9471 | case MPI2_EVENT_IR_PHYSICAL_DISK: | |
4318c734 SPS |
9472 | case MPI2_EVENT_PCIE_ENUMERATION: |
9473 | case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE: | |
f92363d1 SR |
9474 | break; |
9475 | ||
2d8ce8c9 SR |
9476 | case MPI2_EVENT_TEMP_THRESHOLD: |
9477 | _scsih_temp_threshold_events(ioc, | |
9478 | (Mpi2EventDataTemperature_t *) | |
9479 | mpi_reply->EventData); | |
9480 | break; | |
a470a51c C |
9481 | case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION: |
9482 | ActiveCableEventData = | |
9483 | (Mpi26EventDataActiveCableExcept_t *) mpi_reply->EventData; | |
6c44c0fe C |
9484 | switch (ActiveCableEventData->ReasonCode) { |
9485 | case MPI26_EVENT_ACTIVE_CABLE_INSUFFICIENT_POWER: | |
b99b1993 SR |
9486 | pr_notice(MPT3SAS_FMT |
9487 | "Currently an active cable with ReceptacleID %d\n", | |
9488 | ioc->name, ActiveCableEventData->ReceptacleID); | |
9489 | pr_notice("cannot be powered and devices connected\n"); | |
9490 | pr_notice("to this active cable will not be seen\n"); | |
9491 | pr_notice("This active cable requires %d mW of power\n", | |
6c44c0fe | 9492 | ActiveCableEventData->ActiveCablePowerRequirement); |
6c44c0fe C |
9493 | break; |
9494 | ||
9495 | case MPI26_EVENT_ACTIVE_CABLE_DEGRADED: | |
b99b1993 SR |
9496 | pr_notice(MPT3SAS_FMT |
9497 | "Currently a cable with ReceptacleID %d\n", | |
9498 | ioc->name, ActiveCableEventData->ReceptacleID); | |
9499 | pr_notice( | |
9500 | "is not running at optimal speed(12 Gb/s rate)\n"); | |
6c44c0fe | 9501 | break; |
7ebd67e0 | 9502 | } |
6c44c0fe | 9503 | |
a470a51c | 9504 | break; |
2d8ce8c9 | 9505 | |
f92363d1 SR |
9506 | default: /* ignore the rest */ |
9507 | return 1; | |
9508 | } | |
9509 | ||
f92363d1 | 9510 | sz = le16_to_cpu(mpi_reply->EventDataLength) * 4; |
146b16c8 | 9511 | fw_event = alloc_fw_event_work(sz); |
35b62362 | 9512 | if (!fw_event) { |
f92363d1 SR |
9513 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
9514 | ioc->name, __FILE__, __LINE__, __func__); | |
f92363d1 SR |
9515 | return 1; |
9516 | } | |
9517 | ||
9518 | memcpy(fw_event->event_data, mpi_reply->EventData, sz); | |
9519 | fw_event->ioc = ioc; | |
9520 | fw_event->VF_ID = mpi_reply->VF_ID; | |
9521 | fw_event->VP_ID = mpi_reply->VP_ID; | |
9522 | fw_event->event = event; | |
9523 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 | 9524 | fw_event_work_put(fw_event); |
f92363d1 SR |
9525 | return 1; |
9526 | } | |
9527 | ||
f92363d1 SR |
9528 | /** |
9529 | * _scsih_expander_node_remove - removing expander device from list. | |
9530 | * @ioc: per adapter object | |
9531 | * @sas_expander: the sas_device object | |
f92363d1 SR |
9532 | * |
9533 | * Removing object and freeing associated memory from the | |
9534 | * ioc->sas_expander_list. | |
9535 | * | |
9536 | * Return nothing. | |
9537 | */ | |
9538 | static void | |
9539 | _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc, | |
9540 | struct _sas_node *sas_expander) | |
9541 | { | |
9542 | struct _sas_port *mpt3sas_port, *next; | |
bbe3def3 | 9543 | unsigned long flags; |
f92363d1 SR |
9544 | |
9545 | /* remove sibling ports attached to this expander */ | |
9546 | list_for_each_entry_safe(mpt3sas_port, next, | |
9547 | &sas_expander->sas_port_list, port_list) { | |
9548 | if (ioc->shost_recovery) | |
9549 | return; | |
9550 | if (mpt3sas_port->remote_identify.device_type == | |
9551 | SAS_END_DEVICE) | |
9552 | mpt3sas_device_remove_by_sas_address(ioc, | |
9553 | mpt3sas_port->remote_identify.sas_address); | |
9554 | else if (mpt3sas_port->remote_identify.device_type == | |
9555 | SAS_EDGE_EXPANDER_DEVICE || | |
9556 | mpt3sas_port->remote_identify.device_type == | |
9557 | SAS_FANOUT_EXPANDER_DEVICE) | |
9558 | mpt3sas_expander_remove(ioc, | |
9559 | mpt3sas_port->remote_identify.sas_address); | |
9560 | } | |
9561 | ||
9562 | mpt3sas_transport_port_remove(ioc, sas_expander->sas_address, | |
9563 | sas_expander->sas_address_parent); | |
9564 | ||
9565 | pr_info(MPT3SAS_FMT | |
9566 | "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n", | |
9567 | ioc->name, | |
9568 | sas_expander->handle, (unsigned long long) | |
9569 | sas_expander->sas_address); | |
9570 | ||
bbe3def3 SR |
9571 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
9572 | list_del(&sas_expander->list); | |
9573 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
9574 | ||
f92363d1 SR |
9575 | kfree(sas_expander->phy); |
9576 | kfree(sas_expander); | |
9577 | } | |
9578 | ||
9579 | /** | |
9580 | * _scsih_ir_shutdown - IR shutdown notification | |
9581 | * @ioc: per adapter object | |
9582 | * | |
9583 | * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that | |
9584 | * the host system is shutting down. | |
9585 | * | |
9586 | * Return nothing. | |
9587 | */ | |
9588 | static void | |
9589 | _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc) | |
9590 | { | |
9591 | Mpi2RaidActionRequest_t *mpi_request; | |
9592 | Mpi2RaidActionReply_t *mpi_reply; | |
9593 | u16 smid; | |
9594 | ||
9595 | /* is IR firmware build loaded ? */ | |
9596 | if (!ioc->ir_firmware) | |
9597 | return; | |
9598 | ||
9599 | /* are there any volumes ? */ | |
9600 | if (list_empty(&ioc->raid_device_list)) | |
9601 | return; | |
9602 | ||
9603 | mutex_lock(&ioc->scsih_cmds.mutex); | |
9604 | ||
9605 | if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) { | |
9606 | pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n", | |
9607 | ioc->name, __func__); | |
9608 | goto out; | |
9609 | } | |
9610 | ioc->scsih_cmds.status = MPT3_CMD_PENDING; | |
9611 | ||
9612 | smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx); | |
9613 | if (!smid) { | |
9614 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
9615 | ioc->name, __func__); | |
9616 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
9617 | goto out; | |
9618 | } | |
9619 | ||
9620 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
9621 | ioc->scsih_cmds.smid = smid; | |
9622 | memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t)); | |
9623 | ||
9624 | mpi_request->Function = MPI2_FUNCTION_RAID_ACTION; | |
9625 | mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED; | |
9626 | ||
7786ab6a SR |
9627 | if (!ioc->hide_ir_msg) |
9628 | pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name); | |
f92363d1 | 9629 | init_completion(&ioc->scsih_cmds.done); |
81c16f83 | 9630 | ioc->put_smid_default(ioc, smid); |
f92363d1 SR |
9631 | wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ); |
9632 | ||
9633 | if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) { | |
9634 | pr_err(MPT3SAS_FMT "%s: timeout\n", | |
9635 | ioc->name, __func__); | |
9636 | goto out; | |
9637 | } | |
9638 | ||
9639 | if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) { | |
9640 | mpi_reply = ioc->scsih_cmds.reply; | |
7786ab6a SR |
9641 | if (!ioc->hide_ir_msg) |
9642 | pr_info(MPT3SAS_FMT "IR shutdown " | |
9643 | "(complete): ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9644 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), | |
9645 | le32_to_cpu(mpi_reply->IOCLogInfo)); | |
f92363d1 SR |
9646 | } |
9647 | ||
9648 | out: | |
9649 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
9650 | mutex_unlock(&ioc->scsih_cmds.mutex); | |
9651 | } | |
9652 | ||
9653 | /** | |
8a7e4c24 | 9654 | * scsih_remove - detach and remove add host |
f92363d1 SR |
9655 | * @pdev: PCI device struct |
9656 | * | |
9657 | * Routine called when unloading the driver. | |
9658 | * Return nothing. | |
9659 | */ | |
8bbb1cf6 | 9660 | static void scsih_remove(struct pci_dev *pdev) |
f92363d1 SR |
9661 | { |
9662 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9663 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
9664 | struct _sas_port *mpt3sas_port, *next_port; | |
9665 | struct _raid_device *raid_device, *next; | |
9666 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
3075ac49 | 9667 | struct _pcie_device *pcie_device, *pcienext; |
f92363d1 SR |
9668 | struct workqueue_struct *wq; |
9669 | unsigned long flags; | |
9670 | ||
9671 | ioc->remove_host = 1; | |
9672 | _scsih_fw_event_cleanup_queue(ioc); | |
9673 | ||
9674 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
9675 | wq = ioc->firmware_event_thread; | |
9676 | ioc->firmware_event_thread = NULL; | |
9677 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
9678 | if (wq) | |
9679 | destroy_workqueue(wq); | |
9680 | ||
9681 | /* release all the volumes */ | |
9682 | _scsih_ir_shutdown(ioc); | |
9683 | list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list, | |
9684 | list) { | |
9685 | if (raid_device->starget) { | |
9686 | sas_target_priv_data = | |
9687 | raid_device->starget->hostdata; | |
9688 | sas_target_priv_data->deleted = 1; | |
9689 | scsi_remove_target(&raid_device->starget->dev); | |
9690 | } | |
9691 | pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n", | |
9692 | ioc->name, raid_device->handle, | |
9693 | (unsigned long long) raid_device->wwid); | |
9694 | _scsih_raid_device_remove(ioc, raid_device); | |
9695 | } | |
3075ac49 SPS |
9696 | list_for_each_entry_safe(pcie_device, pcienext, &ioc->pcie_device_list, |
9697 | list) { | |
9698 | _scsih_pcie_device_remove_from_sml(ioc, pcie_device); | |
9699 | list_del_init(&pcie_device->list); | |
9700 | pcie_device_put(pcie_device); | |
9701 | } | |
f92363d1 SR |
9702 | |
9703 | /* free ports attached to the sas_host */ | |
9704 | list_for_each_entry_safe(mpt3sas_port, next_port, | |
9705 | &ioc->sas_hba.sas_port_list, port_list) { | |
9706 | if (mpt3sas_port->remote_identify.device_type == | |
9707 | SAS_END_DEVICE) | |
9708 | mpt3sas_device_remove_by_sas_address(ioc, | |
9709 | mpt3sas_port->remote_identify.sas_address); | |
9710 | else if (mpt3sas_port->remote_identify.device_type == | |
9711 | SAS_EDGE_EXPANDER_DEVICE || | |
9712 | mpt3sas_port->remote_identify.device_type == | |
9713 | SAS_FANOUT_EXPANDER_DEVICE) | |
9714 | mpt3sas_expander_remove(ioc, | |
9715 | mpt3sas_port->remote_identify.sas_address); | |
9716 | } | |
9717 | ||
9718 | /* free phys attached to the sas_host */ | |
9719 | if (ioc->sas_hba.num_phys) { | |
9720 | kfree(ioc->sas_hba.phy); | |
9721 | ioc->sas_hba.phy = NULL; | |
9722 | ioc->sas_hba.num_phys = 0; | |
9723 | } | |
9724 | ||
9725 | sas_remove_host(shost); | |
9726 | mpt3sas_base_detach(ioc); | |
08c4d550 | 9727 | spin_lock(&gioc_lock); |
f92363d1 | 9728 | list_del(&ioc->list); |
08c4d550 | 9729 | spin_unlock(&gioc_lock); |
f92363d1 SR |
9730 | scsi_host_put(shost); |
9731 | } | |
9732 | ||
9733 | /** | |
8a7e4c24 | 9734 | * scsih_shutdown - routine call during system shutdown |
f92363d1 SR |
9735 | * @pdev: PCI device struct |
9736 | * | |
9737 | * Return nothing. | |
9738 | */ | |
8bbb1cf6 | 9739 | static void |
8a7e4c24 | 9740 | scsih_shutdown(struct pci_dev *pdev) |
f92363d1 SR |
9741 | { |
9742 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9743 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
9744 | struct workqueue_struct *wq; | |
9745 | unsigned long flags; | |
9746 | ||
9747 | ioc->remove_host = 1; | |
9748 | _scsih_fw_event_cleanup_queue(ioc); | |
9749 | ||
9750 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
9751 | wq = ioc->firmware_event_thread; | |
9752 | ioc->firmware_event_thread = NULL; | |
9753 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
9754 | if (wq) | |
9755 | destroy_workqueue(wq); | |
9756 | ||
9757 | _scsih_ir_shutdown(ioc); | |
9758 | mpt3sas_base_detach(ioc); | |
9759 | } | |
9760 | ||
9761 | ||
9762 | /** | |
9763 | * _scsih_probe_boot_devices - reports 1st device | |
9764 | * @ioc: per adapter object | |
9765 | * | |
9766 | * If specified in bios page 2, this routine reports the 1st | |
9767 | * device scsi-ml or sas transport for persistent boot device | |
9768 | * purposes. Please refer to function _scsih_determine_boot_device() | |
9769 | */ | |
9770 | static void | |
9771 | _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc) | |
9772 | { | |
d88e1eab | 9773 | u32 channel; |
f92363d1 SR |
9774 | void *device; |
9775 | struct _sas_device *sas_device; | |
9776 | struct _raid_device *raid_device; | |
d88e1eab | 9777 | struct _pcie_device *pcie_device; |
f92363d1 SR |
9778 | u16 handle; |
9779 | u64 sas_address_parent; | |
9780 | u64 sas_address; | |
9781 | unsigned long flags; | |
9782 | int rc; | |
d88e1eab | 9783 | int tid; |
f92363d1 SR |
9784 | |
9785 | /* no Bios, return immediately */ | |
9786 | if (!ioc->bios_pg3.BiosVersion) | |
9787 | return; | |
9788 | ||
9789 | device = NULL; | |
f92363d1 SR |
9790 | if (ioc->req_boot_device.device) { |
9791 | device = ioc->req_boot_device.device; | |
d88e1eab | 9792 | channel = ioc->req_boot_device.channel; |
f92363d1 SR |
9793 | } else if (ioc->req_alt_boot_device.device) { |
9794 | device = ioc->req_alt_boot_device.device; | |
d88e1eab | 9795 | channel = ioc->req_alt_boot_device.channel; |
f92363d1 SR |
9796 | } else if (ioc->current_boot_device.device) { |
9797 | device = ioc->current_boot_device.device; | |
d88e1eab | 9798 | channel = ioc->current_boot_device.channel; |
f92363d1 SR |
9799 | } |
9800 | ||
9801 | if (!device) | |
9802 | return; | |
9803 | ||
d88e1eab | 9804 | if (channel == RAID_CHANNEL) { |
f92363d1 SR |
9805 | raid_device = device; |
9806 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
9807 | raid_device->id, 0); | |
9808 | if (rc) | |
9809 | _scsih_raid_device_remove(ioc, raid_device); | |
d88e1eab SPS |
9810 | } else if (channel == PCIE_CHANNEL) { |
9811 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
9812 | pcie_device = device; | |
9813 | tid = pcie_device->id; | |
9814 | list_move_tail(&pcie_device->list, &ioc->pcie_device_list); | |
9815 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
9816 | rc = scsi_add_device(ioc->shost, PCIE_CHANNEL, tid, 0); | |
9817 | if (rc) | |
9818 | _scsih_pcie_device_remove(ioc, pcie_device); | |
f92363d1 SR |
9819 | } else { |
9820 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
9821 | sas_device = device; | |
9822 | handle = sas_device->handle; | |
9823 | sas_address_parent = sas_device->sas_address_parent; | |
9824 | sas_address = sas_device->sas_address; | |
9825 | list_move_tail(&sas_device->list, &ioc->sas_device_list); | |
9826 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
9827 | ||
7786ab6a SR |
9828 | if (ioc->hide_drives) |
9829 | return; | |
f92363d1 SR |
9830 | if (!mpt3sas_transport_port_add(ioc, handle, |
9831 | sas_address_parent)) { | |
9832 | _scsih_sas_device_remove(ioc, sas_device); | |
9833 | } else if (!sas_device->starget) { | |
f5edbe77 SR |
9834 | if (!ioc->is_driver_loading) { |
9835 | mpt3sas_transport_port_remove(ioc, | |
9836 | sas_address, | |
f92363d1 | 9837 | sas_address_parent); |
f5edbe77 SR |
9838 | _scsih_sas_device_remove(ioc, sas_device); |
9839 | } | |
f92363d1 SR |
9840 | } |
9841 | } | |
9842 | } | |
9843 | ||
9844 | /** | |
9845 | * _scsih_probe_raid - reporting raid volumes to scsi-ml | |
9846 | * @ioc: per adapter object | |
9847 | * | |
9848 | * Called during initial loading of the driver. | |
9849 | */ | |
9850 | static void | |
9851 | _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc) | |
9852 | { | |
9853 | struct _raid_device *raid_device, *raid_next; | |
9854 | int rc; | |
9855 | ||
9856 | list_for_each_entry_safe(raid_device, raid_next, | |
9857 | &ioc->raid_device_list, list) { | |
9858 | if (raid_device->starget) | |
9859 | continue; | |
9860 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
9861 | raid_device->id, 0); | |
9862 | if (rc) | |
9863 | _scsih_raid_device_remove(ioc, raid_device); | |
9864 | } | |
9865 | } | |
9866 | ||
d1cb5e49 SR |
9867 | static struct _sas_device *get_next_sas_device(struct MPT3SAS_ADAPTER *ioc) |
9868 | { | |
9869 | struct _sas_device *sas_device = NULL; | |
9870 | unsigned long flags; | |
9871 | ||
9872 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
9873 | if (!list_empty(&ioc->sas_device_init_list)) { | |
9874 | sas_device = list_first_entry(&ioc->sas_device_init_list, | |
9875 | struct _sas_device, list); | |
9876 | sas_device_get(sas_device); | |
9877 | } | |
9878 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
9879 | ||
9880 | return sas_device; | |
9881 | } | |
9882 | ||
9883 | static void sas_device_make_active(struct MPT3SAS_ADAPTER *ioc, | |
9884 | struct _sas_device *sas_device) | |
9885 | { | |
9886 | unsigned long flags; | |
9887 | ||
9888 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
9889 | ||
9890 | /* | |
9891 | * Since we dropped the lock during the call to port_add(), we need to | |
9892 | * be careful here that somebody else didn't move or delete this item | |
9893 | * while we were busy with other things. | |
9894 | * | |
9895 | * If it was on the list, we need a put() for the reference the list | |
9896 | * had. Either way, we need a get() for the destination list. | |
9897 | */ | |
9898 | if (!list_empty(&sas_device->list)) { | |
9899 | list_del_init(&sas_device->list); | |
9900 | sas_device_put(sas_device); | |
9901 | } | |
9902 | ||
9903 | sas_device_get(sas_device); | |
9904 | list_add_tail(&sas_device->list, &ioc->sas_device_list); | |
9905 | ||
9906 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
9907 | } | |
9908 | ||
f92363d1 SR |
9909 | /** |
9910 | * _scsih_probe_sas - reporting sas devices to sas transport | |
9911 | * @ioc: per adapter object | |
9912 | * | |
9913 | * Called during initial loading of the driver. | |
9914 | */ | |
9915 | static void | |
9916 | _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc) | |
9917 | { | |
d1cb5e49 | 9918 | struct _sas_device *sas_device; |
f92363d1 | 9919 | |
d1cb5e49 SR |
9920 | if (ioc->hide_drives) |
9921 | return; | |
7786ab6a | 9922 | |
d1cb5e49 | 9923 | while ((sas_device = get_next_sas_device(ioc))) { |
f92363d1 SR |
9924 | if (!mpt3sas_transport_port_add(ioc, sas_device->handle, |
9925 | sas_device->sas_address_parent)) { | |
d1cb5e49 SR |
9926 | _scsih_sas_device_remove(ioc, sas_device); |
9927 | sas_device_put(sas_device); | |
f92363d1 SR |
9928 | continue; |
9929 | } else if (!sas_device->starget) { | |
9930 | /* | |
9931 | * When asyn scanning is enabled, its not possible to | |
9932 | * remove devices while scanning is turned on due to an | |
9933 | * oops in scsi_sysfs_add_sdev()->add_device()-> | |
9934 | * sysfs_addrm_start() | |
9935 | */ | |
f5edbe77 | 9936 | if (!ioc->is_driver_loading) { |
f92363d1 SR |
9937 | mpt3sas_transport_port_remove(ioc, |
9938 | sas_device->sas_address, | |
9939 | sas_device->sas_address_parent); | |
d1cb5e49 SR |
9940 | _scsih_sas_device_remove(ioc, sas_device); |
9941 | sas_device_put(sas_device); | |
f5edbe77 SR |
9942 | continue; |
9943 | } | |
f92363d1 | 9944 | } |
d1cb5e49 SR |
9945 | sas_device_make_active(ioc, sas_device); |
9946 | sas_device_put(sas_device); | |
f92363d1 SR |
9947 | } |
9948 | } | |
9949 | ||
d88e1eab SPS |
9950 | /** |
9951 | * get_next_pcie_device - Get the next pcie device | |
9952 | * @ioc: per adapter object | |
9953 | * | |
9954 | * Get the next pcie device from pcie_device_init_list list. | |
9955 | * | |
9956 | * Returns pcie device structure if pcie_device_init_list list is not empty | |
9957 | * otherwise returns NULL | |
9958 | */ | |
9959 | static struct _pcie_device *get_next_pcie_device(struct MPT3SAS_ADAPTER *ioc) | |
9960 | { | |
9961 | struct _pcie_device *pcie_device = NULL; | |
9962 | unsigned long flags; | |
9963 | ||
9964 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
9965 | if (!list_empty(&ioc->pcie_device_init_list)) { | |
9966 | pcie_device = list_first_entry(&ioc->pcie_device_init_list, | |
9967 | struct _pcie_device, list); | |
9968 | pcie_device_get(pcie_device); | |
9969 | } | |
9970 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
9971 | ||
9972 | return pcie_device; | |
9973 | } | |
9974 | ||
9975 | /** | |
9976 | * pcie_device_make_active - Add pcie device to pcie_device_list list | |
9977 | * @ioc: per adapter object | |
9978 | * @pcie_device: pcie device object | |
9979 | * | |
9980 | * Add the pcie device which has registered with SCSI Transport Later to | |
9981 | * pcie_device_list list | |
9982 | */ | |
9983 | static void pcie_device_make_active(struct MPT3SAS_ADAPTER *ioc, | |
9984 | struct _pcie_device *pcie_device) | |
9985 | { | |
9986 | unsigned long flags; | |
9987 | ||
9988 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
9989 | ||
9990 | if (!list_empty(&pcie_device->list)) { | |
9991 | list_del_init(&pcie_device->list); | |
9992 | pcie_device_put(pcie_device); | |
9993 | } | |
9994 | pcie_device_get(pcie_device); | |
9995 | list_add_tail(&pcie_device->list, &ioc->pcie_device_list); | |
9996 | ||
9997 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
9998 | } | |
9999 | ||
10000 | /** | |
10001 | * _scsih_probe_pcie - reporting PCIe devices to scsi-ml | |
10002 | * @ioc: per adapter object | |
10003 | * | |
10004 | * Called during initial loading of the driver. | |
10005 | */ | |
10006 | static void | |
10007 | _scsih_probe_pcie(struct MPT3SAS_ADAPTER *ioc) | |
10008 | { | |
10009 | struct _pcie_device *pcie_device; | |
10010 | int rc; | |
10011 | ||
10012 | /* PCIe Device List */ | |
10013 | while ((pcie_device = get_next_pcie_device(ioc))) { | |
10014 | if (pcie_device->starget) { | |
10015 | pcie_device_put(pcie_device); | |
10016 | continue; | |
10017 | } | |
10018 | rc = scsi_add_device(ioc->shost, PCIE_CHANNEL, | |
10019 | pcie_device->id, 0); | |
10020 | if (rc) { | |
10021 | _scsih_pcie_device_remove(ioc, pcie_device); | |
10022 | pcie_device_put(pcie_device); | |
10023 | continue; | |
10024 | } else if (!pcie_device->starget) { | |
10025 | /* | |
10026 | * When async scanning is enabled, its not possible to | |
10027 | * remove devices while scanning is turned on due to an | |
10028 | * oops in scsi_sysfs_add_sdev()->add_device()-> | |
10029 | * sysfs_addrm_start() | |
10030 | */ | |
10031 | if (!ioc->is_driver_loading) { | |
10032 | /* TODO-- Need to find out whether this condition will | |
10033 | * occur or not | |
10034 | */ | |
10035 | _scsih_pcie_device_remove(ioc, pcie_device); | |
10036 | pcie_device_put(pcie_device); | |
10037 | continue; | |
10038 | } | |
10039 | } | |
10040 | pcie_device_make_active(ioc, pcie_device); | |
10041 | pcie_device_put(pcie_device); | |
10042 | } | |
10043 | } | |
10044 | ||
f92363d1 SR |
10045 | /** |
10046 | * _scsih_probe_devices - probing for devices | |
10047 | * @ioc: per adapter object | |
10048 | * | |
10049 | * Called during initial loading of the driver. | |
10050 | */ | |
10051 | static void | |
10052 | _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc) | |
10053 | { | |
10054 | u16 volume_mapping_flags; | |
10055 | ||
10056 | if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR)) | |
10057 | return; /* return when IOC doesn't support initiator mode */ | |
10058 | ||
10059 | _scsih_probe_boot_devices(ioc); | |
10060 | ||
10061 | if (ioc->ir_firmware) { | |
10062 | volume_mapping_flags = | |
10063 | le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) & | |
10064 | MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE; | |
10065 | if (volume_mapping_flags == | |
10066 | MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) { | |
10067 | _scsih_probe_raid(ioc); | |
10068 | _scsih_probe_sas(ioc); | |
10069 | } else { | |
10070 | _scsih_probe_sas(ioc); | |
10071 | _scsih_probe_raid(ioc); | |
10072 | } | |
d88e1eab | 10073 | } else { |
f92363d1 | 10074 | _scsih_probe_sas(ioc); |
d88e1eab SPS |
10075 | _scsih_probe_pcie(ioc); |
10076 | } | |
f92363d1 SR |
10077 | } |
10078 | ||
10079 | /** | |
8a7e4c24 | 10080 | * scsih_scan_start - scsi lld callback for .scan_start |
f92363d1 SR |
10081 | * @shost: SCSI host pointer |
10082 | * | |
10083 | * The shost has the ability to discover targets on its own instead | |
10084 | * of scanning the entire bus. In our implemention, we will kick off | |
10085 | * firmware discovery. | |
10086 | */ | |
8bbb1cf6 | 10087 | static void |
8a7e4c24 | 10088 | scsih_scan_start(struct Scsi_Host *shost) |
f92363d1 SR |
10089 | { |
10090 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10091 | int rc; | |
10092 | if (diag_buffer_enable != -1 && diag_buffer_enable != 0) | |
10093 | mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable); | |
10094 | ||
10095 | if (disable_discovery > 0) | |
10096 | return; | |
10097 | ||
10098 | ioc->start_scan = 1; | |
10099 | rc = mpt3sas_port_enable(ioc); | |
10100 | ||
10101 | if (rc != 0) | |
10102 | pr_info(MPT3SAS_FMT "port enable: FAILED\n", ioc->name); | |
10103 | } | |
10104 | ||
10105 | /** | |
8a7e4c24 | 10106 | * scsih_scan_finished - scsi lld callback for .scan_finished |
f92363d1 SR |
10107 | * @shost: SCSI host pointer |
10108 | * @time: elapsed time of the scan in jiffies | |
10109 | * | |
10110 | * This function will be called periodicallyn until it returns 1 with the | |
10111 | * scsi_host and the elapsed time of the scan in jiffies. In our implemention, | |
10112 | * we wait for firmware discovery to complete, then return 1. | |
10113 | */ | |
8bbb1cf6 | 10114 | static int |
8a7e4c24 | 10115 | scsih_scan_finished(struct Scsi_Host *shost, unsigned long time) |
f92363d1 SR |
10116 | { |
10117 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10118 | ||
10119 | if (disable_discovery > 0) { | |
10120 | ioc->is_driver_loading = 0; | |
10121 | ioc->wait_for_discovery_to_complete = 0; | |
10122 | return 1; | |
10123 | } | |
10124 | ||
10125 | if (time >= (300 * HZ)) { | |
10126 | ioc->base_cmds.status = MPT3_CMD_NOT_USED; | |
10127 | pr_info(MPT3SAS_FMT | |
10128 | "port enable: FAILED with timeout (timeout=300s)\n", | |
10129 | ioc->name); | |
10130 | ioc->is_driver_loading = 0; | |
10131 | return 1; | |
10132 | } | |
10133 | ||
10134 | if (ioc->start_scan) | |
10135 | return 0; | |
10136 | ||
10137 | if (ioc->start_scan_failed) { | |
10138 | pr_info(MPT3SAS_FMT | |
10139 | "port enable: FAILED with (ioc_status=0x%08x)\n", | |
10140 | ioc->name, ioc->start_scan_failed); | |
10141 | ioc->is_driver_loading = 0; | |
10142 | ioc->wait_for_discovery_to_complete = 0; | |
10143 | ioc->remove_host = 1; | |
10144 | return 1; | |
10145 | } | |
10146 | ||
10147 | pr_info(MPT3SAS_FMT "port enable: SUCCESS\n", ioc->name); | |
10148 | ioc->base_cmds.status = MPT3_CMD_NOT_USED; | |
10149 | ||
10150 | if (ioc->wait_for_discovery_to_complete) { | |
10151 | ioc->wait_for_discovery_to_complete = 0; | |
10152 | _scsih_probe_devices(ioc); | |
10153 | } | |
10154 | mpt3sas_base_start_watchdog(ioc); | |
10155 | ioc->is_driver_loading = 0; | |
10156 | return 1; | |
10157 | } | |
10158 | ||
c84b06a4 SR |
10159 | /* shost template for SAS 2.0 HBA devices */ |
10160 | static struct scsi_host_template mpt2sas_driver_template = { | |
10161 | .module = THIS_MODULE, | |
10162 | .name = "Fusion MPT SAS Host", | |
10163 | .proc_name = MPT2SAS_DRIVER_NAME, | |
10164 | .queuecommand = scsih_qcmd, | |
10165 | .target_alloc = scsih_target_alloc, | |
10166 | .slave_alloc = scsih_slave_alloc, | |
10167 | .slave_configure = scsih_slave_configure, | |
10168 | .target_destroy = scsih_target_destroy, | |
10169 | .slave_destroy = scsih_slave_destroy, | |
10170 | .scan_finished = scsih_scan_finished, | |
10171 | .scan_start = scsih_scan_start, | |
10172 | .change_queue_depth = scsih_change_queue_depth, | |
10173 | .eh_abort_handler = scsih_abort, | |
10174 | .eh_device_reset_handler = scsih_dev_reset, | |
10175 | .eh_target_reset_handler = scsih_target_reset, | |
10176 | .eh_host_reset_handler = scsih_host_reset, | |
10177 | .bios_param = scsih_bios_param, | |
10178 | .can_queue = 1, | |
10179 | .this_id = -1, | |
10180 | .sg_tablesize = MPT2SAS_SG_DEPTH, | |
10181 | .max_sectors = 32767, | |
10182 | .cmd_per_lun = 7, | |
10183 | .use_clustering = ENABLE_CLUSTERING, | |
10184 | .shost_attrs = mpt3sas_host_attrs, | |
10185 | .sdev_attrs = mpt3sas_dev_attrs, | |
10186 | .track_queue_depth = 1, | |
10187 | }; | |
10188 | ||
10189 | /* raid transport support for SAS 2.0 HBA devices */ | |
10190 | static struct raid_function_template mpt2sas_raid_functions = { | |
10191 | .cookie = &mpt2sas_driver_template, | |
10192 | .is_raid = scsih_is_raid, | |
10193 | .get_resync = scsih_get_resync, | |
10194 | .get_state = scsih_get_state, | |
10195 | }; | |
d357e84d | 10196 | |
c84b06a4 SR |
10197 | /* shost template for SAS 3.0 HBA devices */ |
10198 | static struct scsi_host_template mpt3sas_driver_template = { | |
10199 | .module = THIS_MODULE, | |
10200 | .name = "Fusion MPT SAS Host", | |
10201 | .proc_name = MPT3SAS_DRIVER_NAME, | |
10202 | .queuecommand = scsih_qcmd, | |
10203 | .target_alloc = scsih_target_alloc, | |
10204 | .slave_alloc = scsih_slave_alloc, | |
10205 | .slave_configure = scsih_slave_configure, | |
10206 | .target_destroy = scsih_target_destroy, | |
10207 | .slave_destroy = scsih_slave_destroy, | |
10208 | .scan_finished = scsih_scan_finished, | |
10209 | .scan_start = scsih_scan_start, | |
10210 | .change_queue_depth = scsih_change_queue_depth, | |
10211 | .eh_abort_handler = scsih_abort, | |
10212 | .eh_device_reset_handler = scsih_dev_reset, | |
10213 | .eh_target_reset_handler = scsih_target_reset, | |
10214 | .eh_host_reset_handler = scsih_host_reset, | |
10215 | .bios_param = scsih_bios_param, | |
10216 | .can_queue = 1, | |
10217 | .this_id = -1, | |
10218 | .sg_tablesize = MPT3SAS_SG_DEPTH, | |
10219 | .max_sectors = 32767, | |
10220 | .cmd_per_lun = 7, | |
10221 | .use_clustering = ENABLE_CLUSTERING, | |
10222 | .shost_attrs = mpt3sas_host_attrs, | |
10223 | .sdev_attrs = mpt3sas_dev_attrs, | |
10224 | .track_queue_depth = 1, | |
10225 | }; | |
10226 | ||
10227 | /* raid transport support for SAS 3.0 HBA devices */ | |
10228 | static struct raid_function_template mpt3sas_raid_functions = { | |
10229 | .cookie = &mpt3sas_driver_template, | |
10230 | .is_raid = scsih_is_raid, | |
10231 | .get_resync = scsih_get_resync, | |
10232 | .get_state = scsih_get_state, | |
10233 | }; | |
10234 | ||
10235 | /** | |
10236 | * _scsih_determine_hba_mpi_version - determine in which MPI version class | |
10237 | * this device belongs to. | |
10238 | * @pdev: PCI device struct | |
10239 | * | |
10240 | * return MPI2_VERSION for SAS 2.0 HBA devices, | |
b130b0d5 SS |
10241 | * MPI25_VERSION for SAS 3.0 HBA devices, and |
10242 | * MPI26 VERSION for Cutlass & Invader SAS 3.0 HBA devices | |
c84b06a4 | 10243 | */ |
8bbb1cf6 | 10244 | static u16 |
c84b06a4 SR |
10245 | _scsih_determine_hba_mpi_version(struct pci_dev *pdev) |
10246 | { | |
10247 | ||
10248 | switch (pdev->device) { | |
7786ab6a | 10249 | case MPI2_MFGPAGE_DEVID_SSS6200: |
d357e84d SR |
10250 | case MPI2_MFGPAGE_DEVID_SAS2004: |
10251 | case MPI2_MFGPAGE_DEVID_SAS2008: | |
10252 | case MPI2_MFGPAGE_DEVID_SAS2108_1: | |
10253 | case MPI2_MFGPAGE_DEVID_SAS2108_2: | |
10254 | case MPI2_MFGPAGE_DEVID_SAS2108_3: | |
10255 | case MPI2_MFGPAGE_DEVID_SAS2116_1: | |
10256 | case MPI2_MFGPAGE_DEVID_SAS2116_2: | |
10257 | case MPI2_MFGPAGE_DEVID_SAS2208_1: | |
10258 | case MPI2_MFGPAGE_DEVID_SAS2208_2: | |
10259 | case MPI2_MFGPAGE_DEVID_SAS2208_3: | |
10260 | case MPI2_MFGPAGE_DEVID_SAS2208_4: | |
10261 | case MPI2_MFGPAGE_DEVID_SAS2208_5: | |
10262 | case MPI2_MFGPAGE_DEVID_SAS2208_6: | |
10263 | case MPI2_MFGPAGE_DEVID_SAS2308_1: | |
10264 | case MPI2_MFGPAGE_DEVID_SAS2308_2: | |
10265 | case MPI2_MFGPAGE_DEVID_SAS2308_3: | |
c84b06a4 | 10266 | return MPI2_VERSION; |
d357e84d SR |
10267 | case MPI25_MFGPAGE_DEVID_SAS3004: |
10268 | case MPI25_MFGPAGE_DEVID_SAS3008: | |
10269 | case MPI25_MFGPAGE_DEVID_SAS3108_1: | |
10270 | case MPI25_MFGPAGE_DEVID_SAS3108_2: | |
10271 | case MPI25_MFGPAGE_DEVID_SAS3108_5: | |
10272 | case MPI25_MFGPAGE_DEVID_SAS3108_6: | |
c84b06a4 | 10273 | return MPI25_VERSION; |
b130b0d5 SS |
10274 | case MPI26_MFGPAGE_DEVID_SAS3216: |
10275 | case MPI26_MFGPAGE_DEVID_SAS3224: | |
10276 | case MPI26_MFGPAGE_DEVID_SAS3316_1: | |
10277 | case MPI26_MFGPAGE_DEVID_SAS3316_2: | |
10278 | case MPI26_MFGPAGE_DEVID_SAS3316_3: | |
10279 | case MPI26_MFGPAGE_DEVID_SAS3316_4: | |
10280 | case MPI26_MFGPAGE_DEVID_SAS3324_1: | |
10281 | case MPI26_MFGPAGE_DEVID_SAS3324_2: | |
10282 | case MPI26_MFGPAGE_DEVID_SAS3324_3: | |
10283 | case MPI26_MFGPAGE_DEVID_SAS3324_4: | |
998f26ae SPS |
10284 | case MPI26_MFGPAGE_DEVID_SAS3508: |
10285 | case MPI26_MFGPAGE_DEVID_SAS3508_1: | |
10286 | case MPI26_MFGPAGE_DEVID_SAS3408: | |
10287 | case MPI26_MFGPAGE_DEVID_SAS3516: | |
10288 | case MPI26_MFGPAGE_DEVID_SAS3516_1: | |
10289 | case MPI26_MFGPAGE_DEVID_SAS3416: | |
15fd7c74 | 10290 | case MPI26_MFGPAGE_DEVID_SAS3616: |
b130b0d5 | 10291 | return MPI26_VERSION; |
d357e84d | 10292 | } |
c84b06a4 | 10293 | return 0; |
d357e84d SR |
10294 | } |
10295 | ||
f92363d1 | 10296 | /** |
c84b06a4 | 10297 | * _scsih_probe - attach and add scsi host |
f92363d1 SR |
10298 | * @pdev: PCI device struct |
10299 | * @id: pci device id | |
10300 | * | |
10301 | * Returns 0 success, anything else error. | |
10302 | */ | |
8bbb1cf6 | 10303 | static int |
c84b06a4 | 10304 | _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
f92363d1 SR |
10305 | { |
10306 | struct MPT3SAS_ADAPTER *ioc; | |
c84b06a4 | 10307 | struct Scsi_Host *shost = NULL; |
b65f1d4d | 10308 | int rv; |
c84b06a4 SR |
10309 | u16 hba_mpi_version; |
10310 | ||
10311 | /* Determine in which MPI version class this pci device belongs */ | |
10312 | hba_mpi_version = _scsih_determine_hba_mpi_version(pdev); | |
10313 | if (hba_mpi_version == 0) | |
10314 | return -ENODEV; | |
10315 | ||
10316 | /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one, | |
10317 | * for other generation HBA's return with -ENODEV | |
10318 | */ | |
10319 | if ((hbas_to_enumerate == 1) && (hba_mpi_version != MPI2_VERSION)) | |
10320 | return -ENODEV; | |
10321 | ||
10322 | /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two, | |
10323 | * for other generation HBA's return with -ENODEV | |
10324 | */ | |
b130b0d5 SS |
10325 | if ((hbas_to_enumerate == 2) && (!(hba_mpi_version == MPI25_VERSION |
10326 | || hba_mpi_version == MPI26_VERSION))) | |
c84b06a4 SR |
10327 | return -ENODEV; |
10328 | ||
10329 | switch (hba_mpi_version) { | |
10330 | case MPI2_VERSION: | |
ffdadd68 | 10331 | pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | |
10332 | PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM); | |
c84b06a4 SR |
10333 | /* Use mpt2sas driver host template for SAS 2.0 HBA's */ |
10334 | shost = scsi_host_alloc(&mpt2sas_driver_template, | |
10335 | sizeof(struct MPT3SAS_ADAPTER)); | |
10336 | if (!shost) | |
10337 | return -ENODEV; | |
10338 | ioc = shost_priv(shost); | |
10339 | memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER)); | |
10340 | ioc->hba_mpi_version_belonged = hba_mpi_version; | |
10341 | ioc->id = mpt2_ids++; | |
10342 | sprintf(ioc->driver_name, "%s", MPT2SAS_DRIVER_NAME); | |
10343 | if (pdev->device == MPI2_MFGPAGE_DEVID_SSS6200) { | |
10344 | ioc->is_warpdrive = 1; | |
10345 | ioc->hide_ir_msg = 1; | |
10346 | } else | |
10347 | ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS; | |
10348 | break; | |
10349 | case MPI25_VERSION: | |
b130b0d5 | 10350 | case MPI26_VERSION: |
c84b06a4 SR |
10351 | /* Use mpt3sas driver host template for SAS 3.0 HBA's */ |
10352 | shost = scsi_host_alloc(&mpt3sas_driver_template, | |
10353 | sizeof(struct MPT3SAS_ADAPTER)); | |
10354 | if (!shost) | |
10355 | return -ENODEV; | |
10356 | ioc = shost_priv(shost); | |
10357 | memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER)); | |
10358 | ioc->hba_mpi_version_belonged = hba_mpi_version; | |
10359 | ioc->id = mpt3_ids++; | |
10360 | sprintf(ioc->driver_name, "%s", MPT3SAS_DRIVER_NAME); | |
998f26ae SPS |
10361 | switch (pdev->device) { |
10362 | case MPI26_MFGPAGE_DEVID_SAS3508: | |
10363 | case MPI26_MFGPAGE_DEVID_SAS3508_1: | |
10364 | case MPI26_MFGPAGE_DEVID_SAS3408: | |
10365 | case MPI26_MFGPAGE_DEVID_SAS3516: | |
10366 | case MPI26_MFGPAGE_DEVID_SAS3516_1: | |
10367 | case MPI26_MFGPAGE_DEVID_SAS3416: | |
15fd7c74 | 10368 | case MPI26_MFGPAGE_DEVID_SAS3616: |
998f26ae SPS |
10369 | ioc->is_gen35_ioc = 1; |
10370 | break; | |
10371 | default: | |
10372 | ioc->is_gen35_ioc = 0; | |
10373 | } | |
b130b0d5 SS |
10374 | if ((ioc->hba_mpi_version_belonged == MPI25_VERSION && |
10375 | pdev->revision >= SAS3_PCI_DEVICE_C0_REVISION) || | |
0bb337c9 SPS |
10376 | (ioc->hba_mpi_version_belonged == MPI26_VERSION)) { |
10377 | ioc->combined_reply_queue = 1; | |
10378 | if (ioc->is_gen35_ioc) | |
10379 | ioc->combined_reply_index_count = | |
10380 | MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G35; | |
10381 | else | |
10382 | ioc->combined_reply_index_count = | |
10383 | MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G3; | |
10384 | } | |
c84b06a4 SR |
10385 | break; |
10386 | default: | |
10387 | return -ENODEV; | |
10388 | } | |
f92363d1 | 10389 | |
f92363d1 | 10390 | INIT_LIST_HEAD(&ioc->list); |
08c4d550 | 10391 | spin_lock(&gioc_lock); |
f92363d1 | 10392 | list_add_tail(&ioc->list, &mpt3sas_ioc_list); |
08c4d550 | 10393 | spin_unlock(&gioc_lock); |
f92363d1 | 10394 | ioc->shost = shost; |
f92363d1 SR |
10395 | ioc->pdev = pdev; |
10396 | ioc->scsi_io_cb_idx = scsi_io_cb_idx; | |
10397 | ioc->tm_cb_idx = tm_cb_idx; | |
10398 | ioc->ctl_cb_idx = ctl_cb_idx; | |
10399 | ioc->base_cb_idx = base_cb_idx; | |
10400 | ioc->port_enable_cb_idx = port_enable_cb_idx; | |
10401 | ioc->transport_cb_idx = transport_cb_idx; | |
10402 | ioc->scsih_cb_idx = scsih_cb_idx; | |
10403 | ioc->config_cb_idx = config_cb_idx; | |
10404 | ioc->tm_tr_cb_idx = tm_tr_cb_idx; | |
10405 | ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx; | |
10406 | ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx; | |
10407 | ioc->logging_level = logging_level; | |
10408 | ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds; | |
10409 | /* misc semaphores and spin locks */ | |
10410 | mutex_init(&ioc->reset_in_progress_mutex); | |
08c4d550 SR |
10411 | /* initializing pci_access_mutex lock */ |
10412 | mutex_init(&ioc->pci_access_mutex); | |
f92363d1 SR |
10413 | spin_lock_init(&ioc->ioc_reset_in_progress_lock); |
10414 | spin_lock_init(&ioc->scsi_lookup_lock); | |
10415 | spin_lock_init(&ioc->sas_device_lock); | |
10416 | spin_lock_init(&ioc->sas_node_lock); | |
10417 | spin_lock_init(&ioc->fw_event_lock); | |
10418 | spin_lock_init(&ioc->raid_device_lock); | |
d88e1eab | 10419 | spin_lock_init(&ioc->pcie_device_lock); |
f92363d1 SR |
10420 | spin_lock_init(&ioc->diag_trigger_lock); |
10421 | ||
10422 | INIT_LIST_HEAD(&ioc->sas_device_list); | |
10423 | INIT_LIST_HEAD(&ioc->sas_device_init_list); | |
10424 | INIT_LIST_HEAD(&ioc->sas_expander_list); | |
d88e1eab SPS |
10425 | INIT_LIST_HEAD(&ioc->pcie_device_list); |
10426 | INIT_LIST_HEAD(&ioc->pcie_device_init_list); | |
f92363d1 SR |
10427 | INIT_LIST_HEAD(&ioc->fw_event_list); |
10428 | INIT_LIST_HEAD(&ioc->raid_device_list); | |
10429 | INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list); | |
10430 | INIT_LIST_HEAD(&ioc->delayed_tr_list); | |
fd0331b3 SS |
10431 | INIT_LIST_HEAD(&ioc->delayed_sc_list); |
10432 | INIT_LIST_HEAD(&ioc->delayed_event_ack_list); | |
f92363d1 | 10433 | INIT_LIST_HEAD(&ioc->delayed_tr_volume_list); |
cf9bd21a | 10434 | INIT_LIST_HEAD(&ioc->reply_queue_list); |
f92363d1 | 10435 | |
c84b06a4 | 10436 | sprintf(ioc->name, "%s_cm%d", ioc->driver_name, ioc->id); |
d357e84d | 10437 | |
f92363d1 SR |
10438 | /* init shost parameters */ |
10439 | shost->max_cmd_len = 32; | |
10440 | shost->max_lun = max_lun; | |
10441 | shost->transportt = mpt3sas_transport_template; | |
10442 | shost->unique_id = ioc->id; | |
10443 | ||
10444 | if (max_sectors != 0xFFFF) { | |
10445 | if (max_sectors < 64) { | |
10446 | shost->max_sectors = 64; | |
10447 | pr_warn(MPT3SAS_FMT "Invalid value %d passed " \ | |
10448 | "for max_sectors, range is 64 to 32767. Assigning " | |
10449 | "value of 64.\n", ioc->name, max_sectors); | |
10450 | } else if (max_sectors > 32767) { | |
10451 | shost->max_sectors = 32767; | |
10452 | pr_warn(MPT3SAS_FMT "Invalid value %d passed " \ | |
10453 | "for max_sectors, range is 64 to 32767. Assigning " | |
10454 | "default value of 32767.\n", ioc->name, | |
10455 | max_sectors); | |
10456 | } else { | |
10457 | shost->max_sectors = max_sectors & 0xFFFE; | |
10458 | pr_info(MPT3SAS_FMT | |
10459 | "The max_sectors value is set to %d\n", | |
10460 | ioc->name, shost->max_sectors); | |
10461 | } | |
10462 | } | |
10463 | ||
f92363d1 SR |
10464 | /* register EEDP capabilities with SCSI layer */ |
10465 | if (prot_mask > 0) | |
10466 | scsi_host_set_prot(shost, prot_mask); | |
10467 | else | |
10468 | scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION | |
10469 | | SHOST_DIF_TYPE2_PROTECTION | |
10470 | | SHOST_DIF_TYPE3_PROTECTION); | |
10471 | ||
10472 | scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC); | |
10473 | ||
10474 | /* event thread */ | |
10475 | snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name), | |
c84b06a4 | 10476 | "fw_event_%s%d", ioc->driver_name, ioc->id); |
bdff785e SR |
10477 | ioc->firmware_event_thread = alloc_ordered_workqueue( |
10478 | ioc->firmware_event_name, WQ_MEM_RECLAIM); | |
f92363d1 SR |
10479 | if (!ioc->firmware_event_thread) { |
10480 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
10481 | ioc->name, __FILE__, __LINE__, __func__); | |
b65f1d4d | 10482 | rv = -ENODEV; |
f92363d1 SR |
10483 | goto out_thread_fail; |
10484 | } | |
10485 | ||
10486 | ioc->is_driver_loading = 1; | |
10487 | if ((mpt3sas_base_attach(ioc))) { | |
10488 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
10489 | ioc->name, __FILE__, __LINE__, __func__); | |
b65f1d4d | 10490 | rv = -ENODEV; |
f92363d1 SR |
10491 | goto out_attach_fail; |
10492 | } | |
7786ab6a | 10493 | |
7786ab6a SR |
10494 | if (ioc->is_warpdrive) { |
10495 | if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) | |
10496 | ioc->hide_drives = 0; | |
10497 | else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS) | |
10498 | ioc->hide_drives = 1; | |
10499 | else { | |
c84b06a4 | 10500 | if (mpt3sas_get_num_volumes(ioc)) |
7786ab6a SR |
10501 | ioc->hide_drives = 1; |
10502 | else | |
10503 | ioc->hide_drives = 0; | |
10504 | } | |
10505 | } else | |
10506 | ioc->hide_drives = 0; | |
7786ab6a | 10507 | |
b65f1d4d SR |
10508 | rv = scsi_add_host(shost, &pdev->dev); |
10509 | if (rv) { | |
4dc06fd8 RS |
10510 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
10511 | ioc->name, __FILE__, __LINE__, __func__); | |
4dc06fd8 RS |
10512 | goto out_add_shost_fail; |
10513 | } | |
10514 | ||
f92363d1 SR |
10515 | scsi_scan_host(shost); |
10516 | return 0; | |
4dc06fd8 RS |
10517 | out_add_shost_fail: |
10518 | mpt3sas_base_detach(ioc); | |
f92363d1 SR |
10519 | out_attach_fail: |
10520 | destroy_workqueue(ioc->firmware_event_thread); | |
10521 | out_thread_fail: | |
08c4d550 | 10522 | spin_lock(&gioc_lock); |
f92363d1 | 10523 | list_del(&ioc->list); |
08c4d550 | 10524 | spin_unlock(&gioc_lock); |
f92363d1 | 10525 | scsi_host_put(shost); |
b65f1d4d | 10526 | return rv; |
f92363d1 SR |
10527 | } |
10528 | ||
10529 | #ifdef CONFIG_PM | |
10530 | /** | |
8a7e4c24 | 10531 | * scsih_suspend - power management suspend main entry point |
f92363d1 SR |
10532 | * @pdev: PCI device struct |
10533 | * @state: PM state change to (usually PCI_D3) | |
10534 | * | |
10535 | * Returns 0 success, anything else error. | |
10536 | */ | |
8bbb1cf6 | 10537 | static int |
8a7e4c24 | 10538 | scsih_suspend(struct pci_dev *pdev, pm_message_t state) |
f92363d1 SR |
10539 | { |
10540 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10541 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10542 | pci_power_t device_state; | |
10543 | ||
10544 | mpt3sas_base_stop_watchdog(ioc); | |
10545 | flush_scheduled_work(); | |
10546 | scsi_block_requests(shost); | |
10547 | device_state = pci_choose_state(pdev, state); | |
10548 | pr_info(MPT3SAS_FMT | |
10549 | "pdev=0x%p, slot=%s, entering operating state [D%d]\n", | |
10550 | ioc->name, pdev, pci_name(pdev), device_state); | |
10551 | ||
10552 | pci_save_state(pdev); | |
10553 | mpt3sas_base_free_resources(ioc); | |
10554 | pci_set_power_state(pdev, device_state); | |
10555 | return 0; | |
10556 | } | |
10557 | ||
10558 | /** | |
8a7e4c24 | 10559 | * scsih_resume - power management resume main entry point |
f92363d1 SR |
10560 | * @pdev: PCI device struct |
10561 | * | |
10562 | * Returns 0 success, anything else error. | |
10563 | */ | |
8bbb1cf6 | 10564 | static int |
8a7e4c24 | 10565 | scsih_resume(struct pci_dev *pdev) |
f92363d1 SR |
10566 | { |
10567 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10568 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10569 | pci_power_t device_state = pdev->current_state; | |
10570 | int r; | |
10571 | ||
10572 | pr_info(MPT3SAS_FMT | |
10573 | "pdev=0x%p, slot=%s, previous operating state [D%d]\n", | |
10574 | ioc->name, pdev, pci_name(pdev), device_state); | |
10575 | ||
10576 | pci_set_power_state(pdev, PCI_D0); | |
10577 | pci_enable_wake(pdev, PCI_D0, 0); | |
10578 | pci_restore_state(pdev); | |
10579 | ioc->pdev = pdev; | |
10580 | r = mpt3sas_base_map_resources(ioc); | |
10581 | if (r) | |
10582 | return r; | |
10583 | ||
98c56ad3 | 10584 | mpt3sas_base_hard_reset_handler(ioc, SOFT_RESET); |
f92363d1 SR |
10585 | scsi_unblock_requests(shost); |
10586 | mpt3sas_base_start_watchdog(ioc); | |
10587 | return 0; | |
10588 | } | |
10589 | #endif /* CONFIG_PM */ | |
10590 | ||
10591 | /** | |
8a7e4c24 | 10592 | * scsih_pci_error_detected - Called when a PCI error is detected. |
f92363d1 SR |
10593 | * @pdev: PCI device struct |
10594 | * @state: PCI channel state | |
10595 | * | |
10596 | * Description: Called when a PCI error is detected. | |
10597 | * | |
10598 | * Return value: | |
10599 | * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT | |
10600 | */ | |
8bbb1cf6 | 10601 | static pci_ers_result_t |
8a7e4c24 | 10602 | scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
f92363d1 SR |
10603 | { |
10604 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10605 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10606 | ||
10607 | pr_info(MPT3SAS_FMT "PCI error: detected callback, state(%d)!!\n", | |
10608 | ioc->name, state); | |
10609 | ||
10610 | switch (state) { | |
10611 | case pci_channel_io_normal: | |
10612 | return PCI_ERS_RESULT_CAN_RECOVER; | |
10613 | case pci_channel_io_frozen: | |
10614 | /* Fatal error, prepare for slot reset */ | |
10615 | ioc->pci_error_recovery = 1; | |
10616 | scsi_block_requests(ioc->shost); | |
10617 | mpt3sas_base_stop_watchdog(ioc); | |
10618 | mpt3sas_base_free_resources(ioc); | |
10619 | return PCI_ERS_RESULT_NEED_RESET; | |
10620 | case pci_channel_io_perm_failure: | |
10621 | /* Permanent error, prepare for device removal */ | |
10622 | ioc->pci_error_recovery = 1; | |
10623 | mpt3sas_base_stop_watchdog(ioc); | |
10624 | _scsih_flush_running_cmds(ioc); | |
10625 | return PCI_ERS_RESULT_DISCONNECT; | |
10626 | } | |
10627 | return PCI_ERS_RESULT_NEED_RESET; | |
10628 | } | |
10629 | ||
10630 | /** | |
8a7e4c24 | 10631 | * scsih_pci_slot_reset - Called when PCI slot has been reset. |
f92363d1 SR |
10632 | * @pdev: PCI device struct |
10633 | * | |
10634 | * Description: This routine is called by the pci error recovery | |
10635 | * code after the PCI slot has been reset, just before we | |
10636 | * should resume normal operations. | |
10637 | */ | |
8bbb1cf6 | 10638 | static pci_ers_result_t |
8a7e4c24 | 10639 | scsih_pci_slot_reset(struct pci_dev *pdev) |
f92363d1 SR |
10640 | { |
10641 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10642 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10643 | int rc; | |
10644 | ||
10645 | pr_info(MPT3SAS_FMT "PCI error: slot reset callback!!\n", | |
10646 | ioc->name); | |
10647 | ||
10648 | ioc->pci_error_recovery = 0; | |
10649 | ioc->pdev = pdev; | |
10650 | pci_restore_state(pdev); | |
10651 | rc = mpt3sas_base_map_resources(ioc); | |
10652 | if (rc) | |
10653 | return PCI_ERS_RESULT_DISCONNECT; | |
10654 | ||
98c56ad3 | 10655 | rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
f92363d1 SR |
10656 | |
10657 | pr_warn(MPT3SAS_FMT "hard reset: %s\n", ioc->name, | |
10658 | (rc == 0) ? "success" : "failed"); | |
10659 | ||
10660 | if (!rc) | |
10661 | return PCI_ERS_RESULT_RECOVERED; | |
10662 | else | |
10663 | return PCI_ERS_RESULT_DISCONNECT; | |
10664 | } | |
10665 | ||
10666 | /** | |
8a7e4c24 | 10667 | * scsih_pci_resume() - resume normal ops after PCI reset |
f92363d1 SR |
10668 | * @pdev: pointer to PCI device |
10669 | * | |
10670 | * Called when the error recovery driver tells us that its | |
10671 | * OK to resume normal operation. Use completion to allow | |
10672 | * halted scsi ops to resume. | |
10673 | */ | |
8bbb1cf6 | 10674 | static void |
8a7e4c24 | 10675 | scsih_pci_resume(struct pci_dev *pdev) |
f92363d1 SR |
10676 | { |
10677 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10678 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10679 | ||
10680 | pr_info(MPT3SAS_FMT "PCI error: resume callback!!\n", ioc->name); | |
10681 | ||
10682 | pci_cleanup_aer_uncorrect_error_status(pdev); | |
10683 | mpt3sas_base_start_watchdog(ioc); | |
10684 | scsi_unblock_requests(ioc->shost); | |
10685 | } | |
10686 | ||
10687 | /** | |
8a7e4c24 | 10688 | * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers |
f92363d1 SR |
10689 | * @pdev: pointer to PCI device |
10690 | */ | |
8bbb1cf6 | 10691 | static pci_ers_result_t |
8a7e4c24 | 10692 | scsih_pci_mmio_enabled(struct pci_dev *pdev) |
f92363d1 SR |
10693 | { |
10694 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10695 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10696 | ||
10697 | pr_info(MPT3SAS_FMT "PCI error: mmio enabled callback!!\n", | |
10698 | ioc->name); | |
10699 | ||
10700 | /* TODO - dump whatever for debugging purposes */ | |
10701 | ||
83c3d340 KW |
10702 | /* This called only if scsih_pci_error_detected returns |
10703 | * PCI_ERS_RESULT_CAN_RECOVER. Read/write to the device still | |
10704 | * works, no need to reset slot. | |
10705 | */ | |
10706 | return PCI_ERS_RESULT_RECOVERED; | |
f92363d1 SR |
10707 | } |
10708 | ||
307d9075 AM |
10709 | /** |
10710 | * scsih__ncq_prio_supp - Check for NCQ command priority support | |
10711 | * @sdev: scsi device struct | |
10712 | * | |
10713 | * This is called when a user indicates they would like to enable | |
10714 | * ncq command priorities. This works only on SATA devices. | |
10715 | */ | |
10716 | bool scsih_ncq_prio_supp(struct scsi_device *sdev) | |
10717 | { | |
10718 | unsigned char *buf; | |
10719 | bool ncq_prio_supp = false; | |
10720 | ||
10721 | if (!scsi_device_supports_vpd(sdev)) | |
10722 | return ncq_prio_supp; | |
10723 | ||
10724 | buf = kmalloc(SCSI_VPD_PG_LEN, GFP_KERNEL); | |
10725 | if (!buf) | |
10726 | return ncq_prio_supp; | |
10727 | ||
10728 | if (!scsi_get_vpd_page(sdev, 0x89, buf, SCSI_VPD_PG_LEN)) | |
10729 | ncq_prio_supp = (buf[213] >> 4) & 1; | |
10730 | ||
10731 | kfree(buf); | |
10732 | return ncq_prio_supp; | |
10733 | } | |
c84b06a4 SR |
10734 | /* |
10735 | * The pci device ids are defined in mpi/mpi2_cnfg.h. | |
10736 | */ | |
10737 | static const struct pci_device_id mpt3sas_pci_table[] = { | |
10738 | /* Spitfire ~ 2004 */ | |
10739 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004, | |
10740 | PCI_ANY_ID, PCI_ANY_ID }, | |
10741 | /* Falcon ~ 2008 */ | |
10742 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008, | |
10743 | PCI_ANY_ID, PCI_ANY_ID }, | |
10744 | /* Liberator ~ 2108 */ | |
10745 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1, | |
10746 | PCI_ANY_ID, PCI_ANY_ID }, | |
10747 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2, | |
10748 | PCI_ANY_ID, PCI_ANY_ID }, | |
10749 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3, | |
10750 | PCI_ANY_ID, PCI_ANY_ID }, | |
10751 | /* Meteor ~ 2116 */ | |
10752 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1, | |
10753 | PCI_ANY_ID, PCI_ANY_ID }, | |
10754 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2, | |
10755 | PCI_ANY_ID, PCI_ANY_ID }, | |
10756 | /* Thunderbolt ~ 2208 */ | |
10757 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1, | |
10758 | PCI_ANY_ID, PCI_ANY_ID }, | |
10759 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2, | |
10760 | PCI_ANY_ID, PCI_ANY_ID }, | |
10761 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3, | |
10762 | PCI_ANY_ID, PCI_ANY_ID }, | |
10763 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4, | |
10764 | PCI_ANY_ID, PCI_ANY_ID }, | |
10765 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5, | |
10766 | PCI_ANY_ID, PCI_ANY_ID }, | |
10767 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6, | |
10768 | PCI_ANY_ID, PCI_ANY_ID }, | |
10769 | /* Mustang ~ 2308 */ | |
10770 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1, | |
10771 | PCI_ANY_ID, PCI_ANY_ID }, | |
10772 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2, | |
10773 | PCI_ANY_ID, PCI_ANY_ID }, | |
10774 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3, | |
10775 | PCI_ANY_ID, PCI_ANY_ID }, | |
10776 | /* SSS6200 */ | |
10777 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200, | |
10778 | PCI_ANY_ID, PCI_ANY_ID }, | |
10779 | /* Fury ~ 3004 and 3008 */ | |
10780 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3004, | |
10781 | PCI_ANY_ID, PCI_ANY_ID }, | |
10782 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3008, | |
10783 | PCI_ANY_ID, PCI_ANY_ID }, | |
10784 | /* Invader ~ 3108 */ | |
10785 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_1, | |
10786 | PCI_ANY_ID, PCI_ANY_ID }, | |
10787 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_2, | |
10788 | PCI_ANY_ID, PCI_ANY_ID }, | |
10789 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_5, | |
10790 | PCI_ANY_ID, PCI_ANY_ID }, | |
10791 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_6, | |
10792 | PCI_ANY_ID, PCI_ANY_ID }, | |
b130b0d5 SS |
10793 | /* Cutlass ~ 3216 and 3224 */ |
10794 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3216, | |
10795 | PCI_ANY_ID, PCI_ANY_ID }, | |
10796 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3224, | |
10797 | PCI_ANY_ID, PCI_ANY_ID }, | |
10798 | /* Intruder ~ 3316 and 3324 */ | |
10799 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_1, | |
10800 | PCI_ANY_ID, PCI_ANY_ID }, | |
10801 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_2, | |
10802 | PCI_ANY_ID, PCI_ANY_ID }, | |
10803 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_3, | |
10804 | PCI_ANY_ID, PCI_ANY_ID }, | |
10805 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_4, | |
10806 | PCI_ANY_ID, PCI_ANY_ID }, | |
10807 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_1, | |
10808 | PCI_ANY_ID, PCI_ANY_ID }, | |
10809 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_2, | |
10810 | PCI_ANY_ID, PCI_ANY_ID }, | |
10811 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_3, | |
10812 | PCI_ANY_ID, PCI_ANY_ID }, | |
10813 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_4, | |
10814 | PCI_ANY_ID, PCI_ANY_ID }, | |
998f26ae SPS |
10815 | /* Ventura, Crusader, Harpoon & Tomcat ~ 3516, 3416, 3508 & 3408*/ |
10816 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3508, | |
10817 | PCI_ANY_ID, PCI_ANY_ID }, | |
10818 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3508_1, | |
10819 | PCI_ANY_ID, PCI_ANY_ID }, | |
10820 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3408, | |
10821 | PCI_ANY_ID, PCI_ANY_ID }, | |
10822 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3516, | |
10823 | PCI_ANY_ID, PCI_ANY_ID }, | |
10824 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3516_1, | |
10825 | PCI_ANY_ID, PCI_ANY_ID }, | |
10826 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3416, | |
10827 | PCI_ANY_ID, PCI_ANY_ID }, | |
15fd7c74 SR |
10828 | /* Mercator ~ 3616*/ |
10829 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3616, | |
10830 | PCI_ANY_ID, PCI_ANY_ID }, | |
c84b06a4 SR |
10831 | {0} /* Terminating entry */ |
10832 | }; | |
10833 | MODULE_DEVICE_TABLE(pci, mpt3sas_pci_table); | |
10834 | ||
10835 | static struct pci_error_handlers _mpt3sas_err_handler = { | |
10836 | .error_detected = scsih_pci_error_detected, | |
10837 | .mmio_enabled = scsih_pci_mmio_enabled, | |
10838 | .slot_reset = scsih_pci_slot_reset, | |
10839 | .resume = scsih_pci_resume, | |
10840 | }; | |
10841 | ||
10842 | static struct pci_driver mpt3sas_driver = { | |
10843 | .name = MPT3SAS_DRIVER_NAME, | |
10844 | .id_table = mpt3sas_pci_table, | |
10845 | .probe = _scsih_probe, | |
10846 | .remove = scsih_remove, | |
10847 | .shutdown = scsih_shutdown, | |
10848 | .err_handler = &_mpt3sas_err_handler, | |
10849 | #ifdef CONFIG_PM | |
10850 | .suspend = scsih_suspend, | |
10851 | .resume = scsih_resume, | |
10852 | #endif | |
10853 | }; | |
10854 | ||
f92363d1 | 10855 | /** |
8a7e4c24 | 10856 | * scsih_init - main entry point for this driver. |
f92363d1 SR |
10857 | * |
10858 | * Returns 0 success, anything else error. | |
10859 | */ | |
8bbb1cf6 | 10860 | static int |
8a7e4c24 | 10861 | scsih_init(void) |
f92363d1 | 10862 | { |
c84b06a4 SR |
10863 | mpt2_ids = 0; |
10864 | mpt3_ids = 0; | |
f92363d1 | 10865 | |
f92363d1 SR |
10866 | mpt3sas_base_initialize_callback_handler(); |
10867 | ||
10868 | /* queuecommand callback hander */ | |
10869 | scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done); | |
10870 | ||
6c7abffc | 10871 | /* task management callback handler */ |
f92363d1 SR |
10872 | tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done); |
10873 | ||
10874 | /* base internal commands callback handler */ | |
10875 | base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done); | |
10876 | port_enable_cb_idx = mpt3sas_base_register_callback_handler( | |
10877 | mpt3sas_port_enable_done); | |
10878 | ||
10879 | /* transport internal commands callback handler */ | |
10880 | transport_cb_idx = mpt3sas_base_register_callback_handler( | |
10881 | mpt3sas_transport_done); | |
10882 | ||
10883 | /* scsih internal commands callback handler */ | |
10884 | scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done); | |
10885 | ||
10886 | /* configuration page API internal commands callback handler */ | |
10887 | config_cb_idx = mpt3sas_base_register_callback_handler( | |
10888 | mpt3sas_config_done); | |
10889 | ||
10890 | /* ctl module callback handler */ | |
10891 | ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done); | |
10892 | ||
10893 | tm_tr_cb_idx = mpt3sas_base_register_callback_handler( | |
10894 | _scsih_tm_tr_complete); | |
10895 | ||
10896 | tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler( | |
10897 | _scsih_tm_volume_tr_complete); | |
10898 | ||
10899 | tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler( | |
10900 | _scsih_sas_control_complete); | |
10901 | ||
7497392a | 10902 | return 0; |
f92363d1 SR |
10903 | } |
10904 | ||
10905 | /** | |
7497392a | 10906 | * scsih_exit - exit point for this driver (when it is a module). |
f92363d1 SR |
10907 | * |
10908 | * Returns 0 success, anything else error. | |
10909 | */ | |
8bbb1cf6 | 10910 | static void |
8a7e4c24 | 10911 | scsih_exit(void) |
f92363d1 | 10912 | { |
f92363d1 SR |
10913 | |
10914 | mpt3sas_base_release_callback_handler(scsi_io_cb_idx); | |
10915 | mpt3sas_base_release_callback_handler(tm_cb_idx); | |
10916 | mpt3sas_base_release_callback_handler(base_cb_idx); | |
10917 | mpt3sas_base_release_callback_handler(port_enable_cb_idx); | |
10918 | mpt3sas_base_release_callback_handler(transport_cb_idx); | |
10919 | mpt3sas_base_release_callback_handler(scsih_cb_idx); | |
10920 | mpt3sas_base_release_callback_handler(config_cb_idx); | |
10921 | mpt3sas_base_release_callback_handler(ctl_cb_idx); | |
10922 | ||
10923 | mpt3sas_base_release_callback_handler(tm_tr_cb_idx); | |
10924 | mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx); | |
10925 | mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx); | |
10926 | ||
10927 | /* raid transport support */ | |
c84b06a4 SR |
10928 | if (hbas_to_enumerate != 1) |
10929 | raid_class_release(mpt3sas_raid_template); | |
10930 | if (hbas_to_enumerate != 2) | |
10931 | raid_class_release(mpt2sas_raid_template); | |
f92363d1 SR |
10932 | sas_release_transport(mpt3sas_transport_template); |
10933 | } | |
7786ab6a | 10934 | |
c84b06a4 SR |
10935 | /** |
10936 | * _mpt3sas_init - main entry point for this driver. | |
10937 | * | |
10938 | * Returns 0 success, anything else error. | |
10939 | */ | |
10940 | static int __init | |
10941 | _mpt3sas_init(void) | |
10942 | { | |
10943 | int error; | |
10944 | ||
10945 | pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME, | |
10946 | MPT3SAS_DRIVER_VERSION); | |
10947 | ||
10948 | mpt3sas_transport_template = | |
10949 | sas_attach_transport(&mpt3sas_transport_functions); | |
10950 | if (!mpt3sas_transport_template) | |
10951 | return -ENODEV; | |
10952 | ||
10953 | /* No need attach mpt3sas raid functions template | |
10954 | * if hbas_to_enumarate value is one. | |
10955 | */ | |
10956 | if (hbas_to_enumerate != 1) { | |
10957 | mpt3sas_raid_template = | |
10958 | raid_class_attach(&mpt3sas_raid_functions); | |
10959 | if (!mpt3sas_raid_template) { | |
10960 | sas_release_transport(mpt3sas_transport_template); | |
10961 | return -ENODEV; | |
10962 | } | |
10963 | } | |
10964 | ||
10965 | /* No need to attach mpt2sas raid functions template | |
10966 | * if hbas_to_enumarate value is two | |
10967 | */ | |
10968 | if (hbas_to_enumerate != 2) { | |
10969 | mpt2sas_raid_template = | |
10970 | raid_class_attach(&mpt2sas_raid_functions); | |
10971 | if (!mpt2sas_raid_template) { | |
10972 | sas_release_transport(mpt3sas_transport_template); | |
10973 | return -ENODEV; | |
10974 | } | |
10975 | } | |
10976 | ||
10977 | error = scsih_init(); | |
10978 | if (error) { | |
10979 | scsih_exit(); | |
10980 | return error; | |
10981 | } | |
10982 | ||
10983 | mpt3sas_ctl_init(hbas_to_enumerate); | |
10984 | ||
10985 | error = pci_register_driver(&mpt3sas_driver); | |
10986 | if (error) | |
10987 | scsih_exit(); | |
10988 | ||
10989 | return error; | |
10990 | } | |
10991 | ||
10992 | /** | |
10993 | * _mpt3sas_exit - exit point for this driver (when it is a module). | |
10994 | * | |
10995 | */ | |
10996 | static void __exit | |
10997 | _mpt3sas_exit(void) | |
10998 | { | |
10999 | pr_info("mpt3sas version %s unloading\n", | |
11000 | MPT3SAS_DRIVER_VERSION); | |
11001 | ||
11002 | pci_unregister_driver(&mpt3sas_driver); | |
11003 | ||
11004 | mpt3sas_ctl_exit(hbas_to_enumerate); | |
11005 | ||
11006 | scsih_exit(); | |
11007 | } | |
11008 | ||
11009 | module_init(_mpt3sas_init); | |
11010 | module_exit(_mpt3sas_exit); |